test code 123

Dependencies:   mbed

Fork of LinkNode-Test by Qi Yao

Committer:
youkee
Date:
Thu Sep 01 05:14:03 2016 +0000
Revision:
0:1ad0e04b1bc5
change internal time from 1s to 200ms

Who changed what in which revision?

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