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/02/08 23:03:57 UTC

[1/5] incubator-mynewt-larva git commit: l2cap_sig thread safety.

Repository: incubator-mynewt-larva
Updated Branches:
  refs/heads/master 9f119799b -> 7f1e6d492


l2cap_sig thread safety.


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

Branch: refs/heads/master
Commit: 17338b6fa531bdb7d680389dca88eba767790f92
Parents: 7ebc72b
Author: Christopher Collins <cc...@gmail.com>
Authored: Mon Feb 8 11:14:15 2016 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Mon Feb 8 14:03:47 2016 -0800

----------------------------------------------------------------------
 net/nimble/host/src/ble_l2cap_priv.h |   1 +
 net/nimble/host/src/ble_l2cap_sig.c  | 233 +++++++++++++++++++++++-------
 2 files changed, 183 insertions(+), 51 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/17338b6f/net/nimble/host/src/ble_l2cap_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_priv.h b/net/nimble/host/src/ble_l2cap_priv.h
index 08cefc1..75c34fb 100644
--- a/net/nimble/host/src/ble_l2cap_priv.h
+++ b/net/nimble/host/src/ble_l2cap_priv.h
@@ -96,6 +96,7 @@ struct ble_l2cap_chan
 
 SLIST_HEAD(ble_l2cap_chan_list, ble_l2cap_chan);
 
