nimble/att: Strip common ATT header before passing buf to handlers This reduce code size and move common part in single place.
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/d458bb8c Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/d458bb8c Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/d458bb8c Branch: refs/heads/master Commit: d458bb8c3b6ea61ed6b05b1465bc876dc070b3bb Parents: 3876f10 Author: Szymon Janc <szymon.j...@codecoup.pl> Authored: Fri Mar 24 15:50:08 2017 +0100 Committer: Szymon Janc <szymon.j...@codecoup.pl> Committed: Mon Apr 10 11:31:33 2017 +0200 ---------------------------------------------------------------------- net/nimble/host/src/ble_att.c | 3 ++ net/nimble/host/src/ble_att_clt.c | 55 -------------------------- net/nimble/host/src/ble_att_svr.c | 70 ---------------------------------- 3 files changed, 3 insertions(+), 125 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d458bb8c/net/nimble/host/src/ble_att.c ---------------------------------------------------------------------- diff --git a/net/nimble/host/src/ble_att.c b/net/nimble/host/src/ble_att.c index 1756fc8..034c71d 100644 --- a/net/nimble/host/src/ble_att.c +++ b/net/nimble/host/src/ble_att.c @@ -490,6 +490,9 @@ ble_att_rx(struct ble_l2cap_chan *chan) ble_att_inc_rx_stat(op); + /* Strip L2CAP ATT header from the front of the mbuf. */ + os_mbuf_adj(*om, 1); + rc = entry->bde_fn(conn_handle, om); if (rc != 0) { return rc; http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d458bb8c/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 4a04e70..9ff9b53 100644 --- a/net/nimble/host/src/ble_att_clt.c +++ b/net/nimble/host/src/ble_att_clt.c @@ -36,11 +36,6 @@ ble_att_clt_rx_error(uint16_t conn_handle, struct os_mbuf **rxom) struct ble_att_error_rsp *rsp; int rc; - /* TODO move this to common part - * Strip L2CAP ATT header from the front of the mbuf. - */ - os_mbuf_adj(*rxom, 1); - rc = ble_hs_mbuf_pullup_base(rxom, sizeof(*rsp)); if (rc != 0) { return rc; @@ -123,11 +118,6 @@ ble_att_clt_rx_mtu(uint16_t conn_handle, struct os_mbuf **rxom) uint16_t mtu; int rc; - /* TODO move this to common part - * Strip L2CAP ATT header from the front of the mbuf. - */ - os_mbuf_adj(*rxom, 1); - mtu = 0; rc = ble_hs_mbuf_pullup_base(rxom, sizeof(*cmd)); @@ -250,11 +240,6 @@ ble_att_clt_rx_find_info(uint16_t conn_handle, struct os_mbuf **om) struct ble_att_find_info_rsp *rsp; int rc; - /* TODO move this to common part - * Strip L2CAP ATT header from the front of the mbuf. - */ - os_mbuf_adj(*om, 1); - rc = ble_hs_mbuf_pullup_base(om, sizeof(*rsp)); if (rc != 0) { goto done; @@ -361,11 +346,6 @@ ble_att_clt_rx_find_type_value(uint16_t conn_handle, struct os_mbuf **rxom) BLE_ATT_LOG_EMPTY_CMD(0, "find type value rsp", conn_handle); - /* TODO move this to common part - * Strip L2CAP ATT header from the front of the mbuf. - */ - os_mbuf_adj(*rxom, 1); - /* Parse the Handles-Information-List field, passing each entry to GATT. */ rc = 0; while (OS_MBUF_PKTLEN(*rxom) > 0) { @@ -432,11 +412,6 @@ ble_att_clt_rx_read_type(uint16_t conn_handle, struct os_mbuf **rxom) uint8_t data_len; int rc; - /* TODO move this to common part - * Strip L2CAP ATT header from the front of the mbuf. - */ - os_mbuf_adj(*rxom, 1); - rc = ble_hs_mbuf_pullup_base(rxom, sizeof(*rsp)); if (rc != 0) { goto done; @@ -526,11 +501,6 @@ ble_att_clt_rx_read(uint16_t conn_handle, struct os_mbuf **rxom) BLE_ATT_LOG_EMPTY_CMD(0, "read rsp", conn_handle); - /* Reponse consists of a one-byte opcode (already verified) and a variable - * length Attribute Value field. Strip the opcode from the response. - */ - os_mbuf_adj(*rxom, BLE_ATT_READ_RSP_BASE_SZ); - /* Pass the Attribute Value field to GATT. */ ble_gattc_rx_read_rsp(conn_handle, 0, rxom); return 0; @@ -583,11 +553,6 @@ ble_att_clt_rx_read_blob(uint16_t conn_handle, struct os_mbuf **rxom) BLE_ATT_LOG_EMPTY_CMD(0, "read blob rsp", conn_handle); - /* TODO move this to common part - * Strip L2CAP ATT header from the front of the mbuf. - */ - os_mbuf_adj(*rxom, 1); - /* Pass the Attribute Value field to GATT. */ ble_gattc_rx_read_blob_rsp(conn_handle, 0, rxom); return 0; @@ -637,11 +602,6 @@ ble_att_clt_rx_read_mult(uint16_t conn_handle, struct os_mbuf **rxom) BLE_ATT_LOG_EMPTY_CMD(0, "read mult rsp", conn_handle); - /* TODO move this to common part - * Strip L2CAP ATT header from the front of the mbuf. - */ - os_mbuf_adj(*rxom, 1); - /* Pass the Attribute Value field to GATT. */ ble_gattc_rx_read_mult_rsp(conn_handle, 0, rxom); return 0; @@ -719,11 +679,6 @@ ble_att_clt_rx_read_group_type(uint16_t conn_handle, struct os_mbuf **rxom) uint8_t len; int rc; - /* TODO move this to common part - * Strip L2CAP ATT header from the front of the mbuf. - */ - os_mbuf_adj(*rxom, 1); - rc = ble_hs_mbuf_pullup_base(rxom, sizeof(*rsp)); if (rc != 0) { goto done; @@ -901,11 +856,6 @@ ble_att_clt_rx_prep_write(uint16_t conn_handle, struct os_mbuf **rxom) 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. */ handle = 0; offset = 0; @@ -971,11 +921,6 @@ ble_att_clt_rx_exec_write(uint16_t conn_handle, struct os_mbuf **rxom) return BLE_HS_ENOTSUP; #endif - /* TODO move this to common part - * Strip L2CAP ATT header from the front of the mbuf. - */ - os_mbuf_adj(*rxom, 1); - BLE_ATT_LOG_EMPTY_CMD(0, "exec write rsp", conn_handle); ble_gattc_rx_exec_write_rsp(conn_handle, 0); http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d458bb8c/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 8c9a6cb..234aac6 100644 --- a/net/nimble/host/src/ble_att_svr.c +++ b/net/nimble/host/src/ble_att_svr.c @@ -733,11 +733,6 @@ ble_att_svr_rx_mtu(uint16_t conn_handle, struct os_mbuf **rxom) 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); - txom = NULL; mtu = 0; @@ -924,11 +919,6 @@ ble_att_svr_rx_find_info(uint16_t conn_handle, struct os_mbuf **rxom) 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; @@ -1243,11 +1233,6 @@ ble_att_svr_rx_find_type_value(uint16_t conn_handle, struct os_mbuf **rxom) 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; @@ -1424,11 +1409,6 @@ ble_att_svr_rx_read_type(uint16_t conn_handle, struct os_mbuf **rxom) 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; @@ -1498,11 +1478,6 @@ ble_att_svr_rx_read(uint16_t conn_handle, struct os_mbuf **rxom) 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; @@ -1553,11 +1528,6 @@ ble_att_svr_rx_read_blob(uint16_t conn_handle, struct os_mbuf **rxom) 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; @@ -1676,11 +1646,6 @@ ble_att_svr_rx_read_mult(uint16_t conn_handle, struct os_mbuf **rxom) 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); - BLE_ATT_LOG_EMPTY_CMD(0, "read mult req", conn_handle); /* Initialize some values in case of early error. */ @@ -1943,11 +1908,6 @@ ble_att_svr_rx_read_group_type(uint16_t conn_handle, struct os_mbuf **rxom) int om_uuid_len; 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; @@ -2054,11 +2014,6 @@ ble_att_svr_rx_write(uint16_t conn_handle, struct os_mbuf **rxom) 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; @@ -2114,11 +2069,6 @@ ble_att_svr_rx_write_no_rsp(uint16_t conn_handle, struct os_mbuf **rxom) uint16_t handle; int rc; - /* TODO move this to common part - * Strip L2CAP ATT header from the front of the mbuf. - */ - os_mbuf_adj(*rxom, 1); - rc = ble_att_svr_pullup_req_base(rxom, sizeof(*req), &att_err); if (rc != 0) { return rc; @@ -2424,11 +2374,6 @@ ble_att_svr_rx_prep_write(uint16_t conn_handle, struct os_mbuf **rxom) 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; @@ -2519,11 +2464,6 @@ ble_att_svr_rx_exec_write(uint16_t conn_handle, struct os_mbuf **rxom) uint8_t flags; 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; err_handle = 0; @@ -2595,11 +2535,6 @@ ble_att_svr_rx_notify(uint16_t conn_handle, struct os_mbuf **rxom) uint16_t handle; int rc; - /* TODO move this to common part - * Strip L2CAP ATT header from the front of the mbuf. - */ - os_mbuf_adj(*rxom, 1); - rc = ble_att_svr_pullup_req_base(rxom, sizeof(*req), NULL); if (rc != 0) { return BLE_HS_ENOMEM; @@ -2670,11 +2605,6 @@ ble_att_svr_rx_indicate(uint16_t conn_handle, struct os_mbuf **rxom) 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;