OSDN Git Service

GATT: fix 32 bit UUID handling
authorJakub Pawlowski <jpawlowski@google.com>
Thu, 12 Apr 2018 12:42:31 +0000 (05:42 -0700)
committerJakub Pawlowski <jpawlowski@google.com>
Wed, 18 Apr 2018 07:10:09 +0000 (07:10 +0000)
When writing UUID into stream with gatt_build_uuid_to_stream, we always
use 16bit or 128bit representation. In GATT code returning service UUID,
we were returning 32bit representation lenght, even though 128bit
representation was being returned in the stream. This resulted in
invalid GATT database content being returned, and the service not being
visible.

Bug: 66912853
Test: create GATT database with 32bit UUID, discover from remote device
Change-Id: I791a518ab080bd99db0a8be18d97e865c838fc7e

stack/gatt/gatt_db.cc
stack/gatt/gatt_int.h
stack/gatt/gatt_sr.cc
stack/gatt/gatt_utils.cc

index 8c33453..31a262d 100644 (file)
@@ -148,13 +148,13 @@ static tGATT_STATUS gatts_check_attr_readability(const tGATT_ATTR& attr,
  *
  * Description      Utility function to read an attribute value.
  *
- * Parameter        p_attr: pointer to the attribute to read.
+ * Parameter        attr16: pointer to the attribute to read.
  *                  offset: read offset.
- *                  p_value: output parameter to carry out the attribute value.
- *                  p_len: output parameter to carry out the attribute length.
+ *                  p_data: output parameter to carry out the attribute value.
  *                  read_long: this is a read blob request.
  *                  mtu: MTU
- *                  sec_flag: current link security status.
+ *                  p_len: output parameter to carry out the attribute length.
+ *                   sec_flag: current link security status.
  *                  key_size: encryption key size.
  *
  * Returns          status of operation.
@@ -182,7 +182,7 @@ static tGATT_STATUS read_attr_value(tGATT_ATTR& attr16, uint16_t offset,
   uint16_t uuid16 = attr16.uuid.As16Bit();
 
   if (uuid16 == GATT_UUID_PRI_SERVICE || uuid16 == GATT_UUID_SEC_SERVICE) {
-    *p_len = attr16.p_value->uuid.GetShortestRepresentationSize();
+    *p_len = gatt_build_uuid_to_stream_len(attr16.p_value->uuid);
     if (mtu < *p_len) return GATT_NO_RESOURCES;
 
     gatt_build_uuid_to_stream(&p, attr16.p_value->uuid);
index a542b05..5052918 100644 (file)
@@ -436,6 +436,7 @@ extern uint32_t gatt_add_sdp_record(const bluetooth::Uuid& uuid,
                                     uint16_t start_hdl, uint16_t end_hdl);
 extern bool gatt_parse_uuid_from_cmd(bluetooth::Uuid* p_uuid, uint16_t len,
                                      uint8_t** p_data);
+extern uint8_t gatt_build_uuid_to_stream_len(const bluetooth::Uuid& uuid);
 extern uint8_t gatt_build_uuid_to_stream(uint8_t** p_dst,
                                          const bluetooth::Uuid& uuid);
 extern void gatt_sr_get_sec_info(const RawAddress& rem_bda,
index 877a881..d71b60d 100644 (file)
@@ -459,7 +459,7 @@ static tGATT_STATUS gatt_build_primary_service_rsp(
     if (!p_uuid) continue;
 
     if (op_code == GATT_REQ_READ_BY_GRP_TYPE)
-      handle_len = 4 + p_uuid->GetShortestRepresentationSize();
+      handle_len = 4 + gatt_build_uuid_to_stream_len(*p_uuid);
 
     /* get the length byte in the repsonse */
     if (p_msg->offset == 0) {
index fd27621..9fa48f8 100644 (file)
@@ -453,6 +453,14 @@ tGATT_TCB* gatt_allocate_tcb_by_bdaddr(const RawAddress& bda,
   return NULL;
 }
 
+/** gatt_build_uuid_to_stream will convert 32bit UUIDs to 128bit. This function
+ * will return lenght required to build uuid, either |UUID:kNumBytes16| or
+ * |UUID::kNumBytes128| */
+uint8_t gatt_build_uuid_to_stream_len(const Uuid& uuid) {
+  size_t len = uuid.GetShortestRepresentationSize();
+  return len == Uuid::kNumBytes32 ? Uuid::kNumBytes128 : len;
+}
+
 /** Add UUID into stream. Returns UUID length. */
 uint8_t gatt_build_uuid_to_stream(uint8_t** p_dst, const Uuid& uuid) {
   uint8_t* p = *p_dst;