xref: /btstack/src/bluetooth.h (revision 1f030017a9b551a6b6734e6bb9bf5ec3fba087ec)
1 /*
2  * Copyright (C) 2015 BlueKitchen GmbH
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the copyright holders nor the names of
14  *    contributors may be used to endorse or promote products derived
15  *    from this software without specific prior written permission.
16  * 4. Any redistribution, use, or modification is done solely for
17  *    personal benefit and not for any commercial purpose or for
18  *    monetary gain.
19  *
20  * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
21  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BLUEKITCHEN
24  * GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
27  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
30  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  *
33  * Please inquire about commercial licensing options at
34  * [email protected]
35  *
36  */
37 
38 /*
39  * bluetooth.h
40  *
41  * Numbers defined or derived from the official Bluetooth specification
42  */
43 
44 #ifndef BLUETOOTH_H
45 #define BLUETOOTH_H
46 
47 #include <stdint.h>
48 
49 /**
50  * @brief hci connection handle type
51  */
52 typedef uint16_t hci_con_handle_t;
53 
54 /**
55  * @brief Length of a bluetooth device address.
56  */
57 #define BD_ADDR_LEN 6
58 
59 /**
60  * @brief Bluetooth address
61  */
62 typedef uint8_t bd_addr_t[BD_ADDR_LEN];
63 
64 /**
65  * Address types
66  */
67  typedef enum {
68     // Public Device Address
69     BD_ADDR_TYPE_LE_PUBLIC = 0,
70     // Random Device Address
71     BD_ADDR_TYPE_LE_RANDOM = 1,
72     // Public Identity Address (Corresponds to Resolved Private Address)
73     BD_ADDR_TYPE_LE_PUBLIC_IDENTITY = 2,
74     // Random (static) Identity Address (Corresponds to Resolved Private Address)
75     BD_ADDR_TYPE_LE_RANDOM_IDENTITY = 3,
76     // internal BTstack addr types for Classic connections
77     BD_ADDR_TYPE_SCO       = 0xfc,
78     BD_ADDR_TYPE_ACL       = 0xfd,
79     BD_ADDR_TYPE_UNKNOWN   = 0xfe,  // also used as 'invalid'
80 } bd_addr_type_t;
81 
82  /**
83   * Pin Codde
84   */
85 #define PIN_CODE_LEN 16
86 
87 /**
88  * Link types for BR/EDR Connections
89  */
90 typedef enum {
91     HCI_LINK_TYPE_SCO  = 0,
92     HCI_LINK_TYPE_ACL  = 1,
93     HCI_LINK_TYPE_ESCO = 2,
94 } hci_link_type_t;
95 
96 
97 /**
98  * @brief link key
99  */
100 #define LINK_KEY_LEN 16
101 #define LINK_KEY_STR_LEN (LINK_KEY_LEN*2)
102 typedef uint8_t link_key_t[LINK_KEY_LEN];
103 
104 /**
105  * @brief link key type
106  */
107 typedef enum {
108   INVALID_LINK_KEY = 0xffff,
109   COMBINATION_KEY = 0,  // standard pairing
110   LOCAL_UNIT_KEY,     // ?
111   REMOTE_UNIT_KEY,    // ?
112   DEBUG_COMBINATION_KEY,  // SSP with debug
113   UNAUTHENTICATED_COMBINATION_KEY_GENERATED_FROM_P192, // SSP Simple Pairing
114   AUTHENTICATED_COMBINATION_KEY_GENERATED_FROM_P192,   // SSP Passkey, Number confirm, OOB
115   CHANGED_COMBINATION_KEY,               // Link key changed using Change Connection Lnk Key
116   UNAUTHENTICATED_COMBINATION_KEY_GENERATED_FROM_P256, // SSP Simpe Pairing
117   AUTHENTICATED_COMBINATION_KEY_GENERATED_FROM_P256,   // SSP Passkey, Number confirm, OOB
118 } link_key_type_t;
119 
120 /**
121  * LE Privacy 1.2
122  */
123 typedef enum {
124     LE_PRIVACY_MODE_NETWORK = 0,
125     LE_PRIVACY_MODE_DEVICE = 1,
126 } le_privacy_mode_t;
127 
128 /**
129  * @brief Extended Inquiry Response
130  */
131 #define EXTENDED_INQUIRY_RESPONSE_DATA_LEN 240
132 
133 /**
134  * @brief Inquiry modes
135  */
136 typedef enum {
137   INQUIRY_MODE_STANDARD = 0,
138   INQUIRY_MODE_RSSI,
139   INQUIRY_MODE_RSSI_AND_EIR,
140 } inquiry_mode_t;
141 
142 /**
143  * @brief Page Scan Types
144  */
145 typedef enum {
146     PAGE_SCAN_MODE_STANDARD = 0,
147     PAGE_SCAN_MODE_INTERLACED,
148 } page_scan_type_t;
149 
150 /**
151  * @brief Inquiry Scan Types
152  */
153 typedef enum {
154     INQUIRY_SCAN_MODE_STANDARD = 0,
155     INQUIRY_SCAN_MODE_INTERLACED,
156 } inquiry_scan_type_t;
157 
158 /**
159  * Link Supervision Timeout Default, 0x7d00 * 0.625ms = 20s
160  */
161 #define HCI_LINK_SUPERVISION_TIMEOUT_DEFAULT 0x7D00
162 
163 /**
164  * Service Type used for QoS Setup and Flow Specification
165  */
166 typedef enum {
167     HCI_SERVICE_TYPE_NO_TRAFFIC = 0,
168     HCI_SERVICE_TYPE_BEST_EFFORT,
169     HCI_SERVICE_TYPE_GUARANTEED,
170     HCI_SERVICE_TYPE_INVALID,
171 } hci_service_type_t;
172 
173 /**
174  * HCI Transport
175  */
176 
177 /**
178  * packet types - used in BTstack and over the H4 UART interface
179  */
180 #define HCI_COMMAND_DATA_PACKET 0x01
181 #define HCI_ACL_DATA_PACKET     0x02
182 #define HCI_SCO_DATA_PACKET     0x03
183 #define HCI_EVENT_PACKET        0x04
184 #define HCI_ISO_DATA_PACKET     0x05
185 
186 /**
187  * Other assigned numbers, Assigned_Numbers_Host Controller Interface.pdf
188  */
189 
190 typedef enum {
191     HCI_AUDIO_CODING_FORMAT_U_LAW_LOG = 0x00,
192     HCI_AUDIO_CODING_FORMAT_A_LAW_LOG,
193     HCI_AUDIO_CODING_FORMAT_CVSD,
194     HCI_AUDIO_CODING_FORMAT_TRANSPARENT, // Indicates that the controller does not do any transcoding or resampling. This is also used for test mode.
195     HCI_AUDIO_CODING_FORMAT_LINEAR_PCM,
196     HCI_AUDIO_CODING_FORMAT_MSBC,
197     HCI_AUDIO_CODING_FORMAT_LC3,
198     HCI_AUDIO_CODING_FORMAT_G_729A,
199     HCI_AUDIO_CODING_FORMAT_RFU,
200     HCI_AUDIO_CODING_FORMAT_VENDOR_SPECIFIC = 0xFF
201 } hci_audio_coding_format_t;
202 
203 /**
204  * HCI Layer
205  */
206 
207 //
208 // Error Codes rfom Bluetooth Core Specification
209 //
210 
211 /* ENUM_START: BLUETOOTH_ERROR_CODE */
212 #define ERROR_CODE_SUCCESS                                            0x00u
213 #define ERROR_CODE_UNKNOWN_HCI_COMMAND                                0x01u
214 #define ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER                      0x02u
215 #define ERROR_CODE_HARDWARE_FAILURE                                   0x03u
216 #define ERROR_CODE_PAGE_TIMEOUT                                       0x04u
217 #define ERROR_CODE_AUTHENTICATION_FAILURE                             0x05u
218 #define ERROR_CODE_PIN_OR_KEY_MISSING                                 0x06u
219 #define ERROR_CODE_MEMORY_CAPACITY_EXCEEDED                           0x07u
220 #define ERROR_CODE_CONNECTION_TIMEOUT                                 0x08u
221 #define ERROR_CODE_CONNECTION_LIMIT_EXCEEDED                          0x09u
222 #define ERROR_CODE_SYNCHRONOUS_CONNECTION_LIMIT_TO_A_DEVICE_EXCEEDED  0x0Au
223 #define ERROR_CODE_ACL_CONNECTION_ALREADY_EXISTS                      0x0Bu
224 #define ERROR_CODE_COMMAND_DISALLOWED                                 0x0Cu
225 #define ERROR_CODE_CONNECTION_REJECTED_DUE_TO_LIMITED_RESOURCES       0x0Du
226 #define ERROR_CODE_CONNECTION_REJECTED_DUE_TO_SECURITY_REASONS        0x0Eu
227 #define ERROR_CODE_CONNECTION_REJECTED_DUE_TO_UNACCEPTABLE_BD_ADDR    0x0Fu
228 #define ERROR_CODE_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE             0x11u
229 #define ERROR_CODE_INVALID_HCI_COMMAND_PARAMETERS                     0x12u
230 #define ERROR_CODE_REMOTE_USER_TERMINATED_CONNECTION                  0x13u
231 #define ERROR_CODE_CONNECTION_ACCEPT_TIMEOUT_EXCEEDED                 0x10u
232 #define ERROR_CODE_REMOTE_DEVICE_TERMINATED_CONNECTION_DUE_TO_LOW_RESOURCES 0x14u
233 #define ERROR_CODE_REMOTE_DEVICE_TERMINATED_CONNECTION_DUE_TO_POWER_OFF     0x15u
234 #define ERROR_CODE_CONNECTION_TERMINATED_BY_LOCAL_HOST                0x16u
235 #define ERROR_CODE_REPEATED_ATTEMPTS                                  0x17u
236 #define ERROR_CODE_PAIRING_NOT_ALLOWED                                0x18u
237 #define ERROR_CODE_UNKNOWN_LMP_PDU                                    0x19u
238 #define ERROR_CODE_UNSUPPORTED_REMOTE_FEATURE_UNSUPPORTED_LMP_FEATURE 0x1Au
239 #define ERROR_CODE_SCO_OFFSET_REJECTED                                0x1Bu
240 #define ERROR_CODE_SCO_INTERVAL_REJECTED                              0x1Cu
241 #define ERROR_CODE_SCO_AIR_MODE_REJECTED                              0x1Du
242 #define ERROR_CODE_INVALID_LMP_PARAMETERS_INVALID_LL_PARAMETERS       0x1Eu
243 #define ERROR_CODE_UNSPECIFIED_ERROR                                  0x1Fu
244 #define ERROR_CODE_UNSUPPORTED_LMP_PARAMETER_VALUE_UNSUPPORTED_LL_PARAMETER_VALUE 0x20u
245 #define ERROR_CODE_ROLE_CHANGE_NOT_ALLOWED                            0x21u
246 #define ERROR_CODE_LMP_RESPONSE_TIMEOUT_LL_RESPONSE_TIMEOUT           0x22u
247 #define ERROR_CODE_LMP_ERROR_TRANSACTION_COLLISION                    0x23u
248 #define ERROR_CODE_LMP_PDU_NOT_ALLOWED                                0x24u
249 #define ERROR_CODE_ENCRYPTION_MODE_NOT_ACCEPTABLE                     0x25u
250 #define ERROR_CODE_LINK_KEY_CANNOT_BE_CHANGED                         0x26u
251 #define ERROR_CODE_REQUESTED_QOS_NOT_SUPPORTED                        0x27u
252 #define ERROR_CODE_INSTANT_PASSED                                     0x28u
253 #define ERROR_CODE_PAIRING_WITH_UNIT_KEY_NOT_SUPPORTED                0x29u
254 #define ERROR_CODE_DIFFERENT_TRANSACTION_COLLISION                    0x2Au
255 #define ERROR_CODE_RESERVED                                           0x2Bu
256 #define ERROR_CODE_QOS_UNACCEPTABLE_PARAMETER                         0x2Cu
257 #define ERROR_CODE_QOS_REJECTED                                       0x2Du
258 #define ERROR_CODE_CHANNEL_CLASSIFICATION_NOT_SUPPORTED               0x2Eu
259 #define ERROR_CODE_INSUFFICIENT_SECURITY                              0x2Fu
260 #define ERROR_CODE_PARAMETER_OUT_OF_MANDATORY_RANGE                   0x30u
261 // #define ERROR_CODE_RESERVED
262 #define ERROR_CODE_ROLE_SWITCH_PENDING                                0x32u
263 // #define ERROR_CODE_RESERVED
264 #define ERROR_CODE_RESERVED_SLOT_VIOLATION                            0x34u
265 #define ERROR_CODE_ROLE_SWITCH_FAILED                                 0x35u
266 #define ERROR_CODE_EXTENDED_INQUIRY_RESPONSE_TOO_LARGE                0x36u
267 #define ERROR_CODE_SECURE_SIMPLE_PAIRING_NOT_SUPPORTED_BY_HOST        0x37u
268 #define ERROR_CODE_HOST_BUSY_PAIRING                                  0x38u
269 #define ERROR_CODE_CONNECTION_REJECTED_DUE_TO_NO_SUITABLE_CHANNEL_FOUND 0x39u
270 #define ERROR_CODE_CONTROLLER_BUSY                                    0x3Au
271 #define ERROR_CODE_UNACCEPTABLE_CONNECTION_PARAMETERS                 0x3Bu
272 #define ERROR_CODE_DIRECTED_ADVERTISING_TIMEOUT                       0x3Cu
273 #define ERROR_CODE_CONNECTION_TERMINATED_DUE_TO_MIC_FAILURE           0x3Du
274 #define ERROR_CODE_CONNECTION_FAILED_TO_BE_ESTABLISHED                0x3Eu
275 #define ERROR_CODE_MAC_CONNECTION_FAILED                              0x3Fu
276 #define ERROR_CODE_COARSE_CLOCK_ADJUSTMENT_REJECTED_BUT_WILL_TRY_TO_ADJUST_USING_CLOCK_DRAGGING 0x40u
277 
278 // BTstack defined ERRORS, mapped into BLuetooth status code range
279 
280 #define BTSTACK_CONNECTION_TO_BTDAEMON_FAILED              0x50
281 #define BTSTACK_ACTIVATION_FAILED_SYSTEM_BLUETOOTH         0x51
282 #define BTSTACK_ACTIVATION_POWERON_FAILED                  0x52
283 #define BTSTACK_ACTIVATION_FAILED_UNKNOWN                  0x53
284 #define BTSTACK_NOT_ACTIVATED                              0x54
285 #define BTSTACK_BUSY                                       0x55
286 #define BTSTACK_MEMORY_ALLOC_FAILED                        0x56
287 #define BTSTACK_ACL_BUFFERS_FULL                           0x57
288 
289 // l2cap errors - enumeration by the command that created them
290 #define L2CAP_COMMAND_REJECT_REASON_COMMAND_NOT_UNDERSTOOD 0x60
291 #define L2CAP_COMMAND_REJECT_REASON_SIGNALING_MTU_EXCEEDED 0x61
292 #define L2CAP_COMMAND_REJECT_REASON_INVALID_CID_IN_REQUEST 0x62
293 
294 #define L2CAP_CONNECTION_RESPONSE_RESULT_SUCCESSFUL        0x63
295 #define L2CAP_CONNECTION_RESPONSE_RESULT_PENDING           0x64
296 #define L2CAP_CONNECTION_RESPONSE_RESULT_REFUSED_PSM       0x65
297 #define L2CAP_CONNECTION_RESPONSE_RESULT_REFUSED_SECURITY  0x66
298 #define L2CAP_CONNECTION_RESPONSE_RESULT_REFUSED_RESOURCES 0x67
299 #define L2CAP_CONNECTION_RESPONSE_RESULT_ERTM_NOT_SUPPORTED 0x68
300 
301 // should be L2CAP_CONNECTION_RTX_TIMEOUT
302 #define L2CAP_CONNECTION_RESPONSE_RESULT_RTX_TIMEOUT       0x69
303 #define L2CAP_CONNECTION_BASEBAND_DISCONNECT               0x6A
304 #define L2CAP_SERVICE_ALREADY_REGISTERED                   0x6B
305 #define L2CAP_DATA_LEN_EXCEEDS_REMOTE_MTU                  0x6C
306 #define L2CAP_SERVICE_DOES_NOT_EXIST                       0x6D
307 #define L2CAP_LOCAL_CID_DOES_NOT_EXIST                     0x6E
308 #define L2CAP_CONNECTION_RESPONSE_UNKNOWN_ERROR            0x6F
309 
310 #define RFCOMM_MULTIPLEXER_STOPPED                         0x70
311 #define RFCOMM_CHANNEL_ALREADY_REGISTERED                  0x71
312 #define RFCOMM_NO_OUTGOING_CREDITS                         0x72
313 #define RFCOMM_AGGREGATE_FLOW_OFF                          0x73
314 #define RFCOMM_DATA_LEN_EXCEEDS_MTU                        0x74
315 
316 #define HFP_REMOTE_REJECTS_AUDIO_CONNECTION                0x7F
317 
318 #define SDP_HANDLE_ALREADY_REGISTERED                      0x80
319 #define SDP_QUERY_INCOMPLETE                               0x81
320 #define SDP_SERVICE_NOT_FOUND                              0x82
321 #define SDP_HANDLE_INVALID                                 0x83
322 #define SDP_QUERY_BUSY                                     0x84
323 
324 #define ATT_HANDLE_VALUE_INDICATION_IN_PROGRESS            0x90
325 #define ATT_HANDLE_VALUE_INDICATION_TIMEOUT                0x91
326 #define ATT_HANDLE_VALUE_INDICATION_DISCONNECT             0x92
327 
328 #define GATT_CLIENT_NOT_CONNECTED                          0x93
329 #define GATT_CLIENT_BUSY                                   0x94
330 #define GATT_CLIENT_IN_WRONG_STATE                         0x95
331 #define GATT_CLIENT_DIFFERENT_CONTEXT_FOR_ADDRESS_ALREADY_EXISTS 0x96
332 #define GATT_CLIENT_VALUE_TOO_LONG                         0x97
333 #define GATT_CLIENT_CHARACTERISTIC_NOTIFICATION_NOT_SUPPORTED 0x98
334 #define GATT_CLIENT_CHARACTERISTIC_INDICATION_NOT_SUPPORTED   0x99
335 
336 #define BNEP_SERVICE_ALREADY_REGISTERED                    0xA0
337 #define BNEP_CHANNEL_NOT_CONNECTED                         0xA1
338 #define BNEP_DATA_LEN_EXCEEDS_MTU                          0xA2
339 #define BNEP_SETUP_CONNECTION_ERROR                        0xA3
340 
341 // OBEX ERRORS
342 #define OBEX_UNKNOWN_ERROR                                 0xB0
343 #define OBEX_CONNECT_FAILED                                0xB1
344 #define OBEX_DISCONNECTED                                  0xB2
345 #define OBEX_NOT_FOUND                                     0xB3
346 #define OBEX_NOT_ACCEPTABLE                                0xB4
347 #define OBEX_ABORTED                                       0xB5
348 
349 #define MESH_ERROR_APPKEY_INDEX_INVALID                    0xD0
350 /* ENUM_END */
351 
352 
353 /* ENUM_START: AVRCP_BROWSING_ERROR_CODE */
354 #define AVRCP_BROWSING_ERROR_CODE_INVALID_COMMAND                     0x00  // Sent if TG received a PDU that it did not understand. Valid for All.
355 #define AVRCP_BROWSING_ERROR_CODE_INVALID_PARAMETER                   0x01  // Sent if the TG received a PDU with a parameter ID that it did not understand. Sent if there is only one parameter ID in the PDU. Valid for All.
356 #define AVRCP_BROWSING_ERROR_CODE_SPECIFIED_PARAMETER_NOT_FOUND       0x02  // Sent if the parameter ID is understood, but content is wrong or corrupted. Valid for All.
357 #define AVRCP_BROWSING_ERROR_CODE_INTERNAL_ERROR                      0x03  // Sent if there are error conditions not covered by a more specific error code. Valid for All.
358 #define AVRCP_BROWSING_ERROR_CODE_SUCCESS                             0x04  // This is the status that should be returned if the operation was successful. Valid for All except where the response CType is AV/C REJECTED.
359 #define AVRCP_BROWSING_ERROR_CODE_UID_CHANGED                         0x05  // The UIDs on the device have changed. Valid for All.
360 #define AVRCP_BROWSING_ERROR_CODE_RESERVED_06                         0x06  // Valid for All.
361 #define AVRCP_BROWSING_ERROR_CODE_INVALID_DIRECTION                   0x07  // The Direction parameter is invalid. Valid for Change Path.
362 #define AVRCP_BROWSING_ERROR_CODE_NOT_A_DIRECTORY                     0x08  // The UID provided does not refer to a folder item. Valid for Change Path.
363 #define AVRCP_BROWSING_ERROR_CODE_DOES_NOT_EXIST                      0x09  // The UID provided does not refer to any currently valid. Valid for Change Path, PlayItem, AddToNowPlaying, GetItemAttributes.
364 #define AVRCP_BROWSING_ERROR_CODE_INVALID_SCOPE                       0x0a  // The scope parameter is invalid. Valid for GetFolderItems, PlayItem, AddToNowPlayer, GetItemAttributes,.
365 #define AVRCP_BROWSING_ERROR_CODE_RANGE_OUT_OF_BOUNDS                 0x0b  // The start of range provided is not valid. Valid for GetFolderItems.
366 #define AVRCP_BROWSING_ERROR_CODE_UID_IS_A_DIRECTORY                  0x0c  // The UID provided refers to a directory, which cannot be handled by this media player. Valid for PlayItem, AddToNowPlaying.
367 #define AVRCP_BROWSING_ERROR_CODE_MEDIA_IN_USES                       0x0d  // The media is not able to be used for this operation at this time. Valid for PlayItem, AddToNowPlaying.
368 #define AVRCP_BROWSING_ERROR_CODE_NOW_PLAYING_LIST_FULL               0x0e  // No more items can be added to the Now Playing List. Valid for AddToNowPlaying.
369 #define AVRCP_BROWSING_ERROR_CODE_SEARCH_NOT_SUPPORTED                0x0f  // The Browsed Media Player does not support search. Valid for Search.
370 #define AVRCP_BROWSING_ERROR_CODE_SEARCH_IN_PROGRESS                  0x10  // A search operation is already in progress. Valid for Search.
371 #define AVRCP_BROWSING_ERROR_CODE_INVALID_PLAYER_ID                   0x11  // The specified Player Id does not refer to a valid player. Valid for SetAddressedPlayer, SetBrowsedPlayer.
372 #define AVRCP_BROWSING_ERROR_CODE_PLAYER_NOT_BROWSABLE                0x12  // The Player Id supplied refers to a Media Player which does not support browsing. Valid for SetBrowsedPlayer.
373 #define AVRCP_BROWSING_ERROR_CODE_PLAYER_NOT_ADDRESSED                0x13  // The Player Id supplied refers to a player which is not currently addressed, and the command is not able to be performed if the player is not set as addressed. Valid for Search SetBrowsedPlayer.
374 #define AVRCP_BROWSING_ERROR_CODE_NO_VALID_SEARCH_RESULTS             0x14  // The Search result list does not contain valid entries, e.g. after being invalidated due to change of browsed player. Valid for GetFolderItems.
375 #define AVRCP_BROWSING_ERROR_CODE_NO_AVAILABLE_PLAYERS                0x15  // Valid for All.
376 #define AVRCP_BROWSING_ERROR_CODE_ADDRESSED_PLAYER_CHANGED            0x16  // Valid for Register Notification.
377 // 0x17-0xff Reserved
378 /* ENUM_END */
379 
380 // HCI roles
381 typedef enum {
382     HCI_ROLE_MASTER = 0,
383     HCI_ROLE_SLAVE  = 1,
384     HCI_ROLE_INVALID = 0xff,
385 } hci_role_t;
386 
387 // packet sizes (max payload)
388 #define HCI_ACL_DM1_SIZE            17
389 #define HCI_ACL_DH1_SIZE            27
390 #define HCI_ACL_2DH1_SIZE           54
391 #define HCI_ACL_3DH1_SIZE           83
392 #define HCI_ACL_DM3_SIZE           121
393 #define HCI_ACL_DH3_SIZE           183
394 #define HCI_ACL_DM5_SIZE           224
395 #define HCI_ACL_DH5_SIZE           339
396 #define HCI_ACL_2DH3_SIZE          367
397 #define HCI_ACL_3DH3_SIZE          552
398 #define HCI_ACL_2DH5_SIZE          679
399 #define HCI_ACL_3DH5_SIZE         1021
400 #define HCI_SCO_HV1_SIZE            10
401 #define HCI_SCO_HV2_SIZE            20
402 #define HCI_SCO_HV3_SIZE            30
403 #define HCI_SCO_EV3_SIZE            30
404 #define HCI_SCO_EV4_SIZE           120
405 #define HCI_SCO_EV5_SIZE           180
406 #define HCI_SCO_2EV3_SIZE           60
407 #define HCI_SCO_2EV5_SIZE          360
408 #define HCI_SCO_3EV3_SIZE           90
409 #define HCI_SCO_3EV5_SIZE          540
410 
411 #define LE_ADVERTISING_DATA_SIZE    31
412 #define LE_EXTENDED_ADVERTISING_DATA_SIZE    229
413 #define LE_EXTENDED_ADVERTISING_LEGACY_HANDLE 0
414 #define LE_EXTENDED_ADVERTISING_MAX_HANDLE 0xEFu
415 #define LE_EXTENDED_ADVERTISING_MAX_CHUNK_LEN 251
416 
417 // advertising event properties for extended advertising
418 #define LE_ADVERTISING_PROPERTIES_CONNECTABLE      (1u<<0)
419 #define LE_ADVERTISING_PROPERTIES_SCANNABLE        (1u<<1)
420 #define LE_ADVERTISING_PROPERTIES_DIRECTED         (1u<<2)
421 #define LE_ADVERTISING_PROPERTIES_HIGH_DUTY_CYCLE  (1u<<3)
422 #define LE_ADVERTISING_PROPERTIES_LEGACY           (1u<<4)
423 #define LE_ADVERTISING_PROPERTIES_ANONYMOUS        (1u<<5)
424 #define LE_ADVERTISING_PROPERTIES_INCLUDE_TX_POWER (1u<<6)
425 
426 // ACL Packet Types
427 #define ACL_PACKET_TYPES_NONE       0x0000
428 #define ACL_PACKET_TYPES_2DH1       0x0002
429 #define ACL_PACKET_TYPES_3DH1       0x0004
430 #define ACL_PACKET_TYPES_DM1        0x0008
431 #define ACL_PACKET_TYPES_DH1        0x0010
432 #define ACL_PACKET_TYPES_2DH3       0x0100
433 #define ACL_PACKET_TYPES_3DH3       0x0200
434 #define ACL_PACKET_TYPES_DM3        0x0400
435 #define ACL_PACKET_TYPES_DH3        0x0800
436 #define ACL_PACKET_TYPES_2DH5       0x1000
437 #define ACL_PACKET_TYPES_3DH5       0x2000
438 #define ACL_PACKET_TYPES_DM5        0x4000
439 #define ACL_PACKET_TYPES_DH5        0x8000
440 #define ACL_PACKET_TYPES_BR         (ACL_PACKET_TYPES_DM1  | ACL_PACKET_TYPES_DH1  | ACL_PACKET_TYPES_DM3  | ACL_PACKET_TYPES_DH3 | ACL_PACKET_TYPES_DM5 | ACL_PACKET_TYPES_DH5)
441 #define ACL_PACKET_TYPES_EDR2       (ACL_PACKET_TYPES_2DH1 | ACL_PACKET_TYPES_2DH3 | ACL_PACKET_TYPES_2DH5)
442 #define ACL_PACKET_TYPES_EDR3       (ACL_PACKET_TYPES_3DH1 | ACL_PACKET_TYPES_3DH3 | ACL_PACKET_TYPES_3DH5)
443 #define ACL_PACKET_TYPES_SLOTS1     (ACL_PACKET_TYPES_DM1  | ACL_PACKET_TYPES_DH1  | ACL_PACKET_TYPES_2DH1 | ACL_PACKET_TYPES_3DH1)
444 #define ACL_PACKET_TYPES_SLOTS3     (ACL_PACKET_TYPES_DM3  | ACL_PACKET_TYPES_DH3  | ACL_PACKET_TYPES_2DH3 | ACL_PACKET_TYPES_3DH3)
445 #define ACL_PACKET_TYPES_SLOTS5     (ACL_PACKET_TYPES_DM5  | ACL_PACKET_TYPES_DH5  | ACL_PACKET_TYPES_2DH5 | ACL_PACKET_TYPES_3DH5)
446 #define ACL_PACKET_TYPES_ALL        (ACL_PACKET_TYPES_BR   | ACL_PACKET_TYPES_EDR2 | ACL_PACKET_TYPES_EDR3)
447 
448 // SCO Packet Types
449 #define SCO_PACKET_TYPES_NONE  0x0000
450 #define SCO_PACKET_TYPES_HV1   0x0001
451 #define SCO_PACKET_TYPES_HV2   0x0002
452 #define SCO_PACKET_TYPES_HV3   0x0004
453 #define SCO_PACKET_TYPES_EV3   0x0008
454 #define SCO_PACKET_TYPES_EV4   0x0010
455 #define SCO_PACKET_TYPES_EV5   0x0020
456 #define SCO_PACKET_TYPES_2EV3  0x0040
457 #define SCO_PACKET_TYPES_3EV3  0x0080
458 #define SCO_PACKET_TYPES_2EV5  0x0100
459 #define SCO_PACKET_TYPES_3EV5  0x0200
460 #define SCO_PACKET_TYPES_ALL   0x03FF
461 #define SCO_PACKET_TYPES_SCO   0x0007
462 #define SCO_PACKET_TYPES_ESCO  0x03F8
463 
464 // Link Policy Settings
465 #define LM_LINK_POLICY_DISABLE_ALL_LM_MODES  0
466 #define LM_LINK_POLICY_ENABLE_ROLE_SWITCH    1
467 #define LM_LINK_POLICY_ENABLE_HOLD_MODE      2
468 #define LM_LINK_POLICY_ENABLE_SNIFF_MODE     4
469 
470 // ACL Connection Modes
471 #define ACL_CONNECTION_MODE_ACTIVE 0
472 #define ACL_CONNECTION_MODE_HOLD   1
473 #define ACL_CONNECTION_MODE_SNIFF  2
474 
475 /**
476  * Default INQ Mode
477  */
478 #define GAP_IAC_GENERAL_INQUIRY 0x9E8B33L // General/Unlimited Inquiry Access Code (GIAC)
479 #define GAP_IAC_LIMITED_INQUIRY 0x9E8B00L // Limited Dedicated Inquiry Access Code (LIAC)
480 
481 /**
482  * SSP IO Capabilities
483  */
484 #define SSP_IO_CAPABILITY_DISPLAY_ONLY   0
485 #define SSP_IO_CAPABILITY_DISPLAY_YES_NO 1
486 #define SSP_IO_CAPABILITY_KEYBOARD_ONLY  2
487 #define SSP_IO_CAPABILITY_NO_INPUT_NO_OUTPUT 3
488 #define SSP_IO_CAPABILITY_UNKNOWN 0xff
489 
490 
491 /**
492  * SSP Authentication Requirements, see IO Capability Request Reply Commmand
493  */
494 
495 // Numeric comparison with automatic accept allowed.
496 #define SSP_IO_AUTHREQ_MITM_PROTECTION_NOT_REQUIRED_NO_BONDING 0x00
497 
498 // Use IO Capabilities to deter- mine authentication procedure
499 #define SSP_IO_AUTHREQ_MITM_PROTECTION_REQUIRED_NO_BONDING 0x01
500 
501 // Numeric compar- ison with automatic accept allowed.
502 #define SSP_IO_AUTHREQ_MITM_PROTECTION_NOT_REQUIRED_DEDICATED_BONDING 0x02
503 
504 // Use IO Capabilities to determine authentication procedure
505 #define SSP_IO_AUTHREQ_MITM_PROTECTION_REQUIRED_DEDICATED_BONDING 0x03
506 
507 // Numeric Compari- son with automatic accept allowed.
508 #define SSP_IO_AUTHREQ_MITM_PROTECTION_NOT_REQUIRED_GENERAL_BONDING 0x04
509 
510 // Use IO capabilities to determine authentication procedure.
511 #define SSP_IO_AUTHREQ_MITM_PROTECTION_REQUIRED_GENERAL_BONDING 0x05
512 
513 
514 // OGFs
515 #define OGF_LINK_CONTROL          0x01
516 #define OGF_LINK_POLICY           0x02
517 #define OGF_CONTROLLER_BASEBAND   0x03
518 #define OGF_INFORMATIONAL_PARAMETERS 0x04
519 #define OGF_STATUS_PARAMETERS     0x05
520 #define OGF_TESTING               0x06
521 #define OGF_LE_CONTROLLER 0x08
522 #define OGF_VENDOR  0x3f
523 
524 
525 
526 
527 /**
528  * L2CAP Layer
529  */
530 
531 #define L2CAP_HEADER_SIZE 4
532 
533 // minimum signaling MTU
534 #define L2CAP_MINIMAL_MTU 48
535 #define L2CAP_DEFAULT_MTU 672
536 
537 // Minimum/default MTU
538 #define L2CAP_LE_DEFAULT_MTU  23
539 
540 // L2CAP Fixed Channel IDs
541 #define L2CAP_CID_SIGNALING                        0x0001
542 #define L2CAP_CID_CONNECTIONLESS_CHANNEL           0x0002
543 #define L2CAP_CID_ATTRIBUTE_PROTOCOL               0x0004
544 #define L2CAP_CID_SIGNALING_LE                     0x0005
545 #define L2CAP_CID_SECURITY_MANAGER_PROTOCOL        0x0006
546 #define L2CAP_CID_BR_EDR_SECURITY_MANAGER          0x0007
547 
548 // L2CAP Channels in Basic and Enhanced Retransmission Mode
549 
550 // connection response result
551 #define L2CAP_CONNECTION_RESULT_SUCCESS                         0x0000
552 #define L2CAP_CONNECTION_RESULT_PENDING                         0x0001
553 #define L2CAP_CONNECTION_RESULT_PSM_NOT_SUPPORTED               0x0002
554 #define L2CAP_CONNECTION_RESULT_SECURITY_BLOCK                  0x0003
555 #define L2CAP_CONNECTION_RESULT_NO_RESOURCES_AVAILABLE          0x0004
556 #define L2CAP_CONNECTION_RESULT_INVALID_SOURCE_CID              0x0006
557 #define L2CAP_CONNECTION_RESULT_SOURCE_CID_ALREADY_ALLOCATED    0x0007
558 
559 // L2CAP Channels in LE Credit-Based Flow-Control Mode
560 
561 // connection response result
562 #define L2CAP_CBM_CONNECTION_RESULT_SUCCESS                         0x0000
563 #define L2CAP_CBM_CONNECTION_RESULT_SPSM_NOT_SUPPORTED              0x0002
564 #define L2CAP_CBM_CONNECTION_RESULT_NO_RESOURCES_AVAILABLE          0x0004
565 #define L2CAP_CBM_CONNECTION_RESULT_INSUFFICIENT_AUTHENTICATION     0x0005
566 #define L2CAP_CBM_CONNECTION_RESULT_INSUFFICIENT_AUTHORIZATION      0x0006
567 #define L2CAP_CBM_CONNECTION_RESULT_ENCYRPTION_KEY_SIZE_TOO_SHORT   0x0007
568 #define L2CAP_CBM_CONNECTION_RESULT_INSUFFICIENT_ENCRYPTION         0x0008
569 #define L2CAP_CBM_CONNECTION_RESULT_INVALID_SOURCE_CID              0x0009
570 #define L2CAP_CBM_CONNECTION_RESULT_SOURCE_CID_ALREADY_ALLOCATED    0x000A
571 #define L2CAP_CBM_CONNECTION_RESULT_UNACCEPTABLE_PARAMETERS         0x000B
572 
573 
574 // L2CAP Channels in Enhanced Credit-Based Flow-Control Mode
575 
576 // number of CIDs in single connection+reconfiguration request/response
577 #define L2CAP_ECBM_MAX_CID_ARRAY_SIZE        5
578 
579 // connection response result
580 #define L2CAP_ECBM_CONNECTION_RESULT_ALL_SUCCESS                                    0x0000
581 #define L2CAP_ECBM_CONNECTION_RESULT_ALL_REFUSED_SPSM_NOT_SUPPORTED                 0x0002
582 #define L2CAP_ECBM_CONNECTION_RESULT_SOME_REFUSED_INSUFFICIENT_RESOURCES_AVAILABLE  0x0004
583 #define L2CAP_ECBM_CONNECTION_RESULT_ALL_REFUSED_INSUFFICIENT_AUTHENTICATION        0x0005
584 #define L2CAP_ECBM_CONNECTION_RESULT_ALL_REFUSED_INSUFFICIENT_AUTHORIZATION         0x0006
585 #define L2CAP_ECBM_CONNECTION_RESULT_ALL_REFUSED_ENCYRPTION_KEY_SIZE_TOO_SHORT      0x0007
586 #define L2CAP_ECBM_CONNECTION_RESULT_ALL_REFUSED_INSUFFICIENT_ENCRYPTION            0x0008
587 #define L2CAP_ECBM_CONNECTION_RESULT_SOME_REFUSED_INVALID_SOURCE_CID                0x0009
588 #define L2CAP_ECBM_CONNECTION_RESULT_SOME_REFUSED_SOURCE_CID_ALREADY_ALOCATED       0x000A
589 #define L2CAP_ECBM_CONNECTION_RESULT_ALL_REFUSED_UNACCEPTABLE_PARAMETERS            0x000B
590 #define L2CAP_ECBM_CONNECTION_RESULT_ALL_REFUSED_INVALID_PARAMETERS                 0x000C
591 #define L2CAP_ECBM_CONNECTION_RESULT_ALL_PENDING_NO_FURTHER_INFORMATION             0x000D
592 #define L2CAP_ECBM_CONNECTION_RESULT_ALL_PENDING_AUTHENTICATION                     0x000E
593 #define L2CAP_ECBM_CONNECTION_RESULT_ALL_PENDING_AUTHORIZATION                      0x000F
594 
595 
596 // Result for Reconfigure Request
597 #define L2CAP_ECBM_RECONFIGURE_SUCCESS                                 0
598 #define L2CAP_ECBM_RECONFIGURE_FAILED_MTU_REDUCTION_NOT_ALLOWED        1
599 #define L2CAP_ECBM_RECONFIGURE_FAILED_MPS_REDUCTION_MULTIPLE_CHANNELS  2
600 #define L2CAP_ECBM_RECONFIGURE_FAILED_DESTINATION_CID_INVALID          3
601 #define L2CAP_ECBM_RECONFIGURE_FAILED_UNACCEPTABLE_PARAMETERS          4
602 
603 /**
604  * SDP Protocol
605  */
606 
607 // Device Vendor ID Sources
608 #define DEVICE_ID_VENDOR_ID_SOURCE_BLUETOOTH 0x0001
609 #define DEVICE_ID_VENDOR_ID_SOURCE_USB       0x0002
610 
611 // OBEX
612 #define SDP_vCard_2_1       0x01
613 #define SDP_vCard_3_0       0x02
614 #define SDP_vCal_1_0        0x03
615 #define SDP_iCal_2_0        0x04
616 #define SDP_vNote           0x05
617 #define SDP_vMessage        0x06
618 #define SDP_OBEXFileTypeAny 0xFF
619 
620 /**
621  * RFCOMM Protocol
622  */
623 
624 // Line Status
625 #define LINE_STATUS_NO_ERROR       0x00
626 #define LINE_STATUS_OVERRUN_ERROR  0x03
627 #define LINE_STATUS_PARITY_ERORR   0x05
628 #define LINE_STATUS_FRAMING_ERROR  0x09
629 
630 // Modem Status Flags
631 #define MODEM_STATUS_FC   0x02
632 #define MODEM_STATUS_RTC  0x04
633 #define MODEM_STATUS_RTR  0x08
634 #define MODEM_STATUS_IC   0x40
635 #define MODEM_STATUS_DV   0x80
636 
637 typedef enum rpn_baud {
638     RPN_BAUD_2400 = 0,
639     RPN_BAUD_4800,
640     RPN_BAUD_7200,
641     RPN_BAUD_9600,
642     RPN_BAUD_19200,
643     RPN_BAUD_38400,
644     RPN_BAUD_57600,
645     RPN_BAUD_115200,
646     RPN_BAUD_230400
647 } rpn_baud_t;
648 
649 typedef enum rpn_data_bits {
650     RPN_DATA_BITS_5 = 0,
651     RPN_DATA_BITS_6 = 0,
652     RPN_DATA_BITS_7 = 0,
653     RPN_DATA_BITS_8 = 0
654 } rpn_data_bits_t;
655 
656 typedef enum rpn_stop_bits {
657     RPN_STOP_BITS_1_0 = 0,
658     RPN_STOP_BITS_1_5
659 } rpn_stop_bits_t;
660 
661 typedef enum rpn_parity {
662     RPN_PARITY_NONE  = 0,
663     RPN_PARITY_ODD   = 1,
664     RPN_PARITY_EVEN  = 3,
665     RPN_PARITY_MARK  = 5,
666     RPN_PARITY_SPACE = 7,
667 } rpn_parity_t;
668 
669 #define RPN_FLOW_CONTROL_XONXOFF_ON_INPUT  0x01
670 #define RPN_FLOW_CONTROL_XONXOFF_ON_OUTPUT 0x02
671 #define RPN_FLOW_CONTROL_RTR_ON_INPUT      0x04
672 #define RPN_FLOW_CONTROL_RTR_ON_OUTPUT     0x08
673 #define RPN_FLOW_CONTROL_RTC_ON_INPUT      0x10
674 #define RPN_FLOW_CONTROL_RTC_ON_OUTPUT     0x20
675 
676 #define RPN_PARAM_MASK_0_BAUD             0x01
677 #define RPN_PARAM_MASK_0_DATA_BITS        0x02
678 #define RPN_PARAM_MASK_0_STOP_BITS        0x04
679 #define RPN_PARAM_MASK_0_PARITY           0x08
680 #define RPN_PARAM_MASK_0_PARITY_TYPE      0x10
681 #define RPN_PARAM_MASK_0_XON_CHAR         0x20
682 #define RPN_PARAM_MASK_0_XOFF_CHAR        0x40
683 #define RPN_PARAM_MASK_0_RESERVED         0x80
684 
685 // @note: values are identical to rpn_flow_control_t
686 #define RPN_PARAM_MASK_1_XONOFF_ON_INPUT  0x01
687 #define RPN_PARAM_MASK_1_XONOFF_ON_OUTPUT 0x02
688 #define RPN_PARAM_MASK_1_RTR_ON_INPUT     0x04
689 #define RPN_PARAM_MASK_1_RTR_ON_OUTPUT    0x08
690 #define RPN_PARAM_MASK_1_RTC_ON_INPUT     0x10
691 #define RPN_PARAM_MASK_1_RTC_ON_OUTPUT    0x20
692 #define RPN_PARAM_MASK_1_RESERVED_0       0x40
693 #define RPN_PARAM_MASK_1_RESERVED_1       0x80
694 
695 /**
696  * BNEP Protocol
697  */
698 
699 #ifndef ETHER_ADDR_LEN
700 #define ETHER_ADDR_LEN 6
701 #endif
702 
703 #ifndef ETHERTYPE_VLAN
704 #define ETHERTYPE_VLAN                                  0x8100 /* IEEE 802.1Q VLAN tag */
705 #endif
706 
707 #define BNEP_MTU_MIN                                    1691
708 
709 
710 /**
711  * PAN Profile
712  */
713 
714 typedef enum {
715     BNEP_SECURITY_NONE = 0x0000,
716     BNEP_SECURITY_SERVICE_LEVEL_ENFORCED,
717     BNEP_SECURITY_802_1X
718 } security_description_t;
719 
720 typedef enum {
721     PAN_NET_ACCESS_TYPE_PSTN = 0x0000,
722     PAN_NET_ACCESS_TYPE_ISDN,
723     PAN_NET_ACCESS_TYPE_DSL,
724     PAN_NET_ACCESS_TYPE_CABLE_MODEM,
725     PAN_NET_ACCESS_TYPE_10MB_ETHERNET,
726     PAN_NET_ACCESS_TYPE_100MB_ETHERNET,
727     PAN_NET_ACCESS_TYPE_4MB_TOKEN_RING,
728     PAN_NET_ACCESS_TYPE_16MB_TOKEN_RING,
729     PAN_NET_ACCESS_TYPE_100MB_TOKEN_RING,
730     PAN_NET_ACCESS_TYPE_FDDI,
731     PAN_NET_ACCESS_TYPE_GSM,
732     PAN_NET_ACCESS_TYPE_CDMA,
733     PAN_NET_ACCESS_TYPE_GPRS,
734     PAN_NET_ACCESS_TYPE_3G,
735     PAN_NET_ACCESS_TYPE_CELULAR,
736     PAN_NET_ACCESS_TYPE_OTHER = 0xFFFE,
737     PAN_NET_ACCESS_TYPE_NONE
738 } net_access_type_t;
739 
740 /**
741  * ATT
742  */
743 
744 // Minimum/default MTU
745 #define ATT_DEFAULT_MTU               23
746 
747 // MARK: ATT Error Codes
748 #define ATT_ERROR_SUCCESS                          0x00u
749 #define ATT_ERROR_INVALID_HANDLE                   0x01u
750 #define ATT_ERROR_READ_NOT_PERMITTED               0x02u
751 #define ATT_ERROR_WRITE_NOT_PERMITTED              0x03u
752 #define ATT_ERROR_INVALID_PDU                      0x04u
753 #define ATT_ERROR_INSUFFICIENT_AUTHENTICATION      0x05u
754 #define ATT_ERROR_REQUEST_NOT_SUPPORTED            0x06u
755 #define ATT_ERROR_INVALID_OFFSET                   0x07u
756 #define ATT_ERROR_INSUFFICIENT_AUTHORIZATION       0x08u
757 #define ATT_ERROR_PREPARE_QUEUE_FULL               0x09u
758 #define ATT_ERROR_ATTRIBUTE_NOT_FOUND              0x0au
759 #define ATT_ERROR_ATTRIBUTE_NOT_LONG               0x0bu
760 #define ATT_ERROR_INSUFFICIENT_ENCRYPTION_KEY_SIZE 0x0cu
761 #define ATT_ERROR_INVALID_ATTRIBUTE_VALUE_LENGTH   0x0du
762 #define ATT_ERROR_UNLIKELY_ERROR                   0x0eu
763 #define ATT_ERROR_INSUFFICIENT_ENCRYPTION          0x0fu
764 #define ATT_ERROR_UNSUPPORTED_GROUP_TYPE           0x10u
765 #define ATT_ERROR_INSUFFICIENT_RESOURCES           0x11u
766 #define ATT_ERROR_VALUE_NOT_ALLOWED                0x13u
767 
768 // MARK: ATT Error Codes defined by BTstack
769 #define ATT_ERROR_HCI_DISCONNECT_RECEIVED          0x1fu
770 #define ATT_ERROR_BONDING_INFORMATION_MISSING      0x70u
771 #define ATT_ERROR_DATA_MISMATCH                    0x7eu
772 #define ATT_ERROR_TIMEOUT                          0x7Fu
773 #define ATT_ERROR_WRITE_RESPONSE_PENDING           0x100u
774 
775 // MARK: ATT Error Codes from Bluetooth Core Specification Supplement, Version 9 or later
776 #define ATT_ERROR_WRITE_REQUEST_REJECTED                                                      0xFCu
777 #define ATT_ERROR_CLIENT_CHARACTERISTIC_CONFIGURATION_DESCRIPTOR_IMPROPERLY_CONFIGURED        0xFDu
778 #define ATT_ERROR_PROCEDURE_ALREADY_IN_PROGRESS                                               0xFEu
779 #define ATT_ERROR_OUT_OF_RANGE                                                                0xFFu
780 
781 // MARK: ATT Error Codes from Cycling Power Service spec
782 #define CYCLING_POWER_ERROR_CODE_INAPPROPRIATE_CONNECTION_PARAMETERS                          0x80u
783 #define CYCLING_POWER_ERROR_CODE_PROCEDURE_ALREADY_IN_PROGRESS                                0xFEu
784 #define CYCLING_POWER_ERROR_CODE_CCC_DESCRIPTOR_IMPROPERLY_CONFIGURED                         0xFDu
785 
786 // MARK: ATT Error Codes from Cycling Speed and Cadence Service spec
787 #define CYCLING_SPEED_AND_CADENCE_ERROR_CODE_PROCEDURE_ALREADY_IN_PROGRESS                    0x80u
788 #define CYCLING_SPEED_AND_CADENCE_ERROR_CODE_CCC_DESCRIPTOR_IMPROPERLY_CONFIGURED             0x81u
789 
790 
791 // MARK: Attribute Property Flags
792 #define ATT_PROPERTY_BROADCAST           0x01
793 #define ATT_PROPERTY_READ                0x02
794 #define ATT_PROPERTY_WRITE_WITHOUT_RESPONSE 0x04
795 #define ATT_PROPERTY_WRITE               0x08
796 #define ATT_PROPERTY_NOTIFY              0x10
797 #define ATT_PROPERTY_INDICATE            0x20
798 #define ATT_PROPERTY_AUTHENTICATED_SIGNED_WRITE 0x40
799 #define ATT_PROPERTY_EXTENDED_PROPERTIES 0x80
800 
801 // MARK: Attribute Property Flag, BTstack extension
802 // value is asked from client
803 #define ATT_PROPERTY_DYNAMIC             0x100
804 
805 // Security levels
806 #define ATT_SECURITY_NONE 0
807 #define ATT_SECURITY_ENCRYPTED 1
808 #define ATT_SECURITY_AUTHENTICATED 2
809 #define ATT_SECURITY_AUTHORIZED 3
810 #define ATT_SECURITY_AUTHENTICATED_SC 4
811 
812 // ATT Transaction Timeout of 30 seconds for Command/Response or Indication/Confirmation
813 #define ATT_TRANSACTION_TIMEOUT_MS     30000
814 
815 #define ATT_TRANSACTION_MODE_NONE      0x0
816 #define ATT_TRANSACTION_MODE_ACTIVE    0x1
817 #define ATT_TRANSACTION_MODE_EXECUTE   0x2
818 #define ATT_TRANSACTION_MODE_CANCEL    0x3
819 #define ATT_TRANSACTION_MODE_VALIDATE  0x4
820 
821 // MARK: GATT UUIDs
822 #define GATT_PRIMARY_SERVICE_UUID                   0x2800
823 #define GATT_SECONDARY_SERVICE_UUID                 0x2801
824 #define GATT_INCLUDE_SERVICE_UUID                   0x2802
825 #define GATT_CHARACTERISTICS_UUID                   0x2803
826 #define GATT_CHARACTERISTIC_EXTENDED_PROPERTIES     0x2900
827 #define GATT_CHARACTERISTIC_USER_DESCRIPTION        0x2901
828 #define GATT_CLIENT_CHARACTERISTICS_CONFIGURATION   0x2902
829 #define GATT_SERVER_CHARACTERISTICS_CONFIGURATION   0x2903
830 #define GATT_CHARACTERISTIC_PRESENTATION_FORMAT     0x2904
831 #define GATT_CHARACTERISTIC_AGGREGATE_FORMAT        0x2905
832 #define GATT_CLIENT_SUPPORTED_FEATURES              0x2B29
833 #define GATT_SERVER_SUPPORTED_FEATURES              0x2B3A
834 
835 #define GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_NONE          0
836 #define GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_NOTIFICATION  1
837 #define GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_INDICATION    2
838 
839 #define GATT_CLIENT_ANY_CONNECTION      0xffff
840 #define GATT_CLIENT_ANY_VALUE_HANDLE    0x0000
841 
842 // GAP Service and Characteristics
843 #define GAP_SERVICE_UUID               0x1800
844 #define GAP_DEVICE_NAME_UUID           0x2a00
845 #define GAP_APPEARANCE_UUID            0x2a01
846 #define GAP_PERIPHERAL_PRIVACY_FLAG    0x2a02
847 #define GAP_RECONNECTION_ADDRESS_UUID  0x2a03
848 #define GAP_PERIPHERAL_PREFERRED_CONNECTION_PARAMETERS_UUID 0x2a04
849 #define GAP_SERVICE_CHANGED            0x2a05
850 
851 // Bluetooth GATT types
852 
853 typedef struct {
854     uint16_t year;      // 0 - year  is not known; or [1582,9999]
855     uint8_t  month;     // 0 - month is not known; or [1,12]
856     uint8_t  day;       // 0 - day   is not known; or [1,31]
857     uint8_t  hours;     // [0,23]
858     uint8_t  minutes;   // [0,59]
859     uint8_t  seconds;   // [0,59]
860 } gatt_date_time_t;
861 
862 typedef enum {
863     GATT_MICROPHONE_CONTROL_MUTE_OFF = 0x00,
864     GATT_MICROPHONE_CONTROL_MUTE_ON,
865     GATT_MICROPHONE_CONTROL_MUTE_DISABLED
866 } gatt_microphone_control_mute_t;
867 
868 /**
869  * SM - LE Security Manager
870  */
871 // Bluetooth Spec definitions
872 typedef enum {
873     SM_CODE_PAIRING_REQUEST = 0X01,
874     SM_CODE_PAIRING_RESPONSE,
875     SM_CODE_PAIRING_CONFIRM,
876     SM_CODE_PAIRING_RANDOM,
877     SM_CODE_PAIRING_FAILED,
878     SM_CODE_ENCRYPTION_INFORMATION,
879     SM_CODE_MASTER_IDENTIFICATION,
880     SM_CODE_IDENTITY_INFORMATION,
881     SM_CODE_IDENTITY_ADDRESS_INFORMATION,
882     SM_CODE_SIGNING_INFORMATION,
883     SM_CODE_SECURITY_REQUEST,
884     SM_CODE_PAIRING_PUBLIC_KEY,
885     SM_CODE_PAIRING_DHKEY_CHECK,
886     SM_CODE_KEYPRESS_NOTIFICATION,
887 } SECURITY_MANAGER_COMMANDS;
888 
889 // IO Capability Values
890 typedef enum {
891     IO_CAPABILITY_DISPLAY_ONLY = 0,
892     IO_CAPABILITY_DISPLAY_YES_NO,
893     IO_CAPABILITY_KEYBOARD_ONLY,
894     IO_CAPABILITY_NO_INPUT_NO_OUTPUT,
895     IO_CAPABILITY_KEYBOARD_DISPLAY, // not used by secure simple pairing
896 } io_capability_t;
897 
898 // Authentication requirement flags
899 #define SM_AUTHREQ_NO_BONDING        0x00
900 #define SM_AUTHREQ_BONDING           0x01
901 #define SM_AUTHREQ_MITM_PROTECTION   0x04
902 #define SM_AUTHREQ_SECURE_CONNECTION 0x08
903 #define SM_AUTHREQ_KEYPRESS          0x10
904 #define SM_AUTHREQ_CT2               0x20
905 
906 // Key distribution flags used by spec
907 #define SM_KEYDIST_ENC_KEY  0x01
908 #define SM_KEYDIST_ID_KEY   0x02
909 #define SM_KEYDIST_SIGN     0x04
910 #define SM_KEYDIST_LINK_KEY 0x08
911 
912 // Key distribution flags used internally
913 #define SM_KEYDIST_FLAG_ENCRYPTION_INFORMATION       0x01
914 #define SM_KEYDIST_FLAG_MASTER_IDENTIFICATION        0x02
915 #define SM_KEYDIST_FLAG_IDENTITY_INFORMATION         0x04
916 #define SM_KEYDIST_FLAG_IDENTITY_ADDRESS_INFORMATION 0x08
917 #define SM_KEYDIST_FLAG_SIGNING_IDENTIFICATION       0x10
918 
919 // STK Generation Methods
920 #define SM_STK_GENERATION_METHOD_JUST_WORKS          0x01
921 #define SM_STK_GENERATION_METHOD_OOB                 0x02
922 #define SM_STK_GENERATION_METHOD_PASSKEY             0x04
923 #define SM_STK_GENERATION_METHOD_NUMERIC_COMPARISON  0x08
924 
925 // Pairing Failed Reasons
926 #define SM_REASON_RESERVED                     0x00
927 #define SM_REASON_PASSKEY_ENTRY_FAILED         0x01
928 #define SM_REASON_OOB_NOT_AVAILABLE            0x02
929 #define SM_REASON_AUTHENTHICATION_REQUIREMENTS 0x03
930 #define SM_REASON_CONFIRM_VALUE_FAILED         0x04
931 #define SM_REASON_PAIRING_NOT_SUPPORTED        0x05
932 #define SM_REASON_ENCRYPTION_KEY_SIZE          0x06
933 #define SM_REASON_COMMAND_NOT_SUPPORTED        0x07
934 #define SM_REASON_UNSPECIFIED_REASON           0x08
935 #define SM_REASON_REPEATED_ATTEMPTS            0x09
936 #define SM_REASON_INVALID_PARAMETERS           0x0a
937 #define SM_REASON_DHKEY_CHECK_FAILED           0x0b
938 #define SM_REASON_NUMERIC_COMPARISON_FAILED    0x0c
939 #define SM_REASON_BR_EDR_PAIRING_IN_PROGRESS   0x0d
940 #define SM_REASON_CROSS_TRANSPORT_KEY_DERIVATION_NOT_ALLOWED 0x0e
941 #define SM_REASON_KEY_REJECTED                 0x0f
942 
943 // also, invalid parameters
944 // and reserved
945 
946 // Keypress Notifications
947 #define SM_KEYPRESS_PASSKEY_ENTRY_STARTED      0x00
948 #define SM_KEYPRESS_PASSKEY_DIGIT_ENTERED      0x01
949 #define SM_KEYPRESS_PASSKEY_DIGIT_ERASED       0x02
950 #define SM_KEYPRESS_PASSKEY_CLEARED            0x03
951 #define SM_KEYPRESS_PASSKEY_ENTRY_COMPLETED    0x04
952 
953 
954 #endif
955