nimble/att: Use packed struct for receiving Read Blob 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/9c897e5c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/9c897e5c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/9c897e5c

Branch: refs/heads/master
Commit: 9c897e5cc99bfe7adc2857e729bafec41fdccdac
Parents: 3b25076
Author: Szymon Janc <[email protected]>
Authored: Fri Mar 24 15:50:04 2017 +0100
Committer: Szymon Janc <[email protected]>
Committed: Mon Apr 10 11:31:32 2017 +0200

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


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9c897e5c/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 f5d39ce..65f3501 100644
--- a/net/nimble/host/src/ble_att_svr.c
+++ b/net/nimble/host/src/ble_att_svr.c
@@ -1547,43 +1547,46 @@ ble_att_svr_rx_read_blob(uint16_t conn_handle, struct 
os_mbuf **rxom)
     return BLE_HS_ENOTSUP;
 #endif
 
-    struct ble_att_read_blob_req req;
+    struct ble_att_read_blob_req *req;
     struct os_mbuf *txom;
-    uint16_t err_handle;
-    uint8_t *dptr;
+    uint16_t err_handle, offset;
     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;
     err_handle = 0;
 
-    rc = ble_att_svr_pullup_req_base(rxom, BLE_ATT_READ_BLOB_REQ_SZ, &att_err);
+    rc = ble_att_svr_pullup_req_base(rxom, sizeof(*req), &att_err);
     if (rc != 0) {
         goto done;
     }
 
-    ble_att_read_blob_req_parse((*rxom)->om_data, (*rxom)->om_len, &req);
+    req = (struct ble_att_read_blob_req *)(*rxom)->om_data;
     BLE_ATT_LOG_CMD(0, "read blob req", conn_handle, ble_att_read_blob_req_log,
-                    &req);
+                    req);
 
-    err_handle = req.babq_handle;
+    err_handle = le16toh(req->babq_handle);
+    offset = le16toh(req->babq_offset);
 
     /* Just reuse the request buffer for the response. */
     txom = *rxom;
     *rxom = NULL;
     os_mbuf_adj(txom, OS_MBUF_PKTLEN(txom));
 
-    dptr = os_mbuf_extend(txom, 1);
-    if (dptr == NULL) {
+    if (ble_att_cmd_prepare(BLE_ATT_OP_READ_BLOB_RSP, 0, txom) == NULL) {
         att_err = BLE_ATT_ERR_INSUFFICIENT_RES;
         rc = BLE_HS_ENOMEM;
         goto done;
     }
-    *dptr = BLE_ATT_OP_READ_BLOB_RSP;
 
-    rc = ble_att_svr_read_handle(conn_handle, req.babq_handle, req.babq_offset,
+    rc = ble_att_svr_read_handle(conn_handle, err_handle, offset,
                                  txom, &att_err);
     if (rc != 0) {
         goto done;

Reply via email to