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/11 23:49:51 UTC

[01/50] [abbrv] incubator-mynewt-core git commit: BLE Host - Update ble_gap_adv_start() API.

Repository: incubator-mynewt-core
Updated Branches:
  refs/heads/ble_hs_api [created] 5ccea9b6c


BLE Host - Update ble_gap_adv_start() API.

* Move own_addr_type from params into a separate parameter.
* Add optional parameter: high_duty_cycle.
* Make read-only parameters const.
* Remove support for default parameters when null is passed.
* Make channel map an optional parameeter.


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

Branch: refs/heads/ble_hs_api
Commit: a3969853398c9b711a2f9d1625d72c9fc2157af3
Parents: b9a61e2
Author: Christopher Collins <cc...@apache.org>
Authored: Tue Jun 21 22:13:13 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Jul 11 16:43:30 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/include/host/ble_gap.h      |  41 ++-
 net/nimble/host/src/ble_gap.c               | 333 ++++++++++++-----------
 net/nimble/host/src/ble_hs_misc.c           |   2 +
 net/nimble/host/src/ble_hs_priv.h           |   5 +-
 net/nimble/host/src/test/ble_gap_test.c     | 177 +++++++++---
 net/nimble/host/src/test/ble_hs_adv_test.c  |  12 +-
 net/nimble/host/src/test/ble_hs_conn_test.c |  67 +----
 net/nimble/host/src/test/ble_hs_test_util.c |  25 +-
 net/nimble/host/src/test/ble_hs_test_util.h |  13 +-
 9 files changed, 384 insertions(+), 291 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a3969853/net/nimble/host/include/host/ble_gap.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/ble_gap.h b/net/nimble/host/include/host/ble_gap.h
index da66ae6..953cfd8 100644
--- a/net/nimble/host/include/host/ble_gap.h
+++ b/net/nimble/host/include/host/ble_gap.h
@@ -24,7 +24,6 @@
 #include "host/ble_hs.h"
 struct hci_le_conn_complete;
 struct hci_conn_update;
-struct hci_adv_params;
 
 /** 30 ms. */
 #define BLE_GAP_ADV_FAST_INTERVAL1_MIN      (30 * 1000 / BLE_HCI_ADV_ITVL)
@@ -71,6 +70,8 @@ struct hci_adv_params;
 /* 50 ms. */
 #define BLE_GAP_INITIAL_CONN_ITVL_MAX       (50 * 1000 / BLE_HCI_CONN_ITVL)
 
+#define BLE_GAP_ADV_DFLT_CHANNEL_MAP        0x07 /* All three channels. */
+
 #define BLE_GAP_INITIAL_CONN_LATENCY        0
 #define BLE_GAP_INITIAL_SUPERVISION_TIMEOUT 0x0100
 #define BLE_GAP_INITIAL_CONN_MIN_CE_LEN     0x0010
@@ -107,13 +108,33 @@ struct ble_gap_sec_state {
     unsigned bonded:1;
 };
 
+/**
+ * @param discoverable_mode     One of the following constants:
+ *                                  o BLE_GAP_DISC_MODE_NON
+ *                                      (non-discoverable; 3.C.9.2.2).
+ *                                  o BLE_GAP_DISC_MODE_LTD
+ *                                      (limited-discoverable; 3.C.9.2.3).
+ *                                  o BLE_GAP_DISC_MODE_GEN
+ *                                      (general-discoverable; 3.C.9.2.4).
+ * @param connectable_mode      One of the following constants:
+ *                                  o BLE_GAP_CONN_MODE_NON
+ *                                      (non-connectable; 3.C.9.3.2).
+ *                                  o BLE_GAP_CONN_MODE_DIR
+ *                                      (directed-connectable; 3.C.9.3.3).
+ *                                  o BLE_GAP_CONN_MODE_UND
+ *                                      (undirected-connectable; 3.C.9.3.4).
+ */
 struct ble_gap_adv_params {
-    uint8_t adv_type;
-    uint8_t adv_channel_map;
-    uint8_t own_addr_type;
-    uint8_t adv_filter_policy;
-    uint16_t adv_itvl_min;
-    uint16_t adv_itvl_max;
+    /*** Mandatory fields. */
+    uint8_t conn_mode;
+    uint8_t disc_mode;
+
+    /*** Optional fields; assign 0 to make the stack calculate them. */
+    uint16_t itvl_min;
+    uint16_t itvl_max;
+    uint8_t channel_map;
+    uint8_t filter_policy;
+    uint8_t high_duty_cycle:1;
 };
 
 struct ble_gap_conn_desc {
@@ -241,11 +262,10 @@ struct ble_gap_white_entry {
 
 int ble_gap_find_conn(uint16_t handle, struct ble_gap_conn_desc *out_desc);
 
-int ble_gap_adv_start(uint8_t discoverable_mode, uint8_t connectable_mode,
-                      uint8_t *peer_addr, uint8_t peer_addr_type,
+int ble_gap_adv_start(uint8_t own_addr_type, uint8_t peer_addr_type,
+                      const uint8_t *peer_addr,
                       const struct ble_gap_adv_params *adv_params,
                       ble_gap_event_fn *cb, void *cb_arg);
-
 int ble_gap_adv_stop(void);
 int ble_gap_adv_set_fields(struct ble_hs_adv_fields *adv_fields);
 int ble_gap_adv_rsp_set_fields(struct ble_hs_adv_fields *rsp_fields);
@@ -268,7 +288,6 @@ int ble_gap_security_initiate(uint16_t conn_handle);
 int ble_gap_pair_initiate(uint16_t conn_handle);
 int ble_gap_encryption_initiate(uint16_t conn_handle, uint8_t *ltk,
                                 uint16_t ediv, uint64_t rand_val, int auth);
-int ble_gap_provide_ltk(uint16_t conn_handle, uint8_t *ltk);
 void ble_gap_init_identity_addr(uint8_t *addr);
 
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a3969853/net/nimble/host/src/ble_gap.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gap.c b/net/nimble/host/src/ble_gap.c
index b2308dc..b187d77 100644
--- a/net/nimble/host/src/ble_gap.c
+++ b/net/nimble/host/src/ble_gap.c
@@ -83,15 +83,6 @@ static const struct ble_gap_conn_params ble_gap_conn_params_dflt = {
     .max_ce_len = BLE_GAP_INITIAL_CONN_MAX_CE_LEN,
 };
 
-static const struct ble_gap_adv_params ble_gap_adv_params_dflt = {
-    .adv_itvl_min = 0,
-    .adv_itvl_max = 0,
-    .adv_type = BLE_HCI_ADV_TYPE_ADV_IND,
-    .own_addr_type = BLE_HCI_ADV_OWN_ADDR_PUBLIC,
-    .adv_channel_map = BLE_HCI_ADV_CHANMASK_DEF,
-    .adv_filter_policy = BLE_HCI_ADV_FILT_DEF,
-};
-
 /**
  * The state of the in-progress master connection.  If no master connection is
  * currently in progress, then the op field is set to BLE_GAP_OP_NULL.
@@ -243,25 +234,25 @@ ble_gap_log_wl(struct ble_gap_white_entry *white_list,
 }
 
 static void
-ble_gap_log_adv(const struct ble_gap_adv_params *adv_params,
-                uint8_t *peer_addr, uint8_t peer_addr_type)
+ble_gap_log_adv(uint8_t own_addr_type, uint8_t peer_addr_type,
+                const uint8_t *peer_addr,
+                const struct ble_gap_adv_params *adv_params)
 {
-    BLE_HS_LOG(INFO, "disc_mode=%d addr_type=%d addr=",
+    BLE_HS_LOG(INFO, "disc_mode=%d peer_addr_type=%d peer_addr=",
                ble_gap_slave.disc_mode, peer_addr_type);
     if(peer_addr) {
         BLE_HS_LOG_ADDR(INFO, peer_addr);
     } else {
         BLE_HS_LOG(INFO, "none");
     }
-    BLE_HS_LOG(INFO, " adv_type=%d adv_channel_map=%d own_addr_type=%d "
+    BLE_HS_LOG(INFO, " adv_channel_map=%d own_addr_type=%d "
                      "adv_filter_policy=%d adv_itvl_min=%d adv_itvl_max=%d "
                      "adv_data_len=%d",
-               adv_params->adv_type,
-               adv_params->adv_channel_map,
-               adv_params->own_addr_type,
-               adv_params->adv_filter_policy,
-               adv_params->adv_itvl_min,
-               adv_params->adv_itvl_max,
+               adv_params->channel_map,
+               own_addr_type,
+               adv_params->filter_policy,
+               adv_params->itvl_min,
+               adv_params->itvl_max,
                ble_gap_slave.adv_data_len);
 }
 
@@ -1190,32 +1181,6 @@ err:
  * $advertise                                                                *
  *****************************************************************************/
 
-static void
-ble_gap_adv_itvls(uint8_t disc_mode, uint8_t conn_mode,
-                  uint16_t *out_itvl_min, uint16_t *out_itvl_max)
-{
-    switch (conn_mode) {
-    case BLE_GAP_CONN_MODE_NON:
-        *out_itvl_min = BLE_GAP_ADV_FAST_INTERVAL2_MIN;
-        *out_itvl_max = BLE_GAP_ADV_FAST_INTERVAL2_MAX;
-        break;
-
-    case BLE_GAP_CONN_MODE_UND:
-        *out_itvl_min = BLE_GAP_ADV_FAST_INTERVAL1_MIN;
-        *out_itvl_max = BLE_GAP_ADV_FAST_INTERVAL1_MAX;
-        break;
-
-    case BLE_GAP_CONN_MODE_DIR:
-        *out_itvl_min = BLE_GAP_ADV_FAST_INTERVAL1_MIN;
-        *out_itvl_max = BLE_GAP_ADV_FAST_INTERVAL1_MAX;
-        break;
-
-    default:
-        BLE_HS_DBG_ASSERT(0);
-        break;
-    }
-}
-
 static int
 ble_gap_adv_enable_tx(void)
 {
@@ -1320,38 +1285,100 @@ ble_gap_adv_data_tx(void)
 }
 
 static int
-ble_gap_adv_params_tx(const struct ble_gap_adv_params *adv_params,
-                      uint8_t *peer_addr, uint8_t peer_addr_type)
+ble_gap_adv_type(const struct ble_gap_adv_params *adv_params)
+{
+    switch (adv_params->conn_mode) {
+    case BLE_GAP_CONN_MODE_NON:
+        if (adv_params->disc_mode == BLE_GAP_DISC_MODE_NON) {
+            return BLE_HCI_ADV_TYPE_ADV_NONCONN_IND;
+        } else {
+            return BLE_HCI_ADV_TYPE_ADV_SCAN_IND;
+        }
+
+    case BLE_GAP_CONN_MODE_UND:
+        return BLE_HCI_ADV_TYPE_ADV_IND;
+
+    case BLE_GAP_CONN_MODE_DIR:
+        if (adv_params->high_duty_cycle) {
+            return BLE_HCI_ADV_TYPE_ADV_DIRECT_IND_HD;
+        } else {
+            return BLE_HCI_ADV_TYPE_ADV_DIRECT_IND_LD;
+        }
+
+    default:
+        BLE_HS_DBG_ASSERT(0);
+        return BLE_HCI_ADV_TYPE_ADV_IND;
+    }
+}
+
+static void
+ble_gap_adv_dflt_itvls(uint8_t conn_mode,
+                       uint16_t *out_itvl_min, uint16_t *out_itvl_max)
+{
+    switch (conn_mode) {
+    case BLE_GAP_CONN_MODE_NON:
+        *out_itvl_min = BLE_GAP_ADV_FAST_INTERVAL2_MIN;
+        *out_itvl_max = BLE_GAP_ADV_FAST_INTERVAL2_MAX;
+        break;
+
+    case BLE_GAP_CONN_MODE_UND:
+        *out_itvl_min = BLE_GAP_ADV_FAST_INTERVAL1_MIN;
+        *out_itvl_max = BLE_GAP_ADV_FAST_INTERVAL1_MAX;
+        break;
+
+    case BLE_GAP_CONN_MODE_DIR:
+        *out_itvl_min = BLE_GAP_ADV_FAST_INTERVAL1_MIN;
+        *out_itvl_max = BLE_GAP_ADV_FAST_INTERVAL1_MAX;
+        break;
+
+    default:
+        BLE_HS_DBG_ASSERT(0);
+        break;
+    }
+}
+
+static int
+ble_gap_adv_params_tx(uint8_t own_addr_type,
+                      uint8_t peer_addr_type, const uint8_t *peer_addr,
+                      const struct ble_gap_adv_params *adv_params)
+
 {
     struct hci_adv_params hci_adv_params;
     uint8_t buf[BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_ADV_PARAM_LEN];
     int rc;
-    uint8_t peer[6];
 
-    if(peer_addr) {
-        memcpy(peer, peer_addr, 6);
-    } else {
-        memset(peer, 0, 6);
+    if (peer_addr == NULL) {
+        peer_addr = ble_hs_misc_null_addr;
     }
 
-    hci_adv_params.adv_channel_map = adv_params->adv_channel_map;
-    hci_adv_params.own_addr_type = adv_params->own_addr_type;
-    hci_adv_params.adv_filter_policy = adv_params->adv_filter_policy;
-    hci_adv_params.adv_itvl_min = adv_params->adv_itvl_min;
-    hci_adv_params.adv_itvl_max = adv_params->adv_itvl_max;
+    hci_adv_params.own_addr_type = own_addr_type;
     hci_adv_params.peer_addr_type = peer_addr_type;
-    hci_adv_params.adv_type = adv_params->adv_type;
-
-    if ((ble_gap_slave.conn_mode == BLE_GAP_CONN_MODE_DIR) ||
-        (adv_params->own_addr_type == BLE_ADDR_TYPE_RPA_PUB_DEFAULT) ||
-        (adv_params->own_addr_type == BLE_ADDR_TYPE_RPA_RND_DEFAULT)) {
-            memcpy(hci_adv_params.peer_addr,peer,
-            sizeof(hci_adv_params.peer_addr));
+    memcpy(hci_adv_params.peer_addr, peer_addr,
+           sizeof hci_adv_params.peer_addr);
+
+    /* Fill optional fields if application did not specify them. */
+    if (adv_params->itvl_min == 0 && adv_params->itvl_max == 0) {
+        ble_gap_adv_dflt_itvls(adv_params->conn_mode,
+                               &hci_adv_params.adv_itvl_min,
+                               &hci_adv_params.adv_itvl_max);
+    } else {
+        hci_adv_params.adv_itvl_min = adv_params->itvl_min;
+        hci_adv_params.adv_itvl_max = adv_params->itvl_max;
     }
+    if (adv_params->channel_map == 0) {
+        hci_adv_params.adv_channel_map = BLE_GAP_ADV_DFLT_CHANNEL_MAP;
+    } else {
+        hci_adv_params.adv_channel_map = adv_params->channel_map;
+    }
+
+    /* Zero is the default value for filter policy and high duty cycle */
+    hci_adv_params.adv_filter_policy = adv_params->filter_policy;
 
-    rc = host_hci_cmd_build_le_set_adv_params(&hci_adv_params, buf, sizeof buf);
+    hci_adv_params.adv_type = ble_gap_adv_type(adv_params);
+    rc = host_hci_cmd_build_le_set_adv_params(&hci_adv_params,
+                                              buf, sizeof buf);
     if (rc != 0) {
-        return rc;
+        return BLE_HS_EINVAL;
     }
 
     rc = ble_hci_cmd_tx_empty_ack(buf);
@@ -1362,67 +1389,47 @@ ble_gap_adv_params_tx(const struct ble_gap_adv_params *adv_params,
     return 0;
 }
 
-/**
- * Enables the specified discoverable mode and connectable mode, and initiates
- * the advertising process.
- *
- * @param discoverable_mode     One of the following constants:
- *                                  o BLE_GAP_DISC_MODE_NON
- *                                      (non-discoverable; 3.C.9.2.2).
- *                                  o BLE_GAP_DISC_MODE_LTD
- *                                      (limited-discoverable; 3.C.9.2.3).
- *                                  o BLE_GAP_DISC_MODE_GEN
- *                                      (general-discoverable; 3.C.9.2.4).
- * @param connectable_mode      One of the following constants:
- *                                  o BLE_GAP_CONN_MODE_NON
- *                                      (non-connectable; 3.C.9.3.2).
- *                                  o BLE_GAP_CONN_MODE_DIR
- *                                      (directed-connectable; 3.C.9.3.3).
- *                                  o BLE_GAP_CONN_MODE_UND
- *                                      (undirected-connectable; 3.C.9.3.4).
- *
- * @return                      0 on success; nonzero on failure.
- */
-int
-ble_gap_adv_start(uint8_t discoverable_mode, uint8_t connectable_mode,
-                  uint8_t *peer_addr, uint8_t peer_addr_type,
-                  const struct ble_gap_adv_params *adv_params,
-                  ble_gap_event_fn *cb, void *cb_arg)
+static int
+ble_gap_adv_validate(uint8_t own_addr_type, uint8_t peer_addr_type,
+                     const uint8_t *peer_addr,
+                     const struct ble_gap_adv_params *adv_params)
 {
-#if !NIMBLE_OPT(ADVERTISE)
-    return BLE_HS_ENOTSUP;
-#endif
-
-    struct ble_gap_adv_params gap_adv_params;
-    int rc;
-
-    ble_hs_lock();
-
-    STATS_INC(ble_gap_stats, adv_start);
-
-    if (ble_gap_slave.op != BLE_GAP_OP_NULL) {
-        rc = BLE_HS_EALREADY;
-        goto done;
+    if (adv_params == NULL) {
+        return BLE_HS_EINVAL;
     }
 
-    if (discoverable_mode >= BLE_GAP_DISC_MODE_MAX) {
-        rc = BLE_HS_EINVAL;
-        goto done;
+    if (own_addr_type > BLE_HCI_ADV_OWN_ADDR_MAX) {
+        return BLE_HS_EINVAL;
     }
 
-    /* Don't initiate a connection procedure if we won't be able to allocate a
-     * connection object on completion.
-     */
-    if (connectable_mode != BLE_GAP_CONN_MODE_NON &&
-        !ble_hs_conn_can_alloc()) {
+    if (adv_params->disc_mode >= BLE_GAP_DISC_MODE_MAX) {
+        return BLE_HS_EINVAL;
+    }
 
-        rc = BLE_HS_ENOMEM;
-        goto done;
+    if (ble_gap_slave.op != BLE_GAP_OP_NULL) {
+        return BLE_HS_EALREADY;
     }
 
-    switch (connectable_mode) {
+    switch (adv_params->conn_mode) {
     case BLE_GAP_CONN_MODE_NON:
+        /* High duty cycle only allowed for directed advertising. */
+        if (adv_params->high_duty_cycle) {
+            return BLE_HS_EINVAL;
+        }
+        break;
+
     case BLE_GAP_CONN_MODE_UND:
+        /* High duty cycle only allowed for directed advertising. */
+        if (adv_params->high_duty_cycle) {
+            return BLE_HS_EINVAL;
+        }
+
+        /* Don't allow connectable advertising if we won't be able to allocate
+         * a new connection.
+         */
+        if (!ble_hs_conn_can_alloc()) {
+            return BLE_HS_ENOMEM;
+        }
         break;
 
     case BLE_GAP_CONN_MODE_DIR:
@@ -1431,69 +1438,76 @@ ble_gap_adv_start(uint8_t discoverable_mode, uint8_t connectable_mode,
             peer_addr_type != BLE_ADDR_TYPE_RPA_PUB_DEFAULT &&
             peer_addr_type != BLE_ADDR_TYPE_RPA_RND_DEFAULT) {
 
-            rc = BLE_HS_EINVAL;
-            goto done;
+            return BLE_HS_EINVAL;
+        }
+        if (peer_addr == NULL) {
+            return BLE_HS_EINVAL;
+        }
+
+        /* Don't allow connectable advertising if we won't be able to allocate
+         * a new connection.
+         */
+        if (!ble_hs_conn_can_alloc()) {
+            return BLE_HS_ENOMEM;
         }
         break;
 
     default:
-        rc = BLE_HS_EINVAL;
-        goto done;
+        return BLE_HS_EINVAL;
     }
 
-    if (adv_params == NULL) {
-        gap_adv_params = ble_gap_adv_params_dflt;
-    } else {
-        gap_adv_params = *adv_params;
-    }
-
-    if (gap_adv_params.own_addr_type > BLE_HCI_ADV_OWN_ADDR_MAX) {
-        rc = BLE_HS_EINVAL;
-        goto done;
-    }
-
-    ble_gap_slave.cb = cb;
-    ble_gap_slave.cb_arg = cb_arg;
-    ble_gap_slave.conn_mode = connectable_mode;
-    ble_gap_slave.disc_mode = discoverable_mode;
-    ble_gap_slave.our_addr_type = gap_adv_params.own_addr_type;
+    return 0;
+}
 
-    ble_gap_adv_itvls(discoverable_mode, connectable_mode,
-                      &gap_adv_params.adv_itvl_min,
-                      &gap_adv_params.adv_itvl_max);
+/**
+ * Enables the specified discoverable mode and connectable mode, and initiates
+ * the advertising process.
+ *
+ * @return                      0 on success; nonzero on failure.
+ */
+int
+ble_gap_adv_start(uint8_t own_addr_type, uint8_t peer_addr_type,
+                  const uint8_t *peer_addr,
+                  const struct ble_gap_adv_params *adv_params,
+                  ble_gap_event_fn *cb, void *cb_arg)
+{
+#if !NIMBLE_OPT(ADVERTISE)
+    return BLE_HS_ENOTSUP;
+#endif
 
-    if (gap_adv_params.own_addr_type == BLE_HCI_ADV_OWN_ADDR_RANDOM) {
-        ble_hs_pvcy_set_our_nrpa();
-    }
+    int rc;
 
-    switch (connectable_mode) {
-    case BLE_GAP_CONN_MODE_NON:
-        gap_adv_params.adv_type = BLE_HCI_ADV_TYPE_ADV_NONCONN_IND;
-        break;
+    ble_hs_lock();
 
-    case BLE_GAP_CONN_MODE_DIR:
-        gap_adv_params.adv_type = BLE_HCI_ADV_TYPE_ADV_DIRECT_IND_HD;
-        break;
+    STATS_INC(ble_gap_stats, adv_start);
 
-    case BLE_GAP_CONN_MODE_UND:
-        gap_adv_params.adv_type = BLE_HCI_ADV_TYPE_ADV_IND;
-        break;
+    rc = ble_gap_adv_validate(own_addr_type, peer_addr_type, peer_addr,
+                              adv_params);
+    if (rc != 0) {
+        goto done;
+    }
 
-    default:
-        BLE_HS_DBG_ASSERT(0);
-        break;
+    if (own_addr_type == BLE_HCI_ADV_OWN_ADDR_RANDOM) {
+        ble_hs_pvcy_set_our_nrpa();
     }
 
     BLE_HS_LOG(INFO, "GAP procedure initiated: advertise; ");
-    ble_gap_log_adv(&gap_adv_params, peer_addr, peer_addr_type);
+    ble_gap_log_adv(own_addr_type, peer_addr_type, peer_addr, adv_params);
     BLE_HS_LOG(INFO, "\n");
 
-    rc = ble_gap_adv_params_tx(&gap_adv_params, peer_addr, peer_addr_type);
+    ble_gap_slave.cb = cb;
+    ble_gap_slave.cb_arg = cb_arg;
+    ble_gap_slave.conn_mode = adv_params->conn_mode;
+    ble_gap_slave.disc_mode = adv_params->disc_mode;
+    ble_gap_slave.our_addr_type = own_addr_type;
+
+    rc = ble_gap_adv_params_tx(own_addr_type, peer_addr_type, peer_addr,
+                               adv_params);
     if (rc != 0) {
         goto done;
     }
 
-    if (ble_gap_slave.conn_mode != BLE_GAP_CONN_MODE_DIR) {
+    if (adv_params->conn_mode != BLE_GAP_CONN_MODE_DIR) {
         rc = ble_gap_adv_data_tx();
         if (rc != 0) {
             goto done;
@@ -1511,7 +1525,6 @@ ble_gap_adv_start(uint8_t discoverable_mode, uint8_t connectable_mode,
     }
 
     ble_gap_slave.op = BLE_GAP_OP_S_ADV;
-
     rc = 0;
 
 done:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a3969853/net/nimble/host/src/ble_hs_misc.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_misc.c b/net/nimble/host/src/ble_hs_misc.c
index 9575ae3..597779c 100644
--- a/net/nimble/host/src/ble_hs_misc.c
+++ b/net/nimble/host/src/ble_hs_misc.c
@@ -23,6 +23,8 @@
 #include "console/console.h"
 #include "ble_hs_priv.h"
 
+const uint8_t ble_hs_misc_null_addr[6];
+
 int
 ble_hs_misc_malloc_mempool(void **mem, struct os_mempool *pool,
                            int num_entries, int entry_size, char *name)

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a3969853/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 1be119a..b902473 100644
--- a/net/nimble/host/src/ble_hs_priv.h
+++ b/net/nimble/host/src/ble_hs_priv.h
@@ -64,13 +64,12 @@ struct ble_hci_ack {
     uint8_t bha_hci_handle;
 };
 
-extern struct ble_hs_dev ble_hs_our_dev;
 extern struct ble_hs_cfg ble_hs_cfg;
-
 extern struct os_mbuf_pool ble_hs_mbuf_pool;
-
 extern struct log ble_hs_log;
 
+extern const uint8_t ble_hs_misc_null_addr[6];
+
 void ble_hs_process_tx_data_queue(void);
 int ble_hs_rx_data(struct os_mbuf *om);
 int ble_hs_tx_data(struct os_mbuf *om);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a3969853/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 5be263f..b55b276 100644
--- a/net/nimble/host/src/test/ble_gap_test.c
+++ b/net/nimble/host/src/test/ble_gap_test.c
@@ -978,12 +978,13 @@ TEST_SUITE(ble_gap_test_suite_conn_terminate)
  *****************************************************************************/
 
 static void
-ble_gap_test_util_adv(uint8_t disc_mode, uint8_t conn_mode,
-                      uint8_t *peer_addr, uint8_t peer_addr_type,
-                      int connect_status,
+ble_gap_test_util_adv(uint8_t own_addr_type, uint8_t peer_addr_type,
+                      const uint8_t *peer_addr, uint8_t conn_mode,
+                      uint8_t disc_mode, int connect_status,
                       int cmd_fail_idx, uint8_t fail_status)
 {
     struct hci_le_conn_complete evt;
+    struct ble_gap_adv_params adv_params;
     struct ble_hs_adv_fields adv_fields;
     uint8_t hci_status;
     int cmd_idx;
@@ -991,6 +992,10 @@ ble_gap_test_util_adv(uint8_t disc_mode, uint8_t conn_mode,
 
     ble_gap_test_util_init();
 
+    adv_params = ble_hs_test_util_adv_params;
+    adv_params.conn_mode = conn_mode;
+    adv_params.disc_mode = disc_mode;
+
     TEST_ASSERT(!ble_gap_slave_in_progress());
 
     cmd_idx = 0;
@@ -1013,8 +1018,8 @@ ble_gap_test_util_adv(uint8_t disc_mode, uint8_t conn_mode,
     }
 
     if (fail_status == 0 || cmd_fail_idx >= cmd_idx) {
-        rc = ble_hs_test_util_adv_start(disc_mode, conn_mode, peer_addr,
-                                        peer_addr_type, NULL,
+        rc = ble_hs_test_util_adv_start(own_addr_type, peer_addr_type,
+                                        peer_addr, &adv_params,
                                         ble_gap_test_util_connect_cb, NULL,
                                         cmd_fail_idx - cmd_idx, fail_status);
 
@@ -1047,7 +1052,9 @@ ble_gap_test_util_adv(uint8_t disc_mode, uint8_t conn_mode,
     }
     cmd_idx++;
 
-    if (fail_status == 0 || cmd_fail_idx >= cmd_idx) {
+    if (connect_status != -1 &&
+        (fail_status == 0 || cmd_fail_idx >= cmd_idx)) {
+
         TEST_ASSERT(ble_gap_slave_in_progress());
 
         /* Receive a connection complete event. */
@@ -1074,49 +1081,139 @@ ble_gap_test_util_adv(uint8_t disc_mode, uint8_t conn_mode,
 
 TEST_CASE(ble_gap_test_case_conn_adv_bad_args)
 {
+    struct ble_gap_adv_params adv_params;
     uint8_t peer_addr[6] = { 1, 2, 3, 4, 5, 6 };
     int rc;
 
     TEST_ASSERT(!ble_gap_slave_in_progress());
 
     /*** Invalid discoverable mode. */
-    rc = ble_hs_test_util_adv_start(-1, BLE_GAP_CONN_MODE_DIR, peer_addr,
-                                    BLE_ADDR_TYPE_PUBLIC, NULL,
+    adv_params = ble_hs_test_util_adv_params;
+    adv_params.disc_mode = 43;
+    rc = ble_hs_test_util_adv_start(BLE_ADDR_TYPE_PUBLIC, BLE_ADDR_TYPE_PUBLIC,
+                                    peer_addr, &adv_params,
                                     ble_gap_test_util_connect_cb, NULL, 0, 0);
     TEST_ASSERT(rc == BLE_HS_EINVAL);
     TEST_ASSERT(!ble_gap_slave_in_progress());
 
     /*** Invalid connectable mode. */
-    rc = ble_hs_test_util_adv_start(BLE_GAP_DISC_MODE_GEN, -1, peer_addr,
-                                    BLE_ADDR_TYPE_PUBLIC, NULL,
+    adv_params = ble_hs_test_util_adv_params;
+    adv_params.conn_mode = 27;
+    rc = ble_hs_test_util_adv_start(BLE_ADDR_TYPE_PUBLIC, BLE_ADDR_TYPE_PUBLIC,
+                                    peer_addr, &adv_params,
                                     ble_gap_test_util_connect_cb, NULL, 0, 0);
     TEST_ASSERT(rc == BLE_HS_EINVAL);
     TEST_ASSERT(!ble_gap_slave_in_progress());
 
     /*** Invalid peer address type with directed advertisable mode. */
-    rc = ble_hs_test_util_adv_start(BLE_GAP_DISC_MODE_GEN,
-                                    BLE_GAP_CONN_MODE_DIR, peer_addr, -1,
-                                    NULL, ble_gap_test_util_connect_cb, NULL,
-                                    0, 0);
+    adv_params = ble_hs_test_util_adv_params;
+    adv_params.conn_mode = BLE_GAP_CONN_MODE_DIR;
+    rc = ble_hs_test_util_adv_start(BLE_ADDR_TYPE_PUBLIC, 12,
+                                    peer_addr, &adv_params,
+                                    ble_gap_test_util_connect_cb, NULL, 0, 0);
     TEST_ASSERT(rc == BLE_HS_EINVAL);
     TEST_ASSERT(!ble_gap_slave_in_progress());
 
     /*** Advertising already in progress. */
-    rc = ble_hs_test_util_adv_start(BLE_GAP_DISC_MODE_GEN,
-                                    BLE_GAP_CONN_MODE_DIR,
-                                    peer_addr, BLE_ADDR_TYPE_PUBLIC, NULL,
+    adv_params = ble_hs_test_util_adv_params;
+    rc = ble_hs_test_util_adv_start(BLE_ADDR_TYPE_PUBLIC, BLE_ADDR_TYPE_PUBLIC,
+                                    peer_addr, &adv_params,
                                     ble_gap_test_util_connect_cb, NULL, 0, 0);
     TEST_ASSERT(rc == 0);
     TEST_ASSERT(ble_gap_slave_in_progress());
 
-    rc = ble_hs_test_util_adv_start(BLE_GAP_DISC_MODE_GEN,
-                                    BLE_GAP_CONN_MODE_DIR,
-                                    peer_addr, BLE_ADDR_TYPE_PUBLIC, NULL,
+    rc = ble_hs_test_util_adv_start(BLE_ADDR_TYPE_PUBLIC, BLE_ADDR_TYPE_PUBLIC,
+                                    peer_addr, &adv_params,
                                     ble_gap_test_util_connect_cb, NULL, 0, 0);
     TEST_ASSERT(rc == BLE_HS_EALREADY);
     TEST_ASSERT(ble_gap_slave_in_progress());
 }
 
+static void
+ble_gap_test_util_adv_verify_dflt_params(uint8_t own_addr_type,
+                                         uint8_t peer_addr_type,
+                                         const uint8_t *peer_addr,
+                                         uint8_t conn_mode,
+                                         uint8_t disc_mode)
+{
+    struct ble_gap_adv_params adv_params;
+    struct hci_adv_params hci_cmd;
+    uint8_t *hci_buf;
+    uint8_t hci_param_len;
+    int rc;
+
+    ble_gap_test_util_init();
+
+    TEST_ASSERT(!ble_gap_slave_in_progress());
+
+    adv_params = ble_hs_test_util_adv_params;
+    adv_params.conn_mode = conn_mode;
+    adv_params.disc_mode = disc_mode;
+
+    /* Let stack calculate all default parameters. */
+    adv_params.itvl_min = 0;
+    adv_params.itvl_max = 0;
+    adv_params.channel_map = 0;
+    adv_params.filter_policy = 0;
+    adv_params.high_duty_cycle = 0;
+
+    rc = ble_hs_test_util_adv_start(BLE_ADDR_TYPE_PUBLIC, BLE_ADDR_TYPE_PUBLIC,
+                                    peer_addr, &adv_params,
+                                    ble_gap_test_util_connect_cb, NULL, 0, 0);
+    TEST_ASSERT_FATAL(rc == 0);
+
+    /* Ensure default parameters properly filled in. */
+    hci_buf = ble_hs_test_util_verify_tx_hci(BLE_HCI_OGF_LE,
+                                             BLE_HCI_OCF_LE_SET_ADV_PARAMS,
+                                             &hci_param_len);
+    TEST_ASSERT_FATAL(hci_buf != NULL);
+    TEST_ASSERT_FATAL(hci_param_len == BLE_HCI_SET_ADV_PARAM_LEN);
+
+    hci_cmd.adv_itvl_min = le16toh(hci_buf + 0);
+    hci_cmd.adv_itvl_max = le16toh(hci_buf + 2);
+    hci_cmd.adv_type = hci_buf[4];
+    hci_cmd.own_addr_type = hci_buf[5];
+    hci_cmd.peer_addr_type = hci_buf[6];
+    memcpy(hci_cmd.peer_addr, hci_buf + 7, 6);
+    hci_cmd.adv_channel_map = hci_buf[13];
+    hci_cmd.adv_filter_policy = hci_buf[14];
+
+    if (conn_mode == BLE_GAP_CONN_MODE_NON) {
+        TEST_ASSERT(hci_cmd.adv_itvl_min == BLE_GAP_ADV_FAST_INTERVAL2_MIN);
+        TEST_ASSERT(hci_cmd.adv_itvl_max == BLE_GAP_ADV_FAST_INTERVAL2_MAX);
+    } else {
+        TEST_ASSERT(hci_cmd.adv_itvl_min == BLE_GAP_ADV_FAST_INTERVAL1_MIN);
+        TEST_ASSERT(hci_cmd.adv_itvl_max == BLE_GAP_ADV_FAST_INTERVAL1_MAX);
+    }
+
+    if (conn_mode == BLE_GAP_CONN_MODE_NON) {
+        if (disc_mode == BLE_GAP_DISC_MODE_NON) {
+            TEST_ASSERT(hci_cmd.adv_type == BLE_HCI_ADV_TYPE_ADV_NONCONN_IND);
+        } else {
+            TEST_ASSERT(hci_cmd.adv_type == BLE_HCI_ADV_TYPE_ADV_SCAN_IND);
+        }
+    } else if (conn_mode == BLE_GAP_CONN_MODE_UND) {
+        TEST_ASSERT(hci_cmd.adv_type == BLE_HCI_ADV_TYPE_ADV_IND);
+    } else {
+        TEST_ASSERT(hci_cmd.adv_type == BLE_HCI_ADV_TYPE_ADV_DIRECT_IND_LD);
+    }
+}
+
+TEST_CASE(ble_gap_test_case_adv_dflt_params)
+{
+    uint8_t peer_addr[6] = { 1, 2, 3, 4, 5, 6 };
+
+    int d;
+    int c;
+
+    for (c = BLE_GAP_CONN_MODE_NON; c < BLE_GAP_CONN_MODE_MAX; c++) {
+        for (d = BLE_GAP_DISC_MODE_NON; d < BLE_GAP_DISC_MODE_MAX; d++) {
+            ble_gap_test_util_adv_verify_dflt_params(
+                BLE_ADDR_TYPE_PUBLIC, BLE_ADDR_TYPE_PUBLIC, peer_addr, c, d);
+        }
+    }
+}
+
 TEST_CASE(ble_gap_test_case_conn_adv_good)
 {
     uint8_t peer_addr[6] = { 1, 2, 3, 4, 5, 6 };
@@ -1125,13 +1222,12 @@ TEST_CASE(ble_gap_test_case_conn_adv_good)
 
     for (c = BLE_GAP_CONN_MODE_NON; c < BLE_GAP_CONN_MODE_MAX; c++) {
         for (d = BLE_GAP_DISC_MODE_NON; d < BLE_GAP_DISC_MODE_MAX; d++) {
-            ble_gap_test_util_adv(d, c, peer_addr, BLE_ADDR_TYPE_PUBLIC,
-                                  BLE_ERR_SUCCESS, -1, 0);
+            ble_gap_test_util_adv(BLE_ADDR_TYPE_PUBLIC, BLE_ADDR_TYPE_PUBLIC,
+                                  peer_addr, c, d, BLE_ERR_SUCCESS, -1, 0);
 
             if (c != BLE_GAP_CONN_MODE_NON) {
                 TEST_ASSERT(!ble_gap_slave_in_progress());
-                TEST_ASSERT(ble_gap_test_conn_event ==
-                            BLE_GAP_EVENT_CONNECT);
+                TEST_ASSERT(ble_gap_test_conn_event == BLE_GAP_EVENT_CONNECT);
                 TEST_ASSERT(ble_gap_test_conn_status == 0);
                 TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2);
                 TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr,
@@ -1148,14 +1244,13 @@ TEST_CASE(ble_gap_test_case_conn_adv_ctlr_fail)
     int d;
     int c;
 
-    for (c = BLE_GAP_CONN_MODE_DIR; c < BLE_GAP_CONN_MODE_MAX; c++) {
+    for (c = BLE_GAP_CONN_MODE_NON + 1; c < BLE_GAP_CONN_MODE_MAX; c++) {
         for (d = BLE_GAP_DISC_MODE_NON; d < BLE_GAP_DISC_MODE_MAX; d++) {
-            ble_gap_test_util_adv(d, c, peer_addr, BLE_ADDR_TYPE_PUBLIC,
-                                  BLE_ERR_DIR_ADV_TMO, -1, 0);
+            ble_gap_test_util_adv(BLE_ADDR_TYPE_PUBLIC, BLE_ADDR_TYPE_PUBLIC,
+                                  peer_addr, c, d, BLE_ERR_DIR_ADV_TMO, -1, 0);
 
             TEST_ASSERT(!ble_gap_slave_in_progress());
-            TEST_ASSERT(ble_gap_test_conn_event ==
-                        BLE_GAP_EVENT_ADV_COMPLETE);
+            TEST_ASSERT(ble_gap_test_conn_event == BLE_GAP_EVENT_ADV_COMPLETE);
             TEST_ASSERT(ble_gap_test_conn_desc.conn_handle ==
                         BLE_HS_CONN_HANDLE_NONE);
             TEST_ASSERT(ble_gap_test_conn_arg == NULL);
@@ -1180,8 +1275,10 @@ TEST_CASE(ble_gap_test_case_conn_adv_hci_fail)
 
         for (d = BLE_GAP_DISC_MODE_NON; d < BLE_GAP_DISC_MODE_MAX; d++) {
             for (fail_idx = 0; fail_idx < num_hci_cmds; fail_idx++) {
-                ble_gap_test_util_adv(d, c, peer_addr, BLE_ADDR_TYPE_PUBLIC,
-                                      0, fail_idx, BLE_ERR_UNSUPPORTED);
+                ble_gap_test_util_adv(BLE_ADDR_TYPE_PUBLIC,
+                                      BLE_ADDR_TYPE_PUBLIC, peer_addr,
+                                      c, d, 0, fail_idx, BLE_ERR_UNSUPPORTED);
+
                 TEST_ASSERT(!ble_gap_slave_in_progress());
                 TEST_ASSERT(ble_gap_test_conn_event == -1);
             }
@@ -1192,6 +1289,7 @@ TEST_CASE(ble_gap_test_case_conn_adv_hci_fail)
 TEST_SUITE(ble_gap_test_suite_conn_adv)
 {
     ble_gap_test_case_conn_adv_bad_args();
+    ble_gap_test_case_adv_dflt_params();
     ble_gap_test_case_conn_adv_good();
     ble_gap_test_case_conn_adv_ctlr_fail();
     ble_gap_test_case_conn_adv_hci_fail();
@@ -1202,8 +1300,8 @@ TEST_SUITE(ble_gap_test_suite_conn_adv)
  *****************************************************************************/
 
 static void
-ble_gap_test_util_stop_adv(uint8_t disc_mode, uint8_t conn_mode,
-                           uint8_t *peer_addr, uint8_t peer_addr_type,
+ble_gap_test_util_stop_adv(uint8_t peer_addr_type, const uint8_t *peer_addr,
+                           uint8_t conn_mode, uint8_t disc_mode,
                            int cmd_fail_idx, uint8_t fail_status)
 {
     uint8_t hci_status;
@@ -1212,16 +1310,11 @@ ble_gap_test_util_stop_adv(uint8_t disc_mode, uint8_t conn_mode,
     ble_gap_test_util_init();
 
     /* Start advertising; don't rx a successful connection event. */
-    ble_gap_test_util_adv(disc_mode, conn_mode, peer_addr,
-                          BLE_ADDR_TYPE_PUBLIC, BLE_ERR_UNSUPPORTED, 0, 0);
+    ble_gap_test_util_adv(BLE_ADDR_TYPE_PUBLIC, peer_addr_type, peer_addr,
+                          conn_mode, disc_mode, -1, -1, 0);
 
     TEST_ASSERT(ble_gap_slave_in_progress());
 
-    /* Clear the advertising event that the host sent; we only care about what
-     * happens after advertising is stopped.
-     */
-    ble_gap_test_util_reset_cb_info();
-
     /* Stop advertising. */
     hci_status = cmd_fail_idx == 0 ? fail_status : 0;
 
@@ -1240,7 +1333,7 @@ TEST_CASE(ble_gap_test_case_conn_stop_adv_good)
 
     for (c = BLE_GAP_CONN_MODE_NON; c < BLE_GAP_CONN_MODE_MAX; c++) {
         for (d = BLE_GAP_DISC_MODE_NON; d < BLE_GAP_DISC_MODE_MAX; d++) {
-            ble_gap_test_util_stop_adv(d, c, peer_addr, BLE_ADDR_TYPE_PUBLIC,
+            ble_gap_test_util_stop_adv(BLE_ADDR_TYPE_PUBLIC, peer_addr, c, d,
                                        -1, 0);
             TEST_ASSERT(!ble_gap_slave_in_progress());
             TEST_ASSERT(ble_gap_test_conn_event == -1);
@@ -1259,7 +1352,7 @@ TEST_CASE(ble_gap_test_case_conn_stop_adv_hci_fail)
 
     for (c = BLE_GAP_CONN_MODE_NON; c < BLE_GAP_CONN_MODE_MAX; c++) {
         for (d = BLE_GAP_DISC_MODE_NON; d < BLE_GAP_DISC_MODE_MAX; d++) {
-            ble_gap_test_util_stop_adv(d, c, peer_addr, BLE_ADDR_TYPE_PUBLIC,
+            ble_gap_test_util_stop_adv(BLE_ADDR_TYPE_PUBLIC, peer_addr, c, d,
                                        0, BLE_ERR_UNSUPPORTED);
             TEST_ASSERT(ble_gap_slave_in_progress());
             TEST_ASSERT(ble_gap_test_conn_event == -1);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a3969853/net/nimble/host/src/test/ble_hs_adv_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_hs_adv_test.c b/net/nimble/host/src/test/ble_hs_adv_test.c
index a9ba2b7..1cd4370 100644
--- a/net/nimble/host/src/test/ble_hs_adv_test.c
+++ b/net/nimble/host/src/test/ble_hs_adv_test.c
@@ -140,18 +140,22 @@ ble_hs_adv_test_misc_tx_and_verify_data(
     struct ble_hs_adv_fields *rsp_fields,
     struct ble_hs_adv_test_field *test_rsp_fields)
 {
+    struct ble_gap_adv_params adv_params;
     int rc;
 
     ble_hs_test_util_init();
 
+    adv_params = ble_hs_test_util_adv_params;
+    adv_params.disc_mode = disc_mode;
+
     rc = ble_hs_test_util_adv_set_fields(adv_fields, 0);
     TEST_ASSERT_FATAL(rc == 0);
 
     rc = ble_gap_adv_rsp_set_fields(rsp_fields);
     TEST_ASSERT_FATAL(rc == 0);
 
-    rc = ble_hs_test_util_adv_start(disc_mode, BLE_GAP_CONN_MODE_UND, NULL, 0,
-                                    NULL, NULL, NULL, 0, 0);
+    rc = ble_hs_test_util_adv_start(BLE_ADDR_TYPE_PUBLIC, 0, NULL, &adv_params,
+                                    NULL, NULL, 0, 0);
     TEST_ASSERT_FATAL(rc == 0);
 
     /* Discard the adv-enable command. */
@@ -164,8 +168,8 @@ ble_hs_adv_test_misc_tx_and_verify_data(
     rc = ble_hs_test_util_adv_stop(0);
     TEST_ASSERT_FATAL(rc == 0);
 
-    rc = ble_hs_test_util_adv_start(disc_mode, BLE_GAP_CONN_MODE_UND, NULL, 0,
-                                    NULL, NULL, NULL, 0, 0);
+    rc = ble_hs_test_util_adv_start(BLE_ADDR_TYPE_PUBLIC, 0, NULL, &adv_params,
+                                    NULL, NULL, 0, 0);
     TEST_ASSERT_FATAL(rc == 0);
 
     /* Discard the adv-enable command. */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a3969853/net/nimble/host/src/test/ble_hs_conn_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_hs_conn_test.c b/net/nimble/host/src/test/ble_hs_conn_test.c
index 41d80fa..50d70c9 100644
--- a/net/nimble/host/src/test/ble_hs_conn_test.c
+++ b/net/nimble/host/src/test/ble_hs_conn_test.c
@@ -87,29 +87,10 @@ TEST_CASE(ble_hs_conn_test_direct_connect_success)
     ble_hs_unlock();
 }
 
-TEST_CASE(ble_hs_conn_test_direct_connect_hci_errors)
-{
-    uint8_t addr[6] = { 1, 2, 3, 4, 5, 6 };
-    int rc;
-
-    ble_hs_test_util_init();
-
-    /* Ensure no current or pending connections. */
-    TEST_ASSERT(!ble_gap_master_in_progress());
-    TEST_ASSERT(!ble_hs_conn_test_util_any());
-
-    /* Initiate connection; receive no HCI ack. */
-    rc = ble_gap_connect(BLE_ADDR_TYPE_PUBLIC, BLE_ADDR_TYPE_PUBLIC,
-                               addr, NULL, NULL, NULL);
-    TEST_ASSERT(rc == BLE_HS_ETIMEOUT_HCI);
-
-    TEST_ASSERT(!ble_gap_master_in_progress());
-    TEST_ASSERT(!ble_hs_conn_test_util_any());
-}
-
 TEST_CASE(ble_hs_conn_test_direct_connectable_success)
 {
     struct hci_le_conn_complete evt;
+    struct ble_gap_adv_params adv_params;
     struct ble_l2cap_chan *chan;
     struct ble_hs_conn *conn;
     uint8_t addr[6] = { 1, 2, 3, 4, 5, 6 };
@@ -123,10 +104,10 @@ TEST_CASE(ble_hs_conn_test_direct_connectable_success)
     TEST_ASSERT(!ble_hs_conn_test_util_any());
 
     /* Initiate advertising. */
-    rc = ble_hs_test_util_adv_start(BLE_GAP_DISC_MODE_NON,
-                                    BLE_GAP_CONN_MODE_DIR, addr,
-                                    BLE_HCI_ADV_PEER_ADDR_PUBLIC, NULL, NULL,
-                                    NULL, 0, 0);
+    adv_params = ble_hs_test_util_adv_params;
+    adv_params.conn_mode = BLE_GAP_CONN_MODE_DIR;
+    rc = ble_hs_test_util_adv_start(BLE_ADDR_TYPE_PUBLIC, BLE_ADDR_TYPE_PUBLIC,
+                                    addr, &adv_params, NULL, NULL, 0, 0);
     TEST_ASSERT(rc == 0);
 
     TEST_ASSERT(!ble_gap_master_in_progress());
@@ -160,38 +141,11 @@ TEST_CASE(ble_hs_conn_test_direct_connectable_success)
     ble_hs_unlock();
 }
 
-TEST_CASE(ble_hs_conn_test_direct_connectable_hci_errors)
-{
-    struct hci_le_conn_complete evt;
-    uint8_t addr[6] = { 1, 2, 3, 4, 5, 6 };
-    int rc;
-
-    ble_hs_test_util_init();
-
-    /* Ensure no current or pending connections. */
-    TEST_ASSERT(!ble_gap_slave_in_progress());
-    TEST_ASSERT(!ble_hs_conn_test_util_any());
-
-    /* Initiate connection. */
-    rc = ble_hs_test_util_adv_start(BLE_GAP_DISC_MODE_NON,
-                                    BLE_GAP_CONN_MODE_DIR, addr,
-                                    BLE_HCI_ADV_PEER_ADDR_PUBLIC, NULL, NULL,
-                                    NULL, 0, 0);
-    TEST_ASSERT(rc == 0);
-    TEST_ASSERT(ble_gap_slave_in_progress());
-
-    /* Receive failure connection complete event. */
-    evt.status = BLE_ERR_UNSPECIFIED;
-    rc = ble_gap_rx_conn_complete(&evt);
-    TEST_ASSERT(rc == 0);
-    TEST_ASSERT(ble_gap_slave_in_progress());
-    TEST_ASSERT(!ble_hs_conn_test_util_any());
-}
-
 TEST_CASE(ble_hs_conn_test_undirect_connectable_success)
 {
     struct ble_hs_adv_fields adv_fields;
     struct hci_le_conn_complete evt;
+    struct ble_gap_adv_params adv_params;
     struct ble_l2cap_chan *chan;
     struct ble_hs_conn *conn;
     uint8_t addr[6] = { 1, 2, 3, 4, 5, 6 };
@@ -210,9 +164,10 @@ TEST_CASE(ble_hs_conn_test_undirect_connectable_success)
     rc = ble_gap_adv_set_fields(&adv_fields);
     TEST_ASSERT_FATAL(rc == 0);
 
-    rc = ble_hs_test_util_adv_start(BLE_GAP_DISC_MODE_NON,
-                                    BLE_GAP_CONN_MODE_UND, NULL, 0, NULL,
-                                    NULL, NULL, 0, 0);
+    adv_params = ble_hs_test_util_adv_params;
+    adv_params.conn_mode = BLE_GAP_CONN_MODE_UND;
+    rc = ble_hs_test_util_adv_start(BLE_ADDR_TYPE_PUBLIC, BLE_ADDR_TYPE_PUBLIC,
+                                    addr, &adv_params, NULL, NULL, 0, 0);
     TEST_ASSERT(rc == 0);
 
     TEST_ASSERT(!ble_gap_master_in_progress());
@@ -249,9 +204,7 @@ TEST_CASE(ble_hs_conn_test_undirect_connectable_success)
 TEST_SUITE(conn_suite)
 {
     ble_hs_conn_test_direct_connect_success();
-    ble_hs_conn_test_direct_connect_hci_errors();
     ble_hs_conn_test_direct_connectable_success();
-    ble_hs_conn_test_direct_connectable_hci_errors();
     ble_hs_conn_test_undirect_connectable_success();
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a3969853/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 6acb9e7..383386d 100644
--- a/net/nimble/host/src/test/ble_hs_test_util.c
+++ b/net/nimble/host/src/test/ble_hs_test_util.c
@@ -54,6 +54,17 @@ int ble_hs_test_util_num_prev_hci_txes;
 
 uint8_t ble_hs_test_util_cur_hci_tx[260];
 
+const struct ble_gap_adv_params ble_hs_test_util_adv_params = {
+    .conn_mode = BLE_GAP_CONN_MODE_UND,
+    .disc_mode = BLE_GAP_DISC_MODE_GEN,
+
+    .itvl_min = 0,
+    .itvl_max = 0,
+    .channel_map = 0,
+    .filter_policy = 0,
+    .high_duty_cycle = 0,
+};
+
 void
 ble_hs_test_util_prev_tx_enqueue(struct os_mbuf *om)
 {
@@ -490,10 +501,9 @@ ble_hs_test_util_adv_set_fields(struct ble_hs_adv_fields *adv_fields,
 }
 
 int
-ble_hs_test_util_adv_start(uint8_t discoverable_mode,
-                           uint8_t connectable_mode,
-                           uint8_t *peer_addr, uint8_t peer_addr_type,
-                           struct ble_gap_adv_params *adv_params,
+ble_hs_test_util_adv_start(uint8_t own_addr_type,
+                           uint8_t peer_addr_type, const uint8_t *peer_addr, 
+                           const struct ble_gap_adv_params *adv_params,
                            ble_gap_event_fn *cb, void *cb_arg,
                            int fail_idx, uint8_t fail_status)
 {
@@ -509,7 +519,7 @@ ble_hs_test_util_adv_start(uint8_t discoverable_mode,
     };
     i++;
 
-    if (connectable_mode != BLE_GAP_CONN_MODE_DIR) {
+    if (adv_params->conn_mode != BLE_GAP_CONN_MODE_DIR) {
         acks[i] = (struct ble_hs_test_util_phony_ack) {
             BLE_HS_TEST_UTIL_LE_OPCODE(BLE_HCI_OCF_LE_RD_ADV_CHAN_TXPWR),
             ble_hs_test_util_exp_hci_status(i, fail_idx, fail_status),
@@ -541,9 +551,8 @@ ble_hs_test_util_adv_start(uint8_t discoverable_mode,
 
     ble_hs_test_util_set_ack_seq(acks);
     
-    rc = ble_gap_adv_start(discoverable_mode, connectable_mode, 
-                        peer_addr, peer_addr_type,
-                        adv_params, cb, cb_arg);
+    rc = ble_gap_adv_start(own_addr_type, peer_addr_type, peer_addr, 
+                           adv_params, cb, cb_arg);
 
     return rc;
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a3969853/net/nimble/host/src/test/ble_hs_test_util.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_hs_test_util.h b/net/nimble/host/src/test/ble_hs_test_util.h
index 30efd03..a242e44 100644
--- a/net/nimble/host/src/test/ble_hs_test_util.h
+++ b/net/nimble/host/src/test/ble_hs_test_util.h
@@ -6,7 +6,7 @@
  * to you under the Apache License, Version 2.0 (the
  * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
- * 
+ *
  *  http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing,
@@ -28,7 +28,8 @@ struct ble_hs_conn;
 struct ble_l2cap_chan;
 struct hci_disconn_complete;
 
-struct os_eventq ble_hs_test_util_evq;
+extern struct os_eventq ble_hs_test_util_evq;
+extern const struct ble_gap_adv_params ble_hs_test_util_adv_params;
 
 struct ble_hs_test_util_num_completed_pkts_entry {
     uint16_t handle_id; /* 0 for terminating entry in array. */
@@ -79,10 +80,10 @@ int ble_hs_test_util_disc(uint32_t duration_ms, uint8_t discovery_mode,
                           uint8_t fail_status);
 int ble_hs_test_util_adv_set_fields(struct ble_hs_adv_fields *adv_fields,
                                     uint8_t hci_status);
-int ble_hs_test_util_adv_start(uint8_t discoverable_mode,
-                               uint8_t connectable_mode,
-                               uint8_t *peer_addr, uint8_t peer_addr_type,
-                               struct ble_gap_adv_params *adv_params,
+int ble_hs_test_util_adv_start(uint8_t own_addr_type,
+                               uint8_t peer_addr_type,
+                               const uint8_t *peer_addr,
+                               const struct ble_gap_adv_params *adv_params,
                                ble_gap_event_fn *cb, void *cb_arg,
                                int fail_idx, uint8_t fail_status);
 int ble_hs_test_util_adv_stop(uint8_t hci_status);



[07/50] [abbrv] incubator-mynewt-core git commit: bletiny - Use new advertise API.

Posted by cc...@apache.org.
bletiny - Use new advertise API.


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

Branch: refs/heads/ble_hs_api
Commit: b014354810228558d83530c5550d781229e6f0d7
Parents: a396985
Author: Christopher Collins <cc...@apache.org>
Authored: Wed Jun 22 13:25:32 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Jul 11 16:43:30 2016 -0700

----------------------------------------------------------------------
 apps/bletiny/src/bletiny.h |  13 ++--
 apps/bletiny/src/cmd.c     | 141 +++++++++++++++++++++-------------------
 apps/bletiny/src/main.c    |   8 +--
 apps/bletiny/src/parse.c   |  45 +++++++++----
 4 files changed, 117 insertions(+), 90 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b0143548/apps/bletiny/src/bletiny.h
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/bletiny.h b/apps/bletiny/src/bletiny.h
index 1ec08c9..9694744 100644
--- a/apps/bletiny/src/bletiny.h
+++ b/apps/bletiny/src/bletiny.h
@@ -100,6 +100,8 @@ const struct cmd_entry *parse_cmd_find(const struct cmd_entry *cmds,
 struct kv_pair *parse_kv_find(struct kv_pair *kvs, char *name);
 char *parse_arg_find(char *key);
 long parse_arg_long_bounds(char *name, long min, long max, int *out_status);
+long parse_arg_long_bounds_default(char *name, long min, long max,
+                                   long dflt, int *out_status);
 uint64_t parse_arg_uint64_bounds(char *name, uint64_t min,
                                  uint64_t max, int *out_status);
 long parse_arg_long(char *name, int *staus);
@@ -109,8 +111,9 @@ uint16_t parse_arg_uint16(char *name, int *status);
 uint16_t parse_arg_uint16_dflt(char *name, uint16_t dflt, int *out_status);
 uint32_t parse_arg_uint32(char *name, int *out_status);
 uint64_t parse_arg_uint64(char *name, int *out_status);
-int parse_arg_kv(char *name, struct kv_pair *kvs);
-int parse_arg_kv_default(char *name, struct kv_pair *kvs, int def_val);
+int parse_arg_kv(char *name, struct kv_pair *kvs, int *out_status);
+int parse_arg_kv_default(char *name, struct kv_pair *kvs, int def_val,
+                         int *out_status);
 int parse_arg_byte_stream(char *name, int max_len, uint8_t *dst, int *out_len);
 int parse_arg_byte_stream_exact_length(char *name, uint8_t *dst, int len);
 int parse_arg_mac(char *name, uint8_t *dst);
@@ -151,9 +154,9 @@ int bletiny_write_long(uint16_t conn_handle, uint16_t attr_handle,
                         void *value, uint16_t value_len);
 int bletiny_write_reliable(uint16_t conn_handle, struct ble_gatt_attr *attrs,
                             int num_attrs);
-int bletiny_adv_start(int disc, int conn,
-                     uint8_t *peer_addr, uint8_t peer_addr_type,
-                     struct ble_gap_adv_params *params);
+int bletiny_adv_start(uint8_t own_addr_type, uint8_t peer_addr_type,
+                      const uint8_t *peer_addr,
+                      const struct ble_gap_adv_params *params);
 int bletiny_adv_stop(void);
 int bletiny_conn_initiate(uint8_t own_addr_type,
                           uint8_t peer_addr_type, uint8_t *peer_addr,

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b0143548/apps/bletiny/src/cmd.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/cmd.c b/apps/bletiny/src/cmd.c
index 26fa807..c6f2019 100644
--- a/apps/bletiny/src/cmd.c
+++ b/apps/bletiny/src/cmd.c
@@ -259,20 +259,10 @@ static struct kv_pair cmd_adv_filt_types[] = {
 static int
 cmd_adv(int argc, char **argv)
 {
-    struct ble_gap_adv_params params = {
-        .adv_itvl_min = 0,
-        .adv_itvl_max = 0,
-        .adv_type = BLE_HCI_ADV_TYPE_ADV_IND,
-        .own_addr_type = BLE_HCI_ADV_OWN_ADDR_PUBLIC,
-        .adv_channel_map = BLE_HCI_ADV_CHANMASK_DEF,
-        .adv_filter_policy = BLE_HCI_ADV_FILT_DEF,
-    };
-    uint8_t u8;
+    struct ble_gap_adv_params params;
     uint8_t peer_addr_type;
+    uint8_t own_addr_type;
     uint8_t peer_addr[8];
-    int addr_type;
-    int conn;
-    int disc;
     int rc;
 
     if (argc > 1 && strcmp(argv[1], "stop") == 0) {
@@ -285,22 +275,24 @@ cmd_adv(int argc, char **argv)
         return 0;
     }
 
-    conn = parse_arg_kv("conn", cmd_adv_conn_modes);
-    if (conn <  0) {
+    params.conn_mode = parse_arg_kv_default("conn", cmd_adv_conn_modes,
+                                            BLE_GAP_CONN_MODE_UND, &rc);
+    if (rc != 0) {
         console_printf("invalid 'conn' parameter\n");
-        return -1;
+        return rc;
     }
 
-    disc = parse_arg_kv("disc", cmd_adv_disc_modes);
-    if (conn <  0) {
-        console_printf("missing 'disc' parameter\n");
-        return -1;
+    params.disc_mode = parse_arg_kv_default("disc", cmd_adv_disc_modes,
+                                            BLE_GAP_DISC_MODE_GEN, &rc);
+    if (rc != 0) {
+        console_printf("invalid 'disc' parameter\n");
+        return rc;
     }
 
-    addr_type = parse_arg_kv_default
-            ("peer_addr_type", cmd_adv_addr_types, BLE_ADDR_TYPE_PUBLIC);
-    if (addr_type == -1) {
-        return -1;
+    peer_addr_type = parse_arg_kv_default(
+        "peer_addr_type", cmd_adv_addr_types, BLE_ADDR_TYPE_PUBLIC, &rc);
+    if (rc != 0) {
+        return rc;
     }
 
     rc = parse_arg_mac("peer_addr", peer_addr);
@@ -310,31 +302,37 @@ cmd_adv(int argc, char **argv)
         return rc;
     }
 
-    peer_addr_type = addr_type;
+    own_addr_type = parse_arg_kv_default(
+        "own_addr_type", cmd_adv_addr_types, BLE_ADDR_TYPE_PUBLIC, &rc);
+    if (rc != 0) {
+        return rc;
+    }
 
-    rc = parse_arg_kv_default
-                ("own_addr_type", cmd_adv_addr_types, BLE_ADDR_TYPE_PUBLIC);
-    if (rc == -1) {
+    params.channel_map = parse_arg_long_bounds_default("chan_map", 0, 0xff, 0,
+                                                       &rc);
+    if (rc != 0) {
         return rc;
     }
 
-    params.own_addr_type = rc;
+    params.filter_policy = parse_arg_kv_default("filt", cmd_adv_filt_types,
+                                                BLE_HCI_ADV_FILT_NONE, &rc);
+    if (rc != 0) {
+        return rc;
+    }
 
-    u8 = parse_arg_long_bounds("chan_map", 0, 0xff, &rc);
-    if (rc == 0) {
-        params.adv_channel_map = u8;
-    } else if (rc != ENOENT) {
+    params.itvl_min = parse_arg_long_bounds_default("itvl_min", 0, UINT16_MAX,
+                                                    0, &rc);
+    if (rc != 0) {
         return rc;
     }
 
-    if (parse_arg_find("filt") != NULL) {
-        params.adv_filter_policy = parse_arg_kv("filt", cmd_adv_filt_types);
-        if (params.adv_filter_policy == -1) {
-            return EINVAL;
-        }
+    params.itvl_max = parse_arg_long_bounds_default("itvl_max", 0, UINT16_MAX,
+                                                    0, &rc);
+    if (rc != 0) {
+        return rc;
     }
 
-    rc = bletiny_adv_start(disc, conn, peer_addr, peer_addr_type, &params);
+    rc = bletiny_adv_start(own_addr_type, peer_addr_type, peer_addr, &params);
     if (rc != 0) {
         console_printf("advertise fail: %d\n", rc);
         return rc;
@@ -383,9 +381,10 @@ cmd_conn(int argc, char **argv)
         return 0;
     }
 
-    peer_addr_type = parse_arg_kv("peer_addr_type", cmd_conn_peer_addr_types);
-    if (peer_addr_type == -1) {
-        return -1;
+    peer_addr_type = parse_arg_kv("peer_addr_type", cmd_conn_peer_addr_types,
+                                  &rc);
+    if (rc != 0) {
+        return rc;
     }
 
     if (peer_addr_type != BLE_GAP_ADDR_TYPE_WL) {
@@ -404,8 +403,8 @@ cmd_conn(int argc, char **argv)
 
     own_addr_type = parse_arg_kv_default("own_addr_type",
                                          cmd_conn_own_addr_types,
-                                         BLE_ADDR_TYPE_PUBLIC);
-    if (own_addr_type < 0) {
+                                         BLE_ADDR_TYPE_PUBLIC, &rc);
+    if (rc != 0) {
         return rc;
     }
 
@@ -952,25 +951,28 @@ cmd_scan(int argc, char **argv)
         return rc;
     }
 
-    disc = parse_arg_kv("disc", cmd_scan_disc_modes);
-    if (disc < 0) {
-        return EINVAL;
+    disc = parse_arg_kv_default("disc", cmd_scan_disc_modes,
+                                BLE_GAP_DISC_MODE_GEN, &rc);
+    if (rc != 0) {
+        return rc;
     }
 
-    type = parse_arg_kv("type", cmd_scan_types);
-    if (type < 0) {
-        return EINVAL;
+    type = parse_arg_kv_default("type", cmd_scan_types,
+                                BLE_HCI_SCAN_TYPE_ACTIVE, &rc);
+    if (rc != 0) {
+        return rc;
     }
 
-    filt = parse_arg_kv("filt", cmd_scan_filt_policies);
-    if (filt < 0) {
-        return EINVAL;
+    filt = parse_arg_kv_default("filt", cmd_scan_filt_policies,
+                                BLE_HCI_SCAN_FILT_NO_WL, &rc);
+    if (rc != 0) {
+        return rc;
     }
 
-    addr_mode = parse_arg_kv_default("addr_mode",
-                                    cmd_scan_addr_types, BLE_ADDR_TYPE_PUBLIC);
-    if (addr_mode == -1) {
-        return EINVAL;
+    addr_mode = parse_arg_kv_default("addr_mode", cmd_scan_addr_types,
+                                     BLE_ADDR_TYPE_PUBLIC, &rc);
+    if (rc != 0) {
+        return rc;
     }
 
     rc = bletiny_scan(dur, disc, type, filt, addr_mode);
@@ -1707,9 +1709,9 @@ cmd_wl(int argc, char **argv)
             return rc;
         }
 
-        addr_type = parse_arg_kv("addr_type", cmd_wl_addr_types);
-        if (addr_type == -1) {
-            return EINVAL;
+        addr_type = parse_arg_kv("addr_type", cmd_wl_addr_types, &rc);
+        if (rc != 0) {
+            return rc;
         }
 
         memcpy(white_list[wl_cnt].addr, addr, 6);
@@ -1848,14 +1850,17 @@ cmd_keystore_parse_keydata(int argc, char **argv, union ble_store_key *out,
     int rc;
 
     memset(out, 0, sizeof(*out));
-    *obj_type = parse_arg_kv("type", cmd_keystore_entry_type);
+    *obj_type = parse_arg_kv("type", cmd_keystore_entry_type, &rc);
+    if (rc != 0) {
+        return rc;
+    }
 
     switch (*obj_type) {
     case BLE_STORE_OBJ_TYPE_PEER_SEC:
     case BLE_STORE_OBJ_TYPE_OUR_SEC:
-        rc = parse_arg_kv("addr_type", cmd_keystore_addr_type);
-        if (rc < 0) {
-            return EINVAL;
+        rc = parse_arg_kv("addr_type", cmd_keystore_addr_type, &rc);
+        if (rc != 0) {
+            return rc;
         }
 
         rc = parse_arg_mac("addr", out->sec.peer_addr);
@@ -1875,7 +1880,7 @@ cmd_keystore_parse_keydata(int argc, char **argv, union ble_store_key *out,
         return 0;
 
     default:
-        return -1;
+        return EINVAL;
     }
 }
 
@@ -2023,11 +2028,11 @@ static int
 cmd_keystore_show(int argc, char **argv)
 {
     int type;
+    int rc;
 
-    type = parse_arg_kv("type", cmd_keystore_entry_type);
-
-    if (type < 0) {
-        return type;
+    type = parse_arg_kv("type", cmd_keystore_entry_type, &rc);
+    if (rc != 0) {
+        return rc;
     }
 
     ble_store_iterate(type, &cmd_keystore_iterator, NULL);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b0143548/apps/bletiny/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/main.c b/apps/bletiny/src/main.c
index d7548c8..c4b2856 100755
--- a/apps/bletiny/src/main.c
+++ b/apps/bletiny/src/main.c
@@ -1246,13 +1246,13 @@ bletiny_adv_stop(void)
 }
 
 int
-bletiny_adv_start(int disc, int conn,
-                uint8_t *peer_addr, uint8_t peer_addr_type,
-                struct ble_gap_adv_params *params)
+bletiny_adv_start(uint8_t own_addr_type, uint8_t peer_addr_type,
+                  const uint8_t *peer_addr,
+                  const struct ble_gap_adv_params *params)
 {
     int rc;
 
-    rc = ble_gap_adv_start(disc, conn, peer_addr, peer_addr_type, params,
+    rc = ble_gap_adv_start(own_addr_type, peer_addr_type, peer_addr, params,
                            bletiny_gap_event, NULL);
     return rc;
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b0143548/apps/bletiny/src/parse.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/parse.c b/apps/bletiny/src/parse.c
index a739d3d..d5c64c5 100644
--- a/apps/bletiny/src/parse.c
+++ b/apps/bletiny/src/parse.c
@@ -129,6 +129,24 @@ parse_arg_long_bounds(char *name, long min, long max, int *out_status)
     return 0;
 }
 
+long
+parse_arg_long_bounds_default(char *name, long min, long max,
+                              long dflt, int *out_status)
+{
+    long val;
+    int rc;
+
+    val = parse_arg_long_bounds(name, min, max, &rc);
+    if (rc == ENOENT) {
+        rc = 0;
+        val = dflt;
+    }
+
+    *out_status = rc;
+
+    return val;
+}
+
 uint64_t
 parse_arg_uint64_bounds(char *name, uint64_t min, uint64_t max, int *out_status)
 {
@@ -207,41 +225,42 @@ parse_arg_uint16_dflt(char *name, uint16_t dflt, int *out_status)
 }
 
 int
-parse_arg_kv(char *name, struct kv_pair *kvs)
+parse_arg_kv(char *name, struct kv_pair *kvs, int *out_status)
 {
     struct kv_pair *kv;
     char *sval;
 
     sval = parse_arg_find(name);
     if (sval == NULL) {
+        *out_status = ENOENT;
         return -1;
     }
 
     kv = parse_kv_find(kvs, sval);
     if (kv == NULL) {
-        return -2;
+        *out_status = EINVAL;
+        return -1;
     }
 
     return kv->val;
 }
 
 int
-parse_arg_kv_default(char *name, struct kv_pair *kvs, int def_val)
+parse_arg_kv_default(char *name, struct kv_pair *kvs, int def_val,
+                     int *out_status)
 {
-    struct kv_pair *kv;
-    char *sval;
+    int val;
+    int rc;
 
-    sval = parse_arg_find(name);
-    if (sval == NULL) {
-        return def_val;
+    val = parse_arg_kv(name, kvs, &rc);
+    if (rc == ENOENT) {
+        rc = 0;
+        val = def_val;
     }
 
-    kv = parse_kv_find(kvs, sval);
-    if (kv == NULL) {
-        return -1;
-    }
+    *out_status = rc;
 
-    return kv->val;
+    return val;
 }
 
 


[29/50] [abbrv] incubator-mynewt-core git commit: BLE Host - Clean up error codes.

Posted by cc...@apache.org.
BLE Host - Clean up error codes.


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

Branch: refs/heads/ble_hs_api
Commit: cd4283ec4d0d4c80e0459c57093b55da47ae70a9
Parents: faed993
Author: Christopher Collins <cc...@apache.org>
Authored: Tue Jul 5 12:18:03 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Jul 11 16:43:33 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/include/host/ble_att.h | 5 ++++-
 net/nimble/include/nimble/ble.h        | 1 -
 2 files changed, 4 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/cd4283ec/net/nimble/host/include/host/ble_att.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/ble_att.h b/net/nimble/host/include/host/ble_att.h
index f25b8e2..848943e 100644
--- a/net/nimble/host/include/host/ble_att.h
+++ b/net/nimble/host/include/host/ble_att.h
@@ -31,14 +31,17 @@
 #define BLE_ATT_ERR_READ_NOT_PERMITTED      0x02
 #define BLE_ATT_ERR_WRITE_NOT_PERMITTED     0x03
 #define BLE_ATT_ERR_INVALID_PDU             0x04
-#define BLE_ATT_ERR_INSUFFICIENT_AUTHENT    0x05
+#define BLE_ATT_ERR_INSUFFICIENT_AUTHEN     0x05
 #define BLE_ATT_ERR_REQ_NOT_SUPPORTED       0x06
 #define BLE_ATT_ERR_INVALID_OFFSET          0x07
+#define BLE_ATT_ERR_INSUFFICIENT_AUTHOR     0x08
 #define BLE_ATT_ERR_PREPARE_QUEUE_FULL      0x09
 #define BLE_ATT_ERR_ATTR_NOT_FOUND          0x0a
 #define BLE_ATT_ERR_ATTR_NOT_LONG           0x0b
+#define BLE_ATT_ERR_INSUFFICIENT_KEY_SZ     0x0c
 #define BLE_ATT_ERR_INVALID_ATTR_VALUE_LEN  0x0d
 #define BLE_ATT_ERR_UNLIKELY                0x0e
+#define BLE_ATT_ERR_INSUFFICIENT_ENC        0x0f
 #define BLE_ATT_ERR_UNSUPPORTED_GROUP       0x10
 #define BLE_ATT_ERR_INSUFFICIENT_RES        0x11
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/cd4283ec/net/nimble/include/nimble/ble.h
----------------------------------------------------------------------
diff --git a/net/nimble/include/nimble/ble.h b/net/nimble/include/nimble/ble.h
index 1607eb8..aae501a 100644
--- a/net/nimble/include/nimble/ble.h
+++ b/net/nimble/include/nimble/ble.h
@@ -222,7 +222,6 @@ enum ble_error_codes
     BLE_ERR_CONN_ESTABLISHMENT  = 62,
     BLE_ERR_MAC_CONN_FAIL       = 63,
     BLE_ERR_COARSE_CLK_ADJ      = 64,
-    BLE_ERR_ATTR_NOT_FOUND      = 65,
     BLE_ERR_MAX                 = 255
 };
 


[23/50] [abbrv] incubator-mynewt-core git commit: BLE Host - Lookup svc, chr, dsc handles by UUID.

Posted by cc...@apache.org.
BLE Host - Lookup svc,chr,dsc handles by UUID.


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

Branch: refs/heads/ble_hs_api
Commit: 787463b5aac59a6d089621c00be14649cb3a97d5
Parents: 2997fff
Author: Christopher Collins <cc...@apache.org>
Authored: Wed Jun 29 10:10:57 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Jul 11 16:43:32 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/include/host/ble_gatt.h       |   7 +
 net/nimble/host/src/ble_att_priv.h            |   5 +-
 net/nimble/host/src/ble_att_svr.c             |  20 +-
 net/nimble/host/src/ble_gatts.c               | 253 ++++++++++++++++++---
 net/nimble/host/src/test/ble_gatts_reg_test.c | 252 +++++++++++++++++++-
 5 files changed, 483 insertions(+), 54 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/787463b5/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 d805590..e69e59b 100644
--- a/net/nimble/host/include/host/ble_gatt.h
+++ b/net/nimble/host/include/host/ble_gatt.h
@@ -356,6 +356,13 @@ typedef void ble_gatt_register_fn(uint8_t op,
 int ble_gatts_register_svcs(const struct ble_gatt_svc_def *svcs,
                             ble_gatt_register_fn *register_cb,
                             void *cb_arg);
+
 void ble_gatts_chr_updated(uint16_t chr_def_handle);
 
+int ble_gatts_find_svc(const void *uuid128, uint16_t *out_handle);
+int ble_gatts_find_chr(const void *svc_uuid128, const void *chr_uuid128,
+                       uint16_t *out_def_handle, uint16_t *out_val_handle);
+int ble_gatts_find_dsc(const void *svc_uuid128, const void *chr_uuid128,
+                       const void *dsc_uuid128, uint16_t *out_dsc_handle);
+
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/787463b5/net/nimble/host/src/ble_att_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att_priv.h b/net/nimble/host/src/ble_att_priv.h
index 5506c58..c1da676 100644
--- a/net/nimble/host/src/ble_att_priv.h
+++ b/net/nimble/host/src/ble_att_priv.h
@@ -156,9 +156,12 @@ int ble_att_init(void);
 /*** @svr */
 
 struct ble_att_svr_entry *
-ble_att_svr_find_by_uuid(struct ble_att_svr_entry *start_at, uint8_t *uuid);
+ble_att_svr_find_by_uuid(struct ble_att_svr_entry *start_at,
+                         const uint8_t *uuid,
+                         uint16_t end_handle);
 uint16_t ble_att_svr_prev_handle(void);
 int ble_att_svr_rx_mtu(uint16_t conn_handle, struct os_mbuf **om);
+struct ble_att_svr_entry *ble_att_svr_find_by_handle(uint16_t handle_id);
 int ble_att_svr_rx_find_info(uint16_t conn_handle, struct os_mbuf **rxom);
 int ble_att_svr_rx_find_type_value(uint16_t conn_handle,
                                    struct os_mbuf **rxom);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/787463b5/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 f7a5d36..8e57452 100644
--- a/net/nimble/host/src/ble_att_svr.c
+++ b/net/nimble/host/src/ble_att_svr.c
@@ -25,7 +25,9 @@
 #include "host/ble_uuid.h"
 #include "ble_hs_priv.h"
 
-static STAILQ_HEAD(, ble_att_svr_entry) ble_att_svr_list;
+STAILQ_HEAD(ble_att_svr_entry_list, ble_att_svr_entry);
+static struct ble_att_svr_entry_list ble_att_svr_list;
+
 static uint16_t ble_att_svr_id;
 
 static void *ble_att_svr_entry_mem;
@@ -159,7 +161,7 @@ ble_att_svr_find_by_handle(uint16_t handle_id)
  * Find a host attribute by UUID.
  *
  * @param uuid                  The ble_uuid_t to search for
- * @param ha_ptr                On input: Indicates the starting point of the
+ * @param prev                  On input: Indicates the starting point of the
  *                                  walk; null means start at the beginning of
  *                                  the list, non-null means start at the
  *                                  following entry.
@@ -170,7 +172,8 @@ ble_att_svr_find_by_handle(uint16_t handle_id)
  * @return                      0 on success; BLE_HS_ENOENT on not found.
  */
 struct ble_att_svr_entry *
-ble_att_svr_find_by_uuid(struct ble_att_svr_entry *prev, uint8_t *uuid)
+ble_att_svr_find_by_uuid(struct ble_att_svr_entry *prev, const uint8_t *uuid,
+                         uint16_t end_handle)
 {
     struct ble_att_svr_entry *entry;
 
@@ -180,7 +183,10 @@ ble_att_svr_find_by_uuid(struct ble_att_svr_entry *prev, uint8_t *uuid)
         entry = STAILQ_NEXT(prev, ha_next);
     }
 
-    for (; entry != NULL; entry = STAILQ_NEXT(entry, ha_next)) {
+    for (;
+         entry != NULL && entry->ha_handle_id <= end_handle;
+         entry = STAILQ_NEXT(entry, ha_next)) {
+
         if (memcmp(entry->ha_uuid, uuid, sizeof entry->ha_uuid) == 0) {
             return entry;
         }
@@ -1247,16 +1253,12 @@ ble_att_svr_build_read_type_rsp(uint16_t conn_handle,
     /* Find all matching attributes, writing a record for each. */
     entry = NULL;
     while (1) {
-        entry = ble_att_svr_find_by_uuid(entry, uuid128);
+        entry = ble_att_svr_find_by_uuid(entry, uuid128, req->batq_end_handle);
         if (entry == NULL) {
             rc = BLE_HS_ENOENT;
             break;
         }
 
-        if (entry->ha_handle_id > req->batq_end_handle) {
-            break;
-        }
-
         if (entry->ha_handle_id >= req->batq_start_handle) {
             ctxt.read.offset = 0;
             rc = ble_att_svr_read(conn_handle, entry, &ctxt, att_err);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/787463b5/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 0665758..82f21b2 100644
--- a/net/nimble/host/src/ble_gatts.c
+++ b/net/nimble/host/src/ble_gatts.c
@@ -35,7 +35,7 @@ struct ble_gatts_svc_entry {
 };
 
 static struct ble_gatts_svc_entry *ble_gatts_svc_entries;
-static int ble_gatts_num_svc_entries;
+static uint16_t ble_gatts_num_svc_entries;
 
 static os_membuf_t *ble_gatts_clt_cfg_mem;
 static struct os_mempool ble_gatts_clt_cfg_pool;
@@ -95,8 +95,6 @@ ble_gatts_inc_access(uint16_t conn_handle, uint16_t attr_handle,
                      uint8_t *uuid128, uint8_t op,
                      struct ble_att_svr_access_ctxt *ctxt, void *arg)
 {
-    static uint8_t buf[BLE_GATTS_INCLUDE_SZ];
-
     const struct ble_gatts_svc_entry *entry;
     uint16_t uuid16;
 
@@ -106,18 +104,17 @@ ble_gatts_inc_access(uint16_t conn_handle, uint16_t attr_handle,
 
     entry = arg;
 
-    htole16(buf + 0, entry->handle);
-    htole16(buf + 2, entry->end_group_handle);
+    htole16(ctxt->read.buf + 0, entry->handle);
+    htole16(ctxt->read.buf + 2, entry->end_group_handle);
 
     /* Only include the service UUID if it has a 16-bit representation. */
     uuid16 = ble_uuid_128_to_16(entry->svc->uuid128);
     if (uuid16 != 0) {
-        htole16(buf + 4, uuid16);
+        htole16(ctxt->read.buf + 4, uuid16);
         ctxt->read.len = 6;
     } else {
         ctxt->read.len = 4;
     }
-    ctxt->read.data = buf;
 
     return 0;
 }
@@ -323,7 +320,7 @@ ble_gatts_chr_val_access(uint16_t conn_handle, uint16_t attr_handle,
 }
 
 static int
-ble_gatts_find_svc(const struct ble_gatt_svc_def *svc)
+ble_gatts_find_svc_entry_idx(const struct ble_gatt_svc_def *svc)
 {
     int i;
 
@@ -348,7 +345,7 @@ ble_gatts_svc_incs_satisfied(const struct ble_gatt_svc_def *svc)
     }
 
     for (i = 0; svc->includes[i] != NULL; i++) {
-        idx = ble_gatts_find_svc(svc->includes[i]);
+        idx = ble_gatts_find_svc_entry_idx(svc->includes[i]);
         if (idx == -1 || ble_gatts_svc_entries[idx].handle == 0) {
             return 0;
         }
@@ -462,8 +459,9 @@ ble_gatts_dsc_is_sane(const struct ble_gatt_dsc_def *dsc)
 }
 
 static int
-ble_gatts_register_dsc(const struct ble_gatt_dsc_def *dsc,
+ble_gatts_register_dsc(const struct ble_gatt_svc_def *svc,
                        const struct ble_gatt_chr_def *chr,
+                       const struct ble_gatt_dsc_def *dsc,
                        uint16_t chr_def_handle,
                        ble_gatt_register_fn *register_cb, void *cb_arg)
 {
@@ -482,11 +480,10 @@ ble_gatts_register_dsc(const struct ble_gatt_dsc_def *dsc,
     }
 
     if (register_cb != NULL) {
-        register_ctxt.dsc.dsc_handle = dsc_handle;
-        register_ctxt.dsc.dsc_def = dsc;
-        register_ctxt.dsc.chr_def_handle = chr_def_handle;
-        register_ctxt.dsc.chr_val_handle = chr_def_handle + 1;
+        register_ctxt.dsc.handle = dsc_handle;
+        register_ctxt.dsc.svc_def = svc;
         register_ctxt.dsc.chr_def = chr;
+        register_ctxt.dsc.dsc_def = dsc;
         register_cb(BLE_GATT_REGISTER_OP_DSC, &register_ctxt, cb_arg);
     }
 
@@ -695,6 +692,13 @@ ble_gatts_register_chr(const struct ble_gatt_svc_def *svc,
         return BLE_HS_EINVAL;
     }
 
+    if (ble_gatts_chr_clt_cfg_allowed(chr) != 0) {
+        if (ble_gatts_num_cfgable_chrs > ble_hs_cfg.max_client_configs) {
+            return BLE_HS_ENOMEM;
+        }
+        ble_gatts_num_cfgable_chrs++;
+    }
+
     /* Register characteristic definition attribute (cast away const on
      * callback arg).
      */
@@ -723,7 +727,7 @@ ble_gatts_register_chr(const struct ble_gatt_svc_def *svc,
     if (register_cb != NULL) {
         register_ctxt.chr.def_handle = def_handle;
         register_ctxt.chr.val_handle = val_handle;
-        register_ctxt.svc.svc_def = svc;
+        register_ctxt.chr.svc_def = svc;
         register_ctxt.chr.chr_def = chr;
         register_cb(BLE_GATT_REGISTER_OP_CHR, &register_ctxt, cb_arg);
     }
@@ -739,7 +743,7 @@ ble_gatts_register_chr(const struct ble_gatt_svc_def *svc,
     /* Register each descriptor. */
     if (chr->descriptors != NULL) {
         for (dsc = chr->descriptors; dsc->uuid128 != NULL; dsc++) {
-            rc = ble_gatts_register_dsc(dsc, chr, def_handle, register_cb,
+            rc = ble_gatts_register_dsc(svc, chr, dsc, def_handle, register_cb,
                                         cb_arg);
             if (rc != 0) {
                 return rc;
@@ -829,7 +833,7 @@ ble_gatts_register_svc(const struct ble_gatt_svc_def *svc,
     /* Register each include. */
     if (svc->includes != NULL) {
         for (i = 0; svc->includes[i] != NULL; i++) {
-            idx = ble_gatts_find_svc(svc->includes[i]);
+            idx = ble_gatts_find_svc_entry_idx(svc->includes[i]);
             BLE_HS_DBG_ASSERT_EVAL(idx != -1);
 
             rc = ble_gatts_register_inc(ble_gatts_svc_entries + idx);
@@ -879,7 +883,7 @@ ble_gatts_register_round(int *out_num_registered, ble_gatt_register_fn *cb,
 
             case BLE_HS_EAGAIN:
                 /* Service could not be registered due to unsatisfied includes.
-                 * Try again on the next itereation.
+                 * Try again on the next iteration.
                  */
                 break;
 
@@ -959,26 +963,10 @@ ble_gatts_start(void)
     int idx;
     int rc;
 
-    rc = ble_uuid_16_to_128(BLE_ATT_UUID_CHARACTERISTIC, uuid128);
-    BLE_HS_DBG_ASSERT_EVAL(rc == 0);
-
-    /* Count the number of client-configurable characteristics. */
-    ble_gatts_num_cfgable_chrs = 0;
-    ha = NULL;
-    while ((ha = ble_att_svr_find_by_uuid(ha, uuid128)) != NULL) {
-        chr = ha->ha_cb_arg;
-        if (ble_gatts_chr_clt_cfg_allowed(chr) != 0) {
-            ble_gatts_num_cfgable_chrs++;
-        }
-    }
     if (ble_gatts_num_cfgable_chrs == 0) {
         return 0;
     }
 
-    if (ble_gatts_num_cfgable_chrs > ble_hs_cfg.max_client_configs) {
-        return BLE_HS_ENOMEM;
-    }
-
     /* Initialize client-configuration memory pool. */
     num_elems = ble_hs_cfg.max_client_configs / ble_gatts_num_cfgable_chrs;
     rc = os_mempool_init(&ble_gatts_clt_cfg_pool, num_elems,
@@ -997,9 +985,11 @@ ble_gatts_start(void)
     }
 
     /* Fill the cache. */
+    rc = ble_uuid_16_to_128(BLE_ATT_UUID_CHARACTERISTIC, uuid128);
+    BLE_HS_DBG_ASSERT_EVAL(rc == 0);
     idx = 0;
     ha = NULL;
-    while ((ha = ble_att_svr_find_by_uuid(ha, uuid128)) != NULL) {
+    while ((ha = ble_att_svr_find_by_uuid(ha, uuid128, 0xffff)) != NULL) {
         chr = ha->ha_cb_arg;
         allowed_flags = ble_gatts_chr_clt_cfg_allowed(chr);
         if (allowed_flags != 0) {
@@ -1403,6 +1393,199 @@ ble_gatts_bonding_restored(uint16_t conn_handle)
     }
 }
 
+static struct ble_gatts_svc_entry *
+ble_gatts_find_svc_entry(const void *uuid128)
+{
+    struct ble_gatts_svc_entry *entry;
+    int i;
+
+    for (i = 0; i < ble_gatts_num_svc_entries; i++) {
+        entry = ble_gatts_svc_entries + i;
+        if (memcmp(uuid128, entry->svc->uuid128, 16) == 0) {
+            return entry;
+        }
+    }
+
+    return NULL;
+}
+
+static int
+ble_gatts_find_svc_chr_attr(const void *svc_uuid128, const void *chr_uuid128,
+                            struct ble_gatts_svc_entry **out_svc_entry,
+                            struct ble_att_svr_entry **out_att_chr)
+{
+    struct ble_gatts_svc_entry *svc_entry;
+    struct ble_att_svr_entry *att_svc;
+    struct ble_att_svr_entry *next;
+    struct ble_att_svr_entry *cur;
+    uint16_t uuid16;
+
+    svc_entry = ble_gatts_find_svc_entry(svc_uuid128);
+    if (svc_entry == NULL) {
+        return BLE_HS_ENOENT;
+    }
+
+    att_svc = ble_att_svr_find_by_handle(svc_entry->handle);
+    if (att_svc == NULL) {
+        return BLE_HS_EUNKNOWN;
+    }
+
+    cur = STAILQ_NEXT(att_svc, ha_next);
+    while (1) {
+        if (cur == NULL) {
+            /* Reached end of attribute list without a match. */
+            return BLE_HS_ENOENT;
+        }
+        next = STAILQ_NEXT(cur, ha_next);
+
+        if (cur->ha_handle_id == svc_entry->end_group_handle) {
+            /* Reached end of service without a match. */
+            return BLE_HS_ENOENT;
+        }
+
+        uuid16 = ble_uuid_128_to_16(cur->ha_uuid);
+        if (uuid16 == BLE_ATT_UUID_CHARACTERISTIC &&
+            next != NULL &&
+            memcmp(next->ha_uuid, chr_uuid128, 16) == 0) {
+
+            if (out_svc_entry != NULL) {
+                *out_svc_entry = svc_entry;
+            }
+            if (out_att_chr != NULL) {
+                *out_att_chr = next;
+            }
+            return 0;
+        }
+
+        cur = next;
+    }
+}
+
+/**
+ * Retrieves the attribute handle associated with a local GATT service.
+ *
+ * @param uuid128               The UUID of the service to look up.
+ * @param out_handle            On success, populated with the handle of the
+ *                                  service attribute.  Pass null if you don't
+ *                                  need this value.
+ *
+ * @return                      0 on success;
+ *                              BLE_HS_ENOENT if the specified service could
+ *                                  not be found.
+ */
+int
+ble_gatts_find_svc(const void *uuid128, uint16_t *out_handle)
+{
+    struct ble_gatts_svc_entry *entry;
+
+    entry = ble_gatts_find_svc_entry(uuid128);
+    if (entry == NULL) {
+        return BLE_HS_ENOENT;
+    }
+
+    if (out_handle != NULL) {
+        *out_handle = entry->handle;
+    }
+    return 0;
+}
+
+/**
+ * Retrieves the pair of attribute handles associated with a local GATT
+ * characteristic.
+ *
+ * @param svc_uuid128           The UUID of the parent service.
+ * @param chr_uuid128           The UUID of the characteristic to look up.
+ * @param out_def_handle        On success, populated with the handle
+ *                                  of the characteristic definition attribute.
+ *                                  Pass null if you don't need this value.
+ * @param out_val_handle        On success, populated with the handle
+ *                                  of the characteristic value attribute.
+ *                                  Pass null if you don't need this value.
+ *
+ * @return                      0 on success;
+ *                              BLE_HS_ENOENT if the specified service or
+ *                                  characteristic could not be found.
+ */
+int
+ble_gatts_find_chr(const void *svc_uuid128, const void *chr_uuid128,
+                   uint16_t *out_def_handle, uint16_t *out_val_handle)
+{
+    struct ble_att_svr_entry *att_chr;
+    int rc;
+
+    rc = ble_gatts_find_svc_chr_attr(svc_uuid128, chr_uuid128, NULL, &att_chr);
+    if (rc != 0) {
+        return rc;
+    }
+
+    if (out_def_handle) {
+        *out_def_handle = att_chr->ha_handle_id - 1;
+    }
+    if (out_val_handle) {
+        *out_val_handle = att_chr->ha_handle_id;
+    }
+    return 0;
+}
+
+/**
+ * Retrieves the attribute handle associated with a local GATT descriptor.
+ *
+ * @param svc_uuid128           The UUID of the grandparent service.
+ * @param chr_uuid128           The UUID of the parent characteristic.
+ * @param dsc_uuid128           The UUID of the descriptor ro look up.
+ * @param out_handle            On success, populated with the handle
+ *                                  of the descripytor attribute.  Pass null if
+ *                                  you don't need this value.
+ *
+ * @return                      0 on success;
+ *                              BLE_HS_ENOENT if the specified service,
+ *                                  characteristic, or descriptor could not be
+ *                                  found.
+ */
+int
+ble_gatts_find_dsc(const void *svc_uuid128, const void *chr_uuid128,
+                   const void *dsc_uuid128, uint16_t *out_handle)
+{
+    struct ble_gatts_svc_entry *svc_entry;
+    struct ble_att_svr_entry *att_chr;
+    struct ble_att_svr_entry *cur;
+    uint16_t uuid16;
+    int rc;
+
+    rc = ble_gatts_find_svc_chr_attr(svc_uuid128, chr_uuid128, &svc_entry,
+                                     &att_chr);
+    if (rc != 0) {
+        return rc;
+    }
+
+    cur = STAILQ_NEXT(att_chr, ha_next);
+    while (1) {
+        if (cur == NULL) {
+            /* Reached end of attribute list without a match. */
+            return BLE_HS_ENOENT;
+        }
+
+        if (cur->ha_handle_id == svc_entry->end_group_handle) {
+            /* Reached end of service without a match. */
+            return BLE_HS_ENOENT;
+        }
+
+        uuid16 = ble_uuid_128_to_16(cur->ha_uuid);
+        if (uuid16 == BLE_ATT_UUID_CHARACTERISTIC) {
+            /* Reached end of characteristic without a match. */
+            return BLE_HS_ENOENT;
+        }
+
+        if (memcmp(cur->ha_uuid, dsc_uuid128, 16) == 0) {
+            if (out_handle != NULL) {
+                *out_handle = cur->ha_handle_id;
+                return 0;
+            }
+        }
+        cur = STAILQ_NEXT(cur, ha_next);
+    }
+}
+
 static void
 ble_gatts_free_mem(void)
 {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/787463b5/net/nimble/host/src/test/ble_gatts_reg_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_gatts_reg_test.c b/net/nimble/host/src/test/ble_gatts_reg_test.c
index f6e5841..ff96f74 100644
--- a/net/nimble/host/src/test/ble_gatts_reg_test.c
+++ b/net/nimble/host/src/test/ble_gatts_reg_test.c
@@ -30,6 +30,12 @@
 struct ble_gatts_reg_test_entry {
     uint8_t op;
     uint8_t uuid128[16];
+    uint16_t handle;
+    uint16_t val_handle; /* If a characteristic. */
+
+    const struct ble_gatt_svc_def *svc;
+    const struct ble_gatt_chr_def *chr;
+    const struct ble_gatt_dsc_def *dsc;
 };
 
 static struct ble_gatts_reg_test_entry
@@ -54,19 +60,197 @@ ble_gatts_reg_test_misc_reg_cb(uint8_t op, union ble_gatt_register_ctxt *ctxt,
                       BLE_GATTS_REG_TEST_MAX_ENTRIES);
 
     entry = ble_gatts_reg_test_entries + ble_gatts_reg_test_num_entries++;
+    memset(entry, 0, sizeof *entry);
 
     entry->op = op;
     switch (op) {
     case BLE_GATT_REGISTER_OP_SVC:
         memcpy(entry->uuid128, ctxt->svc.svc_def->uuid128, 16);
+        entry->handle = ctxt->svc.handle;
+        entry->svc = ctxt->svc.svc_def;
         break;
 
     case BLE_GATT_REGISTER_OP_CHR:
         memcpy(entry->uuid128, ctxt->chr.chr_def->uuid128, 16);
+        entry->handle = ctxt->chr.def_handle;
+        entry->val_handle = ctxt->chr.val_handle;
+        entry->svc = ctxt->chr.svc_def;
+        entry->chr = ctxt->chr.chr_def;
         break;
 
     case BLE_GATT_REGISTER_OP_DSC:
         memcpy(entry->uuid128, ctxt->dsc.dsc_def->uuid128, 16);
+        entry->handle = ctxt->dsc.handle;
+        entry->svc = ctxt->dsc.svc_def;
+        entry->chr = ctxt->dsc.chr_def;
+        entry->dsc = ctxt->dsc.dsc_def;
+        break;
+
+    default:
+        TEST_ASSERT(0);
+        break;
+    }
+}
+
+static void
+ble_gatts_reg_test_misc_lookup_good(struct ble_gatts_reg_test_entry *entry)
+{
+    uint16_t chr_def_handle;
+    uint16_t chr_val_handle;
+    uint16_t svc_handle;
+    uint16_t dsc_handle;
+    int rc;
+
+    switch (entry->op) {
+    case BLE_GATT_REGISTER_OP_SVC:
+        rc = ble_gatts_find_svc(entry->uuid128, &svc_handle);
+        TEST_ASSERT_FATAL(rc == 0);
+        TEST_ASSERT(svc_handle == entry->handle);
+        break;
+
+    case BLE_GATT_REGISTER_OP_CHR:
+        rc = ble_gatts_find_chr(entry->svc->uuid128, entry->chr->uuid128,
+                                &chr_def_handle, &chr_val_handle);
+        TEST_ASSERT_FATAL(rc == 0);
+        TEST_ASSERT(chr_def_handle == entry->handle);
+        TEST_ASSERT(chr_val_handle == entry->val_handle);
+        break;
+
+    case BLE_GATT_REGISTER_OP_DSC:
+        rc = ble_gatts_find_dsc(entry->svc->uuid128, entry->chr->uuid128,
+                                entry->dsc->uuid128, &dsc_handle);
+        break;
+
+    default:
+        TEST_ASSERT(0);
+        break;
+    }
+}
+
+static void
+ble_gatts_reg_test_misc_lookup_bad(struct ble_gatts_reg_test_entry *entry)
+{
+    struct ble_gatts_reg_test_entry *cur;
+    uint8_t wrong_uuid[16];
+    int rc;
+    int i;
+
+    switch (entry->op) {
+    case BLE_GATT_REGISTER_OP_SVC:
+        /* Wrong service UUID. */
+        memcpy(wrong_uuid, entry->svc->uuid128, 16);
+        wrong_uuid[15]++;
+        rc = ble_gatts_find_svc(wrong_uuid, NULL);
+        TEST_ASSERT(rc == BLE_HS_ENOENT);
+        break;
+
+    case BLE_GATT_REGISTER_OP_CHR:
+        /* Correct service UUID, wrong characteristic UUID. */
+        memcpy(wrong_uuid, entry->chr->uuid128, 16);
+        wrong_uuid[15]++;
+        rc = ble_gatts_find_chr(entry->svc->uuid128, wrong_uuid, NULL, NULL);
+        TEST_ASSERT(rc == BLE_HS_ENOENT);
+
+        /* Incorrect service UUID, correct characteristic UUID. */
+        memcpy(wrong_uuid, entry->svc->uuid128, 16);
+        wrong_uuid[15]++;
+        rc = ble_gatts_find_chr(wrong_uuid, entry->chr->uuid128, NULL, NULL);
+        TEST_ASSERT(rc == BLE_HS_ENOENT);
+
+        /* Existing (but wrong) service, correct characteristic UUID. */
+        for (i = 0; i < ble_gatts_reg_test_num_entries; i++) {
+            cur = ble_gatts_reg_test_entries + i;
+            switch (cur->op) {
+            case BLE_GATT_REGISTER_OP_SVC:
+                if (cur->svc != entry->svc) {
+                    rc = ble_gatts_find_chr(cur->svc->uuid128,
+                                            entry->chr->uuid128,
+                                            NULL, NULL);
+                    TEST_ASSERT(rc == BLE_HS_ENOENT);
+                }
+                break;
+
+            case BLE_GATT_REGISTER_OP_CHR:
+                /* Characteristic that isn't in this service. */
+                if (cur->svc != entry->svc) {
+                    rc = ble_gatts_find_chr(entry->svc->uuid128,
+                                            cur->chr->uuid128,
+                                            NULL, NULL);
+                    TEST_ASSERT(rc == BLE_HS_ENOENT);
+                }
+                break;
+
+            case BLE_GATT_REGISTER_OP_DSC:
+                /* Use descriptor UUID instead of characteristic UUID. */
+                rc = ble_gatts_find_chr(entry->svc->uuid128,
+                                        cur->dsc->uuid128,
+                                        NULL, NULL);
+                TEST_ASSERT(rc == BLE_HS_ENOENT);
+                break;
+
+            default:
+                TEST_ASSERT(0);
+                break;
+            }
+        }
+        break;
+
+    case BLE_GATT_REGISTER_OP_DSC:
+        /* Correct svc/chr UUID, wrong dsc UUID. */
+        memcpy(wrong_uuid, entry->dsc->uuid128, 16);
+        wrong_uuid[15]++;
+        rc = ble_gatts_find_dsc(entry->svc->uuid128, entry->chr->uuid128,
+                                wrong_uuid, NULL);
+        TEST_ASSERT(rc == BLE_HS_ENOENT);
+
+        /* Incorrect svc UUID, correct chr/dsc UUID. */
+        memcpy(wrong_uuid, entry->svc->uuid128, 16);
+        wrong_uuid[15]++;
+        rc = ble_gatts_find_dsc(wrong_uuid, entry->chr->uuid128,
+                                entry->dsc->uuid128, NULL);
+        TEST_ASSERT(rc == BLE_HS_ENOENT);
+
+        for (i = 0; i < ble_gatts_reg_test_num_entries; i++) {
+            cur = ble_gatts_reg_test_entries + i;
+            switch (cur->op) {
+            case BLE_GATT_REGISTER_OP_SVC:
+                /* Existing (but wrong) svc, correct chr/dsc UUID. */
+                if (cur->svc != entry->svc) {
+                    rc = ble_gatts_find_dsc(cur->svc->uuid128,
+                                            entry->chr->uuid128,
+                                            entry->dsc->uuid128,
+                                            NULL);
+                    TEST_ASSERT(rc == BLE_HS_ENOENT);
+                }
+                break;
+
+            case BLE_GATT_REGISTER_OP_CHR:
+                /* Existing (but wrong) svc/chr, correct dsc UUID. */
+                if (cur->chr != entry->chr) {
+                    rc = ble_gatts_find_dsc(cur->svc->uuid128,
+                                            cur->chr->uuid128,
+                                            entry->dsc->uuid128,
+                                            NULL);
+                    TEST_ASSERT(rc == BLE_HS_ENOENT);
+                }
+                break;
+
+            case BLE_GATT_REGISTER_OP_DSC:
+                /* Descriptor that isn't in this characteristic. */
+                if (cur->chr != entry->chr) {
+                    rc = ble_gatts_find_dsc(cur->svc->uuid128,
+                                            cur->chr->uuid128,
+                                            entry->dsc->uuid128,
+                                            NULL);
+                    TEST_ASSERT(rc == BLE_HS_ENOENT);
+                }
+                break;
+
+            default:
+                TEST_ASSERT(0);
+                break;
+            }
+        }
         break;
 
     default:
@@ -84,11 +268,25 @@ ble_gatts_reg_test_misc_verify_entry(uint8_t op, const uint8_t *uuid128)
     for (i = 0; i < ble_gatts_reg_test_num_entries; i++) {
         entry = ble_gatts_reg_test_entries + i;
         if (entry->op == op && memcmp(entry->uuid128, uuid128, 16) == 0) {
-            return;
+            break;
         }
     }
+    TEST_ASSERT_FATAL(entry != NULL);
 
-    TEST_ASSERT(0);
+    /* Verify that characteristic value handle was properly assigned at
+     * registration.
+     */
+    if (op == BLE_GATT_REGISTER_OP_CHR) {
+        TEST_ASSERT(*entry->chr->val_handle == entry->val_handle);
+    }
+
+    /* Verify that the entry can be looked up. */
+    ble_gatts_reg_test_misc_lookup_good(entry);
+
+    /* Verify that "barely incorrect" UUID information doesn't retrieve any
+     * handles.
+     */
+    ble_gatts_reg_test_misc_lookup_bad(entry);
 }
 
 static int
@@ -337,6 +535,8 @@ TEST_CASE(ble_gatts_reg_test_svc_cb)
 
 TEST_CASE(ble_gatts_reg_test_chr_cb)
 {
+    uint16_t val_handles[16];
+
     /*** 1 characteristic. */
     ble_gatts_reg_test_misc_svcs((struct ble_gatt_svc_def[]) { {
         .type = BLE_GATT_SVC_TYPE_PRIMARY,
@@ -345,6 +545,7 @@ TEST_CASE(ble_gatts_reg_test_chr_cb)
             .uuid128 = BLE_UUID16(0x1111),
             .access_cb = ble_gatts_reg_test_misc_dummy_access,
             .flags = BLE_GATT_CHR_F_READ,
+            .val_handle = val_handles + 0,
         }, {
             0
         } },
@@ -360,10 +561,12 @@ TEST_CASE(ble_gatts_reg_test_chr_cb)
             .uuid128 = BLE_UUID16(0x1111),
             .access_cb = ble_gatts_reg_test_misc_dummy_access,
             .flags = BLE_GATT_CHR_F_READ,
+            .val_handle = val_handles + 0,
         }, {
             .uuid128 = BLE_UUID16(0x2222),
             .access_cb = ble_gatts_reg_test_misc_dummy_access,
             .flags = BLE_GATT_CHR_F_WRITE,
+            .val_handle = val_handles + 1,
         }, {
             0
         } },
@@ -374,6 +577,7 @@ TEST_CASE(ble_gatts_reg_test_chr_cb)
             .uuid128 = BLE_UUID16(0x3333),
             .access_cb = ble_gatts_reg_test_misc_dummy_access,
             .flags = BLE_GATT_CHR_F_READ,
+            .val_handle = val_handles + 2,
         }, {
             0
         } },
@@ -384,6 +588,8 @@ TEST_CASE(ble_gatts_reg_test_chr_cb)
 
 TEST_CASE(ble_gatts_reg_test_dsc_cb)
 {
+    uint16_t val_handles[16];
+
     /*** 1 descriptor. */
     ble_gatts_reg_test_misc_svcs((struct ble_gatt_svc_def[]) { {
         .type = BLE_GATT_SVC_TYPE_PRIMARY,
@@ -392,8 +598,9 @@ TEST_CASE(ble_gatts_reg_test_dsc_cb)
             .uuid128 = BLE_UUID16(0x1111),
             .access_cb = ble_gatts_reg_test_misc_dummy_access,
             .flags = BLE_GATT_CHR_F_READ,
+            .val_handle = val_handles + 0,
             .descriptors = (struct ble_gatt_dsc_def[]) { {
-                .uuid128 = BLE_UUID16(0xaaaa),
+                .uuid128 = BLE_UUID16(0x111a),
                 .att_flags = 5,
                 .access_cb = ble_gatts_reg_test_misc_dummy_access,
             }, {
@@ -406,7 +613,7 @@ TEST_CASE(ble_gatts_reg_test_dsc_cb)
         0
     } });
 
-    /*** 5 descriptors. */
+    /*** 5+ descriptors. */
     ble_gatts_reg_test_misc_svcs((struct ble_gatt_svc_def[]) { {
         .type = BLE_GATT_SVC_TYPE_PRIMARY,
         .uuid128 = BLE_UUID16(0x1234),
@@ -414,8 +621,9 @@ TEST_CASE(ble_gatts_reg_test_dsc_cb)
             .uuid128 = BLE_UUID16(0x1111),
             .access_cb = ble_gatts_reg_test_misc_dummy_access,
             .flags = BLE_GATT_CHR_F_READ,
+            .val_handle = val_handles + 0,
             .descriptors = (struct ble_gatt_dsc_def[]) { {
-                .uuid128 = BLE_UUID16(0xaaaa),
+                .uuid128 = BLE_UUID16(0x111a),
                 .att_flags = 5,
                 .access_cb = ble_gatts_reg_test_misc_dummy_access,
             }, {
@@ -425,6 +633,7 @@ TEST_CASE(ble_gatts_reg_test_dsc_cb)
             .uuid128 = BLE_UUID16(0x2222),
             .access_cb = ble_gatts_reg_test_misc_dummy_access,
             .flags = BLE_GATT_CHR_F_WRITE,
+            .val_handle = val_handles + 1,
         }, {
             0
         } },
@@ -435,20 +644,45 @@ TEST_CASE(ble_gatts_reg_test_dsc_cb)
             .uuid128 = BLE_UUID16(0x3333),
             .access_cb = ble_gatts_reg_test_misc_dummy_access,
             .flags = BLE_GATT_CHR_F_READ,
+            .val_handle = val_handles + 2,
+            .descriptors = (struct ble_gatt_dsc_def[]) { {
+                .uuid128 = BLE_UUID16(0x333a),
+                .att_flags = 5,
+                .access_cb = ble_gatts_reg_test_misc_dummy_access,
+            }, {
+                .uuid128 = BLE_UUID16(0x333b),
+                .att_flags = 5,
+                .access_cb = ble_gatts_reg_test_misc_dummy_access,
+            }, {
+                .uuid128 = BLE_UUID16(0x333c),
+                .att_flags = 5,
+                .access_cb = ble_gatts_reg_test_misc_dummy_access,
+            }, {
+                .uuid128 = BLE_UUID16(0x333e),
+                .att_flags = 5,
+                .access_cb = ble_gatts_reg_test_misc_dummy_access,
+            }, {
+                0
+            } },
+        }, {
+            .uuid128 = BLE_UUID16(0x4444),
+            .access_cb = ble_gatts_reg_test_misc_dummy_access,
+            .flags = BLE_GATT_CHR_F_READ,
+            .val_handle = val_handles + 3,
             .descriptors = (struct ble_gatt_dsc_def[]) { {
-                .uuid128 = BLE_UUID16(0xaaab),
+                .uuid128 = BLE_UUID16(0x444a),
                 .att_flags = 5,
                 .access_cb = ble_gatts_reg_test_misc_dummy_access,
             }, {
-                .uuid128 = BLE_UUID16(0xaaac),
+                .uuid128 = BLE_UUID16(0x444b),
                 .att_flags = 5,
                 .access_cb = ble_gatts_reg_test_misc_dummy_access,
             }, {
-                .uuid128 = BLE_UUID16(0xaaad),
+                .uuid128 = BLE_UUID16(0x444c),
                 .att_flags = 5,
                 .access_cb = ble_gatts_reg_test_misc_dummy_access,
             }, {
-                .uuid128 = BLE_UUID16(0xaaae),
+                .uuid128 = BLE_UUID16(0x444e),
                 .att_flags = 5,
                 .access_cb = ble_gatts_reg_test_misc_dummy_access,
             }, {


[21/50] [abbrv] incubator-mynewt-core git commit: BLE Host - Const correctness.

Posted by cc...@apache.org.
BLE Host - Const correctness.


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

Branch: refs/heads/ble_hs_api
Commit: 6353155771e1de9d1cd619b97fbe86e1265a5d59
Parents: 46801ab
Author: Christopher Collins <cc...@apache.org>
Authored: Fri Jun 24 17:00:15 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Jul 11 16:43:32 2016 -0700

----------------------------------------------------------------------
 apps/bleprph/src/gatt_svr.c                     |  18 +-
 apps/bletiny/src/bletiny.h                      |   2 +-
 apps/bletiny/src/gatt_svr.c                     |  18 +-
 net/nimble/host/include/host/ble_att.h          |  69 +++++-
 net/nimble/host/include/host/ble_gap.h          |  12 +-
 net/nimble/host/include/host/ble_gatt.h         | 137 ++++--------
 net/nimble/host/include/host/ble_hs_adv.h       |   4 +-
 net/nimble/host/include/host/ble_uuid.h         |   2 +-
 net/nimble/host/include/host/host_hci.h         |  75 +++----
 net/nimble/host/src/ble_att_clt.c               | 112 +++++-----
 net/nimble/host/src/ble_att_cmd.c               | 213 ++++++++++---------
 net/nimble/host/src/ble_att_cmd_priv.h          | 125 +++++------
 net/nimble/host/src/ble_att_priv.h              |  50 ++---
 net/nimble/host/src/ble_att_svr.c               | 113 ++++++----
 net/nimble/host/src/ble_gap.c                   |  25 ++-
 net/nimble/host/src/ble_gatt_priv.h             |   2 -
 net/nimble/host/src/ble_gattc.c                 |  54 ++---
 net/nimble/host/src/ble_gatts.c                 | 159 ++++----------
 net/nimble/host/src/ble_hs_adv.c                |   8 +-
 net/nimble/host/src/ble_hs_priv.h               |   4 +-
 net/nimble/host/src/ble_hs_pvcy.c               |   4 +-
 net/nimble/host/src/ble_sm.c                    |   2 +-
 net/nimble/host/src/ble_sm_priv.h               |   2 +-
 net/nimble/host/src/ble_uuid.c                  |   2 +-
 net/nimble/host/src/host_hci_cmd.c              | 100 +++++----
 net/nimble/host/src/test/ble_att_svr_test.c     |  50 ++---
 net/nimble/host/src/test/ble_gatt_conn_test.c   |  69 +++---
 net/nimble/host/src/test/ble_gatt_disc_c_test.c |   4 +-
 net/nimble/host/src/test/ble_gatt_disc_d_test.c |   5 +-
 net/nimble/host/src/test/ble_gatt_disc_s_test.c |   5 +-
 net/nimble/host/src/test/ble_gatt_find_s_test.c |   4 +-
 net/nimble/host/src/test/ble_gatt_read_test.c   |  11 +-
 net/nimble/host/src/test/ble_gatt_write_test.c  |  13 +-
 .../host/src/test/ble_gatts_notify_test.c       |  16 +-
 net/nimble/host/src/test/ble_gatts_read_test.c  |  34 +--
 net/nimble/host/src/test/ble_gatts_reg_test.c   |   2 +-
 36 files changed, 760 insertions(+), 765 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/63531557/apps/bleprph/src/gatt_svr.c
----------------------------------------------------------------------
diff --git a/apps/bleprph/src/gatt_svr.c b/apps/bleprph/src/gatt_svr.c
index 638257f..fa798ec 100644
--- a/apps/bleprph/src/gatt_svr.c
+++ b/apps/bleprph/src/gatt_svr.c
@@ -56,18 +56,18 @@ static uint8_t gatt_svr_sec_test_static_val;
 
 static int
 gatt_svr_chr_access_gap(uint16_t conn_handle, uint16_t attr_handle, uint8_t op,
-                        union ble_gatt_access_ctxt *ctxt, void *arg);
+                        struct ble_gatt_access_ctxt *ctxt, void *arg);
 static int
 gatt_svr_chr_access_gatt(uint16_t conn_handle, uint16_t attr_handle, uint8_t op,
-                         union ble_gatt_access_ctxt *ctxt, void *arg);
+                         struct ble_gatt_access_ctxt *ctxt, void *arg);
 static int
 gatt_svr_chr_access_alert(uint16_t conn_handle, uint16_t attr_handle,
-                          uint8_t op, union ble_gatt_access_ctxt *ctxt,
+                          uint8_t op, struct ble_gatt_access_ctxt *ctxt,
                           void *arg);
 
 static int
 gatt_svr_chr_access_sec_test(uint16_t conn_handle, uint16_t attr_handle,
-                                uint8_t op, union ble_gatt_access_ctxt *ctxt,
+                                uint8_t op, struct ble_gatt_access_ctxt *ctxt,
                                 void *arg);
 
 static const struct ble_gatt_svc_def gatt_svr_svcs[] = {
@@ -173,7 +173,7 @@ static const struct ble_gatt_svc_def gatt_svr_svcs[] = {
 };
 
 static int
-gatt_svr_chr_write(uint8_t op, union ble_gatt_access_ctxt *ctxt,
+gatt_svr_chr_write(uint8_t op, struct ble_gatt_access_ctxt *ctxt,
                    uint16_t min_len, uint16_t max_len, void *dst,
                    uint16_t *len)
 {
@@ -194,7 +194,7 @@ gatt_svr_chr_write(uint8_t op, union ble_gatt_access_ctxt *ctxt,
 
 static int
 gatt_svr_chr_access_gap(uint16_t conn_handle, uint16_t attr_handle, uint8_t op,
-                        union ble_gatt_access_ctxt *ctxt, void *arg)
+                        struct ble_gatt_access_ctxt *ctxt, void *arg)
 {
     uint16_t uuid16;
 
@@ -245,7 +245,7 @@ gatt_svr_chr_access_gap(uint16_t conn_handle, uint16_t attr_handle, uint8_t op,
 
 static int
 gatt_svr_chr_access_gatt(uint16_t conn_handle, uint16_t attr_handle, uint8_t op,
-                         union ble_gatt_access_ctxt *ctxt, void *arg)
+                         struct ble_gatt_access_ctxt *ctxt, void *arg)
 {
     uint16_t uuid16;
 
@@ -285,7 +285,7 @@ static uint16_t gatt_svr_alert_not_ctrl_pt;
 
 static int
 gatt_svr_chr_access_alert(uint16_t conn_handle, uint16_t attr_handle,
-                          uint8_t op, union ble_gatt_access_ctxt *ctxt,
+                          uint8_t op, struct ble_gatt_access_ctxt *ctxt,
                           void *arg)
 {
     uint16_t uuid16;
@@ -347,7 +347,7 @@ gatt_svr_chr_access_alert(uint16_t conn_handle, uint16_t attr_handle,
 
 static int
 gatt_svr_chr_access_sec_test(uint16_t conn_handle, uint16_t attr_handle,
-                            uint8_t op, union ble_gatt_access_ctxt *ctxt,
+                            uint8_t op, struct ble_gatt_access_ctxt *ctxt,
                             void *arg)
 {
     const void *uuid128;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/63531557/apps/bletiny/src/bletiny.h
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/bletiny.h b/apps/bletiny/src/bletiny.h
index 23699d2..90002e6 100644
--- a/apps/bletiny/src/bletiny.h
+++ b/apps/bletiny/src/bletiny.h
@@ -124,7 +124,7 @@ int parse_err_too_few_args(char *cmd_name);
 int parse_arg_all(int argc, char **argv);
 int cmd_init(void);
 int nm_chr_access(uint16_t conn_handle, uint16_t attr_handle,
-                  uint8_t op, union ble_gatt_access_ctxt *ctxt,
+                  uint8_t op, struct ble_gatt_access_ctxt *ctxt,
                   void *arg);
 int nm_rx_rsp(uint8_t *attr_val, uint16_t attr_len);
 void nm_init(void);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/63531557/apps/bletiny/src/gatt_svr.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/gatt_svr.c b/apps/bletiny/src/gatt_svr.c
index a99b86b..321bf9d 100644
--- a/apps/bletiny/src/gatt_svr.c
+++ b/apps/bletiny/src/gatt_svr.c
@@ -56,18 +56,18 @@ static uint8_t gatt_svr_sec_test_static_val;
 
 static int
 gatt_svr_chr_access_gap(uint16_t conn_handle, uint16_t attr_handle, uint8_t op,
-                        union ble_gatt_access_ctxt *ctxt, void *arg);
+                        struct ble_gatt_access_ctxt *ctxt, void *arg);
 static int
 gatt_svr_chr_access_gatt(uint16_t conn_handle, uint16_t attr_handle, uint8_t op,
-                         union ble_gatt_access_ctxt *ctxt, void *arg);
+                         struct ble_gatt_access_ctxt *ctxt, void *arg);
 static int
 gatt_svr_chr_access_alert(uint16_t conn_handle, uint16_t attr_handle,
-                          uint8_t op, union ble_gatt_access_ctxt *ctxt,
+                          uint8_t op, struct ble_gatt_access_ctxt *ctxt,
                           void *arg);
 
 static int
 gatt_svr_chr_access_sec_test(uint16_t conn_handle, uint16_t attr_handle,
-                                uint8_t op, union ble_gatt_access_ctxt *ctxt,
+                                uint8_t op, struct ble_gatt_access_ctxt *ctxt,
                                 void *arg);
 
 static const struct ble_gatt_svc_def gatt_svr_svcs[] = {
@@ -173,7 +173,7 @@ static const struct ble_gatt_svc_def gatt_svr_svcs[] = {
 };
 
 static int
-gatt_svr_chr_write(uint8_t op, union ble_gatt_access_ctxt *ctxt,
+gatt_svr_chr_write(uint8_t op, struct ble_gatt_access_ctxt *ctxt,
                    uint16_t min_len, uint16_t max_len, void *dst,
                    uint16_t *len)
 {
@@ -194,7 +194,7 @@ gatt_svr_chr_write(uint8_t op, union ble_gatt_access_ctxt *ctxt,
 
 static int
 gatt_svr_chr_access_gap(uint16_t conn_handle, uint16_t attr_handle, uint8_t op,
-                        union ble_gatt_access_ctxt *ctxt, void *arg)
+                        struct ble_gatt_access_ctxt *ctxt, void *arg)
 {
     uint16_t uuid16;
 
@@ -245,7 +245,7 @@ gatt_svr_chr_access_gap(uint16_t conn_handle, uint16_t attr_handle, uint8_t op,
 
 static int
 gatt_svr_chr_access_gatt(uint16_t conn_handle, uint16_t attr_handle, uint8_t op,
-                         union ble_gatt_access_ctxt *ctxt, void *arg)
+                         struct ble_gatt_access_ctxt *ctxt, void *arg)
 {
     uint16_t uuid16;
 
@@ -285,7 +285,7 @@ static uint16_t gatt_svr_alert_not_ctrl_pt;
 
 static int
 gatt_svr_chr_access_alert(uint16_t conn_handle, uint16_t attr_handle,
-                          uint8_t op, union ble_gatt_access_ctxt *ctxt,
+                          uint8_t op, struct ble_gatt_access_ctxt *ctxt,
                           void *arg)
 {
     uint16_t uuid16;
@@ -347,7 +347,7 @@ gatt_svr_chr_access_alert(uint16_t conn_handle, uint16_t attr_handle,
 
 static int
 gatt_svr_chr_access_sec_test(uint16_t conn_handle, uint16_t attr_handle,
-                            uint8_t op, union ble_gatt_access_ctxt *ctxt,
+                            uint8_t op, struct ble_gatt_access_ctxt *ctxt,
                             void *arg)
 {
     const void *uuid128;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/63531557/net/nimble/host/include/host/ble_att.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/ble_att.h b/net/nimble/host/include/host/ble_att.h
index 324ac0b..f25b8e2 100644
--- a/net/nimble/host/include/host/ble_att.h
+++ b/net/nimble/host/include/host/ble_att.h
@@ -86,10 +86,69 @@
 #define BLE_ATT_ACCESS_OP_READ              1
 #define BLE_ATT_ACCESS_OP_WRITE             2
 
+/**
+ * Context for reads of characteristics and descriptors.  An instance of this
+ * gets passed to an application callback whenever a local characteristic or
+ * descriptor is read.
+ */
+struct ble_att_read_ctxt {
+    /**
+     * (stack --> app)
+     * Maximum number of data bytes the stack can send in the read response.
+     * This is based on the connection's ATT MTU.
+     */
+    uint16_t max_data_len;
+
+    /**
+     * (stack --> app)
+     * A buffer that the app can use to write the characteristic response value
+     * to.  This buffer can hold up to max_data_len bytes.
+     */
+    uint8_t *buf;
+
+    /**
+     * (app --> stack)
+     * App points this at the characteristic data to respond with.  Initially
+     * this points to "buf".
+     */
+    const void *data;
+
+    /**
+     * (app --> stack)
+     * App fills this with the number of data bytes contained in characteristic
+     * response.
+     */
+    uint16_t len;
+
+    uint16_t offset;
+};
+
+/**
+ * Context for writes of characteristics and descriptors.  An instance of this
+ * gets passed to an application callback whenever a local characteristic or
+ * descriptor is written.
+ */
+struct ble_att_write_ctxt {
+    /**
+     * (stack --> app)
+     * The data that the peer is writing to the characteristic.
+     */
+    const void *data;
+
+    /**
+     * (stack --> app)
+     * The number of bytes of characteristic data being written.
+     */
+    int len;
+
+    uint16_t offset;
+};
+
 struct ble_att_svr_access_ctxt {
-    void *attr_data;
-    uint16_t data_len;
-    uint16_t offset; /* Only used for read-blob requests. */
+    union {
+        struct ble_att_read_ctxt read;
+        struct ble_att_write_ctxt write;
+    };
 };
 
 /**
@@ -120,9 +179,9 @@ typedef int ble_att_svr_notify_fn(uint16_t conn_handle, uint16_t attr_handle,
                                   uint8_t *attr_val, uint16_t attr_len,
                                   void *arg);
 
-int ble_att_svr_read_local(uint16_t attr_handle, void **out_data,
+int ble_att_svr_read_local(uint16_t attr_handle, const void **out_data,
                            uint16_t *out_attr_len);
-int ble_att_svr_write_local(uint16_t attr_handle, void *data,
+int ble_att_svr_write_local(uint16_t attr_handle, const void *data,
                             uint16_t data_len);
 
 int ble_att_set_preferred_mtu(uint16_t mtu);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/63531557/net/nimble/host/include/host/ble_gap.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/ble_gap.h b/net/nimble/host/include/host/ble_gap.h
index f2adaf5..147eaf4 100644
--- a/net/nimble/host/include/host/ble_gap.h
+++ b/net/nimble/host/include/host/ble_gap.h
@@ -298,8 +298,8 @@ int ble_gap_adv_start(uint8_t own_addr_type, uint8_t peer_addr_type,
                       const struct ble_gap_adv_params *adv_params,
                       ble_gap_event_fn *cb, void *cb_arg);
 int ble_gap_adv_stop(void);
-int ble_gap_adv_set_fields(struct ble_hs_adv_fields *adv_fields);
-int ble_gap_adv_rsp_set_fields(struct ble_hs_adv_fields *rsp_fields);
+int ble_gap_adv_set_fields(const struct ble_hs_adv_fields *adv_fields);
+int ble_gap_adv_rsp_set_fields(const struct ble_hs_adv_fields *rsp_fields);
 int ble_gap_disc(uint8_t own_addr_type, int32_t duration_ms,
                  const struct ble_gap_disc_params *disc_params,
                  ble_gap_disc_fn *cb, void *cb_arg);
@@ -310,14 +310,14 @@ int ble_gap_connect(uint8_t own_addr_type,
                     ble_gap_event_fn *cb, void *cb_arg);
 int ble_gap_terminate(uint16_t handle);
 int ble_gap_conn_cancel(void);
-int ble_gap_wl_set(struct ble_gap_white_entry *white_list,
+int ble_gap_wl_set(const struct ble_gap_white_entry *white_list,
                    uint8_t white_list_count);
 int ble_gap_update_params(uint16_t conn_handle,
-                          struct ble_gap_upd_params *params);
+                          const struct ble_gap_upd_params *params);
 int ble_gap_security_initiate(uint16_t conn_handle);
 int ble_gap_pair_initiate(uint16_t conn_handle);
-int ble_gap_encryption_initiate(uint16_t conn_handle, uint8_t *ltk,
+int ble_gap_encryption_initiate(uint16_t conn_handle, const uint8_t *ltk,
                                 uint16_t ediv, uint64_t rand_val, int auth);
-void ble_gap_init_identity_addr(uint8_t *addr);
+void ble_gap_init_identity_addr(const uint8_t *addr);
 
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/63531557/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 6f68ada..76d61cf 100644
--- a/net/nimble/host/include/host/ble_gatt.h
+++ b/net/nimble/host/include/host/ble_gatt.h
@@ -44,7 +44,7 @@ struct ble_gatt_attr {
     uint16_t handle;
     uint16_t offset;
     uint16_t value_len;
-    void *value;
+    const void *value;
 };
 
 struct ble_gatt_chr {
@@ -59,32 +59,37 @@ struct ble_gatt_dsc {
     uint8_t uuid128[16];
 };
 
-typedef int ble_gatt_mtu_fn(uint16_t conn_handle, struct ble_gatt_error *error,
+typedef int ble_gatt_mtu_fn(uint16_t conn_handle,
+                            const struct ble_gatt_error *error,
                             uint16_t mtu, void *arg);
 typedef int ble_gatt_disc_svc_fn(uint16_t conn_handle,
-                                 struct ble_gatt_error *error,
-                                 struct ble_gatt_svc *service,
+                                 const struct ble_gatt_error *error,
+                                 const struct ble_gatt_svc *service,
                                  void *arg);
 typedef int ble_gatt_attr_fn(uint16_t conn_handle,
-                             struct ble_gatt_error *error,
-                             struct ble_gatt_attr *attr, void *arg);
+                             const struct ble_gatt_error *error,
+                             const struct ble_gatt_attr *attr,
+                             void *arg);
 typedef int ble_gatt_reliable_attr_fn(uint16_t conn_handle,
-                                      struct ble_gatt_error *error,
-                                      struct ble_gatt_attr *attrs,
+                                      const struct ble_gatt_error *error,
+                                      const struct ble_gatt_attr *attrs,
                                       uint8_t num_attrs, void *arg);
 
-typedef int ble_gatt_chr_fn(uint16_t conn_handle, struct ble_gatt_error *error,
-                            struct ble_gatt_chr *chr, void *arg);
+typedef int ble_gatt_chr_fn(uint16_t conn_handle,
+                            const struct ble_gatt_error *error,
+                            const struct ble_gatt_chr *chr, void *arg);
 
-typedef int ble_gatt_dsc_fn(uint16_t conn_handle, struct ble_gatt_error *error,
-                            uint16_t chr_def_handle, struct ble_gatt_dsc *dsc,
+typedef int ble_gatt_dsc_fn(uint16_t conn_handle,
+                            const struct ble_gatt_error *error,
+                            uint16_t chr_def_handle,
+                            const struct ble_gatt_dsc *dsc,
                             void *arg);
 
 int ble_gattc_exchange_mtu(uint16_t conn_handle,
                            ble_gatt_mtu_fn *cb, void *cb_arg);
 int ble_gattc_disc_all_svcs(uint16_t conn_handle,
                             ble_gatt_disc_svc_fn *cb, void *cb_arg);
-int ble_gattc_disc_svc_by_uuid(uint16_t conn_handle, void *service_uuid128,
+int ble_gattc_disc_svc_by_uuid(uint16_t conn_handle, const void *svc_uuid128,
                                ble_gatt_disc_svc_fn *cb, void *cb_arg);
 int ble_gattc_find_inc_svcs(uint16_t conn_handle, uint16_t start_handle,
                             uint16_t end_handle,
@@ -93,7 +98,7 @@ int ble_gattc_disc_all_chrs(uint16_t conn_handle, uint16_t start_handle,
                             uint16_t end_handle, ble_gatt_chr_fn *cb,
                             void *cb_arg);
 int ble_gattc_disc_chrs_by_uuid(uint16_t conn_handle, uint16_t start_handle,
-                               uint16_t end_handle, void *uuid128,
+                               uint16_t end_handle, const void *uuid128,
                                ble_gatt_chr_fn *cb, void *cb_arg);
 int ble_gattc_disc_all_dscs(uint16_t conn_handle, uint16_t chr_val_handle,
                             uint16_t chr_end_handle,
@@ -101,21 +106,23 @@ int ble_gattc_disc_all_dscs(uint16_t conn_handle, uint16_t chr_val_handle,
 int ble_gattc_read(uint16_t conn_handle, uint16_t attr_handle,
                    ble_gatt_attr_fn *cb, void *cb_arg);
 int ble_gattc_read_by_uuid(uint16_t conn_handle, uint16_t start_handle,
-                           uint16_t end_handle, void *uuid128,
+                           uint16_t end_handle, const void *uuid128,
                            ble_gatt_attr_fn *cb, void *cb_arg);
 int ble_gattc_read_long(uint16_t conn_handle, uint16_t handle,
                         ble_gatt_attr_fn *cb, void *cb_arg);
-int ble_gattc_read_mult(uint16_t conn_handle, uint16_t *handles,
+int ble_gattc_read_mult(uint16_t conn_handle, const uint16_t *handles,
                         uint8_t num_handles, ble_gatt_attr_fn *cb,
                         void *cb_arg);
 int ble_gattc_write_no_rsp(uint16_t conn_handle, uint16_t attr_handle,
-                           void *value, uint16_t value_len);
-int ble_gattc_write(uint16_t conn_handle, uint16_t attr_handle, void *value,
-                    uint16_t value_len, ble_gatt_attr_fn *cb, void *cb_arg);
+                           const void *value, uint16_t value_len);
+int ble_gattc_write(uint16_t conn_handle, uint16_t attr_handle,
+                    const void *value, uint16_t value_len,
+                    ble_gatt_attr_fn *cb, void *cb_arg);
 int ble_gattc_write_long(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_write_reliable(uint16_t conn_handle, struct ble_gatt_attr *attrs,
+                         const void *value, uint16_t value_len,
+                         ble_gatt_attr_fn *cb, void *cb_arg);
+int ble_gattc_write_reliable(uint16_t conn_handle,
+                             const struct ble_gatt_attr *attrs,
                              int num_attrs, ble_gatt_reliable_attr_fn *cb,
                              void *cb_arg);
 int ble_gattc_read_dsc(uint16_t conn_handle, uint16_t attr_handle,
@@ -123,14 +130,14 @@ int ble_gattc_read_dsc(uint16_t conn_handle, uint16_t attr_handle,
 int ble_gattc_read_long_dsc(uint16_t conn_handle, uint16_t attr_handle,
                             ble_gatt_attr_fn *cb, void *cb_arg);
 int ble_gattc_write_dsc(uint16_t conn_handle, uint16_t attr_handle,
-                        void *value, uint16_t value_len,
+                        const void *value, uint16_t value_len,
                         ble_gatt_attr_fn *cb, void *cb_arg);
 int ble_gattc_write_long_dsc(uint16_t conn_handle, uint16_t attr_handle,
-                             void *value, uint16_t value_len,
+                             const void *value, uint16_t value_len,
                              ble_gatt_attr_fn *cb, void *cb_arg);
 int ble_gattc_notify(uint16_t conn_handle, uint16_t chr_val_handle);
 int ble_gattc_notify_custom(uint16_t conn_handle, uint16_t att_handle,
-                            void *attr_data, uint16_t attr_data_len);
+                            const void *attr_data, uint16_t attr_data_len);
 
 int ble_gattc_init(void);
 
@@ -150,9 +157,9 @@ int ble_gattc_init(void);
 #define BLE_GATT_ACCESS_OP_READ_DSC         2
 #define BLE_GATT_ACCESS_OP_WRITE_DSC        3
 
-union ble_gatt_access_ctxt;
+struct ble_gatt_access_ctxt;
 typedef int ble_gatt_access_fn(uint16_t conn_handle, uint16_t attr_handle,
-                               uint8_t op, union ble_gatt_access_ctxt *ctxt,
+                               uint8_t op, struct ble_gatt_access_ctxt *ctxt,
                                void *arg);
 
 typedef uint16_t ble_gatt_chr_flags;
@@ -192,87 +199,23 @@ struct ble_gatt_svc_def {
     const struct ble_gatt_chr_def *characteristics;
 };
 
-/**
- * Context for reads of characteristics and descriptors.  An instance of this
- * gets passed to an application callback whenever a local characteristic or
- * descriptor is read.
- */
-struct ble_gatt_read_ctxt {
-    /**
-     * (stack --> app)
-     * Maximum number of data bytes the stack can send in the read response.
-     * This is based on the connection's ATT MTU.
-     */
-    uint16_t max_data_len;
-
-    /**
-     * (stack --> app)
-     * A buffer that the app can use to write the characteristic response value
-     * to.  This buffer can hold up to max_data_len bytes.
-     */
-    uint8_t *buf;
-
-    /**
-     * (app --> stack)
-     * App points this at the characteristic data to respond with.  Initially
-     * this points to "buf".
-     */
-    const void *data;
-
-    /**
-     * (app --> stack)
-     * App fills this with the number of data bytes contained in characteristic
-     * response.
-     */
-    uint16_t len;
-};
-
-/**
- * Context for writes of characteristics and descriptors.  An instance of this
- * gets passed to an application callback whenever a local characteristic or
- * descriptor is written.
- */
-struct ble_gatt_write_ctxt {
-    /**
-     * (stack --> app)
-     * The data that the peer is writing to the characteristic.
-     */
-    const void *data;
-
-    /**
-     * (stack --> app)
-     * The number of bytes of characteristic data being written.
-     */
-    int len;
-};
-
-union ble_gatt_access_ctxt {
-    struct {
+struct ble_gatt_access_ctxt {
+    union {
         /**
          * Points to the characteristic defintion corresponding to the
          * characteristic being accessed.  This is what the app registered at
          * startup.
          */
-        const struct ble_gatt_chr_def *def;
-
-        union {
-            struct ble_gatt_read_ctxt read;
-            struct ble_gatt_write_ctxt write;
-        };
-    } chr;
+        const struct ble_gatt_chr_def *chr;
 
-    struct {
         /**
          * Points to the descriptor defintion corresponding to the descriptor
          * being accessed.  This is what the app registered at startup.
          */
-        const struct ble_gatt_dsc_def *def;
+        const struct ble_gatt_dsc_def *dsc;
+    };
 
-        union {
-            struct ble_gatt_read_ctxt read;
-            struct ble_gatt_write_ctxt write;
-        };
-    } dsc;
+    struct ble_att_svr_access_ctxt *att;
 };
 
 struct ble_gatt_dsc_def {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/63531557/net/nimble/host/include/host/ble_hs_adv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/ble_hs_adv.h b/net/nimble/host/include/host/ble_hs_adv.h
index b967ad0..3f7f911 100644
--- a/net/nimble/host/include/host/ble_hs_adv.h
+++ b/net/nimble/host/include/host/ble_hs_adv.h
@@ -171,9 +171,9 @@ struct ble_hs_adv_fields {
 
 #define BLE_HS_ADV_SVC_DATA_UUID128_MIN_LEN     16
 
-int ble_hs_adv_set_flat(uint8_t type, int data_len, void *data,
+int ble_hs_adv_set_flat(uint8_t type, int data_len, const void *data,
                         uint8_t *dst, uint8_t *dst_len, uint8_t max_len);
-int ble_hs_adv_set_fields(struct ble_hs_adv_fields *adv_fields,
+int ble_hs_adv_set_fields(const struct ble_hs_adv_fields *adv_fields,
                           uint8_t *dst, uint8_t *dst_len, uint8_t max_len);
 int ble_hs_adv_parse_fields(struct ble_hs_adv_fields *adv_fields, uint8_t *src,
                             uint8_t src_len);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/63531557/net/nimble/host/include/host/ble_uuid.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/ble_uuid.h b/net/nimble/host/include/host/ble_uuid.h
index 4424f60..1bcc0b4 100644
--- a/net/nimble/host/include/host/ble_uuid.h
+++ b/net/nimble/host/include/host/ble_uuid.h
@@ -25,7 +25,7 @@ struct os_mbuf;
 
 uint16_t ble_uuid_128_to_16(const void *uuid128);
 int ble_uuid_16_to_128(uint16_t uuid16, void *dst);
-int ble_uuid_append(struct os_mbuf *om, void *uuid128);
+int ble_uuid_append(struct os_mbuf *om, const void *uuid128);
 int ble_uuid_extract(struct os_mbuf *om, int off, void *uuid128);
 
 #define BLE_UUID16_ARR(uuid16) {                                            \

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/63531557/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 c33cb39..f2a2a94 100644
--- a/net/nimble/host/include/host/host_hci.h
+++ b/net/nimble/host/include/host/host_hci.h
@@ -32,7 +32,8 @@ int host_hci_os_event_proc(struct os_event *ev);
 int host_hci_event_rx(uint8_t *data);
 uint16_t host_hci_opcode_join(uint8_t ogf, uint16_t ocf);
 void host_hci_write_hdr(uint8_t ogf, uint8_t ocf, uint8_t len, void *buf);
-int host_hci_cmd_send(uint8_t ogf, uint8_t ocf, uint8_t len, void *cmddata);
+int host_hci_cmd_send(uint8_t ogf, uint8_t ocf, uint8_t len,
+                      const void *cmddata);
 int host_hci_cmd_send_buf(void *cmddata);
 void host_hci_cmd_build_set_event_mask(uint64_t event_mask,
                                        uint8_t *dst, int dst_len);
@@ -43,11 +44,11 @@ void host_hci_cmd_build_disconnect(uint16_t handle, uint8_t reason,
 int host_hci_cmd_disconnect(uint16_t handle, uint8_t reason);
 void host_hci_cmd_build_read_rssi(uint16_t handle, uint8_t *dst, int dst_len);
 int host_hci_cmd_read_rssi(uint16_t handle);
-int host_hci_cmd_build_le_set_scan_rsp_data(uint8_t *data, uint8_t len,
+int host_hci_cmd_build_le_set_scan_rsp_data(const uint8_t *data, uint8_t len,
                                             uint8_t *dst, int dst_len);
-int host_hci_cmd_build_le_set_adv_data(uint8_t *data, uint8_t len,
+int host_hci_cmd_build_le_set_adv_data(const uint8_t *data, uint8_t len,
                                        uint8_t *dst, int dst_len);
-int host_hci_cmd_build_le_set_adv_params(struct hci_adv_params *adv,
+int host_hci_cmd_build_le_set_adv_params(const struct hci_adv_params *adv,
                                          uint8_t *dst, int dst_len);
 void host_hci_cmd_build_le_set_event_mask(uint64_t event_mask,
                                           uint8_t *dst, int dst_len);
@@ -62,16 +63,17 @@ int host_hci_cmd_build_le_set_scan_params(uint8_t scan_type,
                                           uint16_t scan_window,
                                           uint8_t own_addr_type,
                                           uint8_t filter_policy,
-                                          uint8_t *cmd, int cmd_len);
+                                          uint8_t *dst, int dst_len);
 void host_hci_cmd_build_le_set_scan_enable(uint8_t enable,
                                            uint8_t filter_dups,
                                            uint8_t *dst, uint8_t dst_len);
 int host_hci_cmd_le_set_scan_enable(uint8_t enable, uint8_t filter_dups);
-int host_hci_cmd_build_le_create_connection(struct hci_create_conn *hcc,
+int host_hci_cmd_build_le_create_connection(const struct hci_create_conn *hcc,
                                             uint8_t *cmd, int cmd_len);
-int host_hci_cmd_le_create_connection(struct hci_create_conn *hcc);
+int host_hci_cmd_le_create_connection(const struct hci_create_conn *hcc);
 void host_hci_cmd_build_le_clear_whitelist(uint8_t *dst, int dst_len);
-int host_hci_cmd_build_le_add_to_whitelist(uint8_t *addr, uint8_t addr_type,
+int host_hci_cmd_build_le_add_to_whitelist(const uint8_t *addr,
+                                           uint8_t addr_type,
                                            uint8_t *dst, int dst_len);
 void host_hci_cmd_build_reset(uint8_t *dst, int dst_len);
 int host_hci_cmd_reset(void);
@@ -79,21 +81,22 @@ void host_hci_cmd_build_read_adv_pwr(uint8_t *dst, int dst_len);
 int host_hci_cmd_read_adv_pwr(void);
 void host_hci_cmd_build_le_create_conn_cancel(uint8_t *dst, int dst_len);
 int host_hci_cmd_le_create_conn_cancel(void);
-int host_hci_cmd_build_le_conn_update(struct hci_conn_update *hcu,
+int host_hci_cmd_build_le_conn_update(const struct hci_conn_update *hcu,
                                       uint8_t *dst, int dst_len);
-int host_hci_cmd_le_conn_update(struct hci_conn_update *hcu);
-void host_hci_cmd_build_le_lt_key_req_reply(struct hci_lt_key_req_reply *hkr,
-                                            uint8_t *dst, int dst_len);
+int host_hci_cmd_le_conn_update(const struct hci_conn_update *hcu);
+void host_hci_cmd_build_le_lt_key_req_reply(
+    const struct hci_lt_key_req_reply *hkr, uint8_t *dst, int dst_len);
 void host_hci_cmd_build_le_lt_key_req_neg_reply(uint16_t conn_handle,
                                                 uint8_t *dst, int dst_len);
-void host_hci_cmd_build_le_conn_param_reply(struct hci_conn_param_reply *hcr,
-                                            uint8_t *dst, int dst_len);
-int host_hci_cmd_le_conn_param_reply(struct hci_conn_param_reply *hcr);
+void host_hci_cmd_build_le_conn_param_reply(
+    const struct hci_conn_param_reply *hcr, uint8_t *dst, int dst_len);
+int host_hci_cmd_le_conn_param_reply(const struct hci_conn_param_reply *hcr);
 void host_hci_cmd_build_le_conn_param_neg_reply(
-    struct hci_conn_param_neg_reply *hcn, uint8_t *dst, int dst_len);
-int host_hci_cmd_le_conn_param_neg_reply(struct hci_conn_param_neg_reply *hcn);
+    const struct hci_conn_param_neg_reply *hcn, uint8_t *dst, int dst_len);
+int host_hci_cmd_le_conn_param_neg_reply(
+    const struct hci_conn_param_neg_reply *hcn);
 void host_hci_cmd_build_le_rand(uint8_t *dst, int dst_len);
-void host_hci_cmd_build_le_start_encrypt(struct hci_start_encrypt *cmd,
+void host_hci_cmd_build_le_start_encrypt(const struct hci_start_encrypt *cmd,
                                          uint8_t *dst, int dst_len);
 int host_hci_set_buf_size(uint16_t pktlen, uint8_t max_pkts);
 
@@ -106,28 +109,26 @@ int host_hci_cmd_build_set_data_len(uint16_t connection_handle,
                                     uint16_t tx_octets, uint16_t tx_time,
                                     uint8_t *dst, int dst_len);
 int host_hci_cmd_build_add_to_resolv_list(
-                                    struct hci_add_dev_to_resolving_list *padd,
-                                    uint8_t *dst, int dst_len);
-int host_hci_cmd_build_remove_from_resolv_list(uint8_t addr_type,
-                                            uint8_t *addr, uint8_t *dst,
-                                            int dst_len);
+    const struct hci_add_dev_to_resolving_list *padd,
+    uint8_t *dst, int dst_len);
+int host_hci_cmd_build_remove_from_resolv_list(
+    uint8_t addr_type, const uint8_t *addr, uint8_t *dst, int dst_len);
 int host_hci_cmd_build_read_resolv_list_size(uint8_t *dst, int dst_len);
-int
-host_hci_cmd_build_clear_resolv_list(uint8_t *dst, int dst_len);
-int host_hci_cmd_build_read_peer_resolv_addr(uint8_t peer_identity_addr_type,
-                                          uint8_t *peer_identity_addr,
-                                          uint8_t *dst, int dst_len);
-int host_hci_cmd_build_read_lcl_resolv_addr(uint8_t local_identity_addr_type,
-                                        uint8_t *local_identity_addr,
-                                        uint8_t *dst, int dst_len);
-int host_hci_cmd_build_set_addr_res_en(uint8_t enable,
-                                          uint8_t *dst, int dst_len);
-int host_hci_cmd_build_set_resolv_priv_addr_timeout(uint16_t timeout,
-                                                            uint8_t *dst,
-                                                            int dst_len);
+int host_hci_cmd_build_clear_resolv_list(uint8_t *dst, int dst_len);
+int host_hci_cmd_build_read_peer_resolv_addr(
+    uint8_t peer_identity_addr_type, const uint8_t *peer_identity_addr,
+    uint8_t *dst, int dst_len);
+int host_hci_cmd_build_read_lcl_resolv_addr(
+    uint8_t local_identity_addr_type, const uint8_t *local_identity_addr,
+    uint8_t *dst, int dst_len);
+int host_hci_cmd_build_set_addr_res_en(
+    uint8_t enable, uint8_t *dst, int dst_len);
+int host_hci_cmd_build_set_resolv_priv_addr_timeout(
+    uint16_t timeout, uint8_t *dst, int dst_len);
 
 void host_hci_timer_set(void);
 
-int host_hci_cmd_build_set_random_addr(uint8_t *addr, uint8_t *dst, int dst_len);
+int host_hci_cmd_build_set_random_addr(const uint8_t *addr,
+                                       uint8_t *dst, int dst_len);
 
 #endif /* H_HOST_HCI_ */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/63531557/net/nimble/host/src/ble_att_clt.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att_clt.c b/net/nimble/host/src/ble_att_clt.c
index dba3527..cb5acc7 100644
--- a/net/nimble/host/src/ble_att_clt.c
+++ b/net/nimble/host/src/ble_att_clt.c
@@ -57,7 +57,7 @@ err:
 
 static int
 ble_att_clt_append_blob(uint16_t conn_handle, struct os_mbuf *txom,
-                        void *blob, int blob_len)
+                        const void *blob, int blob_len)
 {
     int rc;
 
@@ -77,7 +77,7 @@ ble_att_clt_append_blob(uint16_t conn_handle, struct os_mbuf *txom,
 }
 
 static int
-ble_att_clt_copy_attr_to_flatbuf(struct os_mbuf *om, void **out_attr_val,
+ble_att_clt_copy_attr_to_flatbuf(const struct os_mbuf *om, void **out_attr_val,
                                  uint16_t *out_attr_len)
 {
     uint8_t *flat_buf;
@@ -141,17 +141,17 @@ ble_att_clt_tx_req(uint16_t conn_handle, struct os_mbuf *txom)
  *****************************************************************************/
 
 int
-ble_att_clt_rx_error(uint16_t conn_handle, struct os_mbuf **om)
+ble_att_clt_rx_error(uint16_t conn_handle, struct os_mbuf **rxom)
 {
     struct ble_att_error_rsp rsp;
     int rc;
 
-    rc = ble_hs_misc_pullup_base(om, BLE_ATT_ERROR_RSP_SZ);
+    rc = ble_hs_misc_pullup_base(rxom, BLE_ATT_ERROR_RSP_SZ);
     if (rc != 0) {
         return rc;
     }
 
-    ble_att_error_rsp_parse((*om)->om_data, (*om)->om_len, &rsp);
+    ble_att_error_rsp_parse((*rxom)->om_data, (*rxom)->om_len, &rsp);
     BLE_ATT_LOG_CMD(0, "error rsp", conn_handle, ble_att_error_rsp_log, &rsp);
 
     ble_gattc_rx_err(conn_handle, &rsp);
@@ -164,7 +164,7 @@ ble_att_clt_rx_error(uint16_t conn_handle, struct os_mbuf **om)
  *****************************************************************************/
 
 static int
-ble_att_clt_build_mtu_req(struct ble_att_mtu_cmd *req,
+ble_att_clt_build_mtu_req(const struct ble_att_mtu_cmd *req,
                           struct os_mbuf **out_txom)
 {
     struct os_mbuf *txom;
@@ -190,7 +190,7 @@ done:
 }
 
 int
-ble_att_clt_tx_mtu(uint16_t conn_handle, struct ble_att_mtu_cmd *req)
+ble_att_clt_tx_mtu(uint16_t conn_handle, const struct ble_att_mtu_cmd *req)
 {
     struct ble_l2cap_chan *chan;
     struct ble_hs_conn *conn;
@@ -226,7 +226,7 @@ ble_att_clt_tx_mtu(uint16_t conn_handle, struct ble_att_mtu_cmd *req)
 }
 
 int
-ble_att_clt_rx_mtu(uint16_t conn_handle, struct os_mbuf **om)
+ble_att_clt_rx_mtu(uint16_t conn_handle, struct os_mbuf **rxom)
 {
     struct ble_att_mtu_cmd cmd;
     struct ble_l2cap_chan *chan;
@@ -235,9 +235,9 @@ ble_att_clt_rx_mtu(uint16_t conn_handle, struct os_mbuf **om)
 
     mtu = 0;
 
-    rc = ble_hs_misc_pullup_base(om, BLE_ATT_MTU_CMD_SZ);
+    rc = ble_hs_misc_pullup_base(rxom, BLE_ATT_MTU_CMD_SZ);
     if (rc == 0) {
-        ble_att_mtu_cmd_parse((*om)->om_data, (*om)->om_len, &cmd);
+        ble_att_mtu_cmd_parse((*rxom)->om_data, (*rxom)->om_len, &cmd);
         BLE_ATT_LOG_CMD(0, "mtu rsp", conn_handle, ble_att_mtu_cmd_log, &cmd);
 
         ble_hs_lock();
@@ -260,7 +260,7 @@ ble_att_clt_rx_mtu(uint16_t conn_handle, struct os_mbuf **om)
  *****************************************************************************/
 
 static int
-ble_att_clt_build_find_info_req(struct ble_att_find_info_req *req,
+ble_att_clt_build_find_info_req(const struct ble_att_find_info_req *req,
                                 struct os_mbuf **out_txom)
 {
     struct os_mbuf *txom;
@@ -279,7 +279,7 @@ ble_att_clt_build_find_info_req(struct ble_att_find_info_req *req,
 
 int
 ble_att_clt_tx_find_info(uint16_t conn_handle,
-                         struct ble_att_find_info_req *req)
+                         const struct ble_att_find_info_req *req)
 {
 #if !NIMBLE_OPT(ATT_CLT_FIND_INFO)
     return BLE_HS_ENOTSUP;
@@ -409,9 +409,10 @@ done:
  *****************************************************************************/
 
 static int
-ble_att_clt_build_find_type_value_req(struct ble_att_find_type_value_req *req,
-                                      void *attribute_value, int value_len,
-                                      struct os_mbuf **out_txom)
+ble_att_clt_build_find_type_value_req(
+    const struct ble_att_find_type_value_req *req,
+    const void *attribute_value, int value_len,
+    struct os_mbuf **out_txom)
 {
     int rc;
 
@@ -434,8 +435,8 @@ ble_att_clt_build_find_type_value_req(struct ble_att_find_type_value_req *req,
 
 int
 ble_att_clt_tx_find_type_value(uint16_t conn_handle,
-                               struct ble_att_find_type_value_req *req,
-                               void *attribute_value, int value_len)
+                               const struct ble_att_find_type_value_req *req,
+                               const void *attribute_value, int value_len)
 {
 #if !NIMBLE_OPT(ATT_CLT_FIND_TYPE)
     return BLE_HS_ENOTSUP;
@@ -525,8 +526,8 @@ ble_att_clt_rx_find_type_value(uint16_t conn_handle, struct os_mbuf **rxom)
  *****************************************************************************/
 
 static int
-ble_att_clt_build_read_type_req(struct ble_att_read_type_req *req,
-                                void *uuid128, struct os_mbuf **out_txom)
+ble_att_clt_build_read_type_req(const struct ble_att_read_type_req *req,
+                                const void *uuid128, struct os_mbuf **out_txom)
 {
     struct os_mbuf *txom;
     int rc;
@@ -558,8 +559,8 @@ done:
 
 int
 ble_att_clt_tx_read_type(uint16_t conn_handle,
-                         struct ble_att_read_type_req *req,
-                         void *uuid128)
+                         const struct ble_att_read_type_req *req,
+                         const void *uuid128)
 {
 #if !NIMBLE_OPT(ATT_CLT_READ_TYPE)
     return BLE_HS_ENOTSUP;
@@ -654,7 +655,7 @@ done:
  *****************************************************************************/
 
 static int
-ble_att_clt_build_read_req(struct ble_att_read_req *req,
+ble_att_clt_build_read_req(const struct ble_att_read_req *req,
                            struct os_mbuf **out_txom)
 {
     struct os_mbuf *txom;
@@ -680,7 +681,7 @@ done:
 }
 
 int
-ble_att_clt_tx_read(uint16_t conn_handle, struct ble_att_read_req *req)
+ble_att_clt_tx_read(uint16_t conn_handle, const struct ble_att_read_req *req)
 {
 #if !NIMBLE_OPT(ATT_CLT_READ)
     return BLE_HS_ENOTSUP;
@@ -740,7 +741,7 @@ ble_att_clt_rx_read(uint16_t conn_handle, struct os_mbuf **rxom)
  *****************************************************************************/
 
 static int
-ble_att_clt_build_read_blob_req(struct ble_att_read_blob_req *req,
+ble_att_clt_build_read_blob_req(const struct ble_att_read_blob_req *req,
                                 struct os_mbuf **out_txom)
 {
     struct os_mbuf *txom;
@@ -767,7 +768,7 @@ done:
 
 int
 ble_att_clt_tx_read_blob(uint16_t conn_handle,
-                         struct ble_att_read_blob_req *req)
+                         const struct ble_att_read_blob_req *req)
 {
 #if !NIMBLE_OPT(ATT_CLT_READ_BLOB)
     return BLE_HS_ENOTSUP;
@@ -827,7 +828,8 @@ ble_att_clt_rx_read_blob(uint16_t conn_handle, struct os_mbuf **rxom)
  *****************************************************************************/
 
 static int
-ble_att_clt_build_read_mult_req(uint16_t *att_handles, int num_att_handles,
+ble_att_clt_build_read_mult_req(const uint16_t *att_handles,
+                                int num_att_handles,
                                 struct os_mbuf **out_txom)
 {
     struct os_mbuf *txom;
@@ -867,7 +869,7 @@ done:
 }
 
 int
-ble_att_clt_tx_read_mult(uint16_t conn_handle, uint16_t *att_handles,
+ble_att_clt_tx_read_mult(uint16_t conn_handle, const uint16_t *att_handles,
                          int num_att_handles)
 {
 #if !NIMBLE_OPT(ATT_CLT_READ_MULT)
@@ -927,8 +929,9 @@ ble_att_clt_rx_read_mult(uint16_t conn_handle, struct os_mbuf **rxom)
  *****************************************************************************/
 
 static int
-ble_att_clt_build_read_group_type_req(struct ble_att_read_group_type_req *req,
-                                      void *uuid128, struct os_mbuf **out_txom)
+ble_att_clt_build_read_group_type_req(
+    const struct ble_att_read_group_type_req *req, const void *uuid128,
+    struct os_mbuf **out_txom)
 {
     struct os_mbuf *txom;
     int rc;
@@ -959,8 +962,8 @@ done:
 
 int
 ble_att_clt_tx_read_group_type(uint16_t conn_handle,
-                               struct ble_att_read_group_type_req *req,
-                               void *uuid128)
+                               const struct ble_att_read_group_type_req *req,
+                               const void *uuid128)
 {
 #if !NIMBLE_OPT(ATT_CLT_READ_GROUP_TYPE)
     return BLE_HS_ENOTSUP;
@@ -1064,8 +1067,9 @@ done:
 
 static int
 ble_att_clt_build_write_req_or_cmd(uint16_t conn_handle,
-                                   struct ble_att_write_req *req,
-                                   void *value, uint16_t value_len, int is_req,
+                                   const struct ble_att_write_req *req,
+                                   const void *value, uint16_t value_len,
+                                   int is_req,
                                    struct os_mbuf **out_txom)
 {
     struct os_mbuf *txom;
@@ -1101,8 +1105,8 @@ done:
 
 static int
 ble_att_clt_tx_write_req_or_cmd(uint16_t conn_handle,
-                                struct ble_att_write_req *req,
-                                void *value, uint16_t value_len,
+                                const struct ble_att_write_req *req,
+                                const void *value, uint16_t value_len,
                                 int is_req)
 {
     struct os_mbuf *txom;
@@ -1123,8 +1127,9 @@ ble_att_clt_tx_write_req_or_cmd(uint16_t conn_handle,
 }
 
 int
-ble_att_clt_tx_write_req(uint16_t conn_handle, struct ble_att_write_req *req,
-                         void *value, uint16_t value_len)
+ble_att_clt_tx_write_req(uint16_t conn_handle,
+                         const struct ble_att_write_req *req,
+                         const void *value, uint16_t value_len)
 {
 #if !NIMBLE_OPT(ATT_CLT_WRITE)
     return BLE_HS_ENOTSUP;
@@ -1141,8 +1146,8 @@ ble_att_clt_tx_write_req(uint16_t conn_handle, struct ble_att_write_req *req,
 
 int
 ble_att_clt_tx_write_cmd(uint16_t conn_handle,
-                         struct ble_att_write_req *req,
-                         void *value, uint16_t value_len)
+                         const struct ble_att_write_req *req,
+                         const void *value, uint16_t value_len)
 {
 #if !NIMBLE_OPT(ATT_CLT_WRITE_NO_RSP)
     return BLE_HS_ENOTSUP;
@@ -1177,8 +1182,8 @@ ble_att_clt_rx_write(uint16_t conn_handle, struct os_mbuf **rxom)
 
 static int
 ble_att_clt_build_prep_write_req(uint16_t conn_handle,
-                                 struct ble_att_prep_write_cmd *req,
-                                 void *value, uint16_t value_len,
+                                 const struct ble_att_prep_write_cmd *req,
+                                 const void *value, uint16_t value_len,
                                  struct os_mbuf **out_txom)
 {
     struct os_mbuf *txom;
@@ -1210,8 +1215,8 @@ done:
 
 int
 ble_att_clt_tx_prep_write(uint16_t conn_handle,
-                          struct ble_att_prep_write_cmd *req,
-                          void *value, uint16_t value_len)
+                          const struct ble_att_prep_write_cmd *req,
+                          const void *value, uint16_t value_len)
 {
 #if !NIMBLE_OPT(ATT_CLT_PREP_WRITE)
     return BLE_HS_ENOTSUP;
@@ -1294,7 +1299,7 @@ done:
  *****************************************************************************/
 
 static int
-ble_att_clt_build_exec_write_req(struct ble_att_exec_write_req *req,
+ble_att_clt_build_exec_write_req(const struct ble_att_exec_write_req *req,
                                  struct os_mbuf **out_txom)
 {
     struct os_mbuf *txom;
@@ -1321,7 +1326,7 @@ done:
 
 int
 ble_att_clt_tx_exec_write(uint16_t conn_handle,
-                          struct ble_att_exec_write_req *req)
+                          const struct ble_att_exec_write_req *req)
 {
 #if !NIMBLE_OPT(ATT_CLT_EXEC_WRITE)
     return BLE_HS_ENOTSUP;
@@ -1376,8 +1381,8 @@ ble_att_clt_rx_exec_write(uint16_t conn_handle, struct os_mbuf **rxom)
 
 static int
 ble_att_clt_build_notify_req(uint16_t conn_handle,
-                             struct ble_att_notify_req *req,
-                             void *value, uint16_t value_len,
+                             const struct ble_att_notify_req *req,
+                             const void *value, uint16_t value_len,
                              struct os_mbuf **out_txom)
 {
     struct os_mbuf *txom;
@@ -1408,8 +1413,9 @@ done:
 }
 
 int
-ble_att_clt_tx_notify(uint16_t conn_handle, struct ble_att_notify_req *req,
-                      void *value, uint16_t value_len)
+ble_att_clt_tx_notify(uint16_t conn_handle,
+                      const struct ble_att_notify_req *req,
+                      const void *value, uint16_t value_len)
 {
 #if !NIMBLE_OPT(ATT_CLT_NOTIFY)
     return BLE_HS_ENOTSUP;
@@ -1444,8 +1450,8 @@ ble_att_clt_tx_notify(uint16_t conn_handle, struct ble_att_notify_req *req,
 
 static int
 ble_att_clt_build_indicate_req(uint16_t conn_handle,
-                               struct ble_att_indicate_req *req,
-                               void *value, uint16_t value_len,
+                               const struct ble_att_indicate_req *req,
+                               const void *value, uint16_t value_len,
                                struct os_mbuf **out_txom)
 {
     struct os_mbuf *txom;
@@ -1477,8 +1483,8 @@ done:
 
 int
 ble_att_clt_tx_indicate(uint16_t conn_handle,
-                        struct ble_att_indicate_req *req,
-                        void *value, uint16_t value_len)
+                        const struct ble_att_indicate_req *req,
+                        const void *value, uint16_t value_len)
 {
 #if !NIMBLE_OPT(ATT_CLT_INDICATE)
     return BLE_HS_ENOTSUP;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/63531557/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 5df0846..b8ca094 100644
--- a/net/nimble/host/src/ble_att_cmd.c
+++ b/net/nimble/host/src/ble_att_cmd.c
@@ -26,10 +26,11 @@
 #include "host/ble_uuid.h"
 #include "ble_hs_priv.h"
 
-static void *
-ble_att_init_parse(uint8_t op, void *payload, int min_len, int actual_len)
+static const void *
+ble_att_init_parse(uint8_t op, const void *payload,
+                   int min_len, int actual_len)
 {
-    uint8_t *u8ptr;
+    const uint8_t *u8ptr;
 
     BLE_HS_DBG_ASSERT(actual_len >= min_len);
 
@@ -39,11 +40,11 @@ ble_att_init_parse(uint8_t op, void *payload, int min_len, int actual_len)
     return u8ptr + 1;
 }
 
-static void *
-ble_att_init_parse_2op(uint8_t op1, uint8_t op2, void *payload,
+static const void *
+ble_att_init_parse_2op(uint8_t op1, uint8_t op2, const void *payload,
                        int min_len, int actual_len)
 {
-    uint8_t *u8ptr;
+    const uint8_t *u8ptr;
 
     BLE_HS_DBG_ASSERT(actual_len >= min_len);
 
@@ -68,7 +69,7 @@ ble_att_init_write(uint8_t op, void *payload, int min_len, int actual_len)
 
 static void
 ble_att_error_rsp_swap(struct ble_att_error_rsp *dst,
-                       struct ble_att_error_rsp *src)
+                       const struct ble_att_error_rsp *src)
 {
     dst->baep_req_op = src->baep_req_op;
     dst->baep_handle = TOFROMLE16(src->baep_handle);
@@ -76,9 +77,10 @@ ble_att_error_rsp_swap(struct ble_att_error_rsp *dst,
 }
 
 void
-ble_att_error_rsp_parse(void *payload, int len, struct ble_att_error_rsp *dst)
+ble_att_error_rsp_parse(const void *payload, int len,
+                        struct ble_att_error_rsp *dst)
 {
-    struct ble_att_error_rsp *src;
+    const struct ble_att_error_rsp *src;
 
     src = ble_att_init_parse(BLE_ATT_OP_ERROR_RSP, payload,
                              BLE_ATT_ERROR_RSP_SZ, len);
@@ -86,7 +88,8 @@ ble_att_error_rsp_parse(void *payload, int len, struct ble_att_error_rsp *dst)
 }
 
 void
-ble_att_error_rsp_write(void *payload, int len, struct ble_att_error_rsp *src)
+ble_att_error_rsp_write(void *payload, int len,
+                        const struct ble_att_error_rsp *src)
 {
     struct ble_att_error_rsp *dst;
 
@@ -96,22 +99,24 @@ ble_att_error_rsp_write(void *payload, int len, struct ble_att_error_rsp *src)
 }
 
 void
-ble_att_error_rsp_log(struct ble_att_error_rsp *cmd)
+ble_att_error_rsp_log(const struct ble_att_error_rsp *cmd)
 {
     BLE_HS_LOG(DEBUG, "req_op=%d handle=0x%04x error_code=%d",
                cmd->baep_req_op, cmd->baep_handle, cmd->baep_error_code);
 }
 
 static void
-ble_att_mtu_cmd_swap(struct ble_att_mtu_cmd *dst, struct ble_att_mtu_cmd *src)
+ble_att_mtu_cmd_swap(struct ble_att_mtu_cmd *dst,
+                     const struct ble_att_mtu_cmd *src)
 {
     dst->bamc_mtu = TOFROMLE16(src->bamc_mtu);
 }
 
 void
-ble_att_mtu_cmd_parse(void *payload, int len, struct ble_att_mtu_cmd *dst)
+ble_att_mtu_cmd_parse(const void *payload, int len,
+                      struct ble_att_mtu_cmd *dst)
 {
-    struct ble_att_mtu_cmd *src;
+    const struct ble_att_mtu_cmd *src;
 
     src = ble_att_init_parse_2op(BLE_ATT_OP_MTU_REQ, BLE_ATT_OP_MTU_RSP,
                                  payload, BLE_ATT_MTU_CMD_SZ, len);
@@ -119,7 +124,8 @@ ble_att_mtu_cmd_parse(void *payload, int len, struct ble_att_mtu_cmd *dst)
 }
 
 void
-ble_att_mtu_req_write(void *payload, int len, struct ble_att_mtu_cmd *src)
+ble_att_mtu_req_write(void *payload, int len,
+                      const struct ble_att_mtu_cmd *src)
 {
     struct ble_att_mtu_cmd *dst;
 
@@ -129,7 +135,8 @@ ble_att_mtu_req_write(void *payload, int len, struct ble_att_mtu_cmd *src)
 }
 
 void
-ble_att_mtu_rsp_write(void *payload, int len, struct ble_att_mtu_cmd *src)
+ble_att_mtu_rsp_write(void *payload, int len,
+                      const struct ble_att_mtu_cmd *src)
 {
     struct ble_att_mtu_cmd *dst;
 
@@ -139,24 +146,24 @@ ble_att_mtu_rsp_write(void *payload, int len, struct ble_att_mtu_cmd *src)
 }
 
 void
-ble_att_mtu_cmd_log(struct ble_att_mtu_cmd *cmd)
+ble_att_mtu_cmd_log(const struct ble_att_mtu_cmd *cmd)
 {
     BLE_HS_LOG(DEBUG, "mtu=%d", cmd->bamc_mtu);
 }
 
 static void
 ble_att_find_info_req_swap(struct ble_att_find_info_req *dst,
-                           struct ble_att_find_info_req *src)
+                           const struct ble_att_find_info_req *src)
 {
     dst->bafq_start_handle = TOFROMLE16(src->bafq_start_handle);
     dst->bafq_end_handle = TOFROMLE16(src->bafq_end_handle);
 }
 
 void
-ble_att_find_info_req_parse(void *payload, int len,
+ble_att_find_info_req_parse(const void *payload, int len,
                             struct ble_att_find_info_req *dst)
 {
-    struct ble_att_find_info_req *src;
+    const struct ble_att_find_info_req *src;
 
     src = ble_att_init_parse(BLE_ATT_OP_FIND_INFO_REQ, payload,
                              BLE_ATT_FIND_INFO_REQ_SZ, len);
@@ -165,7 +172,7 @@ ble_att_find_info_req_parse(void *payload, int len,
 
 void
 ble_att_find_info_req_write(void *payload, int len,
-                            struct ble_att_find_info_req *src)
+                            const struct ble_att_find_info_req *src)
 {
     struct ble_att_find_info_req *dst;
 
@@ -175,7 +182,7 @@ ble_att_find_info_req_write(void *payload, int len,
 }
 
 void
-ble_att_find_info_req_log(struct ble_att_find_info_req *cmd)
+ble_att_find_info_req_log(const struct ble_att_find_info_req *cmd)
 {
     BLE_HS_LOG(DEBUG, "start_handle=0x%04x end_handle=0x%04x",
                cmd->bafq_start_handle, cmd->bafq_end_handle);
@@ -183,16 +190,16 @@ ble_att_find_info_req_log(struct ble_att_find_info_req *cmd)
 
 static void
 ble_att_find_info_rsp_swap(struct ble_att_find_info_rsp *dst,
-                           struct ble_att_find_info_rsp *src)
+                           const struct ble_att_find_info_rsp *src)
 {
     dst->bafp_format = src->bafp_format;
 }
 
 void
-ble_att_find_info_rsp_parse(void *payload, int len,
+ble_att_find_info_rsp_parse(const void *payload, int len,
                             struct ble_att_find_info_rsp *dst)
 {
-    struct ble_att_find_info_rsp *src;
+    const struct ble_att_find_info_rsp *src;
 
     src = ble_att_init_parse(BLE_ATT_OP_FIND_INFO_RSP, payload,
                              BLE_ATT_FIND_INFO_RSP_BASE_SZ, len);
@@ -201,7 +208,7 @@ ble_att_find_info_rsp_parse(void *payload, int len,
 
 void
 ble_att_find_info_rsp_write(void *payload, int len,
-                            struct ble_att_find_info_rsp *src)
+                            const struct ble_att_find_info_rsp *src)
 {
     struct ble_att_find_info_rsp *dst;
 
@@ -211,14 +218,14 @@ ble_att_find_info_rsp_write(void *payload, int len,
 }
 
 void
-ble_att_find_info_rsp_log(struct ble_att_find_info_rsp *cmd)
+ble_att_find_info_rsp_log(const struct ble_att_find_info_rsp *cmd)
 {
     BLE_HS_LOG(DEBUG, "format=%d", cmd->bafp_format);
 }
 
 static void
 ble_att_find_type_value_req_swap(struct ble_att_find_type_value_req *dst,
-                                 struct ble_att_find_type_value_req *src)
+                                 const struct ble_att_find_type_value_req *src)
 {
     dst->bavq_start_handle = TOFROMLE16(src->bavq_start_handle);
     dst->bavq_end_handle = TOFROMLE16(src->bavq_end_handle);
@@ -226,10 +233,10 @@ ble_att_find_type_value_req_swap(struct ble_att_find_type_value_req *dst,
 }
 
 void
-ble_att_find_type_value_req_parse(void *payload, int len,
+ble_att_find_type_value_req_parse(const void *payload, int len,
                                   struct ble_att_find_type_value_req *dst)
 {
-    struct ble_att_find_type_value_req *src;
+    const struct ble_att_find_type_value_req *src;
 
     src = ble_att_init_parse(BLE_ATT_OP_FIND_TYPE_VALUE_REQ, payload,
                              BLE_ATT_FIND_TYPE_VALUE_REQ_BASE_SZ, len);
@@ -237,8 +244,8 @@ ble_att_find_type_value_req_parse(void *payload, int len,
 }
 
 void
-ble_att_find_type_value_req_write(void *payload, int len,
-                                  struct ble_att_find_type_value_req *src)
+ble_att_find_type_value_req_write(
+    void *payload, int len, const struct ble_att_find_type_value_req *src)
 {
     struct ble_att_find_type_value_req *dst;
 
@@ -248,7 +255,7 @@ ble_att_find_type_value_req_write(void *payload, int len,
 }
 
 void
-ble_att_find_type_value_req_log(struct ble_att_find_type_value_req *cmd)
+ble_att_find_type_value_req_log(const struct ble_att_find_type_value_req *cmd)
 {
     BLE_HS_LOG(DEBUG, "start_handle=0x%04x end_handle=0x%04x attr_type=%d",
                cmd->bavq_start_handle, cmd->bavq_end_handle,
@@ -257,17 +264,17 @@ ble_att_find_type_value_req_log(struct ble_att_find_type_value_req *cmd)
 
 static void
 ble_att_read_type_req_swap(struct ble_att_read_type_req *dst,
-                           struct ble_att_read_type_req *src)
+                           const struct ble_att_read_type_req *src)
 {
     dst->batq_start_handle = TOFROMLE16(src->batq_start_handle);
     dst->batq_end_handle = TOFROMLE16(src->batq_end_handle);
 }
 
 void
-ble_att_read_type_req_parse(void *payload, int len,
+ble_att_read_type_req_parse(const void *payload, int len,
                             struct ble_att_read_type_req *dst)
 {
-    struct ble_att_read_type_req *src;
+    const struct ble_att_read_type_req *src;
 
     src = ble_att_init_parse(BLE_ATT_OP_READ_TYPE_REQ, payload,
                              BLE_ATT_READ_TYPE_REQ_BASE_SZ, len);
@@ -276,7 +283,7 @@ ble_att_read_type_req_parse(void *payload, int len,
 
 void
 ble_att_read_type_req_write(void *payload, int len,
-                            struct ble_att_read_type_req *src)
+                            const struct ble_att_read_type_req *src)
 {
     struct ble_att_read_type_req *dst;
 
@@ -286,7 +293,7 @@ ble_att_read_type_req_write(void *payload, int len,
 }
 
 void
-ble_att_read_type_req_log(struct ble_att_read_type_req *cmd)
+ble_att_read_type_req_log(const struct ble_att_read_type_req *cmd)
 {
     BLE_HS_LOG(DEBUG, "start_handle=0x%04x end_handle=0x%04x",
                cmd->batq_start_handle, cmd->batq_end_handle);
@@ -294,16 +301,16 @@ ble_att_read_type_req_log(struct ble_att_read_type_req *cmd)
 
 static void
 ble_att_read_type_rsp_swap(struct ble_att_read_type_rsp *dst,
-                           struct ble_att_read_type_rsp *src)
+                           const struct ble_att_read_type_rsp *src)
 {
     dst->batp_length = src->batp_length;
 }
 
 void
-ble_att_read_type_rsp_parse(void *payload, int len,
+ble_att_read_type_rsp_parse(const void *payload, int len,
                             struct ble_att_read_type_rsp *dst)
 {
-    struct ble_att_read_type_rsp *src;
+    const struct ble_att_read_type_rsp *src;
 
     src = ble_att_init_parse(BLE_ATT_OP_READ_TYPE_RSP, payload,
                              BLE_ATT_READ_TYPE_RSP_BASE_SZ, len);
@@ -312,7 +319,7 @@ ble_att_read_type_rsp_parse(void *payload, int len,
 
 void
 ble_att_read_type_rsp_write(void *payload, int len,
-                            struct ble_att_read_type_rsp *src)
+                            const struct ble_att_read_type_rsp *src)
 {
     struct ble_att_read_type_rsp *dst;
 
@@ -322,22 +329,23 @@ ble_att_read_type_rsp_write(void *payload, int len,
 }
 
 void
-ble_att_read_type_rsp_log(struct ble_att_read_type_rsp *cmd)
+ble_att_read_type_rsp_log(const struct ble_att_read_type_rsp *cmd)
 {
     BLE_HS_LOG(DEBUG, "length=%d", cmd->batp_length);
 }
 
 static void
 ble_att_read_req_swap(struct ble_att_read_req *dst,
-                      struct ble_att_read_req *src)
+                      const struct ble_att_read_req *src)
 {
     dst->barq_handle = TOFROMLE16(src->barq_handle);
 }
 
 void
-ble_att_read_req_parse(void *payload, int len, struct ble_att_read_req *dst)
+ble_att_read_req_parse(const void *payload, int len,
+                       struct ble_att_read_req *dst)
 {
-    struct ble_att_read_req *src;
+    const struct ble_att_read_req *src;
 
     src = ble_att_init_parse(BLE_ATT_OP_READ_REQ, payload,
                              BLE_ATT_READ_REQ_SZ, len);
@@ -345,7 +353,8 @@ ble_att_read_req_parse(void *payload, int len, struct ble_att_read_req *dst)
 }
 
 void
-ble_att_read_req_write(void *payload, int len, struct ble_att_read_req *src)
+ble_att_read_req_write(void *payload, int len,
+                       const struct ble_att_read_req *src)
 {
     struct ble_att_read_req *dst;
 
@@ -355,24 +364,24 @@ ble_att_read_req_write(void *payload, int len, struct ble_att_read_req *src)
 }
 
 void
-ble_att_read_req_log(struct ble_att_read_req *cmd)
+ble_att_read_req_log(const struct ble_att_read_req *cmd)
 {
     BLE_HS_LOG(DEBUG, "handle=0x%04x", cmd->barq_handle);
 }
 
 static void
 ble_att_read_blob_req_swap(struct ble_att_read_blob_req *dst,
-                           struct ble_att_read_blob_req *src)
+                           const struct ble_att_read_blob_req *src)
 {
     dst->babq_handle = TOFROMLE16(src->babq_handle);
     dst->babq_offset = TOFROMLE16(src->babq_offset);
 }
 
 void
-ble_att_read_blob_req_parse(void *payload, int len,
+ble_att_read_blob_req_parse(const void *payload, int len,
                             struct ble_att_read_blob_req *dst)
 {
-    struct ble_att_read_blob_req *src;
+    const struct ble_att_read_blob_req *src;
 
     src = ble_att_init_parse(BLE_ATT_OP_READ_BLOB_REQ, payload,
                              BLE_ATT_READ_BLOB_REQ_SZ, len);
@@ -381,7 +390,7 @@ ble_att_read_blob_req_parse(void *payload, int len,
 
 void
 ble_att_read_blob_req_write(void *payload, int len,
-                            struct ble_att_read_blob_req *src)
+                            const struct ble_att_read_blob_req *src)
 {
     struct ble_att_read_blob_req *dst;
 
@@ -391,14 +400,14 @@ ble_att_read_blob_req_write(void *payload, int len,
 }
 
 void
-ble_att_read_blob_req_log(struct ble_att_read_blob_req *cmd)
+ble_att_read_blob_req_log(const struct ble_att_read_blob_req *cmd)
 {
     BLE_HS_LOG(DEBUG, "handle=0x%04x offset=%d", cmd->babq_handle,
                cmd->babq_offset);
 }
 
 void
-ble_att_read_mult_req_parse(void *payload, int len)
+ble_att_read_mult_req_parse(const void *payload, int len)
 {
     ble_att_init_parse(BLE_ATT_OP_READ_MULT_REQ, payload,
                        BLE_ATT_READ_MULT_REQ_BASE_SZ, len);
@@ -412,7 +421,7 @@ ble_att_read_mult_req_write(void *payload, int len)
 }
 
 void
-ble_att_read_mult_rsp_parse(void *payload, int len)
+ble_att_read_mult_rsp_parse(const void *payload, int len)
 {
     ble_att_init_parse(BLE_ATT_OP_READ_MULT_RSP, payload,
                        BLE_ATT_READ_MULT_RSP_BASE_SZ, len);
@@ -427,17 +436,17 @@ ble_att_read_mult_rsp_write(void *payload, int len)
 
 static void
 ble_att_read_group_type_req_swap(struct ble_att_read_group_type_req *dst,
-                                 struct ble_att_read_group_type_req *src)
+                                 const struct ble_att_read_group_type_req *src)
 {
     dst->bagq_start_handle = TOFROMLE16(src->bagq_start_handle);
     dst->bagq_end_handle = TOFROMLE16(src->bagq_end_handle);
 }
 
 void
-ble_att_read_group_type_req_parse(void *payload, int len,
+ble_att_read_group_type_req_parse(const void *payload, int len,
                                   struct ble_att_read_group_type_req *dst)
 {
-    struct ble_att_read_group_type_req *src;
+    const struct ble_att_read_group_type_req *src;
 
     src = ble_att_init_parse(BLE_ATT_OP_READ_GROUP_TYPE_REQ, payload,
                              BLE_ATT_READ_GROUP_TYPE_REQ_BASE_SZ, len);
@@ -445,8 +454,8 @@ ble_att_read_group_type_req_parse(void *payload, int len,
 }
 
 void
-ble_att_read_group_type_req_write(void *payload, int len,
-                                  struct ble_att_read_group_type_req *src)
+ble_att_read_group_type_req_write(
+    void *payload, int len, const struct ble_att_read_group_type_req *src)
 {
     struct ble_att_read_group_type_req *dst;
 
@@ -456,7 +465,7 @@ ble_att_read_group_type_req_write(void *payload, int len,
 }
 
 void
-ble_att_read_group_type_req_log(struct ble_att_read_group_type_req *cmd)
+ble_att_read_group_type_req_log(const struct ble_att_read_group_type_req *cmd)
 {
     BLE_HS_LOG(DEBUG, "start_handle=0x%04x end_handle=0x%04x",
                cmd->bagq_start_handle, cmd->bagq_end_handle);
@@ -464,16 +473,16 @@ ble_att_read_group_type_req_log(struct ble_att_read_group_type_req *cmd)
 
 static void
 ble_att_read_group_type_rsp_swap(struct ble_att_read_group_type_rsp *dst,
-                                 struct ble_att_read_group_type_rsp *src)
+                                 const struct ble_att_read_group_type_rsp *src)
 {
     dst->bagp_length = src->bagp_length;
 }
 
 void
-ble_att_read_group_type_rsp_parse(void *payload, int len,
+ble_att_read_group_type_rsp_parse(const void *payload, int len,
                                   struct ble_att_read_group_type_rsp *dst)
 {
-    struct ble_att_read_group_type_rsp *src;
+    const struct ble_att_read_group_type_rsp *src;
 
     src = ble_att_init_parse(BLE_ATT_OP_READ_GROUP_TYPE_RSP, payload,
                              BLE_ATT_READ_GROUP_TYPE_RSP_BASE_SZ, len);
@@ -481,8 +490,8 @@ ble_att_read_group_type_rsp_parse(void *payload, int len,
 }
 
 void
-ble_att_read_group_type_rsp_write(void *payload, int len,
-                                  struct ble_att_read_group_type_rsp *src)
+ble_att_read_group_type_rsp_write(
+    void *payload, int len, const struct ble_att_read_group_type_rsp *src)
 {
     struct ble_att_read_group_type_rsp *dst;
 
@@ -492,22 +501,23 @@ ble_att_read_group_type_rsp_write(void *payload, int len,
 }
 
 void
-ble_att_read_group_type_rsp_log(struct ble_att_read_group_type_rsp *cmd)
+ble_att_read_group_type_rsp_log(const struct ble_att_read_group_type_rsp *cmd)
 {
     BLE_HS_LOG(DEBUG, "length=%d", cmd->bagp_length);
 }
 
 static void
 ble_att_write_req_swap(struct ble_att_write_req *dst,
-                       struct ble_att_write_req *src)
+                       const struct ble_att_write_req *src)
 {
     dst->bawq_handle = TOFROMLE16(src->bawq_handle);
 }
 
 void
-ble_att_write_req_parse(void *payload, int len, struct ble_att_write_req *dst)
+ble_att_write_req_parse(const void *payload, int len,
+                        struct ble_att_write_req *dst)
 {
-    struct ble_att_write_req *src;
+    const struct ble_att_write_req *src;
 
     src = ble_att_init_parse(BLE_ATT_OP_WRITE_REQ, payload,
                              BLE_ATT_WRITE_REQ_BASE_SZ, len);
@@ -515,9 +525,10 @@ ble_att_write_req_parse(void *payload, int len, struct ble_att_write_req *dst)
 }
 
 void
-ble_att_write_cmd_parse(void *payload, int len, struct ble_att_write_req *dst)
+ble_att_write_cmd_parse(const void *payload, int len,
+                        struct ble_att_write_req *dst)
 {
-    struct ble_att_write_req *src;
+    const struct ble_att_write_req *src;
 
     src = ble_att_init_parse(BLE_ATT_OP_WRITE_CMD, payload,
                              BLE_ATT_WRITE_REQ_BASE_SZ, len);
@@ -525,7 +536,8 @@ ble_att_write_cmd_parse(void *payload, int len, struct ble_att_write_req *dst)
 }
 
 void
-ble_att_write_req_write(void *payload, int len, struct ble_att_write_req *src)
+ble_att_write_req_write(void *payload, int len,
+                        const struct ble_att_write_req *src)
 {
     struct ble_att_write_req *dst;
 
@@ -535,7 +547,8 @@ ble_att_write_req_write(void *payload, int len, struct ble_att_write_req *src)
 }
 
 void
-ble_att_write_cmd_write(void *payload, int len, struct ble_att_write_req *src)
+ble_att_write_cmd_write(void *payload, int len,
+                        const struct ble_att_write_req *src)
 {
     struct ble_att_write_req *dst;
 
@@ -545,24 +558,24 @@ ble_att_write_cmd_write(void *payload, int len, struct ble_att_write_req *src)
 }
 
 void
-ble_att_write_cmd_log(struct ble_att_write_req *cmd)
+ble_att_write_cmd_log(const struct ble_att_write_req *cmd)
 {
     BLE_HS_LOG(DEBUG, "handle=0x%04x", cmd->bawq_handle);
 }
 
 static void
 ble_att_prep_write_cmd_swap(struct ble_att_prep_write_cmd *dst,
-                            struct ble_att_prep_write_cmd *src)
+                            const struct ble_att_prep_write_cmd *src)
 {
     dst->bapc_handle = TOFROMLE16(src->bapc_handle);
     dst->bapc_offset = TOFROMLE16(src->bapc_offset);
 }
 
 void
-ble_att_prep_write_req_parse(void *payload, int len,
+ble_att_prep_write_req_parse(const void *payload, int len,
                              struct ble_att_prep_write_cmd *dst)
 {
-    struct ble_att_prep_write_cmd *src;
+    const struct ble_att_prep_write_cmd *src;
 
     src = ble_att_init_parse(BLE_ATT_OP_PREP_WRITE_REQ, payload,
                              BLE_ATT_PREP_WRITE_CMD_BASE_SZ, len);
@@ -571,7 +584,7 @@ ble_att_prep_write_req_parse(void *payload, int len,
 
 void
 ble_att_prep_write_req_write(void *payload, int len,
-                             struct ble_att_prep_write_cmd *src)
+                             const struct ble_att_prep_write_cmd *src)
 {
     struct ble_att_prep_write_cmd *dst;
 
@@ -581,10 +594,10 @@ ble_att_prep_write_req_write(void *payload, int len,
 }
 
 void
-ble_att_prep_write_rsp_parse(void *payload, int len,
+ble_att_prep_write_rsp_parse(const void *payload, int len,
                              struct ble_att_prep_write_cmd *dst)
 {
-    struct ble_att_prep_write_cmd *src;
+    const struct ble_att_prep_write_cmd *src;
 
     src = ble_att_init_parse(BLE_ATT_OP_PREP_WRITE_RSP, payload,
                              BLE_ATT_PREP_WRITE_CMD_BASE_SZ, len);
@@ -593,7 +606,7 @@ ble_att_prep_write_rsp_parse(void *payload, int len,
 
 void
 ble_att_prep_write_rsp_write(void *payload, int len,
-                             struct ble_att_prep_write_cmd *src)
+                             const struct ble_att_prep_write_cmd *src)
 {
     struct ble_att_prep_write_cmd *dst;
 
@@ -603,7 +616,7 @@ ble_att_prep_write_rsp_write(void *payload, int len,
 }
 
 void
-ble_att_prep_write_cmd_log(struct ble_att_prep_write_cmd *cmd)
+ble_att_prep_write_cmd_log(const struct ble_att_prep_write_cmd *cmd)
 {
     BLE_HS_LOG(DEBUG, "handle=0x%04x offset=%d", cmd->bapc_handle,
                cmd->bapc_offset);
@@ -611,16 +624,16 @@ ble_att_prep_write_cmd_log(struct ble_att_prep_write_cmd *cmd)
 
 static void
 ble_att_exec_write_req_swap(struct ble_att_exec_write_req *dst,
-                            struct ble_att_exec_write_req *src)
+                            const struct ble_att_exec_write_req *src)
 {
     dst->baeq_flags = src->baeq_flags;
 }
 
 void
-ble_att_exec_write_req_parse(void *payload, int len,
+ble_att_exec_write_req_parse(const void *payload, int len,
                              struct ble_att_exec_write_req *dst)
 {
-    struct ble_att_exec_write_req *src;
+    const struct ble_att_exec_write_req *src;
 
     src = ble_att_init_parse(BLE_ATT_OP_EXEC_WRITE_REQ, payload,
                              BLE_ATT_EXEC_WRITE_REQ_SZ, len);
@@ -629,7 +642,7 @@ ble_att_exec_write_req_parse(void *payload, int len,
 
 void
 ble_att_exec_write_req_write(void *payload, int len,
-                             struct ble_att_exec_write_req *src)
+                             const struct ble_att_exec_write_req *src)
 {
     struct ble_att_exec_write_req *dst;
 
@@ -639,13 +652,13 @@ ble_att_exec_write_req_write(void *payload, int len,
 }
 
 void
-ble_att_exec_write_req_log(struct ble_att_exec_write_req *cmd)
+ble_att_exec_write_req_log(const struct ble_att_exec_write_req *cmd)
 {
     BLE_HS_LOG(DEBUG, "flags=0x%02x", cmd->baeq_flags);
 }
 
 void
-ble_att_exec_write_rsp_parse(void *payload, int len)
+ble_att_exec_write_rsp_parse(const void *payload, int len)
 {
     ble_att_init_parse(BLE_ATT_OP_EXEC_WRITE_RSP, payload,
                        BLE_ATT_EXEC_WRITE_RSP_SZ, len);
@@ -660,16 +673,16 @@ ble_att_exec_write_rsp_write(void *payload, int len)
 
 static void
 ble_att_notify_req_swap(struct ble_att_notify_req *dst,
-                        struct ble_att_notify_req *src)
+                        const struct ble_att_notify_req *src)
 {
     dst->banq_handle = TOFROMLE16(src->banq_handle);
 }
 
 void
-ble_att_notify_req_parse(void *payload, int len,
+ble_att_notify_req_parse(const void *payload, int len,
                          struct ble_att_notify_req *dst)
 {
-    struct ble_att_notify_req *src;
+    const struct ble_att_notify_req *src;
 
     src = ble_att_init_parse(BLE_ATT_OP_NOTIFY_REQ, payload,
                              BLE_ATT_NOTIFY_REQ_BASE_SZ, len);
@@ -678,7 +691,7 @@ ble_att_notify_req_parse(void *payload, int len,
 
 void
 ble_att_notify_req_write(void *payload, int len,
-                         struct ble_att_notify_req *src)
+                         const struct ble_att_notify_req *src)
 {
     struct ble_att_notify_req *dst;
 
@@ -688,23 +701,23 @@ ble_att_notify_req_write(void *payload, int len,
 }
 
 void
-ble_att_notify_req_log(struct ble_att_notify_req *cmd)
+ble_att_notify_req_log(const struct ble_att_notify_req *cmd)
 {
     BLE_HS_LOG(DEBUG, "handle=0x%04x", cmd->banq_handle);
 }
 
 static void
 ble_att_indicate_req_swap(struct ble_att_indicate_req *dst,
-                          struct ble_att_indicate_req *src)
+                          const struct ble_att_indicate_req *src)
 {
     dst->baiq_handle = TOFROMLE16(src->baiq_handle);
 }
 
 void
-ble_att_indicate_req_parse(void *payload, int len,
+ble_att_indicate_req_parse(const void *payload, int len,
                            struct ble_att_indicate_req *dst)
 {
-    struct ble_att_indicate_req *src;
+    const struct ble_att_indicate_req *src;
 
     src = ble_att_init_parse(BLE_ATT_OP_INDICATE_REQ, payload,
                              BLE_ATT_INDICATE_REQ_BASE_SZ, len);
@@ -713,7 +726,7 @@ ble_att_indicate_req_parse(void *payload, int len,
 
 void
 ble_att_indicate_req_write(void *payload, int len,
-                           struct ble_att_indicate_req *src)
+                           const struct ble_att_indicate_req *src)
 {
     struct ble_att_indicate_req *dst;
 
@@ -723,13 +736,13 @@ ble_att_indicate_req_write(void *payload, int len,
 }
 
 void
-ble_att_indicate_req_log(struct ble_att_indicate_req *cmd)
+ble_att_indicate_req_log(const struct ble_att_indicate_req *cmd)
 {
     BLE_HS_LOG(DEBUG, "handle=0x%04x", cmd->baiq_handle);
 }
 
 void
-ble_att_indicate_rsp_parse(void *payload, int len)
+ble_att_indicate_rsp_parse(const void *payload, int len)
 {
     ble_att_init_parse(BLE_ATT_OP_INDICATE_RSP, payload,
                        BLE_ATT_INDICATE_RSP_SZ, len);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/63531557/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 38af5f2..44989a1 100644
--- a/net/nimble/host/src/ble_att_cmd_priv.h
+++ b/net/nimble/host/src/ble_att_cmd_priv.h
@@ -304,103 +304,106 @@ struct ble_att_indicate_req {
  */
 #define BLE_ATT_INDICATE_RSP_SZ         1
 
-void ble_att_error_rsp_parse(void *payload, int len,
-                              struct ble_att_error_rsp *rsp);
+void ble_att_error_rsp_parse(const void *payload, int len,
+                             struct ble_att_error_rsp *rsp);
 void ble_att_error_rsp_write(void *payload, int len,
-                              struct ble_att_error_rsp *rsp);
-void ble_att_error_rsp_log(struct ble_att_error_rsp *cmd);
-void ble_att_mtu_cmd_parse(void *payload, int len,
-                            struct ble_att_mtu_cmd *cmd);
+                             const struct ble_att_error_rsp *rsp);
+void ble_att_error_rsp_log(const struct ble_att_error_rsp *cmd);
+void ble_att_mtu_cmd_parse(const void *payload, int len,
+                           struct ble_att_mtu_cmd *cmd);
 void ble_att_mtu_req_write(void *payload, int len,
-                            struct ble_att_mtu_cmd *cmd);
+                           const struct ble_att_mtu_cmd *cmd);
 void ble_att_mtu_rsp_write(void *payload, int len,
-                           struct ble_att_mtu_cmd *cmd);
-void ble_att_mtu_cmd_log(struct ble_att_mtu_cmd *cmd);
-void ble_att_find_info_req_parse(void *payload, int len,
+                           const struct ble_att_mtu_cmd *cmd);
+void ble_att_mtu_cmd_log(const struct ble_att_mtu_cmd *cmd);
+void ble_att_find_info_req_parse(const void *payload, int len,
                                  struct ble_att_find_info_req *req);
 void ble_att_find_info_req_write(void *payload, int len,
-                                 struct ble_att_find_info_req *req);
-void ble_att_find_info_req_log(struct ble_att_find_info_req *cmd);
-void ble_att_find_info_rsp_parse(void *payload, int len,
+                                 const struct ble_att_find_info_req *req);
+void ble_att_find_info_req_log(const struct ble_att_find_info_req *cmd);
+void ble_att_find_info_rsp_parse(const void *payload, int len,
                                  struct ble_att_find_info_rsp *rsp);
 void ble_att_find_info_rsp_write(void *payload, int len,
-                                 struct ble_att_find_info_rsp *rsp);
-void ble_att_find_info_rsp_log(struct ble_att_find_info_rsp *cmd);
-void ble_att_find_type_value_req_parse(void *payload, int len,
-                                       struct ble_att_find_type_value_req *req);
-void ble_att_find_type_value_req_write(void *payload, int len,
-                                       struct ble_att_find_type_value_req *req);
-void ble_att_find_type_value_req_log(struct ble_att_find_type_value_req *cmd);
-void ble_att_read_type_req_parse(void *payload, int len,
+                                 const struct ble_att_find_info_rsp *rsp);
+void ble_att_find_info_rsp_log(const struct ble_att_find_info_rsp *cmd);
+void ble_att_find_type_value_req_parse(
+    const void *payload, int len, struct ble_att_find_type_value_req *req);
+void ble_att_find_type_value_req_write(
+    void *payload, int len, const struct ble_att_find_type_value_req *req);
+void ble_att_find_type_value_req_log(
+    const struct ble_att_find_type_value_req *cmd);
+void ble_att_read_type_req_parse(const void *payload, int len,
                                  struct ble_att_read_type_req *req);
 void ble_att_read_type_req_write(void *payload, int len,
-                                 struct ble_att_read_type_req *req);
-void ble_att_read_type_req_log(struct ble_att_read_type_req *cmd);
-void ble_att_read_type_rsp_parse(void *payload, int len,
+                                 const struct ble_att_read_type_req *req);
+void ble_att_read_type_req_log(const struct ble_att_read_type_req *cmd);
+void ble_att_read_type_rsp_parse(const void *payload, int len,
                                  struct ble_att_read_type_rsp *rsp);
 void ble_att_read_type_rsp_write(void *payload, int len,
-                                 struct ble_att_read_type_rsp *rsp);
-void ble_att_read_type_rsp_log(struct ble_att_read_type_rsp *cmd);
-void ble_att_read_req_parse(void *payload, int len,
+                                 const struct ble_att_read_type_rsp *rsp);
+void ble_att_read_type_rsp_log(const struct ble_att_read_type_rsp *cmd);
+void ble_att_read_req_parse(const void *payload, int len,
                             struct ble_att_read_req *req);
 void ble_att_read_req_write(void *payload, int len,
-                            struct ble_att_read_req *req);
-void ble_att_read_req_log(struct ble_att_read_req *cmd);
-void ble_att_read_blob_req_parse(void *payload, int len,
+                            const struct ble_att_read_req *req);
+void ble_att_read_req_log(const struct ble_att_read_req *cmd);
+void ble_att_read_blob_req_parse(const void *payload, int len,
                                  struct ble_att_read_blob_req *req);
 void ble_att_read_blob_req_write(void *payload, int len,
-                                 struct ble_att_read_blob_req *req);
-void ble_att_read_blob_req_log(struct ble_att_read_blob_req *cmd);
-void ble_att_read_mult_req_parse(void *payload, int len);
+                                 const struct ble_att_read_blob_req *req);
+void ble_att_read_blob_req_log(const struct ble_att_read_blob_req *cmd);
+void ble_att_read_mult_req_parse(const void *payload, int len);
 void ble_att_read_mult_req_write(void *payload, int len);
-void ble_att_read_mult_rsp_parse(void *payload, int len);
+void ble_att_read_mult_rsp_parse(const void *payload, int len);
 void ble_att_read_mult_rsp_write(void *payload, int len);
 void ble_att_read_group_type_req_parse(
-    void *payload, int len, struct ble_att_read_group_type_req *req);
+    const void *payload, int len, struct ble_att_read_group_type_req *req);
 void ble_att_read_group_type_req_write(
-    void *payload, int len, struct ble_att_read_group_type_req *req);
-void ble_att_read_group_type_req_log(struct ble_att_read_group_type_req *cmd);
+    void *payload, int len, const struct ble_att_read_group_type_req *req);
+void ble_att_read_group_type_req_log(
+    const struct ble_att_read_group_type_req *cmd);
 void ble_att_read_group_type_rsp_parse(
-    void *payload, int len, struct ble_att_read_group_type_rsp *rsp);
+    const void *payload, int len, struct ble_att_read_group_type_rsp *rsp);
 void ble_att_read_group_type_rsp_write(
-    void *payload, int len, struct ble_att_read_group_type_rsp *rsp);
-void ble_att_read_group_type_rsp_log(struct ble_att_read_group_type_rsp *cmd);
-void ble_att_write_req_parse(void *payload, int len,
+    void *payload, int len, const struct ble_att_read_group_type_rsp *rsp);
+void ble_att_read_group_type_rsp_log(
+    const struct ble_att_read_group_type_rsp *cmd);
+void ble_att_write_req_parse(const void *payload, int len,
                              struct ble_att_write_req *req);
 void ble_att_write_req_write(void *payload, int len,
-                             struct ble_att_write_req *req);
-void ble_att_write_cmd_parse(void *payload, int len,
+                             const struct ble_att_write_req *req);
+void ble_att_write_cmd_parse(const void *payload, int len,
                              struct ble_att_write_req *req);
 void ble_att_write_cmd_write(void *payload, int len,
-                             struct ble_att_write_req *req);
-void ble_att_write_cmd_log(struct ble_att_write_req *cmd);
-void ble_att_prep_write_req_parse(void *payload, int len,
+                             const struct ble_att_write_req *req);
+void ble_att_write_cmd_log(const struct ble_att_write_req *cmd);
+void ble_att_prep_write_req_parse(const void *payload, int len,
                                   struct ble_att_prep_write_cmd *cmd);
 void ble_att_prep_write_req_write(void *payload, int len,
-                                  struct ble_att_prep_write_cmd *cmd);
-void ble_att_prep_write_cmd_log(struct ble_att_prep_write_cmd *cmd);
-void ble_att_prep_write_rsp_parse(void *payload, int len,
+                                  const struct ble_att_prep_write_cmd *cmd);
+void ble_att_prep_write_cmd_log(const struct ble_att_prep_write_cmd *cmd);
+void ble_att_prep_write_rsp_parse(const void *payload, int len,
                                   struct ble_att_prep_write_cmd *cmd);
 void ble_att_prep_write_rsp_write(void *payload, int len,
-                                  struct ble_att_prep_write_cmd *cmd);
-void ble_att_exec_write_req_parse(void *payload, int len,
+                                  const struct ble_att_prep_write_cmd *cmd);
+void ble_att_exec_write_req_parse(const void *payload, int len,
                                   struct ble_att_exec_write_req *req);
-void ble_att_exec_write_req_log(struct ble_att_exec_write_req *cmd);
+void ble_att_exec_write_req_log(const struct ble_att_exec_write_req *cmd);
 void ble_att_exec_write_req_write(void *payload, int len,
-                                  struct ble_att_exec_write_req *req);
-void ble_att_exec_write_rsp_parse(void *payload, int len);
+                                  const struct ble_att_exec_write_req *req);
+void ble_att_exec_write_rsp_parse(const void *payload, int len);
 void ble_att_exec_write_rsp_write(void *payload, int len);
-void ble_att_notify_req_parse(void *payload, int len,
+void ble_att_notify_req_parse(const void *payload, int len,
                               struct ble_att_notify_req *req);
 void ble_att_notify_req_write(void *payload, int len,
-                              struct ble_att_notify_req *req);
-void ble_att_notify_req_log(struct ble_att_notify_req *cmd);
-void ble_att_indicate_req_parse(void *payload, int len,
+                              const struct ble_att_notify_req *req);
+void ble_att_notify_req_log(const struct ble_att_notify_req *cmd);
+void ble_att_indicate_req_parse(const void *payload, int len,
                                 struct ble_att_indicate_req *req);
 void ble_att_indicate_req_write(void *payload, int len,
-                                struct ble_att_indicate_req *req);
-void ble_att_indicate_rsp_parse(void *payload, int len);
+                                const struct ble_att_indicate_req *req);
+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(struct ble_att_indicate_req *cmd);
+void ble_att_indicate_req_log(const struct ble_att_indicate_req *cmd);
 
 #endif


[46/50] [abbrv] incubator-mynewt-core git commit: BLE Host - Fix for spurious gcc warning.

Posted by cc...@apache.org.
BLE Host - Fix for spurious gcc warning.


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

Branch: refs/heads/ble_hs_api
Commit: 77b9d5ea0f75a77e9275d68a06aa9d710fe1560b
Parents: 3714aea
Author: Christopher Collins <cc...@apache.org>
Authored: Sat Jul 9 13:23:58 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Jul 11 16:43:35 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/src/host_hci.c | 62 ++++++++++++++++++++++---------------
 1 file changed, 37 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/77b9d5ea/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 b7b1bd1..5251231 100644
--- a/net/nimble/host/src/host_hci.c
+++ b/net/nimble/host/src/host_hci.c
@@ -698,47 +698,59 @@ host_hci_data_rx(struct os_mbuf *om)
     int rc;
 
     rc = ble_hci_util_data_hdr_strip(om, &hci_hdr);
-    if (rc == 0) {
+    if (rc != 0) {
+        goto err;
+    }
+
 #if (BLETEST_THROUGHPUT_TEST == 0)
-        BLE_HS_LOG(DEBUG, "host_hci_data_rx(): handle=%u pb=%x len=%u data=",
-                   BLE_HCI_DATA_HANDLE(hci_hdr.hdh_handle_pb_bc), 
-                   BLE_HCI_DATA_PB(hci_hdr.hdh_handle_pb_bc), 
-                   hci_hdr.hdh_len);
-        ble_hs_misc_log_mbuf(om);
-        BLE_HS_LOG(DEBUG, "\n");
+    BLE_HS_LOG(DEBUG, "host_hci_data_rx(): handle=%u pb=%x len=%u data=",
+               BLE_HCI_DATA_HANDLE(hci_hdr.hdh_handle_pb_bc), 
+               BLE_HCI_DATA_PB(hci_hdr.hdh_handle_pb_bc), 
+               hci_hdr.hdh_len);
+    ble_hs_misc_log_mbuf(om);
+    BLE_HS_LOG(DEBUG, "\n");
 #endif
 
-        if (hci_hdr.hdh_len != OS_MBUF_PKTHDR(om)->omp_len) {
-            rc = BLE_HS_EBADDATA;
-        } else {
-            handle = BLE_HCI_DATA_HANDLE(hci_hdr.hdh_handle_pb_bc);
+    if (hci_hdr.hdh_len != OS_MBUF_PKTHDR(om)->omp_len) {
+        rc = BLE_HS_EBADDATA;
+        goto err;
+    }
 
-            ble_hs_lock();
+    handle = BLE_HCI_DATA_HANDLE(hci_hdr.hdh_handle_pb_bc);
 
-            conn = ble_hs_conn_find(handle);
-            if (conn == NULL) {
-                rc = BLE_HS_ENOTCONN;
-            } else {
-                rc = ble_l2cap_rx(conn, &hci_hdr, om, &rx_cb, &rx_buf);
-                om = NULL;
-            }
+    ble_hs_lock();
 
-            ble_hs_unlock();
-        }
+    conn = ble_hs_conn_find(handle);
+    if (conn == NULL) {
+        rc = BLE_HS_ENOTCONN;
+    } else {
+        rc = ble_l2cap_rx(conn, &hci_hdr, om, &rx_cb, &rx_buf);
+        om = NULL;
     }
 
-    os_mbuf_free_chain(om);
+    ble_hs_unlock();
 
-    if (rc == 0) {
+    switch (rc) {
+    case 0:
+        /* Final fragment received. */
         BLE_HS_DBG_ASSERT(rx_cb != NULL);
         BLE_HS_DBG_ASSERT(rx_buf != NULL);
         rc = rx_cb(handle, &rx_buf);
         os_mbuf_free_chain(rx_buf);
-    } else if (rc == BLE_HS_EAGAIN) {
+        break;
+
+    case BLE_HS_EAGAIN:
         /* More fragments on the way. */
-        rc = 0;
+        break;
+
+    default:
+        goto err;
     }
 
+    return 0;
+
+err:
+    os_mbuf_free_chain(om);
     return rc;
 }
 


[12/50] [abbrv] incubator-mynewt-core git commit: BLE Host - Add duration parameter for advertising.

Posted by cc...@apache.org.
BLE Host - Add duration parameter for advertising.


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

Branch: refs/heads/ble_hs_api
Commit: b92ddcd89af37036765a362e429a566f5d4c22b1
Parents: 3ebfc4b
Author: Christopher Collins <cc...@apache.org>
Authored: Thu Jun 23 16:04:42 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Jul 11 16:43:31 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/include/host/ble_gap.h      |   2 +-
 net/nimble/host/include/host/ble_hs.h       |   2 +
 net/nimble/host/src/ble_gap.c               | 239 +++++++++++++++++------
 net/nimble/host/src/ble_gap_priv.h          |   2 +-
 net/nimble/host/src/ble_gatt_priv.h         |   2 +-
 net/nimble/host/src/ble_gattc.c             |   4 +-
 net/nimble/host/src/ble_hs.c                |  43 ++--
 net/nimble/host/src/ble_hs_priv.h           |   1 +
 net/nimble/host/src/ble_l2cap_sig.c         |   4 +-
 net/nimble/host/src/ble_l2cap_sig_priv.h    |   2 +-
 net/nimble/host/src/ble_sm.c                |   4 +-
 net/nimble/host/src/ble_sm_priv.h           |   4 +-
 net/nimble/host/src/test/ble_hs_test_util.c |   2 +-
 13 files changed, 225 insertions(+), 86 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b92ddcd8/net/nimble/host/include/host/ble_gap.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/ble_gap.h b/net/nimble/host/include/host/ble_gap.h
index 953cfd8..6d3dd2a 100644
--- a/net/nimble/host/include/host/ble_gap.h
+++ b/net/nimble/host/include/host/ble_gap.h
@@ -263,7 +263,7 @@ struct ble_gap_white_entry {
 int ble_gap_find_conn(uint16_t handle, struct ble_gap_conn_desc *out_desc);
 
 int ble_gap_adv_start(uint8_t own_addr_type, uint8_t peer_addr_type,
-                      const uint8_t *peer_addr,
+                      const uint8_t *peer_addr, int32_t duration_ms,
                       const struct ble_gap_adv_params *adv_params,
                       ble_gap_event_fn *cb, void *cb_arg);
 int ble_gap_adv_stop(void);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b92ddcd8/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 e493723..7786b9a 100644
--- a/net/nimble/host/include/host/ble_hs.h
+++ b/net/nimble/host/include/host/ble_hs.h
@@ -32,6 +32,8 @@
 struct os_eventq;
 struct os_event;
 
+#define BLE_HS_FOREVER              INT32_MAX
+
 #define BLE_HS_CONN_HANDLE_NONE     0xffff
 
 #define BLE_HS_EAGAIN               1

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b92ddcd8/net/nimble/host/src/ble_gap.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gap.c b/net/nimble/host/src/ble_gap.c
index b187d77..6fc401a 100644
--- a/net/nimble/host/src/ble_gap.c
+++ b/net/nimble/host/src/ble_gap.c
@@ -117,6 +117,9 @@ static bssnz_t struct {
 static bssnz_t struct {
     uint8_t op;
 
+    unsigned exp_set:1;
+    os_time_t exp_os_ticks;
+
     uint8_t conn_mode;
     uint8_t disc_mode;
     unsigned our_addr_type:2;
@@ -132,6 +135,7 @@ static bssnz_t struct {
 } ble_gap_slave;
 
 static int ble_gap_disc_tx_disable(void);
+static int ble_gap_adv_disable_tx(void);
 
 struct ble_gap_snapshot {
     struct ble_gap_conn_desc desc;
@@ -375,19 +379,45 @@ ble_gap_call_event_cb(int event, struct ble_gap_conn_ctxt *ctxt,
 }
 
 static void
+ble_gap_master_reset_state(void)
+{
+    ble_gap_master.op = BLE_GAP_OP_NULL;
+    ble_gap_master.exp_set = 0;
+}
+
+static void
+ble_gap_slave_reset_state(void)
+{
+    ble_gap_slave.op = BLE_GAP_OP_NULL;
+    ble_gap_slave.exp_set = 0;
+}
+
+static void
+ble_gap_master_extract_cb(ble_gap_event_fn **out_cb, void **out_cb_arg)
+{
+    ble_hs_lock();
+
+    *out_cb = ble_gap_master.conn.cb;
+    *out_cb_arg = ble_gap_master.conn.cb_arg;
+    ble_gap_master_reset_state();
+
+    ble_hs_unlock();
+}
+
+static void
 ble_gap_slave_extract_cb(ble_gap_event_fn **out_cb, void **out_cb_arg)
 {
     ble_hs_lock();
 
     *out_cb = ble_gap_slave.cb;
     *out_cb_arg = ble_gap_slave.cb_arg;
-    ble_gap_slave.op = BLE_GAP_OP_NULL;
+    ble_gap_slave_reset_state();
 
     ble_hs_unlock();
 }
 
 static void
-ble_gap_adv_finished(int event)
+ble_gap_adv_finished(void)
 {
     struct ble_gap_conn_ctxt ctxt;
     struct ble_gap_conn_desc desc;
@@ -400,29 +430,10 @@ ble_gap_adv_finished(int event)
         desc.conn_handle = BLE_HS_CONN_HANDLE_NONE;
         ctxt.desc = &desc;
 
-        cb(event, &ctxt, cb_arg);
+        cb(BLE_GAP_EVENT_ADV_COMPLETE, &ctxt, cb_arg);
     }
 }
 
-static void
-ble_gap_master_reset_state(void)
-{
-    ble_gap_master.op = BLE_GAP_OP_NULL;
-    ble_gap_master.exp_set = 0;
-}
-
-static void
-ble_gap_master_extract_cb(ble_gap_event_fn **out_cb, void **out_cb_arg)
-{
-    ble_hs_lock();
-
-    *out_cb = ble_gap_master.conn.cb;
-    *out_cb_arg = ble_gap_master.conn.cb_arg;
-    ble_gap_master_reset_state();
-
-    ble_hs_unlock();
-}
-
 static int
 ble_gap_master_connect_failure(int status)
 {
@@ -528,11 +539,76 @@ ble_gap_update_notify(uint16_t conn_handle, int status)
                           snap.cb, snap.cb_arg);
 }
 
+static uint32_t
+ble_gap_master_ticks_until_exp(void)
+{
+    int32_t ticks;
+
+    if (ble_gap_master.op == BLE_GAP_OP_NULL || !ble_gap_master.exp_set) {
+        /* Timer not set; infinity ticks until next event. */
+        return BLE_HS_FOREVER;
+    }
+
+    ticks = ble_gap_master.exp_os_ticks - os_time_get();
+    if (ticks > 0) {
+        /* Timer not expired yet. */
+        return ticks;
+    }
+
+    /* Timer just expired. */
+    return 0;
+}
+
+static uint32_t
+ble_gap_slave_ticks_until_exp(void)
+{
+    int32_t ticks;
+
+    if (ble_gap_slave.op == BLE_GAP_OP_NULL || !ble_gap_slave.exp_set) {
+        /* Timer not set; infinity ticks until next event. */
+        return BLE_HS_FOREVER;
+    }
+
+    ticks = ble_gap_slave.exp_os_ticks - os_time_get();
+    if (ticks > 0) {
+        /* Timer not expired yet. */
+        return ticks;
+    }
+
+    /* Timer just expired. */
+    return 0;
+}
+
+static void
+ble_gap_heartbeat_sched(void)
+{
+    int32_t mst_ticks;
+    int32_t slv_ticks;
+    int32_t ticks;
+
+    mst_ticks = ble_gap_master_ticks_until_exp();
+    slv_ticks = ble_gap_slave_ticks_until_exp();
+    ticks = min(mst_ticks, slv_ticks);
+
+    ble_hs_heartbeat_sched(ticks);
+}
+
 static void
 ble_gap_master_set_timer(uint32_t ticks_from_now)
 {
     ble_gap_master.exp_os_ticks = os_time_get() + ticks_from_now;
     ble_gap_master.exp_set = 1;
+
+    ble_gap_heartbeat_sched();
+}
+
+static void
+ble_gap_slave_set_timer(uint32_t ticks_from_now)
+{
+    ble_gap_slave.exp_os_ticks = os_time_get() + ticks_from_now;
+    ble_gap_slave.exp_set = 1;
+
+    ble_gap_heartbeat_sched();
 }
 
 /**
@@ -574,7 +650,7 @@ ble_gap_conn_broken(struct ble_gap_snapshot *snap, int reason)
     struct ble_gap_conn_ctxt ctxt;
 
     /* XXX: Consider removing the connection from the list and handing it to
-     * each fo the "connection_broken" functions below.
+     * each of the "connection_broken" functions below.
      */
 
     ble_sm_connection_broken(snap->desc.conn_handle);
@@ -852,7 +928,7 @@ ble_gap_rx_conn_complete(struct hci_le_conn_complete *evt)
         switch (evt->status) {
         case BLE_ERR_DIR_ADV_TMO:
             if (ble_gap_slave_in_progress()) {
-                ble_gap_adv_finished(BLE_GAP_EVENT_ADV_COMPLETE);
+                ble_gap_adv_finished();
             }
             break;
 
@@ -913,7 +989,7 @@ ble_gap_rx_conn_complete(struct hci_le_conn_complete *evt)
         conn->bhc_cb = ble_gap_slave.cb;
         conn->bhc_cb_arg = ble_gap_slave.cb_arg;
         conn->our_addr_type = ble_gap_slave.our_addr_type;
-        ble_gap_slave.op = BLE_GAP_OP_NULL;
+        ble_gap_slave_reset_state();
     }
 
     memcpy(conn->our_rpa_addr, evt->local_rpa, 6);
@@ -956,36 +1032,8 @@ ble_gap_rx_l2cap_update_req(uint16_t conn_handle,
     return rc;
 }
 
-static uint32_t
-ble_gap_master_ticks_until_exp(void)
-{
-    int32_t ticks;
-
-    if (ble_gap_master.op == BLE_GAP_OP_NULL || !ble_gap_master.exp_set) {
-        /* Timer not set; infinity ticks until next event. */
-        return UINT32_MAX;
-    }
-
-    ticks = ble_gap_master.exp_os_ticks - os_time_get();
-    if (ticks > 0) {
-        /* Timer not expired yet. */
-        return ticks;
-    }
-
-    /* Timer just expired. */
-    return 0;
-}
-
-/**
- * Handles timed-out master procedures.
- *
- * Called by the heartbeat timer; executed at least once a second.
- *
- * @return                      The number of ticks until this function should
- *                                  be called again.
- */
-uint32_t
-ble_gap_heartbeat(void)
+static int32_t
+ble_gap_master_heartbeat(void)
 {
     uint32_t ticks_until_exp;
     int rc;
@@ -998,13 +1046,15 @@ ble_gap_heartbeat(void)
 
     /*** Timer expired; process event. */
 
-    /* Clear the timer. */
-    ble_gap_master.exp_set = 0;
-
     switch (ble_gap_master.op) {
     case BLE_GAP_OP_M_DISC:
         /* When a discovery procedure times out, it is not a failure. */
         rc = ble_gap_disc_tx_disable();
+        if (rc != 0) {
+            /* Failed to stop discovery; try again in 100 ms. */
+            return 100;
+        }
+
         ble_gap_call_master_disc_cb(BLE_GAP_EVENT_DISC_COMPLETE, rc,
                                     NULL, NULL, 1);
         break;
@@ -1014,7 +1064,60 @@ ble_gap_heartbeat(void)
         break;
     }
 
-    return UINT32_MAX;
+    /* Clear the timer and cancel the current procedure. */
+    ble_gap_master_reset_state();
+
+    return BLE_HS_FOREVER;
+}
+
+static int32_t
+ble_gap_slave_heartbeat(void)
+{
+    uint32_t ticks_until_exp;
+    int rc;
+
+    ticks_until_exp = ble_gap_slave_ticks_until_exp();
+    if (ticks_until_exp != 0) {
+        /* Timer not expired yet. */
+        return ticks_until_exp;
+    }
+
+    /*** Timer expired; process event. */
+
+    /* Stop advertising. */
+    rc = ble_gap_adv_disable_tx();
+    if (rc != 0) {
+        /* Failed to stop advertising; try again in 100 ms. */
+        return 100;
+    }
+
+    /* Clear the timer and cancel the current procedure. */
+    ble_gap_slave_reset_state();
+
+    /* Indicate to application that advertising has stopped. */
+    ble_gap_adv_finished();
+
+    return BLE_HS_FOREVER;
+}
+
+/**
+ * Handles timed-out master procedures.
+ *
+ * Called by the heartbeat timer; executed at least once a second.
+ *
+ * @return                      The number of ticks until this function should
+ *                                  be called again.
+ */
+int32_t
+ble_gap_heartbeat(void)
+{
+    int32_t master_ticks;
+    int32_t slave_ticks;
+
+    master_ticks = ble_gap_master_heartbeat();
+    slave_ticks = ble_gap_slave_heartbeat();
+
+    return min(master_ticks, slave_ticks);
 }
 
 /*****************************************************************************
@@ -1168,7 +1271,7 @@ ble_gap_adv_stop(void)
         goto err;
     }
 
-    ble_gap_slave.op = BLE_GAP_OP_NULL;
+    ble_gap_slave_reset_state();
 
     return 0;
 
@@ -1467,7 +1570,7 @@ ble_gap_adv_validate(uint8_t own_addr_type, uint8_t peer_addr_type,
  */
 int
 ble_gap_adv_start(uint8_t own_addr_type, uint8_t peer_addr_type,
-                  const uint8_t *peer_addr,
+                  const uint8_t *peer_addr, int32_t duration_ms,
                   const struct ble_gap_adv_params *adv_params,
                   ble_gap_event_fn *cb, void *cb_arg)
 {
@@ -1475,6 +1578,7 @@ ble_gap_adv_start(uint8_t own_addr_type, uint8_t peer_addr_type,
     return BLE_HS_ENOTSUP;
 #endif
 
+    uint32_t duration_ticks;
     int rc;
 
     ble_hs_lock();
@@ -1487,6 +1591,15 @@ ble_gap_adv_start(uint8_t own_addr_type, uint8_t peer_addr_type,
         goto done;
     }
 
+    if (duration_ms != BLE_HS_FOREVER) {
+        rc = os_time_ms_to_ticks(duration_ms, &duration_ticks);
+        if (rc != 0) {
+            /* Duration too great. */
+            rc = BLE_HS_EINVAL;
+            goto done;
+        }
+    }
+
     if (own_addr_type == BLE_HCI_ADV_OWN_ADDR_RANDOM) {
         ble_hs_pvcy_set_our_nrpa();
     }
@@ -1524,6 +1637,10 @@ ble_gap_adv_start(uint8_t own_addr_type, uint8_t peer_addr_type,
         goto done;
     }
 
+    if (duration_ms != BLE_HS_FOREVER) {
+        ble_gap_slave_set_timer(duration_ticks);
+    }
+
     ble_gap_slave.op = BLE_GAP_OP_S_ADV;
     rc = 0;
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b92ddcd8/net/nimble/host/src/ble_gap_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gap_priv.h b/net/nimble/host/src/ble_gap_priv.h
index 547dffb..f0f3135 100644
--- a/net/nimble/host/src/ble_gap_priv.h
+++ b/net/nimble/host/src/ble_gap_priv.h
@@ -86,7 +86,7 @@ void ble_gap_notify_event(uint16_t conn_handle, uint16_t attr_handle,
 int ble_gap_master_in_progress(void);
 int ble_gap_slave_in_progress(void);
 
-uint32_t ble_gap_heartbeat(void);
+int32_t ble_gap_heartbeat(void);
 
 int ble_gap_init(void);
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b92ddcd8/net/nimble/host/src/ble_gatt_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gatt_priv.h b/net/nimble/host/src/ble_gatt_priv.h
index 5955b91..2358994 100644
--- a/net/nimble/host/src/ble_gatt_priv.h
+++ b/net/nimble/host/src/ble_gatt_priv.h
@@ -130,7 +130,7 @@ void ble_gattc_rx_find_info_idata(uint16_t conn_handle,
 void ble_gattc_rx_find_info_complete(uint16_t conn_handle, int status);
 void ble_gattc_connection_txable(uint16_t conn_handle);
 void ble_gattc_connection_broken(uint16_t conn_handle);
-uint32_t ble_gattc_heartbeat(void);
+int32_t ble_gattc_heartbeat(void);
 
 int ble_gattc_any_jobs(void);
 int ble_gattc_init(void);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b92ddcd8/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 29e6b4e..4741959 100644
--- a/net/nimble/host/src/ble_gattc.c
+++ b/net/nimble/host/src/ble_gattc.c
@@ -854,7 +854,7 @@ ble_gattc_extract_with_rx_entry(uint16_t conn_handle,
  *                                  be called again; currently always
  *                                  UINT32_MAX.
  */
-uint32_t
+int32_t
 ble_gattc_heartbeat(void)
 {
     struct ble_gattc_proc_list exp_list;
@@ -875,7 +875,7 @@ ble_gattc_heartbeat(void)
         ble_gattc_proc_free(proc);
     }
 
-    return UINT32_MAX;
+    return BLE_HS_FOREVER;
 }
 
 /**

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b92ddcd8/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 37e4549..e78b5aa 100644
--- a/net/nimble/host/src/ble_hs.c
+++ b/net/nimble/host/src/ble_hs.c
@@ -180,6 +180,23 @@ ble_hs_heartbeat_timer_reset(uint32_t ticks)
     BLE_HS_DBG_ASSERT_EVAL(rc == 0);
 }
 
+void
+ble_hs_heartbeat_sched(int32_t ticks_from_now)
+{
+    if (ticks_from_now == BLE_HS_FOREVER) {
+        return;
+    }
+
+    /* Reset heartbeat timer if it is not currently scheduled or if the
+     * specified time is sooner than the current expiration time.
+     */
+    if (!os_callout_queued(&ble_hs_heartbeat_timer.cf_c) ||
+        OS_TIME_TICK_LT(ticks_from_now, ble_hs_heartbeat_timer.cf_c.c_ticks)) {
+
+        ble_hs_heartbeat_timer_reset(ticks_from_now);
+    }
+}
+
 /**
  * Called once a second by the ble_hs heartbeat timer.  Handles unresponsive
  * timeouts and periodic retries in case of resource shortage.
@@ -187,24 +204,26 @@ ble_hs_heartbeat_timer_reset(uint32_t ticks)
 static void
 ble_hs_heartbeat(void *unused)
 {
-    uint32_t lcl_ticks_until_next;
-    uint32_t ticks_until_next;
+    int32_t ticks_until_next;
 
+    /* Ensure the timer expires at least once in the next second.
+     * XXX: This is not very power efficient.  We will need separate timers for
+     * each module.
+     */
     ticks_until_next = BLE_HS_HEARTBEAT_OS_TICKS;
+    ble_hs_heartbeat_sched(ticks_until_next);
 
-    lcl_ticks_until_next = ble_gattc_heartbeat();
-    ticks_until_next = min(ticks_until_next, lcl_ticks_until_next);
-
-    lcl_ticks_until_next = ble_gap_heartbeat();
-    ticks_until_next = min(ticks_until_next, lcl_ticks_until_next);
+    ticks_until_next = ble_gattc_heartbeat();
+    ble_hs_heartbeat_sched(ticks_until_next);
 
-    lcl_ticks_until_next = ble_l2cap_sig_heartbeat();
-    ticks_until_next = min(ticks_until_next, lcl_ticks_until_next);
+    ticks_until_next = ble_gap_heartbeat();
+    ble_hs_heartbeat_sched(ticks_until_next);
 
-    lcl_ticks_until_next = ble_sm_heartbeat();
-    ticks_until_next = min(ticks_until_next, lcl_ticks_until_next);
+    ticks_until_next = ble_l2cap_sig_heartbeat();
+    ble_hs_heartbeat_sched(ticks_until_next);
 
-    ble_hs_heartbeat_timer_reset(ticks_until_next);
+    ticks_until_next = ble_sm_heartbeat();
+    ble_hs_heartbeat_sched(ticks_until_next);
 }
 
 static void

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b92ddcd8/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 b902473..8c0b47f 100644
--- a/net/nimble/host/src/ble_hs_priv.h
+++ b/net/nimble/host/src/ble_hs_priv.h
@@ -92,6 +92,7 @@ int ble_hs_locked_by_cur_task(void);
 int ble_hs_is_parent_task(void);
 void ble_hs_lock(void);
 void ble_hs_unlock(void);
+void ble_hs_heartbeat_sched(int32_t ticks);
 
 struct os_mbuf *ble_hs_misc_pkthdr(void);
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b92ddcd8/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 93ba2e2..9630a15 100644
--- a/net/nimble/host/src/ble_l2cap_sig.c
+++ b/net/nimble/host/src/ble_l2cap_sig.c
@@ -582,7 +582,7 @@ ble_l2cap_sig_extract_expired(struct ble_l2cap_sig_proc_list *dst_list)
  *                                  be called again; currently always
  *                                  UINT32_MAX.
  */
-uint32_t
+int32_t
 ble_l2cap_sig_heartbeat(void)
 {
     struct ble_l2cap_sig_proc_list temp_list;
@@ -599,7 +599,7 @@ ble_l2cap_sig_heartbeat(void)
         ble_gap_terminate(proc->conn_handle);
     }
 
-    return UINT32_MAX;
+    return BLE_HS_FOREVER;
 }
 
 int

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b92ddcd8/net/nimble/host/src/ble_l2cap_sig_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_sig_priv.h b/net/nimble/host/src/ble_l2cap_sig_priv.h
index a561a82..3477ee1 100644
--- a/net/nimble/host/src/ble_l2cap_sig_priv.h
+++ b/net/nimble/host/src/ble_l2cap_sig_priv.h
@@ -80,7 +80,7 @@ int ble_l2cap_sig_reject_invalid_cid_tx(struct ble_hs_conn *conn,
                                         uint8_t id,
                                         uint16_t src_cid, uint16_t dst_cid);
 
-uint32_t ble_l2cap_sig_heartbeat(void);
+int32_t ble_l2cap_sig_heartbeat(void);
 struct ble_l2cap_chan *ble_l2cap_sig_create_chan(void);
 int ble_l2cap_sig_init(void);
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b92ddcd8/net/nimble/host/src/ble_sm.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_sm.c b/net/nimble/host/src/ble_sm.c
index ab41173..fbd2c59 100644
--- a/net/nimble/host/src/ble_sm.c
+++ b/net/nimble/host/src/ble_sm.c
@@ -2044,7 +2044,7 @@ ble_sm_fail_rx(uint16_t conn_handle, uint8_t op, struct os_mbuf **om,
  *                                  be called again; currently always
  *                                  UINT32_MAX.
  */
-uint32_t
+int32_t
 ble_sm_heartbeat(void)
 {
     struct ble_sm_proc_list exp_list;
@@ -2067,7 +2067,7 @@ ble_sm_heartbeat(void)
         ble_sm_proc_free(proc);
     }
 
-    return UINT32_MAX;
+    return BLE_HS_FOREVER;
 }
 
 /**

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b92ddcd8/net/nimble/host/src/ble_sm_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_sm_priv.h b/net/nimble/host/src/ble_sm_priv.h
index 2543514..707f589 100644
--- a/net/nimble/host/src/ble_sm_priv.h
+++ b/net/nimble/host/src/ble_sm_priv.h
@@ -452,7 +452,7 @@ int ble_sm_ia_ra(struct ble_sm_proc *proc,
                  uint8_t *out_iat, uint8_t *out_ia,
                  uint8_t *out_rat, uint8_t *out_ra);
 
-uint32_t ble_sm_heartbeat(void);
+int32_t ble_sm_heartbeat(void);
 void ble_sm_connection_broken(uint16_t conn_handle);
 int ble_sm_pair_initiate(uint16_t conn_handle);
 int ble_sm_slave_initiate(uint16_t conn_handle);
@@ -471,7 +471,7 @@ int ble_sm_init(void);
 #define ble_sm_ltk_req_rx(evt) ((void)(evt))
 #define ble_sm_enc_key_refresh_rx(evt) ((void)(evt))
 
-#define ble_sm_heartbeat() UINT32_MAX
+#define ble_sm_heartbeat() BLE_HS_FOREVER
 #define ble_sm_connection_broken(conn_handle)
 #define ble_sm_pair_initiate(conn_handle)   BLE_HS_ENOTSUP
 #define ble_sm_slave_initiate(conn_handle)  BLE_HS_ENOTSUP

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b92ddcd8/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 383386d..30c4b40 100644
--- a/net/nimble/host/src/test/ble_hs_test_util.c
+++ b/net/nimble/host/src/test/ble_hs_test_util.c
@@ -552,7 +552,7 @@ ble_hs_test_util_adv_start(uint8_t own_addr_type,
     ble_hs_test_util_set_ack_seq(acks);
     
     rc = ble_gap_adv_start(own_addr_type, peer_addr_type, peer_addr, 
-                           adv_params, cb, cb_arg);
+                           BLE_HS_FOREVER, adv_params, cb, cb_arg);
 
     return rc;
 }


[24/50] [abbrv] incubator-mynewt-core git commit: BLE Host - Indicate GATT proc done - BLE_HS_EDONE

Posted by cc...@apache.org.
BLE Host - Indicate GATT proc done - BLE_HS_EDONE


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

Branch: refs/heads/ble_hs_api
Commit: 2447ea0e1e24859073babda8094d7547cf5df6e6
Parents: 079aff1
Author: Christopher Collins <cc...@apache.org>
Authored: Wed Jun 29 14:13:54 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Jul 11 16:43:32 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/src/ble_gattc.c                 | 258 +++++++++++--------
 net/nimble/host/src/test/ble_gatt_disc_c_test.c |  16 +-
 net/nimble/host/src/test/ble_gatt_disc_d_test.c |  16 +-
 net/nimble/host/src/test/ble_gatt_disc_s_test.c |  17 +-
 net/nimble/host/src/test/ble_gatt_find_s_test.c |  16 +-
 5 files changed, 204 insertions(+), 119 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2447ea0e/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 9081c80..7ff37aa 100644
--- a/net/nimble/host/src/ble_gattc.c
+++ b/net/nimble/host/src/ble_gattc.c
@@ -889,7 +889,7 @@ ble_gattc_error(int status, uint16_t att_handle)
     static struct ble_gatt_error error;
 
     /* For consistency, always indicate a handle of 0 on success. */
-    if (status == 0) {
+    if (status == 0 || status == BLE_HS_EDONE) {
         att_handle = 0;
     }
 
@@ -918,7 +918,7 @@ ble_gattc_mtu_cb(struct ble_gattc_proc *proc, int status, uint16_t att_handle,
     BLE_HS_DBG_ASSERT(!ble_hs_locked_by_cur_task());
     ble_gattc_dbg_assert_proc_not_inserted(proc);
 
-    if (status != 0) {
+    if (status != 0 && status != BLE_HS_EDONE) {
         STATS_INC(ble_gattc_stats, mtu_fail);
     }
 
@@ -1020,9 +1020,10 @@ ble_gattc_disc_all_svcs_cb(struct ble_gattc_proc *proc,
     int rc;
 
     BLE_HS_DBG_ASSERT(!ble_hs_locked_by_cur_task());
+    BLE_HS_DBG_ASSERT(service != NULL || status != 0);
     ble_gattc_dbg_assert_proc_not_inserted(proc);
 
-    if (status != 0) {
+    if (status != 0 && status != BLE_HS_EDONE) {
         STATS_INC(ble_gattc_stats, disc_all_svcs_fail);
     }
 
@@ -1078,7 +1079,7 @@ ble_gattc_disc_all_svcs_err(struct ble_gattc_proc *proc, int status,
 
     if (status == BLE_HS_ATT_ERR(BLE_ATT_ERR_ATTR_NOT_FOUND)) {
         /* Discovery is complete. */
-        status = 0;
+        status = BLE_HS_EDONE;
     }
 
     ble_gattc_disc_all_svcs_cb(proc, status, att_handle, NULL);
@@ -1150,19 +1151,24 @@ ble_gattc_disc_all_svcs_rx_complete(struct ble_gattc_proc *proc, int status)
 
     ble_gattc_dbg_assert_proc_not_inserted(proc);
 
-    if (status != 0 || proc->disc_all_svcs.prev_handle == 0xffff) {
-        /* Error or all svcs discovered. */
+    if (status != 0) {
         ble_gattc_disc_all_svcs_cb(proc, status, 0, NULL);
         return BLE_HS_EDONE;
-    } else {
-        /* Send follow-up request. */
-        rc = ble_gattc_disc_all_svcs_go(proc, 1);
-        if (rc != 0) {
-            return BLE_HS_EDONE;
-        }
+    }
 
-        return 0;
+    if (proc->disc_all_svcs.prev_handle == 0xffff) {
+        /* Service discovery complete. */
+        ble_gattc_disc_all_svcs_cb(proc, BLE_HS_EDONE, 0, NULL);
+        return BLE_HS_EDONE;
     }
+
+    /* Send follow-up request. */
+    rc = ble_gattc_disc_all_svcs_go(proc, 1);
+    if (rc != 0) {
+        return BLE_HS_EDONE;
+    }
+
+    return 0;
 }
 
 /**
@@ -1234,9 +1240,10 @@ ble_gattc_disc_svc_uuid_cb(struct ble_gattc_proc *proc, int status,
     int rc;
 
     BLE_HS_DBG_ASSERT(!ble_hs_locked_by_cur_task());
+    BLE_HS_DBG_ASSERT(service != NULL || status != 0);
     ble_gattc_dbg_assert_proc_not_inserted(proc);
 
-    if (status != 0) {
+    if (status != 0 && status != BLE_HS_EDONE) {
         STATS_INC(ble_gattc_stats, disc_svc_uuid_fail);
     }
 
@@ -1290,7 +1297,7 @@ ble_gattc_disc_svc_uuid_err(struct ble_gattc_proc *proc, int status,
 
     if (status == BLE_HS_ATT_ERR(BLE_ATT_ERR_ATTR_NOT_FOUND)) {
         /* Discovery is complete. */
-        status = 0;
+        status = BLE_HS_EDONE;
     }
 
     ble_gattc_disc_svc_uuid_cb(proc, status, att_handle, NULL);
@@ -1344,18 +1351,24 @@ ble_gattc_disc_svc_uuid_rx_complete(struct ble_gattc_proc *proc, int status)
 
     ble_gattc_dbg_assert_proc_not_inserted(proc);
 
-    if (status != 0 || proc->disc_svc_uuid.prev_handle == 0xffff) {
-        /* Error or all svcs discovered. */
+    if (status != 0) {
         ble_gattc_disc_svc_uuid_cb(proc, status, 0, NULL);
         return BLE_HS_EDONE;
-    } else {
-        /* Send follow-up request. */
-        rc = ble_gattc_disc_svc_uuid_go(proc, 1);
-        if (rc != 0) {
-            return BLE_HS_EDONE;
-        }
-        return 0;
     }
+
+    if (proc->disc_svc_uuid.prev_handle == 0xffff) {
+        /* Service discovery complete. */
+        ble_gattc_disc_svc_uuid_cb(proc, BLE_HS_EDONE, 0, NULL);
+        return BLE_HS_EDONE;
+    }
+
+    /* Send follow-up request. */
+    rc = ble_gattc_disc_svc_uuid_go(proc, 1);
+    if (rc != 0) {
+        return BLE_HS_EDONE;
+    }
+
+    return 0;
 }
 
 /**
@@ -1429,9 +1442,10 @@ ble_gattc_find_inc_svcs_cb(struct ble_gattc_proc *proc, int status,
     int rc;
 
     BLE_HS_DBG_ASSERT(!ble_hs_locked_by_cur_task());
+    BLE_HS_DBG_ASSERT(service != NULL || status != 0);
     ble_gattc_dbg_assert_proc_not_inserted(proc);
 
-    if (status != 0) {
+    if (status != 0 && status != BLE_HS_EDONE) {
         STATS_INC(ble_gattc_stats, find_inc_svcs_fail);
     }
 
@@ -1500,7 +1514,7 @@ ble_gattc_find_inc_svcs_err(struct ble_gattc_proc *proc, int status,
         status == BLE_HS_ATT_ERR(BLE_ATT_ERR_ATTR_NOT_FOUND)) {
 
         /* Discovery is complete. */
-        status = 0;
+        status = BLE_HS_EDONE;
     }
 
     ble_gattc_find_inc_svcs_cb(proc, status, att_handle, NULL);
@@ -1515,7 +1529,6 @@ ble_gattc_find_inc_svcs_rx_read_rsp(struct ble_gattc_proc *proc, int status,
                                     void *value, int value_len)
 {
     struct ble_gatt_svc service;
-    int cbrc;
     int rc;
 
     ble_gattc_dbg_assert_proc_not_inserted(proc);
@@ -1523,41 +1536,43 @@ ble_gattc_find_inc_svcs_rx_read_rsp(struct ble_gattc_proc *proc, int status,
     if (proc->find_inc_svcs.cur_start == 0) {
         /* Unexpected read response; terminate procedure. */
         rc = BLE_HS_EBADDATA;
-        goto done;
+        goto err;
     }
 
     if (status != 0) {
         rc = status;
-        goto done;
+        goto err;
     }
 
     if (value_len != 16) {
         /* Invalid UUID. */
         rc = BLE_HS_EBADDATA;
-        goto done;
+        goto err;
     }
 
+    /* Report discovered service to application. */
     service.start_handle = proc->find_inc_svcs.cur_start;
     service.end_handle = proc->find_inc_svcs.cur_end;
     memcpy(service.uuid128, value, 16);
+    rc = ble_gattc_find_inc_svcs_cb(proc, 0, 0, &service);
+    if (rc != 0) {
+        /* Application has indicated that the procedure should be aborted. */
+        return BLE_HS_EDONE;
+    }
 
-    /* We are done with this service; proceed to the next. */
+    /* Proceed to the next service. */
     proc->find_inc_svcs.cur_start = 0;
     proc->find_inc_svcs.cur_end = 0;
     rc = ble_gattc_find_inc_svcs_go(proc, 1);
     if (rc != 0) {
-        goto done;
+        goto err;
     }
 
-    rc = 0;
+    return 0;
 
-done:
-    cbrc = ble_gattc_find_inc_svcs_cb(proc, rc, 0, &service);
-    if (rc != 0 || cbrc != 0) {
-        return BLE_HS_EDONE;
-    } else {
-        return 0;
-    }
+err:
+    ble_gattc_find_inc_svcs_cb(proc, rc, 0, NULL);
+    return BLE_HS_EDONE;
 }
 
 /**
@@ -1647,18 +1662,23 @@ ble_gattc_find_inc_svcs_rx_complete(struct ble_gattc_proc *proc, int status)
 
     ble_gattc_dbg_assert_proc_not_inserted(proc);
 
-    if (status != 0 || proc->find_inc_svcs.prev_handle == 0xffff) {
-        /* Error or all svcs discovered. */
+    if (status != 0) {
         ble_gattc_find_inc_svcs_cb(proc, status, 0, NULL);
         return BLE_HS_EDONE;
-    } else {
-        /* Send follow-up request. */
-        rc = ble_gattc_find_inc_svcs_go(proc, 1);
-        if (rc != 0) {
-            return BLE_HS_EDONE;
-        }
-        return 0;
     }
+
+    if (proc->find_inc_svcs.prev_handle == 0xffff) {
+        /* Procedure complete. */
+        ble_gattc_find_inc_svcs_cb(proc, BLE_HS_EDONE, 0, NULL);
+        return BLE_HS_EDONE;
+    }
+
+    /* Send follow-up request. */
+    rc = ble_gattc_find_inc_svcs_go(proc, 1);
+    if (rc != 0) {
+        return BLE_HS_EDONE;
+    }
+    return 0;
 }
 
 /**
@@ -1735,9 +1755,10 @@ ble_gattc_disc_all_chrs_cb(struct ble_gattc_proc *proc, int status,
     int rc;
 
     BLE_HS_DBG_ASSERT(!ble_hs_locked_by_cur_task());
+    BLE_HS_DBG_ASSERT(chr != NULL || status != 0);
     ble_gattc_dbg_assert_proc_not_inserted(proc);
 
-    if (status != 0) {
+    if (status != 0 && status != BLE_HS_EDONE) {
         STATS_INC(ble_gattc_stats, disc_all_chrs_fail);
     }
 
@@ -1795,7 +1816,7 @@ ble_gattc_disc_all_chrs_err(struct ble_gattc_proc *proc, int status,
 
     if (status == BLE_HS_ATT_ERR(BLE_ATT_ERR_ATTR_NOT_FOUND)) {
         /* Discovery is complete. */
-        status = 0;
+        status = BLE_HS_EDONE;
     }
 
     ble_gattc_disc_all_chrs_cb(proc, status, att_handle, NULL);
@@ -1870,20 +1891,23 @@ ble_gattc_disc_all_chrs_rx_complete(struct ble_gattc_proc *proc, int status)
 
     ble_gattc_dbg_assert_proc_not_inserted(proc);
 
-    if (status != 0 ||
-        proc->disc_all_chrs.prev_handle == proc->disc_all_chrs.end_handle) {
-
-        /* Error or all svcs discovered. */
+    if (status != 0) {
         ble_gattc_disc_all_chrs_cb(proc, status, 0, NULL);
         return BLE_HS_EDONE;
-    } else {
-        /* Send follow-up request. */
-        rc = ble_gattc_disc_all_chrs_go(proc, 1);
-        if (rc != 0) {
-            return BLE_HS_EDONE;
-        }
-        return 0;
     }
+
+    if (proc->disc_all_chrs.prev_handle == proc->disc_all_chrs.end_handle) {
+        /* Characteristic discovery complete. */
+        ble_gattc_disc_all_chrs_cb(proc, BLE_HS_EDONE, 0, NULL);
+        return BLE_HS_EDONE;
+    }
+
+    /* Send follow-up request. */
+    rc = ble_gattc_disc_all_chrs_go(proc, 1);
+    if (rc != 0) {
+        return BLE_HS_EDONE;
+    }
+    return 0;
 }
 
 /**
@@ -1960,9 +1984,10 @@ ble_gattc_disc_chr_uuid_cb(struct ble_gattc_proc *proc, int status,
     int rc;
 
     BLE_HS_DBG_ASSERT(!ble_hs_locked_by_cur_task());
+    BLE_HS_DBG_ASSERT(chr != NULL || status != 0);
     ble_gattc_dbg_assert_proc_not_inserted(proc);
 
-    if (status != 0) {
+    if (status != 0 && status != BLE_HS_EDONE) {
         STATS_INC(ble_gattc_stats, disc_chrs_uuid_fail);
     }
 
@@ -2020,7 +2045,7 @@ ble_gattc_disc_chr_uuid_err(struct ble_gattc_proc *proc, int status,
 
     if (status == BLE_HS_ATT_ERR(BLE_ATT_ERR_ATTR_NOT_FOUND)) {
         /* Discovery is complete. */
-        status = 0;
+        status = BLE_HS_EDONE;
     }
 
     ble_gattc_disc_chr_uuid_cb(proc, status, att_handle, NULL);
@@ -2077,11 +2102,14 @@ ble_gattc_disc_chr_uuid_rx_adata(struct ble_gattc_proc *proc,
     rc = 0;
 
 done:
-    if (rc != 0 ||
-        memcmp(chr.uuid128, proc->disc_chr_uuid.chr_uuid, 16) == 0) {
-
-        cbrc = ble_gattc_disc_chr_uuid_cb(proc, rc, 0, &chr);
+    if (rc != 0) {
+        /* Failure. */
+        cbrc = ble_gattc_disc_chr_uuid_cb(proc, rc, 0, NULL);
+    } else if (memcmp(chr.uuid128, proc->disc_chr_uuid.chr_uuid, 16) == 0) {
+        /* Requested characteristic discovered. */
+        cbrc = ble_gattc_disc_chr_uuid_cb(proc, 0, 0, &chr);
     } else {
+        /* Uninteresting characteristic; ignore. */
         cbrc = 0;
     }
 
@@ -2103,20 +2131,23 @@ ble_gattc_disc_chr_uuid_rx_complete(struct ble_gattc_proc *proc, int status)
 
     ble_gattc_dbg_assert_proc_not_inserted(proc);
 
-    if (status != 0 ||
-        proc->disc_chr_uuid.prev_handle == proc->disc_chr_uuid.end_handle) {
-
-        /* Error or all svcs discovered. */
+    if (status != 0) {
         ble_gattc_disc_chr_uuid_cb(proc, status, 0, NULL);
         return BLE_HS_EDONE;
-    } else {
-        /* Send follow-up request. */
-        rc = ble_gattc_disc_chr_uuid_go(proc, 1);
-        if (rc != 0) {
-            return BLE_HS_EDONE;
-        }
-        return 0;
     }
+
+    if (proc->disc_chr_uuid.prev_handle == proc->disc_chr_uuid.end_handle) {
+        /* Characteristic discovery complete. */
+        ble_gattc_disc_chr_uuid_cb(proc, BLE_HS_EDONE, 0, NULL);
+        return BLE_HS_EDONE;
+    }
+
+    /* Send follow-up request. */
+    rc = ble_gattc_disc_chr_uuid_go(proc, 1);
+    if (rc != 0) {
+        return BLE_HS_EDONE;
+    }
+    return 0;
 }
 
 /**
@@ -2196,9 +2227,10 @@ ble_gattc_disc_all_dscs_cb(struct ble_gattc_proc *proc, int status,
     int rc;
 
     BLE_HS_DBG_ASSERT(!ble_hs_locked_by_cur_task());
+    BLE_HS_DBG_ASSERT(dsc != NULL || status != 0);
     ble_gattc_dbg_assert_proc_not_inserted(proc);
 
-    if (status != 0) {
+    if (status != 0 && status != BLE_HS_EDONE) {
         STATS_INC(ble_gattc_stats, disc_all_dscs_fail);
     }
 
@@ -2251,7 +2283,7 @@ ble_gattc_disc_all_dscs_err(struct ble_gattc_proc *proc, int status,
 
     if (status == BLE_HS_ATT_ERR(BLE_ATT_ERR_ATTR_NOT_FOUND)) {
         /* Discovery is complete. */
-        status = 0;
+        status = BLE_HS_EDONE;
     }
 
     ble_gattc_disc_all_dscs_cb(proc, status, att_handle, NULL);
@@ -2303,20 +2335,24 @@ ble_gattc_disc_all_dscs_rx_complete(struct ble_gattc_proc *proc, int status)
 
     ble_gattc_dbg_assert_proc_not_inserted(proc);
 
-    if (status != 0 ||
-        proc->disc_all_dscs.prev_handle == proc->disc_all_dscs.end_handle) {
-
-        /* Error or all descriptors discovered. */
+    if (status != 0) {
         ble_gattc_disc_all_dscs_cb(proc, status, 0, NULL);
         return BLE_HS_EDONE;
-    } else {
-        /* Send follow-up request. */
-        rc = ble_gattc_disc_all_dscs_go(proc, 1);
-        if (rc != 0) {
-            return BLE_HS_EDONE;
-        }
-        return 0;
     }
+
+    if (proc->disc_all_dscs.prev_handle == proc->disc_all_dscs.end_handle) {
+        /* All descriptors discovered. */
+        ble_gattc_disc_all_dscs_cb(proc, BLE_HS_EDONE, 0, NULL);
+        return BLE_HS_EDONE;
+    }
+
+    /* Send follow-up request. */
+    rc = ble_gattc_disc_all_dscs_go(proc, 1);
+    if (rc != 0) {
+        return BLE_HS_EDONE;
+    }
+
+    return 0;
 }
 
 /**
@@ -2394,9 +2430,10 @@ ble_gattc_read_cb(struct ble_gattc_proc *proc, int status,
     int rc;
 
     BLE_HS_DBG_ASSERT(!ble_hs_locked_by_cur_task());
+    BLE_HS_DBG_ASSERT(attr != NULL || status != 0);
     ble_gattc_dbg_assert_proc_not_inserted(proc);
 
-    if (status != 0) {
+    if (status != 0 && status != BLE_HS_EDONE) {
         STATS_INC(ble_gattc_stats, read_fail);
     }
 
@@ -2517,9 +2554,10 @@ ble_gattc_read_uuid_cb(struct ble_gattc_proc *proc, int status,
     int rc;
 
     BLE_HS_DBG_ASSERT(!ble_hs_locked_by_cur_task());
+    BLE_HS_DBG_ASSERT(attr != NULL || status != 0);
     ble_gattc_dbg_assert_proc_not_inserted(proc);
 
-    if (status != 0) {
+    if (status != 0 && status != BLE_HS_EDONE) {
         STATS_INC(ble_gattc_stats, read_uuid_fail);
     }
 
@@ -2585,7 +2623,16 @@ static int
 ble_gattc_read_uuid_rx_complete(struct ble_gattc_proc *proc, int status)
 {
     ble_gattc_dbg_assert_proc_not_inserted(proc);
-    ble_gattc_read_uuid_cb(proc, status, 0, NULL);
+
+    if (status != 0) {
+        ble_gattc_read_uuid_cb(proc, status, 0, NULL);
+        return BLE_HS_EDONE;
+    }
+
+    /* XXX: We may need to send a follow-up request to address the possibility
+     * of multiple characteristics with identical UUIDs.
+     */
+    ble_gattc_read_uuid_cb(proc, BLE_HS_EDONE, 0, NULL);
     return BLE_HS_EDONE;
 }
 
@@ -2664,9 +2711,10 @@ ble_gattc_read_long_cb(struct ble_gattc_proc *proc, int status,
     int rc;
 
     BLE_HS_DBG_ASSERT(!ble_hs_locked_by_cur_task());
+    BLE_HS_DBG_ASSERT(attr != NULL || status != 0);
     ble_gattc_dbg_assert_proc_not_inserted(proc);
 
-    if (status != 0) {
+    if (status != 0 && status != BLE_HS_EDONE) {
         STATS_INC(ble_gattc_stats, read_long_fail);
     }
 
@@ -2757,7 +2805,8 @@ ble_gattc_read_long_rx_read_rsp(struct ble_gattc_proc *proc, int status,
     }
 
     if (value_len < mtu - 1) {
-        ble_gattc_read_long_cb(proc, 0, 0, NULL);
+        /* Response shorter than maximum allowed; read complete. */
+        ble_gattc_read_long_cb(proc, BLE_HS_EDONE, 0, NULL);
         return BLE_HS_EDONE;
     }
 
@@ -2844,9 +2893,10 @@ ble_gattc_read_mult_cb(struct ble_gattc_proc *proc, int status,
     int rc;
 
     BLE_HS_DBG_ASSERT(!ble_hs_locked_by_cur_task());
+    BLE_HS_DBG_ASSERT(attr_data != NULL || status != 0);
     ble_gattc_dbg_assert_proc_not_inserted(proc);
 
-    if (status != 0) {
+    if (status != 0 && status != BLE_HS_EDONE) {
         STATS_INC(ble_gattc_stats, read_mult_fail);
     }
 
@@ -2997,7 +3047,7 @@ ble_gattc_write_cb(struct ble_gattc_proc *proc, int status,
     BLE_HS_DBG_ASSERT(!ble_hs_locked_by_cur_task());
     ble_gattc_dbg_assert_proc_not_inserted(proc);
 
-    if (status != 0) {
+    if (status != 0 && status != BLE_HS_EDONE) {
         STATS_INC(ble_gattc_stats, write_fail);
     }
 
@@ -3102,7 +3152,7 @@ ble_gattc_write_long_cb(struct ble_gattc_proc *proc, int status,
     BLE_HS_DBG_ASSERT(!ble_hs_locked_by_cur_task());
     ble_gattc_dbg_assert_proc_not_inserted(proc);
 
-    if (status != 0) {
+    if (status != 0 && status != BLE_HS_EDONE) {
         STATS_INC(ble_gattc_stats, write_long_fail);
     }
 
@@ -3182,7 +3232,6 @@ ble_gattc_write_long_err(struct ble_gattc_proc *proc, int status,
     struct ble_att_exec_write_req exec_req;
 
     ble_gattc_dbg_assert_proc_not_inserted(proc);
-    ble_gattc_write_long_cb(proc, status, att_handle);
 
     /* If we have successfully queued any data, and the failure occurred before
      * we could send the execute write command, then erase all queued data.
@@ -3193,6 +3242,9 @@ ble_gattc_write_long_err(struct ble_gattc_proc *proc, int status,
         exec_req.baeq_flags = 0;
         ble_att_clt_tx_exec_write(proc->conn_handle, &exec_req);
     }
+
+    /* Report failure. */
+    ble_gattc_write_long_cb(proc, status, att_handle);
 }
 
 /**
@@ -3341,7 +3393,7 @@ ble_gattc_write_reliable_cb(struct ble_gattc_proc *proc, int status,
     BLE_HS_DBG_ASSERT(!ble_hs_locked_by_cur_task());
     ble_gattc_dbg_assert_proc_not_inserted(proc);
 
-    if (status != 0) {
+    if (status != 0 && status != BLE_HS_EDONE) {
         STATS_INC(ble_gattc_stats, write_reliable_fail);
     }
 
@@ -3643,7 +3695,7 @@ ble_gattc_indicate_cb(struct ble_gattc_proc *proc, int status,
     BLE_HS_DBG_ASSERT(!ble_hs_locked_by_cur_task());
     ble_gattc_dbg_assert_proc_not_inserted(proc);
 
-    if (status != 0) {
+    if (status != 0 && status != BLE_HS_EDONE) {
         STATS_INC(ble_gattc_stats, indicate_fail);
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2447ea0e/net/nimble/host/src/test/ble_gatt_disc_c_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_gatt_disc_c_test.c b/net/nimble/host/src/test/ble_gatt_disc_c_test.c
index 01a26f7..7db9350 100644
--- a/net/nimble/host/src/test/ble_gatt_disc_c_test.c
+++ b/net/nimble/host/src/test/ble_gatt_disc_c_test.c
@@ -175,19 +175,27 @@ ble_gatt_disc_c_test_misc_cb(uint16_t conn_handle,
     struct ble_gatt_chr *dst;
     int *stop_after;
 
-    TEST_ASSERT(error != NULL && error->status == 0);
+    TEST_ASSERT(error != NULL);
     TEST_ASSERT(!ble_gatt_disc_c_test_rx_complete);
 
     stop_after = arg;
 
-    if (chr == NULL) {
-        ble_gatt_disc_c_test_rx_complete = 1;
-    } else {
+    switch (error->status) {
+    case 0:
         TEST_ASSERT_FATAL(ble_gatt_disc_c_test_num_chars <
                           BLE_GATT_DISC_C_TEST_MAX_CHARS);
 
         dst = ble_gatt_disc_c_test_chars + ble_gatt_disc_c_test_num_chars++;
         *dst = *chr;
+        break;
+
+    case BLE_HS_EDONE:
+        ble_gatt_disc_c_test_rx_complete = 1;
+        break;
+
+    default:
+        TEST_ASSERT(0);
+        break;
     }
 
     if (*stop_after > 0) {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2447ea0e/net/nimble/host/src/test/ble_gatt_disc_d_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_gatt_disc_d_test.c b/net/nimble/host/src/test/ble_gatt_disc_d_test.c
index 7ba58c4..26e49be 100644
--- a/net/nimble/host/src/test/ble_gatt_disc_d_test.c
+++ b/net/nimble/host/src/test/ble_gatt_disc_d_test.c
@@ -164,14 +164,13 @@ ble_gatt_disc_d_test_misc_cb(uint16_t conn_handle,
     struct ble_gatt_disc_d_test_dsc *dst;
     int *stop_after;
 
-    TEST_ASSERT(error != NULL && error->status == 0);
+    TEST_ASSERT(error != NULL);
     TEST_ASSERT(!ble_gatt_disc_d_test_rx_complete);
 
     stop_after = arg;
 
-    if (dsc == NULL) {
-        ble_gatt_disc_d_test_rx_complete = 1;
-    } else {
+    switch (error->status) {
+    case 0:
         TEST_ASSERT_FATAL(ble_gatt_disc_d_test_num_dscs <
                           BLE_GATT_DISC_D_TEST_MAX_DSCS);
 
@@ -179,6 +178,15 @@ ble_gatt_disc_d_test_misc_cb(uint16_t conn_handle,
         dst->chr_def_handle = chr_def_handle;
         dst->dsc_handle = dsc->handle;
         memcpy(dst->dsc_uuid128, dsc->uuid128, 16);
+        break;
+
+    case BLE_HS_EDONE:
+        ble_gatt_disc_d_test_rx_complete = 1;
+        break;
+
+    default:
+        TEST_ASSERT(0);
+        break;
     }
 
     if (*stop_after > 0) {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2447ea0e/net/nimble/host/src/test/ble_gatt_disc_s_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_gatt_disc_s_test.c b/net/nimble/host/src/test/ble_gatt_disc_s_test.c
index 346c71b..1275e38 100644
--- a/net/nimble/host/src/test/ble_gatt_disc_s_test.c
+++ b/net/nimble/host/src/test/ble_gatt_disc_s_test.c
@@ -223,15 +223,24 @@ ble_gatt_disc_s_test_misc_disc_cb(uint16_t conn_handle,
                                   const struct ble_gatt_svc *service,
                                   void *arg)
 {
-    TEST_ASSERT(error != NULL && error->status == 0);
+    TEST_ASSERT(error != NULL);
     TEST_ASSERT(!ble_gatt_disc_s_test_rx_complete);
 
-    if (service == NULL) {
-        ble_gatt_disc_s_test_rx_complete = 1;
-    } else {
+    switch (error->status) {
+    case 0:
+        TEST_ASSERT(service != NULL);
         TEST_ASSERT_FATAL(ble_gatt_disc_s_test_num_svcs <
                           BLE_GATT_DISC_S_TEST_MAX_SERVICES);
         ble_gatt_disc_s_test_svcs[ble_gatt_disc_s_test_num_svcs++] = *service;
+        break;
+
+    case BLE_HS_EDONE:
+        TEST_ASSERT(service == NULL);
+        ble_gatt_disc_s_test_rx_complete = 1;
+        break;
+
+    default:
+        TEST_ASSERT(0);
     }
 
     return 0;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2447ea0e/net/nimble/host/src/test/ble_gatt_find_s_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_gatt_find_s_test.c b/net/nimble/host/src/test/ble_gatt_find_s_test.c
index d9eb0e8..cf988d6 100644
--- a/net/nimble/host/src/test/ble_gatt_find_s_test.c
+++ b/net/nimble/host/src/test/ble_gatt_find_s_test.c
@@ -51,12 +51,20 @@ ble_gatt_find_s_test_misc_cb(uint16_t conn_handle,
                              void *arg)
 {
     TEST_ASSERT(!ble_gatt_find_s_test_proc_complete);
-    TEST_ASSERT(error != NULL && error->status == 0);
+    TEST_ASSERT(error != NULL);
 
-    if (service == NULL) {
-        ble_gatt_find_s_test_proc_complete = 1;
-    } else {
+    switch (error->status) {
+    case 0:
         ble_gatt_find_s_test_svcs[ble_gatt_find_s_test_num_svcs++] = *service;
+        break;
+
+    case BLE_HS_EDONE:
+        ble_gatt_find_s_test_proc_complete = 1;
+        break;
+
+    default:
+        TEST_ASSERT(0);
+        break;
     }
 
     return 0;


[39/50] [abbrv] incubator-mynewt-core git commit: mbuf: fix const correctness in os_mbuf_off().

Posted by cc...@apache.org.
mbuf: fix const correctness in os_mbuf_off().


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

Branch: refs/heads/ble_hs_api
Commit: fd4a12a2d1b7551e6894f9f3090d4ed1dd073787
Parents: 44b45e9
Author: Christopher Collins <cc...@apache.org>
Authored: Fri Jul 8 19:41:52 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Jul 11 16:43:34 2016 -0700

----------------------------------------------------------------------
 libs/os/include/os/os_mbuf.h |  2 +-
 libs/os/src/os_mbuf.c        | 20 ++++++++++++--------
 2 files changed, 13 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/fd4a12a2/libs/os/include/os/os_mbuf.h
----------------------------------------------------------------------
diff --git a/libs/os/include/os/os_mbuf.h b/libs/os/include/os/os_mbuf.h
index 74b9548..831d770 100644
--- a/libs/os/include/os/os_mbuf.h
+++ b/libs/os/include/os/os_mbuf.h
@@ -259,7 +259,7 @@ struct os_mbuf *os_mbuf_get_pkthdr(struct os_mbuf_pool *omp,
 /* Duplicate a mbuf from the pool */
 struct os_mbuf *os_mbuf_dup(struct os_mbuf *m);
 
-struct os_mbuf * os_mbuf_off(struct os_mbuf *om, int off, int *out_off);
+struct os_mbuf * os_mbuf_off(const struct os_mbuf *om, int off, int *out_off);
 
 /* Copy data from an mbuf to a flat buffer. */
 int os_mbuf_copydata(const struct os_mbuf *m, int off, int len, void *dst);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/fd4a12a2/libs/os/src/os_mbuf.c
----------------------------------------------------------------------
diff --git a/libs/os/src/os_mbuf.c b/libs/os/src/os_mbuf.c
index 85232d8..65afc01 100644
--- a/libs/os/src/os_mbuf.c
+++ b/libs/os/src/os_mbuf.c
@@ -576,26 +576,30 @@ err:
  *                              NULL if the specified offset is out of bounds.
  */
 struct os_mbuf *
-os_mbuf_off(struct os_mbuf *om, int off, int *out_off)
+os_mbuf_off(const struct os_mbuf *om, int off, int *out_off)
 {
     struct os_mbuf *next;
+    struct os_mbuf *cur;
+
+    /* Cast away const. */
+    cur = (struct os_mbuf *)om;
 
     while (1) {
-        if (om == NULL) {
+        if (cur == NULL) {
             return NULL;
         }
 
-        next = SLIST_NEXT(om, om_next);
+        next = SLIST_NEXT(cur, om_next);
 
-        if (om->om_len > off ||
-            (om->om_len == off && next == NULL)) {
+        if (cur->om_len > off ||
+            (cur->om_len == off && next == NULL)) {
 
             *out_off = off;
-            return om;
+            return cur;
         }
 
-        off -= om->om_len;
-        om = next;
+        off -= cur->om_len;
+        cur = next;
     }
 }
 


[43/50] [abbrv] incubator-mynewt-core git commit: BLE Host - GAP event callback updates.

Posted by cc...@apache.org.
BLE Host - GAP event callback updates.


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

Branch: refs/heads/ble_hs_api
Commit: 27445b801be5ed517b2577b7c4e335fdfb20b75b
Parents: 3bb2419
Author: Christopher Collins <cc...@apache.org>
Authored: Thu Jul 7 13:44:46 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Jul 11 16:43:34 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/include/host/ble_gap.h      | 226 +++++++++++---
 net/nimble/host/include/host/ble_hs.h       |   6 +-
 net/nimble/host/src/ble_gap.c               | 362 ++++++++++++-----------
 net/nimble/host/src/ble_gap_priv.h          |   2 +-
 net/nimble/host/src/ble_gattc.c             |   2 +-
 net/nimble/host/src/ble_hs.c                |  11 +-
 net/nimble/host/src/ble_sm.c                |   8 +-
 net/nimble/host/src/ble_sm_priv.h           |   2 +-
 net/nimble/host/src/ble_sm_sc.c             |   8 +-
 net/nimble/host/src/test/ble_att_svr_test.c |  17 +-
 net/nimble/host/src/test/ble_gap_test.c     |  98 +++---
 net/nimble/host/src/test/ble_hs_test_util.c |   4 +-
 net/nimble/host/src/test/ble_hs_test_util.h |   2 +-
 net/nimble/host/src/test/ble_l2cap_test.c   |   5 +-
 net/nimble/host/src/test/ble_os_test.c      |  56 ++--
 net/nimble/host/src/test/ble_sm_test_util.c |  36 +--
 net/nimble/host/src/test/ble_sm_test_util.h |   3 +-
 17 files changed, 497 insertions(+), 351 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/27445b80/net/nimble/host/include/host/ble_gap.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/ble_gap.h b/net/nimble/host/include/host/ble_gap.h
index f83b1de..7577d6d 100644
--- a/net/nimble/host/include/host/ble_gap.h
+++ b/net/nimble/host/include/host/ble_gap.h
@@ -105,7 +105,7 @@ struct hci_conn_update;
 #define BLE_GAP_EVENT_CONN_UPDATE_REQ       4
 #define BLE_GAP_EVENT_L2CAP_UPDATE_REQ      5
 #define BLE_GAP_EVENT_TERM_FAILURE          6
-#define BLE_GAP_EVENT_DISC_SUCCESS          7
+#define BLE_GAP_EVENT_DISC                  7
 #define BLE_GAP_EVENT_DISC_COMPLETE         8
 #define BLE_GAP_EVENT_ADV_COMPLETE          9
 #define BLE_GAP_EVENT_ENC_CHANGE            10
@@ -194,89 +194,225 @@ struct ble_gap_upd_params {
     uint16_t max_ce_len;
 };
 
-struct ble_gap_notify_params {
-    uint16_t attr_handle;
-    void *attr_data;
-    uint16_t attr_len;
-
-    unsigned indication:1;
-};
-
-struct ble_gap_passkey_action {
+struct ble_gap_passkey_params {
     uint8_t action;
     uint32_t numcmp;
 };
 
-struct ble_gap_event_ctxt {
-    struct ble_gap_conn_desc *desc;
+struct ble_gap_disc_desc {
+    /*** Common fields. */
+    uint8_t event_type;
+    uint8_t addr_type;
+    uint8_t length_data;
+    int8_t rssi;
+    uint8_t addr[6];
+
+    /*** LE advertising report fields; both null if no data present. */
+    uint8_t *data;
+    struct ble_hs_adv_fields *fields;
 
+    /***
+     * LE direct advertising report fields; direct_addr_type is
+     * BLE_GAP_ADDR_TYPE_NONE if direct address fields are not present.
+     */
+    uint8_t direct_addr_type;
+    uint8_t direct_addr[6];
+};
+
+/**
+ * Represents a GAP-related event.  When such an event occurs, the host
+ * notifies the application by passing an instance of this structure to an
+ * application-specified callback.
+ */
+struct ble_gap_event {
+    /**
+     * Indicates the type of GAP event that occurred.  This is one of the
+     * BLE_GAP_EVENT codes.
+     */
+    uint8_t type;
+
+    /**
+     * A discriminated union containing additional details concerning the GAP
+     * event.  The 'type' field indicates which member of the union is valid.
+     */
     union {
+        /**
+         * Represents a connection attempt.  Valid for the following event
+         * types:
+         *     o BLE_GAP_EVENT_CONNECT
+         */
         struct {
+            /**
+             * The status of the connection attempt;
+             *     o 0: the connection was successfully established.
+             *     o BLE host error code: the connection attempt failed for
+             *       the specified reason.
+             */
             int status;
+
+            /**
+             * Information about the established connection.  Only valid on
+             * success.
+             */
+            struct ble_gap_conn_desc conn;
         } connect;
 
+        /**
+         * Represents a terminated connection.  Valid for the following event
+         * types:
+         *     o BLE_GAP_EVENT_DISCONNECT
+         */
         struct {
+            /**
+             * A BLE host return code indicating the reason for the
+             * disconnect.
+             */
             int reason;
+
+            /** Information about the terminated connection. */
+            struct ble_gap_conn_desc conn;
         } disconnect;
 
+        /**
+         * Represents an advertising report received during a discovery
+         * procedure.  Valid for the following event types:
+         *     o BLE_GAP_EVENT_DISC
+         */
+        struct ble_gap_disc_desc disc;
+
+        /**
+         * Represents an attempt to update a connection's parameters.  Valid
+         * for the following event types:
+         *     o BLE_GAP_EVENT_CONN_UPDATE
+         */
         struct {
+            /**
+             * The result of the connection update attempt;
+             *     o 0: the connection was successfully updated.
+             *     o BLE host error code: the connection update attempt failed
+             *       for the specified reason.
+             */
             int status;
+
+            /**
+             * Information about the relevant connection.  If the connection
+             * update attempt was successful, this descriptor contains the
+             * updated parameters.
+             */
+            struct ble_gap_conn_desc conn;
         } conn_update;
 
+        /**
+         * Represents a peer's request to update the connection parameters.
+         * This event is generated when a peer performs any of the following
+         * procedures:
+         *     o L2CAP Connection Parameter Update Procedure
+         *     o Link-Layer Connection Parameters Request Procedure
+         *
+         * Valid for the following event types:
+         *     o BLE_GAP_EVENT_L2CAP_UPDATE_REQ
+         *     o BLE_GAP_EVENT_CONN_UPDATE_REQ
+         * 
+         */
         struct {
+            /**
+             * Indicates the connection parameters that the peer would like to
+             * use.
+             */
+            const struct ble_gap_upd_params *peer_params;
+
+            /**
+             * Indicates the connection parameters that the local device would
+             * like to use.  The application callback should fill this in.  By
+             * default, this struct contains the requested parameters (i.e.,
+             * it is a copy of 'peer_params').
+             */
             struct ble_gap_upd_params *self_params;
-            struct ble_gap_upd_params *peer_params;
+
+            /** Information about the relevant connection. */
+            struct ble_gap_conn_desc conn;
         } conn_update_req;
 
+        /**
+         * Represents a failed attempt to terminate an established connection.
+         * Valid for the following event types:
+         *     o BLE_GAP_EVENT_TERM_FAILURE
+         */
         struct {
+            /**
+             * A BLE host return code indicating the reason for the failure.
+             */
             int status;
+
+            /** Information about the relevant connection. */
+            struct ble_gap_conn_desc conn;
         } term_failure;
 
+        /**
+         * Represents an attempt to change the encrypted state of a
+         * connection.  Valid for the following event types:
+         *     o BLE_GAP_EVENT_ENC_CHANGE
+         */
         struct {
+            /**
+             * Indicates the result of the encryption state change attempt;
+             *     o 0: the encrypted state was successfully updated;
+             *     o BLE host error code: the encryption state change attempt
+             *       failed for the specified reason.
+             */
             int status;
-        } enc_change;
 
-        struct ble_gap_passkey_action passkey_action;
+            /**
+             * Information about the relevant connection.  If the encryption
+             * state change attempt was successful, this descriptor reflects
+             * the updated state.
+             */
+            struct ble_gap_conn_desc conn;
+        } enc_change;
 
+        /**
+         * Represents a passkey query needed to complete a pairing procedure.
+         * Valid for the following event types:
+         *     o BLE_GAP_EVENT_PASSKEY_ACTION
+         */
+        struct {
+            /** Contains details about the passkey query. */
+            struct ble_gap_passkey_params params;
+
+            /** Information about the relevant connection. */
+            struct ble_gap_conn_desc conn;
+        } passkey;
+
+        /**
+         * Represents a received ATT notification or indication.
+         * Valid for the following event types:
+         *     o BLE_GAP_EVENT_NOTIFY
+         */
         struct {
+            /** The handle of the relevant ATT attribute. */
             uint16_t attr_handle;
+
+            /** The contents of the notification or indication. */
             void *attr_data;
+
+            /** The number of data bytes contained in the message. */
             uint16_t attr_len;
 
+            /** Information about the relevant connection. */
+            struct ble_gap_conn_desc conn;
+
+            /**
+             * Whether the received command is a notification or an
+             * indication;
+             *     o 0: Notification;
+             *     o 1: Indication.
+             */
             unsigned indication:1;
         } notify;
-
-        struct ble_gap_ltk_params *ltk_params;
     };
 };
 
-typedef int ble_gap_event_fn(int event, struct ble_gap_event_ctxt *ctxt,
-                             void *arg);
-
-struct ble_gap_disc_desc {
-    /*** Common fields. */
-    uint8_t event_type;
-    uint8_t addr_type;
-    uint8_t length_data;
-    int8_t rssi;
-    uint8_t addr[6];
-
-    /*** LE advertising report fields; both null if no data present. */
-    uint8_t *data;
-    struct ble_hs_adv_fields *fields;
-
-    /***
-     * LE direct advertising report fields; direct_addr_type is
-     * BLE_GAP_ADDR_TYPE_NONE if direct address fields are not present.
-     */
-    uint8_t direct_addr_type;
-    uint8_t direct_addr[6];
-};
-
-typedef void ble_gap_disc_fn(int event, int status,
-                             struct ble_gap_disc_desc *desc, void *arg);
-
-typedef void ble_gap_wl_fn(int status, void *arg);
+typedef int ble_gap_event_fn(struct ble_gap_event *ctxt, void *arg);
 
 #define BLE_GAP_CONN_MODE_NON               0
 #define BLE_GAP_CONN_MODE_DIR               1
@@ -303,7 +439,7 @@ int ble_gap_adv_set_fields(const struct ble_hs_adv_fields *adv_fields);
 int ble_gap_adv_rsp_set_fields(const struct ble_hs_adv_fields *rsp_fields);
 int ble_gap_disc(uint8_t own_addr_type, int32_t duration_ms,
                  const struct ble_gap_disc_params *disc_params,
-                 ble_gap_disc_fn *cb, void *cb_arg);
+                 ble_gap_event_fn *cb, void *cb_arg);
 int ble_gap_disc_cancel(void);
 int ble_gap_disc_active(void);
 int ble_gap_connect(uint8_t own_addr_type,

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/27445b80/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 3113b0d..61900b6 100644
--- a/net/nimble/host/include/host/ble_hs.h
+++ b/net/nimble/host/include/host/ble_hs.h
@@ -73,17 +73,13 @@ struct os_event;
 #define BLE_HS_ERR_SM_PEER_BASE     0x500   /* 1280 */
 #define BLE_HS_SM_PEER_ERR(x)       ((x) ? BLE_HS_ERR_SM_PEER_BASE + (x) : 0)
 
-/* defines the input output (io) capabilities for the host device */
+/* Defines the IO capabilities for the local device. */
 #define BLE_HS_IO_DISPLAY_ONLY              0x00
 #define BLE_HS_IO_DISPLAY_YESNO             0x01
 #define BLE_HS_IO_KEYBOARD_ONLY             0x02
 #define BLE_HS_IO_NO_INPUT_OUTPUT           0x03
 #define BLE_HS_IO_KEYBOARD_DISPLAY          0x04
 
-#define BLE_HS_PRIVACY_MODE_NONE            0
-#define BLE_HS_PRIVACY_MODE_RANDOM_STATIC   1
-#define BLE_HS_PRIVACY_MODE_RESOLV_RAND     2
-
 struct ble_hs_cfg {
     /*** HCI settings. */
     /**

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/27445b80/net/nimble/host/src/ble_gap.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gap.c b/net/nimble/host/src/ble_gap.c
index 7254287..48285d6 100644
--- a/net/nimble/host/src/ble_gap.c
+++ b/net/nimble/host/src/ble_gap.c
@@ -94,19 +94,18 @@ static bssnz_t struct {
     uint8_t exp_set:1;
     os_time_t exp_os_ticks;
 
+    ble_gap_event_fn *cb;
+    void *cb_arg;
+
     union {
-        struct {
-            ble_gap_event_fn *cb;
-            void *cb_arg;
 
+        struct {
             uint8_t using_wl:1;
             uint8_t our_addr_type:2;
         } conn;
 
         struct {
             uint8_t limited:1;
-            ble_gap_disc_fn *cb;
-            void *cb_arg;
         } disc;
     };
 } ble_gap_master;
@@ -139,7 +138,7 @@ static int ble_gap_disc_tx_disable(void);
 static int ble_gap_adv_disable_tx(void);
 
 struct ble_gap_snapshot {
-    struct ble_gap_conn_desc desc;
+    struct ble_gap_conn_desc *desc;
     ble_gap_event_fn *cb;
     void *cb_arg;
 };
@@ -315,7 +314,7 @@ static void
 ble_gap_conn_to_snapshot(struct ble_hs_conn *conn,
                          struct ble_gap_snapshot *snap)
 {
-    ble_gap_fill_conn_desc(conn, &snap->desc);
+    ble_gap_fill_conn_desc(conn, snap->desc);
     snap->cb = conn->bhc_cb;
     snap->cb_arg = conn->bhc_cb_arg;
 }
@@ -380,7 +379,7 @@ ble_gap_conn_find(uint16_t handle, struct ble_gap_conn_desc *out_desc)
  *****************************************************************************/
 
 static int
-ble_gap_call_event_cb(int event, struct ble_gap_event_ctxt *ctxt,
+ble_gap_call_event_cb(struct ble_gap_event *event,
                       ble_gap_event_fn *cb, void *cb_arg)
 {
     int rc;
@@ -388,12 +387,12 @@ ble_gap_call_event_cb(int event, struct ble_gap_event_ctxt *ctxt,
     BLE_HS_DBG_ASSERT(!ble_hs_locked_by_cur_task());
 
     if (cb != NULL) {
-        rc = cb(event, ctxt, cb_arg);
+        rc = cb(event, cb_arg);
     } else {
-        if (event == BLE_GAP_EVENT_CONN_UPDATE_REQ) {
+        if (event->type == BLE_GAP_EVENT_CONN_UPDATE_REQ) {
             /* Just copy peer parameters back into the reply. */
-            *ctxt->conn_update_req.self_params =
-                *ctxt->conn_update_req.peer_params;
+            *event->conn_update_req.self_params =
+                *event->conn_update_req.peer_params;
         }
         rc = 0;
     }
@@ -416,13 +415,17 @@ ble_gap_slave_reset_state(void)
 }
 
 static void
-ble_gap_master_extract_cb(ble_gap_event_fn **out_cb, void **out_cb_arg)
+ble_gap_master_extract_cb(ble_gap_event_fn **out_cb, void **out_cb_arg,
+                          int reset_state)
 {
     ble_hs_lock();
 
-    *out_cb = ble_gap_master.conn.cb;
-    *out_cb_arg = ble_gap_master.conn.cb_arg;
-    ble_gap_master_reset_state();
+    *out_cb = ble_gap_master.cb;
+    *out_cb_arg = ble_gap_master.cb_arg;
+
+    if (reset_state) {
+        ble_gap_master_reset_state();
+    }
 
     ble_hs_unlock();
 }
@@ -442,40 +445,34 @@ ble_gap_slave_extract_cb(ble_gap_event_fn **out_cb, void **out_cb_arg)
 static void
 ble_gap_adv_finished(void)
 {
-    struct ble_gap_event_ctxt ctxt;
-    struct ble_gap_conn_desc desc;
+    struct ble_gap_event event;
     ble_gap_event_fn *cb;
     void *cb_arg;
 
     ble_gap_slave_extract_cb(&cb, &cb_arg);
     if (cb != NULL) {
-        memset(&ctxt, 0, sizeof ctxt);
-        desc.conn_handle = BLE_HS_CONN_HANDLE_NONE;
-        ctxt.desc = &desc;
+        memset(&event, 0, sizeof event);
+        event.type = BLE_GAP_EVENT_ADV_COMPLETE;
 
-        cb(BLE_GAP_EVENT_ADV_COMPLETE, &ctxt, cb_arg);
+        cb(&event, cb_arg);
     }
 }
 
 static int
 ble_gap_master_connect_failure(int status)
 {
-    struct ble_gap_event_ctxt ctxt;
-    struct ble_gap_conn_desc desc;
+    struct ble_gap_event event;
     ble_gap_event_fn *cb;
     void *cb_arg;
     int rc;
 
-    memset(&desc, 0, sizeof ctxt);
-
-    ble_gap_master_extract_cb(&cb, &cb_arg);
+    ble_gap_master_extract_cb(&cb, &cb_arg, 1);
     if (cb != NULL) {
-        memset(&ctxt, 0, sizeof ctxt);
-        desc.conn_handle = BLE_HS_CONN_HANDLE_NONE;
-        ctxt.desc = &desc;
-        ctxt.connect.status = status;
+        memset(&event, 0, sizeof event);
+        event.type = BLE_GAP_EVENT_CONNECT;
+        event.connect.status = status;
 
-        rc = cb(BLE_GAP_EVENT_CONNECT, &ctxt, cb_arg);
+        rc = cb(&event, cb_arg);
     } else {
         rc = 0;
     }
@@ -486,20 +483,16 @@ ble_gap_master_connect_failure(int status)
 static int
 ble_gap_master_connect_cancel(void)
 {
-    struct ble_gap_event_ctxt ctxt;
-    struct ble_gap_conn_desc desc;
+    struct ble_gap_event event;
     ble_gap_event_fn *cb;
     void *cb_arg;
     int rc;
 
-    memset(&desc, 0, sizeof ctxt);
-    desc.conn_handle = BLE_HS_CONN_HANDLE_NONE;
-
-    ble_gap_master_extract_cb(&cb, &cb_arg);
+    ble_gap_master_extract_cb(&cb, &cb_arg, 1);
     if (cb != NULL) {
-        memset(&ctxt, 0, sizeof ctxt);
-        ctxt.desc = &desc;
-        rc = cb(BLE_GAP_EVENT_CONN_CANCEL, &ctxt, cb_arg);
+        memset(&event, 0, sizeof event);
+        event.type = BLE_GAP_EVENT_CONN_CANCEL;
+        rc = cb(&event, cb_arg);
     } else {
         rc = 0;
     }
@@ -508,46 +501,58 @@ ble_gap_master_connect_cancel(void)
 }
 
 static void
-ble_gap_call_master_disc_cb(int event, int status,
-                            struct ble_gap_disc_desc *desc,
-                            struct ble_hs_adv_fields *fields, int reset_state)
+ble_gap_disc_report(struct ble_gap_disc_desc *desc)
 {
-    ble_gap_disc_fn *cb;
+    struct ble_gap_event event;
+    ble_gap_event_fn *cb;
     void *cb_arg;
 
-    ble_hs_lock();
+    ble_gap_master_extract_cb(&cb, &cb_arg, 0);
 
-    cb = ble_gap_master.disc.cb;
-    cb_arg = ble_gap_master.disc.cb_arg;
+    if (cb != NULL) {
+        memset(&event, 0, sizeof event);
+        event.type = BLE_GAP_EVENT_DISC;
+        event.disc = *desc;
 
-    if (reset_state) {
-        ble_gap_master_reset_state();
+        cb(&event, cb_arg);
     }
+}
 
-    ble_hs_unlock();
+static void
+ble_gap_disc_complete(void)
+{
+    struct ble_gap_event event;
+    ble_gap_event_fn *cb;
+    void *cb_arg;
+
+    ble_gap_master_extract_cb(&cb, &cb_arg, 1);
 
     if (cb != NULL) {
-        cb(event, status, desc, cb_arg);
+        memset(&event, 0, sizeof event);
+        event.type = BLE_GAP_EVENT_DISC_COMPLETE;
+
+        ble_gap_call_event_cb(&event, cb, cb_arg);
     }
 }
 
 static void
 ble_gap_update_notify(uint16_t conn_handle, int status)
 {
-    struct ble_gap_event_ctxt ctxt;
     struct ble_gap_snapshot snap;
+    struct ble_gap_event event;
     int rc;
 
+    memset(&event, 0, sizeof event);
+
+    snap.desc = &event.conn_update.conn;
     rc = ble_gap_find_snapshot(conn_handle, &snap);
     if (rc != 0) {
         return;
     }
 
-    memset(&ctxt, 0, sizeof ctxt);
-    ctxt.desc = &snap.desc;
-    ctxt.conn_update.status = status;
-    ble_gap_call_event_cb(BLE_GAP_EVENT_CONN_UPDATE, &ctxt,
-                          snap.cb, snap.cb_arg);
+    event.type = BLE_GAP_EVENT_CONN_UPDATE;
+    event.conn_update.status = status;
+    ble_gap_call_event_cb(&event, snap.cb, snap.cb_arg);
 }
 
 static uint32_t
@@ -624,25 +629,19 @@ ble_gap_slave_set_timer(uint32_t ticks_from_now)
 
 /**
  * Called when an error is encountered while the master-connection-fsm is
- * active.  Resets the state machine, clears the HCI ack callback, and notifies
- * the host task that the next hci_batch item can be processed.
+ * active.
  */
 static void
 ble_gap_master_failed(int status)
 {
     switch (ble_gap_master.op) {
-    case BLE_GAP_OP_M_DISC:
-        STATS_INC(ble_gap_stats, discover_fail);
-        ble_gap_call_master_disc_cb(BLE_GAP_EVENT_DISC_COMPLETE, status,
-                                    NULL, NULL, 1);
-        break;
-
     case BLE_GAP_OP_M_CONN:
         STATS_INC(ble_gap_stats, initiate_fail);
         ble_gap_master_connect_failure(status);
         break;
 
     default:
+        BLE_HS_DBG_ASSERT(0);
         break;
     }
 }
@@ -656,24 +655,33 @@ ble_gap_update_failed(uint16_t conn_handle, int status)
 }
 
 static void
-ble_gap_conn_broken(struct ble_gap_snapshot *snap, int reason)
+ble_gap_conn_broken(uint16_t conn_handle, int reason)
 {
-    struct ble_gap_event_ctxt ctxt;
+    struct ble_gap_snapshot snap;
+    struct ble_gap_event event;
+    int rc;
+
+    memset(&event, 0, sizeof event);
+    snap.desc = &event.disconnect.conn;
+
+    rc = ble_gap_find_snapshot(conn_handle, &snap);
+    if (rc != 0) {
+        /* No longer connected. */
+        return;
+    }
 
     /* XXX: Consider removing the connection from the list and handing it to
      * each of the "connection_broken" functions below.
      */
 
-    ble_sm_connection_broken(snap->desc.conn_handle);
-    ble_gattc_connection_broken(snap->desc.conn_handle);
+    ble_sm_connection_broken(conn_handle);
+    ble_gattc_connection_broken(conn_handle);
 
-    ble_hs_atomic_conn_delete(snap->desc.conn_handle);
+    ble_hs_atomic_conn_delete(conn_handle);
 
-    memset(&ctxt, 0, sizeof ctxt);
-    ctxt.desc = &snap->desc;
-    ctxt.disconnect.reason = reason;
-    ble_gap_call_event_cb(BLE_GAP_EVENT_DISCONNECT, &ctxt,
-                          snap->cb, snap->cb_arg);
+    event.type = BLE_GAP_EVENT_DISCONNECT;
+    event.disconnect.reason = reason;
+    ble_gap_call_event_cb(&event, snap.cb, snap.cb_arg);
 
     STATS_INC(ble_gap_stats, disconnect);
 }
@@ -685,28 +693,28 @@ ble_gap_rx_disconn_complete(struct hci_disconn_complete *evt)
     return;
 #endif
 
-    struct ble_gap_event_ctxt ctxt;
+    struct ble_gap_event event;
     struct ble_gap_snapshot snap;
     int status;
     int rc;
 
     STATS_INC(ble_gap_stats, rx_disconnect);
 
-    rc = ble_gap_find_snapshot(evt->connection_handle, &snap);
-    if (rc != 0) {
-        /* No longer connected. */
-        return;
-    }
-
     if (evt->status == 0) {
         status = BLE_HS_HCI_ERR(evt->reason);
-        ble_gap_conn_broken(&snap, status);
+        ble_gap_conn_broken(evt->connection_handle, status);
     } else {
-        memset(&ctxt, 0, sizeof ctxt);
-        ctxt.desc = &snap.desc;
-        ctxt.term_failure.status = BLE_HS_HCI_ERR(evt->status);
-        ble_gap_call_event_cb(BLE_GAP_EVENT_TERM_FAILURE, &ctxt,
-                              snap.cb, snap.cb_arg);
+        memset(&event, 0, sizeof event);
+        snap.desc = &event.term_failure.conn;
+        rc = ble_gap_find_snapshot(evt->connection_handle, &snap);
+        if (rc != 0) {
+            /* No longer connected. */
+            return;
+        }
+
+        event.type = BLE_GAP_EVENT_TERM_FAILURE;
+        event.term_failure.status = BLE_HS_HCI_ERR(evt->status);
+        ble_gap_call_event_cb(&event, snap.cb, snap.cb_arg);
     }
 }
 
@@ -717,12 +725,15 @@ ble_gap_rx_update_complete(struct hci_le_conn_upd_complete *evt)
     return;
 #endif
 
-    struct ble_gap_event_ctxt ctxt;
+    struct ble_gap_event event;
     struct ble_gap_snapshot snap;
     struct ble_hs_conn *conn;
 
     STATS_INC(ble_gap_stats, rx_update_complete);
 
+    memset(&event, 0, sizeof event);
+    snap.desc = &event.conn_update.conn;
+
     ble_hs_lock();
 
     conn = ble_hs_conn_find(evt->connection_handle);
@@ -741,11 +752,9 @@ ble_gap_rx_update_complete(struct hci_le_conn_upd_complete *evt)
     ble_hs_unlock();
 
     if (conn != NULL) {
-        memset(&ctxt, 0, sizeof ctxt);
-        ctxt.desc = &snap.desc;
-        ctxt.conn_update.status = BLE_HS_HCI_ERR(evt->status);
-        ble_gap_call_event_cb(BLE_GAP_EVENT_CONN_UPDATE, &ctxt,
-                              snap.cb, snap.cb_arg);
+        event.type = BLE_GAP_EVENT_CONN_UPDATE;
+        event.conn_update.status = BLE_HS_HCI_ERR(evt->status);
+        ble_gap_call_event_cb(&event, snap.cb, snap.cb_arg);
     }
 }
 
@@ -884,8 +893,8 @@ ble_gap_rx_adv_report(struct ble_gap_disc_desc *desc)
         return;
     }
 
-    ble_gap_call_master_disc_cb(BLE_GAP_EVENT_DISC_SUCCESS, 0, desc,
-                                &fields, 0);
+    desc->fields = &fields;
+    ble_gap_disc_report(desc);
 }
 
 /**
@@ -898,24 +907,20 @@ ble_gap_rx_conn_complete(struct hci_le_conn_complete *evt)
     return BLE_HS_ENOTSUP;
 #endif
 
-    struct ble_gap_event_ctxt ctxt;
+    struct ble_gap_event event;
     struct ble_gap_snapshot snap;
     struct ble_hs_conn *conn;
     int rc;
 
     STATS_INC(ble_gap_stats, rx_conn_complete);
 
-    /* Determine if this event refers to a completed connection or a connection
-     * in progress.
-     */
-    rc = ble_gap_find_snapshot(evt->connection_handle, &snap);
-
     /* Apply the event to the existing connection if it exists. */
-    if (rc == 0) {
+    if (ble_hs_atomic_conn_flags(evt->connection_handle, NULL) == 0) {
         /* XXX: Does this ever happen? */
 
         if (evt->status != 0) {
-            ble_gap_conn_broken(&snap, BLE_HS_HCI_ERR(evt->status));
+            ble_gap_conn_broken(evt->connection_handle,
+                                BLE_HS_HCI_ERR(evt->status));
         }
         return 0;
     }
@@ -982,10 +987,10 @@ ble_gap_rx_conn_complete(struct hci_le_conn_complete *evt)
     conn->bhc_supervision_timeout = evt->supervision_timeout;
     conn->bhc_master_clock_accuracy = evt->master_clk_acc;
     if (evt->role == BLE_HCI_LE_CONN_COMPLETE_ROLE_MASTER) {
+        conn->bhc_cb = ble_gap_master.cb;
+        conn->bhc_cb_arg = ble_gap_master.cb_arg;
         conn->bhc_flags |= BLE_HS_CONN_F_MASTER;
-        conn->bhc_cb = ble_gap_master.conn.cb;
         conn->bhc_our_addr_type = ble_gap_master.conn.our_addr_type;
-        conn->bhc_cb_arg = ble_gap_master.conn.cb_arg;
         ble_gap_master_reset_state();
     } else {
         conn->bhc_cb = ble_gap_slave.cb;
@@ -999,15 +1004,16 @@ ble_gap_rx_conn_complete(struct hci_le_conn_complete *evt)
 
     ble_hs_lock();
 
+    memset(&event, 0, sizeof event);
+    snap.desc = &event.connect.conn;
     ble_gap_conn_to_snapshot(conn, &snap);
     ble_hs_conn_insert(conn);
 
     ble_hs_unlock();
 
-    memset(&ctxt, 0, sizeof ctxt);
-    ctxt.desc = &snap.desc;
-    ctxt.connect.status = 0;
-    ble_gap_call_event_cb(BLE_GAP_EVENT_CONNECT, &ctxt, snap.cb, snap.cb_arg);
+    event.type = BLE_GAP_EVENT_CONNECT;
+    event.connect.status = 0;
+    ble_gap_call_event_cb(&event, snap.cb, snap.cb_arg);
 
     return 0;
 }
@@ -1016,20 +1022,21 @@ int
 ble_gap_rx_l2cap_update_req(uint16_t conn_handle,
                             struct ble_gap_upd_params *params)
 {
-    struct ble_gap_event_ctxt ctxt;
+    struct ble_gap_event event;
     struct ble_gap_snapshot snap;
     int rc;
 
+    memset(&event, 0, sizeof event);
+    snap.desc = &event.conn_update.conn;
     rc = ble_gap_find_snapshot(conn_handle, &snap);
     if (rc != 0) {
         return rc;
     }
 
     if (snap.cb != NULL) {
-        memset(&ctxt, 0, sizeof ctxt);
-        ctxt.desc = &snap.desc;
-        ctxt.conn_update_req.peer_params = params;
-        rc = snap.cb(BLE_GAP_EVENT_L2CAP_UPDATE_REQ, &ctxt, snap.cb_arg);
+        event.type = BLE_GAP_EVENT_L2CAP_UPDATE_REQ;
+        event.conn_update_req.peer_params = params;
+        rc = snap.cb(&event, snap.cb_arg);
     } else {
         rc = 0;
     }
@@ -1052,6 +1059,10 @@ ble_gap_master_heartbeat(void)
     /*** Timer expired; process event. */
 
     switch (ble_gap_master.op) {
+    case BLE_GAP_OP_M_CONN:
+        ble_gap_master_failed(BLE_HS_ETIMEOUT);
+        break;
+
     case BLE_GAP_OP_M_DISC:
         /* When a discovery procedure times out, it is not a failure. */
         rc = ble_gap_disc_tx_disable();
@@ -1060,18 +1071,14 @@ ble_gap_master_heartbeat(void)
             return 100;
         }
 
-        ble_gap_call_master_disc_cb(BLE_GAP_EVENT_DISC_COMPLETE, rc,
-                                    NULL, NULL, 1);
+        ble_gap_disc_complete();
         break;
 
     default:
-        ble_gap_master_failed(BLE_HS_ETIMEOUT);
+        BLE_HS_DBG_ASSERT(0);
         break;
     }
 
-    /* Clear the timer and cancel the current procedure. */
-    ble_gap_master_reset_state();
-
     return BLE_HS_FOREVER;
 }
 
@@ -1606,15 +1613,15 @@ ble_gap_adv_validate(uint8_t own_addr_type, uint8_t peer_addr_type,
  *                                      o BLE_ADDR_TYPE_RANDOM
  *                                      o BLE_ADDR_TYPE_RPA_PUB_DEFAULT
  *                                      o BLE_ADDR_TYPE_RPA_RND_DEFAULT
- * @param peer_addr_type        This parameter is ignored unless directed
- *                                  advertising is being used.  Address type of
- *                                  the peer's identity address.  Valid values
- *                                  are:
+ * @param peer_addr_type        Address type of the peer's identity address.
+ *                                  Valid values are:
  *                                      o BLE_ADDR_TYPE_PUBLIC
  *                                      o BLE_ADDR_TYPE_RANDOM
- * @param peer_addr             This parameter is ignored unless directed
- *                                  advertising is being used.  The peer's
- *                                  six-byte identity address.
+ *                                  This parameter is ignored unless directed
+ *                                  advertising is being used.
+ * @param peer_addr             The peer's six-byte identity address.
+ *                                  This parameter is ignored unless directed
+ *                                  advertising is being used.
  * @param duration_ms           The duration of the advertisement procedure.
  *                                  On expiration, the procedure ends and a
  *                                  BLE_GAP_EVENT_ADV_COMPLETE event is
@@ -1962,7 +1969,7 @@ ble_gap_disc_fill_dflts(struct ble_gap_disc_params *disc_params)
 }
 
 static int
-ble_gap_disc_validate(uint8_t own_addr_type, 
+ble_gap_disc_validate(uint8_t own_addr_type,
                       const struct ble_gap_disc_params *disc_params)
 {
     if (disc_params == NULL) {
@@ -1981,17 +1988,17 @@ ble_gap_disc_validate(uint8_t own_addr_type,
 }
 
 /**
- * Performs the Limited or General Discovery Procedures (vol. 3, part C,
- * section 9.2.5 / 9.2.6).
+ * Performs the Limited or General Discovery Procedures.
  *
- * @param own_addr_type         This parameter is ignored unless active
- *                                  scanning is being used. The type of address
- *                                  the stack should use for itself when
- *                                  sending scan requests.  Valid values are:
+ * @param own_addr_type         The type of address the stack should use for
+ *                                  itself when sending scan requests.  Valid
+ *                                  values are:
  *                                      o BLE_ADDR_TYPE_PUBLIC
  *                                      o BLE_ADDR_TYPE_RANDOM
  *                                      o BLE_ADDR_TYPE_RPA_PUB_DEFAULT
  *                                      o BLE_ADDR_TYPE_RPA_RND_DEFAULT
+ *                                  This parameter is ignored unless active
+ *                                  scanning is being used.
  * @param duration_ms           The duration of the discovery procedure.
  *                                  On expiration, the procedure ends and a
  *                                  BLE_GAP_EVENT_DISC_COMPLETE event is
@@ -2011,7 +2018,7 @@ ble_gap_disc_validate(uint8_t own_addr_type,
 int
 ble_gap_disc(uint8_t own_addr_type, int32_t duration_ms,
              const struct ble_gap_disc_params *disc_params,
-             ble_gap_disc_fn *cb, void *cb_arg)
+             ble_gap_event_fn *cb, void *cb_arg)
 {
 #if !NIMBLE_OPT(ROLE_OBSERVER)
     return BLE_HS_ENOTSUP;
@@ -2057,8 +2064,8 @@ ble_gap_disc(uint8_t own_addr_type, int32_t duration_ms,
     }
 
     ble_gap_master.disc.limited = params.limited;
-    ble_gap_master.disc.cb = cb;
-    ble_gap_master.disc.cb_arg = cb_arg;
+    ble_gap_master.cb = cb;
+    ble_gap_master.cb_arg = cb_arg;
 
     BLE_HS_LOG(INFO, "GAP procedure initiated: discovery; ");
     ble_gap_log_disc(own_addr_type, duration_ms, &params);
@@ -2164,7 +2171,7 @@ ble_gap_conn_create_tx(uint8_t own_addr_type,
  *                                      o BLE_ADDR_TYPE_RANDOM
  *                                      o BLE_ADDR_TYPE_RPA_PUB_DEFAULT
  *                                      o BLE_ADDR_TYPE_RPA_RND_DEFAULT
- * @param peer_addr_type        The peer's identity address type.  One of:
+ * @param peer_addr_type        The peer's address type.  One of:
  *                                      o BLE_HCI_CONN_PEER_ADDR_PUBLIC
  *                                      o BLE_HCI_CONN_PEER_ADDR_RANDOM
  *                                      o BLE_HCI_CONN_PEER_ADDR_PUBLIC_IDENT
@@ -2180,6 +2187,14 @@ ble_gap_conn_create_tx(uint8_t own_addr_type,
  * @param conn_params           Additional arguments specifying the particulars
  *                                  of the connect procedure.  Specify null for
  *                                  default values.
+ * @param cb                    The callback to associate with this connect
+ *                                  procedure.  When the connect procedure
+ *                                  completes, the result is reported through
+ *                                  this callback.  If the connect procedure
+ *                                  succeeds, the connection inherits this
+ *                                  callback as its event-reporting mechanism.
+ * @param cb_arg                The optional argument to pass to the callback
+ *                                  function.
  *
  * @return                      0 on success; nonzero on failure.
  */
@@ -2234,8 +2249,8 @@ ble_gap_connect(uint8_t own_addr_type,
     ble_gap_log_conn(own_addr_type, peer_addr_type, peer_addr, conn_params);
     BLE_HS_LOG(INFO, "\n");
 
-    ble_gap_master.conn.cb = cb;
-    ble_gap_master.conn.cb_arg = cb_arg;
+    ble_gap_master.cb = cb;
+    ble_gap_master.cb_arg = cb_arg;
     ble_gap_master.conn.using_wl = peer_addr_type == BLE_GAP_ADDR_TYPE_WL;
     ble_gap_master.conn.our_addr_type = own_addr_type;
 
@@ -2428,13 +2443,15 @@ ble_gap_rx_param_req(struct hci_le_conn_param_req *evt)
 
     struct ble_gap_upd_params peer_params;
     struct ble_gap_upd_params self_params;
-    struct ble_gap_event_ctxt ctxt;
+    struct ble_gap_event event;
     struct ble_gap_snapshot snap;
     uint8_t reject_reason;
     int rc;
 
     reject_reason = 0; /* Silence warning. */
 
+    memset(&event, 0, sizeof event);
+    snap.desc = &event.conn_update_req.conn;
     rc = ble_gap_find_snapshot(evt->connection_handle, &snap);
     if (rc != 0) {
         /* We are not connected to the sender. */
@@ -2454,12 +2471,11 @@ ble_gap_rx_param_req(struct hci_le_conn_param_req *evt)
      */
     self_params = peer_params;
 
-    memset(&ctxt, 0, sizeof ctxt);
-    ctxt.desc = &snap.desc;
-    ctxt.conn_update_req.self_params = &self_params;
-    ctxt.conn_update_req.peer_params = &peer_params;
-    rc = ble_gap_call_event_cb(BLE_GAP_EVENT_CONN_UPDATE_REQ, &ctxt,
-                               snap.cb, snap.cb_arg);
+    memset(&event, 0, sizeof event);
+    event.type = BLE_GAP_EVENT_CONN_UPDATE_REQ;
+    event.conn_update_req.self_params = &self_params;
+    event.conn_update_req.peer_params = &peer_params;
+    rc = ble_gap_call_event_cb(&event, snap.cb, snap.cb_arg);
     if (rc != 0) {
         reject_reason = rc;
     }
@@ -2693,16 +2709,19 @@ ble_gap_encryption_initiate(uint16_t conn_handle,
 
 void
 ble_gap_passkey_event(uint16_t conn_handle,
-                      struct ble_gap_passkey_action *passkey_action)
+                      struct ble_gap_passkey_params *passkey_params)
 {
 #if !NIMBLE_OPT(SM)
     return;
 #endif
 
-    struct ble_gap_event_ctxt ctxt;
+    struct ble_gap_event event;
     struct ble_gap_snapshot snap;
     struct ble_hs_conn *conn;
 
+    memset(&event, 0, sizeof event);
+    snap.desc = &event.passkey.conn;
+
     ble_hs_lock();
 
     conn = ble_hs_conn_find(conn_handle);
@@ -2718,13 +2737,11 @@ ble_gap_passkey_event(uint16_t conn_handle,
     }
 
     BLE_HS_LOG(DEBUG, "send passkey action request %d\n",
-               passkey_action->action);
+               passkey_params->action);
 
-    memset(&ctxt, 0, sizeof ctxt);
-    ctxt.desc = &snap.desc;
-    ctxt.passkey_action = *passkey_action;
-    ble_gap_call_event_cb(BLE_GAP_EVENT_PASSKEY_ACTION, &ctxt,
-                          snap.cb, snap.cb_arg);
+    event.type = BLE_GAP_EVENT_PASSKEY_ACTION;
+    event.passkey.params = *passkey_params;
+    ble_gap_call_event_cb(&event, snap.cb, snap.cb_arg);
 }
 
 void
@@ -2734,24 +2751,24 @@ ble_gap_enc_event(uint16_t conn_handle, int status, int security_restored)
     return;
 #endif
 
-    struct ble_gap_event_ctxt ctxt;
+    struct ble_gap_event event;
     struct ble_gap_snapshot snap;
     int rc;
 
+    memset(&event, 0, sizeof event);
+    snap.desc = &event.enc_change.conn;
     rc = ble_gap_find_snapshot(conn_handle, &snap);
     if (rc != 0) {
         /* No longer connected. */
         return;
     }
 
-    memset(&ctxt, 0, sizeof ctxt);
-    ctxt.desc = &snap.desc;
-    ctxt.enc_change.status = status;
-    ble_gap_call_event_cb(BLE_GAP_EVENT_ENC_CHANGE, &ctxt,
-                          snap.cb, snap.cb_arg);
+    event.type = BLE_GAP_EVENT_ENC_CHANGE;
+    event.enc_change.status = status;
+    ble_gap_call_event_cb(&event, snap.cb, snap.cb_arg);
 
     if (status == 0 && security_restored) {
-        BLE_HS_DBG_ASSERT(snap.desc.sec_state.bonded);
+        BLE_HS_DBG_ASSERT(snap.desc->sec_state.bonded);
         ble_gatts_bonding_restored(conn_handle);
     }
 }
@@ -2768,23 +2785,24 @@ ble_gap_notify_event(uint16_t conn_handle, uint16_t attr_handle,
     return;
 #endif
 
-    struct ble_gap_event_ctxt ctxt;
+    struct ble_gap_event event;
     struct ble_gap_snapshot snap;
     int rc;
 
+    memset(&event, 0, sizeof event);
+    snap.desc = &event.notify.conn;
     rc = ble_gap_find_snapshot(conn_handle, &snap);
     if (rc != 0) {
         /* No longer connected. */
         return;
     }
 
-    memset(&ctxt, 0, sizeof ctxt);
-    ctxt.desc = &snap.desc;
-    ctxt.notify.attr_handle = attr_handle;
-    ctxt.notify.attr_data = attr_data;
-    ctxt.notify.attr_len = attr_len;
-    ctxt.notify.indication = is_indication;
-    ble_gap_call_event_cb(BLE_GAP_EVENT_NOTIFY, &ctxt, snap.cb, snap.cb_arg);
+    event.type = BLE_GAP_EVENT_NOTIFY;
+    event.notify.attr_handle = attr_handle;
+    event.notify.attr_data = attr_data;
+    event.notify.attr_len = attr_len;
+    event.notify.indication = is_indication;
+    ble_gap_call_event_cb(&event, snap.cb, snap.cb_arg);
 }
 
 /*****************************************************************************

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/27445b80/net/nimble/host/src/ble_gap_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gap_priv.h b/net/nimble/host/src/ble_gap_priv.h
index 43030fd..1cb48b5 100644
--- a/net/nimble/host/src/ble_gap_priv.h
+++ b/net/nimble/host/src/ble_gap_priv.h
@@ -81,7 +81,7 @@ int ble_gap_rx_l2cap_update_req(uint16_t conn_handle,
 void ble_gap_enc_event(uint16_t conn_handle, int status,
                        int security_restored);
 void ble_gap_passkey_event(uint16_t conn_handle,
-                           struct ble_gap_passkey_action *passkey_action);
+                           struct ble_gap_passkey_params *passkey_params);
 void ble_gap_notify_event(uint16_t conn_handle, uint16_t attr_handle,
                           void *attr_data, uint16_t attr_len,
                           int is_indication);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/27445b80/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 04ff94f..825365b 100644
--- a/net/nimble/host/src/ble_gattc.c
+++ b/net/nimble/host/src/ble_gattc.c
@@ -3579,7 +3579,7 @@ ble_gattc_write_reliable_rx_exec(struct ble_gattc_proc *proc, int status)
 }
 
 /**
- * Initiates GATT procedure: Write Long Characteristic Values.
+ * Initiates GATT procedure: Reliable Writes.
  *
  * @param conn_handle           The connection over which to execute the
  *                                  procedure.

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/27445b80/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 e3f4bcb..b9f55ae 100644
--- a/net/nimble/host/src/ble_hs.c
+++ b/net/nimble/host/src/ble_hs.c
@@ -286,12 +286,11 @@ ble_hs_event_enqueue(struct os_event *ev)
 }
 
 /**
- * Sends a sequence of HCI commands to the controller.  This sequence of
- * commands is necessary for the host and controller to remain in sync.  This
- * function must be called before any other host functionality is used, but it
- * must be called after both the host and controller are initialized.
- * Typically, the host-parent-task calls this function at the top of its task
- * routine.
+ * Synchronizes the host with the controller by sending a sequence of HCI
+ * commands.  This function must be called before any other host functionality
+ * is used, but it must be called after both the host and controller are
+ * initialized.  Typically, the host-parent-task calls this function at the top
+ * of its task routine.
  *
  * @return                      0 on success; nonzero on error.
  */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/27445b80/net/nimble/host/src/ble_sm.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_sm.c b/net/nimble/host/src/ble_sm.c
index 3f3def0..6f77db2 100644
--- a/net/nimble/host/src/ble_sm.c
+++ b/net/nimble/host/src/ble_sm.c
@@ -824,9 +824,9 @@ ble_sm_process_result(uint16_t conn_handle, struct ble_sm_result *res)
         }
 
         if (res->app_status == 0 &&
-            res->passkey_action.action != BLE_SM_IOACT_NONE) {
+            res->passkey_params.action != BLE_SM_IOACT_NONE) {
 
-            ble_gap_passkey_event(conn_handle, &res->passkey_action);
+            ble_gap_passkey_event(conn_handle, &res->passkey_params);
         }
 
         /* Persist keys if bonding has successfully completed. */
@@ -1466,7 +1466,7 @@ ble_sm_pair_exec(struct ble_sm_proc *proc, struct ble_sm_result *res,
 
         ioact = ble_sm_io_action(proc);
         if (ble_sm_ioact_state(ioact) == proc->state) {
-            res->passkey_action.action = ioact;
+            res->passkey_params.action = ioact;
         }
     }
 
@@ -1575,7 +1575,7 @@ ble_sm_pair_rsp_rx(uint16_t conn_handle, uint8_t op, struct os_mbuf **om,
             proc->state = ble_sm_state_after_pair(proc);
             ioact = ble_sm_io_action(proc);
             if (ble_sm_ioact_state(ioact) == proc->state) {
-                res->passkey_action.action = ioact;
+                res->passkey_params.action = ioact;
             }
             if (ble_sm_proc_can_advance(proc)) {
                 res->execute = 1;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/27445b80/net/nimble/host/src/ble_sm_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_sm_priv.h b/net/nimble/host/src/ble_sm_priv.h
index 95b312b..fbc7139 100644
--- a/net/nimble/host/src/ble_sm_priv.h
+++ b/net/nimble/host/src/ble_sm_priv.h
@@ -276,7 +276,7 @@ struct ble_sm_proc {
 struct ble_sm_result {
     int app_status;
     uint8_t sm_err;
-    struct ble_gap_passkey_action passkey_action;
+    struct ble_gap_passkey_params passkey_params;
     void *state_arg;
     unsigned execute:1;
     unsigned enc_cb:1;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/27445b80/net/nimble/host/src/ble_sm_sc.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_sm_sc.c b/net/nimble/host/src/ble_sm_sc.c
index d98c93b..bb92a19 100644
--- a/net/nimble/host/src/ble_sm_sc.c
+++ b/net/nimble/host/src/ble_sm_sc.c
@@ -280,7 +280,7 @@ ble_sm_sc_gen_numcmp(struct ble_sm_proc *proc, struct ble_sm_result *res)
         pkb = ble_sm_sc_pub_key.u8;
     }
     res->app_status = ble_sm_alg_g2(pka, pkb, proc->randm, proc->rands,
-                                    &res->passkey_action.numcmp);
+                                    &res->passkey_params.numcmp);
     if (res->app_status != 0) {
         res->sm_err = BLE_SM_ERR_UNSPECIFIED;
         res->enc_cb = 1;
@@ -341,7 +341,7 @@ ble_sm_sc_random_exec(struct ble_sm_proc *proc, struct ble_sm_result *res)
         if (ble_sm_ioact_state(ioact) == proc->state &&
             !(proc->flags & BLE_SM_PROC_F_IO_INJECTED)) {
 
-            res->passkey_action.action = ioact;
+            res->passkey_params.action = ioact;
             BLE_HS_DBG_ASSERT(ioact == BLE_SM_IOACT_NUMCMP);
             ble_sm_sc_gen_numcmp(proc, res);
         }
@@ -423,7 +423,7 @@ ble_sm_sc_random_rx(struct ble_sm_proc *proc, struct ble_sm_result *res)
         if (ble_sm_ioact_state(ioact) == proc->state &&
             !(proc->flags & BLE_SM_PROC_F_IO_INJECTED)) {
 
-            res->passkey_action.action = ioact;
+            res->passkey_params.action = ioact;
             BLE_HS_DBG_ASSERT(ioact == BLE_SM_IOACT_NUMCMP);
             ble_sm_sc_gen_numcmp(proc, res);
         } else {
@@ -459,7 +459,7 @@ ble_sm_sc_public_key_exec(struct ble_sm_proc *proc, struct ble_sm_result *res,
 
     ioact = ble_sm_sc_io_action(proc);
     if (ble_sm_ioact_state(ioact) == BLE_SM_PROC_STATE_CONFIRM) {
-        res->passkey_action.action = ioact;
+        res->passkey_params.action = ioact;
     }
 
     if (!(proc->flags & BLE_SM_PROC_F_INITIATOR)) {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/27445b80/net/nimble/host/src/test/ble_att_svr_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_att_svr_test.c b/net/nimble/host/src/test/ble_att_svr_test.c
index a8db378..bb9910a 100644
--- a/net/nimble/host/src/test/ble_att_svr_test.c
+++ b/net/nimble/host/src/test/ble_att_svr_test.c
@@ -42,18 +42,17 @@ static uint8_t ble_att_svr_test_attr_n[1024];
 static int ble_att_svr_test_attr_n_len;
 
 static int
-ble_att_svr_test_misc_gap_cb(int event,
-                             struct ble_gap_event_ctxt *ctxt, void *arg)
+ble_att_svr_test_misc_gap_cb(struct ble_gap_event *event, void *arg)
 {
-    switch (event) {
+    switch (event->type) {
     case BLE_GAP_EVENT_NOTIFY:
-        ble_att_svr_test_n_conn_handle = ctxt->desc->conn_handle;
-        ble_att_svr_test_n_attr_handle = ctxt->notify.attr_handle;
-        TEST_ASSERT_FATAL(ctxt->notify.attr_len <=
+        ble_att_svr_test_n_conn_handle = event->notify.conn.conn_handle;
+        ble_att_svr_test_n_attr_handle = event->notify.attr_handle;
+        TEST_ASSERT_FATAL(event->notify.attr_len <=
                           sizeof ble_att_svr_test_attr_n);
-        ble_att_svr_test_attr_n_len = ctxt->notify.attr_len;
-        memcpy(ble_att_svr_test_attr_n, ctxt->notify.attr_data,
-               ctxt->notify.attr_len);
+        ble_att_svr_test_attr_n_len = event->notify.attr_len;
+        memcpy(ble_att_svr_test_attr_n, event->notify.attr_data,
+               event->notify.attr_len);
         break;
 
     default:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/27445b80/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 43a0269..51469a2 100644
--- a/net/nimble/host/src/test/ble_gap_test.c
+++ b/net/nimble/host/src/test/ble_gap_test.c
@@ -26,15 +26,14 @@
 #include "host/ble_hs_test.h"
 #include "ble_hs_test_util.h"
 
-static int ble_gap_test_conn_event;
+static int ble_gap_test_conn_event_type;
 static int ble_gap_test_conn_status;
 static struct ble_gap_conn_desc ble_gap_test_conn_desc;
 static void *ble_gap_test_conn_arg;
 static struct ble_gap_upd_params ble_gap_test_conn_peer_params;
 static struct ble_gap_upd_params ble_gap_test_conn_self_params;
 
-static int ble_gap_test_disc_event;
-static int ble_gap_test_disc_status;
+static int ble_gap_test_disc_event_type;
 static struct ble_gap_disc_desc ble_gap_test_disc_desc;
 static void *ble_gap_test_disc_arg;
 
@@ -55,13 +54,12 @@ ble_gap_test_util_update_in_progress(uint16_t conn_handle)
 static void
 ble_gap_test_util_reset_cb_info(void)
 {
-    ble_gap_test_conn_event = -1;
+    ble_gap_test_conn_event_type = -1;
     ble_gap_test_conn_status = -1;
     memset(&ble_gap_test_conn_desc, 0xff, sizeof ble_gap_test_conn_desc);
     ble_gap_test_conn_arg = (void *)-1;
 
-    ble_gap_test_disc_event = -1;
-    ble_gap_test_disc_status = -1;
+    ble_gap_test_disc_event_type = -1;
     memset(&ble_gap_test_disc_desc, 0xff, sizeof ble_gap_test_disc_desc);
     ble_gap_test_disc_arg = (void *)-1;
 }
@@ -74,44 +72,46 @@ ble_gap_test_util_init(void)
     ble_gap_test_util_reset_cb_info();
 }
 
-static void
-ble_gap_test_util_disc_cb(int event, int status,
-                          struct ble_gap_disc_desc *desc, void *arg)
+static int
+ble_gap_test_util_disc_cb(struct ble_gap_event *event, void *arg)
 {
-    ble_gap_test_disc_event = event;
-    ble_gap_test_disc_status = status;
-    ble_gap_test_disc_desc = *desc;
+    ble_gap_test_disc_event_type = event->type;
+    ble_gap_test_disc_desc = event->disc;
     ble_gap_test_disc_arg = arg;
+
+    return 0;
 }
 
 static int
-ble_gap_test_util_connect_cb(int event, struct ble_gap_event_ctxt *ctxt,
-                             void *arg)
+ble_gap_test_util_connect_cb(struct ble_gap_event *event, void *arg)
 {
     int *fail_reason;
 
-    ble_gap_test_conn_event = event;
-    ble_gap_test_conn_desc = *ctxt->desc;
+    ble_gap_test_conn_event_type = event->type;
     ble_gap_test_conn_arg = arg;
 
-    switch (event) {
+    switch (event->type) {
     case BLE_GAP_EVENT_CONNECT:
-        ble_gap_test_conn_status = ctxt->connect.status;
+        ble_gap_test_conn_status = event->connect.status;
+        ble_gap_test_conn_desc = event->connect.conn;
         break;
 
     case BLE_GAP_EVENT_DISCONNECT:
-        ble_gap_test_conn_status = ctxt->disconnect.reason;
+        ble_gap_test_conn_status = event->disconnect.reason;
+        ble_gap_test_conn_desc = event->disconnect.conn;
         break;
 
     case BLE_GAP_EVENT_CONN_UPDATE:
-        ble_gap_test_conn_status = ctxt->conn_update.status;
+        ble_gap_test_conn_status = event->conn_update.status;
+        ble_gap_test_conn_desc = event->conn_update.conn;
         break;
 
     case BLE_GAP_EVENT_CONN_CANCEL:
         break;
 
     case BLE_GAP_EVENT_TERM_FAILURE:
-        ble_gap_test_conn_status = ctxt->term_failure.status;
+        ble_gap_test_conn_status = event->term_failure.status;
+        ble_gap_test_conn_desc = event->term_failure.conn;
         break;
 
     case BLE_GAP_EVENT_ADV_COMPLETE:
@@ -119,8 +119,9 @@ ble_gap_test_util_connect_cb(int event, struct ble_gap_event_ctxt *ctxt,
         break;
 
     case BLE_GAP_EVENT_CONN_UPDATE_REQ:
-        ble_gap_test_conn_peer_params = *ctxt->conn_update_req.peer_params;
-        *ctxt->conn_update_req.self_params = ble_gap_test_conn_self_params;
+        ble_gap_test_conn_peer_params = *event->conn_update_req.peer_params;
+        *event->conn_update_req.self_params = ble_gap_test_conn_self_params;
+        ble_gap_test_conn_desc = event->conn_update.conn;
 
         fail_reason = arg;
         if (fail_reason == NULL) {
@@ -532,7 +533,7 @@ ble_gap_test_util_disc(uint8_t own_addr_type,
         TEST_ASSERT(ble_gap_master_in_progress());
         ble_gap_rx_adv_report(desc);
     } else {
-        TEST_ASSERT(ble_gap_test_disc_status == -1);
+        TEST_ASSERT(ble_gap_test_disc_event_type == -1);
     }
 
     if (cmd_fail_idx > 0) {
@@ -632,8 +633,7 @@ TEST_CASE(ble_gap_test_case_disc_good)
         ble_gap_test_util_disc(own_addr_type, &disc_params, &desc, -1, 0);
 
         TEST_ASSERT(ble_gap_master_in_progress());
-        TEST_ASSERT(ble_gap_test_disc_event == BLE_GAP_EVENT_DISC_SUCCESS);
-        TEST_ASSERT(ble_gap_test_disc_status == 0);
+        TEST_ASSERT(ble_gap_test_disc_event_type == BLE_GAP_EVENT_DISC);
         TEST_ASSERT(ble_gap_test_disc_desc.event_type ==
                     BLE_HCI_ADV_TYPE_ADV_IND);
         TEST_ASSERT(ble_gap_test_disc_desc.addr_type ==
@@ -675,7 +675,7 @@ TEST_CASE(ble_gap_test_case_disc_ltd_mismatch)
     TEST_ASSERT(ble_gap_master_in_progress());
 
     /* Verify that the report was ignored because of a mismatched LTD flag. */
-    TEST_ASSERT(ble_gap_test_disc_event == -1);
+    TEST_ASSERT(ble_gap_test_disc_event_type == -1);
 
     /* Stop the scan and swap the flags. */
     rc = ble_hs_test_util_disc_cancel(0);
@@ -691,7 +691,7 @@ TEST_CASE(ble_gap_test_case_disc_ltd_mismatch)
     /* This time we should have reported the advertisement; general discovery
      * hears everything.
      */
-    TEST_ASSERT(ble_gap_test_disc_event == BLE_GAP_EVENT_DISC_SUCCESS);
+    TEST_ASSERT(ble_gap_test_disc_event_type == BLE_GAP_EVENT_DISC);
 }
 
 TEST_CASE(ble_gap_test_case_disc_hci_fail)
@@ -819,7 +819,7 @@ TEST_CASE(ble_gap_test_case_conn_dir_good)
 
     TEST_ASSERT(!ble_gap_master_in_progress());
 
-    TEST_ASSERT(ble_gap_test_conn_event == BLE_GAP_EVENT_CONNECT);
+    TEST_ASSERT(ble_gap_test_conn_event_type == BLE_GAP_EVENT_CONNECT);
     TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2);
     TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr, peer_addr, 6) == 0);
 
@@ -924,7 +924,7 @@ TEST_CASE(ble_gap_test_case_conn_cancel_good)
 
     ble_gap_test_util_conn_cancel(peer_addr, 0);
 
-    TEST_ASSERT(ble_gap_test_conn_event == BLE_GAP_EVENT_CONN_CANCEL);
+    TEST_ASSERT(ble_gap_test_conn_event_type == BLE_GAP_EVENT_CONN_CANCEL);
     TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == BLE_HS_CONN_HANDLE_NONE);
 }
 
@@ -940,7 +940,7 @@ TEST_CASE(ble_gap_test_case_conn_cancel_ctlr_fail)
     /* Make sure the host didn't invoke the application callback.  The cancel
      * failure was indicated via the return code from the gap call.
      */
-    TEST_ASSERT(ble_gap_test_conn_event == -1);
+    TEST_ASSERT(ble_gap_test_conn_event_type == -1);
 
     /* Allow connection complete to succeed. */
     memset(&evt, 0, sizeof evt);
@@ -954,7 +954,7 @@ TEST_CASE(ble_gap_test_case_conn_cancel_ctlr_fail)
 
     TEST_ASSERT(!ble_gap_master_in_progress());
 
-    TEST_ASSERT(ble_gap_test_conn_event == BLE_GAP_EVENT_CONNECT);
+    TEST_ASSERT(ble_gap_test_conn_event_type == BLE_GAP_EVENT_CONNECT);
     TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2);
     TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr,
                        peer_addr, 6) == 0);
@@ -988,7 +988,7 @@ ble_gap_test_util_terminate(uint8_t *peer_addr, uint8_t hci_status)
     /* Reset the callback event code; we don't care about the successful
      * connection in this test.
      */
-    ble_gap_test_conn_event = -1;
+    ble_gap_test_conn_event_type = -1;
 
     /* Terminate the connection. */
     rc = ble_hs_test_util_conn_terminate(2, hci_status);
@@ -1024,7 +1024,7 @@ TEST_CASE(ble_gap_test_case_conn_terminate_good)
 
     ble_gap_test_util_terminate(peer_addr, 0);
 
-    TEST_ASSERT(ble_gap_test_conn_event == BLE_GAP_EVENT_DISCONNECT);
+    TEST_ASSERT(ble_gap_test_conn_event_type == BLE_GAP_EVENT_DISCONNECT);
     TEST_ASSERT(ble_gap_test_conn_status ==
                 BLE_HS_HCI_ERR(BLE_ERR_CONN_TERM_LOCAL));
     TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2);
@@ -1064,7 +1064,7 @@ TEST_CASE(ble_gap_test_case_conn_terminate_ctlr_fail)
     evt.reason = 0;
     ble_gap_rx_disconn_complete(&evt);
 
-    TEST_ASSERT(ble_gap_test_conn_event == BLE_GAP_EVENT_TERM_FAILURE);
+    TEST_ASSERT(ble_gap_test_conn_event_type == BLE_GAP_EVENT_TERM_FAILURE);
     TEST_ASSERT(ble_gap_test_conn_status ==
                 BLE_HS_HCI_ERR(BLE_ERR_UNSUPPORTED));
     TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2);
@@ -1083,7 +1083,7 @@ TEST_CASE(ble_gap_test_case_conn_terminate_hci_fail)
 
     ble_gap_test_util_terminate(peer_addr, BLE_ERR_REPEATED_ATTEMPTS);
 
-    TEST_ASSERT(ble_gap_test_conn_event == -1);
+    TEST_ASSERT(ble_gap_test_conn_event_type == -1);
     TEST_ASSERT(ble_hs_atomic_conn_flags(2, NULL) == 0);
     TEST_ASSERT(!ble_gap_master_in_progress());
 }
@@ -1456,7 +1456,7 @@ TEST_CASE(ble_gap_test_case_adv_good)
 
             if (c != BLE_GAP_CONN_MODE_NON) {
                 TEST_ASSERT(!ble_gap_adv_active());
-                TEST_ASSERT(ble_gap_test_conn_event == BLE_GAP_EVENT_CONNECT);
+                TEST_ASSERT(ble_gap_test_conn_event_type == BLE_GAP_EVENT_CONNECT);
                 TEST_ASSERT(ble_gap_test_conn_status == 0);
                 TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2);
                 TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr,
@@ -1479,7 +1479,7 @@ TEST_CASE(ble_gap_test_case_adv_ctlr_fail)
                                   peer_addr, c, d, BLE_ERR_DIR_ADV_TMO, -1, 0);
 
             TEST_ASSERT(!ble_gap_adv_active());
-            TEST_ASSERT(ble_gap_test_conn_event == BLE_GAP_EVENT_ADV_COMPLETE);
+            TEST_ASSERT(ble_gap_test_conn_event_type == BLE_GAP_EVENT_ADV_COMPLETE);
             TEST_ASSERT(ble_gap_test_conn_desc.conn_handle ==
                         BLE_HS_CONN_HANDLE_NONE);
             TEST_ASSERT(ble_gap_test_conn_arg == NULL);
@@ -1509,7 +1509,7 @@ TEST_CASE(ble_gap_test_case_adv_hci_fail)
                                       c, d, 0, fail_idx, BLE_ERR_UNSUPPORTED);
 
                 TEST_ASSERT(!ble_gap_adv_active());
-                TEST_ASSERT(ble_gap_test_conn_event == -1);
+                TEST_ASSERT(ble_gap_test_conn_event_type == -1);
             }
         }
     }
@@ -1565,7 +1565,7 @@ TEST_CASE(ble_gap_test_case_stop_adv_good)
             ble_gap_test_util_stop_adv(BLE_ADDR_TYPE_PUBLIC, peer_addr, c, d,
                                        -1, 0);
             TEST_ASSERT(!ble_gap_adv_active());
-            TEST_ASSERT(ble_gap_test_conn_event == -1);
+            TEST_ASSERT(ble_gap_test_conn_event_type == -1);
             TEST_ASSERT(ble_gap_test_conn_status == -1);
             TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == (uint16_t)-1);
             TEST_ASSERT(ble_gap_test_conn_arg == (void *)-1);
@@ -1584,7 +1584,7 @@ TEST_CASE(ble_gap_test_case_stop_adv_hci_fail)
             ble_gap_test_util_stop_adv(BLE_ADDR_TYPE_PUBLIC, peer_addr, c, d,
                                        0, BLE_ERR_UNSUPPORTED);
             TEST_ASSERT(ble_gap_adv_active());
-            TEST_ASSERT(ble_gap_test_conn_event == -1);
+            TEST_ASSERT(ble_gap_test_conn_event_type == -1);
             TEST_ASSERT(ble_gap_test_conn_status == -1);
             TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == (uint16_t)-1);
             TEST_ASSERT(ble_gap_test_conn_arg == (void *)-1);
@@ -1643,7 +1643,7 @@ ble_gap_test_util_update(struct ble_gap_upd_params *params,
 
     TEST_ASSERT(!ble_gap_master_in_progress());
 
-    TEST_ASSERT(ble_gap_test_conn_event == BLE_GAP_EVENT_CONN_UPDATE);
+    TEST_ASSERT(ble_gap_test_conn_event_type == BLE_GAP_EVENT_CONN_UPDATE);
     TEST_ASSERT(ble_gap_test_conn_status == 0);
     TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2);
     TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr, peer_addr, 6) == 0);
@@ -1657,7 +1657,7 @@ ble_gap_test_util_update(struct ble_gap_upd_params *params,
     return;
 
 fail:
-    TEST_ASSERT(ble_gap_test_conn_event == BLE_GAP_EVENT_CONN_UPDATE);
+    TEST_ASSERT(ble_gap_test_conn_event_type == BLE_GAP_EVENT_CONN_UPDATE);
     TEST_ASSERT(ble_gap_test_conn_status == status);
     TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2);
     TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr, peer_addr, 6) == 0);
@@ -1688,7 +1688,7 @@ ble_gap_test_util_update_peer(uint8_t status,
 
     TEST_ASSERT(!ble_gap_master_in_progress());
 
-    TEST_ASSERT(ble_gap_test_conn_event == BLE_GAP_EVENT_CONN_UPDATE);
+    TEST_ASSERT(ble_gap_test_conn_event_type == BLE_GAP_EVENT_CONN_UPDATE);
     TEST_ASSERT(ble_gap_test_conn_status == BLE_HS_HCI_ERR(status));
     TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2);
     TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr,
@@ -1743,7 +1743,7 @@ ble_gap_test_util_update_req_pos(struct ble_gap_upd_params *peer_params,
     TEST_ASSERT(!ble_gap_master_in_progress());
     TEST_ASSERT(!ble_gap_test_util_update_in_progress(2));
 
-    TEST_ASSERT(ble_gap_test_conn_event == BLE_GAP_EVENT_CONN_UPDATE);
+    TEST_ASSERT(ble_gap_test_conn_event_type == BLE_GAP_EVENT_CONN_UPDATE);
     TEST_ASSERT(ble_gap_test_conn_status == 0);
     TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2);
     TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr, peer_addr, 6) == 0);
@@ -1755,7 +1755,7 @@ ble_gap_test_util_update_req_pos(struct ble_gap_upd_params *peer_params,
     return;
 
 hci_fail:
-    TEST_ASSERT(ble_gap_test_conn_event == BLE_GAP_EVENT_CONN_UPDATE);
+    TEST_ASSERT(ble_gap_test_conn_event_type == BLE_GAP_EVENT_CONN_UPDATE);
     TEST_ASSERT(ble_gap_test_conn_status == BLE_HS_HCI_ERR(hci_status));
     TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2);
     TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr, peer_addr, 6) == 0);
@@ -1804,7 +1804,7 @@ ble_gap_test_util_update_req_neg(struct ble_gap_upd_params *peer_params,
     return;
 
 hci_fail:
-    TEST_ASSERT(ble_gap_test_conn_event == BLE_GAP_EVENT_CONN_UPDATE);
+    TEST_ASSERT(ble_gap_test_conn_event_type == BLE_GAP_EVENT_CONN_UPDATE);
     TEST_ASSERT(ble_gap_test_conn_status == BLE_HS_HCI_ERR(hci_status));
     TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2);
     TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr, peer_addr, 6) == 0);
@@ -1879,7 +1879,7 @@ ble_gap_test_util_update_req_concurrent(
     TEST_ASSERT(!ble_gap_master_in_progress());
     TEST_ASSERT(!ble_gap_test_util_update_in_progress(2));
 
-    TEST_ASSERT(ble_gap_test_conn_event == BLE_GAP_EVENT_CONN_UPDATE);
+    TEST_ASSERT(ble_gap_test_conn_event_type == BLE_GAP_EVENT_CONN_UPDATE);
     TEST_ASSERT(ble_gap_test_conn_status == 0);
     TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2);
     TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr, peer_addr, 6) == 0);
@@ -1891,7 +1891,7 @@ ble_gap_test_util_update_req_concurrent(
     return;
 
 hci_fail:
-    TEST_ASSERT(ble_gap_test_conn_event == BLE_GAP_EVENT_CONN_UPDATE);
+    TEST_ASSERT(ble_gap_test_conn_event_type == BLE_GAP_EVENT_CONN_UPDATE);
     TEST_ASSERT(ble_gap_test_conn_status == BLE_HS_HCI_ERR(fail_status));
     TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2);
     TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr, peer_addr, 6) == 0);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/27445b80/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 fe701d8..9723b90 100644
--- a/net/nimble/host/src/test/ble_hs_test_util.c
+++ b/net/nimble/host/src/test/ble_hs_test_util.c
@@ -377,7 +377,7 @@ ble_hs_test_util_connect(uint8_t own_addr_type, uint8_t peer_addr_type,
         ack_status);
 
     rc = ble_gap_connect(own_addr_type, peer_addr_type, peer_addr,
-                               params, cb, cb_arg);
+                         params, cb, cb_arg);
 
     TEST_ASSERT(rc == BLE_HS_HCI_ERR(ack_status));
 
@@ -441,7 +441,7 @@ ble_hs_test_util_exp_hci_status(int cmd_idx, int fail_idx, uint8_t fail_status)
 int
 ble_hs_test_util_disc(uint8_t own_addr_type, int32_t duration_ms,
                       const struct ble_gap_disc_params *disc_params,
-                      ble_gap_disc_fn *cb, void *cb_arg, int fail_idx,
+                      ble_gap_event_fn *cb, void *cb_arg, int fail_idx,
                       uint8_t fail_status)
 {
     int rc;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/27445b80/net/nimble/host/src/test/ble_hs_test_util.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_hs_test_util.h b/net/nimble/host/src/test/ble_hs_test_util.h
index d54c8aa..8d2221a 100644
--- a/net/nimble/host/src/test/ble_hs_test_util.h
+++ b/net/nimble/host/src/test/ble_hs_test_util.h
@@ -76,7 +76,7 @@ int ble_hs_test_util_exp_hci_status(int cmd_idx, int fail_idx,
                                     uint8_t fail_status);
 int ble_hs_test_util_disc(uint8_t own_addr_type, int32_t duration_ms,
                           const struct ble_gap_disc_params *disc_params,
-                          ble_gap_disc_fn *cb, void *cb_arg, int fail_idx,
+                          ble_gap_event_fn *cb, void *cb_arg, int fail_idx,
                           uint8_t fail_status);
 int ble_hs_test_util_disc_cancel(uint8_t ack_status);
 int ble_hs_test_util_adv_set_fields(struct ble_hs_adv_fields *adv_fields,

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/27445b80/net/nimble/host/src/test/ble_l2cap_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_l2cap_test.c b/net/nimble/host/src/test/ble_l2cap_test.c
index 1e373f5..b651325 100644
--- a/net/nimble/host/src/test/ble_l2cap_test.c
+++ b/net/nimble/host/src/test/ble_l2cap_test.c
@@ -480,12 +480,11 @@ TEST_CASE(ble_l2cap_test_case_sig_unsol_rsp)
  *****************************************************************************/
 
 static int
-ble_l2cap_test_util_conn_cb(int event, struct ble_gap_event_ctxt *ctxt,
-                            void *arg)
+ble_l2cap_test_util_conn_cb(struct ble_gap_event *event, void *arg)
 {
     int *accept;
 
-    switch (event) {
+    switch (event->type) {
     case BLE_GAP_EVENT_L2CAP_UPDATE_REQ:
         accept = arg;
         return !*accept;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/27445b80/net/nimble/host/src/test/ble_os_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_os_test.c b/net/nimble/host/src/test/ble_os_test.c
index 7aae46e..4df85d9 100644
--- a/net/nimble/host/src/test/ble_os_test.c
+++ b/net/nimble/host/src/test/ble_os_test.c
@@ -43,7 +43,7 @@ static uint8_t ble_os_test_peer_addr[6] = { 1, 2, 3, 4, 5, 6 };
 
 static void ble_os_test_app_task_handler(void *arg);
 
-static int ble_os_test_gap_event;
+static int ble_os_test_gap_event_type;
 
 static void
 ble_os_test_init_app_task(void)
@@ -91,20 +91,20 @@ ble_os_test_misc_conn_exists(uint16_t conn_handle)
 }
 
 static int
-ble_gap_direct_connect_test_connect_cb(int event,
-                                       struct ble_gap_event_ctxt *ctxt,
-                                       void *arg)
+ble_gap_direct_connect_test_connect_cb(struct ble_gap_event *event, void *arg)
 {
     int *cb_called;
 
     cb_called = arg;
     *cb_called = 1;
 
-    TEST_ASSERT(event == BLE_GAP_EVENT_CONNECT);
-    TEST_ASSERT(ctxt->connect.status == 0);
-    TEST_ASSERT(ctxt->desc->conn_handle == 2);
-    TEST_ASSERT(ctxt->desc->peer_id_addr_type == BLE_ADDR_TYPE_PUBLIC);
-    TEST_ASSERT(memcmp(ctxt->desc->peer_id_addr, ble_os_test_peer_addr, 6) == 0);
+    TEST_ASSERT(event->type == BLE_GAP_EVENT_CONNECT);
+    TEST_ASSERT(event->connect.status == 0);
+    TEST_ASSERT(event->connect.conn.conn_handle == 2);
+    TEST_ASSERT(event->connect.conn.peer_id_addr_type ==
+                BLE_ADDR_TYPE_PUBLIC);
+    TEST_ASSERT(memcmp(event->connect.conn.peer_id_addr,
+                       ble_os_test_peer_addr, 6) == 0);
 
     return 0;
 }
@@ -164,21 +164,21 @@ TEST_CASE(ble_gap_direct_connect_test_case)
     os_start();
 }
 
-static void
-ble_gap_gen_disc_test_connect_cb(int event, int status,
-                                 struct ble_gap_disc_desc *desc, void *arg)
+static int
+ble_os_disc_test_cb(struct ble_gap_event *event, void *arg)
 {
     int *cb_called;
 
     cb_called = arg;
     *cb_called = 1;
 
-    TEST_ASSERT(event == BLE_GAP_EVENT_DISC_COMPLETE);
-    TEST_ASSERT(status == 0);
+    TEST_ASSERT(event->type == BLE_GAP_EVENT_DISC_COMPLETE);
+
+    return 0;
 }
 
 static void
-ble_gap_gen_disc_test_task_handler(void *arg)
+ble_os_disc_test_task_handler(void *arg)
 {
     struct ble_gap_disc_params disc_params;
     int cb_called;
@@ -203,7 +203,7 @@ ble_gap_gen_disc_test_task_handler(void *arg)
     /* Initiate the general discovery procedure with a 300 ms timeout. */
     memset(&disc_params, 0, sizeof disc_params);
     rc = ble_hs_test_util_disc(BLE_ADDR_TYPE_PUBLIC, 300, &disc_params,
-                               ble_gap_gen_disc_test_connect_cb,
+                               ble_os_disc_test_cb,
                                &cb_called, 0, 0);
     TEST_ASSERT(rc == 0);
     TEST_ASSERT(!ble_os_test_misc_conn_exists(BLE_HS_CONN_HANDLE_NONE));
@@ -234,13 +234,13 @@ ble_gap_gen_disc_test_task_handler(void *arg)
     tu_restart();
 }
 
-TEST_CASE(ble_gap_gen_disc_test_case)
+TEST_CASE(ble_os_disc_test_case)
 {
     ble_os_test_misc_init();
 
     os_task_init(&ble_os_test_task,
-                 "ble_gap_gen_disc_test_task",
-                 ble_gap_gen_disc_test_task_handler, NULL,
+                 "ble_os_disc_test_task",
+                 ble_os_disc_test_task_handler, NULL,
                  BLE_OS_TEST_TASK_PRIO, OS_WAIT_FOREVER, ble_os_test_stack,
                  OS_STACK_ALIGN(BLE_OS_TEST_STACK_SIZE));
 
@@ -248,15 +248,15 @@ TEST_CASE(ble_gap_gen_disc_test_case)
 }
 
 static int
-ble_gap_terminate_cb(int event, struct ble_gap_event_ctxt *ctxt, void *arg)
+ble_gap_terminate_cb(struct ble_gap_event *event, void *arg)
 {
     int *disconn_handle;
 
-    ble_os_test_gap_event = event;
+    ble_os_test_gap_event_type = event->type;
 
-    if (event == BLE_GAP_EVENT_DISCONNECT) {
+    if (event->type == BLE_GAP_EVENT_DISCONNECT) {
         disconn_handle = arg;
-        *disconn_handle = ctxt->desc->conn_handle;
+        *disconn_handle = event->disconnect.conn.conn_handle;
     }
 
     return 0;
@@ -291,8 +291,8 @@ ble_gap_terminate_test_task_handler(void *arg)
 
     /* Create two direct connections. */
     ble_hs_test_util_connect(BLE_ADDR_TYPE_PUBLIC, BLE_ADDR_TYPE_PUBLIC,
-                                   addr1, NULL, ble_gap_terminate_cb,
-                                   &disconn_handle, 0);
+                             addr1, NULL, ble_gap_terminate_cb,
+                             &disconn_handle, 0);
     memset(&conn_evt, 0, sizeof conn_evt);
     conn_evt.subevent_code = BLE_HCI_LE_SUBEV_CONN_COMPLETE;
     conn_evt.status = BLE_ERR_SUCCESS;
@@ -322,7 +322,7 @@ ble_gap_terminate_test_task_handler(void *arg)
     disconn_evt.status = 0;
     disconn_evt.reason = BLE_ERR_REM_USER_CONN_TERM;
     ble_hs_test_util_rx_disconn_complete_event(&disconn_evt);
-    TEST_ASSERT(ble_os_test_gap_event == BLE_GAP_EVENT_DISCONNECT);
+    TEST_ASSERT(ble_os_test_gap_event_type == BLE_GAP_EVENT_DISCONNECT);
     TEST_ASSERT(disconn_handle == 1);
     TEST_ASSERT_FATAL(!ble_os_test_misc_conn_exists(1));
     TEST_ASSERT_FATAL(ble_os_test_misc_conn_exists(2));
@@ -334,7 +334,7 @@ ble_gap_terminate_test_task_handler(void *arg)
     disconn_evt.status = 0;
     disconn_evt.reason = BLE_ERR_REM_USER_CONN_TERM;
     ble_hs_test_util_rx_disconn_complete_event(&disconn_evt);
-    TEST_ASSERT(ble_os_test_gap_event == BLE_GAP_EVENT_DISCONNECT);
+    TEST_ASSERT(ble_os_test_gap_event_type == BLE_GAP_EVENT_DISCONNECT);
     TEST_ASSERT(disconn_handle == 2);
     TEST_ASSERT_FATAL(!ble_os_test_misc_conn_exists(1));
     TEST_ASSERT_FATAL(!ble_os_test_misc_conn_exists(2));
@@ -382,7 +382,7 @@ TEST_CASE(ble_gap_terminate_test_case)
 
 TEST_SUITE(ble_os_test_suite)
 {
-    ble_gap_gen_disc_test_case();
+    ble_os_disc_test_case();
     ble_gap_direct_connect_test_case();
     ble_gap_terminate_test_case();
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/27445b80/net/nimble/host/src/test/ble_sm_test_util.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_sm_test_util.c b/net/nimble/host/src/test/ble_sm_test_util.c
index 524e8f1..57080dd 100644
--- a/net/nimble/host/src/test/ble_sm_test_util.c
+++ b/net/nimble/host/src/test/ble_sm_test_util.c
@@ -30,7 +30,7 @@
 #include "ble_hs_test_util.h"
 #include "ble_sm_test_util.h"
 
-int ble_sm_test_gap_event;
+int ble_sm_test_gap_event_type;
 int ble_sm_test_gap_status;
 struct ble_gap_sec_state ble_sm_test_sec_state;
 
@@ -103,7 +103,7 @@ ble_sm_test_util_init(void)
     ble_hs_cfg.store_write_cb = ble_sm_test_util_store_write;
 
     ble_sm_test_store_obj_type = -1;
-    ble_sm_test_gap_event = -1;
+    ble_sm_test_gap_event_type = -1;
     ble_sm_test_gap_status = -1;
 
     memset(&ble_sm_test_sec_state, 0xff, sizeof ble_sm_test_sec_state);
@@ -261,29 +261,29 @@ ble_sm_test_util_init_good(struct ble_sm_test_params *params,
     }
 }
 
-struct ble_gap_passkey_action ble_sm_test_ioact;
+struct ble_gap_passkey_params ble_sm_test_ioact;
 
 int
-ble_sm_test_util_conn_cb(int event, struct ble_gap_event_ctxt *ctxt, void *arg)
+ble_sm_test_util_conn_cb(struct ble_gap_event *event, void *arg)
 {
     int rc;
 
-    switch (event) {
+    switch (event->type) {
     case BLE_GAP_EVENT_ENC_CHANGE:
-        ble_sm_test_gap_status = ctxt->enc_change.status;
-        ble_sm_test_sec_state = ctxt->desc->sec_state;
+        ble_sm_test_gap_status = event->enc_change.status;
+        ble_sm_test_sec_state = event->enc_change.conn.sec_state;
         rc = 0;
         break;
 
     case BLE_GAP_EVENT_PASSKEY_ACTION:
-        ble_sm_test_ioact = ctxt->passkey_action;
+        ble_sm_test_ioact = event->passkey.params;
         break;
 
     default:
         return 0;
     }
 
-    ble_sm_test_gap_event = event;
+    ble_sm_test_gap_event_type = event->type;
 
     return rc;
 }
@@ -1260,7 +1260,7 @@ ble_sm_test_util_peer_bonding_good(int send_enc_req,
     TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
 
     /* Verify that security callback was executed. */
-    TEST_ASSERT(ble_sm_test_gap_event == BLE_GAP_EVENT_ENC_CHANGE);
+    TEST_ASSERT(ble_sm_test_gap_event_type == BLE_GAP_EVENT_ENC_CHANGE);
     TEST_ASSERT(ble_sm_test_gap_status == 0);
     TEST_ASSERT(ble_sm_test_sec_state.encrypted);
     TEST_ASSERT(ble_sm_test_sec_state.authenticated ==
@@ -1383,7 +1383,7 @@ ble_sm_test_util_us_bonding_good(int send_enc_req, uint8_t our_addr_type,
     TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
 
     /* Verify that security callback was executed. */
-    TEST_ASSERT(ble_sm_test_gap_event == BLE_GAP_EVENT_ENC_CHANGE);
+    TEST_ASSERT(ble_sm_test_gap_event_type == BLE_GAP_EVENT_ENC_CHANGE);
     TEST_ASSERT(ble_sm_test_gap_status == 0);
     TEST_ASSERT(ble_sm_test_sec_state.encrypted);
     TEST_ASSERT(ble_sm_test_sec_state.authenticated ==
@@ -1442,7 +1442,7 @@ ble_sm_test_util_peer_fail_inval(
     TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
 
     /* Verify that security callback was not executed. */
-    TEST_ASSERT(ble_sm_test_gap_event == -1);
+    TEST_ASSERT(ble_sm_test_gap_event_type == -1);
     TEST_ASSERT(ble_sm_test_gap_status == -1);
 
     /* Verify that connection has correct security state. */
@@ -1519,7 +1519,7 @@ ble_sm_test_util_peer_lgcy_fail_confirm(
     TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
 
     /* Verify that security callback was executed. */
-    TEST_ASSERT(ble_sm_test_gap_event == BLE_GAP_EVENT_ENC_CHANGE);
+    TEST_ASSERT(ble_sm_test_gap_event_type == BLE_GAP_EVENT_ENC_CHANGE);
     TEST_ASSERT(ble_sm_test_gap_status ==
                 BLE_HS_SM_US_ERR(BLE_SM_ERR_CONFIRM_MISMATCH));
     TEST_ASSERT(!ble_sm_test_sec_state.encrypted);
@@ -1779,7 +1779,7 @@ ble_sm_test_util_us_lgcy_good_once(struct ble_sm_test_params *params)
     TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
 
     /* Verify that security callback was executed. */
-    TEST_ASSERT(ble_sm_test_gap_event == BLE_GAP_EVENT_ENC_CHANGE);
+    TEST_ASSERT(ble_sm_test_gap_event_type == BLE_GAP_EVENT_ENC_CHANGE);
     TEST_ASSERT(ble_sm_test_gap_status == 0);
     TEST_ASSERT(ble_sm_test_sec_state.encrypted);
     TEST_ASSERT(ble_sm_test_sec_state.authenticated == params->authenticated);
@@ -1905,7 +1905,7 @@ ble_sm_test_util_peer_lgcy_good_once(struct ble_sm_test_params *params)
     TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
 
     /* Verify that security callback was executed. */
-    TEST_ASSERT(ble_sm_test_gap_event == BLE_GAP_EVENT_ENC_CHANGE);
+    TEST_ASSERT(ble_sm_test_gap_event_type == BLE_GAP_EVENT_ENC_CHANGE);
     TEST_ASSERT(ble_sm_test_gap_status == 0);
     TEST_ASSERT(ble_sm_test_sec_state.encrypted);
     TEST_ASSERT(ble_sm_test_sec_state.authenticated ==
@@ -2090,7 +2090,7 @@ ble_sm_test_util_us_sc_good_once(struct ble_sm_test_params *params)
     TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
 
     /* Verify that security callback was executed. */
-    TEST_ASSERT(ble_sm_test_gap_event == BLE_GAP_EVENT_ENC_CHANGE);
+    TEST_ASSERT(ble_sm_test_gap_event_type == BLE_GAP_EVENT_ENC_CHANGE);
     TEST_ASSERT(ble_sm_test_gap_status == 0);
     TEST_ASSERT(ble_sm_test_sec_state.encrypted);
     TEST_ASSERT(ble_sm_test_sec_state.authenticated ==
@@ -2278,7 +2278,7 @@ ble_sm_test_util_peer_sc_good_once(struct ble_sm_test_params *params)
     TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
 
     /* Verify that security callback was executed. */
-    TEST_ASSERT(ble_sm_test_gap_event == BLE_GAP_EVENT_ENC_CHANGE);
+    TEST_ASSERT(ble_sm_test_gap_event_type == BLE_GAP_EVENT_ENC_CHANGE);
     TEST_ASSERT(ble_sm_test_gap_status == 0);
     TEST_ASSERT(ble_sm_test_sec_state.encrypted);
     TEST_ASSERT(ble_sm_test_sec_state.authenticated ==
@@ -2376,7 +2376,7 @@ ble_sm_test_util_us_fail_inval(struct ble_sm_test_params *params)
     TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
 
     /* Verify that security callback was not executed. */
-    TEST_ASSERT(ble_sm_test_gap_event == -1);
+    TEST_ASSERT(ble_sm_test_gap_event_type == -1);
     TEST_ASSERT(ble_sm_test_gap_status == -1);
 
     /* Verify that connection has correct security state. */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/27445b80/net/nimble/host/src/test/ble_sm_test_util.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_sm_test_util.h b/net/nimble/host/src/test/ble_sm_test_util.h
index 099ed28..3323be6 100644
--- a/net/nimble/host/src/test/ble_sm_test_util.h
+++ b/net/nimble/host/src/test/ble_sm_test_util.h
@@ -78,8 +78,7 @@ extern union ble_store_key ble_sm_test_store_key;
 extern union ble_store_value ble_sm_test_store_value;
 
 void ble_sm_test_util_init(void);
-int ble_sm_test_util_conn_cb(int event, struct ble_gap_event_ctxt *ctxt,
-                             void *arg);
+int ble_sm_test_util_conn_cb(struct ble_gap_event *ctxt, void *arg);
 void ble_sm_test_util_io_inject(struct ble_sm_test_passkey_info *passkey_info,
                                 uint8_t cur_sm_state);
 void ble_sm_test_util_io_inject_bad(uint16_t conn_handle,


[41/50] [abbrv] incubator-mynewt-core git commit: BLE Host - Clean up error codes.

Posted by cc...@apache.org.
BLE Host - Clean up error codes.


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

Branch: refs/heads/ble_hs_api
Commit: f1554a0b5dd6bc07593bdcd1351dcdc857de4624
Parents: 0ebad0f
Author: Christopher Collins <cc...@apache.org>
Authored: Tue Jul 5 12:18:03 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Jul 11 16:43:34 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/src/ble_att_svr.c           | 4 ++--
 net/nimble/host/src/test/ble_att_svr_test.c | 8 ++++----
 2 files changed, 6 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f1554a0b/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 8e57452..4d6fe15 100644
--- a/net/nimble/host/src/ble_att_svr.c
+++ b/net/nimble/host/src/ble_att_svr.c
@@ -271,12 +271,12 @@ ble_att_svr_check_security(uint16_t conn_handle, int is_read,
         /* XXX: Check security database; if required key present, respond with
          * insufficient encryption error code.
          */
-        *out_att_err = BLE_ATT_ERR_INSUFFICIENT_AUTHENT;
+        *out_att_err = BLE_ATT_ERR_INSUFFICIENT_AUTHEN;
         return BLE_HS_ATT_ERR(*out_att_err);
     }
 
     if (authen && !sec_state.authenticated) {
-        *out_att_err = BLE_ATT_ERR_INSUFFICIENT_AUTHENT;
+        *out_att_err = BLE_ATT_ERR_INSUFFICIENT_AUTHEN;
         return BLE_HS_ATT_ERR(*out_att_err);
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f1554a0b/net/nimble/host/src/test/ble_att_svr_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_att_svr_test.c b/net/nimble/host/src/test/ble_att_svr_test.c
index 38964b4..a8db378 100644
--- a/net/nimble/host/src/test/ble_att_svr_test.c
+++ b/net/nimble/host/src/test/ble_att_svr_test.c
@@ -1056,10 +1056,10 @@ TEST_CASE(ble_att_svr_test_read)
 
     rc = ble_hs_test_util_l2cap_rx_payload_flat(conn_handle, BLE_L2CAP_CID_ATT,
                                                 buf, sizeof buf);
-    TEST_ASSERT(rc == BLE_HS_ATT_ERR(BLE_ATT_ERR_INSUFFICIENT_AUTHENT));
+    TEST_ASSERT(rc == BLE_HS_ATT_ERR(BLE_ATT_ERR_INSUFFICIENT_AUTHEN));
     ble_att_svr_test_misc_verify_tx_err_rsp(BLE_ATT_OP_READ_REQ,
                                             req.barq_handle,
-                                            BLE_ATT_ERR_INSUFFICIENT_AUTHENT);
+                                            BLE_ATT_ERR_INSUFFICIENT_AUTHEN);
 
     /* Security check bypassed for local reads. */
     rc = ble_att_svr_read_local(req.barq_handle, &attr_data, &attr_len);
@@ -1299,10 +1299,10 @@ TEST_CASE(ble_att_svr_test_write)
 
     rc = ble_hs_test_util_l2cap_rx_payload_flat(conn_handle, BLE_L2CAP_CID_ATT,
                                                 buf, sizeof buf);
-    TEST_ASSERT(rc == BLE_HS_ATT_ERR(BLE_ATT_ERR_INSUFFICIENT_AUTHENT));
+    TEST_ASSERT(rc == BLE_HS_ATT_ERR(BLE_ATT_ERR_INSUFFICIENT_AUTHEN));
     ble_att_svr_test_misc_verify_tx_err_rsp(BLE_ATT_OP_WRITE_REQ,
                                             req.bawq_handle,
-                                            BLE_ATT_ERR_INSUFFICIENT_AUTHENT);
+                                            BLE_ATT_ERR_INSUFFICIENT_AUTHEN);
 
     /* Security check bypassed for local writes. */
     rc = ble_att_svr_write_local(req.bawq_handle, buf, sizeof buf);


[45/50] [abbrv] incubator-mynewt-core git commit: BLE Host - ble_gap_conn_rssi().

Posted by cc...@apache.org.
BLE Host - ble_gap_conn_rssi().


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

Branch: refs/heads/ble_hs_api
Commit: 44b45e97b14cd7b58a7394e96215d204fbb3878a
Parents: 1c8a135
Author: Christopher Collins <cc...@apache.org>
Authored: Fri Jul 8 13:22:42 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Jul 11 16:43:34 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/include/host/ble_gap.h |  1 +
 net/nimble/host/src/ble_gap.c          | 26 ++++++++++++++++++++++++++
 2 files changed, 27 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/44b45e97/net/nimble/host/include/host/ble_gap.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/ble_gap.h b/net/nimble/host/include/host/ble_gap.h
index 7577d6d..79868c5 100644
--- a/net/nimble/host/include/host/ble_gap.h
+++ b/net/nimble/host/include/host/ble_gap.h
@@ -457,5 +457,6 @@ int ble_gap_security_initiate(uint16_t conn_handle);
 int ble_gap_pair_initiate(uint16_t conn_handle);
 int ble_gap_encryption_initiate(uint16_t conn_handle, const uint8_t *ltk,
                                 uint16_t ediv, uint64_t rand_val, int auth);
+int ble_gap_conn_rssi(uint16_t conn_handle, int8_t *out_rssi);
 
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/44b45e97/net/nimble/host/src/ble_gap.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gap.c b/net/nimble/host/src/ble_gap.c
index 48285d6..73c9e42 100644
--- a/net/nimble/host/src/ble_gap.c
+++ b/net/nimble/host/src/ble_gap.c
@@ -2774,6 +2774,32 @@ ble_gap_enc_event(uint16_t conn_handle, int status, int security_restored)
 }
 
 /*****************************************************************************
+ * $rssi                                                                     *
+ *****************************************************************************/
+
+/**
+ * Retrieves the most-recently measured RSSI for the specified connection.  A
+ * connection's RSSI is updated whenever a data channel PDU is received.
+ *
+ * @param conn_handle           Specifies the connection to query.
+ * @param out_rssi              On success, the retrieved RSSI is written here.
+ *
+ * @return                      0 on success;
+ *                              A BLE host HCI return code if the controller
+ *                                  rejected the request;
+ *                              A BLE host core return code on unexpected
+ *                                  error.
+ */
+int
+ble_gap_conn_rssi(uint16_t conn_handle, int8_t *out_rssi)
+{
+    int rc;
+
+    rc = ble_hci_util_read_rssi(conn_handle, out_rssi);
+    return rc;
+}
+
+/*****************************************************************************
  * $notify                                                                   *
  *****************************************************************************/
 


[15/50] [abbrv] incubator-mynewt-core git commit: BLE Host - Updated GAP discovery API.

Posted by cc...@apache.org.
BLE Host - Updated GAP discovery API.


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

Branch: refs/heads/ble_hs_api
Commit: d586c0e6dfc4aa4fd1523fc580ae2fc6ba6ecc7c
Parents: be39876
Author: Christopher Collins <cc...@apache.org>
Authored: Thu Jun 23 19:31:51 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Jul 11 16:43:31 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/include/host/ble_gap.h      |  21 ++-
 net/nimble/host/src/ble_gap.c               | 170 ++++++++++++--------
 net/nimble/host/src/test/ble_gap_test.c     | 190 ++++++++++++++++++-----
 net/nimble/host/src/test/ble_hs_test_util.c |  21 ++-
 net/nimble/host/src/test/ble_hs_test_util.h |   5 +-
 net/nimble/host/src/test/ble_os_test.c      |  13 +-
 6 files changed, 296 insertions(+), 124 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d586c0e6/net/nimble/host/include/host/ble_gap.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/ble_gap.h b/net/nimble/host/include/host/ble_gap.h
index 6d3dd2a..707b10b 100644
--- a/net/nimble/host/include/host/ble_gap.h
+++ b/net/nimble/host/include/host/ble_gap.h
@@ -43,6 +43,9 @@ struct hci_conn_update;
 /** 60 ms; active scanning. */
 #define BLE_GAP_SCAN_FAST_INTERVAL_MAX      (60 * 1000 / BLE_HCI_ADV_ITVL)
 
+/** 11.25 seconds; limited discovery interval. */
+#define BLE_GAP_LIM_DISC_SCAN_INT           (11.25 * 1000 / BLE_HCI_SCAN_ITVL)
+
 /** 30 ms; active scanning. */
 #define BLE_GAP_SCAN_FAST_WINDOW            (30 * 1000 / BLE_HCI_SCAN_ITVL)
 
@@ -56,7 +59,7 @@ struct hci_conn_update;
 #define BLE_GAP_SCAN_SLOW_WINDOW1           (11.25 * 1000 / BLE_HCI_SCAN_ITVL)
 
 /** 10.24 seconds. */
-#define BLE_GAP_GEN_DISC_SCAN_MIN           (10.24 * 1000)
+#define BLE_GAP_DISC_DUR_DFLT               (10.24 * 1000)
 
 /** 1 second. */
 #define BLE_GAP_CONN_PAUSE_CENTRAL          (1 * 1000)
@@ -164,6 +167,15 @@ struct ble_gap_conn_params {
     uint16_t max_ce_len;
 };
 
+struct ble_gap_disc_params {
+    uint16_t itvl;
+    uint16_t window;
+    uint8_t filter_policy;
+    uint8_t limited:1;
+    uint8_t passive:1;
+    uint8_t filter_duplicates:1;
+};
+
 struct ble_gap_upd_params {
     uint16_t itvl_min;
     uint16_t itvl_max;
@@ -269,10 +281,9 @@ int ble_gap_adv_start(uint8_t own_addr_type, uint8_t peer_addr_type,
 int ble_gap_adv_stop(void);
 int ble_gap_adv_set_fields(struct ble_hs_adv_fields *adv_fields);
 int ble_gap_adv_rsp_set_fields(struct ble_hs_adv_fields *rsp_fields);
-int ble_gap_disc(uint32_t duration_ms, uint8_t discovery_mode,
-                      uint8_t scan_type, uint8_t filter_policy,
-                      uint8_t addr_mode,
-                      ble_gap_disc_fn *cb, void *cb_arg);
+int ble_gap_disc(uint8_t own_addr_type, int32_t duration_ms,
+                 const struct ble_gap_disc_params *disc_params,
+                 ble_gap_disc_fn *cb, void *cb_arg);
 int ble_gap_disc_cancel(void);
 int ble_gap_connect(uint8_t own_addr_type,
                     uint8_t peer_addr_type, const uint8_t *peer_addr,

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d586c0e6/net/nimble/host/src/ble_gap.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gap.c b/net/nimble/host/src/ble_gap.c
index 6fc401a..8792083 100644
--- a/net/nimble/host/src/ble_gap.c
+++ b/net/nimble/host/src/ble_gap.c
@@ -90,7 +90,7 @@ static const struct ble_gap_conn_params ble_gap_conn_params_dflt = {
 static bssnz_t struct {
     uint8_t op;
 
-    unsigned exp_set:1;
+    uint8_t exp_set:1;
     os_time_t exp_os_ticks;
 
     union {
@@ -98,12 +98,12 @@ static bssnz_t struct {
             ble_gap_event_fn *cb;
             void *cb_arg;
 
-            unsigned using_wl:1;
-            unsigned our_addr_type:2;
+            uint8_t using_wl:1;
+            uint8_t our_addr_type:2;
         } conn;
 
         struct {
-            uint8_t disc_mode;
+            uint8_t limited:1;
             ble_gap_disc_fn *cb;
             void *cb_arg;
         } disc;
@@ -181,6 +181,16 @@ STATS_NAME_END(ble_gap_stats)
  *****************************************************************************/
 
 static void
+ble_gap_log_duration(int32_t duration_ms)
+{
+    if (duration_ms == BLE_HS_FOREVER) {
+        BLE_HS_LOG(INFO, "duration=forever");
+    } else {
+        BLE_HS_LOG(INFO, "duration=%dms", duration_ms);
+    }
+}
+
+static void
 ble_gap_log_conn(uint8_t own_addr_type,
                  uint8_t peer_addr_type, const uint8_t *peer_addr,
                  const struct ble_gap_conn_params *params)
@@ -201,11 +211,13 @@ ble_gap_log_conn(uint8_t own_addr_type,
 }
 
 static void
-ble_gap_log_disc(uint8_t scan_type, uint8_t filter_policy, uint8_t addr_mode)
+ble_gap_log_disc(uint8_t own_addr_type, int32_t duration_ms,
+                 const struct ble_gap_disc_params *disc_params)
 {
-    BLE_HS_LOG(INFO, "disc_mode=%d filter_policy=%d scan_type=%d addr_node %d",
-               ble_gap_master.disc.disc_mode,
-               filter_policy, scan_type, addr_mode);
+    BLE_HS_LOG(INFO, "own_addr_type=%d filter_policy=%d passive=%d limited=%d",
+               own_addr_type, disc_params->filter_policy, disc_params->passive,
+               disc_params->limited);
+    ble_gap_log_duration(duration_ms);
 }
 
 static void
@@ -879,7 +891,7 @@ ble_gap_rx_adv_report(struct ble_hs_adv *adv)
         return;
     }
 
-    if (ble_gap_master.disc.disc_mode == BLE_GAP_DISC_MODE_LTD &&
+    if (ble_gap_master.disc.limited &&
         !(fields.flags & BLE_HS_ADV_F_DISC_LTD)) {
 
         return;
@@ -1750,19 +1762,25 @@ ble_gap_disc_tx_enable(void)
 }
 
 static int
-ble_gap_disc_tx_params(uint8_t scan_type, uint8_t filter_policy,
-                       uint8_t addr_mode)
+ble_gap_disc_tx_params(uint8_t own_addr_type,
+                       const struct ble_gap_disc_params *disc_params)
 {
     uint8_t buf[BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_SCAN_PARAM_LEN];
+    uint8_t scan_type;
     int rc;
 
-    rc = host_hci_cmd_build_le_set_scan_params(
-        scan_type,
-        BLE_GAP_SCAN_FAST_INTERVAL_MIN,
-        BLE_GAP_SCAN_FAST_WINDOW,
-        addr_mode,
-        filter_policy,
-        buf, sizeof buf);
+    if (disc_params->passive) {
+        scan_type = BLE_HCI_SCAN_TYPE_PASSIVE;
+    } else {
+        scan_type = BLE_HCI_SCAN_TYPE_ACTIVE;
+    }
+
+    rc = host_hci_cmd_build_le_set_scan_params(scan_type,
+                                               disc_params->itvl,
+                                               disc_params->window,
+                                               own_addr_type,
+                                               disc_params->filter_policy,
+                                               buf, sizeof buf);
     BLE_HS_DBG_ASSERT_EVAL(rc == 0);
 
     rc = ble_hci_cmd_tx_empty_ack(buf);
@@ -1813,6 +1831,45 @@ done:
     return rc;
 }
 
+static void
+ble_gap_disc_fill_dflts(struct ble_gap_disc_params *disc_params)
+{
+   if (disc_params->itvl == 0) {
+        if (disc_params->limited) {
+            disc_params->itvl = BLE_GAP_LIM_DISC_SCAN_INT;
+        } else {
+            disc_params->itvl = BLE_GAP_SCAN_SLOW_INTERVAL1;
+        }
+    }
+
+    if (disc_params->window == 0) {
+        disc_params->window = BLE_GAP_SCAN_SLOW_WINDOW1;
+    }
+}
+
+static int
+ble_gap_disc_validate(uint8_t own_addr_type, 
+                      const struct ble_gap_disc_params *disc_params)
+{
+    if (disc_params == NULL) {
+        return BLE_HS_EINVAL;
+    }
+
+    if (own_addr_type > BLE_HCI_ADV_OWN_ADDR_MAX) {
+        return BLE_HS_EINVAL;
+    }
+
+    if (disc_params->filter_policy > BLE_HCI_SCAN_FILT_MAX) {
+        return BLE_HS_EINVAL;
+    }
+
+    if (ble_gap_master.op != BLE_GAP_OP_NULL) {
+        return BLE_HS_EALREADY;
+    }
+
+    return 0;
+}
+
 /**
  * Performs the Limited or General Discovery Procedures, as described in
  * vol. 3, part C, section 9.2.5 / 9.2.6.
@@ -1820,77 +1877,59 @@ done:
  * @return                      0 on success; nonzero on failure.
  */
 int
-ble_gap_disc(uint32_t duration_ms, uint8_t discovery_mode,
-             uint8_t scan_type, uint8_t filter_policy, uint8_t addr_mode,
+ble_gap_disc(uint8_t own_addr_type, int32_t duration_ms,
+             const struct ble_gap_disc_params *in_disc_params,
              ble_gap_disc_fn *cb, void *cb_arg)
 {
 #if !NIMBLE_OPT(ROLE_OBSERVER)
     return BLE_HS_ENOTSUP;
 #endif
 
+    struct ble_gap_disc_params params;
     uint32_t duration_ticks;
     int rc;
 
-    ble_hs_lock();
-
-    if (ble_gap_master.op != BLE_GAP_OP_NULL) {
-        rc = BLE_HS_EALREADY;
-        goto done;
-    }
-
     STATS_INC(ble_gap_stats, discover);
 
-    if (discovery_mode != BLE_GAP_DISC_MODE_LTD &&
-        discovery_mode != BLE_GAP_DISC_MODE_GEN) {
-
-        rc = BLE_HS_EINVAL;
-        goto done;
-    }
+    ble_hs_lock();
 
-    if (scan_type != BLE_HCI_SCAN_TYPE_PASSIVE &&
-        scan_type != BLE_HCI_SCAN_TYPE_ACTIVE) {
+    /* Make a copy of the parameter strcuture and fill unspecified values with
+     * defaults.
+     */
+    params = *in_disc_params;
+    ble_gap_disc_fill_dflts(&params);
 
-        rc = BLE_HS_EINVAL;
+    rc = ble_gap_disc_validate(own_addr_type, &params);
+    if (rc != 0) {
         goto done;
     }
 
-    if((addr_mode != BLE_HCI_ADV_OWN_ADDR_PUBLIC) &&
-       (addr_mode != BLE_HCI_ADV_OWN_ADDR_RANDOM) &&
-       (addr_mode != BLE_HCI_ADV_OWN_ADDR_PRIV_PUB) &&
-       (addr_mode != BLE_HCI_ADV_OWN_ADDR_PRIV_RAND)) {
-          rc = BLE_HS_EINVAL;
-          goto done;
-      }
-
-    if (filter_policy > BLE_HCI_SCAN_FILT_MAX) {
-        rc = BLE_HS_EINVAL;
-        goto done;
+    if (duration_ms == 0) {
+        duration_ms = BLE_GAP_DISC_DUR_DFLT;
     }
 
-    if (duration_ms == 0) {
-        duration_ms = BLE_GAP_GEN_DISC_SCAN_MIN;
+    if (duration_ms != BLE_HS_FOREVER) {
+        rc = os_time_ms_to_ticks(duration_ms, &duration_ticks);
+        if (rc != 0) {
+            /* Duration too great. */
+            rc = BLE_HS_EINVAL;
+            goto done;
+        }
     }
 
-    rc = os_time_ms_to_ticks(duration_ms, &duration_ticks);
-    if (rc != 0) {
-        /* Duration too great. */
-        rc = BLE_HS_EINVAL;
-        goto done;
+    if (own_addr_type == BLE_HCI_ADV_OWN_ADDR_RANDOM) {
+        ble_hs_pvcy_set_our_nrpa();
     }
 
-    ble_gap_master.disc.disc_mode = discovery_mode;
+    ble_gap_master.disc.limited = params.limited;
     ble_gap_master.disc.cb = cb;
     ble_gap_master.disc.cb_arg = cb_arg;
 
     BLE_HS_LOG(INFO, "GAP procedure initiated: discovery; ");
-    ble_gap_log_disc(scan_type, filter_policy, addr_mode);
+    ble_gap_log_disc(own_addr_type, duration_ms, &params);
     BLE_HS_LOG(INFO, "\n");
 
-    if (addr_mode == BLE_HCI_ADV_OWN_ADDR_RANDOM) {
-        ble_hs_pvcy_set_our_nrpa();
-    }
-
-    rc = ble_gap_disc_tx_params(scan_type, filter_policy, addr_mode);
+    rc = ble_gap_disc_tx_params(own_addr_type, &params);
     if (rc != 0) {
         goto done;
     }
@@ -1900,18 +1939,21 @@ ble_gap_disc(uint32_t duration_ms, uint8_t discovery_mode,
         goto done;
     }
 
-    ble_gap_master_set_timer(duration_ticks);
+    if (duration_ms != BLE_HS_FOREVER) {
+        ble_gap_master_set_timer(duration_ticks);
+    }
+
     ble_gap_master.op = BLE_GAP_OP_M_DISC;
 
     rc = 0;
 
 done:
+    ble_hs_unlock();
+
     if (rc != 0) {
         STATS_INC(ble_gap_stats, discover_fail);
     }
 
-    ble_hs_unlock();
-
     return rc;
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d586c0e6/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 b55b276..b8dbc82 100644
--- a/net/nimble/host/src/test/ble_gap_test.c
+++ b/net/nimble/host/src/test/ble_gap_test.c
@@ -165,7 +165,9 @@ ble_gap_test_util_verify_tx_add_wl(struct ble_gap_white_entry *entry)
 }
 
 static void
-ble_gap_test_util_verify_tx_set_scan_params(uint16_t itvl,
+ble_gap_test_util_verify_tx_set_scan_params(uint8_t own_addr_type,
+                                            uint8_t scan_type,
+                                            uint16_t itvl,
                                             uint16_t scan_window,
                                             uint8_t filter_policy)
 {
@@ -176,15 +178,16 @@ ble_gap_test_util_verify_tx_set_scan_params(uint16_t itvl,
                                            BLE_HCI_OCF_LE_SET_SCAN_PARAMS,
                                            &param_len);
     TEST_ASSERT(param_len == BLE_HCI_SET_SCAN_PARAM_LEN);
-    TEST_ASSERT(param[0] == BLE_HCI_SCAN_TYPE_ACTIVE);
+    TEST_ASSERT(param[0] == scan_type);
     TEST_ASSERT(le16toh(param + 1) == itvl);
     TEST_ASSERT(le16toh(param + 3) == scan_window);
-    TEST_ASSERT(param[5] == BLE_HCI_ADV_OWN_ADDR_PUBLIC);
+    TEST_ASSERT(param[5] == own_addr_type);
     TEST_ASSERT(param[6] == filter_policy);
 }
 
 static void
-ble_gap_test_util_verify_tx_scan_enable(uint8_t enable)
+ble_gap_test_util_verify_tx_scan_enable(uint8_t enable,
+                                        uint8_t filter_duplicates)
 {
     uint8_t param_len;
     uint8_t *param;
@@ -194,6 +197,7 @@ ble_gap_test_util_verify_tx_scan_enable(uint8_t enable)
                                            &param_len);
     TEST_ASSERT(param_len == BLE_HCI_SET_SCAN_ENABLE_LEN);
     TEST_ASSERT(param[0] == enable);
+    TEST_ASSERT(param[1] == filter_duplicates);
 }
 
 static void
@@ -506,7 +510,8 @@ TEST_SUITE(ble_gap_test_suite_conn_wl)
  *****************************************************************************/
 
 static int
-ble_gap_test_util_disc(uint8_t disc_mode, uint8_t *peer_addr,
+ble_gap_test_util_disc(uint8_t own_addr_type,
+                       const struct ble_gap_disc_params *disc_params,
                        struct ble_hs_adv *adv, int cmd_fail_idx,
                        uint8_t fail_status)
 {
@@ -515,8 +520,7 @@ ble_gap_test_util_disc(uint8_t disc_mode, uint8_t *peer_addr,
     ble_gap_test_util_init();
 
     /* Begin the discovery procedure. */
-    rc = ble_hs_test_util_disc(0, disc_mode, BLE_HCI_SCAN_TYPE_ACTIVE,
-                               BLE_HCI_SCAN_FILT_NO_WL,
+    rc = ble_hs_test_util_disc(own_addr_type, BLE_HS_FOREVER, disc_params,
                                ble_gap_test_util_disc_cb, NULL, cmd_fail_idx,
                                fail_status);
     TEST_ASSERT(rc == BLE_HS_HCI_ERR(fail_status));
@@ -530,49 +534,63 @@ ble_gap_test_util_disc(uint8_t disc_mode, uint8_t *peer_addr,
     if (cmd_fail_idx > 0) {
         /* Verify tx of set scan parameters command. */
         ble_gap_test_util_verify_tx_set_scan_params(
-            30 * 1000 / BLE_HCI_ADV_ITVL,
-            30 * 1000 / BLE_HCI_SCAN_ITVL,
-            BLE_HCI_SCAN_FILT_NO_WL);
+            own_addr_type,
+            disc_params->passive ?
+                BLE_HCI_SCAN_TYPE_PASSIVE :
+                BLE_HCI_SCAN_TYPE_ACTIVE,
+            disc_params->itvl,
+            disc_params->window,
+            disc_params->filter_policy);
     }
 
     if (cmd_fail_idx > 1) {
         /* Verify tx of scan enable command. */
-        ble_gap_test_util_verify_tx_scan_enable(1);
+        ble_gap_test_util_verify_tx_scan_enable(
+            1, disc_params->filter_duplicates);
     }
 
     return rc;
 }
 
-TEST_CASE(ble_gap_test_case_conn_disc_bad_args)
+TEST_CASE(ble_gap_test_case_disc_bad_args)
 {
+    struct ble_gap_disc_params params;
     int rc;
 
+    params.itvl = 0;
+    params.window = 0;
+    params.filter_policy = BLE_HCI_SCAN_FILT_NO_WL;
+    params.limited = 0;
+    params.passive = 0;
+    params.filter_duplicates = 0;
+
     ble_gap_test_util_init();
 
-    /*** Invalid discovery mode. */
-    rc = ble_gap_disc(0, BLE_GAP_DISC_MODE_NON, BLE_HCI_SCAN_TYPE_ACTIVE,
-                      BLE_HCI_SCAN_FILT_NO_WL, BLE_ADDR_TYPE_PUBLIC,
+    /*** Invalid filter policy. */
+    params.filter_policy = 6;
+    rc = ble_gap_disc(BLE_ADDR_TYPE_PUBLIC, 0, &params,
                       ble_gap_test_util_disc_cb, NULL);
     TEST_ASSERT(rc == BLE_HS_EINVAL);
 
     /*** Master operation already in progress. */
+    params.filter_policy = BLE_HCI_SCAN_FILT_NO_WL;
     rc = ble_hs_test_util_connect(BLE_ADDR_TYPE_PUBLIC,
                                   BLE_GAP_ADDR_TYPE_WL, NULL, NULL,
                                   ble_gap_test_util_connect_cb, NULL, 0);
-    rc = ble_gap_disc(0, BLE_GAP_DISC_MODE_GEN, BLE_HCI_SCAN_TYPE_ACTIVE,
-                      BLE_HCI_SCAN_FILT_NO_WL, BLE_ADDR_TYPE_PUBLIC,
+    rc = ble_gap_disc(BLE_ADDR_TYPE_PUBLIC, 0, &params,
                       ble_gap_test_util_disc_cb, NULL);
     TEST_ASSERT(rc == BLE_HS_EALREADY);
 }
 
-TEST_CASE(ble_gap_test_case_conn_disc_good)
+TEST_CASE(ble_gap_test_case_disc_good)
 {
     uint8_t adv_data[32];
     uint8_t flags;
+    uint8_t own_addr_type;
+    int passive;
+    int limited;
     int rc;
-    int d;
 
-    uint8_t peer_addr[6] = { 1, 2, 3, 4, 5, 6 };
     struct ble_hs_adv adv = {
         .event_type = BLE_HCI_ADV_TYPE_ADV_IND,
         .addr_type = BLE_ADDR_TYPE_PUBLIC,
@@ -581,6 +599,14 @@ TEST_CASE(ble_gap_test_case_conn_disc_good)
         .addr = { 1, 2, 3, 4, 5, 6 },
         .data = adv_data,
     };
+    struct ble_gap_disc_params disc_params = {
+        .itvl = BLE_GAP_SCAN_SLOW_INTERVAL1,
+        .window = BLE_GAP_SCAN_SLOW_WINDOW1,
+        .filter_policy = BLE_HCI_CONN_FILT_NO_WL,
+        .limited = 0,
+        .passive = 0,
+        .filter_duplicates = 0,
+    };
 
     flags = BLE_HS_ADV_F_DISC_LTD;
     rc = ble_hs_adv_set_flat(BLE_HS_ADV_TYPE_FLAGS, 1, &flags,
@@ -588,15 +614,22 @@ TEST_CASE(ble_gap_test_case_conn_disc_good)
                              sizeof adv_data);
     TEST_ASSERT_FATAL(rc == 0);
 
-    for (d = BLE_GAP_DISC_MODE_LTD; d < BLE_GAP_DISC_MODE_MAX; d++) {
-        ble_gap_test_util_disc(d, peer_addr, &adv, -1, 0);
+    for (own_addr_type = 0;
+         own_addr_type <= BLE_ADDR_TYPE_RPA_RND_DEFAULT;
+         own_addr_type++)
+    for (passive = 0; passive <= 1; passive++)
+    for (limited = 0; limited <= 1; limited++) {
+        disc_params.passive = passive;
+        disc_params.limited = limited;
+        ble_gap_test_util_disc(own_addr_type, &disc_params, &adv, -1, 0);
 
         TEST_ASSERT(ble_gap_master_in_progress());
         TEST_ASSERT(ble_gap_test_disc_event == BLE_GAP_EVENT_DISC_SUCCESS);
         TEST_ASSERT(ble_gap_test_disc_status == 0);
         TEST_ASSERT(ble_gap_test_disc_desc.event_type ==
                     BLE_HCI_ADV_TYPE_ADV_IND);
-        TEST_ASSERT(ble_gap_test_disc_desc.addr_type == BLE_ADDR_TYPE_PUBLIC);
+        TEST_ASSERT(ble_gap_test_disc_desc.addr_type ==
+                    BLE_ADDR_TYPE_PUBLIC);
         TEST_ASSERT(ble_gap_test_disc_desc.length_data == 3);
         TEST_ASSERT(ble_gap_test_disc_desc.rssi == 0);
         TEST_ASSERT(memcmp(ble_gap_test_disc_desc.addr, adv.addr, 6) == 0);
@@ -604,32 +637,61 @@ TEST_CASE(ble_gap_test_case_conn_disc_good)
     }
 }
 
-TEST_CASE(ble_gap_test_case_conn_disc_bad_flags)
+TEST_CASE(ble_gap_test_case_disc_ltd_mismatch)
 {
-    uint8_t peer_addr[6] = { 1, 2, 3, 4, 5, 6 };
+    int rc;
     struct ble_hs_adv adv = {
         .event_type = BLE_HCI_ADV_TYPE_ADV_IND,
         .addr_type = BLE_ADDR_TYPE_PUBLIC,
         .length_data = 0,
         .rssi = 0,
         .addr = { 1, 2, 3, 4, 5, 6 },
-        .data = NULL,
+        .data = (uint8_t[BLE_HCI_MAX_ADV_DATA_LEN]){
+            2, 
+            BLE_HS_ADV_TYPE_FLAGS,
+            BLE_HS_ADV_F_DISC_GEN,
+        },
+    };
+    struct ble_gap_disc_params disc_params = {
+        .itvl = BLE_GAP_SCAN_SLOW_INTERVAL1,
+        .window = BLE_GAP_SCAN_SLOW_WINDOW1,
+        .filter_policy = BLE_HCI_CONN_FILT_NO_WL,
+        .limited = 1,
+        .passive = 0,
+        .filter_duplicates = 0,
     };
 
-    ble_gap_test_util_disc(BLE_GAP_DISC_MODE_LTD, peer_addr, &adv, -1, 0);
+    rc = ble_gap_test_util_disc(BLE_ADDR_TYPE_PUBLIC, &disc_params, &adv,
+                                -1, 0);
+    TEST_ASSERT(rc == 0);
     TEST_ASSERT(ble_gap_master_in_progress());
 
-    /* Verify that the report was ignored becuase of a mismatched LTD flag. */
+    /* Verify that the report was ignored because of a mismatched LTD flag. */
     TEST_ASSERT(ble_gap_test_disc_event == -1);
+
+    /* Stop the scan and swap the flags. */
+    rc = ble_hs_test_util_disc_cancel(0);
+    TEST_ASSERT(rc == 0);
+
+    adv.data[2] = BLE_HS_ADV_F_DISC_LTD;
+    disc_params.limited = 0;
+    rc = ble_gap_test_util_disc(BLE_ADDR_TYPE_PUBLIC, &disc_params, &adv,
+                                -1, 0);
+    TEST_ASSERT(rc == 0);
+    TEST_ASSERT(ble_gap_master_in_progress());
+
+    /* This time we should have reported the advertisement; general discovery
+     * hears everything.
+     */
+    TEST_ASSERT(ble_gap_test_disc_event == BLE_GAP_EVENT_DISC_SUCCESS);
 }
 
-TEST_CASE(ble_gap_test_case_conn_disc_hci_fail)
+TEST_CASE(ble_gap_test_case_disc_hci_fail)
 {
     int fail_idx;
+    int limited;
     int rc;
-    int d;
 
-    uint8_t peer_addr[6] = { 1, 2, 3, 4, 5, 6 };
     struct ble_hs_adv adv = {
         .event_type = BLE_HCI_ADV_TYPE_ADV_IND,
         .addr_type = BLE_ADDR_TYPE_PUBLIC,
@@ -638,23 +700,71 @@ TEST_CASE(ble_gap_test_case_conn_disc_hci_fail)
         .addr = { 1, 2, 3, 4, 5, 6 },
         .data = NULL,
     };
+    struct ble_gap_disc_params disc_params = {
+        .itvl = BLE_GAP_SCAN_SLOW_INTERVAL1,
+        .window = BLE_GAP_SCAN_SLOW_WINDOW1,
+        .filter_policy = BLE_HCI_CONN_FILT_NO_WL,
+        .limited = 0,
+        .passive = 0,
+        .filter_duplicates = 0,
+    };
+
+    for (limited = 0; limited <= 1; limited++) {
+        disc_params.limited = limited;
 
-    for (d = BLE_GAP_DISC_MODE_LTD; d < BLE_GAP_DISC_MODE_MAX; d++) {
         for (fail_idx = 0; fail_idx < 2; fail_idx++) {
-            rc = ble_gap_test_util_disc(d, peer_addr, &adv, fail_idx,
-                                        BLE_ERR_UNSUPPORTED);
+            rc = ble_gap_test_util_disc(BLE_ADDR_TYPE_PUBLIC, &disc_params,
+                                        &adv, fail_idx, BLE_ERR_UNSUPPORTED);
             TEST_ASSERT(rc == BLE_HS_HCI_ERR(BLE_ERR_UNSUPPORTED));
             TEST_ASSERT(!ble_gap_master_in_progress());
         }
     }
 }
 
-TEST_SUITE(ble_gap_test_suite_conn_disc)
+static void
+ble_gap_test_util_disc_dflts_once(int limited)
+{
+    struct ble_gap_disc_params params;
+    uint16_t exp_itvl;
+    int rc;
+
+    ble_gap_test_util_init();
+
+    memset(&params, 0, sizeof params);
+    params.limited = limited;
+
+    rc = ble_hs_test_util_disc(BLE_ADDR_TYPE_PUBLIC, 0, &params,
+                               ble_gap_test_util_disc_cb, NULL, -1, 0);
+    TEST_ASSERT_FATAL(rc == 0);
+
+    if (limited) {
+        exp_itvl = BLE_GAP_LIM_DISC_SCAN_INT;
+    } else {
+        exp_itvl = BLE_GAP_SCAN_SLOW_INTERVAL1;
+    }
+    ble_gap_test_util_verify_tx_set_scan_params(
+        BLE_ADDR_TYPE_PUBLIC,
+        BLE_HCI_SCAN_TYPE_ACTIVE,
+        exp_itvl,
+        BLE_GAP_SCAN_SLOW_WINDOW1,
+        BLE_HCI_SCAN_FILT_NO_WL);
+
+    ble_gap_test_util_verify_tx_scan_enable(1, 0);
+}
+
+TEST_CASE(ble_gap_test_case_disc_dflts)
+{
+    ble_gap_test_util_disc_dflts_once(0);
+    ble_gap_test_util_disc_dflts_once(1);
+}
+
+TEST_SUITE(ble_gap_test_suite_disc)
 {
-    ble_gap_test_case_conn_disc_bad_args();
-    ble_gap_test_case_conn_disc_good();
-    ble_gap_test_case_conn_disc_bad_flags();
-    ble_gap_test_case_conn_disc_hci_fail();
+    ble_gap_test_case_disc_bad_args();
+    ble_gap_test_case_disc_good();
+    ble_gap_test_case_disc_ltd_mismatch();
+    ble_gap_test_case_disc_hci_fail();
+    ble_gap_test_case_disc_dflts();
 }
 
 /*****************************************************************************
@@ -1948,7 +2058,7 @@ int
 ble_gap_test_all(void)
 {
     ble_gap_test_suite_conn_wl();
-    ble_gap_test_suite_conn_disc();
+    ble_gap_test_suite_disc();
     ble_gap_test_suite_conn_dir();
     ble_gap_test_suite_conn_cancel();
     ble_gap_test_suite_conn_terminate();

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d586c0e6/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 30c4b40..f2f334f 100644
--- a/net/nimble/host/src/test/ble_hs_test_util.c
+++ b/net/nimble/host/src/test/ble_hs_test_util.c
@@ -437,8 +437,8 @@ ble_hs_test_util_exp_hci_status(int cmd_idx, int fail_idx, uint8_t fail_status)
 }
 
 int
-ble_hs_test_util_disc(uint32_t duration_ms, uint8_t discovery_mode,
-                      uint8_t scan_type, uint8_t filter_policy,
+ble_hs_test_util_disc(uint8_t own_addr_type, int32_t duration_ms,
+                      const struct ble_gap_disc_params *disc_params,
                       ble_gap_disc_fn *cb, void *cb_arg, int fail_idx,
                       uint8_t fail_status)
 {
@@ -457,12 +457,25 @@ ble_hs_test_util_disc(uint32_t duration_ms, uint8_t discovery_mode,
         { 0 }
     }));
 
-    rc = ble_gap_disc(duration_ms, discovery_mode, scan_type, filter_policy, 
-                      BLE_ADDR_TYPE_PUBLIC,
+    rc = ble_gap_disc(own_addr_type, duration_ms, disc_params,
                       cb, cb_arg);
     return rc;
 }
 
+int
+ble_hs_test_util_disc_cancel(uint8_t ack_status)
+{
+    int rc;
+
+    ble_hs_test_util_set_ack(
+        host_hci_opcode_join(BLE_HCI_OGF_LE,
+                             BLE_HCI_OCF_LE_SET_SCAN_ENABLE),
+        ack_status);
+
+    rc = ble_gap_disc_cancel();
+    return rc;
+}
+
 static void
 ble_hs_test_util_verify_tx_rd_pwr(void)
 {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d586c0e6/net/nimble/host/src/test/ble_hs_test_util.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_hs_test_util.h b/net/nimble/host/src/test/ble_hs_test_util.h
index a242e44..0a7c4e3 100644
--- a/net/nimble/host/src/test/ble_hs_test_util.h
+++ b/net/nimble/host/src/test/ble_hs_test_util.h
@@ -74,10 +74,11 @@ int ble_hs_test_util_conn_terminate(uint16_t conn_handle, uint8_t hci_status);
 void ble_hs_test_util_conn_disconnect(uint16_t conn_handle);
 int ble_hs_test_util_exp_hci_status(int cmd_idx, int fail_idx,
                                     uint8_t fail_status);
-int ble_hs_test_util_disc(uint32_t duration_ms, uint8_t discovery_mode,
-                          uint8_t scan_type, uint8_t filter_policy,
+int ble_hs_test_util_disc(uint8_t own_addr_type, int32_t duration_ms,
+                          const struct ble_gap_disc_params *disc_params,
                           ble_gap_disc_fn *cb, void *cb_arg, int fail_idx,
                           uint8_t fail_status);
+int ble_hs_test_util_disc_cancel(uint8_t ack_status);
 int ble_hs_test_util_adv_set_fields(struct ble_hs_adv_fields *adv_fields,
                                     uint8_t hci_status);
 int ble_hs_test_util_adv_start(uint8_t own_addr_type,

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d586c0e6/net/nimble/host/src/test/ble_os_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_os_test.c b/net/nimble/host/src/test/ble_os_test.c
index 61295d2..a856351 100644
--- a/net/nimble/host/src/test/ble_os_test.c
+++ b/net/nimble/host/src/test/ble_os_test.c
@@ -26,13 +26,8 @@
 #include "host/ble_gap.h"
 #include "ble_hs_test_util.h"
 
-#ifdef ARCH_sim
-#define BLE_OS_TEST_STACK_SIZE      1024
-#define BLE_OS_TEST_APP_STACK_SIZE  1024
-#else
 #define BLE_OS_TEST_STACK_SIZE      256
 #define BLE_OS_TEST_APP_STACK_SIZE  256
-#endif
 
 #define BLE_OS_TEST_APP_PRIO         9
 #define BLE_OS_TEST_TASK_PRIO        10
@@ -185,6 +180,7 @@ ble_gap_gen_disc_test_connect_cb(int event, int status,
 static void
 ble_gap_gen_disc_test_task_handler(void *arg)
 {
+    struct ble_gap_disc_params disc_params;
     int cb_called;
     int rc;
 
@@ -204,10 +200,9 @@ ble_gap_gen_disc_test_task_handler(void *arg)
     TEST_ASSERT(!ble_os_test_misc_conn_exists(BLE_HS_CONN_HANDLE_NONE));
     TEST_ASSERT(!ble_gap_master_in_progress());
 
-    /* Initiate the general discovery procedure with a 200 ms timeout. */
-    rc = ble_hs_test_util_disc(300, BLE_GAP_DISC_MODE_GEN,
-                               BLE_HCI_SCAN_TYPE_ACTIVE,
-                               BLE_HCI_SCAN_FILT_NO_WL,
+    /* Initiate the general discovery procedure with a 300 ms timeout. */
+    memset(&disc_params, 0, sizeof disc_params);
+    rc = ble_hs_test_util_disc(BLE_ADDR_TYPE_PUBLIC, 300, &disc_params,
                                ble_gap_gen_disc_test_connect_cb,
                                &cb_called, 0, 0);
     TEST_ASSERT(rc == 0);


[20/50] [abbrv] incubator-mynewt-core git commit: BLE Host - Const correctness.

Posted by cc...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/63531557/net/nimble/host/src/ble_att_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att_priv.h b/net/nimble/host/src/ble_att_priv.h
index f908b9c..5506c58 100644
--- a/net/nimble/host/src/ble_att_priv.h
+++ b/net/nimble/host/src/ble_att_priv.h
@@ -220,53 +220,55 @@ struct ble_att_read_group_type_adata {
 };
 
 int ble_att_clt_rx_error(uint16_t conn_handle, struct os_mbuf **rxom);
-int ble_att_clt_tx_mtu(uint16_t conn_handle, struct ble_att_mtu_cmd *req);
+int ble_att_clt_tx_mtu(uint16_t conn_handle,
+                       const struct ble_att_mtu_cmd *req);
 int ble_att_clt_rx_mtu(uint16_t conn_handle, struct os_mbuf **rxom);
-int ble_att_clt_tx_read(uint16_t conn_handle, struct ble_att_read_req *req);
+int ble_att_clt_tx_read(uint16_t conn_handle,
+                        const struct ble_att_read_req *req);
 int ble_att_clt_rx_read(uint16_t conn_handle, struct os_mbuf **rxom);
 int ble_att_clt_tx_read_blob(uint16_t conn_handle,
-                             struct ble_att_read_blob_req *req);
+                             const struct ble_att_read_blob_req *req);
 int ble_att_clt_rx_read_blob(uint16_t conn_handle, struct os_mbuf **rxom);
 int ble_att_clt_tx_read_mult(uint16_t conn_handle,
-                             uint16_t *handles, int num_handles);
+                             const uint16_t *handles, int num_handles);
 int ble_att_clt_rx_read_mult(uint16_t conn_handle, struct os_mbuf **rxom);
 int ble_att_clt_tx_read_type(uint16_t conn_handle,
-                             struct ble_att_read_type_req *req,
-                             void *uuid128);
+                             const struct ble_att_read_type_req *req,
+                             const void *uuid128);
 int ble_att_clt_rx_read_type(uint16_t conn_handle, struct os_mbuf **rxom);
-int ble_att_clt_tx_read_group_type(uint16_t conn_handle,
-                                   struct ble_att_read_group_type_req *req,
-                                   void *uuid128);
+int ble_att_clt_tx_read_group_type(
+    uint16_t conn_handle, const struct ble_att_read_group_type_req *req,
+    const void *uuid128);
 int ble_att_clt_rx_read_group_type(uint16_t conn_handle,
                                    struct os_mbuf **rxom);
 int ble_att_clt_tx_find_info(uint16_t conn_handle,
-                             struct ble_att_find_info_req *req);
+                             const struct ble_att_find_info_req *req);
 int ble_att_clt_rx_find_info(uint16_t conn_handle, struct os_mbuf **om);
-int ble_att_clt_tx_find_type_value(uint16_t conn_handle,
-                                   struct ble_att_find_type_value_req *req,
-                                   void *attribute_value, int value_len);
+int ble_att_clt_tx_find_type_value(
+    uint16_t conn_handle, const struct ble_att_find_type_value_req *req,
+    const void *attribute_value, int value_len);
 int ble_att_clt_rx_find_type_value(uint16_t conn_handle,
                                    struct os_mbuf **rxom);
 int ble_att_clt_tx_write_req(uint16_t conn_handle,
-                             struct ble_att_write_req *req,
-                             void *value, uint16_t value_len);
+                             const struct ble_att_write_req *req,
+                             const void *value, uint16_t value_len);
 int ble_att_clt_tx_write_cmd(uint16_t conn_handle,
-                             struct ble_att_write_req *req,
-                             void *value, uint16_t value_len);
+                             const struct ble_att_write_req *req,
+                             const void *value, uint16_t value_len);
 int ble_att_clt_tx_prep_write(uint16_t conn_handle,
-                              struct ble_att_prep_write_cmd *req,
-                              void *value, uint16_t value_len);
+                              const struct ble_att_prep_write_cmd *req,
+                              const void *value, uint16_t value_len);
 int ble_att_clt_rx_prep_write(uint16_t conn_handle, struct os_mbuf **rxom);
 int ble_att_clt_tx_exec_write(uint16_t conn_handle,
-                              struct ble_att_exec_write_req *req);
+                              const struct ble_att_exec_write_req *req);
 int ble_att_clt_rx_exec_write(uint16_t conn_handle, struct os_mbuf **rxom);
 int ble_att_clt_rx_write(uint16_t conn_handle, struct os_mbuf **rxom);
 int ble_att_clt_tx_notify(uint16_t conn_handle,
-                          struct ble_att_notify_req *req,
-                          void *value, uint16_t value_len);
+                          const struct ble_att_notify_req *req,
+                          const void *value, uint16_t value_len);
 int ble_att_clt_tx_indicate(uint16_t conn_handle,
-                            struct ble_att_indicate_req *req,
-                            void *value, uint16_t value_len);
+                            const struct ble_att_indicate_req *req,
+                            const void *value, uint16_t value_len);
 int ble_att_clt_rx_indicate(uint16_t conn_handle, struct os_mbuf **rxom);
 
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/63531557/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 a81dc91..f7a5d36 100644
--- a/net/nimble/host/src/ble_att_svr.c
+++ b/net/nimble/host/src/ble_att_svr.c
@@ -281,6 +281,23 @@ ble_att_svr_check_security(uint16_t conn_handle, int is_read,
     return 0;
 }
 
+static uint16_t
+ble_att_max_read_len(uint16_t conn_handle)
+{
+    uint16_t mtu;
+
+    if (conn_handle == BLE_HS_CONN_HANDLE_NONE) {
+        /* The application is reading from itself; no MTU. */
+        mtu = BLE_ATT_MTU_MAX;
+    } else {
+        mtu = ble_att_mtu(conn_handle);
+    }
+
+    /* Subtract one to account for the att-read-response header. */
+    BLE_HS_DBG_ASSERT(mtu > 0);
+    return mtu - 1;
+}
+
 static int
 ble_att_svr_read(uint16_t conn_handle,
                  struct ble_att_svr_entry *entry,
@@ -305,6 +322,13 @@ ble_att_svr_read(uint16_t conn_handle,
         }
     }
 
+    /* Give the application access to the ATT flat buffer in case it needs
+     * to generate the read response dynamically.
+     */
+    ctxt->read.buf = ble_att_get_flat_buf();
+    ctxt->read.data = ctxt->read.buf;
+    ctxt->read.max_data_len = ble_att_max_read_len(conn_handle);
+
     BLE_HS_DBG_ASSERT(entry->ha_cb != NULL);
     rc = entry->ha_cb(conn_handle, entry->ha_handle_id,
                       entry->ha_uuid, BLE_ATT_ACCESS_OP_READ, ctxt,
@@ -349,13 +373,13 @@ ble_att_svr_read_handle(uint16_t conn_handle, uint16_t attr_handle,
 }
 
 int
-ble_att_svr_read_local(uint16_t attr_handle, void **out_data,
+ble_att_svr_read_local(uint16_t attr_handle, const void **out_data,
                        uint16_t *out_attr_len)
 {
     struct ble_att_svr_access_ctxt ctxt;
     int rc;
 
-    ctxt.offset = 0;
+    ctxt.read.offset = 0;
 
     rc = ble_att_svr_read_handle(BLE_HS_CONN_HANDLE_NONE, attr_handle, &ctxt,
                                  NULL);
@@ -363,8 +387,8 @@ ble_att_svr_read_local(uint16_t attr_handle, void **out_data,
         return rc;
     }
 
-    *out_attr_len = ctxt.data_len;
-    *out_data = ctxt.attr_data;
+    *out_attr_len = ctxt.read.len;
+    *out_data = ctxt.read.data;
 
     return 0;
 }
@@ -1016,13 +1040,13 @@ ble_att_svr_fill_type_value(uint16_t conn_handle,
              */
             uuid16 = ble_uuid_128_to_16(ha->ha_uuid);
             if (uuid16 == req->bavq_attr_type) {
-                ctxt.offset = 0;
+                ctxt.read.offset = 0;
                 rc = ble_att_svr_read(conn_handle, ha, &ctxt, out_att_err);
                 if (rc != 0) {
                     goto done;
                 }
                 rc = os_mbuf_memcmp(rxom, BLE_ATT_FIND_TYPE_VALUE_REQ_BASE_SZ,
-                                    ctxt.attr_data, ctxt.data_len);
+                                    ctxt.read.data, ctxt.read.len);
                 if (rc == 0) {
                     match = 1;
                 }
@@ -1178,8 +1202,8 @@ ble_att_svr_build_read_type_rsp(uint16_t conn_handle,
                                 uint8_t *att_err,
                                 uint16_t *err_handle)
 {
-    struct ble_att_read_type_rsp rsp;
     struct ble_att_svr_access_ctxt ctxt;
+    struct ble_att_read_type_rsp rsp;
     struct ble_att_svr_entry *entry;
     struct os_mbuf *txom;
     uint16_t mtu;
@@ -1234,17 +1258,17 @@ ble_att_svr_build_read_type_rsp(uint16_t conn_handle,
         }
 
         if (entry->ha_handle_id >= req->batq_start_handle) {
-            ctxt.offset = 0;
+            ctxt.read.offset = 0;
             rc = ble_att_svr_read(conn_handle, entry, &ctxt, att_err);
             if (rc != 0) {
                 *err_handle = entry->ha_handle_id;
                 goto done;
             }
 
-            if (ctxt.data_len > mtu - 4) {
+            if (ctxt.read.len > mtu - 4) {
                 attr_len = mtu - 4;
             } else {
-                attr_len = ctxt.data_len;
+                attr_len = ctxt.read.len;
             }
 
             if (prev_attr_len == 0) {
@@ -1267,7 +1291,7 @@ ble_att_svr_build_read_type_rsp(uint16_t conn_handle,
             }
 
             htole16(dptr + 0, entry->ha_handle_id);
-            memcpy(dptr + 2, ctxt.attr_data, attr_len);
+            memcpy(dptr + 2, ctxt.read.data, attr_len);
             entry_written = 1;
         }
     }
@@ -1385,8 +1409,9 @@ done:
  * @return                      0 on success; nonzero on failure.
  */
 static int
-ble_att_svr_build_read_rsp(uint16_t conn_handle, void *attr_data, int attr_len,
-                           struct os_mbuf **out_txom, uint8_t *att_err)
+ble_att_svr_build_read_rsp(uint16_t conn_handle, const void *attr_data,
+                           int attr_len, struct os_mbuf **out_txom,
+                           uint8_t *att_err)
 {
     struct os_mbuf *txom;
     uint16_t data_len;
@@ -1467,7 +1492,7 @@ ble_att_svr_rx_read(uint16_t conn_handle, struct os_mbuf **rxom)
     ble_att_read_req_parse((*rxom)->om_data, (*rxom)->om_len, &req);
     BLE_ATT_LOG_CMD(0, "read req", conn_handle, ble_att_read_req_log, &req);
 
-    ctxt.offset = 0;
+    ctxt.read.offset = 0;
     rc = ble_att_svr_read_handle(conn_handle, req.barq_handle, &ctxt,
                                  &att_err);
     if (rc != 0) {
@@ -1475,7 +1500,7 @@ ble_att_svr_rx_read(uint16_t conn_handle, struct os_mbuf **rxom)
         goto done;
     }
 
-    rc = ble_att_svr_build_read_rsp(conn_handle, ctxt.attr_data, ctxt.data_len,
+    rc = ble_att_svr_build_read_rsp(conn_handle, ctxt.read.data, ctxt.read.len,
                                     &txom, &att_err);
     if (rc != 0) {
         err_handle = req.barq_handle;
@@ -1494,8 +1519,9 @@ done:
  * @return                      0 on success; nonzero on failure.
  */
 static int
-ble_att_svr_build_read_blob_rsp(void *attr_data, int attr_len, uint16_t mtu,
-                                struct os_mbuf **out_txom, uint8_t *att_err)
+ble_att_svr_build_read_blob_rsp(const void *attr_data, int attr_len,
+                                uint16_t mtu, struct os_mbuf **out_txom,
+                                uint8_t *att_err)
 {
     struct os_mbuf *txom;
     uint16_t data_len;
@@ -1574,7 +1600,7 @@ ble_att_svr_rx_read_blob(uint16_t conn_handle, struct os_mbuf **rxom)
     BLE_ATT_LOG_CMD(0, "read blob req", conn_handle, ble_att_read_blob_req_log,
                     &req);
 
-    ctxt.offset = req.babq_offset;
+    ctxt.read.offset = req.babq_offset;
     rc = ble_att_svr_read_handle(conn_handle, req.babq_handle, &ctxt,
                                  &att_err);
     if (rc != 0) {
@@ -1582,14 +1608,14 @@ ble_att_svr_rx_read_blob(uint16_t conn_handle, struct os_mbuf **rxom)
         goto done;
     }
 
-    if (ctxt.offset + ctxt.data_len <= mtu - 3) {
+    if (ctxt.read.offset + ctxt.read.len <= mtu - 3) {
         att_err = BLE_ATT_ERR_ATTR_NOT_LONG;
         err_handle = req.babq_handle;
         rc = BLE_HS_ENOTSUP;
         goto done;
     }
 
-    rc = ble_att_svr_build_read_blob_rsp(ctxt.attr_data, ctxt.data_len, mtu,
+    rc = ble_att_svr_build_read_blob_rsp(ctxt.read.data, ctxt.read.len, mtu,
                                          &txom, &att_err);
     if (rc != 0) {
         err_handle = req.babq_handle;
@@ -1668,20 +1694,20 @@ ble_att_svr_build_read_mult_rsp(uint16_t conn_handle,
         handle = le16toh((*rxom)->om_data);
         os_mbuf_adj(*rxom, 2);
 
-        ctxt.offset = 0;
+        ctxt.read.offset = 0;
         rc = ble_att_svr_read_handle(conn_handle, handle, &ctxt, att_err);
         if (rc != 0) {
             *err_handle = handle;
             goto done;
         }
 
-        if (ctxt.data_len > tx_space) {
+        if (ctxt.read.len > tx_space) {
             chunk_sz = tx_space;
         } else {
-            chunk_sz = ctxt.data_len;
+            chunk_sz = ctxt.read.len;
         }
 
-        rc = os_mbuf_append(txom, ctxt.attr_data, chunk_sz);
+        rc = os_mbuf_append(txom, ctxt.read.data, chunk_sz);
         if (rc != 0) {
             *att_err = BLE_ATT_ERR_INSUFFICIENT_RES;
             *err_handle = handle;
@@ -1763,20 +1789,20 @@ ble_att_svr_service_uuid(struct ble_att_svr_entry *entry, uint16_t *uuid16,
     struct ble_att_svr_access_ctxt ctxt;
     int rc;
 
-    ctxt.offset = 0;
+    ctxt.read.offset = 0;
     rc = ble_att_svr_read(BLE_HS_CONN_HANDLE_NONE, entry, &ctxt, NULL);
     if (rc != 0) {
         return rc;
     }
 
-    switch (ctxt.data_len) {
+    switch (ctxt.read.len) {
     case 16:
         *uuid16 = 0;
-        memcpy(uuid128, ctxt.attr_data, 16);
+        memcpy(uuid128, ctxt.read.data, 16);
         return 0;
 
     case 2:
-        *uuid16 = le16toh(ctxt.attr_data);
+        *uuid16 = le16toh(ctxt.read.data);
         if (*uuid16 == 0) {
             return BLE_HS_EINVAL;
         }
@@ -2124,6 +2150,7 @@ ble_att_svr_rx_write(uint16_t conn_handle, struct os_mbuf **rxom)
     struct ble_att_svr_access_ctxt ctxt;
     struct ble_att_write_req req;
     struct os_mbuf *txom;
+    void *buf;
     uint16_t err_handle;
     uint8_t att_err;
     int rc;
@@ -2147,9 +2174,11 @@ ble_att_svr_rx_write(uint16_t conn_handle, struct os_mbuf **rxom)
     /* Strip the request base from the front of the mbuf. */
     os_mbuf_adj(*rxom, BLE_ATT_WRITE_REQ_BASE_SZ);
 
-    ctxt.attr_data = ble_att_get_flat_buf();
-    ctxt.data_len = OS_MBUF_PKTLEN(*rxom);
-    os_mbuf_copydata(*rxom, 0, ctxt.data_len, ctxt.attr_data);
+    buf = ble_att_get_flat_buf();
+    ctxt.write.len = OS_MBUF_PKTLEN(*rxom);
+    ctxt.write.data = buf;
+    os_mbuf_copydata(*rxom, 0, ctxt.write.len, buf);
+
     rc = ble_att_svr_write_handle(conn_handle, req.bawq_handle, &ctxt,
                                   &att_err);
     if (rc != 0) {
@@ -2182,6 +2211,7 @@ ble_att_svr_rx_write_no_rsp(uint16_t conn_handle, struct os_mbuf **rxom)
     struct ble_att_svr_access_ctxt ctxt;
     struct ble_att_write_req req;
     uint8_t att_err;
+    void *buf;
     int rc;
 
     rc = ble_att_svr_pullup_req_base(rxom, BLE_ATT_WRITE_REQ_BASE_SZ,
@@ -2197,9 +2227,11 @@ ble_att_svr_rx_write_no_rsp(uint16_t conn_handle, struct os_mbuf **rxom)
     /* Strip the request base from the front of the mbuf. */
     os_mbuf_adj(*rxom, BLE_ATT_WRITE_REQ_BASE_SZ);
 
-    ctxt.attr_data = ble_att_get_flat_buf();
-    ctxt.data_len = OS_MBUF_PKTLEN(*rxom);
-    os_mbuf_copydata(*rxom, 0, ctxt.data_len, ctxt.attr_data);
+    buf = ble_att_get_flat_buf();
+    ctxt.write.len = OS_MBUF_PKTLEN(*rxom);
+    ctxt.write.data = buf;
+    os_mbuf_copydata(*rxom, 0, ctxt.write.len, buf);
+
     rc = ble_att_svr_write_handle(conn_handle, req.bawq_handle, &ctxt,
                                   &att_err);
     if (rc != 0) {
@@ -2210,14 +2242,15 @@ ble_att_svr_rx_write_no_rsp(uint16_t conn_handle, struct os_mbuf **rxom)
 }
 
 int
-ble_att_svr_write_local(uint16_t attr_handle, void *data, uint16_t data_len)
+ble_att_svr_write_local(uint16_t attr_handle, const void *data,
+                        uint16_t data_len)
 {
     struct ble_att_svr_access_ctxt ctxt;
     int rc;
 
-    ctxt.attr_data = data;
-    ctxt.data_len = data_len;
-    ctxt.offset = 0;
+    ctxt.write.data = data;
+    ctxt.write.len = data_len;
+    ctxt.write.offset = 0;
 
     rc = ble_att_svr_write_handle(BLE_HS_CONN_HANDLE_NONE, attr_handle, &ctxt,
                                   NULL);
@@ -2374,8 +2407,8 @@ ble_att_svr_prep_write(uint16_t conn_handle,
                 return BLE_ATT_ERR_INVALID_HANDLE;
             }
 
-            ctxt.attr_data = flat_buf;
-            ctxt.data_len = buf_off;
+            ctxt.write.data = flat_buf;
+            ctxt.write.len = buf_off;
             rc = ble_att_svr_write(conn_handle, attr, &ctxt, &att_err);
             if (rc != 0) {
                 *err_handle = entry->bape_handle;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/63531557/net/nimble/host/src/ble_gap.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gap.c b/net/nimble/host/src/ble_gap.c
index 04f9489..eb7df78 100644
--- a/net/nimble/host/src/ble_gap.c
+++ b/net/nimble/host/src/ble_gap.c
@@ -224,7 +224,8 @@ ble_gap_log_disc(uint8_t own_addr_type, int32_t duration_ms,
 }
 
 static void
-ble_gap_log_update(uint16_t conn_handle, struct ble_gap_upd_params *params)
+ble_gap_log_update(uint16_t conn_handle,
+                   const struct ble_gap_upd_params *params)
 {
     BLE_HS_LOG(INFO, "connection parameter update; "
                      "conn_handle=%d itvl_min=%d itvl_max=%d latency=%d "
@@ -235,10 +236,10 @@ ble_gap_log_update(uint16_t conn_handle, struct ble_gap_upd_params *params)
 }
 
 static void
-ble_gap_log_wl(struct ble_gap_white_entry *white_list,
+ble_gap_log_wl(const struct ble_gap_white_entry *white_list,
                uint8_t white_list_count)
 {
-    struct ble_gap_white_entry *entry;
+    const struct ble_gap_white_entry *entry;
     int i;
 
     BLE_HS_LOG(INFO, "count=%d ", white_list_count);
@@ -1153,7 +1154,7 @@ ble_gap_wl_busy(void)
 }
 
 static int
-ble_gap_wl_tx_add(struct ble_gap_white_entry *entry)
+ble_gap_wl_tx_add(const struct ble_gap_white_entry *entry)
 {
     uint8_t buf[BLE_HCI_CMD_HDR_LEN + BLE_HCI_CHG_WHITE_LIST_LEN];
     int rc;
@@ -1188,7 +1189,7 @@ ble_gap_wl_tx_clear(void)
 }
 
 int
-ble_gap_wl_set(struct ble_gap_white_entry *white_list,
+ble_gap_wl_set(const struct ble_gap_white_entry *white_list,
                uint8_t white_list_count)
 {
 #if !NIMBLE_OPT(WHITELIST)
@@ -1676,7 +1677,7 @@ done:
 }
 
 int
-ble_gap_adv_set_fields(struct ble_hs_adv_fields *adv_fields)
+ble_gap_adv_set_fields(const struct ble_hs_adv_fields *adv_fields)
 {
 #if !NIMBLE_OPT(ADVERTISE)
     return BLE_HS_ENOTSUP;
@@ -1722,7 +1723,7 @@ done:
 }
 
 int
-ble_gap_adv_rsp_set_fields(struct ble_hs_adv_fields *rsp_fields)
+ble_gap_adv_rsp_set_fields(const struct ble_hs_adv_fields *rsp_fields)
 {
 #if !NIMBLE_OPT(ADVERTISE)
     return BLE_HS_ENOTSUP;
@@ -2303,7 +2304,8 @@ ble_gap_rx_param_req(struct hci_le_conn_param_req *evt)
 }
 
 static int
-ble_gap_update_tx(uint16_t conn_handle, struct ble_gap_upd_params *params)
+ble_gap_update_tx(uint16_t conn_handle,
+                  const struct ble_gap_upd_params *params)
 {
     uint8_t buf[BLE_HCI_CMD_HDR_LEN + BLE_HCI_CONN_UPDATE_LEN];
     struct hci_conn_update cmd;
@@ -2331,7 +2333,8 @@ ble_gap_update_tx(uint16_t conn_handle, struct ble_gap_upd_params *params)
 }
 
 int
-ble_gap_update_params(uint16_t conn_handle, struct ble_gap_upd_params *params)
+ble_gap_update_params(uint16_t conn_handle,
+                      const struct ble_gap_upd_params *params)
 {
 #if !NIMBLE_OPT(CONNECT)
     return BLE_HS_ENOTSUP;
@@ -2460,7 +2463,7 @@ ble_gap_pair_initiate(uint16_t conn_handle)
 
 int
 ble_gap_encryption_initiate(uint16_t conn_handle,
-                            uint8_t *ltk,
+                            const uint8_t *ltk,
                             uint16_t ediv,
                             uint64_t rand_val,
                             int auth)
@@ -2579,7 +2582,7 @@ ble_gap_notify_event(uint16_t conn_handle, uint16_t attr_handle,
 }
 
 void
-ble_gap_init_identity_addr(uint8_t *addr)
+ble_gap_init_identity_addr(const uint8_t *addr)
 {
     ble_hs_pvcy_set_our_id_addr(addr);
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/63531557/net/nimble/host/src/ble_gatt_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gatt_priv.h b/net/nimble/host/src/ble_gatt_priv.h
index 2358994..9b4ae8a 100644
--- a/net/nimble/host/src/ble_gatt_priv.h
+++ b/net/nimble/host/src/ble_gatt_priv.h
@@ -97,8 +97,6 @@ struct ble_gatts_conn {
 
 /*** @client. */
 int ble_gattc_locked_by_cur_task(void);
-int ble_gattc_write(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_indicate(uint16_t conn_handle, uint16_t chr_val_handle,
                        ble_gatt_attr_fn *cb, void *cb_arg);
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/63531557/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 4741959..98e90cd 100644
--- a/net/nimble/host/src/ble_gattc.c
+++ b/net/nimble/host/src/ble_gattc.c
@@ -182,7 +182,7 @@ struct ble_gattc_proc {
         } write_long;
 
         struct {
-            struct ble_gatt_attr *attrs;
+            const struct ble_gatt_attr *attrs;
             int num_attrs;
             int cur_attr;
             ble_gatt_reliable_attr_fn *cb;
@@ -393,9 +393,9 @@ ble_gattc_log_proc_init(char *name)
 }
 
 static void
-ble_gattc_log_uuid(void *uuid128)
+ble_gattc_log_uuid(const void *uuid128)
 {
-    uint8_t *u8p;
+    const uint8_t *u8p;
 
     u8p = uuid128;
     BLE_HS_LOG(INFO, "%02x%02x%02x%02x-%02x%02x-%02x%02x-"
@@ -461,7 +461,7 @@ ble_gattc_log_read(uint16_t att_handle)
 
 static void
 ble_gattc_log_read_uuid(uint16_t start_handle, uint16_t end_handle,
-                        uint8_t *uuid128)
+                        const uint8_t *uuid128)
 {
     uint16_t uuid16;
 
@@ -486,7 +486,7 @@ ble_gattc_log_read_long(struct ble_gattc_proc *proc)
 }
 
 static void
-ble_gattc_log_read_mult(uint16_t *handles, uint8_t num_handles)
+ble_gattc_log_read_mult(const uint16_t *handles, uint8_t num_handles)
 {
     int i;
 
@@ -1368,7 +1368,7 @@ ble_gattc_disc_svc_uuid_rx_complete(struct ble_gattc_proc *proc, int status)
  * @param cb_arg                The argument to pass to the callback function.
  */
 int
-ble_gattc_disc_svc_by_uuid(uint16_t conn_handle, void *service_uuid128,
+ble_gattc_disc_svc_by_uuid(uint16_t conn_handle, const void *svc_uuid128,
                            ble_gatt_disc_svc_fn *cb, void *cb_arg)
 {
 #if !NIMBLE_OPT(GATT_DISC_SVC_UUID)
@@ -1388,7 +1388,7 @@ ble_gattc_disc_svc_by_uuid(uint16_t conn_handle, void *service_uuid128,
 
     proc->op = BLE_GATT_OP_DISC_SVC_UUID;
     proc->conn_handle = conn_handle;
-    memcpy(proc->disc_svc_uuid.service_uuid, service_uuid128, 16);
+    memcpy(proc->disc_svc_uuid.service_uuid, svc_uuid128, 16);
     proc->disc_svc_uuid.prev_handle = 0x0000;
     proc->disc_svc_uuid.cb = cb;
     proc->disc_svc_uuid.cb_arg = cb_arg;
@@ -2135,7 +2135,7 @@ ble_gattc_disc_chr_uuid_rx_complete(struct ble_gattc_proc *proc, int status)
  */
 int
 ble_gattc_disc_chrs_by_uuid(uint16_t conn_handle, uint16_t start_handle,
-                            uint16_t end_handle, void *uuid128,
+                            uint16_t end_handle, const void *uuid128,
                             ble_gatt_chr_fn *cb, void *cb_arg)
 {
 #if !NIMBLE_OPT(GATT_DISC_CHR_UUID)
@@ -2603,7 +2603,7 @@ ble_gattc_read_uuid_rx_complete(struct ble_gattc_proc *proc, int status)
  */
 int
 ble_gattc_read_by_uuid(uint16_t conn_handle, uint16_t start_handle,
-                       uint16_t end_handle, void *uuid128,
+                       uint16_t end_handle, const void *uuid128,
                        ble_gatt_attr_fn *cb, void *cb_arg)
 {
 #if !NIMBLE_OPT(GATT_READ_UUID)
@@ -2894,7 +2894,7 @@ ble_gattc_read_mult_err(struct ble_gattc_proc *proc, int status,
  * @param cb_arg                The argument to pass to the callback function.
  */
 int
-ble_gattc_read_mult(uint16_t conn_handle, uint16_t *handles,
+ble_gattc_read_mult(uint16_t conn_handle, const uint16_t *handles,
                     uint8_t num_handles, ble_gatt_attr_fn *cb,
                     void *cb_arg)
 {
@@ -2952,8 +2952,8 @@ done:
  * @param cb_arg                The argument to pass to the callback function.
  */
 int
-ble_gattc_write_no_rsp(uint16_t conn_handle, uint16_t attr_handle, void *value,
-                       uint16_t value_len)
+ble_gattc_write_no_rsp(uint16_t conn_handle, uint16_t attr_handle,
+                       const void *value, uint16_t value_len)
 {
 #if !NIMBLE_OPT(GATT_WRITE_NO_RSP)
     return BLE_HS_ENOTSUP;
@@ -3039,7 +3039,7 @@ ble_gattc_write_err(struct ble_gattc_proc *proc, int status,
  * @param cb_arg                The argument to pass to the callback function.
  */
 int
-ble_gattc_write(uint16_t conn_handle, uint16_t attr_handle, void *value,
+ble_gattc_write(uint16_t conn_handle, uint16_t attr_handle, const void *value,
                 uint16_t value_len, ble_gatt_attr_fn *cb, void *cb_arg)
 {
 #if !NIMBLE_OPT(GATT_WRITE)
@@ -3126,7 +3126,7 @@ ble_gattc_write_long_go(struct ble_gattc_proc *proc, int cb_on_err)
 {
     struct ble_att_prep_write_cmd prep_req;
     struct ble_att_exec_write_req exec_req;
-    void *value;
+    const void *value;
     int max_sz;
     int rc;
 
@@ -3276,8 +3276,9 @@ ble_gattc_write_long_rx_exec(struct ble_gattc_proc *proc, int status)
  * @param cb_arg                The argument to pass to the callback function.
  */
 int
-ble_gattc_write_long(uint16_t conn_handle, uint16_t attr_handle, void *value,
-                     uint16_t value_len, ble_gatt_attr_fn *cb, void *cb_arg)
+ble_gattc_write_long(uint16_t conn_handle, uint16_t attr_handle,
+                     const void *value, uint16_t value_len,
+                     ble_gatt_attr_fn *cb, void *cb_arg)
 {
 #if !NIMBLE_OPT(GATT_WRITE_LONG)
     return BLE_HS_ENOTSUP;
@@ -3365,7 +3366,7 @@ ble_gattc_write_reliable_go(struct ble_gattc_proc *proc, int cb_on_err)
 {
     struct ble_att_prep_write_cmd prep_req;
     struct ble_att_exec_write_req exec_req;
-    struct ble_gatt_attr *attr;
+    const struct ble_gatt_attr *attr;
     int attr_idx;
     int rc;
 
@@ -3427,7 +3428,7 @@ ble_gattc_write_reliable_rx_prep(struct ble_gattc_proc *proc,
                                  struct ble_att_prep_write_cmd *rsp,
                                  void *attr_data, uint16_t attr_len)
 {
-    struct ble_gatt_attr *attr;
+    const struct ble_gatt_attr *attr;
     int rc;
 
     ble_gattc_dbg_assert_proc_not_inserted(proc);
@@ -3502,7 +3503,8 @@ ble_gattc_write_reliable_rx_exec(struct ble_gattc_proc *proc, int status)
  * @param cb_arg                The argument to pass to the callback function.
  */
 int
-ble_gattc_write_reliable(uint16_t conn_handle, struct ble_gatt_attr *attrs,
+ble_gattc_write_reliable(uint16_t conn_handle,
+                         const struct ble_gatt_attr *attrs,
                          int num_attrs, ble_gatt_reliable_attr_fn *cb,
                          void *cb_arg)
 {
@@ -3555,7 +3557,7 @@ done:
  */
 int
 ble_gattc_notify_custom(uint16_t conn_handle, uint16_t att_handle,
-                        void *attr_data, uint16_t attr_data_len)
+                        const void *attr_data, uint16_t attr_data_len)
 {
 #if !NIMBLE_OPT(GATT_NOTIFY)
     return BLE_HS_ENOTSUP;
@@ -3580,15 +3582,13 @@ ble_gattc_notify_custom(uint16_t conn_handle, uint16_t att_handle,
             rc = BLE_HS_EAPP;
             goto err;
         }
-    } else {
-        ctxt.attr_data = attr_data;
-        ctxt.data_len = attr_data_len;
-        ctxt.offset = 0;
+
+        attr_data = ctxt.read.data;
+        attr_data_len = ctxt.read.len;
     }
 
     req.banq_handle = att_handle;
-    rc = ble_att_clt_tx_notify(conn_handle, &req,
-                               ctxt.attr_data, ctxt.data_len);
+    rc = ble_att_clt_tx_notify(conn_handle, &req, attr_data, attr_data_len);
     if (rc != 0) {
         goto err;
     }
@@ -3735,7 +3735,7 @@ ble_gattc_indicate(uint16_t conn_handle, uint16_t chr_val_handle,
 
     req.baiq_handle = chr_val_handle;
     rc = ble_att_clt_tx_indicate(conn_handle, &req,
-                                 ctxt.attr_data, ctxt.data_len);
+                                 ctxt.read.data, ctxt.read.len);
 
     if (rc != 0) {
         goto done;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/63531557/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 9c30ed1..320ee65 100644
--- a/net/nimble/host/src/ble_gatts.c
+++ b/net/nimble/host/src/ble_gatts.c
@@ -70,7 +70,7 @@ ble_gatts_svc_access(uint16_t conn_handle, uint16_t attr_handle,
                      struct ble_att_svr_access_ctxt *ctxt, void *arg)
 {
     const struct ble_gatt_svc_def *svc;
-    static uint16_t uuid16;
+    uint16_t uuid16;
 
     STATS_INC(ble_gatts_stats, svc_def_reads);
 
@@ -80,13 +80,11 @@ ble_gatts_svc_access(uint16_t conn_handle, uint16_t attr_handle,
 
     uuid16 = ble_uuid_128_to_16(svc->uuid128);
     if (uuid16 != 0) {
-        htole16(&uuid16, uuid16);
-        ctxt->attr_data = &uuid16;
-        ctxt->data_len = 2;
+        htole16(ctxt->read.buf, uuid16);
+        ctxt->read.len = 2;
     } else {
-        /* Cast away const. */
-        ctxt->attr_data = (void *)svc->uuid128;
-        ctxt->data_len = 16;
+        ctxt->read.data = svc->uuid128;
+        ctxt->read.len = 16;
     }
 
     return 0;
@@ -115,11 +113,11 @@ ble_gatts_inc_access(uint16_t conn_handle, uint16_t attr_handle,
     uuid16 = ble_uuid_128_to_16(entry->svc->uuid128);
     if (uuid16 != 0) {
         htole16(buf + 4, uuid16);
-        ctxt->data_len = 6;
+        ctxt->read.len = 6;
     } else {
-        ctxt->data_len = 4;
+        ctxt->read.len = 4;
     }
-    ctxt->attr_data = buf;
+    ctxt->read.data = buf;
 
     return 0;
 }
@@ -216,7 +214,6 @@ ble_gatts_chr_def_access(uint16_t conn_handle, uint16_t attr_handle,
                          uint8_t *uuid128, uint8_t op,
                          struct ble_att_svr_access_ctxt *ctxt, void *arg)
 {
-    static uint8_t buf[BLE_GATTS_CHR_MAX_SZ];
     const struct ble_gatt_chr_def *chr;
     uint16_t uuid16;
 
@@ -226,20 +223,19 @@ ble_gatts_chr_def_access(uint16_t conn_handle, uint16_t attr_handle,
 
     chr = arg;
 
-    buf[0] = ble_gatts_chr_properties(chr);
+    ctxt->read.buf[0] = ble_gatts_chr_properties(chr);
 
     /* The value attribute is always immediately after the declaration. */
-    htole16(buf + 1, attr_handle + 1);
+    htole16(ctxt->read.buf + 1, attr_handle + 1);
 
     uuid16 = ble_uuid_128_to_16(chr->uuid128);
     if (uuid16 != 0) {
-        htole16(buf + 3, uuid16);
-        ctxt->data_len = 5;
+        htole16(ctxt->read.buf + 3, uuid16);
+        ctxt->read.len = 5;
     } else {
-        memcpy(buf + 3, chr->uuid128, 16);
-        ctxt->data_len = 19;
+        memcpy(ctxt->read.buf + 3, chr->uuid128, 16);
+        ctxt->read.len = 19;
     }
-    ctxt->attr_data = buf;
 
     return 0;
 }
@@ -293,88 +289,34 @@ ble_gatts_chr_inc_val_stat(uint8_t gatt_op)
     }
 }
 
-static uint16_t
-ble_gatts_max_read_len(uint16_t conn_handle)
-{
-    uint16_t mtu;
-
-    if (conn_handle == BLE_HS_CONN_HANDLE_NONE) {
-        /* The application is reading from itself; no MTU. */
-        mtu = BLE_ATT_MTU_MAX;
-    } else {
-        mtu = ble_att_mtu(conn_handle);
-    }
-
-    /* Subtract one to account for the att-read-response header. */
-    BLE_HS_DBG_ASSERT(mtu > 0);
-    return mtu - 1;
-}
-
 static int
 ble_gatts_chr_val_access(uint16_t conn_handle, uint16_t attr_handle,
                          uint8_t *uuid128, uint8_t att_op,
                          struct ble_att_svr_access_ctxt *att_ctxt, void *arg)
 {
-    const struct ble_gatt_chr_def *chr;
-    union ble_gatt_access_ctxt gatt_ctxt;
+    const struct ble_gatt_chr_def *chr_def;
+    struct ble_gatt_access_ctxt gatt_ctxt;
     uint8_t gatt_op;
     int rc;
 
-
-    chr = arg;
-    BLE_HS_DBG_ASSERT(chr != NULL && chr->access_cb != NULL);
-    gatt_ctxt.chr.def = chr;
+    chr_def = arg;
+    BLE_HS_DBG_ASSERT(chr_def != NULL && chr_def->access_cb != NULL);
 
     gatt_op = ble_gatts_chr_op(att_op);
-    switch (gatt_op) {
-    case BLE_GATT_ACCESS_OP_READ_CHR:
-        gatt_ctxt.chr.read.max_data_len = ble_gatts_max_read_len(conn_handle);
-        gatt_ctxt.chr.read.len = 0;
-
-        /* Give the application access to the ATT flat buffer in case it needs
-         * to generate the read response dynamically. */
-        gatt_ctxt.chr.read.buf = ble_att_get_flat_buf();
-        gatt_ctxt.chr.read.data = gatt_ctxt.chr.read.buf;
-        break;
-
-    case BLE_GATT_ACCESS_OP_WRITE_CHR:
-        gatt_ctxt.chr.write.data = att_ctxt->attr_data;
-        gatt_ctxt.chr.write.len = att_ctxt->data_len;
-        break;
-
-    default:
-        BLE_HS_DBG_ASSERT(0);
-        return BLE_HS_EUNKNOWN;
-    }
-
     ble_gatts_chr_inc_val_stat(gatt_op);
 
-    rc = chr->access_cb(conn_handle, attr_handle, gatt_op, &gatt_ctxt,
-                        chr->arg);
+    gatt_ctxt.chr = chr_def;
+    gatt_ctxt.att = att_ctxt;
+    rc = chr_def->access_cb(conn_handle, attr_handle, gatt_op, &gatt_ctxt,
+                            chr_def->arg);
     if (rc != 0) {
         return rc;
     }
 
-    switch (gatt_op) {
-    case BLE_GATT_ACCESS_OP_READ_CHR:
-        /* Cast-away const. */
-        att_ctxt->attr_data = (void *)gatt_ctxt.chr.read.data;
-        att_ctxt->data_len = gatt_ctxt.chr.read.len;
-        break;
+    if (gatt_op == BLE_GATT_ACCESS_OP_WRITE_CHR &&
+        ble_gatts_chr_clt_cfg_allowed(chr_def)) {
 
-    case BLE_GATT_ACCESS_OP_WRITE_CHR:
-        /* Cast-away const. */
-        att_ctxt->attr_data = (void *)gatt_ctxt.chr.write.data;
-        att_ctxt->data_len = gatt_ctxt.chr.write.len;
-
-        if (ble_gatts_chr_clt_cfg_allowed(chr)) {
-            ble_gatts_chr_updated(attr_handle - 1);
-        }
-        break;
-
-    default:
-        BLE_HS_DBG_ASSERT(0);
-        return BLE_HS_EUNKNOWN;
+        ble_gatts_chr_updated(attr_handle - 1);
     }
 
     return 0;
@@ -471,31 +413,20 @@ ble_gatts_dsc_access(uint16_t conn_handle, uint16_t attr_handle,
                      uint8_t *uuid128, uint8_t att_op,
                      struct ble_att_svr_access_ctxt *att_ctxt, void *arg)
 {
-    const struct ble_gatt_dsc_def *dsc;
-    union ble_gatt_access_ctxt gatt_ctxt;
+    struct ble_gatt_access_ctxt gatt_ctxt;
+    const struct ble_gatt_dsc_def *dsc_def;
     uint8_t gatt_op;
     int rc;
 
-    dsc = arg;
-    BLE_HS_DBG_ASSERT(dsc != NULL && dsc->access_cb != NULL);
-    gatt_ctxt.dsc.def = dsc;
+    dsc_def = arg;
+    BLE_HS_DBG_ASSERT(dsc_def != NULL && dsc_def->access_cb != NULL);
 
     gatt_op = ble_gatts_dsc_op(att_op);
     switch (gatt_op) {
     case BLE_GATT_ACCESS_OP_READ_DSC:
-        gatt_ctxt.dsc.read.max_data_len = ble_gatts_max_read_len(conn_handle);
-
-        gatt_ctxt.dsc.read.len = 0;
-
-        /* Give the application access to the ATT flat buffer in case it needs
-         * to generate the read response dynamically. */
-        gatt_ctxt.dsc.read.buf = ble_att_get_flat_buf();
-        gatt_ctxt.dsc.read.data = gatt_ctxt.dsc.read.buf;
         break;
 
     case BLE_GATT_ACCESS_OP_WRITE_DSC:
-        gatt_ctxt.dsc.write.data = att_ctxt->attr_data;
-        gatt_ctxt.dsc.write.len = att_ctxt->data_len;
         break;
 
     default:
@@ -505,30 +436,14 @@ ble_gatts_dsc_access(uint16_t conn_handle, uint16_t attr_handle,
 
     ble_gatts_dsc_inc_stat(gatt_op);
 
-    rc = dsc->access_cb(conn_handle, attr_handle, gatt_op, &gatt_ctxt,
-                        dsc->arg);
+    gatt_ctxt.dsc = dsc_def;
+    gatt_ctxt.att = att_ctxt;
+    rc = dsc_def->access_cb(conn_handle, attr_handle, gatt_op, &gatt_ctxt,
+                            dsc_def->arg);
     if (rc != 0) {
         return rc;
     }
 
-    switch (gatt_op) {
-    case BLE_GATT_ACCESS_OP_READ_DSC:
-        /* Cast-away const. */
-        att_ctxt->attr_data = (void *)gatt_ctxt.dsc.read.data;
-        att_ctxt->data_len = gatt_ctxt.dsc.read.len;
-        break;
-
-    case BLE_GATT_ACCESS_OP_WRITE_DSC:
-        /* Cast-away const. */
-        att_ctxt->attr_data = (void *)gatt_ctxt.dsc.write.data;
-        att_ctxt->data_len = gatt_ctxt.dsc.write.len;
-        break;
-
-    default:
-        BLE_HS_DBG_ASSERT(0);
-        return BLE_HS_EUNKNOWN;
-    }
-
     return 0;
 }
 
@@ -670,17 +585,17 @@ ble_gatts_clt_cfg_access_locked(struct ble_hs_conn *conn, uint16_t attr_handle,
     case BLE_GATT_ACCESS_OP_READ_DSC:
         STATS_INC(ble_gatts_stats, dsc_reads);
         htole16(buf, clt_cfg->flags & ~BLE_GATTS_CLT_CFG_F_RESERVED);
-        ctxt->attr_data = buf;
-        ctxt->data_len = sizeof buf;
+        ctxt->read.data = buf;
+        ctxt->read.len = sizeof buf;
         break;
 
     case BLE_GATT_ACCESS_OP_WRITE_DSC:
         STATS_INC(ble_gatts_stats, dsc_writes);
-        if (ctxt->data_len != 2) {
+        if (ctxt->write.len != 2) {
             return BLE_ATT_ERR_INVALID_ATTR_VALUE_LEN;
         }
 
-        flags = le16toh(ctxt->attr_data);
+        flags = le16toh(ctxt->write.data);
         if ((flags & ~clt_cfg->allowed) != 0) {
             return BLE_ATT_ERR_WRITE_NOT_PERMITTED;
         }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/63531557/net/nimble/host/src/ble_hs_adv.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_adv.c b/net/nimble/host/src/ble_hs_adv.c
index 83dd416..dffbc1f 100644
--- a/net/nimble/host/src/ble_hs_adv.c
+++ b/net/nimble/host/src/ble_hs_adv.c
@@ -40,7 +40,7 @@ ble_hs_adv_set_hdr(uint8_t type, uint8_t data_len, uint8_t max_len,
 }
 
 int
-ble_hs_adv_set_flat(uint8_t type, int data_len, void *data,
+ble_hs_adv_set_flat(uint8_t type, int data_len, const void *data,
                     uint8_t *dst, uint8_t *dst_len, uint8_t max_len)
 {
 #if !NIMBLE_OPT(ADVERTISE)
@@ -63,7 +63,7 @@ ble_hs_adv_set_flat(uint8_t type, int data_len, void *data,
 }
 
 static int
-ble_hs_adv_set_array16(uint8_t type, uint8_t num_elems, uint16_t *elems,
+ble_hs_adv_set_array16(uint8_t type, uint8_t num_elems, const uint16_t *elems,
                        uint8_t *dst, uint8_t *dst_len, uint8_t max_len)
 {
     int rc;
@@ -84,7 +84,7 @@ ble_hs_adv_set_array16(uint8_t type, uint8_t num_elems, uint16_t *elems,
 }
 
 static int
-ble_hs_adv_set_array32(uint8_t type, uint8_t num_elems, uint32_t *elems,
+ble_hs_adv_set_array32(uint8_t type, uint8_t num_elems, const uint32_t *elems,
                        uint8_t *dst, uint8_t *dst_len, uint8_t max_len)
 {
     int rc;
@@ -110,7 +110,7 @@ ble_hs_adv_set_array32(uint8_t type, uint8_t num_elems, uint32_t *elems,
  * @return                      0 on success;  on failure.
  */
 int
-ble_hs_adv_set_fields(struct ble_hs_adv_fields *adv_fields,
+ble_hs_adv_set_fields(const struct ble_hs_adv_fields *adv_fields,
                       uint8_t *dst, uint8_t *dst_len, uint8_t max_len)
 {
 #if !NIMBLE_OPT(ADVERTISE)

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/63531557/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 1eeb57f..d3a9524 100644
--- a/net/nimble/host/src/ble_hs_priv.h
+++ b/net/nimble/host/src/ble_hs_priv.h
@@ -105,8 +105,8 @@ void ble_hci_cmd_rx_ack(uint8_t *ack_ev);
 void ble_hci_cmd_init(void);
 int ble_hs_pvcy_set_our_nrpa(void);
 void ble_hs_pvcy_our_nrpa(uint8_t *addr);
-void ble_hs_pvcy_set_our_id_addr(uint8_t *addr);
-void ble_hs_pvcy_set_our_irk(uint8_t *irk);
+void ble_hs_pvcy_set_our_id_addr(const uint8_t *addr);
+void ble_hs_pvcy_set_our_irk(const uint8_t *irk);
 uint8_t *ble_hs_pvcy_our_id_addr(uint8_t *type);
 uint8_t *ble_hs_pvcy_our_irk(void);
 int ble_hs_pvcy_remove_entry(uint8_t addr_type, uint8_t *addr);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/63531557/net/nimble/host/src/ble_hs_pvcy.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_pvcy.c b/net/nimble/host/src/ble_hs_pvcy.c
index 1ea2f91..01b74d1 100644
--- a/net/nimble/host/src/ble_hs_pvcy.c
+++ b/net/nimble/host/src/ble_hs_pvcy.c
@@ -176,7 +176,7 @@ ble_hs_pvcy_our_id_addr(uint8_t *type)
 }
 
 void
-ble_hs_pvcy_set_our_id_addr(uint8_t *addr)
+ble_hs_pvcy_set_our_id_addr(const uint8_t *addr)
 {
     uint8_t random_addr[6];
     int rc;
@@ -204,7 +204,7 @@ ble_hs_pvcy_set_our_id_addr(uint8_t *addr)
 }
 
 void
-ble_hs_pvcy_set_our_irk(uint8_t *irk)
+ble_hs_pvcy_set_our_irk(const uint8_t *irk)
 {
     uint8_t tmp_addr[6];
     uint8_t new_irk[16];

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/63531557/net/nimble/host/src/ble_sm.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_sm.c b/net/nimble/host/src/ble_sm.c
index fbd2c59..5f9ad05 100644
--- a/net/nimble/host/src/ble_sm.c
+++ b/net/nimble/host/src/ble_sm.c
@@ -2153,7 +2153,7 @@ ble_sm_slave_initiate(uint16_t conn_handle)
  * Initiates the encryption procedure for the specified connection.
  */
 int
-ble_sm_enc_initiate(uint16_t conn_handle, uint8_t *ltk, uint16_t ediv,
+ble_sm_enc_initiate(uint16_t conn_handle, const uint8_t *ltk, uint16_t ediv,
                     uint64_t rand_val, int auth)
 {
     struct ble_sm_result res;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/63531557/net/nimble/host/src/ble_sm_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_sm_priv.h b/net/nimble/host/src/ble_sm_priv.h
index 707f589..71af1a3 100644
--- a/net/nimble/host/src/ble_sm_priv.h
+++ b/net/nimble/host/src/ble_sm_priv.h
@@ -456,7 +456,7 @@ int32_t ble_sm_heartbeat(void);
 void ble_sm_connection_broken(uint16_t conn_handle);
 int ble_sm_pair_initiate(uint16_t conn_handle);
 int ble_sm_slave_initiate(uint16_t conn_handle);
-int ble_sm_enc_initiate(uint16_t conn_handle, uint8_t *ltk,
+int ble_sm_enc_initiate(uint16_t conn_handle, const uint8_t *ltk,
                         uint16_t ediv, uint64_t rand_val, int auth);
 int ble_sm_init(void);
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/63531557/net/nimble/host/src/ble_uuid.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_uuid.c b/net/nimble/host/src/ble_uuid.c
index 7c0ba4a..118b6ea 100644
--- a/net/nimble/host/src/ble_uuid.c
+++ b/net/nimble/host/src/ble_uuid.c
@@ -86,7 +86,7 @@ ble_uuid_16_to_128(uint16_t uuid16, void *uuid128)
 }
 
 int
-ble_uuid_append(struct os_mbuf *om, void *uuid128)
+ble_uuid_append(struct os_mbuf *om, const void *uuid128)
 {
     uint16_t uuid16;
     void *buf;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/63531557/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 baebed3..c1151fc 100644
--- a/net/nimble/host/src/host_hci_cmd.c
+++ b/net/nimble/host/src/host_hci_cmd.c
@@ -71,7 +71,7 @@ host_hci_write_hdr(uint8_t ogf, uint8_t ocf, uint8_t len, void *buf)
 }
 
 int
-host_hci_cmd_send(uint8_t ogf, uint8_t ocf, uint8_t len, void *cmddata)
+host_hci_cmd_send(uint8_t ogf, uint8_t ocf, uint8_t len, const void *cmddata)
 {
     int rc;
 
@@ -131,7 +131,7 @@ host_hci_le_cmd_send(uint16_t ocf, uint8_t len, void *cmddata)
 }
 
 static int
-host_hci_cmd_body_le_whitelist_chg(uint8_t *addr, uint8_t addr_type,
+host_hci_cmd_body_le_whitelist_chg(const uint8_t *addr, uint8_t addr_type,
                                    uint8_t *dst)
 {
     if (addr_type > BLE_ADDR_TYPE_RANDOM) {
@@ -145,7 +145,8 @@ host_hci_cmd_body_le_whitelist_chg(uint8_t *addr, uint8_t addr_type,
 }
 
 static int
-host_hci_cmd_body_le_set_adv_params(struct hci_adv_params *adv, uint8_t *dst)
+host_hci_cmd_body_le_set_adv_params(const struct hci_adv_params *adv,
+                                    uint8_t *dst)
 {
     uint16_t itvl;
 
@@ -192,8 +193,8 @@ host_hci_cmd_body_le_set_adv_params(struct hci_adv_params *adv, uint8_t *dst)
 }
 
 int
-host_hci_cmd_build_le_set_adv_params(struct hci_adv_params *adv, uint8_t *dst,
-                                     int dst_len)
+host_hci_cmd_build_le_set_adv_params(const struct hci_adv_params *adv,
+                                     uint8_t *dst, int dst_len)
 {
     int rc;
 
@@ -225,7 +226,8 @@ host_hci_cmd_build_le_set_adv_params(struct hci_adv_params *adv, uint8_t *dst,
  * @return int
  */
 static int
-host_hci_cmd_body_le_set_adv_data(uint8_t *data, uint8_t len, uint8_t *dst)
+host_hci_cmd_body_le_set_adv_data(const uint8_t *data, uint8_t len,
+                                  uint8_t *dst)
 {
     /* Check for valid parameters */
     if (((data == NULL) && (len != 0)) || (len > BLE_HCI_MAX_ADV_DATA_LEN)) {
@@ -252,8 +254,8 @@ host_hci_cmd_body_le_set_adv_data(uint8_t *data, uint8_t len, uint8_t *dst)
  * @return int
  */
 int
-host_hci_cmd_build_le_set_adv_data(uint8_t *data, uint8_t len, uint8_t *dst,
-                                   int dst_len)
+host_hci_cmd_build_le_set_adv_data(const uint8_t *data, uint8_t len,
+                                   uint8_t *dst, int dst_len)
 {
     int rc;
 
@@ -273,7 +275,7 @@ host_hci_cmd_build_le_set_adv_data(uint8_t *data, uint8_t len, uint8_t *dst,
 }
 
 static int
-host_hci_cmd_body_le_set_scan_rsp_data(uint8_t *data, uint8_t len,
+host_hci_cmd_body_le_set_scan_rsp_data(const uint8_t *data, uint8_t len,
                                        uint8_t *dst)
 {
     /* Check for valid parameters */
@@ -290,7 +292,7 @@ host_hci_cmd_body_le_set_scan_rsp_data(uint8_t *data, uint8_t len,
 }
 
 int
-host_hci_cmd_build_le_set_scan_rsp_data(uint8_t *data, uint8_t len,
+host_hci_cmd_build_le_set_scan_rsp_data(const uint8_t *data, uint8_t len,
                                         uint8_t *dst, int dst_len)
 {
     int rc;
@@ -333,7 +335,7 @@ host_hci_cmd_build_set_event_mask(uint64_t event_mask,
 
 void
 host_hci_cmd_build_set_event_mask2(uint64_t event_mask,
-                                  uint8_t *dst, int dst_len)
+                                   uint8_t *dst, int dst_len)
 {
     BLE_HS_DBG_ASSERT(
         dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_EVENT_MASK_LEN);
@@ -509,20 +511,20 @@ host_hci_cmd_build_le_set_scan_params(uint8_t scan_type, uint16_t scan_itvl,
                                       uint16_t scan_window,
                                       uint8_t own_addr_type,
                                       uint8_t filter_policy,
-                                      uint8_t *cmd, int cmd_len)
+                                      uint8_t *dst, int dst_len)
 {
     int rc;
 
     BLE_HS_DBG_ASSERT(
-        cmd_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_SCAN_PARAM_LEN);
+        dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_SCAN_PARAM_LEN);
 
     host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_SET_SCAN_PARAMS,
-                       BLE_HCI_SET_SCAN_PARAM_LEN, cmd);
-    cmd += BLE_HCI_CMD_HDR_LEN;
+                       BLE_HCI_SET_SCAN_PARAM_LEN, dst);
+    dst += BLE_HCI_CMD_HDR_LEN;
 
     rc = host_hci_cmd_body_le_set_scan_params(scan_type, scan_itvl,
                                               scan_window, own_addr_type,
-                                              filter_policy, cmd);
+                                              filter_policy, dst);
     if (rc != 0) {
         return rc;
     }
@@ -553,7 +555,7 @@ host_hci_cmd_build_le_set_scan_enable(uint8_t enable, uint8_t filter_dups,
 }
 
 static int
-host_hci_cmd_body_le_create_connection(struct hci_create_conn *hcc,
+host_hci_cmd_body_le_create_connection(const struct hci_create_conn *hcc,
                                        uint8_t *cmd)
 {
     /* Check scan interval and scan window */
@@ -627,7 +629,7 @@ host_hci_cmd_body_le_create_connection(struct hci_create_conn *hcc,
 }
 
 int
-host_hci_cmd_build_le_create_connection(struct hci_create_conn *hcc,
+host_hci_cmd_build_le_create_connection(const struct hci_create_conn *hcc,
                                         uint8_t *cmd, int cmd_len)
 {
     int rc;
@@ -656,7 +658,7 @@ host_hci_cmd_build_le_clear_whitelist(uint8_t *dst, int dst_len)
 }
 
 int
-host_hci_cmd_build_le_add_to_whitelist(uint8_t *addr, uint8_t addr_type,
+host_hci_cmd_build_le_add_to_whitelist(const uint8_t *addr, uint8_t addr_type,
                                        uint8_t *dst, int dst_len)
 {
     int rc;
@@ -741,7 +743,8 @@ host_hci_cmd_le_create_conn_cancel(void)
 }
 
 static int
-host_hci_cmd_body_le_conn_update(struct hci_conn_update *hcu, uint8_t *dst)
+host_hci_cmd_body_le_conn_update(const struct hci_conn_update *hcu,
+                                 uint8_t *dst)
 {
     /* XXX: add parameter checking later */
     htole16(dst + 0, hcu->handle);
@@ -756,8 +759,8 @@ host_hci_cmd_body_le_conn_update(struct hci_conn_update *hcu, uint8_t *dst)
 }
 
 int
-host_hci_cmd_build_le_conn_update(struct hci_conn_update *hcu, uint8_t *dst,
-                                  int dst_len)
+host_hci_cmd_build_le_conn_update(const struct hci_conn_update *hcu,
+                                  uint8_t *dst, int dst_len)
 {
     int rc;
 
@@ -777,7 +780,7 @@ host_hci_cmd_build_le_conn_update(struct hci_conn_update *hcu, uint8_t *dst,
 }
 
 int
-host_hci_cmd_le_conn_update(struct hci_conn_update *hcu)
+host_hci_cmd_le_conn_update(const struct hci_conn_update *hcu)
 {
     uint8_t cmd[BLE_HCI_CONN_UPDATE_LEN];
     int rc;
@@ -797,7 +800,7 @@ host_hci_cmd_le_conn_update(struct hci_conn_update *hcu)
 }
 
 static void
-host_hci_cmd_body_le_lt_key_req_reply(struct hci_lt_key_req_reply *hkr,
+host_hci_cmd_body_le_lt_key_req_reply(const struct hci_lt_key_req_reply *hkr,
                                       uint8_t *dst)
 {
     htole16(dst + 0, hkr->conn_handle);
@@ -819,7 +822,7 @@ host_hci_cmd_body_le_lt_key_req_reply(struct hci_lt_key_req_reply *hkr,
  * @return int
  */
 void
-host_hci_cmd_build_le_lt_key_req_reply(struct hci_lt_key_req_reply *hkr,
+host_hci_cmd_build_le_lt_key_req_reply(const struct hci_lt_key_req_reply *hkr,
                                        uint8_t *dst, int dst_len)
 {
     BLE_HS_DBG_ASSERT(
@@ -847,7 +850,7 @@ host_hci_cmd_build_le_lt_key_req_neg_reply(uint16_t conn_handle,
 }
 
 static void
-host_hci_cmd_body_le_conn_param_reply(struct hci_conn_param_reply *hcr,
+host_hci_cmd_body_le_conn_param_reply(const struct hci_conn_param_reply *hcr,
                                       uint8_t *dst)
 {
     htole16(dst + 0, hcr->handle);
@@ -860,7 +863,7 @@ host_hci_cmd_body_le_conn_param_reply(struct hci_conn_param_reply *hcr,
 }
 
 void
-host_hci_cmd_build_le_conn_param_reply(struct hci_conn_param_reply *hcr,
+host_hci_cmd_build_le_conn_param_reply(const struct hci_conn_param_reply *hcr,
                                        uint8_t *dst, int dst_len)
 {
     BLE_HS_DBG_ASSERT(
@@ -874,7 +877,7 @@ host_hci_cmd_build_le_conn_param_reply(struct hci_conn_param_reply *hcr,
 }
 
 int
-host_hci_cmd_le_conn_param_reply(struct hci_conn_param_reply *hcr)
+host_hci_cmd_le_conn_param_reply(const struct hci_conn_param_reply *hcr)
 {
     uint8_t cmd[BLE_HCI_CONN_PARAM_REPLY_LEN];
     int rc;
@@ -893,8 +896,8 @@ host_hci_cmd_le_conn_param_reply(struct hci_conn_param_reply *hcr)
 }
 
 static void
-host_hci_cmd_body_le_conn_param_neg_reply(struct hci_conn_param_neg_reply *hcn,
-                                          uint8_t *dst)
+host_hci_cmd_body_le_conn_param_neg_reply(
+    const struct hci_conn_param_neg_reply *hcn, uint8_t *dst)
 {
     htole16(dst + 0, hcn->handle);
     dst[2] = hcn->reason;
@@ -903,7 +906,7 @@ host_hci_cmd_body_le_conn_param_neg_reply(struct hci_conn_param_neg_reply *hcn,
 
 void
 host_hci_cmd_build_le_conn_param_neg_reply(
-    struct hci_conn_param_neg_reply *hcn, uint8_t *dst, int dst_len)
+    const struct hci_conn_param_neg_reply *hcn, uint8_t *dst, int dst_len)
 {
     BLE_HS_DBG_ASSERT(
         dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_CONN_PARAM_NEG_REPLY_LEN);
@@ -916,7 +919,8 @@ host_hci_cmd_build_le_conn_param_neg_reply(
 }
 
 int
-host_hci_cmd_le_conn_param_neg_reply(struct hci_conn_param_neg_reply *hcn)
+host_hci_cmd_le_conn_param_neg_reply(
+    const struct hci_conn_param_neg_reply *hcn)
 {
     uint8_t cmd[BLE_HCI_CONN_PARAM_NEG_REPLY_LEN];
     int rc;
@@ -944,7 +948,8 @@ host_hci_cmd_build_le_rand(uint8_t *dst, int dst_len)
 }
 
 static void
-host_hci_cmd_body_le_start_encrypt(struct hci_start_encrypt *cmd, uint8_t *dst)
+host_hci_cmd_body_le_start_encrypt(const struct hci_start_encrypt *cmd,
+                                   uint8_t *dst)
 {
     htole16(dst + 0, cmd->connection_handle);
     htole64(dst + 2, cmd->random_number);
@@ -956,7 +961,7 @@ host_hci_cmd_body_le_start_encrypt(struct hci_start_encrypt *cmd, uint8_t *dst)
  * OGF=0x08 OCF=0x0019
  */
 void
-host_hci_cmd_build_le_start_encrypt(struct hci_start_encrypt *cmd,
+host_hci_cmd_build_le_start_encrypt(const struct hci_start_encrypt *cmd,
                                     uint8_t *dst, int dst_len)
 {
     BLE_HS_DBG_ASSERT(
@@ -1051,8 +1056,9 @@ host_hci_cmd_build_set_data_len(uint16_t connection_handle,
  * IRKs are in little endian.
  */
 static int
-host_hci_cmd_body_add_to_resolv_list(uint8_t addr_type, uint8_t *addr,
-                                     uint8_t *peer_irk, uint8_t *local_irk,
+host_hci_cmd_body_add_to_resolv_list(uint8_t addr_type, const uint8_t *addr,
+                                     const uint8_t *peer_irk,
+                                     const uint8_t *local_irk,
                                      uint8_t *dst)
 {
     if (addr_type > BLE_ADDR_TYPE_RANDOM) {
@@ -1074,7 +1080,7 @@ host_hci_cmd_body_add_to_resolv_list(uint8_t addr_type, uint8_t *addr,
  */
 int
 host_hci_cmd_build_add_to_resolv_list(
-    struct hci_add_dev_to_resolving_list *padd,
+    const struct hci_add_dev_to_resolving_list *padd,
     uint8_t *dst,
     int dst_len)
 {
@@ -1097,7 +1103,8 @@ host_hci_cmd_build_add_to_resolv_list(
 }
 
 static int
-host_hci_cmd_body_remove_from_resolv_list(uint8_t addr_type, uint8_t *addr,
+host_hci_cmd_body_remove_from_resolv_list(uint8_t addr_type,
+                                          const uint8_t *addr,
                                           uint8_t *dst)
 {
     if (addr_type > BLE_ADDR_TYPE_RANDOM) {
@@ -1111,7 +1118,8 @@ host_hci_cmd_body_remove_from_resolv_list(uint8_t addr_type, uint8_t *addr,
 
 
 int
-host_hci_cmd_build_remove_from_resolv_list(uint8_t addr_type, uint8_t *addr,
+host_hci_cmd_build_remove_from_resolv_list(uint8_t addr_type,
+                                           const uint8_t *addr,
                                            uint8_t *dst, int dst_len)
 {
     int rc;
@@ -1154,7 +1162,7 @@ host_hci_cmd_build_read_resolv_list_size(uint8_t *dst, int dst_len)
 
 static int
 host_hci_cmd_body_read_peer_resolv_addr(uint8_t peer_identity_addr_type,
-                                        uint8_t *peer_identity_addr,
+                                        const uint8_t *peer_identity_addr,
                                         uint8_t *dst)
 {
     if (peer_identity_addr_type > BLE_ADDR_TYPE_RANDOM) {
@@ -1168,7 +1176,7 @@ host_hci_cmd_body_read_peer_resolv_addr(uint8_t peer_identity_addr_type,
 
 int
 host_hci_cmd_build_read_peer_resolv_addr(uint8_t peer_identity_addr_type,
-                                         uint8_t *peer_identity_addr,
+                                         const uint8_t *peer_identity_addr,
                                          uint8_t *dst,
                                          int dst_len)
 {
@@ -1192,7 +1200,7 @@ host_hci_cmd_build_read_peer_resolv_addr(uint8_t peer_identity_addr_type,
 static int
 host_hci_cmd_body_read_lcl_resolv_addr(
     uint8_t local_identity_addr_type,
-    uint8_t *local_identity_addr,
+    const uint8_t *local_identity_addr,
     uint8_t *dst)
 {
     if (local_identity_addr_type > BLE_ADDR_TYPE_RANDOM) {
@@ -1209,7 +1217,7 @@ host_hci_cmd_body_read_lcl_resolv_addr(
  */
 int
 host_hci_cmd_build_read_lcl_resolv_addr(uint8_t local_identity_addr_type,
-                                        uint8_t *local_identity_addr,
+                                        const uint8_t *local_identity_addr,
                                         uint8_t *dst,
                                         int dst_len)
 {
@@ -1297,14 +1305,16 @@ host_hci_cmd_build_set_resolv_priv_addr_timeout(uint16_t timeout, uint8_t *dst,
 }
 
 static int
-host_hci_cmd_body_set_random_addr(struct hci_rand_addr *paddr, uint8_t *dst)
+host_hci_cmd_body_set_random_addr(const struct hci_rand_addr *paddr,
+                                  uint8_t *dst)
 {
     memcpy(dst, paddr->addr, BLE_DEV_ADDR_LEN);
     return 0;
 }
 
 int
-host_hci_cmd_build_set_random_addr(uint8_t *addr, uint8_t *dst, int dst_len)
+host_hci_cmd_build_set_random_addr(const uint8_t *addr,
+                                   uint8_t *dst, int dst_len)
 {
     struct hci_rand_addr r_addr;
     int rc;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/63531557/net/nimble/host/src/test/ble_att_svr_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_att_svr_test.c b/net/nimble/host/src/test/ble_att_svr_test.c
index f89bd1c..38964b4 100644
--- a/net/nimble/host/src/test/ble_att_svr_test.c
+++ b/net/nimble/host/src/test/ble_att_svr_test.c
@@ -104,14 +104,14 @@ ble_att_svr_test_misc_attr_fn_r_1(uint16_t conn_handle, uint16_t attr_handle,
                                   struct ble_att_svr_access_ctxt *ctxt,
                                   void *arg)
 {
-    if (ctxt->offset > ble_att_svr_test_attr_r_1_len) {
-        return BLE_ATT_ERR_INVALID_OFFSET;
-    }
-
     switch (op) {
     case BLE_ATT_ACCESS_OP_READ:
-        ctxt->attr_data = ble_att_svr_test_attr_r_1 + ctxt->offset;
-        ctxt->data_len = ble_att_svr_test_attr_r_1_len - ctxt->offset;
+        if (ctxt->read.offset > ble_att_svr_test_attr_r_1_len) {
+            return BLE_ATT_ERR_INVALID_OFFSET;
+        }
+
+        ctxt->read.data = ble_att_svr_test_attr_r_1 + ctxt->read.offset;
+        ctxt->read.len = ble_att_svr_test_attr_r_1_len - ctxt->read.offset;
         return 0;
 
     default:
@@ -125,14 +125,14 @@ ble_att_svr_test_misc_attr_fn_r_2(uint16_t conn_handle, uint16_t attr_handle,
                                   struct ble_att_svr_access_ctxt *ctxt,
                                   void *arg)
 {
-    if (ctxt->offset > ble_att_svr_test_attr_r_2_len) {
-        return BLE_ATT_ERR_INVALID_OFFSET;
-    }
 
     switch (op) {
     case BLE_ATT_ACCESS_OP_READ:
-        ctxt->attr_data = ble_att_svr_test_attr_r_2 + ctxt->offset;
-        ctxt->data_len = ble_att_svr_test_attr_r_2_len - ctxt->offset;
+        if (ctxt->read.offset > ble_att_svr_test_attr_r_2_len) {
+            return BLE_ATT_ERR_INVALID_OFFSET;
+        }
+        ctxt->read.data = ble_att_svr_test_attr_r_2 + ctxt->read.offset;
+        ctxt->read.len = ble_att_svr_test_attr_r_2_len - ctxt->read.offset;
         return 0;
 
     default:
@@ -190,11 +190,11 @@ ble_att_svr_test_misc_attr_fn_r_group(uint16_t conn_handle,
     TEST_ASSERT_FATAL(attr_handle >= 1 &&
                       attr_handle <= BLE_ATT_SVR_TEST_LAST_ATTR);
 
-    ctxt->attr_data = vals + attr_handle;
-    if (memcmp(ctxt->attr_data + 2, zeros, 14) == 0) {
-        ctxt->data_len = 2;
+    ctxt->read.data = vals + attr_handle;
+    if (memcmp(ctxt->read.data + 2, zeros, 14) == 0) {
+        ctxt->read.len = 2;
     } else {
-        ctxt->data_len = 16;
+        ctxt->read.len = 16;
     }
 
     return 0;
@@ -288,8 +288,8 @@ ble_att_svr_test_misc_attr_fn_w_1(uint16_t conn_handle, uint16_t attr_handle,
 {
     switch (op) {
     case BLE_ATT_ACCESS_OP_WRITE:
-        memcpy(ble_att_svr_test_attr_w_1, ctxt->attr_data, ctxt->data_len);
-        ble_att_svr_test_attr_w_1_len = ctxt->data_len;
+        memcpy(ble_att_svr_test_attr_w_1, ctxt->write.data, ctxt->write.len);
+        ble_att_svr_test_attr_w_1_len = ctxt->write.len;
         return 0;
 
     default:
@@ -305,8 +305,8 @@ ble_att_svr_test_misc_attr_fn_w_2(uint16_t conn_handle, uint16_t attr_handle,
 {
     switch (op) {
     case BLE_ATT_ACCESS_OP_WRITE:
-        memcpy(ble_att_svr_test_attr_w_2, ctxt->attr_data, ctxt->data_len);
-        ble_att_svr_test_attr_w_2_len = ctxt->data_len;
+        memcpy(ble_att_svr_test_attr_w_2, ctxt->write.data, ctxt->write.len);
+        ble_att_svr_test_attr_w_2_len = ctxt->write.len;
         return 0;
 
     default:
@@ -412,7 +412,7 @@ ble_att_svr_test_misc_verify_tx_read_mult_rsp(uint16_t conn_handle,
     struct ble_l2cap_chan *chan;
     struct os_mbuf *om;
     uint16_t mtu;
-    uint8_t *attr_value;
+    const uint8_t *attr_value;
     uint8_t u8;
     int rc;
     int off;
@@ -1001,7 +1001,7 @@ TEST_CASE(ble_att_svr_test_read)
     uint8_t buf[BLE_ATT_READ_REQ_SZ];
     uint8_t uuid_sec[16] = {1};
     uint8_t uuid[16] = {0};
-    void *attr_data;
+    const void *attr_data;
     int rc;
 
     conn_handle = ble_att_svr_test_misc_init(0);
@@ -1167,7 +1167,7 @@ TEST_CASE(ble_att_svr_test_read_mult)
 
     attr1.value = (uint8_t[]){ 1, 2, 3, 4 };
     attr1.value_len = 4;
-    ble_att_svr_test_attr_r_1 = attr1.value;
+    ble_att_svr_test_attr_r_1 = (void *)attr1.value;
     ble_att_svr_test_attr_r_1_len = attr1.value_len;
     rc = ble_att_svr_register(BLE_UUID16(0x1111), HA_FLAG_PERM_RW,
                               &attr1.handle,
@@ -1176,7 +1176,7 @@ TEST_CASE(ble_att_svr_test_read_mult)
 
     attr2.value = (uint8_t[]){ 2, 3, 4, 5, 6 };
     attr2.value_len = 5;
-    ble_att_svr_test_attr_r_2 = attr2.value;
+    ble_att_svr_test_attr_r_2 = (void *)attr2.value;
     ble_att_svr_test_attr_r_2_len = attr2.value_len;
     rc = ble_att_svr_register(BLE_UUID16(0x2222), HA_FLAG_PERM_RW,
                               &attr2.handle,
@@ -1210,13 +1210,13 @@ TEST_CASE(ble_att_svr_test_read_mult)
     attr1.value =
         (uint8_t[]){0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19};
     attr1.value_len = 20;
-    ble_att_svr_test_attr_r_1 = attr1.value;
+    ble_att_svr_test_attr_r_1 = (void *)attr1.value;
     ble_att_svr_test_attr_r_1_len = attr1.value_len;
 
     attr2.value =
         (uint8_t[]){22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39};
     attr2.value_len = 20;
-    ble_att_svr_test_attr_r_2 = attr2.value;
+    ble_att_svr_test_attr_r_2 = (void *)attr2.value;
     ble_att_svr_test_attr_r_2_len = attr2.value_len;
 
     ble_att_svr_test_misc_verify_all_read_mult(

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/63531557/net/nimble/host/src/test/ble_gatt_conn_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_gatt_conn_test.c b/net/nimble/host/src/test/ble_gatt_conn_test.c
index 6f3a4a5..2617dfc 100644
--- a/net/nimble/host/src/test/ble_gatt_conn_test.c
+++ b/net/nimble/host/src/test/ble_gatt_conn_test.c
@@ -44,8 +44,8 @@ ble_gatt_conn_test_attr_cb(uint16_t conn_handle, uint16_t attr_handle,
 
     switch (op) {
     case BLE_ATT_ACCESS_OP_READ:
-        ctxt->attr_data = &data;
-        ctxt->data_len = 1;
+        ctxt->read.data = &data;
+        ctxt->read.len = 1;
         return 0;
 
     default:
@@ -54,7 +54,8 @@ ble_gatt_conn_test_attr_cb(uint16_t conn_handle, uint16_t attr_handle,
 }
 
 static int
-ble_gatt_conn_test_mtu_cb(uint16_t conn_handle, struct ble_gatt_error *error,
+ble_gatt_conn_test_mtu_cb(uint16_t conn_handle,
+                          const struct ble_gatt_error *error,
                           uint16_t mtu, void *arg)
 {
     struct ble_gatt_conn_test_cb_arg *cb_arg;
@@ -74,9 +75,9 @@ ble_gatt_conn_test_mtu_cb(uint16_t conn_handle, struct ble_gatt_error *error,
 
 static int
 ble_gatt_conn_test_disc_all_svcs_cb(uint16_t conn_handle,
-                                   struct ble_gatt_error *error,
-                                   struct ble_gatt_svc *service,
-                                   void *arg)
+                                    const struct ble_gatt_error *error,
+                                    const struct ble_gatt_svc *service,
+                                    void *arg)
 {
     struct ble_gatt_conn_test_cb_arg *cb_arg;
 
@@ -95,8 +96,8 @@ ble_gatt_conn_test_disc_all_svcs_cb(uint16_t conn_handle,
 
 static int
 ble_gatt_conn_test_disc_svc_uuid_cb(uint16_t conn_handle,
-                                    struct ble_gatt_error *error,
-                                    struct ble_gatt_svc *service,
+                                    const struct ble_gatt_error *error,
+                                    const struct ble_gatt_svc *service,
                                     void *arg)
 {
     struct ble_gatt_conn_test_cb_arg *cb_arg;
@@ -116,8 +117,8 @@ ble_gatt_conn_test_disc_svc_uuid_cb(uint16_t conn_handle,
 
 static int
 ble_gatt_conn_test_find_inc_svcs_cb(uint16_t conn_handle,
-                                    struct ble_gatt_error *error,
-                                    struct ble_gatt_svc *service,
+                                    const struct ble_gatt_error *error,
+                                    const struct ble_gatt_svc *service,
                                     void *arg)
 {
     struct ble_gatt_conn_test_cb_arg *cb_arg;
@@ -137,8 +138,8 @@ ble_gatt_conn_test_find_inc_svcs_cb(uint16_t conn_handle,
 
 static int
 ble_gatt_conn_test_disc_all_chrs_cb(uint16_t conn_handle,
-                                    struct ble_gatt_error *error,
-                                    struct ble_gatt_chr *chr, void *arg)
+                                    const struct ble_gatt_error *error,
+                                    const struct ble_gatt_chr *chr, void *arg)
 {
     struct ble_gatt_conn_test_cb_arg *cb_arg;
 
@@ -157,8 +158,8 @@ ble_gatt_conn_test_disc_all_chrs_cb(uint16_t conn_handle,
 
 static int
 ble_gatt_conn_test_disc_chr_uuid_cb(uint16_t conn_handle,
-                                    struct ble_gatt_error *error,
-                                    struct ble_gatt_chr *chr, void *arg)
+                                    const struct ble_gatt_error *error,
+                                    const struct ble_gatt_chr *chr, void *arg)
 {
     struct ble_gatt_conn_test_cb_arg *cb_arg;
 
@@ -177,9 +178,9 @@ ble_gatt_conn_test_disc_chr_uuid_cb(uint16_t conn_handle,
 
 static int
 ble_gatt_conn_test_disc_all_dscs_cb(uint16_t conn_handle,
-                                    struct ble_gatt_error *error,
+                                    const struct ble_gatt_error *error,
                                     uint16_t chr_def_handle,
-                                    struct ble_gatt_dsc *dsc,
+                                    const struct ble_gatt_dsc *dsc,
                                     void *arg)
 {
     struct ble_gatt_conn_test_cb_arg *cb_arg;
@@ -198,8 +199,9 @@ ble_gatt_conn_test_disc_all_dscs_cb(uint16_t conn_handle,
 }
 
 static int
-ble_gatt_conn_test_read_cb(uint16_t conn_handle, struct ble_gatt_error *error,
-                           struct ble_gatt_attr *attr, void *arg)
+ble_gatt_conn_test_read_cb(uint16_t conn_handle,
+                           const struct ble_gatt_error *error,
+                           const struct ble_gatt_attr *attr, void *arg)
 {
     struct ble_gatt_conn_test_cb_arg *cb_arg;
 
@@ -218,8 +220,8 @@ ble_gatt_conn_test_read_cb(uint16_t conn_handle, struct ble_gatt_error *error,
 
 static int
 ble_gatt_conn_test_read_uuid_cb(uint16_t conn_handle,
-                                struct ble_gatt_error *error,
-                                struct ble_gatt_attr *attr, void *arg)
+                                const struct ble_gatt_error *error,
+                                const struct ble_gatt_attr *attr, void *arg)
 {
     struct ble_gatt_conn_test_cb_arg *cb_arg;
 
@@ -238,8 +240,8 @@ ble_gatt_conn_test_read_uuid_cb(uint16_t conn_handle,
 
 static int
 ble_gatt_conn_test_read_long_cb(uint16_t conn_handle,
-                                struct ble_gatt_error *error,
-                                struct ble_gatt_attr *attr, void *arg)
+                                const struct ble_gatt_error *error,
+                                const struct ble_gatt_attr *attr, void *arg)
 {
     struct ble_gatt_conn_test_cb_arg *cb_arg;
 
@@ -257,8 +259,8 @@ ble_gatt_conn_test_read_long_cb(uint16_t conn_handle,
 }
 static int
 ble_gatt_conn_test_read_mult_cb(uint16_t conn_handle,
-                                struct ble_gatt_error *error,
-                                struct ble_gatt_attr *attr, void *arg)
+                                const struct ble_gatt_error *error,
+                                const struct ble_gatt_attr *attr, void *arg)
 {
     struct ble_gatt_conn_test_cb_arg *cb_arg;
 
@@ -276,8 +278,10 @@ ble_gatt_conn_test_read_mult_cb(uint16_t conn_handle,
 }
 
 static int
-ble_gatt_conn_test_write_cb(uint16_t conn_handle, struct ble_gatt_error *error,
-                            struct ble_gatt_attr *attr, void *arg)
+ble_gatt_conn_test_write_cb(uint16_t conn_handle,
+                            const struct ble_gatt_error *error,
+                            const struct ble_gatt_attr *attr,
+                            void *arg)
 {
     struct ble_gatt_conn_test_cb_arg *cb_arg;
 
@@ -297,8 +301,8 @@ ble_gatt_conn_test_write_cb(uint16_t conn_handle, struct ble_gatt_error *error,
 
 static int
 ble_gatt_conn_test_write_long_cb(uint16_t conn_handle,
-                                 struct ble_gatt_error *error,
-                                 struct ble_gatt_attr *attr, void *arg)
+                                 const struct ble_gatt_error *error,
+                                 const struct ble_gatt_attr *attr, void *arg)
 {
     struct ble_gatt_conn_test_cb_arg *cb_arg;
 
@@ -318,8 +322,9 @@ ble_gatt_conn_test_write_long_cb(uint16_t conn_handle,
 
 static int
 ble_gatt_conn_test_write_rel_cb(uint16_t conn_handle,
-                                struct ble_gatt_error *error,
-                                struct ble_gatt_attr *attrs, uint8_t num_attrs,
+                                const struct ble_gatt_error *error,
+                                const struct ble_gatt_attr *attrs,
+                                uint8_t num_attrs,
                                 void *arg)
 {
     struct ble_gatt_conn_test_cb_arg *cb_arg;
@@ -339,8 +344,8 @@ ble_gatt_conn_test_write_rel_cb(uint16_t conn_handle,
 
 static int
 ble_gatt_conn_test_indicate_cb(uint16_t conn_handle,
-                               struct ble_gatt_error *error,
-                               struct ble_gatt_attr *attr, void *arg)
+                               const struct ble_gatt_error *error,
+                               const struct ble_gatt_attr *attr, void *arg)
 {
     struct ble_gatt_conn_test_cb_arg *cb_arg;
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/63531557/net/nimble/host/src/test/ble_gatt_disc_c_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_gatt_disc_c_test.c b/net/nimble/host/src/test/ble_gatt_disc_c_test.c
index 6325926..0a1f7fd 100644
--- a/net/nimble/host/src/test/ble_gatt_disc_c_test.c
+++ b/net/nimble/host/src/test/ble_gatt_disc_c_test.c
@@ -169,8 +169,8 @@ ble_gatt_disc_c_test_misc_verify_chars(struct ble_gatt_disc_c_test_char *chars,
 
 static int
 ble_gatt_disc_c_test_misc_cb(uint16_t conn_handle,
-                             struct ble_gatt_error *error,
-                             struct ble_gatt_chr *chr, void *arg)
+                             const struct ble_gatt_error *error,
+                             const struct ble_gatt_chr *chr, void *arg)
 {
     struct ble_gatt_chr *dst;
     int *stop_after;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/63531557/net/nimble/host/src/test/ble_gatt_disc_d_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_gatt_disc_d_test.c b/net/nimble/host/src/test/ble_gatt_disc_d_test.c
index 6b0a807..a2bb5a2 100644
--- a/net/nimble/host/src/test/ble_gatt_disc_d_test.c
+++ b/net/nimble/host/src/test/ble_gatt_disc_d_test.c
@@ -156,8 +156,9 @@ ble_gatt_disc_d_test_misc_verify_dscs(struct ble_gatt_disc_d_test_dsc *dscs,
 
 static int
 ble_gatt_disc_d_test_misc_cb(uint16_t conn_handle,
-                             struct ble_gatt_error *error,
-                             uint16_t chr_def_handle, struct ble_gatt_dsc *dsc,
+                             const struct ble_gatt_error *error,
+                             uint16_t chr_def_handle,
+                             const struct ble_gatt_dsc *dsc,
                              void *arg)
 {
     struct ble_gatt_disc_d_test_dsc *dst;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/63531557/net/nimble/host/src/test/ble_gatt_disc_s_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_gatt_disc_s_test.c b/net/nimble/host/src/test/ble_gatt_disc_s_test.c
index d7572b2..b29aacf 100644
--- a/net/nimble/host/src/test/ble_gatt_disc_s_test.c
+++ b/net/nimble/host/src/test/ble_gatt_disc_s_test.c
@@ -219,8 +219,9 @@ ble_gatt_disc_s_test_misc_verify_services(
 
 static int
 ble_gatt_disc_s_test_misc_disc_cb(uint16_t conn_handle,
-                                  struct ble_gatt_error *error,
-                                  struct ble_gatt_svc *service, void *arg)
+                                  const struct ble_gatt_error *error,
+                                  const struct ble_gatt_svc *service,
+                                  void *arg)
 {
     TEST_ASSERT(error == NULL);
     TEST_ASSERT(!ble_gatt_disc_s_test_rx_complete);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/63531557/net/nimble/host/src/test/ble_gatt_find_s_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_gatt_find_s_test.c b/net/nimble/host/src/test/ble_gatt_find_s_test.c
index dca1f36..3e190a6 100644
--- a/net/nimble/host/src/test/ble_gatt_find_s_test.c
+++ b/net/nimble/host/src/test/ble_gatt_find_s_test.c
@@ -46,8 +46,8 @@ ble_gatt_find_s_test_misc_init(void)
 
 static int
 ble_gatt_find_s_test_misc_cb(uint16_t conn_handle,
-                             struct ble_gatt_error *error,
-                             struct ble_gatt_svc *service,
+                             const struct ble_gatt_error *error,
+                             const struct ble_gatt_svc *service,
                              void *arg)
 {
     TEST_ASSERT(!ble_gatt_find_s_test_proc_complete);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/63531557/net/nimble/host/src/test/ble_gatt_read_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_gatt_read_test.c b/net/nimble/host/src/test/ble_gatt_read_test.c
index 03df56e..57a0624 100644
--- a/net/nimble/host/src/test/ble_gatt_read_test.c
+++ b/net/nimble/host/src/test/ble_gatt_read_test.c
@@ -57,8 +57,8 @@ ble_gatt_read_test_misc_init(void)
 }
 
 static int
-ble_gatt_read_test_cb(uint16_t conn_handle, struct ble_gatt_error *error,
-                      struct ble_gatt_attr *attr, void *arg)
+ble_gatt_read_test_cb(uint16_t conn_handle, const struct ble_gatt_error *error,
+                      const struct ble_gatt_attr *attr, void *arg)
 {
     struct ble_gatt_read_test_attr *dst;
     int *stop_after;
@@ -102,8 +102,9 @@ ble_gatt_read_test_cb(uint16_t conn_handle, struct ble_gatt_error *error,
 }
 
 static int
-ble_gatt_read_test_long_cb(uint16_t conn_handle, struct ble_gatt_error *error,
-                           struct ble_gatt_attr *attr, void *arg)
+ble_gatt_read_test_long_cb(uint16_t conn_handle,
+                           const struct ble_gatt_error *error,
+                           const struct ble_gatt_attr *attr, void *arg)
 {
     struct ble_gatt_read_test_attr *dst;
     int *reads_left;
@@ -151,7 +152,7 @@ ble_gatt_read_test_long_cb(uint16_t conn_handle, struct ble_gatt_error *error,
 static void
 ble_gatt_read_test_misc_rx_rsp_good_raw(uint16_t conn_handle,
                                         uint8_t att_op,
-                                        void *data, int data_len)
+                                        const void *data, int data_len)
 {
     uint8_t buf[1024];
     int rc;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/63531557/net/nimble/host/src/test/ble_gatt_write_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_gatt_write_test.c b/net/nimble/host/src/test/ble_gatt_write_test.c
index 56e88d3..98809d1 100644
--- a/net/nimble/host/src/test/ble_gatt_write_test.c
+++ b/net/nimble/host/src/test/ble_gatt_write_test.c
@@ -33,7 +33,7 @@ static int ble_gatt_write_test_cb_called;
 static uint8_t ble_gatt_write_test_attr_value[BLE_ATT_ATTR_MAX_LEN];
 static struct ble_gatt_error ble_gatt_write_test_error;
 
-static struct ble_gatt_attr *
+static const struct ble_gatt_attr *
 ble_gatt_write_test_attrs[BLE_GATT_WRITE_TEST_MAX_ATTRS];
 static int ble_gatt_write_test_num_attrs;
 
@@ -52,8 +52,9 @@ ble_gatt_write_test_init(void)
 }
 
 static int
-ble_gatt_write_test_cb_good(uint16_t conn_handle, struct ble_gatt_error *error,
-                            struct ble_gatt_attr *attr, void *arg)
+ble_gatt_write_test_cb_good(uint16_t conn_handle,
+                            const struct ble_gatt_error *error,
+                            const struct ble_gatt_attr *attr, void *arg)
 {
     int *attr_len;
 
@@ -88,7 +89,7 @@ ble_gatt_write_test_rx_rsp(uint16_t conn_handle)
 static void
 ble_gatt_write_test_rx_prep_rsp(uint16_t conn_handle, uint16_t attr_handle,
                                 uint16_t offset,
-                                void *attr_data, uint16_t attr_data_len)
+                                const void *attr_data, uint16_t attr_data_len)
 {
     struct ble_att_prep_write_cmd rsp;
     uint8_t buf[512];
@@ -255,8 +256,8 @@ ble_gatt_write_test_misc_long_fail_length(uint16_t conn_handle,
 
 static int
 ble_gatt_write_test_reliable_cb_good(uint16_t conn_handle,
-                                     struct ble_gatt_error *error,
-                                     struct ble_gatt_attr *attrs,
+                                     const struct ble_gatt_error *error,
+                                     const struct ble_gatt_attr *attrs,
                                      uint8_t num_attrs, void *arg)
 {
     int i;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/63531557/net/nimble/host/src/test/ble_gatts_notify_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_gatts_notify_test.c b/net/nimble/host/src/test/ble_gatts_notify_test.c
index 1432447..28d2120 100644
--- a/net/nimble/host/src/test/ble_gatts_notify_test.c
+++ b/net/nimble/host/src/test/ble_gatts_notify_test.c
@@ -34,7 +34,7 @@ static uint8_t ble_gatts_notify_test_peer_addr[6] = {2,3,4,5,6,7};
 static int
 ble_gatts_notify_test_misc_access(uint16_t conn_handle,
                                   uint16_t attr_handle, uint8_t op,
-                                  union ble_gatt_access_ctxt *ctxt,
+                                  struct ble_gatt_access_ctxt *ctxt,
                                   void *arg);
 static void
 ble_gatts_notify_test_misc_reg_cb(uint8_t op,
@@ -234,22 +234,22 @@ ble_gatts_notify_test_misc_reg_cb(uint8_t op,
 static int
 ble_gatts_notify_test_misc_access(uint16_t conn_handle,
                                   uint16_t attr_handle, uint8_t op,
-                                  union ble_gatt_access_ctxt *ctxt,
+                                  struct ble_gatt_access_ctxt *ctxt,
                                   void *arg)
 {
     TEST_ASSERT_FATAL(op == BLE_GATT_ACCESS_OP_READ_CHR);
     TEST_ASSERT(conn_handle == 0xffff);
 
     if (attr_handle == ble_gatts_notify_test_chr_1_def_handle + 1) {
-        TEST_ASSERT(ctxt->chr.def ==
+        TEST_ASSERT(ctxt->chr ==
                     &ble_gatts_notify_test_svcs[0].characteristics[0]);
-        ctxt->chr.read.data = ble_gatts_notify_test_chr_1_val;
-        ctxt->chr.read.len = ble_gatts_notify_test_chr_1_len;
+        ctxt->att->read.data = ble_gatts_notify_test_chr_1_val;
+        ctxt->att->read.len = ble_gatts_notify_test_chr_1_len;
     } else if (attr_handle == ble_gatts_notify_test_chr_2_def_handle + 1) {
-        TEST_ASSERT(ctxt->chr.def ==
+        TEST_ASSERT(ctxt->chr ==
                     &ble_gatts_notify_test_svcs[0].characteristics[1]);
-        ctxt->chr.read.data = ble_gatts_notify_test_chr_2_val;
-        ctxt->chr.read.len = ble_gatts_notify_test_chr_2_len;
+        ctxt->att->read.data = ble_gatts_notify_test_chr_2_val;
+        ctxt->att->read.len = ble_gatts_notify_test_chr_2_len;
     } else {
         TEST_ASSERT(0);
     }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/63531557/net/nimble/host/src/test/ble_gatts_read_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_gatts_read_test.c b/net/nimble/host/src/test/ble_gatts_read_test.c
index 2f45425..401ddd8 100644
--- a/net/nimble/host/src/test/ble_gatts_read_test.c
+++ b/net/nimble/host/src/test/ble_gatts_read_test.c
@@ -32,13 +32,13 @@ static uint8_t ble_gatts_read_test_peer_addr[6] = {2,3,4,5,6,7};
 static int
 ble_gatts_read_test_util_access_1(uint16_t conn_handle,
                                   uint16_t attr_handle, uint8_t op,
-                                  union ble_gatt_access_ctxt *ctxt,
+                                  struct ble_gatt_access_ctxt *ctxt,
                                   void *arg);
 
 static int
 ble_gatts_read_test_util_access_2(uint16_t conn_handle,
                                   uint16_t attr_handle, uint8_t op,
-                                  union ble_gatt_access_ctxt *ctxt,
+                                  struct ble_gatt_access_ctxt *ctxt,
                                   void *arg);
 static void
 ble_gatts_read_test_misc_reg_cb(uint8_t op,
@@ -127,16 +127,16 @@ ble_gatts_read_test_misc_reg_cb(uint8_t op,
 static int
 ble_gatts_read_test_util_access_1(uint16_t conn_handle,
                                   uint16_t attr_handle, uint8_t op,
-                                  union ble_gatt_access_ctxt *ctxt,
+                                  struct ble_gatt_access_ctxt *ctxt,
                                   void *arg)
 {
     TEST_ASSERT_FATAL(op == BLE_GATT_ACCESS_OP_READ_CHR);
     TEST_ASSERT_FATAL(attr_handle == ble_gatts_read_test_chr_1_val_handle);
 
-    TEST_ASSERT(ctxt->chr.def ==
+    TEST_ASSERT(ctxt->chr ==
                 &ble_gatts_read_test_svcs[0].characteristics[0]);
-    ctxt->chr.read.data = ble_gatts_read_test_chr_1_val;
-    ctxt->chr.read.len = ble_gatts_read_test_chr_1_len;
+    ctxt->att->read.data = ble_gatts_read_test_chr_1_val;
+    ctxt->att->read.len = ble_gatts_read_test_chr_1_len;
 
     return 0;
 }
@@ -144,25 +144,25 @@ ble_gatts_read_test_util_access_1(uint16_t conn_handle,
 static int
 ble_gatts_read_test_util_access_2(uint16_t conn_handle,
                                   uint16_t attr_handle, uint8_t op,
-                                  union ble_gatt_access_ctxt *ctxt,
+                                  struct ble_gatt_access_ctxt *ctxt,
                                   void *arg)
 {
     TEST_ASSERT_FATAL(op == BLE_GATT_ACCESS_OP_READ_CHR);
     TEST_ASSERT_FATAL(attr_handle == ble_gatts_read_test_chr_2_def_handle + 1);
 
-    TEST_ASSERT(ctxt->chr.def ==
+    TEST_ASSERT(ctxt->chr ==
                 &ble_gatts_read_test_svcs[0].characteristics[1]);
 
-    TEST_ASSERT_FATAL(ctxt->chr.read.data == ctxt->chr.read.buf);
-    TEST_ASSERT(ctxt->chr.read.max_data_len == BLE_ATT_MTU_DFLT - 1);
+    TEST_ASSERT_FATAL(ctxt->att->read.data == ctxt->att->read.buf);
+    TEST_ASSERT(ctxt->att->read.max_data_len == BLE_ATT_MTU_DFLT - 1);
 
-    ctxt->chr.read.buf[0] = 0;
-    ctxt->chr.read.buf[1] = 10;
-    ctxt->chr.read.buf[2] = 20;
-    ctxt->chr.read.buf[3] = 30;
-    ctxt->chr.read.buf[4] = 40;
-    ctxt->chr.read.buf[5] = 50;
-    ctxt->chr.read.len = 6;
+    ctxt->att->read.buf[0] = 0;
+    ctxt->att->read.buf[1] = 10;
+    ctxt->att->read.buf[2] = 20;
+    ctxt->att->read.buf[3] = 30;
+    ctxt->att->read.buf[4] = 40;
+    ctxt->att->read.buf[5] = 50;
+    ctxt->att->read.len = 6;
 
     return 0;
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/63531557/net/nimble/host/src/test/ble_gatts_reg_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_gatts_reg_test.c b/net/nimble/host/src/test/ble_gatts_reg_test.c
index 63283d8..f6e5841 100644
--- a/net/nimble/host/src/test/ble_gatts_reg_test.c
+++ b/net/nimble/host/src/test/ble_gatts_reg_test.c
@@ -94,7 +94,7 @@ ble_gatts_reg_test_misc_verify_entry(uint8_t op, const uint8_t *uuid128)
 static int
 ble_gatts_reg_test_misc_dummy_access(uint16_t conn_handle,
                                      uint16_t attr_handle, uint8_t op,
-                                     union ble_gatt_access_ctxt *ctxt,
+                                     struct ble_gatt_access_ctxt *ctxt,
                                      void *arg)
 {
     return 0;


[33/50] [abbrv] incubator-mynewt-core git commit: BLE Host - Add missing 'static'

Posted by cc...@apache.org.
BLE Host - Add missing 'static'


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

Branch: refs/heads/ble_hs_api
Commit: 270fcf611f0215f133ae27c146c51fa3b590bffd
Parents: f962497
Author: Christopher Collins <cc...@apache.org>
Authored: Thu Jun 30 15:42:59 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Jul 11 16:43:33 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/src/ble_gattc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/270fcf61/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 929c878..77daa19 100644
--- a/net/nimble/host/src/ble_gattc.c
+++ b/net/nimble/host/src/ble_gattc.c
@@ -883,7 +883,7 @@ ble_gattc_heartbeat(void)
  * returned object is statically allocated, so this function is not reentrant.
  * This function should only ever be called by the ble_hs task.
  */
-struct ble_gatt_error *
+static struct ble_gatt_error *
 ble_gattc_error(int status, uint16_t att_handle)
 {
     static struct ble_gatt_error error;
@@ -951,6 +951,8 @@ ble_gattc_mtu_err(struct ble_gattc_proc *proc, int status, uint16_t att_handle)
  * @param cb                    The function to call to report procedure status
  *                                  updates; null for no callback.
  * @param cb_arg                The argument to pass to the callback function.
+ *
+ * @return                      0 on success; nonzero on failure.
  */
 int
 ble_gattc_exchange_mtu(uint16_t conn_handle, ble_gatt_mtu_fn *cb, void *cb_arg)


[05/50] [abbrv] incubator-mynewt-core git commit: BLE Host - GATT registration API changes

Posted by cc...@apache.org.
BLE Host - GATT registration API changes

* In the GATT registration context struct (ble_gatt_register_ctxt),
  rename svc_reg, chr_reg, and dsc_reg to svc, chr, and dsc.

* The characteristic registration context (ble_gatt_register_ctxt.chr)
  now contains a pointer to the parent service definition.  This is
  necessary for identifying the characteristic being registered in case
  multiple characteristics have identical UUIDs.

* The descriptor registration context (ble_gatt_register_ctxt.dsc) now
  contains the parent characteristic value handle (in addition to the
  definition handle that it always contained).


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

Branch: refs/heads/ble_hs_api
Commit: 980c9379ff9a34e4b7ae3718d0e0ea23d214ba63
Parents: 804b445
Author: Christopher Collins <cc...@apache.org>
Authored: Wed Jun 22 11:55:49 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Jul 11 16:43:30 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/include/host/ble_gatt.h         | 19 +++++++++---------
 net/nimble/host/src/ble_gatts.c                 | 21 ++++++++++----------
 net/nimble/host/src/test/ble_att_svr_test.c     |  8 ++++----
 .../host/src/test/ble_gatts_notify_test.c       |  6 +++---
 net/nimble/host/src/test/ble_gatts_read_test.c  | 18 ++++++++++++-----
 net/nimble/host/src/test/ble_gatts_reg_test.c   |  6 +++---
 6 files changed, 44 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/980c9379/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 083a742..6f68ada 100644
--- a/net/nimble/host/include/host/ble_gatt.h
+++ b/net/nimble/host/include/host/ble_gatt.h
@@ -208,7 +208,7 @@ struct ble_gatt_read_ctxt {
     /**
      * (stack --> app)
      * A buffer that the app can use to write the characteristic response value
-     * to.
+     * to.  This buffer can hold up to max_data_len bytes.
      */
     uint8_t *buf;
 
@@ -299,22 +299,23 @@ void ble_gatts_chr_updated(uint16_t chr_def_handle);
 union ble_gatt_register_ctxt {
     struct {
         uint16_t handle;
-        const struct ble_gatt_svc_def *svc;
-    } svc_reg;
+        const struct ble_gatt_svc_def *svc_def;
+    } svc;
 
     struct {
         uint16_t def_handle;
         uint16_t val_handle;
-        const struct ble_gatt_svc_def *svc;
-        const struct ble_gatt_chr_def *chr;
-    } chr_reg;
+        const struct ble_gatt_svc_def *svc_def;
+        const struct ble_gatt_chr_def *chr_def;
+    } chr;
 
     struct {
         uint16_t dsc_handle;
-        const struct ble_gatt_dsc_def *dsc;
+        const struct ble_gatt_dsc_def *dsc_def;
         uint16_t chr_def_handle;
-        const struct ble_gatt_chr_def *chr;
-    } dsc_reg;
+        uint16_t chr_val_handle;
+        const struct ble_gatt_chr_def *chr_def;
+    } dsc;
 };
 
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/980c9379/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 ed3df13..9c30ed1 100644
--- a/net/nimble/host/src/ble_gatts.c
+++ b/net/nimble/host/src/ble_gatts.c
@@ -567,10 +567,11 @@ ble_gatts_register_dsc(const struct ble_gatt_dsc_def *dsc,
     }
 
     if (register_cb != NULL) {
-        register_ctxt.dsc_reg.dsc_handle = dsc_handle;
-        register_ctxt.dsc_reg.dsc = dsc;
-        register_ctxt.dsc_reg.chr_def_handle = chr_def_handle;
-        register_ctxt.dsc_reg.chr = chr;
+        register_ctxt.dsc.dsc_handle = dsc_handle;
+        register_ctxt.dsc.dsc_def = dsc;
+        register_ctxt.dsc.chr_def_handle = chr_def_handle;
+        register_ctxt.dsc.chr_val_handle = chr_def_handle + 1;
+        register_ctxt.dsc.chr_def = chr;
         register_cb(BLE_GATT_REGISTER_OP_DSC, &register_ctxt, cb_arg);
     }
 
@@ -801,10 +802,10 @@ ble_gatts_register_chr(const struct ble_gatt_svc_def *svc,
     BLE_HS_DBG_ASSERT(val_handle == def_handle + 1);
 
     if (register_cb != NULL) {
-        register_ctxt.chr_reg.def_handle = def_handle;
-        register_ctxt.chr_reg.val_handle = val_handle;
-        register_ctxt.svc_reg.svc = svc;
-        register_ctxt.chr_reg.chr = chr;
+        register_ctxt.chr.def_handle = def_handle;
+        register_ctxt.chr.val_handle = val_handle;
+        register_ctxt.svc.svc_def = svc;
+        register_ctxt.chr.chr_def = chr;
         register_cb(BLE_GATT_REGISTER_OP_CHR, &register_ctxt, cb_arg);
     }
 
@@ -901,8 +902,8 @@ ble_gatts_register_svc(const struct ble_gatt_svc_def *svc,
     }
 
     if (register_cb != NULL) {
-        register_ctxt.svc_reg.handle = *out_handle;
-        register_ctxt.svc_reg.svc = svc;
+        register_ctxt.svc.handle = *out_handle;
+        register_ctxt.svc.svc_def = svc;
         register_cb(BLE_GATT_REGISTER_OP_SVC, &register_ctxt, cb_arg);
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/980c9379/net/nimble/host/src/test/ble_att_svr_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_att_svr_test.c b/net/nimble/host/src/test/ble_att_svr_test.c
index ec2d2f6..2afd6f6 100644
--- a/net/nimble/host/src/test/ble_att_svr_test.c
+++ b/net/nimble/host/src/test/ble_att_svr_test.c
@@ -1042,8 +1042,8 @@ TEST_CASE(ble_att_svr_test_read)
     rc = ble_hs_test_util_l2cap_rx_payload_flat(conn_handle, BLE_L2CAP_CID_ATT,
                                                 buf, sizeof buf);
     TEST_ASSERT(rc == 0);
-    ble_att_svr_test_misc_verify_tx_read_rsp(ble_att_svr_test_attr_r_1,
-                                             BLE_ATT_MTU_DFLT - 1);
+    ble_hs_test_util_verify_tx_read_rsp(ble_att_svr_test_attr_r_1,
+                                        BLE_ATT_MTU_DFLT - 1);
 
     /*** Read requires encryption. */
     /* Insufficient authentication. */
@@ -1080,8 +1080,8 @@ TEST_CASE(ble_att_svr_test_read)
     rc = ble_hs_test_util_l2cap_rx_payload_flat(conn_handle, BLE_L2CAP_CID_ATT,
                                                 buf, sizeof buf);
     TEST_ASSERT(rc == 0);
-    ble_att_svr_test_misc_verify_tx_read_rsp(ble_att_svr_test_attr_r_1,
-                                             BLE_ATT_MTU_DFLT - 1);
+    ble_hs_test_util_verify_tx_read_rsp(ble_att_svr_test_attr_r_1,
+                                        BLE_ATT_MTU_DFLT - 1);
 }
 
 TEST_CASE(ble_att_svr_test_read_blob)

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/980c9379/net/nimble/host/src/test/ble_gatts_notify_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_gatts_notify_test.c b/net/nimble/host/src/test/ble_gatts_notify_test.c
index 957551c..1432447 100644
--- a/net/nimble/host/src/test/ble_gatts_notify_test.c
+++ b/net/nimble/host/src/test/ble_gatts_notify_test.c
@@ -214,14 +214,14 @@ ble_gatts_notify_test_misc_reg_cb(uint8_t op,
     uint16_t uuid16;
 
     if (op == BLE_GATT_REGISTER_OP_CHR) {
-        uuid16 = ble_uuid_128_to_16(ctxt->chr_reg.chr->uuid128);
+        uuid16 = ble_uuid_128_to_16(ctxt->chr.chr_def->uuid128);
         switch (uuid16) {
         case BLE_GATTS_NOTIFY_TEST_CHR_1_UUID:
-            ble_gatts_notify_test_chr_1_def_handle = ctxt->chr_reg.def_handle;
+            ble_gatts_notify_test_chr_1_def_handle = ctxt->chr.def_handle;
             break;
 
         case BLE_GATTS_NOTIFY_TEST_CHR_2_UUID:
-            ble_gatts_notify_test_chr_2_def_handle = ctxt->chr_reg.def_handle;
+            ble_gatts_notify_test_chr_2_def_handle = ctxt->chr.def_handle;
             break;
 
         default:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/980c9379/net/nimble/host/src/test/ble_gatts_read_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_gatts_read_test.c b/net/nimble/host/src/test/ble_gatts_read_test.c
index 8f58256..2f45425 100644
--- a/net/nimble/host/src/test/ble_gatts_read_test.c
+++ b/net/nimble/host/src/test/ble_gatts_read_test.c
@@ -65,9 +65,11 @@ static const struct ble_gatt_svc_def ble_gatts_read_test_svcs[] = { {
 
 
 static uint16_t ble_gatts_read_test_chr_1_def_handle;
+static uint16_t ble_gatts_read_test_chr_1_val_handle;
 static uint8_t ble_gatts_read_test_chr_1_val[1024];
 static int ble_gatts_read_test_chr_1_len;
 static uint16_t ble_gatts_read_test_chr_2_def_handle;
+static uint16_t ble_gatts_read_test_chr_2_val_handle;
 
 static void
 ble_gatts_read_test_misc_init(uint16_t *out_conn_handle)
@@ -80,7 +82,11 @@ ble_gatts_read_test_misc_init(uint16_t *out_conn_handle)
                                  ble_gatts_read_test_misc_reg_cb, NULL);
     TEST_ASSERT_FATAL(rc == 0);
     TEST_ASSERT_FATAL(ble_gatts_read_test_chr_1_def_handle != 0);
+    TEST_ASSERT_FATAL(ble_gatts_read_test_chr_1_val_handle ==
+                      ble_gatts_read_test_chr_1_def_handle + 1);
     TEST_ASSERT_FATAL(ble_gatts_read_test_chr_2_def_handle != 0);
+    TEST_ASSERT_FATAL(ble_gatts_read_test_chr_2_val_handle ==
+                      ble_gatts_read_test_chr_2_def_handle + 1);
 
     ble_gatts_start();
 
@@ -99,14 +105,16 @@ ble_gatts_read_test_misc_reg_cb(uint8_t op,
     uint16_t uuid16;
 
     if (op == BLE_GATT_REGISTER_OP_CHR) {
-        uuid16 = ble_uuid_128_to_16(ctxt->chr_reg.chr->uuid128);
+        uuid16 = ble_uuid_128_to_16(ctxt->chr.chr_def->uuid128);
         switch (uuid16) {
         case BLE_GATTS_READ_TEST_CHR_1_UUID:
-            ble_gatts_read_test_chr_1_def_handle = ctxt->chr_reg.def_handle;
+            ble_gatts_read_test_chr_1_def_handle = ctxt->chr.def_handle;
+            ble_gatts_read_test_chr_1_val_handle = ctxt->chr.val_handle;
             break;
 
         case BLE_GATTS_READ_TEST_CHR_2_UUID:
-            ble_gatts_read_test_chr_2_def_handle = ctxt->chr_reg.def_handle;
+            ble_gatts_read_test_chr_2_def_handle = ctxt->chr.def_handle;
+            ble_gatts_read_test_chr_2_val_handle = ctxt->chr.val_handle;
             break;
 
         default:
@@ -123,7 +131,7 @@ ble_gatts_read_test_util_access_1(uint16_t conn_handle,
                                   void *arg)
 {
     TEST_ASSERT_FATAL(op == BLE_GATT_ACCESS_OP_READ_CHR);
-    TEST_ASSERT_FATAL(attr_handle == ble_gatts_read_test_chr_1_def_handle + 1);
+    TEST_ASSERT_FATAL(attr_handle == ble_gatts_read_test_chr_1_val_handle);
 
     TEST_ASSERT(ctxt->chr.def ==
                 &ble_gatts_read_test_svcs[0].characteristics[0]);
@@ -189,7 +197,7 @@ TEST_CASE(ble_gatts_read_test_case_basic)
     ble_gatts_read_test_chr_1_val[2] = 3;
     ble_gatts_read_test_chr_1_len = 3;
     ble_gatts_read_test_once(conn_handle,
-                             ble_gatts_read_test_chr_1_def_handle + 1,
+                             ble_gatts_read_test_chr_1_val_handle,
                              ble_gatts_read_test_chr_1_val,
                              ble_gatts_read_test_chr_1_len);
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/980c9379/net/nimble/host/src/test/ble_gatts_reg_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_gatts_reg_test.c b/net/nimble/host/src/test/ble_gatts_reg_test.c
index 7b66cc7..63283d8 100644
--- a/net/nimble/host/src/test/ble_gatts_reg_test.c
+++ b/net/nimble/host/src/test/ble_gatts_reg_test.c
@@ -58,15 +58,15 @@ ble_gatts_reg_test_misc_reg_cb(uint8_t op, union ble_gatt_register_ctxt *ctxt,
     entry->op = op;
     switch (op) {
     case BLE_GATT_REGISTER_OP_SVC:
-        memcpy(entry->uuid128, ctxt->svc_reg.svc->uuid128, 16);
+        memcpy(entry->uuid128, ctxt->svc.svc_def->uuid128, 16);
         break;
 
     case BLE_GATT_REGISTER_OP_CHR:
-        memcpy(entry->uuid128, ctxt->chr_reg.chr->uuid128, 16);
+        memcpy(entry->uuid128, ctxt->chr.chr_def->uuid128, 16);
         break;
 
     case BLE_GATT_REGISTER_OP_DSC:
-        memcpy(entry->uuid128, ctxt->dsc_reg.dsc->uuid128, 16);
+        memcpy(entry->uuid128, ctxt->dsc.dsc_def->uuid128, 16);
         break;
 
     default:


[36/50] [abbrv] incubator-mynewt-core git commit: BLE Host - Remove obsolete error codes.

Posted by cc...@apache.org.
BLE Host - Remove obsolete error codes.


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

Branch: refs/heads/ble_hs_api
Commit: faed993b3d9295fd402408eebcbb3f0258f7cf67
Parents: 7efbf0e
Author: Christopher Collins <cc...@apache.org>
Authored: Tue Jul 5 12:18:03 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Jul 11 16:43:33 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/include/host/ble_hs.h | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/faed993b/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 2d2a93a..e6a825d 100644
--- a/net/nimble/host/include/host/ble_hs.h
+++ b/net/nimble/host/include/host/ble_hs.h
@@ -47,18 +47,16 @@ struct os_event;
 #define BLE_HS_EAPP                 9
 #define BLE_HS_EBADDATA             10
 #define BLE_HS_EOS                  11
-#define BLE_HS_ECONGESTED           12
-#define BLE_HS_ECONTROLLER          13
-#define BLE_HS_ETIMEOUT             14
-#define BLE_HS_EDONE                15
-#define BLE_HS_EBUSY                16
-#define BLE_HS_EREJECT              17
-#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_ENOADDR              23
+#define BLE_HS_ECONTROLLER          12
+#define BLE_HS_ETIMEOUT             13
+#define BLE_HS_EDONE                14
+#define BLE_HS_EBUSY                15
+#define BLE_HS_EREJECT              16
+#define BLE_HS_EUNKNOWN             17
+#define BLE_HS_EROLE                18
+#define BLE_HS_ETIMEOUT_HCI         19
+#define BLE_HS_ENOMEM_EVT           20
+#define BLE_HS_ENOADDR              21
 
 #define BLE_HS_ERR_ATT_BASE         0x100   /* 256 */
 #define BLE_HS_ATT_ERR(x)           ((x) ? BLE_HS_ERR_ATT_BASE + (x) : 0)


[19/50] [abbrv] incubator-mynewt-core git commit: ble apps - Account for const correctness.

Posted by cc...@apache.org.
ble apps - Account for const correctness.


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

Branch: refs/heads/ble_hs_api
Commit: 3402795548422a0cf5e18a510bb0140b5c104e89
Parents: 6353155
Author: Christopher Collins <cc...@apache.org>
Authored: Fri Jun 24 18:26:07 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Jul 11 16:43:32 2016 -0700

----------------------------------------------------------------------
 apps/bleprph/src/bleprph.h |  4 +--
 apps/bleprph/src/misc.c    |  6 ++--
 apps/bletiny/src/bletiny.h | 28 ++++++++--------
 apps/bletiny/src/cmd.c     |  2 +-
 apps/bletiny/src/main.c    | 72 +++++++++++++++++++++--------------------
 apps/bletiny/src/misc.c    | 20 ++++++------
 6 files changed, 67 insertions(+), 65 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/34027955/apps/bleprph/src/bleprph.h
----------------------------------------------------------------------
diff --git a/apps/bleprph/src/bleprph.h b/apps/bleprph/src/bleprph.h
index a353bac..6a7ffd4 100644
--- a/apps/bleprph/src/bleprph.h
+++ b/apps/bleprph/src/bleprph.h
@@ -59,7 +59,7 @@ int store_read(int obj_type, union ble_store_key *key,
 int store_write(int obj_type, union ble_store_value *val);
 
 /** Misc. */
-void print_bytes(uint8_t *bytes, int len);
-void print_addr(void *addr);
+void print_bytes(const uint8_t *bytes, int len);
+void print_addr(const void *addr);
 
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/34027955/apps/bleprph/src/misc.c
----------------------------------------------------------------------
diff --git a/apps/bleprph/src/misc.c b/apps/bleprph/src/misc.c
index d5d4808..7e27765 100644
--- a/apps/bleprph/src/misc.c
+++ b/apps/bleprph/src/misc.c
@@ -23,7 +23,7 @@
  * Utility function to log an array of bytes.
  */
 void
-print_bytes(uint8_t *bytes, int len)
+print_bytes(const uint8_t *bytes, int len)
 {
     int i;
 
@@ -33,9 +33,9 @@ print_bytes(uint8_t *bytes, int len)
 }
 
 void
-print_addr(void *addr)
+print_addr(const void *addr)
 {
-    uint8_t *u8p;
+    const uint8_t *u8p;
 
     u8p = addr;
     BLEPRPH_LOG(INFO, "%02x:%02x:%02x:%02x:%02x:%02x",

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/34027955/apps/bletiny/src/bletiny.h
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/bletiny.h b/apps/bletiny/src/bletiny.h
index 90002e6..d6051bf 100644
--- a/apps/bletiny/src/bletiny.h
+++ b/apps/bletiny/src/bletiny.h
@@ -93,9 +93,6 @@ extern uint16_t nm_attr_val_handle;
 
 extern struct log bletiny_log;
 
-void print_addr(void *addr);
-void print_uuid(void *uuid128);
-void print_bytes(uint8_t *bytes, int len);
 const struct cmd_entry *parse_cmd_find(const struct cmd_entry *cmds,
                                        char *name);
 struct kv_pair *parse_kv_find(struct kv_pair *kvs, char *name);
@@ -148,14 +145,14 @@ int bletiny_read_by_uuid(uint16_t conn_handle, uint16_t start_handle,
                           uint16_t end_handle, uint8_t *uuid128);
 int bletiny_read_mult(uint16_t conn_handle, uint16_t *attr_handles,
                        int num_attr_handles);
-int bletiny_write(uint16_t conn_handle, uint16_t attr_handle, void *value,
-                   uint16_t value_len);
+int bletiny_write(uint16_t conn_handle, uint16_t attr_handle,
+                  const void *value, uint16_t value_len);
 int bletiny_write_no_rsp(uint16_t conn_handle, uint16_t attr_handle,
-                          void *value, uint16_t value_len);
+                         const void *value, uint16_t value_len);
 int bletiny_write_long(uint16_t conn_handle, uint16_t attr_handle,
-                        void *value, uint16_t value_len);
-int bletiny_write_reliable(uint16_t conn_handle, struct ble_gatt_attr *attrs,
-                            int num_attrs);
+                       const void *value, uint16_t value_len);
+int bletiny_write_reliable(uint16_t conn_handle,
+                           const struct ble_gatt_attr *attrs, int num_attrs);
 int bletiny_adv_start(uint8_t own_addr_type, uint8_t peer_addr_type,
                       const uint8_t *peer_addr, int32_t duration_ms,
                       const struct ble_gap_adv_params *params);
@@ -209,10 +206,13 @@ int store_read(int obj_type, union ble_store_key *key,
 int store_write(int obj_type, union ble_store_value *val);
 
 /** Misc. */
-void print_bytes(uint8_t *bytes, int len);
-int svc_is_empty(struct bletiny_svc *svc);
-uint16_t chr_end_handle(struct bletiny_svc *svc, struct bletiny_chr *chr);
-int chr_is_empty(struct bletiny_svc *svc, struct bletiny_chr *chr);
-void print_conn_desc(struct ble_gap_conn_desc *desc);
+void print_bytes(const uint8_t *bytes, int len);
+void print_addr(const void *addr);
+void print_uuid(const void *uuid128);
+int svc_is_empty(const struct bletiny_svc *svc);
+uint16_t chr_end_handle(const struct bletiny_svc *svc,
+                        const struct bletiny_chr *chr);
+int chr_is_empty(const struct bletiny_svc *svc, const struct bletiny_chr *chr);
+void print_conn_desc(const struct ble_gap_conn_desc *desc);
 
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/34027955/apps/bletiny/src/cmd.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/cmd.c b/apps/bletiny/src/cmd.c
index d6e824d..eee8f22 100644
--- a/apps/bletiny/src/cmd.c
+++ b/apps/bletiny/src/cmd.c
@@ -1815,7 +1815,7 @@ cmd_write(int argc, char **argv)
             return EINVAL;
         }
         rc = bletiny_write_no_rsp(conn_handle, attrs[0].handle,
-                                   attrs[0].value, attrs[0].value_len);
+                                  attrs[0].value, attrs[0].value_len);
     } else if (is_long) {
         if (num_attrs != 1) {
             return EINVAL;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/34027955/apps/bletiny/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/main.c b/apps/bletiny/src/main.c
index 764eb00..02f8566 100755
--- a/apps/bletiny/src/main.c
+++ b/apps/bletiny/src/main.c
@@ -149,7 +149,7 @@ int bletiny_full_disc_prev_chr_def;
 
 static void
 bletiny_print_error(char *msg, uint16_t conn_handle,
-                    struct ble_gatt_error *error)
+                    const struct ble_gatt_error *error)
 {
     if (msg == NULL) {
         msg = "ERROR";
@@ -160,7 +160,7 @@ bletiny_print_error(char *msg, uint16_t conn_handle,
 }
 
 static void
-bletiny_print_adv_fields(struct ble_hs_adv_fields *fields)
+bletiny_print_adv_fields(const struct ble_hs_adv_fields *fields)
 {
     uint32_t u32;
     uint16_t u16;
@@ -338,7 +338,7 @@ bletiny_svc_find_prev(struct bletiny_conn *conn, uint16_t svc_start_handle)
 
 static struct bletiny_svc *
 bletiny_svc_find(struct bletiny_conn *conn, uint16_t svc_start_handle,
-                  struct bletiny_svc **out_prev)
+                 struct bletiny_svc **out_prev)
 {
     struct bletiny_svc *prev;
     struct bletiny_svc *svc;
@@ -403,7 +403,7 @@ bletiny_svc_delete(struct bletiny_svc *svc)
 }
 
 static struct bletiny_svc *
-bletiny_svc_add(uint16_t conn_handle, struct ble_gatt_svc *gatt_svc)
+bletiny_svc_add(uint16_t conn_handle, const struct ble_gatt_svc *gatt_svc)
 {
     struct bletiny_conn *conn;
     struct bletiny_svc *prev;
@@ -443,7 +443,7 @@ bletiny_svc_add(uint16_t conn_handle, struct ble_gatt_svc *gatt_svc)
 }
 
 static struct bletiny_chr *
-bletiny_chr_find_prev(struct bletiny_svc *svc, uint16_t chr_def_handle)
+bletiny_chr_find_prev(const struct bletiny_svc *svc, uint16_t chr_def_handle)
 {
     struct bletiny_chr *prev;
     struct bletiny_chr *chr;
@@ -461,8 +461,8 @@ bletiny_chr_find_prev(struct bletiny_svc *svc, uint16_t chr_def_handle)
 }
 
 static struct bletiny_chr *
-bletiny_chr_find(struct bletiny_svc *svc, uint16_t chr_def_handle,
-                  struct bletiny_chr **out_prev)
+bletiny_chr_find(const struct bletiny_svc *svc, uint16_t chr_def_handle,
+                 struct bletiny_chr **out_prev)
 {
     struct bletiny_chr *prev;
     struct bletiny_chr *chr;
@@ -487,7 +487,7 @@ bletiny_chr_find(struct bletiny_svc *svc, uint16_t chr_def_handle,
 
 static struct bletiny_chr *
 bletiny_chr_add(uint16_t conn_handle,  uint16_t svc_start_handle,
-                 struct ble_gatt_chr *gatt_chr)
+                const struct ble_gatt_chr *gatt_chr)
 {
     struct bletiny_conn *conn;
     struct bletiny_chr *prev;
@@ -534,7 +534,7 @@ bletiny_chr_add(uint16_t conn_handle,  uint16_t svc_start_handle,
 }
 
 static struct bletiny_dsc *
-bletiny_dsc_find_prev(struct bletiny_chr *chr, uint16_t dsc_handle)
+bletiny_dsc_find_prev(const struct bletiny_chr *chr, uint16_t dsc_handle)
 {
     struct bletiny_dsc *prev;
     struct bletiny_dsc *dsc;
@@ -552,8 +552,8 @@ bletiny_dsc_find_prev(struct bletiny_chr *chr, uint16_t dsc_handle)
 }
 
 static struct bletiny_dsc *
-bletiny_dsc_find(struct bletiny_chr *chr, uint16_t dsc_handle,
-                  struct bletiny_dsc **out_prev)
+bletiny_dsc_find(const struct bletiny_chr *chr, uint16_t dsc_handle,
+                 struct bletiny_dsc **out_prev)
 {
     struct bletiny_dsc *prev;
     struct bletiny_dsc *dsc;
@@ -577,7 +577,7 @@ bletiny_dsc_find(struct bletiny_chr *chr, uint16_t dsc_handle,
 
 static struct bletiny_dsc *
 bletiny_dsc_add(uint16_t conn_handle, uint16_t chr_def_handle,
-                 struct ble_gatt_dsc *gatt_dsc)
+                const struct ble_gatt_dsc *gatt_dsc)
 {
     struct bletiny_conn *conn;
     struct bletiny_dsc *prev;
@@ -676,7 +676,7 @@ bletiny_conn_delete_idx(int idx)
 }
 
 static int
-bletiny_on_mtu(uint16_t conn_handle, struct ble_gatt_error *error,
+bletiny_on_mtu(uint16_t conn_handle, const struct ble_gatt_error *error,
                uint16_t mtu, void *arg)
 {
     if (error != NULL) {
@@ -766,8 +766,8 @@ bletiny_disc_full_chrs(uint16_t conn_handle)
 }
 
 static int
-bletiny_on_disc_s(uint16_t conn_handle, struct ble_gatt_error *error,
-                  struct ble_gatt_svc *service, void *arg)
+bletiny_on_disc_s(uint16_t conn_handle, const struct ble_gatt_error *error,
+                  const struct ble_gatt_svc *service, void *arg)
 {
     if (error != NULL) {
         bletiny_print_error(NULL, conn_handle, error);
@@ -784,8 +784,8 @@ bletiny_on_disc_s(uint16_t conn_handle, struct ble_gatt_error *error,
 }
 
 static int
-bletiny_on_disc_c(uint16_t conn_handle, struct ble_gatt_error *error,
-                  struct ble_gatt_chr *chr, void *arg)
+bletiny_on_disc_c(uint16_t conn_handle, const struct ble_gatt_error *error,
+                  const struct ble_gatt_chr *chr, void *arg)
 {
     intptr_t svc_start_handle;
 
@@ -806,9 +806,9 @@ bletiny_on_disc_c(uint16_t conn_handle, struct ble_gatt_error *error,
 }
 
 static int
-bletiny_on_disc_d(uint16_t conn_handle, struct ble_gatt_error *error,
-                   uint16_t chr_def_handle, struct ble_gatt_dsc *dsc,
-                   void *arg)
+bletiny_on_disc_d(uint16_t conn_handle, const struct ble_gatt_error *error,
+                  uint16_t chr_def_handle, const struct ble_gatt_dsc *dsc,
+                  void *arg)
 {
     if (error != NULL) {
         bletiny_print_error(NULL, conn_handle, error);
@@ -825,8 +825,8 @@ bletiny_on_disc_d(uint16_t conn_handle, struct ble_gatt_error *error,
 }
 
 static int
-bletiny_on_read(uint16_t conn_handle, struct ble_gatt_error *error,
-                 struct ble_gatt_attr *attr, void *arg)
+bletiny_on_read(uint16_t conn_handle, const struct ble_gatt_error *error,
+                const struct ble_gatt_attr *attr, void *arg)
 {
     if (error != NULL) {
         bletiny_print_error(NULL, conn_handle, error);
@@ -844,8 +844,8 @@ bletiny_on_read(uint16_t conn_handle, struct ble_gatt_error *error,
 }
 
 static int
-bletiny_on_write(uint16_t conn_handle, struct ble_gatt_error *error,
-                  struct ble_gatt_attr *attr, void *arg)
+bletiny_on_write(uint16_t conn_handle, const struct ble_gatt_error *error,
+                  const struct ble_gatt_attr *attr, void *arg)
 {
     if (error != NULL) {
         bletiny_print_error(NULL, conn_handle, error);
@@ -861,9 +861,10 @@ bletiny_on_write(uint16_t conn_handle, struct ble_gatt_error *error,
 }
 
 static int
-bletiny_on_write_reliable(uint16_t conn_handle, struct ble_gatt_error *error,
-                           struct ble_gatt_attr *attrs, uint8_t num_attrs,
-                           void *arg)
+bletiny_on_write_reliable(uint16_t conn_handle,
+                          const struct ble_gatt_error *error,
+                          const struct ble_gatt_attr *attrs, uint8_t num_attrs,
+                          void *arg)
 {
     int i;
 
@@ -1192,8 +1193,8 @@ bletiny_read_mult(uint16_t conn_handle, uint16_t *attr_handles,
 }
 
 int
-bletiny_write(uint16_t conn_handle, uint16_t attr_handle, void *value,
-               uint16_t value_len)
+bletiny_write(uint16_t conn_handle, uint16_t attr_handle, const void *value,
+              uint16_t value_len)
 {
     int rc;
 
@@ -1208,8 +1209,8 @@ bletiny_write(uint16_t conn_handle, uint16_t attr_handle, void *value,
 }
 
 int
-bletiny_write_no_rsp(uint16_t conn_handle, uint16_t attr_handle, void *value,
-                      uint16_t value_len)
+bletiny_write_no_rsp(uint16_t conn_handle, uint16_t attr_handle,
+                     const void *value, uint16_t value_len)
 {
     int rc;
 
@@ -1219,8 +1220,8 @@ bletiny_write_no_rsp(uint16_t conn_handle, uint16_t attr_handle, void *value,
 }
 
 int
-bletiny_write_long(uint16_t conn_handle, uint16_t attr_handle, void *value,
-                    uint16_t value_len)
+bletiny_write_long(uint16_t conn_handle, uint16_t attr_handle,
+                   const void *value, uint16_t value_len)
 {
     int rc;
 
@@ -1230,8 +1231,9 @@ bletiny_write_long(uint16_t conn_handle, uint16_t attr_handle, void *value,
 }
 
 int
-bletiny_write_reliable(uint16_t conn_handle, struct ble_gatt_attr *attrs,
-                        int num_attrs)
+bletiny_write_reliable(uint16_t conn_handle,
+                       const struct ble_gatt_attr *attrs,
+                       int num_attrs)
 {
     int rc;
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/34027955/apps/bletiny/src/misc.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/misc.c b/apps/bletiny/src/misc.c
index e9f8eee..0df5dee 100644
--- a/apps/bletiny/src/misc.c
+++ b/apps/bletiny/src/misc.c
@@ -27,7 +27,7 @@
  * Utility function to log an array of bytes.
  */
 void
-print_bytes(uint8_t *bytes, int len)
+print_bytes(const uint8_t *bytes, int len)
 {
     int i;
 
@@ -37,9 +37,9 @@ print_bytes(uint8_t *bytes, int len)
 }
 
 void
-print_addr(void *addr)
+print_addr(const void *addr)
 {
-    uint8_t *u8p;
+    const uint8_t *u8p;
 
     u8p = addr;
     console_printf("%02x:%02x:%02x:%02x:%02x:%02x",
@@ -47,10 +47,10 @@ print_addr(void *addr)
 }
 
 void
-print_uuid(void *uuid128)
+print_uuid(const void *uuid128)
 {
     uint16_t uuid16;
-    uint8_t *u8p;
+    const uint8_t *u8p;
 
     uuid16 = ble_uuid_128_to_16(uuid128);
     if (uuid16 != 0) {
@@ -69,15 +69,15 @@ print_uuid(void *uuid128)
 }
 
 int
-svc_is_empty(struct bletiny_svc *svc)
+svc_is_empty(const struct bletiny_svc *svc)
 {
     return svc->svc.end_handle < svc->svc.start_handle;
 }
 
 uint16_t
-chr_end_handle(struct bletiny_svc *svc, struct bletiny_chr *chr)
+chr_end_handle(const struct bletiny_svc *svc, const struct bletiny_chr *chr)
 {
-    struct bletiny_chr *next_chr;
+    const struct bletiny_chr *next_chr;
 
     next_chr = SLIST_NEXT(chr, next);
     if (next_chr != NULL) {
@@ -88,13 +88,13 @@ chr_end_handle(struct bletiny_svc *svc, struct bletiny_chr *chr)
 }
 
 int
-chr_is_empty(struct bletiny_svc *svc, struct bletiny_chr *chr)
+chr_is_empty(const struct bletiny_svc *svc, const struct bletiny_chr *chr)
 {
     return chr_end_handle(svc, chr) <= chr->chr.val_handle;
 }
 
 void
-print_conn_desc(struct ble_gap_conn_desc *desc)
+print_conn_desc(const struct ble_gap_conn_desc *desc)
 {
     console_printf("handle=%d our_ota_addr_type=%d our_ota_addr=",
                    desc->conn_handle, desc->our_ota_addr_type);


[50/50] [abbrv] incubator-mynewt-core git commit: BLE Host - Fix spurious maybe-uninitialized warn.

Posted by cc...@apache.org.
BLE Host - Fix spurious maybe-uninitialized warn.


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

Branch: refs/heads/ble_hs_api
Commit: 5ccea9b6c74a35ca34be7a17b5d63fc3dcda0bda
Parents: fe13229
Author: Christopher Collins <cc...@apache.org>
Authored: Mon Jul 11 16:48:25 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Jul 11 16:48:25 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/src/ble_gap.c | 4 ++++
 1 file changed, 4 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5ccea9b6/net/nimble/host/src/ble_gap.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gap.c b/net/nimble/host/src/ble_gap.c
index 73c9e42..27616f2 100644
--- a/net/nimble/host/src/ble_gap.c
+++ b/net/nimble/host/src/ble_gap.c
@@ -745,6 +745,10 @@ ble_gap_rx_update_complete(struct hci_le_conn_upd_complete *evt)
         }
 
         ble_gap_conn_to_snapshot(conn, &snap);
+    } else {
+        /* Silence spurious maybe-uninitialized warning. */
+        snap.cb = NULL;
+        snap.cb_arg = NULL;
     }
 
     conn->bhc_flags &= ~BLE_HS_CONN_F_UPDATE;


[35/50] [abbrv] incubator-mynewt-core git commit: BLE Host - Add API doxygen comments.

Posted by cc...@apache.org.
BLE Host - Add API doxygen comments.


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

Branch: refs/heads/ble_hs_api
Commit: 085395877352913107a5895d6ae087f8eaf559b2
Parents: 40b635e
Author: Christopher Collins <cc...@apache.org>
Authored: Fri Jul 1 12:13:58 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Jul 11 16:43:33 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/include/host/ble_store.h |  72 ++++++++++
 net/nimble/host/src/ble_eddystone.c      |  12 +-
 net/nimble/host/src/ble_gap.c            | 200 +++++++++++++++++++++++---
 net/nimble/host/src/ble_gattc.c          | 127 ++++++++++++----
 net/nimble/host/src/ble_gatts.c          |  18 +++
 net/nimble/host/src/ble_hs.c             |  26 +++-
 net/nimble/host/src/ble_hs_adv.c         |   2 +-
 net/nimble/host/src/ble_ibeacon.c        |  13 ++
 net/nimble/host/src/ble_uuid.c           |  21 ++-
 9 files changed, 433 insertions(+), 58 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/08539587/net/nimble/host/include/host/ble_store.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/ble_store.h b/net/nimble/host/include/host/ble_store.h
index 9a7efab..a533159 100644
--- a/net/nimble/host/include/host/ble_store.h
+++ b/net/nimble/host/include/host/ble_store.h
@@ -28,6 +28,12 @@
 
 #define BLE_STORE_ADDR_TYPE_NONE        0xff
 
+/**
+ * Used as a key for lookups of security material.  This struct corresponds to
+ * the following store object types:
+ *     o BLE_STORE_OBJ_TYPE_OUR_SEC
+ *     o BLE_STORE_OBJ_TYPE_PEER_SEC
+ */
 struct ble_store_key_sec {
     /**
      * Key by peer identity address;
@@ -52,6 +58,12 @@ struct ble_store_key_sec {
     uint8_t idx;
 };
 
+/**
+ * Represents stored security material.  This struct corresponds to the
+ * following store object types:
+ *     o BLE_STORE_OBJ_TYPE_OUR_SEC
+ *     o BLE_STORE_OBJ_TYPE_PEER_SEC
+ */
 struct ble_store_value_sec {
     uint8_t peer_addr[6];
     uint8_t peer_addr_type;
@@ -71,6 +83,11 @@ struct ble_store_value_sec {
     unsigned sc:1;
 };
 
+/**
+ * Used as a key for lookups of stored client characteristic configuration
+ * descriptors (CCCDs).  This struct corresponds to the BLE_STORE_OBJ_TYPE_CCCD
+ * store object type.
+ */
 struct ble_store_key_cccd {
     /**
      * Key by peer identity address;
@@ -89,6 +106,10 @@ struct ble_store_key_cccd {
     uint8_t idx;
 };
 
+/**
+ * Represents a stored client characteristic configuration descriptor (CCCD).
+ * This struct corresponds to the BLE_STORE_OBJ_TYPE_CCCD store object type.
+ */
 struct ble_store_value_cccd {
     uint8_t peer_addr[6];
     uint8_t peer_addr_type;
@@ -97,21 +118,72 @@ struct ble_store_value_cccd {
     unsigned value_changed:1;
 };
 
+/**
+ * Used as a key for store lookups.  This union must be accompanied by an
+ * object type code to indicate which field is valid.
+ */
 union ble_store_key {
     struct ble_store_key_sec sec;
     struct ble_store_key_cccd cccd;
 };
 
+/**
+ * Represents stored data.  This union must be accompanied by an object type
+ * code to indicate which field is valid.
+ */
 union ble_store_value {
     struct ble_store_value_sec sec;
     struct ble_store_value_cccd cccd;
 };
 
+/**
+ * Searches the store for an object matching the specified criteria.  If a
+ * match is found, it is read from the store and the dst parameter is populated
+ * with the retrieved object.
+ *
+ * @param obj_type              The type of object to search for; one of the
+ *                                  BLE_STORE_OBJ_TYPE_[...] codes.
+ * @param key                   Specifies properties of the object to search
+ *                                  for.  An object is retrieved if it matches
+ *                                  these criteria.
+ * @param dst                   On success, this is populated with the
+ *                                  retrieved object.
+ *
+ * @return                      0 if an object was successfully retreived;
+ *                              BLE_HS_ENOENT if no matching object was found;
+ *                              Other nonzero on error.
+ */
 typedef int ble_store_read_fn(int obj_type, union ble_store_key *key,
                               union ble_store_value *dst);
 
+/**
+ * Writes the specified object to the store.  If an object with the same
+ * identity is already in the store, it is replaced.  If the store lacks
+ * sufficient capacity to write the object, this function may remove previously
+ * stored values to make room.
+ *
+ * @param obj_type              The type of object being written; one of the
+ *                                  BLE_STORE_OBJ_TYPE_[...] codes.
+ * @param val                   The object to persist.
+ *
+ * @return                      0 if the object was successfully written;
+ *                              Other nonzero on error.
+ */
 typedef int ble_store_write_fn(int obj_type, union ble_store_value *val);
 
+/**
+ * Searches the store for the first object matching the specified criteria.  If
+ * a match is found, it is deleted from the store.
+ *
+ * @param obj_type              The type of object to delete; one of the
+ *                                  BLE_STORE_OBJ_TYPE_[...] codes.
+ * @param key                   Specifies properties of the object to search
+ *                                  for.  An object is deleted if it matches
+ *                                  these criteria.
+ * @return                      0 if an object was successfully retreived;
+ *                              BLE_HS_ENOENT if no matching object was found;
+ *                              Other nonzero on error.
+ */
 typedef int ble_store_delete_fn(int obj_type, union ble_store_key *key);
 
 int ble_store_read(int obj_type, union ble_store_key *key,

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/08539587/net/nimble/host/src/ble_eddystone.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_eddystone.c b/net/nimble/host/src/ble_eddystone.c
index 2030c79..5e7a3f0 100644
--- a/net/nimble/host/src/ble_eddystone.c
+++ b/net/nimble/host/src/ble_eddystone.c
@@ -113,7 +113,11 @@ ble_eddystone_set_adv_data_gen(struct ble_hs_adv_fields *adv_fields,
  *                                  this struct before calling this function.
  * @param uid                   The 16-byte UID to advertise.
  *
- * @return                      0 on success; BLE_HS_E... on failure.
+ * @return                      0 on success;
+ *                              BLE_HS_EBUSY if advertising is in progress;
+ *                              BLE_HS_EMSGSIZE if the specified data is too
+ *                                  large to fit in an advertisement;
+ *                              Other nonzero on failure.
  */
 int
 ble_eddystone_set_adv_data_uid(struct ble_hs_adv_fields *adv_fields, void *uid)
@@ -152,7 +156,11 @@ ble_eddystone_set_adv_data_uid(struct ble_hs_adv_fields *adv_fields, void *uid)
  *                                  BLE_EDDYSTONE_URL_SUFFIX_NONE if the suffix
  *                                  is embedded in the body argument.
  *
- * @return                      0 on success; BLE_HS_E... on failure.
+ * @return                      0 on success;
+ *                              BLE_HS_EBUSY if advertising is in progress;
+ *                              BLE_HS_EMSGSIZE if the specified data is too
+ *                                  large to fit in an advertisement;
+ *                              Other nonzero on failure.
  */
 int
 ble_eddystone_set_adv_data_url(struct ble_hs_adv_fields *adv_fields,

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/08539587/net/nimble/host/src/ble_gap.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gap.c b/net/nimble/host/src/ble_gap.c
index 78e8ac1..2745379 100644
--- a/net/nimble/host/src/ble_gap.c
+++ b/net/nimble/host/src/ble_gap.c
@@ -750,7 +750,7 @@ ble_gap_rx_update_complete(struct hci_le_conn_upd_complete *evt)
 }
 
 /**
- * Tells you if the BLE host is in the process of creating a master connection.
+ * Tells you if there is an active central GAP procedure (connect or discover).
  */
 int
 ble_gap_master_in_progress(void)
@@ -1173,6 +1173,14 @@ ble_gap_wl_tx_clear(void)
     return 0;
 }
 
+/**
+ * Overwrites the controller's white list with the specified contents.
+ *
+ * @param white_list            The entries to write to the white list.
+ * @param white_list_count      The number of entries in the white list.
+ *
+ * @return                      0 on success; nonzero on failure.
+ */
 int
 ble_gap_wl_set(const struct ble_gap_white_entry *white_list,
                uint8_t white_list_count)
@@ -1253,6 +1261,16 @@ ble_gap_adv_disable_tx(void)
     return 0;
 }
 
+/**
+ * Stops the currently-active advertising procedure.  A success return
+ * code indicates that advertising has been fully aborted; a new advertising
+ * procedure can be initiated immediately.
+ *
+ * @return                      0 on success;
+ *                              BLE_HS_EALREADY if there is no active
+ *                                  advertising procedure;
+ *                              Other nonzero on error.
+ */
 int
 ble_gap_adv_stop(void)
 {
@@ -1575,8 +1593,38 @@ ble_gap_adv_validate(uint8_t own_addr_type, uint8_t peer_addr_type,
 }
 
 /**
- * Enables the specified discoverable mode and connectable mode, and initiates
- * the advertising process.
+ * Initiates advertising.
+ *
+ * @param own_addr_type         The type of address the stack should use for
+ *                                  itself.  Valid values are:
+ *                                      o BLE_ADDR_TYPE_PUBLIC
+ *                                      o BLE_ADDR_TYPE_RANDOM
+ *                                      o BLE_ADDR_TYPE_RPA_PUB_DEFAULT
+ *                                      o BLE_ADDR_TYPE_RPA_RND_DEFAULT
+ * @param peer_addr_type        This parameter is ignored unless directed
+ *                                  advertising is being used.  Address type of
+ *                                  the peer's identity address.  Valid values
+ *                                  are:
+ *                                      o BLE_ADDR_TYPE_PUBLIC
+ *                                      o BLE_ADDR_TYPE_RANDOM
+ * @param peer_addr             This parameter is ignored unless directed
+ *                                  advertising is being used.  The peer's
+ *                                  six-byte identity address.
+ * @param duration_ms           The duration of the advertisement procedure.
+ *                                  On expiration, the procedure ends and a
+ *                                  BLE_GAP_EVENT_ADV_COMPLETE event is
+ *                                  reported.  Units are milliseconds.  Specify
+ *                                  BLE_HS_FOREVER for no expiration.
+ * @param adv_params            Additional arguments specifying the particulars
+ *                                  of the advertising procedure.
+ * @param cb                    The callback to associate with this advertising
+ *                                  procedure.  If advertising ends, the event
+ *                                  is reported through this callback.  If
+ *                                  advertising results in a connection, the
+ *                                  connection inherits this callback as its
+ *                                  event-reporting mechanism.
+ * @param cb_arg                The optional argument to pass to the callback
+ *                                  function.
  *
  * @return                      0 on success; nonzero on failure.
  */
@@ -1661,6 +1709,17 @@ done:
     return rc;
 }
 
+/**
+ * Configures the data to include in subsequent advertisements.
+ *
+ * @param adv_fields            Specifies the advertisement data.
+ *
+ * @return                      0 on success;
+ *                              BLE_HS_EBUSY if advertising is in progress;
+ *                              BLE_HS_EMSGSIZE if the specified data is too
+ *                                  large to fit in an advertisement;
+ *                              Other nonzero on failure.
+ */
 int
 ble_gap_adv_set_fields(const struct ble_hs_adv_fields *adv_fields)
 {
@@ -1707,6 +1766,17 @@ done:
     return rc;
 }
 
+/**
+ * Configures the data to include in subsequent scan responses.
+ *
+ * @param adv_fields            Specifies the scan response data.
+ *
+ * @return                      0 on success;
+ *                              BLE_HS_EBUSY if advertising is in progress;
+ *                              BLE_HS_EMSGSIZE if the specified data is too
+ *                                  large to fit in an advertisement;
+ *                              Other nonzero on failure.
+ */
 int
 ble_gap_adv_rsp_set_fields(const struct ble_hs_adv_fields *rsp_fields)
 {
@@ -1901,14 +1971,36 @@ ble_gap_disc_validate(uint8_t own_addr_type,
 }
 
 /**
- * Performs the Limited or General Discovery Procedures, as described in
- * vol. 3, part C, section 9.2.5 / 9.2.6.
+ * Performs the Limited or General Discovery Procedures (vol. 3, part C,
+ * section 9.2.5 / 9.2.6).
+ *
+ * @param own_addr_type         This parameter is ignored unless active scanning
+ *                                  is being used. The type of address the
+ *                                  stack should use for itself when sending
+ *                                  scan requests.  Valid values are:
+ *                                      o BLE_ADDR_TYPE_PUBLIC
+ *                                      o BLE_ADDR_TYPE_RANDOM
+ *                                      o BLE_ADDR_TYPE_RPA_PUB_DEFAULT
+ *                                      o BLE_ADDR_TYPE_RPA_RND_DEFAULT
+ * @param duration_ms           The duration of the discovery procedure.
+ *                                  On expiration, the procedure ends and a
+ *                                  BLE_GAP_EVENT_DISC_COMPLETE event is
+ *                                  reported.  Units are milliseconds.  Specify
+ *                                  BLE_HS_FOREVER for no expiration.
+ * @param disc_params           Additional arguments specifying the particulars
+ *                                  of the discovery procedure.
+ * @param cb                    The callback to associate with this discovery
+ *                                  procedure.  Advertising reports and discovery
+ *                                  termination events are reported through
+ *                                  this callback.
+ * @param cb_arg                The optional argument to pass to the callback
+ *                                  function.
  *
  * @return                      0 on success; nonzero on failure.
  */
 int
 ble_gap_disc(uint8_t own_addr_type, int32_t duration_ms,
-             const struct ble_gap_disc_params *in_disc_params,
+             const struct ble_gap_disc_params *disc_params,
              ble_gap_disc_fn *cb, void *cb_arg)
 {
 #if !NIMBLE_OPT(ROLE_OBSERVER)
@@ -1926,7 +2018,7 @@ ble_gap_disc(uint8_t own_addr_type, int32_t duration_ms,
     /* Make a copy of the parameter strcuture and fill unspecified values with
      * defaults.
      */
-    params = *in_disc_params;
+    params = *disc_params;
     ble_gap_disc_fill_dflts(&params);
 
     rc = ble_gap_disc_validate(own_addr_type, &params);
@@ -2047,23 +2139,37 @@ ble_gap_conn_create_tx(uint8_t own_addr_type,
 }
 
 /**
- * Performs the Direct Connection Establishment Procedure, as described in
- * vol. 3, part C, section 9.3.8.
+ * Initiates a connect procedure.
  *
- * @param addr_type             The peer's address type; one of:
- *                                  o BLE_HCI_CONN_PEER_ADDR_PUBLIC
- *                                  o BLE_HCI_CONN_PEER_ADDR_RANDOM
- *                                  o BLE_HCI_CONN_PEER_ADDR_PUBLIC_IDENT
- *                                  o BLE_HCI_CONN_PEER_ADDR_RANDOM_IDENT
- *                                  o BLE_GAP_ADDR_TYPE_WL
- * @param addr                  The address of the peer to connect to.
+ * @param own_addr_type         The type of address the stack should use for
+ *                                  itself during connection establishment.
+ *                                      o BLE_ADDR_TYPE_PUBLIC
+ *                                      o BLE_ADDR_TYPE_RANDOM
+ *                                      o BLE_ADDR_TYPE_RPA_PUB_DEFAULT
+ *                                      o BLE_ADDR_TYPE_RPA_RND_DEFAULT
+ * @param peer_addr_type        The peer's identity address type.  One of:
+ *                                      o BLE_HCI_CONN_PEER_ADDR_PUBLIC
+ *                                      o BLE_HCI_CONN_PEER_ADDR_RANDOM
+ *                                      o BLE_HCI_CONN_PEER_ADDR_PUBLIC_IDENT
+ *                                      o BLE_HCI_CONN_PEER_ADDR_RANDOM_IDENT
+ *                                      o BLE_GAP_ADDR_TYPE_WL
+ * @param peer_addr             The identity address of the peer to connect to.
+ *                                  This parameter is ignored when the white
+ *                                  list is used.
+ * @param duration_ms           The duration of the discovery procedure.
+ *                                  On expiration, the procedure ends and a
+ *                                  BLE_GAP_EVENT_DISC_COMPLETE event is
+ *                                  reported.  Units are milliseconds.
+ * @param conn_params           Additional arguments specifying the particulars
+ *                                  of the connect procedure.  Specify null for
+ *                                  default values.
  *
  * @return                      0 on success; nonzero on failure.
  */
 int
 ble_gap_connect(uint8_t own_addr_type,
                 uint8_t peer_addr_type, const uint8_t *peer_addr,
-                const struct ble_gap_conn_params *params,
+                const struct ble_gap_conn_params *conn_params,
                 ble_gap_event_fn *cb, void *cb_arg)
 {
 #if !NIMBLE_OPT(ROLE_CENTRAL)
@@ -2096,14 +2202,14 @@ ble_gap_connect(uint8_t own_addr_type,
         goto done;
     }
 
-    if (params == NULL) {
-        params = &ble_gap_conn_params_dflt;
+    if (conn_params == NULL) {
+        conn_params = &ble_gap_conn_params_dflt;
     }
 
-    /* XXX: Verify params. */
+    /* XXX: Verify conn_params. */
 
     BLE_HS_LOG(INFO, "GAP procedure initiated: connect; ");
-    ble_gap_log_conn(own_addr_type, peer_addr_type, peer_addr, params);
+    ble_gap_log_conn(own_addr_type, peer_addr_type, peer_addr, conn_params);
     BLE_HS_LOG(INFO, "\n");
 
     ble_gap_master.conn.cb = cb;
@@ -2112,7 +2218,7 @@ ble_gap_connect(uint8_t own_addr_type,
     ble_gap_master.conn.our_addr_type = own_addr_type;
 
     rc = ble_gap_conn_create_tx(own_addr_type, peer_addr_type, peer_addr,
-                                params);
+                                conn_params);
     if (rc != 0) {
         goto done;
     }
@@ -2147,6 +2253,19 @@ ble_gap_conn_active(void)
  * $terminate connection procedure                                           *
  *****************************************************************************/
 
+/**
+ * Terminates an established connection.
+ *
+ * @param conn_handle           The handle corresponding to the connection to
+ *                                  terminate.
+ * @param hci_reason            The HCI error code to indicate as the reason
+ *                                  for termination.
+ *
+ * @return                      0 on success;
+ *                              BLE_HS_ENOTCONN if there is no connection with
+ *                                  the specified handle;
+ *                              Other nonzero on failure.
+ */
 int
 ble_gap_terminate(uint16_t conn_handle, uint8_t hci_reason)
 {
@@ -2188,6 +2307,14 @@ done:
  * $cancel                                                                   *
  *****************************************************************************/
 
+/**
+ * Aborts a connect procedure in progress.
+ *
+ * @return                      0 on success;
+ *                              BLE_HS_EALREADY if there is no active connect
+ *                                  procedure.
+ *                              Other nonzero on error.
+ */
 int
 ble_gap_conn_cancel(void)
 {
@@ -2357,6 +2484,22 @@ ble_gap_update_tx(uint16_t conn_handle,
     return 0;
 }
 
+/**
+ * Initiates a connection parameter update procedure.
+ *
+ * @param conn_handle           The handle corresponding to the connection to
+ *                                  update.
+ * @param params                The connection parameters to attempt to update
+ *                                  to.
+ *
+ * @return                      0 on success;
+ *                              BLE_HS_ENOTCONN if the there is no connection
+ *                                  with the specified handle;
+ *                              BLE_HS_EALREADY if a connection update
+ *                                  procedure for this connection is already in
+ *                                  progress;
+ *                              Other nonzero on error.
+ */
 int
 ble_gap_update_params(uint16_t conn_handle,
                       const struct ble_gap_upd_params *params)
@@ -2407,6 +2550,19 @@ done:
  * $security                                                                 *
  *****************************************************************************/
 
+/**
+ * Initiates the GAP encryption procedure.
+ *
+ * @param conn_handle           The handle corresponding to the connection to
+ *                                  encrypt.
+ *
+ * @return                      0 on success;
+ *                              BLE_HS_ENOTCONN if the there is no connection
+ *                                  with the specified handle;
+ *                              BLE_HS_EALREADY if an encrpytion procedure for
+ *                                  this connection is already in progress;
+ *                              Other nonzero on error.
+ */
 int
 ble_gap_security_initiate(uint16_t conn_handle)
 {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/08539587/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 77daa19..04ff94f 100644
--- a/net/nimble/host/src/ble_gattc.c
+++ b/net/nimble/host/src/ble_gattc.c
@@ -950,7 +950,8 @@ ble_gattc_mtu_err(struct ble_gattc_proc *proc, int status, uint16_t att_handle)
  *                                  procedure.
  * @param cb                    The function to call to report procedure status
  *                                  updates; null for no callback.
- * @param cb_arg                The argument to pass to the callback function.
+ * @param cb_arg                The optional argument to pass to the callback
+ *                                  function.
  *
  * @return                      0 on success; nonzero on failure.
  */
@@ -1180,7 +1181,8 @@ ble_gattc_disc_all_svcs_rx_complete(struct ble_gattc_proc *proc, int status)
  *                                  procedure.
  * @param cb                    The function to call to report procedure status
  *                                  updates; null for no callback.
- * @param cb_arg                The argument to pass to the callback function.
+ * @param cb_arg                The optional argument to pass to the callback
+ *                                  function.
  */
 int
 ble_gattc_disc_all_svcs(uint16_t conn_handle, ble_gatt_disc_svc_fn *cb,
@@ -1381,7 +1383,10 @@ ble_gattc_disc_svc_uuid_rx_complete(struct ble_gattc_proc *proc, int status)
  * @param service_uuid128       The 128-bit UUID of the service to discover.
  * @param cb                    The function to call to report procedure status
  *                                  updates; null for no callback.
- * @param cb_arg                The argument to pass to the callback function.
+ * @param cb_arg                The optional argument to pass to the callback
+ *                                  function.
+ *
+ * @return                      0 on success; nonzero on failure.
  */
 int
 ble_gattc_disc_svc_by_uuid(uint16_t conn_handle, const void *svc_uuid128,
@@ -1694,7 +1699,10 @@ ble_gattc_find_inc_svcs_rx_complete(struct ble_gattc_proc *proc, int status)
  *                                  last handle in the service).
  * @param cb                    The function to call to report procedure status
  *                                  updates; null for no callback.
- * @param cb_arg                The argument to pass to the callback function.
+ * @param cb_arg                The optional argument to pass to the callback
+ *                                  function.
+ *
+ * @return                      0 on success; nonzero on failure.
  */
 int
 ble_gattc_find_inc_svcs(uint16_t conn_handle, uint16_t start_handle,
@@ -1923,7 +1931,10 @@ ble_gattc_disc_all_chrs_rx_complete(struct ble_gattc_proc *proc, int status)
  *                                  last handle in the service).
  * @param cb                    The function to call to report procedure status
  *                                  updates; null for no callback.
- * @param cb_arg                The argument to pass to the callback function.
+ * @param cb_arg                The optional argument to pass to the callback
+ *                                  function.
+ *
+ * @return                      0 on success; nonzero on failure.
  */
 int
 ble_gattc_disc_all_chrs(uint16_t conn_handle, uint16_t start_handle,
@@ -2165,7 +2176,10 @@ ble_gattc_disc_chr_uuid_rx_complete(struct ble_gattc_proc *proc, int status)
  *                                  discover.
  * @param cb                    The function to call to report procedure status
  *                                  updates; null for no callback.
- * @param cb_arg                The argument to pass to the callback function.
+ * @param cb_arg                The optional argument to pass to the callback
+ *                                  function.
+ *
+ * @return                      0 on success; nonzero on failure.
  */
 int
 ble_gattc_disc_chrs_by_uuid(uint16_t conn_handle, uint16_t start_handle,
@@ -2368,7 +2382,10 @@ ble_gattc_disc_all_dscs_rx_complete(struct ble_gattc_proc *proc, int status)
  *                                  definition.
  * @param cb                    The function to call to report procedure status
  *                                  updates; null for no callback.
- * @param cb_arg                The argument to pass to the callback function.
+ * @param cb_arg                The optional argument to pass to the callback
+ *                                  function.
+ *
+ * @return                      0 on success; nonzero on failure.
  */
 int
 ble_gattc_disc_all_dscs(uint16_t conn_handle, uint16_t chr_def_handle,
@@ -2493,7 +2510,10 @@ ble_gattc_read_rx_read_rsp(struct ble_gattc_proc *proc, int status,
  * @param attr_handle           The handle of the characteristic value to read.
  * @param cb                    The function to call to report procedure status
  *                                  updates; null for no callback.
- * @param cb_arg                The argument to pass to the callback function.
+ * @param cb_arg                The optional argument to pass to the callback
+ *                                  function.
+ *
+ * @return                      0 on success; nonzero on failure.
  */
 int
 ble_gattc_read(uint16_t conn_handle, uint16_t attr_handle,
@@ -2649,7 +2669,10 @@ ble_gattc_read_uuid_rx_complete(struct ble_gattc_proc *proc, int status)
  *                                  last handle in the service definition).
  * @param cb                    The function to call to report procedure status
  *                                  updates; null for no callback.
- * @param cb_arg                The argument to pass to the callback function.
+ * @param cb_arg                The optional argument to pass to the callback
+ *                                  function.
+ *
+ * @return                      0 on success; nonzero on failure.
  */
 int
 ble_gattc_read_by_uuid(uint16_t conn_handle, uint16_t start_handle,
@@ -2830,7 +2853,10 @@ ble_gattc_read_long_rx_read_rsp(struct ble_gattc_proc *proc, int status,
  * @param handle                The handle of the characteristic value to read.
  * @param cb                    The function to call to report procedure status
  *                                  updates; null for no callback.
- * @param cb_arg                The argument to pass to the callback function.
+ * @param cb_arg                The optional argument to pass to the callback
+ *                                  function.
+ *
+ * @return                      0 on success; nonzero on failure.
  */
 int
 ble_gattc_read_long(uint16_t conn_handle, uint16_t handle,
@@ -2944,7 +2970,10 @@ ble_gattc_read_mult_err(struct ble_gattc_proc *proc, int status,
  * @param num_handles           The number of entries in the "handles" array.
  * @param cb                    The function to call to report procedure status
  *                                  updates; null for no callback.
- * @param cb_arg                The argument to pass to the callback function.
+ * @param cb_arg                The optional argument to pass to the callback
+ *                                  function.
+ *
+ * @return                      0 on success; nonzero on failure.
  */
 int
 ble_gattc_read_mult(uint16_t conn_handle, const uint16_t *handles,
@@ -3000,9 +3029,8 @@ done:
  *                                  to.
  * @param value                 The value to write to the characteristic.
  * @param value_len             The number of bytes to write.
- * @param cb                    The function to call to report procedure status
- *                                  updates; null for no callback.
- * @param cb_arg                The argument to pass to the callback function.
+ *
+ * @return                      0 on success; nonzero on failure.
  */
 int
 ble_gattc_write_no_rsp(uint16_t conn_handle, uint16_t attr_handle,
@@ -3089,7 +3117,10 @@ ble_gattc_write_err(struct ble_gattc_proc *proc, int status,
  * @param value_len             The number of bytes to write.
  * @param cb                    The function to call to report procedure status
  *                                  updates; null for no callback.
- * @param cb_arg                The argument to pass to the callback function.
+ * @param cb_arg                The optional argument to pass to the callback
+ *                                  function.
+ *
+ * @return                      0 on success; nonzero on failure.
  */
 int
 ble_gattc_write(uint16_t conn_handle, uint16_t attr_handle, const void *value,
@@ -3328,7 +3359,10 @@ ble_gattc_write_long_rx_exec(struct ble_gattc_proc *proc, int status)
  * @param value_len             The number of bytes to write.
  * @param cb                    The function to call to report procedure status
  *                                  updates; null for no callback.
- * @param cb_arg                The argument to pass to the callback function.
+ * @param cb_arg                The optional argument to pass to the callback
+ *                                  function.
+ *
+ * @return                      0 on success; nonzero on failure.
  */
 int
 ble_gattc_write_long(uint16_t conn_handle, uint16_t attr_handle,
@@ -3549,13 +3583,16 @@ ble_gattc_write_reliable_rx_exec(struct ble_gattc_proc *proc, int status)
  *
  * @param conn_handle           The connection over which to execute the
  *                                  procedure.
- * @param attr_handle           The handle of the characteristic value to write
- *                                  to.
- * @param value                 The value to write to the characteristic.
- * @param value_len             The number of bytes to write.
+ * @param attrs                 An array of attribute descriptors; specifies
+ *                                  which characteristics to write to and what
+ *                                  data to write to them.
+ * @param num_attrs             The number of characteristics to write; equal
+ *                                  to the number of elements in the 'attrs'
+ *                                  array.
  * @param cb                    The function to call to report procedure status
  *                                  updates; null for no callback.
- * @param cb_arg                The argument to pass to the callback function.
+ * @param cb_arg                The optional argument to pass to the callback
+ *                                  function.
  */
 int
 ble_gattc_write_reliable(uint16_t conn_handle,
@@ -3607,11 +3644,22 @@ done:
  *****************************************************************************/
 
 /**
- * Sends an attribute notification.  The content of the message is specified
- * in the attr parameter.
+ * Sends a "free-form" characteristic notification.  The content of the message
+ * is specified in the attr parameter.
+ *
+ * @param conn_handle           The connection over which to execute the
+ *                                  procedure.
+ * @param chr_val_handle        The attribute handle to indicate in the
+ *                                  outgoing notification.
+ * @param attr_data             The characteristic value to include in the
+ *                                  outgoing notification.
+ * @param attr_data_len         The number of bytes of attribute data to include
+ *                                  in the notification.
+ *
+ * @return                      0 on success; nonzero on failure.
  */
 int
-ble_gattc_notify_custom(uint16_t conn_handle, uint16_t att_handle,
+ble_gattc_notify_custom(uint16_t conn_handle, uint16_t chr_val_handle,
                         const void *attr_data, uint16_t attr_data_len)
 {
 #if !NIMBLE_OPT(GATT_NOTIFY)
@@ -3624,14 +3672,14 @@ ble_gattc_notify_custom(uint16_t conn_handle, uint16_t att_handle,
 
     STATS_INC(ble_gattc_stats, notify);
 
-    ble_gattc_log_notify(att_handle);
+    ble_gattc_log_notify(chr_val_handle);
 
     if (attr_data == NULL) {
         /* No custom attribute data; read the value from the specified
          * attribute.
          */
         rc = ble_att_svr_read_handle(BLE_HS_CONN_HANDLE_NONE,
-                                     att_handle, &ctxt, NULL);
+                                     chr_val_handle, &ctxt, NULL);
         if (rc != 0) {
             /* Fatal error; application disallowed attribute read. */
             rc = BLE_HS_EAPP;
@@ -3642,7 +3690,7 @@ ble_gattc_notify_custom(uint16_t conn_handle, uint16_t att_handle,
         attr_data_len = ctxt.read.len;
     }
 
-    req.banq_handle = att_handle;
+    req.banq_handle = chr_val_handle;
     rc = ble_att_clt_tx_notify(conn_handle, &req, attr_data, attr_data_len);
     if (rc != 0) {
         goto err;
@@ -3656,8 +3704,16 @@ err:
 }
 
 /**
- * Sends an attribute notification.  The content of the message is read from
+ * Sends a characteristic notification.  The content of the message is read from
  * the specified characteristic.
+ *
+ * @param conn_handle           The connection over which to execute the
+ *                                  procedure.
+ * @param chr_val_handle        The value attribute handle of the
+ *                                  characteristic to include in the outgoing
+ *                                  notification.
+ *
+ * @return                      0 on success; nonzero on failure.
  */
 int
 ble_gattc_notify(uint16_t conn_handle, uint16_t chr_val_handle)
@@ -3747,7 +3803,20 @@ ble_gattc_indicate_rx_rsp(struct ble_gattc_proc *proc)
 }
 
 /**
- * Sends an attribute indication.
+ * Sends a characteristic indication.  The content of the message is read from
+ * the specified characteristic.
+ *
+ * @param conn_handle           The connection over which to execute the
+ *                                  procedure.
+ * @param chr_val_handle        The value attribute handle of the
+ *                                  characteristic to include in the outgoing
+ *                                  indication.
+ * @param cb                    The function to call to report procedure status;
+ *                                  null for no callback.
+ * @param cb_arg                The optional argument to pass to the callback
+ *                                  function.
+ *
+ * @return                      0 on success; nonzero on failure.
  */
 int
 ble_gattc_indicate(uint16_t conn_handle, uint16_t chr_val_handle,

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/08539587/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 82f21b2..2318fdf 100644
--- a/net/nimble/host/src/ble_gatts.c
+++ b/net/nimble/host/src/ble_gatts.c
@@ -901,6 +901,24 @@ ble_gatts_register_round(int *out_num_registered, ble_gatt_register_fn *cb,
     return 0;
 }
 
+/**
+ * Registers a set of services, characteristics, and descriptors to be accessed
+ * by GATT clients.
+ *
+ * @param svcs                  A table of the service definitions to be
+ *                                  registered.
+ * @param cb                    The function to call for each service,
+ *                                  characteristic, and descriptor that gets
+ *                                  registered.
+ * @param cb_arg                The optional argument to pass to the callback
+ *                                  function.
+ *
+ * @return                      0 on success;
+ *                              BLE_HS_ENOMEM if registration failed due to
+ *                                  resource exhaustion;
+ *                              BLE_HS_EINVAL if the service definition table
+ *                                  contains an invalid element.
+ */
 int
 ble_gatts_register_svcs(const struct ble_gatt_svc_def *svcs,
                         ble_gatt_register_fn *cb, void *cb_arg)

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/08539587/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 e78b5aa..e3f4bcb 100644
--- a/net/nimble/host/src/ble_hs.c
+++ b/net/nimble/host/src/ble_hs.c
@@ -285,6 +285,16 @@ ble_hs_event_enqueue(struct os_event *ev)
     os_eventq_put(ble_hs_parent_evq, &ble_hs_event_co.cf_c.c_ev);
 }
 
+/**
+ * Sends a sequence of HCI commands to the controller.  This sequence of
+ * commands is necessary for the host and controller to remain in sync.  This
+ * function must be called before any other host functionality is used, but it
+ * must be called after both the host and controller are initialized.
+ * Typically, the host-parent-task calls this function at the top of its task
+ * routine.
+ *
+ * @return                      0 on success; nonzero on error.
+ */
 int
 ble_hs_start(void)
 {
@@ -348,7 +358,21 @@ ble_hs_free_mem(void)
 }
 
 /**
- * Initializes the host portion of the BLE stack.
+ * Initializes the NimBLE host.  This function must be called before the OS is
+ * started.  The NimBLE stack requires an application task to function.  One
+ * application task in particular is designated as the "host parent task".  In
+ * addition to application-specific work, the host parent task does work for
+ * NimBLE by processing events generated by the host.
+ *
+ * @param app_evq               The event queue associated with the host parent
+ *                                  task.
+ * @param cfg                   The set of configuration settings to initialize
+ *                                  the host with.  Specify null for defaults.
+ *
+ * @return                      0 on success;
+ *                              BLE_HS_ENOMEM if initialization failed due to
+ *                                  resource exhaustion.
+ *                              Other nonzero on error.
  */
 int
 ble_hs_init(struct os_eventq *app_evq, struct ble_hs_cfg *cfg)

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/08539587/net/nimble/host/src/ble_hs_adv.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_adv.c b/net/nimble/host/src/ble_hs_adv.c
index dffbc1f..8a7ed50 100644
--- a/net/nimble/host/src/ble_hs_adv.c
+++ b/net/nimble/host/src/ble_hs_adv.c
@@ -107,7 +107,7 @@ ble_hs_adv_set_array32(uint8_t type, uint8_t num_elems, const uint32_t *elems,
 /**
  * Sets the significant part of the data in outgoing advertisements.
  *
- * @return                      0 on success;  on failure.
+ * @return                      0 on success; nonzero on failure.
  */
 int
 ble_hs_adv_set_fields(const struct ble_hs_adv_fields *adv_fields,

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/08539587/net/nimble/host/src/ble_ibeacon.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_ibeacon.c b/net/nimble/host/src/ble_ibeacon.c
index 06e203a..68c182f 100644
--- a/net/nimble/host/src/ble_ibeacon.c
+++ b/net/nimble/host/src/ble_ibeacon.c
@@ -23,6 +23,19 @@
 
 #define BLE_IBEACON_MFG_DATA_SIZE       25
 
+/**
+ * Configures the device to advertise iBeacons.
+ *
+ * @param uuid                  The 128-bit UUID to advertise.
+ * @param major                 The major version number to include in
+ *                                  iBeacons.
+ * @param minor                 The minor version number to include in
+ *                                  iBeacons.
+ *
+ * @return                      0 on success;
+ *                              BLE_HS_EBUSY if advertising is in progress;
+ *                              Other nonzero on failure.
+ */
 int
 ble_ibeacon_set_adv_data(void *uuid128, uint16_t major, uint16_t minor)
 {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/08539587/net/nimble/host/src/ble_uuid.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_uuid.c b/net/nimble/host/src/ble_uuid.c
index 118b6ea..89a9bf4 100644
--- a/net/nimble/host/src/ble_uuid.c
+++ b/net/nimble/host/src/ble_uuid.c
@@ -34,9 +34,13 @@ static uint8_t ble_uuid_base[16] = {
  * Attempts to convert the supplied 128-bit UUID into its shortened 16-bit
  * form.
  *
+ * @param uuid128                   The 128-bit UUID to attempt to convert.
+ *                                      This must point to 16 contiguous bytes.
+ *
  * @return                          Positive 16-bit unsigned integer on
  *                                      success;
- *                                  0 if the UUID could not be converted.
+ *                                  0 if the UUID cannot be represented in 16
+ *                                      bits.
  */
 uint16_t
 ble_uuid_128_to_16(const void *uuid128)
@@ -68,8 +72,19 @@ ble_uuid_128_to_16(const void *uuid128)
     return uuid16;
 }
 
+/**
+ * Expands a 16-bit UUID into its 128-bit form.
+ *
+ * @param uuid16                The 16-bit UUID to convert.
+ * @param out_uuid128           On success, the resulting 128-bit UUID gets
+ *                                  written here.
+ *
+ * @return                      0 on success;
+ *                              BLE_HS_EINVAL if uuid16 is not a valid 16-bit
+ *                                  UUID.
+ */
 int
-ble_uuid_16_to_128(uint16_t uuid16, void *uuid128)
+ble_uuid_16_to_128(uint16_t uuid16, void *out_uuid128)
 {
     uint8_t *u8ptr;
 
@@ -77,7 +92,7 @@ ble_uuid_16_to_128(uint16_t uuid16, void *uuid128)
         return BLE_HS_EINVAL;
     }
 
-    u8ptr = uuid128;
+    u8ptr = out_uuid128;
 
     memcpy(u8ptr, ble_uuid_base, 16);
     htole16(u8ptr + 12, uuid16);



[08/50] [abbrv] incubator-mynewt-core git commit: BLE Host - ble_gap_conn_ctxt->ble_gap_event_ctxt

Posted by cc...@apache.org.
BLE Host - ble_gap_conn_ctxt->ble_gap_event_ctxt


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

Branch: refs/heads/ble_hs_api
Commit: 9fd788983de9aceb4bd7b03537f1e9d081b10885
Parents: 3890be3
Author: Christopher Collins <cc...@apache.org>
Authored: Fri Jun 24 11:20:18 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Jul 11 16:43:31 2016 -0700

----------------------------------------------------------------------
 apps/bleprph/src/main.c                     |  4 ++--
 apps/bletiny/src/main.c                     |  2 +-
 net/nimble/host/include/host/ble_gap.h      |  4 ++--
 net/nimble/host/src/ble_gap.c               | 28 ++++++++++++------------
 net/nimble/host/src/test/ble_att_svr_test.c |  2 +-
 net/nimble/host/src/test/ble_gap_test.c     |  2 +-
 net/nimble/host/src/test/ble_l2cap_test.c   |  2 +-
 net/nimble/host/src/test/ble_os_test.c      |  4 ++--
 net/nimble/host/src/test/ble_sm_test_util.c |  2 +-
 net/nimble/host/src/test/ble_sm_test_util.h |  2 +-
 10 files changed, 26 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9fd78898/apps/bleprph/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bleprph/src/main.c b/apps/bleprph/src/main.c
index 11c3dc0..9e3a9b5 100755
--- a/apps/bleprph/src/main.c
+++ b/apps/bleprph/src/main.c
@@ -86,7 +86,7 @@ uint8_t bleprph_reconnect_addr[6];
 uint8_t bleprph_pref_conn_params[8];
 uint8_t bleprph_gatt_service_changed[4];
 
-static int bleprph_gap_event(int event, struct ble_gap_conn_ctxt *ctxt,
+static int bleprph_gap_event(int event, struct ble_gap_event_ctxt *ctxt,
                              void *arg);
 
 /**
@@ -193,7 +193,7 @@ bleprph_advertise(void)
  *                                  particular GAP event being signalled.
  */
 static int
-bleprph_gap_event(int event, struct ble_gap_conn_ctxt *ctxt, void *arg)
+bleprph_gap_event(int event, struct ble_gap_event_ctxt *ctxt, void *arg)
 {
     switch (event) {
     case BLE_GAP_EVENT_CONNECT:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9fd78898/apps/bletiny/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/main.c b/apps/bletiny/src/main.c
index 8c53117..d8c43f2 100755
--- a/apps/bletiny/src/main.c
+++ b/apps/bletiny/src/main.c
@@ -885,7 +885,7 @@ bletiny_on_write_reliable(uint16_t conn_handle, struct ble_gatt_error *error,
 }
 
 static int
-bletiny_gap_event(int event, struct ble_gap_conn_ctxt *ctxt, void *arg)
+bletiny_gap_event(int event, struct ble_gap_event_ctxt *ctxt, void *arg)
 {
     int conn_idx;
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9fd78898/net/nimble/host/include/host/ble_gap.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/ble_gap.h b/net/nimble/host/include/host/ble_gap.h
index 90b3f85..48ca957 100644
--- a/net/nimble/host/include/host/ble_gap.h
+++ b/net/nimble/host/include/host/ble_gap.h
@@ -202,7 +202,7 @@ struct ble_gap_passkey_action {
     uint32_t numcmp;
 };
 
-struct ble_gap_conn_ctxt {
+struct ble_gap_event_ctxt {
     struct ble_gap_conn_desc *desc;
 
     union {
@@ -245,7 +245,7 @@ struct ble_gap_conn_ctxt {
     };
 };
 
-typedef int ble_gap_event_fn(int event, struct ble_gap_conn_ctxt *ctxt,
+typedef int ble_gap_event_fn(int event, struct ble_gap_event_ctxt *ctxt,
                              void *arg);
 
 struct ble_gap_disc_desc {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9fd78898/net/nimble/host/src/ble_gap.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gap.c b/net/nimble/host/src/ble_gap.c
index 9270a9f..14b334d 100644
--- a/net/nimble/host/src/ble_gap.c
+++ b/net/nimble/host/src/ble_gap.c
@@ -372,7 +372,7 @@ ble_gap_find_conn(uint16_t handle, struct ble_gap_conn_desc *out_desc)
  *****************************************************************************/
 
 static int
-ble_gap_call_event_cb(int event, struct ble_gap_conn_ctxt *ctxt,
+ble_gap_call_event_cb(int event, struct ble_gap_event_ctxt *ctxt,
                       ble_gap_event_fn *cb, void *cb_arg)
 {
     int rc;
@@ -434,7 +434,7 @@ ble_gap_slave_extract_cb(ble_gap_event_fn **out_cb, void **out_cb_arg)
 static void
 ble_gap_adv_finished(void)
 {
-    struct ble_gap_conn_ctxt ctxt;
+    struct ble_gap_event_ctxt ctxt;
     struct ble_gap_conn_desc desc;
     ble_gap_event_fn *cb;
     void *cb_arg;
@@ -452,7 +452,7 @@ ble_gap_adv_finished(void)
 static int
 ble_gap_master_connect_failure(int status)
 {
-    struct ble_gap_conn_ctxt ctxt;
+    struct ble_gap_event_ctxt ctxt;
     struct ble_gap_conn_desc desc;
     ble_gap_event_fn *cb;
     void *cb_arg;
@@ -478,7 +478,7 @@ ble_gap_master_connect_failure(int status)
 static int
 ble_gap_master_connect_cancel(void)
 {
-    struct ble_gap_conn_ctxt ctxt;
+    struct ble_gap_event_ctxt ctxt;
     struct ble_gap_conn_desc desc;
     ble_gap_event_fn *cb;
     void *cb_arg;
@@ -526,7 +526,7 @@ ble_gap_call_master_disc_cb(int event, int status,
 static void
 ble_gap_update_notify(uint16_t conn_handle, int status)
 {
-    struct ble_gap_conn_ctxt ctxt;
+    struct ble_gap_event_ctxt ctxt;
     struct ble_gap_snapshot snap;
     int rc;
 
@@ -650,7 +650,7 @@ ble_gap_update_failed(uint16_t conn_handle, int status)
 static void
 ble_gap_conn_broken(struct ble_gap_snapshot *snap, int reason)
 {
-    struct ble_gap_conn_ctxt ctxt;
+    struct ble_gap_event_ctxt ctxt;
 
     /* XXX: Consider removing the connection from the list and handing it to
      * each of the "connection_broken" functions below.
@@ -677,7 +677,7 @@ ble_gap_rx_disconn_complete(struct hci_disconn_complete *evt)
     return;
 #endif
 
-    struct ble_gap_conn_ctxt ctxt;
+    struct ble_gap_event_ctxt ctxt;
     struct ble_gap_snapshot snap;
     int status;
     int rc;
@@ -709,7 +709,7 @@ ble_gap_rx_update_complete(struct hci_le_conn_upd_complete *evt)
     return;
 #endif
 
-    struct ble_gap_conn_ctxt ctxt;
+    struct ble_gap_event_ctxt ctxt;
     struct ble_gap_snapshot snap;
     struct ble_hs_conn *conn;
 
@@ -905,7 +905,7 @@ ble_gap_rx_conn_complete(struct hci_le_conn_complete *evt)
     return BLE_HS_ENOTSUP;
 #endif
 
-    struct ble_gap_conn_ctxt ctxt;
+    struct ble_gap_event_ctxt ctxt;
     struct ble_gap_snapshot snap;
     struct ble_hs_conn *conn;
     int rc;
@@ -1017,7 +1017,7 @@ int
 ble_gap_rx_l2cap_update_req(uint16_t conn_handle,
                             struct ble_gap_upd_params *params)
 {
-    struct ble_gap_conn_ctxt ctxt;
+    struct ble_gap_event_ctxt ctxt;
     struct ble_gap_snapshot snap;
     int rc;
 
@@ -2245,7 +2245,7 @@ ble_gap_rx_param_req(struct hci_le_conn_param_req *evt)
 
     struct ble_gap_upd_params peer_params;
     struct ble_gap_upd_params self_params;
-    struct ble_gap_conn_ctxt ctxt;
+    struct ble_gap_event_ctxt ctxt;
     struct ble_gap_snapshot snap;
     uint8_t reject_reason;
     int rc;
@@ -2485,7 +2485,7 @@ ble_gap_passkey_event(uint16_t conn_handle,
     return;
 #endif
 
-    struct ble_gap_conn_ctxt ctxt;
+    struct ble_gap_event_ctxt ctxt;
     struct ble_gap_snapshot snap;
     struct ble_hs_conn *conn;
 
@@ -2520,7 +2520,7 @@ ble_gap_enc_event(uint16_t conn_handle, int status, int security_restored)
     return;
 #endif
 
-    struct ble_gap_conn_ctxt ctxt;
+    struct ble_gap_event_ctxt ctxt;
     struct ble_gap_snapshot snap;
     int rc;
 
@@ -2551,7 +2551,7 @@ ble_gap_notify_event(uint16_t conn_handle, uint16_t attr_handle,
                      void *attr_data, uint16_t attr_len, int is_indication)
 {
     /* XXX: Early return if notifications and indications disabled. */
-    struct ble_gap_conn_ctxt ctxt;
+    struct ble_gap_event_ctxt ctxt;
     struct ble_gap_snapshot snap;
     int rc;
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9fd78898/net/nimble/host/src/test/ble_att_svr_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_att_svr_test.c b/net/nimble/host/src/test/ble_att_svr_test.c
index 2afd6f6..f89bd1c 100644
--- a/net/nimble/host/src/test/ble_att_svr_test.c
+++ b/net/nimble/host/src/test/ble_att_svr_test.c
@@ -43,7 +43,7 @@ static int ble_att_svr_test_attr_n_len;
 
 static int
 ble_att_svr_test_misc_gap_cb(int event,
-                             struct ble_gap_conn_ctxt *ctxt, void *arg)
+                             struct ble_gap_event_ctxt *ctxt, void *arg)
 {
     switch (event) {
     case BLE_GAP_EVENT_NOTIFY:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9fd78898/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 a175dc9..5c8489f 100644
--- a/net/nimble/host/src/test/ble_gap_test.c
+++ b/net/nimble/host/src/test/ble_gap_test.c
@@ -84,7 +84,7 @@ ble_gap_test_util_disc_cb(int event, int status,
 }
 
 static int
-ble_gap_test_util_connect_cb(int event, struct ble_gap_conn_ctxt *ctxt,
+ble_gap_test_util_connect_cb(int event, struct ble_gap_event_ctxt *ctxt,
                              void *arg)
 {
     int *fail_reason;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9fd78898/net/nimble/host/src/test/ble_l2cap_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_l2cap_test.c b/net/nimble/host/src/test/ble_l2cap_test.c
index 161bd55..1e373f5 100644
--- a/net/nimble/host/src/test/ble_l2cap_test.c
+++ b/net/nimble/host/src/test/ble_l2cap_test.c
@@ -480,7 +480,7 @@ TEST_CASE(ble_l2cap_test_case_sig_unsol_rsp)
  *****************************************************************************/
 
 static int
-ble_l2cap_test_util_conn_cb(int event, struct ble_gap_conn_ctxt *ctxt,
+ble_l2cap_test_util_conn_cb(int event, struct ble_gap_event_ctxt *ctxt,
                             void *arg)
 {
     int *accept;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9fd78898/net/nimble/host/src/test/ble_os_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_os_test.c b/net/nimble/host/src/test/ble_os_test.c
index a856351..7aae46e 100644
--- a/net/nimble/host/src/test/ble_os_test.c
+++ b/net/nimble/host/src/test/ble_os_test.c
@@ -92,7 +92,7 @@ ble_os_test_misc_conn_exists(uint16_t conn_handle)
 
 static int
 ble_gap_direct_connect_test_connect_cb(int event,
-                                       struct ble_gap_conn_ctxt *ctxt,
+                                       struct ble_gap_event_ctxt *ctxt,
                                        void *arg)
 {
     int *cb_called;
@@ -248,7 +248,7 @@ TEST_CASE(ble_gap_gen_disc_test_case)
 }
 
 static int
-ble_gap_terminate_cb(int event, struct ble_gap_conn_ctxt *ctxt, void *arg)
+ble_gap_terminate_cb(int event, struct ble_gap_event_ctxt *ctxt, void *arg)
 {
     int *disconn_handle;
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9fd78898/net/nimble/host/src/test/ble_sm_test_util.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_sm_test_util.c b/net/nimble/host/src/test/ble_sm_test_util.c
index be38433..1cc8af9 100644
--- a/net/nimble/host/src/test/ble_sm_test_util.c
+++ b/net/nimble/host/src/test/ble_sm_test_util.c
@@ -263,7 +263,7 @@ ble_sm_test_util_init_good(struct ble_sm_test_params *params,
 struct ble_gap_passkey_action ble_sm_test_ioact;
 
 int
-ble_sm_test_util_conn_cb(int event, struct ble_gap_conn_ctxt *ctxt, void *arg)
+ble_sm_test_util_conn_cb(int event, struct ble_gap_event_ctxt *ctxt, void *arg)
 {
     int rc;
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9fd78898/net/nimble/host/src/test/ble_sm_test_util.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_sm_test_util.h b/net/nimble/host/src/test/ble_sm_test_util.h
index 3b0688b..099ed28 100644
--- a/net/nimble/host/src/test/ble_sm_test_util.h
+++ b/net/nimble/host/src/test/ble_sm_test_util.h
@@ -78,7 +78,7 @@ extern union ble_store_key ble_sm_test_store_key;
 extern union ble_store_value ble_sm_test_store_value;
 
 void ble_sm_test_util_init(void);
-int ble_sm_test_util_conn_cb(int event, struct ble_gap_conn_ctxt *ctxt,
+int ble_sm_test_util_conn_cb(int event, struct ble_gap_event_ctxt *ctxt,
                              void *arg);
 void ble_sm_test_util_io_inject(struct ble_sm_test_passkey_info *passkey_info,
                                 uint8_t cur_sm_state);


[48/50] [abbrv] incubator-mynewt-core git commit: bletiny - conn: peer_addr_type=public by dflt.

Posted by cc...@apache.org.
bletiny - conn: peer_addr_type=public by dflt.


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

Branch: refs/heads/ble_hs_api
Commit: fe132293c9ef3285c12c3597da50ba9dddd66849
Parents: 77b9d5e
Author: Christopher Collins <cc...@apache.org>
Authored: Mon Jul 11 16:41:56 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Jul 11 16:43:35 2016 -0700

----------------------------------------------------------------------
 apps/bletiny/src/cmd.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/fe132293/apps/bletiny/src/cmd.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/cmd.c b/apps/bletiny/src/cmd.c
index 6043aeb..3d05fb7 100644
--- a/apps/bletiny/src/cmd.c
+++ b/apps/bletiny/src/cmd.c
@@ -395,8 +395,9 @@ cmd_conn(int argc, char **argv)
         return 0;
     }
 
-    peer_addr_type = parse_arg_kv("peer_addr_type", cmd_conn_peer_addr_types,
-                                  &rc);
+    peer_addr_type = parse_arg_kv_default("peer_addr_type",
+                                          cmd_conn_peer_addr_types,
+                                          BLE_ADDR_TYPE_PUBLIC, &rc);
     if (rc != 0) {
         return rc;
     }


[04/50] [abbrv] incubator-mynewt-core git commit: bletiny - Use new GATT registration API.

Posted by cc...@apache.org.
bletiny - Use new GATT registration API.


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

Branch: refs/heads/ble_hs_api
Commit: 808148ad9334bc27eb09738b6701be3b8eef379a
Parents: 980c937
Author: Christopher Collins <cc...@apache.org>
Authored: Wed Jun 22 13:26:06 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Jul 11 16:43:30 2016 -0700

----------------------------------------------------------------------
 apps/bletiny/src/gatt_svr.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/808148ad/apps/bletiny/src/gatt_svr.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/gatt_svr.c b/apps/bletiny/src/gatt_svr.c
index ddf4e1f..a99b86b 100644
--- a/apps/bletiny/src/gatt_svr.c
+++ b/apps/bletiny/src/gatt_svr.c
@@ -429,24 +429,24 @@ gatt_svr_register_cb(uint8_t op, union ble_gatt_register_ctxt *ctxt, void *arg)
     switch (op) {
     case BLE_GATT_REGISTER_OP_SVC:
         BLETINY_LOG(DEBUG, "registered service %s with handle=%d\n",
-                    gatt_svr_uuid_to_s(ctxt->svc_reg.svc->uuid128, buf),
-                    ctxt->svc_reg.handle);
+                    gatt_svr_uuid_to_s(ctxt->svc.svc_def->uuid128, buf),
+                    ctxt->svc.handle);
         break;
 
     case BLE_GATT_REGISTER_OP_CHR:
         BLETINY_LOG(DEBUG, "registering characteristic %s with "
                            "def_handle=%d val_handle=%d\n",
-                    gatt_svr_uuid_to_s(ctxt->chr_reg.chr->uuid128, buf),
-                    ctxt->chr_reg.def_handle,
-                    ctxt->chr_reg.val_handle);
+                    gatt_svr_uuid_to_s(ctxt->chr.chr_def->uuid128, buf),
+                    ctxt->chr.def_handle,
+                    ctxt->chr.val_handle);
         break;
 
     case BLE_GATT_REGISTER_OP_DSC:
         BLETINY_LOG(DEBUG, "registering descriptor %s with handle=%d "
                            "chr_handle=%d\n",
-                    gatt_svr_uuid_to_s(ctxt->dsc_reg.dsc->uuid128, buf),
-                    ctxt->dsc_reg.dsc_handle,
-                    ctxt->dsc_reg.chr_def_handle);
+                    gatt_svr_uuid_to_s(ctxt->dsc.dsc_def->uuid128, buf),
+                    ctxt->dsc.dsc_handle,
+                    ctxt->dsc.chr_def_handle);
         break;
 
     default:


[22/50] [abbrv] incubator-mynewt-core git commit: ble apps - Use new GATT callback API.

Posted by cc...@apache.org.
ble apps - Use new GATT callback API.


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

Branch: refs/heads/ble_hs_api
Commit: 81b89f6731e473d0e45d293c70f10e8e3bc6e2e5
Parents: 3402795
Author: Christopher Collins <cc...@apache.org>
Authored: Fri Jun 24 18:26:19 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Jul 11 16:43:32 2016 -0700

----------------------------------------------------------------------
 apps/bleprph/src/gatt_svr.c | 72 ++++++++++++++++++++--------------------
 apps/bletiny/src/gatt_svr.c | 72 ++++++++++++++++++++--------------------
 2 files changed, 72 insertions(+), 72 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/81b89f67/apps/bleprph/src/gatt_svr.c
----------------------------------------------------------------------
diff --git a/apps/bleprph/src/gatt_svr.c b/apps/bleprph/src/gatt_svr.c
index fa798ec..6386663 100644
--- a/apps/bleprph/src/gatt_svr.c
+++ b/apps/bleprph/src/gatt_svr.c
@@ -178,15 +178,15 @@ gatt_svr_chr_write(uint8_t op, struct ble_gatt_access_ctxt *ctxt,
                    uint16_t *len)
 {
     assert(op == BLE_GATT_ACCESS_OP_WRITE_CHR);
-    if (ctxt->chr.write.len < min_len ||
-        ctxt->chr.write.len > max_len) {
+    if (ctxt->att->write.len < min_len ||
+        ctxt->att->write.len > max_len) {
 
         return BLE_ATT_ERR_INVALID_ATTR_VALUE_LEN;
     }
 
-    memcpy(dst, ctxt->chr.write.data, ctxt->chr.write.len);
+    memcpy(dst, ctxt->att->write.data, ctxt->att->write.len);
     if (len != NULL) {
-        *len = ctxt->chr.write.len;
+        *len = ctxt->att->write.len;
     }
 
     return 0;
@@ -198,41 +198,41 @@ gatt_svr_chr_access_gap(uint16_t conn_handle, uint16_t attr_handle, uint8_t op,
 {
     uint16_t uuid16;
 
-    uuid16 = ble_uuid_128_to_16(ctxt->chr.def->uuid128);
+    uuid16 = ble_uuid_128_to_16(ctxt->chr->uuid128);
     assert(uuid16 != 0);
 
     switch (uuid16) {
     case BLE_GAP_CHR_UUID16_DEVICE_NAME:
         assert(op == BLE_GATT_ACCESS_OP_READ_CHR);
-        ctxt->chr.read.data = bleprph_device_name;
-        ctxt->chr.read.len = strlen(bleprph_device_name);
+        ctxt->att->read.data = bleprph_device_name;
+        ctxt->att->read.len = strlen(bleprph_device_name);
         break;
 
     case BLE_GAP_CHR_UUID16_APPEARANCE:
         assert(op == BLE_GATT_ACCESS_OP_READ_CHR);
-        ctxt->chr.read.data = &bleprph_appearance;
-        ctxt->chr.read.len = sizeof bleprph_appearance;
+        ctxt->att->read.data = &bleprph_appearance;
+        ctxt->att->read.len = sizeof bleprph_appearance;
         break;
 
     case BLE_GAP_CHR_UUID16_PERIPH_PRIV_FLAG:
         assert(op == BLE_GATT_ACCESS_OP_READ_CHR);
-        ctxt->chr.read.data = &bleprph_privacy_flag;
-        ctxt->chr.read.len = sizeof bleprph_privacy_flag;
+        ctxt->att->read.data = &bleprph_privacy_flag;
+        ctxt->att->read.len = sizeof bleprph_privacy_flag;
         break;
 
     case BLE_GAP_CHR_UUID16_RECONNECT_ADDR:
         assert(op == BLE_GATT_ACCESS_OP_WRITE_CHR);
-        if (ctxt->chr.write.len != sizeof bleprph_reconnect_addr) {
+        if (ctxt->att->write.len != sizeof bleprph_reconnect_addr) {
             return BLE_ATT_ERR_INVALID_ATTR_VALUE_LEN;
         }
-        memcpy(bleprph_reconnect_addr, ctxt->chr.write.data,
+        memcpy(bleprph_reconnect_addr, ctxt->att->write.data,
                sizeof bleprph_reconnect_addr);
         break;
 
     case BLE_GAP_CHR_UUID16_PERIPH_PREF_CONN_PARAMS:
         assert(op == BLE_GATT_ACCESS_OP_READ_CHR);
-        ctxt->chr.read.data = &bleprph_pref_conn_params;
-        ctxt->chr.read.len = sizeof bleprph_pref_conn_params;
+        ctxt->att->read.data = &bleprph_pref_conn_params;
+        ctxt->att->read.len = sizeof bleprph_pref_conn_params;
         break;
 
     default:
@@ -249,20 +249,20 @@ gatt_svr_chr_access_gatt(uint16_t conn_handle, uint16_t attr_handle, uint8_t op,
 {
     uint16_t uuid16;
 
-    uuid16 = ble_uuid_128_to_16(ctxt->chr.def->uuid128);
+    uuid16 = ble_uuid_128_to_16(ctxt->chr->uuid128);
     assert(uuid16 != 0);
 
     switch (uuid16) {
     case BLE_GATT_CHR_SERVICE_CHANGED_UUID16:
         if (op == BLE_GATT_ACCESS_OP_WRITE_CHR) {
-            if (ctxt->chr.write.len != sizeof bleprph_gatt_service_changed) {
+            if (ctxt->att->write.len != sizeof bleprph_gatt_service_changed) {
                 return BLE_ATT_ERR_INVALID_ATTR_VALUE_LEN;
             }
-            memcpy(bleprph_gatt_service_changed, ctxt->chr.write.data,
+            memcpy(bleprph_gatt_service_changed, ctxt->att->write.data,
                    sizeof bleprph_gatt_service_changed);
         } else if (op == BLE_GATT_ACCESS_OP_READ_CHR) {
-            ctxt->chr.read.data = &bleprph_gatt_service_changed;
-            ctxt->chr.read.len = sizeof bleprph_gatt_service_changed;
+            ctxt->att->read.data = &bleprph_gatt_service_changed;
+            ctxt->att->read.len = sizeof bleprph_gatt_service_changed;
         }
         break;
 
@@ -291,14 +291,14 @@ gatt_svr_chr_access_alert(uint16_t conn_handle, uint16_t attr_handle,
     uint16_t uuid16;
     int rc;
 
-    uuid16 = ble_uuid_128_to_16(ctxt->chr.def->uuid128);
+    uuid16 = ble_uuid_128_to_16(ctxt->chr->uuid128);
     assert(uuid16 != 0);
 
     switch (uuid16) {
     case GATT_SVR_CHR_SUP_NEW_ALERT_CAT_UUID:
         assert(op == BLE_GATT_ACCESS_OP_READ_CHR);
-        ctxt->chr.read.data = &gatt_svr_new_alert_cat;
-        ctxt->chr.read.len = sizeof gatt_svr_new_alert_cat;
+        ctxt->att->read.data = &gatt_svr_new_alert_cat;
+        ctxt->att->read.len = sizeof gatt_svr_new_alert_cat;
         return 0;
 
     case GATT_SVR_CHR_NEW_ALERT:
@@ -308,15 +308,15 @@ gatt_svr_chr_access_alert(uint16_t conn_handle, uint16_t attr_handle,
                                     &gatt_svr_new_alert_val_len);
             return rc;
         } else if (op == BLE_GATT_ACCESS_OP_READ_CHR) {
-            ctxt->chr.read.data = (void *)&gatt_svr_new_alert_val;
-            ctxt->chr.read.len = sizeof gatt_svr_new_alert_val;
+            ctxt->att->read.data = (void *)&gatt_svr_new_alert_val;
+            ctxt->att->read.len = sizeof gatt_svr_new_alert_val;
             return 0;
         }
 
     case GATT_SVR_CHR_SUP_UNR_ALERT_CAT_UUID:
         assert(op == BLE_GATT_ACCESS_OP_READ_CHR);
-        ctxt->chr.read.data = &gatt_svr_unr_alert_cat;
-        ctxt->chr.read.len = sizeof gatt_svr_unr_alert_cat;
+        ctxt->att->read.data = &gatt_svr_unr_alert_cat;
+        ctxt->att->read.len = sizeof gatt_svr_unr_alert_cat;
         return 0;
 
     case GATT_SVR_CHR_UNR_ALERT_STAT_UUID:
@@ -324,8 +324,8 @@ gatt_svr_chr_access_alert(uint16_t conn_handle, uint16_t attr_handle,
             rc = gatt_svr_chr_write(op, ctxt, 2, 2, &gatt_svr_unr_alert_stat,
                                     NULL);
         } else {
-            ctxt->chr.read.data = &gatt_svr_unr_alert_stat;
-            ctxt->chr.read.len = sizeof gatt_svr_unr_alert_stat;
+            ctxt->att->read.data = &gatt_svr_unr_alert_stat;
+            ctxt->att->read.len = sizeof gatt_svr_unr_alert_stat;
             rc = 0;
         }
         return rc;
@@ -347,14 +347,14 @@ gatt_svr_chr_access_alert(uint16_t conn_handle, uint16_t attr_handle,
 
 static int
 gatt_svr_chr_access_sec_test(uint16_t conn_handle, uint16_t attr_handle,
-                            uint8_t op, struct ble_gatt_access_ctxt *ctxt,
-                            void *arg)
+                             uint8_t op, struct ble_gatt_access_ctxt *ctxt,
+                             void *arg)
 {
     const void *uuid128;
     int rand_num;
     int rc;
 
-    uuid128 = ctxt->chr.def->uuid128;
+    uuid128 = ctxt->chr->uuid128;
 
     /* Determine which characteristic is being accessed by examining its
      * 128-bit UUID.
@@ -367,16 +367,16 @@ gatt_svr_chr_access_sec_test(uint16_t conn_handle, uint16_t attr_handle,
          * to hold the response data.
          */
         rand_num = rand();
-        memcpy(ctxt->chr.read.buf, &rand_num, sizeof rand_num);
-        ctxt->chr.read.len = sizeof rand_num;
+        memcpy(ctxt->att->read.buf, &rand_num, sizeof rand_num);
+        ctxt->att->read.len = sizeof rand_num;
         return 0;
     }
 
     if (memcmp(uuid128, gatt_svr_chr_sec_test_static_uuid, 16) == 0) {
         switch (op) {
         case BLE_GATT_ACCESS_OP_READ_CHR:
-            ctxt->chr.read.data = &gatt_svr_sec_test_static_val;
-            ctxt->chr.read.len = sizeof gatt_svr_sec_test_static_val;
+            ctxt->att->read.data = &gatt_svr_sec_test_static_val;
+            ctxt->att->read.len = sizeof gatt_svr_sec_test_static_val;
             return 0;
 
         case BLE_GATT_ACCESS_OP_WRITE_CHR:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/81b89f67/apps/bletiny/src/gatt_svr.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/gatt_svr.c b/apps/bletiny/src/gatt_svr.c
index 321bf9d..19b3a8b 100644
--- a/apps/bletiny/src/gatt_svr.c
+++ b/apps/bletiny/src/gatt_svr.c
@@ -178,15 +178,15 @@ gatt_svr_chr_write(uint8_t op, struct ble_gatt_access_ctxt *ctxt,
                    uint16_t *len)
 {
     assert(op == BLE_GATT_ACCESS_OP_WRITE_CHR);
-    if (ctxt->chr.write.len < min_len ||
-        ctxt->chr.write.len > max_len) {
+    if (ctxt->att->write.len < min_len ||
+        ctxt->att->write.len > max_len) {
 
         return BLE_ATT_ERR_INVALID_ATTR_VALUE_LEN;
     }
 
-    memcpy(dst, ctxt->chr.write.data, ctxt->chr.write.len);
+    memcpy(dst, ctxt->att->write.data, ctxt->att->write.len);
     if (len != NULL) {
-        *len = ctxt->chr.write.len;
+        *len = ctxt->att->write.len;
     }
 
     return 0;
@@ -198,41 +198,41 @@ gatt_svr_chr_access_gap(uint16_t conn_handle, uint16_t attr_handle, uint8_t op,
 {
     uint16_t uuid16;
 
-    uuid16 = ble_uuid_128_to_16(ctxt->chr.def->uuid128);
+    uuid16 = ble_uuid_128_to_16(ctxt->chr->uuid128);
     assert(uuid16 != 0);
 
     switch (uuid16) {
     case BLE_GAP_CHR_UUID16_DEVICE_NAME:
         assert(op == BLE_GATT_ACCESS_OP_READ_CHR);
-        ctxt->chr.read.data = bletiny_device_name;
-        ctxt->chr.read.len = strlen(bletiny_device_name);
+        ctxt->att->read.data = bletiny_device_name;
+        ctxt->att->read.len = strlen(bletiny_device_name);
         break;
 
     case BLE_GAP_CHR_UUID16_APPEARANCE:
         assert(op == BLE_GATT_ACCESS_OP_READ_CHR);
-        ctxt->chr.read.data = &bletiny_appearance;
-        ctxt->chr.read.len = sizeof bletiny_appearance;
+        ctxt->att->read.data = &bletiny_appearance;
+        ctxt->att->read.len = sizeof bletiny_appearance;
         break;
 
     case BLE_GAP_CHR_UUID16_PERIPH_PRIV_FLAG:
         assert(op == BLE_GATT_ACCESS_OP_READ_CHR);
-        ctxt->chr.read.data = &bletiny_privacy_flag;
-        ctxt->chr.read.len = sizeof bletiny_privacy_flag;
+        ctxt->att->read.data = &bletiny_privacy_flag;
+        ctxt->att->read.len = sizeof bletiny_privacy_flag;
         break;
 
     case BLE_GAP_CHR_UUID16_RECONNECT_ADDR:
         assert(op == BLE_GATT_ACCESS_OP_WRITE_CHR);
-        if (ctxt->chr.write.len != sizeof bletiny_reconnect_addr) {
+        if (ctxt->att->write.len != sizeof bletiny_reconnect_addr) {
             return BLE_ATT_ERR_INVALID_ATTR_VALUE_LEN;
         }
-        memcpy(bletiny_reconnect_addr, ctxt->chr.write.data,
+        memcpy(bletiny_reconnect_addr, ctxt->att->write.data,
                sizeof bletiny_reconnect_addr);
         break;
 
     case BLE_GAP_CHR_UUID16_PERIPH_PREF_CONN_PARAMS:
         assert(op == BLE_GATT_ACCESS_OP_READ_CHR);
-        ctxt->chr.read.data = &bletiny_pref_conn_params;
-        ctxt->chr.read.len = sizeof bletiny_pref_conn_params;
+        ctxt->att->read.data = &bletiny_pref_conn_params;
+        ctxt->att->read.len = sizeof bletiny_pref_conn_params;
         break;
 
     default:
@@ -249,20 +249,20 @@ gatt_svr_chr_access_gatt(uint16_t conn_handle, uint16_t attr_handle, uint8_t op,
 {
     uint16_t uuid16;
 
-    uuid16 = ble_uuid_128_to_16(ctxt->chr.def->uuid128);
+    uuid16 = ble_uuid_128_to_16(ctxt->chr->uuid128);
     assert(uuid16 != 0);
 
     switch (uuid16) {
     case BLE_GATT_CHR_SERVICE_CHANGED_UUID16:
         if (op == BLE_GATT_ACCESS_OP_WRITE_CHR) {
-            if (ctxt->chr.write.len != sizeof bletiny_gatt_service_changed) {
+            if (ctxt->att->write.len != sizeof bletiny_gatt_service_changed) {
                 return BLE_ATT_ERR_INVALID_ATTR_VALUE_LEN;
             }
-            memcpy(bletiny_gatt_service_changed, ctxt->chr.write.data,
+            memcpy(bletiny_gatt_service_changed, ctxt->att->write.data,
                    sizeof bletiny_gatt_service_changed);
         } else if (op == BLE_GATT_ACCESS_OP_READ_CHR) {
-            ctxt->chr.read.data = &bletiny_gatt_service_changed;
-            ctxt->chr.read.len = sizeof bletiny_gatt_service_changed;
+            ctxt->att->read.data = &bletiny_gatt_service_changed;
+            ctxt->att->read.len = sizeof bletiny_gatt_service_changed;
         }
         break;
 
@@ -291,14 +291,14 @@ gatt_svr_chr_access_alert(uint16_t conn_handle, uint16_t attr_handle,
     uint16_t uuid16;
     int rc;
 
-    uuid16 = ble_uuid_128_to_16(ctxt->chr.def->uuid128);
+    uuid16 = ble_uuid_128_to_16(ctxt->chr->uuid128);
     assert(uuid16 != 0);
 
     switch (uuid16) {
     case GATT_SVR_CHR_SUP_NEW_ALERT_CAT_UUID:
         assert(op == BLE_GATT_ACCESS_OP_READ_CHR);
-        ctxt->chr.read.data = &gatt_svr_new_alert_cat;
-        ctxt->chr.read.len = sizeof gatt_svr_new_alert_cat;
+        ctxt->att->read.data = &gatt_svr_new_alert_cat;
+        ctxt->att->read.len = sizeof gatt_svr_new_alert_cat;
         return 0;
 
     case GATT_SVR_CHR_NEW_ALERT:
@@ -308,15 +308,15 @@ gatt_svr_chr_access_alert(uint16_t conn_handle, uint16_t attr_handle,
                                     &gatt_svr_new_alert_val_len);
             return rc;
         } else if (op == BLE_GATT_ACCESS_OP_READ_CHR) {
-            ctxt->chr.read.data = (void *)&gatt_svr_new_alert_val;
-            ctxt->chr.read.len = sizeof gatt_svr_new_alert_val;
+            ctxt->att->read.data = (void *)&gatt_svr_new_alert_val;
+            ctxt->att->read.len = sizeof gatt_svr_new_alert_val;
             return 0;
         }
 
     case GATT_SVR_CHR_SUP_UNR_ALERT_CAT_UUID:
         assert(op == BLE_GATT_ACCESS_OP_READ_CHR);
-        ctxt->chr.read.data = &gatt_svr_unr_alert_cat;
-        ctxt->chr.read.len = sizeof gatt_svr_unr_alert_cat;
+        ctxt->att->read.data = &gatt_svr_unr_alert_cat;
+        ctxt->att->read.len = sizeof gatt_svr_unr_alert_cat;
         return 0;
 
     case GATT_SVR_CHR_UNR_ALERT_STAT_UUID:
@@ -324,8 +324,8 @@ gatt_svr_chr_access_alert(uint16_t conn_handle, uint16_t attr_handle,
             rc = gatt_svr_chr_write(op, ctxt, 2, 2, &gatt_svr_unr_alert_stat,
                                     NULL);
         } else {
-            ctxt->chr.read.data = &gatt_svr_unr_alert_stat;
-            ctxt->chr.read.len = sizeof gatt_svr_unr_alert_stat;
+            ctxt->att->read.data = &gatt_svr_unr_alert_stat;
+            ctxt->att->read.len = sizeof gatt_svr_unr_alert_stat;
             rc = 0;
         }
         return rc;
@@ -347,14 +347,14 @@ gatt_svr_chr_access_alert(uint16_t conn_handle, uint16_t attr_handle,
 
 static int
 gatt_svr_chr_access_sec_test(uint16_t conn_handle, uint16_t attr_handle,
-                            uint8_t op, struct ble_gatt_access_ctxt *ctxt,
-                            void *arg)
+                             uint8_t op, struct ble_gatt_access_ctxt *ctxt,
+                             void *arg)
 {
     const void *uuid128;
     int rand_num;
     int rc;
 
-    uuid128 = ctxt->chr.def->uuid128;
+    uuid128 = ctxt->chr->uuid128;
 
     /* Determine which characteristic is being accessed by examining its
      * 128-bit UUID.
@@ -367,16 +367,16 @@ gatt_svr_chr_access_sec_test(uint16_t conn_handle, uint16_t attr_handle,
          * to hold the response data.
          */
         rand_num = rand();
-        memcpy(ctxt->chr.read.buf, &rand_num, sizeof rand_num);
-        ctxt->chr.read.len = sizeof rand_num;
+        memcpy(ctxt->att->read.buf, &rand_num, sizeof rand_num);
+        ctxt->att->read.len = sizeof rand_num;
         return 0;
     }
 
     if (memcmp(uuid128, gatt_svr_chr_sec_test_static_uuid, 16) == 0) {
         switch (op) {
         case BLE_GATT_ACCESS_OP_READ_CHR:
-            ctxt->chr.read.data = &gatt_svr_sec_test_static_val;
-            ctxt->chr.read.len = sizeof gatt_svr_sec_test_static_val;
+            ctxt->att->read.data = &gatt_svr_sec_test_static_val;
+            ctxt->att->read.len = sizeof gatt_svr_sec_test_static_val;
             return 0;
 
         case BLE_GATT_ACCESS_OP_WRITE_CHR:


[17/50] [abbrv] incubator-mynewt-core git commit: BLE Host - Don't auto-generate NRPA.

Posted by cc...@apache.org.
BLE Host - Don't auto-generate NRPA.

We were overwriting our random address with a new NRPA whenever the
application performed a discovery or advertise procedure with an
own_addr_type of random.  The stack should not overwrite the address
automatically, the application should set it.


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

Branch: refs/heads/ble_hs_api
Commit: 9e781e9af3139efb74e41a216c60598c02fc7cf7
Parents: d586c0e
Author: Christopher Collins <cc...@apache.org>
Authored: Thu Jun 23 20:00:33 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Jul 11 16:43:31 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/src/ble_gap.c | 8 --------
 1 file changed, 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9e781e9a/net/nimble/host/src/ble_gap.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gap.c b/net/nimble/host/src/ble_gap.c
index 8792083..57502f8 100644
--- a/net/nimble/host/src/ble_gap.c
+++ b/net/nimble/host/src/ble_gap.c
@@ -1612,10 +1612,6 @@ ble_gap_adv_start(uint8_t own_addr_type, uint8_t peer_addr_type,
         }
     }
 
-    if (own_addr_type == BLE_HCI_ADV_OWN_ADDR_RANDOM) {
-        ble_hs_pvcy_set_our_nrpa();
-    }
-
     BLE_HS_LOG(INFO, "GAP procedure initiated: advertise; ");
     ble_gap_log_adv(own_addr_type, peer_addr_type, peer_addr, adv_params);
     BLE_HS_LOG(INFO, "\n");
@@ -1917,10 +1913,6 @@ ble_gap_disc(uint8_t own_addr_type, int32_t duration_ms,
         }
     }
 
-    if (own_addr_type == BLE_HCI_ADV_OWN_ADDR_RANDOM) {
-        ble_hs_pvcy_set_our_nrpa();
-    }
-
     ble_gap_master.disc.limited = params.limited;
     ble_gap_master.disc.cb = cb;
     ble_gap_master.disc.cb_arg = cb_arg;


[47/50] [abbrv] incubator-mynewt-core git commit: BLE Host - ACL data packet fragmentation.

Posted by cc...@apache.org.
BLE Host - ACL data packet fragmentation.


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

Branch: refs/heads/ble_hs_api
Commit: cd66efc0120d6a8a26a4c62ac82869d0de9b0b6e
Parents: 4cb430a
Author: Christopher Collins <cc...@apache.org>
Authored: Fri Jul 8 19:54:22 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Jul 11 16:43:35 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/src/ble_hci_priv.h          |   2 +
 net/nimble/host/src/ble_hci_util.c          |  19 ++++
 net/nimble/host/src/host_hci.c              | 138 +++++++++++++++++------
 net/nimble/host/src/test/ble_hs_test.c      |   2 -
 net/nimble/host/src/test/ble_hs_test_util.c |  58 +++++++++-
 net/nimble/host/src/test/ble_sm_test_util.c |   2 +-
 6 files changed, 179 insertions(+), 42 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/cd66efc0/net/nimble/host/src/ble_hci_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hci_priv.h b/net/nimble/host/src/ble_hci_priv.h
index 1526a20..7bc019f 100644
--- a/net/nimble/host/src/ble_hci_priv.h
+++ b/net/nimble/host/src/ble_hci_priv.h
@@ -45,5 +45,7 @@ int ble_hci_util_read_rssi(uint16_t conn_handle, int8_t *out_rssi);
 int ble_hci_util_set_random_addr(const uint8_t *addr);
 int ble_hci_util_set_data_len(uint16_t conn_handle, uint16_t tx_octets,
                               uint16_t tx_time);
+int ble_hci_util_data_hdr_strip(struct os_mbuf *om,
+                                struct hci_data_hdr *out_hdr);
 
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/cd66efc0/net/nimble/host/src/ble_hci_util.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hci_util.c b/net/nimble/host/src/ble_hci_util.c
index 3850903..caf36e2 100644
--- a/net/nimble/host/src/ble_hci_util.c
+++ b/net/nimble/host/src/ble_hci_util.c
@@ -157,3 +157,22 @@ ble_hci_util_set_data_len(uint16_t conn_handle, uint16_t tx_octets,
 
     return 0;
 }
+
+int
+ble_hci_util_data_hdr_strip(struct os_mbuf *om, struct hci_data_hdr *out_hdr)
+{
+    int rc;
+
+    rc = os_mbuf_copydata(om, 0, BLE_HCI_DATA_HDR_SZ, out_hdr);
+    if (rc != 0) {
+        return BLE_HS_ECONTROLLER;
+    }
+
+    /* Strip HCI ACL data header from the front of the packet. */
+    os_mbuf_adj(om, BLE_HCI_DATA_HDR_SZ);
+
+    out_hdr->hdh_handle_pb_bc = le16toh(&out_hdr->hdh_handle_pb_bc);
+    out_hdr->hdh_len = le16toh(&out_hdr->hdh_len);
+
+    return 0;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/cd66efc0/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 29c71a1..b7b1bd1 100644
--- a/net/nimble/host/src/host_hci.c
+++ b/net/nimble/host/src/host_hci.c
@@ -677,24 +677,6 @@ ble_hci_transport_ctlr_event_send(uint8_t *hci_ev)
     return 0;
 }
 
-static int
-host_hci_data_hdr_strip(struct os_mbuf *om, struct hci_data_hdr *hdr)
-{
-    int rc;
-
-    rc = os_mbuf_copydata(om, 0, BLE_HCI_DATA_HDR_SZ, hdr);
-    if (rc != 0) {
-        return BLE_HS_ECONTROLLER;
-    }
-
-    /* Strip HCI ACL data header from the front of the packet. */
-    os_mbuf_adj(om, BLE_HCI_DATA_HDR_SZ);
-
-    hdr->hdh_handle_pb_bc = le16toh(&hdr->hdh_handle_pb_bc);
-    hdr->hdh_len = le16toh(&hdr->hdh_len);
-
-    return 0;
-}
 
 /**
  * Called when a data packet is received from the controller.  This function
@@ -715,7 +697,7 @@ host_hci_data_rx(struct os_mbuf *om)
     uint16_t handle;
     int rc;
 
-    rc = host_hci_data_hdr_strip(om, &hci_hdr);
+    rc = ble_hci_util_data_hdr_strip(om, &hci_hdr);
     if (rc == 0) {
 #if (BLETEST_THROUGHPUT_TEST == 0)
         BLE_HS_LOG(DEBUG, "host_hci_data_rx(): handle=%u pb=%x len=%u data=",
@@ -782,33 +764,121 @@ host_hci_data_hdr_prepend(struct os_mbuf *om, uint16_t handle, uint8_t pb_flag)
 }
 
 /**
+ * Splits an appropriately-sized fragment from the front of an outgoing ACL
+ * data packet, if necessary.  If the packet size is within the controller's
+ * buffer size requirements, no splitting is performed.  The fragment data is
+ * removed from the data packet mbuf.
+ *
+ * @param om                    The ACL data packet.
+ * @param out_frag              On success, this points to the fragment to
+ *                                  send.  If the entire packet can fit within
+ *                                  a single fragment, this will point to the
+ *                                  ACL data packet itself ('om').
+ *
+ * @return                      BLE_HS_EDONE: success; this is the final
+ *                                  fragment.
+ *                              BLE_HS_EAGAIN: success; more data remains in
+ *                                  the original mbuf.
+ *                              Other BLE host core return code on error.
+ */
+int
+host_hci_split_frag(struct os_mbuf *om, struct os_mbuf **out_frag)
+{
+    struct os_mbuf *frag;
+    int rc;
+
+    if (OS_MBUF_PKTLEN(om) <= host_hci_buffer_sz) {
+        /* Final fragment. */
+        *out_frag = om;
+        return BLE_HS_EDONE;
+    }
+
+    frag = os_msys_get_pkthdr(host_hci_buffer_sz, 0);
+    if (frag == NULL) {
+        rc = BLE_HS_ENOMEM;
+        goto err;
+    }
+
+    /* Move data from the front of the packet into the fragment mbuf. */
+    rc = os_mbuf_appendfrom(frag, om, 0, host_hci_buffer_sz);
+    if (rc != 0) {
+        rc = BLE_HS_ENOMEM;
+        goto err;
+    }
+    os_mbuf_adj(om, host_hci_buffer_sz);
+
+    /* More fragments to follow. */
+    *out_frag = frag;
+    return BLE_HS_EAGAIN;
+
+err:
+    os_mbuf_free_chain(frag);
+    return rc;
+}
+
+/**
  * Transmits an HCI ACL data packet.  This function consumes the supplied mbuf,
  * regardless of the outcome.
+ *
+ * XXX: Ensure the controller has sufficient buffer capacity for the outgoing
+ * fragments.
  */
 int
 host_hci_data_tx(struct ble_hs_conn *connection, struct os_mbuf *om)
 {
+    struct os_mbuf *frag;
+    uint8_t pb;
+    int done;
     int rc;
 
-    /* XXX: Different transport mechanisms have different fragmentation
-     * requirements.  For now, never fragment.
+    /* The first fragment uses the first-non-flush packet boundary value.
+     * After sending the first fragment, pb gets set appropriately for all
+     * subsequent fragments in this packet.
      */
-    om = host_hci_data_hdr_prepend(om, connection->bhc_handle,
-                                   BLE_HCI_PB_FIRST_NON_FLUSH);
-    if (om == NULL) {
-        return BLE_HS_ENOMEM;
-    }
+    pb = BLE_HCI_PB_FIRST_NON_FLUSH;
+
+    /* Send fragments until the entire packet has been sent. */
+    done = 0;
+    while (!done) {
+        rc = host_hci_split_frag(om, &frag);
+        switch (rc) {
+        case BLE_HS_EDONE:
+            /* This is the final fragment. */
+            done = 1;
+            break;
+
+        case BLE_HS_EAGAIN:
+            /* More fragments to follow. */
+            break;
+
+        default:
+            goto err;
+        }
+
+        frag = host_hci_data_hdr_prepend(frag, connection->bhc_handle, pb);
+        if (frag == NULL) {
+            rc = BLE_HS_ENOMEM;
+            goto err;
+        }
+        pb = BLE_HCI_PB_MIDDLE;
 
-    BLE_HS_LOG(DEBUG, "host_hci_data_tx(): ");
-    ble_hs_misc_log_mbuf(om);
-    BLE_HS_LOG(DEBUG, "\n");
+        BLE_HS_LOG(DEBUG, "host_hci_data_tx(): ");
+        ble_hs_misc_log_mbuf(frag);
+        BLE_HS_LOG(DEBUG, "\n");
 
-    rc = ble_hs_tx_data(om);
-    if (rc != 0) {
-        return rc;
-    }
+        rc = ble_hs_tx_data(frag);
+        if (rc != 0) {
+            goto err;
+        }
 
-    connection->bhc_outstanding_pkts++;
+        connection->bhc_outstanding_pkts++;
+    }
 
     return 0;
+
+err:
+    BLE_HS_DBG_ASSERT(rc != 0);
+
+    os_mbuf_free_chain(om);
+    return rc;
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/cd66efc0/net/nimble/host/src/test/ble_hs_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_hs_test.c b/net/nimble/host/src/test/ble_hs_test.c
index feabb72..388d449 100644
--- a/net/nimble/host/src/test/ble_hs_test.c
+++ b/net/nimble/host/src/test/ble_hs_test.c
@@ -29,8 +29,6 @@ uint8_t g_dev_addr[BLE_DEV_ADDR_LEN] = { 0x0a, 0x54, 0xab, 0x49, 0x7f, 0x06 };
 void
 ble_hs_test_pkt_txed(struct os_mbuf *om)
 {
-    /* XXX: For now, just strip the HCI ACL data and L2CAP headers. */
-    os_mbuf_adj(om, BLE_HCI_DATA_HDR_SZ + BLE_L2CAP_HDR_SZ);
     ble_hs_test_util_prev_tx_enqueue(om);
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/cd66efc0/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 9723b90..895a608 100644
--- a/net/nimble/host/src/test/ble_hs_test_util.c
+++ b/net/nimble/host/src/test/ble_hs_test_util.c
@@ -82,20 +82,65 @@ ble_hs_test_util_prev_tx_enqueue(struct os_mbuf *om)
     }
 }
 
+static struct os_mbuf *
+ble_hs_test_util_prev_tx_dequeue_once(struct hci_data_hdr *out_hci_hdr)
+{
+    struct os_mbuf_pkthdr *omp;
+    struct os_mbuf *om;
+    int rc;
+
+    omp = STAILQ_FIRST(&ble_hs_test_util_prev_tx_queue);
+    if (omp == NULL) {
+        return NULL;
+    }
+    STAILQ_REMOVE_HEAD(&ble_hs_test_util_prev_tx_queue, omp_next);
+
+    om = OS_MBUF_PKTHDR_TO_MBUF(omp);
+
+    rc = ble_hci_util_data_hdr_strip(om, out_hci_hdr);
+    TEST_ASSERT_FATAL(rc == 0);
+    TEST_ASSERT_FATAL(out_hci_hdr->hdh_len == OS_MBUF_PKTLEN(om));
+
+    return om;
+}
+
 struct os_mbuf *
 ble_hs_test_util_prev_tx_dequeue(void)
 {
-    struct os_mbuf_pkthdr *omp;
+    struct ble_l2cap_hdr l2cap_hdr;
+    struct hci_data_hdr hci_hdr;
+    struct os_mbuf *om;
+    uint8_t pb;
+    int rc;
 
     os_mbuf_free_chain(ble_hs_test_util_prev_tx_cur);
 
-    omp = STAILQ_FIRST(&ble_hs_test_util_prev_tx_queue);
-    if (omp != NULL) {
-        STAILQ_REMOVE_HEAD(&ble_hs_test_util_prev_tx_queue, omp_next);
-        ble_hs_test_util_prev_tx_cur = OS_MBUF_PKTHDR_TO_MBUF(omp);
+    om = ble_hs_test_util_prev_tx_dequeue_once(&hci_hdr);
+    if (om != NULL) {
+        pb = BLE_HCI_DATA_PB(hci_hdr.hdh_handle_pb_bc);
+        TEST_ASSERT_FATAL(pb == BLE_HCI_PB_FIRST_NON_FLUSH);
+
+        rc = ble_l2cap_parse_hdr(om, 0, &l2cap_hdr);
+        TEST_ASSERT_FATAL(rc == 0);
+
+        os_mbuf_adj(om, BLE_L2CAP_HDR_SZ);
+
+        ble_hs_test_util_prev_tx_cur = om;
+        while (OS_MBUF_PKTLEN(ble_hs_test_util_prev_tx_cur) <
+               l2cap_hdr.blh_len) {
+
+            om = ble_hs_test_util_prev_tx_dequeue_once(&hci_hdr);
+            TEST_ASSERT_FATAL(om != NULL);
+
+            pb = BLE_HCI_DATA_PB(hci_hdr.hdh_handle_pb_bc);
+            TEST_ASSERT_FATAL(pb == BLE_HCI_PB_MIDDLE);
+
+            os_mbuf_concat(ble_hs_test_util_prev_tx_cur, om);
+        }
     } else {
         ble_hs_test_util_prev_tx_cur = NULL;
     }
+
     return ble_hs_test_util_prev_tx_cur;
 }
 
@@ -963,4 +1008,7 @@ ble_hs_test_util_init(void)
     ble_hs_test_util_prev_hci_tx_clear();
 
     ble_hs_id_set_pub(g_dev_addr);
+
+    /* Use a very low buffer size (16) to test fragmentation. */
+    host_hci_set_buf_size(16, 64);
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/cd66efc0/net/nimble/host/src/test/ble_sm_test_util.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_sm_test_util.c b/net/nimble/host/src/test/ble_sm_test_util.c
index 57080dd..fae524a 100644
--- a/net/nimble/host/src/test/ble_sm_test_util.c
+++ b/net/nimble/host/src/test/ble_sm_test_util.c
@@ -638,7 +638,7 @@ ble_sm_test_util_verify_tx_hdr(uint8_t sm_op, uint16_t payload_len)
 {
     struct os_mbuf *om;
 
-    om = ble_hs_test_util_prev_tx_dequeue();
+    om = ble_hs_test_util_prev_tx_dequeue_pullup();
     TEST_ASSERT_FATAL(om != NULL);
 
     TEST_ASSERT(OS_MBUF_PKTLEN(om) == BLE_SM_HDR_SZ + payload_len);


[31/50] [abbrv] incubator-mynewt-core git commit: BLE Host - Allow HCI reason in ble_gap_terminate()

Posted by cc...@apache.org.
BLE Host - Allow HCI reason in ble_gap_terminate()


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

Branch: refs/heads/ble_hs_api
Commit: f962497bd82556987e33731f228a7437427db07f
Parents: 3757089
Author: Christopher Collins <cc...@apache.org>
Authored: Thu Jun 30 11:32:10 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Jul 11 16:43:33 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/include/host/ble_gap.h      | 2 +-
 net/nimble/host/src/ble_gap.c               | 7 ++++---
 net/nimble/host/src/ble_gattc.c             | 2 +-
 net/nimble/host/src/ble_l2cap_sig.c         | 2 +-
 net/nimble/host/src/test/ble_hs_test_util.c | 2 +-
 5 files changed, 8 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f962497b/net/nimble/host/include/host/ble_gap.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/ble_gap.h b/net/nimble/host/include/host/ble_gap.h
index 9b114cf..c0dc278 100644
--- a/net/nimble/host/include/host/ble_gap.h
+++ b/net/nimble/host/include/host/ble_gap.h
@@ -312,7 +312,7 @@ int ble_gap_connect(uint8_t own_addr_type,
                     ble_gap_event_fn *cb, void *cb_arg);
 int ble_gap_conn_cancel(void);
 int ble_gap_conn_active(void);
-int ble_gap_terminate(uint16_t handle);
+int ble_gap_terminate(uint16_t conn_handle, uint8_t hci_reason);
 int ble_gap_wl_set(const struct ble_gap_white_entry *white_list,
                    uint8_t white_list_count);
 int ble_gap_update_params(uint16_t conn_handle,

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f962497b/net/nimble/host/src/ble_gap.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gap.c b/net/nimble/host/src/ble_gap.c
index d784ff5..c3df545 100644
--- a/net/nimble/host/src/ble_gap.c
+++ b/net/nimble/host/src/ble_gap.c
@@ -2148,7 +2148,7 @@ ble_gap_conn_active(void)
  *****************************************************************************/
 
 int
-ble_gap_terminate(uint16_t conn_handle)
+ble_gap_terminate(uint16_t conn_handle, uint8_t hci_reason)
 {
     uint8_t buf[BLE_HCI_CMD_HDR_LEN + BLE_HCI_DISCONNECT_CMD_LEN];
     int rc;
@@ -2163,9 +2163,10 @@ ble_gap_terminate(uint16_t conn_handle)
     }
 
     BLE_HS_LOG(INFO, "GAP procedure initiated: terminate connection; "
-                     "conn_handle=%d\n", conn_handle);
+                     "conn_handle=%d hci_reason=%d\n",
+               conn_handle, hci_reason);
 
-    host_hci_cmd_build_disconnect(conn_handle, BLE_ERR_REM_USER_CONN_TERM,
+    host_hci_cmd_build_disconnect(conn_handle, hci_reason,
                                   buf, sizeof buf);
     rc = ble_hci_cmd_tx_empty_ack(buf);
     if (rc != 0) {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f962497b/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 7ff37aa..929c878 100644
--- a/net/nimble/host/src/ble_gattc.c
+++ b/net/nimble/host/src/ble_gattc.c
@@ -869,7 +869,7 @@ ble_gattc_heartbeat(void)
     /* Terminate the connection associated with each timed-out procedure. */
     while ((proc = STAILQ_FIRST(&exp_list)) != NULL) {
         STATS_INC(ble_gattc_stats, proc_timeout);
-        ble_gap_terminate(proc->conn_handle);
+        ble_gap_terminate(proc->conn_handle, BLE_ERR_REM_USER_CONN_TERM);
 
         STAILQ_REMOVE_HEAD(&exp_list, next);
         ble_gattc_proc_free(proc);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f962497b/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 9630a15..e75f06f 100644
--- a/net/nimble/host/src/ble_l2cap_sig.c
+++ b/net/nimble/host/src/ble_l2cap_sig.c
@@ -596,7 +596,7 @@ ble_l2cap_sig_heartbeat(void)
     /* Terminate the connection associated with each timed-out procedure. */
     STAILQ_FOREACH(proc, &temp_list, next) {
         STATS_INC(ble_l2cap_stats, proc_timeout);
-        ble_gap_terminate(proc->conn_handle);
+        ble_gap_terminate(proc->conn_handle, BLE_ERR_REM_USER_CONN_TERM);
     }
 
     return BLE_HS_FOREVER;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f962497b/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 1a08801..e2040ae 100644
--- a/net/nimble/host/src/test/ble_hs_test_util.c
+++ b/net/nimble/host/src/test/ble_hs_test_util.c
@@ -407,7 +407,7 @@ ble_hs_test_util_conn_terminate(uint16_t conn_handle, uint8_t hci_status)
                              BLE_HCI_OCF_DISCONNECT_CMD),
         hci_status);
 
-    rc = ble_gap_terminate(conn_handle);
+    rc = ble_gap_terminate(conn_handle, BLE_ERR_REM_USER_CONN_TERM);
     return rc;
 }
 


[32/50] [abbrv] incubator-mynewt-core git commit: BLE Host - ble_gap_conn_cancel() - rc when !active

Posted by cc...@apache.org.
BLE Host - ble_gap_conn_cancel() - rc when !active

Previously this returned BLE_HS_ENOENT
Now it returns BLE_HS_EALREADY.


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

Branch: refs/heads/ble_hs_api
Commit: 16e987169b63ae3eb3fa50de609f0442bd774146
Parents: 270fcf6
Author: Christopher Collins <cc...@apache.org>
Authored: Thu Jun 30 17:23:14 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Jul 11 16:43:33 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/src/ble_gap.c           | 2 +-
 net/nimble/host/src/test/ble_gap_test.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/16e98716/net/nimble/host/src/ble_gap.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gap.c b/net/nimble/host/src/ble_gap.c
index c3df545..78e8ac1 100644
--- a/net/nimble/host/src/ble_gap.c
+++ b/net/nimble/host/src/ble_gap.c
@@ -2199,7 +2199,7 @@ ble_gap_conn_cancel(void)
     ble_hs_lock();
 
     if (!ble_gap_master_in_progress()) {
-        rc = BLE_HS_ENOENT;
+        rc = BLE_HS_EALREADY;
         goto done;
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/16e98716/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 dd8d78a..bb08bd0 100644
--- a/net/nimble/host/src/test/ble_gap_test.c
+++ b/net/nimble/host/src/test/ble_gap_test.c
@@ -914,7 +914,7 @@ TEST_CASE(ble_gap_test_case_conn_cancel_bad_args)
     /* Initiate cancel procedure with no connection in progress. */
     TEST_ASSERT(!ble_gap_master_in_progress());
     rc = ble_hs_test_util_conn_cancel(0);
-    TEST_ASSERT(rc == BLE_HS_ENOENT);
+    TEST_ASSERT(rc == BLE_HS_EALREADY);
 }
 
 TEST_CASE(ble_gap_test_case_conn_cancel_good)


[34/50] [abbrv] incubator-mynewt-core git commit: BLE Host - Clean up private headers.

Posted by cc...@apache.org.
BLE Host - Clean up private headers.


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

Branch: refs/heads/ble_hs_api
Commit: 40b635e6d3b10449e98fe67aea7edb019c23aeee
Parents: 16e9871
Author: Christopher Collins <cc...@apache.org>
Authored: Fri Jul 1 12:13:23 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Jul 11 16:43:33 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/include/host/ble_hs_adv.h |  6 ----
 net/nimble/host/include/host/ble_uuid.h   |  2 --
 net/nimble/host/src/ble_hci_priv.h        | 49 ++++++++++++++++++++++++++
 net/nimble/host/src/ble_hci_util.c        |  2 +-
 net/nimble/host/src/ble_hci_util_priv.h   | 30 ----------------
 net/nimble/host/src/ble_hs_adv_priv.h     | 30 ++++++++++++++++
 net/nimble/host/src/ble_hs_priv.h         | 32 +++--------------
 net/nimble/host/src/ble_hs_pvcy.c         |  4 +--
 net/nimble/host/src/ble_hs_pvcy_priv.h    | 34 ++++++++++++++++++
 net/nimble/host/src/ble_uuid_priv.h       | 28 +++++++++++++++
 10 files changed, 148 insertions(+), 69 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/40b635e6/net/nimble/host/include/host/ble_hs_adv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/ble_hs_adv.h b/net/nimble/host/include/host/ble_hs_adv.h
index 3f7f911..1ce456d 100644
--- a/net/nimble/host/include/host/ble_hs_adv.h
+++ b/net/nimble/host/include/host/ble_hs_adv.h
@@ -171,10 +171,4 @@ struct ble_hs_adv_fields {
 
 #define BLE_HS_ADV_SVC_DATA_UUID128_MIN_LEN     16
 
-int ble_hs_adv_set_flat(uint8_t type, int data_len, const void *data,
-                        uint8_t *dst, uint8_t *dst_len, uint8_t max_len);
-int ble_hs_adv_set_fields(const struct ble_hs_adv_fields *adv_fields,
-                          uint8_t *dst, uint8_t *dst_len, uint8_t max_len);
-int ble_hs_adv_parse_fields(struct ble_hs_adv_fields *adv_fields, uint8_t *src,
-                            uint8_t src_len);
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/40b635e6/net/nimble/host/include/host/ble_uuid.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/ble_uuid.h b/net/nimble/host/include/host/ble_uuid.h
index 1bcc0b4..89d9df0 100644
--- a/net/nimble/host/include/host/ble_uuid.h
+++ b/net/nimble/host/include/host/ble_uuid.h
@@ -25,8 +25,6 @@ struct os_mbuf;
 
 uint16_t ble_uuid_128_to_16(const void *uuid128);
 int ble_uuid_16_to_128(uint16_t uuid16, void *dst);
-int ble_uuid_append(struct os_mbuf *om, const void *uuid128);
-int ble_uuid_extract(struct os_mbuf *om, int off, void *uuid128);
 
 #define BLE_UUID16_ARR(uuid16) {                                            \
     0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80,                         \

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/40b635e6/net/nimble/host/src/ble_hci_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hci_priv.h b/net/nimble/host/src/ble_hci_priv.h
new file mode 100644
index 0000000..dbe3d15
--- /dev/null
+++ b/net/nimble/host/src/ble_hci_priv.h
@@ -0,0 +1,49 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef H_BLE_HCI_PRIV_
+#define H_BLE_HCI_PRIV_
+
+struct ble_hci_ack {
+    int bha_status;         /* A BLE_HS_E<...> error; NOT a naked HCI code. */
+    uint8_t *bha_params;
+    int bha_params_len;
+    uint16_t bha_opcode;
+    uint8_t bha_hci_handle;
+};
+
+int ble_hci_cmd_tx(void *cmd, void *evt_buf, uint8_t evt_buf_len,
+                   uint8_t *out_evt_buf_len);
+int ble_hci_cmd_tx_empty_ack(void *cmd);
+void ble_hci_cmd_rx_ack(uint8_t *ack_ev);
+void ble_hci_cmd_init(void);
+
+#if PHONY_HCI_ACKS
+typedef int ble_hci_cmd_phony_ack_fn(uint8_t *ack, int ack_buf_len);
+void ble_hci_set_phony_ack_cb(ble_hci_cmd_phony_ack_fn *cb);
+#endif
+
+int ble_hci_util_read_adv_tx_pwr(int8_t *out_pwr);
+int ble_hci_util_rand(void *dst, int len);
+int ble_hci_util_read_rssi(uint16_t conn_handle, int8_t *out_rssi);
+int ble_hci_util_set_random_addr(uint8_t *addr);
+int ble_hci_util_set_data_len(uint16_t conn_handle, uint16_t tx_octets,
+                              uint16_t tx_time);
+
+#endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/40b635e6/net/nimble/host/src/ble_hci_util.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hci_util.c b/net/nimble/host/src/ble_hci_util.c
index f9ed2c5..c44c012 100644
--- a/net/nimble/host/src/ble_hci_util.c
+++ b/net/nimble/host/src/ble_hci_util.c
@@ -107,7 +107,7 @@ ble_hci_util_read_rssi(uint16_t conn_handle, int8_t *out_rssi)
 }
 
 int
-ble_hs_util_set_random_addr(uint8_t *addr)
+ble_hci_util_set_random_addr(uint8_t *addr)
 {
     uint8_t buf[BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_RAND_ADDR_LEN];
     int rc;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/40b635e6/net/nimble/host/src/ble_hci_util_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hci_util_priv.h b/net/nimble/host/src/ble_hci_util_priv.h
deleted file mode 100644
index f445514..0000000
--- a/net/nimble/host/src/ble_hci_util_priv.h
+++ /dev/null
@@ -1,30 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-#ifndef H_BLE_HCI_UTIL_
-#define H_BLE_HCI_UTIL_
-
-int ble_hci_util_read_adv_tx_pwr(int8_t *out_pwr);
-int ble_hci_util_rand(void *dst, int len);
-int ble_hci_util_read_rssi(uint16_t conn_handle, int8_t *out_rssi);
-int ble_hs_util_set_random_addr(uint8_t *addr);
-int ble_hci_util_set_data_len(uint16_t conn_handle, uint16_t tx_octets,
-                              uint16_t tx_time);
-
-#endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/40b635e6/net/nimble/host/src/ble_hs_adv_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_adv_priv.h b/net/nimble/host/src/ble_hs_adv_priv.h
new file mode 100644
index 0000000..3ad4f49
--- /dev/null
+++ b/net/nimble/host/src/ble_hs_adv_priv.h
@@ -0,0 +1,30 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef H_BLE_HS_ADV_PRIV_
+#define H_BLE_HS_ADV_PRIV_
+
+int ble_hs_adv_set_flat(uint8_t type, int data_len, const void *data,
+                        uint8_t *dst, uint8_t *dst_len, uint8_t max_len);
+int ble_hs_adv_set_fields(const struct ble_hs_adv_fields *adv_fields,
+                          uint8_t *dst, uint8_t *dst_len, uint8_t max_len);
+int ble_hs_adv_parse_fields(struct ble_hs_adv_fields *adv_fields, uint8_t *src,
+                            uint8_t src_len);
+
+#endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/40b635e6/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 d3a9524..8cd4a83 100644
--- a/net/nimble/host/src/ble_hs_priv.h
+++ b/net/nimble/host/src/ble_hs_priv.h
@@ -26,7 +26,7 @@
 #include "ble_att_priv.h"
 #include "ble_gap_priv.h"
 #include "ble_gatt_priv.h"
-#include "ble_hci_util_priv.h"
+#include "ble_hci_priv.h"
 #include "ble_hs_atomic_priv.h"
 #include "ble_hs_conn_priv.h"
 #include "ble_hs_atomic_priv.h"
@@ -35,6 +35,9 @@
 #include "ble_l2cap_priv.h"
 #include "ble_l2cap_sig_priv.h"
 #include "ble_sm_priv.h"
+#include "ble_hs_adv_priv.h"
+#include "ble_hs_pvcy_priv.h"
+#include "ble_uuid_priv.h"
 #include "host/ble_hs.h"
 #include "log/log.h"
 #include "nimble/nimble_opt.h"
@@ -56,14 +59,6 @@ STATS_SECT_START(ble_hs_stats)
 STATS_SECT_END
 extern STATS_SECT_DECL(ble_hs_stats) ble_hs_stats;
 
-struct ble_hci_ack {
-    int bha_status;         /* A BLE_HS_E<...> error; NOT a naked HCI code. */
-    uint8_t *bha_params;
-    int bha_params_len;
-    uint16_t bha_opcode;
-    uint8_t bha_hci_handle;
-};
-
 extern struct ble_hs_cfg ble_hs_cfg;
 extern struct os_mbuf_pool ble_hs_mbuf_pool;
 extern struct log ble_hs_log;
@@ -98,25 +93,6 @@ struct os_mbuf *ble_hs_misc_pkthdr(void);
 
 int ble_hs_misc_pullup_base(struct os_mbuf **om, int base_len);
 
-int ble_hci_cmd_tx(void *cmd, void *evt_buf, uint8_t evt_buf_len,
-                   uint8_t *out_evt_buf_len);
-int ble_hci_cmd_tx_empty_ack(void *cmd);
-void ble_hci_cmd_rx_ack(uint8_t *ack_ev);
-void ble_hci_cmd_init(void);
-int ble_hs_pvcy_set_our_nrpa(void);
-void ble_hs_pvcy_our_nrpa(uint8_t *addr);
-void ble_hs_pvcy_set_our_id_addr(const uint8_t *addr);
-void ble_hs_pvcy_set_our_irk(const uint8_t *irk);
-uint8_t *ble_hs_pvcy_our_id_addr(uint8_t *type);
-uint8_t *ble_hs_pvcy_our_irk(void);
-int ble_hs_pvcy_remove_entry(uint8_t addr_type, uint8_t *addr);
-int ble_hs_pvcy_add_entry(uint8_t *addr, uint8_t addrtype, uint8_t *irk);
-#if PHONY_HCI_ACKS
-typedef int ble_hci_cmd_phony_ack_fn(uint8_t *ack, int ack_buf_len);
-
-void ble_hci_set_phony_ack_cb(ble_hci_cmd_phony_ack_fn *cb);
-#endif
-
 #define BLE_HS_LOG(lvl, ...) \
     LOG_ ## lvl(&ble_hs_log, LOG_MODULE_NIMBLE_HOST, __VA_ARGS__)
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/40b635e6/net/nimble/host/src/ble_hs_pvcy.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_pvcy.c b/net/nimble/host/src/ble_hs_pvcy.c
index 01b74d1..3a20ce4 100644
--- a/net/nimble/host/src/ble_hs_pvcy.c
+++ b/net/nimble/host/src/ble_hs_pvcy.c
@@ -158,7 +158,7 @@ ble_hs_pvcy_set_our_nrpa(void)
     addr[5] &= ~(0xc0);
     memcpy(ble_hs_pvcy_nrpa, addr, 6);
 
-    return ble_hs_util_set_random_addr(addr);
+    return ble_hci_util_set_random_addr(addr);
 }
 
 uint8_t *
@@ -193,7 +193,7 @@ ble_hs_pvcy_set_our_id_addr(const uint8_t *addr)
     } else {
         /* Generate a new static random address. */
         ble_hs_pvcy_gen_static_random_addr(random_addr);
-        rc = ble_hs_util_set_random_addr(random_addr);
+        rc = ble_hci_util_set_random_addr(random_addr);
         assert(rc == 0);
 
         ble_hs_pvcy_id_addr_type = BLE_HCI_ADV_OWN_ADDR_RANDOM;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/40b635e6/net/nimble/host/src/ble_hs_pvcy_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_pvcy_priv.h b/net/nimble/host/src/ble_hs_pvcy_priv.h
new file mode 100644
index 0000000..282f2ad
--- /dev/null
+++ b/net/nimble/host/src/ble_hs_pvcy_priv.h
@@ -0,0 +1,34 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef H_BLE_HS_PVCY_PRIV_
+#define H_BLE_HS_PVCY_PRIV_
+
+#include <inttypes.h>
+
+int ble_hs_pvcy_set_our_nrpa(void);
+void ble_hs_pvcy_our_nrpa(uint8_t *addr);
+void ble_hs_pvcy_set_our_id_addr(const uint8_t *addr);
+void ble_hs_pvcy_set_our_irk(const uint8_t *irk);
+uint8_t *ble_hs_pvcy_our_id_addr(uint8_t *type);
+uint8_t *ble_hs_pvcy_our_irk(void);
+int ble_hs_pvcy_remove_entry(uint8_t addr_type, uint8_t *addr);
+int ble_hs_pvcy_add_entry(uint8_t *addr, uint8_t addrtype, uint8_t *irk);
+
+#endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/40b635e6/net/nimble/host/src/ble_uuid_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_uuid_priv.h b/net/nimble/host/src/ble_uuid_priv.h
new file mode 100644
index 0000000..a1f1bd4
--- /dev/null
+++ b/net/nimble/host/src/ble_uuid_priv.h
@@ -0,0 +1,28 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef H_BLE_UUID_PRIV_
+#define H_BLE_UUID_PRIV_
+
+struct os_mbuf;
+
+int ble_uuid_append(struct os_mbuf *om, const void *uuid128);
+int ble_uuid_extract(struct os_mbuf *om, int off, void *uuid128);
+
+#endif


[30/50] [abbrv] incubator-mynewt-core git commit: BLE Host - ble_gap_[...]_active() functions.

Posted by cc...@apache.org.
BLE Host - ble_gap_[...]_active() functions.

* ble_gap_adv_active()
* ble_gap_conn_active()
* ble_gap_disc_active()

These function indicate whether the specified type of GAP procedure is
currently in progress.


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

Branch: refs/heads/ble_hs_api
Commit: 375708941487dd28c416a8279e99e03fbea20c0c
Parents: bad2b6a
Author: Christopher Collins <cc...@apache.org>
Authored: Thu Jun 30 11:21:55 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Jul 11 16:43:33 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/include/host/ble_gap.h      |  5 +-
 net/nimble/host/src/ble_gap.c               | 69 +++++++++++++++++-------
 net/nimble/host/src/ble_gap_priv.h          |  1 -
 net/nimble/host/src/test/ble_gap_test.c     | 42 +++++++++------
 net/nimble/host/src/test/ble_hs_conn_test.c | 12 ++---
 5 files changed, 85 insertions(+), 44 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/37570894/net/nimble/host/include/host/ble_gap.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/ble_gap.h b/net/nimble/host/include/host/ble_gap.h
index 147eaf4..9b114cf 100644
--- a/net/nimble/host/include/host/ble_gap.h
+++ b/net/nimble/host/include/host/ble_gap.h
@@ -298,18 +298,21 @@ int ble_gap_adv_start(uint8_t own_addr_type, uint8_t peer_addr_type,
                       const struct ble_gap_adv_params *adv_params,
                       ble_gap_event_fn *cb, void *cb_arg);
 int ble_gap_adv_stop(void);
+int ble_gap_adv_active(void);
 int ble_gap_adv_set_fields(const struct ble_hs_adv_fields *adv_fields);
 int ble_gap_adv_rsp_set_fields(const struct ble_hs_adv_fields *rsp_fields);
 int ble_gap_disc(uint8_t own_addr_type, int32_t duration_ms,
                  const struct ble_gap_disc_params *disc_params,
                  ble_gap_disc_fn *cb, void *cb_arg);
 int ble_gap_disc_cancel(void);
+int ble_gap_disc_active(void);
 int ble_gap_connect(uint8_t own_addr_type,
                     uint8_t peer_addr_type, const uint8_t *peer_addr,
                     const struct ble_gap_conn_params *params,
                     ble_gap_event_fn *cb, void *cb_arg);
-int ble_gap_terminate(uint16_t handle);
 int ble_gap_conn_cancel(void);
+int ble_gap_conn_active(void);
+int ble_gap_terminate(uint16_t handle);
 int ble_gap_wl_set(const struct ble_gap_white_entry *white_list,
                    uint8_t white_list_count);
 int ble_gap_update_params(uint16_t conn_handle,

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/37570894/net/nimble/host/src/ble_gap.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gap.c b/net/nimble/host/src/ble_gap.c
index eb7df78..d784ff5 100644
--- a/net/nimble/host/src/ble_gap.c
+++ b/net/nimble/host/src/ble_gap.c
@@ -759,21 +759,6 @@ ble_gap_master_in_progress(void)
 }
 
 /**
- * Tells you if the BLE host is in the process of creating a slave connection.
- */
-int
-ble_gap_slave_in_progress(void)
-{
-    return ble_gap_slave.op != BLE_GAP_OP_NULL;
-}
-
-static int
-ble_gap_currently_advertising(void)
-{
-    return ble_gap_slave.op == BLE_GAP_OP_S_ADV;
-}
-
-/**
  * Attempts to complete the master connection process in response to a
  * "connection complete" event from the controller.  If the master connection
  * FSM is in a state that can accept this event, and the peer device address is
@@ -838,7 +823,7 @@ ble_gap_accept_slave_conn(uint8_t addr_type, uint8_t *addr)
 {
     int rc;
 
-    if (!ble_gap_currently_advertising()) {
+    if (!ble_gap_adv_active()) {
         rc = BLE_HS_ENOENT;
     } else {
         switch (ble_gap_slave.conn_mode) {
@@ -941,7 +926,7 @@ ble_gap_rx_conn_complete(struct hci_le_conn_complete *evt)
         /* Determine the role from the status code. */
         switch (evt->status) {
         case BLE_ERR_DIR_ADV_TMO:
-            if (ble_gap_slave_in_progress()) {
+            if (ble_gap_adv_active()) {
                 ble_gap_adv_finished();
             }
             break;
@@ -1282,7 +1267,7 @@ ble_gap_adv_stop(void)
     ble_hs_lock();
 
     /* Do nothing if advertising is already disabled. */
-    if (!ble_gap_currently_advertising()) {
+    if (!ble_gap_adv_active()) {
         rc = BLE_HS_EALREADY;
         goto done;
     }
@@ -1757,6 +1742,19 @@ done:
     return rc;
 }
 
+/**
+ * Indicates whether an advertisement procedure is currently in progress.
+ *
+ * @return                      0: No advertisement procedure in progress;
+ *                              1: Advertisement procedure in progress.
+ */
+int
+ble_gap_adv_active(void)
+{
+    /* Assume read is atomic; mutex not necessary. */
+    return ble_gap_slave.op == BLE_GAP_OP_S_ADV;
+}
+
 /*****************************************************************************
  * $discovery procedures                                                     *
  *****************************************************************************/
@@ -1984,6 +1982,19 @@ done:
     return rc;
 }
 
+/**
+ * Indicates whether a discovery procedure is currently in progress.
+ *
+ * @return                      0: No discovery procedure in progress;
+ *                              1: Discovery procedure in progress.
+ */
+int
+ble_gap_disc_active(void)
+{
+    /* Assume read is atomic; mutex not necessary. */
+    return ble_gap_master.op == BLE_GAP_OP_M_DISC;
+}
+
 /*****************************************************************************
  * $connection establishment procedures                                      *
  *****************************************************************************/
@@ -2119,6 +2130,19 @@ done:
     return rc;
 }
 
+/**
+ * Indicates whether a connect procedure is currently in progress.
+ *
+ * @return                      0: No connect procedure in progress;
+ *                              1: Connect procedure in progress.
+ */
+int
+ble_gap_conn_active(void)
+{
+    /* Assume read is atomic; mutex not necessary. */
+    return ble_gap_master.op == BLE_GAP_OP_M_CONN;
+}
+
 /*****************************************************************************
  * $terminate connection procedure                                           *
  *****************************************************************************/
@@ -2561,7 +2585,10 @@ void
 ble_gap_notify_event(uint16_t conn_handle, uint16_t attr_handle,
                      void *attr_data, uint16_t attr_len, int is_indication)
 {
-    /* XXX: Early return if notifications and indications disabled. */
+#if !NIMBLE_OPT(GATT_NOTIFY) && !NIMBLE_OPT(GATT_INDICATE)
+    return;
+#endif
+
     struct ble_gap_event_ctxt ctxt;
     struct ble_gap_snapshot snap;
     int rc;
@@ -2581,6 +2608,10 @@ ble_gap_notify_event(uint16_t conn_handle, uint16_t attr_handle,
     ble_gap_call_event_cb(BLE_GAP_EVENT_NOTIFY, &ctxt, snap.cb, snap.cb_arg);
 }
 
+/*****************************************************************************
+ * $privacy                                                                  *
+ *****************************************************************************/
+
 void
 ble_gap_init_identity_addr(const uint8_t *addr)
 {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/37570894/net/nimble/host/src/ble_gap_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gap_priv.h b/net/nimble/host/src/ble_gap_priv.h
index bb4ef3a..43030fd 100644
--- a/net/nimble/host/src/ble_gap_priv.h
+++ b/net/nimble/host/src/ble_gap_priv.h
@@ -86,7 +86,6 @@ void ble_gap_notify_event(uint16_t conn_handle, uint16_t attr_handle,
                           void *attr_data, uint16_t attr_len,
                           int is_indication);
 int ble_gap_master_in_progress(void);
-int ble_gap_slave_in_progress(void);
 
 int32_t ble_gap_heartbeat(void);
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/37570894/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 dbda665..dd8d78a 100644
--- a/net/nimble/host/src/test/ble_gap_test.c
+++ b/net/nimble/host/src/test/ble_gap_test.c
@@ -520,6 +520,8 @@ ble_gap_test_util_disc(uint8_t own_addr_type,
 
     ble_gap_test_util_init();
 
+    TEST_ASSERT(!ble_gap_disc_active());
+
     /* Begin the discovery procedure. */
     rc = ble_hs_test_util_disc(own_addr_type, BLE_HS_FOREVER, disc_params,
                                ble_gap_test_util_disc_cb, NULL, cmd_fail_idx,
@@ -550,6 +552,10 @@ ble_gap_test_util_disc(uint8_t own_addr_type,
             1, disc_params->filter_duplicates);
     }
 
+    if (rc == 0) {
+        TEST_ASSERT(ble_gap_disc_active());
+    }
+
     return rc;
 }
 
@@ -785,6 +791,7 @@ TEST_CASE(ble_gap_test_case_conn_dir_good)
     ble_gap_test_util_init();
 
     TEST_ASSERT(!ble_gap_master_in_progress());
+    TEST_ASSERT(!ble_gap_conn_active());
 
     rc = ble_hs_test_util_connect(BLE_ADDR_TYPE_PUBLIC,
                                   BLE_ADDR_TYPE_PUBLIC, peer_addr, NULL,
@@ -792,6 +799,7 @@ TEST_CASE(ble_gap_test_case_conn_dir_good)
     TEST_ASSERT(rc == 0);
 
     TEST_ASSERT(ble_gap_master_in_progress());
+    TEST_ASSERT(ble_gap_conn_active());
 
     /* Verify tx of create connection command. */
     ble_gap_test_util_verify_tx_create_conn(BLE_HCI_CONN_FILT_NO_WL);
@@ -1216,7 +1224,7 @@ ble_gap_test_util_adv(uint8_t own_addr_type, uint8_t peer_addr_type,
     adv_params.conn_mode = conn_mode;
     adv_params.disc_mode = disc_mode;
 
-    TEST_ASSERT(!ble_gap_slave_in_progress());
+    TEST_ASSERT(!ble_gap_adv_active());
 
     cmd_idx = 0;
 
@@ -1275,7 +1283,7 @@ ble_gap_test_util_adv(uint8_t own_addr_type, uint8_t peer_addr_type,
     if (connect_status != -1 &&
         (fail_status == 0 || cmd_fail_idx >= cmd_idx)) {
 
-        TEST_ASSERT(ble_gap_slave_in_progress());
+        TEST_ASSERT(ble_gap_adv_active());
 
         /* Receive a connection complete event. */
         if (conn_mode != BLE_GAP_CONN_MODE_NON) {
@@ -1291,9 +1299,9 @@ ble_gap_test_util_adv(uint8_t own_addr_type, uint8_t peer_addr_type,
             if (connect_status == 0 ||
                 connect_status == BLE_ERR_DIR_ADV_TMO) {
 
-                TEST_ASSERT(!ble_gap_slave_in_progress());
+                TEST_ASSERT(!ble_gap_adv_active());
             } else {
-                TEST_ASSERT(ble_gap_slave_in_progress());
+                TEST_ASSERT(ble_gap_adv_active());
             }
         }
     }
@@ -1305,7 +1313,7 @@ TEST_CASE(ble_gap_test_case_adv_bad_args)
     uint8_t peer_addr[6] = { 1, 2, 3, 4, 5, 6 };
     int rc;
 
-    TEST_ASSERT(!ble_gap_slave_in_progress());
+    TEST_ASSERT(!ble_gap_adv_active());
 
     /*** Invalid discoverable mode. */
     adv_params = ble_hs_test_util_adv_params;
@@ -1314,7 +1322,7 @@ TEST_CASE(ble_gap_test_case_adv_bad_args)
                                     peer_addr, &adv_params,
                                     ble_gap_test_util_connect_cb, NULL, 0, 0);
     TEST_ASSERT(rc == BLE_HS_EINVAL);
-    TEST_ASSERT(!ble_gap_slave_in_progress());
+    TEST_ASSERT(!ble_gap_adv_active());
 
     /*** Invalid connectable mode. */
     adv_params = ble_hs_test_util_adv_params;
@@ -1323,7 +1331,7 @@ TEST_CASE(ble_gap_test_case_adv_bad_args)
                                     peer_addr, &adv_params,
                                     ble_gap_test_util_connect_cb, NULL, 0, 0);
     TEST_ASSERT(rc == BLE_HS_EINVAL);
-    TEST_ASSERT(!ble_gap_slave_in_progress());
+    TEST_ASSERT(!ble_gap_adv_active());
 
     /*** Invalid peer address type with directed advertisable mode. */
     adv_params = ble_hs_test_util_adv_params;
@@ -1332,7 +1340,7 @@ TEST_CASE(ble_gap_test_case_adv_bad_args)
                                     peer_addr, &adv_params,
                                     ble_gap_test_util_connect_cb, NULL, 0, 0);
     TEST_ASSERT(rc == BLE_HS_EINVAL);
-    TEST_ASSERT(!ble_gap_slave_in_progress());
+    TEST_ASSERT(!ble_gap_adv_active());
 
     /*** Advertising already in progress. */
     adv_params = ble_hs_test_util_adv_params;
@@ -1340,13 +1348,13 @@ TEST_CASE(ble_gap_test_case_adv_bad_args)
                                     peer_addr, &adv_params,
                                     ble_gap_test_util_connect_cb, NULL, 0, 0);
     TEST_ASSERT(rc == 0);
-    TEST_ASSERT(ble_gap_slave_in_progress());
+    TEST_ASSERT(ble_gap_adv_active());
 
     rc = ble_hs_test_util_adv_start(BLE_ADDR_TYPE_PUBLIC, BLE_ADDR_TYPE_PUBLIC,
                                     peer_addr, &adv_params,
                                     ble_gap_test_util_connect_cb, NULL, 0, 0);
     TEST_ASSERT(rc == BLE_HS_EALREADY);
-    TEST_ASSERT(ble_gap_slave_in_progress());
+    TEST_ASSERT(ble_gap_adv_active());
 }
 
 static void
@@ -1364,7 +1372,7 @@ ble_gap_test_util_adv_verify_dflt_params(uint8_t own_addr_type,
 
     ble_gap_test_util_init();
 
-    TEST_ASSERT(!ble_gap_slave_in_progress());
+    TEST_ASSERT(!ble_gap_adv_active());
 
     adv_params = ble_hs_test_util_adv_params;
     adv_params.conn_mode = conn_mode;
@@ -1446,7 +1454,7 @@ TEST_CASE(ble_gap_test_case_adv_good)
                                   peer_addr, c, d, BLE_ERR_SUCCESS, -1, 0);
 
             if (c != BLE_GAP_CONN_MODE_NON) {
-                TEST_ASSERT(!ble_gap_slave_in_progress());
+                TEST_ASSERT(!ble_gap_adv_active());
                 TEST_ASSERT(ble_gap_test_conn_event == BLE_GAP_EVENT_CONNECT);
                 TEST_ASSERT(ble_gap_test_conn_status == 0);
                 TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2);
@@ -1469,7 +1477,7 @@ TEST_CASE(ble_gap_test_case_adv_ctlr_fail)
             ble_gap_test_util_adv(BLE_ADDR_TYPE_PUBLIC, BLE_ADDR_TYPE_PUBLIC,
                                   peer_addr, c, d, BLE_ERR_DIR_ADV_TMO, -1, 0);
 
-            TEST_ASSERT(!ble_gap_slave_in_progress());
+            TEST_ASSERT(!ble_gap_adv_active());
             TEST_ASSERT(ble_gap_test_conn_event == BLE_GAP_EVENT_ADV_COMPLETE);
             TEST_ASSERT(ble_gap_test_conn_desc.conn_handle ==
                         BLE_HS_CONN_HANDLE_NONE);
@@ -1499,7 +1507,7 @@ TEST_CASE(ble_gap_test_case_adv_hci_fail)
                                       BLE_ADDR_TYPE_PUBLIC, peer_addr,
                                       c, d, 0, fail_idx, BLE_ERR_UNSUPPORTED);
 
-                TEST_ASSERT(!ble_gap_slave_in_progress());
+                TEST_ASSERT(!ble_gap_adv_active());
                 TEST_ASSERT(ble_gap_test_conn_event == -1);
             }
         }
@@ -1533,7 +1541,7 @@ ble_gap_test_util_stop_adv(uint8_t peer_addr_type, const uint8_t *peer_addr,
     ble_gap_test_util_adv(BLE_ADDR_TYPE_PUBLIC, peer_addr_type, peer_addr,
                           conn_mode, disc_mode, -1, -1, 0);
 
-    TEST_ASSERT(ble_gap_slave_in_progress());
+    TEST_ASSERT(ble_gap_adv_active());
 
     /* Stop advertising. */
     hci_status = cmd_fail_idx == 0 ? fail_status : 0;
@@ -1555,7 +1563,7 @@ TEST_CASE(ble_gap_test_case_stop_adv_good)
         for (d = BLE_GAP_DISC_MODE_NON; d < BLE_GAP_DISC_MODE_MAX; d++) {
             ble_gap_test_util_stop_adv(BLE_ADDR_TYPE_PUBLIC, peer_addr, c, d,
                                        -1, 0);
-            TEST_ASSERT(!ble_gap_slave_in_progress());
+            TEST_ASSERT(!ble_gap_adv_active());
             TEST_ASSERT(ble_gap_test_conn_event == -1);
             TEST_ASSERT(ble_gap_test_conn_status == -1);
             TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == (uint16_t)-1);
@@ -1574,7 +1582,7 @@ TEST_CASE(ble_gap_test_case_stop_adv_hci_fail)
         for (d = BLE_GAP_DISC_MODE_NON; d < BLE_GAP_DISC_MODE_MAX; d++) {
             ble_gap_test_util_stop_adv(BLE_ADDR_TYPE_PUBLIC, peer_addr, c, d,
                                        0, BLE_ERR_UNSUPPORTED);
-            TEST_ASSERT(ble_gap_slave_in_progress());
+            TEST_ASSERT(ble_gap_adv_active());
             TEST_ASSERT(ble_gap_test_conn_event == -1);
             TEST_ASSERT(ble_gap_test_conn_status == -1);
             TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == (uint16_t)-1);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/37570894/net/nimble/host/src/test/ble_hs_conn_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_hs_conn_test.c b/net/nimble/host/src/test/ble_hs_conn_test.c
index ef643d7..fcab787 100644
--- a/net/nimble/host/src/test/ble_hs_conn_test.c
+++ b/net/nimble/host/src/test/ble_hs_conn_test.c
@@ -101,7 +101,7 @@ TEST_CASE(ble_hs_conn_test_direct_connectable_success)
 
     /* Ensure no current or pending connections. */
     TEST_ASSERT(!ble_gap_master_in_progress());
-    TEST_ASSERT(!ble_gap_slave_in_progress());
+    TEST_ASSERT(!ble_gap_adv_active());
     TEST_ASSERT(!ble_hs_conn_test_util_any());
 
     /* Initiate advertising. */
@@ -112,7 +112,7 @@ TEST_CASE(ble_hs_conn_test_direct_connectable_success)
     TEST_ASSERT(rc == 0);
 
     TEST_ASSERT(!ble_gap_master_in_progress());
-    TEST_ASSERT(ble_gap_slave_in_progress());
+    TEST_ASSERT(ble_gap_adv_active());
 
     /* Receive successful connection complete event. */
     memset(&evt, 0, sizeof evt);
@@ -124,7 +124,7 @@ TEST_CASE(ble_hs_conn_test_direct_connectable_success)
     rc = ble_gap_rx_conn_complete(&evt);
     TEST_ASSERT(rc == 0);
     TEST_ASSERT(!ble_gap_master_in_progress());
-    TEST_ASSERT(!ble_gap_slave_in_progress());
+    TEST_ASSERT(!ble_gap_adv_active());
 
     ble_hs_lock();
 
@@ -156,7 +156,7 @@ TEST_CASE(ble_hs_conn_test_undirect_connectable_success)
 
     /* Ensure no current or pending connections. */
     TEST_ASSERT(!ble_gap_master_in_progress());
-    TEST_ASSERT(!ble_gap_slave_in_progress());
+    TEST_ASSERT(!ble_gap_adv_active());
     TEST_ASSERT(!ble_hs_conn_test_util_any());
 
     /* Initiate advertising. */
@@ -172,7 +172,7 @@ TEST_CASE(ble_hs_conn_test_undirect_connectable_success)
     TEST_ASSERT(rc == 0);
 
     TEST_ASSERT(!ble_gap_master_in_progress());
-    TEST_ASSERT(ble_gap_slave_in_progress());
+    TEST_ASSERT(ble_gap_adv_active());
 
     /* Receive successful connection complete event. */
     memset(&evt, 0, sizeof evt);
@@ -184,7 +184,7 @@ TEST_CASE(ble_hs_conn_test_undirect_connectable_success)
     rc = ble_gap_rx_conn_complete(&evt);
     TEST_ASSERT(rc == 0);
     TEST_ASSERT(!ble_gap_master_in_progress());
-    TEST_ASSERT(!ble_gap_slave_in_progress());
+    TEST_ASSERT(!ble_gap_adv_active());
 
     ble_hs_lock();
 


[37/50] [abbrv] incubator-mynewt-core git commit: BLE Host - Fill in privacy API.

Posted by cc...@apache.org.
BLE Host - Fill in privacy API.


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

Branch: refs/heads/ble_hs_api
Commit: 7efbf0ee9cdc27bda570f3e3e6c8f27436840c67
Parents: 0853958
Author: Christopher Collins <cc...@apache.org>
Authored: Fri Jul 1 15:58:11 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Jul 11 16:43:33 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/include/host/ble_gap.h      |   1 -
 net/nimble/host/include/host/ble_hs.h       |   1 +
 net/nimble/host/include/host/ble_hs_id.h    |  30 +++
 net/nimble/host/src/ble_gap.c               |  64 +++---
 net/nimble/host/src/ble_gatts.c             |  12 +-
 net/nimble/host/src/ble_hci_priv.h          |   2 +-
 net/nimble/host/src/ble_hci_util.c          |   2 +-
 net/nimble/host/src/ble_hs_conn.c           |  50 ++---
 net/nimble/host/src/ble_hs_conn_priv.h      |  20 +-
 net/nimble/host/src/ble_hs_id.c             | 248 +++++++++++++++++++++++
 net/nimble/host/src/ble_hs_id_priv.h        |  30 +++
 net/nimble/host/src/ble_hs_misc.c           |   6 +-
 net/nimble/host/src/ble_hs_priv.h           |   5 +-
 net/nimble/host/src/ble_hs_pvcy.c           |  99 ++-------
 net/nimble/host/src/ble_hs_pvcy_priv.h      |   7 +-
 net/nimble/host/src/ble_hs_startup.c        |   3 +-
 net/nimble/host/src/ble_sm.c                |  29 ++-
 net/nimble/host/src/ble_sm_alg.c            |   9 +-
 net/nimble/host/src/ble_sm_priv.h           |   7 +-
 net/nimble/host/src/ble_sm_sc.c             |  12 +-
 net/nimble/host/src/test/ble_gap_test.c     |   1 +
 net/nimble/host/src/test/ble_hs_conn_test.c |   6 +-
 net/nimble/host/src/test/ble_hs_test.c      |   2 +-
 net/nimble/host/src/test/ble_hs_test_util.c |  24 ++-
 net/nimble/host/src/test/ble_hs_test_util.h |   2 +-
 net/nimble/host/src/test/ble_sm_test_util.c |  21 +-
 net/nimble/include/nimble/ble.h             |   2 +-
 net/nimble/src/util.c                       |   2 +-
 28 files changed, 489 insertions(+), 208 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7efbf0ee/net/nimble/host/include/host/ble_gap.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/ble_gap.h b/net/nimble/host/include/host/ble_gap.h
index c0dc278..f83b1de 100644
--- a/net/nimble/host/include/host/ble_gap.h
+++ b/net/nimble/host/include/host/ble_gap.h
@@ -321,6 +321,5 @@ int ble_gap_security_initiate(uint16_t conn_handle);
 int ble_gap_pair_initiate(uint16_t conn_handle);
 int ble_gap_encryption_initiate(uint16_t conn_handle, const uint8_t *ltk,
                                 uint16_t ediv, uint64_t rand_val, int auth);
-void ble_gap_init_identity_addr(const uint8_t *addr);
 
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7efbf0ee/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 7786b9a..2d2a93a 100644
--- a/net/nimble/host/include/host/ble_hs.h
+++ b/net/nimble/host/include/host/ble_hs.h
@@ -58,6 +58,7 @@ struct os_event;
 #define BLE_HS_ETIMEOUT_HCI         20
 #define BLE_HS_ENOMEM_HCI           21
 #define BLE_HS_ENOMEM_EVT           22
+#define BLE_HS_ENOADDR              23
 
 #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/7efbf0ee/net/nimble/host/include/host/ble_hs_id.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/ble_hs_id.h b/net/nimble/host/include/host/ble_hs_id.h
new file mode 100644
index 0000000..749524b
--- /dev/null
+++ b/net/nimble/host/include/host/ble_hs_id.h
@@ -0,0 +1,30 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef H_BLE_HS_ID_
+#define H_BLE_HS_ID_
+
+#include <inttypes.h>
+
+int ble_hs_id_gen_rnd(int nrpa, uint8_t *out_addr);
+int ble_hs_id_set_rnd(const uint8_t *rnd_addr);
+int ble_hs_id_copy_addr(uint8_t id_addr_type, uint8_t *out_id_addr,
+                        int *out_is_nrpa);
+
+#endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7efbf0ee/net/nimble/host/src/ble_gap.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gap.c b/net/nimble/host/src/ble_gap.c
index 2745379..7254287 100644
--- a/net/nimble/host/src/ble_gap.c
+++ b/net/nimble/host/src/ble_gap.c
@@ -971,10 +971,12 @@ ble_gap_rx_conn_complete(struct hci_le_conn_complete *evt)
     BLE_HS_DBG_ASSERT(conn != NULL);
 
     conn->bhc_handle = evt->connection_handle;
-    memcpy(conn->bhc_addr, evt->peer_addr, sizeof conn->bhc_addr);
-    conn->bhc_addr_type = evt->peer_addr_type;
-    memcpy(conn->our_rpa_addr, evt->local_rpa, sizeof(conn->our_rpa_addr));
-    memcpy(conn->peer_rpa_addr, evt->peer_rpa, sizeof(conn->peer_rpa_addr));
+    memcpy(conn->bhc_peer_addr, evt->peer_addr, sizeof conn->bhc_peer_addr);
+    conn->bhc_peer_addr_type = evt->peer_addr_type;
+    memcpy(conn->bhc_our_rpa_addr, evt->local_rpa,
+           sizeof conn->bhc_our_rpa_addr);
+    memcpy(conn->bhc_peer_rpa_addr, evt->peer_rpa,
+           sizeof conn->bhc_peer_rpa_addr);
     conn->bhc_itvl = evt->conn_itvl;
     conn->bhc_latency = evt->conn_latency;
     conn->bhc_supervision_timeout = evt->supervision_timeout;
@@ -982,22 +984,25 @@ ble_gap_rx_conn_complete(struct hci_le_conn_complete *evt)
     if (evt->role == BLE_HCI_LE_CONN_COMPLETE_ROLE_MASTER) {
         conn->bhc_flags |= BLE_HS_CONN_F_MASTER;
         conn->bhc_cb = ble_gap_master.conn.cb;
-        conn->our_addr_type = ble_gap_master.conn.our_addr_type;
+        conn->bhc_our_addr_type = ble_gap_master.conn.our_addr_type;
         conn->bhc_cb_arg = ble_gap_master.conn.cb_arg;
         ble_gap_master_reset_state();
     } else {
         conn->bhc_cb = ble_gap_slave.cb;
         conn->bhc_cb_arg = ble_gap_slave.cb_arg;
-        conn->our_addr_type = ble_gap_slave.our_addr_type;
+        conn->bhc_our_addr_type = ble_gap_slave.our_addr_type;
         ble_gap_slave_reset_state();
     }
 
-    memcpy(conn->our_rpa_addr, evt->local_rpa, 6);
-    memcpy(conn->peer_rpa_addr, evt->peer_rpa, 6);
+    memcpy(conn->bhc_our_rpa_addr, evt->local_rpa, 6);
+    memcpy(conn->bhc_peer_rpa_addr, evt->peer_rpa, 6);
+
+    ble_hs_lock();
 
     ble_gap_conn_to_snapshot(conn, &snap);
+    ble_hs_conn_insert(conn);
 
-    ble_hs_atomic_conn_insert(conn);
+    ble_hs_unlock();
 
     memset(&ctxt, 0, sizeof ctxt);
     ctxt.desc = &snap.desc;
@@ -1660,6 +1665,11 @@ ble_gap_adv_start(uint8_t own_addr_type, uint8_t peer_addr_type,
         }
     }
 
+    rc = ble_hs_id_use_addr(own_addr_type);
+    if (rc != 0) {
+        return rc;
+    }
+
     BLE_HS_LOG(INFO, "GAP procedure initiated: advertise; ");
     ble_gap_log_adv(own_addr_type, peer_addr_type, peer_addr, adv_params);
     BLE_HS_LOG(INFO, "\n");
@@ -1974,10 +1984,10 @@ ble_gap_disc_validate(uint8_t own_addr_type,
  * Performs the Limited or General Discovery Procedures (vol. 3, part C,
  * section 9.2.5 / 9.2.6).
  *
- * @param own_addr_type         This parameter is ignored unless active scanning
- *                                  is being used. The type of address the
- *                                  stack should use for itself when sending
- *                                  scan requests.  Valid values are:
+ * @param own_addr_type         This parameter is ignored unless active
+ *                                  scanning is being used. The type of address
+ *                                  the stack should use for itself when
+ *                                  sending scan requests.  Valid values are:
  *                                      o BLE_ADDR_TYPE_PUBLIC
  *                                      o BLE_ADDR_TYPE_RANDOM
  *                                      o BLE_ADDR_TYPE_RPA_PUB_DEFAULT
@@ -1990,9 +2000,9 @@ ble_gap_disc_validate(uint8_t own_addr_type,
  * @param disc_params           Additional arguments specifying the particulars
  *                                  of the discovery procedure.
  * @param cb                    The callback to associate with this discovery
- *                                  procedure.  Advertising reports and discovery
- *                                  termination events are reported through
- *                                  this callback.
+ *                                  procedure.  Advertising reports and
+ *                                  discovery termination events are reported
+ *                                  through this callback.
  * @param cb_arg                The optional argument to pass to the callback
  *                                  function.
  *
@@ -2039,6 +2049,13 @@ ble_gap_disc(uint8_t own_addr_type, int32_t duration_ms,
         }
     }
 
+    if (!params.passive) {
+        rc = ble_hs_id_use_addr(own_addr_type);
+        if (rc != 0) {
+            return rc;
+        }
+    }
+
     ble_gap_master.disc.limited = params.limited;
     ble_gap_master.disc.cb = cb;
     ble_gap_master.disc.cb_arg = cb_arg;
@@ -2208,6 +2225,11 @@ ble_gap_connect(uint8_t own_addr_type,
 
     /* XXX: Verify conn_params. */
 
+    rc = ble_hs_id_use_addr(own_addr_type);
+    if (rc != 0) {
+        return rc;
+    }
+
     BLE_HS_LOG(INFO, "GAP procedure initiated: connect; ");
     ble_gap_log_conn(own_addr_type, peer_addr_type, peer_addr, conn_params);
     BLE_HS_LOG(INFO, "\n");
@@ -2766,16 +2788,6 @@ ble_gap_notify_event(uint16_t conn_handle, uint16_t attr_handle,
 }
 
 /*****************************************************************************
- * $privacy                                                                  *
- *****************************************************************************/
-
-void
-ble_gap_init_identity_addr(const uint8_t *addr)
-{
-    ble_hs_pvcy_set_our_id_addr(addr);
-}
-
-/*****************************************************************************
  * $init                                                                     *
  *****************************************************************************/
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7efbf0ee/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 2318fdf..3b6b0b6 100644
--- a/net/nimble/host/src/ble_gatts.c
+++ b/net/nimble/host/src/ble_gatts.c
@@ -601,8 +601,8 @@ ble_gatts_clt_cfg_access_locked(struct ble_hs_conn *conn, uint16_t attr_handle,
 
         /* Successful writes get persisted for bonded connections. */
         if (conn->bhc_sec_state.bonded) {
-            out_cccd->peer_addr_type = conn->bhc_addr_type;
-            memcpy(out_cccd->peer_addr, conn->bhc_addr, 6);
+            out_cccd->peer_addr_type = conn->bhc_peer_addr_type;
+            memcpy(out_cccd->peer_addr, conn->bhc_peer_addr, 6);
             out_cccd->chr_val_handle = chr_val_handle;
             out_cccd->flags = clt_cfg->flags;
             out_cccd->value_changed = 0;
@@ -1186,8 +1186,8 @@ ble_gatts_rx_indicate_ack(uint16_t conn_handle, uint16_t chr_val_handle)
         persist = conn->bhc_sec_state.bonded &&
                   !(clt_cfg->flags & BLE_GATTS_CLT_CFG_F_INDICATE_PENDING);
         if (persist) {
-            cccd_value.peer_addr_type = conn->bhc_addr_type;
-            memcpy(cccd_value.peer_addr, conn->bhc_addr, 6);
+            cccd_value.peer_addr_type = conn->bhc_peer_addr_type;
+            memcpy(cccd_value.peer_addr, conn->bhc_peer_addr, 6);
             cccd_value.chr_val_handle = chr_val_handle;
             cccd_value.flags = clt_cfg->flags;
             cccd_value.value_changed = 0;
@@ -1356,8 +1356,8 @@ ble_gatts_bonding_restored(uint16_t conn_handle)
     BLE_HS_DBG_ASSERT(conn != NULL);
     BLE_HS_DBG_ASSERT(conn->bhc_sec_state.bonded);
 
-    cccd_key.peer_addr_type = conn->bhc_addr_type;
-    memcpy(cccd_key.peer_addr, conn->bhc_addr, 6);
+    cccd_key.peer_addr_type = conn->bhc_peer_addr_type;
+    memcpy(cccd_key.peer_addr, conn->bhc_peer_addr, 6);
     cccd_key.chr_val_handle = 0;
     cccd_key.idx = 0;
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7efbf0ee/net/nimble/host/src/ble_hci_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hci_priv.h b/net/nimble/host/src/ble_hci_priv.h
index dbe3d15..1526a20 100644
--- a/net/nimble/host/src/ble_hci_priv.h
+++ b/net/nimble/host/src/ble_hci_priv.h
@@ -42,7 +42,7 @@ void ble_hci_set_phony_ack_cb(ble_hci_cmd_phony_ack_fn *cb);
 int ble_hci_util_read_adv_tx_pwr(int8_t *out_pwr);
 int ble_hci_util_rand(void *dst, int len);
 int ble_hci_util_read_rssi(uint16_t conn_handle, int8_t *out_rssi);
-int ble_hci_util_set_random_addr(uint8_t *addr);
+int ble_hci_util_set_random_addr(const uint8_t *addr);
 int ble_hci_util_set_data_len(uint16_t conn_handle, uint16_t tx_octets,
                               uint16_t tx_time);
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7efbf0ee/net/nimble/host/src/ble_hci_util.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hci_util.c b/net/nimble/host/src/ble_hci_util.c
index c44c012..3850903 100644
--- a/net/nimble/host/src/ble_hci_util.c
+++ b/net/nimble/host/src/ble_hci_util.c
@@ -107,7 +107,7 @@ ble_hci_util_read_rssi(uint16_t conn_handle, int8_t *out_rssi)
 }
 
 int
-ble_hci_util_set_random_addr(uint8_t *addr)
+ble_hci_util_set_random_addr(const uint8_t *addr)
 {
     uint8_t buf[BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_RAND_ADDR_LEN];
     int rc;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7efbf0ee/net/nimble/host/src/ble_hs_conn.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_conn.c b/net/nimble/host/src/ble_hs_conn.c
index a4b0f16..cd9f4b7 100644
--- a/net/nimble/host/src/ble_hs_conn.c
+++ b/net/nimble/host/src/ble_hs_conn.c
@@ -21,6 +21,7 @@
 #include <errno.h>
 #include "os/os.h"
 #include "host/host_hci.h"
+#include "host/ble_hs_id.h"
 #include "ble_hs_priv.h"
 
 /** At least three channels required per connection (sig, att, sm). */
@@ -258,8 +259,8 @@ ble_hs_conn_find_by_addr(uint8_t addr_type, uint8_t *addr)
     BLE_HS_DBG_ASSERT(ble_hs_locked_by_cur_task());
 
     SLIST_FOREACH(conn, &ble_hs_conns, bhc_next) {
-        if (conn->bhc_addr_type == addr_type &&
-            memcmp(conn->bhc_addr, addr, 6) == 0) {
+        if (conn->bhc_peer_addr_type == addr_type &&
+            memcmp(conn->bhc_peer_addr, addr, 6) == 0) {
 
             return conn;
         }
@@ -316,59 +317,52 @@ ble_hs_conn_first(void)
 }
 
 void
-ble_hs_conn_addrs(struct ble_hs_conn *conn,
+ble_hs_conn_addrs(const struct ble_hs_conn *conn,
                   struct ble_hs_conn_addrs *addrs)
 {
+    int rc;
+
     /* Determine our address information. */
-    addrs->our_id_addr =
-        ble_hs_pvcy_our_id_addr(&addrs->our_id_addr_type);
-    if (memcmp(conn->our_rpa_addr, ble_hs_conn_null_addr, 6) == 0) {
+    addrs->our_id_addr_type =
+        ble_hs_misc_addr_type_to_id(conn->bhc_our_addr_type);
+    rc = ble_hs_id_addr(addrs->our_id_addr_type, &addrs->our_id_addr, NULL);
+    assert(rc == 0);
+
+    if (memcmp(conn->bhc_our_rpa_addr, ble_hs_conn_null_addr, 6) == 0) {
         addrs->our_ota_addr_type = addrs->our_id_addr_type;
         addrs->our_ota_addr = addrs->our_id_addr;
     } else {
-        switch (addrs->our_id_addr_type) {
-        case BLE_ADDR_TYPE_PUBLIC:
-            addrs->our_ota_addr_type = BLE_ADDR_TYPE_RPA_PUB_DEFAULT;
-            break;
-
-        case BLE_ADDR_TYPE_RANDOM:
-            addrs->our_ota_addr_type = BLE_ADDR_TYPE_RPA_RND_DEFAULT;
-            break;
-
-        default:
-            BLE_HS_DBG_ASSERT(0);
-        }
-
-        addrs->our_ota_addr = conn->our_rpa_addr;
+        addrs->our_ota_addr_type = conn->bhc_our_addr_type;
+        addrs->our_ota_addr = conn->bhc_our_rpa_addr;
     }
 
     /* Determine peer address information. */
-    addrs->peer_ota_addr_type = conn->bhc_addr_type;
-    addrs->peer_id_addr = conn->bhc_addr;
-    switch (conn->bhc_addr_type) {
+    addrs->peer_ota_addr_type = conn->bhc_peer_addr_type;
+    addrs->peer_id_addr = conn->bhc_peer_addr;
+    switch (conn->bhc_peer_addr_type) {
     case BLE_ADDR_TYPE_PUBLIC:
         addrs->peer_id_addr_type = BLE_ADDR_TYPE_PUBLIC;
-        addrs->peer_ota_addr = conn->bhc_addr;
+        addrs->peer_ota_addr = conn->bhc_peer_addr;
         break;
 
     case BLE_ADDR_TYPE_RANDOM:
         addrs->peer_id_addr_type = BLE_ADDR_TYPE_RANDOM;
-        addrs->peer_ota_addr = conn->bhc_addr;
+        addrs->peer_ota_addr = conn->bhc_peer_addr;
         break;
 
     case BLE_ADDR_TYPE_RPA_PUB_DEFAULT:
         addrs->peer_id_addr_type = BLE_ADDR_TYPE_PUBLIC;
-        addrs->peer_ota_addr = conn->peer_rpa_addr;
+        addrs->peer_ota_addr = conn->bhc_peer_rpa_addr;
         break;
 
     case BLE_ADDR_TYPE_RPA_RND_DEFAULT:
         addrs->peer_id_addr_type = BLE_ADDR_TYPE_RANDOM;
-        addrs->peer_ota_addr = conn->peer_rpa_addr;
+        addrs->peer_ota_addr = conn->bhc_peer_rpa_addr;
         break;
 
     default:
         BLE_HS_DBG_ASSERT(0);
-        return;
+        break;
     }
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7efbf0ee/net/nimble/host/src/ble_hs_conn_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_conn_priv.h b/net/nimble/host/src/ble_hs_conn_priv.h
index 3ff7f76..cdcb363 100644
--- a/net/nimble/host/src/ble_hs_conn_priv.h
+++ b/net/nimble/host/src/ble_hs_conn_priv.h
@@ -36,11 +36,11 @@ typedef uint8_t ble_hs_conn_flags_t;
 struct ble_hs_conn {
     SLIST_ENTRY(ble_hs_conn) bhc_next;
     uint16_t bhc_handle;
-    uint8_t bhc_addr_type;
-    uint8_t our_addr_type;
-    uint8_t bhc_addr[6];
-    uint8_t our_rpa_addr[6];
-    uint8_t peer_rpa_addr[6];
+    uint8_t bhc_peer_addr_type;
+    uint8_t bhc_our_addr_type;
+    uint8_t bhc_peer_addr[6];
+    uint8_t bhc_our_rpa_addr[6];
+    uint8_t bhc_peer_rpa_addr[6];
 
     uint16_t bhc_itvl;
     uint16_t bhc_latency;
@@ -67,10 +67,10 @@ struct ble_hs_conn_addrs {
     uint8_t our_id_addr_type;
     uint8_t peer_ota_addr_type;
     uint8_t peer_id_addr_type;
-    uint8_t *our_ota_addr;
-    uint8_t *our_id_addr;
-    uint8_t *peer_ota_addr;
-    uint8_t *peer_id_addr;
+    const uint8_t *our_ota_addr;
+    const uint8_t *our_id_addr;
+    const uint8_t *peer_ota_addr;
+    const uint8_t *peer_id_addr;
 };
 
 int ble_hs_conn_can_alloc(void);
@@ -87,7 +87,7 @@ struct ble_l2cap_chan *ble_hs_conn_chan_find(struct ble_hs_conn *conn,
                                              uint16_t cid);
 int ble_hs_conn_chan_insert(struct ble_hs_conn *conn,
                             struct ble_l2cap_chan *chan);
-void ble_hs_conn_addrs(struct ble_hs_conn *conn,
+void ble_hs_conn_addrs(const struct ble_hs_conn *conn,
                        struct ble_hs_conn_addrs *addrs);
 
 int ble_hs_conn_init(void);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7efbf0ee/net/nimble/host/src/ble_hs_id.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_id.c b/net/nimble/host/src/ble_hs_id.c
new file mode 100644
index 0000000..6d7df2b
--- /dev/null
+++ b/net/nimble/host/src/ble_hs_id.c
@@ -0,0 +1,248 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include <string.h>
+#include "host/ble_hs_id.h"
+#include "ble_hs_priv.h"
+
+static uint8_t ble_hs_id_pub[6];
+static uint8_t ble_hs_id_rnd[6];
+
+void
+ble_hs_id_set_pub(const uint8_t *pub_addr)
+{
+    ble_hs_lock();
+    memcpy(ble_hs_id_pub, pub_addr, 6);
+    ble_hs_unlock();
+}
+
+/**
+ * Generates a new random address.  This function does not configure the device
+ * with the new address; the caller can use the address in subsequent
+ * operations.
+ *
+ * @param nrpa                  The type of random address to generate:
+ *                                  0: static
+ *                                  1: non-resolvable private
+ * @param out_addr              On success, the generated address gets written
+ *                                  here.
+ *
+ * @return                      0 on success; nonzero on failure.
+ */
+int
+ble_hs_id_gen_rnd(int nrpa, uint8_t *out_addr)
+{
+    int rc;
+
+    rc = ble_hci_util_rand(out_addr, 6);
+    if (rc != 0) {
+        return rc;
+    }
+
+    if (nrpa) {
+        out_addr[5] &= ~0xc0;
+    } else {
+        out_addr[5] |= 0xc0;
+    }
+
+    return 0;
+}
+
+/**
+ * Sets the device's random address.  The address type (static vs.
+ * non-resolvable private) is inferred from the most-significant byte of the
+ * address.  The address is specified in host byte order (little-endian!).
+ *
+ * @param rnd_addr              The random address to set.
+ *
+ * @return                      0 on success;
+ *                              BLE_HS_EINVAL if the specified address is not a
+ *                                  valid static random or non-resolvable
+ *                                  private address.
+ *                              Other nonzero on error.
+ */
+int
+ble_hs_id_set_rnd(const uint8_t *rnd_addr)
+{
+    uint8_t addr_type_byte;
+    int rc;
+
+    ble_hs_lock();
+
+    addr_type_byte = rnd_addr[5] & 0xc0;
+    if (addr_type_byte != 0x00 && addr_type_byte != 0xc0) {
+        rc = BLE_HS_EINVAL;
+        goto done;
+    }
+
+    rc = ble_hci_util_set_random_addr(rnd_addr);
+    if (rc != 0) {
+        goto done;
+    }
+
+    memcpy(ble_hs_id_rnd, rnd_addr, 6);
+
+    rc = 0;
+
+done:
+    ble_hs_unlock();
+    return rc;
+}
+
+/**
+ * Retrieves one of the device's identity addresses.  The device can have two
+ * identity addresses: one public and one random.  The id_addr_type argument
+ * specifies which of these two addresses to retrieve.
+ *
+ * @param id_addr_type          The type of identity address to retrieve.
+ *                                  Valid values are:
+ *                                      o BLE_ADDR_TYPE_PUBLIC
+ *                                      o BLE_ADDR_TYPE_RANDOM
+ * @param out_id_addr           On success, this is reseated to point to the
+ *                                  retrieved 6-byte identity address.
+ * @param out_is_nrpa           On success, the pointed-to value indicates
+ *                                  whether the retrieved address is a
+ *                                  non-resolvable private address.
+ *
+ * @return                      0 on success;
+ *                              BLE_HS_EINVAL if an invalid address type was
+ *                                  specified;
+ *                              BLE_HS_ENOADDR if the device does not have an
+ *                                  identity address of the requested type;
+ *                              Other BLE host core code on error.
+ */
+int
+ble_hs_id_addr(uint8_t id_addr_type, const uint8_t **out_id_addr,
+               int *out_is_nrpa)
+{
+    const uint8_t *id_addr;
+    int nrpa;
+
+    BLE_HS_DBG_ASSERT(ble_hs_locked_by_cur_task());
+
+    switch (id_addr_type) {
+    case BLE_ADDR_TYPE_PUBLIC:
+        id_addr = ble_hs_id_pub;
+        nrpa = 0;
+        break;
+
+    case BLE_ADDR_TYPE_RANDOM:
+        id_addr = ble_hs_id_rnd;
+        nrpa = (ble_hs_id_rnd[5] & 0xc0) == 0;
+        break;
+
+    default:
+        return BLE_HS_EINVAL;
+    }
+
+    if (memcmp(id_addr, ble_hs_misc_null_addr, 6) == 0) {
+        return BLE_HS_ENOADDR;
+    }
+
+    if (out_id_addr != NULL) {
+        *out_id_addr = id_addr;
+    }
+    if (out_is_nrpa != NULL) {
+        *out_is_nrpa = nrpa;
+    }
+
+    return 0;
+}
+
+/**
+ * Retrieves one of the device's identity addresses.  The device can have two
+ * identity addresses: one public and one random.  The id_addr_type argument
+ * specifies which of these two addresses to retrieve.
+ *
+ * @param id_addr_type          The type of identity address to retrieve.
+ *                                  Valid values are:
+ *                                      o BLE_ADDR_TYPE_PUBLIC
+ *                                      o BLE_ADDR_TYPE_RANDOM
+ * @param out_id_addr           On success, the requested identity address is
+ *                                  copied into this buffer.  The buffer must
+ *                                  be at least six bytes in size.
+ * @param out_is_nrpa           On success, the pointed-to value indicates
+ *                                  whether the retrieved address is a
+ *                                  non-resolvable private address.
+ *
+ * @return                      0 on success;
+ *                              BLE_HS_EINVAL if an invalid address type was
+ *                                  specified;
+ *                              BLE_HS_ENOADDR if the device does not have an
+ *                                  identity address of the requested type;
+ *                              Other BLE host core code on error.
+ */
+int
+ble_hs_id_copy_addr(uint8_t id_addr_type, uint8_t *out_id_addr,
+                    int *out_is_nrpa)
+{
+    const uint8_t *addr;
+    int rc;
+
+    ble_hs_lock();
+
+    rc = ble_hs_id_addr(id_addr_type, &addr, out_is_nrpa);
+    if (rc == 0) {
+        memcpy(out_id_addr, addr, 6);
+    }
+
+    ble_hs_unlock();
+
+    return rc;
+}
+
+int
+ble_hs_id_use_addr(uint8_t addr_type)
+{
+    uint8_t id_addr_type;
+    int nrpa;
+    int rc;
+
+    switch (addr_type) {
+    case BLE_ADDR_TYPE_PUBLIC:
+    case BLE_ADDR_TYPE_RANDOM:
+        rc = ble_hs_id_addr(addr_type, NULL, NULL);
+        if (rc != 0) {
+            return rc;
+        }
+        break;
+
+    case BLE_ADDR_TYPE_RPA_PUB_DEFAULT:
+    case BLE_ADDR_TYPE_RPA_RND_DEFAULT:
+        id_addr_type = ble_hs_misc_addr_type_to_id(addr_type);
+        rc = ble_hs_id_addr(id_addr_type, NULL, &nrpa);
+        if (rc != 0) {
+            return rc;
+        }
+        if (nrpa) {
+            return BLE_HS_ENOADDR;
+        }
+
+        rc = ble_hs_pvcy_ensure_started();
+        if (rc != 0) {
+            return rc;
+        }
+        break;
+
+    default:
+        return BLE_HS_EINVAL;
+    }
+
+    return 0;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7efbf0ee/net/nimble/host/src/ble_hs_id_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_id_priv.h b/net/nimble/host/src/ble_hs_id_priv.h
new file mode 100644
index 0000000..5c0728c
--- /dev/null
+++ b/net/nimble/host/src/ble_hs_id_priv.h
@@ -0,0 +1,30 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef H_BLE_HS_ID_PRIV_
+#define H_BLE_HS_ID_PRIV_
+
+#include <inttypes.h>
+
+void ble_hs_id_set_pub(const uint8_t *pub_addr);
+int ble_hs_id_addr(uint8_t id_addr_type, const uint8_t **out_id_addr,
+                   int *out_is_nrpa);
+int ble_hs_id_use_addr(uint8_t addr_type);
+
+#endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7efbf0ee/net/nimble/host/src/ble_hs_misc.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_misc.c b/net/nimble/host/src/ble_hs_misc.c
index 597779c..b893cd3 100644
--- a/net/nimble/host/src/ble_hs_misc.c
+++ b/net/nimble/host/src/ble_hs_misc.c
@@ -46,7 +46,7 @@ ble_hs_misc_malloc_mempool(void **mem, struct os_mempool *pool,
 }
 
 void
-ble_hs_misc_log_mbuf(struct os_mbuf *om)
+ble_hs_misc_log_mbuf(const struct os_mbuf *om)
 {
     uint8_t u8;
     int i;
@@ -58,9 +58,9 @@ ble_hs_misc_log_mbuf(struct os_mbuf *om)
 }
 
 void
-ble_hs_misc_log_flat_buf(void *data, int len)
+ble_hs_misc_log_flat_buf(const void *data, int len)
 {
-    uint8_t *u8ptr;
+    const uint8_t *u8ptr;
     int i;
 
     u8ptr = data;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7efbf0ee/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 8cd4a83..e6fe55e 100644
--- a/net/nimble/host/src/ble_hs_priv.h
+++ b/net/nimble/host/src/ble_hs_priv.h
@@ -37,6 +37,7 @@
 #include "ble_sm_priv.h"
 #include "ble_hs_adv_priv.h"
 #include "ble_hs_pvcy_priv.h"
+#include "ble_hs_id_priv.h"
 #include "ble_uuid_priv.h"
 #include "host/ble_hs.h"
 #include "log/log.h"
@@ -71,8 +72,8 @@ int ble_hs_tx_data(struct os_mbuf *om);
 
 int ble_hs_misc_malloc_mempool(void **mem, struct os_mempool *pool,
                                int num_entries, int entry_size, char *name);
-void ble_hs_misc_log_mbuf(struct os_mbuf *om);
-void ble_hs_misc_log_flat_buf(void *data, int len);
+void ble_hs_misc_log_mbuf(const struct os_mbuf *om);
+void ble_hs_misc_log_flat_buf(const void *data, int len);
 int ble_hs_misc_conn_chan_find(uint16_t conn_handle, uint16_t cid,
                                struct ble_hs_conn **out_conn,
                                struct ble_l2cap_chan **out_chan);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7efbf0ee/net/nimble/host/src/ble_hs_pvcy.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_pvcy.c b/net/nimble/host/src/ble_hs_pvcy.c
index 3a20ce4..05f9122 100644
--- a/net/nimble/host/src/ble_hs_pvcy.c
+++ b/net/nimble/host/src/ble_hs_pvcy.c
@@ -21,13 +21,9 @@
 #include <string.h>
 #include "ble_hs_priv.h"
 
-static int ble_hs_pvcy_initialized;
-static uint8_t ble_hs_pvcy_id_addr[6];
-static uint8_t ble_hs_pvcy_id_addr_type;
-static uint8_t ble_hs_pvcy_nrpa[6];
+static uint8_t ble_hs_pvcy_started;
 uint8_t ble_hs_pvcy_irk[16];
 
-
 /** Use this as a default IRK if none gets set. */
 const uint8_t default_irk[16] = {
     0xef, 0x8d, 0xe2, 0x16, 0x4f, 0xec, 0x43, 0x0d,
@@ -35,18 +31,6 @@ const uint8_t default_irk[16] = {
 };
 
 static int
-ble_hs_pvcy_gen_static_random_addr(uint8_t *addr)
-{
-    int rc;
-
-    rc = ble_hci_util_rand(addr, 6);
-    /* TODO -- set bits properly */
-    addr[5] |= 0xc0;
-
-    return rc;
-}
-
-static int
 ble_hs_pvcy_set_addr_timeout(uint16_t timeout)
 {
     uint8_t buf[BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_RESOLV_PRIV_ADDR_TO_LEN];
@@ -125,7 +109,7 @@ ble_hs_pvcy_add_entry(uint8_t *addr, uint8_t addr_type, uint8_t *irk)
 
     add.addr_type = addr_type;
     memcpy(add.addr, addr, 6);
-    memcpy(add.local_irk, ble_hs_pvcy_our_irk(), 16);
+    memcpy(add.local_irk, ble_hs_pvcy_irk, 16);
     memcpy(add.peer_irk, irk, 16);
 
     rc = host_hci_cmd_build_add_to_resolv_list(&add, buf, sizeof(buf));
@@ -141,66 +125,24 @@ ble_hs_pvcy_add_entry(uint8_t *addr, uint8_t addr_type, uint8_t *irk)
     return 0;
 }
 
-void
-ble_hs_pvcy_our_nrpa(uint8_t *addr)
-{
-    memcpy(addr, ble_hs_pvcy_nrpa, 6);
-}
-
-int 
-ble_hs_pvcy_set_our_nrpa(void)
+int
+ble_hs_pvcy_ensure_started(void)
 {
     int rc;
-    uint8_t addr[6];
 
-    rc = ble_hci_util_rand(addr, 6);
-    assert(rc == 0);
-    addr[5] &= ~(0xc0);
-    memcpy(ble_hs_pvcy_nrpa, addr, 6);
-
-    return ble_hci_util_set_random_addr(addr);
-}
-
-uint8_t *
-ble_hs_pvcy_our_id_addr(uint8_t *type)
-{
-    if (!ble_hs_pvcy_initialized) {
-        ble_hs_pvcy_set_our_id_addr(NULL);
+    if (ble_hs_pvcy_started) {
+        return 0;
     }
 
-    if (type != NULL) {
-        *type = ble_hs_pvcy_id_addr_type;
-    }
-
-    return ble_hs_pvcy_id_addr;
-}
-
-void
-ble_hs_pvcy_set_our_id_addr(const uint8_t *addr)
-{
-    uint8_t random_addr[6];
-    int rc;
-
-    if (!ble_hs_pvcy_initialized) {
-        /* Set up the periodic change of our RPA. */
-        rc = ble_hs_pvcy_set_addr_timeout(ble_hs_cfg.rpa_timeout);
-        assert(rc == 0);
+    /* Set up the periodic change of our RPA. */
+    rc = ble_hs_pvcy_set_addr_timeout(ble_hs_cfg.rpa_timeout);
+    if (rc != 0) {
+        return rc;
     }
 
-    if (addr != NULL) {
-        memcpy(ble_hs_pvcy_id_addr, addr, 6);
-        ble_hs_pvcy_id_addr_type = BLE_HCI_ADV_OWN_ADDR_PUBLIC;
-    } else {
-        /* Generate a new static random address. */
-        ble_hs_pvcy_gen_static_random_addr(random_addr);
-        rc = ble_hci_util_set_random_addr(random_addr);
-        assert(rc == 0);
-
-        ble_hs_pvcy_id_addr_type = BLE_HCI_ADV_OWN_ADDR_RANDOM;
-        memcpy(ble_hs_pvcy_id_addr, random_addr, 6);
-    }
+    ble_hs_pvcy_started = 1;
 
-    ble_hs_pvcy_initialized = 1;
+    return 0;
 }
 
 void
@@ -225,21 +167,20 @@ ble_hs_pvcy_set_our_irk(const uint8_t *irk)
         ble_hs_pvcy_clear_entries();
         ble_hs_pvcy_set_resolve_enabled(1);
 
-        /* Push our identity to the controller as a keycache entry with a null
-         * MAC address. The controller uses this entry to generate an RPA when
-         * we do advertising with own-addr-type = rpa.
+        /* Push a null address identity to the controller.  The controller uses
+         * this entry to generate an RPA when we do advertising with
+         * own-addr-type = rpa.
          */
         memset(tmp_addr, 0, 6);
         ble_hs_pvcy_add_entry(tmp_addr, 0, ble_hs_pvcy_irk);
     }
 }
 
-uint8_t *
-ble_hs_pvcy_our_irk(void)
+int
+ble_hs_pvcy_our_irk(const uint8_t **out_irk)
 {
-    if (!ble_hs_pvcy_initialized) {
-        ble_hs_pvcy_set_our_id_addr(NULL);
-    }
+    /* XXX: Return error if privacy not supported. */
 
-    return ble_hs_pvcy_irk;
+    *out_irk = ble_hs_pvcy_irk;
+    return 0;
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7efbf0ee/net/nimble/host/src/ble_hs_pvcy_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_pvcy_priv.h b/net/nimble/host/src/ble_hs_pvcy_priv.h
index 282f2ad..2635778 100644
--- a/net/nimble/host/src/ble_hs_pvcy_priv.h
+++ b/net/nimble/host/src/ble_hs_pvcy_priv.h
@@ -22,13 +22,10 @@
 
 #include <inttypes.h>
 
-int ble_hs_pvcy_set_our_nrpa(void);
-void ble_hs_pvcy_our_nrpa(uint8_t *addr);
-void ble_hs_pvcy_set_our_id_addr(const uint8_t *addr);
 void ble_hs_pvcy_set_our_irk(const uint8_t *irk);
-uint8_t *ble_hs_pvcy_our_id_addr(uint8_t *type);
-uint8_t *ble_hs_pvcy_our_irk(void);
+int ble_hs_pvcy_our_irk(const uint8_t **out_irk);
 int ble_hs_pvcy_remove_entry(uint8_t addr_type, uint8_t *addr);
 int ble_hs_pvcy_add_entry(uint8_t *addr, uint8_t addrtype, uint8_t *irk);
+int ble_hs_pvcy_ensure_started(void);
 
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7efbf0ee/net/nimble/host/src/ble_hs_startup.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_startup.c b/net/nimble/host/src/ble_hs_startup.c
index 1973cf9..568f1ed 100644
--- a/net/nimble/host/src/ble_hs_startup.c
+++ b/net/nimble/host/src/ble_hs_startup.c
@@ -225,7 +225,8 @@ ble_hs_startup_go(void)
     }
 
     /* XXX: Read BD_ADDR. */
-    ble_hs_pvcy_set_our_id_addr(g_dev_addr);
+
+    ble_hs_id_set_pub(g_dev_addr);
     ble_hs_pvcy_set_our_irk(NULL);
 
     return rc;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7efbf0ee/net/nimble/host/src/ble_sm.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_sm.c b/net/nimble/host/src/ble_sm.c
index 5f9ad05..6b53dce 100644
--- a/net/nimble/host/src/ble_sm.c
+++ b/net/nimble/host/src/ble_sm.c
@@ -505,8 +505,8 @@ ble_sm_peer_addr(struct ble_sm_proc *proc,
         return BLE_HS_ENOTCONN;
     }
 
-    *out_type = conn->bhc_addr_type;
-    *out_addr = conn->bhc_addr;
+    *out_type = conn->bhc_peer_addr_type;
+    *out_addr = conn->bhc_peer_addr;
 
     return 0;
 }
@@ -562,8 +562,8 @@ ble_sm_persist_keys(struct ble_sm_proc *proc)
         peer_addr_type = proc->peer_keys.addr_type;
         memcpy(peer_addr, proc->peer_keys.addr, sizeof peer_addr);
     } else {
-        peer_addr_type = ble_hs_misc_addr_type_to_id(conn->bhc_addr_type);
-        memcpy(peer_addr, conn->bhc_addr, sizeof peer_addr);
+        peer_addr_type = ble_hs_misc_addr_type_to_id(conn->bhc_peer_addr_type);
+        memcpy(peer_addr, conn->bhc_peer_addr, sizeof peer_addr);
     }
 
     ble_hs_unlock();
@@ -1703,15 +1703,16 @@ ble_sm_key_exch_exec(struct ble_sm_proc *proc, struct ble_sm_result *res,
                      void *arg)
 {
     struct ble_sm_id_addr_info addr_info;
+    struct ble_hs_conn_addrs addrs;
     struct ble_sm_sign_info sign_info;
     struct ble_sm_master_id master_id;
     struct ble_sm_enc_info enc_info;
     struct ble_sm_id_info id_info;
+    struct ble_hs_conn *conn;
     uint8_t init_key_dist;
     uint8_t resp_key_dist;
     uint8_t our_key_dist;
-    uint8_t *our_id_addr;
-    uint8_t *irk;
+    const uint8_t *irk;
     int rc;
 
     ble_sm_key_dist(proc, &init_key_dist, &resp_key_dist);
@@ -1754,7 +1755,10 @@ ble_sm_key_exch_exec(struct ble_sm_proc *proc, struct ble_sm_result *res,
 
     if (our_key_dist & BLE_SM_PAIR_KEY_DIST_ID) {
         /* Send identity information. */
-        irk = ble_hs_pvcy_our_irk();
+        rc = ble_hs_pvcy_our_irk(&irk);
+        if (rc != 0) {
+            goto err;
+        }
 
         memcpy(id_info.irk, irk, 16);
 
@@ -1765,8 +1769,15 @@ ble_sm_key_exch_exec(struct ble_sm_proc *proc, struct ble_sm_result *res,
         proc->our_keys.irk_valid = 1;
 
         /* Send identity address information. */
-        our_id_addr = ble_hs_pvcy_our_id_addr(&addr_info.addr_type);
-        memcpy(addr_info.bd_addr, our_id_addr, 6);
+        conn = ble_hs_conn_find(proc->conn_handle);
+        if (conn == NULL) {
+            rc = BLE_HS_ENOTCONN;
+            goto err;
+        }
+
+        ble_hs_conn_addrs(conn, &addrs);
+        addr_info.addr_type = addrs.our_id_addr_type;
+        memcpy(addr_info.bd_addr, addrs.our_id_addr, 6);
         rc = ble_sm_id_addr_info_tx(proc->conn_handle, &addr_info);
         if (rc != 0) {
             goto err;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7efbf0ee/net/nimble/host/src/ble_sm_alg.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_sm_alg.c b/net/nimble/host/src/ble_sm_alg.c
index 1885d09..b8e8530 100644
--- a/net/nimble/host/src/ble_sm_alg.c
+++ b/net/nimble/host/src/ble_sm_alg.c
@@ -69,7 +69,7 @@ static const uint8_t ble_sm_alg_dbg_f6[16] = {
 };
 
 static void
-ble_sm_alg_log_buf(char *name, uint8_t *buf, int len)
+ble_sm_alg_log_buf(const char *name, const uint8_t *buf, int len)
 {
     BLE_HS_LOG(DEBUG, "    %s=", name);
     ble_hs_misc_log_flat_buf(buf, len);
@@ -362,9 +362,10 @@ ble_sm_alg_f5(uint8_t *w, uint8_t *n1, uint8_t *n2, uint8_t a1t,
 }
 
 int
-ble_sm_alg_f6(uint8_t *w, uint8_t *n1, uint8_t *n2, uint8_t *r,
-              uint8_t *iocap, uint8_t a1t, uint8_t *a1,
-              uint8_t a2t, uint8_t *a2, uint8_t *check)
+ble_sm_alg_f6(const uint8_t *w, const uint8_t *n1, const uint8_t *n2,
+              const uint8_t *r, const uint8_t *iocap, uint8_t a1t,
+              const uint8_t *a1, uint8_t a2t, const uint8_t *a2,
+              uint8_t *check)
 {
     uint8_t ws[16];
     uint8_t m[65];

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7efbf0ee/net/nimble/host/src/ble_sm_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_sm_priv.h b/net/nimble/host/src/ble_sm_priv.h
index 71af1a3..95b312b 100644
--- a/net/nimble/host/src/ble_sm_priv.h
+++ b/net/nimble/host/src/ble_sm_priv.h
@@ -386,9 +386,10 @@ int ble_sm_alg_g2(uint8_t *u, uint8_t *v, uint8_t *x, uint8_t *y,
 int ble_sm_alg_f5(uint8_t *w, uint8_t *n1, uint8_t *n2, uint8_t a1t,
                   uint8_t *a1, uint8_t a2t, uint8_t *a2,
                   uint8_t *mackey, uint8_t *ltk);
-int ble_sm_alg_f6(uint8_t *w, uint8_t *n1, uint8_t *n2, uint8_t *r,
-                  uint8_t *iocap, uint8_t a1t, uint8_t *a1,
-                  uint8_t a2t, uint8_t *a2, uint8_t *check);
+int ble_sm_alg_f6(const uint8_t *w, const uint8_t *n1, const uint8_t *n2,
+                  const uint8_t *r, const uint8_t *iocap, uint8_t a1t,
+                  const uint8_t *a1, uint8_t a2t, const uint8_t *a2,
+                  uint8_t *check);
 int ble_sm_alg_gen_dhkey(uint8_t *peer_pub_key_x, uint8_t *peer_pub_key_y,
                          uint32_t *our_priv_key, void *out_dhkey);
 int ble_sm_alg_gen_key_pair(void *pub, uint32_t *priv);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7efbf0ee/net/nimble/host/src/ble_sm_sc.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_sm_sc.c b/net/nimble/host/src/ble_sm_sc.c
index fc56804..d98c93b 100644
--- a/net/nimble/host/src/ble_sm_sc.c
+++ b/net/nimble/host/src/ble_sm_sc.c
@@ -534,9 +534,9 @@ ble_sm_sc_public_key_rx(uint16_t conn_handle, uint8_t op, struct os_mbuf **om,
 static int
 ble_sm_sc_dhkey_addrs(struct ble_sm_proc *proc,
                       uint8_t *out_our_id_addr_type,
-                      uint8_t **out_our_ota_addr,
+                      const uint8_t **out_our_ota_addr,
                       uint8_t *out_peer_id_addr_type,
-                      uint8_t **out_peer_ota_addr)
+                      const uint8_t **out_peer_ota_addr)
 {
     struct ble_hs_conn_addrs addrs;
     struct ble_hs_conn *conn;
@@ -569,8 +569,8 @@ ble_sm_sc_dhkey_check_exec(struct ble_sm_proc *proc, struct ble_sm_result *res,
                            void *arg)
 {
     struct ble_sm_dhkey_check cmd;
-    uint8_t *our_ota_addr;
-    uint8_t *peer_ota_addr;
+    const uint8_t *our_ota_addr;
+    const uint8_t *peer_ota_addr;
     uint8_t peer_id_addr_type;
     uint8_t our_id_addr_type;
     uint8_t iocap[3];
@@ -621,8 +621,8 @@ ble_sm_dhkey_check_process(struct ble_sm_proc *proc,
                            struct ble_sm_result *res)
 {
     uint8_t exp_value[16];
-    uint8_t *peer_ota_addr;
-    uint8_t *our_ota_addr;
+    const uint8_t *peer_ota_addr;
+    const uint8_t *our_ota_addr;
     uint8_t peer_id_addr_type;
     uint8_t our_id_addr_type;
     uint8_t iocap[3];

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7efbf0ee/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 bb08bd0..43a0269 100644
--- a/net/nimble/host/src/test/ble_gap_test.c
+++ b/net/nimble/host/src/test/ble_gap_test.c
@@ -70,6 +70,7 @@ static void
 ble_gap_test_util_init(void)
 {
     ble_hs_test_util_init();
+    ble_hs_test_util_set_static_rnd_addr();
     ble_gap_test_util_reset_cb_info();
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7efbf0ee/net/nimble/host/src/test/ble_hs_conn_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_hs_conn_test.c b/net/nimble/host/src/test/ble_hs_conn_test.c
index fcab787..02eba78 100644
--- a/net/nimble/host/src/test/ble_hs_conn_test.c
+++ b/net/nimble/host/src/test/ble_hs_conn_test.c
@@ -77,7 +77,7 @@ TEST_CASE(ble_hs_conn_test_direct_connect_success)
     conn = ble_hs_conn_first();
     TEST_ASSERT_FATAL(conn != NULL);
     TEST_ASSERT(conn->bhc_handle == 2);
-    TEST_ASSERT(memcmp(conn->bhc_addr, addr, 6) == 0);
+    TEST_ASSERT(memcmp(conn->bhc_peer_addr, addr, 6) == 0);
 
     chan = ble_hs_conn_chan_find(conn, BLE_L2CAP_CID_ATT);
     TEST_ASSERT_FATAL(chan != NULL);
@@ -131,7 +131,7 @@ TEST_CASE(ble_hs_conn_test_direct_connectable_success)
     conn = ble_hs_conn_first();
     TEST_ASSERT_FATAL(conn != NULL);
     TEST_ASSERT(conn->bhc_handle == 2);
-    TEST_ASSERT(memcmp(conn->bhc_addr, addr, 6) == 0);
+    TEST_ASSERT(memcmp(conn->bhc_peer_addr, addr, 6) == 0);
 
     chan = ble_hs_conn_chan_find(conn, BLE_L2CAP_CID_ATT);
     TEST_ASSERT_FATAL(chan != NULL);
@@ -191,7 +191,7 @@ TEST_CASE(ble_hs_conn_test_undirect_connectable_success)
     conn = ble_hs_conn_first();
     TEST_ASSERT_FATAL(conn != NULL);
     TEST_ASSERT(conn->bhc_handle == 2);
-    TEST_ASSERT(memcmp(conn->bhc_addr, addr, 6) == 0);
+    TEST_ASSERT(memcmp(conn->bhc_peer_addr, addr, 6) == 0);
 
     chan = ble_hs_conn_chan_find(conn, BLE_L2CAP_CID_ATT);
     TEST_ASSERT_FATAL(chan != NULL);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7efbf0ee/net/nimble/host/src/test/ble_hs_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_hs_test.c b/net/nimble/host/src/test/ble_hs_test.c
index 5b38bb8..feabb72 100644
--- a/net/nimble/host/src/test/ble_hs_test.c
+++ b/net/nimble/host/src/test/ble_hs_test.c
@@ -24,7 +24,7 @@
 #include "ble_hs_test_util.h"
 
 /* Our global device address. */
-uint8_t g_dev_addr[BLE_DEV_ADDR_LEN];
+uint8_t g_dev_addr[BLE_DEV_ADDR_LEN] = { 0x0a, 0x54, 0xab, 0x49, 0x7f, 0x06 };
 
 void
 ble_hs_test_pkt_txed(struct os_mbuf *om)

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7efbf0ee/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 e2040ae..fe701d8 100644
--- a/net/nimble/host/src/test/ble_hs_test_util.c
+++ b/net/nimble/host/src/test/ble_hs_test_util.c
@@ -25,6 +25,7 @@
 #include "nimble/hci_common.h"
 #include "nimble/hci_transport.h"
 #include "host/ble_hs_adv.h"
+#include "host/ble_hs_id.h"
 #include "host/host_hci.h"
 #include "ble_hs_test_util.h"
 
@@ -866,12 +867,6 @@ ble_hs_test_util_tx_all(void)
 }
 
 void
-ble_hs_test_util_set_public_addr(uint8_t *addr)
-{
-    ble_hs_pvcy_set_our_id_addr(addr);
-}
-
-void
 ble_hs_test_util_verify_tx_exec_write(uint8_t expected_flags)
 {
     struct ble_att_exec_write_req req;
@@ -913,6 +908,21 @@ ble_hs_test_util_verify_tx_read_rsp(uint8_t *attr_data, int attr_len)
 }
 
 void
+ble_hs_test_util_set_static_rnd_addr(void)
+{
+    uint8_t addr[6] = { 1, 2, 3, 4, 5, 0xc1 };
+    int rc;
+
+    ble_hs_test_util_set_ack(
+        BLE_HS_TEST_UTIL_LE_OPCODE(BLE_HCI_OCF_LE_SET_RAND_ADDR), 0);
+
+    rc = ble_hs_id_set_rnd(addr);
+    TEST_ASSERT_FATAL(rc == 0);
+
+    ble_hs_test_util_get_first_hci_tx();
+}
+
+void
 ble_hs_test_util_init(void)
 {
     struct ble_hs_cfg cfg;
@@ -952,5 +962,5 @@ ble_hs_test_util_init(void)
 
     ble_hs_test_util_prev_hci_tx_clear();
 
-    ble_hs_test_util_set_public_addr(g_dev_addr);
+    ble_hs_id_set_pub(g_dev_addr);
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7efbf0ee/net/nimble/host/src/test/ble_hs_test_util.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_hs_test_util.h b/net/nimble/host/src/test/ble_hs_test_util.h
index 0a7c4e3..d54c8aa 100644
--- a/net/nimble/host/src/test/ble_hs_test_util.h
+++ b/net/nimble/host/src/test/ble_hs_test_util.h
@@ -115,9 +115,9 @@ void ble_hs_test_util_rx_disconn_complete_event(
 uint8_t *ble_hs_test_util_verify_tx_hci(uint8_t ogf, uint16_t ocf,
                                         uint8_t *out_param_len);
 void ble_hs_test_util_tx_all(void);
-void ble_hs_test_util_set_public_addr(uint8_t *addr);
 void ble_hs_test_util_verify_tx_exec_write(uint8_t expected_flags);
 void ble_hs_test_util_verify_tx_read_rsp(uint8_t *attr_data, int attr_len);
+void ble_hs_test_util_set_static_rnd_addr(void);
 void ble_hs_test_util_init(void);
 
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7efbf0ee/net/nimble/host/src/test/ble_sm_test_util.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_sm_test_util.c b/net/nimble/host/src/test/ble_sm_test_util.c
index 1cc8af9..524e8f1 100644
--- a/net/nimble/host/src/test/ble_sm_test_util.c
+++ b/net/nimble/host/src/test/ble_sm_test_util.c
@@ -26,6 +26,7 @@
 #include "host/host_hci.h"
 #include "host/ble_sm.h"
 #include "host/ble_hs_test.h"
+#include "host/ble_hs_id.h"
 #include "ble_hs_test_util.h"
 #include "ble_sm_test_util.h"
 
@@ -223,7 +224,7 @@ ble_sm_test_util_init_good(struct ble_sm_test_params *params,
         ble_hs_cfg.sm_their_key_dist = out_us->pair_cmd->init_key_dist;
     }
 
-    ble_hs_test_util_set_public_addr(out_us->id_addr);
+    ble_hs_id_set_pub(out_us->id_addr);
     ble_sm_dbg_set_next_pair_rand(out_us->randoms[0].value);
     ble_sm_dbg_set_next_ediv(out_us->ediv);
     ble_sm_dbg_set_next_master_id_rand(out_us->rand_num);
@@ -797,10 +798,14 @@ ble_sm_test_util_verify_tx_id_addr_info(struct ble_sm_id_addr_info *exp_cmd)
 {
     struct ble_sm_id_addr_info cmd;
     struct os_mbuf *om;
-    uint8_t *our_id_addr;
-    uint8_t our_id_addr_type;
+    const uint8_t *our_id_addr;
+    int rc;
+
+    ble_hs_lock();
+    rc = ble_hs_id_addr(exp_cmd->addr_type, &our_id_addr, NULL);
+    ble_hs_unlock();
 
-    our_id_addr = ble_hs_pvcy_our_id_addr(&our_id_addr_type);
+    TEST_ASSERT_FATAL(rc == 0);
 
     ble_hs_test_util_tx_all();
     om = ble_sm_test_util_verify_tx_hdr(BLE_SM_OP_IDENTITY_ADDR_INFO,
@@ -809,8 +814,6 @@ ble_sm_test_util_verify_tx_id_addr_info(struct ble_sm_id_addr_info *exp_cmd)
 
     TEST_ASSERT(cmd.addr_type == exp_cmd->addr_type);
     TEST_ASSERT(memcmp(cmd.bd_addr, exp_cmd->bd_addr, 6) == 0);
-
-    TEST_ASSERT(cmd.addr_type == our_id_addr_type);
     TEST_ASSERT(memcmp(cmd.bd_addr, our_id_addr, 6) == 0);
 }
 
@@ -1405,7 +1408,7 @@ ble_sm_test_util_peer_fail_inval(
     struct ble_hs_conn *conn;
 
     ble_sm_test_util_init();
-    ble_hs_test_util_set_public_addr(resp_addr);
+    ble_hs_id_set_pub(resp_addr);
 
     ble_hs_test_util_create_conn(2, init_id_addr, ble_sm_test_util_conn_cb,
                                  NULL);
@@ -1462,7 +1465,7 @@ ble_sm_test_util_peer_lgcy_fail_confirm(
     struct ble_hs_conn *conn;
 
     ble_sm_test_util_init();
-    ble_hs_test_util_set_public_addr(resp_addr);
+    ble_hs_id_set_pub(resp_addr);
     ble_sm_dbg_set_next_pair_rand(random_rsp->value);
 
     ble_hs_test_util_create_conn(2, init_id_addr, ble_sm_test_util_conn_cb,
@@ -2329,7 +2332,7 @@ ble_sm_test_util_us_fail_inval(struct ble_sm_test_params *params)
     int rc;
 
     ble_sm_test_util_init();
-    ble_hs_test_util_set_public_addr(params->resp_id_addr);
+    ble_hs_id_set_pub(params->resp_id_addr);
 
     ble_sm_dbg_set_next_pair_rand(((uint8_t[16]){0}));
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7efbf0ee/net/nimble/include/nimble/ble.h
----------------------------------------------------------------------
diff --git a/net/nimble/include/nimble/ble.h b/net/nimble/include/nimble/ble.h
index ec030f5..1607eb8 100644
--- a/net/nimble/include/nimble/ble.h
+++ b/net/nimble/include/nimble/ble.h
@@ -150,7 +150,7 @@ uint16_t be16toh(const void *buf);
 uint32_t be32toh(const void *buf);
 uint64_t be64toh(const void *buf);
 void swap_in_place(void *buf, int len);
-void swap_buf(uint8_t *dst, uint8_t *src, int len);
+void swap_buf(uint8_t *dst, const uint8_t *src, int len);
 /* XXX */
 
 /* BLE Error Codes (Core v4.2 Vol 2 part D) */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7efbf0ee/net/nimble/src/util.c
----------------------------------------------------------------------
diff --git a/net/nimble/src/util.c b/net/nimble/src/util.c
index 9d65002..9aef110 100644
--- a/net/nimble/src/util.c
+++ b/net/nimble/src/util.c
@@ -208,7 +208,7 @@ swap_in_place(void *buf, int len)
 
 /* swap octets */
 void
-swap_buf(uint8_t *dst, uint8_t *src, int len)
+swap_buf(uint8_t *dst, const uint8_t *src, int len)
 {
     int i;
 


[11/50] [abbrv] incubator-mynewt-core git commit: bletiny - Account for addition of adv. duration.

Posted by cc...@apache.org.
bletiny - Account for addition of adv. duration.


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

Branch: refs/heads/ble_hs_api
Commit: 2c37b7b2bcd15cb4671ad570c2f3ec8a63120a38
Parents: b92ddcd
Author: Christopher Collins <cc...@apache.org>
Authored: Thu Jun 23 16:28:19 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Jul 11 16:43:31 2016 -0700

----------------------------------------------------------------------
 apps/bletiny/src/bletiny.h |  2 +-
 apps/bletiny/src/cmd.c     | 15 ++++++++++++++-
 apps/bletiny/src/main.c    | 12 ++++++++----
 3 files changed, 23 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2c37b7b2/apps/bletiny/src/bletiny.h
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/bletiny.h b/apps/bletiny/src/bletiny.h
index 9694744..e70effd 100644
--- a/apps/bletiny/src/bletiny.h
+++ b/apps/bletiny/src/bletiny.h
@@ -155,7 +155,7 @@ int bletiny_write_long(uint16_t conn_handle, uint16_t attr_handle,
 int bletiny_write_reliable(uint16_t conn_handle, struct ble_gatt_attr *attrs,
                             int num_attrs);
 int bletiny_adv_start(uint8_t own_addr_type, uint8_t peer_addr_type,
-                      const uint8_t *peer_addr,
+                      const uint8_t *peer_addr, int32_t duration_ms,
                       const struct ble_gap_adv_params *params);
 int bletiny_adv_stop(void);
 int bletiny_conn_initiate(uint8_t own_addr_type,

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2c37b7b2/apps/bletiny/src/cmd.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/cmd.c b/apps/bletiny/src/cmd.c
index c6f2019..18cf51d 100644
--- a/apps/bletiny/src/cmd.c
+++ b/apps/bletiny/src/cmd.c
@@ -260,6 +260,7 @@ static int
 cmd_adv(int argc, char **argv)
 {
     struct ble_gap_adv_params params;
+    int32_t duration_ms;
     uint8_t peer_addr_type;
     uint8_t own_addr_type;
     uint8_t peer_addr[8];
@@ -332,7 +333,19 @@ cmd_adv(int argc, char **argv)
         return rc;
     }
 
-    rc = bletiny_adv_start(own_addr_type, peer_addr_type, peer_addr, &params);
+    params.high_duty_cycle = parse_arg_long_bounds_default("hd", 0, 1, 0, &rc);
+    if (rc != 0) {
+        return rc;
+    }
+
+    duration_ms = parse_arg_long_bounds_default("dur", 1, INT32_MAX,
+                                                BLE_HS_FOREVER, &rc);
+    if (rc != 0) {
+        return rc;
+    }
+
+    rc = bletiny_adv_start(own_addr_type, peer_addr_type, peer_addr,
+                           duration_ms, &params);
     if (rc != 0) {
         console_printf("advertise fail: %d\n", rc);
         return rc;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2c37b7b2/apps/bletiny/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/main.c b/apps/bletiny/src/main.c
index c4b2856..d8b1912 100755
--- a/apps/bletiny/src/main.c
+++ b/apps/bletiny/src/main.c
@@ -891,7 +891,6 @@ bletiny_gap_event(int event, struct ble_gap_conn_ctxt *ctxt, void *arg)
 
     switch (event) {
     case BLE_GAP_EVENT_CONNECT:
-        
         console_printf("connection %s; status=%d ",
                        ctxt->connect.status == 0 ? "established" : "failed",
                        ctxt->connect.status);
@@ -912,6 +911,10 @@ bletiny_gap_event(int event, struct ble_gap_conn_ctxt *ctxt, void *arg)
         }
         return 0;
 
+    case BLE_GAP_EVENT_ADV_COMPLETE:
+        console_printf("advertising complete.\n");
+        return 0;
+
     case BLE_GAP_EVENT_CONN_CANCEL:
         console_printf("connection procedure cancelled.\n");
         return 0;
@@ -953,6 +956,7 @@ bletiny_gap_event(int event, struct ble_gap_conn_ctxt *ctxt, void *arg)
         print_bytes(ctxt->notify.attr_data, ctxt->notify.attr_len);
         console_printf("\n");
         return 0;
+
     default:
         return 0;
     }
@@ -1247,13 +1251,13 @@ bletiny_adv_stop(void)
 
 int
 bletiny_adv_start(uint8_t own_addr_type, uint8_t peer_addr_type,
-                  const uint8_t *peer_addr,
+                  const uint8_t *peer_addr, int32_t duration_ms,
                   const struct ble_gap_adv_params *params)
 {
     int rc;
 
-    rc = ble_gap_adv_start(own_addr_type, peer_addr_type, peer_addr, params,
-                           bletiny_gap_event, NULL);
+    rc = ble_gap_adv_start(own_addr_type, peer_addr_type, peer_addr,
+                           duration_ms, params, bletiny_gap_event, NULL);
     return rc;
 }
 


[44/50] [abbrv] incubator-mynewt-core git commit: bletiny/bleprph - Use new GAP event callback API.

Posted by cc...@apache.org.
bletiny/bleprph - Use new GAP event callback API.


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

Branch: refs/heads/ble_hs_api
Commit: 1c8a135fa2cc1225afe80e1674cdcf33772d9253
Parents: 27445b8
Author: Christopher Collins <cc...@apache.org>
Authored: Thu Jul 7 13:44:58 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Jul 11 16:43:34 2016 -0700

----------------------------------------------------------------------
 apps/bleprph/src/main.c    |  27 +++---
 apps/bletiny/src/bletiny.h |   3 +-
 apps/bletiny/src/cmd.c     |  32 +++++--
 apps/bletiny/src/main.c    | 184 +++++++++++++++++++++++-----------------
 apps/bletiny/src/parse.c   |  16 ++++
 5 files changed, 161 insertions(+), 101 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1c8a135f/apps/bleprph/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bleprph/src/main.c b/apps/bleprph/src/main.c
index 9e3a9b5..f73f2bf 100755
--- a/apps/bleprph/src/main.c
+++ b/apps/bleprph/src/main.c
@@ -86,8 +86,7 @@ uint8_t bleprph_reconnect_addr[6];
 uint8_t bleprph_pref_conn_params[8];
 uint8_t bleprph_gatt_service_changed[4];
 
-static int bleprph_gap_event(int event, struct ble_gap_event_ctxt *ctxt,
-                             void *arg);
+static int bleprph_gap_event(struct ble_gap_event *event, void *arg);
 
 /**
  * Logs information about a connection to the console.
@@ -193,26 +192,26 @@ bleprph_advertise(void)
  *                                  particular GAP event being signalled.
  */
 static int
-bleprph_gap_event(int event, struct ble_gap_event_ctxt *ctxt, void *arg)
+bleprph_gap_event(struct ble_gap_event *event, void *arg)
 {
-    switch (event) {
+    switch (event->type) {
     case BLE_GAP_EVENT_CONNECT:
         /* A new connection was established or a connection attempt failed. */
         BLEPRPH_LOG(INFO, "connection %s; status=%d ",
-                       ctxt->connect.status == 0 ? "established" : "failed",
-                       ctxt->connect.status);
-        bleprph_print_conn_desc(ctxt->desc);
+                       event->connect.status == 0 ? "established" : "failed",
+                       event->connect.status);
+        bleprph_print_conn_desc(&event->connect.conn);
         BLEPRPH_LOG(INFO, "\n");
 
-        if (ctxt->connect.status != 0) {
+        if (event->connect.status != 0) {
             /* Connection failed; resume advertising. */
             bleprph_advertise();
         }
         return 0;
 
     case BLE_GAP_EVENT_DISCONNECT:
-        BLEPRPH_LOG(INFO, "disconnect; reason=%d ", ctxt->disconnect.reason);
-        bleprph_print_conn_desc(ctxt->desc);
+        BLEPRPH_LOG(INFO, "disconnect; reason=%d ", event->disconnect.reason);
+        bleprph_print_conn_desc(&event->disconnect.conn);
         BLEPRPH_LOG(INFO, "\n");
 
         /* Connection terminated; resume advertising. */
@@ -222,16 +221,16 @@ bleprph_gap_event(int event, struct ble_gap_event_ctxt *ctxt, void *arg)
     case BLE_GAP_EVENT_CONN_UPDATE:
         /* The central has updated the connection parameters. */
         BLEPRPH_LOG(INFO, "connection updated; status=%d ",
-                    ctxt->conn_update.status);
-        bleprph_print_conn_desc(ctxt->desc);
+                    event->conn_update.status);
+        bleprph_print_conn_desc(&event->conn_update.conn);
         BLEPRPH_LOG(INFO, "\n");
         return 0;
 
     case BLE_GAP_EVENT_ENC_CHANGE:
         /* Encryption has been enabled or disabled for this connection. */
         BLEPRPH_LOG(INFO, "encryption change event; status=%d ",
-                    ctxt->enc_change.status);
-        bleprph_print_conn_desc(ctxt->desc);
+                    event->enc_change.status);
+        bleprph_print_conn_desc(&event->enc_change.conn);
         BLEPRPH_LOG(INFO, "\n");
         return 0;
     }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1c8a135f/apps/bletiny/src/bletiny.h
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/bletiny.h b/apps/bletiny/src/bletiny.h
index d6051bf..95a0706 100644
--- a/apps/bletiny/src/bletiny.h
+++ b/apps/bletiny/src/bletiny.h
@@ -106,6 +106,7 @@ long parse_arg_long(char *name, int *staus);
 uint8_t parse_arg_bool(char *name, int *status);
 uint8_t parse_arg_bool_default(char *name, uint8_t dflt, int *out_status);
 uint8_t parse_arg_uint8(char *name, int *status);
+uint8_t parse_arg_uint8_dflt(char *name, uint8_t dflt, int *out_status);
 uint16_t parse_arg_uint16(char *name, int *status);
 uint16_t parse_arg_uint16_dflt(char *name, uint16_t dflt, int *out_status);
 uint32_t parse_arg_uint32(char *name, int *out_status);
@@ -161,7 +162,7 @@ int bletiny_conn_initiate(uint8_t own_addr_type,
                           uint8_t peer_addr_type, uint8_t *peer_addr,
                           struct ble_gap_conn_params *params);
 int bletiny_conn_cancel(void);
-int bletiny_term_conn(uint16_t conn_handle);
+int bletiny_term_conn(uint16_t conn_handle, uint8_t reason);
 int bletiny_wl_set(struct ble_gap_white_entry *white_list,
                     int white_list_count);
 int bletiny_scan(uint8_t own_addr_type, int32_t duration_ms,

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1c8a135f/apps/bletiny/src/cmd.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/cmd.c b/apps/bletiny/src/cmd.c
index eee8f22..6043aeb 100644
--- a/apps/bletiny/src/cmd.c
+++ b/apps/bletiny/src/cmd.c
@@ -29,6 +29,7 @@
 #include "host/ble_hs_adv.h"
 #include "host/ble_sm.h"
 #include "host/ble_eddystone.h"
+#include "host/ble_hs_id.h"
 #include "../src/ble_l2cap_priv.h"
 #include "../src/ble_hs_priv.h"
 
@@ -1004,13 +1005,24 @@ cmd_scan(int argc, char **argv)
 static int
 cmd_show_addr(int argc, char **argv)
 {
-    uint8_t *id_addr;
-    uint8_t id_addr_type;
+    uint8_t id_addr[6];
+    int rc;
 
-    id_addr = ble_hs_pvcy_our_id_addr(&id_addr_type);
+    console_printf("public_id_addr=");
+    rc = ble_hs_id_copy_addr(BLE_ADDR_TYPE_PUBLIC, id_addr, NULL);
+    if (rc == 0) {
+        print_addr(id_addr);
+    } else {
+        console_printf("none");
+    }
 
-    console_printf("id_addr_type=%d id_addr=", id_addr_type);
-    print_addr(id_addr);
+    console_printf(" random_id_addr=");
+    rc = ble_hs_id_copy_addr(BLE_ADDR_TYPE_RANDOM, id_addr, NULL);
+    if (rc == 0) {
+        print_addr(id_addr);
+    } else {
+        console_printf("none");
+    }
     console_printf("\n");
 
     return 0;
@@ -1576,7 +1588,7 @@ cmd_set(int argc, char **argv)
          * needs to be removed.
          */
         memcpy(g_dev_addr, addr, 6);
-        ble_gap_init_identity_addr(g_dev_addr);
+        ble_hs_id_set_pub(g_dev_addr);
     } else if (rc != ENOENT) {
         return rc;
     }
@@ -1615,6 +1627,7 @@ static int
 cmd_term(int argc, char **argv)
 {
     uint16_t conn_handle;
+    uint8_t reason;
     int rc;
 
     conn_handle = parse_arg_uint16("conn", &rc);
@@ -1622,7 +1635,12 @@ cmd_term(int argc, char **argv)
         return rc;
     }
 
-    rc = bletiny_term_conn(conn_handle);
+    reason = parse_arg_uint8_dflt("reason", BLE_ERR_REM_USER_CONN_TERM, &rc);
+    if (rc != 0) {
+        return rc;
+    }
+
+    rc = bletiny_term_conn(conn_handle, reason);
     if (rc != 0) {
         console_printf("error terminating connection; rc=%d\n", rc);
         return rc;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1c8a135f/apps/bletiny/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/main.c b/apps/bletiny/src/main.c
index 02f8566..b8a1fbe 100755
--- a/apps/bletiny/src/main.c
+++ b/apps/bletiny/src/main.c
@@ -51,8 +51,8 @@
  * app uses some of nimble's internal details for logging.
  */
 #include "../src/ble_hs_conn_priv.h"
-#include "../src/ble_hci_util_priv.h"
 #include "../src/ble_hs_atomic_priv.h"
+#include "../src/ble_hci_priv.h"
 
 #define BSWAP16(x)  ((uint16_t)(((x) << 8) | (((x) & 0xff00) >> 8)))
 
@@ -679,11 +679,15 @@ static int
 bletiny_on_mtu(uint16_t conn_handle, const struct ble_gatt_error *error,
                uint16_t mtu, void *arg)
 {
-    if (error != NULL) {
-        bletiny_print_error(NULL, conn_handle, error);
-    } else {
+    switch (error->status) {
+    case 0:
         console_printf("mtu exchange complete: conn_handle=%d mtu=%d\n",
                        conn_handle, mtu);
+        break;
+
+    default:
+        bletiny_print_error(NULL, conn_handle, error);
+        break;
     }
 
     return 0;
@@ -769,15 +773,21 @@ static int
 bletiny_on_disc_s(uint16_t conn_handle, const struct ble_gatt_error *error,
                   const struct ble_gatt_svc *service, void *arg)
 {
-    if (error != NULL) {
-        bletiny_print_error(NULL, conn_handle, error);
-    } else if (service != NULL) {
+    switch (error->status) {
+    case 0:
         bletiny_svc_add(conn_handle, service);
-    } else {
+        break;
+
+    case BLE_HS_EDONE:
         console_printf("service discovery successful\n");
         if (bletiny_full_disc_prev_chr_def > 0) {
             bletiny_disc_full_chrs(conn_handle);
         }
+        break;
+
+    default:
+        bletiny_print_error(NULL, conn_handle, error);
+        break;
     }
 
     return 0;
@@ -791,15 +801,21 @@ bletiny_on_disc_c(uint16_t conn_handle, const struct ble_gatt_error *error,
 
     svc_start_handle = (intptr_t)arg;
 
-    if (error != NULL) {
-        bletiny_print_error(NULL, conn_handle, error);
-    } else if (chr != NULL) {
+    switch (error->status) {
+    case 0:
         bletiny_chr_add(conn_handle, svc_start_handle, chr);
-    } else {
+        break;
+
+    case BLE_HS_EDONE:
         console_printf("characteristic discovery successful\n");
         if (bletiny_full_disc_prev_chr_def > 0) {
             bletiny_disc_full_chrs(conn_handle);
         }
+        break;
+
+    default:
+        bletiny_print_error(NULL, conn_handle, error);
+        break;
     }
 
     return 0;
@@ -810,15 +826,21 @@ bletiny_on_disc_d(uint16_t conn_handle, const struct ble_gatt_error *error,
                   uint16_t chr_def_handle, const struct ble_gatt_dsc *dsc,
                   void *arg)
 {
-    if (error != NULL) {
-        bletiny_print_error(NULL, conn_handle, error);
-    } else if (dsc != NULL) {
+    switch (error->status) {
+    case 0:
         bletiny_dsc_add(conn_handle, chr_def_handle, dsc);
-    } else {
+        break;
+
+    case BLE_HS_EDONE:
         console_printf("descriptor discovery successful\n");
         if (bletiny_full_disc_prev_chr_def > 0) {
             bletiny_disc_full_dscs(conn_handle);
         }
+        break;
+
+    default:
+        bletiny_print_error(NULL, conn_handle, error);
+        break;
     }
 
     return 0;
@@ -828,16 +850,22 @@ static int
 bletiny_on_read(uint16_t conn_handle, const struct ble_gatt_error *error,
                 const struct ble_gatt_attr *attr, void *arg)
 {
-    if (error != NULL) {
-        bletiny_print_error(NULL, conn_handle, error);
-    } else if (attr != NULL) {
+    switch (error->status) {
+    case 0:
         console_printf("characteristic read; conn_handle=%d "
                        "attr_handle=%d len=%d value=", conn_handle,
                        attr->handle, attr->value_len);
         print_bytes(attr->value, attr->value_len);
         console_printf("\n");
-    } else {
+        break;
+
+    case BLE_HS_EDONE:
         console_printf("characteristic read complete\n");
+        break;
+
+    default:
+        bletiny_print_error(NULL, conn_handle, error);
+        break;
     }
 
     return 0;
@@ -845,16 +873,20 @@ bletiny_on_read(uint16_t conn_handle, const struct ble_gatt_error *error,
 
 static int
 bletiny_on_write(uint16_t conn_handle, const struct ble_gatt_error *error,
-                  const struct ble_gatt_attr *attr, void *arg)
+                 const struct ble_gatt_attr *attr, void *arg)
 {
-    if (error != NULL) {
-        bletiny_print_error(NULL, conn_handle, error);
-    } else {
+    switch (error->status) {
+    case 0:
         console_printf("characteristic write complete; conn_handle=%d "
                        "attr_handle=%d len=%d value=", conn_handle,
                        attr->handle, attr->value_len);
         print_bytes(attr->value, attr->value_len);
         console_printf("\n");
+        break;
+
+    default:
+        bletiny_print_error(NULL, conn_handle, error);
+        break;
     }
 
     return 0;
@@ -868,9 +900,8 @@ bletiny_on_write_reliable(uint16_t conn_handle,
 {
     int i;
 
-    if (error != NULL) {
-        bletiny_print_error(NULL, conn_handle, error);
-    } else {
+    switch (error->status) {
+    case 0:
         console_printf("characteristic write reliable complete; "
                        "conn_handle=%d", conn_handle);
 
@@ -880,38 +911,60 @@ bletiny_on_write_reliable(uint16_t conn_handle,
             print_bytes(attrs[i].value, attrs[i].value_len);
         }
         console_printf("\n");
+        break;
+
+    default:
+        bletiny_print_error(NULL, conn_handle, error);
+        break;
     }
 
     return 0;
 }
 
 static int
-bletiny_gap_event(int event, struct ble_gap_event_ctxt *ctxt, void *arg)
+bletiny_gap_event(struct ble_gap_event *event, void *arg)
 {
     int conn_idx;
 
-    switch (event) {
+    switch (event->type) {
     case BLE_GAP_EVENT_CONNECT:
         console_printf("connection %s; status=%d ",
-                       ctxt->connect.status == 0 ? "established" : "failed",
-                       ctxt->connect.status);
-        print_conn_desc(ctxt->desc);
+                       event->connect.status == 0 ? "established" : "failed",
+                       event->connect.status);
+        print_conn_desc(&event->connect.conn);
 
-        if (ctxt->connect.status == 0) {
-            bletiny_conn_add(ctxt->desc);
+        if (event->connect.status == 0) {
+            bletiny_conn_add(&event->connect.conn);
         }
         return 0;
 
     case BLE_GAP_EVENT_DISCONNECT:
-        console_printf("disconnect; reason=%d ", ctxt->disconnect.reason);
-        print_conn_desc(ctxt->desc);
+        console_printf("disconnect; reason=%d ", event->disconnect.reason);
+        print_conn_desc(&event->disconnect.conn);
 
-        conn_idx = bletiny_conn_find_idx(ctxt->desc->conn_handle);
+        conn_idx = bletiny_conn_find_idx(event->disconnect.conn.conn_handle);
         if (conn_idx != -1) {
             bletiny_conn_delete_idx(conn_idx);
         }
         return 0;
 
+    case BLE_GAP_EVENT_DISC:
+        console_printf("received advertisement; event_type=%d addr_type=%d "
+                       "addr=", event->disc.event_type,
+                       event->disc.addr_type);
+        print_addr(event->disc.addr);
+        console_printf(" length_data=%d rssi=%d data=",
+                       event->disc.length_data, event->disc.rssi);
+        print_bytes(event->disc.data, event->disc.length_data);
+        console_printf(" fields:\n");
+        bletiny_print_adv_fields(event->disc.fields);
+        console_printf("\n");
+        return 0;
+
+    case BLE_GAP_EVENT_DISC_COMPLETE:
+        console_printf("scanning finished\n");
+        return 0;
+
     case BLE_GAP_EVENT_ADV_COMPLETE:
         console_printf("advertising complete.\n");
         return 0;
@@ -922,39 +975,39 @@ bletiny_gap_event(int event, struct ble_gap_event_ctxt *ctxt, void *arg)
 
     case BLE_GAP_EVENT_CONN_UPDATE:
         console_printf("connection updated; status=%d ",
-                       ctxt->conn_update.status);
-        print_conn_desc(ctxt->desc);
+                       event->conn_update.status);
+        print_conn_desc(&event->conn_update.conn);
         return 0;
 
     case BLE_GAP_EVENT_CONN_UPDATE_REQ:
         console_printf("connection update request\n");
-        *ctxt->conn_update_req.self_params =
-            *ctxt->conn_update_req.peer_params;
+        *event->conn_update_req.self_params =
+            *event->conn_update_req.peer_params;
         return 0;
 
     case BLE_GAP_EVENT_PASSKEY_ACTION:
         console_printf("passkey action event; action=%d",
-                       ctxt->passkey_action.action);
-        if (ctxt->passkey_action.action == BLE_SM_IOACT_NUMCMP) {
+                       event->passkey.params.action);
+        if (event->passkey.params.action == BLE_SM_IOACT_NUMCMP) {
             console_printf(" numcmp=%lu",
-                           (unsigned long)ctxt->passkey_action.numcmp);
+                           (unsigned long)event->passkey.params.numcmp);
         }
         console_printf("\n");
         return 0;
 
     case BLE_GAP_EVENT_ENC_CHANGE:
         console_printf("encryption change event; status=%d ",
-                       ctxt->enc_change.status);
-        print_conn_desc(ctxt->desc);
+                       event->enc_change.status);
+        print_conn_desc(&event->enc_change.conn);
         return 0;
 
     case BLE_GAP_EVENT_NOTIFY:
         console_printf("notification event; attr_handle=%d indication=%d "
                        "len=%d data=",
-                       ctxt->notify.attr_handle, ctxt->notify.indication,
-                       ctxt->notify.attr_len);
+                       event->notify.attr_handle, event->notify.indication,
+                       event->notify.attr_len);
 
-        print_bytes(ctxt->notify.attr_data, ctxt->notify.attr_len);
+        print_bytes(event->notify.attr_data, event->notify.attr_len);
         console_printf("\n");
         return 0;
 
@@ -970,33 +1023,6 @@ bletiny_on_l2cap_update(int status, void *arg)
 }
 
 static void
-bletiny_on_scan(int event, int status, struct ble_gap_disc_desc *desc,
-                void *arg)
-{
-    switch (event) {
-    case BLE_GAP_EVENT_DISC_SUCCESS:
-        console_printf("received advertisement; event_type=%d addr_type=%d "
-                       "addr=", desc->event_type, desc->addr_type);
-        print_addr(desc->addr);
-        console_printf(" length_data=%d rssi=%d data=", desc->length_data,
-                       desc->rssi);
-        print_bytes(desc->data, desc->length_data);
-        console_printf(" fields:\n");
-        bletiny_print_adv_fields(desc->fields);
-        console_printf("\n");
-        break;
-
-    case BLE_GAP_EVENT_DISC_COMPLETE:
-        console_printf("scanning finished; status=%d\n", status);
-        break;
-
-    default:
-        assert(0);
-        break;
-    }
-}
-
-static void
 bletiny_tx_timer_cb(void *arg)
 {
     int i;
@@ -1284,11 +1310,11 @@ bletiny_conn_cancel(void)
 }
 
 int
-bletiny_term_conn(uint16_t conn_handle)
+bletiny_term_conn(uint16_t conn_handle, uint8_t reason)
 {
     int rc;
 
-    rc = ble_gap_terminate(conn_handle);
+    rc = ble_gap_terminate(conn_handle, reason);
     return rc;
 }
 
@@ -1308,7 +1334,7 @@ bletiny_scan(uint8_t own_addr_type, int32_t duration_ms,
     int rc;
 
     rc = ble_gap_disc(own_addr_type, duration_ms, disc_params,
-                      bletiny_on_scan, NULL);
+                      bletiny_gap_event, NULL);
     return rc;
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1c8a135f/apps/bletiny/src/parse.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/parse.c b/apps/bletiny/src/parse.c
index f12ef10..77fdace 100644
--- a/apps/bletiny/src/parse.c
+++ b/apps/bletiny/src/parse.c
@@ -214,6 +214,22 @@ parse_arg_uint64(char *name, int *out_status)
     return parse_arg_uint64_bounds(name, 0, UINT64_MAX, out_status);
 }
 
+uint8_t
+parse_arg_uint8_dflt(char *name, uint8_t dflt, int *out_status)
+{
+    uint8_t val;
+    int rc;
+
+    val = parse_arg_uint8(name, &rc);
+    if (rc == ENOENT) {
+        val = dflt;
+        rc = 0;
+    }
+
+    *out_status = rc;
+    return val;
+}
+
 uint16_t
 parse_arg_uint16_dflt(char *name, uint16_t dflt, int *out_status)
 {


[28/50] [abbrv] incubator-mynewt-core git commit: BLE Host - BLE_HS_ERR_SM_THEM ->BLE_HS_ERR_SM_PEER

Posted by cc...@apache.org.
BLE Host - BLE_HS_ERR_SM_THEM ->BLE_HS_ERR_SM_PEER

This is just a rename.


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

Branch: refs/heads/ble_hs_api
Commit: 0ebad0f9519c921edf4d3ad5b3be9b0c99f0bdf2
Parents: cd4283e
Author: Christopher Collins <cc...@apache.org>
Authored: Tue Jul 5 13:28:29 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Jul 11 16:43:33 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/include/host/ble_hs.h | 4 ++--
 net/nimble/host/src/ble_sm.c          | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0ebad0f9/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 e6a825d..ea06411 100644
--- a/net/nimble/host/include/host/ble_hs.h
+++ b/net/nimble/host/include/host/ble_hs.h
@@ -70,8 +70,8 @@ struct os_event;
 #define BLE_HS_ERR_SM_US_BASE       0x400   /* 1024 */
 #define BLE_HS_SM_US_ERR(x)         ((x) ? BLE_HS_ERR_SM_US_BASE + (x) : 0)
 
-#define BLE_HS_ERR_SM_THEM_BASE     0x500   /* 1280 */
-#define BLE_HS_SM_THEM_ERR(x)       ((x) ? BLE_HS_ERR_SM_THEM_BASE + (x) : 0)
+#define BLE_HS_ERR_SM_PEER_BASE     0x500   /* 1280 */
+#define BLE_HS_SM_PEER_ERR(x)       ((x) ? BLE_HS_ERR_SM_PEER_BASE + (x) : 0)
 
 /* defines the input output (io) capabilities for the host device */
 #define BLE_HS_IO_DISPLAY_ONLY              0x00

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0ebad0f9/net/nimble/host/src/ble_sm.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_sm.c b/net/nimble/host/src/ble_sm.c
index 6b53dce..3f3def0 100644
--- a/net/nimble/host/src/ble_sm.c
+++ b/net/nimble/host/src/ble_sm.c
@@ -2035,7 +2035,7 @@ ble_sm_fail_rx(uint16_t conn_handle, uint8_t op, struct os_mbuf **om,
         ble_sm_pair_fail_parse((*om)->om_data, (*om)->om_len, &cmd);
         BLE_SM_LOG_CMD(0, "fail", conn_handle, ble_sm_pair_fail_log, &cmd);
 
-        res->app_status = BLE_HS_SM_THEM_ERR(cmd.reason);
+        res->app_status = BLE_HS_SM_PEER_ERR(cmd.reason);
     }
 }
 


[03/50] [abbrv] incubator-mynewt-core git commit: bletiny - deal with changes to ble_gap_connect API

Posted by cc...@apache.org.
bletiny - deal with changes to ble_gap_connect API


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

Branch: refs/heads/ble_hs_api
Commit: dba9503b22055f1fb0080b3b8cebb48405bfc03d
Parents: 5f4967d
Author: Christopher Collins <cc...@apache.org>
Authored: Tue Jun 21 20:17:21 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Jul 11 16:43:30 2016 -0700

----------------------------------------------------------------------
 apps/bletiny/src/bletiny.h |  5 +++--
 apps/bletiny/src/cmd.c     | 20 +++++++++++---------
 apps/bletiny/src/main.c    |  8 ++++----
 3 files changed, 18 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/dba9503b/apps/bletiny/src/bletiny.h
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/bletiny.h b/apps/bletiny/src/bletiny.h
index e154fd4..1ec08c9 100644
--- a/apps/bletiny/src/bletiny.h
+++ b/apps/bletiny/src/bletiny.h
@@ -155,8 +155,9 @@ int bletiny_adv_start(int disc, int conn,
                      uint8_t *peer_addr, uint8_t peer_addr_type,
                      struct ble_gap_adv_params *params);
 int bletiny_adv_stop(void);
-int bletiny_conn_initiate(int addr_type, uint8_t *peer_addr,
-                           struct ble_gap_conn_params *params);
+int bletiny_conn_initiate(uint8_t own_addr_type,
+                          uint8_t peer_addr_type, uint8_t *peer_addr,
+                          struct ble_gap_conn_params *params);
 int bletiny_conn_cancel(void);
 int bletiny_term_conn(uint16_t conn_handle);
 int bletiny_wl_set(struct ble_gap_white_entry *white_list,

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/dba9503b/apps/bletiny/src/cmd.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/cmd.c b/apps/bletiny/src/cmd.c
index 71f001f..26fa807 100644
--- a/apps/bletiny/src/cmd.c
+++ b/apps/bletiny/src/cmd.c
@@ -369,7 +369,8 @@ cmd_conn(int argc, char **argv)
 {
     struct ble_gap_conn_params params;
     uint8_t peer_addr[6];
-    int addr_type;
+    int peer_addr_type;
+    int own_addr_type;
     int rc;
 
     if (argc > 1 && strcmp(argv[1], "cancel") == 0) {
@@ -382,12 +383,12 @@ cmd_conn(int argc, char **argv)
         return 0;
     }
 
-    addr_type = parse_arg_kv("peer_addr_type", cmd_conn_peer_addr_types);
-    if (addr_type == -1) {
+    peer_addr_type = parse_arg_kv("peer_addr_type", cmd_conn_peer_addr_types);
+    if (peer_addr_type == -1) {
         return -1;
     }
 
-    if (addr_type != BLE_GAP_ADDR_TYPE_WL) {
+    if (peer_addr_type != BLE_GAP_ADDR_TYPE_WL) {
         rc = parse_arg_mac("peer_addr", peer_addr);
         if (rc == ENOENT) {
             /* Allow "addr" for backwards compatibility. */
@@ -401,12 +402,12 @@ cmd_conn(int argc, char **argv)
         memset(peer_addr, 0, sizeof peer_addr);
     }
 
-    rc = parse_arg_kv_default("own_addr_type",
-                        cmd_conn_own_addr_types, BLE_ADDR_TYPE_PUBLIC);
-    if (rc < 0) {
+    own_addr_type = parse_arg_kv_default("own_addr_type",
+                                         cmd_conn_own_addr_types,
+                                         BLE_ADDR_TYPE_PUBLIC);
+    if (own_addr_type < 0) {
         return rc;
     }
-    params.our_addr_type = rc;
 
     params.scan_itvl = parse_arg_uint16_dflt("scan_itvl", 0x0010, &rc);
     if (rc != 0) {
@@ -450,7 +451,8 @@ cmd_conn(int argc, char **argv)
         return rc;
     }
 
-    rc = bletiny_conn_initiate(addr_type, peer_addr, &params);
+    rc = bletiny_conn_initiate(own_addr_type, peer_addr_type, peer_addr,
+                               &params);
     if (rc != 0) {
         return rc;
     }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/dba9503b/apps/bletiny/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/main.c b/apps/bletiny/src/main.c
index 48e7324..b63d5d0 100755
--- a/apps/bletiny/src/main.c
+++ b/apps/bletiny/src/main.c
@@ -1258,13 +1258,13 @@ bletiny_adv_start(int disc, int conn,
 }
 
 int
-bletiny_conn_initiate(int addr_type, uint8_t *peer_addr,
-                       struct ble_gap_conn_params *params)
+bletiny_conn_initiate(uint8_t own_addr_type, uint8_t peer_addr_type,
+                      uint8_t *peer_addr, struct ble_gap_conn_params *params)
 {
     int rc;
 
-    rc = ble_gap_conn_initiate(addr_type, peer_addr, params, bletiny_gap_event,
-                               NULL);
+    rc = ble_gap_connect(own_addr_type, peer_addr_type, peer_addr, params,
+                         bletiny_gap_event, NULL);
     return rc;
 }
 


[26/50] [abbrv] incubator-mynewt-core git commit: ble apps - Use latest GATT server API.

Posted by cc...@apache.org.
ble apps - Use latest GATT server API.


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

Branch: refs/heads/ble_hs_api
Commit: bad2b6a6829d10b9023ce3408ee4ac6cfa99cb1b
Parents: 2447ea0
Author: Christopher Collins <cc...@apache.org>
Authored: Thu Jun 30 10:12:02 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Jul 11 16:43:32 2016 -0700

----------------------------------------------------------------------
 apps/bleprph/src/gatt_svr.c | 6 ++----
 apps/bletiny/src/gatt_svr.c | 6 ++----
 2 files changed, 4 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bad2b6a6/apps/bleprph/src/gatt_svr.c
----------------------------------------------------------------------
diff --git a/apps/bleprph/src/gatt_svr.c b/apps/bleprph/src/gatt_svr.c
index 6386663..595a0d9 100644
--- a/apps/bleprph/src/gatt_svr.c
+++ b/apps/bleprph/src/gatt_svr.c
@@ -442,11 +442,9 @@ gatt_svr_register_cb(uint8_t op, union ble_gatt_register_ctxt *ctxt, void *arg)
         break;
 
     case BLE_GATT_REGISTER_OP_DSC:
-        BLEPRPH_LOG(DEBUG, "registering descriptor %s with handle=%d "
-                           "chr_handle=%d\n",
+        BLEPRPH_LOG(DEBUG, "registering descriptor %s with handle=%d\n",
                     gatt_svr_uuid_to_s(ctxt->dsc.dsc_def->uuid128, buf),
-                    ctxt->dsc.dsc_handle,
-                    ctxt->dsc.chr_def_handle);
+                    ctxt->dsc.handle);
         break;
 
     default:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bad2b6a6/apps/bletiny/src/gatt_svr.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/gatt_svr.c b/apps/bletiny/src/gatt_svr.c
index 19b3a8b..0b20f8e 100644
--- a/apps/bletiny/src/gatt_svr.c
+++ b/apps/bletiny/src/gatt_svr.c
@@ -442,11 +442,9 @@ gatt_svr_register_cb(uint8_t op, union ble_gatt_register_ctxt *ctxt, void *arg)
         break;
 
     case BLE_GATT_REGISTER_OP_DSC:
-        BLETINY_LOG(DEBUG, "registering descriptor %s with handle=%d "
-                           "chr_handle=%d\n",
+        BLETINY_LOG(DEBUG, "registering descriptor %s with handle=%d\n",
                     gatt_svr_uuid_to_s(ctxt->dsc.dsc_def->uuid128, buf),
-                    ctxt->dsc.dsc_handle,
-                    ctxt->dsc.chr_def_handle);
+                    ctxt->dsc.handle);
         break;
 
     default:


[13/50] [abbrv] incubator-mynewt-core git commit: bletiny - Use new discovery API.

Posted by cc...@apache.org.
bletiny - Use new discovery API.


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

Branch: refs/heads/ble_hs_api
Commit: e2b64ce26c700dbc68b4f22a4248ab5ed63fdc25
Parents: e4c0c0a
Author: Christopher Collins <cc...@apache.org>
Authored: Thu Jun 23 20:45:42 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Jul 11 16:43:31 2016 -0700

----------------------------------------------------------------------
 apps/bletiny/src/bletiny.h |  6 +++--
 apps/bletiny/src/cmd.c     | 55 ++++++++++++++++++++---------------------
 apps/bletiny/src/main.c    |  6 ++---
 apps/bletiny/src/parse.c   |  6 +++++
 4 files changed, 40 insertions(+), 33 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e2b64ce2/apps/bletiny/src/bletiny.h
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/bletiny.h b/apps/bletiny/src/bletiny.h
index e70effd..23699d2 100644
--- a/apps/bletiny/src/bletiny.h
+++ b/apps/bletiny/src/bletiny.h
@@ -37,6 +37,7 @@ union ble_store_value;
 union ble_store_key;
 struct ble_gap_adv_params;
 struct ble_gap_conn_desc;
+struct ble_gap_disc_params;
 
 typedef int cmd_fn(int argc, char **argv);
 struct cmd_entry {
@@ -106,6 +107,7 @@ uint64_t parse_arg_uint64_bounds(char *name, uint64_t min,
                                  uint64_t max, int *out_status);
 long parse_arg_long(char *name, int *staus);
 uint8_t parse_arg_bool(char *name, int *status);
+uint8_t parse_arg_bool_default(char *name, uint8_t dflt, int *out_status);
 uint8_t parse_arg_uint8(char *name, int *status);
 uint16_t parse_arg_uint16(char *name, int *status);
 uint16_t parse_arg_uint16_dflt(char *name, uint16_t dflt, int *out_status);
@@ -165,8 +167,8 @@ int bletiny_conn_cancel(void);
 int bletiny_term_conn(uint16_t conn_handle);
 int bletiny_wl_set(struct ble_gap_white_entry *white_list,
                     int white_list_count);
-int bletiny_scan(uint32_t dur_ms, uint8_t disc_mode, uint8_t scan_type,
-                  uint8_t filter_policy, uint8_t our_addr_mode);
+int bletiny_scan(uint8_t own_addr_type, int32_t duration_ms,
+                 const struct ble_gap_disc_params *disc_params);
 int bletiny_scan_cancel(void);
 int bletiny_set_adv_data(struct ble_hs_adv_fields *adv_fields);
 int bletiny_update_conn(uint16_t conn_handle,

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e2b64ce2/apps/bletiny/src/cmd.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/cmd.c b/apps/bletiny/src/cmd.c
index c840c7e..b735094 100644
--- a/apps/bletiny/src/cmd.c
+++ b/apps/bletiny/src/cmd.c
@@ -911,18 +911,6 @@ cmd_rssi(int argc, char **argv)
  * $scan                                                                     *
  *****************************************************************************/
 
-static struct kv_pair cmd_scan_disc_modes[] = {
-    { "ltd", BLE_GAP_DISC_MODE_LTD },
-    { "gen", BLE_GAP_DISC_MODE_GEN },
-    { NULL }
-};
-
-static struct kv_pair cmd_scan_types[] = {
-    { "passive", BLE_HCI_SCAN_TYPE_PASSIVE },
-    { "active", BLE_HCI_SCAN_TYPE_ACTIVE },
-    { NULL }
-};
-
 static struct kv_pair cmd_scan_filt_policies[] = {
     { "no_wl", BLE_HCI_SCAN_FILT_NO_WL },
     { "use_wl", BLE_HCI_SCAN_FILT_USE_WL },
@@ -942,12 +930,10 @@ static struct kv_pair cmd_scan_addr_types[] = {
 static int
 cmd_scan(int argc, char **argv)
 {
-    int32_t dur;
-    int disc;
-    int type;
-    int filt;
+    struct ble_gap_disc_params params;
+    int32_t duration_ms;
+    uint8_t own_addr_type;
     int rc;
-    int addr_mode;
 
     if (argc > 1 && strcmp(argv[1], "cancel") == 0) {
         rc = bletiny_scan_cancel();
@@ -959,37 +945,50 @@ cmd_scan(int argc, char **argv)
         return 0;
     }
 
-    dur = parse_arg_long_bounds_default("dur", 1, INT32_MAX, BLE_HS_FOREVER,
-                                        &rc);
+    duration_ms = parse_arg_long_bounds_default("dur", 1, INT32_MAX,
+                                                BLE_HS_FOREVER, &rc);
+    if (rc != 0) {
+        return rc;
+    }
+
+    params.limited = parse_arg_bool_default("ltd", 0, &rc);
     if (rc != 0) {
         return rc;
     }
 
-    disc = parse_arg_kv_default("disc", cmd_scan_disc_modes,
-                                BLE_GAP_DISC_MODE_GEN, &rc);
+    params.passive = parse_arg_bool_default("passive", 0, &rc);
     if (rc != 0) {
         return rc;
     }
 
-    type = parse_arg_kv_default("type", cmd_scan_types,
-                                BLE_HCI_SCAN_TYPE_ACTIVE, &rc);
+    params.itvl = parse_arg_uint16_dflt("itvl", 0, &rc);
     if (rc != 0) {
         return rc;
     }
 
-    filt = parse_arg_kv_default("filt", cmd_scan_filt_policies,
-                                BLE_HCI_SCAN_FILT_NO_WL, &rc);
+    params.window = parse_arg_uint16_dflt("window", 0, &rc);
     if (rc != 0) {
         return rc;
     }
 
-    addr_mode = parse_arg_kv_default("addr_mode", cmd_scan_addr_types,
-                                     BLE_ADDR_TYPE_PUBLIC, &rc);
+    params.filter_policy = parse_arg_kv_default(
+        "filt", cmd_scan_filt_policies, BLE_HCI_SCAN_FILT_NO_WL, &rc);
+    if (rc != 0) {
+        return rc;
+    }
+
+    params.filter_duplicates = parse_arg_bool_default("nodups", 0, &rc);
+    if (rc != 0) {
+        return rc;
+    }
+
+    own_addr_type = parse_arg_kv_default("own_addr_type", cmd_scan_addr_types,
+                                         BLE_ADDR_TYPE_PUBLIC, &rc);
     if (rc != 0) {
         return rc;
     }
 
-    rc = bletiny_scan(dur, disc, type, filt, addr_mode);
+    rc = bletiny_scan(own_addr_type, duration_ms, &params);
     if (rc != 0) {
         console_printf("error scanning; rc=%d\n", rc);
         return rc;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e2b64ce2/apps/bletiny/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/main.c b/apps/bletiny/src/main.c
index d8b1912..8c53117 100755
--- a/apps/bletiny/src/main.c
+++ b/apps/bletiny/src/main.c
@@ -1300,12 +1300,12 @@ bletiny_wl_set(struct ble_gap_white_entry *white_list, int white_list_count)
 }
 
 int
-bletiny_scan(uint32_t dur_ms, uint8_t disc_mode, uint8_t scan_type,
-             uint8_t filter_policy, uint8_t addr_mode)
+bletiny_scan(uint8_t own_addr_type, int32_t duration_ms,
+             const struct ble_gap_disc_params *disc_params)
 {
     int rc;
 
-    rc = ble_gap_disc(dur_ms, disc_mode, scan_type, filter_policy, addr_mode,
+    rc = ble_gap_disc(own_addr_type, duration_ms, disc_params,
                       bletiny_on_scan, NULL);
     return rc;
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e2b64ce2/apps/bletiny/src/parse.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/parse.c b/apps/bletiny/src/parse.c
index 927520b..f12ef10 100644
--- a/apps/bletiny/src/parse.c
+++ b/apps/bletiny/src/parse.c
@@ -185,6 +185,12 @@ parse_arg_bool(char *name, int *out_status)
 }
 
 uint8_t
+parse_arg_bool_default(char *name, uint8_t dflt, int *out_status)
+{
+    return parse_arg_long_bounds_default(name, 0, 1, dflt, out_status);
+}
+
+uint8_t
 parse_arg_uint8(char *name, int *out_status)
 {
     return parse_arg_long_bounds(name, 0, UINT8_MAX, out_status);


[18/50] [abbrv] incubator-mynewt-core git commit: BLE Host - Comments for GATT server structs.

Posted by cc...@apache.org.
BLE Host - Comments for GATT server structs.


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

Branch: refs/heads/ble_hs_api
Commit: 2997fff8aaea5f18482506a609b9d28491fb1d1e
Parents: 81b89f6
Author: Christopher Collins <cc...@apache.org>
Authored: Mon Jun 27 18:02:16 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Jul 11 16:43:32 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/include/host/ble_gatt.h | 215 +++++++++++++++++++--------
 net/nimble/host/src/ble_gatts.c         |   4 +
 2 files changed, 160 insertions(+), 59 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2997fff8/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 76d61cf..d805590 100644
--- a/net/nimble/host/include/host/ble_gatt.h
+++ b/net/nimble/host/include/host/ble_gatt.h
@@ -25,9 +25,47 @@
 struct ble_hs_conn;
 struct ble_att_error_rsp;
 
+#define BLE_GATT_REGISTER_OP_SVC                        1
+#define BLE_GATT_REGISTER_OP_CHR                        2
+#define BLE_GATT_REGISTER_OP_DSC                        3
+
 #define BLE_GATT_SVC_UUID16                             0x1801
 #define BLE_GATT_CHR_SERVICE_CHANGED_UUID16             0x2a05
 
+#define BLE_GATT_CHR_PROP_BROADCAST                     0x01
+#define BLE_GATT_CHR_PROP_READ                          0x02
+#define BLE_GATT_CHR_PROP_WRITE_NO_RSP                  0x04
+#define BLE_GATT_CHR_PROP_WRITE                         0x08
+#define BLE_GATT_CHR_PROP_NOTIFY                        0x10
+#define BLE_GATT_CHR_PROP_INDICATE                      0x20
+#define BLE_GATT_CHR_PROP_AUTH_SIGN_WRITE               0x40
+#define BLE_GATT_CHR_PROP_EXTENDED                      0x80
+
+#define BLE_GATT_ACCESS_OP_READ_CHR                     0
+#define BLE_GATT_ACCESS_OP_WRITE_CHR                    1
+#define BLE_GATT_ACCESS_OP_READ_DSC                     2
+#define BLE_GATT_ACCESS_OP_WRITE_DSC                    3
+
+#define BLE_GATT_CHR_F_BROADCAST                        0x0001
+#define BLE_GATT_CHR_F_READ                             0x0002
+#define BLE_GATT_CHR_F_WRITE_NO_RSP                     0x0004
+#define BLE_GATT_CHR_F_WRITE                            0x0008
+#define BLE_GATT_CHR_F_NOTIFY                           0x0010
+#define BLE_GATT_CHR_F_INDICATE                         0x0020
+#define BLE_GATT_CHR_F_AUTH_SIGN_WRITE                  0x0040
+#define BLE_GATT_CHR_F_RELIABLE_WRITE                   0x0080
+#define BLE_GATT_CHR_F_AUX_WRITE                        0x0100
+#define BLE_GATT_CHR_F_READ_ENC                         0x0200
+#define BLE_GATT_CHR_F_READ_AUTHEN                      0x0400
+#define BLE_GATT_CHR_F_READ_AUTHOR                      0x0800
+#define BLE_GATT_CHR_F_WRITE_ENC                        0x1000
+#define BLE_GATT_CHR_F_WRITE_AUTHEN                     0x2000
+#define BLE_GATT_CHR_F_WRITE_AUTHOR                     0x4000
+
+#define BLE_GATT_SVC_TYPE_END                           0
+#define BLE_GATT_SVC_TYPE_PRIMARY                       1
+#define BLE_GATT_SVC_TYPE_SECONDARY                     2
+
 /*** @client. */
 struct ble_gatt_error {
     uint16_t status;
@@ -143,20 +181,6 @@ int ble_gattc_init(void);
 
 /*** @server. */
 
-#define BLE_GATT_CHR_PROP_BROADCAST         0x01
-#define BLE_GATT_CHR_PROP_READ              0x02
-#define BLE_GATT_CHR_PROP_WRITE_NO_RSP      0x04
-#define BLE_GATT_CHR_PROP_WRITE             0x08
-#define BLE_GATT_CHR_PROP_NOTIFY            0x10
-#define BLE_GATT_CHR_PROP_INDICATE          0x20
-#define BLE_GATT_CHR_PROP_AUTH_SIGN_WRITE   0x40
-#define BLE_GATT_CHR_PROP_EXTENDED          0x80
-
-#define BLE_GATT_ACCESS_OP_READ_CHR         0
-#define BLE_GATT_ACCESS_OP_WRITE_CHR        1
-#define BLE_GATT_ACCESS_OP_READ_DSC         2
-#define BLE_GATT_ACCESS_OP_WRITE_DSC        3
-
 struct ble_gatt_access_ctxt;
 typedef int ble_gatt_access_fn(uint16_t conn_handle, uint16_t attr_handle,
                                uint8_t op, struct ble_gatt_access_ctxt *ctxt,
@@ -164,53 +188,79 @@ typedef int ble_gatt_access_fn(uint16_t conn_handle, uint16_t attr_handle,
 
 typedef uint16_t ble_gatt_chr_flags;
 
-#define BLE_GATT_CHR_F_BROADCAST            0x0001
-#define BLE_GATT_CHR_F_READ                 0x0002
-#define BLE_GATT_CHR_F_WRITE_NO_RSP         0x0004
-#define BLE_GATT_CHR_F_WRITE                0x0008
-#define BLE_GATT_CHR_F_NOTIFY               0x0010
-#define BLE_GATT_CHR_F_INDICATE             0x0020
-#define BLE_GATT_CHR_F_AUTH_SIGN_WRITE      0x0040
-#define BLE_GATT_CHR_F_RELIABLE_WRITE       0x0080
-#define BLE_GATT_CHR_F_AUX_WRITE            0x0100
-#define BLE_GATT_CHR_F_READ_ENC             0x0200
-#define BLE_GATT_CHR_F_READ_AUTHEN          0x0400
-#define BLE_GATT_CHR_F_READ_AUTHOR          0x0800
-#define BLE_GATT_CHR_F_WRITE_ENC            0x1000
-#define BLE_GATT_CHR_F_WRITE_AUTHEN         0x2000
-#define BLE_GATT_CHR_F_WRITE_AUTHOR         0x4000
-
 struct ble_gatt_chr_def {
-    const uint8_t *uuid128;   /* NULL if no more characteristics. */
+    /**
+     * Pointer to first element in a uint8_t[16]; use the BLE_UUID16 macro for
+     * 16-bit UUIDs; NULL if there are no more characteristics in the service.
+     */
+    const uint8_t *uuid128;
+
+    /**
+     * Callback that gets executed when this characteristic is read or
+     * written.
+     */
     ble_gatt_access_fn *access_cb;
+
+    /** Optional argument for callback. */
     void *arg;
+
+    /**
+     * Array of this characteristic's descriptors.  NULL if no descriptors.
+     * Do not include CCCD; it gets added automatically if this
+     * characteristic's notify or indicate flag is set.
+     */
     struct ble_gatt_dsc_def *descriptors;
+
+    /** Specifies the set of permitted operations for this characteristic. */
     ble_gatt_chr_flags flags;
-};
 
-#define BLE_GATT_SVC_TYPE_END       0
-#define BLE_GATT_SVC_TYPE_PRIMARY   1
-#define BLE_GATT_SVC_TYPE_SECONDARY 2
+    /** 
+     * At registration time, this is filled in with the characteristic's value
+     * attribute handle.
+     */
+    uint16_t * const val_handle;
+};
 
 struct ble_gatt_svc_def {
+    /**
+     * One of the following:
+     *     o BLE_GATT_SVC_TYPE_PRIMARY - primary service
+     *     o BLE_GATT_SVC_TYPE_SECONDARY - secondary service
+     *     o 0 - No more services in this array.
+     */
     uint8_t type;
+
+    /**
+     * Pointer to first element in a uint8_t[16]; use the BLE_UUID16 macro for
+     * 16-bit UUIDs.
+     */
     const uint8_t *uuid128;
-    const struct ble_gatt_svc_def **includes; /* Terminated with null. */
+
+    /**
+     * Array of pointers to other service definitions.  These services are
+     * reported as "included services" during service discovery.  Terminate the
+     * array with NULL.
+     */
+    const struct ble_gatt_svc_def **includes;
+
+    /**
+     * Array of characteristic definitions corresponding to characteristics
+     * belonging to this service.
+     */
     const struct ble_gatt_chr_def *characteristics;
 };
 
 struct ble_gatt_access_ctxt {
     union {
         /**
-         * Points to the characteristic defintion corresponding to the
-         * characteristic being accessed.  This is what the app registered at
-         * startup.
+         * The characteristic definition corresponding to the characteristic
+         * being accessed.  This is what the app registered at startup.
          */
         const struct ble_gatt_chr_def *chr;
 
         /**
-         * Points to the descriptor defintion corresponding to the descriptor
-         * being accessed.  This is what the app registered at startup.
+         * The descriptor definition corresponding to the descriptor being
+         * accessed.  This is what the app registered at startup.
          */
         const struct ble_gatt_dsc_def *dsc;
     };
@@ -219,46 +269,93 @@ struct ble_gatt_access_ctxt {
 };
 
 struct ble_gatt_dsc_def {
+    /**
+     * The first element in a uint8_t[16]; use the BLE_UUID16 macro for 16-bit
+     * UUIDs; NULL if there are no more descriptors in the characteristic.
+     */
     uint8_t *uuid128;
+
+    /** Specifies the set of permitted operations for this descriptor. */
     uint8_t att_flags;
+
+    /** Callback that gets executed when the descriptor is read or written. */
     ble_gatt_access_fn *access_cb;
+
+    /** Optional argument for callback. */
     void *arg;
 };
 
-#define BLE_GATT_REGISTER_OP_SVC    1
-#define BLE_GATT_REGISTER_OP_CHR    2
-#define BLE_GATT_REGISTER_OP_DSC    3
-
-union ble_gatt_register_ctxt;
-typedef void ble_gatt_register_fn(uint8_t op,
-                                  union ble_gatt_register_ctxt *ctxt,
-                                  void *arg);
-
-int ble_gatts_register_svcs(const struct ble_gatt_svc_def *svcs,
-                            ble_gatt_register_fn *register_cb,
-                            void *cb_arg);
-void ble_gatts_chr_updated(uint16_t chr_def_handle);
-
+/**
+ * Context passed to the registration callback; represents the GATT service,
+ * characteristic, or descriptor being registered.
+ */
 union ble_gatt_register_ctxt {
+    /** Service; valid if op == BLE_GATT_REGISTER_OP_SVC. */
     struct {
+        /** The ATT handle of the service definition attribute. */
         uint16_t handle;
+
+        /**
+         * The service definition representing the service being
+         * registered.
+         */
         const struct ble_gatt_svc_def *svc_def;
     } svc;
 
+    /** Characteristic; valid if op == BLE_GATT_REGISTER_OP_CHR. */
     struct {
+        /** The ATT handle of the characteristic definition attribute. */
         uint16_t def_handle;
+
+        /** The ATT handle of the characteristic value attribute. */
         uint16_t val_handle;
-        const struct ble_gatt_svc_def *svc_def;
+
+        /**
+         * The characteristic definition representing the characteristic being
+         * registered.
+         */
         const struct ble_gatt_chr_def *chr_def;
+
+        /**
+         * The service definition corresponding to the characteristic's parent
+         * service.
+         */
+        const struct ble_gatt_svc_def *svc_def;
     } chr;
 
+    /** Descriptor; valid if op == BLE_GATT_REGISTER_OP_DSC. */
     struct {
-        uint16_t dsc_handle;
+        /** The ATT handle of the descriptor definition attribute. */
+        uint16_t handle;
+
+        /**
+         * The descriptor definition corresponding to the descriptor being
+         * registered.
+         */
         const struct ble_gatt_dsc_def *dsc_def;
-        uint16_t chr_def_handle;
-        uint16_t chr_val_handle;
+
+        /**
+         * The characteristic definition corresponding to the descriptor's
+         * parent characteristic.
+         */
         const struct ble_gatt_chr_def *chr_def;
+
+        /**
+         * The service definition corresponding to the descriptor's grandparent
+         * service
+         */
+        const struct ble_gatt_svc_def *svc_def;
     } dsc;
 };
 
+union ble_gatt_register_ctxt;
+typedef void ble_gatt_register_fn(uint8_t op,
+                                  union ble_gatt_register_ctxt *ctxt,
+                                  void *arg);
+
+int ble_gatts_register_svcs(const struct ble_gatt_svc_def *svcs,
+                            ble_gatt_register_fn *register_cb,
+                            void *cb_arg);
+void ble_gatts_chr_updated(uint16_t chr_def_handle);
+
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2997fff8/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 320ee65..0665758 100644
--- a/net/nimble/host/src/ble_gatts.c
+++ b/net/nimble/host/src/ble_gatts.c
@@ -716,6 +716,10 @@ ble_gatts_register_chr(const struct ble_gatt_svc_def *svc,
     }
     BLE_HS_DBG_ASSERT(val_handle == def_handle + 1);
 
+    if (chr->val_handle != NULL) {
+        *chr->val_handle = val_handle;
+    }
+
     if (register_cb != NULL) {
         register_ctxt.chr.def_handle = def_handle;
         register_ctxt.chr.val_handle = val_handle;


[09/50] [abbrv] incubator-mynewt-core git commit: BLE Host - Always increment GAP stats on failure.

Posted by cc...@apache.org.
BLE Host - Always increment GAP stats on failure.


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

Branch: refs/heads/ble_hs_api
Commit: 3890be3232feccd09d44be818212c68736dbe43d
Parents: e2b64ce
Author: Christopher Collins <cc...@apache.org>
Authored: Fri Jun 24 11:15:08 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Jul 11 16:43:31 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/src/ble_gap.c              | 146 ++++++++++++++++--------
 net/nimble/host/src/ble_gap_priv.h         |   2 +
 net/nimble/host/src/test/ble_hs_adv_test.c |   5 +
 3 files changed, 104 insertions(+), 49 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3890be32/net/nimble/host/src/ble_gap.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gap.c b/net/nimble/host/src/ble_gap.c
index cf80b7e..9270a9f 100644
--- a/net/nimble/host/src/ble_gap.c
+++ b/net/nimble/host/src/ble_gap.c
@@ -175,6 +175,8 @@ STATS_NAME_START(ble_gap_stats)
     STATS_NAME(ble_gap_stats, rx_conn_complete)
     STATS_NAME(ble_gap_stats, discover_cancel)
     STATS_NAME(ble_gap_stats, discover_cancel_fail)
+    STATS_NAME(ble_gap_stats, security_initiate)
+    STATS_NAME(ble_gap_stats, security_initiate_fail)
 STATS_NAME_END(ble_gap_stats)
 
 /*****************************************************************************
@@ -1190,9 +1192,11 @@ ble_gap_wl_set(struct ble_gap_white_entry *white_list,
 
     STATS_INC(ble_gap_stats, wl_set);
 
+    ble_hs_lock();
+
     if (white_list_count == 0) {
         rc = BLE_HS_EINVAL;
-        goto err;
+        goto done;
     }
 
     for (i = 0; i < white_list_count; i++) {
@@ -1200,13 +1204,13 @@ ble_gap_wl_set(struct ble_gap_white_entry *white_list,
             white_list[i].addr_type != BLE_ADDR_TYPE_RANDOM) {
 
             rc = BLE_HS_EINVAL;
-            goto err;
+            goto done;
         }
     }
 
     if (ble_gap_wl_busy()) {
         rc = BLE_HS_EBUSY;
-        goto err;
+        goto done;
     }
 
     BLE_HS_LOG(INFO, "GAP procedure initiated: set whitelist; ");
@@ -1215,20 +1219,24 @@ ble_gap_wl_set(struct ble_gap_white_entry *white_list,
 
     rc = ble_gap_wl_tx_clear();
     if (rc != 0) {
-        goto err;
+        goto done;
     }
 
     for (i = 0; i < white_list_count; i++) {
         rc = ble_gap_wl_tx_add(white_list + i);
         if (rc != 0) {
-            goto err;
+            goto done;
         }
     }
 
-    return 0;
+    rc = 0;
+
+done:
+    ble_hs_unlock();
 
-err:
-    STATS_INC(ble_gap_stats, wl_set_fail);
+    if (rc != 0) {
+        STATS_INC(ble_gap_stats, wl_set_fail);
+    }
     return rc;
 }
 
@@ -1262,25 +1270,31 @@ ble_gap_adv_stop(void)
 
     STATS_INC(ble_gap_stats, adv_stop);
 
+    ble_hs_lock();
+
     /* Do nothing if advertising is already disabled. */
     if (!ble_gap_currently_advertising()) {
         rc = BLE_HS_EALREADY;
-        goto err;
+        goto done;
     }
 
     BLE_HS_LOG(INFO, "GAP procedure initiated: stop advertising.\n");
 
     rc = ble_gap_adv_disable_tx();
     if (rc != 0) {
-        goto err;
+        goto done;
     }
 
     ble_gap_slave_reset_state();
 
-    return 0;
+    rc = 0;
 
-err:
-    STATS_INC(ble_gap_stats, adv_set_fields_fail);
+done:
+    ble_hs_unlock();
+
+    if (rc != 0) {
+        STATS_INC(ble_gap_stats, adv_set_fields_fail);
+    }
     return rc;
 }
 
@@ -1585,10 +1599,10 @@ ble_gap_adv_start(uint8_t own_addr_type, uint8_t peer_addr_type,
     uint32_t duration_ticks;
     int rc;
 
-    ble_hs_lock();
-
     STATS_INC(ble_gap_stats, adv_start);
 
+    ble_hs_lock();
+
     rc = ble_gap_adv_validate(own_addr_type, peer_addr_type, peer_addr,
                               adv_params);
     if (rc != 0) {
@@ -1645,12 +1659,11 @@ ble_gap_adv_start(uint8_t own_addr_type, uint8_t peer_addr_type,
     rc = 0;
 
 done:
+    ble_hs_unlock();
+
     if (rc != 0) {
         STATS_INC(ble_gap_stats, adv_start_fail);
     }
-
-    ble_hs_unlock();
-
     return rc;
 }
 
@@ -1664,9 +1677,15 @@ ble_gap_adv_set_fields(struct ble_hs_adv_fields *adv_fields)
     int max_sz;
     int rc;
 
+    STATS_INC(ble_gap_stats, adv_set_fields);
+
     ble_hs_lock();
 
-    STATS_INC(ble_gap_stats, adv_set_fields);
+    /* Don't allow advertising fields to be set while advertising is active. */
+    if (ble_gap_slave.op != BLE_GAP_OP_NULL) {
+        rc = BLE_HS_EBUSY;
+        goto done;
+    }
 
     /* If application has requested the stack to calculate the flags field
      * automatically (flags == 0), there is less room for user data.
@@ -1682,11 +1701,15 @@ ble_gap_adv_set_fields(struct ble_hs_adv_fields *adv_fields)
     rc = ble_hs_adv_set_fields(adv_fields, ble_gap_slave.adv_data,
                                &ble_gap_slave.adv_data_len, max_sz);
     if (rc != 0) {
-        STATS_INC(ble_gap_stats, adv_set_fields_fail);
+        goto done;
     }
 
+done:
     ble_hs_unlock();
 
+    if (rc != 0) {
+        STATS_INC(ble_gap_stats, adv_set_fields_fail);
+    }
     return rc;
 }
 
@@ -1699,19 +1722,29 @@ ble_gap_adv_rsp_set_fields(struct ble_hs_adv_fields *rsp_fields)
 
     int rc;
 
+    STATS_INC(ble_gap_stats, adv_rsp_set_fields);
+
     ble_hs_lock();
 
-    STATS_INC(ble_gap_stats, adv_rsp_set_fields);
+    /* Don't allow response fields to be set while advertising is active. */
+    if (ble_gap_slave.op != BLE_GAP_OP_NULL) {
+        rc = BLE_HS_EBUSY;
+        goto done;
+    }
 
     rc = ble_hs_adv_set_fields(rsp_fields, ble_gap_slave.rsp_data,
                                &ble_gap_slave.rsp_data_len,
                                BLE_HCI_MAX_ADV_DATA_LEN);
     if (rc != 0) {
-        STATS_INC(ble_gap_stats, adv_rsp_set_fields_fail);
+        goto done;
     }
 
+done:
     ble_hs_unlock();
 
+    if (rc != 0) {
+        STATS_INC(ble_gap_stats, adv_rsp_set_fields_fail);
+    }
     return rc;
 }
 
@@ -1796,10 +1829,10 @@ ble_gap_disc_cancel(void)
 {
     int rc;
 
-    ble_hs_lock();
-
     STATS_INC(ble_gap_stats, discover_cancel);
 
+    ble_hs_lock();
+
     if (ble_gap_master.op != BLE_GAP_OP_M_DISC) {
         rc = BLE_HS_EALREADY;
         goto done;
@@ -1813,11 +1846,11 @@ ble_gap_disc_cancel(void)
     ble_gap_master_reset_state();
 
 done:
+    ble_hs_unlock();
+
     if (rc != 0) {
         STATS_INC(ble_gap_stats, discover_cancel_fail);
     }
-    ble_hs_unlock();
-
     return rc;
 }
 
@@ -1939,7 +1972,6 @@ done:
     if (rc != 0) {
         STATS_INC(ble_gap_stats, discover_fail);
     }
-
     return rc;
 }
 
@@ -2020,6 +2052,8 @@ ble_gap_connect(uint8_t own_addr_type,
 
     int rc;
 
+    STATS_INC(ble_gap_stats, initiate);
+
     ble_hs_lock();
 
     if (ble_gap_master.op != BLE_GAP_OP_NULL) {
@@ -2032,8 +2066,6 @@ ble_gap_connect(uint8_t own_addr_type,
         goto done;
     }
 
-    STATS_INC(ble_gap_stats, initiate);
-
     if (peer_addr_type != BLE_HCI_CONN_PEER_ADDR_PUBLIC &&
         peer_addr_type != BLE_HCI_CONN_PEER_ADDR_RANDOM &&
         peer_addr_type != BLE_HCI_CONN_PEER_ADDR_PUB_ID &&
@@ -2070,12 +2102,11 @@ ble_gap_connect(uint8_t own_addr_type,
     rc = 0;
 
 done:
+    ble_hs_unlock();
+
     if (rc != 0) {
         STATS_INC(ble_gap_stats, initiate_fail);
     }
-
-    ble_hs_unlock();
-
     return rc;
 }
 
@@ -2089,10 +2120,10 @@ ble_gap_terminate(uint16_t conn_handle)
     uint8_t buf[BLE_HCI_CMD_HDR_LEN + BLE_HCI_DISCONNECT_CMD_LEN];
     int rc;
 
-    ble_hs_lock();
-
     STATS_INC(ble_gap_stats, terminate);
 
+    ble_hs_lock();
+
     if (!ble_hs_conn_exists(conn_handle)) {
         rc = BLE_HS_ENOTCONN;
         goto done;
@@ -2111,12 +2142,11 @@ ble_gap_terminate(uint16_t conn_handle)
     rc = 0;
 
 done:
+    ble_hs_unlock();
+
     if (rc != 0) {
         STATS_INC(ble_gap_stats, terminate_fail);
     }
-
-    ble_hs_unlock();
-
     return rc;
 }
 
@@ -2130,10 +2160,10 @@ ble_gap_conn_cancel(void)
     uint8_t buf[BLE_HCI_CMD_HDR_LEN];
     int rc;
 
-    ble_hs_lock();
-
     STATS_INC(ble_gap_stats, cancel);
 
+    ble_hs_lock();
+
     if (!ble_gap_master_in_progress()) {
         rc = BLE_HS_ENOENT;
         goto done;
@@ -2150,12 +2180,11 @@ ble_gap_conn_cancel(void)
     rc = 0;
 
 done:
+    ble_hs_unlock();
+
     if (rc != 0) {
         STATS_INC(ble_gap_stats, cancel_fail);
     }
-
-    ble_hs_unlock();
-
     return rc;
 }
 
@@ -2303,10 +2332,10 @@ ble_gap_update_params(uint16_t conn_handle, struct ble_gap_upd_params *params)
     struct ble_hs_conn *conn;
     int rc;
 
-    ble_hs_lock();
-
     STATS_INC(ble_gap_stats, update);
 
+    ble_hs_lock();
+
     conn = ble_hs_conn_find(conn_handle);
     if (conn == NULL) {
         rc = BLE_HS_ENOTCONN;
@@ -2330,12 +2359,11 @@ ble_gap_update_params(uint16_t conn_handle, struct ble_gap_upd_params *params)
     conn->bhc_flags |= BLE_HS_CONN_F_UPDATE;
 
 done:
+    ble_hs_unlock();
+
     if (rc != 0) {
         STATS_INC(ble_gap_stats, update_fail);
     }
-
-    ble_hs_unlock();
-
     return rc;
 }
 
@@ -2357,6 +2385,8 @@ ble_gap_security_initiate(uint16_t conn_handle)
     struct ble_hs_conn *conn;
     int rc;
 
+    STATS_INC(ble_gap_stats, security_initiate);
+
     ble_hs_lock();
     conn = ble_hs_conn_find(conn_handle);
     if (conn != NULL) {
@@ -2370,7 +2400,8 @@ ble_gap_security_initiate(uint16_t conn_handle)
     ble_hs_unlock();
 
     if (conn == NULL) {
-        return BLE_HS_ENOTCONN;
+        rc = BLE_HS_ENOTCONN;
+        goto done;
     }
 
     if (conn_flags & BLE_HS_CONN_F_MASTER) {
@@ -2383,11 +2414,27 @@ ble_gap_security_initiate(uint16_t conn_handle)
             rc = ble_sm_enc_initiate(conn_handle, value_sec.ltk,
                                      value_sec.ediv, value_sec.rand_num,
                                      value_sec.authenticated);
+            if (rc != 0) {
+                goto done;
+            }
         } else {
             rc = ble_sm_pair_initiate(conn_handle);
+            if (rc != 0) {
+                goto done;
+            }
         }
     } else {
         rc = ble_sm_slave_initiate(conn_handle);
+        if (rc != 0) {
+            goto done;
+        }
+    }
+
+    rc = 0;
+
+done:
+    if (rc != 0) {
+        STATS_INC(ble_gap_stats, security_initiate_fail);
     }
 
     return rc;
@@ -2523,7 +2570,8 @@ ble_gap_notify_event(uint16_t conn_handle, uint16_t attr_handle,
     ble_gap_call_event_cb(BLE_GAP_EVENT_NOTIFY, &ctxt, snap.cb, snap.cb_arg);
 }
 
-void ble_gap_init_identity_addr(uint8_t *addr)
+void
+ble_gap_init_identity_addr(uint8_t *addr)
 {
     ble_hs_pvcy_set_our_id_addr(addr);
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3890be32/net/nimble/host/src/ble_gap_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gap_priv.h b/net/nimble/host/src/ble_gap_priv.h
index 91bbd31..bb4ef3a 100644
--- a/net/nimble/host/src/ble_gap_priv.h
+++ b/net/nimble/host/src/ble_gap_priv.h
@@ -61,6 +61,8 @@ STATS_SECT_START(ble_gap_stats)
     STATS_SECT_ENTRY(rx_conn_complete)
     STATS_SECT_ENTRY(discover_cancel)
     STATS_SECT_ENTRY(discover_cancel_fail)
+    STATS_SECT_ENTRY(security_initiate)
+    STATS_SECT_ENTRY(security_initiate_fail)
 STATS_SECT_END
 
 extern STATS_SECT_DECL(ble_gap_stats) ble_gap_stats;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3890be32/net/nimble/host/src/test/ble_hs_adv_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_hs_adv_test.c b/net/nimble/host/src/test/ble_hs_adv_test.c
index 3a78505..dec9736 100644
--- a/net/nimble/host/src/test/ble_hs_adv_test.c
+++ b/net/nimble/host/src/test/ble_hs_adv_test.c
@@ -1436,6 +1436,8 @@ TEST_CASE(ble_hs_adv_test_case_user_full_payload)
     struct ble_hs_adv_fields rsp_fields;
     int rc;
 
+    ble_hs_test_util_init();
+
     memset(&rsp_fields, 0, sizeof rsp_fields);
 
     /***
@@ -1457,6 +1459,9 @@ TEST_CASE(ble_hs_adv_test_case_user_full_payload)
         }, &rsp_fields, NULL);
 
     /*** Fail with 30 bytes. */
+    rc = ble_hs_test_util_adv_stop(0);
+    TEST_ASSERT_FATAL(rc == 0);
+
     adv_fields.mfg_data_len = 30;
     rc = ble_gap_adv_set_fields(&adv_fields);
     TEST_ASSERT(rc == BLE_HS_EMSGSIZE);


[38/50] [abbrv] incubator-mynewt-core git commit: mbuf: os_mbuf_appendfrom

Posted by cc...@apache.org.
mbuf: os_mbuf_appendfrom

/**
 * Reads data from one mbuf and appends it to another.  On error, the
 * specified data range may be partially appended.  Neither mbuf is
 * required to contain an mbuf packet header.
 *
 * @param dst                   The mbuf to append to.
 * @param src                   The mbuf to copy data from.
 * @param src_off               The absolute offset within the source
 *                                  mbuf chain to read from.
 * @param len                   The number of bytes to append.
 */
int
os_mbuf_appendfrom(struct os_mbuf *dst, const struct os_mbuf *src,
                   uint16_t src_off, uint16_t len)


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

Branch: refs/heads/ble_hs_api
Commit: 98181d7604760f63ab9bac3a02b78865d38719b5
Parents: fd4a12a
Author: Christopher Collins <cc...@apache.org>
Authored: Fri Jul 8 19:45:41 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Jul 11 16:43:34 2016 -0700

----------------------------------------------------------------------
 libs/os/include/os/os_mbuf.h |  3 +++
 libs/os/src/os_mbuf.c        | 39 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 42 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/98181d76/libs/os/include/os/os_mbuf.h
----------------------------------------------------------------------
diff --git a/libs/os/include/os/os_mbuf.h b/libs/os/include/os/os_mbuf.h
index 831d770..82aef4d 100644
--- a/libs/os/include/os/os_mbuf.h
+++ b/libs/os/include/os/os_mbuf.h
@@ -267,6 +267,9 @@ int os_mbuf_copydata(const struct os_mbuf *m, int off, int len, void *dst);
 /* Append data onto a mbuf */
 int os_mbuf_append(struct os_mbuf *m, const void *, uint16_t);
 
+int os_mbuf_appendfrom(struct os_mbuf *dst, const struct os_mbuf *src,
+                       uint16_t src_off, uint16_t len);
+
 /* Free a mbuf */
 int os_mbuf_free(struct os_mbuf *mb);
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/98181d76/libs/os/src/os_mbuf.c
----------------------------------------------------------------------
diff --git a/libs/os/src/os_mbuf.c b/libs/os/src/os_mbuf.c
index 65afc01..92c8bcc 100644
--- a/libs/os/src/os_mbuf.c
+++ b/libs/os/src/os_mbuf.c
@@ -509,6 +509,45 @@ err:
     return (rc);
 }
 
+/**
+ * Reads data from one mbuf and appends it to another.  On error, the specified
+ * data range may be partially appended.  Neither mbuf is required to contain
+ * an mbuf packet header.
+ *
+ * @param dst                   The mbuf to append to.
+ * @param src                   The mbuf to copy data from.
+ * @param src_off               The absolute offset within the source mbuf
+ *                                  chain to read from.
+ * @param len                   The number of bytes to append.
+ */
+int
+os_mbuf_appendfrom(struct os_mbuf *dst, const struct os_mbuf *src,
+                   uint16_t src_off, uint16_t len)
+{
+    const struct os_mbuf *src_cur_om;
+    uint16_t chunk_sz;
+    int src_cur_off;
+    int rc;
+
+    src_cur_om = os_mbuf_off(src, src_off, &src_cur_off);
+    if (src_cur_om == NULL) {
+        return OS_EINVAL;
+    }
+
+    while (len > 0) {
+        chunk_sz = min(len, src_cur_om->om_len - src_cur_off);
+        rc = os_mbuf_append(dst, src_cur_om->om_data + src_cur_off, chunk_sz);
+        if (rc != 0) {
+            return rc;
+        }
+
+        len -= chunk_sz;
+        src_cur_om = SLIST_NEXT(src_cur_om, om_next);
+        src_cur_off = 0;
+    }
+
+    return 0;
+}
 
 /**
  * Duplicate a chain of mbufs.  Return the start of the duplicated chain.


[40/50] [abbrv] incubator-mynewt-core git commit: bletiny - use new rssi function.

Posted by cc...@apache.org.
bletiny - use new rssi function.


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

Branch: refs/heads/ble_hs_api
Commit: 4cb430acb9b0371e425ca6ae041f235549dbdec5
Parents: 98181d7
Author: Christopher Collins <cc...@apache.org>
Authored: Fri Jul 8 19:46:56 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Jul 11 16:43:34 2016 -0700

----------------------------------------------------------------------
 apps/bletiny/src/main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4cb430ac/apps/bletiny/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/main.c b/apps/bletiny/src/main.c
index b8a1fbe..e7aab28 100755
--- a/apps/bletiny/src/main.c
+++ b/apps/bletiny/src/main.c
@@ -1512,7 +1512,7 @@ bletiny_rssi(uint16_t conn_handle, int8_t *out_rssi)
 {
     int rc;
 
-    rc = ble_hci_util_read_rssi(conn_handle, out_rssi);
+    rc = ble_gap_conn_rssi(conn_handle, out_rssi);
     if (rc != 0) {
         return rc;
     }


[25/50] [abbrv] incubator-mynewt-core git commit: BLE Host - GATT client cb: error arg never null.

Posted by cc...@apache.org.
BLE Host - GATT client cb: error arg never null.

Prior to this change, the GATT client indicated success by passing a
null error argument to the application callback.  This made it
unnecessarily difficult for application code, because it would always
have to check error for null before looking at its status field.

Now, the error argument is never null.  Success is indicated by setting
error->status = 0.


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

Branch: refs/heads/ble_hs_api
Commit: 079aff14eafdec45d0aab5a7874d8ec35df6826e
Parents: 787463b
Author: Christopher Collins <cc...@apache.org>
Authored: Wed Jun 29 12:39:45 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Jul 11 16:43:32 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/src/ble_gattc.c                 | 3 ++-
 net/nimble/host/src/test/ble_gatt_disc_c_test.c | 2 +-
 net/nimble/host/src/test/ble_gatt_disc_d_test.c | 2 +-
 net/nimble/host/src/test/ble_gatt_disc_s_test.c | 2 +-
 net/nimble/host/src/test/ble_gatt_find_s_test.c | 2 +-
 net/nimble/host/src/test/ble_gatt_read_test.c   | 8 ++++++--
 net/nimble/host/src/test/ble_gatt_write_test.c  | 9 +++++----
 7 files changed, 17 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/079aff14/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 98e90cd..9081c80 100644
--- a/net/nimble/host/src/ble_gattc.c
+++ b/net/nimble/host/src/ble_gattc.c
@@ -888,8 +888,9 @@ ble_gattc_error(int status, uint16_t att_handle)
 {
     static struct ble_gatt_error error;
 
+    /* For consistency, always indicate a handle of 0 on success. */
     if (status == 0) {
-        return NULL;
+        att_handle = 0;
     }
 
     error.status = status;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/079aff14/net/nimble/host/src/test/ble_gatt_disc_c_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_gatt_disc_c_test.c b/net/nimble/host/src/test/ble_gatt_disc_c_test.c
index 0a1f7fd..01a26f7 100644
--- a/net/nimble/host/src/test/ble_gatt_disc_c_test.c
+++ b/net/nimble/host/src/test/ble_gatt_disc_c_test.c
@@ -175,7 +175,7 @@ ble_gatt_disc_c_test_misc_cb(uint16_t conn_handle,
     struct ble_gatt_chr *dst;
     int *stop_after;
 
-    TEST_ASSERT(error == NULL);
+    TEST_ASSERT(error != NULL && error->status == 0);
     TEST_ASSERT(!ble_gatt_disc_c_test_rx_complete);
 
     stop_after = arg;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/079aff14/net/nimble/host/src/test/ble_gatt_disc_d_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_gatt_disc_d_test.c b/net/nimble/host/src/test/ble_gatt_disc_d_test.c
index a2bb5a2..7ba58c4 100644
--- a/net/nimble/host/src/test/ble_gatt_disc_d_test.c
+++ b/net/nimble/host/src/test/ble_gatt_disc_d_test.c
@@ -164,7 +164,7 @@ ble_gatt_disc_d_test_misc_cb(uint16_t conn_handle,
     struct ble_gatt_disc_d_test_dsc *dst;
     int *stop_after;
 
-    TEST_ASSERT(error == NULL);
+    TEST_ASSERT(error != NULL && error->status == 0);
     TEST_ASSERT(!ble_gatt_disc_d_test_rx_complete);
 
     stop_after = arg;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/079aff14/net/nimble/host/src/test/ble_gatt_disc_s_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_gatt_disc_s_test.c b/net/nimble/host/src/test/ble_gatt_disc_s_test.c
index b29aacf..346c71b 100644
--- a/net/nimble/host/src/test/ble_gatt_disc_s_test.c
+++ b/net/nimble/host/src/test/ble_gatt_disc_s_test.c
@@ -223,7 +223,7 @@ ble_gatt_disc_s_test_misc_disc_cb(uint16_t conn_handle,
                                   const struct ble_gatt_svc *service,
                                   void *arg)
 {
-    TEST_ASSERT(error == NULL);
+    TEST_ASSERT(error != NULL && error->status == 0);
     TEST_ASSERT(!ble_gatt_disc_s_test_rx_complete);
 
     if (service == NULL) {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/079aff14/net/nimble/host/src/test/ble_gatt_find_s_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_gatt_find_s_test.c b/net/nimble/host/src/test/ble_gatt_find_s_test.c
index 3e190a6..d9eb0e8 100644
--- a/net/nimble/host/src/test/ble_gatt_find_s_test.c
+++ b/net/nimble/host/src/test/ble_gatt_find_s_test.c
@@ -51,7 +51,7 @@ ble_gatt_find_s_test_misc_cb(uint16_t conn_handle,
                              void *arg)
 {
     TEST_ASSERT(!ble_gatt_find_s_test_proc_complete);
-    TEST_ASSERT(error == NULL);
+    TEST_ASSERT(error != NULL && error->status == 0);
 
     if (service == NULL) {
         ble_gatt_find_s_test_proc_complete = 1;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/079aff14/net/nimble/host/src/test/ble_gatt_read_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_gatt_read_test.c b/net/nimble/host/src/test/ble_gatt_read_test.c
index 57a0624..d587702 100644
--- a/net/nimble/host/src/test/ble_gatt_read_test.c
+++ b/net/nimble/host/src/test/ble_gatt_read_test.c
@@ -65,7 +65,9 @@ ble_gatt_read_test_cb(uint16_t conn_handle, const struct ble_gatt_error *error,
 
     stop_after = arg;
 
-    if (error != NULL) {
+    TEST_ASSERT_FATAL(error != NULL);
+
+    if (error->status != 0) {
         ble_gatt_read_test_bad_conn_handle = conn_handle;
         ble_gatt_read_test_bad_status = error->status;
         ble_gatt_read_test_complete = 1;
@@ -111,7 +113,9 @@ ble_gatt_read_test_long_cb(uint16_t conn_handle,
 
     reads_left = arg;
 
-    if (error != NULL) {
+    TEST_ASSERT_FATAL(error != NULL);
+
+    if (error->status != 0) {
         ble_gatt_read_test_bad_conn_handle = conn_handle;
         ble_gatt_read_test_bad_status = error->status;
         ble_gatt_read_test_complete = 1;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/079aff14/net/nimble/host/src/test/ble_gatt_write_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_gatt_write_test.c b/net/nimble/host/src/test/ble_gatt_write_test.c
index 98809d1..0581524 100644
--- a/net/nimble/host/src/test/ble_gatt_write_test.c
+++ b/net/nimble/host/src/test/ble_gatt_write_test.c
@@ -60,13 +60,14 @@ ble_gatt_write_test_cb_good(uint16_t conn_handle,
 
     attr_len = arg;
 
+    TEST_ASSERT(error != NULL);
     TEST_ASSERT(conn_handle == 2);
+
+    ble_gatt_write_test_error = *error;
+
     if (attr_len != NULL) {
-        TEST_ASSERT(error == NULL);
+        TEST_ASSERT(error->status == 0);
         TEST_ASSERT(attr->handle == 100);
-    } else {
-        TEST_ASSERT(error != NULL);
-        ble_gatt_write_test_error = *error;
     }
 
     ble_gatt_write_test_cb_called = 1;


[49/50] [abbrv] incubator-mynewt-core git commit: BLE Host - Additional doxygen comments.

Posted by cc...@apache.org.
BLE Host - Additional doxygen comments.


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

Branch: refs/heads/ble_hs_api
Commit: 3714aea7a2e5fe52fcdb87f8214f7e1ed6187ea5
Parents: cd66efc
Author: Christopher Collins <cc...@apache.org>
Authored: Sat Jul 9 12:37:06 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Jul 11 16:43:35 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/include/host/ble_att.h  | 151 ++++++++++++---------------
 net/nimble/host/include/host/ble_gatt.h |  15 +++
 net/nimble/host/src/ble_att.c           |  16 +++
 net/nimble/host/src/ble_att_priv.h      |  24 +++++
 net/nimble/host/src/ble_att_svr.c       |  33 ++++++
 5 files changed, 154 insertions(+), 85 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3714aea7/net/nimble/host/include/host/ble_att.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/ble_att.h b/net/nimble/host/include/host/ble_att.h
index 848943e..6137d25 100644
--- a/net/nimble/host/include/host/ble_att.h
+++ b/net/nimble/host/include/host/ble_att.h
@@ -90,98 +90,79 @@
 #define BLE_ATT_ACCESS_OP_WRITE             2
 
 /**
- * Context for reads of characteristics and descriptors.  An instance of this
- * gets passed to an application callback whenever a local characteristic or
- * descriptor is read.
+ * Context for an access to an ATT attribute.  When a client reads or writes a
+ * locally registered attribute, an instance of this struct gets passed to the
+ * access callback.
  */
-struct ble_att_read_ctxt {
-    /**
-     * (stack --> app)
-     * Maximum number of data bytes the stack can send in the read response.
-     * This is based on the connection's ATT MTU.
-     */
-    uint16_t max_data_len;
-
-    /**
-     * (stack --> app)
-     * A buffer that the app can use to write the characteristic response value
-     * to.  This buffer can hold up to max_data_len bytes.
-     */
-    uint8_t *buf;
-
-    /**
-     * (app --> stack)
-     * App points this at the characteristic data to respond with.  Initially
-     * this points to "buf".
-     */
-    const void *data;
-
-    /**
-     * (app --> stack)
-     * App fills this with the number of data bytes contained in characteristic
-     * response.
-     */
-    uint16_t len;
-
-    uint16_t offset;
-};
-
-/**
- * Context for writes of characteristics and descriptors.  An instance of this
- * gets passed to an application callback whenever a local characteristic or
- * descriptor is written.
- */
-struct ble_att_write_ctxt {
-    /**
-     * (stack --> app)
-     * The data that the peer is writing to the characteristic.
-     */
-    const void *data;
-
+struct ble_att_svr_access_ctxt {
     /**
-     * (stack --> app)
-     * The number of bytes of characteristic data being written.
+     * The ATT operation being performed dictates which field in this union is
+     * valid.  If a read is being performed, the read field is valid.
+     * Otherwise, a write is being performed, in which case the write field is
+     * valid.
      */
-    int len;
-
-    uint16_t offset;
-};
-
-struct ble_att_svr_access_ctxt {
     union {
-        struct ble_att_read_ctxt read;
-        struct ble_att_write_ctxt write;
+        /** Context for reads of ATT attributes. */
+        struct {
+            /**
+             * (stack --> app)
+             * The offset within the attribute that the client is reading from.
+             */
+            uint16_t offset;
+
+            /**
+             * (stack --> app)
+             * Maximum number of data bytes the stack can send in the read
+             * response.  This is based on the connection's ATT MTU.
+             */
+            uint16_t max_data_len;
+
+            /**
+             * (stack --> app)
+             * A buffer that the app can use to write the characteristic
+             * response value to.  This buffer can hold up to max_data_len
+             * bytes.
+             */
+            uint8_t *buf;
+
+            /**
+             * (app --> stack)
+             * App points this at the characteristic data to respond with.
+             * Initially this points to "buf".
+             */
+            const void *data;
+
+            /**
+             * (app --> stack)
+             * App fills this with the number of data bytes contained in
+             * characteristic response.
+             */
+            uint16_t len;
+        } read;
+
+        /** Context for writes of ATT attributes. */
+        struct {
+            /**
+             * (stack --> app)
+             * The data that the peer is writing to the characteristic.
+             */
+            const void *data;
+
+            /**
+             * (stack --> app)
+             * The offset within the attribute that the client is writing to.
+             */
+            uint16_t offset;
+
+            /**
+             * (stack --> app)
+             * The number of bytes of characteristic data being written.
+             */
+            int len;
+        } write;
     };
 };
 
-/**
- * Handles a host attribute request.
- *
- * @param entry                 The host attribute being requested.
- * @param op                    The operation being performed on the attribute.
- * @param arg                   The request data associated with that host
- *                                  attribute.
- *
- * @return                      0 on success;
- *                              One of the BLE_ATT_ERR_[...] codes on
- *                                  failure.
- */
-typedef int ble_att_svr_access_fn(uint16_t conn_handle, uint16_t attr_handle,
-                                  uint8_t *uuid128, uint8_t op,
-                                  struct ble_att_svr_access_ctxt *ctxt,
-                                  void *arg);
-
-int ble_att_svr_register(const uint8_t *uuid, uint8_t flags,
-                         uint16_t *handle_id,
-                         ble_att_svr_access_fn *cb, void *cb_arg);
-int ble_att_svr_register_uuid16(uint16_t uuid16, uint8_t flags,
-                                uint16_t *handle_id, ble_att_svr_access_fn *cb,
-                                void *cb_arg);
-
-typedef int ble_att_svr_notify_fn(uint16_t conn_handle, uint16_t attr_handle,
-                                  uint8_t *attr_val, uint16_t attr_len,
-                                  void *arg);
-
 int ble_att_svr_read_local(uint16_t attr_handle, const void **out_data,
                            uint16_t *out_attr_len);
 int ble_att_svr_write_local(uint16_t attr_handle, const void *data,

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3714aea7/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 e69e59b..2697f71 100644
--- a/net/nimble/host/include/host/ble_gatt.h
+++ b/net/nimble/host/include/host/ble_gatt.h
@@ -250,7 +250,18 @@ struct ble_gatt_svc_def {
     const struct ble_gatt_chr_def *characteristics;
 };
 
+/**
+ * Context for an access to a GATT characteristic or descriptor.  When a client
+ * reads or writes a locally registered characteristic or descriptor, an
+ * instance of this struct gets passed to the application callback.
+ */
 struct ble_gatt_access_ctxt {
+    /**
+     * The GATT operation being performed dictates which field in this union is
+     * valid.  If a characteristic is being accessed, the chr field is valid.
+     * Otherwise, a descriptor is being accessed, in which case the dsc field
+     * is valid.
+     */
     union {
         /**
          * The characteristic definition corresponding to the characteristic
@@ -265,6 +276,10 @@ struct ble_gatt_access_ctxt {
         const struct ble_gatt_dsc_def *dsc;
     };
 
+    /**
+     * Context describing the underlying ATT access.  Specifies additional
+     * details about the read or write being performed.
+     */
     struct ble_att_svr_access_ctxt *att;
 };
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3714aea7/net/nimble/host/src/ble_att.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att.c b/net/nimble/host/src/ble_att.c
index 68e1c7b..6866bc1 100644
--- a/net/nimble/host/src/ble_att.c
+++ b/net/nimble/host/src/ble_att.c
@@ -459,6 +459,22 @@ ble_att_set_peer_mtu(struct ble_l2cap_chan *chan, uint16_t peer_mtu)
     chan->blc_peer_mtu = peer_mtu;
 }
 
+/**
+ * Sets the preferred ATT MTU; the device will indicate this value in all
+ * subseqeunt ATT MTU exchanges.  The ATT MTU of a connection is equal to the
+ * lower of the two peers' preferred MTU values.  The ATT MTU is what dictates
+ * the maximum size of any message sent during a GATT procedure.
+ *
+ * The specified MTU must be within the following range: [23, BLE_ATT_MTU_MAX].
+ * 23 is a minimum imposed by the Bluetooth specification; BLE_ATT_MTU_MAX is a
+ * NimBLE compile-time setting.
+ *
+ * @param mtu                   The preferred ATT MTU.
+ *
+ * @return                      0 on success;
+ *                              BLE_HS_EINVAL if the specifeid value is not
+ *                                  within the allowed range.
+ */
 int
 ble_att_set_preferred_mtu(uint16_t mtu)
 {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3714aea7/net/nimble/host/src/ble_att_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att_priv.h b/net/nimble/host/src/ble_att_priv.h
index c1da676..36bdf6b 100644
--- a/net/nimble/host/src/ble_att_priv.h
+++ b/net/nimble/host/src/ble_att_priv.h
@@ -123,6 +123,30 @@ struct ble_att_svr_conn {
     uint32_t basc_prep_write_rx_time;
 };
 
+/**
+ * Handles a host attribute request.
+ *
+ * @param entry                 The host attribute being requested.
+ * @param op                    The operation being performed on the attribute.
+ * @param arg                   The request data associated with that host
+ *                                  attribute.
+ *
+ * @return                      0 on success;
+ *                              One of the BLE_ATT_ERR_[...] codes on
+ *                                  failure.
+ */
+typedef int ble_att_svr_access_fn(uint16_t conn_handle, uint16_t attr_handle,
+                                  uint8_t *uuid128, uint8_t op,
+                                  struct ble_att_svr_access_ctxt *ctxt,
+                                  void *arg);
+
+int ble_att_svr_register(const uint8_t *uuid, uint8_t flags,
+                         uint16_t *handle_id,
+                         ble_att_svr_access_fn *cb, void *cb_arg);
+int ble_att_svr_register_uuid16(uint16_t uuid16, uint8_t flags,
+                                uint16_t *handle_id, ble_att_svr_access_fn *cb,
+                                void *cb_arg);
+
 struct ble_att_svr_entry {
     STAILQ_ENTRY(ble_att_svr_entry) ha_next;
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3714aea7/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 4d6fe15..3471f0d 100644
--- a/net/nimble/host/src/ble_att_svr.c
+++ b/net/nimble/host/src/ble_att_svr.c
@@ -378,6 +378,23 @@ ble_att_svr_read_handle(uint16_t conn_handle, uint16_t attr_handle,
     return 0;
 }
 
+/**
+ * Reads a locally registered attribute.  If the specified attribute handle
+ * coresponds to a GATT characteristic value or descriptor, the read is
+ * performed by calling the registered GATT access callback.
+ *
+ * @param attr_handle           The 16-bit handle of the attribute to read.
+ * @param out_data              On success, this points to the attribute data
+ *                                  just read.
+ * @param out_attr_len          On success, this points to the number of bytes
+ *                                  of attribute data just read.
+ *
+ * @return                      0 on success
+ *                              NimBLE host ATT return code if the attribute
+ *                                  access callback reports failure;
+ *                              NimBLE host core return code on unexpected
+ *                                  error.
+ */
 int
 ble_att_svr_read_local(uint16_t attr_handle, const void **out_data,
                        uint16_t *out_attr_len)
@@ -2243,6 +2260,22 @@ ble_att_svr_rx_write_no_rsp(uint16_t conn_handle, struct os_mbuf **rxom)
     return 0;
 }
 
+/**
+ * Writes a locally registered attribute.  If the specified attribute handle
+ * coresponds to a GATT characteristic value or descriptor, the write is
+ * performed by calling the registered GATT access callback.
+ *
+ * @param attr_handle           The 16-bit handle of the attribute to write.
+ * @param data                  Buffer containing the data to write to the
+ *                                  attribute.
+ * @param data_len              The number of bytes to write.
+ *
+ * @return                      0 on success
+ *                              NimBLE host ATT return code if the attribute
+ *                                  access callback reports failure;
+ *                              NimBLE host core return code on unexpected
+ *                                  error.
+ */
 int
 ble_att_svr_write_local(uint16_t attr_handle, const void *data,
                         uint16_t data_len)


[14/50] [abbrv] incubator-mynewt-core git commit: BLE Host - handle direct advertising report event.

Posted by cc...@apache.org.
BLE Host - handle direct advertising report event.


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

Branch: refs/heads/ble_hs_api
Commit: e4c0c0ad4966a7329de4d3ea317a4f2061896732
Parents: 9e781e9
Author: Christopher Collins <cc...@apache.org>
Authored: Thu Jun 23 20:34:36 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Jul 11 16:43:31 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/include/host/ble_gap.h      | 16 +++-
 net/nimble/host/src/ble_eddystone.c         |  1 +
 net/nimble/host/src/ble_gap.c               | 44 +++++------
 net/nimble/host/src/ble_gap_priv.h          |  2 +-
 net/nimble/host/src/ble_hs_adv.c            |  1 +
 net/nimble/host/src/ble_hs_adv_priv.h       | 35 ---------
 net/nimble/host/src/ble_hs_priv.h           |  2 +-
 net/nimble/host/src/ble_ibeacon.c           |  1 +
 net/nimble/host/src/host_hci.c              | 97 ++++++++++++++++++++----
 net/nimble/host/src/test/ble_gap_test.c     | 32 ++++----
 net/nimble/host/src/test/ble_hs_adv_test.c  |  1 +
 net/nimble/host/src/test/ble_hs_conn_test.c |  1 +
 net/nimble/host/src/test/ble_hs_test_util.c |  1 +
 net/nimble/include/nimble/hci_common.h      |  3 +
 14 files changed, 146 insertions(+), 91 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e4c0c0ad/net/nimble/host/include/host/ble_gap.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/ble_gap.h b/net/nimble/host/include/host/ble_gap.h
index 707b10b..90b3f85 100644
--- a/net/nimble/host/include/host/ble_gap.h
+++ b/net/nimble/host/include/host/ble_gap.h
@@ -43,9 +43,12 @@ struct hci_conn_update;
 /** 60 ms; active scanning. */
 #define BLE_GAP_SCAN_FAST_INTERVAL_MAX      (60 * 1000 / BLE_HCI_ADV_ITVL)
 
-/** 11.25 seconds; limited discovery interval. */
+/** 11.25 ms; limited discovery interval. */
 #define BLE_GAP_LIM_DISC_SCAN_INT           (11.25 * 1000 / BLE_HCI_SCAN_ITVL)
 
+/** 11.25 ms; limited discovery window (not from the spec). */
+#define BLE_GAP_LIM_DISC_SCAN_WINDOW        (11.25 * 1000 / BLE_HCI_SCAN_ITVL)
+
 /** 30 ms; active scanning. */
 #define BLE_GAP_SCAN_FAST_WINDOW            (30 * 1000 / BLE_HCI_SCAN_ITVL)
 
@@ -90,6 +93,7 @@ struct hci_conn_update;
 #define BLE_GAP_APPEARANCE_GEN_COMPUTER                 128
 
 #define BLE_GAP_ADDR_TYPE_WL                0xff
+#define BLE_GAP_ADDR_TYPE_NONE              0xfe
 
 #define BLE_GAP_EVENT_CONNECT               0
 #define BLE_GAP_EVENT_DISCONNECT            1
@@ -245,13 +249,23 @@ typedef int ble_gap_event_fn(int event, struct ble_gap_conn_ctxt *ctxt,
                              void *arg);
 
 struct ble_gap_disc_desc {
+    /*** Common fields. */
     uint8_t event_type;
     uint8_t addr_type;
     uint8_t length_data;
     int8_t rssi;
     uint8_t addr[6];
+
+    /*** LE advertising report fields; both null if no data present. */
     uint8_t *data;
     struct ble_hs_adv_fields *fields;
+
+    /***
+     * LE direct advertising report fields; direct_addr_type is
+     * BLE_GAP_ADDR_TYPE_NONE if direct address fields are not present.
+     */
+    uint8_t direct_addr_type;
+    uint8_t direct_addr[6];
 };
 
 typedef void ble_gap_disc_fn(int event, int status,

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e4c0c0ad/net/nimble/host/src/ble_eddystone.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_eddystone.c b/net/nimble/host/src/ble_eddystone.c
index dbd8a71..2030c79 100644
--- a/net/nimble/host/src/ble_eddystone.c
+++ b/net/nimble/host/src/ble_eddystone.c
@@ -19,6 +19,7 @@
 
 #include <string.h>
 #include "host/ble_eddystone.h"
+#include "host/ble_hs_adv.h"
 #include "ble_hs_priv.h"
 
 #define BLE_EDDYSTONE_MAX_SVC_DATA_LEN  23

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e4c0c0ad/net/nimble/host/src/ble_gap.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gap.c b/net/nimble/host/src/ble_gap.c
index 57502f8..cf80b7e 100644
--- a/net/nimble/host/src/ble_gap.c
+++ b/net/nimble/host/src/ble_gap.c
@@ -24,6 +24,7 @@
 #include "os/os.h"
 #include "nimble/nimble_opt.h"
 #include "host/host_hci.h"
+#include "host/ble_hs_adv.h"
 #include "ble_hs_priv.h"
 
 /**
@@ -497,27 +498,15 @@ ble_gap_master_connect_cancel(void)
 }
 
 static void
-ble_gap_call_master_disc_cb(int event, int status, struct ble_hs_adv *adv,
+ble_gap_call_master_disc_cb(int event, int status,
+                            struct ble_gap_disc_desc *desc,
                             struct ble_hs_adv_fields *fields, int reset_state)
 {
-    struct ble_gap_disc_desc desc;
     ble_gap_disc_fn *cb;
     void *cb_arg;
 
     ble_hs_lock();
 
-    if (adv != NULL) {
-        desc.event_type = adv->event_type;
-        desc.addr_type = adv->addr_type;
-        desc.length_data = adv->length_data;
-        desc.rssi = adv->rssi;
-        memcpy(desc.addr, adv->addr, sizeof adv->addr);
-        desc.data = adv->data;
-        desc.fields = fields;
-    } else {
-        memset(&desc, 0, sizeof desc);
-    }
-
     cb = ble_gap_master.disc.cb;
     cb_arg = ble_gap_master.disc.cb_arg;
 
@@ -528,7 +517,7 @@ ble_gap_call_master_disc_cb(int event, int status, struct ble_hs_adv *adv,
     ble_hs_unlock();
 
     if (cb != NULL) {
-        cb(event, status, &desc, cb_arg);
+        cb(event, status, desc, cb_arg);
     }
 }
 
@@ -870,7 +859,7 @@ ble_gap_accept_slave_conn(uint8_t addr_type, uint8_t *addr)
 }
 
 void
-ble_gap_rx_adv_report(struct ble_hs_adv *adv)
+ble_gap_rx_adv_report(struct ble_gap_disc_desc *desc)
 {
 #if !NIMBLE_OPT(ROLE_OBSERVER)
     return;
@@ -885,19 +874,22 @@ ble_gap_rx_adv_report(struct ble_hs_adv *adv)
         return;
     }
 
-    rc = ble_hs_adv_parse_fields(&fields, adv->data, adv->length_data);
+    rc = ble_hs_adv_parse_fields(&fields, desc->data, desc->length_data);
     if (rc != 0) {
         /* XXX: Increment stat. */
         return;
     }
 
+    /* If a limited discovery procedure is active, discard non-limited
+     * advertisements.
+     */
     if (ble_gap_master.disc.limited &&
         !(fields.flags & BLE_HS_ADV_F_DISC_LTD)) {
 
         return;
     }
 
-    ble_gap_call_master_disc_cb(BLE_GAP_EVENT_DISC_SUCCESS, 0, adv,
+    ble_gap_call_master_disc_cb(BLE_GAP_EVENT_DISC_SUCCESS, 0, desc,
                                 &fields, 0);
 }
 
@@ -1777,7 +1769,9 @@ ble_gap_disc_tx_params(uint8_t own_addr_type,
                                                own_addr_type,
                                                disc_params->filter_policy,
                                                buf, sizeof buf);
-    BLE_HS_DBG_ASSERT_EVAL(rc == 0);
+    if (rc != 0) {
+        return BLE_HS_EINVAL;
+    }
 
     rc = ble_hci_cmd_tx_empty_ack(buf);
     if (rc != 0) {
@@ -1834,12 +1828,16 @@ ble_gap_disc_fill_dflts(struct ble_gap_disc_params *disc_params)
         if (disc_params->limited) {
             disc_params->itvl = BLE_GAP_LIM_DISC_SCAN_INT;
         } else {
-            disc_params->itvl = BLE_GAP_SCAN_SLOW_INTERVAL1;
+            disc_params->itvl = BLE_GAP_SCAN_FAST_INTERVAL_MIN;
         }
     }
 
     if (disc_params->window == 0) {
-        disc_params->window = BLE_GAP_SCAN_SLOW_WINDOW1;
+        if (disc_params->limited) {
+            disc_params->window = BLE_GAP_LIM_DISC_SCAN_WINDOW;
+        } else {
+            disc_params->window = BLE_GAP_SCAN_FAST_WINDOW;
+        }
     }
 }
 
@@ -1855,10 +1853,6 @@ ble_gap_disc_validate(uint8_t own_addr_type,
         return BLE_HS_EINVAL;
     }
 
-    if (disc_params->filter_policy > BLE_HCI_SCAN_FILT_MAX) {
-        return BLE_HS_EINVAL;
-    }
-
     if (ble_gap_master.op != BLE_GAP_OP_NULL) {
         return BLE_HS_EALREADY;
     }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e4c0c0ad/net/nimble/host/src/ble_gap_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gap_priv.h b/net/nimble/host/src/ble_gap_priv.h
index f0f3135..91bbd31 100644
--- a/net/nimble/host/src/ble_gap_priv.h
+++ b/net/nimble/host/src/ble_gap_priv.h
@@ -69,7 +69,7 @@ extern STATS_SECT_DECL(ble_gap_stats) ble_gap_stats;
 #define BLE_GAP_DISC_MODE_MAX               3
 
 int ble_gap_locked_by_cur_task(void);
-void ble_gap_rx_adv_report(struct ble_hs_adv *adv);
+void ble_gap_rx_adv_report(struct ble_gap_disc_desc *desc);
 int ble_gap_rx_conn_complete(struct hci_le_conn_complete *evt);
 void ble_gap_rx_disconn_complete(struct hci_disconn_complete *evt);
 void ble_gap_rx_update_complete(struct hci_le_conn_upd_complete *evt);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e4c0c0ad/net/nimble/host/src/ble_hs_adv.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_adv.c b/net/nimble/host/src/ble_hs_adv.c
index 853d04a..83dd416 100644
--- a/net/nimble/host/src/ble_hs_adv.c
+++ b/net/nimble/host/src/ble_hs_adv.c
@@ -20,6 +20,7 @@
 #include <string.h>
 #include <errno.h>
 #include "nimble/ble.h"
+#include "host/ble_hs_adv.h"
 #include "ble_hs_priv.h"
 
 static int

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e4c0c0ad/net/nimble/host/src/ble_hs_adv_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_adv_priv.h b/net/nimble/host/src/ble_hs_adv_priv.h
deleted file mode 100644
index 5b85374..0000000
--- a/net/nimble/host/src/ble_hs_adv_priv.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- * 
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-#ifndef H_BLE_HS_ADV_PRIV_
-#define H_BLE_HS_ADV_PRIV_
-
-#include "host/ble_hs_adv.h"
-
-struct ble_hs_adv {
-    uint8_t event_type;
-    uint8_t addr_type;
-    uint8_t length_data;
-    int8_t rssi;
-    uint8_t addr[6];
-    uint8_t *data;
-    struct ble_hs_adv_fields *fields;
-};
-
-#endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e4c0c0ad/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 8c0b47f..1eeb57f 100644
--- a/net/nimble/host/src/ble_hs_priv.h
+++ b/net/nimble/host/src/ble_hs_priv.h
@@ -27,9 +27,9 @@
 #include "ble_gap_priv.h"
 #include "ble_gatt_priv.h"
 #include "ble_hci_util_priv.h"
-#include "ble_hs_adv_priv.h"
 #include "ble_hs_atomic_priv.h"
 #include "ble_hs_conn_priv.h"
+#include "ble_hs_atomic_priv.h"
 #include "ble_hs_endian_priv.h"
 #include "ble_hs_startup_priv.h"
 #include "ble_l2cap_priv.h"

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e4c0c0ad/net/nimble/host/src/ble_ibeacon.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_ibeacon.c b/net/nimble/host/src/ble_ibeacon.c
index db34dfb..06e203a 100644
--- a/net/nimble/host/src/ble_ibeacon.c
+++ b/net/nimble/host/src/ble_ibeacon.c
@@ -18,6 +18,7 @@
  */
 
 #include <string.h>
+#include "host/ble_hs_adv.h"
 #include "ble_hs_priv.h"
 
 #define BLE_IBEACON_MFG_DATA_SIZE       25

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e4c0c0ad/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 4452dcc..29c71a1 100644
--- a/net/nimble/host/src/host_hci.c
+++ b/net/nimble/host/src/host_hci.c
@@ -25,6 +25,7 @@
 #include "nimble/hci_common.h"
 #include "nimble/hci_transport.h"
 #include "host/host_hci.h"
+#include "host/ble_gap.h"
 #include "ble_hs_priv.h"
 #include "host_dbg_priv.h"
 
@@ -44,6 +45,7 @@ static host_hci_le_event_fn host_hci_rx_le_adv_rpt;
 static host_hci_le_event_fn host_hci_rx_le_conn_upd_complete;
 static host_hci_le_event_fn host_hci_rx_le_lt_key_req;
 static host_hci_le_event_fn host_hci_rx_le_conn_parm_req;
+static host_hci_le_event_fn host_hci_rx_le_dir_adv_rpt;
 
 static uint16_t host_hci_buffer_sz;
 static uint8_t host_hci_max_pkts;
@@ -90,6 +92,7 @@ static const struct host_hci_le_event_dispatch_entry
     { BLE_HCI_LE_SUBEV_LT_KEY_REQ, host_hci_rx_le_lt_key_req },
     { BLE_HCI_LE_SUBEV_REM_CONN_PARM_REQ, host_hci_rx_le_conn_parm_req },
     { BLE_HCI_LE_SUBEV_ENH_CONN_COMPLETE, host_hci_rx_le_conn_complete },
+    { BLE_HCI_LE_SUBEV_DIRECT_ADV_RPT, host_hci_rx_le_dir_adv_rpt },
 };
 
 #define HOST_HCI_LE_EVENT_DISPATCH_SZ \
@@ -363,10 +366,11 @@ host_hci_le_adv_rpt_first_pass(uint8_t *data, int len,
 static int
 host_hci_rx_le_adv_rpt(uint8_t subevent, uint8_t *data, int len)
 {
-    struct ble_hs_adv adv;
+    struct ble_gap_disc_desc desc;
     uint8_t num_reports;
     int rssi_off;
     int data_off;
+    int suboff;
     int off;
     int rc;
     int i;
@@ -376,28 +380,93 @@ host_hci_rx_le_adv_rpt(uint8_t subevent, uint8_t *data, int len)
         return rc;
     }
 
+    /* Direct address fields not present in a standard advertising report. */
+    desc.direct_addr_type = BLE_GAP_ADDR_TYPE_NONE;
+    memset(desc.direct_addr, 0, sizeof desc.direct_addr);
+
     data_off = 0;
     for (i = 0; i < num_reports; i++) {
-        off = 2 + 0 * num_reports + i;
-        adv.event_type = data[2 + 0 * num_reports + i];
+        suboff = 0;
+
+        off = 2 + suboff * num_reports + i;
+        desc.event_type = data[off];
+        suboff++;
 
-        off = 2 + 1 * num_reports + i;
-        adv.addr_type = data[2 + 1 * num_reports + i];
+        off = 2 + suboff * num_reports + i;
+        desc.addr_type = data[off];
+        suboff++;
 
-        off = 2 + 2 * num_reports + i * 6;
-        memcpy(adv.addr, data + off, 6);
+        off = 2 + suboff * num_reports + i * 6;
+        memcpy(desc.addr, data + off, 6);
+        suboff += 6;
 
-        off = 2 + 8 * num_reports + i;
-        adv.length_data = data[off];
+        off = 2 + suboff * num_reports + i;
+        desc.length_data = data[off];
+        suboff++;
 
-        off = 2 + 9 * num_reports + data_off;
-        adv.data = data + off;
-        data_off += adv.length_data;
+        off = 2 + suboff * num_reports + data_off;
+        desc.data = data + off;
+        data_off += desc.length_data;
 
         off = rssi_off + 1 * i;
-        adv.rssi = data[off];
+        desc.rssi = data[off];
+
+        ble_gap_rx_adv_report(&desc);
+    }
+
+    return 0;
+}
+
+static int
+host_hci_rx_le_dir_adv_rpt(uint8_t subevent, uint8_t *data, int len)
+{
+    struct ble_gap_disc_desc desc;
+    uint8_t num_reports;
+    int suboff;
+    int off;
+    int i;
+
+    if (len < BLE_HCI_LE_ADV_DIRECT_RPT_LEN) {
+        return BLE_HS_ECONTROLLER;
+    }
+
+    num_reports = data[1];
+    if (len != 2 + num_reports * BLE_HCI_LE_ADV_DIRECT_RPT_SUB_LEN) {
+        return BLE_HS_ECONTROLLER;
+    }
+
+    /* Data fields not present in a direct advertising report. */
+    desc.data = NULL;
+    desc.fields = NULL;
+
+    for (i = 0; i < num_reports; i++) {
+        suboff = 0;
+
+        off = 2 + suboff * num_reports + i;
+        desc.event_type = data[off];
+        suboff++;
+
+        off = 2 + suboff * num_reports + i;
+        desc.addr_type = data[off];
+        suboff++;
+
+        off = 2 + suboff * num_reports + i * 6;
+        memcpy(desc.addr, data + off, 6);
+        suboff += 6;
+
+        off = 2 + suboff * num_reports + i;
+        desc.direct_addr_type = data[off];
+        suboff++;
+
+        off = 2 + suboff * num_reports + i * 6;
+        memcpy(desc.direct_addr, data + off, 6);
+        suboff += 6;
+
+        off = 2 + suboff * num_reports + i;
+        desc.rssi = data[off];
+        suboff++;
 
-        ble_gap_rx_adv_report(&adv);
+        ble_gap_rx_adv_report(&desc);
     }
 
     return 0;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e4c0c0ad/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 b8dbc82..a175dc9 100644
--- a/net/nimble/host/src/test/ble_gap_test.c
+++ b/net/nimble/host/src/test/ble_gap_test.c
@@ -22,6 +22,7 @@
 #include "testutil/testutil.h"
 #include "nimble/ble.h"
 #include "nimble/hci_common.h"
+#include "host/ble_hs_adv.h"
 #include "host/ble_hs_test.h"
 #include "ble_hs_test_util.h"
 
@@ -512,7 +513,7 @@ TEST_SUITE(ble_gap_test_suite_conn_wl)
 static int
 ble_gap_test_util_disc(uint8_t own_addr_type,
                        const struct ble_gap_disc_params *disc_params,
-                       struct ble_hs_adv *adv, int cmd_fail_idx,
+                       struct ble_gap_disc_desc *desc, int cmd_fail_idx,
                        uint8_t fail_status)
 {
     int rc;
@@ -526,7 +527,7 @@ ble_gap_test_util_disc(uint8_t own_addr_type,
     TEST_ASSERT(rc == BLE_HS_HCI_ERR(fail_status));
     if (rc == 0) {
         TEST_ASSERT(ble_gap_master_in_progress());
-        ble_gap_rx_adv_report(adv);
+        ble_gap_rx_adv_report(desc);
     } else {
         TEST_ASSERT(ble_gap_test_disc_status == -1);
     }
@@ -591,7 +592,7 @@ TEST_CASE(ble_gap_test_case_disc_good)
     int limited;
     int rc;
 
-    struct ble_hs_adv adv = {
+    struct ble_gap_disc_desc desc = {
         .event_type = BLE_HCI_ADV_TYPE_ADV_IND,
         .addr_type = BLE_ADDR_TYPE_PUBLIC,
         .length_data = 0,
@@ -610,7 +611,7 @@ TEST_CASE(ble_gap_test_case_disc_good)
 
     flags = BLE_HS_ADV_F_DISC_LTD;
     rc = ble_hs_adv_set_flat(BLE_HS_ADV_TYPE_FLAGS, 1, &flags,
-                             adv.data, &adv.length_data,
+                             desc.data, &desc.length_data,
                              sizeof adv_data);
     TEST_ASSERT_FATAL(rc == 0);
 
@@ -621,7 +622,7 @@ TEST_CASE(ble_gap_test_case_disc_good)
     for (limited = 0; limited <= 1; limited++) {
         disc_params.passive = passive;
         disc_params.limited = limited;
-        ble_gap_test_util_disc(own_addr_type, &disc_params, &adv, -1, 0);
+        ble_gap_test_util_disc(own_addr_type, &disc_params, &desc, -1, 0);
 
         TEST_ASSERT(ble_gap_master_in_progress());
         TEST_ASSERT(ble_gap_test_disc_event == BLE_GAP_EVENT_DISC_SUCCESS);
@@ -632,7 +633,7 @@ TEST_CASE(ble_gap_test_case_disc_good)
                     BLE_ADDR_TYPE_PUBLIC);
         TEST_ASSERT(ble_gap_test_disc_desc.length_data == 3);
         TEST_ASSERT(ble_gap_test_disc_desc.rssi == 0);
-        TEST_ASSERT(memcmp(ble_gap_test_disc_desc.addr, adv.addr, 6) == 0);
+        TEST_ASSERT(memcmp(ble_gap_test_disc_desc.addr, desc.addr, 6) == 0);
         TEST_ASSERT(ble_gap_test_disc_arg == NULL);
     }
 }
@@ -640,7 +641,7 @@ TEST_CASE(ble_gap_test_case_disc_good)
 TEST_CASE(ble_gap_test_case_disc_ltd_mismatch)
 {
     int rc;
-    struct ble_hs_adv adv = {
+    struct ble_gap_disc_desc desc = {
         .event_type = BLE_HCI_ADV_TYPE_ADV_IND,
         .addr_type = BLE_ADDR_TYPE_PUBLIC,
         .length_data = 0,
@@ -661,7 +662,7 @@ TEST_CASE(ble_gap_test_case_disc_ltd_mismatch)
         .filter_duplicates = 0,
     };
 
-    rc = ble_gap_test_util_disc(BLE_ADDR_TYPE_PUBLIC, &disc_params, &adv,
+    rc = ble_gap_test_util_disc(BLE_ADDR_TYPE_PUBLIC, &disc_params, &desc,
                                 -1, 0);
     TEST_ASSERT(rc == 0);
     TEST_ASSERT(ble_gap_master_in_progress());
@@ -673,9 +674,9 @@ TEST_CASE(ble_gap_test_case_disc_ltd_mismatch)
     rc = ble_hs_test_util_disc_cancel(0);
     TEST_ASSERT(rc == 0);
 
-    adv.data[2] = BLE_HS_ADV_F_DISC_LTD;
+    desc.data[2] = BLE_HS_ADV_F_DISC_LTD;
     disc_params.limited = 0;
-    rc = ble_gap_test_util_disc(BLE_ADDR_TYPE_PUBLIC, &disc_params, &adv,
+    rc = ble_gap_test_util_disc(BLE_ADDR_TYPE_PUBLIC, &disc_params, &desc,
                                 -1, 0);
     TEST_ASSERT(rc == 0);
     TEST_ASSERT(ble_gap_master_in_progress());
@@ -692,7 +693,7 @@ TEST_CASE(ble_gap_test_case_disc_hci_fail)
     int limited;
     int rc;
 
-    struct ble_hs_adv adv = {
+    struct ble_gap_disc_desc desc = {
         .event_type = BLE_HCI_ADV_TYPE_ADV_IND,
         .addr_type = BLE_ADDR_TYPE_PUBLIC,
         .length_data = 0,
@@ -714,7 +715,7 @@ TEST_CASE(ble_gap_test_case_disc_hci_fail)
 
         for (fail_idx = 0; fail_idx < 2; fail_idx++) {
             rc = ble_gap_test_util_disc(BLE_ADDR_TYPE_PUBLIC, &disc_params,
-                                        &adv, fail_idx, BLE_ERR_UNSUPPORTED);
+                                        &desc, fail_idx, BLE_ERR_UNSUPPORTED);
             TEST_ASSERT(rc == BLE_HS_HCI_ERR(BLE_ERR_UNSUPPORTED));
             TEST_ASSERT(!ble_gap_master_in_progress());
         }
@@ -725,6 +726,7 @@ static void
 ble_gap_test_util_disc_dflts_once(int limited)
 {
     struct ble_gap_disc_params params;
+    uint16_t exp_window;
     uint16_t exp_itvl;
     int rc;
 
@@ -739,14 +741,16 @@ ble_gap_test_util_disc_dflts_once(int limited)
 
     if (limited) {
         exp_itvl = BLE_GAP_LIM_DISC_SCAN_INT;
+        exp_window = BLE_GAP_LIM_DISC_SCAN_WINDOW;
     } else {
-        exp_itvl = BLE_GAP_SCAN_SLOW_INTERVAL1;
+        exp_itvl = BLE_GAP_SCAN_FAST_INTERVAL_MIN;
+        exp_window = BLE_GAP_SCAN_FAST_WINDOW;
     }
     ble_gap_test_util_verify_tx_set_scan_params(
         BLE_ADDR_TYPE_PUBLIC,
         BLE_HCI_SCAN_TYPE_ACTIVE,
         exp_itvl,
-        BLE_GAP_SCAN_SLOW_WINDOW1,
+        exp_window,
         BLE_HCI_SCAN_FILT_NO_WL);
 
     ble_gap_test_util_verify_tx_scan_enable(1, 0);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e4c0c0ad/net/nimble/host/src/test/ble_hs_adv_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_hs_adv_test.c b/net/nimble/host/src/test/ble_hs_adv_test.c
index 1cd4370..3a78505 100644
--- a/net/nimble/host/src/test/ble_hs_adv_test.c
+++ b/net/nimble/host/src/test/ble_hs_adv_test.c
@@ -22,6 +22,7 @@
 #include <string.h>
 #include "testutil/testutil.h"
 #include "nimble/hci_common.h"
+#include "host/ble_hs_adv.h"
 #include "host/ble_hs_test.h"
 #include "host/host_hci.h"
 #include "ble_hs_test_util.h"

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e4c0c0ad/net/nimble/host/src/test/ble_hs_conn_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_hs_conn_test.c b/net/nimble/host/src/test/ble_hs_conn_test.c
index 50d70c9..ef643d7 100644
--- a/net/nimble/host/src/test/ble_hs_conn_test.c
+++ b/net/nimble/host/src/test/ble_hs_conn_test.c
@@ -22,6 +22,7 @@
 #include <string.h>
 #include "testutil/testutil.h"
 #include "nimble/hci_common.h"
+#include "host/ble_hs_adv.h"
 #include "host/ble_hs_test.h"
 #include "host/host_hci.h"
 #include "ble_hs_test_util.h"

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e4c0c0ad/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 f2f334f..1a08801 100644
--- a/net/nimble/host/src/test/ble_hs_test_util.c
+++ b/net/nimble/host/src/test/ble_hs_test_util.c
@@ -24,6 +24,7 @@
 #include "nimble/ble.h"
 #include "nimble/hci_common.h"
 #include "nimble/hci_transport.h"
+#include "host/ble_hs_adv.h"
 #include "host/host_hci.h"
 #include "ble_hs_test_util.h"
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e4c0c0ad/net/nimble/include/nimble/hci_common.h
----------------------------------------------------------------------
diff --git a/net/nimble/include/nimble/hci_common.h b/net/nimble/include/nimble/hci_common.h
index 0292be5..d5c8743 100644
--- a/net/nimble/include/nimble/hci_common.h
+++ b/net/nimble/include/nimble/hci_common.h
@@ -515,6 +515,9 @@
 #define BLE_HCI_LE_ADV_RPT_NUM_RPTS_MIN     (1)
 #define BLE_HCI_LE_ADV_RPT_NUM_RPTS_MAX     (0x19)
 
+/* Length of each record in an LE direct advertising report event. */
+#define BLE_HCI_LE_ADV_DIRECT_RPT_SUB_LEN   (16)
+
 /* LE connection update complete event (sub event 0x03) */
 #define BLE_HCI_LE_CONN_UPD_LEN             (10)
 


[06/50] [abbrv] incubator-mynewt-core git commit: bleprph - Use new advertise API.

Posted by cc...@apache.org.
bleprph - Use new advertise API.


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

Branch: refs/heads/ble_hs_api
Commit: 804b44566395eaab8791c0894c15abe60e96b2d4
Parents: b014354
Author: Christopher Collins <cc...@apache.org>
Authored: Thu Jun 23 15:05:28 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Jul 11 16:43:30 2016 -0700

----------------------------------------------------------------------
 apps/bleprph/src/main.c  | 8 ++++++--
 apps/bletiny/src/parse.c | 1 +
 2 files changed, 7 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/804b4456/apps/bleprph/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bleprph/src/main.c b/apps/bleprph/src/main.c
index 74c1e4d..c265dc5 100755
--- a/apps/bleprph/src/main.c
+++ b/apps/bleprph/src/main.c
@@ -124,6 +124,7 @@ bleprph_print_conn_desc(struct ble_gap_conn_desc *desc)
 static void
 bleprph_advertise(void)
 {
+    struct ble_gap_adv_params adv_params;
     struct ble_hs_adv_fields fields;
     int rc;
 
@@ -165,8 +166,11 @@ bleprph_advertise(void)
     }
 
     /* Begin advertising. */
-    rc = ble_gap_adv_start(BLE_GAP_DISC_MODE_GEN, BLE_GAP_CONN_MODE_UND,
-                           NULL, 0, NULL, bleprph_gap_event, NULL);
+    memset(&adv_params, 0, sizeof adv_params);
+    adv_params.conn_mode = BLE_GAP_CONN_MODE_UND;
+    adv_params.disc_mode = BLE_GAP_DISC_MODE_GEN;
+    rc = ble_gap_adv_start(BLE_ADDR_TYPE_PUBLIC, 0, NULL, &adv_params,
+                           bleprph_gap_event, NULL);
     if (rc != 0) {
         BLEPRPH_LOG(ERROR, "error enabling advertisement; rc=%d\n", rc);
         return;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/804b4456/apps/bletiny/src/parse.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/parse.c b/apps/bletiny/src/parse.c
index d5c64c5..927520b 100644
--- a/apps/bletiny/src/parse.c
+++ b/apps/bletiny/src/parse.c
@@ -242,6 +242,7 @@ parse_arg_kv(char *name, struct kv_pair *kvs, int *out_status)
         return -1;
     }
 
+    *out_status = 0;
     return kv->val;
 }
 


[27/50] [abbrv] incubator-mynewt-core git commit: BLE Host - Add missing fields to ble_gap_conn_desc

Posted by cc...@apache.org.
BLE Host - Add missing fields to ble_gap_conn_desc

* role
* master_clock_accuracy


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

Branch: refs/heads/ble_hs_api
Commit: 46801abffb80666a2da503a5bf1b3ea9251f4e2c
Parents: 9fd7889
Author: Christopher Collins <cc...@apache.org>
Authored: Fri Jun 24 15:10:27 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Jul 11 16:43:32 2016 -0700

----------------------------------------------------------------------
 apps/bletiny/src/cmd.c                  |   2 +-
 apps/bletiny/src/main.c                 |   2 +-
 net/nimble/host/include/host/ble_gap.h  |   7 +-
 net/nimble/host/src/ble_gap.c           |  10 +-
 net/nimble/host/src/ble_hs_conn_priv.h  |   1 +
 net/nimble/host/src/test/ble_gap_test.c | 155 ++++++++++++++++++++++-----
 6 files changed, 149 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/46801abf/apps/bletiny/src/cmd.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/cmd.c b/apps/bletiny/src/cmd.c
index b735094..d6e824d 100644
--- a/apps/bletiny/src/cmd.c
+++ b/apps/bletiny/src/cmd.c
@@ -1047,7 +1047,7 @@ cmd_show_conn(int argc, char **argv)
     for (i = 0; i < bletiny_num_conns; i++) {
         conn = bletiny_conns + i;
 
-        rc = ble_gap_find_conn(conn->handle, &conn_desc);
+        rc = ble_gap_conn_find(conn->handle, &conn_desc);
         if (rc == 0) {
             print_conn_desc(&conn_desc);
         }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/46801abf/apps/bletiny/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/main.c b/apps/bletiny/src/main.c
index d8c43f2..764eb00 100755
--- a/apps/bletiny/src/main.c
+++ b/apps/bletiny/src/main.c
@@ -1408,7 +1408,7 @@ bletiny_sec_restart(uint16_t conn_handle,
 
     if (ltk == NULL) {
         /* The user is requesting a store lookup. */
-        rc = ble_gap_find_conn(conn_handle, &desc);
+        rc = ble_gap_conn_find(conn_handle, &desc);
         if (rc != 0) {
             return rc;
         }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/46801abf/net/nimble/host/include/host/ble_gap.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/ble_gap.h b/net/nimble/host/include/host/ble_gap.h
index 48ca957..f2adaf5 100644
--- a/net/nimble/host/include/host/ble_gap.h
+++ b/net/nimble/host/include/host/ble_gap.h
@@ -95,6 +95,9 @@ struct hci_conn_update;
 #define BLE_GAP_ADDR_TYPE_WL                0xff
 #define BLE_GAP_ADDR_TYPE_NONE              0xfe
 
+#define BLE_GAP_ROLE_MASTER                 0
+#define BLE_GAP_ROLE_SLAVE                  1
+
 #define BLE_GAP_EVENT_CONNECT               0
 #define BLE_GAP_EVENT_DISCONNECT            1
 #define BLE_GAP_EVENT_CONN_CANCEL           2
@@ -158,6 +161,8 @@ struct ble_gap_conn_desc {
     uint8_t peer_id_addr_type;
     uint8_t our_id_addr_type;
     uint8_t our_ota_addr_type;
+    uint8_t role;
+    uint8_t master_clock_accuracy;
 };
 
 struct ble_gap_conn_params {
@@ -286,7 +291,7 @@ struct ble_gap_white_entry {
     uint8_t addr[6];
 };
 
-int ble_gap_find_conn(uint16_t handle, struct ble_gap_conn_desc *out_desc);
+int ble_gap_conn_find(uint16_t handle, struct ble_gap_conn_desc *out_desc);
 
 int ble_gap_adv_start(uint8_t own_addr_type, uint8_t peer_addr_type,
                       const uint8_t *peer_addr, int32_t duration_ms,

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/46801abf/net/nimble/host/src/ble_gap.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gap.c b/net/nimble/host/src/ble_gap.c
index 14b334d..04f9489 100644
--- a/net/nimble/host/src/ble_gap.c
+++ b/net/nimble/host/src/ble_gap.c
@@ -300,7 +300,14 @@ ble_gap_fill_conn_desc(struct ble_hs_conn *conn,
     desc->conn_itvl = conn->bhc_itvl;
     desc->conn_latency = conn->bhc_latency;
     desc->supervision_timeout = conn->bhc_supervision_timeout;
+    desc->master_clock_accuracy = conn->bhc_master_clock_accuracy;
     desc->sec_state = conn->bhc_sec_state;
+
+    if (conn->bhc_flags & BLE_HS_CONN_F_MASTER) {
+        desc->role = BLE_GAP_ROLE_MASTER;
+    } else {
+        desc->role = BLE_GAP_ROLE_SLAVE;
+    }
 }
 
 static void
@@ -347,7 +354,7 @@ ble_gap_find_snapshot(uint16_t handle, struct ble_gap_snapshot *snap)
  *                                  connection was found.
  */
 int
-ble_gap_find_conn(uint16_t handle, struct ble_gap_conn_desc *out_desc)
+ble_gap_conn_find(uint16_t handle, struct ble_gap_conn_desc *out_desc)
 {
     struct ble_hs_conn *conn;
 
@@ -985,6 +992,7 @@ ble_gap_rx_conn_complete(struct hci_le_conn_complete *evt)
     conn->bhc_itvl = evt->conn_itvl;
     conn->bhc_latency = evt->conn_latency;
     conn->bhc_supervision_timeout = evt->supervision_timeout;
+    conn->bhc_master_clock_accuracy = evt->master_clk_acc;
     if (evt->role == BLE_HCI_LE_CONN_COMPLETE_ROLE_MASTER) {
         conn->bhc_flags |= BLE_HS_CONN_F_MASTER;
         conn->bhc_cb = ble_gap_master.conn.cb;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/46801abf/net/nimble/host/src/ble_hs_conn_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_conn_priv.h b/net/nimble/host/src/ble_hs_conn_priv.h
index 36b483d..3ff7f76 100644
--- a/net/nimble/host/src/ble_hs_conn_priv.h
+++ b/net/nimble/host/src/ble_hs_conn_priv.h
@@ -45,6 +45,7 @@ struct ble_hs_conn {
     uint16_t bhc_itvl;
     uint16_t bhc_latency;
     uint16_t bhc_supervision_timeout;
+    uint8_t bhc_master_clock_accuracy;
 
     ble_hs_conn_flags_t bhc_flags;
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/46801abf/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 5c8489f..dbda665 100644
--- a/net/nimble/host/src/test/ble_gap_test.c
+++ b/net/nimble/host/src/test/ble_gap_test.c
@@ -436,7 +436,7 @@ ble_gap_test_util_wl_set(struct ble_gap_white_entry *white_list,
     }
 }
 
-TEST_CASE(ble_gap_test_case_conn_wl_bad_args)
+TEST_CASE(ble_gap_test_case_wl_bad_args)
 {
     int rc;
 
@@ -468,7 +468,7 @@ TEST_CASE(ble_gap_test_case_conn_wl_bad_args)
     TEST_ASSERT(rc == BLE_HS_EBUSY);
 }
 
-TEST_CASE(ble_gap_test_case_conn_wl_ctlr_fail)
+TEST_CASE(ble_gap_test_case_wl_ctlr_fail)
 {
     int i;
 
@@ -486,7 +486,7 @@ TEST_CASE(ble_gap_test_case_conn_wl_ctlr_fail)
     }
 }
 
-TEST_CASE(ble_gap_test_case_conn_wl_good)
+TEST_CASE(ble_gap_test_case_wl_good)
 {
     struct ble_gap_white_entry white_list[] = {
         { BLE_ADDR_TYPE_PUBLIC, { 1, 2, 3, 4, 5, 6 } },
@@ -499,11 +499,11 @@ TEST_CASE(ble_gap_test_case_conn_wl_good)
     ble_gap_test_util_wl_set(white_list, white_list_count, 0, 0);
 }
 
-TEST_SUITE(ble_gap_test_suite_conn_wl)
+TEST_SUITE(ble_gap_test_suite_wl)
 {
-    ble_gap_test_case_conn_wl_good();
-    ble_gap_test_case_conn_wl_bad_args();
-    ble_gap_test_case_conn_wl_ctlr_fail();
+    ble_gap_test_case_wl_good();
+    ble_gap_test_case_wl_bad_args();
+    ble_gap_test_case_wl_ctlr_fail();
 }
 
 /*****************************************************************************
@@ -1088,6 +1088,112 @@ TEST_SUITE(ble_gap_test_suite_conn_terminate)
 }
 
 /*****************************************************************************
+ * $conn find                                                                *
+ *****************************************************************************/
+
+TEST_CASE(ble_gap_test_case_conn_find)
+{
+
+    struct ble_gap_conn_desc desc;
+    struct ble_hs_conn *conn;
+    int rc;
+
+    /*** We are master; public addresses. */
+    ble_gap_test_util_init();
+
+    ble_hs_test_util_create_rpa_conn(8,
+                                     BLE_ADDR_TYPE_PUBLIC,
+                                     ((uint8_t[6]){0,0,0,0,0,0}),
+                                     BLE_ADDR_TYPE_PUBLIC,
+                                     ((uint8_t[6]){2,3,4,5,6,7}),
+                                     ((uint8_t[6]){0,0,0,0,0,0}),
+                                     ble_gap_test_util_connect_cb,
+                                     NULL);
+
+    rc = ble_gap_conn_find(8, &desc);
+    TEST_ASSERT_FATAL(rc == 0);
+    TEST_ASSERT(desc.conn_handle == 8);
+    TEST_ASSERT(desc.our_id_addr_type == BLE_ADDR_TYPE_PUBLIC);
+    TEST_ASSERT(desc.our_ota_addr_type == BLE_ADDR_TYPE_PUBLIC);
+    TEST_ASSERT(desc.peer_ota_addr_type == BLE_ADDR_TYPE_PUBLIC);
+    TEST_ASSERT(desc.role == BLE_GAP_ROLE_MASTER);
+    TEST_ASSERT(memcmp(desc.our_ota_addr, g_dev_addr, 6) == 0);
+    TEST_ASSERT(memcmp(desc.our_id_addr, g_dev_addr, 6) == 0);
+    TEST_ASSERT(memcmp(desc.peer_ota_addr,
+                       ((uint8_t[6]){2,3,4,5,6,7}), 6) == 0);
+    TEST_ASSERT(memcmp(desc.peer_id_addr,
+                       ((uint8_t[6]){2,3,4,5,6,7}), 6) == 0);
+    TEST_ASSERT(desc.conn_itvl == BLE_GAP_INITIAL_CONN_ITVL_MAX);
+    TEST_ASSERT(desc.conn_latency == BLE_GAP_INITIAL_CONN_LATENCY);
+    TEST_ASSERT(desc.supervision_timeout ==
+                BLE_GAP_INITIAL_SUPERVISION_TIMEOUT);
+    TEST_ASSERT(desc.master_clock_accuracy == 0);
+    TEST_ASSERT(!desc.sec_state.encrypted);
+    TEST_ASSERT(!desc.sec_state.authenticated);
+    TEST_ASSERT(!desc.sec_state.bonded);
+
+    /*** Swap roles. */
+    ble_hs_lock();
+    conn = ble_hs_conn_find(8);
+    conn->bhc_flags &= ~BLE_HS_CONN_F_MASTER;
+    ble_hs_unlock();
+
+    rc = ble_gap_conn_find(8, &desc);
+    TEST_ASSERT_FATAL(rc == 0);
+    TEST_ASSERT(desc.role == BLE_GAP_ROLE_SLAVE);
+
+    /*** We are master; RPAs. */
+    ble_gap_test_util_init();
+
+    ble_hs_test_util_create_rpa_conn(54,
+                                     BLE_ADDR_TYPE_RPA_PUB_DEFAULT,
+                                     ((uint8_t[6]){0x40,1,2,3,4,5}),
+                                     BLE_ADDR_TYPE_RPA_RND_DEFAULT,
+                                     ((uint8_t[6]){3,4,5,6,7,8}),
+                                     ((uint8_t[6]){0x50,1,2,3,4,5}),
+                                     ble_gap_test_util_connect_cb,
+                                     NULL);
+
+    rc = ble_gap_conn_find(54, &desc);
+    TEST_ASSERT_FATAL(rc == 0);
+    TEST_ASSERT(desc.conn_handle == 54);
+    TEST_ASSERT(desc.our_id_addr_type == BLE_ADDR_TYPE_PUBLIC);
+    TEST_ASSERT(desc.our_ota_addr_type == BLE_ADDR_TYPE_RPA_PUB_DEFAULT);
+    TEST_ASSERT(desc.peer_ota_addr_type == BLE_ADDR_TYPE_RPA_RND_DEFAULT);
+    TEST_ASSERT(desc.role == BLE_GAP_ROLE_MASTER);
+    TEST_ASSERT(memcmp(desc.our_ota_addr,
+                       ((uint8_t[6]){0x40,1,2,3,4,5}), 6) == 0);
+    TEST_ASSERT(memcmp(desc.our_id_addr, g_dev_addr, 6) == 0);
+    TEST_ASSERT(memcmp(desc.peer_ota_addr,
+                       ((uint8_t[6]){0x50,1,2,3,4,5}), 6) == 0);
+    TEST_ASSERT(memcmp(desc.peer_id_addr,
+                       ((uint8_t[6]){3,4,5,6,7,8}), 6) == 0);
+    TEST_ASSERT(desc.conn_itvl == BLE_GAP_INITIAL_CONN_ITVL_MAX);
+    TEST_ASSERT(desc.conn_latency == BLE_GAP_INITIAL_CONN_LATENCY);
+    TEST_ASSERT(desc.supervision_timeout ==
+                BLE_GAP_INITIAL_SUPERVISION_TIMEOUT);
+    TEST_ASSERT(desc.master_clock_accuracy == 0);
+    TEST_ASSERT(!desc.sec_state.encrypted);
+    TEST_ASSERT(!desc.sec_state.authenticated);
+    TEST_ASSERT(!desc.sec_state.bonded);
+
+    /*** Swap roles. */
+    ble_hs_lock();
+    conn = ble_hs_conn_find(54);
+    conn->bhc_flags &= ~BLE_HS_CONN_F_MASTER;
+    ble_hs_unlock();
+
+    rc = ble_gap_conn_find(54, &desc);
+    TEST_ASSERT_FATAL(rc == 0);
+    TEST_ASSERT(desc.role == BLE_GAP_ROLE_SLAVE);
+}
+
+TEST_SUITE(ble_gap_test_suite_conn_find)
+{
+    ble_gap_test_case_conn_find();
+}
+
+/*****************************************************************************
  * $advertise                                                                *
  *****************************************************************************/
 
@@ -1193,7 +1299,7 @@ ble_gap_test_util_adv(uint8_t own_addr_type, uint8_t peer_addr_type,
     }
 }
 
-TEST_CASE(ble_gap_test_case_conn_adv_bad_args)
+TEST_CASE(ble_gap_test_case_adv_bad_args)
 {
     struct ble_gap_adv_params adv_params;
     uint8_t peer_addr[6] = { 1, 2, 3, 4, 5, 6 };
@@ -1328,7 +1434,7 @@ TEST_CASE(ble_gap_test_case_adv_dflt_params)
     }
 }
 
-TEST_CASE(ble_gap_test_case_conn_adv_good)
+TEST_CASE(ble_gap_test_case_adv_good)
 {
     uint8_t peer_addr[6] = { 1, 2, 3, 4, 5, 6 };
     int d;
@@ -1352,7 +1458,7 @@ TEST_CASE(ble_gap_test_case_conn_adv_good)
     }
 }
 
-TEST_CASE(ble_gap_test_case_conn_adv_ctlr_fail)
+TEST_CASE(ble_gap_test_case_adv_ctlr_fail)
 {
     uint8_t peer_addr[6] = { 1, 2, 3, 4, 5, 6 };
     int d;
@@ -1372,7 +1478,7 @@ TEST_CASE(ble_gap_test_case_conn_adv_ctlr_fail)
     }
 }
 
-TEST_CASE(ble_gap_test_case_conn_adv_hci_fail)
+TEST_CASE(ble_gap_test_case_adv_hci_fail)
 {
     uint8_t peer_addr[6] = { 1, 2, 3, 4, 5, 6 };
     int num_hci_cmds;
@@ -1400,13 +1506,13 @@ TEST_CASE(ble_gap_test_case_conn_adv_hci_fail)
     }
 }
 
-TEST_SUITE(ble_gap_test_suite_conn_adv)
+TEST_SUITE(ble_gap_test_suite_adv)
 {
-    ble_gap_test_case_conn_adv_bad_args();
+    ble_gap_test_case_adv_bad_args();
     ble_gap_test_case_adv_dflt_params();
-    ble_gap_test_case_conn_adv_good();
-    ble_gap_test_case_conn_adv_ctlr_fail();
-    ble_gap_test_case_conn_adv_hci_fail();
+    ble_gap_test_case_adv_good();
+    ble_gap_test_case_adv_ctlr_fail();
+    ble_gap_test_case_adv_hci_fail();
 }
 
 /*****************************************************************************
@@ -1439,7 +1545,7 @@ ble_gap_test_util_stop_adv(uint8_t peer_addr_type, const uint8_t *peer_addr,
     ble_gap_test_util_verify_tx_adv_enable(0);
 }
 
-TEST_CASE(ble_gap_test_case_conn_stop_adv_good)
+TEST_CASE(ble_gap_test_case_stop_adv_good)
 {
     uint8_t peer_addr[6] = { 1, 2, 3, 4, 5, 6 };
     int d;
@@ -1458,7 +1564,7 @@ TEST_CASE(ble_gap_test_case_conn_stop_adv_good)
     }
 }
 
-TEST_CASE(ble_gap_test_case_conn_stop_adv_hci_fail)
+TEST_CASE(ble_gap_test_case_stop_adv_hci_fail)
 {
     uint8_t peer_addr[6] = { 1, 2, 3, 4, 5, 6 };
     int d;
@@ -1477,10 +1583,10 @@ TEST_CASE(ble_gap_test_case_conn_stop_adv_hci_fail)
     }
 }
 
-TEST_SUITE(ble_gap_test_suite_conn_stop_adv)
+TEST_SUITE(ble_gap_test_suite_stop_adv)
 {
-    ble_gap_test_case_conn_stop_adv_good();
-    ble_gap_test_case_conn_stop_adv_hci_fail();
+    ble_gap_test_case_stop_adv_good();
+    ble_gap_test_case_stop_adv_hci_fail();
 }
 
 /*****************************************************************************
@@ -2061,13 +2167,14 @@ TEST_SUITE(ble_gap_test_suite_update_conn)
 int
 ble_gap_test_all(void)
 {
-    ble_gap_test_suite_conn_wl();
+    ble_gap_test_suite_wl();
     ble_gap_test_suite_disc();
     ble_gap_test_suite_conn_dir();
     ble_gap_test_suite_conn_cancel();
     ble_gap_test_suite_conn_terminate();
-    ble_gap_test_suite_conn_adv();
-    ble_gap_test_suite_conn_stop_adv();
+    ble_gap_test_suite_conn_find();
+    ble_gap_test_suite_adv();
+    ble_gap_test_suite_stop_adv();
     ble_gap_test_suite_update_conn();
 
     return tu_any_failed;


[02/50] [abbrv] incubator-mynewt-core git commit: BLE Host - ble_gap_cancel->ble_gap_conn_cancel

Posted by cc...@apache.org.
BLE Host - ble_gap_cancel->ble_gap_conn_cancel

This function was renamed accidentally.


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

Branch: refs/heads/ble_hs_api
Commit: b9a61e2e6a507a419c8443c9fd8119d906117d1a
Parents: dba9503
Author: Christopher Collins <cc...@apache.org>
Authored: Tue Jun 21 20:19:49 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Jul 11 16:43:30 2016 -0700

----------------------------------------------------------------------
 apps/bletiny/src/main.c                     | 2 +-
 net/nimble/host/include/host/ble_gap.h      | 2 +-
 net/nimble/host/src/ble_gap.c               | 2 +-
 net/nimble/host/src/test/ble_hs_test_util.c | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b9a61e2e/apps/bletiny/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/main.c b/apps/bletiny/src/main.c
index b63d5d0..d7548c8 100755
--- a/apps/bletiny/src/main.c
+++ b/apps/bletiny/src/main.c
@@ -1273,7 +1273,7 @@ bletiny_conn_cancel(void)
 {
     int rc;
 
-    rc = ble_gap_cancel();
+    rc = ble_gap_conn_cancel();
     return rc;
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b9a61e2e/net/nimble/host/include/host/ble_gap.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/ble_gap.h b/net/nimble/host/include/host/ble_gap.h
index b913b7c..da66ae6 100644
--- a/net/nimble/host/include/host/ble_gap.h
+++ b/net/nimble/host/include/host/ble_gap.h
@@ -259,7 +259,7 @@ int ble_gap_connect(uint8_t own_addr_type,
                     const struct ble_gap_conn_params *params,
                     ble_gap_event_fn *cb, void *cb_arg);
 int ble_gap_terminate(uint16_t handle);
-int ble_gap_cancel(void);
+int ble_gap_conn_cancel(void);
 int ble_gap_wl_set(struct ble_gap_white_entry *white_list,
                    uint8_t white_list_count);
 int ble_gap_update_params(uint16_t conn_handle,

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b9a61e2e/net/nimble/host/src/ble_gap.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gap.c b/net/nimble/host/src/ble_gap.c
index 3a9b92c..b2308dc 100644
--- a/net/nimble/host/src/ble_gap.c
+++ b/net/nimble/host/src/ble_gap.c
@@ -1967,7 +1967,7 @@ done:
  *****************************************************************************/
 
 int
-ble_gap_cancel(void)
+ble_gap_conn_cancel(void)
 {
     uint8_t buf[BLE_HCI_CMD_HDR_LEN];
     int rc;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b9a61e2e/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 0a7f8bb..6acb9e7 100644
--- a/net/nimble/host/src/test/ble_hs_test_util.c
+++ b/net/nimble/host/src/test/ble_hs_test_util.c
@@ -381,7 +381,7 @@ ble_hs_test_util_conn_cancel(uint8_t ack_status)
                              BLE_HCI_OCF_LE_CREATE_CONN_CANCEL),
         ack_status);
 
-    rc = ble_gap_cancel();
+    rc = ble_gap_conn_cancel();
     return rc;
 }
 


[10/50] [abbrv] incubator-mynewt-core git commit: bleprph - Account for addition of adv. duration.

Posted by cc...@apache.org.
bleprph - Account for addition of adv. duration.


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

Branch: refs/heads/ble_hs_api
Commit: 3108b11e1d24c6c31d47a82ea27c67f8293c20fd
Parents: 2c37b7b
Author: Christopher Collins <cc...@apache.org>
Authored: Thu Jun 23 16:30:23 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Jul 11 16:43:31 2016 -0700

----------------------------------------------------------------------
 apps/bleprph/src/main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3108b11e/apps/bleprph/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bleprph/src/main.c b/apps/bleprph/src/main.c
index c265dc5..11c3dc0 100755
--- a/apps/bleprph/src/main.c
+++ b/apps/bleprph/src/main.c
@@ -169,8 +169,8 @@ bleprph_advertise(void)
     memset(&adv_params, 0, sizeof adv_params);
     adv_params.conn_mode = BLE_GAP_CONN_MODE_UND;
     adv_params.disc_mode = BLE_GAP_DISC_MODE_GEN;
-    rc = ble_gap_adv_start(BLE_ADDR_TYPE_PUBLIC, 0, NULL, &adv_params,
-                           bleprph_gap_event, NULL);
+    rc = ble_gap_adv_start(BLE_ADDR_TYPE_PUBLIC, 0, NULL, BLE_HS_FOREVER,
+                           &adv_params, bleprph_gap_event, NULL);
     if (rc != 0) {
         BLEPRPH_LOG(ERROR, "error enabling advertisement; rc=%d\n", rc);
         return;


[42/50] [abbrv] incubator-mynewt-core git commit: BLE Host - Move ibeacon prototypes to new header.

Posted by cc...@apache.org.
BLE Host - Move ibeacon prototypes to new header.

net/nimble/host/include/host/ble_ibeacon.h


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

Branch: refs/heads/ble_hs_api
Commit: 3bb24191ff01994a094fb2505d9fa4a303492178
Parents: f1554a0
Author: Christopher Collins <cc...@apache.org>
Authored: Wed Jul 6 15:32:57 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Jul 11 16:43:34 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/include/host/ble_hs.h      |  1 -
 net/nimble/host/include/host/ble_ibeacon.h | 25 +++++++++++++++++++++++++
 2 files changed, 25 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3bb24191/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 ea06411..3113b0d 100644
--- a/net/nimble/host/include/host/ble_hs.h
+++ b/net/nimble/host/include/host/ble_hs.h
@@ -219,7 +219,6 @@ extern const struct ble_hs_cfg ble_hs_cfg_dflt;
 
 int ble_hs_start(void);
 void ble_hs_event_enqueue(struct os_event *ev);
-int ble_ibeacon_set_adv_data(void *uuid128, uint16_t major, uint16_t minor);
 int ble_hs_init(struct os_eventq *app_evq, struct ble_hs_cfg *cfg);
 
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3bb24191/net/nimble/host/include/host/ble_ibeacon.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/ble_ibeacon.h b/net/nimble/host/include/host/ble_ibeacon.h
new file mode 100644
index 0000000..112f52b
--- /dev/null
+++ b/net/nimble/host/include/host/ble_ibeacon.h
@@ -0,0 +1,25 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef H_BLE_IBEACON_
+#define H_BLE_IBEACON_
+
+int ble_ibeacon_set_adv_data(void *uuid128, uint16_t major, uint16_t minor);
+
+#endif


[16/50] [abbrv] incubator-mynewt-core git commit: bletiny - fix bug; scan dur was parsed as uint16

Posted by cc...@apache.org.
bletiny - fix bug; scan dur was parsed as uint16

Now it is properly parsed as an int32.


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

Branch: refs/heads/ble_hs_api
Commit: be39876c0320a876417107ae6842694df6929c53
Parents: 3108b11
Author: Christopher Collins <cc...@apache.org>
Authored: Thu Jun 23 16:39:34 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Jul 11 16:43:31 2016 -0700

----------------------------------------------------------------------
 apps/bletiny/src/cmd.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/be39876c/apps/bletiny/src/cmd.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/cmd.c b/apps/bletiny/src/cmd.c
index 18cf51d..c840c7e 100644
--- a/apps/bletiny/src/cmd.c
+++ b/apps/bletiny/src/cmd.c
@@ -942,7 +942,7 @@ static struct kv_pair cmd_scan_addr_types[] = {
 static int
 cmd_scan(int argc, char **argv)
 {
-    uint32_t dur;
+    int32_t dur;
     int disc;
     int type;
     int filt;
@@ -959,7 +959,8 @@ cmd_scan(int argc, char **argv)
         return 0;
     }
 
-    dur = parse_arg_uint16("dur", &rc);
+    dur = parse_arg_long_bounds_default("dur", 1, INT32_MAX, BLE_HS_FOREVER,
+                                        &rc);
     if (rc != 0) {
         return rc;
     }