cryptnox-sdk-esp32 1.0.0
ESP32 SDK for Cryptnox Hardware Wallet
Loading...
Searching...
No Matches
Pn532NfcTransport.cpp
Go to the documentation of this file.
1/*
2 * SPDX-License-Identifier: LGPL-3.0-or-later
3 * Copyright (c) 2026 Cryptnox SA
4 */
5
14
15#include "Pn532NfcTransport.h"
16
17static const uint32_t PN532_FW_IC_SHIFT = 24U;
18static const uint32_t PN532_FW_VER_SHIFT = 16U;
19static const uint32_t PN532_FW_REV_SHIFT = 8U;
20static const uint32_t PN532_BYTE_MASK = 0xFFU;
21
23 : m_dev(dev), m_logger(logger)
24{
25}
26
28{
29 bool result = pn532_sam_config(m_dev);
30 return result;
31}
32
34{
36 return result;
37}
38
39bool Pn532NfcTransport::sendAPDU(const uint8_t *apdu, uint8_t apduLen,
40 uint8_t *response, uint8_t &responseLen)
41{
42 uint16_t len = static_cast<uint16_t>(responseLen);
43 bool result = pn532_send_apdu(m_dev, apdu, apduLen, response, &len);
44 responseLen = static_cast<uint8_t>((len > static_cast<uint16_t>(UINT8_MAX))
45 ? static_cast<uint16_t>(UINT8_MAX) : len);
46 return result;
47}
48
49bool Pn532NfcTransport::sendAPDULarge(const uint8_t *apdu, uint8_t apduLen,
50 uint8_t *response, uint16_t &responseLen)
51{
52 bool result = pn532_send_apdu(m_dev, apdu, apduLen, response, &responseLen);
53 return result;
54}
55
60
62{
63 uint32_t version = pn532_get_firmware_version(m_dev);
64 bool result = (version != 0U);
65
66 if (result) {
67 m_logger.print("PN5");
68 m_logger.print(static_cast<uint8_t>((version >> PN532_FW_IC_SHIFT) & PN532_BYTE_MASK), HEX);
69 m_logger.print(" firmware v");
70 m_logger.print(static_cast<uint8_t>((version >> PN532_FW_VER_SHIFT) & PN532_BYTE_MASK));
71 m_logger.print('.');
72 m_logger.println(static_cast<uint8_t>((version >> PN532_FW_REV_SHIFT) & PN532_BYTE_MASK));
73 }
74
75 return result;
76}
static const uint32_t PN532_FW_VER_SHIFT
static const uint32_t PN532_FW_IC_SHIFT
static const uint32_t PN532_BYTE_MASK
static const uint32_t PN532_FW_REV_SHIFT
CW_NfcTransport adapter wrapping the ESP-IDF PN532 NFC driver.
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.
pn532_t * m_dev
PN532 device handle (not owned; must outlive this object).
Pn532NfcTransport(pn532_t *dev, CW_Logger &logger)
Construct the transport adapter.
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.
CW_Logger & m_logger
Logger for printFirmwareVersion output.
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).
uint32_t pn532_read_passive_target_id(pn532_t *dev, uint8_t cardbaudrate)
Scan for a passive ISO 14443-A card and return its UID.
Definition pn532.c:775
bool pn532_send_apdu(pn532_t *dev, const uint8_t *apdu, uint8_t apdu_len, uint8_t *response, uint16_t *response_len)
Exchange a single ISO-DEP APDU with the currently selected card.
Definition pn532.c:805
uint32_t pn532_get_firmware_version(pn532_t *dev)
Query the PN532 firmware version.
Definition pn532.c:718
bool pn532_sam_config(pn532_t *dev)
Configure the PN532's Security Access Module (SAM).
Definition pn532.c:752
#define PN532_MIFARE_ISO14443A
Baud-rate selector for ISO 14443-A (Mifare) cards passed to pn532_read_passive_target_id.
Definition pn532.h:54
bool pn532_release_target(pn532_t *dev)
Release the currently selected NFC target.
Definition pn532.c:875
Opaque-like runtime state for a single PN532 instance.
Definition pn532.h:141