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_nfca.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 * PROJECT: ST25R391x firmware 00025 * $Revision: $ 00026 * LANGUAGE: ISO C99 00027 */ 00028 00029 /*! \file rfal_nfca.h 00030 * 00031 * \author Gustavo Patricio 00032 * 00033 * \brief Provides several NFC-A convenience methods and definitions 00034 * 00035 * It provides a Poller (ISO14443A PCD) interface and as well as 00036 * some NFC-A Listener (ISO14443A PICC) helpers. 00037 * 00038 * The definitions and helpers methods provided by this module are only 00039 * up to ISO14443-3 layer 00040 * 00041 * @addtogroup RFAL 00042 * @{ 00043 * 00044 * @addtogroup RFAL-AL 00045 * @brief RFAL Abstraction Layer 00046 * @{ 00047 * 00048 * @addtogroup NFC-A 00049 * @brief RFAL NFC-A Module 00050 * @{ 00051 * 00052 */ 00053 00054 00055 #ifndef RFAL_NFCA_H 00056 #define RFAL_NFCA_H 00057 00058 /* 00059 ****************************************************************************** 00060 * INCLUDES 00061 ****************************************************************************** 00062 */ 00063 #include "platform1.h" 00064 #include "st_errno.h" 00065 #include "rfal_rf.h" 00066 #include "rfal_t1t.h" 00067 00068 /* 00069 ****************************************************************************** 00070 * GLOBAL DEFINES 00071 ****************************************************************************** 00072 */ 00073 00074 #define RFAL_NFCA_CASCADE_1_UID_LEN 4 /*!< UID length of cascade level 1 only tag */ 00075 #define RFAL_NFCA_CASCADE_2_UID_LEN 7 /*!< UID length of cascade level 2 only tag */ 00076 #define RFAL_NFCA_CASCADE_3_UID_LEN 10 /*!< UID length of cascade level 3 only tag */ 00077 00078 #define RFAL_NFCA_SENS_RES_PLATFORM_MASK 0x0F /*!< SENS_RES (ATQA) platform configuration mask Digital 1.1 Table 10 */ 00079 #define RFAL_NFCA_SENS_RES_PLATFORM_T1T 0x0C /*!< SENS_RES (ATQA) T1T platform configuration Digital 1.1 Table 10 */ 00080 00081 #define RFAL_NFCA_SEL_RES_CONF_MASK 0x60 /*!< SEL_RES (SAK) platform configuration mask Digital 1.1 Table 19 */ 00082 #define RFAL_NFCA_SEL_RES_CONF_T2T 0x00 /*!< SEL_RES (SAK) T2T configuration Digital 1.1 Table 19 */ 00083 #define RFAL_NFCA_SEL_RES_CONF_T4T 0x20 /*!< SEL_RES (SAK) T4T configuration Digital 1.1 Table 19 */ 00084 #define RFAL_NFCA_SEL_RES_CONF_NFCDEP 0x40 /*!< SEL_RES (SAK) NFC-DEP configuration Digital 1.1 Table 19 */ 00085 #define RFAL_NFCA_SEL_RES_CONF_T4T_NFCDEP 0x60 /*!< SEL_RES (SAK) T4T and NFC-DEP configuration Digital 1.1 Table 19 */ 00086 00087 00088 /*! NFC-A minimum FDT(listen) = ((n * 128 + (84)) / fc) with n_min = 9 Digital 1.1 6.10.1 00089 * = (1236)/fc 00090 * Relax with 3etu: (3*128)/fc as with multiple NFC-A cards, response may take longer (JCOP cards) 00091 * = (1236 + 384)/fc = 1620 / fc */ 00092 #define RFAL_NFCA_FDTMIN 1620 00093 /* 00094 ****************************************************************************** 00095 * GLOBAL MACROS 00096 ****************************************************************************** 00097 */ 00098 00099 /*! Checks if device is a T1T given its SENS_RES */ 00100 #define rfalNfcaIsSensResT1T( sensRes ) ((((rfalNfcaSensRes*)sensRes)->platformInfo & RFAL_NFCA_SENS_RES_PLATFORM_MASK) == RFAL_NFCA_SENS_RES_PLATFORM_T1T ) 00101 00102 /*! Checks if device is a T2T given its SENS_RES */ 00103 #define rfalNfcaIsSelResT2T( selRes ) ((((rfalNfcaSelRes*)selRes)->sak & RFAL_NFCA_SEL_RES_CONF_MASK) == RFAL_NFCA_SEL_RES_CONF_T2T ) 00104 00105 /*! Checks if device is a T4T given its SENS_RES */ 00106 #define rfalNfcaIsSelResT4T( selRes ) ((((rfalNfcaSelRes*)selRes)->sak & RFAL_NFCA_SEL_RES_CONF_MASK) == RFAL_NFCA_SEL_RES_CONF_T4T ) 00107 00108 /*! Checks if device supports NFC-DEP protocol given its SENS_RES */ 00109 #define rfalNfcaIsSelResNFCDEP( selRes ) ((((rfalNfcaSelRes*)selRes)->sak & RFAL_NFCA_SEL_RES_CONF_MASK) == RFAL_NFCA_SEL_RES_CONF_NFCDEP ) 00110 00111 /*! Checks if device supports ISO-DEP and NFC-DEP protocol given its SENS_RES */ 00112 #define rfalNfcaIsSelResT4TNFCDEP( selRes ) ((((rfalNfcaSelRes*)selRes)->sak & RFAL_NFCA_SEL_RES_CONF_MASK) == RFAL_NFCA_SEL_RES_CONF_T4T_NFCDEP ) 00113 00114 /*! Checks if a NFC-A listener device supports multiple protocols (ISO-DEP and NFC-DEP) */ 00115 #define rfalNfcaLisDevIsMultiProto( lisDev ) (((rfalNfcaListenDevice*)lisDev)->type == RFAL_NFCA_T4T_NFCDEP ) 00116 00117 /* 00118 ****************************************************************************** 00119 * GLOBAL TYPES 00120 ****************************************************************************** 00121 */ 00122 00123 /*! NFC-A Listen device types */ 00124 typedef enum { 00125 RFAL_NFCA_T1T = 0x01, /* Device configured for T1T Digital 1.1 Table 9 */ 00126 RFAL_NFCA_T2T = 0x00, /* Device configured for T2T Digital 1.1 Table 19 */ 00127 RFAL_NFCA_T4T = 0x20, /* Device configured for T4T Digital 1.1 Table 19 */ 00128 RFAL_NFCA_NFCDEP = 0x40, /* Device configured for NFC-DEP Digital 1.1 Table 19 */ 00129 RFAL_NFCA_T4T_NFCDEP = 0x60 /* Device configured for NFC-DEP and T4T Digital 1.1 Table 19 */ 00130 } rfalNfcaListenDeviceType ; 00131 00132 00133 /*! SENS_RES (ATQA) format Digital 1.1 6.6.3 & Table 7 */ 00134 typedef struct 00135 { 00136 uint8_t anticollisionInfo ; /*!< SENS_RES Anticollision Information */ 00137 uint8_t platformInfo ; /*!< SENS_RES Platform Information */ 00138 } rfalNfcaSensRes ; 00139 00140 00141 /*! SDD_REQ (Anticollision) format Digital 1.1 6.7.1 & Table 11 */ 00142 typedef struct 00143 { 00144 uint8_t selCmd ; /*!< SDD_REQ SEL_CMD: cascade Level */ 00145 uint8_t selPar ; /*!< SDD_REQ SEL_PAR: Byte Count[4b] | Bit Count[4b] (NVB: Number of Valid Bits)*/ 00146 } rfalNfcaSddReq ; 00147 00148 00149 /*! SDD_RES (UID CLn) format Digital 1.1 6.7.2 & Table 15 */ 00150 typedef struct 00151 { 00152 uint8_t nfcid1[RFAL_NFCA_CASCADE_1_UID_LEN]; /*!< NFCID1 cascade level NFCID */ 00153 uint8_t bcc ; /*!< BCC Exclusive-OR over first 4 bytes of SDD_RES */ 00154 } rfalNfcaSddRes ; 00155 00156 00157 /*! SEL_REQ (Select) format Digital 1.1 6.8.1 & Table 17 */ 00158 typedef struct 00159 { 00160 uint8_t selCmd ; /*!< SDD_REQ SEL_CMD: cascade Level */ 00161 uint8_t selPar ; /*!< SDD_REQ SEL_PAR: Byte Count[4b] | Bit Count[4b] (NVB: Number of Valid Bits)*/ 00162 uint8_t nfcid1[RFAL_NFCA_CASCADE_1_UID_LEN]; /*!< NFCID1 data */ 00163 uint8_t bcc ; /*!< Checksum calculated as exclusive-OR over the 4 bytes of NFCID1 CLn */ 00164 } rfalNfcaSelReq ; 00165 00166 00167 /*! SEL_RES (SAK) format Digital 1.1 6.8.2 & Table 19 */ 00168 typedef struct 00169 { 00170 uint8_t sak ; /*!< Select Acknowledge */ 00171 } rfalNfcaSelRes ; 00172 00173 00174 /*! NFC-A listener device (PICC) struct */ 00175 typedef struct 00176 { 00177 rfalNfcaListenDeviceType type ; /*!< NFC-A Listen device type */ 00178 rfalNfcaSensRes sensRes ; /*!< SENS_RES (ATQA) */ 00179 rfalNfcaSelRes selRes ; /*!< SEL_RES (SAK) */ 00180 uint8_t nfcId1Len ; /*!< NFCID1 Length */ 00181 uint8_t nfcId1[RFAL_NFCA_CASCADE_3_UID_LEN]; /*!< NFCID1 (UID) */ 00182 #ifdef RFAL_FEATURE_T1T 00183 rfalT1TRidRes ridRes ; /*!< RID_RES */ 00184 #endif /* RFAL_FEATURE_T1T */ 00185 bool isSleep ; /*!< Device sleeping flag */ 00186 } rfalNfcaListenDevice ; 00187 00188 /* 00189 ****************************************************************************** 00190 * GLOBAL FUNCTION PROTOTYPES 00191 ****************************************************************************** 00192 */ 00193 00194 /*! 00195 ***************************************************************************** 00196 * \brief Initialize NFC-A Poller mode 00197 * 00198 * This methods configures RFAL RF layer to perform as a 00199 * NFC-A Poller/RW (ISO14443A PCD) including all default timings and bit rate 00200 * to 106 kbps 00201 00202 * 00203 * \return ERR_WRONG_STATE : RFAL not initialized or mode not set 00204 * \return ERR_NONE : No error 00205 ***************************************************************************** 00206 */ 00207 ReturnCode rfalNfcaPollerInitialize( 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 ); 00208 00209 00210 /*! 00211 ***************************************************************************** 00212 * \brief NFC-A Poller Check Presence 00213 * 00214 * This method checks if a NFC-A Listen device (PICC) is present on the field 00215 * by sending an ALL_REQ (WUPA) or SENS_REQ (REQA) 00216 * 00217 * \param[in] cmd : Indicate if to send an ALL_REQ or a SENS_REQ 00218 * \param[out] sensRes : If received, the SENS_RES 00219 * 00220 * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode 00221 * \return ERR_PARAM : Invalid parameters 00222 * \return ERR_IO : Generic internal error 00223 * \return ERR_RF_COLLISION : Collision detected one or more device in the field 00224 * \return ERR_PAR : Parity error detected, one or more device in the field 00225 * \return ERR_CRC : CRC error detected, one or more device in the field 00226 * \return ERR_FRAMING : Framing error detected, one or more device in the field 00227 * \return ERR_PROTO : Protocol error detected, one or more device in the field 00228 * \return ERR_TIMEOUT : Timeout error, no listener device detected 00229 * \return ERR_NONE : No error, one or more device in the field 00230 ***************************************************************************** 00231 */ 00232 ReturnCode rfalNfcaPollerCheckPresence( rfal14443AShortFrameCmd cmd, rfalNfcaSensRes *sensRes, 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 ); 00233 00234 00235 /*! 00236 ***************************************************************************** 00237 * \brief NFC-A Poller Select 00238 * 00239 * This method selects a NFC-A Listener device (PICC) 00240 * 00241 * \param[in] nfcid1 : Listener device NFCID1 to be selected 00242 * \param[in] nfcidLen : Length of the NFCID1 to be selected 00243 * \param[out] selRes : pointer to place the SEL_RES 00244 * 00245 * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode 00246 * \return ERR_PARAM : Invalid parameters 00247 * \return ERR_IO : Generic internal error 00248 * \return ERR_TIMEOUT : Timeout error 00249 * \return ERR_PAR : Parity error detected 00250 * \return ERR_CRC : CRC error detected 00251 * \return ERR_FRAMING : Framing error detected 00252 * \return ERR_PROTO : Protocol error detected 00253 * \return ERR_NONE : No error, SEL_RES received 00254 ***************************************************************************** 00255 */ 00256 ReturnCode rfalNfcaPollerSelect( uint8_t *nfcid1, uint8_t nfcidLen, rfalNfcaSelRes *selRes, 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 ); 00257 00258 00259 /*! 00260 ***************************************************************************** 00261 * \brief NFC-A Poller Sleep 00262 * 00263 * This method sends a SLP_REQ (HLTA) 00264 * No response is expected afterwards Digital 1.1 6.9.2.1 00265 * 00266 * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode 00267 * \return ERR_PARAM : Invalid parameters 00268 * \return ERR_IO : Generic internal error 00269 * \return ERR_NONE : No error 00270 ***************************************************************************** 00271 */ 00272 ReturnCode rfalNfcaPollerSleep( 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 ); 00273 00274 00275 /*! 00276 ***************************************************************************** 00277 * \brief NFC-A Technology Detection 00278 * 00279 * This method performs NFC-A Technology Detection as defined in the spec 00280 * given in the compliance mode 00281 * 00282 * \param[in] compMode : compliance mode to be performed 00283 * \param[out] sensRes : location to store the SENS_RES, if received 00284 * 00285 * When compMode is set to ISO compliance a SLP_REQ (HLTA) is not sent 00286 * after detection. When set to EMV a ALL_REQ (WUPA) is sent instead of 00287 * a SENS_REQ (REQA) 00288 * 00289 * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode 00290 * \return ERR_PARAM : Invalid parameters 00291 * \return ERR_IO : Generic internal error 00292 * \return ERR_NONE : No error, one or more device in the field 00293 ***************************************************************************** 00294 */ 00295 ReturnCode rfalNfcaPollerTechnologyDetection( rfalComplianceMode compMode, rfalNfcaSensRes *sensRes, 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 ); 00296 00297 00298 /*! 00299 ***************************************************************************** 00300 * \brief NFC-A Poller Collision Resolution 00301 * 00302 * Collision resolution for one NFC-A Listener device/card (PICC) as 00303 * defined in Activity 1.1 9.3.4 00304 * 00305 * This method executes anti collision loop and select the device with higher NFCID1 00306 * 00307 * When devLimit = 0 it is configured to perform collision detection only. Once a collision 00308 * is detected the collision resolution is aborted immidiatly. If only one device is found 00309 * with no collisions, it will properly resolved. 00310 * 00311 * \param[in] devLimit : device limit value (CON_DEVICES_LIMIT) 00312 * \param[out] collPending : pointer to collision pending flag (INT_COLL_PEND) 00313 * \param[out] selRes : location to store the last Select Response from listener device (PICC) 00314 * \param[out] nfcId1 : location to store the NFCID1 (UID), ensure RFAL_NFCA_CASCADE_3_UID_LEN 00315 * \param[out] nfcId1Len : pointer to length of NFCID1 (UID) 00316 * 00317 * \return ERR_WRONG_STATE : RFAL not initialized or mode not set 00318 * \return ERR_PARAM : Invalid parameters 00319 * \return ERR_IO : Generic internal error 00320 * \return ERR_PROTO : Card length invalid 00321 * \return ERR_IGNORE : conDevLimit is 0 and there is a collision 00322 * \return ERR_NONE : No error 00323 ***************************************************************************** 00324 */ 00325 ReturnCode rfalNfcaPollerSingleCollisionResolution( uint8_t devLimit, bool *collPending, rfalNfcaSelRes *selRes, uint8_t *nfcId1, uint8_t *nfcId1Len, 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 ); 00326 00327 00328 /*! 00329 ***************************************************************************** 00330 * \brief NFC-A Poller Full Collision Resolution 00331 * 00332 * Performs a full Collision resolution as defined in Activity 1.0 or 1.1 9.3.4 00333 * 00334 * \param[in] compMode : compliance mode to be performed 00335 * \param[in] devLimit : device limit value, and size nfcaDevList 00336 * \param[out] nfcaDevList : NFC-A listener device info 00337 * \param[out] devCnt : Devices found counter 00338 * 00339 * When compMode is set to ISO compliance it assumes that the device is 00340 * not sleeping and therefore no ALL_REQ (WUPA) is sent at the beginning. 00341 * 00342 * When compMode is set to NFC compliance an additional ALL_REQ (WUPA) is sent at 00343 * the beginning and a proprietary behaviour also takes place. Once a device has been 00344 * resolved an additional SLP_REQ (HLTA) is sent regardless if there was a collision 00345 * (except if the number of devices found already equals the limit). 00346 * This proprietary behaviour ensures proper activation of certain devices that suffer 00347 * from influence of Type B commands as foreseen in ISO14443-3 5.2.3 00348 * 00349 * 00350 * When devLimit = 0 it is configured to perform collision detection only. Once a collision 00351 * is detected the collision resolution is aborted immidiatly. If only one device is found 00352 * with no collisions, it will properly resolved. 00353 * 00354 * 00355 * \return ERR_WRONG_STATE : RFAL not initialized or mode not set 00356 * \return ERR_PARAM : Invalid parameters 00357 * \return ERR_IO : Generic internal error 00358 * \return ERR_NONE : No error 00359 ***************************************************************************** 00360 */ 00361 ReturnCode rfalNfcaPollerFullCollisionResolution( rfalComplianceMode compMode, uint8_t devLimit, rfalNfcaListenDevice *nfcaDevList, uint8_t *devCnt, 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 ); 00362 00363 00364 /*! 00365 ***************************************************************************** 00366 * \brief NFC-A Listener is SLP_REQ 00367 * 00368 * Checks if the given buffer contains valid NFC-A SLP_REQ (HALT) 00369 * 00370 * \param[in] buf: buffer containing data 00371 * \param[in] bufLen: length of the data in buffer to be checked 00372 * 00373 * \return true if data in buf contains a SLP_REQ ; false otherwise 00374 ***************************************************************************** 00375 */ 00376 bool rfalNfcaListenerIsSleepReq( uint8_t *buf, uint16_t bufLen ); 00377 00378 #endif /* RFAL_NFCA_H */ 00379 00380 /** 00381 * @} 00382 * 00383 * @} 00384 * 00385 * @} 00386 */
Generated on Sat Jul 16 2022 13:00:53 by
1.7.2