|
cryptnox-sdk-arduino 1.0.0
Arduino library for Cryptnox Hardware Wallet
|
CW_NfcTransport implementation over the Adafruit_PN532 driver. More...
#include <PN532Adapter.h>
Public Member Functions | |
| PN532Adapter (CW_Logger &logger, uint8_t ssPin, SPIClass *theSPI=&SPI) | |
| Construct an adapter wired over hardware SPI. | |
| PN532Adapter (CW_Logger &logger, uint8_t clk, uint8_t miso, uint8_t mosi, uint8_t ss) | |
| Construct an adapter wired over bit-banged software SPI. | |
| PN532Adapter (CW_Logger &logger, uint8_t irqPin, uint8_t resetPin, TwoWire *wire=&Wire) | |
| Construct an adapter wired over I2C. | |
| PN532Adapter (CW_Logger &logger, uint8_t resetPin, HardwareSerial *uartSerial) | |
| Construct an adapter wired over UART. | |
| ~PN532Adapter () override | |
| Release the heap-allocated Adafruit_PN532 instance. | |
| PN532Adapter (const PN532Adapter &)=delete | |
| PN532Adapter & | operator= (const PN532Adapter &)=delete |
CW_NfcTransport interface | |
| bool | begin () override |
| Initialise the PN532 and probe its firmware version. | |
| bool | sendAPDU (const uint8_t *apdu, uint8_t apduLen, uint8_t *response, uint8_t &responseLen) override |
| Exchange one ISO-DEP APDU with the currently selected card. | |
| bool | sendAPDULarge (const uint8_t *apdu, uint8_t apduLen, uint8_t *response, uint16_t &responseLen) override |
| APDU exchange that can return more than 255 bytes. | |
| bool | inListPassiveTarget () override |
| Poll for a card in the field. | |
| void | resetReader () override |
| Reset the PN532 into a clean idle state. | |
| bool | printFirmwareVersion () override |
| Pretty-print the PN532 firmware version + supported features. | |
| Public Member Functions inherited from CW_NfcTransport | |
| virtual | ~CW_NfcTransport () |
Private Attributes | |
| CW_Logger * | _logger |
| Logger reference (non-owning). | |
| PN532Interface | _interface |
| Wiring variant the active constructor selected. | |
| Adafruit_PN532 * | _nfc |
| Owned Adafruit_PN532 driver instance. | |
CW_NfcTransport implementation over the Adafruit_PN532 driver.
Concrete transport the host integration constructs once per reader and passes by reference to CryptnoxWallet. The class owns the underlying Adafruit_PN532 instance (heap-allocated by the constructor matching the wiring, released by the destructor) — callers do not need to manage its lifetime.
Forwards each CW_NfcTransport call to the equivalent Adafruit_PN532 method, plus a bounds check on APDU length (HIGH-05) and an optional hex-dump of the response when CW_DEBUG_LOGGING is set.
Definition at line 86 of file PN532Adapter.h.
| PN532Adapter::PN532Adapter | ( | CW_Logger & | logger, |
| uint8_t | ssPin, | ||
| SPIClass * | theSPI = &SPI ) |
Construct an adapter wired over hardware SPI.
Uses the MCU's SPI peripheral; SCK/MOSI/MISO are fixed by the SPI block (D13/D11/D12 on the UNO R4). Only the slave-select pin is configurable.
| [in] | logger | Logger sink for debug and error output. |
| [in] | ssPin | GPIO connected to the PN532 SS / NSS pin. |
| [in] | theSPI | Optional SPI instance (defaults to the global SPI). |
Definition at line 22 of file PN532Adapter.cpp.
References _interface, _logger, and _nfc.
Referenced by operator=(), and PN532Adapter().
| PN532Adapter::PN532Adapter | ( | CW_Logger & | logger, |
| uint8_t | clk, | ||
| uint8_t | miso, | ||
| uint8_t | mosi, | ||
| uint8_t | ss ) |
Construct an adapter wired over bit-banged software SPI.
Use this when the hardware SPI peripheral is already taken by another device. Any four GPIOs work; throughput is significantly lower than hardware SPI.
| [in] | logger | Logger sink. |
| [in] | clk | GPIO for SPI clock. |
| [in] | miso | GPIO for MISO (PN532 → MCU). |
| [in] | mosi | GPIO for MOSI (MCU → PN532). |
| [in] | ss | GPIO for slave-select. |
Definition at line 27 of file PN532Adapter.cpp.
References _interface, _logger, and _nfc.
| PN532Adapter::PN532Adapter | ( | CW_Logger & | logger, |
| uint8_t | irqPin, | ||
| uint8_t | resetPin, | ||
| TwoWire * | wire = &Wire ) |
Construct an adapter wired over I2C.
Requires the PN532 SEL0/SEL1 jumpers to be set to I2C and external pull-ups on SDA/SCL (the PN532 breakouts from Adafruit include them).
| [in] | logger | Logger sink. |
| [in] | irqPin | GPIO connected to the PN532 IRQ line. |
| [in] | resetPin | GPIO connected to the PN532 RSTPDN line. |
| [in] | wire | Optional TwoWire instance (defaults to the global Wire). |
Definition at line 32 of file PN532Adapter.cpp.
References _interface, _logger, and _nfc.
| PN532Adapter::PN532Adapter | ( | CW_Logger & | logger, |
| uint8_t | resetPin, | ||
| HardwareSerial * | uartSerial ) |
Construct an adapter wired over UART.
The PN532 must be configured at 115200 baud by its SEL jumpers. UART is the slowest mode but tolerates long cable runs better than SPI/I2C.
| [in] | logger | Logger sink. |
| [in] | resetPin | GPIO connected to the PN532 RSTPDN line. |
| [in] | uartSerial | HardwareSerial connected to the PN532 TX/RX lines. |
Definition at line 37 of file PN532Adapter.cpp.
References _interface, _logger, and _nfc.
|
override |
Release the heap-allocated Adafruit_PN532 instance.
Definition at line 41 of file PN532Adapter.cpp.
References _nfc.
|
delete |
References PN532Adapter().
|
overridevirtual |
Initialise the PN532 and probe its firmware version.
Calls Adafruit_PN532::begin() then issues getFirmwareVersion() as a liveness check.
true if the reader responded to getFirmwareVersion(), false on a wiring fault or a dead module. Implements CW_NfcTransport.
Definition at line 48 of file PN532Adapter.cpp.
References _nfc.
|
overridevirtual |
Poll for a card in the field.
Single shot — returns immediately after one polling cycle. Callers typically invoke this in a loop with a small delay().
true if a card was selected, false otherwise. Implements CW_NfcTransport.
Definition at line 121 of file PN532Adapter.cpp.
References _nfc.
|
delete |
References PN532Adapter().
|
overridevirtual |
Pretty-print the PN532 firmware version + supported features.
Decodes the raw firmware-version word into IC type (0x32 = PN532), major/minor revision, and a feature flag set (MIFARE / ISO-DEP / FeliCa) and emits a tree-style summary to the logger.
true if the PN532 responded, false otherwise. Implements CW_NfcTransport.
Definition at line 129 of file PN532Adapter.cpp.
|
overridevirtual |
Reset the PN532 into a clean idle state.
Issues SAMConfig() which both clears any pending card session and arms the Secure Access Module. Called by CryptnoxWallet between retries so a stuck reader can recover without a hard reset.
Implements CW_NfcTransport.
Definition at line 125 of file PN532Adapter.cpp.
References _nfc.
|
overridevirtual |
Exchange one ISO-DEP APDU with the currently selected card.
Wraps Adafruit_PN532::inDataExchange() and adapts its semantics to the CW_NfcTransport contract: responseLen is in/out (capacity in, actual length out). The uint8_t apduLen already enforces the PN532's 255-byte ISO-DEP frame limit at the type level (HIGH-05).
When CW_DEBUG_LOGGING is set, dumps the response as a hex grid to the logger.
| [in] | apdu | APDU bytes (≤ 255). |
| [in] | apduLen | Length of apdu in bytes. |
| [out] | response | Response buffer (caller-allocated). |
| [in,out] | responseLen | In: capacity of response. Out: number of bytes actually written. |
true on a successful exchange, false on a PN532 / card communication failure. Implements CW_NfcTransport.
Definition at line 53 of file PN532Adapter.cpp.
|
overridevirtual |
APDU exchange that can return more than 255 bytes.
Uses Adafruit_PN532's inDataExchange16() (added by the Adafruit_PN532_extended_frame.patch) which parses both PN532 normal and extended frame formats — required by GET_MANUFACTURER_CERTIFICATE pages that exceed the 255-byte normal-frame ceiling on cards whose cert is ~411 bytes.
| [in] | apdu | APDU bytes (≤ 255). |
| [in] | apduLen | Length of apdu in bytes. |
| [out] | response | Response buffer (caller-allocated). |
| [in,out] | responseLen | In: capacity of response (up to ~436). Out: number of bytes actually written. |
true on a successful exchange, false on a PN532 / card communication failure or frame parse error. Reimplemented from CW_NfcTransport.
Definition at line 87 of file PN532Adapter.cpp.
|
private |
Wiring variant the active constructor selected.
Definition at line 237 of file PN532Adapter.h.
Referenced by PN532Adapter(), PN532Adapter(), PN532Adapter(), and PN532Adapter().
|
private |
Logger reference (non-owning).
Definition at line 236 of file PN532Adapter.h.
Referenced by PN532Adapter(), PN532Adapter(), PN532Adapter(), PN532Adapter(), printFirmwareVersion(), sendAPDU(), and sendAPDULarge().
|
private |
Owned Adafruit_PN532 driver instance.
Definition at line 238 of file PN532Adapter.h.
Referenced by begin(), inListPassiveTarget(), PN532Adapter(), PN532Adapter(), PN532Adapter(), PN532Adapter(), printFirmwareVersion(), resetReader(), sendAPDU(), sendAPDULarge(), and ~PN532Adapter().