Setting nRF5340 Public BLE Address

Hi,

I have been trying to update the BLE mac address to public but unfortunately, I wasn't able to achieve that

I have followed the multiple DevZone threads but wasn't successful in updating the BLEaddress.

nRF5340-DK, ncs2.0.1, (primary application running on app core and using the default child image hci_rpmsg (during build))

These are the two methods, I have used to update but neither of them were successful

Method 1: using bt_ctlr_set_public_addr() 

Issue: undefined reference to bt_ctlr_set_public_addr() even after adding #include <zephyr/bluetooth/controller.h> and also called before bt_enable().

1. Do I need to enable any kconfig symbols and also is the bt_ctlr_set_public_addr() has to be used in the application running on network core

Method 2: using bt_hci_cmd_create and bt_hci_cmd_send_sync but there were no build errors but when I flash the application, MAC address doesn't get updated.

Could you please help me in figuring out this and also I sometimes couldn't understand which specific modules are intended to use by the network core.

Thanks

Parents
  • Hi,

    Method 2: using bt_hci_cmd_create and bt_hci_cmd_send_sync but there were no build errors but when I flash the application, MAC address doesn't get updated.

    I tested it here, and it works fine. Some code snippets:

    Snippet 1:

     #include <zephyr/bluetooth/hci.h>
    #include <sdc_hci_vs.h>
    
    static int set_bd_addr(void)
    {
    	int err = 0;
    	struct net_buf *buf;
    	sdc_hci_cmd_vs_zephyr_write_bd_addr_t *cmd_params;
    
    	buf = bt_hci_cmd_create(SDC_HCI_OPCODE_CMD_VS_ZEPHYR_WRITE_BD_ADDR ,
    				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->bd_addr[0]= 0xCC;
    	cmd_params->bd_addr[1]= 0xCC;
    	cmd_params->bd_addr[2]= 0xCC;
    	cmd_params->bd_addr[3]= 0xCC;
    	cmd_params->bd_addr[4]= 0xCC;
    	cmd_params->bd_addr[5]= 0xCC;
    
    
    
        printk("bt_hci_cmd_send_sync \n");
    
    	err = bt_hci_cmd_send_sync(SDC_HCI_OPCODE_CMD_VS_ZEPHYR_WRITE_BD_ADDR, buf, NULL);
    	printk("err: %d \n",err);
    	if (err) {
    		printk("err: %d \n",err);
    		return err;
    	}
    
    	printk("Successfully set bd addr \n");
    
    	return 0;
    }

    Snippet 2:

    	err = bt_enable(NULL);
    	if (err) {
    		error();
    	}
    
    	LOG_INF("Bluetooth initialized");
    
    	k_sem_give(&ble_init_ok);
    
    	set_bd_addr();

Reply
  • Hi,

    Method 2: using bt_hci_cmd_create and bt_hci_cmd_send_sync but there were no build errors but when I flash the application, MAC address doesn't get updated.

    I tested it here, and it works fine. Some code snippets:

    Snippet 1:

     #include <zephyr/bluetooth/hci.h>
    #include <sdc_hci_vs.h>
    
    static int set_bd_addr(void)
    {
    	int err = 0;
    	struct net_buf *buf;
    	sdc_hci_cmd_vs_zephyr_write_bd_addr_t *cmd_params;
    
    	buf = bt_hci_cmd_create(SDC_HCI_OPCODE_CMD_VS_ZEPHYR_WRITE_BD_ADDR ,
    				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->bd_addr[0]= 0xCC;
    	cmd_params->bd_addr[1]= 0xCC;
    	cmd_params->bd_addr[2]= 0xCC;
    	cmd_params->bd_addr[3]= 0xCC;
    	cmd_params->bd_addr[4]= 0xCC;
    	cmd_params->bd_addr[5]= 0xCC;
    
    
    
        printk("bt_hci_cmd_send_sync \n");
    
    	err = bt_hci_cmd_send_sync(SDC_HCI_OPCODE_CMD_VS_ZEPHYR_WRITE_BD_ADDR, buf, NULL);
    	printk("err: %d \n",err);
    	if (err) {
    		printk("err: %d \n",err);
    		return err;
    	}
    
    	printk("Successfully set bd addr \n");
    
    	return 0;
    }

    Snippet 2:

    	err = bt_enable(NULL);
    	if (err) {
    		error();
    	}
    
    	LOG_INF("Bluetooth initialized");
    
    	k_sem_give(&ble_init_ok);
    
    	set_bd_addr();

Children
  • Thank you for sharing the snippet but I have tried by adding the above snippets but unsuccesful, 
    Do I need to enable any symbols in .conf file?

    Here is my code snippets and .conf file. Could you please confirm if anything I have missed adding

    #include <zephyr/bluetooth/hci.h>
    #include <zephyr/bluetooth/hci_vs.h>
    #include <sdc_hci_vs.h>
    
    static int set_bd_addr(void)
    {
    	int err = 0;
    	struct net_buf *buf;
    	sdc_hci_cmd_vs_zephyr_write_bd_addr_t *cmd_params;
    
    	buf = bt_hci_cmd_create(SDC_HCI_OPCODE_CMD_VS_ZEPHYR_WRITE_BD_ADDR ,
    				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->bd_addr[0]= 0xCC;
    	cmd_params->bd_addr[1]= 0xCC;
    	cmd_params->bd_addr[2]= 0xCC;
    	cmd_params->bd_addr[3]= 0xCC;
    	cmd_params->bd_addr[4]= 0xCC;
    	cmd_params->bd_addr[5]= 0xCC;
    
        printk("bt_hci_cmd_send_sync \n");
    
    	err = bt_hci_cmd_send_sync(SDC_HCI_OPCODE_CMD_VS_ZEPHYR_WRITE_BD_ADDR, buf, NULL);
    	printk("err: %d \n",err);
    	if (err) {
    		printk("err: %d \n",err);
    		return err;
    	}
    
    	printk("Successfully set bd addr \n");
    
    	return 0;
    }
    
    void ble_init()
    {
        int  err;
    	
        err = bt_enable(NULL);
    	if (err) {
    		printk("BLE enabling failed (err %d)\n", err);
    	}
    
    	set_bd_addr();
    
    	err = bt_ready(err);
    	if (err) {
    		printk("BLE initialized failed (err %d)\n", err);
    	}


    prj.conf file

    CONFIG_SERIAL=y     
    
    # Config logger
    CONFIG_LOG=y
    CONFIG_USE_SEGGER_RTT=n
    CONFIG_LOG_BACKEND_RTT=n
    CONFIG_LOG_BACKEND_UART=n
    
    CONFIG_ASSERT=n
    CONFIG_BT=y
    CONFIG_BT_PERIPHERAL=y
    CONFIG_BT_DEBUG_LOG=y
    CONFIG_BT_SMP=y
    CONFIG_BT_DEVICE_NAME="adv"
    CONFIG_BT_MAX_CONN=2
    CONFIG_BT_MAX_PAIRED=2
    CONFIG_BT_DEVICE_APPEARANCE=833
    
    CONFIG_BT_GATT_DM=y
    CONFIG_BT_GATT_CLIENT=y
    
    CONFIG_KERNEL_MEM_POOL=y
    CONFIG_HEAP_MEM_POOL_SIZE=4096
    CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048
    
    CONFIG_DK_LIBRARY=y
    
    # Power management
    CONFIG_PM=n
    
    CONFIG_BT_DATA_LEN_UPDATE=y
    
    
    CONFIG_BT_USER_DATA_LEN_UPDATE=y
    CONFIG_BT_USER_PHY_UPDATE=y
    CONFIG_BT_GAP_AUTO_UPDATE_CONN_PARAMS=n
    CONFIG_BT_BUF_ACL_RX_SIZE=251
    CONFIG_BT_ATT_PREPARE_COUNT=2
    CONFIG_BT_CONN_TX_MAX=10
    CONFIG_BT_L2CAP_TX_BUF_COUNT=10
    CONFIG_BT_L2CAP_TX_MTU=247
    CONFIG_BT_L2CAP_DYNAMIC_CHANNEL=y
    
    CONFIG_BT_THROUGHPUT=n
    
    CONFIG_BT_BUF_ACL_TX_SIZE=251
    CONFIG_BT_BUF_ACL_TX_COUNT=10
    CONFIG_BT_CONN_PARAM_UPDATE_TIMEOUT=300
    
    CONFIG_BT_HCI_VS=y
    CONFIG_BT_HCI_VS_EXT=y
    
    CONFIG_BT_CTLR=n
    CONFIG_BT_LL_SW_SPLIT=y

    child_image/hci_rpmsg.conf

    CONFIG_BT=y
    CONFIG_BT_HCI_RAW=y
    CONFIG_BT_MAX_CONN=10
    CONFIG_BT_CTLR_ASSERT_HANDLER=y
    CONFIG_BT_HCI_RAW_RESERVE=1
    CONFIG_BT_BUF_CMD_TX_COUNT=10
    
    
    CONFIG_BT_BUF_ACL_TX_SIZE=251
    CONFIG_BT_CTLR_DATA_LENGTH_MAX=251
    CONFIG_BT_BUF_ACL_RX_SIZE=251
    CONFIG_BT_MAX_CONN=2

  • Hi,

    I tested using the SoftDevice Controller. Try removing CONFIG_BT_LL_SW_SPLIT=y from prj.conf

  • Thanks for the prompt response

    I have removed the "CONFIG_BT_LL_SW_SPLIT=y from prj.conf" but still no change in MAC address.
    but I have added the snippet to the one of the sample(ncs) and it worked right of the box. 

    I will check my application and check why its not updating in my application and get back to you if I have any questions

  • I have tried adding this to the beacon sample in NCS 2.4 with an nRF5340.

    Unmodified beacon sample advertises with address CE:35:AB:AC:91:C4 (random)

    When, I add these snippets. It logs that the address was successfully updated, but still advertises with the original address (CE:35:AB:AC:91:C4).

    My prj.conf:

    CONFIG_BT=y
    CONFIG_BT_DEBUG_LOG=y
    CONFIG_BT_DEVICE_NAME="Test beacon"
    
    CONFIG_BT_HCI_VS=y
    CONFIG_BT_HCI_VS_EXT=y

    Am I missing configs?
    Is there an updated way to change the address?

  • It logs that the address was successfully updated, but still advertises with the original address (CE:35:AB:AC:91:C4).

    Did you first change the address, and then started the advertising ?

Related