From: zhiweijian <zhiweijian@espressif.com> Date: Fri, 23 Mar 2018 03:08:03 +0000 (+0800) Subject: Component/bt: fix connect fail when remote addr type is random X-Git-Tag: v3.1-beta1~302^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e6262375a31fc16c98a22895bf0cf49ae66514f7;p=esp-idf Component/bt: fix connect fail when remote addr type is random --- diff --git a/components/bt/bluedroid/api/esp_gattc_api.c b/components/bt/bluedroid/api/esp_gattc_api.c index c79ecec5ee..83c9366080 100644 --- a/components/bt/bluedroid/api/esp_gattc_api.c +++ b/components/bt/bluedroid/api/esp_gattc_api.c @@ -67,7 +67,7 @@ esp_err_t esp_ble_gattc_app_unregister(esp_gatt_if_t gattc_if) return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL); } -esp_err_t esp_ble_gattc_open(esp_gatt_if_t gattc_if, esp_bd_addr_t remote_bda, bool is_direct) +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) { btc_msg_t msg; btc_ble_gattc_args_t arg; @@ -79,6 +79,7 @@ esp_err_t esp_ble_gattc_open(esp_gatt_if_t gattc_if, esp_bd_addr_t remote_bda, b msg.act = BTC_GATTC_ACT_OPEN; arg.open.gattc_if = gattc_if; memcpy(arg.open.remote_bda, remote_bda, ESP_BD_ADDR_LEN); + arg.open.remote_addr_type = remote_addr_type; arg.open.is_direct = is_direct; return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL); diff --git a/components/bt/bluedroid/api/include/esp_gattc_api.h b/components/bt/bluedroid/api/include/esp_gattc_api.h index adf3dbda37..26afd0f637 100644 --- a/components/bt/bluedroid/api/include/esp_gattc_api.h +++ b/components/bt/bluedroid/api/include/esp_gattc_api.h @@ -283,6 +283,7 @@ esp_err_t esp_ble_gattc_app_unregister(esp_gatt_if_t gattc_if); * * @param[in] gattc_if: Gatt client access interface. * @param[in] remote_bda: remote device bluetooth device address. + * @param[in] remote_addr_type: remote device bluetooth device the address type. * @param[in] is_direct: direct connection or background auto connection * * @return @@ -290,7 +291,7 @@ esp_err_t esp_ble_gattc_app_unregister(esp_gatt_if_t gattc_if); * - other: failed * */ -esp_err_t esp_ble_gattc_open(esp_gatt_if_t gattc_if, esp_bd_addr_t remote_bda, bool is_direct); +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); /** diff --git a/components/bt/bluedroid/bta/dm/bta_dm_act.c b/components/bt/bluedroid/bta/dm/bta_dm_act.c index 0a14a35acb..60c2867bc6 100644 --- a/components/bt/bluedroid/bta/dm/bta_dm_act.c +++ b/components/bt/bluedroid/bta/dm/bta_dm_act.c @@ -5631,7 +5631,8 @@ void btm_dm_start_gatt_discovery (BD_ADDR bd_addr) bta_sys_stop_timer(&bta_dm_search_cb.gatt_close_timer); btm_dm_start_disc_gatt_services(bta_dm_search_cb.conn_id); } else { - BTA_GATTC_Open(bta_dm_search_cb.client_if, bd_addr, TRUE, BTA_GATT_TRANSPORT_LE); + //TODO need to add addr_type in future + BTA_GATTC_Open(bta_dm_search_cb.client_if, bd_addr, BLE_ADDR_UNKNOWN_TYPE, TRUE, BTA_GATT_TRANSPORT_LE); } } #endif /* #if (GATTC_INCLUDED == TRUE) */ diff --git a/components/bt/bluedroid/bta/gatt/bta_gattc_act.c b/components/bt/bluedroid/bta/gatt/bta_gattc_act.c index c9189b20df..c49e52e522 100644 --- a/components/bt/bluedroid/bta/gatt/bta_gattc_act.c +++ b/components/bt/bluedroid/bta/gatt/bta_gattc_act.c @@ -500,7 +500,7 @@ void bta_gattc_open(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data) found_app = gatt_find_specific_app_in_hold_link(p_tcb, p_clcb->p_rcb->client_if); } /* open/hold a connection */ - if (!GATT_Connect(p_clcb->p_rcb->client_if, p_data->api_conn.remote_bda, + if (!GATT_Connect(p_clcb->p_rcb->client_if, p_data->api_conn.remote_bda, p_data->api_conn.remote_addr_type, TRUE, p_data->api_conn.transport)) { APPL_TRACE_ERROR("Connection open failure"); @@ -536,7 +536,7 @@ void bta_gattc_init_bk_conn(tBTA_GATTC_API_OPEN *p_data, tBTA_GATTC_RCB *p_clreg if (bta_gattc_mark_bg_conn(p_data->client_if, p_data->remote_bda, TRUE, FALSE)) { /* always call open to hold a connection */ - if (!GATT_Connect(p_data->client_if, p_data->remote_bda, FALSE, p_data->transport)) { + if (!GATT_Connect(p_data->client_if, p_data->remote_bda, p_data->remote_addr_type, FALSE, p_data->transport)) { uint8_t *bda = (uint8_t *)p_data->remote_bda; status = BTA_GATT_ERROR; APPL_TRACE_ERROR("%s unable to connect to remote bd_addr:%02x:%02x:%02x:%02x:%02x:%02x", diff --git a/components/bt/bluedroid/bta/gatt/bta_gattc_api.c b/components/bt/bluedroid/bta/gatt/bta_gattc_api.c index 84153d58f9..ab3e919e28 100644 --- a/components/bt/bluedroid/bta/gatt/bta_gattc_api.c +++ b/components/bt/bluedroid/bta/gatt/bta_gattc_api.c @@ -135,13 +135,14 @@ void BTA_GATTC_AppDeregister(tBTA_GATTC_IF client_if) ** ** Parameters client_if: server interface. ** remote_bda: remote device BD address. +** remote_addr_type: remote device BD address type. ** is_direct: direct connection or background auto connection ** transport: Transport to be used for GATT connection (BREDR/LE) ** ** Returns void ** *******************************************************************************/ -void BTA_GATTC_Open(tBTA_GATTC_IF client_if, BD_ADDR remote_bda, +void BTA_GATTC_Open(tBTA_GATTC_IF client_if, BD_ADDR remote_bda, tBTA_ADDR_TYPE remote_addr_type, BOOLEAN is_direct, tBTA_GATT_TRANSPORT transport) { tBTA_GATTC_API_OPEN *p_buf; @@ -152,6 +153,7 @@ void BTA_GATTC_Open(tBTA_GATTC_IF client_if, BD_ADDR remote_bda, p_buf->client_if = client_if; p_buf->is_direct = is_direct; p_buf->transport = transport; + p_buf->remote_addr_type = remote_addr_type; memcpy(p_buf->remote_bda, remote_bda, BD_ADDR_LEN); diff --git a/components/bt/bluedroid/bta/gatt/bta_gatts_act.c b/components/bt/bluedroid/bta/gatt/bta_gatts_act.c index 6bf6a89377..923803b83c 100644 --- a/components/bt/bluedroid/bta/gatt/bta_gatts_act.c +++ b/components/bt/bluedroid/bta/gatt/bta_gatts_act.c @@ -729,7 +729,7 @@ void bta_gatts_open (tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA *p_msg) if ((p_rcb = bta_gatts_find_app_rcb_by_app_if(p_msg->api_open.server_if)) != NULL) { /* should always get the connection ID */ - if (GATT_Connect(p_rcb->gatt_if, p_msg->api_open.remote_bda, + if (GATT_Connect(p_rcb->gatt_if, p_msg->api_open.remote_bda, BLE_ADDR_UNKNOWN_TYPE, p_msg->api_open.is_direct, p_msg->api_open.transport)) { status = BTA_GATT_OK; diff --git a/components/bt/bluedroid/bta/hh/bta_hh_le.c b/components/bt/bluedroid/bta/hh/bta_hh_le.c index a7737a467c..e933771534 100644 --- a/components/bt/bluedroid/bta/hh/bta_hh_le.c +++ b/components/bt/bluedroid/bta/hh/bta_hh_le.c @@ -334,7 +334,7 @@ void bta_hh_le_open_conn(tBTA_HH_DEV_CB *p_cb, BD_ADDR remote_bda) bta_hh_cb.le_cb_index[BTA_HH_GET_LE_CB_IDX(p_cb->hid_handle)] = p_cb->index; p_cb->in_use = TRUE; - BTA_GATTC_Open(bta_hh_cb.gatt_if, remote_bda, TRUE, BTA_GATT_TRANSPORT_LE); + BTA_GATTC_Open(bta_hh_cb.gatt_if, remote_bda, BLE_ADDR_UNKNOWN_TYPE, TRUE, BTA_GATT_TRANSPORT_LE); } /******************************************************************************* @@ -2600,7 +2600,7 @@ static void bta_hh_le_add_dev_bg_conn(tBTA_HH_DEV_CB *p_cb, BOOLEAN check_bond) if (/*p_cb->dscp_info.flag & BTA_HH_LE_NORMAL_CONN &&*/ !p_cb->in_bg_conn && to_add) { /* add device into BG connection to accept remote initiated connection */ - BTA_GATTC_Open(bta_hh_cb.gatt_if, p_cb->addr, FALSE, BTA_GATT_TRANSPORT_LE); + BTA_GATTC_Open(bta_hh_cb.gatt_if, p_cb->addr, BLE_ADDR_UNKNOWN_TYPE, FALSE, BTA_GATT_TRANSPORT_LE); p_cb->in_bg_conn = TRUE; BTA_DmBleSetBgConnType(BTA_DM_BLE_CONN_AUTO, NULL); diff --git a/components/bt/bluedroid/bta/include/bta_gatt_api.h b/components/bt/bluedroid/bta/include/bta_gatt_api.h index 95f6815216..91d4bc917f 100644 --- a/components/bt/bluedroid/bta/include/bta_gatt_api.h +++ b/components/bt/bluedroid/bta/include/bta_gatt_api.h @@ -188,6 +188,8 @@ typedef UINT8 tBTA_GATTC_EVT; typedef tGATT_IF tBTA_GATTC_IF; +typedef UINT8 tBTA_ADDR_TYPE; + typedef struct { UINT16 unit; /* as UUIUD defined by SIG */ UINT16 descr; /* as UUID as defined by SIG */ @@ -737,13 +739,14 @@ extern void BTA_GATTC_AppDeregister (tBTA_GATTC_IF client_if); ** ** Parameters client_if: server interface. ** remote_bda: remote device BD address. +** remote_addr_type: remote device BD address type. ** is_direct: direct connection or background auto connection ** ** Returns void ** *******************************************************************************/ -extern void BTA_GATTC_Open(tBTA_GATTC_IF client_if, BD_ADDR remote_bda, - BOOLEAN is_direct, tBTA_GATT_TRANSPORT transport); +extern void BTA_GATTC_Open(tBTA_GATTC_IF client_if, BD_ADDR remote_bda, tBTA_ADDR_TYPE remote_addr_type, + BOOLEAN is_direct, tBTA_GATT_TRANSPORT transport); /******************************************************************************* ** diff --git a/components/bt/bluedroid/bta/include/bta_gattc_int.h b/components/bt/bluedroid/bta/include/bta_gattc_int.h index 4996b8feb0..8ce7187169 100644 --- a/components/bt/bluedroid/bta/include/bta_gattc_int.h +++ b/components/bt/bluedroid/bta/include/bta_gattc_int.h @@ -116,6 +116,7 @@ typedef tBTA_GATTC_INT_START_IF tBTA_GATTC_INT_DEREG; typedef struct { BT_HDR hdr; BD_ADDR remote_bda; + tBTA_ADDR_TYPE remote_addr_type; tBTA_GATTC_IF client_if; BOOLEAN is_direct; tBTA_TRANSPORT transport; diff --git a/components/bt/bluedroid/bta/jv/bta_jv_act.c b/components/bt/bluedroid/bta/jv/bta_jv_act.c index e7f982d8f9..b3fe83ae9e 100644 --- a/components/bt/bluedroid/bta/jv/bta_jv_act.c +++ b/components/bt/bluedroid/bta/jv/bta_jv_act.c @@ -2648,7 +2648,7 @@ void bta_jv_l2cap_connect_le(tBTA_JV_MSG *p_data) id = t->id; t->init_called = FALSE; - if (L2CA_ConnectFixedChnl(t->chan, t->remote_addr)) { + if (L2CA_ConnectFixedChnl(t->chan, t->remote_addr, BLE_ADDR_UNKNOWN_TYPE)) { evt.l2c_cl_init.status = BTA_JV_SUCCESS; evt.l2c_cl_init.handle = id; diff --git a/components/bt/bluedroid/btc/profile/std/gatt/btc_gattc.c b/components/bt/bluedroid/btc/profile/std/gatt/btc_gattc.c index 3a66df1985..1ad27503f3 100644 --- a/components/bt/bluedroid/btc/profile/std/gatt/btc_gattc.c +++ b/components/bt/bluedroid/btc/profile/std/gatt/btc_gattc.c @@ -196,7 +196,7 @@ static void btc_gattc_app_unregister(btc_ble_gattc_args_t *arg) static void btc_gattc_open(btc_ble_gattc_args_t *arg) { tBTA_GATT_TRANSPORT transport = BTA_GATT_TRANSPORT_LE; - BTA_GATTC_Open(arg->open.gattc_if, arg->open.remote_bda, arg->open.is_direct, transport); + BTA_GATTC_Open(arg->open.gattc_if, arg->open.remote_bda, arg->open.remote_addr_type, arg->open.is_direct, transport); } static void btc_gattc_close(btc_ble_gattc_args_t *arg) diff --git a/components/bt/bluedroid/btc/profile/std/include/btc_gattc.h b/components/bt/bluedroid/btc/profile/std/include/btc_gattc.h index 5087e5d233..3391dd1c9f 100644 --- a/components/bt/bluedroid/btc/profile/std/include/btc_gattc.h +++ b/components/bt/bluedroid/btc/profile/std/include/btc_gattc.h @@ -54,6 +54,7 @@ typedef union { struct open_arg { esp_gatt_if_t gattc_if; esp_bd_addr_t remote_bda; + esp_ble_addr_type_t remote_addr_type; bool is_direct; } open; //BTC_GATTC_ACT_CLOSE, diff --git a/components/bt/bluedroid/stack/btm/btm_ble.c b/components/bt/bluedroid/stack/btm/btm_ble.c index 79b93aaeda..3f0db6062e 100644 --- a/components/bt/bluedroid/stack/btm/btm_ble.c +++ b/components/bt/bluedroid/stack/btm/btm_ble.c @@ -605,18 +605,23 @@ void BTM_ReadDevInfo (BD_ADDR remote_bda, tBT_DEVICE_TYPE *p_dev_type, tBLE_ADDR { tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev (remote_bda); tBTM_INQ_INFO *p_inq_info = BTM_InqDbRead(remote_bda); + tBLE_ADDR_TYPE temp_addr_type = (*p_addr_type); *p_addr_type = BLE_ADDR_PUBLIC; - if (!p_dev_rec) { + if (!p_dev_rec) { *p_dev_type = BT_DEVICE_TYPE_BREDR; /* Check with the BT manager if details about remote device are known */ if (p_inq_info != NULL) { *p_dev_type = p_inq_info->results.device_type ; *p_addr_type = p_inq_info->results.ble_addr_type; } else { - /* unknown device, assume BR/EDR */ - BTM_TRACE_DEBUG ("btm_find_dev_type - unknown device, BR/EDR assumed"); + if(temp_addr_type <= BLE_ADDR_TYPE_MAX) { + *p_addr_type = temp_addr_type; + } else { + /* unknown device, assume BR/EDR */ + BTM_TRACE_DEBUG ("btm_find_dev_type - unknown device, BR/EDR assumed"); + } } } else { /* there is a security device record exisitng */ /* new inquiry result, overwrite device type in security device record */ diff --git a/components/bt/bluedroid/stack/btm/btm_ble_bgconn.c b/components/bt/bluedroid/stack/btm/btm_ble_bgconn.c index 5ee344efe4..828d5dd439 100644 --- a/components/bt/bluedroid/stack/btm/btm_ble_bgconn.c +++ b/components/bt/bluedroid/stack/btm/btm_ble_bgconn.c @@ -571,7 +571,7 @@ void btm_ble_initiate_select_conn(BD_ADDR bda) BTM_TRACE_EVENT ("btm_ble_initiate_select_conn"); /* use direct connection procedure to initiate connection */ - if (!L2CA_ConnectFixedChnl(L2CAP_ATT_CID, bda)) { + if (!L2CA_ConnectFixedChnl(L2CAP_ATT_CID, bda, BLE_ADDR_UNKNOWN_TYPE)) { BTM_TRACE_ERROR("btm_ble_initiate_select_conn failed"); } } diff --git a/components/bt/bluedroid/stack/gap/gap_ble.c b/components/bt/bluedroid/stack/gap/gap_ble.c index 58012633a6..76dfa13e67 100644 --- a/components/bt/bluedroid/stack/gap/gap_ble.c +++ b/components/bt/bluedroid/stack/gap/gap_ble.c @@ -694,7 +694,7 @@ BOOLEAN gap_ble_accept_cl_operation(BD_ADDR peer_bda, UINT16 uuid, tGAP_BLE_CMPL } /* hold the link here */ - if (!GATT_Connect(gap_cb.gatt_if, p_clcb->bda, TRUE, BT_TRANSPORT_LE)) { + if (!GATT_Connect(gap_cb.gatt_if, p_clcb->bda, BLE_ADDR_UNKNOWN_TYPE, TRUE, BT_TRANSPORT_LE)) { return started; } diff --git a/components/bt/bluedroid/stack/gatt/gatt_api.c b/components/bt/bluedroid/stack/gatt/gatt_api.c index 44b8527f9b..1267c0b76a 100644 --- a/components/bt/bluedroid/stack/gatt/gatt_api.c +++ b/components/bt/bluedroid/stack/gatt/gatt_api.c @@ -1337,12 +1337,13 @@ void GATT_StartIf (tGATT_IF gatt_if) ** ** Parameters gatt_if: applicaiton interface ** bd_addr: peer device address. +** bd_addr_type: peer device address type. ** is_direct: is a direct conenection or a background auto connection ** ** Returns TRUE if connection started; FALSE if connection start failure. ** *******************************************************************************/ -BOOLEAN GATT_Connect (tGATT_IF gatt_if, BD_ADDR bd_addr, BOOLEAN is_direct, tBT_TRANSPORT transport) +BOOLEAN GATT_Connect (tGATT_IF gatt_if, BD_ADDR bd_addr, tBLE_ADDR_TYPE bd_addr_type, BOOLEAN is_direct, tBT_TRANSPORT transport) { tGATT_REG *p_reg; BOOLEAN status = FALSE; @@ -1356,7 +1357,7 @@ BOOLEAN GATT_Connect (tGATT_IF gatt_if, BD_ADDR bd_addr, BOOLEAN is_direct, tBT_ } if (is_direct) { - status = gatt_act_connect (p_reg, bd_addr, transport); + status = gatt_act_connect (p_reg, bd_addr, bd_addr_type, transport); } else { if (transport == BT_TRANSPORT_LE) { status = gatt_update_auto_connect_dev(gatt_if, TRUE, bd_addr, TRUE); diff --git a/components/bt/bluedroid/stack/gatt/gatt_attr.c b/components/bt/bluedroid/stack/gatt/gatt_attr.c index 47aec9d2d4..eb1cb8b900 100644 --- a/components/bt/bluedroid/stack/gatt/gatt_attr.c +++ b/components/bt/bluedroid/stack/gatt/gatt_attr.c @@ -494,7 +494,7 @@ void GATT_ConfigServiceChangeCCC (BD_ADDR remote_bda, BOOLEAN enable, tBT_TRANSP p_clcb->connected = TRUE; } /* hold the link here */ - GATT_Connect(gatt_cb.gatt_if, remote_bda, TRUE, transport); + GATT_Connect(gatt_cb.gatt_if, remote_bda, BLE_ADDR_UNKNOWN_TYPE, TRUE, transport); p_clcb->ccc_stage = GATT_SVC_CHANGED_CONNECTING; if (!p_clcb->connected) { diff --git a/components/bt/bluedroid/stack/gatt/gatt_main.c b/components/bt/bluedroid/stack/gatt/gatt_main.c index 7ceb67ddc0..b7486a9ec7 100644 --- a/components/bt/bluedroid/stack/gatt/gatt_main.c +++ b/components/bt/bluedroid/stack/gatt/gatt_main.c @@ -204,11 +204,11 @@ void gatt_free(void) ** Description This function is called to initiate a connection to a peer device. ** ** Parameter rem_bda: remote device address to connect to. -** +** bd_addr_type: emote device address type. ** Returns TRUE if connection is started, otherwise return FALSE. ** *******************************************************************************/ -BOOLEAN gatt_connect (BD_ADDR rem_bda, tGATT_TCB *p_tcb, tBT_TRANSPORT transport) +BOOLEAN gatt_connect (BD_ADDR rem_bda, tBLE_ADDR_TYPE bd_addr_type, tGATT_TCB *p_tcb, tBT_TRANSPORT transport) { BOOLEAN gatt_ret = FALSE; @@ -218,7 +218,7 @@ BOOLEAN gatt_connect (BD_ADDR rem_bda, tGATT_TCB *p_tcb, tBT_TRANSPORT transport if (transport == BT_TRANSPORT_LE) { p_tcb->att_lcid = L2CAP_ATT_CID; - gatt_ret = L2CA_ConnectFixedChnl (L2CAP_ATT_CID, rem_bda); + gatt_ret = L2CA_ConnectFixedChnl (L2CAP_ATT_CID, rem_bda, bd_addr_type); #if (CLASSIC_BT_INCLUDED == TRUE) } else { if ((p_tcb->att_lcid = L2CA_ConnectReq(BT_PSM_ATT, rem_bda)) != 0) { @@ -363,7 +363,7 @@ void gatt_update_app_use_link_flag (tGATT_IF gatt_if, tGATT_TCB *p_tcb, BOOLEAN ** Returns void. ** *******************************************************************************/ -BOOLEAN gatt_act_connect (tGATT_REG *p_reg, BD_ADDR bd_addr, tBT_TRANSPORT transport) +BOOLEAN gatt_act_connect (tGATT_REG *p_reg, BD_ADDR bd_addr, tBLE_ADDR_TYPE bd_addr_type, tBT_TRANSPORT transport) { BOOLEAN ret = FALSE; tGATT_TCB *p_tcb; @@ -376,7 +376,7 @@ BOOLEAN gatt_act_connect (tGATT_REG *p_reg, BD_ADDR bd_addr, tBT_TRANSPORT trans /* before link down, another app try to open a GATT connection */ if (st == GATT_CH_OPEN && gatt_num_apps_hold_link(p_tcb) == 0 && transport == BT_TRANSPORT_LE ) { - if (!gatt_connect(bd_addr, p_tcb, transport)) { + if (!gatt_connect(bd_addr, bd_addr_type, p_tcb, transport)) { ret = FALSE; } } else if (st == GATT_CH_CLOSING) { @@ -385,7 +385,7 @@ BOOLEAN gatt_act_connect (tGATT_REG *p_reg, BD_ADDR bd_addr, tBT_TRANSPORT trans } } else { if ((p_tcb = gatt_allocate_tcb_by_bdaddr(bd_addr, transport)) != NULL) { - if (!gatt_connect(bd_addr, p_tcb, transport)) { + if (!gatt_connect(bd_addr, bd_addr_type, p_tcb, transport)) { GATT_TRACE_ERROR("gatt_connect failed"); fixed_queue_free(p_tcb->pending_enc_clcb, NULL); fixed_queue_free(p_tcb->pending_ind_q, NULL); diff --git a/components/bt/bluedroid/stack/gatt/include/gatt_int.h b/components/bt/bluedroid/stack/gatt/include/gatt_int.h index 4f236f28cc..6aaa42aa0a 100644 --- a/components/bt/bluedroid/stack/gatt/include/gatt_int.h +++ b/components/bt/bluedroid/stack/gatt/include/gatt_int.h @@ -572,8 +572,8 @@ extern void gatt_free(void); /* from gatt_main.c */ extern BOOLEAN gatt_disconnect (tGATT_TCB *p_tcb); -extern BOOLEAN gatt_act_connect (tGATT_REG *p_reg, BD_ADDR bd_addr, tBT_TRANSPORT transport); -extern BOOLEAN gatt_connect (BD_ADDR rem_bda, tGATT_TCB *p_tcb, tBT_TRANSPORT transport); +extern BOOLEAN gatt_act_connect (tGATT_REG *p_reg, BD_ADDR bd_addr, tBLE_ADDR_TYPE bd_addr_type, tBT_TRANSPORT transport); +extern BOOLEAN gatt_connect (BD_ADDR rem_bda, tBLE_ADDR_TYPE bd_addr_type, tGATT_TCB *p_tcb, tBT_TRANSPORT transport); extern void gatt_data_process (tGATT_TCB *p_tcb, BT_HDR *p_buf); extern void gatt_update_app_use_link_flag ( tGATT_IF gatt_if, tGATT_TCB *p_tcb, BOOLEAN is_add, BOOLEAN check_acl_link); diff --git a/components/bt/bluedroid/stack/include/bt_types.h b/components/bt/bluedroid/stack/include/bt_types.h index 1f3f60d8ca..ec44cb8719 100644 --- a/components/bt/bluedroid/stack/include/bt_types.h +++ b/components/bt/bluedroid/stack/include/bt_types.h @@ -499,6 +499,8 @@ typedef struct { #define BLE_ADDR_RANDOM 0x01 #define BLE_ADDR_PUBLIC_ID 0x02 #define BLE_ADDR_RANDOM_ID 0x03 +#define BLE_ADDR_TYPE_MAX BLE_ADDR_RANDOM_ID +#define BLE_ADDR_UNKNOWN_TYPE 0XFF typedef UINT8 tBLE_ADDR_TYPE; #define BLE_ADDR_TYPE_MASK (BLE_ADDR_RANDOM | BLE_ADDR_PUBLIC) diff --git a/components/bt/bluedroid/stack/include/gatt_api.h b/components/bt/bluedroid/stack/include/gatt_api.h index 946e5fee47..7307f53c82 100644 --- a/components/bt/bluedroid/stack/include/gatt_api.h +++ b/components/bt/bluedroid/stack/include/gatt_api.h @@ -1097,13 +1097,14 @@ extern void GATT_StartIf (tGATT_IF gatt_if); ** ** Parameters gatt_if: applicaiton interface ** bd_addr: peer device address. +** bd_addr_type: peer device address type. ** is_direct: is a direct conenection or a background auto connection ** transport : Physical transport for GATT connection (BR/EDR or LE) ** ** Returns TRUE if connection started; FALSE if connection start failure. ** *******************************************************************************/ -extern BOOLEAN GATT_Connect (tGATT_IF gatt_if, BD_ADDR bd_addr, +extern BOOLEAN GATT_Connect (tGATT_IF gatt_if, BD_ADDR bd_addr, tBLE_ADDR_TYPE bd_addr_type, BOOLEAN is_direct, tBT_TRANSPORT transport); diff --git a/components/bt/bluedroid/stack/include/l2c_api.h b/components/bt/bluedroid/stack/include/l2c_api.h index e2faae4175..71e1f48168 100644 --- a/components/bt/bluedroid/stack/include/l2c_api.h +++ b/components/bt/bluedroid/stack/include/l2c_api.h @@ -1079,11 +1079,12 @@ extern BOOLEAN L2CA_RegisterFixedChannel (UINT16 fixed_cid, tL2CAP_FIXED_CHNL_R ** ** Parameters: Fixed CID ** BD Address of remote +** BD Address type ** ** Return value: TRUE if connection started ** *******************************************************************************/ -extern BOOLEAN L2CA_ConnectFixedChnl (UINT16 fixed_cid, BD_ADDR bd_addr); +extern BOOLEAN L2CA_ConnectFixedChnl (UINT16 fixed_cid, BD_ADDR bd_addr, tBLE_ADDR_TYPE bd_addr_type); /******************************************************************************* ** diff --git a/components/bt/bluedroid/stack/l2cap/include/l2c_int.h b/components/bt/bluedroid/stack/l2cap/include/l2c_int.h index e65b328cf0..2728261f30 100644 --- a/components/bt/bluedroid/stack/l2cap/include/l2c_int.h +++ b/components/bt/bluedroid/stack/l2cap/include/l2c_int.h @@ -422,6 +422,7 @@ typedef struct t_l2c_linkcb { tBT_TRANSPORT transport; #if (BLE_INCLUDED == TRUE) + tBLE_ADDR_TYPE open_addr_type; /* be set by open API */ tBLE_ADDR_TYPE ble_addr_type; UINT16 tx_data_len; /* tx data length used in data length extension */ fixed_queue_t *le_sec_pending_q; /* LE coc channels waiting for security check completion */ diff --git a/components/bt/bluedroid/stack/l2cap/l2c_api.c b/components/bt/bluedroid/stack/l2cap/l2c_api.c index 280a2c6876..4c2173e14c 100644 --- a/components/bt/bluedroid/stack/l2cap/l2c_api.c +++ b/components/bt/bluedroid/stack/l2cap/l2c_api.c @@ -1631,11 +1631,12 @@ BOOLEAN L2CA_RegisterFixedChannel (UINT16 fixed_cid, tL2CAP_FIXED_CHNL_REG *p_f ** ** Parameters: Fixed CID ** BD Address of remote +** BD Address type ** ** Return value: TRUE if connection started ** *******************************************************************************/ -BOOLEAN L2CA_ConnectFixedChnl (UINT16 fixed_cid, BD_ADDR rem_bda) +BOOLEAN L2CA_ConnectFixedChnl (UINT16 fixed_cid, BD_ADDR rem_bda, tBLE_ADDR_TYPE bd_addr_type) { tL2C_LCB *p_lcb; tBT_TRANSPORT transport = BT_TRANSPORT_BR_EDR; @@ -1723,7 +1724,9 @@ BOOLEAN L2CA_ConnectFixedChnl (UINT16 fixed_cid, BD_ADDR rem_bda) l2cu_release_lcb (p_lcb); return FALSE; } - +#if (BLE_INCLUDED == TRUE) + p_lcb->open_addr_type = bd_addr_type; +#endif if (!l2cu_create_conn(p_lcb, transport)) { L2CAP_TRACE_WARNING ("%s() - create_conn failed", __func__); l2cu_release_lcb (p_lcb); diff --git a/components/bt/bluedroid/stack/l2cap/l2c_utils.c b/components/bt/bluedroid/stack/l2cap/l2c_utils.c index 119b1f8e60..816deffcc6 100644 --- a/components/bt/bluedroid/stack/l2cap/l2c_utils.c +++ b/components/bt/bluedroid/stack/l2cap/l2c_utils.c @@ -2202,9 +2202,7 @@ BOOLEAN l2cu_create_conn (tL2C_LCB *p_lcb, tBT_TRANSPORT transport) #if (BLE_INCLUDED == TRUE) tBT_DEVICE_TYPE dev_type; - tBLE_ADDR_TYPE addr_type; - - + tBLE_ADDR_TYPE addr_type = p_lcb->open_addr_type; BTM_ReadDevInfo(p_lcb->remote_bd_addr, &dev_type, &addr_type); if (transport == BT_TRANSPORT_LE) { diff --git a/components/bt/bluedroid/stack/smp/smp_api.c b/components/bt/bluedroid/stack/smp/smp_api.c index 54f676a719..fe90034c7d 100644 --- a/components/bt/bluedroid/stack/smp/smp_api.c +++ b/components/bt/bluedroid/stack/smp/smp_api.c @@ -155,7 +155,7 @@ tSMP_STATUS SMP_Pair (BD_ADDR bd_addr) memcpy (p_cb->pairing_bda, bd_addr, BD_ADDR_LEN); - if (!L2CA_ConnectFixedChnl (L2CAP_SMP_CID, bd_addr)) { + if (!L2CA_ConnectFixedChnl (L2CAP_SMP_CID, bd_addr, BLE_ADDR_UNKNOWN_TYPE)) { SMP_TRACE_ERROR("%s: L2C connect fixed channel failed.\n", __FUNCTION__); smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &status); return status; @@ -198,7 +198,7 @@ tSMP_STATUS SMP_BR_PairWith (BD_ADDR bd_addr) memcpy (p_cb->pairing_bda, bd_addr, BD_ADDR_LEN); - if (!L2CA_ConnectFixedChnl (L2CAP_SMP_BR_CID, bd_addr)) { + if (!L2CA_ConnectFixedChnl (L2CAP_SMP_BR_CID, bd_addr, BLE_ADDR_UNKNOWN_TYPE)) { SMP_TRACE_ERROR("%s: L2C connect fixed channel failed.", __FUNCTION__); smp_br_state_machine_event(p_cb, SMP_BR_AUTH_CMPL_EVT, &status); return status; diff --git a/examples/bluetooth/ble_spp_client/main/spp_client_demo.c b/examples/bluetooth/ble_spp_client/main/spp_client_demo.c index fe8485ef48..b1838c4ced 100644 --- a/examples/bluetooth/ble_spp_client/main/spp_client_demo.c +++ b/examples/bluetooth/ble_spp_client/main/spp_client_demo.c @@ -235,7 +235,7 @@ static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *par ESP_LOGI(GATTC_TAG, "Scan stop successed"); if (is_connect == false) { ESP_LOGI(GATTC_TAG, "Connect to the remote device."); - esp_ble_gattc_open(gl_profile_tab[PROFILE_APP_ID].gattc_if, scan_rst.scan_rst.bda, true); + esp_ble_gattc_open(gl_profile_tab[PROFILE_APP_ID].gattc_if, scan_rst.scan_rst.bda, scan_rst.scan_rst.ble_addr_type, true); } break; case ESP_GAP_BLE_SCAN_RESULT_EVT: { diff --git a/examples/bluetooth/gatt_client/main/gattc_demo.c b/examples/bluetooth/gatt_client/main/gattc_demo.c index 5d74c63bb5..a2f8899f4f 100644 --- a/examples/bluetooth/gatt_client/main/gattc_demo.c +++ b/examples/bluetooth/gatt_client/main/gattc_demo.c @@ -338,7 +338,7 @@ static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *par connect = true; ESP_LOGI(GATTC_TAG, "connect to the remote device."); esp_ble_gap_stop_scanning(); - esp_ble_gattc_open(gl_profile_tab[PROFILE_A_APP_ID].gattc_if, scan_result->scan_rst.bda, true); + esp_ble_gattc_open(gl_profile_tab[PROFILE_A_APP_ID].gattc_if, scan_result->scan_rst.bda, scan_result->scan_rst.ble_addr_type, true); } } } diff --git a/examples/bluetooth/gatt_client/tutorial/Gatt_Client_Example_Walkthrough.md b/examples/bluetooth/gatt_client/tutorial/Gatt_Client_Example_Walkthrough.md index 0ec4e4e046..49725751d1 100644 --- a/examples/bluetooth/gatt_client/tutorial/Gatt_Client_Example_Walkthrough.md +++ b/examples/bluetooth/gatt_client/tutorial/Gatt_Client_Example_Walkthrough.md @@ -370,7 +370,7 @@ We are interested in the `ESP_GAP_SEARCH_INQ_RES_EVT` event, which is called eve connect = true; ESP_LOGI(GATTC_TAG, "connect to the remote device."); esp_ble_gap_stop_scanning(); - esp_ble_gattc_open(gl_profile_tab[PROFILE_A_APP_ID].gattc_if, scan_result->scan_rst.bda, true); + esp_ble_gattc_open(gl_profile_tab[PROFILE_A_APP_ID].gattc_if, scan_result->scan_rst.bda, scan_result->scan_rst.ble_addr_type, true); } } } diff --git a/examples/bluetooth/gatt_security_client/main/example_ble_sec_gattc_demo.c b/examples/bluetooth/gatt_security_client/main/example_ble_sec_gattc_demo.c index 32e660bb3e..dcc8585e74 100644 --- a/examples/bluetooth/gatt_security_client/main/example_ble_sec_gattc_demo.c +++ b/examples/bluetooth/gatt_security_client/main/example_ble_sec_gattc_demo.c @@ -395,7 +395,7 @@ static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *par connect = true; ESP_LOGI(GATTC_TAG, "connect to the remote device."); esp_ble_gap_stop_scanning(); - esp_ble_gattc_open(gl_profile_tab[PROFILE_A_APP_ID].gattc_if, scan_result->scan_rst.bda, true); + esp_ble_gattc_open(gl_profile_tab[PROFILE_A_APP_ID].gattc_if, scan_result->scan_rst.bda, scan_result->scan_rst.ble_addr_type, true); } } } diff --git a/examples/bluetooth/gattc_multi_connect/main/gattc_multi_connect.c b/examples/bluetooth/gattc_multi_connect/main/gattc_multi_connect.c index d6c6e089d6..2eca1a8f1c 100644 --- a/examples/bluetooth/gattc_multi_connect/main/gattc_multi_connect.c +++ b/examples/bluetooth/gattc_multi_connect/main/gattc_multi_connect.c @@ -792,7 +792,7 @@ static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *par conn_device_a = true; ESP_LOGI(GATTC_TAG, "Searched device %s", remote_device_name[0]); esp_ble_gap_stop_scanning(); - esp_ble_gattc_open(gl_profile_tab[PROFILE_A_APP_ID].gattc_if, scan_result->scan_rst.bda, true); + esp_ble_gattc_open(gl_profile_tab[PROFILE_A_APP_ID].gattc_if, scan_result->scan_rst.bda, scan_result->scan_rst.ble_addr_type, true); Isconnecting = true; } break; @@ -802,7 +802,7 @@ static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *par conn_device_b = true; ESP_LOGI(GATTC_TAG, "Searched device %s", remote_device_name[1]); esp_ble_gap_stop_scanning(); - esp_ble_gattc_open(gl_profile_tab[PROFILE_B_APP_ID].gattc_if, scan_result->scan_rst.bda, true); + esp_ble_gattc_open(gl_profile_tab[PROFILE_B_APP_ID].gattc_if, scan_result->scan_rst.bda, scan_result->scan_rst.ble_addr_type, true); Isconnecting = true; } @@ -812,7 +812,7 @@ static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *par conn_device_c = true; ESP_LOGI(GATTC_TAG, "Searched device %s", remote_device_name[2]); esp_ble_gap_stop_scanning(); - esp_ble_gattc_open(gl_profile_tab[PROFILE_C_APP_ID].gattc_if, scan_result->scan_rst.bda, true); + esp_ble_gattc_open(gl_profile_tab[PROFILE_C_APP_ID].gattc_if, scan_result->scan_rst.bda, scan_result->scan_rst.ble_addr_type, true); Isconnecting = true; } break;