You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by an...@apache.org on 2017/04/10 11:47:16 UTC

[24/50] incubator-mynewt-core git commit: nimble/att: Use packed struct for receiving Find By Type Response

nimble/att: Use packed struct for receiving Find By Type 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/1e816573
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/1e816573
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/1e816573

Branch: refs/heads/master
Commit: 1e81657393641c3cccbc4fda600104bc7777f28e
Parents: f0949b9
Author: Szymon Janc <sz...@codecoup.pl>
Authored: Fri Mar 24 15:49:19 2017 +0100
Committer: Szymon Janc <sz...@codecoup.pl>
Committed: Mon Apr 10 11:31:32 2017 +0200

----------------------------------------------------------------------
 net/nimble/host/src/ble_att_clt.c      | 19 +++++++++++--------
 net/nimble/host/src/ble_att_cmd_priv.h |  9 +++++++++
 2 files changed, 20 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1e816573/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 4644b35..f3a084c 100644
--- a/net/nimble/host/src/ble_att_clt.c
+++ b/net/nimble/host/src/ble_att_clt.c
@@ -331,15 +331,20 @@ static int
 ble_att_clt_parse_find_type_value_hinfo(
     struct os_mbuf **om, struct ble_att_find_type_value_hinfo *dst)
 {
+    struct ble_att_handle_group *group;
     int rc;
 
-    rc = os_mbuf_copydata(*om, 0, BLE_ATT_FIND_TYPE_VALUE_HINFO_BASE_SZ, dst);
+    rc = ble_hs_mbuf_pullup_base(om, sizeof(*group));
     if (rc != 0) {
         return BLE_HS_EBADDATA;
     }
 
-    dst->attr_handle = TOFROMLE16(dst->attr_handle);
-    dst->group_end_handle = TOFROMLE16(dst->group_end_handle);
+    group = (struct ble_att_handle_group *)(*om)->om_data;
+
+    dst->attr_handle = le16toh(group->attr_handle);
+    dst->group_end_handle = le16toh(group->group_end_handle);
+
+    os_mbuf_adj((*om), sizeof(*group));
 
     return 0;
 }
@@ -356,11 +361,10 @@ 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);
 
-    /* Reponse consists of a one-byte opcode (already verified) and a variable
-     * length Handles-Information-List field.  Strip the opcode from the
-     * response.
+    /* TODO move this to common part
+     * Strip L2CAP ATT header from the front of the mbuf.
      */
-    os_mbuf_adj(*rxom, BLE_ATT_FIND_TYPE_VALUE_RSP_BASE_SZ);
+    os_mbuf_adj(*rxom, 1);
 
     /* Parse the Handles-Information-List field, passing each entry to GATT. */
     rc = 0;
@@ -371,7 +375,6 @@ ble_att_clt_rx_find_type_value(uint16_t conn_handle, struct os_mbuf **rxom)
         }
 
         ble_gattc_rx_find_type_value_hinfo(conn_handle, &hinfo);
-        os_mbuf_adj(*rxom, BLE_ATT_FIND_TYPE_VALUE_HINFO_BASE_SZ);
     }
 
     /* Notify GATT client that the full response has been parsed. */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1e816573/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 3e03cca..4a7e491 100644
--- a/net/nimble/host/src/ble_att_cmd_priv.h
+++ b/net/nimble/host/src/ble_att_cmd_priv.h
@@ -117,6 +117,15 @@ struct ble_att_find_type_value_req {
 #define BLE_ATT_FIND_TYPE_VALUE_RSP_BASE_SZ     1
 #define BLE_ATT_FIND_TYPE_VALUE_HINFO_BASE_SZ   4
 
+struct ble_att_handle_group {
+        uint16_t attr_handle;
+        uint16_t group_end_handle;
+} __attribute__((packed));
+
+struct ble_att_find_type_value_rsp {
+    struct ble_att_handle_group list[0];
+} __attribute__((packed));
+
 /**
  * | Parameter                          | Size (octets)     |
  * +------------------------------------+-------------------+