5 years, 7 months ago.

Why are bytes 2 and 3 zeroed out for 128-bit UUIDs?

In the UUID constructor in UUID.ccp, if the UUID is a long UUID bytes 2 and 3 are being set to '0.' There is some comment about this helping with comparisons, but it does not make sense. I am trying to make a custom characteristic with a 128-bit UUID generated by uuidgen. Since these bytes get set to '0,' the UUID is not correct.

Question relating to:

High level Bluetooth Low Energy API and radio abstraction layer

1 Answer

5 years, 7 months ago.

The reason is down to the way the Nordic SoftDevice handles 128-bit UUIDs. Because it's the SoftDevice that provides the BLE Stack, mbed has adopted the same mechanism.

You can read the documentation below, but the gist of it is:

Nordic uses a 3-byte format for 128-bit UUIDs: 16-bit short UUID that replaces bytes 12 and 13 (2 and 3 but little endian) in the full 128-bit UUID and a third byte that refers to an index in a table with a set of 128-bit UUIDs that have those bytes 12 and 13 zeroed out. Then you can construct the full 128-bit UUID from the 3-byte format by:

1) Use the 1-byte index to look up in the table 2) Replace bytes 12 and 13 of the UUID in the table with the 16-bit value.


Accepted Answer

Thanks for your response Charles. Since this is specific to the Nordic stack/radio, I believe this code should be moved out of the common UUID class. This interferes with implementations of the BLE_API on other stacks/radios. Is there some place in the Nordic implementation that this functionality could be implemented?

posted by Jeremy Brodt 20 Feb 2015

Hi Jeremy. Yes, I agree, this should not be part of the common UUID class. Instead the mbed layer should check if the "base" (i.e. the 128-bit UUID with the 2 bytes zeroed) has already been added to the SoftDevice's table and, if not, add it. Then it could simply use a standard 16-byte notation. Note that I am not familiar enough with the code at this time to be able to give you more details, I'll try to dig into it a bit.

posted by Carles Cufi 20 Feb 2015