nimble/att: Use new helpers for sending Read By Type 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/3f4cac38 Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/3f4cac38 Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/3f4cac38 Branch: refs/heads/master Commit: 3f4cac389abd597446cfdd5edbbf535b9142e294 Parents: ab23765 Author: Szymon Janc <szymon.j...@codecoup.pl> Authored: Fri Mar 24 15:29:40 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 | 43 +++++++++-------------------- 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 | 41 ++++++++------------------- 4 files changed, 28 insertions(+), 62 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3f4cac38/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 95db5bb..96a04e2 100644 --- a/net/nimble/host/src/ble_att_clt.c +++ b/net/nimble/host/src/ble_att_clt.c @@ -445,52 +445,35 @@ ble_att_clt_rx_find_type_value(uint16_t conn_handle, struct os_mbuf **rxom) *****************************************************************************/ int -ble_att_clt_tx_read_type(uint16_t conn_handle, - const struct ble_att_read_type_req *req, - const ble_uuid_t *uuid) +ble_att_clt_tx_read_type(uint16_t conn_handle, uint16_t start_handle, + uint16_t end_handle, const ble_uuid_t *uuid) { #if !NIMBLE_BLE_ATT_CLT_READ_TYPE return BLE_HS_ENOTSUP; #endif + struct ble_att_read_type_req *req; struct os_mbuf *txom; - int rc; - - txom = NULL; - - if (req->batq_start_handle == 0 || - req->batq_start_handle > req->batq_end_handle) { - rc = BLE_HS_EINVAL; - goto err; + if (start_handle == 0 || start_handle > end_handle) { + return BLE_HS_EINVAL; } - rc = ble_att_clt_init_req(BLE_ATT_READ_TYPE_REQ_BASE_SZ, &txom); - if (rc != 0) { - goto err; + req = ble_att_cmd_get(BLE_ATT_OP_READ_TYPE_REQ, + sizeof(*req) + ble_uuid_length(uuid), &txom); + if (req == NULL) { + return BLE_HS_ENOMEM; } - ble_att_read_type_req_write(txom->om_data, txom->om_len, req); - rc = ble_uuid_to_mbuf(uuid, txom); - if (rc != 0) { - rc = BLE_HS_ENOMEM; - goto err; - } + req->batq_start_handle = htole16(start_handle); + req->batq_end_handle = htole16(end_handle); - rc = ble_att_clt_tx_req(conn_handle, txom); - txom = NULL; - if (rc != 0) { - goto err; - } + ble_uuid_flat(uuid, req->uuid); BLE_ATT_LOG_CMD(1, "read type req", conn_handle, ble_att_read_type_req_log, req); - return 0; - -err: - os_mbuf_free_chain(txom); - return rc; + return ble_att_tx(conn_handle, txom); } static int http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3f4cac38/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 c07455a..be7fda3 100644 --- a/net/nimble/host/src/ble_att_cmd_priv.h +++ b/net/nimble/host/src/ble_att_cmd_priv.h @@ -130,6 +130,7 @@ struct ble_att_find_type_value_req { struct ble_att_read_type_req { uint16_t batq_start_handle; uint16_t batq_end_handle; + uint8_t uuid[0]; } __attribute__((packed)); /** http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3f4cac38/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 62bebf9..19f84a4 100644 --- a/net/nimble/host/src/ble_att_priv.h +++ b/net/nimble/host/src/ble_att_priv.h @@ -260,9 +260,8 @@ int ble_att_clt_rx_read_blob(uint16_t conn_handle, struct os_mbuf **rxom); int ble_att_clt_tx_read_mult(uint16_t conn_handle, const uint16_t *handles, int num_handles); int ble_att_clt_rx_read_mult(uint16_t conn_handle, struct os_mbuf **rxom); -int ble_att_clt_tx_read_type(uint16_t conn_handle, - const struct ble_att_read_type_req *req, - const ble_uuid_t *uuid); +int ble_att_clt_tx_read_type(uint16_t conn_handle, uint16_t start_handle, + uint16_t end_handle, const ble_uuid_t *uuid); int ble_att_clt_rx_read_type(uint16_t conn_handle, struct os_mbuf **rxom); int ble_att_clt_tx_read_group_type( uint16_t conn_handle, const struct ble_att_read_group_type_req *req, http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3f4cac38/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 85866b5..2e04e54 100644 --- a/net/nimble/host/src/ble_gattc.c +++ b/net/nimble/host/src/ble_gattc.c @@ -1849,7 +1849,6 @@ ble_gattc_find_inc_svcs_tmo(struct ble_gattc_proc *proc) static int ble_gattc_find_inc_svcs_tx(struct ble_gattc_proc *proc) { - struct ble_att_read_type_req read_type_req; ble_uuid16_t uuid = BLE_UUID16_INIT(BLE_ATT_UUID_INCLUDE); int rc; @@ -1857,12 +1856,9 @@ ble_gattc_find_inc_svcs_tx(struct ble_gattc_proc *proc) if (proc->find_inc_svcs.cur_start == 0) { /* Find the next included service. */ - read_type_req.batq_start_handle = - proc->find_inc_svcs.prev_handle + 1; - read_type_req.batq_end_handle = proc->find_inc_svcs.end_handle; - rc = ble_att_clt_tx_read_type(proc->conn_handle, - &read_type_req, &uuid.u); + proc->find_inc_svcs.prev_handle + 1, + proc->find_inc_svcs.end_handle, &uuid.u); if (rc != 0) { return rc; } @@ -2182,16 +2178,14 @@ ble_gattc_disc_all_chrs_tmo(struct ble_gattc_proc *proc) static int ble_gattc_disc_all_chrs_tx(struct ble_gattc_proc *proc) { - struct ble_att_read_type_req req; ble_uuid16_t uuid = BLE_UUID16_INIT(BLE_ATT_UUID_CHARACTERISTIC); int rc; ble_gattc_dbg_assert_proc_not_inserted(proc); - req.batq_start_handle = proc->disc_all_chrs.prev_handle + 1; - req.batq_end_handle = proc->disc_all_chrs.end_handle; - - rc = ble_att_clt_tx_read_type(proc->conn_handle, &req, &uuid.u); + rc = ble_att_clt_tx_read_type(proc->conn_handle, + proc->disc_all_chrs.prev_handle + 1, + proc->disc_all_chrs.end_handle, &uuid.u); if (rc != 0) { return rc; } @@ -2428,16 +2422,14 @@ ble_gattc_disc_chr_uuid_tmo(struct ble_gattc_proc *proc) static int ble_gattc_disc_chr_uuid_tx(struct ble_gattc_proc *proc) { - struct ble_att_read_type_req req; ble_uuid16_t uuid = BLE_UUID16_INIT(BLE_ATT_UUID_CHARACTERISTIC); int rc; ble_gattc_dbg_assert_proc_not_inserted(proc); - req.batq_start_handle = proc->disc_chr_uuid.prev_handle + 1; - req.batq_end_handle = proc->disc_chr_uuid.end_handle; - - rc = ble_att_clt_tx_read_type(proc->conn_handle, &req, &uuid.u); + rc = ble_att_clt_tx_read_type(proc->conn_handle, + proc->disc_chr_uuid.prev_handle + 1, + proc->disc_chr_uuid.end_handle, &uuid.u); if (rc != 0) { return rc; } @@ -3127,19 +3119,10 @@ ble_gattc_read_uuid_rx_complete(struct ble_gattc_proc *proc, int status) static int ble_gattc_read_uuid_tx(struct ble_gattc_proc *proc) { - struct ble_att_read_type_req req; - int rc; - - req.batq_start_handle = proc->read_uuid.start_handle; - req.batq_end_handle = proc->read_uuid.end_handle; - - rc = ble_att_clt_tx_read_type(proc->conn_handle, &req, - &proc->read_uuid.chr_uuid.u); - if (rc != 0) { - return rc; - } - - return 0; + return ble_att_clt_tx_read_type(proc->conn_handle, + proc->read_uuid.start_handle, + proc->read_uuid.end_handle, + &proc->read_uuid.chr_uuid.u); } /**