prova invio BLE

Dependents:   BLE_HeartRate_IDB04A1

Fork of BLE_API by Bluetooth Low Energy

Committer:
rgrover1
Date:
Fri Jun 19 15:52:08 2015 +0100
Revision:
537:00d5affbb2b2
Parent:
533:c2aafeedaf8c
Child:
538:fff02872b62f
Synchronized with git rev 68683f1c
Author: Rohit Grover
deprecate all GAP APIs from within BLE;
add consistent comment headers.

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