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? 

 

Parents
  • Hi again

    I would like you to try adding the IRK to your advertisement as described in the Using a Whitelist section in the Peer Manager library, by first setting the whitelist in the peer manager, and then retrieving this whitelist and provide it to the Advertising module to use it during advertising. When a whitelist is needed. I have provided the snippets for fetching the list of IDs from the peer manager below.

    {
        // Fetch a list of peer IDs from Peer Manager and whitelist them.
        pm_peer_id_t peer_ids[8] = {PM_PEER_ID_INVALID};
        uint32_t     n_peer_ids  = 0;
        pm_peer_id_t peer_id     = pm_next_peer_id_get(PM_PEER_ID_INVALID);
        while((peer_id != PM_PEER_ID_INVALID) && (n_peer_ids < 8))
        {
            peer_ids[n_peer_ids++] = peer_id;
            peer_id = pm_next_peer_id_get(peer_id);
        }
        // Whitelist peers.
        err_code = pm_whitelist_set(peer_ids, n_peer_ids);
        APP_ERROR_CHECK(err_code);
    }
    static void on_adv_evt(ble_adv_evt_t ble_adv_evt)
    {
        switch (ble_adv_evt)
        {
            ...
            case BLE_ADV_EVT_WHITELIST_REQUEST:
            {
                // When the Advertising module is about to advertise, an event
                // will be received by the application. In this event, the application
                // retrieves a whitelist from the Peer Manager, based on the peers
                // previously whitelisted using pm_whitelist_set().
                ret_code_t err_code;
                // Storage for the whitelist.
                ble_gap_irk_t  irks[8]  = {0};
                ble_gap_addr_t addrs[8] = {0};
                uint32_t irk_cnt  = 8;
                uint32_t addr_cnt = 8;
                err_code = pm_whitelist_get(addrs, &addr_cnt, irks, &irk_cnt);
                APP_ERROR_CHECK(err_code);
                // Apply the whitelist.
                err_code = ble_advertising_whitelist_reply(addrs, addr_cnt, irks, irk_cnt);
                APP_ERROR_CHECK(err_code);
            }
            ...
        }
    }

    It is strongly recommended to use the Peer Manager to manage BLE security, and not use custom calls for retrieving BLE related information.

    Best regards,

    Simon

Reply
  • Hi again

    I would like you to try adding the IRK to your advertisement as described in the Using a Whitelist section in the Peer Manager library, by first setting the whitelist in the peer manager, and then retrieving this whitelist and provide it to the Advertising module to use it during advertising. When a whitelist is needed. I have provided the snippets for fetching the list of IDs from the peer manager below.

    {
        // Fetch a list of peer IDs from Peer Manager and whitelist them.
        pm_peer_id_t peer_ids[8] = {PM_PEER_ID_INVALID};
        uint32_t     n_peer_ids  = 0;
        pm_peer_id_t peer_id     = pm_next_peer_id_get(PM_PEER_ID_INVALID);
        while((peer_id != PM_PEER_ID_INVALID) && (n_peer_ids < 8))
        {
            peer_ids[n_peer_ids++] = peer_id;
            peer_id = pm_next_peer_id_get(peer_id);
        }
        // Whitelist peers.
        err_code = pm_whitelist_set(peer_ids, n_peer_ids);
        APP_ERROR_CHECK(err_code);
    }
    static void on_adv_evt(ble_adv_evt_t ble_adv_evt)
    {
        switch (ble_adv_evt)
        {
            ...
            case BLE_ADV_EVT_WHITELIST_REQUEST:
            {
                // When the Advertising module is about to advertise, an event
                // will be received by the application. In this event, the application
                // retrieves a whitelist from the Peer Manager, based on the peers
                // previously whitelisted using pm_whitelist_set().
                ret_code_t err_code;
                // Storage for the whitelist.
                ble_gap_irk_t  irks[8]  = {0};
                ble_gap_addr_t addrs[8] = {0};
                uint32_t irk_cnt  = 8;
                uint32_t addr_cnt = 8;
                err_code = pm_whitelist_get(addrs, &addr_cnt, irks, &irk_cnt);
                APP_ERROR_CHECK(err_code);
                // Apply the whitelist.
                err_code = ble_advertising_whitelist_reply(addrs, addr_cnt, irks, irk_cnt);
                APP_ERROR_CHECK(err_code);
            }
            ...
        }
    }

    It is strongly recommended to use the Peer Manager to manage BLE security, and not use custom calls for retrieving BLE related information.

    Best regards,

    Simon

Children
Related