1 /**
2  * Copyright (c) 2017, Realtek Semiconductor Corporation. All rights reserved.
3  */
4 
5 #ifndef _BT_TYPES_H_
6 #define _BT_TYPES_H_
7 
8 #ifdef __cplusplus
9 extern "C" {
10 #endif
11 
12 #include <bt_flags.h>
13 /**
14  * \defgroup    BTTYPES     BT Types
15  *
16  * \brief   Defines BT related macros for the upper layers.
17  *
18  */
19 
20 
21 /**
22  * bt_types.h
23  *
24  * \name    BT_LE_LOCAL_SUPPORTED_FEATURES
25  * \brief   BT LE Local Supported Features definitions.
26  * \anchor  BT_LE_LOCAL_SUPPORTED_FEATURES
27  */
28 /**
29  * \ingroup     BTTYPES
30  */
31 #define LE_SUPPORT_FEATURES_MASK_ARRAY_INDEX0                           0
32 
33 #define LE_SUPPORT_FEATURES_ENCRYPTION_MASK_BIT                         ((uint8_t)0x01)
34 #define LE_SUPPORT_FEATURES_CONNPARA_REQ_PROC_MASK_BIT                  ((uint8_t)0x02)
35 #define LE_SUPPORT_FEATURES_EXTENDED_REJECTION_IND_MASK_BIT             ((uint8_t)0x04)
36 #define LE_SUPPORT_FEATURES_SLAVE_INITIATED_FEATURE_EXCHANGE_MASK_BIT   ((uint8_t)0x08)
37 #define LE_SUPPORT_FEATURES_LE_PING_MASK_BIT                            ((uint8_t)0x10)
38 #define LE_SUPPORT_FEATURES_LE_DATA_LENGTH_EXTENSION_MASK_BIT           ((uint8_t)0x20)
39 #define LE_SUPPORT_FEATURES_LL_PRIVACY_MASK_BIT                         ((uint8_t)0x40)
40 #define LE_SUPPORT_FEATURES_EXTENDED_SCANNER_FILTER_POLICY_MASK_BIT     ((uint8_t)0x80)
41 
42 #define LE_SUPPORT_FEATURES_MASK_ARRAY_INDEX1                           1
43 
44 #define LE_SUPPORT_FEATURES_LE_2M_MASK_BIT                              ((uint8_t)0x01)
45 #define LE_SUPPORT_FEATURES_STABLE_MODULATION_INDEX_TX_MASK_BIT         ((uint8_t)0x02)
46 #define LE_SUPPORT_FEATURES_STABLE_MODULATION_INDEX_RX_MASK_BIT         ((uint8_t)0x04)
47 #define LE_SUPPORT_FEATURES_LE_CODED_PHY_MASK_BIT                       ((uint8_t)0x08)
48 #define LE_SUPPORT_FEATURES_LE_EXTENDED_ADV_BIT                         ((uint8_t)0x10)
49 #define LE_SUPPORT_FEATURES_LE_PERIODIC_ADV_MASK_BIT                    ((uint8_t)0x20)
50 #define LE_SUPPORT_FEATURES_CSA2_BIT                                    ((uint8_t)0x40)
51 #define LE_SUPPORT_FEATURES_LE_POWER_CLASS1_MASK_BIT                    ((uint8_t)0x80)
52 
53 #define LE_SUPPORT_FEATURES_MASK_ARRAY_INDEX2                           2
54 
55 #define LE_SUPPORT_FEATURES_MIN_NUM_USED_CHANNEL_MASK_BIT               ((uint8_t)0x01)
56 
57 /**
58  * bt_types.h
59  *
60  * \name    BT_STACK_MODULE_ERROR
61  * \brief   BT stack module error code mask.
62  * \anchor  BT_STACK_MODULE_ERROR
63  */
64 /**
65  * \ingroup     BTTYPES
66  */
67 #define GAP_ERR                 0x0000
68 #define HCI_ERR                 0x0100
69 #define L2C_ERR                 0x0200
70 #define SDP_ERR                 0x0300
71 #define ATT_ERR                 0x0400
72 #define SM_ERR                  0x0500
73 
74 #define GATT_ERR                0x0C00
75 #define APP_ERR                 0x0D00
76 
77 /**
78  * bt_types.h
79  *
80  * \name    BT_HCI_ERROR
81  * \brief   BT hci error code definitions.
82  * \anchor  BT_HCI_ERROR
83  */
84 /**
85  * \ingroup     BTTYPES
86  */
87 #define HCI_SUCCESS                             0x00
88 #define HCI_ERR_UNKNOWN_CMD                     0x01
89 #define HCI_ERR_UNKNOWN_CONN_ID                 0x02
90 #define HCI_ERR_HARDWARE_FAIL                   0x03
91 #define HCI_ERR_PAGE_TIMEOUT                    0x04
92 #define HCI_ERR_AUTHEN_FAIL                     0x05
93 #define HCI_ERR_KEY_MISSING                     0x06
94 #define HCI_ERR_MEMORY_FULL                     0x07
95 #define HCI_ERR_CONN_TIMEOUT                    0x08
96 #define HCI_ERR_MAX_NUM_CONN                    0x09
97 #define HCI_ERR_MAX_NUM_SCO_CONN                0x0A  /* 10 */
98 #define HCI_ERR_ACL_CONN_EXIST                  0x0B  /* 11 */
99 #define HCI_ERR_CMD_DISALLOWED                  0x0C  /* 12 */
100 #define HCI_ERR_REJECT_LIMITED_RESOURCE         0x0D  /* 13 */
101 #define HCI_ERR_REJECT_SECURITY_REASON          0x0E  /* 14 */
102 #define HCI_ERR_REJECT_UNACCEPTABLE_ADDR        0x0F  /* 15 */
103 #define HCI_ERR_HOST_TIMEOUT                    0x10  /* 16 */
104 #define HCI_ERR_UNSUPPORTED_PARAM               0x11  /* 17 */
105 #define HCI_ERR_INVALID_PARAM                   0x12  /* 18 */
106 #define HCI_ERR_REMOTE_USER_TERMINATE           0x13  /* 19 */
107 #define HCI_ERR_REMOTE_LOW_RESOURCE             0x14  /* 20 */
108 #define HCI_ERR_REMOTE_POWER_OFF                0x15  /* 21 */
109 #define HCI_ERR_LOCAL_HOST_TERMINATE            0x16  /* 22 */
110 #define HCI_ERR_REPEATED_ATTEMPTS               0x17  /* 23 */
111 #define HCI_ERR_PARING_NOT_ALLOWED              0x18  /* 24 */
112 #define HCI_ERR_UNKNOWN_LMP_PDU                 0x19  /* 25 */
113 #define HCI_ERR_UNSUPPORTED_REMOTE_FEAT         0x1A  /* 26 */
114 #define HCI_ERR_SCO_OFFSET_REJECTED             0x1B  /* 27 */
115 #define HCI_ERR_SCO_INTERVAL_REJECTED           0x1C  /* 28 */
116 #define HCI_ERR_SCO_AIR_MODE_REJECTED           0x1D  /* 29 */
117 #define HCI_ERR_INVALID_LMP_PARAM               0x1E  /* 30 */
118 #define HCI_ERR_UNSPECIFIED_ERROR               0x1F  /* 31 */
119 #define HCI_ERR_UNSUPPORTED_LMP_PARAM           0x20  /* 32 */
120 #define HCI_ERR_ROLE_CHANGE_NOT_ALLOWED         0x21  /* 33 */
121 #define HCI_ERR_LMP_RESPONSE_TIMEOUT            0x22  /* 34 */
122 #define HCI_ERR_LMP_ERROR_TRANS_COLLISION       0x23  /* 35 */
123 #define HCI_ERR_LMP_PDU_NOT_ALLOWED             0x24  /* 36 */
124 #define HCI_ERR_ENCRYPT_MODE_NOT_ACCEPTABLE     0x25  /* 37 */
125 #define HCI_ERR_UNIT_KEY_USED                   0x26  /* 38 */
126 #define HCI_ERR_QOS_NOT_SUPPORTED               0x27  /* 39 */
127 #define HCI_ERR_INSTANT_PASSED                  0x28  /* 40 */
128 #define HCI_ERR_PAIR_UNIT_KEY_NOT_SUPPORT       0x29  /* 41 */
129 #define HCI_ERR_DIFF_TRANS_COLLISION            0x2A  /* 42 */
130 #define HCI_ERR_QOS_UNACCEPTABLE_PARAM          0x2C  /* 44 */
131 #define HCI_ERR_QOS_REJECT                      0x2D  /* 45 */
132 #define HCI_ERR_CHANN_ASSESS_NOT_SUPPORT        0x2E  /* 46 */
133 #define HCI_ERR_INSUFFICIENT_SECURITY           0x2F  /* 47 */
134 #define HCI_ERR_PARAM_OUT_OF_RANGE              0x30  /* 48 */
135 #define HCI_ERR_ROLE_SWITCH_PANDING             0x32  /* 50 */
136 #define HCI_ERR_RESERVED_SLOT_VIOLATION         0x34  /* 52 */
137 #define HCI_ERR_ROLE_SWITCH_FAILED              0x35  /* 53 */
138 #define HCI_ERR_EXT_INQUIRY_RSP_TOO_LARGE       0x36  /* 54 */
139 #define HCI_ERR_SSP_NOT_SUPPORTED_BY_HOST       0x37  /* 55 */
140 #define HCI_ERR_HOST_BUSY_PAIRING               0x38  /* 56 */
141 #define HCI_ERR_REJECT_NO_SUITABLE_CHANN        0x39  /* 57 */
142 #define HCI_ERR_CONTROLLER_BUSY                 0x3A  /* 58 */
143 #define HCI_ERR_UNACCEPTABLE_CONN_INTERVAL      0x3B  /* 59 */
144 #define HCI_ERR_DIRECTED_ADV_TIMEOUT            0x3C  /* 60 */
145 #define HCI_ERR_MIC_FAILURE                     0x3D  /* 61 */
146 #define HCI_ERR_FAIL_TO_ESTABLISH_CONN          0x3E  /* 62 */
147 #define HCI_ERR_MAC_CONN_FAIL                   0x3F  /* 63 */
148 #define HCI_ERR_COARSE_CLOCK_ADJUST_REJECTED    0x40
149 #define HCI_ERR_TYPE0_SUBMAP_NOT_DEFINED        0x41
150 #define HCI_ERR_UNKNOWN_ADVERTISING_IDENTIFIER  0x42
151 #define HCI_ERR_LIMIT_REACHED                   0x43
152 #define HCI_ERR_OPERATION_CANCELLED_BY_HOST     0x44
153 
154 /* hci local error code */
155 #define HCI_ERR_INVALID_ADDR                    0x64  /* 100 */
156 #define HCI_ERR_TIMEOUT                         0x65  /* 101 */
157 #define HCI_ERR_OUT_OF_SYNC                     0x66  /* 102 */
158 #define HCI_ERR_NO_DESCRIPTOR                   0x67  /* 103 */
159 #define HCI_ERR_NO_MEMORY                       0x68
160 
161 /**
162  * bt_types.h
163  *
164  * \name    BT_L2CAP_ERROR
165  * \brief   BT l2cap error code definitions.
166  * \anchor  BT_L2CAP_ERROR
167  */
168 /**
169  * \ingroup     BTTYPES
170  */
171 #define L2C_SUCCESS                             0x00
172 
173 #define L2C_CONN_ACCEPT                         0x0000
174 #define L2C_CONN_RSP_PENDING                    0x0001
175 #define L2C_CONN_RSP_INVALID_PSM                0x0002
176 #define L2C_CONN_RSP_SECURITY_BLOCK             0x0003
177 #define L2C_CONN_RSP_NO_RESOURCE                0x0004
178 #define L2C_CONN_RSP_INVALID_PARAM              0x0005
179 #define L2C_CONN_RSP_INVALID_SOURCE_CID         0x0006
180 #define L2C_CONN_RSP_SOURCE_CID_ALLOCATED       0x0007
181 
182 /* requset cmd reject reasons */
183 #define L2C_CMD_REJ_NOT_UNDERSTOOD              0x0000
184 #define L2C_CMD_REJ_SIGNAL_MTU_EXCEEDED         0x0001
185 #define L2C_CMD_REJ_INVALID_CID_IN_REQ          0x0002
186 
187 /* config response result codes */
188 #define L2C_CFG_RSP_SUCCESS                     0x0000
189 #define L2C_CFG_RSP_UNACCEPTABLE_PARAMS         0x0001
190 #define L2C_CFG_RSP_REJECTED                    0x0002
191 #define L2C_CFG_RSP_UNKNOWN_OPTIONS             0x0003
192 #define L2C_CFG_RSP_PENDING                     0x0004
193 #define L2C_CFG_RSP_FLOW_SPEC_REJECTED          0x0005
194 
195 #define L2C_LE_CREDIT_CONN_SUCCESS                      0x0000
196 #define L2C_LE_CREDIT_RSP_PSM_NOT_SUPPORTED             0x0002
197 #define L2C_LE_CREDIT_RSP_NO_RESOURCES                  0x0004
198 #define L2C_LE_CREDIT_RSP_INSUFFICIENT_AUTHEN           0x0005
199 #define L2C_LE_CREDIT_RSP_INSUFFICIENT_AUTHOR           0x0006
200 #define L2C_LE_CREDIT_RSP_INSUFFICIENT_ENCRYP_KEY_SIZE  0x0007
201 #define L2C_LE_CREDIT_RSP_INSUFFICIENT_ENCRYP           0x0008
202 #define L2C_LE_CREDIT_RSP_INVALID_SOURCE_CID            0x0009
203 #define L2C_LE_CREDIT_RSP_SOURCE_CID_ALREADY_ALLOC      0x000A
204 
205 /* status for connection updata response */
206 #define L2C_LE_CONN_UPDATE_ACCEPT               0x0000
207 #define L2C_LE_CONN_UPDATE_RSP_REJECT           0x0001
208 #define L2C_LE_CONN_UPDATE_RSP_TOUT             0x0002
209 
210 /* l2cap error code */
211 #define L2C_ERR_REJ_BASE                        0x0010
212 #define L2C_ERR_CFG_BASE                        0x0020
213 #define L2C_ERR_LE_CREDIT_BASE                  0x0030
214 #define L2C_ERR_LE_CONN_UPDATE_BASE             0x0040
215 #define L2C_ERR_VND_BASE                        0x00F0
216 
217 #define L2C_ERR_PENDING                         L2C_CONN_RSP_PENDING
218 #define L2C_ERR_INVALID_PSM                     L2C_CONN_RSP_INVALID_PSM
219 #define L2C_ERR_SECURITY_BLOCK                  L2C_CONN_RSP_SECURITY_BLOCK
220 #define L2C_ERR_NO_RESOURCE                     L2C_CONN_RSP_NO_RESOURCE
221 #define L2C_ERR_INVALID_PARAM                   L2C_CONN_RSP_INVALID_PARAM
222 #define L2C_ERR_INVALID_SOURCE_CID              L2C_CONN_RSP_INVALID_SOURCE_CID
223 #define L2C_ERR_SOURCE_CID_ALLOCATED            L2C_CONN_RSP_SOURCE_CID_ALLOCATED
224 
225 #define L2C_ERR_CMD_NOT_UNDERSTOOD              (L2C_ERR_REJ_BASE + L2C_CMD_REJ_NOT_UNDERSTOOD)
226 #define L2C_ERR_SIGNAL_MTU_EXCEEDED             (L2C_ERR_REJ_BASE + L2C_CMD_REJ_SIGNAL_MTU_EXCEEDED)
227 #define L2C_ERR_INVALID_CID_IN_REQ              (L2C_ERR_REJ_BASE + L2C_CMD_REJ_INVALID_CID_IN_REQ)
228 
229 #define L2C_ERR_CFG_UNACCEPTABLE_PARAM          (L2C_ERR_CFG_BASE + L2C_CFG_RSP_UNACCEPTABLE_PARAMS)
230 #define L2C_ERR_CFG_REJECTED                    (L2C_ERR_CFG_BASE + L2C_CFG_RSP_REJECTED)
231 #define L2C_ERR_CFG_UNKNOWN_OPTIONS             (L2C_ERR_CFG_BASE + L2C_CFG_RSP_UNKNOWN_OPTIONS)
232 #define L2C_ERR_CFG_PENDING                     (L2C_ERR_CFG_BASE + L2C_CFG_RSP_PENDING)
233 #define L2C_ERR_CFG_FLOW_SPEC_REJECTED          (L2C_ERR_CFG_BASE + L2C_CFG_RSP_FLOW_SPEC_REJECTED)
234 
235 #define L2C_ERR_LE_CREDIT_PSM_NOT_SUPPORTED             (L2C_ERR_LE_CREDIT_BASE + L2C_LE_CREDIT_RSP_PSM_NOT_SUPPORTED)
236 #define L2C_ERR_LE_CREDIT_NO_RESOURCES                  (L2C_ERR_LE_CREDIT_BASE + L2C_LE_CREDIT_RSP_NO_RESOURCES)
237 #define L2C_ERR_LE_CREDIT_INSUFFICIENT_AUTHEN           (L2C_ERR_LE_CREDIT_BASE + L2C_LE_CREDIT_RSP_INSUFFICIENT_AUTHEN)
238 #define L2C_ERR_LE_CREDIT_INSUFFICIENT_AUTHOR           (L2C_ERR_LE_CREDIT_BASE + L2C_LE_CREDIT_RSP_INSUFFICIENT_AUTHOR)
239 #define L2C_ERR_LE_CREDIT_INSUFFICIENT_ENCRYP_KEY_SIZE  (L2C_ERR_LE_CREDIT_BASE + L2C_LE_CREDIT_RSP_INSUFFICIENT_ENCRYP_KEY_SIZE)
240 #define L2C_ERR_LE_CREDIT_INSUFFICIENT_ENCRYP           (L2C_ERR_LE_CREDIT_BASE + L2C_LE_CREDIT_RSP_INSUFFICIENT_ENCRYP)
241 #define L2C_ERR_LE_CREDIT_INVALID_SOURCE_CID            (L2C_ERR_LE_CREDIT_BASE + L2C_LE_CREDIT_RSP_INVALID_SOURCE_CID)
242 #define L2C_ERR_LE_CREDIT_SOURCE_CID_ALREADY_ALLOC      (L2C_ERR_LE_CREDIT_BASE + L2C_LE_CREDIT_RSP_SOURCE_CID_ALREADY_ALLOC)
243 
244 #define L2C_ERR_LE_CONN_PARAM_UPDATE_REJECT     (L2C_ERR_LE_CONN_UPDATE_BASE + L2C_LE_CONN_UPDATE_RSP_REJECT)
245 #define L2C_ERR_LE_CONN_PARAM_UPDATE_TOUT       (L2C_ERR_LE_CONN_UPDATE_BASE + L2C_LE_CONN_UPDATE_RSP_TOUT)
246 
247 #define L2C_ERR_VND_CREDITS_EXCEED              (L2C_ERR_VND_BASE + 0x00)
248 #define L2C_ERR_VND_INVAILD_PDU                 (L2C_ERR_VND_BASE + 0x01)
249 #define L2C_ERR_VND_CREDITS_LACK                (L2C_ERR_VND_BASE + 0x02)
250 #define L2C_ERR_VND_NO_MEMORY                   (L2C_ERR_VND_BASE + 0x03)
251 #define L2C_ERR_VND_INVALID_STATE               (L2C_ERR_VND_BASE + 0x04)
252 #define L2C_ERR_VND_INVALID_RX_SEQ              (L2C_ERR_VND_BASE + 0x05)
253 #define L2C_ERR_VND_TIMEOUT                     (L2C_ERR_VND_BASE + 0x06)
254 #define L2C_ERR_VND_INVALID_MODE                (L2C_ERR_VND_BASE + 0x07)
255 #define L2C_ERR_VND_REMOTE_DISCONNECT           (L2C_ERR_VND_BASE + 0x08)
256 
257 /**
258  * bt_types.h
259  *
260  * \name    BT_ATT_ERROR
261  * \brief   BT att error code definitions.
262  * \anchor  BT_ATT_ERROR
263  */
264 /**
265  * \ingroup     BTTYPES
266  */
267 #define ATT_SUCCESS                         0    /**< internal value .. */
268 #define ATT_ERR_INVALID_HANDLE              0x01 /**< Attribute handle value given was not valid on this attribute server */
269 #define ATT_ERR_READ_NOT_PERMITTED          0x02 /**< Attribute cannot be read */
270 #define ATT_ERR_WRITE_NOT_PERMITTED         0x03 /**< Attribute cannot be written */
271 #define ATT_ERR_INVALID_PDU                 0x04 /**< The attribute PDU was invalid */
272 #define ATT_ERR_INSUFFICIENT_AUTHEN         0x05 /**< The attribute requires authentication before it can be read or written */
273 #define ATT_ERR_UNSUPPORTED_REQ             0x06 /**< Attribute server doesn't support the request received from the attribute client */
274 #define ATT_ERR_INVALID_OFFSET              0x07 /**< Offset specified was past the end of the attribute */
275 #define ATT_ERR_INSUFFICIENT_AUTHOR         0x08 /**< The attribute requires an authorization before it can be read or written */
276 #define ATT_ERR_PREP_QUEUE_FULL             0x09 /**< Too many prepare writes have been queued */
277 #define ATT_ERR_ATTR_NOT_FOUND              0x0A /**< No attribute found within the given attribute handle range */
278 #define ATT_ERR_ATTR_NOT_LONG               0x0B /**< Attribute cannot be read or written using the Read Blob Request or Prepare Write Request */
279 #define ATT_ERR_INSUFFICIENT_KEY_SIZE       0x0C /**< The Encryption Key Size used for encrypting this link is insufficient */
280 #define ATT_ERR_INVALID_VALUE_SIZE          0x0D /**< The attribute value length is invalid for the operation */
281 #define ATT_ERR_UNLIKELY                    0x0E /**< The attribute request that was requested has encountered an error that was very unlikely, and therefore could not be completed as requested */
282 #define ATT_ERR_INSUFFICIENT_ENCRYPT        0x0F /**< The attribute requires encryption before it can be read or written */
283 #define ATT_ERR_UNSUPPORTED_GROUP_TYPE      0x10 /**< The attribute type is not a supported grouping attribute as defined by a higher layer specification */
284 #define ATT_ERR_INSUFFICIENT_RESOURCES      0x11 /**< Insufficient Resources to complete the request */
285 
286 /* profile dependent application error codes >= 0x80: */
287 #define ATT_ERR_MIN_APPLIC_CODE             0x80 /**< minimal application error code */
288 #define ATT_ERR_INVALID_VALUE               0x80 /**< The attribute value is invalid for the operation */
289 
290 /* manufacturer specific error codes that are "missing" in GATT spec. >= 0xC0:   */
291 #define ATT_ERR_INVALID_CCC_BITS            0xC0 /**< Invalid client char. config. bits */
292 #define ATT_ERR_INVALID_SIGNED_COUNT        0xC1 /**< Invalid sign count */
293 #define ATT_ERR_INVALID_SIGNED_MAC_FAILED   0xC2 /**< Invalid sign mac value */
294 
295 /* error codes common to various profiles (see "CSS v2.pdf"), >= 0xE0 */
296 #define ATT_ERR_CCCD_IMPROPERLY_CONFIGURED  0xFD /**< CCCD improperly configured */
297 #define ATT_ERR_PROC_ALREADY_IN_PROGRESS    0xFE /**< Procedure Already in Progress */
298 #define ATT_ERR_OUT_OF_RANGE                0xFF /**< Client Characteristic Configuration Descriptor Improperly Configured */
299 
300 /**
301  * bt_types.h
302  *
303  * \name    BT_GATT_ERROR
304  * \brief   BT gatt error code definitions.
305  * \anchor  BT_GATT_ERROR
306  */
307 /**
308  * \ingroup     BTTYPES
309  */
310 #define GATT_SUCCESS                        0x00
311 #define GATT_ERR_OUT_OF_RESOURCE            0x01
312 #define GATT_ERR_UNSUPPORTED                0x02
313 #define GATT_ERR_INVALID_ROLE               0x03
314 #define GATT_ERR_INVALID_STATE              0x04
315 #define GATT_ERR_INVALID_CODING             0x05
316 #define GATT_ERR_INVALID_HANDLE             0x06
317 #define GATT_ERR_INVALID_PARAM              0x07
318 #define GATT_ERR_INTERNAL                   0x08
319 #define GATT_ERR_NOT_ALLOWED                0x09
320 #define GATT_ERR_NOTIF_IND_NOT_CFG          0x0A
321 #define GATT_ERR_NOTIF_IND_CFG              0x0B
322 #define GATT_ERR_NOTIF_IND_CONF_PD          0x0C
323 #define GATT_ERR_TIMEOUT                    0x0D
324 #define GATT_ERR_LINK_DEACTIVATED           0x0E
325 #define GATT_ERR_NOT_AUTHENTICATED          0x0F
326 #define GATT_ERR_NOT_ENCRYPTED              0x10
327 #define GATT_ERR_PROC_FAIL                  0x11
328 
329 /* sm error code */
330 #define SM_SUCCESS                          0x00
331 /* SMP_OP_PAIRING_FAILED causes */
332 #define SMP_ERR_SUCCESS                         0x00
333 #define SMP_ERR_PASSKEY_ENTRY_FAIL              0x01
334 #define SMP_ERR_OOB_NOT_AVAIABLE                0x02
335 #define SMP_ERR_AUTHEN_REQUIREMENTS             0x03
336 #define SMP_ERR_CFM_VALUE_FAILED                0x04
337 #define SMP_ERR_PAIRING_NOT_SUPPORTED           0x05
338 #define SMP_ERR_ENCRYPTION_KEY_SIZE             0x06
339 #define SMP_ERR_CMD_NOT_SUPPORTED               0x07
340 #define SMP_ERR_UNSPECIFIED_REASON              0x08
341 #define SMP_ERR_REPEATED_ATTEMPTS               0x09
342 #define SMP_ERR_INVALID_PARAM                   0x0A
343 #define SMP_ERR_DHKEY_CHECK_FAILED              0x0B
344 #define SMP_ERR_NUMERIC_COMPARISION_FAIL        0x0C
345 #define SMP_ERR_BREDR_PAIRING_IN_PROGRESS       0x0D
346 #define SMP_ERR_CRS_TRANS_KEY_GEN_NOT_ALLOW     0x0E
347 
348 #define SM_ERR_NO_ENTRY                         0xE1
349 #define SM_ERR_DB_FULL                          0xE2
350 #define SM_ERR_INVALID_PARAM                    0xE3
351 #define SM_ERR_INSUFFICIENT_LINK_KEY            0xE4
352 #define SM_ERR_LE_ADDR_NOT_RESOLVED             0xE5
353 #define SM_ERR_INVALID_STATE                    0xE6
354 #define SM_ERR_NO_RESOURCE                      0xE7
355 #define SM_ERR_LINK_KEY_MISSING                 0xE8
356 #define SM_ERR_DISCONNECT                       0xE9
357 #define SM_ERR_PARING_NOT_ALLOWED               0xEA
358 #define SM_ERR_KEY_SAVE_FAILED                  0xEB
359 #define SM_ERR_TIMEOUT                          0xEC
360 #define SM_ERR_UNKNOWN                          0xED
361 #define SM_ERR_NO_PAIRABLE_MODE                 0xEF
362 #define SM_ERR_VENDOR                           0xFF
363 
364 /**
365  * bt_types.h
366  *
367  * \name    BT_BTIF_ERROR
368  * \brief   BT btif error code definitions.
369  * \anchor  BT_BTIF_ERROR
370  */
371 /**
372  * \ingroup     BTTYPES
373  */
374 #define BTIF_ERR                0x0000
375 #define BTIF_SUCCESS                        0x00
376 #define BTIF_ACCEPT                         0x01
377 #define BTIF_ERR_REJECT                     0x02
378 #define BTIF_ERR_NO_RESOURCE                0x03
379 #define BTIF_ERR_INVALID_PARAM              0x04
380 #define BTIF_ERR_INVALID_STATE              0x05
381 #define BTIF_ERR_CONN_DISCONNECT            0x06
382 #define BTIF_ERR_CONN_LOST                  0x07
383 #define BTIF_ERR_AUTHEN_FAIL                0x08
384 #define BTIF_ERR_INIT_TOUT                  0x09
385 #define BTIF_ERR_INIT_OUT_OF_SYNC           0x0A
386 #define BTIF_ERR_INIT_HARDWARE_ERROR        0x0B
387 #define BTIF_ERR_LOWER_LAYER_ERROR          0x0C
388 #define BTIF_ERR_ADDR_NOT_RESOLVED          0x0D
389 #define BTIF_ERR_TOUT                       0x0E
390 
391 #define BTIF_ERR_UNSPECIFIED                0xFD
392 #define BTIF_ERR_NOT_SUPPORTED              0xFE
393 
394 /**
395  * bt_types.h
396  *
397  * \name    BT_GAP_ERROR
398  * \brief   BT GAP error code definitions.
399  * \anchor  BT_GAP_ERROR
400  */
401 /**
402  * \ingroup     BTTYPES
403  */
404 #define GAP_SUCCESS                         0x00
405 #define GAP_ACCEPT                          0x01
406 #define GAP_ERR_REJECT                      0x02
407 #define GAP_ERR_NO_RESOURCE                 0x03
408 #define GAP_ERR_INVALID_PARAM               0x04
409 #define GAP_ERR_INVALID_STATE               0x05
410 #define GAP_ERR_CONN_DISCONNECT             0x06
411 #define GAP_ERR_CONN_LOST                   0x07
412 #define GAP_ERR_AUTHEN_FAIL                 0x08
413 #define GAP_ERR_INIT_TOUT                   0x09
414 #define GAP_ERR_INIT_OUT_OF_SYNC            0x0A
415 #define GAP_ERR_INIT_HARDWARE_ERROR         0x0B
416 #define GAP_ERR_LOWER_LAYER_ERROR           0x0C
417 #define GAP_ERR_ADDR_NOT_RESOLVED           0x0D
418 #define GAP_ERR_TOUT                        0x0E
419 
420 #define GAP_ERR_SW_RESET                    0xFC
421 #define GAP_ERR_UNSPECIFIED                 0xFD
422 #define GAP_ERR_NOT_SUPPORTED               0xFE
423 
424 /**
425  * bt_types.h
426  *
427  * \name    BT_APP_ERROR
428  * \brief   BT APP error code definitions.
429  * \anchor  BT_APP_ERROR
430  */
431 /**
432  * \ingroup     BTTYPES
433  */
434 #define APP_SUCCESS                             0x00
435 #define APP_ERR_PENDING                         0x01
436 #define APP_ERR_ACCEPT                          0x03
437 #define APP_ERR_REJECT                          0x04
438 #define APP_ERR_NOT_RELEASE                     0x05
439 
440 /**
441  * bt_types.h
442  *
443  * \name    BT_BYTE_ORDER
444  * \brief   BT buffer/array byte-order utility macros.
445  * \anchor  BT_BYTE_ORDER
446  */
447 /**
448  * \ingroup     BTTYPES
449  */
450 /** Calculate integer bit count of b'1 */
451 #define INT_BIT_COUNT(integer, count)   {               \
452         count = 0;                                      \
453         while (integer)                                 \
454         {                                               \
455             count++;                                    \
456             integer &= integer - 1;                     \
457         }                                               \
458     }
459 
460 /** Stream skip len */
461 #define STREAM_SKIP_LEN(s, len)     {                   \
462         s += len;                                       \
463     }
464 
465 /** Stream to array */
466 #define STREAM_TO_ARRAY(a, s, len)  {                   \
467         uint32_t ii;                                    \
468         for (ii = 0; ii < len; ii++)                    \
469         {                                               \
470             *((uint8_t *)(a) + ii) = *s++;              \
471         }                                               \
472     }
473 
474 /** Array to stream */
475 #define ARRAY_TO_STREAM(s, a, len)  {                   \
476         uint32_t ii;                                    \
477         for (ii = 0; ii < len; ii++)                    \
478         {                                               \
479             *s++ = *((uint8_t *)(a) + ii);              \
480         }                                               \
481     }
482 
483 /** Little Endian stream to uint8 */
484 #define LE_STREAM_TO_UINT8(u8, s)   {                   \
485         u8  = (uint8_t)(*s);                            \
486         s  += 1;                                        \
487     }
488 
489 /** Little Endian stream to uint16 */
490 #define LE_STREAM_TO_UINT16(u16, s) {                   \
491         u16  = ((uint16_t)(*(s + 0)) << 0) +            \
492                ((uint16_t)(*(s + 1)) << 8);             \
493         s   += 2;                                       \
494     }
495 
496 /** Little Endian stream to uint24 */
497 #define LE_STREAM_TO_UINT24(u24, s) {                   \
498         u24  = ((uint32_t)(*(s + 0)) <<  0) +           \
499                ((uint32_t)(*(s + 1)) <<  8) +           \
500                ((uint32_t)(*(s + 2)) << 16);            \
501         s   += 3;                                       \
502     }
503 
504 /** Little Endian stream to uint32 */
505 #define LE_STREAM_TO_UINT32(u32, s) {                   \
506         u32  = ((uint32_t)(*(s + 0)) <<  0) +           \
507                ((uint32_t)(*(s + 1)) <<  8) +           \
508                ((uint32_t)(*(s + 2)) << 16) +           \
509                ((uint32_t)(*(s + 3)) << 24);            \
510         s   += 4;                                       \
511     }
512 
513 /** Little Endian uint8 to stream */
514 #define LE_UINT8_TO_STREAM(s, u8)   {                   \
515         *s++ = (uint8_t)(u8);                           \
516     }
517 
518 /** Little Endian uint16 to stream */
519 #define LE_UINT16_TO_STREAM(s, u16) {                   \
520         *s++ = (uint8_t)((u16) >> 0);                   \
521         *s++ = (uint8_t)((u16) >> 8);                   \
522     }
523 
524 /** Little Endian uint24 to stream */
525 #define LE_UINT24_TO_STREAM(s, u24) {                   \
526         *s++ = (uint8_t)((u24) >>  0);                  \
527         *s++ = (uint8_t)((u24) >>  8);                  \
528         *s++ = (uint8_t)((u24) >> 16);                  \
529     }
530 
531 /** Little Endian uint32 to stream */
532 #define LE_UINT32_TO_STREAM(s, u32) {                   \
533         *s++ = (uint8_t)((u32) >>  0);                  \
534         *s++ = (uint8_t)((u32) >>  8);                  \
535         *s++ = (uint8_t)((u32) >> 16);                  \
536         *s++ = (uint8_t)((u32) >> 24);                  \
537     }
538 
539 /** Little Endian array to uint8 */
540 #define LE_ARRAY_TO_UINT8(u8, a)    {                   \
541         u8  = (uint8_t)(*(a + 0));                      \
542     }
543 
544 /** Little Endian array to uint16 */
545 #define LE_ARRAY_TO_UINT16(u16, a)  {                   \
546         u16 = ((uint16_t)(*(a + 0)) << 0) +             \
547               ((uint16_t)(*(a + 1)) << 8);              \
548     }
549 
550 /** Little Endian array to uint24 */
551 #define LE_ARRAY_TO_UINT24(u24, a)  {                   \
552         u24 = ((uint32_t)(*(a + 0)) <<  0) +            \
553               ((uint32_t)(*(a + 1)) <<  8) +            \
554               ((uint32_t)(*(a + 2)) << 16);             \
555     }
556 
557 /** Little Endian array to uint32 */
558 #define LE_ARRAY_TO_UINT32(u32, a) {                    \
559         u32 = ((uint32_t)(*(a + 0)) <<  0) +            \
560               ((uint32_t)(*(a + 1)) <<  8) +            \
561               ((uint32_t)(*(a + 2)) << 16) +            \
562               ((uint32_t)(*(a + 3)) << 24);             \
563     }
564 
565 /** Little Endian uint8 to array */
566 #define LE_UINT8_TO_ARRAY(a, u8)    {                   \
567         *((uint8_t *)(a) + 0) = (uint8_t)(u8);          \
568     }
569 
570 /** Little Endian uint16 to array */
571 #define LE_UINT16_TO_ARRAY(a, u16)  {                   \
572         *((uint8_t *)(a) + 0) = (uint8_t)((u16) >> 0);  \
573         *((uint8_t *)(a) + 1) = (uint8_t)((u16) >> 8);  \
574     }
575 
576 /** Little Endian uint24 to array */
577 #define LE_UINT24_TO_ARRAY(a, u24) {                    \
578         *((uint8_t *)(a) + 0) = (uint8_t)((u24) >>  0); \
579         *((uint8_t *)(a) + 1) = (uint8_t)((u24) >>  8); \
580         *((uint8_t *)(a) + 2) = (uint8_t)((u24) >> 16); \
581     }
582 
583 /** Little Endian uint32 to array */
584 #define LE_UINT32_TO_ARRAY(a, u32) {                    \
585         *((uint8_t *)(a) + 0) = (uint8_t)((u32) >>  0); \
586         *((uint8_t *)(a) + 1) = (uint8_t)((u32) >>  8); \
587         *((uint8_t *)(a) + 2) = (uint8_t)((u32) >> 16); \
588         *((uint8_t *)(a) + 3) = (uint8_t)((u32) >> 24); \
589     }
590 
591 /** Big Endian stream to uint8 */
592 #define BE_STREAM_TO_UINT8(u8, s)   {                   \
593         u8   = (uint8_t)(*(s + 0));                     \
594         s   += 1;                                       \
595     }
596 
597 /** Big Endian stream to uint16 */
598 #define BE_STREAM_TO_UINT16(u16, s) {                   \
599         u16  = ((uint16_t)(*(s + 0)) << 8) +            \
600                ((uint16_t)(*(s + 1)) << 0);             \
601         s   += 2;                                       \
602     }
603 
604 /** Big Endian stream to uint24 */
605 #define BE_STREAM_TO_UINT24(u24, s) {                   \
606         u24  = ((uint32_t)(*(s + 0)) << 16) +           \
607                ((uint32_t)(*(s + 1)) <<  8) +           \
608                ((uint32_t)(*(s + 2)) <<  0);            \
609         s   += 3;                                       \
610     }
611 
612 /** Big Endian stream to uint32 */
613 #define BE_STREAM_TO_UINT32(u32, s) {                   \
614         u32  = ((uint32_t)(*(s + 0)) << 24) +           \
615                ((uint32_t)(*(s + 1)) << 16) +           \
616                ((uint32_t)(*(s + 2)) <<  8) +           \
617                ((uint32_t)(*(s + 3)) <<  0);            \
618         s   += 4;                                       \
619     }
620 
621 /** Big Endian uint8 to stream */
622 #define BE_UINT8_TO_STREAM(s, u8)   {                   \
623         *s++ = (uint8_t)(u8);                           \
624     }
625 
626 /** Big Endian uint16 to stream */
627 #define BE_UINT16_TO_STREAM(s, u16) {                   \
628         *s++ = (uint8_t)((u16) >> 8);                   \
629         *s++ = (uint8_t)((u16) >> 0);                   \
630     }
631 
632 /** Big Endian uint24 to stream */
633 #define BE_UINT24_TO_STREAM(s, u24) {                   \
634         *s++ = (uint8_t)((u24) >> 16);                  \
635         *s++ = (uint8_t)((u24) >>  8);                  \
636         *s++ = (uint8_t)((u24) >>  0);                  \
637     }
638 
639 /** Big Endian uint32 to stream */
640 #define BE_UINT32_TO_STREAM(s, u32) {                   \
641         *s++ = (uint8_t)((u32) >> 24);                  \
642         *s++ = (uint8_t)((u32) >> 16);                  \
643         *s++ = (uint8_t)((u32) >>  8);                  \
644         *s++ = (uint8_t)((u32) >>  0);                  \
645     }
646 
647 /** Big Endian array to uint8 */
648 #define BE_ARRAY_TO_UINT8(u8, a)    {                   \
649         u8  = (uint8_t)(*(a + 0));                      \
650     }
651 
652 /** Big Endian array to uint16 */
653 #define BE_ARRAY_TO_UINT16(u16, a)  {                   \
654         u16 = ((uint16_t)(*(a + 0)) << 8) +             \
655               ((uint16_t)(*(a + 1)) << 0);              \
656     }
657 
658 /** Big Endian array to uint24 */
659 #define BE_ARRAY_TO_UINT24(u24, a)  {                   \
660         u24 = ((uint32_t)(*(a + 0)) << 16) +            \
661               ((uint32_t)(*(a + 1)) <<  8) +            \
662               ((uint32_t)(*(a + 2)) <<  0);             \
663     }
664 
665 /** Big Endian array to uint32 */
666 #define BE_ARRAY_TO_UINT32(u32, a)  {                   \
667         u32 = ((uint32_t)(*(a + 0)) << 24) +            \
668               ((uint32_t)(*(a + 1)) << 16) +            \
669               ((uint32_t)(*(a + 2)) <<  8) +            \
670               ((uint32_t)(*(a + 3)) <<  0);             \
671     }
672 
673 /** Big Endian uint8 to array */
674 #define BE_UINT8_TO_ARRAY(a, u8)    {                   \
675         *((uint8_t *)(a) + 0) = (uint8_t)(u8);          \
676     }
677 
678 /** Big Endian uint16 to array */
679 #define BE_UINT16_TO_ARRAY(a, u16)  {                   \
680         *((uint8_t *)(a) + 0) = (uint8_t)((u16) >> 8);  \
681         *((uint8_t *)(a) + 1) = (uint8_t)((u16) >> 0);  \
682     }
683 
684 /** Big Endian uint24 to array */
685 #define BE_UINT24_TO_ARRAY(a, u24)  {                   \
686         *((uint8_t *)(a) + 0) = (uint8_t)((u24) >> 16); \
687         *((uint8_t *)(a) + 1) = (uint8_t)((u24) >>  8); \
688         *((uint8_t *)(a) + 2) = (uint8_t)((u24) >>  0); \
689     }
690 
691 /** Big Endian uint32 to array */
692 #define BE_UINT32_TO_ARRAY(a, u32)  {                   \
693         *((uint8_t *)(a) + 0) = (uint8_t)((u32) >> 24); \
694         *((uint8_t *)(a) + 1) = (uint8_t)((u32) >> 16); \
695         *((uint8_t *)(a) + 2) = (uint8_t)((u32) >>  8); \
696         *((uint8_t *)(a) + 3) = (uint8_t)((u32) >>  0); \
697     }
698 
699 #ifdef __cplusplus
700 }
701 #endif
702 
703 #endif /* _BT_TYPES_H_ */
704