diff options
author | Marcel Holtmann <marcel@holtmann.org> | 2007-08-27 13:16:54 +0000 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2007-08-27 13:16:54 +0000 |
commit | 463995dde9f8a56e46ad3ae85f81962997b11ff3 (patch) | |
tree | 5f8a275b90c09a7e7f1cbca95191e1308bbf1229 | |
parent | 296dcf42cf8a4f4d6f0192cac58a28887be38552 (diff) |
Convert UUID-128 strings into UUID-16 values if possible
-rw-r--r-- | hcid/dbus-common.c | 60 |
1 files changed, 35 insertions, 25 deletions
diff --git a/hcid/dbus-common.c b/hcid/dbus-common.c index 4cbc42aa..812cdc98 100644 --- a/hcid/dbus-common.c +++ b/hcid/dbus-common.c @@ -91,6 +91,7 @@ int str2uuid(uuid_t *uuid, const char *string) { uint16_t svclass, data1, data2, data3, data5; uint32_t data0, data4; + uint8_t val[16]; svclass = sdp_str2svclass(string); if (svclass) { @@ -98,34 +99,43 @@ int str2uuid(uuid_t *uuid, const char *string) return 0; } - if (strlen(string) == 36 && - string[8] == '-' && - string[13] == '-' && - string[18] == '-' && - string[23] == '-' && - sscanf(string, "%08x-%04hx-%04hx-%04hx-%08x%04hx", - &data0, &data1, &data2, &data3, &data4, &data5) == 6) { - uint8_t val[16]; - - data0 = htonl(data0); - data1 = htons(data1); - data2 = htons(data2); - data3 = htons(data3); - data4 = htonl(data4); - data5 = htons(data5); - - memcpy(&val[0], &data0, 4); - memcpy(&val[4], &data1, 2); - memcpy(&val[6], &data2, 2); - memcpy(&val[8], &data3, 2); - memcpy(&val[10], &data4, 4); - memcpy(&val[14], &data5, 2); - - sdp_uuid128_create(uuid, val); + if (strlen(string) != 36) + return -1; + + if (string[8] != '-' || string[13] != '-' || + string[18] != '-' || string[23] != '-') + return -1; + + if (sscanf(string, "%08x-%04hx-%04hx-%04hx-%08x%04hx", + &data0, &data1, &data2, &data3, &data4, &data5) != 6) + return -1; + + /* Base UUID is 00001203-0000-1000-8000-00805F9B34FB */ + if (data1 == 0x0000 && data2 == 0x1000 && data3 == 0x8000 && + data4 == 0x00805F9B && data5 == 0x34FB) { + if ((data0 & 0xffff0000) > 0) + sdp_uuid32_create(uuid, data0); + else + sdp_uuid16_create(uuid, data0); return 0; } - return -1; + data0 = htonl(data0); + data1 = htons(data1); + data2 = htons(data2); + data3 = htons(data3); + data4 = htonl(data4); + data5 = htons(data5); + + memcpy(&val[0], &data0, 4); + memcpy(&val[4], &data1, 2); + memcpy(&val[6], &data2, 2); + memcpy(&val[8], &data3, 2); + memcpy(&val[10], &data4, 4); + memcpy(&val[14], &data5, 2); + + sdp_uuid128_create(uuid, val); + return 0; } int l2raw_connect(const char *local, const bdaddr_t *remote) |