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_nfcDep.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_nfcDep.h 00031 * 00032 * \author Gustavo Patricio 00033 * 00034 * \brief Implementation of NFC-DEP protocol 00035 * 00036 * NFC-DEP is also known as NFCIP - Near Field Communication 00037 * Interface and Protocol 00038 * 00039 * This implementation was based on the following specs: 00040 * - NFC Forum Digital 1.1 00041 * - ECMA 340 3rd Edition 2013 00042 * 00043 * 00044 * @addtogroup RFAL 00045 * @{ 00046 * 00047 * @addtogroup RFAL-AL 00048 * @brief RFAL Abstraction Layer 00049 * @{ 00050 * 00051 * @addtogroup NFC-DEP 00052 * @brief RFAL NFC-DEP Module 00053 * @{ 00054 */ 00055 00056 #ifndef RFAL_NFCDEP_H_ 00057 #define RFAL_NFCDEP_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 ****************************************************************************** 00071 * DEFINES 00072 ****************************************************************************** 00073 */ 00074 #define RFAL_NFCDEP_FRAME_SIZE_MAX_LEN 254 /*!< NFCIP Maximum Frame Size Digital 1.0 Table 91 */ 00075 #define RFAL_NFCDEP_DEPREQ_HEADER_LEN 5 /*!< DEP_REQ header length: CMD_TYPE + CMD_CMD + PBF + DID + NAD */ 00076 00077 00078 00079 /*! Length NFCIP DEP REQ or RES header (incl LEN) */ 00080 #define RFAL_NFCDEP_DEP_HEADER ( RFAL_NFCDEP_LEN_LEN + RFAL_NFCDEP_CMDTYPE_LEN + RFAL_NFCDEP_CMD_LEN + RFAL_NFCDEP_DEP_PFB_LEN ) 00081 #define RFAL_NFCDEP_HEADER ( RFAL_NFCDEP_CMDTYPE_LEN + RFAL_NFCDEP_CMD_LEN ) /*!< NFCIP header length */ 00082 #define RFAL_NFCDEP_SB_LEN 1 /*!< SB length on NFCIP fram for NFC-A */ 00083 #define RFAL_NFCDEP_LEN_LEN 1 /*!< LEN length on NFCIP frame */ 00084 #define RFAL_NFCDEP_CMDTYPE_LEN 1 /*!< Length of the cmd type (REQ | RES) on NFCIP frame */ 00085 #define RFAL_NFCDEP_CMD_LEN 1 /*!< Length of the cmd on NFCIP frame */ 00086 #define RFAL_NFCDEP_DID_LEN 1 /*!< Length of did on NFCIP frame */ 00087 #define RFAL_NFCDEP_DEP_PFB_LEN 1 /*!< Length of the PFB field on NFCIP frame */ 00088 00089 #define RFAL_NFCDEP_DSL_RLS_LEN_NO_DID (RFAL_NFCDEP_LEN_LEN + RFAL_NFCDEP_CMDTYPE_LEN + RFAL_NFCDEP_CMD_LEN) /*!< Length of DSL_REQ and RLS_REQ with no DID */ 00090 #define RFAL_NFCDEP_DSL_RLS_LEN_DID (RFAL_NFCDEP_DSL_RLS_LEN_NO_DID + RFAL_NFCDEP_DID_LEN) /*!< Length of DSL_REQ and RLS_REQ with DID */ 00091 00092 #define RFAL_NFCDEP_FS_VAL_MIN 64 /*!< Minimum LR value */ 00093 #define RFAL_NFCDEP_LR_VAL_MASK 0x03 /*!< Bit mask for a LR value */ 00094 #define RFAL_NFCDEP_PP_LR_MASK 0x30 /*!< Bit mask for LR value in PP byte on a ATR REQ/RES */ 00095 #define RFAL_NFCDEP_PP_LR_SHIFT 4 /*!< Position of LR value in PP byte on a ATR REQ/RES */ 00096 00097 #define RFAL_NFCDEP_DID_MAX 14 /*!< Max DID value Digital 14.6.2.3 */ 00098 #define RFAL_NFCDEP_DID_KEEP 0xFF /*!< Keep DID value already configured */ 00099 #define RFAL_NFCDEP_DID_NO 0x00 /*!< No DID shall be used */ 00100 #define RFAL_NFCDEP_NAD_NO 0x00 /*!< No NAD shall be used */ 00101 00102 #define RFAL_NFCDEP_OPER_RTOX_REQ_DIS 0x01 /*!< Operation config: RTOX REQ disable */ 00103 #define RFAL_NFCDEP_OPER_RTOX_REQ_EN 0x00 /*!< Operation config: RTOX REQ enable */ 00104 00105 #define RFAL_NFCDEP_OPER_ATN_DIS 0x00 /*!< Operation config: ATN disable */ 00106 #define RFAL_NFCDEP_OPER_ATN_EN 0x02 /*!< Operation config: ATN enable */ 00107 00108 #define RFAL_NFCDEP_OPER_EMPTY_DEP_DIS 0x04 /*!< Operation config: empty DEPs disable */ 00109 #define RFAL_NFCDEP_OPER_EMPTY_DEP_EN 0x00 /*!< Operation config: empty DEPs enable */ 00110 00111 #define RFAL_NFCDEP_OPER_FULL_MI_DIS 0x00 /*!< Operation config: full chaining DEPs disable */ 00112 #define RFAL_NFCDEP_OPER_FULL_MI_EN 0x08 /*!< Operation config: full chaining DEPs enable */ 00113 00114 00115 #define RFAL_NFCDEP_BRS_MAINTAIN 0xC0 /*!< Value signalling that BR is to be maintained (no PSL) */ 00116 #define RFAL_NFCDEP_BRS_Dx_MASK 0x07 /*!< Value signalling that BR is to be maintained (no PSL) */ 00117 #define RFAL_NFCDEP_BRS_DSI_POS 3 /*!< Value signalling that BR is to be maintained (no PSL) */ 00118 00119 #define RFAL_NFCDEP_WT_DELTA (16 - RFAL_NFCDEP_WT_DELTA_ADJUST) /*!< NFC-DEP dWRT (adjusted) Digital 1.0 A.10 */ 00120 #define RFAL_NFCDEP_WT_DELTA_ADJUST 4 /*!< dWRT value adjustment */ 00121 00122 00123 #define RFAL_NFCDEP_ATR_REQ_NFCID3_POS 2 /*!< NFCID3 offset in ATR_REQ frame */ 00124 #define RFAL_NFCDEP_NFCID3_LEN 10 /*!< NFCID3 Length */ 00125 00126 #define RFAL_NFCDEP_LEN_MIN 3 /*!< Minimum length byte LEN value */ 00127 #define RFAL_NFCDEP_LEN_MAX 255 /*!< Maximum length byte LEN value */ 00128 00129 #define RFAL_NFCDEP_ATRRES_HEADER_LEN 2 /*!< ATR RES Header Len: CmdType: 0xD5 + Cod: 0x01 */ 00130 #define RFAL_NFCDEP_ATRRES_MIN_LEN 17 /*!< Minimum length for an ATR RES */ 00131 #define RFAL_NFCDEP_ATRRES_MAX_LEN 64 /*!< Maximum length for an ATR RES Digital 1.0 14.6.1 */ 00132 #define RFAL_NFCDEP_ATRREQ_MIN_LEN 16 /*!< Minimum length for an ATR REQ */ 00133 #define RFAL_NFCDEP_ATRREQ_MAX_LEN RFAL_NFCDEP_ATRRES_MAX_LEN /*!< Maximum length for an ATR REQ Digital 1.0 14.6.1 */ 00134 00135 #define RFAL_NFCDEP_GB_MAX_LEN (RFAL_NFCDEP_ATRREQ_MAX_LEN - RFAL_NFCDEP_ATRREQ_MIN_LEN) /*!< Maximum length the General Bytes on ATR Digital 1.1 16.6.3 */ 00136 00137 #define RFAL_NFCDEP_WT_INI_DEFAULT RFAL_NFCDEP_WT_INI_MAX /*!< WT Initiator default value Digital 1.0 14.6.3.8 */ 00138 #define RFAL_NFCDEP_WT_INI_MIN 0 /*!< WT Initiator minimum value Digital 1.0 14.6.3.8 */ 00139 #define RFAL_NFCDEP_WT_INI_MAX 14 /*!< WT Initiator maximum value Digital 1.0 14.6.3.8 A.10*/ 00140 #define RFAL_NFCDEP_RWT_INI_MAX rfalNfcDepWT2RWT( RFAL_NFCDEP_WT_INI_MAX ) /*!< RWT Initiator maximum value */ 00141 00142 #define RFAL_NFCDEP_WT_TRG_MAX_D10 8 /*!< WT target max Digital 1.0 14.6.3.8 A.10 */ 00143 #define RFAL_NFCDEP_WT_TRG_MAX_D11 14 /*!< WT target max Digital 1.1 16.6.3.9 A.9 */ 00144 #define RFAL_NFCDEP_WT_TRG_MAX RFAL_NFCDEP_WT_TRG_MAX_D10 /*!< WT target max Digital 1.x */ 00145 #define RFAL_NFCDEP_RWT_TRG_MAX rfalNfcDepWT2RWT( RFAL_NFCDEP_WT_TRG_MAX ) /*!< RWT Initiator maximum value */ 00146 00147 /*! Maximum Frame Waiting Time = ((256 * 16/fc)*2^FWImax) = ((256*16/fc)*2^14) = (1048576 / 64)/fc = (100000h*64)/fc */ 00148 #define RFAL_NFCDEP_MAX_FWT (1<<20) 00149 00150 #define RFAL_NFCDEP_WT_MASK 0x0F /*!< Bit mask for the Wait Time value */ 00151 00152 #define RFAL_NFCDEP_BR_MASK_106 1 /*!< Enable mask bit rate 106 */ 00153 #define RFAL_NFCDEP_BR_MASK_212 2 /*!< Enable mask bit rate 242 */ 00154 #define RFAL_NFCDEP_BR_MASK_424 4 /*!< Enable mask bit rate 424 */ 00155 00156 /* 00157 ****************************************************************************** 00158 * GLOBAL MACROS 00159 ****************************************************************************** 00160 */ 00161 00162 #define rfalNfcDepWT2RWT( wt ) (1 << ( (wt & RFAL_NFCDEP_WT_MASK) + 6) ) /*!< Converts WT value to RWT */ 00163 00164 /*! Returns the BRS value from the given bit rate */ 00165 #define rfalNfcDepDx2BRS( br ) ( (uint8_t) ( (((br)&RFAL_NFCDEP_BRS_Dx_MASK) << RFAL_NFCDEP_BRS_DSI_POS) | ((br) & RFAL_NFCDEP_BRS_Dx_MASK) )) 00166 00167 #define rfalNfcDepBRS2DRI( brs ) ( (uint8_t) ( brs & RFAL_NFCDEP_BRS_Dx_MASK ) ) /*!< Returns the DRI value from the given BRS byte */ 00168 #define rfalNfcDepBRS2DSI( brs ) ( (uint8_t) ( (brs >> RFAL_NFCDEP_BRS_DSI_POS) & RFAL_NFCDEP_BRS_Dx_MASK ) ) /*!< Returns the DSI value from the given BRS byte */ 00169 00170 #define rfalNfcDepPP2LR( PPx ) ( (uint8_t) ( PPx & RFAL_NFCDEP_PP_LR_MASK ) >> RFAL_NFCDEP_PP_LR_SHIFT) /*!< Returns the LR value from the given PPx byte */ 00171 #define rfalNfcDepLR2PP( LRx ) ( (uint8_t) ((LRx << RFAL_NFCDEP_PP_LR_SHIFT) & RFAL_NFCDEP_PP_LR_MASK)) /*!< Returns the PP byte with the given LRx value */ 00172 00173 /*! Returns the Frame size value from the given LRx value */ 00174 #define rfalNfcDepLR2FS( LRx ) MIN( ((uint8_t) RFAL_NFCDEP_FS_VAL_MIN * (LRx + 1) ), RFAL_NFCDEP_FRAME_SIZE_MAX_LEN ) 00175 00176 /*! 00177 * Despite DIGITAL 1.0 14.6.2.1 stating that the last two bytes may filled with 00178 * any value, some devices (Samsung Google Nexus) only accept when these are 0 */ 00179 #define rfalNfcDepSetNFCID( dst, src, len ) ST_MEMSET( (dst), 0x00, RFAL_NFCDEP_NFCID3_LEN ); \ 00180 ST_MEMCPY( (dst), src, len ) 00181 00182 /* 00183 ****************************************************************************** 00184 * GLOBAL ENUMERATIONS 00185 ****************************************************************************** 00186 */ 00187 00188 00189 00190 /*! Enumeration of NFC-DEP bit rate in ATR Digital 1.0 Table 93 and 94 */ 00191 enum{ 00192 RFAL_NFCDEP_Bx_NO_HIGH_BR = 0x00, /*!< Peer supports no high bit rates */ 00193 RFAL_NFCDEP_Bx_08_848 = 0x01, /*!< Peer also supports 848 */ 00194 RFAL_NFCDEP_Bx_16_1695 = 0x02, /*!< Peer also supports 1695 */ 00195 RFAL_NFCDEP_Bx_32_3390 = 0x04, /*!< Peer also supports 3390 */ 00196 RFAL_NFCDEP_Bx_64_6780 = 0x08 /*!< Peer also supports 6780 */ 00197 }; 00198 00199 /*! Enumeration of NFC-DEP bit rate Dividor in PSL Digital 1.0 Table 100 */ 00200 enum{ 00201 RFAL_NFCDEP_Dx_01_106 = RFAL_BR_106 , /*!< Divisor D = 1 : bit rate = 106 */ 00202 RFAL_NFCDEP_Dx_02_212 = RFAL_BR_212 , /*!< Divisor D = 2 : bit rate = 212 */ 00203 RFAL_NFCDEP_Dx_04_424 = RFAL_BR_424 , /*!< Divisor D = 4 : bit rate = 424 */ 00204 RFAL_NFCDEP_Dx_08_848 = RFAL_BR_848 , /*!< Divisor D = 8 : bit rate = 848 */ 00205 RFAL_NFCDEP_Dx_16_1695 = RFAL_BR_1695 , /*!< Divisor D = 16 : bit rate = 1695 */ 00206 RFAL_NFCDEP_Dx_32_3390 = RFAL_BR_3390 , /*!< Divisor D = 32 : bit rate = 3390 */ 00207 RFAL_NFCDEP_Dx_64_6780 = RFAL_BR_6780 /*!< Divisor D = 64 : bit rate = 6780 */ 00208 }; 00209 00210 /*! Enumeration of NFC-DEP Length Reduction (LR) Digital 1.0 Table 91 */ 00211 enum{ 00212 RFAL_NFCDEP_LR_64 = 0x00, /*!< Maximum payload size is 64 bytes */ 00213 RFAL_NFCDEP_LR_128 = 0x01, /*!< Maximum payload size is 128 bytes */ 00214 RFAL_NFCDEP_LR_192 = 0x02, /*!< Maximum payload size is 192 bytes */ 00215 RFAL_NFCDEP_LR_254 = 0x03 /*!< Maximum payload size is 254 bytes */ 00216 }; 00217 00218 /* 00219 ****************************************************************************** 00220 * GLOBAL DATA TYPES 00221 ****************************************************************************** 00222 */ 00223 00224 /*! NFC-DEP callback to check if upper layer has deactivation pending */ 00225 typedef bool (* rfalNfcDepDeactCallback )(void); 00226 00227 00228 /*! Enumeration of the nfcip communication modes */ 00229 typedef enum{ 00230 RFAL_NFCDEP_COMM_PASSIVE , /*!< Passive communication mode */ 00231 RFAL_NFCDEP_COMM_ACTIVE /*!< Active communication mode */ 00232 } rfalNfcDepCommMode ; 00233 00234 00235 /*! Enumeration of the nfcip roles */ 00236 typedef enum{ 00237 RFAL_NFCDEP_ROLE_INITIATOR , /*!< Perform as Initiator */ 00238 RFAL_NFCDEP_ROLE_TARGET /*!< Perform as Target */ 00239 } rfalNfcDepRole ; 00240 00241 00242 /*! Struct that holds all NFCIP configs */ 00243 typedef struct{ 00244 00245 rfalNfcDepRole role ; /*!< Current NFCIP role */ 00246 rfalNfcDepCommMode commMode ; /*!< Current NFCIP communication mode */ 00247 uint8_t oper ; /*!< Operation config similar to NCI 1.0 Table 81 */ 00248 00249 uint8_t did ; /*!< Current Device ID (DID) */ 00250 uint8_t nad ; /*!< Current Node Addressing (NAD) */ 00251 uint8_t bs ; /*!< Bit rate in Sending Direction */ 00252 uint8_t br ; /*!< Bit rate in Receiving Direction */ 00253 uint8_t nfcid[RFAL_NFCDEP_NFCID3_LEN]; /*!< Pointer to the NFCID to be used */ 00254 uint8_t nfcidLen ; /*!< Length of the given NFCID in nfcid */ 00255 uint8_t gb[RFAL_NFCDEP_GB_MAX_LEN]; /*!< Pointer General Bytes (GB) to be used */ 00256 uint8_t gbLen ; /*!< Length of the given GB in gb */ 00257 uint8_t lr ; /*!< Length Reduction (LR) to be used */ 00258 uint8_t to ; /*!< Timeout (TO) to be used */ 00259 uint32_t fwt ; /*!< Frame Waiting Time (FWT) to be used */ 00260 uint32_t dFwt ; /*!< Delta Frame Waiting Time (dFWT) to be used */ 00261 } rfalNfcDepConfigs ; 00262 00263 00264 /*! ATR_REQ command Digital 1.1 16.6.2 */ 00265 typedef struct { 00266 uint8_t CMD1 ; /*!< Command format 0xD4 */ 00267 uint8_t CMD2 ; /*!< Command Value */ 00268 uint8_t NFCID3[RFAL_NFCDEP_NFCID3_LEN]; /*!< NFCID3 value */ 00269 uint8_t DID ; /*!< DID */ 00270 uint8_t BSi ; /*!< Sending Bitrate for Initiator */ 00271 uint8_t BRi ; /*!< Receiving Bitrate for Initiator */ 00272 uint8_t PPi ; /*!< Optional Parameters presence indicator */ 00273 uint8_t GBi[RFAL_NFCDEP_GB_MAX_LEN]; /*!< General Bytes */ 00274 } rfalNfcDepAtrReq ; 00275 00276 00277 /*! ATR_RES response Digital 1.1 16.6.3 */ 00278 typedef struct { 00279 uint8_t CMD1 ; /*!< Response Byte 0xD5 */ 00280 uint8_t CMD2 ; /*!< Command Value */ 00281 uint8_t NFCID3[RFAL_NFCDEP_NFCID3_LEN]; /*!< NFCID3 value */ 00282 uint8_t DID ; /*!< DID */ 00283 uint8_t BSt ; /*!< Sending Bitrate for Initiator */ 00284 uint8_t BRt ; /*!< Receiving Bitrate for Initiator */ 00285 uint8_t TO ; /*!< Timeout */ 00286 uint8_t PPt ; /*!< Optional Parameters presence indicator */ 00287 uint8_t GBt[RFAL_NFCDEP_GB_MAX_LEN]; /*!< General Bytes */ 00288 } rfalNfcDepAtrRes ; 00289 00290 00291 /*! Structure of transmit I-PDU Buffer format from caller */ 00292 typedef struct 00293 { 00294 uint8_t prologue[RFAL_NFCDEP_DEPREQ_HEADER_LEN]; /*!< Prologue space for NFC-DEP header*/ 00295 uint8_t inf[RFAL_NFCDEP_FRAME_SIZE_MAX_LEN]; /*!< INF | Data area of the buffer */ 00296 } rfalNfcDepBufFormat ; 00297 00298 00299 /*! Activation info as Initiator and Target */ 00300 typedef union { 00301 struct { 00302 rfalNfcDepAtrRes ATR_RES ; /*!< ATR RES (Initiator mode) */ 00303 uint8_t ATR_RESLen ; /*!< ATR RES length (Initiator mode) */ 00304 }Target; /*!< Target */ 00305 struct { 00306 rfalNfcDepAtrReq ATR_REQ ; /*!< ATR REQ (Target mode) */ 00307 uint8_t ATR_REQLen ; /*!< ATR REQ length (Target mode) */ 00308 }Initiator; /*!< Initiator */ 00309 } rfalNfcDepActivation ; 00310 00311 00312 /*! NFC-DEP device Info */ 00313 typedef struct { 00314 uint8_t GBLen ; /*!< General Bytes length */ 00315 uint8_t WT ; /*!< FWT to be used (ignored in Listen Mode) */ 00316 uint32_t FWT ; /*!< FWT to be used (ignored in Listen Mode) */ 00317 uint32_t dFWT ; /*!< Delta FWT to be used */ 00318 uint8_t LR ; /*!< Length Reduction coding the max payload */ 00319 uint16_t FS ; /*!< Frame Size */ 00320 rfalBitRate DSI ; /*!< Bit Rate coding from Initiator to Target */ 00321 rfalBitRate DRI ; /*!< Bit Rate coding from Target to Initiator */ 00322 uint8_t DID ; /*!< Device ID (RFAL_NFCDEP_DID_NO if no DID) */ 00323 uint8_t NAD ; /*!< Node ADdress (RFAL_NFCDEP_NAD_NO if no NAD)*/ 00324 } rfalNfcDepInfo ; 00325 00326 00327 /*! NFC-DEP Device structure */ 00328 typedef struct { 00329 rfalNfcDepActivation activation ; /*!< Activation Info */ 00330 rfalNfcDepInfo info ; /*!< NFC-DEP device Info */ 00331 } rfalNfcDepDevice ; 00332 00333 00334 /*! NFCIP Protocol structure for P2P Target 00335 * 00336 * operParam : derives from NFC-Forum NCI NFC-DEP Operation Parameter 00337 * NCI 1.1 Table 86: NFC-DEP Operation Parameter 00338 * and it's a bit mask composed as: 00339 * [ 0000b 00340 * | Chain SHALL use max. Transport Data Byte[1b] 00341 * | I-PDU with no Transport Data SHALL NOT be sent [1b] 00342 * | NFC-DEP Target SHALL NOT send RTOX request [1b] 00343 * ] 00344 * 00345 */ 00346 typedef struct{ 00347 rfalNfcDepCommMode commMode ; /*!< Initiator in Active P2P or Passive P2P*/ 00348 uint8_t operParam ; /*!< NFC-DEP Operation Parameter */ 00349 uint8_t* nfcid ; /*!< Initiator's NFCID2 or NFCID3 */ 00350 uint8_t nfcidLen ; /*!< Initiator's NFCID length (NFCID2/3) */ 00351 uint8_t DID ; /*!< Initiator's Device ID DID */ 00352 uint8_t NAD ; /*!< Initiator's Node ID NAD */ 00353 uint8_t BS ; /*!< Initiator's Bit Rates supported in Tx */ 00354 uint8_t BR ; /*!< Initiator's Bit Rates supported in Rx */ 00355 uint8_t LR ; /*!< Initiator's Length reduction */ 00356 uint8_t* GB ; /*!< Initiator's General Bytes (Gi) */ 00357 uint8_t GBLen ; /*!< Initiator's General Bytes length */ 00358 } rfalNfcDepAtrParam ; 00359 00360 00361 /*! Structure of parameters to be passed in for nfcDepListenStartActivation */ 00362 typedef struct 00363 { 00364 rfalNfcDepBufFormat *rxBuf ; /*!< Receive Buffer struct reference */ 00365 uint16_t *rxLen ; /*!< Receive INF data length in bytes*/ 00366 bool *isRxChaining ; /*!< Received data is not complete */ 00367 rfalNfcDepDevice *nfcDepDev ; /*!< NFC-DEP device info */ 00368 } rfalNfcDepListenActvParam ; 00369 00370 00371 /*! NFCIP Protocol structure for P2P Target 00372 * 00373 * operParam : derives from NFC-Forum NCI NFC-DEP Operation Parameter 00374 * NCI 1.1 Table 86: NFC-DEP Operation Parameter 00375 * and it's a bit mask composed as: 00376 * [ 0000b 00377 * | Chain SHALL use max. Transport Data Byte[1b] 00378 * | I-PDU with no Transport Data SHALL NOT be sent [1b] 00379 * | NFC-DEP Target SHALL NOT send RTOX request [1b] 00380 * ] 00381 * 00382 */ 00383 typedef struct{ 00384 rfalNfcDepCommMode commMode ; /*!< Target in Active P2P or Passive P2P */ 00385 uint8_t nfcid3[RFAL_NFCDEP_NFCID3_LEN]; /*!< Target's NFCID3 */ 00386 uint8_t bst ; /*!< Target's Bit Rates supported in Tx */ 00387 uint8_t brt ; /*!< Target's Bit Rates supported in Rx */ 00388 uint8_t to ; /*!< Target's timeout (TO) value */ 00389 uint8_t ppt ; /*!< Target's Presence optional Params(PPt)*/ 00390 uint8_t GBt[RFAL_NFCDEP_GB_MAX_LEN]; /*!< Target's General Bytes (Gt) */ 00391 uint8_t GBtLen ; /*!< Target's General Bytes length */ 00392 uint8_t operParam ; /*!< NFC-DEP Operation Parameter */ 00393 } rfalNfcDepTargetParam ; 00394 00395 00396 /*! Structure of parameters to be passed in for nfcDepStartIpduTransceive */ 00397 typedef struct 00398 { 00399 rfalNfcDepBufFormat *txBuf ; /*!< Transmit Buffer struct reference */ 00400 uint16_t txBufLen ; /*!< Transmit Buffer INF field length in bytes */ 00401 bool isTxChaining ; /*!< Transmit data is not complete */ 00402 rfalNfcDepBufFormat *rxBuf ; /*!< Receive Buffer struct reference */ 00403 uint16_t *rxLen ; /*!< Receive INF data length */ 00404 bool *isRxChaining ; /*!< Received data is not complete */ 00405 uint32_t FWT ; /*!< FWT to be used (ignored in Listen Mode) */ 00406 uint32_t dFWT ; /*!< Delta FWT to be used */ 00407 uint16_t FSx ; /*!< Other device Frame Size (FSD or FSC) */ 00408 uint8_t DID ; /*!< Device ID (RFAL_ISODEP_NO_DID if no DID) */ 00409 } rfalNfcDepTxRxParam ; 00410 00411 00412 /* 00413 * ***************************************************************************** 00414 * GLOBAL VARIABLE DECLARATIONS 00415 ****************************************************************************** 00416 */ 00417 00418 00419 /* 00420 ****************************************************************************** 00421 * GLOBAL FUNCTION PROTOTYPES 00422 ****************************************************************************** 00423 */ 00424 00425 /*! 00426 ****************************************************************************** 00427 * \brief NFCIP Initialize 00428 * 00429 * This method resets all NFC-DEP inner states, counters and context and sets 00430 * default values 00431 * 00432 ****************************************************************************** 00433 */ 00434 void rfalNfcDepInitialize( void ); 00435 00436 00437 /*! 00438 ****************************************************************************** 00439 * \brief Set deactivating callback 00440 * 00441 * Sets the deactivating callback so that nfcip layer can check if upper layer 00442 * has a deactivation pending, and not perform error recovery upon specific 00443 * errors 00444 * 00445 * \param[in] pFunc : method pointer to deactivation flag check 00446 ****************************************************************************** 00447 */ 00448 void rfalNfcDepSetDeactivatingCallback( rfalNfcDepDeactCallback pFunc ); 00449 00450 00451 /*! 00452 ****************************************************************************** 00453 * \brief Calculate Response Waiting Time 00454 * 00455 * Calculates the Response Waiting Time (RWT) from the given Waiting Time (WT) 00456 * 00457 * \param[in] wt : the WT value to calculate RWT 00458 * 00459 * \return RWT value 00460 ****************************************************************************** 00461 */ 00462 uint32_t rfalNfcDepCalculateRWT( uint8_t wt ); 00463 00464 00465 /*! 00466 ****************************************************************************** 00467 * \brief NFC-DEP Initiator ATR (Attribute Request) 00468 * 00469 * This method configures the NFC-DEP layer with given parameters and then 00470 * sends an ATR to the Target with and checks for a valid response response 00471 * 00472 * \param[in] param : parameters to initialize and compose the ATR 00473 * \param[out] atrRes : location to store the ATR_RES 00474 * \param[out] atrResLen : length of the ATR_RES received 00475 * 00476 * \return ERR_NONE : No error 00477 * \return ERR_TIMEOUT : Timeout occurred 00478 * \return ERR_PROTO : Protocol error occurred 00479 ****************************************************************************** 00480 */ 00481 ReturnCode rfalNfcDepATR( rfalNfcDepAtrParam * param, rfalNfcDepAtrRes *atrRes, uint8_t* atrResLen, 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 ); 00482 00483 00484 /*! 00485 ****************************************************************************** 00486 * \brief NFC-DEP Initiator PSL (Parameter Selection) 00487 * 00488 * This method sends a PSL to the Target with the given parameters and checks 00489 * for a valid response response 00490 * 00491 * The parameters must be coded according to Digital 1.1 16.7.1 00492 * 00493 * \param[in] BRS : the selected Bit Rates for Initiator and Target 00494 * \param[in] FSL : the maximum length of Commands and Responses 00495 * 00496 * \return ERR_NONE : No error 00497 * \return ERR_TIMEOUT : Timeout occurred 00498 * \return ERR_PROTO : Protocol error occurred 00499 ****************************************************************************** 00500 */ 00501 ReturnCode rfalNfcDepPSL( uint8_t BRS, uint8_t FSL, 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 ); 00502 00503 00504 /*! 00505 ****************************************************************************** 00506 * \brief NFC-DEP Initiator DSL (Deselect) 00507 * 00508 * This method checks if the NFCIP module is configured as initiator and if 00509 * so sends a DSL REQ, waits the target's response and checks it 00510 * 00511 * In case of performing as target no action is taken 00512 * 00513 * \return ERR_NONE : No error 00514 * \return ERR_TIMEOUT : Timeout occurred 00515 * \return ERR_MAX_RERUNS : Timeout occurred 00516 * \return ERR_PROTO : Protocol error occurred 00517 ****************************************************************************** 00518 */ 00519 ReturnCode rfalNfcDepDSL( 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 ); 00520 00521 00522 /*! 00523 ****************************************************************************** 00524 * \brief NFC-DEP Initiator RLS (Release) 00525 * 00526 * This method checks if the NFCIP module is configured as initiator and if 00527 * so sends a RLS REQ, waits target's response and checks it 00528 * 00529 * In case of performing as target no action is taken 00530 * 00531 * \return ERR_NONE : No error 00532 * \return ERR_TIMEOUT : Timeout occurred 00533 * \return ERR_MAX_RERUNS : Timeout occurred 00534 * \return ERR_PROTO : Protocol error occurred 00535 ****************************************************************************** 00536 */ 00537 ReturnCode rfalNfcDepRLS( 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 ); 00538 00539 00540 /*! 00541 ***************************************************************************** 00542 * \brief NFC-DEP Initiator Handle Activation 00543 * 00544 * This performs a Activation into NFC-DEP layer with the given 00545 * parameters. It sends ATR_REQ and if the higher bit rates are supported by 00546 * both devices it additionally sends PSL 00547 * Once Activated all details of the device are provided on nfcDepDev 00548 * 00549 * \param[in] param : required parameters to initialize and send ATR_REQ 00550 * \param[in] desiredBR : Desired bit rate supported by the Poller 00551 * \param[out] nfcDepDev : NFC-DEP information of the activated Listen device 00552 * 00553 * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode 00554 * \return ERR_PARAM : Invalid parameters 00555 * \return ERR_IO : Generic internal error 00556 * \return ERR_TIMEOUT : Timeout error 00557 * \return ERR_PAR : Parity error detected 00558 * \return ERR_CRC : CRC error detected 00559 * \return ERR_FRAMING : Framing error detected 00560 * \return ERR_PROTO : Protocol error detected 00561 * \return ERR_NONE : No error, activation successful 00562 ***************************************************************************** 00563 */ 00564 ReturnCode rfalNfcDepInitiatorHandleActivation( rfalNfcDepAtrParam * param, rfalBitRate desiredBR, rfalNfcDepDevice * nfcDepDev, 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 ); 00565 00566 00567 /*! 00568 ****************************************************************************** 00569 * \brief Check if buffer contains valid ATR_REQ 00570 * 00571 * This method checks if the given ATR_REQ is valid 00572 * 00573 * 00574 * \param[in] buf : buffer holding Initiator's received request 00575 * \param[in] bufLen : size of the msg contained on the buf in Bytes 00576 * \param[out] nfcid3 : pointer to where the NFCID3 may be outputed, 00577 * nfcid3 has NFCF_SENSF_NFCID3_LEN as length 00578 * Pass NULL if output parameter not desired 00579 * 00580 * \return true : Valid ATR_REQ received, the ATR_RES has been computed in txBuf 00581 * \return false : Invalid protocol request 00582 * 00583 ****************************************************************************** 00584 */ 00585 bool rfalNfcDepIsAtrReq( uint8_t* buf, uint16_t bufLen, uint8_t* nfcid3 ); 00586 00587 00588 /*! 00589 ****************************************************************************** 00590 * \brief Check is Target has received ATR 00591 * 00592 * This method checks if the NFCIP module is configured as target and if a 00593 * ATR REQ has been received ( whether is in activation or in data exchange) 00594 * 00595 * \return true : a ATR has already been received 00596 * \return false : no ATR has been received 00597 ****************************************************************************** 00598 */ 00599 bool rfalNfcDepTargetRcvdATR( void ); 00600 00601 /*! 00602 ***************************************************************************** 00603 * \brief NFCDEP Start Listen Activation Handling 00604 * 00605 * Start Activation Handling and setup to receive first frame which may 00606 * contain complete or partial DEP-REQ after activation is completed 00607 * 00608 * Pass in ATR_REQ for NFC-DEP to handle ATR_RES. The Activation Handling 00609 * handles ATR_RES and PSL_RES if a PSL_REQ is received 00610 * 00611 * Activation is completed if PSL_RES is sent or if first I-PDU is received 00612 * 00613 * \ref rfalNfcDepListenGetActivationStatus() provide status of the 00614 * ongoing activation 00615 * 00616 * \warning nfcDepGetTransceiveStatus() shall be called right after activation 00617 * is completed (i.e. rfalNfcDepListenGetActivationStatus() return ERR_NONE) 00618 * to check for first received frame. 00619 * 00620 * \param[in] param : Target parameters to be used 00621 * \param[in] atrReq : reference to buffer containing ATR_REQ 00622 * \param[in] atrReqLength: Length of ATR_REQ 00623 * \param[out] rxParam : references to buffer, length and chaining indication 00624 * for first complete LLCP to be received 00625 * 00626 * \return ERR_NONE : ATR_REQ is valid and activation ongoing 00627 * \return ERR_PARAM : ATR_REQ or other params are invalid 00628 * \return ERR_LINK_LOSS : Remote Field is turned off 00629 ***************************************************************************** 00630 */ 00631 ReturnCode rfalNfcDepListenStartActivation( rfalNfcDepTargetParam *param, uint8_t *atrReq, uint16_t atrReqLength, rfalNfcDepListenActvParam 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 ); 00632 00633 00634 /*! 00635 ***************************************************************************** 00636 * \brief Get the current NFC-DEP Activation Status 00637 * 00638 * \return ERR_NONE : Activation has completed successfully 00639 * \return ERR_BUSY : Activation is ongoing 00640 * \return ERR_LINK_LOSS : Remote Field was turned off 00641 ***************************************************************************** 00642 */ 00643 ReturnCode rfalNfcDepListenGetActivationStatus( 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 Start Transceive 00648 * 00649 * Transceives a complete or partial DEP block 00650 * 00651 * The txBuf contains complete or partial of DEP to be transmitted. 00652 * The Prologue field of the I-PDU is handled internally 00653 * 00654 * If the buffer contains partial LLCP and is not the last block, then 00655 * isTxChaining must be set to true 00656 * 00657 * \param[in] param: reference parameters to be used for the Transceive 00658 * 00659 * \return ERR_PARAM : Bad request 00660 * \return ERR_WRONG_STATE : The module is not in a proper state 00661 * \return ERR_NONE : The Transceive request has been started 00662 ***************************************************************************** 00663 */ 00664 ReturnCode rfalNfcDepStartTransceive( rfalNfcDepTxRxParam *param ); 00665 00666 00667 /*! 00668 ***************************************************************************** 00669 * \brief Return the Transceive status 00670 * 00671 * Returns the status of the NFC-DEP Transceive 00672 * 00673 * \warning When the other device is performing chaining once a chained 00674 * block is received the error ERR_AGAIN is sent. At this point 00675 * caller must handle the received data immediately. 00676 * When ERR_AGAIN is returned an ACK has already been sent to 00677 * the other device and the next block might be incoming. 00678 * If rfalWorker() is called frequently it will place the next 00679 * block on the given buffer 00680 * 00681 * \return ERR_NONE : Transceive has been completed successfully 00682 * \return ERR_BUSY : Transceive is ongoing 00683 * \return ERR_PROTO : Protocol error occurred 00684 * \return ERR_TIMEOUT : Timeout error occurred 00685 * \return ERR_SLEEP_REQ : Deselect has been received and responded 00686 * \return ERR_NOMEM : The received I-PDU does not fit into the 00687 * receive buffer 00688 * \return ERR_LINK_LOSS : Communication is lost because Reader/Writer 00689 * has turned off its field 00690 * \return ERR_AGAIN : received one chaining block, continue to call 00691 * this method to retrieve the remaining blocks 00692 ***************************************************************************** 00693 */ 00694 ReturnCode rfalNfcDepGetTransceiveStatus( 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 ); 00695 00696 00697 #endif /* RFAL_NFCDEP_H_ */ 00698 00699 /** 00700 * @} 00701 * 00702 * @} 00703 * 00704 * @} 00705 */
Generated on Sat Jul 16 2022 13:00:53 by
1.7.2