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

Periodically changing the MAC address on nRF51822 Beacon Kit

Hi,

I am able to change the MAC address of the beacon using the call sd_ble_gap_address_set(BLE_GAP_ADDR_CYCLE_MODE_NONE, &gap_addr), where gap_addr is of type BLE_GAP_ADDR_TYPE_RANDOM_STATIC.

Now what I want to do is to change the MAC address periodically, while the beacon is still advertising. From what I understand, I need to use sd_ble_gap_address_set(BLE_GAP_ADDR_CYCLE_MODE_AUTO, &gap_addr), with an address of type BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_RESOLVABLE. However, the MAC address seems to change only during the boot up and when the SW2 button is pressed (changes one when beacon goes into config mode and once when beacon switches back to advertising). I set the BLE_GAP_DEFAULT_PRIVATE_ADDR_CYCLE_INTERVAL_S to 5 to be able to observe the change. I am calling the sd_ble_gap_address_set function after ble_stack_init() call in the main function of the sample beacon app.

What should I do to achieve periodic change of MAC address? Can this be achieved with LE_GAP_ADDR_CYCLE_MODE_AUTO mode at all, or should I simply set up a timer, create random MAC address and call sd_ble_gap_address_set(BLE_GAP_ADDR_CYCLE_MODE_NONE, &gap_addr) every time timer expires?

Thanks for your help in advance.

Parents
  • Hi Sarah,

    The address should change even while advertising, so there is no need to set up any timers for this. Just to make sure: Are you calling sd_ble_opt_set() with gap_opt.privacy.interval_s set to 5, or just changing the define?

    To change the default address rotation time (15 minutes) you have to do something like this:

    ble_opt_t opt = {0};
    opt.gap_opt.privacy.interval_s = TIME_IN_SECONDS_HERE;
    err_code = sd_ble_opt_set(BLE_GAP_OPT_PRIVACY, &opt);
    APP_ERROR_CHECK(err_code);
    
  • Thanks so much for your answer, Ulrich. In SDK 7.1, sd_ble_opt_set() expects two arguments. One is an option id, the other one is the ble_opt_t structure. In my case, the opt id needs to be opt.gap_opt.privacy.interval_s . Is that right? I tried your code with that, and if I don't comment out APP_ERROR_CHECK(err_code) line, the beacon doesn't work. When I comment it out, it does work, but it doesn't seem to change the MAC id for the given interval. It seems to be changing randomly. Do you have any idea why? Below is how my code looks like now:

    void periodically_change_mac_address(){ ble_gap_addr_t gap_address; uint8_t err_code;

        // Change MAC update interval
    ble_opt_t opt = {0};
    opt.gap_opt.privacy.interval_s = 5;
    err_code = sd_ble_opt_set(opt.gap_opt.privacy.interval_s, &opt);
    //APP_ERROR_CHECK(err_code);
    
    // Change MAC address
    gap_address.addr_type = BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_RESOLVABLE;
    err_code = sd_ble_gap_address_set(BLE_GAP_ADDR_CYCLE_MODE_AUTO, &gap_address);
    APP_ERROR_CHECK(err_code);
    

    }

Reply
  • Thanks so much for your answer, Ulrich. In SDK 7.1, sd_ble_opt_set() expects two arguments. One is an option id, the other one is the ble_opt_t structure. In my case, the opt id needs to be opt.gap_opt.privacy.interval_s . Is that right? I tried your code with that, and if I don't comment out APP_ERROR_CHECK(err_code) line, the beacon doesn't work. When I comment it out, it does work, but it doesn't seem to change the MAC id for the given interval. It seems to be changing randomly. Do you have any idea why? Below is how my code looks like now:

    void periodically_change_mac_address(){ ble_gap_addr_t gap_address; uint8_t err_code;

        // Change MAC update interval
    ble_opt_t opt = {0};
    opt.gap_opt.privacy.interval_s = 5;
    err_code = sd_ble_opt_set(opt.gap_opt.privacy.interval_s, &opt);
    //APP_ERROR_CHECK(err_code);
    
    // Change MAC address
    gap_address.addr_type = BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_RESOLVABLE;
    err_code = sd_ble_gap_address_set(BLE_GAP_ADDR_CYCLE_MODE_AUTO, &gap_address);
    APP_ERROR_CHECK(err_code);
    

    }

Children
No Data
Related