h2zero / esp-nimble-cpp

C++ library for the esp32 NimBLE stack based on and mostly compatible with @nkolban cpp_utils BLE library.
https://h2zero.github.io/esp-nimble-cpp/
Apache License 2.0
181 stars 62 forks source link

Secure connection fails with BLE_HS_EAGAIN #215

Closed thekurtovic closed 2 weeks ago

thekurtovic commented 3 weeks ago

I'm having an issue where the call to secureConnection() returns early starting from commit a2fe5b4. The strange part is that the onAuthenticationComplete is triggered shortly after reporting failure. I use the result of pClient->secureConnection() to determine whether it succeeded or not, but the logs indicate that it succeeds after the call already returned false. Should I use the result from the onAuthenticationComplete callback instead?

Tested with an esp32-s3, idf 5.1.4, arduino 3.0.7 (pioarduino).

Commit a2fe5b4

i [ 11915][avx_ble.cpp:354] Create client, attempting to connect...
V ( 11924) NimBLEClient: >> connect(e3:e4:5b:75:ad:36)
V ( 12862) NimBLEClient: Got Client event BLE_GAP_EVENT_CONNECT
D ( 12862) NimBLEClient: Connected event
V ( 12876) NimBLEClient: Got Client event BLE_GAP_EVENT_MTU
D ( 12877) NimBLEClient: mtu update event; conn_handle=1 mtu=247
D ( 12877) NimBLEClient: Connection established
V ( 12884) NimBLEUtils: gapEventToString: Unknown event type 33 0x21
V ( 12884) NimBLEClient: Got Client event Unknown event type
V ( 12887) NimBLEClient: >> deleteServices
V ( 12898) NimBLEClient: << deleteServices
V ( 12909) NimBLEClient: >> getRssi()
i [ 12909][main.cpp:142] Connected to e3e45b75ad36, RSSI -28 (bond 0)
V ( 12911) NimBLEClient: << connect()
V ( 12914) NimBLEUtils: gapEventToString: Unknown event type 32 0x20
V ( 12914) NimBLEClient: Got Client event Unknown event type
i [ 12922][main.cpp:371] Securing connection...
V ( 12932) NimBLEClient: >> secureConnection()
V ( 12944) NimBLEClient: secureConnection: start security failed 1
e [ 12945][main.cpp:375] Failed to secure, delete client
V ( 13003) NimBLEClient: Got Client event BLE_GAP_EVENT_CONN_UPDATE
D ( 13003) NimBLEClient: Connection parameters updated.
V ( 13129) NimBLEClient: Got Client event BLE_GAP_EVENT_PASSKEY_ACTION
V ( 13130) NimBLEClient: Enter the passkey
i [ 13130][main.cpp:192] Client requesting passkey...
i [ 13140][main.cpp:51] generated key...
V ( 13141) NimBLEDevice: BLE_SM_IOACT_INPUT; ble_sm_inject_io result: 0
V ( 13862) NimBLEClient: Got Client event BLE_GAP_EVENT_ENC_CHANGE
i [ 13863][main.cpp:182] auth event 1

Commit 877a29a

V ( 29590) NimBLEScan: << stop()
V ( 29590) NimBLEScan: erase device: e3:e4:5b:75:ad:36
V ( 29869) NimBLEClient: Got Client event BLE_GAP_EVENT_CONNECT
D ( 29869) NimBLEClient: Connected event
V ( 29886) NimBLEClient: Got Client event BLE_GAP_EVENT_MTU
D ( 29886) NimBLEClient: mtu update event; conn_handle=1 mtu=247
D ( 29887) NimBLEClient: Connection established
V ( 29893) NimBLEUtils: gapEventToString: Unknown event type 33 0x21
V ( 29893) NimBLEClient: Got Client event Unknown event type
V ( 29897) NimBLEClient: >> deleteServices
V ( 29908) NimBLEClient: << deleteServices
V ( 29919) NimBLEClient: >> getRssi()
i [ 29919][main.cpp:142] Connected to e3e45b75ad36, RSSI -29 (bond 0)
V ( 29921) NimBLEClient: << connect()
V ( 29924) NimBLEUtils: gapEventToString: Unknown event type 32 0x20
V ( 29924) NimBLEClient: Got Client event Unknown event type
i [ 29932][main.cpp:371] Securing connection...
V ( 29942) NimBLEClient: >> secureConnection()
V ( 29998) NimBLEClient: Got Client event BLE_GAP_EVENT_CONN_UPDATE
D ( 29998) NimBLEClient: Connection parameters updated.
V ( 30125) NimBLEClient: Got Client event BLE_GAP_EVENT_PASSKEY_ACTION
V ( 30125) NimBLEClient: Enter the passkey
i [ 30125][main.cpp:192] Client requesting passkey...
i [ 30135][main.cpp:51] generated key...
V ( 30136) NimBLEDevice: BLE_SM_IOACT_INPUT; ble_sm_inject_io result: 0
V ( 30857) NimBLEClient: Got Client event BLE_GAP_EVENT_ENC_CHANGE
i [ 30857][main.cpp:182] auth event 1
V ( 30857) NimBLEClient: << secureConnection: success
i [ 30868][main.cpp:390] Secured connection (1)
h2zero commented 2 weeks ago

Thanks, I have addressed this in #217