how to specify a public MAC address

To read the MAC addresses defined I use the following code (with CONFIG_BT_ID_MAX=2 in prj.conf):::

    bt_addr_le_t addr[CONFIG_BT_ID_MAX];    //space for random address and public address
    size_t count = 2;                       //request both addresses
    bt_id_get(addr, &count);                //count will contain the number of addresses returned

In reply, count is set to 1 hence only one address is defined. addr[0] contains an address of type random.
I order to define a public MAC address I got inspired by the following post:

https://devzone.nordicsemi.com/f/nordic-q-a/99585/config-for-using-sdc_hci_cmd-functions

This uses an hci command similar to setting TX power. I had to adapt it for a later version of SDK/Toolchain.
My code is as follows:

static int set_bd_addr(void)
{
    int err = 0;
    struct net_buf *buf;
    struct bt_hci_cp_vs_write_bd_addr *cmd_params;

    buf = bt_hci_cmd_create(BT_VS_CMD_BIT_WRITE_BDADDR , sizeof(*cmd_params));
    if (!buf) {
        printk("Could not allocate command buffer\n");
        return -ENOMEM;
    }

    cmd_params = net_buf_add(buf, sizeof(*cmd_params));

    cmd_params->bdaddr.val[0]= 0xCC;
    cmd_params->bdaddr.val[1]= 0xCC;
    cmd_params->bdaddr.val[2]= 0xCC;
    cmd_params->bdaddr.val[3]= 0xCC;
    cmd_params->bdaddr.val[4]= 0xCC;
    cmd_params->bdaddr.val[5]= 0xCC;

    err = bt_hci_cmd_send_sync(BT_VS_CMD_BIT_WRITE_BDADDR, buf, NULL);
    printk("err: %d \n",err);
    if (err) {
        printk("err: %d \n",err);
        return err;
    }

    printk("Successfully set bd addr \n");

    return 0;
}
I call set_bd_addr() before bl_enable(NULL).
The project built without errors for nrf15l15dk/nrf15l15/cpuapp.
Executing function bt_hci_cmd_send_sync does not return since I get the following fatal error:
[00:06:03.052,316] <err> os: ***** MPU FAULT *****
[00:06:03.052,322] <err> os:   Data Access Violation
[00:06:03.052,326] <err> os:   MMFAR Address: 0x12c1d
[00:06:03.052,336] <err> os: r0/a1:  0x00000000  r1/a2:  0x00000004  r2/a3:  0x00012c1d
[00:06:03.052,342] <err> os: r3/a4:  0x200063c8 r12/ip:  0x00000000 r14/lr:  0x0002259f
[00:06:03.052,347] <err> os:  xpsr:  0x29000000
[00:06:03.052,351] <err> os: Faulting instruction address (r15/pc): 0x00022ca0
[00:06:03.052,369] <err> os: >>> ZEPHYR FATAL ERROR 19: Unknown error on CPU 0
[00:06:03.052,384] <err> os: Current thread: 0x20002ee0 (unknown)
[00:06:03.129,332] <err> os: Halting system
The development board is dead. I needed do an erase via Segger J-Flash.
Hence my question: How does one specify a public MAC address and how can one signal that is should be used ?
Parents
  • Hello,

        cmd_params = net_buf_add(buf, sizeof(*cmd_params));

        cmd_params->bdaddr.val[0]= 0xCC;
        cmd_params->bdaddr.val[1]= 0xCC;
        cmd_params->bdaddr.val[2]= 0xCC;
        cmd_params->bdaddr.val[3]= 0xCC;
        cmd_params->bdaddr.val[4]= 0xCC;
        cmd_params->bdaddr.val[5]= 0xCC;

    For debugging purposes. If you remove all these lines, does the development board stop seeing the fatal error then?

    If so, add the first line back, and directly after the line "cmd_params = net_buf_add(...)", try printing printk("%p\n",cmd_params);

    What is the value of cmd_params that is printed in the log?

    Best regards,

    Edvin

  • Hi Edvin,

    If I remove the lines you sugges I get the following log output:

    [00:00:00.000,640] <err> os: ***** HARD FAULT *****
    [00:00:00.000,640] <err> os:   Debug event
    [00:00:00.000,671] <err> os: r0/a1:  0x11badeba  r1/a2:  0x00000003  r2/a3:  0x0   0000002
    [00:00:00.000,671] <err> os: r3/a4:  0x0000feca r12/ip:  0x00000000 r14/lr:  0x0   001d981
    [00:00:00.000,701] <err> os:  xpsr:  0x61000000
    [00:00:00.000,701] <err> os: Faulting instruction address (r15/pc): 0x0000e3a8
    [00:00:00.000,732] <err> os: >>> ZEPHYR FATAL ERROR 0: CPU exception on CPU 0
    [00:00:00.000,762] <err> os: Current thread: 0x20002a30 (unknown

    The only difference is that the board is not blocked.

    I subsequently left the line "cmd_params = net_buf_add(...)" and added printing printk("%p\n",cmd_params);

    All I get as log is this line:

    [00:00:00.088,073] <err> os: Halting system

    In debug doing F10 at function "bt_hci_cmd_send_sync()" nothing happens.

    Thanks for the support,
    Leon

Reply
  • Hi Edvin,

    If I remove the lines you sugges I get the following log output:

    [00:00:00.000,640] <err> os: ***** HARD FAULT *****
    [00:00:00.000,640] <err> os:   Debug event
    [00:00:00.000,671] <err> os: r0/a1:  0x11badeba  r1/a2:  0x00000003  r2/a3:  0x0   0000002
    [00:00:00.000,671] <err> os: r3/a4:  0x0000feca r12/ip:  0x00000000 r14/lr:  0x0   001d981
    [00:00:00.000,701] <err> os:  xpsr:  0x61000000
    [00:00:00.000,701] <err> os: Faulting instruction address (r15/pc): 0x0000e3a8
    [00:00:00.000,732] <err> os: >>> ZEPHYR FATAL ERROR 0: CPU exception on CPU 0
    [00:00:00.000,762] <err> os: Current thread: 0x20002a30 (unknown

    The only difference is that the board is not blocked.

    I subsequently left the line "cmd_params = net_buf_add(...)" and added printing printk("%p\n",cmd_params);

    All I get as log is this line:

    [00:00:00.088,073] <err> os: Halting system

    In debug doing F10 at function "bt_hci_cmd_send_sync()" nothing happens.

    Thanks for the support,
    Leon

Children
No Data
Related