Please tell me how to achieve re-pairing.

I am developing with nrf52832 (s132 v7.0.1, SDK v17.0.0) as a peripheral device.

I would like to have it re-paired when there is no pairing information for either peripheral or central.

I found out that this can be done by allowing re-pairing when PM_EVT_CONN_SEC_CONFIG_REQ occurs, so I added that process, but the pairing does not succeed and the device is disconnected.

pm_conn_sec_config_t conn_sec_config;

case PM_EVT_CONN_SEC_CONFIG_REQ:
        NRF_LOG_INFO("PM_EVT_CONN_SEC_CONFIG_REQ");
        conn_sec_config.allow_repairing = true;
        pm_conn_sec_config_reply(conn_handle, &conn_sec_config);
        break;

The disconnection is done after PM_EVT_CONN_SEC_FAILED.
No special processing is done in PM_EVT_CONN_SEC_FAILED.

case PM_EVT_CONN_SEC_FAILED:
        if (p_evt.params.conn_sec_failed.error == BLE_GAP_SEC_STATUS_PAIRING_NOT_SUPP) {
            NRF_LOG_INFO("No Bonding Infomation for Central.");
            return;
        }
        else if (p_evt.params.conn_sec_failed.error == PM_CONN_SEC_ERROR_PIN_OR_KEY_MISSING) {
            NRF_LOG_INFO("No Bonding Infomation for Peripheral.");
            return;
        }
        
        break;

How can we achieve re-pairing?

