Skip to content

Commit f420609

Browse files
committed
Merge branch 'bugfix/fix_ble_creat_conn_fail_enh' into 'master'
fix(ble/bluedroid): Fixed BLE create connection fail because of invalid own address type Closes BLERP-639 See merge request espressif/esp-idf!34895
2 parents 5910fc8 + b65f8a9 commit f420609

File tree

24 files changed

+312
-122
lines changed

24 files changed

+312
-122
lines changed

components/bt/esp_ble_mesh/core/bluedroid_host/adapter.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1790,8 +1790,8 @@ int bt_mesh_gattc_conn_create(const bt_mesh_addr_t *addr, uint16_t service_uuid)
17901790

17911791
BTA_DmBleGapPreferExtConnectParamsSet(bt_mesh_gattc_info[i].addr.val, 0x01, &conn_1m_param ,NULL, NULL);
17921792

1793-
BTA_GATTC_Open(bt_mesh_gattc_if, bt_mesh_gattc_info[i].addr.val,
1794-
bt_mesh_gattc_info[i].addr.type, true, BTA_GATT_TRANSPORT_LE, TRUE);
1793+
BTA_GATTC_Enh_Open(bt_mesh_gattc_if, bt_mesh_gattc_info[i].addr.val,
1794+
bt_mesh_gattc_info[i].addr.type, true, BTA_GATT_TRANSPORT_LE, TRUE, BLE_ADDR_UNKNOWN_TYPE);
17951795
#else
17961796
/* Min_interval: 15ms
17971797
* Max_interval: 15ms
@@ -1801,8 +1801,8 @@ int bt_mesh_gattc_conn_create(const bt_mesh_addr_t *addr, uint16_t service_uuid)
18011801

18021802
BTA_DmSetBlePrefConnParams(bt_mesh_gattc_info[i].addr.val, 0x18, 0x18, 0x00, 0x64);
18031803

1804-
BTA_GATTC_Open(bt_mesh_gattc_if, bt_mesh_gattc_info[i].addr.val,
1805-
bt_mesh_gattc_info[i].addr.type, true, BTA_GATT_TRANSPORT_LE, FALSE);
1804+
BTA_GATTC_Enh_Open(bt_mesh_gattc_if, bt_mesh_gattc_info[i].addr.val,
1805+
bt_mesh_gattc_info[i].addr.type, true, BTA_GATT_TRANSPORT_LE, FALSE, BLE_ADDR_UNKNOWN_TYPE);
18061806
#endif
18071807

18081808
return 0;

components/bt/host/bluedroid/Kconfig.in

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,19 +1217,23 @@ config BT_BLE_RPA_TIMEOUT
12171217
Default is 900 s (15 minutes). Range is 1 s to 1 hour (3600 s).
12181218

12191219
config BT_BLE_50_FEATURES_SUPPORTED
1220-
bool "Enable BLE 5.0 features"
1220+
bool "Enable BLE 5.0 features(please disable BLE 4.2 if enable BLE 5.0)"
12211221
depends on (BT_BLE_ENABLED && ((BT_CONTROLLER_ENABLED && SOC_BLE_50_SUPPORTED) || BT_CONTROLLER_DISABLED))
12221222
default y
12231223
help
12241224
Enabling this option activates BLE 5.0 features.
12251225
This option is universally supported in chips that support BLE, except for ESP32.
1226+
BLE 4.2 and BLE 5.0 cannot be used simultaneously.
1227+
12261228

12271229
config BT_BLE_42_FEATURES_SUPPORTED
1228-
bool "Enable BLE 4.2 features"
1230+
bool "Enable BLE 4.2 features(please disable BLE 5.0 if enable BLE 4.2)"
12291231
depends on (BT_BLE_ENABLED && ((BT_CONTROLLER_ENABLED && SOC_BLE_SUPPORTED) || BT_CONTROLLER_DISABLED))
12301232
default n
12311233
help
12321234
This enables BLE 4.2 features.
1235+
This option is universally supported by all ESP chips with BLE capabilities.
1236+
BLE 4.2 and BLE 5.0 cannot be used simultaneously.
12331237

12341238
config BT_BLE_FEAT_PERIODIC_ADV_SYNC_TRANSFER
12351239
bool "Enable BLE periodic advertising sync transfer feature"

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

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ esp_err_t esp_ble_gattc_app_unregister(esp_gatt_if_t gattc_if)
6767

6868
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
6969
}
70-
#if (BLE_42_FEATURE_SUPPORT == TRUE)
71-
esp_err_t esp_ble_gattc_open(esp_gatt_if_t gattc_if, esp_bd_addr_t remote_bda, esp_ble_addr_type_t remote_addr_type, bool is_direct)
70+
71+
esp_err_t esp_ble_gattc_enh_open(esp_gatt_if_t gattc_if, esp_ble_gatt_creat_conn_params_t esp_gatt_create_conn)
7272
{
7373
btc_msg_t msg = {0};
7474
btc_ble_gattc_args_t arg;
@@ -79,34 +79,38 @@ esp_err_t esp_ble_gattc_open(esp_gatt_if_t gattc_if, esp_bd_addr_t remote_bda, e
7979
msg.pid = BTC_PID_GATTC;
8080
msg.act = BTC_GATTC_ACT_OPEN;
8181
arg.open.gattc_if = gattc_if;
82-
memcpy(arg.open.remote_bda, remote_bda, ESP_BD_ADDR_LEN);
83-
arg.open.remote_addr_type = remote_addr_type;
84-
arg.open.is_direct = is_direct;
85-
arg.open.is_aux = false;
82+
memcpy(arg.open.remote_bda, esp_gatt_create_conn.remote_bda, ESP_BD_ADDR_LEN);
83+
arg.open.remote_addr_type = esp_gatt_create_conn.remote_addr_type;
84+
arg.open.is_direct = esp_gatt_create_conn.is_direct;
85+
arg.open.is_aux= esp_gatt_create_conn.is_aux;
86+
arg.open.own_addr_type = esp_gatt_create_conn.own_addr_type;
8687

8788
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
8889
}
90+
91+
#if (BLE_42_FEATURE_SUPPORT == TRUE)
92+
esp_err_t esp_ble_gattc_open(esp_gatt_if_t gattc_if, esp_bd_addr_t remote_bda, esp_ble_addr_type_t remote_addr_type, bool is_direct)
93+
{
94+
esp_ble_gatt_creat_conn_params_t esp_gatt_create_conn;
95+
memcpy(esp_gatt_create_conn.remote_bda, remote_bda, ESP_BD_ADDR_LEN);
96+
esp_gatt_create_conn.remote_addr_type = remote_addr_type;
97+
esp_gatt_create_conn.is_direct = is_direct;
98+
esp_gatt_create_conn.is_aux = false;
99+
esp_gatt_create_conn.own_addr_type = 0xff; //undefined, will use local value
100+
return esp_ble_gattc_enh_open(gattc_if, esp_gatt_create_conn);
101+
}
89102
#endif // #if (BLE_42_FEATURE_SUPPORT == TRUE)
90103

91104
#if (BLE_50_FEATURE_SUPPORT == TRUE)
92105
esp_err_t esp_ble_gattc_aux_open(esp_gatt_if_t gattc_if, esp_bd_addr_t remote_bda, esp_ble_addr_type_t remote_addr_type, bool is_direct)
93106
{
94-
btc_msg_t msg;
95-
btc_ble_gattc_args_t arg;
96-
97-
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
98-
99-
msg.sig = BTC_SIG_API_CALL;
100-
msg.pid = BTC_PID_GATTC;
101-
msg.act = BTC_GATTC_ACT_AUX_OPEN;
102-
arg.open.gattc_if = gattc_if;
103-
memcpy(arg.open.remote_bda, remote_bda, ESP_BD_ADDR_LEN);
104-
arg.open.remote_addr_type = remote_addr_type;
105-
arg.open.is_direct = is_direct;
106-
arg.open.is_aux = true;
107-
108-
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
109-
107+
esp_ble_gatt_creat_conn_params_t esp_gatt_create_conn;
108+
memcpy(esp_gatt_create_conn.remote_bda, remote_bda, ESP_BD_ADDR_LEN);
109+
esp_gatt_create_conn.remote_addr_type = remote_addr_type;
110+
esp_gatt_create_conn.is_direct = is_direct;
111+
esp_gatt_create_conn.is_aux = true;
112+
esp_gatt_create_conn.own_addr_type = 0xff; //undefined, will use local value
113+
return esp_ble_gattc_enh_open(gattc_if, esp_gatt_create_conn);
110114
}
111115
#endif // #if (BLE_50_FEATURE_SUPPORT == TRUE)
112116

components/bt/host/bluedroid/api/include/api/esp_gatt_defs.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,15 @@ typedef struct {
682682
esp_bt_uuid_t uuid; /*!< Included service UUID. */
683683
} esp_gattc_incl_svc_elem_t;
684684

