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 2015/12/22 04:01:40 UTC
[2/4] incubator-mynewt-larva git commit: Add ability to stop
advertising.
Add ability to stop advertising.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/commit/52d8fdfc
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/52d8fdfc
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/52d8fdfc
Branch: refs/heads/master
Commit: 52d8fdfc69bb2e7c2b568ac9ffd14b7d57b7947a
Parents: 70a0871
Author: Christopher Collins <cc...@gmail.com>
Authored: Mon Dec 21 18:39:34 2015 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Mon Dec 21 18:39:34 2015 -0800
----------------------------------------------------------------------
net/nimble/host/include/host/ble_gap.h | 6 +++
net/nimble/host/include/host/ble_hs.h | 1 +
net/nimble/host/src/ble_gap_conn.c | 67 +++++++++++++++++++++++++++++
3 files changed, 74 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/52d8fdfc/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 d81f1d1..1e4adbe 100644
--- a/net/nimble/host/include/host/ble_gap.h
+++ b/net/nimble/host/include/host/ble_gap.h
@@ -25,6 +25,7 @@ struct hci_le_conn_complete;
#define BLE_GAP_CONN_EVENT_TYPE_ADV_RPT 2
#define BLE_GAP_CONN_EVENT_TYPE_SCAN_DONE 3
#define BLE_GAP_CONN_EVENT_TYPE_TERMINATE 4
+#define BLE_GAP_CONN_EVENT_TYPE_ADV_DONE 5
struct ble_gap_conn_connect_rpt {
uint16_t handle;
@@ -49,6 +50,10 @@ struct ble_gap_conn_terminate_rpt {
uint8_t reason;
};
+struct ble_gap_conn_adv_done {
+ uint8_t status;
+};
+
struct ble_gap_conn_event {
uint8_t type;
@@ -56,6 +61,7 @@ struct ble_gap_conn_event {
struct ble_gap_conn_connect_rpt conn;
struct ble_gap_conn_adv_rpt adv;
struct ble_gap_conn_terminate_rpt term;
+ struct ble_gap_conn_adv_done adv_done;
};
};
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/52d8fdfc/net/nimble/host/include/host/ble_hs.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/ble_hs.h b/net/nimble/host/include/host/ble_hs.h
index 6081e4a..f18692a 100644
--- a/net/nimble/host/include/host/ble_hs.h
+++ b/net/nimble/host/include/host/ble_hs.h
@@ -31,6 +31,7 @@
#define BLE_HS_EBADDATA 10
#define BLE_HS_EOS 11
#define BLE_HS_ECONGESTED 12
+#define BLE_HS_ECONTROLLER 13
struct ble_hs_cfg {
uint16_t max_outstanding_pkts_per_conn;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/52d8fdfc/net/nimble/host/src/ble_gap_conn.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gap_conn.c b/net/nimble/host/src/ble_gap_conn.c
index cb64e1f..57ad710 100644
--- a/net/nimble/host/src/ble_gap_conn.c
+++ b/net/nimble/host/src/ble_gap_conn.c
@@ -200,6 +200,17 @@ ble_gap_conn_notify_terminate(uint16_t handle, uint8_t status, uint8_t reason)
}
static void
+ble_gap_conn_notify_adv_done(uint8_t status)
+{
+ struct ble_gap_conn_event event;
+
+ event.type = BLE_GAP_CONN_EVENT_TYPE_ADV_DONE;
+ event.adv_done.status = status;
+
+ ble_gap_conn_call_cb(&event);
+}
+
+static void
ble_gap_conn_master_reset_state(void)
{
ble_gap_conn_master_state = BLE_GAP_CONN_STATE_IDLE;
@@ -511,6 +522,55 @@ ble_gap_conn_slave_timer_exp(void *arg)
}
/*****************************************************************************
+ * $stop advertise *
+ *****************************************************************************/
+
+static void
+ble_gap_conn_adv_ack_disable(struct ble_hci_ack *ack, void *arg)
+{
+ if (ack->bha_status == BLE_ERR_SUCCESS) {
+ /* Advertising should now be aborted. */
+ ble_gap_conn_slave_reset_state();
+ ble_gap_conn_notify_adv_done(0);
+ }
+}
+
+static int
+ble_gap_conn_adv_disable_tx(void *arg)
+{
+ int rc;
+
+ ble_hci_ack_set_callback(ble_gap_conn_adv_ack_disable, NULL);
+ rc = host_hci_cmd_le_set_adv_enable(0);
+ if (rc != BLE_ERR_SUCCESS) {
+ ble_gap_conn_notify_adv_done(BLE_HS_ECONTROLLER);
+ return 1;
+ }
+
+ return 0;
+}
+
+static int
+ble_gap_conn_adv_stop(void)
+{
+ int rc;
+
+ /* Do nothing if advertising is already disabled. */
+ if (ble_gap_conn_s_conn_mode == BLE_GAP_CONN_MODE_NULL &&
+ ble_gap_conn_s_disc_mode == BLE_GAP_DISC_MODE_NULL) {
+
+ return BLE_HS_EALREADY;
+ }
+
+ rc = ble_hci_sched_enqueue(ble_gap_conn_adv_disable_tx, NULL);
+ if (rc != 0) {
+ return rc;
+ }
+
+ return 0;
+}
+
+/*****************************************************************************
* $advertise *
*****************************************************************************/
@@ -787,6 +847,13 @@ ble_gap_conn_advertise(uint8_t discoverable_mode, uint8_t connectable_mode,
{
int rc;
+ if (discoverable_mode == BLE_GAP_DISC_MODE_NULL ||
+ connectable_mode == BLE_GAP_DISC_MODE_NULL) {
+
+ rc = ble_gap_conn_adv_stop();
+ return rc;
+ }
+
if (discoverable_mode >= BLE_GAP_DISC_MODE_MAX ||
connectable_mode >= BLE_GAP_CONN_MODE_MAX) {