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

[42/50] incubator-mynewt-core git commit: nimble/att: Use packed struct for receiving Execute Write Request

nimble/att: Use packed struct for receiving Execute Write Request

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

Branch: refs/heads/master
Commit: ca16b6bc33e35418d2e0aa80cd57d5b918d6e1c8
Parents: 2b2c14e
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 | 64 ++++++++++++----------------------
 1 file changed, 22 insertions(+), 42 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ca16b6bc/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 93d6cef..11877cb 100644
--- a/net/nimble/host/src/ble_att_svr.c
+++ b/net/nimble/host/src/ble_att_svr.c
@@ -2502,38 +2502,6 @@ done:
     return rc;
 }
 
-/**
- * @return                      0 on success; nonzero on failure.
- */
-static int
-ble_att_svr_build_exec_write_rsp(struct os_mbuf **rxom,
-                                 struct os_mbuf **out_txom, uint8_t *att_err)
-{
-    struct os_mbuf *txom;
-    uint8_t *dst;
-    int rc;
-
-    /* Just reuse the request buffer for the response. */
-    txom = *rxom;
-    *rxom = NULL;
-    os_mbuf_adj(txom, OS_MBUF_PKTLEN(txom));
-
-    dst = os_mbuf_extend(txom, BLE_ATT_EXEC_WRITE_RSP_SZ);
-    if (dst == NULL) {
-        *att_err = BLE_ATT_ERR_INSUFFICIENT_RES;
-        rc = BLE_HS_ENOMEM;
-        goto done;
-    }
-
-    ble_att_exec_write_rsp_write(dst, BLE_ATT_EXEC_WRITE_RSP_SZ);
-
-    rc = 0;
-
-done:
-    *out_txom = txom;
-    return rc;
-}
-
 int
 ble_att_svr_rx_exec_write(uint16_t conn_handle, struct os_mbuf **rxom)
 {
@@ -2542,30 +2510,42 @@ ble_att_svr_rx_exec_write(uint16_t conn_handle, struct os_mbuf **rxom)
 #endif
 
     struct ble_att_prep_entry_list prep_list;
-    struct ble_att_exec_write_req req;
+    struct ble_att_exec_write_req *req;
     struct ble_hs_conn *conn;
     struct os_mbuf *txom;
     uint16_t err_handle;
     uint8_t att_err;
+    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;
 
-    rc = ble_att_svr_pullup_req_base(rxom, BLE_ATT_EXEC_WRITE_REQ_SZ,
-                                     &att_err);
+    rc = ble_att_svr_pullup_req_base(rxom, sizeof(*req), &att_err);
     if (rc != 0) {
-        err_handle = 0;
         goto done;
     }
 
-    ble_att_exec_write_req_parse((*rxom)->om_data, (*rxom)->om_len, &req);
+    req = (struct ble_att_exec_write_req *)(*rxom)->om_data;
     BLE_ATT_LOG_CMD(0, "exec write req", conn_handle,
-                    ble_att_exec_write_req_log, &req);
+                    ble_att_exec_write_req_log, req);
 
-    rc = ble_att_svr_build_exec_write_rsp(rxom, &txom, &att_err);
-    if (rc != 0) {
-        err_handle = 0;
+    flags = req->baeq_flags;
+
+    /* Just reuse the request buffer for the response. */
+    txom = *rxom;
+    *rxom = NULL;
+    os_mbuf_adj(txom, OS_MBUF_PKTLEN(txom));
+
+    if (ble_att_cmd_prepare(BLE_ATT_OP_EXEC_WRITE_RSP, 0, txom) == NULL) {
+        att_err = BLE_ATT_ERR_INSUFFICIENT_RES;
+        rc = BLE_HS_ENOMEM;
         goto done;
     }
 
@@ -2585,7 +2565,7 @@ done:
         SLIST_INIT(&conn->bhc_att_svr.basc_prep_list);
         ble_hs_unlock();
 
-        if (req.baeq_flags) {
+        if (flags) {
             /* Perform attribute writes. */
             att_err = ble_att_svr_prep_write(conn_handle, &prep_list,
                                              &err_handle);