Preliminary main mbed library for nexpaq development

Committer:
nexpaq
Date:
Fri Nov 04 20:54:50 2016 +0000
Revision:
1:d96dbedaebdb
Parent:
0:6c56fb4bc5f0
Removed extra directories for other platforms

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nexpaq 0:6c56fb4bc5f0 1 /* mbed Microcontroller Library
nexpaq 0:6c56fb4bc5f0 2 * Copyright (c) 2006-2013 ARM Limited
nexpaq 0:6c56fb4bc5f0 3 *
nexpaq 0:6c56fb4bc5f0 4 * Licensed under the Apache License, Version 2.0 (the "License");
nexpaq 0:6c56fb4bc5f0 5 * you may not use this file except in compliance with the License.
nexpaq 0:6c56fb4bc5f0 6 * You may obtain a copy of the License at
nexpaq 0:6c56fb4bc5f0 7 *
nexpaq 0:6c56fb4bc5f0 8 * http://www.apache.org/licenses/LICENSE-2.0
nexpaq 0:6c56fb4bc5f0 9 *
nexpaq 0:6c56fb4bc5f0 10 * Unless required by applicable law or agreed to in writing, software
nexpaq 0:6c56fb4bc5f0 11 * distributed under the License is distributed on an "AS IS" BASIS,
nexpaq 0:6c56fb4bc5f0 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
nexpaq 0:6c56fb4bc5f0 13 * See the License for the specific language governing permissions and
nexpaq 0:6c56fb4bc5f0 14 * limitations under the License.
nexpaq 0:6c56fb4bc5f0 15 */
nexpaq 0:6c56fb4bc5f0 16
nexpaq 0:6c56fb4bc5f0 17 #ifndef __GAP_ADVERTISING_DATA_H__
nexpaq 0:6c56fb4bc5f0 18 #define __GAP_ADVERTISING_DATA_H__
nexpaq 0:6c56fb4bc5f0 19
nexpaq 0:6c56fb4bc5f0 20 #include <stdint.h>
nexpaq 0:6c56fb4bc5f0 21 #include <string.h>
nexpaq 0:6c56fb4bc5f0 22
nexpaq 0:6c56fb4bc5f0 23 #include "blecommon.h"
nexpaq 0:6c56fb4bc5f0 24
nexpaq 0:6c56fb4bc5f0 25 #define GAP_ADVERTISING_DATA_MAX_PAYLOAD (31)
nexpaq 0:6c56fb4bc5f0 26
nexpaq 0:6c56fb4bc5f0 27 /**
nexpaq 0:6c56fb4bc5f0 28 * @brief This class provides several helper functions to generate properly
nexpaq 0:6c56fb4bc5f0 29 * formatted GAP Advertising and Scan Response data payloads.
nexpaq 0:6c56fb4bc5f0 30 *
nexpaq 0:6c56fb4bc5f0 31 * @note See Bluetooth Specification 4.0 (Vol. 3), Part C, Sections 11 and 18
nexpaq 0:6c56fb4bc5f0 32 * for further information on Advertising and Scan Response data.
nexpaq 0:6c56fb4bc5f0 33 *
nexpaq 0:6c56fb4bc5f0 34 * @par Advertising and Scan Response Payloads
nexpaq 0:6c56fb4bc5f0 35 * Advertising data and Scan Response data are organized around a set of
nexpaq 0:6c56fb4bc5f0 36 * data types called 'AD types' in Bluetooth 4.0 (see the Bluetooth Core
nexpaq 0:6c56fb4bc5f0 37 * Specification v4.0, Vol. 3, Part C, Sections 11 and 18).
nexpaq 0:6c56fb4bc5f0 38 *
nexpaq 0:6c56fb4bc5f0 39 * @par
nexpaq 0:6c56fb4bc5f0 40 * Each AD type has its own standardized assigned number, as defined
nexpaq 0:6c56fb4bc5f0 41 * by the Bluetooth SIG:
nexpaq 0:6c56fb4bc5f0 42 * https://www.bluetooth.org/en-us/specification/assigned-numbers/generic-access-profile.
nexpaq 0:6c56fb4bc5f0 43 *
nexpaq 0:6c56fb4bc5f0 44 * @par
nexpaq 0:6c56fb4bc5f0 45 * For convenience, all appropriate AD types are encapsulated
nexpaq 0:6c56fb4bc5f0 46 * in GapAdvertisingData::DataType.
nexpaq 0:6c56fb4bc5f0 47 *
nexpaq 0:6c56fb4bc5f0 48 * @par
nexpaq 0:6c56fb4bc5f0 49 * Before the AD Types and their payload (if any) can be inserted into
nexpaq 0:6c56fb4bc5f0 50 * the Advertising or Scan Response frames, they need to be formatted as
nexpaq 0:6c56fb4bc5f0 51 * follows:
nexpaq 0:6c56fb4bc5f0 52 *
nexpaq 0:6c56fb4bc5f0 53 * @li @c Record length (1 byte).
nexpaq 0:6c56fb4bc5f0 54 * @li @c AD Type (1 byte).
nexpaq 0:6c56fb4bc5f0 55 * @li @c AD payload (optional; only present if record length > 1).
nexpaq 0:6c56fb4bc5f0 56 *
nexpaq 0:6c56fb4bc5f0 57 * @par
nexpaq 0:6c56fb4bc5f0 58 * This class takes care of properly formatting the payload, performs
nexpaq 0:6c56fb4bc5f0 59 * some basic checks on the payload length, and tries to avoid common
nexpaq 0:6c56fb4bc5f0 60 * errors like adding an exclusive AD field twice in the Advertising
nexpaq 0:6c56fb4bc5f0 61 * or Scan Response payload.
nexpaq 0:6c56fb4bc5f0 62 *
nexpaq 0:6c56fb4bc5f0 63 * @par EXAMPLE
nexpaq 0:6c56fb4bc5f0 64 *
nexpaq 0:6c56fb4bc5f0 65 * @code
nexpaq 0:6c56fb4bc5f0 66 *
nexpaq 0:6c56fb4bc5f0 67 * // ToDo
nexpaq 0:6c56fb4bc5f0 68 *
nexpaq 0:6c56fb4bc5f0 69 * @endcode
nexpaq 0:6c56fb4bc5f0 70 */
nexpaq 0:6c56fb4bc5f0 71 class GapAdvertisingData
nexpaq 0:6c56fb4bc5f0 72 {
nexpaq 0:6c56fb4bc5f0 73 public:
nexpaq 0:6c56fb4bc5f0 74 /*!
nexpaq 0:6c56fb4bc5f0 75 * @brief A list of Advertising Data types commonly used by peripherals.
nexpaq 0:6c56fb4bc5f0 76 * These AD types are used to describe the capabilities of the
nexpaq 0:6c56fb4bc5f0 77 * peripheral, and are inserted inside the advertising or scan
nexpaq 0:6c56fb4bc5f0 78 * response payloads.
nexpaq 0:6c56fb4bc5f0 79 *
nexpaq 0:6c56fb4bc5f0 80 * @par Source
nexpaq 0:6c56fb4bc5f0 81 *
nexpaq 0:6c56fb4bc5f0 82 * @li @c Bluetooth Core Specification 4.0 (Vol. 3), Part C, Section 11, 18.
nexpaq 0:6c56fb4bc5f0 83 * @li @c https://www.bluetooth.org/en-us/specification/assigned-numbers/generic-access-profile.
nexpaq 0:6c56fb4bc5f0 84 */
nexpaq 0:6c56fb4bc5f0 85 enum DataType_t {
nexpaq 0:6c56fb4bc5f0 86 FLAGS = 0x01, /**< Flags, refer to GapAdvertisingData::Flags_t. */
nexpaq 0:6c56fb4bc5f0 87 INCOMPLETE_LIST_16BIT_SERVICE_IDS = 0x02, /**< Incomplete list of 16-bit Service IDs. */
nexpaq 0:6c56fb4bc5f0 88 COMPLETE_LIST_16BIT_SERVICE_IDS = 0x03, /**< Complete list of 16-bit Service IDs. */
nexpaq 0:6c56fb4bc5f0 89 INCOMPLETE_LIST_32BIT_SERVICE_IDS = 0x04, /**< Incomplete list of 32-bit Service IDs (not relevant for Bluetooth 4.0). */
nexpaq 0:6c56fb4bc5f0 90 COMPLETE_LIST_32BIT_SERVICE_IDS = 0x05, /**< Complete list of 32-bit Service IDs (not relevant for Bluetooth 4.0). */
nexpaq 0:6c56fb4bc5f0 91 INCOMPLETE_LIST_128BIT_SERVICE_IDS = 0x06, /**< Incomplete list of 128-bit Service IDs. */
nexpaq 0:6c56fb4bc5f0 92 COMPLETE_LIST_128BIT_SERVICE_IDS = 0x07, /**< Complete list of 128-bit Service IDs. */
nexpaq 0:6c56fb4bc5f0 93 SHORTENED_LOCAL_NAME = 0x08, /**< Shortened Local Name. */
nexpaq 0:6c56fb4bc5f0 94 COMPLETE_LOCAL_NAME = 0x09, /**< Complete Local Name. */
nexpaq 0:6c56fb4bc5f0 95 TX_POWER_LEVEL = 0x0A, /**< TX Power Level (in dBm). */
nexpaq 0:6c56fb4bc5f0 96 DEVICE_ID = 0x10, /**< Device ID. */
nexpaq 0:6c56fb4bc5f0 97 SLAVE_CONNECTION_INTERVAL_RANGE = 0x12, /**< Slave Connection Interval Range. */
nexpaq 0:6c56fb4bc5f0 98 LIST_128BIT_SOLICITATION_IDS = 0x15, /**< List of 128 bit service UUIDs the device is looking for. */
nexpaq 0:6c56fb4bc5f0 99 SERVICE_DATA = 0x16, /**< Service Data. */
nexpaq 0:6c56fb4bc5f0 100 APPEARANCE = 0x19, /**< Appearance, refer to GapAdvertisingData::Appearance_t. */
nexpaq 0:6c56fb4bc5f0 101 ADVERTISING_INTERVAL = 0x1A, /**< Advertising Interval. */
nexpaq 0:6c56fb4bc5f0 102 MANUFACTURER_SPECIFIC_DATA = 0xFF /**< Manufacturer Specific Data. */
nexpaq 0:6c56fb4bc5f0 103 };
nexpaq 0:6c56fb4bc5f0 104 /**
nexpaq 0:6c56fb4bc5f0 105 * Type alias for GapAdvertisingData::DataType_t.
nexpaq 0:6c56fb4bc5f0 106 *
nexpaq 0:6c56fb4bc5f0 107 * @deprecated This type alias will be dropped in future releases.
nexpaq 0:6c56fb4bc5f0 108 */
nexpaq 0:6c56fb4bc5f0 109 typedef enum DataType_t DataType;
nexpaq 0:6c56fb4bc5f0 110
nexpaq 0:6c56fb4bc5f0 111 /**
nexpaq 0:6c56fb4bc5f0 112 * @brief A list of values for the FLAGS AD Type.
nexpaq 0:6c56fb4bc5f0 113 *
nexpaq 0:6c56fb4bc5f0 114 * @note You can use more than one value in the FLAGS AD Type (ex.
nexpaq 0:6c56fb4bc5f0 115 * LE_GENERAL_DISCOVERABLE and BREDR_NOT_SUPPORTED).
nexpaq 0:6c56fb4bc5f0 116 *
nexpaq 0:6c56fb4bc5f0 117 * @par Source
nexpaq 0:6c56fb4bc5f0 118 *
nexpaq 0:6c56fb4bc5f0 119 * @li @c Bluetooth Core Specification 4.0 (Vol. 3), Part C, Section 18.1.
nexpaq 0:6c56fb4bc5f0 120 */
nexpaq 0:6c56fb4bc5f0 121 enum Flags_t {
nexpaq 0:6c56fb4bc5f0 122 LE_LIMITED_DISCOVERABLE = 0x01, /**< Peripheral device is discoverable for a limited period of time. */
nexpaq 0:6c56fb4bc5f0 123 LE_GENERAL_DISCOVERABLE = 0x02, /**< Peripheral device is discoverable at any moment. */
nexpaq 0:6c56fb4bc5f0 124 BREDR_NOT_SUPPORTED = 0x04, /**< Peripheral device is LE only. */
nexpaq 0:6c56fb4bc5f0 125 SIMULTANEOUS_LE_BREDR_C = 0x08, /**< Not relevant - central mode only. */
nexpaq 0:6c56fb4bc5f0 126 SIMULTANEOUS_LE_BREDR_H = 0x10 /**< Not relevant - central mode only. */
nexpaq 0:6c56fb4bc5f0 127 };
nexpaq 0:6c56fb4bc5f0 128 /**
nexpaq 0:6c56fb4bc5f0 129 * Type alias for GapAdvertisingData::Flags_t.
nexpaq 0:6c56fb4bc5f0 130 *
nexpaq 0:6c56fb4bc5f0 131 * @deprecated This type alias will be dropped in future releases.
nexpaq 0:6c56fb4bc5f0 132 */
nexpaq 0:6c56fb4bc5f0 133 typedef enum Flags_t Flags;
nexpaq 0:6c56fb4bc5f0 134
nexpaq 0:6c56fb4bc5f0 135 /**
nexpaq 0:6c56fb4bc5f0 136 * @brief
nexpaq 0:6c56fb4bc5f0 137 * A list of values for the APPEARANCE AD Type, which describes the
nexpaq 0:6c56fb4bc5f0 138 * physical shape or appearance of the device.
nexpaq 0:6c56fb4bc5f0 139 *
nexpaq 0:6c56fb4bc5f0 140 * @par Source
nexpaq 0:6c56fb4bc5f0 141 *
nexpaq 0:6c56fb4bc5f0 142 * @li @c Bluetooth Core Specification Supplement, Part A, Section 1.12.
nexpaq 0:6c56fb4bc5f0 143 * @li @c Bluetooth Core Specification 4.0 (Vol. 3), Part C, Section 12.2.
nexpaq 0:6c56fb4bc5f0 144 * @li @c https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.gap.appearance.xml.
nexpaq 0:6c56fb4bc5f0 145 */
nexpaq 0:6c56fb4bc5f0 146 enum Appearance_t {
nexpaq 0:6c56fb4bc5f0 147 UNKNOWN = 0, /**< Unknown or unspecified appearance type. */
nexpaq 0:6c56fb4bc5f0 148 GENERIC_PHONE = 64, /**< Generic Phone. */
nexpaq 0:6c56fb4bc5f0 149 GENERIC_COMPUTER = 128, /**< Generic Computer. */
nexpaq 0:6c56fb4bc5f0 150 GENERIC_WATCH = 192, /**< Generic Watch. */
nexpaq 0:6c56fb4bc5f0 151 WATCH_SPORTS_WATCH = 193, /**< Sports Watch. */
nexpaq 0:6c56fb4bc5f0 152 GENERIC_CLOCK = 256, /**< Generic Clock. */
nexpaq 0:6c56fb4bc5f0 153 GENERIC_DISPLAY = 320, /**< Generic Display. */
nexpaq 0:6c56fb4bc5f0 154 GENERIC_REMOTE_CONTROL = 384, /**< Generic Remote Control. */
nexpaq 0:6c56fb4bc5f0 155 GENERIC_EYE_GLASSES = 448, /**< Generic Eye Glasses. */
nexpaq 0:6c56fb4bc5f0 156 GENERIC_TAG = 512, /**< Generic Tag. */
nexpaq 0:6c56fb4bc5f0 157 GENERIC_KEYRING = 576, /**< Generic Keyring. */
nexpaq 0:6c56fb4bc5f0 158 GENERIC_MEDIA_PLAYER = 640, /**< Generic Media Player. */
nexpaq 0:6c56fb4bc5f0 159 GENERIC_BARCODE_SCANNER = 704, /**< Generic Barcode Scanner. */
nexpaq 0:6c56fb4bc5f0 160 GENERIC_THERMOMETER = 768, /**< Generic Thermometer. */
nexpaq 0:6c56fb4bc5f0 161 THERMOMETER_EAR = 769, /**< Ear Thermometer. */
nexpaq 0:6c56fb4bc5f0 162 GENERIC_HEART_RATE_SENSOR = 832, /**< Generic Heart Rate Sensor. */
nexpaq 0:6c56fb4bc5f0 163 HEART_RATE_SENSOR_HEART_RATE_BELT = 833, /**< Belt Heart Rate Sensor. */
nexpaq 0:6c56fb4bc5f0 164 GENERIC_BLOOD_PRESSURE = 896, /**< Generic Blood Pressure. */
nexpaq 0:6c56fb4bc5f0 165 BLOOD_PRESSURE_ARM = 897, /**< Arm Blood Pressure. */
nexpaq 0:6c56fb4bc5f0 166 BLOOD_PRESSURE_WRIST = 898, /**< Wrist Blood Pressure. */
nexpaq 0:6c56fb4bc5f0 167 HUMAN_INTERFACE_DEVICE_HID = 960, /**< Human Interface Device (HID). */
nexpaq 0:6c56fb4bc5f0 168 KEYBOARD = 961, /**< Keyboard. */
nexpaq 0:6c56fb4bc5f0 169 MOUSE = 962, /**< Mouse. */
nexpaq 0:6c56fb4bc5f0 170 JOYSTICK = 963, /**< Joystick. */
nexpaq 0:6c56fb4bc5f0 171 GAMEPAD = 964, /**< Gamepad. */
nexpaq 0:6c56fb4bc5f0 172 DIGITIZER_TABLET = 965, /**< Digitizer Tablet. */
nexpaq 0:6c56fb4bc5f0 173 CARD_READER = 966, /**< Card Reader. */
nexpaq 0:6c56fb4bc5f0 174 DIGITAL_PEN = 967, /**< Digital Pen. */
nexpaq 0:6c56fb4bc5f0 175 BARCODE_SCANNER = 968, /**< Barcode Scanner. */
nexpaq 0:6c56fb4bc5f0 176 GENERIC_GLUCOSE_METER = 1024, /**< Generic Glucose Meter. */
nexpaq 0:6c56fb4bc5f0 177 GENERIC_RUNNING_WALKING_SENSOR = 1088, /**< Generic Running/Walking Sensor. */
nexpaq 0:6c56fb4bc5f0 178 RUNNING_WALKING_SENSOR_IN_SHOE = 1089, /**< In Shoe Running/Walking Sensor. */
nexpaq 0:6c56fb4bc5f0 179 RUNNING_WALKING_SENSOR_ON_SHOE = 1090, /**< On Shoe Running/Walking Sensor. */
nexpaq 0:6c56fb4bc5f0 180 RUNNING_WALKING_SENSOR_ON_HIP = 1091, /**< On Hip Running/Walking Sensor. */
nexpaq 0:6c56fb4bc5f0 181 GENERIC_CYCLING = 1152, /**< Generic Cycling. */
nexpaq 0:6c56fb4bc5f0 182 CYCLING_CYCLING_COMPUTER = 1153, /**< Cycling Computer. */
nexpaq 0:6c56fb4bc5f0 183 CYCLING_SPEED_SENSOR = 1154, /**< Cycling Speed Sensor. */
nexpaq 0:6c56fb4bc5f0 184 CYCLING_CADENCE_SENSOR = 1155, /**< Cycling Cadence Sensor. */
nexpaq 0:6c56fb4bc5f0 185 CYCLING_POWER_SENSOR = 1156, /**< Cycling Power Sensor. */
nexpaq 0:6c56fb4bc5f0 186 CYCLING_SPEED_AND_CADENCE_SENSOR = 1157, /**< Cycling Speed and Cadence Sensor. */
nexpaq 0:6c56fb4bc5f0 187 PULSE_OXIMETER_GENERIC = 3136, /**< Generic Pulse Oximeter. */
nexpaq 0:6c56fb4bc5f0 188 PULSE_OXIMETER_FINGERTIP = 3137, /**< Fingertip Pulse Oximeter. */
nexpaq 0:6c56fb4bc5f0 189 PULSE_OXIMETER_WRIST_WORN = 3138, /**< Wrist Worn Pulse Oximeter. */
nexpaq 0:6c56fb4bc5f0 190 GENERIC_WEIGHT_SCALE = 3200, /**< Generic Weight Scale. */
nexpaq 0:6c56fb4bc5f0 191 OUTDOOR_GENERIC = 5184, /**< Generic Outdoor. */
nexpaq 0:6c56fb4bc5f0 192 OUTDOOR_LOCATION_DISPLAY_DEVICE = 5185, /**< Outdoor Location Display Device. */
nexpaq 0:6c56fb4bc5f0 193 OUTDOOR_LOCATION_AND_NAVIGATION_DISPLAY_DEVICE = 5186, /**< Outdoor Location and Navigation Display Device. */
nexpaq 0:6c56fb4bc5f0 194 OUTDOOR_LOCATION_POD = 5187, /**< Outdoor Location Pod. */
nexpaq 0:6c56fb4bc5f0 195 OUTDOOR_LOCATION_AND_NAVIGATION_POD = 5188 /**< Outdoor Location and Navigation Pod. */
nexpaq 0:6c56fb4bc5f0 196 };
nexpaq 0:6c56fb4bc5f0 197 /**
nexpaq 0:6c56fb4bc5f0 198 * Type alias for GapAdvertisingData::Appearance_t.
nexpaq 0:6c56fb4bc5f0 199 *
nexpaq 0:6c56fb4bc5f0 200 * @deprecated This type alias will be dropped in future releases.
nexpaq 0:6c56fb4bc5f0 201 */
nexpaq 0:6c56fb4bc5f0 202 typedef enum Appearance_t Appearance;
nexpaq 0:6c56fb4bc5f0 203
nexpaq 0:6c56fb4bc5f0 204 /**
nexpaq 0:6c56fb4bc5f0 205 * Empty constructor.
nexpaq 0:6c56fb4bc5f0 206 */
nexpaq 0:6c56fb4bc5f0 207 GapAdvertisingData(void) : _payload(), _payloadLen(0), _appearance(GENERIC_TAG) {
nexpaq 0:6c56fb4bc5f0 208 /* empty */
nexpaq 0:6c56fb4bc5f0 209 }
nexpaq 0:6c56fb4bc5f0 210
nexpaq 0:6c56fb4bc5f0 211 /**
nexpaq 0:6c56fb4bc5f0 212 * Adds advertising data based on the specified AD type (see GapAdvertisingData::DataType_t).
nexpaq 0:6c56fb4bc5f0 213 * If the supplied AD type is already present in the advertising
nexpaq 0:6c56fb4bc5f0 214 * payload, then the value is updated.
nexpaq 0:6c56fb4bc5f0 215 *
nexpaq 0:6c56fb4bc5f0 216 * @param[in] advDataType The Advertising 'DataType' to add.
nexpaq 0:6c56fb4bc5f0 217 * @param[in] payload Pointer to the payload contents.
nexpaq 0:6c56fb4bc5f0 218 * @param[in] len Size of the payload in bytes.
nexpaq 0:6c56fb4bc5f0 219 *
nexpaq 0:6c56fb4bc5f0 220 * @return BLE_ERROR_BUFFER_OVERFLOW if the new value causes the
nexpaq 0:6c56fb4bc5f0 221 * advertising buffer to overflow. BLE_ERROR_NONE is returned
nexpaq 0:6c56fb4bc5f0 222 * on success.
nexpaq 0:6c56fb4bc5f0 223 *
nexpaq 0:6c56fb4bc5f0 224 * @note When the specified AD type is INCOMPLETE_LIST_16BIT_SERVICE_IDS,
nexpaq 0:6c56fb4bc5f0 225 * COMPLETE_LIST_16BIT_SERVICE_IDS, INCOMPLETE_LIST_32BIT_SERVICE_IDS,
nexpaq 0:6c56fb4bc5f0 226 * COMPLETE_LIST_32BIT_SERVICE_IDS, INCOMPLETE_LIST_128BIT_SERVICE_IDS,
nexpaq 0:6c56fb4bc5f0 227 * COMPLETE_LIST_128BIT_SERVICE_IDS or LIST_128BIT_SOLICITATION_IDS the
nexpaq 0:6c56fb4bc5f0 228 * supplied value is appended to the values previously added to the
nexpaq 0:6c56fb4bc5f0 229 * payload.
nexpaq 0:6c56fb4bc5f0 230 */
nexpaq 0:6c56fb4bc5f0 231 ble_error_t addData(DataType_t advDataType, const uint8_t *payload, uint8_t len)
nexpaq 0:6c56fb4bc5f0 232 {
nexpaq 0:6c56fb4bc5f0 233 /* Find field */
nexpaq 0:6c56fb4bc5f0 234 uint8_t* field = findField(advDataType);
nexpaq 0:6c56fb4bc5f0 235
nexpaq 0:6c56fb4bc5f0 236 if (field) {
nexpaq 0:6c56fb4bc5f0 237 /* Field type already exist, either add to field or replace */
nexpaq 0:6c56fb4bc5f0 238 return addField(advDataType, payload, len, field);
nexpaq 0:6c56fb4bc5f0 239 } else {
nexpaq 0:6c56fb4bc5f0 240 /* Field doesn't exists, insert new */
nexpaq 0:6c56fb4bc5f0 241 return appendField(advDataType, payload, len);
nexpaq 0:6c56fb4bc5f0 242 }
nexpaq 0:6c56fb4bc5f0 243 }
nexpaq 0:6c56fb4bc5f0 244
nexpaq 0:6c56fb4bc5f0 245 /**
nexpaq 0:6c56fb4bc5f0 246 * Update a particular ADV field in the advertising payload (based on
nexpaq 0:6c56fb4bc5f0 247 * matching type).
nexpaq 0:6c56fb4bc5f0 248 *
nexpaq 0:6c56fb4bc5f0 249 * @param[in] advDataType The Advertising 'DataType' to add.
nexpaq 0:6c56fb4bc5f0 250 * @param[in] payload Pointer to the payload contents.
nexpaq 0:6c56fb4bc5f0 251 * @param[in] len Size of the payload in bytes.
nexpaq 0:6c56fb4bc5f0 252 *
nexpaq 0:6c56fb4bc5f0 253 * @return BLE_ERROR_UNSPECIFIED if the specified field is not found,
nexpaq 0:6c56fb4bc5f0 254 * BLE_ERROR_BUFFER_OVERFLOW if the new value causes the
nexpaq 0:6c56fb4bc5f0 255 * advertising buffer to overflow. BLE_ERROR_NONE is returned
nexpaq 0:6c56fb4bc5f0 256 * on success.
nexpaq 0:6c56fb4bc5f0 257 */
nexpaq 0:6c56fb4bc5f0 258 ble_error_t updateData(DataType_t advDataType, const uint8_t *payload, uint8_t len)
nexpaq 0:6c56fb4bc5f0 259 {
nexpaq 0:6c56fb4bc5f0 260 /* Find field */
nexpaq 0:6c56fb4bc5f0 261 uint8_t* field = findField(advDataType);
nexpaq 0:6c56fb4bc5f0 262
nexpaq 0:6c56fb4bc5f0 263 if (field) {
nexpaq 0:6c56fb4bc5f0 264 /* Field type already exist, replace field contents */
nexpaq 0:6c56fb4bc5f0 265 return updateField(advDataType, payload, len, field);
nexpaq 0:6c56fb4bc5f0 266 } else {
nexpaq 0:6c56fb4bc5f0 267 /* field doesn't exists, return an error */
nexpaq 0:6c56fb4bc5f0 268 return BLE_ERROR_UNSPECIFIED;
nexpaq 0:6c56fb4bc5f0 269 }
nexpaq 0:6c56fb4bc5f0 270 }
nexpaq 0:6c56fb4bc5f0 271
nexpaq 0:6c56fb4bc5f0 272 /**
nexpaq 0:6c56fb4bc5f0 273 * Helper function to add APPEARANCE data to the advertising payload.
nexpaq 0:6c56fb4bc5f0 274 *
nexpaq 0:6c56fb4bc5f0 275 * @param appearance
nexpaq 0:6c56fb4bc5f0 276 * The APPEARANCE value to add.
nexpaq 0:6c56fb4bc5f0 277 *
nexpaq 0:6c56fb4bc5f0 278 * @return BLE_ERROR_BUFFER_OVERFLOW if the specified data would cause the
nexpaq 0:6c56fb4bc5f0 279 * advertising buffer to overflow, else BLE_ERROR_NONE.
nexpaq 0:6c56fb4bc5f0 280 */
nexpaq 0:6c56fb4bc5f0 281 ble_error_t addAppearance(Appearance appearance = GENERIC_TAG) {
nexpaq 0:6c56fb4bc5f0 282 _appearance = appearance;
nexpaq 0:6c56fb4bc5f0 283 return addData(GapAdvertisingData::APPEARANCE, (uint8_t *)&appearance, 2);
nexpaq 0:6c56fb4bc5f0 284 }
nexpaq 0:6c56fb4bc5f0 285
nexpaq 0:6c56fb4bc5f0 286 /**
nexpaq 0:6c56fb4bc5f0 287 * Helper function to add FLAGS data to the advertising payload.
nexpaq 0:6c56fb4bc5f0 288 *
nexpaq 0:6c56fb4bc5f0 289 * @param[in] flags
nexpaq 0:6c56fb4bc5f0 290 * LE_LIMITED_DISCOVERABLE
nexpaq 0:6c56fb4bc5f0 291 * The peripheral is discoverable for a limited period of time.
nexpaq 0:6c56fb4bc5f0 292 * LE_GENERAL_DISCOVERABLE
nexpaq 0:6c56fb4bc5f0 293 * The peripheral is permanently discoverable.
nexpaq 0:6c56fb4bc5f0 294 * BREDR_NOT_SUPPORTED
nexpaq 0:6c56fb4bc5f0 295 * This peripheral is a Bluetooth Low Energy only device (no EDR support).
nexpaq 0:6c56fb4bc5f0 296 *
nexpaq 0:6c56fb4bc5f0 297 * @return BLE_ERROR_BUFFER_OVERFLOW if the specified data would cause the
nexpaq 0:6c56fb4bc5f0 298 * advertising buffer to overflow, else BLE_ERROR_NONE.
nexpaq 0:6c56fb4bc5f0 299 */
nexpaq 0:6c56fb4bc5f0 300 ble_error_t addFlags(uint8_t flags = LE_GENERAL_DISCOVERABLE) {
nexpaq 0:6c56fb4bc5f0 301 return addData(GapAdvertisingData::FLAGS, &flags, 1);
nexpaq 0:6c56fb4bc5f0 302 }
nexpaq 0:6c56fb4bc5f0 303
nexpaq 0:6c56fb4bc5f0 304 /**
nexpaq 0:6c56fb4bc5f0 305 * Helper function to add TX_POWER_LEVEL data to the advertising payload.
nexpaq 0:6c56fb4bc5f0 306 *
nexpaq 0:6c56fb4bc5f0 307 * @return BLE_ERROR_BUFFER_OVERFLOW if the specified data would cause the
nexpaq 0:6c56fb4bc5f0 308 * advertising buffer to overflow, else BLE_ERROR_NONE.
nexpaq 0:6c56fb4bc5f0 309 */
nexpaq 0:6c56fb4bc5f0 310 ble_error_t addTxPower(int8_t txPower) {
nexpaq 0:6c56fb4bc5f0 311 /* To Do: Basic error checking to make sure txPower is in range. */
nexpaq 0:6c56fb4bc5f0 312 return addData(GapAdvertisingData::TX_POWER_LEVEL, (uint8_t *)&txPower, 1);
nexpaq 0:6c56fb4bc5f0 313 }
nexpaq 0:6c56fb4bc5f0 314
nexpaq 0:6c56fb4bc5f0 315 /**
nexpaq 0:6c56fb4bc5f0 316 * Clears the payload and resets the payload length counter.
nexpaq 0:6c56fb4bc5f0 317 */
nexpaq 0:6c56fb4bc5f0 318 void clear(void) {
nexpaq 0:6c56fb4bc5f0 319 memset(&_payload, 0, GAP_ADVERTISING_DATA_MAX_PAYLOAD);
nexpaq 0:6c56fb4bc5f0 320 _payloadLen = 0;
nexpaq 0:6c56fb4bc5f0 321 }
nexpaq 0:6c56fb4bc5f0 322
nexpaq 0:6c56fb4bc5f0 323 /**
nexpaq 0:6c56fb4bc5f0 324 * Access the current payload.
nexpaq 0:6c56fb4bc5f0 325 *
nexpaq 0:6c56fb4bc5f0 326 * @return A pointer to the current payload.
nexpaq 0:6c56fb4bc5f0 327 */
nexpaq 0:6c56fb4bc5f0 328 const uint8_t *getPayload(void) const {
nexpaq 0:6c56fb4bc5f0 329 return _payload;
nexpaq 0:6c56fb4bc5f0 330 }
nexpaq 0:6c56fb4bc5f0 331
nexpaq 0:6c56fb4bc5f0 332 /**
nexpaq 0:6c56fb4bc5f0 333 * Get the current payload length.
nexpaq 0:6c56fb4bc5f0 334 *
nexpaq 0:6c56fb4bc5f0 335 * @return The current payload length (0..31 bytes).
nexpaq 0:6c56fb4bc5f0 336 */
nexpaq 0:6c56fb4bc5f0 337 uint8_t getPayloadLen(void) const {
nexpaq 0:6c56fb4bc5f0 338 return _payloadLen;
nexpaq 0:6c56fb4bc5f0 339 }
nexpaq 0:6c56fb4bc5f0 340
nexpaq 0:6c56fb4bc5f0 341 /**
nexpaq 0:6c56fb4bc5f0 342 * Get the current appearance value.
nexpaq 0:6c56fb4bc5f0 343 *
nexpaq 0:6c56fb4bc5f0 344 * @return The 16-bit appearance value for this device.
nexpaq 0:6c56fb4bc5f0 345 */
nexpaq 0:6c56fb4bc5f0 346 uint16_t getAppearance(void) const {
nexpaq 0:6c56fb4bc5f0 347 return (uint16_t)_appearance;
nexpaq 0:6c56fb4bc5f0 348 }
nexpaq 0:6c56fb4bc5f0 349
nexpaq 0:6c56fb4bc5f0 350 /**
nexpaq 0:6c56fb4bc5f0 351 * Search advertisement data for a specific field.
nexpaq 0:6c56fb4bc5f0 352 *
nexpaq 0:6c56fb4bc5f0 353 * @param[in] type
nexpaq 0:6c56fb4bc5f0 354 * The type of the field to find.
nexpaq 0:6c56fb4bc5f0 355 *
nexpaq 0:6c56fb4bc5f0 356 * @return A pointer to the first element in the field if found, NULL otherwise.
nexpaq 0:6c56fb4bc5f0 357 * Where the first element is the length of the field.
nexpaq 0:6c56fb4bc5f0 358 */
nexpaq 0:6c56fb4bc5f0 359 const uint8_t* findField(DataType_t type) const {
nexpaq 0:6c56fb4bc5f0 360 return findField(type);
nexpaq 0:6c56fb4bc5f0 361 }
nexpaq 0:6c56fb4bc5f0 362
nexpaq 0:6c56fb4bc5f0 363 private:
nexpaq 0:6c56fb4bc5f0 364 /**
nexpaq 0:6c56fb4bc5f0 365 * Append advertising data based on the specified AD type (see
nexpaq 0:6c56fb4bc5f0 366 * GapAdvertisingData::DataType_t).
nexpaq 0:6c56fb4bc5f0 367 *
nexpaq 0:6c56fb4bc5f0 368 * @param[in] advDataType
nexpaq 0:6c56fb4bc5f0 369 * The type of the new data.
nexpaq 0:6c56fb4bc5f0 370 * @param[in] payload
nexpaq 0:6c56fb4bc5f0 371 * A pointer to the data to be appended to the advertising
nexpaq 0:6c56fb4bc5f0 372 * payload.
nexpaq 0:6c56fb4bc5f0 373 * @param[in] len
nexpaq 0:6c56fb4bc5f0 374 * The length of th data pointed to by @p payload.
nexpaq 0:6c56fb4bc5f0 375 *
nexpaq 0:6c56fb4bc5f0 376 * @return BLE_ERROR_BUFFER_OVERFLOW if the specified data would cause the
nexpaq 0:6c56fb4bc5f0 377 * advertising buffer to overflow, else BLE_ERROR_NONE.
nexpaq 0:6c56fb4bc5f0 378 */
nexpaq 0:6c56fb4bc5f0 379 ble_error_t appendField(DataType advDataType, const uint8_t *payload, uint8_t len)
nexpaq 0:6c56fb4bc5f0 380 {
nexpaq 0:6c56fb4bc5f0 381 /* Make sure we don't exceed the 31 byte payload limit */
nexpaq 0:6c56fb4bc5f0 382 if (_payloadLen + len + 2 > GAP_ADVERTISING_DATA_MAX_PAYLOAD) {
nexpaq 0:6c56fb4bc5f0 383 return BLE_ERROR_BUFFER_OVERFLOW;
nexpaq 0:6c56fb4bc5f0 384 }
nexpaq 0:6c56fb4bc5f0 385
nexpaq 0:6c56fb4bc5f0 386 /* Field length. */
nexpaq 0:6c56fb4bc5f0 387 memset(&_payload[_payloadLen], len + 1, 1);
nexpaq 0:6c56fb4bc5f0 388 _payloadLen++;
nexpaq 0:6c56fb4bc5f0 389
nexpaq 0:6c56fb4bc5f0 390 /* Field ID. */
nexpaq 0:6c56fb4bc5f0 391 memset(&_payload[_payloadLen], (uint8_t)advDataType, 1);
nexpaq 0:6c56fb4bc5f0 392 _payloadLen++;
nexpaq 0:6c56fb4bc5f0 393
nexpaq 0:6c56fb4bc5f0 394 /* Payload. */
nexpaq 0:6c56fb4bc5f0 395 memcpy(&_payload[_payloadLen], payload, len);
nexpaq 0:6c56fb4bc5f0 396 _payloadLen += len;
nexpaq 0:6c56fb4bc5f0 397
nexpaq 0:6c56fb4bc5f0 398 return BLE_ERROR_NONE;
nexpaq 0:6c56fb4bc5f0 399 }
nexpaq 0:6c56fb4bc5f0 400
nexpaq 0:6c56fb4bc5f0 401 /**
nexpaq 0:6c56fb4bc5f0 402 * Search advertisement data for field.
nexpaq 0:6c56fb4bc5f0 403 *
nexpaq 0:6c56fb4bc5f0 404 * @param[in] type
nexpaq 0:6c56fb4bc5f0 405 * The type of the data to find.
nexpaq 0:6c56fb4bc5f0 406 *
nexpaq 0:6c56fb4bc5f0 407 * @return A pointer to the first element in the field if found, NULL
nexpaq 0:6c56fb4bc5f0 408 * otherwise. Where the first element is the length of the field.
nexpaq 0:6c56fb4bc5f0 409 */
nexpaq 0:6c56fb4bc5f0 410 uint8_t* findField(DataType_t type) {
nexpaq 0:6c56fb4bc5f0 411 /* Scan through advertisement data */
nexpaq 0:6c56fb4bc5f0 412 for (uint8_t idx = 0; idx < _payloadLen; ) {
nexpaq 0:6c56fb4bc5f0 413 uint8_t fieldType = _payload[idx + 1];
nexpaq 0:6c56fb4bc5f0 414
nexpaq 0:6c56fb4bc5f0 415 if (fieldType == type) {
nexpaq 0:6c56fb4bc5f0 416 return &_payload[idx];
nexpaq 0:6c56fb4bc5f0 417 }
nexpaq 0:6c56fb4bc5f0 418
nexpaq 0:6c56fb4bc5f0 419 /* Advance to next field */
nexpaq 0:6c56fb4bc5f0 420 idx += _payload[idx] + 1;
nexpaq 0:6c56fb4bc5f0 421 }
nexpaq 0:6c56fb4bc5f0 422
nexpaq 0:6c56fb4bc5f0 423 /* Field not found */
nexpaq 0:6c56fb4bc5f0 424 return NULL;
nexpaq 0:6c56fb4bc5f0 425 }
nexpaq 0:6c56fb4bc5f0 426
nexpaq 0:6c56fb4bc5f0 427 /**
nexpaq 0:6c56fb4bc5f0 428 * Given the a pointer to a field in the advertising payload it replaces
nexpaq 0:6c56fb4bc5f0 429 * the existing data in the field with the supplied data.
nexpaq 0:6c56fb4bc5f0 430 *
nexpaq 0:6c56fb4bc5f0 431 * @param[in] advDataType
nexpaq 0:6c56fb4bc5f0 432 * The type of the new data.
nexpaq 0:6c56fb4bc5f0 433 * @param[in] payload
nexpaq 0:6c56fb4bc5f0 434 * A pointer to the data to be added to the advertising
nexpaq 0:6c56fb4bc5f0 435 * payload.
nexpaq 0:6c56fb4bc5f0 436 * @param[in] len
nexpaq 0:6c56fb4bc5f0 437 * The length of th data pointed to by @p payload.
nexpaq 0:6c56fb4bc5f0 438 * @param[in] field
nexpaq 0:6c56fb4bc5f0 439 * A pointer to the field of type @p advDataType in the
nexpaq 0:6c56fb4bc5f0 440 * advertising buffer.
nexpaq 0:6c56fb4bc5f0 441 *
nexpaq 0:6c56fb4bc5f0 442 * When the specified AD type is INCOMPLETE_LIST_16BIT_SERVICE_IDS,
nexpaq 0:6c56fb4bc5f0 443 * COMPLETE_LIST_16BIT_SERVICE_IDS, INCOMPLETE_LIST_32BIT_SERVICE_IDS,
nexpaq 0:6c56fb4bc5f0 444 * COMPLETE_LIST_32BIT_SERVICE_IDS, INCOMPLETE_LIST_128BIT_SERVICE_IDS,
nexpaq 0:6c56fb4bc5f0 445 * COMPLETE_LIST_128BIT_SERVICE_IDS or LIST_128BIT_SOLICITATION_IDS the
nexpaq 0:6c56fb4bc5f0 446 * supplied value is appended to the values previously added to the
nexpaq 0:6c56fb4bc5f0 447 * payload.
nexpaq 0:6c56fb4bc5f0 448 *
nexpaq 0:6c56fb4bc5f0 449 * @return BLE_ERROR_NONE on success.
nexpaq 0:6c56fb4bc5f0 450 */
nexpaq 0:6c56fb4bc5f0 451 ble_error_t addField(DataType_t advDataType, const uint8_t *payload, uint8_t len, uint8_t* field)
nexpaq 0:6c56fb4bc5f0 452 {
nexpaq 0:6c56fb4bc5f0 453 ble_error_t result = BLE_ERROR_BUFFER_OVERFLOW;
nexpaq 0:6c56fb4bc5f0 454
nexpaq 0:6c56fb4bc5f0 455 switch(advDataType) {
nexpaq 0:6c56fb4bc5f0 456 /* These fields will have the new data appended if there is sufficient space */
nexpaq 0:6c56fb4bc5f0 457 case INCOMPLETE_LIST_16BIT_SERVICE_IDS:
nexpaq 0:6c56fb4bc5f0 458 case COMPLETE_LIST_16BIT_SERVICE_IDS:
nexpaq 0:6c56fb4bc5f0 459 case INCOMPLETE_LIST_32BIT_SERVICE_IDS:
nexpaq 0:6c56fb4bc5f0 460 case COMPLETE_LIST_32BIT_SERVICE_IDS:
nexpaq 0:6c56fb4bc5f0 461 case INCOMPLETE_LIST_128BIT_SERVICE_IDS:
nexpaq 0:6c56fb4bc5f0 462 case COMPLETE_LIST_128BIT_SERVICE_IDS:
nexpaq 0:6c56fb4bc5f0 463 case LIST_128BIT_SOLICITATION_IDS: {
nexpaq 0:6c56fb4bc5f0 464 /* Check if data fits */
nexpaq 0:6c56fb4bc5f0 465 if ((_payloadLen + len) <= GAP_ADVERTISING_DATA_MAX_PAYLOAD) {
nexpaq 0:6c56fb4bc5f0 466 /*
nexpaq 0:6c56fb4bc5f0 467 * Make room for new field by moving the remainder of the
nexpaq 0:6c56fb4bc5f0 468 * advertisement payload "to the right" starting after the
nexpaq 0:6c56fb4bc5f0 469 * TYPE field.
nexpaq 0:6c56fb4bc5f0 470 */
nexpaq 0:6c56fb4bc5f0 471 uint8_t* end = &_payload[_payloadLen];
nexpaq 0:6c56fb4bc5f0 472
nexpaq 0:6c56fb4bc5f0 473 while (&field[1] < end) {
nexpaq 0:6c56fb4bc5f0 474 end[len] = *end;
nexpaq 0:6c56fb4bc5f0 475 end--;
nexpaq 0:6c56fb4bc5f0 476 }
nexpaq 0:6c56fb4bc5f0 477
nexpaq 0:6c56fb4bc5f0 478 /* Insert new data */
nexpaq 0:6c56fb4bc5f0 479 for (uint8_t idx = 0; idx < len; idx++) {
nexpaq 0:6c56fb4bc5f0 480 field[2 + idx] = payload[idx];
nexpaq 0:6c56fb4bc5f0 481 }
nexpaq 0:6c56fb4bc5f0 482
nexpaq 0:6c56fb4bc5f0 483 /* Increment lengths */
nexpaq 0:6c56fb4bc5f0 484 field[0] += len;
nexpaq 0:6c56fb4bc5f0 485 _payloadLen += len;
nexpaq 0:6c56fb4bc5f0 486
nexpaq 0:6c56fb4bc5f0 487 result = BLE_ERROR_NONE;
nexpaq 0:6c56fb4bc5f0 488 }
nexpaq 0:6c56fb4bc5f0 489
nexpaq 0:6c56fb4bc5f0 490 break;
nexpaq 0:6c56fb4bc5f0 491 }
nexpaq 0:6c56fb4bc5f0 492 /* These fields will be overwritten with the new value */
nexpaq 0:6c56fb4bc5f0 493 default: {
nexpaq 0:6c56fb4bc5f0 494 result = updateField(advDataType, payload, len, field);
nexpaq 0:6c56fb4bc5f0 495
nexpaq 0:6c56fb4bc5f0 496 break;
nexpaq 0:6c56fb4bc5f0 497 }
nexpaq 0:6c56fb4bc5f0 498 }
nexpaq 0:6c56fb4bc5f0 499
nexpaq 0:6c56fb4bc5f0 500 return result;
nexpaq 0:6c56fb4bc5f0 501 }
nexpaq 0:6c56fb4bc5f0 502
nexpaq 0:6c56fb4bc5f0 503 /**
nexpaq 0:6c56fb4bc5f0 504 * Given the a pointer to a field in the advertising payload it replaces
nexpaq 0:6c56fb4bc5f0 505 * the existing data in the field with the supplied data.
nexpaq 0:6c56fb4bc5f0 506 *
nexpaq 0:6c56fb4bc5f0 507 * @param[in] advDataType
nexpaq 0:6c56fb4bc5f0 508 * The type of the data to be updated.
nexpaq 0:6c56fb4bc5f0 509 * @param[in] payload
nexpaq 0:6c56fb4bc5f0 510 * A pointer to the data to be updated to the advertising
nexpaq 0:6c56fb4bc5f0 511 * payload.
nexpaq 0:6c56fb4bc5f0 512 * @param[in] len
nexpaq 0:6c56fb4bc5f0 513 * The length of th data pointed to by @p payload.
nexpaq 0:6c56fb4bc5f0 514 * @param[in] field
nexpaq 0:6c56fb4bc5f0 515 * A pointer to the field of type @p advDataType in the
nexpaq 0:6c56fb4bc5f0 516 * advertising buffer.
nexpaq 0:6c56fb4bc5f0 517 *
nexpaq 0:6c56fb4bc5f0 518 * @return BLE_ERROR_NONE on success.
nexpaq 0:6c56fb4bc5f0 519 */
nexpaq 0:6c56fb4bc5f0 520 ble_error_t updateField(DataType_t advDataType, const uint8_t *payload, uint8_t len, uint8_t* field)
nexpaq 0:6c56fb4bc5f0 521 {
nexpaq 0:6c56fb4bc5f0 522 ble_error_t result = BLE_ERROR_BUFFER_OVERFLOW;
nexpaq 0:6c56fb4bc5f0 523 uint8_t dataLength = field[0] - 1;
nexpaq 0:6c56fb4bc5f0 524
nexpaq 0:6c56fb4bc5f0 525 /* New data has same length, do in-order replacement */
nexpaq 0:6c56fb4bc5f0 526 if (len == dataLength) {
nexpaq 0:6c56fb4bc5f0 527 for (uint8_t idx = 0; idx < dataLength; idx++) {
nexpaq 0:6c56fb4bc5f0 528 field[2 + idx] = payload[idx];
nexpaq 0:6c56fb4bc5f0 529 }
nexpaq 0:6c56fb4bc5f0 530
nexpaq 0:6c56fb4bc5f0 531 result = BLE_ERROR_NONE;
nexpaq 0:6c56fb4bc5f0 532 } else {
nexpaq 0:6c56fb4bc5f0 533 /* Check if data fits */
nexpaq 0:6c56fb4bc5f0 534 if ((_payloadLen - dataLength + len) <= GAP_ADVERTISING_DATA_MAX_PAYLOAD) {
nexpaq 0:6c56fb4bc5f0 535
nexpaq 0:6c56fb4bc5f0 536 /* Remove old field */
nexpaq 0:6c56fb4bc5f0 537 while ((field + dataLength + 2) < &_payload[_payloadLen]) {
nexpaq 0:6c56fb4bc5f0 538 *field = field[dataLength + 2];
nexpaq 0:6c56fb4bc5f0 539 field++;
nexpaq 0:6c56fb4bc5f0 540 }
nexpaq 0:6c56fb4bc5f0 541
nexpaq 0:6c56fb4bc5f0 542 /* Reduce length */
nexpaq 0:6c56fb4bc5f0 543 _payloadLen -= dataLength + 2;
nexpaq 0:6c56fb4bc5f0 544
nexpaq 0:6c56fb4bc5f0 545 /* Add new field */
nexpaq 0:6c56fb4bc5f0 546 result = appendField(advDataType, payload, len);
nexpaq 0:6c56fb4bc5f0 547 }
nexpaq 0:6c56fb4bc5f0 548 }
nexpaq 0:6c56fb4bc5f0 549
nexpaq 0:6c56fb4bc5f0 550 return result;
nexpaq 0:6c56fb4bc5f0 551 }
nexpaq 0:6c56fb4bc5f0 552
nexpaq 0:6c56fb4bc5f0 553 /**
nexpaq 0:6c56fb4bc5f0 554 * The advertising data buffer
nexpaq 0:6c56fb4bc5f0 555 */
nexpaq 0:6c56fb4bc5f0 556 uint8_t _payload[GAP_ADVERTISING_DATA_MAX_PAYLOAD];
nexpaq 0:6c56fb4bc5f0 557 /**
nexpaq 0:6c56fb4bc5f0 558 * The length of the data added to the advertising buffer.
nexpaq 0:6c56fb4bc5f0 559 */
nexpaq 0:6c56fb4bc5f0 560 uint8_t _payloadLen;
nexpaq 0:6c56fb4bc5f0 561 /**
nexpaq 0:6c56fb4bc5f0 562 * Appearance value.
nexpaq 0:6c56fb4bc5f0 563 */
nexpaq 0:6c56fb4bc5f0 564 uint16_t _appearance;
nexpaq 0:6c56fb4bc5f0 565 };
nexpaq 0:6c56fb4bc5f0 566
nexpaq 0:6c56fb4bc5f0 567 #endif /* ifndef __GAP_ADVERTISING_DATA_H__ */