Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
rfal_isoDep.h
00001 00002 /****************************************************************************** 00003 * @attention 00004 * 00005 * <h2><center>© COPYRIGHT 2016 STMicroelectronics</center></h2> 00006 * 00007 * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); 00008 * You may not use this file except in compliance with the License. 00009 * You may obtain a copy of the License at: 00010 * 00011 * http://www.st.com/myliberty 00012 * 00013 * Unless required by applicable law or agreed to in writing, software 00014 * distributed under the License is distributed on an "AS IS" BASIS, 00015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, 00016 * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, 00017 * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. 00018 * See the License for the specific language governing permissions and 00019 * limitations under the License. 00020 * 00021 ******************************************************************************/ 00022 00023 00024 /* 00025 * PROJECT: ST25R391x firmware 00026 * $Revision: $ 00027 * LANGUAGE: ISO C99 00028 */ 00029 00030 /*! \file rfal_isoDep.h 00031 * 00032 * \author Gustavo Patricio 00033 * 00034 * \brief Implementation of ISO-DEP protocol 00035 * 00036 * This implementation was based on the following specs: 00037 * - ISO/IEC 14443-4 2nd Edition 2008-07-15 00038 * - NFC Forum Digital Protocol 1.1 2014-01-14 00039 * 00040 * 00041 * @addtogroup RFAL 00042 * @{ 00043 * 00044 * @addtogroup RFAL-AL 00045 * @brief RFAL Abstraction Layer 00046 * @{ 00047 * 00048 * @addtogroup ISO-DEP 00049 * @brief RFAL ISO-DEP Module 00050 * @{ 00051 * 00052 */ 00053 00054 #ifndef RFAL_ISODEP_H_ 00055 #define RFAL_ISODEP_H_ 00056 /* 00057 ****************************************************************************** 00058 * INCLUDES 00059 ****************************************************************************** 00060 */ 00061 #include "platform1.h" 00062 #include "rfal_nfcb.h" 00063 00064 /* 00065 ****************************************************************************** 00066 * DEFINES 00067 ****************************************************************************** 00068 */ 00069 00070 #define RFAL_ISODEP_PROLOGUE_SIZE (3) /*!< Length of Prologue Field for I-Block Format */ 00071 00072 #define RFAL_ISODEP_PCB_LEN (1) /*!< PCB length */ 00073 #define RFAL_ISODEP_DID_LEN (1) /*!< DID length */ 00074 #define RFAL_ISODEP_NAD_LEN (1) /*!< NAD length */ 00075 #define RFAL_ISODEP_NO_DID (0x00) /*!< DID value indicating the ISO-DEP layer not to use DID */ 00076 #define RFAL_ISODEP_NO_NAD (0xFF) /*!< NAD value indicating the ISO-DEP layer not to use NAD */ 00077 00078 #define RFAL_ISODEP_FSDI_DEFAULT (8) /*!< Default Frame Size Integer supported by NFCC as Initiator */ 00079 #define RFAL_ISODEP_FWI_MASK (0xF0) /*!< Mask bits of FWI */ 00080 #define RFAL_ISODEP_FWI_SHIFT (4) /*!< Shift val of FWI */ 00081 #define RFAL_ISODEP_FWI_DEFAULT (4) /*!< Default value for FWI Digital 1.0 11.6.2.17 */ 00082 #define RFAL_ISODEP_ADV_FEATURE (0x0F) /*!< Indicate 256 Bytes FSD and Advanc Proto Feature support:NAD & DID */ 00083 00084 #define RFAL_ISODEP_DID_MAX (14) /*!< Maximum DID value */ 00085 00086 #define RFAL_ISODEP_BRI_MASK (0x07) /*!< Mask bits for Poll to Listen Send bitrate */ 00087 #define RFAL_ISODEP_BSI_MASK (0x70) /*!< Mask bits for Listen to Poll Send bitrate */ 00088 #define RFAL_ISODEP_SAME_BITRATE_MASK (0x80) /*!< Mask bit indicate only same bit rate D for both direction support */ 00089 #define RFAL_ISODEP_BITRATE_RFU_MASK (0x08) /*!< Mask bit for RFU */ 00090 00091 /*! Maximum Frame Waiting Time = ((256 * 16/fc) * 2^FWImax) = ((256*16/fc)*2^14) = (67108864)/fc = 2^26 (1/fc) */ 00092 #define RFAL_ISODEP_MAX_FWT (1<<26) 00093 00094 00095 00096 #define RFAL_ISODEP_FSX_KEEP (0xFF) /*!< Flag to keep FSX from activation */ 00097 #define RFAL_ISODEP_DEFAULT_FSCI RFAL_ISODEP_FSXI_256 /*!< FSCI default value to be used in Listen Mode */ 00098 #define RFAL_ISODEP_DEFAULT_FSC RFAL_ISODEP_FSX_256 /*!< FSC default value (aligned RFAL_ISODEP_DEFAULT_FSCI) */ 00099 #define RFAL_ISODEP_DEFAULT_SFGI (0) /*!< SFGI Default value to be used in Listen Mode */ 00100 00101 #define RFAL_ISODEP_APDU_MAX_LEN RFAL_ISODEP_FSX_1024 /*!< Max APDU length */ 00102 00103 #define RFAL_ISODEP_ATTRIB_RES_MBLI_NO_INFO (0x00) /*!< MBLI indicating no information on its internal input buffer size */ 00104 #define RFAL_ISODEP_ATTRIB_REQ_PARAM1_DEFAULT (0x00) /*!< Default values of Param 1 of ATTRIB_REQ Digital 1.0 12.6.1.3-5 */ 00105 #define RFAL_ISODEP_ATTRIB_HLINFO_LEN (32) /*!< Maximum Size of Higher Layer Information */ 00106 #define RFAL_ISODEP_ATS_HB_MAX_LEN (15) /*!< Maximum length of Historical Bytes Digital 1.1 13.6.2.23 */ 00107 #define RFAL_ISODEP_ATTRIB_REQ_MIN_LEN (9) /*!< Minimum Length of ATTRIB_REQ command */ 00108 #define RFAL_ISODEP_ATTRIB_RES_MIN_LEN (1) /*!< Minimum Length of ATTRIB_RES response */ 00109 00110 #define RFAL_ISODEP_ATS_TA_DPL_212 (0x01) /*!< ATS TA DSI 212 kbps support bit mask */ 00111 #define RFAL_ISODEP_ATS_TA_DPL_424 (0x02) /*!< ATS TA DSI 424 kbps support bit mask */ 00112 #define RFAL_ISODEP_ATS_TA_DPL_848 (0x04) /*!< ATS TA DSI 848 kbps support bit mask */ 00113 #define RFAL_ISODEP_ATS_TA_DLP_212 (0x10) /*!< ATS TA DSI 212 kbps support bit mask */ 00114 #define RFAL_ISODEP_ATS_TA_DLP_424 (0x20) /*!< ATS TA DRI 424 kbps support bit mask */ 00115 #define RFAL_ISODEP_ATS_TA_DLP_848 (0x40) /*!< ATS TA DRI 848 kbps support bit mask */ 00116 #define RFAL_ISODEP_ATS_TA_SAME_D (0x80) /*!< ATS TA same bit both directions bit mask */ 00117 #define RFAL_ISODEP_ATS_TB_FWI_MASK (0xF0) /*!< Mask bits for FWI (Frame Waiting Integer) in TB byte */ 00118 #define RFAL_ISODEP_ATS_TB_SFGI_MASK (0x0F) /*!< Mask bits for SFGI (Start-Up Frame Guard Integer) in TB byte */ 00119 00120 #define RFAL_ISODEP_ATS_T0_TA_PRESENCE_MASK (0x10) /*!< Mask bit for TA presence */ 00121 #define RFAL_ISODEP_ATS_T0_TB_PRESENCE_MASK (0x20) /*!< Mask bit for TB presence */ 00122 #define RFAL_ISODEP_ATS_T0_TC_PRESENCE_MASK (0x40) /*!< Mask bit for TC presence */ 00123 #define RFAL_ISODEP_ATS_T0_FSCI_MASK (0x0F) /*!< Mask bit for FSCI presence */ 00124 #define RFAL_ISODEP_ATS_T0_OFFSET (0x01) /*!< Offset of T0 in ATS Response */ 00125 00126 00127 #define RFAL_ISODEP_MAX_I_RETRYS (2) /*!< Number of retries for a I-Block Digital 1.1 15.2.5.4 */ 00128 #define RFAL_ISODEP_MAX_R_RETRYS (3) /*!< Number of retries for a R-Block Digital 1.1 A8 - nRETRY ACK/NAK: [2,5] */ 00129 #define RFAL_ISODEP_MAX_S_RETRYS (3) /*!< Number of retries for a S-Block Digital 1.1 A8 - nRETRY DESELECT: [0,5] WTX[2,5] */ 00130 #define RFAL_ISODEP_RATS_RETRIES (1) /*!< RATS retries upon fail Digital 1.1 A.6 - [0,1] */ 00131 00132 00133 /*! Frame Size for Proximity Card Integer definitions */ 00134 typedef enum 00135 { 00136 RFAL_ISODEP_FSXI_16 = 0, /*!< Frame Size for Proximity Card Integer with 16 bytes */ 00137 RFAL_ISODEP_FSXI_24 = 1, /*!< Frame Size for Proximity Card Integer with 24 bytes */ 00138 RFAL_ISODEP_FSXI_32 = 2, /*!< Frame Size for Proximity Card Integer with 32 bytes */ 00139 RFAL_ISODEP_FSXI_40 = 3, /*!< Frame Size for Proximity Card Integer with 40 bytes */ 00140 RFAL_ISODEP_FSXI_48 = 4, /*!< Frame Size for Proximity Card Integer with 48 bytes */ 00141 RFAL_ISODEP_FSXI_64 = 5, /*!< Frame Size for Proximity Card Integer with 64 bytes */ 00142 RFAL_ISODEP_FSXI_96 = 6, /*!< Frame Size for Proximity Card Integer with 96 bytes */ 00143 RFAL_ISODEP_FSXI_128 = 7, /*!< Frame Size for Proximity Card Integer with 128 bytes */ 00144 RFAL_ISODEP_FSXI_256 = 8, /*!< Frame Size for Proximity Card Integer with 256 bytes */ 00145 RFAL_ISODEP_FSXI_512 = 9, /*!< Frame Size for Proximity Card Integer with 512 bytes ISO14443-3 Amd2 2012 */ 00146 RFAL_ISODEP_FSXI_1024 = 10, /*!< Frame Size for Proximity Card Integer with 1024 bytes ISO14443-3 Amd2 2012 */ 00147 RFAL_ISODEP_FSXI_2048 = 11, /*!< Frame Size for Proximity Card Integer with 2048 bytes ISO14443-3 Amd2 2012 */ 00148 RFAL_ISODEP_FSXI_4096 = 12 /*!< Frame Size for Proximity Card Integer with 4096 bytes ISO14443-3 Amd2 2012 */ 00149 } rfalIsoDepFSxI ; 00150 00151 /*! Frame Size for Proximity Card definitions */ 00152 typedef enum 00153 { 00154 RFAL_ISODEP_FSX_16 = 16, /*!< Frame Size for Proximity Card with 16 bytes */ 00155 RFAL_ISODEP_FSX_24 = 24, /*!< Frame Size for Proximity Card with 16 bytes */ 00156 RFAL_ISODEP_FSX_32 = 32, /*!< Frame Size for Proximity Card with 32 bytes */ 00157 RFAL_ISODEP_FSX_40 = 40, /*!< Frame Size for Proximity Card with 40 bytes */ 00158 RFAL_ISODEP_FSX_48 = 48, /*!< Frame Size for Proximity Card with 48 bytes */ 00159 RFAL_ISODEP_FSX_64 = 64, /*!< Frame Size for Proximity Card with 64 bytes */ 00160 RFAL_ISODEP_FSX_96 = 96, /*!< Frame Size for Proximity Card with 96 bytes */ 00161 RFAL_ISODEP_FSX_128 = 128, /*!< Frame Size for Proximity Card with 128 bytes */ 00162 RFAL_ISODEP_FSX_256 = 256, /*!< Frame Size for Proximity Card with 256 bytes */ 00163 RFAL_ISODEP_FSX_512 = 512, /*!< Frame Size for Proximity Card with 512 bytes ISO14443-3 Amd2 2012 */ 00164 RFAL_ISODEP_FSX_1024 = 1024, /*!< Frame Size for Proximity Card with 1024 bytes ISO14443-3 Amd2 2012 */ 00165 RFAL_ISODEP_FSX_2048 = 2048, /*!< Frame Size for Proximity Card with 2048 bytes ISO14443-3 Amd2 2012 */ 00166 RFAL_ISODEP_FSX_4096 = 4096, /*!< Frame Size for Proximity Card with 4096 bytes ISO14443-3 Amd2 2012 */ 00167 } rfalIsoDepFSx ; 00168 00169 /* 00170 ****************************************************************************** 00171 * GLOBAL MACROS 00172 ****************************************************************************** 00173 */ 00174 00175 /* 00176 ****************************************************************************** 00177 * GLOBAL DATA TYPES 00178 ****************************************************************************** 00179 */ 00180 00181 /*! RATS format Digital 1.1 13.6.1 */ 00182 typedef struct 00183 { 00184 uint8_t CMD ; /*!< RATS command byte: 0xE0 */ 00185 uint8_t PARAM ; /*!< Param indicating FSDI and DID */ 00186 } rfalIsoDepRats ; 00187 00188 00189 /*! ATS response format Digital 1.1 13.6.2 */ 00190 typedef struct 00191 { 00192 uint8_t TL ; /*!< Length Byte, including TL byte itself */ 00193 uint8_t T0 ; /*!< Format Byte T0 indicating if TA, TB, TC */ 00194 uint8_t TA ; /*!< Interface Byte TA(1) */ 00195 uint8_t TB ; /*!< Interface Byte TB(1) */ 00196 uint8_t TC ; /*!< Interface Byte TC(1) */ 00197 uint8_t HB[RFAL_ISODEP_ATS_HB_MAX_LEN]; /*!< Historical Bytes */ 00198 } rfalIsoDepAts ; 00199 00200 00201 /*! PPS Request format (Protocol and Parameter Selection) ISO14443-4 5.3 */ 00202 typedef struct 00203 { 00204 uint8_t PPSS ; /*!< Start Byte: [ 1101b | CID[4b] ] */ 00205 uint8_t PPS0 ; /*!< Parameter 0:[ 000b | PPS1[1n] | 0001b ] */ 00206 uint8_t PPS1 ; /*!< Parameter 1:[ 0000b | DSI[2b] | DRI[2b] ]*/ 00207 } rfalIsoDepPpsReq ; 00208 00209 00210 /*! PPS Response format (Protocol and Parameter Selection) ISO14443-4 5.4 */ 00211 typedef struct 00212 { 00213 uint8_t PPSS ; /*!< Start Byte: [ 1101b | CID[4b] ] */ 00214 } rfalIsoDepPpsRes ; 00215 00216 00217 /*! ATTRIB Command Format Digital 1.1 15.6.1 */ 00218 typedef struct 00219 { 00220 uint8_t cmd ; /*!< ATTRIB_REQ command byte */ 00221 uint8_t nfcid0[RFAL_NFCB_NFCID0_LEN]; /*!< NFCID0 of the card to be selected */ 00222 struct{ 00223 uint8_t PARAM1 ; /*!< PARAM1 of ATTRIB command */ 00224 uint8_t PARAM2 ; /*!< PARAM2 of ATTRIB command */ 00225 uint8_t PARAM3 ; /*!< PARAM3 of ATTRIB command */ 00226 uint8_t PARAM4 ; /*!< PARAM4 of ATTRIB command */ 00227 }Param; /*!< Parameter of ATTRIB command */ 00228 uint8_t HLInfo[RFAL_ISODEP_ATTRIB_HLINFO_LEN]; /*!< Higher Layer Information */ 00229 } rfalIsoDepAttribCmd ; 00230 00231 00232 /*! ATTRIB Response Format Digital 1.1 15.6.2 */ 00233 typedef struct 00234 { 00235 uint8_t mbliDid ; /*!< Contains MBLI and DID */ 00236 uint8_t HLInfo[RFAL_ISODEP_ATTRIB_HLINFO_LEN]; /*!< Higher Layer Information */ 00237 } rfalIsoDepAttribRes ; 00238 00239 00240 /*! Activation info as Poller and Listener for NFC-A and NFC-B */ 00241 typedef union { 00242 00243 /*! NFC-A information */ 00244 union { 00245 struct { 00246 rfalIsoDepAts ATS ; /*!< ATS response (Poller mode) */ 00247 uint8_t ATSLen ; /*!< ATS response length (Poller mode) */ 00248 }Listener; 00249 struct { 00250 rfalIsoDepRats RATS ; /*!< RATS request (Listener mode) */ 00251 }Poller; 00252 }A; 00253 00254 /*! NFC-B information */ 00255 union { 00256 struct{ 00257 rfalIsoDepAttribRes ATTRIB_RES ; /*!< ATTRIB_RES (Poller mode) */ 00258 uint8_t ATTRIB_RESLen ; /*!< ATTRIB_RES length (Poller mode) */ 00259 }Listener; 00260 struct{ 00261 rfalIsoDepAttribCmd ATTRIB ; /*!< ATTRIB request (Listener mode) */ 00262 uint8_t ATTRIBLen ; /*!< ATTRIB request length (Listener mode) */ 00263 }Poller; 00264 }B; 00265 }rfalIsoDepActivation ; 00266 00267 00268 /*! ISO-DEP device Info */ 00269 typedef struct { 00270 uint8_t FWI ; /*!< Frame Waiting Integer */ 00271 uint32_t FWT ; /*!< Frame Waiting Time (1/fc) */ 00272 uint32_t dFWT ; /*!< Delta Frame Waiting Time (1/fc) */ 00273 uint32_t SFGI ; /*!< Start-up Frame Guard time Integer */ 00274 uint32_t SFGT ; /*!< Start-up Frame Guard Time (ms) */ 00275 uint8_t FSxI ; /*!< Frame Size Device/Card Integer (FSDI or FSCI) */ 00276 uint16_t FSx ; /*!< Frame Size Device/Card (FSD or FSC) */ 00277 uint32_t MBL ; /*!< Maximum Buffer Length (optional for NFC-B) */ 00278 rfalBitRate DSI ; /*!< Bit Rate coding from Listener (PICC) to Poller (PCD) */ 00279 rfalBitRate DRI ; /*!< Bit Rate coding from Poller (PCD) to Listener (PICC) */ 00280 uint8_t DID ; /*!< Device ID */ 00281 uint8_t NAD ; /*!< Node ADdress */ 00282 bool supDID ; /*!< DID supported flag */ 00283 bool supNAD ; /*!< NAD supported flag */ 00284 bool supAdFt ; /*!< Advanced Features supported flag */ 00285 } rfalIsoDepInfo ; 00286 00287 00288 /*! ISO-DEP Device structure */ 00289 typedef struct { 00290 rfalIsoDepActivation activation ; /*!< Activation Info */ 00291 rfalIsoDepInfo info ; /*!< ISO-DEP (ISO14443-4) device Info */ 00292 } rfalIsoDepDevice ; 00293 00294 00295 /*! ATTRIB Response parameters */ 00296 typedef struct 00297 { 00298 uint8_t mbli ; /*!< MBLI */ 00299 uint8_t HLInfo[RFAL_ISODEP_ATTRIB_HLINFO_LEN]; /*!< Hi Layer Information */ 00300 uint8_t HLInfoLen ; /*!< Hi Layer Information Length */ 00301 } rfalIsoDepAttribResParam ; 00302 00303 00304 /*! ATS Response parameter */ 00305 typedef struct 00306 { 00307 uint8_t fsci ; /*!< Frame Size of Proximity Card Integer */ 00308 uint8_t fwi ; /*!< Frame Waiting Time Integer */ 00309 uint8_t sfgi ; /*!< Start-Up Frame Guard Time Integer */ 00310 bool didSupport ; /*!< DID Supported */ 00311 uint8_t ta ; /*!< Max supported bitrate both direction */ 00312 uint8_t *hb ; /*!< Historical Bytes data */ 00313 uint8_t hbLen ; /*!< Historical Bytes Length */ 00314 } rfalIsoDepAtsParam ; 00315 00316 00317 /*! Structure of I-Block Buffer format from caller */ 00318 typedef struct 00319 { 00320 uint8_t prologue[RFAL_ISODEP_PROLOGUE_SIZE]; /*!< Prologue/SoD buffer */ 00321 uint8_t inf[RFAL_ISODEP_DEFAULT_FSC]; /*!< INF/Payload buffer */ 00322 } rfalIsoDepBufFormat ; 00323 00324 00325 /*! Structure of APDU Buffer format from caller */ 00326 typedef struct 00327 { 00328 uint8_t prologue[RFAL_ISODEP_PROLOGUE_SIZE]; /*!< Prologue/SoD buffer */ 00329 uint8_t apdu[RFAL_ISODEP_APDU_MAX_LEN]; /*!< APDU/Payload buffer */ 00330 } rfalIsoDepApduBufFormat ; 00331 00332 00333 /*! Listen Activation Parameters Structure */ 00334 typedef struct 00335 { 00336 rfalIsoDepBufFormat *rxBuf ; /*!< Receive Buffer struct reference */ 00337 uint16_t *rxLen ; /*!< Received INF data length in Bytes */ 00338 bool *isRxChaining ; /*!< Received data is not complete */ 00339 rfalIsoDepDevice *isoDepDev ; /*!< ISO-DEP device info */ 00340 } rfalIsoDepListenActvParam ; 00341 00342 00343 /*! Structure of parameters used on ISO DEP Transceive */ 00344 typedef struct 00345 { 00346 rfalIsoDepBufFormat *txBuf ; /*!< Transmit Buffer struct reference */ 00347 uint16_t txBufLen ; /*!< Transmit Buffer INF field length in Bytes*/ 00348 bool isTxChaining ; /*!< Transmit data is not complete */ 00349 rfalIsoDepBufFormat *rxBuf ; /*!< Receive Buffer struct reference in Bytes */ 00350 uint16_t *rxLen ; /*!< Received INF data length in Bytes */ 00351 bool *isRxChaining ; /*!< Received data is not complete */ 00352 uint32_t FWT ; /*!< FWT to be used (ignored in Listen Mode) */ 00353 uint32_t dFWT ; /*!< Delta FWT to be used */ 00354 uint16_t ourFSx ; /*!< Our device Frame Size (FSD or FSC) */ 00355 uint16_t FSx ; /*!< Other device Frame Size (FSD or FSC) */ 00356 uint8_t DID ; /*!< Device ID (RFAL_ISODEP_NO_DID if no DID) */ 00357 } rfalIsoDepTxRxParam ; 00358 00359 00360 /*! Structure of parameters used on ISO DEP APDU Transceive */ 00361 typedef struct 00362 { 00363 rfalIsoDepApduBufFormat *txBuf ; /*!< Transmit Buffer struct reference */ 00364 uint16_t txBufLen ; /*!< Transmit Buffer INF field length in Bytes*/ 00365 rfalIsoDepApduBufFormat *rxBuf ; /*!< Receive Buffer struct reference in Bytes */ 00366 uint16_t *rxLen ; /*!< Received INF data length in Bytes */ 00367 rfalIsoDepBufFormat *tmpBuf ; /*!< Temp buffer for Rx I-Blocks (internal) */ 00368 uint32_t FWT ; /*!< FWT to be used (ignored in Listen Mode) */ 00369 uint32_t dFWT ; /*!< Delta FWT to be used */ 00370 uint16_t FSx ; /*!< Other device Frame Size (FSD or FSC) */ 00371 uint16_t ourFSx ; /*!< Our device Frame Size (FSD or FSC) */ 00372 uint8_t DID ; /*!< Device ID (RFAL_ISODEP_NO_DID if no DID) */ 00373 } rfalIsoDepApduTxRxParam ; 00374 00375 /* 00376 ****************************************************************************** 00377 * GLOBAL FUNCTION PROTOTYPES 00378 ****************************************************************************** 00379 */ 00380 00381 00382 /*! 00383 ****************************************************************************** 00384 * \brief Initialize the ISO-DEP protocol 00385 * 00386 * Initialize the ISO-DEP protocol layer with default config 00387 ****************************************************************************** 00388 */ 00389 void rfalIsoDepInitialize( void ); 00390 00391 00392 /*! 00393 ****************************************************************************** 00394 * \brief Initialize the ISO-DEP protocol 00395 * 00396 * Initialize the ISO-DEP protocol layer with additional parameters allowing 00397 * to customise the protocol layer for specific behaviours 00398 * 00399 * \param[in] compMode : compliance mode to be performed 00400 * \param[in] maxRetriesR : Number of retries for a R-Block 00401 * \param[in] maxRetriesS : Number of retries for a S-Block 00402 * \param[in] maxRetriesI : Number of retries for a I-Block 00403 * \param[in] maxRetriesRATS : Number of retries for RATS 00404 * 00405 ****************************************************************************** 00406 */ 00407 void rfalIsoDepInitializeWithParams( rfalComplianceMode compMode, uint8_t maxRetriesR, uint8_t maxRetriesS, uint8_t maxRetriesI, uint8_t maxRetriesRATS ); 00408 00409 00410 /*! 00411 ***************************************************************************** 00412 * \brief FSxI to FSx 00413 * 00414 * Convert Frame Size for proximity coupling Device Integer (FSxI) to 00415 * Frame Size for proximity coupling Device (FSx) 00416 * 00417 * FSD - maximum frame size for NFC Forum Device in Poll Mode 00418 * FSC - maximum frame size for NFC Forum Device in Listen Mode 00419 * 00420 * FSxI = FSDI or FSCI 00421 * FSx = FSD or FSC 00422 * 00423 * The FSD/FSC value includes the header and CRC 00424 * 00425 * \param[in] fsxi : Frame Size for proximity coupling Device Integer 00426 * 00427 * \return fsx : Frame Size for proximity coupling Device (FSD or FSC) 00428 * 00429 ***************************************************************************** 00430 */ 00431 uint16_t rfalIsoDepFSxI2FSx( uint8_t fsxi ); 00432 00433 00434 /*! 00435 ***************************************************************************** 00436 * \brief FWI to FWT 00437 * 00438 * Convert Frame Waiting time Integer (FWI) to Frame Waiting Time (FWT) in 00439 * 1/fc units 00440 * 00441 * \param[in] fwi : Frame Waiting time Integer 00442 * 00443 * \return fwt : Frame Waiting Time in 1/fc units 00444 * 00445 ***************************************************************************** 00446 */ 00447 uint32_t rfalIsoDepFWI2FWT( uint8_t fwi ); 00448 00449 00450 /*! 00451 ***************************************************************************** 00452 * \brief Check if the buffer data contains a valid RATS command 00453 * 00454 * Check if it is a well formed RATS command with 2 bytes 00455 * This function does not check the validity of FSDI and DID 00456 * 00457 * \param[in] buf : reference to buffer containing the data to be checked 00458 * \param[in] bufLen : length of data in the buffer in bytes 00459 * 00460 * \return true if the data indicates a RATS command; false otherwise 00461 ***************************************************************************** 00462 */ 00463 bool rfalIsoDepIsRats( uint8_t *buf, uint8_t bufLen ); 00464 00465 00466 /*! 00467 ***************************************************************************** 00468 * \brief Check if the buffer data contains a valid ATTRIB command 00469 * 00470 * Check if it is a well formed ATTRIB command, but does not check the 00471 * validity of the information inside 00472 * 00473 * \param[in] buf : reference to buffer containing the data to be checked 00474 * \param[in] bufLen : length of data in the buffer in bytes 00475 * 00476 * \return true if the data indicates a ATTRIB command; false otherwise 00477 ***************************************************************************** 00478 */ 00479 bool rfalIsoDepIsAttrib( uint8_t *buf, uint8_t bufLen ); 00480 00481 00482 /*! 00483 ***************************************************************************** 00484 * \brief Start Listen Activation Handling 00485 * 00486 * Start Listen Activation Handling and setup to receive first I-block which may 00487 * contain complete or partial APDU after activation is completed 00488 * 00489 * Pass in RATS for T4AT, or ATTRIB for T4BT, to handle ATS or ATTRIB Response respectively 00490 * The Activation Handling handles ATS and ATTRIB Response; and additionally PPS Response 00491 * if a PPS is received for T4AT. 00492 * The method uses the current RFAL state machine to determine if it is expecting RATS or ATTRIB 00493 * 00494 * Activation is completed if PPS Response is sent or if first PDU is received in T4T-A 00495 * Activation is completed if ATTRIB Response is sent in T4T-B 00496 * 00497 * \ref rfalIsoDepListenGetActivationStatus provide status if activation is completed. 00498 * \ref rfalIsoDepStartTransceive shall be called right after activation is completed 00499 * 00500 * \param[in] atsParam : reference to ATS parameters 00501 * \param[in] attribResParam : reference to ATTRIB_RES parameters 00502 * \param[in] buf : reference to buffer containing RATS or ATTRIB 00503 * \param[in] bufLen : length in bytes of the given bufffer 00504 * \param[in] rxParam : reference to incoming reception information will be placed 00505 * 00506 * 00507 * \warning Once the Activation has been completed the method 00508 * rfalIsoDepGetTransceiveStatus() must be called. 00509 * If activation has completed due to reception of a data block (not PPS) the 00510 * buffer owned by the caller and passed on rxParam must still contain this data. 00511 * The first data will be processed (I-Block or S-DSL) by rfalIsoDepGetTransceiveStatus() 00512 * inform the caller and then for the next transaction use rfalIsoDepStartTransceive() 00513 * 00514 * \return ERR_NONE : RATS/ATTRIB is valid and activation has started 00515 * \return ERR_PARAM : Invalid parameters 00516 * \return ERR_PROTO : Invalid request 00517 * \return ERR_NOTSUPP : Feature not supported 00518 ***************************************************************************** 00519 */ 00520 ReturnCode rfalIsoDepListenStartActivation( rfalIsoDepAtsParam *atsParam, rfalIsoDepAttribResParam *attribResParam, uint8_t *buf, uint16_t bufLen, rfalIsoDepListenActvParam rxParam, SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 ); 00521 00522 00523 /*! 00524 ***************************************************************************** 00525 * \brief Get the current Activation Status 00526 * 00527 * \return ERR_NONE if Activation is already completed 00528 * \return ERR_BUSY if Activation is ongoing 00529 * \return ERR_LINK_LOSS if Remote Field is turned off 00530 ***************************************************************************** 00531 */ 00532 ReturnCode rfalIsoDepListenGetActivationStatus( SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 ); 00533 00534 00535 /*! 00536 ***************************************************************************** 00537 * \brief Get the ISO-DEP Communication Information 00538 * 00539 * Gets the maximum INF length in bytes based on current Frame Size 00540 * for proximity coupling Device (FSD or FSC) excluding the header and CRC 00541 * 00542 * \return maximum INF length in bytes 00543 ***************************************************************************** 00544 */ 00545 uint16_t rfalIsoDepGetMaxInfLen( void ); 00546 00547 00548 /*! 00549 ***************************************************************************** 00550 * \brief ISO-DEP Start Transceive 00551 * 00552 * This method triggers a ISO-DEP Transceive containing a complete or 00553 * partial APDU 00554 * It transmits the given message and handles all protocol retransmitions, 00555 * error handling and control messages 00556 * 00557 * The txBuf contains a complete or partial APDU (INF) to be transmitted 00558 * The Prologue field will be manipulated by the Transceive 00559 * 00560 * If the buffer contains a partial APDU and is not the last block, 00561 * then isTxChaining must be set to true 00562 * 00563 * \param[in] param: reference parameters to be used for the Transceive 00564 * 00565 * \return ERR_PARAM : Bad request 00566 * \return ERR_WRONG_STATE : The module is not in a proper state 00567 * \return ERR_NONE : The Transceive request has been started 00568 ***************************************************************************** 00569 */ 00570 ReturnCode rfalIsoDepStartTransceive( rfalIsoDepTxRxParam param ); 00571 00572 00573 /*! 00574 ***************************************************************************** 00575 * \brief Get the Transceive status 00576 * 00577 * Returns the status of the ISO-DEP Transceive 00578 * 00579 * \warning When the other device is performing chaining once a chained 00580 * block is received the error ERR_AGAIN is sent. At this point 00581 * caller must handle the received data immediately. 00582 * When ERR_AGAIN is returned an ACK has already been sent to 00583 * the other device and the next block might be incoming. 00584 * If rfalWorker() is called frequently it will place the next 00585 * block on the given buffer 00586 * 00587 * 00588 * \return ERR_NONE : Transceive has been completed successfully 00589 * \return ERR_BUSY : Transceive is ongoing 00590 * \return ERR_PROTO : Protocol error occurred 00591 * \return ERR_TIMEOUT : Timeout error occurred 00592 * \return ERR_SLEEP_REQ : Deselect has been received and responded 00593 * \return ERR_NOMEM : The received INF does not fit into the 00594 * receive buffer 00595 * \return ERR_LINK_LOSS : Communication is lost because Reader/Writer 00596 * has turned off its field 00597 * \return ERR_AGAIN : received one chaining block, continue to call 00598 * this method to retrieve the remaining blocks 00599 ***************************************************************************** 00600 */ 00601 ReturnCode rfalIsoDepGetTransceiveStatus( SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 ); 00602 00603 00604 /*! 00605 ***************************************************************************** 00606 * \brief ISO-DEP Start APDU Transceive 00607 * 00608 * This method triggers a ISO-DEP Transceive containing a complete APDU 00609 * It transmits the given message and handles all protocol retransmitions, 00610 * error handling and control messages 00611 * 00612 * The txBuf contains a complete APDU to be transmitted 00613 * The Prologue field will be manipulated by the Transceive 00614 * 00615 * \warning the txBuf will be modified during the transmission 00616 * \warning the maximum RF frame which can be received is limited by param.tmpBuf 00617 * 00618 * \param[in] param: reference parameters to be used for the Transceive 00619 * 00620 * \return ERR_PARAM : Bad request 00621 * \return ERR_WRONG_STATE : The module is not in a proper state 00622 * \return ERR_NONE : The Transceive request has been started 00623 ***************************************************************************** 00624 */ 00625 ReturnCode rfalIsoDepStartApduTransceive( rfalIsoDepApduTxRxParam param ); 00626 00627 00628 /*! 00629 ***************************************************************************** 00630 * \brief Get the APDU Transceive status 00631 * 00632 * \return ERR_NONE : if Transceive has been completed successfully 00633 * \return ERR_BUSY : if Transceive is ongoing 00634 * \return ERR_PROTO : if a protocol error occurred 00635 * \return ERR_TIMEOUT : if a timeout error occurred 00636 * \return ERR_SLEEP_REQ : if Deselect is received and responded 00637 * \return ERR_NOMEM : if the received INF does not fit into the 00638 * receive buffer 00639 * \return ERR_LINK_LOSS : if communication is lost because Reader/Writer 00640 * has turned off its field 00641 ***************************************************************************** 00642 */ 00643 ReturnCode rfalIsoDepGetApduTransceiveStatus( SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 ); 00644 00645 /*! 00646 ***************************************************************************** 00647 * \brief ISO-DEP Send RATS 00648 * 00649 * This sends a RATS to make a NFC-A Listen Device to enter 00650 * ISO-DEP layer (ISO14443-4) and checks if the received ATS is valid 00651 * 00652 * \param[in] FSDI : Frame Size Device Integer to be used 00653 * \param[in] DID : Device ID to be used or RFAL_ISODEP_NO_DID for not use DID 00654 * \param[out] ats : pointer to place the ATS Response 00655 * \param[out] atsLen : pointer to place the ATS length 00656 * 00657 * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode 00658 * \return ERR_PARAM : Invalid parameters 00659 * \return ERR_IO : Generic internal error 00660 * \return ERR_TIMEOUT : Timeout error 00661 * \return ERR_PAR : Parity error detected 00662 * \return ERR_CRC : CRC error detected 00663 * \return ERR_FRAMING : Framing error detected 00664 * \return ERR_PROTO : Protocol error detected 00665 * \return ERR_NONE : No error, ATS received 00666 ***************************************************************************** 00667 */ 00668 ReturnCode rfalIsoDepRATS( rfalIsoDepFSxI FSDI, uint8_t DID, rfalIsoDepAts *ats , uint8_t *atsLen, SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 ); 00669 00670 00671 /*! 00672 ***************************************************************************** 00673 * \brief ISO-DEP Send PPS 00674 * 00675 * This sends a PPS to make a NFC-A Listen Device change the communications 00676 * bit rate from 106kbps to one of the supported bit rates 00677 * Additionally checks if the received PPS response is valid 00678 * 00679 * \param[in] DID : Device ID 00680 * \param[in] DSI : DSI code the divisor from Listener (PICC) to Poller (PCD) 00681 * \param[in] DRI : DRI code the divisor from Poller (PCD) to Listener (PICC) 00682 * \param[out] ppsRes : pointer to place the PPS Response 00683 * 00684 * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode 00685 * \return ERR_PARAM : Invalid parameters 00686 * \return ERR_IO : Generic internal error 00687 * \return ERR_TIMEOUT : Timeout error 00688 * \return ERR_PAR : Parity error detected 00689 * \return ERR_CRC : CRC error detected 00690 * \return ERR_FRAMING : Framing error detected 00691 * \return ERR_PROTO : Protocol error detected 00692 * \return ERR_NONE : No error, PPS Response received 00693 ***************************************************************************** 00694 */ 00695 ReturnCode rfalIsoDepPPS( uint8_t DID, rfalBitRate DSI, rfalBitRate DRI, rfalIsoDepPpsRes *ppsRes, SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 ); 00696 00697 00698 /*! 00699 ***************************************************************************** 00700 * \brief ISO-DEP Send ATTRIB 00701 * 00702 * This sends a ATTRIB to make a NFC-B Listen Device to enter 00703 * ISO-DEP layer (ISO14443-4) and checks if the received ATTRIB Response is valid 00704 * 00705 * \param[in] nfcid0 : NFCID0 to be used for the ATTRIB 00706 * \param[in] PARAM1 : ATTRIB PARAM1 byte (communication parameters) 00707 * \param[in] DSI : DSI code the divisor from Listener (PICC) to Poller (PCD) 00708 * \param[in] DRI : DRI code the divisor from Poller (PCD) to Listener (PICC) 00709 * \param[in] FSDI : PCD's Frame Size to be announced on the ATTRIB 00710 * \param[in] PARAM3 : ATTRIB PARAM1 byte (protocol type) 00711 * \param[in] DID : Device ID to be used or RFAL_ISODEP_NO_DID for not use DID 00712 * \param[in] HLInfo : pointer to Higher layer INF (NULL if none) 00713 * \param[in] HLInfoLen : Length HLInfo 00714 * \param[in] fwt : Frame Waiting Time to be used (from SENSB_RES) 00715 * \param[out] attribRes : pointer to place the ATTRIB Response 00716 * \param[out] attribResLen : pointer to place the ATTRIB Response length 00717 * 00718 * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode 00719 * \return ERR_PARAM : Invalid parameters 00720 * \return ERR_IO : Generic internal error 00721 * \return ERR_TIMEOUT : Timeout error 00722 * \return ERR_CRC : CRC error detected 00723 * \return ERR_FRAMING : Framing error detected 00724 * \return ERR_PROTO : Protocol error detected 00725 * \return ERR_NONE : No error, ATTRIB Response received 00726 ***************************************************************************** 00727 */ 00728 ReturnCode rfalIsoDepATTRIB( uint8_t* nfcid0, uint8_t PARAM1, rfalBitRate DSI, rfalBitRate DRI, rfalIsoDepFSxI FSDI, uint8_t PARAM3, uint8_t DID, uint8_t* HLInfo, uint8_t HLInfoLen, uint32_t fwt, rfalIsoDepAttribRes *attribRes, uint8_t *attribResLen, SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 ); 00729 00730 00731 /*! 00732 ***************************************************************************** 00733 * \brief Deselects PICC 00734 * 00735 * This function sends a deselect command to PICC and waits for it`s 00736 * responce in a blocking way 00737 * 00738 * \return ERR_NONE : Deselect successfully sent and acknowledged by PICC 00739 * \return ERR_TIMEOUT: No response rcvd from PICC 00740 * 00741 ***************************************************************************** 00742 */ 00743 ReturnCode rfalIsoDepDeselect( SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 ); 00744 00745 /*! 00746 ***************************************************************************** 00747 * \brief ISO-DEP Poller Handle NFC-A Activation 00748 * 00749 * This performs a NFC-A Activation into ISO-DEP layer (ISO14443-4) with the given 00750 * parameters. It sends RATS and if the higher bit rates are supported by 00751 * both devices it additionally sends PPS 00752 * Once Activated all details of the device are provided on isoDepDev 00753 * 00754 * \param[in] FSDI : Frame Size Device Integer to be used 00755 * \param[in] DID : Device ID to be used or RFAL_ISODEP_NO_DID for not use DID 00756 * \param[in] maxBR : Max bit rate supported by the Poller 00757 * \param[out] isoDepDev : ISO-DEP information of the activated Listen device 00758 * 00759 * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode 00760 * \return ERR_PARAM : Invalid parameters 00761 * \return ERR_IO : Generic internal error 00762 * \return ERR_TIMEOUT : Timeout error 00763 * \return ERR_PAR : Parity error detected 00764 * \return ERR_CRC : CRC error detected 00765 * \return ERR_FRAMING : Framing error detected 00766 * \return ERR_PROTO : Protocol error detected 00767 * \return ERR_NONE : No error, activation successful 00768 ***************************************************************************** 00769 */ 00770 ReturnCode rfalIsoDepPollAHandleActivation( rfalIsoDepFSxI FSDI, uint8_t DID, rfalBitRate maxBR, rfalIsoDepDevice *isoDepDev, SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 ); 00771 00772 00773 /*! 00774 ***************************************************************************** 00775 * \brief ISO-DEP Poller Handle NFC-B Activation 00776 * 00777 * This performs a NFC-B Activation into ISO-DEP layer (ISO14443-4) with the given 00778 * parameters. It sends ATTRIB and calculates supported higher bit rates of both 00779 * devices and performs activation. 00780 * Once Activated all details of the device are provided on isoDepDev 00781 * 00782 * \param[in] FSDI : Frame Size Device Integer to be used 00783 * \param[in] DID : Device ID to be used or RFAL_ISODEP_NO_DID for not use DID 00784 * \param[in] maxBR : Max bit rate supported by the Poller 00785 * \param[in] PARAM1 : ATTRIB PARAM1 byte (communication parameters) 00786 * \param[in] nfcbDev : pointer to the NFC-B Device containing the SENSB_RES 00787 * \param[in] HLInfo : pointer to Higher layer INF (NULL if none) 00788 * \param[in] HLInfoLen : Length HLInfo 00789 * \param[out] isoDepDev : ISO-DEP information of the activated Listen device 00790 * 00791 * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode 00792 * \return ERR_PARAM : Invalid parameters 00793 * \return ERR_IO : Generic internal error 00794 * \return ERR_TIMEOUT : Timeout error 00795 * \return ERR_PAR : Parity error detected 00796 * \return ERR_CRC : CRC error detected 00797 * \return ERR_FRAMING : Framing error detected 00798 * \return ERR_PROTO : Protocol error detected 00799 * \return ERR_NONE : No error, activation successful 00800 ***************************************************************************** 00801 */ 00802 ReturnCode rfalIsoDepPollBHandleActivation( rfalIsoDepFSxI FSDI, uint8_t DID, rfalBitRate maxBR, uint8_t PARAM1, rfalNfcbListenDevice *nfcbDev, uint8_t* HLInfo, uint8_t HLInfoLen, rfalIsoDepDevice *isoDepDev, SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 ); 00803 00804 00805 #endif /* RFAL_ISODEP_H_ */ 00806 00807 /** 00808 * @} 00809 * 00810 * @} 00811 * 00812 * @} 00813 */
Generated on Sat Jul 16 2022 13:00:53 by
