Preliminary main mbed library for nexpaq development

Committer:
nexpaq
Date:
Fri Nov 04 20:54:50 2016 +0000
Revision:
1:d96dbedaebdb
Parent:
0:6c56fb4bc5f0
Removed extra directories for other platforms

Who changed what in which revision?

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