Parents
  • I logged it thinking that PM_EVT_CONN_SEC_CONFIG_REQ may not have been called.

    Logs where only pairing information for peripherals was deleted and re-paired.

    00> <info> app: Connected, handle 0x0.
    00> <info> peer_manager_handler: Connection security failed: role: Peripheral, conn_handle: 0x0, procedure: Encryption, error: 4102
    00> <info> app: Connection Security Failed. procedure: 0x0, error: 0x1006, error_src: 0x0.
    00> <info> app: No Bonding Infomation for Peripheral.
    00> <info> app: Disconnected. conn_handle: 0x0, reason 0x13.

    Logs where only central pairing information was deleted and re-paired.

    00> <info> peer_manager_handler: Peer data updated in flash: peer_id: 0, data_id: Peer rank, action: Update, no change
    00> <info> app: Connected, handle 0x0.
    00> <info> app: PHY update request.
    00> <info> peer_manager_handler: Peer data updated in flash: peer_id: 0, data_id: Local database, action: Update
    00> <info> app: PM_EVT_CONN_SEC_CONFIG_REQ
    00> <info> peer_manager_handler: Connection security failed: role: Peripheral, conn_handle: 0x0, procedure: Bonding, error: 133
    00> <info> app: Connection Security Failed. procedure: 0x1, error: 0x85, error_src: 0x0.
    00> <info> app: No Bonding Infomation for Central.
    00> <info> peer_manager_handler: Peer data updated in flash: peer_id: 0, data_id: Local database, action: Update
    00> <info> peer_manager_handler: Peer data updated in flash: peer_id: 0, data_id: Local database, action: Update
    00> <info> peer_manager_handler: Peer data updated in flash: peer_id: 0, data_id: Local database, action: Update
    00> <info> app: Disconnected. conn_handle: 0x0, reason 0x13.

    As a result, PM_EVT_CONN_SEC_CONFIG_REQ was done only when the central pairing information was deleted.

    I still don't know why I can't re-pair.
    If anyone can figure it out, please let me know!

  • Hi. 

    What you are seeing is to be expected. Re-pairing is used for when the peripheral already have a bond for the central that is trying to connect. If the bond information is deleted on the central device and tries to pair with the peripheral that already has a bond with the central, you can use the allow_repairing to either reject the request or update the bond with the peripheral.

    Using allow_repairing = false: 

    A connected peer (central) is trying to pair, but the Peer Manager already has a bond for that peer. Setting allow_repairing to false rejects the pairing request.
    re-paired when there is no pairing information for either peripheral or central.

    If there is no bonding information on either the peripheral or the central, there wouldn't be a reason to re-pair. Then you can simply pair the devices as normal. 

    Br, 
    Joakim

  • I didn't communicate it well, my apologies.

    When I said when disconnected, I meant when BLE_GAP_SEC_STATUS_PAIRING_NOT_SUPP occurs and disconnection occurs.

    Central (phone) does not remember pairing information because it is manually deleted.
    This is because it wants to perform a re-pairing action.

    Thank you in advance for your cooperation.

  • Hello.

    I have re-logged the re-pairing.
    I have changed the log level to Debug to output a more detailed log.
    Can you tell the cause of the error from this information?

    00> <debug> nrf_sdh_ble: BLE event: 0x10.
    00> <debug> peer_manager_handler: Event PM_EVT_BONDED_PEER_CONNECTED
    00> <debug> peer_manager_handler: Previously bonded peer connected: role: Peripheral, conn_handle: 0, peer_id: 0
    00> <debug> peer_manager_handler: Event PM_EVT_CONN_SEC_PARAMS_REQ
    00> <debug> peer_manager_handler: Security parameter request
    00> <debug> peer_manager_handler: Event PM_EVT_PEER_DATA_UPDATE_SUCCEEDED
    00> <info> peer_manager_handler: Peer data updated in flash: peer_id: 0, data_id: Peer rank, action: Update, no change
    00> <debug> peer_manager_handler: Event PM_EVT_LOCAL_DB_CACHE_APPLIED
    00> <debug> peer_manager_handler: Previously stored local DB applied: conn_handle: 0, peer_id: 0
    00> <info> app: Connected, handle 0x0.
    00> <debug> nrf_sdh_ble: BLE event: 0x21.
    00> <info> app: PHY update request.
    00> <debug> nrf_sdh_ble: BLE event: 0x22.
    00> <debug> nrf_sdh_ble: BLE event: 0x23.
    00> <debug> nrf_ble_gatt: Peer on connection 0x0 requested a data length of 251 bytes.
    00> <debug> nrf_ble_gatt: Updating data length to 27 on connection 0x0.
    00> <debug> nrf_sdh_ble: BLE event: 0x24.
    00> <debug> nrf_ble_gatt: Data length updated to 27 on connection 0x0.
    00> <debug> nrf_ble_gatt: max_rx_octets: 27
    00> <debug> nrf_ble_gatt: max_tx_octets: 27
    00> <debug> nrf_ble_gatt: max_rx_time: 2120
    00> <debug> nrf_ble_gatt: max_tx_time: 2120
    00> <debug> nrf_sdh_ble: BLE event: 0x55.
    00> <debug> nrf_ble_gatt: Peer on connection 0x0 requested an ATT MTU of 185 bytes.
    00> <debug> nrf_ble_gatt: Updating ATT MTU to 23 bytes (desired: 23) on connection 0x0.
    00> <debug> nrf_sdh_ble: BLE event: 0x50.
    00> <debug> nrf_sdh_soc: SoC event: 0x2.
    00> <debug> nrf_sdh_soc: SoC event: 0x2.
    00> <debug> nrf_sdh_soc: SoC event: 0x2.
    00> <debug> nrf_sdh_soc: SoC event: 0x2.
    00> <debug> nrf_sdh_soc: SoC event: 0x2.
    00> <debug> peer_manager_handler: Event PM_EVT_PEER_DATA_UPDATE_SUCCEEDED
    00> <info> peer_manager_handler: Peer data updated in flash: peer_id: 0, data_id: Local database, action: Update
    00> <debug> nrf_sdh_soc: SoC event: 0x2.
    00> <debug> nrf_sdh_soc: SoC event: 0x2.
    00> <debug> nrf_sdh_soc: SoC event: 0x2.
    00> <debug> nrf_sdh_soc: SoC event: 0x2.
    00> <debug> nrf_sdh_soc: SoC event: 0x2.
    00> <debug> nrf_sdh_soc: SoC event: 0x2.
    00> <debug> nrf_sdh_soc: SoC event: 0x2.
    00> <debug> peer_manager_handler: Event PM_EVT_FLASH_GARBAGE_COLLECTED
    00> <debug> peer_manager_handler: Flash garbage collection complete.
    00> <debug> nrf_sdh_ble: BLE event: 0x13.
    00> <debug> peer_manager_handler: Event PM_EVT_CONN_SEC_START
    00> <debug> peer_manager_handler: Connection security procedure started: role: Peripheral, conn_handle: 0, procedure: Bonding
    00> <debug> peer_manager_handler: Event PM_EVT_CONN_SEC_PARAMS_REQ
    00> <debug> peer_manager_handler: Security parameter request
    00> <debug> peer_manager_handler: Event PM_EVT_CONN_SEC_CONFIG_REQ
    00> <debug> peer_manager_handler: Security configuration request
    00> <info> app: PM_EVT_CONN_SEC_CONFIG_REQ
    00> <debug> nrf_sdh_ble: BLE event: 0x19.
    00> <debug> peer_manager_handler: Event PM_EVT_CONN_SEC_FAILED
    00> <info> peer_manager_handler: Connection security failed: role: Peripheral, conn_handle: 0x0, procedure: Bonding, error: 133
    00> <debug> peer_manager_handler: Error (decoded): BLE_GAP_SEC_STATUS 0x85
    00> <info> app: Connection Security Failed. procedure: 0x1, error: 0x85, error_src: 0x0.
    00> <info> app: No Bonding Infomation for Central.
    00> <debug> nrf_sdh_ble: BLE event: 0x50.
    00> <debug> nrf_sdh_soc: SoC event: 0x2.
    00> <debug> nrf_sdh_soc: SoC event: 0x2.
    00> <debug> nrf_sdh_soc: SoC event: 0x2.
    00> <debug> nrf_sdh_soc: SoC event: 0x2.
    00> <debug> nrf_sdh_soc: SoC event: 0x2.
    00> <debug> peer_manager_handler: Event PM_EVT_PEER_DATA_UPDATE_SUCCEEDED
    00> <info> peer_manager_handler: Peer data updated in flash: peer_id: 0, data_id: Local database, action: Update
    00> <debug> nrf_sdh_soc: SoC event: 0x2.
    00> <debug> nrf_sdh_soc: SoC event: 0x2.
    00> <debug> nrf_sdh_soc: SoC event: 0x2.
    00> <debug> nrf_sdh_soc: SoC event: 0x2.
    00> <debug> nrf_sdh_soc: SoC event: 0x2.
    00> <debug> nrf_sdh_soc: SoC event: 0x2.
    00> <debug> nrf_sdh_soc: SoC event: 0x2.
    00> <debug> peer_manager_handler: Event PM_EVT_FLASH_GARBAGE_COLLECTED
    00> <debug> peer_manager_handler: Flash garbage collection complete.
    00> <debug> nrf_sdh_ble: BLE event: 0x50.
    00> <debug> nrf_sdh_soc: SoC event: 0x2.
    00> <debug> nrf_sdh_soc: SoC event: 0x2.
    00> <debug> nrf_sdh_soc: SoC event: 0x2.
    00> <debug> nrf_sdh_soc: SoC event: 0x2.
    00> <debug> nrf_sdh_soc: SoC event: 0x2.
    00> <debug> peer_manager_handler: Event PM_EVT_PEER_DATA_UPDATE_SUCCEEDED
    00> <info> peer_manager_handler: Peer data updated in flash: peer_id: 0, data_id: Local database, action: Update
    00> <debug> nrf_sdh_soc: SoC event: 0x2.
    00> <debug> nrf_sdh_soc: SoC event: 0x2.
    00> <debug> nrf_sdh_soc: SoC event: 0x2.
    00> <debug> nrf_sdh_soc: SoC event: 0x2.
    00> <debug> nrf_sdh_soc: SoC event: 0x2.
    00> <debug> nrf_sdh_soc: SoC event: 0x2.
    00> <debug> nrf_sdh_soc: SoC event: 0x2.
    00> <debug> peer_manager_handler: Event PM_EVT_FLASH_GARBAGE_COLLECTED
    00> <debug> peer_manager_handler: Flash garbage collection complete.
    00> <debug> nrf_sdh_ble: BLE event: 0x50.
    00> <debug> nrf_sdh_soc: SoC event: 0x2.
    00> <debug> nrf_sdh_soc: SoC event: 0x2.
    00> <debug> nrf_sdh_soc: SoC event: 0x2.
    00> <debug> nrf_sdh_soc: SoC event: 0x2.
    00> <debug> nrf_sdh_soc: SoC event: 0x2.
    00> <debug> peer_manager_handler: Event PM_EVT_PEER_DATA_UPDATE_SUCCEEDED
    00> <info> peer_manager_handler: Peer data updated in flash: peer_id: 0, data_id: Local database, action: Update
    00> <debug> nrf_sdh_soc: SoC event: 0x2.
    00> <debug> nrf_sdh_soc: SoC event: 0x2.
    00> <debug> nrf_sdh_soc: SoC event: 0x2.
    00> <debug> nrf_sdh_soc: SoC event: 0x2.
    00> <debug> nrf_sdh_ble: BLE event: 0x50.
    00> <debug> nrf_sdh_soc: SoC event: 0x2.
    00> <debug> nrf_sdh_soc: SoC event: 0x2.
    00> <debug> nrf_sdh_soc: SoC event: 0x2.
    00> <debug> peer_manager_handler: Event PM_EVT_FLASH_GARBAGE_COLLECTED
    00> <debug> peer_manager_handler: Flash garbage collection complete.
    00> <debug> nrf_sdh_ble: BLE event: 0x11.
    00> <info> app: Disconnected. conn_handle: 0x0, reason 0x13.

    Best regards and thank you in advance for your help.

  • Thanks!

    Before looking at your logs, I tested this in an example myself, to check if I would reproduce the issue. 

    static void pm_evt_handler(pm_evt_t const * p_evt)
    {
        pm_handler_on_pm_evt(p_evt);
        pm_handler_disconnect_on_sec_failure(p_evt);
        pm_handler_flash_clean(p_evt);
    
        pm_conn_sec_config_t conn_sec_config;
    
        switch (p_evt->evt_id)
        {
            case PM_EVT_PEERS_DELETE_SUCCEEDED:
                advertising_start(false);
                break;
            
            case PM_EVT_CONN_SEC_CONFIG_REQ:
                conn_sec_config.allow_repairing = true;
                pm_conn_sec_config_reply(m_conn_handle, &conn_sec_config);
                break;
    
            default:
                break;
        }
    }

    Paired the device to my phone. Then I deleted the bond on the central (phone) side, and tried to re-pair. Works as expected. 

    BR, 
    Joakim

  • Hello.
    Sorry for the late reply.

    I found the reason why my code did not re-pair.
    When PM_EVT_CONN_SEC_CONFIG_REQ occurred, it was not processed in the event handler, but was stored as a task and processed after some time had passed.

    As you taught us, we implemented PM_EVR_CONN_SEC_CONFIG_REQ and were able to re-pair.

    Thank you!

Reply Children
No Data
Related