diff --git a/core/embed/io/nfc/rfal/include/rfal_isoDep.h b/core/embed/io/nfc/rfal/include/rfal_isoDep.h index 8d2fe25c75..765a3131e9 100644 --- a/core/embed/io/nfc/rfal/include/rfal_isoDep.h +++ b/core/embed/io/nfc/rfal/include/rfal_isoDep.h @@ -27,7 +27,7 @@ * \author Gustavo Patricio * * \brief Implementation of ISO-DEP protocol - * + * * This implementation was based on the following specs: * - ISO/IEC 14443-4 2nd Edition 2008-07-15 * - NFC Forum Digital Protocol 1.1 2014-01-14 @@ -43,7 +43,7 @@ * \addtogroup ISO-DEP * \brief RFAL ISO-DEP Module * @{ - * + * */ #ifndef RFAL_ISODEP_H_ @@ -139,10 +139,10 @@ #define RFAL_ISODEP_SPARAM_TAG_PCD2PICC_LEN (2U) /*!< S(PARAMETERS) bit rates from PICC to PCD Length */ #define RFAL_ISODEP_SPARAM_TAG_BRACK_LEN (0U) /*!< S(PARAMETERS) tag Bit rates Acknowledgement Length */ -#define RFAL_ISODEP_ATS_TA_DPL_212 (0x01U) /*!< ATS TA DSI 212 kbps support bit mask */ -#define RFAL_ISODEP_ATS_TA_DPL_424 (0x02U) /*!< ATS TA DSI 424 kbps support bit mask */ -#define RFAL_ISODEP_ATS_TA_DPL_848 (0x04U) /*!< ATS TA DSI 848 kbps support bit mask */ -#define RFAL_ISODEP_ATS_TA_DLP_212 (0x10U) /*!< ATS TA DSI 212 kbps support bit mask */ +#define RFAL_ISODEP_ATS_TA_DPL_212 (0x01U) /*!< ATS TA DSI_ID 212 kbps support bit mask */ +#define RFAL_ISODEP_ATS_TA_DPL_424 (0x02U) /*!< ATS TA DSI_ID 424 kbps support bit mask */ +#define RFAL_ISODEP_ATS_TA_DPL_848 (0x04U) /*!< ATS TA DSI_ID 848 kbps support bit mask */ +#define RFAL_ISODEP_ATS_TA_DLP_212 (0x10U) /*!< ATS TA DSI_ID 212 kbps support bit mask */ #define RFAL_ISODEP_ATS_TA_DLP_424 (0x20U) /*!< ATS TA DRI 424 kbps support bit mask */ #define RFAL_ISODEP_ATS_TA_DLP_848 (0x40U) /*!< ATS TA DRI 848 kbps support bit mask */ #define RFAL_ISODEP_ATS_TA_SAME_D (0x80U) /*!< ATS TA same bit both directions bit mask */ @@ -163,7 +163,7 @@ #define RFAL_ISODEP_MAX_WTX_RETRYS_ULTD (255U) /*!< Use unlimited number of overall S(WTX) */ #define RFAL_ISODEP_MAX_DSL_RETRYS (0U) /*!< Number of retries for a S(DESELECT) Digital 2.0 B9 - nRETRY DESELECT: [0,5] */ #define RFAL_ISODEP_RATS_RETRIES (1U) /*!< RATS retries upon fail Digital 2.0 B7 - nRETRY RATS [0,1] */ - + /*! Frame Size for Proximity Card Integer definitions */ typedef enum @@ -238,7 +238,7 @@ typedef struct { uint8_t PPSS; /*!< Start Byte: [ 1101b | CID[4b] ] */ uint8_t PPS0; /*!< Parameter 0:[ 000b | PPS1[1n] | 0001b ] */ - uint8_t PPS1; /*!< Parameter 1:[ 0000b | DSI[2b] | DRI[2b] ]*/ + uint8_t PPS1; /*!< Parameter 1:[ 0000b | DSI_ID[2b] | DRI[2b] ]*/ } rfalIsoDepPpsReq; @@ -293,7 +293,7 @@ typedef union {/* PRQA S 0750 # MISRA 19.2 - Both members of the union will not rfalIsoDepRats RATS; /*!< RATS request (Listener mode) */ }Poller; }A; - + /*! NFC-B information */ union { struct{ @@ -318,7 +318,7 @@ typedef struct { uint8_t FSxI; /*!< Frame Size Device/Card Integer (FSDI or FSCI) */ uint16_t FSx; /*!< Frame Size Device/Card (FSD or FSC) */ uint32_t MBL; /*!< Maximum Buffer Length (optional for NFC-B) */ - rfalBitRate DSI; /*!< Bit Rate coding from Listener (PICC) to Poller (PCD) */ + rfalBitRate DSI_ID; /*!< Bit Rate coding from Listener (PICC) to Poller (PCD) */ rfalBitRate DRI; /*!< Bit Rate coding from Poller (PCD) to Listener (PICC) */ uint8_t DID; /*!< Device ID */ uint8_t NAD; /*!< Node ADdress */ @@ -424,8 +424,8 @@ typedef struct /*! ****************************************************************************** - * \brief Initialize the ISO-DEP protocol - * + * \brief Initialize the ISO-DEP protocol + * * Initialize the ISO-DEP protocol layer with default config ****************************************************************************** */ @@ -434,27 +434,27 @@ void rfalIsoDepInitialize( void ); /*! ****************************************************************************** - * \brief Initialize the ISO-DEP protocol - * + * \brief Initialize the ISO-DEP protocol + * * Initialize the ISO-DEP protocol layer with additional parameters allowing * to customise the protocol layer for specific behaviours - * + * * \param[in] compMode : Compliance mode to be performed * \param[in] maxRetriesR : Number of retries for a R-Block * Digital 2.0 B9 - nRETRY ACK/NAK: [2,5] * \param[in] maxRetriesSnWTX : Number of retries for a S(WTX) (only in case - * of NAKs) Digital 2.0 B9 - nRETRY WTX[2,5] - * \param[in] maxRetriesSWTX : Number of overall S(WTX) retries. - * Use RFAL_ISODEP_MAX_WTX_RETRYS_ULTD for disabling + * of NAKs) Digital 2.0 B9 - nRETRY WTX[2,5] + * \param[in] maxRetriesSWTX : Number of overall S(WTX) retries. + * Use RFAL_ISODEP_MAX_WTX_RETRYS_ULTD for disabling * this limit check Digital 2.0 16.2.5.2 * \param[in] maxRetriesSDSL : Number of retries for a S(DESELECT) * Digital 2.0 B9 - nRETRY DESELECT: [0,5] - * \param[in] maxRetriesI : Number of retries for a I-Block + * \param[in] maxRetriesI : Number of retries for a I-Block * Digital 2.0 16.2.5.4 - * \param[in] maxRetriesRATS : Number of retries for RATS + * \param[in] maxRetriesRATS : Number of retries for RATS * Digital 2.0 B7 - nRETRY RATS [0,1] - * + * ****************************************************************************** */ void rfalIsoDepInitializeWithParams( rfalComplianceMode compMode, @@ -470,19 +470,19 @@ void rfalIsoDepInitializeWithParams( rfalComplianceMode compMode, ***************************************************************************** * \brief FSxI to FSx * - * Convert Frame Size for proximity coupling Device Integer (FSxI) to + * Convert Frame Size for proximity coupling Device Integer (FSxI) to * Frame Size for proximity coupling Device (FSx) - * + * * FSD - maximum frame size for NFC Forum Device in Poll Mode * FSC - maximum frame size for NFC Forum Device in Listen Mode - * + * * FSxI = FSDI or FSCI * FSx = FSD or FSC - * + * * The FSD/FSC value includes the header and CRC * * \param[in] FSxI : Frame Size for proximity coupling Device Integer - * + * * \return fsx : Frame Size for proximity coupling Device (FSD or FSC) * ***************************************************************************** @@ -490,7 +490,7 @@ void rfalIsoDepInitializeWithParams( rfalComplianceMode compMode, uint16_t rfalIsoDepFSxI2FSx( uint8_t FSxI ); -/*! +/*! ***************************************************************************** * \brief FWI to FWT * @@ -498,7 +498,7 @@ uint16_t rfalIsoDepFSxI2FSx( uint8_t FSxI ); * 1/fc units * * \param[in] fwi : Frame Waiting time Integer - * + * * \return fwt : Frame Waiting Time in 1/fc units * ***************************************************************************** @@ -506,7 +506,7 @@ uint16_t rfalIsoDepFSxI2FSx( uint8_t FSxI ); uint32_t rfalIsoDepFWI2FWT( uint8_t fwi ); -/*! +/*! ***************************************************************************** * \brief Check if the buffer data contains a valid RATS command * @@ -522,11 +522,11 @@ uint32_t rfalIsoDepFWI2FWT( uint8_t fwi ); bool rfalIsoDepIsRats( const uint8_t *buf, uint8_t bufLen ); -/*! +/*! ***************************************************************************** * \brief Check if the buffer data contains a valid ATTRIB command * - * Check if it is a well formed ATTRIB command, but does not check the + * Check if it is a well formed ATTRIB command, but does not check the * validity of the information inside * * \param[in] buf : reference to buffer containing the data to be checked @@ -541,35 +541,35 @@ bool rfalIsoDepIsAttrib( const uint8_t *buf, uint8_t bufLen ); /*! ***************************************************************************** * \brief Start Listen Activation Handling - * + * * Start Listen Activation Handling and setup to receive first I-block which may - * contain complete or partial APDU after activation is completed - * + * contain complete or partial APDU after activation is completed + * * Pass in RATS for T4AT, or ATTRIB for T4BT, to handle ATS or ATTRIB Response respectively - * The Activation Handling handles ATS and ATTRIB Response; and additionally PPS Response + * The Activation Handling handles ATS and ATTRIB Response; and additionally PPS Response * if a PPS is received for T4AT. * The method uses the current RFAL state machine to determine if it is expecting RATS or ATTRIB - * + * * Activation is completed if PPS Response is sent or if first PDU is received in T4T-A * Activation is completed if ATTRIB Response is sent in T4T-B - * - * \ref rfalIsoDepListenGetActivationStatus provide status if activation is completed. + * + * \ref rfalIsoDepListenGetActivationStatus provide status if activation is completed. * \ref rfalIsoDepStartTransceive shall be called right after activation is completed - * + * * \param[in] atsParam : reference to ATS parameters * \param[in] attribResParam : reference to ATTRIB_RES parameters * \param[in] buf : reference to buffer containing RATS or ATTRIB * \param[in] bufLen : length in bytes of the given bufffer * \param[in] actParam : reference to incoming reception information will be placed - * - * - * \warning Once the Activation has been completed the method + * + * + * \warning Once the Activation has been completed the method * rfalIsoDepGetTransceiveStatus() must be called. - * If activation has completed due to reception of a data block (not PPS) the + * If activation has completed due to reception of a data block (not PPS) the * buffer owned by the caller and passed on actParam must still contain this data. * The first data will be processed (I-Block or S-DSL) by rfalIsoDepGetTransceiveStatus() * inform the caller and then for the next transaction use rfalIsoDepStartTransceive() - * + * * \return RFAL_ERR_NONE : RATS/ATTRIB is valid and activation has started * \return RFAL_ERR_PARAM : Invalid parameters * \return RFAL_ERR_PROTO : Invalid request @@ -582,7 +582,7 @@ ReturnCode rfalIsoDepListenStartActivation( rfalIsoDepAtsParam *atsParam, const /*! ***************************************************************************** * \brief Get the current Activation Status - * + * * \return RFAL_ERR_NONE if Activation is already completed * \return RFAL_ERR_BUSY if Activation is ongoing * \return RFAL_ERR_LINK_LOSS if Remote Field is turned off @@ -594,8 +594,8 @@ ReturnCode rfalIsoDepListenGetActivationStatus( void ); /*! ***************************************************************************** * \brief Get the ISO-DEP Communication Information - * - * Gets the maximum INF length in bytes based on current Frame Size + * + * Gets the maximum INF length in bytes based on current Frame Size * for proximity coupling Device (FSD or FSC) excluding the header and CRC * * \return maximum INF length in bytes @@ -606,21 +606,21 @@ uint16_t rfalIsoDepGetMaxInfLen( void ); /*! ***************************************************************************** - * \brief ISO-DEP Start Transceive - * - * This method triggers a ISO-DEP Transceive containing a complete or + * \brief ISO-DEP Start Transceive + * + * This method triggers a ISO-DEP Transceive containing a complete or * partial APDU * It transmits the given message and handles all protocol retransmitions, * error handling and control messages - * - * The txBuf contains a complete or partial APDU (INF) to be transmitted + * + * The txBuf contains a complete or partial APDU (INF) to be transmitted * The Prologue field will be manipulated by the Transceive - * - * If the buffer contains a partial APDU and is not the last block, + * + * If the buffer contains a partial APDU and is not the last block, * then isTxChaining must be set to true - * + * * \param[in] param: reference parameters to be used for the Transceive - * + * * \return RFAL_ERR_PARAM : Bad request * \return RFAL_ERR_WRONG_STATE : The module is not in a proper state * \return RFAL_ERR_NONE : The Transceive request has been started @@ -632,18 +632,18 @@ ReturnCode rfalIsoDepStartTransceive( rfalIsoDepTxRxParam param ); /*! ***************************************************************************** * \brief Get the Transceive status - * + * * Returns the status of the ISO-DEP Transceive - * - * \warning When the other device is performing chaining once a chained - * block is received the error RFAL_ERR_AGAIN is sent. At this point - * caller must handle the received data immediately. - * When RFAL_ERR_AGAIN is returned an ACK has already been sent to - * the other device and the next block might be incoming. - * If rfalWorker() is called frequently it will place the next - * block on the given buffer - * - * + * + * \warning When the other device is performing chaining once a chained + * block is received the error RFAL_ERR_AGAIN is sent. At this point + * caller must handle the received data immediately. + * When RFAL_ERR_AGAIN is returned an ACK has already been sent to + * the other device and the next block might be incoming. + * If rfalWorker() is called frequently it will place the next + * block on the given buffer + * + * * \return RFAL_ERR_NONE : Transceive has been completed successfully * \return RFAL_ERR_BUSY : Transceive is ongoing * \return RFAL_ERR_PROTO : Protocol error occurred @@ -651,7 +651,7 @@ ReturnCode rfalIsoDepStartTransceive( rfalIsoDepTxRxParam param ); * \return RFAL_ERR_SLEEP_REQ : Deselect has been received and responded * \return RFAL_ERR_NOMEM : The received INF does not fit into the * receive buffer - * \return RFAL_ERR_LINK_LOSS : Communication is lost because Reader/Writer + * \return RFAL_ERR_LINK_LOSS : Communication is lost because Reader/Writer * has turned off its field * \return RFAL_ERR_AGAIN : received one chaining block, continue to call * this method to retrieve the remaining blocks @@ -662,20 +662,20 @@ ReturnCode rfalIsoDepGetTransceiveStatus( void ); /*! ***************************************************************************** - * \brief ISO-DEP Start APDU Transceive - * + * \brief ISO-DEP Start APDU Transceive + * * This method triggers a ISO-DEP Transceive containing a complete APDU * It transmits the given message and handles all protocol retransmitions, * error handling and control messages - * - * The txBuf contains a complete APDU to be transmitted + * + * The txBuf contains a complete APDU to be transmitted * The Prologue field will be manipulated by the Transceive - * + * * \warning the txBuf will be modified during the transmission * \warning the maximum RF frame which can be received is limited by param.tmpBuf - * + * * \param[in] param: reference parameters to be used for the Transceive - * + * * \return RFAL_ERR_PARAM : Bad request * \return RFAL_ERR_WRONG_STATE : The module is not in a proper state * \return RFAL_ERR_NONE : The Transceive request has been started @@ -687,29 +687,29 @@ ReturnCode rfalIsoDepStartApduTransceive( rfalIsoDepApduTxRxParam param ); /*! ***************************************************************************** * \brief Get the APDU Transceive status - * + * * \return RFAL_ERR_NONE : if Transceive has been completed successfully * \return RFAL_ERR_BUSY : if Transceive is ongoing * \return RFAL_ERR_PROTO : if a protocol error occurred * \return RFAL_ERR_TIMEOUT : if a timeout error occurred * \return RFAL_ERR_SLEEP_REQ : if Deselect is received and responded - * \return RFAL_ERR_NOMEM : if the received INF does not fit into the + * \return RFAL_ERR_NOMEM : if the received INF does not fit into the * receive buffer - * \return RFAL_ERR_LINK_LOSS : if communication is lost because Reader/Writer + * \return RFAL_ERR_LINK_LOSS : if communication is lost because Reader/Writer * has turned off its field ***************************************************************************** */ ReturnCode rfalIsoDepGetApduTransceiveStatus( void ); -/*! +/*! ***************************************************************************** * \brief ISO-DEP Send RATS - * - * This sends a RATS to make a NFC-A Listen Device to enter + * + * This sends a RATS to make a NFC-A Listen Device to enter * ISO-DEP layer (ISO14443-4) and checks if the received ATS is valid - * + * * \param[in] FSDI : Frame Size Device Integer to be used - * \param[in] DID : Device ID to be used or RFAL_ISODEP_NO_DID for not use DID + * \param[in] DID : Device ID to be used or RFAL_ISODEP_NO_DID for not use DID * \param[out] ats : pointer to place the ATS Response * \param[out] atsLen : pointer to place the ATS length * @@ -727,16 +727,16 @@ ReturnCode rfalIsoDepGetApduTransceiveStatus( void ); ReturnCode rfalIsoDepRATS( rfalIsoDepFSxI FSDI, uint8_t DID, rfalIsoDepAts *ats , uint8_t *atsLen ); -/*! +/*! ***************************************************************************** * \brief ISO-DEP Send PPS - * + * * This sends a PPS to make a NFC-A Listen Device change the communications * bit rate from 106kbps to one of the supported bit rates * Additionally checks if the received PPS response is valid - * + * * \param[in] DID : Device ID - * \param[in] DSI : DSI code the divisor from Listener (PICC) to Poller (PCD) + * \param[in] DSI_ID : DSI_ID code the divisor from Listener (PICC) to Poller (PCD) * \param[in] DRI : DRI code the divisor from Poller (PCD) to Listener (PICC) * \param[out] ppsRes : pointer to place the PPS Response * @@ -751,19 +751,19 @@ ReturnCode rfalIsoDepRATS( rfalIsoDepFSxI FSDI, uint8_t DID, rfalIsoDepAts *ats * \return RFAL_ERR_NONE : No error, PPS Response received ***************************************************************************** */ -ReturnCode rfalIsoDepPPS( uint8_t DID, rfalBitRate DSI, rfalBitRate DRI, rfalIsoDepPpsRes *ppsRes ); +ReturnCode rfalIsoDepPPS( uint8_t DID, rfalBitRate DSI_ID, rfalBitRate DRI, rfalIsoDepPpsRes *ppsRes ); -/*! +/*! ***************************************************************************** * \brief ISO-DEP Send ATTRIB - * - * This sends a ATTRIB to make a NFC-B Listen Device to enter + * + * This sends a ATTRIB to make a NFC-B Listen Device to enter * ISO-DEP layer (ISO14443-4) and checks if the received ATTRIB Response is valid - * - * \param[in] nfcid0 : NFCID0 to be used for the ATTRIB - * \param[in] PARAM1 : ATTRIB PARAM1 byte (communication parameters) - * \param[in] DSI : DSI code the divisor from Listener (PICC) to Poller (PCD) + * + * \param[in] nfcid0 : NFCID0 to be used for the ATTRIB + * \param[in] PARAM1 : ATTRIB PARAM1 byte (communication parameters) + * \param[in] DSI_ID : DSI_ID code the divisor from Listener (PICC) to Poller (PCD) * \param[in] DRI : DRI code the divisor from Poller (PCD) to Listener (PICC) * \param[in] FSDI : PCD's Frame Size to be announced on the ATTRIB * \param[in] PARAM3 : ATTRIB PARAM1 byte (protocol type) @@ -784,66 +784,66 @@ ReturnCode rfalIsoDepPPS( uint8_t DID, rfalBitRate DSI, rfalBitRate DRI, rfalIso * \return RFAL_ERR_NONE : No error, ATTRIB Response received ***************************************************************************** */ -ReturnCode rfalIsoDepATTRIB( const uint8_t* nfcid0, uint8_t PARAM1, rfalBitRate DSI, rfalBitRate DRI, rfalIsoDepFSxI FSDI, uint8_t PARAM3, uint8_t DID, const uint8_t* HLInfo, uint8_t HLInfoLen, uint32_t fwt, rfalIsoDepAttribRes *attribRes, uint8_t *attribResLen ); +ReturnCode rfalIsoDepATTRIB( const uint8_t* nfcid0, uint8_t PARAM1, rfalBitRate DSI_ID, rfalBitRate DRI, rfalIsoDepFSxI FSDI, uint8_t PARAM3, uint8_t DID, const uint8_t* HLInfo, uint8_t HLInfoLen, uint32_t fwt, rfalIsoDepAttribRes *attribRes, uint8_t *attribResLen ); -/*! +/*! ***************************************************************************** * \brief Deselect PICC * * This function sends a deselect command to PICC and waits for its * responce in a blocking way * - * \return RFAL_ERR_NONE : Deselect successfully sent and acknowledged by PICC + * \return RFAL_ERR_NONE : Deselect successfully sent and acknowledged by PICC * \return RFAL_ERR_PROTO : Protocol error occurred - * \return RFAL_ERR_TIMEOUT : No response rcvd from PICC + * \return RFAL_ERR_TIMEOUT : No response rcvd from PICC * ***************************************************************************** */ ReturnCode rfalIsoDepDeselect( void ); -/*! +/*! ***************************************************************************** - * \brief Start Deselect + * \brief Start Deselect * - * This function starts the exchange to send deselect command to PICC and + * This function starts the exchange to send deselect command to PICC and * waits for its response * - * \return RFAL_ERR_NONE : Deselect successfully sent and acknowledged by PICC + * \return RFAL_ERR_NONE : Deselect successfully sent and acknowledged by PICC * \return RFAL_ERR_PROTO : Protocol error occurred - * \return RFAL_ERR_TIMEOUT : No response rcvd from PICC + * \return RFAL_ERR_TIMEOUT : No response rcvd from PICC * ***************************************************************************** */ ReturnCode rfalIsoDepStartDeselect( void ); -/*! +/*! ***************************************************************************** * \brief Deselect Get Status * * This function sends a deselect command to PICC and waits for it`s * responce in a blocking way * - * \return RFAL_ERR_NONE : Deselect successfully sent and acknowledged by PICC + * \return RFAL_ERR_NONE : Deselect successfully sent and acknowledged by PICC * \return RFAL_ERR_PROTO : Protocol error occurred - * \return RFAL_ERR_TIMEOUT : No response rcvd from PICC + * \return RFAL_ERR_TIMEOUT : No response rcvd from PICC * ***************************************************************************** */ ReturnCode rfalIsoDepGetDeselectStatus( void ); -/*! +/*! ***************************************************************************** * \brief ISO-DEP Poller Handle NFC-A Activation - * + * * This performs a NFC-A Activation into ISO-DEP layer (ISO14443-4) with the given - * parameters. It sends RATS and if the higher bit rates are supported by + * parameters. It sends RATS and if the higher bit rates are supported by * both devices it additionally sends PPS * Once Activated all details of the device are provided on isoDepDev - * + * * \param[in] FSDI : Frame Size Device Integer to be used * \param[in] DID : Device ID to be used or RFAL_ISODEP_NO_DID for not use DID * \param[in] maxBR : Max bit rate supported by the Poller @@ -863,15 +863,15 @@ ReturnCode rfalIsoDepGetDeselectStatus( void ); ReturnCode rfalIsoDepPollAHandleActivation( rfalIsoDepFSxI FSDI, uint8_t DID, rfalBitRate maxBR, rfalIsoDepDevice *rfalIsoDepDev ); -/*! +/*! ***************************************************************************** * \brief ISO-DEP Poller Handle NFC-B Activation - * + * * This performs a NFC-B Activation into ISO-DEP layer (ISO14443-4) with the given - * parameters. It sends ATTRIB and calculates supported higher bit rates of both + * parameters. It sends ATTRIB and calculates supported higher bit rates of both * devices and performs activation. * Once Activated all details of the device are provided on isoDepDev - * + * * \param[in] FSDI : Frame Size Device Integer to be used * \param[in] DID : Device ID to be used or RFAL_ISODEP_NO_DID for not use DID * \param[in] maxBR : Max bit rate supported by the Poller @@ -895,14 +895,14 @@ ReturnCode rfalIsoDepPollAHandleActivation( rfalIsoDepFSxI FSDI, uint8_t DID, rf ReturnCode rfalIsoDepPollBHandleActivation( rfalIsoDepFSxI FSDI, uint8_t DID, rfalBitRate maxBR, uint8_t PARAM1, const rfalNfcbListenDevice *nfcbDev, const uint8_t* HLInfo, uint8_t HLInfoLen, rfalIsoDepDevice *rfalIsoDepDev ); -/*! +/*! ***************************************************************************** * \brief ISO-DEP Poller Handle S(Parameters) - * + * * This checks if PICC supports S(PARAMETERS), retieves PICC's * capabilities and sets the Bit Rate at the highest supported by both * devices - * + * * \param[out] rfalIsoDepDev : ISO-DEP information of the activated Listen device * \param[in] maxTxBR : Maximum Tx bit rate supported by PCD * \param[in] maxRxBR : Maximum Rx bit rate supported by PCD @@ -921,7 +921,7 @@ ReturnCode rfalIsoDepPollHandleSParameters( rfalIsoDepDevice *rfalIsoDepDev, rfa /*! ***************************************************************************** - * \brief ISO-DEP Poller Start NFC-A Activation + * \brief ISO-DEP Poller Start NFC-A Activation * * This starts a NFC-A Activation into ISO-DEP layer (ISO14443-4) with the given * parameters. It sends RATS and if the higher bit rates are supported by @@ -975,10 +975,10 @@ ReturnCode rfalIsoDepPollAGetActivationStatus( void ); /*! ***************************************************************************** - * \brief ISO-DEP Poller Start NFC-B Activation + * \brief ISO-DEP Poller Start NFC-B Activation * * This starts a NFC-B Activation into ISO-DEP layer (ISO14443-4) with the given - * parameters. It will send ATTRIB and calculate supported higher bit rates of both + * parameters. It will send ATTRIB and calculate supported higher bit rates of both * devices and perform activation. * Once Activated all details of the device are provided on isoDepDev * diff --git a/core/embed/io/nfc/rfal/include/rfal_nfcDep.h b/core/embed/io/nfc/rfal/include/rfal_nfcDep.h index f989dbdfa7..1024e0cf24 100644 --- a/core/embed/io/nfc/rfal/include/rfal_nfcDep.h +++ b/core/embed/io/nfc/rfal/include/rfal_nfcDep.h @@ -27,10 +27,10 @@ * \author Gustavo Patricio * * \brief Implementation of NFC-DEP protocol - * - * NFC-DEP is also known as NFCIP - Near Field Communication + * + * NFC-DEP is also known as NFCIP - Near Field Communication * Interface and Protocol - * + * * This implementation was based on the following specs: * - NFC Forum Digital 1.1 * - ECMA 340 3rd Edition 2013 @@ -66,7 +66,7 @@ * ENABLE SWITCH ****************************************************************************** */ - + /* If module is disabled remove the need for the user to set lengths */ #if !RFAL_FEATURE_NFC_DEP #undef RFAL_FEATURE_NFC_DEP_BLOCK_MAX_LEN @@ -85,7 +85,7 @@ #define RFAL_NFCDEP_DEPREQ_HEADER_LEN 5U /*!< DEP_REQ header length: CMD_TYPE + CMD_CMD + PBF + DID + NAD */ /*! Length NFCIP DEP REQ or RES header (incl LEN) */ -#define RFAL_NFCDEP_DEP_HEADER ( RFAL_NFCDEP_LEN_LEN + RFAL_NFCDEP_CMDTYPE_LEN + RFAL_NFCDEP_CMD_LEN + RFAL_NFCDEP_DEP_PFB_LEN ) +#define RFAL_NFCDEP_DEP_HEADER ( RFAL_NFCDEP_LEN_LEN + RFAL_NFCDEP_CMDTYPE_LEN + RFAL_NFCDEP_CMD_LEN + RFAL_NFCDEP_DEP_PFB_LEN ) #define RFAL_NFCDEP_HEADER ( RFAL_NFCDEP_CMDTYPE_LEN + RFAL_NFCDEP_CMD_LEN ) /*!< NFCIP header length */ #define RFAL_NFCDEP_SB_LEN 1U /*!< SB length on NFCIP fram for NFC-A */ #define RFAL_NFCDEP_LEN_LEN 1U /*!< LEN length on NFCIP frame */ @@ -140,7 +140,7 @@ #define RFAL_NFCDEP_ATRREQ_MIN_LEN 16U /*!< Minimum length for an ATR REQ */ #define RFAL_NFCDEP_ATRREQ_MAX_LEN RFAL_NFCDEP_ATRRES_MAX_LEN /*!< Maximum length for an ATR REQ Digital 1.0 14.6.1 */ -#define RFAL_NFCDEP_GB_MAX_LEN (RFAL_NFCDEP_ATRREQ_MAX_LEN - RFAL_NFCDEP_ATRREQ_MIN_LEN) /*!< Maximum length the General Bytes on ATR Digital 1.1 16.6.3 */ +#define RFAL_NFCDEP_GB_MAX_LEN (RFAL_NFCDEP_ATRREQ_MAX_LEN - RFAL_NFCDEP_ATRREQ_MIN_LEN) /*!< Maximum length the General Bytes on ATR Digital 1.1 16.6.3 */ #define RFAL_NFCDEP_WT_INI_DEFAULT RFAL_NFCDEP_WT_INI_MAX /*!< WT Initiator default value Digital 1.0 14.6.3.8 */ #define RFAL_NFCDEP_WT_INI_MIN 0U /*!< WT Initiator minimum value Digital 1.0 14.6.3.8 */ @@ -174,7 +174,7 @@ #define rfalNfcDepDx2BRS( br ) ( (((uint8_t)(br) & RFAL_NFCDEP_BRS_Dx_MASK) << RFAL_NFCDEP_BRS_DSI_POS) | ((uint8_t)(br) & RFAL_NFCDEP_BRS_Dx_MASK) ) #define rfalNfcDepBRS2DRI( brs ) (uint8_t)( (uint8_t)(brs) & RFAL_NFCDEP_BRS_Dx_MASK ) /*!< Returns the DRI value from the given BRS byte */ -#define rfalNfcDepBRS2DSI( brs ) (uint8_t)( ((uint8_t)(brs) >> RFAL_NFCDEP_BRS_DSI_POS) & RFAL_NFCDEP_BRS_Dx_MASK ) /*!< Returns the DSI value from the given BRS byte */ +#define rfalNfcDepBRS2DSI( brs ) (uint8_t)( ((uint8_t)(brs) >> RFAL_NFCDEP_BRS_DSI_POS) & RFAL_NFCDEP_BRS_Dx_MASK ) /*!< Returns the DSI_ID value from the given BRS byte */ #define rfalNfcDepPP2LR( PPx ) ( ((uint8_t)(PPx) & RFAL_NFCDEP_PP_LR_MASK ) >> RFAL_NFCDEP_PP_LR_SHIFT) /*!< Returns the LR value from the given PPx byte */ #define rfalNfcDepLR2PP( LRx ) ( ((uint8_t)(LRx) << RFAL_NFCDEP_PP_LR_SHIFT) & RFAL_NFCDEP_PP_LR_MASK) /*!< Returns the PP byte with the given LRx value */ @@ -182,9 +182,9 @@ /*! Returns the Frame size value from the given LRx value */ #define rfalNfcDepLR2FS( LRx ) (uint16_t)(RFAL_MIN( (RFAL_NFCDEP_FS_VAL_MIN * ((uint16_t)(LRx) + 1U) ), RFAL_NFCDEP_FRAME_SIZE_MAX_LEN )) -/*! - * Despite DIGITAL 1.0 14.6.2.1 stating that the last two bytes may filled with - * any value, some devices (Samsung Google Nexus) only accept when these are 0 */ +/*! + * Despite DIGITAL 1.0 14.6.2.1 stating that the last two bytes may filled with + * any value, some devices (Samsung Google Nexus) only accept when these are 0 */ #define rfalNfcDepSetNFCID( dst, src, len ) RFAL_MEMSET( (dst), 0x00, RFAL_NFCDEP_NFCID3_LEN ); \ if( (len) > 0U ) {RFAL_MEMCPY( (dst), (src), (len) );} @@ -252,7 +252,7 @@ typedef struct{ rfalNfcDepRole role; /*!< Current NFCIP role */ rfalNfcDepCommMode commMode; /*!< Current NFCIP communication mode */ uint8_t oper; /*!< Operation config similar to NCI 1.0 Table 81 */ - + uint8_t did; /*!< Current Device ID (DID) */ uint8_t nad; /*!< Current Node Addressing (NAD) */ uint8_t bs; /*!< Bit rate in Sending Direction */ @@ -291,7 +291,7 @@ typedef struct { uint8_t BRt; /*!< Receiving Bitrate for Initiator */ uint8_t TO; /*!< Timeout */ uint8_t PPt; /*!< Optional Parameters presence indicator */ - uint8_t GBt[RFAL_NFCDEP_GB_MAX_LEN]; /*!< General Bytes */ + uint8_t GBt[RFAL_NFCDEP_GB_MAX_LEN]; /*!< General Bytes */ } rfalNfcDepAtrRes; @@ -332,7 +332,7 @@ typedef struct { uint32_t dFWT; /*!< Delta FWT to be used (1/fc) */ uint8_t LR; /*!< Length Reduction coding the max payload */ uint16_t FS; /*!< Frame Size */ - rfalBitRate DSI; /*!< Bit Rate coding from Initiator to Target */ + rfalBitRate DSI_ID; /*!< Bit Rate coding from Initiator to Target */ rfalBitRate DRI; /*!< Bit Rate coding from Target to Initiator */ uint8_t DID; /*!< Device ID (RFAL_NFCDEP_DID_NO if no DID) */ uint8_t NAD; /*!< Node ADdress (RFAL_NFCDEP_NAD_NO if no NAD)*/ @@ -351,12 +351,12 @@ typedef struct { * operParam : derives from NFC-Forum NCI NFC-DEP Operation Parameter * NCI 1.1 Table 86: NFC-DEP Operation Parameter * and it's a bit mask composed as: - * [ 0000b - * | Chain SHALL use max. Transport Data Byte[1b] + * [ 0000b + * | Chain SHALL use max. Transport Data Byte[1b] * | I-PDU with no Transport Data SHALL NOT be sent [1b] * | NFC-DEP Target SHALL NOT send RTOX request [1b] * ] - * + * */ typedef struct{ rfalNfcDepCommMode commMode; /*!< Initiator in Active P2P or Passive P2P*/ @@ -388,12 +388,12 @@ typedef struct * operParam : derives from NFC-Forum NCI NFC-DEP Operation Parameter * NCI 1.1 Table 86: NFC-DEP Operation Parameter * and it's a bit mask composed as: - * [ 0000b - * | Chain SHALL use max. Transport Data Byte[1b] + * [ 0000b + * | Chain SHALL use max. Transport Data Byte[1b] * | I-PDU with no Transport Data SHALL NOT be sent [1b] * | NFC-DEP Target SHALL NOT send RTOX request [1b] * ] - * + * */ typedef struct{ rfalNfcDepCommMode commMode; /*!< Target in Active P2P or Passive P2P */ @@ -455,10 +455,10 @@ typedef struct /*! ****************************************************************************** * \brief NFCIP Initialize - * + * * This method resets all NFC-DEP inner states, counters and context and sets * default values - * + * ****************************************************************************** */ void rfalNfcDepInitialize( void ); @@ -467,12 +467,12 @@ void rfalNfcDepInitialize( void ); /*! ****************************************************************************** * \brief Set deactivating callback - * + * * Sets the deactivating callback so that nfcip layer can check if upper layer * has a deactivation pending, and not perform error recovery upon specific * errors - * - * \param[in] pFunc : method pointer to deactivation flag check + * + * \param[in] pFunc : method pointer to deactivation flag check ****************************************************************************** */ void rfalNfcDepSetDeactivatingCallback( rfalNfcDepDeactCallback pFunc ); @@ -481,11 +481,11 @@ void rfalNfcDepSetDeactivatingCallback( rfalNfcDepDeactCallback pFunc ); /*! ****************************************************************************** * \brief Calculate Response Waiting Time - * + * * Calculates the Response Waiting Time (RWT) from the given Waiting Time (WT) - * + * * \param[in] wt : the WT value to calculate RWT - * + * * \return RWT value in 1/fc ****************************************************************************** */ @@ -495,14 +495,14 @@ uint32_t rfalNfcDepCalculateRWT( uint8_t wt ); /*! ****************************************************************************** * \brief NFC-DEP Initiator ATR (Attribute Request) - * + * * This method configures the NFC-DEP layer with given parameters and then * sends an ATR to the Target with and checks for a valid response response * * \param[in] param : parameters to initialize and compose the ATR * \param[out] atrRes : location to store the ATR_RES * \param[out] atrResLen : length of the ATR_RES received - * + * * \return RFAL_ERR_NONE : No error * \return RFAL_ERR_TIMEOUT : Timeout occurred * \return RFAL_ERR_PROTO : Protocol error occurred @@ -514,15 +514,15 @@ ReturnCode rfalNfcDepATR( const rfalNfcDepAtrParam* param, rfalNfcDepAtrRes *atr /*! ****************************************************************************** * \brief NFC-DEP Initiator PSL (Parameter Selection) - * + * * This method sends a PSL to the Target with the given parameters and checks * for a valid response response - * + * * The parameters must be coded according to Digital 1.1 16.7.1 - * + * * \param[in] BRS : the selected Bit Rates for Initiator and Target * \param[in] FSL : the maximum length of Commands and Responses - * + * * \return RFAL_ERR_NONE : No error * \return RFAL_ERR_TIMEOUT : Timeout occurred * \return RFAL_ERR_PROTO : Protocol error occurred @@ -534,12 +534,12 @@ ReturnCode rfalNfcDepPSL( uint8_t BRS, uint8_t FSL ); /*! ****************************************************************************** * \brief NFC-DEP Initiator DSL (Deselect) - * - * This method checks if the NFCIP module is configured as initiator and if - * so sends a DSL REQ, waits the target's response and checks it - * - * In case of performing as target no action is taken - * + * + * This method checks if the NFCIP module is configured as initiator and if + * so sends a DSL REQ, waits the target's response and checks it + * + * In case of performing as target no action is taken + * * \return RFAL_ERR_NONE : No error * \return RFAL_ERR_TIMEOUT : Timeout occurred * \return RFAL_ERR_MAX_RERUNS : Timeout occurred @@ -552,12 +552,12 @@ ReturnCode rfalNfcDepDSL( void ); /*! ****************************************************************************** * \brief NFC-DEP Initiator RLS (Release) - * - * This method checks if the NFCIP module is configured as initiator and if - * so sends a RLS REQ, waits target's response and checks it - * - * In case of performing as target no action is taken - * + * + * This method checks if the NFCIP module is configured as initiator and if + * so sends a RLS REQ, waits target's response and checks it + * + * In case of performing as target no action is taken + * * \return RFAL_ERR_NONE : No error * \return RFAL_ERR_TIMEOUT : Timeout occurred * \return RFAL_ERR_MAX_RERUNS : Timeout occurred @@ -567,15 +567,15 @@ ReturnCode rfalNfcDepDSL( void ); ReturnCode rfalNfcDepRLS( void ); -/*! +/*! ***************************************************************************** * \brief NFC-DEP Initiator Handle Activation - * + * * This performs a Activation into NFC-DEP layer with the given - * parameters. It sends ATR_REQ and if the higher bit rates are supported by + * parameters. It sends ATR_REQ and if the higher bit rates are supported by * both devices it additionally sends PSL * Once Activated all details of the device are provided on nfcDepDev - * + * * \param[in] param : required parameters to initialize and send ATR_REQ * \param[in] desiredBR : Desired bit rate supported by the Poller * \param[out] nfcDepDev : NFC-DEP information of the activated Listen device @@ -596,20 +596,20 @@ ReturnCode rfalNfcDepInitiatorHandleActivation( rfalNfcDepAtrParam* param, rfalB /*! ****************************************************************************** - * \brief Check if buffer contains valid ATR_REQ - * + * \brief Check if buffer contains valid ATR_REQ + * * This method checks if the given ATR_REQ is valid - * - * + * + * * \param[in] buf : buffer holding Initiator's received request * \param[in] bufLen : size of the msg contained on the buf in Bytes - * \param[out] nfcid3 : pointer to where the NFCID3 may be outputed, + * \param[out] nfcid3 : pointer to where the NFCID3 may be outputed, * nfcid3 has NFCF_SENSF_NFCID3_LEN as length - * Pass NULL if output parameter not desired - * + * Pass NULL if output parameter not desired + * * \return true : Valid ATR_REQ received, the ATR_RES has been computed in txBuf * \return false : Invalid protocol request - * + * ****************************************************************************** */ bool rfalNfcDepIsAtrReq( const uint8_t* buf, uint16_t bufLen, uint8_t* nfcid3 ); @@ -617,13 +617,13 @@ bool rfalNfcDepIsAtrReq( const uint8_t* buf, uint16_t bufLen, uint8_t* nfcid3 ); /*! ****************************************************************************** - * \brief Check is Target has received ATR - * + * \brief Check is Target has received ATR + * * This method checks if the NFCIP module is configured as target and if a * ATR REQ has been received ( whether is in activation or in data exchange) - * + * * \return true : a ATR has already been received - * \return false : no ATR has been received + * \return false : no ATR has been received ****************************************************************************** */ bool rfalNfcDepTargetRcvdATR( void ); @@ -631,28 +631,28 @@ bool rfalNfcDepTargetRcvdATR( void ); /*! ***************************************************************************** * \brief NFCDEP Start Listen Activation Handling - * + * * Start Activation Handling and setup to receive first frame which may - * contain complete or partial DEP-REQ after activation is completed - * - * Pass in ATR_REQ for NFC-DEP to handle ATR_RES. The Activation Handling + * contain complete or partial DEP-REQ after activation is completed + * + * Pass in ATR_REQ for NFC-DEP to handle ATR_RES. The Activation Handling * handles ATR_RES and PSL_RES if a PSL_REQ is received - * + * * Activation is completed if PSL_RES is sent or if first I-PDU is received - * - * \ref rfalNfcDepListenGetActivationStatus() provide status of the + * + * \ref rfalNfcDepListenGetActivationStatus() provide status of the * ongoing activation - * - * \warning nfcDepGetTransceiveStatus() shall be called right after activation - * is completed (i.e. rfalNfcDepListenGetActivationStatus() return RFAL_ERR_NONE) + * + * \warning nfcDepGetTransceiveStatus() shall be called right after activation + * is completed (i.e. rfalNfcDepListenGetActivationStatus() return RFAL_ERR_NONE) * to check for first received frame. - * + * * \param[in] param : Target parameters to be used - * \param[in] atrReq : reference to buffer containing ATR_REQ + * \param[in] atrReq : reference to buffer containing ATR_REQ * \param[in] atrReqLength: Length of ATR_REQ - * \param[out] rxParam : references to buffer, length and chaining indication + * \param[out] rxParam : references to buffer, length and chaining indication * for first complete LLCP to be received - * + * * \return RFAL_ERR_NONE : ATR_REQ is valid and activation ongoing * \return RFAL_ERR_PARAM : ATR_REQ or other params are invalid * \return RFAL_ERR_LINK_LOSS : Remote Field is turned off @@ -664,7 +664,7 @@ ReturnCode rfalNfcDepListenStartActivation( const rfalNfcDepTargetParam *param, /*! ***************************************************************************** * \brief Get the current NFC-DEP Activation Status - * + * * \return RFAL_ERR_NONE : Activation has completed successfully * \return RFAL_ERR_BUSY : Activation is ongoing * \return RFAL_ERR_LINK_LOSS : Remote Field was turned off @@ -674,18 +674,18 @@ ReturnCode rfalNfcDepListenGetActivationStatus( void ); /*! ***************************************************************************** - * \brief Start Transceive - * + * \brief Start Transceive + * * Transceives a complete or partial DEP block - * - * The txBuf contains complete or partial of DEP to be transmitted. + * + * The txBuf contains complete or partial of DEP to be transmitted. * The Prologue field of the I-PDU is handled internally - * - * If the buffer contains partial LLCP and is not the last block, then + * + * If the buffer contains partial LLCP and is not the last block, then * isTxChaining must be set to true - * + * * \param[in] param: reference parameters to be used for the Transceive - * + * * \return RFAL_ERR_PARAM : Bad request * \return RFAL_ERR_WRONG_STATE : The module is not in a proper state * \return RFAL_ERR_NONE : The Transceive request has been started @@ -699,15 +699,15 @@ ReturnCode rfalNfcDepStartTransceive( const rfalNfcDepTxRxParam *param ); * \brief Return the Transceive status * * Returns the status of the NFC-DEP Transceive - * - * \warning When the other device is performing chaining once a chained - * block is received the error RFAL_ERR_AGAIN is sent. At this point - * caller must handle the received data immediately. - * When RFAL_ERR_AGAIN is returned an ACK has already been sent to - * the other device and the next block might be incoming. - * If rfalWorker() is called frequently it will place the next - * block on the given buffer - * + * + * \warning When the other device is performing chaining once a chained + * block is received the error RFAL_ERR_AGAIN is sent. At this point + * caller must handle the received data immediately. + * When RFAL_ERR_AGAIN is returned an ACK has already been sent to + * the other device and the next block might be incoming. + * If rfalWorker() is called frequently it will place the next + * block on the given buffer + * * \return RFAL_ERR_NONE : Transceive has been completed successfully * \return RFAL_ERR_BUSY : Transceive is ongoing * \return RFAL_ERR_PROTO : Protocol error occurred @@ -715,7 +715,7 @@ ReturnCode rfalNfcDepStartTransceive( const rfalNfcDepTxRxParam *param ); * \return RFAL_ERR_SLEEP_REQ : Deselect has been received and responded * \return RFAL_ERR_NOMEM : The received I-PDU does not fit into the * receive buffer - * \return RFAL_ERR_LINK_LOSS : Communication is lost because Reader/Writer + * \return RFAL_ERR_LINK_LOSS : Communication is lost because Reader/Writer * has turned off its field * \return RFAL_ERR_AGAIN : received one chaining block, continue to call * this method to retrieve the remaining blocks @@ -726,20 +726,20 @@ ReturnCode rfalNfcDepGetTransceiveStatus( void ); /*! ***************************************************************************** - * \brief Start PDU Transceive - * + * \brief Start PDU Transceive + * * This method triggers a NFC-DEP Transceive containing a complete PDU * It transmits the given message and handles all protocol retransmitions, * error handling and control messages - * - * The txBuf contains a complete PDU to be transmitted + * + * The txBuf contains a complete PDU to be transmitted * The Prologue field will be manipulated by the Transceive - * + * * \warning the txBuf will be modified during the transmission * \warning the maximum RF frame which can be received is limited by param.tmpBuf - * + * * \param[in] param: reference parameters to be used for the Transceive - * + * * \return RFAL_ERR_PARAM : Bad request * \return RFAL_ERR_WRONG_STATE : The module is not in a proper state * \return RFAL_ERR_NONE : The Transceive request has been started @@ -753,8 +753,8 @@ ReturnCode rfalNfcDepStartPduTransceive( rfalNfcDepPduTxRxParam param ); * \brief Return the PDU Transceive status * * Returns the status of the NFC-DEP PDU Transceive - * - * + * + * * \return RFAL_ERR_NONE : Transceive has been completed successfully * \return RFAL_ERR_BUSY : Transceive is ongoing * \return RFAL_ERR_PROTO : Protocol error occurred @@ -762,7 +762,7 @@ ReturnCode rfalNfcDepStartPduTransceive( rfalNfcDepPduTxRxParam param ); * \return RFAL_ERR_SLEEP_REQ : Deselect has been received and responded * \return RFAL_ERR_NOMEM : The received I-PDU does not fit into the * receive buffer - * \return RFAL_ERR_LINK_LOSS : Communication is lost because Reader/Writer + * \return RFAL_ERR_LINK_LOSS : Communication is lost because Reader/Writer * has turned off its field ***************************************************************************** */ diff --git a/core/embed/io/nfc/rfal/source/rfal_isoDep.c b/core/embed/io/nfc/rfal/source/rfal_isoDep.c index fef699259a..53a9bc77e9 100644 --- a/core/embed/io/nfc/rfal/source/rfal_isoDep.c +++ b/core/embed/io/nfc/rfal/source/rfal_isoDep.c @@ -26,7 +26,7 @@ * \author Gustavo Patricio * * \brief Implementation of ISO-DEP protocol - * + * * This implementation was based on the following specs: * - ISO/IEC 14443-4 2nd Edition 2008-07-15 * - NFC Forum Digital Protocol 1.1 2014-01-14 @@ -48,10 +48,10 @@ * ENABLE SWITCH ****************************************************************************** */ - -/* Feature switch may be enabled or disabled by user at rfal_platform.h + +/* Feature switch may be enabled or disabled by user at rfal_platform.h * Default configuration (ST25R dependant) also provided at rfal_defConfig.h - * + * * RFAL_FEATURE_ISO_DEP */ @@ -138,7 +138,7 @@ #define ISODEP_MAX_RERUNS (0x0FFFFFFFU)/*!< Maximum rerun retrys for a blocking protocol run*/ -#define ISODEP_PCBSBLOCK ( 0x00U | ISODEP_PCB_SBLOCK | ISODEP_PCB_B2_BIT ) /*!< PCB Value of a S-Block */ +#define ISODEP_PCBSBLOCK ( 0x00U | ISODEP_PCB_SBLOCK | ISODEP_PCB_B2_BIT ) /*!< PCB Value of a S-Block */ #define ISODEP_PCB_SDSL ( ISODEP_PCBSBLOCK | ISODEP_PCB_DESELECT ) /*!< PCB Value of a S-Block with DESELECT */ #define ISODEP_PCB_SWTX ( ISODEP_PCBSBLOCK | ISODEP_PCB_WTX ) /*!< PCB Value of a S-Block with WTX */ #define ISODEP_PCB_SPARAMETERS ( ISODEP_PCB_SBLOCK | ISODEP_PCB_WTX ) /*!< PCB Value of a S-Block with PARAMETERS */ @@ -188,7 +188,7 @@ #define RFAL_ISODEP_PPS0_VALID_MASK (0xEFU) /*!< PPS REQ PPS0 valid coding mask ISO14443-4 5.4 */ #define RFAL_ISODEP_CMD_ATTRIB (0x1DU) /*!< ATTRIB command Digital 1.1 14.6.1 */ -#define RFAL_ISODEP_ATTRIB_PARAM2_DSI_SHIFT (6U) /*!< ATTRIB PARAM2 DSI shift Digital 1.1 14.6.1 */ +#define RFAL_ISODEP_ATTRIB_PARAM2_DSI_SHIFT (6U) /*!< ATTRIB PARAM2 DSI_ID shift Digital 1.1 14.6.1 */ #define RFAL_ISODEP_ATTRIB_PARAM2_DRI_SHIFT (4U) /*!< ATTRIB PARAM2 DRI shift Digital 1.1 14.6.1 */ #define RFAL_ISODEP_ATTRIB_PARAM2_DXI_MASK (0xF0U) /*!< ATTRIB PARAM2 DxI mask Digital 1.1 14.6.1 */ #define RFAL_ISODEP_ATTRIB_PARAM2_FSDI_MASK (0x0FU) /*!< ATTRIB PARAM2 FSDI mask Digital 1.1 14.6.1 */ @@ -224,9 +224,9 @@ #define RFAL_ISODEP_PPS0_PPS1_PRESENT (0x11U) /*!< PPS0 byte indicating that PPS1 is present */ #define RFAL_ISODEP_PPS0_PPS1_NOT_PRESENT (0x01U) /*!< PPS0 byte indicating that PPS1 is NOT present */ #define RFAL_ISODEP_PPS1_DRI_MASK (0x03U) /*!< PPS1 byte DRI mask bits */ -#define RFAL_ISODEP_PPS1_DSI_MASK (0x0CU) /*!< PPS1 byte DSI mask bits */ -#define RFAL_ISODEP_PPS1_DSI_SHIFT (2U) /*!< PPS1 byte DSI shift */ -#define RFAL_ISODEP_PPS1_DxI_MASK (0x03U) /*!< PPS1 byte DSI/DRS mask bits */ +#define RFAL_ISODEP_PPS1_DSI_MASK (0x0CU) /*!< PPS1 byte DSI_ID mask bits */ +#define RFAL_ISODEP_PPS1_DSI_SHIFT (2U) /*!< PPS1 byte DSI_ID shift */ +#define RFAL_ISODEP_PPS1_DxI_MASK (0x03U) /*!< PPS1 byte DSI_ID/DRS mask bits */ /*! Delta Time for polling during Activation (ATS) : 20ms Digital 1.0 11.7.1.1 & A.7 */ @@ -257,27 +257,27 @@ #define rfalIsoDep_PCBisSBlock( pcb ) ( ((pcb) & (ISODEP_PCB_xBLOCK_MASK | ISODEP_PCB_SB_VALID_MASK)) == (ISODEP_PCB_SBLOCK | ISODEP_PCB_SB_VALID_VAL)) /*!< Checks if pcb is a S-Block */ #define rfalIsoDep_PCBisChaining( pcb ) ( ((pcb) & ISODEP_PCB_CHAINING_BIT) == ISODEP_PCB_CHAINING_BIT) /*!< Checks if pcb is indicating chaining */ - + #define rfalIsoDep_PCBisDeselect( pcb ) ( ((pcb) & ISODEP_PCB_Sxx_MASK) == ISODEP_PCB_DESELECT) /*!< Checks if pcb is indicating DESELECT */ #define rfalIsoDep_PCBisWTX( pcb ) ( ((pcb) & ISODEP_PCB_Sxx_MASK) == ISODEP_PCB_WTX) /*!< Checks if pcb is indicating WTX */ - + #define rfalIsoDep_PCBisACK( pcb ) ( ((pcb) & ISODEP_PCB_Rx_MASK) == ISODEP_PCB_ACK) /*!< Checks if pcb is indicating ACK */ #define rfalIsoDep_PCBisNAK( pcb ) ( ((pcb) & ISODEP_PCB_Rx_MASK) == ISODEP_PCB_NAK) /*!< Checks if pcb is indicating ACK */ - + #define rfalIsoDep_PCBhasDID( pcb ) ( ((pcb) & ISODEP_PCB_DID_BIT) == ISODEP_PCB_DID_BIT) /*!< Checks if pcb is indicating DID */ #define rfalIsoDep_PCBhasNAD( pcb ) ( ((pcb) & ISODEP_PCB_NAD_BIT) == ISODEP_PCB_NAD_BIT) /*!< Checks if pcb is indicating NAD */ #define rfalIsoDep_PCBisIChaining( pcb ) ( rfalIsoDep_PCBisIBlock(pcb) && rfalIsoDep_PCBisChaining(pcb) ) /*!< Checks if pcb is I-Block indicating chaining */ - + #define rfalIsoDep_PCBisSDeselect( pcb ) ( rfalIsoDep_PCBisSBlock(pcb) && rfalIsoDep_PCBisDeselect(pcb) ) /*!< Checks if pcb is S-Block indicating DESELECT */ #define rfalIsoDep_PCBisSWTX( pcb ) ( rfalIsoDep_PCBisSBlock(pcb) && rfalIsoDep_PCBisWTX(pcb) ) /*!< Checks if pcb is S-Block indicating WTX */ - + #define rfalIsoDep_PCBisRACK( pcb ) ( rfalIsoDep_PCBisRBlock(pcb) && rfalIsoDep_PCBisACK(pcb) ) /*!< Checks if pcb is R-Block indicating ACK */ #define rfalIsoDep_PCBisRNAK( pcb ) ( rfalIsoDep_PCBisRBlock(pcb) && rfalIsoDep_PCBisNAK(pcb) ) /*!< Checks if pcb is R-Block indicating NAK */ -#define rfalIsoDep_PCBIBlock( bn ) ( (uint8_t)( 0x00U | ISODEP_PCB_IBLOCK | ISODEP_PCB_B2_BIT | ((bn) & ISODEP_PCB_BN_MASK) )) /*!< Returns an I-Block with the given block number (bn) */ +#define rfalIsoDep_PCBIBlock( bn ) ( (uint8_t)( 0x00U | ISODEP_PCB_IBLOCK | ISODEP_PCB_B2_BIT | ((bn) & ISODEP_PCB_BN_MASK) )) /*!< Returns an I-Block with the given block number (bn) */ #define rfalIsoDep_PCBIBlockChaining( bn ) ( (uint8_t)(rfalIsoDep_PCBIBlock(bn) | ISODEP_PCB_CHAINING_BIT)) /*!< Returns an I-Block with the given block number (bn) indicating chaining */ #define rfalIsoDep_PCBRBlock( bn ) ( (uint8_t)( 0x00U | ISODEP_PCB_RBLOCK | ISODEP_PCB_B6_BIT | ISODEP_PCB_B2_BIT | ((bn) & ISODEP_PCB_BN_MASK) ) ) /*!< Returns an R-Block with the given block number (bn) */ @@ -313,17 +313,17 @@ * LOCAL DATA TYPES ****************************************************************************** */ - + /*! Internal structure to be used in handling of S(PARAMETRS) only */ typedef struct -{ +{ uint8_t pcb; /*!< PCB byte */ rfalIsoDepSParameter sParam; /*!< S(PARAMETERS) */ } rfalIsoDepControlMsgSParam; /*! Enumeration of the possible control message types */ typedef enum -{ +{ ISODEP_R_ACK, /*!< R-ACK Acknowledge */ ISODEP_R_NAK, /*!< R-NACK Negative acknowledge */ ISODEP_S_WTX, /*!< S-WTX Waiting Time Extension */ @@ -344,17 +344,17 @@ typedef enum ISODEP_ST_PCD_TX, /*!< PCD Transmission State */ ISODEP_ST_PCD_RX, /*!< PCD Reception State */ ISODEP_ST_PCD_WAIT_DSL, /*!< PCD Wait for DSL response */ - + ISODEP_ST_PICC_ACT_ATS, /*!< PICC has replied to RATS (ATS) */ ISODEP_ST_PICC_ACT_ATTRIB, /*!< PICC has replied to ATTRIB */ ISODEP_ST_PICC_RX, /*!< PICC Reception State */ ISODEP_ST_PICC_SWTX, /*!< PICC Waiting Time eXtension */ ISODEP_ST_PICC_SDSL, /*!< PICC S(DSL) response ongoing */ ISODEP_ST_PICC_TX, /*!< PICC Transmission State */ - + ISODEP_ST_PCD_ACT_RATS, /*!< PCD activation (RATS) */ ISODEP_ST_PCD_ACT_PPS, /*!< PCD activation (PPS) */ - + } rfalIsoDepState; @@ -364,7 +364,7 @@ typedef enum typedef struct{ rfalIsoDepState state; /*!< ISO-DEP module state */ rfalIsoDepRole role; /*!< Current ISO-DEP role */ - + uint8_t blockNumber; /*!< Current block number */ uint8_t did; /*!< Current DID */ uint8_t nad; /*!< Current DID */ @@ -384,8 +384,8 @@ typedef struct{ uint16_t rxBufLen; /*!< Rx buffer length */ uint8_t txBufInfPos; /*!< Start of payload in txBuf */ uint8_t rxBufInfPos; /*!< Start of payload in rxBuf */ - - + + uint16_t ourFsx; /*!< Our current FSx FSC or FSD (Frame size) */ uint8_t lastPCB; /*!< Last PCB sent */ uint8_t lastWTXM; /*!< Last WTXM sent */ @@ -394,46 +394,46 @@ typedef struct{ rfalBitRate txBR; /*!< Current Tx Bit Rate */ rfalBitRate rxBR; /*!< Current Rx Bit Rate */ uint16_t *rxLen; /*!< Output parameter ptr to Rx length */ - bool *rxChaining; /*!< Output parameter ptr to Rx chaining flag */ + bool *rxChaining; /*!< Output parameter ptr to Rx chaining flag */ uint32_t WTXTimer; /*!< Timer used for WTX */ bool lastDID00; /*!< Last PCD block had DID flag (for DID = 0) */ - + bool isTxPending; /*!< Flag pending Block while waiting WTX Ack */ bool isWait4WTX; /*!< Flag for waiting WTX Ack */ - + uint8_t maxRetriesI; /*!< Number of retries for a I-Block */ uint8_t maxRetriesR; /*!< Number of retries for a R-Block */ uint8_t maxRetriesSDSL;/*!< Number of retries for S(DESELECT) errors */ uint8_t maxRetriesSWTX;/*!< Number of retries for S(WTX) errors */ uint8_t maxRetriesSnWTX;/*!< Number of retries S(WTX) replied w NACK */ uint8_t maxRetriesRATS;/*!< Number of retries for RATS */ - + rfalComplianceMode compMode; /*!< Compliance mode */ - + uint8_t ctrlBuf[ISODEP_CONTROLMSG_BUF_LEN]; /*!< Control msg buf */ uint16_t ctrlRxLen; /*!< Control msg rcvd len */ - - union { /* PRQA S 0750 # MISRA 19.2 - Members of the union will not be used concurrently, only one frame at a time */ + + union { /* PRQA S 0750 # MISRA 19.2 - Members of the union will not be used concurrently, only one frame at a time */ #if RFAL_FEATURE_NFCA rfalIsoDepRats ratsReq; rfalIsoDepPpsReq ppsReq; #endif /* RFAL_FEATURE_NFCA */ - + #if RFAL_FEATURE_NFCB rfalIsoDepAttribCmd attribReq; #endif /* RFAL_FEATURE_NFCB */ }actv; /*!< Activation buffer */ - + uint8_t* rxLen8; /*!< Receive length (8-bit) */ rfalIsoDepDevice* actvDev; /*!< Activation Device Info */ rfalIsoDepListenActvParam actvParam; /*!< Listen Activation context */ - - + + rfalIsoDepApduTxRxParam APDUParam; /*!< APDU TxRx params */ uint16_t APDUTxPos; /*!< APDU Tx position */ uint16_t APDURxPos; /*!< APDU Rx position */ bool isAPDURxChaining; /*!< APDU Transceive chaining flag */ - + }rfalIsoDep; @@ -463,15 +463,15 @@ static void rfalIsoDepApdu2IBLockParam( rfalIsoDepApduTxRxParam apduParam, rfalI #if RFAL_FEATURE_NFCA static ReturnCode rfalIsoDepStartRATS( rfalIsoDepFSxI FSDI, uint8_t DID, rfalIsoDepAts *ats, uint8_t *atsLen ); static ReturnCode rfalIsoDepGetRATSStatus( void ); - static ReturnCode rfalIsoDepStartPPS( uint8_t DID, rfalBitRate DSI, rfalBitRate DRI, rfalIsoDepPpsRes *ppsRes ); + static ReturnCode rfalIsoDepStartPPS( uint8_t DID, rfalBitRate DSI_ID, rfalBitRate DRI, rfalIsoDepPpsRes *ppsRes ); static ReturnCode rfalIsoDepGetPPSSTatus( void ); #endif /* RFAL_FEATURE_NFCA */ #if RFAL_FEATURE_NFCB - static ReturnCode rfalIsoDepStartATTRIB( const uint8_t* nfcid0, uint8_t PARAM1, rfalBitRate DSI, rfalBitRate DRI, rfalIsoDepFSxI FSDI, uint8_t PARAM3, uint8_t DID, const uint8_t* HLInfo, uint8_t HLInfoLen, uint32_t fwt, rfalIsoDepAttribRes *attribRes, uint8_t *attribResLen ); + static ReturnCode rfalIsoDepStartATTRIB( const uint8_t* nfcid0, uint8_t PARAM1, rfalBitRate DSI_ID, rfalBitRate DRI, rfalIsoDepFSxI FSDI, uint8_t PARAM3, uint8_t DID, const uint8_t* HLInfo, uint8_t HLInfoLen, uint32_t fwt, rfalIsoDepAttribRes *attribRes, uint8_t *attribResLen ); static ReturnCode rfalIsoDepGetATTRIBStatus( void ); #endif /* RFAL_FEATURE_NFCB */ - + #endif /* RFAL_FEATURE_ISO_DEP_POLL */ #if RFAL_FEATURE_ISO_DEP_LISTEN @@ -504,11 +504,11 @@ static ReturnCode rfalIsoDepTx( uint8_t pcb, const uint8_t* txBuf, uint8_t *infB uint8_t computedPcb; rfalTransceiveContext ctx; - + txBlock = infBuf; /* Point to beginning of the INF, and go backwards */ gIsoDep.lastPCB = pcb; /* Store the last PCB sent */ - - + + if ( infLen > 0U ) { if ( ((uintptr_t)infBuf - (uintptr_t)txBuf) < gIsoDep.hdrLen ) /* Check that we can fit the header in the given space */ @@ -516,39 +516,39 @@ static ReturnCode rfalIsoDepTx( uint8_t pcb, const uint8_t* txBuf, uint8_t *infB return RFAL_ERR_NOMEM; } } - - + + /*******************************************************************************/ /* Compute optional PCB bits */ computedPcb = pcb; if (((gIsoDep.did != RFAL_ISODEP_NO_DID) && (gIsoDep.did != RFAL_ISODEP_DID_00)) || ((gIsoDep.did == RFAL_ISODEP_DID_00) && (gIsoDep.lastDID00)) ) { computedPcb |= ISODEP_PCB_DID_BIT; } if (gIsoDep.nad != RFAL_ISODEP_NO_NAD) { computedPcb |= ISODEP_PCB_NAD_BIT; } - if ((gIsoDep.isTxChaining) && (rfalIsoDep_PCBisIBlock(computedPcb)) ) { computedPcb |= ISODEP_PCB_CHAINING_BIT; } + if ((gIsoDep.isTxChaining) && (rfalIsoDep_PCBisIBlock(computedPcb)) ) { computedPcb |= ISODEP_PCB_CHAINING_BIT; } + - /*******************************************************************************/ /* Compute Payload on the given txBuf, start by the PCB | DID | NAD | before INF */ - + if( (ISODEP_PCB_NAD_BIT & computedPcb) != 0U ) { *(--txBlock) = gIsoDep.nad; /* NAD is optional */ } - + if( (ISODEP_PCB_DID_BIT & computedPcb) != 0U) { *(--txBlock) = gIsoDep.did; /* DID is optional */ } - + *(--txBlock) = computedPcb; /* PCB always present */ - + txBufLen = (infLen + (uint16_t)((uintptr_t)infBuf - (uintptr_t)txBlock)); /* Calculate overall buffer size */ - + if( txBufLen > (gIsoDep.fsx - ISODEP_CRC_LEN) ) /* Check if msg length violates the maximum frame size FSC */ { return RFAL_ERR_NOTSUPP; } - - + + rfalCreateByteFlagsTxRxContext( ctx, txBlock, txBufLen, gIsoDep.rxBuf, gIsoDep.rxBufLen, gIsoDep.rxLen, RFAL_TXRX_FLAGS_DEFAULT, ((gIsoDep.role == ISODEP_ROLE_PICC) ? RFAL_FWT_NONE : fwt ) ); return rfalStartTransceive( &ctx ); } @@ -556,41 +556,41 @@ static ReturnCode rfalIsoDepTx( uint8_t pcb, const uint8_t* txBuf, uint8_t *infB /*******************************************************************************/ static ReturnCode rfalIsoDepHandleControlMsg( rfalIsoDepControlMsg controlMsg, uint8_t param ) { - uint8_t pcb; + uint8_t pcb; uint8_t infLen; uint32_t fwtTemp; - + infLen = 0; fwtTemp = (gIsoDep.fwt + gIsoDep.dFwt); RFAL_MEMSET( gIsoDep.ctrlBuf, 0x00, ISODEP_CONTROLMSG_BUF_LEN ); - + switch( controlMsg ) { /*******************************************************************************/ case ISODEP_R_ACK: - + if( gIsoDep.cntRRetrys++ > gIsoDep.maxRetriesR ) { return RFAL_ERR_TIMEOUT; /* NFC Forum mandates timeout or transmission error depending on previous errors */ } - + pcb = rfalIsoDep_PCBRACK( gIsoDep.blockNumber ); break; - - + + /*******************************************************************************/ case ISODEP_R_NAK: - + if( ( gIsoDep.cntRRetrys++ > gIsoDep.maxRetriesR ) || /* Max R Block retries reached */ ( gIsoDep.cntSWtxNack >= gIsoDep.maxRetriesSnWTX ) ) /* Max number PICC is allowed to respond with S(WTX) to R(NAK) */ { return RFAL_ERR_TIMEOUT; } - + pcb = rfalIsoDep_PCBRNAK( gIsoDep.blockNumber ); break; - - + + /*******************************************************************************/ case ISODEP_S_WTX: @@ -598,34 +598,34 @@ static ReturnCode rfalIsoDepHandleControlMsg( rfalIsoDepControlMsg controlMsg, u { return RFAL_ERR_PROTO; } - + /* Check if WTXM is valid */ if( ! rfalIsoDep_isWTXMValid(param) ) { return RFAL_ERR_PROTO; } - + if( gIsoDep.role == ISODEP_ROLE_PCD ) { - /* Calculate temp Wait Time eXtension */ + /* Calculate temp Wait Time eXtension */ fwtTemp = (gIsoDep.fwt * param); fwtTemp = RFAL_MIN( RFAL_ISODEP_MAX_FWT, fwtTemp ); fwtTemp += gIsoDep.dFwt; } - + pcb = ISODEP_PCB_SWTX; gIsoDep.ctrlBuf[ RFAL_ISODEP_PCB_LEN + RFAL_ISODEP_DID_LEN + infLen++] = param; break; - - + + /*******************************************************************************/ case ISODEP_S_DSL: - + if( gIsoDep.cntSDslRetrys++ > gIsoDep.maxRetriesSDSL ) { return RFAL_ERR_TIMEOUT; /* NFC Forum mandates timeout or transmission error depending on previous errors */ } - + if( gIsoDep.role == ISODEP_ROLE_PCD ) { /* Digital 1.0 - 13.2.7.3 Poller must wait fwtDEACTIVATION */ @@ -634,12 +634,12 @@ static ReturnCode rfalIsoDepHandleControlMsg( rfalIsoDepControlMsg controlMsg, u } pcb = ISODEP_PCB_SDSL; break; - + /*******************************************************************************/ default: return RFAL_ERR_INTERNAL; } - + return rfalIsoDepTx( pcb, gIsoDep.ctrlBuf, &gIsoDep.ctrlBuf[RFAL_ISODEP_PCB_LEN + RFAL_ISODEP_DID_LEN], infLen, fwtTemp ); } @@ -651,22 +651,22 @@ static ReturnCode rfalIsoDepReSendControlMsg( void ) { return rfalIsoDepHandleControlMsg( ISODEP_R_ACK, RFAL_ISODEP_NO_PARAM ); } - + if( rfalIsoDep_PCBisRNAK( gIsoDep.lastPCB ) ) { return rfalIsoDepHandleControlMsg( ISODEP_R_NAK, RFAL_ISODEP_NO_PARAM ); } - + if( rfalIsoDep_PCBisSDeselect( gIsoDep.lastPCB ) ) { return rfalIsoDepHandleControlMsg( ISODEP_S_DSL, RFAL_ISODEP_NO_PARAM ); } - + if( rfalIsoDep_PCBisSWTX( gIsoDep.lastPCB ) ) { return rfalIsoDepHandleControlMsg( ISODEP_S_WTX, gIsoDep.lastWTXM ); } - return RFAL_ERR_WRONG_STATE; + return RFAL_ERR_WRONG_STATE; } #endif /* RFAL_FEATURE_ISO_DEP_LISTEN */ @@ -693,15 +693,15 @@ void rfalIsoDepInitialize( void ) gIsoDep.fsx = (uint16_t)RFAL_ISODEP_FSX_16; gIsoDep.ourFsx = (uint16_t)RFAL_ISODEP_FSX_16; gIsoDep.hdrLen = RFAL_ISODEP_PCB_LEN; - + gIsoDep.rxLen = NULL; gIsoDep.rxBuf = NULL; gIsoDep.rxBufInfPos = 0U; gIsoDep.txBufInfPos = 0U; - + gIsoDep.isTxPending = false; gIsoDep.isWait4WTX = false; - + gIsoDep.compMode = RFAL_COMPLIANCE_MODE_NFC; gIsoDep.maxRetriesR = RFAL_ISODEP_MAX_R_RETRYS; gIsoDep.maxRetriesI = RFAL_ISODEP_MAX_I_RETRYS; @@ -709,15 +709,15 @@ void rfalIsoDepInitialize( void ) gIsoDep.maxRetriesSWTX = RFAL_ISODEP_MAX_WTX_RETRYS; gIsoDep.maxRetriesSnWTX = RFAL_ISODEP_MAX_WTX_NACK_RETRYS; gIsoDep.maxRetriesRATS = RFAL_ISODEP_RATS_RETRIES; - + gIsoDep.APDURxPos = 0; gIsoDep.APDUTxPos = 0; gIsoDep.APDUParam.rxLen = NULL; gIsoDep.APDUParam.rxBuf = NULL; gIsoDep.APDUParam.txBuf = NULL; - + rfalIsoDepClearCounters(); - + /* Destroy any ongoing WTX timer */ rfalIsoDepTimerDestroy( gIsoDep.WTXTimer ); gIsoDep.WTXTimer = 0U; @@ -734,7 +734,7 @@ void rfalIsoDepInitializeWithParams( rfalComplianceMode compMode, uint8_t maxRetriesRATS ) { rfalIsoDepInitialize(); - + gIsoDep.compMode = compMode; gIsoDep.maxRetriesR = maxRetriesR; gIsoDep.maxRetriesSnWTX = maxRetriesSnWTX; @@ -751,33 +751,33 @@ static ReturnCode rfalIsoDepDataExchangePCD( uint16_t *outActRxLen, bool *outIsC { ReturnCode ret; uint8_t rxPCB; - + /* Check out parameters */ if( (outActRxLen == NULL) || (outIsChaining == NULL) ) { return RFAL_ERR_PARAM; - } - + } + *outIsChaining = false; - - /* Calculate header required and check if the buffers InfPositions are suitable */ + + /* Calculate header required and check if the buffers InfPositions are suitable */ gIsoDep.hdrLen = RFAL_ISODEP_PCB_LEN; if ((gIsoDep.did != RFAL_ISODEP_NO_DID) && (gIsoDep.did != RFAL_ISODEP_DID_00)) { gIsoDep.hdrLen += RFAL_ISODEP_DID_LEN; } if (gIsoDep.nad != RFAL_ISODEP_NO_NAD) { gIsoDep.hdrLen += RFAL_ISODEP_NAD_LEN; } - + /* Check if there is enough space before the infPos to append ISO-DEP headers on rx and tx */ if( (gIsoDep.rxBufInfPos < gIsoDep.hdrLen) || (gIsoDep.txBufInfPos < gIsoDep.hdrLen) ) { return RFAL_ERR_PARAM; } - + /*******************************************************************************/ switch( gIsoDep.state ) { /*******************************************************************************/ case ISODEP_ST_IDLE: return RFAL_ERR_NONE; - + /*******************************************************************************/ case ISODEP_ST_PCD_TX: ret = rfalIsoDepTx( rfalIsoDep_PCBIBlock( gIsoDep.blockNumber ), gIsoDep.txBuf, &gIsoDep.txBuf[gIsoDep.txBufInfPos], gIsoDep.txBufLen, (gIsoDep.fwt + gIsoDep.dFwt) ); @@ -786,16 +786,16 @@ static ReturnCode rfalIsoDepDataExchangePCD( uint16_t *outActRxLen, bool *outIsC case RFAL_ERR_NONE: gIsoDep.state = ISODEP_ST_PCD_RX; break; - + default: return ret; } /* fall through */ - + /*******************************************************************************/ case ISODEP_ST_PCD_WAIT_DSL: /* PRQA S 2003 # MISRA 16.3 - Intentional fall through */ case ISODEP_ST_PCD_RX: - + ret = rfalGetTransceiveStatus(); switch( ret ) { @@ -805,9 +805,9 @@ static ReturnCode rfalIsoDepDataExchangePCD( uint16_t *outActRxLen, bool *outIsC case RFAL_ERR_PAR: case RFAL_ERR_FRAMING: /* added to handle test cases scenario TC_POL_NFCB_T4AT_BI_82_x_y & TC_POL_NFCB_T4BT_BI_82_x_y */ case RFAL_ERR_INCOMPLETE_BYTE: /* added to handle test cases scenario TC_POL_NFCB_T4AT_BI_82_x_y & TC_POL_NFCB_T4BT_BI_82_x_y */ - + if( gIsoDep.isRxChaining ) - { /* Rule 5 - In PICC chaining when a invalid/timeout occurs -> R-ACK */ + { /* Rule 5 - In PICC chaining when a invalid/timeout occurs -> R-ACK */ RFAL_EXIT_ON_ERR( ret, rfalIsoDepHandleControlMsg( ISODEP_R_ACK, RFAL_ISODEP_NO_PARAM ) ); } else if( gIsoDep.state == ISODEP_ST_PCD_WAIT_DSL ) @@ -819,47 +819,47 @@ static ReturnCode rfalIsoDepDataExchangePCD( uint16_t *outActRxLen, bool *outIsC RFAL_EXIT_ON_ERR( ret, rfalIsoDepHandleControlMsg( ISODEP_R_NAK, RFAL_ISODEP_NO_PARAM ) ); } return RFAL_ERR_BUSY; - + case RFAL_ERR_NONE: break; - + case RFAL_ERR_BUSY: return RFAL_ERR_BUSY; /* Debug purposes */ - + default: return ret; } - + /*******************************************************************************/ /* No error, process incoming msg */ /*******************************************************************************/ - + (*outActRxLen) = rfalConvBitsToBytes( *outActRxLen ); - - + + /* Check rcvd msg length, cannot be less then the expected header */ if( ((*outActRxLen) < gIsoDep.hdrLen) || ((*outActRxLen) >= gIsoDep.ourFsx) ) { return RFAL_ERR_PROTO; } - + /* Grab rcvd PCB */ rxPCB = gIsoDep.rxBuf[ ISODEP_PCB_POS ]; - - + + /* EMVCo doesn't allow usage of for CID or NAD EMVCo 2.6 TAble 10.2 */ if( (gIsoDep.compMode == RFAL_COMPLIANCE_MODE_EMV) && ( rfalIsoDep_PCBhasDID(rxPCB) || rfalIsoDep_PCBhasNAD(rxPCB)) ) { return RFAL_ERR_PROTO; } - + /* If we are expecting DID, check if PCB signals its presence and if device ID match*/ if( (gIsoDep.did != RFAL_ISODEP_NO_DID) && (gIsoDep.did != RFAL_ISODEP_DID_00) && ( (!rfalIsoDep_PCBhasDID(rxPCB)) || (gIsoDep.did != gIsoDep.rxBuf[ ISODEP_DID_POS ])) ) { return RFAL_ERR_PROTO; } - - + + /*******************************************************************************/ /* Process S-Block */ /*******************************************************************************/ @@ -878,12 +878,12 @@ static ReturnCode rfalIsoDepDataExchangePCD( uint16_t *outActRxLen, bool *outIsC { gIsoDep.cntSWtxNack = 0; /* Reset R(NACK)->S(WTX) counter */ } - + /* Rule 3 - respond to S-block: get 1st INF byte S(STW): Power + WTXM */ - RFAL_EXIT_ON_ERR( ret, rfalIsoDepHandleControlMsg( ISODEP_S_WTX, rfalIsoDep_GetWTXM(gIsoDep.rxBuf[gIsoDep.hdrLen]) ) ); + RFAL_EXIT_ON_ERR( ret, rfalIsoDepHandleControlMsg( ISODEP_S_WTX, rfalIsoDep_GetWTXM(gIsoDep.rxBuf[gIsoDep.hdrLen]) ) ); return RFAL_ERR_BUSY; } - + /* Check if is a deselect response */ if( rfalIsoDep_PCBisSDeselect(rxPCB) ) { @@ -892,14 +892,14 @@ static ReturnCode rfalIsoDepDataExchangePCD( uint16_t *outActRxLen, bool *outIsC rfalIsoDepInitialize(); /* Session finished reInit vars */ return RFAL_ERR_NONE; } - + /* Deselect response not expected */ /* fall through to PROTO error */ } /* Unexpected S-Block */ return RFAL_ERR_PROTO; } - + /*******************************************************************************/ /* Process R-Block */ /*******************************************************************************/ @@ -911,13 +911,13 @@ static ReturnCode rfalIsoDepDataExchangePCD( uint16_t *outActRxLen, bool *outIsC { /* Rule B - ACK with expected bn -> Increment block number */ gIsoDep.blockNumber = rfalIsoDep_PCBNextBN( gIsoDep.blockNumber ); - + /* R-ACK only allowed when PCD chaining */ if( !gIsoDep.isTxChaining ) { return RFAL_ERR_PROTO; } - + /* Rule 7 - Chaining transaction done, continue chaining */ rfalIsoDepClearCounters(); return RFAL_ERR_NONE; /* This block has been transmitted */ @@ -941,7 +941,7 @@ static ReturnCode rfalIsoDepDataExchangePCD( uint16_t *outActRxLen, bool *outIsC return RFAL_ERR_PROTO; } } - + /*******************************************************************************/ /* Process I-Block */ /*******************************************************************************/ @@ -953,53 +953,53 @@ static ReturnCode rfalIsoDepDataExchangePCD( uint16_t *outActRxLen, bool *outIsC { gIsoDep.isRxChaining = true; *outIsChaining = true; - + if( rfalIsoDep_GetBN(rxPCB) == gIsoDep.blockNumber ) { /* Rule B - ACK with correct block number -> Increase Block number */ rfalIsoDep_ToggleBN( gIsoDep.blockNumber ); - + rfalIsoDepClearCounters(); /* Clear counters in case R counter is already at max */ - + /* Rule 2 - Send ACK */ RFAL_EXIT_ON_ERR( ret, rfalIsoDepHandleControlMsg( ISODEP_R_ACK, RFAL_ISODEP_NO_PARAM ) ); - + /* Received I-Block with chaining, send current data to DH */ - + /* remove ISO DEP header, check is necessary to move the INF data on the buffer */ *outActRxLen -= gIsoDep.hdrLen; if( (gIsoDep.hdrLen != gIsoDep.rxBufInfPos) && (*outActRxLen > 0U) ) { RFAL_MEMMOVE( &gIsoDep.rxBuf[gIsoDep.rxBufInfPos], &gIsoDep.rxBuf[gIsoDep.hdrLen], *outActRxLen ); } - + rfalIsoDepClearCounters(); return RFAL_ERR_AGAIN; /* Send Again signalling to run again, but some chaining data has arrived */ } else { /* Rule 5 - PICC chaining invalid I-Block -> R-ACK */ - RFAL_EXIT_ON_ERR( ret, rfalIsoDepHandleControlMsg( ISODEP_R_ACK, RFAL_ISODEP_NO_PARAM ) ); + RFAL_EXIT_ON_ERR( ret, rfalIsoDepHandleControlMsg( ISODEP_R_ACK, RFAL_ISODEP_NO_PARAM ) ); } return RFAL_ERR_BUSY; } - - gIsoDep.isRxChaining = false; /* clear PICC chaining flag */ - + + gIsoDep.isRxChaining = false; /* clear PICC chaining flag */ + if( rfalIsoDep_GetBN(rxPCB) == gIsoDep.blockNumber ) { /* Rule B - I-Block with correct block number -> Increase Block number */ rfalIsoDep_ToggleBN( gIsoDep.blockNumber ); - + /* I-Block transaction done successfully */ - + /* remove ISO DEP header, check is necessary to move the INF data on the buffer */ *outActRxLen -= gIsoDep.hdrLen; if( (gIsoDep.hdrLen != gIsoDep.rxBufInfPos) && (*outActRxLen > 0U) ) { RFAL_MEMMOVE( &gIsoDep.rxBuf[gIsoDep.rxBufInfPos], &gIsoDep.rxBuf[gIsoDep.hdrLen], *outActRxLen ); } - + gIsoDep.state = ISODEP_ST_IDLE; rfalIsoDepClearCounters(); return RFAL_ERR_NONE; @@ -1022,13 +1022,13 @@ static ReturnCode rfalIsoDepDataExchangePCD( uint16_t *outActRxLen, bool *outIsC return RFAL_ERR_PROTO; } /* fall through */ - + /*******************************************************************************/ default: /* PRQA S 2003 # MISRA 16.3 - Intentional fall through */ /* MISRA 16.4: no empty default (comment will suffice) */ break; } - + return RFAL_ERR_INTERNAL; } @@ -1037,10 +1037,10 @@ static ReturnCode rfalIsoDepDataExchangePCD( uint16_t *outActRxLen, bool *outIsC ReturnCode rfalIsoDepDeselect( void ) { ReturnCode ret; - + RFAL_EXIT_ON_ERR( ret, rfalIsoDepStartDeselect() ); rfalRunBlocking( ret, rfalIsoDepGetDeselectStatus() ); - + return ret; } @@ -1056,8 +1056,8 @@ ReturnCode rfalIsoDepStartDeselect( void ) gIsoDep.rxBufLen = ISODEP_CONTROLMSG_BUF_LEN - (RFAL_ISODEP_PCB_LEN + RFAL_ISODEP_DID_LEN); gIsoDep.rxBufInfPos = (RFAL_ISODEP_PCB_LEN + RFAL_ISODEP_DID_LEN); gIsoDep.txBufInfPos = (RFAL_ISODEP_PCB_LEN + RFAL_ISODEP_DID_LEN); - - + + /* Send DSL request */ return rfalIsoDepHandleControlMsg( ISODEP_S_DSL, RFAL_ISODEP_NO_PARAM ); } @@ -1070,7 +1070,7 @@ ReturnCode rfalIsoDepGetDeselectStatus( void ) bool dummyB; RFAL_EXIT_ON_BUSY( ret, rfalIsoDepDataExchangePCD( gIsoDep.rxLen, &dummyB ) ); - + rfalIsoDepInitialize(); return ret; } @@ -1083,10 +1083,10 @@ uint32_t rfalIsoDepFWI2FWT( uint8_t fwi ) { uint32_t result; uint8_t tmpFWI; - + tmpFWI = fwi; - - /* RFU values -> take the default value + + /* RFU values -> take the default value * Digital 1.0 11.6.2.17 FWI[1,14] * Digital 1.1 7.6.2.22 FWI[0,14] * EMVCo 2.6 Table A.5 FWI[0,14] */ @@ -1096,10 +1096,10 @@ uint32_t rfalIsoDepFWI2FWT( uint8_t fwi ) } /* FWT = (256 x 16/fC) x 2^FWI => 2^(FWI+12) Digital 1.1 13.8.1 & 7.9.1 */ - + result = ((uint32_t)1U << (tmpFWI + 12U)); result = RFAL_MIN( RFAL_ISODEP_MAX_FWT, result); /* Maximum Frame Waiting Time must be fulfilled */ - + return result; } @@ -1109,10 +1109,10 @@ uint16_t rfalIsoDepFSxI2FSx( uint8_t FSxI ) { uint16_t fsx; uint8_t fsi; - + /* Enforce maximum FSxI/FSx allowed - NFC Forum and EMVCo differ */ fsi = (( gIsoDep.compMode == RFAL_COMPLIANCE_MODE_EMV ) ? RFAL_MIN( FSxI, RFAL_ISODEP_FSDI_MAX_EMV ) : RFAL_MIN( FSxI, RFAL_ISODEP_FSDI_MAX_NFC )); - + switch( fsi ) { case (uint8_t)RFAL_ISODEP_FSXI_16: fsx = (uint16_t)RFAL_ISODEP_FSX_16; break; @@ -1155,7 +1155,7 @@ bool rfalIsoDepIsAttrib( const uint8_t *buf, uint8_t bufLen ) { if(buf != NULL) { - if ( (RFAL_ISODEP_CMD_ATTRIB == (uint8_t)*buf) && + if ( (RFAL_ISODEP_CMD_ATTRIB == (uint8_t)*buf) && (RFAL_ISODEP_ATTRIB_REQ_MIN_LEN <= bufLen) && ((RFAL_ISODEP_ATTRIB_REQ_MIN_LEN + RFAL_ISODEP_ATTRIB_HLINFO_LEN) >= bufLen) ) { @@ -1173,19 +1173,19 @@ ReturnCode rfalIsoDepListenStartActivation( rfalIsoDepAtsParam *atsParam, const uint8_t *txBuf; uint8_t bufIt; const uint8_t *buffer = buf; - + /*******************************************************************************/ bufIt = 0; txBuf = (uint8_t*)actParam.rxBuf; /* Use the rxBuf as TxBuf as well, the struct enforces a size enough RFAL_MAX( NFCA_ATS_MAX_LEN, NFCB_ATTRIB_RES_MAX_LEN ) */ gIsoDep.txBR = RFAL_BR_106; gIsoDep.rxBR = RFAL_BR_106; - + /* Check for a valid buffer pointer */ if( buffer == NULL ) { return RFAL_ERR_PARAM; } - + /*******************************************************************************/ if( *buffer == RFAL_ISODEP_CMD_RATS ) { @@ -1194,35 +1194,35 @@ ReturnCode rfalIsoDepListenStartActivation( rfalIsoDepAtsParam *atsParam, const { return RFAL_ERR_PARAM; } - + /* If requested copy RATS to device info */ if( actParam.isoDepDev != NULL ) { RFAL_MEMCPY( (uint8_t*)&actParam.isoDepDev->activation.A.Poller.RATS, buffer, sizeof(rfalIsoDepRats) ); /* Copy RATS' CMD + PARAM */ } - - + + /*******************************************************************************/ /* Process RATS */ buffer++; gIsoDep.fsx = rfalIsoDepFSxI2FSx( (((*buffer) & RFAL_ISODEP_RATS_PARAM_FSDI_MASK) >> RFAL_ISODEP_RATS_PARAM_FSDI_SHIFT) ); gIsoDep.did = (*buffer & RFAL_ISODEP_DID_MASK); - - + + /*******************************************************************************/ /* Digital 1.1 13.6.1.8 - DID has to between 0 and 14 */ if( gIsoDep.did > RFAL_ISODEP_DID_MAX ) { return RFAL_ERR_PROTO; } - + /* Check if we are configured to support DID */ if(!atsParam->didSupport) { gIsoDep.did = RFAL_ISODEP_NO_DID; /* Even if requested by PCD to use a certain DID, the ATS setting prevails */ } - + /*******************************************************************************/ /* Check RFAL supported bit rates */ if( ((!RFAL_SUPPORT_BR_CE_A_212) && (((atsParam->ta & RFAL_ISODEP_ATS_TA_DPL_212) != 0U) || ((atsParam->ta & RFAL_ISODEP_ATS_TA_DLP_212) != 0U))) || @@ -1231,40 +1231,40 @@ ReturnCode rfalIsoDepListenStartActivation( rfalIsoDepAtsParam *atsParam, const { return RFAL_ERR_NOTSUPP; } - + /* Enforce proper FWI configuration */ if( atsParam->fwi > ISODEP_FWI_LIS_MAX) { atsParam->fwi = ISODEP_FWI_LIS_MAX; } - + gIsoDep.atsTA = atsParam->ta; gIsoDep.fwt = rfalIsoDepFWI2FWT(atsParam->fwi); gIsoDep.ourFsx = rfalIsoDepFSxI2FSx(atsParam->fsci); - - + + /* Ensure proper/maximum Historical Bytes length */ atsParam->hbLen = RFAL_MIN( RFAL_ISODEP_ATS_HB_MAX_LEN, atsParam->hbLen ); - + /*******************************************************************************/ /* Compute ATS */ - + txBuf[ bufIt++ ] = (RFAL_ISODEP_ATS_HIST_OFFSET + atsParam->hbLen); /* TL */ - txBuf[ bufIt++ ] = ( (RFAL_ISODEP_ATS_T0_TA_PRESENCE_MASK | RFAL_ISODEP_ATS_T0_TB_PRESENCE_MASK | + txBuf[ bufIt++ ] = ( (RFAL_ISODEP_ATS_T0_TA_PRESENCE_MASK | RFAL_ISODEP_ATS_T0_TB_PRESENCE_MASK | RFAL_ISODEP_ATS_T0_TC_PRESENCE_MASK)| atsParam->fsci ); /* T0 */ txBuf[ bufIt++ ] = atsParam->ta; /* TA */ - txBuf[ bufIt++ ] = ( (atsParam->fwi << RFAL_ISODEP_RATS_PARAM_FSDI_SHIFT) | + txBuf[ bufIt++ ] = ( (atsParam->fwi << RFAL_ISODEP_RATS_PARAM_FSDI_SHIFT) | (atsParam->sfgi & RFAL_ISODEP_RATS_PARAM_FSDI_MASK) ); /* TB */ txBuf[ bufIt++ ] = (uint8_t)((atsParam->didSupport) ? RFAL_ISODEP_ATS_TC_DID : 0U); /* TC */ - + if( atsParam->hbLen > 0U ) /* MISRA 21.18 */ { RFAL_MEMCPY( &txBuf[bufIt], atsParam->hb, atsParam->hbLen ); /* T1-Tk */ bufIt += atsParam->hbLen; } - + gIsoDep.state = ISODEP_ST_PICC_ACT_ATS; - + } /*******************************************************************************/ else if( *buffer == RFAL_ISODEP_CMD_ATTRIB ) @@ -1274,7 +1274,7 @@ ReturnCode rfalIsoDepListenStartActivation( rfalIsoDepAtsParam *atsParam, const { return RFAL_ERR_PARAM; } - + /* REMARK: ATTRIB handling */ RFAL_NO_WARNING(attribResParam); RFAL_NO_WARNING(bufLen); @@ -1284,10 +1284,10 @@ ReturnCode rfalIsoDepListenStartActivation( rfalIsoDepAtsParam *atsParam, const { return RFAL_ERR_PARAM; } - + gIsoDep.actvParam = actParam; - - + + /*******************************************************************************/ /* If requested copy to ISO-DEP device info */ if( actParam.isoDepDev != NULL ) @@ -1296,10 +1296,10 @@ ReturnCode rfalIsoDepListenStartActivation( rfalIsoDepAtsParam *atsParam, const actParam.isoDepDev->info.FSx = gIsoDep.fsx; actParam.isoDepDev->info.FWT = gIsoDep.fwt; actParam.isoDepDev->info.dFWT = 0; - actParam.isoDepDev->info.DSI = gIsoDep.txBR; + actParam.isoDepDev->info.DSI_ID = gIsoDep.txBR; actParam.isoDepDev->info.DRI = gIsoDep.rxBR; } - + return rfalTransceiveBlockingTx( txBuf, bufIt, (uint8_t*)actParam.rxBuf, sizeof( rfalIsoDepBufFormat ), actParam.rxLen, RFAL_TXRX_FLAGS_DEFAULT, RFAL_FWT_NONE ); } @@ -1310,24 +1310,24 @@ ReturnCode rfalIsoDepListenGetActivationStatus( void ) ReturnCode err; uint8_t* txBuf; uint8_t bufIt; - + rfalBitRate dsi; rfalBitRate dri; - - + + /* Check if Activation is running */ if( gIsoDep.state < ISODEP_ST_PICC_ACT_ATS ) { return RFAL_ERR_WRONG_STATE; } - + /* Check if Activation has finished already */ if( gIsoDep.state >= ISODEP_ST_PICC_RX ) { return RFAL_ERR_NONE; } - - + + /*******************************************************************************/ /* Check for incoming msg */ err = rfalGetTransceiveStatus(); @@ -1336,18 +1336,18 @@ ReturnCode rfalIsoDepListenGetActivationStatus( void ) /*******************************************************************************/ case RFAL_ERR_NONE: break; - + /*******************************************************************************/ case RFAL_ERR_LINK_LOSS: case RFAL_ERR_BUSY: case RFAL_ERR_SLEEP_REQ: /* S(DSL) handled by lower layer should cause an error reported */ return err; - + /*******************************************************************************/ case RFAL_ERR_CRC: case RFAL_ERR_PAR: case RFAL_ERR_FRAMING: - + /* ISO14443 4 5.6.2.2 2 If ATS has been replied upon a invalid block, PICC disables the PPS responses */ if( gIsoDep.state == ISODEP_ST_PICC_ACT_ATS ) { @@ -1355,25 +1355,25 @@ ReturnCode rfalIsoDepListenGetActivationStatus( void ) break; } /* fall through */ - + /*******************************************************************************/ default: /* PRQA S 2003 # MISRA 16.3 - Intentional fall through */ /* ReEnable the receiver and wait for another frame */ rfalIsoDepReEnableRx( (uint8_t*)gIsoDep.actvParam.rxBuf, sizeof( rfalIsoDepBufFormat ), gIsoDep.actvParam.rxLen ); - + return RFAL_ERR_BUSY; } - - - txBuf = (uint8_t*)gIsoDep.actvParam.rxBuf; /* Use the rxBuf as TxBuf as well, the struct enforces a size enough RFAL_MAX(NFCA_PPS_RES_LEN, ISODEP_DSL_MAX_LEN) */ + + + txBuf = (uint8_t*)gIsoDep.actvParam.rxBuf; /* Use the rxBuf as TxBuf as well, the struct enforces a size enough RFAL_MAX(NFCA_PPS_RES_LEN, ISODEP_DSL_MAX_LEN) */ dri = RFAL_BR_KEEP; /* The RFAL_BR_KEEP is used to check if PPS with BR change was requested */ dsi = RFAL_BR_KEEP; /* MISRA 9.1 */ bufIt = 0; - - + + /*******************************************************************************/ gIsoDep.role = ISODEP_ROLE_PICC; - + /*******************************************************************************/ if( gIsoDep.state == ISODEP_ST_PICC_ACT_ATS ) { @@ -1387,10 +1387,10 @@ ReturnCode rfalIsoDepListenGetActivationStatus( void ) { /* Invalid DID on PPS request or Invalid PPS0, reEnable the receiver and wait another frame */ rfalIsoDepReEnableRx( (uint8_t*)gIsoDep.actvParam.rxBuf, sizeof( rfalIsoDepBufFormat ), gIsoDep.actvParam.rxLen ); - + return RFAL_ERR_BUSY; } - + /*******************************************************************************/ /* Check PPS1 presence */ if( ((uint8_t*)gIsoDep.actvParam.rxBuf)[RFAL_ISODEP_PPS_PPS0_POS] == RFAL_ISODEP_PPS0_PPS1_PRESENT ) @@ -1398,9 +1398,9 @@ ReturnCode rfalIsoDepListenGetActivationStatus( void ) uint8_t newdri = ((uint8_t*)gIsoDep.actvParam.rxBuf)[RFAL_ISODEP_PPS_PPS1_POS] & RFAL_ISODEP_PPS1_DxI_MASK; /* MISRA 10.8 */ uint8_t newdsi = (((uint8_t*)gIsoDep.actvParam.rxBuf)[RFAL_ISODEP_PPS_PPS1_POS] >> RFAL_ISODEP_PPS1_DSI_SHIFT) & RFAL_ISODEP_PPS1_DxI_MASK; /* MISRA 10.8 */ /* PRQA S 4342 2 # MISRA 10.5 - Layout of enum rfalBitRate and above masks guarantee no invalid enum values to be created */ - dri = (rfalBitRate) (newdri); + dri = (rfalBitRate) (newdri); dsi = (rfalBitRate) (newdsi); - + if( ((!(RFAL_SUPPORT_BR_CE_A_106)) && (( dsi == RFAL_BR_106 ) || ( dri == RFAL_BR_106 ))) || ((!(RFAL_SUPPORT_BR_CE_A_212)) && (( dsi == RFAL_BR_212 ) || ( dri == RFAL_BR_212 ))) || ((!(RFAL_SUPPORT_BR_CE_A_424)) && (( dsi == RFAL_BR_424 ) || ( dri == RFAL_BR_424 ))) || @@ -1409,11 +1409,11 @@ ReturnCode rfalIsoDepListenGetActivationStatus( void ) return RFAL_ERR_PROTO; } } - + /*******************************************************************************/ /* Compute and send PPS RES / Ack */ txBuf[ bufIt++ ] = ((uint8_t*)gIsoDep.actvParam.rxBuf)[RFAL_ISODEP_PPS_STARTBYTE_POS]; - + rfalTransceiveBlockingTx( txBuf, bufIt, (uint8_t*)gIsoDep.actvParam.rxBuf, sizeof( rfalIsoDepBufFormat ), gIsoDep.actvParam.rxLen, RFAL_TXRX_FLAGS_DEFAULT, RFAL_FWT_NONE ); /*******************************************************************************/ @@ -1421,37 +1421,37 @@ ReturnCode rfalIsoDepListenGetActivationStatus( void ) if( dri != RFAL_BR_KEEP ) { rfalSetBitRate( dsi, dri ); - - gIsoDep.txBR = dsi; /* DSI codes the divisor from PICC to PCD */ + + gIsoDep.txBR = dsi; /* DSI_ID codes the divisor from PICC to PCD */ gIsoDep.rxBR = dri; /* DRI codes the divisor from PCD to PICC */ - - + + if(gIsoDep.actvParam.isoDepDev != NULL) { - gIsoDep.actvParam.isoDepDev->info.DSI = dsi; + gIsoDep.actvParam.isoDepDev->info.DSI_ID = dsi; gIsoDep.actvParam.isoDepDev->info.DRI = dri; } } } /* Check for a S-Deselect is done on Data Exchange Activity */ } - + /*******************************************************************************/ gIsoDep.hdrLen = RFAL_ISODEP_PCB_LEN; gIsoDep.hdrLen += RFAL_ISODEP_DID_LEN; /* Always assume DID to be aligned with Digital 1.1 15.1.2 and ISO14443 4 5.6.3 #454 */ gIsoDep.hdrLen += (uint8_t)((gIsoDep.nad != RFAL_ISODEP_NO_NAD) ? RFAL_ISODEP_NAD_LEN : 0U); - + /*******************************************************************************/ /* Rule C - The PICC block number shall be initialized to 1 at activation */ gIsoDep.blockNumber = 1; - + /* Activation done, keep the rcvd data in, reMap the activation buffer to the global to be retrieved by the DEP method */ gIsoDep.rxBuf = (uint8_t*)gIsoDep.actvParam.rxBuf; gIsoDep.rxBufLen = sizeof( rfalIsoDepBufFormat ); gIsoDep.rxBufInfPos = (uint8_t)((uint32_t)gIsoDep.actvParam.rxBuf->inf - (uint32_t)gIsoDep.actvParam.rxBuf->prologue); gIsoDep.rxLen = gIsoDep.actvParam.rxLen; gIsoDep.rxChaining = gIsoDep.actvParam.isRxChaining; - + gIsoDep.state = ISODEP_ST_PICC_RX; return RFAL_ERR_NONE; } @@ -1468,7 +1468,7 @@ uint16_t rfalIsoDepGetMaxInfLen( void ) const uint16_t aux = (uint16_t)RFAL_ISODEP_FSX_16; /* MISRA 10.1 */ return (aux - RFAL_ISODEP_PCB_LEN - ISODEP_CRC_LEN); } - + return (gIsoDep.fsx - gIsoDep.hdrLen - ISODEP_CRC_LEN); } @@ -1480,27 +1480,27 @@ ReturnCode rfalIsoDepStartTransceive( rfalIsoDepTxRxParam param ) gIsoDep.txBufInfPos = (uint8_t)((uintptr_t)param.txBuf->inf - (uintptr_t)param.txBuf->prologue); gIsoDep.txBufLen = param.txBufLen; gIsoDep.isTxChaining = param.isTxChaining; - + gIsoDep.rxBuf = param.rxBuf->prologue; gIsoDep.rxBufInfPos = (uint8_t)((uintptr_t)param.rxBuf->inf - (uintptr_t)param.rxBuf->prologue); gIsoDep.rxBufLen = sizeof(rfalIsoDepBufFormat); - + gIsoDep.rxLen = param.rxLen; gIsoDep.rxChaining = param.isRxChaining; - - + + gIsoDep.fwt = param.FWT; gIsoDep.dFwt = param.dFWT; gIsoDep.fsx = param.FSx; gIsoDep.did = param.DID; - + /* Only change the FSx from activation if no to Keep */ gIsoDep.ourFsx = (( param.ourFSx != RFAL_ISODEP_FSX_KEEP ) ? param.ourFSx : gIsoDep.ourFsx); - + /* Clear inner control params for next dataExchange */ gIsoDep.isRxChaining = false; rfalIsoDepClearCounters(); - + if(gIsoDep.role == ISODEP_ROLE_PICC) { if(gIsoDep.txBufLen > 0U) @@ -1517,12 +1517,12 @@ ReturnCode rfalIsoDepStartTransceive( rfalIsoDepTxRxParam param ) gIsoDep.isTxPending = true; } } - + /* Digital 1.1 15.2.5.1 The first block SHALL be sent by the Reader/Writer */ gIsoDep.state = ISODEP_ST_PICC_RX; return RFAL_ERR_NONE; } - + gIsoDep.state = ISODEP_ST_PCD_TX; return RFAL_ERR_NONE; } @@ -1557,60 +1557,60 @@ static ReturnCode rfalIsoDepDataExchangePICC( void ) { uint8_t rxPCB; ReturnCode ret; - + switch( gIsoDep.state ) { /*******************************************************************************/ case ISODEP_ST_IDLE: return RFAL_ERR_NONE; - + /*******************************************************************************/ case ISODEP_ST_PICC_TX: - + ret = rfalIsoDepTx( rfalIsoDep_PCBIBlock( gIsoDep.blockNumber ), gIsoDep.txBuf, &gIsoDep.txBuf[gIsoDep.txBufInfPos], gIsoDep.txBufLen, RFAL_FWT_NONE ); - + /* Clear pending Tx flag */ gIsoDep.isTxPending = false; - + switch( ret ) { case RFAL_ERR_NONE: gIsoDep.state = ISODEP_ST_PICC_RX; return RFAL_ERR_BUSY; - + default: /* MISRA 16.4: no empty default statement (a comment being enough) */ break; } return ret; - - + + /*******************************************************************************/ case ISODEP_ST_PICC_RX: - + ret = rfalGetTransceiveStatus(); switch( ret ) { - /*******************************************************************************/ + /*******************************************************************************/ /* Data rcvd with error or timeout -> mute */ case RFAL_ERR_TIMEOUT: case RFAL_ERR_CRC: case RFAL_ERR_PAR: case RFAL_ERR_FRAMING: - - /* Digital 1.1 - 15.2.6.2 The CE SHALL NOT attempt error recovery and remains in Rx mode upon Transmission or a Protocol Error */ + + /* Digital 1.1 - 15.2.6.2 The CE SHALL NOT attempt error recovery and remains in Rx mode upon Transmission or a Protocol Error */ rfalIsoDepReEnableRx( (uint8_t*)gIsoDep.rxBuf, sizeof( rfalIsoDepBufFormat ), gIsoDep.rxLen ); - + return RFAL_ERR_BUSY; - + /*******************************************************************************/ case RFAL_ERR_LINK_LOSS: return ret; /* Debug purposes */ - + case RFAL_ERR_BUSY: return ret; /* Debug purposes */ - + /*******************************************************************************/ case RFAL_ERR_NONE: *gIsoDep.rxLen = rfalConvBitsToBytes( *gIsoDep.rxLen ); @@ -1622,29 +1622,29 @@ static ReturnCode rfalIsoDepDataExchangePICC( void ) } break; - + /*******************************************************************************/ case ISODEP_ST_PICC_SWTX: - + if( !rfalIsoDepTimerisExpired( gIsoDep.WTXTimer ) ) /* Do nothing until WTX timer has expired */ { return RFAL_ERR_BUSY; } - + /* Set waiting for WTX Ack Flag */ gIsoDep.isWait4WTX = true; - + /* Digital 1.1 15.2.2.9 - Calculate the WTXM such that FWTtemp <= FWTmax */ gIsoDep.lastWTXM = (uint8_t)rfalIsoDep_WTXMListenerMax( gIsoDep.fwt ); RFAL_EXIT_ON_ERR( ret, rfalIsoDepHandleControlMsg( ISODEP_S_WTX, gIsoDep.lastWTXM ) ); - + gIsoDep.state = ISODEP_ST_PICC_RX; /* Go back to Rx to process WTX ack */ return RFAL_ERR_BUSY; - - + + /*******************************************************************************/ case ISODEP_ST_PICC_SDSL: - + if( !rfalIsTransceiveInTx() ) /* Wait until DSL response has been sent */ { rfalIsoDepInitialize(); /* Session finished reInit vars, go back to ISODEP_ST_IDLE */ @@ -1652,40 +1652,40 @@ static ReturnCode rfalIsoDepDataExchangePICC( void ) } return RFAL_ERR_BUSY; - + /*******************************************************************************/ default: return RFAL_ERR_INTERNAL; } - + /* ISO 14443-4 7.5.6.2 CE SHALL NOT attempt error recovery -> clear counters */ rfalIsoDepClearCounters(); - + /*******************************************************************************/ /* No error, process incoming msg */ /*******************************************************************************/ - + /* Grab rcvd PCB */ rxPCB = gIsoDep.rxBuf[ ISODEP_PCB_POS ]; - - + + /*******************************************************************************/ - /* When DID=0 PCD may or may not use DID, therefore check whether current PCD request - * has DID present to be reflected on max INF length #454 */ - + /* When DID=0 PCD may or may not use DID, therefore check whether current PCD request + * has DID present to be reflected on max INF length #454 */ + /* ReCalculate Header Length */ gIsoDep.hdrLen = RFAL_ISODEP_PCB_LEN; gIsoDep.hdrLen += (uint8_t)( (rfalIsoDep_PCBhasDID(rxPCB)) ? RFAL_ISODEP_DID_LEN : 0U ); gIsoDep.hdrLen += (uint8_t)( (rfalIsoDep_PCBhasNAD(rxPCB)) ? RFAL_ISODEP_NAD_LEN : 0U ); - + /* Store whether last PCD block had DID. for PICC special handling of DID = 0 */ if( gIsoDep.did == RFAL_ISODEP_DID_00 ) { gIsoDep.lastDID00 = ( (rfalIsoDep_PCBhasDID(rxPCB)) ? true : false ); } - + /*******************************************************************************/ - /* Check rcvd msg length, cannot be less then the expected header OR * + /* Check rcvd msg length, cannot be less then the expected header OR * * if the rcvd msg exceeds our announced frame size (FSD) */ if( ((*gIsoDep.rxLen) < gIsoDep.hdrLen) || ((*gIsoDep.rxLen) > (gIsoDep.ourFsx - ISODEP_CRC_LEN)) ) { @@ -1702,14 +1702,14 @@ static ReturnCode rfalIsoDepDataExchangePICC( void ) rfalIsoDepReEnableRx( (uint8_t*)gIsoDep.rxBuf, sizeof( rfalIsoDepBufFormat ), gIsoDep.rxLen ); return RFAL_ERR_BUSY; /* Ignore a wrong DID request */ } - + /* If we aren't expecting NAD and it's received */ if( (gIsoDep.nad == RFAL_ISODEP_NO_NAD) && rfalIsoDep_PCBhasNAD(rxPCB) ) { rfalIsoDepReEnableRx( (uint8_t*)gIsoDep.rxBuf, sizeof( rfalIsoDepBufFormat ), gIsoDep.rxLen ); return RFAL_ERR_BUSY; /* Ignore a unexpected NAD request */ } - + /*******************************************************************************/ /* Process S-Block */ /*******************************************************************************/ @@ -1727,38 +1727,38 @@ static ReturnCode rfalIsoDepDataExchangePICC( void ) { /* Clear waiting for RTOX Ack Flag */ gIsoDep.isWait4WTX = false; - + /* Check if a Tx is already pending */ if( gIsoDep.isTxPending ) { - /* Has a pending Tx, go immediately to TX */ + /* Has a pending Tx, go immediately to TX */ gIsoDep.state = ISODEP_ST_PICC_TX; return RFAL_ERR_BUSY; } - + /* Set WTX timer */ rfalIsoDepTimerStart( gIsoDep.WTXTimer, rfalIsoDep_WTXAdjust( (gIsoDep.lastWTXM * rfalConv1fcToMs( gIsoDep.fwt )) ) ); - + gIsoDep.state = ISODEP_ST_PICC_SWTX; return RFAL_ERR_BUSY; } } /* Unexpected/Incorrect S-WTX, fall into reRenable */ } - + /* Check if is a Deselect request */ if( rfalIsoDep_PCBisSDeselect(rxPCB) && ((*gIsoDep.rxLen - gIsoDep.hdrLen) == ISODEP_SDSL_INF_LEN) ) { RFAL_EXIT_ON_ERR( ret, rfalIsoDepHandleControlMsg( ISODEP_S_DSL, RFAL_ISODEP_NO_PARAM ) ); - + /* S-DSL transmission ongoing, wait until complete */ gIsoDep.state = ISODEP_ST_PICC_SDSL; return RFAL_ERR_BUSY; } - + /* Unexpected S-Block, fall into reRenable */ } - + /*******************************************************************************/ /* Process R-Block */ /*******************************************************************************/ @@ -1777,7 +1777,7 @@ static ReturnCode rfalIsoDepDataExchangePICC( void ) { gIsoDep.state = ISODEP_ST_PICC_TX; } - + return RFAL_ERR_BUSY; } else @@ -1788,7 +1788,7 @@ static ReturnCode rfalIsoDepDataExchangePICC( void ) rfalIsoDepReEnableRx( (uint8_t*)gIsoDep.rxBuf, sizeof( rfalIsoDepBufFormat ), gIsoDep.rxLen ); return RFAL_ERR_BUSY; } - + /* Rule E - R(ACK) with not current bn -> toggle bn */ rfalIsoDep_ToggleBN( gIsoDep.blockNumber ); @@ -1797,7 +1797,7 @@ static ReturnCode rfalIsoDepDataExchangePICC( void ) /* Rule 9 - PICC is allowed to send an S(WTX) instead of an I-block or an R(ACK) */ rfalIsoDepTimerStart( gIsoDep.WTXTimer, rfalIsoDep_WTXAdjust( rfalConv1fcToMs( gIsoDep.fwt )) ); gIsoDep.state = ISODEP_ST_PICC_SWTX; - + /* Rule 13 - R(ACK) with not current bn -> continue chaining */ return RFAL_ERR_NONE; /* This block has been transmitted */ } @@ -1815,14 +1815,14 @@ static ReturnCode rfalIsoDepDataExchangePICC( void ) { gIsoDep.state = ISODEP_ST_PICC_TX; } - + return RFAL_ERR_BUSY; } else { /* Rule 12 - R(NAK) with not current bn -> R(ACK) */ RFAL_EXIT_ON_ERR( ret, rfalIsoDepHandleControlMsg( ISODEP_R_ACK, RFAL_ISODEP_NO_PARAM ) ); - + return RFAL_ERR_BUSY; } } @@ -1830,10 +1830,10 @@ static ReturnCode rfalIsoDepDataExchangePICC( void ) { /* MISRA 15.7 - Empty else */ } - + /* Unexpected R-Block, fall into reRenable */ } - + /*******************************************************************************/ /* Process I-Block */ /*******************************************************************************/ @@ -1841,7 +1841,7 @@ static ReturnCode rfalIsoDepDataExchangePICC( void ) { /* Rule D - When an I-block is received, the PICC shall toggle its block number before sending a block */ rfalIsoDep_ToggleBN( gIsoDep.blockNumber ); - + /*******************************************************************************/ /* Check if the block number is the one expected */ /* Check if PCD sent an I-Block instead ACK/NACK when we are chaining */ @@ -1849,62 +1849,62 @@ static ReturnCode rfalIsoDepDataExchangePICC( void ) { /* Remain in the same Block Number */ rfalIsoDep_ToggleBN( gIsoDep.blockNumber ); - - /* ISO 14443-4 7.5.6.2 & Digital 1.1 - 15.2.6.2 The CE SHALL NOT attempt error recovery and remains in Rx mode upon Transmission or a Protocol Error */ + + /* ISO 14443-4 7.5.6.2 & Digital 1.1 - 15.2.6.2 The CE SHALL NOT attempt error recovery and remains in Rx mode upon Transmission or a Protocol Error */ rfalIsoDepReEnableRx( (uint8_t*)gIsoDep.rxBuf, sizeof( rfalIsoDepBufFormat ), gIsoDep.rxLen ); return RFAL_ERR_BUSY; } - + /*******************************************************************************/ /* is PCD performing chaining ? */ if( rfalIsoDep_PCBisChaining(rxPCB) ) { gIsoDep.isRxChaining = true; - *gIsoDep.rxChaining = true; /* Output Parameter*/ - + *gIsoDep.rxChaining = true; /* Output Parameter*/ + RFAL_EXIT_ON_ERR( ret, rfalIsoDepHandleControlMsg( ISODEP_R_ACK, RFAL_ISODEP_NO_PARAM ) ); - + /* Received I-Block with chaining, send current data to DH */ - + /* remove ISO DEP header, check is necessary to move the INF data on the buffer */ *gIsoDep.rxLen -= gIsoDep.hdrLen; if( (gIsoDep.hdrLen != gIsoDep.rxBufInfPos) && (*gIsoDep.rxLen > 0U) ) { RFAL_MEMMOVE( &gIsoDep.rxBuf[gIsoDep.rxBufInfPos], &gIsoDep.rxBuf[gIsoDep.hdrLen], *gIsoDep.rxLen ); } - return RFAL_ERR_AGAIN; /* Send Again signalling to run again, but some chaining data has arrived*/ + return RFAL_ERR_AGAIN; /* Send Again signalling to run again, but some chaining data has arrived*/ } - - + + /*******************************************************************************/ /* PCD is not performing chaining */ gIsoDep.isRxChaining = false; /* clear PCD chaining flag */ *gIsoDep.rxChaining = false; /* Output Parameter */ - + /* remove ISO DEP header, check is necessary to move the INF data on the buffer */ *gIsoDep.rxLen -= gIsoDep.hdrLen; if( (gIsoDep.hdrLen != gIsoDep.rxBufInfPos) && (*gIsoDep.rxLen > 0U) ) { RFAL_MEMMOVE( &gIsoDep.rxBuf[gIsoDep.rxBufInfPos], &gIsoDep.rxBuf[gIsoDep.hdrLen], *gIsoDep.rxLen ); } - - + + /*******************************************************************************/ /* Reception done, send data back and start WTX timer */ rfalIsoDepTimerStart( gIsoDep.WTXTimer, rfalIsoDep_WTXAdjust( rfalConv1fcToMs( gIsoDep.fwt )) ); - + gIsoDep.state = ISODEP_ST_PICC_SWTX; return RFAL_ERR_NONE; - } + } else { /* MISRA 15.7 - Empty else */ } - + /* Unexpected/Unknown Block */ /* ISO 14443-4 7.5.6.2 & Digital 1.1 - 15.2.6.2 The CE SHALL NOT attempt error recovery and remains in Rx mode upon Transmission or a Protocol Error */ rfalIsoDepReEnableRx( (uint8_t*)gIsoDep.rxBuf, sizeof( rfalIsoDepBufFormat ), gIsoDep.rxLen ); - + return RFAL_ERR_BUSY; } #endif /* RFAL_FEATURE_ISO_DEP_LISTEN */ @@ -1918,21 +1918,21 @@ static ReturnCode rfalIsoDepDataExchangePICC( void ) static ReturnCode rfalIsoDepStartRATS( rfalIsoDepFSxI FSDI, uint8_t DID, rfalIsoDepAts *ats, uint8_t *atsLen ) { rfalTransceiveContext ctx; - + if( ats == NULL) { return RFAL_ERR_PARAM; } - + gIsoDep.rxBuf = (uint8_t*) ats; gIsoDep.rxLen8 = atsLen; gIsoDep.did = DID; - + /*******************************************************************************/ /* Compose RATS */ gIsoDep.actv.ratsReq.CMD = RFAL_ISODEP_CMD_RATS; gIsoDep.actv.ratsReq.PARAM = (((uint8_t)FSDI << RFAL_ISODEP_RATS_PARAM_FSDI_SHIFT) & RFAL_ISODEP_RATS_PARAM_FSDI_MASK) | (DID & RFAL_ISODEP_RATS_PARAM_DID_MASK); - + rfalCreateByteFlagsTxRxContext( ctx, (uint8_t*)&gIsoDep.actv.ratsReq, sizeof(rfalIsoDepRats), (uint8_t*)ats, sizeof(rfalIsoDepAts), &gIsoDep.rxBufLen, RFAL_TXRX_FLAGS_DEFAULT, RFAL_ISODEP_T4T_FWT_ACTIVATION ); return rfalStartTransceive( &ctx ); } @@ -1942,28 +1942,28 @@ static ReturnCode rfalIsoDepStartRATS( rfalIsoDepFSxI FSDI, uint8_t DID, rfalIso static ReturnCode rfalIsoDepGetRATSStatus( void ) { ReturnCode ret; - + ret = rfalGetTransceiveStatus(); if( ret == RFAL_ERR_NONE ) { gIsoDep.rxBufLen = rfalConvBitsToBytes(gIsoDep.rxBufLen); - + /* Check for valid ATS length Digital 1.1 13.6.2.1 & 13.6.2.3 */ if( (gIsoDep.rxBufLen < RFAL_ISODEP_ATS_MIN_LEN) || (gIsoDep.rxBufLen > RFAL_ISODEP_ATS_MAX_LEN) || ( gIsoDep.rxBuf[RFAL_ISODEP_ATS_TL_POS] != gIsoDep.rxBufLen) ) { return RFAL_ERR_PROTO; } - + /* Assign our FSx, in case the a Deselect is send without Transceive */ gIsoDep.ourFsx = rfalIsoDepFSxI2FSx( (uint8_t) (gIsoDep.actv.ratsReq.PARAM >> RFAL_ISODEP_RATS_PARAM_FSDI_SHIFT) ); - + /* Check and assign if ATS length was requested (length also available on TL) */ if( gIsoDep.rxLen8 != NULL ) { *gIsoDep.rxLen8 = (uint8_t)gIsoDep.rxBufLen; } } - + return ret; } @@ -1972,32 +1972,32 @@ static ReturnCode rfalIsoDepGetRATSStatus( void ) ReturnCode rfalIsoDepRATS( rfalIsoDepFSxI FSDI, uint8_t DID, rfalIsoDepAts *ats , uint8_t *atsLen) { ReturnCode ret; - + RFAL_EXIT_ON_ERR( ret, rfalIsoDepStartRATS(FSDI, DID, ats, atsLen) ); rfalRunBlocking( ret, rfalIsoDepGetRATSStatus() ); - + return ret; } /*******************************************************************************/ -static ReturnCode rfalIsoDepStartPPS( uint8_t DID, rfalBitRate DSI, rfalBitRate DRI, rfalIsoDepPpsRes *ppsRes ) +static ReturnCode rfalIsoDepStartPPS( uint8_t DID, rfalBitRate DSI_ID, rfalBitRate DRI, rfalIsoDepPpsRes *ppsRes ) { rfalTransceiveContext ctx; - - if( (ppsRes == NULL) || (DSI > RFAL_BR_848) || (DRI > RFAL_BR_848) || ((DID > RFAL_ISODEP_DID_MAX) && (DID != RFAL_ISODEP_NO_DID)) ) + + if( (ppsRes == NULL) || (DSI_ID > RFAL_BR_848) || (DRI > RFAL_BR_848) || ((DID > RFAL_ISODEP_DID_MAX) && (DID != RFAL_ISODEP_NO_DID)) ) { return RFAL_ERR_PARAM; } - + gIsoDep.rxBuf = (uint8_t*) ppsRes; - + /*******************************************************************************/ /* Compose PPS Request */ gIsoDep.actv.ppsReq.PPSS = (RFAL_ISODEP_PPS_SB | (DID & RFAL_ISODEP_PPS_SB_DID_MASK)); gIsoDep.actv.ppsReq.PPS0 = RFAL_ISODEP_PPS_PPS0_PPS1_PRESENT; - gIsoDep.actv.ppsReq.PPS1 = (RFAL_ISODEP_PPS_PPS1 | ((((uint8_t)DSI< RFAL_BR_848) || (DRI > RFAL_BR_848) || ((DID > RFAL_ISODEP_DID_MAX) && (DID != RFAL_ISODEP_NO_DID)) ) + + if( (attribRes == NULL) || (attribResLen == NULL) || (DSI_ID > RFAL_BR_848) || (DRI > RFAL_BR_848) || ((DID > RFAL_ISODEP_DID_MAX) && (DID != RFAL_ISODEP_NO_DID)) ) { return RFAL_ERR_NONE; } - + gIsoDep.rxBuf = (uint8_t*) attribRes; gIsoDep.rxLen8 = attribResLen; gIsoDep.did = DID; - + /*******************************************************************************/ /* Compose ATTRIB command */ gIsoDep.actv.attribReq.cmd = RFAL_ISODEP_CMD_ATTRIB; gIsoDep.actv.attribReq.Param.PARAM1 = PARAM1; - gIsoDep.actv.attribReq.Param.PARAM2 = ( ((((uint8_t)DSI< 0U) ) { RFAL_MEMCPY(gIsoDep.actv.attribReq.HLInfo, HLInfo, RFAL_MIN(HLInfoLen, RFAL_ISODEP_ATTRIB_HLINFO_LEN) ); } - + rfalCreateByteFlagsTxRxContext( ctx, (uint8_t*)&gIsoDep.actv.attribReq, (uint16_t)(RFAL_ISODEP_ATTRIB_HDR_LEN + RFAL_MIN((uint16_t)HLInfoLen, RFAL_ISODEP_ATTRIB_HLINFO_LEN)), (uint8_t*)gIsoDep.rxBuf, sizeof(rfalIsoDepAttribRes), &gIsoDep.rxBufLen, RFAL_TXRX_FLAGS_DEFAULT, fwt ); return rfalStartTransceive( &ctx ); } @@ -2076,38 +2076,38 @@ static ReturnCode rfalIsoDepStartATTRIB( const uint8_t* nfcid0, uint8_t PARAM1, static ReturnCode rfalIsoDepGetATTRIBStatus( void ) { ReturnCode ret; - + ret = rfalGetTransceiveStatus(); if( ret == RFAL_ERR_NONE ) { gIsoDep.rxBufLen = rfalConvBitsToBytes(gIsoDep.rxBufLen); - + /* Check for valid ATTRIB Response Digital 2.3 15.6.2.1 */ if( (gIsoDep.rxBufLen < RFAL_ISODEP_ATTRIB_RES_HDR_LEN) ) { return RFAL_ERR_PROTO; } - + if( gIsoDep.rxLen8 != NULL ) { *gIsoDep.rxLen8 = (uint8_t)gIsoDep.rxBufLen; } - + gIsoDep.ourFsx = rfalIsoDepFSxI2FSx( (uint8_t)(gIsoDep.actv.attribReq.Param.PARAM2 & RFAL_ISODEP_ATTRIB_PARAM2_FSDI_MASK) ); } - + return ret; } /*******************************************************************************/ -ReturnCode rfalIsoDepATTRIB( const uint8_t* nfcid0, uint8_t PARAM1, rfalBitRate DSI, rfalBitRate DRI, rfalIsoDepFSxI FSDI, uint8_t PARAM3, uint8_t DID, const uint8_t* HLInfo, uint8_t HLInfoLen, uint32_t fwt, rfalIsoDepAttribRes *attribRes, uint8_t *attribResLen ) +ReturnCode rfalIsoDepATTRIB( const uint8_t* nfcid0, uint8_t PARAM1, rfalBitRate DSI_ID, rfalBitRate DRI, rfalIsoDepFSxI FSDI, uint8_t PARAM3, uint8_t DID, const uint8_t* HLInfo, uint8_t HLInfoLen, uint32_t fwt, rfalIsoDepAttribRes *attribRes, uint8_t *attribResLen ) { ReturnCode ret; - - RFAL_EXIT_ON_ERR( ret, rfalIsoDepStartATTRIB( nfcid0, PARAM1, DSI, DRI, FSDI, PARAM3, DID, HLInfo, HLInfoLen, fwt, attribRes, attribResLen ) ); + + RFAL_EXIT_ON_ERR( ret, rfalIsoDepStartATTRIB( nfcid0, PARAM1, DSI_ID, DRI, FSDI, PARAM3, DID, HLInfo, HLInfoLen, fwt, attribRes, attribResLen ) ); rfalRunBlocking( ret, rfalIsoDepGetATTRIBStatus() ); - + return ret; } @@ -2120,10 +2120,10 @@ ReturnCode rfalIsoDepATTRIB( const uint8_t* nfcid0, uint8_t PARAM1, rfalBitRate ReturnCode rfalIsoDepPollAHandleActivation( rfalIsoDepFSxI FSDI, uint8_t DID, rfalBitRate maxBR, rfalIsoDepDevice *rfalIsoDepDev ) { ReturnCode ret; - + RFAL_EXIT_ON_ERR( ret, rfalIsoDepPollAStartActivation( FSDI, DID, maxBR, rfalIsoDepDev ) ); rfalRunBlocking( ret, rfalIsoDepPollAGetActivationStatus() ); - + return ret; } @@ -2132,23 +2132,23 @@ ReturnCode rfalIsoDepPollAHandleActivation( rfalIsoDepFSxI FSDI, uint8_t DID, rf ReturnCode rfalIsoDepPollAStartActivation( rfalIsoDepFSxI FSDI, uint8_t DID, rfalBitRate maxBR, rfalIsoDepDevice *rfalIsoDepDev ) { ReturnCode ret; - + if( rfalIsoDepDev == NULL ) { return RFAL_ERR_PARAM; } - + /* Enable EMD suppresssion|handling according to Digital 2.1 4.1.1.1 ; EMVCo 3.0 4.9.2 ; ISO 14443-3 8.3 */ rfalSetErrorHandling( RFAL_ERRORHANDLING_EMD ); - + /* Start RATS Transceive */ RFAL_EXIT_ON_ERR( ret, rfalIsoDepStartRATS( FSDI, DID, &rfalIsoDepDev->activation.A.Listener.ATS, &rfalIsoDepDev->activation.A.Listener.ATSLen ) ); - - rfalIsoDepDev->info.DSI = maxBR; + + rfalIsoDepDev->info.DSI_ID = maxBR; gIsoDep.actvDev = rfalIsoDepDev; gIsoDep.cntRRetrys = gIsoDep.maxRetriesRATS; gIsoDep.state = ISODEP_ST_PCD_ACT_RATS; - + return ret; } @@ -2164,7 +2164,7 @@ ReturnCode rfalIsoDepPollAGetActivationStatus( void ) { /*******************************************************************************/ case ISODEP_ST_PCD_ACT_RATS: - + ret = rfalIsoDepGetRATSStatus(); if( ret != RFAL_ERR_BUSY ) { @@ -2175,17 +2175,17 @@ ReturnCode rfalIsoDepPollAGetActivationStatus( void ) { break; } - + if( gIsoDep.cntRRetrys != 0U ) { /* Ensure FDT before retransmission (reuse RFAL GT timer) */ rfalSetGT( rfalGetFDTPoll() ); rfalFieldOnAndStartGT(); - + /* Send RATS retransmission */ /* PRQA S 4342 1 # MISRA 10.5 - Layout of enum rfalIsoDepFSxI is guaranteed whithin 4bit range */ - RFAL_EXIT_ON_ERR( ret, rfalIsoDepStartRATS( (rfalIsoDepFSxI)(uint8_t)(gIsoDep.actv.ratsReq.PARAM >> RFAL_ISODEP_RATS_PARAM_FSDI_SHIFT), + RFAL_EXIT_ON_ERR( ret, rfalIsoDepStartRATS( (rfalIsoDepFSxI)(uint8_t)(gIsoDep.actv.ratsReq.PARAM >> RFAL_ISODEP_RATS_PARAM_FSDI_SHIFT), gIsoDep.did, - &gIsoDep.actvDev->activation.A.Listener.ATS, + &gIsoDep.actvDev->activation.A.Listener.ATS, &gIsoDep.actvDev->activation.A.Listener.ATSLen ) ); gIsoDep.cntRRetrys--; ret = RFAL_ERR_BUSY; @@ -2196,7 +2196,7 @@ ReturnCode rfalIsoDepPollAGetActivationStatus( void ) else if( gIsoDep.compMode == RFAL_COMPLIANCE_MODE_ISO ) { RFAL_EXIT_ON_ERR( ret, rfalIsoDepStartDeselect() ); - + /* State ISODEP_ST_PCD_WAIT_DSL already set by rfalIsoDepHandleControlMsg DSL */ return RFAL_ERR_BUSY; } @@ -2207,36 +2207,36 @@ ReturnCode rfalIsoDepPollAGetActivationStatus( void ) } else /* ATS received */ { - maxBR = gIsoDep.actvDev->info.DSI; /* Retrieve requested max bitrate */ - + maxBR = gIsoDep.actvDev->info.DSI_ID; /* Retrieve requested max bitrate */ + /*******************************************************************************/ /* Process ATS Response */ gIsoDep.actvDev->info.FWI = RFAL_ISODEP_FWI_DEFAULT; /* Default value EMVCo 2.6 5.7.2.6 */ gIsoDep.actvDev->info.SFGI = 0U; gIsoDep.actvDev->info.MBL = 0U; - gIsoDep.actvDev->info.DSI = RFAL_BR_106; + gIsoDep.actvDev->info.DSI_ID = RFAL_BR_106; gIsoDep.actvDev->info.DRI = RFAL_BR_106; gIsoDep.actvDev->info.FSxI = (uint8_t)RFAL_ISODEP_FSXI_32; /* FSC default value is 32 bytes ISO14443-A 5.2.3 */ - - + + /*******************************************************************************/ /* Check for ATS optional fields */ if( gIsoDep.actvDev->activation.A.Listener.ATS.TL > RFAL_ISODEP_ATS_MIN_LEN ) { msgIt = RFAL_ISODEP_ATS_MIN_LEN; - + /* Format byte T0 is optional, if present assign FSDI */ gIsoDep.actvDev->info.FSxI = (gIsoDep.actvDev->activation.A.Listener.ATS.T0 & RFAL_ISODEP_ATS_T0_FSCI_MASK); - + /* T0 has already been processed, always the same position */ - msgIt++; - + msgIt++; + /* Check if TA is present */ if( (gIsoDep.actvDev->activation.A.Listener.ATS.T0 & RFAL_ISODEP_ATS_T0_TA_PRESENCE_MASK) != 0U ) { - rfalIsoDepCalcBitRate( maxBR, ((uint8_t*)&gIsoDep.actvDev->activation.A.Listener.ATS)[msgIt++], &gIsoDep.actvDev->info.DSI, &gIsoDep.actvDev->info.DRI ); + rfalIsoDepCalcBitRate( maxBR, ((uint8_t*)&gIsoDep.actvDev->activation.A.Listener.ATS)[msgIt++], &gIsoDep.actvDev->info.DSI_ID, &gIsoDep.actvDev->info.DRI ); } - + /* Check if TB is present */ if( (gIsoDep.actvDev->activation.A.Listener.ATS.T0 & RFAL_ISODEP_ATS_T0_TB_PRESENCE_MASK) != 0U ) { @@ -2244,7 +2244,7 @@ ReturnCode rfalIsoDepPollAGetActivationStatus( void ) gIsoDep.actvDev->info.FWI = (uint8_t)((gIsoDep.actvDev->info.SFGI >> RFAL_ISODEP_ATS_TB_FWI_SHIFT) & RFAL_ISODEP_ATS_FWI_MASK); gIsoDep.actvDev->info.SFGI &= RFAL_ISODEP_ATS_TB_SFGI_MASK; } - + /* Check if TC is present */ if( (gIsoDep.actvDev->activation.A.Listener.ATS.T0 & RFAL_ISODEP_ATS_T0_TC_PRESENCE_MASK) != 0U ) { @@ -2255,67 +2255,67 @@ ReturnCode rfalIsoDepPollAGetActivationStatus( void ) gIsoDep.actvDev->info.supNAD = (((((uint8_t*)&gIsoDep.actvDev->activation.A.Listener.ATS)[msgIt++] & RFAL_ISODEP_ATS_TC_NAD) != 0U) ? true : false); } } - + gIsoDep.actvDev->info.FSx = rfalIsoDepFSxI2FSx(gIsoDep.actvDev->info.FSxI); gIsoDep.fsx = gIsoDep.actvDev->info.FSx; - + gIsoDep.actvDev->info.SFGT = rfalIsoDepSFGI2SFGT( (uint8_t)gIsoDep.actvDev->info.SFGI ); - + /* Ensure SFGT before following frame (reuse RFAL GT timer) */ rfalSetGT( rfalConvMsTo1fc(gIsoDep.actvDev->info.SFGT) ); rfalFieldOnAndStartGT(); - + gIsoDep.actvDev->info.FWT = rfalIsoDepFWI2FWT( gIsoDep.actvDev->info.FWI ); gIsoDep.actvDev->info.dFWT = RFAL_ISODEP_DFWT_20; - + gIsoDep.actvDev->info.DID = ( (gIsoDep.actvDev->info.supDID) ? gIsoDep.did : RFAL_ISODEP_NO_DID); gIsoDep.actvDev->info.NAD = RFAL_ISODEP_NO_NAD; - - + + /*******************************************************************************/ /* If higher bit rates are supported by both devices, send PPS */ - if( (gIsoDep.actvDev->info.DSI != RFAL_BR_106) || (gIsoDep.actvDev->info.DRI != RFAL_BR_106) ) + if( (gIsoDep.actvDev->info.DSI_ID != RFAL_BR_106) || (gIsoDep.actvDev->info.DRI != RFAL_BR_106) ) { /* Send PPS */ /* PRQA S 0310 1 # MISRA 11.3 - Intentional safe cast to avoiding buffer duplication */ - RFAL_EXIT_ON_ERR( ret, rfalIsoDepStartPPS( gIsoDep.actvDev->info.DID, gIsoDep.actvDev->info.DSI, gIsoDep.actvDev->info.DRI, (rfalIsoDepPpsRes*)&gIsoDep.ctrlBuf )); - + RFAL_EXIT_ON_ERR( ret, rfalIsoDepStartPPS( gIsoDep.actvDev->info.DID, gIsoDep.actvDev->info.DSI_ID, gIsoDep.actvDev->info.DRI, (rfalIsoDepPpsRes*)&gIsoDep.ctrlBuf )); + gIsoDep.state = ISODEP_ST_PCD_ACT_PPS; return RFAL_ERR_BUSY; } - + return RFAL_ERR_NONE; } } break; - + /*******************************************************************************/ case ISODEP_ST_PCD_ACT_PPS: - + ret = rfalIsoDepGetPPSSTatus(); if( ret != RFAL_ERR_BUSY ) { /* Check whether PPS has been acknowledge */ if( ret == RFAL_ERR_NONE ) { - /* DSI code the divisor from PICC to PCD */ + /* DSI_ID code the divisor from PICC to PCD */ /* DRI code the divisor from PCD to PICC */ - rfalSetBitRate( gIsoDep.actvDev->info.DRI, gIsoDep.actvDev->info.DSI ); + rfalSetBitRate( gIsoDep.actvDev->info.DRI, gIsoDep.actvDev->info.DSI_ID ); } else { /* If PPS has faled keep activation bit rate */ - gIsoDep.actvDev->info.DSI = RFAL_BR_106; + gIsoDep.actvDev->info.DSI_ID = RFAL_BR_106; gIsoDep.actvDev->info.DRI = RFAL_BR_106; - + /* Ignore PPS response fail, proceed to data exchange */ ret = RFAL_ERR_NONE; } } break; - + /*******************************************************************************/ case ISODEP_ST_PCD_WAIT_DSL: - + ret = rfalIsoDepGetDeselectStatus(); if( ret != RFAL_ERR_BUSY ) { @@ -2324,12 +2324,12 @@ ReturnCode rfalIsoDepPollAGetActivationStatus( void ) } break; - /*******************************************************************************/ + /*******************************************************************************/ default: ret = RFAL_ERR_WRONG_STATE; break; } - + return ret; } #endif /* RFAL_FEATURE_NFCA */ @@ -2339,12 +2339,12 @@ ReturnCode rfalIsoDepPollAGetActivationStatus( void ) /*******************************************************************************/ ReturnCode rfalIsoDepPollBHandleActivation( rfalIsoDepFSxI FSDI, uint8_t DID, rfalBitRate maxBR, uint8_t PARAM1, const rfalNfcbListenDevice *nfcbDev, const uint8_t* HLInfo, uint8_t HLInfoLen, rfalIsoDepDevice *rfalIsoDepDev ) { - + ReturnCode ret; - + RFAL_EXIT_ON_ERR( ret, rfalIsoDepPollBStartActivation( FSDI, DID, maxBR, PARAM1, nfcbDev, HLInfo, HLInfoLen, rfalIsoDepDev ) ); rfalRunBlocking( ret, rfalIsoDepPollBGetActivationStatus() ); - + return ret; } @@ -2354,7 +2354,7 @@ ReturnCode rfalIsoDepPollBStartActivation( rfalIsoDepFSxI FSDI, uint8_t DID, rfa { ReturnCode ret; uint32_t tr2; - + /***************************************************************************/ /* Initialize ISO-DEP Device with info from SENSB_RES */ rfalIsoDepDev->info.FWI = ((nfcbDev->sensbRes.protInfo.FwiAdcFo >> RFAL_NFCB_SENSB_RES_FWI_SHIFT) & RFAL_NFCB_SENSB_RES_FWI_MASK); @@ -2367,17 +2367,17 @@ ReturnCode rfalIsoDepPollBStartActivation( rfalIsoDepFSxI FSDI, uint8_t DID, rfa rfalIsoDepDev->info.DID = DID; rfalIsoDepDev->info.supDID = ((( nfcbDev->sensbRes.protInfo.FwiAdcFo & RFAL_NFCB_SENSB_RES_FO_DID_MASK ) != 0U) ? true : false); rfalIsoDepDev->info.supNAD = ((( nfcbDev->sensbRes.protInfo.FwiAdcFo & RFAL_NFCB_SENSB_RES_FO_NAD_MASK ) != 0U) ? true : false); - - + + /* Check if DID requested is supported by PICC */ if( (DID != RFAL_ISODEP_NO_DID) && (!rfalIsoDepDev->info.supDID) ) { return RFAL_ERR_PARAM; } - + /* Enable EMD suppresssion|handling according to Digital 2.1 4.1.1.1 ; EMVCo 3.0 4.9.2 ; ISO 14443-3 8.3 */ rfalSetErrorHandling( RFAL_ERRORHANDLING_EMD ); - + /***************************************************************************/ /* Set FDT Poll to be used on upcoming communications */ if( gIsoDep.compMode == RFAL_COMPLIANCE_MODE_EMV ) @@ -2393,20 +2393,20 @@ ReturnCode rfalIsoDepPollBStartActivation( rfalIsoDepFSxI FSDI, uint8_t DID, rfa /* In case TR2 is longer than the one currently running, ensure it's fulfilled (max: 9472/fc => 700us) */ platformDelay( 1 ); } - + /* Apply minimum TR2 from SENSB_RES Digital 2.1 7.6.2.23 */ rfalSetFDTPoll( tr2 ); } - - + + /* Calculate max Bit Rate */ - rfalIsoDepCalcBitRate( maxBR, nfcbDev->sensbRes.protInfo.BRC, &rfalIsoDepDev->info.DSI, &rfalIsoDepDev->info.DRI ); - + rfalIsoDepCalcBitRate( maxBR, nfcbDev->sensbRes.protInfo.BRC, &rfalIsoDepDev->info.DSI_ID, &rfalIsoDepDev->info.DRI ); + /***************************************************************************/ /* Send ATTRIB Command */ RFAL_EXIT_ON_ERR( ret, rfalIsoDepStartATTRIB( (const uint8_t*)&nfcbDev->sensbRes.nfcid0, (((nfcbDev->sensbRes.protInfo.FwiAdcFo & RFAL_NFCB_SENSB_RES_ADC_ADV_FEATURE_MASK) != 0U) ? PARAM1 : RFAL_ISODEP_ATTRIB_REQ_PARAM1_DEFAULT), - rfalIsoDepDev->info.DSI, + rfalIsoDepDev->info.DSI_ID, rfalIsoDepDev->info.DRI, FSDI, (gIsoDep.compMode == RFAL_COMPLIANCE_MODE_EMV) ? RFAL_NFCB_SENSB_RES_PROTO_ISO_MASK : (nfcbDev->sensbRes.protInfo.FsciProType & ( (RFAL_NFCB_SENSB_RES_PROTO_TR2_MASK<activation.B.Listener.ATTRIB_RES, &rfalIsoDepDev->activation.B.Listener.ATTRIB_RESLen ) ); - - + + gIsoDep.actvDev = rfalIsoDepDev; return ret; } @@ -2443,7 +2443,7 @@ ReturnCode rfalIsoDepPollBGetActivationStatus( void ) { return RFAL_ERR_PROTO; } - + /* Retrieve MBLI and calculate new FDS/MBL (Maximum Buffer Length) */ mbli = ((gIsoDep.actvDev->activation.B.Listener.ATTRIB_RES.mbliDid >> RFAL_ISODEP_ATTRIB_RES_MBLI_SHIFT) & RFAL_ISODEP_ATTRIB_RES_MBLI_MASK); if( mbli > 0U) @@ -2451,30 +2451,30 @@ ReturnCode rfalIsoDepPollBGetActivationStatus( void ) /* Digital 1.1 14.6.2 Calculate Maximum Buffer Length MBL = FSC x 2^(MBLI-1) */ gIsoDep.actvDev->info.MBL = (gIsoDep.actvDev->info.FSx * ((uint32_t)1U<<(mbli-1U))); } - - /* DSI code the divisor from PICC to PCD */ + + /* DSI_ID code the divisor from PICC to PCD */ /* DRI code the divisor from PCD to PICC */ - rfalSetBitRate( gIsoDep.actvDev->info.DRI, gIsoDep.actvDev->info.DSI ); - - + rfalSetBitRate( gIsoDep.actvDev->info.DRI, gIsoDep.actvDev->info.DSI_ID ); + + /* REMARK: SoF EoF TR0 and TR1 are not passed on to RF layer */ - - + + /* Start the SFGT timer (reuse RFAL GT timer) */ rfalSetGT( rfalConvMsTo1fc(gIsoDep.actvDev->info.SFGT) ); rfalFieldOnAndStartGT(); } else { - gIsoDep.actvDev->info.DSI = RFAL_BR_106; + gIsoDep.actvDev->info.DSI_ID = RFAL_BR_106; gIsoDep.actvDev->info.DRI = RFAL_BR_106; } - + /*******************************************************************************/ /* Store already FS info, rfalIsoDepGetMaxInfLen() may be called before setting TxRx params */ gIsoDep.fsx = gIsoDep.actvDev->info.FSx; } - + return ret; } @@ -2488,47 +2488,47 @@ ReturnCode rfalIsoDepPollHandleSParameters( rfalIsoDepDevice *rfalIsoDepDev, rfa uint8_t supPCD2PICC; uint8_t supPICC2PCD; uint8_t currenttxBR; - uint8_t currentrxBR; + uint8_t currentrxBR; rfalBitRate txBR; rfalBitRate rxBR; uint16_t rcvLen; ReturnCode ret; rfalIsoDepControlMsgSParam sParam; - - + + if( (rfalIsoDepDev == NULL) || (maxTxBR > RFAL_BR_13560) || (maxRxBR > RFAL_BR_13560) ) { return RFAL_ERR_PARAM; } - + it = 0; supPICC2PCD = 0x00; supPCD2PICC = 0x00; txBR = RFAL_BR_106; rxBR = RFAL_BR_106; sParam.pcb = ISODEP_PCB_SPARAMETERS; - + /*******************************************************************************/ /* Send S(PARAMETERS) - Block Info */ sParam.sParam.tag = RFAL_ISODEP_SPARAM_TAG_BLOCKINFO; sParam.sParam.value[it++] = RFAL_ISODEP_SPARAM_TAG_BRREQ; sParam.sParam.value[it++] = RFAL_ISODEP_SPARAM_TAG_BRREQ_LEN; sParam.sParam.length = it; - + /* Send S(PARAMETERS). Use a fixed FWI of 4 ISO14443-4 2016 7.2 */ RFAL_EXIT_ON_ERR( ret, rfalTransceiveBlockingTxRx( (uint8_t*)&sParam, (RFAL_ISODEP_SPARAM_HDR_LEN + (uint16_t)it), (uint8_t*)&sParam, sizeof(rfalIsoDepControlMsgSParam), &rcvLen, RFAL_TXRX_FLAGS_DEFAULT, ISODEP_FWT_DEACTIVATION )); - + it = 0; - + /*******************************************************************************/ /* Check S(PARAMETERS) response */ - if( (sParam.pcb != ISODEP_PCB_SPARAMETERS) || (sParam.sParam.tag != RFAL_ISODEP_SPARAM_TAG_BLOCKINFO) || - (sParam.sParam.value[it] != RFAL_ISODEP_SPARAM_TAG_BRIND) || (rcvLen < RFAL_ISODEP_SPARAM_HDR_LEN) || + if( (sParam.pcb != ISODEP_PCB_SPARAMETERS) || (sParam.sParam.tag != RFAL_ISODEP_SPARAM_TAG_BLOCKINFO) || + (sParam.sParam.value[it] != RFAL_ISODEP_SPARAM_TAG_BRIND) || (rcvLen < RFAL_ISODEP_SPARAM_HDR_LEN) || (rcvLen != ((uint16_t)sParam.sParam.length + RFAL_ISODEP_SPARAM_HDR_LEN)) ) { return RFAL_ERR_PROTO; } - + /* Retrieve PICC's bit rate PICC capabilities */ for( it=0; it<(rcvLen-(uint16_t)RFAL_ISODEP_SPARAM_TAG_LEN); it++ ) { @@ -2536,20 +2536,20 @@ ReturnCode rfalIsoDepPollHandleSParameters( rfalIsoDepDevice *rfalIsoDepDev, rfa { supPCD2PICC = sParam.sParam.value[it + RFAL_ISODEP_SPARAM_TAG_PCD2PICC_LEN]; } - + if( (sParam.sParam.value[it] == RFAL_ISODEP_SPARAM_TAG_SUP_PICC2PCD) && (sParam.sParam.value[it+(uint16_t)RFAL_ISODEP_SPARAM_TAG_LEN] == RFAL_ISODEP_SPARAM_TAG_PICC2PCD_LEN) ) { supPICC2PCD = sParam.sParam.value[it + RFAL_ISODEP_SPARAM_TAG_PICC2PCD_LEN]; } } - + /*******************************************************************************/ /* Check if requested bit rates are supported by PICC */ if( (supPICC2PCD == 0x00U) || (supPCD2PICC == 0x00U) ) { return RFAL_ERR_PROTO; } - + for( it=0; it<=(uint8_t)maxTxBR; it++ ) { if( (supPCD2PICC & (0x01U << it)) != 0U ) @@ -2564,11 +2564,11 @@ ReturnCode rfalIsoDepPollHandleSParameters( rfalIsoDepDevice *rfalIsoDepDev, rfa rxBR = (rfalBitRate)it; /* PRQA S 4342 # MISRA 10.5 - Layout of enum rfalBitRate and above clamping of maxTxBR guarantee no invalid enum values to be created */ } } - + it = 0; currenttxBR = (uint8_t)txBR; currentrxBR = (uint8_t)rxBR; - + /*******************************************************************************/ /* Send S(PARAMETERS) - Bit rates Activation */ sParam.sParam.tag = RFAL_ISODEP_SPARAM_TAG_BLOCKINFO; @@ -2583,24 +2583,24 @@ ReturnCode rfalIsoDepPollHandleSParameters( rfalIsoDepDevice *rfalIsoDepDev, rfa sParam.sParam.value[it++] = ((uint8_t)0x01U << currentrxBR); sParam.sParam.value[it++] = 0x00U; sParam.sParam.length = it; - + RFAL_EXIT_ON_ERR( ret, rfalTransceiveBlockingTxRx( (uint8_t*)&sParam, (RFAL_ISODEP_SPARAM_HDR_LEN + (uint16_t)it), (uint8_t*)&sParam, sizeof(rfalIsoDepControlMsgSParam), &rcvLen, RFAL_TXRX_FLAGS_DEFAULT, (rfalIsoDepDev->info.FWT + rfalIsoDepDev->info.dFWT) )); - + it = 0; - + /*******************************************************************************/ /* Check S(PARAMETERS) Acknowledge */ - if( (sParam.pcb != ISODEP_PCB_SPARAMETERS) || (sParam.sParam.tag != RFAL_ISODEP_SPARAM_TAG_BLOCKINFO) || + if( (sParam.pcb != ISODEP_PCB_SPARAMETERS) || (sParam.sParam.tag != RFAL_ISODEP_SPARAM_TAG_BLOCKINFO) || (sParam.sParam.value[it] != RFAL_ISODEP_SPARAM_TAG_BRACK) || (rcvLen < RFAL_ISODEP_SPARAM_HDR_LEN) ) { return RFAL_ERR_PROTO; } - + RFAL_EXIT_ON_ERR( ret, rfalSetBitRate( txBR, rxBR ) ); - + rfalIsoDepDev->info.DRI = txBR; - rfalIsoDepDev->info.DSI = rxBR; - + rfalIsoDepDev->info.DSI_ID = rxBR; + return RFAL_ERR_NONE; } @@ -2613,22 +2613,22 @@ static void rfalIsoDepCalcBitRate( rfalBitRate maxAllowedBR, uint8_t piccBRCapab int16_t i; bool bitrateFound; rfalBitRate curMaxBR; - + curMaxBR = maxAllowedBR; - + do { bitrateFound = true; - + (*dsi) = RFAL_BR_106; (*dri) = RFAL_BR_106; - + /* Digital 1.0 5.6.2.5 & 11.6.2.14: A received RFU value of b4 = 1b MUST be interpreted as if b7 to b1 ? 0000000b (only 106 kbits/s in both direction) */ if( ((RFAL_ISODEP_BITRATE_RFU_MASK & piccBRCapability) != 0U) || (curMaxBR > RFAL_BR_848) || (curMaxBR == RFAL_BR_KEEP) ) { return; } - + /***************************************************************************/ /* Determine Listen->Poll bit rate */ dsiMask = (piccBRCapability & RFAL_ISODEP_BSI_MASK); @@ -2641,11 +2641,11 @@ static void rfalIsoDepCalcBitRate( rfalBitRate maxAllowedBR, uint8_t piccBRCapab break; } } - + /***************************************************************************/ - /* Determine Poll->Listen bit rate */ + /* Determine Poll->Listen bit rate */ driMask = (piccBRCapability & RFAL_ISODEP_BRI_MASK); - for( i = 2; i >= 0; i-- ) /* Check supported bit rate from the highest */ + for( i = 2; i >= 0; i-- ) /* Check supported bit rate from the highest */ { if (((driMask & (0x01U << (uint8_t)i)) != 0U) && (((uint8_t)i+1U) <= (uint8_t)curMaxBR)) { @@ -2654,13 +2654,13 @@ static void rfalIsoDepCalcBitRate( rfalBitRate maxAllowedBR, uint8_t piccBRCapab break; } } - + /***************************************************************************/ /* Check if different bit rate is supported */ - + /* Digital 1.0 Table 67: if b8=1b, then only the same bit rate divisor for both directions is supported */ if( (piccBRCapability & RFAL_ISODEP_SAME_BITRATE_MASK) != 0U ) - { + { (*dsi) = RFAL_MIN((*dsi), (*dri)); (*dri) = (*dsi); /* Check that the baudrate is supported */ @@ -2671,7 +2671,7 @@ static void rfalIsoDepCalcBitRate( rfalBitRate maxAllowedBR, uint8_t piccBRCapab } } } while (!(bitrateFound)); - + } /*******************************************************************************/ @@ -2679,14 +2679,14 @@ static uint32_t rfalIsoDepSFGI2SFGT( uint8_t sfgi ) { uint32_t sfgt; uint8_t tmpSFGI; - + tmpSFGI = sfgi; - + if (tmpSFGI > ISODEP_SFGI_MAX) { tmpSFGI = ISODEP_SFGI_MIN; } - + if (tmpSFGI != ISODEP_SFGI_MIN) { /* If sfgi != 0 wait SFGT + dSFGT Digital 1.1 13.8.2.1 */ @@ -2703,19 +2703,19 @@ static uint32_t rfalIsoDepSFGI2SFGT( uint8_t sfgi ) } #endif /* RFAL_FEATURE_ISO_DEP_POLL */ - + /*******************************************************************************/ static void rfalIsoDepApdu2IBLockParam( rfalIsoDepApduTxRxParam apduParam, rfalIsoDepTxRxParam *iBlockParam, uint16_t txPos, uint16_t rxPos ) { RFAL_NO_WARNING(rxPos); /* Keep this param for future use */ - + iBlockParam->DID = apduParam.DID; iBlockParam->FSx = apduParam.FSx; iBlockParam->ourFSx = apduParam.ourFSx; iBlockParam->FWT = apduParam.FWT; iBlockParam->dFWT = apduParam.dFWT; - + if( (apduParam.txBufLen - txPos) > rfalIsoDepGetMaxInfLen() ) { iBlockParam->isTxChaining = true; @@ -2726,73 +2726,73 @@ static uint32_t rfalIsoDepSFGI2SFGT( uint8_t sfgi ) iBlockParam->isTxChaining = false; iBlockParam->txBufLen = (apduParam.txBufLen - txPos); } - + /* TxBuf is moved to the beginning for every I-Block */ iBlockParam->txBuf = (rfalIsoDepBufFormat*)apduParam.txBuf; /* PRQA S 0310 # MISRA 11.3 - Intentional safe cast to avoiding large buffer duplication */ iBlockParam->rxBuf = apduParam.tmpBuf; /* Simply using the apdu buffer is not possible because of current ACK handling */ iBlockParam->isRxChaining = &gIsoDep.isAPDURxChaining; iBlockParam->rxLen = apduParam.rxLen; } - - + + /*******************************************************************************/ ReturnCode rfalIsoDepStartApduTransceive( rfalIsoDepApduTxRxParam param ) { rfalIsoDepTxRxParam txRxParam; - + /* Initialize and store APDU context */ gIsoDep.APDUParam = param; gIsoDep.APDUTxPos = 0; gIsoDep.APDURxPos = 0; - + /* Assign current FSx to calculate INF length (only change the FSx from activation if no to Keep) */ gIsoDep.ourFsx = (( param.ourFSx != RFAL_ISODEP_FSX_KEEP ) ? param.ourFSx : gIsoDep.ourFsx); gIsoDep.fsx = param.FSx; - + /* Convert APDU TxRxParams to I-Block TxRxParams */ rfalIsoDepApdu2IBLockParam( gIsoDep.APDUParam, &txRxParam, gIsoDep.APDUTxPos, gIsoDep.APDURxPos ); - + return rfalIsoDepStartTransceive( txRxParam ); } - - + + /*******************************************************************************/ ReturnCode rfalIsoDepGetApduTransceiveStatus( void ) { ReturnCode ret; rfalIsoDepTxRxParam txRxParam; - + ret = rfalIsoDepGetTransceiveStatus(); switch( ret ) { /*******************************************************************************/ case RFAL_ERR_NONE: - + /* Check if we are still doing chaining on Tx */ if( gIsoDep.isTxChaining ) { /* Add already Tx bytes */ gIsoDep.APDUTxPos += gIsoDep.txBufLen; - + /* Convert APDU TxRxParams to I-Block TxRxParams */ rfalIsoDepApdu2IBLockParam( gIsoDep.APDUParam, &txRxParam, gIsoDep.APDUTxPos, gIsoDep.APDURxPos ); - + if( txRxParam.txBufLen > 0U ) /* MISRA 21.18 */ { /* Move next I-Block to beginning of APDU Tx buffer */ RFAL_MEMCPY( gIsoDep.APDUParam.txBuf->apdu, &gIsoDep.APDUParam.txBuf->apdu[gIsoDep.APDUTxPos], txRxParam.txBufLen ); } - + RFAL_EXIT_ON_ERR( ret, rfalIsoDepStartTransceive( txRxParam ) ); return RFAL_ERR_BUSY; } - + /* APDU TxRx is done */ /* fall through */ - + /*******************************************************************************/ case RFAL_ERR_AGAIN: /* PRQA S 2003 # MISRA 16.3 - Intentional fall through */ - + /* Check if no APDU transceive has been started before (data from rfalIsoDepListenStartActivation) */ if( gIsoDep.APDUParam.rxLen == NULL ) { @@ -2801,11 +2801,11 @@ ReturnCode rfalIsoDepGetApduTransceiveStatus( void ) /* In Listen mode first chained packet cannot be retrieved via APDU interface */ return RFAL_ERR_NOTSUPP; } - + /* TxRx is complete and full data is already available */ return RFAL_ERR_NONE; } - + if( *gIsoDep.APDUParam.rxLen > 0U ) /* MISRA 21.18 */ { /* Ensure that data in tmpBuf still fits into APDU buffer */ @@ -2813,24 +2813,24 @@ ReturnCode rfalIsoDepGetApduTransceiveStatus( void ) { return RFAL_ERR_NOMEM; } - + /* Copy chained packet from tmp buffer to APDU buffer */ RFAL_MEMCPY( &gIsoDep.APDUParam.rxBuf->apdu[gIsoDep.APDURxPos], gIsoDep.APDUParam.tmpBuf->inf, *gIsoDep.APDUParam.rxLen ); gIsoDep.APDURxPos += *gIsoDep.APDUParam.rxLen; } - + /* Update output param rxLen */ *gIsoDep.APDUParam.rxLen = gIsoDep.APDURxPos; - + /* Wait for following I-Block or APDU TxRx has finished */ return ((ret == RFAL_ERR_AGAIN) ? RFAL_ERR_BUSY : RFAL_ERR_NONE); - + /*******************************************************************************/ default: /* MISRA 16.4: no empty default statement (a comment being enough) */ break; } - + return ret; } diff --git a/core/embed/io/nfc/rfal/source/rfal_nfcDep.c b/core/embed/io/nfc/rfal/source/rfal_nfcDep.c index 0d0398372f..6c605e843f 100644 --- a/core/embed/io/nfc/rfal/source/rfal_nfcDep.c +++ b/core/embed/io/nfc/rfal/source/rfal_nfcDep.c @@ -26,10 +26,10 @@ * \author Gustavo Patricio * * \brief Implementation of NFC-DEP protocol - * - * NFC-DEP is also known as NFCIP - Near Field Communication + * + * NFC-DEP is also known as NFCIP - Near Field Communication * Interface and Protocol - * + * * This implementation was based on the following specs: * - NFC Forum Digital 1.1 * - ECMA 340 3rd Edition 2013 @@ -50,15 +50,15 @@ * ENABLE SWITCH ****************************************************************************** */ - -/* Feature switch may be enabled or disabled by user at rfal_platform.h + +/* Feature switch may be enabled or disabled by user at rfal_platform.h * Default configuration (ST25R dependant) also provided at rfal_defConfig.h - * + * * RFAL_FEATURE_NFC_DEP */ #if RFAL_FEATURE_NFC_DEP - + /* Check for valid Block/Payload length Digital 2.0 Table 90*/ #if( (RFAL_FEATURE_NFC_DEP_BLOCK_MAX_LEN != 64) && (RFAL_FEATURE_NFC_DEP_BLOCK_MAX_LEN != 128) && (RFAL_FEATURE_NFC_DEP_BLOCK_MAX_LEN != 192) && (RFAL_FEATURE_NFC_DEP_BLOCK_MAX_LEN != 254) ) #error " RFAL: Invalid NFC-DEP Block Max length. Please change RFAL_FEATURE_NFC_DEP_BLOCK_MAX_LEN. " @@ -67,7 +67,7 @@ /* Check for valid PDU length */ #if( (RFAL_FEATURE_NFC_DEP_PDU_MAX_LEN < RFAL_FEATURE_NFC_DEP_BLOCK_MAX_LEN) ) #error " RFAL: Invalid NFC-DEP PDU Max length. Please change RFAL_FEATURE_NFC_DEP_PDU_MAX_LEN. " -#endif +#endif /* ****************************************************************************** @@ -105,7 +105,7 @@ #define NFCIP_TARG_MAX_RTOX 59U /*!< Maximum target RTOX value Digital 1.0 14.8.4.1 */ #define NFCIP_TRECOV 1280U /*!< Digital 1.0 A.10 Trecov */ - + #define NFCIP_TIMEOUT_ADJUSTMENT 3072U /*!< Timeout Adjustment to compensate timing from end of Tx to end of frame */ #define NFCIP_RWT_ACTIVATION (0x1000001U + NFCIP_TIMEOUT_ADJUSTMENT) /*!< Digital 2.2 B.11 RWT ACTIVATION 2^24 + RWT Delta + Adjustment*/ #define NFCIP_RWT_ACM_ACTIVATION (0x200001U + NFCIP_TIMEOUT_ADJUSTMENT) /*!< Digital 2.2 B.11 RWT ACTIVATION 2^21 + RWT Delta + Adjustment*/ @@ -115,20 +115,20 @@ #ifndef RFAL_NFCDEP_MAX_TX_RETRYS #define RFAL_NFCDEP_MAX_TX_RETRYS (uint8_t)3U /*!< Number of retransmit retyrs */ #endif /* RFAL_NFCDEP_MAX_TX_RETRYS */ - -#ifndef RFAL_NFCDEP_TO_RETRYS + +#ifndef RFAL_NFCDEP_TO_RETRYS #define RFAL_NFCDEP_TO_RETRYS (uint8_t)3U /*!< Number of retrys for Timeout */ #endif /* RFAL_NFCDEP_TO_RETRYS */ - -#ifndef RFAL_NFCDEP_MAX_RTOX_RETRYS + +#ifndef RFAL_NFCDEP_MAX_RTOX_RETRYS #define RFAL_NFCDEP_MAX_RTOX_RETRYS (uint8_t)10U /*!< Number of retrys for RTOX Digital 2.0 17.12.4.3 */ #endif /* RFAL_NFCDEP_MAX_RTOX_RETRYS */ - -#ifndef RFAL_NFCDEP_MAX_NACK_RETRYS + +#ifndef RFAL_NFCDEP_MAX_NACK_RETRYS #define RFAL_NFCDEP_MAX_NACK_RETRYS (uint8_t)3U /*!< Number of retrys for NACK */ #endif /* RFAL_NFCDEP_MAX_NACK_RETRYS */ - -#ifndef RFAL_NFCDEP_MAX_ATN_RETRYS + +#ifndef RFAL_NFCDEP_MAX_ATN_RETRYS #define RFAL_NFCDEP_MAX_ATN_RETRYS (uint8_t)3U /*!< Number of retrys for ATN */ #endif /* RFAL_NFCDEP_MAX_ATN_RETRYS */ @@ -228,12 +228,12 @@ /*! Checks if isDeactivating callback is set and calls it, otherwise returns false */ #define nfcipIsDeactivationPending() ( (gNfcip.isDeactivating == NULL) ? false : gNfcip.isDeactivating() ) - + /*! Returns the RWT Activation according to the current communication mode */ #define nfcipRWTActivation() ((gNfcip.cfg.commMode == RFAL_NFCDEP_COMM_ACTIVE) ? NFCIP_RWT_ACM_ACTIVATION : NFCIP_RWT_ACTIVATION) -#define nfcipRTOXAdjust( v ) ((v) - ((v)>>3)) /*!< Adjust RTOX timer value to a percentage of the total, current 88% */ +#define nfcipRTOXAdjust( v ) ((v) - ((v)>>3)) /*!< Adjust RTOX timer value to a percentage of the total, current 88% */ /*******************************************************************************/ @@ -260,20 +260,20 @@ /*! Struct that holds all DEP parameters/configs for the following communications */ typedef struct{ uint8_t did; /*!< Device ID (DID) to be used */ - + uint8_t* txBuf; /*!< Pointer to the Tx buffer to be sent */ uint16_t txBufLen; /*!< Length of the data in the txBuf */ uint8_t txBufPaylPos; /*!< Position inside txBuf where data starts */ bool txChaining; /*!< Flag indicating chaining on transmission */ - + uint8_t* rxBuf; /*!< Pointer to the Rx buffer for incoming data */ uint16_t rxBufLen; /*!< Length of the data in the rxBuf */ uint8_t rxBufPaylPos; /*!< Position inside rxBuf where data is to be placed*/ - + uint32_t fwt; /*!< Frame Waiting Time (FWT) to be used */ uint32_t dFwt; /*!< Delta Frame Waiting Time (dFWT) to be used */ uint16_t fsc; /*!< Frame Size (FSC) to be used */ - + } rfalNfcDepDEPParams; /*! NFCIP module states */ @@ -289,7 +289,7 @@ typedef enum NFCIP_ST_INIT_DEP_ATN, NFCIP_ST_INIT_DSL, NFCIP_ST_INIT_RLS, - + NFCIP_ST_TARG_WAIT_ATR, NFCIP_ST_TARG_WAIT_ACTV, NFCIP_ST_TARG_DEP_IDLE, @@ -317,23 +317,23 @@ typedef enum{ /*! Struct that holds all NFCIP data */ -typedef struct{ +typedef struct{ rfalNfcDepConfigs cfg; /*!< Holds the current configuration to be used */ - + rfalNfcDepState state; /*!< Current state of the NFCIP module */ uint8_t pni; /*!< Packet Number Information (PNI) counter */ - + uint8_t lastCmd; /*!< Last command sent */ uint8_t lastPFB; /*!< Last PFB sent */ uint8_t lastPFBnATN; /*!< Last PFB sent (excluding ATN) */ uint8_t lastRTOX; /*!< Last RTOX value sent */ - + uint8_t cntTxRetrys; /*!< Retransmissions counter */ uint8_t cntTORetrys; /*!< Timeouts counter */ uint8_t cntRTOXRetrys; /*!< RTOX counter */ uint8_t cntNACKRetrys; /*!< NACK counter */ uint8_t cntATNRetrys; /*!< Attention (ATN) counter */ - + uint16_t fsc; /*!< Current Frame Size (FSC) to be used */ bool isTxChaining; /*!< Flag for chaining on Transmission */ bool isRxChaining; /*!< Flag for chaining on Reception */ @@ -345,16 +345,16 @@ typedef struct{ uint8_t txBufPaylPos; /*!< Position in txBuf where data starts */ uint8_t rxBufPaylPos; /*!< Position in rxBuf where data is to be placed */ bool *isChaining; /*!< Flag for chaining on Reception */ - + rfalNfcDepDevice *nfcDepDev; /*!< Pointer to NFC-DEP device info */ - uint32_t RTOXTimer; /*!< Timer used for RTOX */ + uint32_t RTOXTimer; /*!< Timer used for RTOX */ rfalNfcDepDeactCallback isDeactivating; /*!< Deactivating flag check callback */ - + bool isReqPending; /*!< Flag pending REQ from Target activation */ bool isTxPending; /*!< Flag pending DEP Block while waiting RTOX Ack */ bool isWait4RTOX; /*!< Flag for waiting RTOX Ack */ - + rfalNfcDepPduTxRxParam PDUParam; /*!< PDU TxRx params */ uint16_t PDUTxPos; /*!< PDU Tx position */ uint16_t PDURxPos; /*!< PDU Rx position */ @@ -388,9 +388,9 @@ static ReturnCode nfcipTargetHandleActivation( rfalNfcDepDevice *nfcDepDev, uint /*! ****************************************************************************** * \brief NFCIP Configure - * - * Configures the nfcip layer with the given configurations - * + * + * Configures the nfcip layer with the given configurations + * * \param[in] cfg : nfcip configuration for following communication ****************************************************************************** */ @@ -400,22 +400,22 @@ static void nfcipConfig( const rfalNfcDepConfigs * cfg ); /*! ****************************************************************************** * \brief Set DEP parameters - * + * * This method sets the parameters/configs for following Data Exchange * Sets the nfcip module state according to the role it is configured - * - * - * \warning To be used only after proper Initiator/Target activation: + * + * + * \warning To be used only after proper Initiator/Target activation: * nfcipTargetHandleActivation() or nfcipInitiatorActivate() has * returned success - * - * This must be called before nfcipRun() in case of Target to pass + * + * This must be called before nfcipRun() in case of Target to pass * rxBuffer - * - * Everytime some data needs to be transmitted call this to set it and + * + * Everytime some data needs to be transmitted call this to set it and * call nfcipRun() until done or error - * - * \param[in] DEPParams : the parameters to be used during Data Exchange + * + * \param[in] DEPParams : the parameters to be used during Data Exchange ****************************************************************************** */ static void nfcipSetDEPParams( const rfalNfcDepDEPParams *DEPParams ); @@ -424,25 +424,25 @@ static void nfcipSetDEPParams( const rfalNfcDepDEPParams *DEPParams ); /*! ****************************************************************************** * \brief NFCIP run protocol - * + * * This method handles all the nfcip protocol during Data Exchange (DEP * requests and responses). - * + * * A data exchange cycle is considered a DEP REQ and a DEP RES. - * + * * In case of Tx chaining(MI) must signal it with nfcipSetDEPParams() - * In case of Rx chaining(MI) outIsChaining will be set to true and the + * In case of Rx chaining(MI) outIsChaining will be set to true and the * current data returned - * + * * \param[out] outActRxLen : data received length * \param[out] outIsChaining : true if other peer is performing chaining(MI) - * + * * \return RFAL_ERR_NONE : Data exchange cycle completed successfully * \return RFAL_ERR_TIMEOUT : Timeout occurred * \return RFAL_ERR_PROTO : Protocol error occurred - * \return RFAL_ERR_AGAIN : Other peer is doing chaining(MI), current block + * \return RFAL_ERR_AGAIN : Other peer is doing chaining(MI), current block * was received successfully call again until complete - * + * ****************************************************************************** */ static ReturnCode nfcipRun( uint16_t *outActRxLen, bool *outIsChaining ); @@ -451,16 +451,16 @@ static ReturnCode nfcipRun( uint16_t *outActRxLen, bool *outIsChaining ); /*! ****************************************************************************** * \brief Transmission method - * + * * This method checks if the current communication is Active or Passive * and performs the necessary procedures for each communication type - * - * Transmits the data hold in txBuf - * + * + * Transmits the data hold in txBuf + * * \param[in] txBuf : buffer to transmit - * \param[in] txBufLen : txBuffer capacity + * \param[in] txBufLen : txBuffer capacity * \param[in] fwt : fwt for current Tx - * + * * \return RFAL_ERR_NONE : No error ****************************************************************************** */ @@ -470,14 +470,14 @@ static ReturnCode nfcipDataTx( uint8_t* txBuf, uint16_t txBufLen, uint32_t fwt ) /*! ****************************************************************************** * \brief Reception method - * + * * This method checks if the current communication is Active or Passive * and calls the appropriate reception method - * + * * Copies incoming data to rxBuf - * + * * \param[in] blocking : reception is to be done blocking or non-blocking - * + * * \return RFAL_ERR_BUSY : Busy * \return RFAL_ERR_NONE : No error ****************************************************************************** @@ -498,16 +498,16 @@ static ReturnCode nfcipDataRx( bool blocking ); static bool nfcipDxIsSupported( uint8_t Dx, uint8_t BRx, uint8_t BSx ) { uint8_t Bx; - + /* Take the min of the possible bit rates, we'll use one for both directions */ Bx = RFAL_MIN(BRx, BSx); - + /* Lower bit rates must be supported for P2P */ if( (Dx <= (uint8_t)RFAL_NFCDEP_Dx_04_424) ) { return true; } - + if( (Dx == (uint8_t)RFAL_NFCDEP_Dx_08_848) && (Bx >= (uint8_t)RFAL_NFCDEP_Bx_08_848) ) { return true; @@ -521,26 +521,26 @@ static bool nfcipDxIsSupported( uint8_t Dx, uint8_t BRx, uint8_t BSx ) 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 ) { ReturnCode ret; - + if( (cmd == NFCIP_CMD_DEP_REQ) || (cmd == NFCIP_CMD_DEP_RES) ) /* this method cannot be used for DEPs */ { return RFAL_ERR_PARAM; } - + /* Assign the global params for this TxRx */ gNfcip.rxBuf = rxBuf; gNfcip.rxBufLen = rxBufLen; gNfcip.rxRcvdLen = rxActLen; - - + + /*******************************************************************************/ /* Transmission */ /*******************************************************************************/ - if(txBuf != NULL) /* if nothing to Tx, just do Rx */ + if(txBuf != NULL) /* if nothing to Tx, just do Rx */ { - RFAL_EXIT_ON_ERR( ret, nfcipTx( cmd, txBuf, paylBuf, paylBufLen, 0, fwt ) ); + RFAL_EXIT_ON_ERR( ret, nfcipTx( cmd, txBuf, paylBuf, paylBufLen, 0, fwt ) ); } - + /*******************************************************************************/ /* Reception */ /*******************************************************************************/ @@ -549,8 +549,8 @@ static ReturnCode nfcipTxRx( rfalNfcDepCmd cmd, uint8_t* txBuf, uint32_t fwt, ui { return ret; } - - /*******************************************************************************/ + + /*******************************************************************************/ *rxActLen = *rxBuf; /* Use LEN byte instead due to with/without CRC modes */ return RFAL_ERR_NONE; /* Tx and Rx completed successfully */ } @@ -568,7 +568,7 @@ static ReturnCode nfcipDEPControlMsg( uint8_t pfb, uint8_t RTOX ) /*******************************************************************************/ const rfalNfcDepCmd depCmd = ((gNfcip.cfg.role == RFAL_NFCDEP_ROLE_TARGET) ? NFCIP_CMD_DEP_RES : NFCIP_CMD_DEP_REQ); 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) ) ); - + if( nfcip_PFBisSTO( pfb ) ) { ctrlMsg[RFAL_NFCDEP_DEPREQ_HEADER_LEN] = RTOX; @@ -599,15 +599,15 @@ static ReturnCode nfcipInitiatorHandleDEP( ReturnCode rxRes, uint16_t rxLen, uin uint8_t rxPFB; uint8_t rxRTOX; uint8_t optHdrLen; - + ret = RFAL_ERR_INTERNAL; rxMsgIt = 0; optHdrLen = 0; - + *outActRxLen = 0; *outIsChaining = false; - - + + /*******************************************************************************/ /* Handle reception errors */ /*******************************************************************************/ @@ -616,9 +616,9 @@ static ReturnCode nfcipInitiatorHandleDEP( ReturnCode rxRes, uint16_t rxLen, uin /*******************************************************************************/ /* Timeout -> Digital 1.0 14.15.5.6 */ case RFAL_ERR_TIMEOUT: - + nfcipLogI( " NFCIP(I) TIMEOUT TORetrys:%d \r\n", gNfcip.cntTORetrys ); - + /* Digital 1.0 14.15.5.6 - If nTO >= Max raise protocol error */ if( gNfcip.cntTORetrys++ >= RFAL_NFCDEP_TO_RETRYS ) { @@ -626,9 +626,9 @@ static ReturnCode nfcipInitiatorHandleDEP( ReturnCode rxRes, uint16_t rxLen, uin } /*******************************************************************************/ - /* Upon Timeout error, if Deactivation is pending, no more error recovery - * will be done #54. - * This is used to address the issue some devices that havea big TO. + /* Upon Timeout error, if Deactivation is pending, no more error recovery + * will be done #54. + * This is used to address the issue some devices that havea big TO. * Normally LLCP layer has timeout already, and NFCIP layer is still * running error handling, retrying ATN/NACKs */ /*******************************************************************************/ @@ -637,7 +637,7 @@ static ReturnCode nfcipInitiatorHandleDEP( ReturnCode rxRes, uint16_t rxLen, uin nfcipLogI( " skipping error recovery due deactivation pending \r\n"); return RFAL_ERR_TIMEOUT; } - + /* Digital 1.0 14.15.5.6 1) If last PDU was NACK */ if( nfcip_PFBisRNACK(gNfcip.lastPFB) ) { @@ -646,35 +646,35 @@ static ReturnCode nfcipInitiatorHandleDEP( ReturnCode rxRes, uint16_t rxLen, uin { return RFAL_ERR_PROTO; } - + /* Send NACK */ nfcipLogI( " NFCIP(I) Sending NACK retry: %d \r\n", gNfcip.cntNACKRetrys ); RFAL_EXIT_ON_ERR( ret, nfcipDEPControlMsg( nfcip_PFBRPDU_NACK(gNfcip.pni), 0 ) ); return RFAL_ERR_BUSY; } - + nfcipLogI( " NFCIP(I) Checking if to send ATN ATNRetrys: %d \r\n", gNfcip.cntATNRetrys ); - - /* Digital 1.0 14.15.5.6 3) Otherwise send ATN */ + + /* Digital 1.0 14.15.5.6 3) Otherwise send ATN */ if( gNfcip.cntATNRetrys++ >= RFAL_NFCDEP_MAX_ATN_RETRYS ) { return RFAL_ERR_PROTO; } - + /* Send ATN */ nfcipLogI( " NFCIP(I) Sending ATN \r\n" ); RFAL_EXIT_ON_ERR( ret, nfcipDEPControlMsg( nfcip_PFBSPDU_ATN(), 0 ) ); return RFAL_ERR_BUSY; - + /*******************************************************************************/ /* Data rcvd with error -> Digital 1.0 14.12.5.4 */ case RFAL_ERR_CRC: case RFAL_ERR_PAR: case RFAL_ERR_FRAMING: case RFAL_ERR_RF_COLLISION: - + nfcipLogI( " NFCIP(I) rx Error: %d \r\n", rxRes ); - + /* Digital 1.0 14.12.5.4 Tx Error with data, ignore */ if( rxLen < NFCIP_MIN_TXERROR_LEN ) { @@ -694,63 +694,63 @@ static ReturnCode nfcipInitiatorHandleDEP( ReturnCode rxRes, uint16_t rxLen, uin { return RFAL_ERR_FRAMING; } - + /* Send NACK */ nfcipLogI( " NFCIP(I) Sending NACK \r\n" ); RFAL_EXIT_ON_ERR( ret, nfcipDEPControlMsg( nfcip_PFBRPDU_NACK(gNfcip.pni), 0 ) ); return RFAL_ERR_BUSY; - + case RFAL_ERR_NONE: break; - + case RFAL_ERR_BUSY: return RFAL_ERR_BUSY; /* Debug purposes */ - + default: nfcipLogW( " NFCIP(I) Error: %d \r\n", rxRes ); return rxRes; - } - + } + /*******************************************************************************/ /* Rx OK check if valid DEP PDU */ /*******************************************************************************/ - + if( gNfcip.rxBuf == NULL ) { return RFAL_ERR_IO; } - + /* Due to different modes on ST25R391x (with/without CRC) use NFC-DEP LEN instead of bytes retrieved */ nfcDepLen = gNfcip.rxBuf[rxMsgIt++]; - + nfcipLogD( " NFCIP(I) rx OK: %d bytes \r\n", nfcDepLen ); - + /* Digital 1.0 14.15.5.5 Protocol Error */ if( gNfcip.rxBuf[rxMsgIt++] != NFCIP_RES ) { nfcipLogW( " NFCIP(I) error %02X instead of %02X \r\n", gNfcip.rxBuf[(rxMsgIt-1U)], NFCIP_RES ); return RFAL_ERR_PROTO; } - + /* Digital 1.0 14.15.5.5 Protocol Error */ if( gNfcip.rxBuf[rxMsgIt++] != (uint8_t)NFCIP_CMD_DEP_RES ) { nfcipLogW( " NFCIP(I) error %02X instead of %02X \r\n", gNfcip.rxBuf[(rxMsgIt-1U)], NFCIP_CMD_DEP_RES ); return RFAL_ERR_PROTO; } - + rxPFB = gNfcip.rxBuf[rxMsgIt++]; - + /*******************************************************************************/ /* Check for valid PFB type */ if( !(nfcip_PFBisSPDU( rxPFB ) || nfcip_PFBisRPDU( rxPFB ) || nfcip_PFBisIPDU( rxPFB )) ) { return RFAL_ERR_PROTO; } - + /*******************************************************************************/ /* Digital 1.0 14.8.2.1 check if DID is expected and match -> Protocol Error */ - if( gNfcip.cfg.did != RFAL_NFCDEP_DID_NO ) + if( gNfcip.cfg.did != RFAL_NFCDEP_DID_NO ) { if( (gNfcip.rxBuf[rxMsgIt++] != gNfcip.cfg.did) || (!nfcip_PFBhasDID( rxPFB )) ) { @@ -766,15 +766,15 @@ static ReturnCode nfcipInitiatorHandleDEP( ReturnCode rxRes, uint16_t rxLen, uin { /* MISRA 15.7 - Empty else */ } - + /*******************************************************************************/ /* Digital 1.0 14.6.2.8 & 14.6.3.11 NAD must not be used */ - if( gNfcip.cfg.nad != RFAL_NFCDEP_NAD_NO ) + if( gNfcip.cfg.nad != RFAL_NFCDEP_NAD_NO ) { if( (gNfcip.rxBuf[rxMsgIt++] != gNfcip.cfg.nad) || (!nfcip_PFBhasNAD( rxPFB )) ) { return RFAL_ERR_PROTO; - } + } optHdrLen++; /* Inc header optional field cnt*/ } else if( nfcip_PFBhasNAD( rxPFB ) ) /* NAD not expected but rcv */ @@ -785,7 +785,7 @@ static ReturnCode nfcipInitiatorHandleDEP( ReturnCode rxRes, uint16_t rxLen, uin { /* MISRA 15.7 - Empty else */ } - + /*******************************************************************************/ /* Process R-PDU */ /*******************************************************************************/ @@ -801,13 +801,13 @@ static ReturnCode nfcipInitiatorHandleDEP( ReturnCode rxRes, uint16_t rxLen, uin { /* 14.12.3.3 R-ACK with correct PNI -> Increment */ gNfcip.pni = nfcip_PNIInc( gNfcip.pni ); - + /* R-ACK while not performing chaining -> Protocol error*/ if( !gNfcip.isTxChaining ) { return RFAL_ERR_PROTO; } - + nfcipClearCounters(); gNfcip.state = NFCIP_ST_INIT_DEP_IDLE; return RFAL_ERR_NONE; /* This block has been transmitted */ @@ -818,12 +818,12 @@ static ReturnCode nfcipInitiatorHandleDEP( ReturnCode rxRes, uint16_t rxLen, uin { return RFAL_ERR_PROTO; } - + /* Extended the MAY in Digital 1.0 14.12.4.5 to only reTransmit if the ACK - * is for the previous DEP, otherwise raise Protocol immediately + * is for the previous DEP, otherwise raise Protocol immediately * If the PNI difference is more than 1 it is worthless to reTransmit 3x * and after raise the error */ - + if( nfcip_PNIDec( gNfcip.pni ) == nfcip_PBF_PNI( rxPFB ) ) { /* ReTransmit */ @@ -831,21 +831,21 @@ static ReturnCode nfcipInitiatorHandleDEP( ReturnCode rxRes, uint16_t rxLen, uin gNfcip.state = NFCIP_ST_INIT_DEP_TX; return RFAL_ERR_BUSY; } - + nfcipLogI( " NFCIP(I) Rcvd ACK unexpected far PNI -> Error \r\n" ); return RFAL_ERR_PROTO; } } else /* Digital 1.0 - 14.12.5.2 Target must never send NACK */ - { + { return RFAL_ERR_PROTO; } } - + /*******************************************************************************/ /* Process S-PDU */ /*******************************************************************************/ - if( nfcip_PFBisSPDU( rxPFB ) ) + if( nfcip_PFBisSPDU( rxPFB ) ) { nfcipLogI( " NFCIP(I) Rcvd S-PDU \r\n" ); /*******************************************************************************/ @@ -855,9 +855,9 @@ static ReturnCode nfcipInitiatorHandleDEP( ReturnCode rxRes, uint16_t rxLen, uin { nfcipLogI( " NFCIP(I) Rcvd ATN \r\n" ); if( nfcip_PFBisSATN( gNfcip.lastPFB ) ) /* Check if is expected */ - { + { gNfcip.cntATNRetrys = 0; /* Clear ATN counter */ - + /* Although spec is not clear NFC Forum Digital test is expecting to * retransmit upon receiving ATN_RES */ if( nfcip_PFBisSTO( gNfcip.lastPFBnATN ) ) @@ -872,11 +872,11 @@ static ReturnCode nfcipInitiatorHandleDEP( ReturnCode rxRes, uint16_t rxLen, uin { return RFAL_ERR_PROTO; } - + nfcipLogI( " NFCIP(I) Rcvd ATN -> reTx PNI: %d \r\n", gNfcip.pni ); gNfcip.state = NFCIP_ST_INIT_DEP_TX; } - + return RFAL_ERR_BUSY; } else /* Digital 1.0 14.12.4.4 & 14.12.4.8 */ @@ -890,25 +890,25 @@ static ReturnCode nfcipInitiatorHandleDEP( ReturnCode rxRes, uint16_t rxLen, uin else if( nfcip_PFBisSTO( rxPFB ) ) /* If is a S-TO (RTOX) */ { nfcipLogI( " NFCIP(I) Rcvd TO \r\n" ); - + rxRTOX = gNfcip.rxBuf[rxMsgIt++]; - + /* Digital 1.1 16.12.4.3 - Initiator MAY stop accepting subsequent RTOX Req * * - RTOX request to an ATN -> Protocol error */ if( (gNfcip.cntRTOXRetrys++ > RFAL_NFCDEP_MAX_RTOX_RETRYS) || nfcip_PFBisSATN( gNfcip.lastPFB ) ) { return RFAL_ERR_PROTO; } - + /* Digital 1.1 16.8.4.1 RTOX must be between [1,59] */ if( (rxRTOX < NFCIP_INIT_MIN_RTOX) || (rxRTOX > NFCIP_INIT_MAX_RTOX) ) { return RFAL_ERR_PROTO; } - + RFAL_EXIT_ON_ERR( ret, nfcipDEPControlMsg( nfcip_PFBSPDU_TO(), rxRTOX ) ); gNfcip.lastRTOX = rxRTOX; - + return RFAL_ERR_BUSY; } else @@ -917,7 +917,7 @@ static ReturnCode nfcipInitiatorHandleDEP( ReturnCode rxRes, uint16_t rxLen, uin return RFAL_ERR_PROTO; } } - + /*******************************************************************************/ /* Process I-PDU */ /*******************************************************************************/ @@ -928,17 +928,17 @@ static ReturnCode nfcipInitiatorHandleDEP( ReturnCode rxRes, uint16_t rxLen, uin nfcipLogI( " NFCIP(I) Rcvd IPDU wrong PNI curPNI: %d rxPNI: %d \r\n", gNfcip.pni , nfcip_PBF_PNI( rxPFB ) ); return RFAL_ERR_PROTO; } - + nfcipLogD( " NFCIP(I) Rcvd IPDU OK PNI: %d \r\n", gNfcip.pni ); - + /* 14.12.3.3 I-PDU with correct PNI -> Increment */ gNfcip.pni = nfcip_PNIInc( gNfcip.pni ); - - + + /* Successful data Exchange */ nfcipClearCounters(); *outActRxLen = ((uint16_t)nfcDepLen - RFAL_NFCDEP_DEP_HEADER - (uint16_t)optHdrLen); - + if( (&gNfcip.rxBuf[gNfcip.rxBufPaylPos] != &gNfcip.rxBuf[RFAL_NFCDEP_DEP_HEADER + optHdrLen]) && (*outActRxLen > 0U) ) { RFAL_MEMMOVE( &gNfcip.rxBuf[gNfcip.rxBufPaylPos], &gNfcip.rxBuf[RFAL_NFCDEP_DEP_HEADER + optHdrLen], *outActRxLen ); @@ -951,17 +951,17 @@ static ReturnCode nfcipInitiatorHandleDEP( ReturnCode rxRes, uint16_t rxLen, uin { gNfcip.isRxChaining = true; *outIsChaining = true; - + nfcipLogD( " NFCIP(I) Rcvd IPDU OK w MI -> ACK \r\n" ); RFAL_EXIT_ON_ERR( ret, nfcipDEPControlMsg( nfcip_PFBRPDU_ACK( gNfcip.pni ), gNfcip.rxBuf[rxMsgIt++] ) ); - + return RFAL_ERR_AGAIN; /* Send Again signalling to run again, but some chaining data has arrived*/ } else { gNfcip.isRxChaining = false; gNfcip.state = NFCIP_ST_INIT_DEP_IDLE; - + ret = RFAL_ERR_NONE; /* Data exchange done */ } } @@ -978,32 +978,32 @@ static ReturnCode nfcipTargetHandleRX( ReturnCode rxRes, uint16_t *outActRxLen, uint8_t rxPFB; uint8_t optHdrLen; uint8_t resBuf[RFAL_NFCDEP_HEADER_PAD + NFCIP_TARGET_RES_MAX]; - - + + ret = RFAL_ERR_INTERNAL; rxMsgIt = 0; optHdrLen = 0; - + *outActRxLen = 0; *outIsChaining = false; - - + + /*******************************************************************************/ /* Handle reception errors */ /*******************************************************************************/ switch( rxRes ) { - /*******************************************************************************/ + /*******************************************************************************/ case RFAL_ERR_NONE: break; - + case RFAL_ERR_LINK_LOSS: nfcipLogW( " NFCIP(T) Error: %d \r\n", rxRes ); return rxRes; - + case RFAL_ERR_BUSY: return RFAL_ERR_BUSY; /* Debug purposes */ - + case RFAL_ERR_TIMEOUT: case RFAL_ERR_CRC: case RFAL_ERR_PAR: @@ -1015,46 +1015,46 @@ static ReturnCode nfcipTargetHandleRX( ReturnCode rxRes, uint16_t *outActRxLen, * Transmission Error or a Protocol Error occurs. * * * * Do not push Transmission/Protocol Errors to upper layer in Listen Mode #766 */ - + nfcDepReEnableRx( gNfcip.rxBuf, gNfcip.rxBufLen, gNfcip.rxRcvdLen ); return RFAL_ERR_BUSY; - } - + } + /*******************************************************************************/ /* Rx OK check if valid DEP PDU */ /*******************************************************************************/ - + if( gNfcip.rxBuf == NULL ) { return RFAL_ERR_IO; } - + /* Due to different modes on ST25R391x (with/without CRC) use NFC-DEP LEN instead of bytes retrieved */ nfcDepLen = gNfcip.rxBuf[rxMsgIt++]; - + nfcipLogD( " NFCIP(T) rx OK: %d bytes \r\n", nfcDepLen ); - + if( gNfcip.rxBuf[rxMsgIt++] != NFCIP_REQ ) { nfcDepReEnableRx( gNfcip.rxBuf, gNfcip.rxBufLen, gNfcip.rxRcvdLen ); return RFAL_ERR_BUSY; /* RFAL_ERR_PROTO - Ignore bad request */ } - - + + /*******************************************************************************/ /* Check whether target rcvd a normal DEP or deactivation request */ /*******************************************************************************/ switch( gNfcip.rxBuf[rxMsgIt++] ) - { + { /*******************************************************************************/ case (uint8_t)NFCIP_CMD_DEP_REQ: break; /* Continue to normal DEP processing */ - + /*******************************************************************************/ case (uint8_t)NFCIP_CMD_DSL_REQ: - + nfcipLogI( " NFCIP(T) rx DSL \r\n" ); - + /* Digital 1.0 14.9.1.2 If DID is used and incorrect ignore it */ /* [Digital 1.0, 16.9.1.2]: If DID == 0, Target SHALL ignore DSL_REQ with DID */ if ( (((gNfcip.rxBuf[rxMsgIt++] != gNfcip.cfg.did) || (nfcDepLen != RFAL_NFCDEP_DSL_RLS_LEN_DID)) && (gNfcip.cfg.did != RFAL_NFCDEP_DID_NO) ) @@ -1064,17 +1064,17 @@ static ReturnCode nfcipTargetHandleRX( ReturnCode rxRes, uint16_t *outActRxLen, nfcipLogI( " NFCIP(T) DSL wrong DID, ignoring \r\n" ); return RFAL_ERR_BUSY; } - + nfcipTx( NFCIP_CMD_DSL_RES, resBuf, NULL, 0, 0, NFCIP_NO_FWT ); - + gNfcip.state = NFCIP_ST_TARG_DEP_SLEEP; return RFAL_ERR_SLEEP_REQ; - + /*******************************************************************************/ case (uint8_t)NFCIP_CMD_RLS_REQ: - + nfcipLogI( " NFCIP(T) rx RLS \r\n" ); - + /* Digital 1.0 14.10.1.2 If DID is used and incorrect ignore it */ /* [Digital 1.0, 16.10.2.2]: If DID == 0, Target SHALL ignore DSL_REQ with DID */ if ( (((gNfcip.rxBuf[rxMsgIt++] != gNfcip.cfg.did) || (nfcDepLen != RFAL_NFCDEP_DSL_RLS_LEN_DID)) && (gNfcip.cfg.did != RFAL_NFCDEP_DID_NO) ) @@ -1084,28 +1084,28 @@ static ReturnCode nfcipTargetHandleRX( ReturnCode rxRes, uint16_t *outActRxLen, nfcipLogI( " NFCIP(T) RLS wrong DID, ignoring \r\n" ); return RFAL_ERR_BUSY; } - + nfcipTx( NFCIP_CMD_RLS_RES, resBuf, NULL, 0, 0, NFCIP_NO_FWT ); - + gNfcip.state = NFCIP_ST_TARG_DEP_IDLE; return RFAL_ERR_RELEASE_REQ; - + /*******************************************************************************/ /*case NFCIP_CMD_PSL_REQ: PSL must be handled in Activation only */ /*case NFCIP_CMD_WUP_REQ: WUP not in NFC Forum Digital 1.0 */ default: - + /* Don't go to NFCIP_ST_TARG_DEP_IDLE state as it needs to ignore this * * invalid frame, and keep waiting for more frames */ - + nfcDepReEnableRx( gNfcip.rxBuf, gNfcip.rxBufLen, gNfcip.rxRcvdLen ); return RFAL_ERR_BUSY; /* RFAL_ERR_PROTO - Ignore bad frame */ } - + /*******************************************************************************/ - + rxPFB = gNfcip.rxBuf[rxMsgIt++]; /* Store rcvd PFB */ - + /*******************************************************************************/ /* Check for valid PFB type */ if( !(nfcip_PFBisSPDU( rxPFB ) || nfcip_PFBisRPDU( rxPFB ) || nfcip_PFBisIPDU( rxPFB )) ) @@ -1113,9 +1113,9 @@ static ReturnCode nfcipTargetHandleRX( ReturnCode rxRes, uint16_t *outActRxLen, nfcDepReEnableRx( gNfcip.rxBuf, gNfcip.rxBufLen, gNfcip.rxRcvdLen ); return RFAL_ERR_BUSY; /* RFAL_ERR_PROTO - Ignore invalid PFB */ } - - /*******************************************************************************/ - if( gNfcip.cfg.did != RFAL_NFCDEP_DID_NO ) + + /*******************************************************************************/ + if( gNfcip.cfg.did != RFAL_NFCDEP_DID_NO ) { if( !nfcip_PFBhasDID( rxPFB ) ) { @@ -1138,10 +1138,10 @@ static ReturnCode nfcipTargetHandleRX( ReturnCode rxRes, uint16_t *outActRxLen, { /* MISRA 15.7 - Empty else */ } - - + + /*******************************************************************************/ - if( gNfcip.cfg.nad != RFAL_NFCDEP_NAD_NO ) + if( gNfcip.cfg.nad != RFAL_NFCDEP_NAD_NO ) { if( (gNfcip.rxBuf[rxMsgIt++] != gNfcip.cfg.did) || (!nfcip_PFBhasDID( rxPFB )) ) { @@ -1159,8 +1159,8 @@ static ReturnCode nfcipTargetHandleRX( ReturnCode rxRes, uint16_t *outActRxLen, { /* MISRA 15.7 - Empty else */ } - - + + /*******************************************************************************/ /* Process R-PDU */ /*******************************************************************************/ @@ -1181,23 +1181,23 @@ static ReturnCode nfcipTargetHandleRX( ReturnCode rxRes, uint16_t *outActRxLen, nfcDepReEnableRx( gNfcip.rxBuf, gNfcip.rxBufLen, gNfcip.rxRcvdLen ); return RFAL_ERR_BUSY; /* RFAL_ERR_PROTO - Ignore unexpected ACK */ } - + /* This block has been transmitted and acknowledged, perform RTOX until next data is provided */ - + /* Digital 1.1 16.12.4.7 - If ACK rcvd continue with chaining or an RTOX */ nfcipTimerStart( gNfcip.RTOXTimer, nfcipRTOXAdjust( nfcipConv1FcToMs( rfalNfcDepWT2RWT( gNfcip.cfg.to ) )) ); gNfcip.state = NFCIP_ST_TARG_DEP_RTOX; - + return RFAL_ERR_NONE; /* This block has been transmitted */ } - + /* Digital 1.0 14.12.3.4 - If last send was ATN and rx PNI is minus 1 */ - else if( nfcip_PFBisSATN( gNfcip.lastPFB ) && (nfcip_PNIDec(gNfcip.pni) == nfcip_PBF_PNI( rxPFB )) ) - { + else if( nfcip_PFBisSATN( gNfcip.lastPFB ) && (nfcip_PNIDec(gNfcip.pni) == nfcip_PBF_PNI( rxPFB )) ) + { nfcipLogI( " NFCIP(T) wrong PNI, last was ATN reTx \r\n" ); /* Spec says to leave current PNI as is, but will be Inc after Tx, remaining the same */ gNfcip.pni = nfcip_PNIDec( gNfcip.pni ); - + gNfcip.state = NFCIP_ST_TARG_DEP_TX; return RFAL_ERR_BUSY; } @@ -1213,39 +1213,39 @@ static ReturnCode nfcipTargetHandleRX( ReturnCode rxRes, uint16_t *outActRxLen, else if( nfcip_PFBisRNACK( rxPFB ) && (nfcip_PNIDec(gNfcip.pni) == nfcip_PBF_PNI( rxPFB ) ) ) { nfcipLogI( " NFCIP(T) Rcvd NACK \r\n" ); - + gNfcip.pni = nfcip_PNIDec( gNfcip.pni ); /* Dec so that has the prev PNI */ - + gNfcip.state = NFCIP_ST_TARG_DEP_TX; return RFAL_ERR_BUSY; } else - { + { nfcipLogI( " NFCIP(T) Unexpected R-PDU \r\n" ); - + nfcDepReEnableRx( gNfcip.rxBuf, gNfcip.rxBufLen, gNfcip.rxRcvdLen ); return RFAL_ERR_BUSY; /* RFAL_ERR_PROTO - Ignore unexpected R-PDU */ } } - + /*******************************************************************************/ /* Process S-PDU */ /*******************************************************************************/ if( nfcip_PFBisSPDU( rxPFB ) ) { nfcipLogD( " NFCIP(T) Rcvd S-PDU \r\n" ); - + /*******************************************************************************/ /* S ATN */ /*******************************************************************************/ /* ISO 18092 12.6.3 Attention */ if( nfcip_PFBisSATN( rxPFB ) ) /* If is a S-ATN */ - { + { nfcipLogI( " NFCIP(T) Rcvd ATN curPNI: %d \r\n", gNfcip.pni ); RFAL_EXIT_ON_ERR( ret, nfcipDEPControlMsg( nfcip_PFBSPDU_ATN(), 0 ) ); return RFAL_ERR_BUSY; } - + /*******************************************************************************/ /* S TO */ /*******************************************************************************/ @@ -1254,32 +1254,32 @@ static ReturnCode nfcipTargetHandleRX( ReturnCode rxRes, uint16_t *outActRxLen, if( nfcip_PFBisSTO( gNfcip.lastPFBnATN ) ) { nfcipLogI( " NFCIP(T) Rcvd TO \r\n" ); - + /* Digital 1.1 16.8.4.6 RTOX value in RES different that in REQ -> Protocol Error */ if( gNfcip.lastRTOX != gNfcip.rxBuf[rxMsgIt++] ) { nfcipLogI( " NFCIP(T) Mismatched RTOX value \r\n" ); - + nfcDepReEnableRx( gNfcip.rxBuf, gNfcip.rxBufLen, gNfcip.rxRcvdLen ); return RFAL_ERR_BUSY; /* RFAL_ERR_PROTO - Ignore unexpected RTOX value */ } - + /* Clear waiting for RTOX Ack Flag */ gNfcip.isWait4RTOX = false; - + /* Check if a Tx is already pending */ if( gNfcip.isTxPending ) { nfcipLogW( " NFCIP(T) Tx pending, go immediately to TX \r\n" ); - + gNfcip.state = NFCIP_ST_TARG_DEP_TX; return RFAL_ERR_BUSY; } - + /* Start RTOX timer and change to check state */ nfcipTimerStart( gNfcip.RTOXTimer, nfcipRTOXAdjust( nfcipConv1FcToMs( gNfcip.lastRTOX * rfalNfcDepWT2RWT(gNfcip.cfg.to ) ) ) ); gNfcip.state = NFCIP_ST_TARG_DEP_RTOX; - + return RFAL_ERR_BUSY; } } @@ -1287,12 +1287,12 @@ static ReturnCode nfcipTargetHandleRX( ReturnCode rxRes, uint16_t *outActRxLen, { /* Unexpected S-PDU */ nfcipLogI( " NFCIP(T) Unexpected S-PDU \r\n" ); - + nfcDepReEnableRx( gNfcip.rxBuf, gNfcip.rxBufLen, gNfcip.rxRcvdLen ); return RFAL_ERR_BUSY; /* RFAL_ERR_PROTO - Ignore unexpected S-PDU */ } } - + /*******************************************************************************/ /* Process I-PDU */ /*******************************************************************************/ @@ -1301,18 +1301,18 @@ static ReturnCode nfcipTargetHandleRX( ReturnCode rxRes, uint16_t *outActRxLen, if( gNfcip.pni != nfcip_PBF_PNI( rxPFB ) ) { nfcipLogI( " NFCIP(T) Rcvd IPDU wrong PNI curPNI: %d rxPNI: %d \r\n", gNfcip.pni, nfcip_PBF_PNI( rxPFB ) ); - + /* Digital 1.1 16.12.3.4 - If last send was ATN and rx PNI is minus 1 */ - if( nfcip_PFBisSATN(gNfcip.lastPFB ) && (nfcip_PNIDec(gNfcip.pni) == nfcip_PBF_PNI( rxPFB )) ) + if( nfcip_PFBisSATN(gNfcip.lastPFB ) && (nfcip_PNIDec(gNfcip.pni) == nfcip_PBF_PNI( rxPFB )) ) { /* Spec says to leave current PNI as is, but will be Inc after Data Tx, remaining the same */ gNfcip.pni = nfcip_PNIDec(gNfcip.pni); - + if( nfcip_PFBisIMI( rxPFB ) ) { nfcipLogI( " NFCIP(T) PNI = prevPNI && ATN before && chaining -> send ACK \r\n" ); RFAL_EXIT_ON_ERR( ret, nfcipDEPControlMsg( nfcip_PFBRPDU_ACK( gNfcip.pni ), gNfcip.rxBuf[rxMsgIt++] ) ); - + /* Digital 1.1 16.12.3.4 (...) leave the current PNI unchanged afterwards */ gNfcip.pni = nfcip_PNIInc( gNfcip.pni ); } @@ -1321,29 +1321,29 @@ static ReturnCode nfcipTargetHandleRX( ReturnCode rxRes, uint16_t *outActRxLen, nfcipLogI( " NFCIP(T) PNI = prevPNI && ATN before -> reTx last I-PDU \r\n" ); gNfcip.state = NFCIP_ST_TARG_DEP_TX; } - + return RFAL_ERR_BUSY; } - + nfcDepReEnableRx( gNfcip.rxBuf, gNfcip.rxBufLen, gNfcip.rxRcvdLen ); return RFAL_ERR_BUSY; /* RFAL_ERR_PROTO - Ignore bad PNI value */ } - + nfcipLogD( " NFCIP(T) Rcvd IPDU OK PNI: %d \r\n", gNfcip.pni ); - + /*******************************************************************************/ /* Successful data exchange */ /*******************************************************************************/ *outActRxLen = ((uint16_t)nfcDepLen - RFAL_NFCDEP_DEP_HEADER - (uint16_t)optHdrLen); - + nfcipClearCounters(); if( (&gNfcip.rxBuf[gNfcip.rxBufPaylPos] != &gNfcip.rxBuf[RFAL_NFCDEP_DEP_HEADER + optHdrLen]) && (*outActRxLen > 0U) ) { RFAL_MEMMOVE( &gNfcip.rxBuf[gNfcip.rxBufPaylPos], &gNfcip.rxBuf[RFAL_NFCDEP_DEP_HEADER + optHdrLen], *outActRxLen ); } - - + + /*******************************************************************************/ /* Check if Initiator is indicating chaining MI */ /*******************************************************************************/ @@ -1351,12 +1351,12 @@ static ReturnCode nfcipTargetHandleRX( ReturnCode rxRes, uint16_t *outActRxLen, { gNfcip.isRxChaining = true; *outIsChaining = true; - + nfcipLogD( " NFCIP(T) Rcvd IPDU OK w MI -> ACK \r\n" ); RFAL_EXIT_ON_ERR( ret, nfcipDEPControlMsg( nfcip_PFBRPDU_ACK( gNfcip.pni ), gNfcip.rxBuf[rxMsgIt++] ) ); - + gNfcip.pni = nfcip_PNIInc( gNfcip.pni ); - + return RFAL_ERR_AGAIN; /* Send Again signalling to run again, but some chaining data has arrived*/ } else @@ -1365,13 +1365,13 @@ static ReturnCode nfcipTargetHandleRX( ReturnCode rxRes, uint16_t *outActRxLen, { nfcipLogI( " NFCIP(T) Rcvd last IPDU chaining finished \r\n" ); } - + /*******************************************************************************/ /* Reception done, send to DH and start RTOX timer */ /*******************************************************************************/ nfcipTimerStart( gNfcip.RTOXTimer, nfcipRTOXAdjust( nfcipConv1FcToMs( rfalNfcDepWT2RWT( gNfcip.cfg.to ) )) ); gNfcip.state = NFCIP_ST_TARG_DEP_RTOX; - + gNfcip.isRxChaining = false; ret = RFAL_ERR_NONE; /* Data exchange done */ } @@ -1387,31 +1387,31 @@ static ReturnCode nfcipTx( rfalNfcDepCmd cmd, uint8_t* txBuf, uint8_t *paylBuf, uint8_t *txBlock; uint8_t *payloadBuf; uint8_t pfb; - - + + if( txBuf == NULL ) { return RFAL_ERR_PARAM; } - + payloadBuf = paylBuf; /* MISRA 17.8: Use intermediate variable */ - + if( (paylLen == 0U) || (payloadBuf == NULL) ) { payloadBuf = (uint8_t*) &txBuf[RFAL_NFCDEP_DEPREQ_HEADER_LEN]; /* If not a DEP (no Data) ensure enough space for header */ } - - + + txBufIt = 0; pfb = pfbData; /* MISRA 17.8: Use intermediate variable */ - - txBlock = payloadBuf; /* Point to beginning of the Data, and go backwards */ - - + + txBlock = payloadBuf; /* Point to beginning of the Data, and go backwards */ + + gNfcip.lastCmd = (uint8_t)cmd; /* Store last cmd sent */ gNfcip.lastPFB = NFCIP_PFB_INVALID; /* Reset last pfb sent */ - + /*******************************************************************************/ /* Compute outgoing NFCIP message */ /*******************************************************************************/ @@ -1420,19 +1420,19 @@ static ReturnCode nfcipTx( rfalNfcDepCmd cmd, uint8_t* txBuf, uint8_t *paylBuf, /*******************************************************************************/ case NFCIP_CMD_ATR_RES: case NFCIP_CMD_ATR_REQ: - + rfalNfcDepSetNFCID( payloadBuf, gNfcip.cfg.nfcid, gNfcip.cfg.nfcidLen ); /* NFCID */ txBufIt += RFAL_NFCDEP_NFCID3_LEN; - + payloadBuf[txBufIt++] = gNfcip.cfg.did; /* DID */ payloadBuf[txBufIt++] = gNfcip.cfg.bs; /* BS */ payloadBuf[txBufIt++] = gNfcip.cfg.br; /* BR */ - + if( cmd == NFCIP_CMD_ATR_RES ) { payloadBuf[txBufIt++] = gNfcip.cfg.to; /* ATR_RES[ TO ] */ } - + if( gNfcip.cfg.gbLen > 0U) { payloadBuf[txBufIt++] = nfcip_PPwGB( gNfcip.cfg.lr ); /* PP signalling GB */ @@ -1443,76 +1443,76 @@ static ReturnCode nfcipTx( rfalNfcDepCmd cmd, uint8_t* txBuf, uint8_t *paylBuf, { payloadBuf[txBufIt++] = rfalNfcDepLR2PP( gNfcip.cfg.lr ); /* PP without GB */ } - + if( (txBufIt + RFAL_NFCDEP_CMDTYPE_LEN + RFAL_NFCDEP_CMD_LEN) > RFAL_NFCDEP_ATRREQ_MAX_LEN ) /* Check max ATR length (ATR_REQ = ATR_RES)*/ { return RFAL_ERR_PARAM; } break; - + /*******************************************************************************/ case NFCIP_CMD_WUP_REQ: /* ISO 18092 - 12.5.2.1 */ - + rfalNfcDepSetNFCID( (payloadBuf), gNfcip.cfg.nfcid, gNfcip.cfg.nfcidLen ); /* NFCID */ txBufIt += RFAL_NFCDEP_NFCID3_LEN; - + *(--txBlock) = gNfcip.cfg.did; /* DID */ break; - + /*******************************************************************************/ case NFCIP_CMD_WUP_RES: /* ISO 18092 - 12.5.2.2 */ case NFCIP_CMD_PSL_REQ: case NFCIP_CMD_PSL_RES: - + *(--txBlock) = gNfcip.cfg.did; /* DID */ break; - + /*******************************************************************************/ case NFCIP_CMD_RLS_REQ: case NFCIP_CMD_RLS_RES: case NFCIP_CMD_DSL_REQ: case NFCIP_CMD_DSL_RES: - + /* Digital 1.0 - 14.8.1.1 & 14.9.1.1 & 14.10.1.1 Only add DID if not 0 */ if( gNfcip.cfg.did != RFAL_NFCDEP_DID_NO ) { *(--txBlock) = gNfcip.cfg.did; /* DID */ } break; - + /*******************************************************************************/ case NFCIP_CMD_DEP_REQ: case NFCIP_CMD_DEP_RES: - + /* Compute optional PFB bits */ if (gNfcip.cfg.did != RFAL_NFCDEP_DID_NO) { pfb |= NFCIP_PFB_DID_BIT; } if (gNfcip.cfg.nad != RFAL_NFCDEP_NAD_NO) { pfb |= NFCIP_PFB_NAD_BIT; } if ((gNfcip.isTxChaining) && (nfcip_PFBisIPDU(pfb)) ) { pfb |= NFCIP_PFB_MI_BIT; } - + /* Store PFB for future handling */ gNfcip.lastPFB = pfb; /* store PFB sent */ - + if( !nfcip_PFBisSATN(pfb) ) { gNfcip.lastPFBnATN = pfb; /* store last PFB different then ATN */ } - - + + /* Add NAD if it is to be supported */ - if( gNfcip.cfg.nad != RFAL_NFCDEP_NAD_NO ) + if( gNfcip.cfg.nad != RFAL_NFCDEP_NAD_NO ) { *(--txBlock) = gNfcip.cfg.nad; /* NAD */ } - + /* Digital 1.0 - 14.8.1.1 & 14.8.1.1 Only add DID if not 0 */ if( gNfcip.cfg.did != RFAL_NFCDEP_DID_NO ) { *(--txBlock) = gNfcip.cfg.did; /* DID */ } - + *(--txBlock) = pfb; /* PFB */ - - + + /* NCI 1.0 - Check if Empty frames are allowed */ if( (paylLen == 0U) && nfcipIsEmptyDEPDisabled(gNfcip.cfg.oper) && nfcip_PFBisIPDU(pfb) ) { @@ -1524,22 +1524,22 @@ static ReturnCode nfcipTx( rfalNfcDepCmd cmd, uint8_t* txBuf, uint8_t *paylBuf, default: return RFAL_ERR_PARAM; } - + /*******************************************************************************/ /* Prepend Header */ - /*******************************************************************************/ + /*******************************************************************************/ *(--txBlock) = (uint8_t)cmd; /* CMD */ *(--txBlock) = (uint8_t)( nfcipCmdIsReq(cmd) ? NFCIP_REQ : NFCIP_RES ); /* CMDType */ - - + + txBufIt += paylLen + (uint16_t)((uintptr_t)payloadBuf - (uintptr_t)txBlock); /* Calculate overall buffer size */ - - + + if( txBufIt > gNfcip.fsc ) /* Check if msg length violates the maximum payload size FSC */ { return RFAL_ERR_NOTSUPP; } - + /*******************************************************************************/ return nfcipDataTx( txBlock, txBufIt, fwt ); } @@ -1553,17 +1553,17 @@ static ReturnCode nfcipTx( rfalNfcDepCmd cmd, uint8_t* txBuf, uint8_t *paylBuf, /*******************************************************************************/ static void nfcipConfig( const rfalNfcDepConfigs * cfg ) { - if (cfg == NULL) + if (cfg == NULL) { return; } - + RFAL_MEMCPY(&gNfcip.cfg, cfg, sizeof(rfalNfcDepConfigs)); /* Copy given config to local */ - + gNfcip.cfg.to = RFAL_MIN( RFAL_NFCDEP_WT_TRG_MAX, gNfcip.cfg.to); /* Ensure proper WT value */ gNfcip.cfg.did = nfcip_DIDMax( gNfcip.cfg.did ); /* Ensure proper DID value */ gNfcip.fsc = rfalNfcDepLR2FS( gNfcip.cfg.lr ); /* Calculate FSC based on given LR */ - + gNfcip.state = ( ( gNfcip.cfg.role == RFAL_NFCDEP_ROLE_TARGET) ? NFCIP_ST_TARG_WAIT_ATR : NFCIP_ST_INIT_IDLE ); } @@ -1572,11 +1572,11 @@ static void nfcipConfig( const rfalNfcDepConfigs * cfg ) static ReturnCode nfcipRun( uint16_t *outActRxLen, bool *outIsChaining ) { ReturnCode ret; - + ret = RFAL_ERR_SYNTAX; - + nfcipLogD( " NFCIP Run() state: %d \r\n", gNfcip.state ); - + switch( gNfcip.state ) { /*******************************************************************************/ @@ -1585,105 +1585,105 @@ static ReturnCode nfcipRun( uint16_t *outActRxLen, bool *outIsChaining ) case NFCIP_ST_TARG_DEP_IDLE: case NFCIP_ST_TARG_DEP_SLEEP: return RFAL_ERR_NONE; - + /*******************************************************************************/ case NFCIP_ST_INIT_DEP_TX: - + nfcipLogD( " NFCIP(I) Tx PNI: %d txLen: %d \r\n", gNfcip.pni, gNfcip.txBufLen ); ret = nfcipTx( NFCIP_CMD_DEP_REQ, gNfcip.txBuf, &gNfcip.txBuf[gNfcip.txBufPaylPos], gNfcip.txBufLen, nfcip_PFBIPDU( gNfcip.pni ), (gNfcip.cfg.fwt + gNfcip.cfg.dFwt) ); - + switch( ret ) { case RFAL_ERR_NONE: gNfcip.state = NFCIP_ST_INIT_DEP_RX; break; - + case RFAL_ERR_PARAM: default: gNfcip.state = NFCIP_ST_INIT_DEP_IDLE; return ret; } /* fall through */ - + /*******************************************************************************/ case NFCIP_ST_INIT_DEP_RX: /* PRQA S 2003 # MISRA 16.3 - Intentional fall through */ ret = nfcipDataRx( false ); - + if( ret != RFAL_ERR_BUSY ) { ret = nfcipInitiatorHandleDEP( ret, ((gNfcip.rxRcvdLen != NULL) ? *gNfcip.rxRcvdLen : 0U), outActRxLen, outIsChaining ); } - + break; - - /*******************************************************************************/ + + /*******************************************************************************/ case NFCIP_ST_TARG_DEP_RTOX: - + if( !nfcipTimerisExpired( gNfcip.RTOXTimer ) ) /* Do nothing until RTOX timer has expired */ { return RFAL_ERR_BUSY; } - - /* If we cannot send a RTOX raise a Timeout error so that we do not + + /* If we cannot send a RTOX raise a Timeout error so that we do not * hold the field On forever in AP2P */ if( nfcipIsRTOXReqDisabled(gNfcip.cfg.oper) ) { - /* We should reEnable Rx, and measure time between our field Off to + /* We should reEnable Rx, and measure time between our field Off to * either report link loss or recover #287 */ nfcipLogI( " NFCIP(T) RTOX not sent due to config, NOT reenabling Rx \r\n" ); return RFAL_ERR_TIMEOUT; - } + } if( gNfcip.cntRTOXRetrys++ > RFAL_NFCDEP_MAX_RTOX_RETRYS ) /* Check maximum consecutive RTOX requests */ { return RFAL_ERR_PROTO; } - + nfcipLogI( " NFCIP(T) RTOX sent \r\n" ); - - gNfcip.lastRTOX = nfcip_RTOXTargMax(gNfcip.cfg.to); /* Calculate requested RTOX value, and send it */ + + gNfcip.lastRTOX = nfcip_RTOXTargMax(gNfcip.cfg.to); /* Calculate requested RTOX value, and send it */ RFAL_EXIT_ON_ERR( ret, nfcipDEPControlMsg( nfcip_PFBSPDU_TO(), gNfcip.lastRTOX ) ); - + /* Set waiting for RTOX Ack Flag */ gNfcip.isWait4RTOX = true; - + gNfcip.state = NFCIP_ST_TARG_DEP_RX; /* Go back to Rx to process RTOX ack */ return RFAL_ERR_BUSY; - + /*******************************************************************************/ case NFCIP_ST_TARG_DEP_TX: - + nfcipLogD( " NFCIP(T) Tx PNI: %d txLen: %d \r\n", gNfcip.pni, gNfcip.txBufLen ); ret = nfcipTx( NFCIP_CMD_DEP_RES, gNfcip.txBuf, &gNfcip.txBuf[gNfcip.txBufPaylPos], gNfcip.txBufLen, nfcip_PFBIPDU( gNfcip.pni ), NFCIP_NO_FWT ); - + /* Clear flags */ gNfcip.isTxPending = false; gNfcip.isWait4RTOX = false; - + /* Digital 1.0 14.12.3.4 Increment the current PNI after Tx */ gNfcip.pni = nfcip_PNIInc( gNfcip.pni ); - + switch( ret ) { case RFAL_ERR_NONE: gNfcip.state = NFCIP_ST_TARG_DEP_RX; /* All OK, goto Rx state */ break; - + case RFAL_ERR_PARAM: default: gNfcip.state = NFCIP_ST_TARG_DEP_IDLE; /* Upon Tx error, goto IDLE state */ return ret; } /* fall through */ - + /*******************************************************************************/ case NFCIP_ST_TARG_DEP_RX: /* PRQA S 2003 # MISRA 16.3 - Intentional fall through */ - + if( gNfcip.isReqPending ) /* if already has Data should be from a DEP from nfcipTargetHandleActivation() */ { nfcipLogD( " NFCIP(T) Skipping Rx Using DEP from Activation \r\n" ); - + gNfcip.isReqPending = false; ret = RFAL_ERR_NONE; } @@ -1691,14 +1691,14 @@ static ReturnCode nfcipRun( uint16_t *outActRxLen, bool *outIsChaining ) { ret = nfcipDataRx( false ); } - + if( ret != RFAL_ERR_BUSY ) { ret = nfcipTargetHandleRX( ret, outActRxLen, outIsChaining ); } - + break; - + /*******************************************************************************/ default: /* MISRA 16.4: no empty default statement (a comment being enough) */ @@ -1719,43 +1719,43 @@ void rfalNfcDepSetDeactivatingCallback( rfalNfcDepDeactCallback pFunc ) void rfalNfcDepInitialize( void ) { nfcipLogD( " NFCIP Ini() \r\n" ); - + gNfcip.state = NFCIP_ST_IDLE; gNfcip.isDeactivating = NULL; - + gNfcip.isTxPending = false; gNfcip.isWait4RTOX = false; gNfcip.isReqPending = false; - - + + 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); - + gNfcip.cfg.did = RFAL_NFCDEP_DID_NO; gNfcip.cfg.nad = RFAL_NFCDEP_NAD_NO; - + gNfcip.cfg.br = RFAL_NFCDEP_Bx_NO_HIGH_BR; gNfcip.cfg.bs = RFAL_NFCDEP_Bx_NO_HIGH_BR; - + gNfcip.cfg.lr = RFAL_NFCDEP_LR_254; gNfcip.fsc = rfalNfcDepLR2FS( gNfcip.cfg.lr ); - + gNfcip.cfg.gbLen = 0; - + gNfcip.cfg.fwt = NFCIP_RWT_ACTIVATION; gNfcip.cfg.dFwt = RFAL_NFCDEP_WT_DELTA; - - gNfcip.pni = 0; - + + gNfcip.pni = 0; + /* Destroy any ongoing RTOX timer*/ nfcipTimerDestroy( gNfcip.RTOXTimer ); gNfcip.RTOXTimer = 0U; - + gNfcip.PDUTxPos = 0; gNfcip.PDURxPos = 0; gNfcip.PDUParam.rxLen = NULL; gNfcip.PDUParam.rxBuf = NULL; gNfcip.PDUParam.txBuf = NULL; - + nfcipClearCounters(); } @@ -1765,7 +1765,7 @@ void rfalNfcDepInitialize( void ) static void nfcipSetDEPParams( const rfalNfcDepDEPParams *DEPParams ) { nfcipLogD( " NFCIP SetDEP() txLen: %d \r\n", DEPParams->txBufLen ); - + gNfcip.isTxChaining = DEPParams->txChaining; gNfcip.txBuf = DEPParams->txBuf; gNfcip.rxBuf = DEPParams->rxBuf; @@ -1773,18 +1773,18 @@ static void nfcipSetDEPParams( const rfalNfcDepDEPParams *DEPParams ) gNfcip.rxBufLen = DEPParams->rxBufLen; gNfcip.txBufPaylPos = DEPParams->txBufPaylPos; gNfcip.rxBufPaylPos = DEPParams->rxBufPaylPos; - + if( DEPParams->did != RFAL_NFCDEP_DID_KEEP ) { gNfcip.cfg.did = nfcip_DIDMax( DEPParams->did ); } - + gNfcip.cfg.fwt = DEPParams->fwt; gNfcip.cfg.dFwt = DEPParams->dFwt; gNfcip.fsc = DEPParams->fsc; - - - + + + if(gNfcip.cfg.role == RFAL_NFCDEP_ROLE_TARGET) { /* If there's any data to be sent go for Tx */ @@ -1800,10 +1800,10 @@ static void nfcipSetDEPParams( const rfalNfcDepDEPParams *DEPParams ) { /* If RTOX Ack is expected, signal a pending Tx to be transmitted right after */ gNfcip.isTxPending = true; - nfcipLogW( " NFCIP(T) Waiting RTOX, queueing outgoing DEP Block \r\n" ); + nfcipLogW( " NFCIP(T) Waiting RTOX, queueing outgoing DEP Block \r\n" ); } - } - + } + /*Digital 1.0 14.12.4.1 In target mode the first PDU MUST be sent by the Initiator */ gNfcip.state = NFCIP_ST_TARG_DEP_RX; return; @@ -1811,7 +1811,7 @@ static void nfcipSetDEPParams( const rfalNfcDepDEPParams *DEPParams ) /* New data TxRx request clear previous error counters for consecutive TxRx without reseting communication/protocol layer*/ nfcipClearCounters(); - + gNfcip.state = NFCIP_ST_INIT_DEP_TX; } @@ -1827,30 +1827,30 @@ bool rfalNfcDepTargetRcvdATR( void ) bool rfalNfcDepIsAtrReq( const uint8_t* buf, uint16_t bufLen, uint8_t* nfcid3 ) { uint8_t msgIt; - + msgIt = 0; - + if ( (bufLen < RFAL_NFCDEP_ATRREQ_MIN_LEN) || (bufLen > RFAL_NFCDEP_ATRREQ_MAX_LEN) ) { return false; } - + if ( buf[msgIt++] != NFCIP_REQ ) { return false; } - + if( buf[msgIt++] != (uint8_t)NFCIP_CMD_ATR_REQ ) { return false; } - + /* Output NFID3 if requested */ if( nfcid3 != NULL ) { RFAL_MEMCPY( nfcid3, &buf[RFAL_NFCDEP_ATR_REQ_NFCID3_POS], RFAL_NFCDEP_NFCID3_LEN ); } - + return true; } @@ -1861,7 +1861,7 @@ static ReturnCode nfcipTargetHandleActivation( rfalNfcDepDevice *nfcDepDev, uint ReturnCode ret; uint8_t msgIt; uint8_t txBuf[RFAL_NFCDEP_HEADER_PAD + NFCIP_PSLRES_LEN]; - + /*******************************************************************************/ /* Check if we are in correct state */ /*******************************************************************************/ @@ -1869,8 +1869,8 @@ static ReturnCode nfcipTargetHandleActivation( rfalNfcDepDevice *nfcDepDev, uint { return RFAL_ERR_WRONG_STATE; } - - + + /*******************************************************************************/ /* Check required parameters */ /*******************************************************************************/ @@ -1878,70 +1878,70 @@ static ReturnCode nfcipTargetHandleActivation( rfalNfcDepDevice *nfcDepDev, uint { return RFAL_ERR_PARAM; } - + /*******************************************************************************/ /* Wait and process incoming cmd (PSL / DEP) */ - /*******************************************************************************/ + /*******************************************************************************/ ret = nfcipDataRx( false ); if( ret != RFAL_ERR_NONE ) { return ret; } - + if( gNfcip.rxBuf == NULL ) { return RFAL_ERR_IO; } - - + + msgIt = 0; *outBRS = RFAL_NFCDEP_BRS_MAINTAIN; /* set out BRS to be maintained */ - + msgIt++; /* Skip LEN byte */ - + if ( gNfcip.rxBuf[msgIt++] != NFCIP_REQ ) { return RFAL_ERR_PROTO; } - + if( gNfcip.rxBuf[msgIt] == (uint8_t)NFCIP_CMD_PSL_REQ ) { msgIt++; - + if( gNfcip.rxBuf[msgIt++] != gNfcip.cfg.did ) /* Checking DID */ { return RFAL_ERR_PROTO; } - + nfcipLogI( " NFCIP(T) PSL REQ rcvd \r\n" ); - + *outBRS = gNfcip.rxBuf[msgIt++]; /* assign output BRS value */ - + /* Store FSL(LR) and update current config */ gNfcip.cfg.lr = (gNfcip.rxBuf[msgIt++] & RFAL_NFCDEP_LR_VAL_MASK); gNfcip.fsc = rfalNfcDepLR2FS( gNfcip.cfg.lr ); - + /*******************************************************************************/ /* Update NFC-DDE Device info */ if( nfcDepDev != NULL ) { /* Update Bitrate info */ /* PRQA S 4342 2 # MISRA 10.5 - Layout of enum rfalBitRate and definition of rfalNfcDepBRS2DSI guarantee no invalid enum values to be created */ - nfcDepDev->info.DSI = (rfalBitRate)rfalNfcDepBRS2DSI( *outBRS ); /* DSI codes the bit rate from Initiator to Target */ + nfcDepDev->info.DSI_ID = (rfalBitRate)rfalNfcDepBRS2DSI( *outBRS ); /* DSI_ID codes the bit rate from Initiator to Target */ nfcDepDev->info.DRI = (rfalBitRate)rfalNfcDepBRS2DRI( *outBRS ); /* DRI codes the bit rate from Target to Initiator */ - + /* Update Length Reduction and Frame Size */ nfcDepDev->info.LR = gNfcip.cfg.lr; nfcDepDev->info.FS = gNfcip.fsc; - + /* Update PPi byte */ nfcDepDev->activation.Initiator.ATR_REQ.PPi &= ~RFAL_NFCDEP_PP_LR_MASK; nfcDepDev->activation.Initiator.ATR_REQ.PPi |= rfalNfcDepLR2PP( gNfcip.cfg.lr ); } - - rfalSetBitRate( RFAL_BR_KEEP, gNfcip.nfcDepDev->info.DSI ); - + + rfalSetBitRate( RFAL_BR_KEEP, gNfcip.nfcDepDev->info.DSI_ID ); + RFAL_EXIT_ON_ERR( ret, nfcipTx( NFCIP_CMD_PSL_RES, txBuf, NULL, 0, 0, NFCIP_NO_FWT ) ); } else @@ -1949,17 +1949,17 @@ static ReturnCode nfcipTargetHandleActivation( rfalNfcDepDevice *nfcDepDev, uint if( gNfcip.rxBuf[msgIt] == (uint8_t)NFCIP_CMD_DEP_REQ ) { msgIt++; - + /*******************************************************************************/ /* Digital 1.0 14.12.3.1 PNI must be initialized to 0 */ if( nfcip_PBF_PNI( gNfcip.rxBuf[msgIt] ) != 0U ) { return RFAL_ERR_PROTO; } - + /*******************************************************************************/ /* Digital 1.0 14.8.2.1 check if DID is expected and match -> Protocol Error */ - if( nfcip_PFBhasDID( gNfcip.rxBuf[ msgIt] ) ) + if( nfcip_PFBhasDID( gNfcip.rxBuf[ msgIt] ) ) { if( gNfcip.rxBuf[++msgIt] != gNfcip.cfg.did ) { @@ -1975,11 +1975,11 @@ static ReturnCode nfcipTargetHandleActivation( rfalNfcDepDevice *nfcDepDev, uint /* MISRA 15.7 - Empty else */ } } - + /* Signal Request pending to be digested on normal Handling (DEP_REQ, DSL_REQ, RLS_REQ) */ gNfcip.isReqPending = true; } - + gNfcip.state = NFCIP_ST_TARG_DEP_RX; return RFAL_ERR_NONE; } @@ -1994,19 +1994,19 @@ ReturnCode rfalNfcDepATR( const rfalNfcDepAtrParam* param, rfalNfcDepAtrRes *atr uint8_t msgIt; uint8_t txBuf[RFAL_NFCDEP_ATRREQ_MAX_LEN]; uint8_t rxBuf[NFCIP_ATRRES_BUF_LEN]; - - + + if( (param == NULL) || (atrRes == NULL) || (atrResLen == NULL) ) { return RFAL_ERR_PARAM; } RFAL_MEMSET( &cfg, 0x00, sizeof(rfalNfcDepConfigs) ); - + /*******************************************************************************/ /* Configure NFC-DEP layer */ /*******************************************************************************/ - + cfg.did = param->DID; cfg.nad = param->NAD; cfg.fwt = RFAL_NFCDEP_MAX_FWT; @@ -2015,58 +2015,58 @@ ReturnCode rfalNfcDepATR( const rfalNfcDepAtrParam* param, rfalNfcDepAtrRes *atr cfg.bs = param->BS; cfg.lr = param->LR; cfg.to = RFAL_NFCDEP_WT_TRG_MAX; /* Not used in Initiator mode */ - - + + cfg.gbLen = param->GBLen; if( cfg.gbLen > 0U ) /* MISRA 21.18 */ { RFAL_MEMCPY( cfg.gb, param->GB, cfg.gbLen ); } - + cfg.nfcidLen = param->nfcidLen; if( cfg.nfcidLen > 0U ) /* MISRA 21.18 */ { RFAL_MEMCPY( cfg.nfcid, param->nfcid, cfg.nfcidLen ); } - + cfg.role = RFAL_NFCDEP_ROLE_INITIATOR; cfg.oper = param->operParam; cfg.commMode = param->commMode; rfalNfcDepInitialize(); nfcipConfig( &cfg ); - + /*******************************************************************************/ /* Send ATR_REQ */ /*******************************************************************************/ - + RFAL_EXIT_ON_ERR( ret, nfcipTxRx(NFCIP_CMD_ATR_REQ, txBuf, nfcipRWTActivation(), NULL, 0, rxBuf, NFCIP_ATRRES_BUF_LEN, &rxLen ) ); - - + + /*******************************************************************************/ /* ATR sent, check response */ /*******************************************************************************/ msgIt = 0; rxLen = ((uint16_t)rxBuf[msgIt++] - RFAL_NFCDEP_LEN_LEN); /* use LEN byte */ - + if( (rxLen < RFAL_NFCDEP_ATRRES_MIN_LEN) || (rxLen > RFAL_NFCDEP_ATRRES_MAX_LEN) ) /* Checking length: ATR_RES */ { return RFAL_ERR_PROTO; } - + if( rxBuf[msgIt++] != NFCIP_RES ) /* Checking if is a response*/ { return RFAL_ERR_PROTO; } - + if( rxBuf[msgIt++] != (uint8_t)NFCIP_CMD_ATR_RES ) /* Checking if is a ATR RES */ { return RFAL_ERR_PROTO; } - + RFAL_MEMCPY( (uint8_t*)atrRes, (rxBuf + RFAL_NFCDEP_LEN_LEN), rxLen ); *atrResLen = (uint8_t)rxLen; - + return RFAL_ERR_NONE; } @@ -2079,86 +2079,86 @@ ReturnCode rfalNfcDepPSL( uint8_t BRS, uint8_t FSL ) uint8_t msgIt; uint8_t txBuf[NFCIP_PSLREQ_LEN + NFCIP_PSLPAY_LEN]; uint8_t rxBuf[NFCIP_PSLRES_LEN]; - + msgIt = NFCIP_PSLREQ_LEN; - + txBuf[msgIt++] = BRS; txBuf[msgIt++] = FSL; - + /*******************************************************************************/ /* Send PSL REQ and wait for response */ /*******************************************************************************/ RFAL_EXIT_ON_ERR( ret, nfcipTxRx( NFCIP_CMD_PSL_REQ, txBuf, (gNfcip.cfg.fwt + gNfcip.cfg.dFwt), &txBuf[NFCIP_PSLREQ_LEN], (msgIt - NFCIP_PSLREQ_LEN), rxBuf, NFCIP_PSLRES_LEN, &rxLen ) ); - - + + /*******************************************************************************/ /* PSL sent, check response */ /*******************************************************************************/ msgIt = 0; rxLen = (uint16_t)(rxBuf[msgIt++]); /* use LEN byte */ - + if( rxLen < NFCIP_PSLRES_LEN ) /* Checking length: LEN + RLS_RES */ { return RFAL_ERR_PROTO; } - + if( rxBuf[msgIt++] != NFCIP_RES ) /* Checking if is a response */ { return RFAL_ERR_PROTO; } - + if( rxBuf[msgIt++] != (uint8_t)NFCIP_CMD_PSL_RES ) /* Checking if is a PSL RES */ { return RFAL_ERR_PROTO; } - + if( rxBuf[msgIt++] != gNfcip.cfg.did ) /* Checking DID */ { return RFAL_ERR_PROTO; } - + return RFAL_ERR_NONE; } /*******************************************************************************/ ReturnCode rfalNfcDepDSL( void ) -{ +{ ReturnCode ret; uint8_t txBuf[ RFAL_NFCDEP_HEADER_PAD + NFCIP_DSLREQ_LEN]; uint8_t rxBuf[NFCIP_DSLRES_LEN]; uint8_t rxMsgIt; uint16_t rxLen = 0; - + if( gNfcip.cfg.role == RFAL_NFCDEP_ROLE_TARGET ) { return RFAL_ERR_NONE; /* Target has no deselect procedure */ } - + /* Repeating a DSL REQ is optional, not doing it */ RFAL_EXIT_ON_ERR( ret, nfcipTxRx( NFCIP_CMD_DSL_REQ, txBuf, (gNfcip.cfg.fwt + gNfcip.cfg.dFwt), NULL, 0, rxBuf, (uint16_t)sizeof(rxBuf), &rxLen ) ); - + /*******************************************************************************/ rxMsgIt = 0; - + if( rxBuf[rxMsgIt++] < NFCIP_DSLRES_MIN ) /* Checking length: LEN + DSL_RES */ { return RFAL_ERR_PROTO; } - + if( rxBuf[rxMsgIt++] != NFCIP_RES ) /* Checking if is a response */ { return RFAL_ERR_PROTO; } - + if( rxBuf[rxMsgIt++] != (uint8_t)NFCIP_CMD_DSL_RES ) /* Checking if is DSL RES */ { return RFAL_ERR_PROTO; } - - if( gNfcip.cfg.did != RFAL_NFCDEP_DID_NO ) + + if( gNfcip.cfg.did != RFAL_NFCDEP_DID_NO ) { - if ( rxBuf[rxMsgIt++] != gNfcip.cfg.did ) + if ( rxBuf[rxMsgIt++] != gNfcip.cfg.did ) { return RFAL_ERR_PROTO; } @@ -2170,47 +2170,47 @@ ReturnCode rfalNfcDepDSL( void ) /*******************************************************************************/ ReturnCode rfalNfcDepRLS( void ) -{ +{ ReturnCode ret; uint8_t txBuf[RFAL_NFCDEP_HEADER_PAD + NFCIP_RLSREQ_LEN]; - uint8_t rxBuf[NFCIP_RLSRES_LEN]; + uint8_t rxBuf[NFCIP_RLSRES_LEN]; uint8_t rxMsgIt; uint16_t rxLen = 0; - + if ( gNfcip.cfg.role == RFAL_NFCDEP_ROLE_TARGET ) /* Target has no release procedure */ { return RFAL_ERR_NONE; } - + /* Repeating a RLS REQ is optional, not doing it */ RFAL_EXIT_ON_ERR( ret, nfcipTxRx( NFCIP_CMD_RLS_REQ, txBuf, (gNfcip.cfg.fwt + gNfcip.cfg.dFwt), NULL, 0, rxBuf, (uint16_t)sizeof(rxBuf), &rxLen ) ); - + /*******************************************************************************/ rxMsgIt = 0; - + if( rxBuf[rxMsgIt++] < NFCIP_RLSRES_MIN ) /* Checking length: LEN + RLS_RES */ { return RFAL_ERR_PROTO; } - + if( rxBuf[rxMsgIt++] != NFCIP_RES ) /* Checking if is a response */ { return RFAL_ERR_PROTO; } - + if( rxBuf[rxMsgIt++] != (uint8_t)NFCIP_CMD_RLS_RES ) /* Checking if is RLS RES */ { return RFAL_ERR_PROTO; } - - if( gNfcip.cfg.did != RFAL_NFCDEP_DID_NO ) + + if( gNfcip.cfg.did != RFAL_NFCDEP_DID_NO ) { - if ( rxBuf[rxMsgIt++] != gNfcip.cfg.did ) + if ( rxBuf[rxMsgIt++] != gNfcip.cfg.did ) { return RFAL_ERR_PROTO; } } - + return RFAL_ERR_NONE; } @@ -2223,22 +2223,22 @@ ReturnCode rfalNfcDepInitiatorHandleActivation( rfalNfcDepAtrParam* param, rfalB uint8_t PSL_BRS; uint8_t PSL_FSL; bool sendPSL; - + if( (param == NULL) || (nfcDepDev == NULL) ) { return RFAL_ERR_PARAM; } - + param->NAD = RFAL_NFCDEP_NAD_NO; /* Digital 1.1 16.6.2.9 Initiator SHALL NOT use NAD */ maxRetyrs = NFCIP_ATR_RETRY_MAX; - + /*******************************************************************************/ /* Send ATR REQ and wait for response */ /*******************************************************************************/ do{ /* Upon transmission error ATR REQ should be retried */ - + ret = rfalNfcDepATR( param, &nfcDepDev->activation.Target.ATR_RES, &nfcDepDev->activation.Target.ATR_RESLen ); - + if( nfcipIsTransmissionError(ret) ) { continue; @@ -2246,12 +2246,12 @@ ReturnCode rfalNfcDepInitiatorHandleActivation( rfalNfcDepAtrParam* param, rfalB break; } while( (maxRetyrs--) != 0U ); - + if( ret != RFAL_ERR_NONE ) { return ret; } - + /*******************************************************************************/ /* Compute NFC-DEP device with ATR_RES */ /*******************************************************************************/ @@ -2263,23 +2263,23 @@ ReturnCode rfalNfcDepInitiatorHandleActivation( rfalNfcDepAtrParam* param, rfalB nfcDepDev->info.WT = (nfcDepDev->activation.Target.ATR_RES.TO & RFAL_NFCDEP_WT_MASK); nfcDepDev->info.FWT = rfalNfcDepCalculateRWT( nfcDepDev->info.WT ); nfcDepDev->info.dFWT = RFAL_NFCDEP_WT_DELTA; - - rfalGetBitRate( &nfcDepDev->info.DSI, &nfcDepDev->info.DRI ); - - - + + rfalGetBitRate( &nfcDepDev->info.DSI_ID, &nfcDepDev->info.DRI ); + + + /*******************************************************************************/ /* Check if a PSL needs to be sent */ /*******************************************************************************/ sendPSL = false; - PSL_BRS = rfalNfcDepDx2BRS( nfcDepDev->info.DSI ); /* Set current bit rate divisor on both directions */ + PSL_BRS = rfalNfcDepDx2BRS( nfcDepDev->info.DSI_ID ); /* Set current bit rate divisor on both directions */ PSL_FSL = nfcDepDev->info.LR; /* Set current Frame Size */ - - + + /* Activity 1.0 9.4.4.15 & 9.4.6.3 NFC-DEP Activation PSL * Activity 2.0 9.4.4.17 & 9.4.6.6 NFC-DEP Activation PSL - * + * * PSL_REQ shall only be sent if desired bit rate is different from current (Activity 1.0) * PSL_REQ shall be sent to update LR or bit rate (Activity 2.0) * */ @@ -2288,74 +2288,74 @@ ReturnCode rfalNfcDepInitiatorHandleActivation( rfalNfcDepAtrParam* param, rfalB /*******************************************************************************/ /* Check Frame Size */ /*******************************************************************************/ - if( gNfcip.cfg.lr < nfcDepDev->info.LR ) /* If our Length reduction is smaller */ + if( gNfcip.cfg.lr < nfcDepDev->info.LR ) /* If our Length reduction is smaller */ { sendPSL = true; - + nfcDepDev->info.LR = RFAL_MIN( nfcDepDev->info.LR, gNfcip.cfg.lr ); - + gNfcip.cfg.lr = nfcDepDev->info.LR; /* Update nfcip LR to be used */ - gNfcip.fsc = rfalNfcDepLR2FS( gNfcip.cfg.lr ); /* Update nfcip FSC to be used */ - + gNfcip.fsc = rfalNfcDepLR2FS( gNfcip.cfg.lr ); /* Update nfcip FSC to be used */ + PSL_FSL = gNfcip.cfg.lr; /* Set LR to be sent */ - + nfcipLogI( " NFCIP(I) Frame Size differ, PSL new fsc: %d \r\n", gNfcip.fsc ); } #endif - - + + /*******************************************************************************/ /* Check Baud rates */ /*******************************************************************************/ - if( (nfcDepDev->info.DSI != desiredBR) && (desiredBR != RFAL_BR_KEEP) ) /* if desired BR is different */ + if( (nfcDepDev->info.DSI_ID != desiredBR) && (desiredBR != RFAL_BR_KEEP) ) /* if desired BR is different */ { if( nfcipDxIsSupported( (uint8_t)desiredBR, nfcDepDev->activation.Target.ATR_RES.BRt, nfcDepDev->activation.Target.ATR_RES.BSt ) ) /* if desired BR is supported */ /* MISRA 13.5 */ { sendPSL = true; PSL_BRS = rfalNfcDepDx2BRS( desiredBR ); - + nfcipLogI( " NFCIP(I) BR differ, PSL BR: 0x%02X \r\n", PSL_BRS ); } } - + /*******************************************************************************/ if( sendPSL ) { /* Apply target's FWT for PSL_REQ Digital 2.2 17.11.2.5 */ gNfcip.cfg.fwt = nfcDepDev->info.FWT; - + /*******************************************************************************/ /* Send PSL REQ and wait for response */ /*******************************************************************************/ RFAL_EXIT_ON_ERR( ret, rfalNfcDepPSL(PSL_BRS, PSL_FSL) ); - + /* Check if bit rate has been changed */ - if( nfcDepDev->info.DSI != desiredBR ) + if( nfcDepDev->info.DSI_ID != desiredBR ) { /* Check if device was in Passive NFC-A and went to higher bit rates, use NFC-F */ - if( (nfcDepDev->info.DSI == RFAL_BR_106) && (gNfcip.cfg.commMode == RFAL_NFCDEP_COMM_PASSIVE) ) + if( (nfcDepDev->info.DSI_ID == RFAL_BR_106) && (gNfcip.cfg.commMode == RFAL_NFCDEP_COMM_PASSIVE) ) { - - #if RFAL_FEATURE_NFCF + + #if RFAL_FEATURE_NFCF /* If Passive initialize NFC-F module */ rfalNfcfPollerInitialize( desiredBR ); #else /* RFAL_FEATURE_NFCF */ return RFAL_ERR_NOTSUPP; #endif /* RFAL_FEATURE_NFCF */ - + } - - nfcDepDev->info.DRI = desiredBR; /* DSI Bit Rate coding from Initiator to Target */ - nfcDepDev->info.DSI = desiredBR; /* DRI Bit Rate coding from Target to Initiator */ - - rfalSetBitRate( nfcDepDev->info.DSI, nfcDepDev->info.DRI ); + + nfcDepDev->info.DRI = desiredBR; /* DSI_ID Bit Rate coding from Initiator to Target */ + nfcDepDev->info.DSI_ID = desiredBR; /* DRI Bit Rate coding from Target to Initiator */ + + rfalSetBitRate( nfcDepDev->info.DSI_ID, nfcDepDev->info.DRI ); } - - + + return RFAL_ERR_NONE; /* PSL has been sent */ } - + return RFAL_ERR_NONE; /* No PSL has been sent */ } @@ -2366,7 +2366,7 @@ uint32_t rfalNfcDepCalculateRWT( uint8_t wt ) /* Digital 1.0 14.6.3.8 & Digital 1.1 16.6.3.9 */ /* Digital 1.1 16.6.3.9 treat all RFU values as WT=14 */ const uint8_t responseWaitTime = RFAL_MIN( RFAL_NFCDEP_WT_INI_MAX, wt ); - + return (uint32_t)rfalNfcDepWT2RWT(responseWaitTime); } @@ -2383,7 +2383,7 @@ static ReturnCode nfcipDataTx( uint8_t* txBuf, uint16_t txBufLen, uint32_t fwt ) static ReturnCode nfcipDataRx( bool blocking ) { ReturnCode ret; - + /* Perform Rx either blocking or non-blocking */ if( blocking ) { @@ -2393,13 +2393,13 @@ static ReturnCode nfcipDataRx( bool blocking ) { ret = rfalGetTransceiveStatus(); } - + if( ret != RFAL_ERR_BUSY ) { if( gNfcip.rxRcvdLen != NULL ) { (*gNfcip.rxRcvdLen) = rfalConvBitsToBytes( *gNfcip.rxRcvdLen ); - + if( (ret == RFAL_ERR_NONE) && (gNfcip.rxBuf != NULL) ) { /* Digital 1.1 16.4.1.3 - Length byte LEN SHALL have a value between 3 and 255 -> otherwise treat as Transmission Error * @@ -2411,7 +2411,7 @@ static ReturnCode nfcipDataRx( bool blocking ) } } } - + return ret; } @@ -2421,27 +2421,27 @@ ReturnCode rfalNfcDepListenStartActivation( const rfalNfcDepTargetParam *param, { ReturnCode ret; rfalNfcDepConfigs cfg; - - + + if( (param == NULL) || (atrReq == NULL) || (rxParam.rxLen == NULL) ) { return RFAL_ERR_PARAM; } - - + + /*******************************************************************************/ /* Check whether is a valid ATR_REQ Compute NFC-DEP device */ if( !rfalNfcDepIsAtrReq( atrReq, atrReqLength, NULL ) ) { return RFAL_ERR_PARAM; } - - rxParam.nfcDepDev->activation.Initiator.ATR_REQLen = (uint8_t)atrReqLength; /* nfcipIsAtrReq() is already checking Min and Max buffer lengths */ + + rxParam.nfcDepDev->activation.Initiator.ATR_REQLen = (uint8_t)atrReqLength; /* nfcipIsAtrReq() is already checking Min and Max buffer lengths */ if( atrReqLength > 0U ) /* MISRA 21.18 */ { RFAL_MEMCPY( (uint8_t*)&rxParam.nfcDepDev->activation.Initiator.ATR_REQ, atrReq, atrReqLength ); - } - + } + rxParam.nfcDepDev->info.GBLen = (uint8_t)(atrReqLength - RFAL_NFCDEP_ATRREQ_MIN_LEN); rxParam.nfcDepDev->info.DID = rxParam.nfcDepDev->activation.Initiator.ATR_REQ.DID; rxParam.nfcDepDev->info.NAD = RFAL_NFCDEP_NAD_NO; /* Digital 1.1 16.6.2.9 Initiator SHALL NOT use NAD */ @@ -2450,45 +2450,45 @@ ReturnCode rfalNfcDepListenStartActivation( const rfalNfcDepTargetParam *param, rxParam.nfcDepDev->info.WT = 0; rxParam.nfcDepDev->info.FWT = NFCIP_NO_FWT; rxParam.nfcDepDev->info.dFWT = NFCIP_NO_FWT; - - rfalGetBitRate( &rxParam.nfcDepDev->info.DSI, &rxParam.nfcDepDev->info.DRI ); - - + + rfalGetBitRate( &rxParam.nfcDepDev->info.DSI_ID, &rxParam.nfcDepDev->info.DRI ); + + /* Store Device Info location, updated upon a PSL */ gNfcip.nfcDepDev = rxParam.nfcDepDev; - - + + /*******************************************************************************/ cfg.did = rxParam.nfcDepDev->activation.Initiator.ATR_REQ.DID; cfg.nad = RFAL_NFCDEP_NAD_NO; - + cfg.fwt = RFAL_NFCDEP_MAX_FWT; cfg.dFwt = RFAL_NFCDEP_WT_DELTA; cfg.br = param->brt; cfg.bs = param->bst; - + cfg.lr = rfalNfcDepPP2LR(param->ppt); - + cfg.gbLen = param->GBtLen; if( cfg.gbLen > 0U ) /* MISRA 21.18 */ { RFAL_MEMCPY(cfg.gb, param->GBt, cfg.gbLen); } - + cfg.nfcidLen = RFAL_NFCDEP_NFCID3_LEN; RFAL_MEMCPY(cfg.nfcid, param->nfcid3, RFAL_NFCDEP_NFCID3_LEN); cfg.to = param->to; - + cfg.role = RFAL_NFCDEP_ROLE_TARGET; cfg.oper = param->operParam; cfg.commMode = param->commMode; rfalNfcDepInitialize(); nfcipConfig( &cfg ); - - + + /*******************************************************************************/ /* Reply with ATR RES to Initiator */ /*******************************************************************************/ @@ -2498,11 +2498,11 @@ ReturnCode rfalNfcDepListenStartActivation( const rfalNfcDepTargetParam *param, gNfcip.rxBufPaylPos = RFAL_NFCDEP_DEPREQ_HEADER_LEN; gNfcip.isChaining = rxParam.isRxChaining; gNfcip.txBufPaylPos = RFAL_NFCDEP_DEPREQ_HEADER_LEN; - + RFAL_EXIT_ON_ERR( ret, nfcipTx( NFCIP_CMD_ATR_RES, (uint8_t*) gNfcip.rxBuf, NULL, 0, 0, NFCIP_NO_FWT ) ); - + gNfcip.state = NFCIP_ST_TARG_WAIT_ACTV; - + return RFAL_ERR_NONE; } @@ -2512,42 +2512,42 @@ ReturnCode rfalNfcDepListenGetActivationStatus( void ) { ReturnCode err; uint8_t BRS; - + BRS = RFAL_NFCDEP_BRS_MAINTAIN; - + err = nfcipTargetHandleActivation( gNfcip.nfcDepDev, &BRS ); - + switch (err) { case RFAL_ERR_NONE: - + if( BRS != RFAL_NFCDEP_BRS_MAINTAIN ) { - /* DSI codes the bit rate from Initiator to Target */ + /* DSI_ID codes the bit rate from Initiator to Target */ /* DRI codes the bit rate from Target to Initiator */ - + if( gNfcip.cfg.commMode == RFAL_NFCDEP_COMM_ACTIVE ) { - RFAL_EXIT_ON_ERR( err, rfalSetMode( RFAL_MODE_LISTEN_ACTIVE_P2P, gNfcip.nfcDepDev->info.DRI, gNfcip.nfcDepDev->info.DSI )); + RFAL_EXIT_ON_ERR( err, rfalSetMode( RFAL_MODE_LISTEN_ACTIVE_P2P, gNfcip.nfcDepDev->info.DRI, gNfcip.nfcDepDev->info.DSI_ID )); } else { - RFAL_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 )); + RFAL_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_ID )); } } break; - + case RFAL_ERR_BUSY: // do nothing break; - + case RFAL_ERR_PROTO: default: // re-enable receiving of data nfcDepReEnableRx( gNfcip.rxBuf, gNfcip.rxBufLen, gNfcip.rxRcvdLen ); break; } - + return err; } @@ -2556,7 +2556,7 @@ ReturnCode rfalNfcDepListenGetActivationStatus( void ) ReturnCode rfalNfcDepStartTransceive( const rfalNfcDepTxRxParam *param ) { rfalNfcDepDEPParams nfcDepParams; - + nfcDepParams.txBuf = (uint8_t *)param->txBuf; nfcDepParams.txBufLen = param->txBufLen; nfcDepParams.txChaining = param->isTxChaining; @@ -2573,7 +2573,7 @@ ReturnCode rfalNfcDepStartTransceive( const rfalNfcDepTxRxParam *param ) gNfcip.isChaining = param->isRxChaining; nfcipSetDEPParams(&nfcDepParams); - + return RFAL_ERR_NONE; } @@ -2602,7 +2602,7 @@ ReturnCode rfalNfcDepGetTransceiveStatus( void ) static void rfalNfcDepPdu2BLockParam( rfalNfcDepPduTxRxParam pduParam, rfalNfcDepTxRxParam *blockParam, uint16_t txPos, uint16_t rxPos ) { uint16_t maxInfLen; - + RFAL_NO_WARNING(rxPos); /* Keep this param for future use */ blockParam->DID = pduParam.DID; @@ -2632,63 +2632,63 @@ ReturnCode rfalNfcDepGetTransceiveStatus( void ) blockParam->isRxChaining = &gNfcip.isPDURxChaining; blockParam->rxLen = pduParam.rxLen; } - - + + /*******************************************************************************/ ReturnCode rfalNfcDepStartPduTransceive( rfalNfcDepPduTxRxParam param ) { rfalNfcDepTxRxParam txRxParam; - + /* Initialize and store APDU context */ gNfcip.PDUParam = param; gNfcip.PDUTxPos = 0; gNfcip.PDURxPos = 0; - + /* Convert PDU TxRxParams to Block TxRxParams */ rfalNfcDepPdu2BLockParam( gNfcip.PDUParam, &txRxParam, gNfcip.PDUTxPos, gNfcip.PDURxPos ); - + return rfalNfcDepStartTransceive( &txRxParam ); } - - + + /*******************************************************************************/ ReturnCode rfalNfcDepGetPduTransceiveStatus( void ) { ReturnCode ret; rfalNfcDepTxRxParam txRxParam; - + ret = rfalNfcDepGetTransceiveStatus(); switch( ret ) { /*******************************************************************************/ case RFAL_ERR_NONE: - + /* Check if we are still doing chaining on Tx */ if( gNfcip.isTxChaining ) { /* Add already Tx bytes */ gNfcip.PDUTxPos += gNfcip.txBufLen; - + /* Convert APDU TxRxParams to I-Block TxRxParams */ rfalNfcDepPdu2BLockParam( gNfcip.PDUParam, &txRxParam, gNfcip.PDUTxPos, gNfcip.PDURxPos ); - + if( txRxParam.txBufLen > 0U ) /* MISRA 21.18 */ { /* Move next Block to beginning of APDU Tx buffer */ RFAL_MEMCPY( gNfcip.PDUParam.txBuf->pdu, &gNfcip.PDUParam.txBuf->pdu[gNfcip.PDUTxPos], txRxParam.txBufLen ); } - + RFAL_EXIT_ON_ERR( ret, rfalNfcDepStartTransceive( &txRxParam ) ); return RFAL_ERR_BUSY; } - + /* PDU TxRx is done */ /* fall through */ - + /*******************************************************************************/ case RFAL_ERR_AGAIN: /* PRQA S 2003 # MISRA 16.3 - Intentional fall through */ - - + + /* Check if no PDU transceive has been started before (data from rfalNfcDepListenStartActivation) */ if( gNfcip.PDUParam.rxLen == NULL ) { @@ -2697,12 +2697,12 @@ ReturnCode rfalNfcDepGetPduTransceiveStatus( void ) { return RFAL_ERR_NOTSUPP; } - + /* TxRx is complete and full data is already available */ return RFAL_ERR_NONE; } - - + + if( (*gNfcip.PDUParam.rxLen) > 0U ) /* MISRA 21.18 */ { /* Ensure that data in tmpBuf still fits into PDU buffer */ @@ -2710,24 +2710,24 @@ ReturnCode rfalNfcDepGetPduTransceiveStatus( void ) { return RFAL_ERR_NOMEM; } - + /* Copy chained packet from tmp buffer to PDU buffer */ RFAL_MEMCPY( &gNfcip.PDUParam.rxBuf->pdu[gNfcip.PDURxPos], gNfcip.PDUParam.tmpBuf->inf, *gNfcip.PDUParam.rxLen ); gNfcip.PDURxPos += *gNfcip.PDUParam.rxLen; } - + /* Update output param rxLen */ *gNfcip.PDUParam.rxLen = gNfcip.PDURxPos; - + /* Wait for following Block or PDU TxRx is done */ return ((ret == RFAL_ERR_AGAIN) ? RFAL_ERR_BUSY : RFAL_ERR_NONE); - + /*******************************************************************************/ default: /* MISRA 16.4: no empty default statement (a comment being enough) */ break; } - + return ret; } diff --git a/core/embed/io/nfc/rfal/source/rfal_nfcv.c b/core/embed/io/nfc/rfal/source/rfal_nfcv.c index 16c52ceb2e..9cbc42a373 100644 --- a/core/embed/io/nfc/rfal/source/rfal_nfcv.c +++ b/core/embed/io/nfc/rfal/source/rfal_nfcv.c @@ -242,7 +242,7 @@ ReturnCode rfalNfcvPollerInventory(rfalNfcvNumSlots nSlots, uint8_t maskLen, ReturnCode ret; rfalNfcvInventoryReq invReq; uint16_t rxLen; -` + if (((maskVal == NULL) && (maskLen != 0U)) || (invRes == NULL)) { return RFAL_ERR_PARAM; }