High level Bluetooth Low Energy API and radio abstraction layer

Fork of BLE_API by Bluetooth Low Energy

Committer:
rgrover1
Date:
Fri Jun 19 15:52:09 2015 +0100
Revision:
543:4defb791aa94
Parent:
541:aa30f63e7b3f
Child:
544:840f428d18c7
Synchronized with git rev 692fe6d4
Author: Rohit Grover
setup Gap::onConnection()

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