extend

Fork of BLE_API by Bluetooth Low Energy

Committer:
rgrover1
Date:
Fri Jun 19 15:52:07 2015 +0100
Revision:
531:bdcd44b03974
Parent:
530:00800f9ffbfb
Child:
533:c2aafeedaf8c
Synchronized with git rev e74eb3b4
Author: Rohit Grover
moved GAP related members out of BLE and into GAP

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