Bluetooth identity creating in extended advertising

Dear all,

I wanted to modify BTHome template sample for Home Assistant software in order to run enable it to advertise on PHY Coded, there I guess I need to enable extended advertiising via:

err = bt_le_ext_adv_create(&param, NULL, &adv);

It seems I was able to enable extended advertising and Home Assistant sees the devices, but anytime I power up the dongle it pops up is Home Assistant as a device with unique MAC address, so everytime I have to add a new device which is not practical, I need the device to appear in Home assistant as a device which was already added, so I guess the MAC address is the key to et rid of this obstacle.

Following the skilled person, tried to base my solution on this, but it seems not to be based on extended advertising, therefore BT_LE_ADV_OPT_USE_IDENTITY, which is also used in BTHome templeate, works perfectly fine:

devzone.nordicsemi.com/.../427087

 

I was trying to my issue with this with  id = bt_id_create(&static_addr, NULL); before bt_enable(NULL), but whenever I try to set up id parameter to  struct bt_le_adv_param param, param.id = id, the application alwas fails here:  err = bt_le_ext_adv_create(&param, NULL, &adv); with error -22. When I use BT_LE_ADV_OPT_USE_IDENTITY in params this way: struct bt_le_adv_param param =
BT_LE_ADV_PARAM_INIT(BT_LE_ADV_OPT_EXT_ADV |
BT_LE_ADV_OPT_USE_IDENTITY |
BT_LE_ADV_OPT_CODED,
BT_GAP_ADV_SLOW_INT_MIN, \
BT_GAP_ADV_SLOW_INT_MAX, NULL); It is not detected in Home Assistant at all. So I got stuck, probably missing a piece of information. The BTHome template works perfectly fine, but I wanted to enhance with bluetooth 5 extended advertising capability.

My prj.conf:

CONFIG_BT=y
#CONFIG_LOG=y
#CONFIG_BT_SMP=y
#CONFIG_BT_PERIPHERAL=y
#CONFIG_BT_PERIPHERAL=n
#CONFIG_BT_DIS=y
#CONFIG_BT_DIS_PNP=n
#CONFIG_BT_BAS=y
CONFIG_BT_DEVICE_NAME="BTHome template"

#CONFIG_BT_DEVICE_APPEARANCE=768
CONFIG_BT_CTLR_PHY_CODED=y
CONFIG_BT_CTLR_ADV_EXT=y
CONFIG_BT_EXT_ADV=y
#CONFIG_CBPRINTF_FP_SUPPORT=y

#!!new
CONFIG_BT_BROADCASTER=y
CONFIG_BT_PRIVACY=n
#CONFIG_BT_GAP_AUTO_UPDATE_CONN_PARAMS=n
CONFIG_BT_SETTINGS=y

