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?

  • 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

  • Hello!
    Thanks for the answer!

    I have it set to true because I want to update the pairing request instead of rejecting it.

    For the central device only bonding information is being deleted, PM_EVT_CONN_SEC_CONFIG_REQ is being called, but it is being errored by BLE_GAP_SEC_STATUS_PAIRING_NOT_SUPP.

    Why am I getting an error even though I have set up an update?

    Also, you say that re-pairing is only done if the central does not have bonding information, how can I update it if the peripheral does not have bonding information?

    Best regards, and thank you in advance for your help.

  • I'll take a closer look at the error you get. 

    I would like to note that if you perform bonding; the best way to avoid this would be not to delete bond information upon disconnection. 

    Br, 
    Joakim

  • Thank you. Please confirm.

    This is because we currently do not delete bonding information when disconnecting.

    Best regards, and thank you in advance for your cooperation.

Related