nimble/att: Use new helpers for sending Execute Write Request 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/d74cc3ee Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/d74cc3ee Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/d74cc3ee Branch: refs/heads/master Commit: d74cc3eeb8a729346de2208fdf9f57593d1627a3 Parents: d290cd7 Author: Szymon Janc <[email protected]> Authored: Fri Mar 24 15:34:55 2017 +0100 Committer: Szymon Janc <[email protected]> Committed: Mon Apr 10 11:31:31 2017 +0200 ---------------------------------------------------------------------- net/nimble/host/src/ble_att_clt.c | 47 ++++-------------------- net/nimble/host/src/ble_att_priv.h | 3 +- net/nimble/host/src/ble_gattc.c | 22 ++++------- net/nimble/host/test/src/ble_att_clt_test.c | 7 +--- 4 files changed, 19 insertions(+), 60 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d74cc3ee/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 141e6e7..52c83c0 100644 --- a/net/nimble/host/src/ble_att_clt.c +++ b/net/nimble/host/src/ble_att_clt.c @@ -27,38 +27,6 @@ #include "ble_hs_priv.h" static int -ble_att_clt_init_req(uint16_t initial_sz, struct os_mbuf **out_txom) -{ - struct os_mbuf *om; - void *buf; - int rc; - - *out_txom = NULL; - - om = ble_hs_mbuf_l2cap_pkt(); - if (om == NULL) { - rc = BLE_HS_ENOMEM; - goto err; - } - - buf = os_mbuf_extend(om, initial_sz); - if (buf == NULL) { - rc = BLE_HS_ENOMEM; - goto err; - } - - /* The caller expects the initial buffer to be at the start of the mbuf. */ - BLE_HS_DBG_ASSERT(buf == om->om_data); - - *out_txom = om; - return 0; - -err: - os_mbuf_free_chain(om); - return rc; -} - -static int ble_att_clt_tx_req(uint16_t conn_handle, struct os_mbuf *txom) { struct ble_l2cap_chan *chan; @@ -955,23 +923,24 @@ done: *****************************************************************************/ int -ble_att_clt_tx_exec_write(uint16_t conn_handle, - const struct ble_att_exec_write_req *req) +ble_att_clt_tx_exec_write(uint16_t conn_handle, uint8_t flags) { #if !NIMBLE_BLE_ATT_CLT_EXEC_WRITE return BLE_HS_ENOTSUP; #endif + struct ble_att_exec_write_req *req; struct os_mbuf *txom; int rc; - rc = ble_att_clt_init_req(BLE_ATT_EXEC_WRITE_REQ_SZ, &txom); - if (rc != 0) { - return rc; + req = ble_att_cmd_get(BLE_ATT_OP_EXEC_WRITE_REQ, sizeof(*req), &txom); + if (req == NULL) { + return BLE_HS_ENOMEM; } - ble_att_exec_write_req_write(txom->om_data, txom->om_len, req); - rc = ble_att_clt_tx_req(conn_handle, txom); + req->baeq_flags = flags; + + rc = ble_att_tx(conn_handle, txom); if (rc != 0) { return rc; } http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d74cc3ee/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 dd14be7..fbc81d9 100644 --- a/net/nimble/host/src/ble_att_priv.h +++ b/net/nimble/host/src/ble_att_priv.h @@ -283,8 +283,7 @@ int ble_att_clt_tx_write_cmd(uint16_t conn_handle, uint16_t handle, int ble_att_clt_tx_prep_write(uint16_t conn_handle, uint16_t handle, uint16_t offset, struct os_mbuf *txom); int ble_att_clt_rx_prep_write(uint16_t conn_handle, struct os_mbuf **rxom); -int ble_att_clt_tx_exec_write(uint16_t conn_handle, - const struct ble_att_exec_write_req *req); +int ble_att_clt_tx_exec_write(uint16_t conn_handle, uint8_t flags); int ble_att_clt_rx_exec_write(uint16_t conn_handle, struct os_mbuf **rxom); int ble_att_clt_rx_write(uint16_t conn_handle, struct os_mbuf **rxom); int ble_att_clt_tx_notify(uint16_t conn_handle, http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d74cc3ee/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 fede8d1..59fbea8 100644 --- a/net/nimble/host/src/ble_gattc.c +++ b/net/nimble/host/src/ble_gattc.c @@ -3816,7 +3816,6 @@ ble_gattc_write_long_tmo(struct ble_gattc_proc *proc) static int ble_gattc_write_long_tx(struct ble_gattc_proc *proc) { - struct ble_att_exec_write_req exec_req; struct os_mbuf *om; int write_len; int max_sz; @@ -3838,8 +3837,8 @@ ble_gattc_write_long_tx(struct ble_gattc_proc *proc) proc->write_long.attr.offset); if (write_len <= 0) { - exec_req.baeq_flags = BLE_ATT_EXEC_WRITE_F_EXECUTE; - rc = ble_att_clt_tx_exec_write(proc->conn_handle, &exec_req); + rc = ble_att_clt_tx_exec_write(proc->conn_handle, + BLE_ATT_EXEC_WRITE_F_EXECUTE); goto done; } @@ -3895,8 +3894,6 @@ static void ble_gattc_write_long_err(struct ble_gattc_proc *proc, int status, uint16_t att_handle) { - struct ble_att_exec_write_req exec_req; - ble_gattc_dbg_assert_proc_not_inserted(proc); /* If we have successfully queued any data, and the failure occurred before @@ -3906,8 +3903,8 @@ ble_gattc_write_long_err(struct ble_gattc_proc *proc, int status, proc->write_long.attr.offset < OS_MBUF_PKTLEN(proc->write_long.attr.om)) { - exec_req.baeq_flags = BLE_ATT_EXEC_WRITE_F_CANCEL; - ble_att_clt_tx_exec_write(proc->conn_handle, &exec_req); + ble_att_clt_tx_exec_write(proc->conn_handle, + BLE_ATT_EXEC_WRITE_F_CANCEL); } /* Report failure. */ @@ -4128,7 +4125,6 @@ ble_gattc_write_reliable_tmo(struct ble_gattc_proc *proc) static int ble_gattc_write_reliable_tx(struct ble_gattc_proc *proc) { - struct ble_att_exec_write_req exec_req; struct ble_gatt_attr *attr; struct os_mbuf *om; uint16_t max_sz; @@ -4142,8 +4138,8 @@ ble_gattc_write_reliable_tx(struct ble_gattc_proc *proc) attr_idx = proc->write_reliable.cur_attr; if (attr_idx >= proc->write_reliable.num_attrs) { - exec_req.baeq_flags = BLE_ATT_EXEC_WRITE_F_EXECUTE; - rc = ble_att_clt_tx_exec_write(proc->conn_handle, &exec_req); + rc = ble_att_clt_tx_exec_write(proc->conn_handle, + BLE_ATT_EXEC_WRITE_F_EXECUTE); goto done; } @@ -4208,8 +4204,6 @@ static void ble_gattc_write_reliable_err(struct ble_gattc_proc *proc, int status, uint16_t att_handle) { - struct ble_att_exec_write_req exec_req; - ble_gattc_dbg_assert_proc_not_inserted(proc); ble_gattc_write_reliable_cb(proc, status, att_handle); @@ -4219,8 +4213,8 @@ ble_gattc_write_reliable_err(struct ble_gattc_proc *proc, int status, if (proc->write_reliable.cur_attr >= 0 && proc->write_reliable.cur_attr < proc->write_reliable.num_attrs) { - exec_req.baeq_flags = BLE_ATT_EXEC_WRITE_F_CANCEL; - ble_att_clt_tx_exec_write(proc->conn_handle, &exec_req); + ble_att_clt_tx_exec_write(proc->conn_handle, + BLE_ATT_EXEC_WRITE_F_CANCEL); } } http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d74cc3ee/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 e3ba5ce..4bd1947 100644 --- a/net/nimble/host/test/src/ble_att_clt_test.c +++ b/net/nimble/host/test/src/ble_att_clt_test.c @@ -227,8 +227,7 @@ ble_att_clt_test_misc_exec_good(uint8_t flags) conn_handle = ble_att_clt_test_misc_init(); - req.baeq_flags = flags; - rc = ble_att_clt_tx_exec_write(conn_handle, &req); + rc = ble_att_clt_tx_exec_write(conn_handle, flags); TEST_ASSERT(rc == 0); ble_hs_test_util_tx_all(); @@ -481,7 +480,6 @@ TEST_CASE(ble_att_clt_test_rx_prep_write) TEST_CASE(ble_att_clt_test_tx_exec_write) { - struct ble_att_exec_write_req req; uint16_t conn_handle; int rc; @@ -492,8 +490,7 @@ TEST_CASE(ble_att_clt_test_tx_exec_write) ble_att_clt_test_misc_exec_good(BLE_ATT_EXEC_WRITE_F_EXECUTE); /*** Success: nonzero == execute. */ - req.baeq_flags = 0x02; - rc = ble_att_clt_tx_exec_write(conn_handle, &req); + rc = ble_att_clt_tx_exec_write(conn_handle, 0x02); TEST_ASSERT(rc == 0); }
