Closed felixdoerre closed 8 months ago
Hi @felixdoerre. Thanks for reporting. You're totally right, the code you've suggested is missing. It's the same code block in the successful lookup a few lines earlier: https://github.com/bluekitchen/btstack/blob/367b47cf6e9c34814b4b65bd34cd20513415ea78/src/ble/sm.c#L1331 I've added the lines in commit 434260a. Please let me know if it doesn't work.
Describe the bug
In a certain situation, when receiving a pairing request immediately after connecting, the SM (in the role of ble periheral) does not respond with a pairing response, leaving the connection hanging and running into a timeout from ble central.
To Reproduce
Connect to a btstack peripheral (e.g. with android).
Expected behavior
After the pairing request is received, a pairing response is sent.
Debugging Trace On my system, when the pairing request is received,
irk_lookup
is still running, causing this branch to be taken: https://github.com/bluekitchen/btstack/blob/367b47cf6e9c34814b4b65bd34cd20513415ea78/src/ble/sm.c#L4495 This leavessm_conn->sm_engine_state
inSM_RESPONDER_PH1_PAIRING_REQUEST_RECEIVED_W4_IRK
.At some point later
irk_lookup
finishes and fails (as expected,because this is a connection from a new device) This event is handled here: https://github.com/bluekitchen/btstack/blob/367b47cf6e9c34814b4b65bd34cd20513415ea78/src/ble/sm.c#L1396However, while there is code to update
SM_RESPONDER_PH0_RECEIVED_LTK_W4_IRK
, the update fromSM_RESPONDER_PH1_PAIRING_REQUEST_RECEIVED_W4_IRK
toSM_RESPONDER_PH1_PAIRING_REQUEST_RECEIVED
seems to be missing.I would expect to see a state update here as well, like for the
ADDRESS_RESOLUTION_SUCCEEDED
-case: https://github.com/bluekitchen/btstack/blob/367b47cf6e9c34814b4b65bd34cd20513415ea78/src/ble/sm.c#L1331Is this state update missing here (e.g. before line 1400)?
Or should this case be handled differently?