diff options
author | Daniel Tomas <dtomas.nxp@gmail.com> | 2011-05-26 15:52:17 +0200 |
---|---|---|
committer | Nick Pelly <npelly@google.com> | 2011-06-28 14:30:24 -0700 |
commit | b313c3d09c64c31439332e88e0aca676ae1858b5 (patch) | |
tree | 0529b38fd67f61dfae286e968a9e81fa57f4da1d | |
parent | 8d4d6a13c4c3bf4e966d12297cc9a9f6cf9d42a8 (diff) | |
download | external_libnfc-nxp-b313c3d09c64c31439332e88e0aca676ae1858b5.zip external_libnfc-nxp-b313c3d09c64c31439332e88e0aca676ae1858b5.tar.gz external_libnfc-nxp-b313c3d09c64c31439332e88e0aca676ae1858b5.tar.bz2 |
Patch to add the windowing support in the libnfc
This patch enables windowing of LLC packets send from chipset to host.
The host will now wait for up to 4 LLC packets from the chipset before
sending an ACK (S-Frame RR).
Change-Id: I6a70e1d780847a104e3ec8e403593a69e222aec9
-rw-r--r-- | inc/phNfcConfig.h | 6 | ||||
-rw-r--r-- | src/phLlcNfc.c | 24 | ||||
-rw-r--r-- | src/phLlcNfc_DataTypes.h | 81 | ||||
-rw-r--r-- | src/phLlcNfc_Frame.c | 200 | ||||
-rw-r--r-- | src/phLlcNfc_Frame.h | 23 | ||||
-rw-r--r-- | src/phLlcNfc_Interface.c | 25 | ||||
-rw-r--r-- | src/phLlcNfc_Timer.c | 165 | ||||
-rw-r--r-- | src/phLlcNfc_Timer.h | 12 |
8 files changed, 340 insertions, 196 deletions
diff --git a/inc/phNfcConfig.h b/inc/phNfcConfig.h index c234724..e7386d9 100644 --- a/inc/phNfcConfig.h +++ b/inc/phNfcConfig.h @@ -223,6 +223,12 @@ #define LINK_CONNECTION_TIMEOUT 1000U #endif +/**< Defines ACK time out value for LLC timer, + 150 is in milliseconds */ +#ifndef LINK_ACK_TIMEOUT +#define LINK_ACK_TIMEOUT 1U +#endif + /**< Defines Firmware Download Completion Timeout value , 120000 is in milliseconds */ diff --git a/src/phLlcNfc.c b/src/phLlcNfc.c index af0a3a1..36b442b 100644 --- a/src/phLlcNfc.c +++ b/src/phLlcNfc.c @@ -228,7 +228,7 @@ phLlcNfc_Init ( { NFCSTATUS result = NFCSTATUS_SUCCESS; phLlcNfc_Context_t *ps_llc_ctxt = (phLlcNfc_Context_t*)pContext; - phLlcNfc_LlcPacket_t *ps_packet_info = NULL; + phLlcNfc_LlcPacket_t s_packet_info; PH_LLCNFC_PRINT("Llc Init called\n"); if ((NULL == ps_llc_ctxt) || (NULL == pLinkInfo)) @@ -239,8 +239,6 @@ phLlcNfc_Init ( else { /* Initialisation */ - ps_packet_info = &(ps_llc_ctxt->s_frameinfo.s_llcpacket); - ps_llc_ctxt->phwinfo = pLinkInfo; /* Call the internal frame initialise */ phLlcNfc_H_Frame_Init(ps_llc_ctxt); @@ -258,17 +256,17 @@ phLlcNfc_Init ( phLlcNfc_CreateTimers(); /* Create a U frame */ - result = phLlcNfc_H_CreateUFramePayload(ps_llc_ctxt, - ps_packet_info, - &(ps_packet_info->llcbuf_len), + result = phLlcNfc_H_CreateUFramePayload(ps_llc_ctxt, + &s_packet_info, + &(s_packet_info.llcbuf_len), phLlcNfc_e_rset); } if (NFCSTATUS_SUCCESS == result) { /* Call DAL write */ result = phLlcNfc_Interface_Write(ps_llc_ctxt, - (uint8_t*)&(ps_packet_info->s_llcbuf), - (uint32_t)ps_packet_info->llcbuf_len); + (uint8_t*)&(s_packet_info.s_llcbuf), + (uint32_t)s_packet_info.llcbuf_len); } if (NFCSTATUS_PENDING == result) { @@ -364,8 +362,7 @@ phLlcNfc_Send ( NFCSTATUS result = NFCSTATUS_SUCCESS; phLlcNfc_Context_t *ps_llc_ctxt = (phLlcNfc_Context_t*)pContext; phLlcNfc_Frame_t *ps_frame_info = NULL; - phLlcNfc_LlcPacket_t *ps_packet_info = NULL, - s_packet_info; + phLlcNfc_LlcPacket_t s_packet_info; phLlcNfc_StoreIFrame_t *ps_store_frame = NULL; #if 0 uint8_t count = 1; @@ -404,7 +401,6 @@ phLlcNfc_Send ( &s_packet_info, pLlcBuf, (uint8_t)llcBufLength); - ps_packet_info = &(ps_frame_info->s_llcpacket); /* Store the I frame in the send list */ (void)phLlcNfc_H_StoreIFrame (ps_store_frame, s_packet_info); @@ -423,13 +419,11 @@ phLlcNfc_Send ( #endif /* #ifdef CTRL_WIN_SIZE_COUNT */ { - (void)memcpy ((void *)ps_packet_info, (void *)&s_packet_info, - sizeof(phLlcNfc_LlcPacket_t)); /* Call write to the below layer, only if previous write is completed */ result = phLlcNfc_Interface_Write (ps_llc_ctxt, - (uint8_t *)&(ps_packet_info->s_llcbuf), - (uint32_t)ps_packet_info->llcbuf_len); + (uint8_t *)&(s_packet_info.s_llcbuf), + (uint32_t)s_packet_info.llcbuf_len); if ((NFCSTATUS_PENDING == result) || (NFCSTATUS_BUSY == PHNFCSTATUS (result))) diff --git a/src/phLlcNfc_DataTypes.h b/src/phLlcNfc_DataTypes.h index 2257513..9d5b588 100644 --- a/src/phLlcNfc_DataTypes.h +++ b/src/phLlcNfc_DataTypes.h @@ -105,79 +105,81 @@ #endif /* #if (!defined (LLC_TRACE) && !defined (LLC_DATA_BYTES)) */ -/* If the below MACRO (RECV_NR_CHECK_ENABLE) is -ENABLED : then check for the NR frame received from PN544 in the I frame is - added. This shall be greater than sent NS from the HOST. - This is used to stop the timer -DISABLED : dont check the N9R) frame received from the PN544 +/* If the below MACRO (RECV_NR_CHECK_ENABLE) is +DEFINED : then check for the NR frame received from PN544 in the I frame is + added. This shall be greater than sent NS from the HOST. + This is used to stop the timer +COMMENTED : dont check the N(R) frame received from the PN544 */ /* #define RECV_NR_CHECK_ENABLE */ -/* If the below MACRO (LLC_UPP_LAYER_NTFY_WRITE_RSP_CB) is -ENABLED : then if an I frame is received and the - upper layer response callback (before another READ is pended) is called - only after sending S frame and wait for the callback and then notify the +/* If the below MACRO (LLC_UPP_LAYER_NTFY_WRITE_RSP_CB) is +DEFINED : then if an I frame is received and the + upper layer response callback (before another READ is pended) is called + only after sending S frame and wait for the callback and then notify the upper layer -DISABLED : then if an I frame is received and the - upper layer response callback (before another READ is pended) is called - immediately after sending S frame (not waiting for the sent S frame +COMMENTED : then if an I frame is received and the + upper layer response callback (before another READ is pended) is called + immediately after sending S frame (not waiting for the sent S frame callback) */ -#define LLC_UPP_LAYER_NTFY_WRITE_RSP_CB +/* #define LLC_UPP_LAYER_NTFY_WRITE_RSP_CB */ -/* PN544 continuously sends an incorrect I frames to the HOST, +/* PN544 continuously sends an incorrect I frames to the HOST, even after the REJ frame from HOST to PN544 -If the below MACRO (LLC_RR_INSTEAD_OF_REJ) is -ENABLED : then if the received NS = (expected NR - 1) then instead of REJ +If the below MACRO (LLC_RR_INSTEAD_OF_REJ) is +DEFINED : then if the received NS = (expected NR - 1) then instead of REJ RR frame is sent -DISABLED : then REJ frame is sent +COMMENTED : then REJ frame is sent */ #define LLC_RR_INSTEAD_OF_REJ #define SEND_UFRAME -/* If the below MACRO (CTRL_WIN_SIZE_COUNT) is -ENABLED : then window size will be maximum -DISABLED : then window size is 1 +/* If the below MACRO (CTRL_WIN_SIZE_COUNT) is +DEFINED : then window size will be maximum +COMMENTED : then window size is 1 */ #define CTRL_WIN_SIZE_COUNT /* If the below MACRO (LLC_URSET_NO_DELAY) is -ENABLED : then after receiving the UA frame, then immediately this will be +DEFINED : then after receiving the UA frame, then immediately this will be notified or further operation will be carried on. -DISABLED : then after receiving the UA frame, then a timer is started, to +COMMENTED : then after receiving the UA frame, then a timer is started, to delay the notifiation or to carry on the next operation */ #define LLC_URSET_NO_DELAY -#ifdef LLC_UPP_LAYER_NTFY_WRITE_RSP_CB - - /* NO definition is required */ - -#else - /* - This macro is useful only if the LLC_UPP_LAYER_NTFY_WRITE_RSP_CB is DISABLED If the below MACRO (LLC_RELEASE_FLAG) is - ENABLED : then whenever LLC release is called the g_release_flag variable - will be made TRUE. Also, NO notification is allowed to the +DEFINED : then whenever LLC release is called the g_release_flag variable + will be made TRUE. Also, NO notification is allowed to the upper layer. - DISABLED : g_release_flag is not declared and not used +COMMENTED : g_release_flag is not declared and not used */ #define LLC_RELEASE_FLAG -#endif /* #ifdef LLC_UPP_LAYER_NTFY_WRITE_RSP_CB */ /* - Actually, there is a send and receive error count, if either of them reaches + Actually, there is a send and receive error count, if either of them reaches limit, then exception is raised. If the below MACRO (LLC_RSET_INSTEAD_OF_EXCEPTION) is - ENABLED : then exception is not raised, instead a U RSET command is sent. - DISABLED : then exception is raised +DEFINED : then exception is not raised, instead a U RSET command is sent. +COMMENTED : then exception is raised */ /* #define LLC_RSET_INSTEAD_OF_EXCEPTION */ +#ifndef LLC_UPP_LAYER_NTFY_WRITE_RSP_CB + /* + If the below MACRO (PIGGY_BACK) is + DEFINED : After receiving I frame, wait till the ACK timer to expire to send an ACK to PN544. + COMMENTED : immediately ACK the received I frame + */ + #define PIGGY_BACK + +#endif /* LLC_UPP_LAYER_NTFY_WRITE_RSP_CB */ + #define LLC_SEND_ERROR_COUNT #define RECV_ERROR_FRAME_COUNT (0x50U) @@ -191,7 +193,7 @@ DISABLED : then after receiving the UA frame, then a timer is started, to #define PH_LLCNFC_CRC_LENGTH (2) #define PH_LLCNFC_MAX_LLC_PAYLOAD ((PH_LLCNFC_MAX_IFRAME_BUFLEN) + (4)) /** Maximum timer used in the Llc */ -#define PH_LLCNFC_MAX_TIMER_USED (2) +#define PH_LLCNFC_MAX_TIMER_USED (3) /** Maximum timer used in the Llc */ #define PH_LLCNFC_MAX_ACK_GUARD_TIMER (4) /** Maximum I frame that can be stored */ @@ -496,7 +498,7 @@ typedef struct phLlcNfc_Timerinfo #ifdef PIGGY_BACK /** This will store the ack time out values */ - uint16_t ack_to_value[PH_LLCNFC_MAX_ACK_GUARD_TIMER]; + uint16_t ack_to_value; #endif /* #ifdef PIGGY_BACK */ /** This is a timer flag @@ -547,6 +549,9 @@ typedef struct phLlcNfc_Frame /** Store the I frames, that has been received, Storage will be till the window size */ phLlcNfc_StoreIFrame_t s_recv_store; + + /** Response received count to send the ACK once it reaches the window size */ + uint8_t resp_recvd_count; #endif /* #ifdef PIGGY_BACK */ /** To receive the packet sent by below layer */ diff --git a/src/phLlcNfc_Frame.c b/src/phLlcNfc_Frame.c index 946f67f..af61761 100644 --- a/src/phLlcNfc_Frame.c +++ b/src/phLlcNfc_Frame.c @@ -52,7 +52,6 @@ #ifdef LLC_RELEASE_FLAG extern uint8_t g_release_flag; #endif /* #ifdef LLC_RELEASE_FLAG */ - /************************ End of global variables *****************************/ /*********************** Local functions ****************************/ @@ -107,28 +106,6 @@ phLlcNfc_H_ProcessSFrame ( /** * \ingroup grp_hal_nfc_llc_helper * -* \brief LLC component <b>Create S frame</b> function -* -* \copydoc page_reg This is a helper function which, creates the S frame -* -* \param[in/out] psFrameInfo Generic frame information -* \param[in/out] cmdType Command type of S frame -* -* \retval NFCSTATUS_SUCCESS Operation successful. -* \retval NFCSTATUS_INVALID_PARAMETER At least one parameter of the function is invalid. -* -*/ -static -NFCSTATUS -phLlcNfc_H_CreateSFramePayload ( - phLlcNfc_Frame_t *psFrameInfo, - phLlcNfc_LlcCmd_t cmdType -); - - -/** -* \ingroup grp_hal_nfc_llc_helper -* * \brief LLC helper functions <b>Update I frame list</b> function * * \copydoc page_reg This function checks the nr value with the stored I frames @@ -433,10 +410,10 @@ phLlcNfc_H_CreateUFramePayload ( return result; } -static NFCSTATUS phLlcNfc_H_CreateSFramePayload ( phLlcNfc_Frame_t *psFrameInfo, + phLlcNfc_LlcPacket_t *psLlcPacket, phLlcNfc_LlcCmd_t cmdType ) { @@ -451,7 +428,7 @@ phLlcNfc_H_CreateSFramePayload ( phLlcNfc_Buffer_t *ps_llc_buf = NULL; uint8_t length = 0; - ps_llc_buf = &(psFrameInfo->s_llcpacket.s_llcbuf); + ps_llc_buf = &(psLlcPacket->s_llcbuf); /* Initial S frame header */ ps_llc_buf->sllcpayload.llcheader = PH_LLCNFC_S_HEADER_INIT; @@ -467,11 +444,10 @@ phLlcNfc_H_CreateSFramePayload ( (ps_llc_buf->sllcpayload.llcheader | (uint8_t)cmdType); /* Maximum S frame length */ - psFrameInfo->s_llcpacket.llcbuf_len = (uint8_t) - PH_LLCNFC_MAX_S_FRAME_LEN; + psLlcPacket->llcbuf_len = (uint8_t)PH_LLCNFC_MAX_S_FRAME_LEN; /* S frame length byte value */ ps_llc_buf->llc_length_byte = (uint8_t) - (psFrameInfo->s_llcpacket.llcbuf_len - 1); + (psLlcPacket->llcbuf_len - 1); /* psFrameInfo->s_llcpacket.s_llcbuf : @@ -493,7 +469,7 @@ phLlcNfc_H_CreateSFramePayload ( (psFrameInfo->s_llcpacket.llcbuf_len - 3) : is the array index of the second CRC byte to be calculated */ - length = psFrameInfo->s_llcpacket.llcbuf_len; + length = psLlcPacket->llcbuf_len; phLlcNfc_H_ComputeCrc( (uint8_t *)ps_llc_buf, (length - 2), &(ps_llc_buf->sllcpayload.llcpayload[(length - 4)]), @@ -760,7 +736,7 @@ phLlcNfc_H_SendUserIFrame ( { NFCSTATUS result = NFCSTATUS_SUCCESS; phLlcNfc_Frame_t *ps_frame_info = NULL; - phLlcNfc_LlcPacket_t *ps_create_packet = NULL; + phLlcNfc_LlcPacket_t s_create_packet; phLlcNfc_LlcPacket_t *ps_get_packet = NULL; phLlcNfc_Payload_t *ps_llc_payload = NULL; phLlcNfc_StoreIFrame_t *ps_store_frame = NULL; @@ -778,7 +754,6 @@ phLlcNfc_H_SendUserIFrame ( else { ps_frame_info = &(psLlcCtxt->s_frameinfo); - ps_create_packet = &(ps_frame_info->s_llcpacket); ps_store_frame = &(ps_frame_info->s_send_store); if ( @@ -788,7 +763,7 @@ phLlcNfc_H_SendUserIFrame ( { /* Get the stored I frame, only if the new frame is sent from the upper layer */ - result = phLlcNfc_H_IFrameList_Peek (psListInfo, &ps_get_packet, + result = phLlcNfc_H_IFrameList_Peek (psListInfo, &ps_get_packet, ps_frame_info->n_s); } @@ -800,25 +775,25 @@ phLlcNfc_H_SendUserIFrame ( llc_header = (uint8_t)(llc_header | ps_frame_info->n_r); /* Create the packet */ - (void)memcpy ((void *)ps_create_packet, (void *)ps_get_packet, + (void)memcpy ((void *)&(s_create_packet), (void *)ps_get_packet, sizeof (phLlcNfc_LlcPacket_t)); - ps_create_packet->s_llcbuf.sllcpayload.llcheader = llc_header; - ps_llc_payload = &(ps_create_packet->s_llcbuf.sllcpayload); + s_create_packet.s_llcbuf.sllcpayload.llcheader = llc_header; + ps_llc_payload = &(s_create_packet.s_llcbuf.sllcpayload); /* Length of the complete llc buffer, sent to PN544 */ - length = ps_create_packet->llcbuf_len; + length = s_create_packet.llcbuf_len; /* Compute CRC for the created packet */ - phLlcNfc_H_ComputeCrc ((uint8_t *)&(ps_create_packet->s_llcbuf), + phLlcNfc_H_ComputeCrc ((uint8_t *)&(s_create_packet.s_llcbuf), (length - 2), (uint8_t *)&(ps_llc_payload->llcpayload[(length - 4)]), (uint8_t *)&(ps_llc_payload->llcpayload[(length - 3)])); /* Send the i frame */ - result = phLlcNfc_Interface_Write (psLlcCtxt, - (uint8_t *)&(ps_create_packet->s_llcbuf), - (uint32_t)ps_create_packet->llcbuf_len); + result = phLlcNfc_Interface_Write (psLlcCtxt, + (uint8_t *)&(s_create_packet.s_llcbuf), + (uint32_t)s_create_packet.llcbuf_len); ps_frame_info->write_status = result; @@ -865,7 +840,7 @@ phLlcNfc_H_SendRejectedIFrame ( { NFCSTATUS result = NFCSTATUS_SUCCESS; phLlcNfc_Frame_t *ps_frame_info = NULL; - phLlcNfc_LlcPacket_t *ps_create_packet = NULL; + phLlcNfc_LlcPacket_t s_create_packet; phLlcNfc_LlcPacket_t *ps_get_packet = NULL; phLlcNfc_Payload_t *ps_llc_payload = NULL; phLlcNfc_StoreIFrame_t *ps_store_frame = NULL; @@ -883,7 +858,6 @@ phLlcNfc_H_SendRejectedIFrame ( else { ps_frame_info = &(psLlcCtxt->s_frameinfo); - ps_create_packet = &(ps_frame_info->s_llcpacket); ps_store_frame = &(ps_frame_info->s_send_store); @@ -898,7 +872,7 @@ phLlcNfc_H_SendRejectedIFrame ( ps_store_frame->s_llcpacket[ns_rejected].frame_to_send) { /* Above check is added to know only if */ - result = phLlcNfc_H_IFrameList_Peek (psListInfo, &ps_get_packet, + result = phLlcNfc_H_IFrameList_Peek (psListInfo, &ps_get_packet, ns_rejected); } else @@ -918,25 +892,25 @@ phLlcNfc_H_SendRejectedIFrame ( llc_header = (uint8_t)(llc_header | ps_frame_info->n_r); /* Create the packet */ - (void)memcpy ((void *)ps_create_packet, (void *)ps_get_packet, + (void)memcpy ((void *)&(s_create_packet), (void *)ps_get_packet, sizeof (phLlcNfc_LlcPacket_t)); - ps_create_packet->s_llcbuf.sllcpayload.llcheader = llc_header; - ps_llc_payload = &(ps_create_packet->s_llcbuf.sllcpayload); + s_create_packet.s_llcbuf.sllcpayload.llcheader = llc_header; + ps_llc_payload = &(s_create_packet.s_llcbuf.sllcpayload); /* Length of the complete llc buffer, sent to PN544 */ - length = ps_create_packet->llcbuf_len; + length = s_create_packet.llcbuf_len; /* Compute CRC for the created packet */ - phLlcNfc_H_ComputeCrc ((uint8_t *)&(ps_create_packet->s_llcbuf), + phLlcNfc_H_ComputeCrc ((uint8_t *)&(s_create_packet.s_llcbuf), (length - 2), (uint8_t *)&(ps_llc_payload->llcpayload[(length - 4)]), (uint8_t *)&(ps_llc_payload->llcpayload[(length - 3)])); /* Send the i frame */ result = phLlcNfc_Interface_Write (psLlcCtxt, - (uint8_t *)&(ps_create_packet->s_llcbuf), - (uint32_t)ps_create_packet->llcbuf_len); + (uint8_t *)&(s_create_packet.s_llcbuf), + (uint32_t)s_create_packet.llcbuf_len); ps_frame_info->write_status = result; @@ -946,7 +920,7 @@ phLlcNfc_H_SendRejectedIFrame ( so update the below variable */ ps_frame_info->write_wait_call = (phLlcNfc_eSentFrameType_t) (((ns_rejected != ps_store_frame->start_pos) && - (resend_i_frame != ps_frame_info->write_wait_call))? + (resend_i_frame != ps_frame_info->write_wait_call))? rejected_i_frame : ps_frame_info->write_wait_call); } else @@ -1009,7 +983,7 @@ phLlcNfc_H_SendTimedOutIFrame ( NFCSTATUS result = NFCSTATUS_SUCCESS; phLlcNfc_Frame_t *ps_frame_info = NULL; phLlcNfc_Timerinfo_t *ps_timer_info = NULL; - phLlcNfc_LlcPacket_t *ps_create_packet = NULL; + phLlcNfc_LlcPacket_t s_create_packet; phLlcNfc_LlcPacket_t *ps_get_packet = NULL; phLlcNfc_Payload_t *ps_llc_payload = NULL; phLlcNfc_StoreIFrame_t *ps_store_frame = NULL; @@ -1033,7 +1007,6 @@ phLlcNfc_H_SendTimedOutIFrame ( ps_frame_info = &(psLlcCtxt->s_frameinfo); ps_timer_info = &(psLlcCtxt->s_timerinfo); - ps_create_packet = &(ps_frame_info->s_llcpacket); ps_store_frame = &(ps_frame_info->s_send_store); timer_index = ps_timer_info->index_to_send; @@ -1043,12 +1016,13 @@ phLlcNfc_H_SendTimedOutIFrame ( PH_LLCNFC_DEBUG("SEND TIMEOUT CALL WIN SIZE CNT : 0x%02X\n", ps_store_frame->winsize_cnt); PH_LLCNFC_DEBUG("SEND TIMEOUT CALL START POS : 0x%02X\n", ps_store_frame->start_pos); PH_LLCNFC_DEBUG("SEND TIMEOUT CALL N S value : 0x%02X\n", ps_frame_info->n_s); + PH_LLCNFC_DEBUG("SEND TIMEOUT TIMER INDEX : 0x%02X\n", timer_index); PH_LLCNFC_DEBUG("SEND TIMEOUT CALL frame type : 0x%02X\n", ps_timer_info->frame_type[timer_index]); if (resend_i_frame == ps_timer_info->frame_type[timer_index]) { /* Get the stored I frame */ - result = phLlcNfc_H_IFrameList_Peek (psListInfo, &ps_get_packet, + result = phLlcNfc_H_IFrameList_Peek (psListInfo, &ps_get_packet, ns_index); } @@ -1061,25 +1035,25 @@ phLlcNfc_H_SendTimedOutIFrame ( llc_header = (uint8_t)(llc_header | ps_frame_info->n_r); /* create the packet */ - (void)memcpy ((void *)ps_create_packet, (void *)ps_get_packet, + (void)memcpy ((void *)&(s_create_packet), (void *)ps_get_packet, sizeof (phLlcNfc_LlcPacket_t)); - ps_create_packet->s_llcbuf.sllcpayload.llcheader = llc_header; - ps_llc_payload = &(ps_create_packet->s_llcbuf.sllcpayload); + s_create_packet.s_llcbuf.sllcpayload.llcheader = llc_header; + ps_llc_payload = &(s_create_packet.s_llcbuf.sllcpayload); /* Length of the complete llc buffer, sent to PN544 */ - length = ps_create_packet->llcbuf_len; + length = s_create_packet.llcbuf_len; /* Compute CRC */ - phLlcNfc_H_ComputeCrc((uint8_t *)&(ps_create_packet->s_llcbuf), + phLlcNfc_H_ComputeCrc((uint8_t *)&(s_create_packet.s_llcbuf), (length - 2), - (uint8_t *)&(ps_llc_payload->llcpayload[(length - 4)]), + (uint8_t *)&(ps_llc_payload->llcpayload[(length - 4)]), (uint8_t *)&(ps_llc_payload->llcpayload[(length - 3)])); /* Send the i frame */ result = phLlcNfc_Interface_Write (psLlcCtxt, - (uint8_t *)&(ps_create_packet->s_llcbuf), - (uint32_t)ps_create_packet->llcbuf_len); + (uint8_t *)&(s_create_packet.s_llcbuf), + (uint32_t)s_create_packet.llcbuf_len); ps_frame_info->write_status = result; PH_LLCNFC_DEBUG("SEND TIMEOUT CALL Write status : 0x%02X\n", result); @@ -1102,9 +1076,9 @@ phLlcNfc_H_SendTimedOutIFrame ( PH_LLCNFC_DEBUG("SEND TIMEOUT CALL timer index : 0x%02X\n", timer_index); - PH_LLCNFC_DEBUG("SEND TIMEOUT CALL GUARD TO VALUE : 0x%02X\n", ps_timer_info->guard_to_value[(timer_index - 1)]); if (timer_index > 0) { + PH_LLCNFC_DEBUG("SEND TIMEOUT CALL GUARD TO VALUE : 0x%02X\n", ps_timer_info->guard_to_value[(timer_index - 1)]); /* Copy the maximum time-out value. */ time_out_value = (uint16_t) ((ps_timer_info->guard_to_value[(timer_index - 1)] >= @@ -1212,12 +1186,6 @@ phLlcNfc_H_ProcessIFrame ( uint8_t recvd_nr = 0; #endif /* #ifdef RECV_NR_CHECK_ENABLE */ -#ifdef LLC_UPP_LAYER_NTFY_WRITE_RSP_CB - /* Nothing required in this define */ -#else - uint8_t prev_local_nr = 0; -#endif /* #ifdef LLC_UPP_LAYER_NTFY_WRITE_RSP_CB */ - ps_frame_info = &(psLlcCtxt->s_frameinfo); ps_store_frame = &(ps_frame_info->s_send_store); ps_recv_pkt = &(ps_frame_info->s_recvpacket); @@ -1259,12 +1227,6 @@ phLlcNfc_H_ProcessIFrame ( phLlcNfc_StopTimers (PH_LLCNFC_GUARDTIMER, no_of_del_frames); } -#ifdef LLC_UPP_LAYER_NTFY_WRITE_RSP_CB - /* Nothing required in this define */ -#else - prev_local_nr = ps_frame_info->n_r; -#endif /* #ifdef LLC_UPP_LAYER_NTFY_WRITE_RSP_CB */ - /* Received buffer, N(S) value = N(R) of host (our structure) then send RR type of s frame else send REJ type of s frame */ @@ -1290,7 +1252,6 @@ phLlcNfc_H_ProcessIFrame ( ps_recv_pkt->s_llcbuf.sllcpayload.llcpayload), psLlcCtxt->recvbuf_length); - #if defined (LLC_SEND_RR_ACK) if (((ns_index < ps_frame_info->n_r) && @@ -1309,6 +1270,11 @@ phLlcNfc_H_ProcessIFrame ( ps_frame_info->n_r = ((ps_frame_info->n_r + 1) % PH_LLCNFC_MOD_NS_NR); +#ifdef PIGGY_BACK + ps_frame_info->resp_recvd_count = (uint8_t) + (ps_frame_info->resp_recvd_count + 1); +#endif /* #ifdef PIGGY_BACK */ + } if (NFCSTATUS_BUSY == PHNFCSTATUS (ps_frame_info->write_status)) @@ -1334,9 +1300,7 @@ phLlcNfc_H_ProcessIFrame ( { dont_send_s_frame = TRUE; #ifdef LLC_UPP_LAYER_NTFY_WRITE_RSP_CB - phLlcNfc_H_SendInfo (psLlcCtxt); - #endif /* #ifdef LLC_UPP_LAYER_NTFY_WRITE_RSP_CB */ } else @@ -1349,15 +1313,10 @@ phLlcNfc_H_ProcessIFrame ( resend_s_frame : s_frame); } -#ifdef LLC_UPP_LAYER_NTFY_WRITE_RSP_CB - - /* Nothing required in this define */ - -#else /* #ifdef LLC_UPP_LAYER_NTFY_WRITE_RSP_CB */ - +#ifdef PIGGY_BACK phLlcNfc_H_SendInfo (psLlcCtxt); +#endif /* #ifdef PIGGY_BACK */ -#endif /* #ifdef LLC_UPP_LAYER_NTFY_WRITE_RSP_CB */ } else { @@ -1425,23 +1384,61 @@ phLlcNfc_H_ProcessIFrame ( #endif /* #ifdef LLC_RELEASE_FLAG */ { - result = phLlcNfc_Interface_Read(psLlcCtxt, + (void)phLlcNfc_Interface_Read(psLlcCtxt, PH_LLCNFC_READWAIT_OFF, &(ps_recv_pkt->s_llcbuf.llc_length_byte), (uint8_t)PH_LLCNFC_BYTES_INIT_READ); +#ifdef PIGGY_BACK + /* Check if any write call is performed or not */ + if (NFCSTATUS_PENDING != result) + { + /* No write is performed, So, now check */ + if (NFCSTATUS_BUSY == PHNFCSTATUS (ps_frame_info->write_status)) + { + /* Any how write cannot be done and some frame is ready to be sent + so this frame will act as the ACK */ + result = phLlcNfc_H_WriteWaitCall (psLlcCtxt); + } + } + + if (NFCSTATUS_PENDING != result) + { + if (ps_frame_info->window_size == ps_frame_info->resp_recvd_count) + { + phLlcNfc_LlcPacket_t s_packet_info; + /* Create S frame */ + (void)phLlcNfc_H_CreateSFramePayload (ps_frame_info, &(s_packet_info), cmdtype); + result = phLlcNfc_Interface_Write(psLlcCtxt, + (uint8_t *)&(s_packet_info.s_llcbuf), + (uint32_t)(s_packet_info.llcbuf_len)); + + + if (0 == ps_frame_info->send_error_count) + { + ps_frame_info->write_wait_call = invalid_frame; + } + ps_frame_info->sent_frame_type = eframe_type; + } + else + { + result = phLlcNfc_StartTimers (PH_LLCNFC_ACKTIMER, 0); + } + } +#else /* #ifdef PIGGY_BACK */ if ((TRUE != ps_frame_info->write_pending) && (PH_LLCNFC_READPEND_REMAIN_BYTE != ps_frame_info->read_pending) && (FALSE == dont_send_s_frame)) { + phLlcNfc_LlcPacket_t s_packet_info = {0}; /* Create S frame */ - (void)phLlcNfc_H_CreateSFramePayload (ps_frame_info, cmdtype); + (void)phLlcNfc_H_CreateSFramePayload (ps_frame_info, &(s_packet_info), cmdtype); result = phLlcNfc_Interface_Write(psLlcCtxt, - (uint8_t *)&(ps_frame_info->s_llcpacket.s_llcbuf), - (uint32_t)(ps_frame_info->s_llcpacket.llcbuf_len)); + (uint8_t *)&(s_packet_info.s_llcbuf), + (uint32_t)(s_packet_info.llcbuf_len)); if (0 == ps_frame_info->send_error_count) @@ -1450,6 +1447,7 @@ phLlcNfc_H_ProcessIFrame ( } ps_frame_info->sent_frame_type = eframe_type; } +#endif /* #ifdef PIGGY_BACK */ } return ; @@ -1962,13 +1960,16 @@ phLlcNfc_H_SendRejectFrame( ) { NFCSTATUS result = NFCSTATUS_SUCCESS; + phLlcNfc_LlcPacket_t s_packet_info = {0}; + result = phLlcNfc_H_CreateSFramePayload( - &(psLlcCtxt->s_frameinfo), + &(psLlcCtxt->s_frameinfo), + &(s_packet_info), phLlcNfc_e_rej); /* Send the "S" frame to the lower layer */ result = phLlcNfc_Interface_Write(psLlcCtxt, - (uint8_t *)&(psLlcCtxt->s_frameinfo.s_llcpacket.s_llcbuf), - (uint32_t)(psLlcCtxt->s_frameinfo.s_llcpacket.llcbuf_len)); + (uint8_t *)&(s_packet_info.s_llcbuf), + (uint32_t)(s_packet_info.llcbuf_len)); if (NFCSTATUS_PENDING == result) { @@ -2160,23 +2161,22 @@ phLlcNfc_H_SendRSETFrame ( ) { NFCSTATUS result = NFCSTATUS_SUCCESS; - phLlcNfc_LlcPacket_t *ps_packet_info = NULL; + phLlcNfc_LlcPacket_t s_packet_info; phLlcNfc_Frame_t *ps_frame_info = NULL; ps_frame_info = &(psLlcCtxt->s_frameinfo); - ps_packet_info = &(psLlcCtxt->s_frameinfo.s_llcpacket); - result = phLlcNfc_H_CreateUFramePayload(psLlcCtxt, - ps_packet_info, - &(ps_packet_info->llcbuf_len), + result = phLlcNfc_H_CreateUFramePayload(psLlcCtxt, + &(s_packet_info), + &(s_packet_info.llcbuf_len), phLlcNfc_e_rset); if (NFCSTATUS_SUCCESS == result) { /* Call DAL write */ - result = phLlcNfc_Interface_Write(psLlcCtxt, - (uint8_t*)&(ps_packet_info->s_llcbuf), - (uint32_t)ps_packet_info->llcbuf_len); + result = phLlcNfc_Interface_Write(psLlcCtxt, + (uint8_t*)&(s_packet_info.s_llcbuf), + (uint32_t)s_packet_info.llcbuf_len); } ps_frame_info->write_status = result; diff --git a/src/phLlcNfc_Frame.h b/src/phLlcNfc_Frame.h index e1662df..e76e017 100644 --- a/src/phLlcNfc_Frame.h +++ b/src/phLlcNfc_Frame.h @@ -264,6 +264,7 @@ phLlcNfc_H_CreateUFramePayload ( * * \param[in/out] psFrameInfo Information related to LLC frames are stored * in this structure +* \param[in/out] psLlcPacket Llc packet sent by the upper layer * \param[in] pLlcBuf User given buffer or the buffer which needs LLC framing * \param[in] llcBufLength Length of the parameter "pLlcBuf" * @@ -427,6 +428,28 @@ phLlcNfc_H_SendRejectedIFrame ( /** * \ingroup grp_hal_nfc_llc_helper * +* \brief LLC component <b>Create S frame</b> function +* +* \copydoc page_reg This is a helper function which, creates the S frame +* +* \param[in/out] psFrameInfo Generic frame information +* \param[in/out] psLlcPacket Llc packet sent by the upper layer +* \param[in/out] cmdType Command type of S frame +* +* \retval NFCSTATUS_SUCCESS Operation successful. +* \retval NFCSTATUS_INVALID_PARAMETER At least one parameter of the function is invalid. +* +*/ +NFCSTATUS +phLlcNfc_H_CreateSFramePayload ( + phLlcNfc_Frame_t *psFrameInfo, + phLlcNfc_LlcPacket_t *psLlcPacket, + phLlcNfc_LlcCmd_t cmdType +); + +/** +* \ingroup grp_hal_nfc_llc_helper +* * \brief LLC Send upper layer information function * * \copydoc page_reg Sends received information to the upper layer frame. diff --git a/src/phLlcNfc_Interface.c b/src/phLlcNfc_Interface.c index 871481b..a1e9938 100644 --- a/src/phLlcNfc_Interface.c +++ b/src/phLlcNfc_Interface.c @@ -48,7 +48,6 @@ /***************************** Macros *******************************/ #define PH_LLCNFC_APPEND_LEN (4) #define LLC_NS_FRAME_HEADER_MASK (0x38U) - /************************ End of macros *****************************/ /*********************** Local functions ****************************/ @@ -81,8 +80,8 @@ phLlcNfc_Interface_Register( ) { NFCSTATUS result = NFCSTATUS_SUCCESS; - phNfcIF_sCallBack_t if_cb; - phNfcIF_sReference_t sreference; + phNfcIF_sCallBack_t if_cb = {0,0,0,0}; + phNfcIF_sReference_t sreference = {0,0,0}; if ((NULL == psLlcCtxt) || (NULL == psIFConfig)) { @@ -247,13 +246,24 @@ phLlcNfc_Interface_Write( PH_LLCNFC_STRING (";\n"); #endif /* LLC_DATA_BYTES */ + + psLlcCtxt->s_frameinfo.s_llcpacket.llcbuf_len = (uint8_t)llcBufferLength; + (void)memcpy ((void *)&(psLlcCtxt->s_frameinfo.s_llcpacket.s_llcbuf), + (void *)pLlcBuffer, llcBufferLength); + result = psLlcCtxt->lower_if.send(psLlcCtxt->lower_if.pcontext, psLlcCtxt->phwinfo, - pLlcBuffer, + (uint8_t *)&(psLlcCtxt->s_frameinfo.s_llcpacket.s_llcbuf), (uint16_t)llcBufferLength); if(NFCSTATUS_PENDING == result) { psLlcCtxt->s_frameinfo.write_pending = TRUE; +#ifdef PIGGY_BACK + /* Stop the ACK timer, as the ACK or I frame is sent */ + phLlcNfc_StopTimers (PH_LLCNFC_ACKTIMER, 0); + /* ACK is sent, so reset the response received count */ + psLlcCtxt->s_frameinfo.resp_recvd_count = 0; +#endif /* #ifdef PIGGY_BACK */ } } } @@ -279,7 +289,7 @@ phLlcNfc_WrResp_Cb( phLlcNfc_Frame_t *ps_frame_info = NULL; phLlcNfc_LlcPacket_t *ps_recv_pkt = NULL; phLlcNfc_StoreIFrame_t *ps_store_frame = NULL; - phNfc_sCompletionInfo_t notifyinfo; + phNfc_sCompletionInfo_t notifyinfo = {0,0,0}; uint8_t count = 0; PH_LLCNFC_PRINT("\n\nLLC : WRITE RESP CB CALLED\n\n"); @@ -497,6 +507,7 @@ phLlcNfc_WrResp_Cb( } else { + /* ***** This notification needs to be disabled ***** */ if(NULL != ps_llc_ctxt->cb_for_if.send_complete) { pCompInfo->length = (pCompInfo->length - @@ -650,7 +661,7 @@ phLlcNfc_RdResp_Cb( phLlcNfc_LlcPacket_t *ps_recv_pkt = NULL; phLlcNfc_Payload_t *ps_llc_payload = NULL; pphNfcIF_Notification_CB_t notifyul = NULL; - phNfc_sCompletionInfo_t notifyinfo; + phNfc_sCompletionInfo_t notifyinfo = {0,0,0}; PH_LLCNFC_PRINT("\n\nLLC : READ RESP CB CALLED\n\n"); @@ -932,7 +943,7 @@ phLlcNfc_H_SendInfo ( { phLlcNfc_LlcPacket_t *ps_recv_pkt = NULL; phLlcNfc_Frame_t *ps_frame_info = NULL; - phNfc_sTransactionInfo_t comp_info; + phNfc_sTransactionInfo_t comp_info = {0,0,0,0,0}; ps_frame_info = &(psLlcCtxt->s_frameinfo); ps_recv_pkt = &(ps_frame_info->s_recvpacket); diff --git a/src/phLlcNfc_Timer.c b/src/phLlcNfc_Timer.c index c079760..06ca7e4 100644 --- a/src/phLlcNfc_Timer.c +++ b/src/phLlcNfc_Timer.c @@ -44,8 +44,6 @@ /***************************** Macros *******************************/ /**< Timer for connection timer index */ #define PH_LLCNFC_CONNECTION_TO_INDEX (0x00) -/**< 0x0A Timer for ack time out value */ -#define PH_LLCNFC_ACK_TO_VALUE (1000) /**< Maximum guard timer can be present */ #define PH_LLCNFC_MAX_GUARD_TIMER (0x04) /** Connection time out bit to set */ @@ -60,6 +58,8 @@ #define PH_LLCNFC_CON_TO_BIT_VAL (0x01) /** Guard time out bit to set */ #define PH_LLCNFC_GUARD_TO_BIT_VAL (0x02) +/** ACK time out bit to set */ +#define PH_LLCNFC_ACK_TO_BIT_VAL (0x04) #define GUARD_TO_URSET @@ -84,7 +84,7 @@ void phLlcNfc_AckTimeoutCb ( uint32_t TimerId ); -#endif +#endif /* #ifdef PIGGY_BACK */ /* This callback is for connection time out */ static @@ -290,17 +290,22 @@ phLlcNfc_StartTimers ( /* Get the ack timer flag */ timerstarted = (uint8_t)GET_BITS8 ( ps_timer_info->timer_flag, - PH_LLCNFC_GUARD_TO_BIT, + PH_LLCNFC_ACK_TO_BIT, PH_LLCNFC_TO_NOOFBITS); - if (0 == timerstarted) + + if (FALSE == timerstarted) { /* Timer not started, so start the timer */ ps_timer_info->timer_flag = (uint8_t) SET_BITS8 (ps_timer_info->timer_flag, - PH_LLCNFC_GUARD_TO_BIT - PH_LLCNFC_TO_NOOFBITS - (PH_LLCNFC_GUARD_TO_BIT - 1)); + PH_LLCNFC_ACK_TO_BIT, + PH_LLCNFC_TO_NOOFBITS, + (PH_LLCNFC_ACK_TO_BIT - 1)); } + + + timer_resolution = ps_timer_info->ack_to_value = (uint16_t) + PH_LLCNFC_ACK_TO_VALUE; timerid = ps_timer_info->timer_id[PH_LLCNFC_ACKTIMER]; Callback = (ppCallBck_t)&phLlcNfc_AckTimeoutCb; break; @@ -380,7 +385,7 @@ phLlcNfc_StopTimers ( { /* The number of guard timer count is more than the guard timer to delete */ - while (start_index < no_of_guard_to_del) + while (start_index < (timer_count - no_of_guard_to_del)) { /* Copy the previous stored timer values to the present */ ps_timer_info->guard_to_value[start_index] = (uint16_t) @@ -457,11 +462,14 @@ phLlcNfc_StopTimers ( #ifdef PIGGY_BACK case PH_LLCNFC_ACKTIMER: { + timerflag = (timerflag & PH_LLCNFC_ACK_TO_BIT_VAL); + ps_timer_info->timer_flag = (uint8_t) SET_BITS8 (ps_timer_info->timer_flag, - PH_LLCNFC_GUARD_TO_BIT, + PH_LLCNFC_ACK_TO_BIT, PH_LLCNFC_TO_NOOFBITS, 0); timerid = ps_timer_info->timer_id[PH_LLCNFC_ACKTIMER]; + ps_timer_info->ack_to_value = 0; break; } #endif /* #ifdef PIGGY_BACK */ @@ -486,7 +494,7 @@ phLlcNfc_StopTimers ( PHNFC_UNUSED_VARIABLE (result); PHNFC_UNUSED_VARIABLE (TimerType); - PHNFC_UNUSED_VARIABLE (no_of_gaurd_to_del); + PHNFC_UNUSED_VARIABLE (no_of_guard_to_del); #endif /* #ifdef LLC_TIMER_ENABLE */ } @@ -602,23 +610,25 @@ phLlcNfc_GuardTimeoutCb ( NFCSTATUS result = NFCSTATUS_SUCCESS; phLlcNfc_Timerinfo_t *ps_timer_info = NULL; phLlcNfc_Frame_t *ps_frame_info = NULL; - phLlcNfc_LlcPacket_t *ps_packet_info = NULL; + phLlcNfc_LlcPacket_t s_packet_info; uint8_t index = 0; + /* zero_to_index = Time out index has become 0 */ uint8_t zero_to_index = 0; + #if defined (GUARD_TO_ERROR) phNfc_sCompletionInfo_t notifyinfo = {0,0,0}; #endif /* #if defined (GUARD_TO_ERROR) */ - PHNFC_UNUSED_VARIABLE(pContext); PH_LLCNFC_PRINT("\n\nLLC : GUARD TIMEOUT CB CALLED \n\n"); - if ((NULL != gpphLlcNfc_Ctxt) && (TimerId == - gpphLlcNfc_Ctxt->s_timerinfo.timer_id[PH_LLCNFC_GUARDTIMER]) && - (PH_LLCNFC_GUARD_TO_BIT_VAL == - (gpphLlcNfc_Ctxt->s_timerinfo.timer_flag & + if ((NULL != gpphLlcNfc_Ctxt) && (TimerId == + gpphLlcNfc_Ctxt->s_timerinfo.timer_id[PH_LLCNFC_GUARDTIMER]) && + (PH_LLCNFC_GUARD_TO_BIT_VAL == + (gpphLlcNfc_Ctxt->s_timerinfo.timer_flag & PH_LLCNFC_GUARD_TO_BIT_VAL))) { uint8_t timer_expired = FALSE; + ps_frame_info = &(gpphLlcNfc_Ctxt->s_frameinfo); ps_timer_info = &(gpphLlcNfc_Ctxt->s_timerinfo); @@ -632,8 +642,15 @@ phLlcNfc_GuardTimeoutCb ( send called */ while (index < ps_timer_info->guard_to_count) { + /* This loop runs for all the timer present in the data structure. + This means if there are 2 I frame has been sent and + response is not received for the I frames sent then the + each time this timer expires, the time out value is decremented + by the PH_LLCNFC_RESOLUTION value */ if (0 != ps_timer_info->guard_to_value[index]) { + /* If timer value is not zero then enter, + this means that the value is not zero */ if (ps_timer_info->guard_to_value[index] > 0) { if (ps_timer_info->guard_to_value[index] >= @@ -651,10 +668,20 @@ phLlcNfc_GuardTimeoutCb ( if (0 == ps_timer_info->guard_to_value[index]) { + /* Timer value has expired, so resend has to be done + Timer value is 0 */ + ps_timer_info->frame_type[index] = (uint8_t)resend_i_frame; + if (FALSE == timer_expired) + { + /* As the statement is in the loop, so there are possibilities + of more than 1 timer value can be 0, so if previous timer + value has already been 0, then again dont change the + index */ zero_to_index = index; timer_expired = TRUE; } } + } index = (uint8_t)(index + 1); } @@ -686,7 +713,6 @@ phLlcNfc_GuardTimeoutCb ( timer_count = ps_timer_info->guard_to_count; - /* Check before changing the index to resend, if index already exist then dont set the index */ while ((FALSE == while_exit) && (start_index < timer_count)) @@ -702,13 +728,29 @@ phLlcNfc_GuardTimeoutCb ( } } - if (TRUE == while_exit) + if (FALSE == while_exit) { + /* This " ps_timer_info->index_to_send " member is + useful, when 2 time out values are 0, then + only first timed out value has to be resent and + other has to wait until the the first timed out + I frame is resent + This statement is executed only if, none of the timer + has expires previously, this is the first timer in the + list that has time out value has 0 + */ ps_timer_info->index_to_send = zero_to_index; } + else + { + /* This statement is executed only if, any one of the time + out value was 0 previously, so first resend has to be done + for the previous I frame, so the index is set to the previous + I frame + */ + ps_timer_info->index_to_send = start_index; + } - ps_timer_info->frame_type[zero_to_index] = (uint8_t) - resend_i_frame; /* Now resend the frame stored */ result = phLlcNfc_H_SendTimedOutIFrame (gpphLlcNfc_Ctxt, &(ps_frame_info->s_send_store), @@ -741,16 +783,15 @@ phLlcNfc_GuardTimeoutCb ( #if (!defined (GUARD_TO_ERROR) && defined (GUARD_TO_URSET)) PH_LLCNFC_PRINT("U-RSET IS SENT \n"); - ps_packet_info = &(gpphLlcNfc_Ctxt->s_frameinfo.s_llcpacket); - result = phLlcNfc_H_CreateUFramePayload(gpphLlcNfc_Ctxt, - ps_packet_info, - &(ps_packet_info->llcbuf_len), + result = phLlcNfc_H_CreateUFramePayload(gpphLlcNfc_Ctxt, + &(s_packet_info), + &(s_packet_info.llcbuf_len), phLlcNfc_e_rset); - result = phLlcNfc_Interface_Write(gpphLlcNfc_Ctxt, - (uint8_t*)&(ps_packet_info->s_llcbuf), - (uint32_t)ps_packet_info->llcbuf_len); + result = phLlcNfc_Interface_Write(gpphLlcNfc_Ctxt, + (uint8_t*)&(s_packet_info.s_llcbuf), + (uint32_t)s_packet_info.llcbuf_len); ps_frame_info->write_status = result; if (NFCSTATUS_PENDING == result) @@ -782,15 +823,71 @@ phLlcNfc_GuardTimeoutCb ( } #ifdef PIGGY_BACK + static void phLlcNfc_AckTimeoutCb ( uint32_t TimerId ) { + NFCSTATUS result = NFCSTATUS_SUCCESS; + phLlcNfc_Frame_t *ps_frame_info = NULL; + phLlcNfc_Timerinfo_t *ps_timer_info = NULL; + phLlcNfc_LlcPacket_t s_packet_info; + + PH_LLCNFC_PRINT("\n\nLLC : ACK TIMEOUT CB CALLED\n\n"); + if ((NULL != gpphLlcNfc_Ctxt) && (TimerId == + gpphLlcNfc_Ctxt->s_timerinfo.timer_id[PH_LLCNFC_ACKTIMER]) + && (PH_LLCNFC_ACK_TO_BIT_VAL == + (gpphLlcNfc_Ctxt->s_timerinfo.timer_flag & + PH_LLCNFC_ACK_TO_BIT_VAL))) + { + ps_frame_info = &(gpphLlcNfc_Ctxt->s_frameinfo); + ps_timer_info = &(gpphLlcNfc_Ctxt->s_timerinfo); + + phLlcNfc_StopTimers (PH_LLCNFC_ACKTIMER, 0); + + if (NFCSTATUS_BUSY == PHNFCSTATUS (ps_frame_info->write_status)) + { + /* Any how write cannot be done and some frame is ready to be sent + so this frame will act as the ACK */ + result = phLlcNfc_H_WriteWaitCall (gpphLlcNfc_Ctxt); + } + else + { + /* Create S frame */ + (void)phLlcNfc_H_CreateSFramePayload (ps_frame_info, &(s_packet_info), phLlcNfc_e_rr); + + result = phLlcNfc_Interface_Write(gpphLlcNfc_Ctxt, + (uint8_t *)&(s_packet_info.s_llcbuf), + (uint32_t)(s_packet_info.llcbuf_len)); + + if (NFCSTATUS_PENDING == result) + { + if (0 == ps_frame_info->send_error_count) + { + ps_frame_info->write_wait_call = invalid_frame; + } + ps_frame_info->sent_frame_type = s_frame; + } + else + { + if (invalid_frame == ps_frame_info->write_wait_call) + { + ps_frame_info->write_wait_call = s_frame; + } + } + } + } + + /* ACK is sent, so reset the response received count */ + gpphLlcNfc_Ctxt->s_frameinfo.resp_recvd_count = 0; + + PH_LLCNFC_PRINT("\n\nLLC : ACK TIMEOUT CB END\n\n"); } -#endif + +#endif /* #ifdef PIGGY_BACK */ static void @@ -805,7 +902,7 @@ phLlcNfc_ConnectionTimeoutCb ( void *p_upperctxt = NULL; phLlcNfc_Frame_t *ps_frame_info = NULL; phLlcNfc_Timerinfo_t *ps_timer_info = NULL; - PHNFC_UNUSED_VARIABLE(pContext); + phLlcNfc_LlcPacket_t s_packet_info; PH_LLCNFC_PRINT("\n\nLLC : CONNECTION TIMEOUT CB CALLED\n\n"); if ((NULL != gpphLlcNfc_Ctxt) && (TimerId == @@ -834,16 +931,16 @@ phLlcNfc_ConnectionTimeoutCb ( { /* Create a U frame */ result = phLlcNfc_H_CreateUFramePayload(gpphLlcNfc_Ctxt, - &(ps_frame_info->s_llcpacket), - &(ps_frame_info->s_llcpacket.llcbuf_len), + &(s_packet_info), + &(s_packet_info.llcbuf_len), phLlcNfc_e_rset); if (NFCSTATUS_SUCCESS == result) { /* Call DAL write */ result = phLlcNfc_Interface_Write (gpphLlcNfc_Ctxt, - (uint8_t*)&(ps_frame_info->s_llcpacket.s_llcbuf), - (uint32_t)(ps_frame_info->s_llcpacket.llcbuf_len)); + (uint8_t*)&(s_packet_info.s_llcbuf), + (uint32_t)(s_packet_info.llcbuf_len)); } if (NFCSTATUS_PENDING == result) { diff --git a/src/phLlcNfc_Timer.h b/src/phLlcNfc_Timer.h index d8f702a..f212a32 100644 --- a/src/phLlcNfc_Timer.h +++ b/src/phLlcNfc_Timer.h @@ -56,6 +56,12 @@ /**< 0x05 Timer for guard time out value */ #define PH_LLCNFC_GUARD_TO_VALUE LINK_GUARD_TIMEOUT +#ifdef PIGGY_BACK + +#define PH_LLCNFC_ACK_TO_VALUE LINK_ACK_TIMEOUT + +#endif /* #ifdef PIGGY_BACK */ + #ifdef LLC_RESET_DELAY #define LLC_URSET_DELAY_TIME_OUT LLC_RESET_DELAY #else @@ -201,8 +207,10 @@ phLlcNfc_DeleteTimer (void); void phLlcNfc_URSET_Delay_Notify ( - uint32_t delay_id, - void *pContext); + + uint32_t delay_id); + + #endif /* #ifdef LLC_URSET_NO_DELAY */ |