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:39 UTC

[47/50] incubator-mynewt-core git commit: nimble/att: Use packed struct for receiving Notification

nimble/att: Use packed struct for receiving Notification

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/7ea6ad88
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/7ea6ad88
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/7ea6ad88

Branch: refs/heads/master
Commit: 7ea6ad8838ffd9b99989eddd5c4317938ce4ae69
Parents: f495fa7
Author: Szymon Janc <sz...@codecoup.pl>
Authored: Fri Mar 24 15:50:06 2017 +0100
Committer: Szymon Janc <sz...@codecoup.pl>
Committed: Mon Apr 10 11:31:33 2017 +0200

----------------------------------------------------------------------
 net/nimble/host/src/ble_att_svr.c | 25 +++++++++++++++----------
 1 file changed, 15 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7ea6ad88/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 11877cb..b6da4df 100644
--- a/net/nimble/host/src/ble_att_svr.c
+++ b/net/nimble/host/src/ble_att_svr.c
@@ -2590,30 +2590,35 @@ ble_att_svr_rx_notify(uint16_t conn_handle, struct os_mbuf **rxom)
     return BLE_HS_ENOTSUP;
 #endif
 
-    struct ble_att_notify_req req;
+    struct ble_att_notify_req *req;
+    uint16_t handle;
     int rc;
 
-    if (OS_MBUF_PKTLEN(*rxom) < BLE_ATT_NOTIFY_REQ_BASE_SZ) {
-        return BLE_HS_EBADDATA;
-    }
+    /* 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, BLE_ATT_NOTIFY_REQ_BASE_SZ, NULL);
+    rc = ble_att_svr_pullup_req_base(rxom, sizeof(*req), NULL);
     if (rc != 0) {
         return BLE_HS_ENOMEM;
     }
 
-    ble_att_notify_req_parse((*rxom)->om_data, (*rxom)->om_len, &req);
+    req = (struct ble_att_notify_req *)(*rxom)->om_data;
+
     BLE_ATT_LOG_CMD(0, "notify req", conn_handle,
-                    ble_att_notify_req_log, &req);
+                    ble_att_notify_req_log, req);
 
-    if (req.banq_handle == 0) {
+    handle = le16toh(req->banq_handle);
+
+    if (handle == 0) {
         return BLE_HS_EBADDATA;
     }
 
     /* Strip the request base from the front of the mbuf. */
-    os_mbuf_adj(*rxom, BLE_ATT_NOTIFY_REQ_BASE_SZ);
+    os_mbuf_adj(*rxom, sizeof(*req));
 
-    ble_gap_notify_rx_event(conn_handle, req.banq_handle, *rxom, 0);
+    ble_gap_notify_rx_event(conn_handle, handle, *rxom, 0);
     *rxom = NULL;
 
     return 0;