cryptnox-sdk-esp32 1.0.0
ESP32 SDK for Cryptnox Hardware Wallet
Loading...
Searching...
No Matches
Pn532NfcTransport Class Reference

CW_NfcTransport implementation backed by the ESP-IDF PN532 driver. More...

#include <Pn532NfcTransport.h>

Inheritance diagram for Pn532NfcTransport:
[legend]
Collaboration diagram for Pn532NfcTransport:
[legend]

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_tm_dev
 PN532 device handle (not owned; must outlive this object).
CW_Logger & m_logger
 Logger for printFirmwareVersion output.

Detailed Description

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.

Note
Non-copyable: the class holds a reference (CW_Logger &) and a raw pointer (pn532_t *) that cannot be transferred safely.
See also
pn532_t
CW_NfcTransport
CryptnoxWallet
Examples
BasicUsage/main/main.cpp, Connect/main/main.cpp, Sign/main/main.cpp, UsdcSigning/main/main.cpp, and VerifyPin/main/main.cpp.

Definition at line 80 of file Pn532NfcTransport.h.

Constructor & Destructor Documentation

◆ Pn532NfcTransport()

Pn532NfcTransport::Pn532NfcTransport ( pn532_t * dev,
CW_Logger & logger )

Construct the transport adapter.

Parameters
[in]devPointer to an already-initialised pn532_t handle. Must remain valid for the lifetime of this object.
[in]loggerLogger used by printFirmwareVersion.

Definition at line 22 of file Pn532NfcTransport.cpp.

References m_dev, and m_logger.

◆ ~Pn532NfcTransport()

Pn532NfcTransport::~Pn532NfcTransport ( )
inlineoverride

Default destructor.

Definition at line 173 of file Pn532NfcTransport.h.

Member Function Documentation

◆ begin()

bool Pn532NfcTransport::begin ( )
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().

Returns
true if the PN532 acknowledged SAMConfiguration, false otherwise.

Definition at line 27 of file Pn532NfcTransport.cpp.

References m_dev, and pn532_sam_config().

◆ inListPassiveTarget()

bool Pn532NfcTransport::inListPassiveTarget ( )
override

Scan for a passive ISO 14443-A card.

Calls pn532_read_passive_target_id with the ISO 14443-A baud-rate selector.

Returns
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().

◆ printFirmwareVersion()

bool Pn532NfcTransport::printFirmwareVersion ( )
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.

Returns
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().

◆ resetReader()

void Pn532NfcTransport::resetReader ( )
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().

◆ sendAPDU()

bool Pn532NfcTransport::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).

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.

Parameters
[in]apduAPDU command bytes (must not be NULL).
[in]apduLenLength of apdu in bytes (≤ PN532_MAX_APDU_LEN).
[out]responseCaller-allocated buffer for the DataOut bytes.
[in,out]responseLenIn: capacity of response. Out: number of DataOut bytes written, capped at UINT8_MAX on overflow.
Returns
true on a successful APDU exchange, false otherwise.
See also
sendAPDULarge

Definition at line 39 of file Pn532NfcTransport.cpp.

References m_dev, and pn532_send_apdu().

◆ sendAPDULarge()

bool Pn532NfcTransport::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).

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).

Parameters
[in]apduAPDU command bytes (must not be NULL).
[in]apduLenLength of apdu in bytes (≤ PN532_MAX_APDU_LEN).
[out]responseCaller-allocated buffer for the DataOut bytes.
[in,out]responseLenIn: capacity of response in bytes. Out: number of DataOut bytes actually written.
Returns
true on a successful APDU exchange, false otherwise.
See also
sendAPDU

Definition at line 49 of file Pn532NfcTransport.cpp.

References m_dev, and pn532_send_apdu().

Member Data Documentation

◆ m_dev

pn532_t* Pn532NfcTransport::m_dev
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().

◆ m_logger

CW_Logger& Pn532NfcTransport::m_logger
private

Logger for printFirmwareVersion output.

Definition at line 177 of file Pn532NfcTransport.h.

Referenced by Pn532NfcTransport(), and printFirmwareVersion().


The documentation for this class was generated from the following files: