aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndre Eisenbach <eisenbach@google.com>2015-10-20 18:03:30 -0700
committerAndre Eisenbach <eisenbach@google.com>2015-10-21 13:29:04 -0700
commit61968383a63be05a335e26bc53ef39d9af98ad72 (patch)
tree5668de9e1f87a53de7b3342c08062292f1552e04
parentac43e88a0aa375e712683e2b218d876c616e6f5e (diff)
downloadbt-61968383a63be05a335e26bc53ef39d9af98ad72.tar.gz
Fix 128-bit UUID byte order for GATT-over-BR/EDR
128-bit UUIDs for GATT services discovered using SDP are byte-ordered incorrectly. This patch fixes both the SDP discovery as well as the SDP record creation code. Bug: 24344122 Change-Id: Iee4bf33dcbbc5ee0f2380b48330107232bd0401b
-rw-r--r--stack/gatt/gatt_utils.c2
-rw-r--r--stack/include/bt_types.h1
-rw-r--r--stack/sdp/sdp_api.c13
3 files changed, 10 insertions, 6 deletions
diff --git a/stack/gatt/gatt_utils.c b/stack/gatt/gatt_utils.c
index fb09704cb..f993fa189 100644
--- a/stack/gatt/gatt_utils.c
+++ b/stack/gatt/gatt_utils.c
@@ -1530,7 +1530,7 @@ UINT32 gatt_add_sdp_record (tBT_UUID *p_uuid, UINT16 start_hdl, UINT16 end_hdl)
case LEN_UUID_128:
UINT8_TO_BE_STREAM (p, (UUID_DESC_TYPE << 3) | SIZE_SIXTEEN_BYTES);
- ARRAY_TO_BE_STREAM (p, p_uuid->uu.uuid128, LEN_UUID_128);
+ ARRAY_TO_BE_STREAM_REVERSE (p, p_uuid->uu.uuid128, LEN_UUID_128);
SDP_AddAttribute (sdp_handle, ATTR_ID_SERVICE_CLASS_ID_LIST, DATA_ELE_SEQ_DESC_TYPE,
(UINT32) (p - buff), buff);
break;
diff --git a/stack/include/bt_types.h b/stack/include/bt_types.h
index 299c7332c..8d761437a 100644
--- a/stack/include/bt_types.h
+++ b/stack/include/bt_types.h
@@ -286,6 +286,7 @@ typedef struct
#define UINT16_TO_BE_STREAM(p, u16) {*(p)++ = (UINT8)((u16) >> 8); *(p)++ = (UINT8)(u16);}
#define UINT8_TO_BE_STREAM(p, u8) {*(p)++ = (UINT8)(u8);}
#define ARRAY_TO_BE_STREAM(p, a, len) {register int ijk; for (ijk = 0; ijk < len; ijk++) *(p)++ = (UINT8) a[ijk];}
+#define ARRAY_TO_BE_STREAM_REVERSE(p, a, len) {register int ijk; for (ijk = 0; ijk < len; ijk++) *(p)++ = (UINT8) a[len - ijk - 1];}
#define BE_STREAM_TO_UINT8(u8, p) {u8 = (UINT8)(*(p)); (p) += 1;}
#define BE_STREAM_TO_UINT16(u16, p) {u16 = (UINT16)(((UINT16)(*(p)) << 8) + (UINT16)(*((p) + 1))); (p) += 2;}
diff --git a/stack/sdp/sdp_api.c b/stack/sdp/sdp_api.c
index f0fdc026b..ca4d12756 100644
--- a/stack/sdp/sdp_api.c
+++ b/stack/sdp/sdp_api.c
@@ -357,7 +357,8 @@ BOOLEAN SDP_FindServiceUUIDInRec(tSDP_DISC_REC *p_rec, tBT_UUID * p_uuid)
else if (SDP_DISC_ATTR_LEN(p_sattr->attr_len_type) == LEN_UUID_128)
{
p_uuid->len = LEN_UUID_128;
- memcpy(p_uuid->uu.uuid128, p_sattr->attr_value.v.array, LEN_UUID_128);
+ for (uint8_t i = 0; i != LEN_UUID_128; ++i)
+ p_uuid->uu.uuid128[i] = p_sattr->attr_value.v.array[LEN_UUID_128-i-1];
}
else if (SDP_DISC_ATTR_LEN(p_sattr->attr_len_type) == LEN_UUID_32)
{
@@ -443,8 +444,9 @@ BOOLEAN SDP_FindServiceUUIDInRec_128bit(tSDP_DISC_REC *p_rec, tBT_UUID * p_uuid)
/* only support 128 bits UUID for now */
if (SDP_DISC_ATTR_LEN(p_sattr->attr_len_type) == 16)
{
- p_uuid->len = 16;
- memcpy(p_uuid->uu.uuid128, p_sattr->attr_value.v.array, MAX_UUID_SIZE);
+ p_uuid->len = LEN_UUID_128;
+ for (uint8_t i = 0; i != LEN_UUID_128; ++i)
+ p_uuid->uu.uuid128[i] = p_sattr->attr_value.v.array[LEN_UUID_128-i-1];
}
return(TRUE);
}
@@ -457,8 +459,9 @@ BOOLEAN SDP_FindServiceUUIDInRec_128bit(tSDP_DISC_REC *p_rec, tBT_UUID * p_uuid)
/* only support 128 bits UUID for now */
&& (SDP_DISC_ATTR_LEN(p_attr->attr_len_type) == 16))
{
- p_uuid->len = 16;
- memcpy(p_uuid->uu.uuid128, p_attr->attr_value.v.array, MAX_UUID_SIZE);
+ p_uuid->len = LEN_UUID_128;
+ for (uint8_t i = 0; i != LEN_UUID_128; ++i)
+ p_uuid->uu.uuid128[i] = p_sattr->attr_value.v.array[LEN_UUID_128-i-1];
return(TRUE);
}
}