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:42 UTC
[4/4] incubator-mynewt-larva git commit: Add ability to cancel a
connection in progress.
Add ability to cancel a connection in progress.
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/cc5b7b72
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/cc5b7b72
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/cc5b7b72
Branch: refs/heads/master
Commit: cc5b7b724c1f064ae05a25977dffd44e24ca163f
Parents: 36945a7
Author: Christopher Collins <cc...@gmail.com>
Authored: Mon Dec 21 19:00:49 2015 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Mon Dec 21 19:00:49 2015 -0800
----------------------------------------------------------------------
net/nimble/host/include/host/ble_gap.h | 1 +
net/nimble/host/include/host/host_hci.h | 1 +
net/nimble/host/src/ble_gap_conn.c | 45 ++++++++++++++++++++++++++++
net/nimble/host/src/host_hci_cmd.c | 10 +++++++
4 files changed, 57 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/cc5b7b72/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 1e4adbe..4523025 100644
--- a/net/nimble/host/include/host/ble_gap.h
+++ b/net/nimble/host/include/host/ble_gap.h
@@ -84,5 +84,6 @@ int ble_gap_conn_set_adv_fields(struct ble_hs_adv_fields *adv_fields);
int ble_gap_conn_disc(uint32_t duration_ms, uint8_t discovery_mode);
int ble_gap_conn_direct_connect(int addr_type, uint8_t *addr);
int ble_gap_conn_terminate(uint16_t handle);
+int ble_gap_conn_cancel(void);
#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/cc5b7b72/net/nimble/host/include/host/host_hci.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/host_hci.h b/net/nimble/host/include/host/host_hci.h
index dde0f3f..31cc70c 100644
--- a/net/nimble/host/include/host/host_hci.h
+++ b/net/nimble/host/include/host/host_hci.h
@@ -45,6 +45,7 @@ int host_hci_cmd_le_add_to_whitelist(uint8_t *addr, uint8_t addr_type);
int host_hci_cmd_le_rmv_from_whitelist(uint8_t *addr, uint8_t addr_type);
int host_hci_cmd_reset(void);
int host_hci_cmd_read_adv_pwr(void);
+int host_hci_cmd_le_create_conn_cancel(void);
int host_hci_set_buf_size(uint16_t pktlen, uint8_t max_pkts);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/cc5b7b72/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 8e7bb1a..2797949 100644
--- a/net/nimble/host/src/ble_gap_conn.c
+++ b/net/nimble/host/src/ble_gap_conn.c
@@ -1173,6 +1173,51 @@ ble_gap_conn_terminate(uint16_t handle)
}
/*****************************************************************************
+ * $cancel *
+ *****************************************************************************/
+
+static void
+ble_gap_conn_cancel_ack(struct ble_hci_ack *ack, void *arg)
+{
+ if (ack->bha_status != 0) {
+ /* XXX: This may be ambiguous to the application. */
+ ble_gap_conn_notify_connect(BLE_HS_ECONTROLLER, NULL);
+ }
+}
+
+static int
+ble_gap_conn_cancel_tx(void *arg)
+{
+ int rc;
+
+ ble_hci_ack_set_callback(ble_gap_conn_cancel_ack, arg);
+
+ rc = host_hci_cmd_le_create_conn_cancel();
+ if (rc != 0) {
+ return 1;
+ }
+
+ return 0;
+}
+
+int
+ble_gap_conn_cancel(void)
+{
+ int rc;
+
+ if (!ble_gap_conn_master_in_progress()) {
+ return BLE_HS_EALREADY;
+ }
+
+ rc = ble_hci_sched_enqueue(ble_gap_conn_cancel_tx, NULL);
+ if (rc != 0) {
+ return rc;
+ }
+
+ return 0;
+}
+
+/*****************************************************************************
* $init *
*****************************************************************************/
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/cc5b7b72/net/nimble/host/src/host_hci_cmd.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/host_hci_cmd.c b/net/nimble/host/src/host_hci_cmd.c
index ab98071..530b9f9 100644
--- a/net/nimble/host/src/host_hci_cmd.c
+++ b/net/nimble/host/src/host_hci_cmd.c
@@ -510,3 +510,13 @@ host_hci_cmd_read_adv_pwr(void)
NULL);
return rc;
}
+
+int
+host_hci_cmd_le_create_conn_cancel(void)
+{
+ int rc;
+
+ rc = host_hci_cmd_send(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_CREATE_CONN_CANCEL,
+ 0, NULL);
+ return rc;
+}