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

Simple whitelisting How-To

I am really puzzled by this and although I've read all the relevant answers in the Q/A I'm still unable to do the following:

  • do non-selective scanning with central device
  • accept the first peripheral device (which has the service I need) and add it to whitelist
  • after central restart load the whitelist and do selective scanning

What I want to achieve with this is that only one peripheral can be connected to central. I understand I need to limit how large the whitelist is - in my case 1.

For this discussion let us all review the ble_app_uart_c example which seems like it implements whitelist (I can't get it to work though - peripheral got connected, then after central restart, whitelist is empty hence it goes into non-selective scannign again).


My question (related to example):

  • after non-selective scanning where exactly is the device address stored to whitelist and saved to flash?

In the example in function scan_start() I can see the whitelist gets created with dm_whitelist_create() but does this function load the whitelist from flash? This would be necessary so selective scanning would be working (after a peripheral's address was added to whitelist in non-selective scanning in previous power-cycle).

  • is the example missing anything which would prevent it from working with whitelist?
  • Hi Primož,

    The dm_whitelist_create() create the whitelist based on the bond information database stored by device manager. The device manager only store bond information (including the public address or the IRK for random resolveable address) when bonded. This happens when BLE_GAP_EVT_AUTH_STATUS event comes. You can find in device_manager_central.c we call device_context_store() when we receive this event.

    The reason the whitelist was blank when you restart ble_app_uart_c example was that you didn't bond with the device. If you don't plan to bond but still want to have whitelist. You have to manage the whitelist manually. Here you can find an example of how to do it manually (this is for whitelist with advertising but it should be the same for scanning).

  • Hi Primoz,

    You would need to call dm_security_setup_req() to tell the device manager on the central to start bonding process. Set SEC_PARAM_BOND to 1 only set the security parameter in the stack that you allow bonding.

    I would suggest you to test with the ble_app_hrs_c in our SDK v10. In that example bonding is triggered when we receive DM_EVT_CONNECTION event.

    The ble_app_uart_c on github is just an example we made (quite long ago) for demonstration and it is not maintained and get updated as good as the examples in the SDK.

  • This is the answer I was looking for! Thank you so much, I got it to work now.

Related