mynewt-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sterl...@apache.org
Subject [28/42] incubator-mynewt-core git commit: BLE Host - distinguish already/busy in conn/disc.
Date Tue, 09 Aug 2016 23:08:02 GMT
BLE Host - distinguish already/busy in conn/disc.

Prior to this change, both ble_gap_connect() and ble_gap_disc() return
BLE_HS_EALREADY if any master procedure was already in progress (either
connect or discover).

Now, Each function returns:

    * BLE_HS_EALREDY if the same procedure is already in progress
    * BLE_HS_EBUSY if the other procedure is already 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/5863ce67
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/5863ce67
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/5863ce67

Branch: refs/heads/sterly_refactor
Commit: 5863ce670c583412b951103a849497d2347907cc
Parents: f5f8370
Author: Christopher Collins <ccollins@apache.org>
Authored: Sat Aug 6 14:08:59 2016 -0700
Committer: Sterling Hughes <sterling@apache.org>
Committed: Tue Aug 9 16:05:21 2016 -0700

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


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5863ce67/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 6086c50..49d678e 100644
--- a/net/nimble/host/src/ble_gap.c
+++ b/net/nimble/host/src/ble_gap.c
@@ -1994,7 +1994,11 @@ ble_gap_disc_validate(uint8_t own_addr_type,
         return BLE_HS_EINVAL;
     }
 
