Microbug / BLE_API

Fork of BLE_API by Bluetooth Low Energy

Committer:
Rohit Grover
Date:
Thu Jun 19 14:09:37 2014 +0100
Revision:
96:6f4c8e545d38
Parent:
47:33f605e109a2
GapAdvertisingData::addFlags() should take a uint8_t bitmask instead of a 'Flags'

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ktownsend 27:4a83843f04b0 1 /* mbed Microcontroller Library
ktownsend 27:4a83843f04b0 2 * Copyright (c) 2006-2013 ARM Limited
ktownsend 27:4a83843f04b0 3 *
ktownsend 27:4a83843f04b0 4 * Licensed under the Apache License, Version 2.0 (the "License");
ktownsend 27:4a83843f04b0 5 * you may not use this file except in compliance with the License.
ktownsend 27:4a83843f04b0 6 * You may obtain a copy of the License at
ktownsend 27:4a83843f04b0 7 *
ktownsend 27:4a83843f04b0 8 * http://www.apache.org/licenses/LICENSE-2.0
ktownsend 27:4a83843f04b0 9 *
ktownsend 27:4a83843f04b0 10 * Unless required by applicable law or agreed to in writing, software
ktownsend 27:4a83843f04b0 11 * distributed under the License is distributed on an "AS IS" BASIS,
ktownsend 27:4a83843f04b0 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
ktownsend 27:4a83843f04b0 13 * See the License for the specific language governing permissions and
ktownsend 27:4a83843f04b0 14 * limitations under the License.
ktownsend 27:4a83843f04b0 15 */
Rohit Grover 34:da2ea8cd6216 16
ktownsend 2:ffc5216bd2cc 17 #ifndef __GAP_ADVERTISING_DATA_H__
ktownsend 2:ffc5216bd2cc 18 #define __GAP_ADVERTISING_DATA_H__
ktownsend 2:ffc5216bd2cc 19
ktownsend 2:ffc5216bd2cc 20 #include "blecommon.h"
ktownsend 2:ffc5216bd2cc 21
ktownsend 3:46de446e82ed 22 #define GAP_ADVERTISING_DATA_MAX_PAYLOAD (31)
ktownsend 3:46de446e82ed 23
ktownsend 3:46de446e82ed 24 /**************************************************************************/
ktownsend 3:46de446e82ed 25 /*!
ktownsend 18:86fe1e247a54 26 \brief
ktownsend 3:46de446e82ed 27 This class provides several helper functions to generate properly
ktownsend 3:46de446e82ed 28 formatted GAP Advertising and Scan Response data payloads
ktownsend 4:50a31ff5f974 29
Rohit Grover 34:da2ea8cd6216 30 \note
ktownsend 18:86fe1e247a54 31 See Bluetooth Specification 4.0 (Vol. 3), Part C, Section 11 and 18
ktownsend 4:50a31ff5f974 32 for further information on Advertising and Scan Response data.
Rohit Grover 34:da2ea8cd6216 33
ktownsend 18:86fe1e247a54 34 \par Advertising and Scan Response Payloads
ktownsend 3:46de446e82ed 35 Advertising data and Scan Response data are organized around a set of
ktownsend 4:50a31ff5f974 36 data types called 'AD types' in Bluetooth 4.0 (see the Bluetooth Core
ktownsend 4:50a31ff5f974 37 Specification v4.0, Vol. 3, Part C, Sections 11 and 18).
ktownsend 4:50a31ff5f974 38
ktownsend 18:86fe1e247a54 39 \par
ktownsend 3:46de446e82ed 40 Each AD type has it's own standardized 'assigned number', as defined
ktownsend 3:46de446e82ed 41 by the Bluetooth SIG:
ktownsend 3:46de446e82ed 42 https://www.bluetooth.org/en-us/specification/assigned-numbers/generic-access-profile
Rohit Grover 34:da2ea8cd6216 43
ktownsend 18:86fe1e247a54 44 \par
ktownsend 3:46de446e82ed 45 For convenience sake, all appropriate AD types have been encapsulated
ktownsend 18:86fe1e247a54 46 into GapAdvertisingData::DataType.
Rohit Grover 34:da2ea8cd6216 47
ktownsend 18:86fe1e247a54 48 \par
ktownsend 4:50a31ff5f974 49 Before the AD Types and their payload (if any) can be inserted into
ktownsend 4:50a31ff5f974 50 the Advertising or Scan Response frames, they need to be formatted as
ktownsend 4:50a31ff5f974 51 follows:
Rohit Grover 34:da2ea8cd6216 52
ktownsend 18:86fe1e247a54 53 \li \c Record length (1 byte)
ktownsend 18:86fe1e247a54 54 \li \c AD Type (1 byte)
ktownsend 18:86fe1e247a54 55 \li \c AD payload (optional, only present if record length > 1)
Rohit Grover 34:da2ea8cd6216 56
ktownsend 18:86fe1e247a54 57 \par
ktownsend 5:7635f81a8e09 58 This class takes care of properly formatting the payload, performs
ktownsend 5:7635f81a8e09 59 some basic checks on the payload length, and tries to avoid common
ktownsend 5:7635f81a8e09 60 errors like adding an exclusive AD field twice in the Advertising
ktownsend 5:7635f81a8e09 61 or Scan Response payload.
Rohit Grover 34:da2ea8cd6216 62
ktownsend 18:86fe1e247a54 63 \par EXAMPLE
Rohit Grover 34:da2ea8cd6216 64
ktownsend 18:86fe1e247a54 65 \code
Rohit Grover 34:da2ea8cd6216 66
ktownsend 5:7635f81a8e09 67 // ToDo
Rohit Grover 34:da2ea8cd6216 68
ktownsend 18:86fe1e247a54 69 \endcode
ktownsend 3:46de446e82ed 70 */
ktownsend 3:46de446e82ed 71 /**************************************************************************/
ktownsend 2:ffc5216bd2cc 72 class GapAdvertisingData
ktownsend 2:ffc5216bd2cc 73 {
Rohit Grover 34:da2ea8cd6216 74 public:
ktownsend 19:a6f33421746c 75 /**********************************************************************/
ktownsend 19:a6f33421746c 76 /*!
ktownsend 19:a6f33421746c 77 \brief
ktownsend 19:a6f33421746c 78 A list of Advertising Data types commonly used by peripherals.
ktownsend 19:a6f33421746c 79 These AD types are used to describe the capabilities of the
ktownsend 19:a6f33421746c 80 peripheral, and get inserted inside the advertising or scan
ktownsend 19:a6f33421746c 81 response payloads.
Rohit Grover 34:da2ea8cd6216 82
ktownsend 19:a6f33421746c 83 \par Source
ktownsend 19:a6f33421746c 84 \li \c Bluetooth Core Specification 4.0 (Vol. 3), Part C, Section 11, 18
ktownsend 19:a6f33421746c 85 \li \c https://www.bluetooth.org/en-us/specification/assigned-numbers/generic-access-profile
ktownsend 19:a6f33421746c 86 */
ktownsend 19:a6f33421746c 87 /**********************************************************************/
Rohit Grover 96:6f4c8e545d38 88 enum DataType {
Rohit Grover 96:6f4c8e545d38 89 FLAGS = 0x01, /**< \ref *Flags */
Rohit Grover 96:6f4c8e545d38 90 INCOMPLETE_LIST_16BIT_SERVICE_IDS = 0x02, /**< Incomplete list of 16-bit Service IDs */
Rohit Grover 96:6f4c8e545d38 91 COMPLETE_LIST_16BIT_SERVICE_IDS = 0x03, /**< Complete list of 16-bit Service IDs */
Rohit Grover 96:6f4c8e545d38 92 INCOMPLETE_LIST_32BIT_SERVICE_IDS = 0x04, /**< Incomplete list of 32-bit Service IDs (not relevant for Bluetooth 4.0) */
Rohit Grover 96:6f4c8e545d38 93 COMPLETE_LIST_32BIT_SERVICE_IDS = 0x05, /**< Complete list of 32-bit Service IDs (not relevant for Bluetooth 4.0) */
Rohit Grover 96:6f4c8e545d38 94 INCOMPLETE_LIST_128BIT_SERVICE_IDS = 0x06, /**< Incomplete list of 128-bit Service IDs */
Rohit Grover 96:6f4c8e545d38 95 COMPLETE_LIST_128BIT_SERVICE_IDS = 0x07, /**< Complete list of 128-bit Service IDs */
Rohit Grover 96:6f4c8e545d38 96 SHORTENED_LOCAL_NAME = 0x08, /**< Shortened Local Name */
Rohit Grover 96:6f4c8e545d38 97 COMPLETE_LOCAL_NAME = 0x09, /**< Complete Local Name */
Rohit Grover 96:6f4c8e545d38 98 TX_POWER_LEVEL = 0x0A, /**< TX Power Level (in dBm) */
Rohit Grover 96:6f4c8e545d38 99 DEVICE_ID = 0x10, /**< Device ID */
Rohit Grover 96:6f4c8e545d38 100 SLAVE_CONNECTION_INTERVAL_RANGE = 0x12, /**< Slave Connection Interval Range */
Rohit Grover 96:6f4c8e545d38 101 SERVICE_DATA = 0x16, /**< Service Data */
Rohit Grover 96:6f4c8e545d38 102 APPEARANCE = 0x19, /**< \ref Appearance */
Rohit Grover 96:6f4c8e545d38 103 ADVERTISING_INTERVAL = 0x1A, /**< Advertising Interval */
Rohit Grover 96:6f4c8e545d38 104 MANUFACTURER_SPECIFIC_DATA = 0xFF /**< Manufacturer Specific Data */
ktownsend 4:50a31ff5f974 105 };
Rohit Grover 34:da2ea8cd6216 106
ktownsend 19:a6f33421746c 107 /**********************************************************************/
ktownsend 19:a6f33421746c 108 /*!
ktownsend 19:a6f33421746c 109 \brief
ktownsend 19:a6f33421746c 110 A list of values for the FLAGS AD Type
Rohit Grover 34:da2ea8cd6216 111
ktownsend 19:a6f33421746c 112 \note
ktownsend 19:a6f33421746c 113 You can use more than one value in the FLAGS AD Type (ex.
ktownsend 19:a6f33421746c 114 LE_GENERAL_DISCOVERABLE and BREDR_NOT_SUPPORTED).
Rohit Grover 34:da2ea8cd6216 115
ktownsend 19:a6f33421746c 116 \par Source
ktownsend 19:a6f33421746c 117 \li \c Bluetooth Core Specification 4.0 (Vol. 3), Part C, Section 18.1
ktownsend 19:a6f33421746c 118 */
ktownsend 19:a6f33421746c 119 /**********************************************************************/
Rohit Grover 96:6f4c8e545d38 120 enum Flags {
Rohit Grover 96:6f4c8e545d38 121 LE_LIMITED_DISCOVERABLE = 0x01, /**< *Peripheral device is discoverable for a limited period of time */
Rohit Grover 96:6f4c8e545d38 122 LE_GENERAL_DISCOVERABLE = 0x02, /**< Peripheral device is discoverable at any moment */
Rohit Grover 96:6f4c8e545d38 123 BREDR_NOT_SUPPORTED = 0x04, /**< Peripheral device is LE only */
Rohit Grover 96:6f4c8e545d38 124 SIMULTANEOUS_LE_BREDR_C = 0x08, /**< Not relevant - central mode only */
Rohit Grover 96:6f4c8e545d38 125 SIMULTANEOUS_LE_BREDR_H = 0x10 /**< Not relevant - central mode only */
ktownsend 4:50a31ff5f974 126 };
ktownsend 4:50a31ff5f974 127
ktownsend 19:a6f33421746c 128 /**********************************************************************/
ktownsend 19:a6f33421746c 129 /*!
ktownsend 19:a6f33421746c 130 \brief
ktownsend 19:a6f33421746c 131 A list of values for the APPEARANCE AD Type, which describes the
ktownsend 19:a6f33421746c 132 physical shape or appearance of the device
Rohit Grover 34:da2ea8cd6216 133
ktownsend 19:a6f33421746c 134 \par Source
ktownsend 19:a6f33421746c 135 \li \c Bluetooth Core Specification Supplement, Part A, Section 1.12
ktownsend 19:a6f33421746c 136 \li \c Bluetooth Core Specification 4.0 (Vol. 3), Part C, Section 12.2
ktownsend 19:a6f33421746c 137 \li \c https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.gap.appearance.xml
ktownsend 19:a6f33421746c 138 */
ktownsend 19:a6f33421746c 139 /**********************************************************************/
Rohit Grover 96:6f4c8e545d38 140 enum Appearance {
Rohit Grover 96:6f4c8e545d38 141 UNKNOWN = 0, /**< Unknown of unspecified appearance type */
Rohit Grover 96:6f4c8e545d38 142 GENERIC_PHONE = 64, /**< Generic Phone */
Rohit Grover 96:6f4c8e545d38 143 GENERIC_COMPUTER = 128, /**< Generic Computer */
Rohit Grover 96:6f4c8e545d38 144 GENERIC_WATCH = 192, /**< Generic Watch */
Rohit Grover 96:6f4c8e545d38 145 WATCH_SPORTS_WATCH = 193, /**< Sports Watch */
Rohit Grover 96:6f4c8e545d38 146 GENERIC_CLOCK = 256, /**< Generic Clock */
Rohit Grover 96:6f4c8e545d38 147 GENERIC_DISPLAY = 320, /**< Generic Display */
Rohit Grover 96:6f4c8e545d38 148 GENERIC_REMOTE_CONTROL = 384, /**< Generic Remote Control */
Rohit Grover 96:6f4c8e545d38 149 GENERIC_EYE_GLASSES = 448, /**< Generic Eye Glasses */
Rohit Grover 96:6f4c8e545d38 150 GENERIC_TAG = 512, /**< Generic Tag */
Rohit Grover 96:6f4c8e545d38 151 GENERIC_KEYRING = 576, /**< Generic Keyring */
Rohit Grover 96:6f4c8e545d38 152 GENERIC_MEDIA_PLAYER = 640, /**< Generic Media Player */
Rohit Grover 96:6f4c8e545d38 153 GENERIC_BARCODE_SCANNER = 704, /**< Generic Barcode Scanner */
Rohit Grover 96:6f4c8e545d38 154 GENERIC_THERMOMETER = 768, /**< Generic Thermometer */
Rohit Grover 96:6f4c8e545d38 155 THERMOMETER_EAR = 769, /**< Ear Thermometer */
Rohit Grover 96:6f4c8e545d38 156 GENERIC_HEART_RATE_SENSOR = 832, /**< Generic Heart Rate Sensor */
Rohit Grover 96:6f4c8e545d38 157 HEART_RATE_SENSOR_HEART_RATE_BELT = 833, /**< Belt Heart Rate Sensor */
Rohit Grover 96:6f4c8e545d38 158 GENERIC_BLOOD_PRESSURE = 896, /**< Generic Blood Pressure */
Rohit Grover 96:6f4c8e545d38 159 BLOOD_PRESSURE_ARM = 897, /**< Arm Blood Pressure */
Rohit Grover 96:6f4c8e545d38 160 BLOOD_PRESSURE_WRIST = 898, /**< Wrist Blood Pressure */
Rohit Grover 96:6f4c8e545d38 161 HUMAN_INTERFACE_DEVICE_HID = 960, /**< Human Interface Device (HID) */
Rohit Grover 96:6f4c8e545d38 162 KEYBOARD = 961, /**< Keyboard */
Rohit Grover 34:da2ea8cd6216 163 MOUSE = 962, /**< Mouse */
Rohit Grover 96:6f4c8e545d38 164 JOYSTICK = 963, /**< Joystick */
Rohit Grover 96:6f4c8e545d38 165 GAMEPAD = 964, /**< Gamepad */
Rohit Grover 96:6f4c8e545d38 166 DIGITIZER_TABLET = 965, /**< Digitizer Tablet */
Rohit Grover 96:6f4c8e545d38 167 CARD_READER = 966, /**< Card Read */
Rohit Grover 96:6f4c8e545d38 168 DIGITAL_PEN = 967, /**< Digital Pen */
Rohit Grover 96:6f4c8e545d38 169 BARCODE_SCANNER = 968, /**< Barcode Scanner */
Rohit Grover 96:6f4c8e545d38 170 GENERIC_GLUCOSE_METER = 1024, /**< Generic Glucose Meter */
Rohit Grover 96:6f4c8e545d38 171 GENERIC_RUNNING_WALKING_SENSOR = 1088, /**< Generic Running/Walking Sensor */
Rohit Grover 96:6f4c8e545d38 172 RUNNING_WALKING_SENSOR_IN_SHOE = 1089, /**< In Shoe Running/Walking Sensor */
Rohit Grover 96:6f4c8e545d38 173 RUNNING_WALKING_SENSOR_ON_SHOE = 1090, /**< On Shoe Running/Walking Sensor */
Rohit Grover 96:6f4c8e545d38 174 RUNNING_WALKING_SENSOR_ON_HIP = 1091, /**< On Hip Running/Walking Sensor */
Rohit Grover 96:6f4c8e545d38 175 GENERIC_CYCLING = 1152, /**< Generic Cycling */
Rohit Grover 96:6f4c8e545d38 176 CYCLING_CYCLING_COMPUTER = 1153, /**< Cycling Computer */
Rohit Grover 96:6f4c8e545d38 177 CYCLING_SPEED_SENSOR = 1154, /**< Cycling Speed Senspr */
Rohit Grover 96:6f4c8e545d38 178 CYCLING_CADENCE_SENSOR = 1155, /**< Cycling Cadence Sensor */
Rohit Grover 96:6f4c8e545d38 179 CYCLING_POWER_SENSOR = 1156, /**< Cycling Power Sensor */
Rohit Grover 96:6f4c8e545d38 180 CYCLING_SPEED_AND_CADENCE_SENSOR = 1157, /**< Cycling Speed and Cadence Sensor */
Rohit Grover 96:6f4c8e545d38 181 PULSE_OXIMETER_GENERIC = 3136, /**< Generic Pulse Oximeter */
Rohit Grover 96:6f4c8e545d38 182 PULSE_OXIMETER_FINGERTIP = 3137, /**< Fingertip Pulse Oximeter */
Rohit Grover 96:6f4c8e545d38 183 PULSE_OXIMETER_WRIST_WORN = 3138, /**< Wrist Worn Pulse Oximeter */
Rohit Grover 96:6f4c8e545d38 184 OUTDOOR_GENERIC = 5184, /**< Generic Outdoor */
Rohit Grover 96:6f4c8e545d38 185 OUTDOOR_LOCATION_DISPLAY_DEVICE = 5185, /**< Outdoor Location Display Device */
Rohit Grover 96:6f4c8e545d38 186 OUTDOOR_LOCATION_AND_NAVIGATION_DISPLAY_DEVICE = 5186, /**< Outdoor Location and Navigation Display Device */
Rohit Grover 96:6f4c8e545d38 187 OUTDOOR_LOCATION_POD = 5187, /**< Outdoor Location Pod */
Rohit Grover 96:6f4c8e545d38 188 OUTDOOR_LOCATION_AND_NAVIGATION_POD = 5188 /**< Outdoor Location and Navigation Pod */
ktownsend 4:50a31ff5f974 189 };
ktownsend 4:50a31ff5f974 190
ktownsend 2:ffc5216bd2cc 191 GapAdvertisingData(void);
ktownsend 2:ffc5216bd2cc 192 virtual ~GapAdvertisingData(void);
ktownsend 3:46de446e82ed 193
Rohit Grover 47:33f605e109a2 194 ble_error_t addData(DataType, const uint8_t *, uint8_t);
bogdanm 31:2c94f0501807 195 ble_error_t addAppearance(Appearance appearance = GENERIC_TAG);
Rohit Grover 96:6f4c8e545d38 196 ble_error_t addFlags(uint8_t flags = LE_GENERAL_DISCOVERABLE);
ktownsend 4:50a31ff5f974 197 ble_error_t addTxPower(int8_t txPower);
ktownsend 4:50a31ff5f974 198 void clear(void);
Rohit Grover 40:d405c9b1419d 199 const uint8_t *getPayload(void) const;
Rohit Grover 40:d405c9b1419d 200 uint8_t getPayloadLen(void) const;
Rohit Grover 40:d405c9b1419d 201 uint16_t getAppearance(void) const;
ktownsend 4:50a31ff5f974 202
Rohit Grover 34:da2ea8cd6216 203 private:
bogdanm 31:2c94f0501807 204 uint8_t _payload[GAP_ADVERTISING_DATA_MAX_PAYLOAD];
bogdanm 31:2c94f0501807 205 uint8_t _payloadLen;
bogdanm 31:2c94f0501807 206 uint16_t _appearance;
ktownsend 2:ffc5216bd2cc 207 };
ktownsend 2:ffc5216bd2cc 208
Rohit Grover 34:da2ea8cd6216 209 #endif // ifndef __GAP_ADVERTISING_DATA_H__