+int ble_l2cap_sig_locked_by_cur_task(void);
 int ble_l2cap_parse_hdr(struct os_mbuf *om, int off,
                         struct ble_l2cap_hdr *l2cap_hdr);
 struct os_mbuf *ble_l2cap_prepend_hdr(struct os_mbuf *om, uint16_t cid,

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/17338b6f/net/nimble/host/src/ble_l2cap_sig.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_sig.c b/net/nimble/host/src/ble_l2cap_sig.c
index 01103c2..85ec413 100644
--- a/net/nimble/host/src/ble_l2cap_sig.c
+++ b/net/nimble/host/src/ble_l2cap_sig.c
@@ -118,7 +118,8 @@ static uint8_t ble_l2cap_sig_cur_id;
 static void *ble_l2cap_sig_proc_mem;
 static struct os_mempool ble_l2cap_sig_proc_pool;
 
-static STAILQ_HEAD(, ble_l2cap_sig_proc) ble_l2cap_sig_list;
+STAILQ_HEAD(ble_l2cap_sig_proc_list, ble_l2cap_sig_proc);
+static struct ble_l2cap_sig_proc_list ble_l2cap_sig_list;
 
 /*****************************************************************************
  * $debug                                                                    *
@@ -153,6 +154,49 @@ ble_l2cap_sig_assert_sanity(void)
 #endif
 }
 
+static struct os_mutex ble_l2cap_sig_mutex;
+
+/*****************************************************************************
+ * $mutex                                                                    *
+ *****************************************************************************/
+
+static void
+ble_l2cap_sig_lock(void)
+{
+    struct os_task *owner;
+    int rc;
+
+    owner = ble_l2cap_sig_mutex.mu_owner;
+    if (owner != NULL) {
+        assert(owner != os_sched_get_current_task());
+    }
+
+    rc = os_mutex_pend(&ble_l2cap_sig_mutex, 0xffffffff);
+    assert(rc == 0 || rc == OS_NOT_STARTED);
+}
+
+static void
+ble_l2cap_sig_unlock(void)
+{
+    int rc;
+
+    rc = os_mutex_release(&ble_l2cap_sig_mutex);
+    assert(rc == 0 || rc == OS_NOT_STARTED);
+}
+
+int
+ble_l2cap_sig_locked_by_cur_task(void)
+{
+    struct os_task *owner;
+
+    owner = ble_l2cap_sig_mutex.mu_owner;
+    return owner != NULL && owner == os_sched_get_current_task();
+}
+
+/*****************************************************************************
+ * $misc                                                                     *
+ *****************************************************************************/
+
 /**
  * Lock restrictions:
  *     o Caller unlocks ble_hs_conn.
@@ -270,21 +314,24 @@ ble_l2cap_sig_proc_free(struct ble_l2cap_sig_proc *proc)
 }
 
 /**
- * Removes the specified proc entry from the global list without freeing it.
+ * Removes the specified proc entry from a list without freeing it.
  *
- * Lock restrictions: None.
+ * Lock restrictions:
+ *     o Caller locks l2cap_sig if the source list is ble_l2cap_sig_list.
  *
+ * @param src_list              The list to remove the proc from.
  * @param proc                  The proc to remove.
  * @param prev                  The proc that is previous to "proc" in the
  *                                  list; null if "proc" is the list head.
  */
 static void
-ble_l2cap_sig_proc_remove(struct ble_l2cap_sig_proc *proc,
+ble_l2cap_sig_proc_remove(struct ble_l2cap_sig_proc_list *src_list,
+                          struct ble_l2cap_sig_proc *proc,
                           struct ble_l2cap_sig_proc *prev)
 {
     if (prev == NULL) {
-        assert(STAILQ_FIRST(&ble_l2cap_sig_list) == proc);
-        STAILQ_REMOVE_HEAD(&ble_l2cap_sig_list, next);
+        assert(STAILQ_FIRST(src_list) == proc);
+        STAILQ_REMOVE_HEAD(src_list, next);
     } else {
         assert(STAILQ_NEXT(prev, next) == proc);
         STAILQ_NEXT(prev, next) = STAILQ_NEXT(proc, next);
@@ -292,20 +339,30 @@ ble_l2cap_sig_proc_remove(struct ble_l2cap_sig_proc *proc,
 }
 
 /**
- * Removes and frees the speicifed proc entry.
+ * Concatenates the specified list onto the end of the main proc list.
  *
- * Lock restrictions: None.
- *
- * @param proc                  The proc to remove and free.
- * @param prev                  The proc that is previous to "proc" in the
- *                                  list; null if "proc" is the list head.
+ * Lock restrictions:
+ *     o Caller unlocks l2cap_sig.
  */
 static void
-ble_l2cap_sig_proc_remove_free(struct ble_l2cap_sig_proc *proc,
-                               struct ble_l2cap_sig_proc *prev)
+ble_l2cap_sig_proc_concat(struct ble_l2cap_sig_proc_list *tail_list)
 {
-    ble_l2cap_sig_proc_remove(proc, prev);
-    ble_l2cap_sig_proc_free(proc);
+    struct ble_l2cap_sig_proc *proc;
+
+    /* Concatenate the tempororary list to the end of the main list. */
+    if (!STAILQ_EMPTY(tail_list)) {
+        ble_l2cap_sig_lock();
+
+        if (STAILQ_EMPTY(&ble_l2cap_sig_list)) {
+            ble_l2cap_sig_list = *tail_list;
+        } else {
+            proc = STAILQ_LAST(&ble_l2cap_sig_list, ble_l2cap_sig_proc, next);
+            STAILQ_NEXT(proc, next) = STAILQ_FIRST(tail_list);
+            ble_l2cap_sig_list.stqh_last = tail_list->stqh_last;
+        }
+
+        ble_l2cap_sig_unlock();
+    }
 }
 
 /**
@@ -411,6 +468,42 @@ ble_l2cap_sig_proc_find(uint16_t conn_handle, uint8_t op, uint8_t id,
 }
 
 /**
+ * Searches the main proc list for an "expecting" entry whose connection handle
+ * and op code match those specified.  If a matching entry is found, it is
+ * removed from the list and returned.
+ *
+ * Lock restrictions:
+ *     o Caller unlocks l2cap_sig.
+ *
+ * @param conn_handle           The connection handle to match against.
+ * @param op                    The op code to match against.
+ * @param identifier            The identifier to match against.
+ *
+ * @return                      The matching proc entry on success;
+ *                                  null on failure.
+ */
+static struct ble_l2cap_sig_proc *
+ble_l2cap_sig_proc_extract(uint16_t conn_handle, uint8_t op,
+                           uint8_t identifier)
+{
+    struct ble_l2cap_sig_proc *proc;
+    struct ble_l2cap_sig_proc *prev;
+
+    ble_l2cap_sig_lock();
+
+    ble_l2cap_sig_assert_sanity();
+
+    proc = ble_l2cap_sig_proc_find(conn_handle, op, identifier, 1, &prev);
+    if (proc != NULL) {
+        ble_l2cap_sig_proc_remove(&ble_l2cap_sig_list, proc, prev);
+    }
+
+    ble_l2cap_sig_unlock();
+
+    return proc;
+}
+
+/**
  * Sets the specified proc entry's "pending" flag (i.e., indicates that the
  * L2CAP sig procedure is stalled until it transmits its next request).
  *
@@ -438,11 +531,9 @@ ble_l2cap_sig_proc_set_expecting(struct ble_l2cap_sig_proc *proc,
 {
     assert(!(proc->flags & BLE_L2CAP_SIG_PROC_F_EXPECTING));
 
-    ble_l2cap_sig_proc_remove(proc, prev);
     proc->flags &= ~BLE_L2CAP_SIG_PROC_F_PENDING;
     proc->flags |= BLE_L2CAP_SIG_PROC_F_EXPECTING;
     proc->tx_time = os_time_get();
-    STAILQ_INSERT_TAIL(&ble_l2cap_sig_list, proc, next);
 }
 
 /**
@@ -549,7 +640,7 @@ ble_l2cap_sig_update_req_rx(uint16_t conn_handle,
 
 /**
  * Lock restrictions:
- *     o Caller unlocks ble_hs_conn.
+ *     o Caller unlocks all ble_hs mutexes.
  */
 static int
 ble_l2cap_sig_update_rsp_rx(uint16_t conn_handle,
@@ -558,13 +649,14 @@ ble_l2cap_sig_update_rsp_rx(uint16_t conn_handle,
 {
     struct ble_l2cap_sig_update_rsp rsp;
     struct ble_l2cap_sig_proc *proc;
-    struct ble_l2cap_sig_proc *prev;
     int cb_status;
     int rc;
 
-    proc = ble_l2cap_sig_proc_find(conn_handle,
-                                   BLE_L2CAP_SIG_PROC_OP_UPDATE,
-                                   hdr->identifier, 1, &prev);
+    ble_hs_misc_assert_no_locks();
+
+    proc = ble_l2cap_sig_proc_extract(conn_handle,
+                                      BLE_L2CAP_SIG_PROC_OP_UPDATE,
+                                      hdr->identifier);
     if (proc ==  NULL) {
         return BLE_HS_ENOENT;
     }
@@ -604,7 +696,7 @@ ble_l2cap_sig_update_rsp_rx(uint16_t conn_handle,
 
 done:
     ble_l2cap_sig_update_call_cb(proc, cb_status);
-    ble_l2cap_sig_proc_remove_free(proc, prev);
+    ble_l2cap_sig_proc_free(proc);
     return rc;
 }
 
@@ -800,44 +892,33 @@ ble_l2cap_sig_heartbeat(void *unused)
 void
 ble_l2cap_sig_wakeup(void)
 {
+    struct ble_l2cap_sig_proc_list proc_list;
     struct ble_l2cap_sig_proc *proc;
     struct ble_l2cap_sig_proc *prev;
     struct ble_l2cap_sig_proc *next;
     ble_l2cap_sig_kick_fn *kick_cb;
     int rc;
 
+    ble_hs_misc_assert_no_locks();
+
+    STAILQ_INIT(&proc_list);
+
+    /* Remove all procs with pending transmits and insert them into the
+     * temporary list. Once the elements are moved, they can be processed
+     * without keeping the l2cap_sig mutex locked.
+     */
+    ble_l2cap_sig_lock();
+
+    ble_l2cap_sig_assert_sanity();
+
     prev = NULL;
     proc = STAILQ_FIRST(&ble_l2cap_sig_list);
     while (proc != NULL) {
         next = STAILQ_NEXT(proc, next);
 
         if (proc->flags & BLE_L2CAP_SIG_PROC_F_PENDING) {
-            kick_cb = ble_l2cap_sig_kick_get(proc->op);
-            rc = kick_cb(proc);
-            switch (rc) {
-            case 0:
-                /* Transmit succeeded.  Response expected. */
-                ble_l2cap_sig_proc_set_expecting(proc, prev);
-                /* Current proc got moved to back; old prev still valid. */
-                break;
-
-            case BLE_HS_EAGAIN:
-                /* Transmit failed due to resource shortage.  Reschedule. */
-                proc->flags &= ~BLE_L2CAP_SIG_PROC_F_PENDING;
-                /* Current proc remains; reseat prev. */
-                prev = proc;
-                break;
-
-            case BLE_HS_EDONE:
-                /* Procedure complete. */
-                ble_l2cap_sig_proc_remove_free(proc, prev);
-                /* Current proc removed; old prev still valid. */
-                break;
-
-            default:
-                assert(0);
-                break;
-            }
+            ble_l2cap_sig_proc_remove(&ble_l2cap_sig_list, proc, prev);
+            STAILQ_INSERT_TAIL(&proc_list, proc, next);
         } else {
             prev = proc;
         }
@@ -845,7 +926,51 @@ ble_l2cap_sig_wakeup(void)
         proc = next;
     }
 
-    ble_l2cap_sig_assert_sanity();
+    ble_l2cap_sig_unlock();
+
+    /* Process each of the pending procs. */
+    prev = NULL;
+    proc = STAILQ_FIRST(&proc_list);
+    while (proc != NULL) {
+        next = STAILQ_NEXT(proc, next);
+
+        kick_cb = ble_l2cap_sig_kick_get(proc->op);
+        rc = kick_cb(proc);
+        switch (rc) {
+        case 0:
+            /* Transmit succeeded.  Response expected. */
+            ble_l2cap_sig_proc_set_expecting(proc, prev);
+
+            /* Current proc remains; reseat prev. */
+            prev = proc;
+            break;
+
+        case BLE_HS_EAGAIN:
+            /* Transmit failed due to resource shortage.  Reschedule. */
+            proc->flags &= ~BLE_L2CAP_SIG_PROC_F_PENDING;
+
+            /* Current proc remains; reseat prev. */
+            prev = proc;
+            break;
+
+        case BLE_HS_EDONE:
+            /* Procedure complete. */
+            ble_l2cap_sig_proc_remove(&proc_list, proc, prev);
+            ble_l2cap_sig_proc_free(proc);
+
+            /* Current proc removed; old prev still valid. */
+            break;
+
+        default:
+            assert(0);
+            break;
+        }
+
+        proc = next;
+    }
+
+    /* Concatenate the tempororary list to the end of the main list. */
+    ble_l2cap_sig_proc_concat(&proc_list);
 }
 
 /**
@@ -858,6 +983,12 @@ ble_l2cap_sig_init(void)
 
     free(ble_l2cap_sig_proc_mem);
 
+    rc = os_mutex_init(&ble_l2cap_sig_mutex);
+    if (rc != 0) {
+        rc = BLE_HS_EOS;
+        goto err;
+    }
+
     ble_l2cap_sig_proc_mem = malloc(
         OS_MEMPOOL_BYTES(BLE_L2CAP_SIG_NUM_PROCS,
                          sizeof (struct ble_l2cap_sig_proc)));


[3/5] incubator-mynewt-larva git commit: L2CAP configurability.

Posted by cc...@apache.org.
L2CAP configurability.


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

Branch: refs/heads/master
Commit: 91c2318ead0b87af48773a7ddd74dab026fd3898
Parents: 17338b6
Author: Christopher Collins <cc...@gmail.com>
Authored: Mon Feb 8 11:18:49 2016 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Mon Feb 8 14:03:48 2016 -0800

----------------------------------------------------------------------
 net/nimble/host/include/host/ble_hs.h |  3 +++
 net/nimble/host/src/ble_hs_cfg.c      |  7 +++++++
 net/nimble/host/src/ble_l2cap_sig.c   | 31 +++++++++++++++---------------
 3 files changed, 26 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/91c2318e/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 01a5983..8ae8350 100644
--- a/net/nimble/host/include/host/ble_hs.h
+++ b/net/nimble/host/include/host/ble_hs.h
@@ -74,6 +74,9 @@ struct ble_hs_cfg {
     /** ATT server settings. */
     uint16_t max_attrs;
     uint8_t max_prep_entries;
+
+    /** L2CAP settings. */
+    uint8_t max_l2cap_sig_procs;
 };
 extern struct ble_hs_cfg ble_hs_cfg;
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/91c2318e/net/nimble/host/src/ble_hs_cfg.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_cfg.c b/net/nimble/host/src/ble_hs_cfg.c
index 2593d20..b435ffa 100644
--- a/net/nimble/host/src/ble_hs_cfg.c
+++ b/net/nimble/host/src/ble_hs_cfg.c
@@ -41,6 +41,9 @@ static const struct ble_hs_cfg ble_hs_cfg_dflt = {
     /** ATT server settings. */
     .max_attrs = 64,
     .max_prep_entries = 6,
+
+    /** L2CAP settings. */
+    .max_l2cap_sig_procs = 8,
 };
 
 struct ble_hs_cfg ble_hs_cfg;
@@ -81,4 +84,8 @@ ble_hs_cfg_init(void)
     if (ble_hs_cfg.max_prep_entries == 0) {
         ble_hs_cfg.max_prep_entries = ble_hs_cfg_dflt.max_prep_entries;
     }
+
+    if (ble_hs_cfg.max_l2cap_sig_procs == 0) {
+        ble_hs_cfg.max_l2cap_sig_procs = ble_hs_cfg_dflt.max_l2cap_sig_procs;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/91c2318e/net/nimble/host/src/ble_l2cap_sig.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_sig.c b/net/nimble/host/src/ble_l2cap_sig.c
index 85ec413..bf5b25c 100644
--- a/net/nimble/host/src/ble_l2cap_sig.c
+++ b/net/nimble/host/src/ble_l2cap_sig.c
@@ -34,7 +34,6 @@
  * $definitions / declarations                                               *
  *****************************************************************************/
 
-#define BLE_L2CAP_SIG_NUM_PROCS                 16      /* XXX Configurable. */
 #define BLE_L2CAP_SIG_HEARTBEAT_PERIOD          1000    /* Milliseconds. */
 #define BLE_L2CAP_SIG_UNRESPONSIVE_TIMEOUT      30000   /* Milliseconds. */
 
@@ -989,21 +988,23 @@ ble_l2cap_sig_init(void)
         goto err;
     }
 
-    ble_l2cap_sig_proc_mem = malloc(
-        OS_MEMPOOL_BYTES(BLE_L2CAP_SIG_NUM_PROCS,
-                         sizeof (struct ble_l2cap_sig_proc)));
-    if (ble_l2cap_sig_proc_mem == NULL) {
-        rc = BLE_HS_ENOMEM;
-        goto err;
-    }
+    if (ble_hs_cfg.max_l2cap_sig_procs > 0) {
+        ble_l2cap_sig_proc_mem = malloc(
+            OS_MEMPOOL_BYTES(ble_hs_cfg.max_l2cap_sig_procs,
+                             sizeof (struct ble_l2cap_sig_proc)));
+        if (ble_l2cap_sig_proc_mem == NULL) {
+            rc = BLE_HS_ENOMEM;
+            goto err;
+        }
 
-    rc = os_mempool_init(&ble_l2cap_sig_proc_pool,
-                         BLE_L2CAP_SIG_NUM_PROCS,
-                         sizeof (struct ble_l2cap_sig_proc),
-                         ble_l2cap_sig_proc_mem,
-                         "ble_l2cap_sig_proc_pool");
-    if (rc != 0) {
-        goto err;
+        rc = os_mempool_init(&ble_l2cap_sig_proc_pool,
+                             ble_hs_cfg.max_l2cap_sig_procs,
+                             sizeof (struct ble_l2cap_sig_proc),
+                             ble_l2cap_sig_proc_mem,
+                             "ble_l2cap_sig_proc_pool");
+        if (rc != 0) {
+            goto err;
+        }
     }
 
     STAILQ_INIT(&ble_l2cap_sig_list);


[5/5] incubator-mynewt-larva git commit: Ensure no locks when notify procedure calls ATT cb

Posted by cc...@apache.org.
Ensure no locks when notify procedure calls ATT cb


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

Branch: refs/heads/master
Commit: 7f1e6d4928e7f1d06c75fe5a3369b55ea014123a
Parents: 774d728
Author: Christopher Collins <cc...@gmail.com>
Authored: Mon Feb 8 14:02:29 2016 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Mon Feb 8 14:03:48 2016 -0800

----------------------------------------------------------------------
 net/nimble/host/include/host/ble_gatt.h |   2 +-
 net/nimble/host/src/ble_gattc.c         | 148 +++++++++++++++++++--------
 net/nimble/host/src/ble_gatts.c         |   4 +-
 3 files changed, 108 insertions(+), 46 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/7f1e6d49/net/nimble/host/include/host/ble_gatt.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/ble_gatt.h b/net/nimble/host/include/host/ble_gatt.h
index b42c331..d147cdf 100644
--- a/net/nimble/host/include/host/ble_gatt.h
+++ b/net/nimble/host/include/host/ble_gatt.h
@@ -135,7 +135,7 @@ int ble_gattc_write_dsc(uint16_t conn_handle, uint16_t attr_handle,
 int ble_gattc_write_long_dsc(uint16_t conn_handle, uint16_t attr_handle,
                              void *value, uint16_t value_len,
                              ble_gatt_attr_fn *cb, void *cb_arg);
-int ble_gattc_notify(struct ble_hs_conn *conn, uint16_t chr_val_handle);
+int ble_gattc_notify(uint16_t conn_handle, uint16_t chr_val_handle);
 int ble_gattc_notify_custom(uint16_t conn_handle, struct ble_gatt_attr *attr);
 
 int ble_gattc_init(void);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/7f1e6d49/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 b403683..93679cb 100644
--- a/net/nimble/host/src/ble_gattc.c
+++ b/net/nimble/host/src/ble_gattc.c
@@ -55,8 +55,9 @@
 #define BLE_GATT_OP_WRITE                       12
 #define BLE_GATT_OP_WRITE_LONG                  13
 #define BLE_GATT_OP_WRITE_RELIABLE              14
-#define BLE_GATT_OP_INDICATE                    15
-#define BLE_GATT_OP_MAX                         16
+#define BLE_GATT_OP_NOTIFY                      15
+#define BLE_GATT_OP_INDICATE                    16
+#define BLE_GATT_OP_MAX                         17
 
 /** Represents an in-progress GATT procedure. */
 struct ble_gattc_proc {
@@ -172,6 +173,12 @@ struct ble_gattc_proc {
             struct ble_gatt_attr attr;
             ble_gatt_attr_fn *cb;
             void *cb_arg;
+        } notify;
+
+        struct {
+            struct ble_gatt_attr attr;
+            ble_gatt_attr_fn *cb;
+            void *cb_arg;
         } indicate;
     };
 };
@@ -217,6 +224,7 @@ static int ble_gattc_write_no_rsp_kick(struct ble_gattc_proc *proc);
 static int ble_gattc_write_kick(struct ble_gattc_proc *proc);
 static int ble_gattc_write_long_kick(struct ble_gattc_proc *proc);
 static int ble_gattc_write_reliable_kick(struct ble_gattc_proc *proc);
+static int ble_gattc_notify_kick(struct ble_gattc_proc *proc);
 static int ble_gattc_indicate_kick(struct ble_gattc_proc *proc);
 
 /**
@@ -443,6 +451,10 @@ static const struct ble_gattc_dispatch_entry {
         .kick_cb = ble_gattc_write_reliable_kick,
         .err_cb = ble_gattc_write_reliable_err,
     },
+    [BLE_GATT_OP_NOTIFY] = {
+        .kick_cb = ble_gattc_notify_kick,
+        .err_cb = NULL,
+    },
     [BLE_GATT_OP_INDICATE] = {
         .kick_cb = ble_gattc_indicate_kick,
         .err_cb = ble_gattc_indicate_err,
@@ -3823,36 +3835,54 @@ ble_gattc_write_reliable(uint16_t conn_handle, struct ble_gatt_attr *attrs,
  *****************************************************************************/
 
 /**
- * Sends an attribute notification.  The content of the message is read from
- * the specified characteristic.
+ * Triggers a pending transmit for the specified indication proc.
  *
- * Lock restrictions: Caller must lock ble_hs_conn mutex.
- *     o Caller locks ble_hs_conn.
+ * Lock restrictions:
+ *     o Caller unlocks all ble_hs mutexes.
  */
-int
-ble_gattc_notify(struct ble_hs_conn *conn, uint16_t chr_val_handle)
+static int
+ble_gattc_notify_kick(struct ble_gattc_proc *proc)
 {
-#if !NIMBLE_OPT_GATT_NOTIFY
-    return BLE_HS_ENOTSUP;
-#endif
-
     struct ble_att_svr_access_ctxt ctxt;
     struct ble_att_notify_req req;
+    struct ble_hs_conn *conn;
     int rc;
 
-    rc = ble_att_svr_read_handle(BLE_HS_CONN_HANDLE_NONE, chr_val_handle,
-                                 &ctxt, NULL);
-    if (rc != 0) {
-        return rc;
+    if (proc->notify.attr.value == NULL) {
+        rc = ble_att_svr_read_handle(BLE_HS_CONN_HANDLE_NONE,
+                                     proc->notify.attr.handle, &ctxt,
+                                     NULL);
+        if (rc != 0) {
+            /* Fatal error; application disallowed attribute read. */
+            return BLE_HS_EDONE;
+        }
+    } else {
+        ctxt.attr_data = proc->notify.attr.value;
+        ctxt.data_len = proc->notify.attr.value_len;
+        ctxt.offset = 0;
     }
 
-    req.banq_handle = chr_val_handle;
-    rc = ble_att_clt_tx_notify(conn, &req, ctxt.attr_data, ctxt.data_len);
-    if (rc != 0) {
-        return rc;
+    ble_hs_conn_lock();
+
+    conn = ble_hs_conn_find(proc->conn_handle);
+    if (conn == NULL) {
+        rc = BLE_HS_ENOTCONN;
+    } else {
+        proc->notify.attr.value = ctxt.attr_data;
+        proc->notify.attr.value_len = ctxt.data_len;
+
+        req.banq_handle = proc->notify.attr.handle;
+        rc = ble_att_clt_tx_notify(conn, &req, proc->notify.attr.value,
+                                   proc->notify.attr.value_len);
     }
 
-    return 0;
+    ble_hs_conn_unlock();
+
+    if (ble_gattc_tx_postpone_chk(proc, rc)) {
+        return BLE_HS_EAGAIN;
+    } else {
+        return BLE_HS_EDONE;
+    }
 }
 
 /**
@@ -3869,25 +3899,46 @@ ble_gattc_notify_custom(uint16_t conn_handle, struct ble_gatt_attr *attr)
     return BLE_HS_ENOTSUP;
 #endif
 
-    struct ble_att_notify_req req;
-    struct ble_hs_conn *conn;
+    struct ble_gattc_proc *proc;
     int rc;
 
-    ble_hs_conn_lock();
-
-    conn = ble_hs_conn_find(conn_handle);
-    if (conn == NULL) {
-        rc = BLE_HS_ENOTCONN;
-    } else {
-        req.banq_handle = attr->handle;
-        rc = ble_att_clt_tx_notify(conn, &req, attr->value, attr->value_len);
+    rc = ble_gattc_new_proc(conn_handle, BLE_GATT_OP_NOTIFY, &proc);
+    if (rc != 0) {
+        return rc;
     }
 
-    ble_hs_conn_unlock();
+    proc->notify.attr = *attr;
+    ble_gattc_proc_set_pending(proc);
 
     return rc;
 }
 
+/**
+ * Sends an attribute notification.  The content of the message is read from
+ * the specified characteristic.
+ *
+ * Lock restrictions: Caller must lock ble_hs_conn mutex.
+ *     o Caller locks ble_hs_conn.
+ */
+int
+ble_gattc_notify(uint16_t conn_handle, uint16_t chr_val_handle)
+{
+#if !NIMBLE_OPT_GATT_NOTIFY
+    return BLE_HS_ENOTSUP;
+#endif
+
+    struct ble_gatt_attr attr;
+    int rc;
+
+    attr.handle = chr_val_handle;
+    attr.offset = 0;
+    attr.value_len = 0;
+    attr.value = NULL;
+
+    rc = ble_gattc_notify_custom(conn_handle, &attr);
+    return rc;
+}
+
 /*****************************************************************************
  * $indicate                                                                 *
  *****************************************************************************/
@@ -3935,23 +3986,32 @@ ble_gattc_indicate_kick(struct ble_gattc_proc *proc)
     struct ble_hs_conn *conn;
     int rc;
 
+    if (proc->indicate.attr.value == NULL) {
+        rc = ble_att_svr_read_handle(BLE_HS_CONN_HANDLE_NONE,
+                                     proc->indicate.attr.handle, &ctxt,
+                                     NULL);
+        if (rc != 0) {
+            /* Fatal error; application disallowed attribute read. */
+            return BLE_HS_EDONE;
+        }
+    } else {
+        ctxt.attr_data = proc->indicate.attr.value;
+        ctxt.data_len = proc->indicate.attr.value_len;
+        ctxt.offset = 0;
+    }
+
     ble_hs_conn_lock();
 
     conn = ble_hs_conn_find(proc->conn_handle);
     if (conn == NULL) {
         rc = BLE_HS_ENOTCONN;
     } else {
-        rc = ble_att_svr_read_handle(BLE_HS_CONN_HANDLE_NONE,
-                                     proc->indicate.attr.handle, &ctxt,
-                                     NULL);
-        if (rc == 0) {
-            proc->indicate.attr.value = ctxt.attr_data;
-            proc->indicate.attr.value_len = ctxt.data_len;
+        proc->indicate.attr.value = ctxt.attr_data;
+        proc->indicate.attr.value_len = ctxt.data_len;
 
-            req.baiq_handle = proc->indicate.attr.handle;
-            rc = ble_att_clt_tx_indicate(conn, &req, proc->indicate.attr.value,
-                                         proc->indicate.attr.value_len);
-        }
+        req.baiq_handle = proc->indicate.attr.handle;
+        rc = ble_att_clt_tx_indicate(conn, &req, proc->indicate.attr.value,
+                                     proc->indicate.attr.value_len);
     }
 
     ble_hs_conn_unlock();
@@ -3993,6 +4053,8 @@ ble_gattc_indicate_rx_rsp(struct ble_gattc_proc *proc)
 {
     struct ble_hs_conn *conn;
 
+    ble_gattc_indicate_cb(proc, 0, 0);
+
     /* Now that the confirmation has been received, we can send any subsequent
      * indication.
      */
@@ -4002,8 +4064,6 @@ ble_gattc_indicate_rx_rsp(struct ble_gattc_proc *proc)
     if (conn != NULL) {
         conn->bhc_gatt_svr.flags &= ~BLE_GATTS_CONN_F_INDICATION_TXED;
 
-        ble_gattc_indicate_cb(proc, 0, 0);
-
         /* Send the next indication if one is pending. */
         ble_gatts_send_notifications(conn);
     }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/7f1e6d49/net/nimble/host/src/ble_gatts.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gatts.c b/net/nimble/host/src/ble_gatts.c
index 3e70d2f..109850c 100644
--- a/net/nimble/host/src/ble_gatts.c
+++ b/net/nimble/host/src/ble_gatts.c
@@ -1031,7 +1031,8 @@ ble_gatts_send_notifications(struct ble_hs_conn *conn)
                     }
                 }
             } else if (clt_cfg->flags & BLE_GATTS_CLT_CFG_F_NOTIFY) {
-                rc = ble_gattc_notify(conn, clt_cfg->chr_def_handle + 1);
+                rc = ble_gattc_notify(conn->bhc_handle,
+                                      clt_cfg->chr_def_handle + 1);
                 if (rc == 0) {
                     clt_cfg->flags &= ~BLE_GATTS_CLT_CFG_F_UPDATED;
                 }
@@ -1072,6 +1073,7 @@ ble_gatts_chr_updated(uint16_t chr_def_handle)
             (BLE_GATTS_CLT_CFG_F_NOTIFY | BLE_GATTS_CLT_CFG_F_INDICATE)) {
 
             clt_cfg->flags |= BLE_GATTS_CLT_CFG_F_UPDATED;
+
             ble_gatts_send_notifications(conn);
         }
     }


[4/5] incubator-mynewt-larva git commit: Allow values of 0 in configurable host options.

Posted by cc...@apache.org.
Allow values of 0 in configurable host options.


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

Branch: refs/heads/master
Commit: 774d72818d2dd1684996fbbacd47fca70c4f4cb3
Parents: 91c2318
Author: Christopher Collins <cc...@gmail.com>
Authored: Mon Feb 8 12:05:09 2016 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Mon Feb 8 14:03:48 2016 -0800

----------------------------------------------------------------------
 net/nimble/host/include/host/ble_hs.h       |  5 +--
 net/nimble/host/src/ble_att_svr.c           |  2 +-
 net/nimble/host/src/ble_hs.c                |  4 +--
 net/nimble/host/src/ble_hs_cfg.c            | 44 ++++--------------------
 net/nimble/host/src/ble_hs_priv.h           |  4 ++-
 net/nimble/host/src/test/ble_hs_test_util.c |  2 +-
 project/bleshell/src/main.c                 |  2 +-
 project/bletiny/src/main.c                  | 16 +++++----
 8 files changed, 26 insertions(+), 53 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/774d7281/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 8ae8350..2ae2532 100644
--- a/net/nimble/host/include/host/ble_hs.h
+++ b/net/nimble/host/include/host/ble_hs.h
@@ -78,8 +78,9 @@ struct ble_hs_cfg {
     /** L2CAP settings. */
     uint8_t max_l2cap_sig_procs;
 };
-extern struct ble_hs_cfg ble_hs_cfg;
 
-int ble_hs_init(uint8_t prio);
+extern const struct ble_hs_cfg ble_hs_cfg_dflt;
+
+int ble_hs_init(uint8_t prio, struct ble_hs_cfg *cfg);
 
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/774d7281/net/nimble/host/src/ble_att_svr.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att_svr.c b/net/nimble/host/src/ble_att_svr.c
index 1ff242e..6b75463 100644
--- a/net/nimble/host/src/ble_att_svr.c
+++ b/net/nimble/host/src/ble_att_svr.c
@@ -303,7 +303,7 @@ ble_att_svr_read(uint16_t conn_handle, struct ble_att_svr_entry *entry,
     uint8_t att_err;
     int rc;
 
-    assert(!ble_hs_conn_locked_by_cur_task());
+    ble_hs_misc_assert_no_locks();
 
     if (conn_handle != BLE_HS_CONN_HANDLE_NONE &&
         !(entry->ha_flags & HA_FLAG_PERM_READ)) {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/774d7281/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 d303dfe..26467bc 100644
--- a/net/nimble/host/src/ble_hs.c
+++ b/net/nimble/host/src/ble_hs.c
@@ -209,11 +209,11 @@ ble_hs_kick_l2cap_sig(void)
  * Initializes the host portion of the BLE stack.
  */
 int
-ble_hs_init(uint8_t prio)
+ble_hs_init(uint8_t prio, struct ble_hs_cfg *cfg)
 {
     int rc;
 
-    ble_hs_cfg_init();
+    ble_hs_cfg_init(cfg);
 
     os_task_init(&ble_hs_task, "ble_hs", ble_hs_task_handler, NULL, prio,
                  OS_WAIT_FOREVER, ble_hs_stack, BLE_HS_STACK_SIZE);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/774d7281/net/nimble/host/src/ble_hs_cfg.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_cfg.c b/net/nimble/host/src/ble_hs_cfg.c
index b435ffa..49f6db3 100644
--- a/net/nimble/host/src/ble_hs_cfg.c
+++ b/net/nimble/host/src/ble_hs_cfg.c
@@ -19,7 +19,7 @@
 
 #include "ble_hs_priv.h"
 
-static const struct ble_hs_cfg ble_hs_cfg_dflt = {
+const struct ble_hs_cfg ble_hs_cfg_dflt = {
     /** Connection settings. */
     .max_outstanding_pkts_per_conn = 5,
 
@@ -49,43 +49,11 @@ static const struct ble_hs_cfg ble_hs_cfg_dflt = {
 struct ble_hs_cfg ble_hs_cfg;
 
 void
-ble_hs_cfg_init(void)
+ble_hs_cfg_init(struct ble_hs_cfg *cfg)
 {
-    if (ble_hs_cfg.max_outstanding_pkts_per_conn == 0) {
-        ble_hs_cfg.max_outstanding_pkts_per_conn =
-            ble_hs_cfg_dflt.max_outstanding_pkts_per_conn;
-    }
-
-    if (ble_hs_cfg.max_connections == 0) {
-        ble_hs_cfg.max_connections = ble_hs_cfg_dflt.max_connections;
-    }
-
-    if (ble_hs_cfg.max_conn_update_entries == 0) {
-        ble_hs_cfg.max_conn_update_entries =
-            ble_hs_cfg_dflt.max_conn_update_entries;
-    }
-
-    if (ble_hs_cfg.max_services == 0) {
-        ble_hs_cfg.max_services = ble_hs_cfg_dflt.max_services;
-    }
-
-    if (ble_hs_cfg.max_client_configs == 0) {
-        ble_hs_cfg.max_client_configs = ble_hs_cfg_dflt.max_client_configs;
-    }
-
-    if (ble_hs_cfg.max_gattc_procs == 0) {
-        ble_hs_cfg.max_gattc_procs = ble_hs_cfg_dflt.max_gattc_procs;
-    }
-
-    if (ble_hs_cfg.max_attrs == 0) {
-        ble_hs_cfg.max_attrs = ble_hs_cfg_dflt.max_attrs;
-    }
-
-    if (ble_hs_cfg.max_prep_entries == 0) {
-        ble_hs_cfg.max_prep_entries = ble_hs_cfg_dflt.max_prep_entries;
-    }
-
-    if (ble_hs_cfg.max_l2cap_sig_procs == 0) {
-        ble_hs_cfg.max_l2cap_sig_procs = ble_hs_cfg_dflt.max_l2cap_sig_procs;
+    if (cfg == NULL) {
+        ble_hs_cfg = ble_hs_cfg_dflt;
+    } else {
+        ble_hs_cfg = *cfg;
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/774d7281/net/nimble/host/src/ble_hs_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_priv.h b/net/nimble/host/src/ble_hs_priv.h
index a0bbc85..0163d53 100644
--- a/net/nimble/host/src/ble_hs_priv.h
+++ b/net/nimble/host/src/ble_hs_priv.h
@@ -31,6 +31,8 @@ struct os_mempool;
 #define BLE_HS_KICK_GATT_EVENT          (OS_EVENT_T_PERUSER + 2)
 #define BLE_HS_KICK_L2CAP_SIG_EVENT     (OS_EVENT_T_PERUSER + 3)
 
+extern struct ble_hs_cfg ble_hs_cfg;
+
 extern struct os_mbuf_pool ble_hs_mbuf_pool;
 extern struct os_eventq ble_hs_evq;
 
@@ -46,7 +48,7 @@ int ble_hs_misc_malloc_mempool(void **mem, struct os_mempool *pool,
 void ble_hs_misc_log_mbuf(struct os_mbuf *om);
 void ble_hs_misc_log_flat_buf(void *data, int len);
 
-void ble_hs_cfg_init(void);
+void ble_hs_cfg_init(struct ble_hs_cfg *cfg);
 
 void ble_hs_misc_assert_no_locks(void);
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/774d7281/net/nimble/host/src/test/ble_hs_test_util.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_hs_test_util.c b/net/nimble/host/src/test/ble_hs_test_util.c
index 6bc7db8..62e91fa 100644
--- a/net/nimble/host/src/test/ble_hs_test_util.c
+++ b/net/nimble/host/src/test/ble_hs_test_util.c
@@ -409,7 +409,7 @@ ble_hs_test_util_init(void)
 
     os_msys_reset();
 
-    rc = ble_hs_init(10);
+    rc = ble_hs_init(10, NULL);
     TEST_ASSERT_FATAL(rc == 0);
 
     rc = os_mempool_init(&ble_hs_test_util_mbuf_mpool,

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/774d7281/project/bleshell/src/main.c
----------------------------------------------------------------------
diff --git a/project/bleshell/src/main.c b/project/bleshell/src/main.c
index e476e84..1bb6f03 100755
--- a/project/bleshell/src/main.c
+++ b/project/bleshell/src/main.c
@@ -1316,7 +1316,7 @@ main(void)
                  bleshell_stack, BLESHELL_STACK_SIZE);
 
     /* Initialize host HCI */
-    rc = ble_hs_init(HOST_TASK_PRIO);
+    rc = ble_hs_init(HOST_TASK_PRIO, NULL);
     assert(rc == 0);
 
     /* Initialize the BLE LL */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/774d7281/project/bletiny/src/main.c
----------------------------------------------------------------------
diff --git a/project/bletiny/src/main.c b/project/bletiny/src/main.c
index 6ee948d..f550a61 100755
--- a/project/bletiny/src/main.c
+++ b/project/bletiny/src/main.c
@@ -1235,9 +1235,10 @@ bletiny_task_handler(void *arg)
 int
 main(void)
 {
-    int i;
-    int rc;
+    struct ble_hs_cfg cfg;
     uint32_t seed;
+    int rc;
+    int i;
 
     /* Initialize OS */
     os_init();
@@ -1308,12 +1309,13 @@ main(void)
                  bletiny_stack, BLETINY_STACK_SIZE);
 
     /* Initialize the BLE host. */
-    ble_hs_cfg.max_connections = 1;
-    ble_hs_cfg.max_services = 4;
-    ble_hs_cfg.max_client_configs = 4;
-    ble_hs_cfg.max_gattc_procs = 2;
+    cfg = ble_hs_cfg_dflt;
+    cfg.max_connections = 1;
+    cfg.max_services = 4;
+    cfg.max_client_configs = 6;
+    cfg.max_gattc_procs = 2;
 
-    rc = ble_hs_init(HOST_TASK_PRIO);
+    rc = ble_hs_init(HOST_TASK_PRIO, &cfg);
     assert(rc == 0);
 
     /* Initialize the BLE LL */


[2/5] incubator-mynewt-larva git commit: Fill in some comments.

Posted by cc...@apache.org.
Fill in some comments.


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

Branch: refs/heads/master
Commit: 7ebc72b2743a680790d57f6e7062cd50f358ec33
Parents: 9f11979
Author: Christopher Collins <cc...@gmail.com>
Authored: Sun Feb 7 23:15:50 2016 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Mon Feb 8 14:03:47 2016 -0800

----------------------------------------------------------------------
 net/nimble/host/src/ble_l2cap.c     | 18 ++++++++++++------
 net/nimble/host/src/ble_l2cap_sig.c | 27 +++++++++++++++++----------
 2 files changed, 29 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/7ebc72b2/net/nimble/host/src/ble_l2cap.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap.c b/net/nimble/host/src/ble_l2cap.c
index 176c32b..89d0e50 100644
--- a/net/nimble/host/src/ble_l2cap.c
+++ b/net/nimble/host/src/ble_l2cap.c
@@ -72,7 +72,8 @@ ble_l2cap_chan_free(struct ble_l2cap_chan *chan)
 }
 
 /**
- * Lock restrictions: Caller must lock ble_hs_conn mutex.
+ * Lock restrictions:
+ *     o Caller locks ble_hs_conn.
  */
 uint16_t
 ble_l2cap_chan_mtu(struct ble_l2cap_chan *chan)
@@ -137,7 +138,8 @@ ble_l2cap_prepend_hdr(struct os_mbuf *om, uint16_t cid, uint16_t len)
 }
 
 /**
- * Lock restrictions: Caller must lock ble_hs_conn mutex.
+ * Lock restrictions:
+ *     o Caller locks ble_hs_conn.
  */
 static void
 ble_l2cap_forget_rx(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan)
@@ -148,7 +150,8 @@ ble_l2cap_forget_rx(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan)
 }
 
 /**
- * Lock restrictions: Caller must lock ble_hs_conn mutex.
+ * Lock restrictions:
+ *     o Caller locks ble_hs_conn.
  */
 static void
 ble_l2cap_discard_rx(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan)
@@ -158,7 +161,8 @@ ble_l2cap_discard_rx(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan)
 }
 
 /**
- * Lock restrictions: Caller must lock ble_hs_conn mutex.
+ * Lock restrictions:
+ *     o Caller locks ble_hs_conn.
  */
 static int
 ble_l2cap_rx_payload(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan,
@@ -195,7 +199,8 @@ ble_l2cap_rx_payload(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan,
 }
 
 /**
- * Lock restrictions: Caller must lock ble_hs_conn mutex.
+ * Lock restrictions:
+ *     o Caller locks ble_hs_conn.
  */
 int
 ble_l2cap_rx(struct ble_hs_conn *conn,
@@ -268,7 +273,8 @@ err:
  * Transmits the L2CAP payload contained in the specified mbuf.  The supplied
  * mbuf is consumed, regardless of the outcome of the function call.
  * 
- * Lock restrictions: Caller must lock ble_hs_conn mutex.
+ * Lock restrictions:
+ *     o Caller locks ble_hs_conn.
  *
  * @param chan                  The L2CAP channel to transmit over.
  * @param om                    The data to transmit.

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/7ebc72b2/net/nimble/host/src/ble_l2cap_sig.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_sig.c b/net/nimble/host/src/ble_l2cap_sig.c
index 95e061c..01103c2 100644
--- a/net/nimble/host/src/ble_l2cap_sig.c
+++ b/net/nimble/host/src/ble_l2cap_sig.c
@@ -154,7 +154,8 @@ ble_l2cap_sig_assert_sanity(void)
 }
 
 /**
- * Lock restrictions: Caller must NOT lock ble_hs_conn mutex.
+ * Lock restrictions:
+ *     o Caller unlocks ble_hs_conn.
  */
 static int
 ble_l2cap_sig_conn_chan_find(uint16_t conn_handle,
@@ -370,7 +371,7 @@ ble_l2cap_sig_proc_matches(struct ble_l2cap_sig_proc *proc,
 }
 
 /**
- * Searched the global proc list for an entry that fits the specified criteria.
+ * Searches the global proc list for an entry that fits the specified criteria.
  *
  * Lock restrictions: None.
  *
@@ -411,7 +412,7 @@ ble_l2cap_sig_proc_find(uint16_t conn_handle, uint8_t op, uint8_t id,
 
 /**
  * Sets the specified proc entry's "pending" flag (i.e., indicates that the
- * L2CAP sig procedure is stalled until it transmits its next request.
+ * L2CAP sig procedure is stalled until it transmits its next request).
  *
  * Lock restrictions: None.
  */
@@ -427,7 +428,7 @@ ble_l2cap_sig_proc_set_pending(struct ble_l2cap_sig_proc *proc)
 
 /**
  * Sets the specified proc entry's "expecting" flag (i.e., indicates that the
- * L2CAP sig procedure is stalled until it receives a response.
+ * L2CAP sig procedure is stalled until it receives a response).
  *
  * Lock restrictions: None.
  */
@@ -460,7 +461,8 @@ ble_l2cap_sig_rx_noop(uint16_t conn_handle,
  *****************************************************************************/
 
 /**
- * Lock restrictions: Caller must NOT lock ble_hs_conn mutex.
+ * Lock restrictions:
+ *     o Caller unlocks ble_hs_conn.
  */
 static void
 ble_l2cap_sig_update_call_cb(struct ble_l2cap_sig_proc *proc, int status)
@@ -473,7 +475,8 @@ ble_l2cap_sig_update_call_cb(struct ble_l2cap_sig_proc *proc, int status)
 }
 
 /**
- * Lock restrictions: Caller must NOT lock ble_hs_conn mutex.
+ * Lock restrictions:
+ *     o Caller unlocks ble_hs_conn.
  */
 int
 ble_l2cap_sig_update_req_rx(uint16_t conn_handle,
@@ -545,7 +548,8 @@ ble_l2cap_sig_update_req_rx(uint16_t conn_handle,
 }
 
 /**
- * Lock restrictions: Caller must NOT lock ble_hs_conn mutex.
+ * Lock restrictions:
+ *     o Caller unlocks ble_hs_conn.
  */
 static int
 ble_l2cap_sig_update_rsp_rx(uint16_t conn_handle,
@@ -605,7 +609,8 @@ done:
 }
 
 /**
- * Lock restrictions: Caller must NOT lock ble_hs_conn mutex.
+ * Lock restrictions:
+ *     o Caller locks ble_hs_conn.
  */
 static int
 ble_l2cap_sig_update_kick(struct ble_l2cap_sig_proc *proc)
@@ -676,7 +681,8 @@ ble_l2cap_sig_update(uint16_t conn_handle,
 }
 
 /**
- * Lock restrictions: Caller must NOT lock ble_hs_conn mutex.
+ * Lock restrictions:
+ *     o Caller unlocks ble_hs_conn.
  */
 static int
 ble_l2cap_sig_rx(uint16_t conn_handle, struct os_mbuf **om)
@@ -788,7 +794,8 @@ ble_l2cap_sig_heartbeat(void *unused)
 }
 
 /**
- * Lock restrictions: Caller must NOT lock ble_hs_conn mutex.
+ * Lock restrictions:
+ *     o Caller unlocks ble_hs_conn.
  */
 void
 ble_l2cap_sig_wakeup(void)