rfal_isoDep.h 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092
  1. /******************************************************************************
  2. * \attention
  3. *
  4. * <h2><center>&copy; COPYRIGHT 2020 STMicroelectronics</center></h2>
  5. *
  6. * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License");
  7. * You may not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at:
  9. *
  10. * www.st.com/myliberty
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
  15. * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
  17. * See the License for the specific language governing permissions and
  18. * limitations under the License.
  19. *
  20. ******************************************************************************/
  21. /*
  22. * PROJECT: ST25R391x firmware
  23. * Revision:
  24. * LANGUAGE: ISO C99
  25. */
  26. /*! \file rfal_isoDep.h
  27. *
  28. * \author Gustavo Patricio
  29. *
  30. * \brief Implementation of ISO-DEP protocol
  31. *
  32. * This implementation was based on the following specs:
  33. * - ISO/IEC 14443-4 2nd Edition 2008-07-15
  34. * - NFC Forum Digital Protocol 1.1 2014-01-14
  35. *
  36. *
  37. * \addtogroup RFAL
  38. * @{
  39. *
  40. * \addtogroup RFAL-AL
  41. * \brief RFAL Abstraction Layer
  42. * @{
  43. *
  44. * \addtogroup ISO-DEP
  45. * \brief RFAL ISO-DEP Module
  46. * @{
  47. *
  48. */
  49. #ifndef RFAL_ISODEP_H_
  50. #define RFAL_ISODEP_H_
  51. /*
  52. ******************************************************************************
  53. * INCLUDES
  54. ******************************************************************************
  55. */
  56. #include "../platform.h"
  57. #include "rfal_nfcb.h"
  58. /*
  59. ******************************************************************************
  60. * ENABLE SWITCH
  61. ******************************************************************************
  62. */
  63. #ifndef RFAL_FEATURE_ISO_DEP
  64. #define RFAL_FEATURE_ISO_DEP \
  65. false /*!< ISO-DEP module configuration missing. Disabled by default */
  66. #endif
  67. /* If module is disabled remove the need for the user to set lengths */
  68. #if !RFAL_FEATURE_ISO_DEP
  69. #undef RFAL_FEATURE_ISO_DEP_IBLOCK_MAX_LEN
  70. #undef RFAL_FEATURE_ISO_DEP_APDU_MAX_LEN
  71. #define RFAL_FEATURE_ISO_DEP_IBLOCK_MAX_LEN (1U) /*!< ISO-DEP I-Block max length, set to "none" */
  72. #define RFAL_FEATURE_ISO_DEP_APDU_MAX_LEN (1U) /*!< ISO-DEP APDU max length, set to "none" */
  73. #endif /* !RFAL_FEATURE_NFC_DEP */
  74. /*
  75. ******************************************************************************
  76. * DEFINES
  77. ******************************************************************************
  78. */
  79. #define RFAL_ISODEP_PROLOGUE_SIZE \
  80. (3U) /*!< Length of Prologue Field for I-Block Format */
  81. #define RFAL_ISODEP_PCB_LEN \
  82. (1U) /*!< PCB length */
  83. #define RFAL_ISODEP_DID_LEN \
  84. (1U) /*!< DID length */
  85. #define RFAL_ISODEP_NAD_LEN \
  86. (1U) /*!< NAD length */
  87. #define RFAL_ISODEP_NO_DID \
  88. (0x00U) /*!< DID value indicating the ISO-DEP layer not to use DID */
  89. #define RFAL_ISODEP_NO_NAD \
  90. (0xFFU) /*!< NAD value indicating the ISO-DEP layer not to use NAD */
  91. #define RFAL_ISODEP_FWI_MASK \
  92. (0xF0U) /*!< Mask bits of FWI */
  93. #define RFAL_ISODEP_FWI_SHIFT \
  94. (4U) /*!< Shift val of FWI */
  95. #define RFAL_ISODEP_FWI_DEFAULT \
  96. (4U) /*!< Default value for FWI Digital 1.0 11.6.2.17 */
  97. #define RFAL_ISODEP_ADV_FEATURE \
  98. (0x0FU) /*!< Indicate 256 Bytes FSD and Advanc Proto Feature support:NAD & DID */
  99. #define RFAL_ISODEP_DID_MAX \
  100. (14U) /*!< Maximum DID value */
  101. #define RFAL_ISODEP_BRI_MASK \
  102. (0x07U) /*!< Mask bits for Poll to Listen Send bitrate */
  103. #define RFAL_ISODEP_BSI_MASK \
  104. (0x70U) /*!< Mask bits for Listen to Poll Send bitrate */
  105. #define RFAL_ISODEP_SAME_BITRATE_MASK \
  106. (0x80U) /*!< Mask bit indicate only same bit rate D for both direction support */
  107. #define RFAL_ISODEP_BITRATE_RFU_MASK \
  108. (0x08U) /*!< Mask bit for RFU */
  109. /*! Maximum Frame Waiting Time = ((256 * 16/fc) * 2^FWImax) = ((256*16/fc)*2^14) = (67108864)/fc = 2^26 (1/fc) */
  110. #define RFAL_ISODEP_MAX_FWT ((uint32_t)1U << 26)
  111. #define RFAL_ISODEP_FSDI_DEFAULT \
  112. RFAL_ISODEP_FSXI_256 /*!< Default Frame Size Integer in Poll mode */
  113. #define RFAL_ISODEP_FSX_KEEP (0xFFU) /*!< Flag to keep FSX from activation */
  114. #define RFAL_ISODEP_DEFAULT_FSCI \
  115. RFAL_ISODEP_FSXI_256 /*!< FSCI default value to be used in Listen Mode */
  116. #define RFAL_ISODEP_DEFAULT_FSC \
  117. RFAL_ISODEP_FSX_256 /*!< FSC default value (aligned RFAL_ISODEP_DEFAULT_FSCI) */
  118. #define RFAL_ISODEP_DEFAULT_SFGI (0U) /*!< SFGI Default value to be used in Listen Mode */
  119. #define RFAL_ISODEP_DEFAULT_FWI (8U) /*!< Default Listener FWI (Max) Digital 2.0 B7 & B3 */
  120. #define RFAL_ISODEP_APDU_MAX_LEN \
  121. RFAL_ISODEP_FSX_1024 /*!< Max APDU length */
  122. #define RFAL_ISODEP_ATTRIB_RES_MBLI_NO_INFO \
  123. (0x00U) /*!< MBLI indicating no information on its internal input buffer size */
  124. #define RFAL_ISODEP_ATTRIB_REQ_PARAM1_DEFAULT \
  125. (0x00U) /*!< Default values of Param 1 of ATTRIB_REQ Digital 1.0 12.6.1.3-5 */
  126. #define RFAL_ISODEP_ATTRIB_HLINFO_LEN \
  127. (32U) /*!< Maximum Size of Higher Layer Information */
  128. #define RFAL_ISODEP_ATS_HB_MAX_LEN \
  129. (15U) /*!< Maximum length of Historical Bytes Digital 1.1 13.6.2.23 */
  130. #define RFAL_ISODEP_ATTRIB_REQ_MIN_LEN \
  131. (9U) /*!< Minimum Length of ATTRIB_REQ command */
  132. #define RFAL_ISODEP_ATTRIB_RES_MIN_LEN \
  133. (1U) /*!< Minimum Length of ATTRIB_RES response */
  134. #define RFAL_ISODEP_SPARAM_VALUES_MAX_LEN \
  135. (16U) /*!< Maximum Length of the value field on S(PARAMETERS) */
  136. #define RFAL_ISODEP_SPARAM_TAG_BLOCKINFO \
  137. (0xA0U) /*!< S(PARAMETERS) tag Block information */
  138. #define RFAL_ISODEP_SPARAM_TAG_BRREQ \
  139. (0xA1U) /*!< S(PARAMETERS) tag Bit rates Request */
  140. #define RFAL_ISODEP_SPARAM_TAG_BRIND \
  141. (0xA2U) /*!< S(PARAMETERS) tag Bit rates Indication */
  142. #define RFAL_ISODEP_SPARAM_TAG_BRACT \
  143. (0xA3U) /*!< S(PARAMETERS) tag Bit rates Activation */
  144. #define RFAL_ISODEP_SPARAM_TAG_BRACK \
  145. (0xA4U) /*!< S(PARAMETERS) tag Bit rates Acknowledgement */
  146. #define RFAL_ISODEP_SPARAM_TAG_SUP_PCD2PICC \
  147. (0x80U) /*!< S(PARAMETERS) tag Supported bit rates from PCD to PICC */
  148. #define RFAL_ISODEP_SPARAM_TAG_SUP_PICC2PCD \
  149. (0x81U) /*!< S(PARAMETERS) tag Supported bit rates from PICC to PCD */
  150. #define RFAL_ISODEP_SPARAM_TAG_SUP_FRAME \
  151. (0x82U) /*!< S(PARAMETERS) tag Supported framing options PICC to PCD */
  152. #define RFAL_ISODEP_SPARAM_TAG_SEL_PCD2PICC \
  153. (0x83U) /*!< S(PARAMETERS) tag Selected bit rate from PCD to PICC */
  154. #define RFAL_ISODEP_SPARAM_TAG_SEL_PICC2PCD \
  155. (0x84U) /*!< S(PARAMETERS) tag Selected bit rate from PICC to PCD */
  156. #define RFAL_ISODEP_SPARAM_TAG_SEL_FRAME \
  157. (0x85U) /*!< S(PARAMETERS) tag Selected framing options PICC to PCD */
  158. #define RFAL_ISODEP_SPARAM_TAG_LEN \
  159. (1) /*!< S(PARAMETERS) Tag Length */
  160. #define RFAL_ISODEP_SPARAM_TAG_BRREQ_LEN \
  161. (0U) /*!< S(PARAMETERS) tag Bit rates Request Length */
  162. #define RFAL_ISODEP_SPARAM_TAG_PICC2PCD_LEN \
  163. (2U) /*!< S(PARAMETERS) bit rates from PCD to PICC Length */
  164. #define RFAL_ISODEP_SPARAM_TAG_PCD2PICC_LEN \
  165. (2U) /*!< S(PARAMETERS) bit rates from PICC to PCD Length */
  166. #define RFAL_ISODEP_SPARAM_TAG_BRACK_LEN \
  167. (0U) /*!< S(PARAMETERS) tag Bit rates Acknowledgement Length */
  168. #define RFAL_ISODEP_ATS_TA_DPL_212 \
  169. (0x01U) /*!< ATS TA DSI 212 kbps support bit mask */
  170. #define RFAL_ISODEP_ATS_TA_DPL_424 \
  171. (0x02U) /*!< ATS TA DSI 424 kbps support bit mask */
  172. #define RFAL_ISODEP_ATS_TA_DPL_848 \
  173. (0x04U) /*!< ATS TA DSI 848 kbps support bit mask */
  174. #define RFAL_ISODEP_ATS_TA_DLP_212 \
  175. (0x10U) /*!< ATS TA DSI 212 kbps support bit mask */
  176. #define RFAL_ISODEP_ATS_TA_DLP_424 \
  177. (0x20U) /*!< ATS TA DRI 424 kbps support bit mask */
  178. #define RFAL_ISODEP_ATS_TA_DLP_848 \
  179. (0x40U) /*!< ATS TA DRI 848 kbps support bit mask */
  180. #define RFAL_ISODEP_ATS_TA_SAME_D \
  181. (0x80U) /*!< ATS TA same bit both directions bit mask */
  182. #define RFAL_ISODEP_ATS_TB_FWI_MASK \
  183. (0xF0U) /*!< Mask bits for FWI (Frame Waiting Integer) in TB byte */
  184. #define RFAL_ISODEP_ATS_TB_SFGI_MASK \
  185. (0x0FU) /*!< Mask bits for SFGI (Start-Up Frame Guard Integer) in TB byte */
  186. #define RFAL_ISODEP_ATS_T0_TA_PRESENCE_MASK \
  187. (0x10U) /*!< Mask bit for TA presence */
  188. #define RFAL_ISODEP_ATS_T0_TB_PRESENCE_MASK \
  189. (0x20U) /*!< Mask bit for TB presence */
  190. #define RFAL_ISODEP_ATS_T0_TC_PRESENCE_MASK \
  191. (0x40U) /*!< Mask bit for TC presence */
  192. #define RFAL_ISODEP_ATS_T0_FSCI_MASK \
  193. (0x0FU) /*!< Mask bit for FSCI presence */
  194. #define RFAL_ISODEP_ATS_T0_OFFSET \
  195. (0x01U) /*!< Offset of T0 in ATS Response */
  196. #define RFAL_ISODEP_MAX_I_RETRYS \
  197. (2U) /*!< Number of retries for a I-Block Digital 2.0 16.2.5.4 */
  198. #define RFAL_ISODEP_MAX_R_RETRYS \
  199. (3U) /*!< Number of retries for a R-Block Digital 2.0 B9 - nRETRY ACK/NAK: [2,5] */
  200. #define RFAL_ISODEP_MAX_WTX_NACK_RETRYS \
  201. (3U) /*!< Number of S(WTX) replied with NACK Digital 2.0 B9 - nRETRY WTX[2,5] */
  202. #define RFAL_ISODEP_MAX_WTX_RETRYS \
  203. (20U) /*!< Number of overall S(WTX) retries Digital 2.0 16.2.5.2 */
  204. #define RFAL_ISODEP_MAX_WTX_RETRYS_ULTD \
  205. (255U) /*!< Use unlimited number of overall S(WTX) */
  206. #define RFAL_ISODEP_MAX_DSL_RETRYS \
  207. (0U) /*!< Number of retries for a S(DESELECT) Digital 2.0 B9 - nRETRY DESELECT: [0,5] */
  208. #define RFAL_ISODEP_RATS_RETRIES \
  209. (1U) /*!< RATS retries upon fail Digital 2.0 B7 - nRETRY RATS [0,1] */
  210. /*! Frame Size for Proximity Card Integer definitions */
  211. typedef enum {
  212. RFAL_ISODEP_FSXI_16 =
  213. 0, /*!< Frame Size for Proximity Card Integer with 16 bytes */
  214. RFAL_ISODEP_FSXI_24 =
  215. 1, /*!< Frame Size for Proximity Card Integer with 24 bytes */
  216. RFAL_ISODEP_FSXI_32 =
  217. 2, /*!< Frame Size for Proximity Card Integer with 32 bytes */
  218. RFAL_ISODEP_FSXI_40 =
  219. 3, /*!< Frame Size for Proximity Card Integer with 40 bytes */
  220. RFAL_ISODEP_FSXI_48 =
  221. 4, /*!< Frame Size for Proximity Card Integer with 48 bytes */
  222. RFAL_ISODEP_FSXI_64 =
  223. 5, /*!< Frame Size for Proximity Card Integer with 64 bytes */
  224. RFAL_ISODEP_FSXI_96 =
  225. 6, /*!< Frame Size for Proximity Card Integer with 96 bytes */
  226. RFAL_ISODEP_FSXI_128 =
  227. 7, /*!< Frame Size for Proximity Card Integer with 128 bytes */
  228. RFAL_ISODEP_FSXI_256 =
  229. 8, /*!< Frame Size for Proximity Card Integer with 256 bytes */
  230. RFAL_ISODEP_FSXI_512 =
  231. 9, /*!< Frame Size for Proximity Card Integer with 512 bytes ISO14443-3 Amd2 2012 */
  232. RFAL_ISODEP_FSXI_1024 =
  233. 10, /*!< Frame Size for Proximity Card Integer with 1024 bytes ISO14443-3 Amd2 2012 */
  234. RFAL_ISODEP_FSXI_2048 =
  235. 11, /*!< Frame Size for Proximity Card Integer with 2048 bytes ISO14443-3 Amd2 2012 */
  236. RFAL_ISODEP_FSXI_4096 =
  237. 12 /*!< Frame Size for Proximity Card Integer with 4096 bytes ISO14443-3 Amd2 2012 */
  238. } rfalIsoDepFSxI;
  239. /*! Frame Size for Proximity Card definitions */
  240. typedef enum {
  241. RFAL_ISODEP_FSX_16 =
  242. 16, /*!< Frame Size for Proximity Card with 16 bytes */
  243. RFAL_ISODEP_FSX_24 =
  244. 24, /*!< Frame Size for Proximity Card with 24 bytes */
  245. RFAL_ISODEP_FSX_32 =
  246. 32, /*!< Frame Size for Proximity Card with 32 bytes */
  247. RFAL_ISODEP_FSX_40 =
  248. 40, /*!< Frame Size for Proximity Card with 40 bytes */
  249. RFAL_ISODEP_FSX_48 =
  250. 48, /*!< Frame Size for Proximity Card with 48 bytes */
  251. RFAL_ISODEP_FSX_64 =
  252. 64, /*!< Frame Size for Proximity Card with 64 bytes */
  253. RFAL_ISODEP_FSX_96 =
  254. 96, /*!< Frame Size for Proximity Card with 96 bytes */
  255. RFAL_ISODEP_FSX_128 =
  256. 128, /*!< Frame Size for Proximity Card with 128 bytes */
  257. RFAL_ISODEP_FSX_256 =
  258. 256, /*!< Frame Size for Proximity Card with 256 bytes */
  259. RFAL_ISODEP_FSX_512 =
  260. 512, /*!< Frame Size for Proximity Card with 512 bytes ISO14443-3 Amd2 2012 */
  261. RFAL_ISODEP_FSX_1024 =
  262. 1024, /*!< Frame Size for Proximity Card with 1024 bytes ISO14443-3 Amd2 2012 */
  263. RFAL_ISODEP_FSX_2048 =
  264. 2048, /*!< Frame Size for Proximity Card with 2048 bytes ISO14443-3 Amd2 2012 */
  265. RFAL_ISODEP_FSX_4096 =
  266. 4096, /*!< Frame Size for Proximity Card with 4096 bytes ISO14443-3 Amd2 2012 */
  267. } rfalIsoDepFSx;
  268. /*
  269. ******************************************************************************
  270. * GLOBAL MACROS
  271. ******************************************************************************
  272. */
  273. /*
  274. ******************************************************************************
  275. * GLOBAL DATA TYPES
  276. ******************************************************************************
  277. */
  278. /*! RATS format Digital 1.1 13.6.1 */
  279. typedef struct {
  280. uint8_t CMD; /*!< RATS command byte: 0xE0 */
  281. uint8_t PARAM; /*!< Param indicating FSDI and DID */
  282. } rfalIsoDepRats;
  283. /*! ATS response format Digital 1.1 13.6.2 */
  284. typedef struct {
  285. uint8_t TL; /*!< Length Byte, including TL byte itself */
  286. uint8_t T0; /*!< Format Byte T0 indicating if TA, TB, TC */
  287. uint8_t TA; /*!< Interface Byte TA(1) */
  288. uint8_t TB; /*!< Interface Byte TB(1) */
  289. uint8_t TC; /*!< Interface Byte TC(1) */
  290. uint8_t HB[RFAL_ISODEP_ATS_HB_MAX_LEN]; /*!< Historical Bytes */
  291. } rfalIsoDepAts;
  292. /*! PPS Request format (Protocol and Parameter Selection) ISO14443-4 5.3 */
  293. typedef struct {
  294. uint8_t PPSS; /*!< Start Byte: [ 1101b | CID[4b] ] */
  295. uint8_t PPS0; /*!< Parameter 0:[ 000b | PPS1[1n] | 0001b ] */
  296. uint8_t PPS1; /*!< Parameter 1:[ 0000b | DSI[2b] | DRI[2b] ]*/
  297. } rfalIsoDepPpsReq;
  298. /*! PPS Response format (Protocol and Parameter Selection) ISO14443-4 5.4 */
  299. typedef struct {
  300. uint8_t PPSS; /*!< Start Byte: [ 1101b | CID[4b] ] */
  301. } rfalIsoDepPpsRes;
  302. /*! ATTRIB Command Format Digital 1.1 15.6.1 */
  303. typedef struct {
  304. uint8_t cmd; /*!< ATTRIB_REQ command byte */
  305. uint8_t nfcid0[RFAL_NFCB_NFCID0_LEN]; /*!< NFCID0 of the card to be selected */
  306. struct {
  307. uint8_t PARAM1; /*!< PARAM1 of ATTRIB command */
  308. uint8_t PARAM2; /*!< PARAM2 of ATTRIB command */
  309. uint8_t PARAM3; /*!< PARAM3 of ATTRIB command */
  310. uint8_t PARAM4; /*!< PARAM4 of ATTRIB command */
  311. } Param; /*!< Parameter of ATTRIB command */
  312. uint8_t HLInfo[RFAL_ISODEP_ATTRIB_HLINFO_LEN]; /*!< Higher Layer Information */
  313. } rfalIsoDepAttribCmd;
  314. /*! ATTRIB Response Format Digital 1.1 15.6.2 */
  315. typedef struct {
  316. uint8_t mbliDid; /*!< Contains MBLI and DID */
  317. uint8_t HLInfo[RFAL_ISODEP_ATTRIB_HLINFO_LEN]; /*!< Higher Layer Information */
  318. } rfalIsoDepAttribRes;
  319. /*! S(Parameters) Command Format ISO14443-4 (2016) Table 4 */
  320. typedef struct {
  321. uint8_t tag; /*!< S(PARAMETERS) Tag field */
  322. uint8_t length; /*!< S(PARAMETERS) Length field */
  323. uint8_t value[RFAL_ISODEP_SPARAM_VALUES_MAX_LEN]; /*!< S(PARAMETERS) Value field */
  324. } rfalIsoDepSParameter;
  325. /*! Activation info as Poller and Listener for NFC-A and NFC-B */
  326. typedef union { /* PRQA S 0750 # MISRA 19.2 - Both members of the union will not be used concurrently, device is only of type A or B at a time. Thus no problem can occur. */
  327. /*! NFC-A information */
  328. union { /* PRQA S 0750 # MISRA 19.2 - Both members of the union will not be used concurrently, device is only PCD or PICC at a time. Thus no problem can occur. */
  329. struct {
  330. rfalIsoDepAts ATS; /*!< ATS response (Poller mode) */
  331. uint8_t ATSLen; /*!< ATS response length (Poller mode) */
  332. } Listener;
  333. struct {
  334. rfalIsoDepRats RATS; /*!< RATS request (Listener mode) */
  335. } Poller;
  336. } A;
  337. /*! NFC-B information */
  338. union { /* PRQA S 0750 # MISRA 19.2 - Both members of the union will not be used concurrently, device is only PCD or PICC at a time. Thus no problem can occur. */
  339. struct {
  340. rfalIsoDepAttribRes ATTRIB_RES; /*!< ATTRIB_RES (Poller mode) */
  341. uint8_t ATTRIB_RESLen; /*!< ATTRIB_RES length (Poller mode) */
  342. } Listener;
  343. struct {
  344. rfalIsoDepAttribCmd ATTRIB; /*!< ATTRIB request (Listener mode) */
  345. uint8_t ATTRIBLen; /*!< ATTRIB request length (Listener mode) */
  346. } Poller;
  347. } B;
  348. } rfalIsoDepActivation;
  349. /*! ISO-DEP device Info */
  350. typedef struct {
  351. uint8_t FWI; /*!< Frame Waiting Integer */
  352. uint32_t FWT; /*!< Frame Waiting Time (1/fc) */
  353. uint32_t dFWT; /*!< Delta Frame Waiting Time (1/fc) */
  354. uint32_t SFGI; /*!< Start-up Frame Guard time Integer */
  355. uint32_t SFGT; /*!< Start-up Frame Guard Time (ms) */
  356. uint8_t FSxI; /*!< Frame Size Device/Card Integer (FSDI or FSCI) */
  357. uint16_t FSx; /*!< Frame Size Device/Card (FSD or FSC) */
  358. uint32_t MBL; /*!< Maximum Buffer Length (optional for NFC-B) */
  359. rfalBitRate DSI; /*!< Bit Rate coding from Listener (PICC) to Poller (PCD) */
  360. rfalBitRate DRI; /*!< Bit Rate coding from Poller (PCD) to Listener (PICC) */
  361. uint8_t DID; /*!< Device ID */
  362. uint8_t NAD; /*!< Node ADdress */
  363. bool supDID; /*!< DID supported flag */
  364. bool supNAD; /*!< NAD supported flag */
  365. bool supAdFt; /*!< Advanced Features supported flag */
  366. } rfalIsoDepInfo;
  367. /*! ISO-DEP Device structure */
  368. typedef struct {
  369. rfalIsoDepActivation activation; /*!< Activation Info */
  370. rfalIsoDepInfo info; /*!< ISO-DEP (ISO14443-4) device Info */
  371. } rfalIsoDepDevice;
  372. /*! ATTRIB Response parameters */
  373. typedef struct {
  374. uint8_t mbli; /*!< MBLI */
  375. uint8_t HLInfo[RFAL_ISODEP_ATTRIB_HLINFO_LEN]; /*!< Hi Layer Information */
  376. uint8_t HLInfoLen; /*!< Hi Layer Information Length */
  377. } rfalIsoDepAttribResParam;
  378. /*! ATS Response parameter */
  379. typedef struct {
  380. uint8_t fsci; /*!< Frame Size of Proximity Card Integer */
  381. uint8_t fwi; /*!< Frame Waiting Time Integer */
  382. uint8_t sfgi; /*!< Start-Up Frame Guard Time Integer */
  383. bool didSupport; /*!< DID Supported */
  384. uint8_t ta; /*!< Max supported bitrate both direction */
  385. uint8_t* hb; /*!< Historical Bytes data */
  386. uint8_t hbLen; /*!< Historical Bytes Length */
  387. } rfalIsoDepAtsParam;
  388. /*! Structure of I-Block Buffer format from caller */
  389. typedef struct {
  390. uint8_t prologue[RFAL_ISODEP_PROLOGUE_SIZE]; /*!< Prologue/SoD buffer */
  391. uint8_t
  392. inf[RFAL_FEATURE_ISO_DEP_IBLOCK_MAX_LEN]; /*!< INF/Payload buffer */
  393. } rfalIsoDepBufFormat;
  394. /*! Structure of APDU Buffer format from caller */
  395. typedef struct {
  396. uint8_t prologue[RFAL_ISODEP_PROLOGUE_SIZE]; /*!< Prologue/SoD buffer */
  397. uint8_t apdu[RFAL_FEATURE_ISO_DEP_APDU_MAX_LEN]; /*!< APDU/Payload buffer */
  398. } rfalIsoDepApduBufFormat;
  399. /*! Listen Activation Parameters Structure */
  400. typedef struct {
  401. rfalIsoDepBufFormat* rxBuf; /*!< Receive Buffer struct reference */
  402. uint16_t* rxLen; /*!< Received INF data length in Bytes */
  403. bool* isRxChaining; /*!< Received data is not complete */
  404. rfalIsoDepDevice* isoDepDev; /*!< ISO-DEP device info */
  405. } rfalIsoDepListenActvParam;
  406. /*! Structure of parameters used on ISO DEP Transceive */
  407. typedef struct {
  408. rfalIsoDepBufFormat* txBuf; /*!< Transmit Buffer struct reference */
  409. uint16_t txBufLen; /*!< Transmit Buffer INF field length in Bytes*/
  410. bool isTxChaining; /*!< Transmit data is not complete */
  411. rfalIsoDepBufFormat* rxBuf; /*!< Receive Buffer struct reference in Bytes */
  412. uint16_t* rxLen; /*!< Received INF data length in Bytes */
  413. bool* isRxChaining; /*!< Received data is not complete */
  414. uint32_t FWT; /*!< FWT to be used (ignored in Listen Mode) */
  415. uint32_t dFWT; /*!< Delta FWT to be used */
  416. uint16_t ourFSx; /*!< Our device Frame Size (FSD or FSC) */
  417. uint16_t FSx; /*!< Other device Frame Size (FSD or FSC) */
  418. uint8_t DID; /*!< Device ID (RFAL_ISODEP_NO_DID if no DID) */
  419. } rfalIsoDepTxRxParam;
  420. /*! Structure of parameters used on ISO DEP APDU Transceive */
  421. typedef struct {
  422. rfalIsoDepApduBufFormat* txBuf; /*!< Transmit Buffer struct reference */
  423. uint16_t txBufLen; /*!< Transmit Buffer INF field length in Bytes*/
  424. rfalIsoDepApduBufFormat* rxBuf; /*!< Receive Buffer struct reference in Bytes */
  425. uint16_t* rxLen; /*!< Received INF data length in Bytes */
  426. rfalIsoDepBufFormat* tmpBuf; /*!< Temp buffer for Rx I-Blocks (internal) */
  427. uint32_t FWT; /*!< FWT to be used (ignored in Listen Mode) */
  428. uint32_t dFWT; /*!< Delta FWT to be used */
  429. uint16_t FSx; /*!< Other device Frame Size (FSD or FSC) */
  430. uint16_t ourFSx; /*!< Our device Frame Size (FSD or FSC) */
  431. uint8_t DID; /*!< Device ID (RFAL_ISODEP_NO_DID if no DID) */
  432. } rfalIsoDepApduTxRxParam;
  433. /*
  434. ******************************************************************************
  435. * GLOBAL FUNCTION PROTOTYPES
  436. ******************************************************************************
  437. */
  438. /*!
  439. ******************************************************************************
  440. * \brief Initialize the ISO-DEP protocol
  441. *
  442. * Initialize the ISO-DEP protocol layer with default config
  443. ******************************************************************************
  444. */
  445. void rfalIsoDepInitialize(void);
  446. /*!
  447. ******************************************************************************
  448. * \brief Initialize the ISO-DEP protocol
  449. *
  450. * Initialize the ISO-DEP protocol layer with additional parameters allowing
  451. * to customise the protocol layer for specific behaviours
  452. *
  453. * \param[in] compMode : Compliance mode to be performed
  454. * \param[in] maxRetriesR : Number of retries for a R-Block
  455. * Digital 2.0 B9 - nRETRY ACK/NAK: [2,5]
  456. * \param[in] maxRetriesSnWTX : Number of retries for a S(WTX) (only in case
  457. * of NAKs) Digital 2.0 B9 - nRETRY WTX[2,5]
  458. * \param[in] maxRetriesSWTX : Number of overall S(WTX) retries.
  459. * Use RFAL_ISODEP_MAX_WTX_RETRYS_ULTD for disabling
  460. * this limit check Digital 2.0 16.2.5.2
  461. * \param[in] maxRetriesSDSL : Number of retries for a S(DESELECT)
  462. * Digital 2.0 B9 - nRETRY DESELECT: [0,5]
  463. * \param[in] maxRetriesI : Number of retries for a I-Block
  464. * Digital 2.0 16.2.5.4
  465. * \param[in] maxRetriesRATS : Number of retries for RATS
  466. * Digital 2.0 B7 - nRETRY RATS [0,1]
  467. *
  468. ******************************************************************************
  469. */
  470. void rfalIsoDepInitializeWithParams(
  471. rfalComplianceMode compMode,
  472. uint8_t maxRetriesR,
  473. uint8_t maxRetriesSnWTX,
  474. uint8_t maxRetriesSWTX,
  475. uint8_t maxRetriesSDSL,
  476. uint8_t maxRetriesI,
  477. uint8_t maxRetriesRATS);
  478. /*!
  479. *****************************************************************************
  480. * \brief FSxI to FSx
  481. *
  482. * Convert Frame Size for proximity coupling Device Integer (FSxI) to
  483. * Frame Size for proximity coupling Device (FSx)
  484. *
  485. * FSD - maximum frame size for NFC Forum Device in Poll Mode
  486. * FSC - maximum frame size for NFC Forum Device in Listen Mode
  487. *
  488. * FSxI = FSDI or FSCI
  489. * FSx = FSD or FSC
  490. *
  491. * The FSD/FSC value includes the header and CRC
  492. *
  493. * \param[in] FSxI : Frame Size for proximity coupling Device Integer
  494. *
  495. * \return fsx : Frame Size for proximity coupling Device (FSD or FSC)
  496. *
  497. *****************************************************************************
  498. */
  499. uint16_t rfalIsoDepFSxI2FSx(uint8_t FSxI);
  500. /*!
  501. *****************************************************************************
  502. * \brief FWI to FWT
  503. *
  504. * Convert Frame Waiting time Integer (FWI) to Frame Waiting Time (FWT) in
  505. * 1/fc units
  506. *
  507. * \param[in] fwi : Frame Waiting time Integer
  508. *
  509. * \return fwt : Frame Waiting Time in 1/fc units
  510. *
  511. *****************************************************************************
  512. */
  513. uint32_t rfalIsoDepFWI2FWT(uint8_t fwi);
  514. /*!
  515. *****************************************************************************
  516. * \brief Check if the buffer data contains a valid RATS command
  517. *
  518. * Check if it is a well formed RATS command with 2 bytes
  519. * This function does not check the validity of FSDI and DID
  520. *
  521. * \param[in] buf : reference to buffer containing the data to be checked
  522. * \param[in] bufLen : length of data in the buffer in bytes
  523. *
  524. * \return true if the data indicates a RATS command; false otherwise
  525. *****************************************************************************
  526. */
  527. bool rfalIsoDepIsRats(const uint8_t* buf, uint8_t bufLen);
  528. /*!
  529. *****************************************************************************
  530. * \brief Check if the buffer data contains a valid ATTRIB command
  531. *
  532. * Check if it is a well formed ATTRIB command, but does not check the
  533. * validity of the information inside
  534. *
  535. * \param[in] buf : reference to buffer containing the data to be checked
  536. * \param[in] bufLen : length of data in the buffer in bytes
  537. *
  538. * \return true if the data indicates a ATTRIB command; false otherwise
  539. *****************************************************************************
  540. */
  541. bool rfalIsoDepIsAttrib(const uint8_t* buf, uint8_t bufLen);
  542. /*!
  543. *****************************************************************************
  544. * \brief Start Listen Activation Handling
  545. *
  546. * Start Listen Activation Handling and setup to receive first I-block which may
  547. * contain complete or partial APDU after activation is completed
  548. *
  549. * Pass in RATS for T4AT, or ATTRIB for T4BT, to handle ATS or ATTRIB Response respectively
  550. * The Activation Handling handles ATS and ATTRIB Response; and additionally PPS Response
  551. * if a PPS is received for T4AT.
  552. * The method uses the current RFAL state machine to determine if it is expecting RATS or ATTRIB
  553. *
  554. * Activation is completed if PPS Response is sent or if first PDU is received in T4T-A
  555. * Activation is completed if ATTRIB Response is sent in T4T-B
  556. *
  557. * \ref rfalIsoDepListenGetActivationStatus provide status if activation is completed.
  558. * \ref rfalIsoDepStartTransceive shall be called right after activation is completed
  559. *
  560. * \param[in] atsParam : reference to ATS parameters
  561. * \param[in] attribResParam : reference to ATTRIB_RES parameters
  562. * \param[in] buf : reference to buffer containing RATS or ATTRIB
  563. * \param[in] bufLen : length in bytes of the given buffer
  564. * \param[in] actParam : reference to incoming reception information will be placed
  565. *
  566. *
  567. * \warning Once the Activation has been completed the method
  568. * rfalIsoDepGetTransceiveStatus() must be called.
  569. * If activation has completed due to reception of a data block (not PPS) the
  570. * buffer owned by the caller and passed on actParam must still contain this data.
  571. * The first data will be processed (I-Block or S-DSL) by rfalIsoDepGetTransceiveStatus()
  572. * inform the caller and then for the next transaction use rfalIsoDepStartTransceive()
  573. *
  574. * \return ERR_NONE : RATS/ATTRIB is valid and activation has started
  575. * \return ERR_PARAM : Invalid parameters
  576. * \return ERR_PROTO : Invalid request
  577. * \return ERR_NOTSUPP : Feature not supported
  578. *****************************************************************************
  579. */
  580. ReturnCode rfalIsoDepListenStartActivation(
  581. rfalIsoDepAtsParam* atsParam,
  582. const rfalIsoDepAttribResParam* attribResParam,
  583. const uint8_t* buf,
  584. uint16_t bufLen,
  585. rfalIsoDepListenActvParam actParam);
  586. /*!
  587. *****************************************************************************
  588. * \brief Get the current Activation Status
  589. *
  590. * \return ERR_NONE if Activation is already completed
  591. * \return ERR_BUSY if Activation is ongoing
  592. * \return ERR_LINK_LOSS if Remote Field is turned off
  593. *****************************************************************************
  594. */
  595. ReturnCode rfalIsoDepListenGetActivationStatus(void);
  596. /*!
  597. *****************************************************************************
  598. * \brief Get the ISO-DEP Communication Information
  599. *
  600. * Gets the maximum INF length in bytes based on current Frame Size
  601. * for proximity coupling Device (FSD or FSC) excluding the header and CRC
  602. *
  603. * \return maximum INF length in bytes
  604. *****************************************************************************
  605. */
  606. uint16_t rfalIsoDepGetMaxInfLen(void);
  607. /*!
  608. *****************************************************************************
  609. * \brief ISO-DEP Start Transceive
  610. *
  611. * This method triggers a ISO-DEP Transceive containing a complete or
  612. * partial APDU
  613. * It transmits the given message and handles all protocol retransmitions,
  614. * error handling and control messages
  615. *
  616. * The txBuf contains a complete or partial APDU (INF) to be transmitted
  617. * The Prologue field will be manipulated by the Transceive
  618. *
  619. * If the buffer contains a partial APDU and is not the last block,
  620. * then isTxChaining must be set to true
  621. *
  622. * \param[in] param: reference parameters to be used for the Transceive
  623. *
  624. * \return ERR_PARAM : Bad request
  625. * \return ERR_WRONG_STATE : The module is not in a proper state
  626. * \return ERR_NONE : The Transceive request has been started
  627. *****************************************************************************
  628. */
  629. ReturnCode rfalIsoDepStartTransceive(rfalIsoDepTxRxParam param);
  630. /*!
  631. *****************************************************************************
  632. * \brief Get the Transceive status
  633. *
  634. * Returns the status of the ISO-DEP Transceive
  635. *
  636. * \warning When the other device is performing chaining once a chained
  637. * block is received the error ERR_AGAIN is sent. At this point
  638. * caller must handle the received data immediately.
  639. * When ERR_AGAIN is returned an ACK has already been sent to
  640. * the other device and the next block might be incoming.
  641. * If rfalWorker() is called frequently it will place the next
  642. * block on the given buffer
  643. *
  644. *
  645. * \return ERR_NONE : Transceive has been completed successfully
  646. * \return ERR_BUSY : Transceive is ongoing
  647. * \return ERR_PROTO : Protocol error occurred
  648. * \return ERR_TIMEOUT : Timeout error occurred
  649. * \return ERR_SLEEP_REQ : Deselect has been received and responded
  650. * \return ERR_NOMEM : The received INF does not fit into the
  651. * receive buffer
  652. * \return ERR_LINK_LOSS : Communication is lost because Reader/Writer
  653. * has turned off its field
  654. * \return ERR_AGAIN : received one chaining block, continue to call
  655. * this method to retrieve the remaining blocks
  656. *****************************************************************************
  657. */
  658. ReturnCode rfalIsoDepGetTransceiveStatus(void);
  659. /*!
  660. *****************************************************************************
  661. * \brief ISO-DEP Start APDU Transceive
  662. *
  663. * This method triggers a ISO-DEP Transceive containing a complete APDU
  664. * It transmits the given message and handles all protocol retransmitions,
  665. * error handling and control messages
  666. *
  667. * The txBuf contains a complete APDU to be transmitted
  668. * The Prologue field will be manipulated by the Transceive
  669. *
  670. * \warning the txBuf will be modified during the transmission
  671. * \warning the maximum RF frame which can be received is limited by param.tmpBuf
  672. *
  673. * \param[in] param: reference parameters to be used for the Transceive
  674. *
  675. * \return ERR_PARAM : Bad request
  676. * \return ERR_WRONG_STATE : The module is not in a proper state
  677. * \return ERR_NONE : The Transceive request has been started
  678. *****************************************************************************
  679. */
  680. ReturnCode rfalIsoDepStartApduTransceive(rfalIsoDepApduTxRxParam param);
  681. /*!
  682. *****************************************************************************
  683. * \brief Get the APDU Transceive status
  684. *
  685. * \return ERR_NONE : if Transceive has been completed successfully
  686. * \return ERR_BUSY : if Transceive is ongoing
  687. * \return ERR_PROTO : if a protocol error occurred
  688. * \return ERR_TIMEOUT : if a timeout error occurred
  689. * \return ERR_SLEEP_REQ : if Deselect is received and responded
  690. * \return ERR_NOMEM : if the received INF does not fit into the
  691. * receive buffer
  692. * \return ERR_LINK_LOSS : if communication is lost because Reader/Writer
  693. * has turned off its field
  694. *****************************************************************************
  695. */
  696. ReturnCode rfalIsoDepGetApduTransceiveStatus(void);
  697. /*!
  698. *****************************************************************************
  699. * \brief ISO-DEP Send RATS
  700. *
  701. * This sends a RATS to make a NFC-A Listen Device to enter
  702. * ISO-DEP layer (ISO14443-4) and checks if the received ATS is valid
  703. *
  704. * \param[in] FSDI : Frame Size Device Integer to be used
  705. * \param[in] DID : Device ID to be used or RFAL_ISODEP_NO_DID for not use DID
  706. * \param[out] ats : pointer to place the ATS Response
  707. * \param[out] atsLen : pointer to place the ATS length
  708. *
  709. * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
  710. * \return ERR_PARAM : Invalid parameters
  711. * \return ERR_IO : Generic internal error
  712. * \return ERR_TIMEOUT : Timeout error
  713. * \return ERR_PAR : Parity error detected
  714. * \return ERR_CRC : CRC error detected
  715. * \return ERR_FRAMING : Framing error detected
  716. * \return ERR_PROTO : Protocol error detected
  717. * \return ERR_NONE : No error, ATS received
  718. *****************************************************************************
  719. */
  720. ReturnCode rfalIsoDepRATS(rfalIsoDepFSxI FSDI, uint8_t DID, rfalIsoDepAts* ats, uint8_t* atsLen);
  721. /*!
  722. *****************************************************************************
  723. * \brief ISO-DEP Send PPS
  724. *
  725. * This sends a PPS to make a NFC-A Listen Device change the communications
  726. * bit rate from 106kbps to one of the supported bit rates
  727. * Additionally checks if the received PPS response is valid
  728. *
  729. * \param[in] DID : Device ID
  730. * \param[in] DSI : DSI code the divisor from Listener (PICC) to Poller (PCD)
  731. * \param[in] DRI : DRI code the divisor from Poller (PCD) to Listener (PICC)
  732. * \param[out] ppsRes : pointer to place the PPS Response
  733. *
  734. * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
  735. * \return ERR_PARAM : Invalid parameters
  736. * \return ERR_IO : Generic internal error
  737. * \return ERR_TIMEOUT : Timeout error
  738. * \return ERR_PAR : Parity error detected
  739. * \return ERR_CRC : CRC error detected
  740. * \return ERR_FRAMING : Framing error detected
  741. * \return ERR_PROTO : Protocol error detected
  742. * \return ERR_NONE : No error, PPS Response received
  743. *****************************************************************************
  744. */
  745. ReturnCode rfalIsoDepPPS(uint8_t DID, rfalBitRate DSI, rfalBitRate DRI, rfalIsoDepPpsRes* ppsRes);
  746. /*!
  747. *****************************************************************************
  748. * \brief ISO-DEP Send ATTRIB
  749. *
  750. * This sends a ATTRIB to make a NFC-B Listen Device to enter
  751. * ISO-DEP layer (ISO14443-4) and checks if the received ATTRIB Response is valid
  752. *
  753. * \param[in] nfcid0 : NFCID0 to be used for the ATTRIB
  754. * \param[in] PARAM1 : ATTRIB PARAM1 byte (communication parameters)
  755. * \param[in] DSI : DSI code the divisor from Listener (PICC) to Poller (PCD)
  756. * \param[in] DRI : DRI code the divisor from Poller (PCD) to Listener (PICC)
  757. * \param[in] FSDI : PCD's Frame Size to be announced on the ATTRIB
  758. * \param[in] PARAM3 : ATTRIB PARAM1 byte (protocol type)
  759. * \param[in] DID : Device ID to be used or RFAL_ISODEP_NO_DID for not use DID
  760. * \param[in] HLInfo : pointer to Higher layer INF (NULL if none)
  761. * \param[in] HLInfoLen : Length HLInfo
  762. * \param[in] fwt : Frame Waiting Time to be used (from SENSB_RES)
  763. * \param[out] attribRes : pointer to place the ATTRIB Response
  764. * \param[out] attribResLen : pointer to place the ATTRIB Response length
  765. *
  766. * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
  767. * \return ERR_PARAM : Invalid parameters
  768. * \return ERR_IO : Generic internal error
  769. * \return ERR_TIMEOUT : Timeout error
  770. * \return ERR_CRC : CRC error detected
  771. * \return ERR_FRAMING : Framing error detected
  772. * \return ERR_PROTO : Protocol error detected
  773. * \return ERR_NONE : No error, ATTRIB Response received
  774. *****************************************************************************
  775. */
  776. ReturnCode rfalIsoDepATTRIB(
  777. const uint8_t* nfcid0,
  778. uint8_t PARAM1,
  779. rfalBitRate DSI,
  780. rfalBitRate DRI,
  781. rfalIsoDepFSxI FSDI,
  782. uint8_t PARAM3,
  783. uint8_t DID,
  784. const uint8_t* HLInfo,
  785. uint8_t HLInfoLen,
  786. uint32_t fwt,
  787. rfalIsoDepAttribRes* attribRes,
  788. uint8_t* attribResLen);
  789. /*!
  790. *****************************************************************************
  791. * \brief Deselects PICC
  792. *
  793. * This function sends a deselect command to PICC and waits for it`s
  794. * response in a blocking way
  795. *
  796. * \return ERR_NONE : Deselect successfully sent and acknowledged by PICC
  797. * \return ERR_TIMEOUT: No response rcvd from PICC
  798. *
  799. *****************************************************************************
  800. */
  801. ReturnCode rfalIsoDepDeselect(void);
  802. /*!
  803. *****************************************************************************
  804. * \brief ISO-DEP Poller Handle NFC-A Activation
  805. *
  806. * This performs a NFC-A Activation into ISO-DEP layer (ISO14443-4) with the given
  807. * parameters. It sends RATS and if the higher bit rates are supported by
  808. * both devices it additionally sends PPS
  809. * Once Activated all details of the device are provided on isoDepDev
  810. *
  811. * \param[in] FSDI : Frame Size Device Integer to be used
  812. * \param[in] DID : Device ID to be used or RFAL_ISODEP_NO_DID for not use DID
  813. * \param[in] maxBR : Max bit rate supported by the Poller
  814. * \param[out] isoDepDev : ISO-DEP information of the activated Listen device
  815. *
  816. * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
  817. * \return ERR_PARAM : Invalid parameters
  818. * \return ERR_IO : Generic internal error
  819. * \return ERR_TIMEOUT : Timeout error
  820. * \return ERR_PAR : Parity error detected
  821. * \return ERR_CRC : CRC error detected
  822. * \return ERR_FRAMING : Framing error detected
  823. * \return ERR_PROTO : Protocol error detected
  824. * \return ERR_NONE : No error, activation successful
  825. *****************************************************************************
  826. */
  827. ReturnCode rfalIsoDepPollAHandleActivation(
  828. rfalIsoDepFSxI FSDI,
  829. uint8_t DID,
  830. rfalBitRate maxBR,
  831. rfalIsoDepDevice* isoDepDev);
  832. /*!
  833. *****************************************************************************
  834. * \brief ISO-DEP Poller Handle NFC-B Activation
  835. *
  836. * This performs a NFC-B Activation into ISO-DEP layer (ISO14443-4) with the given
  837. * parameters. It sends ATTRIB and calculates supported higher bit rates of both
  838. * devices and performs activation.
  839. * Once Activated all details of the device are provided on isoDepDev
  840. *
  841. * \param[in] FSDI : Frame Size Device Integer to be used
  842. * \param[in] DID : Device ID to be used or RFAL_ISODEP_NO_DID for not use DID
  843. * \param[in] maxBR : Max bit rate supported by the Poller
  844. * \param[in] PARAM1 : ATTRIB PARAM1 byte (communication parameters)
  845. * \param[in] nfcbDev : pointer to the NFC-B Device containing the SENSB_RES
  846. * \param[in] HLInfo : pointer to Higher layer INF (NULL if none)
  847. * \param[in] HLInfoLen : Length HLInfo
  848. * \param[out] isoDepDev : ISO-DEP information of the activated Listen device
  849. *
  850. * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
  851. * \return ERR_PARAM : Invalid parameters
  852. * \return ERR_IO : Generic internal error
  853. * \return ERR_TIMEOUT : Timeout error
  854. * \return ERR_PAR : Parity error detected
  855. * \return ERR_CRC : CRC error detected
  856. * \return ERR_FRAMING : Framing error detected
  857. * \return ERR_PROTO : Protocol error detected
  858. * \return ERR_NONE : No error, activation successful
  859. *****************************************************************************
  860. */
  861. ReturnCode rfalIsoDepPollBHandleActivation(
  862. rfalIsoDepFSxI FSDI,
  863. uint8_t DID,
  864. rfalBitRate maxBR,
  865. uint8_t PARAM1,
  866. const rfalNfcbListenDevice* nfcbDev,
  867. const uint8_t* HLInfo,
  868. uint8_t HLInfoLen,
  869. rfalIsoDepDevice* isoDepDev);
  870. /*!
  871. *****************************************************************************
  872. * \brief ISO-DEP Poller Handle S(Parameters)
  873. *
  874. * This checks if PICC supports S(PARAMETERS), retrieves PICC's
  875. * capabilities and sets the Bit Rate at the highest supported by both
  876. * devices
  877. *
  878. * \param[out] isoDepDev : ISO-DEP information of the activated Listen device
  879. * \param[in] maxTxBR : Maximum Tx bit rate supported by PCD
  880. * \param[in] maxRxBR : Maximum Rx bit rate supported by PCD
  881. *
  882. * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
  883. * \return ERR_PARAM : Invalid parameters
  884. * \return ERR_IO : Generic internal error
  885. * \return ERR_TIMEOUT : Timeout error
  886. * \return ERR_FRAMING : Framing error detected
  887. * \return ERR_PROTO : Protocol error detected
  888. * \return ERR_NONE : No error, S(PARAMETERS) selection successful
  889. *****************************************************************************
  890. */
  891. ReturnCode rfalIsoDepPollHandleSParameters(
  892. rfalIsoDepDevice* isoDepDev,
  893. rfalBitRate maxTxBR,
  894. rfalBitRate maxRxBR);
  895. /*!
  896. *****************************************************************************
  897. * \brief ISO-DEP Poller Start NFC-A Activation
  898. *
  899. * This starts a NFC-A Activation into ISO-DEP layer (ISO14443-4) with the given
  900. * parameters. It sends RATS and if the higher bit rates are supported by
  901. * both devices it additionally sends PPS
  902. * Once Activated all details of the device are provided on isoDepDev
  903. *
  904. *
  905. * \see rfalIsoDepPollAGetActivationStatus
  906. *
  907. * \param[in] FSDI : Frame Size Device Integer to be used
  908. * \param[in] DID : Device ID to be used or RFAL_ISODEP_NO_DID for not use DID
  909. * \param[in] maxBR : Max bit rate supported by the Poller
  910. * \param[out] isoDepDev : ISO-DEP information of the activated Listen device
  911. *
  912. * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
  913. * \return ERR_PARAM : Invalid parameters
  914. * \return ERR_IO : Generic internal error
  915. * \return ERR_TIMEOUT : Timeout error
  916. * \return ERR_PAR : Parity error detected
  917. * \return ERR_CRC : CRC error detected
  918. * \return ERR_FRAMING : Framing error detected
  919. * \return ERR_PROTO : Protocol error detected
  920. * \return ERR_NONE : No error, start of asynchronous operation successful
  921. *****************************************************************************
  922. */
  923. ReturnCode rfalIsoDepPollAStartActivation(
  924. rfalIsoDepFSxI FSDI,
  925. uint8_t DID,
  926. rfalBitRate maxBR,
  927. rfalIsoDepDevice* isoDepDev);
  928. /*!
  929. *****************************************************************************
  930. * \brief ISO-DEP Poller Get NFC-A Activation Status
  931. *
  932. * Returns the activation status started by rfalIsoDepPollAStartActivation
  933. *
  934. * \see rfalIsoDepPollAStartActivation
  935. *
  936. * \return ERR_BUSY : Operation is ongoing
  937. * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
  938. * \return ERR_PARAM : Invalid parameters
  939. * \return ERR_IO : Generic internal error
  940. * \return ERR_TIMEOUT : Timeout error
  941. * \return ERR_PAR : Parity error detected
  942. * \return ERR_CRC : CRC error detected
  943. * \return ERR_FRAMING : Framing error detected
  944. * \return ERR_PROTO : Protocol error detected
  945. * \return ERR_NONE : No error, activation successful
  946. *****************************************************************************
  947. */
  948. ReturnCode rfalIsoDepPollAGetActivationStatus(void);
  949. /*!
  950. *****************************************************************************
  951. * \brief ISO-DEP Poller Start NFC-B Activation
  952. *
  953. * This starts a NFC-B Activation into ISO-DEP layer (ISO14443-4) with the given
  954. * parameters. It will send ATTRIB and calculate supported higher bit rates of both
  955. * devices and perform activation.
  956. * Once Activated all details of the device are provided on isoDepDev
  957. *
  958. * \see rfalIsoDepPollBGetActivationStatus
  959. *
  960. * \param[in] FSDI : Frame Size Device Integer to be used
  961. * \param[in] DID : Device ID to be used or RFAL_ISODEP_NO_DID for not use DID
  962. * \param[in] maxBR : Max bit rate supported by the Poller
  963. * \param[in] PARAM1 : ATTRIB PARAM1 byte (communication parameters)
  964. * \param[in] nfcbDev : pointer to the NFC-B Device containing the SENSB_RES
  965. * \param[in] HLInfo : pointer to Higher layer INF (NULL if none)
  966. * \param[in] HLInfoLen : Length HLInfo
  967. * \param[out] isoDepDev : ISO-DEP information of the activated Listen device
  968. *
  969. * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
  970. * \return ERR_PARAM : Invalid parameters
  971. * \return ERR_IO : Generic internal error
  972. * \return ERR_TIMEOUT : Timeout error
  973. * \return ERR_PAR : Parity error detected
  974. * \return ERR_CRC : CRC error detected
  975. * \return ERR_FRAMING : Framing error detected
  976. * \return ERR_PROTO : Protocol error detected
  977. * \return ERR_NONE : No error, start of asynchronous operation successful
  978. *****************************************************************************
  979. */
  980. ReturnCode rfalIsoDepPollBStartActivation(
  981. rfalIsoDepFSxI FSDI,
  982. uint8_t DID,
  983. rfalBitRate maxBR,
  984. uint8_t PARAM1,
  985. const rfalNfcbListenDevice* nfcbDev,
  986. const uint8_t* HLInfo,
  987. uint8_t HLInfoLen,
  988. rfalIsoDepDevice* isoDepDev);
  989. /*!
  990. *****************************************************************************
  991. * \brief ISO-DEP Poller Get NFC-B Activation Status
  992. *
  993. * Returns the activation status started by rfalIsoDepPollBStartActivation
  994. *
  995. * \see rfalIsoDepPollBStartActivation
  996. *
  997. * \return ERR_BUSY : Operation is ongoing
  998. * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
  999. * \return ERR_PARAM : Invalid parameters
  1000. * \return ERR_IO : Generic internal error
  1001. * \return ERR_TIMEOUT : Timeout error
  1002. * \return ERR_PAR : Parity error detected
  1003. * \return ERR_CRC : CRC error detected
  1004. * \return ERR_FRAMING : Framing error detected
  1005. * \return ERR_PROTO : Protocol error detected
  1006. * \return ERR_NONE : No error, activation successful
  1007. *****************************************************************************
  1008. */
  1009. ReturnCode rfalIsoDepPollBGetActivationStatus(void);
  1010. #endif /* RFAL_ISODEP_H_ */
  1011. /**
  1012. * @}
  1013. *
  1014. * @}
  1015. *
  1016. * @}
  1017. */