abc
Fork of BLE_API by
public/BLEDevice.h@370:678fdba95a62, 2015-05-08 (annotated)
- Committer:
- rgrover1
- Date:
- Fri May 08 15:35:48 2015 +0100
- Revision:
- 370:678fdba95a62
- Parent:
- 369:9a76cc068644
- Child:
- 371:6c73b5970f2d
Synchronized with git rev 88829f4e
Author: Rohit Grover
move things around a bit in the implementation area of BLEDevice.h
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rgrover1 | 257:7a50601356cc | 1 | /* mbed Microcontroller Library |
rgrover1 | 257:7a50601356cc | 2 | * Copyright (c) 2006-2013 ARM Limited |
rgrover1 | 257:7a50601356cc | 3 | * |
rgrover1 | 257:7a50601356cc | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
rgrover1 | 257:7a50601356cc | 5 | * you may not use this file except in compliance with the License. |
rgrover1 | 257:7a50601356cc | 6 | * You may obtain a copy of the License at |
rgrover1 | 257:7a50601356cc | 7 | * |
rgrover1 | 257:7a50601356cc | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
rgrover1 | 257:7a50601356cc | 9 | * |
rgrover1 | 257:7a50601356cc | 10 | * Unless required by applicable law or agreed to in writing, software |
rgrover1 | 257:7a50601356cc | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
rgrover1 | 257:7a50601356cc | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
rgrover1 | 257:7a50601356cc | 13 | * See the License for the specific language governing permissions and |
rgrover1 | 257:7a50601356cc | 14 | * limitations under the License. |
rgrover1 | 257:7a50601356cc | 15 | */ |
rgrover1 | 257:7a50601356cc | 16 | |
rgrover1 | 257:7a50601356cc | 17 | #ifndef __BLE_DEVICE__ |
rgrover1 | 257:7a50601356cc | 18 | #define __BLE_DEVICE__ |
rgrover1 | 257:7a50601356cc | 19 | |
rgrover1 | 257:7a50601356cc | 20 | #include "blecommon.h" |
rgrover1 | 257:7a50601356cc | 21 | #include "Gap.h" |
rgrover1 | 257:7a50601356cc | 22 | #include "GattServer.h" |
rgrover1 | 257:7a50601356cc | 23 | #include "BLEDeviceInstanceBase.h" |
rgrover1 | 257:7a50601356cc | 24 | |
rgrover1 | 257:7a50601356cc | 25 | /** |
rgrover1 | 257:7a50601356cc | 26 | * The base class used to abstract away BLE capable radio transceivers or SOCs, |
rgrover1 | 257:7a50601356cc | 27 | * to enable this BLE API to work with any radio transparently. |
rgrover1 | 257:7a50601356cc | 28 | */ |
rgrover1 | 257:7a50601356cc | 29 | class BLEDevice |
rgrover1 | 257:7a50601356cc | 30 | { |
rgrover1 | 257:7a50601356cc | 31 | public: |
rgrover1 | 257:7a50601356cc | 32 | /** |
rgrover1 | 257:7a50601356cc | 33 | * Initialize the BLE controller. This should be called before using |
rgrover1 | 257:7a50601356cc | 34 | * anything else in the BLE_API. |
rgrover1 | 257:7a50601356cc | 35 | */ |
rgrover1 | 257:7a50601356cc | 36 | ble_error_t init(); |
rgrover1 | 257:7a50601356cc | 37 | ble_error_t reset(void); |
rgrover1 | 257:7a50601356cc | 38 | |
rgrover1 | 257:7a50601356cc | 39 | /** |
rgrover1 | 257:7a50601356cc | 40 | * Purge the BLE stack of GATT and GAP state. init() must be called afterwards to re-instate services and GAP state. |
rgrover1 | 257:7a50601356cc | 41 | */ |
rgrover1 | 257:7a50601356cc | 42 | ble_error_t shutdown(void); |
rgrover1 | 257:7a50601356cc | 43 | |
rgrover1 | 257:7a50601356cc | 44 | /* GAP specific APIs */ |
rgrover1 | 257:7a50601356cc | 45 | public: |
rgrover1 | 257:7a50601356cc | 46 | /** |
rgrover1 | 257:7a50601356cc | 47 | * Set the BTLE MAC address and type. |
rgrover1 | 257:7a50601356cc | 48 | * @return BLE_ERROR_NONE on success. |
rgrover1 | 257:7a50601356cc | 49 | */ |
rgrover1 | 257:7a50601356cc | 50 | ble_error_t setAddress(Gap::addr_type_t type, const Gap::address_t address); |
rgrover1 | 257:7a50601356cc | 51 | |
rgrover1 | 257:7a50601356cc | 52 | /** |
rgrover1 | 257:7a50601356cc | 53 | * Fetch the BTLE MAC address and type. |
rgrover1 | 257:7a50601356cc | 54 | * @return BLE_ERROR_NONE on success. |
rgrover1 | 257:7a50601356cc | 55 | */ |
rgrover1 | 257:7a50601356cc | 56 | ble_error_t getAddress(Gap::addr_type_t *typeP, Gap::address_t address); |
rgrover1 | 257:7a50601356cc | 57 | |
rgrover1 | 257:7a50601356cc | 58 | /** |
rgrover1 | 257:7a50601356cc | 59 | * @param[in] advType |
rgrover1 | 257:7a50601356cc | 60 | * The GAP advertising mode to use for this device. Valid |
rgrover1 | 257:7a50601356cc | 61 | * values are defined in AdvertisingType: |
rgrover1 | 257:7a50601356cc | 62 | * |
rgrover1 | 257:7a50601356cc | 63 | * \par ADV_NON_CONNECTABLE_UNDIRECTED |
rgrover1 | 257:7a50601356cc | 64 | * All connections to the peripheral device will be refused. |
rgrover1 | 257:7a50601356cc | 65 | * |
rgrover1 | 257:7a50601356cc | 66 | * \par ADV_CONNECTABLE_DIRECTED |
rgrover1 | 257:7a50601356cc | 67 | * Only connections from a pre-defined central device will be |
rgrover1 | 257:7a50601356cc | 68 | * accepted. |
rgrover1 | 257:7a50601356cc | 69 | * |
rgrover1 | 257:7a50601356cc | 70 | * \par ADV_CONNECTABLE_UNDIRECTED |
rgrover1 | 257:7a50601356cc | 71 | * Any central device can connect to this peripheral. |
rgrover1 | 257:7a50601356cc | 72 | * |
rgrover1 | 257:7a50601356cc | 73 | * \par ADV_SCANNABLE_UNDIRECTED |
rgrover1 | 300:d9a39f759a6a | 74 | * Include support for Scan Response payloads. |
rgrover1 | 257:7a50601356cc | 75 | * |
rgrover1 | 257:7a50601356cc | 76 | * \par |
rgrover1 | 257:7a50601356cc | 77 | * See Bluetooth Core Specification 4.0 (Vol. 3), Part C, |
rgrover1 | 257:7a50601356cc | 78 | * Section 9.3 and Core Specification 4.0 (Vol. 6), Part B, |
rgrover1 | 257:7a50601356cc | 79 | * Section 2.3.1 for further information on GAP connection |
rgrover1 | 257:7a50601356cc | 80 | * modes |
rgrover1 | 257:7a50601356cc | 81 | */ |
rgrover1 | 257:7a50601356cc | 82 | void setAdvertisingType(GapAdvertisingParams::AdvertisingType); |
rgrover1 | 257:7a50601356cc | 83 | |
rgrover1 | 257:7a50601356cc | 84 | /** |
rgrover1 | 257:7a50601356cc | 85 | * @param[in] interval |
rgrover1 | 325:501ad8b8bbe5 | 86 | * Advertising interval in units of milliseconds. Advertising |
rgrover1 | 325:501ad8b8bbe5 | 87 | * is disabled if interval is 0. If interval is smaller than |
rgrover1 | 325:501ad8b8bbe5 | 88 | * the minimum supported value, then the minimum supported |
rgrover1 | 325:501ad8b8bbe5 | 89 | * value is used instead. |
rgrover1 | 257:7a50601356cc | 90 | * |
rgrover1 | 257:7a50601356cc | 91 | * \par |
rgrover1 | 257:7a50601356cc | 92 | * Decreasing this value will allow central devices to detect |
rgrover1 | 257:7a50601356cc | 93 | * your peripheral faster at the expense of more power being |
rgrover1 | 257:7a50601356cc | 94 | * used by the radio due to the higher data transmit rate. |
rgrover1 | 257:7a50601356cc | 95 | * |
rgrover1 | 257:7a50601356cc | 96 | * \par |
rgrover1 | 257:7a50601356cc | 97 | * This field must be set to 0 if connectionMode is equal |
rgrover1 | 257:7a50601356cc | 98 | * to ADV_CONNECTABLE_DIRECTED |
rgrover1 | 257:7a50601356cc | 99 | * |
rgrover1 | 257:7a50601356cc | 100 | * \par |
rgrover1 | 257:7a50601356cc | 101 | * See Bluetooth Core Specification, Vol 3., Part C, |
rgrover1 | 257:7a50601356cc | 102 | * Appendix A for suggested advertising intervals. |
rgrover1 | 334:6bc1223306b9 | 103 | * |
rgrover1 | 334:6bc1223306b9 | 104 | * @Note: [WARNING] This API previously used 0.625ms as the unit for its |
rgrover1 | 334:6bc1223306b9 | 105 | * 'interval' argument. That required an explicit conversion from |
rgrover1 | 334:6bc1223306b9 | 106 | * milliseconds using Gap::MSEC_TO_GAP_DURATION_UNITS(). This conversion is |
rgrover1 | 334:6bc1223306b9 | 107 | * no longer required as the new units are milliseconds. Any application |
rgrover1 | 334:6bc1223306b9 | 108 | * code depending on the old semantics would need to be updated accordingly. |
rgrover1 | 257:7a50601356cc | 109 | */ |
rgrover1 | 257:7a50601356cc | 110 | void setAdvertisingInterval(uint16_t interval); |
rgrover1 | 257:7a50601356cc | 111 | |
rgrover1 | 257:7a50601356cc | 112 | /** |
rgrover1 | 325:501ad8b8bbe5 | 113 | * @return Minimum Advertising interval in milliseconds. |
rgrover1 | 325:501ad8b8bbe5 | 114 | */ |
rgrover1 | 325:501ad8b8bbe5 | 115 | uint16_t getMinAdvertisingInterval(void) const; |
rgrover1 | 325:501ad8b8bbe5 | 116 | /** |
rgrover1 | 325:501ad8b8bbe5 | 117 | * @return Minimum Advertising interval in milliseconds for non connectible mode. |
rgrover1 | 325:501ad8b8bbe5 | 118 | */ |
rgrover1 | 325:501ad8b8bbe5 | 119 | uint16_t getMinNonConnectableAdvertisingInterval(void) const; |
rgrover1 | 325:501ad8b8bbe5 | 120 | /** |
rgrover1 | 325:501ad8b8bbe5 | 121 | * @return Maximum Advertising interval in milliseconds. |
rgrover1 | 325:501ad8b8bbe5 | 122 | */ |
rgrover1 | 325:501ad8b8bbe5 | 123 | uint16_t getMaxAdvertisingInterval(void) const; |
rgrover1 | 325:501ad8b8bbe5 | 124 | |
rgrover1 | 325:501ad8b8bbe5 | 125 | /** |
rgrover1 | 257:7a50601356cc | 126 | * @param[in] timeout |
rgrover1 | 257:7a50601356cc | 127 | * Advertising timeout between 0x1 and 0x3FFF (1 and 16383) |
rgrover1 | 257:7a50601356cc | 128 | * in seconds. Enter 0 to disable the advertising timeout. |
rgrover1 | 257:7a50601356cc | 129 | */ |
rgrover1 | 257:7a50601356cc | 130 | void setAdvertisingTimeout(uint16_t timeout); |
rgrover1 | 257:7a50601356cc | 131 | |
rgrover1 | 257:7a50601356cc | 132 | /** |
rgrover1 | 257:7a50601356cc | 133 | * Please refer to the APIs above. |
rgrover1 | 257:7a50601356cc | 134 | */ |
rgrover1 | 257:7a50601356cc | 135 | void setAdvertisingParams(const GapAdvertisingParams &advParams); |
rgrover1 | 257:7a50601356cc | 136 | |
rgrover1 | 257:7a50601356cc | 137 | /** |
rgrover1 | 257:7a50601356cc | 138 | * This API is typically used as an internal helper to udpate the transport |
rgrover1 | 257:7a50601356cc | 139 | * backend with advertising data before starting to advertise. It may also |
rgrover1 | 257:7a50601356cc | 140 | * be explicity used to dynamically reset the accumulated advertising |
rgrover1 | 257:7a50601356cc | 141 | * payload and scanResponse; to do this, the application can clear and re- |
rgrover1 | 257:7a50601356cc | 142 | * accumulate a new advertising payload (and scanResponse) before using this |
rgrover1 | 257:7a50601356cc | 143 | * API. |
rgrover1 | 257:7a50601356cc | 144 | */ |
rgrover1 | 257:7a50601356cc | 145 | ble_error_t setAdvertisingPayload(void); |
rgrover1 | 257:7a50601356cc | 146 | |
rgrover1 | 257:7a50601356cc | 147 | /** |
rgrover1 | 257:7a50601356cc | 148 | * Reset any advertising payload prepared from prior calls to |
rgrover1 | 257:7a50601356cc | 149 | * accumulateAdvertisingPayload(). |
rgrover1 | 343:4d2576324b62 | 150 | * |
rgrover1 | 343:4d2576324b62 | 151 | * Note: This should be followed by a call to setAdvertisingPayload() or |
rgrover1 | 343:4d2576324b62 | 152 | * startAdvertising() before the update takes effect. |
rgrover1 | 257:7a50601356cc | 153 | */ |
rgrover1 | 257:7a50601356cc | 154 | void clearAdvertisingPayload(void); |
rgrover1 | 257:7a50601356cc | 155 | |
rgrover1 | 257:7a50601356cc | 156 | /** |
rgrover1 | 257:7a50601356cc | 157 | * Accumulate an AD structure in the advertising payload. Please note that |
rgrover1 | 257:7a50601356cc | 158 | * the payload is limited to 31 bytes. The SCAN_RESPONSE message may be used |
rgrover1 | 257:7a50601356cc | 159 | * as an additional 31 bytes if the advertising payload proves to be too |
rgrover1 | 257:7a50601356cc | 160 | * small. |
rgrover1 | 257:7a50601356cc | 161 | * |
rgrover1 | 257:7a50601356cc | 162 | * @param flags |
rgrover1 | 257:7a50601356cc | 163 | * The flags to be added. Multiple flags may be specified in |
rgrover1 | 257:7a50601356cc | 164 | * combination. |
rgrover1 | 257:7a50601356cc | 165 | */ |
rgrover1 | 257:7a50601356cc | 166 | ble_error_t accumulateAdvertisingPayload(uint8_t flags); |
rgrover1 | 257:7a50601356cc | 167 | |
rgrover1 | 257:7a50601356cc | 168 | /** |
rgrover1 | 257:7a50601356cc | 169 | * Accumulate an AD structure in the advertising payload. Please note that |
rgrover1 | 257:7a50601356cc | 170 | * the payload is limited to 31 bytes. The SCAN_RESPONSE message may be used |
rgrover1 | 257:7a50601356cc | 171 | * as an additional 31 bytes if the advertising payload proves to be too |
rgrover1 | 257:7a50601356cc | 172 | * small. |
rgrover1 | 257:7a50601356cc | 173 | * |
rgrover1 | 257:7a50601356cc | 174 | * @param app |
rgrover1 | 257:7a50601356cc | 175 | * The appearance of the peripheral. |
rgrover1 | 257:7a50601356cc | 176 | */ |
rgrover1 | 257:7a50601356cc | 177 | ble_error_t accumulateAdvertisingPayload(GapAdvertisingData::Appearance app); |
rgrover1 | 257:7a50601356cc | 178 | |
rgrover1 | 257:7a50601356cc | 179 | /** |
rgrover1 | 257:7a50601356cc | 180 | * Accumulate an AD structure in the advertising payload. Please note that |
rgrover1 | 257:7a50601356cc | 181 | * the payload is limited to 31 bytes. The SCAN_RESPONSE message may be used |
rgrover1 | 257:7a50601356cc | 182 | * as an additional 31 bytes if the advertising payload proves to be too |
rgrover1 | 257:7a50601356cc | 183 | * small. |
rgrover1 | 257:7a50601356cc | 184 | * |
rgrover1 | 257:7a50601356cc | 185 | * @param app |
rgrover1 | 257:7a50601356cc | 186 | * The max transmit power to be used by the controller. This is |
rgrover1 | 257:7a50601356cc | 187 | * only a hint. |
rgrover1 | 257:7a50601356cc | 188 | */ |
rgrover1 | 257:7a50601356cc | 189 | ble_error_t accumulateAdvertisingPayloadTxPower(int8_t power); |
rgrover1 | 257:7a50601356cc | 190 | |
rgrover1 | 257:7a50601356cc | 191 | /** |
rgrover1 | 257:7a50601356cc | 192 | * Accumulate a variable length byte-stream as an AD structure in the |
rgrover1 | 257:7a50601356cc | 193 | * advertising payload. Please note that the payload is limited to 31 bytes. |
rgrover1 | 257:7a50601356cc | 194 | * The SCAN_RESPONSE message may be used as an additional 31 bytes if the |
rgrover1 | 257:7a50601356cc | 195 | * advertising payload proves to be too small. |
rgrover1 | 257:7a50601356cc | 196 | * |
rgrover1 | 257:7a50601356cc | 197 | * @param type The type which describes the variable length data. |
rgrover1 | 257:7a50601356cc | 198 | * @param data data bytes. |
rgrover1 | 257:7a50601356cc | 199 | * @param len length of data. |
rgrover1 | 257:7a50601356cc | 200 | */ |
rgrover1 | 257:7a50601356cc | 201 | ble_error_t accumulateAdvertisingPayload(GapAdvertisingData::DataType type, const uint8_t *data, uint8_t len); |
rgrover1 | 257:7a50601356cc | 202 | |
rgrover1 | 257:7a50601356cc | 203 | /** |
rgrover1 | 257:7a50601356cc | 204 | * Accumulate a variable length byte-stream as an AD structure in the |
rgrover1 | 257:7a50601356cc | 205 | * scanResponse payload. |
rgrover1 | 257:7a50601356cc | 206 | * |
rgrover1 | 257:7a50601356cc | 207 | * @param type The type which describes the variable length data. |
rgrover1 | 257:7a50601356cc | 208 | * @param data data bytes. |
rgrover1 | 257:7a50601356cc | 209 | * @param len length of data. |
rgrover1 | 257:7a50601356cc | 210 | */ |
rgrover1 | 257:7a50601356cc | 211 | ble_error_t accumulateScanResponse(GapAdvertisingData::DataType type, const uint8_t *data, uint8_t len); |
rgrover1 | 257:7a50601356cc | 212 | |
rgrover1 | 257:7a50601356cc | 213 | /** |
rgrover1 | 343:4d2576324b62 | 214 | * Reset any scan response prepared from prior calls to |
rgrover1 | 343:4d2576324b62 | 215 | * accumulateScanResponse(). |
rgrover1 | 343:4d2576324b62 | 216 | * |
rgrover1 | 343:4d2576324b62 | 217 | * Note: This should be followed by a call to setAdvertisingPayload() or |
rgrover1 | 343:4d2576324b62 | 218 | * startAdvertising() before the update takes effect. |
rgrover1 | 343:4d2576324b62 | 219 | */ |
rgrover1 | 343:4d2576324b62 | 220 | void clearScanResponse(void); |
rgrover1 | 343:4d2576324b62 | 221 | |
rgrover1 | 343:4d2576324b62 | 222 | /** |
rgrover1 | 257:7a50601356cc | 223 | * Start advertising (GAP Discoverable, Connectable modes, Broadcast |
rgrover1 | 257:7a50601356cc | 224 | * Procedure). |
rgrover1 | 257:7a50601356cc | 225 | */ |
rgrover1 | 257:7a50601356cc | 226 | ble_error_t startAdvertising(void); |
rgrover1 | 257:7a50601356cc | 227 | |
rgrover1 | 257:7a50601356cc | 228 | /** |
rgrover1 | 257:7a50601356cc | 229 | * Stop advertising (GAP Discoverable, Connectable modes, Broadcast |
rgrover1 | 257:7a50601356cc | 230 | * Procedure). |
rgrover1 | 257:7a50601356cc | 231 | */ |
rgrover1 | 257:7a50601356cc | 232 | ble_error_t stopAdvertising(void); |
rgrover1 | 257:7a50601356cc | 233 | |
rgrover1 | 335:dea9e14b7ddc | 234 | /** |
rgrover1 | 335:dea9e14b7ddc | 235 | * This call initiates the disconnection procedure, and its completion will |
rgrover1 | 335:dea9e14b7ddc | 236 | * be communicated to the application with an invocation of the |
rgrover1 | 335:dea9e14b7ddc | 237 | * onDisconnection callback. |
rgrover1 | 335:dea9e14b7ddc | 238 | * |
rgrover1 | 335:dea9e14b7ddc | 239 | * @param reason |
rgrover1 | 335:dea9e14b7ddc | 240 | * The reason for disconnection to be sent back to the peer. |
rgrover1 | 335:dea9e14b7ddc | 241 | */ |
rgrover1 | 257:7a50601356cc | 242 | ble_error_t disconnect(Gap::DisconnectionReason_t reason); |
rgrover1 | 257:7a50601356cc | 243 | |
rgrover1 | 257:7a50601356cc | 244 | /* APIs to set GAP callbacks. */ |
rgrover1 | 257:7a50601356cc | 245 | void onTimeout(Gap::EventCallback_t timeoutCallback); |
rgrover1 | 257:7a50601356cc | 246 | |
rgrover1 | 257:7a50601356cc | 247 | void onConnection(Gap::ConnectionEventCallback_t connectionCallback); |
rgrover1 | 257:7a50601356cc | 248 | /** |
rgrover1 | 257:7a50601356cc | 249 | * Used to setup a callback for GAP disconnection. |
rgrover1 | 257:7a50601356cc | 250 | */ |
rgrover1 | 257:7a50601356cc | 251 | void onDisconnection(Gap::DisconnectionEventCallback_t disconnectionCallback); |
rgrover1 | 257:7a50601356cc | 252 | |
rgrover1 | 257:7a50601356cc | 253 | /** |
rgrover1 | 257:7a50601356cc | 254 | * Append to a chain of callbacks to be invoked upon disconnection; these |
rgrover1 | 257:7a50601356cc | 255 | * callbacks receive no context and are therefore different from the |
rgrover1 | 257:7a50601356cc | 256 | * onDisconnection callback. |
rgrover1 | 257:7a50601356cc | 257 | */ |
rgrover1 | 257:7a50601356cc | 258 | template<typename T> |
rgrover1 | 257:7a50601356cc | 259 | void addToDisconnectionCallChain(T *tptr, void (T::*mptr)(void)); |
rgrover1 | 257:7a50601356cc | 260 | |
rgrover1 | 257:7a50601356cc | 261 | /** |
rgrover1 | 261:b275bfc773b9 | 262 | * Add a callback for the GATT event DATA_SENT (which is triggered when |
rgrover1 | 261:b275bfc773b9 | 263 | * updates are sent out by GATT in the form of notifications). |
rgrover1 | 259:a95264ad705c | 264 | * |
rgrover1 | 259:a95264ad705c | 265 | * @Note: it is possible to chain together multiple onDataSent callbacks |
rgrover1 | 259:a95264ad705c | 266 | * (potentially from different modules of an application) to receive updates |
rgrover1 | 260:ea7f9f14cc15 | 267 | * to characteristics. |
rgrover1 | 259:a95264ad705c | 268 | * |
rgrover1 | 259:a95264ad705c | 269 | * @Note: it is also possible to setup a callback into a member function of |
rgrover1 | 259:a95264ad705c | 270 | * some object. |
rgrover1 | 257:7a50601356cc | 271 | */ |
rgrover1 | 259:a95264ad705c | 272 | void onDataSent(void (*callback)(unsigned count)); |
rgrover1 | 259:a95264ad705c | 273 | template <typename T> void onDataSent(T * objPtr, void (T::*memberPtr)(unsigned count)); |
rgrover1 | 257:7a50601356cc | 274 | |
rgrover1 | 257:7a50601356cc | 275 | /** |
rgrover1 | 257:7a50601356cc | 276 | * Setup a callback for when a characteristic has its value updated by a |
rgrover1 | 257:7a50601356cc | 277 | * client. |
rgrover1 | 257:7a50601356cc | 278 | * |
rgrover1 | 257:7a50601356cc | 279 | * @Note: it is possible to chain together multiple onDataWritten callbacks |
rgrover1 | 257:7a50601356cc | 280 | * (potentially from different modules of an application) to receive updates |
rgrover1 | 257:7a50601356cc | 281 | * to characteristics. Many services, such as DFU and UART add their own |
rgrover1 | 257:7a50601356cc | 282 | * onDataWritten callbacks behind the scenes to trap interesting events. |
rgrover1 | 257:7a50601356cc | 283 | * |
rgrover1 | 257:7a50601356cc | 284 | * @Note: it is also possible to setup a callback into a member function of |
rgrover1 | 257:7a50601356cc | 285 | * some object. |
rgrover1 | 257:7a50601356cc | 286 | */ |
rgrover1 | 257:7a50601356cc | 287 | void onDataWritten(void (*callback)(const GattCharacteristicWriteCBParams *eventDataP)); |
rgrover1 | 257:7a50601356cc | 288 | template <typename T> void onDataWritten(T * objPtr, void (T::*memberPtr)(const GattCharacteristicWriteCBParams *context)); |
rgrover1 | 257:7a50601356cc | 289 | |
rgrover1 | 300:d9a39f759a6a | 290 | /** |
rgrover1 | 300:d9a39f759a6a | 291 | * Setup a callback for when a characteristic is being read by a client. |
rgrover1 | 300:d9a39f759a6a | 292 | * |
rgrover1 | 300:d9a39f759a6a | 293 | * @Note: this functionality may not be available on all underlying stacks. |
rgrover1 | 300:d9a39f759a6a | 294 | * You could use GattCharacteristic::setReadAuthorizationCallback() as an |
rgrover1 | 300:d9a39f759a6a | 295 | * alternative. |
rgrover1 | 300:d9a39f759a6a | 296 | * |
rgrover1 | 300:d9a39f759a6a | 297 | * @Note: it is possible to chain together multiple onDataRead callbacks |
rgrover1 | 300:d9a39f759a6a | 298 | * (potentially from different modules of an application) to receive updates |
rgrover1 | 300:d9a39f759a6a | 299 | * to characteristics. Services may add their own onDataRead callbacks |
rgrover1 | 300:d9a39f759a6a | 300 | * behind the scenes to trap interesting events. |
rgrover1 | 300:d9a39f759a6a | 301 | * |
rgrover1 | 300:d9a39f759a6a | 302 | * @Note: it is also possible to setup a callback into a member function of |
rgrover1 | 300:d9a39f759a6a | 303 | * some object. |
rgrover1 | 300:d9a39f759a6a | 304 | * |
rgrover1 | 300:d9a39f759a6a | 305 | * @return BLE_ERROR_NOT_IMPLEMENTED if this functionality isn't available; |
rgrover1 | 300:d9a39f759a6a | 306 | * else BLE_ERROR_NONE. |
rgrover1 | 300:d9a39f759a6a | 307 | */ |
rgrover1 | 300:d9a39f759a6a | 308 | ble_error_t onDataRead(void (*callback)(const GattCharacteristicReadCBParams *eventDataP)); |
rgrover1 | 300:d9a39f759a6a | 309 | template <typename T> ble_error_t onDataRead(T * objPtr, void (T::*memberPtr)(const GattCharacteristicReadCBParams *context)); |
rgrover1 | 300:d9a39f759a6a | 310 | |
rgrover1 | 257:7a50601356cc | 311 | void onUpdatesEnabled(GattServer::EventCallback_t callback); |
rgrover1 | 257:7a50601356cc | 312 | void onUpdatesDisabled(GattServer::EventCallback_t callback); |
rgrover1 | 257:7a50601356cc | 313 | void onConfirmationReceived(GattServer::EventCallback_t callback); |
rgrover1 | 257:7a50601356cc | 314 | |
rgrover1 | 257:7a50601356cc | 315 | /** |
rgrover1 | 341:8a104d9d80c1 | 316 | * Radio Notification is a feature that enables ACTIVE and INACTIVE |
rgrover1 | 341:8a104d9d80c1 | 317 | * (nACTIVE) signals from the stack that notify the application when the |
rgrover1 | 341:8a104d9d80c1 | 318 | * radio is in use. The signal is sent using software interrupt. |
rgrover1 | 341:8a104d9d80c1 | 319 | * |
rgrover1 | 341:8a104d9d80c1 | 320 | * The ACTIVE signal is sent before the Radio Event starts. The nACTIVE |
rgrover1 | 341:8a104d9d80c1 | 321 | * signal is sent at the end of the Radio Event. These signals can be used |
rgrover1 | 341:8a104d9d80c1 | 322 | * by the application programmer to synchronize application logic with radio |
rgrover1 | 341:8a104d9d80c1 | 323 | * activity. For example, the ACTIVE signal can be used to shut off external |
rgrover1 | 341:8a104d9d80c1 | 324 | * devices to manage peak current drawn during periods when the radio is on, |
rgrover1 | 341:8a104d9d80c1 | 325 | * or to trigger sensor data collection for transmission in the Radio Event. |
rgrover1 | 341:8a104d9d80c1 | 326 | * |
rgrover1 | 341:8a104d9d80c1 | 327 | * @param callback |
rgrover1 | 341:8a104d9d80c1 | 328 | * The application handler to be invoked in response to a radio |
rgrover1 | 341:8a104d9d80c1 | 329 | * ACTIVE/INACTIVE event. |
rgrover1 | 341:8a104d9d80c1 | 330 | */ |
rgrover1 | 341:8a104d9d80c1 | 331 | void onRadioNotification(Gap::RadioNotificationEventCallback_t callback); |
rgrover1 | 341:8a104d9d80c1 | 332 | |
rgrover1 | 341:8a104d9d80c1 | 333 | /** |
rgrover1 | 353:5ed63cda3038 | 334 | * Delete all peer device context and all related bonding information from |
rgrover1 | 353:5ed63cda3038 | 335 | * the database within the security manager. |
rgrover1 | 353:5ed63cda3038 | 336 | * |
rgrover1 | 353:5ed63cda3038 | 337 | * @retval BLE_ERROR_NONE On success, else an error code indicating reason for failure. |
rgrover1 | 353:5ed63cda3038 | 338 | * @retval BLE_ERROR_INVALID_STATE If the API is called without module initialization and/or |
rgrover1 | 353:5ed63cda3038 | 339 | * application registration. |
rgrover1 | 353:5ed63cda3038 | 340 | */ |
rgrover1 | 353:5ed63cda3038 | 341 | ble_error_t purgeAllBondingState(void); |
rgrover1 | 353:5ed63cda3038 | 342 | |
rgrover1 | 353:5ed63cda3038 | 343 | /** |
rgrover1 | 257:7a50601356cc | 344 | * Add a service declaration to the local server ATT table. Also add the |
rgrover1 | 257:7a50601356cc | 345 | * characteristics contained within. |
rgrover1 | 257:7a50601356cc | 346 | */ |
rgrover1 | 257:7a50601356cc | 347 | ble_error_t addService(GattService &service); |
rgrover1 | 257:7a50601356cc | 348 | |
rgrover1 | 336:896e159d3af6 | 349 | /** |
rgrover1 | 336:896e159d3af6 | 350 | * Returns the current GAP state of the device using a bitmask which |
rgrover1 | 336:896e159d3af6 | 351 | * describes whether the device is advertising and/or connected. |
rgrover1 | 336:896e159d3af6 | 352 | */ |
rgrover1 | 257:7a50601356cc | 353 | Gap::GapState_t getGapState(void) const; |
rgrover1 | 257:7a50601356cc | 354 | |
rgrover1 | 257:7a50601356cc | 355 | /** |
rgrover1 | 257:7a50601356cc | 356 | * @param[in/out] lengthP |
rgrover1 | 257:7a50601356cc | 357 | * input: Length in bytes to be read, |
rgrover1 | 257:7a50601356cc | 358 | * output: Total length of attribute value upon successful return. |
rgrover1 | 257:7a50601356cc | 359 | */ |
rgrover1 | 328:1fd12f67ed7a | 360 | ble_error_t readCharacteristicValue(GattAttribute::Handle_t attributeHandle, uint8_t *buffer, uint16_t *lengthP); |
rgrover1 | 342:152bd9c825d6 | 361 | /** |
rgrover1 | 342:152bd9c825d6 | 362 | * A version of the same as above with connection handle parameter to allow fetches for connection-specific multivalued attribtues (such as the CCCDs). |
rgrover1 | 342:152bd9c825d6 | 363 | */ |
rgrover1 | 342:152bd9c825d6 | 364 | ble_error_t readCharacteristicValue(Gap::Handle_t connectionHandle, GattAttribute::Handle_t attributeHandle, uint8_t *buffer, uint16_t *lengthP); |
rgrover1 | 257:7a50601356cc | 365 | |
rgrover1 | 257:7a50601356cc | 366 | /** |
rgrover1 | 257:7a50601356cc | 367 | * @param localOnly |
rgrover1 | 257:7a50601356cc | 368 | * Only update the characteristic locally regardless of notify/indicate flags in the CCCD. |
rgrover1 | 257:7a50601356cc | 369 | */ |
rgrover1 | 328:1fd12f67ed7a | 370 | ble_error_t updateCharacteristicValue(GattAttribute::Handle_t attributeHandle, const uint8_t *value, uint16_t size, bool localOnly = false); |
rgrover1 | 342:152bd9c825d6 | 371 | /** |
rgrover1 | 342:152bd9c825d6 | 372 | * A version of the same as above with connection handle parameter to allow updates for connection-specific multivalued attribtues (such as the CCCDs). |
rgrover1 | 342:152bd9c825d6 | 373 | */ |
rgrover1 | 342:152bd9c825d6 | 374 | ble_error_t updateCharacteristicValue(Gap::Handle_t connectionHandle, GattAttribute::Handle_t attributeHandle, const uint8_t *value, uint16_t size, bool localOnly = false); |
rgrover1 | 257:7a50601356cc | 375 | |
rgrover1 | 257:7a50601356cc | 376 | /** |
rgrover1 | 257:7a50601356cc | 377 | * Yield control to the BLE stack or to other tasks waiting for events. This |
rgrover1 | 257:7a50601356cc | 378 | * is a sleep function which will return when there is an application |
rgrover1 | 257:7a50601356cc | 379 | * specific interrupt, but the MCU might wake up several times before |
rgrover1 | 257:7a50601356cc | 380 | * returning (to service the stack). This is not always interchangeable with |
rgrover1 | 257:7a50601356cc | 381 | * WFE(). |
rgrover1 | 257:7a50601356cc | 382 | */ |
rgrover1 | 257:7a50601356cc | 383 | void waitForEvent(void); |
rgrover1 | 257:7a50601356cc | 384 | |
rgrover1 | 257:7a50601356cc | 385 | ble_error_t getPreferredConnectionParams(Gap::ConnectionParams_t *params); |
rgrover1 | 257:7a50601356cc | 386 | ble_error_t setPreferredConnectionParams(const Gap::ConnectionParams_t *params); |
rgrover1 | 257:7a50601356cc | 387 | ble_error_t updateConnectionParams(Gap::Handle_t handle, const Gap::ConnectionParams_t *params); |
rgrover1 | 257:7a50601356cc | 388 | |
rgrover1 | 257:7a50601356cc | 389 | /** |
rgrover1 | 257:7a50601356cc | 390 | * This call allows the application to get the BLE stack version information. |
rgrover1 | 257:7a50601356cc | 391 | * |
rgrover1 | 257:7a50601356cc | 392 | * @return A pointer to a const string representing the version. |
rgrover1 | 257:7a50601356cc | 393 | * Note: The string is owned by the BLE_API. |
rgrover1 | 257:7a50601356cc | 394 | */ |
rgrover1 | 257:7a50601356cc | 395 | const char *getVersion(void); |
rgrover1 | 257:7a50601356cc | 396 | |
rgrover1 | 257:7a50601356cc | 397 | /** |
rgrover1 | 257:7a50601356cc | 398 | * Set the device name characteristic in the GAP service. |
rgrover1 | 257:7a50601356cc | 399 | * @param deviceName The new value for the device-name. This is a UTF-8 encoded, <b>NULL-terminated</b> string. |
rgrover1 | 257:7a50601356cc | 400 | */ |
rgrover1 | 257:7a50601356cc | 401 | ble_error_t setDeviceName(const uint8_t *deviceName); |
rgrover1 | 257:7a50601356cc | 402 | |
rgrover1 | 257:7a50601356cc | 403 | /** |
rgrover1 | 257:7a50601356cc | 404 | * Get the value of the device name characteristic in the GAP service. |
rgrover1 | 257:7a50601356cc | 405 | * @param[out] deviceName Pointer to an empty buffer where the UTF-8 *non NULL- |
rgrover1 | 257:7a50601356cc | 406 | * terminated* string will be placed. Set this |
rgrover1 | 257:7a50601356cc | 407 | * value to NULL in order to obtain the deviceName-length |
rgrover1 | 257:7a50601356cc | 408 | * from the 'length' parameter. |
rgrover1 | 257:7a50601356cc | 409 | * |
rgrover1 | 257:7a50601356cc | 410 | * @param[in/out] lengthP (on input) Length of the buffer pointed to by deviceName; |
rgrover1 | 257:7a50601356cc | 411 | * (on output) the complete device name length (without the |
rgrover1 | 257:7a50601356cc | 412 | * null terminator). |
rgrover1 | 257:7a50601356cc | 413 | * |
rgrover1 | 257:7a50601356cc | 414 | * @note If the device name is longer than the size of the supplied buffer, |
rgrover1 | 257:7a50601356cc | 415 | * length will return the complete device name length, |
rgrover1 | 257:7a50601356cc | 416 | * and not the number of bytes actually returned in deviceName. |
rgrover1 | 257:7a50601356cc | 417 | * The application may use this information to retry with a suitable buffer size. |
rgrover1 | 257:7a50601356cc | 418 | * |
rgrover1 | 257:7a50601356cc | 419 | * Sample use: |
rgrover1 | 257:7a50601356cc | 420 | * uint8_t deviceName[20]; |
rgrover1 | 257:7a50601356cc | 421 | * unsigned length = sizeof(deviceName); |
rgrover1 | 257:7a50601356cc | 422 | * ble.getDeviceName(deviceName, &length); |
rgrover1 | 257:7a50601356cc | 423 | * if (length < sizeof(deviceName)) { |
rgrover1 | 257:7a50601356cc | 424 | * deviceName[length] = 0; |
rgrover1 | 257:7a50601356cc | 425 | * } |
rgrover1 | 257:7a50601356cc | 426 | * DEBUG("length: %u, deviceName: %s\r\n", length, deviceName); |
rgrover1 | 257:7a50601356cc | 427 | */ |
rgrover1 | 257:7a50601356cc | 428 | ble_error_t getDeviceName(uint8_t *deviceName, unsigned *lengthP); |
rgrover1 | 257:7a50601356cc | 429 | |
rgrover1 | 257:7a50601356cc | 430 | /** |
rgrover1 | 257:7a50601356cc | 431 | * Set the appearance characteristic in the GAP service. |
rgrover1 | 257:7a50601356cc | 432 | * @param[in] appearance The new value for the device-appearance. |
rgrover1 | 257:7a50601356cc | 433 | */ |
rgrover1 | 257:7a50601356cc | 434 | ble_error_t setAppearance(uint16_t appearance); |
rgrover1 | 257:7a50601356cc | 435 | |
rgrover1 | 257:7a50601356cc | 436 | /** |
rgrover1 | 257:7a50601356cc | 437 | * Set the appearance characteristic in the GAP service. |
rgrover1 | 257:7a50601356cc | 438 | * @param[out] appearance The new value for the device-appearance. |
rgrover1 | 257:7a50601356cc | 439 | */ |
rgrover1 | 257:7a50601356cc | 440 | ble_error_t getAppearance(uint16_t *appearanceP); |
rgrover1 | 257:7a50601356cc | 441 | |
rgrover1 | 257:7a50601356cc | 442 | /** |
rgrover1 | 257:7a50601356cc | 443 | * Set the radio's transmit power. |
rgrover1 | 257:7a50601356cc | 444 | * @param[in] txPower Radio transmit power in dBm. |
rgrover1 | 257:7a50601356cc | 445 | */ |
rgrover1 | 257:7a50601356cc | 446 | ble_error_t setTxPower(int8_t txPower); |
rgrover1 | 257:7a50601356cc | 447 | |
rgrover1 | 305:71367f7cd078 | 448 | /** |
rgrover1 | 305:71367f7cd078 | 449 | * Query the underlying stack for permitted arguments for setTxPower(). |
rgrover1 | 305:71367f7cd078 | 450 | * |
rgrover1 | 305:71367f7cd078 | 451 | * @param[out] valueArrayPP |
rgrover1 | 305:71367f7cd078 | 452 | * Out parameter to receive the immutable array of Tx values. |
rgrover1 | 305:71367f7cd078 | 453 | * @param[out] countP |
rgrover1 | 305:71367f7cd078 | 454 | * Out parameter to receive the array's size. |
rgrover1 | 305:71367f7cd078 | 455 | */ |
rgrover1 | 305:71367f7cd078 | 456 | void getPermittedTxPowerValues(const int8_t **valueArrayPP, size_t *countP); |
rgrover1 | 305:71367f7cd078 | 457 | |
rgrover1 | 347:20be4234c6fe | 458 | /** |
rgrover1 | 347:20be4234c6fe | 459 | * Enable the BLE stack's Security Manager. The Security Manager implements |
rgrover1 | 347:20be4234c6fe | 460 | * the actual cryptographic algorithms and protocol exchanges that allow two |
rgrover1 | 347:20be4234c6fe | 461 | * devices to securely exchange data and privately detect each other. |
rgrover1 | 347:20be4234c6fe | 462 | * Calling this API is a prerequisite for encryption and pairing (bonding). |
rgrover1 | 357:d4bb5d2b837a | 463 | * |
rgrover1 | 357:d4bb5d2b837a | 464 | * @param[in] enableBonding Allow for bonding. |
rgrover1 | 357:d4bb5d2b837a | 465 | * @param[in] requireMITM Require protection for man-in-the-middle attacks. |
rgrover1 | 357:d4bb5d2b837a | 466 | * @param[in] iocaps To specify IO capabilities of this peripheral, |
rgrover1 | 357:d4bb5d2b837a | 467 | * such as availability of a display or keyboard to |
rgrover1 | 357:d4bb5d2b837a | 468 | * support out-of-band exchanges of security data. |
rgrover1 | 357:d4bb5d2b837a | 469 | * @param[in] passkey To specify a static passkey. |
rgrover1 | 357:d4bb5d2b837a | 470 | * |
rgrover1 | 357:d4bb5d2b837a | 471 | * @return BLE_ERROR_NONE on success. |
rgrover1 | 347:20be4234c6fe | 472 | */ |
rgrover1 | 357:d4bb5d2b837a | 473 | ble_error_t initializeSecurity(bool enableBonding = true, |
rgrover1 | 357:d4bb5d2b837a | 474 | bool requireMITM = true, |
rgrover1 | 357:d4bb5d2b837a | 475 | Gap::SecurityIOCapabilities_t iocaps = Gap::IO_CAPS_NONE, |
rgrover1 | 357:d4bb5d2b837a | 476 | const Gap::Passkey_t passkey = NULL); |
rgrover1 | 347:20be4234c6fe | 477 | |
rgrover1 | 368:89726b616c1b | 478 | /** |
rgrover1 | 368:89726b616c1b | 479 | * Setup a callback for when the security setup procedure (key generation |
rgrover1 | 368:89726b616c1b | 480 | * and exchange) for a link has started. This will be skipped for bonded |
rgrover1 | 368:89726b616c1b | 481 | * devices. The callback is passed in parameters received from the peer's |
rgrover1 | 368:89726b616c1b | 482 | * security request: bool allowBonding, bool requireMITM, and |
rgrover1 | 368:89726b616c1b | 483 | * SecurityIOCapabilities_t. |
rgrover1 | 368:89726b616c1b | 484 | */ |
rgrover1 | 368:89726b616c1b | 485 | void onSecuritySetupInitiated(Gap::SecuritySetupInitiatedCallback_t callback); |
rgrover1 | 368:89726b616c1b | 486 | |
rgrover1 | 368:89726b616c1b | 487 | /** |
rgrover1 | 368:89726b616c1b | 488 | * Setup a callback for when the security setup procedure (key generation |
rgrover1 | 368:89726b616c1b | 489 | * and exchange) for a link has completed. This will be skipped for bonded |
rgrover1 | 368:89726b616c1b | 490 | * devices. The callback is passed in the success/failure status of the |
rgrover1 | 368:89726b616c1b | 491 | * security setup procedure. |
rgrover1 | 368:89726b616c1b | 492 | */ |
rgrover1 | 368:89726b616c1b | 493 | void onSecuritySetupCompleted(Gap::SecuritySetupCompletedCallback_t callback); |
rgrover1 | 368:89726b616c1b | 494 | |
rgrover1 | 368:89726b616c1b | 495 | /** |
rgrover1 | 368:89726b616c1b | 496 | * Setup a callback for when a link with the peer is secured. For bonded |
rgrover1 | 368:89726b616c1b | 497 | * devices, subsequent reconnections with bonded peer will result only in |
rgrover1 | 368:89726b616c1b | 498 | * this callback when the link is secured and setup procedures will not |
rgrover1 | 368:89726b616c1b | 499 | * occur unless the bonding information is either lost or deleted on either |
rgrover1 | 368:89726b616c1b | 500 | * or both sides. The callback is passed in a Gap::SecurityMode_t according |
rgrover1 | 368:89726b616c1b | 501 | * to the level of security in effect for the secured link. |
rgrover1 | 368:89726b616c1b | 502 | */ |
rgrover1 | 368:89726b616c1b | 503 | void onLinkSecured(Gap::LinkSecuredCallback_t callback); |
rgrover1 | 368:89726b616c1b | 504 | |
rgrover1 | 368:89726b616c1b | 505 | /** |
rgrover1 | 368:89726b616c1b | 506 | * Setup a callback for successful bonding; i.e. that link-specific security |
rgrover1 | 368:89726b616c1b | 507 | * context is stored persistently for a peer device. |
rgrover1 | 368:89726b616c1b | 508 | */ |
rgrover1 | 368:89726b616c1b | 509 | void onSecurityContextStored(Gap::HandleSpecificEvent_t callback); |
rgrover1 | 368:89726b616c1b | 510 | |
rgrover1 | 368:89726b616c1b | 511 | /** |
rgrover1 | 369:9a76cc068644 | 512 | * Setup a callback for when the passkey needs to be displayed on a |
rgrover1 | 369:9a76cc068644 | 513 | * peripheral with DISPLAY capability. This happens when security is |
rgrover1 | 369:9a76cc068644 | 514 | * configured to prevent Man-In-The-Middle attacks, and a PIN (or passkey) |
rgrover1 | 369:9a76cc068644 | 515 | * needs to be exchanged between the peers to authenticate the connection |
rgrover1 | 369:9a76cc068644 | 516 | * attempt. |
rgrover1 | 369:9a76cc068644 | 517 | */ |
rgrover1 | 369:9a76cc068644 | 518 | void onPasskeyDisplay(Gap::PasskeyDisplayCallback_t callback); |
rgrover1 | 369:9a76cc068644 | 519 | |
rgrover1 | 369:9a76cc068644 | 520 | /** |
rgrover1 | 368:89726b616c1b | 521 | * Get the security status of a connection. |
rgrover1 | 368:89726b616c1b | 522 | * |
rgrover1 | 368:89726b616c1b | 523 | * @param[in] connectionHandle Handle to identify the connection. |
rgrover1 | 368:89726b616c1b | 524 | * @param[out] securityStatusP security status. |
rgrover1 | 368:89726b616c1b | 525 | * |
rgrover1 | 368:89726b616c1b | 526 | * @return BLE_SUCCESS Or appropriate error code indicating reason for failure. |
rgrover1 | 368:89726b616c1b | 527 | */ |
rgrover1 | 368:89726b616c1b | 528 | ble_error_t getLinkSecurity(Gap::Handle_t connectionHandle, Gap::LinkSecurityStatus_t *securityStatusP); |
rgrover1 | 368:89726b616c1b | 529 | |
rgrover1 | 257:7a50601356cc | 530 | public: |
rgrover1 | 257:7a50601356cc | 531 | BLEDevice() : transport(createBLEDeviceInstance()), advParams(), advPayload(), scanResponse(), needToSetAdvPayload(true) { |
rgrover1 | 257:7a50601356cc | 532 | advPayload.clear(); |
rgrover1 | 257:7a50601356cc | 533 | scanResponse.clear(); |
rgrover1 | 257:7a50601356cc | 534 | } |
rgrover1 | 257:7a50601356cc | 535 | |
rgrover1 | 257:7a50601356cc | 536 | private: |
rgrover1 | 257:7a50601356cc | 537 | BLEDeviceInstanceBase *const transport; /* the device specific backend */ |
rgrover1 | 257:7a50601356cc | 538 | |
rgrover1 | 257:7a50601356cc | 539 | GapAdvertisingParams advParams; |
rgrover1 | 257:7a50601356cc | 540 | GapAdvertisingData advPayload; |
rgrover1 | 257:7a50601356cc | 541 | GapAdvertisingData scanResponse; |
rgrover1 | 257:7a50601356cc | 542 | |
rgrover1 | 257:7a50601356cc | 543 | /* Accumulation of AD structures in the advertisement payload should |
rgrover1 | 257:7a50601356cc | 544 | * eventually result in a call to the target's setAdvertisingData() before |
rgrover1 | 257:7a50601356cc | 545 | * the server begins advertising. This flag marks the status of the pending update.*/ |
rgrover1 | 257:7a50601356cc | 546 | bool needToSetAdvPayload; |
rgrover1 | 257:7a50601356cc | 547 | }; |
rgrover1 | 257:7a50601356cc | 548 | |
rgrover1 | 257:7a50601356cc | 549 | /* BLEDevice methods. Most of these simply forward the calls to the underlying |
rgrover1 | 257:7a50601356cc | 550 | * transport.*/ |
rgrover1 | 257:7a50601356cc | 551 | |
rgrover1 | 257:7a50601356cc | 552 | inline ble_error_t |
rgrover1 | 257:7a50601356cc | 553 | BLEDevice::reset(void) |
rgrover1 | 257:7a50601356cc | 554 | { |
rgrover1 | 257:7a50601356cc | 555 | return transport->reset(); |
rgrover1 | 257:7a50601356cc | 556 | } |
rgrover1 | 257:7a50601356cc | 557 | |
rgrover1 | 257:7a50601356cc | 558 | inline ble_error_t |
rgrover1 | 257:7a50601356cc | 559 | BLEDevice::shutdown(void) |
rgrover1 | 257:7a50601356cc | 560 | { |
rgrover1 | 257:7a50601356cc | 561 | clearAdvertisingPayload(); |
rgrover1 | 257:7a50601356cc | 562 | return transport->shutdown(); |
rgrover1 | 257:7a50601356cc | 563 | } |
rgrover1 | 257:7a50601356cc | 564 | |
rgrover1 | 257:7a50601356cc | 565 | inline ble_error_t |
rgrover1 | 257:7a50601356cc | 566 | BLEDevice::setAddress(Gap::addr_type_t type, const Gap::address_t address) |
rgrover1 | 257:7a50601356cc | 567 | { |
rgrover1 | 257:7a50601356cc | 568 | return transport->getGap().setAddress(type, address); |
rgrover1 | 257:7a50601356cc | 569 | } |
rgrover1 | 257:7a50601356cc | 570 | |
rgrover1 | 257:7a50601356cc | 571 | inline ble_error_t |
rgrover1 | 257:7a50601356cc | 572 | BLEDevice::getAddress(Gap::addr_type_t *typeP, Gap::address_t address) |
rgrover1 | 257:7a50601356cc | 573 | { |
rgrover1 | 257:7a50601356cc | 574 | return transport->getGap().getAddress(typeP, address); |
rgrover1 | 257:7a50601356cc | 575 | } |
rgrover1 | 257:7a50601356cc | 576 | |
rgrover1 | 257:7a50601356cc | 577 | inline void |
rgrover1 | 257:7a50601356cc | 578 | BLEDevice::setAdvertisingType(GapAdvertisingParams::AdvertisingType advType) |
rgrover1 | 257:7a50601356cc | 579 | { |
rgrover1 | 257:7a50601356cc | 580 | advParams.setAdvertisingType(advType); |
rgrover1 | 257:7a50601356cc | 581 | } |
rgrover1 | 257:7a50601356cc | 582 | |
rgrover1 | 257:7a50601356cc | 583 | inline void |
rgrover1 | 257:7a50601356cc | 584 | BLEDevice::setAdvertisingInterval(uint16_t interval) |
rgrover1 | 257:7a50601356cc | 585 | { |
rgrover1 | 325:501ad8b8bbe5 | 586 | if (interval == 0) { |
rgrover1 | 325:501ad8b8bbe5 | 587 | stopAdvertising(); |
rgrover1 | 325:501ad8b8bbe5 | 588 | } else if (interval < getMinAdvertisingInterval()) { |
rgrover1 | 325:501ad8b8bbe5 | 589 | interval = getMinAdvertisingInterval(); |
rgrover1 | 325:501ad8b8bbe5 | 590 | } |
rgrover1 | 325:501ad8b8bbe5 | 591 | advParams.setInterval(Gap::MSEC_TO_ADVERTISEMENT_DURATION_UNITS(interval)); |
rgrover1 | 325:501ad8b8bbe5 | 592 | } |
rgrover1 | 325:501ad8b8bbe5 | 593 | |
rgrover1 | 325:501ad8b8bbe5 | 594 | inline uint16_t |
rgrover1 | 325:501ad8b8bbe5 | 595 | BLEDevice::getMinAdvertisingInterval(void) const { |
rgrover1 | 325:501ad8b8bbe5 | 596 | return transport->getGap().getMinAdvertisingInterval(); |
rgrover1 | 325:501ad8b8bbe5 | 597 | } |
rgrover1 | 325:501ad8b8bbe5 | 598 | |
rgrover1 | 325:501ad8b8bbe5 | 599 | inline uint16_t |
rgrover1 | 325:501ad8b8bbe5 | 600 | BLEDevice::getMinNonConnectableAdvertisingInterval(void) const { |
rgrover1 | 325:501ad8b8bbe5 | 601 | return transport->getGap().getMinNonConnectableAdvertisingInterval(); |
rgrover1 | 325:501ad8b8bbe5 | 602 | } |
rgrover1 | 325:501ad8b8bbe5 | 603 | |
rgrover1 | 325:501ad8b8bbe5 | 604 | inline uint16_t |
rgrover1 | 325:501ad8b8bbe5 | 605 | BLEDevice::getMaxAdvertisingInterval(void) const { |
rgrover1 | 325:501ad8b8bbe5 | 606 | return transport->getGap().getMaxAdvertisingInterval(); |
rgrover1 | 257:7a50601356cc | 607 | } |
rgrover1 | 257:7a50601356cc | 608 | |
rgrover1 | 257:7a50601356cc | 609 | inline void |
rgrover1 | 257:7a50601356cc | 610 | BLEDevice::setAdvertisingTimeout(uint16_t timeout) |
rgrover1 | 257:7a50601356cc | 611 | { |
rgrover1 | 257:7a50601356cc | 612 | advParams.setTimeout(timeout); |
rgrover1 | 257:7a50601356cc | 613 | } |
rgrover1 | 257:7a50601356cc | 614 | |
rgrover1 | 257:7a50601356cc | 615 | inline void |
rgrover1 | 257:7a50601356cc | 616 | BLEDevice::setAdvertisingParams(const GapAdvertisingParams &newAdvParams) |
rgrover1 | 257:7a50601356cc | 617 | { |
rgrover1 | 257:7a50601356cc | 618 | advParams = newAdvParams; |
rgrover1 | 257:7a50601356cc | 619 | } |
rgrover1 | 257:7a50601356cc | 620 | |
rgrover1 | 257:7a50601356cc | 621 | inline void |
rgrover1 | 257:7a50601356cc | 622 | BLEDevice::clearAdvertisingPayload(void) |
rgrover1 | 257:7a50601356cc | 623 | { |
rgrover1 | 257:7a50601356cc | 624 | needToSetAdvPayload = true; |
rgrover1 | 257:7a50601356cc | 625 | advPayload.clear(); |
rgrover1 | 257:7a50601356cc | 626 | } |
rgrover1 | 257:7a50601356cc | 627 | |
rgrover1 | 257:7a50601356cc | 628 | inline ble_error_t |
rgrover1 | 257:7a50601356cc | 629 | BLEDevice::accumulateAdvertisingPayload(uint8_t flags) |
rgrover1 | 257:7a50601356cc | 630 | { |
rgrover1 | 257:7a50601356cc | 631 | needToSetAdvPayload = true; |
rgrover1 | 257:7a50601356cc | 632 | return advPayload.addFlags(flags); |
rgrover1 | 257:7a50601356cc | 633 | } |
rgrover1 | 257:7a50601356cc | 634 | |
rgrover1 | 257:7a50601356cc | 635 | inline ble_error_t |
rgrover1 | 257:7a50601356cc | 636 | BLEDevice::accumulateAdvertisingPayload(GapAdvertisingData::Appearance app) |
rgrover1 | 257:7a50601356cc | 637 | { |
rgrover1 | 257:7a50601356cc | 638 | needToSetAdvPayload = true; |
rgrover1 | 257:7a50601356cc | 639 | transport->getGap().setAppearance(app); |
rgrover1 | 257:7a50601356cc | 640 | return advPayload.addAppearance(app); |
rgrover1 | 257:7a50601356cc | 641 | } |
rgrover1 | 257:7a50601356cc | 642 | |
rgrover1 | 257:7a50601356cc | 643 | inline ble_error_t |
rgrover1 | 257:7a50601356cc | 644 | BLEDevice::accumulateAdvertisingPayloadTxPower(int8_t txPower) |
rgrover1 | 257:7a50601356cc | 645 | { |
rgrover1 | 257:7a50601356cc | 646 | needToSetAdvPayload = true; |
rgrover1 | 257:7a50601356cc | 647 | return advPayload.addTxPower(txPower); |
rgrover1 | 257:7a50601356cc | 648 | } |
rgrover1 | 257:7a50601356cc | 649 | |
rgrover1 | 257:7a50601356cc | 650 | inline ble_error_t |
rgrover1 | 257:7a50601356cc | 651 | BLEDevice::accumulateAdvertisingPayload(GapAdvertisingData::DataType type, const uint8_t *data, uint8_t len) |
rgrover1 | 257:7a50601356cc | 652 | { |
rgrover1 | 257:7a50601356cc | 653 | needToSetAdvPayload = true; |
rgrover1 | 257:7a50601356cc | 654 | if (type == GapAdvertisingData::COMPLETE_LOCAL_NAME) { |
rgrover1 | 257:7a50601356cc | 655 | transport->getGap().setDeviceName(data); |
rgrover1 | 257:7a50601356cc | 656 | } |
rgrover1 | 257:7a50601356cc | 657 | return advPayload.addData(type, data, len); |
rgrover1 | 257:7a50601356cc | 658 | } |
rgrover1 | 257:7a50601356cc | 659 | |
rgrover1 | 257:7a50601356cc | 660 | inline ble_error_t |
rgrover1 | 257:7a50601356cc | 661 | BLEDevice::accumulateScanResponse(GapAdvertisingData::DataType type, const uint8_t *data, uint8_t len) |
rgrover1 | 257:7a50601356cc | 662 | { |
rgrover1 | 257:7a50601356cc | 663 | needToSetAdvPayload = true; |
rgrover1 | 257:7a50601356cc | 664 | return scanResponse.addData(type, data, len); |
rgrover1 | 257:7a50601356cc | 665 | } |
rgrover1 | 257:7a50601356cc | 666 | |
rgrover1 | 343:4d2576324b62 | 667 | inline void |
rgrover1 | 343:4d2576324b62 | 668 | BLEDevice::clearScanResponse(void) |
rgrover1 | 343:4d2576324b62 | 669 | { |
rgrover1 | 343:4d2576324b62 | 670 | needToSetAdvPayload = true; |
rgrover1 | 343:4d2576324b62 | 671 | scanResponse.clear(); |
rgrover1 | 343:4d2576324b62 | 672 | } |
rgrover1 | 343:4d2576324b62 | 673 | |
rgrover1 | 257:7a50601356cc | 674 | inline ble_error_t |
rgrover1 | 257:7a50601356cc | 675 | BLEDevice::setAdvertisingPayload(void) { |
rgrover1 | 257:7a50601356cc | 676 | needToSetAdvPayload = false; |
rgrover1 | 257:7a50601356cc | 677 | return transport->getGap().setAdvertisingData(advPayload, scanResponse); |
rgrover1 | 257:7a50601356cc | 678 | } |
rgrover1 | 257:7a50601356cc | 679 | |
rgrover1 | 257:7a50601356cc | 680 | inline ble_error_t |
rgrover1 | 257:7a50601356cc | 681 | BLEDevice::startAdvertising(void) |
rgrover1 | 257:7a50601356cc | 682 | { |
rgrover1 | 257:7a50601356cc | 683 | ble_error_t rc; |
rgrover1 | 257:7a50601356cc | 684 | if ((rc = transport->getGattServer().initializeGATTDatabase()) != BLE_ERROR_NONE) { |
rgrover1 | 257:7a50601356cc | 685 | return rc; |
rgrover1 | 257:7a50601356cc | 686 | } |
rgrover1 | 257:7a50601356cc | 687 | if (needToSetAdvPayload) { |
rgrover1 | 257:7a50601356cc | 688 | if ((rc = setAdvertisingPayload()) != BLE_ERROR_NONE) { |
rgrover1 | 257:7a50601356cc | 689 | return rc; |
rgrover1 | 257:7a50601356cc | 690 | } |
rgrover1 | 257:7a50601356cc | 691 | } |
rgrover1 | 257:7a50601356cc | 692 | |
rgrover1 | 257:7a50601356cc | 693 | return transport->getGap().startAdvertising(advParams); |
rgrover1 | 257:7a50601356cc | 694 | } |
rgrover1 | 257:7a50601356cc | 695 | |
rgrover1 | 257:7a50601356cc | 696 | inline ble_error_t |
rgrover1 | 257:7a50601356cc | 697 | BLEDevice::stopAdvertising(void) |
rgrover1 | 257:7a50601356cc | 698 | { |
rgrover1 | 257:7a50601356cc | 699 | return transport->getGap().stopAdvertising(); |
rgrover1 | 257:7a50601356cc | 700 | } |
rgrover1 | 257:7a50601356cc | 701 | |
rgrover1 | 257:7a50601356cc | 702 | inline ble_error_t |
rgrover1 | 257:7a50601356cc | 703 | BLEDevice::disconnect(Gap::DisconnectionReason_t reason) |
rgrover1 | 257:7a50601356cc | 704 | { |
rgrover1 | 257:7a50601356cc | 705 | return transport->getGap().disconnect(reason); |
rgrover1 | 257:7a50601356cc | 706 | } |
rgrover1 | 257:7a50601356cc | 707 | |
rgrover1 | 257:7a50601356cc | 708 | inline void |
rgrover1 | 257:7a50601356cc | 709 | BLEDevice::onTimeout(Gap::EventCallback_t timeoutCallback) |
rgrover1 | 257:7a50601356cc | 710 | { |
rgrover1 | 257:7a50601356cc | 711 | transport->getGap().setOnTimeout(timeoutCallback); |
rgrover1 | 257:7a50601356cc | 712 | } |
rgrover1 | 257:7a50601356cc | 713 | |
rgrover1 | 257:7a50601356cc | 714 | inline void |
rgrover1 | 257:7a50601356cc | 715 | BLEDevice::onConnection(Gap::ConnectionEventCallback_t connectionCallback) |
rgrover1 | 257:7a50601356cc | 716 | { |
rgrover1 | 257:7a50601356cc | 717 | transport->getGap().setOnConnection(connectionCallback); |
rgrover1 | 257:7a50601356cc | 718 | } |
rgrover1 | 257:7a50601356cc | 719 | |
rgrover1 | 257:7a50601356cc | 720 | inline void |
rgrover1 | 257:7a50601356cc | 721 | BLEDevice::onDisconnection(Gap::DisconnectionEventCallback_t disconnectionCallback) |
rgrover1 | 257:7a50601356cc | 722 | { |
rgrover1 | 257:7a50601356cc | 723 | transport->getGap().setOnDisconnection(disconnectionCallback); |
rgrover1 | 257:7a50601356cc | 724 | } |
rgrover1 | 257:7a50601356cc | 725 | |
rgrover1 | 257:7a50601356cc | 726 | template<typename T> |
rgrover1 | 257:7a50601356cc | 727 | inline void |
rgrover1 | 257:7a50601356cc | 728 | BLEDevice::addToDisconnectionCallChain(T *tptr, void (T::*mptr)(void)) { |
rgrover1 | 257:7a50601356cc | 729 | transport->getGap().addToDisconnectionCallChain(tptr, mptr); |
rgrover1 | 257:7a50601356cc | 730 | } |
rgrover1 | 257:7a50601356cc | 731 | |
rgrover1 | 257:7a50601356cc | 732 | inline void |
rgrover1 | 259:a95264ad705c | 733 | BLEDevice::onDataSent(void (*callback)(unsigned count)) { |
rgrover1 | 257:7a50601356cc | 734 | transport->getGattServer().setOnDataSent(callback); |
rgrover1 | 257:7a50601356cc | 735 | } |
rgrover1 | 257:7a50601356cc | 736 | |
rgrover1 | 259:a95264ad705c | 737 | template <typename T> inline void |
rgrover1 | 259:a95264ad705c | 738 | BLEDevice::onDataSent(T *objPtr, void (T::*memberPtr)(unsigned count)) { |
rgrover1 | 259:a95264ad705c | 739 | transport->getGattServer().setOnDataSent(objPtr, memberPtr); |
rgrover1 | 259:a95264ad705c | 740 | } |
rgrover1 | 259:a95264ad705c | 741 | |
rgrover1 | 257:7a50601356cc | 742 | inline void |
rgrover1 | 257:7a50601356cc | 743 | BLEDevice::onDataWritten(void (*callback)(const GattCharacteristicWriteCBParams *eventDataP)) { |
rgrover1 | 257:7a50601356cc | 744 | transport->getGattServer().setOnDataWritten(callback); |
rgrover1 | 257:7a50601356cc | 745 | } |
rgrover1 | 257:7a50601356cc | 746 | |
rgrover1 | 257:7a50601356cc | 747 | template <typename T> inline void |
rgrover1 | 257:7a50601356cc | 748 | BLEDevice::onDataWritten(T *objPtr, void (T::*memberPtr)(const GattCharacteristicWriteCBParams *context)) { |
rgrover1 | 257:7a50601356cc | 749 | transport->getGattServer().setOnDataWritten(objPtr, memberPtr); |
rgrover1 | 257:7a50601356cc | 750 | } |
rgrover1 | 257:7a50601356cc | 751 | |
rgrover1 | 300:d9a39f759a6a | 752 | inline ble_error_t |
rgrover1 | 300:d9a39f759a6a | 753 | BLEDevice::onDataRead(void (*callback)(const GattCharacteristicReadCBParams *eventDataP)) { |
rgrover1 | 300:d9a39f759a6a | 754 | return transport->getGattServer().setOnDataRead(callback); |
rgrover1 | 300:d9a39f759a6a | 755 | } |
rgrover1 | 300:d9a39f759a6a | 756 | |
rgrover1 | 300:d9a39f759a6a | 757 | template <typename T> inline ble_error_t |
rgrover1 | 300:d9a39f759a6a | 758 | BLEDevice::onDataRead(T *objPtr, void (T::*memberPtr)(const GattCharacteristicReadCBParams *context)) { |
rgrover1 | 300:d9a39f759a6a | 759 | return transport->getGattServer().setOnDataRead(objPtr, memberPtr); |
rgrover1 | 300:d9a39f759a6a | 760 | } |
rgrover1 | 300:d9a39f759a6a | 761 | |
rgrover1 | 257:7a50601356cc | 762 | inline void |
rgrover1 | 257:7a50601356cc | 763 | BLEDevice::onUpdatesEnabled(GattServer::EventCallback_t callback) |
rgrover1 | 257:7a50601356cc | 764 | { |
rgrover1 | 257:7a50601356cc | 765 | transport->getGattServer().setOnUpdatesEnabled(callback); |
rgrover1 | 257:7a50601356cc | 766 | } |
rgrover1 | 257:7a50601356cc | 767 | |
rgrover1 | 257:7a50601356cc | 768 | inline void |
rgrover1 | 257:7a50601356cc | 769 | BLEDevice::onUpdatesDisabled(GattServer::EventCallback_t callback) |
rgrover1 | 257:7a50601356cc | 770 | { |
rgrover1 | 257:7a50601356cc | 771 | transport->getGattServer().setOnUpdatesDisabled(callback); |
rgrover1 | 257:7a50601356cc | 772 | } |
rgrover1 | 257:7a50601356cc | 773 | |
rgrover1 | 257:7a50601356cc | 774 | inline void |
rgrover1 | 257:7a50601356cc | 775 | BLEDevice::onConfirmationReceived(GattServer::EventCallback_t callback) |
rgrover1 | 257:7a50601356cc | 776 | { |
rgrover1 | 257:7a50601356cc | 777 | transport->getGattServer().setOnConfirmationReceived(callback); |
rgrover1 | 257:7a50601356cc | 778 | } |
rgrover1 | 257:7a50601356cc | 779 | |
rgrover1 | 341:8a104d9d80c1 | 780 | inline void |
rgrover1 | 341:8a104d9d80c1 | 781 | BLEDevice::onRadioNotification(Gap::RadioNotificationEventCallback_t callback) |
rgrover1 | 341:8a104d9d80c1 | 782 | { |
rgrover1 | 341:8a104d9d80c1 | 783 | transport->getGap().setOnRadioNotification(callback); |
rgrover1 | 341:8a104d9d80c1 | 784 | } |
rgrover1 | 341:8a104d9d80c1 | 785 | |
rgrover1 | 353:5ed63cda3038 | 786 | inline ble_error_t |
rgrover1 | 353:5ed63cda3038 | 787 | BLEDevice::purgeAllBondingState(void) |
rgrover1 | 353:5ed63cda3038 | 788 | { |
rgrover1 | 353:5ed63cda3038 | 789 | return transport->getGap().purgeAllBondingState(); |
rgrover1 | 353:5ed63cda3038 | 790 | } |
rgrover1 | 353:5ed63cda3038 | 791 | |
rgrover1 | 353:5ed63cda3038 | 792 | inline ble_error_t |
rgrover1 | 257:7a50601356cc | 793 | BLEDevice::addService(GattService &service) |
rgrover1 | 257:7a50601356cc | 794 | { |
rgrover1 | 257:7a50601356cc | 795 | return transport->getGattServer().addService(service); |
rgrover1 | 257:7a50601356cc | 796 | } |
rgrover1 | 257:7a50601356cc | 797 | |
rgrover1 | 257:7a50601356cc | 798 | inline Gap::GapState_t |
rgrover1 | 257:7a50601356cc | 799 | BLEDevice::getGapState(void) const |
rgrover1 | 257:7a50601356cc | 800 | { |
rgrover1 | 257:7a50601356cc | 801 | return transport->getGap().getState(); |
rgrover1 | 257:7a50601356cc | 802 | } |
rgrover1 | 257:7a50601356cc | 803 | |
rgrover1 | 328:1fd12f67ed7a | 804 | inline ble_error_t BLEDevice::readCharacteristicValue(GattAttribute::Handle_t attributeHandle, uint8_t *buffer, uint16_t *lengthP) |
rgrover1 | 257:7a50601356cc | 805 | { |
rgrover1 | 328:1fd12f67ed7a | 806 | return transport->getGattServer().readValue(attributeHandle, buffer, lengthP); |
rgrover1 | 257:7a50601356cc | 807 | } |
rgrover1 | 257:7a50601356cc | 808 | |
rgrover1 | 342:152bd9c825d6 | 809 | inline ble_error_t BLEDevice::readCharacteristicValue(Gap::Handle_t connectionHandle, GattAttribute::Handle_t attributeHandle, uint8_t *buffer, uint16_t *lengthP) |
rgrover1 | 342:152bd9c825d6 | 810 | { |
rgrover1 | 342:152bd9c825d6 | 811 | return transport->getGattServer().readValue(connectionHandle, attributeHandle, buffer, lengthP); |
rgrover1 | 342:152bd9c825d6 | 812 | } |
rgrover1 | 342:152bd9c825d6 | 813 | |
rgrover1 | 257:7a50601356cc | 814 | inline ble_error_t |
rgrover1 | 328:1fd12f67ed7a | 815 | BLEDevice::updateCharacteristicValue(GattAttribute::Handle_t attributeHandle, const uint8_t *value, uint16_t size, bool localOnly) |
rgrover1 | 257:7a50601356cc | 816 | { |
rgrover1 | 328:1fd12f67ed7a | 817 | return transport->getGattServer().updateValue(attributeHandle, const_cast<uint8_t *>(value), size, localOnly); |
rgrover1 | 257:7a50601356cc | 818 | } |
rgrover1 | 257:7a50601356cc | 819 | |
rgrover1 | 342:152bd9c825d6 | 820 | inline ble_error_t |
rgrover1 | 342:152bd9c825d6 | 821 | BLEDevice::updateCharacteristicValue(Gap::Handle_t connectionHandle, GattAttribute::Handle_t attributeHandle, const uint8_t *value, uint16_t size, bool localOnly) |
rgrover1 | 342:152bd9c825d6 | 822 | { |
rgrover1 | 342:152bd9c825d6 | 823 | return transport->getGattServer().updateValue(connectionHandle, attributeHandle, const_cast<uint8_t *>(value), size, localOnly); |
rgrover1 | 342:152bd9c825d6 | 824 | } |
rgrover1 | 342:152bd9c825d6 | 825 | |
rgrover1 | 257:7a50601356cc | 826 | inline void |
rgrover1 | 257:7a50601356cc | 827 | BLEDevice::waitForEvent(void) |
rgrover1 | 257:7a50601356cc | 828 | { |
rgrover1 | 257:7a50601356cc | 829 | transport->waitForEvent(); |
rgrover1 | 257:7a50601356cc | 830 | } |
rgrover1 | 257:7a50601356cc | 831 | |
rgrover1 | 257:7a50601356cc | 832 | inline ble_error_t |
rgrover1 | 257:7a50601356cc | 833 | BLEDevice::getPreferredConnectionParams(Gap::ConnectionParams_t *params) |
rgrover1 | 257:7a50601356cc | 834 | { |
rgrover1 | 257:7a50601356cc | 835 | return transport->getGap().getPreferredConnectionParams(params); |
rgrover1 | 257:7a50601356cc | 836 | } |
rgrover1 | 257:7a50601356cc | 837 | |
rgrover1 | 257:7a50601356cc | 838 | inline ble_error_t |
rgrover1 | 257:7a50601356cc | 839 | BLEDevice::setPreferredConnectionParams(const Gap::ConnectionParams_t *params) |
rgrover1 | 257:7a50601356cc | 840 | { |
rgrover1 | 257:7a50601356cc | 841 | return transport->getGap().setPreferredConnectionParams(params); |
rgrover1 | 257:7a50601356cc | 842 | } |
rgrover1 | 257:7a50601356cc | 843 | |
rgrover1 | 257:7a50601356cc | 844 | inline ble_error_t |
rgrover1 | 257:7a50601356cc | 845 | BLEDevice::updateConnectionParams(Gap::Handle_t handle, const Gap::ConnectionParams_t *params) { |
rgrover1 | 257:7a50601356cc | 846 | return transport->getGap().updateConnectionParams(handle, params); |
rgrover1 | 257:7a50601356cc | 847 | } |
rgrover1 | 257:7a50601356cc | 848 | |
rgrover1 | 257:7a50601356cc | 849 | inline const char * |
rgrover1 | 257:7a50601356cc | 850 | BLEDevice::getVersion(void) |
rgrover1 | 257:7a50601356cc | 851 | { |
rgrover1 | 257:7a50601356cc | 852 | return transport->getVersion(); |
rgrover1 | 257:7a50601356cc | 853 | } |
rgrover1 | 257:7a50601356cc | 854 | |
rgrover1 | 257:7a50601356cc | 855 | inline ble_error_t |
rgrover1 | 257:7a50601356cc | 856 | BLEDevice::setDeviceName(const uint8_t *deviceName) |
rgrover1 | 257:7a50601356cc | 857 | { |
rgrover1 | 257:7a50601356cc | 858 | return transport->getGap().setDeviceName(deviceName); |
rgrover1 | 257:7a50601356cc | 859 | } |
rgrover1 | 257:7a50601356cc | 860 | |
rgrover1 | 257:7a50601356cc | 861 | inline ble_error_t |
rgrover1 | 257:7a50601356cc | 862 | BLEDevice::getDeviceName(uint8_t *deviceName, unsigned *lengthP) |
rgrover1 | 257:7a50601356cc | 863 | { |
rgrover1 | 257:7a50601356cc | 864 | return transport->getGap().getDeviceName(deviceName, lengthP); |
rgrover1 | 257:7a50601356cc | 865 | } |
rgrover1 | 257:7a50601356cc | 866 | |
rgrover1 | 257:7a50601356cc | 867 | inline ble_error_t |
rgrover1 | 257:7a50601356cc | 868 | BLEDevice::setAppearance(uint16_t appearance) |
rgrover1 | 257:7a50601356cc | 869 | { |
rgrover1 | 257:7a50601356cc | 870 | return transport->getGap().setAppearance(appearance); |
rgrover1 | 257:7a50601356cc | 871 | } |
rgrover1 | 257:7a50601356cc | 872 | |
rgrover1 | 257:7a50601356cc | 873 | inline ble_error_t |
rgrover1 | 257:7a50601356cc | 874 | BLEDevice::getAppearance(uint16_t *appearanceP) |
rgrover1 | 257:7a50601356cc | 875 | { |
rgrover1 | 257:7a50601356cc | 876 | return transport->getGap().getAppearance(appearanceP); |
rgrover1 | 257:7a50601356cc | 877 | } |
rgrover1 | 257:7a50601356cc | 878 | |
rgrover1 | 257:7a50601356cc | 879 | inline ble_error_t |
rgrover1 | 257:7a50601356cc | 880 | BLEDevice::setTxPower(int8_t txPower) |
rgrover1 | 257:7a50601356cc | 881 | { |
rgrover1 | 257:7a50601356cc | 882 | return transport->setTxPower(txPower); |
rgrover1 | 257:7a50601356cc | 883 | } |
rgrover1 | 257:7a50601356cc | 884 | |
rgrover1 | 305:71367f7cd078 | 885 | inline void |
rgrover1 | 305:71367f7cd078 | 886 | BLEDevice::getPermittedTxPowerValues(const int8_t **valueArrayPP, size_t *countP) |
rgrover1 | 305:71367f7cd078 | 887 | { |
rgrover1 | 305:71367f7cd078 | 888 | transport->getPermittedTxPowerValues(valueArrayPP, countP); |
rgrover1 | 305:71367f7cd078 | 889 | } |
rgrover1 | 305:71367f7cd078 | 890 | |
rgrover1 | 347:20be4234c6fe | 891 | inline ble_error_t |
rgrover1 | 357:d4bb5d2b837a | 892 | BLEDevice::initializeSecurity(bool enableBonding, |
rgrover1 | 357:d4bb5d2b837a | 893 | bool requireMITM, |
rgrover1 | 357:d4bb5d2b837a | 894 | Gap::SecurityIOCapabilities_t iocaps, |
rgrover1 | 357:d4bb5d2b837a | 895 | const Gap::Passkey_t passkey) |
rgrover1 | 347:20be4234c6fe | 896 | { |
rgrover1 | 357:d4bb5d2b837a | 897 | return transport->initializeSecurity(enableBonding, requireMITM, iocaps, passkey); |
rgrover1 | 347:20be4234c6fe | 898 | } |
rgrover1 | 347:20be4234c6fe | 899 | |
rgrover1 | 369:9a76cc068644 | 900 | inline void |
rgrover1 | 370:678fdba95a62 | 901 | BLEDevice::onSecuritySetupInitiated(Gap::SecuritySetupInitiatedCallback_t callback) |
rgrover1 | 370:678fdba95a62 | 902 | { |
rgrover1 | 370:678fdba95a62 | 903 | transport->getGap().setOnSecuritySetupInitiated(callback); |
rgrover1 | 370:678fdba95a62 | 904 | } |
rgrover1 | 370:678fdba95a62 | 905 | |
rgrover1 | 370:678fdba95a62 | 906 | inline void |
rgrover1 | 370:678fdba95a62 | 907 | BLEDevice::onSecuritySetupCompleted(Gap::SecuritySetupCompletedCallback_t callback) |
rgrover1 | 370:678fdba95a62 | 908 | { |
rgrover1 | 370:678fdba95a62 | 909 | transport->getGap().setOnSecuritySetupCompleted(callback); |
rgrover1 | 370:678fdba95a62 | 910 | } |
rgrover1 | 370:678fdba95a62 | 911 | |
rgrover1 | 370:678fdba95a62 | 912 | inline void |
rgrover1 | 370:678fdba95a62 | 913 | BLEDevice::onLinkSecured(Gap::LinkSecuredCallback_t callback) |
rgrover1 | 370:678fdba95a62 | 914 | { |
rgrover1 | 370:678fdba95a62 | 915 | transport->getGap().setOnLinkSecured(callback); |
rgrover1 | 370:678fdba95a62 | 916 | } |
rgrover1 | 370:678fdba95a62 | 917 | |
rgrover1 | 370:678fdba95a62 | 918 | inline void |
rgrover1 | 370:678fdba95a62 | 919 | BLEDevice::onSecurityContextStored(Gap::HandleSpecificEvent_t callback) |
rgrover1 | 370:678fdba95a62 | 920 | { |
rgrover1 | 370:678fdba95a62 | 921 | transport->getGap().setOnSecurityContextStored(callback); |
rgrover1 | 370:678fdba95a62 | 922 | } |
rgrover1 | 370:678fdba95a62 | 923 | |
rgrover1 | 370:678fdba95a62 | 924 | inline void |
rgrover1 | 369:9a76cc068644 | 925 | BLEDevice::onPasskeyDisplay(Gap::PasskeyDisplayCallback_t callback) |
rgrover1 | 369:9a76cc068644 | 926 | { |
rgrover1 | 369:9a76cc068644 | 927 | return transport->getGap().setOnPasskeyDisplay(callback); |
rgrover1 | 369:9a76cc068644 | 928 | } |
rgrover1 | 369:9a76cc068644 | 929 | |
rgrover1 | 370:678fdba95a62 | 930 | inline ble_error_t |
rgrover1 | 370:678fdba95a62 | 931 | BLEDevice::getLinkSecurity(Gap::Handle_t connectionHandle, Gap::LinkSecurityStatus_t *securityStatusP) |
rgrover1 | 370:678fdba95a62 | 932 | { |
rgrover1 | 370:678fdba95a62 | 933 | return transport->getGap().getLinkSecurity(connectionHandle, securityStatusP); |
rgrover1 | 370:678fdba95a62 | 934 | } |
rgrover1 | 370:678fdba95a62 | 935 | |
rgrover1 | 257:7a50601356cc | 936 | #endif // ifndef __BLE_DEVICE__ |