nimble/att: Use packed struct for receiving Prepare Write Response 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/2b2c14e7 Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/2b2c14e7 Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/2b2c14e7 Branch: refs/heads/master Commit: 2b2c14e71f9308014c2c13f58681c1c4f2a9586c Parents: 3a3571e Author: Szymon Janc <[email protected]> Authored: Fri Mar 24 15:50:06 2017 +0100 Committer: Szymon Janc <[email protected]> Committed: Mon Apr 10 11:31:33 2017 +0200 ---------------------------------------------------------------------- net/nimble/host/src/ble_att_clt.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2b2c14e7/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 6e91079..2666eb2 100644 --- a/net/nimble/host/src/ble_att_clt.c +++ b/net/nimble/host/src/ble_att_clt.c @@ -897,28 +897,37 @@ ble_att_clt_rx_prep_write(uint16_t conn_handle, struct os_mbuf **rxom) return BLE_HS_ENOTSUP; #endif - struct ble_att_prep_write_cmd rsp; + struct ble_att_prep_write_cmd *rsp; + uint16_t handle, offset; 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. */ - memset(&rsp, 0, sizeof rsp); + handle = 0; + offset = 0; - rc = ble_hs_mbuf_pullup_base(rxom, BLE_ATT_PREP_WRITE_CMD_BASE_SZ); + rc = ble_hs_mbuf_pullup_base(rxom, sizeof(*rsp)); if (rc != 0) { goto done; } - ble_att_prep_write_rsp_parse((*rxom)->om_data, (*rxom)->om_len, &rsp); + rsp = (struct ble_att_prep_write_cmd *)(*rxom)->om_data; BLE_ATT_LOG_CMD(0, "prep write rsp", conn_handle, - ble_att_prep_write_cmd_log, &rsp); + ble_att_prep_write_cmd_log, rsp); + + handle = le16toh(rsp->bapc_handle); + offset = le16toh(rsp->bapc_offset); /* Strip the base from the front of the response. */ - os_mbuf_adj(*rxom, BLE_ATT_PREP_WRITE_CMD_BASE_SZ); + os_mbuf_adj(*rxom, sizeof(*rsp)); done: /* Notify GATT client that the full response has been parsed. */ - ble_gattc_rx_prep_write_rsp(conn_handle, rc, rsp.bapc_handle, - rsp.bapc_offset, rxom); + ble_gattc_rx_prep_write_rsp(conn_handle, rc, handle, offset, rxom); return rc; }
