2 * Copyright (C) 2010 NXP Semiconductors
\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
8 * http://www.apache.org/licenses/LICENSE-2.0
\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
18 * \file phLlcNfc_Frame.h
\r
19 * \brief To append and delete the I or S or U frames.
\r
21 * Project: NFC-FRI-1.1
\r
23 * $Date: Fri Apr 30 10:03:36 2010 $
\r
24 * $Author: ing02260 $
\r
26 * $Aliases: NFC_FRI1.1_WK1017_R34_1,NFC_FRI1.1_WK1017_R34_2,NFC_FRI1.1_WK1023_R35_1 $
\r
30 #ifndef PHLLCNFC_FRAME_H
\r
31 #define PHLLCNFC_FRAME_H
\r
34 * \name LLC NFC frame creation and deletion
\r
36 * File: \ref phLlcNfc_Frame.h
\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
44 /*************************** Includes *******************************/
\r
46 /*********************** End of includes ****************************/
\r
48 /** \defgroup grp_hal_nfc_llc_helper LLC helper functions
\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
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
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
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
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
123 /************************ End of macros *****************************/
\r
125 /********************** Callback functions **************************/
\r
127 /******************* End of Callback functions **********************/
\r
129 /********************* Structures and enums *************************/
\r
131 /****************** End of structures and enums *********************/
\r
133 /******************** Function declarations *************************/
\r
135 * \ingroup grp_hal_nfc_llc_helper
\r
137 * \brief LLC helper functions \b Frame Init function
\r
139 * \copydoc page_reg Gets the LLC main context and stores it.
\r
141 * \param[in] psLlcCtxt Llc main structure information
\r
143 * \retval NFCSTATUS_SUCCESS Operation successful.
\r
144 * \retval NFCSTATUS_INVALID_PARAMETER At least one parameter of the function is invalid.
\r
147 void phLlcNfc_H_Frame_Init (
\r
148 phLlcNfc_Context_t *psLlcCtxt
\r
152 * \ingroup grp_hal_nfc_llc_helper
\r
154 * \brief LLC helper functions \b DeInit function
\r
156 * \copydoc page_reg
\r
158 * \param[in] psFrameInfo Frame structure information
\r
160 * \retval NFCSTATUS_SUCCESS Operation successful.
\r
161 * \retval NFCSTATUS_INVALID_PARAMETER At least one parameter of the function is invalid.
\r
165 phLlcNfc_H_Frame_DeInit (
\r
166 phLlcNfc_Frame_t *psFrameInfo
\r
170 * \ingroup grp_hal_nfc_llc_helper
\r
172 * \brief LLC helper functions \b List append function
\r
174 * \copydoc page_reg Append the new I frame information at the beginning of the list
\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
179 * \retval NFCSTATUS_SUCCESS Operation successful.
\r
180 * \retval NFCSTATUS_INVALID_PARAMETER At least one parameter of the function is invalid.
\r
184 phLlcNfc_H_StoreIFrame (
\r
185 phLlcNfc_StoreIFrame_t *psList,
\r
186 phLlcNfc_LlcPacket_t sPacketInfo
\r
192 * \ingroup grp_hal_nfc_llc_helper
\r
194 * \brief LLC helper functions <b>Create S frame</b> function
\r
196 * \copydoc page_reg This function creates a S frame
\r
198 * \param[in/out] pllcSFrmBuf Required buffer to create the S frame
\r
200 * \retval NFCSTATUS_SUCCESS Operation successful.
\r
201 * \retval NFCSTATUS_INVALID_PARAMETER At least one parameter of the function is invalid.
\r
205 phLlcNfc_H_Create_S_Frame(
\r
206 uint8_t *pllcSFrmBuf
\r
210 * \ingroup grp_hal_nfc_llc_helper
\r
212 * \brief LLC helper functions <b>Compute CRC</b> function
\r
214 * \copydoc page_reg This function is used to compute CRC for the llc data
\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
222 * \retval NFCSTATUS_SUCCESS Operation successful.
\r
223 * \retval NFCSTATUS_INVALID_PARAMETER At least one parameter of the function is invalid.
\r
227 phLlcNfc_H_ComputeCrc(
\r
235 * \ingroup grp_hal_nfc_llc_helper
\r
237 * \brief LLC helper functions <b>Create U frame payload </b> function
\r
239 * \copydoc page_reg This function is used to create a LLC packet with U frame
\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
246 * \retval NFCSTATUS_SUCCESS Operation successful.
\r
247 * \retval NFCSTATUS_INVALID_PARAMETER At least one parameter of the function is invalid.
\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
259 * \ingroup grp_hal_nfc_llc_helper
\r
261 * \brief LLC helper functions <b>Create I frame payload </b> function
\r
263 * \copydoc page_reg This function is used to create a LLC packet with I frame
\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
271 * \retval NFCSTATUS_SUCCESS Operation successful.
\r
272 * \retval NFCSTATUS_INVALID_PARAMETER At least one parameter of the function is invalid.
\r
276 phLlcNfc_H_CreateIFramePayload (
\r
277 phLlcNfc_Frame_t *psFrameInfo,
\r
278 phLlcNfc_LlcPacket_t *psLlcPacket,
\r
280 uint8_t llcBufLength
\r
284 * \ingroup grp_hal_nfc_llc_helper
\r
286 * \brief LLC helper functions <b>Process received frame </b> function
\r
288 * \copydoc page_reg This function process the received data
\r
290 * \param[in] pLlcCtxt Llc main context
\r
292 * \retval NFCSTATUS_SUCCESS Operation successful.
\r
293 * \retval NFCSTATUS_INVALID_FORMAT If any error in the frame
\r
296 phLlcNfc_H_ProRecvFrame (
\r
297 phLlcNfc_Context_t *psLlcCtxt
\r
301 * \ingroup grp_hal_nfc_llc_helper
\r
303 * \brief LLC component <b>resend the I frame</b> function
\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
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
314 * \retval NFCSTATUS_SUCCESS Operation successful.
\r
315 * \retval NFCSTATUS_INVALID_PARAMETER At least one parameter of the function is invalid.
\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
327 * \ingroup grp_hal_nfc_llc_helper
\r
329 * \brief LLC state machine functions \b Change state function
\r
331 * \copydoc page_reg changes the state if possible else returns error
\r
333 * \param[in, out] psLlcCtxt Llc main structure information
\r
334 * \param[in] changeStateTo Next state to change
\r
336 * \retval NFCSTATUS_SUCCESS Operation successful.
\r
337 * \retval NFCSTATUS_INVALID_PARAMETER At least one parameter of the function is invalid.
\r
342 phLlcNfc_H_ChangeState(
\r
343 phLlcNfc_Context_t *psLlcCtxt,
\r
344 phLlcNfc_State_t changeStateTo
\r
347 #ifdef CRC_ERROR_REJ
\r
349 * \ingroup grp_hal_nfc_llc_helper
\r
351 * \brief LLC send reject command function
\r
353 * \copydoc page_reg Sends reject command, when CRC error is recieved
\r
355 * \param[in, out] psLlcCtxt Llc main structure information
\r
357 * \retval NFCSTATUS_SUCCESS Operation successful.
\r
358 * \retval NFCSTATUS_INVALID_PARAMETER At least one parameter of the function is invalid.
\r
363 phLlcNfc_H_SendRejectFrame(
\r
364 phLlcNfc_Context_t *psLlcCtxt
\r
366 #endif /* #ifdef CRC_ERROR_REJ */
\r
369 * \ingroup grp_hal_nfc_llc_helper
\r
371 * \brief LLC Write wait call function
\r
373 * \copydoc page_reg Write that has been ignored earlier will be called in this function
\r
375 * \param[in, out] psLlcCtxt Llc main structure information
\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
384 phLlcNfc_H_WriteWaitCall (
\r
385 phLlcNfc_Context_t *psLlcCtxt
\r
389 * \ingroup grp_hal_nfc_llc_helper
\r
391 * \brief LLC Send user frame function
\r
393 * \copydoc page_reg Sends the stored user frame, that are not sent.
\r
395 * \param[in, out] psLlcCtxt Llc main structure information
\r
396 * \param[in] psListInfo Stored list of packets
\r
402 phLlcNfc_H_SendUserIFrame (
\r
403 phLlcNfc_Context_t *psLlcCtxt,
\r
404 phLlcNfc_StoreIFrame_t *psListInfo
\r
408 * \ingroup grp_hal_nfc_llc_helper
\r
410 * \brief LLC Send rejected frame function
\r
412 * \copydoc page_reg Sends the stored rejected frame from PN544.
\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
422 phLlcNfc_H_SendRejectedIFrame (
\r
423 phLlcNfc_Context_t *psLlcCtxt,
\r
424 phLlcNfc_StoreIFrame_t *psListInfo,
\r
425 uint8_t ns_rejected
\r
429 * \ingroup grp_hal_nfc_llc_helper
\r
431 * \brief LLC component <b>Create S frame</b> function
\r
433 * \copydoc page_reg This is a helper function which, creates the S frame
\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
439 * \retval NFCSTATUS_SUCCESS Operation successful.
\r
440 * \retval NFCSTATUS_INVALID_PARAMETER At least one parameter of the function is invalid.
\r
444 phLlcNfc_H_CreateSFramePayload (
\r
445 phLlcNfc_Frame_t *psFrameInfo,
\r
446 phLlcNfc_LlcPacket_t *psLlcPacket,
\r
447 phLlcNfc_LlcCmd_t cmdType
\r
451 * \ingroup grp_hal_nfc_llc_helper
\r
453 * \brief LLC Send upper layer information function
\r
455 * \copydoc page_reg Sends received information to the upper layer frame.
\r
457 * \param[in, out] psLlcCtxt Llc main structure information
\r
463 phLlcNfc_H_SendInfo(
\r
464 phLlcNfc_Context_t *psLlcCtxt
\r
468 /******************** Function declarations *************************/
\r
469 #endif /* #ifndef PHLLCNFC_FRAME_H */
\r