How can we enable our addr as PUBLIC in our ble advertisement?

We would like configure our device with a public addr instead of the random as is default for NCS/Zephyr. We are currently on Zephyr v3.1.99 and NCS 2.1. I have tracked down the function that should set our device to a public addr but I'm getting an error that says public isn't supported. IAfter some research I've found a couple of places in the forum, github, and documentation that mentions public may not be supported yet. Right now our mobile apps and other factory equipment are expecting our device to advertise as a public addr. So we really need to figure out if this is even possible and if not, when will it be.

Here is the code that I'm using to try and setup the addr:

     bt_addr_le_t  ble_gap_addr;
    ble_gap_addr.type = BT_ADDR_LE_PUBLIC;
    memcpy(&ble_gap_addr.a.val, "\x62\x52\x42\x09\xe7\x34", sizeof(ble_gap_addr.a.val));
    ble_gap_addr.type = BT_ADDR_LE_PUBLIC;
    BT_ADDR_SET_STATIC(&ble_gap_addr.a);
    bt_id_create(&ble_gap_addr, NULL);

I'm seeing an error in my debug log when this code is getting run:

Image Confirmed Successfully!
[00:00:09.546,569] <err> bt_id: Only static random identity address supported
BLE advertisement state change: 0
BLE advertisement state change: 1

  • Hi,

    You are getting this error:

    jio_ble_dev_zephyr.c:279:34: error: 'ble_gap_addr' may be used uninitialized in this function [-Werror=maybe-uninitialized]

    And that makes sense, because of your code, where you make a pointer to a sdc_hci_cmd_vs_zephyr_write_bd_addr instance that exists nowhere, so this is uninitialized memory at a random location. The code snippet you have posted should be something like this instead:

            sdc_hci_cmd_vs_zephyr_write_bd_addr_t ble_gap_addr; // note that there is no * here
            ble_gap_addr.bd_addr[0] = 2; // note the . and not -> here
            ble_gap_addr.bd_addr[1] = 2;
            ble_gap_addr.bd_addr[2] = 2;
            ble_gap_addr.bd_addr[3] = 2;
            ble_gap_addr.bd_addr[4] = 2;
            ble_gap_addr.bd_addr[5] = 2;
            sdc_hci_cmd_vs_zephyr_write_bd_addr(&ble_gap_addr); // note the & here

  • Well, don't I feel silly now. LOL! Thank you!

    But I'm still getting an error during compile after the corrections from above.

    /home/shellpry/Documents/west-workspace/ncs/nrfxlib/crypto/nrf_cc312_platform/lib/cortex-m33/soft-float/no-interrupts/libnrf_cc312_platform_0.9.15.a  -lc && cd /home/shellpry/Documents/west-workspace/wiced-jiobit/WICED-SDK/build/zephyr && /usr/bin/cmake -E echo
    /home/shellpry/gnuarmemb/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.bfd: app/libapp.a(jio_ble_dev_zephyr.c.obj): in function `jio_ble_dev_start':
    /home/shellpry/Documents/west-workspace/wiced-jiobit/WICED-SDK/jiobit/firmware_common/jio_ble_dev/zephyr/jio_ble_dev_zephyr.c:290: undefined reference to `sdc_hci_cmd_vs_zephyr_write_bd_addr'
    collect2: error: ld returned 1 exit status
    ninja: build stopped: subcommand failed.
    FATAL ERROR: command exited with status 1: /usr/bin/cmake --build /home/shellpry/Documents/west-workspace/wiced-jiobit/WICED-SDK/build

     *  The terminal process "/usr/bin/bash '-c', 'west build --pristine -b hawking_cpuapp apps/jiobit_bare/zephyr'" terminated with exit code: 1.
     *  Terminal will be reused by tasks, press any key to close it.

Related