add support for passkey display.

This commit is contained in:
Rohit Grover 2015-05-08 13:51:44 +01:00
parent 838e27c2db
commit d1bd1a612c
2 changed files with 29 additions and 0 deletions

View file

@ -508,6 +508,15 @@ public:
*/
void onSecurityContextStored(Gap::HandleSpecificEvent_t callback);
/**
* Setup a callback for when the passkey needs to be displayed on a
* peripheral with DISPLAY capability. This happens when security is
* configured to prevent Man-In-The-Middle attacks, and a PIN (or passkey)
* needs to be exchanged between the peers to authenticate the connection
* attempt.
*/
void onPasskeyDisplay(Gap::PasskeyDisplayCallback_t callback);
/**
* Get the security status of a connection.
*
@ -918,4 +927,10 @@ BLEDevice::initializeSecurity(bool enableBonding,
return transport->initializeSecurity(enableBonding, requireMITM, iocaps, passkey);
}
inline void
BLEDevice::onPasskeyDisplay(Gap::PasskeyDisplayCallback_t callback)
{
return transport->getGap().setOnPasskeyDisplay(callback);
}
#endif // ifndef __BLE_DEVICE__

View file

@ -139,6 +139,7 @@ public:
typedef void (*SecuritySetupInitiatedCallback_t)(Handle_t, bool allowBonding, bool requireMITM, SecurityIOCapabilities_t iocaps);
typedef void (*SecuritySetupCompletedCallback_t)(Handle_t, SecurityCompletionStatus_t status);
typedef void (*LinkSecuredCallback_t)(Handle_t handle, SecurityMode_t securityMode);
typedef void (*PasskeyDisplayCallback_t)(Handle_t handle, const Passkey_t passkey);
friend class BLEDevice;
private:
@ -206,6 +207,11 @@ protected:
*/
virtual void setOnSecurityContextStored(HandleSpecificEvent_t callback) {onSecurityContextStored = callback;}
/**
* To set the callback for when the passkey needs to be displayed on a peripheral with DISPLAY capability.
*/
virtual void setOnPasskeyDisplay(PasskeyDisplayCallback_t callback) {onPasskeyDisplay = callback;}
/**
* Append to a chain of callbacks to be invoked upon disconnection; these
* callbacks receive no context and are therefore different from the
@ -237,6 +243,7 @@ protected:
onSecuritySetupCompleted(),
onLinkSecured(),
onSecurityContextStored(),
onPasskeyDisplay(),
disconnectionCallChain() {
/* empty */
}
@ -281,6 +288,12 @@ public:
}
}
void processPasskeyDisplayEvent(Handle_t handle, const Passkey_t passkey) {
if (onPasskeyDisplay) {
onPasskeyDisplay(handle, passkey);
}
}
void processEvent(GapEvents::gapEvent_e type) {
switch (type) {
case GapEvents::GAP_EVENT_TIMEOUT:
@ -306,6 +319,7 @@ protected:
SecuritySetupCompletedCallback_t onSecuritySetupCompleted;
LinkSecuredCallback_t onLinkSecured;
HandleSpecificEvent_t onSecurityContextStored;
PasskeyDisplayCallback_t onPasskeyDisplay;
CallChain disconnectionCallChain;
private: