mirror of https://github.com/ARMmbed/mbed-os.git
class interface to avoid multiplying boilerplate code for the callbacks
parent
6f7da0ce1d
commit
eee2ddf709
|
@ -92,41 +92,51 @@ public:
|
|||
typedef void (*LinkSecuredCallback_t)(Gap::Handle_t handle, SecurityMode_t securityMode);
|
||||
typedef void (*PasskeyDisplayCallback_t)(Gap::Handle_t handle, const Passkey_t passkey);
|
||||
|
||||
typedef void (*ValidMicTimeout_t)(Gap::Handle_t handle);
|
||||
typedef void (*Link_key_failure_t)(Gap::Handle_t handle);
|
||||
typedef void (*KeypressNotification_t)(Gap::Handle_t handle, Keypress_t keypress);
|
||||
typedef void (*OobRequest_t)(Gap::Handle_t handle, bool extended = false);
|
||||
typedef void (*PinRequest_t)(Gap::Handle_t handle);
|
||||
typedef void (*PasskeyRequest_t)(Gap::Handle_t handle);
|
||||
typedef void (*ConfirmationRequest_t)(Gap::Handle_t handle);
|
||||
/* subclass to override handlers */
|
||||
class SecurityManagerEventHandler {
|
||||
SecurityManagerEventHandler() {};
|
||||
|
||||
struct SecurityManagerEventBlock {
|
||||
SecurityManagerEventBlock () :
|
||||
securitySetupInitiatedCallback(),
|
||||
securitySetupCompletedCallback(),
|
||||
linkSecuredCallback(),
|
||||
securityContextStoredCallback(),
|
||||
passkeyDisplayCallback(),
|
||||
validMicTimeoutCallback(),
|
||||
linkKeyFailureCallback(),
|
||||
keypressNotificationCallback(),
|
||||
oobRequestCallback(),
|
||||
pinRequestCallback(),
|
||||
passkeyRequestCallback(),
|
||||
confirmationRequestCallback() { }
|
||||
|
||||
SecuritySetupInitiatedCallback_t securitySetupInitiatedCallback;
|
||||
SecuritySetupCompletedCallback_t securitySetupCompletedCallback;
|
||||
LinkSecuredCallback_t linkSecuredCallback;
|
||||
HandleSpecificEvent_t securityContextStoredCallback;
|
||||
PasskeyDisplayCallback_t passkeyDisplayCallback;
|
||||
ValidMicTimeout_t validMicTimeoutCallback;
|
||||
Link_key_failure_t linkKeyFailureCallback;
|
||||
KeypressNotification_t keypressNotificationCallback;
|
||||
OobRequest_t oobRequestCallback;
|
||||
PinRequest_t pinRequestCallback;
|
||||
PasskeyRequest_t passkeyRequestCallback;
|
||||
ConfirmationRequest_t confirmationRequestCallback;
|
||||
void securitySetupInitiatedCallback(Gap::Handle_t handle, bool allowBonding, bool requireMITM, SecurityIOCapabilities_t iocaps) {
|
||||
(void)handle;
|
||||
(void)allowBonding;
|
||||
(void)requireMITM;
|
||||
(void)iocaps;
|
||||
};
|
||||
void securitySetupCompletedCallback(Gap::Handle_t handle, SecurityCompletionStatus_t status) {
|
||||
(void)handle;
|
||||
(void)status;
|
||||
};
|
||||
void linkSecuredCallback(Gap::Handle_t handle, SecurityMode_t securityMode) {
|
||||
(void)handle;
|
||||
(void)securityMode;
|
||||
};
|
||||
void passkeyDisplayCallback(Gap::Handle_t handle, const Passkey_t passkey) {
|
||||
(void)handle;
|
||||
(void)passkey;
|
||||
};
|
||||
void validMicTimeout(Gap::Handle_t handle) {
|
||||
(void)handle;
|
||||
};
|
||||
void link_key_failure(Gap::Handle_t handle) {
|
||||
(void)handle;
|
||||
};
|
||||
void keypressNotification(Gap::Handle_t handle, Keypress_t keypress) {
|
||||
(void)handle;
|
||||
(void)keypress;
|
||||
};
|
||||
void oobRequest(Gap::Handle_t handle, bool extended = false) {
|
||||
(void)handle;
|
||||
(void)extended;
|
||||
};
|
||||
void pinRequest(Gap::Handle_t handle) {
|
||||
(void)handle;
|
||||
};
|
||||
void passkeyRequest(Gap::Handle_t handle) {
|
||||
(void)handle;
|
||||
};
|
||||
void confirmationRequest(Gap::Handle_t handle) {
|
||||
(void)handle;
|
||||
};
|
||||
};
|
||||
|
||||
public:
|
||||
|
@ -275,112 +285,91 @@ public:
|
|||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*
|
||||
* To indicate that a security procedure for the link has started.
|
||||
*/
|
||||
virtual void onSecuritySetupInitiated(SecuritySetupInitiatedCallback_t callback) {_evt.securitySetupInitiatedCallback = callback;}
|
||||
virtual void onSecuritySetupInitiated(SecuritySetupInitiatedCallback_t callback) {securitySetupInitiatedCallback = callback;}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*
|
||||
* To indicate that the security procedure for the link has completed.
|
||||
*/
|
||||
virtual void onSecuritySetupCompleted(SecuritySetupCompletedCallback_t callback) {_evt.securitySetupCompletedCallback = callback;}
|
||||
virtual void onSecuritySetupCompleted(SecuritySetupCompletedCallback_t callback) {securitySetupCompletedCallback = callback;}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*
|
||||
* To indicate that the link with the peer is secured. For bonded devices,
|
||||
* subsequent reconnections with a bonded peer will result only in this callback
|
||||
* when the link is secured; setup procedures will not occur (unless the
|
||||
* bonding information is either lost or deleted on either or both sides).
|
||||
*/
|
||||
virtual void onLinkSecured(LinkSecuredCallback_t callback) {_evt.linkSecuredCallback = callback;}
|
||||
virtual void onLinkSecured(LinkSecuredCallback_t callback) {linkSecuredCallback = callback;}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*
|
||||
* To indicate that device context is stored persistently.
|
||||
*/
|
||||
virtual void onSecurityContextStored(HandleSpecificEvent_t callback) {_evt.securityContextStoredCallback = callback;}
|
||||
virtual void onSecurityContextStored(HandleSpecificEvent_t callback) {securityContextStoredCallback = callback;}
|
||||
|
||||
/**
|
||||
/** @deprecated
|
||||
*
|
||||
* To set the callback for when the passkey needs to be displayed on a peripheral with DISPLAY capability.
|
||||
*/
|
||||
virtual void onPasskeyDisplay(PasskeyDisplayCallback_t callback) {_evt.passkeyDisplayCallback = callback;}
|
||||
virtual void onPasskeyDisplay(PasskeyDisplayCallback_t callback) {passkeyDisplayCallback = callback;}
|
||||
|
||||
virtual void setSecurityManagerEventHandler(SecurityManagerEventHandler* handler) {
|
||||
if (handler) {
|
||||
delete eventHandler;
|
||||
eventHandler = handler;
|
||||
}
|
||||
}
|
||||
|
||||
/* Entry points for the underlying stack to report events back to the user. */
|
||||
public:
|
||||
/** @deprecated */
|
||||
void processSecuritySetupInitiatedEvent(Gap::Handle_t handle, bool allowBonding, bool requireMITM, SecurityIOCapabilities_t iocaps) {
|
||||
if (_evt.securitySetupInitiatedCallback) {
|
||||
_evt.securitySetupInitiatedCallback(handle, allowBonding, requireMITM, iocaps);
|
||||
if (securitySetupInitiatedCallback) {
|
||||
securitySetupInitiatedCallback(handle, allowBonding, requireMITM, iocaps);
|
||||
}
|
||||
}
|
||||
|
||||
/** @deprecated */
|
||||
void processSecuritySetupCompletedEvent(Gap::Handle_t handle, SecurityCompletionStatus_t status) {
|
||||
if (_evt.securitySetupCompletedCallback) {
|
||||
_evt.securitySetupCompletedCallback(handle, status);
|
||||
if (securitySetupCompletedCallback) {
|
||||
securitySetupCompletedCallback(handle, status);
|
||||
}
|
||||
}
|
||||
|
||||
/** @deprecated */
|
||||
void processLinkSecuredEvent(Gap::Handle_t handle, SecurityMode_t securityMode) {
|
||||
if (_evt.linkSecuredCallback) {
|
||||
_evt.linkSecuredCallback(handle, securityMode);
|
||||
if (linkSecuredCallback) {
|
||||
linkSecuredCallback(handle, securityMode);
|
||||
}
|
||||
}
|
||||
|
||||
/** @deprecated */
|
||||
void processSecurityContextStoredEvent(Gap::Handle_t handle) {
|
||||
if (_evt.securityContextStoredCallback) {
|
||||
_evt.securityContextStoredCallback(handle);
|
||||
if (securityContextStoredCallback) {
|
||||
securityContextStoredCallback(handle);
|
||||
}
|
||||
}
|
||||
|
||||
/** @deprecated */
|
||||
void processPasskeyDisplayEvent(Gap::Handle_t handle, const Passkey_t passkey) {
|
||||
if (_evt.passkeyDisplayCallback) {
|
||||
_evt.passkeyDisplayCallback(handle, passkey);
|
||||
}
|
||||
}
|
||||
|
||||
void processValidMicTimeout(Gap::Handle_t handle) {
|
||||
if (_evt.validMicTimeoutCallback) {
|
||||
_evt.validMicTimeoutCallback(handle);
|
||||
}
|
||||
}
|
||||
|
||||
void processLinkKeyFailure(Gap::Handle_t handle) {
|
||||
if (_evt.linkKeyFailureCallback) {
|
||||
_evt.linkKeyFailureCallback(handle);
|
||||
}
|
||||
}
|
||||
|
||||
void processKeypress(Gap::Handle_t handle, keypress_t keypress) {
|
||||
if (_evt.keypressCallback) {
|
||||
_evt.keypressCallback(handle, keypress);
|
||||
}
|
||||
}
|
||||
|
||||
void processOobRequest(Gap::Handle_t handle, bool extended = false) {
|
||||
if (_evt.oobRequestCallback) {
|
||||
_evt.oobRequestCallback(handle, extended);
|
||||
}
|
||||
}
|
||||
|
||||
void processPinRequest(Gap::Handle_t handle) {
|
||||
if (_evt.pinRequestCallback) {
|
||||
_evt.pinRequestCallback(handle);
|
||||
}
|
||||
}
|
||||
|
||||
void processPasskeyRequest(Gap::Handle_t handle) {
|
||||
if (_evt.passkeyRequestCallback) {
|
||||
_evt.passkeyRequestCallback(handle);
|
||||
}
|
||||
}
|
||||
|
||||
void processConfirmationRequest(Gap::Handle_t handle) {
|
||||
if (_evt.confirmationRequestCallback) {
|
||||
_evt.confirmationRequestCallback(handle);
|
||||
if (passkeyDisplayCallback) {
|
||||
passkeyDisplayCallback(handle, passkey);
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
SecurityManager() {
|
||||
/* empty */
|
||||
SecurityManager() :
|
||||
securitySetupInitiatedCallback(),
|
||||
securitySetupCompletedCallback(),
|
||||
linkSecuredCallback(),
|
||||
securityContextStoredCallback(),
|
||||
passkeyDisplayCallback() {
|
||||
eventHandler = new SecurityManagerEventHandler();
|
||||
}
|
||||
|
||||
public:
|
||||
/**
|
||||
* Notify all registered onShutdown callbacks that the SecurityManager is
|
||||
|
@ -399,15 +388,21 @@ public:
|
|||
/* Notify that the instance is about to shutdown */
|
||||
shutdownCallChain.call(this);
|
||||
shutdownCallChain.clear();
|
||||
_evt = SecurityManagerEventBlock();
|
||||
delete eventHandler;
|
||||
eventHandler = new SecurityManagerEventHandler();
|
||||
|
||||
return BLE_ERROR_NONE;
|
||||
}
|
||||
|
||||
protected:
|
||||
SecurityManagerEventBlock _evt;
|
||||
SecuritySetupInitiatedCallback_t securitySetupInitiatedCallback;
|
||||
SecuritySetupCompletedCallback_t securitySetupCompletedCallback;
|
||||
LinkSecuredCallback_t linkSecuredCallback;
|
||||
HandleSpecificEvent_t securityContextStoredCallback;
|
||||
PasskeyDisplayCallback_t passkeyDisplayCallback;
|
||||
|
||||
private:
|
||||
SecurityManagerEventHandler* eventHandler;
|
||||
SecurityManagerShutdownCallbackChain_t shutdownCallChain;
|
||||
};
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ using SecurityManager::SecurityMode_t;
|
|||
using SecurityManager::LinkSecurityStatus_t;
|
||||
using SecurityManager::Passkey_t;
|
||||
using SecurityManager::Keypress_t;
|
||||
using SecurityManager::SecurityManagerEventBlock;
|
||||
using SecurityManager::SecurityManagerEventHandler;
|
||||
|
||||
using BLEProtocol::AddressBytes_t;
|
||||
using BLEProtocol::Address_t;
|
||||
|
@ -72,7 +72,7 @@ struct boonded_list_t {
|
|||
|
||||
class SecurityManagerPal : private mbed::NonCopyable<SecurityManagerPal> {
|
||||
public:
|
||||
SecurityManagerPal(SecurityManagerEventBlock& evt) : _evt(evt) { };
|
||||
SecurityManagerPal(SecurityManagerEventHandler* event_handler) : _event_handler(event_handler) { };
|
||||
|
||||
virtual ble_error_t initialize() = 0;
|
||||
virtual ble_error_t terminate() = 0;
|
||||
|
@ -109,7 +109,7 @@ public:
|
|||
|
||||
/* security level */
|
||||
|
||||
virtual ble_error_t set_link_security_settings(AddressBytes_t address,
|
||||
virtual ble_error_t set_link_security_settings(connection_handle_t address,
|
||||
bool bondable = true,
|
||||
SecurityIOCapabilities_t iocaps = IO_CAPS_NONE,
|
||||
bool use_oob = false,
|
||||
|
@ -124,95 +124,30 @@ public:
|
|||
|
||||
/* MITM */
|
||||
|
||||
virtual ble_error_t confirmation_entered(AddressBytes_t address, bool confirmation) = 0;
|
||||
virtual ble_error_t passkey_entered(AddressBytes_t, passkey_t passkey) = 0;
|
||||
virtual ble_error_t send_keypress_notification(AddressBytes_t, Keypress_t keypress) = 0;
|
||||
virtual ble_error_t confirmation_entered(connection_handle_t address, bool confirmation) = 0;
|
||||
virtual ble_error_t passkey_entered(connection_handle_t, passkey_t passkey) = 0;
|
||||
virtual ble_error_t send_keypress_notification(connection_handle_t, Keypress_t keypress) = 0;
|
||||
|
||||
virtual ble_error_t set_link_oob(AddressBytes_t handle, c192_t*, r192_t*) = 0;
|
||||
virtual ble_error_t set_link_extended_oob(AddressBytes_t handle, c192_t*, r192_t*,c256_t*, r256_t*) = 0;
|
||||
virtual ble_error_t get_local_oob_data(AddressBytes_t handle, c192_t*, r192_t*) = 0;
|
||||
virtual ble_error_t get_local_extended_oob_data(AddressBytes_t handle, c192_t*, r192_t*,c256_t*, r256_t*) = 0;
|
||||
virtual ble_error_t set_link_oob(connection_handle_t handle, c192_t*, r192_t*) = 0;
|
||||
virtual ble_error_t set_link_extended_oob(connection_handle_t handle, c192_t*, r192_t*,c256_t*, r256_t*) = 0;
|
||||
virtual ble_error_t get_local_oob_data(connection_handle_t handle, c192_t*, r192_t*) = 0;
|
||||
virtual ble_error_t get_local_extended_oob_data(connection_handle_t handle, c192_t*, r192_t*,c256_t*, r256_t*) = 0;
|
||||
|
||||
/* Entry points for the underlying stack to report events back to the user. */
|
||||
public:
|
||||
void process_security_setup_initiated_event(connection_handle_t handle,
|
||||
bool allow_bonding,
|
||||
bool require_mitm,
|
||||
SecurityIOCapabilities_t iocaps) {
|
||||
if (_evt.securitySetupInitiatedCallback) {
|
||||
_evt.securitySetupInitiatedCallback(handle, allow_bonding, require_mitm, iocaps);
|
||||
}
|
||||
/* guaranteed to return valid pointer */
|
||||
SecurityManagerEventHandler get_event_handler() {
|
||||
return _event_handler;
|
||||
}
|
||||
|
||||
void process_security_setupCompleted_event(connection_handle_t handle,
|
||||
SecurityCompletionStatus_t status) {
|
||||
if (_evt.securitySetupCompletedCallback) {
|
||||
_evt.securitySetupCompletedCallback(handle, status);
|
||||
}
|
||||
}
|
||||
|
||||
void process_link_secured_event(connection_handle_t handle, SecurityMode_t security_mode) {
|
||||
if (_evt.linkSecuredCallback) {
|
||||
_evt.linkSecuredCallback(handle, security_mode);
|
||||
}
|
||||
}
|
||||
|
||||
void process_security_context_stored_event(connection_handle_t handle) {
|
||||
if (_evt.securityContextStoredCallback) {
|
||||
_evt.securityContextStoredCallback(handle);
|
||||
}
|
||||
}
|
||||
|
||||
void process_passkey_display_event(connection_handle_t handle, const Passkey_t passkey) {
|
||||
if (_evt.passkeyDisplayCallback) {
|
||||
_evt.passkeyDisplayCallback(handle, passkey);
|
||||
}
|
||||
}
|
||||
|
||||
void process_valid_mic_timeout(connection_handle_t handle) {
|
||||
if (_evt.validMicTimeoutCallback) {
|
||||
_evt.validMicTimeoutCallback(handle);
|
||||
}
|
||||
}
|
||||
|
||||
void process_link_key_failure(connection_handle_t handle) {
|
||||
if (_evt.linkKeyFailureCallback) {
|
||||
_evt.linkKeyFailureCallback(handle);
|
||||
}
|
||||
}
|
||||
|
||||
void process_keypress_notification(connection_handle_t handle, Keypress_t keypress) {
|
||||
if (_evt.keypressNotificationCallback) {
|
||||
_evt.keypressNotificationCallback(handle, keypress);
|
||||
}
|
||||
}
|
||||
|
||||
void process_oob_request(connection_handle_t handle, bool extended = false) {
|
||||
if (_evt.oobRequestCallback) {
|
||||
_evt.oobRequestCallback(handle, extended);
|
||||
}
|
||||
}
|
||||
|
||||
void process_pin_request(connection_handle_t handle) {
|
||||
if (_evt.pinRequestCallback) {
|
||||
_evt.pinRequestCallback(handle);
|
||||
}
|
||||
}
|
||||
|
||||
void process_passkey_request(connection_handle_t handle) {
|
||||
if (_evt.passkeyRequestCallback) {
|
||||
_evt.passkeyRequestCallback(handle);
|
||||
}
|
||||
}
|
||||
|
||||
void process_confirmation_request(connection_handle_t handle) {
|
||||
if (_evt.confirmationRequestCallback) {
|
||||
_evt.confirmationRequestCallback(handle);
|
||||
void setSecurityManagerEventHandler(SecurityManagerEventHandler* event_handler) {
|
||||
if (event_handler) {
|
||||
_event_handler = event_handler;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
SecurityManagerEventBlock& _evt;
|
||||
SecurityManagerEventHandler* _event_handler;
|
||||
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue