nimble/att: Use new helpers for sending Indication

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

Branch: refs/heads/master
Commit: 8dbabc6e1ee9dbc9f0fa116815a7ec5ad9f3f391
Parents: 504e0e1
Author: Szymon Janc <[email protected]>
Authored: Fri Mar 24 15:35:42 2017 +0100
Committer: Szymon Janc <[email protected]>
Committed: Mon Apr 10 11:31:31 2017 +0200

----------------------------------------------------------------------
 net/nimble/host/src/ble_att_clt.c  | 53 ++++++---------------------------
 net/nimble/host/src/ble_att_priv.h |  3 +-
 net/nimble/host/src/ble_gattc.c    |  4 +--
 3 files changed, 11 insertions(+), 49 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8dbabc6e/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 d8d5d1c..76d61eb 100644
--- a/net/nimble/host/src/ble_att_clt.c
+++ b/net/nimble/host/src/ble_att_clt.c
@@ -26,36 +26,6 @@
 #include "host/ble_uuid.h"
 #include "ble_hs_priv.h"
 
-static int
-ble_att_clt_tx_req(uint16_t conn_handle, struct os_mbuf *txom)
-{
-    struct ble_l2cap_chan *chan;
-    struct ble_hs_conn *conn;
-    int rc;
-
-    BLE_HS_DBG_ASSERT_EVAL(txom->om_len >= 1);
-    ble_att_inc_tx_stat(txom->om_data[0]);
-
-    ble_hs_lock();
-
-    rc = ble_att_conn_chan_find(conn_handle, &conn, &chan);
-    if (rc != 0) {
-        rc = BLE_HS_ENOTCONN;
-    } else {
-        ble_att_truncate_to_mtu(chan, txom);
-        rc = ble_l2cap_tx(conn, chan, txom);
-        txom = NULL;
-    }
-
-    ble_hs_unlock();
-
-    if (rc != 0) {
-        os_mbuf_free_chain(txom);
-    }
-
-    return rc;
-}
-
 /*****************************************************************************
  * $error response                                                           *
  *****************************************************************************/
@@ -1015,40 +985,35 @@ err:
  *****************************************************************************/
 
 int
-ble_att_clt_tx_indicate(uint16_t conn_handle,
-                        const struct ble_att_indicate_req *req,
+ble_att_clt_tx_indicate(uint16_t conn_handle, uint16_t handle,
                         struct os_mbuf *txom)
 {
 #if !NIMBLE_BLE_ATT_CLT_INDICATE
     return BLE_HS_ENOTSUP;
 #endif
 
+    struct ble_att_indicate_req *req;
+    struct os_mbuf *txom2;
     int rc;
 
-    if (req->baiq_handle == 0) {
+    if (handle == 0) {
         rc = BLE_HS_EINVAL;
         goto err;
     }
 
-    txom = os_mbuf_prepend_pullup(txom, BLE_ATT_INDICATE_REQ_BASE_SZ);
-    if (txom == NULL) {
+    req = ble_att_cmd_get(BLE_ATT_OP_INDICATE_REQ, sizeof(*req), &txom2);
+    if (req == NULL) {
         rc = BLE_HS_ENOMEM;
         goto err;
     }
 
-    ble_att_indicate_req_write(txom->om_data, BLE_ATT_INDICATE_REQ_BASE_SZ,
-                               req);
-
-    rc = ble_att_clt_tx_req(conn_handle, txom);
-    txom = NULL;
-    if (rc != 0) {
-        goto err;
-    }
+    req->baiq_handle = htole16(handle);
+    os_mbuf_concat(txom2, txom);
 
     BLE_ATT_LOG_CMD(1, "indicate req", conn_handle, ble_att_indicate_req_log,
                     req);
 
-    return 0;
+    return ble_att_tx(conn_handle, txom2);
 
 err:
     os_mbuf_free_chain(txom);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8dbabc6e/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 8457767..8e72fba 100644
--- a/net/nimble/host/src/ble_att_priv.h
+++ b/net/nimble/host/src/ble_att_priv.h
@@ -288,8 +288,7 @@ int ble_att_clt_rx_exec_write(uint16_t conn_handle, struct 
os_mbuf **rxom);
 int ble_att_clt_rx_write(uint16_t conn_handle, struct os_mbuf **rxom);
 int ble_att_clt_tx_notify(uint16_t conn_handle, uint16_t handle,
                           struct os_mbuf *txom);
-int ble_att_clt_tx_indicate(uint16_t conn_handle,
-                            const struct ble_att_indicate_req *req,
+int ble_att_clt_tx_indicate(uint16_t conn_handle, uint16_t handle,
                             struct os_mbuf *txom);
 int ble_att_clt_rx_indicate(uint16_t conn_handle, struct os_mbuf **rxom);
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8dbabc6e/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 85111af..6594182 100644
--- a/net/nimble/host/src/ble_gattc.c
+++ b/net/nimble/host/src/ble_gattc.c
@@ -4574,7 +4574,6 @@ ble_gattc_indicate(uint16_t conn_handle, uint16_t 
chr_val_handle)
     return BLE_HS_ENOTSUP;
 #endif
 
-    struct ble_att_indicate_req req;
     struct ble_gattc_proc *proc;
     struct ble_hs_conn *conn;
     struct os_mbuf *om;
@@ -4611,8 +4610,7 @@ ble_gattc_indicate(uint16_t conn_handle, uint16_t 
chr_val_handle)
         goto done;
     }
 
-    req.baiq_handle = chr_val_handle;
-    rc = ble_att_clt_tx_indicate(conn_handle, &req, om);
+    rc = ble_att_clt_tx_indicate(conn_handle, chr_val_handle, om);
     om = NULL;
     if (rc != 0) {
         goto done;

Reply via email to