From f36929963dc6b65851b2889ded534c4d49c8786e Mon Sep 17 00:00:00 2001 From: cmorganBE <51970032+cmorganBE@users.noreply.github.com> Date: Sat, 8 Jun 2024 12:06:57 -0400 Subject: [PATCH] Add disconnect overload to take NimBLEConnInfo reference. (#162) * NimBLEConnInfo - Note that the connection handle is the same as the connection id in the comment for getConnHandle() * NimBLEServer - int disconnect(const NimBLEConnInfo&) helper method --- src/NimBLEConnInfo.h | 2 +- src/NimBLEServer.cpp | 9 +++++++++ src/NimBLEServer.h | 2 ++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/NimBLEConnInfo.h b/src/NimBLEConnInfo.h index 6b45127..7a9b4c6 100644 --- a/src/NimBLEConnInfo.h +++ b/src/NimBLEConnInfo.h @@ -22,7 +22,7 @@ public: /** @brief Gets the ID address of the connected peer */ NimBLEAddress getIdAddress() const { return NimBLEAddress(m_desc.peer_id_addr); } - /** @brief Gets the connection handle of the connected peer */ + /** @brief Gets the connection handle (also known as the connection id) of the connected peer */ uint16_t getConnHandle() const { return m_desc.conn_handle; } /** @brief Gets the connection interval for this connection (in 1.25ms units) */ diff --git a/src/NimBLEServer.cpp b/src/NimBLEServer.cpp index 243ac24..cd5827c 100644 --- a/src/NimBLEServer.cpp +++ b/src/NimBLEServer.cpp @@ -252,6 +252,15 @@ int NimBLEServer::disconnect(uint16_t connId, uint8_t reason) { return rc; } // disconnect +/** + * @brief Disconnect the specified client with optional reason. + * @param [in] connInfo Connection of the client to disconnect. + * @param [in] reason code for disconnecting. + * @return NimBLE host return code. + */ +int NimBLEServer::disconnect(const NimBLEConnInfo &connInfo, uint8_t reason) { + return disconnect(connInfo.getConnHandle(), reason); +} // disconnect #if !CONFIG_BT_NIMBLE_EXT_ADV || defined(_DOXYGEN_) /** diff --git a/src/NimBLEServer.h b/src/NimBLEServer.h index 5e635df..b2b69b1 100644 --- a/src/NimBLEServer.h +++ b/src/NimBLEServer.h @@ -69,6 +69,8 @@ public: NimBLEService* getServiceByHandle(uint16_t handle); int disconnect(uint16_t connID, uint8_t reason = BLE_ERR_REM_USER_CONN_TERM); + int disconnect(const NimBLEConnInfo &connInfo, + uint8_t reason = BLE_ERR_REM_USER_CONN_TERM); void updateConnParams(uint16_t conn_handle, uint16_t minInterval, uint16_t maxInterval, uint16_t latency, uint16_t timeout);