nimble/att: Use packed struct for receiving Indication 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/255debf8 Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/255debf8 Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/255debf8 Branch: refs/heads/master Commit: 255debf84dfea8ff0beb2f7e4729ee09c0226c90 Parents: 7ea6ad8 Author: Szymon Janc <[email protected]> Authored: Fri Mar 24 15:50:07 2017 +0100 Committer: Szymon Janc <[email protected]> Committed: Mon Apr 10 11:31:33 2017 +0200 ---------------------------------------------------------------------- net/nimble/host/src/ble_att_svr.c | 39 ++++++++++++++++------------------ 1 file changed, 18 insertions(+), 21 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/255debf8/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 b6da4df..23599a8 100644 --- a/net/nimble/host/src/ble_att_svr.c +++ b/net/nimble/host/src/ble_att_svr.c @@ -2632,7 +2632,6 @@ ble_att_svr_build_indicate_rsp(struct os_mbuf **rxom, struct os_mbuf **out_txom, uint8_t *out_att_err) { struct os_mbuf *txom; - uint8_t *dst; int rc; /* Allocate a new buffer for the response. An indicate response never @@ -2644,15 +2643,12 @@ ble_att_svr_build_indicate_rsp(struct os_mbuf **rxom, goto done; } - dst = os_mbuf_extend(txom, BLE_ATT_INDICATE_RSP_SZ); - if (dst == NULL) { + if (ble_att_cmd_prepare(BLE_ATT_OP_INDICATE_RSP, 0, txom) == NULL) { rc = BLE_HS_ENOMEM; *out_att_err = BLE_ATT_ERR_INSUFFICIENT_RES; goto done; } - ble_att_indicate_rsp_write(dst, BLE_ATT_INDICATE_RSP_SZ); - rc = 0; done: @@ -2667,33 +2663,34 @@ ble_att_svr_rx_indicate(uint16_t conn_handle, struct os_mbuf **rxom) return BLE_HS_ENOTSUP; #endif - struct ble_att_indicate_req req; + struct ble_att_indicate_req *req; struct os_mbuf *txom; - uint16_t err_handle; + uint16_t handle; uint8_t att_err; 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; - - if (OS_MBUF_PKTLEN(*rxom) < BLE_ATT_INDICATE_REQ_BASE_SZ) { - rc = BLE_HS_EBADDATA; - goto done; - } + handle = 0; - rc = ble_att_svr_pullup_req_base(rxom, BLE_ATT_INDICATE_REQ_BASE_SZ, NULL); + rc = ble_att_svr_pullup_req_base(rxom, sizeof(*req), NULL); if (rc != 0) { goto done; } - ble_att_indicate_req_parse((*rxom)->om_data, (*rxom)->om_len, &req); + req = (struct ble_att_indicate_req *)(*rxom)->om_data; BLE_ATT_LOG_CMD(0, "indicate req", conn_handle, - ble_att_indicate_req_log, &req); - err_handle = req.baiq_handle; + ble_att_indicate_req_log, req); - if (req.baiq_handle == 0) { + handle = le16toh(req->baiq_handle); + + if (handle == 0) { rc = BLE_HS_EBADDATA; goto done; } @@ -2707,9 +2704,9 @@ ble_att_svr_rx_indicate(uint16_t conn_handle, struct os_mbuf **rxom) } /* Strip the request base from the front of the mbuf. */ - os_mbuf_adj(*rxom, BLE_ATT_INDICATE_REQ_BASE_SZ); + os_mbuf_adj(*rxom, sizeof(*req)); - ble_gap_notify_rx_event(conn_handle, req.baiq_handle, *rxom, 1); + ble_gap_notify_rx_event(conn_handle, handle, *rxom, 1); *rxom = NULL; BLE_ATT_LOG_EMPTY_CMD(1, "indicate rsp", conn_handle); @@ -2718,7 +2715,7 @@ ble_att_svr_rx_indicate(uint16_t conn_handle, struct os_mbuf **rxom) done: rc = ble_att_svr_tx_rsp(conn_handle, rc, txom, BLE_ATT_OP_INDICATE_REQ, - att_err, err_handle); + att_err, handle); return rc; }
