nimble/att: Use new helpers for sending Read Blob Request

This constructs response directly on mbuf reducing number of memcopies.


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

Branch: refs/heads/master
Commit: 090f62b725b2713cb4dd9013ff7f4f3fa413a2cc
Parents: 58743be
Author: Szymon Janc <[email protected]>
Authored: Fri Mar 24 15:28:38 2017 +0100
Committer: Szymon Janc <[email protected]>
Committed: Mon Apr 10 11:31:31 2017 +0200

----------------------------------------------------------------------
 net/nimble/host/src/ble_att_clt.c           | 18 ++++++++++--------
 net/nimble/host/src/ble_att_priv.h          |  4 ++--
 net/nimble/host/src/ble_gattc.c             |  7 +++----
 net/nimble/host/test/src/ble_att_clt_test.c |  9 ++-------
 4 files changed, 17 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/090f62b7/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 fc5a432..e85beac 100644
--- a/net/nimble/host/src/ble_att_clt.c
+++ b/net/nimble/host/src/ble_att_clt.c
@@ -612,27 +612,29 @@ ble_att_clt_rx_read(uint16_t conn_handle, struct os_mbuf 
**rxom)
  *****************************************************************************/
 
 int
-ble_att_clt_tx_read_blob(uint16_t conn_handle,
-                         const struct ble_att_read_blob_req *req)
+ble_att_clt_tx_read_blob(uint16_t conn_handle, uint16_t handle, uint16_t 
offset)
 {
 #if !NIMBLE_BLE_ATT_CLT_READ_BLOB
     return BLE_HS_ENOTSUP;
 #endif
 
+    struct ble_att_read_blob_req *req;
     struct os_mbuf *txom;
     int rc;
 
-    if (req->babq_handle == 0) {
+    if (handle == 0) {
         return BLE_HS_EINVAL;
     }
 
-    rc = ble_att_clt_init_req(BLE_ATT_READ_BLOB_REQ_SZ, &txom);
-    if (rc != 0) {
-        return rc;
+    req = ble_att_cmd_get(BLE_ATT_OP_READ_BLOB_REQ, sizeof(*req), &txom);
+    if (req == NULL) {
+        return BLE_HS_ENOMEM;
     }
-    ble_att_read_blob_req_write(txom->om_data, txom->om_len, req);
 
-    rc = ble_att_clt_tx_req(conn_handle, txom);
+    req->babq_handle = htole16(handle);
+    req->babq_offset = htole16(offset);
+
+    rc = ble_att_tx(conn_handle, txom);
     if (rc != 0) {
         return rc;
     }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/090f62b7/net/nimble/host/src/ble_att_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att_priv.h 
b/net/nimble/host/src/ble_att_priv.h
index 85da2de..62bebf9 100644
--- a/net/nimble/host/src/ble_att_priv.h
+++ b/net/nimble/host/src/ble_att_priv.h
@@ -254,8 +254,8 @@ int ble_att_clt_tx_mtu(uint16_t conn_handle, uint16_t mtu);
 int ble_att_clt_rx_mtu(uint16_t conn_handle, struct os_mbuf **rxom);
 int ble_att_clt_tx_read(uint16_t conn_handle, uint16_t handle);
 int ble_att_clt_rx_read(uint16_t conn_handle, struct os_mbuf **rxom);
-int ble_att_clt_tx_read_blob(uint16_t conn_handle,
-                             const struct ble_att_read_blob_req *req);
+int ble_att_clt_tx_read_blob(uint16_t conn_handle, uint16_t handle,
+                             uint16_t offset);
 int ble_att_clt_rx_read_blob(uint16_t conn_handle, struct os_mbuf **rxom);
 int ble_att_clt_tx_read_mult(uint16_t conn_handle,
                              const uint16_t *handles, int num_handles);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/090f62b7/net/nimble/host/src/ble_gattc.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gattc.c b/net/nimble/host/src/ble_gattc.c
index ba84727..85866b5 100644
--- a/net/nimble/host/src/ble_gattc.c
+++ b/net/nimble/host/src/ble_gattc.c
@@ -3252,7 +3252,6 @@ ble_gattc_read_long_tmo(struct ble_gattc_proc *proc)
 static int
 ble_gattc_read_long_tx(struct ble_gattc_proc *proc)
 {
-    struct ble_att_read_blob_req blob_req;
     int rc;
 
     ble_gattc_dbg_assert_proc_not_inserted(proc);
@@ -3263,9 +3262,9 @@ ble_gattc_read_long_tx(struct ble_gattc_proc *proc)
             return rc;
         }
     } else {
-        blob_req.babq_handle = proc->read_long.handle;
-        blob_req.babq_offset = proc->read_long.offset;
-        rc = ble_att_clt_tx_read_blob(proc->conn_handle, &blob_req);
+        rc = ble_att_clt_tx_read_blob(proc->conn_handle,
+                                      proc->read_long.handle,
+                                      proc->read_long.offset);
         if (rc != 0) {
             return rc;
         }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/090f62b7/net/nimble/host/test/src/ble_att_clt_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/test/src/ble_att_clt_test.c 
b/net/nimble/host/test/src/ble_att_clt_test.c
index 3d12ee8..afd7c41 100644
--- a/net/nimble/host/test/src/ble_att_clt_test.c
+++ b/net/nimble/host/test/src/ble_att_clt_test.c
@@ -339,22 +339,17 @@ TEST_CASE(ble_att_clt_test_rx_read)
 
 TEST_CASE(ble_att_clt_test_tx_read_blob)
 {
-    struct ble_att_read_blob_req req;
     uint16_t conn_handle;
     int rc;
 
     conn_handle = ble_att_clt_test_misc_init();
 
     /*** Success. */
-    req.babq_handle = 1;
-    req.babq_offset = 0;
-    rc = ble_att_clt_tx_read_blob(conn_handle, &req);
+    rc = ble_att_clt_tx_read_blob(conn_handle, 1, 0);
     TEST_ASSERT(rc == 0);
 
     /*** Error: handle of 0. */
-    req.babq_handle = 0;
-    req.babq_offset = 0;
-    rc = ble_att_clt_tx_read_blob(conn_handle, &req);
+    rc = ble_att_clt_tx_read_blob(conn_handle, 0, 0);
     TEST_ASSERT(rc == BLE_HS_EINVAL);
 }
 

Reply via email to