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