-    if (ble_gap_master.op != BLE_GAP_OP_NULL) {
+    if (ble_gap_conn_active()) {
+        return BLE_HS_EBUSY;
+    }
+
+    if (ble_gap_disc_active()) {
         return BLE_HS_EALREADY;
     }
 
@@ -2230,11 +2234,16 @@ ble_gap_connect(uint8_t own_addr_type,
 
     ble_hs_lock();
 
-    if (ble_gap_master.op != BLE_GAP_OP_NULL) {
+    if (ble_gap_conn_active()) {
         rc = BLE_HS_EALREADY;
         goto done;
     }
 
+    if (ble_gap_disc_active()) {
+        rc = BLE_HS_EBUSY;
+        goto done;
+    }
+
     if (!ble_hs_conn_can_alloc()) {
         rc = BLE_HS_ENOMEM;
         goto done;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5863ce67/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 170b8d9..2d4c551 100644
--- a/net/nimble/host/src/test/ble_gap_test.c
+++ b/net/nimble/host/src/test/ble_gap_test.c
@@ -572,15 +572,6 @@ TEST_CASE(ble_gap_test_case_disc_bad_args)
     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, 0, NULL,
-                                  ble_gap_test_util_connect_cb, NULL, 0);
-    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_disc_good)
@@ -763,6 +754,45 @@ TEST_CASE(ble_gap_test_case_disc_dflts)
     ble_gap_test_util_disc_dflts_once(1);
 }
 
+TEST_CASE(ble_gap_test_case_disc_already)
+{
+    static const struct ble_gap_disc_params disc_params = { 0 };
+    int rc;
+
+    ble_gap_test_util_init();
+
+    /* Start a discovery procedure. */
+    rc = ble_hs_test_util_disc(BLE_ADDR_TYPE_PUBLIC, BLE_HS_FOREVER,
+                               &disc_params, ble_gap_test_util_disc_cb,
+                               NULL, -1, 0);
+    TEST_ASSERT_FATAL(rc == 0);
+
+    /* Ensure host indicates BLE_HS_EALREADY if we try to discover. */
+    rc = ble_gap_disc(BLE_ADDR_TYPE_PUBLIC, BLE_HS_FOREVER, &disc_params,
+                               ble_gap_test_util_disc_cb, NULL);
+    TEST_ASSERT(rc == BLE_HS_EALREADY);
+}
+
+TEST_CASE(ble_gap_test_case_disc_busy)
+{
+    static const struct ble_gap_disc_params disc_params = { 0 };
+    static const uint8_t peer_addr[6] = { 1, 2, 3, 4, 5, 6 };
+    int rc;
+
+    ble_gap_test_util_init();
+
+    /* Start a connect procedure. */
+    rc = ble_hs_test_util_connect(BLE_ADDR_TYPE_PUBLIC, BLE_ADDR_TYPE_PUBLIC,
+                                  peer_addr, 0, NULL,
+                                  ble_gap_test_util_connect_cb, NULL, 0);
+    TEST_ASSERT_FATAL(rc == 0);
+
+    /* Ensure host indicates BLE_HS_EBUSY if we try to discover. */
+    rc = ble_gap_disc(BLE_ADDR_TYPE_PUBLIC, BLE_HS_FOREVER, &disc_params,
+                               ble_gap_test_util_disc_cb, NULL);
+    TEST_ASSERT(rc == BLE_HS_EBUSY);
+}
+
 TEST_SUITE(ble_gap_test_suite_disc)
 {
     tu_suite_set_post_test_cb(ble_hs_test_util_post_test, NULL);
@@ -772,13 +802,15 @@ TEST_SUITE(ble_gap_test_suite_disc)
     ble_gap_test_case_disc_ltd_mismatch();
     ble_gap_test_case_disc_hci_fail();
     ble_gap_test_case_disc_dflts();
+    ble_gap_test_case_disc_already();
+    ble_gap_test_case_disc_busy();
 }
 
 /*****************************************************************************
  * $direct connect                                                           *
  *****************************************************************************/
 
-TEST_CASE(ble_gap_test_case_conn_dir_good)
+TEST_CASE(ble_gap_test_case_conn_gen_good)
 {
     struct hci_le_conn_complete evt;
     struct ble_gap_conn_params params;
@@ -831,7 +863,7 @@ TEST_CASE(ble_gap_test_case_conn_dir_good)
     TEST_ASSERT(ble_hs_atomic_conn_flags(2, NULL) == 0);
 }
 
-TEST_CASE(ble_gap_test_case_conn_dir_bad_args)
+TEST_CASE(ble_gap_test_case_conn_gen_bad_args)
 {
     int rc;
 
@@ -861,7 +893,7 @@ TEST_CASE(ble_gap_test_case_conn_dir_bad_args)
     TEST_ASSERT(rc == BLE_HS_EALREADY);
 }
 
-TEST_CASE(ble_gap_test_case_conn_dir_dflt_params)
+TEST_CASE(ble_gap_test_case_conn_gen_dflt_params)
 {
     static const uint8_t peer_addr[6] = { 2, 3, 8, 6, 6, 1 };
     int rc;
@@ -874,13 +906,58 @@ TEST_CASE(ble_gap_test_case_conn_dir_dflt_params)
     TEST_ASSERT(rc == 0);
 }
 
-TEST_SUITE(ble_gap_test_suite_conn_dir)
+TEST_CASE(ble_gap_test_case_conn_gen_already)
+{
+    static const struct ble_gap_conn_params conn_params = { 0 };
+    static const uint8_t peer_addr[6] = { 1, 2, 3, 4, 5, 6 };
+    int rc;
+
+    ble_gap_test_util_init();
+
+    /* Start a connect procedure. */
+    rc = ble_hs_test_util_connect(BLE_ADDR_TYPE_PUBLIC, BLE_ADDR_TYPE_PUBLIC,
+                                  peer_addr, 0, NULL,
+                                  ble_gap_test_util_connect_cb, NULL, 0);
+    TEST_ASSERT_FATAL(rc == 0);
+
+    /* Ensure host indicates BLE_HS_EALREADY if we try to connect. */
+    rc = ble_gap_connect(BLE_ADDR_TYPE_PUBLIC, BLE_ADDR_TYPE_PUBLIC,
+                         peer_addr, BLE_HS_FOREVER, &conn_params,
+                         ble_gap_test_util_connect_cb, NULL);
+    TEST_ASSERT(rc == BLE_HS_EALREADY);
+}
+
+TEST_CASE(ble_gap_test_case_conn_gen_busy)
+{
+    static const struct ble_gap_disc_params disc_params = { 0 };
+    static const struct ble_gap_conn_params conn_params = { 0 };
+    static const uint8_t peer_addr[6] = { 1, 2, 3, 4, 5, 6 };
+    int rc;
+
+    ble_gap_test_util_init();
+
+    /* Start a discovery procedure. */
+    rc = ble_hs_test_util_disc(BLE_ADDR_TYPE_PUBLIC, BLE_HS_FOREVER,
+                               &disc_params, ble_gap_test_util_disc_cb,
+                               NULL, -1, 0);
+    TEST_ASSERT_FATAL(rc == 0);
+
+    /* Ensure host indicates BLE_HS_EBUSY if we try to connect. */
+    rc = ble_gap_connect(BLE_ADDR_TYPE_PUBLIC, BLE_ADDR_TYPE_PUBLIC,
+                         peer_addr, BLE_HS_FOREVER, &conn_params,
+                         ble_gap_test_util_connect_cb, NULL);
+    TEST_ASSERT(rc == BLE_HS_EBUSY);
+}
+
+TEST_SUITE(ble_gap_test_suite_conn_gen)
 {
     tu_suite_set_post_test_cb(ble_hs_test_util_post_test, NULL);
 
-    ble_gap_test_case_conn_dir_good();
-    ble_gap_test_case_conn_dir_bad_args();
-    ble_gap_test_case_conn_dir_dflt_params();
+    ble_gap_test_case_conn_gen_good();
+    ble_gap_test_case_conn_gen_bad_args();
+    ble_gap_test_case_conn_gen_dflt_params();
+    ble_gap_test_case_conn_gen_already();
+    ble_gap_test_case_conn_gen_busy();
 }
 
 /*****************************************************************************
@@ -2487,7 +2564,7 @@ ble_gap_test_all(void)
 {
     ble_gap_test_suite_wl();
     ble_gap_test_suite_disc();
-    ble_gap_test_suite_conn_dir();
+    ble_gap_test_suite_conn_gen();
     ble_gap_test_suite_conn_cancel();
     ble_gap_test_suite_conn_terminate();
     ble_gap_test_suite_conn_find();


Mime
View raw message