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
*
* 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.
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);
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,
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) {
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;