nimble/att: Use new helpers for sending Prepare 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/d290cd7e Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/d290cd7e Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/d290cd7e Branch: refs/heads/master Commit: d290cd7eb79540f1d9f14623861894e0dbd8ee9e Parents: a9549fd Author: Szymon Janc <szymon.j...@codecoup.pl> Authored: Fri Mar 24 15:34:39 2017 +0100 Committer: Szymon Janc <szymon.j...@codecoup.pl> Committed: Mon Apr 10 11:31:31 2017 +0200 ---------------------------------------------------------------------- net/nimble/host/src/ble_att_clt.c | 29 ++++++++++-------------- net/nimble/host/src/ble_att_cmd_priv.h | 1 + net/nimble/host/src/ble_att_priv.h | 5 ++-- net/nimble/host/src/ble_gattc.c | 15 ++++-------- net/nimble/host/test/src/ble_att_clt_test.c | 9 ++------ 5 files changed, 22 insertions(+), 37 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d290cd7e/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 114abea..141e6e7 100644 --- a/net/nimble/host/src/ble_att_clt.c +++ b/net/nimble/host/src/ble_att_clt.c @@ -872,52 +872,47 @@ ble_att_clt_rx_write(uint16_t conn_handle, struct os_mbuf **rxom) *****************************************************************************/ int -ble_att_clt_tx_prep_write(uint16_t conn_handle, - const struct ble_att_prep_write_cmd *req, - struct os_mbuf *txom) +ble_att_clt_tx_prep_write(uint16_t conn_handle, uint16_t handle, + uint16_t offset, struct os_mbuf *txom) { #if !NIMBLE_BLE_ATT_CLT_PREP_WRITE return BLE_HS_ENOTSUP; #endif + struct ble_att_prep_write_cmd *req; + struct os_mbuf *txom2; int rc; - if (req->bapc_handle == 0) { + if (handle == 0) { rc = BLE_HS_EINVAL; goto err; } - if (req->bapc_offset + OS_MBUF_PKTLEN(txom) > BLE_ATT_ATTR_MAX_LEN) { + if (offset + OS_MBUF_PKTLEN(txom) > BLE_ATT_ATTR_MAX_LEN) { rc = BLE_HS_EINVAL; goto err; } if (OS_MBUF_PKTLEN(txom) > ble_att_mtu(conn_handle) - BLE_ATT_PREP_WRITE_CMD_BASE_SZ) { - rc = BLE_HS_EINVAL; goto err; } - txom = os_mbuf_prepend_pullup(txom, BLE_ATT_PREP_WRITE_CMD_BASE_SZ); - if (txom == NULL) { + req = ble_att_cmd_get(BLE_ATT_OP_PREP_WRITE_REQ, sizeof(*req), &txom2); + if (req == NULL) { rc = BLE_HS_ENOMEM; goto err; } - ble_att_prep_write_req_write(txom->om_data, BLE_ATT_PREP_WRITE_CMD_BASE_SZ, - req); - - rc = ble_att_clt_tx_req(conn_handle, txom); - txom = NULL; - if (rc != 0) { - goto err; - } + req->bapc_handle = htole16(handle); + req->bapc_offset = htole16(offset); + os_mbuf_concat(txom2, txom); BLE_ATT_LOG_CMD(1, "prep write req", conn_handle, ble_att_prep_write_cmd_log, req); - return 0; + return ble_att_tx(conn_handle, txom2); err: os_mbuf_free_chain(txom); http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d290cd7e/net/nimble/host/src/ble_att_cmd_priv.h ---------------------------------------------------------------------- diff --git a/net/nimble/host/src/ble_att_cmd_priv.h b/net/nimble/host/src/ble_att_cmd_priv.h index 491dc99..3e03cca 100644 --- a/net/nimble/host/src/ble_att_cmd_priv.h +++ b/net/nimble/host/src/ble_att_cmd_priv.h @@ -269,6 +269,7 @@ struct ble_att_write_req { struct ble_att_prep_write_cmd { uint16_t bapc_handle; uint16_t bapc_offset; + uint16_t bapc_value[0]; } __attribute__((packed)); /** http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d290cd7e/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 b7def41..dd14be7 100644 --- a/net/nimble/host/src/ble_att_priv.h +++ b/net/nimble/host/src/ble_att_priv.h @@ -280,9 +280,8 @@ int ble_att_clt_tx_write_req(uint16_t conn_handle, uint16_t handle, struct os_mbuf *txom); int ble_att_clt_tx_write_cmd(uint16_t conn_handle, uint16_t handle, struct os_mbuf *txom); -int ble_att_clt_tx_prep_write(uint16_t conn_handle, - const struct ble_att_prep_write_cmd *req, - struct os_mbuf *txom); +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); http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d290cd7e/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 7e57433..fede8d1 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_prep_write_cmd prep_req; struct ble_att_exec_write_req exec_req; struct os_mbuf *om; int write_len; @@ -3859,10 +3858,9 @@ ble_gattc_write_long_tx(struct ble_gattc_proc *proc) goto done; } - prep_req.bapc_handle = proc->write_long.attr.handle; - prep_req.bapc_offset = proc->write_long.attr.offset; - - rc = ble_att_clt_tx_prep_write(proc->conn_handle, &prep_req, om); + rc = ble_att_clt_tx_prep_write(proc->conn_handle, + proc->write_long.attr.handle, + proc->write_long.attr.offset, om); om = NULL; if (rc != 0) { goto done; @@ -4130,7 +4128,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_prep_write_cmd prep_req; struct ble_att_exec_write_req exec_req; struct ble_gatt_attr *attr; struct os_mbuf *om; @@ -4175,10 +4172,8 @@ ble_gattc_write_reliable_tx(struct ble_gattc_proc *proc) goto done; } - prep_req.bapc_handle = attr->handle; - prep_req.bapc_offset = attr->offset; - - rc = ble_att_clt_tx_prep_write(proc->conn_handle, &prep_req, om); + rc = ble_att_clt_tx_prep_write(proc->conn_handle, attr->handle, + attr->offset, om); om = NULL; if (rc != 0) { goto done; http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d290cd7e/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 97a1a44..e3ba5ce 100644 --- a/net/nimble/host/test/src/ble_att_clt_test.c +++ b/net/nimble/host/test/src/ble_att_clt_test.c @@ -199,10 +199,8 @@ ble_att_clt_test_misc_prep_good(uint16_t handle, uint16_t offset, conn_handle = ble_att_clt_test_misc_init(); - req.bapc_handle = handle; - req.bapc_offset = offset; om = ble_hs_test_util_om_from_flat(attr_data, attr_data_len); - rc = ble_att_clt_tx_prep_write(conn_handle, &req, om); + rc = ble_att_clt_tx_prep_write(conn_handle, handle, offset, om); TEST_ASSERT(rc == 0); ble_hs_test_util_tx_all(); @@ -247,7 +245,6 @@ ble_att_clt_test_misc_prep_bad(uint16_t handle, uint16_t offset, uint8_t *attr_data, uint16_t attr_data_len, int status) { - struct ble_att_prep_write_cmd req; struct os_mbuf *om; uint16_t conn_handle; int rc; @@ -256,9 +253,7 @@ ble_att_clt_test_misc_prep_bad(uint16_t handle, uint16_t offset, om = ble_hs_test_util_om_from_flat(attr_data, attr_data_len); - req.bapc_handle = handle; - req.bapc_offset = offset; - rc = ble_att_clt_tx_prep_write(conn_handle, &req, om); + rc = ble_att_clt_tx_prep_write(conn_handle, handle, offset, om); TEST_ASSERT(rc == status); }