nrf52832 whitelist

Hi,

I have a question about the whitelist,when we use the function "pm_whitelist_set()" to set the whitelist,whether the whitelist is stored in RAM or FLASH? I traced the function "pm_whitelist_set()" and its bottom layer called another function "sd_ble_gap_whitelist_set()",and the "sd_ble_gap_whitelist_set()"  function does not mention where the whitelist is stored,so i have this question.

And at the same time,the example about whitelist has the following function:

If whitelist is enabled, the whitelist setting function will be called each time a "scan_start()" is called,so if whitelist is stored in FLASH,frequent flash writing will speed up flash damage,thus the whitelist must be read and compared before setting.

  • Hi,

    Setting a whitelist does not involve any writes to flash. Specifically, the whitelist is generated based on bonding information, which is stored in the flash. However, this only involves reading data from flash. There is no writing involved here. Also, when setting the whitelist with the sd_ble_gap_whitelist_set() function, this only stores the whitelist in the SoftDevice RAM. In fact, the SoftDevice never writes to flash.

  • Hi,

    Thank you very much, your answer successfully solved my doubts, and also let me know more about the mechanism of the whitelist.

    I ran into another problem when I actually debugged the program,the system reset after "pm_whitelist_set()" and "APP_ERROR_CHECK()" the function is as follows:

    I guess the problem is probably caused by the return value of BLE_GAP_ERROR_WHITELIST_IN_USE,but I didn't find the definition of BLE_GAP_ERROR_WHITELIST_IN_USE in the whole project,should I clear the whitelist first before setting it or is there a better way?

    In addition, there is no problem in calling the above functions when the system is just powered on, but after calling the “scan_start()"  function multiple times, it will cause the system to restart.

  • Hi,

    Which error code code (as number) do you get - just to confirm? The BLE_ERROR_GAP_WHITELIST_IN_USE error (which API documentation unfortunately refers to as BLE_GAP_ERROR_WHITELIST_IN_USE) is returned if a whitelist is already in use, which typically means that you are currently scanning or advertising using a whitelist. That must be stopped before you can update the whitelist.

  • Hi,

    Thank you for your reply, it will give me more confidence to solve the various problems I encounter,following your prompt, I added the output of the error log.

    this is my code:

    static void whitelist_load()
    {
    ret_code_t ret,ret_last=NRF_SUCCESS;
    pm_peer_id_t peers[8];
    uint32_t peer_cnt,cnt1=1,cnt2=1;

    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);

    ret = pm_whitelist_set(peers, peer_cnt);
    while(ret!=NRF_SUCCESS)
    {
    if(ret!=ret_last)
    {
    NRF_LOG_INFO("the ret error code is : 0x%08X",ret);
    ret_last=ret;
    }
    nrf_ble_scan_stop();
    nrf_delay_ms(1);
    cnt1+=1;
    ret = pm_whitelist_set(peers, peer_cnt);
    }
    APP_ERROR_CHECK(ret);

    ret_last=NRF_SUCCESS;
    // Setup the device identies list.
    // Some SoftDevices do not support this feature.
    ret = pm_device_identities_list_set(peers, peer_cnt);
    while((ret!=NRF_SUCCESS) && (ret!=NRF_ERROR_NOT_SUPPORTED))
    {
    if(ret!=ret_last)
    {
    NRF_LOG_INFO("the ret error code is : 0x%08X",ret);
    ret_last=ret;
    }
    nrf_ble_scan_stop();
    nrf_delay_ms(1);
    cnt2+=1;
    ret = pm_device_identities_list_set(peers, peer_cnt);
    }
    if (ret != NRF_ERROR_NOT_SUPPORTED)
    {
    APP_ERROR_CHECK(ret);
    }

    NRF_LOG_INFO("whitelist set cnt : %d , identities list set cnt : %d",cnt1,cnt2);
    }

    and this is the log:

    <info> BLE_M: Disconnected. conn_handle: 0x0, reason: 0x13

    <info> BLE_M: whitelist set cnt : 1 , identities list set cnt : 1

    <info> BLE_M: the ret error code is : 0x00003203

    <info> BLE_M: Connection 0x0 established, starting DB discovery.

    <info> BLE_M: whitelist set cnt : 1 , identities list set cnt : 1

    <info> BLE_M: the ret error code is : 0x00003204

    <info> BLE_M: whitelist set cnt : 1013 , identities list set cnt : 2

    <info> BLE_M: Disconnected. conn_handle: 0x0, reason: 0x13

    <info> BLE_M: whitelist set cnt : 1 , identities list set cnt : 1

    <info> BLE_M: Connection 0x0 established, starting DB discovery.

    <info> BLE_M: whitelist set cnt : 1 , identities list set cnt : 1

    <info> BLE_M: Battery Level read as 82 %

    I think that I called the "scan_start()"  function at the wrong time, so that the previous execution of "whitelist_load()"  has not ended, and the other call to "whitelist_load()"  is executed immediately, resulting in the above error, which should be a timing collision problem.

    I may need a queue or a lock so that the execution of  "whitelist_load()"  is not interrupted.

  • Hi,

    Yes, that makes sense. I also see you get a BLE_ERROR_GAP_DEVICE_IDENTITIES_IN_USE error (0x00003204) which is returned from sd_ble_gap_device_identities_set() in the same situations.

Related