Skip to content

Commit ab0e43d

Browse files
author
Jiang Jiang Jian
committed
Merge branch 'bugfix/sdp_uuid16_match_err_v5.4' into 'release/v5.4'
fix(bt): Fix the incorrect record found using uuid16 search(v5.4) See merge request espressif/esp-idf!36843
2 parents cf39293 + 44c606e commit ab0e43d

File tree

15 files changed

+63
-61
lines changed

15 files changed

+63
-61
lines changed

components/bt/host/bluedroid/api/esp_sdp_api.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -21,6 +21,10 @@ static bool esp_sdp_record_integrity_check(esp_bluetooth_sdp_record_t *record)
2121
bool ret = true;
2222

2323
if (record != NULL) {
24+
if (record->hdr.type < ESP_SDP_TYPE_RAW || record->hdr.type > ESP_SDP_TYPE_DIP_SERVER) {
25+
LOG_ERROR("Invalid type!\n");
26+
return false;
27+
}
2428
switch (record->hdr.type) {
2529
case ESP_SDP_TYPE_DIP_SERVER:
2630
if (record->dip.vendor_id_source != ESP_SDP_VENDOR_ID_SRC_BT &&
@@ -29,14 +33,28 @@ static bool esp_sdp_record_integrity_check(esp_bluetooth_sdp_record_t *record)
2933
ret = false;
3034
}
3135
break;
36+
case ESP_SDP_TYPE_MAP_MAS:
37+
if ((record->mas.mas_instance_id >> 8) || (record->mas.supported_message_types >> 8)) {
38+
LOG_ERROR("mas_instance_id and supported_message_types are defined as uint8_t in the spec!\n");
39+
ret = false;
40+
}
41+
break;
42+
case ESP_SDP_TYPE_PBAP_PSE:
43+
if (record->pse.supported_repositories >> 8) {
44+
LOG_ERROR("supported_repositories is defined in the spec as uint8_t!\n");
45+
ret = false;
46+
}
47+
break;
3248

3349
default:
50+
break;
51+
}
52+
if (record->hdr.type != ESP_SDP_TYPE_DIP_SERVER) {
3453
if (record->hdr.service_name_length > ESP_SDP_SERVER_NAME_MAX ||
3554
strlen(record->hdr.service_name) + 1 != record->hdr.service_name_length) {
3655
LOG_ERROR("Invalid server name!\n");
3756
ret = false;
3857
}
39-
break;
4058
}
4159
} else {
4260
LOG_ERROR("record is NULL!\n");

components/bt/host/bluedroid/bta/sdp/bta_sdp_act.c

Lines changed: 17 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -40,31 +40,6 @@
4040

4141
#if (SDP_INCLUDED == TRUE)
4242

43-
/*****************************************************************************
44-
** Constants
45-
*****************************************************************************/
46-
47-
static const uint8_t UUID_OBEX_OBJECT_PUSH[] = {0x00, 0x00, 0x11, 0x05, 0x00, 0x00, 0x10, 0x00,
48-
0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB
49-
};
50-
static const uint8_t UUID_PBAP_PSE[] = {0x00, 0x00, 0x11, 0x2F, 0x00, 0x00, 0x10, 0x00,
51-
0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB
52-
};
53-
static const uint8_t UUID_PBAP_PCE[] = {0x00, 0x00, 0x11, 0x2E, 0x00, 0x00, 0x10, 0x00,
54-
0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB
55-
};
56-
static const uint8_t UUID_MAP_MAS[] = {0x00, 0x00, 0x11, 0x32, 0x00, 0x00, 0x10, 0x00,
57-
0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB
58-
};
59-
static const uint8_t UUID_MAP_MNS[] = {0x00, 0x00, 0x11, 0x33, 0x00, 0x00, 0x10, 0x00,
60-
0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB
61-
};
62-
static const uint8_t UUID_SPP[] = {0x00, 0x00, 0x11, 0x01, 0x00, 0x00, 0x10, 0x00,
63-
0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB
64-
};
65-
static const uint8_t UUID_SAP[] = {0x00, 0x00, 0x11, 0x2D, 0x00, 0x00, 0x10, 0x00,
66-
0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB
67-
};
6843
// TODO:
6944
// Both the fact that the UUIDs are declared in multiple places, plus the fact
7045
// that there is a mess of UUID comparison and shortening methods will have to
@@ -369,7 +344,7 @@ static void bta_create_sap_sdp_record(bluetooth_sdp_record *record, tSDP_DISC_RE
369344
tSDP_PROTOCOL_ELEM pe;
370345
UINT16 pversion = -1;
371346

372-
record->sap.hdr.type = SDP_TYPE_MAP_MAS;
347+
record->sap.hdr.type = SDP_TYPE_SAP_SERVER;
373348
record->sap.hdr.service_name_length = 0;
374349
record->sap.hdr.service_name = NULL;
375350
record->sap.hdr.rfcomm_channel_number = 0;
@@ -420,6 +395,15 @@ static void bta_create_raw_sdp_record(bluetooth_sdp_record *record, tSDP_DISC_RE
420395
record->raw.hdr.user1_ptr = p_bta_sdp_cfg->p_sdp_db->raw_data;
421396
}
422397

398+
static bool check_if_uuid16_match(UINT16 uuid16, tBT_UUID *uuid)
399+
{
400+
// Because it is converted to a short UUID, only uuid16 needs to be checked.
401+
if (uuid->len == 2 && uuid->uu.uuid16 == uuid16) {
402+
return TRUE;
403+
} else {
404+
return FALSE;
405+
}
406+
}
423407

424408
/*******************************************************************************
425409
**
@@ -456,25 +440,25 @@ static void bta_sdp_search_cback(UINT16 result, void *user_data)
456440
/* generate the matching record data pointer */
457441
if (p_rec != NULL) {
458442
status = BTA_SDP_SUCCESS;
459-
if (uuid->uu.uuid16 == UUID_SERVCLASS_PNP_INFORMATION) {
443+
if (check_if_uuid16_match(UUID_SERVCLASS_PNP_INFORMATION, &su)) {
460444
APPL_TRACE_DEBUG("%s() - found DIP uuid\n", __func__);
461445
bta_create_dip_sdp_record(&evt_data.records[count], p_rec);
462-
} else if (IS_UUID(UUID_MAP_MAS, uuid->uu.uuid128)) {
446+
} else if (check_if_uuid16_match(UUID_SERVCLASS_MESSAGE_ACCESS, &su)) {
463447
APPL_TRACE_DEBUG("%s() - found MAP (MAS) uuid\n", __func__);
464448
bta_create_mas_sdp_record(&evt_data.records[count], p_rec);
465-
} else if (IS_UUID(UUID_MAP_MNS, uuid->uu.uuid128)) {
449+
} else if (check_if_uuid16_match(UUID_SERVCLASS_MESSAGE_NOTIFICATION, &su)) {
466450
APPL_TRACE_DEBUG("%s() - found MAP (MNS) uuid\n", __func__);
467451
bta_create_mns_sdp_record(&evt_data.records[count], p_rec);
468-
} else if (IS_UUID(UUID_PBAP_PSE, uuid->uu.uuid128)) {
452+
} else if (check_if_uuid16_match(UUID_SERVCLASS_PBAP_PSE, &su)) {
469453
APPL_TRACE_DEBUG("%s() - found PBAP (PSE) uuid\n", __func__);
470454
bta_create_pse_sdp_record(&evt_data.records[count], p_rec);
471-
} else if (IS_UUID(UUID_PBAP_PCE, uuid->uu.uuid128)) {
455+
} else if (check_if_uuid16_match(UUID_SERVCLASS_PBAP_PCE, &su)) {
472456
APPL_TRACE_DEBUG("%s() - found PBAP (PCE) uuid\n", __func__);
473457
bta_create_pce_sdp_record(&evt_data.records[count], p_rec);
474-
} else if (IS_UUID(UUID_OBEX_OBJECT_PUSH, uuid->uu.uuid128)) {
458+
} else if (check_if_uuid16_match(UUID_SERVCLASS_OBEX_OBJECT_PUSH, &su)) {
475459
APPL_TRACE_DEBUG("%s() - found Object Push Server (OPS) uuid\n", __func__);
476460
bta_create_ops_sdp_record(&evt_data.records[count], p_rec);
477-
} else if (IS_UUID(UUID_SAP, uuid->uu.uuid128)) {
461+
} else if (check_if_uuid16_match(UUID_SERVCLASS_SAP, &su)) {
478462
APPL_TRACE_DEBUG("%s() - found SAP uuid\n", __func__);
479463
bta_create_sap_sdp_record(&evt_data.records[count], p_rec);
480464
} else {

examples/bluetooth/bluedroid/classic_bt/a2dp_sink/main/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,12 @@ static void bt_app_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *pa
104104
#if (CONFIG_EXAMPLE_A2DP_SINK_SSP_ENABLED == true)
105105
/* when Security Simple Pairing user confirmation requested, this event comes */
106106
case ESP_BT_GAP_CFM_REQ_EVT:
107-
ESP_LOGI(BT_AV_TAG, "ESP_BT_GAP_CFM_REQ_EVT Please compare the numeric value: %"PRIu32, param->cfm_req.num_val);
107+
ESP_LOGI(BT_AV_TAG, "ESP_BT_GAP_CFM_REQ_EVT Please compare the numeric value: %06"PRIu32, param->cfm_req.num_val);
108108
esp_bt_gap_ssp_confirm_reply(param->cfm_req.bda, true);
109109
break;
110110
/* when Security Simple Pairing passkey notified, this event comes */
111111
case ESP_BT_GAP_KEY_NOTIF_EVT:
112-
ESP_LOGI(BT_AV_TAG, "ESP_BT_GAP_KEY_NOTIF_EVT passkey: %"PRIu32, param->key_notif.passkey);
112+
ESP_LOGI(BT_AV_TAG, "ESP_BT_GAP_KEY_NOTIF_EVT passkey: %06"PRIu32, param->key_notif.passkey);
113113
break;
114114
/* when Security Simple Pairing passkey requested, this event comes */
115115
case ESP_BT_GAP_KEY_REQ_EVT:

examples/bluetooth/bluedroid/classic_bt/a2dp_source/main/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,12 +271,12 @@ static void bt_app_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *pa
271271
#if (CONFIG_EXAMPLE_SSP_ENABLED == true)
272272
/* when Security Simple Pairing user confirmation requested, this event comes */
273273
case ESP_BT_GAP_CFM_REQ_EVT:
274-
ESP_LOGI(BT_AV_TAG, "ESP_BT_GAP_CFM_REQ_EVT Please compare the numeric value: %"PRIu32, param->cfm_req.num_val);
274+
ESP_LOGI(BT_AV_TAG, "ESP_BT_GAP_CFM_REQ_EVT Please compare the numeric value: %06"PRIu32, param->cfm_req.num_val);
275275
esp_bt_gap_ssp_confirm_reply(param->cfm_req.bda, true);
276276
break;
277277
/* when Security Simple Pairing passkey notified, this event comes */
278278
case ESP_BT_GAP_KEY_NOTIF_EVT:
279-
ESP_LOGI(BT_AV_TAG, "ESP_BT_GAP_KEY_NOTIF_EVT passkey: %"PRIu32, param->key_notif.passkey);
279+
ESP_LOGI(BT_AV_TAG, "ESP_BT_GAP_KEY_NOTIF_EVT passkey: %06"PRIu32, param->key_notif.passkey);
280280
break;
281281
/* when Security Simple Pairing passkey requested, this event comes */
282282
case ESP_BT_GAP_KEY_REQ_EVT:

examples/bluetooth/bluedroid/classic_bt/bt_hid_mouse_device/main/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,11 @@ void esp_bt_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *param)
205205

206206
#if (CONFIG_EXAMPLE_SSP_ENABLED == true)
207207
case ESP_BT_GAP_CFM_REQ_EVT:
208-
ESP_LOGI(TAG, "ESP_BT_GAP_CFM_REQ_EVT Please compare the numeric value: %"PRIu32, param->cfm_req.num_val);
208+
ESP_LOGI(TAG, "ESP_BT_GAP_CFM_REQ_EVT Please compare the numeric value: %06"PRIu32, param->cfm_req.num_val);
209209
esp_bt_gap_ssp_confirm_reply(param->cfm_req.bda, true);
210210
break;
211211
case ESP_BT_GAP_KEY_NOTIF_EVT:
212-
ESP_LOGI(TAG, "ESP_BT_GAP_KEY_NOTIF_EVT passkey:%"PRIu32, param->key_notif.passkey);
212+
ESP_LOGI(TAG, "ESP_BT_GAP_KEY_NOTIF_EVT passkey:%06"PRIu32, param->key_notif.passkey);
213213
break;
214214
case ESP_BT_GAP_KEY_REQ_EVT:
215215
ESP_LOGI(TAG, "ESP_BT_GAP_KEY_REQ_EVT Please enter passkey!");

examples/bluetooth/bluedroid/classic_bt/bt_l2cap_client/main/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,12 @@ static void esp_bt_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *pa
179179
#if (CONFIG_EXAMPLE_SSP_ENABLED == true)
180180
/* when Security Simple Pairing user confirmation requested, this event comes */
181181
case ESP_BT_GAP_CFM_REQ_EVT:
182-
ESP_LOGI(L2CAP_TAG, "ESP_BT_GAP_CFM_REQ_EVT Please compare the numeric value: %"PRIu32, param->cfm_req.num_val);
182+
ESP_LOGI(L2CAP_TAG, "ESP_BT_GAP_CFM_REQ_EVT Please compare the numeric value: %06"PRIu32, param->cfm_req.num_val);
183183
esp_bt_gap_ssp_confirm_reply(param->cfm_req.bda, true);
184184
break;
185185
/* when Security Simple Pairing passkey notified, this event comes */
186186
case ESP_BT_GAP_KEY_NOTIF_EVT:
187-
ESP_LOGI(L2CAP_TAG, "ESP_BT_GAP_KEY_NOTIF_EVT passkey: %"PRIu32, param->key_notif.passkey);
187+
ESP_LOGI(L2CAP_TAG, "ESP_BT_GAP_KEY_NOTIF_EVT passkey: %06"PRIu32, param->key_notif.passkey);
188188
break;
189189
/* when Security Simple Pairing passkey requested, this event comes */
190190
case ESP_BT_GAP_KEY_REQ_EVT:

examples/bluetooth/bluedroid/classic_bt/bt_l2cap_server/main/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,12 @@ static void esp_bt_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *pa
9393
#if (CONFIG_EXAMPLE_SSP_ENABLED == true)
9494
/* when Security Simple Pairing user confirmation requested, this event comes */
9595
case ESP_BT_GAP_CFM_REQ_EVT:
96-
ESP_LOGI(L2CAP_TAG, "ESP_BT_GAP_CFM_REQ_EVT Please compare the numeric value: %"PRIu32, param->cfm_req.num_val);
96+
ESP_LOGI(L2CAP_TAG, "ESP_BT_GAP_CFM_REQ_EVT Please compare the numeric value: %06"PRIu32, param->cfm_req.num_val);
9797
esp_bt_gap_ssp_confirm_reply(param->cfm_req.bda, true);
9898
break;
9999
/* when Security Simple Pairing passkey notified, this event comes */
100100
case ESP_BT_GAP_KEY_NOTIF_EVT:
101-
ESP_LOGI(L2CAP_TAG, "ESP_BT_GAP_KEY_NOTIF_EVT passkey:%"PRIu32, param->key_notif.passkey);
101+
ESP_LOGI(L2CAP_TAG, "ESP_BT_GAP_KEY_NOTIF_EVT passkey:%06"PRIu32, param->key_notif.passkey);
102102
break;
103103
/* when Security Simple Pairing passkey requested, this event comes */
104104
case ESP_BT_GAP_KEY_REQ_EVT:

examples/bluetooth/bluedroid/classic_bt/bt_spp_acceptor/main/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,11 @@ void esp_bt_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *param)
176176

177177
#if (CONFIG_EXAMPLE_SSP_ENABLED == true)
178178
case ESP_BT_GAP_CFM_REQ_EVT:
179-
ESP_LOGI(SPP_TAG, "ESP_BT_GAP_CFM_REQ_EVT Please compare the numeric value: %"PRIu32, param->cfm_req.num_val);
179+
ESP_LOGI(SPP_TAG, "ESP_BT_GAP_CFM_REQ_EVT Please compare the numeric value: %06"PRIu32, param->cfm_req.num_val);
180180
esp_bt_gap_ssp_confirm_reply(param->cfm_req.bda, true);
181181
break;
182182
case ESP_BT_GAP_KEY_NOTIF_EVT:
183-
ESP_LOGI(SPP_TAG, "ESP_BT_GAP_KEY_NOTIF_EVT passkey:%"PRIu32, param->key_notif.passkey);
183+
ESP_LOGI(SPP_TAG, "ESP_BT_GAP_KEY_NOTIF_EVT passkey:%06"PRIu32, param->key_notif.passkey);
184184
break;
185185
case ESP_BT_GAP_KEY_REQ_EVT:
186186
ESP_LOGI(SPP_TAG, "ESP_BT_GAP_KEY_REQ_EVT Please enter passkey!");

examples/bluetooth/bluedroid/classic_bt/bt_spp_initiator/main/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,11 +305,11 @@ static void esp_bt_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *pa
305305

306306
#if (CONFIG_EXAMPLE_SSP_ENABLED == true)
307307
case ESP_BT_GAP_CFM_REQ_EVT:
308-
ESP_LOGI(SPP_TAG, "ESP_BT_GAP_CFM_REQ_EVT Please compare the numeric value: %"PRIu32, param->cfm_req.num_val);
308+
ESP_LOGI(SPP_TAG, "ESP_BT_GAP_CFM_REQ_EVT Please compare the numeric value: %06"PRIu32, param->cfm_req.num_val);
309309
ESP_LOGW(SPP_TAG, "To confirm the value, type `spp ok;`");
310310
break;
311311
case ESP_BT_GAP_KEY_NOTIF_EVT:
312-
ESP_LOGI(SPP_TAG, "ESP_BT_GAP_KEY_NOTIF_EVT passkey:%"PRIu32, param->key_notif.passkey);
312+
ESP_LOGI(SPP_TAG, "ESP_BT_GAP_KEY_NOTIF_EVT passkey:%06"PRIu32, param->key_notif.passkey);
313313
ESP_LOGW(SPP_TAG, "Waiting response...");
314314
break;
315315
case ESP_BT_GAP_KEY_REQ_EVT:

examples/bluetooth/bluedroid/classic_bt/bt_spp_vfs_acceptor/main/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,11 +188,11 @@ void esp_bt_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *param)
188188

189189
#if (CONFIG_EXAMPLE_SSP_ENABLED == true)
190190
case ESP_BT_GAP_CFM_REQ_EVT:
191-
ESP_LOGI(SPP_TAG, "ESP_BT_GAP_CFM_REQ_EVT Please compare the numeric value: %"PRIu32, param->cfm_req.num_val);
191+
ESP_LOGI(SPP_TAG, "ESP_BT_GAP_CFM_REQ_EVT Please compare the numeric value: %06"PRIu32, param->cfm_req.num_val);
192192
esp_bt_gap_ssp_confirm_reply(param->cfm_req.bda, true);
193193
break;
194194
case ESP_BT_GAP_KEY_NOTIF_EVT:
195-
ESP_LOGI(SPP_TAG, "ESP_BT_GAP_KEY_NOTIF_EVT passkey:%"PRIu32, param->key_notif.passkey);
195+
ESP_LOGI(SPP_TAG, "ESP_BT_GAP_KEY_NOTIF_EVT passkey:%06"PRIu32, param->key_notif.passkey);
196196
break;
197197
case ESP_BT_GAP_KEY_REQ_EVT:
198198
ESP_LOGI(SPP_TAG, "ESP_BT_GAP_KEY_REQ_EVT Please enter passkey!");

0 commit comments

Comments
 (0)