feat(nfc): Update RFAL library to version 4.2.0 due to added presence check on ISO-DEP layer
What changed, and why it matters
This commit upgrades the third-party STMicroelectronics NFC middleware (RFAL) inside Trezor firmware from version 4.0.2 to 4.2.0. The stated reason is to add a 'presence check' in the ISO-DEP layer, which helps the device verify that an NFC card is still nearby during a transaction. The diff is almost entirely a bulk import of ST's updated library files, so the actual security-relevant changes are not visible in the commit itself. There is no Trezor changelog entry and no CVE or advisory referenced.
Treat as a routine dependency update with possible NFC hardening. Review the upstream ST RFAL 4.2.0 release notes for security fixes, run NFC regression tests, and verify that the ISO-DEP presence check behaves correctly with cards that are removed mid-transaction. No immediate emergency response is warranted based solely on this commit.
Security signals we found
Third-party NFC middleware version bump (RFAL 4.0.2 → 4.2.0)
Commit title references 'added presence check on ISO-DEP layer'
No changelog entry ([no changelog])
No CVE, advisory, or security disclosure referenced in commit or supplied materials
Bulk file replacement obscures exact code-level security fixes
Evidence from the diff
The change is a vendor library refresh of core/embed/io/nfc/st25/rfal002 to ST’s RFAL 4.2.0. LOCAL_CHANGES.md records the update and the SBOM JSON now reports version 4.2.0. The commit title says the update is ‘due to added presence check on ISO-DEP layer’. The visible diffs are only header boilerplate additions (C++ linkage guards) and metadata; the functional source differences are not shown because the diff is a wholesale file replacement. Without the upstream RFAL 4.0.2→4.2.0 changelog or a Trezor security advisory, we cannot confirm whether the presence check fixes a concrete vulnerability or is a hardening/robustness improvement.
Changed components
core/embed/io/nfc/st25/rfal002 (STMicroelectronics RFAL middleware)NFC/ISO-DEP layerST25R3916 NFC controller driver integrationInspect captured patch +61604 / −60935
### core/embed/io/nfc/st25/rfal002/LOCAL_CHANGES.md
@@ -5,6 +5,9 @@ https://www.st.com/en/embedded-software/stsw-st25rfal002.html (version 3.0.1)
# RFAL update 4-Nov-2025:
RFAL middleware updated to version 4.0.2 from https://www.st.com/en/embedded-software/stsw-st25rfal002.html
+# RFAL update 10-Aug-2026:
+RFAL middleware updated to version 4.2.0 from https://www.st.com/en/embedded-software/stsw-st25rfal002.html
+
# Local changes
1. rfalIsoDepInfo structure defined in include/rfal_isoDep.h and rfalNfcDepInfo include/rfal_nfcDep.h contains variable DSI which colide with the DSI macro in
### core/embed/io/nfc/st25/rfal002/doc/Release_Notes.html
[binary or diff unavailable]
### core/embed/io/nfc/st25/rfal002/doc/ST25R3916_CERTComplianceReport.html
[binary or diff unavailable]
### core/embed/io/nfc/st25/rfal002/doc/ST25R3916_CoveritySecurityReport.pdf
[binary or diff unavailable]
### core/embed/io/nfc/st25/rfal002/doc/ST25R3916_MisraComplianceReport.html
[binary or diff unavailable]
### core/embed/io/nfc/st25/rfal002/doc/ST25R3916_SBOM.json
@@ -0,0 +1 @@
+{"bomFormat":"CycloneDX","specVersion":"1.5","serialNumber":"urn:uuid:8302c684-b670-4777-bf33-cd803415a660","version":1,"metadata":{"timestamp":"2026-07-24T14:30:33Z","tools":[{"vendor":"Black Duck","name":"Hub","version":"2026.4.2"},{"vendor":"CycloneDX","name":"cyclonedx-core-java","version":"5.0.5"}],"authors":[{"name":"STMicroelectronics NV"}],"component":{"type":"application","bom-ref":"49b18e57-c150-4ffa-882d-1801a35614d9","name":"RFAL_ST25R3916B","version":"4.2.0","licenses":[{"license":{"name":"SLA0051"}}],"pedigree":{"notes":"SLA0051"},"properties":[{"name":"BlackDuck-Component","value":"b16a6015-cfbe-478d-9af7-284276890330"},{"name":"BlackDuck-ComponentVersion","value":"49b18e57-c150-4ffa-882d-1801a35614d9"}]}}}
\ No newline at end of file
### core/embed/io/nfc/st25/rfal002/doc/rfal.chm
[binary or diff unavailable]
### core/embed/io/nfc/st25/rfal002/include/rfal_analogConfig.h
@@ -1,435 +1,448 @@
-
-/******************************************************************************
- * @attention
- *
- * COPYRIGHT 2020 STMicroelectronics, all rights reserved
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
- * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
-******************************************************************************/
-
-/*
- * PROJECT: ST25R firmware
- * Revision:
- * LANGUAGE: ISO C99
- */
-
-/*! \file rfal_AnalogConfig.h
- *
- * \author bkam
- *
- * \brief RF Chip Analog Configuration Settings
- *
- *
- * \addtogroup RFAL
- * @{
- *
- * \addtogroup RFAL-HAL
- * \brief RFAL Hardware Abstraction Layer
- * @{
- *
- * \addtogroup AnalogConfig
- * \brief RFAL Analog Config Module
- * @{
- *
- */
-
-#ifndef RFAL_ANALOG_CONFIG_H
-#define RFAL_ANALOG_CONFIG_H
-
-/*
- ******************************************************************************
- * INCLUDES
- ******************************************************************************
- */
-#include "rfal_platform.h"
-#include "rfal_utils.h"
-#include "rfal_rf.h"
-
-/*
- ******************************************************************************
- * DEFINES
- ******************************************************************************
- */
-
-#ifndef RFAL_ANALOG_CONFIG_TBL_SIZE
- #define RFAL_ANALOG_CONFIG_TBL_SIZE (1024U) /*!< Maximum number of Register-Mask-Value in the Setting List */
-#endif /* RFAL_ANALOG_CONFIG_TBL_SIZE */
-
-#define RFAL_ANALOG_CONFIG_LUT_SIZE (87U) /*!< Maximum number of Configuration IDs in the Loop Up Table */
-#define RFAL_ANALOG_CONFIG_LUT_NOT_FOUND (0xFFU) /*!< Index value indicating no Configuration IDs found */
-
-/*
- ******************************************************************************
- * The Analog Configuration is structured as following
- * +---------+-----------------------+-----------------------------+
- * | ModeID | Num RVM configuration | RVM (Register, Value, Mask) |
- * | (16bit) | (8bit) | (24bit) |
- * +---------+-----------------------+-----------------------------+
- *
- * The Mode ID coding for different use cases is described below
- *
- * 1. ModeID coding for NFC technologies (not chip specific)
- * +----------------------------------------------------------------------+
- * | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
- * +----------------------------------------------------------------------+
- * | P/L | TECH != CHIP | BR | DIR |
- * +----------------------------------------------------------------------+
- *
- * 2. ModeID coding for chip specific modes and events
- * +----------------------------------------------------------------------+
- * | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
- * +----------------------------------------------------------------------+
- * | P/L | TECH == CHIP | CHIP_SPECIFIC |
- * +----------------------------------------------------------------------+
- *
- * 3. Special ModeID coding for Direction == DPO
- * +----------------------------------------------------------------------+
- * | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
- * +----------------------------------------------------------------------+
- * | P/L | DPO_LVL | TECH* | BR | DIR == DPO |
- * +----------------------------------------------------------------------+
- * ^
- * |
- * +----- reuse of TECH_RFU bits as DPO level indicator
- ******************************************************************************
- */
-
-/* Mask bit */
-#define RFAL_ANALOG_CONFIG_POLL_LISTEN_MODE_MASK (0x8000U) /*!< Mask bit of Poll Mode in Analog Configuration ID */
-#define RFAL_ANALOG_CONFIG_TECH_MASK (0x7F00U) /*!< Mask bits for Technology in Analog Configuration ID */
-#define RFAL_ANALOG_CONFIG_BITRATE_MASK (0x00F0U) /*!< Mask bits for Bit rate in Analog Configuration ID */
-#define RFAL_ANALOG_CONFIG_DIRECTION_MASK (0x000FU) /*!< Mask bits for Direction in Analog Configuration ID */
-#define RFAL_ANALOG_CONFIG_CHIP_SPECIFIC_MASK (0x00FFU) /*!< Mask bits for Chip Specific Technology */
-
-/* Shift values */
-#define RFAL_ANALOG_CONFIG_POLL_LISTEN_MODE_SHIFT (15U) /*!< Shift value of Poll Mode in Analog Configuration ID */
-#define RFAL_ANALOG_CONFIG_TECH_SHIFT (8U) /*!< Shift value for Technology in Analog Configuration ID */
-#define RFAL_ANALOG_CONFIG_BITRATE_SHIFT (4U) /*!< Shift value for Technology in Analog Configuration ID */
-#define RFAL_ANALOG_CONFIG_DIRECTION_SHIFT (0U) /*!< Shift value for Direction in Analog Configuration ID */
-
-/* P/L: bit 15 */
-#define RFAL_ANALOG_CONFIG_POLL (0x0000U) /*!< Poll Mode bit setting in Analog Configuration ID */
-#define RFAL_ANALOG_CONFIG_LISTEN (0x8000U) /*!< Listen Mode bit setting in Analog Configuration ID */
-
-/* TECH: bit 14-8 */
-#define RFAL_ANALOG_CONFIG_TECH_CHIP (0x0000U) /*!< Chip-Specific bit setting in Analog Configuration ID */
-#define RFAL_ANALOG_CONFIG_TECH_NFCA (0x0100U) /*!< NFC-A Technology bits setting in Analog Configuration ID */
-#define RFAL_ANALOG_CONFIG_TECH_NFCB (0x0200U) /*!< NFC-B Technology bits setting in Analog Configuration ID */
-#define RFAL_ANALOG_CONFIG_TECH_NFCF (0x0400U) /*!< NFC-F Technology bits setting in Analog Configuration ID */
-#define RFAL_ANALOG_CONFIG_TECH_AP2P (0x0800U) /*!< AP2P Technology bits setting in Analog Configuration ID */
-#define RFAL_ANALOG_CONFIG_TECH_NFCV (0x1000U) /*!< NFC-V Technology bits setting in Analog Configuration ID */
-#define RFAL_ANALOG_CONFIG_TECH_RFU (0x2000U) /*!< RFU for Technology bits */
-#define RFAL_ANALOG_CONFIG_TECH_RFU2 (0x4000U) /*!< RFU for Technology bits */
-
-/* BR: bit 7-4 */
-#define RFAL_ANALOG_CONFIG_BITRATE_COMMON (0x0000U) /*!< Common settings for all bit rates in Analog Configuration ID */
-#define RFAL_ANALOG_CONFIG_BITRATE_106 (0x0010U) /*!< 106kbits/s settings in Analog Configuration ID */
-#define RFAL_ANALOG_CONFIG_BITRATE_212 (0x0020U) /*!< 212kbits/s settings in Analog Configuration ID */
-#define RFAL_ANALOG_CONFIG_BITRATE_424 (0x0030U) /*!< 424kbits/s settings in Analog Configuration ID */
-#define RFAL_ANALOG_CONFIG_BITRATE_848 (0x0040U) /*!< 848kbits/s settings in Analog Configuration ID */
-#define RFAL_ANALOG_CONFIG_BITRATE_1695 (0x0050U) /*!< 1695kbits/s settings in Analog Configuration ID */
-#define RFAL_ANALOG_CONFIG_BITRATE_3390 (0x0060U) /*!< 3390kbits/s settings in Analog Configuration ID */
-#define RFAL_ANALOG_CONFIG_BITRATE_6780 (0x0070U) /*!< 6780kbits/s settings in Analog Configuration ID */
-#define RFAL_ANALOG_CONFIG_BITRATE_211p88 (0x0090U) /*!< 211.88kbits/s (ISO15693 x8) in Analog Configuration ID */
-#define RFAL_ANALOG_CONFIG_BITRATE_105p94 (0x00A0U) /*!< 105.94kbits/s (ISO15693 x4) in Analog Configuration ID */
-#define RFAL_ANALOG_CONFIG_BITRATE_53 (0x00B0U) /*!< 53kbits/s (ISO15693 x2) setting in Analog Configuration ID */
-#define RFAL_ANALOG_CONFIG_BITRATE_26 (0x00C0U) /*!< 26kbit/s (1 out of 4) NFC-V setting Analog Configuration ID */
-#define RFAL_ANALOG_CONFIG_BITRATE_1p6 (0x00D0U) /*!< 1.6kbit/s (1 out of 256) NFC-V setting Analog Config ID */
-#define RFAL_ANALOG_CONFIG_BITRATE_RFU (0x00E0U) /*!< RFU for Bitrate bits */
-#define RFAL_ANALOG_CONFIG_BITRATE_RFU2 (0x00F0U) /*!< RFU for Bitrate bits */
-
-/* DIR: bit 3-0 */
-#define RFAL_ANALOG_CONFIG_NO_DIRECTION (0x0000U) /*!< No direction setting in Analog Conf ID (Chip Specific only) */
-#define RFAL_ANALOG_CONFIG_TX (0x0001U) /*!< Transmission bit setting in Analog Configuration ID */
-#define RFAL_ANALOG_CONFIG_RX (0x0002U) /*!< Reception bit setting in Analog Configuration ID */
-#define RFAL_ANALOG_CONFIG_ANTICOL (0x0003U) /*!< Anticollision setting in Analog Configuration ID */
-#define RFAL_ANALOG_CONFIG_DPO (0x0004U) /*!< DPO setting in Analog Configuration ID */
-#define RFAL_ANALOG_CONFIG_DLMA (0x0005U) /*!< DLMA setting in Analog Configuration ID */
-#define RFAL_ANALOG_CONFIG_DIRECTION_RFU2 (0x0006U) /*!< RFU for Direction bits */
-#define RFAL_ANALOG_CONFIG_DIRECTION_RFU3 (0x0007U) /*!< RFU for Direction bits */
-#define RFAL_ANALOG_CONFIG_DIRECTION_RFU4 (0x0008U) /*!< RFU for Direction bits */
-#define RFAL_ANALOG_CONFIG_DIRECTION_RFU5 (0x0009U) /*!< RFU for Direction bits */
-#define RFAL_ANALOG_CONFIG_DIRECTION_RFU6 (0x000AU) /*!< RFU for Direction bits */
-#define RFAL_ANALOG_CONFIG_DIRECTION_RFU7 (0x000BU) /*!< RFU for Direction bits */
-#define RFAL_ANALOG_CONFIG_DIRECTION_RFU8 (0x000CU) /*!< RFU for Direction bits */
-#define RFAL_ANALOG_CONFIG_DIRECTION_RFU9 (0x000DU) /*!< RFU for Direction bits */
-#define RFAL_ANALOG_CONFIG_DIRECTION_RFU10 (0x000EU) /*!< RFU for Direction bits */
-#define RFAL_ANALOG_CONFIG_DIRECTION_RFU11 (0x000FU) /*!< RFU for Direction bits */
-
-/* bit 7-0 */
-#define RFAL_ANALOG_CONFIG_CHIP_INIT (0x0000U) /*!< Chip-Specific event: Startup;Reset;Initialize */
-#define RFAL_ANALOG_CONFIG_CHIP_DEINIT (0x0001U) /*!< Chip-Specific event: Deinitialize */
-#define RFAL_ANALOG_CONFIG_CHIP_FIELD_ON (0x0002U) /*!< Chip-Specific event: Field On */
-#define RFAL_ANALOG_CONFIG_CHIP_FIELD_OFF (0x0003U) /*!< Chip-Specific event: Field Off */
-#define RFAL_ANALOG_CONFIG_CHIP_WAKEUP_ON (0x0004U) /*!< Chip-Specific event: Wake-up On */
-#define RFAL_ANALOG_CONFIG_CHIP_WAKEUP_OFF (0x0005U) /*!< Chip-Specific event: Wake-up Off */
-#define RFAL_ANALOG_CONFIG_CHIP_LISTEN_ON (0x0006U) /*!< Chip-Specific event: Listen On */
-#define RFAL_ANALOG_CONFIG_CHIP_LISTEN_OFF (0x0007U) /*!< Chip-Specific event: Listen Off */
-#define RFAL_ANALOG_CONFIG_CHIP_POLL_COMMON (0x0008U) /*!< Chip-Specific event: Poll common */
-#define RFAL_ANALOG_CONFIG_CHIP_LISTEN_COMMON (0x0009U) /*!< Chip-Specific event: Listen common */
-#define RFAL_ANALOG_CONFIG_CHIP_LOWPOWER_ON (0x000AU) /*!< Chip-Specific event: Low Power On */
-#define RFAL_ANALOG_CONFIG_CHIP_LOWPOWER_OFF (0x000BU) /*!< Chip-Specific event: Low Power Off */
-
-#define RFAL_ANALOG_CONFIG_CHIP_POWER_LVL_00 (0x0010U) /*!< Chip-Specific event: Power Level 00 (e.g DPO, WLC) */
-#define RFAL_ANALOG_CONFIG_CHIP_POWER_LVL_01 (0x0011U) /*!< Chip-Specific event: Power Level 01 (e.g DPO, WLC) */
-#define RFAL_ANALOG_CONFIG_CHIP_POWER_LVL_02 (0x0012U) /*!< Chip-Specific event: Power Level 02 (e.g DPO, WLC) */
-#define RFAL_ANALOG_CONFIG_CHIP_POWER_LVL_03 (0x0013U) /*!< Chip-Specific event: Power Level 03 (e.g DPO, WLC) */
-#define RFAL_ANALOG_CONFIG_CHIP_POWER_LVL_04 (0x0014U) /*!< Chip-Specific event: Power Level 04 (e.g DPO, WLC) */
-#define RFAL_ANALOG_CONFIG_CHIP_POWER_LVL_05 (0x0015U) /*!< Chip-Specific event: Power Level 05 (e.g DPO, WLC) */
-#define RFAL_ANALOG_CONFIG_CHIP_POWER_LVL_06 (0x0016U) /*!< Chip-Specific event: Power Level 06 (e.g DPO, WLC) */
-#define RFAL_ANALOG_CONFIG_CHIP_POWER_LVL_07 (0x0017U) /*!< Chip-Specific event: Power Level 07 (e.g DPO, WLC) */
-#define RFAL_ANALOG_CONFIG_CHIP_POWER_LVL_08 (0x0018U) /*!< Chip-Specific event: Power Level 08 (e.g DPO, WLC) */
-#define RFAL_ANALOG_CONFIG_CHIP_POWER_LVL_09 (0x0019U) /*!< Chip-Specific event: Power Level 09 (e.g DPO, WLC) */
-#define RFAL_ANALOG_CONFIG_CHIP_POWER_LVL_10 (0x001AU) /*!< Chip-Specific event: Power Level 10 (e.g DPO, WLC) */
-#define RFAL_ANALOG_CONFIG_CHIP_POWER_LVL_11 (0x001BU) /*!< Chip-Specific event: Power Level 11 (e.g DPO, WLC) */
-#define RFAL_ANALOG_CONFIG_CHIP_POWER_LVL_12 (0x001CU) /*!< Chip-Specific event: Power Level 12 (e.g DPO, WLC) */
-#define RFAL_ANALOG_CONFIG_CHIP_POWER_LVL_13 (0x001DU) /*!< Chip-Specific event: Power Level 13 (e.g DPO, WLC) */
-#define RFAL_ANALOG_CONFIG_CHIP_POWER_LVL_14 (0x001EU) /*!< Chip-Specific event: Power Level 14 (e.g DPO, WLC) */
-#define RFAL_ANALOG_CONFIG_CHIP_POWER_LVL_15 (0x001FU) /*!< Chip-Specific event: Power Level 15 (e.g DPO, WLC) */
-
-#define RFAL_ANALOG_CONFIG_UPDATE_LAST (0x00U) /*!< Value indicating Last configuration set during update */
-#define RFAL_ANALOG_CONFIG_UPDATE_MORE (0x01U) /*!< Value indicating More configuration set coming during update */
-
-
-/*
- ******************************************************************************
- * GLOBAL MACROS
- ******************************************************************************
- */
-
-#define RFAL_ANALOG_CONFIG_ID_GET_POLL_LISTEN(id) (RFAL_ANALOG_CONFIG_POLL_LISTEN_MODE_MASK & (id)) /*!< Check if id indicates Listen mode */
-
-#define RFAL_ANALOG_CONFIG_ID_GET_TECH(id) (RFAL_ANALOG_CONFIG_TECH_MASK & (id)) /*!< Get the technology of Configuration ID */
-#define RFAL_ANALOG_CONFIG_ID_IS_CHIP(id) (RFAL_ANALOG_CONFIG_TECH_MASK & (id)) /*!< Check if ID indicates Chip-specific */
-#define RFAL_ANALOG_CONFIG_ID_IS_NFCA(id) (RFAL_ANALOG_CONFIG_TECH_NFCA & (id)) /*!< Check if ID indicates NFC-A */
-#define RFAL_ANALOG_CONFIG_ID_IS_NFCB(id) (RFAL_ANALOG_CONFIG_TECH_NFCB & (id)) /*!< Check if ID indicates NFC-B */
-#define RFAL_ANALOG_CONFIG_ID_IS_NFCF(id) (RFAL_ANALOG_CONFIG_TECH_NFCF & (id)) /*!< Check if ID indicates NFC-F */
-#define RFAL_ANALOG_CONFIG_ID_IS_AP2P(id) (RFAL_ANALOG_CONFIG_TECH_AP2P & (id)) /*!< Check if ID indicates AP2P */
-#define RFAL_ANALOG_CONFIG_ID_IS_NFCV(id) (RFAL_ANALOG_CONFIG_TECH_NFCV & (id)) /*!< Check if ID indicates NFC-V */
-
-#define RFAL_ANALOG_CONFIG_ID_GET_BITRATE(id) (RFAL_ANALOG_CONFIG_BITRATE_MASK & (id)) /*!< Get Bitrate of Configuration ID */
-#define RFAL_ANALOG_CONFIG_ID_IS_COMMON(id) (RFAL_ANALOG_CONFIG_BITRATE_MASK & (id)) /*!< Check if ID indicates common bitrate */
-#define RFAL_ANALOG_CONFIG_ID_IS_106(id) (RFAL_ANALOG_CONFIG_BITRATE_106 & (id)) /*!< Check if ID indicates 106kbits/s */
-#define RFAL_ANALOG_CONFIG_ID_IS_212(id) (RFAL_ANALOG_CONFIG_BITRATE_212 & (id)) /*!< Check if ID indicates 212kbits/s */
-#define RFAL_ANALOG_CONFIG_ID_IS_424(id) (RFAL_ANALOG_CONFIG_BITRATE_424 & (id)) /*!< Check if ID indicates 424kbits/s */
-#define RFAL_ANALOG_CONFIG_ID_IS_848(id) (RFAL_ANALOG_CONFIG_BITRATE_848 & (id)) /*!< Check if ID indicates 848kbits/s */
-#define RFAL_ANALOG_CONFIG_ID_IS_1695(id) (RFAL_ANALOG_CONFIG_BITRATE_1695 & (id)) /*!< Check if ID indicates 1695kbits/s */
-#define RFAL_ANALOG_CONFIG_ID_IS_3390(id) (RFAL_ANALOG_CONFIG_BITRATE_3390 & (id)) /*!< Check if ID indicates 3390kbits/s */
-#define RFAL_ANALOG_CONFIG_ID_IS_6780(id) (RFAL_ANALOG_CONFIG_BITRATE_6780 & (id)) /*!< Check if ID indicates 6780kbits/s */
-#define RFAL_ANALOG_CONFIG_ID_IS_26(id) (RFAL_ANALOG_CONFIG_BITRATE_26 & (id)) /*!< Check if ID indicates 1 out of 4 bitrate */
-#define RFAL_ANALOG_CONFIG_ID_IS_1p6(id) (RFAL_ANALOG_CONFIG_BITRATE_1p6 & (id)) /*!< Check if ID indicates 1 out of 256 bitrate */
-
-#define RFAL_ANALOG_CONFIG_ID_GET_DIRECTION(id) (RFAL_ANALOG_CONFIG_DIRECTION_MASK & (id)) /*!< Get Direction of Configuration ID */
-#define RFAL_ANALOG_CONFIG_ID_IS_TX(id) (RFAL_ANALOG_CONFIG_TX & (id)) /*!< Check if id indicates TX */
-#define RFAL_ANALOG_CONFIG_ID_IS_RX(id) (RFAL_ANALOG_CONFIG_RX & (id)) /*!< Check if id indicates RX */
-
-#define RFAL_ANALOG_CONFIG_CONFIG_NUM(x) (sizeof(x)/sizeof((x)[0])) /*!< Get Analog Config number */
-
-/*! Set Analog Config ID value by: Mode, Technology, Bitrate and Direction */
-#define RFAL_ANALOG_CONFIG_ID_SET(mode, tech, br, direction) \
- ( RFAL_ANALOG_CONFIG_ID_GET_POLL_LISTEN(mode) \
- | RFAL_ANALOG_CONFIG_ID_GET_TECH(tech) \
- | RFAL_ANALOG_CONFIG_ID_GET_BITRATE(br) \
- | RFAL_ANALOG_CONFIG_ID_GET_DIRECTION(direction) \
- )
-
-/*
- ******************************************************************************
- * GLOBAL DATA TYPES
- ******************************************************************************
- */
-
-typedef uint8_t rfalAnalogConfigMode; /*!< Polling or Listening Mode of Configuration */
-typedef uint8_t rfalAnalogConfigTech; /*!< Technology of Configuration */
-typedef uint8_t rfalAnalogConfigBitrate; /*!< Bitrate of Configuration */
-typedef uint8_t rfalAnalogConfigDirection; /*!< Transmit/Receive direction of Configuration */
-
-typedef uint8_t rfalAnalogConfigRegAddr[2]; /*!< Register Address to ST Chip */
-typedef uint8_t rfalAnalogConfigRegMask; /*!< Register Mask Value */
-typedef uint8_t rfalAnalogConfigRegVal; /*!< Register Value */
-
-typedef uint16_t rfalAnalogConfigId; /*!< Analog Configuration ID */
-typedef uint16_t rfalAnalogConfigOffset; /*!< Analog Configuration offset address in the table */
-typedef uint8_t rfalAnalogConfigNum; /*!< Number of Analog settings for the respective Configuration ID */
-
-
-/*! Struct that contain the Register-Mask-Value set. Make sure that the whole structure size is even and unaligned! */
-typedef struct {
- rfalAnalogConfigRegAddr addr; /*!< Register Address */
- rfalAnalogConfigRegMask mask; /*!< Register Mask Value */
- rfalAnalogConfigRegVal val; /*!< Register Value */
-} rfalAnalogConfigRegAddrMaskVal;
-
-
-/*! Struct that represents the Analog Configs */
-typedef struct {
- uint8_t id[sizeof(rfalAnalogConfigId)]; /*!< Configuration ID */
- rfalAnalogConfigNum num; /*!< Number of Config Sets to follow */
- rfalAnalogConfigRegAddrMaskVal regSet[]; /*!< Register-Mask-Value sets */ /* PRQA S 1060 # MISRA 18.7 - Flexible Array Members are the only meaningful way of denoting a variable length input buffer which follows a fixed header structure. */
-} rfalAnalogConfig;
-
-
-/*
-******************************************************************************
-* GLOBAL FUNCTION PROTOTYPES
-******************************************************************************
-*/
-
-/*!
- *****************************************************************************
- * \brief Initialize the Analog Configuration
- *
- * Reset the Analog Configuration LUT pointer to reference to default settings.
- *
- *****************************************************************************
- */
-void rfalAnalogConfigInitialize( void );
-
-
-/*!
- *****************************************************************************
- * \brief Indicate if the current Analog Configuration Table is complete and ready to be used.
- *
- * \return true if current Analog Configuration Table is complete and ready to be used.
- * \return false if current Analog Configuration Table is incomplete
- *
- *****************************************************************************
- */
-bool rfalAnalogConfigIsReady( void );
-
-
-/*!
- *****************************************************************************
- * \brief Write the whole Analog Configuration table in raw format
- *
- * Writes the Analog Configuration and Look Up Table with the given raw table
- *
- * NOTE: Function does not check the validity of the given Table contents
- *
- * \param[in] configTbl : location of config Table to be loaded
- * \param[in] configTblSize : size of the config Table to be loaded
- *
- * \return RFAL_ERR_NONE : if setting is updated
- * \return RFAL_ERR_PARAM : if configTbl is invalid
- * \return RFAL_ERR_NOMEM : if the given Table is bigger exceeds the max size
- * \return RFAL_ERR_REQUEST : if the update Configuration Id is disabled
- *
- *****************************************************************************
- */
-ReturnCode rfalAnalogConfigListWriteRaw( const uint8_t *configTbl, uint16_t configTblSize );
-
-
-/*!
- *****************************************************************************
- * \brief Write the Analog Configuration table with new analog settings.
- *
- * Writes the Analog Configuration and Look Up Table with the new list of register-mask-value
- * and Configuration ID respectively.
- *
- * NOTE: Function does not check for the validity of the Register Address.
- *
- * \param[in] more : 0x00 indicates it is last Configuration ID settings;
- * 0x01 indicates more Configuration ID setting(s) are coming.
- * \param[in] *config : reference to the configuration list of current Configuraiton ID.
- *
- * \return RFAL_ERR_PARAM : if Configuration ID or parameter is invalid
- * \return RFAL_ERR_NOMEM : if LUT is full
- * \return RFAL_ERR_REQUEST : if the update Configuration Id is disabled
- * \return RFAL_ERR_NONE : if setting is updated
- *
- *****************************************************************************
- */
-ReturnCode rfalAnalogConfigListWrite( uint8_t more, const rfalAnalogConfig *config );
-
-
-/*!
- *****************************************************************************
- * \brief Read the whole Analog Configuration table in raw format
- *
- * Reads the whole Analog Configuration Table in raw format
- *
- * \param[out] tblBuf : location to the buffer to place the Config Table
- * \param[in] tblBufLen : length of the buffer to place the Config Table
- * \param[out] configTblSize : Config Table size
- *
- * \return RFAL_ERR_PARAM : if configTbl or configTblSize is invalid
- * \return RFAL_ERR_NOMEM : if configTblSize is not enough for the whole table
- * \return RFAL_ERR_NONE : if read is successful
- *
- *****************************************************************************
- */
-ReturnCode rfalAnalogConfigListReadRaw( uint8_t *tblBuf, uint16_t tblBufLen, uint16_t *configTblSize );
-
-
-/*!
- *****************************************************************************
- * \brief Read the Analog Configuration table.
- *
- * Read the Analog Configuration Table
- *
- * \param[in] configOffset : offset to the next Configuration ID in the List Table to be read.
- * \param[out] more : 0x00 indicates it is last Configuration ID settings;
- * 0x01 indicates more Configuration ID setting(s) are coming.
- * \param[out] config : configuration id, number of configuration sets and register-mask-value sets
- * \param[in] numConfig : the remaining configuration settings space available;
- *
- * \return RFAL_ERR_NOMEM : if number of Configuration for respective Configuration ID is greater the the remaining configuration setting space available
- * \return RFAL_ERR_NONE : if read is successful
- *
- *****************************************************************************
- */
-ReturnCode rfalAnalogConfigListRead( rfalAnalogConfigOffset *configOffset, uint8_t *more, rfalAnalogConfig *config, rfalAnalogConfigNum numConfig );
-
-
-/*!
- *****************************************************************************
- * \brief Set the Analog settings of indicated Configuration ID.
- *
- * Update the chip with indicated analog settings of indicated Configuration ID.
- *
- * \param[in] configId : configuration ID
- *
- * \return RFAL_ERR_PARAM : if Configuration ID is invalid
- * \return RFAL_ERR_INTERNAL : if error updating setting to chip
- * \return RFAL_ERR_NONE : if new settings is applied to chip
- *
- *****************************************************************************
- */
-ReturnCode rfalSetAnalogConfig( rfalAnalogConfigId configId );
-
-
-/*!
- *****************************************************************************
- * \brief Generates Analog Config mode ID
- *
- * Converts RFAL mode and bitrate into Analog Config Mode ID.
- *
- * Update the chip with indicated analog settings of indicated Configuration ID.
- *
- * \param[in] md : RFAL mode format
- * \param[in] br : RFAL bit rate format
- * \param[in] dir : Analog Config communication direction
- *
- * \return Analog Config Mode ID
- *
- *****************************************************************************
- */
-uint16_t rfalAnalogConfigGenModeID( rfalMode md, rfalBitRate br, uint16_t dir );
-
-
-#endif /* RFAL_ANALOG_CONFIG_H */
-
-/**
- * @}
- *
- * @}
- *
- * @}
- */
+
+/******************************************************************************
+ * @attention
+ *
+ * COPYRIGHT 2020 STMicroelectronics, all rights reserved
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
+ * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+******************************************************************************/
+
+/*
+ * PROJECT: ST25R firmware
+ * Revision:
+ * LANGUAGE: ISO C99
+ */
+
+/*! \file rfal_AnalogConfig.h
+ *
+ * \author bkam
+ *
+ * \brief RF Chip Analog Configuration Settings
+ *
+ *
+ * \addtogroup RFAL
+ * @{
+ *
+ * \addtogroup RFAL-HAL
+ * \brief RFAL Hardware Abstraction Layer
+ * @{
+ *
+ * \addtogroup AnalogConfig
+ * \brief RFAL Analog Config Module
+ * @{
+ *
+ */
+
+#ifndef RFAL_ANALOG_CONFIG_H
+#define RFAL_ANALOG_CONFIG_H
+
+/*
+ ******************************************************************************
+ * INCLUDES
+ ******************************************************************************
+ */
+#include "rfal_platform.h"
+#include "rfal_utils.h"
+#include "rfal_rf.h"
+
+/*
+ ******************************************************************************
+ * C LINKAGE GUARD
+ ******************************************************************************
+ */
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/*
+ ******************************************************************************
+ * DEFINES
+ ******************************************************************************
+ */
+
+#ifndef RFAL_ANALOG_CONFIG_TBL_SIZE
+ #define RFAL_ANALOG_CONFIG_TBL_SIZE (1024U) /*!< Maximum number of Register-Mask-Value in the Setting List */
+#endif /* RFAL_ANALOG_CONFIG_TBL_SIZE */
+
+#define RFAL_ANALOG_CONFIG_LUT_SIZE (87U) /*!< Maximum number of Configuration IDs in the Loop Up Table */
+#define RFAL_ANALOG_CONFIG_LUT_NOT_FOUND (0xFFU) /*!< Index value indicating no Configuration IDs found */
+
+/*
+ ******************************************************************************
+ * The Analog Configuration is structured as following
+ * +---------+-----------------------+-----------------------------+
+ * | ModeID | Num RVM configuration | RVM (Register, Value, Mask) |
+ * | (16bit) | (8bit) | (24bit) |
+ * +---------+-----------------------+-----------------------------+
+ *
+ * The Mode ID coding for different use cases is described below
+ *
+ * 1. ModeID coding for NFC technologies (not chip specific)
+ * +----------------------------------------------------------------------+
+ * | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
+ * +----------------------------------------------------------------------+
+ * | P/L | TECH != CHIP | BR | DIR |
+ * +----------------------------------------------------------------------+
+ *
+ * 2. ModeID coding for chip specific modes and events
+ * +----------------------------------------------------------------------+
+ * | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
+ * +----------------------------------------------------------------------+
+ * | P/L | TECH == CHIP | CHIP_SPECIFIC |
+ * +----------------------------------------------------------------------+
+ *
+ * 3. Special ModeID coding for Direction == DPO
+ * +----------------------------------------------------------------------+
+ * | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
+ * +----------------------------------------------------------------------+
+ * | P/L | DPO_LVL | TECH* | BR | DIR == DPO |
+ * +----------------------------------------------------------------------+
+ * ^
+ * |
+ * +----- reuse of TECH_RFU bits as DPO level indicator
+ ******************************************************************************
+ */
+
+/* Mask bit */
+#define RFAL_ANALOG_CONFIG_POLL_LISTEN_MODE_MASK (0x8000U) /*!< Mask bit of Poll Mode in Analog Configuration ID */
+#define RFAL_ANALOG_CONFIG_TECH_MASK (0x7F00U) /*!< Mask bits for Technology in Analog Configuration ID */
+#define RFAL_ANALOG_CONFIG_BITRATE_MASK (0x00F0U) /*!< Mask bits for Bit rate in Analog Configuration ID */
+#define RFAL_ANALOG_CONFIG_DIRECTION_MASK (0x000FU) /*!< Mask bits for Direction in Analog Configuration ID */
+#define RFAL_ANALOG_CONFIG_CHIP_SPECIFIC_MASK (0x00FFU) /*!< Mask bits for Chip Specific Technology */
+
+/* Shift values */
+#define RFAL_ANALOG_CONFIG_POLL_LISTEN_MODE_SHIFT (15U) /*!< Shift value of Poll Mode in Analog Configuration ID */
+#define RFAL_ANALOG_CONFIG_TECH_SHIFT (8U) /*!< Shift value for Technology in Analog Configuration ID */
+#define RFAL_ANALOG_CONFIG_BITRATE_SHIFT (4U) /*!< Shift value for Technology in Analog Configuration ID */
+#define RFAL_ANALOG_CONFIG_DIRECTION_SHIFT (0U) /*!< Shift value for Direction in Analog Configuration ID */
+
+/* P/L: bit 15 */
+#define RFAL_ANALOG_CONFIG_POLL (0x0000U) /*!< Poll Mode bit setting in Analog Configuration ID */
+#define RFAL_ANALOG_CONFIG_LISTEN (0x8000U) /*!< Listen Mode bit setting in Analog Configuration ID */
+
+/* TECH: bit 14-8 */
+#define RFAL_ANALOG_CONFIG_TECH_CHIP (0x0000U) /*!< Chip-Specific bit setting in Analog Configuration ID */
+#define RFAL_ANALOG_CONFIG_TECH_NFCA (0x0100U) /*!< NFC-A Technology bits setting in Analog Configuration ID */
+#define RFAL_ANALOG_CONFIG_TECH_NFCB (0x0200U) /*!< NFC-B Technology bits setting in Analog Configuration ID */
+#define RFAL_ANALOG_CONFIG_TECH_NFCF (0x0400U) /*!< NFC-F Technology bits setting in Analog Configuration ID */
+#define RFAL_ANALOG_CONFIG_TECH_AP2P (0x0800U) /*!< AP2P Technology bits setting in Analog Configuration ID */
+#define RFAL_ANALOG_CONFIG_TECH_NFCV (0x1000U) /*!< NFC-V Technology bits setting in Analog Configuration ID */
+#define RFAL_ANALOG_CONFIG_TECH_RFU (0x2000U) /*!< RFU for Technology bits */
+#define RFAL_ANALOG_CONFIG_TECH_RFU2 (0x4000U) /*!< RFU for Technology bits */
+
+/* BR: bit 7-4 */
+#define RFAL_ANALOG_CONFIG_BITRATE_COMMON (0x0000U) /*!< Common settings for all bit rates in Analog Configuration ID */
+#define RFAL_ANALOG_CONFIG_BITRATE_106 (0x0010U) /*!< 106kbits/s settings in Analog Configuration ID */
+#define RFAL_ANALOG_CONFIG_BITRATE_212 (0x0020U) /*!< 212kbits/s settings in Analog Configuration ID */
+#define RFAL_ANALOG_CONFIG_BITRATE_424 (0x0030U) /*!< 424kbits/s settings in Analog Configuration ID */
+#define RFAL_ANALOG_CONFIG_BITRATE_848 (0x0040U) /*!< 848kbits/s settings in Analog Configuration ID */
+#define RFAL_ANALOG_CONFIG_BITRATE_1695 (0x0050U) /*!< 1695kbits/s settings in Analog Configuration ID */
+#define RFAL_ANALOG_CONFIG_BITRATE_3390 (0x0060U) /*!< 3390kbits/s settings in Analog Configuration ID */
+#define RFAL_ANALOG_CONFIG_BITRATE_6780 (0x0070U) /*!< 6780kbits/s settings in Analog Configuration ID */
+#define RFAL_ANALOG_CONFIG_BITRATE_211p88 (0x0090U) /*!< 211.88kbits/s (ISO15693 x8) in Analog Configuration ID */
+#define RFAL_ANALOG_CONFIG_BITRATE_105p94 (0x00A0U) /*!< 105.94kbits/s (ISO15693 x4) in Analog Configuration ID */
+#define RFAL_ANALOG_CONFIG_BITRATE_53 (0x00B0U) /*!< 53kbits/s (ISO15693 x2) setting in Analog Configuration ID */
+#define RFAL_ANALOG_CONFIG_BITRATE_26 (0x00C0U) /*!< 26kbit/s (1 out of 4) NFC-V setting Analog Configuration ID */
+#define RFAL_ANALOG_CONFIG_BITRATE_1p6 (0x00D0U) /*!< 1.6kbit/s (1 out of 256) NFC-V setting Analog Config ID */
+#define RFAL_ANALOG_CONFIG_BITRATE_RFU (0x00E0U) /*!< RFU for Bitrate bits */
+#define RFAL_ANALOG_CONFIG_BITRATE_RFU2 (0x00F0U) /*!< RFU for Bitrate bits */
+
+/* DIR: bit 3-0 */
+#define RFAL_ANALOG_CONFIG_NO_DIRECTION (0x0000U) /*!< No direction setting in Analog Conf ID (Chip Specific only) */
+#define RFAL_ANALOG_CONFIG_TX (0x0001U) /*!< Transmission bit setting in Analog Configuration ID */
+#define RFAL_ANALOG_CONFIG_RX (0x0002U) /*!< Reception bit setting in Analog Configuration ID */
+#define RFAL_ANALOG_CONFIG_ANTICOL (0x0003U) /*!< Anticollision setting in Analog Configuration ID */
+#define RFAL_ANALOG_CONFIG_DPO (0x0004U) /*!< DPO setting in Analog Configuration ID */
+#define RFAL_ANALOG_CONFIG_DLMA (0x0005U) /*!< DLMA setting in Analog Configuration ID */
+#define RFAL_ANALOG_CONFIG_DIRECTION_RFU2 (0x0006U) /*!< RFU for Direction bits */
+#define RFAL_ANALOG_CONFIG_DIRECTION_RFU3 (0x0007U) /*!< RFU for Direction bits */
+#define RFAL_ANALOG_CONFIG_DIRECTION_RFU4 (0x0008U) /*!< RFU for Direction bits */
+#define RFAL_ANALOG_CONFIG_DIRECTION_RFU5 (0x0009U) /*!< RFU for Direction bits */
+#define RFAL_ANALOG_CONFIG_DIRECTION_RFU6 (0x000AU) /*!< RFU for Direction bits */
+#define RFAL_ANALOG_CONFIG_DIRECTION_RFU7 (0x000BU) /*!< RFU for Direction bits */
+#define RFAL_ANALOG_CONFIG_DIRECTION_RFU8 (0x000CU) /*!< RFU for Direction bits */
+#define RFAL_ANALOG_CONFIG_DIRECTION_RFU9 (0x000DU) /*!< RFU for Direction bits */
+#define RFAL_ANALOG_CONFIG_DIRECTION_RFU10 (0x000EU) /*!< RFU for Direction bits */
+#define RFAL_ANALOG_CONFIG_DIRECTION_RFU11 (0x000FU) /*!< RFU for Direction bits */
+
+/* bit 7-0 */
+#define RFAL_ANALOG_CONFIG_CHIP_INIT (0x0000U) /*!< Chip-Specific event: Startup;Reset;Initialize */
+#define RFAL_ANALOG_CONFIG_CHIP_DEINIT (0x0001U) /*!< Chip-Specific event: Deinitialize */
+#define RFAL_ANALOG_CONFIG_CHIP_FIELD_ON (0x0002U) /*!< Chip-Specific event: Field On */
+#define RFAL_ANALOG_CONFIG_CHIP_FIELD_OFF (0x0003U) /*!< Chip-Specific event: Field Off */
+#define RFAL_ANALOG_CONFIG_CHIP_WAKEUP_ON (0x0004U) /*!< Chip-Specific event: Wake-up On */
+#define RFAL_ANALOG_CONFIG_CHIP_WAKEUP_OFF (0x0005U) /*!< Chip-Specific event: Wake-up Off */
+#define RFAL_ANALOG_CONFIG_CHIP_LISTEN_ON (0x0006U) /*!< Chip-Specific event: Listen On */
+#define RFAL_ANALOG_CONFIG_CHIP_LISTEN_OFF (0x0007U) /*!< Chip-Specific event: Listen Off */
+#define RFAL_ANALOG_CONFIG_CHIP_POLL_COMMON (0x0008U) /*!< Chip-Specific event: Poll common */
+#define RFAL_ANALOG_CONFIG_CHIP_LISTEN_COMMON (0x0009U) /*!< Chip-Specific event: Listen common */
+#define RFAL_ANALOG_CONFIG_CHIP_LOWPOWER_ON (0x000AU) /*!< Chip-Specific event: Low Power On */
+#define RFAL_ANALOG_CONFIG_CHIP_LOWPOWER_OFF (0x000BU) /*!< Chip-Specific event: Low Power Off */
+
+#define RFAL_ANALOG_CONFIG_CHIP_POWER_LVL_00 (0x0010U) /*!< Chip-Specific event: Power Level 00 (e.g DPO, WLC) */
+#define RFAL_ANALOG_CONFIG_CHIP_POWER_LVL_01 (0x0011U) /*!< Chip-Specific event: Power Level 01 (e.g DPO, WLC) */
+#define RFAL_ANALOG_CONFIG_CHIP_POWER_LVL_02 (0x0012U) /*!< Chip-Specific event: Power Level 02 (e.g DPO, WLC) */
+#define RFAL_ANALOG_CONFIG_CHIP_POWER_LVL_03 (0x0013U) /*!< Chip-Specific event: Power Level 03 (e.g DPO, WLC) */
+#define RFAL_ANALOG_CONFIG_CHIP_POWER_LVL_04 (0x0014U) /*!< Chip-Specific event: Power Level 04 (e.g DPO, WLC) */
+#define RFAL_ANALOG_CONFIG_CHIP_POWER_LVL_05 (0x0015U) /*!< Chip-Specific event: Power Level 05 (e.g DPO, WLC) */
+#define RFAL_ANALOG_CONFIG_CHIP_POWER_LVL_06 (0x0016U) /*!< Chip-Specific event: Power Level 06 (e.g DPO, WLC) */
+#define RFAL_ANALOG_CONFIG_CHIP_POWER_LVL_07 (0x0017U) /*!< Chip-Specific event: Power Level 07 (e.g DPO, WLC) */
+#define RFAL_ANALOG_CONFIG_CHIP_POWER_LVL_08 (0x0018U) /*!< Chip-Specific event: Power Level 08 (e.g DPO, WLC) */
+#define RFAL_ANALOG_CONFIG_CHIP_POWER_LVL_09 (0x0019U) /*!< Chip-Specific event: Power Level 09 (e.g DPO, WLC) */
+#define RFAL_ANALOG_CONFIG_CHIP_POWER_LVL_10 (0x001AU) /*!< Chip-Specific event: Power Level 10 (e.g DPO, WLC) */
+#define RFAL_ANALOG_CONFIG_CHIP_POWER_LVL_11 (0x001BU) /*!< Chip-Specific event: Power Level 11 (e.g DPO, WLC) */
+#define RFAL_ANALOG_CONFIG_CHIP_POWER_LVL_12 (0x001CU) /*!< Chip-Specific event: Power Level 12 (e.g DPO, WLC) */
+#define RFAL_ANALOG_CONFIG_CHIP_POWER_LVL_13 (0x001DU) /*!< Chip-Specific event: Power Level 13 (e.g DPO, WLC) */
+#define RFAL_ANALOG_CONFIG_CHIP_POWER_LVL_14 (0x001EU) /*!< Chip-Specific event: Power Level 14 (e.g DPO, WLC) */
+#define RFAL_ANALOG_CONFIG_CHIP_POWER_LVL_15 (0x001FU) /*!< Chip-Specific event: Power Level 15 (e.g DPO, WLC) */
+
+#define RFAL_ANALOG_CONFIG_UPDATE_LAST (0x00U) /*!< Value indicating Last configuration set during update */
+#define RFAL_ANALOG_CONFIG_UPDATE_MORE (0x01U) /*!< Value indicating More configuration set coming during update */
+
+
+/*
+ ******************************************************************************
+ * GLOBAL MACROS
+ ******************************************************************************
+ */
+
+#define RFAL_ANALOG_CONFIG_ID_GET_POLL_LISTEN(id) (RFAL_ANALOG_CONFIG_POLL_LISTEN_MODE_MASK & (id)) /*!< Check if id indicates Listen mode */
+
+#define RFAL_ANALOG_CONFIG_ID_GET_TECH(id) (RFAL_ANALOG_CONFIG_TECH_MASK & (id)) /*!< Get the technology of Configuration ID */
+#define RFAL_ANALOG_CONFIG_ID_IS_CHIP(id) (RFAL_ANALOG_CONFIG_TECH_MASK & (id)) /*!< Check if ID indicates Chip-specific */
+#define RFAL_ANALOG_CONFIG_ID_IS_NFCA(id) (RFAL_ANALOG_CONFIG_TECH_NFCA & (id)) /*!< Check if ID indicates NFC-A */
+#define RFAL_ANALOG_CONFIG_ID_IS_NFCB(id) (RFAL_ANALOG_CONFIG_TECH_NFCB & (id)) /*!< Check if ID indicates NFC-B */
+#define RFAL_ANALOG_CONFIG_ID_IS_NFCF(id) (RFAL_ANALOG_CONFIG_TECH_NFCF & (id)) /*!< Check if ID indicates NFC-F */
+#define RFAL_ANALOG_CONFIG_ID_IS_AP2P(id) (RFAL_ANALOG_CONFIG_TECH_AP2P & (id)) /*!< Check if ID indicates AP2P */
+#define RFAL_ANALOG_CONFIG_ID_IS_NFCV(id) (RFAL_ANALOG_CONFIG_TECH_NFCV & (id)) /*!< Check if ID indicates NFC-V */
+
+#define RFAL_ANALOG_CONFIG_ID_GET_BITRATE(id) (RFAL_ANALOG_CONFIG_BITRATE_MASK & (id)) /*!< Get Bitrate of Configuration ID */
+#define RFAL_ANALOG_CONFIG_ID_IS_COMMON(id) (RFAL_ANALOG_CONFIG_BITRATE_MASK & (id)) /*!< Check if ID indicates common bitrate */
+#define RFAL_ANALOG_CONFIG_ID_IS_106(id) (RFAL_ANALOG_CONFIG_BITRATE_106 & (id)) /*!< Check if ID indicates 106kbits/s */
+#define RFAL_ANALOG_CONFIG_ID_IS_212(id) (RFAL_ANALOG_CONFIG_BITRATE_212 & (id)) /*!< Check if ID indicates 212kbits/s */
+#define RFAL_ANALOG_CONFIG_ID_IS_424(id) (RFAL_ANALOG_CONFIG_BITRATE_424 & (id)) /*!< Check if ID indicates 424kbits/s */
+#define RFAL_ANALOG_CONFIG_ID_IS_848(id) (RFAL_ANALOG_CONFIG_BITRATE_848 & (id)) /*!< Check if ID indicates 848kbits/s */
+#define RFAL_ANALOG_CONFIG_ID_IS_1695(id) (RFAL_ANALOG_CONFIG_BITRATE_1695 & (id)) /*!< Check if ID indicates 1695kbits/s */
+#define RFAL_ANALOG_CONFIG_ID_IS_3390(id) (RFAL_ANALOG_CONFIG_BITRATE_3390 & (id)) /*!< Check if ID indicates 3390kbits/s */
+#define RFAL_ANALOG_CONFIG_ID_IS_6780(id) (RFAL_ANALOG_CONFIG_BITRATE_6780 & (id)) /*!< Check if ID indicates 6780kbits/s */
+#define RFAL_ANALOG_CONFIG_ID_IS_26(id) (RFAL_ANALOG_CONFIG_BITRATE_26 & (id)) /*!< Check if ID indicates 1 out of 4 bitrate */
+#define RFAL_ANALOG_CONFIG_ID_IS_1p6(id) (RFAL_ANALOG_CONFIG_BITRATE_1p6 & (id)) /*!< Check if ID indicates 1 out of 256 bitrate */
+
+#define RFAL_ANALOG_CONFIG_ID_GET_DIRECTION(id) (RFAL_ANALOG_CONFIG_DIRECTION_MASK & (id)) /*!< Get Direction of Configuration ID */
+#define RFAL_ANALOG_CONFIG_ID_IS_TX(id) (RFAL_ANALOG_CONFIG_TX & (id)) /*!< Check if id indicates TX */
+#define RFAL_ANALOG_CONFIG_ID_IS_RX(id) (RFAL_ANALOG_CONFIG_RX & (id)) /*!< Check if id indicates RX */
+
+#define RFAL_ANALOG_CONFIG_CONFIG_NUM(x) (sizeof(x)/sizeof((x)[0])) /*!< Get Analog Config number */
+
+/*! Set Analog Config ID value by: Mode, Technology, Bitrate and Direction */
+#define RFAL_ANALOG_CONFIG_ID_SET(mode, tech, br, direction) \
+ ( RFAL_ANALOG_CONFIG_ID_GET_POLL_LISTEN(mode) \
+ | RFAL_ANALOG_CONFIG_ID_GET_TECH(tech) \
+ | RFAL_ANALOG_CONFIG_ID_GET_BITRATE(br) \
+ | RFAL_ANALOG_CONFIG_ID_GET_DIRECTION(direction) \
+ )
+
+/*
+ ******************************************************************************
+ * GLOBAL DATA TYPES
+ ******************************************************************************
+ */
+
+typedef uint8_t rfalAnalogConfigMode; /*!< Polling or Listening Mode of Configuration */
+typedef uint8_t rfalAnalogConfigTech; /*!< Technology of Configuration */
+typedef uint8_t rfalAnalogConfigBitrate; /*!< Bitrate of Configuration */
+typedef uint8_t rfalAnalogConfigDirection; /*!< Transmit/Receive direction of Configuration */
+
+typedef uint8_t rfalAnalogConfigRegAddr[2]; /*!< Register Address to ST Chip */
+typedef uint8_t rfalAnalogConfigRegMask; /*!< Register Mask Value */
+typedef uint8_t rfalAnalogConfigRegVal; /*!< Register Value */
+
+typedef uint16_t rfalAnalogConfigId; /*!< Analog Configuration ID */
+typedef uint16_t rfalAnalogConfigOffset; /*!< Analog Configuration offset address in the table */
+typedef uint8_t rfalAnalogConfigNum; /*!< Number of Analog settings for the respective Configuration ID */
+
+
+/*! Struct that contain the Register-Mask-Value set. Make sure that the whole structure size is even and unaligned! */
+typedef struct {
+ rfalAnalogConfigRegAddr addr; /*!< Register Address */
+ rfalAnalogConfigRegMask mask; /*!< Register Mask Value */
+ rfalAnalogConfigRegVal val; /*!< Register Value */
+} rfalAnalogConfigRegAddrMaskVal;
+
+
+/*! Struct that represents the Analog Configs */
+typedef struct {
+ uint8_t id[sizeof(rfalAnalogConfigId)]; /*!< Configuration ID */
+ rfalAnalogConfigNum num; /*!< Number of Config Sets to follow */
+ rfalAnalogConfigRegAddrMaskVal regSet[]; /*!< Register-Mask-Value sets */ /* PRQA S 1060 # MISRA 18.7 - Flexible Array Members are the only meaningful way of denoting a variable length input buffer which follows a fixed header structure. */
+} rfalAnalogConfig;
+
+
+/*
+******************************************************************************
+* GLOBAL FUNCTION PROTOTYPES
+******************************************************************************
+*/
+
+/*!
+ *****************************************************************************
+ * \brief Initialize the Analog Configuration
+ *
+ * Reset the Analog Configuration LUT pointer to reference to default settings.
+ *
+ *****************************************************************************
+ */
+void rfalAnalogConfigInitialize( void );
+
+
+/*!
+ *****************************************************************************
+ * \brief Indicate if the current Analog Configuration Table is complete and ready to be used.
+ *
+ * \return true if current Analog Configuration Table is complete and ready to be used.
+ * \return false if current Analog Configuration Table is incomplete
+ *
+ *****************************************************************************
+ */
+bool rfalAnalogConfigIsReady( void );
+
+
+/*!
+ *****************************************************************************
+ * \brief Write the whole Analog Configuration table in raw format
+ *
+ * Writes the Analog Configuration and Look Up Table with the given raw table
+ *
+ * NOTE: Function does not check the validity of the given Table contents
+ *
+ * \param[in] configTbl : location of config Table to be loaded
+ * \param[in] configTblSize : size of the config Table to be loaded
+ *
+ * \return RFAL_ERR_NONE : if setting is updated
+ * \return RFAL_ERR_PARAM : if configTbl is invalid
+ * \return RFAL_ERR_NOMEM : if the given Table is bigger exceeds the max size
+ * \return RFAL_ERR_REQUEST : if the update Configuration Id is disabled
+ *
+ *****************************************************************************
+ */
+ReturnCode rfalAnalogConfigListWriteRaw( const uint8_t *configTbl, uint16_t configTblSize );
+
+
+/*!
+ *****************************************************************************
+ * \brief Write the Analog Configuration table with new analog settings.
+ *
+ * Writes the Analog Configuration and Look Up Table with the new list of register-mask-value
+ * and Configuration ID respectively.
+ *
+ * NOTE: Function does not check for the validity of the Register Address.
+ *
+ * \param[in] more : 0x00 indicates it is last Configuration ID settings;
+ * 0x01 indicates more Configuration ID setting(s) are coming.
+ * \param[in] *config : reference to the configuration list of current Configuraiton ID.
+ *
+ * \return RFAL_ERR_PARAM : if Configuration ID or parameter is invalid
+ * \return RFAL_ERR_NOMEM : if LUT is full
+ * \return RFAL_ERR_REQUEST : if the update Configuration Id is disabled
+ * \return RFAL_ERR_NONE : if setting is updated
+ *
+ *****************************************************************************
+ */
+ReturnCode rfalAnalogConfigListWrite( uint8_t more, const rfalAnalogConfig *config );
+
+
+/*!
+ *****************************************************************************
+ * \brief Read the whole Analog Configuration table in raw format
+ *
+ * Reads the whole Analog Configuration Table in raw format
+ *
+ * \param[out] tblBuf : location to the buffer to place the Config Table
+ * \param[in] tblBufLen : length of the buffer to place the Config Table
+ * \param[out] configTblSize : Config Table size
+ *
+ * \return RFAL_ERR_PARAM : if configTbl or configTblSize is invalid
+ * \return RFAL_ERR_NOMEM : if configTblSize is not enough for the whole table
+ * \return RFAL_ERR_NONE : if read is successful
+ *
+ *****************************************************************************
+ */
+ReturnCode rfalAnalogConfigListReadRaw( uint8_t *tblBuf, uint16_t tblBufLen, uint16_t *configTblSize );
+
+
+/*!
+ *****************************************************************************
+ * \brief Read the Analog Configuration table.
+ *
+ * Read the Analog Configuration Table
+ *
+ * \param[in] configOffset : offset to the next Configuration ID in the List Table to be read.
+ * \param[out] more : 0x00 indicates it is last Configuration ID settings;
+ * 0x01 indicates more Configuration ID setting(s) are coming.
+ * \param[out] config : configuration id, number of configuration sets and register-mask-value sets
+ * \param[in] numConfig : the remaining configuration settings space available;
+ *
+ * \return RFAL_ERR_NOMEM : if number of Configuration for respective Configuration ID is greater the the remaining configuration setting space available
+ * \return RFAL_ERR_NONE : if read is successful
+ *
+ *****************************************************************************
+ */
+ReturnCode rfalAnalogConfigListRead( rfalAnalogConfigOffset *configOffset, uint8_t *more, rfalAnalogConfig *config, rfalAnalogConfigNum numConfig );
+
+
+/*!
+ *****************************************************************************
+ * \brief Set the Analog settings of indicated Configuration ID.
+ *
+ * Update the chip with indicated analog settings of indicated Configuration ID.
+ *
+ * \param[in] configId : configuration ID
+ *
+ * \return RFAL_ERR_PARAM : if Configuration ID is invalid
+ * \return RFAL_ERR_INTERNAL : if error updating setting to chip
+ * \return RFAL_ERR_NONE : if new settings is applied to chip
+ *
+ *****************************************************************************
+ */
+ReturnCode rfalSetAnalogConfig( rfalAnalogConfigId configId );
+
+
+/*!
+ *****************************************************************************
+ * \brief Generates Analog Config mode ID
+ *
+ * Converts RFAL mode and bitrate into Analog Config Mode ID.
+ *
+ * Update the chip with indicated analog settings of indicated Configuration ID.
+ *
+ * \param[in] md : RFAL mode format
+ * \param[in] br : RFAL bit rate format
+ * \param[in] dir : Analog Config communication direction
+ *
+ * \return Analog Config Mode ID
+ *
+ *****************************************************************************
+ */
+uint16_t rfalAnalogConfigGenModeID( rfalMode md, rfalBitRate br, uint16_t dir );
+
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* RFAL_ANALOG_CONFIG_H */
+
+/**
+ * @}
+ *
+ * @}
+ *
+ * @}
+ */
### core/embed/io/nfc/st25/rfal002/include/rfal_cd.h
@@ -1,179 +1,192 @@
-
-/******************************************************************************
- * @attention
- *
- * COPYRIGHT 2019 STMicroelectronics, all rights reserved
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
- * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
-******************************************************************************/
-
-/*
- * PROJECT: ST25R firmware
- * Revision:
- * LANGUAGE: ISO C99
- */
-
-/*! \file rfal_cd.h
- *
- * \author
- *
- * \brief Implementation of a Card Detection Algorithm
- *
- *
- *
- * \addtogroup RFAL
- * @{
- *
- * \addtogroup RFAL-HL
- * \brief RFAL Higher Layer
- * @{
- *
- * \addtogroup CD
- * \brief RFAL Card Detection
- * @{
- *
- */
-
-#ifndef RFAL_CD_H
-#define RFAL_CD_H
-
-/*
- ******************************************************************************
- * INCLUDES
- ******************************************************************************
- */
-#include "rfal_platform.h"
-#include "rfal_utils.h"
-
-/*
- ******************************************************************************
- * GLOBAL DEFINES
- ******************************************************************************
- */
-
-/*
- ******************************************************************************
- * GLOBAL MACROS
- ******************************************************************************
- */
-
-/*
-******************************************************************************
-* GLOBAL TYPES
-******************************************************************************
-*/
-
-/*! Card Detection NFC technology type */
-typedef enum
-{
- RFAL_CD_TECH_NONE = 0x00, /*!< No NFC Technology */
- RFAL_CD_TECH_NFCA = 0x01, /*!< NFC Technology NFCB */
- RFAL_CD_TECH_NFCB = 0x02, /*!< NFC Technology NFCB */
- RFAL_CD_TECH_NFCF = 0x04, /*!< NFC Technology NFCF */
- RFAL_CD_TECH_NFCV = 0x08, /*!< NFC Technology NFCV */
- RFAL_CD_TECH_OTHER = 0x10 /*!< NFC Technology OTHER */
-}rfalCdTech;
-
-
-/*! Card Detection result|outcome type */
-typedef enum
-{
- RFAL_CD_NOT_FOUND = 0, /*<! No NFC device found */
- RFAL_CD_SINGLE_DEV = 1, /*<! An NFC card was found */
- RFAL_CD_MULTIPLE_DEV = 2, /*<! Multiple NFC devices found */
- RFAL_CD_MULTIPLE_TECH = 3, /*<! Multiple NFC technologies observed in a single RF carrier */
- RFAL_CD_CARD_TECH = 4, /*<! A card-exclusive NFC technology found */
- RFAL_CD_SINGLE_MULTI_TECH = 5, /*<! A single NFC device which supports multiple technologies found */
- RFAL_CD_SINGLE_P2P = 6, /*<! A single NFC device which supports NFC-DEP|P2P found */
- RFAL_CD_SINGLE_HB = 7, /*<! A single NFC device where heartbeat was detected */
- RFAL_CD_UNKOWN = 8 /*<! Unable to complete the Card Detection due to unknow|unexpected event */
-}
-rfalCdDetType;
-
-
-/*! Card Detection result|outcome */
-typedef struct
-{
- bool detected; /*!< Card detected flag */
- rfalCdDetType detType; /*!< Card detection type */
-}
-rfalCdRes;
-
-
-/*
-******************************************************************************
-* GLOBAL FUNCTION PROTOTYPES
-******************************************************************************
-*/
-
-/*!
- *****************************************************************************
- * \brief Detect Card
- *
- * This function checks if a passive NFC card is present in the vicinity
- *
- * \param[out] result : Pointer to detection result|outcome
- *
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_WRONG_STATE : Incorrect state for this operation
- * \return RFAL_ERR_NONE : Detection excuted with no error
- * \return RFAL_ERR_RF_COLLISION : RF carrier collision detected
- * \return RFAL_ERR_XXXX : Error occurred
-
- *
- *****************************************************************************
- */
-ReturnCode rfalCdDetectCard( rfalCdRes *result );
-
-
-/*!
- *****************************************************************************
- * \brief Start Card Detection
- *
- * This function starts the detection for a passive NFC card is present
- * in the vicinity
- *
- * \param[out] result : Pointer to detection result|outcome
- *
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_WRONG_STATE : Incorrect state for this operation
- * \return RFAL_ERR_NONE : Detection will be executed
- *
- *****************************************************************************
- */
-ReturnCode rfalCdStartDetectCard( rfalCdRes *result );
-
-
-/*!
- *****************************************************************************
- * \brief Get Card Detection Status
- *
- * This function gets the status of the card detection
- *
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_WRONG_STATE : Incorrect state for this operation
- * \return RFAL_ERR_NONE : Detection excuted with no error
- * \return RFAL_ERR_RF_COLLISION : RF carrier collision detected
- * \return RFAL_ERR_XXXX : Error occurred
- *
- *****************************************************************************
- */
-ReturnCode rfalCdGetDetectCardStatus( void );
-
-
-#endif /* RFAL_CD_H */
-
-/**
- * @}
- *
- * @}
- *
- * @}
- */
+
+/******************************************************************************
+ * @attention
+ *
+ * COPYRIGHT 2019 STMicroelectronics, all rights reserved
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
+ * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+******************************************************************************/
+
+/*
+ * PROJECT: ST25R firmware
+ * Revision:
+ * LANGUAGE: ISO C99
+ */
+
+/*! \file rfal_cd.h
+ *
+ * \author
+ *
+ * \brief Implementation of a Card Detection Algorithm
+ *
+ *
+ *
+ * \addtogroup RFAL
+ * @{
+ *
+ * \addtogroup RFAL-HL
+ * \brief RFAL Higher Layer
+ * @{
+ *
+ * \addtogroup CD
+ * \brief RFAL Card Detection
+ * @{
+ *
+ */
+
+#ifndef RFAL_CD_H
+#define RFAL_CD_H
+
+/*
+ ******************************************************************************
+ * INCLUDES
+ ******************************************************************************
+ */
+#include "rfal_platform.h"
+#include "rfal_utils.h"
+
+/*
+ ******************************************************************************
+ * C LINKAGE GUARD
+ ******************************************************************************
+ */
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/*
+ ******************************************************************************
+ * GLOBAL DEFINES
+ ******************************************************************************
+ */
+
+/*
+ ******************************************************************************
+ * GLOBAL MACROS
+ ******************************************************************************
+ */
+
+/*
+******************************************************************************
+* GLOBAL TYPES
+******************************************************************************
+*/
+
+/*! Card Detection NFC technology type */
+typedef enum
+{
+ RFAL_CD_TECH_NONE = 0x00, /*!< No NFC Technology */
+ RFAL_CD_TECH_NFCA = 0x01, /*!< NFC Technology NFCB */
+ RFAL_CD_TECH_NFCB = 0x02, /*!< NFC Technology NFCB */
+ RFAL_CD_TECH_NFCF = 0x04, /*!< NFC Technology NFCF */
+ RFAL_CD_TECH_NFCV = 0x08, /*!< NFC Technology NFCV */
+ RFAL_CD_TECH_OTHER = 0x10 /*!< NFC Technology OTHER */
+}rfalCdTech;
+
+
+/*! Card Detection result|outcome type */
+typedef enum
+{
+ RFAL_CD_NOT_FOUND = 0, /*!< No NFC device found */
+ RFAL_CD_SINGLE_DEV = 1, /*!< An NFC card was found */
+ RFAL_CD_MULTIPLE_DEV = 2, /*!< Multiple NFC devices found */
+ RFAL_CD_MULTIPLE_TECH = 3, /*!< Multiple NFC technologies observed in a single RF carrier */
+ RFAL_CD_CARD_TECH = 4, /*!< A card-exclusive NFC technology found */
+ RFAL_CD_SINGLE_MULTI_TECH = 5, /*!< A single NFC device which supports multiple technologies found */
+ RFAL_CD_SINGLE_P2P = 6, /*!< A single NFC device which supports NFC-DEP|P2P found */
+ RFAL_CD_SINGLE_HB = 7, /*!< A single NFC device where heartbeat was detected */
+ RFAL_CD_UNKOWN = 8 /*!< Unable to complete the Card Detection due to unknow|unexpected event */
+}
+rfalCdDetType;
+
+
+/*! Card Detection result|outcome */
+typedef struct
+{
+ bool detected; /*!< Card detected flag */
+ rfalCdDetType detType; /*!< Card detection type */
+}
+rfalCdRes;
+
+
+/*
+******************************************************************************
+* GLOBAL FUNCTION PROTOTYPES
+******************************************************************************
+*/
+
+/*!
+ *****************************************************************************
+ * \brief Detect Card
+ *
+ * This function checks if a passive NFC card is present in the vicinity
+ *
+ * \param[out] result : Pointer to detection result|outcome
+ *
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_WRONG_STATE : Incorrect state for this operation
+ * \return RFAL_ERR_NONE : Detection excuted with no error
+ * \return RFAL_ERR_RF_COLLISION : RF carrier collision detected
+ * \return RFAL_ERR_XXXX : Error occurred
+
+ *
+ *****************************************************************************
+ */
+ReturnCode rfalCdDetectCard( rfalCdRes *result );
+
+
+/*!
+ *****************************************************************************
+ * \brief Start Card Detection
+ *
+ * This function starts the detection for a passive NFC card is present
+ * in the vicinity
+ *
+ * \param[out] result : Pointer to detection result|outcome
+ *
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_WRONG_STATE : Incorrect state for this operation
+ * \return RFAL_ERR_NONE : Detection will be executed
+ *
+ *****************************************************************************
+ */
+ReturnCode rfalCdStartDetectCard( rfalCdRes *result );
+
+
+/*!
+ *****************************************************************************
+ * \brief Get Card Detection Status
+ *
+ * This function gets the status of the card detection
+ *
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_WRONG_STATE : Incorrect state for this operation
+ * \return RFAL_ERR_NONE : Detection excuted with no error
+ * \return RFAL_ERR_RF_COLLISION : RF carrier collision detected
+ * \return RFAL_ERR_XXXX : Error occurred
+ *
+ *****************************************************************************
+ */
+ReturnCode rfalCdGetDetectCardStatus( void );
+
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* RFAL_CD_H */
+
+/**
+ * @}
+ *
+ * @}
+ *
+ * @}
+ */
### core/embed/io/nfc/st25/rfal002/include/rfal_chip.h
@@ -1,443 +1,456 @@
-
-/******************************************************************************
- * @attention
- *
- * COPYRIGHT 2016 STMicroelectronics, all rights reserved
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
- * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
-******************************************************************************/
-
-
-
-/*
- * PROJECT: ST25R firmware
- * Revision:
- * LANGUAGE: ISO C99
- */
-
-/*! \file rfal_chip.h
- *
- * \author Gustavo Patricio
- *
- * \brief RF Chip specific Layer
- *
- * \warning This layer, which provides direct access to RF chip, should
- * only be used for debug purposes and/or advanced features
- *
- *
- * \addtogroup RFAL
- * @{
- *
- * \addtogroup RFAL-HAL
- * \brief RFAL Hardware Abstraction Layer
- * @{
- *
- * \addtogroup Chip
- * \brief RFAL RF Chip Module
- * @{
- *
- */
-
-
-#ifndef RFAL_CHIP_H
-#define RFAL_CHIP_H
-
-/*
-******************************************************************************
-* INCLUDES
-******************************************************************************
-*/
-#include "rfal_platform.h"
-#include "rfal_utils.h"
-#include "rfal_rf.h"
-
-
-/*****************************************************************************
- * RF Chip *
- *****************************************************************************/
-
-/*!
- *****************************************************************************
- * \brief Writes a register on the RF Chip
- *
- * Checks if the given register is valid and if so, writes the value(s)
- * on the RF Chip register
- *
- * \param[in] reg : register address to be written, or the first if len > 1
- * \param[in] values : pointer with content to be written on the register(s)
- * \param[in] len : number of consecutive registers to be written
- *
- *
- * \return RFAL_ERR_PARAM : Invalid register or bad request
- * \return RFAL_ERR_NOTSUPP : Feature not supported
- * \return RFAL_ERR_NONE : Write done with no error
- *****************************************************************************
- */
-ReturnCode rfalChipWriteReg( uint16_t reg, const uint8_t* values, uint8_t len );
-
-/*!
- *****************************************************************************
- * \brief Reads a register on the RF Chip
- *
- * Checks if the given register is valid and if so, reads the value(s)
- * of the RF Chip register(s)
- *
- * \param[in] reg : register address to be read, or the first if len > 1
- * \param[out] values : pointer where the register(s) read content will be placed
- * \param[in] len : number of consecutive registers to be read
- *
- * \return RFAL_ERR_PARAM : Invalid register or bad request
- * \return RFAL_ERR_NOTSUPP : Feature not supported
- * \return RFAL_ERR_NONE : Read done with no error
- *****************************************************************************
- */
-ReturnCode rfalChipReadReg( uint16_t reg, uint8_t* values, uint8_t len );
-
-/*!
- *****************************************************************************
- * \brief Change a register on the RF Chip
- *
- * Change the value of the register bits on the RF Chip Test set in the valueMask.
- *
- * \param[in] reg : register address to be modified
- * \param[in] valueMask : mask value of the register bits to be changed
- * \param[in] value : register value to be set
- *
- * \return RFAL_ERR_PARAM : Invalid register or bad request
- * \return RFAL_ERR_NOTSUPP : Feature not supported
- * \return RFAL_ERR_OK : Change done with no error
- *****************************************************************************
- */
-ReturnCode rfalChipChangeRegBits( uint16_t reg, uint8_t valueMask, uint8_t value );
-
-/*!
- *****************************************************************************
- * \brief Writes a Test register on the RF Chip
- *
- * Writes the value on the RF Chip Test register
- *
- * \param[in] reg : register address to be written
- * \param[in] value : value to be written on the register
- *
- *
- * \return RFAL_ERR_PARAM : Invalid register or bad request
- * \return RFAL_ERR_NOTSUPP : Feature not supported
- * \return RFAL_ERR_NONE : Write done with no error
- *****************************************************************************
- */
-ReturnCode rfalChipWriteTestReg( uint16_t reg, uint8_t value );
-
-/*!
- *****************************************************************************
- * \brief Reads a Test register on the RF Chip
- *
- * Reads the value of the RF Chip Test register
- *
- * \param[in] reg : register address to be read
- * \param[out] value : pointer where the register content will be placed
- *
- * \return RFAL_ERR_PARAM :Invalid register or bad request
- * \return RFAL_ERR_NOTSUPP : Feature not supported
- * \return RFAL_ERR_NONE : Read done with no error
- *****************************************************************************
- */
-ReturnCode rfalChipReadTestReg( uint16_t reg, uint8_t* value );
-
-/*!
- *****************************************************************************
- * \brief Change a Test register on the RF Chip
- *
- * Change the value of the register bits on the RF Chip Test set in the valueMask.
- *
- * \param[in] reg : test register address to be modified
- * \param[in] valueMask : mask value of the register bits to be changed
- * \param[in] value : register value to be set
- *
- * \return RFAL_ERR_PARAM : Invalid register or bad request
- * \return RFAL_ERR_NOTSUPP : Feature not supported
- * \return RFAL_ERR_OK : Change done with no error
- *****************************************************************************
- */
-ReturnCode rfalChipChangeTestRegBits( uint16_t reg, uint8_t valueMask, uint8_t value );
-
-/*!
- *****************************************************************************
- * \brief Execute command on the RF Chip
- *
- * Checks if the given command is valid and if so, executes it on
- * the RF Chip
- *
- * \param[in] cmd : direct command to be executed
- *
- * \return RFAL_ERR_PARAM : Invalid command or bad request
- * \return RFAL_ERR_NOTSUPP : Feature not supported
- * \return RFAL_ERR_NONE : Direct command executed with no error
- *****************************************************************************
- */
-ReturnCode rfalChipExecCmd( uint16_t cmd );
-
-/*!
- *****************************************************************************
- * \brief Set RFO
- *
- * Sets the RFO driver resistance value used when the
- * field is on (unmodulated/active)
- *
- * \param[in] rfo : the RFO value to be used
- *
- * \return RFAL_ERR_IO : Internal error
- * \return RFAL_ERR_NOTSUPP : Feature not supported
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalChipSetRFO( uint8_t rfo );
-
-
-/*!
- *****************************************************************************
- * \brief Get RFO
- *
- * Gets the RFO driver resistance value used when the
- * field is on (unmodulated/active)
- *
- * \param[out] result : the current RFO value
- *
- * \return RFAL_ERR_IO : Internal error
- * \return RFAL_ERR_NOTSUPP : Feature not supported
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalChipGetRFO( uint8_t* result );
-
-
-/*!
- *****************************************************************************
- * \brief Get LM Field Indicator
- *
- * Gets an indicator of the signal on RFI while in Passive Listen Mode
- *
- * \param[out] result : the current RFI value
- *
- * \return RFAL_ERR_IO : Internal error
- * \return RFAL_ERR_NOTSUPP : Feature not supported
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalChipGetLmFieldInd( uint8_t* result );
-
-/*!
- *****************************************************************************
- * \brief Set Listen Mode Modulation
- *
- * Sets the modulation (modulated and unmodulated state) when Passive Listen
- * Mode is used
- *
- * \param[in] mod : modulation to be used in modulated state
- * \param[in] unmod : modulation to be used in unmodulated state
- *
- * \return RFAL_ERR_IO : Internal error
- * \return RFAL_ERR_NOTSUPP : Feature not supported
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalChipSetLMMod( uint8_t mod, uint8_t unmod );
-
-
-/*!
- *****************************************************************************
- * \brief Get Listen Mode Modulation
- *
- * Gets the modulation (modulated and unmodulated state) when Passive Listen
- * Mode is used
- *
- * \param[out] mod : modulation set in modulated state
- * \param[out] unmod : modulation set in unmodulated state
- *
- * \return RFAL_ERR_IO : Internal error
- * \return RFAL_ERR_NOTSUPP : Feature not supported
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalChipGetLMMod( uint8_t* mod, uint8_t* unmod );
-
-
-/*!
- *****************************************************************************
- * \brief Measure Amplitude
- *
- * Measures the RF Amplitude
- *
- * \param[out] result : result of RF measurement
- *
- * \return RFAL_ERR_IO : Internal error
- * \return RFAL_ERR_NOTSUPP : Feature not supported
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalChipMeasureAmplitude( uint8_t* result );
-
-
-/*!
- *****************************************************************************
- * \brief Measure Phase
- *
- * Measures the Phase
- *
- * \param[out] result : result of Phase measurement
- *
- * \return RFAL_ERR_IO : Internal error
- * \return RFAL_ERR_NOTSUPP : Feature not supported
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalChipMeasurePhase( uint8_t* result );
-
-
-/*!
- *****************************************************************************
- * \brief Measure Capacitance
- *
- * Measures the Capacitance
- *
- * \param[out] result : result of Capacitance measurement
- *
- * \return RFAL_ERR_IO : Internal error
- * \return RFAL_ERR_NOTSUPP : Feature not supported
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalChipMeasureCapacitance( uint8_t* result );
-
-
-/*!
- *****************************************************************************
- * \brief Measure Power Supply
- *
- * Measures the Power Supply
- *
- * \param[in] param : measurement parameter (chip specific)
- * \param[out] result : result of the measurement
- *
- * \return RFAL_ERR_IO : Internal error
- * \return RFAL_ERR_NOTSUPP : Feature not supported
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalChipMeasurePowerSupply( uint8_t param, uint8_t* result );
-
-
-/*!
- *****************************************************************************
- * \brief Measure I and Q
- *
- * Measures I and Q channels
- *
- * \param[out] resI : 8 bit long result of the I channel (signed)
- * \param[out] resQ : 8 bit long result of the Q channel (signed)
- *
- * \return RFAL_ERR_IO : Internal error
- * \return RFAL_ERR_NOTSUPP : Feature not supported
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalChipMeasureIQ( int8_t* resI, int8_t* resQ );
-
-
-/*!
- *****************************************************************************
- * \brief Measure combined I and Q
- *
- * Measures I and Q channels and combines them
- *
- * \param[out] result : I and Q combined
- *
- * \return RFAL_ERR_IO : Internal error
- * \return RFAL_ERR_NOTSUPP : Feature not supported
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalChipMeasureCombinedIQ( uint8_t* result );
-
-
-/*!
- *****************************************************************************
- * \brief Measure I channel
- *
- * Measures I channel
- *
- * \param[out] result : I channel
- *
- * \return RFAL_ERR_IO : Internal error
- * \return RFAL_ERR_NOTSUPP : Feature not supported
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalChipMeasureI( uint8_t* result );
-
-
-/*!
- *****************************************************************************
- * \brief Measure Q channel
- *
- * Measures Q channel
- *
- * \param[out] result : Q channel
- *
- * \return RFAL_ERR_IO : Internal error
- * \return RFAL_ERR_NOTSUPP : Feature not supported
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalChipMeasureQ( uint8_t* result );
-
-
-/*!
- *****************************************************************************
- * \brief Measure Current
- *
- * Measures the electrical current
- *
- * \param[out] result : current
- *
- * \return RFAL_ERR_IO : Internal error
- * \return RFAL_ERR_NOTSUPP : Feature not supported
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalChipMeasureCurrent( uint8_t* result );
-
-
-/*!
- *****************************************************************************
- * \brief Set Antenna mode
- *
- * Sets the antenna mode.
- * Differential or single ended antenna mode (RFO1 or RFO2)
- *
- * \param[in] single : FALSE differential ; single ended mode
- * \param[in] rfiox : FALSE RFI1/RFO1 ; TRUE RFI2/RFO2
- *
- * \return RFAL_ERR_IO : Internal error
- * \return RFAL_ERR_NOTSUPP : Feature not supported
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalChipSetAntennaMode( bool single, bool rfiox );
-
-#endif /* RFAL_CHIP_H */
-
-/**
- * @}
- *
- * @}
- *
- * @}
- */
+
+/******************************************************************************
+ * @attention
+ *
+ * COPYRIGHT 2016 STMicroelectronics, all rights reserved
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
+ * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+******************************************************************************/
+
+
+
+/*
+ * PROJECT: ST25R firmware
+ * Revision:
+ * LANGUAGE: ISO C99
+ */
+
+/*! \file rfal_chip.h
+ *
+ * \author Gustavo Patricio
+ *
+ * \brief RF Chip specific Layer
+ *
+ * \warning This layer, which provides direct access to RF chip, should
+ * only be used for debug purposes and/or advanced features
+ *
+ *
+ * \addtogroup RFAL
+ * @{
+ *
+ * \addtogroup RFAL-HAL
+ * \brief RFAL Hardware Abstraction Layer
+ * @{
+ *
+ * \addtogroup Chip
+ * \brief RFAL RF Chip Module
+ * @{
+ *
+ */
+
+
+#ifndef RFAL_CHIP_H
+#define RFAL_CHIP_H
+
+/*
+******************************************************************************
+* INCLUDES
+******************************************************************************
+*/
+#include "rfal_platform.h"
+#include "rfal_utils.h"
+#include "rfal_rf.h"
+
+/*
+ ******************************************************************************
+ * C LINKAGE GUARD
+ ******************************************************************************
+ */
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+
+/*****************************************************************************
+ * RF Chip *
+ *****************************************************************************/
+
+/*!
+ *****************************************************************************
+ * \brief Writes a register on the RF Chip
+ *
+ * Checks if the given register is valid and if so, writes the value(s)
+ * on the RF Chip register
+ *
+ * \param[in] reg : register address to be written, or the first if len > 1
+ * \param[in] values : pointer with content to be written on the register(s)
+ * \param[in] len : number of consecutive registers to be written
+ *
+ *
+ * \return RFAL_ERR_PARAM : Invalid register or bad request
+ * \return RFAL_ERR_NOTSUPP : Feature not supported
+ * \return RFAL_ERR_NONE : Write done with no error
+ *****************************************************************************
+ */
+ReturnCode rfalChipWriteReg( uint16_t reg, const uint8_t* values, uint8_t len );
+
+/*!
+ *****************************************************************************
+ * \brief Reads a register on the RF Chip
+ *
+ * Checks if the given register is valid and if so, reads the value(s)
+ * of the RF Chip register(s)
+ *
+ * \param[in] reg : register address to be read, or the first if len > 1
+ * \param[out] values : pointer where the register(s) read content will be placed
+ * \param[in] len : number of consecutive registers to be read
+ *
+ * \return RFAL_ERR_PARAM : Invalid register or bad request
+ * \return RFAL_ERR_NOTSUPP : Feature not supported
+ * \return RFAL_ERR_NONE : Read done with no error
+ *****************************************************************************
+ */
+ReturnCode rfalChipReadReg( uint16_t reg, uint8_t* values, uint8_t len );
+
+/*!
+ *****************************************************************************
+ * \brief Change a register on the RF Chip
+ *
+ * Change the value of the register bits on the RF Chip Test set in the valueMask.
+ *
+ * \param[in] reg : register address to be modified
+ * \param[in] valueMask : mask value of the register bits to be changed
+ * \param[in] value : register value to be set
+ *
+ * \return RFAL_ERR_PARAM : Invalid register or bad request
+ * \return RFAL_ERR_NOTSUPP : Feature not supported
+ * \return RFAL_ERR_OK : Change done with no error
+ *****************************************************************************
+ */
+ReturnCode rfalChipChangeRegBits( uint16_t reg, uint8_t valueMask, uint8_t value );
+
+/*!
+ *****************************************************************************
+ * \brief Writes a Test register on the RF Chip
+ *
+ * Writes the value on the RF Chip Test register
+ *
+ * \param[in] reg : register address to be written
+ * \param[in] value : value to be written on the register
+ *
+ *
+ * \return RFAL_ERR_PARAM : Invalid register or bad request
+ * \return RFAL_ERR_NOTSUPP : Feature not supported
+ * \return RFAL_ERR_NONE : Write done with no error
+ *****************************************************************************
+ */
+ReturnCode rfalChipWriteTestReg( uint16_t reg, uint8_t value );
+
+/*!
+ *****************************************************************************
+ * \brief Reads a Test register on the RF Chip
+ *
+ * Reads the value of the RF Chip Test register
+ *
+ * \param[in] reg : register address to be read
+ * \param[out] value : pointer where the register content will be placed
+ *
+ * \return RFAL_ERR_PARAM :Invalid register or bad request
+ * \return RFAL_ERR_NOTSUPP : Feature not supported
+ * \return RFAL_ERR_NONE : Read done with no error
+ *****************************************************************************
+ */
+ReturnCode rfalChipReadTestReg( uint16_t reg, uint8_t* value );
+
+/*!
+ *****************************************************************************
+ * \brief Change a Test register on the RF Chip
+ *
+ * Change the value of the register bits on the RF Chip Test set in the valueMask.
+ *
+ * \param[in] reg : test register address to be modified
+ * \param[in] valueMask : mask value of the register bits to be changed
+ * \param[in] value : register value to be set
+ *
+ * \return RFAL_ERR_PARAM : Invalid register or bad request
+ * \return RFAL_ERR_NOTSUPP : Feature not supported
+ * \return RFAL_ERR_OK : Change done with no error
+ *****************************************************************************
+ */
+ReturnCode rfalChipChangeTestRegBits( uint16_t reg, uint8_t valueMask, uint8_t value );
+
+/*!
+ *****************************************************************************
+ * \brief Execute command on the RF Chip
+ *
+ * Checks if the given command is valid and if so, executes it on
+ * the RF Chip
+ *
+ * \param[in] cmd : direct command to be executed
+ *
+ * \return RFAL_ERR_PARAM : Invalid command or bad request
+ * \return RFAL_ERR_NOTSUPP : Feature not supported
+ * \return RFAL_ERR_NONE : Direct command executed with no error
+ *****************************************************************************
+ */
+ReturnCode rfalChipExecCmd( uint16_t cmd );
+
+/*!
+ *****************************************************************************
+ * \brief Set RFO
+ *
+ * Sets the RFO driver resistance value used when the
+ * field is on (unmodulated/active)
+ *
+ * \param[in] rfo : the RFO value to be used
+ *
+ * \return RFAL_ERR_IO : Internal error
+ * \return RFAL_ERR_NOTSUPP : Feature not supported
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalChipSetRFO( uint8_t rfo );
+
+
+/*!
+ *****************************************************************************
+ * \brief Get RFO
+ *
+ * Gets the RFO driver resistance value used when the
+ * field is on (unmodulated/active)
+ *
+ * \param[out] result : the current RFO value
+ *
+ * \return RFAL_ERR_IO : Internal error
+ * \return RFAL_ERR_NOTSUPP : Feature not supported
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalChipGetRFO( uint8_t* result );
+
+
+/*!
+ *****************************************************************************
+ * \brief Get LM Field Indicator
+ *
+ * Gets an indicator of the signal on RFI while in Passive Listen Mode
+ *
+ * \param[out] result : the current RFI value
+ *
+ * \return RFAL_ERR_IO : Internal error
+ * \return RFAL_ERR_NOTSUPP : Feature not supported
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalChipGetLmFieldInd( uint8_t* result );
+
+/*!
+ *****************************************************************************
+ * \brief Set Listen Mode Modulation
+ *
+ * Sets the modulation (modulated and unmodulated state) when Passive Listen
+ * Mode is used
+ *
+ * \param[in] mod : modulation to be used in modulated state
+ * \param[in] unmod : modulation to be used in unmodulated state
+ *
+ * \return RFAL_ERR_IO : Internal error
+ * \return RFAL_ERR_NOTSUPP : Feature not supported
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalChipSetLMMod( uint8_t mod, uint8_t unmod );
+
+
+/*!
+ *****************************************************************************
+ * \brief Get Listen Mode Modulation
+ *
+ * Gets the modulation (modulated and unmodulated state) when Passive Listen
+ * Mode is used
+ *
+ * \param[out] mod : modulation set in modulated state
+ * \param[out] unmod : modulation set in unmodulated state
+ *
+ * \return RFAL_ERR_IO : Internal error
+ * \return RFAL_ERR_NOTSUPP : Feature not supported
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalChipGetLMMod( uint8_t* mod, uint8_t* unmod );
+
+
+/*!
+ *****************************************************************************
+ * \brief Measure Amplitude
+ *
+ * Measures the RF Amplitude
+ *
+ * \param[out] result : result of RF measurement
+ *
+ * \return RFAL_ERR_IO : Internal error
+ * \return RFAL_ERR_NOTSUPP : Feature not supported
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalChipMeasureAmplitude( uint8_t* result );
+
+
+/*!
+ *****************************************************************************
+ * \brief Measure Phase
+ *
+ * Measures the Phase
+ *
+ * \param[out] result : result of Phase measurement
+ *
+ * \return RFAL_ERR_IO : Internal error
+ * \return RFAL_ERR_NOTSUPP : Feature not supported
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalChipMeasurePhase( uint8_t* result );
+
+
+/*!
+ *****************************************************************************
+ * \brief Measure Capacitance
+ *
+ * Measures the Capacitance
+ *
+ * \param[out] result : result of Capacitance measurement
+ *
+ * \return RFAL_ERR_IO : Internal error
+ * \return RFAL_ERR_NOTSUPP : Feature not supported
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalChipMeasureCapacitance( uint8_t* result );
+
+
+/*!
+ *****************************************************************************
+ * \brief Measure Power Supply
+ *
+ * Measures the Power Supply
+ *
+ * \param[in] param : measurement parameter (chip specific)
+ * \param[out] result : result of the measurement
+ *
+ * \return RFAL_ERR_IO : Internal error
+ * \return RFAL_ERR_NOTSUPP : Feature not supported
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalChipMeasurePowerSupply( uint8_t param, uint8_t* result );
+
+
+/*!
+ *****************************************************************************
+ * \brief Measure I and Q
+ *
+ * Measures I and Q channels
+ *
+ * \param[out] resI : 8 bit long result of the I channel (signed)
+ * \param[out] resQ : 8 bit long result of the Q channel (signed)
+ *
+ * \return RFAL_ERR_IO : Internal error
+ * \return RFAL_ERR_NOTSUPP : Feature not supported
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalChipMeasureIQ( int8_t* resI, int8_t* resQ );
+
+
+/*!
+ *****************************************************************************
+ * \brief Measure combined I and Q
+ *
+ * Measures I and Q channels and combines them
+ *
+ * \param[out] result : I and Q combined
+ *
+ * \return RFAL_ERR_IO : Internal error
+ * \return RFAL_ERR_NOTSUPP : Feature not supported
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalChipMeasureCombinedIQ( uint8_t* result );
+
+
+/*!
+ *****************************************************************************
+ * \brief Measure I channel
+ *
+ * Measures I channel
+ *
+ * \param[out] result : I channel
+ *
+ * \return RFAL_ERR_IO : Internal error
+ * \return RFAL_ERR_NOTSUPP : Feature not supported
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalChipMeasureI( uint8_t* result );
+
+
+/*!
+ *****************************************************************************
+ * \brief Measure Q channel
+ *
+ * Measures Q channel
+ *
+ * \param[out] result : Q channel
+ *
+ * \return RFAL_ERR_IO : Internal error
+ * \return RFAL_ERR_NOTSUPP : Feature not supported
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalChipMeasureQ( uint8_t* result );
+
+
+/*!
+ *****************************************************************************
+ * \brief Measure Current
+ *
+ * Measures the electrical current
+ *
+ * \param[out] result : current
+ *
+ * \return RFAL_ERR_IO : Internal error
+ * \return RFAL_ERR_NOTSUPP : Feature not supported
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalChipMeasureCurrent( uint8_t* result );
+
+
+/*!
+ *****************************************************************************
+ * \brief Set Antenna mode
+ *
+ * Sets the antenna mode.
+ * Differential or single ended antenna mode (RFO1 or RFO2)
+ *
+ * \param[in] single : FALSE differential ; single ended mode
+ * \param[in] rfiox : FALSE RFI1/RFO1 ; TRUE RFI2/RFO2
+ *
+ * \return RFAL_ERR_IO : Internal error
+ * \return RFAL_ERR_NOTSUPP : Feature not supported
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalChipSetAntennaMode( bool single, bool rfiox );
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* RFAL_CHIP_H */
+
+/**
+ * @}
+ *
+ * @}
+ *
+ * @}
+ */
### core/embed/io/nfc/st25/rfal002/include/rfal_defConfig.h
@@ -1,333 +1,348 @@
-
-/******************************************************************************
- * @attention
- *
- * COPYRIGHT 2016 STMicroelectronics, all rights reserved
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
- * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
-******************************************************************************/
-
-
-
-/*
- * PROJECT: ST25R
- * Revision:
- * LANGUAGE: ISO C99
- */
-
-/*! \file rfal_defConfig.h
- *
- * \author Gustavo Patricio
- *
- * \brief RF Abstraction Layer (RFAL) default Config file
- *
- * This file contains a base/default configuration for the
- * RFAL library.
- * Users can and shall define their on configuration acording
- * to their speficic system needs on rfal_platform.h.
- *
- * \addtogroup RFAL
- * @{
- *
- */
-
-#ifndef RFAL_CONFIG_H
-#define RFAL_CONFIG_H
-
-/*
-******************************************************************************
-* INCLUDES
-******************************************************************************
-*/
-#include "rfal_features.h"
-
-
-/*
-******************************************************************************
-* GLOBAL DEFINES
-******************************************************************************
-*/
-
-
-/*
-******************************************************************************
-* RFAL FEATURES DEFAULT CONFIGURATION
-******************************************************************************
-*/
-#ifndef RFAL_FEATURE_LISTEN_MODE
- #if RFAL_SUPPORT_CE || RFAL_SUPPORT_MODE_LISTEN_ACTIVE_P2P
- #define RFAL_FEATURE_LISTEN_MODE true /*!< Enable RFAL support for Listen Mode */
- #endif /* SUPPORT LISTEN_MODE */
-#endif /* RFAL_FEATURE_LISTEN_MODE */
-
-
-#ifndef RFAL_FEATURE_WAKEUP_MODE
- #define RFAL_FEATURE_WAKEUP_MODE true /*!< Enable RFAL support for the Wake-Up mode */
-#endif /* RFAL_FEATURE_WAKEUP_MODE */
-
-
-#ifndef RFAL_FEATURE_LOWPOWER_MODE
- #define RFAL_FEATURE_LOWPOWER_MODE false /*!< RFAL support for the Low Power mode, Disabled by default */
-#endif /* RFAL_FEATURE_LOWPOWER_MODE */
-
-
-#ifndef RFAL_FEATURE_NFCA
- #if RFAL_SUPPORT_MODE_POLL_NFCA
- #define RFAL_FEATURE_NFCA true /*!< Enable RFAL support for NFC-A (ISO14443A) */
- #endif /* RFAL_SUPPORT_MODE_POLL_NFCA */
-#endif /* RFAL_FEATURE_NFCA */
-
-
-#ifndef RFAL_FEATURE_T1T
- #if RFAL_SUPPORT_MODE_POLL_NFCA
- #define RFAL_FEATURE_T1T true /*!< Enable RFAL support for T1T (Topaz) */
- #endif /* RFAL_SUPPORT_MODE_POLL_NFCA */
-#endif /* RFAL_FEATURE_T1T */
-
-#ifndef RFAL_FEATURE_T2T
- #if RFAL_SUPPORT_MODE_POLL_NFCA
- #define RFAL_FEATURE_T2T true /*!< Enable RFAL support for T2T */
- #endif /* RFAL_SUPPORT_MODE_POLL_NFCA */
-#endif /* RFAL_FEATURE_T2T */
-
-#ifndef RFAL_FEATURE_T4T
- #if RFAL_SUPPORT_MODE_POLL_NFCA
- #define RFAL_FEATURE_T4T true /*!< Enable RFAL support for T4T */
- #endif /* RFAL_SUPPORT_MODE_POLL_NFCA */
-#endif /* RFAL_FEATURE_T2T */
-
-
-#ifndef RFAL_FEATURE_NFCB
- #if RFAL_SUPPORT_MODE_POLL_NFCB
- #define RFAL_FEATURE_NFCB true /*!< Enable RFAL support for NFC-B (ISO14443B) */
- #endif /* RFAL_SUPPORT_MODE_POLL_NFCB */
-#endif /* RFAL_FEATURE_NFCB */
-
-
-#ifndef RFAL_FEATURE_ST25TB
- #if RFAL_SUPPORT_MODE_POLL_NFCB
- #define RFAL_FEATURE_ST25TB true /*!< Enable RFAL support for ST25TB */
- #endif /* RFAL_SUPPORT_MODE_POLL_NFCB */
-#endif /* RFAL_FEATURE_ST25TB */
-
-
-#ifndef RFAL_FEATURE_NFCF
- #if RFAL_SUPPORT_MODE_POLL_NFCF
- #define RFAL_FEATURE_NFCF true /*!< Enable RFAL support for NFC-F (FeliCa) */
- #endif /* RFAL_SUPPORT_MODE_POLL_NFCF */
-#endif /* RFAL_FEATURE_NFCF */
-
-
-#ifndef RFAL_FEATURE_NFCV
- #if RFAL_SUPPORT_MODE_POLL_NFCV
- #define RFAL_FEATURE_NFCV true /*!< Enable RFAL support for NFC-V (ISO15693) */
- #endif /* RFAL_SUPPORT_MODE_POLL_NFCV */
-#endif /* RFAL_FEATURE_NFCV */
-
-
-#ifndef RFAL_FEATURE_ISO_DEP
- #if RFAL_SUPPORT_MODE_POLL_NFCA || RFAL_SUPPORT_MODE_POLL_NFCB || RFAL_SUPPORT_CE
- #define RFAL_FEATURE_ISO_DEP true /*!< Enable RFAL support for ISO-DEP (ISO14443-4) */
- #endif /* RFAL_SUPPORT_MODE_ */
-#endif /* RFAL_FEATURE_ISO_DEP */
-
-
-#ifndef RFAL_FEATURE_ISO_DEP_POLL
- #if RFAL_SUPPORT_MODE_POLL_NFCA || RFAL_SUPPORT_MODE_POLL_NFCB
- #define RFAL_FEATURE_ISO_DEP_POLL true /*!< Enable RFAL support for Poller mode (PCD) ISO-DEP (ISO14443-4) */
- #endif /* RFAL_SUPPORT_MODE_ */
-#endif /* RFAL_FEATURE_ISO_DEP */
-
-
-#ifndef RFAL_FEATURE_ISO_DEP_LISTEN
- #if RFAL_SUPPORT_CE
- #define RFAL_FEATURE_ISO_DEP_LISTEN true /*!< Enable RFAL support for Listen mode (PICC) ISO-DEP (ISO14443-4) */
- #endif /* RFAL_SUPPORT_MODE_ */
-#endif /* RFAL_FEATURE_ISO_DEP */
-
-
-#ifndef RFAL_FEATURE_ISO_DEP_IBLOCK_MAX_LEN
- #if RFAL_FEATURE_ISO_DEP
- #define RFAL_FEATURE_ISO_DEP_IBLOCK_MAX_LEN 256U /*!< ISO-DEP I-Block max length. Please use values as defined by rfalIsoDepFSx */
- #endif /* RFAL_FEATURE_ISO_DEP */
-#endif /* RFAL_FEATURE_ISO_DEP_IBLOCK_MAX_LEN */
-
-
-#ifndef RFAL_FEATURE_ISO_DEP_APDU_MAX_LEN
- #if RFAL_FEATURE_ISO_DEP
- #define RFAL_FEATURE_ISO_DEP_APDU_MAX_LEN 512U /*!< ISO-DEP APDU max length. */
- #endif /* RFAL_FEATURE_ISO_DEP */
-#endif /* RFAL_FEATURE_ISO_DEP_APDU_MAX_LEN */
-
-
-#ifndef RFAL_FEATURE_NFC_DEP
- #if RFAL_SUPPORT_MODE_POLL_NFCA && RFAL_SUPPORT_MODE_POLL_NFCF
- #define RFAL_FEATURE_NFC_DEP true /*!< Enable RFAL support for NFC-DEP (NFCIP1/P2P) */
- #endif /* RFAL_SUPPORT_MODE_POLL_NFCA/F */
-#endif /* RFAL_FEATURE_NFC_DEP */
-
-
-#ifndef RFAL_FEATURE_NFC_DEP_BLOCK_MAX_LEN
- #if RFAL_FEATURE_NFC_DEP
- #define RFAL_FEATURE_NFC_DEP_BLOCK_MAX_LEN 254U /*!< NFC-DEP Block/Payload length. Allowed values: 64, 128, 192, 254 */
- #endif /* RFAL_FEATURE_NFC_DEP */
-#endif /* RFAL_FEATURE_NFC_DEP_BLOCK_MAX_LEN */
-
-
-#ifndef RFAL_FEATURE_NFC_DEP_PDU_MAX_LEN
- #if RFAL_FEATURE_NFC_DEP
- #define RFAL_FEATURE_NFC_DEP_PDU_MAX_LEN 512U /*!< NFC-DEP PDU max length. */
- #endif /* RFAL_FEATURE_NFC_DEP */
-#endif /* RFAL_FEATURE_NFC_DEP_PDU_MAX_LEN */
-
-
-#ifndef RFAL_FEATURE_NFC_RF_BUF_LEN
- #define RFAL_FEATURE_NFC_RF_BUF_LEN 258U /*!< RF buffer length used by RFAL NFC layer */
-#endif /* RFAL_FEATURE_NFC_RF_BUF_LEN */
-
-
-#ifndef RFAL_FEATURE_ST25xV
- #define RFAL_FEATURE_ST25xV false /*!< ST25xV Module configuration missing. Disabled by default */
-#endif
-
-
-#ifndef RFAL_FEATURE_DYNAMIC_ANALOG_CONFIG
- #define RFAL_FEATURE_DYNAMIC_ANALOG_CONFIG false /*!< Dynamic Analog Configs configuration missing. Disabled by default */
-#endif
-
-
-#ifndef RFAL_FEATURE_DPO
- #define RFAL_FEATURE_DPO false /*!< Dynamic Power Module configuration missing. Disabled by default */
-#endif
-
-#ifndef RFAL_FEATURE_DLMA
- #define RFAL_FEATURE_DLMA false /*!< Dynamic LMA Module configuration missing. Disabled by default */
-#endif
-
-
-
-
- /*
- ******************************************************************************
- * RFAL OPTIONAL MACROS
- ******************************************************************************
- */
-
-#ifndef platformProtectST25RIrqStatus
- #define platformProtectST25RIrqStatus() /*!< Protect unique access to IRQ status var - IRQ disable on single thread environment (MCU) ; Mutex lock on a multi thread environment */
-#endif /* platformProtectST25RIrqStatus */
-
-#ifndef platformUnprotectST25RIrqStatus
- #define platformUnprotectST25RIrqStatus() /*!< Unprotect the IRQ status var - IRQ enable on a single thread environment (MCU) ; Mutex unlock on a multi thread environment */
-#endif /* platformUnprotectST25RIrqStatus */
-
-#ifndef platformProtectWorker
- #define platformProtectWorker() /*!< Protect RFAL Worker/Task/Process from concurrent execution on multi thread platforms */
-#endif /* platformProtectWorker */
-
-#ifndef platformUnprotectWorker
- #define platformUnprotectWorker() /*!< Unprotect RFAL Worker/Task/Process from concurrent execution on multi thread platforms */
-#endif /* platformUnprotectWorker */
-
-#ifndef platformIrqST25RPinInitialize
- #define platformIrqST25RPinInitialize() /*!< Initializes ST25R IRQ pin */
-#endif /* platformIrqST25RPinInitialize */
-
-#ifndef platformIrqST25RSetCallback
- #define platformIrqST25RSetCallback( cb ) /*!< Sets ST25R ISR callback */
-#endif /* platformIrqST25RSetCallback */
-
-#ifndef platformLedsInitialize
- #define platformLedsInitialize() /*!< Initializes the pins used as LEDs to outputs */
-#endif /* platformLedsInitialize */
-
-#ifndef platformLedOff
- #define platformLedOff( port, pin ) /*!< Turns the given LED Off */
-#endif /* platformLedOff */
-
-#ifndef platformLedOn
- #define platformLedOn( port, pin ) /*!< Turns the given LED On */
-#endif /* platformLedOn */
-
-#ifndef platformLedToggle
- #define platformLedToggle( port, pin ) /*!< Toggles the given LED */
-#endif /* platformLedToggle */
-
-#ifndef platformGetSysTick
- #define platformGetSysTick() /*!< Get System Tick ( 1 tick = 1 ms) */
-#endif /* platformGetSysTick */
-
-#ifndef platformTimerGetRemaining
- #define platformTimerGetRemaining( timer ) (0U) /*!< Gets the remaining time until expiration */
-#endif /* platformTimerGetRemaining */
-
-#ifndef platformTimerDestroy
- #define platformTimerDestroy( timer ) /*!< Stops and released the given timer */
-#endif /* platformTimerDestroy */
-
-#ifndef platformLog
- #define platformLog(...) /*!< Log method */
-#endif /* platformLog */
-
-#ifndef platformAssert
- #define platformAssert( exp ) /*!< Asserts whether the given expression is true */
-#endif /* platformAssert */
-
-#ifndef platformErrorHandle
- #define platformErrorHandle() /*!< Global error handler or trap */
-#endif /* platformErrorHandle */
-
-
-#ifdef RFAL_USE_I2C
-
- #ifndef platformSpiTxRx
- #define platformSpiTxRx( txBuf, rxBuf, len ) /*!< SPI transceive */
- #endif /* platformSpiTxRx */
-
-#else /* RFAL_USE_I2C */
-
- #ifndef platformI2CTx
- #define platformI2CTx( txBuf, len, last, txOnly ) /*!< I2C Transmit */
- #endif /* platformI2CTx */
-
- #ifndef platformI2CRx
- #define platformI2CRx( txBuf, len ) /*!< I2C Receive */
- #endif /* platformI2CRx */
-
- #ifndef platformI2CStart
- #define platformI2CStart() /*!< I2C Start condition */
- #endif /* platformI2CStart */
-
- #ifndef platformI2CStop
- #define platformI2CStop() /*!< I2C Stop condition */
- #endif /* platformI2CStop */
-
- #ifndef platformI2CRepeatStart
- #define platformI2CRepeatStart() /*!< I2C Repeat Start */
- #endif /* platformI2CRepeatStart */
-
- #ifndef platformI2CSlaveAddrWR
- #define platformI2CSlaveAddrWR(add) /*!< I2C Slave address for Write operation */
- #endif /* platformI2CSlaveAddrWR */
-
- #ifndef platformI2CSlaveAddrRD
- #define platformI2CSlaveAddrRD(add) /*!< I2C Slave address for Read operation */
- #endif /* platformI2CSlaveAddrRD */
-
-#endif /* RFAL_USE_I2C */
-
-#endif /* RFAL_CONFIG_H */
-
-
-/**
- * @}
- *
- */
-
+
+/******************************************************************************
+ * @attention
+ *
+ * COPYRIGHT 2016 STMicroelectronics, all rights reserved
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
+ * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+******************************************************************************/
+
+
+
+/*
+ * PROJECT: ST25R
+ * Revision:
+ * LANGUAGE: ISO C99
+ */
+
+/*! \file rfal_defConfig.h
+ *
+ * \author Gustavo Patricio
+ *
+ * \brief RF Abstraction Layer (RFAL) default Config file
+ *
+ * This file contains a base/default configuration for the
+ * RFAL library.
+ * Users can and shall define their on configuration acording
+ * to their speficic system needs on rfal_platform.h.
+ *
+ * \attention Do not modify this file.
+ *
+ * \addtogroup RFAL
+ * @{
+ *
+ */
+
+#ifndef RFAL_CONFIG_H
+#define RFAL_CONFIG_H
+
+/*
+******************************************************************************
+* INCLUDES
+******************************************************************************
+*/
+#include "rfal_features.h"
+
+/*
+ ******************************************************************************
+ * C LINKAGE GUARD
+ ******************************************************************************
+ */
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+
+/*
+******************************************************************************
+* GLOBAL DEFINES
+******************************************************************************
+*/
+
+
+/*
+******************************************************************************
+* RFAL FEATURES DEFAULT CONFIGURATION
+******************************************************************************
+*/
+#ifndef RFAL_FEATURE_LISTEN_MODE
+ #if RFAL_SUPPORT_CE || RFAL_SUPPORT_MODE_LISTEN_ACTIVE_P2P
+ #define RFAL_FEATURE_LISTEN_MODE true /*!< Enable RFAL support for Listen Mode */
+ #endif /* SUPPORT LISTEN_MODE */
+#endif /* RFAL_FEATURE_LISTEN_MODE */
+
+
+#ifndef RFAL_FEATURE_WAKEUP_MODE
+ #define RFAL_FEATURE_WAKEUP_MODE true /*!< Enable RFAL support for the Wake-Up mode */
+#endif /* RFAL_FEATURE_WAKEUP_MODE */
+
+
+#ifndef RFAL_FEATURE_LOWPOWER_MODE
+ #define RFAL_FEATURE_LOWPOWER_MODE false /*!< RFAL support for the Low Power mode, Disabled by default */
+#endif /* RFAL_FEATURE_LOWPOWER_MODE */
+
+
+#ifndef RFAL_FEATURE_NFCA
+ #if RFAL_SUPPORT_MODE_POLL_NFCA
+ #define RFAL_FEATURE_NFCA true /*!< Enable RFAL support for NFC-A (ISO14443A) */
+ #endif /* RFAL_SUPPORT_MODE_POLL_NFCA */
+#endif /* RFAL_FEATURE_NFCA */
+
+
+#ifndef RFAL_FEATURE_T1T
+ #if RFAL_SUPPORT_MODE_POLL_NFCA
+ #define RFAL_FEATURE_T1T true /*!< Enable RFAL support for T1T (Topaz) */
+ #endif /* RFAL_SUPPORT_MODE_POLL_NFCA */
+#endif /* RFAL_FEATURE_T1T */
+
+#ifndef RFAL_FEATURE_T2T
+ #if RFAL_SUPPORT_MODE_POLL_NFCA
+ #define RFAL_FEATURE_T2T true /*!< Enable RFAL support for T2T */
+ #endif /* RFAL_SUPPORT_MODE_POLL_NFCA */
+#endif /* RFAL_FEATURE_T2T */
+
+#ifndef RFAL_FEATURE_T4T
+ #if RFAL_SUPPORT_MODE_POLL_NFCA
+ #define RFAL_FEATURE_T4T true /*!< Enable RFAL support for T4T */
+ #endif /* RFAL_SUPPORT_MODE_POLL_NFCA */
+#endif /* RFAL_FEATURE_T2T */
+
+
+#ifndef RFAL_FEATURE_NFCB
+ #if RFAL_SUPPORT_MODE_POLL_NFCB
+ #define RFAL_FEATURE_NFCB true /*!< Enable RFAL support for NFC-B (ISO14443B) */
+ #endif /* RFAL_SUPPORT_MODE_POLL_NFCB */
+#endif /* RFAL_FEATURE_NFCB */
+
+
+#ifndef RFAL_FEATURE_ST25TB
+ #if RFAL_SUPPORT_MODE_POLL_NFCB
+ #define RFAL_FEATURE_ST25TB true /*!< Enable RFAL support for ST25TB */
+ #endif /* RFAL_SUPPORT_MODE_POLL_NFCB */
+#endif /* RFAL_FEATURE_ST25TB */
+
+
+#ifndef RFAL_FEATURE_NFCF
+ #if RFAL_SUPPORT_MODE_POLL_NFCF
+ #define RFAL_FEATURE_NFCF true /*!< Enable RFAL support for NFC-F (FeliCa) */
+ #endif /* RFAL_SUPPORT_MODE_POLL_NFCF */
+#endif /* RFAL_FEATURE_NFCF */
+
+
+#ifndef RFAL_FEATURE_NFCV
+ #if RFAL_SUPPORT_MODE_POLL_NFCV
+ #define RFAL_FEATURE_NFCV true /*!< Enable RFAL support for NFC-V (ISO15693) */
+ #endif /* RFAL_SUPPORT_MODE_POLL_NFCV */
+#endif /* RFAL_FEATURE_NFCV */
+
+
+#ifndef RFAL_FEATURE_ISO_DEP
+ #if RFAL_SUPPORT_MODE_POLL_NFCA || RFAL_SUPPORT_MODE_POLL_NFCB || RFAL_SUPPORT_CE
+ #define RFAL_FEATURE_ISO_DEP true /*!< Enable RFAL support for ISO-DEP (ISO14443-4) */
+ #endif /* RFAL_SUPPORT_MODE_ */
+#endif /* RFAL_FEATURE_ISO_DEP */
+
+
+#ifndef RFAL_FEATURE_ISO_DEP_POLL
+ #if RFAL_SUPPORT_MODE_POLL_NFCA || RFAL_SUPPORT_MODE_POLL_NFCB
+ #define RFAL_FEATURE_ISO_DEP_POLL true /*!< Enable RFAL support for Poller mode (PCD) ISO-DEP (ISO14443-4) */
+ #endif /* RFAL_SUPPORT_MODE_ */
+#endif /* RFAL_FEATURE_ISO_DEP */
+
+
+#ifndef RFAL_FEATURE_ISO_DEP_LISTEN
+ #if RFAL_SUPPORT_CE
+ #define RFAL_FEATURE_ISO_DEP_LISTEN true /*!< Enable RFAL support for Listen mode (PICC) ISO-DEP (ISO14443-4) */
+ #endif /* RFAL_SUPPORT_MODE_ */
+#endif /* RFAL_FEATURE_ISO_DEP */
+
+
+#ifndef RFAL_FEATURE_ISO_DEP_IBLOCK_MAX_LEN
+ #if RFAL_FEATURE_ISO_DEP
+ #define RFAL_FEATURE_ISO_DEP_IBLOCK_MAX_LEN 256U /*!< ISO-DEP I-Block max length. Please use values as defined by rfalIsoDepFSx */
+ #endif /* RFAL_FEATURE_ISO_DEP */
+#endif /* RFAL_FEATURE_ISO_DEP_IBLOCK_MAX_LEN */
+
+
+#ifndef RFAL_FEATURE_ISO_DEP_APDU_MAX_LEN
+ #if RFAL_FEATURE_ISO_DEP
+ #define RFAL_FEATURE_ISO_DEP_APDU_MAX_LEN 512U /*!< ISO-DEP APDU max length. */
+ #endif /* RFAL_FEATURE_ISO_DEP */
+#endif /* RFAL_FEATURE_ISO_DEP_APDU_MAX_LEN */
+
+
+#ifndef RFAL_FEATURE_NFC_DEP
+ #if RFAL_SUPPORT_MODE_POLL_NFCA && RFAL_SUPPORT_MODE_POLL_NFCF
+ #define RFAL_FEATURE_NFC_DEP true /*!< Enable RFAL support for NFC-DEP (NFCIP1/P2P) */
+ #endif /* RFAL_SUPPORT_MODE_POLL_NFCA/F */
+#endif /* RFAL_FEATURE_NFC_DEP */
+
+
+#ifndef RFAL_FEATURE_NFC_DEP_BLOCK_MAX_LEN
+ #if RFAL_FEATURE_NFC_DEP
+ #define RFAL_FEATURE_NFC_DEP_BLOCK_MAX_LEN 254U /*!< NFC-DEP Block/Payload length. Allowed values: 64, 128, 192, 254 */
+ #endif /* RFAL_FEATURE_NFC_DEP */
+#endif /* RFAL_FEATURE_NFC_DEP_BLOCK_MAX_LEN */
+
+
+#ifndef RFAL_FEATURE_NFC_DEP_PDU_MAX_LEN
+ #if RFAL_FEATURE_NFC_DEP
+ #define RFAL_FEATURE_NFC_DEP_PDU_MAX_LEN 512U /*!< NFC-DEP PDU max length. */
+ #endif /* RFAL_FEATURE_NFC_DEP */
+#endif /* RFAL_FEATURE_NFC_DEP_PDU_MAX_LEN */
+
+
+#ifndef RFAL_FEATURE_NFC_RF_BUF_LEN
+ #define RFAL_FEATURE_NFC_RF_BUF_LEN 258U /*!< RF buffer length used by RFAL NFC layer */
+#endif /* RFAL_FEATURE_NFC_RF_BUF_LEN */
+
+
+#ifndef RFAL_FEATURE_ST25xV
+ #define RFAL_FEATURE_ST25xV false /*!< ST25xV Module configuration missing. Disabled by default */
+#endif
+
+
+#ifndef RFAL_FEATURE_DYNAMIC_ANALOG_CONFIG
+ #define RFAL_FEATURE_DYNAMIC_ANALOG_CONFIG false /*!< Dynamic Analog Configs configuration missing. Disabled by default */
+#endif
+
+
+#ifndef RFAL_FEATURE_DPO
+ #define RFAL_FEATURE_DPO false /*!< Dynamic Power Module configuration missing. Disabled by default */
+#endif
+
+#ifndef RFAL_FEATURE_DLMA
+ #define RFAL_FEATURE_DLMA false /*!< Dynamic LMA Module configuration missing. Disabled by default */
+#endif
+
+
+
+
+ /*
+ ******************************************************************************
+ * RFAL OPTIONAL MACROS
+ ******************************************************************************
+ */
+
+#ifndef platformProtectST25RIrqStatus
+ #define platformProtectST25RIrqStatus() /*!< Protect unique access to IRQ status var - IRQ disable on single thread environment (MCU) ; Mutex lock on a multi thread environment */
+#endif /* platformProtectST25RIrqStatus */
+
+#ifndef platformUnprotectST25RIrqStatus
+ #define platformUnprotectST25RIrqStatus() /*!< Unprotect the IRQ status var - IRQ enable on a single thread environment (MCU) ; Mutex unlock on a multi thread environment */
+#endif /* platformUnprotectST25RIrqStatus */
+
+#ifndef platformProtectWorker
+ #define platformProtectWorker() /*!< Protect RFAL Worker/Task/Process from concurrent execution on multi thread platforms */
+#endif /* platformProtectWorker */
+
+#ifndef platformUnprotectWorker
+ #define platformUnprotectWorker() /*!< Unprotect RFAL Worker/Task/Process from concurrent execution on multi thread platforms */
+#endif /* platformUnprotectWorker */
+
+#ifndef platformIrqST25RPinInitialize
+ #define platformIrqST25RPinInitialize() /*!< Initializes ST25R IRQ pin */
+#endif /* platformIrqST25RPinInitialize */
+
+#ifndef platformIrqST25RSetCallback
+ #define platformIrqST25RSetCallback( cb ) /*!< Sets ST25R ISR callback */
+#endif /* platformIrqST25RSetCallback */
+
+#ifndef platformLedsInitialize
+ #define platformLedsInitialize() /*!< Initializes the pins used as LEDs to outputs */
+#endif /* platformLedsInitialize */
+
+#ifndef platformLedOff
+ #define platformLedOff( port, pin ) /*!< Turns the given LED Off */
+#endif /* platformLedOff */
+
+#ifndef platformLedOn
+ #define platformLedOn( port, pin ) /*!< Turns the given LED On */
+#endif /* platformLedOn */
+
+#ifndef platformLedToggle
+ #define platformLedToggle( port, pin ) /*!< Toggles the given LED */
+#endif /* platformLedToggle */
+
+#ifndef platformGetSysTick
+ #define platformGetSysTick() /*!< Get System Tick ( 1 tick = 1 ms) */
+#endif /* platformGetSysTick */
+
+#ifndef platformTimerGetRemaining
+ #define platformTimerGetRemaining( timer ) (0U) /*!< Gets the remaining time until expiration */
+#endif /* platformTimerGetRemaining */
+
+#ifndef platformTimerDestroy
+ #define platformTimerDestroy( timer ) /*!< Stops and released the given timer */
+#endif /* platformTimerDestroy */
+
+#ifndef platformLog
+ #define platformLog(...) /*!< Log method */
+#endif /* platformLog */
+
+#ifndef platformAssert
+ #define platformAssert( exp ) /*!< Asserts whether the given expression is true */
+#endif /* platformAssert */
+
+#ifndef platformErrorHandle
+ #define platformErrorHandle() /*!< Global error handler or trap */
+#endif /* platformErrorHandle */
+
+
+#ifdef RFAL_USE_I2C
+
+ #ifndef platformSpiTxRx
+ #define platformSpiTxRx( txBuf, rxBuf, len ) /*!< SPI transceive */
+ #endif /* platformSpiTxRx */
+
+#else /* RFAL_USE_I2C */
+
+ #ifndef platformI2CTx
+ #define platformI2CTx( txBuf, len, last, txOnly ) /*!< I2C Transmit */
+ #endif /* platformI2CTx */
+
+ #ifndef platformI2CRx
+ #define platformI2CRx( rxBuf, len ) /*!< I2C Receive */
+ #endif /* platformI2CRx */
+
+ #ifndef platformI2CStart
+ #define platformI2CStart() /*!< I2C Start condition */
+ #endif /* platformI2CStart */
+
+ #ifndef platformI2CStop
+ #define platformI2CStop() /*!< I2C Stop condition */
+ #endif /* platformI2CStop */
+
+ #ifndef platformI2CRepeatStart
+ #define platformI2CRepeatStart() /*!< I2C Repeat Start */
+ #endif /* platformI2CRepeatStart */
+
+ #ifndef platformI2CSlaveAddrWR
+ #define platformI2CSlaveAddrWR(add) /*!< I2C Slave address for Write operation */
+ #endif /* platformI2CSlaveAddrWR */
+
+ #ifndef platformI2CSlaveAddrRD
+ #define platformI2CSlaveAddrRD(add) /*!< I2C Slave address for Read operation */
+ #endif /* platformI2CSlaveAddrRD */
+
+#endif /* RFAL_USE_I2C */
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* RFAL_CONFIG_H */
+
+
+/**
+ * @}
+ *
+ */
+
### core/embed/io/nfc/st25/rfal002/include/rfal_dlma.h
@@ -1,246 +1,259 @@
-
-/******************************************************************************
- * @attention
- *
- * COPYRIGHT 2016 STMicroelectronics, all rights reserved
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
- * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
-******************************************************************************/
-
-
-/*
- * PROJECT: ST25R firmware
- * $Revision: $
- * LANGUAGE: ISO C99
- */
-
-/*! \file rfal_dlma.h
- *
- * \brief Dynamic load modulation adjustment
- *
- * This module provides an interface to perform the load modulation dynamically
- *
- *
- * \addtogroup RFAL
- * @{
- *
- * \addtogroup RFAL-HAL
- * \brief RFAL Hardware Abstraction Layer
- * @{
- *
- * \addtogroup DLMA
- * \brief RFAL Dynamic Load modulation
- * @{
- *
- */
-
-
-#ifndef RFAL_DLMA_H
-#define RFAL_DLMA_H
-
-/*
- ******************************************************************************
- * INCLUDES
- ******************************************************************************
- */
-#include "rfal_platform.h"
-#include "rfal_utils.h"
-
-/*
- ******************************************************************************
- * GLOBAL DEFINES
- ******************************************************************************
- */
-
-#define RFAL_DLMA_TABLE_MAX_ENTRIES 4U /*!< Max DLMA entries */
-#define RFAL_DLMA_TABLE_PARAM_LEN sizeof(rfalDlmaEntry) /*!< DLMA Parameter length */
-#define RFAL_DLMA_TABLE_SIZE_MAX (RFAL_DLMA_TABLE_MAX_ENTRIES * RFAL_DLMA_TABLE_PARAM_LEN) /*!< Max DLMA table size */
-
-/*
-******************************************************************************
-* GLOBAL TYPES
-******************************************************************************
-*/
-
-/*! Function pointer to methode doing the reference measurement */
-typedef ReturnCode (*rfalDlmaMeasureFunc)(uint8_t* res);
-
-/*! Function pointer to the Adjustment method */
-typedef ReturnCode (*rfalDlmaAdjustFunc)(uint8_t mod, uint8_t unmod);
-
-
-/*! DLMA table entry struct */
-typedef struct
-{
- uint8_t unmodRes; /*!< RFO resistance in Passive Listen Mode: Unmodulated state */
- uint8_t modRes; /*!< RFO resistance in Passive Listen Mode: Modulated state */
- uint8_t inc; /*!< Threshold for incrementing */
- uint8_t dec; /*!< Threshold for decrementing */
-}rfalDlmaEntry;
-
-
-/*! DLMA information struct */
-typedef struct
-{
- bool enabled; /*!< Enabled state */
- uint8_t tableEntry; /*!< Current entry used */
- uint8_t tableEntries; /*!< Number of entries used */
- uint8_t refMeasurement; /*!< Last measurement used to adjust */
- rfalDlmaAdjustFunc adjustCallback; /*!< Pointer to the adjust callback */
- rfalDlmaMeasureFunc measureCallback; /*!< Pointer to the measure callback */
-} rfalDlmaInfo;
-
-
-/*
-******************************************************************************
-* GLOBAL FUNCTION PROTOTYPES
-******************************************************************************
-*/
-
-
-/*!
- *****************************************************************************
- * \brief Initialize dynamic power table
- *
- * This function sets the internal dynamic power table to the default
- * values stored in rfal_DlmaTbl.h
- *
- *****************************************************************************
- */
-void rfalDlmaInitialize( void );
-
-
-/*!
- *****************************************************************************
- * \brief Set the measurement methode
- *
- * This function sets the measurement method used for reference measurement.
- * Based on the measurement the power will then be adjusted
- *
- * \param[in] pFunc: callback of measurement function
- *
- *****************************************************************************
- */
-void rfalDlmaSetMeasureCallback( rfalDlmaMeasureFunc pFunc );
-
-
-/*!
- *****************************************************************************
- * \brief Set the measurement methode
- *
- * This function sets the adjust method.
- *
- * \param[in] pFunc: callback of adjust function
- *
- *****************************************************************************
- */
-void rfalDlmaSetAdjustCallback( rfalDlmaAdjustFunc pFunc );
-
-
-/*!
- *****************************************************************************
- * \brief Dynamic LMA table write
- *
- * Load the dynamic power table
- *
- * \param[in] powerTbl : location of power Table to be loaded
- * \param[in] powerTblEntries : number of entries of the power Table to be loaded
- *
- * \return RFAL_ERR_NONE : No error
- * \return RFAL_ERR_PARAM : If configTbl is invalid
- * \return RFAL_ERR_NOMEM : If the given Table is bigger exceeds the max size
- *****************************************************************************
- */
-ReturnCode rfalDlmaTableWrite( const rfalDlmaEntry* powerTbl, uint8_t powerTblEntries );
-
-
-/*!
- *****************************************************************************
- * \brief Dynamic LMA table Read
- *
- * Read the dynamic power table
- *
- * \param[out] tblBuf : location to the rfalDlmaEntry[] to place the Table
- * \param[in] tblBufEntries : number of entries available in tblBuf to place the power Table
- * \param[out] tableEntries : returned number of entries actually written into tblBuf
- *
- * \return RFAL_ERR_NONE : No error
- * \return RFAL_ERR_WRONG_STATE : If configTbl is invalid
- * \return RFAL_ERR_PARAM : If parameters are invalid
- *****************************************************************************
- */
-ReturnCode rfalDlmaTableRead( rfalDlmaEntry* tblBuf, uint8_t tblBufEntries, uint8_t* tableEntries );
-
-
-/*!
- *****************************************************************************
- * \brief Dynamic LMA adjust
- *
- * It measures the current output and adjusts the power accordingly to
- * the dynamic power table
- *
- * \return RFAL_ERR_NONE : No error
- * \return RFAL_ERR_PARAM : If configTbl is invalid or parameters are invalid
- * \return RFAL_ERR_WRONG_STATE : If the current state is valid for DLMA Adjustment
- *****************************************************************************
- */
-ReturnCode rfalDlmaAdjust( void );
-
-
-/*!
- *****************************************************************************
- * \brief Dynamic LMA set enabled state
- *
- * \param[in] enable : new active state
- *
- * Set state to enable or disable the Dynamic LMA adjustment
- *
- *****************************************************************************
- */
-void rfalDlmaSetEnabled( bool enable );
-
-
-/*!
- *****************************************************************************
- * \brief Get the Dynamic LMA enabled state
- *
- * Get state of the Dynamic power adjustment
- *
- * \return true : DLMA is enabled
- * \return false : DLMA is disabled
- *****************************************************************************
- */
-bool rfalDlmaIsEnabled( void );
-
-
-/*!
- *****************************************************************************
- * \brief Get DLMA information
- *
- * Get the DLMA information|status
- *
- * \param[out] info : DLMA information
- *
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_NONE : No Error
- *****************************************************************************
- */
-ReturnCode rfalDlmaGetInfo( rfalDlmaInfo* info );
-
-
-#endif /* RFAL_DLMA_H */
-
-/**
- * @}
- *
- * @}
- *
- * @}
- */
+
+/******************************************************************************
+ * @attention
+ *
+ * COPYRIGHT 2016 STMicroelectronics, all rights reserved
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
+ * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+******************************************************************************/
+
+
+/*
+ * PROJECT: ST25R firmware
+ * $Revision: $
+ * LANGUAGE: ISO C99
+ */
+
+/*! \file rfal_dlma.h
+ *
+ * \brief Dynamic load modulation adjustment
+ *
+ * This module provides an interface to perform the load modulation dynamically
+ *
+ *
+ * \addtogroup RFAL
+ * @{
+ *
+ * \addtogroup RFAL-HAL
+ * \brief RFAL Hardware Abstraction Layer
+ * @{
+ *
+ * \addtogroup DLMA
+ * \brief RFAL Dynamic Load modulation
+ * @{
+ *
+ */
+
+
+#ifndef RFAL_DLMA_H
+#define RFAL_DLMA_H
+
+/*
+ ******************************************************************************
+ * INCLUDES
+ ******************************************************************************
+ */
+#include "rfal_platform.h"
+#include "rfal_utils.h"
+
+/*
+ ******************************************************************************
+ * C LINKAGE GUARD
+ ******************************************************************************
+ */
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/*
+ ******************************************************************************
+ * GLOBAL DEFINES
+ ******************************************************************************
+ */
+
+#define RFAL_DLMA_TABLE_MAX_ENTRIES 4U /*!< Max DLMA entries */
+#define RFAL_DLMA_TABLE_PARAM_LEN sizeof(rfalDlmaEntry) /*!< DLMA Parameter length */
+#define RFAL_DLMA_TABLE_SIZE_MAX (RFAL_DLMA_TABLE_MAX_ENTRIES * RFAL_DLMA_TABLE_PARAM_LEN) /*!< Max DLMA table size */
+
+/*
+******************************************************************************
+* GLOBAL TYPES
+******************************************************************************
+*/
+
+/*! Function pointer to methode doing the reference measurement */
+typedef ReturnCode (*rfalDlmaMeasureFunc)(uint8_t* res);
+
+/*! Function pointer to the Adjustment method */
+typedef ReturnCode (*rfalDlmaAdjustFunc)(uint8_t mod, uint8_t unmod);
+
+
+/*! DLMA table entry struct */
+typedef struct
+{
+ uint8_t unmodRes; /*!< RFO resistance in Passive Listen Mode: Unmodulated state */
+ uint8_t modRes; /*!< RFO resistance in Passive Listen Mode: Modulated state */
+ uint8_t inc; /*!< Threshold for incrementing */
+ uint8_t dec; /*!< Threshold for decrementing */
+}rfalDlmaEntry;
+
+
+/*! DLMA information struct */
+typedef struct
+{
+ bool enabled; /*!< Enabled state */
+ uint8_t tableEntry; /*!< Current entry used */
+ uint8_t tableEntries; /*!< Number of entries used */
+ uint8_t refMeasurement; /*!< Last measurement used to adjust */
+ rfalDlmaAdjustFunc adjustCallback; /*!< Pointer to the adjust callback */
+ rfalDlmaMeasureFunc measureCallback; /*!< Pointer to the measure callback */
+} rfalDlmaInfo;
+
+
+/*
+******************************************************************************
+* GLOBAL FUNCTION PROTOTYPES
+******************************************************************************
+*/
+
+
+/*!
+ *****************************************************************************
+ * \brief Initialize dynamic power table
+ *
+ * This function sets the internal dynamic power table to the default
+ * values stored in rfal_DlmaTbl.h
+ *
+ *****************************************************************************
+ */
+void rfalDlmaInitialize( void );
+
+
+/*!
+ *****************************************************************************
+ * \brief Set the measurement methode
+ *
+ * This function sets the measurement method used for reference measurement.
+ * Based on the measurement the power will then be adjusted
+ *
+ * \param[in] pFunc: callback of measurement function
+ *
+ *****************************************************************************
+ */
+void rfalDlmaSetMeasureCallback( rfalDlmaMeasureFunc pFunc );
+
+
+/*!
+ *****************************************************************************
+ * \brief Set the measurement methode
+ *
+ * This function sets the adjust method.
+ *
+ * \param[in] pFunc: callback of adjust function
+ *
+ *****************************************************************************
+ */
+void rfalDlmaSetAdjustCallback( rfalDlmaAdjustFunc pFunc );
+
+
+/*!
+ *****************************************************************************
+ * \brief Dynamic LMA table write
+ *
+ * Load the dynamic power table
+ *
+ * \param[in] powerTbl : location of power Table to be loaded
+ * \param[in] powerTblEntries : number of entries of the power Table to be loaded
+ *
+ * \return RFAL_ERR_NONE : No error
+ * \return RFAL_ERR_PARAM : If configTbl is invalid
+ * \return RFAL_ERR_NOMEM : If the given Table is bigger exceeds the max size
+ *****************************************************************************
+ */
+ReturnCode rfalDlmaTableWrite( const rfalDlmaEntry* powerTbl, uint8_t powerTblEntries );
+
+
+/*!
+ *****************************************************************************
+ * \brief Dynamic LMA table Read
+ *
+ * Read the dynamic power table
+ *
+ * \param[out] tblBuf : location to the rfalDlmaEntry[] to place the Table
+ * \param[in] tblBufEntries : number of entries available in tblBuf to place the power Table
+ * \param[out] tableEntries : returned number of entries actually written into tblBuf
+ *
+ * \return RFAL_ERR_NONE : No error
+ * \return RFAL_ERR_WRONG_STATE : If configTbl is invalid
+ * \return RFAL_ERR_PARAM : If parameters are invalid
+ *****************************************************************************
+ */
+ReturnCode rfalDlmaTableRead( rfalDlmaEntry* tblBuf, uint8_t tblBufEntries, uint8_t* tableEntries );
+
+
+/*!
+ *****************************************************************************
+ * \brief Dynamic LMA adjust
+ *
+ * It measures the current output and adjusts the power accordingly to
+ * the dynamic power table
+ *
+ * \return RFAL_ERR_NONE : No error
+ * \return RFAL_ERR_PARAM : If configTbl is invalid or parameters are invalid
+ * \return RFAL_ERR_WRONG_STATE : If the current state is valid for DLMA Adjustment
+ *****************************************************************************
+ */
+ReturnCode rfalDlmaAdjust( void );
+
+
+/*!
+ *****************************************************************************
+ * \brief Dynamic LMA set enabled state
+ *
+ * \param[in] enable : new active state
+ *
+ * Set state to enable or disable the Dynamic LMA adjustment
+ *
+ *****************************************************************************
+ */
+void rfalDlmaSetEnabled( bool enable );
+
+
+/*!
+ *****************************************************************************
+ * \brief Get the Dynamic LMA enabled state
+ *
+ * Get state of the Dynamic power adjustment
+ *
+ * \return true : DLMA is enabled
+ * \return false : DLMA is disabled
+ *****************************************************************************
+ */
+bool rfalDlmaIsEnabled( void );
+
+
+/*!
+ *****************************************************************************
+ * \brief Get DLMA information
+ *
+ * Get the DLMA information|status
+ *
+ * \param[out] info : DLMA information
+ *
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_NONE : No Error
+ *****************************************************************************
+ */
+ReturnCode rfalDlmaGetInfo( rfalDlmaInfo* info );
+
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* RFAL_DLMA_H */
+
+/**
+ * @}
+ *
+ * @}
+ *
+ * @}
+ */
### core/embed/io/nfc/st25/rfal002/include/rfal_dpo.h
@@ -1,258 +1,271 @@
-
-/******************************************************************************
- * @attention
- *
- * COPYRIGHT 2016 STMicroelectronics, all rights reserved
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
- * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
-******************************************************************************/
-
-
-/*
- * PROJECT: ST25R firmware
- * $Revision: $
- * LANGUAGE: ISO C99
- */
-
-/*! \file rfal_dpo.h
- *
- * \author Martin Zechleitner
- *
- * \brief Dynamic Power Output
- *
- * This module provides an interface to perform the power adjustment dynamically
- *
- *
- * \addtogroup RFAL
- * @{
- *
- * \addtogroup RFAL-HAL
- * \brief RFAL Hardware Abstraction Layer
- * @{
- *
- * \addtogroup DPO
- * \brief RFAL Dynamic Power Module
- * @{
- *
- */
-
-
-#ifndef RFAL_DPO_H
-#define RFAL_DPO_H
-
-/*
- ******************************************************************************
- * INCLUDES
- ******************************************************************************
- */
-#include "rfal_platform.h"
-#include "rfal_utils.h"
-
-/*
- ******************************************************************************
- * GLOBAL DEFINES
- ******************************************************************************
- */
-
-#define RFAL_DPO_TABLE_MAX_ENTRIES 4U /*!< Max DPO table entries */
-#define RFAL_DPO_TABLE_PARAM_LEN sizeof(rfalDpoEntry) /*!< DPO Parameter length */
-#define RFAL_DPO_TABLE_SIZE_MAX (RFAL_DPO_TABLE_MAX_ENTRIES * RFAL_DPO_TABLE_PARAM_LEN) /*!< Max DPO table size */
-
-/*
-******************************************************************************
-* GLOBAL TYPES
-******************************************************************************
-*/
-
-/*! Function pointer to the reference Measurement method */
-typedef ReturnCode (*rfalDpoMeasureFunc)(uint8_t* res);
-
-/*! Function pointer to the Adjustment method */
-typedef ReturnCode (*rfalDpoAdjustFunc)(uint8_t res);
-
-
-/*! DPO table entry struct */
-typedef struct
-{
- uint8_t rfoRes; /*!< Setting for the resistance level of the RFO */
- uint8_t inc; /*!< Threshold for incrementing the output power */
- uint8_t dec; /*!< Threshold for decrementing the output power */
-}rfalDpoEntry;
-
-
-/*! DPO information struct */
-typedef struct
-{
- bool enabled; /*!< Enabled state */
- uint8_t tableEntries; /*!< Number of entries used */
- uint8_t tableEntry; /*!< Current entry used */
- uint8_t refMeasurement; /*!< Last measurement used to adjust */
- rfalDpoAdjustFunc adjustCallback; /*!< Pointer to the adjust callback */
- rfalDpoMeasureFunc measureCallback; /*!< Pointer to the measure callback */
-} rfalDpoInfo;
-
-
-/*
-******************************************************************************
-* GLOBAL FUNCTION PROTOTYPES
-******************************************************************************
-*/
-
-
-/*!
- *****************************************************************************
- * \brief Initialize dynamic power table
- *
- * This function sets the internal dynamic power table to the default
- * values stored in rfal_DpoTbl.h
- *
- *****************************************************************************
- */
-void rfalDpoInitialize( void );
-
-
-/*!
- *****************************************************************************
- * \brief Set the Measurement method
- *
- * This function sets the measurement method used for reference measurement.
- * Based on the measurement the power will then be adjusted
- *
- * \param[in] pFunc: callback of measurement function
- *
- *****************************************************************************
- */
-void rfalDpoSetMeasureCallback( rfalDpoMeasureFunc pFunc );
-
-
-/*!
- *****************************************************************************
- * \brief Set the Adjust method
- *
- * This function sets the Adjust method used during DPO adjust
- *
- * \param[in] pFunc: callback of adjust function
- *
- *****************************************************************************
- */
-void rfalDpoSetAdjustCallback( rfalDpoAdjustFunc pFunc );
-
-
-/*!
- *****************************************************************************
- * \brief Write dynamic power table
- *
- * Load the dynamic power table
- *
- * \param[in] powerTbl : location of power Table to be loaded
- * \param[in] powerTblEntries : number of entries of the power Table to be loaded
- *
- * \return RFAL_ERR_NONE : No error
- * \return RFAL_ERR_PARAM : if configTbl is invalid
- * \return RFAL_ERR_NOMEM : if the given Table is bigger exceeds the max size
- *****************************************************************************
- */
-ReturnCode rfalDpoTableWrite( const rfalDpoEntry* powerTbl, uint8_t powerTblEntries );
-
-/*!
- *****************************************************************************
- * \brief Dynamic power table Read
- *
- * Read the dynamic power table
- *
- * \param[out] tblBuf : location to the rfalDpoEntry[] to place the Table
- * \param[in] tblBufEntries : number of entries available in tblBuf to place the power Table
- * \param[out] tableEntries : returned number of entries actually written into tblBuf
- *
- * \return RFAL_ERR_NONE : No error
- * \return RFAL_ERR_PARAM : if configTbl is invalid or parameters are invalid
- *****************************************************************************
- */
-ReturnCode rfalDpoTableRead( rfalDpoEntry* tblBuf, uint8_t tblBufEntries, uint8_t* tableEntries );
-
-
-/*!
- *****************************************************************************
- * \brief Dynamic power adjust
- *
- * It measures the current output and adjusts the power accordingly to
- * the dynamic power table.
- * This method | The adjustment shall be performed when the device
- * is already emiting RF field
- *
- * \return RFAL_ERR_NONE : No error
- * \return RFAL_ERR_PARAM : if configTbl is invalid or parameters are invalid
- * \return RFAL_ERR_WRONG_STATE : if the current state is valid for DPO Adjustment
- *****************************************************************************
- */
-ReturnCode rfalDpoAdjust( void );
-
-
-/*!
- *****************************************************************************
- * \brief Dynamic power set enabled state
- *
- * \param[in] enable : new active state
- *
- * Set state to enable or disable the Dynamic power adjustment
- *
- *****************************************************************************
- */
-void rfalDpoSetEnabled( bool enable );
-
-
-/*!
- *****************************************************************************
- * \brief Get the Dynamic power enabled state
- *
- * Get state of the Dynamic power adjustment
- *
- * \return true : DPO is enabled
- * \return false : DPO is disabled
- *****************************************************************************
- */
-bool rfalDpoIsEnabled( void );
-
-
-/*!
- *****************************************************************************
- * \brief Request DPO adjust
- *
- * Flags the DPO module to perform the adjustment on the next round, even
- * if no change has been perceived from previous measurement|state
-
- *****************************************************************************
- */
-void rfalDpoReqAdj( void );
-
-
-/*!
- *****************************************************************************
- * \brief Get DPO information
- *
- * Get the DPO information|status
- *
- * \param[out] info : pointer where DPO info is to be stored
- *
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_NONE : No Error
- *****************************************************************************
- */
-ReturnCode rfalDpoGetInfo( rfalDpoInfo* info );
-
-#endif /* RFAL_DPO_H */
-
-/**
- * @}
- *
- * @}
- *
- * @}
- */
+
+/******************************************************************************
+ * @attention
+ *
+ * COPYRIGHT 2016 STMicroelectronics, all rights reserved
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
+ * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+******************************************************************************/
+
+
+/*
+ * PROJECT: ST25R firmware
+ * $Revision: $
+ * LANGUAGE: ISO C99
+ */
+
+/*! \file rfal_dpo.h
+ *
+ * \author Martin Zechleitner
+ *
+ * \brief Dynamic Power Output
+ *
+ * This module provides an interface to perform the power adjustment dynamically
+ *
+ *
+ * \addtogroup RFAL
+ * @{
+ *
+ * \addtogroup RFAL-HAL
+ * \brief RFAL Hardware Abstraction Layer
+ * @{
+ *
+ * \addtogroup DPO
+ * \brief RFAL Dynamic Power Module
+ * @{
+ *
+ */
+
+
+#ifndef RFAL_DPO_H
+#define RFAL_DPO_H
+
+/*
+ ******************************************************************************
+ * INCLUDES
+ ******************************************************************************
+ */
+#include "rfal_platform.h"
+#include "rfal_utils.h"
+
+/*
+ ******************************************************************************
+ * C LINKAGE GUARD
+ ******************************************************************************
+ */
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/*
+ ******************************************************************************
+ * GLOBAL DEFINES
+ ******************************************************************************
+ */
+
+#define RFAL_DPO_TABLE_MAX_ENTRIES 4U /*!< Max DPO table entries */
+#define RFAL_DPO_TABLE_PARAM_LEN sizeof(rfalDpoEntry) /*!< DPO Parameter length */
+#define RFAL_DPO_TABLE_SIZE_MAX (RFAL_DPO_TABLE_MAX_ENTRIES * RFAL_DPO_TABLE_PARAM_LEN) /*!< Max DPO table size */
+
+/*
+******************************************************************************
+* GLOBAL TYPES
+******************************************************************************
+*/
+
+/*! Function pointer to the reference Measurement method */
+typedef ReturnCode (*rfalDpoMeasureFunc)(uint8_t* res);
+
+/*! Function pointer to the Adjustment method */
+typedef ReturnCode (*rfalDpoAdjustFunc)(uint8_t res);
+
+
+/*! DPO table entry struct */
+typedef struct
+{
+ uint8_t rfoRes; /*!< Setting for the resistance level of the RFO */
+ uint8_t inc; /*!< Threshold for incrementing the output power */
+ uint8_t dec; /*!< Threshold for decrementing the output power */
+}rfalDpoEntry;
+
+
+/*! DPO information struct */
+typedef struct
+{
+ bool enabled; /*!< Enabled state */
+ uint8_t tableEntries; /*!< Number of entries used */
+ uint8_t tableEntry; /*!< Current entry used */
+ uint8_t refMeasurement; /*!< Last measurement used to adjust */
+ rfalDpoAdjustFunc adjustCallback; /*!< Pointer to the adjust callback */
+ rfalDpoMeasureFunc measureCallback; /*!< Pointer to the measure callback */
+} rfalDpoInfo;
+
+
+/*
+******************************************************************************
+* GLOBAL FUNCTION PROTOTYPES
+******************************************************************************
+*/
+
+
+/*!
+ *****************************************************************************
+ * \brief Initialize dynamic power table
+ *
+ * This function sets the internal dynamic power table to the default
+ * values stored in rfal_DpoTbl.h
+ *
+ *****************************************************************************
+ */
+void rfalDpoInitialize( void );
+
+
+/*!
+ *****************************************************************************
+ * \brief Set the Measurement method
+ *
+ * This function sets the measurement method used for reference measurement.
+ * Based on the measurement the power will then be adjusted
+ *
+ * \param[in] pFunc: callback of measurement function
+ *
+ *****************************************************************************
+ */
+void rfalDpoSetMeasureCallback( rfalDpoMeasureFunc pFunc );
+
+
+/*!
+ *****************************************************************************
+ * \brief Set the Adjust method
+ *
+ * This function sets the Adjust method used during DPO adjust
+ *
+ * \param[in] pFunc: callback of adjust function
+ *
+ *****************************************************************************
+ */
+void rfalDpoSetAdjustCallback( rfalDpoAdjustFunc pFunc );
+
+
+/*!
+ *****************************************************************************
+ * \brief Write dynamic power table
+ *
+ * Load the dynamic power table
+ *
+ * \param[in] powerTbl : location of power Table to be loaded
+ * \param[in] powerTblEntries : number of entries of the power Table to be loaded
+ *
+ * \return RFAL_ERR_NONE : No error
+ * \return RFAL_ERR_PARAM : if configTbl is invalid
+ * \return RFAL_ERR_NOMEM : if the given Table is bigger exceeds the max size
+ *****************************************************************************
+ */
+ReturnCode rfalDpoTableWrite( const rfalDpoEntry* powerTbl, uint8_t powerTblEntries );
+
+/*!
+ *****************************************************************************
+ * \brief Dynamic power table Read
+ *
+ * Read the dynamic power table
+ *
+ * \param[out] tblBuf : location to the rfalDpoEntry[] to place the Table
+ * \param[in] tblBufEntries : number of entries available in tblBuf to place the power Table
+ * \param[out] tableEntries : returned number of entries actually written into tblBuf
+ *
+ * \return RFAL_ERR_NONE : No error
+ * \return RFAL_ERR_PARAM : if configTbl is invalid or parameters are invalid
+ *****************************************************************************
+ */
+ReturnCode rfalDpoTableRead( rfalDpoEntry* tblBuf, uint8_t tblBufEntries, uint8_t* tableEntries );
+
+
+/*!
+ *****************************************************************************
+ * \brief Dynamic power adjust
+ *
+ * It measures the current output and adjusts the power accordingly to
+ * the dynamic power table.
+ * This method | The adjustment shall be performed when the device
+ * is already emiting RF field
+ *
+ * \return RFAL_ERR_NONE : No error
+ * \return RFAL_ERR_PARAM : if configTbl is invalid or parameters are invalid
+ * \return RFAL_ERR_WRONG_STATE : if the current state is valid for DPO Adjustment
+ *****************************************************************************
+ */
+ReturnCode rfalDpoAdjust( void );
+
+
+/*!
+ *****************************************************************************
+ * \brief Dynamic power set enabled state
+ *
+ * \param[in] enable : new active state
+ *
+ * Set state to enable or disable the Dynamic power adjustment
+ *
+ *****************************************************************************
+ */
+void rfalDpoSetEnabled( bool enable );
+
+
+/*!
+ *****************************************************************************
+ * \brief Get the Dynamic power enabled state
+ *
+ * Get state of the Dynamic power adjustment
+ *
+ * \return true : DPO is enabled
+ * \return false : DPO is disabled
+ *****************************************************************************
+ */
+bool rfalDpoIsEnabled( void );
+
+
+/*!
+ *****************************************************************************
+ * \brief Request DPO adjust
+ *
+ * Flags the DPO module to perform the adjustment on the next round, even
+ * if no change has been perceived from previous measurement|state
+
+ *****************************************************************************
+ */
+void rfalDpoReqAdj( void );
+
+
+/*!
+ *****************************************************************************
+ * \brief Get DPO information
+ *
+ * Get the DPO information|status
+ *
+ * \param[out] info : pointer where DPO info is to be stored
+ *
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_NONE : No Error
+ *****************************************************************************
+ */
+ReturnCode rfalDpoGetInfo( rfalDpoInfo* info );
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* RFAL_DPO_H */
+
+/**
+ * @}
+ *
+ * @}
+ *
+ * @}
+ */
### core/embed/io/nfc/st25/rfal002/include/rfal_isoDep.h
[binary or diff unavailable]
### core/embed/io/nfc/st25/rfal002/include/rfal_nfc.h
@@ -1,482 +1,495 @@
-
-/******************************************************************************
- * @attention
- *
- * COPYRIGHT 2016 STMicroelectronics, all rights reserved
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
- * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
-******************************************************************************/
-
-
-
-/*
- * PROJECT: ST25R firmware
- * Revision:
- * LANGUAGE: ISO C99
- */
-
-/*! \file rfal_nfc.h
- *
- * \brief RFAL NFC device
- *
- * This module provides the required features to behave as an NFC Poller
- * or Listener device. It grants an easy to use interface for the following
- * activities: Technology Detection, Collision Resolution, Activation,
- * Data Exchange, and Deactivation
- *
- * This layer is influenced by (but not fully aligned with) the NFC Forum
- * specifications, in particular: Activity 2.0 and NCI 2.0
- *
- *
- *
- * \addtogroup RFAL
- * @{
- *
- * \addtogroup RFAL-HL
- * \brief RFAL Higher Layer
- * @{
- *
- * \addtogroup NFC
- * \brief RFAL NFC Device
- * @{
- *
- */
-
-#ifndef RFAL_NFC_H
-#define RFAL_NFC_H
-
-/*
-******************************************************************************
-* INCLUDES
-******************************************************************************
-*/
-#include "rfal_platform.h"
-#include "rfal_utils.h"
-#include "rfal_rf.h"
-#include "rfal_nfca.h"
-#include "rfal_nfcb.h"
-#include "rfal_nfcf.h"
-#include "rfal_nfcv.h"
-#include "rfal_st25tb.h"
-#include "rfal_nfcDep.h"
-#include "rfal_isoDep.h"
-
-
-/*
-******************************************************************************
-* GLOBAL DEFINES
-******************************************************************************
-*/
-
-#define RFAL_NFC_TECH_NONE 0x0000U /*!< No technology */
-#define RFAL_NFC_POLL_TECH_A 0x0001U /*!< Poll NFC-A technology Flag */
-#define RFAL_NFC_POLL_TECH_B 0x0002U /*!< Poll NFC-B technology Flag */
-#define RFAL_NFC_POLL_TECH_F 0x0004U /*!< Poll NFC-F technology Flag */
-#define RFAL_NFC_POLL_TECH_V 0x0008U /*!< Poll NFC-V technology Flag */
-#define RFAL_NFC_POLL_TECH_AP2P 0x0010U /*!< Poll AP2P technology Flag */
-#define RFAL_NFC_POLL_TECH_ST25TB 0x0020U /*!< Poll ST25TB technology Flag */
-#define RFAL_NFC_POLL_TECH_PROP 0x0040U /*!< Poll Proprietary technology Flag */
-#define RFAL_NFC_LISTEN_TECH_A 0x1000U /*!< Listen NFC-A technology Flag */
-#define RFAL_NFC_LISTEN_TECH_B 0x2000U /*!< Listen NFC-B technology Flag */
-#define RFAL_NFC_LISTEN_TECH_F 0x4000U /*!< Listen NFC-F technology Flag */
-#define RFAL_NFC_LISTEN_TECH_AP2P 0x8000U /*!< Listen AP2P technology Flag */
-
-
-/*
-******************************************************************************
-* GLOBAL MACROS
-******************************************************************************
-*/
-
-/*! Checks if a device is currently activated */
-#define rfalNfcIsDevActivated( st ) ( ((st)>= RFAL_NFC_STATE_ACTIVATED) && ((st)<RFAL_NFC_STATE_DEACTIVATION) )
-
-/*! Checks if a device is in discovery */
-#define rfalNfcIsInDiscovery( st ) ( ((st)>= RFAL_NFC_STATE_START_DISCOVERY) && ((st)<RFAL_NFC_STATE_ACTIVATED) )
-
-/*! Checks if remote device is in Poll mode */
-#define rfalNfcIsRemDevPoller( tp ) ( ((tp)>= RFAL_NFC_POLL_TYPE_NFCA) && ((tp)<=RFAL_NFC_POLL_TYPE_AP2P ) )
-
-/*! Checks if remote device is in Listen mode */
-#define rfalNfcIsRemDevListener( tp ) ( ((int16_t)(tp)>= (int16_t)RFAL_NFC_LISTEN_TYPE_NFCA) && ((tp)<=RFAL_NFC_LISTEN_TYPE_AP2P) )
-
-/*! Sets the discover parameters to its default values */
-#define rfalNfcDefaultDiscParams( dp ) if( (dp) != NULL) { \
- RFAL_MEMSET( (dp), 0x00, sizeof(rfalNfcDiscoverParam) ); \
- ((dp))->compMode = RFAL_COMPLIANCE_MODE_NFC; \
- ((dp))->devLimit = 1U; \
- ((dp))->nfcfBR = RFAL_BR_212; \
- ((dp))->ap2pBR = RFAL_BR_424; \
- ((dp))->maxBR = RFAL_BR_KEEP; \
- ((dp))->isoDepFS = RFAL_ISODEP_FSXI_256; \
- ((dp))->nfcDepLR = RFAL_NFCDEP_LR_254; \
- ((dp))->GBLen = 0U; \
- ((dp))->p2pNfcaPrio = false; \
- ((dp))->wakeupEnabled = false; \
- ((dp))->wakeupConfigDefault = true; \
- ((dp))->wakeupPollBefore = false; \
- ((dp))->wakeupNPolls = 1U; \
- ((dp))->totalDuration = 1000U; \
- ((dp))->techs2Find = RFAL_NFC_TECH_NONE; \
- ((dp))->techs2Bail = RFAL_NFC_TECH_NONE; \
- }
-
-/*
-******************************************************************************
-* GLOBAL ENUMS
-******************************************************************************
-*/
-
-/*
-******************************************************************************
-* GLOBAL TYPES
-******************************************************************************
-*/
-
-/*! Main state */
-typedef enum{
- RFAL_NFC_STATE_NOTINIT = 0, /*!< Not Initialized state */
- RFAL_NFC_STATE_IDLE = 1, /*!< Initialize state */
- RFAL_NFC_STATE_START_DISCOVERY = 2, /*!< Start Discovery loop state */
- RFAL_NFC_STATE_WAKEUP_MODE = 3, /*!< Wake-Up state */
- RFAL_NFC_STATE_POLL_TECHDETECT = 10, /*!< Technology Detection state */
- RFAL_NFC_STATE_POLL_COLAVOIDANCE = 11, /*!< Collision Avoidance state */
- RFAL_NFC_STATE_POLL_SELECT = 12, /*!< Wait for Selection state */
- RFAL_NFC_STATE_POLL_ACTIVATION = 13, /*!< Activation state */
- RFAL_NFC_STATE_LISTEN_TECHDETECT = 20, /*!< Listen Tech Detect */
- RFAL_NFC_STATE_LISTEN_COLAVOIDANCE = 21, /*!< Listen Collision Avoidance */
- RFAL_NFC_STATE_LISTEN_ACTIVATION = 22, /*!< Listen Activation state */
- RFAL_NFC_STATE_LISTEN_SLEEP = 23, /*!< Listen Sleep state */
- RFAL_NFC_STATE_ACTIVATED = 30, /*!< Activated state */
- RFAL_NFC_STATE_DATAEXCHANGE = 31, /*!< Data Exchange Start state */
- RFAL_NFC_STATE_DATAEXCHANGE_DONE = 33, /*!< Data Exchange terminated */
- RFAL_NFC_STATE_DEACTIVATION = 34 /*!< Deactivation state */
-}rfalNfcState;
-
-
-/*! Device type */
-typedef enum{
- RFAL_NFC_LISTEN_TYPE_NFCA = 0, /*!< NFC-A Listener device type */
- RFAL_NFC_LISTEN_TYPE_NFCB = 1, /*!< NFC-B Listener device type */
- RFAL_NFC_LISTEN_TYPE_NFCF = 2, /*!< NFC-F Listener device type */
- RFAL_NFC_LISTEN_TYPE_NFCV = 3, /*!< NFC-V Listener device type */
- RFAL_NFC_LISTEN_TYPE_ST25TB = 4, /*!< ST25TB Listener device type */
- RFAL_NFC_LISTEN_TYPE_AP2P = 5, /*!< AP2P Listener device type */
- RFAL_NFC_LISTEN_TYPE_PROP = 6, /*!< Proprietary Listen dev type */
- RFAL_NFC_POLL_TYPE_NFCA = 10, /*!< NFC-A Poller device type */
- RFAL_NFC_POLL_TYPE_NFCB = 11, /*!< NFC-B Poller device type */
- RFAL_NFC_POLL_TYPE_NFCF = 12, /*!< NFC-F Poller device type */
- RFAL_NFC_POLL_TYPE_NFCV = 13, /*!< NFC-V Poller device type */
- RFAL_NFC_POLL_TYPE_AP2P = 15 /*!< AP2P Poller device type */
-}rfalNfcDevType;
-
-
-/*! Device interface */
-typedef enum{
- RFAL_NFC_INTERFACE_RF = 0, /*!< RF Frame interface */
- RFAL_NFC_INTERFACE_ISODEP = 1, /*!< ISO-DEP interface */
- RFAL_NFC_INTERFACE_NFCDEP = 2 /*!< NFC-DEP interface */
-}rfalNfcRfInterface;
-
-
-/*! Deactivation type */
-typedef enum{
- RFAL_NFC_DEACTIVATE_IDLE = 0, /*!< Deactivate and go to IDLE */
- RFAL_NFC_DEACTIVATE_SLEEP = 1, /*!< Deactivate and go to SELECT */
- RFAL_NFC_DEACTIVATE_DISCOVERY = 2 /*!< Deactivate and restart DISCOVERY */
-}rfalNfcDeactivateType;
-
-
-/*! Device struct containing all its details */
-typedef struct{
- rfalNfcDevType type; /*!< Device's type */
- union{ /* PRQA S 0750 # MISRA 19.2 - Members of the union will not be used concurrently, only one technology at a time */
- rfalNfcaListenDevice nfca; /*!< NFC-A Listen Device instance */
- rfalNfcbListenDevice nfcb; /*!< NFC-B Listen Device instance */
- rfalNfcfListenDevice nfcf; /*!< NFC-F Listen Device instance */
- rfalNfcvListenDevice nfcv; /*!< NFC-V Listen Device instance */
- rfalSt25tbListenDevice st25tb; /*!< ST25TB Listen Device instance*/
- }dev; /*!< Device's instance */
-
- uint8_t *nfcid; /*!< Device's NFCID */
- uint8_t nfcidLen; /*!< Device's NFCID length */
- rfalNfcRfInterface rfInterface; /*!< Device's interface */
-
- union{ /* PRQA S 0750 # MISRA 19.2 - Members of the union will not be used concurrently, only one protocol at a time */
- rfalIsoDepDevice isoDep; /*!< ISO-DEP instance */
- rfalNfcDepDevice nfcDep; /*!< NFC-DEP instance */
- }proto; /*!< Device's protocol */
-}rfalNfcDevice;
-
-
-/*! Callbacks for Proprietary|Other Technology Activity 2.1 & EMVCo 3.0 9.2 */
-typedef ReturnCode (* rfalNfcPropCallback)(void);
-
-
-/*! Struct that holds the Proprietary NFC callbacks */
-typedef struct{
- rfalNfcPropCallback rfalNfcpPollerInitialize; /*!< Prorietary NFC Initialization callback */
- rfalNfcPropCallback rfalNfcpPollerTechnologyDetection; /*!< Prorietary NFC Technoly Detection callback */
- rfalNfcPropCallback rfalNfcpPollerStartCollisionResolution; /*!< Prorietary NFC Start Collision Resolution callback */
- rfalNfcPropCallback rfalNfcpPollerGetCollisionResolutionStatus; /*!< Prorietary NFC Get Collision Resolution status callback */
- rfalNfcPropCallback rfalNfcpStartActivation; /*!< Prorietary NFC Start Activation callback */
- rfalNfcPropCallback rfalNfcpGetActivationStatus; /*!< Prorietary NFC Get Activation status callback */
-} rfalNfcPropCallbacks;
-
-
-/*! Discovery parameters */
-typedef struct{
- rfalComplianceMode compMode; /*!< Compliancy mode to be used */
- uint16_t techs2Find; /*!< Technologies to search for */
- uint16_t techs2Bail; /*!< Bail-out after certain NFC technologies */
- uint16_t totalDuration; /*!< Duration of a whole Poll + Listen cycle NCI 2.1 Table 46 */
- uint8_t devLimit; /*!< Max number of devices Activity 2.1 Table 11 */
- rfalBitRate maxBR; /*!< Max Bit rate to be used NCI 2.1 Table 28 */
-
- rfalBitRate nfcfBR; /*!< Bit rate to poll for NFC-F NCI 2.1 Table 27 */
- uint8_t nfcid3[RFAL_NFCDEP_NFCID3_LEN]; /*!< NFCID3 to be used on the ATR_REQ/ATR_RES */
- uint8_t GB[RFAL_NFCDEP_GB_MAX_LEN]; /*!< General bytes to be used on the ATR-REQ NCI 2.1 Table 29 */
- uint8_t GBLen; /*!< Length of the General Bytes NCI 2.1 Table 29 */
- rfalBitRate ap2pBR; /*!< Bit rate to poll for AP2P NCI 2.1 Table 31 */
- bool p2pNfcaPrio; /*!< NFC-A P2P (true) or ISO14443-4/T4T (false) priority */
- rfalNfcPropCallbacks propNfc; /*!< Proprietary Technlogy callbacks */
-
-
- rfalIsoDepFSxI isoDepFS; /*!< ISO-DEP Poller announced maximum frame size Digital 2.2 Table 60 */
- uint8_t nfcDepLR; /*!< NFC-DEP Poller & Listener maximum frame size Digital 2.2 Table 90 */
-
- rfalLmConfPA lmConfigPA; /*!< Configuration for Passive Listen mode NFC-A */
- rfalLmConfPF lmConfigPF; /*!< Configuration for Passive Listen mode NFC-A */
-
- void (*notifyCb)( rfalNfcState st ); /*!< Callback to Notify upper layer */
-
- bool wakeupEnabled; /*!< Enable Wake-Up mode before polling */
- bool wakeupConfigDefault; /*!< Wake-Up mode default configuration */
- rfalWakeUpConfig wakeupConfig; /*!< Wake-Up mode configuration */
- bool wakeupPollBefore; /*!< Flag to Poll wakeupNPolls times before entering Wake-up */
- uint16_t wakeupNPolls; /*!< Number of polling cycles before|after entering Wake-up */
-}rfalNfcDiscoverParam;
-
-
-/*! Buffer union, only one interface is used at a time */
-typedef union{ /* PRQA S 0750 # MISRA 19.2 - Members of the union will not be used concurrently, only one interface at a time */
- uint8_t rfBuf[RFAL_FEATURE_NFC_RF_BUF_LEN]; /*!< RF buffer */
- rfalIsoDepApduBufFormat isoDepBuf; /*!< ISO-DEP buffer format (with header/prologue) */
- rfalNfcDepPduBufFormat nfcDepBuf; /*!< NFC-DEP buffer format (with header/prologue) */
-}rfalNfcBuffer;
-
-/*******************************************************************************/
-
-/*
-******************************************************************************
-* GLOBAL FUNCTION PROTOTYPES
-******************************************************************************
-*/
-
-/*!
- *****************************************************************************
- * \brief RFAL NFC Worker
- *
- * It runs the internal state machine and runs the RFAL RF worker.
- *****************************************************************************
- */
-void rfalNfcWorker( void );
-
-
-/*!
- *****************************************************************************
- * \brief RFAL NFC Initialize
- *
- * It initializes this module and its dependencies
- *
- * \return RFAL_ERR_WRONG_STATE : Incorrect state for this operation
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalNfcInitialize( void );
-
-
-/*!
- *****************************************************************************
- * \brief RFAL NFC Discovery
- *
- * It set the device in Discovery state.
- * In discovery it will Poll and/or Listen for the technologies configured,
- * and perform Wake-up mode if configured to do so.
- *
- * The device list passed on disParams must not be empty.
- * The number of devices on the list is indicated by the devLimit and shall
- * be at >= 1.
- *
- * \param[in] disParams : discovery configuration parameters
- *
- * \return RFAL_ERR_WRONG_STATE : Incorrect state for this operation
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalNfcDiscover( const rfalNfcDiscoverParam *disParams );
-
-
-/*!
- *****************************************************************************
- * \brief RFAL NFC Get State
- *
- * It returns the current state
- *
- * \return rfalNfcState : the current state
- *****************************************************************************
- */
-rfalNfcState rfalNfcGetState( void );
-
-
-/*!
- *****************************************************************************
- * \brief RFAL NFC Get Devices Found
- *
- * It returns the location of the device list and the number of
- * devices found.
- *
- * \param[out] devList : device list location
- * \param[out] devCnt : number of devices found
- *
- * \return RFAL_ERR_WRONG_STATE : Incorrect state for this operation
- * Discovery still ongoing
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalNfcGetDevicesFound( rfalNfcDevice **devList, uint8_t *devCnt );
-
-
-/*!
- *****************************************************************************
- * \brief RFAL NFC Get Active Device
- *
- * It returns the location of the device current Active device
- *
- * \param[out] dev : device info location
- *
- * \return RFAL_ERR_WRONG_STATE : Incorrect state for this operation
- * No device activated
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalNfcGetActiveDevice( rfalNfcDevice **dev );
-
-
-/*!
- *****************************************************************************
- * \brief RFAL NFC Select Device
- *
- * It selects the device to be activated.
- * It shall be called when more than one device has been identified to
- * indicate which device shall be actived
- *
- * \param[in] devIdx : device index to be activated
- *
- * \return RFAL_ERR_WRONG_STATE : Incorrect state for this operation
- * Not in select state
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalNfcSelect( uint8_t devIdx );
-
-
-/*!
- *****************************************************************************
- * \brief RFAL NFC Start Data Exchange
- *
- * After a device has been activated, it starts a data exchange.
- * It handles automatically which interface/protocol to be used and acts accordingly.
- *
- * In Listen mode the first frame/data shall be sent by the Reader/Initiator
- * therefore this method must be called first with txDataLen set to zero
- * to retrieve the rxData and rcvLen locations.
- *
- *
- * \param[in] txData : data to be transmitted
- * \param[in] txDataLen : size of the data to be transmitted (in bits or bytes - see below)
- * \param[out] rxData : location of the received data after operation is completed
- * \param[out] rvdLen : location of the length of the received data (in bits or bytes - see below)
- * \param[in] fwt : FWT to be used in case of RF interface.
- * If ISO-DEP or NFC-DEP interface is used, this will be ignored
- *
- * \warning In order to support a wider range of protocols, when RF interface is used the lengths
- * are in number of bits (not bytes). Therefore both input txDataLen and output rvdLen refer to
- * bits. If ISO-DEP or NFC-DEP interface is used those are expressed in number of bytes.
- *
- *
- * \return RFAL_ERR_WRONG_STATE : Incorrect state for this operation
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalNfcDataExchangeStart( uint8_t *txData, uint16_t txDataLen, uint8_t **rxData, uint16_t **rvdLen, uint32_t fwt );
-
-
-/*!
- *****************************************************************************
- * \brief RFAL NFC Get Data Exchange Status
- *
- * Gets current Data Exchange status
- *
- * \return RFAL_ERR_NONE : Transceive done with no error
- * \return RFAL_ERR_BUSY : Transceive ongoing
- * \return RFAL_ERR_AGAIN : received one chaining block, copy received data
- * and continue to call this method to retrieve the
- * remaining blocks
- * \return RFAL_ERR_XXXX : Error occurred
- * \return RFAL_ERR_TIMEOUT : No response
- * \return RFAL_ERR_FRAMING : Framing error detected
- * \return RFAL_ERR_PAR : Parity error detected
- * \return RFAL_ERR_CRC : CRC error detected
- * \return RFAL_ERR_LINK_LOSS : Link Loss - External Field is Off
- * \return RFAL_ERR_RF_COLLISION : Collision detected
- * \return RFAL_ERR_IO : Internal error
- *****************************************************************************
- */
-ReturnCode rfalNfcDataExchangeGetStatus( void );
-
-
-/*!
- *****************************************************************************
- * \brief RFAL NFC Deactivate
- *
- * It triggers the deactivation procedure to terminate communications with
- * remote device.
- * In case the deactivation type is RFAL_NFC_DEACTIVATE_SLEEP the field is
- * kept On and device selection shall follow. Otherwise the field will
- * be turned Off.
- *
- * \warning In case the deactivation type is RFAL_NFC_DEACTIVATE_IDLE the
- * deactivation procedure is executed immediately and in a blocking manner
- *
- * \param[in] deactType : Type of deactivation to be performed
- *
- * \return RFAL_ERR_WRONG_STATE : Incorrect state for this operation
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalNfcDeactivate( rfalNfcDeactivateType deactType );
-
-#endif /* RFAL_NFC_H */
-
-
-/**
- * @}
- *
- * @}
- *
- * @}
- */
+
+/******************************************************************************
+ * @attention
+ *
+ * COPYRIGHT 2016 STMicroelectronics, all rights reserved
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
+ * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+******************************************************************************/
+
+
+
+/*
+ * PROJECT: ST25R firmware
+ * Revision:
+ * LANGUAGE: ISO C99
+ */
+
+/*! \file rfal_nfc.h
+ *
+ * \brief RFAL NFC device
+ *
+ * This module provides the required features to behave as an NFC Poller
+ * or Listener device. It grants an easy to use interface for the following
+ * activities: Technology Detection, Collision Resolution, Activation,
+ * Data Exchange, and Deactivation
+ *
+ * This layer is influenced by (but not fully aligned with) the NFC Forum
+ * specifications, in particular: Activity 2.0 and NCI 2.0
+ *
+ *
+ *
+ * \addtogroup RFAL
+ * @{
+ *
+ * \addtogroup RFAL-HL
+ * \brief RFAL Higher Layer
+ * @{
+ *
+ * \addtogroup NFC
+ * \brief RFAL NFC Device
+ * @{
+ *
+ */
+
+#ifndef RFAL_NFC_H
+#define RFAL_NFC_H
+
+/*
+******************************************************************************
+* INCLUDES
+******************************************************************************
+*/
+#include "rfal_platform.h"
+#include "rfal_utils.h"
+#include "rfal_rf.h"
+#include "rfal_nfca.h"
+#include "rfal_nfcb.h"
+#include "rfal_nfcf.h"
+#include "rfal_nfcv.h"
+#include "rfal_st25tb.h"
+#include "rfal_nfcDep.h"
+#include "rfal_isoDep.h"
+
+/*
+ ******************************************************************************
+ * C LINKAGE GUARD
+ ******************************************************************************
+ */
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+
+/*
+******************************************************************************
+* GLOBAL DEFINES
+******************************************************************************
+*/
+
+#define RFAL_NFC_TECH_NONE 0x0000U /*!< No technology */
+#define RFAL_NFC_POLL_TECH_A 0x0001U /*!< Poll NFC-A technology Flag */
+#define RFAL_NFC_POLL_TECH_B 0x0002U /*!< Poll NFC-B technology Flag */
+#define RFAL_NFC_POLL_TECH_F 0x0004U /*!< Poll NFC-F technology Flag */
+#define RFAL_NFC_POLL_TECH_V 0x0008U /*!< Poll NFC-V technology Flag */
+#define RFAL_NFC_POLL_TECH_AP2P 0x0010U /*!< Poll AP2P technology Flag */
+#define RFAL_NFC_POLL_TECH_ST25TB 0x0020U /*!< Poll ST25TB technology Flag */
+#define RFAL_NFC_POLL_TECH_PROP 0x0040U /*!< Poll Proprietary technology Flag */
+#define RFAL_NFC_LISTEN_TECH_A 0x1000U /*!< Listen NFC-A technology Flag */
+#define RFAL_NFC_LISTEN_TECH_B 0x2000U /*!< Listen NFC-B technology Flag */
+#define RFAL_NFC_LISTEN_TECH_F 0x4000U /*!< Listen NFC-F technology Flag */
+#define RFAL_NFC_LISTEN_TECH_AP2P 0x8000U /*!< Listen AP2P technology Flag */
+
+
+/*
+******************************************************************************
+* GLOBAL MACROS
+******************************************************************************
+*/
+
+/*! Checks if a device is currently activated */
+#define rfalNfcIsDevActivated( st ) ( ((st)>= RFAL_NFC_STATE_ACTIVATED) && ((st)<RFAL_NFC_STATE_DEACTIVATION) )
+
+/*! Checks if a device is in discovery */
+#define rfalNfcIsInDiscovery( st ) ( ((st)>= RFAL_NFC_STATE_START_DISCOVERY) && ((st)<RFAL_NFC_STATE_ACTIVATED) )
+
+/*! Checks if remote device is in Poll mode */
+#define rfalNfcIsRemDevPoller( tp ) ( ((tp)>= RFAL_NFC_POLL_TYPE_NFCA) && ((tp)<=RFAL_NFC_POLL_TYPE_AP2P ) )
+
+/*! Checks if remote device is in Listen mode */
+#define rfalNfcIsRemDevListener( tp ) ( ((int16_t)(tp)>= (int16_t)RFAL_NFC_LISTEN_TYPE_NFCA) && ((tp)<=RFAL_NFC_LISTEN_TYPE_AP2P) )
+
+/*! Sets the discover parameters to its default values */
+#define rfalNfcDefaultDiscParams( dp ) if( (dp) != NULL) { \
+ RFAL_MEMSET( (dp), 0x00, sizeof(rfalNfcDiscoverParam) ); \
+ ((dp))->compMode = RFAL_COMPLIANCE_MODE_NFC; \
+ ((dp))->devLimit = 1U; \
+ ((dp))->nfcfBR = RFAL_BR_212; \
+ ((dp))->ap2pBR = RFAL_BR_424; \
+ ((dp))->maxBR = RFAL_BR_KEEP; \
+ ((dp))->isoDepFS = RFAL_ISODEP_FSXI_256; \
+ ((dp))->nfcDepLR = RFAL_NFCDEP_LR_254; \
+ ((dp))->GBLen = 0U; \
+ ((dp))->p2pNfcaPrio = false; \
+ ((dp))->wakeupEnabled = false; \
+ ((dp))->wakeupConfigDefault = true; \
+ ((dp))->wakeupPollBefore = false; \
+ ((dp))->wakeupNPolls = 1U; \
+ ((dp))->totalDuration = 1000U; \
+ ((dp))->techs2Find = RFAL_NFC_TECH_NONE; \
+ ((dp))->techs2Bail = RFAL_NFC_TECH_NONE; \
+ }
+
+/*
+******************************************************************************
+* GLOBAL ENUMS
+******************************************************************************
+*/
+
+/*
+******************************************************************************
+* GLOBAL TYPES
+******************************************************************************
+*/
+
+/*! Main state */
+typedef enum{
+ RFAL_NFC_STATE_NOTINIT = 0, /*!< Not Initialized state */
+ RFAL_NFC_STATE_IDLE = 1, /*!< Initialize state */
+ RFAL_NFC_STATE_START_DISCOVERY = 2, /*!< Start Discovery loop state */
+ RFAL_NFC_STATE_WAKEUP_MODE = 3, /*!< Wake-Up state */
+ RFAL_NFC_STATE_POLL_TECHDETECT = 10, /*!< Technology Detection state */
+ RFAL_NFC_STATE_POLL_COLAVOIDANCE = 11, /*!< Collision Avoidance state */
+ RFAL_NFC_STATE_POLL_SELECT = 12, /*!< Wait for Selection state */
+ RFAL_NFC_STATE_POLL_ACTIVATION = 13, /*!< Activation state */
+ RFAL_NFC_STATE_LISTEN_TECHDETECT = 20, /*!< Listen Tech Detect */
+ RFAL_NFC_STATE_LISTEN_COLAVOIDANCE = 21, /*!< Listen Collision Avoidance */
+ RFAL_NFC_STATE_LISTEN_ACTIVATION = 22, /*!< Listen Activation state */
+ RFAL_NFC_STATE_LISTEN_SLEEP = 23, /*!< Listen Sleep state */
+ RFAL_NFC_STATE_ACTIVATED = 30, /*!< Activated state */
+ RFAL_NFC_STATE_DATAEXCHANGE = 31, /*!< Data Exchange Start state */
+ RFAL_NFC_STATE_DATAEXCHANGE_DONE = 33, /*!< Data Exchange terminated */
+ RFAL_NFC_STATE_DEACTIVATION = 34 /*!< Deactivation state */
+}rfalNfcState;
+
+
+/*! Device type */
+typedef enum{
+ RFAL_NFC_LISTEN_TYPE_NFCA = 0, /*!< NFC-A Listener device type */
+ RFAL_NFC_LISTEN_TYPE_NFCB = 1, /*!< NFC-B Listener device type */
+ RFAL_NFC_LISTEN_TYPE_NFCF = 2, /*!< NFC-F Listener device type */
+ RFAL_NFC_LISTEN_TYPE_NFCV = 3, /*!< NFC-V Listener device type */
+ RFAL_NFC_LISTEN_TYPE_ST25TB = 4, /*!< ST25TB Listener device type */
+ RFAL_NFC_LISTEN_TYPE_AP2P = 5, /*!< AP2P Listener device type */
+ RFAL_NFC_LISTEN_TYPE_PROP = 6, /*!< Proprietary Listen dev type */
+ RFAL_NFC_POLL_TYPE_NFCA = 10, /*!< NFC-A Poller device type */
+ RFAL_NFC_POLL_TYPE_NFCB = 11, /*!< NFC-B Poller device type */
+ RFAL_NFC_POLL_TYPE_NFCF = 12, /*!< NFC-F Poller device type */
+ RFAL_NFC_POLL_TYPE_NFCV = 13, /*!< NFC-V Poller device type */
+ RFAL_NFC_POLL_TYPE_AP2P = 15 /*!< AP2P Poller device type */
+}rfalNfcDevType;
+
+
+/*! Device interface */
+typedef enum{
+ RFAL_NFC_INTERFACE_RF = 0, /*!< RF Frame interface */
+ RFAL_NFC_INTERFACE_ISODEP = 1, /*!< ISO-DEP interface */
+ RFAL_NFC_INTERFACE_NFCDEP = 2 /*!< NFC-DEP interface */
+}rfalNfcRfInterface;
+
+
+/*! Deactivation type */
+typedef enum{
+ RFAL_NFC_DEACTIVATE_IDLE = 0, /*!< Deactivate and go to IDLE */
+ RFAL_NFC_DEACTIVATE_SLEEP = 1, /*!< Deactivate and go to SELECT */
+ RFAL_NFC_DEACTIVATE_DISCOVERY = 2 /*!< Deactivate and restart DISCOVERY */
+}rfalNfcDeactivateType;
+
+
+/*! Device struct containing all its details */
+typedef struct{
+ rfalNfcDevType type; /*!< Device's type */
+ union{ /* PRQA S 0750 # MISRA 19.2 - Members of the union will not be used concurrently, only one technology at a time */
+ rfalNfcaListenDevice nfca; /*!< NFC-A Listen Device instance */
+ rfalNfcbListenDevice nfcb; /*!< NFC-B Listen Device instance */
+ rfalNfcfListenDevice nfcf; /*!< NFC-F Listen Device instance */
+ rfalNfcvListenDevice nfcv; /*!< NFC-V Listen Device instance */
+ rfalSt25tbListenDevice st25tb; /*!< ST25TB Listen Device instance*/
+ }dev; /*!< Device's instance */
+
+ uint8_t *nfcid; /*!< Device's NFCID */
+ uint8_t nfcidLen; /*!< Device's NFCID length */
+ rfalNfcRfInterface rfInterface; /*!< Device's interface */
+
+ union{ /* PRQA S 0750 # MISRA 19.2 - Members of the union will not be used concurrently, only one protocol at a time */
+ rfalIsoDepDevice isoDep; /*!< ISO-DEP instance */
+ rfalNfcDepDevice nfcDep; /*!< NFC-DEP instance */
+ }proto; /*!< Device's protocol */
+}rfalNfcDevice;
+
+
+/*! Callbacks for Proprietary|Other Technology Activity 2.1 & EMVCo 3.0 9.2 */
+typedef ReturnCode (* rfalNfcPropCallback)(void);
+
+
+/*! Struct that holds the Proprietary NFC callbacks */
+typedef struct{
+ rfalNfcPropCallback rfalNfcpPollerInitialize; /*!< Proprietary NFC Initialization callback */
+ rfalNfcPropCallback rfalNfcpPollerTechnologyDetection; /*!< Proprietary NFC Technology Detection callback */
+ rfalNfcPropCallback rfalNfcpPollerStartCollisionResolution; /*!< Proprietary NFC Start Collision Resolution callback */
+ rfalNfcPropCallback rfalNfcpPollerGetCollisionResolutionStatus; /*!< Proprietary NFC Get Collision Resolution status callback*/
+ rfalNfcPropCallback rfalNfcpStartActivation; /*!< Proprietary NFC Start Activation callback */
+ rfalNfcPropCallback rfalNfcpGetActivationStatus; /*!< Proprietary NFC Get Activation status callback */
+} rfalNfcPropCallbacks;
+
+
+/*! Discovery parameters */
+typedef struct{
+ rfalComplianceMode compMode; /*!< Compliancy mode to be used */
+ uint16_t techs2Find; /*!< Technologies to search for */
+ uint16_t techs2Bail; /*!< Bail-out after certain NFC technologies */
+ uint16_t totalDuration; /*!< Duration of a whole Poll + Listen cycle NCI 2.1 Table 46 */
+ uint8_t devLimit; /*!< Max number of devices Activity 2.1 Table 11 */
+ rfalBitRate maxBR; /*!< Max Bit rate to be used NCI 2.1 Table 28 */
+
+ rfalBitRate nfcfBR; /*!< Bit rate to poll for NFC-F NCI 2.1 Table 27 */
+ uint8_t nfcid3[RFAL_NFCDEP_NFCID3_LEN]; /*!< NFCID3 to be used on the ATR_REQ/ATR_RES */
+ uint8_t GB[RFAL_NFCDEP_GB_MAX_LEN]; /*!< General bytes to be used on the ATR-REQ NCI 2.1 Table 29 */
+ uint8_t GBLen; /*!< Length of the General Bytes NCI 2.1 Table 29 */
+ rfalBitRate ap2pBR; /*!< Bit rate to poll for AP2P NCI 2.1 Table 31 */
+ bool p2pNfcaPrio; /*!< NFC-A P2P (true) or ISO14443-4/T4T (false) priority */
+ rfalNfcPropCallbacks propNfc; /*!< Proprietary Technology callbacks */
+
+
+ rfalIsoDepFSxI isoDepFS; /*!< ISO-DEP Poller announced maximum frame size Digital 2.2 Table 60 */
+ uint8_t nfcDepLR; /*!< NFC-DEP Poller & Listener maximum frame size Digital 2.2 Table 90 */
+
+ rfalLmConfPA lmConfigPA; /*!< Configuration for Passive Listen mode NFC-A */
+ rfalLmConfPF lmConfigPF; /*!< Configuration for Passive Listen mode NFC-A */
+
+ void (*notifyCb)( rfalNfcState st ); /*!< Callback to Notify upper layer */
+
+ bool wakeupEnabled; /*!< Enable Wake-Up mode before polling */
+ bool wakeupConfigDefault; /*!< Wake-Up mode default configuration */
+ rfalWakeUpConfig wakeupConfig; /*!< Wake-Up mode configuration */
+ bool wakeupPollBefore; /*!< Flag to Poll wakeupNPolls times before entering Wake-up */
+ uint16_t wakeupNPolls; /*!< Number of polling cycles before|after entering Wake-up */
+}rfalNfcDiscoverParam;
+
+
+/*! Buffer union, only one interface is used at a time */
+typedef union{ /* PRQA S 0750 # MISRA 19.2 - Members of the union will not be used concurrently, only one interface at a time */
+ uint8_t rfBuf[RFAL_FEATURE_NFC_RF_BUF_LEN]; /*!< RF buffer */
+ rfalIsoDepApduBufFormat isoDepBuf; /*!< ISO-DEP buffer format (with header/prologue) */
+ rfalNfcDepPduBufFormat nfcDepBuf; /*!< NFC-DEP buffer format (with header/prologue) */
+}rfalNfcBuffer;
+
+/*******************************************************************************/
+
+/*
+******************************************************************************
+* GLOBAL FUNCTION PROTOTYPES
+******************************************************************************
+*/
+
+/*!
+ *****************************************************************************
+ * \brief RFAL NFC Worker
+ *
+ * It runs the internal state machine and runs the RFAL RF worker.
+ *****************************************************************************
+ */
+void rfalNfcWorker( void );
+
+
+/*!
+ *****************************************************************************
+ * \brief RFAL NFC Initialize
+ *
+ * It initializes this module and its dependencies
+ *
+ * \return RFAL_ERR_WRONG_STATE : Incorrect state for this operation
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalNfcInitialize( void );
+
+
+/*!
+ *****************************************************************************
+ * \brief RFAL NFC Discovery
+ *
+ * It set the device in Discovery state.
+ * In discovery it will Poll and/or Listen for the technologies configured,
+ * and perform Wake-up mode if configured to do so.
+ *
+ * The device list passed on disParams must not be empty.
+ * The number of devices on the list is indicated by the devLimit and shall
+ * be at >= 1.
+ *
+ * \param[in] disParams : discovery configuration parameters
+ *
+ * \return RFAL_ERR_WRONG_STATE : Incorrect state for this operation
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalNfcDiscover( const rfalNfcDiscoverParam *disParams );
+
+
+/*!
+ *****************************************************************************
+ * \brief RFAL NFC Get State
+ *
+ * It returns the current state
+ *
+ * \return rfalNfcState : the current state
+ *****************************************************************************
+ */
+rfalNfcState rfalNfcGetState( void );
+
+
+/*!
+ *****************************************************************************
+ * \brief RFAL NFC Get Devices Found
+ *
+ * It returns the location of the device list and the number of
+ * devices found.
+ *
+ * \param[out] devList : device list location
+ * \param[out] devCnt : number of devices found
+ *
+ * \return RFAL_ERR_WRONG_STATE : Incorrect state for this operation
+ * Discovery still ongoing
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalNfcGetDevicesFound( rfalNfcDevice **devList, uint8_t *devCnt );
+
+
+/*!
+ *****************************************************************************
+ * \brief RFAL NFC Get Active Device
+ *
+ * It returns the location of the device current Active device
+ *
+ * \param[out] dev : device info location
+ *
+ * \return RFAL_ERR_WRONG_STATE : Incorrect state for this operation
+ * No device activated
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalNfcGetActiveDevice( rfalNfcDevice **dev );
+
+
+/*!
+ *****************************************************************************
+ * \brief RFAL NFC Select Device
+ *
+ * It selects the device to be activated.
+ * It shall be called when more than one device has been identified to
+ * indicate which device shall be actived
+ *
+ * \param[in] devIdx : device index to be activated
+ *
+ * \return RFAL_ERR_WRONG_STATE : Incorrect state for this operation
+ * Not in select state
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalNfcSelect( uint8_t devIdx );
+
+
+/*!
+ *****************************************************************************
+ * \brief RFAL NFC Start Data Exchange
+ *
+ * After a device has been activated, it starts a data exchange.
+ * It handles automatically which interface/protocol to be used and acts accordingly.
+ *
+ * In Listen mode the first frame/data shall be sent by the Reader/Initiator
+ * therefore this method must be called first with txDataLen set to zero
+ * to retrieve the rxData and rcvLen locations.
+ *
+ *
+ * \param[in] txData : data to be transmitted
+ * \param[in] txDataLen : size of the data to be transmitted (in bits or bytes - see below)
+ * \param[out] rxData : location of the received data after operation is completed
+ * \param[out] rvdLen : location of the length of the received data (in bits or bytes - see below)
+ * \param[in] fwt : FWT to be used in case of RF interface.
+ * If ISO-DEP or NFC-DEP interface is used, this will be ignored
+ *
+ * \warning In order to support a wider range of protocols, when RF interface is used the lengths
+ * are in number of bits (not bytes). Therefore both input txDataLen and output rvdLen refer to
+ * bits. If ISO-DEP or NFC-DEP interface is used those are expressed in number of bytes.
+ *
+ *
+ * \return RFAL_ERR_WRONG_STATE : Incorrect state for this operation
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalNfcDataExchangeStart( uint8_t *txData, uint16_t txDataLen, uint8_t **rxData, uint16_t **rvdLen, uint32_t fwt );
+
+
+/*!
+ *****************************************************************************
+ * \brief RFAL NFC Get Data Exchange Status
+ *
+ * Gets current Data Exchange status
+ *
+ * \return RFAL_ERR_NONE : Transceive done with no error
+ * \return RFAL_ERR_BUSY : Transceive ongoing
+ * \return RFAL_ERR_AGAIN : received one chaining block, copy received data
+ * and continue to call this method to retrieve the
+ * remaining blocks
+ * \return RFAL_ERR_XXXX : Error occurred
+ * \return RFAL_ERR_TIMEOUT : No response
+ * \return RFAL_ERR_FRAMING : Framing error detected
+ * \return RFAL_ERR_PAR : Parity error detected
+ * \return RFAL_ERR_CRC : CRC error detected
+ * \return RFAL_ERR_LINK_LOSS : Link Loss - External Field is Off
+ * \return RFAL_ERR_RF_COLLISION : Collision detected
+ * \return RFAL_ERR_IO : Internal error
+ *****************************************************************************
+ */
+ReturnCode rfalNfcDataExchangeGetStatus( void );
+
+
+/*!
+ *****************************************************************************
+ * \brief RFAL NFC Deactivate
+ *
+ * It triggers the deactivation procedure to terminate communications with
+ * remote device.
+ * In case the deactivation type is RFAL_NFC_DEACTIVATE_SLEEP the field is
+ * kept On and device selection shall follow. Otherwise the field will
+ * be turned Off.
+ *
+ * \warning In case the deactivation type is RFAL_NFC_DEACTIVATE_IDLE the
+ * deactivation procedure is executed immediately and in a blocking manner
+ *
+ * \param[in] deactType : Type of deactivation to be performed
+ *
+ * \return RFAL_ERR_WRONG_STATE : Incorrect state for this operation
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalNfcDeactivate( rfalNfcDeactivateType deactType );
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* RFAL_NFC_H */
+
+
+/**
+ * @}
+ *
+ * @}
+ *
+ * @}
+ */
### core/embed/io/nfc/st25/rfal002/include/rfal_nfcDep.h
@@ -1,780 +1,794 @@
-
-/******************************************************************************
- * @attention
- *
- * COPYRIGHT 2016 STMicroelectronics, all rights reserved
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
- * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
-******************************************************************************/
-
-
-
-/*
- * PROJECT: ST25R firmware
- * Revision:
- * LANGUAGE: ISO C99
- */
-
-/*! \file rfal_nfcDep.h
- *
- * \author Gustavo Patricio
- *
- * \brief Implementation of NFC-DEP protocol
- *
- * NFC-DEP is also known as NFCIP - Near Field Communication
- * Interface and Protocol
- *
- * This implementation was based on the following specs:
- * - NFC Forum Digital 1.1
- * - ECMA 340 3rd Edition 2013
- *
- *
- * \addtogroup RFAL
- * @{
- *
- * \addtogroup RFAL-AL
- * \brief RFAL Abstraction Layer
- * @{
- *
- * \addtogroup NFC-DEP
- * \brief RFAL NFC-DEP Module
- * @{
- */
-
-#ifndef RFAL_NFCDEP_H_
-#define RFAL_NFCDEP_H_
-
-/*
- ******************************************************************************
- * INCLUDES
- ******************************************************************************
- */
-#include "rfal_platform.h"
-#include "rfal_utils.h"
-#include "rfal_rf.h"
-
-
-/*
- ******************************************************************************
- * ENABLE SWITCH
- ******************************************************************************
- */
-
-/* If module is disabled remove the need for the user to set lengths */
-#if !RFAL_FEATURE_NFC_DEP
- /* PRQA S 0841 2 # MISRA 20.5 - #undef used to ease user defined configuration and memory optimization */ /* PRQA S 0847 2 # MISRA 20.5 - #undef used to ease user defined configuration and memory optimization */
- #undef RFAL_FEATURE_NFC_DEP_BLOCK_MAX_LEN
- #undef RFAL_FEATURE_NFC_DEP_PDU_MAX_LEN
-
- #define RFAL_FEATURE_NFC_DEP_BLOCK_MAX_LEN 2U /*!< NFC-DEP Block/Payload length, set to "none" */ /* MISRA: Some compilers treat an array of length one declared as the final member of a struct as a flexible array member.*/
- #define RFAL_FEATURE_NFC_DEP_PDU_MAX_LEN 2U /*!< NFC-DEP PDU length, set to "none" */ /* MISRA: Some compilers treat an array of length one declared as the final member of a struct as a flexible array member.*/
-#endif /* !RFAL_FEATURE_NFC_DEP */
-
-/*
- ******************************************************************************
- * DEFINES
- ******************************************************************************
- */
-#define RFAL_NFCDEP_FRAME_SIZE_MAX_LEN 254U /*!< Maximum Frame Size Digital 2.0 Table 90 */
-#define RFAL_NFCDEP_DEPREQ_HEADER_LEN 5U /*!< DEP_REQ header length: CMD_TYPE + CMD_CMD + PBF + DID + NAD */
-
-/*! Length NFCIP DEP REQ or RES header (incl LEN) */
-#define RFAL_NFCDEP_DEP_HEADER ( RFAL_NFCDEP_LEN_LEN + RFAL_NFCDEP_CMDTYPE_LEN + RFAL_NFCDEP_CMD_LEN + RFAL_NFCDEP_DEP_PFB_LEN )
-#define RFAL_NFCDEP_HEADER ( RFAL_NFCDEP_CMDTYPE_LEN + RFAL_NFCDEP_CMD_LEN ) /*!< NFCIP header length */
-#define RFAL_NFCDEP_SB_LEN 1U /*!< SB length on NFCIP fram for NFC-A */
-#define RFAL_NFCDEP_LEN_LEN 1U /*!< LEN length on NFCIP frame */
-#define RFAL_NFCDEP_CMDTYPE_LEN 1U /*!< Length of the cmd type (REQ | RES) on NFCIP frame */
-#define RFAL_NFCDEP_CMD_LEN 1U /*!< Length of the cmd on NFCIP frame */
-#define RFAL_NFCDEP_DID_LEN 1U /*!< Length of did on NFCIP frame */
-#define RFAL_NFCDEP_DEP_PFB_LEN 1U /*!< Length of the PFB field on NFCIP frame */
-
-#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 */
-#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 */
-
-#define RFAL_NFCDEP_FS_VAL_MIN 64U /*!< Minimum LR value */
-#define RFAL_NFCDEP_LR_VAL_MASK 0x03U /*!< Bit mask for a LR value */
-#define RFAL_NFCDEP_PP_LR_MASK 0x30U /*!< Bit mask for LR value in PP byte on a ATR REQ/RES */
-#define RFAL_NFCDEP_PP_LR_SHIFT 4U /*!< Position of LR value in PP byte on a ATR REQ/RES */
-
-#define RFAL_NFCDEP_DID_MAX 14U /*!< Max DID value Digital 14.6.2.3 */
-#define RFAL_NFCDEP_DID_KEEP 0xFFU /*!< Keep DID value already configured */
-#define RFAL_NFCDEP_DID_NO 0x00U /*!< No DID shall be used */
-#define RFAL_NFCDEP_NAD_NO 0x00U /*!< No NAD shall be used */
-
-#define RFAL_NFCDEP_OPER_RTOX_REQ_DIS 0x01U /*!< Operation config: RTOX REQ disable */
-#define RFAL_NFCDEP_OPER_RTOX_REQ_EN 0x00U /*!< Operation config: RTOX REQ enable */
-
-#define RFAL_NFCDEP_OPER_ATN_DIS 0x00U /*!< Operation config: ATN disable */
-#define RFAL_NFCDEP_OPER_ATN_EN 0x02U /*!< Operation config: ATN enable */
-
-#define RFAL_NFCDEP_OPER_EMPTY_DEP_DIS 0x04U /*!< Operation config: empty DEPs disable */
-#define RFAL_NFCDEP_OPER_EMPTY_DEP_EN 0x00U /*!< Operation config: empty DEPs enable */
-
-#define RFAL_NFCDEP_OPER_FULL_MI_DIS 0x00U /*!< Operation config: full chaining DEPs disable */
-#define RFAL_NFCDEP_OPER_FULL_MI_EN 0x08U /*!< Operation config: full chaining DEPs enable */
-
-
-#define RFAL_NFCDEP_BRS_MAINTAIN 0xC0U /*!< Value signalling that BR is to be maintained (no PSL) */
-#define RFAL_NFCDEP_BRS_Dx_MASK 0x07U /*!< Value signalling that BR is to be maintained (no PSL) */
-#define RFAL_NFCDEP_BRS_DSI_POS 3U /*!< Value signalling that BR is to be maintained (no PSL) */
-
-#define RFAL_NFCDEP_WT_DELTA (16U - RFAL_NFCDEP_WT_DELTA_ADJUST) /*!< NFC-DEP dWRT (adjusted) Digital 2.0 B.10 */
-#define RFAL_NFCDEP_WT_DELTA_ADJUST 4U /*!< dWRT value adjustment */
-
-
-#define RFAL_NFCDEP_ATR_REQ_NFCID3_POS 2U /*!< NFCID3 offset in ATR_REQ frame */
-#define RFAL_NFCDEP_NFCID3_LEN 10U /*!< NFCID3 Length */
-
-#define RFAL_NFCDEP_LEN_MIN 3U /*!< Minimum length byte LEN value */
-#define RFAL_NFCDEP_LEN_MAX 255U /*!< Maximum length byte LEN value */
-
-#define RFAL_NFCDEP_ATRRES_HEADER_LEN 2U /*!< ATR RES Header Len: CmdType: 0xD5 + Cod: 0x01 */
-#define RFAL_NFCDEP_ATRRES_MIN_LEN 17U /*!< Minimum length for an ATR RES */
-#define RFAL_NFCDEP_ATRRES_MAX_LEN 64U /*!< Maximum length for an ATR RES Digital 1.0 14.6.1 */
-#define RFAL_NFCDEP_ATRREQ_MIN_LEN 16U /*!< Minimum length for an ATR REQ */
-#define RFAL_NFCDEP_ATRREQ_MAX_LEN RFAL_NFCDEP_ATRRES_MAX_LEN /*!< Maximum length for an ATR REQ Digital 1.0 14.6.1 */
-
-#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 */
-
-#define RFAL_NFCDEP_WT_INI_DEFAULT RFAL_NFCDEP_WT_INI_MAX /*!< WT Initiator default value Digital 1.0 14.6.3.8 */
-#define RFAL_NFCDEP_WT_INI_MIN 0U /*!< WT Initiator minimum value Digital 1.0 14.6.3.8 */
-#define RFAL_NFCDEP_WT_INI_MAX 14U /*!< WT Initiator maximum value Digital 1.0 14.6.3.8 A.10 */
-#define RFAL_NFCDEP_RWT_INI_MAX rfalNfcDepWT2RWT( RFAL_NFCDEP_WT_INI_MAX ) /*!< RWT Initiator maximum value */
-
-#define RFAL_NFCDEP_WT_TRG_MAX_D10 8U /*!< WT target max Digital 1.0 14.6.3.8 A.10 */
-#define RFAL_NFCDEP_WT_TRG_MAX_D11 14U /*!< WT target max Digital 1.1 16.6.3.9 A.9 */
-#define RFAL_NFCDEP_WT_TRG_MAX_L13 10U /*!< WT target max [LLCP] 1.3 6.2.1 */
-#define RFAL_NFCDEP_WT_TRG_MAX RFAL_NFCDEP_WT_TRG_MAX_D11 /*!< WT target max Digital x.x | LLCP x.x */
-#define RFAL_NFCDEP_RWT_TRG_MAX rfalNfcDepWT2RWT( RFAL_NFCDEP_WT_TRG_MAX ) /*!< RWT Initiator maximum value */
-
-/*! Maximum Frame Waiting Time = ((256 * 16/fc)*2^FWImax) = ((256*16/fc)*2^14) = (1048576 / 64)/fc = (100000h*64)/fc */
-#define RFAL_NFCDEP_MAX_FWT ((uint32_t)1U<<20)
-
-#define RFAL_NFCDEP_WT_MASK 0x0FU /*!< Bit mask for the Wait Time value */
-
-#define RFAL_NFCDEP_BR_MASK_106 0x01U /*!< Enable mask bit rate 106 */
-#define RFAL_NFCDEP_BR_MASK_212 0x02U /*!< Enable mask bit rate 242 */
-#define RFAL_NFCDEP_BR_MASK_424 0x04U /*!< Enable mask bit rate 424 */
-
-/*
- ******************************************************************************
- * GLOBAL MACROS
- ******************************************************************************
- */
-
-#define rfalNfcDepWT2RWT( wt ) ( (uint32_t)1U << (((uint32_t)(wt) & RFAL_NFCDEP_WT_MASK) + 12U) ) /*!< Converts WT value to RWT (1/fc) */
-
-/*! Returns the BRS value from the given bit rate */
-#define rfalNfcDepDx2BRS( br ) ( (((uint8_t)(br) & RFAL_NFCDEP_BRS_Dx_MASK) << RFAL_NFCDEP_BRS_DSI_POS) | ((uint8_t)(br) & RFAL_NFCDEP_BRS_Dx_MASK) )
-
-#define rfalNfcDepBRS2DRI( brs ) (uint8_t)( (uint8_t)(brs) & RFAL_NFCDEP_BRS_Dx_MASK ) /*!< Returns the DRI value from the given BRS byte */
-#define rfalNfcDepBRS2DSI( brs ) (uint8_t)( ((uint8_t)(brs) >> RFAL_NFCDEP_BRS_DSI_POS) & RFAL_NFCDEP_BRS_Dx_MASK ) /*!< Returns the DSI_ID value from the given BRS byte */
-
-#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 */
-#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 */
-
-/*! Returns the Frame size value from the given LRx value */
-#define rfalNfcDepLR2FS( LRx ) (uint16_t)(RFAL_MIN( (RFAL_NFCDEP_FS_VAL_MIN * ((uint16_t)(LRx) + 1U) ), RFAL_NFCDEP_FRAME_SIZE_MAX_LEN ))
-
-/*!
- * Despite DIGITAL 1.0 14.6.2.1 stating that the last two bytes may filled with
- * any value, some devices (Samsung Google Nexus) only accept when these are 0 */
-#define rfalNfcDepSetNFCID( dst, src, len ) RFAL_MEMSET( (dst), 0x00, RFAL_NFCDEP_NFCID3_LEN ); \
- if( (len) > 0U ) {RFAL_MEMCPY( (dst), (src), (len) );}
-
-/*
- ******************************************************************************
- * GLOBAL ENUMERATIONS
- ******************************************************************************
- */
-
-/*! Enumeration of NFC-DEP bit rate in ATR Digital 1.0 Table 93 and 94 */
-enum{
- RFAL_NFCDEP_Bx_NO_HIGH_BR = 0x00, /*!< Peer supports no high bit rates */
- RFAL_NFCDEP_Bx_08_848 = 0x01, /*!< Peer also supports 848 */
- RFAL_NFCDEP_Bx_16_1695 = 0x02, /*!< Peer also supports 1695 */
- RFAL_NFCDEP_Bx_32_3390 = 0x04, /*!< Peer also supports 3390 */
- RFAL_NFCDEP_Bx_64_6780 = 0x08 /*!< Peer also supports 6780 */
-};
-
-/*! Enumeration of NFC-DEP bit rate Dividor in PSL Digital 1.0 Table 100 */
-enum{
- RFAL_NFCDEP_Dx_01_106 = RFAL_BR_106, /*!< Divisor D = 1 : bit rate = 106 */
- RFAL_NFCDEP_Dx_02_212 = RFAL_BR_212, /*!< Divisor D = 2 : bit rate = 212 */
- RFAL_NFCDEP_Dx_04_424 = RFAL_BR_424, /*!< Divisor D = 4 : bit rate = 424 */
- RFAL_NFCDEP_Dx_08_848 = RFAL_BR_848, /*!< Divisor D = 8 : bit rate = 848 */
- RFAL_NFCDEP_Dx_16_1695 = RFAL_BR_1695, /*!< Divisor D = 16 : bit rate = 1695 */
- RFAL_NFCDEP_Dx_32_3390 = RFAL_BR_3390, /*!< Divisor D = 32 : bit rate = 3390 */
- RFAL_NFCDEP_Dx_64_6780 = RFAL_BR_6780 /*!< Divisor D = 64 : bit rate = 6780 */
-};
-
-/*! Enumeration of NFC-DEP Length Reduction (LR) Digital 1.0 Table 91 */
-enum{
- RFAL_NFCDEP_LR_64 = 0x00, /*!< Maximum payload size is 64 bytes */
- RFAL_NFCDEP_LR_128 = 0x01, /*!< Maximum payload size is 128 bytes */
- RFAL_NFCDEP_LR_192 = 0x02, /*!< Maximum payload size is 192 bytes */
- RFAL_NFCDEP_LR_254 = 0x03 /*!< Maximum payload size is 254 bytes */
-};
-
-/*
- ******************************************************************************
- * GLOBAL DATA TYPES
- ******************************************************************************
- */
-
-/*! NFC-DEP callback to check if upper layer has deactivation pending */
-typedef bool (* rfalNfcDepDeactCallback)(void);
-
-
-/*! Enumeration of the nfcip communication modes */
-typedef enum{
- RFAL_NFCDEP_COMM_PASSIVE, /*!< Passive communication mode */
- RFAL_NFCDEP_COMM_ACTIVE /*!< Active communication mode */
-} rfalNfcDepCommMode;
-
-
-/*! Enumeration of the nfcip roles */
-typedef enum{
- RFAL_NFCDEP_ROLE_INITIATOR, /*!< Perform as Initiator */
- RFAL_NFCDEP_ROLE_TARGET /*!< Perform as Target */
-} rfalNfcDepRole;
-
-
-/*! Struct that holds all NFCIP configs */
-typedef struct{
-
- rfalNfcDepRole role; /*!< Current NFCIP role */
- rfalNfcDepCommMode commMode; /*!< Current NFCIP communication mode */
- uint8_t oper; /*!< Operation config similar to NCI 1.0 Table 81 */
-
- uint8_t did; /*!< Current Device ID (DID) */
- uint8_t nad; /*!< Current Node Addressing (NAD) */
- uint8_t bs; /*!< Bit rate in Sending Direction */
- uint8_t br; /*!< Bit rate in Receiving Direction */
- uint8_t nfcid[RFAL_NFCDEP_NFCID3_LEN]; /*!< Pointer to the NFCID to be used */
- uint8_t nfcidLen; /*!< Length of the given NFCID in nfcid */
- uint8_t gb[RFAL_NFCDEP_GB_MAX_LEN]; /*!< Pointer General Bytes (GB) to be used */
- uint8_t gbLen; /*!< Length of the given GB in gb */
- uint8_t lr; /*!< Length Reduction (LR) to be used */
- uint8_t to; /*!< Timeout (TO) to be used */
- uint32_t fwt; /*!< Frame Waiting Time (FWT) to be used */
- uint32_t dFwt; /*!< Delta Frame Waiting Time (dFWT) to be used */
-} rfalNfcDepConfigs;
-
-
-/*! ATR_REQ command Digital 1.1 16.6.2 */
-typedef struct {
- uint8_t CMD1; /*!< Command format 0xD4 */
- uint8_t CMD2; /*!< Command Value */
- uint8_t NFCID3[RFAL_NFCDEP_NFCID3_LEN]; /*!< NFCID3 value */
- uint8_t DID; /*!< DID */
- uint8_t BSi; /*!< Sending Bitrate for Initiator */
- uint8_t BRi; /*!< Receiving Bitrate for Initiator */
- uint8_t PPi; /*!< Optional Parameters presence indicator */
- uint8_t GBi[RFAL_NFCDEP_GB_MAX_LEN]; /*!< General Bytes */
-} rfalNfcDepAtrReq;
-
-
-/*! ATR_RES response Digital 1.1 16.6.3 */
-typedef struct {
- uint8_t CMD1; /*!< Response Byte 0xD5 */
- uint8_t CMD2; /*!< Command Value */
- uint8_t NFCID3[RFAL_NFCDEP_NFCID3_LEN]; /*!< NFCID3 value */
- uint8_t DID; /*!< DID */
- uint8_t BSt; /*!< Sending Bitrate for Initiator */
- uint8_t BRt; /*!< Receiving Bitrate for Initiator */
- uint8_t TO; /*!< Timeout */
- uint8_t PPt; /*!< Optional Parameters presence indicator */
- uint8_t GBt[RFAL_NFCDEP_GB_MAX_LEN]; /*!< General Bytes */
-} rfalNfcDepAtrRes;
-
-
-/*! Structure of transmit I-PDU Buffer format from caller */
-typedef struct
-{
- uint8_t prologue[RFAL_NFCDEP_DEPREQ_HEADER_LEN]; /*!< Prologue space for NFC-DEP header*/
- uint8_t inf[RFAL_FEATURE_NFC_DEP_BLOCK_MAX_LEN]; /*!< INF | Data area of the buffer */
-} rfalNfcDepBufFormat;
-
-
-/*! Structure of APDU Buffer format from caller */
-typedef struct
-{
- uint8_t prologue[RFAL_NFCDEP_DEPREQ_HEADER_LEN]; /*!< Prologue/SoD buffer */
- uint8_t pdu[RFAL_FEATURE_NFC_DEP_PDU_MAX_LEN]; /*!< Complete PDU/Payload buffer */
-} rfalNfcDepPduBufFormat;
-
-
-/*! Activation info as Initiator and Target */
-typedef union { /* PRQA S 0750 # MISRA 19.2 - Both members of the union will not be used concurrently , device is only initiatior or target a time. No problem can occur. */
- struct {
- rfalNfcDepAtrRes ATR_RES; /*!< ATR RES (Initiator mode) */
- uint8_t ATR_RESLen; /*!< ATR RES length (Initiator mode) */
- }Target; /*!< Target */
- struct {
- rfalNfcDepAtrReq ATR_REQ; /*!< ATR REQ (Target mode) */
- uint8_t ATR_REQLen; /*!< ATR REQ length (Target mode) */
- }Initiator; /*!< Initiator */
-} rfalNfcDepActivation;
-
-
-/*! NFC-DEP device Info */
-typedef struct {
- uint8_t GBLen; /*!< General Bytes length */
- uint8_t WT; /*!< WT to be used (ignored in Listen Mode) */
- uint32_t FWT; /*!< FWT to be used (1/fc)(ignored Listen Mode) */
- uint32_t dFWT; /*!< Delta FWT to be used (1/fc) */
- uint8_t LR; /*!< Length Reduction coding the max payload */
- uint16_t FS; /*!< Frame Size */
- rfalBitRate DSI_ID; /*!< Bit Rate coding from Initiator to Target */
- rfalBitRate DRI; /*!< Bit Rate coding from Target to Initiator */
- uint8_t DID; /*!< Device ID (RFAL_NFCDEP_DID_NO if no DID) */
- uint8_t NAD; /*!< Node ADdress (RFAL_NFCDEP_NAD_NO if no NAD)*/
-} rfalNfcDepInfo;
-
-
-/*! NFC-DEP Device structure */
-typedef struct {
- rfalNfcDepActivation activation; /*!< Activation Info */
- rfalNfcDepInfo info; /*!< NFC-DEP device Info */
-} rfalNfcDepDevice;
-
-
-/*! NFCIP Protocol structure for P2P Target
- *
- * operParam : derives from NFC-Forum NCI NFC-DEP Operation Parameter
- * NCI 1.1 Table 86: NFC-DEP Operation Parameter
- * and it's a bit mask composed as:
- * [ 0000b
- * | Chain SHALL use max. Transport Data Byte[1b]
- * | I-PDU with no Transport Data SHALL NOT be sent [1b]
- * | NFC-DEP Target SHALL NOT send RTOX request [1b]
- * ]
- *
- */
-typedef struct{
- rfalNfcDepCommMode commMode; /*!< Initiator in Active P2P or Passive P2P*/
- uint8_t operParam; /*!< NFC-DEP Operation Parameter */
- uint8_t* nfcid; /*!< Initiator's NFCID2 or NFCID3 */
- uint8_t nfcidLen; /*!< Initiator's NFCID length (NFCID2/3) */
- uint8_t DID; /*!< Initiator's Device ID DID */
- uint8_t NAD; /*!< Initiator's Node ID NAD */
- uint8_t BS; /*!< Initiator's Bit Rates supported in Tx */
- uint8_t BR; /*!< Initiator's Bit Rates supported in Rx */
- uint8_t LR; /*!< Initiator's Length reduction */
- uint8_t* GB; /*!< Initiator's General Bytes (Gi) */
- uint8_t GBLen; /*!< Initiator's General Bytes length */
-} rfalNfcDepAtrParam;
-
-
-/*! Structure of parameters to be passed in for nfcDepListenStartActivation */
-typedef struct
-{
- rfalNfcDepBufFormat *rxBuf; /*!< Receive Buffer struct reference */
- uint16_t *rxLen; /*!< Receive INF data length in bytes */
- bool *isRxChaining; /*!< Received data is not complete */
- rfalNfcDepDevice *nfcDepDev; /*!< NFC-DEP device info */
-} rfalNfcDepListenActvParam;
-
-
-/*! NFCIP Protocol structure for P2P Target
- *
- * operParam : derives from NFC-Forum NCI NFC-DEP Operation Parameter
- * NCI 1.1 Table 86: NFC-DEP Operation Parameter
- * and it's a bit mask composed as:
- * [ 0000b
- * | Chain SHALL use max. Transport Data Byte[1b]
- * | I-PDU with no Transport Data SHALL NOT be sent [1b]
- * | NFC-DEP Target SHALL NOT send RTOX request [1b]
- * ]
- *
- */
-typedef struct{
- rfalNfcDepCommMode commMode; /*!< Target in Active P2P or Passive P2P */
- uint8_t nfcid3[RFAL_NFCDEP_NFCID3_LEN]; /*!< Target's NFCID3 */
- uint8_t bst; /*!< Target's Bit Rates supported in Tx */
- uint8_t brt; /*!< Target's Bit Rates supported in Rx */
- uint8_t to; /*!< Target's timeout (TO) value */
- uint8_t ppt; /*!< Target's Presence optional Params(PPt)*/
- uint8_t GBt[RFAL_NFCDEP_GB_MAX_LEN]; /*!< Target's General Bytes (Gt) */
- uint8_t GBtLen; /*!< Target's General Bytes length */
- uint8_t operParam; /*!< NFC-DEP Operation Parameter */
-} rfalNfcDepTargetParam;
-
-
-/*! Structure of parameters to be passed in for nfcDepStartIpduTransceive */
-typedef struct
-{
- rfalNfcDepBufFormat *txBuf; /*!< Transmit Buffer struct reference */
- uint16_t txBufLen; /*!< Transmit Buffer INF field length in bytes */
- bool isTxChaining; /*!< Transmit data is not complete */
- rfalNfcDepBufFormat *rxBuf; /*!< Receive Buffer struct reference */
- uint16_t *rxLen; /*!< Receive INF data length */
- bool *isRxChaining; /*!< Received data is not complete */
- uint32_t FWT; /*!< FWT to be used (ignored in Listen Mode) */
- uint32_t dFWT; /*!< Delta FWT to be used */
- uint16_t FSx; /*!< Other device Frame Size (FSD or FSC) */
- uint8_t DID; /*!< Device ID (RFAL_ISODEP_NO_DID if no DID) */
-} rfalNfcDepTxRxParam;
-
-
-/*! Structure of parameters used on NFC DEP PDU Transceive */
-typedef struct
-{
- rfalNfcDepPduBufFormat *txBuf; /*!< Transmit Buffer struct reference */
- uint16_t txBufLen; /*!< Transmit Buffer INF field length in Bytes*/
- rfalNfcDepPduBufFormat *rxBuf; /*!< Receive Buffer struct reference in Bytes */
- uint16_t *rxLen; /*!< Received INF data length in Bytes */
- rfalNfcDepBufFormat *tmpBuf; /*!< Temp buffer for single PDUs (internal) */
- uint32_t FWT; /*!< FWT to be used (ignored in Listen Mode) */
- uint32_t dFWT; /*!< Delta FWT to be used */
- uint16_t FSx; /*!< Other device Frame Size (FSD or FSC) */
- uint8_t DID; /*!< Device ID (RFAL_ISODEP_NO_DID if no DID) */
-} rfalNfcDepPduTxRxParam;
-
-
-/*
- * *****************************************************************************
- * GLOBAL VARIABLE DECLARATIONS
- ******************************************************************************
- */
-
-
-/*
- ******************************************************************************
- * GLOBAL FUNCTION PROTOTYPES
- ******************************************************************************
- */
-
-/*!
- ******************************************************************************
- * \brief NFCIP Initialize
- *
- * This method resets all NFC-DEP inner states, counters and context and sets
- * default values
- *
- ******************************************************************************
- */
-void rfalNfcDepInitialize( void );
-
-
-/*!
- ******************************************************************************
- * \brief Set deactivating callback
- *
- * Sets the deactivating callback so that nfcip layer can check if upper layer
- * has a deactivation pending, and not perform error recovery upon specific
- * errors
- *
- * \param[in] pFunc : method pointer to deactivation flag check
- ******************************************************************************
- */
-void rfalNfcDepSetDeactivatingCallback( rfalNfcDepDeactCallback pFunc );
-
-
-/*!
- ******************************************************************************
- * \brief Calculate Response Waiting Time
- *
- * Calculates the Response Waiting Time (RWT) from the given Waiting Time (WT)
- *
- * \param[in] wt : the WT value to calculate RWT
- *
- * \return RWT value in 1/fc
- ******************************************************************************
- */
-uint32_t rfalNfcDepCalculateRWT( uint8_t wt );
-
-
-/*!
- ******************************************************************************
- * \brief NFC-DEP Initiator ATR (Attribute Request)
- *
- * This method configures the NFC-DEP layer with given parameters and then
- * sends an ATR to the Target with and checks for a valid response response
- *
- * \param[in] param : parameters to initialize and compose the ATR
- * \param[out] atrRes : location to store the ATR_RES
- * \param[out] atrResLen : length of the ATR_RES received
- *
- * \return RFAL_ERR_NONE : No error
- * \return RFAL_ERR_TIMEOUT : Timeout occurred
- * \return RFAL_ERR_PROTO : Protocol error occurred
- ******************************************************************************
- */
-ReturnCode rfalNfcDepATR( const rfalNfcDepAtrParam* param, rfalNfcDepAtrRes *atrRes, uint8_t* atrResLen );
-
-
-/*!
- ******************************************************************************
- * \brief NFC-DEP Initiator PSL (Parameter Selection)
- *
- * This method sends a PSL to the Target with the given parameters and checks
- * for a valid response response
- *
- * The parameters must be coded according to Digital 1.1 16.7.1
- *
- * \param[in] BRS : the selected Bit Rates for Initiator and Target
- * \param[in] FSL : the maximum length of Commands and Responses
- *
- * \return RFAL_ERR_NONE : No error
- * \return RFAL_ERR_TIMEOUT : Timeout occurred
- * \return RFAL_ERR_PROTO : Protocol error occurred
- ******************************************************************************
- */
-ReturnCode rfalNfcDepPSL( uint8_t BRS, uint8_t FSL );
-
-
-/*!
- ******************************************************************************
- * \brief NFC-DEP Initiator DSL (Deselect)
- *
- * This method checks if the NFCIP module is configured as initiator and if
- * so sends a DSL REQ, waits the target's response and checks it
- *
- * In case of performing as target no action is taken
- *
- * \return RFAL_ERR_NONE : No error
- * \return RFAL_ERR_TIMEOUT : Timeout occurred
- * \return RFAL_ERR_MAX_RERUNS : Timeout occurred
- * \return RFAL_ERR_PROTO : Protocol error occurred
- ******************************************************************************
- */
-ReturnCode rfalNfcDepDSL( void );
-
-
-/*!
- ******************************************************************************
- * \brief NFC-DEP Initiator RLS (Release)
- *
- * This method checks if the NFCIP module is configured as initiator and if
- * so sends a RLS REQ, waits target's response and checks it
- *
- * In case of performing as target no action is taken
- *
- * \return RFAL_ERR_NONE : No error
- * \return RFAL_ERR_TIMEOUT : Timeout occurred
- * \return RFAL_ERR_MAX_RERUNS : Timeout occurred
- * \return RFAL_ERR_PROTO : Protocol error occurred
- ******************************************************************************
- */
-ReturnCode rfalNfcDepRLS( void );
-
-
-/*!
- *****************************************************************************
- * \brief NFC-DEP Initiator Handle Activation
- *
- * This performs a Activation into NFC-DEP layer with the given
- * parameters. It sends ATR_REQ and if the higher bit rates are supported by
- * both devices it additionally sends PSL
- * Once Activated all details of the device are provided on nfcDepDev
- *
- * \param[in] param : required parameters to initialize and send ATR_REQ
- * \param[in] desiredBR : Desired bit rate supported by the Poller
- * \param[out] nfcDepDev : NFC-DEP information of the activated Listen device
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_TIMEOUT : Timeout error
- * \return RFAL_ERR_PAR : Parity error detected
- * \return RFAL_ERR_CRC : CRC error detected
- * \return RFAL_ERR_FRAMING : Framing error detected
- * \return RFAL_ERR_PROTO : Protocol error detected
- * \return RFAL_ERR_NONE : No error, activation successful
- *****************************************************************************
- */
-ReturnCode rfalNfcDepInitiatorHandleActivation( rfalNfcDepAtrParam* param, rfalBitRate desiredBR, rfalNfcDepDevice* nfcDepDev );
-
-
-/*!
- ******************************************************************************
- * \brief Check if buffer contains valid ATR_REQ
- *
- * This method checks if the given ATR_REQ is valid
- *
- *
- * \param[in] buf : buffer holding Initiator's received request
- * \param[in] bufLen : size of the msg contained on the buf in Bytes
- * \param[out] nfcid3 : pointer to where the NFCID3 may be outputed,
- * nfcid3 has NFCF_SENSF_NFCID3_LEN as length
- * Pass NULL if output parameter not desired
- *
- * \return true : Valid ATR_REQ received, the ATR_RES has been computed in txBuf
- * \return false : Invalid protocol request
- *
- ******************************************************************************
- */
-bool rfalNfcDepIsAtrReq( const uint8_t* buf, uint16_t bufLen, uint8_t* nfcid3 );
-
-
-/*!
- ******************************************************************************
- * \brief Check is Target has received ATR
- *
- * This method checks if the NFCIP module is configured as target and if a
- * ATR REQ has been received ( whether is in activation or in data exchange)
- *
- * \return true : a ATR has already been received
- * \return false : no ATR has been received
- ******************************************************************************
- */
-bool rfalNfcDepTargetRcvdATR( void );
-
-/*!
- *****************************************************************************
- * \brief NFCDEP Start Listen Activation Handling
- *
- * Start Activation Handling and setup to receive first frame which may
- * contain complete or partial DEP-REQ after activation is completed
- *
- * Pass in ATR_REQ for NFC-DEP to handle ATR_RES. The Activation Handling
- * handles ATR_RES and PSL_RES if a PSL_REQ is received
- *
- * Activation is completed if PSL_RES is sent or if first I-PDU is received
- *
- * \ref rfalNfcDepListenGetActivationStatus() provide status of the
- * ongoing activation
- *
- * \warning nfcDepGetTransceiveStatus() shall be called right after activation
- * is completed (i.e. rfalNfcDepListenGetActivationStatus() return RFAL_ERR_NONE)
- * to check for first received frame.
- *
- * \param[in] param : Target parameters to be used
- * \param[in] atrReq : reference to buffer containing ATR_REQ
- * \param[in] atrReqLength: Length of ATR_REQ
- * \param[out] rxParam : references to buffer, length and chaining indication
- * for first complete LLCP to be received
- *
- * \return RFAL_ERR_NONE : ATR_REQ is valid and activation ongoing
- * \return RFAL_ERR_PARAM : ATR_REQ or other params are invalid
- * \return RFAL_ERR_LINK_LOSS : Remote Field is turned off
- *****************************************************************************
- */
-ReturnCode rfalNfcDepListenStartActivation( const rfalNfcDepTargetParam *param, const uint8_t *atrReq, uint16_t atrReqLength, rfalNfcDepListenActvParam rxParam );
-
-
-/*!
- *****************************************************************************
- * \brief Get the current NFC-DEP Activation Status
- *
- * \return RFAL_ERR_NONE : Activation has completed successfully
- * \return RFAL_ERR_BUSY : Activation is ongoing
- * \return RFAL_ERR_LINK_LOSS : Remote Field was turned off
- *****************************************************************************
- */
-ReturnCode rfalNfcDepListenGetActivationStatus( void );
-
-/*!
- *****************************************************************************
- * \brief Start Transceive
- *
- * Transceives a complete or partial DEP block
- *
- * The txBuf contains complete or partial of DEP to be transmitted.
- * The Prologue field of the I-PDU is handled internally
- *
- * If the buffer contains partial LLCP and is not the last block, then
- * isTxChaining must be set to true
- *
- * \param[in] param: reference parameters to be used for the Transceive
- *
- * \return RFAL_ERR_PARAM : Bad request
- * \return RFAL_ERR_WRONG_STATE : The module is not in a proper state
- * \return RFAL_ERR_NONE : The Transceive request has been started
- *****************************************************************************
- */
-ReturnCode rfalNfcDepStartTransceive( const rfalNfcDepTxRxParam *param );
-
-
-/*!
- *****************************************************************************
- * \brief Return the Transceive status
- *
- * Returns the status of the NFC-DEP Transceive
- *
- * \warning When the other device is performing chaining once a chained
- * block is received the error RFAL_ERR_AGAIN is sent. At this point
- * caller must handle the received data immediately.
- * When RFAL_ERR_AGAIN is returned an ACK has already been sent to
- * the other device and the next block might be incoming.
- * If rfalWorker() is called frequently it will place the next
- * block on the given buffer
- *
- * \return RFAL_ERR_NONE : Transceive has been completed successfully
- * \return RFAL_ERR_BUSY : Transceive is ongoing
- * \return RFAL_ERR_PROTO : Protocol error occurred
- * \return RFAL_ERR_TIMEOUT : Timeout error occurred
- * \return RFAL_ERR_SLEEP_REQ : Deselect has been received and responded
- * \return RFAL_ERR_NOMEM : The received I-PDU does not fit into the
- * receive buffer
- * \return RFAL_ERR_LINK_LOSS : Communication is lost because Reader/Writer
- * has turned off its field
- * \return RFAL_ERR_AGAIN : received one chaining block, continue to call
- * this method to retrieve the remaining blocks
- *****************************************************************************
- */
-ReturnCode rfalNfcDepGetTransceiveStatus( void );
-
-
-/*!
- *****************************************************************************
- * \brief Start PDU Transceive
- *
- * This method triggers a NFC-DEP Transceive containing a complete PDU
- * It transmits the given message and handles all protocol retransmitions,
- * error handling and control messages
- *
- * The txBuf contains a complete PDU to be transmitted
- * The Prologue field will be manipulated by the Transceive
- *
- * \warning the txBuf will be modified during the transmission
- * \warning the maximum RF frame which can be received is limited by param.tmpBuf
- *
- * \param[in] param: reference parameters to be used for the Transceive
- *
- * \return RFAL_ERR_PARAM : Bad request
- * \return RFAL_ERR_WRONG_STATE : The module is not in a proper state
- * \return RFAL_ERR_NONE : The Transceive request has been started
- *****************************************************************************
- */
-ReturnCode rfalNfcDepStartPduTransceive( rfalNfcDepPduTxRxParam param );
-
-
-/*!
- *****************************************************************************
- * \brief Return the PDU Transceive status
- *
- * Returns the status of the NFC-DEP PDU Transceive
- *
- *
- * \return RFAL_ERR_NONE : Transceive has been completed successfully
- * \return RFAL_ERR_BUSY : Transceive is ongoing
- * \return RFAL_ERR_PROTO : Protocol error occurred
- * \return RFAL_ERR_TIMEOUT : Timeout error occurred
- * \return RFAL_ERR_SLEEP_REQ : Deselect has been received and responded
- * \return RFAL_ERR_NOMEM : The received I-PDU does not fit into the
- * receive buffer
- * \return RFAL_ERR_LINK_LOSS : Communication is lost because Reader/Writer
- * has turned off its field
- *****************************************************************************
- */
-ReturnCode rfalNfcDepGetPduTransceiveStatus( void );
-
-#endif /* RFAL_NFCDEP_H_ */
-
-/**
- * @}
- *
- * @}
- *
- * @}
- */
+
+/******************************************************************************
+ * @attention
+ *
+ * COPYRIGHT 2016 STMicroelectronics, all rights reserved
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
+ * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+******************************************************************************/
+
+
+
+/*
+ * PROJECT: ST25R firmware
+ * Revision:
+ * LANGUAGE: ISO C99
+ */
+
+/*! \file rfal_nfcDep.h
+ *
+ * \author Gustavo Patricio
+ *
+ * \brief Implementation of NFC-DEP protocol
+ *
+ * NFC-DEP is also known as NFCIP - Near Field Communication
+ * Interface and Protocol
+ *
+ * This implementation was based on the following specs:
+ * - NFC Forum Digital 1.1
+ * - ECMA 340 3rd Edition 2013
+ *
+ *
+ * \addtogroup RFAL
+ * @{
+ *
+ * \addtogroup RFAL-AL
+ * \brief RFAL Abstraction Layer
+ * @{
+ *
+ * \addtogroup NFC-DEP
+ * \brief RFAL NFC-DEP Module
+ * @{
+ */
+
+#ifndef RFAL_NFCDEP_H_
+#define RFAL_NFCDEP_H_
+
+/*
+ ******************************************************************************
+ * INCLUDES
+ ******************************************************************************
+ */
+#include "rfal_platform.h"
+#include "rfal_utils.h"
+#include "rfal_rf.h"
+
+/*
+ ******************************************************************************
+ * C LINKAGE GUARD
+ ******************************************************************************
+ */
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+
+/*
+ ******************************************************************************
+ * ENABLE SWITCH
+ ******************************************************************************
+ */
+
+/* If module is disabled remove the need for the user to set lengths */
+#if !RFAL_FEATURE_NFC_DEP
+ /* PRQA S 0841 2 # MISRA 20.5 - #undef used to ease user defined configuration and memory optimization */ /* PRQA S 0847 2 # MISRA 20.5 - #undef used to ease user defined configuration and memory optimization */
+ #undef RFAL_FEATURE_NFC_DEP_BLOCK_MAX_LEN
+ #undef RFAL_FEATURE_NFC_DEP_PDU_MAX_LEN
+
+ /* MISRA: Some compilers treat an array of length one declared as the final member of a struct as a flexible array member.*/
+ #define RFAL_FEATURE_NFC_DEP_BLOCK_MAX_LEN 2U /*!< NFC-DEP Block/Payload length, set to "none" */
+ #define RFAL_FEATURE_NFC_DEP_PDU_MAX_LEN 2U /*!< NFC-DEP PDU length, set to "none" */
+#endif /* !RFAL_FEATURE_NFC_DEP */
+
+/*
+ ******************************************************************************
+ * DEFINES
+ ******************************************************************************
+ */
+#define RFAL_NFCDEP_FRAME_SIZE_MAX_LEN 254U /*!< Maximum Frame Size Digital 2.0 Table 90 */
+#define RFAL_NFCDEP_DEPREQ_HEADER_LEN 5U /*!< DEP_REQ header length: CMD_TYPE + CMD_CMD + PBF + DID + NAD */
+
+/*! Length NFCIP DEP REQ or RES header (incl LEN) */
+#define RFAL_NFCDEP_DEP_HEADER ( RFAL_NFCDEP_LEN_LEN + RFAL_NFCDEP_CMDTYPE_LEN + RFAL_NFCDEP_CMD_LEN + RFAL_NFCDEP_DEP_PFB_LEN )
+#define RFAL_NFCDEP_HEADER ( RFAL_NFCDEP_CMDTYPE_LEN + RFAL_NFCDEP_CMD_LEN ) /*!< NFCIP header length */
+#define RFAL_NFCDEP_SB_LEN 1U /*!< SB length on NFCIP fram for NFC-A */
+#define RFAL_NFCDEP_LEN_LEN 1U /*!< LEN length on NFCIP frame */
+#define RFAL_NFCDEP_CMDTYPE_LEN 1U /*!< Length of the cmd type (REQ | RES) on NFCIP frame */
+#define RFAL_NFCDEP_CMD_LEN 1U /*!< Length of the cmd on NFCIP frame */
+#define RFAL_NFCDEP_DID_LEN 1U /*!< Length of did on NFCIP frame */
+#define RFAL_NFCDEP_DEP_PFB_LEN 1U /*!< Length of the PFB field on NFCIP frame */
+
+#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 */
+#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 */
+
+#define RFAL_NFCDEP_FS_VAL_MIN 64U /*!< Minimum LR value */
+#define RFAL_NFCDEP_LR_VAL_MASK 0x03U /*!< Bit mask for a LR value */
+#define RFAL_NFCDEP_PP_LR_MASK 0x30U /*!< Bit mask for LR value in PP byte on a ATR REQ/RES */
+#define RFAL_NFCDEP_PP_LR_SHIFT 4U /*!< Position of LR value in PP byte on a ATR REQ/RES */
+
+#define RFAL_NFCDEP_DID_MAX 14U /*!< Max DID value Digital 14.6.2.3 */
+#define RFAL_NFCDEP_DID_KEEP 0xFFU /*!< Keep DID value already configured */
+#define RFAL_NFCDEP_DID_NO 0x00U /*!< No DID shall be used */
+#define RFAL_NFCDEP_NAD_NO 0x00U /*!< No NAD shall be used */
+
+#define RFAL_NFCDEP_OPER_RTOX_REQ_DIS 0x01U /*!< Operation config: RTOX REQ disable */
+#define RFAL_NFCDEP_OPER_RTOX_REQ_EN 0x00U /*!< Operation config: RTOX REQ enable */
+
+#define RFAL_NFCDEP_OPER_ATN_DIS 0x00U /*!< Operation config: ATN disable */
+#define RFAL_NFCDEP_OPER_ATN_EN 0x02U /*!< Operation config: ATN enable */
+
+#define RFAL_NFCDEP_OPER_EMPTY_DEP_DIS 0x04U /*!< Operation config: empty DEPs disable */
+#define RFAL_NFCDEP_OPER_EMPTY_DEP_EN 0x00U /*!< Operation config: empty DEPs enable */
+
+#define RFAL_NFCDEP_OPER_FULL_MI_DIS 0x00U /*!< Operation config: full chaining DEPs disable */
+#define RFAL_NFCDEP_OPER_FULL_MI_EN 0x08U /*!< Operation config: full chaining DEPs enable */
+
+
+#define RFAL_NFCDEP_BRS_MAINTAIN 0xC0U /*!< Value signalling that BR is to be maintained (no PSL) */
+#define RFAL_NFCDEP_BRS_Dx_MASK 0x07U /*!< Value signalling that BR is to be maintained (no PSL) */
+#define RFAL_NFCDEP_BRS_DSI_POS 3U /*!< Value signalling that BR is to be maintained (no PSL) */
+
+#define RFAL_NFCDEP_WT_DELTA (16U - RFAL_NFCDEP_WT_DELTA_ADJUST) /*!< NFC-DEP dWRT (adjusted) Digital 2.0 B.10 */
+#define RFAL_NFCDEP_WT_DELTA_ADJUST 4U /*!< dWRT value adjustment */
+
+
+#define RFAL_NFCDEP_ATR_REQ_NFCID3_POS 2U /*!< NFCID3 offset in ATR_REQ frame */
+#define RFAL_NFCDEP_NFCID3_LEN 10U /*!< NFCID3 Length */
+
+#define RFAL_NFCDEP_LEN_MIN 3U /*!< Minimum length byte LEN value */
+#define RFAL_NFCDEP_LEN_MAX 255U /*!< Maximum length byte LEN value */
+
+#define RFAL_NFCDEP_ATRRES_HEADER_LEN 2U /*!< ATR RES Header Len: CmdType: 0xD5 + Cod: 0x01 */
+#define RFAL_NFCDEP_ATRRES_MIN_LEN 17U /*!< Minimum length for an ATR RES */
+#define RFAL_NFCDEP_ATRRES_MAX_LEN 64U /*!< Maximum length for an ATR RES Digital 1.0 14.6.1 */
+#define RFAL_NFCDEP_ATRREQ_MIN_LEN 16U /*!< Minimum length for an ATR REQ */
+#define RFAL_NFCDEP_ATRREQ_MAX_LEN RFAL_NFCDEP_ATRRES_MAX_LEN /*!< Maximum length for an ATR REQ Digital 1.0 14.6.1 */
+
+#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 */
+
+#define RFAL_NFCDEP_WT_INI_DEFAULT RFAL_NFCDEP_WT_INI_MAX /*!< WT Initiator default value Digital 1.0 14.6.3.8 */
+#define RFAL_NFCDEP_WT_INI_MIN 0U /*!< WT Initiator minimum value Digital 1.0 14.6.3.8 */
+#define RFAL_NFCDEP_WT_INI_MAX 14U /*!< WT Initiator maximum value Digital 1.0 14.6.3.8 A.10 */
+#define RFAL_NFCDEP_RWT_INI_MAX rfalNfcDepWT2RWT( RFAL_NFCDEP_WT_INI_MAX ) /*!< RWT Initiator maximum value */
+
+#define RFAL_NFCDEP_WT_TRG_MAX_D10 8U /*!< WT target max Digital 1.0 14.6.3.8 A.10 */
+#define RFAL_NFCDEP_WT_TRG_MAX_D11 14U /*!< WT target max Digital 1.1 16.6.3.9 A.9 */
+#define RFAL_NFCDEP_WT_TRG_MAX_L13 10U /*!< WT target max [LLCP] 1.3 6.2.1 */
+#define RFAL_NFCDEP_WT_TRG_MAX RFAL_NFCDEP_WT_TRG_MAX_D11 /*!< WT target max Digital x.x | LLCP x.x */
+#define RFAL_NFCDEP_RWT_TRG_MAX rfalNfcDepWT2RWT( RFAL_NFCDEP_WT_TRG_MAX ) /*!< RWT Initiator maximum value */
+
+/*! Maximum Frame Waiting Time = ((256 * 16/fc)*2^FWImax) = ((256*16/fc)*2^14) = (1048576 / 64)/fc = (100000h*64)/fc */
+#define RFAL_NFCDEP_MAX_FWT ((uint32_t)1U<<20)
+
+#define RFAL_NFCDEP_WT_MASK 0x0FU /*!< Bit mask for the Wait Time value */
+
+#define RFAL_NFCDEP_BR_MASK_106 0x01U /*!< Enable mask bit rate 106 */
+#define RFAL_NFCDEP_BR_MASK_212 0x02U /*!< Enable mask bit rate 242 */
+#define RFAL_NFCDEP_BR_MASK_424 0x04U /*!< Enable mask bit rate 424 */
+
+/*
+ ******************************************************************************
+ * GLOBAL MACROS
+ ******************************************************************************
+ */
+
+#define rfalNfcDepWT2RWT( wt ) ( (uint32_t)1U << (((uint32_t)(wt) & RFAL_NFCDEP_WT_MASK) + 12U) ) /*!< Converts WT value to RWT (1/fc) */
+
+/*! Returns the BRS value from the given bit rate */
+#define rfalNfcDepDx2BRS( br ) ( (((uint8_t)(br) & RFAL_NFCDEP_BRS_Dx_MASK) << RFAL_NFCDEP_BRS_DSI_POS) | ((uint8_t)(br) & RFAL_NFCDEP_BRS_Dx_MASK) )
+
+#define rfalNfcDepBRS2DRI( brs ) (uint8_t)( (uint8_t)(brs) & RFAL_NFCDEP_BRS_Dx_MASK ) /*!< Returns the DRI value from the given BRS byte */
+#define rfalNfcDepBRS2DSI( brs ) (uint8_t)( ((uint8_t)(brs) >> RFAL_NFCDEP_BRS_DSI_POS) & RFAL_NFCDEP_BRS_Dx_MASK ) /*!< Returns the DSI_ID value from the given BRS byte */
+
+#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 */
+#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 */
+
+/*! Returns the Frame size value from the given LRx value */
+#define rfalNfcDepLR2FS( LRx ) (uint16_t)(RFAL_MIN( (RFAL_NFCDEP_FS_VAL_MIN * ((uint16_t)(LRx) + 1U) ), RFAL_NFCDEP_FRAME_SIZE_MAX_LEN ))
+
+/*!
+ * Despite DIGITAL 1.0 14.6.2.1 stating that the last two bytes may filled with
+ * any value, some devices (Samsung Google Nexus) only accept when these are 0 */
+#define rfalNfcDepSetNFCID( dst, src, len ) RFAL_MEMSET( (dst), 0x00, RFAL_NFCDEP_NFCID3_LEN ); \
+ if( (len) > 0U ) {RFAL_MEMCPY( (dst), (src), (len) );}
+
+/*
+ ******************************************************************************
+ * GLOBAL ENUMERATIONS
+ ******************************************************************************
+ */
+
+/*! Enumeration of NFC-DEP bit rate in ATR Digital 1.0 Table 93 and 94 */
+enum{
+ RFAL_NFCDEP_Bx_NO_HIGH_BR = 0x00, /*!< Peer supports no high bit rates */
+ RFAL_NFCDEP_Bx_08_848 = 0x01, /*!< Peer also supports 848 */
+ RFAL_NFCDEP_Bx_16_1695 = 0x02, /*!< Peer also supports 1695 */
+ RFAL_NFCDEP_Bx_32_3390 = 0x04, /*!< Peer also supports 3390 */
+ RFAL_NFCDEP_Bx_64_6780 = 0x08 /*!< Peer also supports 6780 */
+};
+
+/*! Enumeration of NFC-DEP bit rate Dividor in PSL Digital 1.0 Table 100 */
+enum{
+ RFAL_NFCDEP_Dx_01_106 = RFAL_BR_106, /*!< Divisor D = 1 : bit rate = 106 */
+ RFAL_NFCDEP_Dx_02_212 = RFAL_BR_212, /*!< Divisor D = 2 : bit rate = 212 */
+ RFAL_NFCDEP_Dx_04_424 = RFAL_BR_424, /*!< Divisor D = 4 : bit rate = 424 */
+ RFAL_NFCDEP_Dx_08_848 = RFAL_BR_848, /*!< Divisor D = 8 : bit rate = 848 */
+ RFAL_NFCDEP_Dx_16_1695 = RFAL_BR_1695, /*!< Divisor D = 16 : bit rate = 1695 */
+ RFAL_NFCDEP_Dx_32_3390 = RFAL_BR_3390, /*!< Divisor D = 32 : bit rate = 3390 */
+ RFAL_NFCDEP_Dx_64_6780 = RFAL_BR_6780 /*!< Divisor D = 64 : bit rate = 6780 */
+};
+
+/*! Enumeration of NFC-DEP Length Reduction (LR) Digital 1.0 Table 91 */
+enum{
+ RFAL_NFCDEP_LR_64 = 0x00, /*!< Maximum payload size is 64 bytes */
+ RFAL_NFCDEP_LR_128 = 0x01, /*!< Maximum payload size is 128 bytes */
+ RFAL_NFCDEP_LR_192 = 0x02, /*!< Maximum payload size is 192 bytes */
+ RFAL_NFCDEP_LR_254 = 0x03 /*!< Maximum payload size is 254 bytes */
+};
+
+/*
+ ******************************************************************************
+ * GLOBAL DATA TYPES
+ ******************************************************************************
+ */
+
+/*! NFC-DEP callback to check if upper layer has deactivation pending */
+typedef bool (* rfalNfcDepDeactCallback)(void);
+
+
+/*! Enumeration of the nfcip communication modes */
+typedef enum{
+ RFAL_NFCDEP_COMM_PASSIVE, /*!< Passive communication mode */
+ RFAL_NFCDEP_COMM_ACTIVE /*!< Active communication mode */
+} rfalNfcDepCommMode;
+
+
+/*! Enumeration of the nfcip roles */
+typedef enum{
+ RFAL_NFCDEP_ROLE_INITIATOR, /*!< Perform as Initiator */
+ RFAL_NFCDEP_ROLE_TARGET /*!< Perform as Target */
+} rfalNfcDepRole;
+
+
+/*! Struct that holds all NFCIP configs */
+typedef struct{
+
+ rfalNfcDepRole role; /*!< Current NFCIP role */
+ rfalNfcDepCommMode commMode; /*!< Current NFCIP communication mode */
+ uint8_t oper; /*!< Operation config similar to NCI 1.0 Table 81 */
+
+ uint8_t did; /*!< Current Device ID (DID) */
+ uint8_t nad; /*!< Current Node Addressing (NAD) */
+ uint8_t bs; /*!< Bit rate in Sending Direction */
+ uint8_t br; /*!< Bit rate in Receiving Direction */
+ uint8_t nfcid[RFAL_NFCDEP_NFCID3_LEN]; /*!< Pointer to the NFCID to be used */
+ uint8_t nfcidLen; /*!< Length of the given NFCID in nfcid */
+ uint8_t gb[RFAL_NFCDEP_GB_MAX_LEN]; /*!< Pointer General Bytes (GB) to be used */
+ uint8_t gbLen; /*!< Length of the given GB in gb */
+ uint8_t lr; /*!< Length Reduction (LR) to be used */
+ uint8_t to; /*!< Timeout (TO) to be used */
+ uint32_t fwt; /*!< Frame Waiting Time (FWT) to be used */
+ uint32_t dFwt; /*!< Delta Frame Waiting Time (dFWT) to be used */
+} rfalNfcDepConfigs;
+
+
+/*! ATR_REQ command Digital 1.1 16.6.2 */
+typedef struct {
+ uint8_t CMD1; /*!< Command format 0xD4 */
+ uint8_t CMD2; /*!< Command Value */
+ uint8_t NFCID3[RFAL_NFCDEP_NFCID3_LEN]; /*!< NFCID3 value */
+ uint8_t DID; /*!< DID */
+ uint8_t BSi; /*!< Sending Bitrate for Initiator */
+ uint8_t BRi; /*!< Receiving Bitrate for Initiator */
+ uint8_t PPi; /*!< Optional Parameters presence indicator */
+ uint8_t GBi[RFAL_NFCDEP_GB_MAX_LEN]; /*!< General Bytes */
+} rfalNfcDepAtrReq;
+
+
+/*! ATR_RES response Digital 1.1 16.6.3 */
+typedef struct {
+ uint8_t CMD1; /*!< Response Byte 0xD5 */
+ uint8_t CMD2; /*!< Command Value */
+ uint8_t NFCID3[RFAL_NFCDEP_NFCID3_LEN]; /*!< NFCID3 value */
+ uint8_t DID; /*!< DID */
+ uint8_t BSt; /*!< Sending Bitrate for Initiator */
+ uint8_t BRt; /*!< Receiving Bitrate for Initiator */
+ uint8_t TO; /*!< Timeout */
+ uint8_t PPt; /*!< Optional Parameters presence indicator */
+ uint8_t GBt[RFAL_NFCDEP_GB_MAX_LEN]; /*!< General Bytes */
+} rfalNfcDepAtrRes;
+
+
+/*! Structure of transmit I-PDU Buffer format from caller */
+typedef struct
+{
+ uint8_t prologue[RFAL_NFCDEP_DEPREQ_HEADER_LEN]; /*!< Prologue space for NFC-DEP header*/
+ uint8_t inf[RFAL_FEATURE_NFC_DEP_BLOCK_MAX_LEN]; /*!< INF | Data area of the buffer */
+} rfalNfcDepBufFormat;
+
+
+/*! Structure of APDU Buffer format from caller */
+typedef struct
+{
+ uint8_t prologue[RFAL_NFCDEP_DEPREQ_HEADER_LEN]; /*!< Prologue/SoD buffer */
+ uint8_t pdu[RFAL_FEATURE_NFC_DEP_PDU_MAX_LEN]; /*!< Complete PDU/Payload buffer */
+} rfalNfcDepPduBufFormat;
+
+
+/*! Activation info as Initiator and Target */
+typedef union { /* PRQA S 0750 # MISRA 19.2 - Both members of the union will not be used concurrently , device is only initiatior or target a time. No problem can occur. */
+ struct {
+ rfalNfcDepAtrRes ATR_RES; /*!< ATR RES (Initiator mode) */
+ uint8_t ATR_RESLen; /*!< ATR RES length (Initiator mode) */
+ }Target; /*!< Target */
+ struct {
+ rfalNfcDepAtrReq ATR_REQ; /*!< ATR REQ (Target mode) */
+ uint8_t ATR_REQLen; /*!< ATR REQ length (Target mode) */
+ }Initiator; /*!< Initiator */
+} rfalNfcDepActivation;
+
+
+/*! NFC-DEP device Info */
+typedef struct {
+ uint8_t GBLen; /*!< General Bytes length */
+ uint8_t WT; /*!< WT to be used (ignored in Listen Mode) */
+ uint32_t FWT; /*!< FWT to be used (1/fc)(ignored Listen Mode) */
+ uint32_t dFWT; /*!< Delta FWT to be used (1/fc) */
+ uint8_t LR; /*!< Length Reduction coding the max payload */
+ uint16_t FS; /*!< Frame Size */
+ rfalBitRate DSI_ID; /*!< Bit Rate coding from Initiator to Target */
+ rfalBitRate DRI; /*!< Bit Rate coding from Target to Initiator */
+ uint8_t DID; /*!< Device ID (RFAL_NFCDEP_DID_NO if no DID) */
+ uint8_t NAD; /*!< Node ADdress (RFAL_NFCDEP_NAD_NO if no NAD)*/
+} rfalNfcDepInfo;
+
+
+/*! NFC-DEP Device structure */
+typedef struct {
+ rfalNfcDepActivation activation; /*!< Activation Info */
+ rfalNfcDepInfo info; /*!< NFC-DEP device Info */
+} rfalNfcDepDevice;
+
+
+/*! NFCIP Protocol structure for P2P Target
+ *
+ * operParam : derives from NFC-Forum NCI NFC-DEP Operation Parameter
+ * NCI 1.1 Table 86: NFC-DEP Operation Parameter
+ * and it's a bit mask composed as:
+ * [ 0000b
+ * | Chain SHALL use max. Transport Data Byte[1b]
+ * | I-PDU with no Transport Data SHALL NOT be sent [1b]
+ * | NFC-DEP Target SHALL NOT send RTOX request [1b]
+ * ]
+ *
+ */
+typedef struct{
+ rfalNfcDepCommMode commMode; /*!< Initiator in Active P2P or Passive P2P*/
+ uint8_t operParam; /*!< NFC-DEP Operation Parameter */
+ uint8_t* nfcid; /*!< Initiator's NFCID2 or NFCID3 */
+ uint8_t nfcidLen; /*!< Initiator's NFCID length (NFCID2/3) */
+ uint8_t DID; /*!< Initiator's Device ID DID */
+ uint8_t NAD; /*!< Initiator's Node ID NAD */
+ uint8_t BS; /*!< Initiator's Bit Rates supported in Tx */
+ uint8_t BR; /*!< Initiator's Bit Rates supported in Rx */
+ uint8_t LR; /*!< Initiator's Length reduction */
+ uint8_t* GB; /*!< Initiator's General Bytes (Gi) */
+ uint8_t GBLen; /*!< Initiator's General Bytes length */
+} rfalNfcDepAtrParam;
+
+
+/*! Structure of parameters to be passed in for nfcDepListenStartActivation */
+typedef struct
+{
+ rfalNfcDepBufFormat *rxBuf; /*!< Receive Buffer struct reference */
+ uint16_t *rxLen; /*!< Receive INF data length in bytes */
+ bool *isRxChaining; /*!< Received data is not complete */
+ rfalNfcDepDevice *nfcDepDev; /*!< NFC-DEP device info */
+} rfalNfcDepListenActvParam;
+
+
+/*! NFCIP Protocol structure for P2P Target
+ *
+ * operParam : derives from NFC-Forum NCI NFC-DEP Operation Parameter
+ * NCI 1.1 Table 86: NFC-DEP Operation Parameter
+ * and it's a bit mask composed as:
+ * [ 0000b
+ * | Chain SHALL use max. Transport Data Byte[1b]
+ * | I-PDU with no Transport Data SHALL NOT be sent [1b]
+ * | NFC-DEP Target SHALL NOT send RTOX request [1b]
+ * ]
+ *
+ */
+typedef struct{
+ rfalNfcDepCommMode commMode; /*!< Target in Active P2P or Passive P2P */
+ uint8_t nfcid3[RFAL_NFCDEP_NFCID3_LEN]; /*!< Target's NFCID3 */
+ uint8_t bst; /*!< Target's Bit Rates supported in Tx */
+ uint8_t brt; /*!< Target's Bit Rates supported in Rx */
+ uint8_t to; /*!< Target's timeout (TO) value */
+ uint8_t ppt; /*!< Target's Presence optional Params(PPt)*/
+ uint8_t GBt[RFAL_NFCDEP_GB_MAX_LEN]; /*!< Target's General Bytes (Gt) */
+ uint8_t GBtLen; /*!< Target's General Bytes length */
+ uint8_t operParam; /*!< NFC-DEP Operation Parameter */
+} rfalNfcDepTargetParam;
+
+
+/*! Structure of parameters to be passed in for nfcDepStartIpduTransceive */
+typedef struct
+{
+ rfalNfcDepBufFormat *txBuf; /*!< Transmit Buffer struct reference */
+ uint16_t txBufLen; /*!< Transmit Buffer INF field length in bytes */
+ bool isTxChaining; /*!< Transmit data is not complete */
+ rfalNfcDepBufFormat *rxBuf; /*!< Receive Buffer struct reference */
+ uint16_t *rxLen; /*!< Receive INF data length */
+ bool *isRxChaining; /*!< Received data is not complete */
+ uint32_t FWT; /*!< FWT to be used (ignored in Listen Mode) */
+ uint32_t dFWT; /*!< Delta FWT to be used */
+ uint16_t FSx; /*!< Other device Frame Size (FSD or FSC) */
+ uint8_t DID; /*!< Device ID (RFAL_ISODEP_NO_DID if no DID) */
+} rfalNfcDepTxRxParam;
+
+
+/*! Structure of parameters used on NFC DEP PDU Transceive */
+typedef struct
+{
+ rfalNfcDepPduBufFormat *txBuf; /*!< Transmit Buffer struct reference */
+ uint16_t txBufLen; /*!< Transmit Buffer INF field length in Bytes*/
+ rfalNfcDepPduBufFormat *rxBuf; /*!< Receive Buffer struct reference in Bytes */
+ uint16_t *rxLen; /*!< Received INF data length in Bytes */
+ rfalNfcDepBufFormat *tmpBuf; /*!< Temp buffer for single PDUs (internal) */
+ uint32_t FWT; /*!< FWT to be used (ignored in Listen Mode) */
+ uint32_t dFWT; /*!< Delta FWT to be used */
+ uint16_t FSx; /*!< Other device Frame Size (FSD or FSC) */
+ uint8_t DID; /*!< Device ID (RFAL_ISODEP_NO_DID if no DID) */
+} rfalNfcDepPduTxRxParam;
+
+
+/*
+ * *****************************************************************************
+ * GLOBAL VARIABLE DECLARATIONS
+ ******************************************************************************
+ */
+
+
+/*
+ ******************************************************************************
+ * GLOBAL FUNCTION PROTOTYPES
+ ******************************************************************************
+ */
+
+/*!
+ ******************************************************************************
+ * \brief NFCIP Initialize
+ *
+ * This method resets all NFC-DEP inner states, counters and context and sets
+ * default values
+ *
+ ******************************************************************************
+ */
+void rfalNfcDepInitialize( void );
+
+
+/*!
+ ******************************************************************************
+ * \brief Set deactivating callback
+ *
+ * Sets the deactivating callback so that nfcip layer can check if upper layer
+ * has a deactivation pending, and not perform error recovery upon specific
+ * errors
+ *
+ * \param[in] pFunc : method pointer to deactivation flag check
+ ******************************************************************************
+ */
+void rfalNfcDepSetDeactivatingCallback( rfalNfcDepDeactCallback pFunc );
+
+
+/*!
+ ******************************************************************************
+ * \brief Calculate Response Waiting Time
+ *
+ * Calculates the Response Waiting Time (RWT) from the given Waiting Time (WT)
+ *
+ * \param[in] wt : the WT value to calculate RWT
+ *
+ * \return RWT value in 1/fc
+ ******************************************************************************
+ */
+uint32_t rfalNfcDepCalculateRWT( uint8_t wt );
+
+
+/*!
+ ******************************************************************************
+ * \brief NFC-DEP Initiator ATR (Attribute Request)
+ *
+ * This method configures the NFC-DEP layer with given parameters and then
+ * sends an ATR to the Target with and checks for a valid response response
+ *
+ * \param[in] param : parameters to initialize and compose the ATR
+ * \param[out] atrRes : location to store the ATR_RES
+ * \param[out] atrResLen : length of the ATR_RES received
+ *
+ * \return RFAL_ERR_NONE : No error
+ * \return RFAL_ERR_TIMEOUT : Timeout occurred
+ * \return RFAL_ERR_PROTO : Protocol error occurred
+ ******************************************************************************
+ */
+ReturnCode rfalNfcDepATR( const rfalNfcDepAtrParam* param, rfalNfcDepAtrRes *atrRes, uint8_t* atrResLen );
+
+
+/*!
+ ******************************************************************************
+ * \brief NFC-DEP Initiator PSL (Parameter Selection)
+ *
+ * This method sends a PSL to the Target with the given parameters and checks
+ * for a valid response response
+ *
+ * The parameters must be coded according to Digital 1.1 16.7.1
+ *
+ * \param[in] BRS : the selected Bit Rates for Initiator and Target
+ * \param[in] FSL : the maximum length of Commands and Responses
+ *
+ * \return RFAL_ERR_NONE : No error
+ * \return RFAL_ERR_TIMEOUT : Timeout occurred
+ * \return RFAL_ERR_PROTO : Protocol error occurred
+ ******************************************************************************
+ */
+ReturnCode rfalNfcDepPSL( uint8_t BRS, uint8_t FSL );
+
+
+/*!
+ ******************************************************************************
+ * \brief NFC-DEP Initiator DSL (Deselect)
+ *
+ * This method checks if the NFCIP module is configured as initiator and if
+ * so sends a DSL REQ, waits the target's response and checks it
+ *
+ * In case of performing as target no action is taken
+ *
+ * \return RFAL_ERR_NONE : No error
+ * \return RFAL_ERR_TIMEOUT : Timeout occurred
+ * \return RFAL_ERR_MAX_RERUNS : Timeout occurred
+ * \return RFAL_ERR_PROTO : Protocol error occurred
+ ******************************************************************************
+ */
+ReturnCode rfalNfcDepDSL( void );
+
+
+/*!
+ ******************************************************************************
+ * \brief NFC-DEP Initiator RLS (Release)
+ *
+ * This method checks if the NFCIP module is configured as initiator and if
+ * so sends a RLS REQ, waits target's response and checks it
+ *
+ * In case of performing as target no action is taken
+ *
+ * \return RFAL_ERR_NONE : No error
+ * \return RFAL_ERR_TIMEOUT : Timeout occurred
+ * \return RFAL_ERR_MAX_RERUNS : Timeout occurred
+ * \return RFAL_ERR_PROTO : Protocol error occurred
+ ******************************************************************************
+ */
+ReturnCode rfalNfcDepRLS( void );
+
+
+/*!
+ *****************************************************************************
+ * \brief NFC-DEP Initiator Handle Activation
+ *
+ * This performs a Activation into NFC-DEP layer with the given
+ * parameters. It sends ATR_REQ and if the higher bit rates are supported by
+ * both devices it additionally sends PSL
+ * Once Activated all details of the device are provided on nfcDepDev
+ *
+ * \param[in] param : required parameters to initialize and send ATR_REQ
+ * \param[in] desiredBR : Desired bit rate supported by the Poller
+ * \param[out] nfcDepDev : NFC-DEP information of the activated Listen device
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_TIMEOUT : Timeout error
+ * \return RFAL_ERR_PAR : Parity error detected
+ * \return RFAL_ERR_CRC : CRC error detected
+ * \return RFAL_ERR_FRAMING : Framing error detected
+ * \return RFAL_ERR_PROTO : Protocol error detected
+ * \return RFAL_ERR_NONE : No error, activation successful
+ *****************************************************************************
+ */
+ReturnCode rfalNfcDepInitiatorHandleActivation( rfalNfcDepAtrParam* param, rfalBitRate desiredBR, rfalNfcDepDevice* nfcDepDev );
+
+
+/*!
+ ******************************************************************************
+ * \brief Check if buffer contains valid ATR_REQ
+ *
+ * This method checks if the given ATR_REQ is valid
+ *
+ *
+ * \param[in] buf : buffer holding Initiator's received request
+ * \param[in] bufLen : size of the msg contained on the buf in Bytes
+ * \param[out] nfcid3 : pointer to where the NFCID3 may be outputed,
+ * nfcid3 has NFCF_SENSF_NFCID3_LEN as length
+ * Pass NULL if output parameter not desired
+ *
+ * \return true : Valid ATR_REQ received, the ATR_RES has been computed in txBuf
+ * \return false : Invalid protocol request
+ *
+ ******************************************************************************
+ */
+bool rfalNfcDepIsAtrReq( const uint8_t* buf, uint16_t bufLen, uint8_t* nfcid3 );
+
+
+/*!
+ ******************************************************************************
+ * \brief Check is Target has received ATR
+ *
+ * This method checks if the NFCIP module is configured as target and if a
+ * ATR REQ has been received ( whether is in activation or in data exchange)
+ *
+ * \return true : a ATR has already been received
+ * \return false : no ATR has been received
+ ******************************************************************************
+ */
+bool rfalNfcDepTargetRcvdATR( void );
+
+/*!
+ *****************************************************************************
+ * \brief NFCDEP Start Listen Activation Handling
+ *
+ * Start Activation Handling and setup to receive first frame which may
+ * contain complete or partial DEP-REQ after activation is completed
+ *
+ * Pass in ATR_REQ for NFC-DEP to handle ATR_RES. The Activation Handling
+ * handles ATR_RES and PSL_RES if a PSL_REQ is received
+ *
+ * Activation is completed if PSL_RES is sent or if first I-PDU is received
+ *
+ * \ref rfalNfcDepListenGetActivationStatus() provide status of the
+ * ongoing activation
+ *
+ * \warning nfcDepGetTransceiveStatus() shall be called right after activation
+ * is completed (i.e. rfalNfcDepListenGetActivationStatus() return RFAL_ERR_NONE)
+ * to check for first received frame.
+ *
+ * \param[in] param : Target parameters to be used
+ * \param[in] atrReq : reference to buffer containing ATR_REQ
+ * \param[in] atrReqLength: Length of ATR_REQ
+ * \param[out] rxParam : references to buffer, length and chaining indication
+ * for first complete LLCP to be received
+ *
+ * \return RFAL_ERR_NONE : ATR_REQ is valid and activation ongoing
+ * \return RFAL_ERR_PARAM : ATR_REQ or other params are invalid
+ * \return RFAL_ERR_LINK_LOSS : Remote Field is turned off
+ *****************************************************************************
+ */
+ReturnCode rfalNfcDepListenStartActivation( const rfalNfcDepTargetParam *param, const uint8_t *atrReq, uint16_t atrReqLength, rfalNfcDepListenActvParam rxParam );
+
+
+/*!
+ *****************************************************************************
+ * \brief Get the current NFC-DEP Activation Status
+ *
+ * \return RFAL_ERR_NONE : Activation has completed successfully
+ * \return RFAL_ERR_BUSY : Activation is ongoing
+ * \return RFAL_ERR_LINK_LOSS : Remote Field was turned off
+ *****************************************************************************
+ */
+ReturnCode rfalNfcDepListenGetActivationStatus( void );
+
+/*!
+ *****************************************************************************
+ * \brief Start Transceive
+ *
+ * Transceives a complete or partial DEP block
+ *
+ * The txBuf contains complete or partial of DEP to be transmitted.
+ * The Prologue field of the I-PDU is handled internally
+ *
+ * If the buffer contains partial LLCP and is not the last block, then
+ * isTxChaining must be set to true
+ *
+ * \param[in] param: reference parameters to be used for the Transceive
+ *
+ * \return RFAL_ERR_PARAM : Bad request
+ * \return RFAL_ERR_WRONG_STATE : The module is not in a proper state
+ * \return RFAL_ERR_NONE : The Transceive request has been started
+ *****************************************************************************
+ */
+ReturnCode rfalNfcDepStartTransceive( const rfalNfcDepTxRxParam *param );
+
+
+/*!
+ *****************************************************************************
+ * \brief Return the Transceive status
+ *
+ * Returns the status of the NFC-DEP Transceive
+ *
+ * \warning When the other device is performing chaining once a chained
+ * block is received the error RFAL_ERR_AGAIN is sent. At this point
+ * caller must handle the received data immediately.
+ * When RFAL_ERR_AGAIN is returned an ACK has already been sent to
+ * the other device and the next block might be incoming.
+ * If rfalWorker() is called frequently it will place the next
+ * block on the given buffer
+ *
+ * \return RFAL_ERR_NONE : Transceive has been completed successfully
+ * \return RFAL_ERR_BUSY : Transceive is ongoing
+ * \return RFAL_ERR_PROTO : Protocol error occurred
+ * \return RFAL_ERR_TIMEOUT : Timeout error occurred
+ * \return RFAL_ERR_SLEEP_REQ : Deselect has been received and responded
+ * \return RFAL_ERR_NOMEM : The received I-PDU does not fit into the
+ * receive buffer
+ * \return RFAL_ERR_LINK_LOSS : Communication is lost because Reader/Writer
+ * has turned off its field
+ * \return RFAL_ERR_AGAIN : received one chaining block, continue to call
+ * this method to retrieve the remaining blocks
+ *****************************************************************************
+ */
+ReturnCode rfalNfcDepGetTransceiveStatus( void );
+
+
+/*!
+ *****************************************************************************
+ * \brief Start PDU Transceive
+ *
+ * This method triggers a NFC-DEP Transceive containing a complete PDU
+ * It transmits the given message and handles all protocol retransmissions,
+ * error handling and control messages
+ *
+ * The txBuf contains a complete PDU to be transmitted
+ * The Prologue field will be manipulated by the Transceive
+ *
+ * \warning the txBuf will be modified during the transmission
+ * \warning the maximum RF frame which can be received is limited by param.tmpBuf
+ *
+ * \param[in] param: reference parameters to be used for the Transceive
+ *
+ * \return RFAL_ERR_PARAM : Bad request
+ * \return RFAL_ERR_WRONG_STATE : The module is not in a proper state
+ * \return RFAL_ERR_NONE : The Transceive request has been started
+ *****************************************************************************
+ */
+ReturnCode rfalNfcDepStartPduTransceive( rfalNfcDepPduTxRxParam param );
+
+
+/*!
+ *****************************************************************************
+ * \brief Return the PDU Transceive status
+ *
+ * Returns the status of the NFC-DEP PDU Transceive
+ *
+ *
+ * \return RFAL_ERR_NONE : Transceive has been completed successfully
+ * \return RFAL_ERR_BUSY : Transceive is ongoing
+ * \return RFAL_ERR_PROTO : Protocol error occurred
+ * \return RFAL_ERR_TIMEOUT : Timeout error occurred
+ * \return RFAL_ERR_SLEEP_REQ : Deselect has been received and responded
+ * \return RFAL_ERR_NOMEM : The received I-PDU does not fit into the
+ * receive buffer
+ * \return RFAL_ERR_LINK_LOSS : Communication is lost because Reader/Writer
+ * has turned off its field
+ *****************************************************************************
+ */
+ReturnCode rfalNfcDepGetPduTransceiveStatus( void );
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* RFAL_NFCDEP_H_ */
+
+/**
+ * @}
+ *
+ * @}
+ *
+ * @}
+ */
### core/embed/io/nfc/st25/rfal002/include/rfal_nfca.h
@@ -1,574 +1,591 @@
-
-/******************************************************************************
- * @attention
- *
- * COPYRIGHT 2016 STMicroelectronics, all rights reserved
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
- * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
-******************************************************************************/
-
-
-/*
- * PROJECT: ST25R firmware
- * Revision:
- * LANGUAGE: ISO C99
- */
-
-/*! \file rfal_nfca.h
- *
- * \author Gustavo Patricio
- *
- * \brief Provides several NFC-A convenience methods and definitions
- *
- * It provides a Poller (ISO14443A PCD) interface as well as
- * some NFC-A Listener (ISO14443A PICC) helpers.
- *
- * The definitions and helper methods provided by this module are only
- * up to ISO14443-3 layer
- *
- *
- * An usage example is provided here: \ref exampleRfalNfca.c
- * \example exampleRfalNfca.c
- *
- *
- * \addtogroup RFAL
- * @{
- *
- * \addtogroup RFAL-AL
- * \brief RFAL Abstraction Layer
- * @{
- *
- * \addtogroup NFC-A
- * \brief RFAL NFC-A Module
- * @{
- *
- */
-
-
-#ifndef RFAL_NFCA_H
-#define RFAL_NFCA_H
-
-/*
- ******************************************************************************
- * INCLUDES
- ******************************************************************************
- */
-#include "rfal_platform.h"
-#include "rfal_utils.h"
-#include "rfal_rf.h"
-#include "rfal_t1t.h"
-
-/*
- ******************************************************************************
- * GLOBAL DEFINES
- ******************************************************************************
- */
-
-#define RFAL_NFCA_CASCADE_1_UID_LEN 4U /*!< UID length of cascade level 1 only tag */
-#define RFAL_NFCA_CASCADE_2_UID_LEN 7U /*!< UID length of cascade level 2 only tag */
-#define RFAL_NFCA_CASCADE_3_UID_LEN 10U /*!< UID length of cascade level 3 only tag */
-
-#define RFAL_NFCA_SENS_RES_PLATFORM_MASK 0x0FU /*!< SENS_RES (ATQA) platform configuration mask Digital 1.1 Table 10 */
-#define RFAL_NFCA_SENS_RES_PLATFORM_T1T 0x0CU /*!< SENS_RES (ATQA) T1T platform configuration Digital 1.1 Table 10 */
-
-#define RFAL_NFCA_SEL_RES_CONF_MASK 0x60U /*!< SEL_RES (SAK) platform configuration mask Digital 1.1 Table 19 */
-#define RFAL_NFCA_SEL_RES_CONF_T2T 0x00U /*!< SEL_RES (SAK) T2T configuration Digital 1.1 Table 19 */
-#define RFAL_NFCA_SEL_RES_CONF_T4T 0x20U /*!< SEL_RES (SAK) T4T configuration Digital 1.1 Table 19 */
-#define RFAL_NFCA_SEL_RES_CONF_NFCDEP 0x40U /*!< SEL_RES (SAK) NFC-DEP configuration Digital 1.1 Table 19 */
-#define RFAL_NFCA_SEL_RES_CONF_T4T_NFCDEP 0x60U /*!< SEL_RES (SAK) T4T and NFC-DEP configuration Digital 1.1 Table 19 */
-
-
-/*! NFC-A minimum FDT(listen) = ((n * 128 + (84)) / fc) with n_min = 9 Digital 1.1 6.10.1
- * = (1236)/fc
- * Relax with 3etu: (3*128)/fc as with multiple NFC-A cards, response may take longer (JCOP cards)
- * = (1236 + 384)/fc = 1620 / fc */
-#define RFAL_NFCA_FDTMIN 1620U
-/*
- ******************************************************************************
- * GLOBAL MACROS
- ******************************************************************************
- */
-
-/*! Checks if device is a T1T given its SENS_RES */
-#define rfalNfcaIsSensResT1T( sensRes ) ((((rfalNfcaSensRes*)(sensRes))->platformInfo & RFAL_NFCA_SENS_RES_PLATFORM_MASK) == RFAL_NFCA_SENS_RES_PLATFORM_T1T )
-
-/*! Checks if device is a T2T given its SENS_RES */
-#define rfalNfcaIsSelResT2T( selRes ) ((((rfalNfcaSelRes*)(selRes))->sak & RFAL_NFCA_SEL_RES_CONF_MASK) == RFAL_NFCA_SEL_RES_CONF_T2T )
-
-/*! Checks if device is a T4T given its SENS_RES */
-#define rfalNfcaIsSelResT4T( selRes ) ((((rfalNfcaSelRes*)(selRes))->sak & RFAL_NFCA_SEL_RES_CONF_MASK) == RFAL_NFCA_SEL_RES_CONF_T4T )
-
-/*! Checks if device supports NFC-DEP protocol given its SENS_RES */
-#define rfalNfcaIsSelResNFCDEP( selRes ) ((((rfalNfcaSelRes*)(selRes))->sak & RFAL_NFCA_SEL_RES_CONF_MASK) == RFAL_NFCA_SEL_RES_CONF_NFCDEP )
-
-/*! Checks if device supports ISO-DEP and NFC-DEP protocol given its SENS_RES */
-#define rfalNfcaIsSelResT4TNFCDEP( selRes ) ((((rfalNfcaSelRes*)(selRes))->sak & RFAL_NFCA_SEL_RES_CONF_MASK) == RFAL_NFCA_SEL_RES_CONF_T4T_NFCDEP )
-
-/*! Checks if a NFC-A listener device supports multiple protocols (ISO-DEP and NFC-DEP) */
-#define rfalNfcaLisDevIsMultiProto( lisDev ) (((rfalNfcaListenDevice*)(lisDev))->type == RFAL_NFCA_T4T_NFCDEP )
-
-/*
-******************************************************************************
-* GLOBAL TYPES
-******************************************************************************
-*/
-
-/*! NFC-A Listen device types */
-typedef enum {
- RFAL_NFCA_T1T = 0x01, /* Device configured for T1T Digital 1.1 Table 9 */
- RFAL_NFCA_T2T = 0x00, /* Device configured for T2T Digital 1.1 Table 19 */
- RFAL_NFCA_T4T = 0x20, /* Device configured for T4T Digital 1.1 Table 19 */
- RFAL_NFCA_NFCDEP = 0x40, /* Device configured for NFC-DEP Digital 1.1 Table 19 */
- RFAL_NFCA_T4T_NFCDEP = 0x60 /* Device configured for NFC-DEP and T4T Digital 1.1 Table 19 */
-} rfalNfcaListenDeviceType;
-
-
-/*! SENS_RES (ATQA) format Digital 1.1 6.6.3 & Table 7 */
-typedef struct
-{
- uint8_t anticollisionInfo; /*!< SENS_RES Anticollision Information */
- uint8_t platformInfo; /*!< SENS_RES Platform Information */
-} rfalNfcaSensRes;
-
-
-/*! SDD_REQ (Anticollision) format Digital 1.1 6.7.1 & Table 11 */
-typedef struct
-{
- uint8_t selCmd; /*!< SDD_REQ SEL_CMD: cascade Level */
- uint8_t selPar; /*!< SDD_REQ SEL_PAR: Byte Count[4b] | Bit Count[4b] (NVB: Number of Valid Bits)*/
-} rfalNfcaSddReq;
-
-
-/*! SDD_RES (UID CLn) format Digital 1.1 6.7.2 & Table 15 */
-typedef struct
-{
- uint8_t nfcid1[RFAL_NFCA_CASCADE_1_UID_LEN]; /*!< NFCID1 cascade level NFCID */
- uint8_t bcc; /*!< BCC Exclusive-OR over first 4 bytes of SDD_RES */
-} rfalNfcaSddRes;
-
-
-/*! SEL_REQ (Select) format Digital 1.1 6.8.1 & Table 17 */
-typedef struct
-{
- uint8_t selCmd; /*!< SDD_REQ SEL_CMD: cascade Level */
- uint8_t selPar; /*!< SDD_REQ SEL_PAR: Byte Count[4b] | Bit Count[4b] (NVB: Number of Valid Bits)*/
- uint8_t nfcid1[RFAL_NFCA_CASCADE_1_UID_LEN]; /*!< NFCID1 data */
- uint8_t bcc; /*!< Checksum calculated as exclusive-OR over the 4 bytes of NFCID1 CLn */
-} rfalNfcaSelReq;
-
-
-/*! SEL_RES (SAK) format Digital 1.1 6.8.2 & Table 19 */
-typedef struct
-{
- uint8_t sak; /*!< Select Acknowledge */
-} rfalNfcaSelRes;
-
-
-/*! NFC-A listener device (PICC) struct */
-typedef struct
-{
- rfalNfcaListenDeviceType type; /*!< NFC-A Listen device type */
- rfalNfcaSensRes sensRes; /*!< SENS_RES (ATQA) */
- rfalNfcaSelRes selRes; /*!< SEL_RES (SAK) */
- uint8_t nfcId1Len; /*!< NFCID1 Length */
- uint8_t nfcId1[RFAL_NFCA_CASCADE_3_UID_LEN]; /*!< NFCID1 (UID) */
-#ifdef RFAL_FEATURE_T1T
- rfalT1TRidRes ridRes; /*!< RID_RES */
-#endif /* RFAL_FEATURE_T1T */
- bool isSleep; /*!< Device sleeping flag */
-} rfalNfcaListenDevice;
-
-/*
-******************************************************************************
-* GLOBAL FUNCTION PROTOTYPES
-******************************************************************************
-*/
-
-/*!
- *****************************************************************************
- * \brief Initialize NFC-A Poller mode
- *
- * This methods configures RFAL RF layer to perform as a
- * NFC-A Poller/RW (ISO14443A PCD) including all default timings and bit rate
- * to 106 kbps
-
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or mode not set
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalNfcaPollerInitialize( void );
-
-
-/*!
- *****************************************************************************
- * \brief NFC-A Poller Check Presence
- *
- * This method checks if a NFC-A Listen device (PICC) is present on the field
- * by sending an ALL_REQ (WUPA) or SENS_REQ (REQA)
- *
- * \param[in] cmd : Indicate if to send an ALL_REQ or a SENS_REQ
- * \param[out] sensRes : If received, the SENS_RES
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_RF_COLLISION : Collision detected one or more device in the field
- * \return RFAL_ERR_PAR : Parity error detected, one or more device in the field
- * \return RFAL_ERR_CRC : CRC error detected, one or more device in the field
- * \return RFAL_ERR_FRAMING : Framing error detected, one or more device in the field
- * \return RFAL_ERR_PROTO : Protocol error detected, one or more device in the field
- * \return RFAL_ERR_TIMEOUT : Timeout error, no listener device detected
- * \return RFAL_ERR_NONE : No error, one or more device in the field
- *****************************************************************************
- */
-ReturnCode rfalNfcaPollerCheckPresence( rfal14443AShortFrameCmd cmd, rfalNfcaSensRes *sensRes );
-
-
-/*!
- *****************************************************************************
- * \brief NFC-A Poller Select
- *
- * This method selects a NFC-A Listener device (PICC)
- *
- * \param[in] nfcid1 : Listener device NFCID1 to be selected
- * \param[in] nfcidLen : Length of the NFCID1 to be selected
- * \param[out] selRes : pointer to place the SEL_RES
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_TIMEOUT : Timeout error
- * \return RFAL_ERR_PAR : Parity error detected
- * \return RFAL_ERR_CRC : CRC error detected
- * \return RFAL_ERR_FRAMING : Framing error detected
- * \return RFAL_ERR_PROTO : Protocol error detected
- * \return RFAL_ERR_NONE : No error, SEL_RES received
- *****************************************************************************
- */
-ReturnCode rfalNfcaPollerSelect( const uint8_t *nfcid1, uint8_t nfcidLen, rfalNfcaSelRes *selRes );
-
-
-/*!
- *****************************************************************************
- * \brief NFC-A Poller Start Select
- *
- * This method starts the selection of a NFC-A Listener device (PICC)
- *
- * \param[in] nfcid1 : Listener device NFCID1 to be selected
- * \param[in] nfcidLen : Length of the NFCID1 to be selected
- * \param[out] selRes : pointer to place the SEL_RES
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_TIMEOUT : Timeout error
- * \return RFAL_ERR_PAR : Parity error detected
- * \return RFAL_ERR_CRC : CRC error detected
- * \return RFAL_ERR_FRAMING : Framing error detected
- * \return RFAL_ERR_PROTO : Protocol error detected
- * \return RFAL_ERR_NONE : No error, SEL_RES received
- *****************************************************************************
- */
-ReturnCode rfalNfcaPollerStartSelect( const uint8_t *nfcid1, uint8_t nfcidLen, rfalNfcaSelRes *selRes );
-
-
-/*!
- *****************************************************************************
- * \brief NFC-A Poller Get Select Status
- *
- * This method gets the selection status
- *
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_TIMEOUT : Timeout error
- * \return RFAL_ERR_PAR : Parity error detected
- * \return RFAL_ERR_CRC : CRC error detected
- * \return RFAL_ERR_FRAMING : Framing error detected
- * \return RFAL_ERR_PROTO : Protocol error detected
- * \return RFAL_ERR_NONE : No error, SEL_RES received
- *****************************************************************************
- */
-ReturnCode rfalNfcaPollerGetSelectStatus( void );
-
-
-/*!
- *****************************************************************************
- * \brief NFC-A Poller Sleep
- *
- * This method sends a SLP_REQ (HLTA)
- * No response is expected afterwards Digital 1.1 6.9.2.1
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalNfcaPollerSleep( void );
-
-
-/*!
- *****************************************************************************
- * \brief NFC-A Poller Start Sleep
- *
- * This method sends a SLP_REQ (HLTA)
- * No response is expected afterwards Digital 1.1 6.9.2.1
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalNfcaPollerStartSleep( void );
-
-
-/*!
- *****************************************************************************
- * \brief NFC-A Poller Get Sleep Status
- *
- * Returns the Sleep status
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalNfcaPollerGetSleepStatus( void );
-
-
-/*!
- *****************************************************************************
- * \brief NFC-A Technology Detection
- *
- * This method performs NFC-A Technology Detection as defined in the spec
- * given in the compliance mode
- *
- * \param[in] compMode : compliance mode to be performed
- * \param[out] sensRes : location to store the SENS_RES, if received
- *
- * When compMode is set to ISO compliance a SLP_REQ (HLTA) is not sent
- * after detection. When set to EMV a ALL_REQ (WUPA) is sent instead of
- * a SENS_REQ (REQA)
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_NONE : No error, one or more device in the field
- *****************************************************************************
- */
-ReturnCode rfalNfcaPollerTechnologyDetection( rfalComplianceMode compMode, rfalNfcaSensRes *sensRes );
-
-
-/*!
- *****************************************************************************
- * \brief NFC-A Start Technology Detection
- *
- * This method starts NFC-A Technology Detection as defined in the spec
- * given in the compliance mode
- *
- * \param[in] compMode : compliance mode to be performed
- * \param[out] sensRes : location to store the SENS_RES, if received
- *
- * When compMode is set to ISO compliance a SLP_REQ (HLTA) is not sent
- * after detection. When set to EMV a ALL_REQ (WUPA) is sent instead of
- * a SENS_REQ (REQA)
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_NONE : No error, one or more device in the field
- *****************************************************************************
- */
-ReturnCode rfalNfcaPollerStartTechnologyDetection( rfalComplianceMode compMode, rfalNfcaSensRes *sensRes );
-
-
-/*!
- *****************************************************************************
- * \brief NFC-A Get Technology Detection Status
- *
- * Returns the Technology Detection status
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_NONE : No error, one or more device in the field
- *****************************************************************************
- */
-ReturnCode rfalNfcaPollerGetTechnologyDetectionStatus( void );
-
-
-/*!
- *****************************************************************************
- * \brief NFC-A Poller Collision Resolution
- *
- * Collision resolution for one NFC-A Listener device/card (PICC) as
- * defined in Activity 2.1 9.3.4
- *
- * This method executes anti collision loop and select the device with higher NFCID1
- *
- * When devLimit = 0 it is configured to perform collision detection only. Once a collision
- * is detected the collision resolution is aborted immidiatly. If only one device is found
- * with no collisions, it will properly resolved.
- *
- * \param[in] devLimit : device limit value (CON_DEVICES_LIMIT)
- * \param[out] collPending : pointer to collision pending flag (INT_COLL_PEND)
- * \param[out] selRes : location to store the last Select Response from listener device (PICC)
- * \param[out] nfcId1 : location to store the NFCID1 (UID), ensure RFAL_NFCA_CASCADE_3_UID_LEN
- * \param[out] nfcId1Len : pointer to length of NFCID1 (UID)
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or mode not set
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_PROTO : Card length invalid
- * \return RFAL_ERR_IGNORE : conDevLimit is 0 and there is a collision
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalNfcaPollerSingleCollisionResolution( uint8_t devLimit, bool *collPending, rfalNfcaSelRes *selRes, uint8_t *nfcId1, uint8_t *nfcId1Len );
-
-
-/*!
- *****************************************************************************
- * \brief NFC-A Poller Full Collision Resolution
- *
- * Performs a full Collision resolution as defined in Activity 2.1 9.3.4
- *
- * \param[in] compMode : compliance mode to be performed
- * \param[in] devLimit : device limit value, and size nfcaDevList
- * \param[out] nfcaDevList : NFC-A listener device info
- * \param[out] devCnt : Devices found counter
- *
- * When compMode is set to ISO compliance it assumes that the device is
- * not sleeping and therefore no ALL_REQ (WUPA) is sent at the beginning.
- * When compMode is set to NFC compliance an additional ALL_REQ (WUPA) is sent
- * at the beginning.
- *
- *
- * When devLimit = 0 it is configured to perform collision detection only. Once a collision
- * is detected the collision resolution is aborted immidiatly. If only one device is found
- * with no collisions, it will properly resolved.
- *
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or mode not set
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalNfcaPollerFullCollisionResolution( rfalComplianceMode compMode, uint8_t devLimit, rfalNfcaListenDevice *nfcaDevList, uint8_t *devCnt );
-
-
-/*!
- *****************************************************************************
- * \brief NFC-A Poller Full Collision Resolution with Sleep
- *
- * Performs a full Collision resolution similar to rfalNfcaPollerFullCollisionResolution
- * but an additional SLP_REQ (HLTA) -> SENS_RES (REQA) is sent regardless if there
- * was a collision.
- * This proprietary behaviour ensures proper activation of certain devices that suffer
- * from influence of Type B commands as foreseen in ISO14443-3 5.2.3 or were somehow
- * not detected by the first round of collision resolution
- *
- * \param[in] devLimit : device limit value, and size nfcaDevList
- * \param[out] nfcaDevList : NFC-A listener device info
- * \param[out] devCnt : Devices found counter
- *
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or mode not set
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalNfcaPollerSleepFullCollisionResolution( uint8_t devLimit, rfalNfcaListenDevice *nfcaDevList, uint8_t *devCnt );
-
-
-/*!
- *****************************************************************************
- * \brief NFC-A Poller Start Full Collision Resolution
- *
- * This method starts the full Collision resolution as defined
- * in Activity 1.0 or 1.1 9.3.4
- *
- * \param[in] compMode : compliance mode to be performed
- * \param[in] devLimit : device limit value, and size nfcaDevList
- * \param[out] nfcaDevList : NFC-A listener device info
- * \param[out] devCnt : Devices found counter
- *
- * When compMode is set to ISO compliance it assumes that the device is
- * not sleeping and therefore no ALL_REQ (WUPA) is sent at the beginning.
- * When compMode is set to NFC compliance an additional ALL_REQ (WUPA) is sent at
- * the beginning.
- *
- *
- * When devLimit = 0 it is configured to perform collision detection only. Once a collision
- * is detected the collision resolution is aborted immidiatly. If only one device is found
- * with no collisions, it will properly resolved.
- *
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or mode not set
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalNfcaPollerStartFullCollisionResolution( rfalComplianceMode compMode, uint8_t devLimit, rfalNfcaListenDevice *nfcaDevList, uint8_t *devCnt );
-
-
-/*!
- *****************************************************************************
- * \brief NFC-A Get Full Collision Resolution Status
- *
- * Returns the Collision Resolution status
- *
- * \return RFAL_ERR_BUSY : Operation is ongoing
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_TIMEOUT : Timeout error
- * \return RFAL_ERR_PAR : Parity error detected
- * \return RFAL_ERR_CRC : CRC error detected
- * \return RFAL_ERR_FRAMING : Framing error detected
- * \return RFAL_ERR_PROTO : Protocol error detected
- * \return RFAL_ERR_NONE : No error, activation successful
- *****************************************************************************
- */
-ReturnCode rfalNfcaPollerGetFullCollisionResolutionStatus( void );
-
-
-/*!
- *****************************************************************************
- * \brief NFC-A Listener is SLP_REQ
- *
- * Checks if the given buffer contains valid NFC-A SLP_REQ (HALT)
- *
- * \param[in] buf: buffer containing data
- * \param[in] bufLen: length of the data in buffer to be checked
- *
- * \return true if data in buf contains a SLP_REQ ; false otherwise
- *****************************************************************************
- */
-bool rfalNfcaListenerIsSleepReq( const uint8_t *buf, uint16_t bufLen );
-
-
-#endif /* RFAL_NFCA_H */
-
-/**
- * @}
- *
- * @}
- *
- * @}
- */
+
+/******************************************************************************
+ * @attention
+ *
+ * COPYRIGHT 2016 STMicroelectronics, all rights reserved
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
+ * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+******************************************************************************/
+
+
+/*
+ * PROJECT: ST25R firmware
+ * Revision:
+ * LANGUAGE: ISO C99
+ */
+
+/*! \file rfal_nfca.h
+ *
+ * \author Gustavo Patricio
+ *
+ * \brief Provides several NFC-A convenience methods and definitions
+ *
+ * It provides a Poller (ISO14443A PCD) interface as well as
+ * some NFC-A Listener (ISO14443A PICC) helpers.
+ *
+ * The definitions and helper methods provided by this module are only
+ * up to ISO14443-3 layer
+ *
+ *
+ * An usage example is provided here: \ref exampleRfalNfca.c
+ * \example exampleRfalNfca.c
+ *
+ *
+ * \addtogroup RFAL
+ * @{
+ *
+ * \addtogroup RFAL-AL
+ * \brief RFAL Abstraction Layer
+ * @{
+ *
+ * \addtogroup NFC-A
+ * \brief RFAL NFC-A Module
+ * @{
+ *
+ */
+
+
+#ifndef RFAL_NFCA_H
+#define RFAL_NFCA_H
+
+/*
+ ******************************************************************************
+ * INCLUDES
+ ******************************************************************************
+ */
+#include "rfal_platform.h"
+#include "rfal_utils.h"
+#include "rfal_rf.h"
+#include "rfal_t1t.h"
+
+/*
+ ******************************************************************************
+ * C LINKAGE GUARD
+ ******************************************************************************
+ */
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/*
+ ******************************************************************************
+ * GLOBAL DEFINES
+ ******************************************************************************
+ */
+
+#define RFAL_NFCA_CASCADE_1_UID_LEN 4U /*!< UID length of cascade level 1 only tag */
+#define RFAL_NFCA_CASCADE_2_UID_LEN 7U /*!< UID length of cascade level 2 only tag */
+#define RFAL_NFCA_CASCADE_3_UID_LEN 10U /*!< UID length of cascade level 3 only tag */
+
+#define RFAL_NFCA_SENS_RES_PLATFORM_MASK 0x0FU /*!< SENS_RES (ATQA) platform configuration mask Digital 1.1 Table 10 */
+#define RFAL_NFCA_SENS_RES_PLATFORM_T1T 0x0CU /*!< SENS_RES (ATQA) T1T platform configuration Digital 1.1 Table 10 */
+
+#define RFAL_NFCA_SEL_RES_CONF_MASK 0x60U /*!< SEL_RES (SAK) platform configuration mask Digital 1.1 Table 19 */
+#define RFAL_NFCA_SEL_RES_CONF_T2T 0x00U /*!< SEL_RES (SAK) T2T configuration Digital 1.1 Table 19 */
+#define RFAL_NFCA_SEL_RES_CONF_T4T 0x20U /*!< SEL_RES (SAK) T4T configuration Digital 1.1 Table 19 */
+#define RFAL_NFCA_SEL_RES_CONF_NFCDEP 0x40U /*!< SEL_RES (SAK) NFC-DEP configuration Digital 1.1 Table 19 */
+#define RFAL_NFCA_SEL_RES_CONF_T4T_NFCDEP 0x60U /*!< SEL_RES (SAK) T4T and NFC-DEP configuration Digital 1.1 Table 19 */
+
+
+/*! NFC-A minimum FDT(listen) = ((n * 128 + (84)) / fc) with n_min = 9 Digital 1.1 6.10.1
+ * = (1236)/fc
+ * Relax with 3etu: (3*128)/fc as with multiple NFC-A cards, response may take longer (JCOP cards)
+ * = (1236 + 384)/fc = 1620 / fc */
+#define RFAL_NFCA_FDTMIN 1620U
+/*
+ ******************************************************************************
+ * GLOBAL MACROS
+ ******************************************************************************
+ */
+
+/*! Checks if device is a T1T given its SENS_RES */
+#define rfalNfcaIsSensResT1T( sensRes ) ((((rfalNfcaSensRes*)(sensRes))->platformInfo & RFAL_NFCA_SENS_RES_PLATFORM_MASK) == RFAL_NFCA_SENS_RES_PLATFORM_T1T )
+
+/*! Checks if device is a T2T given its SENS_RES */
+#define rfalNfcaIsSelResT2T( selRes ) ((((rfalNfcaSelRes*)(selRes))->sak & RFAL_NFCA_SEL_RES_CONF_MASK) == RFAL_NFCA_SEL_RES_CONF_T2T )
+
+/*! Checks if device is a T4T given its SENS_RES */
+#define rfalNfcaIsSelResT4T( selRes ) ((((rfalNfcaSelRes*)(selRes))->sak & RFAL_NFCA_SEL_RES_CONF_MASK) == RFAL_NFCA_SEL_RES_CONF_T4T )
+
+/*! Checks if device supports NFC-DEP protocol given its SENS_RES */
+#define rfalNfcaIsSelResNFCDEP( selRes ) ((((rfalNfcaSelRes*)(selRes))->sak & RFAL_NFCA_SEL_RES_CONF_MASK) == RFAL_NFCA_SEL_RES_CONF_NFCDEP )
+
+/*! Checks if device supports ISO-DEP and NFC-DEP protocol given its SENS_RES */
+#define rfalNfcaIsSelResT4TNFCDEP( selRes ) ((((rfalNfcaSelRes*)(selRes))->sak & RFAL_NFCA_SEL_RES_CONF_MASK) == RFAL_NFCA_SEL_RES_CONF_T4T_NFCDEP )
+
+/*! Checks if a NFC-A listener device supports multiple protocols (ISO-DEP and NFC-DEP) */
+#define rfalNfcaLisDevIsMultiProto( lisDev ) (((rfalNfcaListenDevice*)(lisDev))->type == RFAL_NFCA_T4T_NFCDEP )
+
+/*
+******************************************************************************
+* GLOBAL TYPES
+******************************************************************************
+*/
+
+/*! NFC-A Listen device types */
+typedef enum {
+ RFAL_NFCA_T1T = 0x01, /* Device configured for T1T Digital 1.1 Table 9 */
+ RFAL_NFCA_T2T = 0x00, /* Device configured for T2T Digital 1.1 Table 19 */
+ RFAL_NFCA_T4T = 0x20, /* Device configured for T4T Digital 1.1 Table 19 */
+ RFAL_NFCA_NFCDEP = 0x40, /* Device configured for NFC-DEP Digital 1.1 Table 19 */
+ RFAL_NFCA_T4T_NFCDEP = 0x60 /* Device configured for NFC-DEP and T4T Digital 1.1 Table 19 */
+} rfalNfcaListenDeviceType;
+
+
+/*! SENS_RES (ATQA) format Digital 1.1 6.6.3 & Table 7 */
+typedef struct
+{
+ uint8_t anticollisionInfo; /*!< SENS_RES Anticollision Information */
+ uint8_t platformInfo; /*!< SENS_RES Platform Information */
+} rfalNfcaSensRes;
+
+
+/*! SDD_REQ (Anticollision) format Digital 1.1 6.7.1 & Table 11 */
+typedef struct
+{
+ uint8_t selCmd; /*!< SDD_REQ SEL_CMD: cascade Level */
+ uint8_t selPar; /*!< SDD_REQ SEL_PAR: Byte Count[4b] | Bit Count[4b] (NVB: Number of Valid Bits)*/
+} rfalNfcaSddReq;
+
+
+/*! SDD_RES (UID CLn) format Digital 1.1 6.7.2 & Table 15 */
+typedef struct
+{
+ uint8_t nfcid1[RFAL_NFCA_CASCADE_1_UID_LEN]; /*!< NFCID1 cascade level NFCID */
+ uint8_t bcc; /*!< BCC Exclusive-OR over first 4 bytes of SDD_RES */
+} rfalNfcaSddRes;
+
+
+/*! SEL_REQ (Select) format Digital 1.1 6.8.1 & Table 17 */
+typedef struct
+{
+ uint8_t selCmd; /*!< SDD_REQ SEL_CMD: cascade Level */
+ uint8_t selPar; /*!< SDD_REQ SEL_PAR: Byte Count[4b] | Bit Count[4b] (NVB: Number of Valid Bits)*/
+ uint8_t nfcid1[RFAL_NFCA_CASCADE_1_UID_LEN]; /*!< NFCID1 data */
+ uint8_t bcc; /*!< Checksum calculated as exclusive-OR over the 4 bytes of NFCID1 CLn */
+} rfalNfcaSelReq;
+
+
+/*! SEL_RES (SAK) format Digital 1.1 6.8.2 & Table 19 */
+typedef struct
+{
+ uint8_t sak; /*!< Select Acknowledge */
+} rfalNfcaSelRes;
+
+
+/*! NFC-A listener device (PICC) struct */
+typedef struct
+{
+ rfalNfcaListenDeviceType type; /*!< NFC-A Listen device type */
+ rfalNfcaSensRes sensRes; /*!< SENS_RES (ATQA) */
+ rfalNfcaSelRes selRes; /*!< SEL_RES (SAK) */
+ uint8_t nfcId1Len; /*!< NFCID1 Length */
+ uint8_t nfcId1[RFAL_NFCA_CASCADE_3_UID_LEN]; /*!< NFCID1 (UID) */
+#ifdef RFAL_FEATURE_T1T
+ rfalT1TRidRes ridRes; /*!< RID_RES */
+#endif /* RFAL_FEATURE_T1T */
+ bool isSleep; /*!< Device sleeping flag */
+} rfalNfcaListenDevice;
+
+/*
+******************************************************************************
+* GLOBAL FUNCTION PROTOTYPES
+******************************************************************************
+*/
+
+/*!
+ *****************************************************************************
+ * \brief Initialize NFC-A Poller mode
+ *
+ * This methods configures RFAL RF layer to perform as a
+ * NFC-A Poller/RW (ISO14443A PCD) including all default timings and bit rate
+ * to 106 kbps
+
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or mode not set
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalNfcaPollerInitialize( void );
+
+
+/*!
+ *****************************************************************************
+ * \brief NFC-A Poller Check Presence
+ *
+ * This method checks if a NFC-A Listen device (PICC) is present on the field
+ * by sending an ALL_REQ (WUPA) or SENS_REQ (REQA)
+ *
+ * \param[in] cmd : Indicate if to send an ALL_REQ or a SENS_REQ
+ * \param[out] sensRes : If received, the SENS_RES
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_RF_COLLISION : Collision detected one or more device in the field
+ * \return RFAL_ERR_PAR : Parity error detected, one or more device in the field
+ * \return RFAL_ERR_CRC : CRC error detected, one or more device in the field
+ * \return RFAL_ERR_FRAMING : Framing error detected, one or more device in the field
+ * \return RFAL_ERR_PROTO : Protocol error detected, one or more device in the field
+ * \return RFAL_ERR_TIMEOUT : Timeout error, no listener device detected
+ * \return RFAL_ERR_NONE : No error, one or more device in the field
+ *****************************************************************************
+ */
+ReturnCode rfalNfcaPollerCheckPresence( rfal14443AShortFrameCmd cmd, rfalNfcaSensRes *sensRes );
+
+
+/*!
+ *****************************************************************************
+ * \brief NFC-A Poller Select
+ *
+ * This method selects a NFC-A Listener device (PICC)
+ *
+ * \param[in] nfcid1 : Listener device NFCID1 to be selected
+ * \param[in] nfcidLen : Length of the NFCID1 to be selected
+ * \param[out] selRes : pointer to place the SEL_RES
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_TIMEOUT : Timeout error
+ * \return RFAL_ERR_PAR : Parity error detected
+ * \return RFAL_ERR_CRC : CRC error detected
+ * \return RFAL_ERR_FRAMING : Framing error detected
+ * \return RFAL_ERR_PROTO : Protocol error detected
+ * \return RFAL_ERR_NONE : No error, SEL_RES received
+ *****************************************************************************
+ */
+ReturnCode rfalNfcaPollerSelect( const uint8_t *nfcid1, uint8_t nfcidLen, rfalNfcaSelRes *selRes );
+
+
+/*!
+ *****************************************************************************
+ * \brief NFC-A Poller Start Select
+ *
+ * This method starts the selection of a NFC-A Listener device (PICC)
+ *
+ * \param[in] nfcid1 : Listener device NFCID1 to be selected
+ * \param[in] nfcidLen : Length of the NFCID1 to be selected
+ * \param[out] selRes : pointer to place the SEL_RES
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_TIMEOUT : Timeout error
+ * \return RFAL_ERR_PAR : Parity error detected
+ * \return RFAL_ERR_CRC : CRC error detected
+ * \return RFAL_ERR_FRAMING : Framing error detected
+ * \return RFAL_ERR_PROTO : Protocol error detected
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalNfcaPollerStartSelect( const uint8_t *nfcid1, uint8_t nfcidLen, rfalNfcaSelRes *selRes );
+
+
+/*!
+ *****************************************************************************
+ * \brief NFC-A Poller Get Select Status
+ *
+ * This method gets the selection status
+ *
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_TIMEOUT : Timeout error
+ * \return RFAL_ERR_PAR : Parity error detected
+ * \return RFAL_ERR_CRC : CRC error detected
+ * \return RFAL_ERR_FRAMING : Framing error detected
+ * \return RFAL_ERR_PROTO : Protocol error detected
+ * \return RFAL_ERR_BUSY : Operation is ongoing
+ * \return RFAL_ERR_NONE : No error, SEL_RES received
+ *****************************************************************************
+ */
+ReturnCode rfalNfcaPollerGetSelectStatus( void );
+
+
+/*!
+ *****************************************************************************
+ * \brief NFC-A Poller Sleep
+ *
+ * This method sends a SLP_REQ (HLTA)
+ * No response is expected afterwards Digital 1.1 6.9.2.1
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalNfcaPollerSleep( void );
+
+
+/*!
+ *****************************************************************************
+ * \brief NFC-A Poller Start Sleep
+ *
+ * This method sends a SLP_REQ (HLTA)
+ * No response is expected afterwards Digital 1.1 6.9.2.1
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalNfcaPollerStartSleep( void );
+
+
+/*!
+ *****************************************************************************
+ * \brief NFC-A Poller Get Sleep Status
+ *
+ * Returns the Sleep status
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_BUSY : Operation is ongoing
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalNfcaPollerGetSleepStatus( void );
+
+
+/*!
+ *****************************************************************************
+ * \brief NFC-A Technology Detection
+ *
+ * This method performs NFC-A Technology Detection as defined in the spec
+ * given in the compliance mode
+ *
+ * \param[in] compMode : compliance mode to be performed
+ * \param[out] sensRes : location to store the SENS_RES, if received
+ *
+ * When compMode is set to ISO compliance a SLP_REQ (HLTA) is not sent
+ * after detection. When set to EMV a ALL_REQ (WUPA) is sent instead of
+ * a SENS_REQ (REQA)
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_NONE : No error, one or more device in the field
+ *****************************************************************************
+ */
+ReturnCode rfalNfcaPollerTechnologyDetection( rfalComplianceMode compMode, rfalNfcaSensRes *sensRes );
+
+
+/*!
+ *****************************************************************************
+ * \brief NFC-A Start Technology Detection
+ *
+ * This method starts NFC-A Technology Detection as defined in the spec
+ * given in the compliance mode
+ *
+ * \param[in] compMode : compliance mode to be performed
+ * \param[out] sensRes : location to store the SENS_RES, if received
+ *
+ * When compMode is set to ISO compliance a SLP_REQ (HLTA) is not sent
+ * after detection. When set to EMV a ALL_REQ (WUPA) is sent instead of
+ * a SENS_REQ (REQA)
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalNfcaPollerStartTechnologyDetection( rfalComplianceMode compMode, rfalNfcaSensRes *sensRes );
+
+
+/*!
+ *****************************************************************************
+ * \brief NFC-A Get Technology Detection Status
+ *
+ * Returns the Technology Detection status
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_BUSY : Operation is ongoing
+ * \return RFAL_ERR_NONE : No error, one or more device in the field
+ *****************************************************************************
+ */
+ReturnCode rfalNfcaPollerGetTechnologyDetectionStatus( void );
+
+
+/*!
+ *****************************************************************************
+ * \brief NFC-A Poller Collision Resolution
+ *
+ * Collision resolution for one NFC-A Listener device/card (PICC) as
+ * defined in Activity 2.1 9.3.4
+ *
+ * This method executes anti collision loop and select the device with higher NFCID1
+ *
+ * When devLimit = 0 it is configured to perform collision detection only. Once a collision
+ * is detected the collision resolution is aborted immediately. If only one device is found
+ * with no collisions, it will properly resolved.
+ *
+ * \param[in] devLimit : device limit value (CON_DEVICES_LIMIT)
+ * \param[out] collPending : pointer to collision pending flag (INT_COLL_PEND)
+ * \param[out] selRes : location to store the last Select Response from listener device (PICC)
+ * \param[out] nfcId1 : location to store the NFCID1 (UID), ensure RFAL_NFCA_CASCADE_3_UID_LEN
+ * \param[out] nfcId1Len : pointer to length of NFCID1 (UID)
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or mode not set
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_PROTO : Card length invalid
+ * \return RFAL_ERR_IGNORE : conDevLimit is 0 and there is a collision
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalNfcaPollerSingleCollisionResolution( uint8_t devLimit, bool *collPending, rfalNfcaSelRes *selRes, uint8_t *nfcId1, uint8_t *nfcId1Len );
+
+
+/*!
+ *****************************************************************************
+ * \brief NFC-A Poller Full Collision Resolution
+ *
+ * Performs a full Collision resolution as defined in Activity 2.1 9.3.4
+ *
+ * \param[in] compMode : compliance mode to be performed
+ * \param[in] devLimit : device limit value, and size nfcaDevList
+ * \param[out] nfcaDevList : NFC-A listener device info
+ * \param[out] devCnt : Devices found counter
+ *
+ * When compMode is set to ISO compliance it assumes that the device is
+ * not sleeping and therefore no ALL_REQ (WUPA) is sent at the beginning.
+ * When compMode is set to NFC compliance an additional ALL_REQ (WUPA) is sent
+ * at the beginning.
+ *
+ *
+ * When devLimit = 0 it is configured to perform collision detection only. Once a collision
+ * is detected the collision resolution is aborted immediately. If only one device is found
+ * with no collisions, it will properly resolved.
+ *
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or mode not set
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalNfcaPollerFullCollisionResolution( rfalComplianceMode compMode, uint8_t devLimit, rfalNfcaListenDevice *nfcaDevList, uint8_t *devCnt );
+
+
+/*!
+ *****************************************************************************
+ * \brief NFC-A Poller Full Collision Resolution with Sleep
+ *
+ * Performs a full Collision resolution similar to rfalNfcaPollerFullCollisionResolution
+ * but an additional SLP_REQ (HLTA) -> SENS_RES (REQA) is sent regardless if there
+ * was a collision.
+ * This proprietary behaviour ensures proper activation of certain devices that suffer
+ * from influence of Type B commands as foreseen in ISO14443-3 5.2.3 or were somehow
+ * not detected by the first round of collision resolution
+ *
+ * \param[in] devLimit : device limit value, and size nfcaDevList
+ * \param[out] nfcaDevList : NFC-A listener device info
+ * \param[out] devCnt : Devices found counter
+ *
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or mode not set
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalNfcaPollerSleepFullCollisionResolution( uint8_t devLimit, rfalNfcaListenDevice *nfcaDevList, uint8_t *devCnt );
+
+
+/*!
+ *****************************************************************************
+ * \brief NFC-A Poller Start Full Collision Resolution
+ *
+ * This method starts the full Collision resolution as defined
+ * in Activity 1.0 or 1.1 9.3.4
+ *
+ * \param[in] compMode : compliance mode to be performed
+ * \param[in] devLimit : device limit value, and size nfcaDevList
+ * \param[out] nfcaDevList : NFC-A listener device info
+ * \param[out] devCnt : Devices found counter
+ *
+ * When compMode is set to ISO compliance it assumes that the device is
+ * not sleeping and therefore no ALL_REQ (WUPA) is sent at the beginning.
+ * When compMode is set to NFC compliance an additional ALL_REQ (WUPA) is sent at
+ * the beginning.
+ *
+ *
+ * When devLimit = 0 it is configured to perform collision detection only. Once a collision
+ * is detected the collision resolution is aborted immediately. If only one device is found
+ * with no collisions, it will properly resolved.
+ *
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or mode not set
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalNfcaPollerStartFullCollisionResolution( rfalComplianceMode compMode, uint8_t devLimit, rfalNfcaListenDevice *nfcaDevList, uint8_t *devCnt );
+
+
+/*!
+ *****************************************************************************
+ * \brief NFC-A Get Full Collision Resolution Status
+ *
+ * Returns the Collision Resolution status
+ *
+ * \return RFAL_ERR_BUSY : Operation is ongoing
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_TIMEOUT : Timeout error
+ * \return RFAL_ERR_PAR : Parity error detected
+ * \return RFAL_ERR_CRC : CRC error detected
+ * \return RFAL_ERR_FRAMING : Framing error detected
+ * \return RFAL_ERR_PROTO : Protocol error detected
+ * \return RFAL_ERR_BUSY : Operation is ongoing
+ * \return RFAL_ERR_NONE : No error, activation successful
+ *****************************************************************************
+ */
+ReturnCode rfalNfcaPollerGetFullCollisionResolutionStatus( void );
+
+
+/*!
+ *****************************************************************************
+ * \brief NFC-A Listener is SLP_REQ
+ *
+ * Checks if the given buffer contains valid NFC-A SLP_REQ (HALT)
+ *
+ * \param[in] buf: buffer containing data
+ * \param[in] bufLen: length of the data in buffer to be checked
+ *
+ * \return true if data in buf contains a SLP_REQ ; false otherwise
+ *****************************************************************************
+ */
+bool rfalNfcaListenerIsSleepReq( const uint8_t *buf, uint16_t bufLen );
+
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* RFAL_NFCA_H */
+
+/**
+ * @}
+ *
+ * @}
+ *
+ * @}
+ */
### core/embed/io/nfc/st25/rfal002/include/rfal_nfcb.h
@@ -1,597 +1,614 @@
-
-/******************************************************************************
- * @attention
- *
- * COPYRIGHT 2016 STMicroelectronics, all rights reserved
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
- * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
-******************************************************************************/
-
-
-/*
- * PROJECT: ST25R firmware
- * Revision:
- * LANGUAGE: ISO C99
- */
-
-/*! \file rfal_nfcb.h
- *
- * \author Gustavo Patricio
- *
- * \brief Implementation of NFC-B (ISO14443B) helpers
- *
- * It provides a NFC-B Poller (ISO14443B PCD) interface and
- * also provides some NFC-B Listener (ISO14443B PICC) helpers
- *
- * The definitions and helpers methods provided by this module are only
- * up to ISO14443-3 layer (excluding ATTRIB)
- *
- *
- * \addtogroup RFAL
- * @{
- *
- * \addtogroup RFAL-AL
- * \brief RFAL Abstraction Layer
- * @{
- *
- * \addtogroup NFC-B
- * \brief RFAL NFC-B Module
- * @{
- *
- */
-
-
-#ifndef RFAL_NFCB_H
-#define RFAL_NFCB_H
-
-/*
- ******************************************************************************
- * INCLUDES
- ******************************************************************************
- */
-#include "rfal_platform.h"
-#include "rfal_utils.h"
-#include "rfal_rf.h"
-
-/*
- ******************************************************************************
- * GLOBAL DEFINES
- ******************************************************************************
- */
-
-#define RFAL_NFCB_FWTSENSB 7680U /*!< NFC-B FWT(SENSB) Digital 2.0 B.3 */
-#define RFAL_NFCB_DFWT 49152U /*!< NFC-B dFWT Delta 2.0 7.9.1.3 & B.3 */
-#define RFAL_NFCB_DTPOLL_10 rfalConvMsTo1fc(20) /*!< NFC-B Delta Tb Poll Digital 1.0 A.2 */
-#define RFAL_NFCB_DTPOLL_20 rfalConvMsTo1fc(17) /*!< NFC-B Delta Tb Poll Digital 2.1 B.3 */
-
-#define RFAL_NFCB_AFI 0x00U /*!< NFC-B default Application Family Digital 1.1 7.6.1.1 */
-#define RFAL_NFCB_PARAM 0x00U /*!< NFC-B default SENSB_REQ PARAM */
-#define RFAL_NFCB_CRC_LEN 2U /*!< NFC-B CRC length and CRC_B(AID) Digital 1.1 Table 28 */
-#define RFAL_NFCB_NFCID0_LEN 4U /*!< Length of NFC-B NFCID0 */
-#define RFAL_NFCB_CMD_LEN 1U /*!< Length of NFC-B Command */
-
-#define RFAL_NFCB_SENSB_RES_LEN 12U /*!< Standard length of SENSB_RES without SFGI byte */
-#define RFAL_NFCB_SENSB_RES_EXT_LEN 13U /*!< Extended length of SENSB_RES with SFGI byte */
-
-#define RFAL_NFCB_SENSB_REQ_ADV_FEATURE 0x20U /*!< Bit mask for Advance Feature in SENSB_REQ */
-#define RFAL_NFCB_SENSB_RES_FSCI_MASK 0x0FU /*!< Bit mask for FSCI value in SENSB_RES */
-#define RFAL_NFCB_SENSB_RES_FSCI_SHIFT 4U /*!< Shift for FSCI value in SENSB_RES */
-#define RFAL_NFCB_SENSB_RES_PROTO_RFU_MASK 0x08U /*!< Bit mask for Protocol Type RFU in SENSB_RES */
-#define RFAL_NFCB_SENSB_RES_PROTO_TR2_MASK 0x03U /*!< Bit mask for Protocol Type TR2 in SENSB_RES */
-#define RFAL_NFCB_SENSB_RES_PROTO_TR2_SHIFT 1U /*!< Shift for Protocol Type TR2 in SENSB_RES */
-#define RFAL_NFCB_SENSB_RES_PROTO_ISO_MASK 0x01U /*!< Bit mask Protocol Type ISO14443 Compliant in SENSB_RES */
-#define RFAL_NFCB_SENSB_RES_FWI_MASK 0x0FU /*!< Bit mask for FWI value in SENSB_RES */
-#define RFAL_NFCB_SENSB_RES_FWI_SHIFT 4U /*!< Bit mask for FWI value in SENSB_RES */
-#define RFAL_NFCB_SENSB_RES_ADC_MASK 0x0CU /*!< Bit mask for ADC value in SENSB_RES */
-#define RFAL_NFCB_SENSB_RES_ADC_ADV_FEATURE_MASK 0x08U /*!< Bit mask for ADC.Advanced Proto Features in SENSB_RES */
-#define RFAL_NFCB_SENSB_RES_ADC_PROPRIETARY_MASK 0x04U /*!< Bit mask for ADC.Proprietary Application in SENSB_RES */
-#define RFAL_NFCB_SENSB_RES_FO_DID_MASK 0x01U /*!< Bit mask for DID in SENSB_RES */
-#define RFAL_NFCB_SENSB_RES_FO_NAD_MASK 0x02U /*!< Bit mask for DID in SENSB_RES */
-#define RFAL_NFCB_SENSB_RES_FO_MASK 0x03U /*!< Bit mask for FO value in SENSB_RES (NAD and DID) */
-#define RFAL_NFCB_SENSB_RES_SFGI_MASK 0x0FU /*!< Bit mask for SFGI in SENSB_RES */
-#define RFAL_NFCB_SENSB_RES_SFGI_SHIFT 4U /*!< Shift for SFGI in SENSB_RES */
-
-/*
-******************************************************************************
-* GLOBAL MACROS
-******************************************************************************
-*/
-
-/*! Get device's FSCI given its SENSB_RES Digital 1.1 7.6.2 */
-#define rfalNfcbGetFSCI( sensbRes ) ((((rfalNfcbSensbRes*)(sensbRes))->protInfo.FsciProType >> RFAL_NFCB_SENSB_RES_FSCI_SHIFT) & RFAL_NFCB_SENSB_RES_FSCI_MASK )
-
-/*! Checks if the given NFC-B device indicates ISO-DEP support */
-#define rfalNfcbIsIsoDepSupported( dev ) ( (((rfalNfcbListenDevice*)(dev))->sensbRes.protInfo.FsciProType & RFAL_NFCB_SENSB_RES_PROTO_ISO_MASK) != 0U )
-
-/*
-******************************************************************************
-* GLOBAL TYPES
-******************************************************************************
-*/
-
-/*! SENSB_REQ and ALLB_REQ param Digital 1.1 7.6.1 */
-typedef enum
-{
- RFAL_NFCB_SENS_CMD_ALLB_REQ = 0x08, /*!< ALLB_REQ (WUPB) */
- RFAL_NFCB_SENS_CMD_SENSB_REQ = 0x00 /*!< SENSB_REQ (REQB) */
-} rfalNfcbSensCmd;
-
-
-/*! Number of Slots (NI) codes used for NFC-B anti collision Digital 1.1 Table 26 */
-typedef enum
-{
- RFAL_NFCB_SLOT_NUM_1 = 0, /*!< N=0 : 1 slot */
- RFAL_NFCB_SLOT_NUM_2 = 1, /*!< N=1 : 2 slots */
- RFAL_NFCB_SLOT_NUM_4 = 2, /*!< N=2 : 4 slots */
- RFAL_NFCB_SLOT_NUM_8 = 3, /*!< N=3 : 8 slots */
- RFAL_NFCB_SLOT_NUM_16 = 4 /*!< N=4 : 16 slots */
-}rfalNfcbSlots;
-
-
-/*! SENSB_RES (ATQB) Application Data Format Digital 1.1 Table 28 */
-typedef struct
-{
- uint8_t AFI; /*!< Application Family Identifier */
- uint8_t CRC_B[RFAL_NFCB_CRC_LEN]; /*!< CRC_B of AID */
- uint8_t numApps; /*!< Number of Applications */
-} rfalNfcbSensbResAppData;
-
-
-/*! SENSB_RES Protocol Info format Digital 1.1 Table 29 */
-typedef struct
-{
- uint8_t BRC; /*!< Bit Rate Capability */
- uint8_t FsciProType; /*!< Frame Size Card Integer [4b] | Protocol Type[4 bits] */
- uint8_t FwiAdcFo; /*!< Frame Waiting Integer [4b] | Application Data Coding [2b] | Frame Options [2b] */
- uint8_t SFGI; /*!< Optional: Start-Up Frame Guard Time Integer[4b] | RFU [4b] */
-} rfalNfcbSensbResProtocolInfo;
-
-
-/*! SENSB_RES format Digital 1.1 7.6.2 */
-typedef struct
-{
- uint8_t cmd; /*!< SENSB_RES: 50h */
- uint8_t nfcid0[RFAL_NFCB_NFCID0_LEN]; /*!< NFC Identifier (PUPI)*/
- rfalNfcbSensbResAppData appData; /*!< Application Data */
- rfalNfcbSensbResProtocolInfo protInfo; /*!< Protocol Information */
-} rfalNfcbSensbRes;
-
-
-/*! NFC-B listener device (PICC) struct */
-typedef struct
-{
- uint8_t sensbResLen; /*!< SENSB_RES length */
- rfalNfcbSensbRes sensbRes; /*!< SENSB_RES */
- bool isSleep; /*!< Device sleeping flag */
-}rfalNfcbListenDevice;
-
-/*
-******************************************************************************
-* GLOBAL FUNCTION PROTOTYPES
-******************************************************************************
-*/
-
-/*!
- *****************************************************************************
- * \brief Initialize NFC-B Poller mode
- *
- * This methods configures RFAL RF layer to perform as a
- * NFC-B Poller/RW (ISO14443B PCD) including all default timings
- *
- * It sets NFC-B parameters (AFI, PARAM) to default values
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or mode not set
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalNfcbPollerInitialize( void );
-
-
-/*!
- *****************************************************************************
- * \brief Set NFC-B Poller parameters
- *
- * This methods configures RFAL RF layer to perform as a
- * NFCA Poller/RW (ISO14443A PCD) including all default timings
- *
- * Additionally configures NFC-B specific parameters to be used on the
- * following communications
- *
- * \param[in] AFI : Application Family Identifier to be used
- * \param[in] PARAM : PARAM to be used, it announces whether Advanced
- * Features or Extended SENSB_RES is supported
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or mode not set
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalNfcbPollerInitializeWithParams( uint8_t AFI, uint8_t PARAM );
-
-
-/*!
- *****************************************************************************
- * \brief NFC-B Poller Check Presence
- *
- * This method checks if a NFC-B Listen device (PICC) is present on the field
- * by sending an ALLB_REQ (WUPB) or SENSB_REQ (REQB)
- *
- * \param[in] cmd : Indicate if to send an ALLB_REQ or a SENSB_REQ
- * \param[in] slots : The number of slots to be announced
- * \param[out] sensbRes : If received, the SENSB_RES
- * \param[out] sensbResLen : If received, the SENSB_RES length
- *
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_TIMEOUT : Timeout error, no listener device detected
- * \return RFAL_ERR_RF_COLLISION : Collision detected one or more device in the field
- * \return RFAL_ERR_PAR : Parity error detected, one or more device in the field
- * \return RFAL_ERR_CRC : CRC error detected, one or more device in the field
- * \return RFAL_ERR_FRAMING : Framing error detected, one or more device in the field
- * \return RFAL_ERR_PROTO : Protocol error detected, invalid SENSB_RES received
- * \return RFAL_ERR_NONE : No error, SENSB_RES received
- *****************************************************************************
- */
-ReturnCode rfalNfcbPollerCheckPresence( rfalNfcbSensCmd cmd, rfalNfcbSlots slots, rfalNfcbSensbRes *sensbRes, uint8_t *sensbResLen );
-
-
-/*!
- *****************************************************************************
- * \brief NFC-B Poller Start Check Presence
- *
- * This method starts check for a NFC-B Listen device (PICC) presence on the field
- * by sending an ALLB_REQ (WUPB) or SENSB_REQ (REQB)
- *
- * \param[in] cmd : Indicate if to send an ALL_REQ or a SENS_REQ
- * \param[in] slots : The number of slots to be announced
- * \param[out] sensbRes : If received, the SENSB_RES
- * \param[out] sensbResLen : If received, the SENSB_RES length
- *
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_NONE : No error, SENSB_RES received
- *****************************************************************************
- */
-ReturnCode rfalNfcbPollerStartCheckPresence( rfalNfcbSensCmd cmd, rfalNfcbSlots slots, rfalNfcbSensbRes *sensbRes, uint8_t *sensbResLen );
-
-
-/*!
- *****************************************************************************
- * \brief NFC-B Poller Get Check Presence Status
- *
- * This method get the presence check status
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_TIMEOUT : Timeout error, no listener device detected
- * \return RFAL_ERR_RF_COLLISION : Collision detected one or more device in the field
- * \return RFAL_ERR_PAR : Parity error detected, one or more device in the field
- * \return RFAL_ERR_CRC : CRC error detected, one or more device in the field
- * \return RFAL_ERR_FRAMING : Framing error detected, one or more device in the field
- * \return RFAL_ERR_PROTO : Protocol error detected, invalid SENSB_RES received
- * \return RFAL_ERR_NONE : No error, SENSB_RES received
- *****************************************************************************
- */
-ReturnCode rfalNfcbPollerGetCheckPresenceStatus( void );
-
-
-/*!
- *****************************************************************************
- * \brief NFC-B Poller Sleep
- *
- * This function is used to send the SLPB_REQ (HLTB) command to put the PICC with
- * the given NFCID0 to state HALT so that they do not reply to further SENSB_REQ
- * commands (only to ALLB_REQ)
- *
- * \param[in] nfcid0 : NFCID of the device to be put to Sleep
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalNfcbPollerSleep( const uint8_t* nfcid0 );
-
-
-/*!
- *****************************************************************************
- * \brief NFC-B Poller Slot Marker
- *
- * This method sends a NFC-B Slot marker frame
- *
- * \param[in] slotCode : Slot Code [1-15]
- * \param[out] sensbRes : If received, the SENSB_RES
- * \param[out] sensbResLen : If received, the SENSB_RES length
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_TIMEOUT : Timeout error
- * \return RFAL_ERR_PAR : Parity error detected
- * \return RFAL_ERR_CRC : CRC error detected
- * \return RFAL_ERR_FRAMING : Framing error detected
- * \return RFAL_ERR_PROTO : Protocol error detected
- * \return RFAL_ERR_NONE : No error, SEL_RES received
- *****************************************************************************
- */
-ReturnCode rfalNfcbPollerSlotMarker( uint8_t slotCode, rfalNfcbSensbRes *sensbRes, uint8_t *sensbResLen );
-
-
-/*!
- *****************************************************************************
- * \brief NFC-B Poller Start Slot Marker
- *
- * This method starts a NFC-B Slot marker
- *
- * \param[in] slotCode : Slot Code [1-15]
- * \param[out] sensbRes : If received, the SENSB_RES
- * \param[out] sensbResLen : If received, the SENSB_RES length
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_NONE : No error, SEL_RES received
- *****************************************************************************
- */
-ReturnCode rfalNfcbPollerStartSlotMarker( uint8_t slotCode, rfalNfcbSensbRes *sensbRes, uint8_t *sensbResLen );
-
-
-/*!
- *****************************************************************************
- * \brief NFC-B Poller Get Slot Marker Status
- *
- * This method gets the status of the NFC-B Slot marker
- *
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_TIMEOUT : Timeout error
- * \return RFAL_ERR_PAR : Parity error detected
- * \return RFAL_ERR_CRC : CRC error detected
- * \return RFAL_ERR_FRAMING : Framing error detected
- * \return RFAL_ERR_PROTO : Protocol error detected
- * \return RFAL_ERR_NONE : No error, SEL_RES received
- *****************************************************************************
- */
-ReturnCode rfalNfcbPollerGetSlotMarkerStatus( void );
-
-
-/*!
- *****************************************************************************
- * \brief NFC-B Technology Detection
- *
- * This method performs NFC-B Technology Detection as defined in the spec
- * given in the compliance mode
- *
- * \param[in] compMode : compliance mode to be performed
- * \param[out] sensbRes : location to store the SENSB_RES, if received
- * \param[out] sensbResLen : length of the SENSB_RES, if received
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_NONE : No error, one or more device in the field
- *****************************************************************************
- */
-ReturnCode rfalNfcbPollerTechnologyDetection( rfalComplianceMode compMode, rfalNfcbSensbRes *sensbRes, uint8_t *sensbResLen );
-
-/*!
- *****************************************************************************
- * \brief NFC-B Start Technology Detection
- *
- * This method starts the NFC-B Technology Detection as defined in the spec
- * given in the compliance mode
- *
- * \param[in] compMode : compliance mode to be performed
- * \param[out] sensbRes : location to store the SENSB_RES, if received
- * \param[out] sensbResLen : length of the SENSB_RES, if received
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_NONE : No error, one or more device in the field
- *****************************************************************************
- */
-ReturnCode rfalNfcbPollerStartTechnologyDetection( rfalComplianceMode compMode, rfalNfcbSensbRes *sensbRes, uint8_t *sensbResLen );
-
-
-/*!
- *****************************************************************************
- * \brief NFC-B Get Technology Detection Status
- *
- * This method gets the NFC-B Technology Detection status
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_NONE : No error, one or more device in the field
- *****************************************************************************
- */
-ReturnCode rfalNfcbPollerGetTechnologyDetectionStatus( void );
-
-
-/*!
- *****************************************************************************
- * \brief NFC-B Poller Collision Resolution
- *
- * NFC-B Collision resolution Listener device/card (PICC) as
- * defined in Activity 1.1 9.3.5
- *
- * This function is used to perform collision resolution for detection in case
- * of multiple NFC Forum Devices with Technology B detected.
- * Target with valid SENSB_RES will be stored in nfcbDevList and devCnt incremented.
- *
- * \param[in] compMode : compliance mode to be performed
- * \param[in] devLimit : device limit value, and size nfcbDevList
- * \param[out] nfcbDevList : NFC-B listener device info
- * \param[out] devCnt : devices found counter
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or mode not set
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_PROTO : Protocol error detected
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalNfcbPollerCollisionResolution( rfalComplianceMode compMode, uint8_t devLimit, rfalNfcbListenDevice *nfcbDevList, uint8_t *devCnt );
-
-
-/*!
- *****************************************************************************
- * \brief NFC-B Poller Collision Resolution Slotted
- *
- * NFC-B Collision resolution Listener device/card (PICC). The sequence can
- * be configured to be according to NFC Forum Activity 1.1 9.3.5, ISO10373
- * or EMVCo
- *
- * This function is used to perform collision resolution for detection in case
- * of multiple NFC Forum Devices with Technology B are detected.
- * Target with valid SENSB_RES will be stored in nfcbDevList and devCnt incremented.
- *
- * This method provides the means to perform a collision resolution loop with specific
- * initial and end number of slots. This allows to user to start the loop already with
- * greater number of slots, and or limit the end number of slots. At the end a flag
- * indicating whether there were collisions pending is returned.
- *
- * If RFAL_COMPLIANCE_MODE_ISO is used \a initSlots must be set to RFAL_NFCB_SLOT_NUM_1
- *
- *
- * \param[in] compMode : compliance mode to be performed
- * \param[in] devLimit : device limit value, and size nfcbDevList
- * \param[in] initSlots : number of slots to open initially
- * \param[in] endSlots : number of slots when to stop collision resolution
- * \param[out] nfcbDevList : NFC-B listener device info
- * \param[out] devCnt : devices found counter
- * \param[out] colPending : flag indicating whether collision are still pending
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or mode not set
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_PROTO : Protocol error detected
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalNfcbPollerSlottedCollisionResolution( rfalComplianceMode compMode, uint8_t devLimit, rfalNfcbSlots initSlots, rfalNfcbSlots endSlots, rfalNfcbListenDevice *nfcbDevList, uint8_t *devCnt, bool *colPending );
-
-
-/*!
- *****************************************************************************
- * \brief NFC-B Poller Start Collision Resolution
- *
- * It starts the NFC-B Collision resolution Listener device/card (PICC) as
- * defined in Activity 1.1 9.3.5
- *
- * This function is used to trigger the collision resolution for detection in case
- * of multiple NFC Forum Devices with Technology B detected.
- * Target with valid SENSB_RES will be stored in nfcbDevList and devCnt incremented.
- *
- * \param[in] compMode : compliance mode to be performed
- * \param[in] devLimit : device limit value, and size nfcbDevList
- * \param[out] nfcbDevList : NFC-B listener device info
- * \param[out] devCnt : devices found counter
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or mode not set
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_PROTO : Protocol error detected
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalNfcbPollerStartCollisionResolution( rfalComplianceMode compMode, uint8_t devLimit, rfalNfcbListenDevice *nfcbDevList, uint8_t *devCnt );
-
-
-/*!
- *****************************************************************************
- * \brief NFC-B Poller Start Collision Resolution Slotted
- *
- * Starts NFC-B Collision resolution Listener device/card (PICC). The sequence can
- * be configured to be according to NFC Forum Activity 1.1 9.3.5, ISO10373
- * or EMVCo
- *
- * This function is used to trigger the collision resolution for detection in case
- * of multiple NFC Forum Devices with Technology B are detected.
- * Target with valid SENSB_RES will be stored in nfcbDevList and devCnt incremented.
- *
- * This method provides the means to perform a collision resolution loop with specific
- * initial and end number of slots. This allows to user to start the loop already with
- * greater number of slots, and or limit the end number of slots. At the end a flag
- * indicating whether there were collisions pending is returned.
- *
- * If RFAL_COMPLIANCE_MODE_ISO is used \a initSlots must be set to RFAL_NFCB_SLOT_NUM_1
- *
- *
- * \param[in] compMode : compliance mode to be performed
- * \param[in] devLimit : device limit value, and size nfcbDevList
- * \param[in] initSlots : number of slots to open initially
- * \param[in] endSlots : number of slots when to stop collision resolution
- * \param[out] nfcbDevList : NFC-B listener device info
- * \param[out] devCnt : devices found counter
- * \param[out] colPending : flag indicating whether collision are still pending
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or mode not set
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_PROTO : Protocol error detected
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalNfcbPollerStartSlottedCollisionResolution( rfalComplianceMode compMode, uint8_t devLimit, rfalNfcbSlots initSlots, rfalNfcbSlots endSlots, rfalNfcbListenDevice *nfcbDevList, uint8_t *devCnt, bool *colPending );
-
-
-/*!
- *****************************************************************************
- * \brief NFC-B Get Collision Resolution Status
- *
- * Returns the Collision Resolution status
- *
- * \return RFAL_ERR_BUSY : Operation is ongoing
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_TIMEOUT : Timeout error
- * \return RFAL_ERR_PAR : Parity error detected
- * \return RFAL_ERR_CRC : CRC error detected
- * \return RFAL_ERR_FRAMING : Framing error detected
- * \return RFAL_ERR_PROTO : Protocol error detected
- * \return RFAL_ERR_NONE : No error, activation successful
- *****************************************************************************
- */
-ReturnCode rfalNfcbPollerGetCollisionResolutionStatus( void );
-
-
-/*!
- *****************************************************************************
- * \brief NFC-B TR2 code to FDT
- *
- * Converts the TR2 code as defined in Digital 1.1 Table 33 Minimum
- * TR2 Coding to Frame Delay Time (FDT) in 1/Fc
- *
- * \param[in] tr2Code : TR2 code as defined in Digital 1.1 Table 33
- *
- * \return FDT in 1/Fc
- *****************************************************************************
- */
-uint32_t rfalNfcbTR2ToFDT( uint8_t tr2Code );
-
-#endif /* RFAL_NFCB_H */
-
-/**
- * @}
- *
- * @}
- *
- * @}
- */
+
+/******************************************************************************
+ * @attention
+ *
+ * COPYRIGHT 2016 STMicroelectronics, all rights reserved
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
+ * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+******************************************************************************/
+
+
+/*
+ * PROJECT: ST25R firmware
+ * Revision:
+ * LANGUAGE: ISO C99
+ */
+
+/*! \file rfal_nfcb.h
+ *
+ * \author Gustavo Patricio
+ *
+ * \brief Implementation of NFC-B (ISO14443B) helpers
+ *
+ * It provides a NFC-B Poller (ISO14443B PCD) interface and
+ * also provides some NFC-B Listener (ISO14443B PICC) helpers
+ *
+ * The definitions and helpers methods provided by this module are only
+ * up to ISO14443-3 layer (excluding ATTRIB)
+ *
+ *
+ * \addtogroup RFAL
+ * @{
+ *
+ * \addtogroup RFAL-AL
+ * \brief RFAL Abstraction Layer
+ * @{
+ *
+ * \addtogroup NFC-B
+ * \brief RFAL NFC-B Module
+ * @{
+ *
+ */
+
+
+#ifndef RFAL_NFCB_H
+#define RFAL_NFCB_H
+
+/*
+ ******************************************************************************
+ * INCLUDES
+ ******************************************************************************
+ */
+#include "rfal_platform.h"
+#include "rfal_utils.h"
+#include "rfal_rf.h"
+
+/*
+ ******************************************************************************
+ * C LINKAGE GUARD
+ ******************************************************************************
+ */
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/*
+ ******************************************************************************
+ * GLOBAL DEFINES
+ ******************************************************************************
+ */
+
+#define RFAL_NFCB_FWTSENSB 7680U /*!< NFC-B FWT(SENSB) Digital 2.0 B.3 */
+#define RFAL_NFCB_DFWT 49152U /*!< NFC-B dFWT Delta 2.0 7.9.1.3 & B.3 */
+#define RFAL_NFCB_DTPOLL_10 rfalConvMsTo1fc(20) /*!< NFC-B Delta Tb Poll Digital 1.0 A.2 */
+#define RFAL_NFCB_DTPOLL_20 rfalConvMsTo1fc(17) /*!< NFC-B Delta Tb Poll Digital 2.1 B.3 */
+
+#define RFAL_NFCB_AFI 0x00U /*!< NFC-B default Application Family Digital 1.1 7.6.1.1 */
+#define RFAL_NFCB_PARAM 0x00U /*!< NFC-B default SENSB_REQ PARAM */
+#define RFAL_NFCB_CRC_LEN 2U /*!< NFC-B CRC length and CRC_B(AID) Digital 1.1 Table 28 */
+#define RFAL_NFCB_NFCID0_LEN 4U /*!< Length of NFC-B NFCID0 */
+#define RFAL_NFCB_CMD_LEN 1U /*!< Length of NFC-B Command */
+
+#define RFAL_NFCB_SENSB_RES_LEN 12U /*!< Standard length of SENSB_RES without SFGI byte */
+#define RFAL_NFCB_SENSB_RES_EXT_LEN 13U /*!< Extended length of SENSB_RES with SFGI byte */
+
+#define RFAL_NFCB_SENSB_REQ_ADV_FEATURE 0x20U /*!< Bit mask for Advance Feature in SENSB_REQ */
+#define RFAL_NFCB_SENSB_RES_FSCI_MASK 0x0FU /*!< Bit mask for FSCI value in SENSB_RES */
+#define RFAL_NFCB_SENSB_RES_FSCI_SHIFT 4U /*!< Shift for FSCI value in SENSB_RES */
+#define RFAL_NFCB_SENSB_RES_PROTO_RFU_MASK 0x08U /*!< Bit mask for Protocol Type RFU in SENSB_RES */
+#define RFAL_NFCB_SENSB_RES_PROTO_TR2_MASK 0x03U /*!< Bit mask for Protocol Type TR2 in SENSB_RES */
+#define RFAL_NFCB_SENSB_RES_PROTO_TR2_SHIFT 1U /*!< Shift for Protocol Type TR2 in SENSB_RES */
+#define RFAL_NFCB_SENSB_RES_PROTO_ISO_MASK 0x01U /*!< Bit mask Protocol Type ISO14443 Compliant in SENSB_RES */
+#define RFAL_NFCB_SENSB_RES_FWI_MASK 0x0FU /*!< Bit mask for FWI value in SENSB_RES */
+#define RFAL_NFCB_SENSB_RES_FWI_SHIFT 4U /*!< Bit mask for FWI value in SENSB_RES */
+#define RFAL_NFCB_SENSB_RES_ADC_MASK 0x0CU /*!< Bit mask for ADC value in SENSB_RES */
+#define RFAL_NFCB_SENSB_RES_ADC_ADV_FEATURE_MASK 0x08U /*!< Bit mask for ADC.Advanced Proto Features in SENSB_RES */
+#define RFAL_NFCB_SENSB_RES_ADC_PROPRIETARY_MASK 0x04U /*!< Bit mask for ADC.Proprietary Application in SENSB_RES */
+#define RFAL_NFCB_SENSB_RES_FO_DID_MASK 0x01U /*!< Bit mask for DID in SENSB_RES */
+#define RFAL_NFCB_SENSB_RES_FO_NAD_MASK 0x02U /*!< Bit mask for DID in SENSB_RES */
+#define RFAL_NFCB_SENSB_RES_FO_MASK 0x03U /*!< Bit mask for FO value in SENSB_RES (NAD and DID) */
+#define RFAL_NFCB_SENSB_RES_SFGI_MASK 0x0FU /*!< Bit mask for SFGI in SENSB_RES */
+#define RFAL_NFCB_SENSB_RES_SFGI_SHIFT 4U /*!< Shift for SFGI in SENSB_RES */
+
+/*
+******************************************************************************
+* GLOBAL MACROS
+******************************************************************************
+*/
+
+/*! Get device's FSCI given its SENSB_RES Digital 1.1 7.6.2 */
+#define rfalNfcbGetFSCI( sensbRes ) ((((rfalNfcbSensbRes*)(sensbRes))->protInfo.FsciProType >> RFAL_NFCB_SENSB_RES_FSCI_SHIFT) & RFAL_NFCB_SENSB_RES_FSCI_MASK )
+
+/*! Checks if the given NFC-B device indicates ISO-DEP support */
+#define rfalNfcbIsIsoDepSupported( dev ) ( (((rfalNfcbListenDevice*)(dev))->sensbRes.protInfo.FsciProType & RFAL_NFCB_SENSB_RES_PROTO_ISO_MASK) != 0U )
+
+/*
+******************************************************************************
+* GLOBAL TYPES
+******************************************************************************
+*/
+
+/*! SENSB_REQ and ALLB_REQ param Digital 1.1 7.6.1 */
+typedef enum
+{
+ RFAL_NFCB_SENS_CMD_ALLB_REQ = 0x08, /*!< ALLB_REQ (WUPB) */
+ RFAL_NFCB_SENS_CMD_SENSB_REQ = 0x00 /*!< SENSB_REQ (REQB) */
+} rfalNfcbSensCmd;
+
+
+/*! Number of Slots (NI) codes used for NFC-B anti collision Digital 1.1 Table 26 */
+typedef enum
+{
+ RFAL_NFCB_SLOT_NUM_1 = 0, /*!< N=0 : 1 slot */
+ RFAL_NFCB_SLOT_NUM_2 = 1, /*!< N=1 : 2 slots */
+ RFAL_NFCB_SLOT_NUM_4 = 2, /*!< N=2 : 4 slots */
+ RFAL_NFCB_SLOT_NUM_8 = 3, /*!< N=3 : 8 slots */
+ RFAL_NFCB_SLOT_NUM_16 = 4 /*!< N=4 : 16 slots */
+}rfalNfcbSlots;
+
+
+/*! SENSB_RES (ATQB) Application Data Format Digital 1.1 Table 28 */
+typedef struct
+{
+ uint8_t AFI; /*!< Application Family Identifier */
+ uint8_t CRC_B[RFAL_NFCB_CRC_LEN]; /*!< CRC_B of AID */
+ uint8_t numApps; /*!< Number of Applications */
+} rfalNfcbSensbResAppData;
+
+
+/*! SENSB_RES Protocol Info format Digital 1.1 Table 29 */
+typedef struct
+{
+ uint8_t BRC; /*!< Bit Rate Capability */
+ uint8_t FsciProType; /*!< Frame Size Card Integer [4b] | Protocol Type[4 bits] */
+ uint8_t FwiAdcFo; /*!< Frame Waiting Integer [4b] | Application Data Coding [2b] | Frame Options [2b] */
+ uint8_t SFGI; /*!< Optional: Start-Up Frame Guard Time Integer[4b] | RFU [4b] */
+} rfalNfcbSensbResProtocolInfo;
+
+
+/*! SENSB_RES format Digital 1.1 7.6.2 */
+typedef struct
+{
+ uint8_t cmd; /*!< SENSB_RES: 50h */
+ uint8_t nfcid0[RFAL_NFCB_NFCID0_LEN]; /*!< NFC Identifier (PUPI)*/
+ rfalNfcbSensbResAppData appData; /*!< Application Data */
+ rfalNfcbSensbResProtocolInfo protInfo; /*!< Protocol Information */
+} rfalNfcbSensbRes;
+
+
+/*! NFC-B listener device (PICC) struct */
+typedef struct
+{
+ uint8_t sensbResLen; /*!< SENSB_RES length */
+ rfalNfcbSensbRes sensbRes; /*!< SENSB_RES */
+ bool isSleep; /*!< Device sleeping flag */
+}rfalNfcbListenDevice;
+
+/*
+******************************************************************************
+* GLOBAL FUNCTION PROTOTYPES
+******************************************************************************
+*/
+
+/*!
+ *****************************************************************************
+ * \brief Initialize NFC-B Poller mode
+ *
+ * This methods configures RFAL RF layer to perform as a
+ * NFC-B Poller/RW (ISO14443B PCD) including all default timings
+ *
+ * It sets NFC-B parameters (AFI, PARAM) to default values
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or mode not set
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalNfcbPollerInitialize( void );
+
+
+/*!
+ *****************************************************************************
+ * \brief Set NFC-B Poller parameters
+ *
+ * This methods configures RFAL RF layer to perform as a
+ * NFCA Poller/RW (ISO14443A PCD) including all default timings
+ *
+ * Additionally configures NFC-B specific parameters to be used on the
+ * following communications
+ *
+ * \param[in] AFI : Application Family Identifier to be used
+ * \param[in] PARAM : PARAM to be used, it announces whether Advanced
+ * Features or Extended SENSB_RES is supported
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or mode not set
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalNfcbPollerInitializeWithParams( uint8_t AFI, uint8_t PARAM );
+
+
+/*!
+ *****************************************************************************
+ * \brief NFC-B Poller Check Presence
+ *
+ * This method checks if a NFC-B Listen device (PICC) is present on the field
+ * by sending an ALLB_REQ (WUPB) or SENSB_REQ (REQB)
+ *
+ * \param[in] cmd : Indicate if to send an ALLB_REQ or a SENSB_REQ
+ * \param[in] slots : The number of slots to be announced
+ * \param[out] sensbRes : If received, the SENSB_RES
+ * \param[out] sensbResLen : If received, the SENSB_RES length
+ *
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_TIMEOUT : Timeout error, no listener device detected
+ * \return RFAL_ERR_RF_COLLISION : Collision detected one or more device in the field
+ * \return RFAL_ERR_PAR : Parity error detected, one or more device in the field
+ * \return RFAL_ERR_CRC : CRC error detected, one or more device in the field
+ * \return RFAL_ERR_FRAMING : Framing error detected, one or more device in the field
+ * \return RFAL_ERR_PROTO : Protocol error detected, invalid SENSB_RES received
+ * \return RFAL_ERR_NONE : No error, SENSB_RES received
+ *****************************************************************************
+ */
+ReturnCode rfalNfcbPollerCheckPresence( rfalNfcbSensCmd cmd, rfalNfcbSlots slots, rfalNfcbSensbRes *sensbRes, uint8_t *sensbResLen );
+
+
+/*!
+ *****************************************************************************
+ * \brief NFC-B Poller Start Check Presence
+ *
+ * This method starts check for a NFC-B Listen device (PICC) presence on the field
+ * by sending an ALLB_REQ (WUPB) or SENSB_REQ (REQB)
+ *
+ * \param[in] cmd : Indicate if to send an ALL_REQ or a SENS_REQ
+ * \param[in] slots : The number of slots to be announced
+ * \param[out] sensbRes : If received, the SENSB_RES
+ * \param[out] sensbResLen : If received, the SENSB_RES length
+ *
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalNfcbPollerStartCheckPresence( rfalNfcbSensCmd cmd, rfalNfcbSlots slots, rfalNfcbSensbRes *sensbRes, uint8_t *sensbResLen );
+
+
+/*!
+ *****************************************************************************
+ * \brief NFC-B Poller Get Check Presence Status
+ *
+ * This method get the presence check status
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_TIMEOUT : Timeout error, no listener device detected
+ * \return RFAL_ERR_RF_COLLISION : Collision detected one or more device in the field
+ * \return RFAL_ERR_PAR : Parity error detected, one or more device in the field
+ * \return RFAL_ERR_CRC : CRC error detected, one or more device in the field
+ * \return RFAL_ERR_FRAMING : Framing error detected, one or more device in the field
+ * \return RFAL_ERR_PROTO : Protocol error detected, invalid SENSB_RES received
+ * \return RFAL_ERR_BUSY : Operation is ongoing
+ * \return RFAL_ERR_NONE : No error, SENSB_RES received
+ *****************************************************************************
+ */
+ReturnCode rfalNfcbPollerGetCheckPresenceStatus( void );
+
+
+/*!
+ *****************************************************************************
+ * \brief NFC-B Poller Sleep
+ *
+ * This function is used to send the SLPB_REQ (HLTB) command to put the PICC with
+ * the given NFCID0 to state HALT so that they do not reply to further SENSB_REQ
+ * commands (only to ALLB_REQ)
+ *
+ * \param[in] nfcid0 : NFCID of the device to be put to Sleep
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalNfcbPollerSleep( const uint8_t* nfcid0 );
+
+
+/*!
+ *****************************************************************************
+ * \brief NFC-B Poller Slot Marker
+ *
+ * This method sends a NFC-B Slot marker frame
+ *
+ * \param[in] slotCode : Slot Code [1-15]
+ * \param[out] sensbRes : If received, the SENSB_RES
+ * \param[out] sensbResLen : If received, the SENSB_RES length
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_TIMEOUT : Timeout error
+ * \return RFAL_ERR_PAR : Parity error detected
+ * \return RFAL_ERR_CRC : CRC error detected
+ * \return RFAL_ERR_FRAMING : Framing error detected
+ * \return RFAL_ERR_PROTO : Protocol error detected
+ * \return RFAL_ERR_NONE : No error, SEL_RES received
+ *****************************************************************************
+ */
+ReturnCode rfalNfcbPollerSlotMarker( uint8_t slotCode, rfalNfcbSensbRes *sensbRes, uint8_t *sensbResLen );
+
+
+/*!
+ *****************************************************************************
+ * \brief NFC-B Poller Start Slot Marker
+ *
+ * This method starts a NFC-B Slot marker
+ *
+ * \param[in] slotCode : Slot Code [1-15]
+ * \param[out] sensbRes : If received, the SENSB_RES
+ * \param[out] sensbResLen : If received, the SENSB_RES length
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalNfcbPollerStartSlotMarker( uint8_t slotCode, rfalNfcbSensbRes *sensbRes, uint8_t *sensbResLen );
+
+
+/*!
+ *****************************************************************************
+ * \brief NFC-B Poller Get Slot Marker Status
+ *
+ * This method gets the status of the NFC-B Slot marker
+ *
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_TIMEOUT : Timeout error
+ * \return RFAL_ERR_PAR : Parity error detected
+ * \return RFAL_ERR_CRC : CRC error detected
+ * \return RFAL_ERR_FRAMING : Framing error detected
+ * \return RFAL_ERR_PROTO : Protocol error detected
+ * \return RFAL_ERR_BUSY : Operation is ongoing
+ * \return RFAL_ERR_NONE : No error, SEL_RES received
+ *****************************************************************************
+ */
+ReturnCode rfalNfcbPollerGetSlotMarkerStatus( void );
+
+
+/*!
+ *****************************************************************************
+ * \brief NFC-B Technology Detection
+ *
+ * This method performs NFC-B Technology Detection as defined in the spec
+ * given in the compliance mode
+ *
+ * \param[in] compMode : compliance mode to be performed
+ * \param[out] sensbRes : location to store the SENSB_RES, if received
+ * \param[out] sensbResLen : length of the SENSB_RES, if received
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_NONE : No error, one or more device in the field
+ *****************************************************************************
+ */
+ReturnCode rfalNfcbPollerTechnologyDetection( rfalComplianceMode compMode, rfalNfcbSensbRes *sensbRes, uint8_t *sensbResLen );
+
+/*!
+ *****************************************************************************
+ * \brief NFC-B Start Technology Detection
+ *
+ * This method starts the NFC-B Technology Detection as defined in the spec
+ * given in the compliance mode
+ *
+ * \param[in] compMode : compliance mode to be performed
+ * \param[out] sensbRes : location to store the SENSB_RES, if received
+ * \param[out] sensbResLen : length of the SENSB_RES, if received
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalNfcbPollerStartTechnologyDetection( rfalComplianceMode compMode, rfalNfcbSensbRes *sensbRes, uint8_t *sensbResLen );
+
+
+/*!
+ *****************************************************************************
+ * \brief NFC-B Get Technology Detection Status
+ *
+ * This method gets the NFC-B Technology Detection status
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_BUSY : Operation is ongoing
+ * \return RFAL_ERR_NONE : No error, one or more device in the field
+ *****************************************************************************
+ */
+ReturnCode rfalNfcbPollerGetTechnologyDetectionStatus( void );
+
+
+/*!
+ *****************************************************************************
+ * \brief NFC-B Poller Collision Resolution
+ *
+ * NFC-B Collision resolution Listener device/card (PICC) as
+ * defined in Activity 1.1 9.3.5
+ *
+ * This function is used to perform collision resolution for detection in case
+ * of multiple NFC Forum Devices with Technology B detected.
+ * Target with valid SENSB_RES will be stored in nfcbDevList and devCnt incremented.
+ *
+ * \param[in] compMode : compliance mode to be performed
+ * \param[in] devLimit : device limit value, and size nfcbDevList
+ * \param[out] nfcbDevList : NFC-B listener device info
+ * \param[out] devCnt : devices found counter
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or mode not set
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_PROTO : Protocol error detected
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalNfcbPollerCollisionResolution( rfalComplianceMode compMode, uint8_t devLimit, rfalNfcbListenDevice *nfcbDevList, uint8_t *devCnt );
+
+
+/*!
+ *****************************************************************************
+ * \brief NFC-B Poller Collision Resolution Slotted
+ *
+ * NFC-B Collision resolution Listener device/card (PICC). The sequence can
+ * be configured to be according to NFC Forum Activity 1.1 9.3.5, ISO10373
+ * or EMVCo
+ *
+ * This function is used to perform collision resolution for detection in case
+ * of multiple NFC Forum Devices with Technology B are detected.
+ * Target with valid SENSB_RES will be stored in nfcbDevList and devCnt incremented.
+ *
+ * This method provides the means to perform a collision resolution loop with specific
+ * initial and end number of slots. This allows to user to start the loop already with
+ * greater number of slots, and or limit the end number of slots. At the end a flag
+ * indicating whether there were collisions pending is returned.
+ *
+ * If RFAL_COMPLIANCE_MODE_ISO is used \a initSlots must be set to RFAL_NFCB_SLOT_NUM_1
+ *
+ *
+ * \param[in] compMode : compliance mode to be performed
+ * \param[in] devLimit : device limit value, and size nfcbDevList
+ * \param[in] initSlots : number of slots to open initially
+ * \param[in] endSlots : number of slots when to stop collision resolution
+ * \param[out] nfcbDevList : NFC-B listener device info
+ * \param[out] devCnt : devices found counter
+ * \param[out] colPending : flag indicating whether collision are still pending
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or mode not set
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_PROTO : Protocol error detected
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalNfcbPollerSlottedCollisionResolution( rfalComplianceMode compMode, uint8_t devLimit, rfalNfcbSlots initSlots, rfalNfcbSlots endSlots, rfalNfcbListenDevice *nfcbDevList, uint8_t *devCnt, bool *colPending );
+
+
+/*!
+ *****************************************************************************
+ * \brief NFC-B Poller Start Collision Resolution
+ *
+ * It starts the NFC-B Collision resolution Listener device/card (PICC) as
+ * defined in Activity 1.1 9.3.5
+ *
+ * This function is used to trigger the collision resolution for detection in case
+ * of multiple NFC Forum Devices with Technology B detected.
+ * Target with valid SENSB_RES will be stored in nfcbDevList and devCnt incremented.
+ *
+ * \param[in] compMode : compliance mode to be performed
+ * \param[in] devLimit : device limit value, and size nfcbDevList
+ * \param[out] nfcbDevList : NFC-B listener device info
+ * \param[out] devCnt : devices found counter
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or mode not set
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_PROTO : Protocol error detected
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalNfcbPollerStartCollisionResolution( rfalComplianceMode compMode, uint8_t devLimit, rfalNfcbListenDevice *nfcbDevList, uint8_t *devCnt );
+
+
+/*!
+ *****************************************************************************
+ * \brief NFC-B Poller Start Collision Resolution Slotted
+ *
+ * Starts NFC-B Collision resolution Listener device/card (PICC). The sequence can
+ * be configured to be according to NFC Forum Activity 1.1 9.3.5, ISO10373
+ * or EMVCo
+ *
+ * This function is used to trigger the collision resolution for detection in case
+ * of multiple NFC Forum Devices with Technology B are detected.
+ * Target with valid SENSB_RES will be stored in nfcbDevList and devCnt incremented.
+ *
+ * This method provides the means to perform a collision resolution loop with specific
+ * initial and end number of slots. This allows to user to start the loop already with
+ * greater number of slots, and or limit the end number of slots. At the end a flag
+ * indicating whether there were collisions pending is returned.
+ *
+ * If RFAL_COMPLIANCE_MODE_ISO is used \a initSlots must be set to RFAL_NFCB_SLOT_NUM_1
+ *
+ *
+ * \param[in] compMode : compliance mode to be performed
+ * \param[in] devLimit : device limit value, and size nfcbDevList
+ * \param[in] initSlots : number of slots to open initially
+ * \param[in] endSlots : number of slots when to stop collision resolution
+ * \param[out] nfcbDevList : NFC-B listener device info
+ * \param[out] devCnt : devices found counter
+ * \param[out] colPending : flag indicating whether collision are still pending
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or mode not set
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_PROTO : Protocol error detected
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalNfcbPollerStartSlottedCollisionResolution( rfalComplianceMode compMode, uint8_t devLimit, rfalNfcbSlots initSlots, rfalNfcbSlots endSlots, rfalNfcbListenDevice *nfcbDevList, uint8_t *devCnt, bool *colPending );
+
+
+/*!
+ *****************************************************************************
+ * \brief NFC-B Get Collision Resolution Status
+ *
+ * Returns the Collision Resolution status
+ *
+ * \return RFAL_ERR_BUSY : Operation is ongoing
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_TIMEOUT : Timeout error
+ * \return RFAL_ERR_PAR : Parity error detected
+ * \return RFAL_ERR_CRC : CRC error detected
+ * \return RFAL_ERR_FRAMING : Framing error detected
+ * \return RFAL_ERR_PROTO : Protocol error detected
+ * \return RFAL_ERR_BUSY : Operation is ongoing
+ * \return RFAL_ERR_NONE : No error, collision resolution successful
+ *****************************************************************************
+ */
+ReturnCode rfalNfcbPollerGetCollisionResolutionStatus( void );
+
+
+/*!
+ *****************************************************************************
+ * \brief NFC-B TR2 code to FDT
+ *
+ * Converts the TR2 code as defined in Digital 1.1 Table 33 Minimum
+ * TR2 Coding to Frame Delay Time (FDT) in 1/Fc
+ *
+ * \param[in] tr2Code : TR2 code as defined in Digital 1.1 Table 33
+ *
+ * \return FDT in 1/Fc
+ *****************************************************************************
+ */
+uint32_t rfalNfcbTR2ToFDT( uint8_t tr2Code );
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* RFAL_NFCB_H */
+
+/**
+ * @}
+ *
+ * @}
+ *
+ * @}
+ */
### core/embed/io/nfc/st25/rfal002/include/rfal_nfcf.h
@@ -1,455 +1,470 @@
-
-/******************************************************************************
- * @attention
- *
- * COPYRIGHT 2016 STMicroelectronics, all rights reserved
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
- * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
-******************************************************************************/
-
-
-/*
- * PROJECT: ST25R firmware
- * Revision:
- * LANGUAGE: ISO C99
- */
-
-/*! \file rfal_nfcf.h
- *
- * \author Gustavo Patricio
- *
- * \brief Implementation of NFC-F Poller (FeliCa PCD) device
- *
- * The definitions and helpers methods provided by this module are
- * aligned with NFC-F (FeliCa - JIS X6319-4)
- *
- *
- * \addtogroup RFAL
- * @{
- *
- * \addtogroup RFAL-AL
- * \brief RFAL Abstraction Layer
- * @{
- *
- * \addtogroup NFC-F
- * \brief RFAL NFC-F Module
- * @{
- *
- */
-
-
-#ifndef RFAL_NFCF_H
-#define RFAL_NFCF_H
-
-/*
- ******************************************************************************
- * INCLUDES
- ******************************************************************************
- */
-#include "rfal_platform.h"
-#include "rfal_utils.h"
-#include "rfal_rf.h"
-
-/*
- ******************************************************************************
- * GLOBAL DEFINES
- ******************************************************************************
- */
-
-#define RFAL_NFCF_NFCID2_LEN 8U /*!< NFCID2 (FeliCa IDm) length */
-#define RFAL_NFCF_SENSF_RES_LEN_MIN 16U /*!< SENSF_RES minimum length */
-#define RFAL_NFCF_SENSF_RES_LEN_MAX 18U /*!< SENSF_RES maximum length */
-#define RFAL_NFCF_SENSF_RES_PAD0_LEN 2U /*!< SENSF_RES PAD0 length */
-#define RFAL_NFCF_SENSF_RES_PAD1_LEN 3U /*!< SENSF_RES PAD1 length */
-#define RFAL_NFCF_SENSF_RES_RD_LEN 2U /*!< SENSF_RES Request Data length */
-#define RFAL_NFCF_SENSF_RES_BYTE1 1U /*!< SENSF_RES first byte value */
-#define RFAL_NFCF_SENSF_SC_LEN 2U /*!< Felica SENSF_REQ System Code length */
-#define RFAL_NFCF_SENSF_PARAMS_SC1_POS 0U /*!< System Code byte1 position in the SENSF_REQ */
-#define RFAL_NFCF_SENSF_PARAMS_SC2_POS 1U /*!< System Code byte2 position in the SENSF_REQ */
-#define RFAL_NFCF_SENSF_PARAMS_RC_POS 2U /*!< Request Code position in the SENSF_REQ */
-#define RFAL_NFCF_SENSF_PARAMS_TSN_POS 3U /*!< Time Slot Number position in the SENSF_REQ */
-#define RFAL_NFCF_POLL_MAXCARDS 16U /*!< Max number slots/cards 16 */
-
-
-#define RFAL_NFCF_CMD_POS 0U /*!< Command/Responce code length */
-#define RFAL_NFCF_CMD_LEN 1U /*!< Command/Responce code length */
-#define RFAL_NFCF_LENGTH_LEN 1U /*!< LEN field length */
-#define RFAL_NFCF_HEADER_LEN (RFAL_NFCF_LENGTH_LEN + RFAL_NFCF_CMD_LEN) /*!< Header length */
-
-#define RFAL_NFCF_NOS_LEN 1U /*!< Number of Services length */
-#define RFAL_NFCF_NOB_LEN 1U /*!< Number of Blocks length */
-
-
-#define RFAL_NFCF_SENSF_NFCID2_BYTE1_POS 0U /*!< NFCID2 byte1 position */
-#define RFAL_NFCF_SENSF_NFCID2_BYTE2_POS 1U /*!< NFCID2 byte2 position */
-
-#define RFAL_NFCF_SENSF_NFCID2_PROT_TYPE_LEN 2U /*!< NFCID2 length for byte 1 and byte 2 indicating NFC-DEP or T3T support */
-#define RFAL_NFCF_SENSF_NFCID2_BYTE1_NFCDEP 0x01U /*!< NFCID2 byte1 NFC-DEP support Digital 1.0 Table 44 */
-#define RFAL_NFCF_SENSF_NFCID2_BYTE2_NFCDEP 0xFEU /*!< NFCID2 byte2 NFC-DEP support Digital 1.0 Table 44 */
-
-#define RFAL_NFCF_SYSTEMCODE 0xFFFFU /*!< SENSF_RES Default System Code Digital 2.3 8.6.1.5 */
-#define RFAL_NFCF_SYSTEMCODE_LEN 2U /*!< SENSF_RES System Code length Digital 2.3 8.6.1 */
-
-#define RFAL_NFCF_BLOCK_LEN 16U /*!< NFCF T3T Block size T3T 1.0 4.1 */
-#define RFAL_NFCF_CHECKUPDATE_RES_ST1_POS 9U /*!< Check|Update Res Status Flag 1 position T3T 1.0 Table 8 */
-#define RFAL_NFCF_CHECKUPDATE_RES_ST2_POS 10U /*!< Check|Update Res Status Flag 2 position T3T 1.0 Table 8 */
-#define RFAL_NFCF_CHECKUPDATE_RES_NOB_POS 11U /*!< Check|Update Res Number of Blocks position T3T 1.0 Table 8 */
-
-#define RFAL_NFCF_STATUS_FLAG_SUCCESS 0x00U /*!< Check response Number of Blocks position T3T 1.0 Table 11 */
-#define RFAL_NFCF_STATUS_FLAG_ERROR 0xFFU /*!< Check response Number of Blocks position T3T 1.0 Table 11 */
-
-#define RFAL_NFCF_BLOCKLISTELEM_MAX_LEN 3U /*!< Block List Element max Length (3 bytes) T3T 1.0 5.6.1 */
-#define RFAL_NFCF_BLOCKLISTELEM_LEN_BIT 0x80U /*!< Block List Element Length bit (2|3 bytes) T3T 1.0 5.6.1 */
-
-#define RFAL_NFCF_SERVICECODE_RDONLY 0x000BU /*!< NDEF Service Code as Read-Only T3T 1.0 7.2.1 */
-#define RFAL_NFCF_SERVICECODE_RDWR 0x0009U /*!< NDEF Service Code as Read and Write T3T 1.0 7.2.1 */
-
-#define RFAL_NFCF_TEST_LB_CMD0 0xD8U /*!< T3T loopback CMD0 ETSI TS 102 695-1 5.6.4.4.2 */
-#define RFAL_NFCF_TEST_LB_CMD1 0x00U /*!< T3T loopback CMD1 ETSI TS 102 695-1 5.6.4.4.2 */
-
-
-/*! NFC-F Felica command set JIS X6319-4 9.1 */
-enum
-{
- RFAL_NFCF_CMD_POLLING = 0x00, /*!< SENSF_REQ (Felica Poll/REQC command to identify a card ) */
- RFAL_NFCF_CMD_POLLING_RES = 0x01, /*!< SENSF_RES (Felica Poll/REQC command response ) */
- RFAL_NFCF_CMD_REQUEST_SERVICE = 0x02, /*!< verify the existence of Area and Service */
- RFAL_NFCF_CMD_REQUEST_RESPONSE = 0x04, /*!< verify the existence of a card */
- RFAL_NFCF_CMD_READ_WITHOUT_ENCRYPTION = 0x06, /*!< read Block Data from a Service that requires no authentication */
- RFAL_NFCF_CMD_READ_WITHOUT_ENCRYPTION_RES = 0x07, /*!< read Block Data response from a Service with no authentication */
- RFAL_NFCF_CMD_WRITE_WITHOUT_ENCRYPTION = 0x08, /*!< write Block Data to a Service that requires no authentication */
- RFAL_NFCF_CMD_WRITE_WITHOUT_ENCRYPTION_RES = 0x09, /*!< write Block Data response to a Service with no authentication */
- RFAL_NFCF_CMD_REQUEST_SYSTEM_CODE = 0x0c, /*!< acquire the System Code registered to a card */
- RFAL_NFCF_CMD_AUTHENTICATION1 = 0x10, /*!< authenticate a card */
- RFAL_NFCF_CMD_AUTHENTICATION2 = 0x12, /*!< allow a card to authenticate a Reader/Writer */
- RFAL_NFCF_CMD_READ = 0x14, /*!< read Block Data from a Service that requires authentication */
- RFAL_NFCF_CMD_WRITE = 0x16, /*!< write Block Data to a Service that requires authentication */
-};
-
-/*
- ******************************************************************************
- * GLOBAL MACROS
- ******************************************************************************
- */
-
-/*! Checks if the given NFC-F device indicates NFC-DEP support */
-#define rfalNfcfIsNfcDepSupported( dev ) ( (((rfalNfcfListenDevice*)(dev))->sensfRes.NFCID2[RFAL_NFCF_SENSF_NFCID2_BYTE1_POS] == RFAL_NFCF_SENSF_NFCID2_BYTE1_NFCDEP) && \
- (((rfalNfcfListenDevice*)(dev))->sensfRes.NFCID2[RFAL_NFCF_SENSF_NFCID2_BYTE2_POS] == RFAL_NFCF_SENSF_NFCID2_BYTE2_NFCDEP) )
-
-
-/*
-******************************************************************************
-* GLOBAL TYPES
-******************************************************************************
-*/
-
-
-/*! NFC-F SENSF_RES format Digital 1.1 8.6.2 */
-typedef struct
-{
- uint8_t CMD; /*!< Command Code: 01h */
- uint8_t NFCID2[RFAL_NFCF_NFCID2_LEN]; /*!< NFCID2 */
- uint8_t PAD0[RFAL_NFCF_SENSF_RES_PAD0_LEN]; /*!< PAD0 */
- uint8_t PAD1[RFAL_NFCF_SENSF_RES_PAD1_LEN]; /*!< PAD1 */
- uint8_t MRTIcheck; /*!< MRTIcheck */
- uint8_t MRTIupdate; /*!< MRTIupdate */
- uint8_t PAD2; /*!< PAD2 */
- uint8_t RD[RFAL_NFCF_SENSF_RES_RD_LEN]; /*!< Request Data */
-} rfalNfcfSensfRes;
-
-
-/*! NFC-F poller device (PCD) struct */
-typedef struct
-{
- uint8_t NFCID2[RFAL_NFCF_NFCID2_LEN]; /*!< NFCID2 */
-} rfalNfcfPollDevice;
-
-/*! NFC-F listener device (PICC) struct */
-typedef struct
-{
- uint8_t sensfResLen; /*!< SENF_RES length */
- rfalNfcfSensfRes sensfRes; /*!< SENF_RES */
-} rfalNfcfListenDevice;
-
-typedef uint16_t rfalNfcfServ; /*!< NFC-F Service Code */
-
-/*! NFC-F Block List Element (2 or 3 bytes element) T3T 1.0 5.6.1 */
-typedef struct
-{
- uint8_t conf; /*!< Access Mode | Serv Code List Order */
- uint16_t blockNum; /*!< Block Number */
-}rfalNfcfBlockListElem;
-
-/*! Check Update Service list and Block list parameter */
-typedef struct
-{
- uint8_t numServ; /*!< Number of Services */
- rfalNfcfServ *servList; /*!< Service Code List */
- uint8_t numBlock; /*!< Number of Blocks */
- rfalNfcfBlockListElem *blockList; /*!< Block Number List */
-}rfalNfcfServBlockListParam;
-
-
-/*
-******************************************************************************
-* GLOBAL FUNCTION PROTOTYPES
-******************************************************************************
-*/
-
-/*!
- *****************************************************************************
- * \brief Initialize NFC-F Poller mode
- *
- * This methods configures RFAL RF layer to perform as a
- * NFC-F Poller/RW (FeliCa PCD) including all default timings
- *
- * \param[in] bitRate : NFC-F bitrate to be initialize (212 or 424)
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or mode not set
- * \return RFAL_ERR_PARAM : Incorrect bitrate
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalNfcfPollerInitialize( rfalBitRate bitRate );
-
-
-/*!
- *****************************************************************************
- * \brief NFC-F Poller Check Presence
- *
- * This function sends a Poll/SENSF command according to NFC Activity spec
- * It detects if a NCF-F device is within range
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_CRC : CRC error detected
- * \return RFAL_ERR_FRAMING : Framing error detected
- * \return RFAL_ERR_PROTO : Protocol error detected
- * \return RFAL_ERR_TIMEOUT : Timeout error, no listener device detected
- * \return RFAL_ERR_NONE : No error and some NFC-F device was detected
- *
- *****************************************************************************
- */
-ReturnCode rfalNfcfPollerCheckPresence( void );
-
-
-/*!
- *****************************************************************************
- * \brief NFC-F Poller Start Check Presence
- *
- * This function triggers a Poll/SENSF command according to NFC Activity spec
- * It detects if a NCF-F device is within range
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_NONE : No error and some NFC-F device was detected
- *
- *****************************************************************************
- */
-ReturnCode rfalNfcfPollerStartCheckPresence( void );
-
-
-/*!
- *****************************************************************************
- * \brief NFC-F Poller Get Check Presence Status
- *
- * This function gets the status of the Check Presense operation
- * triggered by rfalNfcfPollerStartCheckPresence()
- *
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_CRC : CRC error detected
- * \return RFAL_ERR_FRAMING : Framing error detected
- * \return RFAL_ERR_PROTO : Protocol error detected
- * \return RFAL_ERR_TIMEOUT : Timeout error, no listener device detected
- * \return RFAL_ERR_NONE : No error and some NFC-F device was detected
- *
- *****************************************************************************
- */
-ReturnCode rfalNfcfPollerGetCheckPresenceStatus( void );
-
-
-/*!
- *****************************************************************************
- * \brief NFC-F Poller Poll
- *
- * This function sends to all PICCs in field the POLL command with the given
- * number of slots.
- *
- * \param[in] slots : the number of slots to be performed
- * \param[in] sysCode : as given in FeliCa poll command
- * \param[in] reqCode : FeliCa communication parameters
- * \param[out] cardList : Parameter of type rfalFeliCaPollRes which will hold the cards found
- * \param[out] devCnt : actual number of cards found
- * \param[out] collisions : number of collisions encountered
- *
- * \warning the list cardList has to be as big as the number of slots for the Poll
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_CRC : CRC error detected
- * \return RFAL_ERR_FRAMING : Framing error detected
- * \return RFAL_ERR_PROTO : Protocol error detected
- * \return RFAL_ERR_TIMEOUT : Timeout error, no listener device detected
- * \return RFAL_ERR_NONE : No error and some NFC-F device was detected
- *
- *****************************************************************************
- */
-ReturnCode rfalNfcfPollerPoll( rfalFeliCaPollSlots slots, uint16_t sysCode, uint8_t reqCode, rfalFeliCaPollRes *cardList, uint8_t *devCnt, uint8_t *collisions );
-
-
-/*!
- *****************************************************************************
- * \brief NFC-F Poller Full Collision Resolution
- *
- * Performs a full Collision resolution as defined in Activity 1.1 9.3.4
- *
- * \param[in] compMode : compliance mode to be performed
- * \param[in] devLimit : device limit value, and size nfcaDevList
- * \param[out] nfcfDevList : NFC-F listener devices list
- * \param[out] devCnt : Devices found counter
- *
- * NFC-F Collision Resolution uses information collected at Technlology dectection (if
- * provided on nfcfDevList). Technology Detection shall be performed using 4 slots, therefore
- * at least 4 slots/devLimit shall be allocated on nfcfDevList.
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or mode not set
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalNfcfPollerCollisionResolution( rfalComplianceMode compMode, uint8_t devLimit, rfalNfcfListenDevice *nfcfDevList, uint8_t *devCnt );
-
-
-/*!
- *****************************************************************************
- * \brief NFC-F Start Poller Collision Resolution
- *
- * Triggers a Collision Resolution as defined in Activity 2.1 9.3.6
- *
- * NFC-F Collision Resolution uses information collected at Technlology dectection (if
- * provided on nfcfDevList). Technology Detection shall be performed using 4 slots, therefore
- * at least 4 slots/devLimit shall be allocated on nfcfDevList.
- *
- * \param[in] compMode : compliance mode to be performed
- * \param[in] devLimit : device limit value, and size nfcaDevList
- * \param[out] nfcfDevList : NFC-F listener devices list
- * \param[out] devCnt : Devices found counter
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or mode not set
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalNfcfPollerStartCollisionResolution( rfalComplianceMode compMode, uint8_t devLimit, rfalNfcfListenDevice *nfcfDevList, uint8_t *devCnt );
-
-
-/*!
- *****************************************************************************
- * \brief NFC-F Poller Get Collision Resolution Status
- *
- * This function gets the status of the Collision Resolution operation
- * triggered by rfalNfcfPollerStartCollisionResolution()
- *
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_CRC : CRC error detected
- * \return RFAL_ERR_FRAMING : Framing error detected
- * \return RFAL_ERR_PROTO : Protocol error detected
- * \return RFAL_ERR_TIMEOUT : Timeout error, no listener device detected
- * \return RFAL_ERR_NONE : No error and some NFC-F device was detected
- *
- *****************************************************************************
- */
-ReturnCode rfalNfcfPollerGetCollisionResolutionStatus( void );
-
-
-/*!
- *****************************************************************************
- * \brief NFC-F Poller Check/Read
- *
- * It computes a Check / Read command accoring to T3T 1.0 and JIS X6319-4 and
- * sends it to PICC. If sucessfully, the rxBuf will contain the the number of
- * blocks in the first byte followed by the blocks data.
- *
- * \param[in] nfcid2 : nfcid2 of the device
- * \param[in] servBlock : parameter containing the list of Services and
- * Blocks to be addressed by this command
- * \param[out] rxBuf : buffer to place check/read data
- * \param[in] rxBufLen : size of the rxBuf
- * \param[out] rcvdLen : length of data placed in rxBuf
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or mode not set
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_REQUEST : The request was executed with error
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalNfcfPollerCheck( const uint8_t* nfcid2, const rfalNfcfServBlockListParam *servBlock, uint8_t *rxBuf, uint16_t rxBufLen, uint16_t *rcvdLen );
-
-
-/*!
- *****************************************************************************
- * \brief NFC-F Poller Update/Write
- *
- * It computes a Update / Write command accoring to T3T 1.0 and JIS X6319-4 and
- * sends it to PICC.
- *
- * \param[in] nfcid2 : nfcid2 of the device
- * \param[in] servBlock : parameter containing the list of Services and
- * Blocks to be addressed by this command
- * \param[in] txBuf : buffer where the request will be composed
- * \param[in] txBufLen : size of txBuf
- * \param[in] blockData : data to written on the given block(s)
- * \param[out] rxBuf : buffer to place check/read data
- * \param[in] rxBufLen : size of the rxBuf
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or mode not set
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_REQUEST : The request was executed with error
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalNfcfPollerUpdate( const uint8_t* nfcid2, const rfalNfcfServBlockListParam *servBlock, uint8_t *txBuf, uint16_t txBufLen, const uint8_t *blockData, uint8_t *rxBuf, uint16_t rxBufLen);
-
-/*!
- *****************************************************************************
- * \brief NFC-F Listener is T3T Request
- *
- * This method checks if the given data is a valid T3T command (Read or Write)
- * and in case a valid request has been received it may output the request's NFCID2
- *
- * \param[in] buf : buffer holding Initiator's received command
- * \param[in] bufLen : length of received command in bytes
- * \param[out] nfcid2 : pointer to where the NFCID2 may be outputed,
- * nfcid2 has NFCF_SENSF_NFCID2_LEN as length
- * Pass NULL if output parameter not desired
- *
- * \return true : Valid T3T command (Read or Write) received
- * \return false : Invalid protocol request
- *
- *****************************************************************************
- */
-bool rfalNfcfListenerIsT3TReq( const uint8_t* buf, uint16_t bufLen, uint8_t* nfcid2 );
-
-
-#endif /* RFAL_NFCF_H */
-
-/**
- * @}
- *
- * @}
- *
- * @}
- */
+
+/******************************************************************************
+ * @attention
+ *
+ * COPYRIGHT 2016 STMicroelectronics, all rights reserved
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
+ * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+******************************************************************************/
+
+
+/*
+ * PROJECT: ST25R firmware
+ * Revision:
+ * LANGUAGE: ISO C99
+ */
+
+/*! \file rfal_nfcf.h
+ *
+ * \author Gustavo Patricio
+ *
+ * \brief Implementation of NFC-F Poller (FeliCa PCD) device
+ *
+ * The definitions and helpers methods provided by this module are
+ * aligned with NFC-F (FeliCa - JIS X6319-4)
+ *
+ *
+ * \addtogroup RFAL
+ * @{
+ *
+ * \addtogroup RFAL-AL
+ * \brief RFAL Abstraction Layer
+ * @{
+ *
+ * \addtogroup NFC-F
+ * \brief RFAL NFC-F Module
+ * @{
+ *
+ */
+
+
+#ifndef RFAL_NFCF_H
+#define RFAL_NFCF_H
+
+/*
+ ******************************************************************************
+ * INCLUDES
+ ******************************************************************************
+ */
+#include "rfal_platform.h"
+#include "rfal_utils.h"
+#include "rfal_rf.h"
+
+/*
+ ******************************************************************************
+ * C LINKAGE GUARD
+ ******************************************************************************
+ */
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/*
+ ******************************************************************************
+ * GLOBAL DEFINES
+ ******************************************************************************
+ */
+
+#define RFAL_NFCF_NFCID2_LEN 8U /*!< NFCID2 (FeliCa IDm) length */
+#define RFAL_NFCF_SENSF_RES_LEN_MIN 16U /*!< SENSF_RES minimum length */
+#define RFAL_NFCF_SENSF_RES_LEN_MAX 18U /*!< SENSF_RES maximum length */
+#define RFAL_NFCF_SENSF_RES_PAD0_LEN 2U /*!< SENSF_RES PAD0 length */
+#define RFAL_NFCF_SENSF_RES_PAD1_LEN 3U /*!< SENSF_RES PAD1 length */
+#define RFAL_NFCF_SENSF_RES_RD_LEN 2U /*!< SENSF_RES Request Data length */
+#define RFAL_NFCF_SENSF_RES_BYTE1 1U /*!< SENSF_RES first byte value */
+#define RFAL_NFCF_SENSF_SC_LEN 2U /*!< Felica SENSF_REQ System Code length */
+#define RFAL_NFCF_SENSF_PARAMS_SC1_POS 0U /*!< System Code byte1 position in the SENSF_REQ */
+#define RFAL_NFCF_SENSF_PARAMS_SC2_POS 1U /*!< System Code byte2 position in the SENSF_REQ */
+#define RFAL_NFCF_SENSF_PARAMS_RC_POS 2U /*!< Request Code position in the SENSF_REQ */
+#define RFAL_NFCF_SENSF_PARAMS_TSN_POS 3U /*!< Time Slot Number position in the SENSF_REQ */
+#define RFAL_NFCF_POLL_MAXCARDS 16U /*!< Max number slots/cards 16 */
+
+
+#define RFAL_NFCF_CMD_POS 0U /*!< Command/Response code length */
+#define RFAL_NFCF_CMD_LEN 1U /*!< Command/Response code length */
+#define RFAL_NFCF_LENGTH_LEN 1U /*!< LEN field length */
+#define RFAL_NFCF_HEADER_LEN (RFAL_NFCF_LENGTH_LEN + RFAL_NFCF_CMD_LEN) /*!< Header length */
+
+#define RFAL_NFCF_NOS_LEN 1U /*!< Number of Services length */
+#define RFAL_NFCF_NOB_LEN 1U /*!< Number of Blocks length */
+
+
+#define RFAL_NFCF_SENSF_NFCID2_BYTE1_POS 0U /*!< NFCID2 byte1 position */
+#define RFAL_NFCF_SENSF_NFCID2_BYTE2_POS 1U /*!< NFCID2 byte2 position */
+
+#define RFAL_NFCF_SENSF_NFCID2_PROT_TYPE_LEN 2U /*!< NFCID2 length for byte 1 and byte 2 indicating NFC-DEP or T3T support */
+#define RFAL_NFCF_SENSF_NFCID2_BYTE1_NFCDEP 0x01U /*!< NFCID2 byte1 NFC-DEP support Digital 1.0 Table 44 */
+#define RFAL_NFCF_SENSF_NFCID2_BYTE2_NFCDEP 0xFEU /*!< NFCID2 byte2 NFC-DEP support Digital 1.0 Table 44 */
+
+#define RFAL_NFCF_SYSTEMCODE 0xFFFFU /*!< SENSF_RES Default System Code Digital 2.3 8.6.1.5 */
+#define RFAL_NFCF_SYSTEMCODE_LEN 2U /*!< SENSF_RES System Code length Digital 2.3 8.6.1 */
+
+#define RFAL_NFCF_BLOCK_LEN 16U /*!< NFCF T3T Block size T3T 1.0 4.1 */
+#define RFAL_NFCF_CHECKUPDATE_RES_ST1_POS 9U /*!< Check|Update Res Status Flag 1 position T3T 1.0 Table 8 */
+#define RFAL_NFCF_CHECKUPDATE_RES_ST2_POS 10U /*!< Check|Update Res Status Flag 2 position T3T 1.0 Table 8 */
+#define RFAL_NFCF_CHECKUPDATE_RES_NOB_POS 11U /*!< Check|Update Res Number of Blocks position T3T 1.0 Table 8 */
+
+#define RFAL_NFCF_STATUS_FLAG_SUCCESS 0x00U /*!< Check response Number of Blocks position T3T 1.0 Table 11 */
+#define RFAL_NFCF_STATUS_FLAG_ERROR 0xFFU /*!< Check response Number of Blocks position T3T 1.0 Table 11 */
+
+#define RFAL_NFCF_BLOCKLISTELEM_MAX_LEN 3U /*!< Block List Element max Length (3 bytes) T3T 1.0 5.6.1 */
+#define RFAL_NFCF_BLOCKLISTELEM_LEN_BIT 0x80U /*!< Block List Element Length bit (2|3 bytes) T3T 1.0 5.6.1 */
+
+#define RFAL_NFCF_SERVICECODE_RDONLY 0x000BU /*!< NDEF Service Code as Read-Only T3T 1.0 7.2.1 */
+#define RFAL_NFCF_SERVICECODE_RDWR 0x0009U /*!< NDEF Service Code as Read and Write T3T 1.0 7.2.1 */
+
+#define RFAL_NFCF_TEST_LB_CMD0 0xD8U /*!< T3T loopback CMD0 ETSI TS 102 695-1 5.6.4.4.2 */
+#define RFAL_NFCF_TEST_LB_CMD1 0x00U /*!< T3T loopback CMD1 ETSI TS 102 695-1 5.6.4.4.2 */
+
+
+/*! NFC-F Felica command set JIS X6319-4 9.1 */
+enum
+{
+ RFAL_NFCF_CMD_POLLING = 0x00, /*!< SENSF_REQ (Felica Poll/REQC command to identify a card ) */
+ RFAL_NFCF_CMD_POLLING_RES = 0x01, /*!< SENSF_RES (Felica Poll/REQC command response ) */
+ RFAL_NFCF_CMD_REQUEST_SERVICE = 0x02, /*!< verify the existence of Area and Service */
+ RFAL_NFCF_CMD_REQUEST_RESPONSE = 0x04, /*!< verify the existence of a card */
+ RFAL_NFCF_CMD_READ_WITHOUT_ENCRYPTION = 0x06, /*!< read Block Data from a Service that requires no authentication */
+ RFAL_NFCF_CMD_READ_WITHOUT_ENCRYPTION_RES = 0x07, /*!< read Block Data response from a Service with no authentication */
+ RFAL_NFCF_CMD_WRITE_WITHOUT_ENCRYPTION = 0x08, /*!< write Block Data to a Service that requires no authentication */
+ RFAL_NFCF_CMD_WRITE_WITHOUT_ENCRYPTION_RES = 0x09, /*!< write Block Data response to a Service with no authentication */
+ RFAL_NFCF_CMD_REQUEST_SYSTEM_CODE = 0x0c, /*!< acquire the System Code registered to a card */
+ RFAL_NFCF_CMD_AUTHENTICATION1 = 0x10, /*!< authenticate a card */
+ RFAL_NFCF_CMD_AUTHENTICATION2 = 0x12, /*!< allow a card to authenticate a Reader/Writer */
+ RFAL_NFCF_CMD_READ = 0x14, /*!< read Block Data from a Service that requires authentication */
+ RFAL_NFCF_CMD_WRITE = 0x16, /*!< write Block Data to a Service that requires authentication */
+};
+
+/*
+ ******************************************************************************
+ * GLOBAL MACROS
+ ******************************************************************************
+ */
+
+/*! Checks if the given NFC-F device indicates NFC-DEP support */
+#define rfalNfcfIsNfcDepSupported( dev ) ( (((rfalNfcfListenDevice*)(dev))->sensfRes.NFCID2[RFAL_NFCF_SENSF_NFCID2_BYTE1_POS] == RFAL_NFCF_SENSF_NFCID2_BYTE1_NFCDEP) && \
+ (((rfalNfcfListenDevice*)(dev))->sensfRes.NFCID2[RFAL_NFCF_SENSF_NFCID2_BYTE2_POS] == RFAL_NFCF_SENSF_NFCID2_BYTE2_NFCDEP) )
+
+
+/*
+******************************************************************************
+* GLOBAL TYPES
+******************************************************************************
+*/
+
+
+/*! NFC-F SENSF_RES format Digital 1.1 8.6.2 */
+typedef struct
+{
+ uint8_t CMD; /*!< Command Code: 01h */
+ uint8_t NFCID2[RFAL_NFCF_NFCID2_LEN]; /*!< NFCID2 */
+ uint8_t PAD0[RFAL_NFCF_SENSF_RES_PAD0_LEN]; /*!< PAD0 */
+ uint8_t PAD1[RFAL_NFCF_SENSF_RES_PAD1_LEN]; /*!< PAD1 */
+ uint8_t MRTIcheck; /*!< MRTIcheck */
+ uint8_t MRTIupdate; /*!< MRTIupdate */
+ uint8_t PAD2; /*!< PAD2 */
+ uint8_t RD[RFAL_NFCF_SENSF_RES_RD_LEN]; /*!< Request Data */
+} rfalNfcfSensfRes;
+
+
+/*! NFC-F poller device (PCD) struct */
+typedef struct
+{
+ uint8_t NFCID2[RFAL_NFCF_NFCID2_LEN]; /*!< NFCID2 */
+} rfalNfcfPollDevice;
+
+/*! NFC-F listener device (PICC) struct */
+typedef struct
+{
+ uint8_t sensfResLen; /*!< SENF_RES length */
+ rfalNfcfSensfRes sensfRes; /*!< SENF_RES */
+} rfalNfcfListenDevice;
+
+typedef uint16_t rfalNfcfServ; /*!< NFC-F Service Code */
+
+/*! NFC-F Block List Element (2 or 3 bytes element) T3T 1.0 5.6.1 */
+typedef struct
+{
+ uint8_t conf; /*!< Access Mode | Serv Code List Order */
+ uint16_t blockNum; /*!< Block Number */
+}rfalNfcfBlockListElem;
+
+/*! Check Update Service list and Block list parameter */
+typedef struct
+{
+ uint8_t numServ; /*!< Number of Services */
+ rfalNfcfServ *servList; /*!< Service Code List */
+ uint8_t numBlock; /*!< Number of Blocks */
+ rfalNfcfBlockListElem *blockList; /*!< Block Number List */
+}rfalNfcfServBlockListParam;
+
+
+/*
+******************************************************************************
+* GLOBAL FUNCTION PROTOTYPES
+******************************************************************************
+*/
+
+/*!
+ *****************************************************************************
+ * \brief Initialize NFC-F Poller mode
+ *
+ * This methods configures RFAL RF layer to perform as a
+ * NFC-F Poller/RW (FeliCa PCD) including all default timings
+ *
+ * \param[in] bitRate : NFC-F bitrate to be initialize (212 or 424)
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or mode not set
+ * \return RFAL_ERR_PARAM : Incorrect bitrate
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalNfcfPollerInitialize( rfalBitRate bitRate );
+
+
+/*!
+ *****************************************************************************
+ * \brief NFC-F Poller Check Presence
+ *
+ * This function sends a Poll/SENSF command according to NFC Activity spec
+ * It detects if a NCF-F device is within range
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_CRC : CRC error detected
+ * \return RFAL_ERR_FRAMING : Framing error detected
+ * \return RFAL_ERR_PROTO : Protocol error detected
+ * \return RFAL_ERR_TIMEOUT : Timeout error, no listener device detected
+ * \return RFAL_ERR_NONE : No error and some NFC-F device was detected
+ *
+ *****************************************************************************
+ */
+ReturnCode rfalNfcfPollerCheckPresence( void );
+
+
+/*!
+ *****************************************************************************
+ * \brief NFC-F Poller Start Check Presence
+ *
+ * This function triggers a Poll/SENSF command according to NFC Activity spec
+ * It detects if a NCF-F device is within range
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_NONE : No error
+ *
+ *****************************************************************************
+ */
+ReturnCode rfalNfcfPollerStartCheckPresence( void );
+
+
+/*!
+ *****************************************************************************
+ * \brief NFC-F Poller Get Check Presence Status
+ *
+ * This function gets the status of the Check Presense operation
+ * triggered by rfalNfcfPollerStartCheckPresence()
+ *
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_CRC : CRC error detected
+ * \return RFAL_ERR_FRAMING : Framing error detected
+ * \return RFAL_ERR_PROTO : Protocol error detected
+ * \return RFAL_ERR_TIMEOUT : Timeout error, no listener device detected
+ * \return RFAL_ERR_BUSY : Operation is ongoing
+ * \return RFAL_ERR_NONE : No error and some NFC-F device was detected
+ *
+ *****************************************************************************
+ */
+ReturnCode rfalNfcfPollerGetCheckPresenceStatus( void );
+
+
+/*!
+ *****************************************************************************
+ * \brief NFC-F Poller Poll
+ *
+ * This function sends to all PICCs in field the POLL command with the given
+ * number of slots.
+ *
+ * \param[in] slots : the number of slots to be performed
+ * \param[in] sysCode : as given in FeliCa poll command
+ * \param[in] reqCode : FeliCa communication parameters
+ * \param[out] cardList : Parameter of type rfalFeliCaPollRes which will hold the cards found
+ * \param[out] devCnt : actual number of cards found
+ * \param[out] collisions : number of collisions encountered
+ *
+ * \warning the list cardList has to be as big as the number of slots for the Poll
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_CRC : CRC error detected
+ * \return RFAL_ERR_FRAMING : Framing error detected
+ * \return RFAL_ERR_PROTO : Protocol error detected
+ * \return RFAL_ERR_TIMEOUT : Timeout error, no listener device detected
+ * \return RFAL_ERR_NONE : No error and some NFC-F device was detected
+ *
+ *****************************************************************************
+ */
+ReturnCode rfalNfcfPollerPoll( rfalFeliCaPollSlots slots, uint16_t sysCode, uint8_t reqCode, rfalFeliCaPollRes *cardList, uint8_t *devCnt, uint8_t *collisions );
+
+
+/*!
+ *****************************************************************************
+ * \brief NFC-F Poller Full Collision Resolution
+ *
+ * Performs a full Collision resolution as defined in Activity 1.1 9.3.4
+ *
+ * \param[in] compMode : compliance mode to be performed
+ * \param[in] devLimit : device limit value, and size nfcaDevList
+ * \param[out] nfcfDevList : NFC-F listener devices list
+ * \param[out] devCnt : Devices found counter
+ *
+ * NFC-F Collision Resolution uses information collected at Technlology dectection (if
+ * provided on nfcfDevList). Technology Detection shall be performed using 4 slots, therefore
+ * at least 4 slots/devLimit shall be allocated on nfcfDevList.
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or mode not set
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalNfcfPollerCollisionResolution( rfalComplianceMode compMode, uint8_t devLimit, rfalNfcfListenDevice *nfcfDevList, uint8_t *devCnt );
+
+
+/*!
+ *****************************************************************************
+ * \brief NFC-F Start Poller Collision Resolution
+ *
+ * Triggers a Collision Resolution as defined in Activity 2.1 9.3.6
+ *
+ * NFC-F Collision Resolution uses information collected at Technlology dectection (if
+ * provided on nfcfDevList). Technology Detection shall be performed using 4 slots, therefore
+ * at least 4 slots/devLimit shall be allocated on nfcfDevList.
+ *
+ * \param[in] compMode : compliance mode to be performed
+ * \param[in] devLimit : device limit value, and size nfcaDevList
+ * \param[out] nfcfDevList : NFC-F listener devices list
+ * \param[out] devCnt : Devices found counter
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or mode not set
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalNfcfPollerStartCollisionResolution( rfalComplianceMode compMode, uint8_t devLimit, rfalNfcfListenDevice *nfcfDevList, uint8_t *devCnt );
+
+
+/*!
+ *****************************************************************************
+ * \brief NFC-F Poller Get Collision Resolution Status
+ *
+ * This function gets the status of the Collision Resolution operation
+ * triggered by rfalNfcfPollerStartCollisionResolution()
+ *
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_CRC : CRC error detected
+ * \return RFAL_ERR_FRAMING : Framing error detected
+ * \return RFAL_ERR_PROTO : Protocol error detected
+ * \return RFAL_ERR_TIMEOUT : Timeout error, no listener device detected
+ * \return RFAL_ERR_BUSY : Operation is ongoing
+ * \return RFAL_ERR_NONE : No error and some NFC-F device was detected
+ *
+ *****************************************************************************
+ */
+ReturnCode rfalNfcfPollerGetCollisionResolutionStatus( void );
+
+
+/*!
+ *****************************************************************************
+ * \brief NFC-F Poller Check/Read
+ *
+ * It computes a Check / Read command accoring to T3T 1.0 and JIS X6319-4 and
+ * sends it to PICC. If successful, the rxBuf will contain the the number of
+ * blocks in the first byte followed by the blocks data.
+ *
+ * \param[in] nfcid2 : nfcid2 of the device
+ * \param[in] servBlock : parameter containing the list of Services and
+ * Blocks to be addressed by this command
+ * \param[out] rxBuf : buffer to place check/read data
+ * \param[in] rxBufLen : size of the rxBuf
+ * \param[out] rcvdLen : length of data placed in rxBuf
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or mode not set
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_REQUEST : The request was executed with error
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalNfcfPollerCheck( const uint8_t* nfcid2, const rfalNfcfServBlockListParam *servBlock, uint8_t *rxBuf, uint16_t rxBufLen, uint16_t *rcvdLen );
+
+
+/*!
+ *****************************************************************************
+ * \brief NFC-F Poller Update/Write
+ *
+ * It computes a Update / Write command accoring to T3T 1.0 and JIS X6319-4 and
+ * sends it to PICC.
+ *
+ * \param[in] nfcid2 : nfcid2 of the device
+ * \param[in] servBlock : parameter containing the list of Services and
+ * Blocks to be addressed by this command
+ * \param[in] txBuf : buffer where the request will be composed
+ * \param[in] txBufLen : size of txBuf
+ * \param[in] blockData : data to written on the given block(s)
+ * \param[out] rxBuf : buffer to place check/read data
+ * \param[in] rxBufLen : size of the rxBuf
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or mode not set
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_REQUEST : The request was executed with error
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalNfcfPollerUpdate( const uint8_t* nfcid2, const rfalNfcfServBlockListParam *servBlock, uint8_t *txBuf, uint16_t txBufLen, const uint8_t *blockData, uint8_t *rxBuf, uint16_t rxBufLen);
+
+/*!
+ *****************************************************************************
+ * \brief NFC-F Listener is T3T Request
+ *
+ * This method checks if the given data is a valid T3T command (Read or Write)
+ * and in case a valid request has been received it may output the request's NFCID2
+ *
+ * \param[in] buf : buffer holding Initiator's received command
+ * \param[in] bufLen : length of received command in bytes
+ * \param[out] nfcid2 : pointer to where the NFCID2 may be outputed,
+ * nfcid2 has NFCF_SENSF_NFCID2_LEN as length
+ * Pass NULL if output parameter not desired
+ *
+ * \return true : Valid T3T command (Read or Write) received
+ * \return false : Invalid protocol request
+ *
+ *****************************************************************************
+ */
+bool rfalNfcfListenerIsT3TReq( const uint8_t* buf, uint16_t bufLen, uint8_t* nfcid2 );
+
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* RFAL_NFCF_H */
+
+/**
+ * @}
+ *
+ * @}
+ *
+ * @}
+ */
### core/embed/io/nfc/st25/rfal002/include/rfal_nfcv.h
@@ -1,769 +1,782 @@
-
-/******************************************************************************
- * @attention
- *
- * COPYRIGHT 2016 STMicroelectronics, all rights reserved
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
- * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
-******************************************************************************/
-
-
-/*
- * PROJECT: ST25R firmware
- * Revision:
- * LANGUAGE: ISO C99
- */
-
-/*! \file rfal_nfcv.h
- *
- * \author Gustavo Patricio
- *
- * \brief Implementation of NFC-V Poller (ISO15693) device
- *
- * The definitions and helpers methods provided by this module
- * are aligned with NFC-V Digital 2.1
- *
- *
- * \addtogroup RFAL
- * @{
- *
- * \addtogroup RFAL-AL
- * \brief RFAL Abstraction Layer
- * @{
- *
- * \addtogroup NFC-V
- * \brief RFAL NFC-V Module
- * @{
- *
- */
-
-#ifndef RFAL_NFCV_H
-#define RFAL_NFCV_H
-
-/*
- ******************************************************************************
- * INCLUDES
- ******************************************************************************
- */
-#include "rfal_platform.h"
-#include "rfal_utils.h"
-#include "rfal_rf.h"
-
-/*
- ******************************************************************************
- * GLOBAL DEFINES
- ******************************************************************************
- */
-
-#define RFAL_NFCV_UID_LEN 8U /*!< NFC-V UID length */
-#define RFAL_NFCV_MAX_BLOCK_LEN 32U /*!< Max Block size: can be of up to 256 bits ISO 15693 2000 5 */
-#define RFAL_NFCV_BNO_LEN 1U /*!< NFC-V Block Number length */
-#define RFAL_NFCV_CRC_LEN 2U /*!< NFC-V CRC length */
-#define RFAL_NFCV_MAX_GEN_DATA_LEN (RFAL_NFCV_MAX_BLOCK_LEN + RFAL_NFCV_BNO_LEN + RFAL_NFCV_UID_LEN) /*!<Max data */
-#define RFAL_NFCV_BLOCKNUM_LEN 1U /*!< Block Number length on normal commands: 8 bits */
-#define RFAL_NFCV_BLOCKNUM_EXTENDED_LEN 2U /*!< Block Number length on extended commands: 16 bits */
-#define RFAL_NFCV_PARAM_SKIP 0U /*!< Skip proprietary Param Request */
-#define RFAL_NFCV_ST_IC_MFG_CODE 0x02U /*!< ST IC Mfg code (used for custom commands) */
-
-
-
-/*! NFC-V RequestFlags ISO15693 2000 7.3.1 */
-enum{
- RFAL_NFCV_REQ_FLAG_DEFAULT = 0x02U, /*!< Default Request Flags */
- RFAL_NFCV_REQ_FLAG_SUB_CARRIER = 0x01U, /*!< Sub Carrier flag */
- RFAL_NFCV_REQ_FLAG_DATA_RATE = 0x02U, /*!< Data Rate flag */
- RFAL_NFCV_REQ_FLAG_INVENTORY = 0x04U, /*!< Inventory flag */
- RFAL_NFCV_REQ_FLAG_PROTOCOL_EXT = 0x08U, /*!< Protocol Extension flag */
- RFAL_NFCV_REQ_FLAG_SELECT = 0x10U, /*!< Select flag */
- RFAL_NFCV_REQ_FLAG_ADDRESS = 0x20U, /*!< Address flag */
- RFAL_NFCV_REQ_FLAG_OPTION = 0x40U, /*!< Option flag */
- RFAL_NFCV_REQ_FLAG_RFU = 0x80U, /*!< RFU flag */
- RFAL_NFCV_REQ_FLAG_AFI = 0x10U, /*!< AFI flag */
- RFAL_NFCV_REQ_FLAG_NB_SLOTS = 0x20U, /*!< Number of Slots flag */
-};
-
-/*! NFC-V Response Flags ISO15693 2000 7.4.1 */
-enum{
- RFAL_NFCV_RES_FLAG_ERROR = 0x01U, /*!< Error flag */
- RFAL_NFCV_RES_FLAG_RFU1 = 0x02U, /*!< RFU flag */
- RFAL_NFCV_RES_FLAG_RFU2 = 0x04U, /*!< RFU flag */
- RFAL_NFCV_RES_FLAG_EXTENSION = 0x08U, /*!< Extension flag */
- RFAL_NFCV_RES_FLAG_RFU3 = 0x10U, /*!< RFU flag */
- RFAL_NFCV_RES_FLAG_RFU4 = 0x20U, /*!< RFU flag */
- RFAL_NFCV_RES_FLAG_RFU5 = 0x40U, /*!< RFU flag */
- RFAL_NFCV_RES_FLAG_RFU6 = 0x80U /*!< RFU flag */
-};
-
-/*! NFC-V Error code ISO15693 2000 7.4.2 */
-enum{
- RFAL_NFCV_ERROR_CMD_NOT_SUPPORTED = 0x01U, /*!< The command is not supported, code is not recognised */
- RFAL_NFCV_ERROR_CMD_NOT_RECOGNIZED = 0x02U, /*!< The command is not recognised, format error occurred */
- RFAL_NFCV_ERROR_OPTION_NOT_SUPPORTED = 0x03U, /*!< The option is not supported */
- RFAL_NFCV_ERROR_UNKNOWN = 0x0FU, /*!< Unknown error */
- RFAL_NFCV_ERROR_BLOCK_NOT_AVALIABLE = 0x10U, /*!< The specified block is not available */
- RFAL_NFCV_ERROR_BLOCK_ALREDY_LOCKED = 0x11U, /*!< The specified block is already locked */
- RFAL_NFCV_ERROR_BLOCK_LOCKED = 0x12U, /*!< The specified block is locked */
- RFAL_NFCV_ERROR_WRITE_FAILED = 0x13U, /*!< The specified block was not successfully programmed */
- RFAL_NFCV_ERROR_BLOCK_FAILED = 0x14U /*!< The specified block was not successfully locked */
-};
-
-
-/*! NFC-V command set ISO15693 2000 9.1 */
-enum
-{
- RFAL_NFCV_CMD_INVENTORY = 0x01U, /*!< INVENTORY_REQ (Inventory) command */
- RFAL_NFCV_CMD_SLPV = 0x02U, /*!< SLPV_REQ (Stay quiet) command */
- RFAL_NFCV_CMD_READ_SINGLE_BLOCK = 0x20U, /*!< Read single block command */
- RFAL_NFCV_CMD_WRITE_SINGLE_BLOCK = 0x21U, /*!< Write single block command */
- RFAL_NFCV_CMD_LOCK_BLOCK = 0x22U, /*!< Lock block command */
- RFAL_NFCV_CMD_READ_MULTIPLE_BLOCKS = 0x23U, /*!< Read multiple blocks command */
- RFAL_NFCV_CMD_WRITE_MULTIPLE_BLOCKS = 0x24U, /*!< Write multiple blocks command */
- RFAL_NFCV_CMD_SELECT = 0x25U, /*!< Select command */
- RFAL_NFCV_CMD_RESET_TO_READY = 0x26U, /*!< Reset To Ready command */
- RFAL_NFCV_CMD_GET_SYS_INFO = 0x2BU, /*!< Get System Information command */
- RFAL_NFCV_CMD_EXTENDED_READ_SINGLE_BLOCK = 0x30U, /*!< Extended read single block command */
- RFAL_NFCV_CMD_EXTENDED_WRITE_SINGLE_BLOCK = 0x31U, /*!< Extended write single block command */
- RFAL_NFCV_CMD_EXTENDED_LOCK_SINGLE_BLOCK = 0x32U, /*!< Extended lock single block command */
- RFAL_NFCV_CMD_EXTENDED_READ_MULTIPLE_BLOCK = 0x33U, /*!< Extended read multiple block command */
- RFAL_NFCV_CMD_EXTENDED_WRITE_MULTIPLE_BLOCK = 0x34U, /*!< Extended read multiple block command */
- RFAL_NFCV_CMD_EXTENDED_GET_SYS_INFO = 0x3BU /*!< Extended Get System Information command */
-};
-
-/*! ST25TV/ST25DV command set */
-enum
-{
- RFAL_NFCV_CMD_READ_CONFIGURATION = 0xA0U, /*!< Read configuration command */
- RFAL_NFCV_CMD_WRITE_CONFIGURATION = 0xA1U, /*!< Write configuration command */
- RFAL_NFCV_CMD_SET_EAS = 0xA2U, /*!< Set EAS command */
- RFAL_NFCV_CMD_RESET_EAS = 0xA3U, /*!< Reset EAS command */
- RFAL_NFCV_CMD_LOCK_EAS = 0xA4U, /*!< Lock EAS command */
- RFAL_NFCV_CMD_ENABLE_EAS = 0xA5U, /*!< Enable EAS command */
- RFAL_NFCV_CMD_KILL = 0xA6U, /*!< Kill command */
- RFAL_NFCV_CMD_WRITE_EAS_ID = 0xA7U, /*!< Write EAS ID command */
- RFAL_NFCV_CMD_WRITE_EAS_CONFIG = 0xA8U, /*!< Write EAS CONFIG command */
- RFAL_NFCV_CMD_MANAGE_GPO = 0xA9U, /*!< Manage GPO command */
- RFAL_NFCV_CMD_WRITE_MESSAGE = 0xAAU, /*!< Write Message command */
- RFAL_NFCV_CMD_READ_MESSAGE_LENGTH = 0xABU, /*!< Read Message Length command */
- RFAL_NFCV_CMD_READ_MESSAGE = 0xACU, /*!< Read Message command */
- RFAL_NFCV_CMD_READ_DYN_CONFIGURATION = 0xADU, /*!< Read Dynamic Configuration command */
- RFAL_NFCV_CMD_WRITE_DYN_CONFIGURATION = 0xAEU, /*!< Write Dynamic Configuration command */
- RFAL_NFCV_CMD_WRITE_PASSWORD = 0xB1U, /*!< Write Kill Password / Write Password command */
- RFAL_NFCV_CMD_LOCK_KILL = 0xB2U, /*!< Lock Kill command */
- RFAL_NFCV_CMD_PRESENT_PASSWORD = 0xB3U, /*!< Present Password command */
- RFAL_NFCV_CMD_GET_RANDOM_NUMBER = 0xB4U, /*!< Get Random Number command */
- RFAL_NFCV_CMD_FAST_READ_SINGLE_BLOCK = 0xC0U, /*!< Fast Read single block command */
- RFAL_NFCV_CMD_FAST_READ_MULTIPLE_BLOCKS = 0xC3U, /*!< Fast Read multiple blocks command */
- RFAL_NFCV_CMD_FAST_EXTENDED_READ_SINGLE_BLOCK = 0xC4U, /*!< Fast Extended Read single block command */
- RFAL_NFCV_CMD_FAST_EXTENDED_READ_MULTIPLE_BLOCKS = 0xC5U, /*!< Fast Extended Read multiple blocks command */
- RFAL_NFCV_CMD_FAST_WRITE_MESSAGE = 0xCAU, /*!< Fast Write Message */
- RFAL_NFCV_CMD_FAST_READ_MESSAGE_LENGTH = 0xCBU, /*!< Fast Read Message Length */
- RFAL_NFCV_CMD_FAST_READ_MESSAGE = 0xCCU, /*!< Fast Read Message */
- RFAL_NFCV_CMD_FAST_READ_DYN_CONFIGURATION = 0xCDU, /*!< Fast Read Dynamic configuration */
- RFAL_NFCV_CMD_FAST_WRITE_DYN_CONFIGURATION = 0xCEU /*!< Fast Write Dynamic Configuration */
-};
-
-/*! ISO 15693 Get System info parameter request field ISO15693 2018 Table 94 */
-enum
-{
- RFAL_NFCV_SYSINFO_DFSID = 0x01U, /*!< Get System info DFSID flag */
- RFAL_NFCV_SYSINFO_AFI = 0x02U, /*!< Get System info AFI flag */
- RFAL_NFCV_SYSINFO_MEMSIZE = 0x04U, /*!< Get System info MEMSIZE flag */
- RFAL_NFCV_SYSINFO_ICREF = 0x08U, /*!< Get System info ICREF flag */
- RFAL_NFCV_SYSINFO_MOI = 0x10U, /*!< Get System info MOI flag */
- RFAL_NFCV_SYSINFO_CMDLIST = 0x20U, /*!< Get System info CMDLIST flag */
- RFAL_NFCV_SYSINFO_CSI = 0x40U, /*!< Get System info CSI flag */
- RFAL_NFCV_SYSINFO_REQ_ALL = 0x7FU /*!< Get System info request of all parameters */
-};
-
-/*
- ******************************************************************************
- * GLOBAL MACROS
- ******************************************************************************
- */
-
-
-/*
-******************************************************************************
-* GLOBAL TYPES
-******************************************************************************
-*/
-
-/*! NFC-V Number of slots Digital 2.0 9.6.1 */
-typedef enum
-{
- RFAL_NFCV_NUM_SLOTS_1 = 0x20, /*!< Number of slots: 1 */
- RFAL_NFCV_NUM_SLOTS_16 = 0x00, /*!< Number of slots: 16 */
-} rfalNfcvNumSlots;
-
-
-/*! NFC-V INVENTORY_RES format Digital 2.0 9.6.2 */
-typedef struct
-{
- uint8_t RES_FLAG; /*!< Response Flags */
- uint8_t DSFID; /*!< Data Storage Format Identifier */
- uint8_t UID[RFAL_NFCV_UID_LEN]; /*!< NFC-V device UID */
- uint8_t crc[RFAL_CRC_LEN]; /*!< CRC */
-} rfalNfcvInventoryRes;
-
-
-/*! NFC-V Generic Req format */
-typedef struct
-{
- uint8_t REQ_FLAG; /*!< Request Flags */
- uint8_t CMD; /*!< Command code */
- union { /* PRQA S 0750 # MISRA 19.2 - Both members are of the same type, just different names. Thus no problem can occur. */
- uint8_t UID[RFAL_NFCV_UID_LEN]; /*!< Mask Value */
- uint8_t data[RFAL_NFCV_MAX_GEN_DATA_LEN]; /*!< Data */
- }payload; /*!< Payload */
-} rfalNfcvGenericReq;
-
-
-/*! NFC-V Generic Response format */
-typedef struct
-{
- uint8_t RES_FLAG; /*!< Response Flags */
- uint8_t data[RFAL_NFCV_MAX_GEN_DATA_LEN]; /*!< Data */
-} rfalNfcvGenericRes;
-
-
-/*! NFC-V listener device (VICC) struct */
-typedef struct
-{
- rfalNfcvInventoryRes InvRes; /*!< INVENTORY_RES */
- bool isSleep; /*!< Device sleeping flag */
-} rfalNfcvListenDevice;
-
-
-/*
-******************************************************************************
-* GLOBAL FUNCTION PROTOTYPES
-******************************************************************************
-*/
-
-/*!
- *****************************************************************************
- * \brief Initialize NFC-V Poller mode
- *
- * This methods configures RFAL RF layer to perform as a
- * NFC-V Poller/RW (ISO15693) including all default timings
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or mode not set
- * \return RFAL_ERR_PARAM : Incorrect bitrate
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalNfcvPollerInitialize( void );
-
-/*!
- *****************************************************************************
- * \brief NFC-V Poller Check Presence
- *
- * This method checks if a NFC-V Listen device (VICC) is present on the field
- * by sending an Inventory (INVENTORY_REQ)
- *
- * \param[out] invRes : If received, the INVENTORY_RES. Please note that
- * received invRes may contain errors and is not
- * guaranteed to contain valid data.
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_TIMEOUT : Timeout error, no listener device detectedd
- * \return RFAL_ERR_NONE : No error, one or more device in the field
- *****************************************************************************
- */
-ReturnCode rfalNfcvPollerCheckPresence( rfalNfcvInventoryRes *invRes );
-
-/*!
- *****************************************************************************
- * \brief NFC-V Poller Poll
- *
- * This function sends to all VICCs in field the INVENTORY command with the
- * given number of slots
- *
- * If more than one slot is used the following EOF need to be handled
- * by the caller using rfalISO15693TransceiveEOFAnticollision()
- *
- * \param[in] nSlots : Number of Slots to be sent (1 or 16)
- * \param[in] maskLen : Number bits on the Mask value
- * \param[in] maskVal : location of the Mask value
- * \param[out] invRes : location to place the INVENTORY_RES
- * \param[out] rcvdLen : number of bits received (without collision)
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_RF_COLLISION : Collision detected
- * \return RFAL_ERR_CRC : CRC error detected
- * \return RFAL_ERR_PROTO : Protocol error detected
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalNfcvPollerInventory( rfalNfcvNumSlots nSlots, uint8_t maskLen, const uint8_t *maskVal, rfalNfcvInventoryRes *invRes, uint16_t* rcvdLen );
-
-/*!
- *****************************************************************************
- * \brief NFC-V Poller Full Collision Resolution
- *
- * Performs a full Collision resolution as defined in Activity 2.0 9.3.7
- * Once done, the devCnt will indicate how many (if any) devices have
- * been identified and their details are contained on nfcvDevList
- *
- * \param[in] compMode : compliance mode to be performed
- * \param[in] devLimit : device limit value, and size nfcaDevList
- * \param[out] nfcvDevList : NFC-V listener devices list
- * \param[out] devCnt : Devices found counter
- *
- * When compMode is set to ISO the function immediately goes to 16 slots improving
- * chances to detect more than only one strong card.
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or mode not set
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalNfcvPollerCollisionResolution( rfalComplianceMode compMode, uint8_t devLimit, rfalNfcvListenDevice *nfcvDevList, uint8_t *devCnt );
-
-/*!
- *****************************************************************************
- * \brief NFC-V Poller Full Collision Resolution With Sleep
- *
- * Performs a full Collision resolution which is different from Activity 2.0 9.3.7.
- * The implementation uses SLPV (StayQuiet) command to make sure all cards are found.
- * Once done, the devCnt will indicate how many (if any) devices have
- * been identified and their details are contained on nfcvDevList
- *
- * \param[in] devLimit : device limit value, and size nfcaDevList
- * \param[out] nfcvDevList : NFC-V listener devices list
- * \param[out] devCnt : Devices found counter
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or mode not set
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalNfcvPollerSleepCollisionResolution( uint8_t devLimit, rfalNfcvListenDevice *nfcvDevList, uint8_t *devCnt );
-
-/*!
- *****************************************************************************
- * \brief NFC-V Poller Sleep
- *
- * This function is used to send the SLPV_REQ (Stay Quiet) command to put the VICC
- * with the given UID to state QUIET so that they do not reply to more Inventory
- *
- * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
- * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
- * \param[in] uid : UID of the device to be put to Sleep
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalNfcvPollerSleep( uint8_t flags, const uint8_t* uid );
-
-/*!
- *****************************************************************************
- * \brief NFC-V Poller Select
- *
- * Selects a device (VICC) by its UID
- *
- * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
- * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
- * \param[in] uid : UID of the device to be put to be Selected
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_CRC : CRC error detected
- * \return RFAL_ERR_FRAMING : Framing error detected
- * \return RFAL_ERR_PROTO : Protocol error detected
- * \return RFAL_ERR_TIMEOUT : Timeout error
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalNfcvPollerSelect( uint8_t flags, const uint8_t* uid );
-
-/*!
- *****************************************************************************
- * \brief NFC-V Poller Read Single Block
- *
- * Reads a Single Block from a device (VICC)
- *
- * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
- * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
- * \param[in] uid : UID of the device to be put to be read
- * if UID is provided Addressed mode will be used
- * \param[in] blockNum : Number of the block to read
- * \param[out] rxBuf : buffer to store response (also with RES_FLAGS)
- * \param[in] rxBufLen : length of rxBuf
- * \param[out] rcvLen : number of bytes received
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_CRC : CRC error detected
- * \return RFAL_ERR_FRAMING : Framing error detected
- * \return RFAL_ERR_PROTO : Protocol error detected
- * \return RFAL_ERR_TIMEOUT : Timeout error
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalNfcvPollerReadSingleBlock( uint8_t flags, const uint8_t* uid, uint8_t blockNum, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen );
-
-/*!
- *****************************************************************************
- * \brief NFC-V Poller Write Single Block
- *
- * Writes a Single Block from a device (VICC)
- *
- * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
- * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
- * \param[in] uid : UID of the device to be put to be written
- * if UID is provided Addressed mode will be used
- * \param[in] blockNum : Number of the block to write
- * \param[in] wrData : data to be written on the given block
- * \param[in] blockLen : number of bytes of a block
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_CRC : CRC error detected
- * \return RFAL_ERR_FRAMING : Framing error detected
- * \return RFAL_ERR_PROTO : Protocol error detected
- * \return RFAL_ERR_TIMEOUT : Timeout error
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalNfcvPollerWriteSingleBlock( uint8_t flags, const uint8_t* uid, uint8_t blockNum, const uint8_t* wrData, uint8_t blockLen );
-
-/*!
- *****************************************************************************
- * \brief NFC-V Poller Read Multiple Blocks
- *
- * Reads Multiple Blocks from a device (VICC)
- *
- * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
- * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
- * \param[in] uid : UID of the device to be put to be read
- * if UID is provided Addressed mode will be used
- * \param[in] firstBlockNum : first block to be read
- * \param[in] numOfBlocks : number of block to read
- * \param[out] rxBuf : buffer to store response (also with RES_FLAGS)
- * \param[in] rxBufLen : length of rxBuf
- * \param[out] rcvLen : number of bytes received
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_CRC : CRC error detected
- * \return RFAL_ERR_FRAMING : Framing error detected
- * \return RFAL_ERR_PROTO : Protocol error detected
- * \return RFAL_ERR_TIMEOUT : Timeout error
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalNfcvPollerReadMultipleBlocks( uint8_t flags, const uint8_t* uid, uint8_t firstBlockNum, uint8_t numOfBlocks, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen );
-
-/*!
- *****************************************************************************
- * \brief NFC-V Poller Write Multiple Blocks
- *
- * Writes Multiple Blocks from a device (VICC)
- * In order to not limit the length of the Write multiple command, a buffer
- * must be provided where the request will be composed and then sent.
- *
- * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
- * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
- * \param[in] uid : UID of the device to be put to be read
- * if UID is provided Addressed mode will be used
- * \param[in] firstBlockNum : first block to be written
- * \param[in] numOfBlocks : number of consecutive blocks to write
- * \param[in] txBuf : buffer where the request will be composed
- * \param[in] txBufLen : length of txBuf
- * \param[in] blockLen : number of bytes of a block
- * \param[in] wrData : data to be written
- * \param[in] wrDataLen : length of the data do be written. Must be
- * aligned with number of blocks to write and
- * the size of a block
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_CRC : CRC error detected
- * \return RFAL_ERR_FRAMING : Framing error detected
- * \return RFAL_ERR_PROTO : Protocol error detected
- * \return RFAL_ERR_TIMEOUT : Timeout error
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalNfcvPollerWriteMultipleBlocks( uint8_t flags, const uint8_t* uid, uint8_t firstBlockNum, uint8_t numOfBlocks, uint8_t *txBuf, uint16_t txBufLen, uint8_t blockLen, const uint8_t* wrData, uint16_t wrDataLen );
-
-/*!
- *****************************************************************************
- * \brief NFC-V Poller Lock Single Block
- *
- * Locks a Single Block from a device (VICC) supporting extended commands
- *
- * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
- * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
- * \param[in] uid : UID of the device
- * if UID is provided Addressed mode will be used
- * \param[in] blockNum : Number of the block to be locked
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_CRC : CRC error detected
- * \return RFAL_ERR_FRAMING : Framing error detected
- * \return RFAL_ERR_PROTO : Protocol error detected
- * \return RFAL_ERR_TIMEOUT : Timeout error
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalNfcvPollerLockBlock( uint8_t flags, const uint8_t* uid, uint8_t blockNum );
-
-/*!
- *****************************************************************************
- * \brief NFC-V Poller Extended Lock Single Block
- *
- * Locks a Single Block from a device (VICC) supporting extended commands
- *
- * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
- * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
- * \param[in] uid : UID of the device
- * if UID is provided Addressed mode will be used
- * \param[in] blockNum : Number of the block to be locked (16 bits)
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_CRC : CRC error detected
- * \return RFAL_ERR_FRAMING : Framing error detected
- * \return RFAL_ERR_PROTO : Protocol error detected
- * \return RFAL_ERR_TIMEOUT : Timeout error
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalNfcvPollerExtendedLockSingleBlock( uint8_t flags, const uint8_t* uid, uint16_t blockNum );
-
-/*!
- *****************************************************************************
- * \brief NFC-V Poller Extended Read Single Block
- *
- * Reads a Single Block from a device (VICC) supporting extended commands
- *
- * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
- * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
- * \param[in] uid : UID of the device to be put to be read
- * if UID is provided Addressed mode will be used
- * \param[in] blockNum : Number of the block to read (16 bits)
- * \param[out] rxBuf : buffer to store response (also with RES_FLAGS)
- * \param[in] rxBufLen : length of rxBuf
- * \param[out] rcvLen : number of bytes received
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_CRC : CRC error detected
- * \return RFAL_ERR_FRAMING : Framing error detected
- * \return RFAL_ERR_PROTO : Protocol error detected
- * \return RFAL_ERR_TIMEOUT : Timeout error
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalNfcvPollerExtendedReadSingleBlock( uint8_t flags, const uint8_t* uid, uint16_t blockNum, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen );
-
-/*!
- *****************************************************************************
- * \brief NFC-V Poller Extended Write Single Block
- *
- * Writes a Single Block from a device (VICC) supporting extended commands
- *
- * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
- * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
- * \param[in] uid : UID of the device
- * if UID is provided Addressed mode will be used
- * \param[in] blockNum : Number of the block to write (16 bits)
- * \param[in] wrData : data to be written on the given block
- * \param[in] blockLen : number of bytes of a block
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_CRC : CRC error detected
- * \return RFAL_ERR_FRAMING : Framing error detected
- * \return RFAL_ERR_PROTO : Protocol error detected
- * \return RFAL_ERR_TIMEOUT : Timeout error
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalNfcvPollerExtendedWriteSingleBlock( uint8_t flags, const uint8_t* uid, uint16_t blockNum, const uint8_t* wrData, uint8_t blockLen );
-
-/*!
- *****************************************************************************
- * \brief NFC-V Poller Extended Read Multiple Blocks
- *
- * Reads Multiple Blocks from a device (VICC) supporting extended commands
- *
- * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
- * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
- * \param[in] uid : UID of the device to be put to be read
- * if UID is provided Addressed mode will be used
- * \param[in] firstBlockNum : first block to be read (16 bits)
- * \param[in] numOfBlocks : number of consecutive blocks to read (16 bits)
- * \param[out] rxBuf : buffer to store response (also with RES_FLAGS)
- * \param[in] rxBufLen : length of rxBuf
- * \param[out] rcvLen : number of bytes received
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_CRC : CRC error detected
- * \return RFAL_ERR_FRAMING : Framing error detected
- * \return RFAL_ERR_PROTO : Protocol error detected
- * \return RFAL_ERR_TIMEOUT : Timeout error
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalNfcvPollerExtendedReadMultipleBlocks( uint8_t flags, const uint8_t* uid, uint16_t firstBlockNum, uint16_t numOfBlocks, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen );
-
-/*!
- *****************************************************************************
- * \brief NFC-V Poller Extended Write Multiple Blocks
- *
- * Writes Multiple Blocks from a device (VICC) supporting extended commands
- * In order to not limit the length of the Write multiple command, a buffer
- * must be provided where the request will be composed and then sent.
- *
- * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
- * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
- * \param[in] uid : UID of the device to be put to be read
- * if UID is provided Addressed mode will be used
- * \param[in] firstBlockNum : first block to be write (16 bits)
- * \param[in] numOfBlocks : number of consecutive blocks to write (16 bits)
- * \param[in] txBuf : buffer where the request will be composed
- * \param[in] txBufLen : length of txBuf
- * \param[in] blockLen : number of bytes of a block
- * \param[in] wrData : data to be written
- * \param[in] wrDataLen : length of the data do be written. Must be
- * aligned with number of blocks to write and
- * the size of a block
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_CRC : CRC error detected
- * \return RFAL_ERR_FRAMING : Framing error detected
- * \return RFAL_ERR_PROTO : Protocol error detected
- * \return RFAL_ERR_TIMEOUT : Timeout error
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalNfcvPollerExtendedWriteMultipleBlocks( uint8_t flags, const uint8_t* uid, uint16_t firstBlockNum, uint16_t numOfBlocks, uint8_t *txBuf, uint16_t txBufLen, uint8_t blockLen, const uint8_t* wrData, uint16_t wrDataLen );
-
-/*!
- *****************************************************************************
- * \brief NFC-V Get System Information
- *
- * Sends Get System Information command
- *
- * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
- * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
- * \param[in] uid : UID of the device to be put to be read
- * if UID is provided Addressed mode will be used
- * \param[out] rxBuf : buffer to store response (also with RES_FLAGS)
- * \param[in] rxBufLen : length of rxBuf
- * \param[out] rcvLen : number of bytes received
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_CRC : CRC error detected
- * \return RFAL_ERR_FRAMING : Framing error detected
- * \return RFAL_ERR_PROTO : Protocol error detected
- * \return RFAL_ERR_TIMEOUT : Timeout error
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalNfcvPollerGetSystemInformation( uint8_t flags, const uint8_t* uid, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen );
-
-/*!
- *****************************************************************************
- * \brief NFC-V Extended Get System Information
- *
- * Sends Extended Get System Information command
- *
- * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
- * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
- * \param[in] uid : UID of the device to be put to be read
- * if UID is provided Addressed mode will be used
- * \param[in] requestField : Get System info parameter request field
- * \param[out] rxBuf : buffer to store response (also with RES_FLAGS)
- * \param[in] rxBufLen : length of rxBuf
- * \param[out] rcvLen : number of bytes received
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_CRC : CRC error detected
- * \return RFAL_ERR_FRAMING : Framing error detected
- * \return RFAL_ERR_PROTO : Protocol error detected
- * \return RFAL_ERR_TIMEOUT : Timeout error
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalNfcvPollerExtendedGetSystemInformation( uint8_t flags, const uint8_t* uid, uint8_t requestField, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen );
-
-
-/*!
- *****************************************************************************
- * \brief NFC-V Transceive Request
- *
- * Performs a generic transceive with an ISO15693 tag
- *
- * \param[in] cmd : NFC-V command
- * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
- * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
- * \param[in] param : Prepend parameter on certain proprietary requests
- * For default commands skip: RFAL_NFCV_PARAM_SKIP
- * \param[in] uid : UID of the device to be put to be read
- * if UID is provided Addressed mode will be used
- * \param[in] data : command parameters append after UID
- * \param[in] dataLen : command parameters Len
- * \param[out] rxBuf : buffer to store response (also with RES_FLAGS)
- * \param[in] rxBufLen : length of rxBuf
- * \param[out] rcvLen : number of bytes received
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_CRC : CRC error detected
- * \return RFAL_ERR_FRAMING : Framing error detected
- * \return RFAL_ERR_PROTO : Protocol error detected
- * \return RFAL_ERR_TIMEOUT : Timeout error
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalNfcvPollerTransceiveReq( uint8_t cmd, uint8_t flags, uint8_t param, const uint8_t* uid, const uint8_t *data, uint16_t dataLen, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen );
-
-#endif /* RFAL_NFCV_H */
-
-/**
- * @}
- *
- * @}
- *
- * @}
- */
-
+
+/******************************************************************************
+ * @attention
+ *
+ * COPYRIGHT 2016 STMicroelectronics, all rights reserved
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
+ * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+******************************************************************************/
+
+
+/*
+ * PROJECT: ST25R firmware
+ * Revision:
+ * LANGUAGE: ISO C99
+ */
+
+/*! \file rfal_nfcv.h
+ *
+ * \author Gustavo Patricio
+ *
+ * \brief Implementation of NFC-V Poller (ISO15693) device
+ *
+ * The definitions and helpers methods provided by this module
+ * are aligned with NFC-V Digital 2.1
+ *
+ *
+ * \addtogroup RFAL
+ * @{
+ *
+ * \addtogroup RFAL-AL
+ * \brief RFAL Abstraction Layer
+ * @{
+ *
+ * \addtogroup NFC-V
+ * \brief RFAL NFC-V Module
+ * @{
+ *
+ */
+
+#ifndef RFAL_NFCV_H
+#define RFAL_NFCV_H
+
+/*
+ ******************************************************************************
+ * INCLUDES
+ ******************************************************************************
+ */
+#include "rfal_platform.h"
+#include "rfal_utils.h"
+#include "rfal_rf.h"
+
+/*
+ ******************************************************************************
+ * C LINKAGE GUARD
+ ******************************************************************************
+ */
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/*
+ ******************************************************************************
+ * GLOBAL DEFINES
+ ******************************************************************************
+ */
+
+#define RFAL_NFCV_UID_LEN 8U /*!< NFC-V UID length */
+#define RFAL_NFCV_MAX_BLOCK_LEN 32U /*!< Max Block size: can be of up to 256 bits ISO 15693 2000 5 */
+#define RFAL_NFCV_BNO_LEN 1U /*!< NFC-V Block Number length */
+#define RFAL_NFCV_CRC_LEN 2U /*!< NFC-V CRC length */
+#define RFAL_NFCV_MAX_GEN_DATA_LEN (RFAL_NFCV_MAX_BLOCK_LEN + RFAL_NFCV_BNO_LEN + RFAL_NFCV_UID_LEN) /*!<Max data */
+#define RFAL_NFCV_BLOCKNUM_LEN 1U /*!< Block Number length on normal commands: 8 bits */
+#define RFAL_NFCV_BLOCKNUM_EXTENDED_LEN 2U /*!< Block Number length on extended commands: 16 bits */
+#define RFAL_NFCV_PARAM_SKIP 0U /*!< Skip proprietary Param Request */
+#define RFAL_NFCV_ST_IC_MFG_CODE 0x02U /*!< ST IC Mfg code (used for custom commands) */
+
+
+
+/*! NFC-V RequestFlags ISO15693 2000 7.3.1 */
+enum{
+ RFAL_NFCV_REQ_FLAG_DEFAULT = 0x02U, /*!< Default Request Flags */
+ RFAL_NFCV_REQ_FLAG_SUB_CARRIER = 0x01U, /*!< Sub Carrier flag */
+ RFAL_NFCV_REQ_FLAG_DATA_RATE = 0x02U, /*!< Data Rate flag */
+ RFAL_NFCV_REQ_FLAG_INVENTORY = 0x04U, /*!< Inventory flag */
+ RFAL_NFCV_REQ_FLAG_PROTOCOL_EXT = 0x08U, /*!< Protocol Extension flag */
+ RFAL_NFCV_REQ_FLAG_SELECT = 0x10U, /*!< Select flag */
+ RFAL_NFCV_REQ_FLAG_ADDRESS = 0x20U, /*!< Address flag */
+ RFAL_NFCV_REQ_FLAG_OPTION = 0x40U, /*!< Option flag */
+ RFAL_NFCV_REQ_FLAG_RFU = 0x80U, /*!< RFU flag */
+ RFAL_NFCV_REQ_FLAG_AFI = 0x10U, /*!< AFI flag */
+ RFAL_NFCV_REQ_FLAG_NB_SLOTS = 0x20U, /*!< Number of Slots flag */
+};
+
+/*! NFC-V Response Flags ISO15693 2000 7.4.1 */
+enum{
+ RFAL_NFCV_RES_FLAG_ERROR = 0x01U, /*!< Error flag */
+ RFAL_NFCV_RES_FLAG_RFU1 = 0x02U, /*!< RFU flag */
+ RFAL_NFCV_RES_FLAG_RFU2 = 0x04U, /*!< RFU flag */
+ RFAL_NFCV_RES_FLAG_EXTENSION = 0x08U, /*!< Extension flag */
+ RFAL_NFCV_RES_FLAG_RFU3 = 0x10U, /*!< RFU flag */
+ RFAL_NFCV_RES_FLAG_RFU4 = 0x20U, /*!< RFU flag */
+ RFAL_NFCV_RES_FLAG_RFU5 = 0x40U, /*!< RFU flag */
+ RFAL_NFCV_RES_FLAG_RFU6 = 0x80U /*!< RFU flag */
+};
+
+/*! NFC-V Error code ISO15693 2000 7.4.2 */
+enum{
+ RFAL_NFCV_ERROR_CMD_NOT_SUPPORTED = 0x01U, /*!< The command is not supported, code is not recognised */
+ RFAL_NFCV_ERROR_CMD_NOT_RECOGNIZED = 0x02U, /*!< The command is not recognised, format error occurred */
+ RFAL_NFCV_ERROR_OPTION_NOT_SUPPORTED = 0x03U, /*!< The option is not supported */
+ RFAL_NFCV_ERROR_UNKNOWN = 0x0FU, /*!< Unknown error */
+ RFAL_NFCV_ERROR_BLOCK_NOT_AVALIABLE = 0x10U, /*!< The specified block is not available */
+ RFAL_NFCV_ERROR_BLOCK_ALREDY_LOCKED = 0x11U, /*!< The specified block is already locked */
+ RFAL_NFCV_ERROR_BLOCK_LOCKED = 0x12U, /*!< The specified block is locked */
+ RFAL_NFCV_ERROR_WRITE_FAILED = 0x13U, /*!< The specified block was not successfully programmed */
+ RFAL_NFCV_ERROR_BLOCK_FAILED = 0x14U /*!< The specified block was not successfully locked */
+};
+
+
+/*! NFC-V command set ISO15693 2000 9.1 */
+enum
+{
+ RFAL_NFCV_CMD_INVENTORY = 0x01U, /*!< INVENTORY_REQ (Inventory) command */
+ RFAL_NFCV_CMD_SLPV = 0x02U, /*!< SLPV_REQ (Stay quiet) command */
+ RFAL_NFCV_CMD_READ_SINGLE_BLOCK = 0x20U, /*!< Read single block command */
+ RFAL_NFCV_CMD_WRITE_SINGLE_BLOCK = 0x21U, /*!< Write single block command */
+ RFAL_NFCV_CMD_LOCK_BLOCK = 0x22U, /*!< Lock block command */
+ RFAL_NFCV_CMD_READ_MULTIPLE_BLOCKS = 0x23U, /*!< Read multiple blocks command */
+ RFAL_NFCV_CMD_WRITE_MULTIPLE_BLOCKS = 0x24U, /*!< Write multiple blocks command */
+ RFAL_NFCV_CMD_SELECT = 0x25U, /*!< Select command */
+ RFAL_NFCV_CMD_RESET_TO_READY = 0x26U, /*!< Reset To Ready command */
+ RFAL_NFCV_CMD_GET_SYS_INFO = 0x2BU, /*!< Get System Information command */
+ RFAL_NFCV_CMD_EXTENDED_READ_SINGLE_BLOCK = 0x30U, /*!< Extended read single block command */
+ RFAL_NFCV_CMD_EXTENDED_WRITE_SINGLE_BLOCK = 0x31U, /*!< Extended write single block command */
+ RFAL_NFCV_CMD_EXTENDED_LOCK_SINGLE_BLOCK = 0x32U, /*!< Extended lock single block command */
+ RFAL_NFCV_CMD_EXTENDED_READ_MULTIPLE_BLOCK = 0x33U, /*!< Extended read multiple block command */
+ RFAL_NFCV_CMD_EXTENDED_WRITE_MULTIPLE_BLOCK = 0x34U, /*!< Extended read multiple block command */
+ RFAL_NFCV_CMD_EXTENDED_GET_SYS_INFO = 0x3BU /*!< Extended Get System Information command */
+};
+
+/*! ST25TV/ST25DV command set */
+enum
+{
+ RFAL_NFCV_CMD_READ_CONFIGURATION = 0xA0U, /*!< Read configuration command */
+ RFAL_NFCV_CMD_WRITE_CONFIGURATION = 0xA1U, /*!< Write configuration command */
+ RFAL_NFCV_CMD_SET_EAS = 0xA2U, /*!< Set EAS command */
+ RFAL_NFCV_CMD_RESET_EAS = 0xA3U, /*!< Reset EAS command */
+ RFAL_NFCV_CMD_LOCK_EAS = 0xA4U, /*!< Lock EAS command */
+ RFAL_NFCV_CMD_ENABLE_EAS = 0xA5U, /*!< Enable EAS command */
+ RFAL_NFCV_CMD_KILL = 0xA6U, /*!< Kill command */
+ RFAL_NFCV_CMD_WRITE_EAS_ID = 0xA7U, /*!< Write EAS ID command */
+ RFAL_NFCV_CMD_WRITE_EAS_CONFIG = 0xA8U, /*!< Write EAS CONFIG command */
+ RFAL_NFCV_CMD_MANAGE_GPO = 0xA9U, /*!< Manage GPO command */
+ RFAL_NFCV_CMD_WRITE_MESSAGE = 0xAAU, /*!< Write Message command */
+ RFAL_NFCV_CMD_READ_MESSAGE_LENGTH = 0xABU, /*!< Read Message Length command */
+ RFAL_NFCV_CMD_READ_MESSAGE = 0xACU, /*!< Read Message command */
+ RFAL_NFCV_CMD_READ_DYN_CONFIGURATION = 0xADU, /*!< Read Dynamic Configuration command */
+ RFAL_NFCV_CMD_WRITE_DYN_CONFIGURATION = 0xAEU, /*!< Write Dynamic Configuration command */
+ RFAL_NFCV_CMD_WRITE_PASSWORD = 0xB1U, /*!< Write Kill Password / Write Password command */
+ RFAL_NFCV_CMD_LOCK_KILL = 0xB2U, /*!< Lock Kill command */
+ RFAL_NFCV_CMD_PRESENT_PASSWORD = 0xB3U, /*!< Present Password command */
+ RFAL_NFCV_CMD_GET_RANDOM_NUMBER = 0xB4U, /*!< Get Random Number command */
+ RFAL_NFCV_CMD_FAST_READ_SINGLE_BLOCK = 0xC0U, /*!< Fast Read single block command */
+ RFAL_NFCV_CMD_FAST_READ_MULTIPLE_BLOCKS = 0xC3U, /*!< Fast Read multiple blocks command */
+ RFAL_NFCV_CMD_FAST_EXTENDED_READ_SINGLE_BLOCK = 0xC4U, /*!< Fast Extended Read single block command */
+ RFAL_NFCV_CMD_FAST_EXTENDED_READ_MULTIPLE_BLOCKS = 0xC5U, /*!< Fast Extended Read multiple blocks command */
+ RFAL_NFCV_CMD_FAST_WRITE_MESSAGE = 0xCAU, /*!< Fast Write Message */
+ RFAL_NFCV_CMD_FAST_READ_MESSAGE_LENGTH = 0xCBU, /*!< Fast Read Message Length */
+ RFAL_NFCV_CMD_FAST_READ_MESSAGE = 0xCCU, /*!< Fast Read Message */
+ RFAL_NFCV_CMD_FAST_READ_DYN_CONFIGURATION = 0xCDU, /*!< Fast Read Dynamic configuration */
+ RFAL_NFCV_CMD_FAST_WRITE_DYN_CONFIGURATION = 0xCEU /*!< Fast Write Dynamic Configuration */
+};
+
+/*! ISO 15693 Get System info parameter request field ISO15693 2018 Table 94 */
+enum
+{
+ RFAL_NFCV_SYSINFO_DFSID = 0x01U, /*!< Get System info DFSID flag */
+ RFAL_NFCV_SYSINFO_AFI = 0x02U, /*!< Get System info AFI flag */
+ RFAL_NFCV_SYSINFO_MEMSIZE = 0x04U, /*!< Get System info MEMSIZE flag */
+ RFAL_NFCV_SYSINFO_ICREF = 0x08U, /*!< Get System info ICREF flag */
+ RFAL_NFCV_SYSINFO_MOI = 0x10U, /*!< Get System info MOI flag */
+ RFAL_NFCV_SYSINFO_CMDLIST = 0x20U, /*!< Get System info CMDLIST flag */
+ RFAL_NFCV_SYSINFO_CSI = 0x40U, /*!< Get System info CSI flag */
+ RFAL_NFCV_SYSINFO_REQ_ALL = 0x7FU /*!< Get System info request of all parameters */
+};
+
+/*
+ ******************************************************************************
+ * GLOBAL MACROS
+ ******************************************************************************
+ */
+
+
+/*
+******************************************************************************
+* GLOBAL TYPES
+******************************************************************************
+*/
+
+/*! NFC-V Number of slots Digital 2.0 9.6.1 */
+typedef enum
+{
+ RFAL_NFCV_NUM_SLOTS_1 = 0x20, /*!< Number of slots: 1 */
+ RFAL_NFCV_NUM_SLOTS_16 = 0x00, /*!< Number of slots: 16 */
+} rfalNfcvNumSlots;
+
+
+/*! NFC-V INVENTORY_RES format Digital 2.0 9.6.2 */
+typedef struct
+{
+ uint8_t RES_FLAG; /*!< Response Flags */
+ uint8_t DSFID; /*!< Data Storage Format Identifier */
+ uint8_t UID[RFAL_NFCV_UID_LEN]; /*!< NFC-V device UID */
+ uint8_t crc[RFAL_CRC_LEN]; /*!< CRC */
+} rfalNfcvInventoryRes;
+
+
+/*! NFC-V Generic Req format */
+typedef struct
+{
+ uint8_t REQ_FLAG; /*!< Request Flags */
+ uint8_t CMD; /*!< Command code */
+ union { /* PRQA S 0750 # MISRA 19.2 - Both members are of the same type, just different names. Thus no problem can occur. */
+ uint8_t UID[RFAL_NFCV_UID_LEN]; /*!< Mask Value */
+ uint8_t data[RFAL_NFCV_MAX_GEN_DATA_LEN]; /*!< Data */
+ }payload; /*!< Payload */
+} rfalNfcvGenericReq;
+
+
+/*! NFC-V Generic Response format */
+typedef struct
+{
+ uint8_t RES_FLAG; /*!< Response Flags */
+ uint8_t data[RFAL_NFCV_MAX_GEN_DATA_LEN]; /*!< Data */
+} rfalNfcvGenericRes;
+
+
+/*! NFC-V listener device (VICC) struct */
+typedef struct
+{
+ rfalNfcvInventoryRes InvRes; /*!< INVENTORY_RES */
+ bool isSleep; /*!< Device sleeping flag */
+} rfalNfcvListenDevice;
+
+
+/*
+******************************************************************************
+* GLOBAL FUNCTION PROTOTYPES
+******************************************************************************
+*/
+
+/*!
+ *****************************************************************************
+ * \brief Initialize NFC-V Poller mode
+ *
+ * This methods configures RFAL RF layer to perform as a
+ * NFC-V Poller/RW (ISO15693) including all default timings
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or mode not set
+ * \return RFAL_ERR_PARAM : Incorrect bitrate
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalNfcvPollerInitialize( void );
+
+/*!
+ *****************************************************************************
+ * \brief NFC-V Poller Check Presence
+ *
+ * This method checks if a NFC-V Listen device (VICC) is present on the field
+ * by sending an Inventory (INVENTORY_REQ)
+ *
+ * \param[out] invRes : If received, the INVENTORY_RES. Please note that
+ * received invRes may contain errors and is not
+ * guaranteed to contain valid data.
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_TIMEOUT : Timeout error, no listener device detectedd
+ * \return RFAL_ERR_NONE : No error, one or more device in the field
+ *****************************************************************************
+ */
+ReturnCode rfalNfcvPollerCheckPresence( rfalNfcvInventoryRes *invRes );
+
+/*!
+ *****************************************************************************
+ * \brief NFC-V Poller Poll
+ *
+ * This function sends to all VICCs in field the INVENTORY command with the
+ * given number of slots
+ *
+ * If more than one slot is used the following EOF need to be handled
+ * by the caller using rfalISO15693TransceiveEOFAnticollision()
+ *
+ * \param[in] nSlots : Number of Slots to be sent (1 or 16)
+ * \param[in] maskLen : Number bits on the Mask value
+ * \param[in] maskVal : location of the Mask value
+ * \param[out] invRes : location to place the INVENTORY_RES
+ * \param[out] rcvdLen : number of bits received (without collision)
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_RF_COLLISION : Collision detected
+ * \return RFAL_ERR_CRC : CRC error detected
+ * \return RFAL_ERR_PROTO : Protocol error detected
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalNfcvPollerInventory( rfalNfcvNumSlots nSlots, uint8_t maskLen, const uint8_t *maskVal, rfalNfcvInventoryRes *invRes, uint16_t* rcvdLen );
+
+/*!
+ *****************************************************************************
+ * \brief NFC-V Poller Full Collision Resolution
+ *
+ * Performs a full Collision resolution as defined in Activity 2.0 9.3.7
+ * Once done, the devCnt will indicate how many (if any) devices have
+ * been identified and their details are contained on nfcvDevList
+ *
+ * \param[in] compMode : compliance mode to be performed
+ * \param[in] devLimit : device limit value, and size nfcaDevList
+ * \param[out] nfcvDevList : NFC-V listener devices list
+ * \param[out] devCnt : Devices found counter
+ *
+ * When compMode is set to ISO the function immediately goes to 16 slots improving
+ * chances to detect more than only one strong card.
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or mode not set
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalNfcvPollerCollisionResolution( rfalComplianceMode compMode, uint8_t devLimit, rfalNfcvListenDevice *nfcvDevList, uint8_t *devCnt );
+
+/*!
+ *****************************************************************************
+ * \brief NFC-V Poller Full Collision Resolution With Sleep
+ *
+ * Performs a full Collision resolution which is different from Activity 2.0 9.3.7.
+ * The implementation uses SLPV (StayQuiet) command to make sure all cards are found.
+ * Once done, the devCnt will indicate how many (if any) devices have
+ * been identified and their details are contained on nfcvDevList
+ *
+ * \param[in] devLimit : device limit value, and size nfcaDevList
+ * \param[out] nfcvDevList : NFC-V listener devices list
+ * \param[out] devCnt : Devices found counter
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or mode not set
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalNfcvPollerSleepCollisionResolution( uint8_t devLimit, rfalNfcvListenDevice *nfcvDevList, uint8_t *devCnt );
+
+/*!
+ *****************************************************************************
+ * \brief NFC-V Poller Sleep
+ *
+ * This function is used to send the SLPV_REQ (Stay Quiet) command to put the VICC
+ * with the given UID to state QUIET so that they do not reply to more Inventory
+ *
+ * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
+ * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
+ * \param[in] uid : UID of the device to be put to Sleep
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalNfcvPollerSleep( uint8_t flags, const uint8_t* uid );
+
+/*!
+ *****************************************************************************
+ * \brief NFC-V Poller Select
+ *
+ * Selects a device (VICC) by its UID
+ *
+ * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
+ * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
+ * \param[in] uid : UID of the device to be put to be Selected
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_CRC : CRC error detected
+ * \return RFAL_ERR_FRAMING : Framing error detected
+ * \return RFAL_ERR_PROTO : Protocol error detected
+ * \return RFAL_ERR_TIMEOUT : Timeout error
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalNfcvPollerSelect( uint8_t flags, const uint8_t* uid );
+
+/*!
+ *****************************************************************************
+ * \brief NFC-V Poller Read Single Block
+ *
+ * Reads a Single Block from a device (VICC)
+ *
+ * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
+ * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
+ * \param[in] uid : UID of the device to be put to be read
+ * if UID is provided Addressed mode will be used
+ * \param[in] blockNum : Number of the block to read
+ * \param[out] rxBuf : buffer to store response (also with RES_FLAGS)
+ * \param[in] rxBufLen : length of rxBuf
+ * \param[out] rcvLen : number of bytes received
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_CRC : CRC error detected
+ * \return RFAL_ERR_FRAMING : Framing error detected
+ * \return RFAL_ERR_PROTO : Protocol error detected
+ * \return RFAL_ERR_TIMEOUT : Timeout error
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalNfcvPollerReadSingleBlock( uint8_t flags, const uint8_t* uid, uint8_t blockNum, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen );
+
+/*!
+ *****************************************************************************
+ * \brief NFC-V Poller Write Single Block
+ *
+ * Writes a Single Block from a device (VICC)
+ *
+ * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
+ * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
+ * \param[in] uid : UID of the device to be put to be written
+ * if UID is provided Addressed mode will be used
+ * \param[in] blockNum : Number of the block to write
+ * \param[in] wrData : data to be written on the given block
+ * \param[in] blockLen : number of bytes of a block
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_CRC : CRC error detected
+ * \return RFAL_ERR_FRAMING : Framing error detected
+ * \return RFAL_ERR_PROTO : Protocol error detected
+ * \return RFAL_ERR_TIMEOUT : Timeout error
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalNfcvPollerWriteSingleBlock( uint8_t flags, const uint8_t* uid, uint8_t blockNum, const uint8_t* wrData, uint8_t blockLen );
+
+/*!
+ *****************************************************************************
+ * \brief NFC-V Poller Read Multiple Blocks
+ *
+ * Reads Multiple Blocks from a device (VICC)
+ *
+ * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
+ * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
+ * \param[in] uid : UID of the device to be put to be read
+ * if UID is provided Addressed mode will be used
+ * \param[in] firstBlockNum : first block to be read
+ * \param[in] numOfBlocks : number of block to read
+ * \param[out] rxBuf : buffer to store response (also with RES_FLAGS)
+ * \param[in] rxBufLen : length of rxBuf
+ * \param[out] rcvLen : number of bytes received
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_CRC : CRC error detected
+ * \return RFAL_ERR_FRAMING : Framing error detected
+ * \return RFAL_ERR_PROTO : Protocol error detected
+ * \return RFAL_ERR_TIMEOUT : Timeout error
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalNfcvPollerReadMultipleBlocks( uint8_t flags, const uint8_t* uid, uint8_t firstBlockNum, uint8_t numOfBlocks, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen );
+
+/*!
+ *****************************************************************************
+ * \brief NFC-V Poller Write Multiple Blocks
+ *
+ * Writes Multiple Blocks from a device (VICC)
+ * In order to not limit the length of the Write multiple command, a buffer
+ * must be provided where the request will be composed and then sent.
+ *
+ * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
+ * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
+ * \param[in] uid : UID of the device to be put to be read
+ * if UID is provided Addressed mode will be used
+ * \param[in] firstBlockNum : first block to be written
+ * \param[in] numOfBlocks : number of consecutive blocks to write
+ * \param[in] txBuf : buffer where the request will be composed
+ * \param[in] txBufLen : length of txBuf
+ * \param[in] blockLen : number of bytes of a block
+ * \param[in] wrData : data to be written
+ * \param[in] wrDataLen : length of the data do be written. Must be
+ * aligned with number of blocks to write and
+ * the size of a block
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_CRC : CRC error detected
+ * \return RFAL_ERR_FRAMING : Framing error detected
+ * \return RFAL_ERR_PROTO : Protocol error detected
+ * \return RFAL_ERR_TIMEOUT : Timeout error
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalNfcvPollerWriteMultipleBlocks( uint8_t flags, const uint8_t* uid, uint8_t firstBlockNum, uint8_t numOfBlocks, uint8_t *txBuf, uint16_t txBufLen, uint8_t blockLen, const uint8_t* wrData, uint16_t wrDataLen );
+
+/*!
+ *****************************************************************************
+ * \brief NFC-V Poller Lock Single Block
+ *
+ * Locks a Single Block from a device (VICC) supporting extended commands
+ *
+ * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
+ * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
+ * \param[in] uid : UID of the device
+ * if UID is provided Addressed mode will be used
+ * \param[in] blockNum : Number of the block to be locked
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_CRC : CRC error detected
+ * \return RFAL_ERR_FRAMING : Framing error detected
+ * \return RFAL_ERR_PROTO : Protocol error detected
+ * \return RFAL_ERR_TIMEOUT : Timeout error
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalNfcvPollerLockBlock( uint8_t flags, const uint8_t* uid, uint8_t blockNum );
+
+/*!
+ *****************************************************************************
+ * \brief NFC-V Poller Extended Lock Single Block
+ *
+ * Locks a Single Block from a device (VICC) supporting extended commands
+ *
+ * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
+ * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
+ * \param[in] uid : UID of the device
+ * if UID is provided Addressed mode will be used
+ * \param[in] blockNum : Number of the block to be locked (16 bits)
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_CRC : CRC error detected
+ * \return RFAL_ERR_FRAMING : Framing error detected
+ * \return RFAL_ERR_PROTO : Protocol error detected
+ * \return RFAL_ERR_TIMEOUT : Timeout error
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalNfcvPollerExtendedLockSingleBlock( uint8_t flags, const uint8_t* uid, uint16_t blockNum );
+
+/*!
+ *****************************************************************************
+ * \brief NFC-V Poller Extended Read Single Block
+ *
+ * Reads a Single Block from a device (VICC) supporting extended commands
+ *
+ * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
+ * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
+ * \param[in] uid : UID of the device to be put to be read
+ * if UID is provided Addressed mode will be used
+ * \param[in] blockNum : Number of the block to read (16 bits)
+ * \param[out] rxBuf : buffer to store response (also with RES_FLAGS)
+ * \param[in] rxBufLen : length of rxBuf
+ * \param[out] rcvLen : number of bytes received
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_CRC : CRC error detected
+ * \return RFAL_ERR_FRAMING : Framing error detected
+ * \return RFAL_ERR_PROTO : Protocol error detected
+ * \return RFAL_ERR_TIMEOUT : Timeout error
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalNfcvPollerExtendedReadSingleBlock( uint8_t flags, const uint8_t* uid, uint16_t blockNum, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen );
+
+/*!
+ *****************************************************************************
+ * \brief NFC-V Poller Extended Write Single Block
+ *
+ * Writes a Single Block from a device (VICC) supporting extended commands
+ *
+ * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
+ * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
+ * \param[in] uid : UID of the device
+ * if UID is provided Addressed mode will be used
+ * \param[in] blockNum : Number of the block to write (16 bits)
+ * \param[in] wrData : data to be written on the given block
+ * \param[in] blockLen : number of bytes of a block
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_CRC : CRC error detected
+ * \return RFAL_ERR_FRAMING : Framing error detected
+ * \return RFAL_ERR_PROTO : Protocol error detected
+ * \return RFAL_ERR_TIMEOUT : Timeout error
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalNfcvPollerExtendedWriteSingleBlock( uint8_t flags, const uint8_t* uid, uint16_t blockNum, const uint8_t* wrData, uint8_t blockLen );
+
+/*!
+ *****************************************************************************
+ * \brief NFC-V Poller Extended Read Multiple Blocks
+ *
+ * Reads Multiple Blocks from a device (VICC) supporting extended commands
+ *
+ * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
+ * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
+ * \param[in] uid : UID of the device to be put to be read
+ * if UID is provided Addressed mode will be used
+ * \param[in] firstBlockNum : first block to be read (16 bits)
+ * \param[in] numOfBlocks : number of consecutive blocks to read (16 bits)
+ * \param[out] rxBuf : buffer to store response (also with RES_FLAGS)
+ * \param[in] rxBufLen : length of rxBuf
+ * \param[out] rcvLen : number of bytes received
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_CRC : CRC error detected
+ * \return RFAL_ERR_FRAMING : Framing error detected
+ * \return RFAL_ERR_PROTO : Protocol error detected
+ * \return RFAL_ERR_TIMEOUT : Timeout error
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalNfcvPollerExtendedReadMultipleBlocks( uint8_t flags, const uint8_t* uid, uint16_t firstBlockNum, uint16_t numOfBlocks, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen );
+
+/*!
+ *****************************************************************************
+ * \brief NFC-V Poller Extended Write Multiple Blocks
+ *
+ * Writes Multiple Blocks from a device (VICC) supporting extended commands
+ * In order to not limit the length of the Write multiple command, a buffer
+ * must be provided where the request will be composed and then sent.
+ *
+ * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
+ * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
+ * \param[in] uid : UID of the device to be put to be read
+ * if UID is provided Addressed mode will be used
+ * \param[in] firstBlockNum : first block to be write (16 bits)
+ * \param[in] numOfBlocks : number of consecutive blocks to write (16 bits)
+ * \param[in] txBuf : buffer where the request will be composed
+ * \param[in] txBufLen : length of txBuf
+ * \param[in] blockLen : number of bytes of a block
+ * \param[in] wrData : data to be written
+ * \param[in] wrDataLen : length of the data do be written. Must be
+ * aligned with number of blocks to write and
+ * the size of a block
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_CRC : CRC error detected
+ * \return RFAL_ERR_FRAMING : Framing error detected
+ * \return RFAL_ERR_PROTO : Protocol error detected
+ * \return RFAL_ERR_TIMEOUT : Timeout error
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalNfcvPollerExtendedWriteMultipleBlocks( uint8_t flags, const uint8_t* uid, uint16_t firstBlockNum, uint16_t numOfBlocks, uint8_t *txBuf, uint16_t txBufLen, uint8_t blockLen, const uint8_t* wrData, uint16_t wrDataLen );
+
+/*!
+ *****************************************************************************
+ * \brief NFC-V Get System Information
+ *
+ * Sends Get System Information command
+ *
+ * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
+ * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
+ * \param[in] uid : UID of the device to be put to be read
+ * if UID is provided Addressed mode will be used
+ * \param[out] rxBuf : buffer to store response (also with RES_FLAGS)
+ * \param[in] rxBufLen : length of rxBuf
+ * \param[out] rcvLen : number of bytes received
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_CRC : CRC error detected
+ * \return RFAL_ERR_FRAMING : Framing error detected
+ * \return RFAL_ERR_PROTO : Protocol error detected
+ * \return RFAL_ERR_TIMEOUT : Timeout error
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalNfcvPollerGetSystemInformation( uint8_t flags, const uint8_t* uid, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen );
+
+/*!
+ *****************************************************************************
+ * \brief NFC-V Extended Get System Information
+ *
+ * Sends Extended Get System Information command
+ *
+ * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
+ * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
+ * \param[in] uid : UID of the device to be put to be read
+ * if UID is provided Addressed mode will be used
+ * \param[in] requestField : Get System info parameter request field
+ * \param[out] rxBuf : buffer to store response (also with RES_FLAGS)
+ * \param[in] rxBufLen : length of rxBuf
+ * \param[out] rcvLen : number of bytes received
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_CRC : CRC error detected
+ * \return RFAL_ERR_FRAMING : Framing error detected
+ * \return RFAL_ERR_PROTO : Protocol error detected
+ * \return RFAL_ERR_TIMEOUT : Timeout error
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalNfcvPollerExtendedGetSystemInformation( uint8_t flags, const uint8_t* uid, uint8_t requestField, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen );
+
+
+/*!
+ *****************************************************************************
+ * \brief NFC-V Transceive Request
+ *
+ * Performs a generic transceive with an ISO15693 tag
+ *
+ * \param[in] cmd : NFC-V command
+ * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
+ * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
+ * \param[in] param : Prepend parameter on certain proprietary requests
+ * For default commands skip: RFAL_NFCV_PARAM_SKIP
+ * \param[in] uid : UID of the device to be put to be read
+ * if UID is provided Addressed mode will be used
+ * \param[in] data : command parameters append after UID
+ * \param[in] dataLen : command parameters Len
+ * \param[out] rxBuf : buffer to store response (also with RES_FLAGS)
+ * \param[in] rxBufLen : length of rxBuf
+ * \param[out] rcvLen : number of bytes received
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_CRC : CRC error detected
+ * \return RFAL_ERR_FRAMING : Framing error detected
+ * \return RFAL_ERR_PROTO : Protocol error detected
+ * \return RFAL_ERR_TIMEOUT : Timeout error
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalNfcvPollerTransceiveReq( uint8_t cmd, uint8_t flags, uint8_t param, const uint8_t* uid, const uint8_t *data, uint16_t dataLen, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen );
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* RFAL_NFCV_H */
+
+/**
+ * @}
+ *
+ * @}
+ *
+ * @}
+ */
+
### core/embed/io/nfc/st25/rfal002/include/rfal_rf.h
[binary or diff unavailable]
### core/embed/io/nfc/st25/rfal002/include/rfal_st25tb.h
@@ -1,350 +1,363 @@
-
-/******************************************************************************
- * @attention
- *
- * COPYRIGHT 2016 STMicroelectronics, all rights reserved
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
- * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
-******************************************************************************/
-
-
-/*
- * PROJECT: ST25R firmware
- * Revision:
- * LANGUAGE: ISO C99
- */
-
-/*! \file rfal_st25tb.h
- *
- * \author Gustavo Patricio
- *
- * \brief Implementation of ST25TB interface
- *
- *
- * \addtogroup RFAL
- * @{
- *
- * \addtogroup RFAL-AL
- * \brief RFAL Abstraction Layer
- * @{
- *
- * \addtogroup ST25TB
- * \brief RFAL ST25TB Module
- * @{
- *
- */
-
-
-#ifndef RFAL_ST25TB_H
-#define RFAL_ST25TB_H
-
-/*
- ******************************************************************************
- * INCLUDES
- ******************************************************************************
- */
-#include "rfal_platform.h"
-#include "rfal_utils.h"
-#include "rfal_rf.h"
-#include "rfal_nfcb.h"
-
-/*
- ******************************************************************************
- * GLOBAL DEFINES
- ******************************************************************************
- */
-
-#define RFAL_ST25TB_CHIP_ID_LEN 1U /*!< ST25TB chip ID length */
-#define RFAL_ST25TB_CRC_LEN 2U /*!< ST25TB CRC length */
-#define RFAL_ST25TB_UID_LEN 8U /*!< ST25TB Unique ID length */
-#define RFAL_ST25TB_BLOCK_LEN 4U /*!< ST25TB Data Block length */
-
-/*
-******************************************************************************
-* GLOBAL MACROS
-******************************************************************************
-*/
-
-
-
-/*
-******************************************************************************
-* GLOBAL TYPES
-******************************************************************************
-*/
-typedef uint8_t rfalSt25tbUID[RFAL_ST25TB_UID_LEN]; /*!< ST25TB UID type */
-typedef uint8_t rfalSt25tbBlock[RFAL_ST25TB_BLOCK_LEN]; /*!< ST25TB Block type */
-
-
-/*! ST25TB listener device (PICC) struct */
-typedef struct
-{
- uint8_t chipID; /*!< Device's session Chip ID */
- rfalSt25tbUID UID; /*!< Device's UID */
- bool isDeselected; /*!< Device deselect flag */
-}rfalSt25tbListenDevice;
-
-
-/*
-******************************************************************************
-* GLOBAL FUNCTION PROTOTYPES
-******************************************************************************
-*/
-
-/*!
- *****************************************************************************
- * \brief Initialize ST25TB Poller mode
- *
- * This methods configures RFAL RF layer to perform as a
- * ST25TB Poller/RW including all default timings
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or mode not set
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalSt25tbPollerInitialize( void );
-
-
-/*!
- *****************************************************************************
- * \brief ST25TB Poller Check Presence
- *
- * This method checks if a ST25TB Listen device (PICC) is present on the field
- * by sending an Initiate command
- *
- * \param[out] chipId : if successfully retrieved, the device's chip ID
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_TIMEOUT : Timeout error, no listener device detected
- * \return RFAL_ERR_RF_COLLISION : Collision detected one or more device in the field
- * \return RFAL_ERR_PROTO : Protocol error detected
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalSt25tbPollerCheckPresence( uint8_t *chipId );
-
-
-/*!
- *****************************************************************************
- * \brief ST25TB Poller Collision Resolution
- *
- * This method performs ST25TB Collision resolution, selects the each device,
- * retrieves its UID and then deselects.
- * In case only one device is identified the ST25TB device is left in select
- * state.
- *
- * \param[in] devLimit : device limit value, and size st25tbDevList
- * \param[out] st25tbDevList : ST35TB listener device info
- * \param[out] devCnt : Devices found counter
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_TIMEOUT : Timeout error, no listener device detected
- * \return RFAL_ERR_RF_COLLISION : Collision detected one or more device in the field
- * \return RFAL_ERR_PROTO : Protocol error detected
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalSt25tbPollerCollisionResolution( uint8_t devLimit, rfalSt25tbListenDevice *st25tbDevList, uint8_t *devCnt );
-
-/*!
- *****************************************************************************
- * \brief ST25TB Poller Initiate
- *
- * This method sends an Initiate command
- *
- * If a single device responds the chip ID will be retrieved
- *
- * \param[out] chipId : chip ID of the device
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_TIMEOUT : Timeout error, no listener device detected
- * \return RFAL_ERR_PROTO : Protocol error detected
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalSt25tbPollerInitiate( uint8_t *chipId );
-
-
-/*!
- *****************************************************************************
- * \brief ST25TB Poller Pcall
- *
- * This method sends a Pcall command
- * If successful the device's chip ID will be retrieved
- *
- * \param[out] chipId : Chip ID of the device
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_TIMEOUT : Timeout error, no listener device detected
- * \return RFAL_ERR_PROTO : Protocol error detected
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalSt25tbPollerPcall( uint8_t *chipId );
-
-
-/*!
- *****************************************************************************
- * \brief ST25TB Poller Slot Marker
- *
- * This method sends a Slot Marker
- *
- * If a single device responds the chip ID will be retrieved
- *
- * \param[in] slotNum : Slot Number
- * \param[out] chipIdRes : Chip ID of the device
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_TIMEOUT : Timeout error, no listener device detected
- * \return RFAL_ERR_PROTO : Protocol error detected
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalSt25tbPollerSlotMarker( uint8_t slotNum, uint8_t *chipIdRes );
-
-
-/*!
- *****************************************************************************
- * \brief ST25TB Poller Select
- *
- * This method sends a ST25TB Select command with the given chip ID.
- *
- * If the device is already in Selected state and receives an incorrect chip
- * ID, it goes into Deselected state
- *
- * \param[in] chipId : chip ID of the device to be selected
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_TIMEOUT : Timeout error, no listener device detected
- * \return RFAL_ERR_PROTO : Protocol error detected
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalSt25tbPollerSelect( uint8_t chipId );
-
-
-/*!
- *****************************************************************************
- * \brief ST25TB Get UID
- *
- * This method sends a Get_UID command
- *
- * If a single device responds the chip UID will be retrieved
- *
- * \param[out] UID : UID of the found device
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_TIMEOUT : Timeout error, no listener device detected
- * \return RFAL_ERR_PROTO : Protocol error detected
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalSt25tbPollerGetUID( rfalSt25tbUID *UID );
-
-
-/*!
- *****************************************************************************
- * \brief ST25TB Poller Read Block
- *
- * This method reads a block of the ST25TB
- *
- * \param[in] blockAddress : address of the block to be read
- * \param[out] blockData : location to place the data read from block
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_TIMEOUT : Timeout error, no listener device detected
- * \return RFAL_ERR_PROTO : Protocol error detected
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalSt25tbPollerReadBlock( uint8_t blockAddress, rfalSt25tbBlock *blockData );
-
-
-/*!
- *****************************************************************************
- * \brief ST25TB Poller Write Block
- *
- * This method writes a block of the ST25TB
- *
- * \param[in] blockAddress : address of the block to be written
- * \param[in] blockData : data to be written on the block
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_TIMEOUT : Timeout error, no listener device detected
- * \return RFAL_ERR_PROTO : Protocol error detected
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalSt25tbPollerWriteBlock( uint8_t blockAddress, const rfalSt25tbBlock *blockData );
-
-
-/*!
- *****************************************************************************
- * \brief ST25TB Poller Completion
- *
- * This method sends a completion command to the ST25TB. After the
- * completion the card no longer will reply to any command.
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_TIMEOUT : Timeout error, no listener device detected
- * \return RFAL_ERR_PROTO : Protocol error detected, invalid SENSB_RES received
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalSt25tbPollerCompletion( void );
-
-
-/*!
- *****************************************************************************
- * \brief ST25TB Poller Reset to Inventory
- *
- * This method sends a Reset to Inventory command to the ST25TB.
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_TIMEOUT : Timeout error, no listener device detected
- * \return RFAL_ERR_PROTO : Protocol error detected, invalid SENSB_RES received
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalSt25tbPollerResetToInventory( void );
-
-
-#endif /* RFAL_ST25TB_H */
-
-/**
- * @}
- *
- * @}
- *
- * @}
- */
-
+
+/******************************************************************************
+ * @attention
+ *
+ * COPYRIGHT 2016 STMicroelectronics, all rights reserved
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
+ * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+******************************************************************************/
+
+
+/*
+ * PROJECT: ST25R firmware
+ * Revision:
+ * LANGUAGE: ISO C99
+ */
+
+/*! \file rfal_st25tb.h
+ *
+ * \author Gustavo Patricio
+ *
+ * \brief Implementation of ST25TB interface
+ *
+ *
+ * \addtogroup RFAL
+ * @{
+ *
+ * \addtogroup RFAL-AL
+ * \brief RFAL Abstraction Layer
+ * @{
+ *
+ * \addtogroup ST25TB
+ * \brief RFAL ST25TB Module
+ * @{
+ *
+ */
+
+
+#ifndef RFAL_ST25TB_H
+#define RFAL_ST25TB_H
+
+/*
+ ******************************************************************************
+ * INCLUDES
+ ******************************************************************************
+ */
+#include "rfal_platform.h"
+#include "rfal_utils.h"
+#include "rfal_rf.h"
+#include "rfal_nfcb.h"
+
+/*
+ ******************************************************************************
+ * C LINKAGE GUARD
+ ******************************************************************************
+ */
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/*
+ ******************************************************************************
+ * GLOBAL DEFINES
+ ******************************************************************************
+ */
+
+#define RFAL_ST25TB_CHIP_ID_LEN 1U /*!< ST25TB chip ID length */
+#define RFAL_ST25TB_CRC_LEN 2U /*!< ST25TB CRC length */
+#define RFAL_ST25TB_UID_LEN 8U /*!< ST25TB Unique ID length */
+#define RFAL_ST25TB_BLOCK_LEN 4U /*!< ST25TB Data Block length */
+
+/*
+******************************************************************************
+* GLOBAL MACROS
+******************************************************************************
+*/
+
+
+
+/*
+******************************************************************************
+* GLOBAL TYPES
+******************************************************************************
+*/
+typedef uint8_t rfalSt25tbUID[RFAL_ST25TB_UID_LEN]; /*!< ST25TB UID type */
+typedef uint8_t rfalSt25tbBlock[RFAL_ST25TB_BLOCK_LEN]; /*!< ST25TB Block type */
+
+
+/*! ST25TB listener device (PICC) struct */
+typedef struct
+{
+ uint8_t chipID; /*!< Device's session Chip ID */
+ rfalSt25tbUID UID; /*!< Device's UID */
+ bool isDeselected; /*!< Device deselect flag */
+}rfalSt25tbListenDevice;
+
+
+/*
+******************************************************************************
+* GLOBAL FUNCTION PROTOTYPES
+******************************************************************************
+*/
+
+/*!
+ *****************************************************************************
+ * \brief Initialize ST25TB Poller mode
+ *
+ * This methods configures RFAL RF layer to perform as a
+ * ST25TB Poller/RW including all default timings
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or mode not set
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalSt25tbPollerInitialize( void );
+
+
+/*!
+ *****************************************************************************
+ * \brief ST25TB Poller Check Presence
+ *
+ * This method checks if a ST25TB Listen device (PICC) is present on the field
+ * by sending an Initiate command
+ *
+ * \param[out] chipId : if successfully retrieved, the device's chip ID
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_TIMEOUT : Timeout error, no listener device detected
+ * \return RFAL_ERR_RF_COLLISION : Collision detected one or more device in the field
+ * \return RFAL_ERR_PROTO : Protocol error detected
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalSt25tbPollerCheckPresence( uint8_t *chipId );
+
+
+/*!
+ *****************************************************************************
+ * \brief ST25TB Poller Collision Resolution
+ *
+ * This method performs ST25TB Collision resolution, selects the each device,
+ * retrieves its UID and then deselects.
+ * In case only one device is identified the ST25TB device is left in select
+ * state.
+ *
+ * \param[in] devLimit : device limit value, and size st25tbDevList
+ * \param[out] st25tbDevList : ST35TB listener device info
+ * \param[out] devCnt : Devices found counter
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_TIMEOUT : Timeout error, no listener device detected
+ * \return RFAL_ERR_RF_COLLISION : Collision detected one or more device in the field
+ * \return RFAL_ERR_PROTO : Protocol error detected
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalSt25tbPollerCollisionResolution( uint8_t devLimit, rfalSt25tbListenDevice *st25tbDevList, uint8_t *devCnt );
+
+/*!
+ *****************************************************************************
+ * \brief ST25TB Poller Initiate
+ *
+ * This method sends an Initiate command
+ *
+ * If a single device responds the chip ID will be retrieved
+ *
+ * \param[out] chipId : chip ID of the device
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_TIMEOUT : Timeout error, no listener device detected
+ * \return RFAL_ERR_PROTO : Protocol error detected
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalSt25tbPollerInitiate( uint8_t *chipId );
+
+
+/*!
+ *****************************************************************************
+ * \brief ST25TB Poller Pcall
+ *
+ * This method sends a Pcall command
+ * If successful the device's chip ID will be retrieved
+ *
+ * \param[out] chipId : Chip ID of the device
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_TIMEOUT : Timeout error, no listener device detected
+ * \return RFAL_ERR_PROTO : Protocol error detected
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalSt25tbPollerPcall( uint8_t *chipId );
+
+
+/*!
+ *****************************************************************************
+ * \brief ST25TB Poller Slot Marker
+ *
+ * This method sends a Slot Marker
+ *
+ * If a single device responds the chip ID will be retrieved
+ *
+ * \param[in] slotNum : Slot Number
+ * \param[out] chipIdRes : Chip ID of the device
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_TIMEOUT : Timeout error, no listener device detected
+ * \return RFAL_ERR_PROTO : Protocol error detected
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalSt25tbPollerSlotMarker( uint8_t slotNum, uint8_t *chipIdRes );
+
+
+/*!
+ *****************************************************************************
+ * \brief ST25TB Poller Select
+ *
+ * This method sends a ST25TB Select command with the given chip ID.
+ *
+ * If the device is already in Selected state and receives an incorrect chip
+ * ID, it goes into Deselected state
+ *
+ * \param[in] chipId : chip ID of the device to be selected
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_TIMEOUT : Timeout error, no listener device detected
+ * \return RFAL_ERR_PROTO : Protocol error detected
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalSt25tbPollerSelect( uint8_t chipId );
+
+
+/*!
+ *****************************************************************************
+ * \brief ST25TB Get UID
+ *
+ * This method sends a Get_UID command
+ *
+ * If a single device responds the chip UID will be retrieved
+ *
+ * \param[out] UID : UID of the found device
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_TIMEOUT : Timeout error, no listener device detected
+ * \return RFAL_ERR_PROTO : Protocol error detected
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalSt25tbPollerGetUID( rfalSt25tbUID *UID );
+
+
+/*!
+ *****************************************************************************
+ * \brief ST25TB Poller Read Block
+ *
+ * This method reads a block of the ST25TB
+ *
+ * \param[in] blockAddress : address of the block to be read
+ * \param[out] blockData : location to place the data read from block
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_TIMEOUT : Timeout error, no listener device detected
+ * \return RFAL_ERR_PROTO : Protocol error detected
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalSt25tbPollerReadBlock( uint8_t blockAddress, rfalSt25tbBlock *blockData );
+
+
+/*!
+ *****************************************************************************
+ * \brief ST25TB Poller Write Block
+ *
+ * This method writes a block of the ST25TB
+ *
+ * \param[in] blockAddress : address of the block to be written
+ * \param[in] blockData : data to be written on the block
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_TIMEOUT : Timeout error, no listener device detected
+ * \return RFAL_ERR_PROTO : Protocol error detected
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalSt25tbPollerWriteBlock( uint8_t blockAddress, const rfalSt25tbBlock *blockData );
+
+
+/*!
+ *****************************************************************************
+ * \brief ST25TB Poller Completion
+ *
+ * This method sends a completion command to the ST25TB. After the
+ * completion the card no longer will reply to any command.
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_TIMEOUT : Timeout error, no listener device detected
+ * \return RFAL_ERR_PROTO : Protocol error detected, invalid SENSB_RES received
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalSt25tbPollerCompletion( void );
+
+
+/*!
+ *****************************************************************************
+ * \brief ST25TB Poller Reset to Inventory
+ *
+ * This method sends a Reset to Inventory command to the ST25TB.
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_TIMEOUT : Timeout error, no listener device detected
+ * \return RFAL_ERR_PROTO : Protocol error detected, invalid SENSB_RES received
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalSt25tbPollerResetToInventory( void );
+
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* RFAL_ST25TB_H */
+
+/**
+ * @}
+ *
+ * @}
+ *
+ * @}
+ */
+
### core/embed/io/nfc/st25/rfal002/include/rfal_st25xv.h
@@ -1,803 +1,814 @@
-
-/******************************************************************************
- * @attention
- *
- * COPYRIGHT 2016 STMicroelectronics, all rights reserved
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
- * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
-******************************************************************************/
-
-
-/*
- * PROJECT: ST25R firmware
- * Revision:
- * LANGUAGE: ISO C99
- */
-
-/*! \file rfal_st25xv.h
- *
- * \author Gustavo Patricio
- *
- * \brief NFC-V ST25 NFC-V Tag specific features
- *
- * This module provides support for ST's specific features available on
- * NFC-V (ISO15693) tag families: ST25D, ST25TV, M24LR
- *
- *
- * \addtogroup RFAL
- * @{
- *
- * \addtogroup RFAL-AL
- * \brief RFAL Abstraction Layer
- * @{
- *
- * \addtogroup ST25xV
- * \brief RFAL ST25xV Module
- * @{
- *
- */
-
-#ifndef RFAL_ST25xV_H
-#define RFAL_ST25xV_H
-
-/*
- ******************************************************************************
- * INCLUDES
- ******************************************************************************
- */
-#include "rfal_platform.h"
-#include "rfal_utils.h"
-#include "rfal_rf.h"
-
-/*
- ******************************************************************************
- * GLOBAL DEFINES
- ******************************************************************************
- */
-
-
-#define RFAL_NFCV_BLOCKNUM_M24LR_LEN 2U /*!< Block Number length of MR24LR tags: 16 bits */
-
-/*!
- *****************************************************************************
- * \brief NFC-V Poller Read Single Block (M24LR)
- *
- * Reads a Single Block from a M24LR tag which has the number of blocks
- * bigger than 256 (M24LR16 ; M24LR64)
- *
- * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
- * default: RFAL_NFCV_REQ_FLAG_DEFAULT
- * \param[in] uid : UID of the device to be put to be read
- * if not provided Select mode will be used
- * \param[in] blockNum : Number of the block to read (16 bits)
- * \param[out] rxBuf : buffer to store response (also with RES_FLAGS)
- * \param[in] rxBufLen : length of rxBuf
- * \param[out] rcvLen : number of bytes received
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_CRC : CRC error detected
- * \return RFAL_ERR_FRAMING : Framing error detected
- * \return RFAL_ERR_PROTO : Protocol error detected
- * \return RFAL_ERR_TIMEOUT : Timeout error
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalST25xVPollerM24LRReadSingleBlock( uint8_t flags, const uint8_t* uid, uint16_t blockNum, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen );
-
-/*!
- *****************************************************************************
- * \brief NFC-V Poller Fast Read Single Block (M24LR)
- *
- * Reads a Single Block from a M24LR tag which has the number of blocks
- * bigger than 256 (M24LR16 ; M24LR64) using ST Fast mode
- *
- * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
- * default: RFAL_NFCV_REQ_FLAG_DEFAULT
- * \param[in] uid : UID of the device to be put to be read
- * if not provided Select mode will be used
- * \param[in] blockNum : Number of the block to read (16 bits)
- * \param[out] rxBuf : buffer to store response (also with RES_FLAGS)
- * \param[in] rxBufLen : length of rxBuf
- * \param[out] rcvLen : number of bytes received
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_CRC : CRC error detected
- * \return RFAL_ERR_FRAMING : Framing error detected
- * \return RFAL_ERR_PROTO : Protocol error detected
- * \return RFAL_ERR_TIMEOUT : Timeout error
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalST25xVPollerM24LRFastReadSingleBlock( uint8_t flags, const uint8_t* uid, uint16_t blockNum, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen );
-
-/*!
- *****************************************************************************
- * \brief NFC-V Poller Write Single Block (M24LR)
- *
- * Writes a Single Block from a M24LR tag which has the number of blocks
- * bigger than 256 (M24LR16 ; M24LR64)
- *
- * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
- * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
- * \param[in] uid : UID of the device to be put to be written
- * if not provided Select mode will be used
- * \param[in] blockNum : Number of the block to write (16 bits)
- * \param[in] wrData : data to be written on the given block
- * \param[in] blockLen : number of bytes of a block
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_CRC : CRC error detected
- * \return RFAL_ERR_FRAMING : Framing error detected
- * \return RFAL_ERR_PROTO : Protocol error detected
- * \return RFAL_ERR_TIMEOUT : Timeout error
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalST25xVPollerM24LRWriteSingleBlock( uint8_t flags, const uint8_t* uid, uint16_t blockNum, const uint8_t* wrData, uint8_t blockLen );
-
-/*!
- *****************************************************************************
- * \brief NFC-V Poller Read Multiple Blocks (M24LR)
- *
- * Reads Multiple Blocks from a device from a M24LR tag which has the number of blocks
- * bigger than 256 (M24LR16 ; M24LR64)
- *
- * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
- * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
- * \param[in] uid : UID of the device to be put to be read
- * if not provided Select mode will be used
- * \param[in] firstBlockNum : first block to be read (16 bits)
- * \param[in] numOfBlocks : number of block to read
- * \param[out] rxBuf : buffer to store response (also with RES_FLAGS)
- * \param[in] rxBufLen : length of rxBuf
- * \param[out] rcvLen : number of bytes received
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_CRC : CRC error detected
- * \return RFAL_ERR_FRAMING : Framing error detected
- * \return RFAL_ERR_PROTO : Protocol error detected
- * \return RFAL_ERR_TIMEOUT : Timeout error
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalST25xVPollerM24LRReadMultipleBlocks( uint8_t flags, const uint8_t* uid, uint16_t firstBlockNum, uint8_t numOfBlocks, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen );
-
-
-/*!
- *****************************************************************************
- * \brief NFC-V Poller Fast Read Multiple Blocks (M24LR)
- *
- * Reads Multiple Blocks from a device from a M24LR tag which has the number of blocks
- * bigger than 256 (M24LR16 ; M24LR64) using ST Fast mode
- *
- * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
- * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
- * \param[in] uid : UID of the device to be put to be read
- * if not provided Select mode will be used
- * \param[in] firstBlockNum : first block to be read (16 bits)
- * \param[in] numOfBlocks : number of block to read
- * \param[out] rxBuf : buffer to store response (also with RES_FLAGS)
- * \param[in] rxBufLen : length of rxBuf
- * \param[out] rcvLen : number of bytes received
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_CRC : CRC error detected
- * \return RFAL_ERR_FRAMING : Framing error detected
- * \return RFAL_ERR_PROTO : Protocol error detected
- * \return RFAL_ERR_TIMEOUT : Timeout error
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalST25xVPollerM24LRFastReadMultipleBlocks( uint8_t flags, const uint8_t* uid, uint16_t firstBlockNum, uint8_t numOfBlocks, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen );
-
-/*!
- *****************************************************************************
- * \brief NFC-V Poller Fast Read Single Block
- *
- * Reads a Single Block from a device (VICC) using ST Fast mode
- *
- * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
- * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
- * \param[in] uid : UID of the device to be put to be read
- * if not provided Select mode will be used
- * \param[in] blockNum : Number of the block to read
- * \param[out] rxBuf : buffer to store response (also with RES_FLAGS)
- * \param[in] rxBufLen : length of rxBuf
- * \param[out] rcvLen : number of bytes received
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_CRC : CRC error detected
- * \return RFAL_ERR_FRAMING : Framing error detected
- * \return RFAL_ERR_PROTO : Protocol error detected
- * \return RFAL_ERR_TIMEOUT : Timeout error
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalST25xVPollerFastReadSingleBlock( uint8_t flags, const uint8_t* uid, uint8_t blockNum, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen );
-
-/*!
- *****************************************************************************
- * \brief NFC-V Poller Fast Read Multiple Blocks
- *
- * Reads Multiple Blocks from a device (VICC) using ST Fast mode
- *
- * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
- * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
- * \param[in] uid : UID of the device to be put to be read
- * if not provided Select mode will be used
- * \param[in] firstBlockNum : first block to be read
- * \param[in] numOfBlocks : number of block to read
- * \param[out] rxBuf : buffer to store response (also with RES_FLAGS)
- * \param[in] rxBufLen : length of rxBuf
- * \param[out] rcvLen : number of bytes received
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_CRC : CRC error detected
- * \return RFAL_ERR_FRAMING : Framing error detected
- * \return RFAL_ERR_PROTO : Protocol error detected
- * \return RFAL_ERR_TIMEOUT : Timeout error
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalST25xVPollerFastReadMultipleBlocks( uint8_t flags, const uint8_t* uid, uint8_t firstBlockNum, uint8_t numOfBlocks, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen );
-
-/*!
- *****************************************************************************
- * \brief NFC-V Poller Fast Extended Read Single Block
- *
- * Reads a Single Block from a device (VICC) supporting extended commands using ST Fast mode
- *
- * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
- * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
- * \param[in] uid : UID of the device to be put to be read
- * if not provided Select mode will be used
- * \param[in] blockNum : Number of the block to read (16 bits)
- * \param[out] rxBuf : buffer to store response (also with RES_FLAGS)
- * \param[in] rxBufLen : length of rxBuf
- * \param[out] rcvLen : number of bytes received
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_CRC : CRC error detected
- * \return RFAL_ERR_FRAMING : Framing error detected
- * \return RFAL_ERR_PROTO : Protocol error detected
- * \return RFAL_ERR_TIMEOUT : Timeout error
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalST25xVPollerFastExtendedReadSingleBlock( uint8_t flags, const uint8_t* uid, uint16_t blockNum, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen );
-
-/*!
- *****************************************************************************
- * \brief NFC-V Poller Fast Extended Read Multiple Blocks
- *
- * Reads Multiple Blocks from a device (VICC) supporting extended commands using ST Fast mode
- *
- * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
- * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
- * \param[in] uid : UID of the device to be put to be read
- * if not provided Select mode will be used
- * \param[in] firstBlockNum : first block to be read (16 bits)
- * \param[in] numOfBlocks : number of consecutive blocks to read (16 bits)
- * \param[out] rxBuf : buffer to store response (also with RES_FLAGS)
- * \param[in] rxBufLen : length of rxBuf
- * \param[out] rcvLen : number of bytes received
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_CRC : CRC error detected
- * \return RFAL_ERR_FRAMING : Framing error detected
- * \return RFAL_ERR_PROTO : Protocol error detected
- * \return RFAL_ERR_TIMEOUT : Timeout error
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalST25xVPollerFastExtReadMultipleBlocks( uint8_t flags, const uint8_t* uid, uint16_t firstBlockNum, uint16_t numOfBlocks, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen );
-
-/*!
- *****************************************************************************
- * \brief NFC-V Poller Read Configuration
- *
- * Reads static configuration registers at the Pointer address
- *
- * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
- * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
- * \param[in] uid : UID of the device to be put to be read
- * if not provided Select mode will be used
- * \param[in] pointer : Pointer address
- * \param[out] regValue : Register value
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_CRC : CRC error detected
- * \return RFAL_ERR_FRAMING : Framing error detected
- * \return RFAL_ERR_PROTO : Protocol error detected
- * \return RFAL_ERR_TIMEOUT : Timeout error
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalST25xVPollerReadConfiguration( uint8_t flags, const uint8_t* uid, uint8_t pointer, uint8_t* regValue );
-
-/*!
- *****************************************************************************
- * \brief NFC-V Poller Write Configuration
- *
- * Writes static configuration registers at the Pointer address
- *
- * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
- * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
- * \param[in] uid : UID of the device to be put to be read
- * if not provided Select mode will be used
- * \param[in] pointer : Pointer address
- * \param[in] regValue : Register value
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_CRC : CRC error detected
- * \return RFAL_ERR_FRAMING : Framing error detected
- * \return RFAL_ERR_PROTO : Protocol error detected
- * \return RFAL_ERR_TIMEOUT : Timeout error
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalST25xVPollerWriteConfiguration( uint8_t flags, const uint8_t* uid, uint8_t pointer, uint8_t regValue );
-
-
-/*!
- *****************************************************************************
- * \brief NFC-V Poller Read Dynamic Configuration
- *
- * Reads dynamic registers at the Pointer address
- *
- * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
- * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
- * \param[in] uid : UID of the device to be put to be read
- * if not provided Select mode will be used
- * \param[in] pointer : Pointer address
- * \param[out] regValue : Register value
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_CRC : CRC error detected
- * \return RFAL_ERR_FRAMING : Framing error detected
- * \return RFAL_ERR_PROTO : Protocol error detected
- * \return RFAL_ERR_TIMEOUT : Timeout error
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalST25xVPollerReadDynamicConfiguration( uint8_t flags, const uint8_t* uid, uint8_t pointer, uint8_t* regValue );
-
-/*!
- *****************************************************************************
- * \brief NFC-V Poller Write Dynamic Configuration
- *
- * Writes dynamic registers at the Pointer address
- *
- * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
- * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
- * \param[in] uid : UID of the device to be put to be read
- * if not provided Select mode will be used
- * \param[in] pointer : Pointer address
- * \param[in] regValue : Register value
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_CRC : CRC error detected
- * \return RFAL_ERR_FRAMING : Framing error detected
- * \return RFAL_ERR_PROTO : Protocol error detected
- * \return RFAL_ERR_TIMEOUT : Timeout error
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalST25xVPollerWriteDynamicConfiguration( uint8_t flags, const uint8_t* uid, uint8_t pointer, uint8_t regValue );
-
-/*!
- *****************************************************************************
- * \brief NFC-V Poller Fast Read Dynamic Configuration
- *
- * Reads dynamic registers at the Pointer address using ST Fast mode
- *
- * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
- * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
- * \param[in] uid : UID of the device to be put to be read
- * if not provided Select mode will be used
- * \param[in] pointer : Pointer address
- * \param[out] regValue : Register value
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_CRC : CRC error detected
- * \return RFAL_ERR_FRAMING : Framing error detected
- * \return RFAL_ERR_PROTO : Protocol error detected
- * \return RFAL_ERR_TIMEOUT : Timeout error
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalST25xVPollerFastReadDynamicConfiguration( uint8_t flags, const uint8_t* uid, uint8_t pointer, uint8_t* regValue );
-
-/*!
- *****************************************************************************
- * \brief NFC-V Poller Fast Write Dynamic Configuration
- *
- * Writes dynamic registers at the Pointer address using ST Fast mode
- *
- * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
- * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
- * \param[in] uid : UID of the device to be put to be read
- * if not provided Select mode will be used
- * \param[in] pointer : Pointer address
- * \param[in] regValue : Register value
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_CRC : CRC error detected
- * \return RFAL_ERR_FRAMING : Framing error detected
- * \return RFAL_ERR_PROTO : Protocol error detected
- * \return RFAL_ERR_TIMEOUT : Timeout error
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalST25xVPollerFastWriteDynamicConfiguration( uint8_t flags, const uint8_t* uid, uint8_t pointer, uint8_t regValue );
-
-/*!
- *****************************************************************************
- * \brief NFC-V Poller Present Password
- *
- * Sends the Present Password command
- *
- * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
- * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
- * \param[in] uid : UID of the device to be put to be read
- * if not provided Select mode will be used
- * \param[in] pwdNum : Password number
- * \param[in] pwd : Password
- * \param[in] pwdLen : Password length
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_CRC : CRC error detected
- * \return RFAL_ERR_FRAMING : Framing error detected
- * \return RFAL_ERR_PROTO : Protocol error detected
- * \return RFAL_ERR_TIMEOUT : Timeout error
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalST25xVPollerPresentPassword( uint8_t flags, const uint8_t* uid, uint8_t pwdNum, const uint8_t* pwd, uint8_t pwdLen );
-
-/*!
- *****************************************************************************
- * \brief NFC-V Poller Write Password
- *
- * Sends the Write Password command
- *
- * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
- * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
- * \param[in] uid : UID of the device to be put to be read
- * if not provided Select mode will be used
- * \param[in] pwdNum : Password number
- * \param[in] pwd : Password
- * \param[in] pwdLen : Password length
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_CRC : CRC error detected
- * \return RFAL_ERR_FRAMING : Framing error detected
- * \return RFAL_ERR_PROTO : Protocol error detected
- * \return RFAL_ERR_TIMEOUT : Timeout error
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalST25xVPollerWritePassword( uint8_t flags, const uint8_t* uid, uint8_t pwdNum, const uint8_t *pwd, uint8_t pwdLen);
-
-/*!
- *****************************************************************************
- * \brief NFC-V Poller Get Random Number
- *
- * Returns a 16 bit random number
- *
- * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
- * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
- * \param[in] uid : UID of the device to be put to be read
- * if not provided Select mode will be used
- * \param[out] rxBuf : buffer to store response (also with RES_FLAGS)
- * \param[in] rxBufLen : length of rxBuf
- * \param[out] rcvLen : number of bytes received
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_CRC : CRC error detected
- * \return RFAL_ERR_FRAMING : Framing error detected
- * \return RFAL_ERR_PROTO : Protocol error detected
- * \return RFAL_ERR_TIMEOUT : Timeout error
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalST25xVPollerGetRandomNumber( uint8_t flags, const uint8_t* uid, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen );
-
-/*!
- *****************************************************************************
- * \brief NFC-V Poller Read Message length
- *
- * Sends a Read Message Length message to retrieve the value of MB_LEN_Dyn
- *
- * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
- * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
- * \param[in] uid : UID of the device to be put to be read
- * if not provided Select mode will be used
- * \param[out] msgLen : Message Length
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_CRC : CRC error detected
- * \return RFAL_ERR_FRAMING : Framing error detected
- * \return RFAL_ERR_PROTO : Protocol error detected
- * \return RFAL_ERR_TIMEOUT : Timeout error
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalST25xVPollerReadMessageLength( uint8_t flags, const uint8_t* uid, uint8_t* msgLen );
-
-/*!
- *****************************************************************************
- * \brief NFC-V Poller Fast Read Message length
- *
- * Sends a Fast Read Message Length message to retrieve the value of MB_LEN_Dyn using ST Fast mode.
- *
- * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
- * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
- * \param[in] uid : UID of the device to be put to be read
- * if not provided Select mode will be used
- * \param[out] msgLen : Message Length
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_CRC : CRC error detected
- * \return RFAL_ERR_FRAMING : Framing error detected
- * \return RFAL_ERR_PROTO : Protocol error detected
- * \return RFAL_ERR_TIMEOUT : Timeout error
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalST25xVPollerFastReadMsgLength( uint8_t flags, const uint8_t* uid, uint8_t* msgLen );
-
-/*!
- *****************************************************************************
- * \brief NFC-V Poller Read Message
- *
- * Reads up to 256 bytes in the Mailbox from the location
- * specified by MBpointer and sends back their value in the rxBuf response.
- * First MailBox location is '00'. When Number of bytes is set to 00h
- * and MBPointer is equals to 00h, the MB_LEN bytes of the full message
- * are returned. Otherwise, Read Message command returns (Number of Bytes + 1) bytes
- * (i.e. 01h returns 2 bytes, FFh returns 256 bytes).
- * An error is reported if (Pointer + Nb of bytes + 1) is greater than the message length.
- * RF Reading of the last byte of the mailbox message automatically clears b1
- * of MB_CTRL_Dyn HOST_PUT_MSG, and allows RF to put a new message.
- *
- * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
- * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
- * \param[in] uid : UID of the device to be put to be read
- * if not provided Select mode will be used
- * \param[in] mbPointer : MPpointer
- * \param[in] numBytes : number of bytes
- * \param[out] rxBuf : buffer to store response (also with RES_FLAGS)
- * \param[in] rxBufLen : length of rxBuf
- * \param[out] rcvLen : number of bytes received
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_CRC : CRC error detected
- * \return RFAL_ERR_FRAMING : Framing error detected
- * \return RFAL_ERR_PROTO : Protocol error detected
- * \return RFAL_ERR_TIMEOUT : Timeout error
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalST25xVPollerReadMessage( uint8_t flags, const uint8_t* uid, uint8_t mbPointer, uint8_t numBytes, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen );
-
-/*!
- *****************************************************************************
- * \brief NFC-V Poller Fast Read Message
- *
- * Reads up to 256 bytes in the Mailbox from the location
- * specified by MBpointer and sends back their value in the rxBuf response using ST Fast mode.
- * First MailBox location is '00'. When Number of bytes is set to 00h
- * and MBPointer is equals to 00h, the MB_LEN bytes of the full message
- * are returned. Otherwise, Read Message command returns (Number of Bytes + 1) bytes
- * (i.e. 01h returns 2 bytes, FFh returns 256 bytes).
- * An error is reported if (Pointer + Nb of bytes + 1) is greater than the message length.
- * RF Reading of the last byte of the mailbox message automatically clears b1
- * of MB_CTRL_Dyn HOST_PUT_MSG, and allows RF to put a new message.
- *
- * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
- * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
- * \param[in] uid : UID of the device to be put to be read
- * if not provided Select mode will be used
- * \param[in] mbPointer : MPpointer
- * \param[in] numBytes : number of bytes
- * \param[out] rxBuf : buffer to store response (also with RES_FLAGS)
- * \param[in] rxBufLen : length of rxBuf
- * \param[out] rcvLen : number of bytes received
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_CRC : CRC error detected
- * \return RFAL_ERR_FRAMING : Framing error detected
- * \return RFAL_ERR_PROTO : Protocol error detected
- * \return RFAL_ERR_TIMEOUT : Timeout error
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalST25xVPollerFastReadMessage( uint8_t flags, const uint8_t* uid, uint8_t mbPointer, uint8_t numBytes, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen );
-
-/*!
- *****************************************************************************
- * \brief NFC-V Poller Write Message
- *
- * Sends Write message Command
- *
- * On receiving the Write Message command, the ST25DVxxx puts the data contained
- * in the request into the Mailbox buffer, update the MB_LEN_Dyn register, and
- * set bit RF_PUT_MSG in MB_CTRL_Dyn register. It then reports if the write operation was successful
- * in the response. The ST25DVxxx Mailbox contains up to 256 data bytes which are filled from the
- * first location '00'. MSGlength parameter of the command is the number of
- * Data bytes minus 1 (00 for 1 byte of data, FFh for 256 bytes of data).
- * Write Message could be executed only when Mailbox is accessible by RF.
- *
- * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
- * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
- * \param[in] uid : UID of the device to be put to be read
- * if not provided Select mode will be used
- * \param[in] msgLen : MSGLen number of Data bytes minus 1
- * \param[in] msgData : Message Data
- * \param[out] txBuf : buffer to used to build the Write Message command
- * \param[in] txBufLen : length of txBuf
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_CRC : CRC error detected
- * \return RFAL_ERR_FRAMING : Framing error detected
- * \return RFAL_ERR_PROTO : Protocol error detected
- * \return RFAL_ERR_TIMEOUT : Timeout error
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalST25xVPollerWriteMessage( uint8_t flags, const uint8_t* uid, uint8_t msgLen, const uint8_t* msgData, uint8_t* txBuf, uint16_t txBufLen );
-
-/*!
- *****************************************************************************
- * \brief NFC-V Poller Fast Write Message
- *
- * Sends Fast Write message Command using ST Fast mode
- *
- * On receiving the Write Message command, the ST25DVxxx puts the data contained
- * in the request into the Mailbox buffer, update the MB_LEN_Dyn register, and
- * set bit RF_PUT_MSG in MB_CTRL_Dyn register. It then reports if the write operation was successful
- * in the response. The ST25DVxxx Mailbox contains up to 256 data bytes which are filled from the
- * first location '00'. MSGlength parameter of the command is the number of
- * Data bytes minus 1 (00 for 1 byte of data, FFh for 256 bytes of data).
- * Write Message could be executed only when Mailbox is accessible by RF.
- *
- * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
- * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
- * \param[in] uid : UID of the device to be put to be read
- * if not provided Select mode will be used
- * \param[in] msgLen : MSGLen number of Data bytes minus 1
- * \param[in] msgData : Message Data
- * \param[out] txBuf : buffer to used to build the Write Message command
- * \param[in] txBufLen : length of txBuf
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_CRC : CRC error detected
- * \return RFAL_ERR_FRAMING : Framing error detected
- * \return RFAL_ERR_PROTO : Protocol error detected
- * \return RFAL_ERR_TIMEOUT : Timeout error
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalST25xVPollerFastWriteMessage( uint8_t flags, const uint8_t* uid, uint8_t msgLen, const uint8_t* msgData, uint8_t* txBuf, uint16_t txBufLen );
-
-/*!
- *****************************************************************************
- * \brief NFC-V Poller Read Configuration (ST25TV02KC ST25TV512C version)
- *
- * Reads static configuration registers at the Pointer address
- *
- * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
- * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
- * \param[in] uid : UID of the device to be put to be read
- * if not provided Select mode will be used
- * \param[in] fid : FID
- * \param[in] pid : PID
- * \param[out] rxBuf : buffer to store response (also with RES_FLAGS)
- * \param[in] rxBufLen : length of rxBuf
- * \param[out] rcvLen : number of bytes received
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_CRC : CRC error detected
- * \return RFAL_ERR_FRAMING : Framing error detected
- * \return RFAL_ERR_PROTO : Protocol error detected
- * \return RFAL_ERR_TIMEOUT : Timeout error
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalST25TV512CPollerReadConfiguration(uint8_t flags, const uint8_t* uid, uint8_t fid, uint8_t pid, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen );
-
-/*!
- *****************************************************************************
- * \brief NFC-V Poller Write Configuration (ST25TV02KC ST25TV512C version)
- *
- * Writes static configuration registers at the Pointer address
- *
- * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
- * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
- * \param[in] uid : UID of the device to be put to be read
- * if not provided Select mode will be used
- * \param[in] fid : FID
- * \param[in] pid : PID
- * \param[in] data : Register value
- * \param[in] dataLen : size of register value
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
- * \return RFAL_ERR_PARAM : Invalid parameters
- * \return RFAL_ERR_IO : Generic internal error
- * \return RFAL_ERR_CRC : CRC error detected
- * \return RFAL_ERR_FRAMING : Framing error detected
- * \return RFAL_ERR_PROTO : Protocol error detected
- * \return RFAL_ERR_TIMEOUT : Timeout error
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalST25TV512CPollerWriteConfiguration(uint8_t flags, const uint8_t* uid, uint8_t fid, uint8_t pid, const uint8_t *data, uint8_t dataLen );
-
-#endif /* RFAL_ST25xV_H */
-
-/**
- * @}
- *
- * @}
- *
- * @}
- */
-
+
+/******************************************************************************
+ * @attention
+ *
+ * COPYRIGHT 2016 STMicroelectronics, all rights reserved
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
+ * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+******************************************************************************/
+
+
+/*
+ * PROJECT: ST25R firmware
+ * Revision:
+ * LANGUAGE: ISO C99
+ */
+
+/*! \file rfal_st25xv.h
+ *
+ * \author Gustavo Patricio
+ *
+ * \brief NFC-V ST25 NFC-V Tag specific features
+ *
+ * This module provides support for ST's specific features available on
+ * NFC-V (ISO15693) tag families: ST25D, ST25TV, M24LR
+ *
+ *
+ * \addtogroup RFAL
+ * @{
+ *
+ * \addtogroup RFAL-AL
+ * \brief RFAL Abstraction Layer
+ * @{
+ *
+ * \addtogroup ST25xV
+ * \brief RFAL ST25xV Module
+ * @{
+ *
+ */
+
+#ifndef RFAL_ST25xV_H
+#define RFAL_ST25xV_H
+
+/*
+ ******************************************************************************
+ * INCLUDES
+ ******************************************************************************
+ */
+#include "rfal_platform.h"
+#include "rfal_utils.h"
+#include "rfal_rf.h"
+
+/*
+ ******************************************************************************
+ * C LINKAGE GUARD
+ ******************************************************************************
+ */
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/*
+ ******************************************************************************
+ * GLOBAL DEFINES
+ ******************************************************************************
+ */
+
+
+/*!
+ *****************************************************************************
+ * \brief NFC-V Poller Read Single Block (M24LR)
+ *
+ * Reads a Single Block from a M24LR tag which has the number of blocks
+ * bigger than 256 (M24LR16 ; M24LR64)
+ *
+ * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
+ * default: RFAL_NFCV_REQ_FLAG_DEFAULT
+ * \param[in] uid : UID of the device to be put to be read
+ * if not provided Select mode will be used
+ * \param[in] blockNum : Number of the block to read (16 bits)
+ * \param[out] rxBuf : buffer to store response (also with RES_FLAGS)
+ * \param[in] rxBufLen : length of rxBuf
+ * \param[out] rcvLen : number of bytes received
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_CRC : CRC error detected
+ * \return RFAL_ERR_FRAMING : Framing error detected
+ * \return RFAL_ERR_PROTO : Protocol error detected
+ * \return RFAL_ERR_TIMEOUT : Timeout error
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalST25xVPollerM24LRReadSingleBlock( uint8_t flags, const uint8_t* uid, uint16_t blockNum, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen );
+
+/*!
+ *****************************************************************************
+ * \brief NFC-V Poller Fast Read Single Block (M24LR)
+ *
+ * Reads a Single Block from a M24LR tag which has the number of blocks
+ * bigger than 256 (M24LR16 ; M24LR64) using ST Fast mode
+ *
+ * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
+ * default: RFAL_NFCV_REQ_FLAG_DEFAULT
+ * \param[in] uid : UID of the device to be put to be read
+ * if not provided Select mode will be used
+ * \param[in] blockNum : Number of the block to read (16 bits)
+ * \param[out] rxBuf : buffer to store response (also with RES_FLAGS)
+ * \param[in] rxBufLen : length of rxBuf
+ * \param[out] rcvLen : number of bytes received
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_CRC : CRC error detected
+ * \return RFAL_ERR_FRAMING : Framing error detected
+ * \return RFAL_ERR_PROTO : Protocol error detected
+ * \return RFAL_ERR_TIMEOUT : Timeout error
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalST25xVPollerM24LRFastReadSingleBlock( uint8_t flags, const uint8_t* uid, uint16_t blockNum, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen );
+
+/*!
+ *****************************************************************************
+ * \brief NFC-V Poller Write Single Block (M24LR)
+ *
+ * Writes a Single Block from a M24LR tag which has the number of blocks
+ * bigger than 256 (M24LR16 ; M24LR64)
+ *
+ * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
+ * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
+ * \param[in] uid : UID of the device to be put to be written
+ * if not provided Select mode will be used
+ * \param[in] blockNum : Number of the block to write (16 bits)
+ * \param[in] wrData : data to be written on the given block
+ * \param[in] blockLen : number of bytes of a block
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_CRC : CRC error detected
+ * \return RFAL_ERR_FRAMING : Framing error detected
+ * \return RFAL_ERR_PROTO : Protocol error detected
+ * \return RFAL_ERR_TIMEOUT : Timeout error
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalST25xVPollerM24LRWriteSingleBlock( uint8_t flags, const uint8_t* uid, uint16_t blockNum, const uint8_t* wrData, uint8_t blockLen );
+
+/*!
+ *****************************************************************************
+ * \brief NFC-V Poller Read Multiple Blocks (M24LR)
+ *
+ * Reads Multiple Blocks from a device from a M24LR tag which has the number of blocks
+ * bigger than 256 (M24LR16 ; M24LR64)
+ *
+ * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
+ * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
+ * \param[in] uid : UID of the device to be put to be read
+ * if not provided Select mode will be used
+ * \param[in] firstBlockNum : first block to be read (16 bits)
+ * \param[in] numOfBlocks : number of block to read
+ * \param[out] rxBuf : buffer to store response (also with RES_FLAGS)
+ * \param[in] rxBufLen : length of rxBuf
+ * \param[out] rcvLen : number of bytes received
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_CRC : CRC error detected
+ * \return RFAL_ERR_FRAMING : Framing error detected
+ * \return RFAL_ERR_PROTO : Protocol error detected
+ * \return RFAL_ERR_TIMEOUT : Timeout error
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalST25xVPollerM24LRReadMultipleBlocks( uint8_t flags, const uint8_t* uid, uint16_t firstBlockNum, uint8_t numOfBlocks, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen );
+
+
+/*!
+ *****************************************************************************
+ * \brief NFC-V Poller Fast Read Multiple Blocks (M24LR)
+ *
+ * Reads Multiple Blocks from a device from a M24LR tag which has the number of blocks
+ * bigger than 256 (M24LR16 ; M24LR64) using ST Fast mode
+ *
+ * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
+ * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
+ * \param[in] uid : UID of the device to be put to be read
+ * if not provided Select mode will be used
+ * \param[in] firstBlockNum : first block to be read (16 bits)
+ * \param[in] numOfBlocks : number of block to read
+ * \param[out] rxBuf : buffer to store response (also with RES_FLAGS)
+ * \param[in] rxBufLen : length of rxBuf
+ * \param[out] rcvLen : number of bytes received
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_CRC : CRC error detected
+ * \return RFAL_ERR_FRAMING : Framing error detected
+ * \return RFAL_ERR_PROTO : Protocol error detected
+ * \return RFAL_ERR_TIMEOUT : Timeout error
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalST25xVPollerM24LRFastReadMultipleBlocks( uint8_t flags, const uint8_t* uid, uint16_t firstBlockNum, uint8_t numOfBlocks, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen );
+
+/*!
+ *****************************************************************************
+ * \brief NFC-V Poller Fast Read Single Block
+ *
+ * Reads a Single Block from a device (VICC) using ST Fast mode
+ *
+ * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
+ * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
+ * \param[in] uid : UID of the device to be put to be read
+ * if not provided Select mode will be used
+ * \param[in] blockNum : Number of the block to read
+ * \param[out] rxBuf : buffer to store response (also with RES_FLAGS)
+ * \param[in] rxBufLen : length of rxBuf
+ * \param[out] rcvLen : number of bytes received
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_CRC : CRC error detected
+ * \return RFAL_ERR_FRAMING : Framing error detected
+ * \return RFAL_ERR_PROTO : Protocol error detected
+ * \return RFAL_ERR_TIMEOUT : Timeout error
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalST25xVPollerFastReadSingleBlock( uint8_t flags, const uint8_t* uid, uint8_t blockNum, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen );
+
+/*!
+ *****************************************************************************
+ * \brief NFC-V Poller Fast Read Multiple Blocks
+ *
+ * Reads Multiple Blocks from a device (VICC) using ST Fast mode
+ *
+ * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
+ * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
+ * \param[in] uid : UID of the device to be put to be read
+ * if not provided Select mode will be used
+ * \param[in] firstBlockNum : first block to be read
+ * \param[in] numOfBlocks : number of block to read
+ * \param[out] rxBuf : buffer to store response (also with RES_FLAGS)
+ * \param[in] rxBufLen : length of rxBuf
+ * \param[out] rcvLen : number of bytes received
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_CRC : CRC error detected
+ * \return RFAL_ERR_FRAMING : Framing error detected
+ * \return RFAL_ERR_PROTO : Protocol error detected
+ * \return RFAL_ERR_TIMEOUT : Timeout error
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalST25xVPollerFastReadMultipleBlocks( uint8_t flags, const uint8_t* uid, uint8_t firstBlockNum, uint8_t numOfBlocks, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen );
+
+/*!
+ *****************************************************************************
+ * \brief NFC-V Poller Fast Extended Read Single Block
+ *
+ * Reads a Single Block from a device (VICC) supporting extended commands using ST Fast mode
+ *
+ * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
+ * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
+ * \param[in] uid : UID of the device to be put to be read
+ * if not provided Select mode will be used
+ * \param[in] blockNum : Number of the block to read (16 bits)
+ * \param[out] rxBuf : buffer to store response (also with RES_FLAGS)
+ * \param[in] rxBufLen : length of rxBuf
+ * \param[out] rcvLen : number of bytes received
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_CRC : CRC error detected
+ * \return RFAL_ERR_FRAMING : Framing error detected
+ * \return RFAL_ERR_PROTO : Protocol error detected
+ * \return RFAL_ERR_TIMEOUT : Timeout error
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalST25xVPollerFastExtendedReadSingleBlock( uint8_t flags, const uint8_t* uid, uint16_t blockNum, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen );
+
+/*!
+ *****************************************************************************
+ * \brief NFC-V Poller Fast Extended Read Multiple Blocks
+ *
+ * Reads Multiple Blocks from a device (VICC) supporting extended commands using ST Fast mode
+ *
+ * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
+ * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
+ * \param[in] uid : UID of the device to be put to be read
+ * if not provided Select mode will be used
+ * \param[in] firstBlockNum : first block to be read (16 bits)
+ * \param[in] numOfBlocks : number of consecutive blocks to read (16 bits)
+ * \param[out] rxBuf : buffer to store response (also with RES_FLAGS)
+ * \param[in] rxBufLen : length of rxBuf
+ * \param[out] rcvLen : number of bytes received
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_CRC : CRC error detected
+ * \return RFAL_ERR_FRAMING : Framing error detected
+ * \return RFAL_ERR_PROTO : Protocol error detected
+ * \return RFAL_ERR_TIMEOUT : Timeout error
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalST25xVPollerFastExtReadMultipleBlocks( uint8_t flags, const uint8_t* uid, uint16_t firstBlockNum, uint16_t numOfBlocks, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen );
+
+/*!
+ *****************************************************************************
+ * \brief NFC-V Poller Read Configuration
+ *
+ * Reads static configuration registers at the Pointer address
+ *
+ * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
+ * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
+ * \param[in] uid : UID of the device to be put to be read
+ * if not provided Select mode will be used
+ * \param[in] pointer : Pointer address
+ * \param[out] regValue : Register value
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_CRC : CRC error detected
+ * \return RFAL_ERR_FRAMING : Framing error detected
+ * \return RFAL_ERR_PROTO : Protocol error detected
+ * \return RFAL_ERR_TIMEOUT : Timeout error
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalST25xVPollerReadConfiguration( uint8_t flags, const uint8_t* uid, uint8_t pointer, uint8_t* regValue );
+
+/*!
+ *****************************************************************************
+ * \brief NFC-V Poller Write Configuration
+ *
+ * Writes static configuration registers at the Pointer address
+ *
+ * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
+ * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
+ * \param[in] uid : UID of the device to be put to be read
+ * if not provided Select mode will be used
+ * \param[in] pointer : Pointer address
+ * \param[in] regValue : Register value
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_CRC : CRC error detected
+ * \return RFAL_ERR_FRAMING : Framing error detected
+ * \return RFAL_ERR_PROTO : Protocol error detected
+ * \return RFAL_ERR_TIMEOUT : Timeout error
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalST25xVPollerWriteConfiguration( uint8_t flags, const uint8_t* uid, uint8_t pointer, uint8_t regValue );
+
+
+/*!
+ *****************************************************************************
+ * \brief NFC-V Poller Read Dynamic Configuration
+ *
+ * Reads dynamic registers at the Pointer address
+ *
+ * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
+ * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
+ * \param[in] uid : UID of the device to be put to be read
+ * if not provided Select mode will be used
+ * \param[in] pointer : Pointer address
+ * \param[out] regValue : Register value
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_CRC : CRC error detected
+ * \return RFAL_ERR_FRAMING : Framing error detected
+ * \return RFAL_ERR_PROTO : Protocol error detected
+ * \return RFAL_ERR_TIMEOUT : Timeout error
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalST25xVPollerReadDynamicConfiguration( uint8_t flags, const uint8_t* uid, uint8_t pointer, uint8_t* regValue );
+
+/*!
+ *****************************************************************************
+ * \brief NFC-V Poller Write Dynamic Configuration
+ *
+ * Writes dynamic registers at the Pointer address
+ *
+ * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
+ * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
+ * \param[in] uid : UID of the device to be put to be read
+ * if not provided Select mode will be used
+ * \param[in] pointer : Pointer address
+ * \param[in] regValue : Register value
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_CRC : CRC error detected
+ * \return RFAL_ERR_FRAMING : Framing error detected
+ * \return RFAL_ERR_PROTO : Protocol error detected
+ * \return RFAL_ERR_TIMEOUT : Timeout error
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalST25xVPollerWriteDynamicConfiguration( uint8_t flags, const uint8_t* uid, uint8_t pointer, uint8_t regValue );
+
+/*!
+ *****************************************************************************
+ * \brief NFC-V Poller Fast Read Dynamic Configuration
+ *
+ * Reads dynamic registers at the Pointer address using ST Fast mode
+ *
+ * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
+ * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
+ * \param[in] uid : UID of the device to be put to be read
+ * if not provided Select mode will be used
+ * \param[in] pointer : Pointer address
+ * \param[out] regValue : Register value
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_CRC : CRC error detected
+ * \return RFAL_ERR_FRAMING : Framing error detected
+ * \return RFAL_ERR_PROTO : Protocol error detected
+ * \return RFAL_ERR_TIMEOUT : Timeout error
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalST25xVPollerFastReadDynamicConfiguration( uint8_t flags, const uint8_t* uid, uint8_t pointer, uint8_t* regValue );
+
+/*!
+ *****************************************************************************
+ * \brief NFC-V Poller Fast Write Dynamic Configuration
+ *
+ * Writes dynamic registers at the Pointer address using ST Fast mode
+ *
+ * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
+ * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
+ * \param[in] uid : UID of the device to be put to be read
+ * if not provided Select mode will be used
+ * \param[in] pointer : Pointer address
+ * \param[in] regValue : Register value
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_CRC : CRC error detected
+ * \return RFAL_ERR_FRAMING : Framing error detected
+ * \return RFAL_ERR_PROTO : Protocol error detected
+ * \return RFAL_ERR_TIMEOUT : Timeout error
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalST25xVPollerFastWriteDynamicConfiguration( uint8_t flags, const uint8_t* uid, uint8_t pointer, uint8_t regValue );
+
+/*!
+ *****************************************************************************
+ * \brief NFC-V Poller Present Password
+ *
+ * Sends the Present Password command
+ *
+ * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
+ * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
+ * \param[in] uid : UID of the device to be put to be read
+ * if not provided Select mode will be used
+ * \param[in] pwdNum : Password number
+ * \param[in] pwd : Password
+ * \param[in] pwdLen : Password length
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_CRC : CRC error detected
+ * \return RFAL_ERR_FRAMING : Framing error detected
+ * \return RFAL_ERR_PROTO : Protocol error detected
+ * \return RFAL_ERR_TIMEOUT : Timeout error
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalST25xVPollerPresentPassword( uint8_t flags, const uint8_t* uid, uint8_t pwdNum, const uint8_t* pwd, uint8_t pwdLen );
+
+/*!
+ *****************************************************************************
+ * \brief NFC-V Poller Write Password
+ *
+ * Sends the Write Password command
+ *
+ * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
+ * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
+ * \param[in] uid : UID of the device to be put to be read
+ * if not provided Select mode will be used
+ * \param[in] pwdNum : Password number
+ * \param[in] pwd : Password
+ * \param[in] pwdLen : Password length
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_CRC : CRC error detected
+ * \return RFAL_ERR_FRAMING : Framing error detected
+ * \return RFAL_ERR_PROTO : Protocol error detected
+ * \return RFAL_ERR_TIMEOUT : Timeout error
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalST25xVPollerWritePassword( uint8_t flags, const uint8_t* uid, uint8_t pwdNum, const uint8_t *pwd, uint8_t pwdLen);
+
+/*!
+ *****************************************************************************
+ * \brief NFC-V Poller Get Random Number
+ *
+ * Returns a 16 bit random number
+ *
+ * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
+ * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
+ * \param[in] uid : UID of the device to be put to be read
+ * if not provided Select mode will be used
+ * \param[out] rxBuf : buffer to store response (also with RES_FLAGS)
+ * \param[in] rxBufLen : length of rxBuf
+ * \param[out] rcvLen : number of bytes received
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_CRC : CRC error detected
+ * \return RFAL_ERR_FRAMING : Framing error detected
+ * \return RFAL_ERR_PROTO : Protocol error detected
+ * \return RFAL_ERR_TIMEOUT : Timeout error
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalST25xVPollerGetRandomNumber( uint8_t flags, const uint8_t* uid, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen );
+
+/*!
+ *****************************************************************************
+ * \brief NFC-V Poller Read Message length
+ *
+ * Sends a Read Message Length message to retrieve the value of MB_LEN_Dyn
+ *
+ * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
+ * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
+ * \param[in] uid : UID of the device to be put to be read
+ * if not provided Select mode will be used
+ * \param[out] msgLen : Message Length
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_CRC : CRC error detected
+ * \return RFAL_ERR_FRAMING : Framing error detected
+ * \return RFAL_ERR_PROTO : Protocol error detected
+ * \return RFAL_ERR_TIMEOUT : Timeout error
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalST25xVPollerReadMessageLength( uint8_t flags, const uint8_t* uid, uint8_t* msgLen );
+
+/*!
+ *****************************************************************************
+ * \brief NFC-V Poller Fast Read Message length
+ *
+ * Sends a Fast Read Message Length message to retrieve the value of MB_LEN_Dyn using ST Fast mode.
+ *
+ * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
+ * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
+ * \param[in] uid : UID of the device to be put to be read
+ * if not provided Select mode will be used
+ * \param[out] msgLen : Message Length
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_CRC : CRC error detected
+ * \return RFAL_ERR_FRAMING : Framing error detected
+ * \return RFAL_ERR_PROTO : Protocol error detected
+ * \return RFAL_ERR_TIMEOUT : Timeout error
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalST25xVPollerFastReadMsgLength( uint8_t flags, const uint8_t* uid, uint8_t* msgLen );
+
+/*!
+ *****************************************************************************
+ * \brief NFC-V Poller Read Message
+ *
+ * Reads up to 256 bytes in the Mailbox from the location
+ * specified by MBpointer and sends back their value in the rxBuf response.
+ * First MailBox location is '00'. When Number of bytes is set to 00h
+ * and MBPointer is equals to 00h, the MB_LEN bytes of the full message
+ * are returned. Otherwise, Read Message command returns (Number of Bytes + 1) bytes
+ * (i.e. 01h returns 2 bytes, FFh returns 256 bytes).
+ * An error is reported if (Pointer + Nb of bytes + 1) is greater than the message length.
+ * RF Reading of the last byte of the mailbox message automatically clears b1
+ * of MB_CTRL_Dyn HOST_PUT_MSG, and allows RF to put a new message.
+ *
+ * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
+ * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
+ * \param[in] uid : UID of the device to be put to be read
+ * if not provided Select mode will be used
+ * \param[in] mbPointer : MPpointer
+ * \param[in] numBytes : number of bytes
+ * \param[out] rxBuf : buffer to store response (also with RES_FLAGS)
+ * \param[in] rxBufLen : length of rxBuf
+ * \param[out] rcvLen : number of bytes received
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_CRC : CRC error detected
+ * \return RFAL_ERR_FRAMING : Framing error detected
+ * \return RFAL_ERR_PROTO : Protocol error detected
+ * \return RFAL_ERR_TIMEOUT : Timeout error
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalST25xVPollerReadMessage( uint8_t flags, const uint8_t* uid, uint8_t mbPointer, uint8_t numBytes, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen );
+
+/*!
+ *****************************************************************************
+ * \brief NFC-V Poller Fast Read Message
+ *
+ * Reads up to 256 bytes in the Mailbox from the location
+ * specified by MBpointer and sends back their value in the rxBuf response using ST Fast mode.
+ * First MailBox location is '00'. When Number of bytes is set to 00h
+ * and MBPointer is equals to 00h, the MB_LEN bytes of the full message
+ * are returned. Otherwise, Read Message command returns (Number of Bytes + 1) bytes
+ * (i.e. 01h returns 2 bytes, FFh returns 256 bytes).
+ * An error is reported if (Pointer + Nb of bytes + 1) is greater than the message length.
+ * RF Reading of the last byte of the mailbox message automatically clears b1
+ * of MB_CTRL_Dyn HOST_PUT_MSG, and allows RF to put a new message.
+ *
+ * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
+ * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
+ * \param[in] uid : UID of the device to be put to be read
+ * if not provided Select mode will be used
+ * \param[in] mbPointer : MPpointer
+ * \param[in] numBytes : number of bytes
+ * \param[out] rxBuf : buffer to store response (also with RES_FLAGS)
+ * \param[in] rxBufLen : length of rxBuf
+ * \param[out] rcvLen : number of bytes received
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_CRC : CRC error detected
+ * \return RFAL_ERR_FRAMING : Framing error detected
+ * \return RFAL_ERR_PROTO : Protocol error detected
+ * \return RFAL_ERR_TIMEOUT : Timeout error
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalST25xVPollerFastReadMessage( uint8_t flags, const uint8_t* uid, uint8_t mbPointer, uint8_t numBytes, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen );
+
+/*!
+ *****************************************************************************
+ * \brief NFC-V Poller Write Message
+ *
+ * Sends Write message Command
+ *
+ * On receiving the Write Message command, the ST25DVxxx puts the data contained
+ * in the request into the Mailbox buffer, update the MB_LEN_Dyn register, and
+ * set bit RF_PUT_MSG in MB_CTRL_Dyn register. It then reports if the write operation was successful
+ * in the response. The ST25DVxxx Mailbox contains up to 256 data bytes which are filled from the
+ * first location '00'. MSGlength parameter of the command is the number of
+ * Data bytes minus 1 (00 for 1 byte of data, FFh for 256 bytes of data).
+ * Write Message could be executed only when Mailbox is accessible by RF.
+ *
+ * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
+ * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
+ * \param[in] uid : UID of the device to be put to be read
+ * if not provided Select mode will be used
+ * \param[in] msgLen : MSGLen number of Data bytes minus 1
+ * \param[in] msgData : Message Data
+ * \param[out] txBuf : buffer to used to build the Write Message command
+ * \param[in] txBufLen : length of txBuf
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_CRC : CRC error detected
+ * \return RFAL_ERR_FRAMING : Framing error detected
+ * \return RFAL_ERR_PROTO : Protocol error detected
+ * \return RFAL_ERR_TIMEOUT : Timeout error
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalST25xVPollerWriteMessage( uint8_t flags, const uint8_t* uid, uint8_t msgLen, const uint8_t* msgData, uint8_t* txBuf, uint16_t txBufLen );
+
+/*!
+ *****************************************************************************
+ * \brief NFC-V Poller Fast Write Message
+ *
+ * Sends Fast Write message Command using ST Fast mode
+ *
+ * On receiving the Write Message command, the ST25DVxxx puts the data contained
+ * in the request into the Mailbox buffer, update the MB_LEN_Dyn register, and
+ * set bit RF_PUT_MSG in MB_CTRL_Dyn register. It then reports if the write operation was successful
+ * in the response. The ST25DVxxx Mailbox contains up to 256 data bytes which are filled from the
+ * first location '00'. MSGlength parameter of the command is the number of
+ * Data bytes minus 1 (00 for 1 byte of data, FFh for 256 bytes of data).
+ * Write Message could be executed only when Mailbox is accessible by RF.
+ *
+ * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
+ * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
+ * \param[in] uid : UID of the device to be put to be read
+ * if not provided Select mode will be used
+ * \param[in] msgLen : MSGLen number of Data bytes minus 1
+ * \param[in] msgData : Message Data
+ * \param[out] txBuf : buffer to used to build the Write Message command
+ * \param[in] txBufLen : length of txBuf
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_CRC : CRC error detected
+ * \return RFAL_ERR_FRAMING : Framing error detected
+ * \return RFAL_ERR_PROTO : Protocol error detected
+ * \return RFAL_ERR_TIMEOUT : Timeout error
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalST25xVPollerFastWriteMessage( uint8_t flags, const uint8_t* uid, uint8_t msgLen, const uint8_t* msgData, uint8_t* txBuf, uint16_t txBufLen );
+
+/*!
+ *****************************************************************************
+ * \brief NFC-V Poller Read Configuration (ST25TV02KC ST25TV512C version)
+ *
+ * Reads static configuration registers at the Pointer address
+ *
+ * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
+ * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
+ * \param[in] uid : UID of the device to be put to be read
+ * if not provided Select mode will be used
+ * \param[in] fid : FID
+ * \param[in] pid : PID
+ * \param[out] rxBuf : buffer to store response (also with RES_FLAGS)
+ * \param[in] rxBufLen : length of rxBuf
+ * \param[out] rcvLen : number of bytes received
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_CRC : CRC error detected
+ * \return RFAL_ERR_FRAMING : Framing error detected
+ * \return RFAL_ERR_PROTO : Protocol error detected
+ * \return RFAL_ERR_TIMEOUT : Timeout error
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalST25TV512CPollerReadConfiguration(uint8_t flags, const uint8_t* uid, uint8_t fid, uint8_t pid, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen );
+
+/*!
+ *****************************************************************************
+ * \brief NFC-V Poller Write Configuration (ST25TV02KC ST25TV512C version)
+ *
+ * Writes static configuration registers at the Pointer address
+ *
+ * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
+ * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
+ * \param[in] uid : UID of the device to be put to be read
+ * if not provided Select mode will be used
+ * \param[in] fid : FID
+ * \param[in] pid : PID
+ * \param[in] data : Register value
+ * \param[in] dataLen : size of register value
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or incorrect mode
+ * \return RFAL_ERR_PARAM : Invalid parameters
+ * \return RFAL_ERR_IO : Generic internal error
+ * \return RFAL_ERR_CRC : CRC error detected
+ * \return RFAL_ERR_FRAMING : Framing error detected
+ * \return RFAL_ERR_PROTO : Protocol error detected
+ * \return RFAL_ERR_TIMEOUT : Timeout error
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalST25TV512CPollerWriteConfiguration(uint8_t flags, const uint8_t* uid, uint8_t fid, uint8_t pid, const uint8_t *data, uint8_t dataLen );
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* RFAL_ST25xV_H */
+
+/**
+ * @}
+ *
+ * @}
+ *
+ * @}
+ */
+
### core/embed/io/nfc/st25/rfal002/include/rfal_t1t.h
@@ -1,182 +1,195 @@
-
-/******************************************************************************
- * @attention
- *
- * COPYRIGHT 2016 STMicroelectronics, all rights reserved
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
- * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
-******************************************************************************/
-
-
-/*
- * PROJECT: ST25R firmware
- * Revision:
- * LANGUAGE: ISO C99
- */
-
-/*! \file rfal_t1t.h
- *
- * \author Gustavo Patricio
- *
- * \brief Provides NFC-A T1T convenience methods and definitions
- *
- * This module provides an interface to perform as a NFC-A Reader/Writer
- * to handle a Type 1 Tag T1T (Topaz)
- *
- *
- * \addtogroup RFAL
- * @{
- *
- * \addtogroup RFAL-AL
- * \brief RFAL Abstraction Layer
- * @{
- *
- * \addtogroup T1T
- * \brief RFAL T1T Module
- * @{
- *
- */
-
-
-#ifndef RFAL_T1T_H
-#define RFAL_T1T_H
-
-/*
- ******************************************************************************
- * INCLUDES
- ******************************************************************************
- */
-#include "rfal_platform.h"
-#include "rfal_utils.h"
-#include "rfal_rf.h"
-
-/*
- ******************************************************************************
- * GLOBAL DEFINES
- ******************************************************************************
- */
-#define RFAL_T1T_UID_LEN 4 /*!< T1T UID length of cascade level 1 only tag */
-#define RFAL_T1T_HR_LENGTH 2 /*!< T1T HR(Header ROM) length */
-
-#define RFAL_T1T_HR0_NDEF_MASK 0xF0 /*!< T1T HR0 NDEF capability mask T1T 1.2 2.2.2 */
-#define RFAL_T1T_HR0_NDEF_SUPPORT 0x10 /*!< T1T HR0 NDEF capable value T1T 1.2 2.2.2 */
-
-
-/*! NFC-A T1T (Topaz) command set */
-typedef enum
-{
- RFAL_T1T_CMD_RID = 0x78, /*!< T1T Read UID */
- RFAL_T1T_CMD_RALL = 0x00, /*!< T1T Read All */
- RFAL_T1T_CMD_READ = 0x01, /*!< T1T Read */
- RFAL_T1T_CMD_WRITE_E = 0x53, /*!< T1T Write with erase (single byte) */
- RFAL_T1T_CMD_WRITE_NE = 0x1A /*!< T1T Write with no erase (single byte) */
-} rfalT1Tcmds;
-
-
-/*
-******************************************************************************
-* GLOBAL TYPES
-******************************************************************************
-*/
-
-
-/*! NFC-A T1T (Topaz) RID_RES Digital 1.1 10.6.2 & Table 50 */
-typedef struct
-{
- uint8_t hr0; /*!< T1T Header ROM: HR0 */
- uint8_t hr1; /*!< T1T Header ROM: HR1 */
- uint8_t uid[RFAL_T1T_UID_LEN]; /*!< T1T UID */
-} rfalT1TRidRes;
-
-/*
-******************************************************************************
-* GLOBAL FUNCTION PROTOTYPES
-******************************************************************************
-*/
-
-
-/*!
- *****************************************************************************
- * \brief Initialize NFC-A T1T Poller mode
- *
- * This methods configures RFAL RF layer to perform as a
- * NFC-A T1T Poller/RW (Topaz) including all default timings
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or mode not set
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalT1TPollerInitialize( void );
-
-
-/*!
- *****************************************************************************
- * \brief NFC-A T1T Poller RID
- *
- * This method reads the UID of a NFC-A T1T Listener device
- *
- *
- * \param[out] ridRes : pointer to place the RID_RES
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or mode not set
- * \return RFAL_ERR_PARAM : Invalid parameter
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalT1TPollerRid( rfalT1TRidRes *ridRes );
-
-
-/*!
- *****************************************************************************
- * \brief NFC-A T1T Poller RALL
- *
- * This method send a Read All command to a NFC-A T1T Listener device
- *
- *
- * \param[in] uid : the UID of the device to read data
- * \param[out] rxBuf : pointer to place the read data
- * \param[in] rxBufLen : size of rxBuf
- * \param[out] rxRcvdLen : actual received data
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or mode not set
- * \return RFAL_ERR_PARAM : Invalid parameter
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalT1TPollerRall( const uint8_t* uid, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rxRcvdLen );
-
-
-/*!
- *****************************************************************************
- * \brief NFC-A T1T Poller Write
- *
- * This method writes the given data on the address of a NFC-A T1T Listener device
- *
- *
- * \param[in] uid : the UID of the device to read data
- * \param[in] address : address to write the data
- * \param[in] data : the data to be written
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or mode not set
- * \return RFAL_ERR_PARAM : Invalid parameter
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalT1TPollerWrite( const uint8_t* uid, uint8_t address, uint8_t data );
-
-#endif /* RFAL_T1T_H */
-
-/**
- * @}
- *
- * @}
- *
- * @}
- */
+
+/******************************************************************************
+ * @attention
+ *
+ * COPYRIGHT 2016 STMicroelectronics, all rights reserved
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
+ * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+******************************************************************************/
+
+
+/*
+ * PROJECT: ST25R firmware
+ * Revision:
+ * LANGUAGE: ISO C99
+ */
+
+/*! \file rfal_t1t.h
+ *
+ * \author Gustavo Patricio
+ *
+ * \brief Provides NFC-A T1T convenience methods and definitions
+ *
+ * This module provides an interface to perform as a NFC-A Reader/Writer
+ * to handle a Type 1 Tag T1T (Topaz)
+ *
+ *
+ * \addtogroup RFAL
+ * @{
+ *
+ * \addtogroup RFAL-AL
+ * \brief RFAL Abstraction Layer
+ * @{
+ *
+ * \addtogroup T1T
+ * \brief RFAL T1T Module
+ * @{
+ *
+ */
+
+
+#ifndef RFAL_T1T_H
+#define RFAL_T1T_H
+
+/*
+ ******************************************************************************
+ * INCLUDES
+ ******************************************************************************
+ */
+#include "rfal_platform.h"
+#include "rfal_utils.h"
+#include "rfal_rf.h"
+
+/*
+ ******************************************************************************
+ * C LINKAGE GUARD
+ ******************************************************************************
+ */
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/*
+ ******************************************************************************
+ * GLOBAL DEFINES
+ ******************************************************************************
+ */
+#define RFAL_T1T_UID_LEN 4 /*!< T1T UID length of cascade level 1 only tag */
+#define RFAL_T1T_HR_LENGTH 2 /*!< T1T HR(Header ROM) length */
+
+#define RFAL_T1T_HR0_NDEF_MASK 0xF0 /*!< T1T HR0 NDEF capability mask T1T 1.2 2.2.2 */
+#define RFAL_T1T_HR0_NDEF_SUPPORT 0x10 /*!< T1T HR0 NDEF capable value T1T 1.2 2.2.2 */
+
+
+/*! NFC-A T1T (Topaz) command set */
+typedef enum
+{
+ RFAL_T1T_CMD_RID = 0x78, /*!< T1T Read UID */
+ RFAL_T1T_CMD_RALL = 0x00, /*!< T1T Read All */
+ RFAL_T1T_CMD_READ = 0x01, /*!< T1T Read */
+ RFAL_T1T_CMD_WRITE_E = 0x53, /*!< T1T Write with erase (single byte) */
+ RFAL_T1T_CMD_WRITE_NE = 0x1A /*!< T1T Write with no erase (single byte) */
+} rfalT1Tcmds;
+
+
+/*
+******************************************************************************
+* GLOBAL TYPES
+******************************************************************************
+*/
+
+
+/*! NFC-A T1T (Topaz) RID_RES Digital 1.1 10.6.2 & Table 50 */
+typedef struct
+{
+ uint8_t hr0; /*!< T1T Header ROM: HR0 */
+ uint8_t hr1; /*!< T1T Header ROM: HR1 */
+ uint8_t uid[RFAL_T1T_UID_LEN]; /*!< T1T UID */
+} rfalT1TRidRes;
+
+/*
+******************************************************************************
+* GLOBAL FUNCTION PROTOTYPES
+******************************************************************************
+*/
+
+
+/*!
+ *****************************************************************************
+ * \brief Initialize NFC-A T1T Poller mode
+ *
+ * This methods configures RFAL RF layer to perform as a
+ * NFC-A T1T Poller/RW (Topaz) including all default timings
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or mode not set
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalT1TPollerInitialize( void );
+
+
+/*!
+ *****************************************************************************
+ * \brief NFC-A T1T Poller RID
+ *
+ * This method reads the UID of a NFC-A T1T Listener device
+ *
+ *
+ * \param[out] ridRes : pointer to place the RID_RES
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or mode not set
+ * \return RFAL_ERR_PARAM : Invalid parameter
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalT1TPollerRid( rfalT1TRidRes *ridRes );
+
+
+/*!
+ *****************************************************************************
+ * \brief NFC-A T1T Poller RALL
+ *
+ * This method send a Read All command to a NFC-A T1T Listener device
+ *
+ *
+ * \param[in] uid : the UID of the device to read data
+ * \param[out] rxBuf : pointer to place the read data
+ * \param[in] rxBufLen : size of rxBuf
+ * \param[out] rxRcvdLen : actual received data
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or mode not set
+ * \return RFAL_ERR_PARAM : Invalid parameter
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalT1TPollerRall( const uint8_t* uid, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rxRcvdLen );
+
+
+/*!
+ *****************************************************************************
+ * \brief NFC-A T1T Poller Write
+ *
+ * This method writes the given data on the address of a NFC-A T1T Listener device
+ *
+ *
+ * \param[in] uid : the UID of the device to read data
+ * \param[in] address : address to write the data
+ * \param[in] data : the data to be written
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or mode not set
+ * \return RFAL_ERR_PARAM : Invalid parameter
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalT1TPollerWrite( const uint8_t* uid, uint8_t address, uint8_t data );
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* RFAL_T1T_H */
+
+/**
+ * @}
+ *
+ * @}
+ *
+ * @}
+ */
### core/embed/io/nfc/st25/rfal002/include/rfal_t2t.h
@@ -1,148 +1,161 @@
-
-/******************************************************************************
- * @attention
- *
- * COPYRIGHT 2016 STMicroelectronics, all rights reserved
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
- * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
-******************************************************************************/
-
-
-/*
- * PROJECT: ST25R firmware
- * Revision:
- * LANGUAGE: ISO C99
- */
-
-/*! \file rfal_t2t.h
- *
- * \author Gustavo Patricio
- *
- * \brief Provides NFC-A T2T convenience methods and definitions
- *
- * This module provides an interface to perform as a NFC-A Reader/Writer
- * to handle a Type 2 Tag T2T
- *
- *
- * \addtogroup RFAL
- * @{
- *
- * \addtogroup RFAL-AL
- * \brief RFAL Abstraction Layer
- * @{
- *
- * \addtogroup T2T
- * \brief RFAL T2T Module
- * @{
- *
- */
-
-
-#ifndef RFAL_T2T_H
-#define RFAL_T2T_H
-
-/*
- ******************************************************************************
- * INCLUDES
- ******************************************************************************
- */
-#include "rfal_platform.h"
-#include "rfal_utils.h"
-#include "rfal_rf.h"
-
-/*
- ******************************************************************************
- * GLOBAL DEFINES
- ******************************************************************************
- */
-
-#define RFAL_T2T_BLOCK_LEN 4U /*!< T2T block length */
-#define RFAL_T2T_READ_DATA_LEN (4U * RFAL_T2T_BLOCK_LEN) /*!< T2T READ data length */
-#define RFAL_T2T_WRITE_DATA_LEN RFAL_T2T_BLOCK_LEN /*!< T2T WRITE data length */
-
-/*
-******************************************************************************
-* GLOBAL TYPES
-******************************************************************************
-*/
-
-
-/*
-******************************************************************************
-* GLOBAL FUNCTION PROTOTYPES
-******************************************************************************
-*/
-
-/*!
- *****************************************************************************
- * \brief NFC-A T2T Poller Read
- *
- * This method sends a Read command to a NFC-A T2T Listener device
- *
- *
- * \param[in] blockNum : Number of the block to read
- * \param[out] rxBuf : pointer to place the read data
- * \param[in] rxBufLen : size of rxBuf (RFAL_T2T_READ_DATA_LEN)
- * \param[out] rcvLen : actual received data
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or mode not set
- * \return RFAL_ERR_PARAM : Invalid parameter
- * \return RFAL_ERR_PROTO : Protocol error
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalT2TPollerRead( uint8_t blockNum, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen );
-
-
-/*!
- *****************************************************************************
- * \brief NFC-A T2T Poller Write
- *
- * This method sends a Write command to a NFC-A T2T Listener device
- *
- *
- * \param[in] blockNum : Number of the block to write
- * \param[in] wrData : data to be written on the given block
- * size must be of RFAL_T2T_WRITE_DATA_LEN
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or mode not set
- * \return RFAL_ERR_PARAM : Invalid parameter
- * \return RFAL_ERR_PROTO : Protocol error
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalT2TPollerWrite( uint8_t blockNum, const uint8_t* wrData );
-
-
-/*!
- *****************************************************************************
- * \brief NFC-A T2T Poller Sector Select
- *
- * This method sends a Sector Select commands to a NFC-A T2T Listener device
- *
- * \param[in] sectorNum : Sector Number
- *
- * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or mode not set
- * \return RFAL_ERR_PARAM : Invalid parameter
- * \return RFAL_ERR_PROTO : Protocol error
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalT2TPollerSectorSelect( uint8_t sectorNum );
-
-#endif /* RFAL_T2T_H */
-
-/**
- * @}
- *
- * @}
- *
- * @}
- */
+
+/******************************************************************************
+ * @attention
+ *
+ * COPYRIGHT 2016 STMicroelectronics, all rights reserved
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
+ * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+******************************************************************************/
+
+
+/*
+ * PROJECT: ST25R firmware
+ * Revision:
+ * LANGUAGE: ISO C99
+ */
+
+/*! \file rfal_t2t.h
+ *
+ * \author Gustavo Patricio
+ *
+ * \brief Provides NFC-A T2T convenience methods and definitions
+ *
+ * This module provides an interface to perform as a NFC-A Reader/Writer
+ * to handle a Type 2 Tag T2T
+ *
+ *
+ * \addtogroup RFAL
+ * @{
+ *
+ * \addtogroup RFAL-AL
+ * \brief RFAL Abstraction Layer
+ * @{
+ *
+ * \addtogroup T2T
+ * \brief RFAL T2T Module
+ * @{
+ *
+ */
+
+
+#ifndef RFAL_T2T_H
+#define RFAL_T2T_H
+
+/*
+ ******************************************************************************
+ * INCLUDES
+ ******************************************************************************
+ */
+#include "rfal_platform.h"
+#include "rfal_utils.h"
+#include "rfal_rf.h"
+
+/*
+ ******************************************************************************
+ * C LINKAGE GUARD
+ ******************************************************************************
+ */
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/*
+ ******************************************************************************
+ * GLOBAL DEFINES
+ ******************************************************************************
+ */
+
+#define RFAL_T2T_BLOCK_LEN 4U /*!< T2T block length */
+#define RFAL_T2T_READ_DATA_LEN (4U * RFAL_T2T_BLOCK_LEN) /*!< T2T READ data length */
+#define RFAL_T2T_WRITE_DATA_LEN RFAL_T2T_BLOCK_LEN /*!< T2T WRITE data length */
+
+/*
+******************************************************************************
+* GLOBAL TYPES
+******************************************************************************
+*/
+
+
+/*
+******************************************************************************
+* GLOBAL FUNCTION PROTOTYPES
+******************************************************************************
+*/
+
+/*!
+ *****************************************************************************
+ * \brief NFC-A T2T Poller Read
+ *
+ * This method sends a Read command to a NFC-A T2T Listener device
+ *
+ *
+ * \param[in] blockNum : Number of the block to read
+ * \param[out] rxBuf : pointer to place the read data
+ * \param[in] rxBufLen : size of rxBuf (RFAL_T2T_READ_DATA_LEN)
+ * \param[out] rcvLen : actual received data
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or mode not set
+ * \return RFAL_ERR_PARAM : Invalid parameter
+ * \return RFAL_ERR_PROTO : Protocol error
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalT2TPollerRead( uint8_t blockNum, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen );
+
+
+/*!
+ *****************************************************************************
+ * \brief NFC-A T2T Poller Write
+ *
+ * This method sends a Write command to a NFC-A T2T Listener device
+ *
+ *
+ * \param[in] blockNum : Number of the block to write
+ * \param[in] wrData : data to be written on the given block
+ * size must be of RFAL_T2T_WRITE_DATA_LEN
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or mode not set
+ * \return RFAL_ERR_PARAM : Invalid parameter
+ * \return RFAL_ERR_PROTO : Protocol error
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalT2TPollerWrite( uint8_t blockNum, const uint8_t* wrData );
+
+
+/*!
+ *****************************************************************************
+ * \brief NFC-A T2T Poller Sector Select
+ *
+ * This method sends a Sector Select commands to a NFC-A T2T Listener device
+ *
+ * \param[in] sectorNum : Sector Number
+ *
+ * \return RFAL_ERR_WRONG_STATE : RFAL not initialized or mode not set
+ * \return RFAL_ERR_PARAM : Invalid parameter
+ * \return RFAL_ERR_PROTO : Protocol error
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalT2TPollerSectorSelect( uint8_t sectorNum );
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* RFAL_T2T_H */
+
+/**
+ * @}
+ *
+ * @}
+ *
+ * @}
+ */
### core/embed/io/nfc/st25/rfal002/include/rfal_t4t.h
@@ -1,359 +1,372 @@
-
-/******************************************************************************
- * @attention
- *
- * COPYRIGHT 2016 STMicroelectronics, all rights reserved
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
- * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
-******************************************************************************/
-
-/*
- * PROJECT: ST25R firmware
- * Revision:
- * LANGUAGE: ISO C99
- */
-
-/*! \file rfal_t4t.h
- *
- * \author Gustavo Patricio
- *
- * \brief Provides convenience methods and definitions for T4T (ISO7816-4)
- *
- * This module provides an interface to exchange T4T APDUs according to
- * NFC Forum T4T and ISO7816-4
- *
- * This implementation was based on the following specs:
- * - ISO/IEC 7816-4 3rd Edition 2013-04-15
- * - NFC Forum T4T Technical Specification 1.0 2017-08-28
- *
- * \addtogroup RFAL
- * @{
- *
- * \addtogroup RFAL-AL
- * \brief RFAL Abstraction Layer
- * @{
- *
- * \addtogroup T4T
- * \brief RFAL T4T Module
- * @{
- *
- */
-
-
-#ifndef RFAL_T4T_H
-#define RFAL_T4T_H
-
-/*
- ******************************************************************************
- * INCLUDES
- ******************************************************************************
- */
-#include "rfal_platform.h"
-#include "rfal_utils.h"
-#include "rfal_rf.h"
-#include "rfal_isoDep.h"
-
-/*
- ******************************************************************************
- * GLOBAL DEFINES
- ******************************************************************************
- */
-
-#define RFAL_T4T_MAX_CAPDU_PROLOGUE_LEN 4U /*!< Command-APDU prologue length (CLA INS P1 P2) */
-#define RFAL_T4T_LE_LEN 1U /*!< Le Expected Response Length (short field coding) */
-#define RFAL_T4T_LC_LEN 1U /*!< Lc Data field length (short field coding) */
-#define RFAL_T4T_MAX_RAPDU_SW1SW2_LEN 2U /*!< SW1 SW2 length */
-#define RFAL_T4T_CLA 0x00U /*!< Class byte (contains 00h because secure message are not used) */
-
-#define RFAL_T4T_ISO7816_P1_SELECT_BY_DF_NAME 0x04U /*!< P1 value for Select by name */
-#define RFAL_T4T_ISO7816_P1_SELECT_BY_FILEID 0x00U /*!< P1 value for Select by file identifier */
-#define RFAL_T4T_ISO7816_P2_SELECT_FIRST_OR_ONLY_OCCURENCE 0x00U /*!< b2b1 P2 value for First or only occurence */
-#define RFAL_T4T_ISO7816_P2_SELECT_RETURN_FCI_TEMPLATE 0x00U /*!< b4b3 P2 value for Return FCI template */
-#define RFAL_T4T_ISO7816_P2_SELECT_NO_RESPONSE_DATA 0x0CU /*!< b4b3 P2 value for No responce data */
-
-#define RFAL_T4T_ISO7816_STATUS_COMPLETE 0x9000U /*!< Command completed \ Normal processing - No further qualification*/
-
-
-/*
-******************************************************************************
-* GLOBAL VARIABLES
-******************************************************************************
-*/
-
-
-/*
-******************************************************************************
-* GLOBAL TYPES
-******************************************************************************
-*/
-/*! NFC-A T4T Command-APDU structure */
-typedef struct
-{
- uint8_t CLA; /*!< Class byte */
- uint8_t INS; /*!< Instruction byte */
- uint8_t P1; /*!< Parameter byte 1 */
- uint8_t P2; /*!< Parameter byte 2 */
- uint8_t Lc; /*!< Data field length */
- bool LcFlag; /*!< Lc flag (append Lc when true) */
- uint8_t Le; /*!< Expected Response Length */
- bool LeFlag; /*!< Le flag (append Le when true) */
-
- rfalIsoDepApduBufFormat *cApduBuf; /*!< Command-APDU buffer (Tx) */
- uint16_t *cApduLen; /*!< Command-APDU Length */
-}rfalT4tCApduParam;
-
-/*! NFC-A T4T Response-APDU structure */
-typedef struct
-{
- rfalIsoDepApduBufFormat *rApduBuf; /*!< Response-APDU buffer (Rx) */
- uint16_t rcvdLen; /*!< Full response length */
- uint16_t rApduBodyLen; /*!< Response body length */
- uint16_t statusWord; /*!< R-APDU Status Word SW1|SW2 */
-}rfalT4tRApduParam;
-
-
-
-/*! NFC-A T4T command set T4T 1.0 & ISO7816-4 2013 Table 4 */
-typedef enum
-{
- RFAL_T4T_INS_SELECT = 0xA4U, /*!< T4T Select */
- RFAL_T4T_INS_READBINARY = 0xB0U, /*!< T4T ReadBinary */
- RFAL_T4T_INS_UPDATEBINARY = 0xD6U, /*!< T4T UpdateBinay */
- RFAL_T4T_INS_READBINARY_ODO = 0xB1U, /*!< T4T ReadBinary using ODO */
- RFAL_T4T_INS_UPDATEBINARY_ODO = 0xD7U /*!< T4T UpdateBinay using ODO */
-} rfalT4tCmds;
-
-/*
-******************************************************************************
-* GLOBAL FUNCTION PROTOTYPES
-******************************************************************************
-*/
-
-/*!
- *****************************************************************************
- * \brief T4T Compose APDU
- *
- * This method computes a C-APDU according to NFC Forum T4T and ISO7816-4.
- *
- * If C-APDU contains data to be sent, it must be placed inside the buffer
- * rfalT4tTxRxApduParam.txRx.cApduBuf.apdu and signaled by Lc
- *
- * To transceive the formed APDU the ISO-DEP layer shall be used
- *
- * \see rfalIsoDepStartApduTransceive()
- * \see rfalIsoDepGetApduTransceiveStatus()
- * \see rfalT4TPollerParseRAPDU()
- *
- * \warning The ISO-DEP module is used to perform the tranceive. Usually
- * activation has been done via ISO-DEP activatiavtion. If not
- * please call rfalIsoDepInitialize() before.
- *
- * \param[in,out] apduParam : APDU parameters
- * apduParam.cApduLen will contain the APDU length
- *
- * \return RFAL_ERR_PARAM : Invalid parameter
- * \return RFAL_ERR_PROTO : Protocol error
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalT4TPollerComposeCAPDU( const rfalT4tCApduParam *apduParam );
-
-
-/*!
- *****************************************************************************
- * \brief T4T Parse R-APDU
- *
- * This method parses a R-APDU according to NFC Forum T4T and ISO7816-4.
- * It will extract the data length and check if the Satus word is expected.
- *
- * \param[in,out] apduParam : APDU parameters
- * apduParam.rApduBodyLen will contain the data length
- * apduParam.statusWord will contain the SW1 and SW2
- *
- * \return RFAL_ERR_REQUEST : Status word (SW1 SW2) different from 9000
- * \return RFAL_ERR_PARAM : Invalid parameter
- * \return RFAL_ERR_PROTO : Protocol error
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalT4TPollerParseRAPDU( rfalT4tRApduParam *apduParam );
-
-/*!
- *****************************************************************************
- * \brief T4T Compose Select Application APDU
- *
- * This method computes a Select Application APDU according to NFC Forum T4T
- *
- * To transceive the formed APDU the ISO-DEP layer shall be used
- *
- * \see rfalIsoDepStartApduTransceive()
- * \see rfalIsoDepGetApduTransceiveStatus()
- *
- * \param[out] cApduBuf : buffer where the C-APDU will be placed
- * \param[in] aid : Application ID to be used
- * \param[in] aidLen : Application ID length
- * \param[out] cApduLen : Composed C-APDU length
- *
- * \return RFAL_ERR_PARAM : Invalid parameter
- * \return RFAL_ERR_PROTO : Protocol error
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalT4TPollerComposeSelectAppl( rfalIsoDepApduBufFormat *cApduBuf, const uint8_t* aid, uint8_t aidLen, uint16_t *cApduLen );
-
-/*!
- *****************************************************************************
- * \brief T4T Compose Select File APDU
- *
- * This method computes a Select File APDU according to NFC Forum T4T
- *
- * To transceive the formed APDU the ISO-DEP layer shall be used
- *
- * \see rfalIsoDepStartApduTransceive()
- * \see rfalIsoDepGetApduTransceiveStatus()
- *
- * \param[out] cApduBuf : buffer where the C-APDU will be placed
- * \param[in] fid : File ID to be used
- * \param[in] fidLen : File ID length
- * \param[out] cApduLen : Composed C-APDU length
- *
- * \return RFAL_ERR_PARAM : Invalid parameter
- * \return RFAL_ERR_PROTO : Protocol error
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalT4TPollerComposeSelectFile( rfalIsoDepApduBufFormat *cApduBuf, const uint8_t* fid, uint8_t fidLen, uint16_t *cApduLen );
-
-/*!
- *****************************************************************************
- * \brief T4T Compose Select File APDU for Mapping Version 1
- *
- * This method computes a Select File APDU according to NFC Forum T4TOP_v1.0
- *
- * To transceive the formed APDU the ISO-DEP layer shall be used
- *
- * \see rfalIsoDepStartApduTransceive()
- * \see rfalIsoDepGetApduTransceiveStatus()
- *
- * \param[out] cApduBuf : buffer where the C-APDU will be placed
- * \param[in] fid : File ID to be used
- * \param[in] fidLen : File ID length
- * \param[out] cApduLen : Composed C-APDU length
- *
- * \return RFAL_ERR_PARAM : Invalid parameter
- * \return RFAL_ERR_PROTO : Protocol error
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalT4TPollerComposeSelectFileV1Mapping( rfalIsoDepApduBufFormat *cApduBuf, const uint8_t* fid, uint8_t fidLen, uint16_t *cApduLen );
-
-/*!
- *****************************************************************************
- * \brief T4T Compose Read Data APDU
- *
- * This method computes a Read Data APDU according to NFC Forum T4T
- *
- * To transceive the formed APDU the ISO-DEP layer shall be used
- *
- * \see rfalIsoDepStartApduTransceive()
- * \see rfalIsoDepGetApduTransceiveStatus()
- *
- * \param[out] cApduBuf : buffer where the C-APDU will be placed
- * \param[in] offset : File offset
- * \param[in] expLen : Expected length (Le)
- * \param[out] cApduLen : Composed C-APDU length
- *
- * \return RFAL_ERR_PARAM : Invalid parameter
- * \return RFAL_ERR_PROTO : Protocol error
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalT4TPollerComposeReadData( rfalIsoDepApduBufFormat *cApduBuf, uint16_t offset, uint8_t expLen, uint16_t *cApduLen );
-
-/*!
- *****************************************************************************
- * \brief T4T Compose Read Data ODO APDU
- *
- * This method computes a Read Data ODO APDU according to NFC Forum T4T
- *
- * To transceive the formed APDU the ISO-DEP layer shall be used
- *
- * \see rfalIsoDepStartApduTransceive()
- * \see rfalIsoDepGetApduTransceiveStatus()
- *
- * \param[out] cApduBuf : buffer where the C-APDU will be placed
- * \param[in] offset : File offset
- * \param[in] expLen : Expected length (Le)
- * \param[out] cApduLen : Composed C-APDU length
- *
- * \return RFAL_ERR_PARAM : Invalid parameter
- * \return RFAL_ERR_PROTO : Protocol error
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalT4TPollerComposeReadDataODO( rfalIsoDepApduBufFormat *cApduBuf, uint32_t offset, uint8_t expLen, uint16_t *cApduLen );
-
-/*!
- *****************************************************************************
- * \brief T4T Compose Write Data APDU
- *
- * This method computes a Write Data APDU according to NFC Forum T4T
- *
- * To transceive the formed APDU the ISO-DEP layer shall be used
- *
- * \see rfalIsoDepStartApduTransceive()
- * \see rfalIsoDepGetApduTransceiveStatus()
- *
- * \param[out] cApduBuf : buffer where the C-APDU will be placed
- * \param[in] offset : File offset
- * \param[in] data : Data to be written
- * \param[in] dataLen : Data length to be written (Lc)
- * \param[out] cApduLen : Composed C-APDU length
- *
- * \return RFAL_ERR_PARAM : Invalid parameter
- * \return RFAL_ERR_PROTO : Protocol error
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalT4TPollerComposeWriteData( rfalIsoDepApduBufFormat *cApduBuf, uint16_t offset, const uint8_t* data, uint8_t dataLen, uint16_t *cApduLen );
-
-/*!
- *****************************************************************************
- * \brief T4T Compose Write Data ODO APDU
- *
- * This method computes a Write Data ODO sAPDU according to NFC Forum T4T
- *
- * To transceive the formed APDU the ISO-DEP layer shall be used
- *
- * \see rfalIsoDepStartApduTransceive()
- * \see rfalIsoDepGetApduTransceiveStatus()
- *
- * \param[out] cApduBuf : buffer where the C-APDU will be placed
- * \param[in] offset : File offset
- * \param[in] data : Data to be written
- * \param[in] dataLen : Data length to be written (Lc)
- * \param[out] cApduLen : Composed C-APDU length
- *
- * \return RFAL_ERR_PARAM : Invalid parameter
- * \return RFAL_ERR_PROTO : Protocol error
- * \return RFAL_ERR_NONE : No error
- *****************************************************************************
- */
-ReturnCode rfalT4TPollerComposeWriteDataODO( rfalIsoDepApduBufFormat *cApduBuf, uint32_t offset, const uint8_t* data, uint8_t dataLen, uint16_t *cApduLen );
-
-#endif /* RFAL_T4T_H */
-
-/**
- * @}
- *
- * @}
- *
- * @}
- */
+
+/******************************************************************************
+ * @attention
+ *
+ * COPYRIGHT 2016 STMicroelectronics, all rights reserved
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
+ * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+******************************************************************************/
+
+/*
+ * PROJECT: ST25R firmware
+ * Revision:
+ * LANGUAGE: ISO C99
+ */
+
+/*! \file rfal_t4t.h
+ *
+ * \author Gustavo Patricio
+ *
+ * \brief Provides convenience methods and definitions for T4T (ISO7816-4)
+ *
+ * This module provides an interface to exchange T4T APDUs according to
+ * NFC Forum T4T and ISO7816-4
+ *
+ * This implementation was based on the following specs:
+ * - ISO/IEC 7816-4 3rd Edition 2013-04-15
+ * - NFC Forum T4T Technical Specification 1.0 2017-08-28
+ *
+ * \addtogroup RFAL
+ * @{
+ *
+ * \addtogroup RFAL-AL
+ * \brief RFAL Abstraction Layer
+ * @{
+ *
+ * \addtogroup T4T
+ * \brief RFAL T4T Module
+ * @{
+ *
+ */
+
+
+#ifndef RFAL_T4T_H
+#define RFAL_T4T_H
+
+/*
+ ******************************************************************************
+ * INCLUDES
+ ******************************************************************************
+ */
+#include "rfal_platform.h"
+#include "rfal_utils.h"
+#include "rfal_rf.h"
+#include "rfal_isoDep.h"
+
+/*
+ ******************************************************************************
+ * C LINKAGE GUARD
+ ******************************************************************************
+ */
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/*
+ ******************************************************************************
+ * GLOBAL DEFINES
+ ******************************************************************************
+ */
+
+#define RFAL_T4T_MAX_CAPDU_PROLOGUE_LEN 4U /*!< Command-APDU prologue length (CLA INS P1 P2) */
+#define RFAL_T4T_LE_LEN 1U /*!< Le Expected Response Length (short field coding) */
+#define RFAL_T4T_LC_LEN 1U /*!< Lc Data field length (short field coding) */
+#define RFAL_T4T_MAX_RAPDU_SW1SW2_LEN 2U /*!< SW1 SW2 length */
+#define RFAL_T4T_CLA 0x00U /*!< Class byte (contains 00h because secure message are not used) */
+
+#define RFAL_T4T_ISO7816_P1_SELECT_BY_DF_NAME 0x04U /*!< P1 value for Select by name */
+#define RFAL_T4T_ISO7816_P1_SELECT_BY_FILEID 0x00U /*!< P1 value for Select by file identifier */
+#define RFAL_T4T_ISO7816_P2_SELECT_FIRST_OR_ONLY_OCCURENCE 0x00U /*!< b2b1 P2 value for First or only occurence */
+#define RFAL_T4T_ISO7816_P2_SELECT_RETURN_FCI_TEMPLATE 0x00U /*!< b4b3 P2 value for Return FCI template */
+#define RFAL_T4T_ISO7816_P2_SELECT_NO_RESPONSE_DATA 0x0CU /*!< b4b3 P2 value for No response data */
+
+#define RFAL_T4T_ISO7816_STATUS_COMPLETE 0x9000U /*!< Command completed \ Normal processing - No further qualification*/
+
+
+/*
+******************************************************************************
+* GLOBAL VARIABLES
+******************************************************************************
+*/
+
+
+/*
+******************************************************************************
+* GLOBAL TYPES
+******************************************************************************
+*/
+/*! NFC-A T4T Command-APDU structure */
+typedef struct
+{
+ uint8_t CLA; /*!< Class byte */
+ uint8_t INS; /*!< Instruction byte */
+ uint8_t P1; /*!< Parameter byte 1 */
+ uint8_t P2; /*!< Parameter byte 2 */
+ uint8_t Lc; /*!< Data field length */
+ bool LcFlag; /*!< Lc flag (append Lc when true) */
+ uint8_t Le; /*!< Expected Response Length */
+ bool LeFlag; /*!< Le flag (append Le when true) */
+
+ rfalIsoDepApduBufFormat *cApduBuf; /*!< Command-APDU buffer (Tx) */
+ uint16_t *cApduLen; /*!< Command-APDU Length */
+}rfalT4tCApduParam;
+
+/*! NFC-A T4T Response-APDU structure */
+typedef struct
+{
+ rfalIsoDepApduBufFormat *rApduBuf; /*!< Response-APDU buffer (Rx) */
+ uint16_t rcvdLen; /*!< Full response length */
+ uint16_t rApduBodyLen; /*!< Response body length */
+ uint16_t statusWord; /*!< R-APDU Status Word SW1|SW2 */
+}rfalT4tRApduParam;
+
+
+
+/*! NFC-A T4T command set T4T 1.0 & ISO7816-4 2013 Table 4 */
+typedef enum
+{
+ RFAL_T4T_INS_SELECT = 0xA4U, /*!< T4T Select */
+ RFAL_T4T_INS_READBINARY = 0xB0U, /*!< T4T ReadBinary */
+ RFAL_T4T_INS_UPDATEBINARY = 0xD6U, /*!< T4T UpdateBinay */
+ RFAL_T4T_INS_READBINARY_ODO = 0xB1U, /*!< T4T ReadBinary using ODO */
+ RFAL_T4T_INS_UPDATEBINARY_ODO = 0xD7U /*!< T4T UpdateBinay using ODO */
+} rfalT4tCmds;
+
+/*
+******************************************************************************
+* GLOBAL FUNCTION PROTOTYPES
+******************************************************************************
+*/
+
+/*!
+ *****************************************************************************
+ * \brief T4T Compose APDU
+ *
+ * This method computes a C-APDU according to NFC Forum T4T and ISO7816-4.
+ *
+ * If C-APDU contains data to be sent, it must be placed inside the buffer
+ * rfalT4tTxRxApduParam.txRx.cApduBuf.apdu and signaled by Lc
+ *
+ * To transceive the formed APDU the ISO-DEP layer shall be used
+ *
+ * \see rfalIsoDepStartApduTransceive()
+ * \see rfalIsoDepGetApduTransceiveStatus()
+ * \see rfalT4TPollerParseRAPDU()
+ *
+ * \warning The ISO-DEP module is used to perform the tranceive. Usually
+ * activation has been done via ISO-DEP activatiavtion. If not
+ * please call rfalIsoDepInitialize() before.
+ *
+ * \param[in,out] apduParam : APDU parameters
+ * apduParam.cApduLen will contain the APDU length
+ *
+ * \return RFAL_ERR_PARAM : Invalid parameter
+ * \return RFAL_ERR_PROTO : Protocol error
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalT4TPollerComposeCAPDU( const rfalT4tCApduParam *apduParam );
+
+
+/*!
+ *****************************************************************************
+ * \brief T4T Parse R-APDU
+ *
+ * This method parses a R-APDU according to NFC Forum T4T and ISO7816-4.
+ * It will extract the data length and check if the Satus word is expected.
+ *
+ * \param[in,out] apduParam : APDU parameters
+ * apduParam.rApduBodyLen will contain the data length
+ * apduParam.statusWord will contain the SW1 and SW2
+ *
+ * \return RFAL_ERR_REQUEST : Status word (SW1 SW2) different from 9000
+ * \return RFAL_ERR_PARAM : Invalid parameter
+ * \return RFAL_ERR_PROTO : Protocol error
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalT4TPollerParseRAPDU( rfalT4tRApduParam *apduParam );
+
+/*!
+ *****************************************************************************
+ * \brief T4T Compose Select Application APDU
+ *
+ * This method computes a Select Application APDU according to NFC Forum T4T
+ *
+ * To transceive the formed APDU the ISO-DEP layer shall be used
+ *
+ * \see rfalIsoDepStartApduTransceive()
+ * \see rfalIsoDepGetApduTransceiveStatus()
+ *
+ * \param[out] cApduBuf : buffer where the C-APDU will be placed
+ * \param[in] aid : Application ID to be used
+ * \param[in] aidLen : Application ID length
+ * \param[out] cApduLen : Composed C-APDU length
+ *
+ * \return RFAL_ERR_PARAM : Invalid parameter
+ * \return RFAL_ERR_PROTO : Protocol error
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalT4TPollerComposeSelectAppl( rfalIsoDepApduBufFormat *cApduBuf, const uint8_t* aid, uint8_t aidLen, uint16_t *cApduLen );
+
+/*!
+ *****************************************************************************
+ * \brief T4T Compose Select File APDU
+ *
+ * This method computes a Select File APDU according to NFC Forum T4T
+ *
+ * To transceive the formed APDU the ISO-DEP layer shall be used
+ *
+ * \see rfalIsoDepStartApduTransceive()
+ * \see rfalIsoDepGetApduTransceiveStatus()
+ *
+ * \param[out] cApduBuf : buffer where the C-APDU will be placed
+ * \param[in] fid : File ID to be used
+ * \param[in] fidLen : File ID length
+ * \param[out] cApduLen : Composed C-APDU length
+ *
+ * \return RFAL_ERR_PARAM : Invalid parameter
+ * \return RFAL_ERR_PROTO : Protocol error
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalT4TPollerComposeSelectFile( rfalIsoDepApduBufFormat *cApduBuf, const uint8_t* fid, uint8_t fidLen, uint16_t *cApduLen );
+
+/*!
+ *****************************************************************************
+ * \brief T4T Compose Select File APDU for Mapping Version 1
+ *
+ * This method computes a Select File APDU according to NFC Forum T4TOP_v1.0
+ *
+ * To transceive the formed APDU the ISO-DEP layer shall be used
+ *
+ * \see rfalIsoDepStartApduTransceive()
+ * \see rfalIsoDepGetApduTransceiveStatus()
+ *
+ * \param[out] cApduBuf : buffer where the C-APDU will be placed
+ * \param[in] fid : File ID to be used
+ * \param[in] fidLen : File ID length
+ * \param[out] cApduLen : Composed C-APDU length
+ *
+ * \return RFAL_ERR_PARAM : Invalid parameter
+ * \return RFAL_ERR_PROTO : Protocol error
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalT4TPollerComposeSelectFileV1Mapping( rfalIsoDepApduBufFormat *cApduBuf, const uint8_t* fid, uint8_t fidLen, uint16_t *cApduLen );
+
+/*!
+ *****************************************************************************
+ * \brief T4T Compose Read Data APDU
+ *
+ * This method computes a Read Data APDU according to NFC Forum T4T
+ *
+ * To transceive the formed APDU the ISO-DEP layer shall be used
+ *
+ * \see rfalIsoDepStartApduTransceive()
+ * \see rfalIsoDepGetApduTransceiveStatus()
+ *
+ * \param[out] cApduBuf : buffer where the C-APDU will be placed
+ * \param[in] offset : File offset
+ * \param[in] expLen : Expected length (Le)
+ * \param[out] cApduLen : Composed C-APDU length
+ *
+ * \return RFAL_ERR_PARAM : Invalid parameter
+ * \return RFAL_ERR_PROTO : Protocol error
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalT4TPollerComposeReadData( rfalIsoDepApduBufFormat *cApduBuf, uint16_t offset, uint8_t expLen, uint16_t *cApduLen );
+
+/*!
+ *****************************************************************************
+ * \brief T4T Compose Read Data ODO APDU
+ *
+ * This method computes a Read Data ODO APDU according to NFC Forum T4T
+ *
+ * To transceive the formed APDU the ISO-DEP layer shall be used
+ *
+ * \see rfalIsoDepStartApduTransceive()
+ * \see rfalIsoDepGetApduTransceiveStatus()
+ *
+ * \param[out] cApduBuf : buffer where the C-APDU will be placed
+ * \param[in] offset : File offset
+ * \param[in] expLen : Expected length (Le)
+ * \param[out] cApduLen : Composed C-APDU length
+ *
+ * \return RFAL_ERR_PARAM : Invalid parameter
+ * \return RFAL_ERR_PROTO : Protocol error
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalT4TPollerComposeReadDataODO( rfalIsoDepApduBufFormat *cApduBuf, uint32_t offset, uint8_t expLen, uint16_t *cApduLen );
+
+/*!
+ *****************************************************************************
+ * \brief T4T Compose Write Data APDU
+ *
+ * This method computes a Write Data APDU according to NFC Forum T4T
+ *
+ * To transceive the formed APDU the ISO-DEP layer shall be used
+ *
+ * \see rfalIsoDepStartApduTransceive()
+ * \see rfalIsoDepGetApduTransceiveStatus()
+ *
+ * \param[out] cApduBuf : buffer where the C-APDU will be placed
+ * \param[in] offset : File offset
+ * \param[in] data : Data to be written
+ * \param[in] dataLen : Data length to be written (Lc)
+ * \param[out] cApduLen : Composed C-APDU length
+ *
+ * \return RFAL_ERR_PARAM : Invalid parameter
+ * \return RFAL_ERR_PROTO : Protocol error
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalT4TPollerComposeWriteData( rfalIsoDepApduBufFormat *cApduBuf, uint16_t offset, const uint8_t* data, uint8_t dataLen, uint16_t *cApduLen );
+
+/*!
+ *****************************************************************************
+ * \brief T4T Compose Write Data ODO APDU
+ *
+ * This method computes a Write Data ODO sAPDU according to NFC Forum T4T
+ *
+ * To transceive the formed APDU the ISO-DEP layer shall be used
+ *
+ * \see rfalIsoDepStartApduTransceive()
+ * \see rfalIsoDepGetApduTransceiveStatus()
+ *
+ * \param[out] cApduBuf : buffer where the C-APDU will be placed
+ * \param[in] offset : File offset
+ * \param[in] data : Data to be written
+ * \param[in] dataLen : Data length to be written (Lc)
+ * \param[out] cApduLen : Composed C-APDU length
+ *
+ * \return RFAL_ERR_PARAM : Invalid parameter
+ * \return RFAL_ERR_PROTO : Protocol error
+ * \return RFAL_ERR_NONE : No error
+ *****************************************************************************
+ */
+ReturnCode rfalT4TPollerComposeWriteDataODO( rfalIsoDepApduBufFormat *cApduBuf, uint32_t offset, const uint8_t* data, uint8_t dataLen, uint16_t *cApduLen );
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* RFAL_T4T_H */
+
+/**
+ * @}
+ *
+ * @}
+ *
+ * @}
+ */
### core/embed/io/nfc/st25/rfal002/include/rfal_utils.h
@@ -1,176 +1,214 @@
-
-/******************************************************************************
- * @attention
- *
- * COPYRIGHT 2016 STMicroelectronics, all rights reserved
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
- * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
-******************************************************************************/
-
-
-
-/*
- * PROJECT: ST25R
- * Revision:
- * LANGUAGE: ISO C99
- */
-
-/*! \file rfal_utils.h
- *
- * \author Gustavo Patricio
- *
- * \brief RF Abstraction Layer (RFAL) Utils
- *
- * \addtogroup RFAL
- * @{
- *
- */
-
-#ifndef RFAL_UTILS_H
-#define RFAL_UTILS_H
-
-/*
-******************************************************************************
-* INCLUDES
-******************************************************************************
-*/
-#include <stdint.h>
-#include <string.h>
-
-
-/*
-******************************************************************************
-* GLOBAL DATA TYPES
-******************************************************************************
-*/
-
-typedef uint16_t ReturnCode; /*!< Standard Return Code type from function. */
-
-/*
-******************************************************************************
-* DEFINES
-******************************************************************************
-*/
-
-/*
- * Error codes to be used within the application.
- * They are represented by an uint8_t
- */
-
-#define RFAL_ERR_NONE ((ReturnCode)0U) /*!< no error occurred */
-#define RFAL_ERR_NOMEM ((ReturnCode)1U) /*!< not enough memory to perform the requested operation */
-#define RFAL_ERR_BUSY ((ReturnCode)2U) /*!< device or resource busy */
-#define RFAL_ERR_IO ((ReturnCode)3U) /*!< generic IO error */
-#define RFAL_ERR_TIMEOUT ((ReturnCode)4U) /*!< error due to timeout */
-#define RFAL_ERR_REQUEST ((ReturnCode)5U) /*!< invalid request or requested function can't be executed at the moment */
-#define RFAL_ERR_NOMSG ((ReturnCode)6U) /*!< No message of desired type */
-#define RFAL_ERR_PARAM ((ReturnCode)7U) /*!< Parameter error */
-#define RFAL_ERR_SYSTEM ((ReturnCode)8U) /*!< System error */
-#define RFAL_ERR_FRAMING ((ReturnCode)9U) /*!< Framing error */
-#define RFAL_ERR_OVERRUN ((ReturnCode)10U) /*!< lost one or more received bytes */
-#define RFAL_ERR_PROTO ((ReturnCode)11U) /*!< protocol error */
-#define RFAL_ERR_INTERNAL ((ReturnCode)12U) /*!< Internal Error */
-#define RFAL_ERR_AGAIN ((ReturnCode)13U) /*!< Call again */
-#define RFAL_ERR_MEM_CORRUPT ((ReturnCode)14U) /*!< memory corruption */
-#define RFAL_ERR_NOT_IMPLEMENTED ((ReturnCode)15U) /*!< not implemented */
-#define RFAL_ERR_PC_CORRUPT ((ReturnCode)16U) /*!< Program Counter has been manipulated or spike/noise trigger illegal operation */
-#define RFAL_ERR_SEND ((ReturnCode)17U) /*!< error sending*/
-#define RFAL_ERR_IGNORE ((ReturnCode)18U) /*!< indicates error detected but to be ignored */
-#define RFAL_ERR_SEMANTIC ((ReturnCode)19U) /*!< indicates error in state machine (unexpected cmd) */
-#define RFAL_ERR_SYNTAX ((ReturnCode)20U) /*!< indicates error in state machine (unknown cmd) */
-#define RFAL_ERR_CRC ((ReturnCode)21U) /*!< crc error */
-#define RFAL_ERR_NOTFOUND ((ReturnCode)22U) /*!< transponder not found */
-#define RFAL_ERR_NOTUNIQUE ((ReturnCode)23U) /*!< transponder not unique - more than one transponder in field */
-#define RFAL_ERR_NOTSUPP ((ReturnCode)24U) /*!< requested operation not supported */
-#define RFAL_ERR_WRITE ((ReturnCode)25U) /*!< write error */
-#define RFAL_ERR_FIFO ((ReturnCode)26U) /*!< fifo over or underflow error */
-#define RFAL_ERR_PAR ((ReturnCode)27U) /*!< parity error */
-#define RFAL_ERR_DONE ((ReturnCode)28U) /*!< transfer has already finished */
-#define RFAL_ERR_RF_COLLISION ((ReturnCode)29U) /*!< collision error (Bit Collision or during RF Collision avoidance ) */
-#define RFAL_ERR_HW_OVERRUN ((ReturnCode)30U) /*!< lost one or more received bytes */
-#define RFAL_ERR_RELEASE_REQ ((ReturnCode)31U) /*!< device requested release */
-#define RFAL_ERR_SLEEP_REQ ((ReturnCode)32U) /*!< device requested sleep */
-#define RFAL_ERR_WRONG_STATE ((ReturnCode)33U) /*!< incorrent state for requested operation */
-#define RFAL_ERR_MAX_RERUNS ((ReturnCode)34U) /*!< blocking procedure reached maximum runs */
-#define RFAL_ERR_DISABLED ((ReturnCode)35U) /*!< operation aborted due to disabled configuration */
-#define RFAL_ERR_HW_MISMATCH ((ReturnCode)36U) /*!< expected hw do not match */
-#define RFAL_ERR_LINK_LOSS ((ReturnCode)37U) /*!< Other device's field didn't behave as expected: turned off by Initiator in Passive mode, or AP2P did not turn on field */
-#define RFAL_ERR_INVALID_HANDLE ((ReturnCode)38U) /*!< invalid or not initialized device handle */
-
-#define RFAL_ERR_INCOMPLETE_BYTE ((ReturnCode)40U) /*!< Incomplete byte rcvd */
-#define RFAL_ERR_INCOMPLETE_BYTE_01 ((ReturnCode)41U) /*!< Incomplete byte rcvd - 1 bit */
-#define RFAL_ERR_INCOMPLETE_BYTE_02 ((ReturnCode)42U) /*!< Incomplete byte rcvd - 2 bit */
-#define RFAL_ERR_INCOMPLETE_BYTE_03 ((ReturnCode)43U) /*!< Incomplete byte rcvd - 3 bit */
-#define RFAL_ERR_INCOMPLETE_BYTE_04 ((ReturnCode)44U) /*!< Incomplete byte rcvd - 4 bit */
-#define RFAL_ERR_INCOMPLETE_BYTE_05 ((ReturnCode)45U) /*!< Incomplete byte rcvd - 5 bit */
-#define RFAL_ERR_INCOMPLETE_BYTE_06 ((ReturnCode)46U) /*!< Incomplete byte rcvd - 6 bit */
-#define RFAL_ERR_INCOMPLETE_BYTE_07 ((ReturnCode)47U) /*!< Incomplete byte rcvd - 7 bit */
-
-/*
-******************************************************************************
-* GLOBAL MACROS
-******************************************************************************
-*/
-/*! Common code to exit a function with the error if function f return error */
-#define RFAL_EXIT_ON_ERR(r, f) \
- (r) = (f); \
- if (RFAL_ERR_NONE != (r)) \
- { \
- return (r); \
- }
-
-
-/*! Common code to exit a function if process/function f has not concluded */
-#define RFAL_EXIT_ON_BUSY(r, f) \
- (r) = (f); \
- if (RFAL_ERR_BUSY == (r)) \
- { \
- return (r); \
- }
-
-#define RFAL_SIZEOF_ARRAY(a) (sizeof(a) / sizeof((a)[0])) /*!< Compute the size of an array */
-#define RFAL_MAX(a, b) (((a) > (b)) ? (a) : (b)) /*!< Return the maximum of the 2 values */
-#define RFAL_MIN(a, b) (((a) < (b)) ? (a) : (b)) /*!< Return the minimum of the 2 values */
-#define RFAL_GETU16(a) (((uint16_t)(a)[0] << 8) | (uint16_t)(a)[1])/*!< Cast two Big Endian 8-bits byte array to 16-bits unsigned */
-#define RFAL_GETU32(a) (((uint32_t)(a)[0] << 24) | ((uint32_t)(a)[1] << 16) | ((uint32_t)(a)[2] << 8) | ((uint32_t)(a)[3])) /*!< Cast four Big Endian 8-bit byte array to 32-bit unsigned */
-
-
-#ifdef __CSMC__
-/* STM8 COSMIC */
-#define RFAL_MEMMOVE(s1,s2,n) memmove(s1,s2,n) /* PRQA S 5003 # CERT C 9 - string.h from Cosmic only provides functions with low qualified parameters */ /*!< map memmove to string library code */
-static inline void * RFAL_MEMCPY(void *s1, const void *s2, uint32_t n) { return memcpy(s1,s2,(uint16_t)n); } /* PRQA S 0431 # MISRA 1.1 - string.h from Cosmic only provides functions with low qualified parameters */
-#define RFAL_MEMSET(s1,c,n) memset(s1,(char)(c),n) /*!< map memset to string library code */
-static inline int32_t RFAL_BYTECMP(void *s1, const void *s2, uint32_t n) { return (int32_t)memcmp(s1,s2,(uint16_t)n); } /* PRQA S 0431 # MISRA 1.1 - string.h from Cosmic only provides functions with low qualified parameters */
-
-#else /* __CSMC__ */
-
-#define RFAL_MEMMOVE memmove /*!< map memmove to string library code */
-#define RFAL_MEMCPY memcpy /*!< map memcpy to string library code */
-#define RFAL_MEMSET memset /*!< map memset to string library code */
-#define RFAL_BYTECMP memcmp /*!< map bytecmp to string library code */
-#endif /* __CSMC__ */
-
-#define RFAL_NO_WARNING(v) ((void) (v)) /*!< Macro to suppress compiler warning */
-
-
-#ifndef NULL
- #define NULL (void*)0 /*!< represents a NULL pointer */
-#endif /* !NULL */
-
-
-
-#endif /* RFAL_UTILS_H */
-
-
-/**
- * @}
- *
- */
-
+
+/******************************************************************************
+ * @attention
+ *
+ * COPYRIGHT 2016 STMicroelectronics, all rights reserved
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
+ * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+******************************************************************************/
+
+
+
+/*
+ * PROJECT: ST25R
+ * Revision:
+ * LANGUAGE: ISO C99
+ */
+
+/*! \file rfal_utils.h
+ *
+ * \author Gustavo Patricio
+ *
+ * \brief RF Abstraction Layer (RFAL) Utils
+ *
+ * \addtogroup RFAL
+ * @{
+ *
+ */
+
+#ifndef RFAL_UTILS_H
+#define RFAL_UTILS_H
+
+/*
+******************************************************************************
+* INCLUDES
+******************************************************************************
+*/
+#include <stdint.h>
+#include <stdbool.h>
+#include <string.h>
+
+/*
+ ******************************************************************************
+ * C LINKAGE GUARD
+ ******************************************************************************
+ */
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/*
+******************************************************************************
+* GLOBAL DATA TYPES
+******************************************************************************
+*/
+
+typedef uint16_t ReturnCode; /*!< Standard Return Code type from function. */
+
+/*
+******************************************************************************
+* DEFINES
+******************************************************************************
+*/
+
+/*
+ * Error codes to be used within the application.
+ * They are represented by an uint8_t
+ */
+
+#define RFAL_ERR_NONE ((ReturnCode)0U) /*!< no error occurred */
+#define RFAL_ERR_NOMEM ((ReturnCode)1U) /*!< not enough memory to perform the requested operation */
+#define RFAL_ERR_BUSY ((ReturnCode)2U) /*!< device or resource busy */
+#define RFAL_ERR_IO ((ReturnCode)3U) /*!< generic IO error */
+#define RFAL_ERR_TIMEOUT ((ReturnCode)4U) /*!< error due to timeout */
+#define RFAL_ERR_REQUEST ((ReturnCode)5U) /*!< invalid request or requested function can't be executed at the moment */
+#define RFAL_ERR_NOMSG ((ReturnCode)6U) /*!< No message of desired type */
+#define RFAL_ERR_PARAM ((ReturnCode)7U) /*!< Parameter error */
+#define RFAL_ERR_SYSTEM ((ReturnCode)8U) /*!< System error */
+#define RFAL_ERR_FRAMING ((ReturnCode)9U) /*!< Framing error */
+#define RFAL_ERR_OVERRUN ((ReturnCode)10U) /*!< lost one or more received bytes */
+#define RFAL_ERR_PROTO ((ReturnCode)11U) /*!< protocol error */
+#define RFAL_ERR_INTERNAL ((ReturnCode)12U) /*!< Internal Error */
+#define RFAL_ERR_AGAIN ((ReturnCode)13U) /*!< Call again */
+#define RFAL_ERR_MEM_CORRUPT ((ReturnCode)14U) /*!< memory corruption */
+#define RFAL_ERR_NOT_IMPLEMENTED ((ReturnCode)15U) /*!< not implemented */
+#define RFAL_ERR_PC_CORRUPT ((ReturnCode)16U) /*!< Program Counter has been manipulated or spike/noise trigger illegal operation */
+#define RFAL_ERR_SEND ((ReturnCode)17U) /*!< error sending*/
+#define RFAL_ERR_IGNORE ((ReturnCode)18U) /*!< indicates error detected but to be ignored */
+#define RFAL_ERR_SEMANTIC ((ReturnCode)19U) /*!< indicates error in state machine (unexpected cmd) */
+#define RFAL_ERR_SYNTAX ((ReturnCode)20U) /*!< indicates error in state machine (unknown cmd) */
+#define RFAL_ERR_CRC ((ReturnCode)21U) /*!< crc error */
+#define RFAL_ERR_NOTFOUND ((ReturnCode)22U) /*!< transponder not found */
+#define RFAL_ERR_NOTUNIQUE ((ReturnCode)23U) /*!< transponder not unique - more than one transponder in field */
+#define RFAL_ERR_NOTSUPP ((ReturnCode)24U) /*!< requested operation not supported */
+#define RFAL_ERR_WRITE ((ReturnCode)25U) /*!< write error */
+#define RFAL_ERR_FIFO ((ReturnCode)26U) /*!< fifo over or underflow error */
+#define RFAL_ERR_PAR ((ReturnCode)27U) /*!< parity error */
+#define RFAL_ERR_DONE ((ReturnCode)28U) /*!< transfer has already finished */
+#define RFAL_ERR_RF_COLLISION ((ReturnCode)29U) /*!< collision error (Bit Collision or during RF Collision avoidance ) */
+#define RFAL_ERR_HW_OVERRUN ((ReturnCode)30U) /*!< lost one or more received bytes */
+#define RFAL_ERR_RELEASE_REQ ((ReturnCode)31U) /*!< device requested release */
+#define RFAL_ERR_SLEEP_REQ ((ReturnCode)32U) /*!< device requested sleep */
+#define RFAL_ERR_WRONG_STATE ((ReturnCode)33U) /*!< incorrect state for requested operation */
+#define RFAL_ERR_MAX_RERUNS ((ReturnCode)34U) /*!< blocking procedure reached maximum runs */
+#define RFAL_ERR_DISABLED ((ReturnCode)35U) /*!< operation aborted due to disabled configuration */
+#define RFAL_ERR_HW_MISMATCH ((ReturnCode)36U) /*!< expected hw do not match */
+#define RFAL_ERR_LINK_LOSS ((ReturnCode)37U) /*!< Other device's field didn't behave as expected: turned off by Initiator in Passive mode, or AP2P did not turn on field */
+#define RFAL_ERR_INVALID_HANDLE ((ReturnCode)38U) /*!< invalid or not initialized device handle */
+
+#define RFAL_ERR_INCOMPLETE_BYTE ((ReturnCode)40U) /*!< Incomplete byte rcvd */
+#define RFAL_ERR_INCOMPLETE_BYTE_01 ((ReturnCode)41U) /*!< Incomplete byte rcvd - 1 bit */
+#define RFAL_ERR_INCOMPLETE_BYTE_02 ((ReturnCode)42U) /*!< Incomplete byte rcvd - 2 bit */
+#define RFAL_ERR_INCOMPLETE_BYTE_03 ((ReturnCode)43U) /*!< Incomplete byte rcvd - 3 bit */
+#define RFAL_ERR_INCOMPLETE_BYTE_04 ((ReturnCode)44U) /*!< Incomplete byte rcvd - 4 bit */
+#define RFAL_ERR_INCOMPLETE_BYTE_05 ((ReturnCode)45U) /*!< Incomplete byte rcvd - 5 bit */
+#define RFAL_ERR_INCOMPLETE_BYTE_06 ((ReturnCode)46U) /*!< Incomplete byte rcvd - 6 bit */
+#define RFAL_ERR_INCOMPLETE_BYTE_07 ((ReturnCode)47U) /*!< Incomplete byte rcvd - 7 bit */
+
+/*
+******************************************************************************
+* GLOBAL MACROS
+******************************************************************************
+*/
+/*! Common code to exit a function with the error if function f return error */
+#define RFAL_EXIT_ON_ERR(r, f) \
+ (r) = (f); \
+ if (RFAL_ERR_NONE != (r)) \
+ { \
+ return (r); \
+ }
+
+
+/*! Common code to exit a function if process/function f has not concluded */
+#define RFAL_EXIT_ON_BUSY(r, f) \
+ (r) = (f); \
+ if (RFAL_ERR_BUSY == (r)) \
+ { \
+ return (r); \
+ }
+
+#define RFAL_SIZEOF_ARRAY(a) (sizeof(a) / sizeof((a)[0])) /*!< Compute the size of an array */
+#define RFAL_MAX(a, b) (((a) > (b)) ? (a) : (b)) /*!< Return the maximum of the 2 values */
+#define RFAL_MIN(a, b) (((a) < (b)) ? (a) : (b)) /*!< Return the minimum of the 2 values */
+#define RFAL_DELTA(a, b) (((a) > (b)) ? ((a)-(b)) : ((b)-(a))) /*!< Return the delta between 2 values */
+#define RFAL_GETU16(a) (((uint16_t)(a)[0] << 8) | (uint16_t)(a)[1])/*!< Cast two Big Endian 8-bits byte array to 16-bits unsigned */
+#define RFAL_GETU32(a) (((uint32_t)(a)[0] << 24) | ((uint32_t)(a)[1] << 16) | ((uint32_t)(a)[2] << 8) | ((uint32_t)(a)[3])) /*!< Cast four Big Endian 8-bit byte array to 32-bit unsigned */
+
+
+#ifdef __CSMC__
+/* STM8 COSMIC */
+#define RFAL_MEMMOVE(s1,s2,n) memmove(s1,s2,n) /* PRQA S 5003 # CERT C 9 - string.h from Cosmic only provides functions with low qualified parameters */ /*!< map memmove to string library code */
+static inline void * RFAL_MEMCPY(void *s1, const void *s2, uint32_t n) { return memcpy(s1,s2,(uint16_t)n); } /* PRQA S 0431 # MISRA 1.1 - string.h from Cosmic only provides functions with low qualified parameters */
+#define RFAL_MEMSET(s1,c,n) memset(s1,(char)(c),n) /*!< map memset to string library code */
+static inline int32_t RFAL_BYTECMP(void *s1, const void *s2, uint32_t n) { return (int32_t)memcmp(s1,s2,(uint16_t)n); } /* PRQA S 0431 # MISRA 1.1 - string.h from Cosmic only provides functions with low qualified parameters */
+
+#else /* __CSMC__ */
+
+#define RFAL_MEMMOVE memmove /*!< map memmove to string library code */
+#define RFAL_MEMCPY memcpy /*!< map memcpy to string library code */
+#define RFAL_MEMSET memset /*!< map memset to string library code */
+#define RFAL_BYTECMP memcmp /*!< map bytecmp to string library code */
+#endif /* __CSMC__ */
+
+#define RFAL_NO_WARNING(v) ((void) (v)) /*!< Macro to suppress compiler warning */
+
+
+
+/*
+******************************************************************************
+* RFAL GUARDS / CHECKS / INCOMPATIBILITIES
+******************************************************************************
+*/
+
+
+#ifndef NULL
+ #define NULL (void*)0 /*!< represents a NULL pointer */
+#endif /* !NULL */
+
+/*******************************************************************************/
+/* RFAL requires definition of its types - RFAL User Manual (UM2890).
+ C standard library is typically used (stdint.h stdbool.h), but user defined
+ types are also possible.
+ bool values must be preprocessor integer constants (e.g. stdbool) and not
+ enum/tydefs which are not intepreted by C preprocessor.
+*/
+#ifndef __cplusplus
+ #ifndef bool
+ #error "RFAL: Invalid Configuration. bool definition apparently missing. "
+ #endif
+ #if (false != 0)
+ #error "RFAL: Invalid Configuration. Unexpected defintion of the boolean false "
+ #endif
+#endif /* __cplusplus */
+
+
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* RFAL_UTILS_H */
+
+
+/**
+ * @}
+ *
+ */
+
### core/embed/io/nfc/st25/rfal002/source/rfal_analogConfig.c
@@ -1,487 +1,487 @@
-
-/******************************************************************************
- * @attention
- *
- * COPYRIGHT 2016 STMicroelectronics, all rights reserved
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
- * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
-******************************************************************************/
-
-
-/*
- * PROJECT: ST25R firmware
- * Revision:
- * LANGUAGE: ISO C99
- */
-
-/*! \file rfal_analogConfig.c
- *
- * \author bkam
- *
- * \brief Funcitons to manage and set analog settings.
- *
- */
-
-/*
- ******************************************************************************
- * INCLUDES
- ******************************************************************************
- */
-#include "rfal_analogConfig.h"
-#include "rfal_chip.h"
-#include "rfal_utils.h"
-#include "rfal_platform.h"
-
-
-#define RFAL_TEST_REG 0x0080U /*!< Test Register indicator */
-
-/* Check whether the Default Analog settings are to be used or custom ones */
-#ifdef RFAL_ANALOG_CONFIG_CUSTOM
- extern const uint8_t rfalAnalogConfigCustomSettings[];
- extern const uint16_t rfalAnalogConfigCustomSettingsLength;
-#else
- #include "rfal_analogConfigTbl.h"
-#endif
-
-/*
- ******************************************************************************
- * DEFINES
- ******************************************************************************
- */
-
-
-
-/*
- ******************************************************************************
- * MACROS
- ******************************************************************************
- */
-
-/*
- ******************************************************************************
- * LOCAL DATA TYPES
- ******************************************************************************
- */
-
-#if RFAL_FEATURE_DYNAMIC_ANALOG_CONFIG
- static uint8_t gRfalAnalogConfig[RFAL_ANALOG_CONFIG_TBL_SIZE]; /*!< Analog Configuration Settings List */
-#endif /* RFAL_FEATURE_DYNAMIC_ANALOG_CONFIG */
-
-
-/*! Struct for Analog Config Look Up Table Update */
-typedef struct {
- const uint8_t *currentAnalogConfigTbl; /*!< Reference to start of current Analog Configuration */
- uint16_t configTblSize; /*!< Total size of Analog Configuration */
- bool ready; /*!< Indicate if Look Up Table is complete and ready for use */
-} rfalAnalogConfigMgmt;
-
-static rfalAnalogConfigMgmt gRfalAnalogConfigMgmt; /*!< Analog Configuration LUT management */
-
-/*
- ******************************************************************************
- * LOCAL TABLES
- ******************************************************************************
- */
-
-/*
- ******************************************************************************
- * LOCAL FUNCTION PROTOTYPES
- ******************************************************************************
- */
-static rfalAnalogConfigNum rfalAnalogConfigSearch( rfalAnalogConfigId configId, uint16_t *configOffset );
-
-#if RFAL_FEATURE_DYNAMIC_ANALOG_CONFIG
- static void rfalAnalogConfigPtrUpdate( const uint8_t* analogConfigTbl );
-#endif /* RFAL_FEATURE_DYNAMIC_ANALOG_CONFIG */
-
-/*
- ******************************************************************************
- * GLOBAL VARIABLE DEFINITIONS
- ******************************************************************************
- */
-
-/*
- ******************************************************************************
- * GLOBAL FUNCTIONS
- ******************************************************************************
- */
-
-
-/*******************************************************************************/
-void rfalAnalogConfigInitialize( void )
-{
- /* Use default Analog configuration settings in Flash by default. */
-
-/* Check whether the Default Analog settings are to be used or custom ones */
-#ifdef RFAL_ANALOG_CONFIG_CUSTOM
- gRfalAnalogConfigMgmt.currentAnalogConfigTbl = rfalAnalogConfigCustomSettings;
- gRfalAnalogConfigMgmt.configTblSize = rfalAnalogConfigCustomSettingsLength;
-#else
- gRfalAnalogConfigMgmt.currentAnalogConfigTbl = rfalAnalogConfigDefaultSettings;
- gRfalAnalogConfigMgmt.configTblSize = sizeof(rfalAnalogConfigDefaultSettings);
-#endif
-
- gRfalAnalogConfigMgmt.ready = true;
-}
-
-
-/*******************************************************************************/
-bool rfalAnalogConfigIsReady( void )
-{
- return gRfalAnalogConfigMgmt.ready;
-}
-
-
-/*******************************************************************************/
-ReturnCode rfalAnalogConfigListWriteRaw( const uint8_t *configTbl, uint16_t configTblSize )
-{
-#if RFAL_FEATURE_DYNAMIC_ANALOG_CONFIG
-
- /* Check if the Configuration Table exceed the Table size */
- if ( configTblSize >= RFAL_ANALOG_CONFIG_TBL_SIZE )
- {
- return RFAL_ERR_NOMEM;
- }
-
- /* Check for invalid parameters */
- if( (configTbl == NULL) || (configTblSize == 0U) )
- {
- return RFAL_ERR_PARAM;
- }
-
- /* NOTE: On this API (rfalAnalogConfigListWriteRaw) the current AC Table is not reset upon error, as on rfalAnalogConfigListWrite. */
- /* On rfalAnalogConfigListWrite the AC table is written in mutiple chunks of data which may lead to an invalid|incomplte AC */
- /* table if an error arises, where here the whole AC Table is written all together. */
-
- /* NOTE: Function does not check for the validity of the Table contents (conf IDs, conf sets, register address) */
- RFAL_MEMCPY( gRfalAnalogConfig, configTbl, configTblSize );
-
- /* Update the total size of configuration settings */
- gRfalAnalogConfigMgmt.configTblSize = configTblSize;
-
- rfalAnalogConfigPtrUpdate(gRfalAnalogConfig);
- return RFAL_ERR_NONE;
-
-#else
-
- /* If Analog Configuration Update is to be disabled */
- RFAL_NO_WARNING(configTbl);
- RFAL_NO_WARNING(configTblSize);
- return RFAL_ERR_REQUEST;
-
-#endif /* RFAL_FEATURE_DYNAMIC_ANALOG_CONFIG */
-}
-
-
-/*******************************************************************************/
-ReturnCode rfalAnalogConfigListWrite( uint8_t more, const rfalAnalogConfig *config )
-{
-#if RFAL_FEATURE_DYNAMIC_ANALOG_CONFIG
-
- rfalAnalogConfigId configId;
- rfalAnalogConfigNum numConfig;
- uint8_t configSize;
-
- if( true == gRfalAnalogConfigMgmt.ready )
- { /* First Update to the Configuration list */
- gRfalAnalogConfigMgmt.ready = false; /* Invalidate the config List */
- gRfalAnalogConfigMgmt.configTblSize = 0; /* Clear the config List */
- }
-
- configId = RFAL_GETU16(config->id);
-
- /* Check validity of the Configuration ID. */
- /* NOTE: Direction DPO uses 2msb of the Technology field as level indicator */
- if( ((RFAL_ANALOG_CONFIG_TECH_RFU <= RFAL_ANALOG_CONFIG_ID_GET_TECH(configId)) && ((RFAL_ANALOG_CONFIG_ID_GET_DIRECTION(configId) != RFAL_ANALOG_CONFIG_DPO) && (RFAL_ANALOG_CONFIG_ID_GET_DIRECTION(configId) != RFAL_ANALOG_CONFIG_DLMA)) )
- ||((RFAL_ANALOG_CONFIG_BITRATE_6780 < RFAL_ANALOG_CONFIG_ID_GET_BITRATE(configId)) && (RFAL_ANALOG_CONFIG_BITRATE_211p88 > RFAL_ANALOG_CONFIG_ID_GET_BITRATE(configId)))
- ||(RFAL_ANALOG_CONFIG_BITRATE_1p6 < RFAL_ANALOG_CONFIG_ID_GET_BITRATE(configId))
- )
- {
- rfalAnalogConfigInitialize(); /* Revert to default Analog Configuration */
- return RFAL_ERR_PARAM;
- }
-
- numConfig = config->num;
- configSize = (uint8_t)(sizeof(rfalAnalogConfigId) + sizeof(rfalAnalogConfigNum) + (numConfig * sizeof(rfalAnalogConfigRegAddrMaskVal)));
-
- /* Check if the Configuration Set exceed the Table size. */
- if( RFAL_ANALOG_CONFIG_TBL_SIZE <= (gRfalAnalogConfigMgmt.configTblSize + configSize) )
- {
- rfalAnalogConfigInitialize(); /* Revert to default Analog Configuration */
- return RFAL_ERR_NOMEM;
- }
-
- /* NOTE: Function does not check for the validity of the Register Address. */
- RFAL_MEMCPY(&gRfalAnalogConfig[gRfalAnalogConfigMgmt.configTblSize], (const uint8_t*)config, configSize);
-
- /* Increment the total size of configuration settings. */
- gRfalAnalogConfigMgmt.configTblSize += configSize;
-
- /* Check if it is the last Analog Configuration to load. */
- if( RFAL_ANALOG_CONFIG_UPDATE_LAST == more )
- { /* Update the Analog Configuration to the new settings. */
- rfalAnalogConfigPtrUpdate(gRfalAnalogConfig);
- }
-
- return RFAL_ERR_NONE;
-
-#else
-
- /* If Analog Configuration Update is to be disabled */
- RFAL_NO_WARNING(config);
- RFAL_NO_WARNING(more);
- return RFAL_ERR_DISABLED;
-
-#endif /* RFAL_FEATURE_DYNAMIC_ANALOG_CONFIG */
-
-}
-
-
-/*******************************************************************************/
-ReturnCode rfalAnalogConfigListReadRaw( uint8_t *tblBuf, uint16_t tblBufLen, uint16_t *configTblSize )
-{
- /* Check if the the current table will fit into the given buffer */
- if( tblBufLen < gRfalAnalogConfigMgmt.configTblSize )
- {
- return RFAL_ERR_NOMEM;
- }
-
- /* Check for invalid parameters */
- if( (configTblSize == NULL) || (tblBuf == NULL) )
- {
- return RFAL_ERR_PARAM;
- }
-
- /* Copy the whole Table to the given buffer */
- if( gRfalAnalogConfigMgmt.configTblSize > 0U ) /* MISRA 21.18 */
- {
- RFAL_MEMCPY( tblBuf, gRfalAnalogConfigMgmt.currentAnalogConfigTbl, gRfalAnalogConfigMgmt.configTblSize );
- }
- *configTblSize = gRfalAnalogConfigMgmt.configTblSize;
-
- return RFAL_ERR_NONE;
-}
-
-
-/*******************************************************************************/
-ReturnCode rfalAnalogConfigListRead( rfalAnalogConfigOffset *configOffset, uint8_t *more, rfalAnalogConfig *config, rfalAnalogConfigNum numConfig )
-{
- uint16_t configSize;
- const rfalAnalogConfigOffset offset = *configOffset;
- rfalAnalogConfigNum numConfigSet;
-
- /* Check if the number of register-mask-value settings for the respective Configuration ID will fit into the buffer passed in. */
- if( gRfalAnalogConfigMgmt.currentAnalogConfigTbl[offset + sizeof(rfalAnalogConfigId)] > numConfig )
- {
- return RFAL_ERR_NOMEM;
- }
-
- /* Get the number of Configuration set */
- numConfigSet = gRfalAnalogConfigMgmt.currentAnalogConfigTbl[offset + sizeof(rfalAnalogConfigId)];
-
- /* Pass Configuration Register-Mask-Value sets */
- configSize = (sizeof(rfalAnalogConfigId) + sizeof(rfalAnalogConfigNum) + (uint16_t)(numConfigSet * sizeof(rfalAnalogConfigRegAddrMaskVal)));
- RFAL_MEMCPY( (uint8_t*) config
- , &gRfalAnalogConfigMgmt.currentAnalogConfigTbl[offset]
- , configSize
- );
- *configOffset = offset + configSize;
-
- /* Check if it is the last Analog Configuration in the Table.*/
- *more = (uint8_t)((*configOffset >= gRfalAnalogConfigMgmt.configTblSize) ? RFAL_ANALOG_CONFIG_UPDATE_LAST
- : RFAL_ANALOG_CONFIG_UPDATE_MORE);
-
- return RFAL_ERR_NONE;
-
-}
-
-
-/*******************************************************************************/
-ReturnCode rfalSetAnalogConfig( rfalAnalogConfigId configId )
-{
- rfalAnalogConfigOffset configOffset = 0;
- rfalAnalogConfigNum numConfigSet;
- const rfalAnalogConfigRegAddrMaskVal *configTbl;
- ReturnCode retCode = RFAL_ERR_NONE;
- rfalAnalogConfigNum i;
-
- if( true != gRfalAnalogConfigMgmt.ready )
- {
- return RFAL_ERR_REQUEST;
- }
-
- /* Search LUT for the specific Configuration ID */
- while( true )
- {
- numConfigSet = rfalAnalogConfigSearch(configId, &configOffset);
- if( RFAL_ANALOG_CONFIG_LUT_NOT_FOUND == numConfigSet )
- {
- break;
- }
-
- configTbl = (rfalAnalogConfigRegAddrMaskVal *)( (uintptr_t)gRfalAnalogConfigMgmt.currentAnalogConfigTbl + (uint32_t)configOffset);
- /* Increment the offset to the next index to search from */
- configOffset += (uint16_t)(numConfigSet * sizeof(rfalAnalogConfigRegAddrMaskVal));
-
- if ((gRfalAnalogConfigMgmt.configTblSize + 1U) < configOffset)
- { /* Error check make sure that the we do not access outside the configuration Table Size */
- return RFAL_ERR_NOMEM;
- }
-
- for ( i = 0; i < numConfigSet; i++)
- {
- if( (RFAL_GETU16(configTbl[i].addr) & RFAL_TEST_REG) != 0U )
- {
- RFAL_EXIT_ON_ERR(retCode, rfalChipChangeTestRegBits( (RFAL_GETU16(configTbl[i].addr) & ~RFAL_TEST_REG), configTbl[i].mask, configTbl[i].val) );
- }
- else
- {
- RFAL_EXIT_ON_ERR(retCode, rfalChipChangeRegBits( RFAL_GETU16(configTbl[i].addr), configTbl[i].mask, configTbl[i].val) );
- }
- }
-
- } /* while(found Analog Config Id) */
-
- return retCode;
-}
-
-
-/*******************************************************************************/
-uint16_t rfalAnalogConfigGenModeID( rfalMode md, rfalBitRate br, uint16_t dir )
-{
- uint16_t id;
-
- /* Assign Poll/Listen Mode */
- id = ((md >= RFAL_MODE_LISTEN_NFCA) ? RFAL_ANALOG_CONFIG_LISTEN : RFAL_ANALOG_CONFIG_POLL);
-
- /* Assign Technology */
- switch( md )
- {
- case RFAL_MODE_POLL_NFCA:
- case RFAL_MODE_POLL_NFCA_T1T:
- case RFAL_MODE_LISTEN_NFCA:
- id |= RFAL_ANALOG_CONFIG_TECH_NFCA;
- break;
-
- case RFAL_MODE_POLL_NFCB:
- case RFAL_MODE_POLL_B_PRIME:
- case RFAL_MODE_POLL_B_CTS:
- case RFAL_MODE_LISTEN_NFCB:
- id |= RFAL_ANALOG_CONFIG_TECH_NFCB;
- break;
-
- case RFAL_MODE_POLL_NFCF:
- case RFAL_MODE_LISTEN_NFCF:
- id |= RFAL_ANALOG_CONFIG_TECH_NFCF;
- break;
-
- case RFAL_MODE_POLL_NFCV:
- case RFAL_MODE_POLL_PICOPASS:
- id |= RFAL_ANALOG_CONFIG_TECH_NFCV;
- break;
-
- case RFAL_MODE_POLL_ACTIVE_P2P:
- case RFAL_MODE_LISTEN_ACTIVE_P2P:
- id |= RFAL_ANALOG_CONFIG_TECH_AP2P;
- break;
-
- default:
- id = RFAL_ANALOG_CONFIG_TECH_CHIP;
- break;
- }
-
- /* Assign Bitrate */
- id |= (((((uint16_t)(br) >= (uint16_t)RFAL_BR_52p97) ? (uint16_t)(br) : ((uint16_t)(br)+1U)) << RFAL_ANALOG_CONFIG_BITRATE_SHIFT) & RFAL_ANALOG_CONFIG_BITRATE_MASK);
-
- /* Assign Direction */
- id |= ((dir<<RFAL_ANALOG_CONFIG_DIRECTION_SHIFT) & RFAL_ANALOG_CONFIG_DIRECTION_MASK);
-
- return id;
-}
-
-/*
- ******************************************************************************
- * LOCAL FUNCTIONS
- ******************************************************************************
- */
-
-/*!
- *****************************************************************************
- * \brief Update the link to Analog Configuration LUT
- *
- * Update the link to the Analog Configuration LUT for the subsequent search
- * of Analog Settings.
- *
- * \param[in] analogConfigTbl: reference to the start of the new Analog Configuration Table
- *
- *****************************************************************************
- */
-#if RFAL_FEATURE_DYNAMIC_ANALOG_CONFIG
-static void rfalAnalogConfigPtrUpdate( const uint8_t* analogConfigTbl )
-{
- gRfalAnalogConfigMgmt.currentAnalogConfigTbl = analogConfigTbl;
- gRfalAnalogConfigMgmt.ready = true;
-}
-#endif /* RFAL_FEATURE_DYNAMIC_ANALOG_CONFIG */
-
-
-/*!
- *****************************************************************************
- * \brief Search the Analog Configuration LUT for a specific Configuration ID.
- *
- * Search the Analog Configuration LUT for the Configuration ID.
- *
- * \param[in] configId: Configuration ID to search for.
- * \param[in] configOffset: Configuration Offset in Table
- *
- * \return number of Configuration Sets
- * \return #RFAL_ANALOG_CONFIG_LUT_NOT_FOUND in case Configuration ID is not found.
- *****************************************************************************
- */
-static rfalAnalogConfigNum rfalAnalogConfigSearch( rfalAnalogConfigId configId, uint16_t *configOffset )
-{
- rfalAnalogConfigId foundConfigId;
- rfalAnalogConfigId configIdMaskVal;
- const uint8_t *configTbl;
- const uint8_t *currentConfigTbl;
- uint16_t i;
-
- currentConfigTbl = gRfalAnalogConfigMgmt.currentAnalogConfigTbl;
- configIdMaskVal = ((RFAL_ANALOG_CONFIG_POLL_LISTEN_MODE_MASK | RFAL_ANALOG_CONFIG_BITRATE_MASK)
- |((RFAL_ANALOG_CONFIG_TECH_CHIP == RFAL_ANALOG_CONFIG_ID_GET_TECH(configId)) ? (RFAL_ANALOG_CONFIG_TECH_MASK | RFAL_ANALOG_CONFIG_CHIP_SPECIFIC_MASK) : configId)
- |((RFAL_ANALOG_CONFIG_NO_DIRECTION == RFAL_ANALOG_CONFIG_ID_GET_DIRECTION(configId)) ? RFAL_ANALOG_CONFIG_DIRECTION_MASK : configId)
- );
-
-
- /* When specific ConfigIDs are to be used, override search mask */
- if( (RFAL_ANALOG_CONFIG_ID_GET_DIRECTION(configId) == RFAL_ANALOG_CONFIG_DPO) || (RFAL_ANALOG_CONFIG_ID_GET_DIRECTION(configId) == RFAL_ANALOG_CONFIG_DLMA) )
- {
- configIdMaskVal = (RFAL_ANALOG_CONFIG_POLL_LISTEN_MODE_MASK | RFAL_ANALOG_CONFIG_TECH_MASK | RFAL_ANALOG_CONFIG_BITRATE_MASK | RFAL_ANALOG_CONFIG_DIRECTION_MASK);
- }
-
- i = (*configOffset);
- while( i < gRfalAnalogConfigMgmt.configTblSize )
- {
- configTbl = ¤tConfigTbl[i];
- foundConfigId = RFAL_GETU16(configTbl);
- if (configId == (foundConfigId & configIdMaskVal))
- {
- *configOffset = (uint16_t)(i + sizeof(rfalAnalogConfigId) + sizeof(rfalAnalogConfigNum));
- return configTbl[sizeof(rfalAnalogConfigId)];
- }
-
- /* If Config Id does not match, increment to next Configuration Id */
- i += (uint16_t)( sizeof(rfalAnalogConfigId) + sizeof(rfalAnalogConfigNum)
- + (configTbl[sizeof(rfalAnalogConfigId)] * sizeof(rfalAnalogConfigRegAddrMaskVal) )
- );
- } /* for */
-
- return RFAL_ANALOG_CONFIG_LUT_NOT_FOUND;
-}
+
+/******************************************************************************
+ * @attention
+ *
+ * COPYRIGHT 2016 STMicroelectronics, all rights reserved
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
+ * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+******************************************************************************/
+
+
+/*
+ * PROJECT: ST25R firmware
+ * Revision:
+ * LANGUAGE: ISO C99
+ */
+
+/*! \file rfal_analogConfig.c
+ *
+ * \author bkam
+ *
+ * \brief Funcitons to manage and set analog settings.
+ *
+ */
+
+/*
+ ******************************************************************************
+ * INCLUDES
+ ******************************************************************************
+ */
+#include "rfal_analogConfig.h"
+#include "rfal_chip.h"
+#include "rfal_utils.h"
+#include "rfal_platform.h"
+
+
+#define RFAL_TEST_REG 0x0080U /*!< Test Register indicator */
+
+/* Check whether the Default Analog settings are to be used or custom ones */
+#ifdef RFAL_ANALOG_CONFIG_CUSTOM
+ extern const uint8_t rfalAnalogConfigCustomSettings[];
+ extern const uint16_t rfalAnalogConfigCustomSettingsLength;
+#else
+ #include "rfal_analogConfigTbl.h"
+#endif
+
+/*
+ ******************************************************************************
+ * DEFINES
+ ******************************************************************************
+ */
+
+
+
+/*
+ ******************************************************************************
+ * MACROS
+ ******************************************************************************
+ */
+
+/*
+ ******************************************************************************
+ * LOCAL DATA TYPES
+ ******************************************************************************
+ */
+
+#if RFAL_FEATURE_DYNAMIC_ANALOG_CONFIG
+ static uint8_t gRfalAnalogConfig[RFAL_ANALOG_CONFIG_TBL_SIZE]; /*!< Analog Configuration Settings List */
+#endif /* RFAL_FEATURE_DYNAMIC_ANALOG_CONFIG */
+
+
+/*! Struct for Analog Config Look Up Table Update */
+typedef struct {
+ const uint8_t *currentAnalogConfigTbl; /*!< Reference to start of current Analog Configuration */
+ uint16_t configTblSize; /*!< Total size of Analog Configuration */
+ bool ready; /*!< Indicate if Look Up Table is complete and ready for use */
+} rfalAnalogConfigMgmt;
+
+static rfalAnalogConfigMgmt gRfalAnalogConfigMgmt; /*!< Analog Configuration LUT management */
+
+/*
+ ******************************************************************************
+ * LOCAL TABLES
+ ******************************************************************************
+ */
+
+/*
+ ******************************************************************************
+ * LOCAL FUNCTION PROTOTYPES
+ ******************************************************************************
+ */
+static rfalAnalogConfigNum rfalAnalogConfigSearch( rfalAnalogConfigId configId, uint16_t *configOffset );
+
+#if RFAL_FEATURE_DYNAMIC_ANALOG_CONFIG
+ static void rfalAnalogConfigPtrUpdate( const uint8_t* analogConfigTbl );
+#endif /* RFAL_FEATURE_DYNAMIC_ANALOG_CONFIG */
+
+/*
+ ******************************************************************************
+ * GLOBAL VARIABLE DEFINITIONS
+ ******************************************************************************
+ */
+
+/*
+ ******************************************************************************
+ * GLOBAL FUNCTIONS
+ ******************************************************************************
+ */
+
+
+/*******************************************************************************/
+void rfalAnalogConfigInitialize( void )
+{
+ /* Use default Analog configuration settings in Flash by default. */
+
+/* Check whether the Default Analog settings are to be used or custom ones */
+#ifdef RFAL_ANALOG_CONFIG_CUSTOM
+ gRfalAnalogConfigMgmt.currentAnalogConfigTbl = rfalAnalogConfigCustomSettings;
+ gRfalAnalogConfigMgmt.configTblSize = rfalAnalogConfigCustomSettingsLength;
+#else
+ gRfalAnalogConfigMgmt.currentAnalogConfigTbl = rfalAnalogConfigDefaultSettings;
+ gRfalAnalogConfigMgmt.configTblSize = sizeof(rfalAnalogConfigDefaultSettings);
+#endif
+
+ gRfalAnalogConfigMgmt.ready = true;
+}
+
+
+/*******************************************************************************/
+bool rfalAnalogConfigIsReady( void )
+{
+ return gRfalAnalogConfigMgmt.ready;
+}
+
+
+/*******************************************************************************/
+ReturnCode rfalAnalogConfigListWriteRaw( const uint8_t *configTbl, uint16_t configTblSize )
+{
+#if RFAL_FEATURE_DYNAMIC_ANALOG_CONFIG
+
+ /* Check if the Configuration Table exceed the Table size */
+ if ( configTblSize >= RFAL_ANALOG_CONFIG_TBL_SIZE )
+ {
+ return RFAL_ERR_NOMEM;
+ }
+
+ /* Check for invalid parameters */
+ if( (configTbl == NULL) || (configTblSize == 0U) )
+ {
+ return RFAL_ERR_PARAM;
+ }
+
+ /* NOTE: On this API (rfalAnalogConfigListWriteRaw) the current AC Table is not reset upon error, as on rfalAnalogConfigListWrite. */
+ /* On rfalAnalogConfigListWrite the AC table is written in mutiple chunks of data which may lead to an invalid|incomplte AC */
+ /* table if an error arises, where here the whole AC Table is written all together. */
+
+ /* NOTE: Function does not check for the validity of the Table contents (conf IDs, conf sets, register address) */
+ RFAL_MEMCPY( gRfalAnalogConfig, configTbl, configTblSize );
+
+ /* Update the total size of configuration settings */
+ gRfalAnalogConfigMgmt.configTblSize = configTblSize;
+
+ rfalAnalogConfigPtrUpdate(gRfalAnalogConfig);
+ return RFAL_ERR_NONE;
+
+#else
+
+ /* If Analog Configuration Update is to be disabled */
+ RFAL_NO_WARNING(configTbl);
+ RFAL_NO_WARNING(configTblSize);
+ return RFAL_ERR_REQUEST;
+
+#endif /* RFAL_FEATURE_DYNAMIC_ANALOG_CONFIG */
+}
+
+
+/*******************************************************************************/
+ReturnCode rfalAnalogConfigListWrite( uint8_t more, const rfalAnalogConfig *config )
+{
+#if RFAL_FEATURE_DYNAMIC_ANALOG_CONFIG
+
+ rfalAnalogConfigId configId;
+ rfalAnalogConfigNum numConfig;
+ uint8_t configSize;
+
+ if( true == gRfalAnalogConfigMgmt.ready )
+ { /* First Update to the Configuration list */
+ gRfalAnalogConfigMgmt.ready = false; /* Invalidate the config List */
+ gRfalAnalogConfigMgmt.configTblSize = 0; /* Clear the config List */
+ }
+
+ configId = RFAL_GETU16(config->id);
+
+ /* Check validity of the Configuration ID. */
+ /* NOTE: Direction DPO uses 2msb of the Technology field as level indicator */
+ if( ((RFAL_ANALOG_CONFIG_TECH_RFU <= RFAL_ANALOG_CONFIG_ID_GET_TECH(configId)) && ((RFAL_ANALOG_CONFIG_ID_GET_DIRECTION(configId) != RFAL_ANALOG_CONFIG_DPO) && (RFAL_ANALOG_CONFIG_ID_GET_DIRECTION(configId) != RFAL_ANALOG_CONFIG_DLMA)) )
+ ||((RFAL_ANALOG_CONFIG_BITRATE_6780 < RFAL_ANALOG_CONFIG_ID_GET_BITRATE(configId)) && (RFAL_ANALOG_CONFIG_BITRATE_211p88 > RFAL_ANALOG_CONFIG_ID_GET_BITRATE(configId)))
+ ||(RFAL_ANALOG_CONFIG_BITRATE_1p6 < RFAL_ANALOG_CONFIG_ID_GET_BITRATE(configId))
+ )
+ {
+ rfalAnalogConfigInitialize(); /* Revert to default Analog Configuration */
+ return RFAL_ERR_PARAM;
+ }
+
+ numConfig = config->num;
+ configSize = (uint8_t)(sizeof(rfalAnalogConfigId) + sizeof(rfalAnalogConfigNum) + (numConfig * sizeof(rfalAnalogConfigRegAddrMaskVal)));
+
+ /* Check if the Configuration Set exceed the Table size. */
+ if( RFAL_ANALOG_CONFIG_TBL_SIZE <= (gRfalAnalogConfigMgmt.configTblSize + configSize) )
+ {
+ rfalAnalogConfigInitialize(); /* Revert to default Analog Configuration */
+ return RFAL_ERR_NOMEM;
+ }
+
+ /* NOTE: Function does not check for the validity of the Register Address. */
+ RFAL_MEMCPY(&gRfalAnalogConfig[gRfalAnalogConfigMgmt.configTblSize], (const uint8_t*)config, configSize);
+
+ /* Increment the total size of configuration settings. */
+ gRfalAnalogConfigMgmt.configTblSize += configSize;
+
+ /* Check if it is the last Analog Configuration to load. */
+ if( RFAL_ANALOG_CONFIG_UPDATE_LAST == more )
+ { /* Update the Analog Configuration to the new settings. */
+ rfalAnalogConfigPtrUpdate(gRfalAnalogConfig);
+ }
+
+ return RFAL_ERR_NONE;
+
+#else
+
+ /* If Analog Configuration Update is to be disabled */
+ RFAL_NO_WARNING(config);
+ RFAL_NO_WARNING(more);
+ return RFAL_ERR_DISABLED;
+
+#endif /* RFAL_FEATURE_DYNAMIC_ANALOG_CONFIG */
+
+}
+
+
+/*******************************************************************************/
+ReturnCode rfalAnalogConfigListReadRaw( uint8_t *tblBuf, uint16_t tblBufLen, uint16_t *configTblSize )
+{
+ /* Check if the the current table will fit into the given buffer */
+ if( tblBufLen < gRfalAnalogConfigMgmt.configTblSize )
+ {
+ return RFAL_ERR_NOMEM;
+ }
+
+ /* Check for invalid parameters */
+ if( (configTblSize == NULL) || (tblBuf == NULL) )
+ {
+ return RFAL_ERR_PARAM;
+ }
+
+ /* Copy the whole Table to the given buffer */
+ if( gRfalAnalogConfigMgmt.configTblSize > 0U ) /* MISRA 21.18 */
+ {
+ RFAL_MEMCPY( tblBuf, gRfalAnalogConfigMgmt.currentAnalogConfigTbl, gRfalAnalogConfigMgmt.configTblSize );
+ }
+ *configTblSize = gRfalAnalogConfigMgmt.configTblSize;
+
+ return RFAL_ERR_NONE;
+}
+
+
+/*******************************************************************************/
+ReturnCode rfalAnalogConfigListRead( rfalAnalogConfigOffset *configOffset, uint8_t *more, rfalAnalogConfig *config, rfalAnalogConfigNum numConfig )
+{
+ uint16_t configSize;
+ const rfalAnalogConfigOffset offset = *configOffset;
+ rfalAnalogConfigNum numConfigSet;
+
+ /* Check if the number of register-mask-value settings for the respective Configuration ID will fit into the buffer passed in. */
+ if( gRfalAnalogConfigMgmt.currentAnalogConfigTbl[offset + sizeof(rfalAnalogConfigId)] > numConfig )
+ {
+ return RFAL_ERR_NOMEM;
+ }
+
+ /* Get the number of Configuration set */
+ numConfigSet = gRfalAnalogConfigMgmt.currentAnalogConfigTbl[offset + sizeof(rfalAnalogConfigId)];
+
+ /* Pass Configuration Register-Mask-Value sets */
+ configSize = (sizeof(rfalAnalogConfigId) + sizeof(rfalAnalogConfigNum) + (uint16_t)(numConfigSet * sizeof(rfalAnalogConfigRegAddrMaskVal)));
+ RFAL_MEMCPY( (uint8_t*) config
+ , &gRfalAnalogConfigMgmt.currentAnalogConfigTbl[offset]
+ , configSize
+ );
+ *configOffset = offset + configSize;
+
+ /* Check if it is the last Analog Configuration in the Table.*/
+ *more = (uint8_t)((*configOffset >= gRfalAnalogConfigMgmt.configTblSize) ? RFAL_ANALOG_CONFIG_UPDATE_LAST
+ : RFAL_ANALOG_CONFIG_UPDATE_MORE);
+
+ return RFAL_ERR_NONE;
+
+}
+
+
+/*******************************************************************************/
+ReturnCode rfalSetAnalogConfig( rfalAnalogConfigId configId )
+{
+ rfalAnalogConfigOffset configOffset = 0;
+ rfalAnalogConfigNum numConfigSet;
+ const rfalAnalogConfigRegAddrMaskVal *configTbl;
+ ReturnCode retCode = RFAL_ERR_NONE;
+ rfalAnalogConfigNum i;
+
+ if( true != gRfalAnalogConfigMgmt.ready )
+ {
+ return RFAL_ERR_REQUEST;
+ }
+
+ /* Search LUT for the specific Configuration ID */
+ while( true )
+ {
+ numConfigSet = rfalAnalogConfigSearch(configId, &configOffset);
+ if( RFAL_ANALOG_CONFIG_LUT_NOT_FOUND == numConfigSet )
+ {
+ break;
+ }
+
+ configTbl = (rfalAnalogConfigRegAddrMaskVal *)( (uintptr_t)gRfalAnalogConfigMgmt.currentAnalogConfigTbl + (uint32_t)configOffset);
+ /* Increment the offset to the next index to search from */
+ configOffset += (uint16_t)(numConfigSet * sizeof(rfalAnalogConfigRegAddrMaskVal));
+
+ if ((gRfalAnalogConfigMgmt.configTblSize + 1U) < configOffset)
+ { /* Error check make sure that the we do not access outside the configuration Table Size */
+ return RFAL_ERR_NOMEM;
+ }
+
+ for ( i = 0; i < numConfigSet; i++)
+ {
+ if( (RFAL_GETU16(configTbl[i].addr) & RFAL_TEST_REG) != 0U )
+ {
+ RFAL_EXIT_ON_ERR(retCode, rfalChipChangeTestRegBits( (RFAL_GETU16(configTbl[i].addr) & ~RFAL_TEST_REG), configTbl[i].mask, configTbl[i].val) );
+ }
+ else
+ {
+ RFAL_EXIT_ON_ERR(retCode, rfalChipChangeRegBits( RFAL_GETU16(configTbl[i].addr), configTbl[i].mask, configTbl[i].val) );
+ }
+ }
+
+ } /* while(found Analog Config Id) */
+
+ return retCode;
+}
+
+
+/*******************************************************************************/
+uint16_t rfalAnalogConfigGenModeID( rfalMode md, rfalBitRate br, uint16_t dir )
+{
+ uint16_t id;
+
+ /* Assign Poll/Listen Mode */
+ id = ((md >= RFAL_MODE_LISTEN_NFCA) ? RFAL_ANALOG_CONFIG_LISTEN : RFAL_ANALOG_CONFIG_POLL);
+
+ /* Assign Technology */
+ switch( md )
+ {
+ case RFAL_MODE_POLL_NFCA:
+ case RFAL_MODE_POLL_NFCA_T1T:
+ case RFAL_MODE_LISTEN_NFCA:
+ id |= RFAL_ANALOG_CONFIG_TECH_NFCA;
+ break;
+
+ case RFAL_MODE_POLL_NFCB:
+ case RFAL_MODE_POLL_B_PRIME:
+ case RFAL_MODE_POLL_B_CTS:
+ case RFAL_MODE_LISTEN_NFCB:
+ id |= RFAL_ANALOG_CONFIG_TECH_NFCB;
+ break;
+
+ case RFAL_MODE_POLL_NFCF:
+ case RFAL_MODE_LISTEN_NFCF:
+ id |= RFAL_ANALOG_CONFIG_TECH_NFCF;
+ break;
+
+ case RFAL_MODE_POLL_NFCV:
+ case RFAL_MODE_POLL_PICOPASS:
+ id |= RFAL_ANALOG_CONFIG_TECH_NFCV;
+ break;
+
+ case RFAL_MODE_POLL_ACTIVE_P2P:
+ case RFAL_MODE_LISTEN_ACTIVE_P2P:
+ id |= RFAL_ANALOG_CONFIG_TECH_AP2P;
+ break;
+
+ default:
+ id = RFAL_ANALOG_CONFIG_TECH_CHIP;
+ break;
+ }
+
+ /* Assign Bitrate */
+ id |= (((((uint16_t)(br) >= (uint16_t)RFAL_BR_52p97) ? (uint16_t)(br) : ((uint16_t)(br)+1U)) << RFAL_ANALOG_CONFIG_BITRATE_SHIFT) & RFAL_ANALOG_CONFIG_BITRATE_MASK);
+
+ /* Assign Direction */
+ id |= ((dir<<RFAL_ANALOG_CONFIG_DIRECTION_SHIFT) & RFAL_ANALOG_CONFIG_DIRECTION_MASK);
+
+ return id;
+}
+
+/*
+ ******************************************************************************
+ * LOCAL FUNCTIONS
+ ******************************************************************************
+ */
+
+/*!
+ *****************************************************************************
+ * \brief Update the link to Analog Configuration LUT
+ *
+ * Update the link to the Analog Configuration LUT for the subsequent search
+ * of Analog Settings.
+ *
+ * \param[in] analogConfigTbl: reference to the start of the new Analog Configuration Table
+ *
+ *****************************************************************************
+ */
+#if RFAL_FEATURE_DYNAMIC_ANALOG_CONFIG
+static void rfalAnalogConfigPtrUpdate( const uint8_t* analogConfigTbl )
+{
+ gRfalAnalogConfigMgmt.currentAnalogConfigTbl = analogConfigTbl;
+ gRfalAnalogConfigMgmt.ready = true;
+}
+#endif /* RFAL_FEATURE_DYNAMIC_ANALOG_CONFIG */
+
+
+/*!
+ *****************************************************************************
+ * \brief Search the Analog Configuration LUT for a specific Configuration ID.
+ *
+ * Search the Analog Configuration LUT for the Configuration ID.
+ *
+ * \param[in] configId: Configuration ID to search for.
+ * \param[in] configOffset: Configuration Offset in Table
+ *
+ * \return number of Configuration Sets
+ * \return #RFAL_ANALOG_CONFIG_LUT_NOT_FOUND in case Configuration ID is not found.
+ *****************************************************************************
+ */
+static rfalAnalogConfigNum rfalAnalogConfigSearch( rfalAnalogConfigId configId, uint16_t *configOffset )
+{
+ rfalAnalogConfigId foundConfigId;
+ rfalAnalogConfigId configIdMaskVal;
+ const uint8_t *configTbl;
+ const uint8_t *currentConfigTbl;
+ uint16_t i;
+
+ currentConfigTbl = gRfalAnalogConfigMgmt.currentAnalogConfigTbl;
+ configIdMaskVal = ((RFAL_ANALOG_CONFIG_POLL_LISTEN_MODE_MASK | RFAL_ANALOG_CONFIG_BITRATE_MASK)
+ |((RFAL_ANALOG_CONFIG_TECH_CHIP == RFAL_ANALOG_CONFIG_ID_GET_TECH(configId)) ? (RFAL_ANALOG_CONFIG_TECH_MASK | RFAL_ANALOG_CONFIG_CHIP_SPECIFIC_MASK) : configId)
+ |((RFAL_ANALOG_CONFIG_NO_DIRECTION == RFAL_ANALOG_CONFIG_ID_GET_DIRECTION(configId)) ? RFAL_ANALOG_CONFIG_DIRECTION_MASK : configId)
+ );
+
+
+ /* When specific ConfigIDs are to be used, override search mask */
+ if( (RFAL_ANALOG_CONFIG_ID_GET_DIRECTION(configId) == RFAL_ANALOG_CONFIG_DPO) || (RFAL_ANALOG_CONFIG_ID_GET_DIRECTION(configId) == RFAL_ANALOG_CONFIG_DLMA) )
+ {
+ configIdMaskVal = (RFAL_ANALOG_CONFIG_POLL_LISTEN_MODE_MASK | RFAL_ANALOG_CONFIG_TECH_MASK | RFAL_ANALOG_CONFIG_BITRATE_MASK | RFAL_ANALOG_CONFIG_DIRECTION_MASK);
+ }
+
+ i = (*configOffset);
+ while( i < gRfalAnalogConfigMgmt.configTblSize )
+ {
+ configTbl = ¤tConfigTbl[i];
+ foundConfigId = RFAL_GETU16(configTbl);
+ if (configId == (foundConfigId & configIdMaskVal))
+ {
+ *configOffset = (uint16_t)(i + sizeof(rfalAnalogConfigId) + sizeof(rfalAnalogConfigNum));
+ return configTbl[sizeof(rfalAnalogConfigId)];
+ }
+
+ /* If Config Id does not match, increment to next Configuration Id */
+ i += (uint16_t)( sizeof(rfalAnalogConfigId) + sizeof(rfalAnalogConfigNum)
+ + (configTbl[sizeof(rfalAnalogConfigId)] * sizeof(rfalAnalogConfigRegAddrMaskVal) )
+ );
+ } /* for */
+
+ return RFAL_ANALOG_CONFIG_LUT_NOT_FOUND;
+}
### core/embed/io/nfc/st25/rfal002/source/rfal_cd.c
@@ -1,741 +1,741 @@
-/******************************************************************************
- * @attention
- *
- * COPYRIGHT 2020 STMicroelectronics, all rights reserved
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
- * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
-******************************************************************************/
-
-/*! \file rfal_cd.c
- *
- * \author Gustavo Patricio
- *
- * \brief RFAL Card Detection
- *
- * This module implements the Card Detection Algorithm.
- * It may be used for applications that require to identify if a card is on
- * the vicinity of the NFC antenna, for example: to protect cards against
- * damage by a wireless charger (WPC Qi PTx).
- *
- * Algorith details
- * - The algorithm treats multiple devices as if a card is present
- * - The algorithm will identify cards by the following distinguishing features
- * - Only cards support NFC-V or other non standard technologies (ST25TB, ...)
- * - Compliant cards support only a single technology
- * - The algorithm will identify phones by the following distinguishing features
- * - Only phones support P2P (NFC-DEP)
- * - Only phones are able to communicate on different NFC technologies
- *
- */
-
-/*
- ******************************************************************************
- * INCLUDES
- ******************************************************************************
- */
-#include "rfal_cd.h"
-#include "rfal_rf.h"
-#include "rfal_nfca.h"
-#include "rfal_nfcb.h"
-#include "rfal_nfcf.h"
-#include "rfal_nfcv.h"
-#include "rfal_st25tb.h"
-
-/*
-******************************************************************************
-* GLOBAL DEFINES
-******************************************************************************
-*/
-
-#define RFAL_CD_NFCF_DEVLIMIT 4U /*!< NFC-F device limit (TechDet aligned) */
-
-/*
-******************************************************************************
-* GLOBAL MACROS
-******************************************************************************
-*/
-
-/*
-******************************************************************************
-* GLOBAL TYPES
-******************************************************************************
-*/
-
-/*! Card Detection states */
-typedef enum{
- RFAL_CD_ST_IDLE, /*!< CD idle */
- RFAL_CD_ST_START, /*!< CD starting */
- RFAL_CD_ST_NFCA_INIT, /*!< NFC-A Initialization */
- RFAL_CD_ST_NFCA_TECHDET, /*!< NFC-A Technology Detection */
- RFAL_CD_ST_NFCA_COLRES_START, /*!< NFC-A Collision Resolution starting */
- RFAL_CD_ST_NFCA_COLRES, /*!< NFC-A Collision Resolution */
- RFAL_CD_ST_NFCB_INIT, /*!< NFC-B Initialization */
- RFAL_CD_ST_NFCB_TECHDET, /*!< NFC-B Technology Detection */
- RFAL_CD_ST_NFCB_COLRES_START, /*!< NFC-B Collision Resolution starting */
- RFAL_CD_ST_NFCB_COLRES, /*!< NFC-B Collision Resolution */
- RFAL_CD_ST_NFCF_INIT, /*!< NFC-F Initialization */
- RFAL_CD_ST_NFCF_TECHDET_START, /*!< NFC-F Technology Detection starting */
- RFAL_CD_ST_NFCF_TECHDET, /*!< NFC-F Technology Detection */
- RFAL_CD_ST_NFCF_COLRES_START, /*!< NFC-F Collision Resolution starting */
- RFAL_CD_ST_NFCF_COLRES, /*!< NFC-F Collision Resolution */
- RFAL_CD_ST_NFCV_INIT, /*!< NFC-V Initialization */
- RFAL_CD_ST_NFCV_TECHDET, /*!< NFC-V Technology Detection */
- RFAL_CD_ST_NFCV_COLRES_START, /*!< NFC-V Collision Resolution starting */
- RFAL_CD_ST_NFCV_COLRES, /*!< NFC-V Collision Resolution */
- RFAL_CD_ST_PROPRIETARY, /*!< Proprietary NFC Technologies starting */
- RFAL_CD_ST_ST25TB_INIT, /*!< ST25TB Initialization */
- RFAL_CD_ST_ST25TB_TECHDET, /*!< ST25TB Technology Detection */
- RFAL_CD_ST_CHECK_PROTO, /*!< Evaluate device(s) found and protocols */
- RFAL_CD_ST_HB_START, /*!< Heartbeat Detection start | Field reset*/
- RFAL_CD_ST_HB, /*!< Heartbeat Detection */
- RFAL_CD_ST_DETECTED, /*!< CD completed: card detected */
- RFAL_CD_ST_NOT_DETECTED, /*!< CD completed: No card detected */
- RFAL_CD_ST_ERROR /*!< Error during card detection */
-}rfalCdState;
-
-
-/*! Card Detection context */
-typedef struct{
- rfalCdState st; /*!< CD state */
- ReturnCode lastErr; /*!< Last occured error */
- rfalNfcaListenDevice nfcaDev; /*!< NFC-A Device Info */
- rfalNfcbListenDevice nfcbDev; /*!< NFC-B Device Info */
- rfalNfcfListenDevice nfcfDev[RFAL_CD_NFCF_DEVLIMIT]; /*!< NFC-F Device Info */
- uint8_t devCnt; /*!< Tech device counter */
- uint8_t mulDevCnt; /*!< Multi Tech device counter */
- rfalCdTech techFound; /*!< First NFC Technology found */
- bool skipTechFound; /*!< Second round ongoing, skip techFound */
- rfalCdRes *res; /*!< Card Detection output result location */
- uint32_t tmr; /*!< Field reset timer */
-}rfalCdCtx;
-
-
-/*
- ******************************************************************************
- * LOCAL VARIABLES
- ******************************************************************************
- */
-
-static rfalCdCtx gCd;
-
-
-/*
-******************************************************************************
-* LOCAL FUNCTION PROTOTYPES
-******************************************************************************
-*/
-#ifdef RFAL_CD_HB
-extern bool rfalCdHbDetect( rfalCdTech tech );
-#endif /* RFAL_CD_HB */
-
-/*
-******************************************************************************
-* GLOBAL FUNCTION PROTOTYPES
-******************************************************************************
-*/
-
-/*******************************************************************************/
-ReturnCode rfalCdDetectCard( rfalCdRes *result )
-{
- ReturnCode err;
-
- RFAL_EXIT_ON_ERR( err, rfalCdStartDetectCard( result ) );
- rfalRunBlocking( err, rfalCdGetDetectCardStatus() );
-
- return err;
-}
-
-
-/*******************************************************************************/
-ReturnCode rfalCdStartDetectCard( rfalCdRes *result )
-{
- if( result == NULL )
- {
- return RFAL_ERR_PARAM;
- }
-
- gCd.st = RFAL_CD_ST_START;
- gCd.res = result;
-
- return RFAL_ERR_NONE;
-}
-
-
-/*******************************************************************************/
-ReturnCode rfalCdGetDetectCardStatus( void )
-{
- ReturnCode err;
- rfalNfcaSensRes sensRes;
- rfalNfcbSensbRes sensbRes;
- rfalNfcvInventoryRes invRes;
-
-
- switch( gCd.st )
- {
- /*******************************************************************************/
- case RFAL_CD_ST_START:
-
- gCd.mulDevCnt = 0; /* Initialize Card Detection context */
- gCd.skipTechFound = false;
- gCd.techFound = RFAL_CD_TECH_NONE;
- gCd.tmr = RFAL_TIMING_NONE;
-
- gCd.st = RFAL_CD_ST_NFCA_INIT;
- break;
-
-
- /*******************************************************************************/
- case RFAL_CD_ST_NFCA_INIT:
-
- /* Verify if we are performing multi technology check */
- if( (gCd.skipTechFound) )
- {
- /* If staring multi technology check if field has been Off long enough */
- if( (!platformTimerIsExpired(gCd.tmr)) )
- {
- break;
- }
-
- if( gCd.techFound == RFAL_CD_TECH_NFCA )
- {
- gCd.st = RFAL_CD_ST_NFCB_INIT; /* If single card card found before was NFC-A skip tech now */
- break;
- }
- }
-
- rfalNfcaPollerInitialize(); /* Initialize for NFC-A */
- err = rfalFieldOnAndStartGT(); /* Turns the Field On if not already and start GT timer */
- if( err != RFAL_ERR_NONE )
- {
- gCd.lastErr = err;
- gCd.st = RFAL_CD_ST_ERROR; /* Unable to turn the field On, cannot continue Card Detection */
- break;
- }
-
- gCd.st = RFAL_CD_ST_NFCA_TECHDET;
- break;
-
-
- /*******************************************************************************/
- case RFAL_CD_ST_NFCA_TECHDET:
-
- if( !rfalIsGTExpired() )
- {
- break; /* Wait until GT has been fulfilled */
- }
-
- err = rfalNfcaPollerTechnologyDetection( RFAL_COMPLIANCE_MODE_ISO, &sensRes );
- if( err == RFAL_ERR_NONE )
- {
- if( gCd.skipTechFound ) /* Verify if we are performing multi technology check */
- {
- gCd.res->detType = RFAL_CD_SINGLE_MULTI_TECH;
- gCd.st = RFAL_CD_ST_NOT_DETECTED;/* Single device was another technology and now NFC-A */
- break;
- }
-
- gCd.st = RFAL_CD_ST_NFCA_COLRES_START; /* NFC-A detected perform collision resolution */
- break;
- }
-
- gCd.st = RFAL_CD_ST_NFCB_INIT; /* NFC-A not detected, move to NFC-B */
- break;
-
-
- /*******************************************************************************/
- case RFAL_CD_ST_NFCA_COLRES_START:
-
- err = rfalNfcaPollerStartFullCollisionResolution( RFAL_COMPLIANCE_MODE_ISO, 0, &gCd.nfcaDev, &gCd.devCnt );
- if( err != RFAL_ERR_NONE )
- {
- gCd.lastErr = err;
- gCd.st = RFAL_CD_ST_ERROR; /* Collision resolution could not be performed */
- break;
- }
-
- gCd.st = RFAL_CD_ST_NFCA_COLRES;
- break;
-
-
- /*******************************************************************************/
- case RFAL_CD_ST_NFCA_COLRES:
-
- err = rfalNfcaPollerGetFullCollisionResolutionStatus();
- if( err != RFAL_ERR_BUSY )
- {
- if( (err == RFAL_ERR_NONE) && (gCd.devCnt == 1U) ) /* Collision resolution OK and a single card was found */
- {
- gCd.mulDevCnt++;
- gCd.techFound = RFAL_CD_TECH_NFCA;
- }
-
- /* Check if multiple cards or technologies have already been identified */
- if( (err != RFAL_ERR_NONE) || (gCd.devCnt > 1U) || (gCd.mulDevCnt > 1U) )
- {
- gCd.res->detType = RFAL_CD_MULTIPLE_DEV; /* Report multiple devices. A T1T will also fail at ColRes */
- gCd.st = RFAL_CD_ST_DETECTED;
-
- break;
- }
-
- gCd.st = RFAL_CD_ST_NFCB_INIT; /* Move to NFC-B */
- }
- break;
-
-
- /*******************************************************************************/
- case RFAL_CD_ST_NFCB_INIT:
-
- /* Verify if we are performing multi technology check */
- if( (gCd.skipTechFound) && (gCd.techFound == RFAL_CD_TECH_NFCB) )
- {
- gCd.st = RFAL_CD_ST_NFCF_INIT; /* If single card card found before was NFC-B skip tech now */
- break;
- }
-
- rfalNfcbPollerInitialize(); /* Initialize for NFC-B */
- rfalFieldOnAndStartGT(); /* Turns the Field On if not already and start GT timer */
-
- gCd.st = RFAL_CD_ST_NFCB_TECHDET;
- break;
-
-
- /*******************************************************************************/
- case RFAL_CD_ST_NFCB_TECHDET:
-
- if( !rfalIsGTExpired() )
- {
- break; /* Wait until GT has been fulfilled */
- }
-
- err = rfalNfcbPollerTechnologyDetection( RFAL_COMPLIANCE_MODE_NFC, &sensbRes, &gCd.devCnt );
- if( err == RFAL_ERR_NONE )
- {
- /* Verify if we are performing multi technology check OR already found one on the first round */
- if( gCd.skipTechFound )
- {
- gCd.res->detType = RFAL_CD_SINGLE_MULTI_TECH;
- gCd.st = RFAL_CD_ST_NOT_DETECTED;/* Single device was another technology and now NFC-B */
- break;
- }
- else if( gCd.techFound != RFAL_CD_TECH_NONE ) /* If on the first round check if other Tech was already found */
- {
- gCd.res->detType = RFAL_CD_MULTIPLE_TECH;
- gCd.st = RFAL_CD_ST_DETECTED;
- break;
- }
- else
- {
- /* MISRA 15.7 - Empty else */
- }
-
- gCd.st = RFAL_CD_ST_NFCB_COLRES_START; /* NFC-B detected perform collision resolution */
- break;
- }
-
- gCd.st = RFAL_CD_ST_NFCF_INIT; /* NFC-B not detected, move to NFC-B */
- break;
-
-
- /*******************************************************************************/
- case RFAL_CD_ST_NFCB_COLRES_START:
-
- err = rfalNfcbPollerStartCollisionResolution( RFAL_COMPLIANCE_MODE_NFC, 0, &gCd.nfcbDev, &gCd.devCnt );
- if( err != RFAL_ERR_NONE )
- {
- gCd.lastErr = err;
- gCd.st = RFAL_CD_ST_ERROR; /* Collision resolution could not be performed */
- break;
- }
-
- gCd.st = RFAL_CD_ST_NFCB_COLRES;
- break;
-
-
- /*******************************************************************************/
- case RFAL_CD_ST_NFCB_COLRES:
-
- err = rfalNfcbPollerGetCollisionResolutionStatus();
- if( err != RFAL_ERR_BUSY )
- {
- if( (err == RFAL_ERR_NONE) && (gCd.devCnt == 1U) ) /* Collision resolution OK and a single card was found */
- {
- gCd.mulDevCnt++;
- gCd.techFound = RFAL_CD_TECH_NFCB;
- }
-
- /* Check if multiple cards or technologies have already been identified */
- if( (err != RFAL_ERR_NONE) || (gCd.devCnt > 1U) || (gCd.mulDevCnt > 1U) )
- {
- gCd.res->detType = RFAL_CD_MULTIPLE_DEV;
- gCd.st = RFAL_CD_ST_DETECTED;
- break;
- }
-
- gCd.st = ( (RFAL_SUPPORT_MODE_POLL_NFCF) ? RFAL_CD_ST_NFCF_INIT : RFAL_CD_ST_NFCV_INIT); /* Move to NFC-F or NFC-V */
- }
- break;
-
- /*******************************************************************************/
- case RFAL_CD_ST_NFCF_INIT:
-
- #if !RFAL_SUPPORT_MODE_POLL_NFCF
- gCd.st = RFAL_CD_ST_NFCV_INIT;
- break;
- #else
- /* Verify if we are performing multi technology check */
- if( (gCd.skipTechFound) && (gCd.techFound == RFAL_CD_TECH_NFCF) )
- {
- gCd.st = RFAL_CD_ST_PROPRIETARY; /* If single card card found before was NFC-F skip tech now */
- break;
- }
-
- rfalNfcfPollerInitialize(RFAL_BR_212); /* Initialize for NFC-F */
- rfalFieldOnAndStartGT(); /* Turns the Field On if not already and start GT timer */
-
- gCd.st = RFAL_CD_ST_NFCF_TECHDET_START;
- break;
-
-
- /*******************************************************************************/
- case RFAL_CD_ST_NFCF_TECHDET_START:
- if( !rfalIsGTExpired() )
- {
- break; /* Wait until GT has been fulfilled */
- }
-
- err = rfalNfcfPollerStartCheckPresence();
- gCd.st = RFAL_CD_ST_NFCF_TECHDET;
- break;
-
-
- /*******************************************************************************/
- case RFAL_CD_ST_NFCF_TECHDET:
-
- err = rfalNfcfPollerGetCheckPresenceStatus();
- if( err == RFAL_ERR_BUSY )
- {
- break; /* Wait until NFC-F Technlogy Detection is completed */
- }
-
- if( gCd.skipTechFound ) /* Verify if we are performing multi technology check */
- {
- gCd.st = RFAL_CD_ST_PROPRIETARY;
-
- /* If single device was another technology and now NFC-F, otherwise conclude*/
- if(err == RFAL_ERR_NONE)
- {
- gCd.res->detType = RFAL_CD_SINGLE_MULTI_TECH;
- gCd.st = RFAL_CD_ST_NOT_DETECTED;
- }
- break;
- }
-
- if( err == RFAL_ERR_NONE )
- {
- if( gCd.techFound != RFAL_CD_TECH_NONE ) /* If on the first round check if other Tech was already found */
- {
- gCd.res->detType = RFAL_CD_MULTIPLE_TECH;
- gCd.st = RFAL_CD_ST_DETECTED;
- break;
- }
-
- gCd.st = RFAL_CD_ST_NFCF_COLRES_START; /* NFC-F detected, perform collision resolution */
- break;
- }
-
- gCd.st = RFAL_CD_ST_NFCV_INIT; /* NFC-F not detected, move to NFC-V */
- break;
-
-
- /*******************************************************************************/
- case RFAL_CD_ST_NFCF_COLRES_START:
-
- err = rfalNfcfPollerStartCollisionResolution( RFAL_COMPLIANCE_MODE_NFC, RFAL_CD_NFCF_DEVLIMIT, gCd.nfcfDev, &gCd.devCnt );
- if( err != RFAL_ERR_NONE )
- {
- gCd.lastErr = err;
- gCd.st = RFAL_CD_ST_ERROR; /* Collision resolution could not be performed */
- break;
- }
-
- gCd.st = RFAL_CD_ST_NFCF_COLRES;
- break;
-
-
- /*******************************************************************************/
- case RFAL_CD_ST_NFCF_COLRES:
-
- err = rfalNfcfPollerGetCollisionResolutionStatus();
- if( err != RFAL_ERR_BUSY )
- {
- if( (err == RFAL_ERR_NONE) && (gCd.devCnt == 1U) ) /* Collision resolution OK and a single card was found */
- {
- gCd.mulDevCnt++;
- gCd.techFound = RFAL_CD_TECH_NFCF;
- }
-
- /* Check if multiple cards or technologies have already been identified */
- if( (err != RFAL_ERR_NONE) || (gCd.devCnt > 1U) || (gCd.mulDevCnt > 1U) )
- {
- gCd.res->detType = RFAL_CD_MULTIPLE_DEV;
- gCd.st = RFAL_CD_ST_DETECTED;
- break;
- }
-
- gCd.st = RFAL_CD_ST_NFCV_INIT; /* Move to NFC-V */
- }
- break;
- #endif /* RFAL_SUPPORT_MODE_POLL_NFCF*/
-
- /*******************************************************************************/
- case RFAL_CD_ST_NFCV_INIT:
-
- rfalNfcvPollerInitialize(); /* Initialize for NFC-V */
- rfalFieldOnAndStartGT(); /* Turns the Field On if not already and start GT timer */
-
- gCd.st = RFAL_CD_ST_NFCV_TECHDET;
- break;
-
- /*******************************************************************************/
- case RFAL_CD_ST_NFCV_TECHDET:
-
- if( !rfalIsGTExpired() )
- {
- break; /* Wait until GT has been fulfilled */
- }
-
- err = rfalNfcvPollerCheckPresence( &invRes );
- if( err == RFAL_ERR_NONE )
- {
- if( gCd.techFound != RFAL_CD_TECH_NONE ) /* If other Tech was already found */
- {
- gCd.res->detType = RFAL_CD_MULTIPLE_TECH;
- gCd.st = RFAL_CD_ST_DETECTED;
- break;
- }
-
- gCd.techFound = RFAL_CD_TECH_NFCV; /* If NFC-V is regarded as card as CE NFC-V is currently not supported by active devices */
- gCd.res->detType = RFAL_CD_CARD_TECH;
- gCd.st = RFAL_CD_ST_DETECTED;
- break;
- }
-
- gCd.st = RFAL_CD_ST_PROPRIETARY; /* Move to Proprietary NFC Technologies */
- break;
-
-
- /*******************************************************************************/
- case RFAL_CD_ST_PROPRIETARY:
-
- rfalFieldOff();
- platformTimerDestroy( gCd.tmr );
- gCd.tmr = platformTimerCreate( (uint8_t)rfalConv1fcToMs(RFAL_GT_NFCA) );
-
- /* If none of the other NFC technologies was not seen on a second round, regard as card */
- if( gCd.skipTechFound )
- {
- gCd.res->detType = RFAL_CD_SINGLE_DEV;
- gCd.st = RFAL_CD_ST_DETECTED;
-
-
- /*******************************************************************************/
- /* Only one device found which does not support NFC-DEP and only *
- * answered in one technology, perform heartbeat detection */
-
- #ifdef RFAL_CD_HB
- gCd.st = RFAL_CD_ST_HB_START;
- #endif /* RFAL_CD_HB */
-
- /*******************************************************************************/
-
- break;
- }
-
- gCd.st = RFAL_CD_ST_ST25TB_INIT;
- break;
-
-
- /*******************************************************************************/
- case RFAL_CD_ST_ST25TB_INIT:
-
- if( (!platformTimerIsExpired( gCd.tmr )) ) /* Check if field has been Off long enough */
- {
- break;
- }
-
- rfalSt25tbPollerInitialize(); /* Initialize for ST25TB */
- err = rfalFieldOnAndStartGT(); /* Turns the Field On if not already and start GT timer */
-
- if( err != RFAL_ERR_NONE )
- {
- gCd.lastErr = err;
- gCd.st = RFAL_CD_ST_ERROR; /* Unable to turn the field On, cannot continue Card Detection */
- break;
- }
-
- gCd.st = RFAL_CD_ST_ST25TB_TECHDET;
- break;
-
-
- /*******************************************************************************/
- case RFAL_CD_ST_ST25TB_TECHDET:
-
- if( (!rfalIsGTExpired()) )
- {
- break; /* Wait until GT has been fulfilled */
- }
-
- err = rfalSt25tbPollerCheckPresence( NULL );
- if( err == RFAL_ERR_NONE )
- {
- gCd.techFound = RFAL_CD_TECH_OTHER; /* If ST25TB is regarded as card as CE is not supported by active devices */
- gCd.res->detType = RFAL_CD_CARD_TECH;
- gCd.st = RFAL_CD_ST_DETECTED;
- break;
- }
-
- gCd.st = RFAL_CD_ST_CHECK_PROTO;
- break;
-
-
- /*******************************************************************************/
- case RFAL_CD_ST_CHECK_PROTO:
-
- if( gCd.mulDevCnt == 0U ) /* No NFC listener has been detected */
- {
- gCd.res->detType = RFAL_CD_NOT_FOUND;
- gCd.st = RFAL_CD_ST_NOT_DETECTED;
- break;
- }
-
- if( gCd.mulDevCnt == 1U ) /* A single NFC listener has been identified */
- {
- /* Check if it supports NFC-DEP protocol */
- if( ( (gCd.techFound == RFAL_CD_TECH_NFCA) && ((gCd.nfcaDev.type == RFAL_NFCA_NFCDEP) || (gCd.nfcaDev.type == RFAL_NFCA_T4T_NFCDEP)) ) ||
- ( (gCd.techFound == RFAL_CD_TECH_NFCF) && rfalNfcfIsNfcDepSupported( &gCd.nfcfDev[0] ) ) )
- {
- gCd.res->detType = RFAL_CD_SINGLE_P2P;
- gCd.st = RFAL_CD_ST_NOT_DETECTED;/* NFC-DEP supported, regarded as non passive card */
- break;
- }
-
- /* If a single NFC listener has been detected, and did not announce NFC-DEP support, *
- * check if it supports mutiple NFC technologies (skip the one it was previous seen) */
- gCd.skipTechFound = true;
- gCd.st = RFAL_CD_ST_NFCA_INIT;
-
- /* Reset Field once again to avoid unwanted effect of Proprietary NFC Tech modulation */
- rfalFieldOff();
- platformTimerDestroy( gCd.tmr );
- gCd.tmr = platformTimerCreate( (uint8_t)rfalConv1fcToMs(RFAL_GT_NFCA) );
- break;
- }
-
- gCd.res->detType = RFAL_CD_MULTIPLE_DEV;
- gCd.st = RFAL_CD_ST_DETECTED;
- break;
-
-
- #ifdef RFAL_CD_HB
- /*******************************************************************************/
- case RFAL_CD_ST_HB_START:
-
- if( (!platformTimerIsExpired( gCd.tmr )) ) /* Check if field has been Off long enough */
- {
- break;
- }
-
- switch( gCd.techFound )
- {
- case RFAL_CD_TECH_NFCF:
- rfalNfcfPollerInitialize( RFAL_BR_212 );
- break;
-
- case RFAL_CD_TECH_NFCB:
- rfalNfcbPollerInitialize();
- break;
-
- case RFAL_CD_TECH_NFCA:
- default:
- rfalNfcaPollerInitialize();
- break;
- }
-
- err = rfalFieldOnAndStartGT();
- if( err != RFAL_ERR_NONE )
- {
- gCd.lastErr = err;
- gCd.st = RFAL_CD_ST_ERROR; /* Unable to turn the field On, cannot continue Card Detection */
- break;
- }
-
- gCd.st = RFAL_CD_ST_HB;
- break;
-
-
- /*******************************************************************************/
- case RFAL_CD_ST_HB:
- if( !rfalIsGTExpired() ) /* Check if GT has been fulfilled */
- {
- break;
- }
-
- if( rfalCdHbDetect( gCd.techFound ) ) /* Perform tha heartbeat detection sequence */
- {
- gCd.res->detType = RFAL_CD_SINGLE_HB;
- gCd.st = RFAL_CD_ST_NOT_DETECTED; /* Single device performing ALM, no passive card */
- break;
- }
-
- gCd.res->detType = RFAL_CD_SINGLE_DEV;
- gCd.st = RFAL_CD_ST_DETECTED; /* ALM not detected on single device, regard as card */
- break;
- #endif /* RFAL_CD_HB */
-
-
- /*******************************************************************************/
- case RFAL_CD_ST_DETECTED:
- case RFAL_CD_ST_NOT_DETECTED:
-
- /* Card Detection completed, return outcome */
- gCd.res->detected = ((gCd.st == RFAL_CD_ST_NOT_DETECTED) ? false : true);
-
- rfalFieldOff();
- gCd.st = RFAL_CD_ST_IDLE;
-
- return RFAL_ERR_NONE;
-
-
- /*******************************************************************************/
- case RFAL_CD_ST_IDLE:
- return RFAL_ERR_WRONG_STATE;
-
-
- /*******************************************************************************/
- case RFAL_CD_ST_ERROR:
-
- gCd.res->detType = RFAL_CD_UNKOWN;
- gCd.res->detected = true; /* Error ocurred, mark as card present to avoid damage */
-
- rfalFieldOff();
- gCd.st = RFAL_CD_ST_IDLE;
-
- return gCd.lastErr;
-
-
- /*******************************************************************************/
- default:
- return RFAL_ERR_INTERNAL;
- }
-
- return RFAL_ERR_BUSY;
-}
-
+/******************************************************************************
+ * @attention
+ *
+ * COPYRIGHT 2020 STMicroelectronics, all rights reserved
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
+ * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+******************************************************************************/
+
+/*! \file rfal_cd.c
+ *
+ * \author Gustavo Patricio
+ *
+ * \brief RFAL Card Detection
+ *
+ * This module implements the Card Detection Algorithm.
+ * It may be used for applications that require to identify if a card is on
+ * the vicinity of the NFC antenna, for example: to protect cards against
+ * damage by a wireless charger (WPC Qi PTx).
+ *
+ * Algorith details
+ * - The algorithm treats multiple devices as if a card is present
+ * - The algorithm will identify cards by the following distinguishing features
+ * - Only cards support NFC-V or other non standard technologies (ST25TB, ...)
+ * - Compliant cards support only a single technology
+ * - The algorithm will identify phones by the following distinguishing features
+ * - Only phones support P2P (NFC-DEP)
+ * - Only phones are able to communicate on different NFC technologies
+ *
+ */
+
+/*
+ ******************************************************************************
+ * INCLUDES
+ ******************************************************************************
+ */
+#include "rfal_cd.h"
+#include "rfal_rf.h"
+#include "rfal_nfca.h"
+#include "rfal_nfcb.h"
+#include "rfal_nfcf.h"
+#include "rfal_nfcv.h"
+#include "rfal_st25tb.h"
+
+/*
+******************************************************************************
+* GLOBAL DEFINES
+******************************************************************************
+*/
+
+#define RFAL_CD_NFCF_DEVLIMIT 4U /*!< NFC-F device limit (TechDet aligned) */
+
+/*
+******************************************************************************
+* GLOBAL MACROS
+******************************************************************************
+*/
+
+/*
+******************************************************************************
+* GLOBAL TYPES
+******************************************************************************
+*/
+
+/*! Card Detection states */
+typedef enum{
+ RFAL_CD_ST_IDLE, /*!< CD idle */
+ RFAL_CD_ST_START, /*!< CD starting */
+ RFAL_CD_ST_NFCA_INIT, /*!< NFC-A Initialization */
+ RFAL_CD_ST_NFCA_TECHDET, /*!< NFC-A Technology Detection */
+ RFAL_CD_ST_NFCA_COLRES_START, /*!< NFC-A Collision Resolution starting */
+ RFAL_CD_ST_NFCA_COLRES, /*!< NFC-A Collision Resolution */
+ RFAL_CD_ST_NFCB_INIT, /*!< NFC-B Initialization */
+ RFAL_CD_ST_NFCB_TECHDET, /*!< NFC-B Technology Detection */
+ RFAL_CD_ST_NFCB_COLRES_START, /*!< NFC-B Collision Resolution starting */
+ RFAL_CD_ST_NFCB_COLRES, /*!< NFC-B Collision Resolution */
+ RFAL_CD_ST_NFCF_INIT, /*!< NFC-F Initialization */
+ RFAL_CD_ST_NFCF_TECHDET_START, /*!< NFC-F Technology Detection starting */
+ RFAL_CD_ST_NFCF_TECHDET, /*!< NFC-F Technology Detection */
+ RFAL_CD_ST_NFCF_COLRES_START, /*!< NFC-F Collision Resolution starting */
+ RFAL_CD_ST_NFCF_COLRES, /*!< NFC-F Collision Resolution */
+ RFAL_CD_ST_NFCV_INIT, /*!< NFC-V Initialization */
+ RFAL_CD_ST_NFCV_TECHDET, /*!< NFC-V Technology Detection */
+ RFAL_CD_ST_NFCV_COLRES_START, /*!< NFC-V Collision Resolution starting */
+ RFAL_CD_ST_NFCV_COLRES, /*!< NFC-V Collision Resolution */
+ RFAL_CD_ST_PROPRIETARY, /*!< Proprietary NFC Technologies starting */
+ RFAL_CD_ST_ST25TB_INIT, /*!< ST25TB Initialization */
+ RFAL_CD_ST_ST25TB_TECHDET, /*!< ST25TB Technology Detection */
+ RFAL_CD_ST_CHECK_PROTO, /*!< Evaluate device(s) found and protocols */
+ RFAL_CD_ST_HB_START, /*!< Heartbeat Detection start | Field reset*/
+ RFAL_CD_ST_HB, /*!< Heartbeat Detection */
+ RFAL_CD_ST_DETECTED, /*!< CD completed: card detected */
+ RFAL_CD_ST_NOT_DETECTED, /*!< CD completed: No card detected */
+ RFAL_CD_ST_ERROR /*!< Error during card detection */
+}rfalCdState;
+
+
+/*! Card Detection context */
+typedef struct{
+ rfalCdState st; /*!< CD state */
+ ReturnCode lastErr; /*!< Last occured error */
+ rfalNfcaListenDevice nfcaDev; /*!< NFC-A Device Info */
+ rfalNfcbListenDevice nfcbDev; /*!< NFC-B Device Info */
+ rfalNfcfListenDevice nfcfDev[RFAL_CD_NFCF_DEVLIMIT]; /*!< NFC-F Device Info */
+ uint8_t devCnt; /*!< Tech device counter */
+ uint8_t mulDevCnt; /*!< Multi Tech device counter */
+ rfalCdTech techFound; /*!< First NFC Technology found */
+ bool skipTechFound; /*!< Second round ongoing, skip techFound */
+ rfalCdRes *res; /*!< Card Detection output result location */
+ uint32_t tmr; /*!< Field reset timer */
+}rfalCdCtx;
+
+
+/*
+ ******************************************************************************
+ * LOCAL VARIABLES
+ ******************************************************************************
+ */
+
+static rfalCdCtx gCd;
+
+
+/*
+******************************************************************************
+* LOCAL FUNCTION PROTOTYPES
+******************************************************************************
+*/
+#ifdef RFAL_CD_HB
+extern bool rfalCdHbDetect( rfalCdTech tech );
+#endif /* RFAL_CD_HB */
+
+/*
+******************************************************************************
+* GLOBAL FUNCTION PROTOTYPES
+******************************************************************************
+*/
+
+/*******************************************************************************/
+ReturnCode rfalCdDetectCard( rfalCdRes *result )
+{
+ ReturnCode err;
+
+ RFAL_EXIT_ON_ERR( err, rfalCdStartDetectCard( result ) );
+ rfalRunBlocking( err, rfalCdGetDetectCardStatus() );
+
+ return err;
+}
+
+
+/*******************************************************************************/
+ReturnCode rfalCdStartDetectCard( rfalCdRes *result )
+{
+ if( result == NULL )
+ {
+ return RFAL_ERR_PARAM;
+ }
+
+ gCd.st = RFAL_CD_ST_START;
+ gCd.res = result;
+
+ return RFAL_ERR_NONE;
+}
+
+
+/*******************************************************************************/
+ReturnCode rfalCdGetDetectCardStatus( void )
+{
+ ReturnCode err;
+ rfalNfcaSensRes sensRes;
+ rfalNfcbSensbRes sensbRes;
+ rfalNfcvInventoryRes invRes;
+
+
+ switch( gCd.st )
+ {
+ /*******************************************************************************/
+ case RFAL_CD_ST_START:
+
+ gCd.mulDevCnt = 0; /* Initialize Card Detection context */
+ gCd.skipTechFound = false;
+ gCd.techFound = RFAL_CD_TECH_NONE;
+ gCd.tmr = RFAL_TIMING_NONE;
+
+ gCd.st = RFAL_CD_ST_NFCA_INIT;
+ break;
+
+
+ /*******************************************************************************/
+ case RFAL_CD_ST_NFCA_INIT:
+
+ /* Verify if we are performing multi technology check */
+ if( (gCd.skipTechFound) )
+ {
+ /* If staring multi technology check if field has been Off long enough */
+ if( (!platformTimerIsExpired(gCd.tmr)) )
+ {
+ break;
+ }
+
+ if( gCd.techFound == RFAL_CD_TECH_NFCA )
+ {
+ gCd.st = RFAL_CD_ST_NFCB_INIT; /* If single card card found before was NFC-A skip tech now */
+ break;
+ }
+ }
+
+ rfalNfcaPollerInitialize(); /* Initialize for NFC-A */
+ err = rfalFieldOnAndStartGT(); /* Turns the Field On if not already and start GT timer */
+ if( err != RFAL_ERR_NONE )
+ {
+ gCd.lastErr = err;
+ gCd.st = RFAL_CD_ST_ERROR; /* Unable to turn the field On, cannot continue Card Detection */
+ break;
+ }
+
+ gCd.st = RFAL_CD_ST_NFCA_TECHDET;
+ break;
+
+
+ /*******************************************************************************/
+ case RFAL_CD_ST_NFCA_TECHDET:
+
+ if( !rfalIsGTExpired() )
+ {
+ break; /* Wait until GT has been fulfilled */
+ }
+
+ err = rfalNfcaPollerTechnologyDetection( RFAL_COMPLIANCE_MODE_ISO, &sensRes );
+ if( err == RFAL_ERR_NONE )
+ {
+ if( gCd.skipTechFound ) /* Verify if we are performing multi technology check */
+ {
+ gCd.res->detType = RFAL_CD_SINGLE_MULTI_TECH;
+ gCd.st = RFAL_CD_ST_NOT_DETECTED;/* Single device was another technology and now NFC-A */
+ break;
+ }
+
+ gCd.st = RFAL_CD_ST_NFCA_COLRES_START; /* NFC-A detected perform collision resolution */
+ break;
+ }
+
+ gCd.st = RFAL_CD_ST_NFCB_INIT; /* NFC-A not detected, move to NFC-B */
+ break;
+
+
+ /*******************************************************************************/
+ case RFAL_CD_ST_NFCA_COLRES_START:
+
+ err = rfalNfcaPollerStartFullCollisionResolution( RFAL_COMPLIANCE_MODE_ISO, 0, &gCd.nfcaDev, &gCd.devCnt );
+ if( err != RFAL_ERR_NONE )
+ {
+ gCd.lastErr = err;
+ gCd.st = RFAL_CD_ST_ERROR; /* Collision resolution could not be performed */
+ break;
+ }
+
+ gCd.st = RFAL_CD_ST_NFCA_COLRES;
+ break;
+
+
+ /*******************************************************************************/
+ case RFAL_CD_ST_NFCA_COLRES:
+
+ err = rfalNfcaPollerGetFullCollisionResolutionStatus();
+ if( err != RFAL_ERR_BUSY )
+ {
+ if( (err == RFAL_ERR_NONE) && (gCd.devCnt == 1U) ) /* Collision resolution OK and a single card was found */
+ {
+ gCd.mulDevCnt++;
+ gCd.techFound = RFAL_CD_TECH_NFCA;
+ }
+
+ /* Check if multiple cards or technologies have already been identified */
+ if( (err != RFAL_ERR_NONE) || (gCd.devCnt > 1U) || (gCd.mulDevCnt > 1U) )
+ {
+ gCd.res->detType = RFAL_CD_MULTIPLE_DEV; /* Report multiple devices. A T1T will also fail at ColRes */
+ gCd.st = RFAL_CD_ST_DETECTED;
+
+ break;
+ }
+
+ gCd.st = RFAL_CD_ST_NFCB_INIT; /* Move to NFC-B */
+ }
+ break;
+
+
+ /*******************************************************************************/
+ case RFAL_CD_ST_NFCB_INIT:
+
+ /* Verify if we are performing multi technology check */
+ if( (gCd.skipTechFound) && (gCd.techFound == RFAL_CD_TECH_NFCB) )
+ {
+ gCd.st = RFAL_CD_ST_NFCF_INIT; /* If single card card found before was NFC-B skip tech now */
+ break;
+ }
+
+ rfalNfcbPollerInitialize(); /* Initialize for NFC-B */
+ (void)rfalFieldOnAndStartGT(); /* Turns the Field On if not already and start GT timer */
+
+ gCd.st = RFAL_CD_ST_NFCB_TECHDET;
+ break;
+
+
+ /*******************************************************************************/
+ case RFAL_CD_ST_NFCB_TECHDET:
+
+ if( !rfalIsGTExpired() )
+ {
+ break; /* Wait until GT has been fulfilled */
+ }
+
+ err = rfalNfcbPollerTechnologyDetection( RFAL_COMPLIANCE_MODE_NFC, &sensbRes, &gCd.devCnt );
+ if( err == RFAL_ERR_NONE )
+ {
+ /* Verify if we are performing multi technology check OR already found one on the first round */
+ if( gCd.skipTechFound )
+ {
+ gCd.res->detType = RFAL_CD_SINGLE_MULTI_TECH;
+ gCd.st = RFAL_CD_ST_NOT_DETECTED;/* Single device was another technology and now NFC-B */
+ break;
+ }
+ else if( gCd.techFound != RFAL_CD_TECH_NONE ) /* If on the first round check if other Tech was already found */
+ {
+ gCd.res->detType = RFAL_CD_MULTIPLE_TECH;
+ gCd.st = RFAL_CD_ST_DETECTED;
+ break;
+ }
+ else
+ {
+ /* MISRA 15.7 - Empty else */
+ }
+
+ gCd.st = RFAL_CD_ST_NFCB_COLRES_START; /* NFC-B detected perform collision resolution */
+ break;
+ }
+
+ gCd.st = RFAL_CD_ST_NFCF_INIT; /* NFC-B not detected, move to NFC-B */
+ break;
+
+
+ /*******************************************************************************/
+ case RFAL_CD_ST_NFCB_COLRES_START:
+
+ err = rfalNfcbPollerStartCollisionResolution( RFAL_COMPLIANCE_MODE_NFC, 0, &gCd.nfcbDev, &gCd.devCnt );
+ if( err != RFAL_ERR_NONE )
+ {
+ gCd.lastErr = err;
+ gCd.st = RFAL_CD_ST_ERROR; /* Collision resolution could not be performed */
+ break;
+ }
+
+ gCd.st = RFAL_CD_ST_NFCB_COLRES;
+ break;
+
+
+ /*******************************************************************************/
+ case RFAL_CD_ST_NFCB_COLRES:
+
+ err = rfalNfcbPollerGetCollisionResolutionStatus();
+ if( err != RFAL_ERR_BUSY )
+ {
+ if( (err == RFAL_ERR_NONE) && (gCd.devCnt == 1U) ) /* Collision resolution OK and a single card was found */
+ {
+ gCd.mulDevCnt++;
+ gCd.techFound = RFAL_CD_TECH_NFCB;
+ }
+
+ /* Check if multiple cards or technologies have already been identified */
+ if( (err != RFAL_ERR_NONE) || (gCd.devCnt > 1U) || (gCd.mulDevCnt > 1U) )
+ {
+ gCd.res->detType = RFAL_CD_MULTIPLE_DEV;
+ gCd.st = RFAL_CD_ST_DETECTED;
+ break;
+ }
+
+ gCd.st = ( (RFAL_SUPPORT_MODE_POLL_NFCF) ? RFAL_CD_ST_NFCF_INIT : RFAL_CD_ST_NFCV_INIT); /* Move to NFC-F or NFC-V */
+ }
+ break;
+
+ /*******************************************************************************/
+ case RFAL_CD_ST_NFCF_INIT:
+
+ #if !RFAL_SUPPORT_MODE_POLL_NFCF
+ gCd.st = RFAL_CD_ST_NFCV_INIT;
+ break;
+ #else
+ /* Verify if we are performing multi technology check */
+ if( (gCd.skipTechFound) && (gCd.techFound == RFAL_CD_TECH_NFCF) )
+ {
+ gCd.st = RFAL_CD_ST_PROPRIETARY; /* If single card card found before was NFC-F skip tech now */
+ break;
+ }
+
+ rfalNfcfPollerInitialize(RFAL_BR_212); /* Initialize for NFC-F */
+ (void)rfalFieldOnAndStartGT(); /* Turns the Field On if not already and start GT timer */
+
+ gCd.st = RFAL_CD_ST_NFCF_TECHDET_START;
+ break;
+
+
+ /*******************************************************************************/
+ case RFAL_CD_ST_NFCF_TECHDET_START:
+ if( !rfalIsGTExpired() )
+ {
+ break; /* Wait until GT has been fulfilled */
+ }
+
+ err = rfalNfcfPollerStartCheckPresence();
+ gCd.st = RFAL_CD_ST_NFCF_TECHDET;
+ break;
+
+
+ /*******************************************************************************/
+ case RFAL_CD_ST_NFCF_TECHDET:
+
+ err = rfalNfcfPollerGetCheckPresenceStatus();
+ if( err == RFAL_ERR_BUSY )
+ {
+ break; /* Wait until NFC-F Technology Detection is completed */
+ }
+
+ if( gCd.skipTechFound ) /* Verify if we are performing multi technology check */
+ {
+ gCd.st = RFAL_CD_ST_PROPRIETARY;
+
+ /* If single device was another technology and now NFC-F, otherwise conclude*/
+ if(err == RFAL_ERR_NONE)
+ {
+ gCd.res->detType = RFAL_CD_SINGLE_MULTI_TECH;
+ gCd.st = RFAL_CD_ST_NOT_DETECTED;
+ }
+ break;
+ }
+
+ if( err == RFAL_ERR_NONE )
+ {
+ if( gCd.techFound != RFAL_CD_TECH_NONE ) /* If on the first round check if other Tech was already found */
+ {
+ gCd.res->detType = RFAL_CD_MULTIPLE_TECH;
+ gCd.st = RFAL_CD_ST_DETECTED;
+ break;
+ }
+
+ gCd.st = RFAL_CD_ST_NFCF_COLRES_START; /* NFC-F detected, perform collision resolution */
+ break;
+ }
+
+ gCd.st = RFAL_CD_ST_NFCV_INIT; /* NFC-F not detected, move to NFC-V */
+ break;
+
+
+ /*******************************************************************************/
+ case RFAL_CD_ST_NFCF_COLRES_START:
+
+ err = rfalNfcfPollerStartCollisionResolution( RFAL_COMPLIANCE_MODE_NFC, RFAL_CD_NFCF_DEVLIMIT, gCd.nfcfDev, &gCd.devCnt );
+ if( err != RFAL_ERR_NONE )
+ {
+ gCd.lastErr = err;
+ gCd.st = RFAL_CD_ST_ERROR; /* Collision resolution could not be performed */
+ break;
+ }
+
+ gCd.st = RFAL_CD_ST_NFCF_COLRES;
+ break;
+
+
+ /*******************************************************************************/
+ case RFAL_CD_ST_NFCF_COLRES:
+
+ err = rfalNfcfPollerGetCollisionResolutionStatus();
+ if( err != RFAL_ERR_BUSY )
+ {
+ if( (err == RFAL_ERR_NONE) && (gCd.devCnt == 1U) ) /* Collision resolution OK and a single card was found */
+ {
+ gCd.mulDevCnt++;
+ gCd.techFound = RFAL_CD_TECH_NFCF;
+ }
+
+ /* Check if multiple cards or technologies have already been identified */
+ if( (err != RFAL_ERR_NONE) || (gCd.devCnt > 1U) || (gCd.mulDevCnt > 1U) )
+ {
+ gCd.res->detType = RFAL_CD_MULTIPLE_DEV;
+ gCd.st = RFAL_CD_ST_DETECTED;
+ break;
+ }
+
+ gCd.st = RFAL_CD_ST_NFCV_INIT; /* Move to NFC-V */
+ }
+ break;
+ #endif /* RFAL_SUPPORT_MODE_POLL_NFCF*/
+
+ /*******************************************************************************/
+ case RFAL_CD_ST_NFCV_INIT:
+
+ rfalNfcvPollerInitialize(); /* Initialize for NFC-V */
+ (void)rfalFieldOnAndStartGT(); /* Turns the Field On if not already and start GT timer */
+
+ gCd.st = RFAL_CD_ST_NFCV_TECHDET;
+ break;
+
+ /*******************************************************************************/
+ case RFAL_CD_ST_NFCV_TECHDET:
+
+ if( !rfalIsGTExpired() )
+ {
+ break; /* Wait until GT has been fulfilled */
+ }
+
+ err = rfalNfcvPollerCheckPresence( &invRes );
+ if( err == RFAL_ERR_NONE )
+ {
+ if( gCd.techFound != RFAL_CD_TECH_NONE ) /* If other Tech was already found */
+ {
+ gCd.res->detType = RFAL_CD_MULTIPLE_TECH;
+ gCd.st = RFAL_CD_ST_DETECTED;
+ break;
+ }
+
+ gCd.techFound = RFAL_CD_TECH_NFCV; /* If NFC-V is regarded as card as CE NFC-V is currently not supported by active devices */
+ gCd.res->detType = RFAL_CD_CARD_TECH;
+ gCd.st = RFAL_CD_ST_DETECTED;
+ break;
+ }
+
+ gCd.st = RFAL_CD_ST_PROPRIETARY; /* Move to Proprietary NFC Technologies */
+ break;
+
+
+ /*******************************************************************************/
+ case RFAL_CD_ST_PROPRIETARY:
+
+ rfalFieldOff();
+ platformTimerDestroy( gCd.tmr );
+ gCd.tmr = platformTimerCreate( (uint8_t)rfalConv1fcToMs(RFAL_GT_NFCA) );
+
+ /* If none of the other NFC technologies was not seen on a second round, regard as card */
+ if( gCd.skipTechFound )
+ {
+ gCd.res->detType = RFAL_CD_SINGLE_DEV;
+ gCd.st = RFAL_CD_ST_DETECTED;
+
+
+ /*******************************************************************************/
+ /* Only one device found which does not support NFC-DEP and only *
+ * answered in one technology, perform heartbeat detection */
+
+ #ifdef RFAL_CD_HB
+ gCd.st = RFAL_CD_ST_HB_START;
+ #endif /* RFAL_CD_HB */
+
+ /*******************************************************************************/
+
+ break;
+ }
+
+ gCd.st = RFAL_CD_ST_ST25TB_INIT;
+ break;
+
+
+ /*******************************************************************************/
+ case RFAL_CD_ST_ST25TB_INIT:
+
+ if( (!platformTimerIsExpired( gCd.tmr )) ) /* Check if field has been Off long enough */
+ {
+ break;
+ }
+
+ rfalSt25tbPollerInitialize(); /* Initialize for ST25TB */
+ err = rfalFieldOnAndStartGT(); /* Turns the Field On if not already and start GT timer */
+
+ if( err != RFAL_ERR_NONE )
+ {
+ gCd.lastErr = err;
+ gCd.st = RFAL_CD_ST_ERROR; /* Unable to turn the field On, cannot continue Card Detection */
+ break;
+ }
+
+ gCd.st = RFAL_CD_ST_ST25TB_TECHDET;
+ break;
+
+
+ /*******************************************************************************/
+ case RFAL_CD_ST_ST25TB_TECHDET:
+
+ if( (!rfalIsGTExpired()) )
+ {
+ break; /* Wait until GT has been fulfilled */
+ }
+
+ err = rfalSt25tbPollerCheckPresence( NULL );
+ if( err == RFAL_ERR_NONE )
+ {
+ gCd.techFound = RFAL_CD_TECH_OTHER; /* If ST25TB is regarded as card as CE is not supported by active devices */
+ gCd.res->detType = RFAL_CD_CARD_TECH;
+ gCd.st = RFAL_CD_ST_DETECTED;
+ break;
+ }
+
+ gCd.st = RFAL_CD_ST_CHECK_PROTO;
+ break;
+
+
+ /*******************************************************************************/
+ case RFAL_CD_ST_CHECK_PROTO:
+
+ if( gCd.mulDevCnt == 0U ) /* No NFC listener has been detected */
+ {
+ gCd.res->detType = RFAL_CD_NOT_FOUND;
+ gCd.st = RFAL_CD_ST_NOT_DETECTED;
+ break;
+ }
+
+ if( gCd.mulDevCnt == 1U ) /* A single NFC listener has been identified */
+ {
+ /* Check if it supports NFC-DEP protocol */
+ if( ( (gCd.techFound == RFAL_CD_TECH_NFCA) && ((gCd.nfcaDev.type == RFAL_NFCA_NFCDEP) || (gCd.nfcaDev.type == RFAL_NFCA_T4T_NFCDEP)) ) ||
+ ( (gCd.techFound == RFAL_CD_TECH_NFCF) && rfalNfcfIsNfcDepSupported( &gCd.nfcfDev[0] ) ) )
+ {
+ gCd.res->detType = RFAL_CD_SINGLE_P2P;
+ gCd.st = RFAL_CD_ST_NOT_DETECTED;/* NFC-DEP supported, regarded as non passive card */
+ break;
+ }
+
+ /* If a single NFC listener has been detected, and did not announce NFC-DEP support, *
+ * check if it supports mutiple NFC technologies (skip the one it was previous seen) */
+ gCd.skipTechFound = true;
+ gCd.st = RFAL_CD_ST_NFCA_INIT;
+
+ /* Reset Field once again to avoid unwanted effect of Proprietary NFC Tech modulation */
+ rfalFieldOff();
+ platformTimerDestroy( gCd.tmr );
+ gCd.tmr = platformTimerCreate( (uint8_t)rfalConv1fcToMs(RFAL_GT_NFCA) );
+ break;
+ }
+
+ gCd.res->detType = RFAL_CD_MULTIPLE_DEV;
+ gCd.st = RFAL_CD_ST_DETECTED;
+ break;
+
+
+ #ifdef RFAL_CD_HB
+ /*******************************************************************************/
+ case RFAL_CD_ST_HB_START:
+
+ if( (!platformTimerIsExpired( gCd.tmr )) ) /* Check if field has been Off long enough */
+ {
+ break;
+ }
+
+ switch( gCd.techFound )
+ {
+ case RFAL_CD_TECH_NFCF:
+ rfalNfcfPollerInitialize( RFAL_BR_212 );
+ break;
+
+ case RFAL_CD_TECH_NFCB:
+ rfalNfcbPollerInitialize();
+ break;
+
+ case RFAL_CD_TECH_NFCA:
+ default:
+ rfalNfcaPollerInitialize();
+ break;
+ }
+
+ err = rfalFieldOnAndStartGT();
+ if( err != RFAL_ERR_NONE )
+ {
+ gCd.lastErr = err;
+ gCd.st = RFAL_CD_ST_ERROR; /* Unable to turn the field On, cannot continue Card Detection */
+ break;
+ }
+
+ gCd.st = RFAL_CD_ST_HB;
+ break;
+
+
+ /*******************************************************************************/
+ case RFAL_CD_ST_HB:
+ if( !rfalIsGTExpired() ) /* Check if GT has been fulfilled */
+ {
+ break;
+ }
+
+ if( rfalCdHbDetect( gCd.techFound ) ) /* Perform tha heartbeat detection sequence */
+ {
+ gCd.res->detType = RFAL_CD_SINGLE_HB;
+ gCd.st = RFAL_CD_ST_NOT_DETECTED; /* Single device performing ALM, no passive card */
+ break;
+ }
+
+ gCd.res->detType = RFAL_CD_SINGLE_DEV;
+ gCd.st = RFAL_CD_ST_DETECTED; /* ALM not detected on single device, regard as card */
+ break;
+ #endif /* RFAL_CD_HB */
+
+
+ /*******************************************************************************/
+ case RFAL_CD_ST_DETECTED:
+ case RFAL_CD_ST_NOT_DETECTED:
+
+ /* Card Detection completed, return outcome */
+ gCd.res->detected = ((gCd.st == RFAL_CD_ST_NOT_DETECTED) ? false : true);
+
+ rfalFieldOff();
+ gCd.st = RFAL_CD_ST_IDLE;
+
+ return RFAL_ERR_NONE;
+
+
+ /*******************************************************************************/
+ case RFAL_CD_ST_IDLE:
+ return RFAL_ERR_WRONG_STATE;
+
+
+ /*******************************************************************************/
+ case RFAL_CD_ST_ERROR:
+
+ gCd.res->detType = RFAL_CD_UNKOWN;
+ gCd.res->detected = true; /* Error ocurred, mark as card present to avoid damage */
+
+ rfalFieldOff();
+ gCd.st = RFAL_CD_ST_IDLE;
+
+ return gCd.lastErr;
+
+
+ /*******************************************************************************/
+ default:
+ return RFAL_ERR_INTERNAL;
+ }
+
+ return RFAL_ERR_BUSY;
+}
+
### core/embed/io/nfc/st25/rfal002/source/rfal_crc.c
@@ -1,81 +1,81 @@
-
-/******************************************************************************
- * @attention
- *
- * COPYRIGHT 2016 STMicroelectronics, all rights reserved
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
- * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
-******************************************************************************/
-
-
-/*
- * PROJECT: ST25R firmware
- * Revision:
- * LANGUAGE: ISO C99
- */
-
-/*! \file rfal_crc.c
- *
- * \author Oliver Regenfelder
- *
- * \brief CRC calculation implementation
- *
- */
-
-/*
-******************************************************************************
-* INCLUDES
-******************************************************************************
-*/
-#include "rfal_crc.h"
-
-/*
-******************************************************************************
-* LOCAL FUNCTION PROTOTYPES
-******************************************************************************
-*/
-static uint16_t rfalCrcUpdateCcitt(uint16_t crcSeed, uint8_t dataByte);
-
-/*
-******************************************************************************
-* GLOBAL FUNCTIONS
-******************************************************************************
-*/
-uint16_t rfalCrcCalculateCcitt(uint16_t preloadValue, const uint8_t* buf, uint16_t length)
-{
- uint16_t crc = preloadValue;
- uint16_t index;
-
- for (index = 0; index < length; index++)
- {
- crc = rfalCrcUpdateCcitt(crc, buf[index]);
- }
-
- return crc;
-}
-
-/*
-******************************************************************************
-* LOCAL FUNCTIONS
-******************************************************************************
-*/
-static uint16_t rfalCrcUpdateCcitt(uint16_t crcSeed, uint8_t dataByte)
-{
- uint16_t crc = crcSeed;
- uint8_t dat = dataByte;
-
- dat ^= (uint8_t)(crc & 0xFFU);
- dat ^= (dat << 4);
-
- crc = (crc >> 8)^(((uint16_t) dat) << 8)^(((uint16_t) dat) << 3)^(((uint16_t) dat) >> 4);
-
- return crc;
-}
-
+
+/******************************************************************************
+ * @attention
+ *
+ * COPYRIGHT 2016 STMicroelectronics, all rights reserved
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
+ * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+******************************************************************************/
+
+
+/*
+ * PROJECT: ST25R firmware
+ * Revision:
+ * LANGUAGE: ISO C99
+ */
+
+/*! \file rfal_crc.c
+ *
+ * \author Oliver Regenfelder
+ *
+ * \brief CRC calculation implementation
+ *
+ */
+
+/*
+******************************************************************************
+* INCLUDES
+******************************************************************************
+*/
+#include "rfal_crc.h"
+
+/*
+******************************************************************************
+* LOCAL FUNCTION PROTOTYPES
+******************************************************************************
+*/
+static uint16_t rfalCrcUpdateCcitt(uint16_t crcSeed, uint8_t dataByte);
+
+/*
+******************************************************************************
+* GLOBAL FUNCTIONS
+******************************************************************************
+*/
+uint16_t rfalCrcCalculateCcitt(uint16_t preloadValue, const uint8_t* buf, uint16_t length)
+{
+ uint16_t crc = preloadValue;
+ uint16_t index;
+
+ for (index = 0; index < length; index++)
+ {
+ crc = rfalCrcUpdateCcitt(crc, buf[index]);
+ }
+
+ return crc;
+}
+
+/*
+******************************************************************************
+* LOCAL FUNCTIONS
+******************************************************************************
+*/
+static uint16_t rfalCrcUpdateCcitt(uint16_t crcSeed, uint8_t dataByte)
+{
+ uint16_t crc = crcSeed;
+ uint8_t dat = dataByte;
+
+ dat ^= (uint8_t)(crc & 0xFFU);
+ dat ^= (dat << 4);
+
+ crc = (crc >> 8)^(((uint16_t) dat) << 8)^(((uint16_t) dat) << 3)^(((uint16_t) dat) >> 4);
+
+ return crc;
+}
+
### core/embed/io/nfc/st25/rfal002/source/rfal_crc.h
@@ -1,70 +1,83 @@
-
-/******************************************************************************
- * @attention
- *
- * COPYRIGHT 2016 STMicroelectronics, all rights reserved
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
- * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
-******************************************************************************/
-
-
-/*
- * PROJECT: ST25R firmware
- * Revision:
- * LANGUAGE: ISO C99
- */
-
-/*! \file rfal_crc.h
- *
- * \author Ulrich Herrmann
- *
- * \brief CRC calculation module
- *
- */
-/*!
- *
- */
-
-#ifndef RFAL_CRC_H_
-#define RFAL_CRC_H_
-
-/*
-******************************************************************************
-* INCLUDES
-******************************************************************************
-*/
-#include "rfal_platform.h"
-
-/*
-******************************************************************************
-* GLOBAL FUNCTION PROTOTYPES
-******************************************************************************
-*/
-/*!
- *****************************************************************************
- * \brief Calculate CRC according to CCITT standard.
- *
- * This function takes \a length bytes from \a buf and calculates the CRC
- * for this data. The result is returned.
- * \note This implementation calculates the CRC with LSB first, i.e. all
- * bytes are "read" from right to left.
- *
- * \param[in] preloadValue : Initial value of CRC calculation.
- * \param[in] buf : buffer to calculate the CRC for.
- * \param[in] length : size of the buffer.
- *
- * \return 16 bit long crc value.
- *
- *****************************************************************************
- */
-extern uint16_t rfalCrcCalculateCcitt(uint16_t preloadValue, const uint8_t* buf, uint16_t length);
-
-#endif /* RFAL_CRC_H_ */
-
+
+/******************************************************************************
+ * @attention
+ *
+ * COPYRIGHT 2016 STMicroelectronics, all rights reserved
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
+ * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+******************************************************************************/
+
+
+/*
+ * PROJECT: ST25R firmware
+ * Revision:
+ * LANGUAGE: ISO C99
+ */
+
+/*! \file rfal_crc.h
+ *
+ * \author Ulrich Herrmann
+ *
+ * \brief CRC calculation module
+ *
+ */
+/*!
+ *
+ */
+
+#ifndef RFAL_CRC_H_
+#define RFAL_CRC_H_
+
+/*
+******************************************************************************
+* INCLUDES
+******************************************************************************
+*/
+#include "rfal_platform.h"
+
+/*
+ ******************************************************************************
+ * C LINKAGE GUARD
+ ******************************************************************************
+ */
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/*
+******************************************************************************
+* GLOBAL FUNCTION PROTOTYPES
+******************************************************************************
+*/
+/*!
+ *****************************************************************************
+ * \brief Calculate CRC according to CCITT standard.
+ *
+ * This function takes \a length bytes from \a buf and calculates the CRC
+ * for this data. The result is returned.
+ * \note This implementation calculates the CRC with LSB first, i.e. all
+ * bytes are "read" from right to left.
+ *
+ * \param[in] preloadValue : Initial value of CRC calculation.
+ * \param[in] buf : buffer to calculate the CRC for.
+ * \param[in] length : size of the buffer.
+ *
+ * \return 16 bit long crc value.
+ *
+ *****************************************************************************
+ */
+extern uint16_t rfalCrcCalculateCcitt(uint16_t preloadValue, const uint8_t* buf, uint16_t length);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* RFAL_CRC_H_ */
+
### core/embed/io/nfc/st25/rfal002/source/rfal_dlma.c
@@ -1,319 +1,319 @@
-
-/******************************************************************************
- * @attention
- *
- * COPYRIGHT 2016 STMicroelectronics, all rights reserved
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
- * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
-******************************************************************************/
-
-/*
- * PROJECT: ST25R firmware
- * $Revision: $
- * LANGUAGE: ISO C99
- */
-
-/*! \file rfal_dlma.c
- *
- * \brief Functions to manage dynamically the LMA
- *
- *
- * It provides handling for dynamic LMA for Passive Listen Mode
- *
- * \warning DLMA is applicable only when the ST25R driver is used for Passive
- * Listen Mode, not if driven externally
- */
-
-/*
- ******************************************************************************
- * INCLUDES
- ******************************************************************************
- */
-#include "rfal_dlma.h"
-#include "rfal_platform.h"
-#include "rfal_rf.h"
-#include "rfal_chip.h"
-#include "rfal_analogConfig.h"
-#include "rfal_utils.h"
-
-
-/*
- ******************************************************************************
- * ENABLE SWITCH
- ******************************************************************************
- */
-
-/* Feature switch may be enabled or disabled by user at rfal_platform.h
- * Default configuration (ST25R dependant) also provided at rfal_defConfig.h
- *
- * RFAL_FEATURE_DLMA
- */
-
-
-#if RFAL_FEATURE_DLMA
-
-
-/* Check for valid Configuration */
-#if !RFAL_SUPPORT_CE
- #error " RFAL: Invalid configuration. DLMA only applicable for ST25R supporting Passive Listen Mode. "
-#endif
-
-
-/*
- ******************************************************************************
- * CONDITIONAL INCLUDES
- ******************************************************************************
- */
-#include "rfal_dlmaTbl.h"
-
-/*
- ******************************************************************************
- * DEFINES
- ******************************************************************************
- */
-#define RFAL_DLMA_ANALOGCONFIG_SHIFT 13U
-#define RFAL_DLMA_ANALOGCONFIG_MASK 0x6000U
-
-/*
- ******************************************************************************
- * LOCAL DATA TYPES
- ******************************************************************************
- */
-
-/*! RFAL DLMA instance */
-typedef struct{
- bool enabled;
- const rfalDlmaEntry* currentDlma;
- uint8_t tableEntries;
- rfalDlmaEntry table[RFAL_DLMA_TABLE_MAX_ENTRIES];
- uint8_t tableEntry;
- uint8_t refMeasurement;
- rfalDlmaMeasureFunc measureCallback;
- rfalDlmaAdjustFunc adjustCallback;
-}rfalDlma;
-
-
-/*
- ******************************************************************************
- * LOCAL VARIABLES
- ******************************************************************************
- */
-
-static rfalDlma gRfalDlma;
-
-/*
- ******************************************************************************
- * GLOBAL FUNCTIONS
- ******************************************************************************
- */
-void rfalDlmaInitialize( void )
-{
- /* By default DLMA is disabled */
- rfalDlmaSetEnabled( false );
-
- /* Set default measurement and adjust methods */
- gRfalDlma.measureCallback = &rfalChipGetLmFieldInd;
- gRfalDlma.adjustCallback = &rfalChipSetLMMod;
-
-
- /* Use the default Dynamic LMA values */
- gRfalDlma.currentDlma = rfalDlmaDefaultSettings;
- gRfalDlma.tableEntries = (sizeof(rfalDlmaDefaultSettings) / RFAL_DLMA_TABLE_PARAM_LEN);
-
- RFAL_MEMCPY( gRfalDlma.table, gRfalDlma.currentDlma, sizeof(rfalDlmaDefaultSettings) );
-}
-
-
-/*******************************************************************************/
-void rfalDlmaSetMeasureCallback( rfalDlmaMeasureFunc pFunc )
-{
- gRfalDlma.measureCallback = pFunc;
-}
-
-
-/*******************************************************************************/
-void rfalDlmaSetAdjustCallback( rfalDlmaAdjustFunc pFunc )
-{
- gRfalDlma.adjustCallback = pFunc;
-}
-
-
-/*******************************************************************************/
-ReturnCode rfalDlmaTableWrite( const rfalDlmaEntry* powerTbl, uint8_t powerTblEntries )
-{
- uint8_t entry;
-
- /* Check if the table size parameter is too big */
- if( powerTblEntries > RFAL_DLMA_TABLE_MAX_ENTRIES)
- {
- return RFAL_ERR_NOMEM;
- }
-
- /* Check if the first increase entry is 0xFF */
- if( (powerTblEntries == 0U) || (powerTbl == NULL) )
- {
- return RFAL_ERR_PARAM;
- }
-
- /* Check if the entries of the dynamic power table are valid */
- for( entry = 0; entry < powerTblEntries; entry++ )
- {
- if(powerTbl[entry].inc < powerTbl[entry].dec)
- {
- return RFAL_ERR_PARAM;
- }
- }
-
- /* Copy the data set */
- RFAL_MEMCPY( gRfalDlma.table, powerTbl, (powerTblEntries * RFAL_DLMA_TABLE_PARAM_LEN) );
- gRfalDlma.currentDlma = gRfalDlma.table;
- gRfalDlma.tableEntries = powerTblEntries;
-
- if( gRfalDlma.tableEntry > powerTblEntries )
- {
- /* powerTblEntries is always greater then zero, verified at parameter check */
- gRfalDlma.tableEntry = (powerTblEntries - 1U);
- }
-
- return RFAL_ERR_NONE;
-}
-
-
-/*******************************************************************************/
-ReturnCode rfalDlmaTableRead( rfalDlmaEntry* tblBuf, uint8_t tblBufEntries, uint8_t* tableEntries )
-{
- /* Check parameters */
- if( (tblBuf == NULL) || (tblBufEntries < gRfalDlma.tableEntries) || (tableEntries == NULL) )
- {
- return RFAL_ERR_PARAM;
- }
-
- /* Not properly initialized */
- if( gRfalDlma.currentDlma == NULL )
- {
- return RFAL_ERR_WRONG_STATE;
- }
-
- /* Copy the whole Table to the given buffer */
- RFAL_MEMCPY( tblBuf, gRfalDlma.currentDlma, (tblBufEntries * RFAL_DLMA_TABLE_PARAM_LEN) );
- *tableEntries = gRfalDlma.tableEntries;
-
- return RFAL_ERR_NONE;
-}
-
-
-/*******************************************************************************/
-ReturnCode rfalDlmaAdjust( void )
-{
- uint8_t refValue;
- uint16_t modeID;
- rfalBitRate br;
- rfalMode mode;
- uint8_t tableEntry;
- uint8_t i;
- const rfalDlmaEntry* dlmaTable;
-
- /* Initialize local vars */
- tableEntry = gRfalDlma.tableEntry;
- dlmaTable = gRfalDlma.currentDlma;
- refValue = 0;
- mode = RFAL_MODE_NONE;
- br = RFAL_BR_KEEP;
-
- /* Obtain RFAL's current mode and bit rate */
- mode = rfalGetMode();
- rfalGetBitRate( &br, NULL );
-
-
- /* Check if the Power Adjustment is disabled and *
- * if the callback to the measurement method is properly set */
- if( (!gRfalDlma.enabled) || (gRfalDlma.measureCallback == NULL) || (gRfalDlma.adjustCallback == NULL) )
- {
- return RFAL_ERR_PARAM;
- }
-
- /* Ensure that the table is initialized*/
- if( gRfalDlma.currentDlma == NULL )
- {
- return RFAL_ERR_WRONG_STATE;
- }
-
- /* Ensure a proper measure reference value */
- if( RFAL_ERR_NONE != gRfalDlma.measureCallback( &refValue ) )
- {
- return RFAL_ERR_IO;
- }
-
- for( i = 0; i < RFAL_DLMA_TABLE_MAX_ENTRIES; i++ )
- {
- /* Search the table to find matching entry */
- if( (refValue <= dlmaTable[i].inc) && (refValue >= dlmaTable[i].dec) )
- {
- tableEntry = i;
- break;
- }
- }
-
- /* Apply configs and Update local context */
- gRfalDlma.refMeasurement = refValue;
- gRfalDlma.tableEntry = tableEntry;
-
-
- /* Set the new value for LMA (e.g. RFO resistance) form the table and apply it */
- gRfalDlma.adjustCallback( dlmaTable[gRfalDlma.tableEntry].modRes, dlmaTable[gRfalDlma.tableEntry].unmodRes );
-
- /* Apply the DLMA Analog Config according to this threshold */
- /* Technology field is being extended for DLMA: 2msb are used for threshold step (only 4 allowed) */
- modeID = rfalAnalogConfigGenModeID( mode, br, RFAL_ANALOG_CONFIG_DLMA ); /* Generate Analog Config mode ID */
- modeID |= (((uint16_t)gRfalDlma.tableEntry << RFAL_DLMA_ANALOGCONFIG_SHIFT) & RFAL_DLMA_ANALOGCONFIG_MASK); /* Add DLMA threshold step|level */
- rfalSetAnalogConfig( modeID ); /* Apply DLMA Analog Config */
-
- return RFAL_ERR_NONE;
-}
-
-
-/*******************************************************************************/
-void rfalDlmaSetEnabled( bool enable )
-{
- gRfalDlma.enabled = enable;
- gRfalDlma.tableEntry = 0;
- gRfalDlma.refMeasurement = 0;
-}
-
-
-/*******************************************************************************/
-bool rfalDlmaIsEnabled( void )
-{
- return gRfalDlma.enabled;
-}
-
-
-/*******************************************************************************/
-ReturnCode rfalDlmaGetInfo( rfalDlmaInfo* info )
-{
- if( info == NULL )
- {
- return RFAL_ERR_PARAM;
- }
-
- /* Clear info structure */
- RFAL_MEMSET( info, 0, sizeof(rfalDlmaInfo) );
-
- info->enabled = gRfalDlma.enabled;
- info->refMeasurement = gRfalDlma.refMeasurement;
- info->tableEntry = gRfalDlma.tableEntry;
- info->tableEntries = gRfalDlma.tableEntries;
- info->measureCallback = gRfalDlma.measureCallback;
- info->adjustCallback = gRfalDlma.adjustCallback;
-
- return RFAL_ERR_NONE;
-}
-
-#endif /* RFAL_FEATURE_DLMA */
+
+/******************************************************************************
+ * @attention
+ *
+ * COPYRIGHT 2016 STMicroelectronics, all rights reserved
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
+ * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+******************************************************************************/
+
+/*
+ * PROJECT: ST25R firmware
+ * $Revision: $
+ * LANGUAGE: ISO C99
+ */
+
+/*! \file rfal_dlma.c
+ *
+ * \brief Functions to manage dynamically the LMA
+ *
+ *
+ * It provides handling for dynamic LMA for Passive Listen Mode
+ *
+ * \warning DLMA is applicable only when the ST25R driver is used for Passive
+ * Listen Mode, not if driven externally
+ */
+
+/*
+ ******************************************************************************
+ * INCLUDES
+ ******************************************************************************
+ */
+#include "rfal_dlma.h"
+#include "rfal_platform.h"
+#include "rfal_rf.h"
+#include "rfal_chip.h"
+#include "rfal_analogConfig.h"
+#include "rfal_utils.h"
+
+
+/*
+ ******************************************************************************
+ * ENABLE SWITCH
+ ******************************************************************************
+ */
+
+/* Feature switch may be enabled or disabled by user at rfal_platform.h
+ * Default configuration (ST25R dependant) also provided at rfal_defConfig.h
+ *
+ * RFAL_FEATURE_DLMA
+ */
+
+
+#if RFAL_FEATURE_DLMA
+
+
+/* Check for valid Configuration */
+#if !RFAL_SUPPORT_CE
+ #error " RFAL: Invalid configuration. DLMA only applicable for ST25R supporting Passive Listen Mode. "
+#endif
+
+
+/*
+ ******************************************************************************
+ * CONDITIONAL INCLUDES
+ ******************************************************************************
+ */
+#include "rfal_dlmaTbl.h"
+
+/*
+ ******************************************************************************
+ * DEFINES
+ ******************************************************************************
+ */
+#define RFAL_DLMA_ANALOGCONFIG_SHIFT 13U
+#define RFAL_DLMA_ANALOGCONFIG_MASK 0x6000U
+
+/*
+ ******************************************************************************
+ * LOCAL DATA TYPES
+ ******************************************************************************
+ */
+
+/*! RFAL DLMA instance */
+typedef struct{
+ bool enabled;
+ const rfalDlmaEntry* currentDlma;
+ uint8_t tableEntries;
+ rfalDlmaEntry table[RFAL_DLMA_TABLE_MAX_ENTRIES];
+ uint8_t tableEntry;
+ uint8_t refMeasurement;
+ rfalDlmaMeasureFunc measureCallback;
+ rfalDlmaAdjustFunc adjustCallback;
+}rfalDlma;
+
+
+/*
+ ******************************************************************************
+ * LOCAL VARIABLES
+ ******************************************************************************
+ */
+
+static rfalDlma gRfalDlma;
+
+/*
+ ******************************************************************************
+ * GLOBAL FUNCTIONS
+ ******************************************************************************
+ */
+void rfalDlmaInitialize( void )
+{
+ /* By default DLMA is disabled */
+ rfalDlmaSetEnabled( false );
+
+ /* Set default measurement and adjust methods */
+ gRfalDlma.measureCallback = &rfalChipGetLmFieldInd;
+ gRfalDlma.adjustCallback = &rfalChipSetLMMod;
+
+
+ /* Use the default Dynamic LMA values */
+ gRfalDlma.currentDlma = rfalDlmaDefaultSettings;
+ gRfalDlma.tableEntries = (sizeof(rfalDlmaDefaultSettings) / RFAL_DLMA_TABLE_PARAM_LEN);
+
+ RFAL_MEMCPY( gRfalDlma.table, gRfalDlma.currentDlma, sizeof(rfalDlmaDefaultSettings) );
+}
+
+
+/*******************************************************************************/
+void rfalDlmaSetMeasureCallback( rfalDlmaMeasureFunc pFunc )
+{
+ gRfalDlma.measureCallback = pFunc;
+}
+
+
+/*******************************************************************************/
+void rfalDlmaSetAdjustCallback( rfalDlmaAdjustFunc pFunc )
+{
+ gRfalDlma.adjustCallback = pFunc;
+}
+
+
+/*******************************************************************************/
+ReturnCode rfalDlmaTableWrite( const rfalDlmaEntry* powerTbl, uint8_t powerTblEntries )
+{
+ uint8_t entry;
+
+ /* Check if the table size parameter is too big */
+ if( powerTblEntries > RFAL_DLMA_TABLE_MAX_ENTRIES)
+ {
+ return RFAL_ERR_NOMEM;
+ }
+
+ /* Check if the first increase entry is 0xFF */
+ if( (powerTblEntries == 0U) || (powerTbl == NULL) )
+ {
+ return RFAL_ERR_PARAM;
+ }
+
+ /* Check if the entries of the dynamic power table are valid */
+ for( entry = 0; entry < powerTblEntries; entry++ )
+ {
+ if(powerTbl[entry].inc < powerTbl[entry].dec)
+ {
+ return RFAL_ERR_PARAM;
+ }
+ }
+
+ /* Copy the data set */
+ RFAL_MEMCPY( gRfalDlma.table, powerTbl, (powerTblEntries * RFAL_DLMA_TABLE_PARAM_LEN) );
+ gRfalDlma.currentDlma = gRfalDlma.table;
+ gRfalDlma.tableEntries = powerTblEntries;
+
+ if( gRfalDlma.tableEntry > powerTblEntries )
+ {
+ /* powerTblEntries is always greater then zero, verified at parameter check */
+ gRfalDlma.tableEntry = (powerTblEntries - 1U);
+ }
+
+ return RFAL_ERR_NONE;
+}
+
+
+/*******************************************************************************/
+ReturnCode rfalDlmaTableRead( rfalDlmaEntry* tblBuf, uint8_t tblBufEntries, uint8_t* tableEntries )
+{
+ /* Check parameters */
+ if( (tblBuf == NULL) || (tblBufEntries < gRfalDlma.tableEntries) || (tableEntries == NULL) )
+ {
+ return RFAL_ERR_PARAM;
+ }
+
+ /* Not properly initialized */
+ if( gRfalDlma.currentDlma == NULL )
+ {
+ return RFAL_ERR_WRONG_STATE;
+ }
+
+ /* Copy the whole Table to the given buffer */
+ RFAL_MEMCPY( tblBuf, gRfalDlma.currentDlma, (tblBufEntries * RFAL_DLMA_TABLE_PARAM_LEN) );
+ *tableEntries = gRfalDlma.tableEntries;
+
+ return RFAL_ERR_NONE;
+}
+
+
+/*******************************************************************************/
+ReturnCode rfalDlmaAdjust( void )
+{
+ uint8_t refValue;
+ uint16_t modeID;
+ rfalBitRate br;
+ rfalMode mode;
+ uint8_t tableEntry;
+ uint8_t i;
+ const rfalDlmaEntry* dlmaTable;
+
+ /* Initialize local vars */
+ tableEntry = gRfalDlma.tableEntry;
+ dlmaTable = gRfalDlma.currentDlma;
+ refValue = 0;
+ mode = RFAL_MODE_NONE;
+ br = RFAL_BR_KEEP;
+
+ /* Obtain RFAL's current mode and bit rate */
+ mode = rfalGetMode();
+ rfalGetBitRate( &br, NULL );
+
+
+ /* Check if the Power Adjustment is disabled and *
+ * if the callback to the measurement method is properly set */
+ if( (!gRfalDlma.enabled) || (gRfalDlma.measureCallback == NULL) || (gRfalDlma.adjustCallback == NULL) )
+ {
+ return RFAL_ERR_PARAM;
+ }
+
+ /* Ensure that the table is initialized*/
+ if( gRfalDlma.currentDlma == NULL )
+ {
+ return RFAL_ERR_WRONG_STATE;
+ }
+
+ /* Ensure a proper measure reference value */
+ if( RFAL_ERR_NONE != gRfalDlma.measureCallback( &refValue ) )
+ {
+ return RFAL_ERR_IO;
+ }
+
+ for( i = 0; i < RFAL_DLMA_TABLE_MAX_ENTRIES; i++ )
+ {
+ /* Search the table to find matching entry */
+ if( (refValue <= dlmaTable[i].inc) && (refValue >= dlmaTable[i].dec) )
+ {
+ tableEntry = i;
+ break;
+ }
+ }
+
+ /* Apply configs and Update local context */
+ gRfalDlma.refMeasurement = refValue;
+ gRfalDlma.tableEntry = tableEntry;
+
+
+ /* Set the new value for LMA (e.g. RFO resistance) form the table and apply it */
+ gRfalDlma.adjustCallback( dlmaTable[gRfalDlma.tableEntry].modRes, dlmaTable[gRfalDlma.tableEntry].unmodRes );
+
+ /* Apply the DLMA Analog Config according to this threshold */
+ /* Technology field is being extended for DLMA: 2msb are used for threshold step (only 4 allowed) */
+ modeID = rfalAnalogConfigGenModeID( mode, br, RFAL_ANALOG_CONFIG_DLMA ); /* Generate Analog Config mode ID */
+ modeID |= (((uint16_t)gRfalDlma.tableEntry << RFAL_DLMA_ANALOGCONFIG_SHIFT) & RFAL_DLMA_ANALOGCONFIG_MASK); /* Add DLMA threshold step|level */
+ rfalSetAnalogConfig( modeID ); /* Apply DLMA Analog Config */
+
+ return RFAL_ERR_NONE;
+}
+
+
+/*******************************************************************************/
+void rfalDlmaSetEnabled( bool enable )
+{
+ gRfalDlma.enabled = enable;
+ gRfalDlma.tableEntry = 0;
+ gRfalDlma.refMeasurement = 0;
+}
+
+
+/*******************************************************************************/
+bool rfalDlmaIsEnabled( void )
+{
+ return gRfalDlma.enabled;
+}
+
+
+/*******************************************************************************/
+ReturnCode rfalDlmaGetInfo( rfalDlmaInfo* info )
+{
+ if( info == NULL )
+ {
+ return RFAL_ERR_PARAM;
+ }
+
+ /* Clear info structure */
+ RFAL_MEMSET( info, 0, sizeof(rfalDlmaInfo) );
+
+ info->enabled = gRfalDlma.enabled;
+ info->refMeasurement = gRfalDlma.refMeasurement;
+ info->tableEntry = gRfalDlma.tableEntry;
+ info->tableEntries = gRfalDlma.tableEntries;
+ info->measureCallback = gRfalDlma.measureCallback;
+ info->adjustCallback = gRfalDlma.adjustCallback;
+
+ return RFAL_ERR_NONE;
+}
+
+#endif /* RFAL_FEATURE_DLMA */
### core/embed/io/nfc/st25/rfal002/source/rfal_dpo.c
@@ -1,356 +1,356 @@
-
-/******************************************************************************
- * @attention
- *
- * COPYRIGHT 2016 STMicroelectronics, all rights reserved
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
- * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
-******************************************************************************/
-
-/*
- * PROJECT: ST25R firmware
- * $Revision: $
- * LANGUAGE: ISO C99
- */
-
-/*! \file rfal_dpo.c
- *
- * \author Martin Zechleitner
- *
- * \brief Functions to manage and set dynamic power settings
- *
- */
-
-/*
- ******************************************************************************
- * INCLUDES
- ******************************************************************************
- */
-#include "rfal_dpoTbl.h"
-#include "rfal_dpo.h"
-#include "rfal_platform.h"
-#include "rfal_rf.h"
-#include "rfal_chip.h"
-#include "rfal_analogConfig.h"
-#include "rfal_utils.h"
-
-
-/*
- ******************************************************************************
- * ENABLE SWITCH
- ******************************************************************************
- */
-
-/* Feature switch may be enabled or disabled by user at rfal_platform.h
- * Default configuration (ST25R dependant) also provided at rfal_defConfig.h
- *
- * RFAL_FEATURE_DPO
- */
-
-#if RFAL_FEATURE_DPO
-
-
-/*
- ******************************************************************************
- * DEFINES
- ******************************************************************************
- */
-#define RFAL_DPO_ANALOGCONFIG_SHIFT 13U
-#define RFAL_DPO_ANALOGCONFIG_MASK 0x6000U
-
-/*
- ******************************************************************************
- * LOCAL DATA TYPES
- ******************************************************************************
- */
-
-/*! RFAL DPO instance */
-typedef struct{
- bool enabled;
- const rfalDpoEntry* currentDpo;
- uint8_t tableEntries;
- rfalDpoEntry table[RFAL_DPO_TABLE_MAX_ENTRIES];
- uint8_t tableEntry;
- rfalDpoMeasureFunc measureCallback;
- rfalDpoAdjustFunc adjustCallback;
- uint8_t refMeasurement;
- rfalMode curMode;
- rfalBitRate curBR;
- bool forceAdj;
-}rfalDpo;
-
-
-/*
- ******************************************************************************
- * LOCAL VARIABLES
- ******************************************************************************
- */
-
-static rfalDpo gRfalDpo;
-
-/*
- ******************************************************************************
- * GLOBAL FUNCTIONS
- ******************************************************************************
- */
-void rfalDpoInitialize( void )
-{
- /* By default DPO is disabled */
- rfalDpoSetEnabled( false );
-
-
- /* Set default measurement */
- #if defined(ST25R3911) || defined(ST25R3916) || defined(ST25R3916B)
- gRfalDpo.measureCallback = &rfalChipMeasureAmplitude;
- #else
- gRfalDpo.measureCallback = &rfalChipMeasureCombinedIQ;
- #endif /* ST25R */
-
-
- /* Set default adjustment */
- gRfalDpo.adjustCallback = &rfalChipSetRFO;
-
-
- /* Use the default Dynamic Power values */
- gRfalDpo.currentDpo = rfalDpoDefaultSettings;
- gRfalDpo.tableEntries = (sizeof(rfalDpoDefaultSettings) / RFAL_DPO_TABLE_PARAM_LEN);
-
- RFAL_MEMCPY( gRfalDpo.table, gRfalDpo.currentDpo, sizeof(rfalDpoDefaultSettings) );
-}
-
-
-/*******************************************************************************/
-void rfalDpoSetMeasureCallback( rfalDpoMeasureFunc pFunc )
-{
- gRfalDpo.measureCallback = pFunc;
-}
-
-
-/*******************************************************************************/
-void rfalDpoSetAdjustCallback( rfalDpoAdjustFunc pFunc )
-{
- gRfalDpo.adjustCallback = pFunc;
-}
-
-
-/*******************************************************************************/
-ReturnCode rfalDpoTableWrite( const rfalDpoEntry* powerTbl, uint8_t powerTblEntries )
-{
- uint8_t entry;
-
- /* Check if the table size parameter is too big */
- if( (powerTblEntries * RFAL_DPO_TABLE_PARAM_LEN) > RFAL_DPO_TABLE_SIZE_MAX)
- {
- return RFAL_ERR_NOMEM;
- }
-
- /* Check if the first increase entry is 0xFF */
- if( (powerTblEntries == 0U) || (powerTbl == NULL) )
- {
- return RFAL_ERR_PARAM;
- }
-
- /* Check if the entries of the dynamic power table are valid */
- for( entry = 0; entry < powerTblEntries; entry++ )
- {
- if(powerTbl[entry].inc < powerTbl[entry].dec)
- {
- return RFAL_ERR_PARAM;
- }
- }
-
- /* Copy the data set */
- RFAL_MEMCPY( gRfalDpo.table, powerTbl, (powerTblEntries * RFAL_DPO_TABLE_PARAM_LEN) );
-
- gRfalDpo.currentDpo = gRfalDpo.table;
- gRfalDpo.tableEntries = powerTblEntries;
-
- if( gRfalDpo.tableEntry > powerTblEntries )
- {
- /* powerTblEntries is always greater then zero, verified at parameter check */
- gRfalDpo.tableEntry = (powerTblEntries - 1U);
- }
-
- return RFAL_ERR_NONE;
-}
-
-
-/*******************************************************************************/
-ReturnCode rfalDpoTableRead( rfalDpoEntry* tblBuf, uint8_t tblBufEntries, uint8_t* tableEntries )
-{
- /* Wrong request */
- if( (tblBuf == NULL) || (tblBufEntries < gRfalDpo.tableEntries) || (tableEntries == NULL) )
- {
- return RFAL_ERR_PARAM;
- }
-
- /* Not properly initialized */
- if( gRfalDpo.currentDpo == NULL )
- {
- return RFAL_ERR_WRONG_STATE;
- }
-
- /* Copy the whole Table to the given buffer */
- RFAL_MEMCPY( tblBuf, gRfalDpo.currentDpo, (tblBufEntries * RFAL_DPO_TABLE_PARAM_LEN) );
- *tableEntries = gRfalDpo.tableEntries;
-
- return RFAL_ERR_NONE;
-}
-
-
-/*******************************************************************************/
-ReturnCode rfalDpoAdjust( void )
-{
- uint8_t refValue;
- uint16_t modeID;
- rfalBitRate br;
- rfalMode mode;
- uint8_t tableEntry;
- const rfalDpoEntry* dpoTable;
-
- /* Initialize local vars */
- tableEntry = gRfalDpo.tableEntry;
- dpoTable = gRfalDpo.currentDpo;
- refValue = 0;
- mode = RFAL_MODE_NONE;
- br = RFAL_BR_KEEP;
-
- /* Obtain RFAL's current mode and bit rate */
- mode = rfalGetMode();
- rfalGetBitRate( &br, NULL );
-
-
- /* Check if the Power Adjustment is disabled and *
- * if the callback to the measurement method is properly set */
- if( (!gRfalDpo.enabled) || (gRfalDpo.measureCallback == NULL) || (gRfalDpo.adjustCallback == NULL) )
- {
- return RFAL_ERR_PARAM;
- }
-
- /* Ensure that the current mode is Passive Poller and table is initialized*/
- if( (!rfalIsModePassivePoll( mode )) || (gRfalDpo.currentDpo == NULL) )
- {
- return RFAL_ERR_WRONG_STATE;
- }
-
- /* Ensure a proper measure reference value */
- if( RFAL_ERR_NONE != gRfalDpo.measureCallback( &refValue ) )
- {
- return RFAL_ERR_IO;
- }
-
- /* Store last measurement */
- gRfalDpo.refMeasurement = refValue;
-
-
- if( refValue >= dpoTable[gRfalDpo.tableEntry].inc )
- { /* Increase the output power */
- /* the top of the table represents the highest amplitude value*/
- if( gRfalDpo.tableEntry == 0U )
- {
- /* Maximum driver value has been reached */
- }
- else
- {
- /* Go up in the table to decrease the driver resistance */
- tableEntry--;
- }
- }
- else if( refValue <= dpoTable[gRfalDpo.tableEntry].dec )
- { /* Decrease the output power */
- /* The bottom is the highest possible value */
- if( (gRfalDpo.tableEntry + 1U) >= gRfalDpo.tableEntries )
- {
- /* minimum driver value has been reached */
- }
- else
- {
- /* Go down in the table to increase the driver resistance */
- tableEntry++;
- }
- }
- else
- {
- /* Fall through to evaluate whether to write dpo and its associated analog configs */
- }
-
- /* Apply new configs if there was a change on DPO level or RFAL mode|bitrate */
- /* Also adjust power in case mode is not yet set and a different table entry|setting is applicbale */
- if( (mode != gRfalDpo.curMode) || (br != gRfalDpo.curBR) || (tableEntry != gRfalDpo.tableEntry) || ((mode == RFAL_MODE_NONE) && (tableEntry != gRfalDpo.tableEntry)) || (gRfalDpo.forceAdj) )
- {
- /* Update local context */
- gRfalDpo.curMode = mode;
- gRfalDpo.curBR = br;
- gRfalDpo.tableEntry = tableEntry;
- gRfalDpo.forceAdj = false;
-
- /* Get the new value from the table (e.g. RFO resistance) and apply the new setting */
- gRfalDpo.adjustCallback( dpoTable[gRfalDpo.tableEntry].rfoRes );
-
- /* Apply the DPO Analog Config according to this threshold */
- /* Technology field is being extended for DPO: 2msb are used for threshold step (only 4 allowed) */
- modeID = rfalAnalogConfigGenModeID( gRfalDpo.curMode, gRfalDpo.curBR, RFAL_ANALOG_CONFIG_DPO ); /* Generate Analog Config mode ID */
- modeID |= (((uint16_t)gRfalDpo.tableEntry << RFAL_DPO_ANALOGCONFIG_SHIFT) & RFAL_DPO_ANALOGCONFIG_MASK); /* Add DPO threshold step|level */
- rfalSetAnalogConfig( modeID ); /* Apply DPO Analog Config */
- }
-
- return RFAL_ERR_NONE;
-}
-
-
-/*******************************************************************************/
-void rfalDpoSetEnabled( bool enable )
-{
- gRfalDpo.enabled = enable;
- gRfalDpo.forceAdj = enable;
- gRfalDpo.curMode = RFAL_MODE_NONE;
- gRfalDpo.curBR = RFAL_BR_KEEP;
- gRfalDpo.tableEntry = 0;
- gRfalDpo.refMeasurement = 0;
-}
-
-
-/*******************************************************************************/
-bool rfalDpoIsEnabled( void )
-{
- return gRfalDpo.enabled;
-}
-
-
-/*******************************************************************************/
-void rfalDpoReqAdj( void )
-{
- gRfalDpo.forceAdj = true;
-}
-
-
-/*******************************************************************************/
-ReturnCode rfalDpoGetInfo( rfalDpoInfo* info )
-{
- if( info == NULL )
- {
- return RFAL_ERR_PARAM;
- }
-
- /* Clear info structure */
- RFAL_MEMSET( info, 0, sizeof(rfalDpoInfo) );
-
- info->enabled = gRfalDpo.enabled;
- info->tableEntries = gRfalDpo.tableEntries;
- info->tableEntry = gRfalDpo.tableEntry;
- info->adjustCallback = gRfalDpo.adjustCallback;
- info->measureCallback = gRfalDpo.measureCallback;
- info->refMeasurement = gRfalDpo.refMeasurement;
-
- return RFAL_ERR_NONE;
-}
-
-
-#endif /* RFAL_FEATURE_DPO */
+
+/******************************************************************************
+ * @attention
+ *
+ * COPYRIGHT 2016 STMicroelectronics, all rights reserved
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
+ * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+******************************************************************************/
+
+/*
+ * PROJECT: ST25R firmware
+ * $Revision: $
+ * LANGUAGE: ISO C99
+ */
+
+/*! \file rfal_dpo.c
+ *
+ * \author Martin Zechleitner
+ *
+ * \brief Functions to manage and set dynamic power settings
+ *
+ */
+
+/*
+ ******************************************************************************
+ * INCLUDES
+ ******************************************************************************
+ */
+#include "rfal_dpoTbl.h"
+#include "rfal_dpo.h"
+#include "rfal_platform.h"
+#include "rfal_rf.h"
+#include "rfal_chip.h"
+#include "rfal_analogConfig.h"
+#include "rfal_utils.h"
+
+
+/*
+ ******************************************************************************
+ * ENABLE SWITCH
+ ******************************************************************************
+ */
+
+/* Feature switch may be enabled or disabled by user at rfal_platform.h
+ * Default configuration (ST25R dependant) also provided at rfal_defConfig.h
+ *
+ * RFAL_FEATURE_DPO
+ */
+
+#if RFAL_FEATURE_DPO
+
+
+/*
+ ******************************************************************************
+ * DEFINES
+ ******************************************************************************
+ */
+#define RFAL_DPO_ANALOGCONFIG_SHIFT 13U
+#define RFAL_DPO_ANALOGCONFIG_MASK 0x6000U
+
+/*
+ ******************************************************************************
+ * LOCAL DATA TYPES
+ ******************************************************************************
+ */
+
+/*! RFAL DPO instance */
+typedef struct{
+ bool enabled;
+ const rfalDpoEntry* currentDpo;
+ uint8_t tableEntries;
+ rfalDpoEntry table[RFAL_DPO_TABLE_MAX_ENTRIES];
+ uint8_t tableEntry;
+ rfalDpoMeasureFunc measureCallback;
+ rfalDpoAdjustFunc adjustCallback;
+ uint8_t refMeasurement;
+ rfalMode curMode;
+ rfalBitRate curBR;
+ bool forceAdj;
+}rfalDpo;
+
+
+/*
+ ******************************************************************************
+ * LOCAL VARIABLES
+ ******************************************************************************
+ */
+
+static rfalDpo gRfalDpo;
+
+/*
+ ******************************************************************************
+ * GLOBAL FUNCTIONS
+ ******************************************************************************
+ */
+void rfalDpoInitialize( void )
+{
+ /* By default DPO is disabled */
+ rfalDpoSetEnabled( false );
+
+
+ /* Set default measurement */
+ #if defined(ST25R3911) || defined(ST25R3916) || defined(ST25R3916B)
+ gRfalDpo.measureCallback = &rfalChipMeasureAmplitude;
+ #else
+ gRfalDpo.measureCallback = &rfalChipMeasureCombinedIQ;
+ #endif /* ST25R */
+
+
+ /* Set default adjustment */
+ gRfalDpo.adjustCallback = &rfalChipSetRFO;
+
+
+ /* Use the default Dynamic Power values */
+ gRfalDpo.currentDpo = rfalDpoDefaultSettings;
+ gRfalDpo.tableEntries = (sizeof(rfalDpoDefaultSettings) / RFAL_DPO_TABLE_PARAM_LEN);
+
+ RFAL_MEMCPY( gRfalDpo.table, gRfalDpo.currentDpo, sizeof(rfalDpoDefaultSettings) );
+}
+
+
+/*******************************************************************************/
+void rfalDpoSetMeasureCallback( rfalDpoMeasureFunc pFunc )
+{
+ gRfalDpo.measureCallback = pFunc;
+}
+
+
+/*******************************************************************************/
+void rfalDpoSetAdjustCallback( rfalDpoAdjustFunc pFunc )
+{
+ gRfalDpo.adjustCallback = pFunc;
+}
+
+
+/*******************************************************************************/
+ReturnCode rfalDpoTableWrite( const rfalDpoEntry* powerTbl, uint8_t powerTblEntries )
+{
+ uint8_t entry;
+
+ /* Check if the table size parameter is too big */
+ if( (powerTblEntries * RFAL_DPO_TABLE_PARAM_LEN) > RFAL_DPO_TABLE_SIZE_MAX)
+ {
+ return RFAL_ERR_NOMEM;
+ }
+
+ /* Check if the first increase entry is 0xFF */
+ if( (powerTblEntries == 0U) || (powerTbl == NULL) )
+ {
+ return RFAL_ERR_PARAM;
+ }
+
+ /* Check if the entries of the dynamic power table are valid */
+ for( entry = 0; entry < powerTblEntries; entry++ )
+ {
+ if(powerTbl[entry].inc < powerTbl[entry].dec)
+ {
+ return RFAL_ERR_PARAM;
+ }
+ }
+
+ /* Copy the data set */
+ RFAL_MEMCPY( gRfalDpo.table, powerTbl, (powerTblEntries * RFAL_DPO_TABLE_PARAM_LEN) );
+
+ gRfalDpo.currentDpo = gRfalDpo.table;
+ gRfalDpo.tableEntries = powerTblEntries;
+
+ if( gRfalDpo.tableEntry > powerTblEntries )
+ {
+ /* powerTblEntries is always greater then zero, verified at parameter check */
+ gRfalDpo.tableEntry = (powerTblEntries - 1U);
+ }
+
+ return RFAL_ERR_NONE;
+}
+
+
+/*******************************************************************************/
+ReturnCode rfalDpoTableRead( rfalDpoEntry* tblBuf, uint8_t tblBufEntries, uint8_t* tableEntries )
+{
+ /* Wrong request */
+ if( (tblBuf == NULL) || (tblBufEntries < gRfalDpo.tableEntries) || (tableEntries == NULL) )
+ {
+ return RFAL_ERR_PARAM;
+ }
+
+ /* Not properly initialized */
+ if( gRfalDpo.currentDpo == NULL )
+ {
+ return RFAL_ERR_WRONG_STATE;
+ }
+
+ /* Copy the whole Table to the given buffer */
+ RFAL_MEMCPY( tblBuf, gRfalDpo.currentDpo, (tblBufEntries * RFAL_DPO_TABLE_PARAM_LEN) );
+ *tableEntries = gRfalDpo.tableEntries;
+
+ return RFAL_ERR_NONE;
+}
+
+
+/*******************************************************************************/
+ReturnCode rfalDpoAdjust( void )
+{
+ uint8_t refValue;
+ uint16_t modeID;
+ rfalBitRate br;
+ rfalMode mode;
+ uint8_t tableEntry;
+ const rfalDpoEntry* dpoTable;
+
+ /* Initialize local vars */
+ tableEntry = gRfalDpo.tableEntry;
+ dpoTable = gRfalDpo.currentDpo;
+ refValue = 0;
+ mode = RFAL_MODE_NONE;
+ br = RFAL_BR_KEEP;
+
+ /* Obtain RFAL's current mode and bit rate */
+ mode = rfalGetMode();
+ rfalGetBitRate( &br, NULL );
+
+
+ /* Check if the Power Adjustment is disabled and *
+ * if the callback to the measurement method is properly set */
+ if( (!gRfalDpo.enabled) || (gRfalDpo.measureCallback == NULL) || (gRfalDpo.adjustCallback == NULL) )
+ {
+ return RFAL_ERR_PARAM;
+ }
+
+ /* Ensure that the current mode is Passive Poller and table is initialized*/
+ if( (!rfalIsModePassivePoll( mode )) || (gRfalDpo.currentDpo == NULL) )
+ {
+ return RFAL_ERR_WRONG_STATE;
+ }
+
+ /* Ensure a proper measure reference value */
+ if( RFAL_ERR_NONE != gRfalDpo.measureCallback( &refValue ) )
+ {
+ return RFAL_ERR_IO;
+ }
+
+ /* Store last measurement */
+ gRfalDpo.refMeasurement = refValue;
+
+
+ if( refValue >= dpoTable[gRfalDpo.tableEntry].inc )
+ { /* Increase the output power */
+ /* the top of the table represents the highest amplitude value*/
+ if( gRfalDpo.tableEntry == 0U )
+ {
+ /* Maximum driver value has been reached */
+ }
+ else
+ {
+ /* Go up in the table to decrease the driver resistance */
+ tableEntry--;
+ }
+ }
+ else if( refValue <= dpoTable[gRfalDpo.tableEntry].dec )
+ { /* Decrease the output power */
+ /* The bottom is the highest possible value */
+ if( (gRfalDpo.tableEntry + 1U) >= gRfalDpo.tableEntries )
+ {
+ /* minimum driver value has been reached */
+ }
+ else
+ {
+ /* Go down in the table to increase the driver resistance */
+ tableEntry++;
+ }
+ }
+ else
+ {
+ /* Fall through to evaluate whether to write dpo and its associated analog configs */
+ }
+
+ /* Apply new configs if there was a change on DPO level or RFAL mode|bitrate */
+ /* Also adjust power in case mode is not yet set and a different table entry|setting is applicable */
+ if( (mode != gRfalDpo.curMode) || (br != gRfalDpo.curBR) || (tableEntry != gRfalDpo.tableEntry) || ((mode == RFAL_MODE_NONE) && (tableEntry != gRfalDpo.tableEntry)) || (gRfalDpo.forceAdj) )
+ {
+ /* Update local context */
+ gRfalDpo.curMode = mode;
+ gRfalDpo.curBR = br;
+ gRfalDpo.tableEntry = tableEntry;
+ gRfalDpo.forceAdj = false;
+
+ /* Get the new value from the table (e.g. RFO resistance) and apply the new setting */
+ gRfalDpo.adjustCallback( dpoTable[gRfalDpo.tableEntry].rfoRes );
+
+ /* Apply the DPO Analog Config according to this threshold */
+ /* Technology field is being extended for DPO: 2msb are used for threshold step (only 4 allowed) */
+ modeID = rfalAnalogConfigGenModeID( gRfalDpo.curMode, gRfalDpo.curBR, RFAL_ANALOG_CONFIG_DPO ); /* Generate Analog Config mode ID */
+ modeID |= (((uint16_t)gRfalDpo.tableEntry << RFAL_DPO_ANALOGCONFIG_SHIFT) & RFAL_DPO_ANALOGCONFIG_MASK); /* Add DPO threshold step|level */
+ rfalSetAnalogConfig( modeID ); /* Apply DPO Analog Config */
+ }
+
+ return RFAL_ERR_NONE;
+}
+
+
+/*******************************************************************************/
+void rfalDpoSetEnabled( bool enable )
+{
+ gRfalDpo.enabled = enable;
+ gRfalDpo.forceAdj = enable;
+ gRfalDpo.curMode = RFAL_MODE_NONE;
+ gRfalDpo.curBR = RFAL_BR_KEEP;
+ gRfalDpo.tableEntry = 0;
+ gRfalDpo.refMeasurement = 0;
+}
+
+
+/*******************************************************************************/
+bool rfalDpoIsEnabled( void )
+{
+ return gRfalDpo.enabled;
+}
+
+
+/*******************************************************************************/
+void rfalDpoReqAdj( void )
+{
+ gRfalDpo.forceAdj = true;
+}
+
+
+/*******************************************************************************/
+ReturnCode rfalDpoGetInfo( rfalDpoInfo* info )
+{
+ if( info == NULL )
+ {
+ return RFAL_ERR_PARAM;
+ }
+
+ /* Clear info structure */
+ RFAL_MEMSET( info, 0, sizeof(rfalDpoInfo) );
+
+ info->enabled = gRfalDpo.enabled;
+ info->tableEntries = gRfalDpo.tableEntries;
+ info->tableEntry = gRfalDpo.tableEntry;
+ info->adjustCallback = gRfalDpo.adjustCallback;
+ info->measureCallback = gRfalDpo.measureCallback;
+ info->refMeasurement = gRfalDpo.refMeasurement;
+
+ return RFAL_ERR_NONE;
+}
+
+
+#endif /* RFAL_FEATURE_DPO */
### core/embed/io/nfc/st25/rfal002/source/rfal_iso15693_2.c
[binary or diff unavailable]
### core/embed/io/nfc/st25/rfal002/source/rfal_iso15693_2.h
[binary or diff unavailable]
### core/embed/io/nfc/st25/rfal002/source/rfal_isoDep.c
[binary or diff unavailable]
### core/embed/io/nfc/st25/rfal002/source/rfal_nfc.c
[binary or diff unavailable]
### core/embed/io/nfc/st25/rfal002/source/rfal_nfcDep.c
[binary or diff unavailable]
### core/embed/io/nfc/st25/rfal002/source/rfal_nfca.c
[binary or diff unavailable]
### core/embed/io/nfc/st25/rfal002/source/rfal_nfcb.c
[binary or diff unavailable]
### core/embed/io/nfc/st25/rfal002/source/rfal_nfcf.c
[binary or diff unavailable]
### core/embed/io/nfc/st25/rfal002/source/rfal_nfcv.c
[binary or diff unavailable]
### core/embed/io/nfc/st25/rfal002/source/rfal_st25tb.c
[binary or diff unavailable]
### core/embed/io/nfc/st25/rfal002/source/rfal_st25xv.c
[binary or diff unavailable]
### core/embed/io/nfc/st25/rfal002/source/rfal_t1t.c
[binary or diff unavailable]
### core/embed/io/nfc/st25/rfal002/source/rfal_t2t.c
[binary or diff unavailable]
### core/embed/io/nfc/st25/rfal002/source/rfal_t4t.c
[binary or diff unavailable]
### core/embed/io/nfc/st25/rfal002/source/st25r3916/rfal_analogConfigTbl.h
[binary or diff unavailable]
### core/embed/io/nfc/st25/rfal002/source/st25r3916/rfal_dlmaTbl.h
[binary or diff unavailable]
### core/embed/io/nfc/st25/rfal002/source/st25r3916/rfal_dpoTbl.h
[binary or diff unavailable]
### core/embed/io/nfc/st25/rfal002/source/st25r3916/rfal_features.h
[binary or diff unavailable]
### core/embed/io/nfc/st25/rfal002/source/st25r3916/rfal_rfst25r3916.c
[binary or diff unavailable]
### core/embed/io/nfc/st25/rfal002/source/st25r3916/st25r3916.c
[binary or diff unavailable]
### core/embed/io/nfc/st25/rfal002/source/st25r3916/st25r3916.h
[binary or diff unavailable]
### core/embed/io/nfc/st25/rfal002/source/st25r3916/st25r3916_aat.c
[binary or diff unavailable]
### core/embed/io/nfc/st25/rfal002/source/st25r3916/st25r3916_aat.h
[binary or diff unavailable]
### core/embed/io/nfc/st25/rfal002/source/st25r3916/st25r3916_com.c
[binary or diff unavailable]
### core/embed/io/nfc/st25/rfal002/source/st25r3916/st25r3916_com.h
[binary or diff unavailable]
### core/embed/io/nfc/st25/rfal002/source/st25r3916/st25r3916_irq.c
[binary or diff unavailable]
### core/embed/io/nfc/st25/rfal002/source/st25r3916/st25r3916_irq.h
[binary or diff unavailable]
### core/embed/io/nfc/st25/rfal002/source/st25r3916/st25r3916_led.c
[binary or diff unavailable]
### core/embed/io/nfc/st25/rfal002/source/st25r3916/st25r3916_led.h
[binary or diff unavailable]Why this scored 32/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.