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:52:06 2015 +0100
Revision:
526:caa67c3187a0
Parent:
524:6e97ab392e2a
Child:
527:493185cebc03
Synchronized with git rev 9bcd7433
Author: Rohit Grover
Rename BLEDevice as BLE. Retain an alias to BLEDevice for the sake of compatibility with old code.

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