[BREAKING] Asynchronous pin injections for Numeric Comparison and PassKey Input (#165)

* Make NimBLEConnInfo functions const.

* Update callback functions and update client to use new functions.

* Update examples.

* Update migration guide.

---------

Co-authored-by: Casey Smith <csmith@morningstarcorp.com>
This commit is contained in:
h2zero
2024-06-06 19:36:14 -06:00
committed by GitHub
co-authored by Casey Smith
parent 6ca61bbd9c
commit 9c1f1adf7a
14 changed files with 202 additions and 181 deletions
+21 -10
View File
@@ -51,17 +51,28 @@ class MyClientCallback : public BLEClientCallbacks {
}
/***************** New - Security handled here ********************
****** Note: these are the same return values as defaults ********/
uint32_t onPassKeyRequest(){
printf("Client PassKeyRequest\n");
return 123456;
}
bool onConfirmPIN(uint32_t pass_key){
printf("The passkey YES/NO number: %" PRIu32"\n", pass_key);
return true;
}
void onPassKeyEntry(const NimBLEConnInfo& connInfo){
printf("Server Passkey Entry\n");
/** This should prompt the user to enter the passkey displayed
* on the peer device.
*/
NimBLEDevice::injectPassKey(connInfo, 123456);
};
void onAuthenticationComplete(BLEConnInfo& connInfo){
printf("Starting BLE work!\n");
void onConfirmPIN(const NimBLEConnInfo& connInfo, uint32_t pass_key){
printf("The passkey YES/NO number: %" PRIu32 "\n", pass_key);
/** Inject false if passkeys don't match. */
NimBLEDevice::injectConfirmPIN(connInfo, true);
};
/** Pairing process complete, we can check the results in connInfo */
void onAuthenticationComplete(const NimBLEConnInfo& connInfo){
if(!connInfo.isEncrypted()) {
printf("Encrypt connection failed - disconnecting\n");
/** Find the client with the connection handle provided in desc */
NimBLEDevice::getClientByID(connInfo.getConnHandle())->disconnect();
return;
}
}
/*******************************************************************/
};