merge with master
[adaptation/devices/nfc-plugin-nxp.git] / src / phLlcNfc_Frame.h
1 /*\r
2  * Copyright (C) 2010 NXP Semiconductors\r
3  *\r
4  * Licensed under the Apache License, Version 2.0 (the "License");\r
5  * you may not use this file except in compliance with the License.\r
6  * You may obtain a copy of the License at\r
7  *\r
8  *      http://www.apache.org/licenses/LICENSE-2.0\r
9  *\r
10  * Unless required by applicable law or agreed to in writing, software\r
11  * distributed under the License is distributed on an "AS IS" BASIS,\r
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13  * See the License for the specific language governing permissions and\r
14  * limitations under the License.\r
15  */\r
16 \r
17 /*!\r
18 * \file  phLlcNfc_Frame.h\r
19 * \brief To append and delete the I or S or U frames.\r
20 *\r
21 * Project: NFC-FRI-1.1\r
22 *\r
23 * $Date: Fri Apr 30 10:03:36 2010 $\r
24 * $Author: ing02260 $\r
25 * $Revision: 1.19 $\r
26 * $Aliases: NFC_FRI1.1_WK1017_R34_1,NFC_FRI1.1_WK1017_R34_2,NFC_FRI1.1_WK1023_R35_1 $\r
27 *\r
28 */\r
29 \r
30 #ifndef PHLLCNFC_FRAME_H\r
31 #define PHLLCNFC_FRAME_H\r
32 \r
33 /**\r
34 *  \name LLC NFC frame creation and deletion\r
35 *\r
36 * File: \ref phLlcNfc_Frame.h\r
37 *\r
38 */\r
39 /*@{*/\r
40 #define PHLLCNFCFRAME_FILEREVISION "$Revision: 1.19 $" /**< \ingroup grp_hal_nfc_llc */\r
41 #define PHLLCNFCFRAME_FILEALIASES   "$Aliases: NFC_FRI1.1_WK1017_R34_1,NFC_FRI1.1_WK1017_R34_2,NFC_FRI1.1_WK1023_R35_1 $"    /**< \ingroup grp_hal_nfc_llc */\r
42 /*@}*/\r
43 \r
44 /*************************** Includes *******************************/\r
45 \r
46 /*********************** End of includes ****************************/\r
47 \r
48 /** \defgroup grp_hal_nfc_llc_helper LLC helper functions\r
49  *\r
50  *\r
51  *\r
52  */\r
53 \r
54 /***************************** Macros *******************************/\r
55 /** Maximum buffer that LLC can send and receive */\r
56 #define PH_LLCNFC_MAX_BUFLEN_RECV_SEND                      (33)\r
57 /** Maximum buffer that LLC can send and receive */\r
58 #define PH_LLCNFC_MIN_BUFLEN_RECVD                      (1)\r
59 /** Modulo to calculate the N(S) and N(R), when it extends 7, because \r
60     N(S) and N(R) can have the value maximum up to 7 */\r
61 #define PH_LLCNFC_MOD_NS_NR                                 (8)\r
62 /** When the entire LLC buffer is created or received, the header byte \r
63     will be the first byte (not the 0th byte which is the LLC length)\r
64     of the buffer */\r
65 #define PH_LLCNFC_HEADER_BYTE_IN_BUFFER                     (1)\r
66 /** Maximum windows size, which is obtained by sending or \r
67     receiving the U - frame */\r
68 #define PH_LLCNFC_U_FRAME_MAX_WIN_SIZE                      (4)\r
69 /** Minimum windows size, which is obtained by sending or \r
70     receiving the U - frame */\r
71 #define PH_LLCNFC_U_FRAME_MIN_WIN_SIZE                      (2)\r
72 /** Start position of the U frame */\r
73 #define PH_LLCNFC_U_FRAME_START_POS                         (0)\r
74 /** No of position to set the U frame */\r
75 #define PH_LLCNFC_U_FRAME_NO_OF_POS                         (5)\r
76 /** This mask is to find the frame type ( S or U) */\r
77 #define PH_LLCNFC_LLC_HEADER_MASK                           (0xE0)\r
78 /** This mask is to find the frame type (I, S or U) */\r
79 #define PH_LLCNFC_I_FRM_HEADER_MASK                         (0x80)\r
80 /** If S frame is received or to be sent, the maximum length that \r
81     can be sent or received is 4 */\r
82 #define PH_LLCNFC_MAX_S_FRAME_LEN                           (4)\r
83 /** If S frame is received, to know the command type like RR, RNR, \r
84     REJ or SREJ */\r
85 #define PH_LLCNFC_S_FRAME_TYPE_MASK                         (0x18)\r
86 /** Maximum value of N(S) or N(R) */\r
87 #define PH_LLCNFC_I_S_FRAME_MAX_NR                          (0x07)\r
88 /** If U frame is received or to be sent, the maximum length that \r
89     can be sent or received is 7 */\r
90 #define PH_LLCNFC_U_FRAME_LEN                               (7)\r
91 /** If S frame is received, to know the command type like RSET or UA */\r
92 #define PH_LLCNFC_U_FRAME_MODIFIER_MASK                     (0x1F)\r
93 /** Extra length to be append to the user buffer Length to create the \r
94     LLC buffer */\r
95 #define PH_LLCNFC_LEN_APPEND                                (0x04)\r
96 /** U frame header without modifier */\r
97 #define PH_LLCNFC_U_HEADER_INIT                             (0xE0)\r
98 /** I frame header without N(S) and N(R) */\r
99 #define PH_LLCNFC_I_HEADER_INIT                             (0x80)\r
100 /** S frame header without type and N(R) */\r
101 #define PH_LLCNFC_S_HEADER_INIT                             (0xC0)\r
102 /** N(S) start bit position */\r
103 #define PH_LLCNFC_NS_START_BIT_POS                          (0x03)\r
104 /** N(R) start bit position */\r
105 #define PH_LLCNFC_NR_START_BIT_POS                          (0x00)\r
106 /** Number of bits N(R) and N(S)  */\r
107 #define PH_LLCNFC_NR_NS_NO_OF_BITS                          (0x03)\r
108 /** S frame type start bit position */\r
109 #define PH_LLCNFC_S_FRAME_TYPE_POS                          (0x03)\r
110 /** Number of bits (Type in S frame)  */\r
111 #define PH_LLCNFC_SFRAME_TYPE_NOOFBITS                      (0x02)\r
112 /** SREJ command */\r
113 #define PH_LLCNFC_SREJ_BYTE_VALUE                           (0x00)\r
114 /** Number of CRC bytes in a LLC packet */\r
115 #define PH_LLCNFC_NUM_OF_CRC_BYTES                          (0x02)\r
116 \r
117 /* This macro is used as the input for the function "phLlcNfc_H_IFrameList_Peek" \r
118     and "phLlcNfc_H_SendTimedOutIFrame" functions. This values means, take the starting \r
119     position as the reference */\r
120 #define DEFAULT_PACKET_INPUT                                (0xFFU)\r
121 #define MAX_NS_NR_VALUE                                     (0x07U)\r
122 \r
123 /************************ End of macros *****************************/\r
124 \r
125 /********************** Callback functions **************************/\r
126 \r
127 /******************* End of Callback functions **********************/\r
128 \r
129 /********************* Structures and enums *************************/\r
130 \r
131 /****************** End of structures and enums *********************/\r
132 \r
133 /******************** Function declarations *************************/\r
134 /**\r
135 * \ingroup grp_hal_nfc_llc_helper\r
136 *\r
137 * \brief LLC helper functions \b Frame Init function\r
138 *\r
139 * \copydoc page_reg Gets the LLC main context and stores it.\r
140 *\r
141 * \param[in] psLlcCtxt  Llc main structure information\r
142 *\r
143 * \retval NFCSTATUS_SUCCESS                Operation successful.\r
144 * \retval NFCSTATUS_INVALID_PARAMETER      At least one parameter of the function is invalid.\r
145 *\r
146 */\r
147 void phLlcNfc_H_Frame_Init (\r
148     phLlcNfc_Context_t  *psLlcCtxt\r
149 );\r
150 \r
151 /**\r
152 * \ingroup grp_hal_nfc_llc_helper\r
153 *\r
154 * \brief LLC helper functions \b DeInit function\r
155 *\r
156 * \copydoc page_reg \r
157 *\r
158 * \param[in] psFrameInfo    Frame structure information\r
159 *\r
160 * \retval NFCSTATUS_SUCCESS                Operation successful.\r
161 * \retval NFCSTATUS_INVALID_PARAMETER      At least one parameter of the function is invalid.\r
162 *\r
163 */\r
164 void \r
165 phLlcNfc_H_Frame_DeInit (\r
166     phLlcNfc_Frame_t    *psFrameInfo\r
167 );\r
168 \r
169 /**\r
170 * \ingroup grp_hal_nfc_llc_helper\r
171 *\r
172 * \brief LLC helper functions \b List append function\r
173 *\r
174 * \copydoc page_reg Append the new I frame information at the beginning of the list\r
175 *\r
176 * \param[in/out] psList     List inofrmation to know where shall the packet should be stored\r
177 * \param[in] packetInfo     Llc packet information\r
178 *\r
179 * \retval NFCSTATUS_SUCCESS                Operation successful.\r
180 * \retval NFCSTATUS_INVALID_PARAMETER      At least one parameter of the function is invalid.\r
181 *\r
182 */\r
183 NFCSTATUS \r
184 phLlcNfc_H_StoreIFrame (\r
185     phLlcNfc_StoreIFrame_t      *psList,\r
186     phLlcNfc_LlcPacket_t        sPacketInfo\r
187 \r
188 );\r
189 \r
190 \r
191 /**\r
192 * \ingroup grp_hal_nfc_llc_helper\r
193 *\r
194 * \brief LLC helper functions <b>Create S frame</b> function\r
195 *\r
196 * \copydoc page_reg This function creates a S frame\r
197 *\r
198 * \param[in/out] pllcSFrmBuf    Required buffer to create the S frame\r
199 *\r
200 * \retval NFCSTATUS_SUCCESS                Operation successful.\r
201 * \retval NFCSTATUS_INVALID_PARAMETER      At least one parameter of the function is invalid.\r
202 *\r
203 */\r
204 void \r
205 phLlcNfc_H_Create_S_Frame(\r
206     uint8_t     *pllcSFrmBuf\r
207 );\r
208 \r
209 /**\r
210 * \ingroup grp_hal_nfc_llc_helper\r
211 *\r
212 * \brief LLC helper functions <b>Compute CRC</b> function\r
213 *\r
214 * \copydoc page_reg This function is used to compute CRC for the llc data\r
215 *\r
216 * \param[in] pData      Llc data for which the CRC needs to be calculated\r
217 * \param[in] length     Length is the value till the CRC needs to be \r
218 *                       calculated for the Llc data\r
219 * \param[in] pCrc1      1st CRC byte\r
220 * \param[in] pCrc2      2nd CRC byte\r
221 *\r
222 * \retval NFCSTATUS_SUCCESS                Operation successful.\r
223 * \retval NFCSTATUS_INVALID_PARAMETER      At least one parameter of the function is invalid.\r
224 *\r
225 */\r
226 void \r
227 phLlcNfc_H_ComputeCrc(\r
228     uint8_t     *pData, \r
229     uint8_t     length,\r
230     uint8_t     *pCrc1, \r
231     uint8_t     *pCrc2\r
232 );\r
233 \r
234 /**\r
235 * \ingroup grp_hal_nfc_llc_helper\r
236 *\r
237 * \brief LLC helper functions <b>Create U frame payload </b> function\r
238 *\r
239 * \copydoc page_reg This function is used to create a LLC packet with U frame\r
240 *\r
241 * \param[in/out]    psLlcCtxt           Llc main structure information\r
242 * \param[in/out]    psLlcPacket         Llc packet sent by the upper layer\r
243 * \param[in/out]    pLlcPacketLength    Length of the llc packet\r
244 * \param[in]        cmdType             U frame has RSET/UA commands\r
245 *\r
246 * \retval NFCSTATUS_SUCCESS                Operation successful.\r
247 * \retval NFCSTATUS_INVALID_PARAMETER      At least one parameter of the function is invalid.\r
248 *\r
249 */\r
250 NFCSTATUS\r
251 phLlcNfc_H_CreateUFramePayload (\r
252     phLlcNfc_Context_t      *psLlcCtxt, \r
253     phLlcNfc_LlcPacket_t    *psLlcPacket, \r
254     uint8_t                 *pLlcPacketLength, \r
255     phLlcNfc_LlcCmd_t       cmdType\r
256 );\r
257 \r
258 /**\r
259 * \ingroup grp_hal_nfc_llc_helper\r
260 *\r
261 * \brief LLC helper functions <b>Create I frame payload </b> function\r
262 *\r
263 * \copydoc page_reg This function is used to create a LLC packet with I frame\r
264 *\r
265 * \param[in/out]    psFrameInfo Information related to LLC frames are stored \r
266 *                           in this structure\r
267 * \param[in/out]    psLlcPacket         Llc packet sent by the upper layer\r
268 * \param[in]        pLlcBuf     User given buffer or the buffer which needs LLC framing\r
269 * \param[in]        llcBufLength    Length of the parameter "pLlcBuf" \r
270 *\r
271 * \retval NFCSTATUS_SUCCESS                Operation successful.\r
272 * \retval NFCSTATUS_INVALID_PARAMETER      At least one parameter of the function is invalid.\r
273 *\r
274 */\r
275 NFCSTATUS\r
276 phLlcNfc_H_CreateIFramePayload (\r
277     phLlcNfc_Frame_t        *psFrameInfo, \r
278     phLlcNfc_LlcPacket_t    *psLlcPacket, \r
279     uint8_t                 *pLlcBuf, \r
280     uint8_t                 llcBufLength\r
281 );\r
282 \r
283 /**\r
284  * \ingroup grp_hal_nfc_llc_helper\r
285  *\r
286  * \brief LLC helper functions <b>Process received frame </b> function\r
287  *\r
288  * \copydoc page_reg This function process the received data\r
289  *\r
290  * \param[in]   pLlcCtxt    Llc main context\r
291  *\r
292  * \retval NFCSTATUS_SUCCESS           Operation successful.\r
293  * \retval NFCSTATUS_INVALID_FORMAT    If any error in the frame\r
294  */\r
295 NFCSTATUS \r
296 phLlcNfc_H_ProRecvFrame (\r
297     phLlcNfc_Context_t      *psLlcCtxt\r
298 );\r
299 \r
300 /**\r
301 * \ingroup grp_hal_nfc_llc_helper\r
302 *\r
303 * \brief LLC component <b>resend the I frame</b> function\r
304 *\r
305 * \copydoc page_reg This is a helper function which, sends back the timed out \r
306 *   I frame to the PN544. This is due to the reason that ACK is not received \r
307 *   from PN544 within the guard time-out value\r
308 *\r
309 * \param[in] psLlcCtxt          Llc main structure information\r
310 * \param[in/out] psListInfo     List of I frame information\r
311 * \param[in] ns_frame_no        Frame number to send (to send the first stored  \r
312 *                               frame send DEFAULT_PACKET_INPUT)\r
313 *\r
314 * \retval NFCSTATUS_SUCCESS                Operation successful.\r
315 * \retval NFCSTATUS_INVALID_PARAMETER      At least one parameter of the function is invalid.\r
316 *\r
317 */\r
318 extern \r
319 NFCSTATUS \r
320 phLlcNfc_H_SendTimedOutIFrame (\r
321     phLlcNfc_Context_t      *psLlcCtxt, \r
322     phLlcNfc_StoreIFrame_t  *psListInfo, \r
323     uint8_t                 ns_frame_no\r
324 );\r
325 \r
326 /**\r
327 * \ingroup grp_hal_nfc_llc_helper\r
328 *\r
329 * \brief LLC state machine functions \b Change state function\r
330 *\r
331 * \copydoc page_reg changes the state if possible else returns error\r
332 *\r
333 * \param[in, out] psLlcCtxt     Llc main structure information\r
334 * \param[in] changeStateTo      Next state to change\r
335 *\r
336 * \retval NFCSTATUS_SUCCESS                Operation successful.\r
337 * \retval NFCSTATUS_INVALID_PARAMETER      At least one parameter of the function is invalid.\r
338 *\r
339 */\r
340 extern \r
341 NFCSTATUS \r
342 phLlcNfc_H_ChangeState(\r
343                        phLlcNfc_Context_t  *psLlcCtxt, \r
344                        phLlcNfc_State_t    changeStateTo\r
345                        );\r
346 \r
347 #ifdef CRC_ERROR_REJ\r
348 /**\r
349 * \ingroup grp_hal_nfc_llc_helper\r
350 *\r
351 * \brief LLC send reject command function\r
352 *\r
353 * \copydoc page_reg Sends reject command, when CRC error is recieved\r
354 *\r
355 * \param[in, out] psLlcCtxt     Llc main structure information\r
356 *\r
357 * \retval NFCSTATUS_SUCCESS                Operation successful.\r
358 * \retval NFCSTATUS_INVALID_PARAMETER      At least one parameter of the function is invalid.\r
359 *\r
360 */\r
361 extern \r
362 NFCSTATUS \r
363 phLlcNfc_H_SendRejectFrame(\r
364                       phLlcNfc_Context_t  *psLlcCtxt\r
365                       );\r
366 #endif /* #ifdef CRC_ERROR_REJ */\r
367 \r
368 /**\r
369 * \ingroup grp_hal_nfc_llc_helper\r
370 *\r
371 * \brief LLC Write wait call function\r
372 *\r
373 * \copydoc page_reg Write that has been ignored earlier will be called in this function\r
374 *\r
375 * \param[in, out] psLlcCtxt     Llc main structure information\r
376 *\r
377 * \retval NFCSTATUS_SUCCESS                 Operation successful.\r
378 * \retval NFCSTATUS_BUSY                    Write is pended, so wait till it completes.\r
379 * \retval NFCSTATUS_INVALID_PARAMETER      At least one parameter of the function is invalid.\r
380 *\r
381 */\r
382 extern \r
383 NFCSTATUS  \r
384 phLlcNfc_H_WriteWaitCall (\r
385     phLlcNfc_Context_t  *psLlcCtxt\r
386     );\r
387 \r
388 /**\r
389 * \ingroup grp_hal_nfc_llc_helper\r
390 *\r
391 * \brief LLC Send user frame function\r
392 *\r
393 * \copydoc page_reg Sends the stored user frame, that are not sent.\r
394 *\r
395 * \param[in, out]   psLlcCtxt       Llc main structure information\r
396 * \param[in]        psListInfo      Stored list of packets\r
397 *\r
398 * No return value\r
399 *\r
400 */\r
401 NFCSTATUS \r
402 phLlcNfc_H_SendUserIFrame (\r
403     phLlcNfc_Context_t      *psLlcCtxt, \r
404     phLlcNfc_StoreIFrame_t  *psListInfo\r
405     );\r
406 \r
407 /**\r
408 * \ingroup grp_hal_nfc_llc_helper\r
409 *\r
410 * \brief LLC Send rejected frame function\r
411 *\r
412 * \copydoc page_reg Sends the stored rejected frame from PN544.\r
413 *\r
414 * \param[in, out]   psLlcCtxt       Llc main structure information\r
415 * \param[in]        psListInfo      Stored list of packets\r
416 * \param[in]        ns_rejected     N(S) that was rejected\r
417 *\r
418 * No return value\r
419 *\r
420 */\r
421 NFCSTATUS \r
422 phLlcNfc_H_SendRejectedIFrame (\r
423     phLlcNfc_Context_t      *psLlcCtxt, \r
424     phLlcNfc_StoreIFrame_t  *psListInfo, \r
425     uint8_t                 ns_rejected\r
426     );\r
427 \r
428 /**\r
429 * \ingroup grp_hal_nfc_llc_helper\r
430 *\r
431 * \brief LLC component <b>Create S frame</b> function\r
432 *\r
433 * \copydoc page_reg This is a helper function which, creates the S frame\r
434 *\r
435 * \param[in/out] psFrameInfo    Generic frame information\r
436 * \param[in/out] psLlcPacket         Llc packet sent by the upper layer\r
437 * \param[in/out] cmdType        Command type of S frame\r
438 *\r
439 * \retval NFCSTATUS_SUCCESS                Operation successful.\r
440 * \retval NFCSTATUS_INVALID_PARAMETER      At least one parameter of the function is invalid.\r
441 *\r
442 */\r
443 NFCSTATUS\r
444 phLlcNfc_H_CreateSFramePayload (\r
445     phLlcNfc_Frame_t        *psFrameInfo,\r
446     phLlcNfc_LlcPacket_t    *psLlcPacket,\r
447     phLlcNfc_LlcCmd_t       cmdType\r
448 );\r
449 \r
450 /**\r
451 * \ingroup grp_hal_nfc_llc_helper\r
452 *\r
453 * \brief LLC Send upper layer information function\r
454 *\r
455 * \copydoc page_reg Sends received information to the upper layer frame.\r
456 *\r
457 * \param[in, out]   psLlcCtxt       Llc main structure information\r
458 *\r
459 * No return value\r
460 *\r
461 */\r
462 void \r
463 phLlcNfc_H_SendInfo(\r
464                     phLlcNfc_Context_t          *psLlcCtxt\r
465                     );\r
466 \r
467 \r
468 /******************** Function declarations *************************/\r
469 #endif /* #ifndef PHLLCNFC_FRAME_H */\r
470 \r
471 \r