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;
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);
*
* @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
* - 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);
/**
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) */
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");
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",
**
** 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;
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);
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;
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);
}
/*******************************************************************************
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);
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 */
**
** 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);
/*******************************************************************************
**
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;
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;
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)
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,
{
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 */
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");
}
}
}
/* 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;
}
**
** 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;
}
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);
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) {
** 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;
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) {
** 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;
/* 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) {
}
} 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);
/* 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);
#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)
**
** 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);
**
** 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);
/*******************************************************************************
**
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 */
**
** 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;
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);
#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) {
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;
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;
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: {
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);
}
}
}
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);
}
}
}
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);
}
}
}
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;
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;
}
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;