espressif / esp-nimble

A fork of NimBLE stack, for use with ESP32 and ESP-IDF
Apache License 2.0
76 stars 49 forks source link

No listen values after first connection on iPhone with RPA enabled #23

Closed lvaccaro closed 4 months ago

lvaccaro commented 3 years ago

Hi, I am using nimble-1.2.0-idf library with esp v4.2 on a m5stick ble board to exchange communication between the device and android/iphone using 2 characteristics: one to write and one to read with indicate property: https://github.com/Blockstream/Jade/blob/master/main/ble/ble.c#L153 .

Using the LightBlue app on an iPhone, in the 1st connection (so after the 1st pairing ble procedure) I am able to listen for notifications and write/read messages. Then, in a following connection, the connection is established, the iOS app sends a message to the device but this time I don't get a response (from the device logs, the device received the message and sent a response, but the app doesn't receive any notifications). The only solution to make it working again is to remove the bonded device from the list of bluetooth paired device in the iphone settings and repeat pairing again.

On the other hand, if in the 1st connection (after pairing the device) I close the connection without making any action on the characteristics (so no listen or write), then the following connections will work as expected.

The bluetooth device enable RPA with random address and bonding as the following:

    int rc = ble_hs_util_ensure_addr(0);
    ...
    own_addr_type = BLE_OWN_ADDR_RANDOM;
    rc = ble_hs_pvcy_rpa_config(1);
    ...
    ble_hs_cfg.sm_bonding = 1;
    ble_hs_cfg.sm_mitm = 1;
    ble_hs_cfg.sm_sc = 1;
    ...
    ble_hs_cfg.sm_our_key_dist = BLE_SM_PAIR_KEY_DIST_ENC | BLE_SM_PAIR_KEY_DIST_ID;
    ble_hs_cfg.sm_their_key_dist = BLE_SM_PAIR_KEY_DIST_ENC | BLE_SM_PAIR_KEY_DIST_ID;

log_first_connection_success.txt log_second_connection_failure.txt

prasad-alatkar commented 3 years ago

@lvaccaro , apologies for late response. Can you please send device side logs with DEBUG prints enabled (menuconfig--> Component config --> Log output --> Debug log verbosity to Debug)?

rahult-github commented 4 months ago

This is an old issue reported on IDF versions which are no more supported.

Tested the same sequence on latest esp idf and see no issues between two connection attempts . Attached log for reference.

Closing the issue. Feel free to reopen if issue still observed. twice_connection.txt