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/12/01 04:26:01 UTC

incubator-mynewt-larva git commit: Allow simulataneous BLE host jobs.

Repository: incubator-mynewt-larva
Updated Branches:
  refs/heads/master 61e167e60 -> b390b9f9f


Allow simulataneous BLE host jobs.


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

Branch: refs/heads/master
Commit: b390b9f9f163f9a9d258919768cae321cbaad55a
Parents: 61e167e
Author: Christopher Collins <cc...@gmail.com>
Authored: Mon Nov 30 19:25:38 2015 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Mon Nov 30 19:25:38 2015 -0800

----------------------------------------------------------------------
 net/nimble/host/src/ble_gap_conn.c      |   8 --
 net/nimble/host/src/ble_hs.c            |  10 +-
 net/nimble/host/src/ble_hs_att.h        |   8 ++
 net/nimble/host/src/ble_hs_att_batch.c  | 134 +++++++++++++++++++++++++++
 net/nimble/host/src/ble_hs_att_clt.c    |  22 +++--
 net/nimble/host/src/ble_hs_work.c       |  49 ++--------
 net/nimble/host/src/ble_hs_work.h       |   6 +-
 net/nimble/host/src/host_hci.c          |   2 -
 net/nimble/host/src/test/ble_gap_test.c |   3 -
 9 files changed, 170 insertions(+), 72 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b390b9f9/net/nimble/host/src/ble_gap_conn.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gap_conn.c b/net/nimble/host/src/ble_gap_conn.c
index df4f57d..c2ab8de 100644
--- a/net/nimble/host/src/ble_gap_conn.c
+++ b/net/nimble/host/src/ble_gap_conn.c
@@ -78,7 +78,6 @@ ble_gap_conn_master_failed(uint8_t status)
 {
     ble_gap_conn_master_state = BLE_GAP_CONN_STATE_IDLE;
     ble_hs_ack_set_callback(NULL, NULL);
-    ble_hs_work_done();
     ble_gap_conn_notify_app(status, NULL);
 }
 
@@ -92,7 +91,6 @@ ble_gap_conn_slave_failed(uint8_t status)
 {
     ble_gap_conn_slave_state = BLE_GAP_CONN_STATE_IDLE;
     ble_hs_ack_set_callback(NULL, NULL);
-    ble_hs_work_done();
     ble_gap_conn_notify_app(status, NULL);
 }
 
@@ -111,9 +109,6 @@ ble_gap_conn_master_ack(struct ble_hs_ack *ack, void *arg)
     } else {
         ble_gap_conn_master_state = BLE_GAP_CONN_STATE_MASTER_DIRECT_ACKED;
     }
-
-    /* The host is done sending commands to the controller. */
-    ble_hs_work_done();
 }
 
 /**
@@ -144,9 +139,6 @@ ble_gap_conn_slave_ack(struct ble_hs_ack *ack, void *arg)
             ble_gap_conn_slave_failed(ack->bha_status);
         } else {
             ble_gap_conn_slave_state = BLE_GAP_CONN_STATE_SLAVE_ENABLE_ACKED;
-
-            /* The host is done sending commands to the controller. */
-            ble_hs_work_done();
         }
         break;
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b390b9f9/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 7c67b4c..f1a4fdc 100644
--- a/net/nimble/host/src/ble_hs.c
+++ b/net/nimble/host/src/ble_hs.c
@@ -169,12 +169,10 @@ ble_hs_task_handler(void *arg)
             break;
         }
 
-        /* If a work event is not already in progress and there is another
-         * event pending, begin processing it.
-         */
-        if (ble_hs_work_cur_entry == NULL) {
-            ble_hs_work_process_next();
-        }
+        /* Process all pending jobs in the work queue. */
+        do {
+            rc = ble_hs_work_process_next();
+        } while (rc == EAGAIN);
     }
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b390b9f9/net/nimble/host/src/ble_hs_att.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_att.h b/net/nimble/host/src/ble_hs_att.h
index d76f4d1..0aa71ec 100644
--- a/net/nimble/host/src/ble_hs_att.h
+++ b/net/nimble/host/src/ble_hs_att.h
@@ -23,6 +23,7 @@ struct os_mbuf;
 struct ble_hs_conn;
 struct ble_l2cap_chan;
 struct ble_hs_att_find_info_req;
+struct ble_hs_att_error_rsp;
 
 #define BLE_HS_ATT_MTU_DFLT         23  /* Also the minimum. */
 #define BLE_HS_ATT_MTU_MAX          256 /* XXX: I'm making this up! */
