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

How do I implement an address filter?

I am very new to BLE development, and am building my application on top of the ble_central\ble_app_uart_c example.

I have this tag defined at the start, with the other global variable definitions.

#define NRF_BLE_SCAN_ADDR_FILTER 0x02

This is the function where I am initializing the module: 

/**
 * @brief Parameters used when scanning.
 */
static const ble_gap_scan_params_t m_scan_params =
{
    .active   = 1,
    .interval = SCAN_INTERVAL,
    .window   = SCAN_WINDOW,
    .timeout  = SCAN_TIMEOUT,
    #if (NRF_SD_BLE_API_VERSION == 2)
        .selective   = 0,
        .p_whitelist = NULL,
    #endif
    #if (NRF_SD_BLE_API_VERSION == 3)
        .use_whitelist = 0,
    #endif
};
 

I am calling the module (or setting the filter, unsure of the terminology) here in the scan_start() function:

/**
 * @brief Parameters used when scanning.
 */
static const ble_gap_scan_params_t m_scan_params =
{
    .active   = 1,
    .interval = SCAN_INTERVAL,
    .window   = SCAN_WINDOW,
    .timeout  = SCAN_TIMEOUT,
    #if (NRF_SD_BLE_API_VERSION == 2)
        .selective   = 0,
        .p_whitelist = NULL,
    #endif
    #if (NRF_SD_BLE_API_VERSION == 3)
        .use_whitelist = 0,
    #endif
};

The scan_start() function is called in main(). I have not yet tested this implementation as it is unfinished.

My questions around this are:

  1. Where do I set the address I want to filter for? It merely advertises and I can't connect to it.
  2. Once the address is set, is this implementation correct?

Thank you!

Parents
  • Hello,

    Thanks again, if I have time today I will try to implement the sniffer. :)

    I am away from my laptop at the moment, but when I get back I will check for the library and declare the address pointer. I have checked other examples and am still unclear. This is how I have it currently (haven't tested as I am away from laptop).

    Static const hex * im21_addr = {0xc6, 0x6b, 0x58, 0x7b, 0xf2, 0x69}

    Is this correct?

    Thanks!!

  • Hello,

    panda_noob_2000 said:
    Thanks again, if I have time today I will try to implement the sniffer. :)

    Great! Please do not hesitate to open a new ticket if you should encounter any issues or questions about the sniffer installation or produced sniffer traces - then we'll handle that separately in the dedicated ticket.

    panda_noob_2000 said:

    I am away from my laptop at the moment, but when I get back I will check for the library and declare the address pointer. I have checked other examples and am still unclear. This is how I have it currently (haven't tested as I am away from laptop).

    Static const hex * im21_addr = {0xc6, 0x6b, 0x58, 0x7b, 0xf2, 0x69}

    Is this correct?

    No, this is not quite right. The address should be written as an LSB uint8_t array, and be incorporated into a ble_gap_addr_t structure, before passing the ble_gap_addr_t structure to the filter set function. Something like this, or similar:

    ble_gap_addr_t LOCK_ADDRESS = {0,BLE_GAP_ADDR_TYPE_RANDOM_STATIC,{0xAA,0xBB,0xCC,0xDD,0xEE,0xFF}};


    panda_noob_2000 said:
    Static const hex * im21_addr = {0xc6, 0x6b, 0x58, 0x7b, 0xf2, 0x69}

    For future reference I thought I should also mention: There is not 'hex' type or keyword in C, since this is just a way of writing numbers - it does not say anything about how much memory a 'hex' type will need (which is why types is so important in C). The compiler reads the values as hex when they start with 0x, similarly you could write things as binary using the prefix 0b. 
    Furthermore, in C, the variable for an array will always be the pointer to the first element of the array, so in your line here you are making a pointer to the array pointer, since you are write
    * addr = {} . Please let me know if any part of this should still be unclear, so I may try to articulate it better.

    Best regards,
    Karl

Reply
  • Hello,

    panda_noob_2000 said:
    Thanks again, if I have time today I will try to implement the sniffer. :)

    Great! Please do not hesitate to open a new ticket if you should encounter any issues or questions about the sniffer installation or produced sniffer traces - then we'll handle that separately in the dedicated ticket.

    panda_noob_2000 said:

    I am away from my laptop at the moment, but when I get back I will check for the library and declare the address pointer. I have checked other examples and am still unclear. This is how I have it currently (haven't tested as I am away from laptop).

    Static const hex * im21_addr = {0xc6, 0x6b, 0x58, 0x7b, 0xf2, 0x69}

    Is this correct?

    No, this is not quite right. The address should be written as an LSB uint8_t array, and be incorporated into a ble_gap_addr_t structure, before passing the ble_gap_addr_t structure to the filter set function. Something like this, or similar:

    ble_gap_addr_t LOCK_ADDRESS = {0,BLE_GAP_ADDR_TYPE_RANDOM_STATIC,{0xAA,0xBB,0xCC,0xDD,0xEE,0xFF}};


    panda_noob_2000 said:
    Static const hex * im21_addr = {0xc6, 0x6b, 0x58, 0x7b, 0xf2, 0x69}

    For future reference I thought I should also mention: There is not 'hex' type or keyword in C, since this is just a way of writing numbers - it does not say anything about how much memory a 'hex' type will need (which is why types is so important in C). The compiler reads the values as hex when they start with 0x, similarly you could write things as binary using the prefix 0b. 
    Furthermore, in C, the variable for an array will always be the pointer to the first element of the array, so in your line here you are making a pointer to the array pointer, since you are write
    * addr = {} . Please let me know if any part of this should still be unclear, so I may try to articulate it better.

    Best regards,
    Karl

Children
No Data
Related