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