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);