BLE_API for nRF51

Fork of BLE_API by Bluetooth Low Energy

Committer:
rgrover1
Date:
Fri Jun 19 15:52:07 2015 +0100
Revision:
528:8d21604fe31d
Child:
529:ccfae9d8e56e
Synchronized with git rev c89eea7a
Author: Rohit Grover
rename BLEDevice as BLE; BLEDeviceInstanceBase as BLEInstanceBase

Who changed what in which revision?

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