Bike service
Fork of BLE_API by
ble/Gap.h@1189:039621a96054, 2016-04-06 (annotated)
- Committer:
- vcoubard
- Date:
- Wed Apr 06 19:15:42 2016 +0100
- Revision:
- 1189:039621a96054
- Parent:
- 1188:231e4007429a
- Child:
- 1190:740911150041
Synchronized with git rev bdfcd49c
Author: Andres Amaya Garcia
Gap doesnt commit adv payload changes on failure
Gap function members that modify the advertising and scan payload use the
underlying stack to test if the new payload is sane. If any errors are
generated, then the changes are not committed to copy of the payload in BLE API.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
vcoubard | 1132:692ddf04fc42 | 1 | /* mbed Microcontroller Library |
vcoubard | 1132:692ddf04fc42 | 2 | * Copyright (c) 2006-2013 ARM Limited |
vcoubard | 1132:692ddf04fc42 | 3 | * |
vcoubard | 1132:692ddf04fc42 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
vcoubard | 1132:692ddf04fc42 | 5 | * you may not use this file except in compliance with the License. |
vcoubard | 1132:692ddf04fc42 | 6 | * You may obtain a copy of the License at |
vcoubard | 1132:692ddf04fc42 | 7 | * |
vcoubard | 1132:692ddf04fc42 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
vcoubard | 1132:692ddf04fc42 | 9 | * |
vcoubard | 1132:692ddf04fc42 | 10 | * Unless required by applicable law or agreed to in writing, software |
vcoubard | 1132:692ddf04fc42 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
vcoubard | 1132:692ddf04fc42 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
vcoubard | 1132:692ddf04fc42 | 13 | * See the License for the specific language governing permissions and |
vcoubard | 1132:692ddf04fc42 | 14 | * limitations under the License. |
vcoubard | 1132:692ddf04fc42 | 15 | */ |
vcoubard | 1132:692ddf04fc42 | 16 | |
vcoubard | 1132:692ddf04fc42 | 17 | #ifndef __GAP_H__ |
vcoubard | 1132:692ddf04fc42 | 18 | #define __GAP_H__ |
vcoubard | 1132:692ddf04fc42 | 19 | |
vcoubard | 1136:22aada733dbd | 20 | #include "ble/BLEProtocol.h" |
vcoubard | 1132:692ddf04fc42 | 21 | #include "GapAdvertisingData.h" |
vcoubard | 1132:692ddf04fc42 | 22 | #include "GapAdvertisingParams.h" |
vcoubard | 1132:692ddf04fc42 | 23 | #include "GapScanningParams.h" |
vcoubard | 1132:692ddf04fc42 | 24 | #include "GapEvents.h" |
vcoubard | 1132:692ddf04fc42 | 25 | #include "CallChainOfFunctionPointersWithContext.h" |
vcoubard | 1132:692ddf04fc42 | 26 | #include "FunctionPointerWithContext.h" |
vcoubard | 1136:22aada733dbd | 27 | #include "deprecate.h" |
vcoubard | 1132:692ddf04fc42 | 28 | |
vcoubard | 1132:692ddf04fc42 | 29 | /* Forward declarations for classes that will only be used for pointers or references in the following. */ |
vcoubard | 1132:692ddf04fc42 | 30 | class GapAdvertisingParams; |
vcoubard | 1132:692ddf04fc42 | 31 | class GapScanningParams; |
vcoubard | 1132:692ddf04fc42 | 32 | class GapAdvertisingData; |
vcoubard | 1132:692ddf04fc42 | 33 | |
vcoubard | 1132:692ddf04fc42 | 34 | class Gap { |
vcoubard | 1136:22aada733dbd | 35 | /* |
vcoubard | 1136:22aada733dbd | 36 | * DEPRECATION ALERT: all of the APIs in this `public` block are deprecated. |
vcoubard | 1136:22aada733dbd | 37 | * They have been relocated to the class BLEProtocol. |
vcoubard | 1136:22aada733dbd | 38 | */ |
vcoubard | 1132:692ddf04fc42 | 39 | public: |
vcoubard | 1136:22aada733dbd | 40 | /** |
vcoubard | 1136:22aada733dbd | 41 | * Address-type for BLEProtocol addresses. |
vcoubard | 1136:22aada733dbd | 42 | * |
vcoubard | 1184:1589830dbdb7 | 43 | * @deprecated Use BLEProtocol::AddressType_t instead. |
vcoubard | 1136:22aada733dbd | 44 | */ |
vcoubard | 1136:22aada733dbd | 45 | typedef BLEProtocol::AddressType_t AddressType_t; |
vcoubard | 1136:22aada733dbd | 46 | |
vcoubard | 1136:22aada733dbd | 47 | /** |
vcoubard | 1136:22aada733dbd | 48 | * Address-type for BLEProtocol addresses. |
vcoubard | 1184:1589830dbdb7 | 49 | * |
vcoubard | 1184:1589830dbdb7 | 50 | * @deprecated Use BLEProtocol::AddressType_t instead. |
vcoubard | 1136:22aada733dbd | 51 | */ |
vcoubard | 1136:22aada733dbd | 52 | typedef BLEProtocol::AddressType_t addr_type_t; |
vcoubard | 1136:22aada733dbd | 53 | |
vcoubard | 1136:22aada733dbd | 54 | /** |
vcoubard | 1136:22aada733dbd | 55 | * Address-type for BLEProtocol addresses. |
vcoubard | 1136:22aada733dbd | 56 | * |
vcoubard | 1184:1589830dbdb7 | 57 | * @deprecated Use BLEProtocol::AddressType_t instead. The following |
vcoubard | 1184:1589830dbdb7 | 58 | * constants have been left in their deprecated state to |
vcoubard | 1184:1589830dbdb7 | 59 | * transparenly support existing applications which may have |
vcoubard | 1184:1589830dbdb7 | 60 | * used Gap::ADDR_TYPE_*. |
vcoubard | 1136:22aada733dbd | 61 | */ |
vcoubard | 1136:22aada733dbd | 62 | enum DeprecatedAddressType_t { |
vcoubard | 1136:22aada733dbd | 63 | ADDR_TYPE_PUBLIC = BLEProtocol::AddressType::PUBLIC, |
vcoubard | 1136:22aada733dbd | 64 | ADDR_TYPE_RANDOM_STATIC = BLEProtocol::AddressType::RANDOM_STATIC, |
vcoubard | 1136:22aada733dbd | 65 | ADDR_TYPE_RANDOM_PRIVATE_RESOLVABLE = BLEProtocol::AddressType::RANDOM_PRIVATE_RESOLVABLE, |
vcoubard | 1136:22aada733dbd | 66 | ADDR_TYPE_RANDOM_PRIVATE_NON_RESOLVABLE = BLEProtocol::AddressType::RANDOM_PRIVATE_NON_RESOLVABLE |
vcoubard | 1132:692ddf04fc42 | 67 | }; |
vcoubard | 1132:692ddf04fc42 | 68 | |
vcoubard | 1184:1589830dbdb7 | 69 | /** |
vcoubard | 1184:1589830dbdb7 | 70 | * Length (in octets) of the BLE MAC address. |
vcoubard | 1184:1589830dbdb7 | 71 | */ |
vcoubard | 1184:1589830dbdb7 | 72 | static const unsigned ADDR_LEN = BLEProtocol::ADDR_LEN; |
vcoubard | 1184:1589830dbdb7 | 73 | /** |
vcoubard | 1184:1589830dbdb7 | 74 | * 48-bit address, LSB format. |
vcoubard | 1184:1589830dbdb7 | 75 | * |
vcoubard | 1184:1589830dbdb7 | 76 | * @deprecated Use BLEProtocol::AddressBytes_t instead. |
vcoubard | 1184:1589830dbdb7 | 77 | */ |
vcoubard | 1184:1589830dbdb7 | 78 | typedef BLEProtocol::AddressBytes_t Address_t; |
vcoubard | 1184:1589830dbdb7 | 79 | /** |
vcoubard | 1184:1589830dbdb7 | 80 | * 48-bit address, LSB format. |
vcoubard | 1184:1589830dbdb7 | 81 | * |
vcoubard | 1184:1589830dbdb7 | 82 | * @deprecated Use BLEProtocol::AddressBytes_t instead. |
vcoubard | 1184:1589830dbdb7 | 83 | */ |
vcoubard | 1184:1589830dbdb7 | 84 | typedef BLEProtocol::AddressBytes_t address_t; |
vcoubard | 1132:692ddf04fc42 | 85 | |
vcoubard | 1136:22aada733dbd | 86 | public: |
vcoubard | 1184:1589830dbdb7 | 87 | /** |
vcoubard | 1184:1589830dbdb7 | 88 | * Enumeration for timeout sources. |
vcoubard | 1184:1589830dbdb7 | 89 | */ |
vcoubard | 1132:692ddf04fc42 | 90 | enum TimeoutSource_t { |
vcoubard | 1132:692ddf04fc42 | 91 | TIMEOUT_SRC_ADVERTISING = 0x00, /**< Advertising timeout. */ |
vcoubard | 1132:692ddf04fc42 | 92 | TIMEOUT_SRC_SECURITY_REQUEST = 0x01, /**< Security request timeout. */ |
vcoubard | 1132:692ddf04fc42 | 93 | TIMEOUT_SRC_SCAN = 0x02, /**< Scanning timeout. */ |
vcoubard | 1132:692ddf04fc42 | 94 | TIMEOUT_SRC_CONN = 0x03, /**< Connection timeout. */ |
vcoubard | 1132:692ddf04fc42 | 95 | }; |
vcoubard | 1132:692ddf04fc42 | 96 | |
vcoubard | 1132:692ddf04fc42 | 97 | /** |
vcoubard | 1132:692ddf04fc42 | 98 | * Enumeration for disconnection reasons. The values for these reasons are |
vcoubard | 1132:692ddf04fc42 | 99 | * derived from Nordic's implementation, but the reasons are meant to be |
vcoubard | 1132:692ddf04fc42 | 100 | * independent of the transport. If you are returned a reason that is not |
vcoubard | 1132:692ddf04fc42 | 101 | * covered by this enumeration, please refer to the underlying |
vcoubard | 1132:692ddf04fc42 | 102 | * transport library. |
vcoubard | 1132:692ddf04fc42 | 103 | */ |
vcoubard | 1132:692ddf04fc42 | 104 | enum DisconnectionReason_t { |
vcoubard | 1132:692ddf04fc42 | 105 | CONNECTION_TIMEOUT = 0x08, |
vcoubard | 1132:692ddf04fc42 | 106 | REMOTE_USER_TERMINATED_CONNECTION = 0x13, |
vcoubard | 1132:692ddf04fc42 | 107 | REMOTE_DEV_TERMINATION_DUE_TO_LOW_RESOURCES = 0x14, /**< Remote device terminated connection due to low resources.*/ |
vcoubard | 1132:692ddf04fc42 | 108 | REMOTE_DEV_TERMINATION_DUE_TO_POWER_OFF = 0x15, /**< Remote device terminated connection due to power off. */ |
vcoubard | 1132:692ddf04fc42 | 109 | LOCAL_HOST_TERMINATED_CONNECTION = 0x16, |
vcoubard | 1132:692ddf04fc42 | 110 | CONN_INTERVAL_UNACCEPTABLE = 0x3B, |
vcoubard | 1132:692ddf04fc42 | 111 | }; |
vcoubard | 1132:692ddf04fc42 | 112 | |
vcoubard | 1136:22aada733dbd | 113 | /** |
vcoubard | 1136:22aada733dbd | 114 | * Enumeration for whitelist advertising policy filter modes. The possible |
vcoubard | 1136:22aada733dbd | 115 | * filter modes were obtained from the Bluetooth Core Specification |
vcoubard | 1136:22aada733dbd | 116 | * 4.2 (Vol. 6), Part B, Section 4.3.2. |
vcoubard | 1136:22aada733dbd | 117 | * |
vcoubard | 1136:22aada733dbd | 118 | * @experimental |
vcoubard | 1136:22aada733dbd | 119 | */ |
vcoubard | 1136:22aada733dbd | 120 | enum AdvertisingPolicyMode_t { |
vcoubard | 1136:22aada733dbd | 121 | ADV_POLICY_IGNORE_WHITELIST = 0, |
vcoubard | 1136:22aada733dbd | 122 | ADV_POLICY_FILTER_SCAN_REQS = 1, |
vcoubard | 1136:22aada733dbd | 123 | ADV_POLICY_FILTER_CONN_REQS = 2, |
vcoubard | 1136:22aada733dbd | 124 | ADV_POLICY_FILTER_ALL_REQS = 3, |
vcoubard | 1136:22aada733dbd | 125 | }; |
vcoubard | 1136:22aada733dbd | 126 | |
vcoubard | 1136:22aada733dbd | 127 | /** |
vcoubard | 1136:22aada733dbd | 128 | * Enumeration for whitelist scanning policy filter modes. The possible |
vcoubard | 1136:22aada733dbd | 129 | * filter modes were obtained from the Bluetooth Core Specification |
vcoubard | 1136:22aada733dbd | 130 | * 4.2 (Vol. 6), Part B, Section 4.3.3. |
vcoubard | 1136:22aada733dbd | 131 | * |
vcoubard | 1136:22aada733dbd | 132 | * @experimental |
vcoubard | 1136:22aada733dbd | 133 | */ |
vcoubard | 1136:22aada733dbd | 134 | enum ScanningPolicyMode_t { |
vcoubard | 1136:22aada733dbd | 135 | SCAN_POLICY_IGNORE_WHITELIST = 0, |
vcoubard | 1136:22aada733dbd | 136 | SCAN_POLICY_FILTER_ALL_ADV = 1, |
vcoubard | 1136:22aada733dbd | 137 | }; |
vcoubard | 1136:22aada733dbd | 138 | |
vcoubard | 1136:22aada733dbd | 139 | /** |
vcoubard | 1136:22aada733dbd | 140 | * Enumeration for the whitelist initiator policy fiter modes. The possible |
vcoubard | 1136:22aada733dbd | 141 | * filter modes were obtained from the Bluetooth Core Specification |
vcoubard | 1136:22aada733dbd | 142 | * 4.2 (vol. 6), Part B, Section 4.4.4. |
vcoubard | 1136:22aada733dbd | 143 | * |
vcoubard | 1136:22aada733dbd | 144 | * @experimental |
vcoubard | 1136:22aada733dbd | 145 | */ |
vcoubard | 1136:22aada733dbd | 146 | enum InitiatorPolicyMode_t { |
vcoubard | 1136:22aada733dbd | 147 | INIT_POLICY_IGNORE_WHITELIST = 0, |
vcoubard | 1136:22aada733dbd | 148 | INIT_POLICY_FILTER_ALL_ADV = 1, |
vcoubard | 1136:22aada733dbd | 149 | }; |
vcoubard | 1136:22aada733dbd | 150 | |
vcoubard | 1136:22aada733dbd | 151 | /** |
vcoubard | 1136:22aada733dbd | 152 | * Representation of a Bluetooth Low Enery Whitelist containing addresses. |
vcoubard | 1136:22aada733dbd | 153 | * |
vcoubard | 1136:22aada733dbd | 154 | * @experimental |
vcoubard | 1136:22aada733dbd | 155 | */ |
vcoubard | 1136:22aada733dbd | 156 | struct Whitelist_t { |
vcoubard | 1184:1589830dbdb7 | 157 | BLEProtocol::Address_t *addresses; /**< List of BLE addresses in the whitelist. */ |
vcoubard | 1184:1589830dbdb7 | 158 | uint8_t size; /**< Total number of BLE addresses in this whitelist */ |
vcoubard | 1184:1589830dbdb7 | 159 | uint8_t capacity; /**< Maximum number of BLE addresses that can be added to this whitelist. */ |
vcoubard | 1136:22aada733dbd | 160 | }; |
vcoubard | 1136:22aada733dbd | 161 | |
vcoubard | 1136:22aada733dbd | 162 | |
vcoubard | 1184:1589830dbdb7 | 163 | /** |
vcoubard | 1184:1589830dbdb7 | 164 | * Describes the current state of the device (more than one bit can be set). |
vcoubard | 1184:1589830dbdb7 | 165 | */ |
vcoubard | 1132:692ddf04fc42 | 166 | struct GapState_t { |
vcoubard | 1132:692ddf04fc42 | 167 | unsigned advertising : 1; /**< Peripheral is currently advertising. */ |
vcoubard | 1132:692ddf04fc42 | 168 | unsigned connected : 1; /**< Peripheral is connected to a central. */ |
vcoubard | 1132:692ddf04fc42 | 169 | }; |
vcoubard | 1132:692ddf04fc42 | 170 | |
vcoubard | 1184:1589830dbdb7 | 171 | /** |
vcoubard | 1184:1589830dbdb7 | 172 | * Type for connection handle. |
vcoubard | 1184:1589830dbdb7 | 173 | */ |
vcoubard | 1184:1589830dbdb7 | 174 | typedef uint16_t Handle_t; |
vcoubard | 1132:692ddf04fc42 | 175 | |
vcoubard | 1184:1589830dbdb7 | 176 | /** |
vcoubard | 1184:1589830dbdb7 | 177 | * Structure containing GAP connection parameters. When in peripheral role |
vcoubard | 1184:1589830dbdb7 | 178 | * the connection parameters are suggestions. The choice of the connection |
vcoubard | 1184:1589830dbdb7 | 179 | * parameters is eventually up to the central. |
vcoubard | 1184:1589830dbdb7 | 180 | */ |
vcoubard | 1132:692ddf04fc42 | 181 | typedef struct { |
vcoubard | 1184:1589830dbdb7 | 182 | uint16_t minConnectionInterval; /**< Minimum Connection Interval in 1.25 ms units, see BLE_GAP_CP_LIMITS.*/ |
vcoubard | 1184:1589830dbdb7 | 183 | uint16_t maxConnectionInterval; /**< Maximum Connection Interval in 1.25 ms units, see BLE_GAP_CP_LIMITS.*/ |
vcoubard | 1184:1589830dbdb7 | 184 | uint16_t slaveLatency; /**< Slave Latency in number of connection events, see BLE_GAP_CP_LIMITS.*/ |
vcoubard | 1184:1589830dbdb7 | 185 | uint16_t connectionSupervisionTimeout; /**< Connection Supervision Timeout in 10 ms units, see BLE_GAP_CP_LIMITS.*/ |
vcoubard | 1132:692ddf04fc42 | 186 | } ConnectionParams_t; |
vcoubard | 1132:692ddf04fc42 | 187 | |
vcoubard | 1184:1589830dbdb7 | 188 | /** |
vcoubard | 1184:1589830dbdb7 | 189 | * Enumeration for the possible GAP roles of a BLE device. |
vcoubard | 1184:1589830dbdb7 | 190 | */ |
vcoubard | 1132:692ddf04fc42 | 191 | enum Role_t { |
vcoubard | 1132:692ddf04fc42 | 192 | PERIPHERAL = 0x1, /**< Peripheral Role. */ |
vcoubard | 1132:692ddf04fc42 | 193 | CENTRAL = 0x2, /**< Central Role. */ |
vcoubard | 1132:692ddf04fc42 | 194 | }; |
vcoubard | 1132:692ddf04fc42 | 195 | |
vcoubard | 1184:1589830dbdb7 | 196 | /** |
vcoubard | 1184:1589830dbdb7 | 197 | * Structure containing data and metadata of a scanned advertising packet. |
vcoubard | 1184:1589830dbdb7 | 198 | */ |
vcoubard | 1132:692ddf04fc42 | 199 | struct AdvertisementCallbackParams_t { |
vcoubard | 1184:1589830dbdb7 | 200 | BLEProtocol::AddressBytes_t peerAddr; /**< The peer's BLE address. */ |
vcoubard | 1184:1589830dbdb7 | 201 | int8_t rssi; /**< The advertisement packet RSSI value. */ |
vcoubard | 1184:1589830dbdb7 | 202 | bool isScanResponse; /**< Whether this packet is the response to a scan request. */ |
vcoubard | 1184:1589830dbdb7 | 203 | GapAdvertisingParams::AdvertisingType_t type; /**< The type of advertisement. */ |
vcoubard | 1184:1589830dbdb7 | 204 | uint8_t advertisingDataLen; /**< Length of the advertisement data. */ |
vcoubard | 1184:1589830dbdb7 | 205 | const uint8_t *advertisingData; /**< Pointer to the advertisement packet's data. */ |
vcoubard | 1132:692ddf04fc42 | 206 | }; |
vcoubard | 1184:1589830dbdb7 | 207 | |
vcoubard | 1184:1589830dbdb7 | 208 | /** |
vcoubard | 1184:1589830dbdb7 | 209 | * Type for the handlers of advertisement callback events. Refer to |
vcoubard | 1184:1589830dbdb7 | 210 | * Gap::startScan(). |
vcoubard | 1184:1589830dbdb7 | 211 | */ |
vcoubard | 1132:692ddf04fc42 | 212 | typedef FunctionPointerWithContext<const AdvertisementCallbackParams_t *> AdvertisementReportCallback_t; |
vcoubard | 1132:692ddf04fc42 | 213 | |
vcoubard | 1184:1589830dbdb7 | 214 | /** |
vcoubard | 1184:1589830dbdb7 | 215 | * Encapsulates the parameters of a connection. This information is passed |
vcoubard | 1184:1589830dbdb7 | 216 | * to the registered handler of connection events. Refer to Gap::onConnection(). |
vcoubard | 1184:1589830dbdb7 | 217 | */ |
vcoubard | 1132:692ddf04fc42 | 218 | struct ConnectionCallbackParams_t { |
vcoubard | 1184:1589830dbdb7 | 219 | Handle_t handle; /**< The ID for this connection */ |
vcoubard | 1184:1589830dbdb7 | 220 | Role_t role; /**< This device's role in the connection */ |
vcoubard | 1184:1589830dbdb7 | 221 | BLEProtocol::AddressType_t peerAddrType; /**< The peer's BLE address type */ |
vcoubard | 1184:1589830dbdb7 | 222 | BLEProtocol::AddressBytes_t peerAddr; /**< The peer's BLE address */ |
vcoubard | 1184:1589830dbdb7 | 223 | BLEProtocol::AddressType_t ownAddrType; /**< This device's BLE address type */ |
vcoubard | 1184:1589830dbdb7 | 224 | BLEProtocol::AddressBytes_t ownAddr; /**< This devices's BLE address */ |
vcoubard | 1184:1589830dbdb7 | 225 | const ConnectionParams_t *connectionParams; /**< The currently configured connection parameters */ |
vcoubard | 1132:692ddf04fc42 | 226 | |
vcoubard | 1184:1589830dbdb7 | 227 | /** |
vcoubard | 1184:1589830dbdb7 | 228 | * Constructor for ConnectionCallbackParams_t. |
vcoubard | 1184:1589830dbdb7 | 229 | * |
vcoubard | 1184:1589830dbdb7 | 230 | * @param[in] handleIn |
vcoubard | 1184:1589830dbdb7 | 231 | * Value for ConnectionCallbackParams_t::handle |
vcoubard | 1184:1589830dbdb7 | 232 | * @param[in] roleIn |
vcoubard | 1184:1589830dbdb7 | 233 | * Value for ConnectionCallbackParams_t::role |
vcoubard | 1184:1589830dbdb7 | 234 | * @param[in] peerAddrTypeIn |
vcoubard | 1184:1589830dbdb7 | 235 | * Value for ConnectionCallbackParams_t::peerAddrType |
vcoubard | 1184:1589830dbdb7 | 236 | * @param[in] peerAddrIn |
vcoubard | 1184:1589830dbdb7 | 237 | * Value for ConnectionCallbackParams_t::peerAddr |
vcoubard | 1184:1589830dbdb7 | 238 | * @param[in] ownAddrTypeIn |
vcoubard | 1184:1589830dbdb7 | 239 | * Value for ConnectionCallbackParams_t::ownAddrType |
vcoubard | 1184:1589830dbdb7 | 240 | * @param[in] ownAddrIn |
vcoubard | 1184:1589830dbdb7 | 241 | * Value for ConnectionCallbackParams_t::ownAddr |
vcoubard | 1184:1589830dbdb7 | 242 | * @param[in] connectionParamsIn |
vcoubard | 1184:1589830dbdb7 | 243 | * Value for ConnectionCallbackParams_t::connectionParams |
vcoubard | 1184:1589830dbdb7 | 244 | */ |
vcoubard | 1136:22aada733dbd | 245 | ConnectionCallbackParams_t(Handle_t handleIn, |
vcoubard | 1136:22aada733dbd | 246 | Role_t roleIn, |
vcoubard | 1136:22aada733dbd | 247 | BLEProtocol::AddressType_t peerAddrTypeIn, |
vcoubard | 1136:22aada733dbd | 248 | const uint8_t *peerAddrIn, |
vcoubard | 1136:22aada733dbd | 249 | BLEProtocol::AddressType_t ownAddrTypeIn, |
vcoubard | 1136:22aada733dbd | 250 | const uint8_t *ownAddrIn, |
vcoubard | 1136:22aada733dbd | 251 | const ConnectionParams_t *connectionParamsIn) : |
vcoubard | 1132:692ddf04fc42 | 252 | handle(handleIn), |
vcoubard | 1132:692ddf04fc42 | 253 | role(roleIn), |
vcoubard | 1132:692ddf04fc42 | 254 | peerAddrType(peerAddrTypeIn), |
vcoubard | 1132:692ddf04fc42 | 255 | peerAddr(), |
vcoubard | 1132:692ddf04fc42 | 256 | ownAddrType(ownAddrTypeIn), |
vcoubard | 1132:692ddf04fc42 | 257 | ownAddr(), |
vcoubard | 1132:692ddf04fc42 | 258 | connectionParams(connectionParamsIn) { |
vcoubard | 1132:692ddf04fc42 | 259 | memcpy(peerAddr, peerAddrIn, ADDR_LEN); |
vcoubard | 1132:692ddf04fc42 | 260 | memcpy(ownAddr, ownAddrIn, ADDR_LEN); |
vcoubard | 1132:692ddf04fc42 | 261 | } |
vcoubard | 1132:692ddf04fc42 | 262 | }; |
vcoubard | 1132:692ddf04fc42 | 263 | |
vcoubard | 1184:1589830dbdb7 | 264 | /** |
vcoubard | 1184:1589830dbdb7 | 265 | * Structure that encapsulates information about a disconnection event. |
vcoubard | 1184:1589830dbdb7 | 266 | * Refer to Gap::onDisconnection(). |
vcoubard | 1184:1589830dbdb7 | 267 | */ |
vcoubard | 1132:692ddf04fc42 | 268 | struct DisconnectionCallbackParams_t { |
vcoubard | 1184:1589830dbdb7 | 269 | Handle_t handle; /**< The ID of the connection that caused the disconnection event */ |
vcoubard | 1184:1589830dbdb7 | 270 | DisconnectionReason_t reason; /**< The reason of the disconnection event */ |
vcoubard | 1132:692ddf04fc42 | 271 | |
vcoubard | 1184:1589830dbdb7 | 272 | /** |
vcoubard | 1184:1589830dbdb7 | 273 | * Constructor for DisconnectionCallbackParams_t. |
vcoubard | 1184:1589830dbdb7 | 274 | * |
vcoubard | 1184:1589830dbdb7 | 275 | * @param[in] handleIn |
vcoubard | 1184:1589830dbdb7 | 276 | * Value for DisconnectionCallbackParams_t::handle. |
vcoubard | 1184:1589830dbdb7 | 277 | * @param[in] reasonIn |
vcoubard | 1184:1589830dbdb7 | 278 | * Value for DisconnectionCallbackParams_t::reason. |
vcoubard | 1184:1589830dbdb7 | 279 | */ |
vcoubard | 1132:692ddf04fc42 | 280 | DisconnectionCallbackParams_t(Handle_t handleIn, |
vcoubard | 1132:692ddf04fc42 | 281 | DisconnectionReason_t reasonIn) : |
vcoubard | 1132:692ddf04fc42 | 282 | handle(handleIn), |
vcoubard | 1132:692ddf04fc42 | 283 | reason(reasonIn) |
vcoubard | 1132:692ddf04fc42 | 284 | {} |
vcoubard | 1132:692ddf04fc42 | 285 | }; |
vcoubard | 1132:692ddf04fc42 | 286 | |
vcoubard | 1132:692ddf04fc42 | 287 | static const uint16_t UNIT_1_25_MS = 1250; /**< Number of microseconds in 1.25 milliseconds. */ |
vcoubard | 1184:1589830dbdb7 | 288 | /** |
vcoubard | 1184:1589830dbdb7 | 289 | * Helper function to convert from units of milliseconds to GAP duration |
vcoubard | 1184:1589830dbdb7 | 290 | * units. |
vcoubard | 1184:1589830dbdb7 | 291 | * |
vcoubard | 1184:1589830dbdb7 | 292 | * @param[in] durationInMillis |
vcoubard | 1184:1589830dbdb7 | 293 | * The duration in milliseconds. |
vcoubard | 1184:1589830dbdb7 | 294 | * |
vcoubard | 1184:1589830dbdb7 | 295 | * @return The duration in GAP duration units. |
vcoubard | 1184:1589830dbdb7 | 296 | */ |
vcoubard | 1132:692ddf04fc42 | 297 | static uint16_t MSEC_TO_GAP_DURATION_UNITS(uint32_t durationInMillis) { |
vcoubard | 1132:692ddf04fc42 | 298 | return (durationInMillis * 1000) / UNIT_1_25_MS; |
vcoubard | 1132:692ddf04fc42 | 299 | } |
vcoubard | 1132:692ddf04fc42 | 300 | |
vcoubard | 1184:1589830dbdb7 | 301 | /** |
vcoubard | 1184:1589830dbdb7 | 302 | * Type for the registered callbacks added to the timeout event callchain. |
vcoubard | 1184:1589830dbdb7 | 303 | * Refer to Gap::onTimeout(). |
vcoubard | 1184:1589830dbdb7 | 304 | */ |
vcoubard | 1132:692ddf04fc42 | 305 | typedef FunctionPointerWithContext<TimeoutSource_t> TimeoutEventCallback_t; |
vcoubard | 1184:1589830dbdb7 | 306 | /** |
vcoubard | 1184:1589830dbdb7 | 307 | * Type for the timeout event callchain. Refer to Gap::onTimeout(). |
vcoubard | 1184:1589830dbdb7 | 308 | */ |
vcoubard | 1132:692ddf04fc42 | 309 | typedef CallChainOfFunctionPointersWithContext<TimeoutSource_t> TimeoutEventCallbackChain_t; |
vcoubard | 1132:692ddf04fc42 | 310 | |
vcoubard | 1184:1589830dbdb7 | 311 | /** |
vcoubard | 1184:1589830dbdb7 | 312 | * Type for the registered callbacks added to the connection event |
vcoubard | 1184:1589830dbdb7 | 313 | * callchain. Refer to Gap::onConnection(). |
vcoubard | 1184:1589830dbdb7 | 314 | */ |
vcoubard | 1132:692ddf04fc42 | 315 | typedef FunctionPointerWithContext<const ConnectionCallbackParams_t *> ConnectionEventCallback_t; |
vcoubard | 1184:1589830dbdb7 | 316 | /** |
vcoubard | 1184:1589830dbdb7 | 317 | * Type for the connection event callchain. Refer to Gap::onConnection(). |
vcoubard | 1184:1589830dbdb7 | 318 | */ |
vcoubard | 1132:692ddf04fc42 | 319 | typedef CallChainOfFunctionPointersWithContext<const ConnectionCallbackParams_t *> ConnectionEventCallbackChain_t; |
vcoubard | 1132:692ddf04fc42 | 320 | |
vcoubard | 1184:1589830dbdb7 | 321 | /** |
vcoubard | 1184:1589830dbdb7 | 322 | * Type for the registered callbacks added to the disconnection event |
vcoubard | 1184:1589830dbdb7 | 323 | * callchain. Refer to Gap::onDisconnetion(). |
vcoubard | 1184:1589830dbdb7 | 324 | */ |
vcoubard | 1132:692ddf04fc42 | 325 | typedef FunctionPointerWithContext<const DisconnectionCallbackParams_t*> DisconnectionEventCallback_t; |
vcoubard | 1184:1589830dbdb7 | 326 | /** |
vcoubard | 1184:1589830dbdb7 | 327 | * Type for the disconnection event callchain. Refer to Gap::onDisconnection(). |
vcoubard | 1184:1589830dbdb7 | 328 | */ |
vcoubard | 1133:6362b7c2fdff | 329 | typedef CallChainOfFunctionPointersWithContext<const DisconnectionCallbackParams_t*> DisconnectionEventCallbackChain_t; |
vcoubard | 1132:692ddf04fc42 | 330 | |
vcoubard | 1184:1589830dbdb7 | 331 | /** |
vcoubard | 1184:1589830dbdb7 | 332 | * Type for the handlers of radio notification callback events. Refer to |
vcoubard | 1184:1589830dbdb7 | 333 | * Gap::onRadioNotification(). |
vcoubard | 1184:1589830dbdb7 | 334 | */ |
vcoubard | 1132:692ddf04fc42 | 335 | typedef FunctionPointerWithContext<bool> RadioNotificationEventCallback_t; |
vcoubard | 1132:692ddf04fc42 | 336 | |
vcoubard | 1184:1589830dbdb7 | 337 | /** |
vcoubard | 1184:1589830dbdb7 | 338 | * Type for the handlers of shutdown callback events. Refer to |
vcoubard | 1184:1589830dbdb7 | 339 | * Gap::onShutdown(). |
vcoubard | 1184:1589830dbdb7 | 340 | */ |
vcoubard | 1136:22aada733dbd | 341 | typedef FunctionPointerWithContext<const Gap *> GapShutdownCallback_t; |
vcoubard | 1184:1589830dbdb7 | 342 | /** |
vcoubard | 1184:1589830dbdb7 | 343 | * Type for the shutdown event callchain. Refer to Gap::onShutdown(). |
vcoubard | 1184:1589830dbdb7 | 344 | */ |
vcoubard | 1136:22aada733dbd | 345 | typedef CallChainOfFunctionPointersWithContext<const Gap *> GapShutdownCallbackChain_t; |
vcoubard | 1136:22aada733dbd | 346 | |
vcoubard | 1132:692ddf04fc42 | 347 | /* |
vcoubard | 1132:692ddf04fc42 | 348 | * The following functions are meant to be overridden in the platform-specific sub-class. |
vcoubard | 1132:692ddf04fc42 | 349 | */ |
vcoubard | 1132:692ddf04fc42 | 350 | public: |
vcoubard | 1132:692ddf04fc42 | 351 | /** |
vcoubard | 1132:692ddf04fc42 | 352 | * Set the BTLE MAC address and type. Please note that the address format is |
vcoubard | 1136:22aada733dbd | 353 | * least significant byte first (LSB). Please refer to BLEProtocol::AddressBytes_t. |
vcoubard | 1132:692ddf04fc42 | 354 | * |
vcoubard | 1184:1589830dbdb7 | 355 | * @param[in] type |
vcoubard | 1184:1589830dbdb7 | 356 | * The type of the BLE address to set. |
vcoubard | 1184:1589830dbdb7 | 357 | * @param[in] address |
vcoubard | 1184:1589830dbdb7 | 358 | * The BLE address to set. |
vcoubard | 1184:1589830dbdb7 | 359 | * |
vcoubard | 1132:692ddf04fc42 | 360 | * @return BLE_ERROR_NONE on success. |
vcoubard | 1132:692ddf04fc42 | 361 | */ |
vcoubard | 1136:22aada733dbd | 362 | virtual ble_error_t setAddress(BLEProtocol::AddressType_t type, const BLEProtocol::AddressBytes_t address) { |
vcoubard | 1132:692ddf04fc42 | 363 | /* avoid compiler warnings about unused variables */ |
vcoubard | 1132:692ddf04fc42 | 364 | (void)type; |
vcoubard | 1132:692ddf04fc42 | 365 | (void)address; |
vcoubard | 1132:692ddf04fc42 | 366 | |
vcoubard | 1132:692ddf04fc42 | 367 | return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */ |
vcoubard | 1132:692ddf04fc42 | 368 | } |
vcoubard | 1132:692ddf04fc42 | 369 | |
vcoubard | 1132:692ddf04fc42 | 370 | /** |
vcoubard | 1132:692ddf04fc42 | 371 | * Fetch the BTLE MAC address and type. |
vcoubard | 1132:692ddf04fc42 | 372 | * |
vcoubard | 1184:1589830dbdb7 | 373 | * @param[out] typeP |
vcoubard | 1184:1589830dbdb7 | 374 | * The current BLE address type. |
vcoubard | 1184:1589830dbdb7 | 375 | * @param[out] address |
vcoubard | 1184:1589830dbdb7 | 376 | * The current BLE address. |
vcoubard | 1184:1589830dbdb7 | 377 | * |
vcoubard | 1132:692ddf04fc42 | 378 | * @return BLE_ERROR_NONE on success. |
vcoubard | 1132:692ddf04fc42 | 379 | */ |
vcoubard | 1136:22aada733dbd | 380 | virtual ble_error_t getAddress(BLEProtocol::AddressType_t *typeP, BLEProtocol::AddressBytes_t address) { |
vcoubard | 1132:692ddf04fc42 | 381 | /* Avoid compiler warnings about unused variables. */ |
vcoubard | 1132:692ddf04fc42 | 382 | (void)typeP; |
vcoubard | 1132:692ddf04fc42 | 383 | (void)address; |
vcoubard | 1132:692ddf04fc42 | 384 | |
vcoubard | 1132:692ddf04fc42 | 385 | return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */ |
vcoubard | 1132:692ddf04fc42 | 386 | } |
vcoubard | 1132:692ddf04fc42 | 387 | |
vcoubard | 1132:692ddf04fc42 | 388 | /** |
vcoubard | 1184:1589830dbdb7 | 389 | * Get the minimum advertising interval in milliseconds for connectable |
vcoubard | 1184:1589830dbdb7 | 390 | * undirected and connectable directed event types supported by the |
vcoubard | 1184:1589830dbdb7 | 391 | * underlying BLE stack. |
vcoubard | 1184:1589830dbdb7 | 392 | * |
vcoubard | 1135:d540a48f650d | 393 | * @return Minimum Advertising interval in milliseconds for connectable |
vcoubard | 1184:1589830dbdb7 | 394 | * undirected and connectable directed event types. |
vcoubard | 1132:692ddf04fc42 | 395 | */ |
vcoubard | 1132:692ddf04fc42 | 396 | virtual uint16_t getMinAdvertisingInterval(void) const { |
vcoubard | 1132:692ddf04fc42 | 397 | return 0; /* Requesting action from porter(s): override this API if this capability is supported. */ |
vcoubard | 1132:692ddf04fc42 | 398 | } |
vcoubard | 1132:692ddf04fc42 | 399 | |
vcoubard | 1132:692ddf04fc42 | 400 | /** |
vcoubard | 1184:1589830dbdb7 | 401 | * Get the minimum advertising interval in milliseconds for scannable |
vcoubard | 1184:1589830dbdb7 | 402 | * undirected and non-connectable undirected even types supported by the |
vcoubard | 1184:1589830dbdb7 | 403 | * underlying BLE stack. |
vcoubard | 1184:1589830dbdb7 | 404 | * |
vcoubard | 1135:d540a48f650d | 405 | * @return Minimum Advertising interval in milliseconds for scannable |
vcoubard | 1184:1589830dbdb7 | 406 | * undirected and non-connectable undirected event types. |
vcoubard | 1132:692ddf04fc42 | 407 | */ |
vcoubard | 1132:692ddf04fc42 | 408 | virtual uint16_t getMinNonConnectableAdvertisingInterval(void) const { |
vcoubard | 1132:692ddf04fc42 | 409 | return 0; /* Requesting action from porter(s): override this API if this capability is supported. */ |
vcoubard | 1132:692ddf04fc42 | 410 | } |
vcoubard | 1132:692ddf04fc42 | 411 | |
vcoubard | 1132:692ddf04fc42 | 412 | /** |
vcoubard | 1184:1589830dbdb7 | 413 | * Get the maximum advertising interval in milliseconds for all event types |
vcoubard | 1184:1589830dbdb7 | 414 | * supported by the underlying BLE stack. |
vcoubard | 1184:1589830dbdb7 | 415 | * |
vcoubard | 1132:692ddf04fc42 | 416 | * @return Maximum Advertising interval in milliseconds. |
vcoubard | 1132:692ddf04fc42 | 417 | */ |
vcoubard | 1132:692ddf04fc42 | 418 | virtual uint16_t getMaxAdvertisingInterval(void) const { |
vcoubard | 1132:692ddf04fc42 | 419 | return 0xFFFF; /* Requesting action from porter(s): override this API if this capability is supported. */ |
vcoubard | 1132:692ddf04fc42 | 420 | } |
vcoubard | 1132:692ddf04fc42 | 421 | |
vcoubard | 1184:1589830dbdb7 | 422 | /** |
vcoubard | 1184:1589830dbdb7 | 423 | * Stop advertising. The current advertising parameters remain in effect. |
vcoubard | 1184:1589830dbdb7 | 424 | * |
vcoubard | 1184:1589830dbdb7 | 425 | * @retval BLE_ERROR_NONE if successfully stopped advertising procedure. |
vcoubard | 1184:1589830dbdb7 | 426 | */ |
vcoubard | 1132:692ddf04fc42 | 427 | virtual ble_error_t stopAdvertising(void) { |
vcoubard | 1132:692ddf04fc42 | 428 | return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */ |
vcoubard | 1132:692ddf04fc42 | 429 | } |
vcoubard | 1132:692ddf04fc42 | 430 | |
vcoubard | 1132:692ddf04fc42 | 431 | /** |
vcoubard | 1132:692ddf04fc42 | 432 | * Stop scanning. The current scanning parameters remain in effect. |
vcoubard | 1132:692ddf04fc42 | 433 | * |
vcoubard | 1132:692ddf04fc42 | 434 | * @retval BLE_ERROR_NONE if successfully stopped scanning procedure. |
vcoubard | 1132:692ddf04fc42 | 435 | */ |
vcoubard | 1132:692ddf04fc42 | 436 | virtual ble_error_t stopScan() { |
vcoubard | 1132:692ddf04fc42 | 437 | return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */ |
vcoubard | 1132:692ddf04fc42 | 438 | } |
vcoubard | 1132:692ddf04fc42 | 439 | |
vcoubard | 1132:692ddf04fc42 | 440 | /** |
vcoubard | 1132:692ddf04fc42 | 441 | * Create a connection (GAP Link Establishment). |
vcoubard | 1132:692ddf04fc42 | 442 | * |
vcoubard | 1184:1589830dbdb7 | 443 | * @param[in] peerAddr |
vcoubard | 1184:1589830dbdb7 | 444 | * 48-bit address, LSB format. |
vcoubard | 1184:1589830dbdb7 | 445 | * @param[in] peerAddrType |
vcoubard | 1184:1589830dbdb7 | 446 | * Address type of the peer. |
vcoubard | 1184:1589830dbdb7 | 447 | * @param[in] connectionParams |
vcoubard | 1184:1589830dbdb7 | 448 | * Connection parameters. |
vcoubard | 1184:1589830dbdb7 | 449 | * @param[in] scanParams |
vcoubard | 1184:1589830dbdb7 | 450 | * Paramters to be used while scanning for the peer. |
vcoubard | 1184:1589830dbdb7 | 451 | * |
vcoubard | 1132:692ddf04fc42 | 452 | * @return BLE_ERROR_NONE if connection establishment procedure is started |
vcoubard | 1184:1589830dbdb7 | 453 | * successfully. The connectionCallChain (if set) will be invoked upon |
vcoubard | 1184:1589830dbdb7 | 454 | * a connection event. |
vcoubard | 1132:692ddf04fc42 | 455 | */ |
vcoubard | 1136:22aada733dbd | 456 | virtual ble_error_t connect(const BLEProtocol::AddressBytes_t peerAddr, |
vcoubard | 1136:22aada733dbd | 457 | BLEProtocol::AddressType_t peerAddrType, |
vcoubard | 1136:22aada733dbd | 458 | const ConnectionParams_t *connectionParams, |
vcoubard | 1136:22aada733dbd | 459 | const GapScanningParams *scanParams) { |
vcoubard | 1132:692ddf04fc42 | 460 | /* Avoid compiler warnings about unused variables. */ |
vcoubard | 1132:692ddf04fc42 | 461 | (void)peerAddr; |
vcoubard | 1132:692ddf04fc42 | 462 | (void)peerAddrType; |
vcoubard | 1132:692ddf04fc42 | 463 | (void)connectionParams; |
vcoubard | 1132:692ddf04fc42 | 464 | (void)scanParams; |
vcoubard | 1132:692ddf04fc42 | 465 | |
vcoubard | 1132:692ddf04fc42 | 466 | return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */ |
vcoubard | 1132:692ddf04fc42 | 467 | } |
vcoubard | 1132:692ddf04fc42 | 468 | |
vcoubard | 1132:692ddf04fc42 | 469 | /** |
vcoubard | 1136:22aada733dbd | 470 | * Create a connection (GAP Link Establishment). |
vcoubard | 1136:22aada733dbd | 471 | * |
vcoubard | 1184:1589830dbdb7 | 472 | * @deprecated This funtion overloads Gap::connect(const BLEProtocol::Address_t peerAddr, |
vcoubard | 1184:1589830dbdb7 | 473 | * BLEProtocol::AddressType_t peerAddrType, |
vcoubard | 1184:1589830dbdb7 | 474 | * const ConnectionParams_t *connectionParams, |
vcoubard | 1184:1589830dbdb7 | 475 | * const GapScanningParams *scanParams) |
vcoubard | 1184:1589830dbdb7 | 476 | * to maintain backward compatibility for change from Gap::AddressType_t to |
vcoubard | 1184:1589830dbdb7 | 477 | * BLEProtocol::AddressType_t. |
vcoubard | 1136:22aada733dbd | 478 | */ |
vcoubard | 1136:22aada733dbd | 479 | ble_error_t connect(const BLEProtocol::AddressBytes_t peerAddr, |
vcoubard | 1136:22aada733dbd | 480 | DeprecatedAddressType_t peerAddrType, |
vcoubard | 1136:22aada733dbd | 481 | const ConnectionParams_t *connectionParams, |
vcoubard | 1136:22aada733dbd | 482 | const GapScanningParams *scanParams) |
vcoubard | 1136:22aada733dbd | 483 | __deprecated_message("Gap::DeprecatedAddressType_t is deprecated, use BLEProtocol::AddressType_t instead") { |
vcoubard | 1136:22aada733dbd | 484 | return connect(peerAddr, (BLEProtocol::AddressType_t) peerAddrType, connectionParams, scanParams); |
vcoubard | 1136:22aada733dbd | 485 | } |
vcoubard | 1136:22aada733dbd | 486 | |
vcoubard | 1136:22aada733dbd | 487 | /** |
vcoubard | 1132:692ddf04fc42 | 488 | * This call initiates the disconnection procedure, and its completion will |
vcoubard | 1132:692ddf04fc42 | 489 | * be communicated to the application with an invocation of the |
vcoubard | 1132:692ddf04fc42 | 490 | * disconnectionCallback. |
vcoubard | 1132:692ddf04fc42 | 491 | * |
vcoubard | 1184:1589830dbdb7 | 492 | * @param[in] reason |
vcoubard | 1184:1589830dbdb7 | 493 | * The reason for disconnection; to be sent back to the peer. |
vcoubard | 1184:1589830dbdb7 | 494 | * @param[in] connectionHandle |
vcoubard | 1184:1589830dbdb7 | 495 | * The handle of the connection to disconnect from. |
vcoubard | 1184:1589830dbdb7 | 496 | * |
vcoubard | 1184:1589830dbdb7 | 497 | * @return BLE_ERROR_NONE if disconnection was successful. |
vcoubard | 1132:692ddf04fc42 | 498 | */ |
vcoubard | 1132:692ddf04fc42 | 499 | virtual ble_error_t disconnect(Handle_t connectionHandle, DisconnectionReason_t reason) { |
vcoubard | 1132:692ddf04fc42 | 500 | /* avoid compiler warnings about unused variables */ |
vcoubard | 1132:692ddf04fc42 | 501 | (void)connectionHandle; |
vcoubard | 1132:692ddf04fc42 | 502 | (void)reason; |
vcoubard | 1132:692ddf04fc42 | 503 | |
vcoubard | 1132:692ddf04fc42 | 504 | return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */ |
vcoubard | 1132:692ddf04fc42 | 505 | } |
vcoubard | 1132:692ddf04fc42 | 506 | |
vcoubard | 1132:692ddf04fc42 | 507 | /** |
vcoubard | 1132:692ddf04fc42 | 508 | * This call initiates the disconnection procedure, and its completion will |
vcoubard | 1132:692ddf04fc42 | 509 | * be communicated to the application with an invocation of the |
vcoubard | 1132:692ddf04fc42 | 510 | * disconnectionCallback. |
vcoubard | 1132:692ddf04fc42 | 511 | * |
vcoubard | 1184:1589830dbdb7 | 512 | * @param[in] reason |
vcoubard | 1184:1589830dbdb7 | 513 | * The reason for disconnection; to be sent back to the peer. |
vcoubard | 1184:1589830dbdb7 | 514 | * |
vcoubard | 1184:1589830dbdb7 | 515 | * @return BLE_ERROR_NONE if disconnection was successful. |
vcoubard | 1132:692ddf04fc42 | 516 | * |
vcoubard | 1184:1589830dbdb7 | 517 | * @deprecated This version of disconnect() doesn't take a connection handle. It |
vcoubard | 1184:1589830dbdb7 | 518 | * works reliably only for stacks that are limited to a single |
vcoubard | 1184:1589830dbdb7 | 519 | * connection. Use instead Gap::disconnect(Handle_t connectionHandle, |
vcoubard | 1184:1589830dbdb7 | 520 | * DisconnectionReason_t reason) instead. |
vcoubard | 1132:692ddf04fc42 | 521 | */ |
vcoubard | 1132:692ddf04fc42 | 522 | virtual ble_error_t disconnect(DisconnectionReason_t reason) { |
vcoubard | 1132:692ddf04fc42 | 523 | /* Avoid compiler warnings about unused variables. */ |
vcoubard | 1132:692ddf04fc42 | 524 | (void)reason; |
vcoubard | 1132:692ddf04fc42 | 525 | |
vcoubard | 1132:692ddf04fc42 | 526 | return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */ |
vcoubard | 1132:692ddf04fc42 | 527 | } |
vcoubard | 1132:692ddf04fc42 | 528 | |
vcoubard | 1132:692ddf04fc42 | 529 | /** |
vcoubard | 1132:692ddf04fc42 | 530 | * Get the GAP peripheral preferred connection parameters. These are the |
vcoubard | 1132:692ddf04fc42 | 531 | * defaults that the peripheral would like to have in a connection. The |
vcoubard | 1132:692ddf04fc42 | 532 | * choice of the connection parameters is eventually up to the central. |
vcoubard | 1132:692ddf04fc42 | 533 | * |
vcoubard | 1132:692ddf04fc42 | 534 | * @param[out] params |
vcoubard | 1132:692ddf04fc42 | 535 | * The structure where the parameters will be stored. Memory |
vcoubard | 1132:692ddf04fc42 | 536 | * for this is owned by the caller. |
vcoubard | 1132:692ddf04fc42 | 537 | * |
vcoubard | 1132:692ddf04fc42 | 538 | * @return BLE_ERROR_NONE if the parameters were successfully filled into |
vcoubard | 1184:1589830dbdb7 | 539 | * the given structure pointed to by params. |
vcoubard | 1132:692ddf04fc42 | 540 | */ |
vcoubard | 1132:692ddf04fc42 | 541 | virtual ble_error_t getPreferredConnectionParams(ConnectionParams_t *params) { |
vcoubard | 1132:692ddf04fc42 | 542 | /* Avoid compiler warnings about unused variables. */ |
vcoubard | 1132:692ddf04fc42 | 543 | (void)params; |
vcoubard | 1132:692ddf04fc42 | 544 | |
vcoubard | 1132:692ddf04fc42 | 545 | return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */ |
vcoubard | 1132:692ddf04fc42 | 546 | } |
vcoubard | 1132:692ddf04fc42 | 547 | |
vcoubard | 1132:692ddf04fc42 | 548 | /** |
vcoubard | 1132:692ddf04fc42 | 549 | * Set the GAP peripheral preferred connection parameters. These are the |
vcoubard | 1132:692ddf04fc42 | 550 | * defaults that the peripheral would like to have in a connection. The |
vcoubard | 1132:692ddf04fc42 | 551 | * choice of the connection parameters is eventually up to the central. |
vcoubard | 1132:692ddf04fc42 | 552 | * |
vcoubard | 1132:692ddf04fc42 | 553 | * @param[in] params |
vcoubard | 1132:692ddf04fc42 | 554 | * The structure containing the desired parameters. |
vcoubard | 1184:1589830dbdb7 | 555 | * |
vcoubard | 1184:1589830dbdb7 | 556 | * @return BLE_ERROR_NONE if the preferred connection params were set |
vcoubard | 1184:1589830dbdb7 | 557 | * correctly. |
vcoubard | 1132:692ddf04fc42 | 558 | */ |
vcoubard | 1132:692ddf04fc42 | 559 | virtual ble_error_t setPreferredConnectionParams(const ConnectionParams_t *params) { |
vcoubard | 1132:692ddf04fc42 | 560 | /* Avoid compiler warnings about unused variables. */ |
vcoubard | 1132:692ddf04fc42 | 561 | (void)params; |
vcoubard | 1132:692ddf04fc42 | 562 | |
vcoubard | 1132:692ddf04fc42 | 563 | return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */ |
vcoubard | 1132:692ddf04fc42 | 564 | } |
vcoubard | 1132:692ddf04fc42 | 565 | |
vcoubard | 1132:692ddf04fc42 | 566 | /** |
vcoubard | 1184:1589830dbdb7 | 567 | * Update connection parameters. In the central role this will initiate a |
vcoubard | 1184:1589830dbdb7 | 568 | * Link Layer connection parameter update procedure. In the peripheral role, |
vcoubard | 1184:1589830dbdb7 | 569 | * this will send the corresponding L2CAP request and wait for the central |
vcoubard | 1184:1589830dbdb7 | 570 | * to perform the procedure. |
vcoubard | 1132:692ddf04fc42 | 571 | * |
vcoubard | 1132:692ddf04fc42 | 572 | * @param[in] handle |
vcoubard | 1132:692ddf04fc42 | 573 | * Connection Handle. |
vcoubard | 1132:692ddf04fc42 | 574 | * @param[in] params |
vcoubard | 1132:692ddf04fc42 | 575 | * Pointer to desired connection parameters. If NULL is provided on a peripheral role, |
vcoubard | 1132:692ddf04fc42 | 576 | * the parameters in the PPCP characteristic of the GAP service will be used instead. |
vcoubard | 1184:1589830dbdb7 | 577 | * |
vcoubard | 1184:1589830dbdb7 | 578 | * @return BLE_ERROR_NONE if the connection parameters were updated correctly. |
vcoubard | 1132:692ddf04fc42 | 579 | */ |
vcoubard | 1132:692ddf04fc42 | 580 | virtual ble_error_t updateConnectionParams(Handle_t handle, const ConnectionParams_t *params) { |
vcoubard | 1132:692ddf04fc42 | 581 | /* avoid compiler warnings about unused variables */ |
vcoubard | 1132:692ddf04fc42 | 582 | (void)handle; |
vcoubard | 1132:692ddf04fc42 | 583 | (void)params; |
vcoubard | 1132:692ddf04fc42 | 584 | |
vcoubard | 1132:692ddf04fc42 | 585 | return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */ |
vcoubard | 1132:692ddf04fc42 | 586 | } |
vcoubard | 1132:692ddf04fc42 | 587 | |
vcoubard | 1132:692ddf04fc42 | 588 | /** |
vcoubard | 1132:692ddf04fc42 | 589 | * Set the device name characteristic in the GAP service. |
vcoubard | 1184:1589830dbdb7 | 590 | * |
vcoubard | 1132:692ddf04fc42 | 591 | * @param[in] deviceName |
vcoubard | 1132:692ddf04fc42 | 592 | * The new value for the device-name. This is a UTF-8 encoded, <b>NULL-terminated</b> string. |
vcoubard | 1184:1589830dbdb7 | 593 | * |
vcoubard | 1184:1589830dbdb7 | 594 | * @return BLE_ERROR_NONE if the device name was set correctly. |
vcoubard | 1132:692ddf04fc42 | 595 | */ |
vcoubard | 1132:692ddf04fc42 | 596 | virtual ble_error_t setDeviceName(const uint8_t *deviceName) { |
vcoubard | 1132:692ddf04fc42 | 597 | /* Avoid compiler warnings about unused variables. */ |
vcoubard | 1132:692ddf04fc42 | 598 | (void)deviceName; |
vcoubard | 1132:692ddf04fc42 | 599 | |
vcoubard | 1132:692ddf04fc42 | 600 | return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */ |
vcoubard | 1132:692ddf04fc42 | 601 | } |
vcoubard | 1132:692ddf04fc42 | 602 | |
vcoubard | 1132:692ddf04fc42 | 603 | /** |
vcoubard | 1132:692ddf04fc42 | 604 | * Get the value of the device name characteristic in the GAP service. |
vcoubard | 1184:1589830dbdb7 | 605 | * |
vcoubard | 1132:692ddf04fc42 | 606 | * @param[out] deviceName |
vcoubard | 1132:692ddf04fc42 | 607 | * Pointer to an empty buffer where the UTF-8 *non NULL- |
vcoubard | 1132:692ddf04fc42 | 608 | * terminated* string will be placed. Set this |
vcoubard | 1132:692ddf04fc42 | 609 | * value to NULL in order to obtain the deviceName-length |
vcoubard | 1132:692ddf04fc42 | 610 | * from the 'length' parameter. |
vcoubard | 1132:692ddf04fc42 | 611 | * |
vcoubard | 1184:1589830dbdb7 | 612 | * @param[in,out] lengthP |
vcoubard | 1132:692ddf04fc42 | 613 | * (on input) Length of the buffer pointed to by deviceName; |
vcoubard | 1132:692ddf04fc42 | 614 | * (on output) the complete device name length (without the |
vcoubard | 1132:692ddf04fc42 | 615 | * null terminator). |
vcoubard | 1132:692ddf04fc42 | 616 | * |
vcoubard | 1184:1589830dbdb7 | 617 | * @return BLE_ERROR_NONE if the device name was fetched correctly from the |
vcoubard | 1184:1589830dbdb7 | 618 | * underlying BLE stack. |
vcoubard | 1184:1589830dbdb7 | 619 | * |
vcoubard | 1132:692ddf04fc42 | 620 | * @note If the device name is longer than the size of the supplied buffer, |
vcoubard | 1184:1589830dbdb7 | 621 | * length will return the complete device name length, and not the |
vcoubard | 1184:1589830dbdb7 | 622 | * number of bytes actually returned in deviceName. The application may |
vcoubard | 1184:1589830dbdb7 | 623 | * use this information to retry with a suitable buffer size. |
vcoubard | 1132:692ddf04fc42 | 624 | */ |
vcoubard | 1132:692ddf04fc42 | 625 | virtual ble_error_t getDeviceName(uint8_t *deviceName, unsigned *lengthP) { |
vcoubard | 1132:692ddf04fc42 | 626 | /* avoid compiler warnings about unused variables */ |
vcoubard | 1132:692ddf04fc42 | 627 | (void)deviceName; |
vcoubard | 1132:692ddf04fc42 | 628 | (void)lengthP; |
vcoubard | 1132:692ddf04fc42 | 629 | |
vcoubard | 1132:692ddf04fc42 | 630 | return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */ |
vcoubard | 1132:692ddf04fc42 | 631 | } |
vcoubard | 1132:692ddf04fc42 | 632 | |
vcoubard | 1132:692ddf04fc42 | 633 | /** |
vcoubard | 1132:692ddf04fc42 | 634 | * Set the appearance characteristic in the GAP service. |
vcoubard | 1184:1589830dbdb7 | 635 | * |
vcoubard | 1132:692ddf04fc42 | 636 | * @param[in] appearance |
vcoubard | 1132:692ddf04fc42 | 637 | * The new value for the device-appearance. |
vcoubard | 1184:1589830dbdb7 | 638 | * |
vcoubard | 1184:1589830dbdb7 | 639 | * @return BLE_ERROR_NONE if the new appearance was set correctly. |
vcoubard | 1132:692ddf04fc42 | 640 | */ |
vcoubard | 1132:692ddf04fc42 | 641 | virtual ble_error_t setAppearance(GapAdvertisingData::Appearance appearance) { |
vcoubard | 1132:692ddf04fc42 | 642 | /* Avoid compiler warnings about unused variables. */ |
vcoubard | 1132:692ddf04fc42 | 643 | (void)appearance; |
vcoubard | 1132:692ddf04fc42 | 644 | |
vcoubard | 1132:692ddf04fc42 | 645 | return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */ |
vcoubard | 1132:692ddf04fc42 | 646 | } |
vcoubard | 1132:692ddf04fc42 | 647 | |
vcoubard | 1132:692ddf04fc42 | 648 | /** |
vcoubard | 1132:692ddf04fc42 | 649 | * Get the appearance characteristic in the GAP service. |
vcoubard | 1184:1589830dbdb7 | 650 | * |
vcoubard | 1132:692ddf04fc42 | 651 | * @param[out] appearance |
vcoubard | 1184:1589830dbdb7 | 652 | * The current device-appearance value. |
vcoubard | 1184:1589830dbdb7 | 653 | * |
vcoubard | 1184:1589830dbdb7 | 654 | * @return BLE_ERROR_NONE if the device-appearance was fetched correctly |
vcoubard | 1184:1589830dbdb7 | 655 | * from the underlying BLE stack. |
vcoubard | 1132:692ddf04fc42 | 656 | */ |
vcoubard | 1132:692ddf04fc42 | 657 | virtual ble_error_t getAppearance(GapAdvertisingData::Appearance *appearanceP) { |
vcoubard | 1132:692ddf04fc42 | 658 | /* Avoid compiler warnings about unused variables. */ |
vcoubard | 1132:692ddf04fc42 | 659 | (void)appearanceP; |
vcoubard | 1132:692ddf04fc42 | 660 | |
vcoubard | 1132:692ddf04fc42 | 661 | return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */ |
vcoubard | 1132:692ddf04fc42 | 662 | } |
vcoubard | 1132:692ddf04fc42 | 663 | |
vcoubard | 1132:692ddf04fc42 | 664 | /** |
vcoubard | 1132:692ddf04fc42 | 665 | * Set the radio's transmit power. |
vcoubard | 1184:1589830dbdb7 | 666 | * |
vcoubard | 1184:1589830dbdb7 | 667 | * @param[in] txPower |
vcoubard | 1184:1589830dbdb7 | 668 | * Radio's transmit power in dBm. |
vcoubard | 1184:1589830dbdb7 | 669 | * |
vcoubard | 1184:1589830dbdb7 | 670 | * @return BLE_ERROR_NONE if the new radio's transmit power was set |
vcoubard | 1184:1589830dbdb7 | 671 | * correctly. |
vcoubard | 1132:692ddf04fc42 | 672 | */ |
vcoubard | 1132:692ddf04fc42 | 673 | virtual ble_error_t setTxPower(int8_t txPower) { |
vcoubard | 1132:692ddf04fc42 | 674 | /* Avoid compiler warnings about unused variables. */ |
vcoubard | 1132:692ddf04fc42 | 675 | (void)txPower; |
vcoubard | 1132:692ddf04fc42 | 676 | |
vcoubard | 1132:692ddf04fc42 | 677 | return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */ |
vcoubard | 1132:692ddf04fc42 | 678 | } |
vcoubard | 1132:692ddf04fc42 | 679 | |
vcoubard | 1132:692ddf04fc42 | 680 | /** |
vcoubard | 1132:692ddf04fc42 | 681 | * Query the underlying stack for permitted arguments for setTxPower(). |
vcoubard | 1132:692ddf04fc42 | 682 | * |
vcoubard | 1132:692ddf04fc42 | 683 | * @param[out] valueArrayPP |
vcoubard | 1132:692ddf04fc42 | 684 | * Out parameter to receive the immutable array of Tx values. |
vcoubard | 1132:692ddf04fc42 | 685 | * @param[out] countP |
vcoubard | 1132:692ddf04fc42 | 686 | * Out parameter to receive the array's size. |
vcoubard | 1132:692ddf04fc42 | 687 | */ |
vcoubard | 1132:692ddf04fc42 | 688 | virtual void getPermittedTxPowerValues(const int8_t **valueArrayPP, size_t *countP) { |
vcoubard | 1132:692ddf04fc42 | 689 | /* Avoid compiler warnings about unused variables. */ |
vcoubard | 1132:692ddf04fc42 | 690 | (void)valueArrayPP; |
vcoubard | 1132:692ddf04fc42 | 691 | (void)countP; |
vcoubard | 1132:692ddf04fc42 | 692 | |
vcoubard | 1132:692ddf04fc42 | 693 | *countP = 0; /* Requesting action from porter(s): override this API if this capability is supported. */ |
vcoubard | 1132:692ddf04fc42 | 694 | } |
vcoubard | 1132:692ddf04fc42 | 695 | |
vcoubard | 1136:22aada733dbd | 696 | /** |
vcoubard | 1184:1589830dbdb7 | 697 | * Get the maximum size of the whitelist. |
vcoubard | 1184:1589830dbdb7 | 698 | * |
vcoubard | 1136:22aada733dbd | 699 | * @return Maximum size of the whitelist. |
vcoubard | 1136:22aada733dbd | 700 | * |
vcoubard | 1184:1589830dbdb7 | 701 | * @note If using mbed OS the size of the whitelist can be configured by |
vcoubard | 1184:1589830dbdb7 | 702 | * setting the YOTTA_CFG_WHITELIST_MAX_SIZE macro in your yotta |
vcoubard | 1184:1589830dbdb7 | 703 | * config file. |
vcoubard | 1184:1589830dbdb7 | 704 | * |
vcoubard | 1136:22aada733dbd | 705 | * @experimental |
vcoubard | 1136:22aada733dbd | 706 | */ |
vcoubard | 1136:22aada733dbd | 707 | virtual uint8_t getMaxWhitelistSize(void) const |
vcoubard | 1136:22aada733dbd | 708 | { |
vcoubard | 1136:22aada733dbd | 709 | return 0; |
vcoubard | 1136:22aada733dbd | 710 | } |
vcoubard | 1136:22aada733dbd | 711 | |
vcoubard | 1136:22aada733dbd | 712 | /** |
vcoubard | 1136:22aada733dbd | 713 | * Get the internal whitelist to be used by the Link Layer when scanning, |
vcoubard | 1136:22aada733dbd | 714 | * advertising or initiating a connection depending on the filter policies. |
vcoubard | 1136:22aada733dbd | 715 | * |
vcoubard | 1184:1589830dbdb7 | 716 | * @param[in,out] whitelist |
vcoubard | 1136:22aada733dbd | 717 | * (on input) whitelist.capacity contains the maximum number |
vcoubard | 1136:22aada733dbd | 718 | * of addresses to be returned. |
vcoubard | 1136:22aada733dbd | 719 | * (on output) The populated whitelist with copies of the |
vcoubard | 1136:22aada733dbd | 720 | * addresses in the implementation's whitelist. |
vcoubard | 1136:22aada733dbd | 721 | * |
vcoubard | 1136:22aada733dbd | 722 | * @return BLE_ERROR_NONE if the implementation's whitelist was successfully |
vcoubard | 1136:22aada733dbd | 723 | * copied into the supplied reference. |
vcoubard | 1136:22aada733dbd | 724 | * |
vcoubard | 1136:22aada733dbd | 725 | * @experimental |
vcoubard | 1136:22aada733dbd | 726 | */ |
vcoubard | 1136:22aada733dbd | 727 | virtual ble_error_t getWhitelist(Whitelist_t &whitelist) const |
vcoubard | 1136:22aada733dbd | 728 | { |
vcoubard | 1136:22aada733dbd | 729 | (void) whitelist; |
vcoubard | 1136:22aada733dbd | 730 | return BLE_ERROR_NOT_IMPLEMENTED; |
vcoubard | 1136:22aada733dbd | 731 | } |
vcoubard | 1136:22aada733dbd | 732 | |
vcoubard | 1136:22aada733dbd | 733 | /** |
vcoubard | 1136:22aada733dbd | 734 | * Set the internal whitelist to be used by the Link Layer when scanning, |
vcoubard | 1136:22aada733dbd | 735 | * advertising or initiating a connection depending on the filter policies. |
vcoubard | 1136:22aada733dbd | 736 | * |
vcoubard | 1136:22aada733dbd | 737 | * @param[in] whitelist |
vcoubard | 1136:22aada733dbd | 738 | * A reference to a whitelist containing the addresses to |
vcoubard | 1136:22aada733dbd | 739 | * be added to the internal whitelist. |
vcoubard | 1136:22aada733dbd | 740 | * |
vcoubard | 1136:22aada733dbd | 741 | * @return BLE_ERROR_NONE if the implementation's whitelist was successfully |
vcoubard | 1136:22aada733dbd | 742 | * populated with the addresses in the given whitelist. |
vcoubard | 1136:22aada733dbd | 743 | * |
vcoubard | 1136:22aada733dbd | 744 | * @note The whitelist must not contain addresses of type @ref |
vcoubard | 1136:22aada733dbd | 745 | * BLEProtocol::AddressType_t::RANDOM_PRIVATE_NON_RESOLVABLE, this |
vcoubard | 1136:22aada733dbd | 746 | * this will result in a @ref BLE_ERROR_INVALID_PARAM since the |
vcoubard | 1136:22aada733dbd | 747 | * remote peer might change its private address at any time and it |
vcoubard | 1136:22aada733dbd | 748 | * is not possible to resolve it. |
vcoubard | 1136:22aada733dbd | 749 | * @note If the input whitelist is larger than @ref getMaxWhitelistSize() |
vcoubard | 1136:22aada733dbd | 750 | * the @ref BLE_ERROR_PARAM_OUT_OF_RANGE is returned. |
vcoubard | 1136:22aada733dbd | 751 | * |
vcoubard | 1136:22aada733dbd | 752 | * @experimental |
vcoubard | 1136:22aada733dbd | 753 | */ |
vcoubard | 1136:22aada733dbd | 754 | virtual ble_error_t setWhitelist(const Whitelist_t &whitelist) |
vcoubard | 1136:22aada733dbd | 755 | { |
vcoubard | 1136:22aada733dbd | 756 | (void) whitelist; |
vcoubard | 1136:22aada733dbd | 757 | return BLE_ERROR_NOT_IMPLEMENTED; |
vcoubard | 1136:22aada733dbd | 758 | } |
vcoubard | 1136:22aada733dbd | 759 | |
vcoubard | 1136:22aada733dbd | 760 | /** |
vcoubard | 1136:22aada733dbd | 761 | * Set the advertising policy filter mode to be used in the next call |
vcoubard | 1136:22aada733dbd | 762 | * to startAdvertising(). |
vcoubard | 1136:22aada733dbd | 763 | * |
vcoubard | 1136:22aada733dbd | 764 | * @param[in] mode |
vcoubard | 1136:22aada733dbd | 765 | * The new advertising policy filter mode. |
vcoubard | 1136:22aada733dbd | 766 | * |
vcoubard | 1136:22aada733dbd | 767 | * @return BLE_ERROR_NONE if the specified policy filter mode was set |
vcoubard | 1136:22aada733dbd | 768 | * successfully. |
vcoubard | 1136:22aada733dbd | 769 | * |
vcoubard | 1136:22aada733dbd | 770 | * @experimental |
vcoubard | 1136:22aada733dbd | 771 | */ |
vcoubard | 1136:22aada733dbd | 772 | virtual ble_error_t setAdvertisingPolicyMode(AdvertisingPolicyMode_t mode) |
vcoubard | 1136:22aada733dbd | 773 | { |
vcoubard | 1136:22aada733dbd | 774 | (void) mode; |
vcoubard | 1136:22aada733dbd | 775 | return BLE_ERROR_NOT_IMPLEMENTED; |
vcoubard | 1136:22aada733dbd | 776 | } |
vcoubard | 1136:22aada733dbd | 777 | |
vcoubard | 1136:22aada733dbd | 778 | /** |
vcoubard | 1136:22aada733dbd | 779 | * Set the scan policy filter mode to be used in the next call |
vcoubard | 1136:22aada733dbd | 780 | * to startScan(). |
vcoubard | 1136:22aada733dbd | 781 | * |
vcoubard | 1136:22aada733dbd | 782 | * @param[in] mode |
vcoubard | 1136:22aada733dbd | 783 | * The new scan policy filter mode. |
vcoubard | 1136:22aada733dbd | 784 | * |
vcoubard | 1136:22aada733dbd | 785 | * @return BLE_ERROR_NONE if the specified policy filter mode was set |
vcoubard | 1136:22aada733dbd | 786 | * successfully. |
vcoubard | 1136:22aada733dbd | 787 | * |
vcoubard | 1136:22aada733dbd | 788 | * @experimental |
vcoubard | 1136:22aada733dbd | 789 | */ |
vcoubard | 1136:22aada733dbd | 790 | virtual ble_error_t setScanningPolicyMode(ScanningPolicyMode_t mode) |
vcoubard | 1136:22aada733dbd | 791 | { |
vcoubard | 1136:22aada733dbd | 792 | (void) mode; |
vcoubard | 1136:22aada733dbd | 793 | return BLE_ERROR_NOT_IMPLEMENTED; |
vcoubard | 1136:22aada733dbd | 794 | } |
vcoubard | 1136:22aada733dbd | 795 | |
vcoubard | 1136:22aada733dbd | 796 | /** |
vcoubard | 1136:22aada733dbd | 797 | * Set the initiator policy filter mode to be used. |
vcoubard | 1136:22aada733dbd | 798 | * |
vcoubard | 1136:22aada733dbd | 799 | * @param[in] mode |
vcoubard | 1136:22aada733dbd | 800 | * The new initiator policy filter mode. |
vcoubard | 1136:22aada733dbd | 801 | * |
vcoubard | 1136:22aada733dbd | 802 | * @return BLE_ERROR_NONE if the specified policy filter mode was set |
vcoubard | 1136:22aada733dbd | 803 | * successfully. |
vcoubard | 1136:22aada733dbd | 804 | * |
vcoubard | 1136:22aada733dbd | 805 | * @experimental |
vcoubard | 1136:22aada733dbd | 806 | */ |
vcoubard | 1136:22aada733dbd | 807 | virtual ble_error_t setInitiatorPolicyMode(InitiatorPolicyMode_t mode) |
vcoubard | 1136:22aada733dbd | 808 | { |
vcoubard | 1136:22aada733dbd | 809 | (void) mode; |
vcoubard | 1136:22aada733dbd | 810 | return BLE_ERROR_NOT_IMPLEMENTED; |
vcoubard | 1136:22aada733dbd | 811 | } |
vcoubard | 1136:22aada733dbd | 812 | |
vcoubard | 1136:22aada733dbd | 813 | /** |
vcoubard | 1136:22aada733dbd | 814 | * Get the advertising policy filter mode that will be used in the next |
vcoubard | 1136:22aada733dbd | 815 | * call to startAdvertising(). |
vcoubard | 1136:22aada733dbd | 816 | * |
vcoubard | 1136:22aada733dbd | 817 | * @return The set advertising policy filter mode. |
vcoubard | 1136:22aada733dbd | 818 | * |
vcoubard | 1136:22aada733dbd | 819 | * @experimental |
vcoubard | 1136:22aada733dbd | 820 | */ |
vcoubard | 1136:22aada733dbd | 821 | virtual AdvertisingPolicyMode_t getAdvertisingPolicyMode(void) const |
vcoubard | 1136:22aada733dbd | 822 | { |
vcoubard | 1136:22aada733dbd | 823 | return ADV_POLICY_IGNORE_WHITELIST; |
vcoubard | 1136:22aada733dbd | 824 | } |
vcoubard | 1136:22aada733dbd | 825 | |
vcoubard | 1136:22aada733dbd | 826 | /** |
vcoubard | 1136:22aada733dbd | 827 | * Get the scan policy filter mode that will be used in the next |
vcoubard | 1136:22aada733dbd | 828 | * call to startScan(). |
vcoubard | 1136:22aada733dbd | 829 | * |
vcoubard | 1136:22aada733dbd | 830 | * @return The set scan policy filter mode. |
vcoubard | 1136:22aada733dbd | 831 | * |
vcoubard | 1136:22aada733dbd | 832 | * @experimental |
vcoubard | 1136:22aada733dbd | 833 | */ |
vcoubard | 1136:22aada733dbd | 834 | virtual ScanningPolicyMode_t getScanningPolicyMode(void) const |
vcoubard | 1136:22aada733dbd | 835 | { |
vcoubard | 1136:22aada733dbd | 836 | return SCAN_POLICY_IGNORE_WHITELIST; |
vcoubard | 1136:22aada733dbd | 837 | } |
vcoubard | 1136:22aada733dbd | 838 | |
vcoubard | 1136:22aada733dbd | 839 | /** |
vcoubard | 1136:22aada733dbd | 840 | * Get the initiator policy filter mode that will be used. |
vcoubard | 1136:22aada733dbd | 841 | * |
vcoubard | 1136:22aada733dbd | 842 | * @return The set scan policy filter mode. |
vcoubard | 1136:22aada733dbd | 843 | * |
vcoubard | 1136:22aada733dbd | 844 | * @experimental |
vcoubard | 1136:22aada733dbd | 845 | */ |
vcoubard | 1136:22aada733dbd | 846 | virtual InitiatorPolicyMode_t getInitiatorPolicyMode(void) const |
vcoubard | 1136:22aada733dbd | 847 | { |
vcoubard | 1136:22aada733dbd | 848 | return INIT_POLICY_IGNORE_WHITELIST; |
vcoubard | 1136:22aada733dbd | 849 | } |
vcoubard | 1136:22aada733dbd | 850 | |
vcoubard | 1132:692ddf04fc42 | 851 | protected: |
vcoubard | 1132:692ddf04fc42 | 852 | /* Override the following in the underlying adaptation layer to provide the functionality of scanning. */ |
vcoubard | 1184:1589830dbdb7 | 853 | |
vcoubard | 1184:1589830dbdb7 | 854 | /** |
vcoubard | 1184:1589830dbdb7 | 855 | * Start scanning procedure in the underlying BLE stack. |
vcoubard | 1184:1589830dbdb7 | 856 | * |
vcoubard | 1184:1589830dbdb7 | 857 | * @param[in] scanningParams |
vcoubard | 1184:1589830dbdb7 | 858 | * The GAP scanning parameters. |
vcoubard | 1184:1589830dbdb7 | 859 | * |
vcoubard | 1184:1589830dbdb7 | 860 | * @return BLE_ERROR_NONE if the scan procedure started successfully. |
vcoubard | 1184:1589830dbdb7 | 861 | */ |
vcoubard | 1132:692ddf04fc42 | 862 | virtual ble_error_t startRadioScan(const GapScanningParams &scanningParams) { |
vcoubard | 1132:692ddf04fc42 | 863 | (void)scanningParams; |
vcoubard | 1132:692ddf04fc42 | 864 | return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */ |
vcoubard | 1132:692ddf04fc42 | 865 | } |
vcoubard | 1132:692ddf04fc42 | 866 | |
vcoubard | 1132:692ddf04fc42 | 867 | /* |
vcoubard | 1132:692ddf04fc42 | 868 | * APIs with non-virtual implementations. |
vcoubard | 1132:692ddf04fc42 | 869 | */ |
vcoubard | 1132:692ddf04fc42 | 870 | public: |
vcoubard | 1132:692ddf04fc42 | 871 | /** |
vcoubard | 1184:1589830dbdb7 | 872 | * Get the current GAP state of the device using a bitmask that |
vcoubard | 1132:692ddf04fc42 | 873 | * describes whether the device is advertising or connected. |
vcoubard | 1184:1589830dbdb7 | 874 | * |
vcoubard | 1184:1589830dbdb7 | 875 | * @return The current GAP state of the device. |
vcoubard | 1132:692ddf04fc42 | 876 | */ |
vcoubard | 1132:692ddf04fc42 | 877 | GapState_t getState(void) const { |
vcoubard | 1132:692ddf04fc42 | 878 | return state; |
vcoubard | 1132:692ddf04fc42 | 879 | } |
vcoubard | 1132:692ddf04fc42 | 880 | |
vcoubard | 1132:692ddf04fc42 | 881 | /** |
vcoubard | 1132:692ddf04fc42 | 882 | * Set the GAP advertising mode to use for this device. |
vcoubard | 1184:1589830dbdb7 | 883 | * |
vcoubard | 1184:1589830dbdb7 | 884 | * @param[in] advType |
vcoubard | 1184:1589830dbdb7 | 885 | * The new type of the advertising packets. |
vcoubard | 1132:692ddf04fc42 | 886 | */ |
vcoubard | 1132:692ddf04fc42 | 887 | void setAdvertisingType(GapAdvertisingParams::AdvertisingType_t advType) { |
vcoubard | 1132:692ddf04fc42 | 888 | _advParams.setAdvertisingType(advType); |
vcoubard | 1132:692ddf04fc42 | 889 | } |
vcoubard | 1132:692ddf04fc42 | 890 | |
vcoubard | 1132:692ddf04fc42 | 891 | /** |
vcoubard | 1184:1589830dbdb7 | 892 | * Set the advertising interval. |
vcoubard | 1184:1589830dbdb7 | 893 | * |
vcoubard | 1132:692ddf04fc42 | 894 | * @param[in] interval |
vcoubard | 1132:692ddf04fc42 | 895 | * Advertising interval in units of milliseconds. Advertising |
vcoubard | 1132:692ddf04fc42 | 896 | * is disabled if interval is 0. If interval is smaller than |
vcoubard | 1132:692ddf04fc42 | 897 | * the minimum supported value, then the minimum supported |
vcoubard | 1132:692ddf04fc42 | 898 | * value is used instead. This minimum value can be discovered |
vcoubard | 1132:692ddf04fc42 | 899 | * using getMinAdvertisingInterval(). |
vcoubard | 1132:692ddf04fc42 | 900 | * |
vcoubard | 1132:692ddf04fc42 | 901 | * This field must be set to 0 if connectionMode is equal |
vcoubard | 1132:692ddf04fc42 | 902 | * to ADV_CONNECTABLE_DIRECTED. |
vcoubard | 1132:692ddf04fc42 | 903 | * |
vcoubard | 1184:1589830dbdb7 | 904 | * @note Decreasing this value will allow central devices to detect a |
vcoubard | 1184:1589830dbdb7 | 905 | * peripheral faster, at the expense of more power being used by the radio |
vcoubard | 1184:1589830dbdb7 | 906 | * due to the higher data transmit rate. |
vcoubard | 1132:692ddf04fc42 | 907 | * |
vcoubard | 1184:1589830dbdb7 | 908 | * @note [WARNING] This API previously used 0.625ms as the unit for its |
vcoubard | 1184:1589830dbdb7 | 909 | * @p interval argument. That required an explicit conversion from |
vcoubard | 1184:1589830dbdb7 | 910 | * milliseconds using Gap::MSEC_TO_GAP_DURATION_UNITS(). This conversion is |
vcoubard | 1184:1589830dbdb7 | 911 | * no longer required as the new units are milliseconds. Any application |
vcoubard | 1184:1589830dbdb7 | 912 | * code depending on the old semantics needs to be updated accordingly. |
vcoubard | 1132:692ddf04fc42 | 913 | */ |
vcoubard | 1132:692ddf04fc42 | 914 | void setAdvertisingInterval(uint16_t interval) { |
vcoubard | 1132:692ddf04fc42 | 915 | if (interval == 0) { |
vcoubard | 1132:692ddf04fc42 | 916 | stopAdvertising(); |
vcoubard | 1132:692ddf04fc42 | 917 | } else if (interval < getMinAdvertisingInterval()) { |
vcoubard | 1132:692ddf04fc42 | 918 | interval = getMinAdvertisingInterval(); |
vcoubard | 1132:692ddf04fc42 | 919 | } |
vcoubard | 1132:692ddf04fc42 | 920 | _advParams.setInterval(interval); |
vcoubard | 1132:692ddf04fc42 | 921 | } |
vcoubard | 1132:692ddf04fc42 | 922 | |
vcoubard | 1132:692ddf04fc42 | 923 | /** |
vcoubard | 1184:1589830dbdb7 | 924 | * Set the advertising timeout. The length of time to advertise for before |
vcoubard | 1184:1589830dbdb7 | 925 | * a timeout event is generated. |
vcoubard | 1184:1589830dbdb7 | 926 | * |
vcoubard | 1132:692ddf04fc42 | 927 | * @param[in] timeout |
vcoubard | 1132:692ddf04fc42 | 928 | * Advertising timeout (in seconds) between 0x1 and 0x3FFF (1 |
vcoubard | 1132:692ddf04fc42 | 929 | * and 16383). Use 0 to disable the advertising timeout. |
vcoubard | 1132:692ddf04fc42 | 930 | */ |
vcoubard | 1132:692ddf04fc42 | 931 | void setAdvertisingTimeout(uint16_t timeout) { |
vcoubard | 1132:692ddf04fc42 | 932 | _advParams.setTimeout(timeout); |
vcoubard | 1132:692ddf04fc42 | 933 | } |
vcoubard | 1132:692ddf04fc42 | 934 | |
vcoubard | 1132:692ddf04fc42 | 935 | /** |
vcoubard | 1132:692ddf04fc42 | 936 | * Start advertising. |
vcoubard | 1184:1589830dbdb7 | 937 | * |
vcoubard | 1184:1589830dbdb7 | 938 | * @return BLE_ERROR_NONE if the device started advertising successfully. |
vcoubard | 1132:692ddf04fc42 | 939 | */ |
vcoubard | 1132:692ddf04fc42 | 940 | ble_error_t startAdvertising(void) { |
vcoubard | 1187:61ac7e01586f | 941 | return startAdvertising(_advParams); |
vcoubard | 1132:692ddf04fc42 | 942 | } |
vcoubard | 1132:692ddf04fc42 | 943 | |
vcoubard | 1132:692ddf04fc42 | 944 | /** |
vcoubard | 1132:692ddf04fc42 | 945 | * Reset any advertising payload prepared from prior calls to |
vcoubard | 1132:692ddf04fc42 | 946 | * accumulateAdvertisingPayload(). This automatically propagates the re- |
vcoubard | 1132:692ddf04fc42 | 947 | * initialized advertising payload to the underlying stack. |
vcoubard | 1132:692ddf04fc42 | 948 | */ |
vcoubard | 1132:692ddf04fc42 | 949 | void clearAdvertisingPayload(void) { |
vcoubard | 1132:692ddf04fc42 | 950 | _advPayload.clear(); |
vcoubard | 1189:039621a96054 | 951 | setAdvertisingData(_advPayload, _scanResponse); |
vcoubard | 1132:692ddf04fc42 | 952 | } |
vcoubard | 1132:692ddf04fc42 | 953 | |
vcoubard | 1132:692ddf04fc42 | 954 | /** |
vcoubard | 1132:692ddf04fc42 | 955 | * Accumulate an AD structure in the advertising payload. Please note that |
vcoubard | 1132:692ddf04fc42 | 956 | * the payload is limited to 31 bytes. The SCAN_RESPONSE message may be used |
vcoubard | 1132:692ddf04fc42 | 957 | * as an additional 31 bytes if the advertising payload is too |
vcoubard | 1132:692ddf04fc42 | 958 | * small. |
vcoubard | 1132:692ddf04fc42 | 959 | * |
vcoubard | 1132:692ddf04fc42 | 960 | * @param[in] flags |
vcoubard | 1132:692ddf04fc42 | 961 | * The flags to be added. Please refer to |
vcoubard | 1132:692ddf04fc42 | 962 | * GapAdvertisingData::Flags for valid flags. Multiple |
vcoubard | 1132:692ddf04fc42 | 963 | * flags may be specified in combination. |
vcoubard | 1184:1589830dbdb7 | 964 | * |
vcoubard | 1184:1589830dbdb7 | 965 | * @return BLE_ERROR_NONE if the data was successfully added to the |
vcoubard | 1184:1589830dbdb7 | 966 | * advertising payload. |
vcoubard | 1132:692ddf04fc42 | 967 | */ |
vcoubard | 1132:692ddf04fc42 | 968 | ble_error_t accumulateAdvertisingPayload(uint8_t flags) { |
vcoubard | 1189:039621a96054 | 969 | GapAdvertisingData advPayloadCopy = _advPayload; |
vcoubard | 1132:692ddf04fc42 | 970 | ble_error_t rc; |
vcoubard | 1189:039621a96054 | 971 | if ((rc = advPayloadCopy.addFlags(flags)) != BLE_ERROR_NONE) { |
vcoubard | 1132:692ddf04fc42 | 972 | return rc; |
vcoubard | 1132:692ddf04fc42 | 973 | } |
vcoubard | 1132:692ddf04fc42 | 974 | |
vcoubard | 1189:039621a96054 | 975 | rc = setAdvertisingData(advPayloadCopy, _scanResponse); |
vcoubard | 1189:039621a96054 | 976 | if (rc == BLE_ERROR_NONE) { |
vcoubard | 1189:039621a96054 | 977 | _advPayload = advPayloadCopy; |
vcoubard | 1189:039621a96054 | 978 | } |
vcoubard | 1189:039621a96054 | 979 | |
vcoubard | 1189:039621a96054 | 980 | return rc; |
vcoubard | 1132:692ddf04fc42 | 981 | } |
vcoubard | 1132:692ddf04fc42 | 982 | |
vcoubard | 1132:692ddf04fc42 | 983 | /** |
vcoubard | 1132:692ddf04fc42 | 984 | * Accumulate an AD structure in the advertising payload. Please note that |
vcoubard | 1132:692ddf04fc42 | 985 | * the payload is limited to 31 bytes. The SCAN_RESPONSE message may be used |
vcoubard | 1132:692ddf04fc42 | 986 | * as an additional 31 bytes if the advertising payload is too |
vcoubard | 1132:692ddf04fc42 | 987 | * small. |
vcoubard | 1132:692ddf04fc42 | 988 | * |
vcoubard | 1184:1589830dbdb7 | 989 | * @param[in] app |
vcoubard | 1184:1589830dbdb7 | 990 | * The appearance of the peripheral. |
vcoubard | 1184:1589830dbdb7 | 991 | * |
vcoubard | 1184:1589830dbdb7 | 992 | * @return BLE_ERROR_NONE if the data was successfully added to the |
vcoubard | 1184:1589830dbdb7 | 993 | * advertising payload. |
vcoubard | 1132:692ddf04fc42 | 994 | */ |
vcoubard | 1132:692ddf04fc42 | 995 | ble_error_t accumulateAdvertisingPayload(GapAdvertisingData::Appearance app) { |
vcoubard | 1189:039621a96054 | 996 | GapAdvertisingData advPayloadCopy = _advPayload; |
vcoubard | 1132:692ddf04fc42 | 997 | ble_error_t rc; |
vcoubard | 1189:039621a96054 | 998 | if ((rc = advPayloadCopy.addAppearance(app)) != BLE_ERROR_NONE) { |
vcoubard | 1132:692ddf04fc42 | 999 | return rc; |
vcoubard | 1132:692ddf04fc42 | 1000 | } |
vcoubard | 1132:692ddf04fc42 | 1001 | |
vcoubard | 1189:039621a96054 | 1002 | rc = setAdvertisingData(advPayloadCopy, _scanResponse); |
vcoubard | 1189:039621a96054 | 1003 | if (rc == BLE_ERROR_NONE) { |
vcoubard | 1189:039621a96054 | 1004 | _advPayload = advPayloadCopy; |
vcoubard | 1189:039621a96054 | 1005 | } |
vcoubard | 1189:039621a96054 | 1006 | |
vcoubard | 1189:039621a96054 | 1007 | return rc; |
vcoubard | 1132:692ddf04fc42 | 1008 | } |
vcoubard | 1132:692ddf04fc42 | 1009 | |
vcoubard | 1132:692ddf04fc42 | 1010 | /** |
vcoubard | 1132:692ddf04fc42 | 1011 | * Accumulate an AD structure in the advertising payload. Please note that |
vcoubard | 1132:692ddf04fc42 | 1012 | * the payload is limited to 31 bytes. The SCAN_RESPONSE message may be used |
vcoubard | 1132:692ddf04fc42 | 1013 | * as an additional 31 bytes if the advertising payload is too |
vcoubard | 1132:692ddf04fc42 | 1014 | * small. |
vcoubard | 1132:692ddf04fc42 | 1015 | * |
vcoubard | 1184:1589830dbdb7 | 1016 | * @param[in] power |
vcoubard | 1184:1589830dbdb7 | 1017 | * The max transmit power to be used by the controller (in dBm). |
vcoubard | 1184:1589830dbdb7 | 1018 | * |
vcoubard | 1184:1589830dbdb7 | 1019 | * @return BLE_ERROR_NONE if the data was successfully added to the |
vcoubard | 1184:1589830dbdb7 | 1020 | * advertising payload. |
vcoubard | 1132:692ddf04fc42 | 1021 | */ |
vcoubard | 1132:692ddf04fc42 | 1022 | ble_error_t accumulateAdvertisingPayloadTxPower(int8_t power) { |
vcoubard | 1189:039621a96054 | 1023 | if (power < -100 || power > 20) { |
vcoubard | 1189:039621a96054 | 1024 | return BLE_ERROR_PARAM_OUT_OF_RANGE; |
vcoubard | 1189:039621a96054 | 1025 | } |
vcoubard | 1189:039621a96054 | 1026 | |
vcoubard | 1132:692ddf04fc42 | 1027 | ble_error_t rc; |
vcoubard | 1132:692ddf04fc42 | 1028 | if ((rc = _advPayload.addTxPower(power)) != BLE_ERROR_NONE) { |
vcoubard | 1132:692ddf04fc42 | 1029 | return rc; |
vcoubard | 1132:692ddf04fc42 | 1030 | } |
vcoubard | 1132:692ddf04fc42 | 1031 | |
vcoubard | 1189:039621a96054 | 1032 | return setAdvertisingData(_advPayload, _scanResponse); |
vcoubard | 1132:692ddf04fc42 | 1033 | } |
vcoubard | 1132:692ddf04fc42 | 1034 | |
vcoubard | 1132:692ddf04fc42 | 1035 | /** |
vcoubard | 1132:692ddf04fc42 | 1036 | * Accumulate a variable length byte-stream as an AD structure in the |
vcoubard | 1132:692ddf04fc42 | 1037 | * advertising payload. Please note that the payload is limited to 31 bytes. |
vcoubard | 1132:692ddf04fc42 | 1038 | * The SCAN_RESPONSE message may be used as an additional 31 bytes if the |
vcoubard | 1132:692ddf04fc42 | 1039 | * advertising payload is too small. |
vcoubard | 1132:692ddf04fc42 | 1040 | * |
vcoubard | 1184:1589830dbdb7 | 1041 | * @param[in] type |
vcoubard | 1184:1589830dbdb7 | 1042 | * The type describing the variable length data. |
vcoubard | 1184:1589830dbdb7 | 1043 | * @param[in] data |
vcoubard | 1184:1589830dbdb7 | 1044 | * Data bytes. |
vcoubard | 1184:1589830dbdb7 | 1045 | * @param[in] len |
vcoubard | 1184:1589830dbdb7 | 1046 | * Length of data. |
vcoubard | 1136:22aada733dbd | 1047 | * |
vcoubard | 1136:22aada733dbd | 1048 | * @return BLE_ERROR_NONE if the advertisement payload was updated based on |
vcoubard | 1136:22aada733dbd | 1049 | * matching AD type; otherwise, an appropriate error. |
vcoubard | 1136:22aada733dbd | 1050 | * |
vcoubard | 1136:22aada733dbd | 1051 | * @note When the specified AD type is INCOMPLETE_LIST_16BIT_SERVICE_IDS, |
vcoubard | 1136:22aada733dbd | 1052 | * COMPLETE_LIST_16BIT_SERVICE_IDS, INCOMPLETE_LIST_32BIT_SERVICE_IDS, |
vcoubard | 1136:22aada733dbd | 1053 | * COMPLETE_LIST_32BIT_SERVICE_IDS, INCOMPLETE_LIST_128BIT_SERVICE_IDS, |
vcoubard | 1136:22aada733dbd | 1054 | * COMPLETE_LIST_128BIT_SERVICE_IDS or LIST_128BIT_SOLICITATION_IDS the |
vcoubard | 1136:22aada733dbd | 1055 | * supplied value is appended to the values previously added to the |
vcoubard | 1136:22aada733dbd | 1056 | * payload. |
vcoubard | 1132:692ddf04fc42 | 1057 | */ |
vcoubard | 1132:692ddf04fc42 | 1058 | ble_error_t accumulateAdvertisingPayload(GapAdvertisingData::DataType type, const uint8_t *data, uint8_t len) { |
vcoubard | 1189:039621a96054 | 1059 | GapAdvertisingData advPayloadCopy = _advPayload; |
vcoubard | 1132:692ddf04fc42 | 1060 | ble_error_t rc; |
vcoubard | 1189:039621a96054 | 1061 | if ((rc = advPayloadCopy.addData(type, data, len)) != BLE_ERROR_NONE) { |
vcoubard | 1132:692ddf04fc42 | 1062 | return rc; |
vcoubard | 1132:692ddf04fc42 | 1063 | } |
vcoubard | 1132:692ddf04fc42 | 1064 | |
vcoubard | 1189:039621a96054 | 1065 | rc = setAdvertisingData(advPayloadCopy, _scanResponse); |
vcoubard | 1189:039621a96054 | 1066 | if (rc == BLE_ERROR_NONE) { |
vcoubard | 1189:039621a96054 | 1067 | _advPayload = advPayloadCopy; |
vcoubard | 1189:039621a96054 | 1068 | } |
vcoubard | 1189:039621a96054 | 1069 | |
vcoubard | 1189:039621a96054 | 1070 | return rc; |
vcoubard | 1132:692ddf04fc42 | 1071 | } |
vcoubard | 1132:692ddf04fc42 | 1072 | |
vcoubard | 1132:692ddf04fc42 | 1073 | /** |
vcoubard | 1132:692ddf04fc42 | 1074 | * Update a particular ADV field in the advertising payload (based on |
vcoubard | 1136:22aada733dbd | 1075 | * matching type). |
vcoubard | 1132:692ddf04fc42 | 1076 | * |
vcoubard | 1184:1589830dbdb7 | 1077 | * @param[in] type |
vcoubard | 1184:1589830dbdb7 | 1078 | * The ADV type field describing the variable length data. |
vcoubard | 1184:1589830dbdb7 | 1079 | * @param[in] data |
vcoubard | 1184:1589830dbdb7 | 1080 | * Data bytes. |
vcoubard | 1184:1589830dbdb7 | 1081 | * @param[in] len |
vcoubard | 1184:1589830dbdb7 | 1082 | * Length of data. |
vcoubard | 1132:692ddf04fc42 | 1083 | * |
vcoubard | 1184:1589830dbdb7 | 1084 | * @note If advertisements are enabled, then the update will take effect immediately. |
vcoubard | 1132:692ddf04fc42 | 1085 | * |
vcoubard | 1132:692ddf04fc42 | 1086 | * @return BLE_ERROR_NONE if the advertisement payload was updated based on |
vcoubard | 1136:22aada733dbd | 1087 | * matching AD type; otherwise, an appropriate error. |
vcoubard | 1132:692ddf04fc42 | 1088 | */ |
vcoubard | 1132:692ddf04fc42 | 1089 | ble_error_t updateAdvertisingPayload(GapAdvertisingData::DataType type, const uint8_t *data, uint8_t len) { |
vcoubard | 1189:039621a96054 | 1090 | GapAdvertisingData advPayloadCopy = _advPayload; |
vcoubard | 1132:692ddf04fc42 | 1091 | ble_error_t rc; |
vcoubard | 1189:039621a96054 | 1092 | if ((rc = advPayloadCopy.updateData(type, data, len)) != BLE_ERROR_NONE) { |
vcoubard | 1132:692ddf04fc42 | 1093 | return rc; |
vcoubard | 1132:692ddf04fc42 | 1094 | } |
vcoubard | 1132:692ddf04fc42 | 1095 | |
vcoubard | 1189:039621a96054 | 1096 | rc = setAdvertisingData(advPayloadCopy, _scanResponse); |
vcoubard | 1189:039621a96054 | 1097 | if (rc == BLE_ERROR_NONE) { |
vcoubard | 1189:039621a96054 | 1098 | _advPayload = advPayloadCopy; |
vcoubard | 1189:039621a96054 | 1099 | } |
vcoubard | 1189:039621a96054 | 1100 | |
vcoubard | 1189:039621a96054 | 1101 | return rc; |
vcoubard | 1132:692ddf04fc42 | 1102 | } |
vcoubard | 1132:692ddf04fc42 | 1103 | |
vcoubard | 1132:692ddf04fc42 | 1104 | /** |
vcoubard | 1132:692ddf04fc42 | 1105 | * Set up a particular, user-constructed advertisement payload for the |
vcoubard | 1132:692ddf04fc42 | 1106 | * underlying stack. It would be uncommon for this API to be used directly; |
vcoubard | 1184:1589830dbdb7 | 1107 | * there are other APIs to build an advertisement payload (refer to |
vcoubard | 1184:1589830dbdb7 | 1108 | * Gap::accumulateAdvertisingPayload()). |
vcoubard | 1184:1589830dbdb7 | 1109 | * |
vcoubard | 1184:1589830dbdb7 | 1110 | * @param[in] payload |
vcoubard | 1184:1589830dbdb7 | 1111 | * A reference to a user constructed advertisement |
vcoubard | 1184:1589830dbdb7 | 1112 | * payload. |
vcoubard | 1184:1589830dbdb7 | 1113 | * |
vcoubard | 1184:1589830dbdb7 | 1114 | * @return BLE_ERROR_NONE if the advertisement payload was successfully |
vcoubard | 1184:1589830dbdb7 | 1115 | * set. |
vcoubard | 1132:692ddf04fc42 | 1116 | */ |
vcoubard | 1132:692ddf04fc42 | 1117 | ble_error_t setAdvertisingPayload(const GapAdvertisingData &payload) { |
vcoubard | 1189:039621a96054 | 1118 | ble_error_t rc = setAdvertisingData(_advPayload, _scanResponse); |
vcoubard | 1189:039621a96054 | 1119 | if (rc != BLE_ERROR_NONE) { |
vcoubard | 1189:039621a96054 | 1120 | /* The payload has a problem, do not store it */ |
vcoubard | 1189:039621a96054 | 1121 | return rc; |
vcoubard | 1189:039621a96054 | 1122 | } |
vcoubard | 1132:692ddf04fc42 | 1123 | _advPayload = payload; |
vcoubard | 1189:039621a96054 | 1124 | return BLE_ERROR_NONE; |
vcoubard | 1132:692ddf04fc42 | 1125 | } |
vcoubard | 1132:692ddf04fc42 | 1126 | |
vcoubard | 1132:692ddf04fc42 | 1127 | /** |
vcoubard | 1184:1589830dbdb7 | 1128 | * Get a reference to the advertising payload. |
vcoubard | 1184:1589830dbdb7 | 1129 | * |
vcoubard | 1184:1589830dbdb7 | 1130 | * @return Read back advertising data. |
vcoubard | 1184:1589830dbdb7 | 1131 | * |
vcoubard | 1184:1589830dbdb7 | 1132 | * @note Useful for storing and restoring payload. |
vcoubard | 1132:692ddf04fc42 | 1133 | */ |
vcoubard | 1132:692ddf04fc42 | 1134 | const GapAdvertisingData &getAdvertisingPayload(void) const { |
vcoubard | 1132:692ddf04fc42 | 1135 | return _advPayload; |
vcoubard | 1132:692ddf04fc42 | 1136 | } |
vcoubard | 1132:692ddf04fc42 | 1137 | |
vcoubard | 1132:692ddf04fc42 | 1138 | /** |
vcoubard | 1132:692ddf04fc42 | 1139 | * Accumulate a variable length byte-stream as an AD structure in the |
vcoubard | 1132:692ddf04fc42 | 1140 | * scanResponse payload. |
vcoubard | 1132:692ddf04fc42 | 1141 | * |
vcoubard | 1184:1589830dbdb7 | 1142 | * @param[in] type |
vcoubard | 1184:1589830dbdb7 | 1143 | * The type describing the variable length data. |
vcoubard | 1184:1589830dbdb7 | 1144 | * @param[in] data |
vcoubard | 1184:1589830dbdb7 | 1145 | * Data bytes. |
vcoubard | 1184:1589830dbdb7 | 1146 | * @param[in] len |
vcoubard | 1184:1589830dbdb7 | 1147 | * Length of data. |
vcoubard | 1184:1589830dbdb7 | 1148 | * |
vcoubard | 1184:1589830dbdb7 | 1149 | * @return BLE_ERROR_NONE if the data was successfully added to the scan |
vcoubard | 1184:1589830dbdb7 | 1150 | * response payload. |
vcoubard | 1132:692ddf04fc42 | 1151 | */ |
vcoubard | 1132:692ddf04fc42 | 1152 | ble_error_t accumulateScanResponse(GapAdvertisingData::DataType type, const uint8_t *data, uint8_t len) { |
vcoubard | 1189:039621a96054 | 1153 | GapAdvertisingData scanResponseCopy = _scanResponse; |
vcoubard | 1132:692ddf04fc42 | 1154 | ble_error_t rc; |
vcoubard | 1189:039621a96054 | 1155 | if ((rc = scanResponseCopy.addData(type, data, len)) != BLE_ERROR_NONE) { |
vcoubard | 1132:692ddf04fc42 | 1156 | return rc; |
vcoubard | 1132:692ddf04fc42 | 1157 | } |
vcoubard | 1132:692ddf04fc42 | 1158 | |
vcoubard | 1189:039621a96054 | 1159 | rc = setAdvertisingData(_advPayload, scanResponseCopy); |
vcoubard | 1189:039621a96054 | 1160 | if (rc == BLE_ERROR_NONE) { |
vcoubard | 1189:039621a96054 | 1161 | _scanResponse = scanResponseCopy; |
vcoubard | 1189:039621a96054 | 1162 | } |
vcoubard | 1189:039621a96054 | 1163 | |
vcoubard | 1189:039621a96054 | 1164 | return rc; |
vcoubard | 1132:692ddf04fc42 | 1165 | } |
vcoubard | 1132:692ddf04fc42 | 1166 | |
vcoubard | 1132:692ddf04fc42 | 1167 | /** |
vcoubard | 1132:692ddf04fc42 | 1168 | * Reset any scan response prepared from prior calls to |
vcoubard | 1184:1589830dbdb7 | 1169 | * Gap::accumulateScanResponse(). |
vcoubard | 1132:692ddf04fc42 | 1170 | * |
vcoubard | 1184:1589830dbdb7 | 1171 | * @note This should be followed by a call to Gap::setAdvertisingPayload() or |
vcoubard | 1184:1589830dbdb7 | 1172 | * Gap::startAdvertising() before the update takes effect. |
vcoubard | 1132:692ddf04fc42 | 1173 | */ |
vcoubard | 1132:692ddf04fc42 | 1174 | void clearScanResponse(void) { |
vcoubard | 1132:692ddf04fc42 | 1175 | _scanResponse.clear(); |
vcoubard | 1189:039621a96054 | 1176 | setAdvertisingData(_advPayload, _scanResponse); |
vcoubard | 1132:692ddf04fc42 | 1177 | } |
vcoubard | 1132:692ddf04fc42 | 1178 | |
vcoubard | 1132:692ddf04fc42 | 1179 | /** |
vcoubard | 1132:692ddf04fc42 | 1180 | * Set up parameters for GAP scanning (observer mode). |
vcoubard | 1184:1589830dbdb7 | 1181 | * |
vcoubard | 1132:692ddf04fc42 | 1182 | * @param[in] interval |
vcoubard | 1132:692ddf04fc42 | 1183 | * Scan interval (in milliseconds) [valid values lie between 2.5ms and 10.24s]. |
vcoubard | 1132:692ddf04fc42 | 1184 | * @param[in] window |
vcoubard | 1132:692ddf04fc42 | 1185 | * Scan Window (in milliseconds) [valid values lie between 2.5ms and 10.24s]. |
vcoubard | 1132:692ddf04fc42 | 1186 | * @param[in] timeout |
vcoubard | 1132:692ddf04fc42 | 1187 | * Scan timeout (in seconds) between 0x0001 and 0xFFFF; 0x0000 disables the timeout. |
vcoubard | 1132:692ddf04fc42 | 1188 | * @param[in] activeScanning |
vcoubard | 1132:692ddf04fc42 | 1189 | * Set to True if active-scanning is required. This is used to fetch the |
vcoubard | 1132:692ddf04fc42 | 1190 | * scan response from a peer if possible. |
vcoubard | 1132:692ddf04fc42 | 1191 | * |
vcoubard | 1184:1589830dbdb7 | 1192 | * @return BLE_ERROR_NONE if the scan parameters were correctly set. |
vcoubard | 1132:692ddf04fc42 | 1193 | * |
vcoubard | 1184:1589830dbdb7 | 1194 | * @note The scanning window divided by the interval determines the duty cycle for |
vcoubard | 1184:1589830dbdb7 | 1195 | * scanning. For example, if the interval is 100ms and the window is 10ms, |
vcoubard | 1184:1589830dbdb7 | 1196 | * then the controller will scan for 10 percent of the time. It is possible |
vcoubard | 1184:1589830dbdb7 | 1197 | * to have the interval and window set to the same value. In this case, |
vcoubard | 1184:1589830dbdb7 | 1198 | * scanning is continuous, with a change of scanning frequency once every |
vcoubard | 1184:1589830dbdb7 | 1199 | * interval. |
vcoubard | 1132:692ddf04fc42 | 1200 | * |
vcoubard | 1184:1589830dbdb7 | 1201 | * @note Once the scanning parameters have been configured, scanning can be |
vcoubard | 1184:1589830dbdb7 | 1202 | * enabled by using startScan(). |
vcoubard | 1184:1589830dbdb7 | 1203 | * |
vcoubard | 1184:1589830dbdb7 | 1204 | * @note The scan interval and window are recommendations to the BLE stack. |
vcoubard | 1132:692ddf04fc42 | 1205 | */ |
vcoubard | 1132:692ddf04fc42 | 1206 | ble_error_t setScanParams(uint16_t interval = GapScanningParams::SCAN_INTERVAL_MAX, |
vcoubard | 1132:692ddf04fc42 | 1207 | uint16_t window = GapScanningParams::SCAN_WINDOW_MAX, |
vcoubard | 1132:692ddf04fc42 | 1208 | uint16_t timeout = 0, |
vcoubard | 1132:692ddf04fc42 | 1209 | bool activeScanning = false) { |
vcoubard | 1132:692ddf04fc42 | 1210 | ble_error_t rc; |
vcoubard | 1132:692ddf04fc42 | 1211 | if (((rc = _scanningParams.setInterval(interval)) == BLE_ERROR_NONE) && |
vcoubard | 1132:692ddf04fc42 | 1212 | ((rc = _scanningParams.setWindow(window)) == BLE_ERROR_NONE) && |
vcoubard | 1132:692ddf04fc42 | 1213 | ((rc = _scanningParams.setTimeout(timeout)) == BLE_ERROR_NONE)) { |
vcoubard | 1132:692ddf04fc42 | 1214 | _scanningParams.setActiveScanning(activeScanning); |
vcoubard | 1132:692ddf04fc42 | 1215 | return BLE_ERROR_NONE; |
vcoubard | 1132:692ddf04fc42 | 1216 | } |
vcoubard | 1132:692ddf04fc42 | 1217 | |
vcoubard | 1132:692ddf04fc42 | 1218 | return rc; |
vcoubard | 1132:692ddf04fc42 | 1219 | } |
vcoubard | 1132:692ddf04fc42 | 1220 | |
vcoubard | 1132:692ddf04fc42 | 1221 | /** |
vcoubard | 1132:692ddf04fc42 | 1222 | * Set up the scanInterval parameter for GAP scanning (observer mode). |
vcoubard | 1184:1589830dbdb7 | 1223 | * |
vcoubard | 1132:692ddf04fc42 | 1224 | * @param[in] interval |
vcoubard | 1132:692ddf04fc42 | 1225 | * Scan interval (in milliseconds) [valid values lie between 2.5ms and 10.24s]. |
vcoubard | 1132:692ddf04fc42 | 1226 | * |
vcoubard | 1184:1589830dbdb7 | 1227 | * @return BLE_ERROR_NONE if the scan interval was correctly set. |
vcoubard | 1132:692ddf04fc42 | 1228 | * |
vcoubard | 1184:1589830dbdb7 | 1229 | * @note The scanning window divided by the interval determines the duty cycle for |
vcoubard | 1184:1589830dbdb7 | 1230 | * scanning. For example, if the interval is 100ms and the window is 10ms, |
vcoubard | 1184:1589830dbdb7 | 1231 | * then the controller will scan for 10 percent of the time. It is possible |
vcoubard | 1184:1589830dbdb7 | 1232 | * to have the interval and window set to the same value. In this case, |
vcoubard | 1184:1589830dbdb7 | 1233 | * scanning is continuous, with a change of scanning frequency once every |
vcoubard | 1184:1589830dbdb7 | 1234 | * interval. |
vcoubard | 1184:1589830dbdb7 | 1235 | * |
vcoubard | 1184:1589830dbdb7 | 1236 | * @note Once the scanning parameters have been configured, scanning can be |
vcoubard | 1184:1589830dbdb7 | 1237 | * enabled by using startScan(). |
vcoubard | 1132:692ddf04fc42 | 1238 | */ |
vcoubard | 1132:692ddf04fc42 | 1239 | ble_error_t setScanInterval(uint16_t interval) { |
vcoubard | 1132:692ddf04fc42 | 1240 | return _scanningParams.setInterval(interval); |
vcoubard | 1132:692ddf04fc42 | 1241 | } |
vcoubard | 1132:692ddf04fc42 | 1242 | |
vcoubard | 1132:692ddf04fc42 | 1243 | /** |
vcoubard | 1132:692ddf04fc42 | 1244 | * Set up the scanWindow parameter for GAP scanning (observer mode). |
vcoubard | 1184:1589830dbdb7 | 1245 | * |
vcoubard | 1132:692ddf04fc42 | 1246 | * @param[in] window |
vcoubard | 1132:692ddf04fc42 | 1247 | * Scan Window (in milliseconds) [valid values lie between 2.5ms and 10.24s]. |
vcoubard | 1132:692ddf04fc42 | 1248 | * |
vcoubard | 1184:1589830dbdb7 | 1249 | * @return BLE_ERROR_NONE if the scan window was correctly set. |
vcoubard | 1132:692ddf04fc42 | 1250 | * |
vcoubard | 1184:1589830dbdb7 | 1251 | * @note The scanning window divided by the interval determines the duty cycle for |
vcoubard | 1184:1589830dbdb7 | 1252 | * scanning. For example, if the interval is 100ms and the window is 10ms, |
vcoubard | 1184:1589830dbdb7 | 1253 | * then the controller will scan for 10 percent of the time. It is possible |
vcoubard | 1184:1589830dbdb7 | 1254 | * to have the interval and window set to the same value. In this case, |
vcoubard | 1184:1589830dbdb7 | 1255 | * scanning is continuous, with a change of scanning frequency once every |
vcoubard | 1184:1589830dbdb7 | 1256 | * interval. |
vcoubard | 1132:692ddf04fc42 | 1257 | * |
vcoubard | 1184:1589830dbdb7 | 1258 | * @note Once the scanning parameters have been configured, scanning can be |
vcoubard | 1184:1589830dbdb7 | 1259 | * enabled by using startScan(). |
vcoubard | 1184:1589830dbdb7 | 1260 | * |
vcoubard | 1184:1589830dbdb7 | 1261 | * @note If scanning is already active, the updated value of scanWindow will be |
vcoubard | 1184:1589830dbdb7 | 1262 | * propagated to the underlying BLE stack. |
vcoubard | 1132:692ddf04fc42 | 1263 | */ |
vcoubard | 1132:692ddf04fc42 | 1264 | ble_error_t setScanWindow(uint16_t window) { |
vcoubard | 1132:692ddf04fc42 | 1265 | ble_error_t rc; |
vcoubard | 1132:692ddf04fc42 | 1266 | if ((rc = _scanningParams.setWindow(window)) != BLE_ERROR_NONE) { |
vcoubard | 1132:692ddf04fc42 | 1267 | return rc; |
vcoubard | 1132:692ddf04fc42 | 1268 | } |
vcoubard | 1132:692ddf04fc42 | 1269 | |
vcoubard | 1132:692ddf04fc42 | 1270 | /* If scanning is already active, propagate the new setting to the stack. */ |
vcoubard | 1132:692ddf04fc42 | 1271 | if (scanningActive) { |
vcoubard | 1132:692ddf04fc42 | 1272 | return startRadioScan(_scanningParams); |
vcoubard | 1132:692ddf04fc42 | 1273 | } |
vcoubard | 1132:692ddf04fc42 | 1274 | |
vcoubard | 1132:692ddf04fc42 | 1275 | return BLE_ERROR_NONE; |
vcoubard | 1132:692ddf04fc42 | 1276 | } |
vcoubard | 1132:692ddf04fc42 | 1277 | |
vcoubard | 1132:692ddf04fc42 | 1278 | /** |
vcoubard | 1132:692ddf04fc42 | 1279 | * Set up parameters for GAP scanning (observer mode). |
vcoubard | 1184:1589830dbdb7 | 1280 | * |
vcoubard | 1132:692ddf04fc42 | 1281 | * @param[in] timeout |
vcoubard | 1132:692ddf04fc42 | 1282 | * Scan timeout (in seconds) between 0x0001 and 0xFFFF; 0x0000 disables the timeout. |
vcoubard | 1132:692ddf04fc42 | 1283 | * |
vcoubard | 1184:1589830dbdb7 | 1284 | * @return BLE_ERROR_NONE if the scan timeout was correctly set. |
vcoubard | 1132:692ddf04fc42 | 1285 | * |
vcoubard | 1184:1589830dbdb7 | 1286 | * @note Once the scanning parameters have been configured, scanning can be |
vcoubard | 1184:1589830dbdb7 | 1287 | * enabled by using startScan(). |
vcoubard | 1184:1589830dbdb7 | 1288 | * |
vcoubard | 1184:1589830dbdb7 | 1289 | * @note If scanning is already active, the updated value of scanTimeout will be |
vcoubard | 1184:1589830dbdb7 | 1290 | * propagated to the underlying BLE stack. |
vcoubard | 1132:692ddf04fc42 | 1291 | */ |
vcoubard | 1132:692ddf04fc42 | 1292 | ble_error_t setScanTimeout(uint16_t timeout) { |
vcoubard | 1132:692ddf04fc42 | 1293 | ble_error_t rc; |
vcoubard | 1132:692ddf04fc42 | 1294 | if ((rc = _scanningParams.setTimeout(timeout)) != BLE_ERROR_NONE) { |
vcoubard | 1132:692ddf04fc42 | 1295 | return rc; |
vcoubard | 1132:692ddf04fc42 | 1296 | } |
vcoubard | 1132:692ddf04fc42 | 1297 | |
vcoubard | 1132:692ddf04fc42 | 1298 | /* If scanning is already active, propagate the new settings to the stack. */ |
vcoubard | 1132:692ddf04fc42 | 1299 | if (scanningActive) { |
vcoubard | 1132:692ddf04fc42 | 1300 | return startRadioScan(_scanningParams); |
vcoubard | 1132:692ddf04fc42 | 1301 | } |
vcoubard | 1132:692ddf04fc42 | 1302 | |
vcoubard | 1132:692ddf04fc42 | 1303 | return BLE_ERROR_NONE; |
vcoubard | 1132:692ddf04fc42 | 1304 | } |
vcoubard | 1132:692ddf04fc42 | 1305 | |
vcoubard | 1132:692ddf04fc42 | 1306 | /** |
vcoubard | 1184:1589830dbdb7 | 1307 | * Modify the active scanning parameter for GAP scanning (observer mode). |
vcoubard | 1184:1589830dbdb7 | 1308 | * This is used to fetch the scan response from a peer if possible. |
vcoubard | 1184:1589830dbdb7 | 1309 | * |
vcoubard | 1132:692ddf04fc42 | 1310 | * @param[in] activeScanning |
vcoubard | 1184:1589830dbdb7 | 1311 | * Set to True if active-scanning is required. |
vcoubard | 1132:692ddf04fc42 | 1312 | * |
vcoubard | 1184:1589830dbdb7 | 1313 | * @return BLE_ERROR_NONE if active scanning was successfully set. |
vcoubard | 1132:692ddf04fc42 | 1314 | * |
vcoubard | 1184:1589830dbdb7 | 1315 | * @note Once the scanning parameters have been configured, scanning can be |
vcoubard | 1184:1589830dbdb7 | 1316 | * enabled by using startScan(). |
vcoubard | 1184:1589830dbdb7 | 1317 | * |
vcoubard | 1184:1589830dbdb7 | 1318 | * @note If scanning is already in progress, then active-scanning will be enabled |
vcoubard | 1184:1589830dbdb7 | 1319 | * for the underlying BLE stack. |
vcoubard | 1132:692ddf04fc42 | 1320 | */ |
vcoubard | 1132:692ddf04fc42 | 1321 | ble_error_t setActiveScanning(bool activeScanning) { |
vcoubard | 1132:692ddf04fc42 | 1322 | _scanningParams.setActiveScanning(activeScanning); |
vcoubard | 1132:692ddf04fc42 | 1323 | |
vcoubard | 1132:692ddf04fc42 | 1324 | /* If scanning is already active, propagate the new settings to the stack. */ |
vcoubard | 1132:692ddf04fc42 | 1325 | if (scanningActive) { |
vcoubard | 1132:692ddf04fc42 | 1326 | return startRadioScan(_scanningParams); |
vcoubard | 1132:692ddf04fc42 | 1327 | } |
vcoubard | 1132:692ddf04fc42 | 1328 | |
vcoubard | 1132:692ddf04fc42 | 1329 | return BLE_ERROR_NONE; |
vcoubard | 1132:692ddf04fc42 | 1330 | } |
vcoubard | 1132:692ddf04fc42 | 1331 | |
vcoubard | 1132:692ddf04fc42 | 1332 | /** |
vcoubard | 1132:692ddf04fc42 | 1333 | * Start scanning (Observer Procedure) based on the parameters currently in |
vcoubard | 1132:692ddf04fc42 | 1334 | * effect. |
vcoubard | 1132:692ddf04fc42 | 1335 | * |
vcoubard | 1132:692ddf04fc42 | 1336 | * @param[in] callback |
vcoubard | 1132:692ddf04fc42 | 1337 | * The application-specific callback to be invoked upon |
vcoubard | 1132:692ddf04fc42 | 1338 | * receiving every advertisement report. This can be passed in |
vcoubard | 1132:692ddf04fc42 | 1339 | * as NULL, in which case scanning may not be enabled at all. |
vcoubard | 1184:1589830dbdb7 | 1340 | * |
vcoubard | 1184:1589830dbdb7 | 1341 | * @return BLE_ERROR_NONE if the device successfully started the scan |
vcoubard | 1184:1589830dbdb7 | 1342 | * procedure. |
vcoubard | 1132:692ddf04fc42 | 1343 | */ |
vcoubard | 1132:692ddf04fc42 | 1344 | ble_error_t startScan(void (*callback)(const AdvertisementCallbackParams_t *params)) { |
vcoubard | 1132:692ddf04fc42 | 1345 | ble_error_t err = BLE_ERROR_NONE; |
vcoubard | 1132:692ddf04fc42 | 1346 | if (callback) { |
vcoubard | 1132:692ddf04fc42 | 1347 | if ((err = startRadioScan(_scanningParams)) == BLE_ERROR_NONE) { |
vcoubard | 1132:692ddf04fc42 | 1348 | scanningActive = true; |
vcoubard | 1132:692ddf04fc42 | 1349 | onAdvertisementReport.attach(callback); |
vcoubard | 1132:692ddf04fc42 | 1350 | } |
vcoubard | 1132:692ddf04fc42 | 1351 | } |
vcoubard | 1132:692ddf04fc42 | 1352 | |
vcoubard | 1132:692ddf04fc42 | 1353 | return err; |
vcoubard | 1132:692ddf04fc42 | 1354 | } |
vcoubard | 1132:692ddf04fc42 | 1355 | |
vcoubard | 1132:692ddf04fc42 | 1356 | /** |
vcoubard | 1184:1589830dbdb7 | 1357 | * Same as Gap::startScan(), but allows the possibility to add an object |
vcoubard | 1184:1589830dbdb7 | 1358 | * reference and member function as handler for advertisement event |
vcoubard | 1184:1589830dbdb7 | 1359 | * callbacks. |
vcoubard | 1184:1589830dbdb7 | 1360 | * |
vcoubard | 1184:1589830dbdb7 | 1361 | * @param[in] object |
vcoubard | 1184:1589830dbdb7 | 1362 | * Pointer to the object of a class defining the member callback |
vcoubard | 1184:1589830dbdb7 | 1363 | * function (@p callbackMember). |
vcoubard | 1184:1589830dbdb7 | 1364 | * @param[in] callbackMember |
vcoubard | 1184:1589830dbdb7 | 1365 | * The member callback (within the context of an object) to be |
vcoubard | 1184:1589830dbdb7 | 1366 | * invoked. |
vcoubard | 1184:1589830dbdb7 | 1367 | * |
vcoubard | 1184:1589830dbdb7 | 1368 | * @return BLE_ERROR_NONE if the device successfully started the scan |
vcoubard | 1184:1589830dbdb7 | 1369 | * procedure. |
vcoubard | 1132:692ddf04fc42 | 1370 | */ |
vcoubard | 1132:692ddf04fc42 | 1371 | template<typename T> |
vcoubard | 1132:692ddf04fc42 | 1372 | ble_error_t startScan(T *object, void (T::*callbackMember)(const AdvertisementCallbackParams_t *params)) { |
vcoubard | 1132:692ddf04fc42 | 1373 | ble_error_t err = BLE_ERROR_NONE; |
vcoubard | 1132:692ddf04fc42 | 1374 | if (object && callbackMember) { |
vcoubard | 1132:692ddf04fc42 | 1375 | if ((err = startRadioScan(_scanningParams)) == BLE_ERROR_NONE) { |
vcoubard | 1132:692ddf04fc42 | 1376 | scanningActive = true; |
vcoubard | 1132:692ddf04fc42 | 1377 | onAdvertisementReport.attach(object, callbackMember); |
vcoubard | 1132:692ddf04fc42 | 1378 | } |
vcoubard | 1132:692ddf04fc42 | 1379 | } |
vcoubard | 1132:692ddf04fc42 | 1380 | |
vcoubard | 1132:692ddf04fc42 | 1381 | return err; |
vcoubard | 1132:692ddf04fc42 | 1382 | } |
vcoubard | 1132:692ddf04fc42 | 1383 | |
vcoubard | 1132:692ddf04fc42 | 1384 | /** |
vcoubard | 1132:692ddf04fc42 | 1385 | * Initialize radio-notification events to be generated from the stack. |
vcoubard | 1132:692ddf04fc42 | 1386 | * This API doesn't need to be called directly. |
vcoubard | 1132:692ddf04fc42 | 1387 | * |
vcoubard | 1132:692ddf04fc42 | 1388 | * Radio Notification is a feature that enables ACTIVE and INACTIVE |
vcoubard | 1132:692ddf04fc42 | 1389 | * (nACTIVE) signals from the stack that notify the application when the |
vcoubard | 1132:692ddf04fc42 | 1390 | * radio is in use. |
vcoubard | 1132:692ddf04fc42 | 1391 | * |
vcoubard | 1132:692ddf04fc42 | 1392 | * The ACTIVE signal is sent before the radio event starts. The nACTIVE |
vcoubard | 1132:692ddf04fc42 | 1393 | * signal is sent at the end of the radio event. These signals can be used |
vcoubard | 1132:692ddf04fc42 | 1394 | * by the application programmer to synchronize application logic with radio |
vcoubard | 1132:692ddf04fc42 | 1395 | * activity. For example, the ACTIVE signal can be used to shut off external |
vcoubard | 1132:692ddf04fc42 | 1396 | * devices, to manage peak current drawn during periods when the radio is on, |
vcoubard | 1132:692ddf04fc42 | 1397 | * or to trigger sensor data collection for transmission in the Radio Event. |
vcoubard | 1132:692ddf04fc42 | 1398 | * |
vcoubard | 1132:692ddf04fc42 | 1399 | * @return BLE_ERROR_NONE on successful initialization, otherwise an error code. |
vcoubard | 1132:692ddf04fc42 | 1400 | */ |
vcoubard | 1132:692ddf04fc42 | 1401 | virtual ble_error_t initRadioNotification(void) { |
vcoubard | 1132:692ddf04fc42 | 1402 | return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */ |
vcoubard | 1132:692ddf04fc42 | 1403 | } |
vcoubard | 1132:692ddf04fc42 | 1404 | |
vcoubard | 1132:692ddf04fc42 | 1405 | private: |
vcoubard | 1184:1589830dbdb7 | 1406 | /** |
vcoubard | 1184:1589830dbdb7 | 1407 | * Functionality that is BLE stack-dependent and must be implemented by the |
vcoubard | 1184:1589830dbdb7 | 1408 | * ported. This is a helper function to set the advertising data in the |
vcoubard | 1184:1589830dbdb7 | 1409 | * BLE stack. |
vcoubard | 1184:1589830dbdb7 | 1410 | * |
vcoubard | 1184:1589830dbdb7 | 1411 | * @param[in] advData |
vcoubard | 1184:1589830dbdb7 | 1412 | * The new advertising data. |
vcoubard | 1184:1589830dbdb7 | 1413 | * @param[in] scanResponse |
vcoubard | 1184:1589830dbdb7 | 1414 | * The new scan response data. |
vcoubard | 1184:1589830dbdb7 | 1415 | * |
vcoubard | 1184:1589830dbdb7 | 1416 | * @return BLE_ERROR_NONE if the advertising data was set successfully. |
vcoubard | 1184:1589830dbdb7 | 1417 | */ |
vcoubard | 1132:692ddf04fc42 | 1418 | virtual ble_error_t setAdvertisingData(const GapAdvertisingData &advData, const GapAdvertisingData &scanResponse) = 0; |
vcoubard | 1184:1589830dbdb7 | 1419 | |
vcoubard | 1184:1589830dbdb7 | 1420 | /** |
vcoubard | 1184:1589830dbdb7 | 1421 | * Functionality that is BLE stack-dependent and must be implemented by the |
vcoubard | 1184:1589830dbdb7 | 1422 | * ported. This is a helper function to start the advertising procedure in |
vcoubard | 1184:1589830dbdb7 | 1423 | * the underlying BLE stack. |
vcoubard | 1184:1589830dbdb7 | 1424 | * |
vcoubard | 1184:1589830dbdb7 | 1425 | * @param[in] |
vcoubard | 1184:1589830dbdb7 | 1426 | * The advertising parameters. |
vcoubard | 1184:1589830dbdb7 | 1427 | * |
vcoubard | 1184:1589830dbdb7 | 1428 | * @return BLE_ERROR_NONE if the advertising procedure was successfully |
vcoubard | 1184:1589830dbdb7 | 1429 | * started. |
vcoubard | 1184:1589830dbdb7 | 1430 | */ |
vcoubard | 1132:692ddf04fc42 | 1431 | virtual ble_error_t startAdvertising(const GapAdvertisingParams &) = 0; |
vcoubard | 1132:692ddf04fc42 | 1432 | |
vcoubard | 1132:692ddf04fc42 | 1433 | public: |
vcoubard | 1132:692ddf04fc42 | 1434 | /** |
vcoubard | 1184:1589830dbdb7 | 1435 | * Accessor to read back currently active advertising parameters. |
vcoubard | 1184:1589830dbdb7 | 1436 | * |
vcoubard | 1184:1589830dbdb7 | 1437 | * @return A reference to the current advertising parameters. |
vcoubard | 1132:692ddf04fc42 | 1438 | */ |
vcoubard | 1132:692ddf04fc42 | 1439 | GapAdvertisingParams &getAdvertisingParams(void) { |
vcoubard | 1132:692ddf04fc42 | 1440 | return _advParams; |
vcoubard | 1132:692ddf04fc42 | 1441 | } |
vcoubard | 1184:1589830dbdb7 | 1442 | |
vcoubard | 1184:1589830dbdb7 | 1443 | /** |
vcoubard | 1184:1589830dbdb7 | 1444 | * A const alternative to Gap::getAdvertisingParams(). |
vcoubard | 1184:1589830dbdb7 | 1445 | * |
vcoubard | 1184:1589830dbdb7 | 1446 | * @return A const reference to the current advertising parameters. |
vcoubard | 1184:1589830dbdb7 | 1447 | */ |
vcoubard | 1132:692ddf04fc42 | 1448 | const GapAdvertisingParams &getAdvertisingParams(void) const { |
vcoubard | 1132:692ddf04fc42 | 1449 | return _advParams; |
vcoubard | 1132:692ddf04fc42 | 1450 | } |
vcoubard | 1132:692ddf04fc42 | 1451 | |
vcoubard | 1132:692ddf04fc42 | 1452 | /** |
vcoubard | 1132:692ddf04fc42 | 1453 | * Set up a particular, user-constructed set of advertisement parameters for |
vcoubard | 1132:692ddf04fc42 | 1454 | * the underlying stack. It would be uncommon for this API to be used |
vcoubard | 1132:692ddf04fc42 | 1455 | * directly; there are other APIs to tweak advertisement parameters |
vcoubard | 1132:692ddf04fc42 | 1456 | * individually. |
vcoubard | 1184:1589830dbdb7 | 1457 | * |
vcoubard | 1184:1589830dbdb7 | 1458 | * @param[in] newParams |
vcoubard | 1184:1589830dbdb7 | 1459 | * The new advertising parameters. |
vcoubard | 1132:692ddf04fc42 | 1460 | */ |
vcoubard | 1132:692ddf04fc42 | 1461 | void setAdvertisingParams(const GapAdvertisingParams &newParams) { |
vcoubard | 1132:692ddf04fc42 | 1462 | _advParams = newParams; |
vcoubard | 1132:692ddf04fc42 | 1463 | } |
vcoubard | 1132:692ddf04fc42 | 1464 | |
vcoubard | 1132:692ddf04fc42 | 1465 | /* Event callback handlers. */ |
vcoubard | 1132:692ddf04fc42 | 1466 | public: |
vcoubard | 1132:692ddf04fc42 | 1467 | /** |
vcoubard | 1132:692ddf04fc42 | 1468 | * Set up a callback for timeout events. Refer to TimeoutSource_t for |
vcoubard | 1132:692ddf04fc42 | 1469 | * possible event types. |
vcoubard | 1184:1589830dbdb7 | 1470 | * |
vcoubard | 1184:1589830dbdb7 | 1471 | * @param[in] callback |
vcoubard | 1184:1589830dbdb7 | 1472 | * Event handler being registered. |
vcoubard | 1184:1589830dbdb7 | 1473 | * |
vcoubard | 1184:1589830dbdb7 | 1474 | * @note It is possible to unregister callbacks using onTimeout().detach(callback). |
vcoubard | 1132:692ddf04fc42 | 1475 | */ |
vcoubard | 1132:692ddf04fc42 | 1476 | void onTimeout(TimeoutEventCallback_t callback) { |
vcoubard | 1132:692ddf04fc42 | 1477 | timeoutCallbackChain.add(callback); |
vcoubard | 1132:692ddf04fc42 | 1478 | } |
vcoubard | 1132:692ddf04fc42 | 1479 | |
vcoubard | 1132:692ddf04fc42 | 1480 | /** |
vcoubard | 1184:1589830dbdb7 | 1481 | * @brief Provide access to the callchain of timeout event callbacks. |
vcoubard | 1184:1589830dbdb7 | 1482 | * |
vcoubard | 1184:1589830dbdb7 | 1483 | * @note It is possible to register callbacks using onTimeout().add(callback). |
vcoubard | 1184:1589830dbdb7 | 1484 | * |
vcoubard | 1184:1589830dbdb7 | 1485 | * @note It is possible to unregister callbacks using onTimeout().detach(callback). |
vcoubard | 1184:1589830dbdb7 | 1486 | * |
vcoubard | 1184:1589830dbdb7 | 1487 | * @return A reference to the timeout event callbacks chain. |
vcoubard | 1132:692ddf04fc42 | 1488 | */ |
vcoubard | 1132:692ddf04fc42 | 1489 | TimeoutEventCallbackChain_t& onTimeout() { |
vcoubard | 1132:692ddf04fc42 | 1490 | return timeoutCallbackChain; |
vcoubard | 1132:692ddf04fc42 | 1491 | } |
vcoubard | 1132:692ddf04fc42 | 1492 | |
vcoubard | 1132:692ddf04fc42 | 1493 | /** |
vcoubard | 1132:692ddf04fc42 | 1494 | * Append to a chain of callbacks to be invoked upon GAP connection. |
vcoubard | 1184:1589830dbdb7 | 1495 | * |
vcoubard | 1184:1589830dbdb7 | 1496 | * @param[in] callback |
vcoubard | 1184:1589830dbdb7 | 1497 | * Event handler being registered. |
vcoubard | 1184:1589830dbdb7 | 1498 | * |
vcoubard | 1132:692ddf04fc42 | 1499 | * @note It is possible to unregister callbacks using onConnection().detach(callback) |
vcoubard | 1132:692ddf04fc42 | 1500 | */ |
vcoubard | 1184:1589830dbdb7 | 1501 | void onConnection(ConnectionEventCallback_t callback) { |
vcoubard | 1184:1589830dbdb7 | 1502 | connectionCallChain.add(callback); |
vcoubard | 1184:1589830dbdb7 | 1503 | } |
vcoubard | 1132:692ddf04fc42 | 1504 | |
vcoubard | 1132:692ddf04fc42 | 1505 | /** |
vcoubard | 1184:1589830dbdb7 | 1506 | * Same as Gap::onConnection(), but allows the possibility to add an object |
vcoubard | 1184:1589830dbdb7 | 1507 | * reference and member function as handler for connection event |
vcoubard | 1184:1589830dbdb7 | 1508 | * callbacks. |
vcoubard | 1184:1589830dbdb7 | 1509 | * |
vcoubard | 1184:1589830dbdb7 | 1510 | * @param[in] tptr |
vcoubard | 1184:1589830dbdb7 | 1511 | * Pointer to the object of a class defining the member callback |
vcoubard | 1184:1589830dbdb7 | 1512 | * function (@p mptr). |
vcoubard | 1184:1589830dbdb7 | 1513 | * @param[in] mptr |
vcoubard | 1184:1589830dbdb7 | 1514 | * The member callback (within the context of an object) to be |
vcoubard | 1184:1589830dbdb7 | 1515 | * invoked. |
vcoubard | 1184:1589830dbdb7 | 1516 | */ |
vcoubard | 1184:1589830dbdb7 | 1517 | template<typename T> |
vcoubard | 1184:1589830dbdb7 | 1518 | void onConnection(T *tptr, void (T::*mptr)(const ConnectionCallbackParams_t*)) { |
vcoubard | 1184:1589830dbdb7 | 1519 | connectionCallChain.add(tptr, mptr); |
vcoubard | 1184:1589830dbdb7 | 1520 | } |
vcoubard | 1184:1589830dbdb7 | 1521 | |
vcoubard | 1184:1589830dbdb7 | 1522 | /** |
vcoubard | 1184:1589830dbdb7 | 1523 | * @brief Provide access to the callchain of connection event callbacks. |
vcoubard | 1184:1589830dbdb7 | 1524 | * |
vcoubard | 1184:1589830dbdb7 | 1525 | * @return A reference to the connection event callbacks chain. |
vcoubard | 1184:1589830dbdb7 | 1526 | * |
vcoubard | 1184:1589830dbdb7 | 1527 | * @note It is possible to register callbacks using onConnection().add(callback). |
vcoubard | 1184:1589830dbdb7 | 1528 | * |
vcoubard | 1184:1589830dbdb7 | 1529 | * @note It is possible to unregister callbacks using onConnection().detach(callback). |
vcoubard | 1132:692ddf04fc42 | 1530 | */ |
vcoubard | 1133:6362b7c2fdff | 1531 | ConnectionEventCallbackChain_t& onConnection() { |
vcoubard | 1132:692ddf04fc42 | 1532 | return connectionCallChain; |
vcoubard | 1132:692ddf04fc42 | 1533 | } |
vcoubard | 1132:692ddf04fc42 | 1534 | |
vcoubard | 1132:692ddf04fc42 | 1535 | /** |
vcoubard | 1132:692ddf04fc42 | 1536 | * Append to a chain of callbacks to be invoked upon GAP disconnection. |
vcoubard | 1184:1589830dbdb7 | 1537 | * |
vcoubard | 1184:1589830dbdb7 | 1538 | * @param[in] callback |
vcoubard | 1184:1589830dbdb7 | 1539 | Event handler being registered. |
vcoubard | 1184:1589830dbdb7 | 1540 | * |
vcoubard | 1184:1589830dbdb7 | 1541 | * @note It is possible to unregister callbacks using onDisconnection().detach(callback). |
vcoubard | 1132:692ddf04fc42 | 1542 | */ |
vcoubard | 1184:1589830dbdb7 | 1543 | void onDisconnection(DisconnectionEventCallback_t callback) { |
vcoubard | 1184:1589830dbdb7 | 1544 | disconnectionCallChain.add(callback); |
vcoubard | 1184:1589830dbdb7 | 1545 | } |
vcoubard | 1132:692ddf04fc42 | 1546 | |
vcoubard | 1132:692ddf04fc42 | 1547 | /** |
vcoubard | 1184:1589830dbdb7 | 1548 | * Same as Gap::onDisconnection(), but allows the possibility to add an object |
vcoubard | 1184:1589830dbdb7 | 1549 | * reference and member function as handler for disconnection event |
vcoubard | 1184:1589830dbdb7 | 1550 | * callbacks. |
vcoubard | 1184:1589830dbdb7 | 1551 | * |
vcoubard | 1184:1589830dbdb7 | 1552 | * @param[in] tptr |
vcoubard | 1184:1589830dbdb7 | 1553 | * Pointer to the object of a class defining the member callback |
vcoubard | 1184:1589830dbdb7 | 1554 | * function (@p mptr). |
vcoubard | 1184:1589830dbdb7 | 1555 | * @param[in] mptr |
vcoubard | 1184:1589830dbdb7 | 1556 | * The member callback (within the context of an object) to be |
vcoubard | 1184:1589830dbdb7 | 1557 | * invoked. |
vcoubard | 1184:1589830dbdb7 | 1558 | */ |
vcoubard | 1184:1589830dbdb7 | 1559 | template<typename T> |
vcoubard | 1184:1589830dbdb7 | 1560 | void onDisconnection(T *tptr, void (T::*mptr)(const DisconnectionCallbackParams_t*)) { |
vcoubard | 1184:1589830dbdb7 | 1561 | disconnectionCallChain.add(tptr, mptr); |
vcoubard | 1184:1589830dbdb7 | 1562 | } |
vcoubard | 1184:1589830dbdb7 | 1563 | |
vcoubard | 1184:1589830dbdb7 | 1564 | /** |
vcoubard | 1184:1589830dbdb7 | 1565 | * @brief Provide access to the callchain of disconnection event callbacks. |
vcoubard | 1184:1589830dbdb7 | 1566 | * |
vcoubard | 1184:1589830dbdb7 | 1567 | * @return A reference to the disconnection event callback chain. |
vcoubard | 1184:1589830dbdb7 | 1568 | * |
vcoubard | 1184:1589830dbdb7 | 1569 | * @note It is possible to register callbacks using onDisconnection().add(callback). |
vcoubard | 1184:1589830dbdb7 | 1570 | * |
vcoubard | 1184:1589830dbdb7 | 1571 | * @note It is possible to unregister callbacks using onDisconnection().detach(callback). |
vcoubard | 1132:692ddf04fc42 | 1572 | */ |
vcoubard | 1132:692ddf04fc42 | 1573 | DisconnectionEventCallbackChain_t& onDisconnection() { |
vcoubard | 1132:692ddf04fc42 | 1574 | return disconnectionCallChain; |
vcoubard | 1132:692ddf04fc42 | 1575 | } |
vcoubard | 1132:692ddf04fc42 | 1576 | |
vcoubard | 1132:692ddf04fc42 | 1577 | /** |
vcoubard | 1132:692ddf04fc42 | 1578 | * Set the application callback for radio-notification events. |
vcoubard | 1132:692ddf04fc42 | 1579 | * |
vcoubard | 1132:692ddf04fc42 | 1580 | * Radio Notification is a feature that enables ACTIVE and INACTIVE |
vcoubard | 1132:692ddf04fc42 | 1581 | * (nACTIVE) signals from the stack that notify the application when the |
vcoubard | 1132:692ddf04fc42 | 1582 | * radio is in use. |
vcoubard | 1132:692ddf04fc42 | 1583 | * |
vcoubard | 1132:692ddf04fc42 | 1584 | * The ACTIVE signal is sent before the radio event starts. The nACTIVE |
vcoubard | 1132:692ddf04fc42 | 1585 | * signal is sent at the end of the radio event. These signals can be used |
vcoubard | 1132:692ddf04fc42 | 1586 | * by the application programmer to synchronize application logic with radio |
vcoubard | 1132:692ddf04fc42 | 1587 | * activity. For example, the ACTIVE signal can be used to shut off external |
vcoubard | 1132:692ddf04fc42 | 1588 | * devices, to manage peak current drawn during periods when the radio is on, |
vcoubard | 1132:692ddf04fc42 | 1589 | * or to trigger sensor data collection for transmission in the Radio Event. |
vcoubard | 1132:692ddf04fc42 | 1590 | * |
vcoubard | 1184:1589830dbdb7 | 1591 | * @param[in] callback |
vcoubard | 1184:1589830dbdb7 | 1592 | * The application handler to be invoked in response to a radio |
vcoubard | 1184:1589830dbdb7 | 1593 | * ACTIVE/INACTIVE event. |
vcoubard | 1132:692ddf04fc42 | 1594 | */ |
vcoubard | 1132:692ddf04fc42 | 1595 | void onRadioNotification(void (*callback)(bool param)) { |
vcoubard | 1132:692ddf04fc42 | 1596 | radioNotificationCallback.attach(callback); |
vcoubard | 1132:692ddf04fc42 | 1597 | } |
vcoubard | 1184:1589830dbdb7 | 1598 | |
vcoubard | 1184:1589830dbdb7 | 1599 | /** |
vcoubard | 1184:1589830dbdb7 | 1600 | * Same as Gap::onRadioNotification(), but allows the posibility to |
vcoubard | 1184:1589830dbdb7 | 1601 | * register an object reference and member function as handler for radio |
vcoubard | 1184:1589830dbdb7 | 1602 | * notification events. |
vcoubard | 1184:1589830dbdb7 | 1603 | * |
vcoubard | 1184:1589830dbdb7 | 1604 | * @param[in] tptr |
vcoubard | 1184:1589830dbdb7 | 1605 | * Pointer to the object of a class defining the member callback |
vcoubard | 1184:1589830dbdb7 | 1606 | * function (@p mptr). |
vcoubard | 1184:1589830dbdb7 | 1607 | * @param[in] mptr |
vcoubard | 1184:1589830dbdb7 | 1608 | * The member callback (within the context of an object) to be |
vcoubard | 1184:1589830dbdb7 | 1609 | * invoked in response to a radio ACTIVE/INACTIVE event. |
vcoubard | 1184:1589830dbdb7 | 1610 | */ |
vcoubard | 1132:692ddf04fc42 | 1611 | template <typename T> |
vcoubard | 1132:692ddf04fc42 | 1612 | void onRadioNotification(T *tptr, void (T::*mptr)(bool)) { |
vcoubard | 1132:692ddf04fc42 | 1613 | radioNotificationCallback.attach(tptr, mptr); |
vcoubard | 1132:692ddf04fc42 | 1614 | } |
vcoubard | 1132:692ddf04fc42 | 1615 | |
vcoubard | 1136:22aada733dbd | 1616 | /** |
vcoubard | 1136:22aada733dbd | 1617 | * Setup a callback to be invoked to notify the user application that the |
vcoubard | 1136:22aada733dbd | 1618 | * Gap instance is about to shutdown (possibly as a result of a call |
vcoubard | 1136:22aada733dbd | 1619 | * to BLE::shutdown()). |
vcoubard | 1136:22aada733dbd | 1620 | * |
vcoubard | 1184:1589830dbdb7 | 1621 | * @param[in] callback |
vcoubard | 1184:1589830dbdb7 | 1622 | * The handler that is being registered to be notified of |
vcoubard | 1184:1589830dbdb7 | 1623 | * shutdown events. |
vcoubard | 1184:1589830dbdb7 | 1624 | * |
vcoubard | 1184:1589830dbdb7 | 1625 | * @note It is possible to chain together multiple onShutdown callbacks |
vcoubard | 1136:22aada733dbd | 1626 | * (potentially from different modules of an application) to be notified |
vcoubard | 1136:22aada733dbd | 1627 | * before the Gap instance is shutdown. |
vcoubard | 1136:22aada733dbd | 1628 | * |
vcoubard | 1184:1589830dbdb7 | 1629 | * @note It is also possible to set up a callback into a member function of |
vcoubard | 1136:22aada733dbd | 1630 | * some object. |
vcoubard | 1136:22aada733dbd | 1631 | * |
vcoubard | 1184:1589830dbdb7 | 1632 | * @note It is possible to unregister a callback using onShutdown().detach(callback) |
vcoubard | 1136:22aada733dbd | 1633 | */ |
vcoubard | 1136:22aada733dbd | 1634 | void onShutdown(const GapShutdownCallback_t& callback) { |
vcoubard | 1136:22aada733dbd | 1635 | shutdownCallChain.add(callback); |
vcoubard | 1136:22aada733dbd | 1636 | } |
vcoubard | 1184:1589830dbdb7 | 1637 | |
vcoubard | 1184:1589830dbdb7 | 1638 | /** |
vcoubard | 1184:1589830dbdb7 | 1639 | * Same as Gap::onShutdown(), but allows the posibility to |
vcoubard | 1184:1589830dbdb7 | 1640 | * register an object reference and member function as handler for shutdown |
vcoubard | 1184:1589830dbdb7 | 1641 | * events. |
vcoubard | 1184:1589830dbdb7 | 1642 | * |
vcoubard | 1184:1589830dbdb7 | 1643 | * @param[in] objPtr |
vcoubard | 1184:1589830dbdb7 | 1644 | * Pointer to the object of a class defining the member callback |
vcoubard | 1184:1589830dbdb7 | 1645 | * function (@p memberPtr). |
vcoubard | 1184:1589830dbdb7 | 1646 | * @param[in] memberPtr |
vcoubard | 1184:1589830dbdb7 | 1647 | * The member callback (within the context of an object) to be |
vcoubard | 1184:1589830dbdb7 | 1648 | * invoked in response to a shutdown event. |
vcoubard | 1184:1589830dbdb7 | 1649 | */ |
vcoubard | 1136:22aada733dbd | 1650 | template <typename T> |
vcoubard | 1136:22aada733dbd | 1651 | void onShutdown(T *objPtr, void (T::*memberPtr)(void)) { |
vcoubard | 1136:22aada733dbd | 1652 | shutdownCallChain.add(objPtr, memberPtr); |
vcoubard | 1136:22aada733dbd | 1653 | } |
vcoubard | 1136:22aada733dbd | 1654 | |
vcoubard | 1136:22aada733dbd | 1655 | /** |
vcoubard | 1184:1589830dbdb7 | 1656 | * @brief Provide access to the callchain of shutdown event callbacks. |
vcoubard | 1184:1589830dbdb7 | 1657 | * |
vcoubard | 1184:1589830dbdb7 | 1658 | * @return A reference to the shutdown event callback chain. |
vcoubard | 1184:1589830dbdb7 | 1659 | * |
vcoubard | 1184:1589830dbdb7 | 1660 | * @note It is possible to register callbacks using onShutdown().add(callback). |
vcoubard | 1184:1589830dbdb7 | 1661 | * |
vcoubard | 1184:1589830dbdb7 | 1662 | * @note It is possible to unregister callbacks using onShutdown().detach(callback). |
vcoubard | 1136:22aada733dbd | 1663 | */ |
vcoubard | 1136:22aada733dbd | 1664 | GapShutdownCallbackChain_t& onShutdown() { |
vcoubard | 1136:22aada733dbd | 1665 | return shutdownCallChain; |
vcoubard | 1136:22aada733dbd | 1666 | } |
vcoubard | 1136:22aada733dbd | 1667 | |
vcoubard | 1136:22aada733dbd | 1668 | public: |
vcoubard | 1136:22aada733dbd | 1669 | /** |
vcoubard | 1136:22aada733dbd | 1670 | * Notify all registered onShutdown callbacks that the Gap instance is |
vcoubard | 1136:22aada733dbd | 1671 | * about to be shutdown and clear all Gap state of the |
vcoubard | 1136:22aada733dbd | 1672 | * associated object. |
vcoubard | 1136:22aada733dbd | 1673 | * |
vcoubard | 1136:22aada733dbd | 1674 | * This function is meant to be overridden in the platform-specific |
vcoubard | 1136:22aada733dbd | 1675 | * sub-class. Nevertheless, the sub-class is only expected to reset its |
vcoubard | 1136:22aada733dbd | 1676 | * state and not the data held in Gap members. This shall be achieved by a |
vcoubard | 1136:22aada733dbd | 1677 | * call to Gap::reset() from the sub-class' reset() implementation. |
vcoubard | 1136:22aada733dbd | 1678 | * |
vcoubard | 1136:22aada733dbd | 1679 | * @return BLE_ERROR_NONE on success. |
vcoubard | 1136:22aada733dbd | 1680 | * |
vcoubard | 1184:1589830dbdb7 | 1681 | * @note Currently a call to reset() does not reset the advertising and |
vcoubard | 1136:22aada733dbd | 1682 | * scan parameters to default values. |
vcoubard | 1136:22aada733dbd | 1683 | */ |
vcoubard | 1136:22aada733dbd | 1684 | virtual ble_error_t reset(void) { |
vcoubard | 1136:22aada733dbd | 1685 | /* Notify that the instance is about to shutdown */ |
vcoubard | 1136:22aada733dbd | 1686 | shutdownCallChain.call(this); |
vcoubard | 1136:22aada733dbd | 1687 | shutdownCallChain.clear(); |
vcoubard | 1136:22aada733dbd | 1688 | |
vcoubard | 1136:22aada733dbd | 1689 | /* Clear Gap state */ |
vcoubard | 1136:22aada733dbd | 1690 | state.advertising = 0; |
vcoubard | 1136:22aada733dbd | 1691 | state.connected = 0; |
vcoubard | 1181:e11b058d005e | 1692 | connectionCount = 0; |
vcoubard | 1136:22aada733dbd | 1693 | |
vcoubard | 1136:22aada733dbd | 1694 | /* Clear scanning state */ |
vcoubard | 1136:22aada733dbd | 1695 | scanningActive = false; |
vcoubard | 1136:22aada733dbd | 1696 | |
vcoubard | 1136:22aada733dbd | 1697 | /* Clear advertising and scanning data */ |
vcoubard | 1136:22aada733dbd | 1698 | _advPayload.clear(); |
vcoubard | 1136:22aada733dbd | 1699 | _scanResponse.clear(); |
vcoubard | 1136:22aada733dbd | 1700 | |
vcoubard | 1136:22aada733dbd | 1701 | /* Clear callbacks */ |
vcoubard | 1136:22aada733dbd | 1702 | timeoutCallbackChain.clear(); |
vcoubard | 1136:22aada733dbd | 1703 | connectionCallChain.clear(); |
vcoubard | 1136:22aada733dbd | 1704 | disconnectionCallChain.clear(); |
vcoubard | 1136:22aada733dbd | 1705 | radioNotificationCallback = NULL; |
vcoubard | 1136:22aada733dbd | 1706 | onAdvertisementReport = NULL; |
vcoubard | 1136:22aada733dbd | 1707 | |
vcoubard | 1136:22aada733dbd | 1708 | return BLE_ERROR_NONE; |
vcoubard | 1136:22aada733dbd | 1709 | } |
vcoubard | 1136:22aada733dbd | 1710 | |
vcoubard | 1132:692ddf04fc42 | 1711 | protected: |
vcoubard | 1184:1589830dbdb7 | 1712 | /** |
vcoubard | 1184:1589830dbdb7 | 1713 | * Construct a Gap instance. |
vcoubard | 1184:1589830dbdb7 | 1714 | */ |
vcoubard | 1132:692ddf04fc42 | 1715 | Gap() : |
vcoubard | 1132:692ddf04fc42 | 1716 | _advParams(), |
vcoubard | 1132:692ddf04fc42 | 1717 | _advPayload(), |
vcoubard | 1132:692ddf04fc42 | 1718 | _scanningParams(), |
vcoubard | 1132:692ddf04fc42 | 1719 | _scanResponse(), |
vcoubard | 1181:e11b058d005e | 1720 | connectionCount(0), |
vcoubard | 1132:692ddf04fc42 | 1721 | state(), |
vcoubard | 1132:692ddf04fc42 | 1722 | scanningActive(false), |
vcoubard | 1132:692ddf04fc42 | 1723 | timeoutCallbackChain(), |
vcoubard | 1132:692ddf04fc42 | 1724 | radioNotificationCallback(), |
vcoubard | 1132:692ddf04fc42 | 1725 | onAdvertisementReport(), |
vcoubard | 1132:692ddf04fc42 | 1726 | connectionCallChain(), |
vcoubard | 1132:692ddf04fc42 | 1727 | disconnectionCallChain() { |
vcoubard | 1132:692ddf04fc42 | 1728 | _advPayload.clear(); |
vcoubard | 1132:692ddf04fc42 | 1729 | _scanResponse.clear(); |
vcoubard | 1132:692ddf04fc42 | 1730 | } |
vcoubard | 1132:692ddf04fc42 | 1731 | |
vcoubard | 1132:692ddf04fc42 | 1732 | /* Entry points for the underlying stack to report events back to the user. */ |
vcoubard | 1132:692ddf04fc42 | 1733 | public: |
vcoubard | 1184:1589830dbdb7 | 1734 | /** |
vcoubard | 1184:1589830dbdb7 | 1735 | * Helper function that notifies all registered handlers of an occurrence |
vcoubard | 1184:1589830dbdb7 | 1736 | * of a connection event. This function is meant to be called from the |
vcoubard | 1184:1589830dbdb7 | 1737 | * BLE stack specific implementation when a connection event occurs. |
vcoubard | 1184:1589830dbdb7 | 1738 | * |
vcoubard | 1184:1589830dbdb7 | 1739 | * @param[in] handle |
vcoubard | 1184:1589830dbdb7 | 1740 | * The ID of the connection that generated the event. |
vcoubard | 1184:1589830dbdb7 | 1741 | * @param[in] role |
vcoubard | 1184:1589830dbdb7 | 1742 | * The role of this BLE device in the connection. |
vcoubard | 1184:1589830dbdb7 | 1743 | * @param[in] peerAddrType |
vcoubard | 1184:1589830dbdb7 | 1744 | * The peer's BLE address type. |
vcoubard | 1184:1589830dbdb7 | 1745 | * @param[in] peerAddr |
vcoubard | 1184:1589830dbdb7 | 1746 | * The peer's BLE address. |
vcoubard | 1184:1589830dbdb7 | 1747 | * @param[in] ownAddrType |
vcoubard | 1184:1589830dbdb7 | 1748 | * This device's BLE address type. |
vcoubard | 1184:1589830dbdb7 | 1749 | * @param[in] ownAddr |
vcoubard | 1184:1589830dbdb7 | 1750 | * This device's BLE address. |
vcoubard | 1184:1589830dbdb7 | 1751 | * @param[in] connectionParams |
vcoubard | 1184:1589830dbdb7 | 1752 | * The parameters configured for this connection. |
vcoubard | 1184:1589830dbdb7 | 1753 | */ |
vcoubard | 1136:22aada733dbd | 1754 | void processConnectionEvent(Handle_t handle, |
vcoubard | 1136:22aada733dbd | 1755 | Role_t role, |
vcoubard | 1136:22aada733dbd | 1756 | BLEProtocol::AddressType_t peerAddrType, |
vcoubard | 1136:22aada733dbd | 1757 | const BLEProtocol::AddressBytes_t peerAddr, |
vcoubard | 1136:22aada733dbd | 1758 | BLEProtocol::AddressType_t ownAddrType, |
vcoubard | 1136:22aada733dbd | 1759 | const BLEProtocol::AddressBytes_t ownAddr, |
vcoubard | 1136:22aada733dbd | 1760 | const ConnectionParams_t *connectionParams) { |
vcoubard | 1181:e11b058d005e | 1761 | /* Update Gap state */ |
vcoubard | 1181:e11b058d005e | 1762 | state.advertising = 0; |
vcoubard | 1181:e11b058d005e | 1763 | state.connected = 1; |
vcoubard | 1181:e11b058d005e | 1764 | ++connectionCount; |
vcoubard | 1181:e11b058d005e | 1765 | |
vcoubard | 1132:692ddf04fc42 | 1766 | ConnectionCallbackParams_t callbackParams(handle, role, peerAddrType, peerAddr, ownAddrType, ownAddr, connectionParams); |
vcoubard | 1132:692ddf04fc42 | 1767 | connectionCallChain.call(&callbackParams); |
vcoubard | 1132:692ddf04fc42 | 1768 | } |
vcoubard | 1132:692ddf04fc42 | 1769 | |
vcoubard | 1184:1589830dbdb7 | 1770 | /** |
vcoubard | 1184:1589830dbdb7 | 1771 | * Helper function that notifies all registered handlers of an occurrence |
vcoubard | 1184:1589830dbdb7 | 1772 | * of a disconnection event. This function is meant to be called from the |
vcoubard | 1184:1589830dbdb7 | 1773 | * BLE stack specific implementation when a disconnection event occurs. |
vcoubard | 1184:1589830dbdb7 | 1774 | * |
vcoubard | 1184:1589830dbdb7 | 1775 | * @param[in] handle |
vcoubard | 1184:1589830dbdb7 | 1776 | * The ID of the connection that generated the event. |
vcoubard | 1184:1589830dbdb7 | 1777 | * @param[in] reason |
vcoubard | 1184:1589830dbdb7 | 1778 | * The reason for disconnection. |
vcoubard | 1184:1589830dbdb7 | 1779 | */ |
vcoubard | 1132:692ddf04fc42 | 1780 | void processDisconnectionEvent(Handle_t handle, DisconnectionReason_t reason) { |
vcoubard | 1181:e11b058d005e | 1781 | /* Update Gap state */ |
vcoubard | 1181:e11b058d005e | 1782 | --connectionCount; |
vcoubard | 1181:e11b058d005e | 1783 | if (!connectionCount) { |
vcoubard | 1181:e11b058d005e | 1784 | state.connected = 0; |
vcoubard | 1181:e11b058d005e | 1785 | } |
vcoubard | 1181:e11b058d005e | 1786 | |
vcoubard | 1132:692ddf04fc42 | 1787 | DisconnectionCallbackParams_t callbackParams(handle, reason); |
vcoubard | 1132:692ddf04fc42 | 1788 | disconnectionCallChain.call(&callbackParams); |
vcoubard | 1132:692ddf04fc42 | 1789 | } |
vcoubard | 1132:692ddf04fc42 | 1790 | |
vcoubard | 1184:1589830dbdb7 | 1791 | /** |
vcoubard | 1184:1589830dbdb7 | 1792 | * Helper function that notifies the registered handler of a scanned |
vcoubard | 1184:1589830dbdb7 | 1793 | * advertisement packet. This function is meant to be called from the |
vcoubard | 1184:1589830dbdb7 | 1794 | * BLE stack specific implementation when a such event occurs. |
vcoubard | 1184:1589830dbdb7 | 1795 | * |
vcoubard | 1184:1589830dbdb7 | 1796 | * @param[in] peerAddr |
vcoubard | 1184:1589830dbdb7 | 1797 | * The peer's BLE address. |
vcoubard | 1184:1589830dbdb7 | 1798 | * @param[in] rssi |
vcoubard | 1184:1589830dbdb7 | 1799 | * The advertisement packet RSSI value. |
vcoubard | 1184:1589830dbdb7 | 1800 | * @param[in] isScanReponse |
vcoubard | 1184:1589830dbdb7 | 1801 | * Whether this packet is the response to a scan request. |
vcoubard | 1184:1589830dbdb7 | 1802 | * @param[in] type |
vcoubard | 1184:1589830dbdb7 | 1803 | * The type of advertisement. |
vcoubard | 1184:1589830dbdb7 | 1804 | * @param[in] advertisingDataLen |
vcoubard | 1184:1589830dbdb7 | 1805 | * Length of the advertisement data. |
vcoubard | 1184:1589830dbdb7 | 1806 | * @param[in] advertisingData |
vcoubard | 1184:1589830dbdb7 | 1807 | * Pointer to the advertisement packet's data. |
vcoubard | 1184:1589830dbdb7 | 1808 | */ |
vcoubard | 1136:22aada733dbd | 1809 | void processAdvertisementReport(const BLEProtocol::AddressBytes_t peerAddr, |
vcoubard | 1136:22aada733dbd | 1810 | int8_t rssi, |
vcoubard | 1136:22aada733dbd | 1811 | bool isScanResponse, |
vcoubard | 1132:692ddf04fc42 | 1812 | GapAdvertisingParams::AdvertisingType_t type, |
vcoubard | 1136:22aada733dbd | 1813 | uint8_t advertisingDataLen, |
vcoubard | 1136:22aada733dbd | 1814 | const uint8_t *advertisingData) { |
vcoubard | 1132:692ddf04fc42 | 1815 | AdvertisementCallbackParams_t params; |
vcoubard | 1132:692ddf04fc42 | 1816 | memcpy(params.peerAddr, peerAddr, ADDR_LEN); |
vcoubard | 1132:692ddf04fc42 | 1817 | params.rssi = rssi; |
vcoubard | 1132:692ddf04fc42 | 1818 | params.isScanResponse = isScanResponse; |
vcoubard | 1132:692ddf04fc42 | 1819 | params.type = type; |
vcoubard | 1132:692ddf04fc42 | 1820 | params.advertisingDataLen = advertisingDataLen; |
vcoubard | 1132:692ddf04fc42 | 1821 | params.advertisingData = advertisingData; |
vcoubard | 1132:692ddf04fc42 | 1822 | onAdvertisementReport.call(¶ms); |
vcoubard | 1132:692ddf04fc42 | 1823 | } |
vcoubard | 1132:692ddf04fc42 | 1824 | |
vcoubard | 1184:1589830dbdb7 | 1825 | /** |
vcoubard | 1184:1589830dbdb7 | 1826 | * Helper function that notifies all registered handlers of an occurrence |
vcoubard | 1184:1589830dbdb7 | 1827 | * of a timeout event. This function is meant to be called from the |
vcoubard | 1184:1589830dbdb7 | 1828 | * BLE stack specific implementation when a timeout event occurs. |
vcoubard | 1184:1589830dbdb7 | 1829 | * |
vcoubard | 1184:1589830dbdb7 | 1830 | * @param[in] source |
vcoubard | 1184:1589830dbdb7 | 1831 | * The source of the timout event. |
vcoubard | 1184:1589830dbdb7 | 1832 | */ |
vcoubard | 1132:692ddf04fc42 | 1833 | void processTimeoutEvent(TimeoutSource_t source) { |
vcoubard | 1180:4ab722f8dca0 | 1834 | if (source == TIMEOUT_SRC_ADVERTISING) { |
vcoubard | 1180:4ab722f8dca0 | 1835 | /* Update gap state if the source is an advertising timeout */ |
vcoubard | 1180:4ab722f8dca0 | 1836 | state.advertising = 0; |
vcoubard | 1180:4ab722f8dca0 | 1837 | } |
vcoubard | 1132:692ddf04fc42 | 1838 | if (timeoutCallbackChain) { |
vcoubard | 1132:692ddf04fc42 | 1839 | timeoutCallbackChain(source); |
vcoubard | 1132:692ddf04fc42 | 1840 | } |
vcoubard | 1132:692ddf04fc42 | 1841 | } |
vcoubard | 1132:692ddf04fc42 | 1842 | |
vcoubard | 1132:692ddf04fc42 | 1843 | protected: |
vcoubard | 1184:1589830dbdb7 | 1844 | /** |
vcoubard | 1184:1589830dbdb7 | 1845 | * Currently set advertising parameters. |
vcoubard | 1184:1589830dbdb7 | 1846 | */ |
vcoubard | 1132:692ddf04fc42 | 1847 | GapAdvertisingParams _advParams; |
vcoubard | 1184:1589830dbdb7 | 1848 | /** |
vcoubard | 1184:1589830dbdb7 | 1849 | * Currently set advertising data. |
vcoubard | 1184:1589830dbdb7 | 1850 | */ |
vcoubard | 1132:692ddf04fc42 | 1851 | GapAdvertisingData _advPayload; |
vcoubard | 1184:1589830dbdb7 | 1852 | /** |
vcoubard | 1184:1589830dbdb7 | 1853 | * Currently set scanning parameters. |
vcoubard | 1184:1589830dbdb7 | 1854 | */ |
vcoubard | 1132:692ddf04fc42 | 1855 | GapScanningParams _scanningParams; |
vcoubard | 1184:1589830dbdb7 | 1856 | /** |
vcoubard | 1184:1589830dbdb7 | 1857 | * Currently set scan response data. |
vcoubard | 1184:1589830dbdb7 | 1858 | */ |
vcoubard | 1132:692ddf04fc42 | 1859 | GapAdvertisingData _scanResponse; |
vcoubard | 1132:692ddf04fc42 | 1860 | |
vcoubard | 1181:e11b058d005e | 1861 | /** |
vcoubard | 1181:e11b058d005e | 1862 | * Total number of open connections. |
vcoubard | 1181:e11b058d005e | 1863 | */ |
vcoubard | 1181:e11b058d005e | 1864 | uint8_t connectionCount; |
vcoubard | 1184:1589830dbdb7 | 1865 | /** |
vcoubard | 1184:1589830dbdb7 | 1866 | * The current GAP state. |
vcoubard | 1184:1589830dbdb7 | 1867 | */ |
vcoubard | 1132:692ddf04fc42 | 1868 | GapState_t state; |
vcoubard | 1184:1589830dbdb7 | 1869 | /** |
vcoubard | 1184:1589830dbdb7 | 1870 | * Whether active scanning is set. This is used to fetch the scan response |
vcoubard | 1184:1589830dbdb7 | 1871 | * from a peer if possible. |
vcoubard | 1184:1589830dbdb7 | 1872 | */ |
vcoubard | 1132:692ddf04fc42 | 1873 | bool scanningActive; |
vcoubard | 1132:692ddf04fc42 | 1874 | |
vcoubard | 1132:692ddf04fc42 | 1875 | protected: |
vcoubard | 1184:1589830dbdb7 | 1876 | /** |
vcoubard | 1184:1589830dbdb7 | 1877 | * Callchain containing all registered callback handlers for timeout |
vcoubard | 1184:1589830dbdb7 | 1878 | * events. |
vcoubard | 1184:1589830dbdb7 | 1879 | */ |
vcoubard | 1132:692ddf04fc42 | 1880 | TimeoutEventCallbackChain_t timeoutCallbackChain; |
vcoubard | 1184:1589830dbdb7 | 1881 | /** |
vcoubard | 1184:1589830dbdb7 | 1882 | * The registered callback handler for radio notification events. |
vcoubard | 1184:1589830dbdb7 | 1883 | */ |
vcoubard | 1132:692ddf04fc42 | 1884 | RadioNotificationEventCallback_t radioNotificationCallback; |
vcoubard | 1184:1589830dbdb7 | 1885 | /** |
vcoubard | 1184:1589830dbdb7 | 1886 | * The registered callback handler for scanned advertisement packet |
vcoubard | 1184:1589830dbdb7 | 1887 | * notifications. |
vcoubard | 1184:1589830dbdb7 | 1888 | */ |
vcoubard | 1132:692ddf04fc42 | 1889 | AdvertisementReportCallback_t onAdvertisementReport; |
vcoubard | 1184:1589830dbdb7 | 1890 | /** |
vcoubard | 1184:1589830dbdb7 | 1891 | * Callchain containing all registered callback handlers for connection |
vcoubard | 1184:1589830dbdb7 | 1892 | * events. |
vcoubard | 1184:1589830dbdb7 | 1893 | */ |
vcoubard | 1132:692ddf04fc42 | 1894 | ConnectionEventCallbackChain_t connectionCallChain; |
vcoubard | 1184:1589830dbdb7 | 1895 | /** |
vcoubard | 1184:1589830dbdb7 | 1896 | * Callchain containing all registered callback handlers for disconnection |
vcoubard | 1184:1589830dbdb7 | 1897 | * events. |
vcoubard | 1184:1589830dbdb7 | 1898 | */ |
vcoubard | 1132:692ddf04fc42 | 1899 | DisconnectionEventCallbackChain_t disconnectionCallChain; |
vcoubard | 1132:692ddf04fc42 | 1900 | |
vcoubard | 1132:692ddf04fc42 | 1901 | private: |
vcoubard | 1184:1589830dbdb7 | 1902 | /** |
vcoubard | 1184:1589830dbdb7 | 1903 | * Callchain containing all registered callback handlers for shutdown |
vcoubard | 1184:1589830dbdb7 | 1904 | * events. |
vcoubard | 1184:1589830dbdb7 | 1905 | */ |
vcoubard | 1136:22aada733dbd | 1906 | GapShutdownCallbackChain_t shutdownCallChain; |
vcoubard | 1136:22aada733dbd | 1907 | |
vcoubard | 1136:22aada733dbd | 1908 | private: |
vcoubard | 1132:692ddf04fc42 | 1909 | /* Disallow copy and assignment. */ |
vcoubard | 1132:692ddf04fc42 | 1910 | Gap(const Gap &); |
vcoubard | 1132:692ddf04fc42 | 1911 | Gap& operator=(const Gap &); |
vcoubard | 1132:692ddf04fc42 | 1912 | }; |
vcoubard | 1132:692ddf04fc42 | 1913 | |
rgrover1 | 710:b2e1a2660ec2 | 1914 | #endif // ifndef __GAP_H__ |