MAC Address BLE scan filter not working

Hello all,

Currently I am developing a code in which a central (nRF52840) scans and reads adverisement packets from 2 beacons (no connection required). I decided to use an adress filter to limit the amount of advertisement data received; however, it seems that it is not working because:
1. I´m getting TONS of advertisement packets that don´t look similar to what I´m expecting.
2. The event NRF_BLE_SCAN_EVT_FILTER_MATCH is never triggered.

Below I´ll show you some key points of the code: 

Declarition of the target MAC address (AC:23:3F:A9:EF:E2)

static bool is_connect_per_addr = true;            /**< If you want to connect to a peripheral with a given address, set this to true and put the correct address in the variable below. */

static ble_gap_addr_t const m_target_periph_addr =
{
    /* Possible values for addr_type:
       BLE_GAP_ADDR_TYPE_PUBLIC,
       BLE_GAP_ADDR_TYPE_RANDOM_STATIC,
       BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_RESOLVABLE,
       BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_NON_RESOLVABLE. */
    //.addr_type = BLE_GAP_ADDR_TYPE_RANDOM_STATIC,
    .addr      = {0xE2, 0xEF, 0xA9, 0x3F, 0x23, 0xAC}
    //.addr      = {0x41, 0x8C, 0xFE, 0x05, 0x1C, 0x00}
};

Filters settings

static void scan_init(void)
{
    ret_code_t          err_code;
    nrf_ble_scan_init_t init_scan;

    //static char const test_periph_addr[] = {0xEA, 0xEF, 0xA9, 0x3F, 0x23, 0xAC};

    memset(&init_scan, 0, sizeof(init_scan));

    init_scan.p_scan_param     = &m_scan_param;
    init_scan.connect_if_match = true;
    init_scan.conn_cfg_tag     = APP_BLE_CONN_CFG_TAG;

    err_code = nrf_ble_scan_init(&m_scan, &init_scan, scan_evt_handler);
    APP_ERROR_CHECK(err_code);

    ble_uuid_t uuid =
    {
        .uuid = TARGET_UUID,
        .type = BLE_UUID_TYPE_VENDOR_BEGIN,
    };

    err_code = nrf_ble_scan_filter_set(&m_scan,
                                       SCAN_UUID_FILTER,
                                       &uuid);
    APP_ERROR_CHECK(err_code);

    if (strlen(m_target_periph_name) != 0)
    {
        err_code = nrf_ble_scan_filter_set(&m_scan,
                                           SCAN_NAME_FILTER,
                                           m_target_periph_name);
        APP_ERROR_CHECK(err_code);
    }

    if (is_connect_per_addr)
    {
       err_code = nrf_ble_scan_filter_set(&m_scan,
                                          SCAN_ADDR_FILTER,
                                          m_target_periph_addr.addr);
       APP_ERROR_CHECK(err_code);
    }

    err_code = nrf_ble_scan_filters_enable(&m_scan,
                                           NRF_BLE_SCAN_ALL_FILTER,
                                           false);
    APP_ERROR_CHECK(err_code);
}


ADV_REPORT EVENT

static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
{
    ret_code_t            err_code;
    ble_gap_evt_t const * p_gap_evt = &p_ble_evt->evt.gap_evt;

    switch (p_ble_evt->header.evt_id)
    {
        case BLE_GAP_EVT_ADV_REPORT:
            NRF_LOG_INFO("Advertisement report");
            //on_adv_report(&p_gap_evt->params.adv_report);

            //if( p_gap_evt->params.adv_report.direct_addr.addr == m_target_periph_addr.addr)
            //{    
            //    NRF_LOG_INFO("Found");
            //}

           
            uint8_t data_length = p_gap_evt->params.adv_report.data.len;
            NRF_LOG_INFO("Data length: %d", data_length);

            uint8_t i;

            for (i=0; i<=data_length; i++)
            {
                uint8_t data = p_gap_evt->params.adv_report.data.p_data[i];
                NRF_LOG_INFO("0x%02X", data);
            }

            break;

...


Thank you so much in advance

Parents
  • Hello,

    The peripheral looks to be using the private resolvable address type if I'm reading the address correctly.

    From the BT Core specification:

    In that case, you can't rely on the address to reliably identify the device you want to connect to (it may change at any time). Instead you may have to use other filters such as device name and UUID.

    ADV_REPORT EVENT

    The adv_report_event comes directly from the Softdevice and has not gone through the filtering implemented in the scanner module. NRF_BLE_SCAN_EVT_* events will be notified through your registered scan_evt_handler().

    Best regards,

    Vidar

Reply
  • Hello,

    The peripheral looks to be using the private resolvable address type if I'm reading the address correctly.

    From the BT Core specification:

    In that case, you can't rely on the address to reliably identify the device you want to connect to (it may change at any time). Instead you may have to use other filters such as device name and UUID.

    ADV_REPORT EVENT

    The adv_report_event comes directly from the Softdevice and has not gone through the filtering implemented in the scanner module. NRF_BLE_SCAN_EVT_* events will be notified through your registered scan_evt_handler().

    Best regards,

    Vidar

Children
No Data
Related