summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Collins <ccollins@apache.org>2016-08-06 14:08:59 -0700
committerChristopher Collins <ccollins@apache.org>2016-08-06 14:08:59 -0700
commitf153e244ebd8080a6a72183a2b5b2d320047c8af (patch)
treed46ca3ef05e13ea9736e027cd544fe1b6f456bae
parentdf7516609b89b223c405c1921eda9ba7c36eaa4b (diff)
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
-rw-r--r--net/nimble/host/src/ble_gap.c13
-rw-r--r--net/nimble/host/src/test/ble_gap_test.c111
2 files changed, 105 insertions, 19 deletions
diff --git a/net/nimble/host/src/ble_gap.c b/net/nimble/host/src/ble_gap.c
index 6086c50d..49d678e0 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;
diff --git a/net/nimble/host/src/test/ble_gap_test.c b/net/nimble/host/src/test/ble_gap_test.c
index 170b8d99..2d4c5512 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();