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_nfcb.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_nfcb.h 00030 * 00031 * \author Gustavo Patricio 00032 * 00033 * \brief Implementation of NFC-B (ISO14443B) helpers 00034 * 00035 * It provides a NFC-B Poller (ISO14443B PCD) interface and 00036 * also provides some NFC-B Listener (ISO14443B PICC) helpers 00037 * 00038 * The definitions and helpers methods provided by this module are only 00039 * up to ISO14443-3 layer (excluding ATTRIB) 00040 * 00041 * 00042 * @addtogroup RFAL 00043 * @{ 00044 * 00045 * @addtogroup RFAL-AL 00046 * @brief RFAL Abstraction Layer 00047 * @{ 00048 * 00049 * @addtogroup NFC-B 00050 * @brief RFAL NFC-B Module 00051 * @{ 00052 * 00053 */ 00054 00055 00056 #ifndef RFAL_NFCB_H 00057 #define RFAL_NFCB_H 00058 00059 /* 00060 ****************************************************************************** 00061 * INCLUDES 00062 ****************************************************************************** 00063 */ 00064 #include "platform1.h" 00065 #include "st_errno.h" 00066 #include "rfal_rf.h" 00067 00068 /* 00069 ****************************************************************************** 00070 * GLOBAL DEFINES 00071 ****************************************************************************** 00072 */ 00073 00074 #define RFAL_NFCB_FWTSENSB 7680 /*!< NFC-B FWT(SENSB) Digital 1.1 A.3 */ 00075 #define RFAL_NFCB_DTPOLL 49152 /*!< NFC-B Delta Tb Poll Digital 1.1 A.3 */ 00076 #define RFAL_NFCB_DFWT_11 rfalConvMsTo1fc(17) /*!< NFC-B dFWT (16.4ms) Digital 1.1 A.3 */ 00077 #define RFAL_NFCB_DFWT_10 rfalConvMsTo1fc(20) /*!< NFC-B dFWT (20ms) Digital 1.0 A.2 */ 00078 00079 #define RFAL_NFCB_AFI 0x00 /*!< NFC-B default Application Family Digital 1.1 7.6.1.1 */ 00080 #define RFAL_NFCB_PARAM 0x00 /*!< NFC-B default SENSB_REQ PARAM */ 00081 #define RFAL_NFCB_CRC_LEN 2 /*!< NFC-B CRC length and CRC_B(AID) Digital 1.1 Table 28 */ 00082 #define RFAL_NFCB_NFCID0_LEN 4 /*!< Length of NFC-B NFCID0 */ 00083 #define RFAL_NFCB_CMD_LEN 1 /*!< Length of NFC-B Command */ 00084 00085 #define RFAL_NFCB_SENSB_RES_LEN 12 /*!< Standard length of SENSB_RES without SFGI byte */ 00086 #define RFAL_NFCB_SENSB_RES_EXT_LEN 13 /*!< Extended length of SENSB_RES with SFGI byte */ 00087 00088 #define RFAL_NFCB_SENSB_REQ_ADV_FEATURE 0x20 /*!< Bit mask for Advance Feature in SENSB_REQ */ 00089 #define RFAL_NFCB_SENSB_RES_FSCI_MASK 0x0F /*!< Bit mask for FSCI value in SENSB_RES */ 00090 #define RFAL_NFCB_SENSB_RES_FSCI_SHIFT 4 /*!< Shift for FSCI value in SENSB_RES */ 00091 #define RFAL_NFCB_SENSB_RES_PROTO_RFU_MASK 0x08 /*!< Bit mask for Protocol Type RFU in SENSB_RES */ 00092 #define RFAL_NFCB_SENSB_RES_PROTO_TR2_MASK 0x03 /*!< Bit mask for Protocol Type TR2 in SENSB_RES */ 00093 #define RFAL_NFCB_SENSB_RES_PROTO_TR2_SHIFT 1 /*!< Shift for Protocol Type TR2 in SENSB_RES */ 00094 #define RFAL_NFCB_SENSB_RES_PROTO_ISO_MASK 0x01 /*!< Bit mask Protocol Type ISO14443 Compliant in SENSB_RES */ 00095 #define RFAL_NFCB_SENSB_RES_FWI_MASK 0x0F /*!< Bit mask for FWI value in SENSB_RES */ 00096 #define RFAL_NFCB_SENSB_RES_FWI_SHIFT 4 /*!< Bit mask for FWI value in SENSB_RES */ 00097 #define RFAL_NFCB_SENSB_RES_ADC_MASK 0x0C /*!< Bit mask for ADC value in SENSB_RES */ 00098 #define RFAL_NFCB_SENSB_RES_ADC_ADV_FEATURE_MASK 0x08 /*!< Bit mask for ADC.Advanced Proto Features in SENSB_RES */ 00099 #define RFAL_NFCB_SENSB_RES_ADC_PROPRIETARY_MASK 0x04 /*!< Bit mask for ADC.Proprietary Application in SENSB_RES */ 00100 #define RFAL_NFCB_SENSB_RES_FO_DID_MASK 0x01 /*!< Bit mask for DID in SENSB_RES */ 00101 #define RFAL_NFCB_SENSB_RES_FO_NAD_MASK 0x02 /*!< Bit mask for DID in SENSB_RES */ 00102 #define RFAL_NFCB_SENSB_RES_FO_MASK 0x03 /*!< Bit mask for FO value in SENSB_RES (NAD and DID) */ 00103 #define RFAL_NFCB_SENSB_RES_SFGI_MASK 0x0F /*!< Bit mask for SFGI in SENSB_RES */ 00104 #define RFAL_NFCB_SENSB_RES_SFGI_SHIFT 4 /*!< Shift for SFGI in SENSB_RES */ 00105 00106 /* 00107 ****************************************************************************** 00108 * GLOBAL MACROS 00109 ****************************************************************************** 00110 */ 00111 00112 /*! Get device's FSCI given its SENSB_RES Digital 1.1 7.6.2 */ 00113 #define rfalNfcbGetFSCI( sensbRes ) ((((rfalNfcbSensbRes*)sensbRes)->protInfo.FsciProType >> RFAL_NFCB_SENSB_RES_FSCI_SHIFT) & RFAL_NFCB_SENSB_RES_FSCI_MASK ) 00114 00115 /* 00116 ****************************************************************************** 00117 * GLOBAL TYPES 00118 ****************************************************************************** 00119 */ 00120 00121 /*! SENSB_REQ and ALLB_REQ param Digital 1.1 7.6.1 */ 00122 typedef enum 00123 { 00124 RFAL_NFCB_SENS_CMD_ALLB_REQ = 0x08, /*!< ALLB_REQ (WUPB) */ 00125 RFAL_NFCB_SENS_CMD_SENSB_REQ = 0x00 /*!< SENSB_REQ (REQB) */ 00126 } rfalNfcbSensCmd ; 00127 00128 00129 /*! Number of Slots (NI) codes used for NFC-B anti collision Digital 1.1 Table 26 */ 00130 typedef enum 00131 { 00132 RFAL_NFCB_SLOT_NUM_1 = 0, /*!< N=0 : 1 slot */ 00133 RFAL_NFCB_SLOT_NUM_2 = 1, /*!< N=1 : 2 slots */ 00134 RFAL_NFCB_SLOT_NUM_4 = 2, /*!< N=2 : 4 slots */ 00135 RFAL_NFCB_SLOT_NUM_8 = 3, /*!< N=3 : 8 slots */ 00136 RFAL_NFCB_SLOT_NUM_16 = 4 /*!< N=4 : 16 slots */ 00137 }rfalNfcbSlots ; 00138 00139 00140 /*! SENSB_RES (ATQB) Application Data Format Digital 1.1 Table 28 */ 00141 typedef struct 00142 { 00143 uint8_t AFI ; /*!< Application Family Identifier */ 00144 uint8_t CRC_B[RFAL_NFCB_CRC_LEN]; /*!< CRC_B of AID */ 00145 uint8_t numApps ; /*!< Number of Applications */ 00146 } rfalNfcbSensbResAppData ; 00147 00148 00149 /*! SENSB_RES Protocol Info format Digital 1.1 Table 29 */ 00150 typedef struct 00151 { 00152 uint8_t BRC ; /*!< Bit Rate Capability */ 00153 uint8_t FsciProType ; /*!< Frame Size Card Integer [4b] | Protocol Type[4 bits] */ 00154 uint8_t FwiAdcFo ; /*!< Frame Waiting Integer [4b] | Application Data Coding [2b] | Frame Options [2b] */ 00155 uint8_t SFGI ; /*!< Optional: Start-Up Frame Guard Time Integer[4b] | RFU [4b] */ 00156 } rfalNfcbSensbResProtocolInfo ; 00157 00158 00159 /*! SENSB_RES format Digital 1.1 7.6.2 */ 00160 typedef struct 00161 { 00162 uint8_t cmd ; /*!< SENSB_RES: 50h */ 00163 uint8_t nfcid0[RFAL_NFCB_NFCID0_LEN]; /*!< NFC Identifier (PUPI)*/ 00164 rfalNfcbSensbResAppData appData ; /*!< Application Data */ 00165 rfalNfcbSensbResProtocolInfo protInfo ; /*!< Protocol Information */ 00166 } rfalNfcbSensbRes ; 00167 00168 00169 /*! NFC-B listener device (PICC) struct */ 00170 typedef struct 00171 { 00172 uint8_t sensbResLen ; /*!< SENSB_RES length */ 00173 rfalNfcbSensbRes sensbRes ; /*!< SENSB_RES */ 00174 bool isSleep ; /*!< Device sleeping flag */ 00175 }rfalNfcbListenDevice ; 00176 00177 /* 00178 ****************************************************************************** 00179 * GLOBAL FUNCTION PROTOTYPES 00180 ****************************************************************************** 00181 */ 00182 00183 /*! 00184 ***************************************************************************** 00185 * \brief Initialize NFC-B Poller mode 00186 * 00187 * This methods configures RFAL RF layer to perform as a 00188 * NFC-B Poller/RW (ISO14443B PCD) including all default timings 00189 * 00190 * It sets NFC-B parameters (AFI, PARAM) to default values 00191 * 00192 * \return ERR_WRONG_STATE : RFAL not initialized or mode not set 00193 * \return ERR_NONE : No error 00194 ***************************************************************************** 00195 */ 00196 ReturnCode rfalNfcbPollerInitialize( 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 ); 00197 00198 00199 /*! 00200 ***************************************************************************** 00201 * \brief Set NFC-B Poller parameters 00202 * 00203 * This methods configures RFAL RF layer to perform as a 00204 * NFCA Poller/RW (ISO14443A PCD) including all default timings 00205 * 00206 * Additionally configures NFC-B specific parameters to be used on the 00207 * following communications 00208 * 00209 * \param[in] AFI : Application Family Identifier to be used 00210 * \param[in] PARAM : PARAM to be used, it announces whether Advanced 00211 * Features or Extended SENSB_RES is supported 00212 * 00213 * \return ERR_WRONG_STATE : RFAL not initialized or mode not set 00214 * \return ERR_NONE : No error 00215 ***************************************************************************** 00216 */ 00217 ReturnCode rfalNfcbPollerInitializeWithParams( uint8_t AFI, uint8_t PARAM, 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 ); 00218 00219 00220 /*! 00221 ***************************************************************************** 00222 * \brief NFC-B Poller Check Presence 00223 * 00224 * This method checks if a NFC-B Listen device (PICC) is present on the field 00225 * by sending an ALLB_REQ (WUPB) or SENSB_REQ (REQB) 00226 * 00227 * \param[in] cmd : Indicate if to send an ALL_REQ or a SENS_REQ 00228 * \param[in] slots : The number of slots to be announced 00229 * \param[out] sensbRes : If received, the SENSB_RES 00230 * \param[out] sensbResLen : If received, the SENSB_RES length 00231 * 00232 * 00233 * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode 00234 * \return ERR_PARAM : Invalid parameters 00235 * \return ERR_IO : Generic internal error 00236 * \return ERR_TIMEOUT : Timeout error, no listener device detected 00237 * \return ERR_RF_COLLISION : Collision detected one or more device in the field 00238 * \return ERR_PAR : Parity error detected, one or more device in the field 00239 * \return ERR_CRC : CRC error detected, one or more device in the field 00240 * \return ERR_FRAMING : Framing error detected, one or more device in the field 00241 * \return ERR_PROTO : Protocol error detected, invalid SENSB_RES received 00242 * \return ERR_NONE : No error, SENSB_RES received 00243 ***************************************************************************** 00244 */ 00245 ReturnCode rfalNfcbPollerCheckPresence( rfalNfcbSensCmd cmd, rfalNfcbSlots slots, rfalNfcbSensbRes *sensbRes, uint8_t *sensbResLen, 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 ); 00246 00247 00248 /*! 00249 ***************************************************************************** 00250 * \brief NFC-B Poller Sleep 00251 * 00252 * This function is used to send the SLPB_REQ (HLTB) command to put the PICC with 00253 * the given NFCID0 to state HALT so that they do not reply to further SENSB_REQ 00254 * commands (only to ALLB_REQ) 00255 * 00256 * \param[in] nfcid0 : NFCID of the device to be put to Sleep 00257 * 00258 * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode 00259 * \return ERR_PARAM : Invalid parameters 00260 * \return ERR_IO : Generic internal error 00261 * \return ERR_NONE : No error 00262 ***************************************************************************** 00263 */ 00264 ReturnCode rfalNfcbPollerSleep( uint8_t* nfcid0, 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 ); 00265 00266 00267 /*! 00268 ***************************************************************************** 00269 * \brief NFC-B Poller Slot Marker 00270 * 00271 * This method selects a NFC-B Slot marker frame 00272 * 00273 * \param[in] slotCode : Slot Code [1-15] 00274 * \param[out] sensbRes : If received, the SENSB_RES 00275 * \param[out] sensbResLen : If received, the SENSB_RES length 00276 * 00277 * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode 00278 * \return ERR_PARAM : Invalid parameters 00279 * \return ERR_IO : Generic internal error 00280 * \return ERR_TIMEOUT : Timeout error 00281 * \return ERR_PAR : Parity error detected 00282 * \return ERR_CRC : CRC error detected 00283 * \return ERR_FRAMING : Framing error detected 00284 * \return ERR_PROTO : Protocol error detected 00285 * \return ERR_NONE : No error, SEL_RES received 00286 ***************************************************************************** 00287 */ 00288 ReturnCode rfalNfcbPollerSlotMarker( uint8_t slotCode, rfalNfcbSensbRes *sensbRes, uint8_t *sensbResLen, 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 ); 00289 00290 /*! 00291 ***************************************************************************** 00292 * \brief NFC-B Technology Detection 00293 * 00294 * This method performs NFC-B Technology Detection as defined in the spec 00295 * given in the compliance mode 00296 * 00297 * \param[in] compMode : compliance mode to be performed 00298 * \param[out] sensbRes : location to store the SENSB_RES, if received 00299 * \param[out] sensbResLen : length of the SENSB_RES, if received 00300 * 00301 * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode 00302 * \return ERR_PARAM : Invalid parameters 00303 * \return ERR_IO : Generic internal error 00304 * \return ERR_NONE : No error, one or more device in the field 00305 ***************************************************************************** 00306 */ 00307 ReturnCode rfalNfcbPollerTechnologyDetection( rfalComplianceMode compMode, rfalNfcbSensbRes *sensbRes, uint8_t *sensbResLen, 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 ); 00308 00309 /*! 00310 ***************************************************************************** 00311 * \brief NFC-B Poller Collision Resolution 00312 * 00313 * NFC-B Collision resolution Listener device/card (PICC) as 00314 * defined in Activity 1.1 9.3.5 00315 * 00316 * This function is used to perform collision resolution for detection in case 00317 * of multiple NFC Forum Devices with Technology B detected. 00318 * Target with valid SENSB_RES will be stored in devInfo and nfcbDevCount incremented. 00319 * 00320 * \param[in] compMode : compliance mode to be performed 00321 * \param[in] devLimit : device limit value, and size nfcbDevList 00322 * \param[out] nfcbDevList : NFC-B listener device info 00323 * \param[out] devCnt : devices found counter 00324 * 00325 * \return ERR_WRONG_STATE : RFAL not initialized or mode not set 00326 * \return ERR_PARAM : Invalid parameters 00327 * \return ERR_IO : Generic internal error 00328 * \return ERR_PROTO : Protocol error detected 00329 * \return ERR_NONE : No error 00330 ***************************************************************************** 00331 */ 00332 ReturnCode rfalNfcbPollerCollisionResolution( rfalComplianceMode compMode, uint8_t devLimit, rfalNfcbListenDevice *nfcbDevList, 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 ); 00333 00334 /*! 00335 ***************************************************************************** 00336 * \brief NFC-B Poller Collision Resolution Slotted 00337 * 00338 * NFC-B Collision resolution Listener device/card (PICC). The sequence can 00339 * be configured to be according to NFC Forum Activity 1.1 9.3.5, ISO10373 00340 * or EMVCo 00341 * 00342 * This function is used to perform collision resolution for detection in case 00343 * of multiple NFC Forum Devices with Technology B are detected. 00344 * Target with valid SENSB_RES will be stored in devInfo and nfcbDevCount incremented. 00345 * 00346 * This method provides the means to perform a collision resolution loop with specific 00347 * initial and end number of slots. This allows to user to start the loop already with 00348 * greater number of slots, and or limit the end number of slots. At the end a flag 00349 * indicating whether there were collisions pending is returned. 00350 * 00351 * If RFAL_COMPLIANCE_MODE_ISO is used \a initSlots must be set to RFAL_NFCB_SLOT_NUM_1 00352 * 00353 * 00354 * \param[in] compMode : compliance mode to be performed 00355 * \param[in] devLimit : device limit value, and size nfcbDevList 00356 * \param[in] initSlots : number of slots to open initially 00357 * \param[in] endSlots : number of slots when to stop collision resolution 00358 * \param[out] nfcbDevList : NFC-B listener device info 00359 * \param[out] devCnt : devices found counter 00360 * \param[out] colPending : flag indicating whether collision are still pending 00361 * 00362 * \return ERR_WRONG_STATE : RFAL not initialized or mode not set 00363 * \return ERR_PARAM : Invalid parameters 00364 * \return ERR_IO : Generic internal error 00365 * \return ERR_PROTO : Protocol error detected 00366 * \return ERR_NONE : No error 00367 ***************************************************************************** 00368 */ 00369 ReturnCode rfalNfcbPollerCollisionResolutionSlotted( rfalComplianceMode compMode, uint8_t devLimit, rfalNfcbSlots initSlots, rfalNfcbSlots endSlots, rfalNfcbListenDevice *nfcbDevList, uint8_t *devCnt, bool *colPending, 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 ); 00370 00371 00372 /*! 00373 ***************************************************************************** 00374 * \brief NFC-B TR2 code to FDT 00375 * 00376 * Converts the TR2 code as defined in Digital 1.1 Table 33 Minimum 00377 * TR2 Coding to Frame Delay Time (FDT) in 1/Fc 00378 * 00379 * \param[in] tr2Code : TR2 code as defined in Digital 1.1 Table 33 00380 * 00381 * \return FDT in 1/Fc 00382 ***************************************************************************** 00383 */ 00384 uint32_t rfalNfcbTR2ToFDT( uint8_t tr2Code ); 00385 00386 00387 #endif /* RFAL_NFCB_H */ 00388 00389 /** 00390 * @} 00391 * 00392 * @} 00393 * 00394 * @} 00395 */
Generated on Fri Jul 15 2022 06:42:12 by
1.7.2