2 * Copyright (C) 2010 NXP Semiconductors
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * \file phLlcNfc_DataTypes.h
19 * \brief Contains the structure information.
21 * Project: NFC-FRI-1.1
23 * $Date: Fri Apr 30 10:03:36 2010 $
26 * $Aliases: NFC_FRI1.1_WK1017_R34_1,NFC_FRI1.1_WK1017_R34_2,NFC_FRI1.1_WK1023_R35_1 $
30 #ifndef PHLLCNFC_DATATYPES_H
31 #define PHLLCNFC_DATATYPES_H
34 * \name LLC NFC frame creation, deletion and processing
36 * File: \ref phLlcNfc_DataTypes.h
40 #define PH_LLCNFC_DATATYPES_FILEREVISION "$Revision: 1.43 $" /**< \ingroup grp_hal_nfc_llc */
41 #define PH_LLCNFC_DATATYPES_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 */
43 /*************************** Includes *******************************/
44 #include <phNfcCompId.h>
45 /*********************** End of includes ****************************/
46 /***************************** Macros *******************************/
48 /* Trace buffer declaration */
49 #if defined (LLC_TRACE)
50 #include <phOsalNfc.h>
53 extern char phOsalNfc_DbgTraceBuffer[];
54 #define trace_buffer phOsalNfc_DbgTraceBuffer
56 #define MAX_TRACE_BUFFER 150
57 #define PH_LLCNFC_PRINT( str ) phOsalNfc_DbgString(str)
58 #define PH_LLCNFC_PRINT_DATA(buf,len)
59 #define PH_LLCNFC_STRING( str )
60 #define PH_LLCNFC_DEBUG(str, arg) \
62 snprintf(trace_buffer,MAX_TRACE_BUFFER,str,arg); \
63 phOsalNfc_DbgString(trace_buffer); \
65 #define PH_LLCNFC_PRINT_BUFFER(buf,len) \
68 char trace_buffer[MAX_TRACE_BUFFER]; \
69 snprintf(trace_buffer,MAX_TRACE_BUFFER,"\n\t %s:",msg); \
70 phOsalNfc_DbgString(trace); */\
71 phOsalNfc_DbgTrace(buf,len); \
72 phOsalNfc_DbgString("\r"); \
74 #endif /* #if defined (LLC_TRACE) */
77 #if (!defined (LLC_TRACE) && defined (LLC_DATA_BYTES))
78 #include <phOsalNfc.h>
80 extern char phOsalNfc_DbgTraceBuffer[];
81 #define trace_buffer phOsalNfc_DbgTraceBuffer
83 #define PH_LLCNFC_PRINT( str )
84 #define PH_LLCNFC_PRINT_BUFFER(buf, len)
85 #define PH_LLCNFC_DEBUG(str, arg1)
86 #define PH_LLCNFC_STRING( str ) phOsalNfc_DbgString(str)
87 #define PH_LLCNFC_PRINT_DATA(buf,len) \
90 char trace_buffer[MAX_TRACE_BUFFER]; \
91 snprintf(trace_buffer,MAX_TRACE_BUFFER,"\n\t %s:",msg); \
92 phOsalNfc_DbgString(trace_buffer); */\
93 phOsalNfc_DbgTrace(buf,len); \
95 #endif /* #if (!defined (LLC_TRACE) && defined (LLC_DATA_BYTES)) */
98 #if (!defined (LLC_TRACE) && !defined (LLC_DATA_BYTES))
99 /** To disable prints */
100 #define PH_LLCNFC_PRINT(str)
101 #define PH_LLCNFC_PRINT_BUFFER(buf, len)
102 #define PH_LLCNFC_DEBUG(str, arg1)
103 #define PH_LLCNFC_PRINT_DATA(buf,len)
104 #define PH_LLCNFC_STRING( str )
105 #endif /* #if (!defined (LLC_TRACE) && !defined (LLC_DATA_BYTES)) */
108 /* If the below MACRO (RECV_NR_CHECK_ENABLE) is
109 DEFINED : then check for the NR frame received from PN544 in the I frame is
110 added. This shall be greater than sent NS from the HOST.
111 This is used to stop the timer
112 COMMENTED : dont check the N(R) frame received from the PN544
114 /* #define RECV_NR_CHECK_ENABLE */
116 /* If the below MACRO (LLC_UPP_LAYER_NTFY_WRITE_RSP_CB) is
117 DEFINED : then if an I frame is received and the
118 upper layer response callback (before another READ is pended) is called
119 only after sending S frame and wait for the callback and then notify the
121 COMMENTED : then if an I frame is received and the
122 upper layer response callback (before another READ is pended) is called
123 immediately after sending S frame (not waiting for the sent S frame
126 /* #define LLC_UPP_LAYER_NTFY_WRITE_RSP_CB */
128 /* PN544 continuously sends an incorrect I frames to the HOST,
129 even after the REJ frame from HOST to PN544
130 If the below MACRO (LLC_RR_INSTEAD_OF_REJ) is
131 DEFINED : then if the received NS = (expected NR - 1) then instead of REJ
133 COMMENTED : then REJ frame is sent
135 // #define LLC_RR_INSTEAD_OF_REJ
139 /* If the below MACRO (CTRL_WIN_SIZE_COUNT) is
140 DEFINED : then window size will be maximum
141 COMMENTED : then window size is 1
143 #define CTRL_WIN_SIZE_COUNT
146 If the below MACRO (LLC_URSET_NO_DELAY) is
147 DEFINED : then after receiving the UA frame, then immediately this will be
148 notified or further operation will be carried on.
149 COMMENTED : then after receiving the UA frame, then a timer is started, to
150 delay the notifiation or to carry on the next operation
152 #define LLC_URSET_NO_DELAY
155 If the below MACRO (LLC_RELEASE_FLAG) is
156 DEFINED : then whenever LLC release is called the g_release_flag variable
157 will be made TRUE. Also, NO notification is allowed to the
159 COMMENTED : g_release_flag is not declared and not used
161 #define LLC_RELEASE_FLAG
165 Actually, there is a send and receive error count, if either of them reaches
166 limit, then exception is raised.
167 If the below MACRO (LLC_RSET_INSTEAD_OF_EXCEPTION) is
168 DEFINED : then exception is not raised, instead a U RSET command is sent.
169 COMMENTED : then exception is raised
171 /* #define LLC_RSET_INSTEAD_OF_EXCEPTION */
173 #ifndef LLC_UPP_LAYER_NTFY_WRITE_RSP_CB
175 If the below MACRO (PIGGY_BACK) is
176 DEFINED : After receiving I frame, wait till the ACK timer to expire to send an ACK to PN544.
177 COMMENTED : immediately ACK the received I frame
181 #endif /* LLC_UPP_LAYER_NTFY_WRITE_RSP_CB */
183 #define LLC_SEND_ERROR_COUNT
185 #define RECV_ERROR_FRAME_COUNT (0x50U)
186 #define SENT_ERROR_FRAME_COUNT (0x50U)
188 /** Initial bytes to read */
189 #define PH_LLCNFC_BYTES_INIT_READ (1)
190 /** Maximum buffer that I frame can send */
191 #define PH_LLCNFC_MAX_IFRAME_BUFLEN (29)
192 #define PH_LLCNFC_MAX_UFRAME_BUFLEN (4)
193 #define PH_LLCNFC_CRC_LENGTH (2)
194 #define PH_LLCNFC_MAX_LLC_PAYLOAD ((PH_LLCNFC_MAX_IFRAME_BUFLEN) + (4))
195 /** Maximum timer used in the Llc */
196 #define PH_LLCNFC_MAX_TIMER_USED (3)
197 /** Maximum timer used in the Llc */
198 #define PH_LLCNFC_MAX_ACK_GUARD_TIMER (4)
199 /** Maximum I frame that can be stored */
200 #define PH_LLCNFC_MAX_I_FRAME_STORE (8)
202 /** Read pending for one byte */
203 #define PH_LLCNFC_READPEND_ONE_BYTE (0x01U)
204 /** Read pending for remaining byte */
205 #define PH_LLCNFC_READPEND_REMAIN_BYTE (0x02U)
206 /** Read pending not done */
207 #define PH_LLCNFC_READPEND_FLAG_OFF FALSE
208 #define PH_LLCNFC_MAX_REJ_RETRY_COUNT (200)
211 /**** Macros for state machine ****/
213 typedef enum phLlcNfc_State
215 /** This specifies that LLC is in uninitialise state */
216 phLlcNfc_Uninitialise_State = 0x00,
217 /** This specifies that LLC initialise is in progress */
218 phLlcNfc_Initialising_State = 0x01,
219 /** This specifies that LLC is in initialise is complete */
220 phLlcNfc_Initialised_State = 0x02,
221 /** This specifies that LLC is send with the
223 phLlcNfc_Sending_State = 0x03,
224 /** This specifies that LLC is receive with the
226 phLlcNfc_Receiving_State = 0x04,
227 /** This specifies that LLC is receive wait with the
229 phLlcNfc_ReceiveWait_State = 0x05,
230 /** This specifies that LLC is resending the I frames */
231 phLlcNfc_Resend_State = 0x06
233 /**** Macros for state machine end ****/
235 /************************ End of macros *****************************/
237 /********************** Callback functions **************************/
239 /******************* End of Callback functions **********************/
241 /********************* Structures and enums *************************/
243 * \ingroup grp_hal_nfc_llc
244 * \brief Enum to get the baud rate
246 * This enum contains the baud rate information.
250 typedef enum phLlcNfc_LlcBaudRate
252 /** Baud rate = 9600 */
253 phLlcNfc_e_9600 = 0x00,
254 /** Baud rate = 19200 */
255 phLlcNfc_e_19200 = 0x01,
256 /** Baud rate = 28800 */
257 phLlcNfc_e_28800 = 0x02,
258 /** Baud rate = 38400 */
259 phLlcNfc_e_38400 = 0x03,
260 /** Baud rate = 57600 */
261 phLlcNfc_e_57600 = 0x04,
262 /** Baud rate = 115200 */
263 phLlcNfc_e_115200 = 0x05,
264 /** Baud rate = 23400 */
265 phLlcNfc_e_234000 = 0x06,
266 /** Baud rate = 46800 */
267 phLlcNfc_e_460800 = 0x07,
268 /** Baud rate = 921600 */
269 phLlcNfc_e_921600 = 0x08,
270 /** Baud rate = 1228000 */
271 phLlcNfc_e_1228000 = 0x09,
272 /** Baud rate error */
273 phLlcNfc_e_bdrate_err = 0xFF
274 }phLlcNfc_LlcBaudRate_t;
278 * \ingroup grp_hal_nfc_llc
279 * \brief Enum to select the U or I or S frame
281 * This enum is to set the frames.
285 typedef enum phLlcNfc_LlcCmd
287 /** This command is for I frame (no command) */
288 phLlcNfc_e_no_cmd = 0xFF,
289 /** This command is for U frame */
290 phLlcNfc_e_rset = 0x19,
291 /** This command is for U frame */
292 phLlcNfc_e_ua = 0x06,
293 /** This is RR command for S frame */
294 phLlcNfc_e_rr = 0x00,
295 /** This is REJ command for S frame */
296 phLlcNfc_e_rej = 0x08,
297 /** This is RNR command for S frame */
298 phLlcNfc_e_rnr = 0x10,
299 /** This is SREJ command for S frame */
300 phLlcNfc_e_srej = 0x18,
302 phLlcNfc_e_error = 0xFE
307 * \ingroup grp_hal_nfc_llc
308 * \brief Enum to select the U or I or S frame
310 * This enum is to set the frames.
314 typedef enum phLlcNfc_FrameType
317 phLlcNfc_eU_frame = 0x00,
319 phLlcNfc_eI_frame = 0x01,
321 phLlcNfc_eS_frame = 0x02,
322 /** Error frame type */
323 phLlcNfc_eErr_frame = 0x03
324 }phLlcNfc_FrameType_t;
328 * \ingroup grp_hal_nfc_llc
329 * \brief LLC sent frame type
331 * This enum values defines what are the frames sent to the PN544
336 typedef enum phLlcNfc_eSentFrameType
339 /* During initialisation the U RSET is sent to PN544 */
341 /* During initialisation the UA is sent to PN544 */
343 /* After unsuccessful retries of sending I frame to PN544,
346 /* If PN544 sends the URSET frame in between any transaction, then
347 the UA response shall be sent */
349 /* S frame is sent to PN544, this will be sent only if an I frame
350 is received from PN544 */
352 /* User has sent an I frame, for that a write response callback
355 /* LLC, internally (means stored non acknowledged frames) has sent
356 an I frame as it doesnt get a proper acknowledgement */
358 /* LLC, internally (means stored non acknowledged frames) has sent
359 an I frame as it doesnt get a reject as acknowledgement */
361 /* LLC has received a I frame for the re-sent I frames, so an S
364 /* LLC has received a I frame for the re-sent I frames, so an S
367 /* PN544 has sent an I frame, which is wrong, so send a reject S
370 #ifdef LLC_RR_INSTEAD_OF_REJ
372 /* RR is sent instead of REJECT */
375 #endif /* #ifdef LLC_RR_INSTEAD_OF_REJ */
376 /* For any of the above sent frames, the response shall be received */
378 }phLlcNfc_eSentFrameType_t;
383 * \ingroup grp_hal_nfc_llc
386 * This structure contains both the header information and
387 * the exact length of the buffer.
391 typedef struct phLlcNfc_Payload
393 /** Llc header information */
396 /** User or received buffer */
397 uint8_t llcpayload[PH_LLCNFC_MAX_LLC_PAYLOAD];
402 * \ingroup grp_hal_nfc_llc
405 * This structure contains the information of the LLC length byte
410 typedef struct phLlcNfc_Buffer
413 uint8_t llc_length_byte;
415 /** LLC data including the LLC header and CRC */
416 phLlcNfc_Payload_t sllcpayload;
421 * \ingroup grp_hal_nfc_llc
422 * \brief Packet information
424 * This structure contains the length and buffer of the packet.
428 typedef struct phLlcNfc_LlcPacket
430 /** Complete LLC buffer */
431 phLlcNfc_Buffer_t s_llcbuf;
433 /** LLC buffer length */
436 /** Stored frame needs completion callback, to be sent to HCI */
437 phLlcNfc_eSentFrameType_t frame_to_send;
439 }phLlcNfc_LlcPacket_t;
443 * \ingroup grp_hal_nfc_llc_helper
444 * \brief I frame details
446 * This structure stores the information of the I frame
447 * (to support sliding window).
451 typedef struct phLlcNfc_StoreIFrame
453 /** Complete LLC packet */
454 phLlcNfc_LlcPacket_t s_llcpacket[PH_LLCNFC_MAX_I_FRAME_STORE];
456 /** Window size count */
459 /** Start position */
462 }phLlcNfc_StoreIFrame_t;
466 * \ingroup grp_hal_nfc_llc
467 * \brief LLC timer information
469 * This structure contains the timer related information
473 typedef struct phLlcNfc_Timerinfo
475 /** Store the timer id for each timer create */
476 uint32_t timer_id[PH_LLCNFC_MAX_TIMER_USED];
478 /** This will store the connection time out value */
479 uint16_t con_to_value;
481 /** This will store the guard time out values */
482 uint16_t guard_to_value[PH_LLCNFC_MAX_ACK_GUARD_TIMER];
484 /** This will store the guard time out values */
485 uint16_t iframe_send_count[PH_LLCNFC_MAX_ACK_GUARD_TIMER];
487 /** This will store ns value for the sent N(S) */
488 uint8_t timer_ns_value[PH_LLCNFC_MAX_ACK_GUARD_TIMER];
490 /** Each frame stored needs to be */
491 uint8_t frame_type[PH_LLCNFC_MAX_ACK_GUARD_TIMER];
493 /** Index to re-send */
494 uint8_t index_to_send;
496 /** This is a count for gaurd time out */
497 uint8_t guard_to_count;
500 /** This will store the ack time out values */
501 uint16_t ack_to_value;
502 #endif /* #ifdef PIGGY_BACK */
504 /** This is a timer flag
505 Bit 0 = 1 means connection time out started else stopped
506 Bit 1 = 1 means guard time out started else stopped
507 Bit 2 = 1 means ack time out started else stopped
510 }phLlcNfc_Timerinfo_t;
514 * \ingroup grp_hal_nfc_llc
515 * \brief LLC frame information
517 * This structure contains the information of the LLC frame.
521 typedef struct phLlcNfc_Frame
523 /** N(S) - Number of information frame */
526 /** N(R) - Number of next information frame to receive */
529 /** Store the window size */
532 /** SREJ is optional, so store the flag whether it is set or not */
535 /** Store the baud rate */
538 /** Flag to find the rset_recvd */
541 /** Complete LLC packet information */
542 phLlcNfc_LlcPacket_t s_llcpacket;
544 /** Store the I frames, that has been sent, Storage will be till
546 phLlcNfc_StoreIFrame_t s_send_store;
549 /** Store the I frames, that has been received, Storage will be
550 till the window size */
551 phLlcNfc_StoreIFrame_t s_recv_store;
553 /** Response received count to send the ACK once it reaches the window size */
554 uint8_t resp_recvd_count;
555 #endif /* #ifdef PIGGY_BACK */
557 /** To receive the packet sent by below layer */
558 phLlcNfc_LlcPacket_t s_recvpacket;
560 /** Number of window I frames has to be sent again */
563 /** To store the count received error frames like
564 wrong CRC, REJ and RNR frames */
565 uint8_t recv_error_count;
567 /** Sending error frames like REJ frames to the PN544 */
568 uint8_t send_error_count;
570 /** Send U frame count */
573 /** Read pending flag, to know that read is already pended
574 or not. Use the below macros to ON and OFF the flag
575 PH_LLCNFC_READPEND_FLAG_OFF
576 PH_LLCNFC_READPEND_ONE_BYTE
577 PH_LLCNFC_READPEND_REMAIN_BYTE
579 uint8_t read_pending;
582 uint8_t write_pending;
584 /** Sent frame type */
585 phLlcNfc_eSentFrameType_t sent_frame_type;
587 /** upper receive called */
588 uint8_t upper_recv_call;
590 /** Status returned during DAL write */
591 NFCSTATUS write_status;
593 /** Depending on the "write_status", write call has to be called */
594 phLlcNfc_eSentFrameType_t write_wait_call;
599 * \ingroup grp_hal_nfc_llc
600 * \brief LLC Component Context Structure
602 * This structure is used to store the current context information
607 typedef struct phLlcNfc_Context
609 /** Information regarding all the LLC frame */
610 phLlcNfc_Frame_t s_frameinfo;
612 /** Local send and receive */
613 phNfc_sLowerIF_t lower_if;
615 /** Register attention, send and receive callback from the
616 register functions of the upper layer */
617 phNfcIF_sCallBack_t cb_for_if;
619 /** Store the length, which shall be sent later through the
620 "send complete" callback */
621 uint32_t send_cb_len;
623 /** Receive buffer provided by the upper layer */
624 uint8_t precv_buf[PH_LLCNFC_MAX_LLC_PAYLOAD];
626 /** Receive length provided by the upper layer */
627 uint32_t recvbuf_length;
630 phLlcNfc_State_t state;
632 /** Hardware information */
635 /** Timer information */
636 phLlcNfc_Timerinfo_t s_timerinfo;
639 /****************** End of structures and enums *********************/
641 /******************** Function declarations *************************/
643 /******************** Function declarations *************************/
644 #endif /* PHLLCNFC_DATATYPES_H */