Fork of the GitHub

Committer:
DiegoOstuni
Date:
Thu Nov 14 14:34:50 2019 +0000
Revision:
0:75fc82583a41
Add files

Who changed what in which revision?

UserRevisionLine numberNew contents of line
DiegoOstuni 0:75fc82583a41 1
DiegoOstuni 0:75fc82583a41 2 /******************************************************************************
DiegoOstuni 0:75fc82583a41 3 * @attention
DiegoOstuni 0:75fc82583a41 4 *
DiegoOstuni 0:75fc82583a41 5 * <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
DiegoOstuni 0:75fc82583a41 6 *
DiegoOstuni 0:75fc82583a41 7 * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License");
DiegoOstuni 0:75fc82583a41 8 * You may not use this file except in compliance with the License.
DiegoOstuni 0:75fc82583a41 9 * You may obtain a copy of the License at:
DiegoOstuni 0:75fc82583a41 10 *
DiegoOstuni 0:75fc82583a41 11 * http://www.st.com/myliberty
DiegoOstuni 0:75fc82583a41 12 *
DiegoOstuni 0:75fc82583a41 13 * Unless required by applicable law or agreed to in writing, software
DiegoOstuni 0:75fc82583a41 14 * distributed under the License is distributed on an "AS IS" BASIS,
DiegoOstuni 0:75fc82583a41 15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
DiegoOstuni 0:75fc82583a41 16 * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
DiegoOstuni 0:75fc82583a41 17 * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
DiegoOstuni 0:75fc82583a41 18 * See the License for the specific language governing permissions and
DiegoOstuni 0:75fc82583a41 19 * limitations under the License.
DiegoOstuni 0:75fc82583a41 20 *
DiegoOstuni 0:75fc82583a41 21 ******************************************************************************/
DiegoOstuni 0:75fc82583a41 22
DiegoOstuni 0:75fc82583a41 23
DiegoOstuni 0:75fc82583a41 24 /*
DiegoOstuni 0:75fc82583a41 25 * PROJECT: NFCC firmware
DiegoOstuni 0:75fc82583a41 26 * LANGUAGE: ISO C99
DiegoOstuni 0:75fc82583a41 27 */
DiegoOstuni 0:75fc82583a41 28
DiegoOstuni 0:75fc82583a41 29 /*! \file rfal_nfcDep.c
DiegoOstuni 0:75fc82583a41 30 *
DiegoOstuni 0:75fc82583a41 31 * \author Gustavo Patricio
DiegoOstuni 0:75fc82583a41 32 *
DiegoOstuni 0:75fc82583a41 33 * \brief Implementation of NFC-DEP protocol
DiegoOstuni 0:75fc82583a41 34 *
DiegoOstuni 0:75fc82583a41 35 * NFC-DEP is also known as NFCIP - Near Field Communication
DiegoOstuni 0:75fc82583a41 36 * Interface and Protocol
DiegoOstuni 0:75fc82583a41 37 *
DiegoOstuni 0:75fc82583a41 38 * This implementation was based on the following specs:
DiegoOstuni 0:75fc82583a41 39 * - NFC Forum Digital 1.1
DiegoOstuni 0:75fc82583a41 40 * - ECMA 340 3rd Edition 2013
DiegoOstuni 0:75fc82583a41 41 *
DiegoOstuni 0:75fc82583a41 42 */
DiegoOstuni 0:75fc82583a41 43
DiegoOstuni 0:75fc82583a41 44 /*
DiegoOstuni 0:75fc82583a41 45 ******************************************************************************
DiegoOstuni 0:75fc82583a41 46 * INCLUDES
DiegoOstuni 0:75fc82583a41 47 ******************************************************************************
DiegoOstuni 0:75fc82583a41 48 */
DiegoOstuni 0:75fc82583a41 49 #include <platform1.h>
DiegoOstuni 0:75fc82583a41 50 #include "rfal_nfcDep.h"
DiegoOstuni 0:75fc82583a41 51 #include "rfal_nfcf.h"
DiegoOstuni 0:75fc82583a41 52 #include "utils.h"
DiegoOstuni 0:75fc82583a41 53
DiegoOstuni 0:75fc82583a41 54 /*
DiegoOstuni 0:75fc82583a41 55 ******************************************************************************
DiegoOstuni 0:75fc82583a41 56 * ENABLE SWITCH
DiegoOstuni 0:75fc82583a41 57 ******************************************************************************
DiegoOstuni 0:75fc82583a41 58 */
DiegoOstuni 0:75fc82583a41 59
DiegoOstuni 0:75fc82583a41 60 #ifndef RFAL_FEATURE_NFC_DEP
DiegoOstuni 0:75fc82583a41 61 #error " RFAL: Module configuration missing. Please enable/disable NFC-DEP module by setting: RFAL_FEATURE_NFC_DEP "
DiegoOstuni 0:75fc82583a41 62 #endif
DiegoOstuni 0:75fc82583a41 63
DiegoOstuni 0:75fc82583a41 64 #if RFAL_FEATURE_NFC_DEP
DiegoOstuni 0:75fc82583a41 65
DiegoOstuni 0:75fc82583a41 66 /*
DiegoOstuni 0:75fc82583a41 67 ******************************************************************************
DiegoOstuni 0:75fc82583a41 68 * DEFINES
DiegoOstuni 0:75fc82583a41 69 ******************************************************************************
DiegoOstuni 0:75fc82583a41 70 */
DiegoOstuni 0:75fc82583a41 71
DiegoOstuni 0:75fc82583a41 72 #define NFCIP_LOOP_MAX 0x0005FFFF /*!< Max blocking reRuns */
DiegoOstuni 0:75fc82583a41 73 #define NFCIP_ATR_RETRY_MAX 2 /*!< Max consecutive retrys of an ATR REQ with transm error*/
DiegoOstuni 0:75fc82583a41 74
DiegoOstuni 0:75fc82583a41 75 #define NFCIP_PSLPAY_LEN (2) /*!< PSL Payload length (BRS + FSL) */
DiegoOstuni 0:75fc82583a41 76 #define NFCIP_PSLREQ_LEN (3 + RFAL_NFCDEP_LEN_LEN) /*!< PSL REQ length (incl LEN) */
DiegoOstuni 0:75fc82583a41 77 #define NFCIP_PSLRES_LEN (3 + RFAL_NFCDEP_LEN_LEN) /*!< PSL RES length (incl LEN) */
DiegoOstuni 0:75fc82583a41 78
DiegoOstuni 0:75fc82583a41 79 #define NFCIP_ATRREQ_BUF_LEN (RFAL_NFCDEP_ATRREQ_MAX_LEN + RFAL_NFCDEP_LEN_LEN) /*!< ATR REQ max length (incl LEN) */
DiegoOstuni 0:75fc82583a41 80 #define NFCIP_ATRRES_BUF_LEN (RFAL_NFCDEP_ATRRES_MAX_LEN + RFAL_NFCDEP_LEN_LEN) /*!< ATR RES max length (incl LEN) */
DiegoOstuni 0:75fc82583a41 81
DiegoOstuni 0:75fc82583a41 82 #define NFCIP_RLSREQ_LEN (3 + RFAL_NFCDEP_LEN_LEN) /*!< RLS REQ length (incl LEN) */
DiegoOstuni 0:75fc82583a41 83 #define NFCIP_RLSRES_LEN (3 + RFAL_NFCDEP_LEN_LEN) /*!< RSL RES length (incl LEN) */
DiegoOstuni 0:75fc82583a41 84 #define NFCIP_RLSRES_MIN (2 + RFAL_NFCDEP_LEN_LEN) /*!< Minimum length for a RLS RES (incl LEN) */
DiegoOstuni 0:75fc82583a41 85
DiegoOstuni 0:75fc82583a41 86 #define NFCIP_DSLREQ_LEN (3 + RFAL_NFCDEP_LEN_LEN) /*!< DSL REQ length (incl LEN) */
DiegoOstuni 0:75fc82583a41 87 #define NFCIP_DSLRES_LEN (3 + RFAL_NFCDEP_LEN_LEN) /*!< DSL RES length (incl LEN) */
DiegoOstuni 0:75fc82583a41 88 #define NFCIP_DSLRES_MIN (2 + RFAL_NFCDEP_LEN_LEN) /*!< Minimum length for a DSL RES (incl LEN) */
DiegoOstuni 0:75fc82583a41 89
DiegoOstuni 0:75fc82583a41 90 #define NFCIP_DSLRES_MAX_LEN (3 + RFAL_NFCDEP_LEN_LEN) /*!< Maximum length for a DSL RES (incl LEN) */
DiegoOstuni 0:75fc82583a41 91 #define NFCIP_RLSRES_MAX_LEN (3 + RFAL_NFCDEP_LEN_LEN) /*!< Minimum length for a RLS RES (incl LEN) */
DiegoOstuni 0:75fc82583a41 92 #define NFCIP_TARGET_RES_MAX ( MAX( NFCIP_RLSRES_MAX_LEN, NFCIP_DSLRES_MAX_LEN) ) /*!< Max target control res length */
DiegoOstuni 0:75fc82583a41 93
DiegoOstuni 0:75fc82583a41 94
DiegoOstuni 0:75fc82583a41 95
DiegoOstuni 0:75fc82583a41 96 #define NFCIP_NO_FWT RFAL_FWT_NONE /*!< No FWT value - Target Mode */
DiegoOstuni 0:75fc82583a41 97 #define NFCIP_INIT_MIN_RTOX 1 /*!< Minimum RTOX value Digital 1.0 14.8.4.1 */
DiegoOstuni 0:75fc82583a41 98 #define NFCIP_INIT_MAX_RTOX 59 /*!< Maximum RTOX value Digital 1.0 14.8.4.1 */
DiegoOstuni 0:75fc82583a41 99
DiegoOstuni 0:75fc82583a41 100 #define NFCIP_TARG_MIN_RTOX 1 /*!< Minimum target RTOX value Digital 1.0 14.8.4.1 */
DiegoOstuni 0:75fc82583a41 101 #define NFCIP_TARG_MAX_RTOX 59 /*!< Maximum target RTOX value Digital 1.0 14.8.4.1 */
DiegoOstuni 0:75fc82583a41 102
DiegoOstuni 0:75fc82583a41 103 #define NFCIP_TRECOV (1280 / 64) /*!< Digital 1.0 A.10 Trecov */
DiegoOstuni 0:75fc82583a41 104
DiegoOstuni 0:75fc82583a41 105 #define NFCIP_TIMEOUT_ADJUSTMENT 8 /*!< Timeout Adjustment to compensate timing from end of Tx to end of frame: (512/64)/fc */
DiegoOstuni 0:75fc82583a41 106 #define NFCIP_RWT_ACTIVATION (0x40001 + NFCIP_TIMEOUT_ADJUSTMENT) /*!< Digital 1.0 A.10 RWT ACTIVATION 2^24/64[64/fc] + RWT Delta + Adjustment */
DiegoOstuni 0:75fc82583a41 107
DiegoOstuni 0:75fc82583a41 108 #define RFAL_NFCDEP_HEADER_PAD (RFAL_NFCDEP_DEPREQ_HEADER_LEN - RFAL_NFCDEP_LEN_MIN) /*!< Difference between expected rcvd header len and max foreseen */
DiegoOstuni 0:75fc82583a41 109
DiegoOstuni 0:75fc82583a41 110
DiegoOstuni 0:75fc82583a41 111 #define NFCIP_MAX_TX_RETRYS 3 /*!< Number of retransmit retyrs */
DiegoOstuni 0:75fc82583a41 112 #define NFCIP_MAX_TO_RETRYS 3 /*!< Number of retrys for Timeout */
DiegoOstuni 0:75fc82583a41 113 #define NFCIP_MAX_RTOX_RETRYS 3 /*!< Number of retrys for RTOX */
DiegoOstuni 0:75fc82583a41 114 #define NFCIP_MAX_NACK_RETRYS 3 /*!< Number of retrys for NACK */
DiegoOstuni 0:75fc82583a41 115 #define NFCIP_MAX_ATN_RETRYS 3 /*!< Number of retrys for ATN */
DiegoOstuni 0:75fc82583a41 116
DiegoOstuni 0:75fc82583a41 117 #define NFCIP_MIN_TXERROR_LEN 4 /*!< Minimum frame length with error to be ignored Digital 1.0 14.12.5.4 */
DiegoOstuni 0:75fc82583a41 118
DiegoOstuni 0:75fc82583a41 119 #define NFCIP_REQ 0xD4 /*!<NFCIP REQuest code */
DiegoOstuni 0:75fc82583a41 120 #define NFCIP_RES 0xD5 /*!<NFCIP RESponce code */
DiegoOstuni 0:75fc82583a41 121
DiegoOstuni 0:75fc82583a41 122 #define NFCIP_BS_MASK 0x0F /*!< Bit mask for BS value on a ATR REQ/RES */
DiegoOstuni 0:75fc82583a41 123 #define NFCIP_BR_MASK NFCIP_BS_MASK /*!< Bit mask for BR value on a ATR REQ/RES */
DiegoOstuni 0:75fc82583a41 124
DiegoOstuni 0:75fc82583a41 125 #define NFCIP_PP_GB_MASK 0x02 /*!< Bit mask for GB value in PP byte on a ATR REQ/RES */
DiegoOstuni 0:75fc82583a41 126 #define NFCIP_PP_NAD_MASK 0x01 /*!< Bit mask for NAD value in PP byte on a ATR REQ/RES */
DiegoOstuni 0:75fc82583a41 127
DiegoOstuni 0:75fc82583a41 128 #define NFCIP_PFB_xPDU_MASK 0xE0 /*!< Bit mask for PDU type */
DiegoOstuni 0:75fc82583a41 129 #define NFCIP_PFB_IPDU 0x00 /*!< Bit mask indicating a Information PDU */
DiegoOstuni 0:75fc82583a41 130 #define NFCIP_PFB_RPDU 0x40 /*!< Bit mask indicating a Response PDU */
DiegoOstuni 0:75fc82583a41 131 #define NFCIP_PFB_SPDU 0x80 /*!< Bit mask indicating a Supervisory PDU */
DiegoOstuni 0:75fc82583a41 132
DiegoOstuni 0:75fc82583a41 133 #define NFCIP_PFB_MI_BIT 0x10 /*!< Bit mask for the chaining bit (MI) of PFB */
DiegoOstuni 0:75fc82583a41 134 #define NFCIP_PFB_DID_BIT 0x04 /*!< Bit mask for the DID presence bit of PFB */
DiegoOstuni 0:75fc82583a41 135 #define NFCIP_PFB_NAD_BIT 0x08 /*!< Bit mask for the NAD presence bit of PFB */
DiegoOstuni 0:75fc82583a41 136 #define NFCIP_PFB_PNI_MASK 0x03 /*!< Bit mask for the Packet Number Information */
DiegoOstuni 0:75fc82583a41 137
DiegoOstuni 0:75fc82583a41 138 #define NFCIP_PFB_Rx_MASK 0x10 /*!< Bit mask for the R-PDU type */
DiegoOstuni 0:75fc82583a41 139 #define NFCIP_PFB_ACK 0x00 /*!< Bit mask for R-PDU indicating ACK */
DiegoOstuni 0:75fc82583a41 140 #define NFCIP_PFB_NACK 0x10 /*!< Bit mask for R-PDU indicating NAK */
DiegoOstuni 0:75fc82583a41 141
DiegoOstuni 0:75fc82583a41 142 #define NFCIP_PFB_Sx_MASK 0x10 /*!< Bit mask for the R-PDU type */
DiegoOstuni 0:75fc82583a41 143 #define NFCIP_PFB_ATN 0x00 /*!< Bit mask for R-PDU indicating ACK */
DiegoOstuni 0:75fc82583a41 144 #define NFCIP_PFB_TO 0x10 /*!< Bit mask for R-PDU indicating NAK */
DiegoOstuni 0:75fc82583a41 145
DiegoOstuni 0:75fc82583a41 146 #define NFCIP_PFB_INVALID 0xFF /*!< Invalid PFB value */
DiegoOstuni 0:75fc82583a41 147
DiegoOstuni 0:75fc82583a41 148 /*
DiegoOstuni 0:75fc82583a41 149 ******************************************************************************
DiegoOstuni 0:75fc82583a41 150 * MACROS
DiegoOstuni 0:75fc82583a41 151 ******************************************************************************
DiegoOstuni 0:75fc82583a41 152 */
DiegoOstuni 0:75fc82583a41 153
DiegoOstuni 0:75fc82583a41 154 #define nfcipIsTransmissionError(e) ( (ERR_NO_MASK(e) == ERR_CRC) || (ERR_NO_MASK(e) == ERR_FRAMING) || (ERR_NO_MASK(e) == ERR_PAR) ) /*!< Checks if is a Trasmission error */
DiegoOstuni 0:75fc82583a41 155
DiegoOstuni 0:75fc82583a41 156
DiegoOstuni 0:75fc82583a41 157 #define nfcipConv1FcToMs( v ) (((v * 64) / 13560) + 1) /*!< Converts value v 1fc into milliseconds (fc=13.56) */
DiegoOstuni 0:75fc82583a41 158
DiegoOstuni 0:75fc82583a41 159 #define nfcipCmdIsReq( cmd ) ((cmd % 2) == 0) /*!< Checks if the nfcip cmd is a REQ */
DiegoOstuni 0:75fc82583a41 160
DiegoOstuni 0:75fc82583a41 161 #define nfcip_PFBhasDID( pfb ) ( (pfb & NFCIP_PFB_DID_BIT) == NFCIP_PFB_DID_BIT) /*!< Checks if pfb is signalling DID */
DiegoOstuni 0:75fc82583a41 162 #define nfcip_PFBhasNAD( pfb ) ( (pfb & NFCIP_PFB_NAD_BIT) == NFCIP_PFB_NAD_BIT) /*!< Checks if pfb is signalling NAD */
DiegoOstuni 0:75fc82583a41 163
DiegoOstuni 0:75fc82583a41 164 #define nfcip_PFBisIPDU( pfb ) ( (pfb & NFCIP_PFB_xPDU_MASK) == NFCIP_PFB_IPDU) /*!< Checks if pfb is a Information PDU */
DiegoOstuni 0:75fc82583a41 165 #define nfcip_PFBisRPDU( pfb ) ( (pfb & NFCIP_PFB_xPDU_MASK) == NFCIP_PFB_RPDU) /*!< Checks if pfb is Response PDU */
DiegoOstuni 0:75fc82583a41 166 #define nfcip_PFBisSPDU( pfb ) ( (pfb & NFCIP_PFB_xPDU_MASK) == NFCIP_PFB_SPDU) /*!< Checks if pfb is a Supervisory PDU */
DiegoOstuni 0:75fc82583a41 167
DiegoOstuni 0:75fc82583a41 168 #define nfcip_PFBisIMI( pfb ) ( nfcip_PFBisIPDU( pfb ) && (pfb & NFCIP_PFB_MI_BIT) == NFCIP_PFB_MI_BIT) /*!< Checks if pfb is a Information PDU indicating MI chaining */
DiegoOstuni 0:75fc82583a41 169
DiegoOstuni 0:75fc82583a41 170 #define nfcip_PFBisRNACK( pfb ) ( nfcip_PFBisRPDU( pfb ) && ((pfb & NFCIP_PFB_Rx_MASK) == NFCIP_PFB_NACK)) /*!< Checks if pfb is a R-PDU indicating NACK */
DiegoOstuni 0:75fc82583a41 171 #define nfcip_PFBisRACK( pfb ) ( nfcip_PFBisRPDU( pfb ) && ((pfb & NFCIP_PFB_Rx_MASK) == NFCIP_PFB_ACK )) /*!< Checks if pfb is a R-PDU indicating ACK */
DiegoOstuni 0:75fc82583a41 172
DiegoOstuni 0:75fc82583a41 173 #define nfcip_PFBisSATN( pfb ) ( nfcip_PFBisSPDU( pfb ) && ((pfb & NFCIP_PFB_Sx_MASK) == NFCIP_PFB_ATN)) /*!< Checks if pfb is a R-PDU indicating ATN */
DiegoOstuni 0:75fc82583a41 174 #define nfcip_PFBisSTO( pfb ) ( nfcip_PFBisSPDU( pfb ) && ((pfb & NFCIP_PFB_Sx_MASK) == NFCIP_PFB_TO) ) /*!< Checks if pfb is a R-PDU indicating TO */
DiegoOstuni 0:75fc82583a41 175
DiegoOstuni 0:75fc82583a41 176
DiegoOstuni 0:75fc82583a41 177 #define nfcip_PFBIPDU( pni ) ( (uint8_t)( 0x00 | NFCIP_PFB_IPDU | (pni & NFCIP_PFB_PNI_MASK) ))/*!< Returns a PFB I-PDU with the given packet number (pni) */
DiegoOstuni 0:75fc82583a41 178 #define nfcip_PFBIPDU_MI( pni ) ( (uint8_t)(isoDep_PCBIBlock(pni) | NFCIP_PFB_MI_BIT)) /*!< Returns a PFB I-PDU with the given packet number (pni) indicating chaing */
DiegoOstuni 0:75fc82583a41 179
DiegoOstuni 0:75fc82583a41 180 #define nfcip_PFBRPDU( pni ) ( (uint8_t)( 0x00 | NFCIP_PFB_RPDU | (pni & NFCIP_PFB_PNI_MASK) ))/*!< Returns a PFB R-PDU with the given packet number (pni) */
DiegoOstuni 0:75fc82583a41 181 #define nfcip_PFBRPDU_NACK( pni ) ( (uint8_t)(nfcip_PFBRPDU(pni) | NFCIP_PFB_NACK)) /*!< Returns a PFB R-PDU with the given packet number (pni) indicating NACK */
DiegoOstuni 0:75fc82583a41 182 #define nfcip_PFBRPDU_ACK( pni ) ( (uint8_t)(nfcip_PFBRPDU(pni) | NFCIP_PFB_ACK)) /*!< Returns a PFB R-PDU with the given packet number (pni) indicating ACK */
DiegoOstuni 0:75fc82583a41 183
DiegoOstuni 0:75fc82583a41 184 #define nfcip_PFBSPDU() ( (uint8_t)( 0x00 | NFCIP_PFB_SPDU )) /*!< Returns a PFB S-PDU */
DiegoOstuni 0:75fc82583a41 185 #define nfcip_PFBSPDU_ATN() ( (uint8_t)(nfcip_PFBSPDU() | NFCIP_PFB_ATN)) /*!< Returns a PFB S-PDU indicating ATN */
DiegoOstuni 0:75fc82583a41 186 #define nfcip_PFBSPDU_TO() ( (uint8_t)(nfcip_PFBSPDU() | NFCIP_PFB_TO)) /*!< Returns a PFB S-PDU indicating TO */
DiegoOstuni 0:75fc82583a41 187
DiegoOstuni 0:75fc82583a41 188
DiegoOstuni 0:75fc82583a41 189 #define nfcip_PNIInc( pni ) ( (uint8_t) ((pni+1) & NFCIP_PFB_PNI_MASK) ) /*!< Returns a incremented PNI from the given (pni) */
DiegoOstuni 0:75fc82583a41 190 #define nfcip_PNIDec( pni ) ( (uint8_t) ((pni-1) & NFCIP_PFB_PNI_MASK) ) /*!< Returns a decremented PNI from the given (pni) */
DiegoOstuni 0:75fc82583a41 191
DiegoOstuni 0:75fc82583a41 192 #define nfcip_PBF_PNI( pfb ) ( (uint8_t) (pfb & NFCIP_PFB_PNI_MASK )) /*!< Returns the Packet Number Information (pni) */
DiegoOstuni 0:75fc82583a41 193
DiegoOstuni 0:75fc82583a41 194 #define nfcip_PPwGB( lr ) ( rfalNfcDepLR2PP( lr ) | NFCIP_PP_GB_MASK) /*!< Returns a PP byte containing the given PP value indicating GB */
DiegoOstuni 0:75fc82583a41 195
DiegoOstuni 0:75fc82583a41 196 #define nfcip_DIDMax( did ) ( MIN( (did), RFAL_NFCDEP_DID_MAX) ) /*!< Ensures that the given did has proper value Digital 14.6.2.3 DID [0 14] */
DiegoOstuni 0:75fc82583a41 197 #define nfcip_RTOXTargMax( wt ) ( MIN( (RFAL_NFCDEP_RWT_TRG_MAX / rfalNfcDepWT2RWT(wt)), NFCIP_TARG_MAX_RTOX) )/*!< Calculates the Maximum RTOX value for the given wt as a Target */
DiegoOstuni 0:75fc82583a41 198
DiegoOstuni 0:75fc82583a41 199 #define nfcipIsInitiator( st ) ( ((st) >= NFCIP_ST_INIT_IDLE) && ((st) <= NFCIP_ST_INIT_RLS) )/*!< Checks if module is set as Initiator */
DiegoOstuni 0:75fc82583a41 200 #define nfcipIsTarget( st ) (!nfcipIsInitiator(st)) /*!< Checks if module is set as Target */
DiegoOstuni 0:75fc82583a41 201
DiegoOstuni 0:75fc82583a41 202 #define nfcipIsBRAllowed( br, mBR ) (((1<<(br)) & mBR) != 0) /*!< Checks bit rate is allowed by given mask */
DiegoOstuni 0:75fc82583a41 203
DiegoOstuni 0:75fc82583a41 204 #define nfcipIsEmptyDEPEnabled( op ) (!nfcipIsEmptyDEPDisabled(op)) /*!< Checks if empty payload is allowed by operation config NCI 1.0 Table 81 */
DiegoOstuni 0:75fc82583a41 205 #define nfcipIsEmptyDEPDisabled( op ) ((op & RFAL_NFCDEP_OPER_EMPTY_DEP_DIS) != 0) /*!< Checks if empty payload is not allowed by operation config NCI 1.0 Table 81 */
DiegoOstuni 0:75fc82583a41 206
DiegoOstuni 0:75fc82583a41 207 #define nfcipIsRTOXReqEnabled( op ) (!nfcipIsRTOXReqDisabled(op)) /*!< Checks if send a RTOX_REQ is allowed by operation config NCI 1.0 Table 81 */
DiegoOstuni 0:75fc82583a41 208 #define nfcipIsRTOXReqDisabled( op ) ((op & RFAL_NFCDEP_OPER_RTOX_REQ_DIS) != 0) /*!< Checks if send a RTOX_REQ is not allowed by operation config NCI 1.0 Table 81 */
DiegoOstuni 0:75fc82583a41 209
DiegoOstuni 0:75fc82583a41 210
DiegoOstuni 0:75fc82583a41 211 /*! Checks if isDeactivating callback is set and calls it, otherwise returns false */
DiegoOstuni 0:75fc82583a41 212 #define nfcipIsDeactivationPending() ( (gNfcip.isDeactivating == NULL) ? false : gNfcip.isDeactivating() )
DiegoOstuni 0:75fc82583a41 213
DiegoOstuni 0:75fc82583a41 214
DiegoOstuni 0:75fc82583a41 215 #define nfcipRTOXAdjust( v ) (v - (v>>3)) /*!< Adjust RTOX timer value to a percentage of the total, current 88% */
DiegoOstuni 0:75fc82583a41 216
DiegoOstuni 0:75fc82583a41 217 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 218
DiegoOstuni 0:75fc82583a41 219 /* timerPollTimeoutValue is necessary after timerCalculateTimeout so that system will wake up upon timer timeout. */
DiegoOstuni 0:75fc82583a41 220 #define nfcipTimerStart( timer, time_ms ) timer = platformTimerCreate(time_ms) /*!< Configures and starts the RTOX timer */
DiegoOstuni 0:75fc82583a41 221 #define nfcipTimerisExpired( timer ) platformTimerIsExpired( timer ) /*!< Checks RTOX timer has expired */
DiegoOstuni 0:75fc82583a41 222
DiegoOstuni 0:75fc82583a41 223 #define nfcipLogE(...) /*!< Macro for the error log method */
DiegoOstuni 0:75fc82583a41 224 #define nfcipLogW(...) /*!< Macro for the warning log method */
DiegoOstuni 0:75fc82583a41 225 #define nfcipLogI(...) /*!< Macro for the info log method */
DiegoOstuni 0:75fc82583a41 226 #define nfcipLogD(...) /*!< Macro for the debug log method */
DiegoOstuni 0:75fc82583a41 227
DiegoOstuni 0:75fc82583a41 228
DiegoOstuni 0:75fc82583a41 229 /*! Digital 1.1 - 16.12.5.2 The Target SHALL NOT attempt any error recovery and remains in Rx mode upon Transmission or a Protocol Error */
DiegoOstuni 0:75fc82583a41 230 #define nfcDepReEnableRx( rxB, rxBL, rxL ) rfalTransceiveBlockingTx( NULL, 0, rxB, rxBL, rxL, ( RFAL_TXRX_FLAGS_DEFAULT | RFAL_TXRX_FLAGS_NFCIP1_ON ), RFAL_FWT_NONE, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 )
DiegoOstuni 0:75fc82583a41 231
DiegoOstuni 0:75fc82583a41 232
DiegoOstuni 0:75fc82583a41 233 uint8_t txBuf[RFAL_NFCDEP_ATRREQ_MAX_LEN];
DiegoOstuni 0:75fc82583a41 234 uint8_t rxBuf[NFCIP_ATRRES_BUF_LEN];
DiegoOstuni 0:75fc82583a41 235
DiegoOstuni 0:75fc82583a41 236 uint8_t txBufPSL[NFCIP_PSLREQ_LEN];
DiegoOstuni 0:75fc82583a41 237 uint8_t pslBufPSL[NFCIP_PSLPAY_LEN];
DiegoOstuni 0:75fc82583a41 238 uint8_t rxBufPSL[NFCIP_PSLRES_LEN];
DiegoOstuni 0:75fc82583a41 239
DiegoOstuni 0:75fc82583a41 240 uint8_t txBufDSL[ RFAL_NFCDEP_HEADER_PAD + NFCIP_DSLREQ_LEN];
DiegoOstuni 0:75fc82583a41 241 uint8_t rxBufDSL[NFCIP_DSLRES_LEN];
DiegoOstuni 0:75fc82583a41 242
DiegoOstuni 0:75fc82583a41 243 uint8_t txBufRLS[RFAL_NFCDEP_HEADER_PAD + NFCIP_RLSREQ_LEN];
DiegoOstuni 0:75fc82583a41 244 uint8_t rxBufRLS[NFCIP_RLSRES_LEN];
DiegoOstuni 0:75fc82583a41 245
DiegoOstuni 0:75fc82583a41 246 /*
DiegoOstuni 0:75fc82583a41 247 ******************************************************************************
DiegoOstuni 0:75fc82583a41 248 * LOCAL DATA TYPES
DiegoOstuni 0:75fc82583a41 249 ******************************************************************************
DiegoOstuni 0:75fc82583a41 250 */
DiegoOstuni 0:75fc82583a41 251
DiegoOstuni 0:75fc82583a41 252 /*! Struct that holds all DEP parameters/configs for the following communications */
DiegoOstuni 0:75fc82583a41 253 typedef struct{
DiegoOstuni 0:75fc82583a41 254 uint8_t did; /*!< Device ID (DID) to be used */
DiegoOstuni 0:75fc82583a41 255
DiegoOstuni 0:75fc82583a41 256 uint8_t* txBuf; /*!< Pointer to the Tx buffer to be sent */
DiegoOstuni 0:75fc82583a41 257 uint16_t txBufLen; /*!< Length of the data in the txBuf */
DiegoOstuni 0:75fc82583a41 258 uint8_t txBufPaylPos; /*!< Position inside txBuf where data starts */
DiegoOstuni 0:75fc82583a41 259 uint8_t txChaining; /*!< Flag indicating chaining on transmission */
DiegoOstuni 0:75fc82583a41 260
DiegoOstuni 0:75fc82583a41 261 uint8_t* rxBuf; /*!< Pointer to the Rx buffer for incoming data */
DiegoOstuni 0:75fc82583a41 262 uint16_t rxBufLen; /*!< Length of the data in the rxBuf */
DiegoOstuni 0:75fc82583a41 263 uint8_t rxBufPaylPos; /*!< Position inside rxBuf where data is to be placed*/
DiegoOstuni 0:75fc82583a41 264
DiegoOstuni 0:75fc82583a41 265 uint32_t fwt; /*!< Frame Waiting Time (FWT) to be used */
DiegoOstuni 0:75fc82583a41 266 uint32_t dFwt; /*!< Delta Frame Waiting Time (dFWT) to be used */
DiegoOstuni 0:75fc82583a41 267 uint16_t fsc; /*!< Frame Size (FSC) to be used */
DiegoOstuni 0:75fc82583a41 268
DiegoOstuni 0:75fc82583a41 269 } rfalNfcDepDEPParams;
DiegoOstuni 0:75fc82583a41 270
DiegoOstuni 0:75fc82583a41 271 /*! NFCIP module states */
DiegoOstuni 0:75fc82583a41 272 typedef enum NfcipState
DiegoOstuni 0:75fc82583a41 273 {
DiegoOstuni 0:75fc82583a41 274 NFCIP_ST_IDLE,
DiegoOstuni 0:75fc82583a41 275 NFCIP_ST_INIT_IDLE,
DiegoOstuni 0:75fc82583a41 276 NFCIP_ST_INIT_ATR,
DiegoOstuni 0:75fc82583a41 277 NFCIP_ST_INIT_PSL,
DiegoOstuni 0:75fc82583a41 278 NFCIP_ST_INIT_DEP_IDLE,
DiegoOstuni 0:75fc82583a41 279 NFCIP_ST_INIT_DEP_TX,
DiegoOstuni 0:75fc82583a41 280 NFCIP_ST_INIT_DEP_RX,
DiegoOstuni 0:75fc82583a41 281 NFCIP_ST_INIT_DEP_ATN,
DiegoOstuni 0:75fc82583a41 282 NFCIP_ST_INIT_DSL,
DiegoOstuni 0:75fc82583a41 283 NFCIP_ST_INIT_RLS,
DiegoOstuni 0:75fc82583a41 284
DiegoOstuni 0:75fc82583a41 285 NFCIP_ST_TARG_WAIT_ATR,
DiegoOstuni 0:75fc82583a41 286 NFCIP_ST_TARG_WAIT_ACTV,
DiegoOstuni 0:75fc82583a41 287 NFCIP_ST_TARG_DEP_IDLE,
DiegoOstuni 0:75fc82583a41 288 NFCIP_ST_TARG_DEP_RX,
DiegoOstuni 0:75fc82583a41 289 NFCIP_ST_TARG_DEP_RTOX,
DiegoOstuni 0:75fc82583a41 290 NFCIP_ST_TARG_DEP_TX,
DiegoOstuni 0:75fc82583a41 291 NFCIP_ST_TARG_DEP_SLEEP
DiegoOstuni 0:75fc82583a41 292 } rfalNfcDepState;
DiegoOstuni 0:75fc82583a41 293
DiegoOstuni 0:75fc82583a41 294 /*! NFCIP commands (Request, Response) */
DiegoOstuni 0:75fc82583a41 295 typedef enum{
DiegoOstuni 0:75fc82583a41 296 NFCIP_CMD_ATR_REQ = 0x00,
DiegoOstuni 0:75fc82583a41 297 NFCIP_CMD_ATR_RES = 0x01,
DiegoOstuni 0:75fc82583a41 298 NFCIP_CMD_WUP_REQ = 0x02,
DiegoOstuni 0:75fc82583a41 299 NFCIP_CMD_WUP_RES = 0x03,
DiegoOstuni 0:75fc82583a41 300 NFCIP_CMD_PSL_REQ = 0x04,
DiegoOstuni 0:75fc82583a41 301 NFCIP_CMD_PSL_RES = 0x05,
DiegoOstuni 0:75fc82583a41 302 NFCIP_CMD_DEP_REQ = 0x06,
DiegoOstuni 0:75fc82583a41 303 NFCIP_CMD_DEP_RES = 0x07,
DiegoOstuni 0:75fc82583a41 304 NFCIP_CMD_DSL_REQ = 0x08,
DiegoOstuni 0:75fc82583a41 305 NFCIP_CMD_DSL_RES = 0x09,
DiegoOstuni 0:75fc82583a41 306 NFCIP_CMD_RLS_REQ = 0x0A,
DiegoOstuni 0:75fc82583a41 307 NFCIP_CMD_RLS_RES = 0x0B
DiegoOstuni 0:75fc82583a41 308 } rfalNfcDepCmd;
DiegoOstuni 0:75fc82583a41 309
DiegoOstuni 0:75fc82583a41 310
DiegoOstuni 0:75fc82583a41 311 /*! Struct that holds all NFCIP data */
DiegoOstuni 0:75fc82583a41 312 typedef struct{
DiegoOstuni 0:75fc82583a41 313 rfalNfcDepConfigs cfg; /*!< Holds the current configuration to be used */
DiegoOstuni 0:75fc82583a41 314
DiegoOstuni 0:75fc82583a41 315 rfalNfcDepState state; /*!< Current state of the NFCIP module */
DiegoOstuni 0:75fc82583a41 316 uint8_t pni; /*!< Packet Number Information (PNI) counter */
DiegoOstuni 0:75fc82583a41 317
DiegoOstuni 0:75fc82583a41 318 uint8_t lastCmd; /*!< Last command sent */
DiegoOstuni 0:75fc82583a41 319 uint8_t lastPFB; /*!< Last PFB sent */
DiegoOstuni 0:75fc82583a41 320 uint8_t lastPFBnATN; /*!< Last PFB sent (excluding ATN) */
DiegoOstuni 0:75fc82583a41 321 uint8_t lastRTOX; /*!< Last RTOX value sent */
DiegoOstuni 0:75fc82583a41 322
DiegoOstuni 0:75fc82583a41 323 uint8_t cntTxRetrys; /*!< Retransmissions counter */
DiegoOstuni 0:75fc82583a41 324 uint8_t cntTORetrys; /*!< Timeouts counter */
DiegoOstuni 0:75fc82583a41 325 uint8_t cntRTOXRetrys; /*!< RTOX counter */
DiegoOstuni 0:75fc82583a41 326 uint8_t cntNACKRetrys; /*!< NACK counter */
DiegoOstuni 0:75fc82583a41 327 uint8_t cntATNRetrys; /*!< Attention (ATN) counter */
DiegoOstuni 0:75fc82583a41 328
DiegoOstuni 0:75fc82583a41 329 uint16_t fsc; /*!< Current Frame Size (FSC) to be used */
DiegoOstuni 0:75fc82583a41 330 bool isTxChaining; /*!< Flag for chaining on Transmission */
DiegoOstuni 0:75fc82583a41 331 bool isRxChaining; /*!< Flag for chaining on Reception */
DiegoOstuni 0:75fc82583a41 332 uint8_t* txBuf; /*!< Pointer to the Tx buffer to be sent */
DiegoOstuni 0:75fc82583a41 333 uint8_t* rxBuf; /*!< Pointer to the Rx buffer for incoming data */
DiegoOstuni 0:75fc82583a41 334 uint16_t txBufLen; /*!< Length of the data in the txBuf */
DiegoOstuni 0:75fc82583a41 335 uint16_t rxBufLen; /*!< Length of rxBuf buffer */
DiegoOstuni 0:75fc82583a41 336 uint16_t* rxRcvdLen; /*!< Length of the data in the rxBuf */
DiegoOstuni 0:75fc82583a41 337 uint8_t txBufPaylPos; /*!< Position in txBuf where data starts */
DiegoOstuni 0:75fc82583a41 338 uint8_t rxBufPaylPos; /*!< Position in rxBuf where data is to be placed */
DiegoOstuni 0:75fc82583a41 339 bool *isChaining; /*!< Flag for chaining on Reception */
DiegoOstuni 0:75fc82583a41 340
DiegoOstuni 0:75fc82583a41 341 rfalNfcDepDevice *nfcDepDev; /*!< Pointer to NFC-DEP device info */
DiegoOstuni 0:75fc82583a41 342
DiegoOstuni 0:75fc82583a41 343 uint32_t RTOXTimer; /*!< Timer used for RTOX */
DiegoOstuni 0:75fc82583a41 344 rfalNfcDepDeactCallback isDeactivating; /*!< Deactivating flag check callback */
DiegoOstuni 0:75fc82583a41 345
DiegoOstuni 0:75fc82583a41 346 bool isReqPending; /*!< Flag pending REQ from Target activation */
DiegoOstuni 0:75fc82583a41 347 bool isTxPending; /*!< Flag pending DEP Block while waiting RTOX Ack */
DiegoOstuni 0:75fc82583a41 348 bool isWait4RTOX; /*!< Flag for waiting RTOX Ack */
DiegoOstuni 0:75fc82583a41 349 }rfalNfcDep;
DiegoOstuni 0:75fc82583a41 350
DiegoOstuni 0:75fc82583a41 351
DiegoOstuni 0:75fc82583a41 352 /*
DiegoOstuni 0:75fc82583a41 353 ******************************************************************************
DiegoOstuni 0:75fc82583a41 354 * LOCAL VARIABLES
DiegoOstuni 0:75fc82583a41 355 ******************************************************************************
DiegoOstuni 0:75fc82583a41 356 */
DiegoOstuni 0:75fc82583a41 357
DiegoOstuni 0:75fc82583a41 358 static rfalNfcDep gNfcip; /*!< NFCIP module instance */
DiegoOstuni 0:75fc82583a41 359
DiegoOstuni 0:75fc82583a41 360
DiegoOstuni 0:75fc82583a41 361 /*
DiegoOstuni 0:75fc82583a41 362 ******************************************************************************
DiegoOstuni 0:75fc82583a41 363 * LOCAL FUNCTION PROTOTYPES
DiegoOstuni 0:75fc82583a41 364 ******************************************************************************
DiegoOstuni 0:75fc82583a41 365 */
DiegoOstuni 0:75fc82583a41 366
DiegoOstuni 0:75fc82583a41 367 static ReturnCode nfcipTxRx( rfalNfcDepCmd cmd, uint8_t* txBuf, uint32_t fwt, uint8_t* paylBuf, uint8_t paylBufLen, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rxActLen, SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 );
DiegoOstuni 0:75fc82583a41 368 static ReturnCode nfcipTx( rfalNfcDepCmd cmd, uint8_t* txBuf, uint8_t *paylBuf, uint16_t paylLen, uint8_t pfb, uint32_t fwt, SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 );
DiegoOstuni 0:75fc82583a41 369 static ReturnCode nfcipDEPControlMsg( uint8_t pfb, uint8_t RTOX, SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 );
DiegoOstuni 0:75fc82583a41 370 static ReturnCode nfcipInitiatorHandleDEP( ReturnCode rxRes, uint16_t rxLen, uint16_t *outActRxLen, bool *outIsChaining, SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 );
DiegoOstuni 0:75fc82583a41 371 static ReturnCode nfcipTargetHandleRX( ReturnCode rxRes, uint16_t *outActRxLen, bool *outIsChaining, SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 );
DiegoOstuni 0:75fc82583a41 372 static ReturnCode nfcipTargetHandleActivation( rfalNfcDepDevice *nfcDepDev, uint8_t *outBRS, SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 );
DiegoOstuni 0:75fc82583a41 373
DiegoOstuni 0:75fc82583a41 374
DiegoOstuni 0:75fc82583a41 375 /*!
DiegoOstuni 0:75fc82583a41 376 ******************************************************************************
DiegoOstuni 0:75fc82583a41 377 * \brief NFCIP Congigure
DiegoOstuni 0:75fc82583a41 378 *
DiegoOstuni 0:75fc82583a41 379 * Configures the nfcip layer with the given configurations
DiegoOstuni 0:75fc82583a41 380 *
DiegoOstuni 0:75fc82583a41 381 * \param[in] cfg : nfcip configuration for following communication
DiegoOstuni 0:75fc82583a41 382 ******************************************************************************
DiegoOstuni 0:75fc82583a41 383 */
DiegoOstuni 0:75fc82583a41 384 static void nfcipConfig( rfalNfcDepConfigs cfg );
DiegoOstuni 0:75fc82583a41 385
DiegoOstuni 0:75fc82583a41 386
DiegoOstuni 0:75fc82583a41 387 /*!
DiegoOstuni 0:75fc82583a41 388 ******************************************************************************
DiegoOstuni 0:75fc82583a41 389 * \brief Set DEP parameters
DiegoOstuni 0:75fc82583a41 390 *
DiegoOstuni 0:75fc82583a41 391 * This method sets the parameters/configs for following Data Exchange
DiegoOstuni 0:75fc82583a41 392 * Sets the nfcip module state according to the role it is configured
DiegoOstuni 0:75fc82583a41 393 *
DiegoOstuni 0:75fc82583a41 394 *
DiegoOstuni 0:75fc82583a41 395 * \warning To be used only after proper Initiator/Target activation:
DiegoOstuni 0:75fc82583a41 396 * nfcipTargetHandleActivation() or nfcipInitiatorActivate() has
DiegoOstuni 0:75fc82583a41 397 * returned success
DiegoOstuni 0:75fc82583a41 398 *
DiegoOstuni 0:75fc82583a41 399 * This must be called before nfcipRun() in case of Target to pass
DiegoOstuni 0:75fc82583a41 400 * rxBuffer
DiegoOstuni 0:75fc82583a41 401 *
DiegoOstuni 0:75fc82583a41 402 * Everytime some data needs to be transmitted call this to set it and
DiegoOstuni 0:75fc82583a41 403 * call nfcipRun() until done or error
DiegoOstuni 0:75fc82583a41 404 *
DiegoOstuni 0:75fc82583a41 405 * \param[in] DEPParams : the parameters to be used during Data Exchange
DiegoOstuni 0:75fc82583a41 406 ******************************************************************************
DiegoOstuni 0:75fc82583a41 407 */
DiegoOstuni 0:75fc82583a41 408 static void nfcipSetDEPParams( rfalNfcDepDEPParams *DEPParams );
DiegoOstuni 0:75fc82583a41 409
DiegoOstuni 0:75fc82583a41 410
DiegoOstuni 0:75fc82583a41 411 /*!
DiegoOstuni 0:75fc82583a41 412 ******************************************************************************
DiegoOstuni 0:75fc82583a41 413 * \brief NFCIP run protocol
DiegoOstuni 0:75fc82583a41 414 *
DiegoOstuni 0:75fc82583a41 415 * This method handles all the nfcip protocol during Data Exchange (DEP
DiegoOstuni 0:75fc82583a41 416 * requests and responses).
DiegoOstuni 0:75fc82583a41 417 *
DiegoOstuni 0:75fc82583a41 418 * A data exchange cycle is considered a DEP REQ and a DEP RES.
DiegoOstuni 0:75fc82583a41 419 *
DiegoOstuni 0:75fc82583a41 420 * In case of Tx chaining(MI) must signal it with nfcipSetDEPParams()
DiegoOstuni 0:75fc82583a41 421 * In case of Rx chaining(MI) outIsChaining will be set to true and the
DiegoOstuni 0:75fc82583a41 422 * current data returned
DiegoOstuni 0:75fc82583a41 423 *
DiegoOstuni 0:75fc82583a41 424 * \param[out] outActRxLen : data received length
DiegoOstuni 0:75fc82583a41 425 * \param[out] outIsChaining : true if other peer is performing chaining(MI)
DiegoOstuni 0:75fc82583a41 426 *
DiegoOstuni 0:75fc82583a41 427 * \return ERR_NONE : Data exchange cycle completed successfully
DiegoOstuni 0:75fc82583a41 428 * \return ERR_TIMEOUT : Timeout occurred
DiegoOstuni 0:75fc82583a41 429 * \return ERR_PROTO : Protocol error occurred
DiegoOstuni 0:75fc82583a41 430 * \return ERR_AGAIN : Other peer is doing chaining(MI), current block
DiegoOstuni 0:75fc82583a41 431 * was received successfully call again until complete
DiegoOstuni 0:75fc82583a41 432 *
DiegoOstuni 0:75fc82583a41 433 ******************************************************************************
DiegoOstuni 0:75fc82583a41 434 */
DiegoOstuni 0:75fc82583a41 435 static ReturnCode nfcipRun( uint16_t *outActRxLen, bool *outIsChaining, SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 );
DiegoOstuni 0:75fc82583a41 436
DiegoOstuni 0:75fc82583a41 437
DiegoOstuni 0:75fc82583a41 438 /*!
DiegoOstuni 0:75fc82583a41 439 ******************************************************************************
DiegoOstuni 0:75fc82583a41 440 * \brief Transmission method
DiegoOstuni 0:75fc82583a41 441 *
DiegoOstuni 0:75fc82583a41 442 * This method checks if the current communication is Active or Passive
DiegoOstuni 0:75fc82583a41 443 * and performs the necessary procedures for each communication type
DiegoOstuni 0:75fc82583a41 444 *
DiegoOstuni 0:75fc82583a41 445 * Transmits the data hold in txBuf
DiegoOstuni 0:75fc82583a41 446 *
DiegoOstuni 0:75fc82583a41 447 * \param[in] txBuf : buffer to transmit
DiegoOstuni 0:75fc82583a41 448 * \param[in] txBufLen : txBuffer capacity
DiegoOstuni 0:75fc82583a41 449 * \param[in] fwt : fwt for current Tx
DiegoOstuni 0:75fc82583a41 450 *
DiegoOstuni 0:75fc82583a41 451 * \return ERR_NONE : No error
DiegoOstuni 0:75fc82583a41 452 ******************************************************************************
DiegoOstuni 0:75fc82583a41 453 */
DiegoOstuni 0:75fc82583a41 454 static ReturnCode nfcipDataTx( uint8_t* txBuf, uint16_t txBufLen, uint32_t fwt, SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 );
DiegoOstuni 0:75fc82583a41 455
DiegoOstuni 0:75fc82583a41 456
DiegoOstuni 0:75fc82583a41 457 /*!
DiegoOstuni 0:75fc82583a41 458 ******************************************************************************
DiegoOstuni 0:75fc82583a41 459 * \brief Reception method
DiegoOstuni 0:75fc82583a41 460 *
DiegoOstuni 0:75fc82583a41 461 * This method checks if the current communication is Active or Passive
DiegoOstuni 0:75fc82583a41 462 * and calls the appropriate reception method
DiegoOstuni 0:75fc82583a41 463 *
DiegoOstuni 0:75fc82583a41 464 * Copies incoming data to rxBuf
DiegoOstuni 0:75fc82583a41 465 *
DiegoOstuni 0:75fc82583a41 466 * \param[out] rxBuf : buffer to hold incomming data
DiegoOstuni 0:75fc82583a41 467 * \param[in] rxBufLen : rxBuf capacity
DiegoOstuni 0:75fc82583a41 468 * \param[out] actualRxLen : length of the data received
DiegoOstuni 0:75fc82583a41 469 *
DiegoOstuni 0:75fc82583a41 470 * \return ERR_NONE : No error
DiegoOstuni 0:75fc82583a41 471 ******************************************************************************
DiegoOstuni 0:75fc82583a41 472 */
DiegoOstuni 0:75fc82583a41 473 static ReturnCode nfcipDataRx( void );
DiegoOstuni 0:75fc82583a41 474
DiegoOstuni 0:75fc82583a41 475
DiegoOstuni 0:75fc82583a41 476 /*
DiegoOstuni 0:75fc82583a41 477 ******************************************************************************
DiegoOstuni 0:75fc82583a41 478 * LOCAL FUNCTIONS
DiegoOstuni 0:75fc82583a41 479 ******************************************************************************
DiegoOstuni 0:75fc82583a41 480 */
DiegoOstuni 0:75fc82583a41 481
DiegoOstuni 0:75fc82583a41 482 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 483
DiegoOstuni 0:75fc82583a41 484
DiegoOstuni 0:75fc82583a41 485 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 486 static bool nfcipDxIsSupported( uint8_t Dx, uint8_t BRx, uint8_t BSx )
DiegoOstuni 0:75fc82583a41 487 {
DiegoOstuni 0:75fc82583a41 488 uint8_t Bx;
DiegoOstuni 0:75fc82583a41 489
DiegoOstuni 0:75fc82583a41 490 /* Take the min of the possible bit rates, we'll use one for both directions */
DiegoOstuni 0:75fc82583a41 491 Bx = MIN(BRx, BSx);
DiegoOstuni 0:75fc82583a41 492
DiegoOstuni 0:75fc82583a41 493 /* Lower bit rates must be supported for P2P */
DiegoOstuni 0:75fc82583a41 494 if( (Dx <= RFAL_NFCDEP_Dx_04_424) )
DiegoOstuni 0:75fc82583a41 495 {
DiegoOstuni 0:75fc82583a41 496 return true;
DiegoOstuni 0:75fc82583a41 497 }
DiegoOstuni 0:75fc82583a41 498
DiegoOstuni 0:75fc82583a41 499 if( (Dx == RFAL_NFCDEP_Dx_08_848) && (Bx >= RFAL_NFCDEP_Bx_08_848) )
DiegoOstuni 0:75fc82583a41 500 {
DiegoOstuni 0:75fc82583a41 501 return true;
DiegoOstuni 0:75fc82583a41 502 }
DiegoOstuni 0:75fc82583a41 503
DiegoOstuni 0:75fc82583a41 504 return false;
DiegoOstuni 0:75fc82583a41 505 }
DiegoOstuni 0:75fc82583a41 506
DiegoOstuni 0:75fc82583a41 507
DiegoOstuni 0:75fc82583a41 508 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 509 static ReturnCode nfcipTxRx( rfalNfcDepCmd cmd, uint8_t* txBuf, uint32_t fwt, uint8_t* paylBuf,
DiegoOstuni 0:75fc82583a41 510 uint8_t paylBufLen, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rxActLen,
DiegoOstuni 0:75fc82583a41 511 SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ,
DiegoOstuni 0:75fc82583a41 512 DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03,
DiegoOstuni 0:75fc82583a41 513 DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 )
DiegoOstuni 0:75fc82583a41 514 {
DiegoOstuni 0:75fc82583a41 515 ReturnCode ret;
DiegoOstuni 0:75fc82583a41 516 uint32_t reRun;
DiegoOstuni 0:75fc82583a41 517
DiegoOstuni 0:75fc82583a41 518 reRun = NFCIP_LOOP_MAX; /* set maximum loop reRuns */
DiegoOstuni 0:75fc82583a41 519
DiegoOstuni 0:75fc82583a41 520 if( (cmd == NFCIP_CMD_DEP_REQ) || (cmd == NFCIP_CMD_DEP_RES) ) /* this method cannot be used for DEPs */
DiegoOstuni 0:75fc82583a41 521 {
DiegoOstuni 0:75fc82583a41 522 return ERR_PARAM;
DiegoOstuni 0:75fc82583a41 523 }
DiegoOstuni 0:75fc82583a41 524
DiegoOstuni 0:75fc82583a41 525 /* Assign the global params for this TxRx */
DiegoOstuni 0:75fc82583a41 526 gNfcip.rxBuf = rxBuf;
DiegoOstuni 0:75fc82583a41 527 gNfcip.rxBufLen = rxBufLen;
DiegoOstuni 0:75fc82583a41 528 gNfcip.rxRcvdLen = rxActLen;
DiegoOstuni 0:75fc82583a41 529
DiegoOstuni 0:75fc82583a41 530
DiegoOstuni 0:75fc82583a41 531 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 532 /* Transmission */
DiegoOstuni 0:75fc82583a41 533 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 534 if(txBuf != NULL) /* if nothing to Tx, just do Rx */
DiegoOstuni 0:75fc82583a41 535 {
DiegoOstuni 0:75fc82583a41 536 EXIT_ON_ERR( ret, nfcipTx( cmd, txBuf, paylBuf, paylBufLen, 0, fwt, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) );
DiegoOstuni 0:75fc82583a41 537 }
DiegoOstuni 0:75fc82583a41 538
DiegoOstuni 0:75fc82583a41 539 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 540 /* Reception */
DiegoOstuni 0:75fc82583a41 541 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 542 do /* call Rx() until done or max reRuns reached */
DiegoOstuni 0:75fc82583a41 543 {
DiegoOstuni 0:75fc82583a41 544 ret = nfcipDataRx();
DiegoOstuni 0:75fc82583a41 545
DiegoOstuni 0:75fc82583a41 546
DiegoOstuni 0:75fc82583a41 547 rfalWorker( mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ;
DiegoOstuni 0:75fc82583a41 548
DiegoOstuni 0:75fc82583a41 549 if( !reRun-- ) /* if max reRuns reached return error */
DiegoOstuni 0:75fc82583a41 550 {
DiegoOstuni 0:75fc82583a41 551 return ERR_MAX_RERUNS;
DiegoOstuni 0:75fc82583a41 552 }
DiegoOstuni 0:75fc82583a41 553 }
DiegoOstuni 0:75fc82583a41 554 while( ret == ERR_NO_MASK(ERR_BUSY) );
DiegoOstuni 0:75fc82583a41 555
DiegoOstuni 0:75fc82583a41 556 if( ret != ERR_NONE )
DiegoOstuni 0:75fc82583a41 557 {
DiegoOstuni 0:75fc82583a41 558 return ret;
DiegoOstuni 0:75fc82583a41 559 }
DiegoOstuni 0:75fc82583a41 560
DiegoOstuni 0:75fc82583a41 561 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 562 *rxActLen = *rxBuf; /* Use LEN byte instead due to with/without CRC modes */
DiegoOstuni 0:75fc82583a41 563 return ERR_NONE; /* Tx and Rx completed successfully */
DiegoOstuni 0:75fc82583a41 564 }
DiegoOstuni 0:75fc82583a41 565
DiegoOstuni 0:75fc82583a41 566
DiegoOstuni 0:75fc82583a41 567 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 568 static ReturnCode nfcipDEPControlMsg( uint8_t pfb, uint8_t RTOX, SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 )
DiegoOstuni 0:75fc82583a41 569 {
DiegoOstuni 0:75fc82583a41 570 uint8_t ctrlMsg[20];
DiegoOstuni 0:75fc82583a41 571 rfalNfcDepCmd depCmd;
DiegoOstuni 0:75fc82583a41 572 uint32_t fwt;
DiegoOstuni 0:75fc82583a41 573
DiegoOstuni 0:75fc82583a41 574 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 575 /* Calculate Cmd and fwt to be used */
DiegoOstuni 0:75fc82583a41 576 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 577 depCmd = ((gNfcip.cfg.role == RFAL_NFCDEP_ROLE_TARGET) ? NFCIP_CMD_DEP_RES : NFCIP_CMD_DEP_REQ);
DiegoOstuni 0:75fc82583a41 578 fwt = ((gNfcip.cfg.role == RFAL_NFCDEP_ROLE_TARGET) ? NFCIP_NO_FWT : (nfcip_PFBisSTO( pfb ) ? ( (RTOX*gNfcip.cfg.fwt) + gNfcip.cfg.dFwt) : (gNfcip.cfg.fwt + gNfcip.cfg.dFwt) ) );
DiegoOstuni 0:75fc82583a41 579
DiegoOstuni 0:75fc82583a41 580 if( nfcip_PFBisSTO( pfb ) )
DiegoOstuni 0:75fc82583a41 581 {
DiegoOstuni 0:75fc82583a41 582 return nfcipTx( depCmd, ctrlMsg, &RTOX, sizeof(RTOX), pfb, fwt, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ;
DiegoOstuni 0:75fc82583a41 583 }
DiegoOstuni 0:75fc82583a41 584 else
DiegoOstuni 0:75fc82583a41 585 {
DiegoOstuni 0:75fc82583a41 586 return nfcipTx( depCmd, ctrlMsg, 0, 0, pfb, fwt, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ;
DiegoOstuni 0:75fc82583a41 587 }
DiegoOstuni 0:75fc82583a41 588 }
DiegoOstuni 0:75fc82583a41 589
DiegoOstuni 0:75fc82583a41 590 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 591 static void nfcipClearCounters( void )
DiegoOstuni 0:75fc82583a41 592 {
DiegoOstuni 0:75fc82583a41 593 gNfcip.cntATNRetrys = 0;
DiegoOstuni 0:75fc82583a41 594 gNfcip.cntNACKRetrys = 0;
DiegoOstuni 0:75fc82583a41 595 gNfcip.cntTORetrys = 0;
DiegoOstuni 0:75fc82583a41 596 gNfcip.cntTxRetrys = 0;
DiegoOstuni 0:75fc82583a41 597 gNfcip.cntRTOXRetrys = 0;
DiegoOstuni 0:75fc82583a41 598 }
DiegoOstuni 0:75fc82583a41 599
DiegoOstuni 0:75fc82583a41 600 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 601 static ReturnCode nfcipInitiatorHandleDEP( ReturnCode rxRes, uint16_t rxLen, uint16_t *outActRxLen, bool *outIsChaining, SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 )
DiegoOstuni 0:75fc82583a41 602 {
DiegoOstuni 0:75fc82583a41 603 ReturnCode ret;
DiegoOstuni 0:75fc82583a41 604 uint8_t nfcDepLen;
DiegoOstuni 0:75fc82583a41 605 uint8_t rxMsgIt;
DiegoOstuni 0:75fc82583a41 606 uint8_t rxPFB;
DiegoOstuni 0:75fc82583a41 607 uint8_t rxRTOX;
DiegoOstuni 0:75fc82583a41 608 uint8_t optHdrLen;
DiegoOstuni 0:75fc82583a41 609
DiegoOstuni 0:75fc82583a41 610 ret = ERR_INTERNAL;
DiegoOstuni 0:75fc82583a41 611 rxMsgIt = 0;
DiegoOstuni 0:75fc82583a41 612 optHdrLen = 0;
DiegoOstuni 0:75fc82583a41 613
DiegoOstuni 0:75fc82583a41 614 *outActRxLen = 0;
DiegoOstuni 0:75fc82583a41 615 *outIsChaining = false;
DiegoOstuni 0:75fc82583a41 616
DiegoOstuni 0:75fc82583a41 617
DiegoOstuni 0:75fc82583a41 618 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 619 /* Handle reception errors */
DiegoOstuni 0:75fc82583a41 620 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 621 switch( rxRes )
DiegoOstuni 0:75fc82583a41 622 {
DiegoOstuni 0:75fc82583a41 623 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 624 /* Timeout -> Digital 1.0 14.15.5.6 */
DiegoOstuni 0:75fc82583a41 625 case ERR_TIMEOUT:
DiegoOstuni 0:75fc82583a41 626
DiegoOstuni 0:75fc82583a41 627 nfcipLogI( " NFCIP(I) TIMEOUT TORetrys:%d \r\n", gNfcip.cntTORetrys );
DiegoOstuni 0:75fc82583a41 628
DiegoOstuni 0:75fc82583a41 629 /* Digital 1.0 14.15.5.6 - If nTO >= Max raise protocol error */
DiegoOstuni 0:75fc82583a41 630 if( gNfcip.cntTORetrys++ >= NFCIP_MAX_TO_RETRYS )
DiegoOstuni 0:75fc82583a41 631 {
DiegoOstuni 0:75fc82583a41 632 return ERR_PROTO;
DiegoOstuni 0:75fc82583a41 633 }
DiegoOstuni 0:75fc82583a41 634
DiegoOstuni 0:75fc82583a41 635 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 636 /* Upon Timeout error, if Deactivation is pending, no more error recovery
DiegoOstuni 0:75fc82583a41 637 * will be done #54.
DiegoOstuni 0:75fc82583a41 638 * This is used to address the issue some devices that havea big TO.
DiegoOstuni 0:75fc82583a41 639 * Normally LLCP layer has timeout already, and NFCIP layer is still
DiegoOstuni 0:75fc82583a41 640 * running error handling, retrying ATN/NACKs */
DiegoOstuni 0:75fc82583a41 641 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 642 if( nfcipIsDeactivationPending() )
DiegoOstuni 0:75fc82583a41 643 {
DiegoOstuni 0:75fc82583a41 644 nfcipLogI( " skipping error recovery due deactivation pending \r\n");
DiegoOstuni 0:75fc82583a41 645 return ERR_TIMEOUT;
DiegoOstuni 0:75fc82583a41 646 }
DiegoOstuni 0:75fc82583a41 647
DiegoOstuni 0:75fc82583a41 648 /* Digital 1.0 14.15.5.6 1) If last PDU was NACK */
DiegoOstuni 0:75fc82583a41 649 if( nfcip_PFBisRNACK(gNfcip.lastPFB) )
DiegoOstuni 0:75fc82583a41 650 {
DiegoOstuni 0:75fc82583a41 651 /* Digital 1.0 14.15.5.6 2) if NACKs failed raise protocol error */
DiegoOstuni 0:75fc82583a41 652 if( gNfcip.cntNACKRetrys++ >= NFCIP_MAX_NACK_RETRYS )
DiegoOstuni 0:75fc82583a41 653 {
DiegoOstuni 0:75fc82583a41 654 return ERR_PROTO;
DiegoOstuni 0:75fc82583a41 655 }
DiegoOstuni 0:75fc82583a41 656
DiegoOstuni 0:75fc82583a41 657 /* Send NACK */
DiegoOstuni 0:75fc82583a41 658 nfcipLogI( " NFCIP(I) Sending NACK retry: %d \r\n", gNfcip.cntNACKRetrys );
DiegoOstuni 0:75fc82583a41 659 EXIT_ON_ERR( ret, nfcipDEPControlMsg( nfcip_PFBRPDU_NACK(gNfcip.pni), 0, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) );
DiegoOstuni 0:75fc82583a41 660 return ERR_BUSY;
DiegoOstuni 0:75fc82583a41 661 }
DiegoOstuni 0:75fc82583a41 662
DiegoOstuni 0:75fc82583a41 663 nfcipLogI( " NFCIP(I) Checking if to send ATN ATNRetrys: %d \r\n", gNfcip.cntATNRetrys );
DiegoOstuni 0:75fc82583a41 664
DiegoOstuni 0:75fc82583a41 665 /* Digital 1.0 14.15.5.6 3) Otherwise send ATN */
DiegoOstuni 0:75fc82583a41 666 if( gNfcip.cntATNRetrys++ >= NFCIP_MAX_NACK_RETRYS )
DiegoOstuni 0:75fc82583a41 667 {
DiegoOstuni 0:75fc82583a41 668 return ERR_PROTO;
DiegoOstuni 0:75fc82583a41 669 }
DiegoOstuni 0:75fc82583a41 670
DiegoOstuni 0:75fc82583a41 671 /* Send ATN */
DiegoOstuni 0:75fc82583a41 672 nfcipLogI( " NFCIP(I) Sending ATN \r\n" );
DiegoOstuni 0:75fc82583a41 673 EXIT_ON_ERR( ret, nfcipDEPControlMsg( nfcip_PFBSPDU_ATN(), 0, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) );
DiegoOstuni 0:75fc82583a41 674 return ERR_BUSY;
DiegoOstuni 0:75fc82583a41 675
DiegoOstuni 0:75fc82583a41 676 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 677 /* Data rcvd with error -> Digital 1.0 14.12.5.4 */
DiegoOstuni 0:75fc82583a41 678 case ERR_CRC:
DiegoOstuni 0:75fc82583a41 679 case ERR_PAR:
DiegoOstuni 0:75fc82583a41 680 case ERR_FRAMING:
DiegoOstuni 0:75fc82583a41 681 case ERR_RF_COLLISION:
DiegoOstuni 0:75fc82583a41 682
DiegoOstuni 0:75fc82583a41 683 nfcipLogI( " NFCIP(I) rx Error: %d \r\n", rxRes );
DiegoOstuni 0:75fc82583a41 684
DiegoOstuni 0:75fc82583a41 685 /* Digital 1.0 14.12.5.4 Tx Error with data, ignore */
DiegoOstuni 0:75fc82583a41 686 if( rxLen < NFCIP_MIN_TXERROR_LEN )
DiegoOstuni 0:75fc82583a41 687 {
DiegoOstuni 0:75fc82583a41 688 nfcipLogI( " NFCIP(I) Transmission error w data \r\n" );
DiegoOstuni 0:75fc82583a41 689 #if 0
DiegoOstuni 0:75fc82583a41 690 if(gNfcip.cfg.commMode == RFAL_NFCDEP_COMM_PASSIVE)
DiegoOstuni 0:75fc82583a41 691 {
DiegoOstuni 0:75fc82583a41 692 nfcipLogI( " NFCIP(I) Transmission error w data -> reEnabling Rx \r\n" );
DiegoOstuni 0:75fc82583a41 693 nfcipReEnableRxTout( NFCIP_TRECOV );
DiegoOstuni 0:75fc82583a41 694 return ERR_BUSY;
DiegoOstuni 0:75fc82583a41 695 }
DiegoOstuni 0:75fc82583a41 696 #endif /* 0 */
DiegoOstuni 0:75fc82583a41 697 }
DiegoOstuni 0:75fc82583a41 698
DiegoOstuni 0:75fc82583a41 699 /* Digital 1.1 16.12.5.4 if NACKs failed raise Transmission error */
DiegoOstuni 0:75fc82583a41 700 if( gNfcip.cntNACKRetrys++ >= NFCIP_MAX_NACK_RETRYS )
DiegoOstuni 0:75fc82583a41 701 {
DiegoOstuni 0:75fc82583a41 702 return ERR_FRAMING;
DiegoOstuni 0:75fc82583a41 703 }
DiegoOstuni 0:75fc82583a41 704
DiegoOstuni 0:75fc82583a41 705 /* Send NACK */
DiegoOstuni 0:75fc82583a41 706 nfcipLogI( " NFCIP(I) Sending NACK \r\n" );
DiegoOstuni 0:75fc82583a41 707 EXIT_ON_ERR( ret, nfcipDEPControlMsg( nfcip_PFBRPDU_NACK(gNfcip.pni), 0, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) );
DiegoOstuni 0:75fc82583a41 708 return ERR_BUSY;
DiegoOstuni 0:75fc82583a41 709
DiegoOstuni 0:75fc82583a41 710 case ERR_NONE:
DiegoOstuni 0:75fc82583a41 711 break;
DiegoOstuni 0:75fc82583a41 712
DiegoOstuni 0:75fc82583a41 713 case ERR_BUSY:
DiegoOstuni 0:75fc82583a41 714 return ERR_BUSY; /* Debug purposes */
DiegoOstuni 0:75fc82583a41 715
DiegoOstuni 0:75fc82583a41 716 default:
DiegoOstuni 0:75fc82583a41 717 nfcipLogW( " NFCIP(I) Error: %d \r\n", rxRes );
DiegoOstuni 0:75fc82583a41 718 return rxRes;
DiegoOstuni 0:75fc82583a41 719 }
DiegoOstuni 0:75fc82583a41 720
DiegoOstuni 0:75fc82583a41 721 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 722 /* Rx OK check if valid DEP PDU */
DiegoOstuni 0:75fc82583a41 723 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 724
DiegoOstuni 0:75fc82583a41 725 /* Due to different modes on ST25R391x (with/without CRC) use NFC-DEP LEN instead of bytes retrieved */
DiegoOstuni 0:75fc82583a41 726 nfcDepLen = gNfcip.rxBuf[rxMsgIt++];
DiegoOstuni 0:75fc82583a41 727
DiegoOstuni 0:75fc82583a41 728 nfcipLogD( " NFCIP(I) rx OK: %d bytes \r\n", nfcDepLen );
DiegoOstuni 0:75fc82583a41 729
DiegoOstuni 0:75fc82583a41 730 /* Digital 1.0 14.15.5.5 Protocol Error */
DiegoOstuni 0:75fc82583a41 731 if( gNfcip.rxBuf[rxMsgIt++] != NFCIP_RES )
DiegoOstuni 0:75fc82583a41 732 {
DiegoOstuni 0:75fc82583a41 733 nfcipLogW( " NFCIP(I) error %02X instead of %02X \r\n", gNfcip.rxBuf[--rxMsgIt], NFCIP_RES );
DiegoOstuni 0:75fc82583a41 734 return ERR_PROTO;
DiegoOstuni 0:75fc82583a41 735 }
DiegoOstuni 0:75fc82583a41 736
DiegoOstuni 0:75fc82583a41 737 /* Digital 1.0 14.15.5.5 Protocol Error */
DiegoOstuni 0:75fc82583a41 738 if( gNfcip.rxBuf[rxMsgIt++] != NFCIP_CMD_DEP_RES )
DiegoOstuni 0:75fc82583a41 739 {
DiegoOstuni 0:75fc82583a41 740 nfcipLogW( " NFCIP(I) error %02X instead of %02X \r\n", gNfcip.rxBuf[--rxMsgIt], NFCIP_CMD_DEP_RES );
DiegoOstuni 0:75fc82583a41 741 return ERR_PROTO;
DiegoOstuni 0:75fc82583a41 742 }
DiegoOstuni 0:75fc82583a41 743
DiegoOstuni 0:75fc82583a41 744 rxPFB = gNfcip.rxBuf[rxMsgIt++];
DiegoOstuni 0:75fc82583a41 745
DiegoOstuni 0:75fc82583a41 746 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 747 /* Check for valid PFB type */
DiegoOstuni 0:75fc82583a41 748 if( !(nfcip_PFBisSPDU( rxPFB ) || nfcip_PFBisRPDU( rxPFB ) || nfcip_PFBisIPDU( rxPFB )) )
DiegoOstuni 0:75fc82583a41 749 {
DiegoOstuni 0:75fc82583a41 750 return ERR_PROTO;
DiegoOstuni 0:75fc82583a41 751 }
DiegoOstuni 0:75fc82583a41 752
DiegoOstuni 0:75fc82583a41 753 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 754 /* Digital 1.0 14.8.2.1 check if DID is expected and match -> Protocol Error */
DiegoOstuni 0:75fc82583a41 755 if( gNfcip.cfg.did != RFAL_NFCDEP_DID_NO )
DiegoOstuni 0:75fc82583a41 756 {
DiegoOstuni 0:75fc82583a41 757 if( !nfcip_PFBhasDID( rxPFB ) || gNfcip.rxBuf[rxMsgIt++] != gNfcip.cfg.did )
DiegoOstuni 0:75fc82583a41 758 {
DiegoOstuni 0:75fc82583a41 759 return ERR_PROTO;
DiegoOstuni 0:75fc82583a41 760 }
DiegoOstuni 0:75fc82583a41 761 optHdrLen++; /* Inc header optional field cnt*/
DiegoOstuni 0:75fc82583a41 762 }
DiegoOstuni 0:75fc82583a41 763 else if( nfcip_PFBhasDID( rxPFB ) ) /* DID not expected but rcv */
DiegoOstuni 0:75fc82583a41 764 {
DiegoOstuni 0:75fc82583a41 765 return ERR_PROTO;
DiegoOstuni 0:75fc82583a41 766 }
DiegoOstuni 0:75fc82583a41 767
DiegoOstuni 0:75fc82583a41 768 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 769 /* Digital 1.0 14.6.2.8 & 14.6.3.11 NAD must not be used */
DiegoOstuni 0:75fc82583a41 770 if( gNfcip.cfg.nad != RFAL_NFCDEP_NAD_NO )
DiegoOstuni 0:75fc82583a41 771 {
DiegoOstuni 0:75fc82583a41 772 if( !nfcip_PFBhasNAD( rxPFB ) || gNfcip.rxBuf[rxMsgIt++] != gNfcip.cfg.nad )
DiegoOstuni 0:75fc82583a41 773 {
DiegoOstuni 0:75fc82583a41 774 return ERR_PROTO;
DiegoOstuni 0:75fc82583a41 775 }
DiegoOstuni 0:75fc82583a41 776 optHdrLen++; /* Inc header optional field cnt*/
DiegoOstuni 0:75fc82583a41 777 }
DiegoOstuni 0:75fc82583a41 778 else if( nfcip_PFBhasNAD( rxPFB ) ) /* NAD not expected but rcv */
DiegoOstuni 0:75fc82583a41 779 {
DiegoOstuni 0:75fc82583a41 780 return ERR_PROTO;
DiegoOstuni 0:75fc82583a41 781 }
DiegoOstuni 0:75fc82583a41 782
DiegoOstuni 0:75fc82583a41 783 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 784 /* Process R-PDU */
DiegoOstuni 0:75fc82583a41 785 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 786 if( nfcip_PFBisRPDU( rxPFB ) )
DiegoOstuni 0:75fc82583a41 787 {
DiegoOstuni 0:75fc82583a41 788 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 789 /* R ACK */
DiegoOstuni 0:75fc82583a41 790 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 791 if( nfcip_PFBisRACK( rxPFB ) )
DiegoOstuni 0:75fc82583a41 792 {
DiegoOstuni 0:75fc82583a41 793 nfcipLogI( " NFCIP(I) Rcvd ACK \r\n" );
DiegoOstuni 0:75fc82583a41 794 if( gNfcip.pni == nfcip_PBF_PNI( rxPFB ) )
DiegoOstuni 0:75fc82583a41 795 {
DiegoOstuni 0:75fc82583a41 796 /* 14.12.3.3 R-ACK with correct PNI -> Increment */
DiegoOstuni 0:75fc82583a41 797 gNfcip.pni = nfcip_PNIInc( gNfcip.pni );
DiegoOstuni 0:75fc82583a41 798
DiegoOstuni 0:75fc82583a41 799 /* R-ACK while not performing chaining -> Protocol error*/
DiegoOstuni 0:75fc82583a41 800 if( !gNfcip.isTxChaining )
DiegoOstuni 0:75fc82583a41 801 {
DiegoOstuni 0:75fc82583a41 802 return ERR_PROTO;
DiegoOstuni 0:75fc82583a41 803 }
DiegoOstuni 0:75fc82583a41 804
DiegoOstuni 0:75fc82583a41 805 nfcipClearCounters();
DiegoOstuni 0:75fc82583a41 806 gNfcip.state = NFCIP_ST_INIT_DEP_IDLE;
DiegoOstuni 0:75fc82583a41 807 return ERR_NONE; /* This block has been transmitted */
DiegoOstuni 0:75fc82583a41 808 }
DiegoOstuni 0:75fc82583a41 809 else /* Digital 1.0 14.12.4.5 ACK with wrong PNI Initiator may retransmit */
DiegoOstuni 0:75fc82583a41 810 {
DiegoOstuni 0:75fc82583a41 811 if( gNfcip.cntTxRetrys++ >= NFCIP_MAX_TX_RETRYS )
DiegoOstuni 0:75fc82583a41 812 {
DiegoOstuni 0:75fc82583a41 813 return ERR_PROTO;
DiegoOstuni 0:75fc82583a41 814 }
DiegoOstuni 0:75fc82583a41 815
DiegoOstuni 0:75fc82583a41 816 /* Extended the MAY in Digital 1.0 14.12.4.5 to only reTransmit if the ACK
DiegoOstuni 0:75fc82583a41 817 * is for the previous DEP, otherwise raise Protocol immediately
DiegoOstuni 0:75fc82583a41 818 * If the PNI difference is more than 1 it`s worthless to reTransmit 3x
DiegoOstuni 0:75fc82583a41 819 * and after raise the error */
DiegoOstuni 0:75fc82583a41 820
DiegoOstuni 0:75fc82583a41 821 if( nfcip_PNIDec( gNfcip.pni ) == nfcip_PBF_PNI( rxPFB ) )
DiegoOstuni 0:75fc82583a41 822 {
DiegoOstuni 0:75fc82583a41 823 /* ReTransmit */
DiegoOstuni 0:75fc82583a41 824 nfcipLogI( " NFCIP(I) Rcvd ACK prev PNI -> reTx \r\n" );
DiegoOstuni 0:75fc82583a41 825 gNfcip.state = NFCIP_ST_INIT_DEP_TX;
DiegoOstuni 0:75fc82583a41 826 return ERR_BUSY;
DiegoOstuni 0:75fc82583a41 827 }
DiegoOstuni 0:75fc82583a41 828
DiegoOstuni 0:75fc82583a41 829 nfcipLogI( " NFCIP(I) Rcvd ACK unexpected far PNI -> Error \r\n" );
DiegoOstuni 0:75fc82583a41 830 return ERR_PROTO;
DiegoOstuni 0:75fc82583a41 831 }
DiegoOstuni 0:75fc82583a41 832 }
DiegoOstuni 0:75fc82583a41 833 else /* Digital 1.0 - 14.12.5.2 Target must never send NACK */
DiegoOstuni 0:75fc82583a41 834 {
DiegoOstuni 0:75fc82583a41 835 return ERR_PROTO;
DiegoOstuni 0:75fc82583a41 836 }
DiegoOstuni 0:75fc82583a41 837 }
DiegoOstuni 0:75fc82583a41 838
DiegoOstuni 0:75fc82583a41 839 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 840 /* Process S-PDU */
DiegoOstuni 0:75fc82583a41 841 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 842 if( nfcip_PFBisSPDU( rxPFB ) )
DiegoOstuni 0:75fc82583a41 843 {
DiegoOstuni 0:75fc82583a41 844 nfcipLogI( " NFCIP(I) Rcvd S-PDU \r\n" );
DiegoOstuni 0:75fc82583a41 845 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 846 /* S ATN */
DiegoOstuni 0:75fc82583a41 847 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 848 if( nfcip_PFBisSATN( rxPFB ) ) /* If is a S-ATN */
DiegoOstuni 0:75fc82583a41 849 {
DiegoOstuni 0:75fc82583a41 850 nfcipLogI( " NFCIP(I) Rcvd ATN \r\n" );
DiegoOstuni 0:75fc82583a41 851 if( nfcip_PFBisSATN( gNfcip.lastPFB ) ) /* Check if is expected */
DiegoOstuni 0:75fc82583a41 852 {
DiegoOstuni 0:75fc82583a41 853 gNfcip.cntATNRetrys = 0; /* Clear ATN counter */
DiegoOstuni 0:75fc82583a41 854
DiegoOstuni 0:75fc82583a41 855 /* Although spec is not clear NFC Forum Digital test is expecting to
DiegoOstuni 0:75fc82583a41 856 * retransmit upon receiving ATN_RES */
DiegoOstuni 0:75fc82583a41 857 if( nfcip_PFBisSTO( gNfcip.lastPFBnATN ) )
DiegoOstuni 0:75fc82583a41 858 {
DiegoOstuni 0:75fc82583a41 859 nfcipLogI( " NFCIP(I) Rcvd ATN -> reTx RTOX_RES \r\n" );
DiegoOstuni 0:75fc82583a41 860 EXIT_ON_ERR( ret, nfcipDEPControlMsg( nfcip_PFBSPDU_TO(), gNfcip.lastRTOX, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) );
DiegoOstuni 0:75fc82583a41 861 }
DiegoOstuni 0:75fc82583a41 862 else
DiegoOstuni 0:75fc82583a41 863 {
DiegoOstuni 0:75fc82583a41 864 /* ReTransmit ? */
DiegoOstuni 0:75fc82583a41 865 if( gNfcip.cntTxRetrys++ >= NFCIP_MAX_TX_RETRYS )
DiegoOstuni 0:75fc82583a41 866 {
DiegoOstuni 0:75fc82583a41 867 return ERR_PROTO;
DiegoOstuni 0:75fc82583a41 868 }
DiegoOstuni 0:75fc82583a41 869
DiegoOstuni 0:75fc82583a41 870 nfcipLogI( " NFCIP(I) Rcvd ATN -> reTx PNI: %d \r\n", gNfcip.pni );
DiegoOstuni 0:75fc82583a41 871 gNfcip.state = NFCIP_ST_INIT_DEP_TX;
DiegoOstuni 0:75fc82583a41 872 }
DiegoOstuni 0:75fc82583a41 873
DiegoOstuni 0:75fc82583a41 874 return ERR_BUSY;
DiegoOstuni 0:75fc82583a41 875 }
DiegoOstuni 0:75fc82583a41 876 else /* Digital 1.0 14.12.4.4 & 14.12.4.8 */
DiegoOstuni 0:75fc82583a41 877 {
DiegoOstuni 0:75fc82583a41 878 return ERR_PROTO;
DiegoOstuni 0:75fc82583a41 879 }
DiegoOstuni 0:75fc82583a41 880 }
DiegoOstuni 0:75fc82583a41 881 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 882 /* S TO */
DiegoOstuni 0:75fc82583a41 883 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 884 else if( nfcip_PFBisSTO( rxPFB ) ) /* If is a S-TO (RTOX) */
DiegoOstuni 0:75fc82583a41 885 {
DiegoOstuni 0:75fc82583a41 886 nfcipLogI( " NFCIP(I) Rcvd TO \r\n" );
DiegoOstuni 0:75fc82583a41 887
DiegoOstuni 0:75fc82583a41 888 rxRTOX = gNfcip.rxBuf[rxMsgIt++];
DiegoOstuni 0:75fc82583a41 889
DiegoOstuni 0:75fc82583a41 890 /* Digital 1.1 16.12.4.3 - Initiator MAY stop accepting subsequent RTOX Req *
DiegoOstuni 0:75fc82583a41 891 * - RTOX request to an ATN -> Protocol error */
DiegoOstuni 0:75fc82583a41 892 if( (gNfcip.cntRTOXRetrys++ > NFCIP_MAX_RTOX_RETRYS) || nfcip_PFBisSATN( gNfcip.lastPFB ) )
DiegoOstuni 0:75fc82583a41 893 {
DiegoOstuni 0:75fc82583a41 894 return ERR_PROTO;
DiegoOstuni 0:75fc82583a41 895 }
DiegoOstuni 0:75fc82583a41 896
DiegoOstuni 0:75fc82583a41 897 /* Digital 1.1 16.8.4.1 RTOX must be between [1,59] */
DiegoOstuni 0:75fc82583a41 898 if( (rxRTOX < NFCIP_INIT_MIN_RTOX) || (rxRTOX > NFCIP_INIT_MAX_RTOX) )
DiegoOstuni 0:75fc82583a41 899 {
DiegoOstuni 0:75fc82583a41 900 return ERR_PROTO;
DiegoOstuni 0:75fc82583a41 901 }
DiegoOstuni 0:75fc82583a41 902
DiegoOstuni 0:75fc82583a41 903 EXIT_ON_ERR( ret, nfcipDEPControlMsg( nfcip_PFBSPDU_TO(), rxRTOX, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) );
DiegoOstuni 0:75fc82583a41 904 gNfcip.lastRTOX = rxRTOX;
DiegoOstuni 0:75fc82583a41 905
DiegoOstuni 0:75fc82583a41 906 return ERR_BUSY;
DiegoOstuni 0:75fc82583a41 907 }
DiegoOstuni 0:75fc82583a41 908
DiegoOstuni 0:75fc82583a41 909 /* Unexpected S-PDU */
DiegoOstuni 0:75fc82583a41 910 return ERR_PROTO;
DiegoOstuni 0:75fc82583a41 911 }
DiegoOstuni 0:75fc82583a41 912
DiegoOstuni 0:75fc82583a41 913 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 914 /* Process I-PDU */
DiegoOstuni 0:75fc82583a41 915 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 916 if( nfcip_PFBisIPDU( rxPFB ) )
DiegoOstuni 0:75fc82583a41 917 {
DiegoOstuni 0:75fc82583a41 918 if( gNfcip.pni != nfcip_PBF_PNI( rxPFB ) )
DiegoOstuni 0:75fc82583a41 919 {
DiegoOstuni 0:75fc82583a41 920 nfcipLogI( " NFCIP(I) Rcvd IPDU wrong PNI curPNI: %d rxPNI: %d \r\n", gNfcip.pni , nfcip_PBF_PNI( rxPFB ) );
DiegoOstuni 0:75fc82583a41 921 return ERR_PROTO;
DiegoOstuni 0:75fc82583a41 922 }
DiegoOstuni 0:75fc82583a41 923
DiegoOstuni 0:75fc82583a41 924 nfcipLogD( " NFCIP(I) Rcvd IPDU OK PNI: %d \r\n", gNfcip.pni );
DiegoOstuni 0:75fc82583a41 925
DiegoOstuni 0:75fc82583a41 926 /* 14.12.3.3 I-PDU with correct PNI -> Increment */
DiegoOstuni 0:75fc82583a41 927 gNfcip.pni = nfcip_PNIInc( gNfcip.pni );
DiegoOstuni 0:75fc82583a41 928
DiegoOstuni 0:75fc82583a41 929
DiegoOstuni 0:75fc82583a41 930 /* Successful data Exchange */
DiegoOstuni 0:75fc82583a41 931 nfcipClearCounters();
DiegoOstuni 0:75fc82583a41 932 *outActRxLen = (nfcDepLen - RFAL_NFCDEP_DEP_HEADER - optHdrLen);
DiegoOstuni 0:75fc82583a41 933
DiegoOstuni 0:75fc82583a41 934 if( (gNfcip.rxBuf + gNfcip.rxBufPaylPos) != (gNfcip.rxBuf + RFAL_NFCDEP_DEP_HEADER + optHdrLen) )
DiegoOstuni 0:75fc82583a41 935 {
DiegoOstuni 0:75fc82583a41 936 ST_MEMMOVE( (gNfcip.rxBuf + gNfcip.rxBufPaylPos), (gNfcip.rxBuf + RFAL_NFCDEP_DEP_HEADER + optHdrLen), *outActRxLen );
DiegoOstuni 0:75fc82583a41 937 }
DiegoOstuni 0:75fc82583a41 938
DiegoOstuni 0:75fc82583a41 939 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 940 /* Check if target is indicating chaining MI */
DiegoOstuni 0:75fc82583a41 941 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 942 if( nfcip_PFBisIMI( rxPFB ) )
DiegoOstuni 0:75fc82583a41 943 {
DiegoOstuni 0:75fc82583a41 944 gNfcip.isRxChaining = true;
DiegoOstuni 0:75fc82583a41 945 *outIsChaining = true;
DiegoOstuni 0:75fc82583a41 946
DiegoOstuni 0:75fc82583a41 947 nfcipLogD( " NFCIP(I) Rcvd IPDU OK w MI -> ACK \r\n" );
DiegoOstuni 0:75fc82583a41 948 EXIT_ON_ERR( ret, nfcipDEPControlMsg( nfcip_PFBRPDU_ACK( gNfcip.pni ), gNfcip.rxBuf[rxMsgIt++], mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) );
DiegoOstuni 0:75fc82583a41 949
DiegoOstuni 0:75fc82583a41 950 return ERR_AGAIN; /* Send Again signalling to run again, but some chaining data has arrived*/
DiegoOstuni 0:75fc82583a41 951 }
DiegoOstuni 0:75fc82583a41 952 else
DiegoOstuni 0:75fc82583a41 953 {
DiegoOstuni 0:75fc82583a41 954 gNfcip.isRxChaining = false;
DiegoOstuni 0:75fc82583a41 955 gNfcip.state = NFCIP_ST_INIT_DEP_IDLE;
DiegoOstuni 0:75fc82583a41 956
DiegoOstuni 0:75fc82583a41 957 return ERR_NONE; /* Data exchange done */
DiegoOstuni 0:75fc82583a41 958 }
DiegoOstuni 0:75fc82583a41 959 }
DiegoOstuni 0:75fc82583a41 960 return ret;
DiegoOstuni 0:75fc82583a41 961 }
DiegoOstuni 0:75fc82583a41 962
DiegoOstuni 0:75fc82583a41 963
DiegoOstuni 0:75fc82583a41 964 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 965 static ReturnCode nfcipTargetHandleRX( ReturnCode rxRes, uint16_t *outActRxLen, bool *outIsChaining, SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 )
DiegoOstuni 0:75fc82583a41 966 {
DiegoOstuni 0:75fc82583a41 967 ReturnCode ret;
DiegoOstuni 0:75fc82583a41 968 uint8_t nfcDepLen;
DiegoOstuni 0:75fc82583a41 969 uint8_t rxMsgIt;
DiegoOstuni 0:75fc82583a41 970 uint8_t rxPFB;
DiegoOstuni 0:75fc82583a41 971 uint8_t optHdrLen;
DiegoOstuni 0:75fc82583a41 972 uint8_t resBuf[NFCIP_TARGET_RES_MAX];
DiegoOstuni 0:75fc82583a41 973
DiegoOstuni 0:75fc82583a41 974
DiegoOstuni 0:75fc82583a41 975 ret = ERR_INTERNAL;
DiegoOstuni 0:75fc82583a41 976 rxMsgIt = 0;
DiegoOstuni 0:75fc82583a41 977 optHdrLen = 0;
DiegoOstuni 0:75fc82583a41 978
DiegoOstuni 0:75fc82583a41 979 *outActRxLen = 0;
DiegoOstuni 0:75fc82583a41 980 *outIsChaining = false;
DiegoOstuni 0:75fc82583a41 981
DiegoOstuni 0:75fc82583a41 982
DiegoOstuni 0:75fc82583a41 983 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 984 /* Handle reception errors */
DiegoOstuni 0:75fc82583a41 985 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 986 switch( rxRes )
DiegoOstuni 0:75fc82583a41 987 {
DiegoOstuni 0:75fc82583a41 988 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 989 case ERR_NONE:
DiegoOstuni 0:75fc82583a41 990 break;
DiegoOstuni 0:75fc82583a41 991
DiegoOstuni 0:75fc82583a41 992 case ERR_TIMEOUT:
DiegoOstuni 0:75fc82583a41 993 case ERR_CRC:
DiegoOstuni 0:75fc82583a41 994 case ERR_PAR:
DiegoOstuni 0:75fc82583a41 995 case ERR_FRAMING:
DiegoOstuni 0:75fc82583a41 996 case ERR_PROTO:
DiegoOstuni 0:75fc82583a41 997 default:
DiegoOstuni 0:75fc82583a41 998 /* Digital 1.1 16.12.5.2 The Target MUST NOT attempt any error recovery. *
DiegoOstuni 0:75fc82583a41 999 * The Target MUST always stay in receive mode when a *
DiegoOstuni 0:75fc82583a41 1000 * Transmission Error or a Protocol Error occurs. *
DiegoOstuni 0:75fc82583a41 1001 * *
DiegoOstuni 0:75fc82583a41 1002 * Do not push Transmission/Protocol Errors to upper layer in Listen Mode #766 */
DiegoOstuni 0:75fc82583a41 1003
DiegoOstuni 0:75fc82583a41 1004 nfcDepReEnableRx( gNfcip.rxBuf, gNfcip.rxBufLen, gNfcip.rxRcvdLen );
DiegoOstuni 0:75fc82583a41 1005 return ERR_BUSY;
DiegoOstuni 0:75fc82583a41 1006
DiegoOstuni 0:75fc82583a41 1007 case ERR_LINK_LOSS:
DiegoOstuni 0:75fc82583a41 1008 nfcipLogW( " NFCIP(T) Error: %d \r\n", rxRes );
DiegoOstuni 0:75fc82583a41 1009 return rxRes;
DiegoOstuni 0:75fc82583a41 1010
DiegoOstuni 0:75fc82583a41 1011 case ERR_BUSY:
DiegoOstuni 0:75fc82583a41 1012 return ERR_BUSY; /* Debug purposes */
DiegoOstuni 0:75fc82583a41 1013
DiegoOstuni 0:75fc82583a41 1014 }
DiegoOstuni 0:75fc82583a41 1015
DiegoOstuni 0:75fc82583a41 1016 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 1017 /* Rx OK check if valid DEP PDU */
DiegoOstuni 0:75fc82583a41 1018 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 1019
DiegoOstuni 0:75fc82583a41 1020 /* Due to different modes on ST25R391x (with/without CRC) use NFC-DEP LEN instead of bytes retrieved */
DiegoOstuni 0:75fc82583a41 1021 nfcDepLen = gNfcip.rxBuf[rxMsgIt++];
DiegoOstuni 0:75fc82583a41 1022
DiegoOstuni 0:75fc82583a41 1023 nfcipLogD( " NFCIP(T) rx OK: %d bytes \r\n", nfcDepLen );
DiegoOstuni 0:75fc82583a41 1024
DiegoOstuni 0:75fc82583a41 1025 if( gNfcip.rxBuf[rxMsgIt++] != NFCIP_REQ )
DiegoOstuni 0:75fc82583a41 1026 {
DiegoOstuni 0:75fc82583a41 1027 nfcDepReEnableRx( gNfcip.rxBuf, gNfcip.rxBufLen, gNfcip.rxRcvdLen );
DiegoOstuni 0:75fc82583a41 1028 return ERR_BUSY; /* ERR_PROTO - Ignore bad request */
DiegoOstuni 0:75fc82583a41 1029 }
DiegoOstuni 0:75fc82583a41 1030
DiegoOstuni 0:75fc82583a41 1031
DiegoOstuni 0:75fc82583a41 1032 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 1033 /* Check whether target rcvd a normal DEP or deactivation request */
DiegoOstuni 0:75fc82583a41 1034 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 1035 switch( gNfcip.rxBuf[rxMsgIt++] )
DiegoOstuni 0:75fc82583a41 1036 {
DiegoOstuni 0:75fc82583a41 1037 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 1038 case NFCIP_CMD_DEP_REQ:
DiegoOstuni 0:75fc82583a41 1039 break; /* Continue to normal DEP processing */
DiegoOstuni 0:75fc82583a41 1040
DiegoOstuni 0:75fc82583a41 1041 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 1042 case NFCIP_CMD_DSL_REQ:
DiegoOstuni 0:75fc82583a41 1043
DiegoOstuni 0:75fc82583a41 1044 nfcipLogI( " NFCIP(T) rx DSL \r\n" );
DiegoOstuni 0:75fc82583a41 1045
DiegoOstuni 0:75fc82583a41 1046 /* Digital 1.0 14.9.1.2 If DID is used and incorrect ignore it */
DiegoOstuni 0:75fc82583a41 1047 /* [Digital 1.0, 16.9.1.2]: If DID == 0, Target SHALL ignore DSL_REQ with DID */
DiegoOstuni 0:75fc82583a41 1048 if ( ((gNfcip.cfg.did != RFAL_NFCDEP_DID_NO) && ((nfcDepLen != RFAL_NFCDEP_DSL_RLS_LEN_DID) || (gNfcip.rxBuf[rxMsgIt++] != gNfcip.cfg.did)) )
DiegoOstuni 0:75fc82583a41 1049 ||((gNfcip.cfg.did == RFAL_NFCDEP_DID_NO) && (nfcDepLen != RFAL_NFCDEP_DSL_RLS_LEN_NO_DID))
DiegoOstuni 0:75fc82583a41 1050 )
DiegoOstuni 0:75fc82583a41 1051 {
DiegoOstuni 0:75fc82583a41 1052 nfcipLogI( " NFCIP(T) DSL wrong DID, ignoring \r\n" );
DiegoOstuni 0:75fc82583a41 1053 return ERR_BUSY;
DiegoOstuni 0:75fc82583a41 1054 }
DiegoOstuni 0:75fc82583a41 1055
DiegoOstuni 0:75fc82583a41 1056 nfcipTx( NFCIP_CMD_DSL_RES, resBuf, 0, 0, 0, NFCIP_NO_FWT, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ;
DiegoOstuni 0:75fc82583a41 1057
DiegoOstuni 0:75fc82583a41 1058 gNfcip.state = NFCIP_ST_TARG_DEP_SLEEP;
DiegoOstuni 0:75fc82583a41 1059 return ERR_SLEEP_REQ;
DiegoOstuni 0:75fc82583a41 1060
DiegoOstuni 0:75fc82583a41 1061 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 1062 case NFCIP_CMD_RLS_REQ:
DiegoOstuni 0:75fc82583a41 1063
DiegoOstuni 0:75fc82583a41 1064 nfcipLogI( " NFCIP(T) rx RLS \r\n" );
DiegoOstuni 0:75fc82583a41 1065
DiegoOstuni 0:75fc82583a41 1066 /* Digital 1.0 14.10.1.2 If DID is used and incorrect ignore it */
DiegoOstuni 0:75fc82583a41 1067 /* [Digital 1.0, 16.10.2.2]: If DID == 0, Target SHALL ignore DSL_REQ with DID */
DiegoOstuni 0:75fc82583a41 1068 if ( ( (gNfcip.cfg.did != RFAL_NFCDEP_DID_NO) && ((nfcDepLen != RFAL_NFCDEP_DSL_RLS_LEN_DID) || (gNfcip.rxBuf[rxMsgIt++] != gNfcip.cfg.did)) )
DiegoOstuni 0:75fc82583a41 1069 ||( (gNfcip.cfg.did == RFAL_NFCDEP_DID_NO) && (nfcDepLen > RFAL_NFCDEP_DSL_RLS_LEN_NO_DID))
DiegoOstuni 0:75fc82583a41 1070 )
DiegoOstuni 0:75fc82583a41 1071 {
DiegoOstuni 0:75fc82583a41 1072 nfcipLogI( " NFCIP(T) RLS wrong DID, ignoring \r\n" );
DiegoOstuni 0:75fc82583a41 1073 return ERR_BUSY;
DiegoOstuni 0:75fc82583a41 1074 }
DiegoOstuni 0:75fc82583a41 1075
DiegoOstuni 0:75fc82583a41 1076 nfcipTx( NFCIP_CMD_RLS_RES, resBuf, 0, 0, 0, NFCIP_NO_FWT, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ;
DiegoOstuni 0:75fc82583a41 1077
DiegoOstuni 0:75fc82583a41 1078 gNfcip.state = NFCIP_ST_TARG_DEP_IDLE;
DiegoOstuni 0:75fc82583a41 1079 return ERR_RELEASE_REQ;
DiegoOstuni 0:75fc82583a41 1080
DiegoOstuni 0:75fc82583a41 1081 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 1082 /*case NFCIP_CMD_PSL_REQ: PSL must be handled in Activation only */
DiegoOstuni 0:75fc82583a41 1083 /*case NFCIP_CMD_WUP_REQ: WUP not in NFC Forum Digital 1.0 */
DiegoOstuni 0:75fc82583a41 1084 default:
DiegoOstuni 0:75fc82583a41 1085
DiegoOstuni 0:75fc82583a41 1086 /* Don't go to NFCIP_ST_TARG_DEP_IDLE state as it needs to ignore this *
DiegoOstuni 0:75fc82583a41 1087 * invalid frame, and keep waiting for more frames */
DiegoOstuni 0:75fc82583a41 1088
DiegoOstuni 0:75fc82583a41 1089 nfcDepReEnableRx( gNfcip.rxBuf, gNfcip.rxBufLen, gNfcip.rxRcvdLen );
DiegoOstuni 0:75fc82583a41 1090 return ERR_BUSY; /* ERR_PROTO - Ignore bad frame */
DiegoOstuni 0:75fc82583a41 1091 }
DiegoOstuni 0:75fc82583a41 1092
DiegoOstuni 0:75fc82583a41 1093 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 1094
DiegoOstuni 0:75fc82583a41 1095 rxPFB = gNfcip.rxBuf[rxMsgIt++]; /* Store rcvd PFB */
DiegoOstuni 0:75fc82583a41 1096
DiegoOstuni 0:75fc82583a41 1097 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 1098 /* Check for valid PFB type */
DiegoOstuni 0:75fc82583a41 1099 if( !(nfcip_PFBisSPDU( rxPFB ) || nfcip_PFBisRPDU( rxPFB ) || nfcip_PFBisIPDU( rxPFB )) )
DiegoOstuni 0:75fc82583a41 1100 {
DiegoOstuni 0:75fc82583a41 1101 nfcDepReEnableRx( gNfcip.rxBuf, gNfcip.rxBufLen, gNfcip.rxRcvdLen );
DiegoOstuni 0:75fc82583a41 1102 return ERR_BUSY; /* ERR_PROTO - Ignore invalid PFB */
DiegoOstuni 0:75fc82583a41 1103 }
DiegoOstuni 0:75fc82583a41 1104
DiegoOstuni 0:75fc82583a41 1105 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 1106 if( gNfcip.cfg.did != RFAL_NFCDEP_DID_NO )
DiegoOstuni 0:75fc82583a41 1107 {
DiegoOstuni 0:75fc82583a41 1108 if( !nfcip_PFBhasDID( rxPFB ) || gNfcip.rxBuf[rxMsgIt++] != gNfcip.cfg.did )
DiegoOstuni 0:75fc82583a41 1109 {
DiegoOstuni 0:75fc82583a41 1110 nfcDepReEnableRx( gNfcip.rxBuf, gNfcip.rxBufLen, gNfcip.rxRcvdLen );
DiegoOstuni 0:75fc82583a41 1111 return ERR_BUSY; /* ERR_PROTO - Ignore bad/missing DID */
DiegoOstuni 0:75fc82583a41 1112 }
DiegoOstuni 0:75fc82583a41 1113 optHdrLen++; /* Inc header optional field cnt*/
DiegoOstuni 0:75fc82583a41 1114 }
DiegoOstuni 0:75fc82583a41 1115 else if( nfcip_PFBhasDID( rxPFB ) ) /* DID not expected but rcv */
DiegoOstuni 0:75fc82583a41 1116 {
DiegoOstuni 0:75fc82583a41 1117 nfcDepReEnableRx( gNfcip.rxBuf, gNfcip.rxBufLen, gNfcip.rxRcvdLen );
DiegoOstuni 0:75fc82583a41 1118 return ERR_BUSY; /* ERR_PROTO - Ignore unexpected DID */
DiegoOstuni 0:75fc82583a41 1119 }
DiegoOstuni 0:75fc82583a41 1120
DiegoOstuni 0:75fc82583a41 1121
DiegoOstuni 0:75fc82583a41 1122 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 1123 if( gNfcip.cfg.nad != RFAL_NFCDEP_NAD_NO )
DiegoOstuni 0:75fc82583a41 1124 {
DiegoOstuni 0:75fc82583a41 1125 if( !nfcip_PFBhasNAD( rxPFB ) || gNfcip.rxBuf[rxMsgIt++] != gNfcip.cfg.nad )
DiegoOstuni 0:75fc82583a41 1126 {
DiegoOstuni 0:75fc82583a41 1127 nfcDepReEnableRx( gNfcip.rxBuf, gNfcip.rxBufLen, gNfcip.rxRcvdLen );
DiegoOstuni 0:75fc82583a41 1128 return ERR_BUSY; /* ERR_PROTO - Ignore bad/missing NAD */
DiegoOstuni 0:75fc82583a41 1129 }
DiegoOstuni 0:75fc82583a41 1130 optHdrLen++; /* Inc header optional field cnt*/
DiegoOstuni 0:75fc82583a41 1131 }
DiegoOstuni 0:75fc82583a41 1132 else if( nfcip_PFBhasNAD( rxPFB ) ) /* NAD not expected but rcv */
DiegoOstuni 0:75fc82583a41 1133 {
DiegoOstuni 0:75fc82583a41 1134 nfcDepReEnableRx( gNfcip.rxBuf, gNfcip.rxBufLen, gNfcip.rxRcvdLen );
DiegoOstuni 0:75fc82583a41 1135 return ERR_BUSY; /* ERR_PROTO - Ignore unexpected NAD */
DiegoOstuni 0:75fc82583a41 1136 }
DiegoOstuni 0:75fc82583a41 1137
DiegoOstuni 0:75fc82583a41 1138
DiegoOstuni 0:75fc82583a41 1139 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 1140 /* Process R-PDU */
DiegoOstuni 0:75fc82583a41 1141 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 1142 if( nfcip_PFBisRPDU( rxPFB ) )
DiegoOstuni 0:75fc82583a41 1143 {
DiegoOstuni 0:75fc82583a41 1144 nfcipLogD( " NFCIP(T) Rcvd R-PDU \r\n" );
DiegoOstuni 0:75fc82583a41 1145 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 1146 /* R ACK */
DiegoOstuni 0:75fc82583a41 1147 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 1148 if( nfcip_PFBisRACK( rxPFB ) )
DiegoOstuni 0:75fc82583a41 1149 {
DiegoOstuni 0:75fc82583a41 1150 nfcipLogI( " NFCIP(T) Rcvd ACK \r\n" );
DiegoOstuni 0:75fc82583a41 1151 if( gNfcip.pni == nfcip_PBF_PNI( rxPFB ) )
DiegoOstuni 0:75fc82583a41 1152 {
DiegoOstuni 0:75fc82583a41 1153 /* R-ACK while not performing chaining -> Protocol error */
DiegoOstuni 0:75fc82583a41 1154 if( !gNfcip.isTxChaining )
DiegoOstuni 0:75fc82583a41 1155 {
DiegoOstuni 0:75fc82583a41 1156 nfcDepReEnableRx( gNfcip.rxBuf, gNfcip.rxBufLen, gNfcip.rxRcvdLen );
DiegoOstuni 0:75fc82583a41 1157 return ERR_BUSY; /* ERR_PROTO - Ignore unexpected ACK */
DiegoOstuni 0:75fc82583a41 1158 }
DiegoOstuni 0:75fc82583a41 1159
DiegoOstuni 0:75fc82583a41 1160 /* This block has been transmitted and acknowledged, perform RTOX until next data is provided */
DiegoOstuni 0:75fc82583a41 1161
DiegoOstuni 0:75fc82583a41 1162 /* Digital 1.1 16.12.4.7 - If ACK rcvd continue with chaining or an RTOX */
DiegoOstuni 0:75fc82583a41 1163 nfcipTimerStart( gNfcip.RTOXTimer, nfcipRTOXAdjust( nfcipConv1FcToMs( rfalNfcDepWT2RWT( gNfcip.cfg.to ) )) );
DiegoOstuni 0:75fc82583a41 1164 gNfcip.state = NFCIP_ST_TARG_DEP_RTOX;
DiegoOstuni 0:75fc82583a41 1165
DiegoOstuni 0:75fc82583a41 1166 return ERR_NONE; /* This block has been transmitted */
DiegoOstuni 0:75fc82583a41 1167 }
DiegoOstuni 0:75fc82583a41 1168
DiegoOstuni 0:75fc82583a41 1169 /* Digital 1.0 14.12.3.4 - If last send was ATN and rx PNI is minus 1 */
DiegoOstuni 0:75fc82583a41 1170 else if( nfcip_PFBisSATN( gNfcip.lastPFB ) && (nfcip_PNIDec(gNfcip.pni) == nfcip_PBF_PNI( rxPFB )) )
DiegoOstuni 0:75fc82583a41 1171 {
DiegoOstuni 0:75fc82583a41 1172 nfcipLogI( " NFCIP(T) wrong PNI, last was ATN reTx \r\n" );
DiegoOstuni 0:75fc82583a41 1173 /* Spec says to leave current PNI as is, but will be Inc after Tx, remaining the same */
DiegoOstuni 0:75fc82583a41 1174 gNfcip.pni = nfcip_PNIDec( gNfcip.pni );
DiegoOstuni 0:75fc82583a41 1175
DiegoOstuni 0:75fc82583a41 1176 gNfcip.state = NFCIP_ST_TARG_DEP_TX;
DiegoOstuni 0:75fc82583a41 1177 return ERR_BUSY;
DiegoOstuni 0:75fc82583a41 1178 }
DiegoOstuni 0:75fc82583a41 1179 }
DiegoOstuni 0:75fc82583a41 1180 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 1181 /* R NACK */
DiegoOstuni 0:75fc82583a41 1182 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 1183 /* ISO 18092 12.6.1.3.3 When rcv NACK if PNI = prev PNI sent -> reTx */
DiegoOstuni 0:75fc82583a41 1184 else if( nfcip_PFBisRNACK( rxPFB ) && (nfcip_PNIDec(gNfcip.pni) == nfcip_PBF_PNI( rxPFB ) ) )
DiegoOstuni 0:75fc82583a41 1185 {
DiegoOstuni 0:75fc82583a41 1186 nfcipLogI( " NFCIP(T) Rcvd NACK \r\n" );
DiegoOstuni 0:75fc82583a41 1187
DiegoOstuni 0:75fc82583a41 1188 gNfcip.pni = nfcip_PNIDec( gNfcip.pni ); /* Dec so that has the prev PNI */
DiegoOstuni 0:75fc82583a41 1189
DiegoOstuni 0:75fc82583a41 1190 gNfcip.state = NFCIP_ST_TARG_DEP_TX;
DiegoOstuni 0:75fc82583a41 1191 return ERR_BUSY;
DiegoOstuni 0:75fc82583a41 1192 }
DiegoOstuni 0:75fc82583a41 1193
DiegoOstuni 0:75fc82583a41 1194 nfcipLogI( " NFCIP(T) Unexpected R-PDU \r\n" );
DiegoOstuni 0:75fc82583a41 1195
DiegoOstuni 0:75fc82583a41 1196 nfcDepReEnableRx( gNfcip.rxBuf, gNfcip.rxBufLen, gNfcip.rxRcvdLen );
DiegoOstuni 0:75fc82583a41 1197 return ERR_BUSY; /* ERR_PROTO - Ignore unexpected R-PDU */
DiegoOstuni 0:75fc82583a41 1198 }
DiegoOstuni 0:75fc82583a41 1199
DiegoOstuni 0:75fc82583a41 1200 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 1201 /* Process S-PDU */
DiegoOstuni 0:75fc82583a41 1202 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 1203 if( nfcip_PFBisSPDU( rxPFB ) )
DiegoOstuni 0:75fc82583a41 1204 {
DiegoOstuni 0:75fc82583a41 1205 nfcipLogD( " NFCIP(T) Rcvd S-PDU \r\n" );
DiegoOstuni 0:75fc82583a41 1206
DiegoOstuni 0:75fc82583a41 1207 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 1208 /* S ATN */
DiegoOstuni 0:75fc82583a41 1209 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 1210 /* ISO 18092 12.6.3 Attention */
DiegoOstuni 0:75fc82583a41 1211 if( nfcip_PFBisSATN( rxPFB ) ) /* If is a S-ATN */
DiegoOstuni 0:75fc82583a41 1212 {
DiegoOstuni 0:75fc82583a41 1213 nfcipLogI( " NFCIP(T) Rcvd ATN curPNI: %d \r\n", gNfcip.pni );
DiegoOstuni 0:75fc82583a41 1214 EXIT_ON_ERR( ret, nfcipDEPControlMsg( nfcip_PFBSPDU_ATN(), 0, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) );
DiegoOstuni 0:75fc82583a41 1215 return ERR_BUSY;
DiegoOstuni 0:75fc82583a41 1216 }
DiegoOstuni 0:75fc82583a41 1217
DiegoOstuni 0:75fc82583a41 1218 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 1219 /* S TO */
DiegoOstuni 0:75fc82583a41 1220 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 1221 else if( nfcip_PFBisSTO( rxPFB ) ) /* If is a S-TO (RTOX) */
DiegoOstuni 0:75fc82583a41 1222 {
DiegoOstuni 0:75fc82583a41 1223 if( nfcip_PFBisSTO( gNfcip.lastPFBnATN ) )
DiegoOstuni 0:75fc82583a41 1224 {
DiegoOstuni 0:75fc82583a41 1225 nfcipLogI( " NFCIP(T) Rcvd TO \r\n" );
DiegoOstuni 0:75fc82583a41 1226
DiegoOstuni 0:75fc82583a41 1227 /* Digital 1.1 16.8.4.6 RTOX value in RES different that in REQ -> Protocol Error */
DiegoOstuni 0:75fc82583a41 1228 if( gNfcip.lastRTOX != gNfcip.rxBuf[rxMsgIt++] )
DiegoOstuni 0:75fc82583a41 1229 {
DiegoOstuni 0:75fc82583a41 1230 nfcipLogI( " NFCIP(T) Mismatched RTOX value \r\n" );
DiegoOstuni 0:75fc82583a41 1231
DiegoOstuni 0:75fc82583a41 1232 nfcDepReEnableRx( gNfcip.rxBuf, gNfcip.rxBufLen, gNfcip.rxRcvdLen );
DiegoOstuni 0:75fc82583a41 1233 return ERR_BUSY; /* ERR_PROTO - Ignore unexpected RTOX value */
DiegoOstuni 0:75fc82583a41 1234 }
DiegoOstuni 0:75fc82583a41 1235
DiegoOstuni 0:75fc82583a41 1236 /* Clear waiting for RTOX Ack Flag */
DiegoOstuni 0:75fc82583a41 1237 gNfcip.isWait4RTOX = false;
DiegoOstuni 0:75fc82583a41 1238
DiegoOstuni 0:75fc82583a41 1239 /* Check if a Tx is already pending */
DiegoOstuni 0:75fc82583a41 1240 if( gNfcip.isTxPending )
DiegoOstuni 0:75fc82583a41 1241 {
DiegoOstuni 0:75fc82583a41 1242 nfcipLogW( " NFCIP(T) Tx pending, go immediately to TX \r\n" );
DiegoOstuni 0:75fc82583a41 1243
DiegoOstuni 0:75fc82583a41 1244 gNfcip.state = NFCIP_ST_TARG_DEP_TX;
DiegoOstuni 0:75fc82583a41 1245 return ERR_BUSY;
DiegoOstuni 0:75fc82583a41 1246 }
DiegoOstuni 0:75fc82583a41 1247
DiegoOstuni 0:75fc82583a41 1248 /* Start RTOX timer and change to check state */
DiegoOstuni 0:75fc82583a41 1249 nfcipTimerStart( gNfcip.RTOXTimer, nfcipRTOXAdjust( nfcipConv1FcToMs( gNfcip.lastRTOX * rfalNfcDepWT2RWT(gNfcip.cfg.to ) ) ) );
DiegoOstuni 0:75fc82583a41 1250 gNfcip.state = NFCIP_ST_TARG_DEP_RTOX;
DiegoOstuni 0:75fc82583a41 1251
DiegoOstuni 0:75fc82583a41 1252 return ERR_BUSY;
DiegoOstuni 0:75fc82583a41 1253 }
DiegoOstuni 0:75fc82583a41 1254 }
DiegoOstuni 0:75fc82583a41 1255 /* Unexpected S-PDU */
DiegoOstuni 0:75fc82583a41 1256 nfcipLogI( " NFCIP(T) Unexpected S-PDU \r\n" );
DiegoOstuni 0:75fc82583a41 1257
DiegoOstuni 0:75fc82583a41 1258 nfcDepReEnableRx( gNfcip.rxBuf, gNfcip.rxBufLen, gNfcip.rxRcvdLen );
DiegoOstuni 0:75fc82583a41 1259 return ERR_BUSY; /* ERR_PROTO - Ignore unexpected S-PDU */
DiegoOstuni 0:75fc82583a41 1260 }
DiegoOstuni 0:75fc82583a41 1261
DiegoOstuni 0:75fc82583a41 1262 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 1263 /* Process I-PDU */
DiegoOstuni 0:75fc82583a41 1264 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 1265 if( nfcip_PFBisIPDU( rxPFB ) )
DiegoOstuni 0:75fc82583a41 1266 {
DiegoOstuni 0:75fc82583a41 1267 if( gNfcip.pni != nfcip_PBF_PNI( rxPFB ) )
DiegoOstuni 0:75fc82583a41 1268 {
DiegoOstuni 0:75fc82583a41 1269 nfcipLogI( " NFCIP(T) Rcvd IPDU wrong PNI curPNI: %d rxPNI: %d \r\n", gNfcip.pni, nfcip_PBF_PNI( rxPFB ) );
DiegoOstuni 0:75fc82583a41 1270
DiegoOstuni 0:75fc82583a41 1271 /* Digital 1.1 16.12.3.4 - If last send was ATN and rx PNI is minus 1 */
DiegoOstuni 0:75fc82583a41 1272 if( nfcip_PFBisSATN(gNfcip.lastPFB ) && (nfcip_PNIDec(gNfcip.pni) == nfcip_PBF_PNI( rxPFB )) )
DiegoOstuni 0:75fc82583a41 1273 {
DiegoOstuni 0:75fc82583a41 1274 /* Spec says to leave current PNI as is, but will be Inc after Data Tx, remaining the same */
DiegoOstuni 0:75fc82583a41 1275 gNfcip.pni = nfcip_PNIDec(gNfcip.pni);
DiegoOstuni 0:75fc82583a41 1276
DiegoOstuni 0:75fc82583a41 1277 if( nfcip_PFBisIMI( rxPFB ) )
DiegoOstuni 0:75fc82583a41 1278 {
DiegoOstuni 0:75fc82583a41 1279 nfcipLogI( " NFCIP(T) PNI = prevPNI && ATN before && chaining -> send ACK \r\n" );
DiegoOstuni 0:75fc82583a41 1280 EXIT_ON_ERR( ret, nfcipDEPControlMsg( nfcip_PFBRPDU_ACK( gNfcip.pni ), gNfcip.rxBuf[rxMsgIt++], mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) );
DiegoOstuni 0:75fc82583a41 1281
DiegoOstuni 0:75fc82583a41 1282 /* Digital 1.1 16.12.3.4 (...) leave the current PNI unchanged afterwards */
DiegoOstuni 0:75fc82583a41 1283 gNfcip.pni = nfcip_PNIInc( gNfcip.pni );
DiegoOstuni 0:75fc82583a41 1284 }
DiegoOstuni 0:75fc82583a41 1285 else
DiegoOstuni 0:75fc82583a41 1286 {
DiegoOstuni 0:75fc82583a41 1287 nfcipLogI( " NFCIP(T) PNI = prevPNI && ATN before -> reTx last I-PDU \r\n" );
DiegoOstuni 0:75fc82583a41 1288 gNfcip.state = NFCIP_ST_TARG_DEP_TX;
DiegoOstuni 0:75fc82583a41 1289 }
DiegoOstuni 0:75fc82583a41 1290
DiegoOstuni 0:75fc82583a41 1291 return ERR_BUSY;
DiegoOstuni 0:75fc82583a41 1292 }
DiegoOstuni 0:75fc82583a41 1293
DiegoOstuni 0:75fc82583a41 1294 nfcDepReEnableRx( gNfcip.rxBuf, gNfcip.rxBufLen, gNfcip.rxRcvdLen );
DiegoOstuni 0:75fc82583a41 1295 return ERR_BUSY; /* ERR_PROTO - Ignore bad PNI value */
DiegoOstuni 0:75fc82583a41 1296 }
DiegoOstuni 0:75fc82583a41 1297
DiegoOstuni 0:75fc82583a41 1298 nfcipLogD( " NFCIP(T) Rcvd IPDU OK PNI: %d \r\n", gNfcip.pni );
DiegoOstuni 0:75fc82583a41 1299
DiegoOstuni 0:75fc82583a41 1300 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 1301 /* Successful data exchange */
DiegoOstuni 0:75fc82583a41 1302 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 1303 *outActRxLen = (nfcDepLen - RFAL_NFCDEP_DEP_HEADER - optHdrLen);
DiegoOstuni 0:75fc82583a41 1304
DiegoOstuni 0:75fc82583a41 1305 nfcipClearCounters();
DiegoOstuni 0:75fc82583a41 1306
DiegoOstuni 0:75fc82583a41 1307 if( (gNfcip.rxBuf + gNfcip.rxBufPaylPos) != (gNfcip.rxBuf + RFAL_NFCDEP_DEP_HEADER + optHdrLen) )
DiegoOstuni 0:75fc82583a41 1308 {
DiegoOstuni 0:75fc82583a41 1309 ST_MEMMOVE( (gNfcip.rxBuf + gNfcip.rxBufPaylPos), (gNfcip.rxBuf + RFAL_NFCDEP_DEP_HEADER + optHdrLen), *outActRxLen );
DiegoOstuni 0:75fc82583a41 1310 }
DiegoOstuni 0:75fc82583a41 1311
DiegoOstuni 0:75fc82583a41 1312
DiegoOstuni 0:75fc82583a41 1313 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 1314 /* Check if Initiator is indicating chaining MI */
DiegoOstuni 0:75fc82583a41 1315 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 1316 if( nfcip_PFBisIMI( rxPFB ) )
DiegoOstuni 0:75fc82583a41 1317 {
DiegoOstuni 0:75fc82583a41 1318 gNfcip.isRxChaining = true;
DiegoOstuni 0:75fc82583a41 1319 *outIsChaining = true;
DiegoOstuni 0:75fc82583a41 1320
DiegoOstuni 0:75fc82583a41 1321 nfcipLogD( " NFCIP(T) Rcvd IPDU OK w MI -> ACK \r\n" );
DiegoOstuni 0:75fc82583a41 1322 EXIT_ON_ERR( ret, nfcipDEPControlMsg( nfcip_PFBRPDU_ACK( gNfcip.pni ), gNfcip.rxBuf[rxMsgIt++], mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) );
DiegoOstuni 0:75fc82583a41 1323
DiegoOstuni 0:75fc82583a41 1324 gNfcip.pni = nfcip_PNIInc( gNfcip.pni );
DiegoOstuni 0:75fc82583a41 1325
DiegoOstuni 0:75fc82583a41 1326 return ERR_AGAIN; /* Send Again signalling to run again, but some chaining data has arrived*/
DiegoOstuni 0:75fc82583a41 1327 }
DiegoOstuni 0:75fc82583a41 1328 else
DiegoOstuni 0:75fc82583a41 1329 {
DiegoOstuni 0:75fc82583a41 1330 if(gNfcip.isRxChaining)
DiegoOstuni 0:75fc82583a41 1331 {
DiegoOstuni 0:75fc82583a41 1332 nfcipLogI( " NFCIP(T) Rcvd last IPDU chaining finished \r\n" );
DiegoOstuni 0:75fc82583a41 1333 }
DiegoOstuni 0:75fc82583a41 1334
DiegoOstuni 0:75fc82583a41 1335 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 1336 /* Reception done, send to DH and start RTOX timer */
DiegoOstuni 0:75fc82583a41 1337 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 1338 nfcipTimerStart( gNfcip.RTOXTimer, nfcipRTOXAdjust( nfcipConv1FcToMs( rfalNfcDepWT2RWT( gNfcip.cfg.to ) )) );
DiegoOstuni 0:75fc82583a41 1339 gNfcip.state = NFCIP_ST_TARG_DEP_RTOX;
DiegoOstuni 0:75fc82583a41 1340
DiegoOstuni 0:75fc82583a41 1341 gNfcip.isRxChaining = false;
DiegoOstuni 0:75fc82583a41 1342 return ERR_NONE; /* Data exchange done */
DiegoOstuni 0:75fc82583a41 1343 }
DiegoOstuni 0:75fc82583a41 1344 }
DiegoOstuni 0:75fc82583a41 1345 return ret;
DiegoOstuni 0:75fc82583a41 1346 }
DiegoOstuni 0:75fc82583a41 1347
DiegoOstuni 0:75fc82583a41 1348
DiegoOstuni 0:75fc82583a41 1349 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 1350 static ReturnCode nfcipTx( rfalNfcDepCmd cmd, uint8_t* txBuf, uint8_t *paylBuf, uint16_t paylLen, uint8_t pfb, uint32_t fwt, SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 )
DiegoOstuni 0:75fc82583a41 1351 {
DiegoOstuni 0:75fc82583a41 1352 uint16_t txBufIt;
DiegoOstuni 0:75fc82583a41 1353 uint8_t *txBlock;
DiegoOstuni 0:75fc82583a41 1354
DiegoOstuni 0:75fc82583a41 1355 if( txBuf == NULL )
DiegoOstuni 0:75fc82583a41 1356 {
DiegoOstuni 0:75fc82583a41 1357 return ERR_PARAM;
DiegoOstuni 0:75fc82583a41 1358 }
DiegoOstuni 0:75fc82583a41 1359
DiegoOstuni 0:75fc82583a41 1360
DiegoOstuni 0:75fc82583a41 1361 if( (paylLen == 0) || (paylBuf == NULL) )
DiegoOstuni 0:75fc82583a41 1362 {
DiegoOstuni 0:75fc82583a41 1363 paylBuf = (txBuf + RFAL_NFCDEP_DEPREQ_HEADER_LEN); /* If not a DEP (no Data) ensure enough space for header */
DiegoOstuni 0:75fc82583a41 1364 }
DiegoOstuni 0:75fc82583a41 1365
DiegoOstuni 0:75fc82583a41 1366
DiegoOstuni 0:75fc82583a41 1367 txBufIt = 0;
DiegoOstuni 0:75fc82583a41 1368 txBlock = paylBuf; /* Point to beginning of the Data, and go backwards */
DiegoOstuni 0:75fc82583a41 1369
DiegoOstuni 0:75fc82583a41 1370
DiegoOstuni 0:75fc82583a41 1371 gNfcip.lastCmd = cmd; /* store last cmd sent */
DiegoOstuni 0:75fc82583a41 1372 gNfcip.lastPFB = NFCIP_PFB_INVALID; /* reset last pfb sent */
DiegoOstuni 0:75fc82583a41 1373
DiegoOstuni 0:75fc82583a41 1374 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 1375 /* Compute outgoing NFCIP message */
DiegoOstuni 0:75fc82583a41 1376 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 1377 switch( cmd )
DiegoOstuni 0:75fc82583a41 1378 {
DiegoOstuni 0:75fc82583a41 1379 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 1380 case NFCIP_CMD_ATR_RES:
DiegoOstuni 0:75fc82583a41 1381 case NFCIP_CMD_ATR_REQ:
DiegoOstuni 0:75fc82583a41 1382
DiegoOstuni 0:75fc82583a41 1383 rfalNfcDepSetNFCID( paylBuf, gNfcip.cfg.nfcid, gNfcip.cfg.nfcidLen ); /* NFCID */
DiegoOstuni 0:75fc82583a41 1384 txBufIt += RFAL_NFCDEP_NFCID3_LEN;
DiegoOstuni 0:75fc82583a41 1385
DiegoOstuni 0:75fc82583a41 1386 *(paylBuf + txBufIt++) = gNfcip.cfg.did; /* DID */
DiegoOstuni 0:75fc82583a41 1387 *(paylBuf + txBufIt++) = gNfcip.cfg.bs; /* BS */
DiegoOstuni 0:75fc82583a41 1388 *(paylBuf + txBufIt++) = gNfcip.cfg.br; /* BR */
DiegoOstuni 0:75fc82583a41 1389
DiegoOstuni 0:75fc82583a41 1390 if( cmd == NFCIP_CMD_ATR_RES )
DiegoOstuni 0:75fc82583a41 1391 {
DiegoOstuni 0:75fc82583a41 1392 *(paylBuf + txBufIt++) = gNfcip.cfg.to; /* ATR_RES[ TO ] */
DiegoOstuni 0:75fc82583a41 1393 }
DiegoOstuni 0:75fc82583a41 1394
DiegoOstuni 0:75fc82583a41 1395 if( gNfcip.cfg.gbLen > 0)
DiegoOstuni 0:75fc82583a41 1396 {
DiegoOstuni 0:75fc82583a41 1397 *(paylBuf + txBufIt++) = nfcip_PPwGB( gNfcip.cfg.lr ); /* PP signalling GB */
DiegoOstuni 0:75fc82583a41 1398 ST_MEMCPY( (paylBuf + txBufIt), gNfcip.cfg.gb, gNfcip.cfg.gbLen ); /* set General Bytes */
DiegoOstuni 0:75fc82583a41 1399 txBufIt += gNfcip.cfg.gbLen;
DiegoOstuni 0:75fc82583a41 1400 }
DiegoOstuni 0:75fc82583a41 1401 else
DiegoOstuni 0:75fc82583a41 1402 {
DiegoOstuni 0:75fc82583a41 1403 *(paylBuf + txBufIt++) = rfalNfcDepLR2PP( gNfcip.cfg.lr ); /* PP without GB */
DiegoOstuni 0:75fc82583a41 1404 }
DiegoOstuni 0:75fc82583a41 1405
DiegoOstuni 0:75fc82583a41 1406 if( (txBufIt + RFAL_NFCDEP_CMDTYPE_LEN + RFAL_NFCDEP_CMD_LEN) > RFAL_NFCDEP_ATRREQ_MAX_LEN ) /* Check max ATR length (ATR_REQ = ATR_RES)*/
DiegoOstuni 0:75fc82583a41 1407 {
DiegoOstuni 0:75fc82583a41 1408 return ERR_PARAM;
DiegoOstuni 0:75fc82583a41 1409 }
DiegoOstuni 0:75fc82583a41 1410
DiegoOstuni 0:75fc82583a41 1411 break;
DiegoOstuni 0:75fc82583a41 1412
DiegoOstuni 0:75fc82583a41 1413 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 1414 case NFCIP_CMD_WUP_REQ: /* ISO 18092 - 12.5.2.1 */
DiegoOstuni 0:75fc82583a41 1415
DiegoOstuni 0:75fc82583a41 1416 rfalNfcDepSetNFCID( (paylBuf), gNfcip.cfg.nfcid, gNfcip.cfg.nfcidLen ); /* NFCID */
DiegoOstuni 0:75fc82583a41 1417 txBufIt += RFAL_NFCDEP_NFCID3_LEN;
DiegoOstuni 0:75fc82583a41 1418
DiegoOstuni 0:75fc82583a41 1419 *(--txBlock) = gNfcip.cfg.did; /* DID */
DiegoOstuni 0:75fc82583a41 1420 break;
DiegoOstuni 0:75fc82583a41 1421
DiegoOstuni 0:75fc82583a41 1422 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 1423 case NFCIP_CMD_WUP_RES: /* ISO 18092 - 12.5.2.2 */
DiegoOstuni 0:75fc82583a41 1424 case NFCIP_CMD_PSL_REQ:
DiegoOstuni 0:75fc82583a41 1425 case NFCIP_CMD_PSL_RES:
DiegoOstuni 0:75fc82583a41 1426
DiegoOstuni 0:75fc82583a41 1427 *(--txBlock) = gNfcip.cfg.did; /* DID */
DiegoOstuni 0:75fc82583a41 1428 break;
DiegoOstuni 0:75fc82583a41 1429
DiegoOstuni 0:75fc82583a41 1430 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 1431 case NFCIP_CMD_RLS_REQ:
DiegoOstuni 0:75fc82583a41 1432 case NFCIP_CMD_RLS_RES:
DiegoOstuni 0:75fc82583a41 1433 case NFCIP_CMD_DSL_REQ:
DiegoOstuni 0:75fc82583a41 1434 case NFCIP_CMD_DSL_RES:
DiegoOstuni 0:75fc82583a41 1435
DiegoOstuni 0:75fc82583a41 1436 /* Digital 1.0 - 14.8.1.1 & 14.9.1.1 & 14.10.1.1 Only add DID if not 0 */
DiegoOstuni 0:75fc82583a41 1437 if( gNfcip.cfg.did != RFAL_NFCDEP_DID_NO )
DiegoOstuni 0:75fc82583a41 1438 {
DiegoOstuni 0:75fc82583a41 1439 *(--txBlock) = gNfcip.cfg.did; /* DID */
DiegoOstuni 0:75fc82583a41 1440 }
DiegoOstuni 0:75fc82583a41 1441 break;
DiegoOstuni 0:75fc82583a41 1442
DiegoOstuni 0:75fc82583a41 1443 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 1444 case NFCIP_CMD_DEP_REQ:
DiegoOstuni 0:75fc82583a41 1445 case NFCIP_CMD_DEP_RES:
DiegoOstuni 0:75fc82583a41 1446
DiegoOstuni 0:75fc82583a41 1447 /* Compute optional PFB bits */
DiegoOstuni 0:75fc82583a41 1448 if(gNfcip.cfg.did != RFAL_NFCDEP_DID_NO) pfb |= NFCIP_PFB_DID_BIT;
DiegoOstuni 0:75fc82583a41 1449 if(gNfcip.cfg.nad != RFAL_NFCDEP_NAD_NO) pfb |= NFCIP_PFB_NAD_BIT;
DiegoOstuni 0:75fc82583a41 1450 if((gNfcip.isTxChaining) && (nfcip_PFBisIPDU(pfb)) ) pfb |= NFCIP_PFB_MI_BIT;
DiegoOstuni 0:75fc82583a41 1451
DiegoOstuni 0:75fc82583a41 1452 /* Store PFB for future handling */
DiegoOstuni 0:75fc82583a41 1453 gNfcip.lastPFB = pfb; /* store PFB sent */
DiegoOstuni 0:75fc82583a41 1454
DiegoOstuni 0:75fc82583a41 1455 if( !nfcip_PFBisSATN(pfb) )
DiegoOstuni 0:75fc82583a41 1456 {
DiegoOstuni 0:75fc82583a41 1457 gNfcip.lastPFBnATN = pfb; /* store last PFB different then ATN */
DiegoOstuni 0:75fc82583a41 1458 }
DiegoOstuni 0:75fc82583a41 1459
DiegoOstuni 0:75fc82583a41 1460
DiegoOstuni 0:75fc82583a41 1461 /* Add NAD if it is to be supported */
DiegoOstuni 0:75fc82583a41 1462 if( gNfcip.cfg.nad != RFAL_NFCDEP_NAD_NO )
DiegoOstuni 0:75fc82583a41 1463 {
DiegoOstuni 0:75fc82583a41 1464 *(--txBlock) = gNfcip.cfg.nad; /* NAD */
DiegoOstuni 0:75fc82583a41 1465 }
DiegoOstuni 0:75fc82583a41 1466
DiegoOstuni 0:75fc82583a41 1467 /* Digital 1.0 - 14.8.1.1 & 14.8.1.1 Only add DID if not 0 */
DiegoOstuni 0:75fc82583a41 1468 if( gNfcip.cfg.did != RFAL_NFCDEP_DID_NO )
DiegoOstuni 0:75fc82583a41 1469 {
DiegoOstuni 0:75fc82583a41 1470 *(--txBlock) = gNfcip.cfg.did; /* DID */
DiegoOstuni 0:75fc82583a41 1471 }
DiegoOstuni 0:75fc82583a41 1472
DiegoOstuni 0:75fc82583a41 1473 *(--txBlock) = pfb; /* PFB */
DiegoOstuni 0:75fc82583a41 1474
DiegoOstuni 0:75fc82583a41 1475
DiegoOstuni 0:75fc82583a41 1476 /* NCI 1.0 - Check if Empty frames are allowed */
DiegoOstuni 0:75fc82583a41 1477 if( (paylLen == 0) && nfcipIsEmptyDEPDisabled(gNfcip.cfg.oper) && nfcip_PFBisIPDU(pfb) )
DiegoOstuni 0:75fc82583a41 1478 {
DiegoOstuni 0:75fc82583a41 1479 return ERR_PARAM;
DiegoOstuni 0:75fc82583a41 1480 }
DiegoOstuni 0:75fc82583a41 1481 break;
DiegoOstuni 0:75fc82583a41 1482
DiegoOstuni 0:75fc82583a41 1483 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 1484 default:
DiegoOstuni 0:75fc82583a41 1485 return ERR_PARAM;
DiegoOstuni 0:75fc82583a41 1486 }
DiegoOstuni 0:75fc82583a41 1487
DiegoOstuni 0:75fc82583a41 1488 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 1489 /* Prepend Header */
DiegoOstuni 0:75fc82583a41 1490 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 1491 *(--txBlock) = (uint8_t)cmd; /* CMD */
DiegoOstuni 0:75fc82583a41 1492 *(--txBlock) = ( nfcipCmdIsReq(cmd) ? NFCIP_REQ : NFCIP_RES ); /* CMDType */
DiegoOstuni 0:75fc82583a41 1493
DiegoOstuni 0:75fc82583a41 1494
DiegoOstuni 0:75fc82583a41 1495 txBufIt += paylLen + (paylBuf - txBlock); /* Calculate overall buffer size */
DiegoOstuni 0:75fc82583a41 1496
DiegoOstuni 0:75fc82583a41 1497
DiegoOstuni 0:75fc82583a41 1498 if( txBufIt > gNfcip.fsc ) /* Check if msg length violates the maximum payload size FSC */
DiegoOstuni 0:75fc82583a41 1499 {
DiegoOstuni 0:75fc82583a41 1500 return ERR_NOTSUPP;
DiegoOstuni 0:75fc82583a41 1501 }
DiegoOstuni 0:75fc82583a41 1502
DiegoOstuni 0:75fc82583a41 1503 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 1504 return nfcipDataTx( txBlock, txBufIt, fwt, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ;
DiegoOstuni 0:75fc82583a41 1505 }
DiegoOstuni 0:75fc82583a41 1506
DiegoOstuni 0:75fc82583a41 1507 /*
DiegoOstuni 0:75fc82583a41 1508 ******************************************************************************
DiegoOstuni 0:75fc82583a41 1509 * GLOBAL FUNCTIONS
DiegoOstuni 0:75fc82583a41 1510 ******************************************************************************
DiegoOstuni 0:75fc82583a41 1511 */
DiegoOstuni 0:75fc82583a41 1512
DiegoOstuni 0:75fc82583a41 1513 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 1514 static void nfcipConfig( rfalNfcDepConfigs cfg )
DiegoOstuni 0:75fc82583a41 1515 {
DiegoOstuni 0:75fc82583a41 1516 ST_MEMCPY(&gNfcip.cfg, &cfg, sizeof(rfalNfcDepConfigs)); /* Copy given config to local */
DiegoOstuni 0:75fc82583a41 1517
DiegoOstuni 0:75fc82583a41 1518 gNfcip.cfg.to = MIN( RFAL_NFCDEP_WT_TRG_MAX, gNfcip.cfg.to); /* Ensure proper WT value */
DiegoOstuni 0:75fc82583a41 1519 gNfcip.cfg.did = nfcip_DIDMax( gNfcip.cfg.did ); /* Ensure proper DID value */
DiegoOstuni 0:75fc82583a41 1520 gNfcip.fsc = rfalNfcDepLR2FS( gNfcip.cfg.lr ); /* Calculate FSC based on given LR */
DiegoOstuni 0:75fc82583a41 1521
DiegoOstuni 0:75fc82583a41 1522 gNfcip.state = ( ( gNfcip.cfg.role == RFAL_NFCDEP_ROLE_TARGET) ? NFCIP_ST_TARG_WAIT_ATR : NFCIP_ST_INIT_IDLE );
DiegoOstuni 0:75fc82583a41 1523 }
DiegoOstuni 0:75fc82583a41 1524
DiegoOstuni 0:75fc82583a41 1525
DiegoOstuni 0:75fc82583a41 1526 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 1527 static ReturnCode nfcipRun( uint16_t *outActRxLen, bool *outIsChaining, SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 )
DiegoOstuni 0:75fc82583a41 1528 {
DiegoOstuni 0:75fc82583a41 1529 ReturnCode ret;
DiegoOstuni 0:75fc82583a41 1530
DiegoOstuni 0:75fc82583a41 1531 ret = ERR_SYNTAX;
DiegoOstuni 0:75fc82583a41 1532
DiegoOstuni 0:75fc82583a41 1533 nfcipLogD( " NFCIP Run() state: %d \r\n", gNfcip.state );
DiegoOstuni 0:75fc82583a41 1534
DiegoOstuni 0:75fc82583a41 1535 switch( gNfcip.state )
DiegoOstuni 0:75fc82583a41 1536 {
DiegoOstuni 0:75fc82583a41 1537 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 1538 case NFCIP_ST_IDLE:
DiegoOstuni 0:75fc82583a41 1539 case NFCIP_ST_INIT_DEP_IDLE:
DiegoOstuni 0:75fc82583a41 1540 case NFCIP_ST_TARG_DEP_IDLE:
DiegoOstuni 0:75fc82583a41 1541 case NFCIP_ST_TARG_DEP_SLEEP:
DiegoOstuni 0:75fc82583a41 1542 return ERR_NONE;
DiegoOstuni 0:75fc82583a41 1543
DiegoOstuni 0:75fc82583a41 1544 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 1545 case NFCIP_ST_INIT_DEP_TX:
DiegoOstuni 0:75fc82583a41 1546
DiegoOstuni 0:75fc82583a41 1547 nfcipLogD( " NFCIP(I) Tx PNI: %d txLen: %d \r\n", gNfcip.pni, gNfcip.txBufLen );
DiegoOstuni 0:75fc82583a41 1548 ret = nfcipTx( NFCIP_CMD_DEP_REQ, gNfcip.txBuf, (gNfcip.txBuf + gNfcip.txBufPaylPos), gNfcip.txBufLen, nfcip_PFBIPDU( gNfcip.pni ), (gNfcip.cfg.fwt + gNfcip.cfg.dFwt), mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ;
DiegoOstuni 0:75fc82583a41 1549
DiegoOstuni 0:75fc82583a41 1550 switch( ERR_NO_MASK(ret) )
DiegoOstuni 0:75fc82583a41 1551 {
DiegoOstuni 0:75fc82583a41 1552 case ERR_PARAM:
DiegoOstuni 0:75fc82583a41 1553 default:
DiegoOstuni 0:75fc82583a41 1554 gNfcip.state = NFCIP_ST_INIT_DEP_IDLE;
DiegoOstuni 0:75fc82583a41 1555 return ret;
DiegoOstuni 0:75fc82583a41 1556
DiegoOstuni 0:75fc82583a41 1557 case ERR_NONE:
DiegoOstuni 0:75fc82583a41 1558 gNfcip.state = NFCIP_ST_INIT_DEP_RX;
DiegoOstuni 0:75fc82583a41 1559
DiegoOstuni 0:75fc82583a41 1560 }
DiegoOstuni 0:75fc82583a41 1561 /* fall through */
DiegoOstuni 0:75fc82583a41 1562
DiegoOstuni 0:75fc82583a41 1563 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 1564 case NFCIP_ST_INIT_DEP_RX:
DiegoOstuni 0:75fc82583a41 1565
DiegoOstuni 0:75fc82583a41 1566 ret = nfcipDataRx();
DiegoOstuni 0:75fc82583a41 1567
DiegoOstuni 0:75fc82583a41 1568 if( ret != ERR_NO_MASK(ERR_BUSY) )
DiegoOstuni 0:75fc82583a41 1569 {
DiegoOstuni 0:75fc82583a41 1570 ret = nfcipInitiatorHandleDEP( ret, *gNfcip.rxRcvdLen, outActRxLen, outIsChaining, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ;
DiegoOstuni 0:75fc82583a41 1571 }
DiegoOstuni 0:75fc82583a41 1572
DiegoOstuni 0:75fc82583a41 1573 break;
DiegoOstuni 0:75fc82583a41 1574
DiegoOstuni 0:75fc82583a41 1575 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 1576 case NFCIP_ST_TARG_DEP_RTOX:
DiegoOstuni 0:75fc82583a41 1577
DiegoOstuni 0:75fc82583a41 1578 if( !nfcipTimerisExpired( gNfcip.RTOXTimer ) ) /* Do nothing until RTOX timer has expired */
DiegoOstuni 0:75fc82583a41 1579 {
DiegoOstuni 0:75fc82583a41 1580 return ERR_BUSY;
DiegoOstuni 0:75fc82583a41 1581 }
DiegoOstuni 0:75fc82583a41 1582
DiegoOstuni 0:75fc82583a41 1583 /* If we cannot send a RTOX raise a Timeout error so that we do not
DiegoOstuni 0:75fc82583a41 1584 * hold the field On forever in AP2P */
DiegoOstuni 0:75fc82583a41 1585 if( nfcipIsRTOXReqDisabled(gNfcip.cfg.oper) )
DiegoOstuni 0:75fc82583a41 1586 {
DiegoOstuni 0:75fc82583a41 1587 /* We should reEnable Rx, and measure time between our field Off to
DiegoOstuni 0:75fc82583a41 1588 * either report link loss or recover #287 */
DiegoOstuni 0:75fc82583a41 1589 nfcipLogI( " NFCIP(T) RTOX not sent due to config, NOT reenabling Rx \r\n" );
DiegoOstuni 0:75fc82583a41 1590 return ERR_TIMEOUT;
DiegoOstuni 0:75fc82583a41 1591 }
DiegoOstuni 0:75fc82583a41 1592
DiegoOstuni 0:75fc82583a41 1593 if( gNfcip.cntRTOXRetrys++ > NFCIP_MAX_RTOX_RETRYS ) /* Check maximum consecutive RTOX requests */
DiegoOstuni 0:75fc82583a41 1594 {
DiegoOstuni 0:75fc82583a41 1595 return ERR_PROTO;
DiegoOstuni 0:75fc82583a41 1596 }
DiegoOstuni 0:75fc82583a41 1597
DiegoOstuni 0:75fc82583a41 1598 nfcipLogI( " NFCIP(T) RTOX sent \r\n" );
DiegoOstuni 0:75fc82583a41 1599
DiegoOstuni 0:75fc82583a41 1600 gNfcip.lastRTOX = nfcip_RTOXTargMax(gNfcip.cfg.to); /* Calculate requested RTOX value, and send it */
DiegoOstuni 0:75fc82583a41 1601 EXIT_ON_ERR( ret, nfcipDEPControlMsg( nfcip_PFBSPDU_TO(), gNfcip.lastRTOX, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) );
DiegoOstuni 0:75fc82583a41 1602
DiegoOstuni 0:75fc82583a41 1603 /* Set waiting for RTOX Ack Flag */
DiegoOstuni 0:75fc82583a41 1604 gNfcip.isWait4RTOX = true;
DiegoOstuni 0:75fc82583a41 1605
DiegoOstuni 0:75fc82583a41 1606 gNfcip.state = NFCIP_ST_TARG_DEP_RX; /* Go back to Rx to process RTOX ack */
DiegoOstuni 0:75fc82583a41 1607 return ERR_BUSY;
DiegoOstuni 0:75fc82583a41 1608
DiegoOstuni 0:75fc82583a41 1609 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 1610 case NFCIP_ST_TARG_DEP_TX:
DiegoOstuni 0:75fc82583a41 1611
DiegoOstuni 0:75fc82583a41 1612 nfcipLogD( " NFCIP(T) Tx PNI: %d txLen: %d \r\n", gNfcip.pni, gNfcip.txBufLen );
DiegoOstuni 0:75fc82583a41 1613 ret = nfcipTx( NFCIP_CMD_DEP_RES, gNfcip.txBuf, (gNfcip.txBuf + gNfcip.txBufPaylPos), gNfcip.txBufLen, nfcip_PFBIPDU( gNfcip.pni ), NFCIP_NO_FWT, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ;
DiegoOstuni 0:75fc82583a41 1614
DiegoOstuni 0:75fc82583a41 1615 /* Clear flags */
DiegoOstuni 0:75fc82583a41 1616 gNfcip.isTxPending = false;
DiegoOstuni 0:75fc82583a41 1617 gNfcip.isWait4RTOX = false;
DiegoOstuni 0:75fc82583a41 1618
DiegoOstuni 0:75fc82583a41 1619 /* Digital 1.0 14.12.3.4 Increment the current PNI after Tx */
DiegoOstuni 0:75fc82583a41 1620 gNfcip.pni = nfcip_PNIInc( gNfcip.pni );
DiegoOstuni 0:75fc82583a41 1621
DiegoOstuni 0:75fc82583a41 1622 switch( ERR_NO_MASK(ret) )
DiegoOstuni 0:75fc82583a41 1623 {
DiegoOstuni 0:75fc82583a41 1624 case ERR_PARAM:
DiegoOstuni 0:75fc82583a41 1625 default:
DiegoOstuni 0:75fc82583a41 1626 gNfcip.state = NFCIP_ST_TARG_DEP_IDLE; /* Upon Tx error, goto IDLE state */
DiegoOstuni 0:75fc82583a41 1627 return ret;
DiegoOstuni 0:75fc82583a41 1628
DiegoOstuni 0:75fc82583a41 1629 case ERR_NONE:
DiegoOstuni 0:75fc82583a41 1630 gNfcip.state = NFCIP_ST_TARG_DEP_RX; /* All OK, goto Rx state */
DiegoOstuni 0:75fc82583a41 1631 }
DiegoOstuni 0:75fc82583a41 1632 /* fall through */
DiegoOstuni 0:75fc82583a41 1633
DiegoOstuni 0:75fc82583a41 1634 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 1635 case NFCIP_ST_TARG_DEP_RX:
DiegoOstuni 0:75fc82583a41 1636
DiegoOstuni 0:75fc82583a41 1637 if( gNfcip.isReqPending ) /* if already has Data should be from a DEP from nfcipTargetHandleActivation() */
DiegoOstuni 0:75fc82583a41 1638 {
DiegoOstuni 0:75fc82583a41 1639 nfcipLogD( " NFCIP(T) Skipping Rx Using DEP from Activation \r\n" );
DiegoOstuni 0:75fc82583a41 1640
DiegoOstuni 0:75fc82583a41 1641 gNfcip.isReqPending = false;
DiegoOstuni 0:75fc82583a41 1642 ret = ERR_NONE;
DiegoOstuni 0:75fc82583a41 1643 }
DiegoOstuni 0:75fc82583a41 1644 else
DiegoOstuni 0:75fc82583a41 1645 {
DiegoOstuni 0:75fc82583a41 1646 ret = nfcipDataRx();
DiegoOstuni 0:75fc82583a41 1647 }
DiegoOstuni 0:75fc82583a41 1648
DiegoOstuni 0:75fc82583a41 1649 if( ret != ERR_NO_MASK(ERR_BUSY) )
DiegoOstuni 0:75fc82583a41 1650 {
DiegoOstuni 0:75fc82583a41 1651 ret = nfcipTargetHandleRX( ret, outActRxLen, outIsChaining, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ;
DiegoOstuni 0:75fc82583a41 1652 }
DiegoOstuni 0:75fc82583a41 1653
DiegoOstuni 0:75fc82583a41 1654 break;
DiegoOstuni 0:75fc82583a41 1655
DiegoOstuni 0:75fc82583a41 1656 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 1657 default:
DiegoOstuni 0:75fc82583a41 1658 break;
DiegoOstuni 0:75fc82583a41 1659 }
DiegoOstuni 0:75fc82583a41 1660 return ret;
DiegoOstuni 0:75fc82583a41 1661 }
DiegoOstuni 0:75fc82583a41 1662
DiegoOstuni 0:75fc82583a41 1663
DiegoOstuni 0:75fc82583a41 1664 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 1665 void rfalNfcDepSetDeactivatingCallback( rfalNfcDepDeactCallback pFunc )
DiegoOstuni 0:75fc82583a41 1666 {
DiegoOstuni 0:75fc82583a41 1667 gNfcip.isDeactivating = pFunc;
DiegoOstuni 0:75fc82583a41 1668 }
DiegoOstuni 0:75fc82583a41 1669
DiegoOstuni 0:75fc82583a41 1670
DiegoOstuni 0:75fc82583a41 1671 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 1672 void rfalNfcDepInitialize( void )
DiegoOstuni 0:75fc82583a41 1673 {
DiegoOstuni 0:75fc82583a41 1674 nfcipLogD( " NFCIP Ini() \r\n" );
DiegoOstuni 0:75fc82583a41 1675
DiegoOstuni 0:75fc82583a41 1676 gNfcip.state = NFCIP_ST_IDLE;
DiegoOstuni 0:75fc82583a41 1677 gNfcip.isDeactivating = NULL;
DiegoOstuni 0:75fc82583a41 1678
DiegoOstuni 0:75fc82583a41 1679 gNfcip.isTxPending = false;
DiegoOstuni 0:75fc82583a41 1680 gNfcip.isWait4RTOX = false;
DiegoOstuni 0:75fc82583a41 1681 gNfcip.isReqPending = false;
DiegoOstuni 0:75fc82583a41 1682
DiegoOstuni 0:75fc82583a41 1683
DiegoOstuni 0:75fc82583a41 1684 gNfcip.cfg.oper = (RFAL_NFCDEP_OPER_FULL_MI_DIS | RFAL_NFCDEP_OPER_EMPTY_DEP_EN | RFAL_NFCDEP_OPER_ATN_EN | RFAL_NFCDEP_OPER_RTOX_REQ_EN);
DiegoOstuni 0:75fc82583a41 1685
DiegoOstuni 0:75fc82583a41 1686 gNfcip.cfg.did = RFAL_NFCDEP_DID_NO;
DiegoOstuni 0:75fc82583a41 1687 gNfcip.cfg.nad = RFAL_NFCDEP_NAD_NO;
DiegoOstuni 0:75fc82583a41 1688
DiegoOstuni 0:75fc82583a41 1689 gNfcip.cfg.br = RFAL_NFCDEP_Bx_NO_HIGH_BR;
DiegoOstuni 0:75fc82583a41 1690 gNfcip.cfg.bs = RFAL_NFCDEP_Bx_NO_HIGH_BR;
DiegoOstuni 0:75fc82583a41 1691
DiegoOstuni 0:75fc82583a41 1692 gNfcip.cfg.lr = RFAL_NFCDEP_LR_254;
DiegoOstuni 0:75fc82583a41 1693 gNfcip.fsc = rfalNfcDepLR2FS( gNfcip.cfg.lr );
DiegoOstuni 0:75fc82583a41 1694
DiegoOstuni 0:75fc82583a41 1695 gNfcip.cfg.gbLen = 0;
DiegoOstuni 0:75fc82583a41 1696
DiegoOstuni 0:75fc82583a41 1697 gNfcip.cfg.fwt = RFAL_NFCDEP_MAX_FWT;
DiegoOstuni 0:75fc82583a41 1698 gNfcip.cfg.dFwt = RFAL_NFCDEP_MAX_FWT;
DiegoOstuni 0:75fc82583a41 1699
DiegoOstuni 0:75fc82583a41 1700 gNfcip.pni = 0;
DiegoOstuni 0:75fc82583a41 1701 gNfcip.RTOXTimer = 0;
DiegoOstuni 0:75fc82583a41 1702
DiegoOstuni 0:75fc82583a41 1703 nfcipClearCounters();
DiegoOstuni 0:75fc82583a41 1704 }
DiegoOstuni 0:75fc82583a41 1705
DiegoOstuni 0:75fc82583a41 1706
DiegoOstuni 0:75fc82583a41 1707 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 1708 static void nfcipSetDEPParams( rfalNfcDepDEPParams *DEPParams )
DiegoOstuni 0:75fc82583a41 1709 {
DiegoOstuni 0:75fc82583a41 1710 nfcipLogD( " NFCIP SetDEP() txLen: %d \r\n", DEPParams->txBufLen );
DiegoOstuni 0:75fc82583a41 1711
DiegoOstuni 0:75fc82583a41 1712 gNfcip.isTxChaining = DEPParams->txChaining;
DiegoOstuni 0:75fc82583a41 1713 gNfcip.txBuf = DEPParams->txBuf;
DiegoOstuni 0:75fc82583a41 1714 gNfcip.rxBuf = DEPParams->rxBuf;
DiegoOstuni 0:75fc82583a41 1715 gNfcip.txBufLen = DEPParams->txBufLen;
DiegoOstuni 0:75fc82583a41 1716 gNfcip.rxBufLen = DEPParams->rxBufLen;
DiegoOstuni 0:75fc82583a41 1717 gNfcip.txBufPaylPos = DEPParams->txBufPaylPos;
DiegoOstuni 0:75fc82583a41 1718 gNfcip.rxBufPaylPos = DEPParams->rxBufPaylPos;
DiegoOstuni 0:75fc82583a41 1719
DiegoOstuni 0:75fc82583a41 1720 if( DEPParams->did != RFAL_NFCDEP_DID_KEEP )
DiegoOstuni 0:75fc82583a41 1721 {
DiegoOstuni 0:75fc82583a41 1722 gNfcip.cfg.did = nfcip_DIDMax( DEPParams->did );
DiegoOstuni 0:75fc82583a41 1723 }
DiegoOstuni 0:75fc82583a41 1724
DiegoOstuni 0:75fc82583a41 1725 gNfcip.cfg.fwt = DEPParams->fwt;
DiegoOstuni 0:75fc82583a41 1726 gNfcip.cfg.dFwt = DEPParams->dFwt;
DiegoOstuni 0:75fc82583a41 1727 gNfcip.fsc = DEPParams->fsc;
DiegoOstuni 0:75fc82583a41 1728
DiegoOstuni 0:75fc82583a41 1729
DiegoOstuni 0:75fc82583a41 1730
DiegoOstuni 0:75fc82583a41 1731 if(gNfcip.cfg.role == RFAL_NFCDEP_ROLE_TARGET)
DiegoOstuni 0:75fc82583a41 1732 {
DiegoOstuni 0:75fc82583a41 1733 /* If there's any data to be sent go for Tx */
DiegoOstuni 0:75fc82583a41 1734 if(DEPParams->txBufLen > 0)
DiegoOstuni 0:75fc82583a41 1735 {
DiegoOstuni 0:75fc82583a41 1736 /* Ensure that an RTOX Ack is not being expected at moment */
DiegoOstuni 0:75fc82583a41 1737 if( !gNfcip.isWait4RTOX )
DiegoOstuni 0:75fc82583a41 1738 {
DiegoOstuni 0:75fc82583a41 1739 gNfcip.state = NFCIP_ST_TARG_DEP_TX;
DiegoOstuni 0:75fc82583a41 1740 return;
DiegoOstuni 0:75fc82583a41 1741 }
DiegoOstuni 0:75fc82583a41 1742 else
DiegoOstuni 0:75fc82583a41 1743 {
DiegoOstuni 0:75fc82583a41 1744 /* If RTOX Ack is expected, signal a pending Tx to be transmitted right after */
DiegoOstuni 0:75fc82583a41 1745 gNfcip.isTxPending = true;
DiegoOstuni 0:75fc82583a41 1746 nfcipLogW( " NFCIP(T) Waiting RTOX, queueing outgoing DEP Block \r\n" );
DiegoOstuni 0:75fc82583a41 1747 }
DiegoOstuni 0:75fc82583a41 1748 }
DiegoOstuni 0:75fc82583a41 1749
DiegoOstuni 0:75fc82583a41 1750 /*Digital 1.0 14.12.4.1 In target mode the first PDU MUST be sent by the Initiator */
DiegoOstuni 0:75fc82583a41 1751 gNfcip.state = NFCIP_ST_TARG_DEP_RX;
DiegoOstuni 0:75fc82583a41 1752 return;
DiegoOstuni 0:75fc82583a41 1753 }
DiegoOstuni 0:75fc82583a41 1754
DiegoOstuni 0:75fc82583a41 1755 /* New data TxRx request clear previous error counters for consecutive TxRx without reseting communication/protocol layer*/
DiegoOstuni 0:75fc82583a41 1756 nfcipClearCounters();
DiegoOstuni 0:75fc82583a41 1757
DiegoOstuni 0:75fc82583a41 1758 gNfcip.state = NFCIP_ST_INIT_DEP_TX;
DiegoOstuni 0:75fc82583a41 1759 }
DiegoOstuni 0:75fc82583a41 1760
DiegoOstuni 0:75fc82583a41 1761
DiegoOstuni 0:75fc82583a41 1762 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 1763 bool rfalNfcDepTargetRcvdATR( void )
DiegoOstuni 0:75fc82583a41 1764 {
DiegoOstuni 0:75fc82583a41 1765 return ( (gNfcip.cfg.role == RFAL_NFCDEP_ROLE_TARGET) && nfcipIsTarget(gNfcip.state) && (gNfcip.state > NFCIP_ST_TARG_WAIT_ATR) );
DiegoOstuni 0:75fc82583a41 1766 }
DiegoOstuni 0:75fc82583a41 1767
DiegoOstuni 0:75fc82583a41 1768
DiegoOstuni 0:75fc82583a41 1769 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 1770 bool rfalNfcDepIsAtrReq( uint8_t* buf, uint16_t bufLen, uint8_t* nfcid3 )
DiegoOstuni 0:75fc82583a41 1771 {
DiegoOstuni 0:75fc82583a41 1772 uint8_t msgIt;
DiegoOstuni 0:75fc82583a41 1773
DiegoOstuni 0:75fc82583a41 1774 msgIt = 0;
DiegoOstuni 0:75fc82583a41 1775
DiegoOstuni 0:75fc82583a41 1776 if ( (bufLen < RFAL_NFCDEP_ATRREQ_MIN_LEN) || (bufLen > RFAL_NFCDEP_ATRREQ_MAX_LEN) )
DiegoOstuni 0:75fc82583a41 1777 {
DiegoOstuni 0:75fc82583a41 1778 return false;
DiegoOstuni 0:75fc82583a41 1779 }
DiegoOstuni 0:75fc82583a41 1780
DiegoOstuni 0:75fc82583a41 1781 if ( *(buf + msgIt++) != NFCIP_REQ )
DiegoOstuni 0:75fc82583a41 1782 {
DiegoOstuni 0:75fc82583a41 1783 return false;
DiegoOstuni 0:75fc82583a41 1784 }
DiegoOstuni 0:75fc82583a41 1785
DiegoOstuni 0:75fc82583a41 1786 if( *(buf + msgIt++) != NFCIP_CMD_ATR_REQ )
DiegoOstuni 0:75fc82583a41 1787 {
DiegoOstuni 0:75fc82583a41 1788 return false;
DiegoOstuni 0:75fc82583a41 1789 }
DiegoOstuni 0:75fc82583a41 1790
DiegoOstuni 0:75fc82583a41 1791 /* Output NFID2 if requested */
DiegoOstuni 0:75fc82583a41 1792 if( nfcid3 != NULL )
DiegoOstuni 0:75fc82583a41 1793 {
DiegoOstuni 0:75fc82583a41 1794 ST_MEMCPY( nfcid3, (uint8_t*)(buf + RFAL_NFCDEP_ATR_REQ_NFCID3_POS), RFAL_NFCDEP_NFCID3_LEN );
DiegoOstuni 0:75fc82583a41 1795 }
DiegoOstuni 0:75fc82583a41 1796
DiegoOstuni 0:75fc82583a41 1797 return true;
DiegoOstuni 0:75fc82583a41 1798 }
DiegoOstuni 0:75fc82583a41 1799
DiegoOstuni 0:75fc82583a41 1800
DiegoOstuni 0:75fc82583a41 1801 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 1802 static ReturnCode nfcipTargetHandleActivation( rfalNfcDepDevice *nfcDepDev, uint8_t *outBRS, SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 )
DiegoOstuni 0:75fc82583a41 1803 {
DiegoOstuni 0:75fc82583a41 1804 ReturnCode ret;
DiegoOstuni 0:75fc82583a41 1805 uint8_t msgIt;
DiegoOstuni 0:75fc82583a41 1806 uint8_t txBuf[RFAL_NFCDEP_HEADER_PAD + NFCIP_PSLRES_LEN];
DiegoOstuni 0:75fc82583a41 1807
DiegoOstuni 0:75fc82583a41 1808 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 1809 /* Check if we are in correct state */
DiegoOstuni 0:75fc82583a41 1810 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 1811 if( gNfcip.state != NFCIP_ST_TARG_WAIT_ACTV )
DiegoOstuni 0:75fc82583a41 1812 {
DiegoOstuni 0:75fc82583a41 1813 return ERR_WRONG_STATE;
DiegoOstuni 0:75fc82583a41 1814 }
DiegoOstuni 0:75fc82583a41 1815
DiegoOstuni 0:75fc82583a41 1816
DiegoOstuni 0:75fc82583a41 1817 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 1818 /* Check required parameters */
DiegoOstuni 0:75fc82583a41 1819 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 1820 if( outBRS == NULL )
DiegoOstuni 0:75fc82583a41 1821 {
DiegoOstuni 0:75fc82583a41 1822 return ERR_PARAM;
DiegoOstuni 0:75fc82583a41 1823 }
DiegoOstuni 0:75fc82583a41 1824
DiegoOstuni 0:75fc82583a41 1825 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 1826 /* Wait and process incoming cmd (PSL / DEP) */
DiegoOstuni 0:75fc82583a41 1827 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 1828 ret = nfcipDataRx();
DiegoOstuni 0:75fc82583a41 1829
DiegoOstuni 0:75fc82583a41 1830 if( ret != ERR_NONE )
DiegoOstuni 0:75fc82583a41 1831 {
DiegoOstuni 0:75fc82583a41 1832 return ret;
DiegoOstuni 0:75fc82583a41 1833 }
DiegoOstuni 0:75fc82583a41 1834
DiegoOstuni 0:75fc82583a41 1835 msgIt = 0;
DiegoOstuni 0:75fc82583a41 1836 *outBRS = RFAL_NFCDEP_BRS_MAINTAIN; /* set out BRS to be maintained */
DiegoOstuni 0:75fc82583a41 1837
DiegoOstuni 0:75fc82583a41 1838 msgIt++; /* Skip LEN byte */
DiegoOstuni 0:75fc82583a41 1839
DiegoOstuni 0:75fc82583a41 1840 if ( *(gNfcip.rxBuf + msgIt++) != NFCIP_REQ )
DiegoOstuni 0:75fc82583a41 1841 {
DiegoOstuni 0:75fc82583a41 1842 return ERR_PROTO;
DiegoOstuni 0:75fc82583a41 1843 }
DiegoOstuni 0:75fc82583a41 1844
DiegoOstuni 0:75fc82583a41 1845 if( *(gNfcip.rxBuf + msgIt) == NFCIP_CMD_PSL_REQ )
DiegoOstuni 0:75fc82583a41 1846 {
DiegoOstuni 0:75fc82583a41 1847 msgIt++;
DiegoOstuni 0:75fc82583a41 1848
DiegoOstuni 0:75fc82583a41 1849 if( *(gNfcip.rxBuf + msgIt++) != gNfcip.cfg.did ) /* Checking DID */
DiegoOstuni 0:75fc82583a41 1850 {
DiegoOstuni 0:75fc82583a41 1851 return ERR_PROTO;
DiegoOstuni 0:75fc82583a41 1852 }
DiegoOstuni 0:75fc82583a41 1853
DiegoOstuni 0:75fc82583a41 1854 nfcipLogI( " NFCIP(T) PSL REQ rcvd \r\n" );
DiegoOstuni 0:75fc82583a41 1855
DiegoOstuni 0:75fc82583a41 1856 *outBRS = *(gNfcip.rxBuf + msgIt++); /* assign output BRS value */
DiegoOstuni 0:75fc82583a41 1857
DiegoOstuni 0:75fc82583a41 1858 /* Store FSL(LR) and update current config */
DiegoOstuni 0:75fc82583a41 1859 gNfcip.cfg.lr = (*(gNfcip.rxBuf + msgIt++) & RFAL_NFCDEP_LR_VAL_MASK);
DiegoOstuni 0:75fc82583a41 1860 gNfcip.fsc = rfalNfcDepLR2FS( gNfcip.cfg.lr );
DiegoOstuni 0:75fc82583a41 1861
DiegoOstuni 0:75fc82583a41 1862 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 1863 /* Update NFC-DDE Device info */
DiegoOstuni 0:75fc82583a41 1864 if( nfcDepDev != NULL )
DiegoOstuni 0:75fc82583a41 1865 {
DiegoOstuni 0:75fc82583a41 1866 /* Update Bitrate info */
DiegoOstuni 0:75fc82583a41 1867 nfcDepDev->info.DSI = (rfalBitRate)rfalNfcDepBRS2DSI( *outBRS ); /* DSI codes the bit rate from Initiator to Target */
DiegoOstuni 0:75fc82583a41 1868 nfcDepDev->info.DRI = (rfalBitRate)rfalNfcDepBRS2DRI( *outBRS ); /* DRI codes the bit rate from Target to Initiator */
DiegoOstuni 0:75fc82583a41 1869
DiegoOstuni 0:75fc82583a41 1870 /* Update Length Reduction and Frame Size */
DiegoOstuni 0:75fc82583a41 1871 nfcDepDev->info.LR = gNfcip.cfg.lr;
DiegoOstuni 0:75fc82583a41 1872 nfcDepDev->info.FS = gNfcip.fsc;
DiegoOstuni 0:75fc82583a41 1873
DiegoOstuni 0:75fc82583a41 1874 /* Update PPi byte */
DiegoOstuni 0:75fc82583a41 1875 nfcDepDev->activation.Initiator.ATR_REQ.PPi &= ~RFAL_NFCDEP_PP_LR_MASK;
DiegoOstuni 0:75fc82583a41 1876 nfcDepDev->activation.Initiator.ATR_REQ.PPi |= rfalNfcDepLR2PP( gNfcip.cfg.lr );
DiegoOstuni 0:75fc82583a41 1877 }
DiegoOstuni 0:75fc82583a41 1878
DiegoOstuni 0:75fc82583a41 1879 EXIT_ON_ERR( ret, nfcipTx( NFCIP_CMD_PSL_RES, txBuf, 0, 0, 0, NFCIP_NO_FWT, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) );
DiegoOstuni 0:75fc82583a41 1880 }
DiegoOstuni 0:75fc82583a41 1881 else
DiegoOstuni 0:75fc82583a41 1882 {
DiegoOstuni 0:75fc82583a41 1883 if( *(gNfcip.rxBuf + msgIt) == NFCIP_CMD_DEP_REQ )
DiegoOstuni 0:75fc82583a41 1884 {
DiegoOstuni 0:75fc82583a41 1885 msgIt++;
DiegoOstuni 0:75fc82583a41 1886
DiegoOstuni 0:75fc82583a41 1887 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 1888 /* Digital 1.0 14.12.3.1 PNI must be initialized to 0 */
DiegoOstuni 0:75fc82583a41 1889 if( nfcip_PBF_PNI( *(gNfcip.rxBuf + msgIt) ) != 0 )
DiegoOstuni 0:75fc82583a41 1890 {
DiegoOstuni 0:75fc82583a41 1891 return ERR_PROTO;
DiegoOstuni 0:75fc82583a41 1892 }
DiegoOstuni 0:75fc82583a41 1893
DiegoOstuni 0:75fc82583a41 1894 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 1895 /* Digital 1.0 14.8.2.1 check if DID is expected and match -> Protocol Error */
DiegoOstuni 0:75fc82583a41 1896 if( nfcip_PFBhasDID( *(gNfcip.rxBuf + msgIt) ) )
DiegoOstuni 0:75fc82583a41 1897 {
DiegoOstuni 0:75fc82583a41 1898 if( *(gNfcip.rxBuf + (++msgIt)) != gNfcip.cfg.did)
DiegoOstuni 0:75fc82583a41 1899 {
DiegoOstuni 0:75fc82583a41 1900 return ERR_PROTO;
DiegoOstuni 0:75fc82583a41 1901 }
DiegoOstuni 0:75fc82583a41 1902 }
DiegoOstuni 0:75fc82583a41 1903 else if( gNfcip.cfg.did != RFAL_NFCDEP_DID_NO ) /* DID expected but not rcv */
DiegoOstuni 0:75fc82583a41 1904 {
DiegoOstuni 0:75fc82583a41 1905 return ERR_PROTO;
DiegoOstuni 0:75fc82583a41 1906 }
DiegoOstuni 0:75fc82583a41 1907 }
DiegoOstuni 0:75fc82583a41 1908
DiegoOstuni 0:75fc82583a41 1909 /* Signal Request pending to be digested on normal Handling (DEP_REQ, DSL_REQ, RLS_REQ) */
DiegoOstuni 0:75fc82583a41 1910 gNfcip.isReqPending = true;
DiegoOstuni 0:75fc82583a41 1911 }
DiegoOstuni 0:75fc82583a41 1912
DiegoOstuni 0:75fc82583a41 1913 gNfcip.state = NFCIP_ST_TARG_DEP_RX;
DiegoOstuni 0:75fc82583a41 1914 return ERR_NONE;
DiegoOstuni 0:75fc82583a41 1915 }
DiegoOstuni 0:75fc82583a41 1916
DiegoOstuni 0:75fc82583a41 1917
DiegoOstuni 0:75fc82583a41 1918 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 1919 ReturnCode rfalNfcDepATR( rfalNfcDepAtrParam* param, rfalNfcDepAtrRes *atrRes,
DiegoOstuni 0:75fc82583a41 1920 uint8_t* atrResLen, SPI* mspiChannel, ST25R3911* mST25,
DiegoOstuni 0:75fc82583a41 1921 DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01,
DiegoOstuni 0:75fc82583a41 1922 DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04,
DiegoOstuni 0:75fc82583a41 1923 DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 )
DiegoOstuni 0:75fc82583a41 1924 {
DiegoOstuni 0:75fc82583a41 1925 ReturnCode ret;
DiegoOstuni 0:75fc82583a41 1926 rfalNfcDepConfigs cfg;
DiegoOstuni 0:75fc82583a41 1927 uint16_t rxLen;
DiegoOstuni 0:75fc82583a41 1928 uint8_t msgIt;
DiegoOstuni 0:75fc82583a41 1929
DiegoOstuni 0:75fc82583a41 1930
DiegoOstuni 0:75fc82583a41 1931
DiegoOstuni 0:75fc82583a41 1932 if( (param == NULL) || (atrRes == NULL) || (atrResLen == NULL) )
DiegoOstuni 0:75fc82583a41 1933 {
DiegoOstuni 0:75fc82583a41 1934 return ERR_PARAM;
DiegoOstuni 0:75fc82583a41 1935 }
DiegoOstuni 0:75fc82583a41 1936
DiegoOstuni 0:75fc82583a41 1937 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 1938 /* Configure NFC-DEP layer */
DiegoOstuni 0:75fc82583a41 1939 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 1940
DiegoOstuni 0:75fc82583a41 1941 cfg.did = param->DID;
DiegoOstuni 0:75fc82583a41 1942 cfg.nad = param->NAD;
DiegoOstuni 0:75fc82583a41 1943 cfg.fwt = RFAL_NFCDEP_MAX_FWT;
DiegoOstuni 0:75fc82583a41 1944 cfg.dFwt = RFAL_NFCDEP_MAX_FWT;
DiegoOstuni 0:75fc82583a41 1945 cfg.br = param->BR;
DiegoOstuni 0:75fc82583a41 1946 cfg.bs = param->BS;
DiegoOstuni 0:75fc82583a41 1947 cfg.lr = param->LR;
DiegoOstuni 0:75fc82583a41 1948 cfg.to = RFAL_NFCDEP_WT_TRG_MAX; /* Not used in Initiator mode */
DiegoOstuni 0:75fc82583a41 1949
DiegoOstuni 0:75fc82583a41 1950
DiegoOstuni 0:75fc82583a41 1951 cfg.gbLen = param->GBLen;
DiegoOstuni 0:75fc82583a41 1952 ST_MEMCPY( cfg.gb, param->GB, cfg.gbLen );
DiegoOstuni 0:75fc82583a41 1953
DiegoOstuni 0:75fc82583a41 1954 cfg.nfcidLen = param->nfcidLen;
DiegoOstuni 0:75fc82583a41 1955 ST_MEMCPY( cfg.nfcid, param->nfcid, param->nfcidLen );
DiegoOstuni 0:75fc82583a41 1956
DiegoOstuni 0:75fc82583a41 1957 cfg.role = RFAL_NFCDEP_ROLE_INITIATOR;
DiegoOstuni 0:75fc82583a41 1958 cfg.oper = param->operParam;
DiegoOstuni 0:75fc82583a41 1959 cfg.commMode = param->commMode;
DiegoOstuni 0:75fc82583a41 1960
DiegoOstuni 0:75fc82583a41 1961 rfalNfcDepInitialize();
DiegoOstuni 0:75fc82583a41 1962 nfcipConfig( cfg );
DiegoOstuni 0:75fc82583a41 1963
DiegoOstuni 0:75fc82583a41 1964 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 1965 /* Send ATR_REQ */
DiegoOstuni 0:75fc82583a41 1966 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 1967
DiegoOstuni 0:75fc82583a41 1968 EXIT_ON_ERR( ret, nfcipTxRx(NFCIP_CMD_ATR_REQ, txBuf, NFCIP_RWT_ACTIVATION, NULL,
DiegoOstuni 0:75fc82583a41 1969 0, rxBuf, NFCIP_ATRRES_BUF_LEN, &rxLen, mspiChannel, mST25, gpio_cs,
DiegoOstuni 0:75fc82583a41 1970 IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) );
DiegoOstuni 0:75fc82583a41 1971
DiegoOstuni 0:75fc82583a41 1972
DiegoOstuni 0:75fc82583a41 1973 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 1974 /* ATR sent, check response */
DiegoOstuni 0:75fc82583a41 1975 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 1976 msgIt = 0;
DiegoOstuni 0:75fc82583a41 1977 rxLen = (uint16_t)(*(rxBuf + msgIt++) - RFAL_NFCDEP_LEN_LEN); /* use LEN byte */
DiegoOstuni 0:75fc82583a41 1978
DiegoOstuni 0:75fc82583a41 1979 if( (rxLen < RFAL_NFCDEP_ATRRES_MIN_LEN) || (rxLen > RFAL_NFCDEP_ATRRES_MAX_LEN) ) /* Checking length: ATR_RES */
DiegoOstuni 0:75fc82583a41 1980 {
DiegoOstuni 0:75fc82583a41 1981 return ERR_PROTO;
DiegoOstuni 0:75fc82583a41 1982 }
DiegoOstuni 0:75fc82583a41 1983
DiegoOstuni 0:75fc82583a41 1984 if( *(rxBuf + msgIt++) != NFCIP_RES ) /* Checking if is a response*/
DiegoOstuni 0:75fc82583a41 1985 {
DiegoOstuni 0:75fc82583a41 1986 return ERR_PROTO;
DiegoOstuni 0:75fc82583a41 1987 }
DiegoOstuni 0:75fc82583a41 1988
DiegoOstuni 0:75fc82583a41 1989 if( *(rxBuf + msgIt++) != NFCIP_CMD_ATR_RES ) /* Checking if is a ATR RES */
DiegoOstuni 0:75fc82583a41 1990 {
DiegoOstuni 0:75fc82583a41 1991 return ERR_PROTO;
DiegoOstuni 0:75fc82583a41 1992 }
DiegoOstuni 0:75fc82583a41 1993
DiegoOstuni 0:75fc82583a41 1994 ST_MEMCPY(atrRes, (rxBuf + RFAL_NFCDEP_LEN_LEN), rxLen);
DiegoOstuni 0:75fc82583a41 1995 *atrResLen = (uint8_t)rxLen;
DiegoOstuni 0:75fc82583a41 1996
DiegoOstuni 0:75fc82583a41 1997 return ERR_NONE;
DiegoOstuni 0:75fc82583a41 1998 }
DiegoOstuni 0:75fc82583a41 1999
DiegoOstuni 0:75fc82583a41 2000
DiegoOstuni 0:75fc82583a41 2001 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 2002 ReturnCode rfalNfcDepPSL( uint8_t BRS, uint8_t FSL, SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 )
DiegoOstuni 0:75fc82583a41 2003 {
DiegoOstuni 0:75fc82583a41 2004 ReturnCode ret;
DiegoOstuni 0:75fc82583a41 2005 uint16_t rxLen;
DiegoOstuni 0:75fc82583a41 2006 uint8_t msgIt;
DiegoOstuni 0:75fc82583a41 2007
DiegoOstuni 0:75fc82583a41 2008
DiegoOstuni 0:75fc82583a41 2009 msgIt = 0;
DiegoOstuni 0:75fc82583a41 2010
DiegoOstuni 0:75fc82583a41 2011
DiegoOstuni 0:75fc82583a41 2012 //changed here in plsbufPSL
DiegoOstuni 0:75fc82583a41 2013 pslBufPSL[msgIt++] = BRS;
DiegoOstuni 0:75fc82583a41 2014 pslBufPSL[msgIt++] = FSL;
DiegoOstuni 0:75fc82583a41 2015
DiegoOstuni 0:75fc82583a41 2016 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 2017 /* Send PSL REQ and wait for response */
DiegoOstuni 0:75fc82583a41 2018 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 2019 EXIT_ON_ERR( ret, nfcipTxRx( NFCIP_CMD_PSL_REQ, txBufPSL, NFCIP_RWT_ACTIVATION, pslBufPSL, msgIt, rxBufPSL, NFCIP_PSLRES_LEN, &rxLen, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) );
DiegoOstuni 0:75fc82583a41 2020
DiegoOstuni 0:75fc82583a41 2021
DiegoOstuni 0:75fc82583a41 2022 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 2023 /* PSL sent, check response */
DiegoOstuni 0:75fc82583a41 2024 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 2025 msgIt = 0;
DiegoOstuni 0:75fc82583a41 2026 rxLen = (uint16_t)(*(rxBuf + msgIt++) ); /* use LEN byte */
DiegoOstuni 0:75fc82583a41 2027
DiegoOstuni 0:75fc82583a41 2028 if( rxLen < NFCIP_PSLRES_LEN ) /* Checking length: LEN + RLS_RES */
DiegoOstuni 0:75fc82583a41 2029 {
DiegoOstuni 0:75fc82583a41 2030 return ERR_PROTO;
DiegoOstuni 0:75fc82583a41 2031 }
DiegoOstuni 0:75fc82583a41 2032
DiegoOstuni 0:75fc82583a41 2033 if( *(rxBuf + msgIt++) != NFCIP_RES ) /* Checking if is a response */
DiegoOstuni 0:75fc82583a41 2034 {
DiegoOstuni 0:75fc82583a41 2035 return ERR_PROTO;
DiegoOstuni 0:75fc82583a41 2036 }
DiegoOstuni 0:75fc82583a41 2037
DiegoOstuni 0:75fc82583a41 2038 if( *(rxBuf + msgIt++) != NFCIP_CMD_PSL_RES ) /* Checking if is a PSL RES */
DiegoOstuni 0:75fc82583a41 2039 {
DiegoOstuni 0:75fc82583a41 2040 return ERR_PROTO;
DiegoOstuni 0:75fc82583a41 2041 }
DiegoOstuni 0:75fc82583a41 2042
DiegoOstuni 0:75fc82583a41 2043 if( *(rxBuf + msgIt++) != gNfcip.cfg.did ) /* Checking DID */
DiegoOstuni 0:75fc82583a41 2044 {
DiegoOstuni 0:75fc82583a41 2045 return ERR_PROTO;
DiegoOstuni 0:75fc82583a41 2046 }
DiegoOstuni 0:75fc82583a41 2047
DiegoOstuni 0:75fc82583a41 2048 return ERR_NONE;
DiegoOstuni 0:75fc82583a41 2049 }
DiegoOstuni 0:75fc82583a41 2050
DiegoOstuni 0:75fc82583a41 2051
DiegoOstuni 0:75fc82583a41 2052 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 2053 ReturnCode rfalNfcDepDSL( SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 )
DiegoOstuni 0:75fc82583a41 2054 {
DiegoOstuni 0:75fc82583a41 2055 ReturnCode ret;
DiegoOstuni 0:75fc82583a41 2056
DiegoOstuni 0:75fc82583a41 2057 uint8_t rxMsgIt;
DiegoOstuni 0:75fc82583a41 2058 uint16_t rxLen = 0;
DiegoOstuni 0:75fc82583a41 2059
DiegoOstuni 0:75fc82583a41 2060 if( gNfcip.cfg.role == RFAL_NFCDEP_ROLE_TARGET )
DiegoOstuni 0:75fc82583a41 2061 {
DiegoOstuni 0:75fc82583a41 2062 return ERR_NONE; /* Target has no deselect procedure */
DiegoOstuni 0:75fc82583a41 2063 }
DiegoOstuni 0:75fc82583a41 2064
DiegoOstuni 0:75fc82583a41 2065 /* Repeating a DSL REQ is optional, not doing it */
DiegoOstuni 0:75fc82583a41 2066 EXIT_ON_ERR( ret, nfcipTxRx( NFCIP_CMD_DSL_REQ, txBufDSL, NFCIP_RWT_ACTIVATION, 0, 0, rxBufDSL, RFAL_NFCDEP_ATRRES_MAX_LEN, &rxLen, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) );
DiegoOstuni 0:75fc82583a41 2067
DiegoOstuni 0:75fc82583a41 2068 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 2069 rxMsgIt = 0;
DiegoOstuni 0:75fc82583a41 2070
DiegoOstuni 0:75fc82583a41 2071 if( *(rxBuf + rxMsgIt++) < NFCIP_DSLRES_MIN ) /* Checking length: LEN + DSL_RES */
DiegoOstuni 0:75fc82583a41 2072 {
DiegoOstuni 0:75fc82583a41 2073 return ERR_PROTO;
DiegoOstuni 0:75fc82583a41 2074 }
DiegoOstuni 0:75fc82583a41 2075
DiegoOstuni 0:75fc82583a41 2076 if( *(rxBuf + rxMsgIt++) != NFCIP_RES ) /* Checking if is a response */
DiegoOstuni 0:75fc82583a41 2077 {
DiegoOstuni 0:75fc82583a41 2078 return ERR_PROTO;
DiegoOstuni 0:75fc82583a41 2079 }
DiegoOstuni 0:75fc82583a41 2080
DiegoOstuni 0:75fc82583a41 2081 if( *(rxBuf + rxMsgIt++) != NFCIP_CMD_DSL_RES ) /* Checking if is DSL RES */
DiegoOstuni 0:75fc82583a41 2082 {
DiegoOstuni 0:75fc82583a41 2083 return ERR_PROTO;
DiegoOstuni 0:75fc82583a41 2084 }
DiegoOstuni 0:75fc82583a41 2085
DiegoOstuni 0:75fc82583a41 2086 if( (gNfcip.cfg.did != RFAL_NFCDEP_DID_NO) && (*(rxBuf + rxMsgIt++) != gNfcip.cfg.did ) )
DiegoOstuni 0:75fc82583a41 2087 {
DiegoOstuni 0:75fc82583a41 2088 return ERR_PROTO;
DiegoOstuni 0:75fc82583a41 2089 }
DiegoOstuni 0:75fc82583a41 2090
DiegoOstuni 0:75fc82583a41 2091 return ERR_NONE;
DiegoOstuni 0:75fc82583a41 2092 }
DiegoOstuni 0:75fc82583a41 2093
DiegoOstuni 0:75fc82583a41 2094
DiegoOstuni 0:75fc82583a41 2095 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 2096 ReturnCode rfalNfcDepRLS( SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 )
DiegoOstuni 0:75fc82583a41 2097 {
DiegoOstuni 0:75fc82583a41 2098 ReturnCode ret;
DiegoOstuni 0:75fc82583a41 2099
DiegoOstuni 0:75fc82583a41 2100 uint8_t rxMsgIt;
DiegoOstuni 0:75fc82583a41 2101 uint16_t rxLen = 0;
DiegoOstuni 0:75fc82583a41 2102
DiegoOstuni 0:75fc82583a41 2103 if( gNfcip.cfg.role == RFAL_NFCDEP_ROLE_TARGET )
DiegoOstuni 0:75fc82583a41 2104 return ERR_NONE; /* Target has no release procedure */
DiegoOstuni 0:75fc82583a41 2105
DiegoOstuni 0:75fc82583a41 2106 /* Repeating a RLS REQ is optional, not doing it */
DiegoOstuni 0:75fc82583a41 2107 EXIT_ON_ERR( ret, nfcipTxRx( NFCIP_CMD_RLS_REQ, txBufRLS, NFCIP_RWT_ACTIVATION, 0, 0, rxBufRLS, RFAL_NFCDEP_ATRRES_MAX_LEN, &rxLen, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) );
DiegoOstuni 0:75fc82583a41 2108
DiegoOstuni 0:75fc82583a41 2109 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 2110 rxMsgIt = 0;
DiegoOstuni 0:75fc82583a41 2111
DiegoOstuni 0:75fc82583a41 2112 if( *(rxBuf + rxMsgIt++) < NFCIP_RLSRES_MIN ) /* Checking length: LEN + RLS_RES */
DiegoOstuni 0:75fc82583a41 2113 {
DiegoOstuni 0:75fc82583a41 2114 return ERR_PROTO;
DiegoOstuni 0:75fc82583a41 2115 }
DiegoOstuni 0:75fc82583a41 2116
DiegoOstuni 0:75fc82583a41 2117 if( *(rxBuf + rxMsgIt++) != NFCIP_RES ) /* Checking if is a response */
DiegoOstuni 0:75fc82583a41 2118 {
DiegoOstuni 0:75fc82583a41 2119 return ERR_PROTO;
DiegoOstuni 0:75fc82583a41 2120 }
DiegoOstuni 0:75fc82583a41 2121
DiegoOstuni 0:75fc82583a41 2122 if( *(rxBuf + rxMsgIt++) != NFCIP_CMD_RLS_RES ) /* Checking if is RLS RES */
DiegoOstuni 0:75fc82583a41 2123 {
DiegoOstuni 0:75fc82583a41 2124 return ERR_PROTO;
DiegoOstuni 0:75fc82583a41 2125 }
DiegoOstuni 0:75fc82583a41 2126
DiegoOstuni 0:75fc82583a41 2127 if( (gNfcip.cfg.did != RFAL_NFCDEP_DID_NO) && (*(rxBuf + rxMsgIt++) != gNfcip.cfg.did ) )
DiegoOstuni 0:75fc82583a41 2128 {
DiegoOstuni 0:75fc82583a41 2129 return ERR_PROTO;
DiegoOstuni 0:75fc82583a41 2130 }
DiegoOstuni 0:75fc82583a41 2131
DiegoOstuni 0:75fc82583a41 2132 return ERR_NONE;
DiegoOstuni 0:75fc82583a41 2133 }
DiegoOstuni 0:75fc82583a41 2134
DiegoOstuni 0:75fc82583a41 2135
DiegoOstuni 0:75fc82583a41 2136 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 2137 ReturnCode rfalNfcDepInitiatorHandleActivation( rfalNfcDepAtrParam* param, rfalBitRate desiredBR, rfalNfcDepDevice* nfcDepDev, SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 )
DiegoOstuni 0:75fc82583a41 2138 {
DiegoOstuni 0:75fc82583a41 2139 ReturnCode ret;
DiegoOstuni 0:75fc82583a41 2140 uint8_t maxRetyrs;
DiegoOstuni 0:75fc82583a41 2141 uint8_t PSL_BRS;
DiegoOstuni 0:75fc82583a41 2142 uint8_t PSL_FSL;
DiegoOstuni 0:75fc82583a41 2143 bool sendPSL;
DiegoOstuni 0:75fc82583a41 2144
DiegoOstuni 0:75fc82583a41 2145 if( (param == NULL) || (nfcDepDev == NULL) )
DiegoOstuni 0:75fc82583a41 2146 {
DiegoOstuni 0:75fc82583a41 2147 return ERR_PARAM;
DiegoOstuni 0:75fc82583a41 2148 }
DiegoOstuni 0:75fc82583a41 2149
DiegoOstuni 0:75fc82583a41 2150 param->NAD = RFAL_NFCDEP_NAD_NO; /* Digital 1.1 16.6.2.9 Initiator SHALL NOT use NAD */
DiegoOstuni 0:75fc82583a41 2151 maxRetyrs = NFCIP_ATR_RETRY_MAX;
DiegoOstuni 0:75fc82583a41 2152
DiegoOstuni 0:75fc82583a41 2153 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 2154 /* Send ATR REQ and wait for response */
DiegoOstuni 0:75fc82583a41 2155 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 2156 do{ /* Upon transmission error ATR REQ should be retried */
DiegoOstuni 0:75fc82583a41 2157
DiegoOstuni 0:75fc82583a41 2158 ret = rfalNfcDepATR( param, &nfcDepDev->activation.Target.ATR_RES, &nfcDepDev->activation.Target.ATR_RESLen,
DiegoOstuni 0:75fc82583a41 2159 mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04,
DiegoOstuni 0:75fc82583a41 2160 fieldLED_05, fieldLED_06 ) ;
DiegoOstuni 0:75fc82583a41 2161
DiegoOstuni 0:75fc82583a41 2162 if( nfcipIsTransmissionError(ret) )
DiegoOstuni 0:75fc82583a41 2163 {
DiegoOstuni 0:75fc82583a41 2164 continue;
DiegoOstuni 0:75fc82583a41 2165 }
DiegoOstuni 0:75fc82583a41 2166 break;
DiegoOstuni 0:75fc82583a41 2167 }
DiegoOstuni 0:75fc82583a41 2168 while( (maxRetyrs--) );
DiegoOstuni 0:75fc82583a41 2169
DiegoOstuni 0:75fc82583a41 2170 if( ERR_NO_MASK(ret) != ERR_NONE )
DiegoOstuni 0:75fc82583a41 2171 {
DiegoOstuni 0:75fc82583a41 2172 return ret;
DiegoOstuni 0:75fc82583a41 2173 }
DiegoOstuni 0:75fc82583a41 2174
DiegoOstuni 0:75fc82583a41 2175 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 2176 /* Compute NFC-DEP device with ATR_RES */
DiegoOstuni 0:75fc82583a41 2177 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 2178 nfcDepDev->info.GBLen = (nfcDepDev->activation.Target.ATR_RESLen - RFAL_NFCDEP_ATRRES_MIN_LEN);
DiegoOstuni 0:75fc82583a41 2179 nfcDepDev->info.DID = nfcDepDev->activation.Target.ATR_RES.DID;
DiegoOstuni 0:75fc82583a41 2180 nfcDepDev->info.NAD = RFAL_NFCDEP_NAD_NO; /* Digital 1.1 16.6.3.11 Initiator SHALL ignore b1 of PPt */
DiegoOstuni 0:75fc82583a41 2181 nfcDepDev->info.LR = rfalNfcDepPP2LR( nfcDepDev->activation.Target.ATR_RES.PPt );
DiegoOstuni 0:75fc82583a41 2182 nfcDepDev->info.FS = rfalNfcDepLR2FS( nfcDepDev->info.LR );
DiegoOstuni 0:75fc82583a41 2183 nfcDepDev->info.WT = (nfcDepDev->activation.Target.ATR_RES.TO & RFAL_NFCDEP_WT_MASK);
DiegoOstuni 0:75fc82583a41 2184 nfcDepDev->info.FWT = rfalNfcDepCalculateRWT( nfcDepDev->info.WT );
DiegoOstuni 0:75fc82583a41 2185 nfcDepDev->info.dFWT = rfalNfcDepCalculateRWT( RFAL_NFCDEP_WT_DELTA );
DiegoOstuni 0:75fc82583a41 2186
DiegoOstuni 0:75fc82583a41 2187 rfalGetBitRate( &nfcDepDev->info.DSI, &nfcDepDev->info.DRI );
DiegoOstuni 0:75fc82583a41 2188
DiegoOstuni 0:75fc82583a41 2189
DiegoOstuni 0:75fc82583a41 2190
DiegoOstuni 0:75fc82583a41 2191 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 2192 /* Check if a PSL needs to be sent */
DiegoOstuni 0:75fc82583a41 2193 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 2194 sendPSL = false;
DiegoOstuni 0:75fc82583a41 2195 PSL_BRS = rfalNfcDepDx2BRS( nfcDepDev->info.DSI ); /* Set current bit rate divisor on both directions */
DiegoOstuni 0:75fc82583a41 2196 PSL_FSL = nfcDepDev->info.LR; /* Set current Frame Size */
DiegoOstuni 0:75fc82583a41 2197
DiegoOstuni 0:75fc82583a41 2198
DiegoOstuni 0:75fc82583a41 2199 #if 0
DiegoOstuni 0:75fc82583a41 2200 /* Activity 1.0
DiegoOstuni 0:75fc82583a41 2201 * 9.4.6.3 NFC-F NFC-DEP Activation
DiegoOstuni 0:75fc82583a41 2202 * 9.4.4.15 NFC-A NFC-DEP Activation
DiegoOstuni 0:75fc82583a41 2203 *
DiegoOstuni 0:75fc82583a41 2204 * PSL_REQ shall only be sent if desired bit rate is different from current
DiegoOstuni 0:75fc82583a41 2205 * */
DiegoOstuni 0:75fc82583a41 2206
DiegoOstuni 0:75fc82583a41 2207 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 2208 /* Check Frame Size */
DiegoOstuni 0:75fc82583a41 2209 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 2210 if( gNfcip.cfg.lr < nfcDepDev->info.LR ) /* If our Length reduction is smaller */
DiegoOstuni 0:75fc82583a41 2211 {
DiegoOstuni 0:75fc82583a41 2212 sendPSL = true;
DiegoOstuni 0:75fc82583a41 2213
DiegoOstuni 0:75fc82583a41 2214 nfcDepDev->info.LR = MIN( nfcDepDev->info.LR, gNfcip.cfg.lr );
DiegoOstuni 0:75fc82583a41 2215
DiegoOstuni 0:75fc82583a41 2216 gNfcip.cfg.lr = nfcDepDev->info.LR /* Update nfcip LR to be used */
DiegoOstuni 0:75fc82583a41 2217 gNfcip.fsc = rfalNfcDepLR2FS( gNfcip.cfg.lr ); /* Update nfcip FSC to be used */
DiegoOstuni 0:75fc82583a41 2218
DiegoOstuni 0:75fc82583a41 2219 PSL_FSL = gNfcip.cfg.lr; /* Set LR to be sent */
DiegoOstuni 0:75fc82583a41 2220
DiegoOstuni 0:75fc82583a41 2221 nfcipLogI( " NFCIP(I) Frame Size differ, PSL new fsc: %d \r\n", gNfcip.fsc );
DiegoOstuni 0:75fc82583a41 2222 }
DiegoOstuni 0:75fc82583a41 2223 #endif
DiegoOstuni 0:75fc82583a41 2224
DiegoOstuni 0:75fc82583a41 2225
DiegoOstuni 0:75fc82583a41 2226 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 2227 /* Check Baud rates */
DiegoOstuni 0:75fc82583a41 2228 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 2229 if( ((nfcDepDev->info.DSI != desiredBR) && nfcipDxIsSupported( desiredBR, nfcDepDev->activation.Target.ATR_RES.BRt, nfcDepDev->activation.Target.ATR_RES.BSt )) /* if desired BR is different and supported */
DiegoOstuni 0:75fc82583a41 2230 /* || (target->brt != RFAL_NFCDEP_Bx_NO_HIGH_BR) || (target->bst != RFAL_NFCDEP_Bx_NO_HIGH_BR) */ ) /* if target supports higher BR, must send PSL? */
DiegoOstuni 0:75fc82583a41 2231 {
DiegoOstuni 0:75fc82583a41 2232 sendPSL = true;
DiegoOstuni 0:75fc82583a41 2233 PSL_BRS = rfalNfcDepDx2BRS( desiredBR );
DiegoOstuni 0:75fc82583a41 2234
DiegoOstuni 0:75fc82583a41 2235 nfcipLogI( " NFCIP(I) BR differ, PSL BR: 0x%02X \r\n", PSL_BRS );
DiegoOstuni 0:75fc82583a41 2236 }
DiegoOstuni 0:75fc82583a41 2237
DiegoOstuni 0:75fc82583a41 2238
DiegoOstuni 0:75fc82583a41 2239 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 2240 if( sendPSL )
DiegoOstuni 0:75fc82583a41 2241 {
DiegoOstuni 0:75fc82583a41 2242 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 2243 /* Send PSL REQ and wait for response */
DiegoOstuni 0:75fc82583a41 2244 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 2245 EXIT_ON_ERR( ret, rfalNfcDepPSL(PSL_BRS, PSL_FSL, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) );
DiegoOstuni 0:75fc82583a41 2246
DiegoOstuni 0:75fc82583a41 2247 /* Check if bit rate has been changed */
DiegoOstuni 0:75fc82583a41 2248 if( nfcDepDev->info.DSI != desiredBR )
DiegoOstuni 0:75fc82583a41 2249 {
DiegoOstuni 0:75fc82583a41 2250 /* Check if device was in Passive NFC-A and went to higher bit rates, use NFC-F */
DiegoOstuni 0:75fc82583a41 2251 if( (nfcDepDev->info.DSI == RFAL_BR_106) && (gNfcip.cfg.commMode == RFAL_NFCDEP_COMM_PASSIVE) )
DiegoOstuni 0:75fc82583a41 2252 {
DiegoOstuni 0:75fc82583a41 2253
DiegoOstuni 0:75fc82583a41 2254 #if RFAL_FEATURE_NFCF
DiegoOstuni 0:75fc82583a41 2255 /* If Passive initialize NFC-F module */
DiegoOstuni 0:75fc82583a41 2256 rfalNfcfPollerInitialize( desiredBR, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ;
DiegoOstuni 0:75fc82583a41 2257 #else /* RFAL_FEATURE_NFCF */
DiegoOstuni 0:75fc82583a41 2258 return ERR_NOTSUPP;
DiegoOstuni 0:75fc82583a41 2259 #endif /* RFAL_FEATURE_NFCF */
DiegoOstuni 0:75fc82583a41 2260
DiegoOstuni 0:75fc82583a41 2261 }
DiegoOstuni 0:75fc82583a41 2262
DiegoOstuni 0:75fc82583a41 2263 nfcDepDev->info.DRI = desiredBR; /* DSI Bit Rate coding from Initiator to Target */
DiegoOstuni 0:75fc82583a41 2264 nfcDepDev->info.DSI = desiredBR; /* DRI Bit Rate coding from Target to Initiator */
DiegoOstuni 0:75fc82583a41 2265
DiegoOstuni 0:75fc82583a41 2266 rfalSetBitRate( nfcDepDev->info.DSI, nfcDepDev->info.DRI, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ;
DiegoOstuni 0:75fc82583a41 2267 }
DiegoOstuni 0:75fc82583a41 2268
DiegoOstuni 0:75fc82583a41 2269
DiegoOstuni 0:75fc82583a41 2270 return ERR_NONE; /* PSL has been sent */
DiegoOstuni 0:75fc82583a41 2271 }
DiegoOstuni 0:75fc82583a41 2272
DiegoOstuni 0:75fc82583a41 2273 return ERR_NONE; /* No PSL has been sent */
DiegoOstuni 0:75fc82583a41 2274 }
DiegoOstuni 0:75fc82583a41 2275
DiegoOstuni 0:75fc82583a41 2276
DiegoOstuni 0:75fc82583a41 2277 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 2278 uint32_t rfalNfcDepCalculateRWT( uint8_t wt )
DiegoOstuni 0:75fc82583a41 2279 {
DiegoOstuni 0:75fc82583a41 2280 /* Digital 1.0 14.6.3.8 & Digital 1.1 16.6.3.9 */
DiegoOstuni 0:75fc82583a41 2281 /* Digital 1.1 16.6.3.9 treat all RFU values as WT=14 */
DiegoOstuni 0:75fc82583a41 2282 wt = MIN( RFAL_NFCDEP_WT_INI_MAX, wt );
DiegoOstuni 0:75fc82583a41 2283
DiegoOstuni 0:75fc82583a41 2284 return rfalNfcDepWT2RWT(wt);
DiegoOstuni 0:75fc82583a41 2285 }
DiegoOstuni 0:75fc82583a41 2286
DiegoOstuni 0:75fc82583a41 2287
DiegoOstuni 0:75fc82583a41 2288
DiegoOstuni 0:75fc82583a41 2289 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 2290 static ReturnCode nfcipDataTx( uint8_t* txBuf, uint16_t txBufLen, uint32_t fwt, SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 )
DiegoOstuni 0:75fc82583a41 2291 {
DiegoOstuni 0:75fc82583a41 2292 return rfalTransceiveBlockingTx( txBuf, txBufLen, gNfcip.rxBuf, gNfcip.rxBufLen, gNfcip.rxRcvdLen, (RFAL_TXRX_FLAGS_DEFAULT | RFAL_TXRX_FLAGS_NFCIP1_ON), ((fwt == NFCIP_NO_FWT) ? RFAL_FWT_NONE : rfalConv64fcTo1fc(fwt)), mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ;
DiegoOstuni 0:75fc82583a41 2293 }
DiegoOstuni 0:75fc82583a41 2294
DiegoOstuni 0:75fc82583a41 2295
DiegoOstuni 0:75fc82583a41 2296 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 2297 static ReturnCode nfcipDataRx( void )
DiegoOstuni 0:75fc82583a41 2298 {
DiegoOstuni 0:75fc82583a41 2299 ReturnCode ret;
DiegoOstuni 0:75fc82583a41 2300
DiegoOstuni 0:75fc82583a41 2301 ret = rfalGetTransceiveStatus();
DiegoOstuni 0:75fc82583a41 2302
DiegoOstuni 0:75fc82583a41 2303 if( ret != ERR_BUSY )
DiegoOstuni 0:75fc82583a41 2304 {
DiegoOstuni 0:75fc82583a41 2305 (*gNfcip.rxRcvdLen) = rfalConvBitsToBytes( *gNfcip.rxRcvdLen );
DiegoOstuni 0:75fc82583a41 2306
DiegoOstuni 0:75fc82583a41 2307 if( (ret == ERR_NONE) && (gNfcip.rxRcvdLen != NULL) && (gNfcip.rxBuf != NULL) )
DiegoOstuni 0:75fc82583a41 2308 {
DiegoOstuni 0:75fc82583a41 2309 /* Digital 1.1 16.4.1.3 - Length byte LEN SHALL have a value between 3 and 255 ->
DiegoOstuni 0:75fc82583a41 2310 * otherwise treat as Transmission Error *
DiegoOstuni 0:75fc82583a41 2311 * - Ensure that actual received and frame length do match,
DiegoOstuni 0:75fc82583a41 2312 * otherwise treat as Transmission error */
DiegoOstuni 0:75fc82583a41 2313
DiegoOstuni 0:75fc82583a41 2314 if( (*gNfcip.rxRcvdLen != (uint16_t)*gNfcip.rxBuf) || (*gNfcip.rxRcvdLen < RFAL_NFCDEP_LEN_MIN) || (*gNfcip.rxRcvdLen > RFAL_NFCDEP_LEN_MAX) )
DiegoOstuni 0:75fc82583a41 2315 {
DiegoOstuni 0:75fc82583a41 2316 return ERR_FRAMING;
DiegoOstuni 0:75fc82583a41 2317
DiegoOstuni 0:75fc82583a41 2318 }
DiegoOstuni 0:75fc82583a41 2319 }
DiegoOstuni 0:75fc82583a41 2320 }
DiegoOstuni 0:75fc82583a41 2321
DiegoOstuni 0:75fc82583a41 2322 return ret;
DiegoOstuni 0:75fc82583a41 2323 }
DiegoOstuni 0:75fc82583a41 2324
DiegoOstuni 0:75fc82583a41 2325
DiegoOstuni 0:75fc82583a41 2326 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 2327 ReturnCode rfalNfcDepListenStartActivation( rfalNfcDepTargetParam *param, uint8_t *atrReq, uint16_t atrReqLength, rfalNfcDepListenActvParam rxParam, SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 )
DiegoOstuni 0:75fc82583a41 2328 {
DiegoOstuni 0:75fc82583a41 2329 ReturnCode ret;
DiegoOstuni 0:75fc82583a41 2330 rfalNfcDepConfigs cfg;
DiegoOstuni 0:75fc82583a41 2331
DiegoOstuni 0:75fc82583a41 2332
DiegoOstuni 0:75fc82583a41 2333 if( (param == NULL) || (atrReq == NULL) || (rxParam.rxLen == NULL) )
DiegoOstuni 0:75fc82583a41 2334 {
DiegoOstuni 0:75fc82583a41 2335 return ERR_PARAM;
DiegoOstuni 0:75fc82583a41 2336 }
DiegoOstuni 0:75fc82583a41 2337
DiegoOstuni 0:75fc82583a41 2338
DiegoOstuni 0:75fc82583a41 2339 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 2340 /* Check whether is a valid ATR_REQ Compute NFC-DEP device */
DiegoOstuni 0:75fc82583a41 2341 if( !rfalNfcDepIsAtrReq( atrReq, atrReqLength, NULL ) )
DiegoOstuni 0:75fc82583a41 2342 {
DiegoOstuni 0:75fc82583a41 2343 return ERR_PARAM;
DiegoOstuni 0:75fc82583a41 2344 }
DiegoOstuni 0:75fc82583a41 2345
DiegoOstuni 0:75fc82583a41 2346 rxParam.nfcDepDev->activation.Initiator.ATR_REQLen = atrReqLength; /* nfcipIsAtrReq() is already checking Min and Max buffer lengths */
DiegoOstuni 0:75fc82583a41 2347 ST_MEMCPY( (uint8_t*)&rxParam.nfcDepDev->activation.Initiator.ATR_REQ, atrReq, atrReqLength );
DiegoOstuni 0:75fc82583a41 2348
DiegoOstuni 0:75fc82583a41 2349 rxParam.nfcDepDev->info.GBLen = (atrReqLength - RFAL_NFCDEP_ATRREQ_MIN_LEN);
DiegoOstuni 0:75fc82583a41 2350 rxParam.nfcDepDev->info.DID = rxParam.nfcDepDev->activation.Initiator.ATR_REQ.DID;
DiegoOstuni 0:75fc82583a41 2351 rxParam.nfcDepDev->info.NAD = RFAL_NFCDEP_NAD_NO; /* Digital 1.1 16.6.2.9 Initiator SHALL NOT use NAD */
DiegoOstuni 0:75fc82583a41 2352 rxParam.nfcDepDev->info.LR = rfalNfcDepPP2LR( rxParam.nfcDepDev->activation.Initiator.ATR_REQ.PPi );
DiegoOstuni 0:75fc82583a41 2353 rxParam.nfcDepDev->info.FS = rfalNfcDepLR2FS( rxParam.nfcDepDev->info.LR );
DiegoOstuni 0:75fc82583a41 2354 rxParam.nfcDepDev->info.WT = 0;
DiegoOstuni 0:75fc82583a41 2355 rxParam.nfcDepDev->info.FWT = NFCIP_NO_FWT;
DiegoOstuni 0:75fc82583a41 2356 rxParam.nfcDepDev->info.dFWT = NFCIP_NO_FWT;
DiegoOstuni 0:75fc82583a41 2357
DiegoOstuni 0:75fc82583a41 2358 rfalGetBitRate( &rxParam.nfcDepDev->info.DSI, &rxParam.nfcDepDev->info.DRI );
DiegoOstuni 0:75fc82583a41 2359
DiegoOstuni 0:75fc82583a41 2360
DiegoOstuni 0:75fc82583a41 2361 /* Store Device Info location, updated upon a PSL */
DiegoOstuni 0:75fc82583a41 2362 gNfcip.nfcDepDev = rxParam.nfcDepDev;
DiegoOstuni 0:75fc82583a41 2363
DiegoOstuni 0:75fc82583a41 2364
DiegoOstuni 0:75fc82583a41 2365 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 2366 cfg.did = rxParam.nfcDepDev->activation.Initiator.ATR_REQ.DID;
DiegoOstuni 0:75fc82583a41 2367 cfg.nad = RFAL_NFCDEP_NAD_NO;
DiegoOstuni 0:75fc82583a41 2368
DiegoOstuni 0:75fc82583a41 2369 cfg.fwt = RFAL_NFCDEP_MAX_FWT;
DiegoOstuni 0:75fc82583a41 2370 cfg.dFwt = RFAL_NFCDEP_MAX_FWT;
DiegoOstuni 0:75fc82583a41 2371
DiegoOstuni 0:75fc82583a41 2372 cfg.br = param->brt;
DiegoOstuni 0:75fc82583a41 2373 cfg.bs = param->bst;
DiegoOstuni 0:75fc82583a41 2374
DiegoOstuni 0:75fc82583a41 2375 cfg.lr = rfalNfcDepPP2LR(param->ppt);
DiegoOstuni 0:75fc82583a41 2376
DiegoOstuni 0:75fc82583a41 2377 cfg.gbLen = param->GBtLen;
DiegoOstuni 0:75fc82583a41 2378 ST_MEMCPY(cfg.gb, param->GBt, cfg.gbLen);
DiegoOstuni 0:75fc82583a41 2379
DiegoOstuni 0:75fc82583a41 2380 cfg.nfcidLen = RFAL_NFCDEP_NFCID3_LEN;
DiegoOstuni 0:75fc82583a41 2381 ST_MEMCPY(cfg.nfcid, param->nfcid3, RFAL_NFCDEP_NFCID3_LEN);
DiegoOstuni 0:75fc82583a41 2382
DiegoOstuni 0:75fc82583a41 2383 cfg.to = param->to;
DiegoOstuni 0:75fc82583a41 2384
DiegoOstuni 0:75fc82583a41 2385 cfg.role = RFAL_NFCDEP_ROLE_TARGET;
DiegoOstuni 0:75fc82583a41 2386 cfg.oper = param->operParam;
DiegoOstuni 0:75fc82583a41 2387 cfg.commMode = param->commMode;
DiegoOstuni 0:75fc82583a41 2388
DiegoOstuni 0:75fc82583a41 2389 rfalNfcDepInitialize();
DiegoOstuni 0:75fc82583a41 2390 nfcipConfig( cfg );
DiegoOstuni 0:75fc82583a41 2391
DiegoOstuni 0:75fc82583a41 2392
DiegoOstuni 0:75fc82583a41 2393 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 2394 /* Reply with ATR RES to Initiator */
DiegoOstuni 0:75fc82583a41 2395 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 2396 gNfcip.rxBuf = (uint8_t*)rxParam.rxBuf;
DiegoOstuni 0:75fc82583a41 2397 gNfcip.rxBufLen = sizeof(rfalNfcDepBufFormat);
DiegoOstuni 0:75fc82583a41 2398 gNfcip.rxRcvdLen = rxParam.rxLen;
DiegoOstuni 0:75fc82583a41 2399 gNfcip.rxBufPaylPos = RFAL_NFCDEP_DEPREQ_HEADER_LEN;
DiegoOstuni 0:75fc82583a41 2400 gNfcip.isChaining = rxParam.isRxChaining;
DiegoOstuni 0:75fc82583a41 2401 gNfcip.txBufPaylPos = RFAL_NFCDEP_DEPREQ_HEADER_LEN;
DiegoOstuni 0:75fc82583a41 2402
DiegoOstuni 0:75fc82583a41 2403 EXIT_ON_ERR( ret, nfcipTx( NFCIP_CMD_ATR_RES, (uint8_t*) gNfcip.rxBuf, NULL, 0, 0, NFCIP_NO_FWT, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) );
DiegoOstuni 0:75fc82583a41 2404
DiegoOstuni 0:75fc82583a41 2405 gNfcip.state = NFCIP_ST_TARG_WAIT_ACTV;
DiegoOstuni 0:75fc82583a41 2406
DiegoOstuni 0:75fc82583a41 2407 return ERR_NONE;
DiegoOstuni 0:75fc82583a41 2408 }
DiegoOstuni 0:75fc82583a41 2409
DiegoOstuni 0:75fc82583a41 2410
DiegoOstuni 0:75fc82583a41 2411 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 2412 ReturnCode rfalNfcDepListenGetActivationStatus( SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 )
DiegoOstuni 0:75fc82583a41 2413 {
DiegoOstuni 0:75fc82583a41 2414 ReturnCode err;
DiegoOstuni 0:75fc82583a41 2415 uint8_t BRS;
DiegoOstuni 0:75fc82583a41 2416
DiegoOstuni 0:75fc82583a41 2417 BRS = RFAL_NFCDEP_BRS_MAINTAIN;
DiegoOstuni 0:75fc82583a41 2418
DiegoOstuni 0:75fc82583a41 2419 err = nfcipTargetHandleActivation( gNfcip.nfcDepDev, &BRS, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ;
DiegoOstuni 0:75fc82583a41 2420
DiegoOstuni 0:75fc82583a41 2421 switch (err)
DiegoOstuni 0:75fc82583a41 2422 {
DiegoOstuni 0:75fc82583a41 2423 case ERR_NONE:
DiegoOstuni 0:75fc82583a41 2424
DiegoOstuni 0:75fc82583a41 2425 if( BRS != RFAL_NFCDEP_BRS_MAINTAIN )
DiegoOstuni 0:75fc82583a41 2426 {
DiegoOstuni 0:75fc82583a41 2427 /* DSI codes the bit rate from Initiator to Target */
DiegoOstuni 0:75fc82583a41 2428 /* DRI codes the bit rate from Target to Initiator */
DiegoOstuni 0:75fc82583a41 2429
DiegoOstuni 0:75fc82583a41 2430 if( gNfcip.cfg.commMode == RFAL_NFCDEP_COMM_ACTIVE )
DiegoOstuni 0:75fc82583a41 2431 {
DiegoOstuni 0:75fc82583a41 2432 EXIT_ON_ERR( err, rfalSetMode( RFAL_MODE_LISTEN_ACTIVE_P2P, gNfcip.nfcDepDev->info.DRI, gNfcip.nfcDepDev->info.DSI, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) );
DiegoOstuni 0:75fc82583a41 2433 }
DiegoOstuni 0:75fc82583a41 2434 else
DiegoOstuni 0:75fc82583a41 2435 {
DiegoOstuni 0:75fc82583a41 2436 EXIT_ON_ERR( err, rfalSetMode( ((RFAL_BR_106 == gNfcip.nfcDepDev->info.DRI) ? RFAL_MODE_LISTEN_NFCA : RFAL_MODE_LISTEN_NFCF), gNfcip.nfcDepDev->info.DRI, gNfcip.nfcDepDev->info.DSI, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) );
DiegoOstuni 0:75fc82583a41 2437 }
DiegoOstuni 0:75fc82583a41 2438 }
DiegoOstuni 0:75fc82583a41 2439 break;
DiegoOstuni 0:75fc82583a41 2440
DiegoOstuni 0:75fc82583a41 2441 case ERR_BUSY:
DiegoOstuni 0:75fc82583a41 2442 /* do nothing */
DiegoOstuni 0:75fc82583a41 2443 break;
DiegoOstuni 0:75fc82583a41 2444
DiegoOstuni 0:75fc82583a41 2445 case ERR_PROTO:
DiegoOstuni 0:75fc82583a41 2446 default:
DiegoOstuni 0:75fc82583a41 2447 /* re-enable receiving of data */
DiegoOstuni 0:75fc82583a41 2448 nfcDepReEnableRx( gNfcip.rxBuf, gNfcip.rxBufLen, gNfcip.rxRcvdLen );
DiegoOstuni 0:75fc82583a41 2449 break;
DiegoOstuni 0:75fc82583a41 2450 }
DiegoOstuni 0:75fc82583a41 2451
DiegoOstuni 0:75fc82583a41 2452 return err;
DiegoOstuni 0:75fc82583a41 2453 }
DiegoOstuni 0:75fc82583a41 2454
DiegoOstuni 0:75fc82583a41 2455
DiegoOstuni 0:75fc82583a41 2456 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 2457 ReturnCode rfalNfcDepStartTransceive( rfalNfcDepTxRxParam *param )
DiegoOstuni 0:75fc82583a41 2458 {
DiegoOstuni 0:75fc82583a41 2459 rfalNfcDepDEPParams nfcDepParams;
DiegoOstuni 0:75fc82583a41 2460
DiegoOstuni 0:75fc82583a41 2461 nfcDepParams.txBuf = (uint8_t *)param->txBuf;
DiegoOstuni 0:75fc82583a41 2462 nfcDepParams.txBufLen = param->txBufLen;
DiegoOstuni 0:75fc82583a41 2463 nfcDepParams.txChaining = param->isTxChaining;
DiegoOstuni 0:75fc82583a41 2464 nfcDepParams.txBufPaylPos = RFAL_NFCDEP_DEPREQ_HEADER_LEN; /* position in txBuf where actual outgoing data is located */
DiegoOstuni 0:75fc82583a41 2465 nfcDepParams.did = RFAL_NFCDEP_DID_KEEP;
DiegoOstuni 0:75fc82583a41 2466 nfcDepParams.rxBufPaylPos = RFAL_NFCDEP_DEPREQ_HEADER_LEN;
DiegoOstuni 0:75fc82583a41 2467 nfcDepParams.rxBuf = (uint8_t *)param->rxBuf;
DiegoOstuni 0:75fc82583a41 2468 nfcDepParams.rxBufLen = sizeof(rfalNfcDepBufFormat);
DiegoOstuni 0:75fc82583a41 2469 nfcDepParams.fsc = param->FSx;
DiegoOstuni 0:75fc82583a41 2470 nfcDepParams.fwt = param->FWT;
DiegoOstuni 0:75fc82583a41 2471 nfcDepParams.dFwt = param->dFWT;
DiegoOstuni 0:75fc82583a41 2472
DiegoOstuni 0:75fc82583a41 2473 gNfcip.rxRcvdLen = param->rxLen;
DiegoOstuni 0:75fc82583a41 2474 gNfcip.isChaining = param->isRxChaining;
DiegoOstuni 0:75fc82583a41 2475
DiegoOstuni 0:75fc82583a41 2476 nfcipSetDEPParams(&nfcDepParams);
DiegoOstuni 0:75fc82583a41 2477
DiegoOstuni 0:75fc82583a41 2478 return ERR_NONE;
DiegoOstuni 0:75fc82583a41 2479 }
DiegoOstuni 0:75fc82583a41 2480
DiegoOstuni 0:75fc82583a41 2481
DiegoOstuni 0:75fc82583a41 2482 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 2483 ReturnCode rfalNfcDepGetTransceiveStatus( SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 )
DiegoOstuni 0:75fc82583a41 2484 {
DiegoOstuni 0:75fc82583a41 2485 return nfcipRun( gNfcip.rxRcvdLen, gNfcip.isChaining, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ;
DiegoOstuni 0:75fc82583a41 2486 }
DiegoOstuni 0:75fc82583a41 2487
DiegoOstuni 0:75fc82583a41 2488 #endif /* RFAL_FEATURE_NFC_DEP */