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/13 20:55:35 UTC

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

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/develop
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();