esp-nimble-cpp icon indicating copy to clipboard operation
esp-nimble-cpp copied to clipboard

Numeric Comparison and Passkey Entry are not properly handled

Open csmith-morningstar opened this issue 2 years ago • 1 comments

In NimBLEServer.cpp: Currently Numeric Comparison and Passkey Entry (BLE_SM_IOACT_NUMCMP and BLE_SM_IOACT_INPUT respectively) perform blocking calls to callbacks in order to determine the input for ble_sm_inject_io. However, this prevents the SMP Timeout (Vol. 3 Part H Section 3.4 of the Bluetooth 4.2 spec) from properly triggering, as those functions may pend too long waiting for user input.

Furthermore, even if the callbacks do properly timeout themselves, there is no way for them to properly align with the spec, which states that in the event of a timeout "No further SMP commands shall be sent over the L2CAP Security Manager Channel." This is because when the callbacks return, ble_sm_inject_io is always called, which results in a "Pairing Failed" command being sent over the SMP channel.

Instead of relying on blocking function calls, these two scenarios should initiate the callbacks only as a means of displaying a prompt to the user, and relying on an asynchronous event for the call to ble_sm_inject_io. This allows the timeout event to properly occur.

csmith-morningstar avatar Apr 14 '23 15:04 csmith-morningstar

Hello, yes you are absolutely correct, this has been on my radar to address for quite some time. I will look into fixing this when I get some free time.

h2zero avatar Apr 16 '23 23:04 h2zero