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

  • Hi

    Since bt_id_reset() removes any connections and pairing keys and it seems like the connection and bonding is done with the random static address. I don't really see why you call this function at all in your application if you want to keep the pairing information throughout a power-on reset. I'd recommend not calling it during your initialization.

    Best regards,

    Simon

  • Hi

    I believe I need to use bt_id_reset() to update the static random address stored in NVM at startup.

    Which API should I use to update static random address?

    Regards,

    yaho4624

  • Is there a reason you want to change the static random address between boot-ups? The random address is actually the one that is pre-programmed from the factory. This is why it remains the same even though you erase your device and re-program it. It is expected that the random address stays the same between boot-ups.

    Best regards,

    Simon

  • Hi

    I recognize the following about BLE BD addresses.
    ・Public Address:Addresses corresponding to hardware written in OTP, etc.
    ・Static Random Address:Address that changes with each boot to prevent the device from being tracked.

    Is this perception wrong?

    Regards,

    yaho4624

  • Hi

    That's not quite it I'm afraid.

    Public address: A public address is a fixed address that is programmed into the device at the manufacturer. This is globally unique and can not be erased.

    Random addresses: Much more common, does not require registration with IEEE and can be manually configured by the user. It's either programmed within the device or created during run time. A random static address can be allocated and then fixed throughout the lifetime of the device. It can be altered at boot-up but doesn't have to be. 

    More details here. Do you need to mask/change the address to not be tracked for some specific reason? Using a resolvable or non-resolvable random private address is more used as it changes periodically

    Best reagrds,

    Simon

Related