Hi,
I use SES IDE, nRF5_SDK_16.0.0, nRF52840 DKs. I am using ble_app_uart_c as a template for my application that needs to connect to multiple peripherals whose device names are "ABC_xxxx" where xxxx is peripheral device's serial number. I am trying to find a way to set a scan name filter so that my central device can connect to any peripheral whose name begins with "ABC_". I set NRF_BLE_SCAN_NAME_CNT= 8 and use SCAN_NAME_FILTER of "ABC_" in scan_init(). I found this function call stack in nrf_ble_scan.c: nrf_ble_scan_on_adv_report() -> adv_name_compare() -> ble_advdata_name_find() which compares advertised name and target name. I removed the original 'if' condition and used my own 'if' condition as seen below:
bool ble_advdata_name_find(uint8_t const * p_encoded_data,
uint16_t data_len,
char const * p_target_name)
{
uint16_t parsed_name_len;
uint8_t const * p_parsed_name;
uint16_t data_offset = 0;
if (p_target_name == NULL)
{
return false;
}
parsed_name_len = ble_advdata_search(p_encoded_data,
data_len,
&data_offset,
BLE_GAP_AD_TYPE_COMPLETE_LOCAL_NAME);
p_parsed_name = &p_encoded_data[data_offset];
// NAME FILTER COMPARE START
uint16_t target_name_len= strlen(p_target_name);
if(memcmp(p_target_name, p_parsed_name, target_name_len)== 0) // compare only target_name_len chars of advertised name and target name
/* // Dont compare entire p_parsed_name with p_target_name
if ( (data_offset != 0)
&& (parsed_name_len != 0)
&& (strlen(p_target_name) == parsed_name_len)
&& (memcmp(p_target_name, p_parsed_name, parsed_name_len) == 0)) // compare entire p_parsed_name
*/
// NAME FILTER COMPARE END
{
return true;
}
return false;
}
I observed that this works well for me. Is this the right way to set the kind of name filter I want or is there a better way to do it?
Thanks
-Kunal