@@ -150,4 +151,11 @@ int ble_hs_att_clt_rx_find_info(struct ble_hs_conn *conn,
                                 struct os_mbuf *om);
 int ble_hs_att_clt_init(void);
 
+/*** @batch */
+void ble_hs_att_batch_rx_error(struct ble_hs_conn *conn,
+                               struct ble_hs_att_error_rsp *rsp);
+void ble_hs_att_batch_rx_find_info(struct ble_hs_conn *conn, int status,
+                                   uint16_t last_handle_id);
+int ble_hs_att_batch_init(void);
+
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b390b9f9/net/nimble/host/src/ble_hs_att_batch.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_att_batch.c b/net/nimble/host/src/ble_hs_att_batch.c
new file mode 100644
index 0000000..e8f7370
--- /dev/null
+++ b/net/nimble/host/src/ble_hs_att_batch.c
@@ -0,0 +1,134 @@
+#include <stddef.h>
+#include <assert.h>
+#include <stdlib.h>
+#include <errno.h>
+#include "os/os_mempool.h"
+#include "ble_hs_conn.h"
+#include "ble_hs_att_cmd.h"
+#include "ble_hs_att.h"
+
+#define BLE_HS_ATT_BATCH_OP_NONE            0
+#define BLE_HS_ATT_BATCH_OP_FIND_INFO       1
+
+struct ble_hs_att_batch_entry {
+    STAILQ_ENTRY(ble_hs_att_batch_entry) next;
+
+    uint8_t op;
+    uint16_t peer_handle;
+    union {
+        struct {
+            uint16_t start_handle;
+            uint16_t end_handle;
+        } find_info;
+    };
+};
+
+#define BLE_HS_ATT_BATCH_NUM_ENTRIES          4
+static void *ble_hs_att_batch_entry_mem;
+static struct os_mempool ble_hs_att_batch_entry_pool;
+
+static STAILQ_HEAD(, ble_hs_att_batch_entry) ble_hs_att_batch_list;
+
+static struct ble_hs_att_batch_entry *
+ble_hs_att_batch_find(uint16_t peer_handle)
+{
+    struct ble_hs_att_batch_entry *entry;
+
+    STAILQ_FOREACH(entry, &ble_hs_att_batch_list, next) {
+        if (entry->peer_handle == peer_handle) {
+            return entry;
+        }
+    }
+
+    return NULL;
+}
+
+void
+ble_hs_att_batch_rx_error(struct ble_hs_conn *conn,
+                          struct ble_hs_att_error_rsp *rsp)
+{
+    struct ble_hs_att_batch_entry *entry;
+
+    entry = ble_hs_att_batch_find(conn->bhc_handle);
+    if (entry == NULL) {
+        /* Not expecting a response from this device. */
+        return;
+    }
+
+    switch (entry->op) {
+    case BLE_HS_ATT_BATCH_OP_NONE:
+        break;
+
+    case BLE_HS_ATT_BATCH_OP_FIND_INFO:
+        /* XXX: Branch on error status. */
+        break;
+
+    default:
+        assert(0);
+        break;
+    }
+}
+
+void
+ble_hs_att_batch_rx_find_info(struct ble_hs_conn *conn, int status,
+                              uint16_t last_handle_id)
+{
+    struct ble_hs_att_batch_entry *entry;
+
+    entry = ble_hs_att_batch_find(conn->bhc_handle);
+    if (entry == NULL) {
+        /* Not expecting a response from this device. */
+        return;
+    }
+
+    if (entry->op != BLE_HS_ATT_BATCH_OP_FIND_INFO) {
+        /* Not expecting a find info response from this device. */
+        return;
+    }
+
+    if (status != 0) {
+        /* XXX: Call failure callback. */
+        return;
+    }
+
+    if (last_handle_id == 0xffff) {
+        /* Call success callback. */
+    }
+
+    /* XXX: Send follow up request. */
+}
+
+int
+ble_hs_att_batch_init(void)
+{
+    int rc;
+
+    free(ble_hs_att_batch_entry_mem);
+
+    ble_hs_att_batch_entry_mem = malloc(
+        OS_MEMPOOL_BYTES(BLE_HS_ATT_BATCH_NUM_ENTRIES,
+                         sizeof (struct ble_hs_att_batch_entry)));
+    if (ble_hs_att_batch_entry_mem == NULL) {
+        rc = ENOMEM;
+        goto err;
+    }
+
+    rc = os_mempool_init(&ble_hs_att_batch_entry_pool,
+                         BLE_HS_ATT_BATCH_NUM_ENTRIES,
+                         sizeof (struct ble_hs_att_batch_entry),
+                         ble_hs_att_batch_entry_mem,
+                         "ble_hs_att_batch_entry_pool");
+    if (rc != 0) {
+        goto err;
+    }
+
+    STAILQ_INIT(&ble_hs_att_batch_list);
+
+    return 0;
+
+err:
+    free(ble_hs_att_batch_entry_mem);
+    ble_hs_att_batch_entry_mem = NULL;
+
+    return rc;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b390b9f9/net/nimble/host/src/ble_hs_att_clt.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_att_clt.c b/net/nimble/host/src/ble_hs_att_clt.c
index 28a2d8d..a58485c 100644
--- a/net/nimble/host/src/ble_hs_att_clt.c
+++ b/net/nimble/host/src/ble_hs_att_clt.c
@@ -185,11 +185,13 @@ ble_hs_att_clt_rx_find_info(struct ble_hs_conn *conn,
         return rc;
     }
 
+    handle_id = 0;
     off = BLE_HS_ATT_FIND_INFO_RSP_MIN_SZ;
     while (off < OS_MBUF_PKTHDR(om)->omp_len) {
         rc = os_mbuf_copydata(om, off, 2, &handle_id);
         if (rc != 0) {
-            return EINVAL;
+            rc = EINVAL;
+            goto done;
         }
         off += 2;
         handle_id = le16toh(&handle_id);
@@ -198,27 +200,31 @@ ble_hs_att_clt_rx_find_info(struct ble_hs_conn *conn,
         case BLE_HS_ATT_FIND_INFO_RSP_FORMAT_16BIT:
             rc = os_mbuf_copydata(om, off, 2, &uuid16);
             if (rc != 0) {
-                return EINVAL;
+                rc = EINVAL;
+                goto done;
             }
             off += 2;
             uuid16 = le16toh(&uuid16);
 
             rc = ble_hs_uuid_from_16bit(uuid16, uuid128);
             if (rc != 0) {
-                return EINVAL;
+                rc = EINVAL;
+                goto done;
             }
             break;
 
         case BLE_HS_ATT_FIND_INFO_RSP_FORMAT_128BIT:
             rc = os_mbuf_copydata(om, off, 16, &uuid128);
             if (rc != 0) {
-                return EINVAL;
+                rc = EINVAL;
+                goto done;
             }
             off += 16;
             break;
 
         default:
-            return EINVAL;
+            rc = EINVAL;
+            goto done;
         }
 
         rc = ble_hs_att_clt_entry_insert(conn, handle_id, uuid128);
@@ -227,7 +233,11 @@ ble_hs_att_clt_rx_find_info(struct ble_hs_conn *conn,
         }
     }
 
-    return 0;
+    rc = 0;
+
+done:
+    ble_hs_att_batch_rx_find_info(conn, -rc, handle_id);
+    return rc;
 }
 
 int

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b390b9f9/net/nimble/host/src/ble_hs_work.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_work.c b/net/nimble/host/src/ble_hs_work.c
index 545056b..e971aa5 100644
--- a/net/nimble/host/src/ble_hs_work.c
+++ b/net/nimble/host/src/ble_hs_work.c
@@ -25,8 +25,6 @@
 
 #define BLE_HS_WORK_NUM_ENTRIES     16
 
