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