1 /**
2   ******************************************************************************
3   * @file    ble_status.h
4   * @author  GPM WBL Application team
5   * @brief   Header file which contains definition of Bluetooth status and error codes.
6   * @note    Error Codes are defined according to Bluetooth Specifications
7   *              Vol.2 Part D.
8   *           - HCI/Controller standard codes range is [0x00 : 0x3F].
9   *             Their name is prefixed by "BLE_ERROR_"
10   *           - Host specific (and proprietary) error codes range is [0x80 : 0xFF].
11   *             Their name is prefixed by "BLE_STATUS_" and they're grouped by Layer
12   *           - BLE_STATUS_SUCCESS value is 0x00 and is the unique error code
13   *             used by both Controller and Host layers.
14   ******************************************************************************
15   * @attention
16   *
17   * Copyright (c) 2024 STMicroelectronics.
18   * All rights reserved.
19   *
20   * This software is licensed under terms that can be found in the LICENSE file
21   * in the root directory of this software component.
22   * If no LICENSE file comes with this software, it is provided AS-IS.
23   *
24   ******************************************************************************
25   */
26 
27 #ifndef __BLE_STATUS_H__
28 #define __BLE_STATUS_H__
29 
30 #include <stdint.h>
31 typedef uint8_t tBleStatus;
32 
33 /* @brief Standard Error Codes as specified by the Bluetooth Specifications
34  * Vol.2, Part D ("Error Codes").
35  * According to the spec the error codes range is from 0x00 to 0x3F.
36  */
37 #define BLE_STATUS_SUCCESS                          ((tBleStatus)(0x00))
38 
39 #define BLE_ERROR_UNKNOWN_HCI_COMMAND               ((tBleStatus)(0x01))
40 #define BLE_ERROR_UNKNOWN_CONNECTION_ID             ((tBleStatus)(0x02))
41 
42 #define BLE_ERROR_HARDWARE_FAILURE                  ((tBleStatus)(0x03))
43 
44 #define BLE_ERROR_AUTHENTICATION_FAILURE            ((tBleStatus)(0x05))
45 #define BLE_ERROR_KEY_MISSING                       ((tBleStatus)(0x06))
46 #define BLE_ERROR_MEMORY_CAPACITY_EXCEEDED          ((tBleStatus)(0x07))
47 #define BLE_ERROR_CONNECTION_TIMEOUT                ((tBleStatus)(0x08))
48 #define BLE_ERROR_CONN_LIMIT                        ((tBleStatus)(0x09))
49 
50 #define BLE_ERROR_CONNECTION_ALREADY_EXISTS         ((tBleStatus)(0x0B))
51 #define BLE_ERROR_COMMAND_DISALLOWED                ((tBleStatus)(0x0C))
52 
53 #define BLE_ERROR_CONN_REJECT_DUE_TO_LIMITED_RESOURCES ((tBleStatus)(0x0D))
54 
55 #define BLE_ERROR_CONNECTION_ACCEPT_TIMEOUT_EXCEEDED      ((tBleStatus)(0x10))
56 
57 #define BLE_ERROR_UNSUPPORTED_FEATURE               ((tBleStatus)(0x11))
58 
59 #define BLE_ERROR_INVALID_HCI_CMD_PARAMS            ((tBleStatus)(0x12))
60 
61 #define BLE_ERROR_TERMINATED_REMOTE_USER            ((tBleStatus)(0x13))
62 
63 #define BLE_ERROR_TERMINATED_LOCAL_HOST             ((tBleStatus)(0x16))
64 
65 #define BLE_ERROR_UNSUPP_RMT_FEATURE                ((tBleStatus)(0x1A))
66 
67 #define BLE_ERROR_INVALID_LMP_LL_PARAMS             ((tBleStatus)(0x1E))
68 
69 #define BLE_ERROR_UNSPECIFIED                       ((tBleStatus)(0x1F))
70 
71 #define BLE_ERROR_UNSUPP_LMP_LL_PARAM_VALUE         ((tBleStatus)(0x20))
72 
73 #define BLE_ERROR_LL_RESPONSE_TIMEOUT               ((tBleStatus)(0x22))
74 
75 #define BLE_ERROR_LL_PROCEDURE_COLLISION            ((tBleStatus)(0x23))
76 
77 #define BLE_ERROR_LMP_PDU_NOT_ALLOWED               ((tBleStatus)(0x24))
78 
79 #define BLE_ERROR_ENC_MODE_NOT_ACCEPTABLE           ((tBleStatus)(0x25))
80 
81 #define BLE_ERROR_INSTANT_PASSED                    ((tBleStatus)(0x28))
82 
83 #define BLE_ERROR_DIFFERENT_TRANSACTION_COLLISION   ((tBleStatus)(0x2A))
84 
85 #define BLE_ERROR_CHANNEL_ASSESSMENT_NOT_SUPPORTED  ((tBleStatus)(0x2E))
86 
87 #define BLE_ERROR_PARAMETER_OUT_OF_RANGE            ((tBleStatus)(0x30))
88 
89 #define BLE_ERROR_HOST_BUSY_PAIRING                 ((tBleStatus)(0x38))
90 
91 #define BLE_ERROR_CONTROLLER_BUSY                   ((tBleStatus)(0x3A))
92 
93 #define BLE_ERROR_UNACCEPTABLE_CONNECTION_PARAMS    ((tBleStatus)(0x3B))
94 
95 #define BLE_ERROR_ADVERTISING_TIMEOUT               ((tBleStatus)(0x3C))
96 
97 #define BLE_ERROR_CONNECTION_END_WITH_MIC_FAILURE   ((tBleStatus)(0x3D))
98 
99 #define BLE_ERROR_CONNECTION_FAILED_TO_ESTABLISH    ((tBleStatus)(0x3E))
100 
101 #define BLE_ERROR_COARSE_CLOCK_ADJ_REJECTED         ((tBleStatus)(0x40))
102 
103 #define BLE_ERROR_TYPE0_SUBMAP_NOT_DEFINED          ((tBleStatus)(0x41))
104 
105 #define BLE_ERROR_UNKNOWN_ADVERTISING_IDENTIFIER    ((tBleStatus)(0x42))
106 
107 #define BLE_ERROR_LIMIT_REACHED                     ((tBleStatus)(0x43))
108 
109 #define BLE_ERROR_OPERATION_CANCELLED_BY_HOST       ((tBleStatus)(0x44))
110 
111 #define BLE_ERROR_PACKET_TOO_LONG                   ((tBleStatus)(0x45))
112 
113 #define BLE_ERROR_TOO_LATE                          ((tBleStatus)(0x46))
114 
115 #define BLE_ERROR_TOO_EARLY                         ((tBleStatus)(0x47))
116 
117 
118 
119 /**
120 * @name Generic/System error codes
121 * @brief The error codes as reported by the different Protocol layers.
122 *        They start with 0x80
123 * @{
124 */
125 
126 /**
127  * @brief The Connection Identifier does not exist.
128  * Temporary remapped to corresponding Controller Error.
129  */
130 #define BLE_STATUS_UNKNOWN_CONNECTION_ID    ((tBleStatus)(BLE_ERROR_UNKNOWN_CONNECTION_ID))
131 
132 /**
133  * @brief The Host failed while performing the requested operation.
134  */
135 #define BLE_STATUS_FAILED                   ((tBleStatus)(0x81))
136 
137 /**
138  * @brief Invalid parameters passed at Host layer.
139  */
140 #define BLE_STATUS_INVALID_PARAMS           ((tBleStatus)(BLE_ERROR_INVALID_HCI_CMD_PARAMS))
141 
142 
143 /**
144  * @brief The Host is already processing another request received in advance.
145  */
146 #define BLE_STATUS_BUSY                     ((tBleStatus)(0x83))
147 
148 /**
149  * @brief The operation requested cannot be completed immediately by the Host
150  * (usually because of lack of resources).
151  * The operation is generally put on hold by the caller and it's usually
152  * retried on later time.
153  */
154 #define BLE_STATUS_PENDING                  ((tBleStatus)(0x84))
155 
156 /**
157  * @brief The requested operation cannot be performed by the Host in the current status.
158  */
159 #define BLE_STATUS_NOT_ALLOWED              ((tBleStatus)(BLE_ERROR_COMMAND_DISALLOWED))
160 
161 
162 /**
163  * @brief The requested operation violates the logic of the called layer/function or
164  * the format of the data to be processed during the operation.
165  */
166 #define BLE_STATUS_ERROR                    ((tBleStatus)(0x86))
167 
168 /**
169  * @brief The requested operation failed because of lack of memory.
170  * Out of memory shall be returned for situations where memory will never
171  * become available again
172  */
173 #define BLE_STATUS_OUT_OF_MEMORY            ((tBleStatus)(0x87))
174 
175 /**
176  * @brief The requested operation failed for a temporary lack of resources
177  * (e.g. packet pool or timers), but it may be retried later when resources may
178  * become available (packets or timers may have been released by other consumers).
179  */
180 #define BLE_STATUS_INSUFFICIENT_RESOURCES   ((tBleStatus)(0x88))
181 
182 /**
183  * @brief A NULL pointer was passed as function parameter
184  */
185 #define BLE_STATUS_NULL_PARAM               ((tBleStatus)(BLE_ERROR_INVALID_HCI_CMD_PARAMS))
186 
187 /**
188  * @brief The Host is temporarily waiting for user response, usually required
189  *        through a (vendor specific) event that notifies the required action/response
190  *        that shall be typically provided through a (vendor specific) command.
191  */
192 #define BLE_STATUS_WAITING_FOR_USER_RESPONSE         ((tBleStatus)(0x90))
193 
194 /**
195  * @brief Indicate that the requested Security Level cannot be achieved based
196  *        on available IO Capabilities and Authentication requirements.
197  */
198 #define BLE_STATUS_SECURITY_REQUIREMENTS_NOT_ACHIEVABLE ((tBleStatus)(0x91))
199 
200 /**
201 *@}
202 */
203 
204 
205 /**
206  * @name L2CAP error codes, start with 0xA0
207 *  @brief Error codes returned by the L2CAP, start at 0xA0
208  * @{
209  */
210 
211 /**
212  * @brief An invalid L2CAP CID/channel has been selected to send data over.
213  */
214 #define BLE_STATUS_INVALID_CID              ((tBleStatus)(0xA0))
215 
216 /**
217 *@}
218 */
219 
220 
221 /**
222 * @name  Security Manager error codes
223 * @brief Error codes returned by the Security Manager Protocol (SMP), start at
224 *        0xB0
225 * @{
226 */
227 
228 /**
229  * @brief The remote device in in the Blacklist and the pairing operation it requested
230  * cannot be performed.
231  */
232 #define BLE_STATUS_DEV_IN_BLACKLIST         ((tBleStatus)(0xB0))
233 
234 /**
235  * @brief CSRK not found during validation of an incoming signed packet
236  */
237 #define BLE_STATUS_CSRK_NOT_FOUND           ((tBleStatus)(0xB1))
238 
239 /**
240  * @brief Currently not used!
241  */
242 #define BLE_STATUS_IRK_NOT_FOUND            ((tBleStatus)(0xB2))
243 
244 /**
245  * @brief A search for a specific remote device was unsuccessful because no entry exists
246  * either into Security/GATT Database (flash-based) or in volatile database.
247  */
248 #define BLE_STATUS_DEV_NOT_FOUND            ((tBleStatus)(0xB3))
249 
250 /**
251  * @brief The security database is full and no more records can be added.
252  */
253 #define BLE_STATUS_SEC_DB_FULL              ((tBleStatus)(0xB4))
254 
255 /**
256  * @brief The remote device is not bonded, and no operations related to bonded devices
257  * may be performed (e.g. writing Gatt Client data).
258  */
259 #define BLE_STATUS_DEV_NOT_BONDED           ((tBleStatus)(0xB5))
260 
261 /**
262  * @brief The encryption key size used for encrypting the link is insufficient\n
263  */
264 #define BLE_INSUFFICIENT_ENC_KEYSIZE        ((tBleStatus)(0xB6))
265 
266 /**
267  * @brief The security database is temporarily unaccessible because the
268  *        underlying physical NVM module is busy with other operations.
269  */
270 #define BLE_STATUS_SEC_DB_BUSY              ((tBleStatus)(0xB7))
271 
272 /**
273 *@}
274 */
275 
276 
277 /**
278 * @name Gatt layer Error Codes
279 * @brief Error codes returned by the Gatt layer, start at 0xC0
280 * @{
281 */
282 
283 /**
284  * @brief Notification/Indication can't be sent to the requested remote device because
285  * it doesn't satisfy the needed security permission.
286  */
287 #define BLE_STATUS_SEC_PERMISSION_ERROR     ((tBleStatus)(0xC0))
288 
289 /**
290 *@}
291 */
292 
293 
294 /**
295 * @name GAP layer Error Codes
296 * @brief Error codes returned by the GAP layer. start at 0xD0
297 * @{
298 */
299 
300 /**
301  *  @brief The address of the device could not be resolved using the IRK stored
302  */
303 #define BLE_STATUS_ADDRESS_NOT_RESOLVED          ((tBleStatus)(0xD0))
304 
305 /**
306  *  @brief The configuration set by the aci_gap_set_scan_configuration command
307  *         is not coherent with the GAP procedure that is requested to be started
308  */
309 #define BLE_STATUS_INVALID_SCAN_CONFIGURATION    ((tBleStatus)(0xD1))
310 
311 /**
312  *  @brief The configuration set by the aci_gap_set_connect_configuration command
313  *         is not coherent with the GAP procedure that is requested to be started
314  */
315 #define BLE_STATUS_INVALID_CONNECT_CONFIGURATION ((tBleStatus)(0xD2))
316 
317 /**
318  *  @brief The configuration set by the aci_gap_set_advertising_configuration command
319  *         is not valid
320  */
321 #define BLE_STATUS_INVALID_ADV_CONFIGURATION     ((tBleStatus)(0xD3))
322 
323 /**
324  *  @brief The discoverability flags in the advertising data are not coherent
325  *         with the discoverability mode set in the advertising configuration
326  */
327 #define BLE_STATUS_INVALID_ADV_FLAGS             ((tBleStatus)(0xD4))
328 /**
329 *@}
330 */
331 
332 
333 /**
334 * @name flash error codes
335 * @brief Flash sector read write error codes, start at 0xF0
336 *        and are currently remapped from 0xFA to 0xFC
337 * @{
338 */
339 #define BLE_STATUS_NVM_READ_FAILED               ((tBleStatus)(0xF0))
340 #define BLE_STATUS_NVM_WRITE_FAILED              ((tBleStatus)(0xF1))
341 #define BLE_STATUS_NVM_ERASE_FAILED              ((tBleStatus)(0xF2))
342 
343 /**
344 *@}
345 */
346 
347 #define BLE_STATUS_TIMEOUT                       ((tBleStatus)(0xFF))
348 
349 
350 #endif
351