Lightly modified version of the BLE stack, that doesn't bring up a DFUService by default... as we have our own.
Fork of BLE_API by
Revision 349:b8b2b3973c47, committed 2015-05-08
- Comitter:
- rgrover1
- Date:
- Fri May 08 15:35:46 2015 +0100
- Parent:
- 348:d5ad8959683f
- Child:
- 350:64b656246a72
- Commit message:
- Synchronized with git rev 0e8731df
Author: Rohit Grover
Add APIs to setup callbacks for events related to security/bonding.
Changed in this revision
public/BLEDevice.h | Show annotated file Show diff for this revision Revisions of this file |
public/Gap.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/public/BLEDevice.h Fri May 08 15:35:45 2015 +0100 +++ b/public/BLEDevice.h Fri May 08 15:35:46 2015 +0100 @@ -331,6 +331,32 @@ void onRadioNotification(Gap::RadioNotificationEventCallback_t callback); /** + * Setup a callback for when the security procedure for a link has started. + */ + void setOnSecuritySetupStarted(Gap::HandleSpecificEvent_t callback); + + /** + * Setup a callback for when the security procedure for a link has + * completed. + */ + void setOnSecuritySetupCompleted(Gap::HandleSpecificEvent_t callback); + + /** + * Setup a callback for when a link with the peer is secured. For bonded + * devices, subsequent reconnections with bonded peer will result only in + * this callback when the link is secured and setup procedures will not + * occur unless the bonding information is either lost or deleted on either + * or both sides. + */ + void setOnLinkSecured(Gap::HandleSpecificEvent_t callback); + + /** + * Setup a callback for bonding; i.e. that link-specific security context + * is stored persistently for a peer device. + */ + void setOnSecurityContextStored(Gap::HandleSpecificEvent_t callback); + + /** * Add a service declaration to the local server ATT table. Also add the * characteristics contained within. */ @@ -709,6 +735,30 @@ transport->getGap().setOnRadioNotification(callback); } +inline void +BLEDevice::setOnSecuritySetupStarted(Gap::HandleSpecificEvent_t callback) +{ + transport->getGap().setOnSecuritySetupStarted(callback); +} + +inline void +BLEDevice::setOnSecuritySetupCompleted(Gap::HandleSpecificEvent_t callback) +{ + transport->getGap().setOnSecuritySetupCompleted(callback); +} + +inline void +BLEDevice::setOnLinkSecured(Gap::HandleSpecificEvent_t callback) +{ + transport->getGap().setOnLinkSecured(callback); +} + +inline void +BLEDevice::setOnSecurityContextStored(Gap::HandleSpecificEvent_t callback) +{ + transport->getGap().setOnSecurityContextStored(callback); +} + inline ble_error_t BLEDevice::addService(GattService &service) {
--- a/public/Gap.h Fri May 08 15:35:45 2015 +0100 +++ b/public/Gap.h Fri May 08 15:35:46 2015 +0100 @@ -81,6 +81,7 @@ addr_type_t peerAddrType, const address_t peerAddr, addr_type_t ownAddrType, const address_t ownAddr, const ConnectionParams_t *); + typedef void (*HandleSpecificEvent_t)(Handle_t handle); typedef void (*DisconnectionEventCallback_t)(Handle_t, DisconnectionReason_t); typedef void (*RadioNotificationEventCallback_t) (bool radio_active); /* gets passed true for ACTIVE; false for INACTIVE. */ @@ -125,6 +126,29 @@ virtual void setOnRadioNotification(RadioNotificationEventCallback_t callback) {onRadioNotification = callback;} /** + * To indicate that security procedure for link has started. + */ + virtual void setOnSecuritySetupStarted(HandleSpecificEvent_t callback) {onSecuritySetupStarted = callback;} + + /** + * To indicate that security procedure for link has completed. + */ + virtual void setOnSecuritySetupCompleted(HandleSpecificEvent_t callback) {onSecuritySetupCompleted = callback;} + + /** + * To indicate that link with the peer is secured. For bonded devices, + * subsequent reconnections with bonded peer will result only in this callback + * when the link is secured and setup procedures will not occur unless the + * bonding information is either lost or deleted on either or both sides. + */ + virtual void setOnLinkSecured(HandleSpecificEvent_t callback) {onLinkSecured = callback;} + + /** + * To indicate that device context is stored persistently. + */ + virtual void setOnSecurityContextStored(HandleSpecificEvent_t callback) {onSecurityContextStored = callback;} + + /** * Append to a chain of callbacks to be invoked upon disconnection; these * callbacks receive no context and are therefore different from the * onDisconnection callback. @@ -145,8 +169,17 @@ } protected: - /* Default constructor. */ - Gap() : state(), onTimeout(NULL), onConnection(NULL), onDisconnection(NULL), onRadioNotification(), disconnectionCallChain() { + Gap() : + state(), + onTimeout(NULL), + onConnection(NULL), + onDisconnection(NULL), + onRadioNotification(), + onSecuritySetupStarted(), + onSecuritySetupCompleted(), + onLinkSecured(), + onSecurityContextStored(), + disconnectionCallChain() { /* empty */ } @@ -166,6 +199,30 @@ disconnectionCallChain.call(); } + void processSecuritySetupStartedEvent(Handle_t handle) { + if (onSecuritySetupStarted) { + onSecuritySetupStarted(handle); + } + } + + void processSecuritySetupCompletedEvent(Handle_t handle) { + if (onSecuritySetupCompleted) { + onSecuritySetupCompleted(handle); + } + } + + void processLinkSecuredEvent(Handle_t handle) { + if (onLinkSecured) { + onLinkSecured(handle); + } + } + + void processSecurityContextStoredEvent(Handle_t handle) { + if (onSecurityContextStored) { + onSecurityContextStored(handle); + } + } + void processEvent(GapEvents::gapEvent_e type) { switch (type) { case GapEvents::GAP_EVENT_TIMEOUT: @@ -187,6 +244,10 @@ ConnectionEventCallback_t onConnection; DisconnectionEventCallback_t onDisconnection; RadioNotificationEventCallback_t onRadioNotification; + HandleSpecificEvent_t onSecuritySetupStarted; + HandleSpecificEvent_t onSecuritySetupCompleted; + HandleSpecificEvent_t onLinkSecured; + HandleSpecificEvent_t onSecurityContextStored; CallChain disconnectionCallChain; private: