From: Grzegorz Kolodziejczyk Date: Sun, 1 Sep 2019 22:44:54 +0000 (+0200) Subject: gattc: Extend gattc queue with mtu exchange X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=813bf3ddd;p=android-x86%2Fsystem-bt.git gattc: Extend gattc queue with mtu exchange Patch allows to exchange mtu using queue. Without this patch there was no possiblity to exchange mtu mixing this synchronous and queue api. Tag: #feature Test: CtsVerifier Sponsor: jpawlowski@ Change-Id: I2dd699d78de1b9eee8c683969f0c6586ccd21780 --- diff --git a/bta/gatt/bta_gattc_act.cc b/bta/gatt/bta_gattc_act.cc index e280ab8a3..c3bfce863 100644 --- a/bta/gatt/bta_gattc_act.cc +++ b/bta/gatt/bta_gattc_act.cc @@ -911,6 +911,8 @@ void bta_gattc_exec_cmpl(tBTA_GATTC_CLCB* p_clcb, tBTA_GATTC_OP_CMPL* p_data) { /** configure MTU operation complete */ void bta_gattc_cfg_mtu_cmpl(tBTA_GATTC_CLCB* p_clcb, tBTA_GATTC_OP_CMPL* p_data) { + GATT_CONFIGURE_MTU_OP_CB cb = p_clcb->p_q_cmd->api_mtu.mtu_cb; + void* my_cb_data = p_clcb->p_q_cmd->api_mtu.mtu_cb_data; tBTA_GATTC cb_data; osi_free_and_reset((void**)&p_clcb->p_q_cmd); @@ -924,6 +926,10 @@ void bta_gattc_cfg_mtu_cmpl(tBTA_GATTC_CLCB* p_clcb, cb_data.cfg_mtu.status = p_data->status; cb_data.cfg_mtu.mtu = p_clcb->p_srcb->mtu; + if (cb) { + cb(p_clcb->bta_conn_id, p_data->status, my_cb_data); + } + (*p_clcb->p_rcb->p_cback)(BTA_GATTC_CFG_MTU_EVT, &cb_data); } diff --git a/bta/gatt/bta_gattc_api.cc b/bta/gatt/bta_gattc_api.cc index 8ee19c495..e31d8af72 100644 --- a/bta/gatt/bta_gattc_api.cc +++ b/bta/gatt/bta_gattc_api.cc @@ -213,6 +213,19 @@ void BTA_GATTC_ConfigureMTU(uint16_t conn_id, uint16_t mtu) { bta_sys_sendmsg(p_buf); } +void BTA_GATTC_ConfigureMTU(uint16_t conn_id, uint16_t mtu, + GATT_CONFIGURE_MTU_OP_CB callback, void* cb_data) { + tBTA_GATTC_API_CFG_MTU* p_buf = + (tBTA_GATTC_API_CFG_MTU*)osi_malloc(sizeof(tBTA_GATTC_API_CFG_MTU)); + + p_buf->hdr.event = BTA_GATTC_API_CFG_MTU_EVT; + p_buf->hdr.layer_specific = conn_id; + p_buf->mtu = mtu; + p_buf->mtu_cb = callback; + p_buf->mtu_cb_data = cb_data; + + bta_sys_sendmsg(p_buf); +} /******************************************************************************* * diff --git a/bta/gatt/bta_gattc_int.h b/bta/gatt/bta_gattc_int.h index a1264ee7c..1e0ea8e43 100644 --- a/bta/gatt/bta_gattc_int.h +++ b/bta/gatt/bta_gattc_int.h @@ -161,6 +161,8 @@ typedef struct { typedef struct { BT_HDR hdr; uint16_t mtu; + GATT_CONFIGURE_MTU_OP_CB mtu_cb; + void* mtu_cb_data; } tBTA_GATTC_API_CFG_MTU; typedef struct { diff --git a/bta/gatt/bta_gattc_queue.cc b/bta/gatt/bta_gattc_queue.cc index 6d8f57c3f..0058741b4 100644 --- a/bta/gatt/bta_gattc_queue.cc +++ b/bta/gatt/bta_gattc_queue.cc @@ -26,6 +26,7 @@ constexpr uint8_t GATT_READ_CHAR = 1; constexpr uint8_t GATT_READ_DESC = 2; constexpr uint8_t GATT_WRITE_CHAR = 3; constexpr uint8_t GATT_WRITE_DESC = 4; +constexpr uint8_t GATT_CONFIG_MTU = 5; struct gatt_read_op_data { GATT_READ_OP_CB cb; @@ -80,6 +81,29 @@ void BtaGattQueue::gatt_write_op_finished(uint16_t conn_id, tGATT_STATUS status, } } +struct gatt_configure_mtu_op_data { + GATT_CONFIGURE_MTU_OP_CB cb; + void* cb_data; +}; + +void BtaGattQueue::gatt_configure_mtu_op_finished(uint16_t conn_id, + tGATT_STATUS status, + void* data) { + gatt_configure_mtu_op_data* tmp = (gatt_configure_mtu_op_data*)data; + GATT_CONFIGURE_MTU_OP_CB tmp_cb = tmp->cb; + void* tmp_cb_data = tmp->cb_data; + + osi_free(data); + + mark_as_not_executing(conn_id); + gatt_execute_next_op(conn_id); + + if (tmp_cb) { + tmp_cb(conn_id, status, tmp_cb_data); + return; + } +} + void BtaGattQueue::gatt_execute_next_op(uint16_t conn_id) { APPL_TRACE_DEBUG("%s: conn_id=0x%x", __func__, conn_id); if (gatt_op_queue.empty()) { @@ -137,6 +161,14 @@ void BtaGattQueue::gatt_execute_next_op(uint16_t conn_id) { data->cb_data = op.write_cb_data; BTA_GATTC_WriteCharDescr(conn_id, op.handle, std::move(op.value), GATT_AUTH_REQ_NONE, gatt_write_op_finished, data); + } else if (op.type == GATT_CONFIG_MTU) { + gatt_configure_mtu_op_data* data = + (gatt_configure_mtu_op_data*)osi_malloc(sizeof(gatt_configure_mtu_op_data)); + data->cb = op.mtu_cb; + data->cb_data = op.mtu_cb_data; + BTA_GATTC_ConfigureMTU(conn_id, static_cast(op.value[0] | + (op.value[1] << 8)), + gatt_configure_mtu_op_finished, data); } gatt_ops.pop_front(); @@ -190,3 +222,12 @@ void BtaGattQueue::WriteDescriptor(uint16_t conn_id, uint16_t handle, .value = std::move(value)}); gatt_execute_next_op(conn_id); } + +void BtaGattQueue::ConfigureMtu(uint16_t conn_id, uint16_t mtu) { + LOG(INFO) << __func__ << ", mtu: " << static_cast(mtu); + std::vector value = {static_cast(mtu & 0xff), + static_cast(mtu >> 8)}; + gatt_op_queue[conn_id].push_back({.type = GATT_CONFIG_MTU, + .value = std::move(value)}); + gatt_execute_next_op(conn_id); +} diff --git a/bta/include/bta_gatt_api.h b/bta/include/bta_gatt_api.h index 610989c75..89418ca6c 100644 --- a/bta/include/bta_gatt_api.h +++ b/bta/include/bta_gatt_api.h @@ -601,6 +601,8 @@ typedef void (*GATT_READ_OP_CB)(uint16_t conn_id, tGATT_STATUS status, void* data); typedef void (*GATT_WRITE_OP_CB)(uint16_t conn_id, tGATT_STATUS status, uint16_t handle, void* data); +typedef void (*GATT_CONFIGURE_MTU_OP_CB)(uint16_t conn_id, tGATT_STATUS status, + void* data); /******************************************************************************* * @@ -808,6 +810,9 @@ extern void BTA_GATTC_Refresh(const RawAddress& remote_bda); * ******************************************************************************/ extern void BTA_GATTC_ConfigureMTU(uint16_t conn_id, uint16_t mtu); +extern void BTA_GATTC_ConfigureMTU(uint16_t conn_id, uint16_t mtu, + GATT_CONFIGURE_MTU_OP_CB callback, + void* cb_data); /******************************************************************************* * BTA GATT Server API diff --git a/bta/include/bta_gatt_queue.h b/bta/include/bta_gatt_queue.h index 963fc138a..a87a053fe 100644 --- a/bta/include/bta_gatt_queue.h +++ b/bta/include/bta_gatt_queue.h @@ -47,6 +47,7 @@ class BtaGattQueue { std::vector value, tGATT_WRITE_TYPE write_type, GATT_WRITE_OP_CB cb, void* cb_data); + static void ConfigureMtu(uint16_t conn_id, uint16_t mtu); /* Holds pending GATT operations */ struct gatt_operation { @@ -56,6 +57,8 @@ class BtaGattQueue { void* read_cb_data; GATT_WRITE_OP_CB write_cb; void* write_cb_data; + GATT_CONFIGURE_MTU_OP_CB mtu_cb; + void* mtu_cb_data; /* write-specific fields */ tGATT_WRITE_TYPE write_type; @@ -70,6 +73,8 @@ class BtaGattQueue { uint8_t* value, void* data); static void gatt_write_op_finished(uint16_t conn_id, tGATT_STATUS status, uint16_t handle, void* data); + static void gatt_configure_mtu_op_finished(uint16_t conn_id, + tGATT_STATUS status, void* data); // maps connection id to operations waiting for execution static std::unordered_map> gatt_op_queue; diff --git a/btif/src/btif_gatt_client.cc b/btif/src/btif_gatt_client.cc index 8780d5478..530030a48 100644 --- a/btif/src/btif_gatt_client.cc +++ b/btif/src/btif_gatt_client.cc @@ -577,7 +577,9 @@ static bt_status_t btif_gattc_read_remote_rssi(int client_if, static bt_status_t btif_gattc_configure_mtu(int conn_id, int mtu) { CHECK_BTGATT_INIT(); return do_in_jni_thread( - Bind(base::IgnoreResult(&BTA_GATTC_ConfigureMTU), conn_id, mtu)); + Bind(base::IgnoreResult( + static_cast(&BTA_GATTC_ConfigureMTU)), + conn_id, mtu)); } static void btif_gattc_conn_parameter_update_impl(