1 #ifndef ATT_H_
2 #define ATT_H_
3 
4 /**
5  ****************************************************************************************
6  * @addtogroup ATT Attribute Protocol
7  * @ingroup HOST
8  * @brief Attribute Protocol.
9  *
10  * The ATT block contains the procedures for discovering, reading, writing
11  * and indicating attributes to peer device . It also defines a number of items
12  * that caters to the security aspect of the block as access to some information
13  * may require both authorization and an authenticated and encrypted physical
14  * link before an attribute can be read or written
15  *
16  * @{
17  *
18  ****************************************************************************************
19  */
20 
21 /*
22  * INCLUDE FILES
23  ****************************************************************************************
24  */
25 #include <stdint.h>
26 
27 /*
28  * DEFINES
29  ****************************************************************************************
30  */
31 
32 /// Macro used to convert CPU integer define to LSB first 16-bits UUID
33 #define ATT_UUID_16(uuid)                          (uuid)
34 
35 /// Invalid attribute handle
36 #define ATT_INVALID_HDL                            (0x0000)
37 /// Invalid attribute idx (used for profiles)
38 #define ATT_INVALID_IDX                            (0xff)
39 
40 #define ATT_1ST_REQ_START_HDL                      0x0001
41 #define ATT_1ST_REQ_END_HDL                        0xFFFF
42 
43 /// Maximum possible attribute handle
44 #define ATT_MAX_ATTR_HDL                           ATT_1ST_REQ_END_HDL
45 
46 /// Offset of value in signed PDU
47 #define ATT_SIGNED_PDU_VAL_OFFSET               0x03
48 
49 /// Attribute Features
50 #define ATT_SERVER_CONFIG                       0x0001
51 #define ATT_SERVICE_DISC                        0x0002
52 #define ATT_RELATIONSHIP_DISC                   0x0004
53 #define ATT_CHAR_DISC                           0x0008
54 #define ATT_CHAR_DESC_DISC                      0x0010
55 #define ATT_RD_CHAR_VALUE                       0x0020
56 #define ATT_WR_CHAR_VALUE                       0x0040
57 #define ATT_NOTIF_CHAR_VALUE                    0x0080
58 #define ATT_IND_CHAR_VALUE                      0x0100
59 #define ATT_RD_CHAR_DESC                        0x0200
60 #define ATT_WR_CHAR_DESC                        0x0400
61 
62 /// Length, number, offset defines
63 #define ATT_SVC_VALUE_MAX_LEN                   0x0030
64 #define ATT_CHAR_NAME_MAX_LEN                   0x0030
65 #define ATT_UUID_16_LEN                         0x0002
66 #define ATT_UUID_32_LEN                         0x0004
67 #define ATT_UUID_128_LEN                        0x0010
68 
69 /// offset - l2cap header and ATT code
70 #define ATT_PDU_DATA_OFFSET                     0x05
71 
72 /// Characteristic Properties Bit
73 #define ATT_CHAR_PROP_BCAST                     0x01
74 #define ATT_CHAR_PROP_RD                        0x02
75 #define ATT_CHAR_PROP_WR_NO_RESP                0x04
76 #define ATT_CHAR_PROP_WR                        0x08
77 #define ATT_CHAR_PROP_NTF                       0x10
78 #define ATT_CHAR_PROP_IND                       0x20
79 #define ATT_CHAR_PROP_AUTH                      0x40
80 #define ATT_CHAR_PROP_EXT_PROP                  0x80
81 /// Invalid Attribute Handle
82 #define ATT_INVALID_SEARCH_HANDLE               0x0000
83 #define ATT_INVALID_HANDLE                      0x0000
84 /// Read Information Request
85 #define ATT_UUID_FILTER_0                       0x00
86 #define ATT_UUID_FILTER_2                       0x02
87 #define ATT_UUID_FILTER_16                      0x10
88 /// Read Information Response
89 #define ATT_FORMAT_LEN                          0x0001
90 #define ATT_FORMAT_16BIT_UUID                   0x01
91 #define ATT_FORMAT_128BIT_UUID                  0x02
92 /// For No fix length PDU
93 #define ATT_HANDLE_LEN                          0x0002
94 #define ATT_EACHLEN_LEN                         0x0001
95 #define ATT_PROP_LEN                            0x0001
96 #define ATT_CODE_LEN                            0x0001
97 #define ATT_CODE_AND_DATA_LEN                   0x0002
98 #define ATT_CODE_AND_HANDLE_LEN                 0x0003
99 #define ATT_CODE_AND_HANDLE_LEN_AND_OFFSET      0x0005
100 #define ATT_SIGNATURE_LEN                       0x0C
101 
102 /// extended characteristics
103 #define ATT_EXT_RELIABLE_WRITE                  0x0001
104 #define ATT_EXT_WRITABLE_AUX                    0x0002
105 #define ATT_EXT_RFU                             0xFFFC
106 
107 /// PDU size for error response
108 #define ATT_ERROR_RESP_LEN                      0x05
109 
110 /// Offset of value in signed PDU
111 #define ATT_SIGNED_PDU_VAL_OFFSET               0x03
112 
113 
114 
115 #define ATT_BT_UUID_128 {0xFB, 0x34, 0x9B, 0x5F, 0x80, 0x00, 0x00, 0x80, \
116                           0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
117 
118 
119 
120 /* Attribute Specification Defines */
121 
122 /// Common 16-bit Universal Unique Identifier
123 enum {
124     ATT_INVALID_UUID                            = ATT_UUID_16(0x0000),
125     /*----------------- SERVICES ---------------------*/
126     /// Generic Access Profile
127     ATT_SVC_GENERIC_ACCESS                      = ATT_UUID_16(0x1800),
128     /// Attribute Profile
129     ATT_SVC_GENERIC_ATTRIBUTE                   = ATT_UUID_16(0x1801),
130     /// Immediate alert Service
131     ATT_SVC_IMMEDIATE_ALERT                     = ATT_UUID_16(0x1802),
132     /// Link Loss Service
133     ATT_SVC_LINK_LOSS                           = ATT_UUID_16(0x1803),
134     /// Tx Power Service
135     ATT_SVC_TX_POWER                            = ATT_UUID_16(0x1804),
136     /// Current Time Service Service
137     ATT_SVC_CURRENT_TIME                        = ATT_UUID_16(0x1805),
138     /// Reference Time Update Service
139     ATT_SVC_REF_TIME_UPDATE                     = ATT_UUID_16(0x1806),
140     /// Next DST Change Service
141     ATT_SVC_NEXT_DST_CHANGE                     = ATT_UUID_16(0x1807),
142     /// Glucose Service
143     ATT_SVC_GLUCOSE                             = ATT_UUID_16(0x1808),
144     /// Health Thermometer Service
145     ATT_SVC_HEALTH_THERMOM                      = ATT_UUID_16(0x1809),
146     /// Device Information Service
147     ATT_SVC_DEVICE_INFO                         = ATT_UUID_16(0x180A),
148     /// Heart Rate Service
149     ATT_SVC_HEART_RATE                          = ATT_UUID_16(0x180D),
150     /// Phone Alert Status Service
151     ATT_SVC_PHONE_ALERT_STATUS                  = ATT_UUID_16(0x180E),
152     /// Battery Service
153     ATT_SVC_BATTERY_SERVICE                     = ATT_UUID_16(0x180F),
154     /// Blood Pressure Service
155     ATT_SVC_BLOOD_PRESSURE                      = ATT_UUID_16(0x1810),
156     /// Alert Notification Service
157     ATT_SVC_ALERT_NTF                           = ATT_UUID_16(0x1811),
158     /// HID Service
159     ATT_SVC_HID                                 = ATT_UUID_16(0x1812),
160     /// Scan Parameters Service
161     ATT_SVC_SCAN_PARAMETERS                     = ATT_UUID_16(0x1813),
162     /// Running Speed and Cadence Service
163     ATT_SVC_RUNNING_SPEED_CADENCE               = ATT_UUID_16(0x1814),
164     /// Cycling Speed and Cadence Service
165     ATT_SVC_CYCLING_SPEED_CADENCE               = ATT_UUID_16(0x1816),
166     /// Cycling Power Service
167     ATT_SVC_CYCLING_POWER                       = ATT_UUID_16(0x1818),
168     /// Location and Navigation Service
169     ATT_SVC_LOCATION_AND_NAVIGATION             = ATT_UUID_16(0x1819),
170     /// Environmental Sensing Service
171     ATT_SVC_ENVIRONMENTAL_SENSING               = ATT_UUID_16(0x181A),
172     /// Body Composition Service
173     ATT_SVC_BODY_COMPOSITION                    = ATT_UUID_16(0x181B),
174     /// User Data Service
175     ATT_SVC_USER_DATA                           = ATT_UUID_16(0x181C),
176     /// Weight Scale Service
177     ATT_SVC_WEIGHT_SCALE                        = ATT_UUID_16(0x181D),
178     /// Bond Management Service
179     ATT_SVC_BOND_MANAGEMENT                     = ATT_UUID_16(0x181E),
180     /// Continuous Glucose Monitoring Service
181     ATT_SVC_CONTINUOUS_GLUCOSE_MONITORING       = ATT_UUID_16(0x181F),
182     /// Internet Protocol Support Service
183     ATT_SVC_IP_SUPPORT                          = ATT_UUID_16(0x1820),
184     /// Indoor Positioning Service
185     ATT_SVC_INDOOR_POSITIONING                  = ATT_UUID_16(0x1821),
186     /// Pulse Oximeter Service
187     ATT_SVC_PULSE_OXIMETER                      = ATT_UUID_16(0x1822),
188     /// HTTP Proxy Service
189     ATT_SVC_HTTP_PROXY                          = ATT_UUID_16(0x1823),
190     /// Transport Discovery Service
191     ATT_SVC_TRANSPORT_DISCOVERY                 = ATT_UUID_16(0x1824),
192     /// Object Transfer Service
193     ATT_SVC_OBJECT_TRANSFER                     = ATT_UUID_16(0x1825),
194 
195     /*------------------- UNITS ---------------------*/
196     /// No defined unit
197     ATT_UNIT_UNITLESS                           = ATT_UUID_16(0x2700),
198     /// Length Unit - Metre
199     ATT_UNIT_METRE                              = ATT_UUID_16(0x2701),
200     ///Mass unit - Kilogram
201     ATT_UNIT_KG                                 = ATT_UUID_16(0x2702),
202     ///Time unit - second
203     ATT_UNIT_SECOND                             = ATT_UUID_16(0x2703),
204     ///Electric current unit - Ampere
205     ATT_UNIT_AMPERE                             = ATT_UUID_16(0x2704),
206     ///Thermodynamic Temperature unit - Kelvin
207     ATT_UNIT_KELVIN                             = ATT_UUID_16(0x2705),
208     /// Amount of substance unit - mole
209     ATT_UNIT_MOLE                               = ATT_UUID_16(0x2706),
210     ///Luminous intensity unit - candela
211     ATT_UNIT_CANDELA                            = ATT_UUID_16(0x2707),
212     ///Area unit - square metres
213     ATT_UNIT_SQ_METRE                           = ATT_UUID_16(0x2710),
214     ///Colume unit - cubic metres
215     ATT_UNIT_CUBIC_METRE                        = ATT_UUID_16(0x2710),
216     ///Velocity unit - metres per second
217     ATT_UNIT_METRE_PER_SECOND                   = ATT_UUID_16(0x2711),
218     ///Acceleration unit - metres per second squared
219     ATT_UNIT_METRES_PER_SEC_SQ                  = ATT_UUID_16(0x2712),
220     ///Wavenumber unit - reciprocal metre
221     ATT_UNIT_RECIPROCAL_METRE                   = ATT_UUID_16(0x2713),
222     ///Density unit - kilogram per cubic metre
223     ATT_UNIT_DENS_KG_PER_CUBIC_METRE            = ATT_UUID_16(0x2714),
224     ///Surface density unit - kilogram per square metre
225     ATT_UNIT_KG_PER_SQ_METRE                    = ATT_UUID_16(0x2715),
226     ///Specific volume unit - cubic metre per kilogram
227     ATT_UNIT_CUBIC_METRE_PER_KG                 = ATT_UUID_16(0x2716),
228     ///Current density unit - ampere per square metre
229     ATT_UNIT_AMPERE_PER_SQ_METRE                = ATT_UUID_16(0x2717),
230     ///Magnetic field strength unit - Ampere per metre
231     ATT_UNIT_AMPERE_PER_METRE                   = ATT_UUID_16(0x2718),
232     ///Amount concentration unit - mole per cubic metre
233     ATT_UNIT_MOLE_PER_CUBIC_METRE               = ATT_UUID_16(0x2719),
234     ///Mass Concentration unit - kilogram per cubic metre
235     ATT_UNIT_MASS_KG_PER_CUBIC_METRE            = ATT_UUID_16(0x271A),
236     ///Luminance unit - candela per square metre
237     ATT_UNIT_CANDELA_PER_SQ_METRE               = ATT_UUID_16(0x271B),
238     ///Refractive index unit
239     ATT_UNIT_REFRACTIVE_INDEX                   = ATT_UUID_16(0x271C),
240     ///Relative permeability unit
241     ATT_UNIT_RELATIVE_PERMEABILITY              = ATT_UUID_16(0x271D),
242     ///Plane angle unit - radian
243     ATT_UNIT_RADIAN                             = ATT_UUID_16(0x2720),
244     ///Solid angle unit - steradian
245     ATT_UNIT_STERADIAN                          = ATT_UUID_16(0x2721),
246     ///Frequency unit - Hertz
247     ATT_UNIT_HERTZ                              = ATT_UUID_16(0x2722),
248     ///Force unit - Newton
249     ATT_UNIT_NEWTON                             = ATT_UUID_16(0x2723),
250     ///Pressure unit - Pascal
251     ATT_UNIT_PASCAL                             = ATT_UUID_16(0x2724),
252     ///Energy unit - Joule
253     ATT_UNIT_JOULE                              = ATT_UUID_16(0x2725),
254     ///Power unit - Watt
255     ATT_UNIT_WATT                               = ATT_UUID_16(0x2726),
256     ///electric Charge unit - Coulomb
257     ATT_UNIT_COULOMB                            = ATT_UUID_16(0x2727),
258     ///Electric potential difference - Volt
259     ATT_UNIT_VOLT                               = ATT_UUID_16(0x2728),
260     ///Capacitance unit - Farad
261     ATT_UNIT_FARAD                              = ATT_UUID_16(0x2729),
262     ///electric resistance unit - Ohm
263     ATT_UNIT_OHM                                = ATT_UUID_16(0x272A),
264     ///Electric conductance - Siemens
265     ATT_UNIT_SIEMENS                            = ATT_UUID_16(0x272B),
266     ///Magnetic flux unit - Weber
267     ATT_UNIT_WEBER                              = ATT_UUID_16(0x272C),
268     ///Magnetic flux density unit - Tesla
269     ATT_UNIT_TESLA                              = ATT_UUID_16(0x272D),
270     ///Inductance unit - Henry
271     ATT_UNIT_HENRY                              = ATT_UUID_16(0x272E),
272     ///Temperature unit - degree Celsius
273     ATT_UNIT_CELSIUS                            = ATT_UUID_16(0x272F),
274     ///Luminous flux unit - lumen
275     ATT_UNIT_LUMEN                              = ATT_UUID_16(0x2730),
276     ///Illuminance unit - lux
277     ATT_UNIT_LUX                                = ATT_UUID_16(0x2731),
278     ///Activity referred to a radionuclide unit - becquerel
279     ATT_UNIT_BECQUEREL                          = ATT_UUID_16(0x2732),
280     ///Absorbed dose unit - Gray
281     ATT_UNIT_GRAY                               = ATT_UUID_16(0x2733),
282     ///Dose equivalent unit - Sievert
283     ATT_UNIT_SIEVERT                            = ATT_UUID_16(0x2734),
284     ///Catalytic activity unit - Katal
285     ATT_UNIT_KATAL                              = ATT_UUID_16(0x2735),
286     ///Synamic viscosity unit - Pascal second
287     ATT_UNIT_PASCAL_SECOND                      = ATT_UUID_16(0x2740),
288     ///Moment of force unit - Newton metre
289     ATT_UNIT_NEWTON_METRE                       = ATT_UUID_16(0x2741),
290     ///surface tension unit - Newton per metre
291     ATT_UNIT_NEWTON_PER_METRE                   = ATT_UUID_16(0x2742),
292     ///Angular velocity unit - radian per second
293     ATT_UNIT_RADIAN_PER_SECOND                  = ATT_UUID_16(0x2743),
294     ///Angular acceleration unit - radian per second squared
295     ATT_UNIT_RADIAN_PER_SECOND_SQ               = ATT_UUID_16(0x2744),
296     ///Heat flux density unit - Watt per square metre
297     ATT_UNIT_WATT_PER_SQ_METRE                  = ATT_UUID_16(0x2745),
298     ///HEat capacity unit - Joule per Kelvin
299     ATT_UNIT_JOULE_PER_KELVIN                   = ATT_UUID_16(0x2746),
300     ///Specific heat capacity unit - Joule per kilogram kelvin
301     ATT_UNIT_JOULE_PER_KG_KELVIN                = ATT_UUID_16(0x2747),
302     ///Specific Energy unit - Joule per kilogram
303     ATT_UNIT_JOULE_PER_KG                       = ATT_UUID_16(0x2748),
304     ///Thermal conductivity - Watt per metre Kelvin
305     ATT_UNIT_WATT_PER_METRE_KELVIN              = ATT_UUID_16(0x2749),
306     ///Energy Density unit - joule per cubic metre
307     ATT_UNIT_JOULE_PER_CUBIC_METRE              = ATT_UUID_16(0x274A),
308     ///Electric field strength unit - volt per metre
309     ATT_UNIT_VOLT_PER_METRE                     = ATT_UUID_16(0x274B),
310     ///Electric charge density unit - coulomb per cubic metre
311     ATT_UNIT_COULOMB_PER_CUBIC_METRE            = ATT_UUID_16(0x274C),
312     ///Surface charge density unit - coulomb per square metre
313     ATT_UNIT_SURF_COULOMB_PER_SQ_METRE          = ATT_UUID_16(0x274D),
314     ///Electric flux density unit - coulomb per square metre
315     ATT_UNIT_FLUX_COULOMB_PER_SQ_METRE          = ATT_UUID_16(0x274E),
316     ///Permittivity unit - farad per metre
317     ATT_UNIT_FARAD_PER_METRE                    = ATT_UUID_16(0x274F),
318     ///Permeability unit - henry per metre
319     ATT_UNIT_HENRY_PER_METRE                    = ATT_UUID_16(0x2750),
320     ///Molar energy unit - joule per mole
321     ATT_UNIT_JOULE_PER_MOLE                     = ATT_UUID_16(0x2751),
322     ///Molar entropy unit - joule per mole kelvin
323     ATT_UNIT_JOULE_PER_MOLE_KELVIN              = ATT_UUID_16(0x2752),
324     ///Exposure unit - coulomb per kilogram
325     ATT_UNIT_COULOMB_PER_KG                     = ATT_UUID_16(0x2753),
326     ///Absorbed dose rate unit - gray per second
327     ATT_UNIT_GRAY_PER_SECOND                    = ATT_UUID_16(0x2754),
328     ///Radiant intensity unit - watt per steradian
329     ATT_UNIT_WATT_PER_STERADIAN                 = ATT_UUID_16(0x2755),
330     ///Radiance unit - watt per square meter steradian
331     ATT_UNIT_WATT_PER_SQ_METRE_STERADIAN        = ATT_UUID_16(0x2756),
332     ///Catalytic activity concentration unit - katal per cubic metre
333     ATT_UNIT_KATAL_PER_CUBIC_METRE              = ATT_UUID_16(0x2757),
334     ///Time unit - minute
335     ATT_UNIT_MINUTE                             = ATT_UUID_16(0x2760),
336     ///Time unit - hour
337     ATT_UNIT_HOUR                               = ATT_UUID_16(0x2761),
338     ///Time unit - day
339     ATT_UNIT_DAY                                = ATT_UUID_16(0x2762),
340     ///Plane angle unit - degree
341     ATT_UNIT_ANGLE_DEGREE                       = ATT_UUID_16(0x2763),
342     ///Plane angle unit - minute
343     ATT_UNIT_ANGLE_MINUTE                       = ATT_UUID_16(0x2764),
344     ///Plane angle unit - second
345     ATT_UNIT_ANGLE_SECOND                       = ATT_UUID_16(0x2765),
346     ///Area unit - hectare
347     ATT_UNIT_HECTARE                            = ATT_UUID_16(0x2766),
348     ///Volume unit - litre
349     ATT_UNIT_LITRE                              = ATT_UUID_16(0x2767),
350     ///Mass unit - tonne
351     ATT_UNIT_TONNE                              = ATT_UUID_16(0x2768),
352     ///Pressure unit - bar
353     ATT_UNIT_BAR                                = ATT_UUID_16(0x2780),
354     ///Pressure unit - millimetre of mercury
355     ATT_UNIT_MM_MERCURY                         = ATT_UUID_16(0x2781),
356     ///Length unit - angstrom
357     ATT_UNIT_ANGSTROM                           = ATT_UUID_16(0x2782),
358     ///Length unit - nautical mile
359     ATT_UNIT_NAUTICAL_MILE                      = ATT_UUID_16(0x2783),
360     ///Area unit - barn
361     ATT_UNIT_BARN                               = ATT_UUID_16(0x2784),
362     ///Velocity unit - knot
363     ATT_UNIT_KNOT                               = ATT_UUID_16(0x2785),
364     ///Logarithmic radio quantity unit - neper
365     ATT_UNIT_NEPER                              = ATT_UUID_16(0x2786),
366     ///Logarithmic radio quantity unit - bel
367     ATT_UNIT_BEL                                = ATT_UUID_16(0x2787),
368     ///Length unit - yard
369     ATT_UNIT_YARD                               = ATT_UUID_16(0x27A0),
370     ///Length unit - parsec
371     ATT_UNIT_PARSEC                             = ATT_UUID_16(0x27A1),
372     ///length unit - inch
373     ATT_UNIT_INCH                               = ATT_UUID_16(0x27A2),
374     ///length unit - foot
375     ATT_UNIT_FOOT                               = ATT_UUID_16(0x27A3),
376     ///length unit - mile
377     ATT_UNIT_MILE                               = ATT_UUID_16(0x27A4),
378     ///pressure unit - pound-force per square inch
379     ATT_UNIT_POUND_FORCE_PER_SQ_INCH            = ATT_UUID_16(0x27A5),
380     ///velocity unit - kilometre per hour
381     ATT_UNIT_KM_PER_HOUR                        = ATT_UUID_16(0x27A6),
382     ///velocity unit - mile per hour
383     ATT_UNIT_MILE_PER_HOUR                      = ATT_UUID_16(0x27A7),
384     ///angular velocity unit - revolution per minute
385     ATT_UNIT_REVOLUTION_PER_MINUTE              = ATT_UUID_16(0x27A8),
386     ///energy unit - gram calorie
387     ATT_UNIT_GRAM_CALORIE                       = ATT_UUID_16(0x27A9),
388     ///energy unit - kilogram calorie
389     ATT_UNIT_KG_CALORIE                         = ATT_UUID_16(0x27AA),
390     /// energy unit - kilowatt hour
391     ATT_UNIT_KILOWATT_HOUR                      = ATT_UUID_16(0x27AB),
392     ///thermodynamic temperature unit - degree Fahrenheit
393     ATT_UNIT_FAHRENHEIT                         = ATT_UUID_16(0x27AC),
394     ///percentage
395     ATT_UNIT_PERCENTAGE                         = ATT_UUID_16(0x27AD),
396     ///per mille
397     ATT_UNIT_PER_MILLE                          = ATT_UUID_16(0x27AE),
398     ///period unit - beats per minute)
399     ATT_UNIT_BEATS_PER_MINUTE                   = ATT_UUID_16(0x27AF),
400     ///electric charge unit - ampere hours
401     ATT_UNIT_AMPERE_HOURS                       = ATT_UUID_16(0x27B0),
402     ///mass density unit - milligram per decilitre
403     ATT_UNIT_MILLIGRAM_PER_DECILITRE            = ATT_UUID_16(0x27B1),
404     ///mass density unit - millimole per litre
405     ATT_UNIT_MILLIMOLE_PER_LITRE                = ATT_UUID_16(0x27B2),
406     ///time unit - year
407     ATT_UNIT_YEAR                               = ATT_UUID_16(0x27B3),
408     ////time unit - month
409     ATT_UNIT_MONTH                              = ATT_UUID_16(0x27B4),
410 
411 
412     /*---------------- DECLARATIONS -----------------*/
413     /// Primary service Declaration
414     ATT_DECL_PRIMARY_SERVICE                     = ATT_UUID_16(0x2800),
415     /// Secondary service Declaration
416     ATT_DECL_SECONDARY_SERVICE                   = ATT_UUID_16(0x2801),
417     /// Include Declaration
418     ATT_DECL_INCLUDE                             = ATT_UUID_16(0x2802),
419     /// Characteristic Declaration
420     ATT_DECL_CHARACTERISTIC                      = ATT_UUID_16(0x2803),
421 
422 
423     /*----------------- DESCRIPTORS -----------------*/
424     /// Characteristic extended properties
425     ATT_DESC_CHAR_EXT_PROPERTIES                 = ATT_UUID_16(0x2900),
426     /// Characteristic user description
427     ATT_DESC_CHAR_USER_DESCRIPTION               = ATT_UUID_16(0x2901),
428     /// Client characteristic configuration
429     ATT_DESC_CLIENT_CHAR_CFG                     = ATT_UUID_16(0x2902),
430     /// Server characteristic configuration
431     ATT_DESC_SERVER_CHAR_CFG                     = ATT_UUID_16(0x2903),
432     /// Characteristic Presentation Format
433     ATT_DESC_CHAR_PRES_FORMAT                    = ATT_UUID_16(0x2904),
434     /// Characteristic Aggregate Format
435     ATT_DESC_CHAR_AGGREGATE_FORMAT               = ATT_UUID_16(0x2905),
436     /// Valid Range
437     ATT_DESC_VALID_RANGE                         = ATT_UUID_16(0x2906),
438     /// External Report Reference
439     ATT_DESC_EXT_REPORT_REF                      = ATT_UUID_16(0x2907),
440     /// Report Reference
441     ATT_DESC_REPORT_REF                          = ATT_UUID_16(0x2908),
442     /// Environmental Sensing Configuration
443     ATT_DESC_ES_CONFIGURATION                    = ATT_UUID_16(0x290B),
444     /// Environmental Sensing Measurement
445     ATT_DESC_ES_MEASUREMENT                      = ATT_UUID_16(0x290C),
446     /// Environmental Sensing Trigger Setting
447     ATT_DESC_ES_TRIGGER_SETTING                  = ATT_UUID_16(0x290D),
448 
449 
450     /*--------------- CHARACTERISTICS ---------------*/
451     /// Device name
452     ATT_CHAR_DEVICE_NAME                        = ATT_UUID_16(0x2A00),
453     /// Appearance
454     ATT_CHAR_APPEARANCE                         = ATT_UUID_16(0x2A01),
455     /// Privacy flag
456     ATT_CHAR_PRIVACY_FLAG                       = ATT_UUID_16(0x2A02),
457     /// Reconnection address
458     ATT_CHAR_RECONNECTION_ADDR                  = ATT_UUID_16(0x2A03),
459     /// Peripheral preferred connection parameters
460     ATT_CHAR_PERIPH_PREF_CON_PARAM              = ATT_UUID_16(0x2A04),
461     /// Service handles changed
462     ATT_CHAR_SERVICE_CHANGED                    = ATT_UUID_16(0x2A05),
463     /// Alert Level characteristic
464     ATT_CHAR_ALERT_LEVEL                        = ATT_UUID_16(0x2A06),
465     /// Tx Power Level
466     ATT_CHAR_TX_POWER_LEVEL                     = ATT_UUID_16(0x2A07),
467     /// Date Time
468     ATT_CHAR_DATE_TIME                          = ATT_UUID_16(0x2A08),
469     /// Day of Week
470     ATT_CHAR_DAY_WEEK                           = ATT_UUID_16(0x2A09),
471     /// Day Date Time
472     ATT_CHAR_DAY_DATE_TIME                      = ATT_UUID_16(0x2A0A),
473     /// Exact time 256
474     ATT_CHAR_EXACT_TIME_256                     = ATT_UUID_16(0x2A0C),
475     /// DST Offset
476     ATT_CHAR_DST_OFFSET                         = ATT_UUID_16(0x2A0D),
477     /// Time zone
478     ATT_CHAR_TIME_ZONE                          = ATT_UUID_16(0x2A0E),
479     /// Local time Information
480     ATT_CHAR_LOCAL_TIME_INFO                    = ATT_UUID_16(0x2A0F),
481     /// Time with DST
482     ATT_CHAR_TIME_WITH_DST                      = ATT_UUID_16(0x2A11),
483     /// Time Accuracy
484     ATT_CHAR_TIME_ACCURACY                      = ATT_UUID_16(0x2A12),
485     ///Time Source
486     ATT_CHAR_TIME_SOURCE                        = ATT_UUID_16(0x2A13),
487     /// Reference Time Information
488     ATT_CHAR_REFERENCE_TIME_INFO                = ATT_UUID_16(0x2A14),
489     /// Time Update Control Point
490     ATT_CHAR_TIME_UPDATE_CNTL_POINT             = ATT_UUID_16(0x2A16),
491     /// Time Update State
492     ATT_CHAR_TIME_UPDATE_STATE                  = ATT_UUID_16(0x2A17),
493     /// Glucose Measurement
494     ATT_CHAR_GLUCOSE_MEAS                       = ATT_UUID_16(0x2A18),
495     /// Battery Level
496     ATT_CHAR_BATTERY_LEVEL                      = ATT_UUID_16(0x2A19),
497     /// Temperature Measurement
498     ATT_CHAR_TEMPERATURE_MEAS                   = ATT_UUID_16(0x2A1C),
499     /// Temperature Type
500     ATT_CHAR_TEMPERATURE_TYPE                   = ATT_UUID_16(0x2A1D),
501     /// Intermediate Temperature
502     ATT_CHAR_INTERMED_TEMPERATURE               = ATT_UUID_16(0x2A1E),
503     /// Measurement Interval
504     ATT_CHAR_MEAS_INTERVAL                      = ATT_UUID_16(0x2A21),
505     /// Boot Keyboard Input Report
506     ATT_CHAR_BOOT_KB_IN_REPORT                  = ATT_UUID_16(0x2A22),
507     /// System ID
508     ATT_CHAR_SYS_ID                             = ATT_UUID_16(0x2A23),
509     /// Model Number String
510     ATT_CHAR_MODEL_NB                           = ATT_UUID_16(0x2A24),
511     /// Serial Number String
512     ATT_CHAR_SERIAL_NB                          = ATT_UUID_16(0x2A25),
513     /// Firmware Revision String
514     ATT_CHAR_FW_REV                             = ATT_UUID_16(0x2A26),
515     /// Hardware revision String
516     ATT_CHAR_HW_REV                             = ATT_UUID_16(0x2A27),
517     /// Software Revision String
518     ATT_CHAR_SW_REV                             = ATT_UUID_16(0x2A28),
519     /// Manufacturer Name String
520     ATT_CHAR_MANUF_NAME                         = ATT_UUID_16(0x2A29),
521     /// IEEE Regulatory Certification Data List
522     ATT_CHAR_IEEE_CERTIF                        = ATT_UUID_16(0x2A2A),
523     /// CT Time
524     ATT_CHAR_CT_TIME                            = ATT_UUID_16(0x2A2B),
525     /// Magnetic Declination
526     ATT_CHAR_MAGN_DECLINE                       = ATT_UUID_16(0x2A2C),
527     /// Scan Refresh
528     ATT_CHAR_SCAN_REFRESH                       = ATT_UUID_16(0x2A31),
529     /// Boot Keyboard Output Report
530     ATT_CHAR_BOOT_KB_OUT_REPORT                 = ATT_UUID_16(0x2A32),
531     /// Boot Mouse Input Report
532     ATT_CHAR_BOOT_MOUSE_IN_REPORT               = ATT_UUID_16(0x2A33),
533     /// Glucose Measurement Context
534     ATT_CHAR_GLUCOSE_MEAS_CTX                   = ATT_UUID_16(0x2A34),
535     /// Blood Pressure Measurement
536     ATT_CHAR_BLOOD_PRESSURE_MEAS                = ATT_UUID_16(0x2A35),
537     /// Intermediate Cuff Pressure
538     ATT_CHAR_INTERMEDIATE_CUFF_PRESSURE         = ATT_UUID_16(0x2A36),
539     /// Heart Rate Measurement
540     ATT_CHAR_HEART_RATE_MEAS                    = ATT_UUID_16(0x2A37),
541     /// Body Sensor Location
542     ATT_CHAR_BODY_SENSOR_LOCATION               = ATT_UUID_16(0x2A38),
543     /// Heart Rate Control Point
544     ATT_CHAR_HEART_RATE_CNTL_POINT              = ATT_UUID_16(0x2A39),
545     /// Alert Status
546     ATT_CHAR_ALERT_STATUS                       = ATT_UUID_16(0x2A3F),
547     /// Ringer Control Point
548     ATT_CHAR_RINGER_CNTL_POINT                  = ATT_UUID_16(0x2A40),
549     /// Ringer Setting
550     ATT_CHAR_RINGER_SETTING                     = ATT_UUID_16(0x2A41),
551     /// Alert Category ID Bit Mask
552     ATT_CHAR_ALERT_CAT_ID_BIT_MASK              = ATT_UUID_16(0x2A42),
553     /// Alert Category ID
554     ATT_CHAR_ALERT_CAT_ID                       = ATT_UUID_16(0x2A43),
555     /// Alert Notification Control Point
556     ATT_CHAR_ALERT_NTF_CTNL_PT                  = ATT_UUID_16(0x2A44),
557     /// Unread Alert Status
558     ATT_CHAR_UNREAD_ALERT_STATUS                = ATT_UUID_16(0x2A45),
559     /// New Alert
560     ATT_CHAR_NEW_ALERT                          = ATT_UUID_16(0x2A46),
561     /// Supported New Alert Category
562     ATT_CHAR_SUP_NEW_ALERT_CAT                  = ATT_UUID_16(0x2A47),
563     /// Supported Unread Alert Category
564     ATT_CHAR_SUP_UNREAD_ALERT_CAT               = ATT_UUID_16(0x2A48),
565     /// Blood Pressure Feature
566     ATT_CHAR_BLOOD_PRESSURE_FEATURE             = ATT_UUID_16(0x2A49),
567     /// HID Information
568     ATT_CHAR_HID_INFO                           = ATT_UUID_16(0x2A4A),
569     /// Report Map
570     ATT_CHAR_REPORT_MAP                         = ATT_UUID_16(0x2A4B),
571     /// HID Control Point
572     ATT_CHAR_HID_CTNL_PT                        = ATT_UUID_16(0x2A4C),
573     /// Report
574     ATT_CHAR_REPORT                             = ATT_UUID_16(0x2A4D),
575     /// Protocol Mode
576     ATT_CHAR_PROTOCOL_MODE                      = ATT_UUID_16(0x2A4E),
577     /// Scan Interval Window
578     ATT_CHAR_SCAN_INTV_WD                       = ATT_UUID_16(0x2A4F),
579     /// PnP ID
580     ATT_CHAR_PNP_ID                             = ATT_UUID_16(0x2A50),
581     /// Glucose Feature
582     ATT_CHAR_GLUCOSE_FEATURE                    = ATT_UUID_16(0x2A51),
583     /// Record access control point
584     ATT_CHAR_REC_ACCESS_CTRL_PT                 = ATT_UUID_16(0x2A52),
585     /// RSC Measurement
586     ATT_CHAR_RSC_MEAS                           = ATT_UUID_16(0x2A53),
587     /// RSC Feature
588     ATT_CHAR_RSC_FEAT                           = ATT_UUID_16(0x2A54),
589     /// SC Control Point
590     ATT_CHAR_SC_CNTL_PT                         = ATT_UUID_16(0x2A55),
591     /// CSC Measurement
592     ATT_CHAR_CSC_MEAS                           = ATT_UUID_16(0x2A5B),
593     /// CSC Feature
594     ATT_CHAR_CSC_FEAT                           = ATT_UUID_16(0x2A5C),
595     /// Sensor Location
596     ATT_CHAR_SENSOR_LOC                         = ATT_UUID_16(0x2A5D),
597     /// CP Measurement
598     ATT_CHAR_CP_MEAS                            = ATT_UUID_16(0x2A63),
599     /// CP Vector
600     ATT_CHAR_CP_VECTOR                          = ATT_UUID_16(0x2A64),
601     /// CP Feature
602     ATT_CHAR_CP_FEAT                            = ATT_UUID_16(0x2A65),
603     /// CP Control Point
604     ATT_CHAR_CP_CNTL_PT                         = ATT_UUID_16(0x2A66),
605     /// Location and Speed
606     ATT_CHAR_LOC_SPEED                          = ATT_UUID_16(0x2A67),
607     /// Navigation
608     ATT_CHAR_NAVIGATION                         = ATT_UUID_16(0x2A68),
609     /// Position Quality
610     ATT_CHAR_POS_QUALITY                        = ATT_UUID_16(0x2A69),
611     /// LN Feature
612     ATT_CHAR_LN_FEAT                            = ATT_UUID_16(0x2A6A),
613     /// LN Control Point
614     ATT_CHAR_LN_CNTL_PT                         = ATT_UUID_16(0x2A6B),
615     /// Elevation
616     ATT_CHAR_ELEVATION                          = ATT_UUID_16(0x2A6C),
617     /// Pressure
618     ATT_CHAR_PRESSURE                           = ATT_UUID_16(0x2A6D),
619     /// Temperature
620     ATT_CHAR_TEMPERATURE                        = ATT_UUID_16(0x2A6E),
621     /// Humidity
622     ATT_CHAR_HUMIDITY                           = ATT_UUID_16(0x2A6F),
623     /// True Wind Speed
624     ATT_CHAR_TRUE_WIND_SPEED                    = ATT_UUID_16(0x2A70),
625     /// True Wind Direction
626     ATT_CHAR_TRUE_WIND_DIR                      = ATT_UUID_16(0x2A71),
627     /// Apparent Wind Speed
628     ATT_CHAR_APRNT_WIND_SPEED                   = ATT_UUID_16(0x2A72),
629     /// Apparent Wind Direction
630     ATT_CHAR_APRNT_WIND_DIRECTION               = ATT_UUID_16(0x2A73),
631     /// Gust Factor
632     ATT_CHAR_GUST_FACTOR                        = ATT_UUID_16(0x2A74),
633     /// Pollen Concentration
634     ATT_CHAR_POLLEN_CONC                        = ATT_UUID_16(0x2A75),
635     /// UV Index
636     ATT_CHAR_UV_INDEX                           = ATT_UUID_16(0x2A76),
637     /// Irradiance
638     ATT_CHAR_IRRADIANCE                         = ATT_UUID_16(0x2A77),
639     /// Rainfall
640     ATT_CHAR_RAINFALL                           = ATT_UUID_16(0x2A78),
641     /// Wind Chill
642     ATT_CHAR_WIND_CHILL                         = ATT_UUID_16(0x2A79),
643     /// Heat Index
644     ATT_CHAR_HEAT_INDEX                         = ATT_UUID_16(0x2A7A),
645     /// Dew Point
646     ATT_CHAR_DEW_POINT                          = ATT_UUID_16(0x2A7B),
647     /// Descriptor Value Changed
648     ATT_CHAR_DESCRIPTOR_VALUE_CHANGED           = ATT_UUID_16(0x2A7D),
649     /// Aerobic Heart Rate Lower Limit
650     ATT_CHAR_AEROBIC_HEART_RATE_LOWER_LIMIT     = ATT_UUID_16(0x2A7E),
651     /// Aerobic Threshhold
652     ATT_CHAR_AEROBIC_THRESHHOLD                 = ATT_UUID_16(0x2A7F),
653     /// Age
654     ATT_CHAR_AGE                                = ATT_UUID_16(0x2A80),
655     /// Anaerobic Heart Rate Lower Limit
656     ATT_CHAR_ANAEROBIC_HEART_RATE_LOWER_LIMIT   = ATT_UUID_16(0x2A81),
657     /// Anaerobic Heart Rate Upper Limit
658     ATT_CHAR_ANAEROBIC_HEART_RATE_UPPER_LIMIT   = ATT_UUID_16(0x2A82),
659     /// Anaerobic Threshhold
660     ATT_CHAR_ANAEROBIC_THRESHHOLD               = ATT_UUID_16(0x2A83),
661     /// Aerobic Heart Rate Upper Limit
662     ATT_CHAR_AEROBIC_HEART_RATE_UPPER_LIMIT     = ATT_UUID_16(0x2A84),
663     /// Date Of Birth
664     ATT_CHAR_DATE_OF_BIRTH                      = ATT_UUID_16(0x2A85),
665     /// Date Of Threshold Assessment
666     ATT_CHAR_DATE_OF_THRESHOLD_ASSESSMENT       = ATT_UUID_16(0x2A86),
667     /// Email Address
668     ATT_CHAR_EMAIL_ADDRESS                      = ATT_UUID_16(0x2A87),
669     /// Fat Burn Heart Rate Lower Limit
670     ATT_CHAR_FAT_BURN_HEART_RATE_LOWER_LIMIT    = ATT_UUID_16(0x2A88),
671     /// Fat Burn Heart Rate Upper Limit
672     ATT_CHAR_FAT_BURN_HEART_RATE_UPPER_LIMIT    = ATT_UUID_16(0x2A89),
673     /// First Name
674     ATT_CHAR_FIRST_NAME                         = ATT_UUID_16(0x2A8A),
675     /// Five Zone Heart Rate Limits
676     ATT_CHAR_FIVE_ZONE_HEART_RATE_LIMITS        = ATT_UUID_16(0x2A8B),
677     /// Gender
678     ATT_CHAR_GENDER                             = ATT_UUID_16(0x2A8C),
679     /// Max Heart Rate
680     ATT_CHAR_MAX_HEART_RATE                     = ATT_UUID_16(0x2A8D),
681     /// Height
682     ATT_CHAR_HEIGHT                             = ATT_UUID_16(0x2A8E),
683     /// Hip Circumference
684     ATT_CHAR_HIP_CIRCUMFERENCE                  = ATT_UUID_16(0x2A8F),
685     /// Last Name
686     ATT_CHAR_LAST_NAME                          = ATT_UUID_16(0x2A90),
687     /// Maximum Recommended Heart Rate
688     ATT_CHAR_MAXIMUM_RECOMMENDED_HEART_RATE     = ATT_UUID_16(0x2A91),
689     /// Resting Heart Rate
690     ATT_CHAR_RESTING_HEART_RATE                 = ATT_UUID_16(0x2A92),
691     /// Sport Type For Aerobic And Anaerobic Thresholds
692     ATT_CHAR_SPORT_TYPE_FOR_AEROBIC_AND_ANAEROBIC_THRESHOLDS = ATT_UUID_16(0x2A93),
693     /// Three Zone Heart Rate Limits
694     ATT_CHAR_THREE_ZONE_HEART_RATE_LIMITS       = ATT_UUID_16(0x2A94),
695     /// Two Zone Heart Rate Limit
696     ATT_CHAR_TWO_ZONE_HEART_RATE_LIMIT          = ATT_UUID_16(0x2A95),
697     /// Vo2 Max
698     ATT_CHAR_VO2_MAX                            = ATT_UUID_16(0x2A96),
699     /// Waist Circumference
700     ATT_CHAR_WAIST_CIRCUMFERENCE                = ATT_UUID_16(0x2A97),
701     /// Weight
702     ATT_CHAR_WEIGHT                             = ATT_UUID_16(0x2A98),
703     /// Database Change Increment
704     ATT_CHAR_DATABASE_CHANGE_INCREMENT          = ATT_UUID_16(0x2A99),
705     /// User Index
706     ATT_CHAR_USER_INDEX                         = ATT_UUID_16(0x2A9A),
707     /// Body Composition Feature
708     ATT_CHAR_BODY_COMPOSITION_FEATURE           = ATT_UUID_16(0x2A9B),
709     /// Body Composition Measurement
710     ATT_CHAR_BODY_COMPOSITION_MEASUREMENT       = ATT_UUID_16(0x2A9C),
711     /// Weight Measurement
712     ATT_CHAR_WEIGHT_MEASUREMENT                 = ATT_UUID_16(0x2A9D),
713     /// Weight Scale Feature
714     ATT_CHAR_WEIGHT_SCALE_FEATURE               = ATT_UUID_16(0x2A9E),
715     /// User Control Point
716     ATT_CHAR_USER_CONTROL_POINT                 = ATT_UUID_16(0x2A9F),
717     /// Flux Density - 2D
718     ATT_CHAR_MAGN_FLUX_2D                       = ATT_UUID_16(0x2AA0),
719     /// Magnetic Flux Density - 3D
720     ATT_CHAR_MAGN_FLUX_3D                       = ATT_UUID_16(0x2AA1),
721     /// Language string
722     ATT_CHAR_LANGUAGE                           = ATT_UUID_16(0x2AA2),
723     /// Barometric Pressure Trend
724     ATT_CHAR_BAR_PRES_TREND                     = ATT_UUID_16(0x2AA3),
725     /// Central Address Resolution Support
726     ATT_CHAR_CTL_ADDR_RESOL_SUPP                = ATT_UUID_16(0x2AA6),
727 };
728 
729 /// Format for Characteristic Presentation
730 enum {
731     /// unsigned 1-bit: true or false
732     ATT_FORMAT_BOOL     = 0x01,
733     /// unsigned 2-bit integer
734     ATT_FORMAT_2BIT,
735     /// unsigned 4-bit integer
736     ATT_FORMAT_NIBBLE,
737     /// unsigned 8-bit integer
738     ATT_FORMAT_UINT8,
739     /// unsigned 12-bit integer
740     ATT_FORMAT_UINT12,
741     /// unsigned 16-bit integer
742     ATT_FORMAT_UINT16,
743     /// unsigned 24-bit integer
744     ATT_FORMAT_UINT24,
745     /// unsigned 32-bit integer
746     ATT_FORMAT_UINT32,
747     /// unsigned 48-bit integer
748     ATT_FORMAT_UINT48,
749     /// unsigned 64-bit integer
750     ATT_FORMAT_UINT64,
751     /// unsigned 128-bit integer
752     ATT_FORMAT_UINT128,
753     /// signed 8-bit integer
754     ATT_FORMAT_SINT8,
755     /// signed 12-bit integer
756     ATT_FORMAT_SINT12,
757     /// signed 16-bit integer
758     ATT_FORMAT_SINT16,
759     /// signed 24-bit integer
760     ATT_FORMAT_SINT24,
761     /// signed 32-bit integer
762     ATT_FORMAT_SINT32,
763     /// signed 48-bit integer
764     ATT_FORMAT_SINT48,
765     /// signed 64-bit integer
766     ATT_FORMAT_SINT64,
767     /// signed 128-bit integer
768     ATT_FORMAT_SINT128,
769     /// IEEE-754 32-bit floating point
770     ATT_FORMAT_FLOAT32,
771     /// IEEE-754 64-bit floating point
772     ATT_FORMAT_FLOAT64,
773     /// IEEE-11073 16-bit SFLOAT
774     ATT_FORMAT_SFLOAT,
775     /// IEEE-11073 32-bit FLOAT
776     ATT_FORMAT_FLOAT,
777     /// IEEE-20601 format
778     ATT_FORMAT_DUINT16,
779     /// UTF-8 string
780     ATT_FORMAT_UTF8S,
781     /// UTF-16 string
782     ATT_FORMAT_UTF16S,
783     /// Opaque structure
784     ATT_FORMAT_STRUCT,
785     /// Last format
786     ATT_FORMAT_LAST
787 };
788 
789 
790 /// Client Characteristic Configuration Codes
791 enum att_ccc_val
792 {
793     /// Stop notification/indication
794     ATT_CCC_STOP_NTFIND = 0x0000,
795     /// Start notification
796     ATT_CCC_START_NTF,
797     /// Start indication
798     ATT_CCC_START_IND
799 };
800 
801 /*
802  * Type Definition
803  ****************************************************************************************
804  */
805 
806 /// Attribute length type
807 typedef uint16_t att_size_t;
808 
809 
810 /// UUID - 128-bit type
811 struct att_uuid_128
812 {
813     /// 128-bit UUID
814     uint8_t uuid[ATT_UUID_128_LEN];
815 };
816 
817 /// UUID - 32-bit type
818 struct att_uuid_32
819 {
820     /// 32-bit UUID
821     uint8_t uuid[ATT_UUID_32_LEN];
822 };
823 
824 
825 
826 /// Characteristic Value Descriptor
827 struct att_char_desc
828 {
829     /// properties
830     uint8_t prop;
831     /// attribute handle
832     uint8_t attr_hdl[ATT_HANDLE_LEN];
833     /// attribute type
834     uint8_t attr_type[ATT_UUID_16_LEN];
835 };
836 
837 /// Characteristic Value Descriptor
838 struct att_char128_desc
839 {
840     /// properties
841     uint8_t prop;
842     /// attribute handle
843     uint8_t attr_hdl[ATT_HANDLE_LEN];
844     /// attribute type
845     uint8_t attr_type[ATT_UUID_128_LEN];
846 };
847 
848 /// Service Value Descriptor - 16-bit
849 typedef uint16_t att_svc_desc_t;
850 
851 /// include service entry element
852 struct att_incl_desc
853 {
854     /// start handle value of included service
855     uint16_t start_hdl;
856     /// end handle value of included service
857     uint16_t end_hdl;
858     /// attribute value UUID
859     uint16_t uuid;
860 };
861 
862 /// include service entry element
863 struct att_incl128_desc
864 {
865     /// start handle value of included service
866     uint16_t start_hdl;
867     /// end handle value of included service
868     uint16_t end_hdl;
869 };
870 
871 
872 // -------------------------- PDU HANDLER Definition  --------------------------
873 
874 /// used to know if PDU handler has been found
875 #define ATT_PDU_HANDLER_NOT_FOUND       (0xff)
876 
877 /// Format of a pdu handler function
878 typedef int (*att_func_t)(uint8_t conidx, void *pdu);
879 
880 /// Element of a pdu handler table.
881 struct att_pdu_handler
882 {
883     /// PDU identifier of the message
884     uint8_t pdu_id;
885     /// Pointer to the handler function for the pdu above.
886     att_func_t handler;
887 };
888 
889 
890 // --------------------------- Database permissions -----------------------------
891 
892 /// Macro used to retrieve access permission rights
893 #define PERM_GET(perm, access)\
894         (((perm) & (PERM_MASK_ ## access)) >> (PERM_POS_ ## access))
895 
896 /// Macro used to retrieve permission value from access and rights on attribute.
897 #define PERM(access, right) \
898     (((PERM_RIGHT_ ## right) << (PERM_POS_ ## access)) & (PERM_MASK_ ## access))
899 
900 /// Macro used know if permission is set or not.
901 #define PERM_IS_SET(perm, access, right) \
902     (((perm) & (((PERM_RIGHT_ ## right) << (PERM_POS_ ## access))) \
903                 & (PERM_MASK_ ## access)) == PERM(access, right))
904 
905 /// Macro used to create permission value
906 #define PERM_VAL(access, perm) \
907     ((((perm) << (PERM_POS_ ## access))) & (PERM_MASK_ ## access))
908 
909 
910 
911 /// Retrieve attribute security level from attribute right and service right
912 #define ATT_GET_SEC_LVL(att_right, svc_right) \
913     co_max(((att_right) & PERM_RIGHT_AUTH), ((svc_right) & PERM_RIGHT_AUTH));
914 
915 /// Retrieve UUID LEN from UUID Length Permission
916 #define ATT_UUID_LEN(uuid_len_perm) ((uuid_len_perm == 0) ? ATT_UUID_16_LEN : \
917         ((uuid_len_perm == 1) ? ATT_UUID_32_LEN  :                        \
918         ((uuid_len_perm == 2) ? ATT_UUID_128_LEN : 0)))
919 
920 /// Initialization of attribute element
921 #define ATT_ELEMT_INIT                                   {{NULL}, false}
922 
923 /**
924  *   15   14   13   12   11   10    9    8    7    6    5    4    3    2    1    0
925  * +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+
926  * |EXT | WS | I  | N  | WR | WC | RD | B  |    NP   |    IP   |   WP    |    RP   |
927  * +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+
928  *
929  * Bit [0-1]  : Read Permission         (0 = NO_AUTH, 1 = UNAUTH, 2 = AUTH, 3 = SEC_CON)
930  * Bit [2-3]  : Write Permission        (0 = NO_AUTH, 1 = UNAUTH, 2 = AUTH, 3 = SEC_CON)
931  * Bit [4-5]  : Indication Permission   (0 = NO_AUTH, 1 = UNAUTH, 2 = AUTH, 3 = SEC_CON)
932  * Bit [6-7]  : Notification Permission (0 = NO_AUTH, 1 = UNAUTH, 2 = AUTH, 3 = SEC_CON)
933  *
934  * Bit [8]    : Extended properties present (only relevant for a characteristic value)
935  * Bit [9]    : Broadcast permission        (only relevant for a characteristic value)
936  * Bit [10]   : Write Command accepted
937  * Bit [11]   : Write Signed accepted
938  * Bit [12]   : Write Request accepted
939  * Bit [13]   : Encryption key Size must be 16 bytes
940  */
941 enum attm_perm_mask
942 {
943     /// retrieve all permission info
944     PERM_MASK_ALL            = 0x0000,
945     /// Read Permission Mask
946     PERM_MASK_RP             = 0x0003,
947     PERM_POS_RP              = 0,
948     /// Write Permission Mask
949     PERM_MASK_WP             = 0x000C,
950     PERM_POS_WP              = 2,
951     /// Indication Access Mask
952     PERM_MASK_IP            = 0x0030,
953     PERM_POS_IP             = 4,
954     /// Notification Access Mask
955     PERM_MASK_NP            = 0x00C0,
956     PERM_POS_NP             = 6,
957     /// Broadcast descriptor present
958     PERM_MASK_BROADCAST     = 0x0100,
959     PERM_POS_BROADCAST      = 8,
960     /// Read Access Mask
961     PERM_MASK_RD            = 0x0200,
962     PERM_POS_RD             = 9,
963     /// Write Command Enabled attribute Mask
964     PERM_MASK_WRITE_COMMAND = 0x0400,
965     PERM_POS_WRITE_COMMAND  = 10,
966     /// Write Request Enabled attribute Mask
967     PERM_MASK_WRITE_REQ     = 0x0800,
968     PERM_POS_WRITE_REQ      = 11,
969     /// Notification Access Mask
970     PERM_MASK_NTF           = 0x1000,
971     PERM_POS_NTF            = 12,
972     /// Indication Access Mask
973     PERM_MASK_IND           = 0x2000,
974     PERM_POS_IND            = 13,
975     /// Write Signed Enabled attribute Mask
976     PERM_MASK_WRITE_SIGNED  = 0x4000,
977     PERM_POS_WRITE_SIGNED   = 14,
978     /// Extended properties descriptor present
979     PERM_MASK_EXT           = 0x8000,
980     PERM_POS_EXT            = 15,
981 
982     /// Properties
983     PERM_MASK_PROP          = 0xFF00,
984     PERM_POS_PROP           = 8,
985 };
986 
987 /**
988  * Value permission bit field
989  *
990  *   15   14   13   12   11   10    9    8    7    6    5    4    3    2    1    0
991  * +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+
992  * | RI |UUID_LEN |EKS |    MAX_LEN (RI = 1) / Value Offset  (RI = 0)              |
993  * +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+
994  *
995  * Bit [0-11] : Maximum Attribute Length or Value Offset pointer
996  * Bit [12]   : Encryption key Size must be 16 bytes
997  * Bit [14-13]: UUID Length             (0 = 16 bits, 1 = 32 bits, 2 = 128 bits, 3 = RFU)
998  * Bit [15]   : Trigger Read Indication (0 = Value present in Database, 1 = Value not present in Database)
999  */
1000 enum attm_value_perm_mask
1001 {
1002     /// Maximum Attribute Length
1003     PERM_MASK_MAX_LEN     = 0x0FFF,
1004     PERM_POS_MAX_LEN      = 0,
1005     /// Attribute value Offset
1006     PERM_MASK_VAL_OFFSET  = 0x0FFF,
1007     PERM_POS_VAL_OFFSET   = 0,
1008     /// Check Encryption key size Mask
1009     PERM_MASK_EKS         = 0x1000,
1010     PERM_POS_EKS          = 12,
1011     /// UUID Length
1012     PERM_MASK_UUID_LEN    = 0x6000,
1013     PERM_POS_UUID_LEN     = 13,
1014     /// Read trigger Indication
1015     PERM_MASK_RI          = 0x8000,
1016     PERM_POS_RI           = 15,
1017 };
1018 
1019 
1020 /**
1021  * Service permissions
1022  *
1023  *    7    6    5    4    3    2    1    0
1024  * +----+----+----+----+----+----+----+----+
1025  * |SEC |UUID_LEN |DIS |  AUTH   |EKS | MI |
1026  * +----+----+----+----+----+----+----+----+
1027  *
1028  * Bit [0]  : Task that manage service is multi-instantiated (Connection index is conveyed)
1029  * Bit [1]  : Encryption key Size must be 16 bytes
1030  * Bit [2-3]: Service Permission      (0 = NO_AUTH, 1 = UNAUTH, 2 = AUTH, 3 = Secure Connect)
1031  * Bit [4]  : Disable the service
1032  * Bit [5-6]: UUID Length             (0 = 16 bits, 1 = 32 bits, 2 = 128 bits, 3 = RFU)
1033  * Bit [7]  : Secondary Service       (0 = Primary Service, 1 = Secondary Service)
1034  */
1035 enum attm_svc_perm_mask
1036 {
1037     /// Task that manage service is multi-instantiated
1038     PERM_MASK_SVC_MI        = 0x01,
1039     PERM_POS_SVC_MI         = 0,
1040     /// Check Encryption key size for service Access
1041     PERM_MASK_SVC_EKS       = 0x02,
1042     PERM_POS_SVC_EKS        = 1,
1043     /// Service Permission authentication
1044     PERM_MASK_SVC_AUTH      = 0x0C,
1045     PERM_POS_SVC_AUTH       = 2,
1046     /// Disable the service
1047     PERM_MASK_SVC_DIS       = 0x10,
1048     PERM_POS_SVC_DIS        = 4,
1049     /// Service UUID Length
1050     PERM_MASK_SVC_UUID_LEN  = 0x60,
1051     PERM_POS_SVC_UUID_LEN   = 5,
1052     /// Service type Secondary
1053     PERM_MASK_SVC_SECONDARY = 0x80,
1054     PERM_POS_SVC_SECONDARY  = 7,
1055 };
1056 
1057 /// Attribute & Service access mode
1058 enum
1059 {
1060     /// Disable access
1061     PERM_RIGHT_DISABLE   = 0,
1062     /// Enable access
1063     PERM_RIGHT_ENABLE   = 1,
1064 };
1065 
1066 /// Attribute & Service access rights
1067 enum
1068 {
1069     /// No Authentication
1070     PERM_RIGHT_NO_AUTH  = 0,
1071     /// Access Requires Unauthenticated link
1072     PERM_RIGHT_UNAUTH   = 1,
1073     /// Access Requires Authenticated link
1074     PERM_RIGHT_AUTH     = 2,
1075     /// Access Requires Secure Connection link
1076     PERM_RIGHT_SEC_CON  = 3,
1077 };
1078 
1079 /// Attribute & Service UUID Length
1080 enum
1081 {
1082     /// 16  bits UUID
1083     PERM_UUID_16         = 0,
1084     PERM_RIGHT_UUID_16         = 0,
1085     /// 32  bits UUID
1086     PERM_UUID_32         = 1,
1087     PERM_RIGHT_UUID_32         = 1,
1088     /// 128 bits UUID
1089     PERM_UUID_128        = 2,
1090     PERM_RIGHT_UUID_128        = 2,
1091     /// Invalid
1092     PERM_UUID_RFU        = 3,
1093 };
1094 
1095 /// execute flags
1096 enum
1097 {
1098     /// Cancel All the Reliable Writes
1099     ATT_CANCEL_ALL_PREPARED_WRITES = 0x00,
1100     /// Write All the Reliable Writes
1101     ATT_EXECUTE_ALL_PREPARED_WRITES
1102 };
1103 
1104 
1105 
1106 /// @} ATT
1107 #endif // ATT_H_
1108