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