You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2015/11/23 21:17:24 UTC

incubator-mynewt-larva git commit: Use mbufs for incoming HCI ACL data packets.

Repository: incubator-mynewt-larva
Updated Branches:
  refs/heads/master 426d59151 -> 9601758b7


Use mbufs for incoming HCI ACL data packets.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/commit/9601758b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/9601758b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/9601758b

Branch: refs/heads/master
Commit: 9601758b73bbde1a3e92981dbf7fa7af05381154
Parents: 426d591
Author: Christopher Collins <cc...@gmail.com>
Authored: Mon Nov 23 12:17:10 2015 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Mon Nov 23 12:17:10 2015 -0800

----------------------------------------------------------------------
 net/nimble/host/include/host/host_hci.h |  2 +-
 net/nimble/host/src/ble_hs.c            | 11 ++++++
 net/nimble/host/src/host_hci.c          | 53 ++++++++++++++--------------
 3 files changed, 38 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/9601758b/net/nimble/host/include/host/host_hci.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/host_hci.h b/net/nimble/host/include/host/host_hci.h
index 89b07e0..53d7ca1 100644
--- a/net/nimble/host/include/host/host_hci.h
+++ b/net/nimble/host/include/host/host_hci.h
@@ -37,7 +37,7 @@ int host_hci_cmd_le_read_whitelist(void);
 int host_hci_cmd_le_add_to_whitelist(uint8_t *addr, uint8_t addr_type);
 int host_hci_cmd_le_rmv_from_whitelist(uint8_t *addr, uint8_t addr_type);
 
-int host_hci_data_rx(void *pkt, uint16_t len);
+int host_hci_data_rx(struct os_mbuf *om);
 
 void host_hci_init(void);
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/9601758b/net/nimble/host/src/ble_hs.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs.c b/net/nimble/host/src/ble_hs.c
index a0882d6..8e2aaab 100644
--- a/net/nimble/host/src/ble_hs.c
+++ b/net/nimble/host/src/ble_hs.c
@@ -106,6 +106,8 @@ ble_hs_process_rx_data_queue(void)
 
     while ((tpq_elem = tpq_get(&ble_hs_tx_q)) != NULL) {
         pkt = (void *)tpq_elem;
+        host_hci_data_rx(pkt->bhp_om);
+
         os_memblock_put(&ble_hs_pkt_pool, pkt);
     }
 }
@@ -155,6 +157,15 @@ ble_hs_task_handler(void *arg)
     }
 }
 
+/**
+ * Called when a data packet is received from the controller.  This function
+ * consumes the supplied mbuf, regardless of the outcome.
+ *
+ * @param om                    The incoming data packet, beginning with the
+ *                                  HCI ACL data header.
+ *
+ * @return                      0 on success; nonzero on failure.
+ */
 int
 ble_hs_rx_data(struct os_mbuf *om)
 {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/9601758b/net/nimble/host/src/host_hci.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/host_hci.c b/net/nimble/host/src/host_hci.c
index 5306560..82d6b71 100644
--- a/net/nimble/host/src/host_hci.c
+++ b/net/nimble/host/src/host_hci.c
@@ -29,6 +29,9 @@
 #include "ble_hs_ack.h"
 #include "ble_gap_conn.h"
 
+_Static_assert(sizeof (struct hci_data_hdr) == BLE_HCI_DATA_HDR_SZ,
+               "struct hci_data_hdr must be 4 bytes");
+
 static int host_hci_rx_cmd_complete(uint8_t event_code, uint8_t *data,
                                     int len);
 static int host_hci_rx_cmd_status(uint8_t event_code, uint8_t *data, int len);
@@ -348,62 +351,58 @@ ble_hci_transport_ctlr_event_send(uint8_t *hci_ev)
     return 0;
 }
 
-#if 0
 static int
-host_hci_data_parse_hdr(void *pkt, uint16_t len, struct hci_data_hdr *hdr)
+host_hci_data_hdr_strip(struct os_mbuf *om, struct hci_data_hdr *hdr)
 {
-    uint8_t *u8ptr;
-    uint16_t off;
+    int rc;
 
-    if (len < BLE_HCI_DATA_HDR_SZ) {
+    rc = os_mbuf_copydata(om, 0, BLE_HCI_DATA_HDR_SZ, hdr);
+    if (rc != 0) {
         return EMSGSIZE;
     }
 
-    off = 0;
-    u8ptr = pkt;
+    /* Strip HCI ACL data header from the front of the packet. */
+    /* XXX: This is probably the wrong mbuf pool. */
+    os_mbuf_adj(&ble_hs_mbuf_pool, om, BLE_HCI_DATA_HDR_SZ);
 
-    hdr->hdh_handle_pb_bc = le16toh(u8ptr + off);
-    off += 2;
-
-    hdr->hdh_len = le16toh(u8ptr + off);
-    off += 2;
+    hdr->hdh_handle_pb_bc = le16toh(&hdr->hdh_handle_pb_bc);
+    hdr->hdh_len = le16toh(&hdr->hdh_len);
 
     return 0;
 }
 
 int
-host_hci_data_rx(void *pkt, uint16_t len)
+host_hci_data_rx(struct os_mbuf *om)
 {
     struct ble_hs_conn *connection;
     struct hci_data_hdr hci_hdr;
     uint16_t handle;
-    uint16_t off;
-    uint8_t *u8ptr;
     int rc;
 
-    u8ptr = pkt;
-    off = 0;
-
-    rc = host_hci_data_parse_hdr(u8ptr + off, len - off, &hci_hdr);
+    rc = host_hci_data_hdr_strip(om, &hci_hdr);
     if (rc != 0) {
-        return rc;
+        goto done;
     }
-    off += BLE_HCI_DATA_HDR_SZ;
-    if (len < off + hci_hdr.hdh_len) {
-        return EMSGSIZE;
+
+    if (hci_hdr.hdh_len != OS_MBUF_PKTHDR(om)->omp_len) {
+        rc = EMSGSIZE;
+        goto done;
     }
 
     handle = BLE_HCI_DATA_HANDLE(hci_hdr.hdh_handle_pb_bc);
     connection = ble_hs_conn_find(handle);
     if (connection == NULL) {
-        return ENOTCONN;
+        rc = ENOTCONN;
+        goto done;
     }
 
-    ble_l2cap_rx(connection, &hci_hdr, u8ptr + off);
+    rc = ble_l2cap_rx(connection, &hci_hdr, om);
+    om = NULL;
 
-    return 0;
+done:
+    os_mbuf_free_chain(&ble_hs_mbuf_pool, om); /* XXX: Wrong pool. */
+    return rc;
 }
-#endif
 
 void
 host_hci_init(void)