I don't know why this is happening.
Fork of BLE_API by
services/URIBeaconConfigService.h@278:8a935a2d4a16, 2015-02-13 (annotated)
- Committer:
- rgrover1
- Date:
- Fri Feb 13 13:00:40 2015 +0000
- Revision:
- 278:8a935a2d4a16
- Parent:
- 277:1407d2f1ce3c
- Child:
- 279:00649389c020
Synchronized with git rev bc315805
Author: Bill Schilit
Update config service
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rgrover1 | 171:6092e61690dc | 1 | /* mbed Microcontroller Library |
rgrover1 | 171:6092e61690dc | 2 | * Copyright (c) 2006-2013 ARM Limited |
rgrover1 | 171:6092e61690dc | 3 | * |
rgrover1 | 171:6092e61690dc | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
rgrover1 | 171:6092e61690dc | 5 | * you may not use this file except in compliance with the License. |
rgrover1 | 171:6092e61690dc | 6 | * You may obtain a copy of the License at |
rgrover1 | 171:6092e61690dc | 7 | * |
rgrover1 | 171:6092e61690dc | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
rgrover1 | 171:6092e61690dc | 9 | * |
rgrover1 | 171:6092e61690dc | 10 | * Unless required by applicable law or agreed to in writing, software |
rgrover1 | 171:6092e61690dc | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
rgrover1 | 171:6092e61690dc | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
rgrover1 | 171:6092e61690dc | 13 | * See the License for the specific language governing permissions and |
rgrover1 | 171:6092e61690dc | 14 | * limitations under the License. |
rgrover1 | 171:6092e61690dc | 15 | */ |
rgrover1 | 171:6092e61690dc | 16 | |
rgrover1 | 278:8a935a2d4a16 | 17 | #ifndef SERVICES_URIBEACONCONFIGSERVICE_H_ |
rgrover1 | 278:8a935a2d4a16 | 18 | #define SERVICES_URIBEACONCONFIGSERVICE_H_ |
rgrover1 | 171:6092e61690dc | 19 | |
rgrover1 | 171:6092e61690dc | 20 | #include "BLEDevice.h" |
rgrover1 | 278:8a935a2d4a16 | 21 | #include "GattCharacteristic.h" |
rgrover1 | 278:8a935a2d4a16 | 22 | #include "mbed.h" |
rgrover1 | 171:6092e61690dc | 23 | |
rgrover1 | 278:8a935a2d4a16 | 24 | #define UUID_URI_BEACON(FIRST, SECOND) { \ |
rgrover1 | 225:f6cbfd817d16 | 25 | 0xee, 0x0c, FIRST, SECOND, 0x87, 0x86, 0x40, 0xba, \ |
rgrover1 | 225:f6cbfd817d16 | 26 | 0xab, 0x96, 0x99, 0xb9, 0x1a, 0xc9, 0x81, 0xd8, \ |
rgrover1 | 171:6092e61690dc | 27 | } |
rgrover1 | 278:8a935a2d4a16 | 28 | |
rgrover1 | 278:8a935a2d4a16 | 29 | static const uint8_t UUID_URI_BEACON_SERVICE[] = UUID_URI_BEACON(0x20, 0x80); |
rgrover1 | 278:8a935a2d4a16 | 30 | static const uint8_t UUID_LOCK_STATE_CHAR[] = UUID_URI_BEACON(0x20, 0x81); |
rgrover1 | 278:8a935a2d4a16 | 31 | static const uint8_t UUID_LOCK_CHAR[] = UUID_URI_BEACON(0x20, 0x82); |
rgrover1 | 278:8a935a2d4a16 | 32 | static const uint8_t UUID_UNLOCK_CHAR[] = UUID_URI_BEACON(0x20, 0x83); |
rgrover1 | 278:8a935a2d4a16 | 33 | static const uint8_t UUID_URI_DATA_CHAR[] = UUID_URI_BEACON(0x20, 0x84); |
rgrover1 | 278:8a935a2d4a16 | 34 | static const uint8_t UUID_FLAGS_CHAR[] = UUID_URI_BEACON(0x20, 0x85); |
rgrover1 | 278:8a935a2d4a16 | 35 | static const uint8_t UUID_ADV_POWER_LEVELS_CHAR[] = UUID_URI_BEACON(0x20, 0x86); |
rgrover1 | 278:8a935a2d4a16 | 36 | static const uint8_t UUID_TX_POWER_MODE_CHAR[] = UUID_URI_BEACON(0x20, 0x87); |
rgrover1 | 278:8a935a2d4a16 | 37 | static const uint8_t UUID_BEACON_PERIOD_CHAR[] = UUID_URI_BEACON(0x20, 0x88); |
rgrover1 | 278:8a935a2d4a16 | 38 | static const uint8_t UUID_RESET_CHAR[] = UUID_URI_BEACON(0x20, 0x89); |
rgrover1 | 278:8a935a2d4a16 | 39 | static const uint8_t BEACON_UUID[] = {0xD8, 0xFE}; |
rgrover1 | 171:6092e61690dc | 40 | |
mbedAustin | 231:1c4a4fd961a5 | 41 | /** |
mbedAustin | 231:1c4a4fd961a5 | 42 | * @class URIBeaconConfigService |
rgrover1 | 242:0e9201b67e2f | 43 | * @brief UriBeacon Configuration Service. Can be used to set URL, adjust power levels, and set flags. |
rgrover1 | 278:8a935a2d4a16 | 44 | * See http://uribeacon.org |
rgrover1 | 278:8a935a2d4a16 | 45 | * |
mbedAustin | 231:1c4a4fd961a5 | 46 | */ |
rgrover1 | 207:e88130dc254c | 47 | class URIBeaconConfigService { |
rgrover1 | 278:8a935a2d4a16 | 48 | public: |
mbedAustin | 231:1c4a4fd961a5 | 49 | /** |
rgrover1 | 242:0e9201b67e2f | 50 | * @brief Transmission Power Modes for UriBeacon |
rgrover1 | 242:0e9201b67e2f | 51 | */ |
rgrover1 | 278:8a935a2d4a16 | 52 | static const uint8_t TX_POWER_MODE_LOWEST = 0; /*!< Lowest TX power mode */ |
rgrover1 | 278:8a935a2d4a16 | 53 | static const uint8_t TX_POWER_MODE_LOW = 1; /*!< Low TX power mode */ |
rgrover1 | 278:8a935a2d4a16 | 54 | static const uint8_t TX_POWER_MODE_MEDIUM = 2; /*!< Medium TX power mode */ |
rgrover1 | 278:8a935a2d4a16 | 55 | static const uint8_t TX_POWER_MODE_HIGH = 3; /*!< High TX power mode */ |
rgrover1 | 278:8a935a2d4a16 | 56 | static const int NUM_POWER_MODES = 4; /*!< Number of Power Modes defined */ |
rgrover1 | 278:8a935a2d4a16 | 57 | |
rgrover1 | 278:8a935a2d4a16 | 58 | |
rgrover1 | 278:8a935a2d4a16 | 59 | typedef uint8_t Lock_t[16]; /* 128 bits */ |
rgrover1 | 278:8a935a2d4a16 | 60 | typedef int8_t PowerLevels_t[NUM_POWER_MODES]; |
rgrover1 | 278:8a935a2d4a16 | 61 | |
rgrover1 | 278:8a935a2d4a16 | 62 | static const int URI_DATA_MAX = 18; |
rgrover1 | 278:8a935a2d4a16 | 63 | typedef uint8_t UriData_t[URI_DATA_MAX]; |
rgrover1 | 278:8a935a2d4a16 | 64 | |
rgrover1 | 278:8a935a2d4a16 | 65 | struct Params_t { |
rgrover1 | 278:8a935a2d4a16 | 66 | Lock_t lock; |
rgrover1 | 278:8a935a2d4a16 | 67 | uint8_t uriDataLength; |
rgrover1 | 278:8a935a2d4a16 | 68 | UriData_t uriData; |
rgrover1 | 278:8a935a2d4a16 | 69 | uint8_t flags; |
rgrover1 | 278:8a935a2d4a16 | 70 | // Current value of AdvertisedPowerLevels |
rgrover1 | 278:8a935a2d4a16 | 71 | PowerLevels_t advPowerLevels; |
rgrover1 | 278:8a935a2d4a16 | 72 | // Firmware power levels used with setTxPower() |
rgrover1 | 278:8a935a2d4a16 | 73 | uint8_t txPowerMode; |
rgrover1 | 278:8a935a2d4a16 | 74 | uint16_t beaconPeriod; |
rgrover1 | 175:4e85f7225f8f | 75 | }; |
rgrover1 | 175:4e85f7225f8f | 76 | |
rgrover1 | 269:d818d11dca4e | 77 | |
rgrover1 | 181:bbb6ce1082c3 | 78 | /** |
rgrover1 | 181:bbb6ce1082c3 | 79 | * @param[ref] ble |
rgrover1 | 181:bbb6ce1082c3 | 80 | * BLEDevice object for the underlying controller. |
rgrover1 | 208:88a3a58769bf | 81 | * @param[in] uridata |
rgrover1 | 181:bbb6ce1082c3 | 82 | * URI as a null-terminated string. |
rgrover1 | 181:bbb6ce1082c3 | 83 | * @param[in] flagsIn |
rgrover1 | 181:bbb6ce1082c3 | 84 | * UriBeacon Flags. |
rgrover1 | 218:8ae02569fab9 | 85 | * @param[in] powerLevels[] |
rgrover1 | 218:8ae02569fab9 | 86 | * Table of UriBeacon Tx Power Levels in dBm. |
rgrover1 | 218:8ae02569fab9 | 87 | * @param[in] powerMode |
rgrover1 | 218:8ae02569fab9 | 88 | * Currently effective power mode. |
rgrover1 | 181:bbb6ce1082c3 | 89 | * @param[in] beaconPeriodIn |
rgrover1 | 181:bbb6ce1082c3 | 90 | * The period in milliseconds that a UriBeacon packet is |
rgrover1 | 181:bbb6ce1082c3 | 91 | * transmitted. A value of zero disables UriBeacon |
rgrover1 | 181:bbb6ce1082c3 | 92 | * transmissions. |
rgrover1 | 181:bbb6ce1082c3 | 93 | */ |
rgrover1 | 218:8ae02569fab9 | 94 | URIBeaconConfigService(BLEDevice &bleIn, |
rgrover1 | 278:8a935a2d4a16 | 95 | Params_t ¶msIn, |
rgrover1 | 278:8a935a2d4a16 | 96 | bool resetToDefaultsFlag, |
rgrover1 | 278:8a935a2d4a16 | 97 | UriData_t &defaultUriDataIn, |
rgrover1 | 278:8a935a2d4a16 | 98 | int defaultUriDataLengthIn, |
rgrover1 | 278:8a935a2d4a16 | 99 | PowerLevels_t &defaultAdvPowerLevelsIn) : |
rgrover1 | 192:3fd3dcf49005 | 100 | ble(bleIn), |
rgrover1 | 278:8a935a2d4a16 | 101 | params(paramsIn), |
rgrover1 | 278:8a935a2d4a16 | 102 | defaultUriDataLength(defaultUriDataLengthIn), |
rgrover1 | 278:8a935a2d4a16 | 103 | defaultUriData(defaultUriDataIn), |
rgrover1 | 278:8a935a2d4a16 | 104 | defaultAdvPowerLevels(defaultAdvPowerLevelsIn), |
rgrover1 | 192:3fd3dcf49005 | 105 | initSucceeded(false), |
rgrover1 | 278:8a935a2d4a16 | 106 | lockedStateChar(UUID_LOCK_STATE_CHAR, &lockedState), |
rgrover1 | 278:8a935a2d4a16 | 107 | lockChar(UUID_LOCK_CHAR, ¶ms.lock), |
rgrover1 | 278:8a935a2d4a16 | 108 | uriDataChar(UUID_URI_DATA_CHAR, params.uriData, URI_DATA_MAX, params.uriDataLength, |
rgrover1 | 278:8a935a2d4a16 | 109 | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE), |
rgrover1 | 278:8a935a2d4a16 | 110 | unlockChar(UUID_UNLOCK_CHAR, ¶ms.lock), |
rgrover1 | 278:8a935a2d4a16 | 111 | flagsChar(UUID_FLAGS_CHAR, ¶ms.flags), |
rgrover1 | 278:8a935a2d4a16 | 112 | advPowerLevelsChar(UUID_ADV_POWER_LEVELS_CHAR, ¶ms.advPowerLevels), |
rgrover1 | 278:8a935a2d4a16 | 113 | txPowerModeChar(UUID_TX_POWER_MODE_CHAR, ¶ms.txPowerMode), |
rgrover1 | 278:8a935a2d4a16 | 114 | beaconPeriodChar(UUID_BEACON_PERIOD_CHAR, ¶ms.beaconPeriod), |
rgrover1 | 278:8a935a2d4a16 | 115 | resetChar(UUID_RESET_CHAR, &resetFlag) { |
rgrover1 | 278:8a935a2d4a16 | 116 | if (defaultUriDataLengthIn > URI_DATA_MAX) { |
rgrover1 | 192:3fd3dcf49005 | 117 | return; |
rgrover1 | 192:3fd3dcf49005 | 118 | } |
rgrover1 | 192:3fd3dcf49005 | 119 | |
rgrover1 | 278:8a935a2d4a16 | 120 | if (params.uriDataLength > URI_DATA_MAX) { |
rgrover1 | 278:8a935a2d4a16 | 121 | resetToDefaultsFlag = true; |
rgrover1 | 218:8ae02569fab9 | 122 | } |
rgrover1 | 218:8ae02569fab9 | 123 | |
rgrover1 | 278:8a935a2d4a16 | 124 | lockedState = isLocked(); |
rgrover1 | 171:6092e61690dc | 125 | |
rgrover1 | 278:8a935a2d4a16 | 126 | if (resetToDefaultsFlag) { |
rgrover1 | 278:8a935a2d4a16 | 127 | resetToDefaults(); |
rgrover1 | 278:8a935a2d4a16 | 128 | } else { |
rgrover1 | 278:8a935a2d4a16 | 129 | updateCharacteristicValues(); |
rgrover1 | 278:8a935a2d4a16 | 130 | } |
rgrover1 | 274:f540619754bb | 131 | |
rgrover1 | 272:65b9d9c87ed1 | 132 | lockChar.setWriteAuthorizationCallback(this, &URIBeaconConfigService::lockAuthorizationCallback); |
rgrover1 | 272:65b9d9c87ed1 | 133 | unlockChar.setWriteAuthorizationCallback(this, &URIBeaconConfigService::unlockAuthorizationCallback); |
rgrover1 | 250:6862d374e613 | 134 | uriDataChar.setWriteAuthorizationCallback(this, &URIBeaconConfigService::uriDataWriteAuthorizationCallback); |
rgrover1 | 255:cdb7231f83df | 135 | flagsChar.setWriteAuthorizationCallback(this, &URIBeaconConfigService::flagsAuthorizationCallback); |
rgrover1 | 278:8a935a2d4a16 | 136 | advPowerLevelsChar.setWriteAuthorizationCallback(this, &URIBeaconConfigService::denyGATTWritesIfLocked); |
rgrover1 | 278:8a935a2d4a16 | 137 | txPowerModeChar.setWriteAuthorizationCallback(this, &URIBeaconConfigService::denyGATTWritesIfLocked); |
rgrover1 | 250:6862d374e613 | 138 | beaconPeriodChar.setWriteAuthorizationCallback(this, &URIBeaconConfigService::denyGATTWritesIfLocked); |
rgrover1 | 250:6862d374e613 | 139 | resetChar.setWriteAuthorizationCallback(this, &URIBeaconConfigService::denyGATTWritesIfLocked); |
rgrover1 | 250:6862d374e613 | 140 | |
rgrover1 | 278:8a935a2d4a16 | 141 | static GattCharacteristic *charTable[] = { |
rgrover1 | 278:8a935a2d4a16 | 142 | &lockedStateChar, &lockChar, &unlockChar, &uriDataChar, |
rgrover1 | 278:8a935a2d4a16 | 143 | &flagsChar, &advPowerLevelsChar, &txPowerModeChar, &beaconPeriodChar, &resetChar |
rgrover1 | 278:8a935a2d4a16 | 144 | }; |
rgrover1 | 182:d16f8c11816b | 145 | |
rgrover1 | 278:8a935a2d4a16 | 146 | GattService configService(UUID_URI_BEACON_SERVICE, charTable, sizeof(charTable) / sizeof(GattCharacteristic *)); |
rgrover1 | 278:8a935a2d4a16 | 147 | |
rgrover1 | 278:8a935a2d4a16 | 148 | ble.addService(configService); |
rgrover1 | 278:8a935a2d4a16 | 149 | ble.onDataWritten(this, &URIBeaconConfigService::onDataWrittenCallback); |
rgrover1 | 278:8a935a2d4a16 | 150 | |
rgrover1 | 278:8a935a2d4a16 | 151 | initSucceeded = true; |
rgrover1 | 192:3fd3dcf49005 | 152 | } |
rgrover1 | 192:3fd3dcf49005 | 153 | |
rgrover1 | 193:ac2feceb7e87 | 154 | bool configuredSuccessfully(void) const { |
rgrover1 | 192:3fd3dcf49005 | 155 | return initSucceeded; |
rgrover1 | 171:6092e61690dc | 156 | } |
rgrover1 | 171:6092e61690dc | 157 | |
rgrover1 | 171:6092e61690dc | 158 | |
rgrover1 | 278:8a935a2d4a16 | 159 | private: |
rgrover1 | 278:8a935a2d4a16 | 160 | bool isLocked() { |
rgrover1 | 278:8a935a2d4a16 | 161 | Lock_t testLock; |
rgrover1 | 278:8a935a2d4a16 | 162 | memset(testLock, 0, sizeof(Lock_t)); |
rgrover1 | 278:8a935a2d4a16 | 163 | return memcmp(params.lock, testLock, sizeof(Lock_t)); |
rgrover1 | 171:6092e61690dc | 164 | } |
rgrover1 | 171:6092e61690dc | 165 | |
mbedAustin | 232:4cfb5b8a4fb9 | 166 | /* |
rgrover1 | 242:0e9201b67e2f | 167 | * This callback is invoked when a GATT client attempts to modify any of the |
rgrover1 | 250:6862d374e613 | 168 | * characteristics of this service. Attempts to do so are also applied to |
rgrover1 | 250:6862d374e613 | 169 | * the internal state of this service object. |
rgrover1 | 242:0e9201b67e2f | 170 | */ |
rgrover1 | 278:8a935a2d4a16 | 171 | void onDataWrittenCallback(const GattCharacteristicWriteCBParams *writeParams) { |
rgrover1 | 278:8a935a2d4a16 | 172 | uint16_t handle = writeParams->charHandle; |
rgrover1 | 278:8a935a2d4a16 | 173 | |
rgrover1 | 268:bc525cdc88f7 | 174 | if (handle == lockChar.getValueHandle()) { |
rgrover1 | 278:8a935a2d4a16 | 175 | // Validated earlier |
rgrover1 | 278:8a935a2d4a16 | 176 | memcpy(params.lock, writeParams->data, sizeof(Lock_t)); |
rgrover1 | 278:8a935a2d4a16 | 177 | lockedState = true; |
rgrover1 | 268:bc525cdc88f7 | 178 | } else if (handle == unlockChar.getValueHandle()) { |
rgrover1 | 278:8a935a2d4a16 | 179 | // Validated earlier |
rgrover1 | 278:8a935a2d4a16 | 180 | memset(params.lock, 0, sizeof(Lock_t)); |
rgrover1 | 268:bc525cdc88f7 | 181 | lockedState = false; |
rgrover1 | 268:bc525cdc88f7 | 182 | } else if (handle == uriDataChar.getValueHandle()) { |
rgrover1 | 278:8a935a2d4a16 | 183 | params.uriDataLength = writeParams->len; |
rgrover1 | 278:8a935a2d4a16 | 184 | memcpy(params.uriData, writeParams->data, params.uriDataLength); |
rgrover1 | 229:6664b6c0e92b | 185 | } else if (handle == flagsChar.getValueHandle()) { |
rgrover1 | 278:8a935a2d4a16 | 186 | params.flags = *(writeParams->data); |
rgrover1 | 278:8a935a2d4a16 | 187 | } else if (handle == advPowerLevelsChar.getValueHandle()) { |
rgrover1 | 278:8a935a2d4a16 | 188 | memcpy(params.advPowerLevels, writeParams->data, sizeof(PowerLevels_t)); |
rgrover1 | 229:6664b6c0e92b | 189 | } else if (handle == txPowerModeChar.getValueHandle()) { |
rgrover1 | 278:8a935a2d4a16 | 190 | params.txPowerMode = *(writeParams->data); |
rgrover1 | 229:6664b6c0e92b | 191 | } else if (handle == beaconPeriodChar.getValueHandle()) { |
rgrover1 | 278:8a935a2d4a16 | 192 | params.beaconPeriod = *((uint16_t *)(writeParams->data)); |
rgrover1 | 229:6664b6c0e92b | 193 | } else if (handle == resetChar.getValueHandle()) { |
rgrover1 | 278:8a935a2d4a16 | 194 | resetToDefaults(); |
rgrover1 | 185:7cd70497aec8 | 195 | } |
rgrover1 | 185:7cd70497aec8 | 196 | } |
rgrover1 | 185:7cd70497aec8 | 197 | |
mbedAustin | 232:4cfb5b8a4fb9 | 198 | /* |
rgrover1 | 251:6ce809c972bb | 199 | * Reset the default values. |
rgrover1 | 242:0e9201b67e2f | 200 | */ |
rgrover1 | 278:8a935a2d4a16 | 201 | void resetToDefaults(void) { |
rgrover1 | 278:8a935a2d4a16 | 202 | lockedState = false; |
rgrover1 | 278:8a935a2d4a16 | 203 | memset(params.lock, 0, sizeof(Lock_t)); |
rgrover1 | 278:8a935a2d4a16 | 204 | memcpy(params.uriData, defaultUriData, URI_DATA_MAX); |
rgrover1 | 278:8a935a2d4a16 | 205 | params.uriDataLength = defaultUriDataLength; |
rgrover1 | 278:8a935a2d4a16 | 206 | params.flags = 0; |
rgrover1 | 278:8a935a2d4a16 | 207 | memcpy(params.advPowerLevels, defaultAdvPowerLevels, sizeof(PowerLevels_t)); |
rgrover1 | 278:8a935a2d4a16 | 208 | params.txPowerMode = TX_POWER_MODE_LOW; |
rgrover1 | 278:8a935a2d4a16 | 209 | params.beaconPeriod = 1000; |
rgrover1 | 278:8a935a2d4a16 | 210 | updateCharacteristicValues(); |
rgrover1 | 211:f181effe5de3 | 211 | } |
rgrover1 | 211:f181effe5de3 | 212 | |
mbedAustin | 232:4cfb5b8a4fb9 | 213 | /* |
rgrover1 | 242:0e9201b67e2f | 214 | * Internal helper function used to update the GATT database following any |
rgrover1 | 242:0e9201b67e2f | 215 | * change to the internal state of the service object. |
rgrover1 | 242:0e9201b67e2f | 216 | */ |
rgrover1 | 278:8a935a2d4a16 | 217 | void updateCharacteristicValues(void) { |
rgrover1 | 278:8a935a2d4a16 | 218 | ble.updateCharacteristicValue(lockedStateChar.getValueHandle(), &lockedState, 1); |
rgrover1 | 278:8a935a2d4a16 | 219 | ble.updateCharacteristicValue(uriDataChar.getValueHandle(), params.uriData, params.uriDataLength); |
rgrover1 | 278:8a935a2d4a16 | 220 | ble.updateCharacteristicValue(flagsChar.getValueHandle(), ¶ms.flags, 1); |
rgrover1 | 278:8a935a2d4a16 | 221 | ble.updateCharacteristicValue(beaconPeriodChar.getValueHandle(), |
rgrover1 | 278:8a935a2d4a16 | 222 | reinterpret_cast<uint8_t *>(¶ms.beaconPeriod), sizeof(uint16_t)); |
rgrover1 | 278:8a935a2d4a16 | 223 | ble.updateCharacteristicValue(txPowerModeChar.getValueHandle(), ¶ms.txPowerMode, 1); |
rgrover1 | 278:8a935a2d4a16 | 224 | ble.updateCharacteristicValue(advPowerLevelsChar.getValueHandle(), |
rgrover1 | 278:8a935a2d4a16 | 225 | reinterpret_cast<uint8_t *>(params.advPowerLevels), sizeof(PowerLevels_t)); |
rgrover1 | 189:a23091b54ab5 | 226 | } |
rgrover1 | 189:a23091b54ab5 | 227 | |
rgrover1 | 278:8a935a2d4a16 | 228 | private: |
rgrover1 | 278:8a935a2d4a16 | 229 | void lockAuthorizationCallback(GattCharacteristicWriteAuthCBParams *authParams) { |
rgrover1 | 278:8a935a2d4a16 | 230 | authParams->authorizationReply = (authParams->len == sizeof(Lock_t)) && !lockedState; |
rgrover1 | 218:8ae02569fab9 | 231 | } |
rgrover1 | 218:8ae02569fab9 | 232 | |
rgrover1 | 268:bc525cdc88f7 | 233 | |
rgrover1 | 278:8a935a2d4a16 | 234 | void unlockAuthorizationCallback(GattCharacteristicWriteAuthCBParams *authParams) { |
rgrover1 | 278:8a935a2d4a16 | 235 | if (!lockedState || (authParams->len == sizeof(Lock_t) && (memcmp(authParams->data, params.lock, sizeof(Lock_t)) == 0))) { |
rgrover1 | 278:8a935a2d4a16 | 236 | authParams->authorizationReply = true; |
rgrover1 | 268:bc525cdc88f7 | 237 | } else { |
rgrover1 | 278:8a935a2d4a16 | 238 | authParams->authorizationReply = false; |
rgrover1 | 268:bc525cdc88f7 | 239 | } |
rgrover1 | 268:bc525cdc88f7 | 240 | } |
rgrover1 | 268:bc525cdc88f7 | 241 | |
rgrover1 | 278:8a935a2d4a16 | 242 | void uriDataWriteAuthorizationCallback(GattCharacteristicWriteAuthCBParams *authParams) { |
rgrover1 | 278:8a935a2d4a16 | 243 | if (lockedState || (authParams->offset != 0) || (authParams->len > URI_DATA_MAX)) { |
rgrover1 | 278:8a935a2d4a16 | 244 | authParams->authorizationReply = false; |
rgrover1 | 250:6862d374e613 | 245 | } |
rgrover1 | 250:6862d374e613 | 246 | } |
rgrover1 | 250:6862d374e613 | 247 | |
rgrover1 | 278:8a935a2d4a16 | 248 | void flagsAuthorizationCallback(GattCharacteristicWriteAuthCBParams *authParams) { |
rgrover1 | 278:8a935a2d4a16 | 249 | if (lockedState || authParams->len != 1) { |
rgrover1 | 278:8a935a2d4a16 | 250 | authParams->authorizationReply = false; |
rgrover1 | 250:6862d374e613 | 251 | } |
rgrover1 | 250:6862d374e613 | 252 | } |
rgrover1 | 250:6862d374e613 | 253 | |
rgrover1 | 278:8a935a2d4a16 | 254 | void denyGATTWritesIfLocked(GattCharacteristicWriteAuthCBParams *authParams) { |
rgrover1 | 250:6862d374e613 | 255 | if (lockedState) { |
rgrover1 | 278:8a935a2d4a16 | 256 | authParams->authorizationReply = false; |
rgrover1 | 250:6862d374e613 | 257 | } |
rgrover1 | 250:6862d374e613 | 258 | } |
rgrover1 | 250:6862d374e613 | 259 | |
rgrover1 | 206:49646c933822 | 260 | BLEDevice &ble; |
rgrover1 | 278:8a935a2d4a16 | 261 | Params_t ¶ms; |
rgrover1 | 278:8a935a2d4a16 | 262 | // Default value that is restored on reset |
rgrover1 | 278:8a935a2d4a16 | 263 | uint16_t defaultUriDataLength; |
rgrover1 | 278:8a935a2d4a16 | 264 | UriData_t &defaultUriData; |
rgrover1 | 278:8a935a2d4a16 | 265 | // Default value that is restored on reset |
rgrover1 | 278:8a935a2d4a16 | 266 | PowerLevels_t &defaultAdvPowerLevels; |
rgrover1 | 278:8a935a2d4a16 | 267 | uint8_t lockedState; |
rgrover1 | 278:8a935a2d4a16 | 268 | bool initSucceeded; |
rgrover1 | 278:8a935a2d4a16 | 269 | uint8_t resetFlag; |
rgrover1 | 171:6092e61690dc | 270 | |
rgrover1 | 182:d16f8c11816b | 271 | |
rgrover1 | 278:8a935a2d4a16 | 272 | ReadOnlyGattCharacteristic<uint8_t> lockedStateChar; |
rgrover1 | 278:8a935a2d4a16 | 273 | WriteOnlyGattCharacteristic<Lock_t> lockChar; |
rgrover1 | 278:8a935a2d4a16 | 274 | GattCharacteristic uriDataChar; |
rgrover1 | 278:8a935a2d4a16 | 275 | WriteOnlyGattCharacteristic<Lock_t> unlockChar; |
rgrover1 | 278:8a935a2d4a16 | 276 | ReadWriteGattCharacteristic<uint8_t> flagsChar; |
rgrover1 | 278:8a935a2d4a16 | 277 | ReadWriteGattCharacteristic<PowerLevels_t> advPowerLevelsChar; |
rgrover1 | 278:8a935a2d4a16 | 278 | ReadWriteGattCharacteristic<uint8_t> txPowerModeChar; |
rgrover1 | 278:8a935a2d4a16 | 279 | ReadWriteGattCharacteristic<uint16_t> beaconPeriodChar; |
rgrover1 | 278:8a935a2d4a16 | 280 | WriteOnlyGattCharacteristic<uint8_t> resetChar; |
rgrover1 | 171:6092e61690dc | 281 | }; |
rgrover1 | 171:6092e61690dc | 282 | |
rgrover1 | 278:8a935a2d4a16 | 283 | #endif // SERVICES_URIBEACONCONFIGSERVICE_H_ |