Parents
  • Hi,

    First of all I have to say that the BTHome template sample is not made by Nordic per se, and I am not familiar with it myself. However I do not see why any of this shouldn't work. In this previous case you see a situation that reminds me a bit of yours, though I am not sure if a "BTHome spec" mandates a certain type of address, or if it can use an IRK key. 

    Might be misunderstanding you somewhere here, but it sounds like you want a random static address tied to an id, and this sample should show how to do that. The DevAcademy can also be a great resource here.

    It seems I was able to enable extended advertising and Home Assistant sees the devices, but anytime I power up the dongle it pops up is Home Assistant as a device with unique MAC address, so everytime I have to add a new device which is not practical

    So this was not the case earlier, before switching to extended advertising?

    Regards,

    Elfving

  • Exactly, before switching to extended advertising, it worked perfectly.

    In this post:

    https://devzone.nordicsemi.com/f/nordic-q-a/100063/setting-bluetooth-mac-address/427087 

    the guy is using  BT_LE_ADV_OPT_USE_IDENTITY in BT_LE_ADV_PARAM which does not work for me, but he is probably using legacy advertising, not extended.

    No I am trying to set up permanent MAC address, because I somehow think it is related to the the usb printout of bluetooth stack initilization when logging enabled:

    [00:00:02.140,045] <err> bt_id: Only random static identity address supported
    [00:00:02.144,348] <inf> bt_hci_core: HW Platform: Nordic Semiconductor (0x0002)
    [00:00:02.144,378] <inf> bt_hci_core: HW Variant: nRF52x (0x0002)
    [00:00:02.144,409] <inf> bt_hci_core: Firmware: Standard Bluetooth controller (0x00) Version 4.1 Build 0
    [00:00:02.144,866] <inf> bt_hci_core: Identity: F5:59:E4:A3:3B:84 (random)
    [00:00:02.144,897] <inf> bt_hci_core: HCI: version 5.4 (0x0d) revision 0x0000, manufacturer 0x05f1
    [00:00:02.144,927] <inf> bt_hci_core: LMP: version 5.4 (0x0d) subver 0xffff

    I was trying to achieve this with either this: 

    id = bt_id_create(&static_addr, NULL);

    struct bt_le_adv_param param =
    BT_LE_ADV_PARAM_INIT(
    BT_LE_ADV_OPT_EXT_ADV |
    BT_LE_ADV_OPT_CODED,

    BT_GAP_ADV_FAST_INT_MIN_2,
    BT_GAP_ADV_FAST_INT_MAX_2,
    NULL);

    param.id = id;

    err = bt_le_ext_adv_create(&param, NULL, &adv);

    But the result is:

    Failed to create advertiser set (err -22)

    or this:

    • bt_ctlr_set_public_addr()

  • Thank you sir.I will go through the adresses you recommend.

    The situation is like this.I managed to run my device over PHY CODED to Home Assistant.

    I am using extended advertising with PHY coded.

    The problem is,anytime I reset the bluetooth device,it pops up in Home Assistant as a completely new device with unique adress which is not practical as I need to add the device again anytime this happens.

    I experienced the same problem in legacy advertising (the original sample bthome template in Zephyr tree) and this BT_LE_ADV_OPT_USE_IDENTITY fixed the issue.

    But with extended advertising with BT_LE_ADV_OPT_USE_IDENTITY the device does not show up in Home Assistant at all,but bluetoothctl in Linux command line sees the device with LECODEDTX/RX enabled, the only way I can make it visible in Home Assistant is to omit BT_LE_ADV_OPT_USE_IDENTITY, but with the problem of unique MAC adress.

    I read that anytime I boot my bluetooth device I see a certain MAC address in usb printk info output at the initialization bt_enable() which is stable across reboots and this address is inside identity number 0 when I get the addressfromidentity number 0 and printit,with BT_LE_ADV_OPT_USE_IDENTITY Zephyr stack forces bluetooth to use this identity 0 to be visible as. address.

    BUT without BT_LE_ADV_OPT_USE_IDENTITY I read it generates some kind of virtual RPA adress which is derived via some IRK + random number and creates completely unique address which is updated every 15 minutes due to security,so I wanted to bypass RPA with BT_LE_ADV_OPT_USE_IDENTITY,but that does not work.

    I also saw a solution where seetings_load() which should  generate a fixed RPA address which will be generated once then stored to flash and wil be used anytime the device is rebooted,but that also did not work.

    I am definitely not against RPA especially when you recommend it,but how to force the MAC address to be stable with RPA and also make it visible in Home Assistant?

    Maybe I understand it completely wrong,I am not that skilled in bluetooth.

  • Actually I can use BT_LE_ADV_OPT_ANONYMOUS, this works, but then I ran into issues whenever I want to add multiple sensors, they clash as they all are assigned 00:00:00:00:00:00. So I guess the MAC address must be unique as well as fixed, otherwise Home Assistant will not work properly, but I do not know how to achieve this

  • The reason why it doesn't work with extended advertising might also be that there is something missing somewhere. It works slightly differently with extended advertising after all. But then it doesn't immediately make sense to me how you got BT_LE_ADV_OPT_ANONYMOUS working.

    Ivo H said:
    I read that anytime I boot my bluetooth device I see a certain MAC address in usb printk info output at the initialization bt_enable()

    I am not sure if I understood this entire part, but the next part about randomization for privacy is correct. But if you do not need that, that is fine.

    You can have a look at the code I sent below, which seems to me atleast to use the same address each time. You can also change it when needed.

    Regards,

    Elfving

  • Thank you,if  you mean the code you sent in your first reply I guess that is just abbriviationfor this  BT_LE_ADV_PARAM_INIT(BT_LE_ADV_OPT_EXT_ADV |
    BT_LE_ADV_OPT_USE_IDENTITY |
    BT_LE_ADV_OPT_CODED,
    BT_GAP_ADV_SLOW_INT_MIN, \
    BT_GAP_ADV_SLOW_INT_MAX, NULL); 

    Right?

    This I used in my first post and it did not show up in Home Assistant with extended advertising,but anyway  will verify it once more with your NCONN_IDENTITY and double check.

    Anyway,this uses identity,isn't there a way how to omit IDENTITY and make the RPA address fixed?So instead of this:

    BT_LE_EXT_ADV_CODED_NCONN_IDENTITY

    ,we will use this 

    BT_LE_EXT_ADV_CODED_NCONN

    ?

  • Thank you very much for help, but unfortunately, your code with 

    BT_LE_EXT_ADV_CODED_NCONN_IDENTITY

    does not cause the device to be visible in Home Assistant, it is visible in bluetoothctl, but it does not pop up even once in Home Assistant.

    I read it is related to extended_advertising, in legacy, 

    IDENTITY 

    works fine, but in extended, it is different.

Reply
  • Thank you very much for help, but unfortunately, your code with 

    BT_LE_EXT_ADV_CODED_NCONN_IDENTITY

    does not cause the device to be visible in Home Assistant, it is visible in bluetoothctl, but it does not pop up even once in Home Assistant.

    I read it is related to extended_advertising, in legacy, 

    IDENTITY 

    works fine, but in extended, it is different.

Children
No Data
Related