|
cryptnox-sdk-esp32 1.0.0
ESP32 SDK for Cryptnox Hardware Wallet
|
CW_NfcTransport implementation backed by the ESP-IDF PN532 driver. More...
#include <Pn532NfcTransport.h>
Public Member Functions | |
| Pn532NfcTransport (pn532_t *dev, CW_Logger &logger) | |
| Construct the transport adapter. | |
| bool | begin () override |
| Configure the PN532 SAM and prepare it to accept card commands. | |
| bool | inListPassiveTarget () override |
| Scan for a passive ISO 14443-A card. | |
| bool | sendAPDU (const uint8_t *apdu, uint8_t apduLen, uint8_t *response, uint8_t &responseLen) override |
| Exchange one ISO-DEP APDU with the selected card (short response). | |
| bool | sendAPDULarge (const uint8_t *apdu, uint8_t apduLen, uint8_t *response, uint16_t &responseLen) override |
| Exchange one ISO-DEP APDU with the selected card (large response). | |
| void | resetReader () override |
| Release the currently selected NFC target. | |
| bool | printFirmwareVersion () override |
| Query and log the PN532 firmware version. | |
| ~Pn532NfcTransport () override | |
| Default destructor. | |
Private Attributes | |
| pn532_t * | m_dev |
| PN532 device handle (not owned; must outlive this object). | |
| CW_Logger & | m_logger |
| Logger for printFirmwareVersion output. | |
CW_NfcTransport implementation backed by the ESP-IDF PN532 driver.
Delegates every NFC operation to the C-level PN532 NFC driver via a pn532_t handle supplied by the caller. The handle's lifetime must exceed the lifetime of this object.
Both sendAPDU (response ≤ 255 bytes, uint8_t length) and sendAPDULarge (response ≤ 65535 bytes, uint16_t length) are implemented; both ultimately call pn532_send_apdu — the difference is only in the type used to report the response length back to the caller.
CW_Logger &) and a raw pointer (pn532_t *) that cannot be transferred safely.Definition at line 80 of file Pn532NfcTransport.h.
| Pn532NfcTransport::Pn532NfcTransport | ( | pn532_t * | dev, |
| CW_Logger & | logger ) |
Construct the transport adapter.
| [in] | dev | Pointer to an already-initialised pn532_t handle. Must remain valid for the lifetime of this object. |
| [in] | logger | Logger used by printFirmwareVersion. |
Definition at line 22 of file Pn532NfcTransport.cpp.
|
inlineoverride |
Default destructor.
Definition at line 173 of file Pn532NfcTransport.h.
|
override |
Configure the PN532 SAM and prepare it to accept card commands.
Calls pn532_sam_config. Must succeed before inListPassiveTarget or any APDU exchange is attempted. Called automatically by CryptnoxWallet::begin().
true if the PN532 acknowledged SAMConfiguration, false otherwise. Definition at line 27 of file Pn532NfcTransport.cpp.
References m_dev, and pn532_sam_config().
|
override |
Scan for a passive ISO 14443-A card.
Calls pn532_read_passive_target_id with the ISO 14443-A baud-rate selector.
true if at least one card was found in the RF field, false if no card is present or a communication error occurred. Definition at line 33 of file Pn532NfcTransport.cpp.
References m_dev, PN532_MIFARE_ISO14443A, and pn532_read_passive_target_id().
|
override |
Query and log the PN532 firmware version.
Calls pn532_get_firmware_version and prints a human-readable version string ("PN5xx firmware vX.Y") via the injected logger.
true if the PN532 returned a non-zero version, false on communication failure. Definition at line 61 of file Pn532NfcTransport.cpp.
References m_dev, m_logger, PN532_BYTE_MASK, PN532_FW_IC_SHIFT, PN532_FW_REV_SHIFT, PN532_FW_VER_SHIFT, and pn532_get_firmware_version().
Referenced by app_main().
|
override |
Release the currently selected NFC target.
Calls pn532_release_target so the PN532 drops its logical link to the card and is ready for the next inListPassiveTarget call.
Definition at line 56 of file Pn532NfcTransport.cpp.
References m_dev, and pn532_release_target().
|
override |
Exchange one ISO-DEP APDU with the selected card (short response).
Use this overload when the card's DataOut is guaranteed to fit in a uint8_t (≤ 255 bytes). For larger responses — such as the manufacturer certificate — use sendAPDULarge.
| [in] | apdu | APDU command bytes (must not be NULL). |
| [in] | apduLen | Length of apdu in bytes (≤ PN532_MAX_APDU_LEN). |
| [out] | response | Caller-allocated buffer for the DataOut bytes. |
| [in,out] | responseLen | In: capacity of response. Out: number of DataOut bytes written, capped at UINT8_MAX on overflow. |
true on a successful APDU exchange, false otherwise.Definition at line 39 of file Pn532NfcTransport.cpp.
References m_dev, and pn532_send_apdu().
|
override |
Exchange one ISO-DEP APDU with the selected card (large response).
Identical to sendAPDU but uses a uint16_t response length, allowing DataOut up to 65535 bytes. Used for commands whose response can exceed 255 bytes (e.g. GET_MANUFACTURER_CERTIFICATE whose DataOut may be ~415 bytes and requires an extended PN532 frame).
| [in] | apdu | APDU command bytes (must not be NULL). |
| [in] | apduLen | Length of apdu in bytes (≤ PN532_MAX_APDU_LEN). |
| [out] | response | Caller-allocated buffer for the DataOut bytes. |
| [in,out] | responseLen | In: capacity of response in bytes. Out: number of DataOut bytes actually written. |
true on a successful APDU exchange, false otherwise.Definition at line 49 of file Pn532NfcTransport.cpp.
References m_dev, and pn532_send_apdu().
|
private |
PN532 device handle (not owned; must outlive this object).
Definition at line 176 of file Pn532NfcTransport.h.
Referenced by begin(), inListPassiveTarget(), Pn532NfcTransport(), printFirmwareVersion(), resetReader(), sendAPDU(), and sendAPDULarge().
|
private |
Logger for printFirmwareVersion output.
Definition at line 177 of file Pn532NfcTransport.h.
Referenced by Pn532NfcTransport(), and printFirmwareVersion().