Repository: incubator-mynewt-core
Updated Branches:
  refs/heads/master e23872dc6 -> 95935c62c


nimble/att: Add generic helpers for sending commands

Those will be used to construct ATT command directly in os_mbuf.


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

Branch: refs/heads/master
Commit: 71a8a47cb6acaad0d7899adbfbc09d23e4e7a9d5
Parents: a94e4de
Author: Szymon Janc <[email protected]>
Authored: Fri Mar 24 12:51:52 2017 +0100
Committer: Szymon Janc <[email protected]>
Committed: Mon Apr 10 10:23:07 2017 +0200

----------------------------------------------------------------------
 net/nimble/host/src/ble_att_cmd.c      | 55 +++++++++++++++++++++++++++++
 net/nimble/host/src/ble_att_cmd_priv.h | 12 +++++++
 2 files changed, 67 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/71a8a47c/net/nimble/host/src/ble_att_cmd.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att_cmd.c 
b/net/nimble/host/src/ble_att_cmd.c
index b99f896..7997ff1 100644
--- a/net/nimble/host/src/ble_att_cmd.c
+++ b/net/nimble/host/src/ble_att_cmd.c
@@ -26,6 +26,61 @@
 #include "host/ble_uuid.h"
 #include "ble_hs_priv.h"
 
+void *
+ble_att_cmd_prepare(uint8_t opcode, size_t len, struct os_mbuf *txom)
+{
+    struct ble_att_hdr *hdr;
+
+    if (os_mbuf_extend(txom, sizeof(*hdr) + len) == NULL) {
+        os_mbuf_free_chain(txom);
+        return NULL;
+    }
+
+    hdr = (struct ble_att_hdr *)(txom)->om_data;
+
+    hdr->opcode = opcode;
+
+    return hdr->data;
+}
+
+void *
+ble_att_cmd_get(uint8_t opcode, size_t len, struct os_mbuf **txom)
+{
+    *txom = ble_hs_mbuf_l2cap_pkt();
+    if (*txom == NULL) {
+        return NULL;
+    }
+
+    return ble_att_cmd_prepare(opcode, len, *txom);
+}
+
+int
+ble_att_tx(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();
+
+    ble_hs_misc_conn_chan_find_reqd(conn_handle, BLE_L2CAP_CID_ATT, &conn,
+                                    &chan);
+    if (chan == NULL) {
+        os_mbuf_free_chain(txom);
+        rc = BLE_HS_ENOTCONN;
+    } else {
+        ble_att_truncate_to_mtu(chan, txom);
+        rc = ble_l2cap_tx(conn, chan, txom);
+    }
+
+    ble_hs_unlock();
+
+    return rc;
+}
+
 static const void *
 ble_att_init_parse(uint8_t op, const void *payload,
                    int min_len, int actual_len)

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/71a8a47c/net/nimble/host/src/ble_att_cmd_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att_cmd_priv.h 
b/net/nimble/host/src/ble_att_cmd_priv.h
index ec96c22..17516e8 100644
--- a/net/nimble/host/src/ble_att_cmd_priv.h
+++ b/net/nimble/host/src/ble_att_cmd_priv.h
@@ -21,10 +21,18 @@
 #define H_BLE_ATT_CMD_
 
 #include <inttypes.h>
+#include <stddef.h>
+#include "os/os_mbuf.h"
+
 #ifdef __cplusplus
 extern "C" {
 #endif
 
+struct ble_att_hdr {
+    uint8_t opcode;
+    uint8_t data[0];
+} __attribute__((packed));
+
 /**
  * | Parameter                          | Size (octets)     |
  * +------------------------------------+-------------------+
@@ -412,6 +420,10 @@ void ble_att_indicate_rsp_parse(const void *payload, int 
len);
 void ble_att_indicate_rsp_write(void *payload, int len);
 void ble_att_indicate_req_log(const struct ble_att_indicate_req *cmd);
 
+void *ble_att_cmd_prepare(uint8_t opcode, size_t len, struct os_mbuf *txom);
+void *ble_att_cmd_get(uint8_t opcode, size_t len, struct os_mbuf **txom);
+int ble_att_tx(uint16_t conn_handle, struct os_mbuf *txom);
+
 #ifdef __cplusplus
 }
 #endif

Reply via email to