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

Scan with whitelist vs. scan filtering

Hello,
    i have a trouble that stock me several days, i'm using sdk15.2 on nrf52840, and i want to do scanning using whitelist, please help me, here is the situation.


    i have several peripheral peers and one peer with multiroles(central and peripheral at same time), i want to make this multiroles peer do scanning with whitelist to connect with these

peripherals.


my questions:


    1. what's the difference between scan addr filter and whitelist? if i use a whitelist, i don't need to set scan filter?


    2. i want to add a mac addr to whitelist, i want to use pm_whitelist_set(), but it only takes peer id and peer count as parameters(i delete all the peers before), what should i do?

  • what's the difference between scan addr filter and whitelist?

    Whitelisting is filtering that happens in the SoftDevice and filters devices based on their address while scan filtering happens on a higher layer of abstraction, specifically in the nrf_ble_scan.c library. Scan filtering performs filtering based on names, short names, addresses, UUIDs and appearance.

    The whitelist is set through the SVCALL sd_ble_gap_whitelist_set(..), where you provide a struct containing the address and an indication if the address is resolved using an IRK (read about IRK here). If you want to whitelist a device advertising with an address of type Public or Random Static, then the address doesn't need to be resolved and the IRK is not needed. However, if the address is of the type Random Private Resolvable, it needs to be resolved. I would recommend you to take a look at the BLE Heart Rate Collector Example where whitelisting is implemented using the Peer Manager and the ID Manager libraries. When you set a whitelist in the SoftDevice for a scanning device, the SoftDevice will perform filtering on the incoming advertising packets, and forward those packets that passes the filtering to the application. Thus, you will only see the advertising packets from addresses in the whitelist.

    A scan filter can be set using the function nrf_ble_scan_filter_set(..) in the nrf_ble_scan library, and you can perform filtering based on these types:

    • Names
    • Short names
    • Addresses
    • UUID's
    • Appearance

    Unlike whitelisting, all the advertising packets will be forwarded to the application from the SoftDevice. Down below I am showing the "route" that an advertising packet follows when using scan filtering:

    1. The SoftDevice receives an advertising packet and forwards it to the application
    2. The function nrf_ble_scan_on_ble_evt() in nrf_ble_scan.c receives the packet (Since the function is set as an observer through NRF_SDH_BLE_OBSERVER)
    3. The case BLE_GAP_EVT_ADV_REPORT gets triggered and nrf_ble_scan_on_adv_report(..) is called
      1. If whitelisting is used, the scan filter is not checked and function nrf_ble_scan_connect_with_target(..) is called
      2. Otherwise it will check if the filter match (based on the filters set through nrf_ble_scan_filter_set(..)) and run nrf_ble_scan_connect_with_target() in case of a match
    4.  Eventually the connection event will be forwarded to the application to the event handler set through nrf_ble_scan_init()

    I would recommend you to take a look at the BLE App UART Central example, which performs filtering using the nrf_ble_scan Iibrary. 

     

    if i use a whitelist, i don't need to set scan filter?

     As I mentioned above in point 1.a, there is no point of settting a scan filter if you are using a whitelist, since the function will return and not check the scan filter at all. Look at the top of the function nrf_ble_scan_on_adv_report(..) in the nrf_ble_scan library. You should read the explanation above, understand the difference between the two filtering mechanisms, and pick the one that fits your application.

     

    want to add a mac addr to whitelist, i want to use pm_whitelist_set(), but it only takes peer id and peer count as parameters(i delete all the peers before), what should i do?

     The function pm_whitelist_set() will set the whitelist based on the peers stored in flash, and if you delete all the peers before running the function, there are no devices to put into the whitelist. When you bond with a device the peer is stored in flash, it allocates a peer ID and stores the bonding data (address, IRK and encryption keys) of the new device to flash.

    Best regards,

    Simon

  • nrf_ble_scan_filter_set(..) where this function comes in ble_app_uart central example

  • It is inside the function scan_init(..) 

    Best regards,

    Simon

Related