add "LE Device Address" 0x1B to advertising data types

Fork of BLE_API by Bluetooth Low Energy

Committer:
vcoubard
Date:
Mon Jan 11 08:52:05 2016 +0000
Revision:
1124:7ffed715734a
Parent:
1123:685c954464e1
Synchronized with git rev 0dd7f295
Author: Andres Amaya Garcia
Change return value of set.*PolicyMode() functions in Gap

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rgrover1 710:b2e1a2660ec2 1 /* mbed Microcontroller Library
rgrover1 710:b2e1a2660ec2 2 * Copyright (c) 2006-2013 ARM Limited
rgrover1 710:b2e1a2660ec2 3 *
rgrover1 710:b2e1a2660ec2 4 * Licensed under the Apache License, Version 2.0 (the "License");
rgrover1 710:b2e1a2660ec2 5 * you may not use this file except in compliance with the License.
rgrover1 710:b2e1a2660ec2 6 * You may obtain a copy of the License at
rgrover1 710:b2e1a2660ec2 7 *
rgrover1 710:b2e1a2660ec2 8 * http://www.apache.org/licenses/LICENSE-2.0
rgrover1 710:b2e1a2660ec2 9 *
rgrover1 710:b2e1a2660ec2 10 * Unless required by applicable law or agreed to in writing, software
rgrover1 710:b2e1a2660ec2 11 * distributed under the License is distributed on an "AS IS" BASIS,
rgrover1 710:b2e1a2660ec2 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
rgrover1 710:b2e1a2660ec2 13 * See the License for the specific language governing permissions and
rgrover1 710:b2e1a2660ec2 14 * limitations under the License.
rgrover1 710:b2e1a2660ec2 15 */
rgrover1 710:b2e1a2660ec2 16
rgrover1 710:b2e1a2660ec2 17 #ifndef __GAP_H__
rgrover1 710:b2e1a2660ec2 18 #define __GAP_H__
rgrover1 710:b2e1a2660ec2 19
vcoubard 1078:79c089630b38 20 #include "ble/BLEProtocol.h"
rgrover1 710:b2e1a2660ec2 21 #include "GapAdvertisingData.h"
rgrover1 710:b2e1a2660ec2 22 #include "GapAdvertisingParams.h"
rgrover1 710:b2e1a2660ec2 23 #include "GapScanningParams.h"
rgrover1 710:b2e1a2660ec2 24 #include "GapEvents.h"
rgrover1 829:9072de50087b 25 #include "CallChainOfFunctionPointersWithContext.h"
rgrover1 710:b2e1a2660ec2 26 #include "FunctionPointerWithContext.h"
vcoubard 1116:9cb51490b3f7 27 #include "deprecate.h"
rgrover1 710:b2e1a2660ec2 28
vcoubard 1048:efb29faf12fc 29 /* Forward declarations for classes that will only be used for pointers or references in the following. */
rgrover1 710:b2e1a2660ec2 30 class GapAdvertisingParams;
rgrover1 710:b2e1a2660ec2 31 class GapScanningParams;
rgrover1 710:b2e1a2660ec2 32 class GapAdvertisingData;
rgrover1 710:b2e1a2660ec2 33
rgrover1 710:b2e1a2660ec2 34 class Gap {
vcoubard 1078:79c089630b38 35 /*
vcoubard 1078:79c089630b38 36 * DEPRECATION ALERT: all of the APIs in this `public` block are deprecated.
vcoubard 1078:79c089630b38 37 * They have been relocated to the class BLEProtocol.
vcoubard 1078:79c089630b38 38 */
rgrover1 710:b2e1a2660ec2 39 public:
vcoubard 1078:79c089630b38 40 /**
vcoubard 1078:79c089630b38 41 * Address-type for BLEProtocol addresses.
vcoubard 1091:58b2dac13261 42 *
vcoubard 1086:75d4e8ce277d 43 * @note: deprecated. Use BLEProtocol::AddressType_t instead.
vcoubard 1078:79c089630b38 44 */
vcoubard 1086:75d4e8ce277d 45 typedef BLEProtocol::AddressType_t AddressType_t;
vcoubard 1086:75d4e8ce277d 46
vcoubard 1086:75d4e8ce277d 47 /**
vcoubard 1086:75d4e8ce277d 48 * Address-type for BLEProtocol addresses.
vcoubard 1086:75d4e8ce277d 49 * @note: deprecated. Use BLEProtocol::AddressType_t instead.
vcoubard 1087:4c6e11878033 50 */
vcoubard 1087:4c6e11878033 51 typedef BLEProtocol::AddressType_t addr_type_t;
vcoubard 1087:4c6e11878033 52
vcoubard 1091:58b2dac13261 53 /**
vcoubard 1091:58b2dac13261 54 * Address-type for BLEProtocol addresses.
vcoubard 1116:9cb51490b3f7 55 * \deprecated: Use BLEProtocol::AddressType_t instead.
vcoubard 1091:58b2dac13261 56 *
vcoubard 1091:58b2dac13261 57 * DEPRECATION ALERT: The following constants have been left in their
vcoubard 1091:58b2dac13261 58 * deprecated state to transparenly support existing applications which may
vcoubard 1091:58b2dac13261 59 * have used Gap::ADDR_TYPE_*.
vcoubard 1091:58b2dac13261 60 */
vcoubard 1116:9cb51490b3f7 61 enum DeprecatedAddressType_t {
vcoubard 1091:58b2dac13261 62 ADDR_TYPE_PUBLIC = BLEProtocol::AddressType::PUBLIC,
vcoubard 1091:58b2dac13261 63 ADDR_TYPE_RANDOM_STATIC = BLEProtocol::AddressType::RANDOM_STATIC,
vcoubard 1091:58b2dac13261 64 ADDR_TYPE_RANDOM_PRIVATE_RESOLVABLE = BLEProtocol::AddressType::RANDOM_PRIVATE_RESOLVABLE,
vcoubard 1091:58b2dac13261 65 ADDR_TYPE_RANDOM_PRIVATE_NON_RESOLVABLE = BLEProtocol::AddressType::RANDOM_PRIVATE_NON_RESOLVABLE
vcoubard 1091:58b2dac13261 66 };
vcoubard 1091:58b2dac13261 67
vcoubard 1078:79c089630b38 68 static const unsigned ADDR_LEN = BLEProtocol::ADDR_LEN; /**< Length (in octets) of the BLE MAC address. */
vcoubard 1119:7a487d506451 69 typedef BLEProtocol::AddressBytes_t Address_t; /**< 48-bit address, LSB format. @Note: Deprecated. Use BLEProtocol::AddressBytes_t instead. */
vcoubard 1119:7a487d506451 70 typedef BLEProtocol::AddressBytes_t address_t; /**< 48-bit address, LSB format. @Note: Deprecated. Use BLEProtocol::AddressBytes_t instead. */
vcoubard 1078:79c089630b38 71
vcoubard 1078:79c089630b38 72 public:
rgrover1 710:b2e1a2660ec2 73 enum TimeoutSource_t {
rgrover1 710:b2e1a2660ec2 74 TIMEOUT_SRC_ADVERTISING = 0x00, /**< Advertising timeout. */
rgrover1 710:b2e1a2660ec2 75 TIMEOUT_SRC_SECURITY_REQUEST = 0x01, /**< Security request timeout. */
rgrover1 710:b2e1a2660ec2 76 TIMEOUT_SRC_SCAN = 0x02, /**< Scanning timeout. */
rgrover1 710:b2e1a2660ec2 77 TIMEOUT_SRC_CONN = 0x03, /**< Connection timeout. */
rgrover1 710:b2e1a2660ec2 78 };
rgrover1 710:b2e1a2660ec2 79
rgrover1 710:b2e1a2660ec2 80 /**
rgrover1 710:b2e1a2660ec2 81 * Enumeration for disconnection reasons. The values for these reasons are
vcoubard 1048:efb29faf12fc 82 * derived from Nordic's implementation, but the reasons are meant to be
vcoubard 1048:efb29faf12fc 83 * independent of the transport. If you are returned a reason that is not
vcoubard 1048:efb29faf12fc 84 * covered by this enumeration, please refer to the underlying
rgrover1 710:b2e1a2660ec2 85 * transport library.
rgrover1 710:b2e1a2660ec2 86 */
rgrover1 710:b2e1a2660ec2 87 enum DisconnectionReason_t {
rgrover1 710:b2e1a2660ec2 88 CONNECTION_TIMEOUT = 0x08,
rgrover1 710:b2e1a2660ec2 89 REMOTE_USER_TERMINATED_CONNECTION = 0x13,
vcoubard 1048:efb29faf12fc 90 REMOTE_DEV_TERMINATION_DUE_TO_LOW_RESOURCES = 0x14, /**< Remote device terminated connection due to low resources.*/
vcoubard 1048:efb29faf12fc 91 REMOTE_DEV_TERMINATION_DUE_TO_POWER_OFF = 0x15, /**< Remote device terminated connection due to power off. */
rgrover1 710:b2e1a2660ec2 92 LOCAL_HOST_TERMINATED_CONNECTION = 0x16,
rgrover1 710:b2e1a2660ec2 93 CONN_INTERVAL_UNACCEPTABLE = 0x3B,
rgrover1 710:b2e1a2660ec2 94 };
rgrover1 710:b2e1a2660ec2 95
vcoubard 1118:88af68f0226b 96 /**
vcoubard 1118:88af68f0226b 97 * Enumeration for whitelist advertising policy filter modes. The possible
vcoubard 1118:88af68f0226b 98 * filter modes were obtained from the Bluetooth Core Specification
vcoubard 1118:88af68f0226b 99 * 4.2 (Vol. 6), Part B, Section 4.3.2.
vcoubard 1123:685c954464e1 100 *
vcoubard 1123:685c954464e1 101 * @experimental
vcoubard 1118:88af68f0226b 102 */
vcoubard 1118:88af68f0226b 103 enum AdvertisingPolicyMode_t {
vcoubard 1118:88af68f0226b 104 ADV_POLICY_IGNORE_WHITELIST = 0,
vcoubard 1118:88af68f0226b 105 ADV_POLICY_FILTER_SCAN_REQS = 1,
vcoubard 1118:88af68f0226b 106 ADV_POLICY_FILTER_CONN_REQS = 2,
vcoubard 1118:88af68f0226b 107 ADV_POLICY_FILTER_ALL_REQS = 3,
vcoubard 1118:88af68f0226b 108 };
vcoubard 1118:88af68f0226b 109
vcoubard 1118:88af68f0226b 110 /**
vcoubard 1118:88af68f0226b 111 * Enumeration for whitelist scanning policy filter modes. The possible
vcoubard 1118:88af68f0226b 112 * filter modes were obtained from the Bluetooth Core Specification
vcoubard 1118:88af68f0226b 113 * 4.2 (Vol. 6), Part B, Section 4.3.3.
vcoubard 1123:685c954464e1 114 *
vcoubard 1123:685c954464e1 115 * @experimental
vcoubard 1118:88af68f0226b 116 */
vcoubard 1118:88af68f0226b 117 enum ScanningPolicyMode_t {
vcoubard 1118:88af68f0226b 118 SCAN_POLICY_IGNORE_WHITELIST = 0,
vcoubard 1118:88af68f0226b 119 SCAN_POLICY_FILTER_ALL_ADV = 1,
vcoubard 1118:88af68f0226b 120 };
vcoubard 1118:88af68f0226b 121
vcoubard 1118:88af68f0226b 122 /**
vcoubard 1118:88af68f0226b 123 * Enumeration for the whitelist initiator policy fiter modes. The possible
vcoubard 1118:88af68f0226b 124 * filter modes were obtained from the Bluetooth Core Specification
vcoubard 1118:88af68f0226b 125 * 4.2 (vol. 6), Part B, Section 4.4.4.
vcoubard 1123:685c954464e1 126 *
vcoubard 1123:685c954464e1 127 * @experimental
vcoubard 1118:88af68f0226b 128 */
vcoubard 1118:88af68f0226b 129 enum InitiatorPolicyMode_t {
vcoubard 1118:88af68f0226b 130 INIT_POLICY_IGNORE_WHITELIST = 0,
vcoubard 1118:88af68f0226b 131 INIT_POLICY_FILTER_ALL_ADV = 1,
vcoubard 1118:88af68f0226b 132 };
vcoubard 1118:88af68f0226b 133
vcoubard 1123:685c954464e1 134 /**
vcoubard 1123:685c954464e1 135 * Representation of a Bluetooth Low Enery Whitelist containing addresses.
vcoubard 1123:685c954464e1 136 *
vcoubard 1123:685c954464e1 137 * @experimental
vcoubard 1123:685c954464e1 138 */
vcoubard 1118:88af68f0226b 139 struct Whitelist_t {
vcoubard 1118:88af68f0226b 140 BLEProtocol::Address_t *addresses;
vcoubard 1118:88af68f0226b 141 uint8_t size;
vcoubard 1122:57dcf7dc2fe8 142 uint8_t capacity;
vcoubard 1118:88af68f0226b 143 };
vcoubard 1118:88af68f0226b 144
vcoubard 1118:88af68f0226b 145
vcoubard 1048:efb29faf12fc 146 /* Describes the current state of the device (more than one bit can be set). */
rgrover1 710:b2e1a2660ec2 147 struct GapState_t {
vcoubard 1048:efb29faf12fc 148 unsigned advertising : 1; /**< Peripheral is currently advertising. */
vcoubard 1048:efb29faf12fc 149 unsigned connected : 1; /**< Peripheral is connected to a central. */
rgrover1 710:b2e1a2660ec2 150 };
rgrover1 710:b2e1a2660ec2 151
rgrover1 710:b2e1a2660ec2 152 typedef uint16_t Handle_t; /* Type for connection handle. */
rgrover1 710:b2e1a2660ec2 153
rgrover1 710:b2e1a2660ec2 154 typedef struct {
vcoubard 1119:7a487d506451 155 uint16_t minConnectionInterval; /**< Minimum Connection Interval in 1.25 ms units, see @ref BLE_GAP_CP_LIMITS.*/
vcoubard 1119:7a487d506451 156 uint16_t maxConnectionInterval; /**< Maximum Connection Interval in 1.25 ms units, see @ref BLE_GAP_CP_LIMITS.*/
vcoubard 1119:7a487d506451 157 uint16_t slaveLatency; /**< Slave Latency in number of connection events, see @ref BLE_GAP_CP_LIMITS.*/
rgrover1 710:b2e1a2660ec2 158 uint16_t connectionSupervisionTimeout; /**< Connection Supervision Timeout in 10 ms units, see @ref BLE_GAP_CP_LIMITS.*/
rgrover1 710:b2e1a2660ec2 159 } ConnectionParams_t;
rgrover1 710:b2e1a2660ec2 160
rgrover1 710:b2e1a2660ec2 161 enum Role_t {
rgrover1 710:b2e1a2660ec2 162 PERIPHERAL = 0x1, /**< Peripheral Role. */
rgrover1 710:b2e1a2660ec2 163 CENTRAL = 0x2, /**< Central Role. */
rgrover1 710:b2e1a2660ec2 164 };
rgrover1 710:b2e1a2660ec2 165
rgrover1 710:b2e1a2660ec2 166 struct AdvertisementCallbackParams_t {
vcoubard 1117:421bdb7c5711 167 BLEProtocol::AddressBytes_t peerAddr;
vcoubard 1079:6e2d9514f3df 168 int8_t rssi;
vcoubard 1079:6e2d9514f3df 169 bool isScanResponse;
vcoubard 1079:6e2d9514f3df 170 GapAdvertisingParams::AdvertisingType_t type;
vcoubard 1079:6e2d9514f3df 171 uint8_t advertisingDataLen;
vcoubard 1079:6e2d9514f3df 172 const uint8_t *advertisingData;
rgrover1 710:b2e1a2660ec2 173 };
rgrover1 710:b2e1a2660ec2 174 typedef FunctionPointerWithContext<const AdvertisementCallbackParams_t *> AdvertisementReportCallback_t;
rgrover1 710:b2e1a2660ec2 175
rgrover1 710:b2e1a2660ec2 176 struct ConnectionCallbackParams_t {
vcoubard 1078:79c089630b38 177 Handle_t handle;
vcoubard 1078:79c089630b38 178 Role_t role;
vcoubard 1078:79c089630b38 179 BLEProtocol::AddressType_t peerAddrType;
vcoubard 1119:7a487d506451 180 BLEProtocol::AddressBytes_t peerAddr;
vcoubard 1078:79c089630b38 181 BLEProtocol::AddressType_t ownAddrType;
vcoubard 1119:7a487d506451 182 BLEProtocol::AddressBytes_t ownAddr;
vcoubard 1078:79c089630b38 183 const ConnectionParams_t *connectionParams;
rgrover1 710:b2e1a2660ec2 184
vcoubard 1078:79c089630b38 185 ConnectionCallbackParams_t(Handle_t handleIn,
vcoubard 1078:79c089630b38 186 Role_t roleIn,
vcoubard 1078:79c089630b38 187 BLEProtocol::AddressType_t peerAddrTypeIn,
vcoubard 1078:79c089630b38 188 const uint8_t *peerAddrIn,
vcoubard 1078:79c089630b38 189 BLEProtocol::AddressType_t ownAddrTypeIn,
vcoubard 1078:79c089630b38 190 const uint8_t *ownAddrIn,
vcoubard 1078:79c089630b38 191 const ConnectionParams_t *connectionParamsIn) :
rgrover1 710:b2e1a2660ec2 192 handle(handleIn),
rgrover1 710:b2e1a2660ec2 193 role(roleIn),
rgrover1 710:b2e1a2660ec2 194 peerAddrType(peerAddrTypeIn),
rgrover1 710:b2e1a2660ec2 195 peerAddr(),
rgrover1 710:b2e1a2660ec2 196 ownAddrType(ownAddrTypeIn),
rgrover1 710:b2e1a2660ec2 197 ownAddr(),
rgrover1 710:b2e1a2660ec2 198 connectionParams(connectionParamsIn) {
rgrover1 710:b2e1a2660ec2 199 memcpy(peerAddr, peerAddrIn, ADDR_LEN);
rgrover1 710:b2e1a2660ec2 200 memcpy(ownAddr, ownAddrIn, ADDR_LEN);
rgrover1 710:b2e1a2660ec2 201 }
rgrover1 710:b2e1a2660ec2 202 };
rgrover1 710:b2e1a2660ec2 203
rgrover1 829:9072de50087b 204 struct DisconnectionCallbackParams_t {
rgrover1 829:9072de50087b 205 Handle_t handle;
rgrover1 829:9072de50087b 206 DisconnectionReason_t reason;
rgrover1 829:9072de50087b 207
rgrover1 829:9072de50087b 208 DisconnectionCallbackParams_t(Handle_t handleIn,
rgrover1 829:9072de50087b 209 DisconnectionReason_t reasonIn) :
rgrover1 829:9072de50087b 210 handle(handleIn),
rgrover1 829:9072de50087b 211 reason(reasonIn)
rgrover1 829:9072de50087b 212 {}
rgrover1 829:9072de50087b 213 };
rgrover1 829:9072de50087b 214
rgrover1 710:b2e1a2660ec2 215 static const uint16_t UNIT_1_25_MS = 1250; /**< Number of microseconds in 1.25 milliseconds. */
rgrover1 710:b2e1a2660ec2 216 static uint16_t MSEC_TO_GAP_DURATION_UNITS(uint32_t durationInMillis) {
rgrover1 710:b2e1a2660ec2 217 return (durationInMillis * 1000) / UNIT_1_25_MS;
rgrover1 710:b2e1a2660ec2 218 }
rgrover1 766:03f1a26f132f 219
vcoubard 1052:b55e1ad3e1b3 220 typedef FunctionPointerWithContext<TimeoutSource_t> TimeoutEventCallback_t;
vcoubard 1052:b55e1ad3e1b3 221 typedef CallChainOfFunctionPointersWithContext<TimeoutSource_t> TimeoutEventCallbackChain_t;
rgrover1 710:b2e1a2660ec2 222
vcoubard 1052:b55e1ad3e1b3 223 typedef FunctionPointerWithContext<const ConnectionCallbackParams_t *> ConnectionEventCallback_t;
vcoubard 1052:b55e1ad3e1b3 224 typedef CallChainOfFunctionPointersWithContext<const ConnectionCallbackParams_t *> ConnectionEventCallbackChain_t;
vcoubard 1052:b55e1ad3e1b3 225
vcoubard 1052:b55e1ad3e1b3 226 typedef FunctionPointerWithContext<const DisconnectionCallbackParams_t*> DisconnectionEventCallback_t;
vcoubard 1054:f59e5d9a992a 227 typedef CallChainOfFunctionPointersWithContext<const DisconnectionCallbackParams_t*> DisconnectionEventCallbackChain_t;
vcoubard 1052:b55e1ad3e1b3 228
rgrover1 753:0f60274cd3ad 229 typedef FunctionPointerWithContext<bool> RadioNotificationEventCallback_t;
rgrover1 710:b2e1a2660ec2 230
vcoubard 1090:148d8b9b56a5 231 typedef FunctionPointerWithContext<const Gap *> GapShutdownCallback_t;
vcoubard 1090:148d8b9b56a5 232 typedef CallChainOfFunctionPointersWithContext<const Gap *> GapShutdownCallbackChain_t;
vcoubard 1090:148d8b9b56a5 233
rgrover1 710:b2e1a2660ec2 234 /*
rgrover1 710:b2e1a2660ec2 235 * The following functions are meant to be overridden in the platform-specific sub-class.
rgrover1 710:b2e1a2660ec2 236 */
rgrover1 710:b2e1a2660ec2 237 public:
rgrover1 710:b2e1a2660ec2 238 /**
rgrover1 710:b2e1a2660ec2 239 * Set the BTLE MAC address and type. Please note that the address format is
vcoubard 1119:7a487d506451 240 * least significant byte first (LSB). Please refer to BLEProtocol::AddressBytes_t.
rgrover1 710:b2e1a2660ec2 241 *
rgrover1 710:b2e1a2660ec2 242 * @return BLE_ERROR_NONE on success.
rgrover1 710:b2e1a2660ec2 243 */
vcoubard 1115:82d4a8a56d91 244 virtual ble_error_t setAddress(BLEProtocol::AddressType_t type, const BLEProtocol::AddressBytes_t address) {
rgrover1 734:4872b70437ce 245 /* avoid compiler warnings about unused variables */
rgrover1 734:4872b70437ce 246 (void)type;
rgrover1 734:4872b70437ce 247 (void)address;
rgrover1 734:4872b70437ce 248
rgrover1 728:997ba5e7b3b6 249 return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */
rgrover1 710:b2e1a2660ec2 250 }
rgrover1 710:b2e1a2660ec2 251
rgrover1 710:b2e1a2660ec2 252 /**
rgrover1 710:b2e1a2660ec2 253 * Fetch the BTLE MAC address and type.
rgrover1 710:b2e1a2660ec2 254 *
rgrover1 710:b2e1a2660ec2 255 * @return BLE_ERROR_NONE on success.
rgrover1 710:b2e1a2660ec2 256 */
vcoubard 1115:82d4a8a56d91 257 virtual ble_error_t getAddress(BLEProtocol::AddressType_t *typeP, BLEProtocol::AddressBytes_t address) {
vcoubard 1048:efb29faf12fc 258 /* Avoid compiler warnings about unused variables. */
rgrover1 734:4872b70437ce 259 (void)typeP;
rgrover1 734:4872b70437ce 260 (void)address;
rgrover1 734:4872b70437ce 261
rgrover1 728:997ba5e7b3b6 262 return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */
rgrover1 710:b2e1a2660ec2 263 }
rgrover1 710:b2e1a2660ec2 264
rgrover1 710:b2e1a2660ec2 265 /**
vcoubard 1056:ce2fb3d09929 266 * @return Minimum Advertising interval in milliseconds for connectable
vcoubard 1056:ce2fb3d09929 267 * undirected and connectable directed event types.
rgrover1 710:b2e1a2660ec2 268 */
rgrover1 710:b2e1a2660ec2 269 virtual uint16_t getMinAdvertisingInterval(void) const {
rgrover1 742:861ed7eb186d 270 return 0; /* Requesting action from porter(s): override this API if this capability is supported. */
rgrover1 710:b2e1a2660ec2 271 }
rgrover1 710:b2e1a2660ec2 272
rgrover1 710:b2e1a2660ec2 273 /**
vcoubard 1056:ce2fb3d09929 274 * @return Minimum Advertising interval in milliseconds for scannable
vcoubard 1056:ce2fb3d09929 275 * undirected and non-connectable undirected event types.
rgrover1 710:b2e1a2660ec2 276 */
rgrover1 710:b2e1a2660ec2 277 virtual uint16_t getMinNonConnectableAdvertisingInterval(void) const {
rgrover1 742:861ed7eb186d 278 return 0; /* Requesting action from porter(s): override this API if this capability is supported. */
rgrover1 710:b2e1a2660ec2 279 }
rgrover1 710:b2e1a2660ec2 280
rgrover1 710:b2e1a2660ec2 281 /**
rgrover1 710:b2e1a2660ec2 282 * @return Maximum Advertising interval in milliseconds.
rgrover1 710:b2e1a2660ec2 283 */
rgrover1 710:b2e1a2660ec2 284 virtual uint16_t getMaxAdvertisingInterval(void) const {
rgrover1 742:861ed7eb186d 285 return 0xFFFF; /* Requesting action from porter(s): override this API if this capability is supported. */
rgrover1 710:b2e1a2660ec2 286 }
rgrover1 710:b2e1a2660ec2 287
rgrover1 710:b2e1a2660ec2 288 virtual ble_error_t stopAdvertising(void) {
rgrover1 728:997ba5e7b3b6 289 return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */
rgrover1 710:b2e1a2660ec2 290 }
rgrover1 710:b2e1a2660ec2 291
rgrover1 710:b2e1a2660ec2 292 /**
rgrover1 710:b2e1a2660ec2 293 * Stop scanning. The current scanning parameters remain in effect.
rgrover1 710:b2e1a2660ec2 294 *
rgrover1 710:b2e1a2660ec2 295 * @retval BLE_ERROR_NONE if successfully stopped scanning procedure.
rgrover1 710:b2e1a2660ec2 296 */
rgrover1 710:b2e1a2660ec2 297 virtual ble_error_t stopScan() {
rgrover1 728:997ba5e7b3b6 298 return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */
rgrover1 710:b2e1a2660ec2 299 }
rgrover1 710:b2e1a2660ec2 300
rgrover1 710:b2e1a2660ec2 301 /**
rgrover1 710:b2e1a2660ec2 302 * Create a connection (GAP Link Establishment).
rgrover1 710:b2e1a2660ec2 303 *
rgrover1 710:b2e1a2660ec2 304 * @param peerAddr
rgrover1 710:b2e1a2660ec2 305 * 48-bit address, LSB format.
rgrover1 710:b2e1a2660ec2 306 * @param peerAddrType
rgrover1 710:b2e1a2660ec2 307 * Address type of the peer.
rgrover1 710:b2e1a2660ec2 308 * @param connectionParams
rgrover1 710:b2e1a2660ec2 309 * Connection parameters.
rgrover1 710:b2e1a2660ec2 310 * @param scanParams
rgrover1 710:b2e1a2660ec2 311 * Paramters to be used while scanning for the peer.
rgrover1 710:b2e1a2660ec2 312 * @return BLE_ERROR_NONE if connection establishment procedure is started
rgrover1 829:9072de50087b 313 * successfully. The connectionCallChain (if set) will be invoked upon
rgrover1 710:b2e1a2660ec2 314 * a connection event.
rgrover1 710:b2e1a2660ec2 315 */
vcoubard 1115:82d4a8a56d91 316 virtual ble_error_t connect(const BLEProtocol::AddressBytes_t peerAddr,
vcoubard 1117:421bdb7c5711 317 BLEProtocol::AddressType_t peerAddrType,
vcoubard 1117:421bdb7c5711 318 const ConnectionParams_t *connectionParams,
vcoubard 1117:421bdb7c5711 319 const GapScanningParams *scanParams) {
vcoubard 1048:efb29faf12fc 320 /* Avoid compiler warnings about unused variables. */
rgrover1 734:4872b70437ce 321 (void)peerAddr;
rgrover1 734:4872b70437ce 322 (void)peerAddrType;
rgrover1 734:4872b70437ce 323 (void)connectionParams;
rgrover1 734:4872b70437ce 324 (void)scanParams;
rgrover1 734:4872b70437ce 325
rgrover1 728:997ba5e7b3b6 326 return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */
rgrover1 710:b2e1a2660ec2 327 }
rgrover1 710:b2e1a2660ec2 328
rgrover1 710:b2e1a2660ec2 329 /**
vcoubard 1116:9cb51490b3f7 330 * Create a connection (GAP Link Establishment).
vcoubard 1116:9cb51490b3f7 331 *
vcoubard 1116:9cb51490b3f7 332 * \deprecated: This funtion overloads Gap::connect(const BLEProtocol::Address_t peerAddr,
vcoubard 1116:9cb51490b3f7 333 BLEProtocol::AddressType_t peerAddrType,
vcoubard 1116:9cb51490b3f7 334 const ConnectionParams_t *connectionParams,
vcoubard 1116:9cb51490b3f7 335 const GapScanningParams *scanParams)
vcoubard 1116:9cb51490b3f7 336 * to maintain backward compatibility for change from Gap::AddressType_t to BLEProtocol::AddressType_t
vcoubard 1116:9cb51490b3f7 337 */
vcoubard 1117:421bdb7c5711 338 ble_error_t connect(const BLEProtocol::AddressBytes_t peerAddr,
vcoubard 1117:421bdb7c5711 339 DeprecatedAddressType_t peerAddrType,
vcoubard 1117:421bdb7c5711 340 const ConnectionParams_t *connectionParams,
vcoubard 1117:421bdb7c5711 341 const GapScanningParams *scanParams)
vcoubard 1116:9cb51490b3f7 342 __deprecated_message("Gap::DeprecatedAddressType_t is deprecated, use BLEProtocol::AddressType_t instead") {
vcoubard 1116:9cb51490b3f7 343 return connect(peerAddr, (BLEProtocol::AddressType_t) peerAddrType, connectionParams, scanParams);
vcoubard 1116:9cb51490b3f7 344 }
vcoubard 1116:9cb51490b3f7 345
vcoubard 1116:9cb51490b3f7 346 /**
rgrover1 710:b2e1a2660ec2 347 * This call initiates the disconnection procedure, and its completion will
rgrover1 710:b2e1a2660ec2 348 * be communicated to the application with an invocation of the
rgrover1 710:b2e1a2660ec2 349 * disconnectionCallback.
rgrover1 710:b2e1a2660ec2 350 *
rgrover1 710:b2e1a2660ec2 351 * @param reason
vcoubard 1048:efb29faf12fc 352 * The reason for disconnection; to be sent back to the peer.
rgrover1 710:b2e1a2660ec2 353 */
rgrover1 710:b2e1a2660ec2 354 virtual ble_error_t disconnect(Handle_t connectionHandle, DisconnectionReason_t reason) {
rgrover1 734:4872b70437ce 355 /* avoid compiler warnings about unused variables */
rgrover1 734:4872b70437ce 356 (void)connectionHandle;
rgrover1 734:4872b70437ce 357 (void)reason;
rgrover1 734:4872b70437ce 358
rgrover1 728:997ba5e7b3b6 359 return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */
rgrover1 710:b2e1a2660ec2 360 }
rgrover1 710:b2e1a2660ec2 361
rgrover1 710:b2e1a2660ec2 362 /**
rgrover1 710:b2e1a2660ec2 363 * This call initiates the disconnection procedure, and its completion will
rgrover1 710:b2e1a2660ec2 364 * be communicated to the application with an invocation of the
rgrover1 710:b2e1a2660ec2 365 * disconnectionCallback.
rgrover1 710:b2e1a2660ec2 366 *
rgrover1 710:b2e1a2660ec2 367 * @param reason
vcoubard 1048:efb29faf12fc 368 * The reason for disconnection; to be sent back to the peer.
rgrover1 710:b2e1a2660ec2 369 *
vcoubard 1048:efb29faf12fc 370 * @note: This version of disconnect() doesn't take a connection handle. It
vcoubard 1048:efb29faf12fc 371 * works reliably only for stacks that are limited to a single
rgrover1 710:b2e1a2660ec2 372 * connection. This API should be considered *deprecated* in favour of the
vcoubard 1048:efb29faf12fc 373 * alternative, which takes a connection handle. It will be dropped in the future.
rgrover1 710:b2e1a2660ec2 374 */
rgrover1 710:b2e1a2660ec2 375 virtual ble_error_t disconnect(DisconnectionReason_t reason) {
vcoubard 1048:efb29faf12fc 376 /* Avoid compiler warnings about unused variables. */
rgrover1 734:4872b70437ce 377 (void)reason;
rgrover1 734:4872b70437ce 378
rgrover1 728:997ba5e7b3b6 379 return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */
rgrover1 710:b2e1a2660ec2 380 }
rgrover1 710:b2e1a2660ec2 381
rgrover1 710:b2e1a2660ec2 382 /**
rgrover1 710:b2e1a2660ec2 383 * Get the GAP peripheral preferred connection parameters. These are the
rgrover1 710:b2e1a2660ec2 384 * defaults that the peripheral would like to have in a connection. The
rgrover1 710:b2e1a2660ec2 385 * choice of the connection parameters is eventually up to the central.
rgrover1 710:b2e1a2660ec2 386 *
rgrover1 710:b2e1a2660ec2 387 * @param[out] params
rgrover1 710:b2e1a2660ec2 388 * The structure where the parameters will be stored. Memory
rgrover1 710:b2e1a2660ec2 389 * for this is owned by the caller.
rgrover1 710:b2e1a2660ec2 390 *
rgrover1 710:b2e1a2660ec2 391 * @return BLE_ERROR_NONE if the parameters were successfully filled into
rgrover1 710:b2e1a2660ec2 392 * the given structure pointed to by params.
rgrover1 710:b2e1a2660ec2 393 */
rgrover1 710:b2e1a2660ec2 394 virtual ble_error_t getPreferredConnectionParams(ConnectionParams_t *params) {
vcoubard 1048:efb29faf12fc 395 /* Avoid compiler warnings about unused variables. */
rgrover1 734:4872b70437ce 396 (void)params;
rgrover1 734:4872b70437ce 397
rgrover1 728:997ba5e7b3b6 398 return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */
rgrover1 710:b2e1a2660ec2 399 }
rgrover1 710:b2e1a2660ec2 400
rgrover1 710:b2e1a2660ec2 401 /**
rgrover1 710:b2e1a2660ec2 402 * Set the GAP peripheral preferred connection parameters. These are the
rgrover1 710:b2e1a2660ec2 403 * defaults that the peripheral would like to have in a connection. The
rgrover1 710:b2e1a2660ec2 404 * choice of the connection parameters is eventually up to the central.
rgrover1 710:b2e1a2660ec2 405 *
rgrover1 710:b2e1a2660ec2 406 * @param[in] params
rgrover1 710:b2e1a2660ec2 407 * The structure containing the desired parameters.
rgrover1 710:b2e1a2660ec2 408 */
rgrover1 710:b2e1a2660ec2 409 virtual ble_error_t setPreferredConnectionParams(const ConnectionParams_t *params) {
vcoubard 1048:efb29faf12fc 410 /* Avoid compiler warnings about unused variables. */
rgrover1 734:4872b70437ce 411 (void)params;
rgrover1 734:4872b70437ce 412
rgrover1 728:997ba5e7b3b6 413 return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */
rgrover1 710:b2e1a2660ec2 414 }
rgrover1 710:b2e1a2660ec2 415
rgrover1 710:b2e1a2660ec2 416 /**
rgrover1 816:2b4f0ef8c06e 417 * Update connection parameters.
vcoubard 1048:efb29faf12fc 418 * In the central role this will initiate a Link Layer connection parameter update procedure.
vcoubard 1048:efb29faf12fc 419 * In the peripheral role, this will send the corresponding L2CAP request and wait for
rgrover1 816:2b4f0ef8c06e 420 * the central to perform the procedure.
rgrover1 816:2b4f0ef8c06e 421 *
rgrover1 710:b2e1a2660ec2 422 * @param[in] handle
vcoubard 1048:efb29faf12fc 423 * Connection Handle.
rgrover1 710:b2e1a2660ec2 424 * @param[in] params
rgrover1 710:b2e1a2660ec2 425 * Pointer to desired connection parameters. If NULL is provided on a peripheral role,
rgrover1 710:b2e1a2660ec2 426 * the parameters in the PPCP characteristic of the GAP service will be used instead.
rgrover1 710:b2e1a2660ec2 427 */
rgrover1 710:b2e1a2660ec2 428 virtual ble_error_t updateConnectionParams(Handle_t handle, const ConnectionParams_t *params) {
rgrover1 734:4872b70437ce 429 /* avoid compiler warnings about unused variables */
rgrover1 734:4872b70437ce 430 (void)handle;
rgrover1 734:4872b70437ce 431 (void)params;
rgrover1 734:4872b70437ce 432
rgrover1 728:997ba5e7b3b6 433 return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */
rgrover1 710:b2e1a2660ec2 434 }
rgrover1 710:b2e1a2660ec2 435
rgrover1 710:b2e1a2660ec2 436 /**
rgrover1 710:b2e1a2660ec2 437 * Set the device name characteristic in the GAP service.
rgrover1 710:b2e1a2660ec2 438 * @param[in] deviceName
rgrover1 710:b2e1a2660ec2 439 * The new value for the device-name. This is a UTF-8 encoded, <b>NULL-terminated</b> string.
rgrover1 710:b2e1a2660ec2 440 */
rgrover1 710:b2e1a2660ec2 441 virtual ble_error_t setDeviceName(const uint8_t *deviceName) {
vcoubard 1048:efb29faf12fc 442 /* Avoid compiler warnings about unused variables. */
rgrover1 734:4872b70437ce 443 (void)deviceName;
rgrover1 734:4872b70437ce 444
rgrover1 728:997ba5e7b3b6 445 return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */
rgrover1 710:b2e1a2660ec2 446 }
rgrover1 710:b2e1a2660ec2 447
rgrover1 710:b2e1a2660ec2 448 /**
rgrover1 710:b2e1a2660ec2 449 * Get the value of the device name characteristic in the GAP service.
rgrover1 710:b2e1a2660ec2 450 * @param[out] deviceName
rgrover1 710:b2e1a2660ec2 451 * Pointer to an empty buffer where the UTF-8 *non NULL-
rgrover1 710:b2e1a2660ec2 452 * terminated* string will be placed. Set this
rgrover1 710:b2e1a2660ec2 453 * value to NULL in order to obtain the deviceName-length
rgrover1 710:b2e1a2660ec2 454 * from the 'length' parameter.
rgrover1 710:b2e1a2660ec2 455 *
rgrover1 710:b2e1a2660ec2 456 * @param[in/out] lengthP
rgrover1 710:b2e1a2660ec2 457 * (on input) Length of the buffer pointed to by deviceName;
rgrover1 710:b2e1a2660ec2 458 * (on output) the complete device name length (without the
rgrover1 710:b2e1a2660ec2 459 * null terminator).
rgrover1 710:b2e1a2660ec2 460 *
rgrover1 710:b2e1a2660ec2 461 * @note If the device name is longer than the size of the supplied buffer,
rgrover1 710:b2e1a2660ec2 462 * length will return the complete device name length, and not the
rgrover1 710:b2e1a2660ec2 463 * number of bytes actually returned in deviceName. The application may
rgrover1 710:b2e1a2660ec2 464 * use this information to retry with a suitable buffer size.
rgrover1 710:b2e1a2660ec2 465 */
rgrover1 710:b2e1a2660ec2 466 virtual ble_error_t getDeviceName(uint8_t *deviceName, unsigned *lengthP) {
rgrover1 734:4872b70437ce 467 /* avoid compiler warnings about unused variables */
rgrover1 734:4872b70437ce 468 (void)deviceName;
rgrover1 734:4872b70437ce 469 (void)lengthP;
rgrover1 734:4872b70437ce 470
rgrover1 728:997ba5e7b3b6 471 return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */
rgrover1 710:b2e1a2660ec2 472 }
rgrover1 710:b2e1a2660ec2 473
rgrover1 710:b2e1a2660ec2 474 /**
rgrover1 710:b2e1a2660ec2 475 * Set the appearance characteristic in the GAP service.
rgrover1 710:b2e1a2660ec2 476 * @param[in] appearance
rgrover1 710:b2e1a2660ec2 477 * The new value for the device-appearance.
rgrover1 710:b2e1a2660ec2 478 */
rgrover1 710:b2e1a2660ec2 479 virtual ble_error_t setAppearance(GapAdvertisingData::Appearance appearance) {
vcoubard 1048:efb29faf12fc 480 /* Avoid compiler warnings about unused variables. */
rgrover1 734:4872b70437ce 481 (void)appearance;
rgrover1 734:4872b70437ce 482
rgrover1 728:997ba5e7b3b6 483 return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */
rgrover1 710:b2e1a2660ec2 484 }
rgrover1 710:b2e1a2660ec2 485
rgrover1 710:b2e1a2660ec2 486 /**
rgrover1 710:b2e1a2660ec2 487 * Get the appearance characteristic in the GAP service.
rgrover1 710:b2e1a2660ec2 488 * @param[out] appearance
rgrover1 710:b2e1a2660ec2 489 * The new value for the device-appearance.
rgrover1 710:b2e1a2660ec2 490 */
rgrover1 710:b2e1a2660ec2 491 virtual ble_error_t getAppearance(GapAdvertisingData::Appearance *appearanceP) {
vcoubard 1048:efb29faf12fc 492 /* Avoid compiler warnings about unused variables. */
rgrover1 734:4872b70437ce 493 (void)appearanceP;
rgrover1 734:4872b70437ce 494
rgrover1 728:997ba5e7b3b6 495 return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */
rgrover1 710:b2e1a2660ec2 496 }
rgrover1 710:b2e1a2660ec2 497
rgrover1 710:b2e1a2660ec2 498 /**
rgrover1 710:b2e1a2660ec2 499 * Set the radio's transmit power.
rgrover1 710:b2e1a2660ec2 500 * @param[in] txPower Radio transmit power in dBm.
rgrover1 710:b2e1a2660ec2 501 */
rgrover1 710:b2e1a2660ec2 502 virtual ble_error_t setTxPower(int8_t txPower) {
vcoubard 1048:efb29faf12fc 503 /* Avoid compiler warnings about unused variables. */
rgrover1 734:4872b70437ce 504 (void)txPower;
rgrover1 734:4872b70437ce 505
rgrover1 728:997ba5e7b3b6 506 return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */
rgrover1 710:b2e1a2660ec2 507 }
rgrover1 710:b2e1a2660ec2 508
rgrover1 710:b2e1a2660ec2 509 /**
rgrover1 710:b2e1a2660ec2 510 * Query the underlying stack for permitted arguments for setTxPower().
rgrover1 710:b2e1a2660ec2 511 *
rgrover1 710:b2e1a2660ec2 512 * @param[out] valueArrayPP
rgrover1 710:b2e1a2660ec2 513 * Out parameter to receive the immutable array of Tx values.
rgrover1 710:b2e1a2660ec2 514 * @param[out] countP
rgrover1 710:b2e1a2660ec2 515 * Out parameter to receive the array's size.
rgrover1 710:b2e1a2660ec2 516 */
rgrover1 710:b2e1a2660ec2 517 virtual void getPermittedTxPowerValues(const int8_t **valueArrayPP, size_t *countP) {
vcoubard 1048:efb29faf12fc 518 /* Avoid compiler warnings about unused variables. */
rgrover1 734:4872b70437ce 519 (void)valueArrayPP;
rgrover1 734:4872b70437ce 520 (void)countP;
rgrover1 734:4872b70437ce 521
rgrover1 742:861ed7eb186d 522 *countP = 0; /* Requesting action from porter(s): override this API if this capability is supported. */
rgrover1 710:b2e1a2660ec2 523 }
rgrover1 710:b2e1a2660ec2 524
vcoubard 1118:88af68f0226b 525 /**
vcoubard 1118:88af68f0226b 526 * @return Maximum size of the whitelist.
vcoubard 1123:685c954464e1 527 *
vcoubard 1123:685c954464e1 528 * @experimental
vcoubard 1118:88af68f0226b 529 */
vcoubard 1118:88af68f0226b 530 virtual uint8_t getMaxWhitelistSize(void) const
vcoubard 1118:88af68f0226b 531 {
vcoubard 1121:df91547290be 532 return 0;
vcoubard 1118:88af68f0226b 533 }
vcoubard 1118:88af68f0226b 534
vcoubard 1118:88af68f0226b 535 /**
vcoubard 1118:88af68f0226b 536 * Get the internal whitelist to be used by the Link Layer when scanning,
vcoubard 1118:88af68f0226b 537 * advertising or initiating a connection depending on the filter policies.
vcoubard 1118:88af68f0226b 538 *
vcoubard 1118:88af68f0226b 539 * @param[in/out] whitelist
vcoubard 1122:57dcf7dc2fe8 540 * (on input) whitelist.capacity contains the maximum number
vcoubard 1118:88af68f0226b 541 * of addresses to be returned.
vcoubard 1118:88af68f0226b 542 * (on output) The populated whitelist with copies of the
vcoubard 1118:88af68f0226b 543 * addresses in the implementation's whitelist.
vcoubard 1118:88af68f0226b 544 *
vcoubard 1118:88af68f0226b 545 * @return BLE_ERROR_NONE if the implementation's whitelist was successfully
vcoubard 1118:88af68f0226b 546 * copied into the supplied reference.
vcoubard 1123:685c954464e1 547 *
vcoubard 1123:685c954464e1 548 * @experimental
vcoubard 1118:88af68f0226b 549 */
vcoubard 1118:88af68f0226b 550 virtual ble_error_t getWhitelist(Whitelist_t &whitelist) const
vcoubard 1118:88af68f0226b 551 {
vcoubard 1118:88af68f0226b 552 (void) whitelist;
vcoubard 1118:88af68f0226b 553 return BLE_ERROR_NOT_IMPLEMENTED;
vcoubard 1118:88af68f0226b 554 }
vcoubard 1118:88af68f0226b 555
vcoubard 1118:88af68f0226b 556 /**
vcoubard 1118:88af68f0226b 557 * Set the internal whitelist to be used by the Link Layer when scanning,
vcoubard 1118:88af68f0226b 558 * advertising or initiating a connection depending on the filter policies.
vcoubard 1118:88af68f0226b 559 *
vcoubard 1121:df91547290be 560 * @param[in] whitelist
vcoubard 1118:88af68f0226b 561 * A reference to a whitelist containing the addresses to
vcoubard 1118:88af68f0226b 562 * be added to the internal whitelist.
vcoubard 1118:88af68f0226b 563 *
vcoubard 1118:88af68f0226b 564 * @return BLE_ERROR_NONE if the implementation's whitelist was successfully
vcoubard 1118:88af68f0226b 565 * populated with the addresses in the given whitelist.
vcoubard 1118:88af68f0226b 566 *
vcoubard 1118:88af68f0226b 567 * @note The whitelist must not contain addresses of type @ref
vcoubard 1118:88af68f0226b 568 * BLEProtocol::AddressType_t::RANDOM_PRIVATE_NON_RESOLVABLE, this
vcoubard 1118:88af68f0226b 569 * this will result in a @ref BLE_ERROR_INVALID_PARAM since the
vcoubard 1118:88af68f0226b 570 * remote peer might change its private address at any time and it
vcoubard 1118:88af68f0226b 571 * is not possible to resolve it.
vcoubard 1118:88af68f0226b 572 * @note If the input whitelist is larger than @ref getMaxWhitelistSize()
vcoubard 1118:88af68f0226b 573 * the @ref BLE_ERROR_PARAM_OUT_OF_RANGE is returned.
vcoubard 1123:685c954464e1 574 *
vcoubard 1123:685c954464e1 575 * @experimental
vcoubard 1118:88af68f0226b 576 */
vcoubard 1121:df91547290be 577 virtual ble_error_t setWhitelist(const Whitelist_t &whitelist)
vcoubard 1118:88af68f0226b 578 {
vcoubard 1118:88af68f0226b 579 (void) whitelist;
vcoubard 1118:88af68f0226b 580 return BLE_ERROR_NOT_IMPLEMENTED;
vcoubard 1118:88af68f0226b 581 }
vcoubard 1118:88af68f0226b 582
vcoubard 1118:88af68f0226b 583 /**
vcoubard 1118:88af68f0226b 584 * Set the advertising policy filter mode to be used in the next call
vcoubard 1118:88af68f0226b 585 * to startAdvertising().
vcoubard 1118:88af68f0226b 586 *
vcoubard 1118:88af68f0226b 587 * @param[in] mode
vcoubard 1118:88af68f0226b 588 * The new advertising policy filter mode.
vcoubard 1123:685c954464e1 589 *
vcoubard 1124:7ffed715734a 590 * @return BLE_ERROR_NONE if the specified policy filter mode was set
vcoubard 1124:7ffed715734a 591 * successfully.
vcoubard 1124:7ffed715734a 592 *
vcoubard 1123:685c954464e1 593 * @experimental
vcoubard 1118:88af68f0226b 594 */
vcoubard 1124:7ffed715734a 595 virtual ble_error_t setAdvertisingPolicyMode(AdvertisingPolicyMode_t mode)
vcoubard 1118:88af68f0226b 596 {
vcoubard 1118:88af68f0226b 597 (void) mode;
vcoubard 1124:7ffed715734a 598 return BLE_ERROR_NOT_IMPLEMENTED;
vcoubard 1118:88af68f0226b 599 }
vcoubard 1118:88af68f0226b 600
vcoubard 1118:88af68f0226b 601 /**
vcoubard 1118:88af68f0226b 602 * Set the scan policy filter mode to be used in the next call
vcoubard 1118:88af68f0226b 603 * to startScan().
vcoubard 1118:88af68f0226b 604 *
vcoubard 1118:88af68f0226b 605 * @param[in] mode
vcoubard 1118:88af68f0226b 606 * The new scan policy filter mode.
vcoubard 1123:685c954464e1 607 *
vcoubard 1124:7ffed715734a 608 * @return BLE_ERROR_NONE if the specified policy filter mode was set
vcoubard 1124:7ffed715734a 609 * successfully.
vcoubard 1124:7ffed715734a 610 *
vcoubard 1123:685c954464e1 611 * @experimental
vcoubard 1118:88af68f0226b 612 */
vcoubard 1124:7ffed715734a 613 virtual ble_error_t setScanningPolicyMode(ScanningPolicyMode_t mode)
vcoubard 1118:88af68f0226b 614 {
vcoubard 1118:88af68f0226b 615 (void) mode;
vcoubard 1124:7ffed715734a 616 return BLE_ERROR_NOT_IMPLEMENTED;
vcoubard 1118:88af68f0226b 617 }
vcoubard 1118:88af68f0226b 618
vcoubard 1118:88af68f0226b 619 /**
vcoubard 1118:88af68f0226b 620 * Set the initiator policy filter mode to be used.
vcoubard 1118:88af68f0226b 621 *
vcoubard 1118:88af68f0226b 622 * @param[in] mode
vcoubard 1118:88af68f0226b 623 * The new initiator policy filter mode.
vcoubard 1123:685c954464e1 624 *
vcoubard 1124:7ffed715734a 625 * @return BLE_ERROR_NONE if the specified policy filter mode was set
vcoubard 1124:7ffed715734a 626 * successfully.
vcoubard 1124:7ffed715734a 627 *
vcoubard 1123:685c954464e1 628 * @experimental
vcoubard 1118:88af68f0226b 629 */
vcoubard 1124:7ffed715734a 630 virtual ble_error_t setInitiatorPolicyMode(InitiatorPolicyMode_t mode)
vcoubard 1118:88af68f0226b 631 {
vcoubard 1118:88af68f0226b 632 (void) mode;
vcoubard 1124:7ffed715734a 633 return BLE_ERROR_NOT_IMPLEMENTED;
vcoubard 1118:88af68f0226b 634 }
vcoubard 1118:88af68f0226b 635
vcoubard 1118:88af68f0226b 636 /**
vcoubard 1118:88af68f0226b 637 * Get the advertising policy filter mode that will be used in the next
vcoubard 1118:88af68f0226b 638 * call to startAdvertising().
vcoubard 1118:88af68f0226b 639 *
vcoubard 1118:88af68f0226b 640 * @return The set advertising policy filter mode.
vcoubard 1123:685c954464e1 641 *
vcoubard 1123:685c954464e1 642 * @experimental
vcoubard 1118:88af68f0226b 643 */
vcoubard 1118:88af68f0226b 644 virtual AdvertisingPolicyMode_t getAdvertisingPolicyMode(void) const
vcoubard 1118:88af68f0226b 645 {
vcoubard 1118:88af68f0226b 646 return ADV_POLICY_IGNORE_WHITELIST;
vcoubard 1118:88af68f0226b 647 }
vcoubard 1118:88af68f0226b 648
vcoubard 1118:88af68f0226b 649 /**
vcoubard 1118:88af68f0226b 650 * Get the scan policy filter mode that will be used in the next
vcoubard 1118:88af68f0226b 651 * call to startScan().
vcoubard 1118:88af68f0226b 652 *
vcoubard 1118:88af68f0226b 653 * @return The set scan policy filter mode.
vcoubard 1123:685c954464e1 654 *
vcoubard 1123:685c954464e1 655 * @experimental
vcoubard 1118:88af68f0226b 656 */
vcoubard 1118:88af68f0226b 657 virtual ScanningPolicyMode_t getScanningPolicyMode(void) const
vcoubard 1118:88af68f0226b 658 {
vcoubard 1118:88af68f0226b 659 return SCAN_POLICY_IGNORE_WHITELIST;
vcoubard 1118:88af68f0226b 660 }
vcoubard 1118:88af68f0226b 661
vcoubard 1118:88af68f0226b 662 /**
vcoubard 1118:88af68f0226b 663 * Get the initiator policy filter mode that will be used.
vcoubard 1118:88af68f0226b 664 *
vcoubard 1118:88af68f0226b 665 * @return The set scan policy filter mode.
vcoubard 1123:685c954464e1 666 *
vcoubard 1123:685c954464e1 667 * @experimental
vcoubard 1118:88af68f0226b 668 */
vcoubard 1118:88af68f0226b 669 virtual InitiatorPolicyMode_t getInitiatorPolicyMode(void) const
vcoubard 1118:88af68f0226b 670 {
vcoubard 1118:88af68f0226b 671 return INIT_POLICY_IGNORE_WHITELIST;
vcoubard 1118:88af68f0226b 672 }
vcoubard 1118:88af68f0226b 673
vcoubard 1118:88af68f0226b 674
rgrover1 710:b2e1a2660ec2 675 protected:
rgrover1 710:b2e1a2660ec2 676 /* Override the following in the underlying adaptation layer to provide the functionality of scanning. */
rgrover1 710:b2e1a2660ec2 677 virtual ble_error_t startRadioScan(const GapScanningParams &scanningParams) {
rgrover1 772:b6d27ab66c94 678 (void)scanningParams;
rgrover1 728:997ba5e7b3b6 679 return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */
rgrover1 710:b2e1a2660ec2 680 }
rgrover1 710:b2e1a2660ec2 681
rgrover1 710:b2e1a2660ec2 682 /*
rgrover1 710:b2e1a2660ec2 683 * APIs with non-virtual implementations.
rgrover1 710:b2e1a2660ec2 684 */
rgrover1 710:b2e1a2660ec2 685 public:
rgrover1 710:b2e1a2660ec2 686 /**
vcoubard 1048:efb29faf12fc 687 * Returns the current GAP state of the device using a bitmask that
vcoubard 1048:efb29faf12fc 688 * describes whether the device is advertising or connected.
rgrover1 710:b2e1a2660ec2 689 */
rgrover1 710:b2e1a2660ec2 690 GapState_t getState(void) const {
rgrover1 710:b2e1a2660ec2 691 return state;
rgrover1 710:b2e1a2660ec2 692 }
rgrover1 710:b2e1a2660ec2 693
rgrover1 710:b2e1a2660ec2 694 /**
rgrover1 710:b2e1a2660ec2 695 * Set the GAP advertising mode to use for this device.
rgrover1 710:b2e1a2660ec2 696 */
rgrover1 710:b2e1a2660ec2 697 void setAdvertisingType(GapAdvertisingParams::AdvertisingType_t advType) {
rgrover1 710:b2e1a2660ec2 698 _advParams.setAdvertisingType(advType);
rgrover1 710:b2e1a2660ec2 699 }
rgrover1 710:b2e1a2660ec2 700
rgrover1 710:b2e1a2660ec2 701 /**
rgrover1 710:b2e1a2660ec2 702 * @param[in] interval
rgrover1 710:b2e1a2660ec2 703 * Advertising interval in units of milliseconds. Advertising
rgrover1 710:b2e1a2660ec2 704 * is disabled if interval is 0. If interval is smaller than
rgrover1 710:b2e1a2660ec2 705 * the minimum supported value, then the minimum supported
rgrover1 710:b2e1a2660ec2 706 * value is used instead. This minimum value can be discovered
rgrover1 710:b2e1a2660ec2 707 * using getMinAdvertisingInterval().
rgrover1 710:b2e1a2660ec2 708 *
rgrover1 710:b2e1a2660ec2 709 * This field must be set to 0 if connectionMode is equal
rgrover1 710:b2e1a2660ec2 710 * to ADV_CONNECTABLE_DIRECTED.
rgrover1 710:b2e1a2660ec2 711 *
rgrover1 710:b2e1a2660ec2 712 * @note: Decreasing this value will allow central devices to detect a
vcoubard 1048:efb29faf12fc 713 * peripheral faster, at the expense of more power being used by the radio
rgrover1 710:b2e1a2660ec2 714 * due to the higher data transmit rate.
rgrover1 710:b2e1a2660ec2 715 *
rgrover1 710:b2e1a2660ec2 716 * @Note: [WARNING] This API previously used 0.625ms as the unit for its
rgrover1 710:b2e1a2660ec2 717 * 'interval' argument. That required an explicit conversion from
rgrover1 710:b2e1a2660ec2 718 * milliseconds using Gap::MSEC_TO_GAP_DURATION_UNITS(). This conversion is
rgrover1 710:b2e1a2660ec2 719 * no longer required as the new units are milliseconds. Any application
vcoubard 1048:efb29faf12fc 720 * code depending on the old semantics needs to be updated accordingly.
rgrover1 710:b2e1a2660ec2 721 */
rgrover1 710:b2e1a2660ec2 722 void setAdvertisingInterval(uint16_t interval) {
rgrover1 710:b2e1a2660ec2 723 if (interval == 0) {
rgrover1 710:b2e1a2660ec2 724 stopAdvertising();
rgrover1 710:b2e1a2660ec2 725 } else if (interval < getMinAdvertisingInterval()) {
rgrover1 710:b2e1a2660ec2 726 interval = getMinAdvertisingInterval();
rgrover1 710:b2e1a2660ec2 727 }
rgrover1 786:d6d7087d8377 728 _advParams.setInterval(interval);
rgrover1 710:b2e1a2660ec2 729 }
rgrover1 710:b2e1a2660ec2 730
rgrover1 710:b2e1a2660ec2 731 /**
rgrover1 710:b2e1a2660ec2 732 * @param[in] timeout
rgrover1 710:b2e1a2660ec2 733 * Advertising timeout (in seconds) between 0x1 and 0x3FFF (1
rgrover1 710:b2e1a2660ec2 734 * and 16383). Use 0 to disable the advertising timeout.
rgrover1 710:b2e1a2660ec2 735 */
rgrover1 710:b2e1a2660ec2 736 void setAdvertisingTimeout(uint16_t timeout) {
rgrover1 710:b2e1a2660ec2 737 _advParams.setTimeout(timeout);
rgrover1 710:b2e1a2660ec2 738 }
rgrover1 710:b2e1a2660ec2 739
rgrover1 710:b2e1a2660ec2 740 /**
rgrover1 710:b2e1a2660ec2 741 * Start advertising.
rgrover1 710:b2e1a2660ec2 742 */
rgrover1 710:b2e1a2660ec2 743 ble_error_t startAdvertising(void) {
vcoubard 1048:efb29faf12fc 744 setAdvertisingData(); /* Update the underlying stack. */
rgrover1 710:b2e1a2660ec2 745 return startAdvertising(_advParams);
rgrover1 710:b2e1a2660ec2 746 }
rgrover1 710:b2e1a2660ec2 747
rgrover1 710:b2e1a2660ec2 748 /**
rgrover1 710:b2e1a2660ec2 749 * Reset any advertising payload prepared from prior calls to
rgrover1 710:b2e1a2660ec2 750 * accumulateAdvertisingPayload(). This automatically propagates the re-
vcoubard 1048:efb29faf12fc 751 * initialized advertising payload to the underlying stack.
rgrover1 710:b2e1a2660ec2 752 */
rgrover1 710:b2e1a2660ec2 753 void clearAdvertisingPayload(void) {
rgrover1 710:b2e1a2660ec2 754 _advPayload.clear();
rgrover1 710:b2e1a2660ec2 755 setAdvertisingData();
rgrover1 710:b2e1a2660ec2 756 }
rgrover1 710:b2e1a2660ec2 757
rgrover1 710:b2e1a2660ec2 758 /**
rgrover1 710:b2e1a2660ec2 759 * Accumulate an AD structure in the advertising payload. Please note that
rgrover1 710:b2e1a2660ec2 760 * the payload is limited to 31 bytes. The SCAN_RESPONSE message may be used
vcoubard 1048:efb29faf12fc 761 * as an additional 31 bytes if the advertising payload is too
rgrover1 710:b2e1a2660ec2 762 * small.
rgrover1 710:b2e1a2660ec2 763 *
rgrover1 710:b2e1a2660ec2 764 * @param[in] flags
rgrover1 710:b2e1a2660ec2 765 * The flags to be added. Please refer to
rgrover1 710:b2e1a2660ec2 766 * GapAdvertisingData::Flags for valid flags. Multiple
rgrover1 710:b2e1a2660ec2 767 * flags may be specified in combination.
rgrover1 710:b2e1a2660ec2 768 */
rgrover1 710:b2e1a2660ec2 769 ble_error_t accumulateAdvertisingPayload(uint8_t flags) {
rgrover1 710:b2e1a2660ec2 770 ble_error_t rc;
rgrover1 710:b2e1a2660ec2 771 if ((rc = _advPayload.addFlags(flags)) != BLE_ERROR_NONE) {
rgrover1 710:b2e1a2660ec2 772 return rc;
rgrover1 710:b2e1a2660ec2 773 }
rgrover1 710:b2e1a2660ec2 774
rgrover1 710:b2e1a2660ec2 775 return setAdvertisingData();
rgrover1 710:b2e1a2660ec2 776 }
rgrover1 710:b2e1a2660ec2 777
rgrover1 710:b2e1a2660ec2 778 /**
rgrover1 710:b2e1a2660ec2 779 * Accumulate an AD structure in the advertising payload. Please note that
rgrover1 710:b2e1a2660ec2 780 * the payload is limited to 31 bytes. The SCAN_RESPONSE message may be used
vcoubard 1048:efb29faf12fc 781 * as an additional 31 bytes if the advertising payload is too
rgrover1 710:b2e1a2660ec2 782 * small.
rgrover1 710:b2e1a2660ec2 783 *
rgrover1 710:b2e1a2660ec2 784 * @param app
rgrover1 710:b2e1a2660ec2 785 * The appearance of the peripheral.
rgrover1 710:b2e1a2660ec2 786 */
rgrover1 710:b2e1a2660ec2 787 ble_error_t accumulateAdvertisingPayload(GapAdvertisingData::Appearance app) {
rgrover1 710:b2e1a2660ec2 788 setAppearance(app);
rgrover1 710:b2e1a2660ec2 789
rgrover1 710:b2e1a2660ec2 790 ble_error_t rc;
rgrover1 710:b2e1a2660ec2 791 if ((rc = _advPayload.addAppearance(app)) != BLE_ERROR_NONE) {
rgrover1 710:b2e1a2660ec2 792 return rc;
rgrover1 710:b2e1a2660ec2 793 }
rgrover1 710:b2e1a2660ec2 794
rgrover1 710:b2e1a2660ec2 795 return setAdvertisingData();
rgrover1 710:b2e1a2660ec2 796 }
rgrover1 710:b2e1a2660ec2 797
rgrover1 710:b2e1a2660ec2 798 /**
rgrover1 710:b2e1a2660ec2 799 * Accumulate an AD structure in the advertising payload. Please note that
rgrover1 710:b2e1a2660ec2 800 * the payload is limited to 31 bytes. The SCAN_RESPONSE message may be used
vcoubard 1048:efb29faf12fc 801 * as an additional 31 bytes if the advertising payload is too
rgrover1 710:b2e1a2660ec2 802 * small.
rgrover1 710:b2e1a2660ec2 803 *
vcoubard 1048:efb29faf12fc 804 * @param power
rgrover1 764:1e560f0d45e1 805 * The max transmit power to be used by the controller (in dBm).
rgrover1 710:b2e1a2660ec2 806 */
rgrover1 710:b2e1a2660ec2 807 ble_error_t accumulateAdvertisingPayloadTxPower(int8_t power) {
rgrover1 710:b2e1a2660ec2 808 ble_error_t rc;
rgrover1 710:b2e1a2660ec2 809 if ((rc = _advPayload.addTxPower(power)) != BLE_ERROR_NONE) {
rgrover1 710:b2e1a2660ec2 810 return rc;
rgrover1 710:b2e1a2660ec2 811 }
rgrover1 710:b2e1a2660ec2 812
rgrover1 710:b2e1a2660ec2 813 return setAdvertisingData();
rgrover1 710:b2e1a2660ec2 814 }
rgrover1 710:b2e1a2660ec2 815
rgrover1 710:b2e1a2660ec2 816 /**
rgrover1 710:b2e1a2660ec2 817 * Accumulate a variable length byte-stream as an AD structure in the
rgrover1 710:b2e1a2660ec2 818 * advertising payload. Please note that the payload is limited to 31 bytes.
rgrover1 710:b2e1a2660ec2 819 * The SCAN_RESPONSE message may be used as an additional 31 bytes if the
vcoubard 1048:efb29faf12fc 820 * advertising payload is too small.
rgrover1 710:b2e1a2660ec2 821 *
vcoubard 1048:efb29faf12fc 822 * @param type The type describing the variable length data.
vcoubard 1048:efb29faf12fc 823 * @param data Data bytes.
vcoubard 1048:efb29faf12fc 824 * @param len Length of data.
vcoubard 1104:0244fbb0324e 825 *
vcoubard 1104:0244fbb0324e 826 * @return BLE_ERROR_NONE if the advertisement payload was updated based on
vcoubard 1104:0244fbb0324e 827 * matching AD type; otherwise, an appropriate error.
vcoubard 1104:0244fbb0324e 828 *
vcoubard 1104:0244fbb0324e 829 * @note When the specified AD type is INCOMPLETE_LIST_16BIT_SERVICE_IDS,
vcoubard 1104:0244fbb0324e 830 * COMPLETE_LIST_16BIT_SERVICE_IDS, INCOMPLETE_LIST_32BIT_SERVICE_IDS,
vcoubard 1104:0244fbb0324e 831 * COMPLETE_LIST_32BIT_SERVICE_IDS, INCOMPLETE_LIST_128BIT_SERVICE_IDS,
vcoubard 1104:0244fbb0324e 832 * COMPLETE_LIST_128BIT_SERVICE_IDS or LIST_128BIT_SOLICITATION_IDS the
vcoubard 1104:0244fbb0324e 833 * supplied value is appended to the values previously added to the
vcoubard 1104:0244fbb0324e 834 * payload.
rgrover1 710:b2e1a2660ec2 835 */
rgrover1 710:b2e1a2660ec2 836 ble_error_t accumulateAdvertisingPayload(GapAdvertisingData::DataType type, const uint8_t *data, uint8_t len) {
rgrover1 710:b2e1a2660ec2 837 if (type == GapAdvertisingData::COMPLETE_LOCAL_NAME) {
rgrover1 710:b2e1a2660ec2 838 setDeviceName(data);
rgrover1 710:b2e1a2660ec2 839 }
rgrover1 710:b2e1a2660ec2 840
rgrover1 710:b2e1a2660ec2 841 ble_error_t rc;
rgrover1 710:b2e1a2660ec2 842 if ((rc = _advPayload.addData(type, data, len)) != BLE_ERROR_NONE) {
rgrover1 710:b2e1a2660ec2 843 return rc;
rgrover1 710:b2e1a2660ec2 844 }
rgrover1 710:b2e1a2660ec2 845
rgrover1 710:b2e1a2660ec2 846 return setAdvertisingData();
rgrover1 710:b2e1a2660ec2 847 }
rgrover1 710:b2e1a2660ec2 848
rgrover1 710:b2e1a2660ec2 849 /**
rgrover1 765:4cd91998cd48 850 * Update a particular ADV field in the advertising payload (based on
vcoubard 1104:0244fbb0324e 851 * matching type).
rgrover1 763:36c3e2b1f1ae 852 *
vcoubard 1048:efb29faf12fc 853 * @param[in] type The ADV type field describing the variable length data.
vcoubard 1048:efb29faf12fc 854 * @param[in] data Data bytes.
vcoubard 1048:efb29faf12fc 855 * @param[in] len Length of data.
rgrover1 765:4cd91998cd48 856 *
rgrover1 765:4cd91998cd48 857 * @note: If advertisements are enabled, then the update will take effect immediately.
rgrover1 765:4cd91998cd48 858 *
rgrover1 765:4cd91998cd48 859 * @return BLE_ERROR_NONE if the advertisement payload was updated based on
vcoubard 1104:0244fbb0324e 860 * matching AD type; otherwise, an appropriate error.
rgrover1 763:36c3e2b1f1ae 861 */
rgrover1 763:36c3e2b1f1ae 862 ble_error_t updateAdvertisingPayload(GapAdvertisingData::DataType type, const uint8_t *data, uint8_t len) {
rgrover1 763:36c3e2b1f1ae 863 if (type == GapAdvertisingData::COMPLETE_LOCAL_NAME) {
rgrover1 763:36c3e2b1f1ae 864 setDeviceName(data);
rgrover1 763:36c3e2b1f1ae 865 }
rgrover1 763:36c3e2b1f1ae 866
rgrover1 763:36c3e2b1f1ae 867 ble_error_t rc;
rgrover1 763:36c3e2b1f1ae 868 if ((rc = _advPayload.updateData(type, data, len)) != BLE_ERROR_NONE) {
rgrover1 763:36c3e2b1f1ae 869 return rc;
rgrover1 763:36c3e2b1f1ae 870 }
rgrover1 763:36c3e2b1f1ae 871
rgrover1 763:36c3e2b1f1ae 872 return setAdvertisingData();
rgrover1 763:36c3e2b1f1ae 873 }
rgrover1 763:36c3e2b1f1ae 874
rgrover1 763:36c3e2b1f1ae 875 /**
vcoubard 1048:efb29faf12fc 876 * Set up a particular, user-constructed advertisement payload for the
rgrover1 710:b2e1a2660ec2 877 * underlying stack. It would be uncommon for this API to be used directly;
rgrover1 710:b2e1a2660ec2 878 * there are other APIs to build an advertisement payload (see above).
rgrover1 710:b2e1a2660ec2 879 */
rgrover1 710:b2e1a2660ec2 880 ble_error_t setAdvertisingPayload(const GapAdvertisingData &payload) {
rgrover1 710:b2e1a2660ec2 881 _advPayload = payload;
rgrover1 710:b2e1a2660ec2 882 return setAdvertisingData();
rgrover1 710:b2e1a2660ec2 883 }
rgrover1 710:b2e1a2660ec2 884
rgrover1 710:b2e1a2660ec2 885 /**
rgrover1 710:b2e1a2660ec2 886 * @return Read back advertising data. Useful for storing and
rgrover1 710:b2e1a2660ec2 887 * restoring payload.
rgrover1 710:b2e1a2660ec2 888 */
rgrover1 710:b2e1a2660ec2 889 const GapAdvertisingData &getAdvertisingPayload(void) const {
rgrover1 710:b2e1a2660ec2 890 return _advPayload;
rgrover1 710:b2e1a2660ec2 891 }
rgrover1 710:b2e1a2660ec2 892
rgrover1 710:b2e1a2660ec2 893 /**
rgrover1 710:b2e1a2660ec2 894 * Accumulate a variable length byte-stream as an AD structure in the
rgrover1 710:b2e1a2660ec2 895 * scanResponse payload.
rgrover1 710:b2e1a2660ec2 896 *
vcoubard 1048:efb29faf12fc 897 * @param[in] type The type describing the variable length data.
vcoubard 1048:efb29faf12fc 898 * @param[in] data Data bytes.
vcoubard 1048:efb29faf12fc 899 * @param[in] len Length of data.
rgrover1 710:b2e1a2660ec2 900 */
rgrover1 710:b2e1a2660ec2 901 ble_error_t accumulateScanResponse(GapAdvertisingData::DataType type, const uint8_t *data, uint8_t len) {
rgrover1 710:b2e1a2660ec2 902 ble_error_t rc;
rgrover1 710:b2e1a2660ec2 903 if ((rc = _scanResponse.addData(type, data, len)) != BLE_ERROR_NONE) {
rgrover1 710:b2e1a2660ec2 904 return rc;
rgrover1 710:b2e1a2660ec2 905 }
rgrover1 710:b2e1a2660ec2 906
rgrover1 710:b2e1a2660ec2 907 return setAdvertisingData();
rgrover1 710:b2e1a2660ec2 908 }
rgrover1 710:b2e1a2660ec2 909
rgrover1 710:b2e1a2660ec2 910 /**
rgrover1 710:b2e1a2660ec2 911 * Reset any scan response prepared from prior calls to
rgrover1 710:b2e1a2660ec2 912 * accumulateScanResponse().
rgrover1 710:b2e1a2660ec2 913 *
rgrover1 710:b2e1a2660ec2 914 * Note: This should be followed by a call to setAdvertisingPayload() or
rgrover1 710:b2e1a2660ec2 915 * startAdvertising() before the update takes effect.
rgrover1 710:b2e1a2660ec2 916 */
rgrover1 710:b2e1a2660ec2 917 void clearScanResponse(void) {
rgrover1 710:b2e1a2660ec2 918 _scanResponse.clear();
rgrover1 710:b2e1a2660ec2 919 setAdvertisingData();
rgrover1 710:b2e1a2660ec2 920 }
rgrover1 710:b2e1a2660ec2 921
rgrover1 710:b2e1a2660ec2 922 /**
vcoubard 1048:efb29faf12fc 923 * Set up parameters for GAP scanning (observer mode).
rgrover1 710:b2e1a2660ec2 924 * @param[in] interval
rgrover1 710:b2e1a2660ec2 925 * Scan interval (in milliseconds) [valid values lie between 2.5ms and 10.24s].
rgrover1 710:b2e1a2660ec2 926 * @param[in] window
rgrover1 710:b2e1a2660ec2 927 * Scan Window (in milliseconds) [valid values lie between 2.5ms and 10.24s].
rgrover1 710:b2e1a2660ec2 928 * @param[in] timeout
vcoubard 1048:efb29faf12fc 929 * Scan timeout (in seconds) between 0x0001 and 0xFFFF; 0x0000 disables the timeout.
rgrover1 710:b2e1a2660ec2 930 * @param[in] activeScanning
rgrover1 710:b2e1a2660ec2 931 * Set to True if active-scanning is required. This is used to fetch the
rgrover1 710:b2e1a2660ec2 932 * scan response from a peer if possible.
rgrover1 710:b2e1a2660ec2 933 *
rgrover1 710:b2e1a2660ec2 934 * The scanning window divided by the interval determines the duty cycle for
rgrover1 710:b2e1a2660ec2 935 * scanning. For example, if the interval is 100ms and the window is 10ms,
rgrover1 710:b2e1a2660ec2 936 * then the controller will scan for 10 percent of the time. It is possible
rgrover1 710:b2e1a2660ec2 937 * to have the interval and window set to the same value. In this case,
rgrover1 710:b2e1a2660ec2 938 * scanning is continuous, with a change of scanning frequency once every
rgrover1 710:b2e1a2660ec2 939 * interval.
rgrover1 710:b2e1a2660ec2 940 *
rgrover1 710:b2e1a2660ec2 941 * Once the scanning parameters have been configured, scanning can be
rgrover1 710:b2e1a2660ec2 942 * enabled by using startScan().
rgrover1 710:b2e1a2660ec2 943 *
rgrover1 710:b2e1a2660ec2 944 * @Note: The scan interval and window are recommendations to the BLE stack.
rgrover1 710:b2e1a2660ec2 945 */
rgrover1 710:b2e1a2660ec2 946 ble_error_t setScanParams(uint16_t interval = GapScanningParams::SCAN_INTERVAL_MAX,
rgrover1 710:b2e1a2660ec2 947 uint16_t window = GapScanningParams::SCAN_WINDOW_MAX,
rgrover1 710:b2e1a2660ec2 948 uint16_t timeout = 0,
rgrover1 710:b2e1a2660ec2 949 bool activeScanning = false) {
rgrover1 710:b2e1a2660ec2 950 ble_error_t rc;
rgrover1 710:b2e1a2660ec2 951 if (((rc = _scanningParams.setInterval(interval)) == BLE_ERROR_NONE) &&
rgrover1 710:b2e1a2660ec2 952 ((rc = _scanningParams.setWindow(window)) == BLE_ERROR_NONE) &&
rgrover1 710:b2e1a2660ec2 953 ((rc = _scanningParams.setTimeout(timeout)) == BLE_ERROR_NONE)) {
rgrover1 710:b2e1a2660ec2 954 _scanningParams.setActiveScanning(activeScanning);
rgrover1 710:b2e1a2660ec2 955 return BLE_ERROR_NONE;
rgrover1 710:b2e1a2660ec2 956 }
rgrover1 710:b2e1a2660ec2 957
rgrover1 710:b2e1a2660ec2 958 return rc;
rgrover1 710:b2e1a2660ec2 959 }
rgrover1 710:b2e1a2660ec2 960
rgrover1 710:b2e1a2660ec2 961 /**
vcoubard 1048:efb29faf12fc 962 * Set up the scanInterval parameter for GAP scanning (observer mode).
rgrover1 710:b2e1a2660ec2 963 * @param[in] interval
rgrover1 710:b2e1a2660ec2 964 * Scan interval (in milliseconds) [valid values lie between 2.5ms and 10.24s].
rgrover1 710:b2e1a2660ec2 965 *
rgrover1 710:b2e1a2660ec2 966 * The scanning window divided by the interval determines the duty cycle for
rgrover1 710:b2e1a2660ec2 967 * scanning. For example, if the interval is 100ms and the window is 10ms,
rgrover1 710:b2e1a2660ec2 968 * then the controller will scan for 10 percent of the time. It is possible
rgrover1 710:b2e1a2660ec2 969 * to have the interval and window set to the same value. In this case,
rgrover1 710:b2e1a2660ec2 970 * scanning is continuous, with a change of scanning frequency once every
rgrover1 710:b2e1a2660ec2 971 * interval.
rgrover1 710:b2e1a2660ec2 972 *
rgrover1 710:b2e1a2660ec2 973 * Once the scanning parameters have been configured, scanning can be
rgrover1 710:b2e1a2660ec2 974 * enabled by using startScan().
rgrover1 710:b2e1a2660ec2 975 */
rgrover1 710:b2e1a2660ec2 976 ble_error_t setScanInterval(uint16_t interval) {
rgrover1 710:b2e1a2660ec2 977 return _scanningParams.setInterval(interval);
rgrover1 710:b2e1a2660ec2 978 }
rgrover1 710:b2e1a2660ec2 979
rgrover1 710:b2e1a2660ec2 980 /**
vcoubard 1048:efb29faf12fc 981 * Set up the scanWindow parameter for GAP scanning (observer mode).
rgrover1 710:b2e1a2660ec2 982 * @param[in] window
rgrover1 710:b2e1a2660ec2 983 * Scan Window (in milliseconds) [valid values lie between 2.5ms and 10.24s].
rgrover1 710:b2e1a2660ec2 984 *
rgrover1 710:b2e1a2660ec2 985 * The scanning window divided by the interval determines the duty cycle for
rgrover1 710:b2e1a2660ec2 986 * scanning. For example, if the interval is 100ms and the window is 10ms,
rgrover1 710:b2e1a2660ec2 987 * then the controller will scan for 10 percent of the time. It is possible
rgrover1 710:b2e1a2660ec2 988 * to have the interval and window set to the same value. In this case,
rgrover1 710:b2e1a2660ec2 989 * scanning is continuous, with a change of scanning frequency once every
rgrover1 710:b2e1a2660ec2 990 * interval.
rgrover1 710:b2e1a2660ec2 991 *
rgrover1 710:b2e1a2660ec2 992 * Once the scanning parameters have been configured, scanning can be
rgrover1 710:b2e1a2660ec2 993 * enabled by using startScan().
rgrover1 770:079b714e9c1a 994 *
rgrover1 770:079b714e9c1a 995 * If scanning is already active, the updated value of scanWindow will be
rgrover1 770:079b714e9c1a 996 * propagated to the underlying BLE stack.
rgrover1 710:b2e1a2660ec2 997 */
rgrover1 710:b2e1a2660ec2 998 ble_error_t setScanWindow(uint16_t window) {
rgrover1 770:079b714e9c1a 999 ble_error_t rc;
rgrover1 770:079b714e9c1a 1000 if ((rc = _scanningParams.setWindow(window)) != BLE_ERROR_NONE) {
rgrover1 770:079b714e9c1a 1001 return rc;
rgrover1 770:079b714e9c1a 1002 }
rgrover1 770:079b714e9c1a 1003
rgrover1 770:079b714e9c1a 1004 /* If scanning is already active, propagate the new setting to the stack. */
rgrover1 770:079b714e9c1a 1005 if (scanningActive) {
rgrover1 770:079b714e9c1a 1006 return startRadioScan(_scanningParams);
rgrover1 770:079b714e9c1a 1007 }
rgrover1 770:079b714e9c1a 1008
rgrover1 770:079b714e9c1a 1009 return BLE_ERROR_NONE;
rgrover1 710:b2e1a2660ec2 1010 }
rgrover1 710:b2e1a2660ec2 1011
rgrover1 710:b2e1a2660ec2 1012 /**
vcoubard 1048:efb29faf12fc 1013 * Set up parameters for GAP scanning (observer mode).
rgrover1 710:b2e1a2660ec2 1014 * @param[in] timeout
vcoubard 1048:efb29faf12fc 1015 * Scan timeout (in seconds) between 0x0001 and 0xFFFF; 0x0000 disables the timeout.
rgrover1 710:b2e1a2660ec2 1016 *
rgrover1 710:b2e1a2660ec2 1017 * Once the scanning parameters have been configured, scanning can be
rgrover1 710:b2e1a2660ec2 1018 * enabled by using startScan().
rgrover1 770:079b714e9c1a 1019 *
rgrover1 770:079b714e9c1a 1020 * If scanning is already active, the updated value of scanTimeout will be
rgrover1 770:079b714e9c1a 1021 * propagated to the underlying BLE stack.
rgrover1 710:b2e1a2660ec2 1022 */
rgrover1 710:b2e1a2660ec2 1023 ble_error_t setScanTimeout(uint16_t timeout) {
rgrover1 770:079b714e9c1a 1024 ble_error_t rc;
rgrover1 770:079b714e9c1a 1025 if ((rc = _scanningParams.setTimeout(timeout)) != BLE_ERROR_NONE) {
rgrover1 770:079b714e9c1a 1026 return rc;
rgrover1 770:079b714e9c1a 1027 }
rgrover1 770:079b714e9c1a 1028
rgrover1 770:079b714e9c1a 1029 /* If scanning is already active, propagate the new settings to the stack. */
rgrover1 770:079b714e9c1a 1030 if (scanningActive) {
rgrover1 770:079b714e9c1a 1031 return startRadioScan(_scanningParams);
rgrover1 770:079b714e9c1a 1032 }
rgrover1 770:079b714e9c1a 1033
rgrover1 770:079b714e9c1a 1034 return BLE_ERROR_NONE;
rgrover1 710:b2e1a2660ec2 1035 }
rgrover1 710:b2e1a2660ec2 1036
rgrover1 710:b2e1a2660ec2 1037 /**
vcoubard 1048:efb29faf12fc 1038 * Set up parameters for GAP scanning (observer mode).
rgrover1 710:b2e1a2660ec2 1039 * @param[in] activeScanning
rgrover1 710:b2e1a2660ec2 1040 * Set to True if active-scanning is required. This is used to fetch the
rgrover1 710:b2e1a2660ec2 1041 * scan response from a peer if possible.
rgrover1 710:b2e1a2660ec2 1042 *
rgrover1 710:b2e1a2660ec2 1043 * Once the scanning parameters have been configured, scanning can be
rgrover1 710:b2e1a2660ec2 1044 * enabled by using startScan().
rgrover1 770:079b714e9c1a 1045 *
rgrover1 770:079b714e9c1a 1046 * If scanning is already in progress, then active-scanning will be enabled
rgrover1 770:079b714e9c1a 1047 * for the underlying BLE stack.
rgrover1 710:b2e1a2660ec2 1048 */
rgrover1 770:079b714e9c1a 1049 ble_error_t setActiveScanning(bool activeScanning) {
rgrover1 710:b2e1a2660ec2 1050 _scanningParams.setActiveScanning(activeScanning);
rgrover1 770:079b714e9c1a 1051
rgrover1 770:079b714e9c1a 1052 /* If scanning is already active, propagate the new settings to the stack. */
rgrover1 770:079b714e9c1a 1053 if (scanningActive) {
rgrover1 770:079b714e9c1a 1054 return startRadioScan(_scanningParams);
rgrover1 770:079b714e9c1a 1055 }
rgrover1 770:079b714e9c1a 1056
rgrover1 770:079b714e9c1a 1057 return BLE_ERROR_NONE;
rgrover1 710:b2e1a2660ec2 1058 }
rgrover1 710:b2e1a2660ec2 1059
rgrover1 710:b2e1a2660ec2 1060 /**
rgrover1 710:b2e1a2660ec2 1061 * Start scanning (Observer Procedure) based on the parameters currently in
rgrover1 710:b2e1a2660ec2 1062 * effect.
rgrover1 710:b2e1a2660ec2 1063 *
rgrover1 710:b2e1a2660ec2 1064 * @param[in] callback
vcoubard 1048:efb29faf12fc 1065 * The application-specific callback to be invoked upon
rgrover1 710:b2e1a2660ec2 1066 * receiving every advertisement report. This can be passed in
rgrover1 710:b2e1a2660ec2 1067 * as NULL, in which case scanning may not be enabled at all.
rgrover1 710:b2e1a2660ec2 1068 */
rgrover1 710:b2e1a2660ec2 1069 ble_error_t startScan(void (*callback)(const AdvertisementCallbackParams_t *params)) {
rgrover1 710:b2e1a2660ec2 1070 ble_error_t err = BLE_ERROR_NONE;
rgrover1 710:b2e1a2660ec2 1071 if (callback) {
rgrover1 710:b2e1a2660ec2 1072 if ((err = startRadioScan(_scanningParams)) == BLE_ERROR_NONE) {
rgrover1 770:079b714e9c1a 1073 scanningActive = true;
rgrover1 710:b2e1a2660ec2 1074 onAdvertisementReport.attach(callback);
rgrover1 710:b2e1a2660ec2 1075 }
rgrover1 710:b2e1a2660ec2 1076 }
rgrover1 710:b2e1a2660ec2 1077
rgrover1 710:b2e1a2660ec2 1078 return err;
rgrover1 710:b2e1a2660ec2 1079 }
rgrover1 710:b2e1a2660ec2 1080
rgrover1 710:b2e1a2660ec2 1081 /**
rgrover1 710:b2e1a2660ec2 1082 * Same as above, but this takes an (object, method) pair for a callback.
rgrover1 710:b2e1a2660ec2 1083 */
rgrover1 710:b2e1a2660ec2 1084 template<typename T>
rgrover1 710:b2e1a2660ec2 1085 ble_error_t startScan(T *object, void (T::*callbackMember)(const AdvertisementCallbackParams_t *params)) {
rgrover1 710:b2e1a2660ec2 1086 ble_error_t err = BLE_ERROR_NONE;
rgrover1 710:b2e1a2660ec2 1087 if (object && callbackMember) {
rgrover1 710:b2e1a2660ec2 1088 if ((err = startRadioScan(_scanningParams)) == BLE_ERROR_NONE) {
rgrover1 770:079b714e9c1a 1089 scanningActive = true;
rgrover1 710:b2e1a2660ec2 1090 onAdvertisementReport.attach(object, callbackMember);
rgrover1 710:b2e1a2660ec2 1091 }
rgrover1 710:b2e1a2660ec2 1092 }
rgrover1 710:b2e1a2660ec2 1093
rgrover1 710:b2e1a2660ec2 1094 return err;
rgrover1 710:b2e1a2660ec2 1095 }
rgrover1 710:b2e1a2660ec2 1096
rgrover1 753:0f60274cd3ad 1097 /**
rgrover1 753:0f60274cd3ad 1098 * Initialize radio-notification events to be generated from the stack.
vcoubard 1048:efb29faf12fc 1099 * This API doesn't need to be called directly.
rgrover1 753:0f60274cd3ad 1100 *
rgrover1 753:0f60274cd3ad 1101 * Radio Notification is a feature that enables ACTIVE and INACTIVE
rgrover1 753:0f60274cd3ad 1102 * (nACTIVE) signals from the stack that notify the application when the
rgrover1 753:0f60274cd3ad 1103 * radio is in use.
rgrover1 753:0f60274cd3ad 1104 *
vcoubard 1048:efb29faf12fc 1105 * The ACTIVE signal is sent before the radio event starts. The nACTIVE
vcoubard 1048:efb29faf12fc 1106 * signal is sent at the end of the radio event. These signals can be used
rgrover1 753:0f60274cd3ad 1107 * by the application programmer to synchronize application logic with radio
rgrover1 753:0f60274cd3ad 1108 * activity. For example, the ACTIVE signal can be used to shut off external
vcoubard 1048:efb29faf12fc 1109 * devices, to manage peak current drawn during periods when the radio is on,
rgrover1 753:0f60274cd3ad 1110 * or to trigger sensor data collection for transmission in the Radio Event.
rgrover1 753:0f60274cd3ad 1111 *
rgrover1 753:0f60274cd3ad 1112 * @return BLE_ERROR_NONE on successful initialization, otherwise an error code.
rgrover1 753:0f60274cd3ad 1113 */
rgrover1 753:0f60274cd3ad 1114 virtual ble_error_t initRadioNotification(void) {
rgrover1 753:0f60274cd3ad 1115 return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */
rgrover1 753:0f60274cd3ad 1116 }
rgrover1 753:0f60274cd3ad 1117
rgrover1 710:b2e1a2660ec2 1118 private:
rgrover1 710:b2e1a2660ec2 1119 ble_error_t setAdvertisingData(void) {
rgrover1 710:b2e1a2660ec2 1120 return setAdvertisingData(_advPayload, _scanResponse);
rgrover1 710:b2e1a2660ec2 1121 }
rgrover1 710:b2e1a2660ec2 1122
rgrover1 710:b2e1a2660ec2 1123 private:
rgrover1 896:791741895cd8 1124 virtual ble_error_t setAdvertisingData(const GapAdvertisingData &advData, const GapAdvertisingData &scanResponse) = 0;
rgrover1 896:791741895cd8 1125 virtual ble_error_t startAdvertising(const GapAdvertisingParams &) = 0;
rgrover1 710:b2e1a2660ec2 1126
rgrover1 710:b2e1a2660ec2 1127 public:
rgrover1 710:b2e1a2660ec2 1128 /**
rgrover1 710:b2e1a2660ec2 1129 * Accessors to read back currently active advertising params.
rgrover1 710:b2e1a2660ec2 1130 */
rgrover1 710:b2e1a2660ec2 1131 GapAdvertisingParams &getAdvertisingParams(void) {
rgrover1 710:b2e1a2660ec2 1132 return _advParams;
rgrover1 710:b2e1a2660ec2 1133 }
rgrover1 710:b2e1a2660ec2 1134 const GapAdvertisingParams &getAdvertisingParams(void) const {
rgrover1 710:b2e1a2660ec2 1135 return _advParams;
rgrover1 710:b2e1a2660ec2 1136 }
rgrover1 710:b2e1a2660ec2 1137
rgrover1 710:b2e1a2660ec2 1138 /**
vcoubard 1048:efb29faf12fc 1139 * Set up a particular, user-constructed set of advertisement parameters for
rgrover1 710:b2e1a2660ec2 1140 * the underlying stack. It would be uncommon for this API to be used
rgrover1 710:b2e1a2660ec2 1141 * directly; there are other APIs to tweak advertisement parameters
rgrover1 710:b2e1a2660ec2 1142 * individually.
rgrover1 710:b2e1a2660ec2 1143 */
rgrover1 710:b2e1a2660ec2 1144 void setAdvertisingParams(const GapAdvertisingParams &newParams) {
rgrover1 710:b2e1a2660ec2 1145 _advParams = newParams;
rgrover1 710:b2e1a2660ec2 1146 }
rgrover1 710:b2e1a2660ec2 1147
rgrover1 710:b2e1a2660ec2 1148 /* Event callback handlers. */
rgrover1 710:b2e1a2660ec2 1149 public:
rgrover1 710:b2e1a2660ec2 1150 /**
vcoubard 1048:efb29faf12fc 1151 * Set up a callback for timeout events. Refer to TimeoutSource_t for
rgrover1 710:b2e1a2660ec2 1152 * possible event types.
vcoubard 1052:b55e1ad3e1b3 1153 * @note It is possible to unregister callbacks using onTimeout().detach(callback)
rgrover1 710:b2e1a2660ec2 1154 */
vcoubard 1052:b55e1ad3e1b3 1155 void onTimeout(TimeoutEventCallback_t callback) {
vcoubard 1052:b55e1ad3e1b3 1156 timeoutCallbackChain.add(callback);
vcoubard 1052:b55e1ad3e1b3 1157 }
vcoubard 1052:b55e1ad3e1b3 1158
vcoubard 1052:b55e1ad3e1b3 1159 /**
vcoubard 1052:b55e1ad3e1b3 1160 * @brief provide access to the callchain of timeout event callbacks
vcoubard 1052:b55e1ad3e1b3 1161 * It is possible to register callbacks using onTimeout().add(callback);
vcoubard 1054:f59e5d9a992a 1162 * It is possible to unregister callbacks using onTimeout().detach(callback)
vcoubard 1052:b55e1ad3e1b3 1163 * @return The timeout event callbacks chain
vcoubard 1052:b55e1ad3e1b3 1164 */
vcoubard 1052:b55e1ad3e1b3 1165 TimeoutEventCallbackChain_t& onTimeout() {
vcoubard 1052:b55e1ad3e1b3 1166 return timeoutCallbackChain;
vcoubard 1052:b55e1ad3e1b3 1167 }
rgrover1 710:b2e1a2660ec2 1168
rgrover1 710:b2e1a2660ec2 1169 /**
rgrover1 829:9072de50087b 1170 * Append to a chain of callbacks to be invoked upon GAP connection.
vcoubard 1052:b55e1ad3e1b3 1171 * @note It is possible to unregister callbacks using onConnection().detach(callback)
rgrover1 710:b2e1a2660ec2 1172 */
rgrover1 829:9072de50087b 1173 void onConnection(ConnectionEventCallback_t callback) {connectionCallChain.add(callback);}
rgrover1 710:b2e1a2660ec2 1174
rgrover1 829:9072de50087b 1175 template<typename T>
rgrover1 829:9072de50087b 1176 void onConnection(T *tptr, void (T::*mptr)(const ConnectionCallbackParams_t*)) {connectionCallChain.add(tptr, mptr);}
rgrover1 710:b2e1a2660ec2 1177
rgrover1 710:b2e1a2660ec2 1178 /**
vcoubard 1052:b55e1ad3e1b3 1179 * @brief provide access to the callchain of connection event callbacks
vcoubard 1052:b55e1ad3e1b3 1180 * It is possible to register callbacks using onConnection().add(callback);
vcoubard 1054:f59e5d9a992a 1181 * It is possible to unregister callbacks using onConnection().detach(callback)
vcoubard 1052:b55e1ad3e1b3 1182 * @return The connection event callbacks chain
vcoubard 1052:b55e1ad3e1b3 1183 */
vcoubard 1054:f59e5d9a992a 1184 ConnectionEventCallbackChain_t& onConnection() {
vcoubard 1052:b55e1ad3e1b3 1185 return connectionCallChain;
vcoubard 1052:b55e1ad3e1b3 1186 }
vcoubard 1052:b55e1ad3e1b3 1187
vcoubard 1052:b55e1ad3e1b3 1188 /**
rgrover1 829:9072de50087b 1189 * Append to a chain of callbacks to be invoked upon GAP disconnection.
vcoubard 1052:b55e1ad3e1b3 1190 * @note It is possible to unregister callbacks using onDisconnection().detach(callback)
rgrover1 816:2b4f0ef8c06e 1191 */
rgrover1 829:9072de50087b 1192 void onDisconnection(DisconnectionEventCallback_t callback) {disconnectionCallChain.add(callback);}
rgrover1 816:2b4f0ef8c06e 1193
rgrover1 710:b2e1a2660ec2 1194 template<typename T>
rgrover1 829:9072de50087b 1195 void onDisconnection(T *tptr, void (T::*mptr)(const DisconnectionCallbackParams_t*)) {disconnectionCallChain.add(tptr, mptr);}
rgrover1 710:b2e1a2660ec2 1196
rgrover1 710:b2e1a2660ec2 1197 /**
vcoubard 1052:b55e1ad3e1b3 1198 * @brief provide access to the callchain of disconnection event callbacks
vcoubard 1052:b55e1ad3e1b3 1199 * It is possible to register callbacks using onDisconnection().add(callback);
vcoubard 1054:f59e5d9a992a 1200 * It is possible to unregister callbacks using onDisconnection().detach(callback)
vcoubard 1052:b55e1ad3e1b3 1201 * @return The disconnection event callbacks chain
vcoubard 1052:b55e1ad3e1b3 1202 */
vcoubard 1052:b55e1ad3e1b3 1203 DisconnectionEventCallbackChain_t& onDisconnection() {
vcoubard 1052:b55e1ad3e1b3 1204 return disconnectionCallChain;
vcoubard 1052:b55e1ad3e1b3 1205 }
vcoubard 1052:b55e1ad3e1b3 1206
vcoubard 1052:b55e1ad3e1b3 1207 /**
rgrover1 710:b2e1a2660ec2 1208 * Set the application callback for radio-notification events.
rgrover1 710:b2e1a2660ec2 1209 *
rgrover1 710:b2e1a2660ec2 1210 * Radio Notification is a feature that enables ACTIVE and INACTIVE
rgrover1 710:b2e1a2660ec2 1211 * (nACTIVE) signals from the stack that notify the application when the
rgrover1 753:0f60274cd3ad 1212 * radio is in use.
rgrover1 710:b2e1a2660ec2 1213 *
vcoubard 1048:efb29faf12fc 1214 * The ACTIVE signal is sent before the radio event starts. The nACTIVE
vcoubard 1048:efb29faf12fc 1215 * signal is sent at the end of the radio event. These signals can be used
rgrover1 710:b2e1a2660ec2 1216 * by the application programmer to synchronize application logic with radio
rgrover1 710:b2e1a2660ec2 1217 * activity. For example, the ACTIVE signal can be used to shut off external
vcoubard 1048:efb29faf12fc 1218 * devices, to manage peak current drawn during periods when the radio is on,
rgrover1 710:b2e1a2660ec2 1219 * or to trigger sensor data collection for transmission in the Radio Event.
rgrover1 710:b2e1a2660ec2 1220 *
rgrover1 710:b2e1a2660ec2 1221 * @param callback
rgrover1 710:b2e1a2660ec2 1222 * The application handler to be invoked in response to a radio
rgrover1 710:b2e1a2660ec2 1223 * ACTIVE/INACTIVE event.
rgrover1 754:9b391fb5c5d7 1224 *
vcoubard 1048:efb29faf12fc 1225 * Or in the other version:
rgrover1 754:9b391fb5c5d7 1226 *
rgrover1 754:9b391fb5c5d7 1227 * @param tptr
rgrover1 754:9b391fb5c5d7 1228 * Pointer to the object of a class defining the member callback
rgrover1 754:9b391fb5c5d7 1229 * function (mptr).
rgrover1 754:9b391fb5c5d7 1230 * @param mptr
rgrover1 754:9b391fb5c5d7 1231 * The member callback (within the context of an object) to be
rgrover1 754:9b391fb5c5d7 1232 * invoked in response to a radio ACTIVE/INACTIVE event.
rgrover1 710:b2e1a2660ec2 1233 */
rgrover1 753:0f60274cd3ad 1234 void onRadioNotification(void (*callback)(bool param)) {
rgrover1 753:0f60274cd3ad 1235 radioNotificationCallback.attach(callback);
rgrover1 753:0f60274cd3ad 1236 }
rgrover1 753:0f60274cd3ad 1237 template <typename T>
rgrover1 753:0f60274cd3ad 1238 void onRadioNotification(T *tptr, void (T::*mptr)(bool)) {
rgrover1 753:0f60274cd3ad 1239 radioNotificationCallback.attach(tptr, mptr);
rgrover1 753:0f60274cd3ad 1240 }
rgrover1 710:b2e1a2660ec2 1241
vcoubard 1090:148d8b9b56a5 1242 /**
vcoubard 1090:148d8b9b56a5 1243 * Setup a callback to be invoked to notify the user application that the
vcoubard 1090:148d8b9b56a5 1244 * Gap instance is about to shutdown (possibly as a result of a call
vcoubard 1090:148d8b9b56a5 1245 * to BLE::shutdown()).
vcoubard 1090:148d8b9b56a5 1246 *
vcoubard 1090:148d8b9b56a5 1247 * @Note: It is possible to chain together multiple onShutdown callbacks
vcoubard 1090:148d8b9b56a5 1248 * (potentially from different modules of an application) to be notified
vcoubard 1090:148d8b9b56a5 1249 * before the Gap instance is shutdown.
vcoubard 1090:148d8b9b56a5 1250 *
vcoubard 1090:148d8b9b56a5 1251 * @Note: It is also possible to set up a callback into a member function of
vcoubard 1090:148d8b9b56a5 1252 * some object.
vcoubard 1090:148d8b9b56a5 1253 *
vcoubard 1090:148d8b9b56a5 1254 * @Note It is possible to unregister a callback using onShutdown().detach(callback)
vcoubard 1090:148d8b9b56a5 1255 */
vcoubard 1090:148d8b9b56a5 1256 void onShutdown(const GapShutdownCallback_t& callback) {
vcoubard 1090:148d8b9b56a5 1257 shutdownCallChain.add(callback);
vcoubard 1090:148d8b9b56a5 1258 }
vcoubard 1090:148d8b9b56a5 1259 template <typename T>
vcoubard 1090:148d8b9b56a5 1260 void onShutdown(T *objPtr, void (T::*memberPtr)(void)) {
vcoubard 1090:148d8b9b56a5 1261 shutdownCallChain.add(objPtr, memberPtr);
vcoubard 1090:148d8b9b56a5 1262 }
vcoubard 1090:148d8b9b56a5 1263
vcoubard 1090:148d8b9b56a5 1264 /**
vcoubard 1090:148d8b9b56a5 1265 * @brief provide access to the callchain of shutdown event callbacks
vcoubard 1090:148d8b9b56a5 1266 * It is possible to register callbacks using onShutdown().add(callback);
vcoubard 1090:148d8b9b56a5 1267 * It is possible to unregister callbacks using onShutdown().detach(callback)
vcoubard 1090:148d8b9b56a5 1268 * @return The shutdown event callbacks chain
vcoubard 1090:148d8b9b56a5 1269 */
vcoubard 1090:148d8b9b56a5 1270 GapShutdownCallbackChain_t& onShutdown() {
vcoubard 1090:148d8b9b56a5 1271 return shutdownCallChain;
vcoubard 1090:148d8b9b56a5 1272 }
vcoubard 1090:148d8b9b56a5 1273
vcoubard 1082:127667021827 1274 public:
vcoubard 1082:127667021827 1275 /**
vcoubard 1090:148d8b9b56a5 1276 * Notify all registered onShutdown callbacks that the Gap instance is
vcoubard 1090:148d8b9b56a5 1277 * about to be shutdown and clear all Gap state of the
vcoubard 1090:148d8b9b56a5 1278 * associated object.
vcoubard 1082:127667021827 1279 *
vcoubard 1082:127667021827 1280 * This function is meant to be overridden in the platform-specific
vcoubard 1082:127667021827 1281 * sub-class. Nevertheless, the sub-class is only expected to reset its
vcoubard 1082:127667021827 1282 * state and not the data held in Gap members. This shall be achieved by a
vcoubard 1082:127667021827 1283 * call to Gap::reset() from the sub-class' reset() implementation.
vcoubard 1082:127667021827 1284 *
vcoubard 1082:127667021827 1285 * @return BLE_ERROR_NONE on success.
vcoubard 1082:127667021827 1286 *
vcoubard 1082:127667021827 1287 * @note: Currently a call to reset() does not reset the advertising and
vcoubard 1082:127667021827 1288 * scan parameters to default values.
vcoubard 1082:127667021827 1289 */
vcoubard 1082:127667021827 1290 virtual ble_error_t reset(void) {
vcoubard 1090:148d8b9b56a5 1291 /* Notify that the instance is about to shutdown */
vcoubard 1090:148d8b9b56a5 1292 shutdownCallChain.call(this);
vcoubard 1090:148d8b9b56a5 1293 shutdownCallChain.clear();
vcoubard 1090:148d8b9b56a5 1294
vcoubard 1082:127667021827 1295 /* Clear Gap state */
vcoubard 1082:127667021827 1296 state.advertising = 0;
vcoubard 1084:40c1e518d6de 1297 state.connected = 0;
vcoubard 1082:127667021827 1298
vcoubard 1082:127667021827 1299 /* Clear scanning state */
vcoubard 1082:127667021827 1300 scanningActive = false;
vcoubard 1082:127667021827 1301
vcoubard 1082:127667021827 1302 /* Clear advertising and scanning data */
vcoubard 1082:127667021827 1303 _advPayload.clear();
vcoubard 1082:127667021827 1304 _scanResponse.clear();
vcoubard 1082:127667021827 1305
vcoubard 1082:127667021827 1306 /* Clear callbacks */
vcoubard 1082:127667021827 1307 timeoutCallbackChain.clear();
vcoubard 1082:127667021827 1308 connectionCallChain.clear();
vcoubard 1082:127667021827 1309 disconnectionCallChain.clear();
vcoubard 1082:127667021827 1310 radioNotificationCallback = NULL;
vcoubard 1084:40c1e518d6de 1311 onAdvertisementReport = NULL;
vcoubard 1082:127667021827 1312
vcoubard 1082:127667021827 1313 return BLE_ERROR_NONE;
vcoubard 1082:127667021827 1314 }
vcoubard 1082:127667021827 1315
rgrover1 710:b2e1a2660ec2 1316 protected:
rgrover1 710:b2e1a2660ec2 1317 Gap() :
rgrover1 710:b2e1a2660ec2 1318 _advParams(),
rgrover1 710:b2e1a2660ec2 1319 _advPayload(),
rgrover1 710:b2e1a2660ec2 1320 _scanningParams(),
rgrover1 710:b2e1a2660ec2 1321 _scanResponse(),
rgrover1 710:b2e1a2660ec2 1322 state(),
rgrover1 770:079b714e9c1a 1323 scanningActive(false),
vcoubard 1052:b55e1ad3e1b3 1324 timeoutCallbackChain(),
rgrover1 710:b2e1a2660ec2 1325 radioNotificationCallback(),
rgrover1 710:b2e1a2660ec2 1326 onAdvertisementReport(),
rgrover1 816:2b4f0ef8c06e 1327 connectionCallChain(),
rgrover1 710:b2e1a2660ec2 1328 disconnectionCallChain() {
rgrover1 710:b2e1a2660ec2 1329 _advPayload.clear();
rgrover1 710:b2e1a2660ec2 1330 _scanResponse.clear();
rgrover1 710:b2e1a2660ec2 1331 }
rgrover1 710:b2e1a2660ec2 1332
rgrover1 710:b2e1a2660ec2 1333 /* Entry points for the underlying stack to report events back to the user. */
rgrover1 710:b2e1a2660ec2 1334 public:
vcoubard 1119:7a487d506451 1335 void processConnectionEvent(Handle_t handle,
vcoubard 1119:7a487d506451 1336 Role_t role,
vcoubard 1119:7a487d506451 1337 BLEProtocol::AddressType_t peerAddrType,
vcoubard 1115:82d4a8a56d91 1338 const BLEProtocol::AddressBytes_t peerAddr,
vcoubard 1119:7a487d506451 1339 BLEProtocol::AddressType_t ownAddrType,
vcoubard 1115:82d4a8a56d91 1340 const BLEProtocol::AddressBytes_t ownAddr,
vcoubard 1119:7a487d506451 1341 const ConnectionParams_t *connectionParams) {
rgrover1 710:b2e1a2660ec2 1342 state.connected = 1;
rgrover1 829:9072de50087b 1343 ConnectionCallbackParams_t callbackParams(handle, role, peerAddrType, peerAddr, ownAddrType, ownAddr, connectionParams);
rgrover1 829:9072de50087b 1344 connectionCallChain.call(&callbackParams);
rgrover1 710:b2e1a2660ec2 1345 }
rgrover1 710:b2e1a2660ec2 1346
rgrover1 710:b2e1a2660ec2 1347 void processDisconnectionEvent(Handle_t handle, DisconnectionReason_t reason) {
rgrover1 710:b2e1a2660ec2 1348 state.connected = 0;
rgrover1 829:9072de50087b 1349 DisconnectionCallbackParams_t callbackParams(handle, reason);
rgrover1 829:9072de50087b 1350 disconnectionCallChain.call(&callbackParams);
rgrover1 710:b2e1a2660ec2 1351 }
rgrover1 710:b2e1a2660ec2 1352
vcoubard 1119:7a487d506451 1353 void processAdvertisementReport(const BLEProtocol::AddressBytes_t peerAddr,
vcoubard 1079:6e2d9514f3df 1354 int8_t rssi,
vcoubard 1079:6e2d9514f3df 1355 bool isScanResponse,
rgrover1 710:b2e1a2660ec2 1356 GapAdvertisingParams::AdvertisingType_t type,
vcoubard 1079:6e2d9514f3df 1357 uint8_t advertisingDataLen,
vcoubard 1079:6e2d9514f3df 1358 const uint8_t *advertisingData) {
rgrover1 710:b2e1a2660ec2 1359 AdvertisementCallbackParams_t params;
rgrover1 710:b2e1a2660ec2 1360 memcpy(params.peerAddr, peerAddr, ADDR_LEN);
rgrover1 710:b2e1a2660ec2 1361 params.rssi = rssi;
rgrover1 710:b2e1a2660ec2 1362 params.isScanResponse = isScanResponse;
rgrover1 710:b2e1a2660ec2 1363 params.type = type;
rgrover1 710:b2e1a2660ec2 1364 params.advertisingDataLen = advertisingDataLen;
rgrover1 710:b2e1a2660ec2 1365 params.advertisingData = advertisingData;
rgrover1 710:b2e1a2660ec2 1366 onAdvertisementReport.call(&params);
rgrover1 710:b2e1a2660ec2 1367 }
rgrover1 710:b2e1a2660ec2 1368
rgrover1 710:b2e1a2660ec2 1369 void processTimeoutEvent(TimeoutSource_t source) {
vcoubard 1052:b55e1ad3e1b3 1370 if (timeoutCallbackChain) {
vcoubard 1052:b55e1ad3e1b3 1371 timeoutCallbackChain(source);
rgrover1 710:b2e1a2660ec2 1372 }
rgrover1 710:b2e1a2660ec2 1373 }
rgrover1 710:b2e1a2660ec2 1374
rgrover1 710:b2e1a2660ec2 1375 protected:
rgrover1 710:b2e1a2660ec2 1376 GapAdvertisingParams _advParams;
rgrover1 710:b2e1a2660ec2 1377 GapAdvertisingData _advPayload;
rgrover1 710:b2e1a2660ec2 1378 GapScanningParams _scanningParams;
rgrover1 710:b2e1a2660ec2 1379 GapAdvertisingData _scanResponse;
rgrover1 710:b2e1a2660ec2 1380
rgrover1 710:b2e1a2660ec2 1381 GapState_t state;
rgrover1 770:079b714e9c1a 1382 bool scanningActive;
rgrover1 710:b2e1a2660ec2 1383
rgrover1 710:b2e1a2660ec2 1384 protected:
vcoubard 1052:b55e1ad3e1b3 1385 TimeoutEventCallbackChain_t timeoutCallbackChain;
vcoubard 1052:b55e1ad3e1b3 1386 RadioNotificationEventCallback_t radioNotificationCallback;
vcoubard 1052:b55e1ad3e1b3 1387 AdvertisementReportCallback_t onAdvertisementReport;
vcoubard 1052:b55e1ad3e1b3 1388 ConnectionEventCallbackChain_t connectionCallChain;
vcoubard 1052:b55e1ad3e1b3 1389 DisconnectionEventCallbackChain_t disconnectionCallChain;
rgrover1 710:b2e1a2660ec2 1390
rgrover1 710:b2e1a2660ec2 1391 private:
vcoubard 1090:148d8b9b56a5 1392 GapShutdownCallbackChain_t shutdownCallChain;
vcoubard 1090:148d8b9b56a5 1393
vcoubard 1090:148d8b9b56a5 1394 private:
vcoubard 1048:efb29faf12fc 1395 /* Disallow copy and assignment. */
rgrover1 710:b2e1a2660ec2 1396 Gap(const Gap &);
rgrover1 710:b2e1a2660ec2 1397 Gap& operator=(const Gap &);
rgrover1 710:b2e1a2660ec2 1398 };
rgrover1 710:b2e1a2660ec2 1399
rgrover1 710:b2e1a2660ec2 1400 #endif // ifndef __GAP_H__