Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

[Bug report] nrf_ble_scan filter bugs

I have two bugs to report in
nRF5_SDK_16.0.0_98a08e2\components\ble\nrf_ble_scan\nrf_ble_scan.c

The following functions in nrf_ble_scan.c follow a pattern
nrf_ble_scan_addr_filter_add
nrf_ble_scan_name_filter_add
nrf_ble_scan_short_name_filter_add
nrf_ble_scan_uuid_filter_add
nrf_ble_scan_appearance_filter_add

After validating inputs and checking there is room to add the filter the functions then check whether the filter to be added is already present in the filter table. If it is then no new filter is added and the NRF_SUCCESS code is returned. However, the code for iterating through the filters checks the entire filter table rather than just the number of table items that have already been added. If the new filter happens to match table entries beyond those already added then the new filter won't be added and no filtering will be done on it despite the NRF_SUCCESS code being returned

For example, in the nrf_ble_scan_addr_filter_add() function the following line
    for (index = 0; index < NRF_BLE_SCAN_ADDRESS_CNT; index++)
should be
    for (index = 0; index < *p_counter; index++)

The second bug is in the nrf_ble_scan_uuid_filter_add() function. The test within the loop is
    if (p_uuid_filter[index].uuid == p_uuid->uuid)
but this ignores the p_uuid->type member. The code assumes that only BLE-defined UUIDs will be used. It should use the more comprehensive test done in the adv_uuid_compare() function.

Related