This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to correctly generate UUIDs-128 for user services and chars.?

I know it was asked and I was searching but I didn't find a clear answer about that. I know that I can generate any random 128bit UUID for all my user services & characteristics. But there are at least 5 algorythms how to generate an UUID according to wiki. I tried to download M$ uudigen.exe and run uuidgen on our linux server and both give me random UUIDs (type 4). But BLE base UUID is type 1 that is less random and it allows to mask first 32b to use them for incremental short UUIDs

Also in one of Nordic examples I can see this: #define LBS_UUID_BASE {0x23, 0xD1, 0xBC, 0xEA, 0x5F, 0x78, 0x23, 0x15, 0xDE, 0xEF, 0x12, 0x12, 0x00, 0x00, 0x00, 0x00} #define LBS_UUID_SERVICE 0x1523 #define LBS_UUID_LED_CHAR 0x1525 #define LBS_UUID_BUTTON_CHAR 0x1524

This base UUID was also masked so four last bytes are zero. I'm not sure about byte order, is it right that 1st byte of APP_UUID_BASE is the last byte of UUID in string format as I see from generator? If it was a random UUID then it become non-random after masking (I can generate many UUIDs that will differ only in last 4 bytes and if I zero them I got same UUID - that are no longer UUIDs).

So I guess that version 1 of UUID algorythm should be used (MAC+time), then some part of UUID remains constant and I can safely mask the part occupied by some low bytes of time, am I right? What program do you reccomend for UUID ver 1 generation? I found this Python script that seems doing it well, so can I then mask the beginninig 32bits and use as my UUID_BASE for entire project just incrementing the first 32b part when need a new service or characteristic?

Parents
  • For the order :

    Generated UUID (from nfrgo studio) : B131xxxx-7195-142B-E012-0808817F198D :

    #define DBS_UUID_BASE {0x8D, 0x19, 0x7F, 0x81, 0x08, 0x08,0x12,0xE0,0x2B,0x14,0x95,0x71,0xXX,0xXX,0x31,0xB1} #define DBS_UUID_SERVICE 0x1523 #define DBS_UUID_VALUE_CHAR 0x1525

    The 2 bytes XXXX will be replaced by the 2 bytes of service in the UUID service, or the 2 bytes of characteritic in the characteritic UUID.

    Exemple : Each service and each characteritic have an UUID
    Service UUID will be : 0x8D, 0x19, 0x7F, 0x81, 0x08, 0x08,0x12,0xE0,0x2B,0x14,0x95,0x71, 0x15,0x23 ,0x31,0xB1 Characteritic UUID will be : 0x8D, 0x19, 0x7F, 0x81, 0x08, 0x08,0x12,0xE0,0x2B,0x14,0x95,0x71, 0x15,0x25 ,0x31,0xB1

    Only these 2 bytes differ between characteristics of same service You can put what do you want one the 2 bytes Service or Char... The UUID base without this 2 bytes is unique yet.

Reply
  • For the order :

    Generated UUID (from nfrgo studio) : B131xxxx-7195-142B-E012-0808817F198D :

    #define DBS_UUID_BASE {0x8D, 0x19, 0x7F, 0x81, 0x08, 0x08,0x12,0xE0,0x2B,0x14,0x95,0x71,0xXX,0xXX,0x31,0xB1} #define DBS_UUID_SERVICE 0x1523 #define DBS_UUID_VALUE_CHAR 0x1525

    The 2 bytes XXXX will be replaced by the 2 bytes of service in the UUID service, or the 2 bytes of characteritic in the characteritic UUID.

    Exemple : Each service and each characteritic have an UUID
    Service UUID will be : 0x8D, 0x19, 0x7F, 0x81, 0x08, 0x08,0x12,0xE0,0x2B,0x14,0x95,0x71, 0x15,0x23 ,0x31,0xB1 Characteritic UUID will be : 0x8D, 0x19, 0x7F, 0x81, 0x08, 0x08,0x12,0xE0,0x2B,0x14,0x95,0x71, 0x15,0x25 ,0x31,0xB1

    Only these 2 bytes differ between characteristics of same service You can put what do you want one the 2 bytes Service or Char... The UUID base without this 2 bytes is unique yet.

Children
No Data
Related