Add asynchronous client connection secure

* Adds parameter `rcPtr` to `NimBLEDevice::startSecurity`, default value works as the original method.
* * `rcPtr`: if not nullptr, will allow caller to obtain the internal return code.
* Adds parameter `async` to `NimBLEClient::secureConnection`, default value works as the original method.
* * `async`; if true, will send the secure command and return immediately with a true value for successfully sending the command, else false.
This commit is contained in:
thekurtovic
2024-12-02 09:54:18 -07:00
committed by h2zero
parent e0fe1668de
commit 15392bf581
4 changed files with 33 additions and 7 deletions
+6 -3
View File
@@ -1136,14 +1136,17 @@ uint32_t NimBLEDevice::getSecurityPasskey() {
/**
* @brief Start the connection securing and authorization for this connection.
* @param connHandle The connection handle of the peer device.
* @returns NimBLE stack return code, 0 = success.
* @param rcPtr Optional pointer to pass the return code to the caller.
* @returns True if successfully started, success = 0 or BLE_HS_EALREADY.
*/
bool NimBLEDevice::startSecurity(uint16_t connHandle) {
bool NimBLEDevice::startSecurity(uint16_t connHandle, int* rcPtr) {
int rc = ble_gap_security_initiate(connHandle);
if (rc != 0) {
NIMBLE_LOGE(LOG_TAG, "ble_gap_security_initiate: rc=%d %s", rc, NimBLEUtils::returnCodeToString(rc));
}
if (rcPtr) {
*rcPtr = rc;
}
return rc == 0 || rc == BLE_HS_EALREADY;
} // startSecurity