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 2016/07/08 21:19:51 UTC

[04/50] [abbrv] incubator-mynewt-core git commit: BLE Host - Return oom errors on no hci buf / no ev.

BLE Host - Return oom errors on no hci buf / no ev.


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

Branch: refs/heads/master
Commit: 39660c0fca5899f346574782bc245db553170169
Parents: b8b3232
Author: Christopher Collins <cc...@apache.org>
Authored: Mon Jun 20 20:22:23 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Jun 20 20:31:29 2016 -0700

----------------------------------------------------------------------
 net/nimble/controller/src/ble_ll_hci.c |  7 +++--
 net/nimble/host/include/host/ble_hs.h  |  2 ++
 net/nimble/host/src/ble_hci_cmd.c      |  2 +-
 net/nimble/host/src/host_hci_cmd.c     | 42 +++++++++++++++++++----------
 4 files changed, 36 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/39660c0f/net/nimble/controller/src/ble_ll_hci.c
----------------------------------------------------------------------
diff --git a/net/nimble/controller/src/ble_ll_hci.c b/net/nimble/controller/src/ble_ll_hci.c
index fd75fbb..a17515f 100644
--- a/net/nimble/controller/src/ble_ll_hci.c
+++ b/net/nimble/controller/src/ble_ll_hci.c
@@ -982,7 +982,10 @@ ble_ll_hci_cmd_proc(struct os_event *ev)
     ble_ll_hci_event_send(cmdbuf);
 }
 
-/* XXX: For now, put this here */
+/**
+ * @return                      0 on success;
+ *                              BLE_ERR_MEM_CAPACITY on HCI buffer exhaustion.
+ */
 int
 ble_hci_transport_host_cmd_send(uint8_t *cmd)
 {
@@ -994,7 +997,7 @@ ble_hci_transport_host_cmd_send(uint8_t *cmd)
     if (!ev) {
         err = os_memblock_put(&g_hci_cmd_pool, cmd);
         assert(err == OS_OK);
-        return -1;
+        return BLE_ERR_MEM_CAPACITY;
     }
 
     /* Fill out the event and post to Link Layer */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/39660c0f/net/nimble/host/include/host/ble_hs.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/ble_hs.h b/net/nimble/host/include/host/ble_hs.h
index 18eb588..63720c3 100644
--- a/net/nimble/host/include/host/ble_hs.h
+++ b/net/nimble/host/include/host/ble_hs.h
@@ -54,6 +54,8 @@ struct os_event;
 #define BLE_HS_EUNKNOWN             18
 #define BLE_HS_EROLE                19
 #define BLE_HS_ETIMEOUT_HCI         20
+#define BLE_HS_ENOMEM_HCI           21
+#define BLE_HS_ENOMEM_EVT           22
 
 #define BLE_HS_ERR_ATT_BASE         0x100   /* 256 */
 #define BLE_HS_ATT_ERR(x)           ((x) ? BLE_HS_ERR_ATT_BASE + (x) : 0)

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/39660c0f/net/nimble/host/src/ble_hci_cmd.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hci_cmd.c b/net/nimble/host/src/ble_hci_cmd.c
index c41f038..014ef0a 100644
--- a/net/nimble/host/src/ble_hci_cmd.c
+++ b/net/nimble/host/src/ble_hci_cmd.c
@@ -204,7 +204,7 @@ ble_hci_cmd_wait_for_ack(void)
         BLE_HS_DBG_ASSERT(ble_hci_cmd_ack_ev == NULL);
         ble_hci_cmd_ack_ev = os_memblock_get(&g_hci_cmd_pool);
         if (ble_hci_cmd_ack_ev == NULL) {
-            rc = BLE_HS_ENOMEM;
+            rc = BLE_HS_ENOMEM_HCI;
         } else {
             rc = ble_hci_cmd_phony_ack_cb(ble_hci_cmd_ack_ev, 260);
         }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/39660c0f/net/nimble/host/src/host_hci_cmd.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/host_hci_cmd.c b/net/nimble/host/src/host_hci_cmd.c
index d638ed6..281b270 100644
--- a/net/nimble/host/src/host_hci_cmd.c
+++ b/net/nimble/host/src/host_hci_cmd.c
@@ -39,7 +39,19 @@ host_hci_cmd_transport(uint8_t *cmdbuf)
     ble_hs_test_hci_txed(cmdbuf);
     return 0;
 #else
-    return ble_hci_transport_host_cmd_send(cmdbuf);
+    int rc;
+
+    rc = ble_hci_transport_host_cmd_send(cmdbuf);
+    switch (rc) {
+    case 0:
+        return 0;
+
+    case BLE_ERR_MEM_CAPACITY:
+        return BLE_HS_ENOMEM_EVT;
+
+    default:
+        return BLE_HS_EUNKNOWN;
+    }
 #endif
 }
 
@@ -63,21 +75,23 @@ host_hci_cmd_send(uint8_t ogf, uint8_t ocf, uint8_t len, void *cmddata)
     uint8_t *cmd;
     uint16_t opcode;
 
-    rc = -1;
     cmd = os_memblock_get(&g_hci_cmd_pool);
-    if (cmd) {
-        opcode = (ogf << 10) | ocf;
-        htole16(cmd, opcode);
-        cmd[2] = len;
-        if (len) {
-            memcpy(cmd + BLE_HCI_CMD_HDR_LEN, cmddata, len);
-        }
-        rc = host_hci_cmd_transport(cmd);
-        BLE_HS_LOG(DEBUG, "host_hci_cmd_send: ogf=0x%02x ocf=0x%02x len=%d\n",
-                   ogf, ocf, len);
-        ble_hs_misc_log_flat_buf(cmd, len + BLE_HCI_CMD_HDR_LEN);
-        BLE_HS_LOG(DEBUG, "\n");
+    if (cmd == NULL) {
+        /* XXX: Increment stat. */
+        return BLE_HS_ENOMEM_HCI;
+    }
+
+    opcode = (ogf << 10) | ocf;
+    htole16(cmd, opcode);
+    cmd[2] = len;
+    if (len) {
+        memcpy(cmd + BLE_HCI_CMD_HDR_LEN, cmddata, len);
     }
+    rc = host_hci_cmd_transport(cmd);
+    BLE_HS_LOG(DEBUG, "host_hci_cmd_send: ogf=0x%02x ocf=0x%02x len=%d "
+                      "rc=%d\n", ogf, ocf, len, rc);
+    ble_hs_misc_log_flat_buf(cmd, len + BLE_HCI_CMD_HDR_LEN);
+    BLE_HS_LOG(DEBUG, "\n");
 
     if (rc == 0) {
         STATS_INC(ble_hs_stats, hci_cmd);