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/06/19 23:01:31 UTC
[2/2] incubator-mynewt-core git commit: BLE Host - Ability to cancel
discovery operation.
BLE Host - Ability to cancel discovery operation.
"discovery" here is in the GAP sense (i.e., scanning).
/**
* Cancels the discovery procedure currently in progress. A success return
* code indicates that scanning has been fully aborted; a new discovery or
* connect procedure can be initiated immediately.
*
* @return 0 on success;
* BLE_HS_EALREADY if there is no discovery
* procedure to cancel;
* Other nonzero on unexpected error.
*/
int
ble_gap_disc_cancel(void)
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/63b20b2c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/63b20b2c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/63b20b2c
Branch: refs/heads/develop
Commit: 63b20b2cd705da1516c0e97998c58d458d43d84f
Parents: 2f57efe
Author: Christopher Collins <cc...@apache.org>
Authored: Sun Jun 19 15:43:46 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Sun Jun 19 16:00:16 2016 -0700
----------------------------------------------------------------------
net/nimble/host/include/host/ble_gap.h | 1 +
net/nimble/host/src/ble_gap.c | 50 +++++++++++++++++++++++++++--
net/nimble/host/src/ble_gap_priv.h | 2 ++
3 files changed, 50 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/63b20b2c/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 b7d2878..23b8f46 100644
--- a/net/nimble/host/include/host/ble_gap.h
+++ b/net/nimble/host/include/host/ble_gap.h
@@ -260,6 +260,7 @@ int ble_gap_disc(uint32_t duration_ms, uint8_t discovery_mode,
uint8_t scan_type, uint8_t filter_policy,
uint8_t addr_mode,
ble_gap_disc_fn *cb, void *cb_arg);
+int ble_gap_disc_cancel(void);
int ble_gap_conn_initiate(int addr_type, uint8_t *addr,
struct ble_gap_crt_params *params,
ble_gap_event_fn *cb, void *cb_arg);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/63b20b2c/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 ee924b0..12a4994 100644
--- a/net/nimble/host/src/ble_gap.c
+++ b/net/nimble/host/src/ble_gap.c
@@ -43,8 +43,10 @@
* callback. The callback is executed when the procedure completes.
*
* Notes on thread-safety:
- * 1. The ble_hs mutex must never be locked when an application callback is
- * executed. A callback is free to initiate additional host procedures.
+ * 1. The ble_hs mutex must always be unlocked when an application callback is
+ * executed. The purpose of this requirement is to allow callbacks to
+ * initiate additional host procedures, which may require locking of the
+ * mutex.
* 2. Functions called directly by the application never call callbacks.
* Generally, these functions lock the ble_hs mutex at the start, and only
* unlock it at return.
@@ -180,6 +182,8 @@ STATS_NAME_START(ble_gap_stats)
STATS_NAME(ble_gap_stats, rx_update_complete)
STATS_NAME(ble_gap_stats, rx_adv_report)
STATS_NAME(ble_gap_stats, rx_conn_complete)
+ STATS_NAME(ble_gap_stats, discover_cancel)
+ STATS_NAME(ble_gap_stats, discover_cancel_fail)
STATS_NAME_END(ble_gap_stats)
/*****************************************************************************
@@ -1624,7 +1628,7 @@ ble_gap_disc_tx_enable(void)
static int
ble_gap_disc_tx_params(uint8_t scan_type, uint8_t filter_policy,
- uint8_t addr_mode)
+ uint8_t addr_mode)
{
uint8_t buf[BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_SCAN_PARAM_LEN];
int rc;
@@ -1647,6 +1651,46 @@ ble_gap_disc_tx_params(uint8_t scan_type, uint8_t filter_policy,
}
/**
+ * Cancels the discovery procedure currently in progress. A success return
+ * code indicates that scanning has been fully aborted; a new discovery or
+ * connect procedure can be initiated immediately.
+ *
+ * @return 0 on success;
+ * BLE_HS_EALREADY if there is no discovery
+ * procedure to cancel;
+ * Other nonzero on unexpected error.
+ */
+int
+ble_gap_disc_cancel(void)
+{
+ int rc;
+
+ ble_hs_lock();
+
+ STATS_INC(ble_gap_stats, discover_cancel);
+
+ if (ble_gap_master.op != BLE_GAP_OP_M_DISC) {
+ rc = BLE_HS_EALREADY;
+ goto done;
+ }
+
+ rc = ble_gap_disc_tx_disable();
+ if (rc != 0) {
+ goto done;
+ }
+
+ ble_gap_master.op = BLE_GAP_OP_NULL;
+
+done:
+ if (rc != 0) {
+ STATS_INC(ble_gap_stats, discover_cancel_fail);
+ }
+ ble_hs_unlock();
+
+ return rc;
+}
+
+/**
* Performs the Limited or General Discovery Procedures, as described in
* vol. 3, part C, section 9.2.5 / 9.2.6.
*
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/63b20b2c/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 af9438c..547dffb 100644
--- a/net/nimble/host/src/ble_gap_priv.h
+++ b/net/nimble/host/src/ble_gap_priv.h
@@ -59,6 +59,8 @@ STATS_SECT_START(ble_gap_stats)
STATS_SECT_ENTRY(rx_update_complete)
STATS_SECT_ENTRY(rx_adv_report)
STATS_SECT_ENTRY(rx_conn_complete)
+ STATS_SECT_ENTRY(discover_cancel)
+ STATS_SECT_ENTRY(discover_cancel_fail)
STATS_SECT_END
extern STATS_SECT_DECL(ble_gap_stats) ble_gap_stats;