High level Bluetooth Low Energy API and radio abstraction layer

Dependencies:   nRF51822

Dependents:   LinkNode_LIS3DH

Fork of BLE_API by Bluetooth Low Energy

Committer:
rgrover1
Date:
Fri Jun 19 15:51:56 2015 +0100
Revision:
445:c1e8af80a9cd
Parent:
444:0ecf7ce69172
Child:
446:4fdb01767cff
Synchronized with git rev cc30c92f
Author: Rohit Grover
pass in some useful connection paramters from connect()

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rgrover1 257:7a50601356cc 1 /* mbed Microcontroller Library
rgrover1 257:7a50601356cc 2 * Copyright (c) 2006-2013 ARM Limited
rgrover1 257:7a50601356cc 3 *
rgrover1 257:7a50601356cc 4 * Licensed under the Apache License, Version 2.0 (the "License");
rgrover1 257:7a50601356cc 5 * you may not use this file except in compliance with the License.
rgrover1 257:7a50601356cc 6 * You may obtain a copy of the License at
rgrover1 257:7a50601356cc 7 *
rgrover1 257:7a50601356cc 8 * http://www.apache.org/licenses/LICENSE-2.0
rgrover1 257:7a50601356cc 9 *
rgrover1 257:7a50601356cc 10 * Unless required by applicable law or agreed to in writing, software
rgrover1 257:7a50601356cc 11 * distributed under the License is distributed on an "AS IS" BASIS,
rgrover1 257:7a50601356cc 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
rgrover1 257:7a50601356cc 13 * See the License for the specific language governing permissions and
rgrover1 257:7a50601356cc 14 * limitations under the License.
rgrover1 257:7a50601356cc 15 */
rgrover1 257:7a50601356cc 16
rgrover1 257:7a50601356cc 17 #ifndef __BLE_DEVICE__
rgrover1 257:7a50601356cc 18 #define __BLE_DEVICE__
rgrover1 257:7a50601356cc 19
rgrover1 257:7a50601356cc 20 #include "blecommon.h"
rgrover1 257:7a50601356cc 21 #include "Gap.h"
rgrover1 257:7a50601356cc 22 #include "GattServer.h"
rgrover1 434:bd1f1cc10277 23 #include "BLEDeviceInstanceBase.h"
rgrover1 434:bd1f1cc10277 24
rgrover1 434:bd1f1cc10277 25 #include "GapAdvertisingData.h"
rgrover1 434:bd1f1cc10277 26 #include "GapAdvertisingParams.h"
rgrover1 380:2109a08c311c 27 #include "GapScanningParams.h"
rgrover1 434:bd1f1cc10277 28
rgrover1 257:7a50601356cc 29
rgrover1 257:7a50601356cc 30 /**
rgrover1 257:7a50601356cc 31 * The base class used to abstract away BLE capable radio transceivers or SOCs,
rgrover1 257:7a50601356cc 32 * to enable this BLE API to work with any radio transparently.
rgrover1 257:7a50601356cc 33 */
rgrover1 257:7a50601356cc 34 class BLEDevice
rgrover1 257:7a50601356cc 35 {
rgrover1 257:7a50601356cc 36 public:
rgrover1 257:7a50601356cc 37 /**
rgrover1 257:7a50601356cc 38 * Initialize the BLE controller. This should be called before using
rgrover1 257:7a50601356cc 39 * anything else in the BLE_API.
rgrover1 411:cf2cce37ad73 40 *
rgrover1 411:cf2cce37ad73 41 * init() hands control to the underlying BLE module to accomplish
rgrover1 411:cf2cce37ad73 42 * initialization. This initialization may tacitly depend on other hardware
rgrover1 411:cf2cce37ad73 43 * setup (such as clocks or power-modes) which happens early on during
rgrover1 411:cf2cce37ad73 44 * system startup. It may not be safe to call init() from global static
rgrover1 411:cf2cce37ad73 45 * context where ordering is compiler specific and can't be guaranteed--it
rgrover1 411:cf2cce37ad73 46 * is safe to call BLEDevice::init() from within main().
rgrover1 257:7a50601356cc 47 */
rgrover1 257:7a50601356cc 48 ble_error_t init();
rgrover1 411:cf2cce37ad73 49
rgrover1 257:7a50601356cc 50 ble_error_t reset(void);
rgrover1 257:7a50601356cc 51
rgrover1 257:7a50601356cc 52 /**
rgrover1 257:7a50601356cc 53 * Purge the BLE stack of GATT and GAP state. init() must be called afterwards to re-instate services and GAP state.
rgrover1 257:7a50601356cc 54 */
rgrover1 257:7a50601356cc 55 ble_error_t shutdown(void);
rgrover1 257:7a50601356cc 56
rgrover1 257:7a50601356cc 57 /* GAP specific APIs */
rgrover1 257:7a50601356cc 58 public:
rgrover1 257:7a50601356cc 59 /**
rgrover1 257:7a50601356cc 60 * Set the BTLE MAC address and type.
rgrover1 257:7a50601356cc 61 * @return BLE_ERROR_NONE on success.
rgrover1 257:7a50601356cc 62 */
rgrover1 424:370d5f1f292f 63 ble_error_t setAddress(Gap::AddressType_t type, const Gap::address_t address);
rgrover1 257:7a50601356cc 64
rgrover1 257:7a50601356cc 65 /**
rgrover1 257:7a50601356cc 66 * Fetch the BTLE MAC address and type.
rgrover1 257:7a50601356cc 67 * @return BLE_ERROR_NONE on success.
rgrover1 257:7a50601356cc 68 */
rgrover1 424:370d5f1f292f 69 ble_error_t getAddress(Gap::AddressType_t *typeP, Gap::address_t address);
rgrover1 257:7a50601356cc 70
rgrover1 257:7a50601356cc 71 /**
rgrover1 257:7a50601356cc 72 * @param[in] advType
rgrover1 257:7a50601356cc 73 * The GAP advertising mode to use for this device. Valid
rgrover1 257:7a50601356cc 74 * values are defined in AdvertisingType:
rgrover1 257:7a50601356cc 75 *
rgrover1 257:7a50601356cc 76 * \par ADV_NON_CONNECTABLE_UNDIRECTED
rgrover1 257:7a50601356cc 77 * All connections to the peripheral device will be refused.
rgrover1 257:7a50601356cc 78 *
rgrover1 257:7a50601356cc 79 * \par ADV_CONNECTABLE_DIRECTED
rgrover1 257:7a50601356cc 80 * Only connections from a pre-defined central device will be
rgrover1 257:7a50601356cc 81 * accepted.
rgrover1 257:7a50601356cc 82 *
rgrover1 257:7a50601356cc 83 * \par ADV_CONNECTABLE_UNDIRECTED
rgrover1 257:7a50601356cc 84 * Any central device can connect to this peripheral.
rgrover1 257:7a50601356cc 85 *
rgrover1 257:7a50601356cc 86 * \par ADV_SCANNABLE_UNDIRECTED
rgrover1 300:d9a39f759a6a 87 * Include support for Scan Response payloads.
rgrover1 257:7a50601356cc 88 *
rgrover1 257:7a50601356cc 89 * \par
rgrover1 257:7a50601356cc 90 * See Bluetooth Core Specification 4.0 (Vol. 3), Part C,
rgrover1 257:7a50601356cc 91 * Section 9.3 and Core Specification 4.0 (Vol. 6), Part B,
rgrover1 257:7a50601356cc 92 * Section 2.3.1 for further information on GAP connection
rgrover1 257:7a50601356cc 93 * modes
rgrover1 257:7a50601356cc 94 */
rgrover1 257:7a50601356cc 95 void setAdvertisingType(GapAdvertisingParams::AdvertisingType);
rgrover1 257:7a50601356cc 96
rgrover1 257:7a50601356cc 97 /**
rgrover1 257:7a50601356cc 98 * @param[in] interval
rgrover1 325:501ad8b8bbe5 99 * Advertising interval in units of milliseconds. Advertising
rgrover1 325:501ad8b8bbe5 100 * is disabled if interval is 0. If interval is smaller than
rgrover1 325:501ad8b8bbe5 101 * the minimum supported value, then the minimum supported
rgrover1 325:501ad8b8bbe5 102 * value is used instead.
rgrover1 257:7a50601356cc 103 *
rgrover1 257:7a50601356cc 104 * \par
rgrover1 257:7a50601356cc 105 * Decreasing this value will allow central devices to detect
rgrover1 257:7a50601356cc 106 * your peripheral faster at the expense of more power being
rgrover1 257:7a50601356cc 107 * used by the radio due to the higher data transmit rate.
rgrover1 257:7a50601356cc 108 *
rgrover1 257:7a50601356cc 109 * \par
rgrover1 257:7a50601356cc 110 * This field must be set to 0 if connectionMode is equal
rgrover1 257:7a50601356cc 111 * to ADV_CONNECTABLE_DIRECTED
rgrover1 257:7a50601356cc 112 *
rgrover1 257:7a50601356cc 113 * \par
rgrover1 257:7a50601356cc 114 * See Bluetooth Core Specification, Vol 3., Part C,
rgrover1 257:7a50601356cc 115 * Appendix A for suggested advertising intervals.
rgrover1 334:6bc1223306b9 116 *
rgrover1 334:6bc1223306b9 117 * @Note: [WARNING] This API previously used 0.625ms as the unit for its
rgrover1 334:6bc1223306b9 118 * 'interval' argument. That required an explicit conversion from
rgrover1 334:6bc1223306b9 119 * milliseconds using Gap::MSEC_TO_GAP_DURATION_UNITS(). This conversion is
rgrover1 334:6bc1223306b9 120 * no longer required as the new units are milliseconds. Any application
rgrover1 334:6bc1223306b9 121 * code depending on the old semantics would need to be updated accordingly.
rgrover1 257:7a50601356cc 122 */
rgrover1 257:7a50601356cc 123 void setAdvertisingInterval(uint16_t interval);
rgrover1 257:7a50601356cc 124
rgrover1 257:7a50601356cc 125 /**
rgrover1 325:501ad8b8bbe5 126 * @return Minimum Advertising interval in milliseconds.
rgrover1 325:501ad8b8bbe5 127 */
rgrover1 325:501ad8b8bbe5 128 uint16_t getMinAdvertisingInterval(void) const;
rgrover1 325:501ad8b8bbe5 129 /**
rgrover1 325:501ad8b8bbe5 130 * @return Minimum Advertising interval in milliseconds for non connectible mode.
rgrover1 325:501ad8b8bbe5 131 */
rgrover1 325:501ad8b8bbe5 132 uint16_t getMinNonConnectableAdvertisingInterval(void) const;
rgrover1 325:501ad8b8bbe5 133 /**
rgrover1 325:501ad8b8bbe5 134 * @return Maximum Advertising interval in milliseconds.
rgrover1 325:501ad8b8bbe5 135 */
rgrover1 325:501ad8b8bbe5 136 uint16_t getMaxAdvertisingInterval(void) const;
rgrover1 325:501ad8b8bbe5 137
rgrover1 325:501ad8b8bbe5 138 /**
rgrover1 257:7a50601356cc 139 * @param[in] timeout
rgrover1 257:7a50601356cc 140 * Advertising timeout between 0x1 and 0x3FFF (1 and 16383)
rgrover1 257:7a50601356cc 141 * in seconds. Enter 0 to disable the advertising timeout.
rgrover1 257:7a50601356cc 142 */
rgrover1 257:7a50601356cc 143 void setAdvertisingTimeout(uint16_t timeout);
rgrover1 257:7a50601356cc 144
rgrover1 257:7a50601356cc 145 /**
rgrover1 257:7a50601356cc 146 * Please refer to the APIs above.
rgrover1 257:7a50601356cc 147 */
rgrover1 257:7a50601356cc 148 void setAdvertisingParams(const GapAdvertisingParams &advParams);
rgrover1 257:7a50601356cc 149
rgrover1 257:7a50601356cc 150 /**
rgrover1 409:37a4202649dd 151 * @return Read back advertising parameters. Useful for storing and
rgrover1 409:37a4202649dd 152 * restoring parameters rapidly.
rgrover1 409:37a4202649dd 153 */
rgrover1 410:af8f2d1b67b6 154 const GapAdvertisingParams &getAdvertisingParams(void) const;
rgrover1 409:37a4202649dd 155
rgrover1 409:37a4202649dd 156 /**
rgrover1 257:7a50601356cc 157 * This API is typically used as an internal helper to udpate the transport
rgrover1 257:7a50601356cc 158 * backend with advertising data before starting to advertise. It may also
rgrover1 257:7a50601356cc 159 * be explicity used to dynamically reset the accumulated advertising
rgrover1 257:7a50601356cc 160 * payload and scanResponse; to do this, the application can clear and re-
rgrover1 257:7a50601356cc 161 * accumulate a new advertising payload (and scanResponse) before using this
rgrover1 257:7a50601356cc 162 * API.
rgrover1 257:7a50601356cc 163 */
rgrover1 257:7a50601356cc 164 ble_error_t setAdvertisingPayload(void);
rgrover1 257:7a50601356cc 165
rgrover1 257:7a50601356cc 166 /**
rgrover1 409:37a4202649dd 167 * Set advertising data using object.
rgrover1 409:37a4202649dd 168 */
rgrover1 409:37a4202649dd 169 ble_error_t setAdvertisingData(const GapAdvertisingData &advData);
rgrover1 409:37a4202649dd 170
rgrover1 409:37a4202649dd 171 /**
rgrover1 409:37a4202649dd 172 * @return Read back advertising data. Useful for storing and
rgrover1 409:37a4202649dd 173 * restoring payload.
rgrover1 409:37a4202649dd 174 */
rgrover1 410:af8f2d1b67b6 175 const GapAdvertisingData &getAdvertisingData(void) const;
rgrover1 409:37a4202649dd 176
rgrover1 409:37a4202649dd 177 /**
rgrover1 257:7a50601356cc 178 * Reset any advertising payload prepared from prior calls to
rgrover1 257:7a50601356cc 179 * accumulateAdvertisingPayload().
rgrover1 343:4d2576324b62 180 *
rgrover1 343:4d2576324b62 181 * Note: This should be followed by a call to setAdvertisingPayload() or
rgrover1 343:4d2576324b62 182 * startAdvertising() before the update takes effect.
rgrover1 257:7a50601356cc 183 */
rgrover1 257:7a50601356cc 184 void clearAdvertisingPayload(void);
rgrover1 257:7a50601356cc 185
rgrover1 257:7a50601356cc 186 /**
rgrover1 257:7a50601356cc 187 * Accumulate an AD structure in the advertising payload. Please note that
rgrover1 257:7a50601356cc 188 * the payload is limited to 31 bytes. The SCAN_RESPONSE message may be used
rgrover1 257:7a50601356cc 189 * as an additional 31 bytes if the advertising payload proves to be too
rgrover1 257:7a50601356cc 190 * small.
rgrover1 257:7a50601356cc 191 *
rgrover1 257:7a50601356cc 192 * @param flags
rgrover1 257:7a50601356cc 193 * The flags to be added. Multiple flags may be specified in
rgrover1 257:7a50601356cc 194 * combination.
rgrover1 257:7a50601356cc 195 */
rgrover1 257:7a50601356cc 196 ble_error_t accumulateAdvertisingPayload(uint8_t flags);
rgrover1 257:7a50601356cc 197
rgrover1 257:7a50601356cc 198 /**
rgrover1 257:7a50601356cc 199 * Accumulate an AD structure in the advertising payload. Please note that
rgrover1 257:7a50601356cc 200 * the payload is limited to 31 bytes. The SCAN_RESPONSE message may be used
rgrover1 257:7a50601356cc 201 * as an additional 31 bytes if the advertising payload proves to be too
rgrover1 257:7a50601356cc 202 * small.
rgrover1 257:7a50601356cc 203 *
rgrover1 257:7a50601356cc 204 * @param app
rgrover1 257:7a50601356cc 205 * The appearance of the peripheral.
rgrover1 257:7a50601356cc 206 */
rgrover1 257:7a50601356cc 207 ble_error_t accumulateAdvertisingPayload(GapAdvertisingData::Appearance app);
rgrover1 257:7a50601356cc 208
rgrover1 257:7a50601356cc 209 /**
rgrover1 257:7a50601356cc 210 * Accumulate an AD structure in the advertising payload. Please note that
rgrover1 257:7a50601356cc 211 * the payload is limited to 31 bytes. The SCAN_RESPONSE message may be used
rgrover1 257:7a50601356cc 212 * as an additional 31 bytes if the advertising payload proves to be too
rgrover1 257:7a50601356cc 213 * small.
rgrover1 257:7a50601356cc 214 *
rgrover1 257:7a50601356cc 215 * @param app
rgrover1 257:7a50601356cc 216 * The max transmit power to be used by the controller. This is
rgrover1 257:7a50601356cc 217 * only a hint.
rgrover1 257:7a50601356cc 218 */
rgrover1 257:7a50601356cc 219 ble_error_t accumulateAdvertisingPayloadTxPower(int8_t power);
rgrover1 257:7a50601356cc 220
rgrover1 257:7a50601356cc 221 /**
rgrover1 257:7a50601356cc 222 * Accumulate a variable length byte-stream as an AD structure in the
rgrover1 257:7a50601356cc 223 * advertising payload. Please note that the payload is limited to 31 bytes.
rgrover1 257:7a50601356cc 224 * The SCAN_RESPONSE message may be used as an additional 31 bytes if the
rgrover1 257:7a50601356cc 225 * advertising payload proves to be too small.
rgrover1 257:7a50601356cc 226 *
rgrover1 257:7a50601356cc 227 * @param type The type which describes the variable length data.
rgrover1 257:7a50601356cc 228 * @param data data bytes.
rgrover1 257:7a50601356cc 229 * @param len length of data.
rgrover1 257:7a50601356cc 230 */
rgrover1 257:7a50601356cc 231 ble_error_t accumulateAdvertisingPayload(GapAdvertisingData::DataType type, const uint8_t *data, uint8_t len);
rgrover1 257:7a50601356cc 232
rgrover1 257:7a50601356cc 233 /**
rgrover1 257:7a50601356cc 234 * Accumulate a variable length byte-stream as an AD structure in the
rgrover1 257:7a50601356cc 235 * scanResponse payload.
rgrover1 257:7a50601356cc 236 *
rgrover1 257:7a50601356cc 237 * @param type The type which describes the variable length data.
rgrover1 257:7a50601356cc 238 * @param data data bytes.
rgrover1 257:7a50601356cc 239 * @param len length of data.
rgrover1 257:7a50601356cc 240 */
rgrover1 257:7a50601356cc 241 ble_error_t accumulateScanResponse(GapAdvertisingData::DataType type, const uint8_t *data, uint8_t len);
rgrover1 257:7a50601356cc 242
rgrover1 257:7a50601356cc 243 /**
rgrover1 343:4d2576324b62 244 * Reset any scan response prepared from prior calls to
rgrover1 343:4d2576324b62 245 * accumulateScanResponse().
rgrover1 343:4d2576324b62 246 *
rgrover1 343:4d2576324b62 247 * Note: This should be followed by a call to setAdvertisingPayload() or
rgrover1 343:4d2576324b62 248 * startAdvertising() before the update takes effect.
rgrover1 343:4d2576324b62 249 */
rgrover1 343:4d2576324b62 250 void clearScanResponse(void);
rgrover1 343:4d2576324b62 251
rgrover1 343:4d2576324b62 252 /**
rgrover1 257:7a50601356cc 253 * Start advertising (GAP Discoverable, Connectable modes, Broadcast
rgrover1 257:7a50601356cc 254 * Procedure).
rgrover1 257:7a50601356cc 255 */
rgrover1 257:7a50601356cc 256 ble_error_t startAdvertising(void);
rgrover1 257:7a50601356cc 257
rgrover1 257:7a50601356cc 258 /**
rgrover1 257:7a50601356cc 259 * Stop advertising (GAP Discoverable, Connectable modes, Broadcast
rgrover1 257:7a50601356cc 260 * Procedure).
rgrover1 257:7a50601356cc 261 */
rgrover1 257:7a50601356cc 262 ble_error_t stopAdvertising(void);
rgrover1 257:7a50601356cc 263
rgrover1 335:dea9e14b7ddc 264 /**
rgrover1 380:2109a08c311c 265 * Setup parameters for GAP scanning--i.e. observer mode.
rgrover1 380:2109a08c311c 266 * @param interval Scan interval (in milliseconds) [valid values lie between 2.5ms and 10.24s].
rgrover1 380:2109a08c311c 267 * @param window Scan Window (in milliseconds) [valid values lie between 2.5ms and 10.24s].
rgrover1 380:2109a08c311c 268 * @param timeout Scan timeout (in seconds) between 0x0001 and 0xFFFF, 0x0000 disables timeout.
rgrover1 396:039ee79c9924 269 * @param activeScanning Set to True if active-scanning is required. This is used to fetch the
rgrover1 396:039ee79c9924 270 * scan response from a peer if possible.
rgrover1 390:4bf41689c7f9 271 *
rgrover1 390:4bf41689c7f9 272 * The scanning window divided by the interval determines the duty cycle for
rgrover1 390:4bf41689c7f9 273 * scanning. For example, if the interval is 100ms and the window is 10ms,
rgrover1 390:4bf41689c7f9 274 * then the controller will scan for 10 percent of the time. It is possible
rgrover1 390:4bf41689c7f9 275 * to have the interval and window set to the same value. In this case,
rgrover1 390:4bf41689c7f9 276 * scanning is continuous, with a change of scanning frequency once every
rgrover1 390:4bf41689c7f9 277 * interval.
rgrover1 390:4bf41689c7f9 278 *
rgrover1 390:4bf41689c7f9 279 * Once the scanning parameters have been configured, scanning can be
rgrover1 390:4bf41689c7f9 280 * enabled by using startScan().
rgrover1 390:4bf41689c7f9 281 *
rgrover1 390:4bf41689c7f9 282 * @Note: The scan interval and window are recommendations to the BLE stack.
rgrover1 380:2109a08c311c 283 */
rgrover1 394:598368c24bbb 284 ble_error_t setScanParams(uint16_t interval = GapScanningParams::SCAN_INTERVAL_MAX,
rgrover1 394:598368c24bbb 285 uint16_t window = GapScanningParams::SCAN_WINDOW_MAX,
rgrover1 394:598368c24bbb 286 uint16_t timeout = 0,
rgrover1 394:598368c24bbb 287 bool activeScanning = false);
rgrover1 392:3201f029c2eb 288 ble_error_t setScanInterval(uint16_t interval);
rgrover1 392:3201f029c2eb 289 ble_error_t setScanWindow (uint16_t window);
rgrover1 392:3201f029c2eb 290 ble_error_t setScanTimeout (uint16_t timeout);
rgrover1 395:4124520c17fc 291 void setActiveScan (bool activeScanning);
rgrover1 380:2109a08c311c 292
rgrover1 380:2109a08c311c 293 /**
rgrover1 380:2109a08c311c 294 * Start scanning (Observer Procedure) based on the scan-params currently
rgrover1 380:2109a08c311c 295 * in effect.
rgrover1 380:2109a08c311c 296 *
rgrover1 380:2109a08c311c 297 * @param callback The application callback to be invoked upon receiving
rgrover1 380:2109a08c311c 298 * every advertisement report. Can be passed in as NULL, in which case
rgrover1 380:2109a08c311c 299 * scanning may not be enabled at all.
rgrover1 380:2109a08c311c 300 */
rgrover1 406:cec6778acc66 301 ble_error_t startScan(void (*callback)(const Gap::AdvertisementCallbackParams_t *params));
rgrover1 380:2109a08c311c 302
rgrover1 380:2109a08c311c 303 /**
rgrover1 407:ca6b956b33d1 304 * Start scanning (Observer Procedure) based on the scan-params currently
rgrover1 407:ca6b956b33d1 305 * in effect.
rgrover1 407:ca6b956b33d1 306 *
rgrover1 407:ca6b956b33d1 307 * @param[in] object
rgrover1 407:ca6b956b33d1 308 * @param[in] callbackMember
rgrover1 407:ca6b956b33d1 309 * The above pair of parameters define the callback object
rgrover1 407:ca6b956b33d1 310 * and member function to receive the advertisement params.
rgrover1 407:ca6b956b33d1 311 */
rgrover1 407:ca6b956b33d1 312 template<typename T>
rgrover1 407:ca6b956b33d1 313 ble_error_t startScan(T *object, void (T::*memberCallback)(const Gap::AdvertisementCallbackParams_t *params));
rgrover1 407:ca6b956b33d1 314
rgrover1 407:ca6b956b33d1 315 /**
rgrover1 380:2109a08c311c 316 * Stop scanning. The current scanning parameters remain in effect.
rgrover1 380:2109a08c311c 317 *
rgrover1 380:2109a08c311c 318 * @retval BLE_ERROR_NONE if successfully stopped scanning procedure.
rgrover1 380:2109a08c311c 319 */
rgrover1 392:3201f029c2eb 320 ble_error_t stopScan(void);
rgrover1 380:2109a08c311c 321
rgrover1 441:2d864886aeca 322 ble_error_t connect(const Gap::Address_t peerAddr, Gap::AddressType_t peerAddrType = Gap::ADDR_TYPE_RANDOM_STATIC);
rgrover1 442:c120ffca22fa 323 ble_error_t connect(const Gap::Address_t peerAddr, Gap::AddressType_t peerAddrType, const GapScanningParams &scanParams);
rgrover1 441:2d864886aeca 324
rgrover1 380:2109a08c311c 325 /**
rgrover1 335:dea9e14b7ddc 326 * This call initiates the disconnection procedure, and its completion will
rgrover1 335:dea9e14b7ddc 327 * be communicated to the application with an invocation of the
rgrover1 335:dea9e14b7ddc 328 * onDisconnection callback.
rgrover1 335:dea9e14b7ddc 329 *
rgrover1 335:dea9e14b7ddc 330 * @param reason
rgrover1 335:dea9e14b7ddc 331 * The reason for disconnection to be sent back to the peer.
rgrover1 335:dea9e14b7ddc 332 */
rgrover1 257:7a50601356cc 333 ble_error_t disconnect(Gap::DisconnectionReason_t reason);
rgrover1 257:7a50601356cc 334
rgrover1 257:7a50601356cc 335 /* APIs to set GAP callbacks. */
rgrover1 257:7a50601356cc 336 void onTimeout(Gap::EventCallback_t timeoutCallback);
rgrover1 257:7a50601356cc 337
rgrover1 257:7a50601356cc 338 void onConnection(Gap::ConnectionEventCallback_t connectionCallback);
rgrover1 257:7a50601356cc 339 /**
rgrover1 257:7a50601356cc 340 * Used to setup a callback for GAP disconnection.
rgrover1 257:7a50601356cc 341 */
rgrover1 257:7a50601356cc 342 void onDisconnection(Gap::DisconnectionEventCallback_t disconnectionCallback);
rgrover1 257:7a50601356cc 343
rgrover1 257:7a50601356cc 344 /**
rgrover1 257:7a50601356cc 345 * Append to a chain of callbacks to be invoked upon disconnection; these
rgrover1 257:7a50601356cc 346 * callbacks receive no context and are therefore different from the
rgrover1 257:7a50601356cc 347 * onDisconnection callback.
rgrover1 257:7a50601356cc 348 */
rgrover1 257:7a50601356cc 349 template<typename T>
rgrover1 257:7a50601356cc 350 void addToDisconnectionCallChain(T *tptr, void (T::*mptr)(void));
rgrover1 257:7a50601356cc 351
rgrover1 257:7a50601356cc 352 /**
rgrover1 261:b275bfc773b9 353 * Add a callback for the GATT event DATA_SENT (which is triggered when
rgrover1 261:b275bfc773b9 354 * updates are sent out by GATT in the form of notifications).
rgrover1 259:a95264ad705c 355 *
rgrover1 259:a95264ad705c 356 * @Note: it is possible to chain together multiple onDataSent callbacks
rgrover1 259:a95264ad705c 357 * (potentially from different modules of an application) to receive updates
rgrover1 260:ea7f9f14cc15 358 * to characteristics.
rgrover1 259:a95264ad705c 359 *
rgrover1 259:a95264ad705c 360 * @Note: it is also possible to setup a callback into a member function of
rgrover1 259:a95264ad705c 361 * some object.
rgrover1 257:7a50601356cc 362 */
rgrover1 259:a95264ad705c 363 void onDataSent(void (*callback)(unsigned count));
rgrover1 259:a95264ad705c 364 template <typename T> void onDataSent(T * objPtr, void (T::*memberPtr)(unsigned count));
rgrover1 257:7a50601356cc 365
rgrover1 257:7a50601356cc 366 /**
rgrover1 257:7a50601356cc 367 * Setup a callback for when a characteristic has its value updated by a
rgrover1 257:7a50601356cc 368 * client.
rgrover1 257:7a50601356cc 369 *
rgrover1 257:7a50601356cc 370 * @Note: it is possible to chain together multiple onDataWritten callbacks
rgrover1 257:7a50601356cc 371 * (potentially from different modules of an application) to receive updates
rgrover1 257:7a50601356cc 372 * to characteristics. Many services, such as DFU and UART add their own
rgrover1 257:7a50601356cc 373 * onDataWritten callbacks behind the scenes to trap interesting events.
rgrover1 257:7a50601356cc 374 *
rgrover1 257:7a50601356cc 375 * @Note: it is also possible to setup a callback into a member function of
rgrover1 257:7a50601356cc 376 * some object.
rgrover1 257:7a50601356cc 377 */
rgrover1 257:7a50601356cc 378 void onDataWritten(void (*callback)(const GattCharacteristicWriteCBParams *eventDataP));
rgrover1 257:7a50601356cc 379 template <typename T> void onDataWritten(T * objPtr, void (T::*memberPtr)(const GattCharacteristicWriteCBParams *context));
rgrover1 257:7a50601356cc 380
rgrover1 300:d9a39f759a6a 381 /**
rgrover1 300:d9a39f759a6a 382 * Setup a callback for when a characteristic is being read by a client.
rgrover1 300:d9a39f759a6a 383 *
rgrover1 300:d9a39f759a6a 384 * @Note: this functionality may not be available on all underlying stacks.
rgrover1 300:d9a39f759a6a 385 * You could use GattCharacteristic::setReadAuthorizationCallback() as an
rgrover1 300:d9a39f759a6a 386 * alternative.
rgrover1 300:d9a39f759a6a 387 *
rgrover1 300:d9a39f759a6a 388 * @Note: it is possible to chain together multiple onDataRead callbacks
rgrover1 300:d9a39f759a6a 389 * (potentially from different modules of an application) to receive updates
rgrover1 300:d9a39f759a6a 390 * to characteristics. Services may add their own onDataRead callbacks
rgrover1 300:d9a39f759a6a 391 * behind the scenes to trap interesting events.
rgrover1 300:d9a39f759a6a 392 *
rgrover1 300:d9a39f759a6a 393 * @Note: it is also possible to setup a callback into a member function of
rgrover1 300:d9a39f759a6a 394 * some object.
rgrover1 300:d9a39f759a6a 395 *
rgrover1 300:d9a39f759a6a 396 * @return BLE_ERROR_NOT_IMPLEMENTED if this functionality isn't available;
rgrover1 300:d9a39f759a6a 397 * else BLE_ERROR_NONE.
rgrover1 300:d9a39f759a6a 398 */
rgrover1 300:d9a39f759a6a 399 ble_error_t onDataRead(void (*callback)(const GattCharacteristicReadCBParams *eventDataP));
rgrover1 300:d9a39f759a6a 400 template <typename T> ble_error_t onDataRead(T * objPtr, void (T::*memberPtr)(const GattCharacteristicReadCBParams *context));
rgrover1 300:d9a39f759a6a 401
rgrover1 257:7a50601356cc 402 void onUpdatesEnabled(GattServer::EventCallback_t callback);
rgrover1 257:7a50601356cc 403 void onUpdatesDisabled(GattServer::EventCallback_t callback);
rgrover1 257:7a50601356cc 404 void onConfirmationReceived(GattServer::EventCallback_t callback);
rgrover1 257:7a50601356cc 405
rgrover1 257:7a50601356cc 406 /**
rgrover1 341:8a104d9d80c1 407 * Radio Notification is a feature that enables ACTIVE and INACTIVE
rgrover1 341:8a104d9d80c1 408 * (nACTIVE) signals from the stack that notify the application when the
rgrover1 341:8a104d9d80c1 409 * radio is in use. The signal is sent using software interrupt.
rgrover1 341:8a104d9d80c1 410 *
rgrover1 341:8a104d9d80c1 411 * The ACTIVE signal is sent before the Radio Event starts. The nACTIVE
rgrover1 341:8a104d9d80c1 412 * signal is sent at the end of the Radio Event. These signals can be used
rgrover1 341:8a104d9d80c1 413 * by the application programmer to synchronize application logic with radio
rgrover1 341:8a104d9d80c1 414 * activity. For example, the ACTIVE signal can be used to shut off external
rgrover1 341:8a104d9d80c1 415 * devices to manage peak current drawn during periods when the radio is on,
rgrover1 341:8a104d9d80c1 416 * or to trigger sensor data collection for transmission in the Radio Event.
rgrover1 341:8a104d9d80c1 417 *
rgrover1 341:8a104d9d80c1 418 * @param callback
rgrover1 341:8a104d9d80c1 419 * The application handler to be invoked in response to a radio
rgrover1 341:8a104d9d80c1 420 * ACTIVE/INACTIVE event.
rgrover1 341:8a104d9d80c1 421 */
rgrover1 341:8a104d9d80c1 422 void onRadioNotification(Gap::RadioNotificationEventCallback_t callback);
rgrover1 341:8a104d9d80c1 423
rgrover1 341:8a104d9d80c1 424 /**
rgrover1 257:7a50601356cc 425 * Add a service declaration to the local server ATT table. Also add the
rgrover1 257:7a50601356cc 426 * characteristics contained within.
rgrover1 257:7a50601356cc 427 */
rgrover1 257:7a50601356cc 428 ble_error_t addService(GattService &service);
rgrover1 257:7a50601356cc 429
rgrover1 336:896e159d3af6 430 /**
rgrover1 336:896e159d3af6 431 * Returns the current GAP state of the device using a bitmask which
rgrover1 336:896e159d3af6 432 * describes whether the device is advertising and/or connected.
rgrover1 336:896e159d3af6 433 */
rgrover1 257:7a50601356cc 434 Gap::GapState_t getGapState(void) const;
rgrover1 257:7a50601356cc 435
rgrover1 257:7a50601356cc 436 /**
rgrover1 257:7a50601356cc 437 * @param[in/out] lengthP
rgrover1 257:7a50601356cc 438 * input: Length in bytes to be read,
rgrover1 257:7a50601356cc 439 * output: Total length of attribute value upon successful return.
rgrover1 257:7a50601356cc 440 */
rgrover1 328:1fd12f67ed7a 441 ble_error_t readCharacteristicValue(GattAttribute::Handle_t attributeHandle, uint8_t *buffer, uint16_t *lengthP);
rgrover1 342:152bd9c825d6 442 /**
rgrover1 342:152bd9c825d6 443 * A version of the same as above with connection handle parameter to allow fetches for connection-specific multivalued attribtues (such as the CCCDs).
rgrover1 342:152bd9c825d6 444 */
rgrover1 342:152bd9c825d6 445 ble_error_t readCharacteristicValue(Gap::Handle_t connectionHandle, GattAttribute::Handle_t attributeHandle, uint8_t *buffer, uint16_t *lengthP);
rgrover1 257:7a50601356cc 446
rgrover1 257:7a50601356cc 447 /**
rgrover1 257:7a50601356cc 448 * @param localOnly
rgrover1 257:7a50601356cc 449 * Only update the characteristic locally regardless of notify/indicate flags in the CCCD.
rgrover1 257:7a50601356cc 450 */
rgrover1 328:1fd12f67ed7a 451 ble_error_t updateCharacteristicValue(GattAttribute::Handle_t attributeHandle, const uint8_t *value, uint16_t size, bool localOnly = false);
rgrover1 342:152bd9c825d6 452 /**
rgrover1 342:152bd9c825d6 453 * A version of the same as above with connection handle parameter to allow updates for connection-specific multivalued attribtues (such as the CCCDs).
rgrover1 342:152bd9c825d6 454 */
rgrover1 342:152bd9c825d6 455 ble_error_t updateCharacteristicValue(Gap::Handle_t connectionHandle, GattAttribute::Handle_t attributeHandle, const uint8_t *value, uint16_t size, bool localOnly = false);
rgrover1 257:7a50601356cc 456
rgrover1 257:7a50601356cc 457 /**
rgrover1 257:7a50601356cc 458 * Yield control to the BLE stack or to other tasks waiting for events. This
rgrover1 257:7a50601356cc 459 * is a sleep function which will return when there is an application
rgrover1 257:7a50601356cc 460 * specific interrupt, but the MCU might wake up several times before
rgrover1 257:7a50601356cc 461 * returning (to service the stack). This is not always interchangeable with
rgrover1 257:7a50601356cc 462 * WFE().
rgrover1 257:7a50601356cc 463 */
rgrover1 257:7a50601356cc 464 void waitForEvent(void);
rgrover1 257:7a50601356cc 465
rgrover1 257:7a50601356cc 466 ble_error_t getPreferredConnectionParams(Gap::ConnectionParams_t *params);
rgrover1 257:7a50601356cc 467 ble_error_t setPreferredConnectionParams(const Gap::ConnectionParams_t *params);
rgrover1 257:7a50601356cc 468 ble_error_t updateConnectionParams(Gap::Handle_t handle, const Gap::ConnectionParams_t *params);
rgrover1 257:7a50601356cc 469
rgrover1 257:7a50601356cc 470 /**
rgrover1 257:7a50601356cc 471 * This call allows the application to get the BLE stack version information.
rgrover1 257:7a50601356cc 472 *
rgrover1 257:7a50601356cc 473 * @return A pointer to a const string representing the version.
rgrover1 257:7a50601356cc 474 * Note: The string is owned by the BLE_API.
rgrover1 257:7a50601356cc 475 */
rgrover1 257:7a50601356cc 476 const char *getVersion(void);
rgrover1 257:7a50601356cc 477
rgrover1 257:7a50601356cc 478 /**
rgrover1 257:7a50601356cc 479 * Set the device name characteristic in the GAP service.
rgrover1 257:7a50601356cc 480 * @param deviceName The new value for the device-name. This is a UTF-8 encoded, <b>NULL-terminated</b> string.
rgrover1 257:7a50601356cc 481 */
rgrover1 257:7a50601356cc 482 ble_error_t setDeviceName(const uint8_t *deviceName);
rgrover1 257:7a50601356cc 483
rgrover1 257:7a50601356cc 484 /**
rgrover1 257:7a50601356cc 485 * Get the value of the device name characteristic in the GAP service.
rgrover1 257:7a50601356cc 486 * @param[out] deviceName Pointer to an empty buffer where the UTF-8 *non NULL-
rgrover1 257:7a50601356cc 487 * terminated* string will be placed. Set this
rgrover1 257:7a50601356cc 488 * value to NULL in order to obtain the deviceName-length
rgrover1 257:7a50601356cc 489 * from the 'length' parameter.
rgrover1 257:7a50601356cc 490 *
rgrover1 257:7a50601356cc 491 * @param[in/out] lengthP (on input) Length of the buffer pointed to by deviceName;
rgrover1 257:7a50601356cc 492 * (on output) the complete device name length (without the
rgrover1 257:7a50601356cc 493 * null terminator).
rgrover1 257:7a50601356cc 494 *
rgrover1 257:7a50601356cc 495 * @note If the device name is longer than the size of the supplied buffer,
rgrover1 257:7a50601356cc 496 * length will return the complete device name length,
rgrover1 257:7a50601356cc 497 * and not the number of bytes actually returned in deviceName.
rgrover1 257:7a50601356cc 498 * The application may use this information to retry with a suitable buffer size.
rgrover1 257:7a50601356cc 499 *
rgrover1 257:7a50601356cc 500 * Sample use:
rgrover1 257:7a50601356cc 501 * uint8_t deviceName[20];
rgrover1 257:7a50601356cc 502 * unsigned length = sizeof(deviceName);
rgrover1 257:7a50601356cc 503 * ble.getDeviceName(deviceName, &length);
rgrover1 257:7a50601356cc 504 * if (length < sizeof(deviceName)) {
rgrover1 257:7a50601356cc 505 * deviceName[length] = 0;
rgrover1 257:7a50601356cc 506 * }
rgrover1 257:7a50601356cc 507 * DEBUG("length: %u, deviceName: %s\r\n", length, deviceName);
rgrover1 257:7a50601356cc 508 */
rgrover1 257:7a50601356cc 509 ble_error_t getDeviceName(uint8_t *deviceName, unsigned *lengthP);
rgrover1 257:7a50601356cc 510
rgrover1 257:7a50601356cc 511 /**
rgrover1 257:7a50601356cc 512 * Set the appearance characteristic in the GAP service.
rgrover1 257:7a50601356cc 513 * @param[in] appearance The new value for the device-appearance.
rgrover1 257:7a50601356cc 514 */
rgrover1 257:7a50601356cc 515 ble_error_t setAppearance(uint16_t appearance);
rgrover1 257:7a50601356cc 516
rgrover1 257:7a50601356cc 517 /**
rgrover1 257:7a50601356cc 518 * Set the appearance characteristic in the GAP service.
rgrover1 257:7a50601356cc 519 * @param[out] appearance The new value for the device-appearance.
rgrover1 257:7a50601356cc 520 */
rgrover1 257:7a50601356cc 521 ble_error_t getAppearance(uint16_t *appearanceP);
rgrover1 257:7a50601356cc 522
rgrover1 257:7a50601356cc 523 /**
rgrover1 257:7a50601356cc 524 * Set the radio's transmit power.
rgrover1 257:7a50601356cc 525 * @param[in] txPower Radio transmit power in dBm.
rgrover1 257:7a50601356cc 526 */
rgrover1 257:7a50601356cc 527 ble_error_t setTxPower(int8_t txPower);
rgrover1 257:7a50601356cc 528
rgrover1 305:71367f7cd078 529 /**
rgrover1 305:71367f7cd078 530 * Query the underlying stack for permitted arguments for setTxPower().
rgrover1 305:71367f7cd078 531 *
rgrover1 305:71367f7cd078 532 * @param[out] valueArrayPP
rgrover1 305:71367f7cd078 533 * Out parameter to receive the immutable array of Tx values.
rgrover1 305:71367f7cd078 534 * @param[out] countP
rgrover1 305:71367f7cd078 535 * Out parameter to receive the array's size.
rgrover1 305:71367f7cd078 536 */
rgrover1 305:71367f7cd078 537 void getPermittedTxPowerValues(const int8_t **valueArrayPP, size_t *countP);
rgrover1 305:71367f7cd078 538
rgrover1 347:20be4234c6fe 539 /**
rgrover1 347:20be4234c6fe 540 * Enable the BLE stack's Security Manager. The Security Manager implements
rgrover1 347:20be4234c6fe 541 * the actual cryptographic algorithms and protocol exchanges that allow two
rgrover1 347:20be4234c6fe 542 * devices to securely exchange data and privately detect each other.
rgrover1 347:20be4234c6fe 543 * Calling this API is a prerequisite for encryption and pairing (bonding).
rgrover1 357:d4bb5d2b837a 544 *
rgrover1 357:d4bb5d2b837a 545 * @param[in] enableBonding Allow for bonding.
rgrover1 357:d4bb5d2b837a 546 * @param[in] requireMITM Require protection for man-in-the-middle attacks.
rgrover1 357:d4bb5d2b837a 547 * @param[in] iocaps To specify IO capabilities of this peripheral,
rgrover1 357:d4bb5d2b837a 548 * such as availability of a display or keyboard to
rgrover1 357:d4bb5d2b837a 549 * support out-of-band exchanges of security data.
rgrover1 357:d4bb5d2b837a 550 * @param[in] passkey To specify a static passkey.
rgrover1 357:d4bb5d2b837a 551 *
rgrover1 357:d4bb5d2b837a 552 * @return BLE_ERROR_NONE on success.
rgrover1 347:20be4234c6fe 553 */
rgrover1 357:d4bb5d2b837a 554 ble_error_t initializeSecurity(bool enableBonding = true,
rgrover1 357:d4bb5d2b837a 555 bool requireMITM = true,
rgrover1 357:d4bb5d2b837a 556 Gap::SecurityIOCapabilities_t iocaps = Gap::IO_CAPS_NONE,
rgrover1 357:d4bb5d2b837a 557 const Gap::Passkey_t passkey = NULL);
rgrover1 347:20be4234c6fe 558
rgrover1 368:89726b616c1b 559 /**
rgrover1 368:89726b616c1b 560 * Setup a callback for when the security setup procedure (key generation
rgrover1 368:89726b616c1b 561 * and exchange) for a link has started. This will be skipped for bonded
rgrover1 368:89726b616c1b 562 * devices. The callback is passed in parameters received from the peer's
rgrover1 368:89726b616c1b 563 * security request: bool allowBonding, bool requireMITM, and
rgrover1 368:89726b616c1b 564 * SecurityIOCapabilities_t.
rgrover1 368:89726b616c1b 565 */
rgrover1 368:89726b616c1b 566 void onSecuritySetupInitiated(Gap::SecuritySetupInitiatedCallback_t callback);
rgrover1 368:89726b616c1b 567
rgrover1 368:89726b616c1b 568 /**
rgrover1 368:89726b616c1b 569 * Setup a callback for when the security setup procedure (key generation
rgrover1 368:89726b616c1b 570 * and exchange) for a link has completed. This will be skipped for bonded
rgrover1 368:89726b616c1b 571 * devices. The callback is passed in the success/failure status of the
rgrover1 368:89726b616c1b 572 * security setup procedure.
rgrover1 368:89726b616c1b 573 */
rgrover1 368:89726b616c1b 574 void onSecuritySetupCompleted(Gap::SecuritySetupCompletedCallback_t callback);
rgrover1 368:89726b616c1b 575
rgrover1 368:89726b616c1b 576 /**
rgrover1 368:89726b616c1b 577 * Setup a callback for when a link with the peer is secured. For bonded
rgrover1 368:89726b616c1b 578 * devices, subsequent reconnections with bonded peer will result only in
rgrover1 368:89726b616c1b 579 * this callback when the link is secured and setup procedures will not
rgrover1 368:89726b616c1b 580 * occur unless the bonding information is either lost or deleted on either
rgrover1 368:89726b616c1b 581 * or both sides. The callback is passed in a Gap::SecurityMode_t according
rgrover1 368:89726b616c1b 582 * to the level of security in effect for the secured link.
rgrover1 368:89726b616c1b 583 */
rgrover1 368:89726b616c1b 584 void onLinkSecured(Gap::LinkSecuredCallback_t callback);
rgrover1 368:89726b616c1b 585
rgrover1 368:89726b616c1b 586 /**
rgrover1 368:89726b616c1b 587 * Setup a callback for successful bonding; i.e. that link-specific security
rgrover1 368:89726b616c1b 588 * context is stored persistently for a peer device.
rgrover1 368:89726b616c1b 589 */
rgrover1 368:89726b616c1b 590 void onSecurityContextStored(Gap::HandleSpecificEvent_t callback);
rgrover1 368:89726b616c1b 591
rgrover1 368:89726b616c1b 592 /**
rgrover1 369:9a76cc068644 593 * Setup a callback for when the passkey needs to be displayed on a
rgrover1 369:9a76cc068644 594 * peripheral with DISPLAY capability. This happens when security is
rgrover1 369:9a76cc068644 595 * configured to prevent Man-In-The-Middle attacks, and a PIN (or passkey)
rgrover1 369:9a76cc068644 596 * needs to be exchanged between the peers to authenticate the connection
rgrover1 369:9a76cc068644 597 * attempt.
rgrover1 369:9a76cc068644 598 */
rgrover1 369:9a76cc068644 599 void onPasskeyDisplay(Gap::PasskeyDisplayCallback_t callback);
rgrover1 369:9a76cc068644 600
rgrover1 369:9a76cc068644 601 /**
rgrover1 368:89726b616c1b 602 * Get the security status of a connection.
rgrover1 368:89726b616c1b 603 *
rgrover1 368:89726b616c1b 604 * @param[in] connectionHandle Handle to identify the connection.
rgrover1 368:89726b616c1b 605 * @param[out] securityStatusP security status.
rgrover1 368:89726b616c1b 606 *
rgrover1 368:89726b616c1b 607 * @return BLE_SUCCESS Or appropriate error code indicating reason for failure.
rgrover1 368:89726b616c1b 608 */
rgrover1 368:89726b616c1b 609 ble_error_t getLinkSecurity(Gap::Handle_t connectionHandle, Gap::LinkSecurityStatus_t *securityStatusP);
rgrover1 368:89726b616c1b 610
rgrover1 371:6c73b5970f2d 611 /**
rgrover1 371:6c73b5970f2d 612 * Delete all peer device context and all related bonding information from
rgrover1 371:6c73b5970f2d 613 * the database within the security manager.
rgrover1 371:6c73b5970f2d 614 *
rgrover1 371:6c73b5970f2d 615 * @retval BLE_ERROR_NONE On success, else an error code indicating reason for failure.
rgrover1 371:6c73b5970f2d 616 * @retval BLE_ERROR_INVALID_STATE If the API is called without module initialization and/or
rgrover1 371:6c73b5970f2d 617 * application registration.
rgrover1 371:6c73b5970f2d 618 */
rgrover1 371:6c73b5970f2d 619 ble_error_t purgeAllBondingState(void);
rgrover1 371:6c73b5970f2d 620
rgrover1 257:7a50601356cc 621 public:
rgrover1 383:7bd527ea7280 622 BLEDevice() : transport(createBLEDeviceInstance()), advParams(), advPayload(), scanResponse(), needToSetAdvPayload(true), scanningParams() {
rgrover1 257:7a50601356cc 623 advPayload.clear();
rgrover1 257:7a50601356cc 624 scanResponse.clear();
rgrover1 257:7a50601356cc 625 }
rgrover1 257:7a50601356cc 626
rgrover1 257:7a50601356cc 627 private:
rgrover1 257:7a50601356cc 628 BLEDeviceInstanceBase *const transport; /* the device specific backend */
rgrover1 257:7a50601356cc 629
rgrover1 257:7a50601356cc 630 GapAdvertisingParams advParams;
rgrover1 257:7a50601356cc 631 GapAdvertisingData advPayload;
rgrover1 257:7a50601356cc 632 GapAdvertisingData scanResponse;
rgrover1 257:7a50601356cc 633
rgrover1 257:7a50601356cc 634 /* Accumulation of AD structures in the advertisement payload should
rgrover1 257:7a50601356cc 635 * eventually result in a call to the target's setAdvertisingData() before
rgrover1 257:7a50601356cc 636 * the server begins advertising. This flag marks the status of the pending update.*/
rgrover1 257:7a50601356cc 637 bool needToSetAdvPayload;
rgrover1 380:2109a08c311c 638
rgrover1 380:2109a08c311c 639 GapScanningParams scanningParams;
rgrover1 257:7a50601356cc 640 };
rgrover1 257:7a50601356cc 641
rgrover1 257:7a50601356cc 642 /* BLEDevice methods. Most of these simply forward the calls to the underlying
rgrover1 257:7a50601356cc 643 * transport.*/
rgrover1 257:7a50601356cc 644
rgrover1 257:7a50601356cc 645 inline ble_error_t
rgrover1 257:7a50601356cc 646 BLEDevice::reset(void)
rgrover1 257:7a50601356cc 647 {
rgrover1 257:7a50601356cc 648 return transport->reset();
rgrover1 257:7a50601356cc 649 }
rgrover1 257:7a50601356cc 650
rgrover1 257:7a50601356cc 651 inline ble_error_t
rgrover1 257:7a50601356cc 652 BLEDevice::shutdown(void)
rgrover1 257:7a50601356cc 653 {
rgrover1 257:7a50601356cc 654 clearAdvertisingPayload();
rgrover1 257:7a50601356cc 655 return transport->shutdown();
rgrover1 257:7a50601356cc 656 }
rgrover1 257:7a50601356cc 657
rgrover1 257:7a50601356cc 658 inline ble_error_t
rgrover1 424:370d5f1f292f 659 BLEDevice::setAddress(Gap::AddressType_t type, const Gap::address_t address)
rgrover1 257:7a50601356cc 660 {
rgrover1 257:7a50601356cc 661 return transport->getGap().setAddress(type, address);
rgrover1 257:7a50601356cc 662 }
rgrover1 257:7a50601356cc 663
rgrover1 257:7a50601356cc 664 inline ble_error_t
rgrover1 424:370d5f1f292f 665 BLEDevice::getAddress(Gap::AddressType_t *typeP, Gap::address_t address)
rgrover1 257:7a50601356cc 666 {
rgrover1 257:7a50601356cc 667 return transport->getGap().getAddress(typeP, address);
rgrover1 257:7a50601356cc 668 }
rgrover1 257:7a50601356cc 669
rgrover1 257:7a50601356cc 670 inline void
rgrover1 257:7a50601356cc 671 BLEDevice::setAdvertisingType(GapAdvertisingParams::AdvertisingType advType)
rgrover1 257:7a50601356cc 672 {
rgrover1 257:7a50601356cc 673 advParams.setAdvertisingType(advType);
rgrover1 257:7a50601356cc 674 }
rgrover1 257:7a50601356cc 675
rgrover1 257:7a50601356cc 676 inline void
rgrover1 257:7a50601356cc 677 BLEDevice::setAdvertisingInterval(uint16_t interval)
rgrover1 257:7a50601356cc 678 {
rgrover1 325:501ad8b8bbe5 679 if (interval == 0) {
rgrover1 325:501ad8b8bbe5 680 stopAdvertising();
rgrover1 325:501ad8b8bbe5 681 } else if (interval < getMinAdvertisingInterval()) {
rgrover1 325:501ad8b8bbe5 682 interval = getMinAdvertisingInterval();
rgrover1 325:501ad8b8bbe5 683 }
rgrover1 325:501ad8b8bbe5 684 advParams.setInterval(Gap::MSEC_TO_ADVERTISEMENT_DURATION_UNITS(interval));
rgrover1 325:501ad8b8bbe5 685 }
rgrover1 325:501ad8b8bbe5 686
rgrover1 325:501ad8b8bbe5 687 inline uint16_t
rgrover1 325:501ad8b8bbe5 688 BLEDevice::getMinAdvertisingInterval(void) const {
rgrover1 325:501ad8b8bbe5 689 return transport->getGap().getMinAdvertisingInterval();
rgrover1 325:501ad8b8bbe5 690 }
rgrover1 325:501ad8b8bbe5 691
rgrover1 325:501ad8b8bbe5 692 inline uint16_t
rgrover1 325:501ad8b8bbe5 693 BLEDevice::getMinNonConnectableAdvertisingInterval(void) const {
rgrover1 325:501ad8b8bbe5 694 return transport->getGap().getMinNonConnectableAdvertisingInterval();
rgrover1 325:501ad8b8bbe5 695 }
rgrover1 325:501ad8b8bbe5 696
rgrover1 325:501ad8b8bbe5 697 inline uint16_t
rgrover1 325:501ad8b8bbe5 698 BLEDevice::getMaxAdvertisingInterval(void) const {
rgrover1 325:501ad8b8bbe5 699 return transport->getGap().getMaxAdvertisingInterval();
rgrover1 257:7a50601356cc 700 }
rgrover1 257:7a50601356cc 701
rgrover1 257:7a50601356cc 702 inline void
rgrover1 257:7a50601356cc 703 BLEDevice::setAdvertisingTimeout(uint16_t timeout)
rgrover1 257:7a50601356cc 704 {
rgrover1 257:7a50601356cc 705 advParams.setTimeout(timeout);
rgrover1 257:7a50601356cc 706 }
rgrover1 257:7a50601356cc 707
rgrover1 257:7a50601356cc 708 inline void
rgrover1 257:7a50601356cc 709 BLEDevice::setAdvertisingParams(const GapAdvertisingParams &newAdvParams)
rgrover1 257:7a50601356cc 710 {
rgrover1 257:7a50601356cc 711 advParams = newAdvParams;
rgrover1 257:7a50601356cc 712 }
rgrover1 257:7a50601356cc 713
rgrover1 410:af8f2d1b67b6 714 inline const GapAdvertisingParams &
rgrover1 410:af8f2d1b67b6 715 BLEDevice::getAdvertisingParams(void) const
rgrover1 409:37a4202649dd 716 {
rgrover1 409:37a4202649dd 717 return advParams;
rgrover1 409:37a4202649dd 718 }
rgrover1 409:37a4202649dd 719
rgrover1 257:7a50601356cc 720 inline void
rgrover1 257:7a50601356cc 721 BLEDevice::clearAdvertisingPayload(void)
rgrover1 257:7a50601356cc 722 {
rgrover1 257:7a50601356cc 723 needToSetAdvPayload = true;
rgrover1 257:7a50601356cc 724 advPayload.clear();
rgrover1 257:7a50601356cc 725 }
rgrover1 257:7a50601356cc 726
rgrover1 257:7a50601356cc 727 inline ble_error_t
rgrover1 257:7a50601356cc 728 BLEDevice::accumulateAdvertisingPayload(uint8_t flags)
rgrover1 257:7a50601356cc 729 {
rgrover1 257:7a50601356cc 730 needToSetAdvPayload = true;
rgrover1 257:7a50601356cc 731 return advPayload.addFlags(flags);
rgrover1 257:7a50601356cc 732 }
rgrover1 257:7a50601356cc 733
rgrover1 257:7a50601356cc 734 inline ble_error_t
rgrover1 257:7a50601356cc 735 BLEDevice::accumulateAdvertisingPayload(GapAdvertisingData::Appearance app)
rgrover1 257:7a50601356cc 736 {
rgrover1 257:7a50601356cc 737 needToSetAdvPayload = true;
rgrover1 257:7a50601356cc 738 transport->getGap().setAppearance(app);
rgrover1 257:7a50601356cc 739 return advPayload.addAppearance(app);
rgrover1 257:7a50601356cc 740 }
rgrover1 257:7a50601356cc 741
rgrover1 257:7a50601356cc 742 inline ble_error_t
rgrover1 257:7a50601356cc 743 BLEDevice::accumulateAdvertisingPayloadTxPower(int8_t txPower)
rgrover1 257:7a50601356cc 744 {
rgrover1 257:7a50601356cc 745 needToSetAdvPayload = true;
rgrover1 257:7a50601356cc 746 return advPayload.addTxPower(txPower);
rgrover1 257:7a50601356cc 747 }
rgrover1 257:7a50601356cc 748
rgrover1 257:7a50601356cc 749 inline ble_error_t
rgrover1 257:7a50601356cc 750 BLEDevice::accumulateAdvertisingPayload(GapAdvertisingData::DataType type, const uint8_t *data, uint8_t len)
rgrover1 257:7a50601356cc 751 {
rgrover1 257:7a50601356cc 752 needToSetAdvPayload = true;
rgrover1 257:7a50601356cc 753 if (type == GapAdvertisingData::COMPLETE_LOCAL_NAME) {
rgrover1 257:7a50601356cc 754 transport->getGap().setDeviceName(data);
rgrover1 257:7a50601356cc 755 }
rgrover1 257:7a50601356cc 756 return advPayload.addData(type, data, len);
rgrover1 257:7a50601356cc 757 }
rgrover1 257:7a50601356cc 758
rgrover1 257:7a50601356cc 759 inline ble_error_t
rgrover1 257:7a50601356cc 760 BLEDevice::accumulateScanResponse(GapAdvertisingData::DataType type, const uint8_t *data, uint8_t len)
rgrover1 257:7a50601356cc 761 {
rgrover1 257:7a50601356cc 762 needToSetAdvPayload = true;
rgrover1 257:7a50601356cc 763 return scanResponse.addData(type, data, len);
rgrover1 257:7a50601356cc 764 }
rgrover1 257:7a50601356cc 765
rgrover1 343:4d2576324b62 766 inline void
rgrover1 343:4d2576324b62 767 BLEDevice::clearScanResponse(void)
rgrover1 343:4d2576324b62 768 {
rgrover1 343:4d2576324b62 769 needToSetAdvPayload = true;
rgrover1 343:4d2576324b62 770 scanResponse.clear();
rgrover1 343:4d2576324b62 771 }
rgrover1 343:4d2576324b62 772
rgrover1 257:7a50601356cc 773 inline ble_error_t
rgrover1 257:7a50601356cc 774 BLEDevice::setAdvertisingPayload(void) {
rgrover1 257:7a50601356cc 775 needToSetAdvPayload = false;
rgrover1 257:7a50601356cc 776 return transport->getGap().setAdvertisingData(advPayload, scanResponse);
rgrover1 257:7a50601356cc 777 }
rgrover1 257:7a50601356cc 778
rgrover1 257:7a50601356cc 779 inline ble_error_t
rgrover1 409:37a4202649dd 780 BLEDevice::setAdvertisingData(const GapAdvertisingData& newPayload)
rgrover1 409:37a4202649dd 781 {
rgrover1 409:37a4202649dd 782 advPayload = newPayload;
rgrover1 409:37a4202649dd 783
rgrover1 409:37a4202649dd 784 return setAdvertisingPayload();
rgrover1 409:37a4202649dd 785 }
rgrover1 409:37a4202649dd 786
rgrover1 410:af8f2d1b67b6 787 inline const GapAdvertisingData &
rgrover1 410:af8f2d1b67b6 788 BLEDevice::getAdvertisingData(void) const {
rgrover1 409:37a4202649dd 789 return advPayload;
rgrover1 409:37a4202649dd 790 }
rgrover1 409:37a4202649dd 791
rgrover1 409:37a4202649dd 792 inline ble_error_t
rgrover1 257:7a50601356cc 793 BLEDevice::startAdvertising(void)
rgrover1 257:7a50601356cc 794 {
rgrover1 257:7a50601356cc 795 ble_error_t rc;
rgrover1 257:7a50601356cc 796 if ((rc = transport->getGattServer().initializeGATTDatabase()) != BLE_ERROR_NONE) {
rgrover1 257:7a50601356cc 797 return rc;
rgrover1 257:7a50601356cc 798 }
rgrover1 257:7a50601356cc 799 if (needToSetAdvPayload) {
rgrover1 257:7a50601356cc 800 if ((rc = setAdvertisingPayload()) != BLE_ERROR_NONE) {
rgrover1 257:7a50601356cc 801 return rc;
rgrover1 257:7a50601356cc 802 }
rgrover1 257:7a50601356cc 803 }
rgrover1 257:7a50601356cc 804
rgrover1 257:7a50601356cc 805 return transport->getGap().startAdvertising(advParams);
rgrover1 257:7a50601356cc 806 }
rgrover1 257:7a50601356cc 807
rgrover1 257:7a50601356cc 808 inline ble_error_t
rgrover1 257:7a50601356cc 809 BLEDevice::stopAdvertising(void)
rgrover1 257:7a50601356cc 810 {
rgrover1 257:7a50601356cc 811 return transport->getGap().stopAdvertising();
rgrover1 257:7a50601356cc 812 }
rgrover1 257:7a50601356cc 813
rgrover1 257:7a50601356cc 814 inline ble_error_t
rgrover1 394:598368c24bbb 815 BLEDevice::setScanParams(uint16_t interval, uint16_t window, uint16_t timeout, bool activeScanning) {
rgrover1 384:48412313df56 816 ble_error_t rc;
rgrover1 384:48412313df56 817 if (((rc = scanningParams.setInterval(interval)) == BLE_ERROR_NONE) &&
rgrover1 384:48412313df56 818 ((rc = scanningParams.setWindow(window)) == BLE_ERROR_NONE) &&
rgrover1 384:48412313df56 819 ((rc = scanningParams.setTimeout(timeout)) == BLE_ERROR_NONE)) {
rgrover1 394:598368c24bbb 820 scanningParams.setActiveScanning(activeScanning);
rgrover1 384:48412313df56 821 return BLE_ERROR_NONE;
rgrover1 384:48412313df56 822 }
rgrover1 384:48412313df56 823
rgrover1 384:48412313df56 824 return rc;
rgrover1 384:48412313df56 825 }
rgrover1 384:48412313df56 826
rgrover1 384:48412313df56 827 inline ble_error_t
rgrover1 392:3201f029c2eb 828 BLEDevice::setScanInterval(uint16_t interval) {
rgrover1 384:48412313df56 829 return scanningParams.setInterval(interval);
rgrover1 384:48412313df56 830 }
rgrover1 384:48412313df56 831
rgrover1 384:48412313df56 832 inline ble_error_t
rgrover1 392:3201f029c2eb 833 BLEDevice::setScanWindow(uint16_t window) {
rgrover1 384:48412313df56 834 return scanningParams.setWindow(window);
rgrover1 384:48412313df56 835 }
rgrover1 384:48412313df56 836
rgrover1 384:48412313df56 837 inline ble_error_t
rgrover1 392:3201f029c2eb 838 BLEDevice::setScanTimeout(uint16_t timeout) {
rgrover1 384:48412313df56 839 return scanningParams.setTimeout(timeout);
rgrover1 384:48412313df56 840 }
rgrover1 384:48412313df56 841
rgrover1 394:598368c24bbb 842 inline void
rgrover1 394:598368c24bbb 843 BLEDevice::setActiveScan(bool activeScanning) {
rgrover1 394:598368c24bbb 844 return scanningParams.setActiveScanning(activeScanning);
rgrover1 394:598368c24bbb 845 }
rgrover1 394:598368c24bbb 846
rgrover1 384:48412313df56 847 inline ble_error_t
rgrover1 406:cec6778acc66 848 BLEDevice::startScan(void (*callback)(const Gap::AdvertisementCallbackParams_t *params)) {
rgrover1 392:3201f029c2eb 849 return transport->getGap().startScan(scanningParams, callback);
rgrover1 385:6e66d1c6de00 850 }
rgrover1 385:6e66d1c6de00 851
rgrover1 407:ca6b956b33d1 852 template<typename T>
rgrover1 407:ca6b956b33d1 853 inline ble_error_t
rgrover1 407:ca6b956b33d1 854 BLEDevice::startScan(T *object, void (T::*memberCallback)(const Gap::AdvertisementCallbackParams_t *params)) {
rgrover1 407:ca6b956b33d1 855 return transport->getGap().startScan(scanningParams, object, memberCallback);
rgrover1 407:ca6b956b33d1 856 }
rgrover1 407:ca6b956b33d1 857
rgrover1 385:6e66d1c6de00 858 inline ble_error_t
rgrover1 392:3201f029c2eb 859 BLEDevice::stopScan(void) {
rgrover1 392:3201f029c2eb 860 return transport->getGap().stopScan();
rgrover1 387:7faa54079669 861 }
rgrover1 387:7faa54079669 862
rgrover1 387:7faa54079669 863 inline ble_error_t
rgrover1 441:2d864886aeca 864 BLEDevice::connect(const Gap::Address_t peerAddr, Gap::AddressType_t peerAddrType) {
rgrover1 445:c1e8af80a9cd 865 Gap::ConnectionParams_t connectionParams = {
rgrover1 445:c1e8af80a9cd 866 .minConnectionInterval = 30,
rgrover1 445:c1e8af80a9cd 867 .maxConnectionInterval = 100,
rgrover1 445:c1e8af80a9cd 868 .slaveLatency = 0,
rgrover1 445:c1e8af80a9cd 869 .connectionSupervisionTimeout = 400
rgrover1 445:c1e8af80a9cd 870 };
rgrover1 445:c1e8af80a9cd 871
rgrover1 444:0ecf7ce69172 872 return transport->getGap().connect(peerAddr, peerAddrType, scanningParams, connectionParams);
rgrover1 442:c120ffca22fa 873 }
rgrover1 442:c120ffca22fa 874 inline ble_error_t
rgrover1 442:c120ffca22fa 875 BLEDevice::connect(const Gap::Address_t peerAddr, Gap::AddressType_t peerAddrType, const GapScanningParams &scanParams) {
rgrover1 445:c1e8af80a9cd 876 Gap::ConnectionParams_t connectionParams = {
rgrover1 445:c1e8af80a9cd 877 .minConnectionInterval = 30,
rgrover1 445:c1e8af80a9cd 878 .maxConnectionInterval = 100,
rgrover1 445:c1e8af80a9cd 879 .slaveLatency = 0,
rgrover1 445:c1e8af80a9cd 880 .connectionSupervisionTimeout = 400
rgrover1 445:c1e8af80a9cd 881 };
rgrover1 445:c1e8af80a9cd 882
rgrover1 444:0ecf7ce69172 883 return transport->getGap().connect(peerAddr, peerAddrType, scanParams, connectionParams);
rgrover1 441:2d864886aeca 884 }
rgrover1 441:2d864886aeca 885
rgrover1 441:2d864886aeca 886 inline ble_error_t
rgrover1 257:7a50601356cc 887 BLEDevice::disconnect(Gap::DisconnectionReason_t reason)
rgrover1 257:7a50601356cc 888 {
rgrover1 257:7a50601356cc 889 return transport->getGap().disconnect(reason);
rgrover1 257:7a50601356cc 890 }
rgrover1 257:7a50601356cc 891
rgrover1 257:7a50601356cc 892 inline void
rgrover1 257:7a50601356cc 893 BLEDevice::onTimeout(Gap::EventCallback_t timeoutCallback)
rgrover1 257:7a50601356cc 894 {
rgrover1 257:7a50601356cc 895 transport->getGap().setOnTimeout(timeoutCallback);
rgrover1 257:7a50601356cc 896 }
rgrover1 257:7a50601356cc 897
rgrover1 257:7a50601356cc 898 inline void
rgrover1 257:7a50601356cc 899 BLEDevice::onConnection(Gap::ConnectionEventCallback_t connectionCallback)
rgrover1 257:7a50601356cc 900 {
rgrover1 257:7a50601356cc 901 transport->getGap().setOnConnection(connectionCallback);
rgrover1 257:7a50601356cc 902 }
rgrover1 257:7a50601356cc 903
rgrover1 257:7a50601356cc 904 inline void
rgrover1 257:7a50601356cc 905 BLEDevice::onDisconnection(Gap::DisconnectionEventCallback_t disconnectionCallback)
rgrover1 257:7a50601356cc 906 {
rgrover1 257:7a50601356cc 907 transport->getGap().setOnDisconnection(disconnectionCallback);
rgrover1 257:7a50601356cc 908 }
rgrover1 257:7a50601356cc 909
rgrover1 257:7a50601356cc 910 template<typename T>
rgrover1 257:7a50601356cc 911 inline void
rgrover1 257:7a50601356cc 912 BLEDevice::addToDisconnectionCallChain(T *tptr, void (T::*mptr)(void)) {
rgrover1 257:7a50601356cc 913 transport->getGap().addToDisconnectionCallChain(tptr, mptr);
rgrover1 257:7a50601356cc 914 }
rgrover1 257:7a50601356cc 915
rgrover1 257:7a50601356cc 916 inline void
rgrover1 259:a95264ad705c 917 BLEDevice::onDataSent(void (*callback)(unsigned count)) {
rgrover1 257:7a50601356cc 918 transport->getGattServer().setOnDataSent(callback);
rgrover1 257:7a50601356cc 919 }
rgrover1 257:7a50601356cc 920
rgrover1 259:a95264ad705c 921 template <typename T> inline void
rgrover1 259:a95264ad705c 922 BLEDevice::onDataSent(T *objPtr, void (T::*memberPtr)(unsigned count)) {
rgrover1 259:a95264ad705c 923 transport->getGattServer().setOnDataSent(objPtr, memberPtr);
rgrover1 259:a95264ad705c 924 }
rgrover1 259:a95264ad705c 925
rgrover1 257:7a50601356cc 926 inline void
rgrover1 257:7a50601356cc 927 BLEDevice::onDataWritten(void (*callback)(const GattCharacteristicWriteCBParams *eventDataP)) {
rgrover1 257:7a50601356cc 928 transport->getGattServer().setOnDataWritten(callback);
rgrover1 257:7a50601356cc 929 }
rgrover1 257:7a50601356cc 930
rgrover1 257:7a50601356cc 931 template <typename T> inline void
rgrover1 257:7a50601356cc 932 BLEDevice::onDataWritten(T *objPtr, void (T::*memberPtr)(const GattCharacteristicWriteCBParams *context)) {
rgrover1 257:7a50601356cc 933 transport->getGattServer().setOnDataWritten(objPtr, memberPtr);
rgrover1 257:7a50601356cc 934 }
rgrover1 257:7a50601356cc 935
rgrover1 300:d9a39f759a6a 936 inline ble_error_t
rgrover1 300:d9a39f759a6a 937 BLEDevice::onDataRead(void (*callback)(const GattCharacteristicReadCBParams *eventDataP)) {
rgrover1 300:d9a39f759a6a 938 return transport->getGattServer().setOnDataRead(callback);
rgrover1 300:d9a39f759a6a 939 }
rgrover1 300:d9a39f759a6a 940
rgrover1 300:d9a39f759a6a 941 template <typename T> inline ble_error_t
rgrover1 300:d9a39f759a6a 942 BLEDevice::onDataRead(T *objPtr, void (T::*memberPtr)(const GattCharacteristicReadCBParams *context)) {
rgrover1 300:d9a39f759a6a 943 return transport->getGattServer().setOnDataRead(objPtr, memberPtr);
rgrover1 300:d9a39f759a6a 944 }
rgrover1 300:d9a39f759a6a 945
rgrover1 257:7a50601356cc 946 inline void
rgrover1 257:7a50601356cc 947 BLEDevice::onUpdatesEnabled(GattServer::EventCallback_t callback)
rgrover1 257:7a50601356cc 948 {
rgrover1 257:7a50601356cc 949 transport->getGattServer().setOnUpdatesEnabled(callback);
rgrover1 257:7a50601356cc 950 }
rgrover1 257:7a50601356cc 951
rgrover1 257:7a50601356cc 952 inline void
rgrover1 257:7a50601356cc 953 BLEDevice::onUpdatesDisabled(GattServer::EventCallback_t callback)
rgrover1 257:7a50601356cc 954 {
rgrover1 257:7a50601356cc 955 transport->getGattServer().setOnUpdatesDisabled(callback);
rgrover1 257:7a50601356cc 956 }
rgrover1 257:7a50601356cc 957
rgrover1 257:7a50601356cc 958 inline void
rgrover1 257:7a50601356cc 959 BLEDevice::onConfirmationReceived(GattServer::EventCallback_t callback)
rgrover1 257:7a50601356cc 960 {
rgrover1 257:7a50601356cc 961 transport->getGattServer().setOnConfirmationReceived(callback);
rgrover1 257:7a50601356cc 962 }
rgrover1 257:7a50601356cc 963
rgrover1 341:8a104d9d80c1 964 inline void
rgrover1 341:8a104d9d80c1 965 BLEDevice::onRadioNotification(Gap::RadioNotificationEventCallback_t callback)
rgrover1 341:8a104d9d80c1 966 {
rgrover1 341:8a104d9d80c1 967 transport->getGap().setOnRadioNotification(callback);
rgrover1 341:8a104d9d80c1 968 }
rgrover1 341:8a104d9d80c1 969
rgrover1 353:5ed63cda3038 970 inline ble_error_t
rgrover1 257:7a50601356cc 971 BLEDevice::addService(GattService &service)
rgrover1 257:7a50601356cc 972 {
rgrover1 257:7a50601356cc 973 return transport->getGattServer().addService(service);
rgrover1 257:7a50601356cc 974 }
rgrover1 257:7a50601356cc 975
rgrover1 257:7a50601356cc 976 inline Gap::GapState_t
rgrover1 257:7a50601356cc 977 BLEDevice::getGapState(void) const
rgrover1 257:7a50601356cc 978 {
rgrover1 257:7a50601356cc 979 return transport->getGap().getState();
rgrover1 257:7a50601356cc 980 }
rgrover1 257:7a50601356cc 981
rgrover1 328:1fd12f67ed7a 982 inline ble_error_t BLEDevice::readCharacteristicValue(GattAttribute::Handle_t attributeHandle, uint8_t *buffer, uint16_t *lengthP)
rgrover1 257:7a50601356cc 983 {
rgrover1 328:1fd12f67ed7a 984 return transport->getGattServer().readValue(attributeHandle, buffer, lengthP);
rgrover1 257:7a50601356cc 985 }
rgrover1 257:7a50601356cc 986
rgrover1 342:152bd9c825d6 987 inline ble_error_t BLEDevice::readCharacteristicValue(Gap::Handle_t connectionHandle, GattAttribute::Handle_t attributeHandle, uint8_t *buffer, uint16_t *lengthP)
rgrover1 342:152bd9c825d6 988 {
rgrover1 342:152bd9c825d6 989 return transport->getGattServer().readValue(connectionHandle, attributeHandle, buffer, lengthP);
rgrover1 342:152bd9c825d6 990 }
rgrover1 342:152bd9c825d6 991
rgrover1 257:7a50601356cc 992 inline ble_error_t
rgrover1 328:1fd12f67ed7a 993 BLEDevice::updateCharacteristicValue(GattAttribute::Handle_t attributeHandle, const uint8_t *value, uint16_t size, bool localOnly)
rgrover1 257:7a50601356cc 994 {
rgrover1 328:1fd12f67ed7a 995 return transport->getGattServer().updateValue(attributeHandle, const_cast<uint8_t *>(value), size, localOnly);
rgrover1 257:7a50601356cc 996 }
rgrover1 257:7a50601356cc 997
rgrover1 342:152bd9c825d6 998 inline ble_error_t
rgrover1 342:152bd9c825d6 999 BLEDevice::updateCharacteristicValue(Gap::Handle_t connectionHandle, GattAttribute::Handle_t attributeHandle, const uint8_t *value, uint16_t size, bool localOnly)
rgrover1 342:152bd9c825d6 1000 {
rgrover1 342:152bd9c825d6 1001 return transport->getGattServer().updateValue(connectionHandle, attributeHandle, const_cast<uint8_t *>(value), size, localOnly);
rgrover1 342:152bd9c825d6 1002 }
rgrover1 342:152bd9c825d6 1003
rgrover1 257:7a50601356cc 1004 inline void
rgrover1 257:7a50601356cc 1005 BLEDevice::waitForEvent(void)
rgrover1 257:7a50601356cc 1006 {
rgrover1 257:7a50601356cc 1007 transport->waitForEvent();
rgrover1 257:7a50601356cc 1008 }
rgrover1 257:7a50601356cc 1009
rgrover1 257:7a50601356cc 1010 inline ble_error_t
rgrover1 257:7a50601356cc 1011 BLEDevice::getPreferredConnectionParams(Gap::ConnectionParams_t *params)
rgrover1 257:7a50601356cc 1012 {
rgrover1 257:7a50601356cc 1013 return transport->getGap().getPreferredConnectionParams(params);
rgrover1 257:7a50601356cc 1014 }
rgrover1 257:7a50601356cc 1015
rgrover1 257:7a50601356cc 1016 inline ble_error_t
rgrover1 257:7a50601356cc 1017 BLEDevice::setPreferredConnectionParams(const Gap::ConnectionParams_t *params)
rgrover1 257:7a50601356cc 1018 {
rgrover1 257:7a50601356cc 1019 return transport->getGap().setPreferredConnectionParams(params);
rgrover1 257:7a50601356cc 1020 }
rgrover1 257:7a50601356cc 1021
rgrover1 257:7a50601356cc 1022 inline ble_error_t
rgrover1 257:7a50601356cc 1023 BLEDevice::updateConnectionParams(Gap::Handle_t handle, const Gap::ConnectionParams_t *params) {
rgrover1 257:7a50601356cc 1024 return transport->getGap().updateConnectionParams(handle, params);
rgrover1 257:7a50601356cc 1025 }
rgrover1 257:7a50601356cc 1026
rgrover1 257:7a50601356cc 1027 inline const char *
rgrover1 257:7a50601356cc 1028 BLEDevice::getVersion(void)
rgrover1 257:7a50601356cc 1029 {
rgrover1 257:7a50601356cc 1030 return transport->getVersion();
rgrover1 257:7a50601356cc 1031 }
rgrover1 257:7a50601356cc 1032
rgrover1 257:7a50601356cc 1033 inline ble_error_t
rgrover1 257:7a50601356cc 1034 BLEDevice::setDeviceName(const uint8_t *deviceName)
rgrover1 257:7a50601356cc 1035 {
rgrover1 257:7a50601356cc 1036 return transport->getGap().setDeviceName(deviceName);
rgrover1 257:7a50601356cc 1037 }
rgrover1 257:7a50601356cc 1038
rgrover1 257:7a50601356cc 1039 inline ble_error_t
rgrover1 257:7a50601356cc 1040 BLEDevice::getDeviceName(uint8_t *deviceName, unsigned *lengthP)
rgrover1 257:7a50601356cc 1041 {
rgrover1 257:7a50601356cc 1042 return transport->getGap().getDeviceName(deviceName, lengthP);
rgrover1 257:7a50601356cc 1043 }
rgrover1 257:7a50601356cc 1044
rgrover1 257:7a50601356cc 1045 inline ble_error_t
rgrover1 257:7a50601356cc 1046 BLEDevice::setAppearance(uint16_t appearance)
rgrover1 257:7a50601356cc 1047 {
rgrover1 257:7a50601356cc 1048 return transport->getGap().setAppearance(appearance);
rgrover1 257:7a50601356cc 1049 }
rgrover1 257:7a50601356cc 1050
rgrover1 257:7a50601356cc 1051 inline ble_error_t
rgrover1 257:7a50601356cc 1052 BLEDevice::getAppearance(uint16_t *appearanceP)
rgrover1 257:7a50601356cc 1053 {
rgrover1 257:7a50601356cc 1054 return transport->getGap().getAppearance(appearanceP);
rgrover1 257:7a50601356cc 1055 }
rgrover1 257:7a50601356cc 1056
rgrover1 257:7a50601356cc 1057 inline ble_error_t
rgrover1 257:7a50601356cc 1058 BLEDevice::setTxPower(int8_t txPower)
rgrover1 257:7a50601356cc 1059 {
rgrover1 257:7a50601356cc 1060 return transport->setTxPower(txPower);
rgrover1 257:7a50601356cc 1061 }
rgrover1 257:7a50601356cc 1062
rgrover1 305:71367f7cd078 1063 inline void
rgrover1 305:71367f7cd078 1064 BLEDevice::getPermittedTxPowerValues(const int8_t **valueArrayPP, size_t *countP)
rgrover1 305:71367f7cd078 1065 {
rgrover1 305:71367f7cd078 1066 transport->getPermittedTxPowerValues(valueArrayPP, countP);
rgrover1 305:71367f7cd078 1067 }
rgrover1 305:71367f7cd078 1068
rgrover1 347:20be4234c6fe 1069 inline ble_error_t
rgrover1 357:d4bb5d2b837a 1070 BLEDevice::initializeSecurity(bool enableBonding,
rgrover1 357:d4bb5d2b837a 1071 bool requireMITM,
rgrover1 357:d4bb5d2b837a 1072 Gap::SecurityIOCapabilities_t iocaps,
rgrover1 357:d4bb5d2b837a 1073 const Gap::Passkey_t passkey)
rgrover1 347:20be4234c6fe 1074 {
rgrover1 357:d4bb5d2b837a 1075 return transport->initializeSecurity(enableBonding, requireMITM, iocaps, passkey);
rgrover1 347:20be4234c6fe 1076 }
rgrover1 347:20be4234c6fe 1077
rgrover1 369:9a76cc068644 1078 inline void
rgrover1 370:678fdba95a62 1079 BLEDevice::onSecuritySetupInitiated(Gap::SecuritySetupInitiatedCallback_t callback)
rgrover1 370:678fdba95a62 1080 {
rgrover1 370:678fdba95a62 1081 transport->getGap().setOnSecuritySetupInitiated(callback);
rgrover1 370:678fdba95a62 1082 }
rgrover1 370:678fdba95a62 1083
rgrover1 370:678fdba95a62 1084 inline void
rgrover1 370:678fdba95a62 1085 BLEDevice::onSecuritySetupCompleted(Gap::SecuritySetupCompletedCallback_t callback)
rgrover1 370:678fdba95a62 1086 {
rgrover1 370:678fdba95a62 1087 transport->getGap().setOnSecuritySetupCompleted(callback);
rgrover1 370:678fdba95a62 1088 }
rgrover1 370:678fdba95a62 1089
rgrover1 370:678fdba95a62 1090 inline void
rgrover1 370:678fdba95a62 1091 BLEDevice::onLinkSecured(Gap::LinkSecuredCallback_t callback)
rgrover1 370:678fdba95a62 1092 {
rgrover1 370:678fdba95a62 1093 transport->getGap().setOnLinkSecured(callback);
rgrover1 370:678fdba95a62 1094 }
rgrover1 370:678fdba95a62 1095
rgrover1 370:678fdba95a62 1096 inline void
rgrover1 370:678fdba95a62 1097 BLEDevice::onSecurityContextStored(Gap::HandleSpecificEvent_t callback)
rgrover1 370:678fdba95a62 1098 {
rgrover1 370:678fdba95a62 1099 transport->getGap().setOnSecurityContextStored(callback);
rgrover1 370:678fdba95a62 1100 }
rgrover1 370:678fdba95a62 1101
rgrover1 370:678fdba95a62 1102 inline void
rgrover1 369:9a76cc068644 1103 BLEDevice::onPasskeyDisplay(Gap::PasskeyDisplayCallback_t callback)
rgrover1 369:9a76cc068644 1104 {
rgrover1 369:9a76cc068644 1105 return transport->getGap().setOnPasskeyDisplay(callback);
rgrover1 369:9a76cc068644 1106 }
rgrover1 369:9a76cc068644 1107
rgrover1 370:678fdba95a62 1108 inline ble_error_t
rgrover1 370:678fdba95a62 1109 BLEDevice::getLinkSecurity(Gap::Handle_t connectionHandle, Gap::LinkSecurityStatus_t *securityStatusP)
rgrover1 370:678fdba95a62 1110 {
rgrover1 370:678fdba95a62 1111 return transport->getGap().getLinkSecurity(connectionHandle, securityStatusP);
rgrover1 370:678fdba95a62 1112 }
rgrover1 370:678fdba95a62 1113
rgrover1 371:6c73b5970f2d 1114 inline ble_error_t
rgrover1 371:6c73b5970f2d 1115 BLEDevice::purgeAllBondingState(void)
rgrover1 371:6c73b5970f2d 1116 {
rgrover1 371:6c73b5970f2d 1117 return transport->getGap().purgeAllBondingState();
rgrover1 371:6c73b5970f2d 1118 }
rgrover1 371:6c73b5970f2d 1119
rgrover1 257:7a50601356cc 1120 #endif // ifndef __BLE_DEVICE__