You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ry...@apache.org on 2019/07/19 11:55:07 UTC

[mynewt-nimble] 02/04: nimble/gap: Add helper ble_gap_terminate_with_conn()

This is an automated email from the ASF dual-hosted git repository.

rymek pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git

commit 605d2225de7729c3b7e98db3e52f992c8b155a9b
Author: Ɓukasz Rymanowski <lu...@codecoup.pl>
AuthorDate: Fri May 31 14:10:13 2019 +0200

    nimble/gap: Add helper ble_gap_terminate_with_conn()
    
    This is going to be used in following patch
---
 nimble/host/src/ble_gap.c      | 45 ++++++++++++++++++++++++------------------
 nimble/host/src/ble_gap_priv.h |  1 +
 2 files changed, 27 insertions(+), 19 deletions(-)

diff --git a/nimble/host/src/ble_gap.c b/nimble/host/src/ble_gap.c
index 45bc401..70690f2 100644
--- a/nimble/host/src/ble_gap.c
+++ b/nimble/host/src/ble_gap.c
@@ -4610,44 +4610,51 @@ ble_gap_conn_active(void)
 /*****************************************************************************
  * $terminate connection procedure                                           *
  *****************************************************************************/
-
 int
-ble_gap_terminate(uint16_t conn_handle, uint8_t hci_reason)
+ble_gap_terminate_with_conn(struct ble_hs_conn *conn, uint8_t hci_reason)
 {
     uint8_t buf[BLE_HCI_DISCONNECT_CMD_LEN];
-    struct ble_hs_conn *conn;
     int rc;
 
-    STATS_INC(ble_gap_stats, terminate);
-
-    ble_hs_lock();
-
-    conn = ble_hs_conn_find(conn_handle);
-    if (conn == NULL) {
-        rc = BLE_HS_ENOTCONN;
-        goto done;
-    }
-
+    BLE_HS_DBG_ASSERT(ble_hs_locked_by_cur_task());
     if (conn->bhc_flags & BLE_HS_CONN_F_TERMINATING) {
-        rc = BLE_HS_EALREADY;
-        goto done;
+        return BLE_HS_EALREADY;
     }
 
     BLE_HS_LOG(INFO, "GAP procedure initiated: terminate connection; "
                      "conn_handle=%d hci_reason=%d\n",
-               conn_handle, hci_reason);
+                     conn->bhc_handle, hci_reason);
 
-    ble_hs_hci_cmd_build_disconnect(conn_handle, hci_reason,
+    ble_hs_hci_cmd_build_disconnect(conn->bhc_handle, hci_reason,
                                     buf, sizeof buf);
     rc = ble_hs_hci_cmd_tx_empty_ack(BLE_HCI_OP(BLE_HCI_OGF_LINK_CTRL,
                                                 BLE_HCI_OCF_DISCONNECT_CMD),
                                      buf, sizeof(buf));
     if (rc != 0) {
-        goto done;
+        return rc;
     }
 
     conn->bhc_flags |= BLE_HS_CONN_F_TERMINATING;
-    rc = 0;
+    return 0;
+}
+
+int
+ble_gap_terminate(uint16_t conn_handle, uint8_t hci_reason)
+{
+    struct ble_hs_conn *conn;
+    int rc;
+
+    STATS_INC(ble_gap_stats, terminate);
+
+    ble_hs_lock();
+
+    conn = ble_hs_conn_find(conn_handle);
+    if (conn == NULL) {
+        rc = BLE_HS_ENOTCONN;
+        goto done;
+    }
+
+    rc = ble_gap_terminate_with_conn(conn, hci_reason);
 
 done:
     ble_hs_unlock();
diff --git a/nimble/host/src/ble_gap_priv.h b/nimble/host/src/ble_gap_priv.h
index 48a1253..a2eff53 100644
--- a/nimble/host/src/ble_gap_priv.h
+++ b/nimble/host/src/ble_gap_priv.h
@@ -118,6 +118,7 @@ int ble_gap_master_in_progress(void);
 void ble_gap_preempt(void);
 void ble_gap_preempt_done(void);
 
+int ble_gap_terminate_with_conn(struct ble_hs_conn *conn, uint8_t hci_reason);
 void ble_gap_conn_broken(uint16_t conn_handle, int reason);
 int32_t ble_gap_timer(void);