BLE_API_Tiny_BLE

Dependents:   CSSE4011_BLE_IMU

Fork of BLE_API by Bluetooth Low Energy

Committer:
rgrover1
Date:
Wed Jan 21 09:32:49 2015 +0000
Revision:
260:ea7f9f14cc15
Parent:
106:a20be740075d
Child:
331:10f190629734
Synchronized with git rev bec9560c
Author: Rohit Grover
fix all line endings to be Unix style

Who changed what in which revision?

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