#include <base/callback.h>
#include "bt_common.h"
#include "bt_target.h"
+#include "bta_closure_api.h"
#include "bta_gattc_int.h"
#include "bta_sys.h"
#include "btif/include/btif_debug_conn.h"
}
}
-/*******************************************************************************
- *
- * Function bta_gattc_register
- *
- * Description Register a GATT client application with BTA.
- *
- * Returns void
- *
- ******************************************************************************/
+/** start an application interface */
+void bta_gattc_start_if(uint8_t client_if) {
+ if (!bta_gattc_cl_get_regcb(client_if)) {
+ APPL_TRACE_ERROR("Unable to start app.: Unknown interface =%d", client_if);
+ return;
+ }
+
+ GATT_StartIf(client_if);
+}
+
+/** Register a GATT client application with BTA */
void bta_gattc_register(tBT_UUID* p_app_uuid, tBTA_GATTC_CBACK* p_cback,
BtaAppRegisterCallback cb) {
tBTA_GATT_STATUS status = BTA_GATT_NO_RESOURCES;
/* BTA use the same client interface as BTE GATT statck */
client_if = bta_gattc_cb.cl_rcb[i].client_if;
- tBTA_GATTC_INT_START_IF* p_buf = (tBTA_GATTC_INT_START_IF*)osi_malloc(
- sizeof(tBTA_GATTC_INT_START_IF));
- p_buf->hdr.event = BTA_GATTC_INT_START_IF_EVT;
- p_buf->client_if = bta_gattc_cb.cl_rcb[i].client_if;
+ do_in_bta_thread(FROM_HERE, base::Bind(&bta_gattc_start_if, client_if));
- bta_sys_sendmsg(p_buf);
status = BTA_GATT_OK;
break;
}
if (!cb.is_null()) cb.Run(client_if, status);
}
-/*******************************************************************************
- *
- * Function bta_gattc_start_if
- *
- * Description start an application interface.
- *
- * Returns none.
- *
- ******************************************************************************/
-void bta_gattc_start_if(tBTA_GATTC_DATA* p_msg) {
- if (bta_gattc_cl_get_regcb(p_msg->int_start_if.client_if) != NULL) {
- GATT_StartIf(p_msg->int_start_if.client_if);
- } else {
- APPL_TRACE_ERROR("Unable to start app.: Unknown interface =%d",
- p_msg->int_start_if.client_if);
- }
-}
+
/*******************************************************************************
*
* Function bta_gattc_deregister
}
}
-/*******************************************************************************
- *
- * Function bta_gattc_process_enc_cmpl
- *
- * Description process encryption complete message.
- *
- * Returns void
- *
- ******************************************************************************/
-void bta_gattc_process_enc_cmpl(tBTA_GATTC_DATA* p_msg) {
+/** process encryption complete message */
+void bta_gattc_process_enc_cmpl(tGATT_IF client_if, bt_bdaddr_t bda) {
tBTA_GATTC_RCB* p_clreg;
tBTA_GATTC cb_data;
- p_clreg = bta_gattc_cl_get_regcb(p_msg->enc_cmpl.client_if);
+ p_clreg = bta_gattc_cl_get_regcb(client_if);
if (p_clreg && p_clreg->p_cback) {
memset(&cb_data, 0, sizeof(tBTA_GATTC));
- cb_data.enc_cmpl.client_if = p_msg->enc_cmpl.client_if;
- bdcpy(cb_data.enc_cmpl.remote_bda, p_msg->enc_cmpl.remote_bda);
+ cb_data.enc_cmpl.client_if = client_if;
+ memcpy(cb_data.enc_cmpl.remote_bda, bda.address, BD_ADDR_LEN);
(*p_clreg->p_cback)(BTA_GATTC_ENC_CMPL_CB_EVT, &cb_data);
}
APPL_TRACE_DEBUG("%s: cif = %d", __func__, gattc_if);
- tBTA_GATTC_DATA* p_buf =
- (tBTA_GATTC_DATA*)osi_calloc(sizeof(tBTA_GATTC_DATA));
- p_buf->enc_cmpl.hdr.event = BTA_GATTC_ENC_CMPL_EVT;
- p_buf->enc_cmpl.hdr.layer_specific = p_clcb->bta_conn_id;
- p_buf->enc_cmpl.client_if = gattc_if;
- bdcpy(p_buf->enc_cmpl.remote_bda, bda);
-
- bta_sys_sendmsg(p_buf);
+ bt_bdaddr_t addr;
+ memcpy(addr.address, bda, BD_ADDR_LEN);
+ do_in_bta_thread(FROM_HERE,
+ base::Bind(&bta_gattc_process_enc_cmpl, gattc_if, addr));
}
/*******************************************************************************
return;
}
- BT_HDR* p_buf = (BT_HDR*)osi_malloc(sizeof(BT_HDR));
- p_buf->event = BTA_GATTC_API_DISABLE_EVT;
-
- bta_sys_sendmsg(p_buf);
+ do_in_bta_thread(FROM_HERE, base::Bind(&bta_gattc_disable));
bta_sys_deregister(BTA_ID_GATTC);
}
p_client_cb, std::move(cb)));
}
+static void app_deregister_impl(tBTA_GATTC_IF client_if) {
+ bta_gattc_deregister(bta_gattc_cl_get_regcb(client_if));
+}
/*******************************************************************************
*
* Function BTA_GATTC_AppDeregister
*
******************************************************************************/
void BTA_GATTC_AppDeregister(tBTA_GATTC_IF client_if) {
- tBTA_GATTC_API_DEREG* p_buf =
- (tBTA_GATTC_API_DEREG*)osi_malloc(sizeof(tBTA_GATTC_API_DEREG));
-
- p_buf->hdr.event = BTA_GATTC_API_DEREG_EVT;
- p_buf->client_if = client_if;
-
- bta_sys_sendmsg(p_buf);
+ do_in_bta_thread(FROM_HERE, base::Bind(&app_deregister_impl, client_if));
}
/*******************************************************************************
BTA_GATTC_INT_DISCOVER_EVT,
BTA_GATTC_DISCOVER_CMPL_EVT,
BTA_GATTC_OP_CMPL_EVT,
- BTA_GATTC_INT_DISCONN_EVT,
-
- BTA_GATTC_INT_START_IF_EVT,
- BTA_GATTC_API_DEREG_EVT,
- BTA_GATTC_API_DISABLE_EVT,
- BTA_GATTC_ENC_CMPL_EVT
+ BTA_GATTC_INT_DISCONN_EVT
};
typedef uint16_t tBTA_GATTC_INT_EVT;
/* internal strucutre for GATTC register API */
typedef struct {
BT_HDR hdr;
- tBTA_GATTC_IF client_if;
-} tBTA_GATTC_INT_START_IF;
-
-typedef tBTA_GATTC_INT_START_IF tBTA_GATTC_API_DEREG;
-typedef tBTA_GATTC_INT_START_IF tBTA_GATTC_INT_DEREG;
-
-typedef struct {
- BT_HDR hdr;
BD_ADDR remote_bda;
tBTA_GATTC_IF client_if;
bool is_direct;
tGATT_DISCONN_REASON reason;
} tBTA_GATTC_INT_CONN;
-typedef struct {
- BT_HDR hdr;
- BD_ADDR remote_bda;
- tBTA_GATTC_IF client_if;
-} tBTA_GATTC_ENC_CMPL;
-
typedef union {
BT_HDR hdr;
- tBTA_GATTC_API_DEREG api_dereg;
tBTA_GATTC_API_OPEN api_conn;
tBTA_GATTC_API_CANCEL_OPEN api_cancel_conn;
tBTA_GATTC_API_READ api_read;
tBTA_GATTC_API_CFG_MTU api_mtu;
tBTA_GATTC_OP_CMPL op_cmpl;
tBTA_GATTC_INT_CONN int_conn;
- tBTA_GATTC_ENC_CMPL enc_cmpl;
-
- tBTA_GATTC_INT_START_IF int_start_if;
- tBTA_GATTC_INT_DEREG int_dereg;
-
} tBTA_GATTC_DATA;
/* GATT server cache on the client */
extern void bta_gattc_disable();
extern void bta_gattc_register(tBT_UUID* p_app_uuid, tBTA_GATTC_CBACK* p_data,
BtaAppRegisterCallback cb);
-extern void bta_gattc_start_if(tBTA_GATTC_DATA* p_data);
extern void bta_gattc_process_api_open(tBTA_GATTC_DATA* p_msg);
extern void bta_gattc_process_api_open_cancel(tBTA_GATTC_DATA* p_msg);
extern void bta_gattc_deregister(tBTA_GATTC_RCB* p_clreg);
-extern void bta_gattc_process_enc_cmpl(tBTA_GATTC_DATA* p_msg);
/* function within state machine */
extern void bta_gattc_open(tBTA_GATTC_CLCB* p_clcb, tBTA_GATTC_DATA* p_data);
******************************************************************************/
bool bta_gattc_hdl_event(BT_HDR* p_msg) {
tBTA_GATTC_CLCB* p_clcb = NULL;
- tBTA_GATTC_RCB* p_clreg;
bool rt = true;
#if (BTA_GATT_DEBUG == TRUE)
APPL_TRACE_DEBUG("bta_gattc_hdl_event: Event [%s]",
gattc_evt_code(p_msg->event));
#endif
switch (p_msg->event) {
- case BTA_GATTC_API_DISABLE_EVT:
- bta_gattc_disable();
- break;
-
- case BTA_GATTC_INT_START_IF_EVT:
- bta_gattc_start_if((tBTA_GATTC_DATA*)p_msg);
- break;
-
- case BTA_GATTC_API_DEREG_EVT:
- p_clreg = bta_gattc_cl_get_regcb(
- ((tBTA_GATTC_DATA*)p_msg)->api_dereg.client_if);
- bta_gattc_deregister(p_clreg);
- break;
case BTA_GATTC_API_OPEN_EVT:
bta_gattc_process_api_open((tBTA_GATTC_DATA*)p_msg);
bta_gattc_process_api_refresh((tBTA_GATTC_DATA*)p_msg);
break;
- case BTA_GATTC_ENC_CMPL_EVT:
- bta_gattc_process_enc_cmpl((tBTA_GATTC_DATA*)p_msg);
- break;
-
default:
if (p_msg->event == BTA_GATTC_INT_CONN_EVT)
p_clcb = bta_gattc_find_int_conn_clcb((tBTA_GATTC_DATA*)p_msg);
return "BTA_GATTC_OP_CMPL_EVT";
case BTA_GATTC_INT_DISCONN_EVT:
return "BTA_GATTC_INT_DISCONN_EVT";
- case BTA_GATTC_INT_START_IF_EVT:
- return "BTA_GATTC_INT_START_IF_EVT";
- case BTA_GATTC_API_DEREG_EVT:
- return "BTA_GATTC_API_DEREG_EVT";
case BTA_GATTC_API_REFRESH_EVT:
return "BTA_GATTC_API_REFRESH_EVT";
- case BTA_GATTC_API_DISABLE_EVT:
- return "BTA_GATTC_API_DISABLE_EVT";
case BTA_GATTC_API_CFG_MTU_EVT:
return "BTA_GATTC_API_CFG_MTU_EVT";
default: