Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Can Peripheral ask for bonding after Central connection?

Hi, we're using \nRF5_SDK_14.2.0_17b948a\examples\ble_peripheral\ble_app_hids_keyboard to test Pairing/Bonding/whitelist.

After connection, when the central try to read a secured characteristic, the central send the bonding request and the peripheral reply and add the device to its whitelist. After disconnection whitelisted advertising is performed by periperal. Reset bonding and advertising restart without whitelist.

Is there a way, into peripheral code, to trigger the bonding/add to whitelist procedure directly after central connection? 

Thanks

Luca

  • I just solved using pm_conn_secure() on BLE_GAP_EVT_CONNECTED.

    I wrote this code into example aplication \nRF5_SDK_14.2.0_17b948a\examples\ble_peripheral\ble_app_hids_keyboard :

    /**@brief Function for handling BLE events.
     *
     * @param[in]   p_ble_evt   Bluetooth stack event.
     * @param[in]   p_context   Unused.
     */
    static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
    {
       ret_code_t err_code;
       
       switch (p_ble_evt->header.evt_id)
       {
          case BLE_GAP_EVT_CONNECTED:
          {
             NRF_LOG_INFO("Connected");
             err_code = bsp_indication_set(BSP_INDICATE_CONNECTED);
             APP_ERROR_CHECK(err_code);
             m_conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
             
             /* Try to ask secure connection */
             err_code = pm_conn_secure(m_conn_handle, false);
             APP_ERROR_CHECK(err_code);
          }
          break;
          
          ...

Related