This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How do I find out if devices already bonded after building up a connection?

Hello,

I have an BLE application were I want, for security reasons, to allow a connection only if a button is pushed or if the devices already have bonded before. The Button is no problem I just wait for the BLE_GAP_EVT_CONNECTED event. Then I ask if the Button had been pushed. If the button had been pushed I do nothing and my application continues. My problem is now, if the Button hadn't been pushed, how do I find out if the devices already bonded at this point in the code to close the connection?

I know that if the devices already bonded the PM_EVT_BONDED_PEER_CONNECTED event occurs. But in case the button hadn't been pushed and the devices aren't already bonded I have no event I can wait for and then close the connection. All the other peer_manager events only occur after the device tries to bond and not after building up a connection.

I hope it gets clear where my problem is and I'm thankful for any advice.

(I'm using the nrf52 developer Board an the SDK12.2.0)

Regards Lea

Parents
  • If you wait for the BLE_GAP_EVT_CONNECTED event you have already allowed connection, if you want to disallow connections you should advertise with a whitelist containing the addresses of the bonded devices, and advertise without whitelist when the button is pushed.

    If you want to allow connections but only let devices pair when the button is pushed I think you can use pm_sec_params_set().

    When the button is pushed call pm_sec_params_set() with the security parameters you want to use when pairing/bonding, when button is released call pm_sec_params_set(NULL) to disallow pairing.

    I guess you could alternatively call pm_sec_params_set() with or without NULL depending on button state every time you get an event from the SoftDevice.

Reply
  • If you wait for the BLE_GAP_EVT_CONNECTED event you have already allowed connection, if you want to disallow connections you should advertise with a whitelist containing the addresses of the bonded devices, and advertise without whitelist when the button is pushed.

    If you want to allow connections but only let devices pair when the button is pushed I think you can use pm_sec_params_set().

    When the button is pushed call pm_sec_params_set() with the security parameters you want to use when pairing/bonding, when button is released call pm_sec_params_set(NULL) to disallow pairing.

    I guess you could alternatively call pm_sec_params_set() with or without NULL depending on button state every time you get an event from the SoftDevice.

Children
No Data
Related