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

  • When pairing again, we also confirm that the security error "BT_SECURITY_ERR_PIN_OR_KEY_MISSING" occurs.

  • Hi

    Yes, this is expected, as Bluetooth pairing is only done for a specific connection, and so if the devices disconnect and I.E. the advertising address on one device changes, they will no longer be paired. However if you do bonding, as well after pairing, the devices will exchange a LTK (long term key) so that they can reconnect to one another and keep the encrypted connection without having to re-pair upon every connection. Please check out the DevAcademy on Bluetooth Low Energy available here. Lesson 5 covers Security in BLE and the pairing process specifically.

    Best regards,

    Simon

  • Hi Simonr.

    Thank you for your reply.

    We will check on Lesson 5 later. Thank you for sharing the link.

    I have paired and bonded with Public address only, do I have to pair again?

    Specifically, the procedure is as follows.

    1. Power-on
    2. Public address is created by bt_enable()
    3. Static Random address is created by bt_id_create()
    4. Start advertising with Public address
    5. Pairing and bonding at Public address
    6. Disconnect
    7. Power-on reset
    8. Public address is created by bt_enable()
    9. Static Random address is created by bt_id_reset()
    10. Start advertising with Public address
    11. It needs to be paired again.

    Without bt_id_reset(), it was not necessary to pair again after power-on reset.

    When pairing again, we also confirm that the security error "BT_SECURITY_ERR_PIN_OR_KEY_MISSING" occurs.

    Regards,

    yaho4624

  • Hi

    Is there a reason you're using bt_id_reset()? This function resets or reclaims the identity of a Bluetooth LE ID. From the documentation: "When given an existing identity this function will disconnect any connections created using it, remove any pairing keys or other data associated with it, and then create a new identity in the same slot, based on the addr and irk parameters."

    Best regards,

    Simon

  • Hi

    No reason. I am new to using Zepher and just used an API that I could use from the API documentation. As per my first question, could you please tell me the best practice for initializing Public and Static Random addresses?

    As far as I can tell from the API documentation, bt_id_reset() takes a static random address index as an argument, so the expected behavior is that only static random address information will disappear from NVM. Conversely, we expect that the public address information will not disappear.

    Regards,

    yaho4624

Related