-struct ble_hs_work_entry *ble_hs_work_cur_entry;
-
 static void *ble_hs_work_entry_mem;
 static struct os_mempool ble_hs_work_entry_pool;
 static STAILQ_HEAD(, ble_hs_work_entry) ble_hs_work_queue;
@@ -47,74 +45,43 @@ ble_hs_work_enqueue(struct ble_hs_work_entry *entry)
     ble_hs_kick();
 }
 
-void
+int
 ble_hs_work_process_next(void)
 {
     struct ble_hs_work_entry *entry;
-    int rc;
-
-    assert(ble_hs_work_cur_entry == NULL);
 
     entry = STAILQ_FIRST(&ble_hs_work_queue);
     if (entry == NULL) {
-        return;
+        return 0;
     }
 
     STAILQ_REMOVE_HEAD(&ble_hs_work_queue, bwe_next);
 
-    ble_hs_work_cur_entry = entry;
-
     switch (entry->bwe_type) {
     case BLE_HS_WORK_TYPE_DIRECT_CONNECT:
-        rc = ble_gap_conn_direct_connect(
+        ble_gap_conn_direct_connect(
             entry->bwe_direct_connect.bwdc_peer_addr_type,
             entry->bwe_direct_connect.bwdc_peer_addr);
         break;
 
     case BLE_HS_WORK_TYPE_DIRECT_ADVERTISE:
-        rc = ble_gap_conn_direct_advertise(
+        ble_gap_conn_direct_advertise(
             entry->bwe_direct_advertise.bwda_peer_addr_type,
             entry->bwe_direct_advertise.bwda_peer_addr);
         break;
 
     case BLE_HS_WORK_TYPE_READ_HCI_BUF_SIZE:
-        rc = host_hci_read_buf_size();
+        host_hci_read_buf_size();
         break;
 
     default:
-        rc = -1;
         assert(0);
         break;
     }
 
-    if (rc != 0) {
-        os_memblock_put(&ble_hs_work_entry_pool, entry);
-        ble_hs_work_cur_entry = NULL;
-    }
-}
-
-void
-ble_hs_work_done(void)
-{
-    assert(ble_hs_work_cur_entry != NULL || !g_os_started);
-
-    if (ble_hs_work_cur_entry != NULL) {
-        os_memblock_put(&ble_hs_work_entry_pool, ble_hs_work_cur_entry);
-        ble_hs_work_cur_entry = NULL;
-    }
-}
-
-int
-ble_hs_work_done_if(int work_type)
-{
-    if (ble_hs_work_cur_entry != NULL &&
-        ble_hs_work_cur_entry->bwe_type == work_type) {
+    os_memblock_put(&ble_hs_work_entry_pool, entry);
 
-        ble_hs_work_done();
-        return 0;
-    } else {
-        return 1;
-    }
+    return EAGAIN;
 }
 
 int
@@ -139,7 +106,5 @@ ble_hs_work_init(void)
 
     STAILQ_INIT(&ble_hs_work_queue);
 
-    ble_hs_work_cur_entry = NULL;
-
     return 0;
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b390b9f9/net/nimble/host/src/ble_hs_work.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_work.h b/net/nimble/host/src/ble_hs_work.h
index b187c98..7b9a554 100644
--- a/net/nimble/host/src/ble_hs_work.h
+++ b/net/nimble/host/src/ble_hs_work.h
@@ -47,11 +47,7 @@ struct ble_hs_work_entry {
 
 struct ble_hs_work_entry *ble_hs_work_entry_alloc(void);
 void ble_hs_work_enqueue(struct ble_hs_work_entry *entry);
-void ble_hs_work_process_next(void);
-void ble_hs_work_done(void);
-int ble_hs_work_done_if(int work_type);
+int ble_hs_work_process_next(void);
 int ble_hs_work_init(void);
 
-extern struct ble_hs_work_entry *ble_hs_work_cur_entry;
-
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b390b9f9/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 b49c22e..52295be 100644
--- a/net/nimble/host/src/host_hci.c
+++ b/net/nimble/host/src/host_hci.c
@@ -330,8 +330,6 @@ host_hci_rx_read_buf_size_ack(struct ble_hs_ack *ack, void *arg)
 
     host_hci_buffer_sz = pktlen;
     host_hci_max_pkts = max_pkts;
-
-    ble_hs_work_done_if(BLE_HS_WORK_TYPE_READ_HCI_BUF_SIZE);
 }
 
 int

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b390b9f9/net/nimble/host/src/test/ble_gap_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_gap_test.c b/net/nimble/host/src/test/ble_gap_test.c
index 863bbd3..4be9147 100644
--- a/net/nimble/host/src/test/ble_gap_test.c
+++ b/net/nimble/host/src/test/ble_gap_test.c
@@ -89,18 +89,15 @@ ble_gap_test_task_handler(void *arg)
     /* Make sure there are no created connections and no connections in
      * progress.
      */
-    TEST_ASSERT(ble_hs_work_cur_entry == NULL);
     TEST_ASSERT(ble_hs_conn_first() == NULL);
 
     /* Initiate a direct connection. */
     ble_gap_direct_connection_establishment(0, addr);
-    TEST_ASSERT(ble_hs_work_cur_entry != NULL);
     TEST_ASSERT(ble_hs_conn_first() == NULL);
     TEST_ASSERT(!cb_called);
 
     /* Receive an ack for the HCI create-connection command. */
     ble_gap_test_misc_rx_ack(BLE_HCI_OCF_LE_CREATE_CONN, 0);
-    TEST_ASSERT(ble_hs_work_cur_entry == NULL);
     TEST_ASSERT(ble_hs_conn_first() == NULL);
     TEST_ASSERT(!cb_called);