Problem with multiple connection in multirole device

Hello,

In my project, I have a device (nrf52833 custom board) which I want to operate in dual role (central/peripheral). I've followed a ble_app_hrs_rscs_relay example and got it working in some degree which includes:

  • pairing in both central and peripheral role works OK
  • connection securing in both roles works OK (when connecting one at the time)
  • disconnection in both roles works OK

The problem appears when the device is connected in peripheral role (with bonded nrfConnect app on android phone), and trying to connect in central role (another nrf52833 custom board peripheral device). In this case this is the output:

00> <error> peer_manager_sm: Could not perform security procedure. smd_link_secure() returned NRF_ERROR_INVALID_ADDR. conn_handle: 0
00> 
00> <error> peer_manager_handler: Asserting. pm_conn_secure() returned NRF_ERROR_INTERNAL on conn_handle 0.
00> 
00> <error> app: ERROR 3 [NRF_ERROR_INTERNAL] at ../../../../../../../resources/nRF5_SDK_17.0.2_d674dde/components/ble/peer_manager/peer_manager_handler.c:224
00> 
00> PC at: 0x00039603
00> 
00> <error> app: End of error report

I wanted to ask if there is maybe something I'm missing or some obvious reason for that error? 

I'm using SDK 17.0.2 

PS: I'm not sharing the project as it is large and it would be impossible to run it on any devkit as it requires this custom hardware setup to work

Parents
  • Hi Jakub, 

    The error log suggested a bad memory address (NRF_ERROR_INVALID_ADDR) . So we need to look into how you called pm_conn_secure() when you connected to the peripheral.

    You may want to add a breakpoint and step into the code when the central (relay) try to encrypt the link after the connection is established. Double check if the connection handle is correct. 

  • Thanks for your answer. I don't have debug setup to set breakpoints, the only way I can debug is via logs. What I've managed to establish while playing around is:

    1. This is the procedure to force the issue (I'm posting steps to show when exactly something goes wrong):
      - pair with phone -> OK
      - pair with peripheral - > OK
      - connect with phone, connect and disconnect with peripheral while phone connected -> OK
      - disconnect with phone -> OK
      - connect with the peripheral (no matter if yo reconnect with phone or not) -> ERROR

    2. The error hapens in pm_handler_on_pm_evt(p_evt) when p_evt == PM_EVT_BONDED_PEER_CONNECTED

    3. The connection handles are ok each time it happens (always 0 for peripheral and 1 for phone)

    4. For some reason phone gets conn_handle = 1 and peripheral gets conn_handle = 0 even if phone bonds first. Is it supposed to be that way?

    It looks like during those operations the peer_manager looses bonding information of peripheral device. It seems like it happens when the phone disconnects. Could you please tell me how is address linked with conn_handle, and what are the possible reasons that pm_conn_secure won't have bonded device's address in it's memory? 

  • Hi Jakub, 
    Could you let me know more about your setup ? Why you can program it but not debug it  ? 
    Can you reproduce the issue on a development kit ? 
    If you test with ble_app_hrs_rscs_relay do you see the same problem ? 
    If not have you checked the sdk_config.h file to see if there is any difference ? 

    The conn_handle is simply increment from 0 or from the first free connection handler. I don't see an issue if the conn_handle is 1 or 0 or other as long as you use the correct conn_handle for the correct connection you want to control.

    What is a "correct" connection handle then ? It's the connection handle that originally returned from BLE_GAP_EVT_CONNECTED

    However, I don't think the issue is with the connection handle. It may have something to do with either sd_ble_gap_encrypt() that's called by link_secure_central_encryption(). 

    Please try to debug the smd_link_secure() function or use log to debug, and find what exactly throwing NRF_ERROR_INVALID_ADDR. 

Reply
  • Hi Jakub, 
    Could you let me know more about your setup ? Why you can program it but not debug it  ? 
    Can you reproduce the issue on a development kit ? 
    If you test with ble_app_hrs_rscs_relay do you see the same problem ? 
    If not have you checked the sdk_config.h file to see if there is any difference ? 

    The conn_handle is simply increment from 0 or from the first free connection handler. I don't see an issue if the conn_handle is 1 or 0 or other as long as you use the correct conn_handle for the correct connection you want to control.

    What is a "correct" connection handle then ? It's the connection handle that originally returned from BLE_GAP_EVT_CONNECTED

    However, I don't think the issue is with the connection handle. It may have something to do with either sd_ble_gap_encrypt() that's called by link_secure_central_encryption(). 

    Please try to debug the smd_link_secure() function or use log to debug, and find what exactly throwing NRF_ERROR_INVALID_ADDR. 

Children
No Data
Related