Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / src / ble / BleError.h
1 /*
2  *
3  *    Copyright (c) 2020 Project CHIP Authors
4  *    Copyright (c) 2015-2017 Nest Labs, Inc.
5  *
6  *    Licensed under the Apache License, Version 2.0 (the "License");
7  *    you may not use this file except in compliance with the License.
8  *    You may obtain a copy of the License at
9  *
10  *        http://www.apache.org/licenses/LICENSE-2.0
11  *
12  *    Unless required by applicable law or agreed to in writing, software
13  *    distributed under the License is distributed on an "AS IS" BASIS,
14  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  *    See the License for the specific language governing permissions and
16  *    limitations under the License.
17  */
18
19 /**
20  *    @file
21  *      This file defines constants for the CHIP BleLayer subsystem.
22  *
23  *      Error types, ranges, and mappings overrides may be made by
24  *      defining the appropriate BLE_CONFIG_* or _BLE_CONFIG_*
25  *      macros.
26  *
27  *  NOTE WELL: On some platforms, this header is included by C-language programs.
28  *
29  */
30
31 #pragma once
32
33 #include "BleConfig.h"
34
35 // clang-format off
36
37 /**
38  *  @def BLE_NO_ERROR
39  *
40  *  @brief
41  *    This defines the BleLayer error code for success or no
42  *    error. This value may be configured via #BLE_CONFIG_NO_ERROR.
43  *
44  */
45 #define BLE_NO_ERROR                   BLE_CONFIG_NO_ERROR
46
47 /**
48  *  @def BLE_ERROR_MIN
49  *
50  *  @brief
51  *    This defines the base or minimum value of the BleLayer error number
52  *    range. This value may be configured via #BLE_CONFIG_ERROR_MIN.
53  *
54  */
55 #define BLE_ERROR_MIN                  BLE_CONFIG_ERROR_MIN
56
57 /**
58  *  @def BLE_ERROR_MAX
59  *
60  *  @brief
61  *    This defines the top or maximum value of the BleLayer error number
62  *    range. This value may be configured via #BLE_CONFIG_ERROR_MAX.
63  *
64  */
65 #define BLE_ERROR_MAX                  BLE_CONFIG_ERROR_MAX
66
67 /**
68  *  @def _BLE_ERROR(e)
69  *
70  *  @brief
71  *    This defines a mapping function for BleLayer errors that allows
72  *    mapping such errors into a platform- or system-specific
73  *    range. This function may be configured via
74  *    #_BLE_CONFIG_ERROR.
75  *
76  *  @param[in]  e  The BleLayer error to map.
77  *
78  *  @return The mapped BleLayer error.
79  *
80  */
81 #define _BLE_ERROR(e)                  _BLE_CONFIG_ERROR(e)
82
83 /**
84  *  @typedef BLE_ERROR
85  *
86  *  The basic type for all BleLayer errors.
87  *
88  *  This is defined to a platform- or system-specific type.
89  *
90  */
91 typedef BLE_CONFIG_ERROR_TYPE BLE_ERROR;
92
93 /**
94  *  @name Error Definitions
95  *
96  *  @{
97  */
98
99 /**
100  *  @def BLE_ERROR_BAD_ARGS
101  *
102  *  @brief
103  *    An invalid argument or arguments were supplied.
104  *
105  */
106 #define BLE_ERROR_BAD_ARGS                                 _BLE_ERROR(0)
107
108 /**
109  *  @def BLE_ERROR_INCORRECT_STATE
110  *
111  *  @brief
112  *    An unexpected state was encountered.
113  *
114  */
115 #define BLE_ERROR_INCORRECT_STATE                          _BLE_ERROR(1)
116
117 /**
118  *  @def BLE_ERROR_NO_ENDPOINTS
119  *
120  *  @brief
121  *    No BLE endpoint is available.
122  *
123  */
124 #define BLE_ERROR_NO_ENDPOINTS                             _BLE_ERROR(2)
125
126 /**
127  *  @def BLE_ERROR_NO_CONNECTION_RECEIVED_CALLBACK
128  *
129  *  @brief
130  *    No callback was registered to receive a BLE Transport Protocol (BTP)
131  *    connection.
132  *
133  */
134 #define BLE_ERROR_NO_CONNECTION_RECEIVED_CALLBACK          _BLE_ERROR(3)
135
136 /**
137  *  @def BLE_ERROR_CENTRAL_UNSUBSCRIBED
138  *
139  *  @brief
140  *    A BLE central device unsubscribed from a peripheral device's BLE
141  *    Transport Protocol (BTP) transmit characteristic.
142  *
143  */
144 #define BLE_ERROR_CENTRAL_UNSUBSCRIBED                     _BLE_ERROR(4)
145
146 /**
147  *  @def BLE_ERROR_GATT_SUBSCRIBE_FAILED
148  *
149  *  @brief
150  *    A BLE central device failed to subscribe to a peripheral device's BLE
151  *    Transport Protocol (BTP) transmit characteristic.
152  *
153  */
154 #define BLE_ERROR_GATT_SUBSCRIBE_FAILED                    _BLE_ERROR(5)
155
156 /**
157  *  @def BLE_ERROR_GATT_UNSUBSCRIBE_FAILED
158  *
159  *  @brief
160  *    A BLE central device failed to unsubscribe from a peripheral device's
161  *    BLE Transport Protocol (BTP) transmit characteristic.
162  *
163  */
164 #define BLE_ERROR_GATT_UNSUBSCRIBE_FAILED                  _BLE_ERROR(6)
165
166 /**
167  *  @def BLE_ERROR_GATT_WRITE_FAILED
168  *
169  *  @brief
170  *    A General Attribute Profile (GATT) write operation failed.
171  *
172  */
173 #define BLE_ERROR_GATT_WRITE_FAILED                        _BLE_ERROR(7)
174
175 /**
176  *  @def BLE_ERROR_GATT_INDICATE_FAILED
177  *
178  *  @brief
179  *    A General Attribute Profile (GATT) indicate operation failed.
180  *
181  */
182 #define BLE_ERROR_GATT_INDICATE_FAILED                     _BLE_ERROR(8)
183
184 /**
185  *  @def BLE_ERROR_NOT_IMPLEMENTED
186  *
187  *  @brief
188  *    A requested function or feature is not implemented.
189  *
190  */
191 #define BLE_ERROR_NOT_IMPLEMENTED                          _BLE_ERROR(9)
192
193 /*
194  * Unused                                                  _BLE_ERROR(10)
195  */
196
197 /**
198  *  @def BLE_ERROR_CHIPOBLE_PROTOCOL_ABORT
199  *
200  *  @brief
201  *    A BLE Transport Protocol (BTP) error was encountered.
202  *
203  */
204 #define BLE_ERROR_CHIPOBLE_PROTOCOL_ABORT                     _BLE_ERROR(11)
205
206 /**
207  *  @def BLE_ERROR_REMOTE_DEVICE_DISCONNECTED
208  *
209  *  @brief
210  *    A remote BLE connection peer disconnected, either actively or due to the
211  *    expiration of a BLE connection supervision timeout.
212  *
213  */
214 #define BLE_ERROR_REMOTE_DEVICE_DISCONNECTED               _BLE_ERROR(12)
215
216 /**
217  *  @def BLE_ERROR_APP_CLOSED_CONNECTION
218  *
219  *  @brief
220  *    The local application closed a BLE connection, and has informed BleLayer.
221  *
222  */
223 #define BLE_ERROR_APP_CLOSED_CONNECTION                    _BLE_ERROR(13)
224
225 /**
226  *  @def BLE_ERROR_OUTBOUND_MESSAGE_TOO_BIG
227  *
228  *  @brief
229  *    More outbound message data is pending than available buffer space
230  *    available to copy it.
231  *
232  */
233 #define BLE_ERROR_OUTBOUND_MESSAGE_TOO_BIG                 _BLE_ERROR(14)
234
235 /**
236  *  @def BLE_ERROR_NOT_CHIP_DEVICE
237  *
238  *  @brief
239  *    A BLE peripheral device did not expose the General Attribute Profile
240  *    (GATT) service required by the Bluetooth Transport Protocol (BTP).
241  *
242  */
243 #define BLE_ERROR_NOT_CHIP_DEVICE                         _BLE_ERROR(15)
244
245 /**
246  *  @def BLE_ERROR_INCOMPATIBLE_PROTOCOL_VERSIONS
247  *
248  *  @brief
249  *    A remote device does not offer a compatible version of the Bluetooth
250  *    Transport Protocol (BTP).
251  *
252  */
253 #define BLE_ERROR_INCOMPATIBLE_PROTOCOL_VERSIONS           _BLE_ERROR(16)
254
255 /**
256  *  @def BLE_ERROR_NO_MEMORY
257  *
258  *  @brief
259  *    A request for memory could not be fulfilled.
260  *
261  */
262 #define BLE_ERROR_NO_MEMORY                                _BLE_ERROR(17)
263
264 /**
265  *  @def BLE_ERROR_MESSAGE_INCOMPLETE
266  *
267  *  @brief
268  *    A received Bluetooth Transport Protocol (BTP) message was incomplete.
269  *
270  */
271 #define BLE_ERROR_MESSAGE_INCOMPLETE                       _BLE_ERROR(18)
272
273 /**
274  *  @def BLE_ERROR_INVALID_FRAGMENT_SIZE
275  *
276  *  @brief
277  *    A remote device selected in invalid Bluetooth Transport Protocol (BTP)
278  *    fragment size.
279  *
280  */
281 #define BLE_ERROR_INVALID_FRAGMENT_SIZE                    _BLE_ERROR(19)
282
283 /**
284  *  @def BLE_ERROR_START_TIMER_FAILED
285  *
286  *  @brief
287  *    A timer failed to start within BleLayer.
288  *
289  */
290 #define BLE_ERROR_START_TIMER_FAILED                       _BLE_ERROR(20)
291
292 /**
293  *  @def BLE_ERROR_CONNECT_TIMED_OUT
294  *
295  *  @brief
296  *    A remote BLE peripheral device's Bluetooth Transport Protocol (BTP)
297  *    connect handshake response timed out.
298  *
299  */
300 #define BLE_ERROR_CONNECT_TIMED_OUT                        _BLE_ERROR(21)
301
302 /**
303  *  @def BLE_ERROR_RECEIVE_TIMED_OUT
304  *
305  *  @brief
306  *    A remote BLE central device's Bluetooth Transport Protocol (BTP) connect
307  *    handshake timed out.
308  *
309  */
310 #define BLE_ERROR_RECEIVE_TIMED_OUT                        _BLE_ERROR(22)
311
312 /**
313  *  @def BLE_ERROR_INVALID_MESSAGE
314  *
315  *  @brief
316  *    An invalid Bluetooth Transport Protocol (BTP) message was received.
317  *
318  */
319 #define BLE_ERROR_INVALID_MESSAGE                          _BLE_ERROR(23)
320
321 /**
322  *  @def BLE_ERROR_FRAGMENT_ACK_TIMED_OUT
323  *
324  *  @brief
325  *    Receipt of an expected Bluetooth Transport Protocol (BTP) fragment
326  *    acknowledgement timed out.
327  *
328  */
329 #define BLE_ERROR_FRAGMENT_ACK_TIMED_OUT                   _BLE_ERROR(24)
330
331 /**
332  *  @def BLE_ERROR_KEEP_ALIVE_TIMED_OUT
333  *
334  *  @brief
335  *    Receipt of an expected Bluetooth Transport Protocol (BTP) keep-alive
336  *    fragment timed out.
337  *
338  */
339 #define BLE_ERROR_KEEP_ALIVE_TIMED_OUT                     _BLE_ERROR(25)
340
341 /**
342  *  @def BLE_ERROR_NO_CONNECT_COMPLETE_CALLBACK
343  *
344  *  @brief
345  *    No callback was registered to handle Bluetooth Transport Protocol (BTP)
346  *    connect completion.
347  *
348  */
349 #define BLE_ERROR_NO_CONNECT_COMPLETE_CALLBACK            _BLE_ERROR(26)
350
351 /**
352  *  @def BLE_ERROR_INVALID_ACK
353  *
354  *  @brief
355  *    A Bluetooth Transport Protcol (BTP) fragment acknowledgement was invalid.
356  *
357  */
358 #define BLE_ERROR_INVALID_ACK                              _BLE_ERROR(27)
359
360 /**
361  *  @def BLE_ERROR_REASSEMBLER_MISSING_DATA
362  *
363  *  @brief
364  *    A Bluetooth Transport Protocol (BTP) end-of-message fragment was
365  *    received, but the total size of the received fragments is less than
366  *    the indicated size of the original fragmented message.
367  *
368  */
369 #define BLE_ERROR_REASSEMBLER_MISSING_DATA                 _BLE_ERROR(28)
370
371 /**
372  *  @def BLE_ERROR_INVALID_BTP_HEADER_FLAGS
373  *
374  *  @brief
375  *    A set of Bluetooth Transport Protocol (BTP) header flags is invalid.
376  *
377  */
378 #define BLE_ERROR_INVALID_BTP_HEADER_FLAGS                 _BLE_ERROR(29)
379
380 /**
381  *  @def BLE_ERROR_INVALID_BTP_SEQUENCE_NUMBER
382  *
383  *  @brief
384  *    A Bluetooth Transport Protocol (BTP) fragment sequence number is invalid.
385  *
386  */
387 #define BLE_ERROR_INVALID_BTP_SEQUENCE_NUMBER              _BLE_ERROR(30)
388
389 /**
390  *  @def BLE_ERROR_REASSEMBLER_INCORRECT_STATE
391  *
392  *  @brief
393  *    The Bluetooth Transport Protocol (BTP) message reassembly engine
394  *    encountered an unexpected state.
395  *
396  */
397 #define BLE_ERROR_REASSEMBLER_INCORRECT_STATE              _BLE_ERROR(31)
398
399 /**
400  *  @def BLE_ERROR_RECEIVED_MESSAGE_TOO_BIG
401  *
402  *  @brief
403  *    More inbound message data is pending than available buffer space
404  *    available to copy it.
405  *
406  */
407 #define BLE_ERROR_RECEIVED_MESSAGE_TOO_BIG                 _BLE_ERROR(32)
408
409 // !!!!! IMPORTANT !!!!!  If you add new Ble errors, please update the translation
410 // of error codes to strings in BleError.cpp, and add them to unittest
411 // in test-apps/TestErrorStr.cpp
412
413 /**
414  *  @}
415  */
416
417 // clang-format on
418
419 namespace chip {
420 namespace Ble {
421
422 extern void RegisterLayerErrorFormatter();
423 extern bool FormatLayerError(char * buf, uint16_t bufSize, int32_t err);
424
425 } /* namespace Ble */
426 } /* namespace chip */