just a fork

Fork of BLE_API by Bluetooth Low Energy

Committer:
marfife
Date:
Fri Jul 08 23:39:31 2016 +0000
Revision:
1201:6dd8b141406e
Parent:
1193:c8bbf3a6712d
init

Who changed what in which revision?

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