685+
/** @brief Represents a creat connection element. */
686+
typedef struct {
687+
esp_bd_addr_t remote_bda; /*!< The Bluetooth address of the remote device */
688+
esp_ble_addr_type_t remote_addr_type; /*!< Address type of the remote device */
689+
bool is_direct; /*!< Direct connection or background auto connection(by now, background auto connection is not supported */
690+
bool is_aux; /*!< Set to true for BLE 5.0 or higher to enable auxiliary connections; set to false for BLE 4.2 or lower. */
691+
esp_ble_addr_type_t own_addr_type; /*!< Specifies the address type used in the connection request. Set to 0xFF if the address type is unknown. */
692+
} esp_ble_gatt_creat_conn_params_t;
693+
685694
#ifdef __cplusplus
686695
}
687696
#endif

components/bt/host/bluedroid/api/include/api/esp_gattc_api.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,20 @@ esp_err_t esp_ble_gattc_app_register(uint16_t app_id);
314314
*/
315315
esp_err_t esp_ble_gattc_app_unregister(esp_gatt_if_t gattc_if);
316316

317-
#if (BLE_42_FEATURE_SUPPORT == TRUE)
317+
/**
318+
* @brief Open a direct connection or add a background auto connection.
319+
* Note: Do not enable both BLE_42_FEATURE_SUPPORT and BLE_50_FEATURE_SUPPORT configuration options simultaneously.
320+
*
321+
* @param[in] gattc_if: GATT client access interface.
322+
* @param[in] esp_gatt_create_conn: Structure containing connection parameters.
323+
*
324+
* @return
325+
* - ESP_OK: Operation successful
326+
* - others: Operation failed
327+
*
328+
*/
329+
esp_err_t esp_ble_gattc_enh_open(esp_gatt_if_t gattc_if, esp_ble_gatt_creat_conn_params_t esp_gatt_create_conn);
330+
318331
/**
319332
* @brief Open a direct connection or add a background auto connection
320333
*
@@ -328,12 +341,14 @@ esp_err_t esp_ble_gattc_app_unregister(esp_gatt_if_t gattc_if);
328341
* - other: failed
329342
*
330343
*/
344+
#if (BLE_42_FEATURE_SUPPORT == TRUE)
331345
esp_err_t esp_ble_gattc_open(esp_gatt_if_t gattc_if, esp_bd_addr_t remote_bda, esp_ble_addr_type_t remote_addr_type, bool is_direct);
332346
#endif // #if (BLE_42_FEATURE_SUPPORT == TRUE)
333347

