nimble/att: Use new helpers for sending read command This constructs response directly on mbuf reducing number of memcopies.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/58743be0 Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/58743be0 Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/58743be0 Branch: refs/heads/master Commit: 58743be0c8f1991e4dc98b4c33d3b0420bdb3743 Parents: 55b8a5c Author: Szymon Janc <[email protected]> Authored: Fri Mar 24 15:27:57 2017 +0100 Committer: Szymon Janc <[email protected]> Committed: Mon Apr 10 11:31:31 2017 +0200 ---------------------------------------------------------------------- net/nimble/host/src/ble_att_clt.c | 16 +++++++++------- net/nimble/host/src/ble_att_priv.h | 3 +-- net/nimble/host/src/ble_gattc.c | 13 ++++--------- net/nimble/host/test/src/ble_att_clt_test.c | 7 ++----- 4 files changed, 16 insertions(+), 23 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/58743be0/net/nimble/host/src/ble_att_clt.c ---------------------------------------------------------------------- diff --git a/net/nimble/host/src/ble_att_clt.c b/net/nimble/host/src/ble_att_clt.c index 7ea7980..fc5a432 100644 --- a/net/nimble/host/src/ble_att_clt.c +++ b/net/nimble/host/src/ble_att_clt.c @@ -557,26 +557,28 @@ done: *****************************************************************************/ int -ble_att_clt_tx_read(uint16_t conn_handle, const struct ble_att_read_req *req) +ble_att_clt_tx_read(uint16_t conn_handle, uint16_t handle) { #if !NIMBLE_BLE_ATT_CLT_READ return BLE_HS_ENOTSUP; #endif + struct ble_att_read_req *req; struct os_mbuf *txom; int rc; - if (req->barq_handle == 0) { + if (handle == 0) { return BLE_HS_EINVAL; } - rc = ble_att_clt_init_req(BLE_ATT_READ_REQ_SZ, &txom); - if (rc != 0) { - return rc; + req = ble_att_cmd_get(BLE_ATT_OP_READ_REQ, sizeof(*req), &txom); + if (req == NULL) { + return BLE_HS_ENOMEM; } - ble_att_read_req_write(txom->om_data, txom->om_len, req); - rc = ble_att_clt_tx_req(conn_handle, txom); + req->barq_handle = htole16(handle); + + rc = ble_att_tx(conn_handle, txom); if (rc != 0) { return rc; } http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/58743be0/net/nimble/host/src/ble_att_priv.h ---------------------------------------------------------------------- diff --git a/net/nimble/host/src/ble_att_priv.h b/net/nimble/host/src/ble_att_priv.h index 4e37bb7..85da2de 100644 --- a/net/nimble/host/src/ble_att_priv.h +++ b/net/nimble/host/src/ble_att_priv.h @@ -252,8 +252,7 @@ struct ble_att_read_group_type_adata { int ble_att_clt_rx_error(uint16_t conn_handle, struct os_mbuf **rxom); int ble_att_clt_tx_mtu(uint16_t conn_handle, uint16_t mtu); int ble_att_clt_rx_mtu(uint16_t conn_handle, struct os_mbuf **rxom); -int ble_att_clt_tx_read(uint16_t conn_handle, - const struct ble_att_read_req *req); +int ble_att_clt_tx_read(uint16_t conn_handle, uint16_t handle); int ble_att_clt_rx_read(uint16_t conn_handle, struct os_mbuf **rxom); int ble_att_clt_tx_read_blob(uint16_t conn_handle, const struct ble_att_read_blob_req *req); http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/58743be0/net/nimble/host/src/ble_gattc.c ---------------------------------------------------------------------- diff --git a/net/nimble/host/src/ble_gattc.c b/net/nimble/host/src/ble_gattc.c index d50368f..ba84727 100644 --- a/net/nimble/host/src/ble_gattc.c +++ b/net/nimble/host/src/ble_gattc.c @@ -1850,7 +1850,6 @@ static int ble_gattc_find_inc_svcs_tx(struct ble_gattc_proc *proc) { struct ble_att_read_type_req read_type_req; - struct ble_att_read_req read_req; ble_uuid16_t uuid = BLE_UUID16_INIT(BLE_ATT_UUID_INCLUDE); int rc; @@ -1869,8 +1868,8 @@ ble_gattc_find_inc_svcs_tx(struct ble_gattc_proc *proc) } } else { /* Read the UUID of the previously found service. */ - read_req.barq_handle = proc->find_inc_svcs.cur_start; - rc = ble_att_clt_tx_read(proc->conn_handle, &read_req); + rc = ble_att_clt_tx_read(proc->conn_handle, + proc->find_inc_svcs.cur_start); if (rc != 0) { return rc; } @@ -2950,11 +2949,9 @@ ble_gattc_read_rx_read_rsp(struct ble_gattc_proc *proc, int status, static int ble_gattc_read_tx(struct ble_gattc_proc *proc) { - struct ble_att_read_req req; int rc; - req.barq_handle = proc->read.handle; - rc = ble_att_clt_tx_read(proc->conn_handle, &req); + rc = ble_att_clt_tx_read(proc->conn_handle, proc->read.handle); if (rc != 0) { return rc; } @@ -3256,14 +3253,12 @@ static int ble_gattc_read_long_tx(struct ble_gattc_proc *proc) { struct ble_att_read_blob_req blob_req; - struct ble_att_read_req read_req; int rc; ble_gattc_dbg_assert_proc_not_inserted(proc); if (proc->read_long.offset == 0) { - read_req.barq_handle = proc->read_long.handle; - rc = ble_att_clt_tx_read(proc->conn_handle, &read_req); + rc = ble_att_clt_tx_read(proc->conn_handle, proc->read_long.handle); if (rc != 0) { return rc; } http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/58743be0/net/nimble/host/test/src/ble_att_clt_test.c ---------------------------------------------------------------------- diff --git a/net/nimble/host/test/src/ble_att_clt_test.c b/net/nimble/host/test/src/ble_att_clt_test.c index c452128..3d12ee8 100644 --- a/net/nimble/host/test/src/ble_att_clt_test.c +++ b/net/nimble/host/test/src/ble_att_clt_test.c @@ -297,20 +297,17 @@ TEST_CASE(ble_att_clt_test_tx_write) TEST_CASE(ble_att_clt_test_tx_read) { - struct ble_att_read_req req; uint16_t conn_handle; int rc; conn_handle = ble_att_clt_test_misc_init(); /*** Success. */ - req.barq_handle = 1; - rc = ble_att_clt_tx_read(conn_handle, &req); + rc = ble_att_clt_tx_read(conn_handle, 1); TEST_ASSERT(rc == 0); /*** Error: handle of 0. */ - req.barq_handle = 0; - rc = ble_att_clt_tx_read(conn_handle, &req); + rc = ble_att_clt_tx_read(conn_handle, 0); TEST_ASSERT(rc == BLE_HS_EINVAL); }
