Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BT Classic: support for 32 and 128-bit custom UUIDs (IDFGH-10721) #11942

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 28 additions & 11 deletions components/bt/host/bluedroid/bta/dm/bta_dm_act.c
Original file line number Diff line number Diff line change
Expand Up @@ -4255,7 +4255,7 @@ static void bta_dm_set_eir (char *local_name)
for (custom_uuid_idx = 0; custom_uuid_idx < BTA_EIR_SERVER_NUM_CUSTOM_UUID; custom_uuid_idx++) {
if (bta_dm_cb.custom_uuid[custom_uuid_idx].len == LEN_UUID_128) {
if ( num_uuid < max_num_uuid ) {
ARRAY16_TO_STREAM(p, bta_dm_cb.custom_uuid[custom_uuid_idx].uu.uuid128);
ARRAY_TO_STREAM(p, bta_dm_cb.custom_uuid[custom_uuid_idx].uu.uuid128, LEN_UUID_128);
num_uuid++;
} else {
data_type = BTM_EIR_MORE_128BITS_UUID_TYPE;
Expand Down Expand Up @@ -4452,21 +4452,38 @@ static void bta_dm_eir_search_services( tBTM_INQ_RESULTS *p_result,
** Returns None
**
*******************************************************************************/
void bta_dm_eir_update_uuid(UINT16 uuid16, BOOLEAN adding)
void bta_dm_eir_update_uuid(tBT_UUID uuid, BOOLEAN adding)
{
/* if this UUID is not advertised in EIR */
if ( !BTM_HasEirService( p_bta_dm_eir_cfg->uuid_mask, uuid16 )) {
return;
}
/* 32 and 128-bit UUIDs go to the bta_dm_cb.custom_uuid array */
if ((uuid.len == LEN_UUID_32) || (uuid.len == LEN_UUID_128)) {
if (adding) {
if (BTM_HasCustomEirService(bta_dm_cb.custom_uuid, uuid)) {
APPL_TRACE_EVENT("UUID is already added for EIR");
return;
}
APPL_TRACE_EVENT("Adding %d-bit UUID into EIR", uuid.len * 8);

if ( adding ) {
APPL_TRACE_EVENT("Adding UUID=0x%04X into EIR", uuid16);
BTM_AddCustomEirService(bta_dm_cb.custom_uuid, uuid);
} else {
APPL_TRACE_EVENT("Removing %d-bit UUID from EIR", uuid.len * 8);

BTM_AddEirService( bta_dm_cb.eir_uuid, uuid16 );
BTM_RemoveCustomEirService(bta_dm_cb.custom_uuid, uuid);
}
} else {
APPL_TRACE_EVENT("Removing UUID=0x%04X from EIR", uuid16);
/* if this UUID is not advertised in EIR */
if (!BTM_HasEirService(p_bta_dm_eir_cfg->uuid_mask, uuid.uu.uuid16)) {
return;
}

if (adding) {
APPL_TRACE_EVENT("Adding UUID=0x%04X into EIR", uuid.uu.uuid16);

BTM_RemoveEirService( bta_dm_cb.eir_uuid, uuid16 );
BTM_AddEirService(bta_dm_cb.eir_uuid, uuid.uu.uuid16);
} else {
APPL_TRACE_EVENT("Removing UUID=0x%04X from EIR", uuid.uu.uuid16);

BTM_RemoveEirService(bta_dm_cb.eir_uuid, uuid.uu.uuid16);
}
}
#if CLASSIC_BT_INCLUDED
bta_dm_set_eir (NULL);
Expand Down
2 changes: 1 addition & 1 deletion components/bt/host/bluedroid/bta/dm/include/bta_dm_int.h
Original file line number Diff line number Diff line change
Expand Up @@ -1808,7 +1808,7 @@ extern void bta_dm_search_cancel_notify (tBTA_DM_MSG *p_data);
extern void bta_dm_search_cancel_transac_cmpl(tBTA_DM_MSG *p_data);
extern void bta_dm_disc_rmt_name (tBTA_DM_MSG *p_data);
extern tBTA_DM_PEER_DEVICE *bta_dm_find_peer_device(BD_ADDR peer_addr);
void bta_dm_eir_update_uuid(UINT16 uuid16, BOOLEAN adding);
void bta_dm_eir_update_uuid(tBT_UUID uuid, BOOLEAN adding);

extern void bta_dm_enable_test_mode(tBTA_DM_MSG *p_data);
extern void bta_dm_disable_test_mode(tBTA_DM_MSG *p_data);
Expand Down
12 changes: 10 additions & 2 deletions components/bt/host/bluedroid/bta/include/bta/bta_sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ typedef void (tBTA_SYS_SSR_CFG_CBACK)(UINT8 id, UINT8 app_id, UINT16 latency, UI

#if (BTA_EIR_CANNED_UUID_LIST != TRUE)
/* eir callback for adding/removeing UUID */
typedef void (tBTA_SYS_EIR_CBACK)(UINT16 uuid16, BOOLEAN adding);
typedef void (tBTA_SYS_EIR_CBACK)(tBT_UUID uuid, BOOLEAN adding);
#endif

/* registration structure */
Expand Down Expand Up @@ -263,12 +263,20 @@ extern void bta_sys_notify_collision (BD_ADDR_PTR p_bda);

#if (BTA_EIR_CANNED_UUID_LIST != TRUE)
extern void bta_sys_eir_register(tBTA_SYS_EIR_CBACK *p_cback);
extern void bta_sys_add_uuid(UINT16 uuid16);
extern void bta_sys_add_uuid(UINT16 uuid);
extern void bta_sys_add_uuid_32(UINT32 uuid32);
extern void bta_sys_add_uuid_128(UINT8 *uuid128);
extern void bta_sys_remove_uuid(UINT16 uuid16);
extern void bta_sys_remove_uuid_32(UINT32 uuid32);
extern void bta_sys_remove_uuid_128(UINT8 *uuid128);
#else
#define bta_sys_eir_register(ut)
#define bta_sys_add_uuid(ut)
#define bta_sys_add_uuid_32(ut)
#define bta_sys_add_uuid_128(ut)
#define bta_sys_remove_uuid(ut)
#define bta_sys_remove_uuid_32(ut)
#define bta_sys_remove_uuid_128(ut)
#endif

extern void bta_sys_set_policy (UINT8 id, UINT8 policy, BD_ADDR peer_addr);
Expand Down
98 changes: 96 additions & 2 deletions components/bt/host/bluedroid/bta/sys/bta_sys_conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -527,8 +527,55 @@ void bta_sys_eir_register(tBTA_SYS_EIR_CBACK *p_cback)
*******************************************************************************/
void bta_sys_add_uuid(UINT16 uuid16)
{
tBT_UUID uuid;
uuid.len = LEN_UUID_16;
uuid.uu.uuid16 = uuid16;

if (bta_sys_cb.eir_cb) {
bta_sys_cb.eir_cb(uuid, TRUE);
}
}


/*******************************************************************************
**
** Function bta_sys_add_uuid_32
**
** Description Called by BTA subsystems to indicate to DM that new service
** class UUID is added.
**
** Returns void
**
*******************************************************************************/
void bta_sys_add_uuid_32(UINT32 uuid32)
{
tBT_UUID uuid;
uuid.len = LEN_UUID_32;
uuid.uu.uuid32 = uuid32;

if (bta_sys_cb.eir_cb) {
bta_sys_cb.eir_cb(uuid, TRUE);
}
}

/*******************************************************************************
**
** Function bta_sys_add_uuid_128
**
** Description Called by BTA subsystems to indicate to DM that new service
** class UUID is added.
**
** Returns void
**
*******************************************************************************/
void bta_sys_add_uuid_128(UINT8 *uuid128)
{
tBT_UUID uuid;
uuid.len = LEN_UUID_128;
memcpy(&uuid.uu.uuid128, uuid128, LEN_UUID_128);

if (bta_sys_cb.eir_cb) {
bta_sys_cb.eir_cb(uuid16, TRUE );
bta_sys_cb.eir_cb(uuid, TRUE);
}
}

Expand All @@ -544,10 +591,57 @@ void bta_sys_add_uuid(UINT16 uuid16)
*******************************************************************************/
void bta_sys_remove_uuid(UINT16 uuid16)
{
tBT_UUID uuid;
uuid.len = LEN_UUID_16;
uuid.uu.uuid16 = uuid16;

if (bta_sys_cb.eir_cb) {
bta_sys_cb.eir_cb(uuid, FALSE);
}
}

/*******************************************************************************
**
** Function bta_sys_remove_uuid_32
**
** Description Called by BTA subsystems to indicate to DM that the service
** class UUID is removed.
**
** Returns void
**
*******************************************************************************/
void bta_sys_remove_uuid_32(UINT32 uuid32)
{
tBT_UUID uuid;
uuid.len = LEN_UUID_32;
uuid.uu.uuid32 = uuid32;

if (bta_sys_cb.eir_cb) {
bta_sys_cb.eir_cb(uuid16, FALSE);
bta_sys_cb.eir_cb(uuid, FALSE);
}
}

/*******************************************************************************
**
** Function bta_sys_remove_uuid_128
**
** Description Called by BTA subsystems to indicate to DM that the service
** class UUID is removed.
**
** Returns void
**
*******************************************************************************/
void bta_sys_remove_uuid_128(UINT8 *uuid128)
{
tBT_UUID uuid;
uuid.len = LEN_UUID_128;
memcpy(&uuid.uu.uuid128, uuid128, LEN_UUID_128);

if (bta_sys_cb.eir_cb) {
bta_sys_cb.eir_cb(uuid, FALSE);
}
}

#endif

/*******************************************************************************
Expand Down
93 changes: 77 additions & 16 deletions components/bt/host/bluedroid/btc/profile/std/sdp/btc_sdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,44 @@ static void set_sdp_handle(int id, int handle)
osi_mutex_unlock(&sdp_local_param.sdp_slot_mutex);
}


static bool get_sdp_record_by_handle(int handle, bluetooth_sdp_record* record)
{
sdp_slot_t *slot = NULL;

osi_mutex_lock(&sdp_local_param.sdp_slot_mutex, OSI_MUTEX_MAX_TIMEOUT);

for (int i = 0; i < SDP_MAX_RECORDS; i++) {
slot = sdp_local_param.sdp_slots[i];
if ((slot != NULL) && (slot->sdp_handle == handle)) {
memcpy(record, slot->record_data, sizeof(bluetooth_sdp_record));
osi_mutex_unlock(&sdp_local_param.sdp_slot_mutex);
return true;
}
}

osi_mutex_unlock(&sdp_local_param.sdp_slot_mutex);
return false;
}

static int get_sdp_slot_id_by_handle(int handle)
{
sdp_slot_t *slot = NULL;

osi_mutex_lock(&sdp_local_param.sdp_slot_mutex, OSI_MUTEX_MAX_TIMEOUT);

for (int i = 0; i < SDP_MAX_RECORDS; i++) {
slot = sdp_local_param.sdp_slots[i];
if ((slot != NULL) && (slot->sdp_handle == handle)) {
osi_mutex_unlock(&sdp_local_param.sdp_slot_mutex);
return i;
}
}

osi_mutex_unlock(&sdp_local_param.sdp_slot_mutex);
return -1;
}

static sdp_slot_t *start_create_sdp(int id)
{
sdp_slot_t *sdp_slot = NULL;
Expand Down Expand Up @@ -257,7 +295,6 @@ static int free_sdp_slot(int id)
static int add_raw_sdp(const bluetooth_sdp_record* rec)
{
tSDP_PROTOCOL_ELEM protoList [2];
UINT16 service = 0;
UINT16 browse = UUID_SERVCLASS_PUBLIC_BROWSE_GROUP;
bool status = true;
// Buffer capable to hold 2, 4 and 16-byte UUIDs
Expand All @@ -273,18 +310,15 @@ static int add_raw_sdp(const bluetooth_sdp_record* rec)
return sdp_handle;
}

if (rec->hdr.bt_uuid.len == 16) {
memcpy(&service, &rec->hdr.bt_uuid.uuid.uuid128[2], sizeof(service));
UINT8_TO_BE_STREAM(p_temp, (UUID_DESC_TYPE << 3) | SIZE_SIXTEEN_BYTES);
ARRAY_TO_BE_STREAM(p_temp, rec->hdr.bt_uuid.uuid.uuid128, LEN_UUID_128);
} else if (rec->hdr.bt_uuid.len == 2) {
memcpy(&service, &rec->hdr.bt_uuid.uuid.uuid16, sizeof(service));
UINT8_TO_BE_STREAM(p_temp, (UUID_DESC_TYPE << 3) | SIZE_TWO_BYTES);
UINT16_TO_BE_STREAM(p_temp, rec->hdr.bt_uuid.uuid.uuid16);
} else if (rec->hdr.bt_uuid.len == 4) {
memcpy(&service, &rec->hdr.bt_uuid.uuid.uuid16, sizeof(service));
UINT8_TO_BE_STREAM(p_temp, (UUID_DESC_TYPE << 3) | SIZE_FOUR_BYTES);
UINT32_TO_BE_STREAM(p_temp, rec->hdr.bt_uuid.uuid.uuid32);
if (rec->hdr.bt_uuid.len == ESP_UUID_LEN_16) {
UINT8_TO_BE_STREAM (p_temp, (UUID_DESC_TYPE << 3) | SIZE_TWO_BYTES);
UINT16_TO_BE_STREAM (p_temp, rec->hdr.bt_uuid.uuid.uuid16);
} else if (rec->hdr.bt_uuid.len == ESP_UUID_LEN_32) {
UINT8_TO_BE_STREAM (p_temp, (UUID_DESC_TYPE << 3) | SIZE_FOUR_BYTES);
UINT32_TO_BE_STREAM (p_temp, rec->hdr.bt_uuid.uuid.uuid32);
} else if (rec->hdr.bt_uuid.len == ESP_UUID_LEN_128) {
UINT8_TO_BE_STREAM (p_temp, (UUID_DESC_TYPE << 3) | SIZE_SIXTEEN_BYTES);
ARRAY_TO_BE_STREAM (p_temp, rec->hdr.bt_uuid.uuid.uuid128, LEN_UUID_128);
} else {
SDP_DeleteRecord(sdp_handle);
sdp_handle = 0;
Expand Down Expand Up @@ -331,7 +365,13 @@ static int add_raw_sdp(const bluetooth_sdp_record* rec)
sdp_handle = 0;
BTC_TRACE_ERROR("%s() FAILED, status = %d", __func__, status);
} else {
bta_sys_add_uuid(service);
if (rec->hdr.bt_uuid.len == ESP_UUID_LEN_16) {
bta_sys_add_uuid(rec->hdr.bt_uuid.uuid.uuid16);
ilutchenko marked this conversation as resolved.
Show resolved Hide resolved
} else if (rec->hdr.bt_uuid.len == ESP_UUID_LEN_32) {
bta_sys_add_uuid_32(rec->hdr.bt_uuid.uuid.uuid32);
} else if (rec->hdr.bt_uuid.len == ESP_UUID_LEN_128) {
bta_sys_add_uuid_128((UINT8 *)&rec->hdr.bt_uuid.uuid.uuid128);
}
BTC_TRACE_DEBUG("%s(): SDP Registered (handle 0x%08x)", __func__, sdp_handle);
}

Expand Down Expand Up @@ -842,7 +882,8 @@ static void btc_sdp_dm_cback(tBTA_SDP_EVT event, tBTA_SDP* p_data, void* user_da
switch (event) {
case BTA_SDP_CREATE_RECORD_USER_EVT: {
if (p_data->status == BTA_SDP_SUCCESS) {
if(btc_handle_create_record_event((int)user_data) < 0) {
p_data->sdp_create_record.handle = btc_handle_create_record_event((int)user_data);
if (p_data->sdp_create_record.handle < 0) {
p_data->status = BTA_SDP_FAILURE;
}
}
Expand Down Expand Up @@ -981,9 +1022,29 @@ static void btc_sdp_remove_record(btc_sdp_args_t *arg)
break;
}

bluetooth_sdp_record rec;
if (get_sdp_record_by_handle(arg->remove_record.record_handle, &rec)) {
if (rec.hdr.bt_uuid.len == ESP_UUID_LEN_16) {
bta_sys_remove_uuid(rec.hdr.bt_uuid.uuid.uuid16);
} else if (rec.hdr.bt_uuid.len == ESP_UUID_LEN_32) {
bta_sys_remove_uuid_32(rec.hdr.bt_uuid.uuid.uuid32);
} else if (rec.hdr.bt_uuid.len == ESP_UUID_LEN_128) {
bta_sys_remove_uuid_128((UINT8 *)&rec.hdr.bt_uuid.uuid.uuid128);
}
} else {
BTC_TRACE_ERROR("%s SDP record with handle %d not found",
__func__, arg->remove_record.record_handle);
return;
}

/* Get the Record handle, and free the slot */
/* The application layer record_handle is equivalent to the id of the btc layer */
handle = free_sdp_slot(arg->remove_record.record_handle);
int slot = get_sdp_slot_id_by_handle(arg->remove_record.record_handle);
if (slot < 0) {
return;
}

handle = free_sdp_slot(slot);

BTC_TRACE_DEBUG("Sdp Server %s id=%d to handle=0x%08x",
__func__, arg->remove_record.record_handle, handle);
Expand Down
Loading
Loading