1 /*****************************************************************************
2  * @file    ble_defs.h
3  * @author  MDG
4  * @brief   This file contains definitions used for BLE Stack interface.
5  *****************************************************************************
6  * @attention
7  *
8  * Copyright (c) 2018-2023 STMicroelectronics.
9  * All rights reserved.
10  *
11  * This software is licensed under terms that can be found in the LICENSE file
12  * in the root directory of this software component.
13  * If no LICENSE file comes with this software, it is provided AS-IS.
14  *
15  *****************************************************************************
16  */
17 
18 #ifndef BLE_DEFS_H__
19 #define BLE_DEFS_H__
20 
21 
22 /* ------------------------------------------------------------------------- */
23 
24 /* Status codes */
25 
26 /* Returned when the command has completed with success
27  */
28 #define BLE_STATUS_SUCCESS                              0x00U
29 
30 /* The remote device in in the Blacklist and the pairing operation it requested
31  * cannot be performed.
32  */
33 #define BLE_STATUS_DEV_IN_BLACKLIST                     0x59U
34 
35 /* CSRK not found during validation of an incoming signed packet
36  */
37 #define BLE_STATUS_CSRK_NOT_FOUND                       0x5AU
38 
39 /* IRK not found (Currently not used)
40  */
41 #define BLE_STATUS_IRK_NOT_FOUND                        0x5BU
42 
43 /* A search for a specific remote device was unsuccessful because no entry
44  * exists either into NVM Database or in volatile database.
45  */
46 #define BLE_STATUS_DEV_NOT_FOUND                        0x5CU
47 
48 /* The remote device is not bonded, and no operations related to bonded devices
49  * may be performed (e.g. writing Gatt Client data).
50  */
51 #define BLE_STATUS_DEV_NOT_BONDED                       0x5EU
52 
53 /* The attribute handle is invalid.
54  */
55 #define BLE_STATUS_INVALID_HANDLE                       0x60U
56 
57 /* There aren't sufficient Attributes handles available for allocation during
58  * creation of Services, Characteristics or Descriptors.
59  */
60 #define BLE_STATUS_OUT_OF_HANDLE                        0x61U
61 
62 /* The requested GATT operation is not allowed in this context/status or using
63  * the provided parameters.
64  * This is a specific GATT error, different from generic Not Allowed error,
65  * because it refers to specific GATT specifications/rules.
66  */
67 #define BLE_STATUS_INVALID_OPERATION                    0x62U
68 
69 /* The requested operation failed for a temporary lack of resources
70  * (e.g. packet pool or timers), but it may be retried later when resources may
71  * become available (packets or timers may have been released by other
72  * consumers).
73  */
74 #define BLE_STATUS_INSUFFICIENT_RESOURCES               0x64U
75 
76 /* Notification/Indication can't be sent to the requested remote device because
77  * it doesn't satisfy the needed security permission.
78  */
79 #define BLE_STATUS_SEC_PERMISSION_ERROR                 0x65U
80 
81 /* The address of the device could not be resolved using the IRK stored\n
82  */
83 #define BLE_STATUS_ADDRESS_NOT_RESOLVED                 0x70U
84 
85 /* Returned when no valid slots are available
86  * (e.g. when there are no available state machines).
87  */
88 #define BLE_STATUS_NO_VALID_SLOT                        0x82U
89 
90 /* The only slot available is not long enough to satisfy scan window request.
91  */
92 #define BLE_STATUS_SCAN_WINDOW_SHORT                    0x83U
93 
94 /* Returned when the maximum requested interval to be allocated is shorter
95  * then the current anchor period and there is no submultiple for the
96  * current anchor period that is between the minimum and the maximum requested
97  * intervals.
98  */
99 #define BLE_STATUS_NEW_INTERVAL_FAILED                  0x84U
100 
101 /* Returned when the maximum requested interval to be allocated is greater
102  * than the current anchor period and there is no multiple of the anchor
103  * period that is between the minimum and the maximum requested intervals.
104  */
105 #define BLE_STATUS_INTERVAL_TOO_LARGE                   0x85U
106 
107 /* Returned when the current anchor period or a new one can be found that
108  * is compatible to the interval range requested by the new slot but the
109  * maximum available length that can be allocated is less than the minimum
110  * requested slot length.
111  */
112 #define BLE_STATUS_LENGTH_FAILED                        0x86U
113 
114 /* The Host failed while performing the requested operation.
115  */
116 #define BLE_STATUS_FAILED                               0x91U
117 
118 /* Invalid parameters in Host commands
119  */
120 #define BLE_STATUS_INVALID_PARAMS                       0x92U
121 
122 /* The Host is already processing another request received in advance.
123  */
124 #define BLE_STATUS_BUSY                                 0x93U
125 
126 /* The operation requested cannot be completed immediately by the Host
127  * (usually because of lack of resources).
128  * The operation is generally put on hold by the caller and it's usually
129  * retried on later time.
130  */
131 #define BLE_STATUS_PENDING                              0x95U
132 
133 /* The requested operation violates the logic of the called layer/function or
134  * the format of the data to be processed during the operation.
135  */
136 #define BLE_STATUS_ERROR                                0x97U
137 
138 /* The requested operation failed because of lack of memory.
139  * Out of memory shall be returned for situations where memory will never
140  * become available again (e.g. ATT database)
141  */
142 #define BLE_STATUS_OUT_OF_MEMORY                        0x98U
143 
144 /* Returned when a timeout occurs at BLE application interface
145  */
146 #define BLE_STATUS_TIMEOUT                              0xFFU
147 
148 /* ------------------------------------------------------------------------- */
149 
150 /* Characteristic value lengths
151  */
152 #define DEVICE_NAME_CHARACTERISTIC_LEN                  8
153 #define APPEARANCE_CHARACTERISTIC_LEN                   2
154 #define PERIPHERAL_PRIVACY_CHARACTERISTIC_LEN           1
155 #define RECONNECTION_ADDR_CHARACTERISTIC_LEN            6
156 #define PERIPHERAL_PREF_CONN_PARAMS_CHARACTERISTIC_LEN  8
157 
158 /* Adv. lengths
159  */
160 #define MAX_ADV_DATA_LEN                              31U
161 #define BD_ADDR_SIZE                                   6U
162 
163 /* Privacy flag values
164  */
165 #define PRIVACY_DISABLED                              0x00
166 #define PRIVACY_ENABLED                               0x02
167 
168 /* Intervals in terms of 625 micro sec
169  */
170 #define DIR_CONN_ADV_INT_MIN                        0x190U  /* 250 ms */
171 #define DIR_CONN_ADV_INT_MAX                        0x320U  /* 500 ms */
172 #define UNDIR_CONN_ADV_INT_MIN                      0x800U  /* 1.28 s */
173 #define UNDIR_CONN_ADV_INT_MAX                     0x1000U  /* 2.56 s */
174 #define LIM_DISC_ADV_INT_MIN                        0x190U  /* 250 ms */
175 #define LIM_DISC_ADV_INT_MAX                        0x320U  /* 500 ms */
176 #define GEN_DISC_ADV_INT_MIN                        0x800U  /* 1.28 s */
177 #define GEN_DISC_ADV_INT_MAX                       0x1000U  /* 2.56 s */
178 
179 /* GAP Roles
180  */
181 #define GAP_PERIPHERAL_ROLE                          0x01U
182 #define GAP_BROADCASTER_ROLE                         0x02U
183 #define GAP_CENTRAL_ROLE                             0x04U
184 #define GAP_OBSERVER_ROLE                            0x08U
185 
186 /* GAP procedure codes
187  * Procedure codes for ACI_GAP_PROC_COMPLETE_EVENT event
188  * and ACI_GAP_TERMINATE_GAP_PROC command.
189  */
190 #define GAP_LIMITED_DISCOVERY_PROC                   0x01U
191 #define GAP_GENERAL_DISCOVERY_PROC                   0x02U
192 #define GAP_PERIODIC_ADVERTISING_CONNECTION_PROC     0x04U
193 #define GAP_AUTO_CONNECTION_ESTABLISHMENT_PROC       0x08U
194 #define GAP_GENERAL_CONNECTION_ESTABLISHMENT_PROC    0x10U
195 #define GAP_SELECTIVE_CONNECTION_ESTABLISHMENT_PROC  0x20U
196 #define GAP_DIRECT_CONNECTION_ESTABLISHMENT_PROC     0x40U
197 #define GAP_OBSERVATION_PROC                         0x80U
198 
199 /* GAP Address Type
200  */
201 #define GAP_PUBLIC_ADDR                              0x00U
202 #define GAP_STATIC_RANDOM_ADDR                       0x01U
203 #define GAP_RESOLVABLE_PRIVATE_ADDR                  0x02U
204 #define GAP_NON_RESOLVABLE_PRIVATE_ADDR              0x03U
205 
206 /* Bitmap definitions for Mode of ACI_GAP_ADD_DEVICES_TO_LIST
207  */
208 #define GAP_ADD_DEV_MODE_RESOLVING_LIST_ONLY         0x00U
209 #define GAP_ADD_DEV_MODE_CLEAR                       0x01U
210 #define GAP_ADD_DEV_MODE_FILTER_ACC_LIST_ONLY        0x02U
211 #define GAP_ADD_DEV_MODE_BOTH_LISTS                  0x04U
212 
213 /* ------------------------------------------------------------------------- */
214 
215 /* IO capabilities
216  * (ACI_GAP_SET_IO_CAPABILITY)
217  */
218 #define IO_CAP_DISPLAY_ONLY                        0x00U
219 #define IO_CAP_DISPLAY_YES_NO                      0x01U
220 #define IO_CAP_KEYBOARD_ONLY                       0x02U
221 #define IO_CAP_NO_INPUT_NO_OUTPUT                  0x03U
222 #define IO_CAP_KEYBOARD_DISPLAY                    0x04U
223 
224 /* Bonding mode
225  * (ACI_GAP_SET_AUTHENTICATION_REQUIREMENT)
226  */
227 #define NO_BONDING                                 0x00U
228 #define BONDING                                    0x01U
229 
230 /* MITM protection
231  * (ACI_GAP_SET_AUTHENTICATION_REQUIREMENT)
232  */
233 #define MITM_PROTECTION_NOT_REQUIRED               0x00U
234 #define MITM_PROTECTION_REQUIRED                   0x01U
235 
236 /* LE Secure Connections support
237  * (ACI_GAP_SET_AUTHENTICATION_REQUIREMENT)
238  */
239 #define SC_PAIRING_UNSUPPORTED                     0x00U
240 #define SC_PAIRING_OPTIONAL                        0x01U
241 #define SC_PAIRING_ONLY                            0x02U
242 
243 /* Keypress notification support
244  * (ACI_GAP_SET_AUTHENTICATION_REQUIREMENT)
245  */
246 #define KEYPRESS_NOT_SUPPORTED                     0x00U
247 #define KEYPRESS_SUPPORTED                         0x01U
248 
249 /* Use fixed pin
250  * (ACI_GAP_SET_AUTHENTICATION_REQUIREMENT)
251  */
252 #define USE_FIXED_PIN_FOR_PAIRING_ALLOWED          0x00U
253 #define USE_FIXED_PIN_FOR_PAIRING_FORBIDDEN        0x01U
254 
255 /* Authorization requirements
256  * (ACI_GAP_SET_AUTHORIZATION_REQUIREMENT)
257  */
258 #define AUTHORIZATION_NOT_REQUIRED                 0x00U
259 #define AUTHORIZATION_REQUIRED                     0x01U
260 
261 /* Connection authorization response
262  * (ACI_GAP_AUTHORIZATION_RESP)
263  */
264 #define CONNECTION_AUTHORIZED                      0x01U
265 #define CONNECTION_REJECTED                        0x02U
266 
267 /* SMP pairing status
268  * (ACI_GAP_PAIRING_COMPLETE_EVENT)
269  */
270 #define SMP_PAIRING_STATUS_SUCCESS                 0x00U
271 #define SMP_PAIRING_STATUS_SMP_TIMEOUT             0x01U
272 #define SMP_PAIRING_STATUS_PAIRING_FAILED          0x02U
273 #define SMP_PAIRING_STATUS_ENCRYPT_FAILED          0x03U
274 
275 /* SMP pairing failed reason code
276  * (ACI_GAP_PAIRING_COMPLETE_EVENT)
277  */
278 #define REASON_PASSKEY_ENTRY_FAILED                0x01U
279 #define REASON_OOB_NOT_AVAILABLE                   0x02U
280 #define REASON_AUTHENTICATION_REQ                  0x03U
281 #define REASON_CONFIRM_VALUE_FAILED                0x04U
282 #define REASON_PAIRING_NOT_SUPPORTED               0x05U
283 #define REASON_ENCRYPTION_KEY_SIZE                 0x06U
284 #define REASON_COMMAND_NOT_SUPPORTED               0x07U
285 #define REASON_UNSPECIFIED_REASON                  0x08U
286 #define REASON_REPEATED_ATTEMPTS                   0x09U
287 #define REASON_INVALID_PARAMETERS                  0x0AU
288 #define REASON_DHKEY_CHECK_FAILED                  0x0BU
289 #define REASON_NUM_COMPARISON_FAILED               0x0CU
290 #define REASON_KEY_REJECTED                        0x0FU
291 
292 /* Passkey input type detected
293  * (ACI_GAP_PASSKEY_INPUT)
294  */
295 #define PASSKEY_ENTRY_STARTED                      0x00U
296 #define PASSKEY_DIGIT_ENTERED                      0x01U
297 #define PASSKEY_DIGIT_ERASED                       0x02U
298 #define PASSKEY_CLEARED                            0x03U
299 #define PASSKEY_ENTRY_COMPLETED                    0x04U
300 
301 /* Numeric Comparison Confirm Value
302  * (ACI_GAP_NUMERIC_COMPARISON_VALUE_CONFIRM_YESNO)
303  */
304 #define NUMERIC_COMPARISON_CONFIRM_NO              0x00U
305 #define NUMERIC_COMPARISON_CONFIRM_YES             0x01U
306 
307 /* OOB Device Type
308  * (ACI_GAP_SET_OOB_DATA)
309  */
310 #define OOB_DEVICE_TYPE_LOCAL                      0x00U
311 #define OOB_DEVICE_TYPE_REMOTE                     0x01U
312 
313 /* OOB Data Type
314  * (ACI_GAP_GET_OOB_DATA, ACI_GAP_SET_OOB_DATA)
315  */
316 #define OOB_DATA_TYPE_LP_TK                        0x00U
317 #define OOB_DATA_TYPE_SC_RANDOM                    0x01U
318 #define OOB_DATA_TYPE_SC_CONFIRM                   0x02U
319 
320 /* ------------------------------------------------------------------------- */
321 
322 /* Access permissions for an attribute
323  */
324 #define ATTR_NO_ACCESS                           0x00U
325 #define ATTR_ACCESS_READ_ONLY                    0x01U
326 #define ATTR_ACCESS_WRITE_REQ_ONLY               0x02U
327 #define ATTR_ACCESS_READ_WRITE                   0x03U
328 #define ATTR_ACCESS_WRITE_WITHOUT_RESPONSE       0x04U
329 #define ATTR_ACCESS_SIGNED_WRITE_ALLOWED         0x08U
330 #define ATTR_ACCESS_WRITE_ANY                    0x0EU
331 #define ATTR_ACCESS_ANY                          0x0FU
332 
333 /* Characteristic properties
334  */
335 #define CHAR_PROP_NONE                           0x00U
336 #define CHAR_PROP_BROADCAST                      0x01U
337 #define CHAR_PROP_READ                           0x02U
338 #define CHAR_PROP_WRITE_WITHOUT_RESP             0x04U
339 #define CHAR_PROP_WRITE                          0x08U
340 #define CHAR_PROP_NOTIFY                         0x10u
341 #define CHAR_PROP_INDICATE                       0x20U
342 #define CHAR_PROP_SIGNED_WRITE                   0x40U
343 #define CHAR_PROP_EXT                            0x80U
344 
345 /* Security permissions for an attribute
346  */
347 #define ATTR_PERMISSION_NONE           0x00U /* No security. */
348 #define ATTR_PERMISSION_AUTHEN_READ    0x01U /* Need authentication to read */
349 #define ATTR_PERMISSION_AUTHOR_READ    0x02U /* Need authorization to read */
350 #define ATTR_PERMISSION_ENCRY_READ     0x04U /* Need encryption to read */
351 #define ATTR_PERMISSION_AUTHEN_WRITE   0x08U /* Need authentication to write */
352 #define ATTR_PERMISSION_AUTHOR_WRITE   0x10U /* Need authorization to write */
353 #define ATTR_PERMISSION_ENCRY_WRITE    0x20U /* Need encryption to write */
354 
355 /* Type of UUID (16 bit or 128 bit)
356  */
357 #define UUID_TYPE_16                             0x01U
358 #define UUID_TYPE_128                            0x02U
359 
360 /* Type of service (primary or secondary)
361  */
362 #define PRIMARY_SERVICE                          0x01U
363 #define SECONDARY_SERVICE                        0x02U
364 
365 /* Gatt Event Mask
366  * Type of event generated by GATT server
367  * See aci_gatt_add_char.
368  */
369 #define GATT_DONT_NOTIFY_EVENTS                       0x00U
370 #define GATT_NOTIFY_ATTRIBUTE_WRITE                   0x01U
371 #define GATT_NOTIFY_WRITE_REQ_AND_WAIT_FOR_APPL_RESP  0x02U
372 #define GATT_NOTIFY_READ_REQ_AND_WAIT_FOR_APPL_RESP   0x04U
373 #define GATT_NOTIFY_NOTIFICATION_COMPLETION           0x08U
374 
375 /* Type of characteristic length (see ACI_GATT_ADD_CHAR)
376  */
377 #define CHAR_VALUE_LEN_CONSTANT                  0x00
378 #define CHAR_VALUE_LEN_VARIABLE                  0x01
379 
380 /* Encryption key size
381  */
382 #define MIN_ENCRY_KEY_SIZE                       7U
383 #define MAX_ENCRY_KEY_SIZE                      16U
384 
385 /* Format
386  */
387 #define FORMAT_UINT8                             0x04U
388 #define FORMAT_UINT16                            0x06U
389 #define FORMAT_SINT16                            0x0EU
390 #define FORMAT_SINT24                            0x0FU
391 
392 /* Unit
393  */
394 #define UNIT_UNITLESS                          0x2700
395 #define UNIT_TEMP_CELSIUS                      0x272F
396 #define UNIT_PRESSURE_BAR                      0x2780
397 
398 /* Update_Type definitions for ACI_GATT_UPDATE_CHAR_VALUE_EXT
399  */
400 #define GATT_CHAR_UPDATE_LOCAL_ONLY                   0x00U
401 #define GATT_CHAR_UPDATE_SEND_NOTIFICATION            0x01U
402 #define GATT_CHAR_UPDATE_SEND_INDICATION              0x02U
403 
404 /* ------------------------------------------------------------------------- */
405 
406 /* Advertising Type
407  */
408 #define ADV_IND                                        0
409 #define ADV_DIRECT_IND                                 1
410 #define ADV_SCAN_IND                                   2
411 #define ADV_NONCONN_IND                                3
412 #define ADV_DIRECT_IND_LDC                             4
413 #define SCAN_RSP                                       4
414 
415 /* Advertising channels
416  */
417 #define ADV_CH_37                              0x01
418 #define ADV_CH_38                              0x02
419 #define ADV_CH_39                              0x04
420 
421 /* ------------------------------------------------------------------------- */
422 
423 /* Definitions for Radio_Activity_Mask
424  * (ACI_HAL_SET_RADIO_ACTIVITY_MASK)
425  */
426 #define RADIO_ACT_MASK_IDLE                        0x0001U
427 #define RADIO_ACT_MASK_ADVERTISING                 0x0002U
428 #define RADIO_ACT_MASK_PERIPH_CONNECT              0x0004U
429 #define RADIO_ACT_MASK_SCANNING                    0x0008U
430 #define RADIO_ACT_MASK_CENTR_CONNECT               0x0020U
431 #define RADIO_ACT_MASK_TX_TEST                     0x0040U
432 #define RADIO_ACT_MASK_RX_TEST                     0x0080U
433 #define RADIO_ACT_MASK_PERIOD_ADVERTISING          0x0200U
434 #define RADIO_ACT_MASK_PERIOD_SYNC                 0x0400U
435 #define RADIO_ACT_MASK_ISO_BROADCAST               0x0800U
436 #define RADIO_ACT_MASK_ISO_SYNC                    0x1000U
437 #define RADIO_ACT_MASK_ISO_PERIPH_CONNECT          0x2000U
438 #define RADIO_ACT_MASK_ISO_CENTR_CONNECT           0x4000U
439 
440 /* ------------------------------------------------------------------------- */
441 
442 /* Definitions for FW_Error_Type
443  * (ACI_HAL_FW_ERROR_EVENT)
444  */
445 #define FW_L2CAP_RECOMBINATION_ERROR                 0x01U
446 #define FW_GATT_UNEXPECTED_PEER_MESSAGE              0x02U
447 #define FW_NVM_LEVEL_WARNING                         0x03U
448 #define FW_COC_RX_DATA_LENGTH_TOO_LARGE              0x04U
449 #define FW_ECOC_CONN_RSP_ALREADY_ASSIGNED_DCID       0x05U
450 
451 /* ------------------------------------------------------------------------- */
452 
453 /* Offset for configuration values (see ACI_HAL_WRITE_CONFIG_DATA)
454  */
455 #define CONFIG_DATA_PUBADDR_OFFSET             0x00U
456 #define CONFIG_DATA_ER_OFFSET                  0x08U
457 #define CONFIG_DATA_IR_OFFSET                  0x18U
458 #define CONFIG_DATA_RANDOM_ADDRESS_OFFSET      0x2EU
459 #define CONFIG_DATA_GAP_ADD_REC_NBR_OFFSET     0x34U
460 #define CONFIG_DATA_SC_KEY_TYPE_OFFSET         0x35U
461 #define CONFIG_DATA_SMP_MODE_OFFSET            0xB0U
462 #define CONFIG_DATA_LL_SCAN_CHAN_MAP_OFFSET    0xC0U
463 #define CONFIG_DATA_LL_BG_SCAN_MODE_OFFSET     0xC1U
464 
465 /* Length for configuration values (see ACI_HAL_WRITE_CONFIG_DATA)
466  */
467 #define CONFIG_DATA_PUBADDR_LEN                6
468 #define CONFIG_DATA_ER_LEN                    16
469 #define CONFIG_DATA_IR_LEN                    16
470 #define CONFIG_DATA_RANDOM_ADDRESS_LEN         6
471 #define CONFIG_DATA_GAP_ADD_REC_NBR_LEN        1
472 #define CONFIG_DATA_SC_KEY_TYPE_LEN            1
473 #define CONFIG_DATA_SMP_MODE_LEN               1
474 #define CONFIG_DATA_LL_SCAN_CHAN_MAP_LEN       1
475 #define CONFIG_DATA_LL_BG_SCAN_MODE_LEN        1
476 
477 /* ------------------------------------------------------------------------- */
478 
479 
480 #endif /* BLE_DEFS_H__ */
481