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

How to add bonding information manually?

Hi,

I want to add bonding information manually. 

1.can I assume IRK key will be constant for multiple peripherals?

2.if IRK only key is available, can i add it to peer list using pm_peer_new? 

 

  • I am not talking about advertising. I want to add a device(whose IRK is known) to a whitelist  in peripheral device.

  • If I'm not understanding you correctly, you need to explain in detail what exactly you're trying to achieve. I'm trying to help you, but if I don't understand what it is you're trying to do, guessing my way there makes it very hard (for both of us) to resolve this.

    I'll try again then. To add the IRK address of a device in any whitelist, you need to add the IRK to the identity list using sd_ble_gap_device_identities_set(), then call sd_ble_gap_whitelist_set() to set that whitelist.

    However, if you use the peer manager, this will also manipulate this list, and if you do, you may want to add this IRK via the peer manager API. Most SDK examples that use whitelisting use something like the code snippet below to do so when handling the BLE_ADV_EVT_WHITELIST_REQUEST, although that is based on having the bonding information:

    static void whitelist_load()
    {
        ret_code_t   ret;
        pm_peer_id_t peers[8];
        uint32_t     peer_cnt;
    
        memset(peers, PM_PEER_ID_INVALID, sizeof(peers));
        peer_cnt = (sizeof(peers) / sizeof(pm_peer_id_t));
    
        // Load all peers from the flash and whitelist them.
        peer_list_get(peers, &peer_cnt);
    
        ret = pm_whitelist_set(peers, peer_cnt);
        APP_ERROR_CHECK(ret);
    
        // Set up the list of device identities.
        // Some SoftDevices do not support this feature.
        ret = pm_device_identities_list_set(peers, peer_cnt);
        if (ret != NRF_ERROR_NOT_SUPPORTED)
        {
            APP_ERROR_CHECK(ret);
        }
    }
    
    
    static void on_whitelist_req(void)
    {
        ret_code_t     err_code;
    
        // Whitelist buffers.
        ble_gap_addr_t whitelist_addrs[8];
        ble_gap_irk_t  whitelist_irks[8];
    
        memset(whitelist_addrs, 0x00, sizeof(whitelist_addrs));
        memset(whitelist_irks,  0x00, sizeof(whitelist_irks));
    
        uint32_t addr_cnt = (sizeof(whitelist_addrs) / sizeof(ble_gap_addr_t));
        uint32_t irk_cnt  = (sizeof(whitelist_irks)  / sizeof(ble_gap_irk_t));
    
        // Reload the whitelist and whitelist all peers.
        whitelist_load();
    
        // Get the whitelist previously set using pm_whitelist_set().
        err_code = pm_whitelist_get(whitelist_addrs, &addr_cnt,
                                    whitelist_irks,  &irk_cnt);
        APP_ERROR_CHECK(err_code);
    
        if (((addr_cnt == 0) && (irk_cnt == 0)) ||
            (m_whitelist_disabled))
        {
            // Don't use whitelist
            err_code = nrf_ble_scan_params_set(&m_scan, NULL);
            APP_ERROR_CHECK(err_code);
            NRF_LOG_INFO("Starting scan.");
        }
        else
        {
            // Use whitelist.
            NRF_LOG_INFO("Starting scan with whitelist.");
        }
    
        bsp_board_led_on(CENTRAL_SCANNING_LED);
    }

    Another option is to hardcode it. If so you can refer to this example which uses a slightly modified peer manager example for getting an existing bond and rewriting it.

    ble_app_hrs_sidechannel_bonding.zip

    Best regards,

    Simon

  • Ok. I have to get peer list and set it to whitelist. But I don't have peer list. How to create and add a peer with irk

  • Surya said:
    How to create and add a peer with irk

     In which device would you like to add a peer with IRK. Please help me help you by being a bit more specific in your replies. 

    Best regards,

    Simon

  • In which device would you like to add a peer with IRK. Please help me help you by being a bit more specific in your replies. 

    I have been talking only about peripheral from starting onwards.

    anyway, if you confused, is adding "a peer with IRK " differ from device to device (whether central or peripheral) ?

    or you mean That I was trying to add IRK of a device to its own whitelist?

    I want to add a peer to a peripheral which is not bonded and IRK of some X device is known to it.

Related