Skip to content

Conversation

@kaabia
Copy link

@kaabia kaabia commented Oct 31, 2025

This patch corrects a logical error in the bt_nxp_set_mac_address function
where a dynamically generated Bluetooth MAC address uses the device's
Unique ID (UID) for its local part (3 LSBs).

Problem:
The offset calculation used in memcpy was:
uid + uuidLen - (BD_ADDR_UUID_PART_SIZE + 1)
This resulted in missing the last byte of the actual UID data, potentially
leading to non-unique or less-random MAC addresses when the UID is
longer than 3 bytes.

Fix:
The offset is corrected to use only the size of the MAC part:
uid + uuidLen - BD_ADDR_UUID_PART_SIZE
This ensures the last BD_ADDR_UUID_PART_SIZE (3) bytes of the MCU
UID are used as intended.

The bt_nxp_set_mac_address function incorrectly calculates the offset
when attempting to extract the last 3 bytes of the MCU Unique ID (UID)
to form the local part of the Bluetooth MAC address.

The incorrect offset calculation included an extra '- 1', causing the
copy operation to miss the final byte of the UID and copy a less unique
or non-intended byte sequence.

Fix this by correcting the offset calculation to:
'uid + uuidLen - BD_ADDR_UUID_PART_SIZE'.
Signed-off-by: Badr Bacem KAABIA <[email protected]>
@sonarqubecloud
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: Bluetooth HCI Bluetooth HCI Driver area: Bluetooth platform: NXP NXP size: XS A PR changing only a single line of code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants