Use one type for UUID (1/5)
Currently, we have few different representations for UUID in stack:
tBT_UUID, tSDP_UUID, bt_uuid_t, bluetooth:UUID, or uint8_t*.
Additionally, tBT_UUID and bt_uuid_t are used to hold UUID as 128bit
as Little Endian or Big Endian, depending on which part of stack (GATT
or SDP) is using it.
This patch is creating one type, bluetooth::Uuid, that will replace all
other types.
Bug: 66912853
Test: all sl4a tests for GATT and RFCOMM
Merged-In: Ia42d3233146db0488728ed6f878f99b368fe8838
Change-Id: Ia42d3233146db0488728ed6f878f99b368fe8838
diff --git a/stack/a2dp/a2dp_api.cc b/stack/a2dp/a2dp_api.cc
index 4be2bdd..3c2f1bb 100644
--- a/stack/a2dp/a2dp_api.cc
+++ b/stack/a2dp/a2dp_api.cc
@@ -35,6 +35,8 @@
#include "osi/include/log.h"
#include "sdpdefs.h"
+using bluetooth::Uuid;
+
/*****************************************************************************
* Global data
****************************************************************************/
@@ -269,7 +271,6 @@
tA2DP_STATUS A2DP_FindService(uint16_t service_uuid, const RawAddress& bd_addr,
tA2DP_SDP_DB_PARAMS* p_db,
tA2DP_FIND_CBACK* p_cback) {
- tSDP_UUID uuid_list;
bool result = true;
LOG_VERBOSE(LOG_TAG, "%s: uuid: 0x%x", __func__, service_uuid);
@@ -282,10 +283,6 @@
a2dp_cb.find.service_uuid == UUID_SERVCLASS_AUDIO_SINK)
return A2DP_BUSY;
- /* set up discovery database */
- uuid_list.len = LEN_UUID_16;
- uuid_list.uu.uuid16 = service_uuid;
-
if (p_db->p_attrs == NULL || p_db->num_attr == 0) {
p_db->p_attrs = a2dp_attr_list;
p_db->num_attr = A2DP_NUM_ATTR;
@@ -294,6 +291,7 @@
if (a2dp_cb.find.p_db == NULL)
a2dp_cb.find.p_db = (tSDP_DISCOVERY_DB*)osi_malloc(p_db->db_len);
+ Uuid uuid_list = Uuid::From16Bit(service_uuid);
result = SDP_InitDiscoveryDb(a2dp_cb.find.p_db, p_db->db_len, 1, &uuid_list,
p_db->num_attr, p_db->p_attrs);
diff --git a/stack/avrc/avrc_sdp.cc b/stack/avrc/avrc_sdp.cc
index 3a7ed96..0527fa3 100644
--- a/stack/avrc/avrc_sdp.cc
+++ b/stack/avrc/avrc_sdp.cc
@@ -27,6 +27,8 @@
#include "avrc_int.h"
#include "bt_common.h"
+using bluetooth::Uuid;
+
/*****************************************************************************
* Global data
****************************************************************************/
@@ -106,7 +108,6 @@
uint16_t AVRC_FindService(uint16_t service_uuid, const RawAddress& bd_addr,
tAVRC_SDP_DB_PARAMS* p_db,
tAVRC_FIND_CBACK* p_cback) {
- tSDP_UUID uuid_list;
bool result = true;
AVRC_TRACE_API("%s uuid: %x", __func__, service_uuid);
@@ -120,15 +121,13 @@
avrc_cb.service_uuid == UUID_SERVCLASS_AV_REMOTE_CONTROL)
return AVRC_NO_RESOURCES;
- /* set up discovery database */
- uuid_list.len = LEN_UUID_16;
- uuid_list.uu.uuid16 = service_uuid;
if (p_db->p_attrs == NULL || p_db->num_attr == 0) {
p_db->p_attrs = a2dp_attr_list_sdp;
p_db->num_attr = AVRC_NUM_ATTR;
}
+ Uuid uuid_list = Uuid::From16Bit(service_uuid);
result = SDP_InitDiscoveryDb(p_db->p_db, p_db->db_len, 1, &uuid_list,
p_db->num_attr, p_db->p_attrs);
diff --git a/stack/bnep/bnep_api.cc b/stack/bnep/bnep_api.cc
index 923ce50..89cf0be 100644
--- a/stack/bnep/bnep_api.cc
+++ b/stack/bnep/bnep_api.cc
@@ -26,6 +26,8 @@
#include <string.h>
#include "bnep_int.h"
+using bluetooth::Uuid;
+
/*******************************************************************************
*
* Function BNEP_Init
@@ -123,8 +125,8 @@
* BNEP_NO_RESOURCES if no resources
*
******************************************************************************/
-tBNEP_RESULT BNEP_Connect(const RawAddress& p_rem_bda, tBT_UUID* src_uuid,
- tBT_UUID* dst_uuid, uint16_t* p_handle) {
+tBNEP_RESULT BNEP_Connect(const RawAddress& p_rem_bda, const Uuid& src_uuid,
+ const Uuid& dst_uuid, uint16_t* p_handle) {
uint16_t cid;
tBNEP_CONN* p_bcb = bnepu_find_bcb_by_bd_addr(p_rem_bda);
@@ -132,9 +134,6 @@
if (!bnep_cb.profile_registered) return BNEP_WRONG_STATE;
- /* Both source and destination UUID lengths should be same */
- if (src_uuid->len != dst_uuid->len) return BNEP_CONN_FAILED_UUID_SIZE;
-
if (!p_bcb) {
p_bcb = bnepu_allocate_bcb(p_rem_bda);
if (p_bcb == NULL) return (BNEP_NO_RESOURCES);
@@ -142,29 +141,27 @@
return BNEP_WRONG_STATE;
else {
/* Backup current UUID values to restore if role change fails */
- memcpy((uint8_t*)&(p_bcb->prv_src_uuid), (uint8_t*)&(p_bcb->src_uuid),
- sizeof(tBT_UUID));
- memcpy((uint8_t*)&(p_bcb->prv_dst_uuid), (uint8_t*)&(p_bcb->dst_uuid),
- sizeof(tBT_UUID));
+ p_bcb->prv_src_uuid = p_bcb->src_uuid;
+ p_bcb->prv_dst_uuid = p_bcb->dst_uuid;
}
/* We are the originator of this connection */
p_bcb->con_flags |= BNEP_FLAGS_IS_ORIG;
- memcpy((uint8_t*)&(p_bcb->src_uuid), (uint8_t*)src_uuid, sizeof(tBT_UUID));
- memcpy((uint8_t*)&(p_bcb->dst_uuid), (uint8_t*)dst_uuid, sizeof(tBT_UUID));
+ p_bcb->src_uuid = src_uuid;
+ p_bcb->dst_uuid = dst_uuid;
if (p_bcb->con_state == BNEP_STATE_CONNECTED) {
/* Transition to the next appropriate state, waiting for connection confirm.
*/
p_bcb->con_state = BNEP_STATE_SEC_CHECKING;
- BNEP_TRACE_API("BNEP initiating security procedures for src uuid 0x%x",
- p_bcb->src_uuid.uu.uuid16);
+ BNEP_TRACE_API("BNEP initiating security procedures for src uuid %s",
+ p_bcb->src_uuid.ToString().c_str());
#if (BNEP_DO_AUTH_FOR_ROLE_SWITCH == TRUE)
btm_sec_mx_access_request(p_bcb->rem_bda, BT_PSM_BNEP, true,
- BTM_SEC_PROTO_BNEP, bnep_get_uuid32(src_uuid),
+ BTM_SEC_PROTO_BNEP, src_uuid.As32Bit(),
&bnep_sec_check_complete, p_bcb);
#else
bnep_sec_check_complete(p_bcb->rem_bda, p_bcb, BTM_SUCCESS);
@@ -249,10 +246,8 @@
p_bcb->con_state = BNEP_STATE_CONNECTED;
p_bcb->con_flags &= (~BNEP_FLAGS_SETUP_RCVD);
- memcpy((uint8_t*)&(p_bcb->src_uuid), (uint8_t*)&(p_bcb->prv_src_uuid),
- sizeof(tBT_UUID));
- memcpy((uint8_t*)&(p_bcb->dst_uuid), (uint8_t*)&(p_bcb->prv_dst_uuid),
- sizeof(tBT_UUID));
+ p_bcb->src_uuid = p_bcb->prv_src_uuid;
+ p_bcb->dst_uuid = p_bcb->prv_dst_uuid;
}
/* Process remaining part of the setup message (extension headers) */
@@ -680,8 +675,8 @@
p_status->rcvd_mcast_filters = p_bcb->rcvd_mcast_filters;
p_status->rem_bda = p_bcb->rem_bda;
- memcpy(&(p_status->src_uuid), &(p_bcb->src_uuid), sizeof(tBT_UUID));
- memcpy(&(p_status->dst_uuid), &(p_bcb->dst_uuid), sizeof(tBT_UUID));
+ p_status->src_uuid = p_bcb->src_uuid;
+ p_status->dst_uuid = p_bcb->dst_uuid;
return BNEP_SUCCESS;
#else
diff --git a/stack/bnep/bnep_int.h b/stack/bnep/bnep_int.h
index e25e7f8..2a7bac0 100644
--- a/stack/bnep/bnep_int.h
+++ b/stack/bnep/bnep_int.h
@@ -149,10 +149,10 @@
uint16_t bad_pkts_rcvd;
uint8_t re_transmits;
uint16_t handle;
- tBT_UUID prv_src_uuid;
- tBT_UUID prv_dst_uuid;
- tBT_UUID src_uuid;
- tBT_UUID dst_uuid;
+ bluetooth::Uuid prv_src_uuid;
+ bluetooth::Uuid prv_dst_uuid;
+ bluetooth::Uuid src_uuid;
+ bluetooth::Uuid dst_uuid;
} tBNEP_CONN;
@@ -231,6 +231,5 @@
uint16_t protocol,
bool fw_ext_present,
uint8_t* p_data);
-extern uint32_t bnep_get_uuid32(tBT_UUID* src_uuid);
#endif
diff --git a/stack/bnep/bnep_main.cc b/stack/bnep/bnep_main.cc
index 636a511..246d5c0 100644
--- a/stack/bnep/bnep_main.cc
+++ b/stack/bnep/bnep_main.cc
@@ -254,9 +254,9 @@
bnep_conn_timer_timeout, p_bcb);
if (p_bcb->con_flags & BNEP_FLAGS_IS_ORIG) {
- btm_sec_mx_access_request(
- p_bcb->rem_bda, BT_PSM_BNEP, true, BTM_SEC_PROTO_BNEP,
- bnep_get_uuid32(&(p_bcb->src_uuid)), &bnep_sec_check_complete, p_bcb);
+ btm_sec_mx_access_request(p_bcb->rem_bda, BT_PSM_BNEP, true,
+ BTM_SEC_PROTO_BNEP, p_bcb->src_uuid.As32Bit(),
+ &bnep_sec_check_complete, p_bcb);
}
}
}
@@ -298,8 +298,7 @@
if (p_bcb->con_flags & BNEP_FLAGS_IS_ORIG) {
btm_sec_mx_access_request(p_bcb->rem_bda, BT_PSM_BNEP, true,
- BTM_SEC_PROTO_BNEP,
- bnep_get_uuid32(&(p_bcb->src_uuid)),
+ BTM_SEC_PROTO_BNEP, p_bcb->src_uuid.As32Bit(),
&bnep_sec_check_complete, p_bcb);
}
}
diff --git a/stack/bnep/bnep_utils.cc b/stack/bnep/bnep_utils.cc
index 29d41fc..070f275 100644
--- a/stack/bnep/bnep_utils.cc
+++ b/stack/bnep/bnep_utils.cc
@@ -33,6 +33,8 @@
#include "device/include/controller.h"
#include "osi/include/osi.h"
+using bluetooth::Uuid;
+
/******************************************************************************/
/* L O C A L F U N C T I O N P R O T O T Y P E S */
/******************************************************************************/
@@ -164,8 +166,8 @@
BT_HDR* p_buf = (BT_HDR*)osi_malloc(BNEP_BUF_SIZE);
uint8_t *p, *p_start;
- BNEP_TRACE_DEBUG("%s: sending setup req with dst uuid %x", __func__,
- p_bcb->dst_uuid.uu.uuid16);
+ BNEP_TRACE_DEBUG("%s: sending setup req with dst uuid %s", __func__,
+ p_bcb->dst_uuid.ToString().c_str());
p_buf->offset = L2CAP_MIN_OFFSET;
p = p_start = (uint8_t*)(p_buf + 1) + L2CAP_MIN_OFFSET;
@@ -176,22 +178,26 @@
/* Put in filter message type - set filters */
UINT8_TO_BE_STREAM(p, BNEP_SETUP_CONNECTION_REQUEST_MSG);
- UINT8_TO_BE_STREAM(p, p_bcb->dst_uuid.len);
+ int len = std::max(p_bcb->dst_uuid.GetShortestRepresentationSize(),
+ p_bcb->src_uuid.GetShortestRepresentationSize());
- if (p_bcb->dst_uuid.len == 2) {
- UINT16_TO_BE_STREAM(p, p_bcb->dst_uuid.uu.uuid16);
- UINT16_TO_BE_STREAM(p, p_bcb->src_uuid.uu.uuid16);
- } else if (p_bcb->dst_uuid.len == 4) {
- UINT32_TO_BE_STREAM(p, p_bcb->dst_uuid.uu.uuid32);
- UINT32_TO_BE_STREAM(p, p_bcb->src_uuid.uu.uuid32);
- } else if (p_bcb->dst_uuid.len == 16) {
- memcpy(p, p_bcb->dst_uuid.uu.uuid128, p_bcb->dst_uuid.len);
- p += p_bcb->dst_uuid.len;
- memcpy(p, p_bcb->src_uuid.uu.uuid128, p_bcb->dst_uuid.len);
- p += p_bcb->dst_uuid.len;
+ UINT8_TO_BE_STREAM(p, len);
+
+ if (len == Uuid::kNumBytes16) {
+ UINT16_TO_BE_STREAM(p, p_bcb->dst_uuid.As16Bit());
+ UINT16_TO_BE_STREAM(p, p_bcb->src_uuid.As16Bit());
+ } else if (len == Uuid::kNumBytes32) {
+ UINT32_TO_BE_STREAM(p, p_bcb->dst_uuid.As32Bit());
+ UINT32_TO_BE_STREAM(p, p_bcb->src_uuid.As32Bit());
+ } else if (len == Uuid::kNumBytes128) {
+ memcpy(p, p_bcb->dst_uuid.To128BitBE().data(), Uuid::kNumBytes128);
+ p += Uuid::kNumBytes128;
+ memcpy(p, p_bcb->src_uuid.To128BitBE().data(), Uuid::kNumBytes128);
+ p += Uuid::kNumBytes128;
} else {
- BNEP_TRACE_ERROR("%s: uuid: %x, invalid length: %x", __func__,
- p_bcb->dst_uuid.uu.uuid16, p_bcb->dst_uuid.len);
+ BNEP_TRACE_ERROR("%s: uuid: %s, invalid length: %zu", __func__,
+ p_bcb->dst_uuid.ToString().c_str(),
+ p_bcb->dst_uuid.GetShortestRepresentationSize());
}
p_buf->len = (uint16_t)(p - p_start);
@@ -523,8 +529,7 @@
******************************************************************************/
void bnep_process_setup_conn_req(tBNEP_CONN* p_bcb, uint8_t* p_setup,
uint8_t len) {
- BNEP_TRACE_EVENT("BNEP - bnep_process_setup_conn_req for CID: 0x%x",
- p_bcb->l2cap_cid);
+ BNEP_TRACE_EVENT("BNEP - %s for CID: 0x%x", __func__, p_bcb->l2cap_cid);
if (p_bcb->con_state != BNEP_STATE_CONN_SETUP &&
p_bcb->con_state != BNEP_STATE_SEC_CHECKING &&
@@ -553,36 +558,43 @@
}
if (p_bcb->con_state == BNEP_STATE_CONNECTED) {
- memcpy((uint8_t*)&(p_bcb->prv_src_uuid), (uint8_t*)&(p_bcb->src_uuid),
- sizeof(tBT_UUID));
- memcpy((uint8_t*)&(p_bcb->prv_dst_uuid), (uint8_t*)&(p_bcb->dst_uuid),
- sizeof(tBT_UUID));
+ p_bcb->prv_src_uuid = p_bcb->src_uuid;
+ p_bcb->prv_dst_uuid = p_bcb->dst_uuid;
}
- p_bcb->dst_uuid.len = p_bcb->src_uuid.len = len;
-
- if (p_bcb->dst_uuid.len == 2) {
+ if (len == Uuid::kNumBytes16) {
/* because peer initiated connection keep src uuid as dst uuid */
- BE_STREAM_TO_UINT16(p_bcb->src_uuid.uu.uuid16, p_setup);
- BE_STREAM_TO_UINT16(p_bcb->dst_uuid.uu.uuid16, p_setup);
+ uint16_t tmp;
+
+ BE_STREAM_TO_UINT16(tmp, p_setup);
+ p_bcb->src_uuid = Uuid::From16Bit(tmp);
+
+ BE_STREAM_TO_UINT16(tmp, p_setup);
+ p_bcb->dst_uuid = Uuid::From16Bit(tmp);
/* If nothing has changed don't bother the profile */
if (p_bcb->con_state == BNEP_STATE_CONNECTED &&
- p_bcb->src_uuid.uu.uuid16 == p_bcb->prv_src_uuid.uu.uuid16 &&
- p_bcb->dst_uuid.uu.uuid16 == p_bcb->prv_dst_uuid.uu.uuid16) {
+ p_bcb->src_uuid == p_bcb->prv_src_uuid &&
+ p_bcb->dst_uuid == p_bcb->prv_dst_uuid) {
bnep_send_conn_responce(p_bcb, BNEP_SETUP_CONN_OK);
return;
}
- } else if (p_bcb->dst_uuid.len == 4) {
- BE_STREAM_TO_UINT32(p_bcb->src_uuid.uu.uuid32, p_setup);
- BE_STREAM_TO_UINT32(p_bcb->dst_uuid.uu.uuid32, p_setup);
- } else if (p_bcb->dst_uuid.len == 16) {
- memcpy(p_bcb->src_uuid.uu.uuid128, p_setup, p_bcb->src_uuid.len);
- p_setup += p_bcb->src_uuid.len;
- memcpy(p_bcb->dst_uuid.uu.uuid128, p_setup, p_bcb->dst_uuid.len);
- p_setup += p_bcb->dst_uuid.len;
+ } else if (len == Uuid::kNumBytes32) {
+ uint32_t tmp;
+
+ BE_STREAM_TO_UINT32(tmp, p_setup);
+ p_bcb->src_uuid = Uuid::From32Bit(tmp);
+
+ BE_STREAM_TO_UINT32(tmp, p_setup);
+ p_bcb->dst_uuid = Uuid::From32Bit(tmp);
+ } else if (len == Uuid::kNumBytes128) {
+ p_bcb->src_uuid = Uuid::From128BitBE(p_setup);
+ p_setup += len;
+
+ p_bcb->dst_uuid = Uuid::From128BitBE(p_setup);
+ p_setup += len;
} else {
- BNEP_TRACE_ERROR("BNEP - Bad UID len %d in ConnReq", p_bcb->dst_uuid.len);
+ BNEP_TRACE_ERROR("BNEP - Bad UID len %d in ConnReq", len);
bnep_send_conn_responce(p_bcb, BNEP_SETUP_INVALID_UUID_SIZE);
return;
}
@@ -591,16 +603,16 @@
p_bcb->con_flags |= BNEP_FLAGS_SETUP_RCVD;
BNEP_TRACE_EVENT(
- "BNEP initiating security check for incoming call for uuid 0x%x",
- p_bcb->src_uuid.uu.uuid16);
+ "BNEP initiating security check for incoming call for uuid %s",
+ p_bcb->src_uuid.ToString().c_str());
#if (BNEP_DO_AUTH_FOR_ROLE_SWITCH == FALSE)
if (p_bcb->con_flags & BNEP_FLAGS_CONN_COMPLETED)
bnep_sec_check_complete(p_bcb->rem_bda, p_bcb, BTM_SUCCESS);
else
#endif
- btm_sec_mx_access_request(
- p_bcb->rem_bda, BT_PSM_BNEP, false, BTM_SEC_PROTO_BNEP,
- bnep_get_uuid32(&(p_bcb->src_uuid)), &bnep_sec_check_complete, p_bcb);
+ btm_sec_mx_access_request(p_bcb->rem_bda, BT_PSM_BNEP, false,
+ BTM_SEC_PROTO_BNEP, p_bcb->src_uuid.As32Bit(),
+ &bnep_sec_check_complete, p_bcb);
return;
}
@@ -664,10 +676,8 @@
/* Restore the earlier BNEP status */
p_bcb->con_state = BNEP_STATE_CONNECTED;
p_bcb->con_flags &= (~BNEP_FLAGS_SETUP_RCVD);
- memcpy((uint8_t*)&(p_bcb->src_uuid), (uint8_t*)&(p_bcb->prv_src_uuid),
- sizeof(tBT_UUID));
- memcpy((uint8_t*)&(p_bcb->dst_uuid), (uint8_t*)&(p_bcb->prv_dst_uuid),
- sizeof(tBT_UUID));
+ p_bcb->src_uuid = p_bcb->prv_src_uuid;
+ p_bcb->dst_uuid = p_bcb->prv_dst_uuid;
/* Ensure timer is stopped */
alarm_cancel(p_bcb->conn_timer);
@@ -1116,10 +1126,8 @@
BNEP_SECURITY_FAIL, is_role_change);
p_bcb->con_state = BNEP_STATE_CONNECTED;
- memcpy((uint8_t*)&(p_bcb->src_uuid), (uint8_t*)&(p_bcb->prv_src_uuid),
- sizeof(tBT_UUID));
- memcpy((uint8_t*)&(p_bcb->dst_uuid), (uint8_t*)&(p_bcb->prv_dst_uuid),
- sizeof(tBT_UUID));
+ p_bcb->src_uuid = p_bcb->prv_src_uuid;
+ p_bcb->dst_uuid = p_bcb->prv_dst_uuid;
return;
}
@@ -1152,10 +1160,8 @@
* state */
p_bcb->con_state = BNEP_STATE_CONNECTED;
p_bcb->con_flags &= (~BNEP_FLAGS_SETUP_RCVD);
- memcpy((uint8_t*)&(p_bcb->src_uuid), (uint8_t*)&(p_bcb->prv_src_uuid),
- sizeof(tBT_UUID));
- memcpy((uint8_t*)&(p_bcb->dst_uuid), (uint8_t*)&(p_bcb->prv_dst_uuid),
- sizeof(tBT_UUID));
+ p_bcb->src_uuid = p_bcb->prv_src_uuid;
+ p_bcb->dst_uuid = p_bcb->prv_dst_uuid;
return;
}
@@ -1167,8 +1173,8 @@
if (bnep_cb.p_conn_ind_cb) {
p_bcb->con_state = BNEP_STATE_CONN_SETUP;
- (*bnep_cb.p_conn_ind_cb)(p_bcb->handle, p_bcb->rem_bda, &p_bcb->dst_uuid,
- &p_bcb->src_uuid, is_role_change);
+ (*bnep_cb.p_conn_ind_cb)(p_bcb->handle, p_bcb->rem_bda, p_bcb->dst_uuid,
+ p_bcb->src_uuid, is_role_change);
} else {
/* Profile didn't register connection indication call back */
bnep_send_conn_responce(p_bcb, resp_code);
@@ -1256,26 +1262,3 @@
return BNEP_SUCCESS;
}
-
-/*******************************************************************************
- *
- * Function bnep_get_uuid32
- *
- * Description This function returns the 32-bit equivalent of the UUID
- *
- * Returns uint32_t - 32-bit equivalent of the UUID
- *
- ******************************************************************************/
-uint32_t bnep_get_uuid32(tBT_UUID* src_uuid) {
- uint32_t result;
-
- if (src_uuid->len == 2)
- return ((uint32_t)src_uuid->uu.uuid16);
- else if (src_uuid->len == 4)
- return (src_uuid->uu.uuid32 & 0x0000FFFF);
- else {
- result = src_uuid->uu.uuid128[2];
- result = (result << 8) | (src_uuid->uu.uuid128[3]);
- return result;
- }
-}
diff --git a/stack/btm/btm_ble_adv_filter.cc b/stack/btm/btm_ble_adv_filter.cc
index eb3fc4d..bcca3c8 100644
--- a/stack/btm/btm_ble_adv_filter.cc
+++ b/stack/btm/btm_ble_adv_filter.cc
@@ -34,6 +34,8 @@
#include "hcidefs.h"
#include "hcimsgs.h"
+using bluetooth::Uuid;
+
#define BTM_BLE_ADV_FILT_META_HDR_LENGTH 3
#define BTM_BLE_ADV_FILT_FEAT_SELN_LEN 13
#define BTM_BLE_ADV_FILT_TRACK_NUM 2
@@ -537,7 +539,8 @@
*/
void BTM_LE_PF_uuid_filter(tBTM_BLE_SCAN_COND_OP action,
tBTM_BLE_PF_FILT_INDEX filt_index,
- tBTM_BLE_PF_COND_TYPE filter_type, tBT_UUID uuid,
+ tBTM_BLE_PF_COND_TYPE filter_type,
+ const bluetooth::Uuid& uuid,
tBTM_BLE_PF_LOGIC_TYPE cond_logic,
tBTM_BLE_PF_COND_MASK* p_uuid_mask,
tBTM_BLE_PF_CFG_CBACK cb) {
@@ -559,36 +562,38 @@
UINT8_TO_STREAM(p, action);
UINT8_TO_STREAM(p, filt_index);
+ uint8_t uuid_len = uuid.GetShortestRepresentationSize();
if (action != BTM_BLE_SCAN_COND_CLEAR) {
- if (uuid.len == LEN_UUID_16) {
- UINT16_TO_STREAM(p, uuid.uu.uuid16);
- len += LEN_UUID_16;
- } else if (uuid.len == LEN_UUID_32) {
- UINT32_TO_STREAM(p, uuid.uu.uuid32);
- len += LEN_UUID_32;
- } else if (uuid.len == LEN_UUID_128) {
- ARRAY_TO_STREAM(p, uuid.uu.uuid128, LEN_UUID_128);
- len += LEN_UUID_128;
+ if (uuid_len == Uuid::kNumBytes16) {
+ UINT16_TO_STREAM(p, uuid.As16Bit());
+ len += Uuid::kNumBytes16;
+ } else if (uuid_len == Uuid::kNumBytes32) {
+ UINT32_TO_STREAM(p, uuid.As32Bit());
+ len += Uuid::kNumBytes32;
+ } else if (uuid_len == Uuid::kNumBytes128) {
+ const auto& tmp = uuid.To128BitLE();
+ ARRAY_TO_STREAM(p, tmp.data(), (int)Uuid::kNumBytes128);
+ len += Uuid::kNumBytes128;
} else {
- BTM_TRACE_ERROR("illegal UUID length: %d", uuid.len);
+ BTM_TRACE_ERROR("illegal UUID length: %d", uuid_len);
cb.Run(0, BTM_BLE_PF_CONFIG, 1 /*BTA_FAILURE*/);
return;
}
if (p_uuid_mask) {
- if (uuid.len == LEN_UUID_16) {
+ if (uuid_len == Uuid::kNumBytes16) {
UINT16_TO_STREAM(p, p_uuid_mask->uuid16_mask);
- len += LEN_UUID_16;
- } else if (uuid.len == LEN_UUID_32) {
+ len += Uuid::kNumBytes16;
+ } else if (uuid_len == Uuid::kNumBytes32) {
UINT32_TO_STREAM(p, p_uuid_mask->uuid32_mask);
- len += LEN_UUID_32;
- } else if (uuid.len == LEN_UUID_128) {
- ARRAY_TO_STREAM(p, p_uuid_mask->uuid128_mask, LEN_UUID_128);
- len += LEN_UUID_128;
+ len += Uuid::kNumBytes32;
+ } else if (uuid_len == Uuid::kNumBytes128) {
+ ARRAY_TO_STREAM(p, p_uuid_mask->uuid128_mask, (int)Uuid::kNumBytes128);
+ len += Uuid::kNumBytes128;
}
} else {
- memset(p, 0xff, uuid.len);
- len += uuid.len;
+ memset(p, 0xff, uuid_len);
+ len += uuid_len;
}
}
diff --git a/stack/btm/btm_inq.cc b/stack/btm/btm_inq.cc
index 213683c..df5eac2 100644
--- a/stack/btm/btm_inq.cc
+++ b/stack/btm/btm_inq.cc
@@ -43,6 +43,8 @@
#include "hcidefs.h"
#include "hcimsgs.h"
+using bluetooth::Uuid;
+
/* 3 second timeout waiting for responses */
#define BTM_INQ_REPLY_TIMEOUT_MS (3 * 1000)
@@ -121,8 +123,6 @@
uint8_t uuid_size,
uint8_t* p_num_uuid,
uint8_t* p_uuid_list_type);
-static uint16_t btm_convert_uuid_to_uuid16(const uint8_t* p_uuid,
- uint8_t uuid_size);
/*******************************************************************************
*
@@ -2433,7 +2433,8 @@
*
* Parameters p_eir - EIR
* eir_len - EIR len
- * uuid_size - LEN_UUID_16, LEN_UUID_32, LEN_UUID_128
+ * uuid_size - Uuid::kNumBytes16, Uuid::kNumBytes32,
+ * Uuid::kNumBytes128
* p_num_uuid - return number of UUID in found list
* p_uuid_list - return UUID list
* max_num_uuid - maximum number of UUID to be returned
@@ -2455,7 +2456,7 @@
uint8_t yy, xx;
uint16_t* p_uuid16 = (uint16_t*)p_uuid_list;
uint32_t* p_uuid32 = (uint32_t*)p_uuid_list;
- char buff[LEN_UUID_128 * 2 + 1];
+ char buff[Uuid::kNumBytes128 * 2 + 1];
p_uuid_data =
btm_eir_get_uuid_list(p_eir, eir_len, uuid_size, p_num_uuid, &type);
@@ -2472,22 +2473,22 @@
BTM_TRACE_DEBUG("%s: type = %02X, number of uuid = %d", __func__, type,
*p_num_uuid);
- if (uuid_size == LEN_UUID_16) {
+ if (uuid_size == Uuid::kNumBytes16) {
for (yy = 0; yy < *p_num_uuid; yy++) {
STREAM_TO_UINT16(*(p_uuid16 + yy), p_uuid_data);
BTM_TRACE_DEBUG(" 0x%04X", *(p_uuid16 + yy));
}
- } else if (uuid_size == LEN_UUID_32) {
+ } else if (uuid_size == Uuid::kNumBytes32) {
for (yy = 0; yy < *p_num_uuid; yy++) {
STREAM_TO_UINT32(*(p_uuid32 + yy), p_uuid_data);
BTM_TRACE_DEBUG(" 0x%08X", *(p_uuid32 + yy));
}
- } else if (uuid_size == LEN_UUID_128) {
+ } else if (uuid_size == Uuid::kNumBytes128) {
for (yy = 0; yy < *p_num_uuid; yy++) {
- STREAM_TO_ARRAY16(p_uuid_list + yy * LEN_UUID_128, p_uuid_data);
- for (xx = 0; xx < LEN_UUID_128; xx++)
+ STREAM_TO_ARRAY16(p_uuid_list + yy * Uuid::kNumBytes128, p_uuid_data);
+ for (xx = 0; xx < Uuid::kNumBytes128; xx++)
snprintf(buff + xx * 2, sizeof(buff) - xx * 2, "%02X",
- *(p_uuid_list + yy * LEN_UUID_128 + xx));
+ *(p_uuid_list + yy * Uuid::kNumBytes128 + xx));
BTM_TRACE_DEBUG(" 0x%s", buff);
}
}
@@ -2520,15 +2521,15 @@
uint8_t uuid_len;
switch (uuid_size) {
- case LEN_UUID_16:
+ case Uuid::kNumBytes16:
complete_type = BTM_EIR_COMPLETE_16BITS_UUID_TYPE;
more_type = BTM_EIR_MORE_16BITS_UUID_TYPE;
break;
- case LEN_UUID_32:
+ case Uuid::kNumBytes32:
complete_type = BTM_EIR_COMPLETE_32BITS_UUID_TYPE;
more_type = BTM_EIR_MORE_32BITS_UUID_TYPE;
break;
- case LEN_UUID_128:
+ case Uuid::kNumBytes128:
complete_type = BTM_EIR_COMPLETE_128BITS_UUID_TYPE;
more_type = BTM_EIR_MORE_128BITS_UUID_TYPE;
break;
@@ -2567,7 +2568,7 @@
******************************************************************************/
static uint16_t btm_convert_uuid_to_uuid16(const uint8_t* p_uuid,
uint8_t uuid_size) {
- static const uint8_t base_uuid[LEN_UUID_128] = {
+ static const uint8_t base_uuid[Uuid::kNumBytes128] = {
0xFB, 0x34, 0x9B, 0x5F, 0x80, 0x00, 0x00, 0x80,
0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
uint16_t uuid16 = 0;
@@ -2576,26 +2577,26 @@
uint8_t xx;
switch (uuid_size) {
- case LEN_UUID_16:
+ case Uuid::kNumBytes16:
STREAM_TO_UINT16(uuid16, p_uuid);
break;
- case LEN_UUID_32:
+ case Uuid::kNumBytes32:
STREAM_TO_UINT32(uuid32, p_uuid);
if (uuid32 < 0x10000) uuid16 = (uint16_t)uuid32;
break;
- case LEN_UUID_128:
+ case Uuid::kNumBytes128:
/* See if we can compress his UUID down to 16 or 32bit UUIDs */
is_base_uuid = true;
- for (xx = 0; xx < LEN_UUID_128 - 4; xx++) {
+ for (xx = 0; xx < Uuid::kNumBytes128 - 4; xx++) {
if (p_uuid[xx] != base_uuid[xx]) {
is_base_uuid = false;
break;
}
}
if (is_base_uuid) {
- if ((p_uuid[LEN_UUID_128 - 1] == 0) &&
- (p_uuid[LEN_UUID_128 - 2] == 0)) {
- p_uuid += (LEN_UUID_128 - 4);
+ if ((p_uuid[Uuid::kNumBytes128 - 1] == 0) &&
+ (p_uuid[Uuid::kNumBytes128 - 2] == 0)) {
+ p_uuid += (Uuid::kNumBytes128 - 4);
STREAM_TO_UINT16(uuid16, p_uuid);
}
}
@@ -2629,7 +2630,7 @@
uint8_t type = BTM_EIR_MORE_16BITS_UUID_TYPE;
p_uuid_data = btm_eir_get_uuid_list(p_eir, HCI_EXT_INQ_RESPONSE_LEN,
- LEN_UUID_16, &num_uuid, &type);
+ Uuid::kNumBytes16, &num_uuid, &type);
if (type == BTM_EIR_COMPLETE_16BITS_UUID_TYPE) {
p_results->eir_complete_list = true;
@@ -2648,21 +2649,21 @@
}
p_uuid_data = btm_eir_get_uuid_list(p_eir, HCI_EXT_INQ_RESPONSE_LEN,
- LEN_UUID_32, &num_uuid, &type);
+ Uuid::kNumBytes32, &num_uuid, &type);
if (p_uuid_data) {
for (yy = 0; yy < num_uuid; yy++) {
- uuid16 = btm_convert_uuid_to_uuid16(p_uuid_data, LEN_UUID_32);
- p_uuid_data += LEN_UUID_32;
+ uuid16 = btm_convert_uuid_to_uuid16(p_uuid_data, Uuid::kNumBytes32);
+ p_uuid_data += Uuid::kNumBytes32;
if (uuid16) BTM_AddEirService(p_results->eir_uuid, uuid16);
}
}
p_uuid_data = btm_eir_get_uuid_list(p_eir, HCI_EXT_INQ_RESPONSE_LEN,
- LEN_UUID_128, &num_uuid, &type);
+ Uuid::kNumBytes128, &num_uuid, &type);
if (p_uuid_data) {
for (yy = 0; yy < num_uuid; yy++) {
- uuid16 = btm_convert_uuid_to_uuid16(p_uuid_data, LEN_UUID_128);
- p_uuid_data += LEN_UUID_128;
+ uuid16 = btm_convert_uuid_to_uuid16(p_uuid_data, Uuid::kNumBytes128);
+ p_uuid_data += Uuid::kNumBytes128;
if (uuid16) BTM_AddEirService(p_results->eir_uuid, uuid16);
}
}
diff --git a/stack/gap/gap_ble.cc b/stack/gap/gap_ble.cc
index 2247a14..62f12aa 100644
--- a/stack/gap/gap_ble.cc
+++ b/stack/gap/gap_ble.cc
@@ -26,6 +26,7 @@
#include "gatt_api.h"
using base::StringPrintf;
+using bluetooth::Uuid;
namespace {
@@ -246,8 +247,7 @@
tGATT_READ_PARAM param;
memset(¶m, 0, sizeof(tGATT_READ_PARAM));
- param.service.uuid.len = LEN_UUID_16;
- param.service.uuid.uu.uuid16 = uuid;
+ param.service.uuid = Uuid::From16Bit(uuid);
param.service.s_handle = 1;
param.service.e_handle = 0xFFFF;
param.service.auth_req = 0;
@@ -393,23 +393,22 @@
*
******************************************************************************/
void gap_attr_db_init(void) {
- tBT_UUID app_uuid = {LEN_UUID_128, {0}};
uint16_t service_handle;
/* Fill our internal UUID with a fixed pattern 0x82 */
- memset(&app_uuid.uu.uuid128, 0x82, LEN_UUID_128);
+ std::array<uint8_t, Uuid::kNumBytes128> tmp;
+ tmp.fill(0x82);
+ Uuid app_uuid = Uuid::From128BitBE(tmp);
gatt_attr.fill({});
- gatt_if = GATT_Register(&app_uuid, &gap_cback);
+ gatt_if = GATT_Register(app_uuid, &gap_cback);
GATT_StartIf(gatt_if);
- bt_uuid_t svc_uuid, name_uuid, icon_uuid, pref_uuid, addr_res_uuid;
- uuid_128_from_16(&svc_uuid, UUID_SERVCLASS_GAP_SERVER);
- uuid_128_from_16(&name_uuid, GATT_UUID_GAP_DEVICE_NAME);
- uuid_128_from_16(&icon_uuid, GATT_UUID_GAP_ICON);
- uuid_128_from_16(&pref_uuid, GATT_UUID_GAP_PREF_CONN_PARAM);
- uuid_128_from_16(&addr_res_uuid, GATT_UUID_GAP_CENTRAL_ADDR_RESOL);
+ Uuid svc_uuid = Uuid::From16Bit(UUID_SERVCLASS_GAP_SERVER);
+ Uuid name_uuid = Uuid::From16Bit(GATT_UUID_GAP_DEVICE_NAME);
+ Uuid icon_uuid = Uuid::From16Bit(GATT_UUID_GAP_ICON);
+ Uuid addr_res_uuid = Uuid::From16Bit(GATT_UUID_GAP_CENTRAL_ADDR_RESOL);
btgatt_db_element_t service[] = {
{.type = BTGATT_DB_PRIMARY_SERVICE, .uuid = svc_uuid},
@@ -428,7 +427,7 @@
#if (BTM_PERIPHERAL_ENABLED == TRUE) /* Only needed for peripheral testing */
,
{.type = BTGATT_DB_CHARACTERISTIC,
- .uuid = pref_uuid,
+ .uuid = Uuid::From16Bit(GATT_UUID_GAP_PREF_CONN_PARAM),
.properties = GATT_CHAR_PROP_BIT_READ,
.permissions = GATT_PERM_READ}
#endif
diff --git a/stack/gatt/att_protocol.cc b/stack/gatt/att_protocol.cc
index ce809d0..73763f1 100644
--- a/stack/gatt/att_protocol.cc
+++ b/stack/gatt/att_protocol.cc
@@ -32,6 +32,7 @@
#define GATT_START_END_HANDLE_SIZE 4
using base::StringPrintf;
+using bluetooth::Uuid;
/**********************************************************************
* ATT protocl message building utility *
**********************************************************************/
@@ -124,9 +125,9 @@
*
******************************************************************************/
BT_HDR* attp_build_browse_cmd(uint8_t op_code, uint16_t s_hdl, uint16_t e_hdl,
- tBT_UUID uuid) {
+ const bluetooth::Uuid& uuid) {
const size_t payload_size =
- (GATT_OP_CODE_SIZE) + (GATT_START_END_HANDLE_SIZE) + (LEN_UUID_128);
+ (GATT_OP_CODE_SIZE) + (GATT_START_END_HANDLE_SIZE) + (Uuid::kNumBytes128);
BT_HDR* p_buf =
(BT_HDR*)osi_malloc(sizeof(BT_HDR) + payload_size + L2CAP_MIN_OFFSET);
diff --git a/stack/gatt/gatt_api.cc b/stack/gatt/gatt_api.cc
index 1ee014d..fd301df 100644
--- a/stack/gatt/gatt_api.cc
+++ b/stack/gatt/gatt_api.cc
@@ -23,6 +23,7 @@
******************************************************************************/
#include "bt_target.h"
+#include <base/strings/string_number_conversions.h>
#include <base/strings/stringprintf.h>
#include <stdio.h>
#include <string.h>
@@ -34,6 +35,7 @@
#include "l2c_api.h"
using base::StringPrintf;
+using bluetooth::Uuid;
/**
* Add an service handle range to the list in decending order of the start
@@ -95,53 +97,6 @@
return status;
}
-static uint8_t BASE_UUID[16] = {0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80,
- 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
-
-static int uuidType(unsigned char* p_uuid) {
- if (memcmp(p_uuid, BASE_UUID, 12) != 0) return LEN_UUID_128;
- if (memcmp(p_uuid + 14, BASE_UUID + 14, 2) != 0) return LEN_UUID_32;
-
- return LEN_UUID_16;
-}
-
-/*******************************************************************************
- * BTIF -> BTA conversion functions
- ******************************************************************************/
-
-static void btif_to_bta_uuid(tBT_UUID* p_dest, bt_uuid_t* p_src) {
- char* p_byte = (char*)p_src;
- int i = 0;
-
- p_dest->len = uuidType(p_src->uu);
-
- switch (p_dest->len) {
- case LEN_UUID_16:
- p_dest->uu.uuid16 = (p_src->uu[13] << 8) + p_src->uu[12];
- break;
-
- case LEN_UUID_32:
- p_dest->uu.uuid32 = (p_src->uu[15] << 24) + (p_src->uu[14] << 16) +
- (p_src->uu[13] << 8) + p_src->uu[12];
- break;
-
- case LEN_UUID_128:
- for (i = 0; i != 16; ++i) p_dest->uu.uuid128[i] = p_byte[i];
- break;
-
- default:
- LOG(ERROR) << __func__ << ": Unknown UUID length %d!" << +p_dest->len;
- break;
- }
-}
-
-void uuid_128_from_16(bt_uuid_t* uuid, uint16_t uuid16) {
- memcpy(uuid, &BASE_UUID, sizeof(bt_uuid_t));
-
- uuid->uu[13] = (uint8_t)((0xFF00 & uuid16) >> 8);
- uuid->uu[12] = (uint8_t)(0x00FF & uuid16);
-}
-
static uint16_t compute_service_size(btgatt_db_element_t* service, int count) {
int db_size = 0;
btgatt_db_element_t* el = service;
@@ -160,11 +115,11 @@
return db_size;
}
-static bool is_gatt_attr_type(const tBT_UUID& uuid) {
- if (uuid.len == LEN_UUID_16 && (uuid.uu.uuid16 == GATT_UUID_PRI_SERVICE ||
- uuid.uu.uuid16 == GATT_UUID_SEC_SERVICE ||
- uuid.uu.uuid16 == GATT_UUID_INCLUDE_SERVICE ||
- uuid.uu.uuid16 == GATT_UUID_CHAR_DECLARE)) {
+static bool is_gatt_attr_type(const Uuid& uuid) {
+ if (uuid == Uuid::From16Bit(GATT_UUID_PRI_SERVICE) ||
+ uuid == Uuid::From16Bit(GATT_UUID_SEC_SERVICE) ||
+ uuid == Uuid::From16Bit(GATT_UUID_INCLUDE_SERVICE) ||
+ uuid == Uuid::From16Bit(GATT_UUID_CHAR_DECLARE)) {
return true;
}
return false;
@@ -198,28 +153,22 @@
uint16_t s_hdl = 0;
bool save_hdl = false;
tGATT_REG* p_reg = gatt_get_regcb(gatt_if);
- tBT_UUID* p_app_uuid128;
bool is_pri = (service->type == BTGATT_DB_PRIMARY_SERVICE) ? true : false;
- tBT_UUID svc_uuid;
- btif_to_bta_uuid(&svc_uuid, &service->uuid);
+ Uuid svc_uuid = service->uuid;
LOG(INFO) << __func__;
- if (p_reg == NULL) {
+ if (!p_reg) {
LOG(ERROR) << "Inavlid gatt_if=" << +gatt_if;
return GATT_INTERNAL_ERROR;
}
- p_app_uuid128 = &p_reg->app_uuid128;
-
uint16_t num_handles = compute_service_size(service, count);
- if ((svc_uuid.len == LEN_UUID_16) &&
- (svc_uuid.uu.uuid16 == UUID_SERVCLASS_GATT_SERVER)) {
+ if (svc_uuid == Uuid::From16Bit(UUID_SERVCLASS_GATT_SERVER)) {
s_hdl = gatt_cb.hdl_cfg.gatt_start_hdl;
- } else if ((svc_uuid.len == LEN_UUID_16) &&
- (svc_uuid.uu.uuid16 == UUID_SERVCLASS_GAP_SERVER)) {
+ } else if (svc_uuid == Uuid::From16Bit(UUID_SERVCLASS_GAP_SERVER)) {
s_hdl = gatt_cb.hdl_cfg.gap_start_hdl;
} else {
if (!gatt_cb.hdl_list_info->empty()) {
@@ -241,7 +190,7 @@
}
tGATT_HDL_LIST_ELEM& list = gatt_add_an_item_to_list(s_hdl);
- list.asgn_range.app_uuid128 = *p_app_uuid128;
+ list.asgn_range.app_uuid128 = p_reg->app_uuid128;
list.asgn_range.svc_uuid = svc_uuid;
list.asgn_range.s_handle = s_hdl;
list.asgn_range.e_handle = s_hdl + num_handles - 1;
@@ -252,20 +201,18 @@
(*gatt_cb.cb_info.p_nv_save_callback)(true, &list.asgn_range);
}
- gatts_init_service_db(list.svc_db, &svc_uuid, is_pri, s_hdl, num_handles);
+ gatts_init_service_db(list.svc_db, svc_uuid, is_pri, s_hdl, num_handles);
VLOG(1) << StringPrintf(
- "%s: handles needed:%u s_hdl=%u e_hdl=%u %s[%x] is_primary=%d", __func__,
+ "%s: handles needed:%u s_hdl=%u e_hdl=%u %s is_primary=%d", __func__,
num_handles, list.asgn_range.s_handle, list.asgn_range.e_handle,
- ((list.asgn_range.svc_uuid.len == 2) ? "uuid16" : "uuid128"),
- list.asgn_range.svc_uuid.uu.uuid16, list.asgn_range.is_primary);
+ list.asgn_range.svc_uuid.ToString().c_str(), list.asgn_range.is_primary);
service->attribute_handle = s_hdl;
btgatt_db_element_t* el = service + 1;
for (int i = 0; i < count - 1; i++, el++) {
- tBT_UUID uuid;
- btif_to_bta_uuid(&uuid, &el->uuid);
+ const Uuid& uuid = el->uuid;
if (el->type == BTGATT_DB_CHARACTERISTIC) {
/* data validity checking */
@@ -282,8 +229,8 @@
if (is_gatt_attr_type(uuid)) {
LOG(ERROR) << StringPrintf(
"%s: attept to add characteristic with UUID equal to GATT "
- "Attribute Type 0x%04x ",
- __func__, uuid.uu.uuid16);
+ "Attribute Type %s ",
+ __func__, uuid.ToString().c_str());
return GATT_INTERNAL_ERROR;
}
@@ -293,8 +240,8 @@
if (is_gatt_attr_type(uuid)) {
LOG(ERROR) << StringPrintf(
"%s: attept to add descriptor with UUID equal to GATT "
- "Attribute Type 0x%04x ",
- __func__, uuid.uu.uuid16);
+ "Attribute Type %s",
+ __func__, uuid.ToString().c_str());
return GATT_INTERNAL_ERROR;
}
@@ -333,13 +280,13 @@
elem.p_db = &list.svc_db;
elem.is_primary = list.asgn_range.is_primary;
- memcpy(&elem.app_uuid, &list.asgn_range.app_uuid128, sizeof(tBT_UUID));
+ elem.app_uuid = list.asgn_range.app_uuid128;
elem.type = list.asgn_range.is_primary ? GATT_UUID_PRI_SERVICE
: GATT_UUID_SEC_SERVICE;
if (elem.type == GATT_UUID_PRI_SERVICE) {
- tBT_UUID* p_uuid = gatts_get_service_uuid(elem.p_db);
- elem.sdp_handle = gatt_add_sdp_record(p_uuid, elem.s_hdl, elem.e_hdl);
+ Uuid* p_uuid = gatts_get_service_uuid(elem.p_db);
+ elem.sdp_handle = gatt_add_sdp_record(*p_uuid, elem.s_hdl, elem.e_hdl);
} else {
elem.sdp_handle = 0;
}
@@ -355,17 +302,14 @@
return GATT_SERVICE_STARTED;
}
-bool is_active_service(tBT_UUID* p_app_uuid128, tBT_UUID* p_svc_uuid,
+bool is_active_service(const Uuid& app_uuid128, Uuid* p_svc_uuid,
uint16_t start_handle) {
for (auto& info : *gatt_cb.srv_list_info) {
- tBT_UUID* p_this_uuid = gatts_get_service_uuid(info.p_db);
+ Uuid* p_this_uuid = gatts_get_service_uuid(info.p_db);
- if (p_this_uuid && gatt_uuid_compare(*p_app_uuid128, info.app_uuid) &&
- gatt_uuid_compare(*p_svc_uuid, *p_this_uuid) &&
- (start_handle == info.s_hdl)) {
- LOG(ERROR) << "Active Service Found";
- gatt_dbg_display_uuid(*p_svc_uuid);
-
+ if (p_this_uuid && app_uuid128 == info.app_uuid &&
+ *p_svc_uuid == *p_this_uuid && (start_handle == info.s_hdl)) {
+ LOG(ERROR) << "Active Service Found: " << *p_svc_uuid;
return true;
}
}
@@ -386,7 +330,7 @@
* was not found.
*
******************************************************************************/
-bool GATTS_DeleteService(tGATT_IF gatt_if, tBT_UUID* p_svc_uuid,
+bool GATTS_DeleteService(tGATT_IF gatt_if, Uuid* p_svc_uuid,
uint16_t svc_inst) {
VLOG(1) << __func__;
@@ -396,8 +340,8 @@
return false;
}
- tBT_UUID* p_app_uuid128 = &p_reg->app_uuid128;
- auto it = gatt_find_hdl_buffer_by_app_id(p_app_uuid128, p_svc_uuid, svc_inst);
+ auto it =
+ gatt_find_hdl_buffer_by_app_id(p_reg->app_uuid128, p_svc_uuid, svc_inst);
if (it == gatt_cb.hdl_list_info->end()) {
LOG(ERROR) << "No Service found";
return false;
@@ -405,7 +349,7 @@
gatt_proc_srv_chg();
- if (is_active_service(p_app_uuid128, p_svc_uuid, svc_inst)) {
+ if (is_active_service(p_reg->app_uuid128, p_svc_uuid, svc_inst)) {
GATTS_StopService(it->asgn_range.s_handle);
}
@@ -660,7 +604,6 @@
(tGATT_CL_MSG*)&mtu);
}
-
/*******************************************************************************
*
* Function GATTC_Discover
@@ -695,7 +638,7 @@
if (!GATT_HANDLE_IS_VALID(p_param->s_handle) ||
!GATT_HANDLE_IS_VALID(p_param->e_handle) ||
/* search by type does not have a valid UUID param */
- (disc_type == GATT_DISC_SRVC_BY_UUID && p_param->service.len == 0)) {
+ (disc_type == GATT_DISC_SRVC_BY_UUID && p_param->service.IsEmpty())) {
return GATT_ILLEGAL_PARAMETER;
}
@@ -765,7 +708,7 @@
case GATT_READ_CHAR_VALUE:
p_clcb->s_handle = p_read->service.s_handle;
p_clcb->e_handle = p_read->service.e_handle;
- memcpy(&p_clcb->uuid, &p_read->service.uuid, sizeof(tBT_UUID));
+ p_clcb->uuid = p_read->service.uuid;
break;
case GATT_READ_MULTIPLE: {
p_clcb->s_handle = 0;
@@ -778,7 +721,7 @@
}
case GATT_READ_BY_HANDLE:
case GATT_READ_PARTIAL:
- memset(&p_clcb->uuid, 0, sizeof(tBT_UUID));
+ p_clcb->uuid = Uuid::kEmpty;
p_clcb->s_handle = p_read->by_handle.handle;
if (type == GATT_READ_PARTIAL) {
@@ -990,19 +933,16 @@
* with GATT
*
******************************************************************************/
-tGATT_IF GATT_Register(tBT_UUID* p_app_uuid128, tGATT_CBACK* p_cb_info) {
+tGATT_IF GATT_Register(const Uuid& app_uuid128, tGATT_CBACK* p_cb_info) {
tGATT_REG* p_reg;
uint8_t i_gatt_if = 0;
tGATT_IF gatt_if = 0;
- LOG(INFO) << __func__;
- gatt_dbg_display_uuid(*p_app_uuid128);
+ LOG(INFO) << __func__ << app_uuid128;
for (i_gatt_if = 0, p_reg = gatt_cb.cl_rcb; i_gatt_if < GATT_MAX_APPS;
i_gatt_if++, p_reg++) {
- if (p_reg->in_use &&
- !memcmp(p_app_uuid128->uu.uuid128, p_reg->app_uuid128.uu.uuid128,
- LEN_UUID_128)) {
+ if (p_reg->in_use && p_reg->app_uuid128 == app_uuid128) {
LOG(ERROR) << "application already registered.";
return 0;
}
@@ -1013,7 +953,7 @@
if (!p_reg->in_use) {
memset(p_reg, 0, sizeof(tGATT_REG));
i_gatt_if++; /* one based number */
- p_reg->app_uuid128 = *p_app_uuid128;
+ p_reg->app_uuid128 = app_uuid128;
gatt_if = p_reg->gatt_if = (tGATT_IF)i_gatt_if;
p_reg->app_cb = *p_cb_info;
p_reg->in_use = true;
@@ -1063,7 +1003,7 @@
}
/* free all services db buffers if owned by this application */
- gatt_free_srvc_db_buffer_app_id(&p_reg->app_uuid128);
+ gatt_free_srvc_db_buffer_app_id(p_reg->app_uuid128);
/* When an application deregisters, check remove the link associated with the
* app */
diff --git a/stack/gatt/gatt_attr.cc b/stack/gatt/gatt_attr.cc
index f4e028a..4f3578d 100644
--- a/stack/gatt/gatt_attr.cc
+++ b/stack/gatt/gatt_attr.cc
@@ -26,12 +26,12 @@
#include "bt_target.h"
#include "bt_utils.h"
-#include "btcore/include/uuid.h"
#include "gatt_api.h"
#include "gatt_int.h"
#include "osi/include/osi.h"
using base::StringPrintf;
+using bluetooth::Uuid;
#define GATTP_MAX_NUM_INC_SVR 0
#define GATTP_MAX_CHAR_NUM 2
@@ -269,21 +269,19 @@
*
******************************************************************************/
void gatt_profile_db_init(void) {
- tBT_UUID app_uuid = {LEN_UUID_128, {0}};
uint16_t service_handle = 0;
/* Fill our internal UUID with a fixed pattern 0x81 */
- memset(&app_uuid.uu.uuid128, 0x81, LEN_UUID_128);
+ std::array<uint8_t, Uuid::kNumBytes128> tmp;
+ tmp.fill(0x81);
/* Create a GATT profile service */
- gatt_cb.gatt_if = GATT_Register(&app_uuid, &gatt_profile_cback);
+ gatt_cb.gatt_if = GATT_Register(Uuid::From128BitBE(tmp), &gatt_profile_cback);
GATT_StartIf(gatt_cb.gatt_if);
- bt_uuid_t service_uuid;
- uuid_128_from_16(&service_uuid, UUID_SERVCLASS_GATT_SERVER);
+ Uuid service_uuid = Uuid::From16Bit(UUID_SERVCLASS_GATT_SERVER);
- bt_uuid_t char_uuid;
- uuid_128_from_16(&char_uuid, GATT_UUID_GATT_SRV_CHGD);
+ Uuid char_uuid = Uuid::From16Bit(GATT_UUID_GATT_SRV_CHGD);
btgatt_db_element_t service[] = {
{.type = BTGATT_DB_PRIMARY_SERVICE, .uuid = service_uuid},
@@ -329,7 +327,7 @@
break;
case GATT_DISC_CHAR_DSCPT: /* stage 3 */
- if (p_data->type.uu.uuid16 == GATT_UUID_CHAR_CLIENT_CONFIG) {
+ if (p_data->type == Uuid::From16Bit(GATT_UUID_CHAR_CLIENT_CONFIG)) {
p_clcb->s_handle = p_data->handle;
p_clcb->ccc_result++;
}
@@ -398,16 +396,14 @@
case GATT_SVC_CHANGED_SERVICE: /* discover GATT service */
srvc_disc_param.s_handle = 1;
srvc_disc_param.e_handle = 0xffff;
- srvc_disc_param.service.len = 2;
- srvc_disc_param.service.uu.uuid16 = UUID_SERVCLASS_GATT_SERVER;
+ srvc_disc_param.service = Uuid::From16Bit(UUID_SERVCLASS_GATT_SERVER);
GATTC_Discover(p_clcb->conn_id, GATT_DISC_SRVC_BY_UUID, &srvc_disc_param);
break;
case GATT_SVC_CHANGED_CHARACTERISTIC: /* discover service change char */
srvc_disc_param.s_handle = 1;
srvc_disc_param.e_handle = p_clcb->e_handle;
- srvc_disc_param.service.len = 2;
- srvc_disc_param.service.uu.uuid16 = GATT_UUID_GATT_SRV_CHGD;
+ srvc_disc_param.service = Uuid::From16Bit(GATT_UUID_GATT_SRV_CHGD);
GATTC_Discover(p_clcb->conn_id, GATT_DISC_CHAR, &srvc_disc_param);
break;
diff --git a/stack/gatt/gatt_cl.cc b/stack/gatt/gatt_cl.cc
index a3fcf08..cce268c 100644
--- a/stack/gatt/gatt_cl.cc
+++ b/stack/gatt/gatt_cl.cc
@@ -43,6 +43,8 @@
#define GATT_READ_BY_TYPE_RSP_MIN_LEN 1
using base::StringPrintf;
+using bluetooth::Uuid;
+
/*******************************************************************************
* G L O B A L G A T T D A T A *
******************************************************************************/
@@ -87,27 +89,27 @@
cl_req.browse.e_handle = p_clcb->e_handle;
if (disc_type_to_uuid[p_clcb->op_subtype] != 0) {
- cl_req.browse.uuid.len = 2;
- cl_req.browse.uuid.uu.uuid16 = disc_type_to_uuid[p_clcb->op_subtype];
+ cl_req.browse.uuid =
+ bluetooth::Uuid::From16Bit(disc_type_to_uuid[p_clcb->op_subtype]);
}
if (p_clcb->op_subtype ==
GATT_DISC_SRVC_BY_UUID) /* fill in the FindByTypeValue request info*/
{
- cl_req.find_type_value.uuid.len = 2;
- cl_req.find_type_value.uuid.uu.uuid16 =
- disc_type_to_uuid[p_clcb->op_subtype];
+ cl_req.find_type_value.uuid =
+ bluetooth::Uuid::From16Bit(disc_type_to_uuid[p_clcb->op_subtype]);
cl_req.find_type_value.s_handle = p_clcb->s_handle;
cl_req.find_type_value.e_handle = p_clcb->e_handle;
- cl_req.find_type_value.value_len = p_clcb->uuid.len;
- /* if service type is 32 bits UUID, convert it now */
- if (p_clcb->uuid.len == LEN_UUID_32) {
- cl_req.find_type_value.value_len = LEN_UUID_128;
- gatt_convert_uuid32_to_uuid128(cl_req.find_type_value.value,
- p_clcb->uuid.uu.uuid32);
+
+ size_t size = p_clcb->uuid.GetShortestRepresentationSize();
+ cl_req.find_type_value.value_len = size;
+ if (size == Uuid::kNumBytes32) {
+ /* if service type is 32 bits UUID, convert it now */
+ memcpy(cl_req.find_type_value.value, p_clcb->uuid.To128BitLE().data(),
+ Uuid::kNumBytes128);
} else
- memcpy(cl_req.find_type_value.value, &p_clcb->uuid.uu,
- p_clcb->uuid.len);
+ memcpy(cl_req.find_type_value.value, p_clcb->uuid.To128BitLE().data(),
+ size);
}
st = attp_send_cl_msg(*p_clcb->p_tcb, p_clcb, op_code, &cl_req);
@@ -143,10 +145,9 @@
msg.browse.s_handle = p_clcb->s_handle;
msg.browse.e_handle = p_clcb->e_handle;
if (p_clcb->op_subtype == GATT_READ_BY_TYPE)
- memcpy(&msg.browse.uuid, &p_clcb->uuid, sizeof(tBT_UUID));
+ msg.browse.uuid = p_clcb->uuid;
else {
- msg.browse.uuid.len = LEN_UUID_16;
- msg.browse.uuid.uu.uuid16 = GATT_UUID_CHAR_DECLARE;
+ msg.browse.uuid = bluetooth::Uuid::From16Bit(GATT_UUID_CHAR_DECLARE);
}
break;
@@ -373,15 +374,13 @@
return;
memset(&result, 0, sizeof(tGATT_DISC_RES));
- result.type.len = 2;
- result.type.uu.uuid16 = GATT_UUID_PRI_SERVICE;
+ result.type = bluetooth::Uuid::From16Bit(GATT_UUID_PRI_SERVICE);
/* returns a series of handle ranges */
while (len >= 4) {
STREAM_TO_UINT16(result.handle, p);
STREAM_TO_UINT16(result.value.group_value.e_handle, p);
- memcpy(&result.value.group_value.service_type, &p_clcb->uuid,
- sizeof(tBT_UUID));
+ result.value.group_value.service_type = p_clcb->uuid;
len -= 4;
@@ -428,9 +427,9 @@
len -= 1;
if (type == GATT_INFO_TYPE_PAIR_16)
- uuid_len = LEN_UUID_16;
+ uuid_len = Uuid::kNumBytes16;
else if (type == GATT_INFO_TYPE_PAIR_128)
- uuid_len = LEN_UUID_128;
+ uuid_len = Uuid::kNumBytes128;
while (len >= uuid_len + 2) {
STREAM_TO_UINT16(result.handle, p);
@@ -438,7 +437,7 @@
if (uuid_len > 0) {
if (!gatt_parse_uuid_from_cmd(&result.type, uuid_len, &p)) break;
} else
- memcpy(&result.type, &p_clcb->uuid, sizeof(tBT_UUID));
+ result.type = p_clcb->uuid;
len -= (uuid_len + 2);
@@ -590,9 +589,10 @@
tGATT_REG* p_reg;
uint16_t conn_id;
tGATT_STATUS encrypt_status;
- uint8_t *p = p_data, i, event = (op_code == GATT_HANDLE_VALUE_NOTIF)
- ? GATTC_OPTYPE_NOTIFICATION
- : GATTC_OPTYPE_INDICATION;
+ uint8_t *p = p_data, i,
+ event = (op_code == GATT_HANDLE_VALUE_NOTIF)
+ ? GATTC_OPTYPE_NOTIFICATION
+ : GATTC_OPTYPE_INDICATION;
VLOG(1) << __func__;
@@ -718,8 +718,8 @@
memset(&record_value, 0, sizeof(tGATT_DISC_VALUE));
result.handle = handle;
- result.type.len = 2;
- result.type.uu.uuid16 = disc_type_to_uuid[p_clcb->op_subtype];
+ result.type =
+ bluetooth::Uuid::From16Bit(disc_type_to_uuid[p_clcb->op_subtype]);
/* discover all services */
if (p_clcb->operation == GATTC_OPTYPE_DISCOVERY &&
@@ -752,8 +752,10 @@
}
if (value_len == 6) {
- STREAM_TO_UINT16(record_value.incl_service.service_type.uu.uuid16, p);
- record_value.incl_service.service_type.len = LEN_UUID_16;
+ uint16_t tmp;
+ STREAM_TO_UINT16(tmp, p);
+ record_value.incl_service.service_type =
+ bluetooth::Uuid::From16Bit(tmp);
} else if (value_len == 4) {
p_clcb->s_handle = record_value.incl_service.s_handle;
p_clcb->read_uuid128.wait_for_read_rsp = true;
@@ -807,10 +809,14 @@
}
/* UUID not matching */
- if (!gatt_uuid_compare(record_value.dclr_value.char_uuid, p_clcb->uuid)) {
+ if (!p_clcb->uuid.IsEmpty() &&
+ !record_value.dclr_value.char_uuid.IsEmpty() &&
+ record_value.dclr_value.char_uuid != p_clcb->uuid) {
len -= (value_len + 2);
continue; /* skip the result, and look for next one */
- } else if (p_clcb->operation == GATTC_OPTYPE_READ)
+ }
+
+ if (p_clcb->operation == GATTC_OPTYPE_READ)
/* UUID match for read characteristic value */
{
/* only read the first matching UUID characteristic value, and
@@ -906,12 +912,9 @@
p_clcb->read_uuid128.wait_for_read_rsp) {
p_clcb->s_handle = p_clcb->read_uuid128.next_disc_start_hdl;
p_clcb->read_uuid128.wait_for_read_rsp = false;
- if (len == LEN_UUID_128) {
- memcpy(p_clcb->read_uuid128.result.value.incl_service.service_type.uu
- .uuid128,
- p, len);
- p_clcb->read_uuid128.result.value.incl_service.service_type.len =
- LEN_UUID_128;
+ if (len == Uuid::kNumBytes128) {
+ p_clcb->read_uuid128.result.value.incl_service.service_type =
+ bluetooth::Uuid::From128BitLE(p);
if (p_clcb->p_reg->app_cb.p_disc_res_cb)
(*p_clcb->p_reg->app_cb.p_disc_res_cb)(p_clcb->conn_id,
p_clcb->op_subtype,
diff --git a/stack/gatt/gatt_db.cc b/stack/gatt/gatt_db.cc
index ac3d959..0ba408e 100644
--- a/stack/gatt/gatt_db.cc
+++ b/stack/gatt/gatt_db.cc
@@ -35,10 +35,12 @@
#include "osi/include/osi.h"
using base::StringPrintf;
+using bluetooth::Uuid;
+
/*******************************************************************************
* L O C A L F U N C T I O N P R O T O T Y P E S *
******************************************************************************/
-static tGATT_ATTR& allocate_attr_in_db(tGATT_SVC_DB& db, const tBT_UUID& uuid,
+static tGATT_ATTR& allocate_attr_in_db(tGATT_SVC_DB& db, const Uuid& uuid,
tGATT_PERM perm);
static tGATT_STATUS gatts_send_app_read_request(
tGATT_TCB& tcb, uint8_t op_code, uint16_t handle, uint16_t offset,
@@ -47,8 +49,8 @@
/**
* Initialize a memory space to be a service database.
*/
-void gatts_init_service_db(tGATT_SVC_DB& db, tBT_UUID* p_service, bool is_pri,
- uint16_t s_hdl, uint16_t num_handle) {
+void gatts_init_service_db(tGATT_SVC_DB& db, const Uuid& service_uuid,
+ bool is_pri, uint16_t s_hdl, uint16_t num_handle) {
db.attr_list.reserve(num_handle);
VLOG(1) << StringPrintf("%s: s_hdl= %d num_handle= %d", __func__, s_hdl,
@@ -59,14 +61,14 @@
db.end_handle = s_hdl + num_handle;
/* add service declration record */
- tBT_UUID uuid = {LEN_UUID_16, {0}};
- uuid.uu.uuid16 = is_pri ? GATT_UUID_PRI_SERVICE : GATT_UUID_SEC_SERVICE;
+ Uuid uuid =
+ Uuid::From16Bit(is_pri ? GATT_UUID_PRI_SERVICE : GATT_UUID_SEC_SERVICE);
tGATT_ATTR& attr = allocate_attr_in_db(db, uuid, GATT_PERM_READ);
- attr.p_value.reset((tGATT_ATTR_VALUE*)(new tBT_UUID));
- memcpy(&attr.p_value->uuid, p_service, sizeof(tBT_UUID));
+ attr.p_value.reset((tGATT_ATTR_VALUE*)(new Uuid));
+ attr.p_value->uuid = service_uuid;
}
-tBT_UUID* gatts_get_service_uuid(tGATT_SVC_DB* p_db) {
+Uuid* gatts_get_service_uuid(tGATT_SVC_DB* p_db) {
if (!p_db || p_db->attr_list.empty()) {
LOG(ERROR) << "service DB empty";
return NULL;
@@ -119,8 +121,8 @@
return GATT_INSUF_KEY_SIZE;
}
- if (read_long && attr.uuid.len == LEN_UUID_16) {
- switch (attr.uuid.uu.uuid16) {
+ if (read_long && attr.uuid.Is16Bit()) {
+ switch (attr.uuid.As16Bit()) {
case GATT_UUID_PRI_SERVICE:
case GATT_UUID_SEC_SERVICE:
case GATT_UUID_CHAR_DECLARE:
@@ -162,75 +164,70 @@
uint8_t** p_data, bool read_long,
uint16_t mtu, uint16_t* p_len,
tGATT_SEC_FLAG sec_flag, uint8_t key_size) {
- uint16_t len = 0, uuid16 = 0;
uint8_t* p = *p_data;
- VLOG(1)
- << __func__
- << StringPrintf(
- " uuid=0x%04x perm=0x%02x sec_flag=0x%x offset=%d read_long=%d",
- attr16.uuid.uu.uuid16, attr16.permission, sec_flag, offset,
- read_long);
+ VLOG(1) << __func__ << " uuid=" << attr16.uuid
+ << StringPrintf(" perm=0x%02x sec_flag=0x%x offset=%d read_long=%d",
+ attr16.permission, sec_flag, offset, read_long);
tGATT_STATUS status = gatts_check_attr_readability(attr16, offset, read_long,
sec_flag, key_size);
-
if (status != GATT_SUCCESS) return status;
- if (attr16.uuid.len == LEN_UUID_16) uuid16 = attr16.uuid.uu.uuid16;
-
- status = GATT_NO_RESOURCES;
-
- if (uuid16 == GATT_UUID_PRI_SERVICE || uuid16 == GATT_UUID_SEC_SERVICE) {
- len = attr16.p_value->uuid.len;
- if (mtu >= attr16.p_value->uuid.len) {
- gatt_build_uuid_to_stream(&p, attr16.p_value->uuid);
- status = GATT_SUCCESS;
- }
- } else if (uuid16 == GATT_UUID_CHAR_DECLARE) {
- tGATT_ATTR* val_attr = &attr16 + 1;
- len = (val_attr->uuid.len == LEN_UUID_16) ? 5 : 19;
-
- if (mtu >= len) {
- UINT8_TO_STREAM(p, attr16.p_value->char_decl.property);
- UINT16_TO_STREAM(p, attr16.p_value->char_decl.char_val_handle);
-
- if (val_attr->uuid.len == LEN_UUID_16) {
- UINT16_TO_STREAM(p, val_attr->uuid.uu.uuid16);
- }
- /* convert a 32bits UUID to 128 bits */
- else if (val_attr->uuid.len == LEN_UUID_32) {
- gatt_convert_uuid32_to_uuid128(p, val_attr->uuid.uu.uuid32);
- p += LEN_UUID_128;
- } else {
- ARRAY_TO_STREAM(p, val_attr->uuid.uu.uuid128, LEN_UUID_128);
- }
- status = GATT_SUCCESS;
- }
-
- } else if (uuid16 == GATT_UUID_INCLUDE_SERVICE) {
- if (attr16.p_value->incl_handle.service_type.len == LEN_UUID_16)
- len = 6;
- else
- len = 4;
-
- if (mtu >= len) {
- UINT16_TO_STREAM(p, attr16.p_value->incl_handle.s_handle);
- UINT16_TO_STREAM(p, attr16.p_value->incl_handle.e_handle);
-
- if (attr16.p_value->incl_handle.service_type.len == LEN_UUID_16) {
- UINT16_TO_STREAM(p, attr16.p_value->incl_handle.service_type.uu.uuid16);
- }
- status = GATT_SUCCESS;
- }
- } else /* characteristic description or characteristic value */
- {
- status = GATT_PENDING;
+ if (!attr16.uuid.Is16Bit()) {
+ /* characteristic description or characteristic value */
+ return GATT_PENDING;
}
- *p_len = len;
- *p_data = p;
- return status;
+ uint16_t uuid16 = attr16.uuid.As16Bit();
+
+ if (uuid16 == GATT_UUID_PRI_SERVICE || uuid16 == GATT_UUID_SEC_SERVICE) {
+ *p_len = attr16.p_value->uuid.GetShortestRepresentationSize();
+ if (mtu < *p_len) return GATT_NO_RESOURCES;
+
+ gatt_build_uuid_to_stream(&p, attr16.p_value->uuid);
+ return GATT_SUCCESS;
+ }
+
+ if (uuid16 == GATT_UUID_CHAR_DECLARE) {
+ tGATT_ATTR* val_attr = &attr16 + 1;
+ uint8_t val_len = val_attr->uuid.GetShortestRepresentationSize();
+ *p_len = (val_len == Uuid::kNumBytes16) ? 5 : 19;
+
+ if (mtu < *p_len) return GATT_NO_RESOURCES;
+
+ UINT8_TO_STREAM(p, attr16.p_value->char_decl.property);
+ UINT16_TO_STREAM(p, attr16.p_value->char_decl.char_val_handle);
+
+ if (val_len == Uuid::kNumBytes16) {
+ UINT16_TO_STREAM(p, val_attr->uuid.As16Bit());
+ } else {
+ /* if 32 bit UUID, convert to 128 bit */
+ ARRAY_TO_STREAM(p, val_attr->uuid.To128BitLE(), (int)Uuid::kNumBytes128);
+ }
+ return GATT_SUCCESS;
+ }
+
+ if (uuid16 == GATT_UUID_INCLUDE_SERVICE) {
+ tGATT_INCL_SRVC& incl_handle = attr16.p_value->incl_handle;
+ if (incl_handle.service_type.Is16Bit())
+ *p_len = 6;
+ else
+ *p_len = 4;
+
+ if (mtu < *p_len) return GATT_NO_RESOURCES;
+
+ UINT16_TO_STREAM(p, incl_handle.s_handle);
+ UINT16_TO_STREAM(p, incl_handle.e_handle);
+
+ if (incl_handle.service_type.Is16Bit()) {
+ UINT16_TO_STREAM(p, incl_handle.service_type.As16Bit());
+ }
+ return GATT_SUCCESS;
+ }
+
+ /* characteristic description or characteristic value (again) */
+ return GATT_PENDING;
}
/*******************************************************************************
@@ -253,7 +250,7 @@
******************************************************************************/
tGATT_STATUS gatts_db_read_attr_value_by_type(
tGATT_TCB& tcb, tGATT_SVC_DB* p_db, uint8_t op_code, BT_HDR* p_rsp,
- uint16_t s_handle, uint16_t e_handle, tBT_UUID type, uint16_t* p_len,
+ uint16_t s_handle, uint16_t e_handle, const Uuid& type, uint16_t* p_len,
tGATT_SEC_FLAG sec_flag, uint8_t key_size, uint32_t trans_id,
uint16_t* p_cur_handle) {
tGATT_STATUS status = GATT_NOT_FOUND;
@@ -262,9 +259,7 @@
if (p_db) {
for (tGATT_ATTR& attr : p_db->attr_list) {
- tBT_UUID attr_uuid = attr.uuid;
-
- if (attr.handle >= s_handle && gatt_uuid_compare(type, attr_uuid)) {
+ if (attr.handle >= s_handle && type == attr.uuid) {
if (*p_len <= 2) {
status = GATT_NO_RESOURCES;
break;
@@ -304,7 +299,7 @@
uint8_t flag = 0;
if (BTM_GetSecurityFlags(tcb.peer_bda, &flag)) {
if ((tcb.att_lcid == L2CAP_ATT_CID) && (status == GATT_PENDING) &&
- (type.uu.uuid16 == GATT_UUID_GAP_DEVICE_NAME)) {
+ (type.As16Bit() == GATT_UUID_GAP_DEVICE_NAME)) {
if ((flag & (BTM_SEC_LINK_KEY_KNOWN | BTM_SEC_FLAG_ENCRYPTED)) ==
BTM_SEC_LINK_KEY_KNOWN) {
tACL_CONN* p = btm_bda_to_acl(tcb.peer_bda, BT_TRANSPORT_LE);
@@ -328,13 +323,14 @@
*
*/
uint16_t gatts_add_included_service(tGATT_SVC_DB& db, uint16_t s_handle,
- uint16_t e_handle, tBT_UUID service) {
- tBT_UUID uuid = {LEN_UUID_16, {GATT_UUID_INCLUDE_SERVICE}};
+ uint16_t e_handle, const Uuid& service) {
+ Uuid uuid = Uuid::From16Bit(GATT_UUID_INCLUDE_SERVICE);
- VLOG(1) << StringPrintf("%s: s_hdl = 0x%04x e_hdl = 0x%04x uuid = 0x%04x",
- __func__, s_handle, e_handle, service.uu.uuid16);
+ VLOG(1) << __func__
+ << StringPrintf(": s_hdl=0x%04x e_hdl=0x%04x ", s_handle, e_handle)
+ << "service uuid = " << service;
- if (service.len == 0 || s_handle == 0 || e_handle == 0) {
+ if (service.IsEmpty() || s_handle == 0 || e_handle == 0) {
LOG(ERROR) << __func__ << ": Illegal Params.";
return 0;
}
@@ -344,7 +340,7 @@
attr.p_value.reset((tGATT_ATTR_VALUE*)(new tGATT_INCL_SRVC));
attr.p_value->incl_handle.s_handle = s_handle;
attr.p_value->incl_handle.e_handle = e_handle;
- memcpy(&attr.p_value->incl_handle.service_type, &service, sizeof(tBT_UUID));
+ attr.p_value->incl_handle.service_type = service;
return attr.handle;
}
@@ -366,8 +362,8 @@
******************************************************************************/
uint16_t gatts_add_characteristic(tGATT_SVC_DB& db, tGATT_PERM perm,
tGATT_CHAR_PROP property,
- tBT_UUID& char_uuid) {
- tBT_UUID uuid = {LEN_UUID_16, {GATT_UUID_CHAR_DECLARE}};
+ const Uuid& char_uuid) {
+ Uuid uuid = Uuid::From16Bit(GATT_UUID_CHAR_DECLARE);
VLOG(1) << StringPrintf("%s: perm=0x%0x property=0x%0x", __func__, perm,
property);
@@ -384,46 +380,6 @@
/*******************************************************************************
*
- * Function gatt_convertchar_descr_type
- *
- * Description Convert a char descript UUID into descriptor type.
- *
- * Returns descriptor type.
- *
- ******************************************************************************/
-uint8_t gatt_convertchar_descr_type(tBT_UUID* p_descr_uuid) {
- tBT_UUID std_descr = {LEN_UUID_16, {GATT_UUID_CHAR_EXT_PROP}};
-
- if (gatt_uuid_compare(std_descr, *p_descr_uuid))
- return GATT_DESCR_EXT_DSCPTOR;
-
- std_descr.uu.uuid16++;
- if (gatt_uuid_compare(std_descr, *p_descr_uuid))
- return GATT_DESCR_USER_DSCPTOR;
-
- std_descr.uu.uuid16++;
- if (gatt_uuid_compare(std_descr, *p_descr_uuid)) return GATT_DESCR_CLT_CONFIG;
-
- std_descr.uu.uuid16++;
- if (gatt_uuid_compare(std_descr, *p_descr_uuid)) return GATT_DESCR_SVR_CONFIG;
-
- std_descr.uu.uuid16++;
- if (gatt_uuid_compare(std_descr, *p_descr_uuid))
- return GATT_DESCR_PRES_FORMAT;
-
- std_descr.uu.uuid16++;
- if (gatt_uuid_compare(std_descr, *p_descr_uuid))
- return GATT_DESCR_AGGR_FORMAT;
-
- std_descr.uu.uuid16++;
- if (gatt_uuid_compare(std_descr, *p_descr_uuid))
- return GATT_DESCR_VALID_RANGE;
-
- return GATT_DESCR_UNKNOWN;
-}
-
-/*******************************************************************************
- *
* Function gatts_add_char_descr
*
* Description This function add a characteristics descriptor.
@@ -437,9 +393,9 @@
*
******************************************************************************/
uint16_t gatts_add_char_descr(tGATT_SVC_DB& db, tGATT_PERM perm,
- tBT_UUID& descr_uuid) {
- VLOG(1) << StringPrintf("gatts_add_char_descr uuid=0x%04x",
- descr_uuid.uu.uuid16);
+ const Uuid& descr_uuid) {
+ VLOG(1) << StringPrintf("gatts_add_char_descr uuid=%s",
+ descr_uuid.ToString().c_str());
/* Add characteristic descriptors */
tGATT_ATTR& char_dscptr = allocate_attr_in_db(db, descr_uuid, perm);
@@ -626,13 +582,14 @@
status = GATT_INSUF_AUTHENTICATION;
LOG(ERROR) << __func__
<< ": GATT_INSUF_AUTHENTICATION: LE security mode 2 required";
- } else /* writable: must be char value declaration or char descritpors
- */
+ } else /* writable: must be char value declaration or char descritpors */
{
uint16_t max_size = 0;
- if (p_attr->uuid.len == LEN_UUID_16) {
- switch (p_attr->uuid.uu.uuid16) {
+ if (p_attr->uuid.IsEmpty()) {
+ status = GATT_INVALID_PDU;
+ } else if (p_attr->uuid.Is16Bit()) {
+ switch (p_attr->uuid.As16Bit()) {
case GATT_UUID_CHAR_PRESENT_FORMAT: /* should be readable only */
case GATT_UUID_CHAR_EXT_PROP: /* should be readable only */
case GATT_UUID_CHAR_AGG_FORMAT: /* should be readable only */
@@ -650,31 +607,28 @@
status = GATT_SUCCESS;
break;
}
- } else if (p_attr->uuid.len == LEN_UUID_128 ||
- p_attr->uuid.len == LEN_UUID_32) {
+ } else { // 32 or 128 bit UUID
status = GATT_SUCCESS;
- } else {
- status = GATT_INVALID_PDU;
}
if (p_data == NULL && len > 0) {
- status = GATT_INVALID_PDU;
+ return GATT_INVALID_PDU;
}
+
/* these attribute does not allow write blob */
- else if ((p_attr->uuid.len == LEN_UUID_16) &&
- (p_attr->uuid.uu.uuid16 == GATT_UUID_CHAR_CLIENT_CONFIG ||
- p_attr->uuid.uu.uuid16 == GATT_UUID_CHAR_SRVR_CONFIG)) {
- if (op_code == GATT_REQ_PREPARE_WRITE &&
- offset != 0) /* does not allow write blob */
- {
+ if (p_attr->uuid.Is16Bit() &&
+ (p_attr->uuid.As16Bit() == GATT_UUID_CHAR_CLIENT_CONFIG ||
+ p_attr->uuid.As16Bit() == GATT_UUID_CHAR_SRVR_CONFIG)) {
+ if (op_code == GATT_REQ_PREPARE_WRITE && offset != 0) {
+ /* does not allow write blob */
status = GATT_NOT_LONG;
LOG(ERROR) << __func__ << ": GATT_NOT_LONG";
- } else if (len != max_size) /* data does not match the required format */
- {
+ } else if (len != max_size) {
+ /* data does not match the required format */
status = GATT_INVALID_ATTR_LEN;
LOG(ERROR) << __func__ << ": GATT_INVALID_PDU";
} else {
- status = GATT_SUCCESS;
+ return GATT_SUCCESS;
}
}
}
@@ -682,26 +636,6 @@
return status;
}
-static void uuid_to_str(const tBT_UUID bt_uuid, char* str_buf, size_t buf_len) {
- if (bt_uuid.len == LEN_UUID_16) {
- snprintf(str_buf, buf_len, "0x%04x", bt_uuid.uu.uuid16);
- } else if (bt_uuid.len == LEN_UUID_32) {
- snprintf(str_buf, buf_len, "0x%08x", bt_uuid.uu.uuid32);
- } else if (bt_uuid.len == LEN_UUID_128) {
- int x = snprintf(str_buf, buf_len, "%02x%02x%02x%02x-%02x%02x-%02x%02x-",
- bt_uuid.uu.uuid128[15], bt_uuid.uu.uuid128[14],
- bt_uuid.uu.uuid128[13], bt_uuid.uu.uuid128[12],
- bt_uuid.uu.uuid128[11], bt_uuid.uu.uuid128[10],
- bt_uuid.uu.uuid128[9], bt_uuid.uu.uuid128[8]);
- snprintf(&str_buf[x], buf_len - x, "%02x%02x-%02x%02x%02x%02x%02x%02x",
- bt_uuid.uu.uuid128[7], bt_uuid.uu.uuid128[6],
- bt_uuid.uu.uuid128[5], bt_uuid.uu.uuid128[4],
- bt_uuid.uu.uuid128[3], bt_uuid.uu.uuid128[2],
- bt_uuid.uu.uuid128[1], bt_uuid.uu.uuid128[0]);
- } else
- snprintf(str_buf, buf_len, "Unknown (len=%d)", bt_uuid.len);
-}
-
/**
* Description Allocate a memory space for a new attribute, and link this
* attribute into the database attribute list.
@@ -713,7 +647,7 @@
* Returns pointer to the newly allocated attribute.
*
*/
-static tGATT_ATTR& allocate_attr_in_db(tGATT_SVC_DB& db, const tBT_UUID& uuid,
+static tGATT_ATTR& allocate_attr_in_db(tGATT_SVC_DB& db, const Uuid& uuid,
tGATT_PERM perm) {
if (db.next_handle >= db.end_handle) {
LOG(FATAL) << __func__
@@ -726,10 +660,6 @@
attr.handle = db.next_handle++;
attr.uuid = uuid;
attr.permission = perm;
-
- char uuid_str[37];
- uuid_to_str(attr.uuid, uuid_str, sizeof(uuid_str));
-
return attr;
}
diff --git a/stack/gatt/gatt_int.h b/stack/gatt/gatt_int.h
index 4274e71..4e61d35 100644
--- a/stack/gatt/gatt_int.h
+++ b/stack/gatt/gatt_int.h
@@ -101,7 +101,7 @@
/* GATT client FIND_TYPE_VALUE_Request data */
typedef struct {
- tBT_UUID uuid; /* type of attribute to be found */
+ bluetooth::Uuid uuid; /* type of attribute to be found */
uint16_t s_handle; /* starting handle */
uint16_t e_handle; /* ending handle */
uint16_t value_len; /* length of the attribute value */
@@ -152,7 +152,7 @@
/* attribute value maintained in the server database
*/
typedef union {
- tBT_UUID uuid; /* service declaration */
+ bluetooth::Uuid uuid; /* service declaration */
tGATT_CHAR_DECL char_decl; /* characteristic declaration */
tGATT_INCL_SRVC incl_handle; /* included service */
} tGATT_ATTR_VALUE;
@@ -170,7 +170,7 @@
std::unique_ptr<tGATT_ATTR_VALUE> p_value;
tGATT_PERM permission;
uint16_t handle;
- tBT_UUID uuid;
+ bluetooth::Uuid uuid;
bt_gatt_db_attribute_type_t gatt_type;
} tGATT_ATTR;
@@ -188,7 +188,7 @@
/* attribute handle, service UUID and a set of GATT server callback. */
typedef struct {
- tBT_UUID app_uuid128;
+ bluetooth::Uuid app_uuid128;
tGATT_CBACK app_cb;
tGATT_IF gatt_if; /* one based */
bool in_use;
@@ -254,7 +254,7 @@
/* attribute handle, service UUID and a set of GATT server callback. */
typedef struct {
tGATT_SVC_DB* p_db; /* pointer to the service database */
- tBT_UUID app_uuid; /* applicatino UUID */
+ bluetooth::Uuid app_uuid; /* application UUID */
uint32_t sdp_handle; /* primamry service SDP handle */
uint16_t type; /* service type UUID, primary or secondary */
uint16_t s_hdl; /* service starting handle */
@@ -308,7 +308,7 @@
tGATT_REG* p_reg; /* owner of this CLCB */
uint8_t sccb_idx;
uint8_t* p_attr_buf; /* attribute buffer for read multiple, prepare write */
- tBT_UUID uuid;
+ bluetooth::Uuid uuid;
uint16_t conn_id; /* connection handle */
uint16_t s_handle; /* starting handle of the active request */
uint16_t e_handle; /* ending handle of the active request */
@@ -432,14 +432,12 @@
/* utility functions */
extern uint8_t* gatt_dbg_op_name(uint8_t op_code);
-extern uint32_t gatt_add_sdp_record(tBT_UUID* p_uuid, uint16_t start_hdl,
- uint16_t end_hdl);
-extern bool gatt_parse_uuid_from_cmd(tBT_UUID* p_uuid, uint16_t len,
+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(uint8_t** p_dst, tBT_UUID uuid);
-extern bool gatt_uuid_compare(tBT_UUID src, tBT_UUID tar);
-extern void gatt_convert_uuid32_to_uuid128(uint8_t uuid_128[LEN_UUID_128],
- uint32_t uuid_32);
+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,
tBT_TRANSPORT transport, uint8_t* p_sec_flag,
uint8_t* p_key_size);
@@ -452,7 +450,6 @@
extern tGATT_STATUS gatt_send_error_rsp(tGATT_TCB& tcb, uint8_t err_code,
uint8_t op_code, uint16_t handle,
bool deq);
-extern void gatt_dbg_display_uuid(tBT_UUID bt_uuid);
extern bool gatt_is_srv_chg_ind_pending(tGATT_TCB* p_tcb);
extern tGATTS_SRV_CHG* gatt_is_bda_in_the_srv_chg_clt_list(
@@ -464,12 +461,13 @@
extern void gatt_set_srv_chg(void);
extern void gatt_delete_dev_from_srv_chg_clt_list(const RawAddress& bd_addr);
extern tGATT_VALUE* gatt_add_pending_ind(tGATT_TCB* p_tcb, tGATT_VALUE* p_ind);
-extern void gatt_free_srvc_db_buffer_app_id(tBT_UUID* p_app_id);
+extern void gatt_free_srvc_db_buffer_app_id(const bluetooth::Uuid& app_id);
extern bool gatt_cl_send_next_cmd_inq(tGATT_TCB& tcb);
/* reserved handle list */
extern std::list<tGATT_HDL_LIST_ELEM>::iterator gatt_find_hdl_buffer_by_app_id(
- tBT_UUID* p_app_uuid128, tBT_UUID* p_svc_uuid, uint16_t svc_inst);
+ const bluetooth::Uuid& app_uuid128, bluetooth::Uuid* p_svc_uuid,
+ uint16_t svc_inst);
extern tGATT_HDL_LIST_ELEM* gatt_find_hdl_buffer_by_handle(uint16_t handle);
extern tGATTS_SRV_CHG* gatt_add_srv_chg_clt(tGATTS_SRV_CHG* p_srv_chg);
@@ -486,9 +484,6 @@
/* server function */
extern std::list<tGATT_SRV_LIST_ELEM>::iterator gatt_sr_find_i_rcb_by_handle(
uint16_t handle);
-extern bool gatt_sr_find_i_rcb_by_app_id(tBT_UUID* p_app_uuid128,
- tBT_UUID* p_svc_uuid,
- uint16_t svc_inst);
extern tGATT_STATUS gatt_sr_process_app_rsp(tGATT_TCB& tcb, tGATT_IF gatt_if,
uint32_t trans_id, uint8_t op_code,
tGATT_STATUS status,
@@ -559,21 +554,22 @@
extern void gatt_set_sec_act(tGATT_TCB* p_tcb, tGATT_SEC_ACTION sec_act);
/* gatt_db.cc */
-extern void gatts_init_service_db(tGATT_SVC_DB& db, tBT_UUID* p_service,
- bool is_pri, uint16_t s_hdl,
- uint16_t num_handle);
+extern void gatts_init_service_db(tGATT_SVC_DB& db,
+ const bluetooth::Uuid& service, bool is_pri,
+ uint16_t s_hdl, uint16_t num_handle);
extern uint16_t gatts_add_included_service(tGATT_SVC_DB& db, uint16_t s_handle,
- uint16_t e_handle, tBT_UUID service);
+ uint16_t e_handle,
+ const bluetooth::Uuid& service);
extern uint16_t gatts_add_characteristic(tGATT_SVC_DB& db, tGATT_PERM perm,
tGATT_CHAR_PROP property,
- tBT_UUID& char_uuid);
+ const bluetooth::Uuid& char_uuid);
extern uint16_t gatts_add_char_descr(tGATT_SVC_DB& db, tGATT_PERM perm,
- tBT_UUID& dscp_uuid);
+ const bluetooth::Uuid& dscp_uuid);
extern tGATT_STATUS gatts_db_read_attr_value_by_type(
tGATT_TCB& tcb, tGATT_SVC_DB* p_db, uint8_t op_code, BT_HDR* p_rsp,
- uint16_t s_handle, uint16_t e_handle, tBT_UUID type, uint16_t* p_len,
- tGATT_SEC_FLAG sec_flag, uint8_t key_size, uint32_t trans_id,
- uint16_t* p_cur_handle);
+ uint16_t s_handle, uint16_t e_handle, const bluetooth::Uuid& type,
+ uint16_t* p_len, tGATT_SEC_FLAG sec_flag, uint8_t key_size,
+ uint32_t trans_id, uint16_t* p_cur_handle);
extern tGATT_STATUS gatts_read_attr_value_by_handle(
tGATT_TCB& tcb, tGATT_SVC_DB* p_db, uint8_t op_code, uint16_t handle,
uint16_t offset, uint8_t* p_value, uint16_t* p_len, uint16_t mtu,
@@ -585,6 +581,6 @@
uint16_t handle,
tGATT_SEC_FLAG sec_flag,
uint8_t key_size);
-extern tBT_UUID* gatts_get_service_uuid(tGATT_SVC_DB* p_db);
+extern bluetooth::Uuid* gatts_get_service_uuid(tGATT_SVC_DB* p_db);
#endif
diff --git a/stack/gatt/gatt_sr.cc b/stack/gatt/gatt_sr.cc
index 211e57c..264bc82 100644
--- a/stack/gatt/gatt_sr.cc
+++ b/stack/gatt/gatt_sr.cc
@@ -33,6 +33,8 @@
#define GATT_MTU_REQ_MIN_LEN 2
using base::StringPrintf;
+using bluetooth::Uuid;
+
/*******************************************************************************
*
* Function gatt_sr_enqueue_cmd
@@ -439,57 +441,59 @@
******************************************************************************/
static tGATT_STATUS gatt_build_primary_service_rsp(
BT_HDR* p_msg, tGATT_TCB& tcb, uint8_t op_code, uint16_t s_hdl,
- uint16_t e_hdl, UNUSED_ATTR uint8_t* p_data, tBT_UUID value) {
+ uint16_t e_hdl, UNUSED_ATTR uint8_t* p_data, const Uuid& value) {
tGATT_STATUS status = GATT_NOT_FOUND;
- uint8_t handle_len = 4, *p;
- tBT_UUID* p_uuid;
+ uint8_t handle_len = 4;
- p = (uint8_t*)(p_msg + 1) + L2CAP_MIN_OFFSET;
+ uint8_t* p = (uint8_t*)(p_msg + 1) + L2CAP_MIN_OFFSET;
for (tGATT_SRV_LIST_ELEM& el : *gatt_cb.srv_list_info) {
- if (el.s_hdl >= s_hdl && el.s_hdl <= e_hdl &&
- el.type == GATT_UUID_PRI_SERVICE) {
- p_uuid = gatts_get_service_uuid(el.p_db);
- if (p_uuid != NULL) {
- if (op_code == GATT_REQ_READ_BY_GRP_TYPE) handle_len = 4 + p_uuid->len;
+ if (el.s_hdl < s_hdl || el.s_hdl > e_hdl ||
+ el.type != GATT_UUID_PRI_SERVICE) {
+ continue;
+ }
- /* get the length byte in the repsonse */
- if (p_msg->offset == 0) {
- *p++ = op_code + 1;
- p_msg->len++;
- p_msg->offset = handle_len;
+ Uuid* p_uuid = gatts_get_service_uuid(el.p_db);
+ if (!p_uuid) continue;
- if (op_code == GATT_REQ_READ_BY_GRP_TYPE) {
- *p++ = (uint8_t)p_msg->offset; /* length byte */
- p_msg->len++;
- }
- }
+ if (op_code == GATT_REQ_READ_BY_GRP_TYPE)
+ handle_len = 4 + p_uuid->GetShortestRepresentationSize();
- if (p_msg->len + p_msg->offset <= tcb.payload_size &&
- handle_len == p_msg->offset) {
- if (op_code != GATT_REQ_FIND_TYPE_VALUE ||
- gatt_uuid_compare(value, *p_uuid)) {
- UINT16_TO_STREAM(p, el.s_hdl);
+ /* get the length byte in the repsonse */
+ if (p_msg->offset == 0) {
+ *p++ = op_code + 1;
+ p_msg->len++;
+ p_msg->offset = handle_len;
- if (gatt_cb.last_primary_s_handle &&
- gatt_cb.last_primary_s_handle == el.s_hdl) {
- VLOG(1) << "Use 0xFFFF for the last primary attribute";
- /* see GATT ERRATA 4065, 4063, ATT ERRATA 4062 */
- UINT16_TO_STREAM(p, 0xFFFF);
- } else {
- UINT16_TO_STREAM(p, el.e_hdl);
- }
-
- if (op_code == GATT_REQ_READ_BY_GRP_TYPE)
- gatt_build_uuid_to_stream(&p, *p_uuid);
-
- status = GATT_SUCCESS;
- p_msg->len += p_msg->offset;
- }
- } else
- break;
+ if (op_code == GATT_REQ_READ_BY_GRP_TYPE) {
+ *p++ = (uint8_t)p_msg->offset; /* length byte */
+ p_msg->len++;
}
}
+
+ if (p_msg->len + p_msg->offset > tcb.payload_size ||
+ handle_len != p_msg->offset) {
+ break;
+ }
+
+ if (op_code == GATT_REQ_FIND_TYPE_VALUE && value != *p_uuid) continue;
+
+ UINT16_TO_STREAM(p, el.s_hdl);
+
+ if (gatt_cb.last_primary_s_handle &&
+ gatt_cb.last_primary_s_handle == el.s_hdl) {
+ VLOG(1) << "Use 0xFFFF for the last primary attribute";
+ /* see GATT ERRATA 4065, 4063, ATT ERRATA 4062 */
+ UINT16_TO_STREAM(p, 0xFFFF);
+ } else {
+ UINT16_TO_STREAM(p, el.e_hdl);
+ }
+
+ if (op_code == GATT_REQ_READ_BY_GRP_TYPE)
+ gatt_build_uuid_to_stream(&p, *p_uuid);
+
+ status = GATT_SUCCESS;
+ p_msg->len += p_msg->offset;
}
p_msg->offset = L2CAP_MIN_OFFSET;
@@ -518,25 +522,25 @@
if (attr.handle < s_hdl) continue;
+ uint8_t uuid_len = attr.uuid.GetShortestRepresentationSize();
if (p_msg->offset == 0)
- p_msg->offset = (attr.uuid.len == LEN_UUID_16) ? GATT_INFO_TYPE_PAIR_16
- : GATT_INFO_TYPE_PAIR_128;
+ p_msg->offset = (uuid_len == Uuid::kNumBytes16) ? GATT_INFO_TYPE_PAIR_16
+ : GATT_INFO_TYPE_PAIR_128;
if (len < info_pair_len[p_msg->offset - 1]) return GATT_NO_RESOURCES;
if (p_msg->offset == GATT_INFO_TYPE_PAIR_16 &&
- attr.uuid.len == LEN_UUID_16) {
+ uuid_len == Uuid::kNumBytes16) {
UINT16_TO_STREAM(p, attr.handle);
- UINT16_TO_STREAM(p, attr.uuid.uu.uuid16);
+ UINT16_TO_STREAM(p, attr.uuid.As16Bit());
} else if (p_msg->offset == GATT_INFO_TYPE_PAIR_128 &&
- attr.uuid.len == LEN_UUID_128) {
+ uuid_len == Uuid::kNumBytes128) {
UINT16_TO_STREAM(p, attr.handle);
- ARRAY_TO_STREAM(p, attr.uuid.uu.uuid128, LEN_UUID_128);
+ ARRAY_TO_STREAM(p, attr.uuid.To128BitLE(), (int)Uuid::kNumBytes128);
} else if (p_msg->offset == GATT_INFO_TYPE_PAIR_128 &&
- attr.uuid.len == LEN_UUID_32) {
+ uuid_len == Uuid::kNumBytes32) {
UINT16_TO_STREAM(p, attr.handle);
- gatt_convert_uuid32_to_uuid128(p, attr.uuid.uu.uuid32);
- p += LEN_UUID_128;
+ ARRAY_TO_STREAM(p, attr.uuid.To128BitLE(), (int)Uuid::kNumBytes128);
} else {
LOG(ERROR) << "format mismatch";
return GATT_NO_RESOURCES;
@@ -568,7 +572,7 @@
}
static tGATT_STATUS gatts_validate_packet_format(uint8_t op_code, uint16_t& len,
- uint8_t*& p, tBT_UUID* p_uuid,
+ uint8_t*& p, Uuid* p_uuid,
uint16_t& s_hdl,
uint16_t& e_hdl) {
tGATT_STATUS ret = read_handles(len, p, s_hdl, e_hdl);
@@ -602,7 +606,7 @@
void gatts_process_primary_service_req(tGATT_TCB& tcb, uint8_t op_code,
uint16_t len, uint8_t* p_data) {
uint16_t s_hdl = 0, e_hdl = 0;
- tBT_UUID uuid;
+ Uuid uuid = Uuid::kEmpty;
uint8_t reason =
gatts_validate_packet_format(op_code, len, p_data, &uuid, s_hdl, e_hdl);
@@ -611,25 +615,23 @@
return;
}
- tBT_UUID primary_service = {LEN_UUID_16, {GATT_UUID_PRI_SERVICE}};
- if (!gatt_uuid_compare(uuid, primary_service)) {
+ if (uuid != Uuid::From16Bit(GATT_UUID_PRI_SERVICE)) {
if (op_code == GATT_REQ_READ_BY_GRP_TYPE) {
gatt_send_error_rsp(tcb, GATT_UNSUPPORT_GRP_TYPE, op_code, s_hdl, false);
- VLOG(1) << StringPrintf("unexpected ReadByGrpType Group: 0x%04x",
- uuid.uu.uuid16);
+ VLOG(1) << StringPrintf("unexpected ReadByGrpType Group: %s",
+ uuid.ToString().c_str());
return;
}
// we do not support ReadByTypeValue with any non-primamry_service type
gatt_send_error_rsp(tcb, GATT_NOT_FOUND, op_code, s_hdl, false);
- VLOG(1) << StringPrintf("unexpected ReadByTypeValue type: 0x%04x",
- uuid.uu.uuid16);
+ VLOG(1) << StringPrintf("unexpected ReadByTypeValue type: %s",
+ uuid.ToString().c_str());
return;
}
// TODO: we assume theh value is UUID, there is no such requirement in spec
- tBT_UUID value;
- memset(&value, 0, sizeof(tBT_UUID));
+ Uuid value = Uuid::kEmpty;
if (op_code == GATT_REQ_FIND_TYPE_VALUE) {
if (gatt_parse_uuid_from_cmd(&value, len, &p_data) == false) {
gatt_send_error_rsp(tcb, GATT_INVALID_PDU, op_code, s_hdl, false);
@@ -775,7 +777,7 @@
******************************************************************************/
void gatts_process_read_by_type_req(tGATT_TCB& tcb, uint8_t op_code,
uint16_t len, uint8_t* p_data) {
- tBT_UUID uuid;
+ Uuid uuid = Uuid::kEmpty;
uint16_t s_hdl, e_hdl, err_hdl = 0;
tGATT_STATUS reason =
gatts_validate_packet_format(op_code, len, p_data, &uuid, s_hdl, e_hdl);
diff --git a/stack/gatt/gatt_utils.cc b/stack/gatt/gatt_utils.cc
index ad8ab7a..976bcae 100644
--- a/stack/gatt/gatt_utils.cc
+++ b/stack/gatt/gatt_utils.cc
@@ -37,6 +37,7 @@
#include "sdp_api.h"
using base::StringPrintf;
+using bluetooth::Uuid;
/* check if [x, y] and [a, b] have overlapping range */
#define GATT_VALIDATE_HANDLE_RANGE(x, y, a, b) ((y) >= (a) && (x) <= (b))
@@ -76,10 +77,6 @@
"ATT_HANDLE_VALUE_CONF",
"ATT_OP_CODE_MAX"};
-static const uint8_t base_uuid[LEN_UUID_128] = {
- 0xFB, 0x34, 0x9B, 0x5F, 0x80, 0x00, 0x00, 0x80,
- 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
-
/*******************************************************************************
*
* Function gatt_free_pending_ind
@@ -220,12 +217,12 @@
*
******************************************************************************/
std::list<tGATT_HDL_LIST_ELEM>::iterator gatt_find_hdl_buffer_by_app_id(
- tBT_UUID* p_app_uuid128, tBT_UUID* p_svc_uuid, uint16_t start_handle) {
+ const Uuid& app_uuid128, Uuid* p_svc_uuid, uint16_t start_handle) {
auto end_it = gatt_cb.hdl_list_info->end();
auto it = gatt_cb.hdl_list_info->begin();
for (; it != end_it; it++) {
- if (gatt_uuid_compare(*p_app_uuid128, it->asgn_range.app_uuid128) &&
- gatt_uuid_compare(*p_svc_uuid, it->asgn_range.svc_uuid) &&
+ if (app_uuid128 == it->asgn_range.app_uuid128 &&
+ *p_svc_uuid == it->asgn_range.svc_uuid &&
(start_handle == it->asgn_range.s_handle)) {
return it;
}
@@ -238,11 +235,11 @@
* free the service attribute database buffers by the owner of the service app
* ID.
*/
-void gatt_free_srvc_db_buffer_app_id(tBT_UUID* p_app_id) {
+void gatt_free_srvc_db_buffer_app_id(const Uuid& app_id) {
auto it = gatt_cb.hdl_list_info->begin();
auto end = gatt_cb.hdl_list_info->end();
while (it != end) {
- if (memcmp(p_app_id, &it->asgn_range.app_uuid128, sizeof(tBT_UUID)) == 0) {
+ if (app_id == it->asgn_range.app_uuid128) {
it = gatt_cb.hdl_list_info->erase(it);
} else {
it++;
@@ -461,179 +458,51 @@
return NULL;
}
-/*******************************************************************************
- *
- * Function gatt_convert_uuid16_to_uuid128
- *
- * Description Convert a 16 bits UUID to be an standard 128 bits one.
- *
- * Returns true if two uuid match; false otherwise.
- *
- ******************************************************************************/
-void gatt_convert_uuid16_to_uuid128(uint8_t uuid_128[LEN_UUID_128],
- uint16_t uuid_16) {
- uint8_t* p = &uuid_128[LEN_UUID_128 - 4];
-
- memcpy(uuid_128, base_uuid, LEN_UUID_128);
-
- UINT16_TO_STREAM(p, uuid_16);
-}
-
-/*******************************************************************************
- *
- * Function gatt_convert_uuid32_to_uuid128
- *
- * Description Convert a 32 bits UUID to be an standard 128 bits one.
- *
- * Returns true if two uuid match; false otherwise.
- *
- ******************************************************************************/
-void gatt_convert_uuid32_to_uuid128(uint8_t uuid_128[LEN_UUID_128],
- uint32_t uuid_32) {
- uint8_t* p = &uuid_128[LEN_UUID_128 - 4];
-
- memcpy(uuid_128, base_uuid, LEN_UUID_128);
-
- UINT32_TO_STREAM(p, uuid_32);
-}
-/*******************************************************************************
- *
- * Function gatt_uuid_compare
- *
- * Description Compare two UUID to see if they are the same.
- *
- * Returns true if two uuid match; false otherwise.
- *
- ******************************************************************************/
-bool gatt_uuid_compare(tBT_UUID src, tBT_UUID tar) {
- uint8_t su[LEN_UUID_128], tu[LEN_UUID_128];
- uint8_t *ps, *pt;
-
- /* any of the UUID is unspecified */
- if (src.len == 0 || tar.len == 0) {
- return true;
- }
-
- /* If both are 16-bit, we can do a simple compare */
- if (src.len == LEN_UUID_16 && tar.len == LEN_UUID_16) {
- return src.uu.uuid16 == tar.uu.uuid16;
- }
-
- /* If both are 32-bit, we can do a simple compare */
- if (src.len == LEN_UUID_32 && tar.len == LEN_UUID_32) {
- return src.uu.uuid32 == tar.uu.uuid32;
- }
-
- /* One or both of the UUIDs is 128-bit */
- if (src.len == LEN_UUID_16) {
- /* convert a 16 bits UUID to 128 bits value */
- gatt_convert_uuid16_to_uuid128(su, src.uu.uuid16);
- ps = su;
- } else if (src.len == LEN_UUID_32) {
- gatt_convert_uuid32_to_uuid128(su, src.uu.uuid32);
- ps = su;
- } else
- ps = src.uu.uuid128;
-
- if (tar.len == LEN_UUID_16) {
- /* convert a 16 bits UUID to 128 bits value */
- gatt_convert_uuid16_to_uuid128(tu, tar.uu.uuid16);
- pt = tu;
- } else if (tar.len == LEN_UUID_32) {
- /* convert a 32 bits UUID to 128 bits value */
- gatt_convert_uuid32_to_uuid128(tu, tar.uu.uuid32);
- pt = tu;
- } else
- pt = tar.uu.uuid128;
-
- return (memcmp(ps, pt, LEN_UUID_128) == 0);
-}
-
-/*******************************************************************************
- *
- * Function gatt_build_uuid_to_stream
- *
- * Description Add UUID into stream.
- *
- * Returns UUID length.
- *
- ******************************************************************************/
-uint8_t gatt_build_uuid_to_stream(uint8_t** p_dst, tBT_UUID uuid) {
+/** 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;
- uint8_t len = 0;
+ size_t len = uuid.GetShortestRepresentationSize();
- if (uuid.len == LEN_UUID_16) {
- UINT16_TO_STREAM(p, uuid.uu.uuid16);
- len = LEN_UUID_16;
- } else if (uuid.len ==
- LEN_UUID_32) /* always convert 32 bits into 128 bits as alwats */
- {
- gatt_convert_uuid32_to_uuid128(p, uuid.uu.uuid32);
- p += LEN_UUID_128;
- len = LEN_UUID_128;
- } else if (uuid.len == LEN_UUID_128) {
- ARRAY_TO_STREAM(p, uuid.uu.uuid128, LEN_UUID_128);
- len = LEN_UUID_128;
+ if (uuid.IsEmpty()) {
+ return 0;
+ }
+
+ if (len == Uuid::kNumBytes16) {
+ UINT16_TO_STREAM(p, uuid.As16Bit());
+ } else if (len == Uuid::kNumBytes32) {
+ /* always convert 32 bits into 128 bits */
+ ARRAY_TO_STREAM(p, uuid.To128BitLE(), (int)Uuid::kNumBytes128);
+ len = Uuid::kNumBytes128;
+ } else if (len == Uuid::kNumBytes128) {
+ ARRAY_TO_STREAM(p, uuid.To128BitLE(), (int)Uuid::kNumBytes128);
}
*p_dst = p;
return len;
}
-/*******************************************************************************
- *
- * Function gatt_parse_uuid_from_cmd
- *
- * Description Convert a 128 bits UUID into a 16 bits UUID.
- *
- * Returns true if command sent, otherwise false.
- *
- ******************************************************************************/
-bool gatt_parse_uuid_from_cmd(tBT_UUID* p_uuid_rec, uint16_t uuid_size,
+bool gatt_parse_uuid_from_cmd(Uuid* p_uuid_rec, uint16_t uuid_size,
uint8_t** p_data) {
- bool is_base_uuid, ret = true;
- uint8_t xx;
+ bool ret = true;
uint8_t* p_uuid = *p_data;
- memset(p_uuid_rec, 0, sizeof(tBT_UUID));
-
switch (uuid_size) {
- case LEN_UUID_16:
- p_uuid_rec->len = uuid_size;
- STREAM_TO_UINT16(p_uuid_rec->uu.uuid16, p_uuid);
- *p_data += LEN_UUID_16;
- break;
+ case Uuid::kNumBytes16: {
+ uint16_t val;
+ STREAM_TO_UINT16(val, p_uuid);
+ *p_uuid_rec = Uuid::From16Bit(val);
+ *p_data += Uuid::kNumBytes16;
+ return true;
+ }
- case LEN_UUID_128:
- /* See if we can compress his UUID down to 16 or 32bit UUIDs */
- is_base_uuid = true;
- for (xx = 0; xx < LEN_UUID_128 - 4; xx++) {
- if (p_uuid[xx] != base_uuid[xx]) {
- is_base_uuid = false;
- break;
- }
- }
- if (is_base_uuid) {
- if ((p_uuid[LEN_UUID_128 - 1] == 0) &&
- (p_uuid[LEN_UUID_128 - 2] == 0)) {
- p_uuid += (LEN_UUID_128 - 4);
- p_uuid_rec->len = LEN_UUID_16;
- STREAM_TO_UINT16(p_uuid_rec->uu.uuid16, p_uuid);
- } else {
- p_uuid += (LEN_UUID_128 - LEN_UUID_32);
- p_uuid_rec->len = LEN_UUID_32;
- STREAM_TO_UINT32(p_uuid_rec->uu.uuid32, p_uuid);
- }
- }
- if (!is_base_uuid) {
- p_uuid_rec->len = LEN_UUID_128;
- memcpy(p_uuid_rec->uu.uuid128, p_uuid, LEN_UUID_128);
- }
- *p_data += LEN_UUID_128;
- break;
+ case Uuid::kNumBytes128: {
+ *p_uuid_rec = Uuid::From128BitLE(p_uuid);
+ *p_data += Uuid::kNumBytes128;
+ return true;
+ }
/* do not allow 32 bits UUID in ATT PDU now */
- case LEN_UUID_32:
+ case Uuid::kNumBytes32:
LOG(ERROR) << "DO NOT ALLOW 32 BITS UUID IN ATT PDU";
return false;
case 0:
@@ -877,47 +746,43 @@
* Returns 0 if error else sdp handle for the record.
*
******************************************************************************/
-uint32_t gatt_add_sdp_record(tBT_UUID* p_uuid, uint16_t start_hdl,
+uint32_t gatt_add_sdp_record(const Uuid& uuid, uint16_t start_hdl,
uint16_t end_hdl) {
- tSDP_PROTOCOL_ELEM proto_elem_list[2];
- uint32_t sdp_handle;
- uint16_t list = UUID_SERVCLASS_PUBLIC_BROWSE_GROUP;
uint8_t buff[60];
uint8_t* p = buff;
VLOG(1) << __func__
<< StringPrintf(" s_hdl=0x%x s_hdl=0x%x", start_hdl, end_hdl);
- sdp_handle = SDP_CreateRecord();
+ uint32_t sdp_handle = SDP_CreateRecord();
if (sdp_handle == 0) return 0;
- switch (p_uuid->len) {
- case LEN_UUID_16:
- SDP_AddServiceClassIdList(sdp_handle, 1, &p_uuid->uu.uuid16);
+ switch (uuid.GetShortestRepresentationSize()) {
+ case Uuid::kNumBytes16: {
+ uint16_t tmp = uuid.As16Bit();
+ SDP_AddServiceClassIdList(sdp_handle, 1, &tmp);
break;
+ }
- case LEN_UUID_32:
+ case Uuid::kNumBytes32: {
UINT8_TO_BE_STREAM(p, (UUID_DESC_TYPE << 3) | SIZE_FOUR_BYTES);
- UINT32_TO_BE_STREAM(p, p_uuid->uu.uuid32);
+ uint32_t tmp = uuid.As32Bit();
+ UINT32_TO_BE_STREAM(p, tmp);
SDP_AddAttribute(sdp_handle, ATTR_ID_SERVICE_CLASS_ID_LIST,
DATA_ELE_SEQ_DESC_TYPE, (uint32_t)(p - buff), buff);
break;
+ }
- case LEN_UUID_128:
+ case Uuid::kNumBytes128:
UINT8_TO_BE_STREAM(p, (UUID_DESC_TYPE << 3) | SIZE_SIXTEEN_BYTES);
- ARRAY_TO_BE_STREAM_REVERSE(p, p_uuid->uu.uuid128, LEN_UUID_128);
+ ARRAY_TO_BE_STREAM(p, uuid.To128BitBE().data(), (int)Uuid::kNumBytes128);
SDP_AddAttribute(sdp_handle, ATTR_ID_SERVICE_CLASS_ID_LIST,
DATA_ELE_SEQ_DESC_TYPE, (uint32_t)(p - buff), buff);
break;
-
- default:
- LOG(ERROR) << "inavlid UUID len=" << +p_uuid->len;
- SDP_DeleteRecord(sdp_handle);
- return 0;
- break;
}
/*** Fill out the protocol element sequence for SDP ***/
+ tSDP_PROTOCOL_ELEM proto_elem_list[2];
proto_elem_list[0].protocol_uuid = UUID_PROTOCOL_L2CAP;
proto_elem_list[0].num_params = 1;
proto_elem_list[0].params[0] = BT_PSM_ATT;
@@ -929,6 +794,7 @@
SDP_AddProtocolList(sdp_handle, 2, proto_elem_list);
/* Make the service browseable */
+ uint16_t list = UUID_SERVCLASS_PUBLIC_BROWSE_GROUP;
SDP_AddUuidSequence(sdp_handle, ATTR_ID_BROWSE_GROUP_LIST, 1, &list);
return (sdp_handle);
@@ -1440,40 +1306,6 @@
return (uint8_t*)"Op Code Exceed Max";
}
-/*******************************************************************************
- *
- * Function gatt_dbg_display_uuid
- *
- * Description Disaplay the UUID
- *
- * Returns None
- *
- ******************************************************************************/
-void gatt_dbg_display_uuid(tBT_UUID bt_uuid) {
- char str_buf[50];
-
- if (bt_uuid.len == LEN_UUID_16) {
- snprintf(str_buf, sizeof(str_buf), "0x%04x", bt_uuid.uu.uuid16);
- } else if (bt_uuid.len == LEN_UUID_32) {
- snprintf(str_buf, sizeof(str_buf), "0x%08x",
- (unsigned int)bt_uuid.uu.uuid32);
- } else if (bt_uuid.len == LEN_UUID_128) {
- int x = snprintf(
- str_buf, sizeof(str_buf), "0x%02x%02x%02x%02x%02x%02x%02x%02x",
- bt_uuid.uu.uuid128[15], bt_uuid.uu.uuid128[14], bt_uuid.uu.uuid128[13],
- bt_uuid.uu.uuid128[12], bt_uuid.uu.uuid128[11], bt_uuid.uu.uuid128[10],
- bt_uuid.uu.uuid128[9], bt_uuid.uu.uuid128[8]);
- snprintf(
- &str_buf[x], sizeof(str_buf) - x, "%02x%02x%02x%02x%02x%02x%02x%02x",
- bt_uuid.uu.uuid128[7], bt_uuid.uu.uuid128[6], bt_uuid.uu.uuid128[5],
- bt_uuid.uu.uuid128[4], bt_uuid.uu.uuid128[3], bt_uuid.uu.uuid128[2],
- bt_uuid.uu.uuid128[1], bt_uuid.uu.uuid128[0]);
- } else
- strlcpy(str_buf, "Unknown UUID 0", sizeof(str_buf));
-
- VLOG(1) << StringPrintf("UUID=[%s]", str_buf);
-}
-
/** Returns true if this is one of the background devices for the application,
* false otherwise */
bool gatt_is_bg_dev_for_app(tGATT_BG_CONN_DEV* p_dev, tGATT_IF gatt_if) {
diff --git a/stack/hid/hidh_api.cc b/stack/hid/hidh_api.cc
index 704426f..3fe2d28 100644
--- a/stack/hid/hidh_api.cc
+++ b/stack/hid/hidh_api.cc
@@ -35,6 +35,8 @@
#include "hidh_api.h"
#include "hidh_int.h"
+using bluetooth::Uuid;
+
tHID_HOST_CTB hh_cb;
static void hidh_search_callback(uint16_t sdp_result);
@@ -51,14 +53,11 @@
tHID_STATUS HID_HostGetSDPRecord(const RawAddress& addr,
tSDP_DISCOVERY_DB* p_db, uint32_t db_len,
tHID_HOST_SDP_CALLBACK* sdp_cback) {
- tSDP_UUID uuid_list;
if (hh_cb.sdp_busy) return HID_ERR_SDP_BUSY;
- uuid_list.len = 2;
- uuid_list.uu.uuid16 = UUID_SERVCLASS_HUMAN_INTERFACE;
-
hh_cb.p_sdp_db = p_db;
+ Uuid uuid_list = Uuid::From16Bit(UUID_SERVCLASS_HUMAN_INTERFACE);
SDP_InitDiscoveryDb(p_db, db_len, 1, &uuid_list, 0, NULL);
if (SDP_ServiceSearchRequest(addr, p_db, hidh_search_callback)) {
@@ -92,12 +91,9 @@
tSDP_DISCOVERY_DB* p_db = hh_cb.p_sdp_db;
tSDP_DISC_REC* p_rec;
tSDP_DISC_ATTR *p_attr, *p_subattr1, *p_subattr2, *p_repdesc;
- tBT_UUID hid_uuid;
tHID_DEV_SDP_INFO* p_nvi = &hh_cb.sdp_rec;
uint16_t attr_mask = 0;
- hid_uuid.len = LEN_UUID_16;
- hid_uuid.uu.uuid16 = UUID_SERVCLASS_HUMAN_INTERFACE;
hh_cb.sdp_busy = false;
@@ -106,7 +102,8 @@
return;
}
- p_rec = SDP_FindServiceUUIDInDb(p_db, &hid_uuid, NULL);
+ Uuid hid_uuid = Uuid::From16Bit(UUID_SERVCLASS_HUMAN_INTERFACE);
+ p_rec = SDP_FindServiceUUIDInDb(p_db, hid_uuid, NULL);
if (p_rec == NULL) {
hh_cb.sdp_cback(HID_SDP_NO_SERV_UUID, 0, NULL);
return;
diff --git a/stack/include/bnep_api.h b/stack/include/bnep_api.h
index 4116ac9..579f590 100644
--- a/stack/include/bnep_api.h
+++ b/stack/include/bnep_api.h
@@ -91,7 +91,8 @@
* use BNEP_ConnectResp call to accept or reject the request
*/
typedef void(tBNEP_CONNECT_IND_CB)(uint16_t handle, const RawAddress& bd_addr,
- tBT_UUID* remote_uuid, tBT_UUID* local_uuid,
+ const bluetooth::Uuid& remote_uuid,
+ const bluetooth::Uuid& local_uuid,
bool is_role_change);
/* Data buffer received indication callback prototype. Parameters are
@@ -190,8 +191,8 @@
uint16_t sent_mcast_filters;
uint16_t rcvd_num_filters;
uint16_t rcvd_mcast_filters;
- tBT_UUID src_uuid;
- tBT_UUID dst_uuid;
+ bluetooth::Uuid src_uuid;
+ bluetooth::Uuid dst_uuid;
} tBNEP_STATUS;
@@ -246,7 +247,8 @@
*
******************************************************************************/
extern tBNEP_RESULT BNEP_Connect(const RawAddress& p_rem_bda,
- tBT_UUID* src_uuid, tBT_UUID* dst_uuid,
+ const bluetooth::Uuid& src_uuid,
+ const bluetooth::Uuid& dst_uuid,
uint16_t* p_handle);
/*******************************************************************************
diff --git a/stack/include/bt_types.h b/stack/include/bt_types.h
index 22cb48d..99f687a 100644
--- a/stack/include/bt_types.h
+++ b/stack/include/bt_types.h
@@ -639,23 +639,6 @@
#define BT_1SEC_TIMEOUT_MS (1 * 1000) /* 1 second */
-/* Maximum UUID size - 16 bytes, and structure to hold any type of UUID. */
-#define MAX_UUID_SIZE 16
-typedef struct {
-#define LEN_UUID_16 2
-#define LEN_UUID_32 4
-#define LEN_UUID_128 16
-
- uint16_t len;
-
- union {
- uint16_t uuid16;
- uint32_t uuid32;
- uint8_t uuid128[MAX_UUID_SIZE];
- } uu;
-
-} tBT_UUID;
-
#define BT_EIR_FLAGS_TYPE 0x01
#define BT_EIR_MORE_16BITS_UUID_TYPE 0x02
#define BT_EIR_COMPLETE_16BITS_UUID_TYPE 0x03
diff --git a/stack/include/btm_api.h b/stack/include/btm_api.h
index 10f4f65..451471e 100644
--- a/stack/include/btm_api.h
+++ b/stack/include/btm_api.h
@@ -1956,7 +1956,8 @@
*
* Parameters p_eir - EIR
* eirl_len - EIR len
- * uuid_size - LEN_UUID_16, LEN_UUID_32, LEN_UUID_128
+ * uuid_size - Uuid::kNumBytes16, Uuid::kNumBytes32,
+ * Uuid::kNumBytes128
* p_num_uuid - return number of UUID in found list
* p_uuid_list - return UUID 16-bit list
* max_num_uuid - maximum number of UUID to be returned
diff --git a/stack/include/btm_ble_api.h b/stack/include/btm_ble_api.h
index 36c8128..f43a1fb 100644
--- a/stack/include/btm_ble_api.h
+++ b/stack/include/btm_ble_api.h
@@ -775,7 +775,7 @@
extern void BTM_LE_PF_uuid_filter(tBTM_BLE_SCAN_COND_OP action,
tBTM_BLE_PF_FILT_INDEX filt_index,
tBTM_BLE_PF_COND_TYPE filter_type,
- tBT_UUID uuid,
+ const bluetooth::Uuid& uuid,
tBTM_BLE_PF_LOGIC_TYPE cond_logic,
tBTM_BLE_PF_COND_MASK* p_uuid_mask,
tBTM_BLE_PF_CFG_CBACK cb);
diff --git a/stack/include/btm_ble_api_types.h b/stack/include/btm_ble_api_types.h
index 57ef0d1..b9a7273 100644
--- a/stack/include/btm_ble_api_types.h
+++ b/stack/include/btm_ble_api_types.h
@@ -462,7 +462,7 @@
typedef union {
uint16_t uuid16_mask;
uint32_t uuid32_mask;
- uint8_t uuid128_mask[LEN_UUID_128];
+ uint8_t uuid128_mask[bluetooth::Uuid::kNumBytes128];
} tBTM_BLE_PF_COND_MASK;
/* per device filter + one generic filter indexed by 0 */
diff --git a/stack/include/gatt_api.h b/stack/include/gatt_api.h
index 48ca8e3..6ab60e6 100644
--- a/stack/include/gatt_api.h
+++ b/stack/include/gatt_api.h
@@ -411,7 +411,7 @@
/* Discover parameters of different discovery types
*/
typedef struct {
- tBT_UUID service;
+ bluetooth::Uuid service;
uint16_t s_handle;
uint16_t e_handle;
} tGATT_DISC_PARAM;
@@ -434,7 +434,7 @@
tGATT_AUTH_REQ auth_req;
uint16_t s_handle;
uint16_t e_handle;
- tBT_UUID uuid;
+ bluetooth::Uuid uuid;
} tGATT_READ_BY_TYPE;
/* GATT_READ_MULTIPLE request data
@@ -499,20 +499,20 @@
typedef struct {
tGATT_CHAR_PROP char_prop; /* characterisitc properties */
uint16_t val_handle; /* characteristic value attribute handle */
- tBT_UUID char_uuid; /* characteristic UUID type */
+ bluetooth::Uuid char_uuid; /* characteristic UUID type */
} tGATT_CHAR_DCLR_VAL;
/* primary service group data
*/
typedef struct {
uint16_t e_handle; /* ending handle of the group */
- tBT_UUID service_type; /* group type */
+ bluetooth::Uuid service_type; /* group type */
} tGATT_GROUP_VALUE;
/* included service attribute value
*/
typedef struct {
- tBT_UUID service_type; /* included service UUID */
+ bluetooth::Uuid service_type; /* included service UUID */
uint16_t s_handle; /* starting handle */
uint16_t e_handle; /* ending handle */
} tGATT_INCL_SRVC;
@@ -535,7 +535,7 @@
/* discover result record
*/
typedef struct {
- tBT_UUID type;
+ bluetooth::Uuid type;
uint16_t handle;
tGATT_DISC_VALUE value;
} tGATT_DISC_RES;
@@ -605,8 +605,8 @@
/***************** Start Handle Management Definitions *********************/
typedef struct {
- tBT_UUID app_uuid128;
- tBT_UUID svc_uuid;
+ bluetooth::Uuid app_uuid128;
+ bluetooth::Uuid svc_uuid;
uint16_t s_handle;
uint16_t e_handle;
bool is_primary; /* primary service or secondary */
@@ -687,10 +687,6 @@
******************************************************************************/
extern bool GATTS_NVRegister(tGATT_APPL_INFO* p_cb_info);
-/* Converts 16bit uuid to bt_uuid_t that can be used when adding
- * service/characteristic/descriptor with GATTS_AddService */
-void uuid_128_from_16(bt_uuid_t* uuid, uint16_t uuid16);
-
/*******************************************************************************
*
* Function BTA_GATTS_AddService
@@ -725,7 +721,7 @@
* Returns true if operation succeed, else false
*
******************************************************************************/
-extern bool GATTS_DeleteService(tGATT_IF gatt_if, tBT_UUID* p_svc_uuid,
+extern bool GATTS_DeleteService(tGATT_IF gatt_if, bluetooth::Uuid* p_svc_uuid,
uint16_t svc_inst);
/*******************************************************************************
@@ -931,7 +927,8 @@
* with GATT
*
******************************************************************************/
-extern tGATT_IF GATT_Register(tBT_UUID* p_app_uuid128, tGATT_CBACK* p_cb_info);
+extern tGATT_IF GATT_Register(const bluetooth::Uuid& p_app_uuid128,
+ tGATT_CBACK* p_cb_info);
/*******************************************************************************
*
diff --git a/stack/include/sdp_api.h b/stack/include/sdp_api.h
index 72ccd0e..c6fce4a 100644
--- a/stack/include/sdp_api.h
+++ b/stack/include/sdp_api.h
@@ -52,9 +52,6 @@
/* Define the PSM that SDP uses */
#define SDP_PSM 0x0001
-/* Legacy #define to avoid code changes - SDP UUID is same as BT UUID */
-#define tSDP_UUID tBT_UUID
-
/* Masks for attr_value field of tSDP_DISC_ATTR */
#define SDP_DISC_ATTR_LEN_MASK 0x0FFF
#define SDP_DISC_ATTR_TYPE(len_type) ((len_type) >> 12)
@@ -120,7 +117,7 @@
uint32_t mem_free; /* Memory still available */
tSDP_DISC_REC* p_first_rec; /* Addr of first record in DB */
uint16_t num_uuid_filters; /* Number of UUIds to filter */
- tSDP_UUID uuid_filters[SDP_MAX_UUID_FILTERS]; /* UUIDs to filter */
+ bluetooth::Uuid uuid_filters[SDP_MAX_UUID_FILTERS]; /* UUIDs to filter */
uint16_t num_attr_filters; /* Number of attribute filters */
uint16_t attr_filters[SDP_MAX_ATTR_FILTERS]; /* Attributes to filter */
uint8_t* p_free_mem; /* Pointer to free memory */
@@ -176,7 +173,7 @@
*
******************************************************************************/
bool SDP_InitDiscoveryDb(tSDP_DISCOVERY_DB* p_db, uint32_t len,
- uint16_t num_uuid, tSDP_UUID* p_uuid_list,
+ uint16_t num_uuid, const bluetooth::Uuid* p_uuid_list,
uint16_t num_attr, uint16_t* p_attr_list);
/*******************************************************************************
@@ -295,13 +292,13 @@
*
* NOTE the only difference between this function and the previous
* function "SDP_FindServiceInDb()" is that this function takes
- * a tBT_UUID input.
+ * a Uuid input.
*
* Returns Pointer to record containing service class, or NULL
*
******************************************************************************/
tSDP_DISC_REC* SDP_FindServiceUUIDInDb(tSDP_DISCOVERY_DB* p_db,
- tBT_UUID* p_uuid,
+ const bluetooth::Uuid& uuid,
tSDP_DISC_REC* p_start_rec);
/*******************************************************************************
@@ -317,7 +314,8 @@
* Returns true if found, otherwise false.
*
******************************************************************************/
-bool SDP_FindServiceUUIDInRec_128bit(tSDP_DISC_REC* p_rec, tBT_UUID* p_uuid);
+bool SDP_FindServiceUUIDInRec_128bit(tSDP_DISC_REC* p_rec,
+ bluetooth::Uuid* p_uuid);
/*******************************************************************************
*
@@ -636,11 +634,6 @@
* Returns true if found, otherwise false.
*
******************************************************************************/
-bool SDP_FindServiceUUIDInRec(tSDP_DISC_REC* p_rec, tBT_UUID* p_uuid);
-
-// Converts UUID-16 to UUID-128 by including the base UUID.
-// |uuid16| is the 2-byte UUID to convert.
-// The result with the expanded 128-bit UUID is stored in |p_uuid128|.
-void sdpu_uuid16_to_uuid128(uint16_t uuid16, uint8_t* p_uuid128);
+bool SDP_FindServiceUUIDInRec(tSDP_DISC_REC* p_rec, bluetooth::Uuid* p_uuid);
#endif /* SDP_API_H */
diff --git a/stack/pan/pan_api.cc b/stack/pan/pan_api.cc
index a36793c..a7cace5 100644
--- a/stack/pan/pan_api.cc
+++ b/stack/pan/pan_api.cc
@@ -37,6 +37,8 @@
#include "sdp_api.h"
#include "sdpdefs.h"
+using bluetooth::Uuid;
+
/*******************************************************************************
*
* Function PAN_Register
@@ -266,9 +268,6 @@
******************************************************************************/
tPAN_RESULT PAN_Connect(const RawAddress& rem_bda, uint8_t src_role,
uint8_t dst_role, uint16_t* handle) {
- tPAN_CONN* pcb;
- tBNEP_RESULT result;
- tBT_UUID src_uuid, dst_uuid;
uint32_t mx_chan_id;
/*
@@ -294,8 +293,9 @@
}
/* Check if connection exists for this remote device */
- pcb = pan_get_pcb_by_addr(rem_bda);
+ tPAN_CONN* pcb = pan_get_pcb_by_addr(rem_bda);
+ uint16_t src_uuid, dst_uuid;
/* If we are PANU for this role validate destination role */
if (src_role == PAN_ROLE_CLIENT) {
if ((pan_cb.num_conns > 1) || (pan_cb.num_conns && (!pcb))) {
@@ -310,15 +310,15 @@
return PAN_INVALID_SRC_ROLE;
}
- src_uuid.uu.uuid16 = UUID_SERVCLASS_PANU;
+ src_uuid = UUID_SERVCLASS_PANU;
if (dst_role == PAN_ROLE_CLIENT) {
- dst_uuid.uu.uuid16 = UUID_SERVCLASS_PANU;
+ dst_uuid = UUID_SERVCLASS_PANU;
} else if (dst_role == PAN_ROLE_GN_SERVER) {
- dst_uuid.uu.uuid16 = UUID_SERVCLASS_GN;
+ dst_uuid = UUID_SERVCLASS_GN;
} else {
- dst_uuid.uu.uuid16 = UUID_SERVCLASS_NAP;
+ dst_uuid = UUID_SERVCLASS_NAP;
}
- mx_chan_id = dst_uuid.uu.uuid16;
+ mx_chan_id = dst_uuid;
}
/* If destination is PANU role validate source role */
else if (dst_role == PAN_ROLE_CLIENT) {
@@ -327,13 +327,13 @@
return PAN_INVALID_SRC_ROLE;
}
- dst_uuid.uu.uuid16 = UUID_SERVCLASS_PANU;
+ dst_uuid = UUID_SERVCLASS_PANU;
if (src_role == PAN_ROLE_GN_SERVER) {
- src_uuid.uu.uuid16 = UUID_SERVCLASS_GN;
+ src_uuid = UUID_SERVCLASS_GN;
} else {
- src_uuid.uu.uuid16 = UUID_SERVCLASS_NAP;
+ src_uuid = UUID_SERVCLASS_NAP;
}
- mx_chan_id = src_uuid.uu.uuid16;
+ mx_chan_id = src_uuid;
}
/* The role combination is not valid */
else {
@@ -364,16 +364,14 @@
pcb->prv_src_uuid = pcb->src_uuid;
pcb->prv_dst_uuid = pcb->dst_uuid;
- pcb->src_uuid = src_uuid.uu.uuid16;
- pcb->dst_uuid = dst_uuid.uu.uuid16;
+ pcb->src_uuid = src_uuid;
+ pcb->dst_uuid = dst_uuid;
- src_uuid.len = 2;
- dst_uuid.len = 2;
-
- result = BNEP_Connect(rem_bda, &src_uuid, &dst_uuid, &(pcb->handle));
- if (result != BNEP_SUCCESS) {
+ tBNEP_RESULT ret = BNEP_Connect(rem_bda, Uuid::From16Bit(src_uuid),
+ Uuid::From16Bit(dst_uuid), &(pcb->handle));
+ if (ret != BNEP_SUCCESS) {
pan_release_pcb(pcb);
- return result;
+ return ret;
}
PAN_TRACE_DEBUG("PAN_Connect() current active role set to %d", src_role);
diff --git a/stack/pan/pan_int.h b/stack/pan/pan_int.h
index 27fe666..bd6d620 100644
--- a/stack/pan/pan_int.h
+++ b/stack/pan/pan_int.h
@@ -98,7 +98,8 @@
/******************************************************************************/
extern void pan_register_with_bnep(void);
extern void pan_conn_ind_cb(uint16_t handle, const RawAddress& p_bda,
- tBT_UUID* remote_uuid, tBT_UUID* local_uuid,
+ const bluetooth::Uuid& remote_uuid,
+ const bluetooth::Uuid& local_uuid,
bool is_role_change);
extern void pan_connect_state_cb(uint16_t handle, const RawAddress& rem_bda,
tBNEP_RESULT result, bool is_role_change);
diff --git a/stack/pan/pan_main.cc b/stack/pan/pan_main.cc
index 8817c4e..61ea846 100644
--- a/stack/pan/pan_main.cc
+++ b/stack/pan/pan_main.cc
@@ -36,11 +36,9 @@
#include "sdp_api.h"
#include "sdpdefs.h"
-tPAN_CB pan_cb;
+using bluetooth::Uuid;
-#define UUID_CONSTANT_PART 12
-uint8_t constant_pan_uuid[UUID_CONSTANT_PART] = {
- 0, 0, 0x10, 0, 0x80, 0x00, 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb};
+tPAN_CB pan_cb;
/*******************************************************************************
*
@@ -90,135 +88,71 @@
*
******************************************************************************/
void pan_conn_ind_cb(uint16_t handle, const RawAddress& p_bda,
- tBT_UUID* remote_uuid, tBT_UUID* local_uuid,
+ const Uuid& remote_uuid, const Uuid& local_uuid,
bool is_role_change) {
- tPAN_CONN* pcb;
- uint8_t req_role;
- bool wrong_uuid;
+ /* If we are in GN or NAP role and have one or more active connections and the
+ * received connection is for user role reject it. If we are in user role with
+ * one connection active reject the connection. Allocate PCB and store the
+ * parameters. Make bridge request to the host system if connection is for NAP
+ */
- /*
- ** If we are in GN or NAP role and have one or more
- ** active connections and the received connection is
- ** for user role reject it.
- ** If we are in user role with one connection active
- ** reject the connection.
- ** Allocate PCB and store the parameters
- ** Make bridge request to the host system if connection
- ** is for NAP
- */
- wrong_uuid = false;
- if (remote_uuid->len == 16) {
- /*
- ** If the UUID is 16 bytes forst two bytes should be zeros
- ** and last 12 bytes should match the spec defined constant value
- */
- if (memcmp(constant_pan_uuid, remote_uuid->uu.uuid128 + 4,
- UUID_CONSTANT_PART))
- wrong_uuid = true;
-
- if (remote_uuid->uu.uuid128[0] || remote_uuid->uu.uuid128[1])
- wrong_uuid = true;
-
- /* Extract the 16 bit equivalent of the UUID */
- remote_uuid->uu.uuid16 = (uint16_t)((remote_uuid->uu.uuid128[2] << 8) |
- remote_uuid->uu.uuid128[3]);
- remote_uuid->len = 2;
- }
- if (remote_uuid->len == 4) {
- /* First two bytes should be zeros */
- if (remote_uuid->uu.uuid32 & 0xFFFF0000) wrong_uuid = true;
-
- remote_uuid->uu.uuid16 = (uint16_t)remote_uuid->uu.uuid32;
- remote_uuid->len = 2;
- }
-
- if (wrong_uuid) {
+ if (!remote_uuid.Is16Bit()) {
PAN_TRACE_ERROR("PAN Connection failed because of wrong remote UUID ");
BNEP_ConnectResp(handle, BNEP_CONN_FAILED_SRC_UUID);
return;
}
- wrong_uuid = false;
- if (local_uuid->len == 16) {
- /*
- ** If the UUID is 16 bytes forst two bytes should be zeros
- ** and last 12 bytes should match the spec defined constant value
- */
- if (memcmp(constant_pan_uuid, local_uuid->uu.uuid128 + 4,
- UUID_CONSTANT_PART))
- wrong_uuid = true;
-
- if (local_uuid->uu.uuid128[0] || local_uuid->uu.uuid128[1])
- wrong_uuid = true;
-
- /* Extract the 16 bit equivalent of the UUID */
- local_uuid->uu.uuid16 = (uint16_t)((local_uuid->uu.uuid128[2] << 8) |
- local_uuid->uu.uuid128[3]);
- local_uuid->len = 2;
- }
- if (local_uuid->len == 4) {
- /* First two bytes should be zeros */
- if (local_uuid->uu.uuid32 & 0xFFFF0000) wrong_uuid = true;
-
- local_uuid->uu.uuid16 = (uint16_t)local_uuid->uu.uuid32;
- local_uuid->len = 2;
- }
-
- if (wrong_uuid) {
+ if (!local_uuid.Is16Bit()) {
PAN_TRACE_ERROR("PAN Connection failed because of wrong local UUID ");
BNEP_ConnectResp(handle, BNEP_CONN_FAILED_DST_UUID);
return;
}
+ uint16_t remote_uuid16 = remote_uuid.As16Bit();
+ uint16_t local_uuid16 = local_uuid.As16Bit();
+
PAN_TRACE_EVENT(
- "pan_conn_ind_cb - for handle %d, current role %d, dst uuid 0x%x, src "
- "uuid 0x%x, role change %s",
- handle, pan_cb.role, local_uuid->uu.uuid16, remote_uuid->uu.uuid16,
+ "%s - handle %d, current role %d, dst uuid 0x%x, src uuid 0x%x, role "
+ "change %s",
+ __func__, handle, pan_cb.role, local_uuid16, remote_uuid16,
is_role_change ? "YES" : "NO");
- /* The acceptable UUID size is only 2 */
- if (remote_uuid->len != 2) {
- PAN_TRACE_ERROR("PAN Connection failed because of wrong UUID size %d",
- remote_uuid->len);
- BNEP_ConnectResp(handle, BNEP_CONN_FAILED_UUID_SIZE);
- return;
- }
/* Check if the source UUID is a valid one */
- if (remote_uuid->uu.uuid16 != UUID_SERVCLASS_PANU &&
- remote_uuid->uu.uuid16 != UUID_SERVCLASS_NAP &&
- remote_uuid->uu.uuid16 != UUID_SERVCLASS_GN) {
- PAN_TRACE_ERROR("Src UUID 0x%x is not valid", remote_uuid->uu.uuid16);
+ if (remote_uuid16 != UUID_SERVCLASS_PANU &&
+ remote_uuid16 != UUID_SERVCLASS_NAP &&
+ remote_uuid16 != UUID_SERVCLASS_GN) {
+ PAN_TRACE_ERROR("Src UUID 0x%x is not valid", remote_uuid16);
BNEP_ConnectResp(handle, BNEP_CONN_FAILED_SRC_UUID);
return;
}
/* Check if the destination UUID is a valid one */
- if (local_uuid->uu.uuid16 != UUID_SERVCLASS_PANU &&
- local_uuid->uu.uuid16 != UUID_SERVCLASS_NAP &&
- local_uuid->uu.uuid16 != UUID_SERVCLASS_GN) {
- PAN_TRACE_ERROR("Dst UUID 0x%x is not valid", remote_uuid->uu.uuid16);
+ if (local_uuid16 != UUID_SERVCLASS_PANU &&
+ local_uuid16 != UUID_SERVCLASS_NAP && local_uuid16 != UUID_SERVCLASS_GN) {
+ PAN_TRACE_ERROR("Dst UUID 0x%x is not valid", local_uuid16);
BNEP_ConnectResp(handle, BNEP_CONN_FAILED_DST_UUID);
return;
}
/* Check if currently we support the destination role requested */
if (((!(pan_cb.role & UUID_SERVCLASS_PANU)) &&
- local_uuid->uu.uuid16 == UUID_SERVCLASS_PANU) ||
+ local_uuid16 == UUID_SERVCLASS_PANU) ||
((!(pan_cb.role & UUID_SERVCLASS_GN)) &&
- local_uuid->uu.uuid16 == UUID_SERVCLASS_GN) ||
+ local_uuid16 == UUID_SERVCLASS_GN) ||
((!(pan_cb.role & UUID_SERVCLASS_NAP)) &&
- local_uuid->uu.uuid16 == UUID_SERVCLASS_NAP)) {
+ local_uuid16 == UUID_SERVCLASS_NAP)) {
PAN_TRACE_ERROR(
"PAN Connection failed because of unsupported destination UUID 0x%x",
- local_uuid->uu.uuid16);
+ local_uuid16);
BNEP_ConnectResp(handle, BNEP_CONN_FAILED_DST_UUID);
return;
}
+ uint8_t req_role;
/* Requested destination role is */
- if (local_uuid->uu.uuid16 == UUID_SERVCLASS_PANU)
+ if (local_uuid16 == UUID_SERVCLASS_PANU)
req_role = PAN_ROLE_CLIENT;
- else if (local_uuid->uu.uuid16 == UUID_SERVCLASS_GN)
+ else if (local_uuid16 == UUID_SERVCLASS_GN)
req_role = PAN_ROLE_GN_SERVER;
else
req_role = PAN_ROLE_NAP_SERVER;
@@ -226,9 +160,9 @@
/* If the connection indication is for the existing connection
** Check if the new destination role is acceptable
*/
- pcb = pan_get_pcb_by_handle(handle);
+ tPAN_CONN* pcb = pan_get_pcb_by_handle(handle);
if (pcb) {
- if (pan_cb.num_conns > 1 && local_uuid->uu.uuid16 == UUID_SERVCLASS_PANU) {
+ if (pan_cb.num_conns > 1 && local_uuid16 == UUID_SERVCLASS_PANU) {
/* There are connections other than this one
** so we cann't accept PANU role. Reject
*/
@@ -241,14 +175,14 @@
/* If it is already in connected state check for bridging status */
if (pcb->con_state == PAN_STATE_CONNECTED) {
- PAN_TRACE_EVENT("PAN Role changing New Src 0x%x Dst 0x%x",
- remote_uuid->uu.uuid16, local_uuid->uu.uuid16);
+ PAN_TRACE_EVENT("PAN Role changing New Src 0x%x Dst 0x%x", remote_uuid16,
+ local_uuid16);
pcb->prv_src_uuid = pcb->src_uuid;
pcb->prv_dst_uuid = pcb->dst_uuid;
if (pcb->src_uuid == UUID_SERVCLASS_NAP &&
- local_uuid->uu.uuid16 != UUID_SERVCLASS_NAP) {
+ local_uuid16 != UUID_SERVCLASS_NAP) {
/* Remove bridging */
if (pan_cb.pan_bridge_req_cb)
(*pan_cb.pan_bridge_req_cb)(pcb->rem_bda, false);
@@ -256,8 +190,8 @@
}
/* Set the latest active PAN role */
pan_cb.active_role = req_role;
- pcb->src_uuid = local_uuid->uu.uuid16;
- pcb->dst_uuid = remote_uuid->uu.uuid16;
+ pcb->src_uuid = local_uuid16;
+ pcb->dst_uuid = remote_uuid16;
BNEP_ConnectResp(handle, BNEP_SUCCESS);
return;
} else {
@@ -265,7 +199,7 @@
** we already have a connection then reject the request.
** If we have a connection in PANU role then reject it
*/
- if (pan_cb.num_conns && (local_uuid->uu.uuid16 == UUID_SERVCLASS_PANU ||
+ if (pan_cb.num_conns && (local_uuid16 == UUID_SERVCLASS_PANU ||
pan_cb.active_role == PAN_ROLE_CLIENT)) {
PAN_TRACE_ERROR("PAN already have a connection and can't be user");
BNEP_ConnectResp(handle, BNEP_CONN_FAILED_DST_UUID);
@@ -282,12 +216,11 @@
return;
}
- PAN_TRACE_EVENT("PAN connection destination UUID is 0x%x",
- local_uuid->uu.uuid16);
+ PAN_TRACE_EVENT("PAN connection destination UUID is 0x%x", local_uuid16);
/* Set the latest active PAN role */
pan_cb.active_role = req_role;
- pcb->src_uuid = local_uuid->uu.uuid16;
- pcb->dst_uuid = remote_uuid->uu.uuid16;
+ pcb->src_uuid = local_uuid16;
+ pcb->dst_uuid = remote_uuid16;
pcb->con_state = PAN_STATE_CONN_START;
pan_cb.num_conns++;
diff --git a/stack/rfcomm/port_api.cc b/stack/rfcomm/port_api.cc
index 808b567..b32e038 100644
--- a/stack/rfcomm/port_api.cc
+++ b/stack/rfcomm/port_api.cc
@@ -126,7 +126,7 @@
if ((scn == 0) || (scn >= PORT_MAX_RFC_PORTS)) {
/* Server Channel Number(SCN) should be in range 1...30 */
- RFCOMM_TRACE_ERROR("RFCOMM_CreateConnection - invalid SCN");
+ RFCOMM_TRACE_ERROR("%s - invalid SCN", __func__);
return (PORT_INVALID_SCN);
}
@@ -136,10 +136,8 @@
dlci = (scn << 1) + 1;
else
dlci = (scn << 1);
- RFCOMM_TRACE_API(
- "RFCOMM_CreateConnection(): scn:%d, dlci:%d, is_server:%d mtu:%d, "
- "p_mcb:%p",
- scn, dlci, is_server, mtu, p_mcb);
+ RFCOMM_TRACE_API("%s: scn:%d, dlci:%d, is_server:%d mtu:%d, p_mcb:%p",
+ __func__, scn, dlci, is_server, mtu, p_mcb);
/* For the server side always allocate a new port. On the client side */
/* do not allow the same (dlci, bd_addr) to be opened twice by application */
@@ -149,9 +147,8 @@
/* if existing port is also a client port */
if (p_port->is_server == false) {
RFCOMM_TRACE_ERROR(
- "RFCOMM_CreateConnection - already opened state:%d, RFC state:%d, "
- "MCB state:%d",
- p_port->state, p_port->rfc.state,
+ "%s - already opened state:%d, RFC state:%d, MCB state:%d",
+ __func__, p_port->state, p_port->rfc.state,
p_port->rfc.p_mcb ? p_port->rfc.p_mcb->state : 0);
*p_handle = p_port->inx;
return (PORT_ALREADY_OPENED);
@@ -161,12 +158,11 @@
p_port = port_allocate_port(dlci, bd_addr);
if (p_port == NULL) {
- RFCOMM_TRACE_WARNING("RFCOMM_CreateConnection - no resources");
+ RFCOMM_TRACE_WARNING("%s - no resources", __func__);
return (PORT_NO_RESOURCES);
}
RFCOMM_TRACE_API(
- "RFCOMM_CreateConnection(): scn:%d, dlci:%d, is_server:%d mtu:%d, "
- "p_mcb:%p, p_port:%p",
+ "%s: scn:%d, dlci:%d, is_server:%d mtu:%d, p_mcb:%p, p_port:%p", __func__,
scn, dlci, is_server, mtu, p_mcb, p_port);
p_port->default_signal_state =
@@ -188,7 +184,7 @@
break;
}
- RFCOMM_TRACE_EVENT("RFCOMM_CreateConnection dlci:%d signal state:0x%x", dlci,
+ RFCOMM_TRACE_EVENT("%s dlci:%d signal state:0x%x", __func__, dlci,
p_port->default_signal_state);
*p_handle = p_port->inx;
diff --git a/stack/sdp/sdp_api.cc b/stack/sdp/sdp_api.cc
index c89eca5..8800d07 100644
--- a/stack/sdp/sdp_api.cc
+++ b/stack/sdp/sdp_api.cc
@@ -39,6 +39,8 @@
#include "osi/include/osi.h"
+using bluetooth::Uuid;
+
/**********************************************************************
* C L I E N T F U N C T I O N P R O T O T Y P E S *
**********************************************************************/
@@ -66,7 +68,7 @@
*
******************************************************************************/
bool SDP_InitDiscoveryDb(tSDP_DISCOVERY_DB* p_db, uint32_t len,
- uint16_t num_uuid, tSDP_UUID* p_uuid_list,
+ uint16_t num_uuid, const Uuid* p_uuid_list,
uint16_t num_attr, uint16_t* p_attr_list) {
uint16_t xx;
@@ -289,7 +291,7 @@
* Returns true if found, otherwise false.
*
******************************************************************************/
-bool SDP_FindServiceUUIDInRec(tSDP_DISC_REC* p_rec, tBT_UUID* p_uuid) {
+bool SDP_FindServiceUUIDInRec(tSDP_DISC_REC* p_rec, Uuid* p_uuid) {
tSDP_DISC_ATTR *p_attr, *p_sattr, *p_extra_sattr;
p_attr = p_rec->p_first_attr;
@@ -300,18 +302,14 @@
for (p_sattr = p_attr->attr_value.v.p_sub_attr; p_sattr;
p_sattr = p_sattr->p_next_attr) {
if (SDP_DISC_ATTR_TYPE(p_sattr->attr_len_type) == UUID_DESC_TYPE) {
- if (SDP_DISC_ATTR_LEN(p_sattr->attr_len_type) == LEN_UUID_16) {
- p_uuid->len = LEN_UUID_16;
- p_uuid->uu.uuid16 = p_sattr->attr_value.v.u16;
+ if (SDP_DISC_ATTR_LEN(p_sattr->attr_len_type) == Uuid::kNumBytes16) {
+ *p_uuid = Uuid::From16Bit(p_sattr->attr_value.v.u16);
} else if (SDP_DISC_ATTR_LEN(p_sattr->attr_len_type) ==
- LEN_UUID_128) {
- 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];
- } else if (SDP_DISC_ATTR_LEN(p_sattr->attr_len_type) == LEN_UUID_32) {
- p_uuid->len = LEN_UUID_32;
- p_uuid->uu.uuid32 = p_sattr->attr_value.v.u32;
+ Uuid::kNumBytes128) {
+ *p_uuid = Uuid::From128BitBE(p_sattr->attr_value.v.array);
+ } else if (SDP_DISC_ATTR_LEN(p_sattr->attr_len_type) ==
+ Uuid::kNumBytes32) {
+ *p_uuid = Uuid::From32Bit(p_sattr->attr_value.v.u32);
}
return (true);
@@ -332,8 +330,7 @@
UUID_DESC_TYPE)
/* only support 16 bits UUID for now */
&& (SDP_DISC_ATTR_LEN(p_extra_sattr->attr_len_type) == 2)) {
- p_uuid->len = 2;
- p_uuid->uu.uuid16 = p_extra_sattr->attr_value.v.u16;
+ *p_uuid = Uuid::From16Bit(p_extra_sattr->attr_value.v.u16);
return (true);
}
}
@@ -345,8 +342,7 @@
if ((SDP_DISC_ATTR_TYPE(p_attr->attr_len_type) == UUID_DESC_TYPE)
/* only support 16 bits UUID for now */
&& (SDP_DISC_ATTR_LEN(p_attr->attr_len_type) == 2)) {
- p_uuid->len = 2;
- p_uuid->uu.uuid16 = p_attr->attr_value.v.u16;
+ *p_uuid = Uuid::From16Bit(p_attr->attr_value.v.u16);
return (true);
}
}
@@ -368,7 +364,7 @@
* Returns true if found, otherwise false.
*
******************************************************************************/
-bool SDP_FindServiceUUIDInRec_128bit(tSDP_DISC_REC* p_rec, tBT_UUID* p_uuid) {
+bool SDP_FindServiceUUIDInRec_128bit(tSDP_DISC_REC* p_rec, Uuid* p_uuid) {
tSDP_DISC_ATTR* p_attr = p_rec->p_first_attr;
while (p_attr) {
if ((p_attr->attr_id == ATTR_ID_SERVICE_CLASS_ID_LIST) &&
@@ -378,10 +374,7 @@
if (SDP_DISC_ATTR_TYPE(p_sattr->attr_len_type) == UUID_DESC_TYPE) {
/* only support 128 bits UUID for now */
if (SDP_DISC_ATTR_LEN(p_sattr->attr_len_type) == 16) {
- 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];
+ *p_uuid = Uuid::From128BitBE(p_sattr->attr_value.v.array);
}
return (true);
}
@@ -393,10 +386,7 @@
if ((SDP_DISC_ATTR_TYPE(p_attr->attr_len_type) == UUID_DESC_TYPE)
/* only support 128 bits UUID for now */
&& (SDP_DISC_ATTR_LEN(p_attr->attr_len_type) == 16)) {
- p_uuid->len = LEN_UUID_128;
- for (uint8_t i = 0; i != LEN_UUID_128; ++i)
- p_uuid->uu.uuid128[i] =
- p_attr->attr_value.v.array[LEN_UUID_128 - i - 1];
+ *p_uuid = Uuid::From128BitBE(p_attr->attr_value.v.array);
return (true);
}
}
@@ -573,13 +563,13 @@
*
* NOTE the only difference between this function and the previous
* function "SDP_FindServiceInDb()" is that this function takes
- * a tBT_UUID input
+ * a Uuid input
*
* Returns Pointer to record containing service class, or NULL
*
******************************************************************************/
tSDP_DISC_REC* SDP_FindServiceUUIDInDb(tSDP_DISCOVERY_DB* p_db,
- tBT_UUID* p_uuid,
+ const Uuid& uuid,
tSDP_DISC_REC* p_start_rec) {
tSDP_DISC_REC* p_rec;
tSDP_DISC_ATTR *p_attr, *p_sattr;
@@ -601,13 +591,13 @@
for (p_sattr = p_attr->attr_value.v.p_sub_attr; p_sattr;
p_sattr = p_sattr->p_next_attr) {
if (SDP_DISC_ATTR_TYPE(p_sattr->attr_len_type) == UUID_DESC_TYPE) {
- if (sdpu_compare_uuid_with_attr(p_uuid, p_sattr)) return (p_rec);
+ if (sdpu_compare_uuid_with_attr(uuid, p_sattr)) return (p_rec);
}
}
break;
} else if (p_attr->attr_id == ATTR_ID_SERVICE_ID) {
if (SDP_DISC_ATTR_TYPE(p_attr->attr_len_type) == UUID_DESC_TYPE) {
- if (sdpu_compare_uuid_with_attr(p_uuid, p_attr)) return (p_rec);
+ if (sdpu_compare_uuid_with_attr(uuid, p_attr)) return (p_rec);
}
}
@@ -829,9 +819,7 @@
uint16_t di_uuid = UUID_SERVCLASS_PNP_INFORMATION;
/* build uuid for db init */
- tSDP_UUID init_uuid;
- init_uuid.len = 2;
- init_uuid.uu.uuid16 = di_uuid;
+ Uuid init_uuid = Uuid::From16Bit(di_uuid);
if (SDP_InitDiscoveryDb(p_db, len, num_uuids, &init_uuid, 0, NULL))
if (SDP_ServiceSearchRequest(remote_device, p_db, p_cb))
diff --git a/stack/sdp/sdp_discovery.cc b/stack/sdp/sdp_discovery.cc
index fd9339f..9bc87a3 100644
--- a/stack/sdp/sdp_discovery.cc
+++ b/stack/sdp/sdp_discovery.cc
@@ -36,6 +36,8 @@
#include "sdp_api.h"
#include "sdpint.h"
+using bluetooth::Uuid;
+
#ifndef SDP_DEBUG_RAW
#define SDP_DEBUG_RAW false
#endif
@@ -68,7 +70,7 @@
*
******************************************************************************/
static uint8_t* sdpu_build_uuid_seq(uint8_t* p_out, uint16_t num_uuids,
- tSDP_UUID* p_uuid_list) {
+ Uuid* p_uuid_list) {
uint16_t xx;
uint8_t* p_len;
@@ -81,18 +83,19 @@
/* Now, loop through and put in all the UUID(s) */
for (xx = 0; xx < num_uuids; xx++, p_uuid_list++) {
- if (p_uuid_list->len == LEN_UUID_16) {
+ int len = p_uuid_list->GetShortestRepresentationSize();
+ if (len == Uuid::kNumBytes16) {
UINT8_TO_BE_STREAM(p_out, (UUID_DESC_TYPE << 3) | SIZE_TWO_BYTES);
- UINT16_TO_BE_STREAM(p_out, p_uuid_list->uu.uuid16);
- } else if (p_uuid_list->len == LEN_UUID_32) {
+ UINT16_TO_BE_STREAM(p_out, p_uuid_list->As16Bit());
+ } else if (len == Uuid::kNumBytes32) {
UINT8_TO_BE_STREAM(p_out, (UUID_DESC_TYPE << 3) | SIZE_FOUR_BYTES);
- UINT32_TO_BE_STREAM(p_out, p_uuid_list->uu.uuid32);
- } else if (p_uuid_list->len == LEN_UUID_128) {
+ UINT32_TO_BE_STREAM(p_out, p_uuid_list->As32Bit());
+ } else if (len == Uuid::kNumBytes128) {
UINT8_TO_BE_STREAM(p_out, (UUID_DESC_TYPE << 3) | SIZE_SIXTEEN_BYTES);
- ARRAY_TO_BE_STREAM(p_out, p_uuid_list->uu.uuid128, p_uuid_list->len);
+ ARRAY_TO_BE_STREAM(p_out, p_uuid_list->To128BitBE(),
+ (int)Uuid::kNumBytes128);
} else {
- SDP_TRACE_ERROR("SDP: Passed UUID has invalid length %x",
- p_uuid_list->len);
+ DCHECK(0) << "SDP: Passed UUID has invalid length " << len;
}
}
@@ -874,12 +877,12 @@
(p_attr->attr_len_type & ~SDP_DISC_ATTR_LEN_MASK) | 2;
p += 2;
BE_STREAM_TO_UINT16(p_attr->attr_value.v.u16, p);
- p += MAX_UUID_SIZE - 4;
+ p += Uuid::kNumBytes128 - 4;
} else {
p_attr->attr_len_type =
(p_attr->attr_len_type & ~SDP_DISC_ATTR_LEN_MASK) | 4;
BE_STREAM_TO_UINT32(p_attr->attr_value.v.u32, p);
- p += MAX_UUID_SIZE - 4;
+ p += Uuid::kNumBytes128 - 4;
}
} else {
BE_STREAM_TO_ARRAY(p, p_attr->attr_value.v.array,
diff --git a/stack/sdp/sdp_utils.cc b/stack/sdp/sdp_utils.cc
index 720c746..76dc33a 100644
--- a/stack/sdp/sdp_utils.cc
+++ b/stack/sdp/sdp_utils.cc
@@ -39,6 +39,7 @@
#include "btu.h"
+using bluetooth::Uuid;
static const uint8_t sdp_base_uuid[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x10, 0x00, 0x80, 0x00, 0x00, 0x80,
0x5F, 0x9B, 0x34, 0xFB};
@@ -569,7 +570,7 @@
bool sdpu_is_base_uuid(uint8_t* p_uuid) {
uint16_t xx;
- for (xx = 4; xx < MAX_UUID_SIZE; xx++)
+ for (xx = 4; xx < Uuid::kNumBytes128; xx++)
if (p_uuid[xx] != sdp_base_uuid[xx]) return (false);
/* If here, matched */
@@ -590,8 +591,8 @@
******************************************************************************/
bool sdpu_compare_uuid_arrays(uint8_t* p_uuid1, uint32_t len1, uint8_t* p_uuid2,
uint16_t len2) {
- uint8_t nu1[MAX_UUID_SIZE];
- uint8_t nu2[MAX_UUID_SIZE];
+ uint8_t nu1[Uuid::kNumBytes128];
+ uint8_t nu2[Uuid::kNumBytes128];
if (((len1 != 2) && (len1 != 4) && (len1 != 16)) ||
((len2 != 2) && (len2 != 4) && (len2 != 16))) {
@@ -615,15 +616,15 @@
(p_uuid1[2] == p_uuid2[0]) && (p_uuid1[3] == p_uuid2[1]));
} else {
/* Normalize UUIDs to 16-byte form, then compare. Len1 must be 16 */
- memcpy(nu1, p_uuid1, MAX_UUID_SIZE);
- memcpy(nu2, sdp_base_uuid, MAX_UUID_SIZE);
+ memcpy(nu1, p_uuid1, Uuid::kNumBytes128);
+ memcpy(nu2, sdp_base_uuid, Uuid::kNumBytes128);
if (len2 == 4)
memcpy(nu2, p_uuid2, len2);
else if (len2 == 2)
memcpy(nu2 + 2, p_uuid2, len2);
- return (memcmp(nu1, nu2, MAX_UUID_SIZE) == 0);
+ return (memcmp(nu1, nu2, Uuid::kNumBytes128) == 0);
}
} else {
/* len2 is greater than len1 */
@@ -633,47 +634,21 @@
(p_uuid2[2] == p_uuid1[0]) && (p_uuid2[3] == p_uuid1[1]));
} else {
/* Normalize UUIDs to 16-byte form, then compare. Len1 must be 16 */
- memcpy(nu2, p_uuid2, MAX_UUID_SIZE);
- memcpy(nu1, sdp_base_uuid, MAX_UUID_SIZE);
+ memcpy(nu2, p_uuid2, Uuid::kNumBytes128);
+ memcpy(nu1, sdp_base_uuid, Uuid::kNumBytes128);
if (len1 == 4)
memcpy(nu1, p_uuid1, (size_t)len1);
else if (len1 == 2)
memcpy(nu1 + 2, p_uuid1, (size_t)len1);
- return (memcmp(nu1, nu2, MAX_UUID_SIZE) == 0);
+ return (memcmp(nu1, nu2, Uuid::kNumBytes128) == 0);
}
}
}
/*******************************************************************************
*
- * Function sdpu_compare_bt_uuids
- *
- * Description This function compares 2 BT UUID structures.
- *
- * NOTE it is assumed that BT UUID structures are compressed to the
- * smallest possible UUIDs (by removing the base SDP UUID)
- *
- * Returns true if matched, else false
- *
- ******************************************************************************/
-bool sdpu_compare_bt_uuids(tBT_UUID* p_uuid1, tBT_UUID* p_uuid2) {
- /* Lengths must match for BT UUIDs to match */
- if (p_uuid1->len == p_uuid2->len) {
- if (p_uuid1->len == 2)
- return (p_uuid1->uu.uuid16 == p_uuid2->uu.uuid16);
- else if (p_uuid1->len == 4)
- return (p_uuid1->uu.uuid32 == p_uuid2->uu.uuid32);
- else if (!memcmp(p_uuid1->uu.uuid128, p_uuid2->uu.uuid128, 16))
- return (true);
- }
-
- return (false);
-}
-
-/*******************************************************************************
- *
* Function sdpu_compare_uuid_with_attr
*
* Description This function compares a BT UUID structure with the UUID in
@@ -688,18 +663,12 @@
* Returns true if matched, else false
*
******************************************************************************/
-bool sdpu_compare_uuid_with_attr(tBT_UUID* p_btuuid, tSDP_DISC_ATTR* p_attr) {
- uint16_t attr_len = SDP_DISC_ATTR_LEN(p_attr->attr_len_type);
-
- /* Since both UUIDs are compressed, lengths must match */
- if (p_btuuid->len != attr_len) return (false);
-
- if (p_btuuid->len == 2)
- return (bool)(p_btuuid->uu.uuid16 == p_attr->attr_value.v.u16);
- else if (p_btuuid->len == 4)
- return (bool)(p_btuuid->uu.uuid32 == p_attr->attr_value.v.u32);
- else if (!memcmp(p_btuuid->uu.uuid128, (void*)p_attr->attr_value.v.array,
- MAX_UUID_SIZE))
+bool sdpu_compare_uuid_with_attr(const Uuid& uuid, tSDP_DISC_ATTR* p_attr) {
+ int len = uuid.GetShortestRepresentationSize();
+ if (len == 2) return uuid.As16Bit() == p_attr->attr_value.v.u16;
+ if (len == 4) return uuid.As32Bit() == p_attr->attr_value.v.u32;
+ if (memcmp(uuid.To128BitBE().data(), (void*)p_attr->attr_value.v.array,
+ Uuid::kNumBytes128) == 0)
return (true);
return (false);
@@ -903,25 +872,3 @@
osi_free(p_attr_buff);
return p_out;
}
-
-/*******************************************************************************
- *
- * Function sdpu_uuid16_to_uuid128
- *
- * Description This function converts UUID-16 to UUID-128 by including the
- * base UUID
- *
- * uuid16: 2-byte UUID
- * p_uuid128: Expanded 128-bit UUID
- *
- * Returns None
- *
- ******************************************************************************/
-void sdpu_uuid16_to_uuid128(uint16_t uuid16, uint8_t* p_uuid128) {
- uint16_t uuid16_bo;
- memset(p_uuid128, 0, 16);
-
- memcpy(p_uuid128, sdp_base_uuid, MAX_UUID_SIZE);
- uuid16_bo = ntohs(uuid16);
- memcpy(p_uuid128 + 2, &uuid16_bo, sizeof(uint16_t));
-}
diff --git a/stack/sdp/sdpint.h b/stack/sdp/sdpint.h
index 3a046b6..820c914 100644
--- a/stack/sdp/sdpint.h
+++ b/stack/sdp/sdpint.h
@@ -25,6 +25,7 @@
#ifndef SDP_INT_H
#define SDP_INT_H
+#include "bluetooth/uuid.h"
#include "bt_target.h"
#include "l2c_api.h"
#include "osi/include/alarm.h"
@@ -65,7 +66,7 @@
#define SDP_DEVICE_NOTI_FLAG 0x03
/* Define the Protocol Data Unit (PDU) types.
-*/
+ */
#define SDP_PDU_ERROR_RESPONSE 0x01
#define SDP_PDU_SERVICE_SEARCH_REQ 0x02
#define SDP_PDU_SERVICE_SEARCH_RSP 0x03
@@ -88,7 +89,7 @@
/* Internal UUID sequence representation */
typedef struct {
uint16_t len;
- uint8_t value[MAX_UUID_SIZE];
+ uint8_t value[bluetooth::Uuid::kNumBytes128];
} tUID_ENT;
typedef struct {
@@ -229,7 +230,7 @@
#endif
/* Functions provided by sdp_conn.cc
-*/
+ */
extern void sdp_conn_rcv_l2e_conn_ind(BT_HDR* p_msg);
extern void sdp_conn_rcv_l2e_conn_cfm(BT_HDR* p_msg);
extern void sdp_conn_rcv_l2e_disc(BT_HDR* p_msg);
@@ -244,7 +245,7 @@
extern tCONN_CB* sdp_conn_originate(const RawAddress& p_bd_addr);
/* Functions provided by sdp_utils.cc
-*/
+ */
extern tCONN_CB* sdpu_find_ccb_by_cid(uint16_t cid);
extern tCONN_CB* sdpu_find_ccb_by_db(tSDP_DISCOVERY_DB* p_db);
extern tCONN_CB* sdpu_allocate_ccb(void);
@@ -266,8 +267,7 @@
extern bool sdpu_is_base_uuid(uint8_t* p_uuid);
extern bool sdpu_compare_uuid_arrays(uint8_t* p_uuid1, uint32_t len1,
uint8_t* p_uuid2, uint16_t len2);
-extern bool sdpu_compare_bt_uuids(tBT_UUID* p_uuid1, tBT_UUID* p_uuid2);
-extern bool sdpu_compare_uuid_with_attr(tBT_UUID* p_btuuid,
+extern bool sdpu_compare_uuid_with_attr(const bluetooth::Uuid& uuid,
tSDP_DISC_ATTR* p_attr);
extern void sdpu_sort_attr_list(uint16_t num_attr, tSDP_DISCOVERY_DB* p_db);
@@ -281,7 +281,7 @@
uint16_t len, uint16_t* offset);
/* Functions provided by sdp_db.cc
-*/
+ */
extern tSDP_RECORD* sdp_db_service_search(tSDP_RECORD* p_rec,
tSDP_UUID_SEQ* p_seq);
extern tSDP_RECORD* sdp_db_find_record(uint32_t handle);
@@ -290,7 +290,7 @@
uint16_t end_attr);
/* Functions provided by sdp_server.cc
-*/
+ */
#if (SDP_SERVER_ENABLED == TRUE)
extern void sdp_server_handle_client_req(tCONN_CB* p_ccb, BT_HDR* p_msg);
#else
@@ -298,7 +298,7 @@
#endif
/* Functions provided by sdp_discovery.cc
-*/
+ */
extern void sdp_disc_connected(tCONN_CB* p_ccb);
extern void sdp_disc_server_rsp(tCONN_CB* p_ccb, BT_HDR* p_msg);
diff --git a/stack/srvc/srvc_battery.cc b/stack/srvc/srvc_battery.cc
index 2d9fe18..9bae14b 100644
--- a/stack/srvc/srvc_battery.cc
+++ b/stack/srvc/srvc_battery.cc
@@ -18,7 +18,6 @@
#include "bt_target.h"
#include "bt_utils.h"
-#include "btcore/include/uuid.h"
#include "gatt_api.h"
#include "gatt_int.h"
#include "osi/include/osi.h"
@@ -185,13 +184,13 @@
btgatt_db_element_t service[BA_MAX_ATTR_NUM] = {};
- bt_uuid_t service_uuid;
- uuid_128_from_16(&service_uuid, UUID_SERVCLASS_BATTERY);
+ bluetooth::Uuid service_uuid =
+ bluetooth::Uuid::From16Bit(UUID_SERVCLASS_BATTERY);
service[0].type = /* p_reg_info->is_pri */ BTGATT_DB_PRIMARY_SERVICE;
service[0].uuid = service_uuid;
- bt_uuid_t char_uuid;
- uuid_128_from_16(&char_uuid, GATT_UUID_BATTERY_LEVEL);
+ bluetooth::Uuid char_uuid =
+ bluetooth::Uuid::From16Bit(GATT_UUID_BATTERY_LEVEL);
service[1].type = BTGATT_DB_CHARACTERISTIC;
service[1].uuid = char_uuid;
service[1].properties = GATT_CHAR_PROP_BIT_READ;
@@ -200,8 +199,8 @@
int i = 2;
if (p_reg_info->ba_level_descr & BA_LEVEL_NOTIFY) {
- bt_uuid_t desc_uuid;
- uuid_128_from_16(&desc_uuid, GATT_UUID_CHAR_CLIENT_CONFIG);
+ bluetooth::Uuid desc_uuid =
+ bluetooth::Uuid::From16Bit(GATT_UUID_CHAR_CLIENT_CONFIG);
service[i].type = BTGATT_DB_DESCRIPTOR;
service[i].uuid = desc_uuid;
@@ -211,8 +210,8 @@
/* need presentation format descriptor? */
if (p_reg_info->ba_level_descr & BA_LEVEL_PRE_FMT) {
- bt_uuid_t desc_uuid;
- uuid_128_from_16(&desc_uuid, GATT_UUID_CHAR_PRESENT_FORMAT);
+ bluetooth::Uuid desc_uuid =
+ bluetooth::Uuid::From16Bit(GATT_UUID_CHAR_PRESENT_FORMAT);
service[i].type = BTGATT_DB_DESCRIPTOR;
service[i].uuid = desc_uuid;
@@ -222,8 +221,8 @@
/* need presentation format descriptor? */
if (p_reg_info->ba_level_descr & BA_LEVEL_RPT_REF) {
- bt_uuid_t desc_uuid;
- uuid_128_from_16(&desc_uuid, GATT_UUID_RPT_REF_DESCR);
+ bluetooth::Uuid desc_uuid =
+ bluetooth::Uuid::From16Bit(GATT_UUID_RPT_REF_DESCR);
service[i].type = BTGATT_DB_DESCRIPTOR;
service[i].uuid = desc_uuid;
diff --git a/stack/srvc/srvc_dis.cc b/stack/srvc/srvc_dis.cc
index 85de4b4..3997984 100644
--- a/stack/srvc/srvc_dis.cc
+++ b/stack/srvc/srvc_dis.cc
@@ -20,7 +20,6 @@
#include "bt_target.h"
#include "bt_utils.h"
-#include "btcore/include/uuid.h"
#include "gatt_api.h"
#include "gatt_int.h"
#include "osi/include/log.h"
@@ -232,7 +231,6 @@
memset(¶m, 0, sizeof(tGATT_READ_PARAM));
- param.service.uuid.len = LEN_UUID_16;
param.service.s_handle = 1;
param.service.e_handle = 0xFFFF;
param.service.auth_req = 0;
@@ -240,13 +238,14 @@
while (dis_cb.dis_read_uuid_idx < DIS_MAX_CHAR_NUM) {
if (dis_uuid_to_attr(dis_attr_uuid[dis_cb.dis_read_uuid_idx]) &
dis_cb.request_mask) {
- param.service.uuid.uu.uuid16 = dis_attr_uuid[dis_cb.dis_read_uuid_idx];
+ param.service.uuid =
+ bluetooth::Uuid::From16Bit(dis_attr_uuid[dis_cb.dis_read_uuid_idx]);
if (GATTC_Read(conn_id, GATT_READ_BY_TYPE, ¶m) == GATT_SUCCESS)
return true;
- LOG(ERROR) << "Read DISInfo: 0x" << std::hex
- << param.service.uuid.uu.uuid16 << "GATT_Read Failed";
+ LOG(ERROR) << "Read DISInfo: " << param.service.uuid
+ << " GATT_Read Failed";
}
dis_cb.dis_read_uuid_idx++;
@@ -350,16 +349,16 @@
btgatt_db_element_t service[DIS_MAX_ATTR_NUM] = {};
- bt_uuid_t svc_uuid;
- uuid_128_from_16(&svc_uuid, UUID_SERVCLASS_DEVICE_INFO);
+ bluetooth::Uuid svc_uuid =
+ bluetooth::Uuid::From16Bit(UUID_SERVCLASS_DEVICE_INFO);
service[0].type = BTGATT_DB_PRIMARY_SERVICE;
service[0].uuid = svc_uuid;
for (int i = 0; dis_attr_mask != 0 && i < DIS_MAX_CHAR_NUM; i++) {
dis_cb.dis_attr[i].uuid = dis_attr_uuid[i];
- bt_uuid_t char_uuid;
- uuid_128_from_16(&char_uuid, dis_cb.dis_attr[i].uuid);
+ bluetooth::Uuid char_uuid =
+ bluetooth::Uuid::From16Bit(dis_cb.dis_attr[i].uuid);
/* index 0 is service, so characteristics start from 1 */
service[i + 1].type = BTGATT_DB_CHARACTERISTIC;
service[i + 1].uuid = char_uuid;
diff --git a/stack/srvc/srvc_eng.cc b/stack/srvc/srvc_eng.cc
index f054f67..23fb8fa 100644
--- a/stack/srvc/srvc_eng.cc
+++ b/stack/srvc/srvc_eng.cc
@@ -402,7 +402,6 @@
*
******************************************************************************/
tGATT_STATUS srvc_eng_init(void) {
- tBT_UUID app_uuid = {LEN_UUID_16, {UUID_SERVCLASS_DEVICE_INFO}};
if (srvc_eng_cb.enabled) {
LOG(ERROR) << "DIS already initalized";
@@ -410,7 +409,9 @@
memset(&srvc_eng_cb, 0, sizeof(tSRVC_ENG_CB));
/* Create a GATT profile service */
- srvc_eng_cb.gatt_if = GATT_Register(&app_uuid, &srvc_gatt_cback);
+ bluetooth::Uuid app_uuid =
+ bluetooth::Uuid::From16Bit(UUID_SERVCLASS_DEVICE_INFO);
+ srvc_eng_cb.gatt_if = GATT_Register(app_uuid, &srvc_gatt_cback);
GATT_StartIf(srvc_eng_cb.gatt_if);
VLOG(1) << "Srvc_Init: gatt_if=" << +srvc_eng_cb.gatt_if;