Closed dalvisachin closed 4 months ago
Hi @dalvisachin ,
ESP32C3 has controller based privacy enabled by default.
I make a call to ble_hs_pvcy_rpa_config() with parameter NIMBLE_HOST_ENABLE_NRPA since my local host is not using RPA but only the Peer uses RPA.
This functionality is basically host based privacy. Enabling both at same time should not be done. So, i suggest do not enable host based privacy for ESP32C3.
Can you please share the idf version being used ? Also, if you have any debug enabled logs, then that would be helpful to understand the flow of commands / events.
Thanks, Rahul
Hello @rahult-github, Thank you for replying.
I removed the host based privacy and tried again but no luck.
I have attached the sources, sdkconfig and logs as well. I am using esp-idf v4.4.1, I have also tried v4.3.2 but it has same behavior. The source is based on blecent example.
I added some debug logs in function ble_gap_security_initiate() in file ble_gap.c to check if LTK is found or not. And for the peer even after it is disconnected and ble_gap_unpair() is called, LTK for this peer is always found in subsequent connection attempts.
if (conn_flags & BLE_HS_CONN_F_MASTER) {
/* Search the security database for an LTK for this peer. If one
* is found, perform the encryption procedure rather than the pairing
* procedure.
*/
rc = ble_store_read_peer_sec(&key_sec, &value_sec);
if (rc == 0 && value_sec.ltk_present) {
MODLOG_DFLT(WARN, "Found LTK for %02X:%02X:%02X:%02X:%02X:%02X",
addrs.peer_id_addr.val[5], addrs.peer_id_addr.val[4],
addrs.peer_id_addr.val[3], addrs.peer_id_addr.val[2],
addrs.peer_id_addr.val[1], addrs.peer_id_addr.val[0]
);
rc = ble_sm_enc_initiate(conn_handle, value_sec.key_size,
value_sec.ltk, value_sec.ediv,
value_sec.rand_num,
value_sec.authenticated);
if (rc != 0) {
goto done;
}
} else {
MODLOG_DFLT(WARN, "NO LTK found for %02X:%02X:%02X:%02X:%02X:%02X",
addrs.peer_id_addr.val[5], addrs.peer_id_addr.val[4],
addrs.peer_id_addr.val[3], addrs.peer_id_addr.val[2],
addrs.peer_id_addr.val[1], addrs.peer_id_addr.val[0]
);
rc = ble_sm_pair_initiate(conn_handle);
if (rc != 0) {
goto done;
}
}
}
Steps to reproduce-
I also checked with BLE sniffer and found out that, ESP32 sends encryption requests (since it finds LTK) for all subsequent connections and peer then terminates the connection since it expects pairing request.
Thanks, Sachin
ble_gap_unpair was updated to delete IRK / LTK for various scenarios. That should help fix this issue.
I have ESP32C3 acting as a client. The peer is NRF52832. ESP32C3 is using public address where as NRF is using random address.
My application requires bonding with just works pairing.
At very first connection everything works as expected.
Now Peer (NRF52) disconnects and in ESP32 I get the event
BLE_GAP_EVENT_DISCONNECT
in which I callble_gap_unpair()
to unpair with this peer and deleting the bonding info, keys etc.When I want to connect again with this Peer, i expect ESP32 to send the pairing request again and start the bonding process fresh. But instead it send encryption request. After digging deeper I found when I make call to function
ble_gap_security_initiate()
inBLE_GAP_EVENT_CONNECT
it always finds the LTK for this peer.
below is the snippet from function
ble_gap_security_initiate()
in file ble_gap.cThis problem does not occur with Peers who advertise public address.
After reading this https://github.com/espressif/esp-nimble/pull/7 and this https://github.com/espressif/esp-nimble/issues/8
I make a call to
ble_hs_pvcy_rpa_config()
with parameterNIMBLE_HOST_ENABLE_NRPA
since my local host is not using RPA but only the Peer uses RPA.the function blecent_on_sync() is as follows
the function blecent_scan() is as follows
SM configuration for ESP32C3 is
Can someone please help me with this ? Or tell me if I am doing something wrong? My goal is to have public address and bond to peer with random address, when this peer disconnects the connection then remove the bonding info and start pairing process again.
Like I already mentioned everything works fine if if peer has public address.