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:50:02 UTC

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

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;
 }