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