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_nfcf.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_nfcf.h 00030 * 00031 * \author Gustavo Patricio 00032 * 00033 * \brief Implementation of NFC-F Poller (FeliCa PCD) device 00034 * 00035 * The definitions and helpers methods provided by this module are 00036 * aligned with NFC-F (FeliCa - JIS X6319-4) 00037 * 00038 * 00039 * @addtogroup RFAL 00040 * @{ 00041 * 00042 * @addtogroup RFAL-AL 00043 * @brief RFAL Abstraction Layer 00044 * @{ 00045 * 00046 * @addtogroup NFC-F 00047 * @brief RFAL NFC-F Module 00048 * @{ 00049 * 00050 */ 00051 00052 00053 #ifndef RFAL_NFCF_H 00054 #define RFAL_NFCF_H 00055 00056 /* 00057 ****************************************************************************** 00058 * INCLUDES 00059 ****************************************************************************** 00060 */ 00061 #include "platform1.h" 00062 #include "st_errno.h" 00063 #include "rfal_rf.h" 00064 00065 /* 00066 ****************************************************************************** 00067 * GLOBAL DEFINES 00068 ****************************************************************************** 00069 */ 00070 00071 #define RFAL_NFCF_NFCID2_LEN 8 /*!< NFCID2 (FeliCa IDm) length */ 00072 #define RFAL_NFCF_SENSF_RES_LEN_MIN 16 /*!< SENSF_RES minimum length */ 00073 #define RFAL_NFCF_SENSF_RES_LEN_MAX 18 /*!< SENSF_RES maximum length */ 00074 #define RFAL_NFCF_SENSF_RES_PAD0_LEN 2 /*!< SENSF_RES PAD0 length */ 00075 #define RFAL_NFCF_SENSF_RES_PAD1_LEN 2 /*!< SENSF_RES PAD1 length */ 00076 #define RFAL_NFCF_SENSF_RES_RD_LEN 2 /*!< SENSF_RES Request Data length */ 00077 #define RFAL_NFCF_SENSF_RES_BYTE1 1 /*!< SENSF_RES first byte value */ 00078 #define RFAL_NFCF_SENSF_SC_LEN 2 /*!< Felica SENSF_REQ System Code length */ 00079 #define RFAL_NFCF_SENSF_PARAMS_SC1_POS 0 /*!< System Code byte1 position in the SENSF_REQ */ 00080 #define RFAL_NFCF_SENSF_PARAMS_SC2_POS 1 /*!< System Code byte2 position in the SENSF_REQ */ 00081 #define RFAL_NFCF_SENSF_PARAMS_RC_POS 2 /*!< Request Code position in the SENSF_REQ */ 00082 #define RFAL_NFCF_SENSF_PARAMS_TSN_POS 3 /*!< Time Slot Number position in the SENSF_REQ */ 00083 #define RFAL_NFCF_POLL_MAXCARDS 16 /*!< Max number slots/cards 16 */ 00084 00085 00086 #define RFAL_NFCF_CMD_LEN 1 /*!< Command/Responce code length */ 00087 #define RFAL_NFCF_LENGTH_LEN 1 /*!< LEN field length */ 00088 #define RFAL_NFCF_HEADER_LEN (RFAL_NFCF_LENGTH_LEN + RFAL_NFCF_CMD_LEN) /*!< Header length*/ 00089 00090 00091 #define RFAL_NFCF_SENSF_NFCID2_BYTE1_POS 0 /*!< NFCID2 byte1 position */ 00092 #define RFAL_NFCF_SENSF_NFCID2_BYTE2_POS 1 /*!< NFCID2 byte2 position */ 00093 00094 #define RFAL_NFCF_SENSF_NFCID2_PROT_TYPE_LEN 2 /*!< NFCID2 length for byte 1 and byte 2 indicating NFC-DEP or T3T support */ 00095 #define RFAL_NFCF_SENSF_NFCID2_BYTE1_NFCDEP 0x01 /*!< NFCID2 byte1 NFC-DEP support Digital 1.0 Table 44*/ 00096 #define RFAL_NFCF_SENSF_NFCID2_BYTE2_NFCDEP 0xFE /*!< NFCID2 byte2 NFC-DEP support Digital 1.0 Table 44*/ 00097 00098 #define RFAL_NFCF_SYSTEMCODE 0xFFFF /*!< SENSF_RES Default System Code Digital 1.0 6.6.1.1 */ 00099 00100 00101 /*! NFC-F Felica command set JIS X6319-4 9.1 */ 00102 enum 00103 { 00104 RFAL_NFCF_CMD_POLLING = 0x00, /*!< SENSF_REQ (Felica Poll/REQC command to identify a card ) */ 00105 RFAL_NFCF_CMD_POLLING_RES = 0x01, /*!< SENSF_RES (Felica Poll/REQC command response ) */ 00106 RFAL_NFCF_CMD_REQUEST_SERVICE = 0x02, /*!< verify the existence of Area and Service */ 00107 RFAL_NFCF_CMD_REQUEST_RESPONSE = 0x04, /*!< verify the existence of a card */ 00108 RFAL_NFCF_CMD_READ_WITHOUT_ENCRYPTION = 0x06, /*!< read Block Data from a Service that requires no authentication */ 00109 RFAL_NFCF_CMD_WRITE_WITHOUT_ENCRYPTION = 0x08, /*!< write Block Data to a Service that requires no authentication */ 00110 RFAL_NFCF_CMD_REQUEST_SYSTEM_CODE = 0x0c, /*!< acquire the System Code registered to a card */ 00111 RFAL_NFCF_CMD_AUTHENTICATION1 = 0x10, /*!< authenticate a card */ 00112 RFAL_NFCF_CMD_AUTHENTICATION2 = 0x12, /*!< allow a card to authenticate a Reader/Writer */ 00113 RFAL_NFCF_CMD_READ = 0x14, /*!< read Block Data from a Service that requires authentication */ 00114 RFAL_NFCF_CMD_WRITE = 0x16, /*!< write Block Data to a Service that requires authentication */ 00115 }; 00116 00117 /* 00118 ****************************************************************************** 00119 * GLOBAL MACROS 00120 ****************************************************************************** 00121 */ 00122 00123 /*! Checks if the given NFC-F device indicates NFC-DEP support */ 00124 #define rfalNfcfIsNfcDepSupported( dev ) ( (((rfalNfcfListenDevice*)(dev))->sensfRes.NFCID2[RFAL_NFCF_SENSF_NFCID2_BYTE1_POS] == RFAL_NFCF_SENSF_NFCID2_BYTE1_NFCDEP) && \ 00125 (((rfalNfcfListenDevice*)(dev))->sensfRes.NFCID2[RFAL_NFCF_SENSF_NFCID2_BYTE2_POS] == RFAL_NFCF_SENSF_NFCID2_BYTE2_NFCDEP) ) 00126 00127 00128 /* 00129 ****************************************************************************** 00130 * GLOBAL TYPES 00131 ****************************************************************************** 00132 */ 00133 00134 00135 /*! NFC-F SENSF_RES format Digital 1.1 8.6.2 */ 00136 typedef struct 00137 { 00138 uint8_t CMD ; /*!< Command Code: 01h */ 00139 uint8_t NFCID2[RFAL_NFCF_NFCID2_LEN]; /*!< NFCID2 */ 00140 uint8_t PAD0[RFAL_NFCF_SENSF_RES_PAD0_LEN]; /*!< PAD0 */ 00141 uint8_t PAD1[RFAL_NFCF_SENSF_RES_PAD1_LEN]; /*!< PAD1 */ 00142 uint8_t MRTIcheck ; /*!< MRTIcheck */ 00143 uint8_t MRTIupdate ; /*!< MRTIupdate */ 00144 uint8_t PAD2 ; /*!< PAD2 */ 00145 uint8_t RD[RFAL_NFCF_SENSF_RES_RD_LEN]; /*!< Request Data */ 00146 } rfalNfcfSensfRes ; 00147 00148 00149 /*! NFC-F poller device (PCD) struct */ 00150 typedef struct 00151 { 00152 uint8_t NFCID2[RFAL_NFCF_NFCID2_LEN]; /*!< NFCID2 */ 00153 } rfalNfcfPollDevice ; 00154 00155 /*! NFC-F listener device (PICC) struct */ 00156 typedef struct 00157 { 00158 uint8_t sensfResLen ; /*!< SENF_RES length */ 00159 rfalNfcfSensfRes sensfRes ; /*!< SENF_RES */ 00160 } rfalNfcfListenDevice ; 00161 00162 00163 /* 00164 ****************************************************************************** 00165 * GLOBAL FUNCTION PROTOTYPES 00166 ****************************************************************************** 00167 */ 00168 00169 /*! 00170 ***************************************************************************** 00171 * \brief Initialize NFC-F Poller mode 00172 * 00173 * This methods configures RFAL RF layer to perform as a 00174 * NFC-F Poller/RW (FeliCa PCD) including all default timings 00175 * 00176 * \param[in] bitRate : NFC-F bitrate to be initialize (212 or 424) 00177 * 00178 * \return ERR_WRONG_STATE : RFAL not initialized or mode not set 00179 * \return ERR_PARAM : Incorrect bitrate 00180 * \return ERR_NONE : No error 00181 ***************************************************************************** 00182 */ 00183 ReturnCode rfalNfcfPollerInitialize( rfalBitRate bitRate, 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 ); 00184 00185 00186 /*! 00187 ***************************************************************************** 00188 * \brief NFC-F Poller Check Presence 00189 * 00190 * This function sends a Poll/SENSF command according to NFC Activity spec 00191 * It detects if a NCF-F device is within range 00192 * 00193 * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode 00194 * \return ERR_PARAM : Invalid parameters 00195 * \return ERR_IO : Generic internal error 00196 * \return ERR_CRC : CRC error detected 00197 * \return ERR_FRAMING : Framing error detected 00198 * \return ERR_PROTO : Protocol error detected 00199 * \return ERR_TIMEOUT : Timeout error, no listener device detected 00200 * \return ERR_NONE : No error and some NFC-F device was detected 00201 * 00202 ***************************************************************************** 00203 */ 00204 ReturnCode rfalNfcfPollerCheckPresence( 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 ); 00205 00206 00207 /*! 00208 ***************************************************************************** 00209 * \brief NFC-F Poller Poll 00210 * 00211 * This function sends to all PICCs in field the POLL command with the given 00212 * number of slots. 00213 * 00214 * \param[in] slots : the number of slots to be performed 00215 * \param[in] sysCode : as given in FeliCa poll command 00216 * \param[in] reqCode : FeliCa communication parameters 00217 * \param[out] cardList : Parameter of type rfalFeliCaPollRes which will hold the cards found 00218 * \param[out] devCnt : actual number of cards found 00219 * \param[out] collisions : number of collisions encountered 00220 * 00221 * \warning the list cardList has to be as big as the number of slots for the Poll 00222 * 00223 * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode 00224 * \return ERR_PARAM : Invalid parameters 00225 * \return ERR_IO : Generic internal error 00226 * \return ERR_CRC : CRC error detected 00227 * \return ERR_FRAMING : Framing error detected 00228 * \return ERR_PROTO : Protocol error detected 00229 * \return ERR_TIMEOUT : Timeout error, no listener device detected 00230 * \return ERR_NONE : No error and some NFC-F device was detected 00231 * 00232 ***************************************************************************** 00233 */ 00234 ReturnCode rfalNfcfPollerPoll( rfalFeliCaPollSlots slots, uint16_t sysCode, uint8_t reqCode, rfalFeliCaPollRes *cardList, uint8_t *devCnt, uint8_t *collisions, 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 ); 00235 00236 00237 /*! 00238 ***************************************************************************** 00239 * \brief NFC-F Poller Full Collision Resolution 00240 * 00241 * Performs a full Collision resolution as defined in Activity 1.1 9.3.4 00242 * 00243 * \param[in] compMode : compliance mode to be performed 00244 * \param[in] devLimit : device limit value, and size nfcaDevList 00245 * \param[out] nfcfDevList : NFC-F listener devices list 00246 * \param[out] devCnt : Devices found counter 00247 * 00248 * \return ERR_WRONG_STATE : RFAL not initialized or mode not set 00249 * \return ERR_PARAM : Invalid parameters 00250 * \return ERR_IO : Generic internal error 00251 * \return ERR_NONE : No error 00252 ***************************************************************************** 00253 */ 00254 ReturnCode rfalNfcfPollerCollisionResolution( rfalComplianceMode compMode, uint8_t devLimit, rfalNfcfListenDevice *nfcfDevList, 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 ); 00255 00256 00257 /*! 00258 ***************************************************************************** 00259 * \brief NFC-F Listener is T3T Request 00260 * 00261 * This method checks if the given data is a valid T3T command (Read or Write) 00262 * and in case a valid request has been received it may output the request's NFCID2 00263 * 00264 * \param[in] buf : buffer holding Initiator's received command 00265 * \param[in] bufLen : length of received command in bytes 00266 * \param[out] nfcid2 : pointer to where the NFCID2 may be outputed, 00267 * nfcid2 has NFCF_SENSF_NFCID2_LEN as length 00268 * Pass NULL if output parameter not desired 00269 * 00270 * \return true : Valid T3T command (Read or Write) received 00271 * \return false : Invalid protocol request 00272 * 00273 ***************************************************************************** 00274 */ 00275 bool rfalNfcfListenerIsT3TReq( uint8_t* buf, uint16_t bufLen, uint8_t* nfcid2 ); 00276 00277 00278 #endif /* RFAL_NFCF_H */ 00279 00280 /** 00281 * @} 00282 * 00283 * @} 00284 * 00285 * @} 00286 */ 00287
Generated on Sat Jul 16 2022 13:00:53 by
1.7.2