1 /******************************************************************************
2  *
3  *  Copyright (C) 2012-2014 Broadcom Corporation
4  *
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at:
8  *
9  *  http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  ******************************************************************************/
18 
19 #ifndef NFC_TYPES_H
20 #define NFC_TYPES_H
21 
22 /****************************************************************************
23 ** NFC_HDR header definition for NFC messages
24 *****************************************************************************/
25 typedef struct {
26   uint16_t event;
27   uint16_t len;
28   uint16_t offset;
29   uint16_t layer_specific;
30 } NFC_HDR;
31 #define NFC_HDR_SIZE (sizeof(NFC_HDR))
32 
33 /* Mask for NFC_HDR event field */
34 #define NFC_EVT_MASK 0xFF00
35 #define NFC_SUB_EVT_MASK 0x00FF
36 
37 /****************************************************************************
38 ** NFC_HAL_TASK  definitions
39 *****************************************************************************/
40 
41 /* NFC_HAL_TASK event messages */
42 /* NCI message for sending to NFCC          */
43 #define NFC_HAL_EVT_TO_NFC_NCI 0x0100
44 /* Request to start NCIT quick timer        */
45 #define NFC_HAL_EVT_POST_CORE_RESET 0x0200
46 /* Request to start chip-specific config    */
47 #define NFC_HAL_EVT_TO_START_QUICK_TIMER 0x0300
48 /* NCI message for hci persistency data     */
49 #define NFC_HAL_EVT_HCI 0x0400
50 /* NCI message to issue prediscover config  */
51 #define NFC_HAL_EVT_PRE_DISCOVER 0x0500
52 /* permission to send commands queued in HAL*/
53 #define NFC_HAL_EVT_CONTROL_GRANTED 0x0600
54 
55 /* NFC_HAL_TASK sub event messages */
56 #define NFC_HAL_HCI_RSP_NV_READ_EVT (0x01 | NFC_HAL_EVT_HCI)
57 #define NFC_HAL_HCI_RSP_NV_WRITE_EVT (0x02 | NFC_HAL_EVT_HCI)
58 #define NFC_HAL_HCI_VSC_TIMEOUT_EVT (0x03 | NFC_HAL_EVT_HCI)
59 
60 /* Event masks for NFC_TASK messages */
61 /* NCI message for sending to host stack    */
62 #define NFC_EVT_TO_NFC_NCI 0x4000
63 /* Error notification to NFC Task           */
64 #define NFC_EVT_TO_NFC_ERR 0x4100
65 /* Messages between NFC and NCI task        */
66 #define NFC_EVT_TO_NFC_MSGS 0x4200
67 
68 /*****************************************************************************
69 ** Macros to get and put bytes to and from a stream (Little Endian format).
70 *****************************************************************************/
71 
72 #define UINT32_TO_STREAM(p, u32)     \
73   {                                  \
74     *(p)++ = (uint8_t)(u32);         \
75     *(p)++ = (uint8_t)((u32) >> 8);  \
76     *(p)++ = (uint8_t)((u32) >> 16); \
77     *(p)++ = (uint8_t)((u32) >> 24); \
78   }
79 #define UINT24_TO_STREAM(p, u24)     \
80   {                                  \
81     *(p)++ = (uint8_t)(u24);         \
82     *(p)++ = (uint8_t)((u24) >> 8);  \
83     *(p)++ = (uint8_t)((u24) >> 16); \
84   }
85 #define UINT16_TO_STREAM(p, u16)    \
86   {                                 \
87     *(p)++ = (uint8_t)(u16);        \
88     *(p)++ = (uint8_t)((u16) >> 8); \
89   }
90 #define UINT8_TO_STREAM(p, u8) \
91   { *(p)++ = (uint8_t)(u8); }
92 #define INT8_TO_STREAM(p, u8) \
93   { *(p)++ = (int8_t)(u8); }
94 #define ARRAY32_TO_STREAM(p, a)                                   \
95   {                                                               \
96     register int ijk;                                             \
97     for (ijk = 0; ijk < 32; ijk++) *(p)++ = (uint8_t)a[31 - ijk]; \
98   }
99 #define ARRAY16_TO_STREAM(p, a)                                   \
100   {                                                               \
101     register int ijk;                                             \
102     for (ijk = 0; ijk < 16; ijk++) *(p)++ = (uint8_t)a[15 - ijk]; \
103   }
104 #define ARRAY8_TO_STREAM(p, a)                                  \
105   {                                                             \
106     register int ijk;                                           \
107     for (ijk = 0; ijk < 8; ijk++) *(p)++ = (uint8_t)a[7 - ijk]; \
108   }
109 #define BDADDR_TO_STREAM(p, a)                    \
110   {                                               \
111     register int ijk;                             \
112     for (ijk = 0; ijk < BD_ADDR_LEN; ijk++)       \
113       *(p)++ = (uint8_t)a[BD_ADDR_LEN - 1 - ijk]; \
114   }
115 #define LAP_TO_STREAM(p, a)                   \
116   {                                           \
117     register int ijk;                         \
118     for (ijk = 0; ijk < LAP_LEN; ijk++)       \
119       *(p)++ = (uint8_t)a[LAP_LEN - 1 - ijk]; \
120   }
121 #define DEVCLASS_TO_STREAM(p, a)                    \
122   {                                                 \
123     register int ijk;                               \
124     for (ijk = 0; ijk < DEV_CLASS_LEN; ijk++)       \
125       *(p)++ = (uint8_t)a[DEV_CLASS_LEN - 1 - ijk]; \
126   }
127 #define ARRAY_TO_STREAM(p, a, len)                            \
128   {                                                           \
129     register int ijk;                                         \
130     for (ijk = 0; ijk < len; ijk++) *(p)++ = (uint8_t)a[ijk]; \
131   }
132 #define REVERSE_ARRAY_TO_STREAM(p, a, len)                              \
133   {                                                                     \
134     register int ijk;                                                   \
135     for (ijk = 0; ijk < len; ijk++) *(p)++ = (uint8_t)a[len - 1 - ijk]; \
136   }
137 
138 #define STREAM_TO_UINT8(u8, p) \
139   {                            \
140     u8 = (uint8_t)(*(p));      \
141     (p) += 1;                  \
142   }
143 #define STREAM_TO_UINT16(u16, p)                                \
144   {                                                             \
145     u16 = ((uint16_t)(*(p)) + (((uint16_t)(*((p) + 1))) << 8)); \
146     (p) += 2;                                                   \
147   }
148 #define STREAM_TO_UINT24(u32, p)                                    \
149   {                                                                 \
150     u32 = (((uint32_t)(*(p))) + ((((uint32_t)(*((p) + 1)))) << 8) + \
151            ((((uint32_t)(*((p) + 2)))) << 16));                     \
152     (p) += 3;                                                       \
153   }
154 #define STREAM_TO_UINT32(u32, p)                                    \
155   {                                                                 \
156     u32 = (((uint32_t)(*(p))) + ((((uint32_t)(*((p) + 1)))) << 8) + \
157            ((((uint32_t)(*((p) + 2)))) << 16) +                     \
158            ((((uint32_t)(*((p) + 3)))) << 24));                     \
159     (p) += 4;                                                       \
160   }
161 #define STREAM_TO_BDADDR(a, p)                              \
162   {                                                         \
163     register int ijk;                                       \
164     register uint8_t* pbda = (uint8_t*)a + BD_ADDR_LEN - 1; \
165     for (ijk = 0; ijk < BD_ADDR_LEN; ijk++) *pbda-- = *p++; \
166   }
167 #define STREAM_TO_ARRAY32(a, p)                   \
168   {                                               \
169     register int ijk;                             \
170     register uint8_t* _pa = (uint8_t*)a + 31;     \
171     for (ijk = 0; ijk < 32; ijk++) *_pa-- = *p++; \
172   }
173 #define STREAM_TO_ARRAY16(a, p)                   \
174   {                                               \
175     register int ijk;                             \
176     register uint8_t* _pa = (uint8_t*)a + 15;     \
177     for (ijk = 0; ijk < 16; ijk++) *_pa-- = *p++; \
178   }
179 #define STREAM_TO_ARRAY8(a, p)                   \
180   {                                              \
181     register int ijk;                            \
182     register uint8_t* _pa = (uint8_t*)a + 7;     \
183     for (ijk = 0; ijk < 8; ijk++) *_pa-- = *p++; \
184   }
185 #define STREAM_TO_DEVCLASS(a, p)                             \
186   {                                                          \
187     register int ijk;                                        \
188     register uint8_t* _pa = (uint8_t*)a + DEV_CLASS_LEN - 1; \
189     for (ijk = 0; ijk < DEV_CLASS_LEN; ijk++) *_pa-- = *p++; \
190   }
191 #define STREAM_TO_LAP(a, p)                             \
192   {                                                     \
193     register int ijk;                                   \
194     register uint8_t* plap = (uint8_t*)a + LAP_LEN - 1; \
195     for (ijk = 0; ijk < LAP_LEN; ijk++) *plap-- = *p++; \
196   }
197 #define STREAM_TO_ARRAY(a, p, len)                             \
198   {                                                            \
199     register int ijk;                                          \
200     for (ijk = 0; ijk < len; ijk++) ((uint8_t*)a)[ijk] = *p++; \
201   }
202 #define REVERSE_STREAM_TO_ARRAY(a, p, len)         \
203   {                                                \
204     register int ijk;                              \
205     register uint8_t* _pa = (uint8_t*)a + len - 1; \
206     for (ijk = 0; ijk < len; ijk++) *_pa-- = *p++; \
207   }
208 
209 /*****************************************************************************
210 ** Macros to get and put bytes to and from a field (Little Endian format).
211 ** These are the same as to stream, except the pointer is not incremented.
212 *****************************************************************************/
213 
214 #define UINT32_TO_FIELD(p, u32)                    \
215   {                                                \
216     *(uint8_t*)(p) = (uint8_t)(u32);               \
217     *((uint8_t*)(p) + 1) = (uint8_t)((u32) >> 8);  \
218     *((uint8_t*)(p) + 2) = (uint8_t)((u32) >> 16); \
219     *((uint8_t*)(p) + 3) = (uint8_t)((u32) >> 24); \
220   }
221 #define UINT24_TO_FIELD(p, u24)                    \
222   {                                                \
223     *(uint8_t*)(p) = (uint8_t)(u24);               \
224     *((uint8_t*)(p) + 1) = (uint8_t)((u24) >> 8);  \
225     *((uint8_t*)(p) + 2) = (uint8_t)((u24) >> 16); \
226   }
227 #define UINT16_TO_FIELD(p, u16)                   \
228   {                                               \
229     *(uint8_t*)(p) = (uint8_t)(u16);              \
230     *((uint8_t*)(p) + 1) = (uint8_t)((u16) >> 8); \
231   }
232 #define UINT8_TO_FIELD(p, u8) \
233   { *(uint8_t*)(p) = (uint8_t)(u8); }
234 
235 /*****************************************************************************
236 ** Macros to get and put bytes to and from a stream (Big Endian format)
237 *****************************************************************************/
238 
239 #define UINT32_TO_BE_STREAM(p, u32)  \
240   {                                  \
241     *(p)++ = (uint8_t)((u32) >> 24); \
242     *(p)++ = (uint8_t)((u32) >> 16); \
243     *(p)++ = (uint8_t)((u32) >> 8);  \
244     *(p)++ = (uint8_t)(u32);         \
245   }
246 #define UINT24_TO_BE_STREAM(p, u24)  \
247   {                                  \
248     *(p)++ = (uint8_t)((u24) >> 16); \
249     *(p)++ = (uint8_t)((u24) >> 8);  \
250     *(p)++ = (uint8_t)(u24);         \
251   }
252 #define UINT16_TO_BE_STREAM(p, u16) \
253   {                                 \
254     *(p)++ = (uint8_t)((u16) >> 8); \
255     *(p)++ = (uint8_t)(u16);        \
256   }
257 #define UINT8_TO_BE_STREAM(p, u8) \
258   { *(p)++ = (uint8_t)(u8); }
259 #define ARRAY_TO_BE_STREAM(p, a, len)                         \
260   {                                                           \
261     register int ijk;                                         \
262     for (ijk = 0; ijk < len; ijk++) *(p)++ = (uint8_t)a[ijk]; \
263   }
264 
265 #define BE_STREAM_TO_UINT8(u8, p) \
266   {                               \
267     u8 = (uint8_t)(*(p));         \
268     (p) += 1;                     \
269   }
270 #define BE_STREAM_TO_UINT16(u16, p)                                     \
271   {                                                                     \
272     u16 = (uint16_t)(((uint16_t)(*(p)) << 8) + (uint16_t)(*((p) + 1))); \
273     (p) += 2;                                                           \
274   }
275 #define BE_STREAM_TO_UINT24(u32, p)                                   \
276   {                                                                   \
277     u32 = (((uint32_t)(*((p) + 2))) + ((uint32_t)(*((p) + 1)) << 8) + \
278            ((uint32_t)(*(p)) << 16));                                 \
279     (p) += 3;                                                         \
280   }
281 #define BE_STREAM_TO_UINT32(u32, p)                                    \
282   {                                                                    \
283     u32 = ((uint32_t)(*((p) + 3)) + ((uint32_t)(*((p) + 2)) << 8) +    \
284            ((uint32_t)(*((p) + 1)) << 16) + ((uint32_t)(*(p)) << 24)); \
285     (p) += 4;                                                          \
286   }
287 #define BE_STREAM_TO_ARRAY(p, a, len)                          \
288   {                                                            \
289     register int ijk;                                          \
290     for (ijk = 0; ijk < len; ijk++) ((uint8_t*)a)[ijk] = *p++; \
291   }
292 
293 /*****************************************************************************
294 ** Macros to get and put bytes to and from a field (Big Endian format).
295 ** These are the same as to stream, except the pointer is not incremented.
296 *****************************************************************************/
297 
298 #define UINT32_TO_BE_FIELD(p, u32)                 \
299   {                                                \
300     *(uint8_t*)(p) = (uint8_t)((u32) >> 24);       \
301     *((uint8_t*)(p) + 1) = (uint8_t)((u32) >> 16); \
302     *((uint8_t*)(p) + 2) = (uint8_t)((u32) >> 8);  \
303     *((uint8_t*)(p) + 3) = (uint8_t)(u32);         \
304   }
305 #define UINT24_TO_BE_FIELD(p, u24)                \
306   {                                               \
307     *(uint8_t*)(p) = (uint8_t)((u24) >> 16);      \
308     *((uint8_t*)(p) + 1) = (uint8_t)((u24) >> 8); \
309     *((uint8_t*)(p) + 2) = (uint8_t)(u24);        \
310   }
311 #define UINT16_TO_BE_FIELD(p, u16)          \
312   {                                         \
313     *(uint8_t*)(p) = (uint8_t)((u16) >> 8); \
314     *((uint8_t*)(p) + 1) = (uint8_t)(u16);  \
315   }
316 #define UINT8_TO_BE_FIELD(p, u8) \
317   { *(uint8_t*)(p) = (uint8_t)(u8); }
318 
319 /*****************************************************************************
320 ** Define trace levels
321 *****************************************************************************/
322 
323 /* No trace messages to be generated    */
324 #define BT_TRACE_LEVEL_NONE 0
325 /* Error condition trace messages       */
326 #define BT_TRACE_LEVEL_ERROR 1
327 /* Warning condition trace messages     */
328 #define BT_TRACE_LEVEL_WARNING 2
329 /* API traces                           */
330 #define BT_TRACE_LEVEL_API 3
331 /* Debug messages for events            */
332 #define BT_TRACE_LEVEL_EVENT 4
333 /* Full debug messages                  */
334 #define BT_TRACE_LEVEL_DEBUG 5
335 
336 #define TRACE_CTRL_GENERAL 0x00000000
337 #define TRACE_LAYER_NCI 0x00280000
338 #define TRACE_LAYER_HAL 0x00310000
339 #define TRACE_LAYER_GKI 0x001a0000
340 #define TRACE_ORG_STACK 0x00000000
341 #define TRACE_ORG_GKI 0x00000400
342 
343 #define TRACE_TYPE_ERROR 0x00000000
344 #define TRACE_TYPE_WARNING 0x00000001
345 #define TRACE_TYPE_API 0x00000002
346 #define TRACE_TYPE_EVENT 0x00000003
347 #define TRACE_TYPE_DEBUG 0x00000004
348 
349 #define TRACE_TYPE_GENERIC 0x00000008
350 
351 #endif /* NFC_TYPES_H */
352