This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC2340R5: random mac address need add in advt report

Part Number: CC2340R5
Other Parts Discussed in Thread: SYSCONFIG,

Tool/software:

Dear team

I'm working with the CC2340R5 using SDK 8.40 and IDE 12.8.

I'm trying to change the device’s MAC address during a firmware update.

I tried using SysConfig by setting the address type to "RPA with Public Identity", but the MAC address changes on every power cycle, which is not the desired behavior.

I also attempted to change the MAC address programmatically using the code below. It works only the first time — the MAC address does not update with subsequent firmware updates.

Could you please advise on how to ensure the MAC address is updated reliably during each firmware update?

Thank you.


static uint32_t seedCounter = 0;

uint8_t getFakeRandom()
{
seedCounter++; // This increments every time the function is called
return (uint8_t)((Random_getNumber() + seedCounter * 31) & 0xFF); // 31 is just a salt multiplier
}

void generateRandomMAC(uint8_t *macAddr)
{
macAddr[0] = getFakeRandom() & 0x3F; // Lower 6 bits only
macAddr[1] = getFakeRandom();
macAddr[2] = getFakeRandom();
}


// Initialize or load the custom BD address
void setCustomBDAddr(void)
{
uint8_t customBDAddr[6] = { 0x00, 0x12, 0x34, 0x56, 0x78, 0x9A };
// Open NVS
NVS_Params nvsParams;
NVS_Params_init(&nvsParams);
nvsHandle = NVS_open(CONFIG_NVS_0, &nvsParams);

if (nvsHandle == NULL) {
// Handle error
return;
}

NVS_getAttrs(nvsHandle, &regionAttrs);

// Read existing MAC from flash
uint8_t readMac[MAC_ADDR_SIZE];
int status = NVS_read(nvsHandle, 0, readMac, MAC_ADDR_SIZE);

// If no MAC saved, generate and write it
if (status != NVS_STATUS_SUCCESS || readMac[0] == 0xFF) {
generateRandomMAC(customBDAddr);
NVS_erase(nvsHandle, 0, regionAttrs.sectorSize); // Clean sector
NVS_write(nvsHandle, 0, customBDAddr, MAC_ADDR_SIZE, NVS_WRITE_POST_VERIFY);

}
// Set BD_ADDR with HCI command
HCI_EXT_SetBDADDRCmd(readMac);

// Optional debug

NVS_close(nvsHandle);
}

  • Hello,

    Thank you for reaching out! Are you using the CC2350R5 or the CC2340R5-Q1?

    Best Regards,

    Tarek

  • Dear Tarek,

    I'm using CC2340R5 

    Thanks and Regards

    Abinesh

  • Hello Abinesh,

    Are you attempting to change the BLE address or the random address of the device?

    For changing the random address, I would recommend using the HCI_EXT_SetAdvSetRandAddrCmd() function. As for changing the BLE address, this should only be used when the device is in standby, and the effect will take place when the device is reset (hardware reset, not HCI reset). Here's the documentation on using the HCI_EXT_SetBADDRCmd() function:   https://dev.ti.com/tirex/content/simplelink_lowpower_f3_sdk_8_40_02_01/docs/ble5stack/ble_user_guide/doxygen/ble/html/group___h_c_i.html#gaea8af8b8d0099e813cde1e30b864a0a7


    I would recommend using the random address in a scenario where you want to change the address, as changing the BLE address (also known as the MAC address) could cause a violation in the IEEE standards and the BLE specifications: "Each Bluetooth device shall be allocated a unique 48-bit Bluetooth Device Address (BD_ADDR). The address shall be a 48-bit extended unique identifier (EUI-48) created in accordance with section 8.2 ("Universal addresses") of the IEEE 802-2014 standard " (BLUETOOTH CORE SPECIFICATION Version 5.4 | Vol 2, Part B)/


    I hope this helps!

    Best Regards,

    Tarek

  • Hi Tarek,

    Are you attempting to change the BLE address or the random address of the device?

    YES,I want to change BLE MAC Address.

    My requirement is that each time the firmware is flashed to a new board, it should generate a unique MAC address.

    Once flashed, the MAC address should remain the same for the lifetime of the device, unless the firmware is updated again.

    Thanks and Regards

    Abinesh

  • Helo Abines,

    Thank you for the clarification! I think you should keep using the same function, HCI_EXT_SetAdvRandAddrCmd(), to change the MAC address. I recommend calling it in the app_main.c file, inside the APP_StackInitDoneHandler, as this function should be run as soon as possible. Please also keep in mind that the address you are changing to needs to be a valid BLE address that doesn't violate the BLE spec. I hope this answers your question!

    Best Regards,

    Tarek

  • Dear Tarek,

    I have tried Adding HCI_EXT_SetAdvRandAddrCmd() function but its showing as ANONYMOUS without mac address, but after adding  HCI_EXT_SetBDADDRCmd(customBDAddr) function its showing same address for every build.

    In sys-config Address mode as Public address.

    Thanks and regards

    Abinesh.

  • Hello Abinesh,

    Thanks for providing this info! This is actually expected behavior.

    The HCI_EXT_SetAdvRandAddrCmd(uint8_t advHandle, uint8_t *randaddr) function is used for changing the RPA address to a specific value The HCI_EXT_SetBDADDRCmd(uint8_t *bdaddr) should be used to change the BLE address (also known as the MAC address) also to a specific value. These functions set their respective addresses to a specific value set by the user in the argument of the function, and they do not randomize the address.

    When I mentioned above that I recommend using HCI_EXT_SetAdvRandAddrCmd, I also meant that I recommend using the RPA address and changing that, rather than changing the BLE address.

    I hope this helps!

    Best Regards,

    Tarek