Bike service

Fork of BLE_API by Bluetooth Low Energy

Committer:
rgrover1
Date:
Fri Jun 19 15:52:08 2015 +0100
Revision:
538:fff02872b62f
Parent:
537:00d5affbb2b2
Child:
539:0b6e82025358
Synchronized with git rev 42aaf6bb
Author: Rohit Grover
add BLE::gattServer()

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