Switch between Public address and Static Random address.

Power-on reset will require pairing again.

I found this happening by doing bt_id_reset().

Is there a problem with the way the BD address is initialized?

How to initialize BD address:

    bt_enable(NULL);

    if (IS_ENABLED(CONFIG_BT_SETTINGS))
    {
        settings_load();
    }

    bt_addr_le_t get_addr[CONFIG_BT_ID_MAX];
    size_t count = CONFIG_BT_ID_MAX;
    memset(&get_addr, 0, sizeof(get_addr));

    bt_id_get(get_addr, &count);
    if(get_addr[BD_ADDRESS_INDEX_RANDOM].a.val[5] == 0 && get_addr[BD_ADDRESS_INDEX_RANDOM].a.val[4] == 0 &&
        get_addr[BD_ADDRESS_INDEX_RANDOM].a.val[3] == 0 && get_addr[BD_ADDRESS_INDEX_RANDOM].a.val[2] == 0 &&
        get_addr[BD_ADDRESS_INDEX_RANDOM].a.val[1] == 0 && get_addr[BD_ADDRESS_INDEX_RANDOM].a.val[0] == 0){
        bt_id_create(&addr, nullptr);
    }else{
        bt_id_reset(BD_ADDRESS_INDEX_RANDOM, &addr, nullptr);
    }

Build Option:

CONFIG_BT_SMP=1
CONFIG_BT_ID_MAX=2
CONFIG_BT_SETTINGS=1
CONFIG_BT_KEYS_OVERWRITE_OLDEST=1

Parents
  • Hi

    We don't have any ready sample code on changing addresses during run time I'm afraid, how do you see in your application that you're using the public address for pairing/bonding. Since the bt_id_reset() is deleting the pairing keys when calling it with the BD_ADDRESS_INDEX_RANDOM in your case it seems like the connection is made using the random address.

    Best regards,

    Simon

Reply
  • Hi

    We don't have any ready sample code on changing addresses during run time I'm afraid, how do you see in your application that you're using the public address for pairing/bonding. Since the bt_id_reset() is deleting the pairing keys when calling it with the BD_ADDRESS_INDEX_RANDOM in your case it seems like the connection is made using the random address.

    Best regards,

    Simon

Children
Related