nimble/att: Use packed struct for receiving Read Request Use packed structure to map it to received mbuf instead of using dedicated parsing function. Modern compilers generate effective code in such case anyway.
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/3b250764 Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/3b250764 Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/3b250764 Branch: refs/heads/master Commit: 3b2507644e34a87016fce639416ea47302169ae2 Parents: c3cca42 Author: Szymon Janc <[email protected]> Authored: Fri Mar 24 15:50:04 2017 +0100 Committer: Szymon Janc <[email protected]> Committed: Mon Apr 10 11:31:32 2017 +0200 ---------------------------------------------------------------------- net/nimble/host/src/ble_att_svr.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3b250764/net/nimble/host/src/ble_att_svr.c ---------------------------------------------------------------------- diff --git a/net/nimble/host/src/ble_att_svr.c b/net/nimble/host/src/ble_att_svr.c index fffb9dd..f5d39ce 100644 --- a/net/nimble/host/src/ble_att_svr.c +++ b/net/nimble/host/src/ble_att_svr.c @@ -1492,43 +1492,44 @@ ble_att_svr_rx_read(uint16_t conn_handle, struct os_mbuf **rxom) return BLE_HS_ENOTSUP; #endif - struct ble_att_read_req req; + struct ble_att_read_req *req; struct os_mbuf *txom; uint16_t err_handle; uint8_t att_err; - uint8_t *dptr; int rc; + /* TODO move this to common part + * Strip L2CAP ATT header from the front of the mbuf. + */ + os_mbuf_adj(*rxom, 1); + /* Initialize some values in case of early error. */ txom = NULL; att_err = 0; err_handle = 0; - rc = ble_att_svr_pullup_req_base(rxom, BLE_ATT_READ_REQ_SZ, &att_err); + rc = ble_att_svr_pullup_req_base(rxom, sizeof(*req), &att_err); if (rc != 0) { goto done; } - ble_att_read_req_parse((*rxom)->om_data, (*rxom)->om_len, &req); - BLE_ATT_LOG_CMD(0, "read req", conn_handle, ble_att_read_req_log, &req); + req = (struct ble_att_read_req *)(*rxom)->om_data; + BLE_ATT_LOG_CMD(0, "read req", conn_handle, ble_att_read_req_log, req); - err_handle = req.barq_handle; + err_handle = le16toh(req->barq_handle); /* Just reuse the request buffer for the response. */ txom = *rxom; *rxom = NULL; os_mbuf_adj(txom, OS_MBUF_PKTLEN(txom)); - dptr = os_mbuf_extend(txom, 1); - if (dptr == NULL) { + if (ble_att_cmd_prepare(BLE_ATT_OP_READ_RSP, 0, txom) == NULL) { att_err = BLE_ATT_ERR_INSUFFICIENT_RES; rc = BLE_HS_ENOMEM; goto done; } - *dptr = BLE_ATT_OP_READ_RSP; - rc = ble_att_svr_read_handle(conn_handle, req.barq_handle, 0, txom, - &att_err); + rc = ble_att_svr_read_handle(conn_handle, err_handle, 0, txom, &att_err); if (rc != 0) { goto done; }
