nimble/att: Use new helpers for sending Find By Type Value Request This constructs response directly on mbuf reducing number of memcopies. read
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/191acab7 Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/191acab7 Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/191acab7 Branch: refs/heads/master Commit: 191acab73c9c77c157a806d8871b653f3c64cbc9 Parents: 5e82b3f Author: Szymon Janc <[email protected]> Authored: Fri Mar 24 15:33:07 2017 +0100 Committer: Szymon Janc <[email protected]> Committed: Mon Apr 10 11:31:31 2017 +0200 ---------------------------------------------------------------------- net/nimble/host/src/ble_att_clt.c | 48 +++++++++++------------------ net/nimble/host/src/ble_att_cmd_priv.h | 1 + net/nimble/host/src/ble_att_priv.h | 6 ++-- net/nimble/host/src/ble_gattc.c | 10 +++--- 4 files changed, 26 insertions(+), 39 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/191acab7/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 f72b209..0464821 100644 --- a/net/nimble/host/src/ble_att_clt.c +++ b/net/nimble/host/src/ble_att_clt.c @@ -333,53 +333,41 @@ done: * $find by type value * *****************************************************************************/ +/* + * TODO consider this to accept UUID instead of value, it is used only for this + * anyway + */ int -ble_att_clt_tx_find_type_value(uint16_t conn_handle, - const struct ble_att_find_type_value_req *req, +ble_att_clt_tx_find_type_value(uint16_t conn_handle, uint16_t start_handle, + uint16_t end_handle, uint16_t attribute_type, const void *attribute_value, int value_len) { #if !NIMBLE_BLE_ATT_CLT_FIND_TYPE return BLE_HS_ENOTSUP; #endif + struct ble_att_find_type_value_req *req; struct os_mbuf *txom; - int rc; - - txom = NULL; - - if (req->bavq_start_handle == 0 || - req->bavq_start_handle > req->bavq_end_handle) { - - rc = BLE_HS_EINVAL; - goto err; - } - rc = ble_att_clt_init_req(BLE_ATT_FIND_TYPE_VALUE_REQ_BASE_SZ, &txom); - if (rc != 0) { - goto err; + if (start_handle == 0 || start_handle > end_handle) { + return BLE_HS_EINVAL; } - ble_att_find_type_value_req_write(txom->om_data, txom->om_len, req); - rc = os_mbuf_append(txom, attribute_value, value_len); - if (rc != 0) { - rc = BLE_HS_ENOMEM; - goto err; + req = ble_att_cmd_get(BLE_ATT_OP_FIND_INFO_REQ, sizeof(*req) + value_len, + &txom); + if (req == NULL) { + return BLE_HS_ENOMEM; } - rc = ble_att_clt_tx_req(conn_handle, txom); - txom = NULL; - if (rc != 0) { - goto err; - } + req->bavq_start_handle = htole16(start_handle); + req->bavq_end_handle = htole16(end_handle); + req->bavq_attr_type = htole16(attribute_type); + memcpy(req->bavq_value, attribute_value, value_len); BLE_ATT_LOG_CMD(1, "find type value req", conn_handle, ble_att_find_type_value_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/191acab7/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 d1c7d33..80fe713 100644 --- a/net/nimble/host/src/ble_att_cmd_priv.h +++ b/net/nimble/host/src/ble_att_cmd_priv.h @@ -105,6 +105,7 @@ struct ble_att_find_type_value_req { uint16_t bavq_start_handle; uint16_t bavq_end_handle; uint16_t bavq_attr_type; + uint16_t bavq_value[0]; } __attribute__((packed)); /** http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/191acab7/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 86a7b76..a51f7cc 100644 --- a/net/nimble/host/src/ble_att_priv.h +++ b/net/nimble/host/src/ble_att_priv.h @@ -271,9 +271,9 @@ int ble_att_clt_rx_read_group_type(uint16_t conn_handle, int ble_att_clt_tx_find_info(uint16_t conn_handle, uint16_t start_handle, uint16_t end_handle); int ble_att_clt_rx_find_info(uint16_t conn_handle, struct os_mbuf **rxom); -int ble_att_clt_tx_find_type_value( - uint16_t conn_handle, const struct ble_att_find_type_value_req *req, - const void *attribute_value, int value_len); +int ble_att_clt_tx_find_type_value(uint16_t conn_handle, uint16_t start_handle, + uint16_t end_handle, uint16_t attribute_type, + const void *attribute_value, int value_len); int ble_att_clt_rx_find_type_value(uint16_t conn_handle, struct os_mbuf **rxom); int ble_att_clt_tx_write_req(uint16_t conn_handle, http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/191acab7/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 99d2e83..6aa8bb1 100644 --- a/net/nimble/host/src/ble_gattc.c +++ b/net/nimble/host/src/ble_gattc.c @@ -1619,18 +1619,16 @@ ble_gattc_disc_svc_uuid_tmo(struct ble_gattc_proc *proc) static int ble_gattc_disc_svc_uuid_tx(struct ble_gattc_proc *proc) { - struct ble_att_find_type_value_req req; uint8_t val[16]; int rc; ble_gattc_dbg_assert_proc_not_inserted(proc); - req.bavq_start_handle = proc->disc_svc_uuid.prev_handle + 1; - req.bavq_end_handle = 0xffff; - req.bavq_attr_type = BLE_ATT_UUID_PRIMARY_SERVICE; - ble_uuid_flat(&proc->disc_svc_uuid.service_uuid.u, val); - rc = ble_att_clt_tx_find_type_value(proc->conn_handle, &req, val, + rc = ble_att_clt_tx_find_type_value(proc->conn_handle, + proc->disc_svc_uuid.prev_handle + 1, + 0xffff, BLE_ATT_UUID_PRIMARY_SERVICE, + val, ble_uuid_length(&proc->disc_svc_uuid.service_uuid.u)); if (rc != 0) { return rc;
