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? 

 

  • memcpy(&(whitelist_irks[0].irk),&(bond_info.peer_ble_id.id_info.irk),16);

    you said that the above line has few invalid parameters, but not telling what are they.

    I am coping IRK key from prepopulated structure of bonding information. and I verified IRK is copied correctly by bonding and comparing with another 52810 with mobile.

  • Hi

    I'm sorry, but it's hard to tell which parameters exactly are invalid here, all I can tell is that the error you're seeing is due to invalid parameters in this call. But I don't see why you need to copy the IRK like this, and not set it to your custom valueby changing the pointer used to point to the IRK you'd like to use.

    Best regards,

    Simon

  • I'm sorry, but it's hard to tell which parameters exactly are invalid here,

    I am coping Only IRK key. is there any parameters in IRK?

    But I don't see why you need to copy the IRK like this,

    Yes, but is it wrong?

    I am just prepopulating a bonding info structure and coping IRK key from it.

    our discussion is not even going towards a solution. what you want me to do?

    whitelist_irks[0] = {IRK}; is ok ? returned same error

    or  passing pointer to IRK to the function "ble_advertising_whitelist_reply" returned the same error.

    err_code = ble_advertising_whitelist_reply(&m_advertising,whitelist_addrs,addr_cnt,whitelist_irks,irk_cnt);
    APP_ERROR_CHECK(err_code);

    if error comes in the line you mentioned, why it is not being detected? is there any bug in SDK that 

    "ble_advertising_whitelist_reply"  can't detect Invalid parameters? which is later detected while starting advertising by  "ble_advertising_start()".

  • 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

  • fetching peer ids will returns PM_PEER_ID_INVALID as o bonding is done.

    with only IRK information how to add peer to peer_list?

Related