xref: /btstack/port/stm32-wb55xx-nucleo-freertos/Middlewares/STM32_WPAN/ble/core/ble_defs.h (revision 0561b2d8d5dba972c7daa57d5e677f7a1327edfd)
1 /*****************************************************************************
2  * @file    ble_defs.h
3  * @author  MCD Application Team
4  * @brief   This file contains definitions used for BLE Stack interface.
5  *****************************************************************************
6  * @attention
7  *
8  * <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
9  * All rights reserved.</center></h2>
10  *
11  * This software component is licensed by ST under Ultimate Liberty license
12  * SLA0044, the "License"; You may not use this file except in compliance with
13  * the License. You may obtain a copy of the License at:
14  *                             www.st.com/SLA0044
15  *
16  ******************************************************************************
17  */
18 
19 #ifndef BLE_DEFS_H__
20 #define BLE_DEFS_H__
21 
22 
23 /* ------------------------------------------------------------------------- */
24 
25 
26 /* Status codes */
27 #define BLE_STATUS_SUCCESS                          0x00
28 #define BLE_STATUS_FAILED                           0x41
29 #define BLE_STATUS_INVALID_PARAMS                   0x42
30 #define BLE_STATUS_BUSY                             0x43
31 #define BLE_STATUS_INVALID_LEN_PDU                  0x44
32 #define BLE_STATUS_PENDING                          0x45
33 #define BLE_STATUS_NOT_ALLOWED                      0x46
34 #define BLE_STATUS_ERROR                            0x47
35 #define BLE_STATUS_ADDR_NOT_RESOLVED                0x48
36 #define BLE_STATUS_INVALID_CID                      0x50
37 #define TIMER_NOT_VALID_LAYER                       0x54
38 #define TIMER_INSUFFICIENT_RESOURCES                0x55
39 #define BLE_STATUS_CSRK_NOT_FOUND                   0x5A
40 #define BLE_STATUS_IRK_NOT_FOUND                    0x5B
41 #define BLE_STATUS_DEV_NOT_FOUND_IN_DB              0x5C
42 #define BLE_STATUS_SEC_DB_FULL                      0x5D
43 #define BLE_STATUS_DEV_NOT_BONDED                   0x5E
44 #define BLE_STATUS_DEV_IN_BLACKLIST                 0x5F
45 #define BLE_STATUS_INVALID_HANDLE                   0x60
46 #define BLE_STATUS_INVALID_PARAMETER                0x61
47 #define BLE_STATUS_OUT_OF_HANDLE                    0x62
48 #define BLE_STATUS_INVALID_OPERATION                0x63
49 #define BLE_STATUS_INSUFFICIENT_RESOURCES           0x64
50 #define BLE_INSUFFICIENT_ENC_KEYSIZE                0x65
51 #define BLE_STATUS_CHARAC_ALREADY_EXISTS            0x66
52 
53 /* Returned when no valid slots are available
54  * (e.g. when there are no available state machines).
55  */
56 #define BLE_STATUS_NO_VALID_SLOT                    0x82
57 
58 /* Returned when a scan window shorter than minimum allowed value has been
59  * requested (i.e. 2ms)
60  */
61 #define BLE_STATUS_SCAN_WINDOW_SHORT                0x83
62 
63 /* Returned when the maximum requested interval to be allocated is shorter
64  * then the current anchor period and a there is no submultiple for the
65  * current anchor period that is between the minimum and the maximum requested
66  * intervals.
67  */
68 #define BLE_STATUS_NEW_INTERVAL_FAILED              0x84
69 
70 /* Returned when the maximum requested interval to be allocated is greater
71  * than the current anchor period and there is no multiple of the anchor
72  * period that is between the minimum and the maximum requested intervals.
73  */
74 #define BLE_STATUS_INTERVAL_TOO_LARGE               0x85
75 
76 /* Returned when the current anchor period or a new one can be found that
77  * is compatible to the interval range requested by the new slot but the
78  * maximum available length that can be allocated is less than the minimum
79  * requested slot length.
80  */
81 #define BLE_STATUS_LENGTH_FAILED                    0x86
82 
83 /*
84  * Library Error Codes
85  */
86 #define BLE_STATUS_TIMEOUT                          0xFF
87 #define BLE_STATUS_PROFILE_ALREADY_INITIALIZED      0xF0
88 #define BLE_STATUS_NULL_PARAM                       0xF1
89 
90 
91 /* ------------------------------------------------------------------------- */
92 
93 
94 /* GAP UUIDs
95  */
96 #define GAP_SERVICE_UUID                           0x1800
97 #define DEVICE_NAME_UUID                           0x2A00
98 #define APPEARANCE_UUID                            0x2A01
99 #define PERIPHERAL_PRIVACY_FLAG_UUID               0x2A02
100 #define RECONNECTION_ADDR_UUID                     0x2A03
101 #define PERIPHERAL_PREFERRED_CONN_PARAMS_UUID      0x2A04
102 
103 
104 /* Characteristic value lengths
105  */
106 #define DEVICE_NAME_CHARACTERISTIC_LEN                  8
107 #define APPEARANCE_CHARACTERISTIC_LEN                   2
108 #define PERIPHERAL_PRIVACY_CHARACTERISTIC_LEN           1
109 #define RECONNECTION_ADDR_CHARACTERISTIC_LEN            6
110 #define PERIPHERAL_PREF_CONN_PARAMS_CHARACTERISTIC_LEN  8
111 
112 
113 /* Adv. lengths
114  */
115 #define MAX_ADV_DATA_LEN                               31
116 #define DEVICE_NAME_LEN                                 7
117 #define BD_ADDR_SIZE                                    6
118 
119 
120 /* AD types for adv. data and scan response data
121  */
122 #define AD_TYPE_FLAGS                              0x01
123 #define AD_TYPE_16_BIT_SERV_UUID                   0x02
124 #define AD_TYPE_16_BIT_SERV_UUID_CMPLT_LIST        0x03
125 #define AD_TYPE_32_BIT_SERV_UUID                   0x04
126 #define AD_TYPE_32_BIT_SERV_UUID_CMPLT_LIST        0x05
127 #define AD_TYPE_128_BIT_SERV_UUID                  0x06
128 #define AD_TYPE_128_BIT_SERV_UUID_CMPLT_LIST       0x07
129 #define AD_TYPE_SHORTENED_LOCAL_NAME               0x08
130 #define AD_TYPE_COMPLETE_LOCAL_NAME                0x09
131 #define AD_TYPE_TX_POWER_LEVEL                     0x0A
132 #define AD_TYPE_CLASS_OF_DEVICE                    0x0D
133 #define AD_TYPE_SEC_MGR_TK_VALUE                   0x10
134 #define AD_TYPE_SEC_MGR_OOB_FLAGS                  0x11
135 #define AD_TYPE_SLAVE_CONN_INTERVAL                0x12
136 #define AD_TYPE_SERV_SOLICIT_16_BIT_UUID_LIST      0x14
137 #define AD_TYPE_SERV_SOLICIT_128_BIT_UUID_LIST     0x15
138 #define AD_TYPE_SERVICE_DATA                       0x16
139 #define AD_TYPE_APPEARANCE                         0x19
140 #define AD_TYPE_ADVERTISING_INTERVAL               0x1A
141 #define AD_TYPE_LE_ROLE                            0x1C
142 #define AD_TYPE_SERV_SOLICIT_32_BIT_UUID_LIST      0x1F
143 #define AD_TYPE_URI                                0x24
144 #define AD_TYPE_MANUFACTURER_SPECIFIC_DATA         0xFF
145 
146 
147 /* Flag bits for Flags AD Type
148  */
149 #define FLAG_BIT_LE_LIMITED_DISCOVERABLE_MODE      0x01
150 #define FLAG_BIT_LE_GENERAL_DISCOVERABLE_MODE      0x02
151 #define FLAG_BIT_BR_EDR_NOT_SUPPORTED              0x04
152 #define FLAG_BIT_LE_BR_EDR_CONTROLLER              0x08
153 #define FLAG_BIT_LE_BR_EDR_HOST                    0x10
154 
155 
156 /* Privacy flag values
157  */
158 #define PRIVACY_ENABLED                          0x02
159 #define PRIVACY_DISABLED                         0x00
160 
161 
162 /* Intervals in terms of 625 micro sec
163  */
164 #define DIR_CONN_ADV_INT_MIN             0x190  /* 250 ms */
165 #define DIR_CONN_ADV_INT_MAX             0x320  /* 500 ms */
166 #define UNDIR_CONN_ADV_INT_MIN           0x800  /* 1.28 s */
167 #define UNDIR_CONN_ADV_INT_MAX           0x1000 /* 2.56 s */
168 #define LIM_DISC_ADV_INT_MIN             0x190  /* 250 ms */
169 #define LIM_DISC_ADV_INT_MAX             0x320  /* 500 ms */
170 #define GEN_DISC_ADV_INT_MIN             0x800  /* 1.28 s */
171 #define GEN_DISC_ADV_INT_MAX             0x1000 /* 2.56 s */
172 
173 
174 /* Timeout values
175  */
176 #define LIM_DISC_MODE_TIMEOUT            180000 /* 180 seconds */
177 #define PRIVATE_ADDR_INT_TIMEOUT         900000 /* 15 minutes */
178 
179 
180 /* GAP Roles
181  */
182 #define GAP_PERIPHERAL_ROLE               0x01
183 #define GAP_BROADCASTER_ROLE              0x02
184 #define GAP_CENTRAL_ROLE                  0x04
185 #define GAP_OBSERVER_ROLE                 0x08
186 
187 
188 /* GAP procedure codes
189  * Procedure codes for EVT_BLUE_GAP_PROCEDURE_COMPLETE event
190  * and aci_gap_terminate_gap_procedure() command.
191  */
192 #define GAP_LIMITED_DISCOVERY_PROC                   0x01
193 #define GAP_GENERAL_DISCOVERY_PROC                   0x02
194 #define GAP_NAME_DISCOVERY_PROC                      0x04
195 #define GAP_AUTO_CONNECTION_ESTABLISHMENT_PROC       0x08
196 #define GAP_GENERAL_CONNECTION_ESTABLISHMENT_PROC    0x10
197 #define GAP_SELECTIVE_CONNECTION_ESTABLISHMENT_PROC  0x20
198 #define GAP_DIRECT_CONNECTION_ESTABLISHMENT_PROC     0x40
199 #define GAP_OBSERVATION_PROC                         0x80
200 
201 
202 /* ------------------------------------------------------------------------- */
203 
204 
205 /* IO capabilities
206  */
207 #define IO_CAP_DISPLAY_ONLY                  0x00
208 #define IO_CAP_DISPLAY_YES_NO                0x01
209 #define IO_CAP_KEYBOARD_ONLY                 0x02
210 #define IO_CAP_NO_INPUT_NO_OUTPUT            0x03
211 #define IO_CAP_KEYBOARD_DISPLAY              0x04
212 
213 
214 /* Authentication requirements
215  */
216 #define NO_BONDING                           0x00
217 #define BONDING                              0x01
218 
219 
220 /* MITM protection requirements
221  */
222 #define MITM_PROTECTION_NOT_REQUIRED         0x00
223 #define MITM_PROTECTION_REQUIRED             0x01
224 
225 
226 /* Out-Of-Band data
227  */
228 #define OOB_AUTH_DATA_ABSENT                 0x00
229 #define OOB_AUTH_DATA_PRESENT                0x01
230 
231 
232 /* Authorization requirements
233  */
234 #define AUTHORIZATION_NOT_REQUIRED           0x00
235 #define AUTHORIZATION_REQUIRED               0x01
236 
237 
238 /* Connection authorization
239  */
240 #define CONNECTION_AUTHORIZED                0x01
241 #define CONNECTION_REJECTED                  0x02
242 
243 
244 /* Use fixed pin
245  */
246 #define USE_FIXED_PIN_FOR_PAIRING            0x00
247 #define DONOT_USE_FIXED_PIN_FOR_PAIRING      0x01
248 
249 
250 /* Link security status
251  */
252 #define SM_LINK_AUTHENTICATED                0x01
253 #define SM_LINK_AUTHORIZED                   0x02
254 #define SM_LINK_ENCRYPTED                    0x04
255 
256 
257 /* SMP pairing failed reason codes
258  */
259 #define PASSKEY_ENTRY_FAILED                 0x01
260 #define OOB_NOT_AVAILABLE                    0x02
261 #define AUTH_REQ_CANNOT_BE_MET               0x03
262 #define CONFIRM_VALUE_FAILED                 0x04
263 #define PAIRING_NOT_SUPPORTED                0x05
264 #define INSUFF_ENCRYPTION_KEY_SIZE           0x06
265 #define CMD_NOT_SUPPORTED                    0x07
266 #define UNSPECIFIED_REASON                   0x08
267 #define VERY_EARLY_NEXT_ATTEMPT              0x09
268 #define SM_INVALID_PARAMS                    0x0A
269 
270 
271 /* Pairing failed error codes
272  * Error codes in EVT_BLUE_GAP_PAIRING_CMPLT event
273  */
274 #define SM_PAIRING_SUCCESS                   0x00
275 #define SM_PAIRING_TIMEOUT                   0x01
276 #define SM_PAIRING_FAILED                    0x02
277 
278 
279 /* ------------------------------------------------------------------------- */
280 
281 
282 /* Well-Known UUIDs
283  */
284 #define PRIMARY_SERVICE_UUID                       0x2800
285 #define SECONDARY_SERVICE_UUID                     0x2801
286 #define INCLUDE_SERVICE_UUID                       0x2802
287 #define CHARACTERISTIC_UUID                        0x2803
288 #define CHAR_EXTENDED_PROP_DESC_UUID               0x2900
289 #define CHAR_USER_DESC_UUID                        0x2901
290 #define CHAR_CLIENT_CONFIG_DESC_UUID               0x2902
291 #define CHAR_SERVER_CONFIG_DESC_UUID               0x2903
292 #define CHAR_FORMAT_DESC_UUID                      0x2904
293 #define CHAR_AGGR_FMT_DESC_UUID                    0x2905
294 #define GATT_SERVICE_UUID                          0x1801
295 #define GAP_SERVICE_UUID                           0x1800
296 #define SERVICE_CHANGED_UUID                       0x2A05
297 
298 
299 /* Access permissions for an attribute
300  */
301 #define ATTR_NO_ACCESS                             0x00
302 #define ATTR_ACCESS_READ_ONLY                      0x01
303 #define ATTR_ACCESS_WRITE_REQ_ONLY                 0x02
304 #define ATTR_ACCESS_READ_WRITE                     0x03
305 #define ATTR_ACCESS_WRITE_WITHOUT_RESPONSE         0x04
306 #define ATTR_ACCESS_SIGNED_WRITE_ALLOWED           0x08
307 #define ATTR_ACCESS_WRITE_ANY                      0x0E
308 
309 
310 /* Characteristic properties.
311  */
312 #define CHAR_PROP_BROADCAST                      0x01
313 #define CHAR_PROP_READ                           0x02
314 #define CHAR_PROP_WRITE_WITHOUT_RESP             0x04
315 #define CHAR_PROP_WRITE                          0x08
316 #define CHAR_PROP_NOTIFY                         0x10
317 #define CHAR_PROP_INDICATE                       0x20
318 #define CHAR_PROP_SIGNED_WRITE                   0x40
319 #define CHAR_PROP_EXT                            0x80
320 
321 
322 /* Security permissions for an attribute.
323  */
324 #define ATTR_PERMISSION_NONE          0x00 /* No security. */
325 #define ATTR_PERMISSION_AUTHEN_READ   0x01 /* Need authentication to read */
326 #define ATTR_PERMISSION_AUTHOR_READ   0x02 /* Need authorization to read */
327 #define ATTR_PERMISSION_ENCRY_READ    0x04 /* Need encryption to read */
328 #define ATTR_PERMISSION_AUTHEN_WRITE  0x08 /* Need authentication to write */
329 #define ATTR_PERMISSION_AUTHOR_WRITE  0x10 /* Need authorization to write */
330 #define ATTR_PERMISSION_ENCRY_WRITE   0x20 /* Need encryption to write */
331 
332 
333 /* Type of UUID (16 bit or 128 bit.
334  */
335 #define UUID_TYPE_16                               0x01
336 #define UUID_TYPE_128                              0x02
337 
338 
339 /* Type of service (primary or secondary
340  */
341 #define PRIMARY_SERVICE                            0x01
342 #define SECONDARY_SERVICE                          0x02
343 
344 
345 /* Gatt Event Mask
346  * Type of event generated by GATT server
347  * See aci_gatt_add_char.
348  */
349 #define GATT_DONT_NOTIFY_EVENTS                       0x00
350 #define GATT_NOTIFY_ATTRIBUTE_WRITE                   0x01
351 #define GATT_NOTIFY_WRITE_REQ_AND_WAIT_FOR_APPL_RESP  0x02
352 #define GATT_NOTIFY_READ_REQ_AND_WAIT_FOR_APPL_RESP   0x04
353 
354 
355 /* Type of characteristic length
356  * See aci_gatt_add_char()
357  */
358 #define CHAR_VALUE_LEN_CONSTANT               0x00
359 #define CHAR_VALUE_LEN_VARIABLE               0x01
360 
361 
362 /* Encryption key size
363  */
364 #define MIN_ENCRY_KEY_SIZE                    7
365 #define MAX_ENCRY_KEY_SIZE                    0x10
366 
367 
368 /* Format
369  */
370 #define FORMAT_UINT8                          0x04
371 #define FORMAT_UINT16                         0x06
372 #define FORMAT_SINT16                         0x0E
373 #define FORMAT_SINT24                         0x0F
374 
375 
376 /* Unit
377  */
378 #define UNIT_UNITLESS                         0x2700
379 #define UNIT_TEMP_CELSIUS                     0x272F
380 #define UNIT_PRESSURE_BAR                     0x2780
381 
382 
383 /* ------------------------------------------------------------------------- */
384 
385 
386 /* Advertising policy for filtering (white list related)
387  * See hci_le_set_advertising_parameters
388  */
389 #define NO_WHITE_LIST_USE                      0x00
390 #define WHITE_LIST_FOR_ONLY_SCAN               0x01
391 #define WHITE_LIST_FOR_ONLY_CONN               0x02
392 #define WHITE_LIST_FOR_ALL                     0x03
393 
394 
395 /* Bluetooth address types
396  */
397 #define PUBLIC_ADDR                            0
398 #define RANDOM_ADDR                            1
399 #define STATIC_RANDOM_ADDR                     1
400 #define RESOLVABLE_PRIVATE_ADDR                2
401 #define NON_RESOLVABLE_PRIVATE_ADDR            3
402 
403 
404 /* Directed advertising types
405  * Type of advertising during directed advertising
406  */
407 #define HIGH_DUTY_CYCLE_DIRECTED_ADV           1
408 #define LOW_DUTY_CYCLE_DIRECTED_ADV            4
409 
410 
411 /* Advertising type
412  * See hci_le_set_advertising_parameters
413   */
414 #define ADV_IND                                0x00
415 #define ADV_DIRECT_IND                         0x01
416 #define ADV_SCAN_IND                           0x02
417 #define ADV_NONCONN_IND                        0x03
418 #define SCAN_RSP                               0x04
419 
420 
421 /* Lowest allowed interval value for connectable types(20ms)..multiple of 625us
422  */
423 #define ADV_INTERVAL_LOWEST_CONN               0X0020
424 
425 
426 /* Highest allowed interval value (10.24s)..multiple of 625us.
427  */
428 #define ADV_INTERVAL_HIGHEST                   0X4000
429 
430 
431 /* Lowest allowed interval value for non connectable types
432  * (100ms)..multiple of 625us.
433  */
434 #define ADV_INTERVAL_LOWEST_NONCONN            0X00a0
435 
436 
437 /* Advertising channels
438  */
439 #define ADV_CH_37                              0x01
440 #define ADV_CH_38                              0x02
441 #define ADV_CH_39                              0x04
442 
443 
444 /* Scan_types Scan types
445  */
446 #define PASSIVE_SCAN                           0
447 #define ACTIVE_SCAN                            1
448 
449 
450 /* ------------------------------------------------------------------------- */
451 
452 
453 /* Configuration values.
454  * See aci_hal_write_config_data().
455  */
456 #define CONFIG_DATA_PUBADDR_OFFSET            0x00
457 #define CONFIG_DATA_DIV_OFFSET                0x06
458 #define CONFIG_DATA_ER_OFFSET                 0x08
459 #define CONFIG_DATA_IR_OFFSET                 0x18
460 #define CONFIG_DATA_RANDOM_ADDRESS_OFFSET     0x2E
461 
462 /* Length for configuration values.
463  * See aci_hal_write_config_data().
464  */
465 #define CONFIG_DATA_PUBADDR_LEN               6
466 #define CONFIG_DATA_DIV_LEN                   2
467 #define CONFIG_DATA_ER_LEN                    16
468 #define CONFIG_DATA_IR_LEN                    16
469 #define CONFIG_DATA_RANDOM_ADDRESS_LEN        6
470 
471 
472 /* ------------------------------------------------------------------------- */
473 
474 
475 #endif /* BLE_DEFS_H__ */
476