Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
6 years 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:
6 years 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.