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();

  • 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 ?

Reply Children
Related