Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of BLE_API by
public/Gap.h@381:12cb29d3cea4, 2015-05-13 (annotated)
- Committer:
- rgrover1
- Date:
- Wed May 13 08:51:07 2015 +0100
- Revision:
- 381:12cb29d3cea4
- Parent:
- 380:2109a08c311c
- Child:
- 382:dcd0428dadb0
Synchronized with git rev aabb9c18
Author: Rohit Grover
update declaration for AdvertisementReportCallback_t
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| rgrover1 | 260:ea7f9f14cc15 | 1 | /* mbed Microcontroller Library |
| rgrover1 | 260:ea7f9f14cc15 | 2 | * Copyright (c) 2006-2013 ARM Limited |
| rgrover1 | 260:ea7f9f14cc15 | 3 | * |
| rgrover1 | 260:ea7f9f14cc15 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| rgrover1 | 260:ea7f9f14cc15 | 5 | * you may not use this file except in compliance with the License. |
| rgrover1 | 260:ea7f9f14cc15 | 6 | * You may obtain a copy of the License at |
| rgrover1 | 260:ea7f9f14cc15 | 7 | * |
| rgrover1 | 260:ea7f9f14cc15 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| rgrover1 | 260:ea7f9f14cc15 | 9 | * |
| rgrover1 | 260:ea7f9f14cc15 | 10 | * Unless required by applicable law or agreed to in writing, software |
| rgrover1 | 260:ea7f9f14cc15 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| rgrover1 | 260:ea7f9f14cc15 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| rgrover1 | 260:ea7f9f14cc15 | 13 | * See the License for the specific language governing permissions and |
| rgrover1 | 260:ea7f9f14cc15 | 14 | * limitations under the License. |
| rgrover1 | 260:ea7f9f14cc15 | 15 | */ |
| rgrover1 | 260:ea7f9f14cc15 | 16 | |
| rgrover1 | 260:ea7f9f14cc15 | 17 | #ifndef __GAP_H__ |
| rgrover1 | 260:ea7f9f14cc15 | 18 | #define __GAP_H__ |
| rgrover1 | 260:ea7f9f14cc15 | 19 | |
| rgrover1 | 260:ea7f9f14cc15 | 20 | #include "GapAdvertisingData.h" |
| rgrover1 | 260:ea7f9f14cc15 | 21 | #include "GapAdvertisingParams.h" |
| rgrover1 | 260:ea7f9f14cc15 | 22 | #include "GapEvents.h" |
| rgrover1 | 260:ea7f9f14cc15 | 23 | #include "CallChain.h" |
| rgrover1 | 260:ea7f9f14cc15 | 24 | |
| rgrover1 | 260:ea7f9f14cc15 | 25 | using namespace mbed; |
| rgrover1 | 260:ea7f9f14cc15 | 26 | |
| rgrover1 | 260:ea7f9f14cc15 | 27 | class Gap { |
| rgrover1 | 260:ea7f9f14cc15 | 28 | public: |
| rgrover1 | 375:9cb0b006227e | 29 | enum AddressType_t { |
| rgrover1 | 260:ea7f9f14cc15 | 30 | ADDR_TYPE_PUBLIC = 0, |
| rgrover1 | 260:ea7f9f14cc15 | 31 | ADDR_TYPE_RANDOM_STATIC, |
| rgrover1 | 260:ea7f9f14cc15 | 32 | ADDR_TYPE_RANDOM_PRIVATE_RESOLVABLE, |
| rgrover1 | 260:ea7f9f14cc15 | 33 | ADDR_TYPE_RANDOM_PRIVATE_NON_RESOLVABLE |
| rgrover1 | 375:9cb0b006227e | 34 | }; |
| rgrover1 | 375:9cb0b006227e | 35 | typedef enum AddressType_t addr_type_t; /* @Note: decprecated. */ |
| rgrover1 | 260:ea7f9f14cc15 | 36 | |
| rgrover1 | 260:ea7f9f14cc15 | 37 | static const unsigned ADDR_LEN = 6; |
| rgrover1 | 375:9cb0b006227e | 38 | typedef uint8_t Address_t[ADDR_LEN]; /* 48-bit address, LSB format. */ |
| rgrover1 | 375:9cb0b006227e | 39 | typedef Address_t address_t; /* @Note: deprecated. */ |
| rgrover1 | 260:ea7f9f14cc15 | 40 | |
| rgrover1 | 380:2109a08c311c | 41 | enum AdvertisementType_t { |
| rgrover1 | 380:2109a08c311c | 42 | ADV_IND = 0x00, /**< Connectable undirected. */ |
| rgrover1 | 380:2109a08c311c | 43 | ADV_DIRECT_IND = 0x01, /**< Connectable directed. */ |
| rgrover1 | 380:2109a08c311c | 44 | ADV_SCAN_IND = 0x02, /**< Scannable undirected. */ |
| rgrover1 | 380:2109a08c311c | 45 | ADV_NONCONN_IND = 0x03, /**< Non connectable undirected. */ |
| rgrover1 | 380:2109a08c311c | 46 | }; |
| rgrover1 | 380:2109a08c311c | 47 | |
| rgrover1 | 260:ea7f9f14cc15 | 48 | /** |
| rgrover1 | 260:ea7f9f14cc15 | 49 | * Enumeration for disconnection reasons. The values for these reasons are |
| rgrover1 | 260:ea7f9f14cc15 | 50 | * derived from Nordic's implementation; but the reasons are meant to be |
| rgrover1 | 260:ea7f9f14cc15 | 51 | * independent of the transport. If you are returned a reason which is not |
| rgrover1 | 260:ea7f9f14cc15 | 52 | * covered by this enumeration, then please refer to the underlying |
| rgrover1 | 260:ea7f9f14cc15 | 53 | * transport library. |
| rgrover1 | 260:ea7f9f14cc15 | 54 | */ |
| rgrover1 | 260:ea7f9f14cc15 | 55 | enum DisconnectionReason_t { |
| rgrover1 | 260:ea7f9f14cc15 | 56 | REMOTE_USER_TERMINATED_CONNECTION = 0x13, |
| rgrover1 | 260:ea7f9f14cc15 | 57 | LOCAL_HOST_TERMINATED_CONNECTION = 0x16, |
| rgrover1 | 260:ea7f9f14cc15 | 58 | CONN_INTERVAL_UNACCEPTABLE = 0x3B, |
| rgrover1 | 260:ea7f9f14cc15 | 59 | }; |
| rgrover1 | 260:ea7f9f14cc15 | 60 | |
| rgrover1 | 260:ea7f9f14cc15 | 61 | /* Describes the current state of the device (more than one bit can be set) */ |
| rgrover1 | 260:ea7f9f14cc15 | 62 | typedef struct GapState_s { |
| rgrover1 | 260:ea7f9f14cc15 | 63 | unsigned advertising : 1; /**< peripheral is currently advertising */ |
| rgrover1 | 260:ea7f9f14cc15 | 64 | unsigned connected : 1; /**< peripheral is connected to a central */ |
| rgrover1 | 260:ea7f9f14cc15 | 65 | } GapState_t; |
| rgrover1 | 260:ea7f9f14cc15 | 66 | |
| rgrover1 | 260:ea7f9f14cc15 | 67 | typedef uint16_t Handle_t; |
| rgrover1 | 260:ea7f9f14cc15 | 68 | |
| rgrover1 | 260:ea7f9f14cc15 | 69 | typedef struct { |
| rgrover1 | 260:ea7f9f14cc15 | 70 | uint16_t minConnectionInterval; /**< Minimum Connection Interval in 1.25 ms units, see @ref BLE_GAP_CP_LIMITS.*/ |
| rgrover1 | 260:ea7f9f14cc15 | 71 | uint16_t maxConnectionInterval; /**< Maximum Connection Interval in 1.25 ms units, see @ref BLE_GAP_CP_LIMITS.*/ |
| rgrover1 | 260:ea7f9f14cc15 | 72 | uint16_t slaveLatency; /**< Slave Latency in number of connection events, see @ref BLE_GAP_CP_LIMITS.*/ |
| rgrover1 | 260:ea7f9f14cc15 | 73 | uint16_t connectionSupervisionTimeout; /**< Connection Supervision Timeout in 10 ms units, see @ref BLE_GAP_CP_LIMITS.*/ |
| rgrover1 | 260:ea7f9f14cc15 | 74 | } ConnectionParams_t; |
| rgrover1 | 260:ea7f9f14cc15 | 75 | |
| rgrover1 | 360:7d37e1adef33 | 76 | enum SecurityMode_t { |
| rgrover1 | 361:9686f5c882fa | 77 | SECURITY_MODE_NO_ACCESS, |
| rgrover1 | 372:0db007a23f71 | 78 | SECURITY_MODE_ENCRYPTION_OPEN_LINK, /**< require no protection, open link. */ |
| rgrover1 | 372:0db007a23f71 | 79 | SECURITY_MODE_ENCRYPTION_NO_MITM, /**< require encryption, but no MITM protection. */ |
| rgrover1 | 372:0db007a23f71 | 80 | SECURITY_MODE_ENCRYPTION_WITH_MITM, /**< require encryption and MITM protection. */ |
| rgrover1 | 372:0db007a23f71 | 81 | SECURITY_MODE_SIGNED_NO_MITM, /**< require signing or encryption, but no MITM protection. */ |
| rgrover1 | 372:0db007a23f71 | 82 | SECURITY_MODE_SIGNED_WITH_MITM, /**< require signing or encryption, and MITM protection. */ |
| rgrover1 | 360:7d37e1adef33 | 83 | }; |
| rgrover1 | 360:7d37e1adef33 | 84 | |
| rgrover1 | 352:79d7cb60ae27 | 85 | /** |
| rgrover1 | 352:79d7cb60ae27 | 86 | * @brief Defines possible security status/states. |
| rgrover1 | 352:79d7cb60ae27 | 87 | * |
| rgrover1 | 352:79d7cb60ae27 | 88 | * @details Defines possible security status/states of a link when requested by getLinkSecurity(). |
| rgrover1 | 352:79d7cb60ae27 | 89 | */ |
| rgrover1 | 352:79d7cb60ae27 | 90 | enum LinkSecurityStatus_t { |
| rgrover1 | 352:79d7cb60ae27 | 91 | NOT_ENCRYPTED, /**< The link is not secured. */ |
| rgrover1 | 352:79d7cb60ae27 | 92 | ENCRYPTION_IN_PROGRESS, /**< Link security is being established.*/ |
| rgrover1 | 352:79d7cb60ae27 | 93 | ENCRYPTED /**< The link is secure.*/ |
| rgrover1 | 352:79d7cb60ae27 | 94 | }; |
| rgrover1 | 352:79d7cb60ae27 | 95 | |
| rgrover1 | 357:d4bb5d2b837a | 96 | enum SecurityIOCapabilities_t { |
| rgrover1 | 357:d4bb5d2b837a | 97 | IO_CAPS_DISPLAY_ONLY = 0x00, /**< Display Only. */ |
| rgrover1 | 357:d4bb5d2b837a | 98 | IO_CAPS_DISPLAY_YESNO = 0x01, /**< Display and Yes/No entry. */ |
| rgrover1 | 357:d4bb5d2b837a | 99 | IO_CAPS_KEYBOARD_ONLY = 0x02, /**< Keyboard Only. */ |
| rgrover1 | 357:d4bb5d2b837a | 100 | IO_CAPS_NONE = 0x03, /**< No I/O capabilities. */ |
| rgrover1 | 357:d4bb5d2b837a | 101 | IO_CAPS_KEYBOARD_DISPLAY = 0x04, /**< Keyboard and Display. */ |
| rgrover1 | 357:d4bb5d2b837a | 102 | }; |
| rgrover1 | 357:d4bb5d2b837a | 103 | |
| rgrover1 | 359:611485c370f5 | 104 | enum SecurityCompletionStatus_t { |
| rgrover1 | 359:611485c370f5 | 105 | SEC_STATUS_SUCCESS = 0x00, /**< Procedure completed with success. */ |
| rgrover1 | 359:611485c370f5 | 106 | SEC_STATUS_TIMEOUT = 0x01, /**< Procedure timed out. */ |
| rgrover1 | 359:611485c370f5 | 107 | SEC_STATUS_PDU_INVALID = 0x02, /**< Invalid PDU received. */ |
| rgrover1 | 367:c3f4ad55ed33 | 108 | SEC_STATUS_PASSKEY_ENTRY_FAILED = 0x81, /**< Passkey entry failed (user canceled or other). */ |
| rgrover1 | 359:611485c370f5 | 109 | SEC_STATUS_OOB_NOT_AVAILABLE = 0x82, /**< Out of Band Key not available. */ |
| rgrover1 | 359:611485c370f5 | 110 | SEC_STATUS_AUTH_REQ = 0x83, /**< Authentication requirements not met. */ |
| rgrover1 | 359:611485c370f5 | 111 | SEC_STATUS_CONFIRM_VALUE = 0x84, /**< Confirm value failed. */ |
| rgrover1 | 359:611485c370f5 | 112 | SEC_STATUS_PAIRING_NOT_SUPP = 0x85, /**< Pairing not supported. */ |
| rgrover1 | 359:611485c370f5 | 113 | SEC_STATUS_ENC_KEY_SIZE = 0x86, /**< Encryption key size. */ |
| rgrover1 | 359:611485c370f5 | 114 | SEC_STATUS_SMP_CMD_UNSUPPORTED = 0x87, /**< Unsupported SMP command. */ |
| rgrover1 | 359:611485c370f5 | 115 | SEC_STATUS_UNSPECIFIED = 0x88, /**< Unspecified reason. */ |
| rgrover1 | 359:611485c370f5 | 116 | SEC_STATUS_REPEATED_ATTEMPTS = 0x89, /**< Too little time elapsed since last attempt. */ |
| rgrover1 | 359:611485c370f5 | 117 | SEC_STATUS_INVALID_PARAMS = 0x8A, /**< Invalid parameters. */ |
| rgrover1 | 359:611485c370f5 | 118 | }; |
| rgrover1 | 359:611485c370f5 | 119 | |
| rgrover1 | 357:d4bb5d2b837a | 120 | /** |
| rgrover1 | 357:d4bb5d2b837a | 121 | * Declaration of type containing a passkey to be used during pairing. This |
| rgrover1 | 357:d4bb5d2b837a | 122 | * is passed into initializeSecurity() to specify a pre-programmed passkey |
| rgrover1 | 357:d4bb5d2b837a | 123 | * for authentication instead of generating a random one. |
| rgrover1 | 357:d4bb5d2b837a | 124 | */ |
| rgrover1 | 357:d4bb5d2b837a | 125 | static const unsigned PASSKEY_LEN = 6; |
| rgrover1 | 357:d4bb5d2b837a | 126 | typedef uint8_t Passkey_t[PASSKEY_LEN]; /**< 6-digit passkey in ASCII ('0'-'9' digits only). */ |
| rgrover1 | 357:d4bb5d2b837a | 127 | |
| rgrover1 | 260:ea7f9f14cc15 | 128 | static const uint16_t UNIT_1_25_MS = 1250; /**< Number of microseconds in 1.25 milliseconds. */ |
| rgrover1 | 260:ea7f9f14cc15 | 129 | static const uint16_t UNIT_0_625_MS = 650; /**< Number of microseconds in 0.625 milliseconds. */ |
| rgrover1 | 260:ea7f9f14cc15 | 130 | static uint16_t MSEC_TO_GAP_DURATION_UNITS(uint32_t durationInMillis) { |
| rgrover1 | 260:ea7f9f14cc15 | 131 | return (durationInMillis * 1000) / UNIT_1_25_MS; |
| rgrover1 | 260:ea7f9f14cc15 | 132 | } |
| rgrover1 | 260:ea7f9f14cc15 | 133 | static uint16_t MSEC_TO_ADVERTISEMENT_DURATION_UNITS(uint32_t durationInMillis) { |
| rgrover1 | 260:ea7f9f14cc15 | 134 | return (durationInMillis * 1000) / UNIT_0_625_MS; |
| rgrover1 | 260:ea7f9f14cc15 | 135 | } |
| rgrover1 | 325:501ad8b8bbe5 | 136 | static uint16_t GAP_DURATION_UNITS_TO_MS(uint16_t gapUnits) { |
| rgrover1 | 325:501ad8b8bbe5 | 137 | return (gapUnits * UNIT_0_625_MS) / 1000; |
| rgrover1 | 325:501ad8b8bbe5 | 138 | } |
| rgrover1 | 260:ea7f9f14cc15 | 139 | |
| rgrover1 | 260:ea7f9f14cc15 | 140 | typedef void (*EventCallback_t)(void); |
| rgrover1 | 342:152bd9c825d6 | 141 | typedef void (*ConnectionEventCallback_t)(Handle_t, |
| rgrover1 | 342:152bd9c825d6 | 142 | addr_type_t peerAddrType, const address_t peerAddr, |
| rgrover1 | 342:152bd9c825d6 | 143 | addr_type_t ownAddrType, const address_t ownAddr, |
| rgrover1 | 342:152bd9c825d6 | 144 | const ConnectionParams_t *); |
| rgrover1 | 349:b8b2b3973c47 | 145 | typedef void (*HandleSpecificEvent_t)(Handle_t handle); |
| rgrover1 | 260:ea7f9f14cc15 | 146 | typedef void (*DisconnectionEventCallback_t)(Handle_t, DisconnectionReason_t); |
| rgrover1 | 341:8a104d9d80c1 | 147 | typedef void (*RadioNotificationEventCallback_t) (bool radio_active); /* gets passed true for ACTIVE; false for INACTIVE. */ |
| rgrover1 | 363:a3d59a6e5da0 | 148 | typedef void (*SecuritySetupInitiatedCallback_t)(Handle_t, bool allowBonding, bool requireMITM, SecurityIOCapabilities_t iocaps); |
| rgrover1 | 363:a3d59a6e5da0 | 149 | typedef void (*SecuritySetupCompletedCallback_t)(Handle_t, SecurityCompletionStatus_t status); |
| rgrover1 | 362:3b1ff00ad8a4 | 150 | typedef void (*LinkSecuredCallback_t)(Handle_t handle, SecurityMode_t securityMode); |
| rgrover1 | 369:9a76cc068644 | 151 | typedef void (*PasskeyDisplayCallback_t)(Handle_t handle, const Passkey_t passkey); |
| rgrover1 | 260:ea7f9f14cc15 | 152 | |
| rgrover1 | 381:12cb29d3cea4 | 153 | typedef void (*AdvertisementReportCallback_t)(const address_t peerAddr, |
| rgrover1 | 381:12cb29d3cea4 | 154 | int8_t rssi, |
| rgrover1 | 381:12cb29d3cea4 | 155 | bool isScanResponse, |
| rgrover1 | 381:12cb29d3cea4 | 156 | AdvertisementType_t type, |
| rgrover1 | 381:12cb29d3cea4 | 157 | uint8_t advertisingDataLen, |
| rgrover1 | 381:12cb29d3cea4 | 158 | const uint8_t *advertisingData); |
| rgrover1 | 380:2109a08c311c | 159 | |
| rgrover1 | 260:ea7f9f14cc15 | 160 | friend class BLEDevice; |
| rgrover1 | 378:a8b035d877a8 | 161 | |
| rgrover1 | 260:ea7f9f14cc15 | 162 | private: |
| rgrover1 | 260:ea7f9f14cc15 | 163 | /* These functions must be defined in the sub-class */ |
| rgrover1 | 260:ea7f9f14cc15 | 164 | virtual ble_error_t setAddress(addr_type_t type, const address_t address) = 0; |
| rgrover1 | 260:ea7f9f14cc15 | 165 | virtual ble_error_t getAddress(addr_type_t *typeP, address_t address) = 0; |
| rgrover1 | 260:ea7f9f14cc15 | 166 | virtual ble_error_t setAdvertisingData(const GapAdvertisingData &, const GapAdvertisingData &) = 0; |
| rgrover1 | 260:ea7f9f14cc15 | 167 | virtual ble_error_t startAdvertising(const GapAdvertisingParams &) = 0; |
| rgrover1 | 260:ea7f9f14cc15 | 168 | virtual ble_error_t stopAdvertising(void) = 0; |
| rgrover1 | 325:501ad8b8bbe5 | 169 | virtual uint16_t getMinAdvertisingInterval(void) const = 0; |
| rgrover1 | 325:501ad8b8bbe5 | 170 | virtual uint16_t getMinNonConnectableAdvertisingInterval(void) const = 0; |
| rgrover1 | 325:501ad8b8bbe5 | 171 | virtual uint16_t getMaxAdvertisingInterval(void) const = 0; |
| rgrover1 | 260:ea7f9f14cc15 | 172 | virtual ble_error_t disconnect(DisconnectionReason_t reason) = 0; |
| rgrover1 | 260:ea7f9f14cc15 | 173 | virtual ble_error_t getPreferredConnectionParams(ConnectionParams_t *params) = 0; |
| rgrover1 | 260:ea7f9f14cc15 | 174 | virtual ble_error_t setPreferredConnectionParams(const ConnectionParams_t *params) = 0; |
| rgrover1 | 260:ea7f9f14cc15 | 175 | virtual ble_error_t updateConnectionParams(Handle_t handle, const ConnectionParams_t *params) = 0; |
| rgrover1 | 260:ea7f9f14cc15 | 176 | |
| rgrover1 | 353:5ed63cda3038 | 177 | virtual ble_error_t purgeAllBondingState(void) = 0; |
| rgrover1 | 352:79d7cb60ae27 | 178 | virtual ble_error_t getLinkSecurity(Handle_t connectionHandle, LinkSecurityStatus_t *securityStatusP) = 0; |
| rgrover1 | 352:79d7cb60ae27 | 179 | |
| rgrover1 | 260:ea7f9f14cc15 | 180 | virtual ble_error_t setDeviceName(const uint8_t *deviceName) = 0; |
| rgrover1 | 260:ea7f9f14cc15 | 181 | virtual ble_error_t getDeviceName(uint8_t *deviceName, unsigned *lengthP) = 0; |
| rgrover1 | 260:ea7f9f14cc15 | 182 | virtual ble_error_t setAppearance(uint16_t appearance) = 0; |
| rgrover1 | 260:ea7f9f14cc15 | 183 | virtual ble_error_t getAppearance(uint16_t *appearanceP) = 0; |
| rgrover1 | 260:ea7f9f14cc15 | 184 | |
| rgrover1 | 337:e7c2eb38f5cc | 185 | protected: |
| rgrover1 | 260:ea7f9f14cc15 | 186 | /* Event callback handlers */ |
| rgrover1 | 260:ea7f9f14cc15 | 187 | void setOnTimeout(EventCallback_t callback) {onTimeout = callback;} |
| rgrover1 | 260:ea7f9f14cc15 | 188 | void setOnConnection(ConnectionEventCallback_t callback) {onConnection = callback;} |
| rgrover1 | 260:ea7f9f14cc15 | 189 | |
| rgrover1 | 260:ea7f9f14cc15 | 190 | /** |
| rgrover1 | 260:ea7f9f14cc15 | 191 | * Set the application callback for disconnection events. |
| rgrover1 | 260:ea7f9f14cc15 | 192 | * @param callback |
| rgrover1 | 260:ea7f9f14cc15 | 193 | * Pointer to the unique callback. |
| rgrover1 | 260:ea7f9f14cc15 | 194 | */ |
| rgrover1 | 260:ea7f9f14cc15 | 195 | void setOnDisconnection(DisconnectionEventCallback_t callback) {onDisconnection = callback;} |
| rgrover1 | 260:ea7f9f14cc15 | 196 | |
| rgrover1 | 260:ea7f9f14cc15 | 197 | /** |
| rgrover1 | 341:8a104d9d80c1 | 198 | * Set the application callback for radio-notification events. |
| rgrover1 | 341:8a104d9d80c1 | 199 | * @param callback |
| rgrover1 | 367:c3f4ad55ed33 | 200 | * Handler to be executed in response to a radio notification event. |
| rgrover1 | 341:8a104d9d80c1 | 201 | */ |
| rgrover1 | 341:8a104d9d80c1 | 202 | virtual void setOnRadioNotification(RadioNotificationEventCallback_t callback) {onRadioNotification = callback;} |
| rgrover1 | 341:8a104d9d80c1 | 203 | |
| rgrover1 | 341:8a104d9d80c1 | 204 | /** |
| rgrover1 | 349:b8b2b3973c47 | 205 | * To indicate that security procedure for link has started. |
| rgrover1 | 349:b8b2b3973c47 | 206 | */ |
| rgrover1 | 364:03a7a439a3bf | 207 | virtual void setOnSecuritySetupInitiated(SecuritySetupInitiatedCallback_t callback) {onSecuritySetupInitiated = callback;} |
| rgrover1 | 349:b8b2b3973c47 | 208 | |
| rgrover1 | 349:b8b2b3973c47 | 209 | /** |
| rgrover1 | 349:b8b2b3973c47 | 210 | * To indicate that security procedure for link has completed. |
| rgrover1 | 349:b8b2b3973c47 | 211 | */ |
| rgrover1 | 364:03a7a439a3bf | 212 | virtual void setOnSecuritySetupCompleted(SecuritySetupCompletedCallback_t callback) {onSecuritySetupCompleted = callback;} |
| rgrover1 | 349:b8b2b3973c47 | 213 | |
| rgrover1 | 349:b8b2b3973c47 | 214 | /** |
| rgrover1 | 349:b8b2b3973c47 | 215 | * To indicate that link with the peer is secured. For bonded devices, |
| rgrover1 | 367:c3f4ad55ed33 | 216 | * subsequent re-connections with bonded peer will result only in this callback |
| rgrover1 | 349:b8b2b3973c47 | 217 | * when the link is secured and setup procedures will not occur unless the |
| rgrover1 | 349:b8b2b3973c47 | 218 | * bonding information is either lost or deleted on either or both sides. |
| rgrover1 | 349:b8b2b3973c47 | 219 | */ |
| rgrover1 | 362:3b1ff00ad8a4 | 220 | virtual void setOnLinkSecured(LinkSecuredCallback_t callback) {onLinkSecured = callback;} |
| rgrover1 | 349:b8b2b3973c47 | 221 | |
| rgrover1 | 349:b8b2b3973c47 | 222 | /** |
| rgrover1 | 349:b8b2b3973c47 | 223 | * To indicate that device context is stored persistently. |
| rgrover1 | 349:b8b2b3973c47 | 224 | */ |
| rgrover1 | 349:b8b2b3973c47 | 225 | virtual void setOnSecurityContextStored(HandleSpecificEvent_t callback) {onSecurityContextStored = callback;} |
| rgrover1 | 349:b8b2b3973c47 | 226 | |
| rgrover1 | 349:b8b2b3973c47 | 227 | /** |
| rgrover1 | 369:9a76cc068644 | 228 | * To set the callback for when the passkey needs to be displayed on a peripheral with DISPLAY capability. |
| rgrover1 | 369:9a76cc068644 | 229 | */ |
| rgrover1 | 369:9a76cc068644 | 230 | virtual void setOnPasskeyDisplay(PasskeyDisplayCallback_t callback) {onPasskeyDisplay = callback;} |
| rgrover1 | 369:9a76cc068644 | 231 | |
| rgrover1 | 369:9a76cc068644 | 232 | /** |
| rgrover1 | 260:ea7f9f14cc15 | 233 | * Append to a chain of callbacks to be invoked upon disconnection; these |
| rgrover1 | 260:ea7f9f14cc15 | 234 | * callbacks receive no context and are therefore different from the |
| rgrover1 | 260:ea7f9f14cc15 | 235 | * onDisconnection callback. |
| rgrover1 | 260:ea7f9f14cc15 | 236 | * @param callback |
| rgrover1 | 260:ea7f9f14cc15 | 237 | * function pointer to be invoked upon disconnection; receives no context. |
| rgrover1 | 260:ea7f9f14cc15 | 238 | * |
| rgrover1 | 260:ea7f9f14cc15 | 239 | * @note the disconnection CallChain should have been merged with |
| rgrover1 | 260:ea7f9f14cc15 | 240 | * onDisconnctionCallback; but this was not possible because |
| rgrover1 | 260:ea7f9f14cc15 | 241 | * FunctionPointer (which is a building block for CallChain) doesn't |
| rgrover1 | 260:ea7f9f14cc15 | 242 | * accept variadic templates. |
| rgrover1 | 260:ea7f9f14cc15 | 243 | */ |
| rgrover1 | 260:ea7f9f14cc15 | 244 | template<typename T> |
| rgrover1 | 260:ea7f9f14cc15 | 245 | void addToDisconnectionCallChain(T *tptr, void (T::*mptr)(void)) {disconnectionCallChain.add(tptr, mptr);} |
| rgrover1 | 260:ea7f9f14cc15 | 246 | |
| rgrover1 | 337:e7c2eb38f5cc | 247 | private: |
| rgrover1 | 260:ea7f9f14cc15 | 248 | GapState_t getState(void) const { |
| rgrover1 | 260:ea7f9f14cc15 | 249 | return state; |
| rgrover1 | 260:ea7f9f14cc15 | 250 | } |
| rgrover1 | 260:ea7f9f14cc15 | 251 | |
| rgrover1 | 260:ea7f9f14cc15 | 252 | protected: |
| rgrover1 | 349:b8b2b3973c47 | 253 | Gap() : |
| rgrover1 | 349:b8b2b3973c47 | 254 | state(), |
| rgrover1 | 349:b8b2b3973c47 | 255 | onTimeout(NULL), |
| rgrover1 | 349:b8b2b3973c47 | 256 | onConnection(NULL), |
| rgrover1 | 349:b8b2b3973c47 | 257 | onDisconnection(NULL), |
| rgrover1 | 349:b8b2b3973c47 | 258 | onRadioNotification(), |
| rgrover1 | 364:03a7a439a3bf | 259 | onSecuritySetupInitiated(), |
| rgrover1 | 364:03a7a439a3bf | 260 | onSecuritySetupCompleted(), |
| rgrover1 | 349:b8b2b3973c47 | 261 | onLinkSecured(), |
| rgrover1 | 349:b8b2b3973c47 | 262 | onSecurityContextStored(), |
| rgrover1 | 369:9a76cc068644 | 263 | onPasskeyDisplay(), |
| rgrover1 | 349:b8b2b3973c47 | 264 | disconnectionCallChain() { |
| rgrover1 | 260:ea7f9f14cc15 | 265 | /* empty */ |
| rgrover1 | 260:ea7f9f14cc15 | 266 | } |
| rgrover1 | 260:ea7f9f14cc15 | 267 | |
| rgrover1 | 260:ea7f9f14cc15 | 268 | public: |
| rgrover1 | 342:152bd9c825d6 | 269 | void processConnectionEvent(Handle_t handle, addr_type_t peerAddrType, const address_t peerAddr, addr_type_t ownAddrType, const address_t ownAddr, const ConnectionParams_t *params) { |
| rgrover1 | 260:ea7f9f14cc15 | 270 | state.connected = 1; |
| rgrover1 | 260:ea7f9f14cc15 | 271 | if (onConnection) { |
| rgrover1 | 342:152bd9c825d6 | 272 | onConnection(handle, peerAddrType, peerAddr, ownAddrType, ownAddr, params); |
| rgrover1 | 260:ea7f9f14cc15 | 273 | } |
| rgrover1 | 260:ea7f9f14cc15 | 274 | } |
| rgrover1 | 260:ea7f9f14cc15 | 275 | |
| rgrover1 | 260:ea7f9f14cc15 | 276 | void processDisconnectionEvent(Handle_t handle, DisconnectionReason_t reason) { |
| rgrover1 | 260:ea7f9f14cc15 | 277 | state.connected = 0; |
| rgrover1 | 260:ea7f9f14cc15 | 278 | if (onDisconnection) { |
| rgrover1 | 260:ea7f9f14cc15 | 279 | onDisconnection(handle, reason); |
| rgrover1 | 260:ea7f9f14cc15 | 280 | } |
| rgrover1 | 260:ea7f9f14cc15 | 281 | disconnectionCallChain.call(); |
| rgrover1 | 260:ea7f9f14cc15 | 282 | } |
| rgrover1 | 260:ea7f9f14cc15 | 283 | |
| rgrover1 | 363:a3d59a6e5da0 | 284 | void processSecuritySetupInitiatedEvent(Handle_t handle, bool allowBonding, bool requireMITM, SecurityIOCapabilities_t iocaps) { |
| rgrover1 | 364:03a7a439a3bf | 285 | if (onSecuritySetupInitiated) { |
| rgrover1 | 364:03a7a439a3bf | 286 | onSecuritySetupInitiated(handle, allowBonding, requireMITM, iocaps); |
| rgrover1 | 349:b8b2b3973c47 | 287 | } |
| rgrover1 | 349:b8b2b3973c47 | 288 | } |
| rgrover1 | 349:b8b2b3973c47 | 289 | |
| rgrover1 | 363:a3d59a6e5da0 | 290 | void processSecuritySetupCompletedEvent(Handle_t handle, SecurityCompletionStatus_t status) { |
| rgrover1 | 364:03a7a439a3bf | 291 | if (onSecuritySetupCompleted) { |
| rgrover1 | 364:03a7a439a3bf | 292 | onSecuritySetupCompleted(handle, status); |
| rgrover1 | 349:b8b2b3973c47 | 293 | } |
| rgrover1 | 349:b8b2b3973c47 | 294 | } |
| rgrover1 | 349:b8b2b3973c47 | 295 | |
| rgrover1 | 362:3b1ff00ad8a4 | 296 | void processLinkSecuredEvent(Handle_t handle, SecurityMode_t securityMode) { |
| rgrover1 | 349:b8b2b3973c47 | 297 | if (onLinkSecured) { |
| rgrover1 | 362:3b1ff00ad8a4 | 298 | onLinkSecured(handle, securityMode); |
| rgrover1 | 349:b8b2b3973c47 | 299 | } |
| rgrover1 | 349:b8b2b3973c47 | 300 | } |
| rgrover1 | 349:b8b2b3973c47 | 301 | |
| rgrover1 | 349:b8b2b3973c47 | 302 | void processSecurityContextStoredEvent(Handle_t handle) { |
| rgrover1 | 349:b8b2b3973c47 | 303 | if (onSecurityContextStored) { |
| rgrover1 | 349:b8b2b3973c47 | 304 | onSecurityContextStored(handle); |
| rgrover1 | 349:b8b2b3973c47 | 305 | } |
| rgrover1 | 349:b8b2b3973c47 | 306 | } |
| rgrover1 | 349:b8b2b3973c47 | 307 | |
| rgrover1 | 369:9a76cc068644 | 308 | void processPasskeyDisplayEvent(Handle_t handle, const Passkey_t passkey) { |
| rgrover1 | 369:9a76cc068644 | 309 | if (onPasskeyDisplay) { |
| rgrover1 | 369:9a76cc068644 | 310 | onPasskeyDisplay(handle, passkey); |
| rgrover1 | 369:9a76cc068644 | 311 | } |
| rgrover1 | 369:9a76cc068644 | 312 | } |
| rgrover1 | 369:9a76cc068644 | 313 | |
| rgrover1 | 260:ea7f9f14cc15 | 314 | void processEvent(GapEvents::gapEvent_e type) { |
| rgrover1 | 260:ea7f9f14cc15 | 315 | switch (type) { |
| rgrover1 | 260:ea7f9f14cc15 | 316 | case GapEvents::GAP_EVENT_TIMEOUT: |
| rgrover1 | 260:ea7f9f14cc15 | 317 | state.advertising = 0; |
| rgrover1 | 260:ea7f9f14cc15 | 318 | if (onTimeout) { |
| rgrover1 | 260:ea7f9f14cc15 | 319 | onTimeout(); |
| rgrover1 | 260:ea7f9f14cc15 | 320 | } |
| rgrover1 | 260:ea7f9f14cc15 | 321 | break; |
| rgrover1 | 267:ad6f6f40eb24 | 322 | default: |
| rgrover1 | 267:ad6f6f40eb24 | 323 | break; |
| rgrover1 | 260:ea7f9f14cc15 | 324 | } |
| rgrover1 | 260:ea7f9f14cc15 | 325 | } |
| rgrover1 | 260:ea7f9f14cc15 | 326 | |
| rgrover1 | 260:ea7f9f14cc15 | 327 | protected: |
| rgrover1 | 363:a3d59a6e5da0 | 328 | GapState_t state; |
| rgrover1 | 260:ea7f9f14cc15 | 329 | |
| rgrover1 | 337:e7c2eb38f5cc | 330 | protected: |
| rgrover1 | 363:a3d59a6e5da0 | 331 | EventCallback_t onTimeout; |
| rgrover1 | 363:a3d59a6e5da0 | 332 | ConnectionEventCallback_t onConnection; |
| rgrover1 | 363:a3d59a6e5da0 | 333 | DisconnectionEventCallback_t onDisconnection; |
| rgrover1 | 363:a3d59a6e5da0 | 334 | RadioNotificationEventCallback_t onRadioNotification; |
| rgrover1 | 364:03a7a439a3bf | 335 | SecuritySetupInitiatedCallback_t onSecuritySetupInitiated; |
| rgrover1 | 364:03a7a439a3bf | 336 | SecuritySetupCompletedCallback_t onSecuritySetupCompleted; |
| rgrover1 | 363:a3d59a6e5da0 | 337 | LinkSecuredCallback_t onLinkSecured; |
| rgrover1 | 363:a3d59a6e5da0 | 338 | HandleSpecificEvent_t onSecurityContextStored; |
| rgrover1 | 369:9a76cc068644 | 339 | PasskeyDisplayCallback_t onPasskeyDisplay; |
| rgrover1 | 363:a3d59a6e5da0 | 340 | CallChain disconnectionCallChain; |
| rgrover1 | 260:ea7f9f14cc15 | 341 | |
| rgrover1 | 260:ea7f9f14cc15 | 342 | private: |
| rgrover1 | 260:ea7f9f14cc15 | 343 | /* disallow copy and assignment */ |
| rgrover1 | 260:ea7f9f14cc15 | 344 | Gap(const Gap &); |
| rgrover1 | 260:ea7f9f14cc15 | 345 | Gap& operator=(const Gap &); |
| rgrover1 | 260:ea7f9f14cc15 | 346 | }; |
| rgrover1 | 260:ea7f9f14cc15 | 347 | |
| rgrover1 | 260:ea7f9f14cc15 | 348 | #endif // ifndef __GAP_H__ |
