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

About the number of saved bonding information

Hello.
I am developing using nrf52832 (S132 v7.0.1, SDK v16.0.0).

I use whitelist to store bonding information. Is there an upper limit to the number that can be stored?
Also, how can I set it to increase the number that can be saved?

If you have any materials, please let me know.
Please let us know if you have any questions.
Thank you.

  • Hi Kei, 

    You can have a look at the ble_app_hids_mouse as an example on how you can setup the whitelist for scanning/advertising. The function to setup the whitelist is whitelist_set(): 

    /**@brief Function for setting filtered whitelist.
     *
     * @param[in] skip  Filter passed to @ref pm_peer_id_list.
     */
    static void whitelist_set(pm_peer_id_list_skip_t skip)
    {
        pm_peer_id_t peer_ids[BLE_GAP_WHITELIST_ADDR_MAX_COUNT];
        uint32_t     peer_id_count = BLE_GAP_WHITELIST_ADDR_MAX_COUNT;
    
        ret_code_t err_code = pm_peer_id_list(peer_ids, &peer_id_count, PM_PEER_ID_INVALID, skip);
        APP_ERROR_CHECK(err_code);
    
        NRF_LOG_INFO("\tm_whitelist_peer_cnt %d, MAX_PEERS_WLIST %d",
                       peer_id_count + 1,
                       BLE_GAP_WHITELIST_ADDR_MAX_COUNT);
    
        err_code = pm_whitelist_set(peer_ids, peer_id_count);
        APP_ERROR_CHECK(err_code);
    }
    

    However this code will load all peers and it will be limited by BLE_GAP_WHITELIST_ADDR_MAX_COUNT = 8. 

    If you want to rotate the list, you would need to study the code a little bit and call pm_whitelist_set() so that it will switch between peer_ids. I haven't tried, but it may work this way: 
    First call: 
    err_code = pm_whitelist_set(peer_ids, 8);
    APP_ERROR_CHECK(err_code);

    Second call (after you scan for  a while) 

    err_code = pm_whitelist_set(peer_ids+sizeof(uint16_t)*8, 8);
    APP_ERROR_CHECK(err_code);

    And so on. I suggest to look deeper into the code of the peer manager to understand how the whitelist setting works. 

  • Hello.

    I'm considering rotating the list.
    I am trying to do pm_whitelist_set 1 second after setting with pm_whitelist_set. (Switch peer_ids)
    However, when I make the second call, I get a BLE_GAP_ERROR_WHITELIST_IN_USE error.
    I tried to clear the whitelist before setting, but I got the same error.

    Is there any countermeasure?

    Thank you.

  • Hi Kei, 


    Could you try to stop scanning (and advertising if you also do advertising) before you change the whitelist ? It's mentioned in the documentation of sd_ble_gap_whitelist_set() that "The whitelist cannot be set if a BLE role is using the whitelist."

  • Hello.

    Changed to do sd_ble_gap_scan_stop before doing pm_whitelist_set. Thanks to you, BLE_GAP_ERROR_WHITELIST_IN_USE no longer occurs.
    However, the second call now causes an NRF_ERROR_NOT_FOUND.

    I described the process of rotating with reference to whitelist_load of ble_app_gatts. The source code is as follows.

    Which part should I fix?

    Thank you.

    #define BLE_GAP_WHITELIST_ADDR_MAX_COUNT (1)
    static uint8_t whitelist_cnt;
    
    void whitelist_load(void)
    {
        ret_code_t   ret;
        pm_peer_id_t peers[BLE_GAP_WHITELIST_ADDR_MAX_COUNT];
        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 flash and whitelist them.
        peer_list_get(peers, &peer_cnt);
        
        if (whitelist_cnt >= pm_peer_count())
        {
            whitelist_cnt = 0;
        }
    
        ret = pm_whitelist_set(peers + (sizeof(uint16_t) * (BLE_GAP_WHITELIST_ADDR_MAX_COUNT * whitelist_cnt)), peer_cnt);
        APP_ERROR_CHECK(ret);
    
        // Setup the device identities list.
        // 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);
        }
    }

  • Hi Kei, 
    I don't really understand this part: 

    ret = pm_whitelist_set(peers + (sizeof(uint16_t) * (BLE_GAP_WHITELIST_ADDR_MAX_COUNT * whitelist_cnt)), peer_cnt);
    APP_ERROR_CHECK(ret);

    Could you explain ? What's the value of whitelist_cnt  ? and  peer_cnt ? 
    What's inside peer_list_get() ? 
    What you need to do is to feed the first 8 peers and then after that you feed the next 4 peers for example (if you have 12 peers in total). 
    What you do here with peer_cnt is just feed the whole 12 peers in at once which is not correct. 
    Please clearly show how you call the first whitelist set, and then how you call the second whitelist set. 

Related