Sarah Marsh / Mbed OS EddystoneBeacon
Committer:
sarahmarshy
Date:
Tue Nov 29 06:29:10 2016 +0000
Revision:
0:1c7da5f83647
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sarahmarshy 0:1c7da5f83647 1 /*
sarahmarshy 0:1c7da5f83647 2 * Copyright (c) 2006-2016 Google Inc, All Rights Reserved
sarahmarshy 0:1c7da5f83647 3 *
sarahmarshy 0:1c7da5f83647 4 * Licensed under the Apache License, Version 2.0 (the "License");
sarahmarshy 0:1c7da5f83647 5 * you may not use this file except in compliance with the License.
sarahmarshy 0:1c7da5f83647 6 * You may obtain a copy of the License at
sarahmarshy 0:1c7da5f83647 7 *
sarahmarshy 0:1c7da5f83647 8 * http://www.apache.org/licenses/LICENSE-2.0
sarahmarshy 0:1c7da5f83647 9 *
sarahmarshy 0:1c7da5f83647 10 * Unless required by applicable law or agreed to in writing, software
sarahmarshy 0:1c7da5f83647 11 * distributed under the License is distributed on an "AS IS" BASIS,
sarahmarshy 0:1c7da5f83647 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
sarahmarshy 0:1c7da5f83647 13 * See the License for the specific language governing permissions and
sarahmarshy 0:1c7da5f83647 14 * limitations under the License.
sarahmarshy 0:1c7da5f83647 15 */
sarahmarshy 0:1c7da5f83647 16
sarahmarshy 0:1c7da5f83647 17 #ifndef __EDDYSTONESERVICE_H__
sarahmarshy 0:1c7da5f83647 18 #define __EDDYSTONESERVICE_H__
sarahmarshy 0:1c7da5f83647 19 //
sarahmarshy 0:1c7da5f83647 20 // 2016-03 Eddystone Unified GATT
sarahmarshy 0:1c7da5f83647 21 //
sarahmarshy 0:1c7da5f83647 22 #include "EventQueue/EventQueue.h"
sarahmarshy 0:1c7da5f83647 23 #include "ble/BLE.h"
sarahmarshy 0:1c7da5f83647 24 #include "EddystoneTypes.h"
sarahmarshy 0:1c7da5f83647 25 #include "UIDFrame.h"
sarahmarshy 0:1c7da5f83647 26 #include "URLFrame.h"
sarahmarshy 0:1c7da5f83647 27 #include "TLMFrame.h"
sarahmarshy 0:1c7da5f83647 28 #include "EIDFrame.h"
sarahmarshy 0:1c7da5f83647 29 #include <string.h>
sarahmarshy 0:1c7da5f83647 30 #include "mbedtls/aes.h"
sarahmarshy 0:1c7da5f83647 31 #include "mbedtls/entropy.h"
sarahmarshy 0:1c7da5f83647 32 #include "mbedtls/ctr_drbg.h"
sarahmarshy 0:1c7da5f83647 33 // #include "PersistentStorageHelper/ConfigParamsPersistence.h"
sarahmarshy 0:1c7da5f83647 34
sarahmarshy 0:1c7da5f83647 35 #ifdef YOTTA_CFG_MBED_OS
sarahmarshy 0:1c7da5f83647 36 #include "mbed-drivers/mbed.h"
sarahmarshy 0:1c7da5f83647 37 #include "mbed-drivers/CircularBuffer.h"
sarahmarshy 0:1c7da5f83647 38 #else
sarahmarshy 0:1c7da5f83647 39 #include "mbed.h"
sarahmarshy 0:1c7da5f83647 40 #include "CircularBuffer.h"
sarahmarshy 0:1c7da5f83647 41 #endif
sarahmarshy 0:1c7da5f83647 42
sarahmarshy 0:1c7da5f83647 43 #include "stdio.h"
sarahmarshy 0:1c7da5f83647 44 #include "Eddystone_config.h"
sarahmarshy 0:1c7da5f83647 45 #include "pstorage_platform.h"
sarahmarshy 0:1c7da5f83647 46
sarahmarshy 0:1c7da5f83647 47 /**
sarahmarshy 0:1c7da5f83647 48 * This class implements the Eddystone-URL Config Service and the Eddystone
sarahmarshy 0:1c7da5f83647 49 * Protocol Specification as defined in the publicly available specification at
sarahmarshy 0:1c7da5f83647 50 * https://github.com/google/eddystone/blob/master/protocol-specification.md.
sarahmarshy 0:1c7da5f83647 51 */
sarahmarshy 0:1c7da5f83647 52 class EddystoneService
sarahmarshy 0:1c7da5f83647 53 {
sarahmarshy 0:1c7da5f83647 54 public:
sarahmarshy 0:1c7da5f83647 55 /**
sarahmarshy 0:1c7da5f83647 56 * Total number of GATT Characteristics in the Eddystonei-URL Configuration
sarahmarshy 0:1c7da5f83647 57 * Service.
sarahmarshy 0:1c7da5f83647 58 */
sarahmarshy 0:1c7da5f83647 59 static const uint16_t TOTAL_CHARACTERISTICS = 12;
sarahmarshy 0:1c7da5f83647 60
sarahmarshy 0:1c7da5f83647 61 /**
sarahmarshy 0:1c7da5f83647 62 * Max data that can be written to the data characteristic
sarahmarshy 0:1c7da5f83647 63 */
sarahmarshy 0:1c7da5f83647 64 static const uint8_t MAX_DATA_WRITE = 34; // FrameType+32B(IdentityKey)+Exp
sarahmarshy 0:1c7da5f83647 65
sarahmarshy 0:1c7da5f83647 66 /**
sarahmarshy 0:1c7da5f83647 67 * Default interval for advertising packets for the Eddystone-URL
sarahmarshy 0:1c7da5f83647 68 * Configuration Service.
sarahmarshy 0:1c7da5f83647 69 */
sarahmarshy 0:1c7da5f83647 70 static const uint32_t DEFAULT_CONFIG_PERIOD_MSEC = EDDYSTONE_DEFAULT_CONFIG_ADV_INTERVAL;
sarahmarshy 0:1c7da5f83647 71
sarahmarshy 0:1c7da5f83647 72 /**
sarahmarshy 0:1c7da5f83647 73 * Enumeration that defines the various operation modes of the
sarahmarshy 0:1c7da5f83647 74 * EddystoneService.
sarahmarshy 0:1c7da5f83647 75 *
sarahmarshy 0:1c7da5f83647 76 * @note The main app can change the mode of EddystoneService at any point
sarahmarshy 0:1c7da5f83647 77 * of time by calling startConfigService() or startBeaconService().
sarahmarshy 0:1c7da5f83647 78 * Resources from the previous mode will be freed.
sarahmarshy 0:1c7da5f83647 79 *
sarahmarshy 0:1c7da5f83647 80 * @note It is currently NOT possible to force EddystoneService back into
sarahmarshy 0:1c7da5f83647 81 * EDDYSTONE_MODE_NONE.
sarahmarshy 0:1c7da5f83647 82 */
sarahmarshy 0:1c7da5f83647 83 enum OperationModes {
sarahmarshy 0:1c7da5f83647 84 /**
sarahmarshy 0:1c7da5f83647 85 * NONE: EddystoneService has been initialized but no memory has been
sarahmarshy 0:1c7da5f83647 86 * dynamically allocated. Additionally, no services are running
sarahmarshy 0:1c7da5f83647 87 * nothing is being advertised.
sarahmarshy 0:1c7da5f83647 88 */
sarahmarshy 0:1c7da5f83647 89 EDDYSTONE_MODE_NONE,
sarahmarshy 0:1c7da5f83647 90 /**
sarahmarshy 0:1c7da5f83647 91 * CONFIG: EddystoneService has been initialized, the configuration
sarahmarshy 0:1c7da5f83647 92 * service started and memory has been allocated for BLE
sarahmarshy 0:1c7da5f83647 93 * characteristics. Memory consumption peaks during CONFIG
sarahmarshy 0:1c7da5f83647 94 * mode.
sarahmarshy 0:1c7da5f83647 95 */
sarahmarshy 0:1c7da5f83647 96 EDDYSTONE_MODE_CONFIG,
sarahmarshy 0:1c7da5f83647 97 /**
sarahmarshy 0:1c7da5f83647 98 * BEACON: Eddystone service is running as a beacon advertising URL,
sarahmarshy 0:1c7da5f83647 99 * UID and/or TLM frames depending on how it is configured.
sarahmarshy 0:1c7da5f83647 100 */
sarahmarshy 0:1c7da5f83647 101 EDDYSTONE_MODE_BEACON
sarahmarshy 0:1c7da5f83647 102 };
sarahmarshy 0:1c7da5f83647 103
sarahmarshy 0:1c7da5f83647 104 /**
sarahmarshy 0:1c7da5f83647 105 * Structure that encapsulates the Eddystone configuration parameters. This
sarahmarshy 0:1c7da5f83647 106 * structure is particularly useful when storing the parameters to
sarahmarshy 0:1c7da5f83647 107 * persistent storage.
sarahmarshy 0:1c7da5f83647 108 */
sarahmarshy 0:1c7da5f83647 109 struct EddystoneParams_t {
sarahmarshy 0:1c7da5f83647 110 /**
sarahmarshy 0:1c7da5f83647 111 *
sarahmarshy 0:1c7da5f83647 112 */
sarahmarshy 0:1c7da5f83647 113 TimeParams_t timeParams;
sarahmarshy 0:1c7da5f83647 114 /**
sarahmarshy 0:1c7da5f83647 115 * A buffer describing the capabilities of the beacon
sarahmarshy 0:1c7da5f83647 116 */
sarahmarshy 0:1c7da5f83647 117 Capability_t capabilities;
sarahmarshy 0:1c7da5f83647 118
sarahmarshy 0:1c7da5f83647 119 /**
sarahmarshy 0:1c7da5f83647 120 * Defines the slot that advInterval, radioPower, advPower, advSlotData operate on
sarahmarshy 0:1c7da5f83647 121 */
sarahmarshy 0:1c7da5f83647 122 uint8_t activeSlot;
sarahmarshy 0:1c7da5f83647 123
sarahmarshy 0:1c7da5f83647 124 /**
sarahmarshy 0:1c7da5f83647 125 * The Beacon interval for each beacon slot
sarahmarshy 0:1c7da5f83647 126 *
sarahmarshy 0:1c7da5f83647 127 * @note A value of zero disables Eddystone-URL frame trasmissions.
sarahmarshy 0:1c7da5f83647 128 */
sarahmarshy 0:1c7da5f83647 129 SlotAdvIntervals_t slotAdvIntervals;
sarahmarshy 0:1c7da5f83647 130
sarahmarshy 0:1c7da5f83647 131 /**
sarahmarshy 0:1c7da5f83647 132 * The Radio TX Powers supported by this beacon
sarahmarshy 0:1c7da5f83647 133 */
sarahmarshy 0:1c7da5f83647 134 PowerLevels_t radioTxPowerLevels;
sarahmarshy 0:1c7da5f83647 135
sarahmarshy 0:1c7da5f83647 136 /**
sarahmarshy 0:1c7da5f83647 137 * The Radio TX Power set for each slot
sarahmarshy 0:1c7da5f83647 138 */
sarahmarshy 0:1c7da5f83647 139 SlotTxPowerLevels_t slotRadioTxPowerLevels;
sarahmarshy 0:1c7da5f83647 140
sarahmarshy 0:1c7da5f83647 141 /**
sarahmarshy 0:1c7da5f83647 142 * The Calibrated Adv TX Powers supported by this beacon (one for each radio power)
sarahmarshy 0:1c7da5f83647 143 */
sarahmarshy 0:1c7da5f83647 144 PowerLevels_t advTxPowerLevels;
sarahmarshy 0:1c7da5f83647 145
sarahmarshy 0:1c7da5f83647 146 /**
sarahmarshy 0:1c7da5f83647 147 * The Adv TX Power set for each slot
sarahmarshy 0:1c7da5f83647 148 */
sarahmarshy 0:1c7da5f83647 149 SlotTxPowerLevels_t slotAdvTxPowerLevels;
sarahmarshy 0:1c7da5f83647 150
sarahmarshy 0:1c7da5f83647 151 /**
sarahmarshy 0:1c7da5f83647 152 * The value of the Eddystone-URL Configuration Service Lock State
sarahmarshy 0:1c7da5f83647 153 * characteristic.
sarahmarshy 0:1c7da5f83647 154 */
sarahmarshy 0:1c7da5f83647 155 uint8_t lockState;
sarahmarshy 0:1c7da5f83647 156
sarahmarshy 0:1c7da5f83647 157 /**
sarahmarshy 0:1c7da5f83647 158 * The value of the Eddystone-URL Configuration Service Unlock
sarahmarshy 0:1c7da5f83647 159 * characteristic that can be used to unlock the beacon and clear the
sarahmarshy 0:1c7da5f83647 160 * single-use lock-code.
sarahmarshy 0:1c7da5f83647 161 */
sarahmarshy 0:1c7da5f83647 162 Lock_t unlockToken;
sarahmarshy 0:1c7da5f83647 163
sarahmarshy 0:1c7da5f83647 164 /**
sarahmarshy 0:1c7da5f83647 165 * An array holding the 128-bit unlockKey (big endian)
sarahmarshy 0:1c7da5f83647 166 */
sarahmarshy 0:1c7da5f83647 167 Lock_t unlockKey;
sarahmarshy 0:1c7da5f83647 168
sarahmarshy 0:1c7da5f83647 169 /**
sarahmarshy 0:1c7da5f83647 170 * An array holding the 128-bit challenge (big endian) in the
sarahmarshy 0:1c7da5f83647 171 * challenge/response unlock protocol
sarahmarshy 0:1c7da5f83647 172 */
sarahmarshy 0:1c7da5f83647 173 Lock_t challenge;
sarahmarshy 0:1c7da5f83647 174
sarahmarshy 0:1c7da5f83647 175 /**
sarahmarshy 0:1c7da5f83647 176 * EID: An array holding the slot rotation period exponents
sarahmarshy 0:1c7da5f83647 177 */
sarahmarshy 0:1c7da5f83647 178 SlotEidRotationPeriodExps_t slotEidRotationPeriodExps;
sarahmarshy 0:1c7da5f83647 179
sarahmarshy 0:1c7da5f83647 180 /**
sarahmarshy 0:1c7da5f83647 181 * EID: An array holding the slot 128-bit EID Identity Key (big endian)
sarahmarshy 0:1c7da5f83647 182 */
sarahmarshy 0:1c7da5f83647 183 SlotEidIdentityKeys_t slotEidIdentityKeys;
sarahmarshy 0:1c7da5f83647 184
sarahmarshy 0:1c7da5f83647 185 /**
sarahmarshy 0:1c7da5f83647 186 * Specifies the type of each frame indexed by slot
sarahmarshy 0:1c7da5f83647 187 */
sarahmarshy 0:1c7da5f83647 188 SlotFrameTypes_t slotFrameTypes;
sarahmarshy 0:1c7da5f83647 189
sarahmarshy 0:1c7da5f83647 190 /**
sarahmarshy 0:1c7da5f83647 191 * A buffer that contains all slot frames, 32-bytes allocated to each frame
sarahmarshy 0:1c7da5f83647 192 */
sarahmarshy 0:1c7da5f83647 193 SlotStorage_t slotStorage;
sarahmarshy 0:1c7da5f83647 194
sarahmarshy 0:1c7da5f83647 195 /**
sarahmarshy 0:1c7da5f83647 196 * The state of the recently invoked Factory Reset characteristic
sarahmarshy 0:1c7da5f83647 197 */
sarahmarshy 0:1c7da5f83647 198 uint8_t factoryReset;
sarahmarshy 0:1c7da5f83647 199
sarahmarshy 0:1c7da5f83647 200 /**
sarahmarshy 0:1c7da5f83647 201 * The state of the recently invoked Remain Connectable characteristic
sarahmarshy 0:1c7da5f83647 202 */
sarahmarshy 0:1c7da5f83647 203 uint8_t remainConnectable;
sarahmarshy 0:1c7da5f83647 204 };
sarahmarshy 0:1c7da5f83647 205
sarahmarshy 0:1c7da5f83647 206 /**
sarahmarshy 0:1c7da5f83647 207 * Enumeration that defines the various error codes for EddystoneService.
sarahmarshy 0:1c7da5f83647 208 */
sarahmarshy 0:1c7da5f83647 209 enum EddystoneError_t {
sarahmarshy 0:1c7da5f83647 210 /**
sarahmarshy 0:1c7da5f83647 211 * No error occurred.
sarahmarshy 0:1c7da5f83647 212 */
sarahmarshy 0:1c7da5f83647 213 EDDYSTONE_ERROR_NONE,
sarahmarshy 0:1c7da5f83647 214 /**
sarahmarshy 0:1c7da5f83647 215 * The supplied advertising interval is invalid. The interval may be
sarahmarshy 0:1c7da5f83647 216 * too short/long for the type of advertising packets being broadcast.
sarahmarshy 0:1c7da5f83647 217 *
sarahmarshy 0:1c7da5f83647 218 * @note For the acceptable range of advertising interval refer to the
sarahmarshy 0:1c7da5f83647 219 * following functions in mbed BLE API:
sarahmarshy 0:1c7da5f83647 220 * - Gap::getMinNonConnectableAdvertisingInterval()
sarahmarshy 0:1c7da5f83647 221 * - Gap::getMinAdvertisingInterval()
sarahmarshy 0:1c7da5f83647 222 * - Gap::getMaxAdvertisingInterval()
sarahmarshy 0:1c7da5f83647 223 */
sarahmarshy 0:1c7da5f83647 224 EDDYSTONE_ERROR_INVALID_ADVERTISING_INTERVAL,
sarahmarshy 0:1c7da5f83647 225 /**
sarahmarshy 0:1c7da5f83647 226 * The result of executing a call when the the EddystoneService is in
sarahmarshy 0:1c7da5f83647 227 * the incorrect operation mode.
sarahmarshy 0:1c7da5f83647 228 */
sarahmarshy 0:1c7da5f83647 229 EDDYSTONE_ERROR_INVALID_STATE
sarahmarshy 0:1c7da5f83647 230 };
sarahmarshy 0:1c7da5f83647 231
sarahmarshy 0:1c7da5f83647 232 /**
sarahmarshy 0:1c7da5f83647 233 * Enumeration that defines the available frame types within Eddystone
sarahmarshy 0:1c7da5f83647 234 * advertising packets.
sarahmarshy 0:1c7da5f83647 235 */
sarahmarshy 0:1c7da5f83647 236 enum FrameType {
sarahmarshy 0:1c7da5f83647 237 /**
sarahmarshy 0:1c7da5f83647 238 * The Eddystone-UID frame. Refer to
sarahmarshy 0:1c7da5f83647 239 * https://github.com/google/eddystone/tree/master/eddystone-uid.
sarahmarshy 0:1c7da5f83647 240 */
sarahmarshy 0:1c7da5f83647 241 EDDYSTONE_FRAME_UID,
sarahmarshy 0:1c7da5f83647 242 /**
sarahmarshy 0:1c7da5f83647 243 * The Eddystone-URL frame. Refer to
sarahmarshy 0:1c7da5f83647 244 * https://github.com/google/eddystone/tree/master/eddystone-url.
sarahmarshy 0:1c7da5f83647 245 */
sarahmarshy 0:1c7da5f83647 246 EDDYSTONE_FRAME_URL,
sarahmarshy 0:1c7da5f83647 247 /**
sarahmarshy 0:1c7da5f83647 248 * The Eddystone-TLM frame. Refer to
sarahmarshy 0:1c7da5f83647 249 * https://github.com/google/eddystone/tree/master/eddystone-tlm.
sarahmarshy 0:1c7da5f83647 250 */
sarahmarshy 0:1c7da5f83647 251 EDDYSTONE_FRAME_TLM,
sarahmarshy 0:1c7da5f83647 252 /**
sarahmarshy 0:1c7da5f83647 253 * The Eddystone-EID frame. Refer to
sarahmarshy 0:1c7da5f83647 254 * https://github.com/google/eddystone/tree/master/eddystone-eid.
sarahmarshy 0:1c7da5f83647 255 */
sarahmarshy 0:1c7da5f83647 256 EDDYSTONE_FRAME_EID,
sarahmarshy 0:1c7da5f83647 257 /**
sarahmarshy 0:1c7da5f83647 258 * The total number Eddystone frame types.
sarahmarshy 0:1c7da5f83647 259 */
sarahmarshy 0:1c7da5f83647 260 NUM_EDDYSTONE_FRAMES
sarahmarshy 0:1c7da5f83647 261 };
sarahmarshy 0:1c7da5f83647 262
sarahmarshy 0:1c7da5f83647 263 typedef eq::EventQueue event_queue_t;
sarahmarshy 0:1c7da5f83647 264
sarahmarshy 0:1c7da5f83647 265 /**
sarahmarshy 0:1c7da5f83647 266 * Constructor that Initializes the EddystoneService using parameters from
sarahmarshy 0:1c7da5f83647 267 * the supplied EddystoneParams_t. This constructor is particularly useful
sarahmarshy 0:1c7da5f83647 268 * for configuring the EddystoneService with parameters fetched from
sarahmarshy 0:1c7da5f83647 269 * persistent storage.
sarahmarshy 0:1c7da5f83647 270 *
sarahmarshy 0:1c7da5f83647 271 * @param[in] bleIn
sarahmarshy 0:1c7da5f83647 272 * The BLE instance.
sarahmarshy 0:1c7da5f83647 273 * @param[in] paramIn
sarahmarshy 0:1c7da5f83647 274 * The input Eddystone configuration parameters.
sarahmarshy 0:1c7da5f83647 275 * @param[in] radioPowerLevelsIn
sarahmarshy 0:1c7da5f83647 276 * The value set internally into the radion tx power.
sarahmarshy 0:1c7da5f83647 277 * @param[in] eventQueue
sarahmarshy 0:1c7da5f83647 278 * The event queue used by the service to schedule tasks.
sarahmarshy 0:1c7da5f83647 279 * @param[in] advConfigIntervalIn
sarahmarshy 0:1c7da5f83647 280 * The advertising interval for advertising packets of the
sarahmarshy 0:1c7da5f83647 281 * Eddystone-URL Configuration Service.
sarahmarshy 0:1c7da5f83647 282 */
sarahmarshy 0:1c7da5f83647 283 EddystoneService(BLE &bleIn,
sarahmarshy 0:1c7da5f83647 284 EddystoneParams_t &paramsIn,
sarahmarshy 0:1c7da5f83647 285 const PowerLevels_t &radioPowerLevelsIn,
sarahmarshy 0:1c7da5f83647 286 event_queue_t &eventQueue,
sarahmarshy 0:1c7da5f83647 287 uint32_t advConfigIntervalIn = DEFAULT_CONFIG_PERIOD_MSEC);
sarahmarshy 0:1c7da5f83647 288
sarahmarshy 0:1c7da5f83647 289 /**
sarahmarshy 0:1c7da5f83647 290 * Constructor to initialize the EddystoneService to default values.
sarahmarshy 0:1c7da5f83647 291 *
sarahmarshy 0:1c7da5f83647 292 * @param[in] bleIn
sarahmarshy 0:1c7da5f83647 293 * The BLE instance.
sarahmarshy 0:1c7da5f83647 294 * @param[in] advPowerLevelsIn
sarahmarshy 0:1c7da5f83647 295 * The value of the Eddystone-URL Configuration Service TX
sarahmarshy 0:1c7da5f83647 296 * Power Mode characteristic.
sarahmarshy 0:1c7da5f83647 297 * @param[in] radioPowerLevelsIn
sarahmarshy 0:1c7da5f83647 298 * The value set internally into the radion tx power.
sarahmarshy 0:1c7da5f83647 299 * @param[in] eventQueue
sarahmarshy 0:1c7da5f83647 300 * The event queue used by the service to schedule tasks.
sarahmarshy 0:1c7da5f83647 301 * @param[in] advConfigIntervalIn
sarahmarshy 0:1c7da5f83647 302 * The advertising interval for advertising packets of the
sarahmarshy 0:1c7da5f83647 303 * Eddystone-URL Configuration Service.
sarahmarshy 0:1c7da5f83647 304 *
sarahmarshy 0:1c7da5f83647 305 * @note When using this constructor the setURLData(), setTMLData() and
sarahmarshy 0:1c7da5f83647 306 * setUIDData() and setEIDData() functions must be called to initialize
sarahmarshy 0:1c7da5f83647 307 * EddystoneService manually.
sarahmarshy 0:1c7da5f83647 308 */
sarahmarshy 0:1c7da5f83647 309 EddystoneService(BLE &bleIn,
sarahmarshy 0:1c7da5f83647 310 const PowerLevels_t &advPowerLevelsIn,
sarahmarshy 0:1c7da5f83647 311 const PowerLevels_t &radioPowerLevelsIn,
sarahmarshy 0:1c7da5f83647 312 event_queue_t &eventQueue,
sarahmarshy 0:1c7da5f83647 313 uint32_t advConfigIntervalIn = DEFAULT_CONFIG_PERIOD_MSEC);
sarahmarshy 0:1c7da5f83647 314
sarahmarshy 0:1c7da5f83647 315
sarahmarshy 0:1c7da5f83647 316 /**
sarahmarshy 0:1c7da5f83647 317 * Generate the EID Beacon Random ECHD Keys (private and Public)
sarahmarshy 0:1c7da5f83647 318 */
sarahmarshy 0:1c7da5f83647 319 void genEIDBeaconKeys(void);
sarahmarshy 0:1c7da5f83647 320
sarahmarshy 0:1c7da5f83647 321 /**
sarahmarshy 0:1c7da5f83647 322 * Factory Reset all parameters in the beacon
sarahmarshy 0:1c7da5f83647 323 */
sarahmarshy 0:1c7da5f83647 324 void doFactoryReset(void);
sarahmarshy 0:1c7da5f83647 325
sarahmarshy 0:1c7da5f83647 326 /**
sarahmarshy 0:1c7da5f83647 327 * Setup callback to update BatteryVoltage in Eddystone-TLM frames
sarahmarshy 0:1c7da5f83647 328 *
sarahmarshy 0:1c7da5f83647 329 * @param[in] tlmBatteryVoltageCallbackIn
sarahmarshy 0:1c7da5f83647 330 * The callback being registered.
sarahmarshy 0:1c7da5f83647 331 */
sarahmarshy 0:1c7da5f83647 332 void onTLMBatteryVoltageUpdate(TlmUpdateCallback_t tlmBatteryVoltageCallbackIn);
sarahmarshy 0:1c7da5f83647 333
sarahmarshy 0:1c7da5f83647 334 /**
sarahmarshy 0:1c7da5f83647 335 * Setup callback to update BeaconTemperature in Eddystone-TLM frames
sarahmarshy 0:1c7da5f83647 336 *
sarahmarshy 0:1c7da5f83647 337 * @param[in] tlmBeaconTemperatureCallbackIn
sarahmarshy 0:1c7da5f83647 338 * The callback being registered.
sarahmarshy 0:1c7da5f83647 339 */
sarahmarshy 0:1c7da5f83647 340 void onTLMBeaconTemperatureUpdate(TlmUpdateCallback_t tlmBeaconTemperatureCallbackIn);
sarahmarshy 0:1c7da5f83647 341
sarahmarshy 0:1c7da5f83647 342 /**
sarahmarshy 0:1c7da5f83647 343 * Change the EddystoneService OperationMode to EDDYSTONE_MODE_CONFIG.
sarahmarshy 0:1c7da5f83647 344 *
sarahmarshy 0:1c7da5f83647 345 * @retval EDDYSTONE_ERROR_NONE if the operation succeeded.
sarahmarshy 0:1c7da5f83647 346 * @retval EDDYSONE_ERROR_INVALID_ADVERTISING_INTERVAL if the configured
sarahmarshy 0:1c7da5f83647 347 * advertising interval is zero.
sarahmarshy 0:1c7da5f83647 348 *
sarahmarshy 0:1c7da5f83647 349 * @note If EddystoneService was previously in EDDYSTONE_MODE_BEACON, then
sarahmarshy 0:1c7da5f83647 350 * the resources allocated to that mode of operation such as memory
sarahmarshy 0:1c7da5f83647 351 * are freed and the BLE instance shutdown before the new operation
sarahmarshy 0:1c7da5f83647 352 * mode is configured.
sarahmarshy 0:1c7da5f83647 353 */
sarahmarshy 0:1c7da5f83647 354 EddystoneError_t startConfigService(void);
sarahmarshy 0:1c7da5f83647 355
sarahmarshy 0:1c7da5f83647 356 /**
sarahmarshy 0:1c7da5f83647 357 * Change the EddystoneService to start transmitting Eddystone beacons
sarahmarshy 0:1c7da5f83647 358 * operationMode = EDDYSTONE_MODE_BEACON
sarahmarshy 0:1c7da5f83647 359 *
sarahmarshy 0:1c7da5f83647 360 * @retval EDDYSTONE_ERROR_NONE if the operation succeeded.
sarahmarshy 0:1c7da5f83647 361 * @retval EDDYSONE_ERROR_INVALID_ADVERTISING_INTERVAL if the configured
sarahmarshy 0:1c7da5f83647 362 * advertising interval is zero.
sarahmarshy 0:1c7da5f83647 363 *
sarahmarshy 0:1c7da5f83647 364 * @note If EddystoneService was previously in EDDYSTONE_MODE_CONFIG, then
sarahmarshy 0:1c7da5f83647 365 * the resources allocated to that mode of operation such as memory
sarahmarshy 0:1c7da5f83647 366 * are freed and the BLE instance shutdown before the new operation
sarahmarshy 0:1c7da5f83647 367 * mode is configured.
sarahmarshy 0:1c7da5f83647 368 */
sarahmarshy 0:1c7da5f83647 369 EddystoneError_t startEddystoneBeaconAdvertisements(void);
sarahmarshy 0:1c7da5f83647 370
sarahmarshy 0:1c7da5f83647 371 /**
sarahmarshy 0:1c7da5f83647 372 * Set the Comple Local Name for the BLE device. This not only updates
sarahmarshy 0:1c7da5f83647 373 * the value of the Device Name Characteristic, it also updates the scan
sarahmarshy 0:1c7da5f83647 374 * response payload if the EddystoneService is currently in
sarahmarshy 0:1c7da5f83647 375 * EDDYSTONE_MODE_CONFIG.
sarahmarshy 0:1c7da5f83647 376 *
sarahmarshy 0:1c7da5f83647 377 * @param[in] deviceNameIn
sarahmarshy 0:1c7da5f83647 378 * A pointer to a null terminated string containing the new
sarahmarshy 0:1c7da5f83647 379 * device name.
sarahmarshy 0:1c7da5f83647 380 *
sarahmarshy 0:1c7da5f83647 381 * @return BLE_ERROR_NONE if the name was successfully set. Otherwise an
sarahmarshy 0:1c7da5f83647 382 * appropriate error.
sarahmarshy 0:1c7da5f83647 383 *
sarahmarshy 0:1c7da5f83647 384 * @note EddystoneService does not make an internal copy of the string
sarahmarshy 0:1c7da5f83647 385 * pointed to by @p deviceNameIn. Therefore, the user is responsible
sarahmarshy 0:1c7da5f83647 386 * for ensuring that the string persists in memory as long as it is
sarahmarshy 0:1c7da5f83647 387 * in use by the EddystoneService.
sarahmarshy 0:1c7da5f83647 388 *
sarahmarshy 0:1c7da5f83647 389 * @note The device name is not considered an Eddystone configuration
sarahmarshy 0:1c7da5f83647 390 * parameter; therefore, it is not contained within the
sarahmarshy 0:1c7da5f83647 391 * EddystoneParams_t structure and must be stored to persistent
sarahmarshy 0:1c7da5f83647 392 * storage separately.
sarahmarshy 0:1c7da5f83647 393 */
sarahmarshy 0:1c7da5f83647 394 ble_error_t setCompleteDeviceName(const char *deviceNameIn);
sarahmarshy 0:1c7da5f83647 395
sarahmarshy 0:1c7da5f83647 396 /**
sarahmarshy 0:1c7da5f83647 397 * Get the Eddystone Configuration parameters. This is particularly useful
sarahmarshy 0:1c7da5f83647 398 * for storing the configuration parameters in persistent storage.
sarahmarshy 0:1c7da5f83647 399 * It is not the responsibility of the Eddystone implementation to store
sarahmarshy 0:1c7da5f83647 400 * the configured parameters in persistent storage since this is
sarahmarshy 0:1c7da5f83647 401 * platform-specific.
sarahmarshy 0:1c7da5f83647 402 *
sarahmarshy 0:1c7da5f83647 403 * @param[out] params
sarahmarshy 0:1c7da5f83647 404 * A reference to an EddystoneParams_t structure with the
sarahmarshy 0:1c7da5f83647 405 * configured parameters of the EddystoneService.
sarahmarshy 0:1c7da5f83647 406 */
sarahmarshy 0:1c7da5f83647 407 void getEddystoneParams(EddystoneParams_t &params);
sarahmarshy 0:1c7da5f83647 408
sarahmarshy 0:1c7da5f83647 409 /**
sarahmarshy 0:1c7da5f83647 410 * Start advertising packets indicating the Eddystone Configuration state
sarahmarshy 0:1c7da5f83647 411 * operationMode = EDDYSTONE_MODE_CONFIG
sarahmarshy 0:1c7da5f83647 412 */
sarahmarshy 0:1c7da5f83647 413 EddystoneService::EddystoneError_t startEddystoneConfigAdvertisements(void);
sarahmarshy 0:1c7da5f83647 414
sarahmarshy 0:1c7da5f83647 415 /**
sarahmarshy 0:1c7da5f83647 416 * Free the resources acquired by a call to setupBeaconService() and
sarahmarshy 0:1c7da5f83647 417 * cancel all pending callbacks that operate the radio and frame queue.
sarahmarshy 0:1c7da5f83647 418 *
sarahmarshy 0:1c7da5f83647 419 * @note This call will not modify the current state of the BLE device.
sarahmarshy 0:1c7da5f83647 420 * EddystoneService::stopBeaconService should only be called after
sarahmarshy 0:1c7da5f83647 421 * a call to BLE::shutdown().
sarahmarshy 0:1c7da5f83647 422 */
sarahmarshy 0:1c7da5f83647 423 void stopEddystoneBeaconAdvertisements(void);
sarahmarshy 0:1c7da5f83647 424
sarahmarshy 0:1c7da5f83647 425 /**
sarahmarshy 0:1c7da5f83647 426 * Initialize and start the BLE Eddystone Configuration Service
sarahmarshy 0:1c7da5f83647 427 * This will create the 12-characteristics of the service and make them
sarahmarshy 0:1c7da5f83647 428 * available when a client connects
sarahmarshy 0:1c7da5f83647 429 */
sarahmarshy 0:1c7da5f83647 430 void startEddystoneConfigService();
sarahmarshy 0:1c7da5f83647 431
sarahmarshy 0:1c7da5f83647 432 /**
sarahmarshy 0:1c7da5f83647 433 * Stops the Eddystone Configuration Service and frees its resources
sarahmarshy 0:1c7da5f83647 434 * and cancels all pending callbacks that operate the radio and frame queue.
sarahmarshy 0:1c7da5f83647 435 *
sarahmarshy 0:1c7da5f83647 436 * @note This call will not modify the current state of the BLE device.
sarahmarshy 0:1c7da5f83647 437 * EddystoneService::stopBeaconService should only be called after
sarahmarshy 0:1c7da5f83647 438 * a call to BLE::shutdown().
sarahmarshy 0:1c7da5f83647 439 */
sarahmarshy 0:1c7da5f83647 440 void stopEddystoneConfigService();
sarahmarshy 0:1c7da5f83647 441
sarahmarshy 0:1c7da5f83647 442 /**
sarahmarshy 0:1c7da5f83647 443 * Tests if the beacon is locked or not
sarahmarshy 0:1c7da5f83647 444 *
sarahmarshy 0:1c7da5f83647 445 * @return bool
sarahmarshy 0:1c7da5f83647 446 */
sarahmarshy 0:1c7da5f83647 447 bool isLocked();
sarahmarshy 0:1c7da5f83647 448
sarahmarshy 0:1c7da5f83647 449 /**
sarahmarshy 0:1c7da5f83647 450 * Print an array as a set of hex values
sarahmarshy 0:1c7da5f83647 451 *
sarahmarshy 0:1c7da5f83647 452 * @param[in] a
sarahmarshy 0:1c7da5f83647 453 * The array to be printed.
sarahmarshy 0:1c7da5f83647 454 *
sarahmarshy 0:1c7da5f83647 455 * @param[in] len
sarahmarshy 0:1c7da5f83647 456 * The length of the array.
sarahmarshy 0:1c7da5f83647 457 *
sarahmarshy 0:1c7da5f83647 458 * @return void
sarahmarshy 0:1c7da5f83647 459 *
sarahmarshy 0:1c7da5f83647 460 */
sarahmarshy 0:1c7da5f83647 461 static void logPrintHex(uint8_t* a, int len);
sarahmarshy 0:1c7da5f83647 462
sarahmarshy 0:1c7da5f83647 463 /**
sarahmarshy 0:1c7da5f83647 464 * Swaps the endianess of an array ptrIn[size] to ptrOut[size]
sarahmarshy 0:1c7da5f83647 465 *
sarahmarshy 0:1c7da5f83647 466 * @param[in] *ptrIn
sarahmarshy 0:1c7da5f83647 467 * The input array
sarahmarshy 0:1c7da5f83647 468 * @param[in] *ptrOut
sarahmarshy 0:1c7da5f83647 469 * The output array
sarahmarshy 0:1c7da5f83647 470 * @param[in] size
sarahmarshy 0:1c7da5f83647 471 * The sizes of the arrays (num bytes to be reversed)
sarahmarshy 0:1c7da5f83647 472 */
sarahmarshy 0:1c7da5f83647 473 static void swapEndianArray(uint8_t *ptrIn, uint8_t *ptrOut, int size);
sarahmarshy 0:1c7da5f83647 474
sarahmarshy 0:1c7da5f83647 475 /**
sarahmarshy 0:1c7da5f83647 476 * Generate a random array of bytes of length size
sarahmarshy 0:1c7da5f83647 477 *
sarahmarshy 0:1c7da5f83647 478 * @param[in] *ain
sarahmarshy 0:1c7da5f83647 479 * The input/output array
sarahmarshy 0:1c7da5f83647 480 * @param[in] size
sarahmarshy 0:1c7da5f83647 481 * The size of the array in bytes
sarahmarshy 0:1c7da5f83647 482 */
sarahmarshy 0:1c7da5f83647 483 static void generateRandom(uint8_t *ain, int size);
sarahmarshy 0:1c7da5f83647 484
sarahmarshy 0:1c7da5f83647 485 /**
sarahmarshy 0:1c7da5f83647 486 * Timer that keeps track of the time since boot.
sarahmarshy 0:1c7da5f83647 487 */
sarahmarshy 0:1c7da5f83647 488 static Timer timeSinceBootTimer;
sarahmarshy 0:1c7da5f83647 489
sarahmarshy 0:1c7da5f83647 490 private:
sarahmarshy 0:1c7da5f83647 491
sarahmarshy 0:1c7da5f83647 492 static const uint8_t NO_EID_SLOT_SET = 0xff;
sarahmarshy 0:1c7da5f83647 493
sarahmarshy 0:1c7da5f83647 494 static const uint8_t UNDEFINED_FRAME_FORMAT = 0xff;
sarahmarshy 0:1c7da5f83647 495
sarahmarshy 0:1c7da5f83647 496 static const uint8_t REMAIN_CONNECTABLE_SET = 0x01;
sarahmarshy 0:1c7da5f83647 497
sarahmarshy 0:1c7da5f83647 498 static const uint8_t REMAIN_CONNECTABLE_UNSET = 0x00;
sarahmarshy 0:1c7da5f83647 499
sarahmarshy 0:1c7da5f83647 500 static const uint8_t CONFIG_FRAME_HDR_LEN = 4;
sarahmarshy 0:1c7da5f83647 501
sarahmarshy 0:1c7da5f83647 502 /**
sarahmarshy 0:1c7da5f83647 503 * Helper funtion that will be registered as an initialization complete
sarahmarshy 0:1c7da5f83647 504 * callback when BLE::shutdown() is called. This is necessary when changing
sarahmarshy 0:1c7da5f83647 505 * Eddystone OperationModes. Once the BLE initialization is complete, this
sarahmarshy 0:1c7da5f83647 506 * callback will initialize all the necessary resource to operate
sarahmarshy 0:1c7da5f83647 507 * Eddystone service in the selected mode.
sarahmarshy 0:1c7da5f83647 508 *
sarahmarshy 0:1c7da5f83647 509 * @param[in] initContext
sarahmarshy 0:1c7da5f83647 510 * The context provided by BLE API when initialization
sarahmarshy 0:1c7da5f83647 511 * completes.
sarahmarshy 0:1c7da5f83647 512 */
sarahmarshy 0:1c7da5f83647 513 void bleInitComplete(BLE::InitializationCompleteCallbackContext* initContext);
sarahmarshy 0:1c7da5f83647 514
sarahmarshy 0:1c7da5f83647 515 /**
sarahmarshy 0:1c7da5f83647 516 * When in EDDYSTONE_MODE_BEACON this function is called to update the
sarahmarshy 0:1c7da5f83647 517 * advertising payload to contain the information related to the specified
sarahmarshy 0:1c7da5f83647 518 * FrameType.
sarahmarshy 0:1c7da5f83647 519 *
sarahmarshy 0:1c7da5f83647 520 * @param[in] slot
sarahmarshy 0:1c7da5f83647 521 * The slot to populate the advertising payload with.
sarahmarshy 0:1c7da5f83647 522 */
sarahmarshy 0:1c7da5f83647 523 void swapAdvertisedFrame(int slot);
sarahmarshy 0:1c7da5f83647 524
sarahmarshy 0:1c7da5f83647 525 /**
sarahmarshy 0:1c7da5f83647 526 * Helper function that manages the BLE radio that is used to broadcast
sarahmarshy 0:1c7da5f83647 527 * advertising packets. To advertise frames at the configured intervals
sarahmarshy 0:1c7da5f83647 528 * the actual advertising interval of the BLE instance is set to the value
sarahmarshy 0:1c7da5f83647 529 * returned by Gap::getMaxAdvertisingInterval() from the BLE API. When a
sarahmarshy 0:1c7da5f83647 530 * frame needs to be advertised, the enqueueFrame() callbacks add the frame
sarahmarshy 0:1c7da5f83647 531 * type to the advFrameQueue and post a manageRadio() callback. When the
sarahmarshy 0:1c7da5f83647 532 * callback is executed, the frame is dequeued and advertised using the
sarahmarshy 0:1c7da5f83647 533 * radio (by updating the advertising payload). manageRadio() also posts a
sarahmarshy 0:1c7da5f83647 534 * callback to itself Gap::getMinNonConnectableAdvertisingInterval()
sarahmarshy 0:1c7da5f83647 535 * milliseconds later. In this callback, manageRadio() will advertise the
sarahmarshy 0:1c7da5f83647 536 * next frame in the queue, yet if there is none it calls
sarahmarshy 0:1c7da5f83647 537 * Gap::stopAdvertising() and does not post any further callbacks.
sarahmarshy 0:1c7da5f83647 538 */
sarahmarshy 0:1c7da5f83647 539 void manageRadio(void);
sarahmarshy 0:1c7da5f83647 540
sarahmarshy 0:1c7da5f83647 541 /**
sarahmarshy 0:1c7da5f83647 542 * Regular callbacks posted at the rate of slotAdvPeriod[slot] milliseconds
sarahmarshy 0:1c7da5f83647 543 * enqueue frames to be advertised. If the
sarahmarshy 0:1c7da5f83647 544 * frame queue is currently empty, then this function directly calls
sarahmarshy 0:1c7da5f83647 545 * manageRadio() to broadcast the required FrameType.
sarahmarshy 0:1c7da5f83647 546 *
sarahmarshy 0:1c7da5f83647 547 * @param[in] frameType
sarahmarshy 0:1c7da5f83647 548 * The FrameType to enqueue for broadcasting.
sarahmarshy 0:1c7da5f83647 549 */
sarahmarshy 0:1c7da5f83647 550 void enqueueFrame(int slot);
sarahmarshy 0:1c7da5f83647 551
sarahmarshy 0:1c7da5f83647 552 /**
sarahmarshy 0:1c7da5f83647 553 * Helper function that updates the advertising payload when in
sarahmarshy 0:1c7da5f83647 554 * EDDYSTONE_MODE_BEACON to contain a new frame.
sarahmarshy 0:1c7da5f83647 555 *
sarahmarshy 0:1c7da5f83647 556 * @param[in] rawFrame
sarahmarshy 0:1c7da5f83647 557 * The raw bytes of the frame to advertise.
sarahmarshy 0:1c7da5f83647 558 * @param[in] rawFrameLength
sarahmarshy 0:1c7da5f83647 559 * The length in bytes of the array pointed to by @p rawFrame.
sarahmarshy 0:1c7da5f83647 560 */
sarahmarshy 0:1c7da5f83647 561 void updateAdvertisementPacket(const uint8_t* rawFrame, size_t rawFrameLength);
sarahmarshy 0:1c7da5f83647 562
sarahmarshy 0:1c7da5f83647 563 /**
sarahmarshy 0:1c7da5f83647 564 * Helper function that updates the information in the Eddystone-TLM frames
sarahmarshy 0:1c7da5f83647 565 * Internally, this function executes the registered callbacks to update
sarahmarshy 0:1c7da5f83647 566 * beacon Battery Voltage and Temperature (if available). Furthermore, this
sarahmarshy 0:1c7da5f83647 567 * function updates the raw frame data. This operation must be done fairly
sarahmarshy 0:1c7da5f83647 568 * often because the Eddystone-TLM frame Time Since Boot must have a 0.1
sarahmarshy 0:1c7da5f83647 569 * seconds resolution according to the Eddystone specification.
sarahmarshy 0:1c7da5f83647 570 */
sarahmarshy 0:1c7da5f83647 571 void updateRawTLMFrame(uint8_t* frame);
sarahmarshy 0:1c7da5f83647 572
sarahmarshy 0:1c7da5f83647 573 /**
sarahmarshy 0:1c7da5f83647 574 * Calculate the Frame pointer from the slot number
sarahmarshy 0:1c7da5f83647 575 */
sarahmarshy 0:1c7da5f83647 576 uint8_t* slotToFrame(int slot);
sarahmarshy 0:1c7da5f83647 577
sarahmarshy 0:1c7da5f83647 578 /**
sarahmarshy 0:1c7da5f83647 579 * Free the characteric resources acquired by a call to
sarahmarshy 0:1c7da5f83647 580 * startEddystoneConfigService().
sarahmarshy 0:1c7da5f83647 581 */
sarahmarshy 0:1c7da5f83647 582 void freeConfigCharacteristics(void);
sarahmarshy 0:1c7da5f83647 583
sarahmarshy 0:1c7da5f83647 584 /**
sarahmarshy 0:1c7da5f83647 585 * Helper function used to update the GATT database following any
sarahmarshy 0:1c7da5f83647 586 * change to the internal state of the service object.
sarahmarshy 0:1c7da5f83647 587 */
sarahmarshy 0:1c7da5f83647 588 void updateCharacteristicValues(void);
sarahmarshy 0:1c7da5f83647 589
sarahmarshy 0:1c7da5f83647 590 /**
sarahmarshy 0:1c7da5f83647 591 * Helper function to setup the payload of scan response packets for
sarahmarshy 0:1c7da5f83647 592 * Eddystone-URL Configuration Service.
sarahmarshy 0:1c7da5f83647 593 */
sarahmarshy 0:1c7da5f83647 594 void setupEddystoneConfigScanResponse(void);
sarahmarshy 0:1c7da5f83647 595
sarahmarshy 0:1c7da5f83647 596 /**
sarahmarshy 0:1c7da5f83647 597 * Callback registered to the BLE API to authorize write operations to the
sarahmarshy 0:1c7da5f83647 598 * Eddystone Configuration Service Lock characteristic.
sarahmarshy 0:1c7da5f83647 599 *
sarahmarshy 0:1c7da5f83647 600 * @param[in] authParams
sarahmarshy 0:1c7da5f83647 601 * Write authentication information.
sarahmarshy 0:1c7da5f83647 602 */
sarahmarshy 0:1c7da5f83647 603 void writeLockAuthorizationCallback(GattWriteAuthCallbackParams *authParams);
sarahmarshy 0:1c7da5f83647 604
sarahmarshy 0:1c7da5f83647 605 /**
sarahmarshy 0:1c7da5f83647 606 * Callback registered to the BLE API to authorize write operations to the
sarahmarshy 0:1c7da5f83647 607 * Eddystone Configuration Service Unlock characteristic.
sarahmarshy 0:1c7da5f83647 608 *
sarahmarshy 0:1c7da5f83647 609 * @param[in] authParams
sarahmarshy 0:1c7da5f83647 610 * Write authentication information.
sarahmarshy 0:1c7da5f83647 611 */
sarahmarshy 0:1c7da5f83647 612 void writeUnlockAuthorizationCallback(GattWriteAuthCallbackParams *authParams);
sarahmarshy 0:1c7da5f83647 613
sarahmarshy 0:1c7da5f83647 614 /**
sarahmarshy 0:1c7da5f83647 615 * Callback registered to the BLE API to authorize write operations to the
sarahmarshy 0:1c7da5f83647 616 * Eddystone Configuration Service advSlotData characteristic.
sarahmarshy 0:1c7da5f83647 617 *
sarahmarshy 0:1c7da5f83647 618 * @param[in] authParams
sarahmarshy 0:1c7da5f83647 619 * Write authentication information.
sarahmarshy 0:1c7da5f83647 620 */
sarahmarshy 0:1c7da5f83647 621 void writeVarLengthDataAuthorizationCallback(GattWriteAuthCallbackParams *authParams);
sarahmarshy 0:1c7da5f83647 622
sarahmarshy 0:1c7da5f83647 623 /**
sarahmarshy 0:1c7da5f83647 624 * Callback registered to the BLE API to authorize write operations to the
sarahmarshy 0:1c7da5f83647 625 * lockState characteristic which can be 1 byte or 17 bytes long.
sarahmarshy 0:1c7da5f83647 626 *
sarahmarshy 0:1c7da5f83647 627 * @param[in] authParams
sarahmarshy 0:1c7da5f83647 628 * Write authentication information.
sarahmarshy 0:1c7da5f83647 629 */
sarahmarshy 0:1c7da5f83647 630 void writeLockStateAuthorizationCallback(GattWriteAuthCallbackParams *authParams);
sarahmarshy 0:1c7da5f83647 631
sarahmarshy 0:1c7da5f83647 632 /**
sarahmarshy 0:1c7da5f83647 633 * Callback registered to the BLE API to authorize write operations to simple fixed length
sarahmarshy 0:1c7da5f83647 634 * value characteristic types.
sarahmarshy 0:1c7da5f83647 635 *
sarahmarshy 0:1c7da5f83647 636 * @param[in] authParams
sarahmarshy 0:1c7da5f83647 637 * Write authentication information.
sarahmarshy 0:1c7da5f83647 638 */
sarahmarshy 0:1c7da5f83647 639 template <typename T>
sarahmarshy 0:1c7da5f83647 640 void writeBasicAuthorizationCallback(GattWriteAuthCallbackParams *authParams);
sarahmarshy 0:1c7da5f83647 641
sarahmarshy 0:1c7da5f83647 642 /**
sarahmarshy 0:1c7da5f83647 643 * This callback is invoked when a GATT client attempts to write to the
sarahmarshy 0:1c7da5f83647 644 * Active Slot characteristic of the service.
sarahmarshy 0:1c7da5f83647 645 *
sarahmarshy 0:1c7da5f83647 646 * @param[in] authParams
sarahmarshy 0:1c7da5f83647 647 * Information about the values that are being read.
sarahmarshy 0:1c7da5f83647 648 */
sarahmarshy 0:1c7da5f83647 649 template <typename T>
sarahmarshy 0:1c7da5f83647 650 void writeActiveSlotAuthorizationCallback(GattWriteAuthCallbackParams *authParams);
sarahmarshy 0:1c7da5f83647 651
sarahmarshy 0:1c7da5f83647 652 /**
sarahmarshy 0:1c7da5f83647 653 * READ AUTHORIZATIONS
sarahmarshy 0:1c7da5f83647 654 */
sarahmarshy 0:1c7da5f83647 655
sarahmarshy 0:1c7da5f83647 656 /**
sarahmarshy 0:1c7da5f83647 657 * This callback is invoked when a GATT client attempts to read from a
sarahmarshy 0:1c7da5f83647 658 * basic characteristic of the Eddystone Configuration Service, which
sarahmarshy 0:1c7da5f83647 659 * is blocked if the beacon lock is set to LOCKED.
sarahmarshy 0:1c7da5f83647 660 *
sarahmarshy 0:1c7da5f83647 661 * @param[in] authParams
sarahmarshy 0:1c7da5f83647 662 * Information about the values that are being read.
sarahmarshy 0:1c7da5f83647 663 */
sarahmarshy 0:1c7da5f83647 664 void readBasicTestLockAuthorizationCallback(GattReadAuthCallbackParams *authParams);
sarahmarshy 0:1c7da5f83647 665
sarahmarshy 0:1c7da5f83647 666 /**
sarahmarshy 0:1c7da5f83647 667 * This callback is invoked when a GATT client attempts to read from the
sarahmarshy 0:1c7da5f83647 668 * EidIdentityKey characteristic of the Eddystone Configuration Service,
sarahmarshy 0:1c7da5f83647 669 * which is blocked if the beacon lock is set to LOCKED, or the key has not
sarahmarshy 0:1c7da5f83647 670 * been set/initialized.
sarahmarshy 0:1c7da5f83647 671 *
sarahmarshy 0:1c7da5f83647 672 * @param[in] authParams
sarahmarshy 0:1c7da5f83647 673 * Information about the values that are being read.
sarahmarshy 0:1c7da5f83647 674 */
sarahmarshy 0:1c7da5f83647 675 void readEidIdentityAuthorizationCallback(GattReadAuthCallbackParams *authParams);
sarahmarshy 0:1c7da5f83647 676
sarahmarshy 0:1c7da5f83647 677 /**
sarahmarshy 0:1c7da5f83647 678 * This callback is invoked when a GATT client attempts to read from the
sarahmarshy 0:1c7da5f83647 679 * PublicEcdhKey characteristic of the Eddystone Configuration Service,
sarahmarshy 0:1c7da5f83647 680 * which is blocked if the beacon lock is set to LOCKED, or the key has not
sarahmarshy 0:1c7da5f83647 681 * been set/initialized.
sarahmarshy 0:1c7da5f83647 682 *
sarahmarshy 0:1c7da5f83647 683 * @param[in] authParams
sarahmarshy 0:1c7da5f83647 684 * Information about the values that are being read.
sarahmarshy 0:1c7da5f83647 685 */
sarahmarshy 0:1c7da5f83647 686 void readPublicEcdhKeyAuthorizationCallback(GattReadAuthCallbackParams *authParams);
sarahmarshy 0:1c7da5f83647 687
sarahmarshy 0:1c7da5f83647 688
sarahmarshy 0:1c7da5f83647 689 /**
sarahmarshy 0:1c7da5f83647 690 * This callback is invoked when a GATT client attempts to read from the
sarahmarshy 0:1c7da5f83647 691 * Adv Slot Data characteristic of the Eddystone Configuration Service,
sarahmarshy 0:1c7da5f83647 692 * which isblocked if the beacon lock is set to LOCKED.
sarahmarshy 0:1c7da5f83647 693 *
sarahmarshy 0:1c7da5f83647 694 * @param[in] authParams
sarahmarshy 0:1c7da5f83647 695 * Information about the values that are being read.
sarahmarshy 0:1c7da5f83647 696 */
sarahmarshy 0:1c7da5f83647 697 void readDataAuthorizationCallback(GattReadAuthCallbackParams *authParams);
sarahmarshy 0:1c7da5f83647 698
sarahmarshy 0:1c7da5f83647 699 /**
sarahmarshy 0:1c7da5f83647 700 * Checks if this is valid frame data (i.e. length > 0)
sarahmarshy 0:1c7da5f83647 701 *
sarahmarshy 0:1c7da5f83647 702 * @param[in] frame
sarahmarshy 0:1c7da5f83647 703 * The frame being tested
sarahmarshy 0:1c7da5f83647 704 * @returns frame is valid or not.
sarahmarshy 0:1c7da5f83647 705 */
sarahmarshy 0:1c7da5f83647 706 bool testValidFrame(uint8_t* frame);
sarahmarshy 0:1c7da5f83647 707
sarahmarshy 0:1c7da5f83647 708 /**
sarahmarshy 0:1c7da5f83647 709 * This callback is invoked when a GATT client attempts to read the challenge
sarahmarshy 0:1c7da5f83647 710 * from the Unlock characteristic of the Eddystone Configuration Service,
sarahmarshy 0:1c7da5f83647 711 * which is blocked if the beacon lock is set to UNLOCKED.
sarahmarshy 0:1c7da5f83647 712 *
sarahmarshy 0:1c7da5f83647 713 * @param[in] authParams
sarahmarshy 0:1c7da5f83647 714 * Information about the values that are being read.
sarahmarshy 0:1c7da5f83647 715 */
sarahmarshy 0:1c7da5f83647 716 void readUnlockAuthorizationCallback(GattReadAuthCallbackParams *authParams);
sarahmarshy 0:1c7da5f83647 717
sarahmarshy 0:1c7da5f83647 718 /**
sarahmarshy 0:1c7da5f83647 719 * This callback is invoked when a GATT client attempts to read from the
sarahmarshy 0:1c7da5f83647 720 * Radio Tx Power characteristic of the Eddystone Configuration Service,
sarahmarshy 0:1c7da5f83647 721 * which is blocked if the beacon lock is set to LOCKED.
sarahmarshy 0:1c7da5f83647 722 *
sarahmarshy 0:1c7da5f83647 723 * @param[in] authParams
sarahmarshy 0:1c7da5f83647 724 * Information about the values that are being read.
sarahmarshy 0:1c7da5f83647 725 */
sarahmarshy 0:1c7da5f83647 726 void readRadioTxPowerAuthorizationCallback(GattReadAuthCallbackParams *authParams);
sarahmarshy 0:1c7da5f83647 727
sarahmarshy 0:1c7da5f83647 728 /**
sarahmarshy 0:1c7da5f83647 729 * This callback is invoked when a GATT client attempts to read from the
sarahmarshy 0:1c7da5f83647 730 * Radio Tx Power characteristic of the Eddystone Configuration Service,
sarahmarshy 0:1c7da5f83647 731 * which is blocked if the beacon lock is set to LOCKED.
sarahmarshy 0:1c7da5f83647 732 *
sarahmarshy 0:1c7da5f83647 733 * @param[in] authParams
sarahmarshy 0:1c7da5f83647 734 * Information about the values that are being read.
sarahmarshy 0:1c7da5f83647 735 */
sarahmarshy 0:1c7da5f83647 736 void readAdvTxPowerAuthorizationCallback(GattReadAuthCallbackParams *authParams);
sarahmarshy 0:1c7da5f83647 737
sarahmarshy 0:1c7da5f83647 738 /**
sarahmarshy 0:1c7da5f83647 739 * This callback is invoked when a GATT client attempts to read from the
sarahmarshy 0:1c7da5f83647 740 * Adv Interval characteristic of the Eddystone Configuration Service,
sarahmarshy 0:1c7da5f83647 741 * which is blocked if the beacon lock is set to LOCKED.
sarahmarshy 0:1c7da5f83647 742 *
sarahmarshy 0:1c7da5f83647 743 * @param[in] authParams
sarahmarshy 0:1c7da5f83647 744 * Information about the values that are being read.
sarahmarshy 0:1c7da5f83647 745 */
sarahmarshy 0:1c7da5f83647 746 void readAdvIntervalAuthorizationCallback(GattReadAuthCallbackParams *authParams);
sarahmarshy 0:1c7da5f83647 747
sarahmarshy 0:1c7da5f83647 748 /**
sarahmarshy 0:1c7da5f83647 749 * Calculates the index in the radio power levels array which can be used
sarahmarshy 0:1c7da5f83647 750 * to index into the adv power levels array to find the calibrated adv power
sarahmarshy 0:1c7da5f83647 751 * used in the adv frame.
sarahmarshy 0:1c7da5f83647 752 */
sarahmarshy 0:1c7da5f83647 753 uint8_t radioTxPowerToIndex(int8_t txPower);
sarahmarshy 0:1c7da5f83647 754
sarahmarshy 0:1c7da5f83647 755 /**
sarahmarshy 0:1c7da5f83647 756 * This callback is invoked when a GATT client attempts to modify any of the
sarahmarshy 0:1c7da5f83647 757 * characteristics of this service. Attempts to do so are also applied to
sarahmarshy 0:1c7da5f83647 758 * the internal state of this service object.
sarahmarshy 0:1c7da5f83647 759 *
sarahmarshy 0:1c7da5f83647 760 * @param[in] writeParams
sarahmarshy 0:1c7da5f83647 761 * Information about the values that are being written.
sarahmarshy 0:1c7da5f83647 762 */
sarahmarshy 0:1c7da5f83647 763 void onDataWrittenCallback(const GattWriteCallbackParams *writeParams);
sarahmarshy 0:1c7da5f83647 764
sarahmarshy 0:1c7da5f83647 765 /**
sarahmarshy 0:1c7da5f83647 766 * Sets the power for the frame in a particular slot using the
sarahmarshy 0:1c7da5f83647 767 * adv tx power parmeter
sarahmarshy 0:1c7da5f83647 768 *
sarahmarshy 0:1c7da5f83647 769 * @param[in] slot
sarahmarshy 0:1c7da5f83647 770 * The the current slot number being considered
sarahmarshy 0:1c7da5f83647 771 * @param[in] advTxPower
sarahmarshy 0:1c7da5f83647 772 * The adv power required in a frame
sarahmarshy 0:1c7da5f83647 773 */
sarahmarshy 0:1c7da5f83647 774 void setFrameTxPower(uint8_t slot, int8_t advTxPower);
sarahmarshy 0:1c7da5f83647 775
sarahmarshy 0:1c7da5f83647 776 /**
sarahmarshy 0:1c7da5f83647 777 * AES128 ECB Encrypts a 16-byte input array with a key, to an output array
sarahmarshy 0:1c7da5f83647 778 *
sarahmarshy 0:1c7da5f83647 779 * @param[in] *key
sarahmarshy 0:1c7da5f83647 780 * The encryption key
sarahmarshy 0:1c7da5f83647 781 * @param[in] *input
sarahmarshy 0:1c7da5f83647 782 * The input array
sarahmarshy 0:1c7da5f83647 783 * @param[in] *output
sarahmarshy 0:1c7da5f83647 784 * The output array (contains the encrypted data)
sarahmarshy 0:1c7da5f83647 785 */
sarahmarshy 0:1c7da5f83647 786 void aes128Encrypt(uint8_t *key, uint8_t *input, uint8_t *output);
sarahmarshy 0:1c7da5f83647 787
sarahmarshy 0:1c7da5f83647 788 /**
sarahmarshy 0:1c7da5f83647 789 * AES128 ECB Deccrypts a 16-byte input array with a key, to an output array
sarahmarshy 0:1c7da5f83647 790 *
sarahmarshy 0:1c7da5f83647 791 * @param[in] *key
sarahmarshy 0:1c7da5f83647 792 * The decryption key
sarahmarshy 0:1c7da5f83647 793 * @param[in] *input
sarahmarshy 0:1c7da5f83647 794 * The input array
sarahmarshy 0:1c7da5f83647 795 * @param[in] *output
sarahmarshy 0:1c7da5f83647 796 * The output array (containing the decrypted data)
sarahmarshy 0:1c7da5f83647 797 */
sarahmarshy 0:1c7da5f83647 798 void aes128Decrypt(uint8_t *key, uint8_t *input, uint8_t *output);
sarahmarshy 0:1c7da5f83647 799
sarahmarshy 0:1c7da5f83647 800
sarahmarshy 0:1c7da5f83647 801
sarahmarshy 0:1c7da5f83647 802 /**
sarahmarshy 0:1c7da5f83647 803 * Swaps the endianess of a 16-bit unsigned int
sarahmarshy 0:1c7da5f83647 804 *
sarahmarshy 0:1c7da5f83647 805 * @param[in] arg
sarahmarshy 0:1c7da5f83647 806 * The value with the byte order to be reversed
sarahmarshy 0:1c7da5f83647 807 *
sarahmarshy 0:1c7da5f83647 808 * @return The resulting 16-bit value with byte order reversed
sarahmarshy 0:1c7da5f83647 809 */
sarahmarshy 0:1c7da5f83647 810 uint16_t swapEndian(uint16_t arg);
sarahmarshy 0:1c7da5f83647 811
sarahmarshy 0:1c7da5f83647 812 /**
sarahmarshy 0:1c7da5f83647 813 * Correct the advertising interval for non-connectable packets.
sarahmarshy 0:1c7da5f83647 814 *
sarahmarshy 0:1c7da5f83647 815 * @param[in] beaconPeriodIn
sarahmarshy 0:1c7da5f83647 816 * The input interval in milliseconds.
sarahmarshy 0:1c7da5f83647 817 *
sarahmarshy 0:1c7da5f83647 818 * @return The corrected interval in milliseconds.
sarahmarshy 0:1c7da5f83647 819 *
sarahmarshy 0:1c7da5f83647 820 * @note For the acceptable range of advertising interval refer to the
sarahmarshy 0:1c7da5f83647 821 * following functions in mbed BLE API:
sarahmarshy 0:1c7da5f83647 822 * - Gap::getMinNonConnectableAdvertisingInterval()
sarahmarshy 0:1c7da5f83647 823 * - Gap::getMaxAdvertisingInterval()
sarahmarshy 0:1c7da5f83647 824 */
sarahmarshy 0:1c7da5f83647 825 uint16_t correctAdvertisementPeriod(uint16_t beaconPeriodIn) const;
sarahmarshy 0:1c7da5f83647 826
sarahmarshy 0:1c7da5f83647 827 /**
sarahmarshy 0:1c7da5f83647 828 * Swaps the endianess of a 16-bit unsigned int
sarahmarshy 0:1c7da5f83647 829 *
sarahmarshy 0:1c7da5f83647 830 * @param[in] arg
sarahmarshy 0:1c7da5f83647 831 * The value with the byte order to be reversed
sarahmarshy 0:1c7da5f83647 832 *
sarahmarshy 0:1c7da5f83647 833 * @return The resulting 16-bit value with byte order reversed
sarahmarshy 0:1c7da5f83647 834 */
sarahmarshy 0:1c7da5f83647 835 void setRandomMacAddress(void);
sarahmarshy 0:1c7da5f83647 836
sarahmarshy 0:1c7da5f83647 837 /**
sarahmarshy 0:1c7da5f83647 838 * Finds the first EID slot set
sarahmarshy 0:1c7da5f83647 839 *
sarahmarshy 0:1c7da5f83647 840 * @return slot number (and if not, returns NO_EID_SLOT_SET = -1)
sarahmarshy 0:1c7da5f83647 841 */
sarahmarshy 0:1c7da5f83647 842 int getEidSlot(void);
sarahmarshy 0:1c7da5f83647 843
sarahmarshy 0:1c7da5f83647 844 /**
sarahmarshy 0:1c7da5f83647 845 * Returns the current time in Secs (Prior Time + Time since boot)
sarahmarshy 0:1c7da5f83647 846 *
sarahmarshy 0:1c7da5f83647 847 * @return time
sarahmarshy 0:1c7da5f83647 848 */
sarahmarshy 0:1c7da5f83647 849 uint32_t getTimeSinceFirstBootSecs(void);
sarahmarshy 0:1c7da5f83647 850
sarahmarshy 0:1c7da5f83647 851
sarahmarshy 0:1c7da5f83647 852 /**
sarahmarshy 0:1c7da5f83647 853 * Returns the time since boot in Milliseconds
sarahmarshy 0:1c7da5f83647 854 *
sarahmarshy 0:1c7da5f83647 855 * @return time
sarahmarshy 0:1c7da5f83647 856 */
sarahmarshy 0:1c7da5f83647 857 static uint64_t getTimeSinceLastBootMs(void);
sarahmarshy 0:1c7da5f83647 858
sarahmarshy 0:1c7da5f83647 859 /**
sarahmarshy 0:1c7da5f83647 860 * Saves only the Time Params in pStorage (a subset of all the Eddsytone Params)
sarahmarshy 0:1c7da5f83647 861 * This is more efficient than periodically saving all state (its just 8 bytes)
sarahmarshy 0:1c7da5f83647 862 */
sarahmarshy 0:1c7da5f83647 863 void nvmSaveTimeParams(void);
sarahmarshy 0:1c7da5f83647 864
sarahmarshy 0:1c7da5f83647 865 /**
sarahmarshy 0:1c7da5f83647 866 * BLE instance that EddystoneService will operate on.
sarahmarshy 0:1c7da5f83647 867 */
sarahmarshy 0:1c7da5f83647 868 BLE &ble;
sarahmarshy 0:1c7da5f83647 869
sarahmarshy 0:1c7da5f83647 870 /**
sarahmarshy 0:1c7da5f83647 871 * The advertising interval for Eddystone-URL Config Service advertising
sarahmarshy 0:1c7da5f83647 872 * packets.
sarahmarshy 0:1c7da5f83647 873 */
sarahmarshy 0:1c7da5f83647 874 uint32_t advConfigInterval;
sarahmarshy 0:1c7da5f83647 875 /**
sarahmarshy 0:1c7da5f83647 876 * Current EddystoneServce operation mode.
sarahmarshy 0:1c7da5f83647 877 */
sarahmarshy 0:1c7da5f83647 878 uint8_t operationMode;
sarahmarshy 0:1c7da5f83647 879
sarahmarshy 0:1c7da5f83647 880 /**
sarahmarshy 0:1c7da5f83647 881 * Parameter to consistently record the return code when generating Beacon Keys
sarahmarshy 0:1c7da5f83647 882 */
sarahmarshy 0:1c7da5f83647 883 int genBeaconKeyRC;
sarahmarshy 0:1c7da5f83647 884
sarahmarshy 0:1c7da5f83647 885 /**
sarahmarshy 0:1c7da5f83647 886 * Keeps track of time in prior boots and current/last boot
sarahmarshy 0:1c7da5f83647 887 */
sarahmarshy 0:1c7da5f83647 888 TimeParams_t timeParams;
sarahmarshy 0:1c7da5f83647 889
sarahmarshy 0:1c7da5f83647 890 /**
sarahmarshy 0:1c7da5f83647 891 * GATT Service Variables
sarahmarshy 0:1c7da5f83647 892 */
sarahmarshy 0:1c7da5f83647 893
sarahmarshy 0:1c7da5f83647 894 /**
sarahmarshy 0:1c7da5f83647 895 * An array describing the capabilites of the beacon.
sarahmarshy 0:1c7da5f83647 896 */
sarahmarshy 0:1c7da5f83647 897 Capability_t capabilities;
sarahmarshy 0:1c7da5f83647 898
sarahmarshy 0:1c7da5f83647 899 /**
sarahmarshy 0:1c7da5f83647 900 * The currenty defined active slot.
sarahmarshy 0:1c7da5f83647 901 */
sarahmarshy 0:1c7da5f83647 902 uint8_t activeSlot;
sarahmarshy 0:1c7da5f83647 903
sarahmarshy 0:1c7da5f83647 904 /**
sarahmarshy 0:1c7da5f83647 905 * An array containing all the adv intervals for each slot index
sarahmarshy 0:1c7da5f83647 906 */
sarahmarshy 0:1c7da5f83647 907 SlotAdvIntervals_t slotAdvIntervals;
sarahmarshy 0:1c7da5f83647 908
sarahmarshy 0:1c7da5f83647 909 /**
sarahmarshy 0:1c7da5f83647 910 * The value of the Eddystone Configuration Service radioTX Power
sarahmarshy 0:1c7da5f83647 911 * characteristic.
sarahmarshy 0:1c7da5f83647 912 */
sarahmarshy 0:1c7da5f83647 913 SlotTxPowerLevels_t slotRadioTxPowerLevels;
sarahmarshy 0:1c7da5f83647 914
sarahmarshy 0:1c7da5f83647 915 /**
sarahmarshy 0:1c7da5f83647 916 * An array containing the supported radio tx power levels for this beacon
sarahmarshy 0:1c7da5f83647 917 */
sarahmarshy 0:1c7da5f83647 918 PowerLevels_t radioTxPowerLevels;
sarahmarshy 0:1c7da5f83647 919
sarahmarshy 0:1c7da5f83647 920 /**
sarahmarshy 0:1c7da5f83647 921 * An array containing all possible values for advertised tx power in Eddystone
sarahmarshy 0:1c7da5f83647 922 * slots.
sarahmarshy 0:1c7da5f83647 923 */
sarahmarshy 0:1c7da5f83647 924 SlotTxPowerLevels_t slotAdvTxPowerLevels;
sarahmarshy 0:1c7da5f83647 925
sarahmarshy 0:1c7da5f83647 926 /**
sarahmarshy 0:1c7da5f83647 927 * An array containing the supported adv tx power levels for this beacon
sarahmarshy 0:1c7da5f83647 928 */
sarahmarshy 0:1c7da5f83647 929 PowerLevels_t advTxPowerLevels;
sarahmarshy 0:1c7da5f83647 930
sarahmarshy 0:1c7da5f83647 931 /**
sarahmarshy 0:1c7da5f83647 932 * The value of the Eddystone Configuration Service Lock State
sarahmarshy 0:1c7da5f83647 933 * characteristic.
sarahmarshy 0:1c7da5f83647 934 */
sarahmarshy 0:1c7da5f83647 935 uint8_t lockState;
sarahmarshy 0:1c7da5f83647 936
sarahmarshy 0:1c7da5f83647 937
sarahmarshy 0:1c7da5f83647 938 /**
sarahmarshy 0:1c7da5f83647 939 * The value of the Eddystone Configuration Service Lock State
sarahmarshy 0:1c7da5f83647 940 * buffer
sarahmarshy 0:1c7da5f83647 941 */
sarahmarshy 0:1c7da5f83647 942 LockState_t lockStateBuf;
sarahmarshy 0:1c7da5f83647 943
sarahmarshy 0:1c7da5f83647 944 /**
sarahmarshy 0:1c7da5f83647 945 * The value of the Eddystone Configuration Service unlock key
sarahmarshy 0:1c7da5f83647 946 */
sarahmarshy 0:1c7da5f83647 947 Lock_t unlockKey;
sarahmarshy 0:1c7da5f83647 948
sarahmarshy 0:1c7da5f83647 949 /**
sarahmarshy 0:1c7da5f83647 950 * The value of the Eddystone Configuration Service unlock challenge
sarahmarshy 0:1c7da5f83647 951 */
sarahmarshy 0:1c7da5f83647 952 Lock_t challenge;
sarahmarshy 0:1c7da5f83647 953
sarahmarshy 0:1c7da5f83647 954 /**
sarahmarshy 0:1c7da5f83647 955 * The value of the Eddystone Configuration Service unlock token. A write
sarahmarshy 0:1c7da5f83647 956 * to the unlock characteristic must contain this token to unlock the beacon
sarahmarshy 0:1c7da5f83647 957 */
sarahmarshy 0:1c7da5f83647 958 Lock_t unlockToken;
sarahmarshy 0:1c7da5f83647 959
sarahmarshy 0:1c7da5f83647 960
sarahmarshy 0:1c7da5f83647 961 /**
sarahmarshy 0:1c7da5f83647 962 * EID: An array holding the 256-bit private Ecdh Key (big endian)
sarahmarshy 0:1c7da5f83647 963 */
sarahmarshy 0:1c7da5f83647 964 PrivateEcdhKey_t privateEcdhKey;
sarahmarshy 0:1c7da5f83647 965
sarahmarshy 0:1c7da5f83647 966 /**
sarahmarshy 0:1c7da5f83647 967 * EID: An array holding the 256-bit public Ecdh Key (big endian)
sarahmarshy 0:1c7da5f83647 968 */
sarahmarshy 0:1c7da5f83647 969 PublicEcdhKey_t publicEcdhKey;
sarahmarshy 0:1c7da5f83647 970
sarahmarshy 0:1c7da5f83647 971 /**
sarahmarshy 0:1c7da5f83647 972 * EID: An array holding the 256-bit public Ecdh Key (little endian)
sarahmarshy 0:1c7da5f83647 973 */
sarahmarshy 0:1c7da5f83647 974 PublicEcdhKey_t publicEcdhKeyLE;
sarahmarshy 0:1c7da5f83647 975
sarahmarshy 0:1c7da5f83647 976 /**
sarahmarshy 0:1c7da5f83647 977 * EID: An array holding the slot rotation period exponents
sarahmarshy 0:1c7da5f83647 978 */
sarahmarshy 0:1c7da5f83647 979 SlotEidRotationPeriodExps_t slotEidRotationPeriodExps;
sarahmarshy 0:1c7da5f83647 980
sarahmarshy 0:1c7da5f83647 981 /**
sarahmarshy 0:1c7da5f83647 982 * EID: An array holding the slot Eid Identity Keys
sarahmarshy 0:1c7da5f83647 983 */
sarahmarshy 0:1c7da5f83647 984 SlotEidIdentityKeys_t slotEidIdentityKeys;
sarahmarshy 0:1c7da5f83647 985
sarahmarshy 0:1c7da5f83647 986 /**
sarahmarshy 0:1c7da5f83647 987 * EID: An array holding the slot Eid Public Ecdh Keys
sarahmarshy 0:1c7da5f83647 988 */
sarahmarshy 0:1c7da5f83647 989 //SlotEidPublicEcdhKeys_t slotEidPublicEcdhKeys;
sarahmarshy 0:1c7da5f83647 990
sarahmarshy 0:1c7da5f83647 991 /**
sarahmarshy 0:1c7da5f83647 992 * Instance of the UID frame.
sarahmarshy 0:1c7da5f83647 993 */
sarahmarshy 0:1c7da5f83647 994 UIDFrame uidFrame;
sarahmarshy 0:1c7da5f83647 995
sarahmarshy 0:1c7da5f83647 996 /**
sarahmarshy 0:1c7da5f83647 997 * Instance of the URL frame.
sarahmarshy 0:1c7da5f83647 998 */
sarahmarshy 0:1c7da5f83647 999 URLFrame urlFrame;
sarahmarshy 0:1c7da5f83647 1000
sarahmarshy 0:1c7da5f83647 1001 /**
sarahmarshy 0:1c7da5f83647 1002 * Instance of the TLM frame.
sarahmarshy 0:1c7da5f83647 1003 */
sarahmarshy 0:1c7da5f83647 1004 TLMFrame tlmFrame;
sarahmarshy 0:1c7da5f83647 1005
sarahmarshy 0:1c7da5f83647 1006 /**
sarahmarshy 0:1c7da5f83647 1007 * Instance of the EID frame.
sarahmarshy 0:1c7da5f83647 1008 */
sarahmarshy 0:1c7da5f83647 1009 EIDFrame eidFrame;
sarahmarshy 0:1c7da5f83647 1010
sarahmarshy 0:1c7da5f83647 1011 /**
sarahmarshy 0:1c7da5f83647 1012 * The value of the Eddystone Configuration Service reset
sarahmarshy 0:1c7da5f83647 1013 * characteristic.
sarahmarshy 0:1c7da5f83647 1014 */
sarahmarshy 0:1c7da5f83647 1015 uint8_t factoryReset;
sarahmarshy 0:1c7da5f83647 1016
sarahmarshy 0:1c7da5f83647 1017 /**
sarahmarshy 0:1c7da5f83647 1018 * The value of the Eddystone Configuration Service Remain Connectable
sarahmarshy 0:1c7da5f83647 1019 * characteristic.
sarahmarshy 0:1c7da5f83647 1020 */
sarahmarshy 0:1c7da5f83647 1021 uint8_t remainConnectable;
sarahmarshy 0:1c7da5f83647 1022
sarahmarshy 0:1c7da5f83647 1023 /**
sarahmarshy 0:1c7da5f83647 1024 * CHARACTERISTIC STORAGE
sarahmarshy 0:1c7da5f83647 1025 */
sarahmarshy 0:1c7da5f83647 1026
sarahmarshy 0:1c7da5f83647 1027 /**
sarahmarshy 0:1c7da5f83647 1028 * Pointer to the BLE API characteristic encapsulation for the Eddystone
sarahmarshy 0:1c7da5f83647 1029 * Configuration Service Capabilities characteristic.
sarahmarshy 0:1c7da5f83647 1030 */
sarahmarshy 0:1c7da5f83647 1031 ReadOnlyArrayGattCharacteristic<uint8_t, sizeof(Capability_t)> *capabilitiesChar;
sarahmarshy 0:1c7da5f83647 1032
sarahmarshy 0:1c7da5f83647 1033 /**
sarahmarshy 0:1c7da5f83647 1034 * Pointer to the BLE API characteristic encapsulation for the Eddystone
sarahmarshy 0:1c7da5f83647 1035 * Configuration Service Active Slot characteristic.
sarahmarshy 0:1c7da5f83647 1036 */
sarahmarshy 0:1c7da5f83647 1037 ReadWriteGattCharacteristic<uint8_t> *activeSlotChar;
sarahmarshy 0:1c7da5f83647 1038
sarahmarshy 0:1c7da5f83647 1039 /**
sarahmarshy 0:1c7da5f83647 1040 * Pointer to the BLE API characteristic encapsulation for the Eddystone
sarahmarshy 0:1c7da5f83647 1041 * Configuration Service Adv Interval characteristic.
sarahmarshy 0:1c7da5f83647 1042 */
sarahmarshy 0:1c7da5f83647 1043 ReadWriteGattCharacteristic<uint16_t> *advIntervalChar;
sarahmarshy 0:1c7da5f83647 1044
sarahmarshy 0:1c7da5f83647 1045 /**
sarahmarshy 0:1c7da5f83647 1046 * Pointer to the BLE API characteristic encapsulation for the Eddystone
sarahmarshy 0:1c7da5f83647 1047 * Configuration Service Radio Tx Power characteristic.
sarahmarshy 0:1c7da5f83647 1048 */
sarahmarshy 0:1c7da5f83647 1049 ReadWriteGattCharacteristic<int8_t> *radioTxPowerChar;
sarahmarshy 0:1c7da5f83647 1050
sarahmarshy 0:1c7da5f83647 1051 /**
sarahmarshy 0:1c7da5f83647 1052 * Pointer to the BLE API characteristic encapsulation for the Eddystone
sarahmarshy 0:1c7da5f83647 1053 * Configuration Service Adv Tx Power characteristic.
sarahmarshy 0:1c7da5f83647 1054 */
sarahmarshy 0:1c7da5f83647 1055 ReadWriteGattCharacteristic<int8_t> *advTxPowerChar;
sarahmarshy 0:1c7da5f83647 1056
sarahmarshy 0:1c7da5f83647 1057 /**
sarahmarshy 0:1c7da5f83647 1058 * Pointer to the BLE API characteristic encapsulation for the Eddystone
sarahmarshy 0:1c7da5f83647 1059 * Configuration Service Lock State characteristic.
sarahmarshy 0:1c7da5f83647 1060 */
sarahmarshy 0:1c7da5f83647 1061 GattCharacteristic *lockStateChar;
sarahmarshy 0:1c7da5f83647 1062
sarahmarshy 0:1c7da5f83647 1063 /**
sarahmarshy 0:1c7da5f83647 1064 * Pointer to the BLE API characteristic encapsulation for the Eddystone
sarahmarshy 0:1c7da5f83647 1065 * Configuration Service Unlock characteristic.
sarahmarshy 0:1c7da5f83647 1066 */
sarahmarshy 0:1c7da5f83647 1067 ReadWriteArrayGattCharacteristic<uint8_t, sizeof(Lock_t)> *unlockChar;
sarahmarshy 0:1c7da5f83647 1068
sarahmarshy 0:1c7da5f83647 1069 /**
sarahmarshy 0:1c7da5f83647 1070 * Pointer to the BLE API characteristic encapsulation for the Eddystone
sarahmarshy 0:1c7da5f83647 1071 * Configuration Service Public ECDH Key characteristic.
sarahmarshy 0:1c7da5f83647 1072 */
sarahmarshy 0:1c7da5f83647 1073 GattCharacteristic *publicEcdhKeyChar;
sarahmarshy 0:1c7da5f83647 1074
sarahmarshy 0:1c7da5f83647 1075 /**
sarahmarshy 0:1c7da5f83647 1076 * Pointer to the BLE API characteristic encapsulation for the Eddystone-URL
sarahmarshy 0:1c7da5f83647 1077 * Configuration Service EID Identity Key characteristic.
sarahmarshy 0:1c7da5f83647 1078 */
sarahmarshy 0:1c7da5f83647 1079 GattCharacteristic *eidIdentityKeyChar;
sarahmarshy 0:1c7da5f83647 1080
sarahmarshy 0:1c7da5f83647 1081 /**
sarahmarshy 0:1c7da5f83647 1082 * Pointer to the BLE API characteristic encapsulation for the Eddystone-URL
sarahmarshy 0:1c7da5f83647 1083 * Configuration Service Adv Slot Data characteristic.
sarahmarshy 0:1c7da5f83647 1084 */
sarahmarshy 0:1c7da5f83647 1085 GattCharacteristic *advSlotDataChar;
sarahmarshy 0:1c7da5f83647 1086
sarahmarshy 0:1c7da5f83647 1087 /**
sarahmarshy 0:1c7da5f83647 1088 * Pointer to the BLE API characteristic encapsulation for the Eddystone-URL
sarahmarshy 0:1c7da5f83647 1089 * Configuration Service Factory Reset characteristic.
sarahmarshy 0:1c7da5f83647 1090 */
sarahmarshy 0:1c7da5f83647 1091 WriteOnlyGattCharacteristic<uint8_t> *factoryResetChar;
sarahmarshy 0:1c7da5f83647 1092
sarahmarshy 0:1c7da5f83647 1093 /**
sarahmarshy 0:1c7da5f83647 1094 * Pointer to the BLE API characteristic encapsulation for the Eddystone-GATT
sarahmarshy 0:1c7da5f83647 1095 * Configuration Service Remain Connectable characteristic.
sarahmarshy 0:1c7da5f83647 1096 */
sarahmarshy 0:1c7da5f83647 1097 ReadWriteGattCharacteristic<uint8_t> *remainConnectableChar;
sarahmarshy 0:1c7da5f83647 1098
sarahmarshy 0:1c7da5f83647 1099 /**
sarahmarshy 0:1c7da5f83647 1100 * END OF GATT CHARACTERISTICS
sarahmarshy 0:1c7da5f83647 1101 */
sarahmarshy 0:1c7da5f83647 1102
sarahmarshy 0:1c7da5f83647 1103 /**
sarahmarshy 0:1c7da5f83647 1104 * EID: An array holding the slot next rotation times
sarahmarshy 0:1c7da5f83647 1105 */
sarahmarshy 0:1c7da5f83647 1106 SlotEidNextRotationTimes_t slotEidNextRotationTimes;
sarahmarshy 0:1c7da5f83647 1107
sarahmarshy 0:1c7da5f83647 1108 /**
sarahmarshy 0:1c7da5f83647 1109 * EID: Storage for the current slot encrypted EID Identity Key
sarahmarshy 0:1c7da5f83647 1110 */
sarahmarshy 0:1c7da5f83647 1111 EidIdentityKey_t encryptedEidIdentityKey;
sarahmarshy 0:1c7da5f83647 1112
sarahmarshy 0:1c7da5f83647 1113 /*
sarahmarshy 0:1c7da5f83647 1114 * Storage for all the slots / frames
sarahmarshy 0:1c7da5f83647 1115 */
sarahmarshy 0:1c7da5f83647 1116 SlotStorage_t slotStorage;
sarahmarshy 0:1c7da5f83647 1117
sarahmarshy 0:1c7da5f83647 1118 /**
sarahmarshy 0:1c7da5f83647 1119 * An array that defines the frame type of each slot using the slot number
sarahmarshy 0:1c7da5f83647 1120 * as an index.
sarahmarshy 0:1c7da5f83647 1121 */
sarahmarshy 0:1c7da5f83647 1122 SlotFrameTypes_t slotFrameTypes;
sarahmarshy 0:1c7da5f83647 1123
sarahmarshy 0:1c7da5f83647 1124 /**
sarahmarshy 0:1c7da5f83647 1125 * Circular buffer that represents of Eddystone frames to be advertised.
sarahmarshy 0:1c7da5f83647 1126 */
sarahmarshy 0:1c7da5f83647 1127 CircularBuffer<uint8_t, MAX_ADV_SLOTS> advFrameQueue;
sarahmarshy 0:1c7da5f83647 1128
sarahmarshy 0:1c7da5f83647 1129 /**
sarahmarshy 0:1c7da5f83647 1130 * The registered callback to update the Eddystone-TLM frame Battery
sarahmarshy 0:1c7da5f83647 1131 * Voltage.
sarahmarshy 0:1c7da5f83647 1132 */
sarahmarshy 0:1c7da5f83647 1133 TlmUpdateCallback_t tlmBatteryVoltageCallback;
sarahmarshy 0:1c7da5f83647 1134
sarahmarshy 0:1c7da5f83647 1135 /**
sarahmarshy 0:1c7da5f83647 1136 * The registered callback to update the Eddystone-TLM frame Beacon
sarahmarshy 0:1c7da5f83647 1137 * Temperature.
sarahmarshy 0:1c7da5f83647 1138 */
sarahmarshy 0:1c7da5f83647 1139 TlmUpdateCallback_t tlmBeaconTemperatureCallback;
sarahmarshy 0:1c7da5f83647 1140
sarahmarshy 0:1c7da5f83647 1141 /**
sarahmarshy 0:1c7da5f83647 1142 * Type for the array of callback handles for all the slot timers
sarahmarshy 0:1c7da5f83647 1143 */
sarahmarshy 0:1c7da5f83647 1144 typedef event_queue_t::event_handle_t SlotCallbackHandles_t[MAX_ADV_SLOTS];
sarahmarshy 0:1c7da5f83647 1145
sarahmarshy 0:1c7da5f83647 1146 /**
sarahmarshy 0:1c7da5f83647 1147 * An array of all the slot timer callbacks handles
sarahmarshy 0:1c7da5f83647 1148 */
sarahmarshy 0:1c7da5f83647 1149 SlotCallbackHandles_t slotCallbackHandles;
sarahmarshy 0:1c7da5f83647 1150
sarahmarshy 0:1c7da5f83647 1151 /**
sarahmarshy 0:1c7da5f83647 1152 * Callback handle to keep track of manageRadio() callbacks.
sarahmarshy 0:1c7da5f83647 1153 */
sarahmarshy 0:1c7da5f83647 1154 event_queue_t::event_handle_t radioManagerCallbackHandle;
sarahmarshy 0:1c7da5f83647 1155
sarahmarshy 0:1c7da5f83647 1156 /**
sarahmarshy 0:1c7da5f83647 1157 * GattCharacteristic table used to populate the BLE ATT table in the
sarahmarshy 0:1c7da5f83647 1158 * GATT Server.
sarahmarshy 0:1c7da5f83647 1159 */
sarahmarshy 0:1c7da5f83647 1160 GattCharacteristic *charTable[TOTAL_CHARACTERISTICS];
sarahmarshy 0:1c7da5f83647 1161
sarahmarshy 0:1c7da5f83647 1162 /**
sarahmarshy 0:1c7da5f83647 1163 * Pointer to the device name currently being used.
sarahmarshy 0:1c7da5f83647 1164 */
sarahmarshy 0:1c7da5f83647 1165 const char *deviceName;
sarahmarshy 0:1c7da5f83647 1166
sarahmarshy 0:1c7da5f83647 1167 /**
sarahmarshy 0:1c7da5f83647 1168 * Defines an array of string constants (a container) used to initialise any URL slots
sarahmarshy 0:1c7da5f83647 1169 */
sarahmarshy 0:1c7da5f83647 1170 static const char* const slotDefaultUrls[];
sarahmarshy 0:1c7da5f83647 1171
sarahmarshy 0:1c7da5f83647 1172 /**
sarahmarshy 0:1c7da5f83647 1173 * Defines an array of UIDs to initialize UID slots
sarahmarshy 0:1c7da5f83647 1174 */
sarahmarshy 0:1c7da5f83647 1175 static const uint8_t slotDefaultUids[MAX_ADV_SLOTS][16];
sarahmarshy 0:1c7da5f83647 1176
sarahmarshy 0:1c7da5f83647 1177 /**
sarahmarshy 0:1c7da5f83647 1178 * Defines an array of EID (Identity keys) to initialize EID slots
sarahmarshy 0:1c7da5f83647 1179 */
sarahmarshy 0:1c7da5f83647 1180 static const uint8_t slotDefaultEidIdentityKeys[MAX_ADV_SLOTS][16];
sarahmarshy 0:1c7da5f83647 1181
sarahmarshy 0:1c7da5f83647 1182 /**
sarahmarshy 0:1c7da5f83647 1183 * Defines default EID payload before being updated with the first EID rotation value
sarahmarshy 0:1c7da5f83647 1184 */
sarahmarshy 0:1c7da5f83647 1185 static const uint8_t nullEid[8];
sarahmarshy 0:1c7da5f83647 1186
sarahmarshy 0:1c7da5f83647 1187 /**
sarahmarshy 0:1c7da5f83647 1188 * Reference to the event queue used to post tasks
sarahmarshy 0:1c7da5f83647 1189 */
sarahmarshy 0:1c7da5f83647 1190 event_queue_t& eventQueue;
sarahmarshy 0:1c7da5f83647 1191
sarahmarshy 0:1c7da5f83647 1192 /**
sarahmarshy 0:1c7da5f83647 1193 * Next EID slot frame that will be transmitted
sarahmarshy 0:1c7da5f83647 1194 */
sarahmarshy 0:1c7da5f83647 1195 uint8_t nextEidSlot;
sarahmarshy 0:1c7da5f83647 1196 };
sarahmarshy 0:1c7da5f83647 1197
sarahmarshy 0:1c7da5f83647 1198 #endif /* __EDDYSTONESERVICE_H__ */