Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 6C206200B6F for ; Wed, 10 Aug 2016 01:07:43 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 6B022160AB9; Tue, 9 Aug 2016 23:07:43 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 8ADE9160AB0 for ; Wed, 10 Aug 2016 01:07:42 +0200 (CEST) Received: (qmail 14147 invoked by uid 500); 9 Aug 2016 23:07:41 -0000 Mailing-List: contact commits-help@mynewt.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@mynewt.incubator.apache.org Delivered-To: mailing list commits@mynewt.incubator.apache.org Received: (qmail 14091 invoked by uid 99); 9 Aug 2016 23:07:41 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 09 Aug 2016 23:07:41 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 56007186575 for ; Tue, 9 Aug 2016 23:07:41 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -4.646 X-Spam-Level: X-Spam-Status: No, score=-4.646 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-1.426] autolearn=disabled Received: from mx2-lw-us.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id etRYC8uvf-LD for ; Tue, 9 Aug 2016 23:07:39 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx2-lw-us.apache.org (ASF Mail Server at mx2-lw-us.apache.org) with SMTP id C061861277 for ; Tue, 9 Aug 2016 23:07:37 +0000 (UTC) Received: (qmail 12620 invoked by uid 99); 9 Aug 2016 23:07:35 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 09 Aug 2016 23:07:35 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id D827AE1171; Tue, 9 Aug 2016 23:07:35 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: sterling@apache.org To: commits@mynewt.incubator.apache.org Date: Tue, 09 Aug 2016 23:08:02 -0000 Message-Id: <3a191b7891bd4c1a8b1120e6c9a1f609@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [28/42] incubator-mynewt-core git commit: BLE Host - distinguish already/busy in conn/disc. archived-at: Tue, 09 Aug 2016 23:07:43 -0000 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 Authored: Sat Aug 6 14:08:59 2016 -0700 Committer: Sterling Hughes 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, ¶ms, 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, ¶ms, - 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();