334348
#if (BLE_50_FEATURE_SUPPORT == TRUE)
335349
esp_err_t esp_ble_gattc_aux_open(esp_gatt_if_t gattc_if, esp_bd_addr_t remote_bda, esp_ble_addr_type_t remote_addr_type, bool is_direct);
336350
#endif // #if (BLE_50_FEATURE_SUPPORT == TRUE)
351+
337352
/**
338353
* @brief Close the virtual connection to the GATT server. gattc may have multiple virtual GATT server connections when multiple app_id registered,
339354
* this API only close one virtual GATT server connection. if there exist other virtual GATT server connections,

components/bt/host/bluedroid/bta/dm/bta_dm_act.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6673,7 +6673,8 @@ void btm_dm_start_gatt_discovery (BD_ADDR bd_addr)
66736673
btm_dm_start_disc_gatt_services(bta_dm_search_cb.conn_id);
66746674
} else {
66756675
//TODO need to add addr_type in future
6676-
BTA_GATTC_Open(bta_dm_search_cb.client_if, bd_addr, BLE_ADDR_UNKNOWN_TYPE, TRUE, BTA_GATT_TRANSPORT_LE, FALSE);
6676+
BTA_GATTC_Enh_Open(bta_dm_search_cb.client_if, bd_addr, BLE_ADDR_UNKNOWN_TYPE, TRUE, BTA_GATT_TRANSPORT_LE, FALSE, BLE_ADDR_UNKNOWN_TYPE);
6677+
66776678
}
66786679
}
66796680
#endif /* #if (GATTC_INCLUDED == TRUE) */

components/bt/host/bluedroid/bta/gatt/bta_gattc_act.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ static void bta_gattc_req_cback (UINT16 conn_id, UINT32 trans_id, tGATTS_REQ_TYP
7070
static tBTA_GATTC_FIND_SERVICE_CB bta_gattc_register_service_change_notify(UINT16 conn_id, BD_ADDR remote_bda);
7171

7272
extern void btc_gattc_congest_callback(tBTA_GATTC *param);
73+
extern uint32_t BTM_BleUpdateOwnType(uint8_t *own_bda_type, tBTM_START_ADV_CMPL_CBACK *cb);
7374

7475
static const tGATT_CBACK bta_gattc_cl_cback = {
7576
bta_gattc_conn_cback,
@@ -336,6 +337,10 @@ void bta_gattc_process_api_open (tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA *p_msg)
336337
UNUSED(p_cb);
337338

338339
if (p_clreg != NULL) {
340+
if (p_msg->api_conn.own_addr_type <= BLE_ADDR_TYPE_MAX) {
341+
// update own address type for creating connection
342+
BTM_BleUpdateOwnType(&p_msg->api_conn.own_addr_type, NULL);
343+
}
339344
if (p_msg->api_conn.is_direct) {
340345
if ((p_clcb = bta_gattc_find_alloc_clcb(p_msg->api_conn.client_if,
341346
p_msg->api_conn.remote_bda,

components/bt/host/bluedroid/bta/gatt/bta_gattc_api.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ void BTA_GATTC_AppDeregister(tBTA_GATTC_IF client_if)
128128

129129
/*******************************************************************************
130130
**
131-
** Function BTA_GATTC_Open
131+
** Function BTA_GATTC_Enh_Open
132132
**
133133
** Description Open a direct connection or add a background auto connection
134134
** bd address
@@ -142,8 +142,8 @@ void BTA_GATTC_AppDeregister(tBTA_GATTC_IF client_if)
142142
** Returns void
143143
**
144144
*******************************************************************************/
145-
void BTA_GATTC_Open(tBTA_GATTC_IF client_if, BD_ADDR remote_bda, tBTA_ADDR_TYPE remote_addr_type,
146-
BOOLEAN is_direct, tBTA_GATT_TRANSPORT transport, BOOLEAN is_aux)
145+
void BTA_GATTC_Enh_Open(tBTA_GATTC_IF client_if, BD_ADDR remote_bda, tBTA_ADDR_TYPE remote_addr_type,
146+
BOOLEAN is_direct, tBTA_GATT_TRANSPORT transport, BOOLEAN is_aux, tBTA_ADDR_TYPE own_addr_type)
147147
{
148148
tBTA_GATTC_API_OPEN *p_buf;
149149

@@ -155,6 +155,7 @@ void BTA_GATTC_Open(tBTA_GATTC_IF client_if, BD_ADDR remote_bda, tBTA_ADDR_TYPE
155155
p_buf->transport = transport;
156156
p_buf->is_aux = is_aux;
157157
p_buf->remote_addr_type = remote_addr_type;
158+
p_buf->own_addr_type = own_addr_type;
158159
memcpy(p_buf->remote_bda, remote_bda, BD_ADDR_LEN);
159160

160161

@@ -472,7 +473,7 @@ void BTA_GATTC_GetGattDb(UINT16 conn_id, UINT16 start_handle, UINT16 end_handle
472473
** Description This function is called to read a characteristics value
473474
**
474475
** Parameters conn_id - connection ID.
475-
** handle - characteritic handle to read.
476+
** handle - characteristic handle to read.
476477
**
477478
** Returns None
478479
**
@@ -607,7 +608,7 @@ void BTA_GATTC_ReadMultipleVariable(UINT16 conn_id, tBTA_GATTC_MULTI *p_read_mul
607608
**
608609
** Parameters conn_id - connection ID.
609610
** s_handle - start handle.
610-
** e_handle - end hanle
611+
** e_handle - end handle
611612
** uuid - The attribute UUID.
612613
**
613614
** Returns None
@@ -687,7 +688,7 @@ void BTA_GATTC_WriteCharValue ( UINT16 conn_id,
687688
** Description This function is called to write descriptor value.
688689
**
689690
** Parameters conn_id - connection ID
690-
** handle - descriptor hadle to write.
691+
** handle - descriptor handle to write.
691692
** write_type - write type.
692693
** p_value - the value to be written.
693694
**
@@ -738,7 +739,7 @@ void BTA_GATTC_WriteCharDescr (UINT16 conn_id,
738739
** Description This function is called to prepare write a characteristic value.
739740
**
740741
** Parameters conn_id - connection ID.
741-
** p_char_id - GATT characteritic ID of the service.
742+
** p_char_id - GATT characteristic ID of the service.
742743
** offset - offset of the write value.
743744
** len: length of the data to be written.
744745
** p_value - the value to be written.
@@ -781,7 +782,7 @@ void BTA_GATTC_PrepareWrite (UINT16 conn_id, UINT16 handle,
781782
** Description This function is called to prepare write a characteristic descriptor value.
782783
**
783784
** Parameters conn_id - connection ID.
784-
** p_char_descr_id - GATT characteritic descriptor ID of the service.
785+
** p_char_descr_id - GATT characteristic descriptor ID of the service.
785786
** offset - offset of the write value.
786787
** len: length of the data to be written.
787788
** p_value - the value to be written.

components/bt/host/bluedroid/bta/gatt/include/bta_gattc_int.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ typedef enum {
110110
#define BTA_GATTC_WRITE_PREPARE GATT_WRITE_PREPARE
111111
#define BTA_GATTC_INVALID_HANDLE 0
112112

113-
/* internal strucutre for GATTC register API */
113+
/* internal structure for GATTC register API */
114114
typedef struct {
115115
BT_HDR hdr;
116116
tBT_UUID app_uuid;
@@ -133,6 +133,7 @@ typedef struct {
133133
BOOLEAN is_direct;
134134
BOOLEAN is_aux;
135135
tBTA_TRANSPORT transport;
136+
tBTA_ADDR_TYPE own_addr_type;
136137
} tBTA_GATTC_API_OPEN;
137138

138139
typedef tBTA_GATTC_API_OPEN tBTA_GATTC_API_CANCEL_OPEN;
@@ -313,7 +314,7 @@ typedef struct {
313314
UINT16 total_char;
314315
UINT16 total_attr;
315316
UINT8 srvc_hdl_chg; /* service handle change indication pending */
316-
UINT16 attr_index; /* cahce NV saving/loading attribute index */
317+
UINT16 attr_index; /* cache NV saving/loading attribute index */
317318

318319
UINT16 mtu;
319320
bool update_incl_srvc;

0 commit comments

Comments
 (0)