modules/woz_nfc/src/pn532.c
openaliro/openaliro
Module

pn532.c

PN532 host-protocol driver. See pn532.h. OS-free: no Zephyr headers, no…

modules/woz_nfc/src/pn532.c19 documented symbols

Overview

PN532 host-protocol driver. See pn532.h. OS-free: no Zephyr headers, no allocation, no sleeping — waiting is delegated to the bus wait_ready op.

depends on pn532.h

API

Fvoid pn532_init(struct pn532 *p, const struct pn532_bus_ops *ops, void *ctx)

modules/woz_nfc/src/pn532.c:34

Initialize a PN532 instance with bus operations and opaque context; set default ACK and response timeouts and clear state.

Fstatic size_t build_frame(uint8_t cmd, const uint8_t *params, size_t params_len, uint8_t *out)

modules/woz_nfc/src/pn532.c:44

Build a normal information frame around TFI 0xD4 + cmd + params.

called by pn532_transact

Fstatic int find_start(const uint8_t *buf, size_t len, size_t *start)

modules/woz_nfc/src/pn532.c:67

Locate the 00 FF start code, tolerating leading preamble/idle bytes.

called by parse_frame

Fconst char *pn532_frame_error_name(enum pn532_frame_error error)

modules/woz_nfc/src/pn532.c:85

Return a human-readable name for a PN532 frame parsing error code: "none", "start-code", "lcs", "truncated", etc., or "unknown" for unrecognized codes.

Fstatic int frame_error(struct pn532 *p, enum pn532_frame_error error)

modules/woz_nfc/src/pn532.c:119

Record a frame parse error in the PN532 state and return PN532_ERR_FRAME; used to aggregate error details across parse steps.

called by parse_frame, pn532_in_data_exchange, pn532_transact

Fstatic int parse_frame(struct pn532 *p, const uint8_t *buf, size_t len, const uint8_t **payload, size_t *payload_len, bool *is_ack)

modules/woz_nfc/src/pn532.c:128

Parse one chip-to-host frame. On success *payload points at PD0 (the byte after TFI) inside buf and *payload_len counts PD0 onward. is_ack reports a bare ACK frame (no payload).

called by read_frame  ·  calls find_start, frame_error

Fstatic int read_frame(struct pn532 *p, uint8_t *buf, size_t read_len, const uint8_t **payload, size_t *payload_len, bool *is_ack, int timeout_ms)

modules/woz_nfc/src/pn532.c:210

read_len bounds how many bytes to clock out of the chip: PN532_ACK_READ_LEN for the ACK (kept tight, see pn532.h) and PN532_FRAME_BUF_SIZE for a response (over-read is fine and lets the transport stay length-agnostic).

called by pn532_transact  ·  calls parse_frame

Fint pn532_transact(struct pn532 *p, uint8_t cmd, const uint8_t *params, size_t params_len, uint8_t *resp, size_t resp_cap, size_t *resp_len, int response_timeout_ms)

modules/woz_nfc/src/pn532.c:225

One full command transaction: write frame, consume ACK, read response. resp receives the response payload after TFI and the echoed command byte. A negative response_timeout_ms uses the default from struct pn532.

called by pn532_comm_thru, pn532_get_firmware_version, pn532_in_data_exchange, pn532_in_release, pn532_list_passive_target_106a, pn532_rf_field, pn532_sam_configuration, pn532_set_retries  ·  calls build_frame, frame_error, read_frame

Fint pn532_get_firmware_version(struct pn532 *p, uint8_t out[4])

modules/woz_nfc/src/pn532.c:283

Request firmware version from the PN532 chip and receive 4-byte response (IC version, version, subversion, flags); return PN532_OK on success or error code on transaction failure or invalid response length.

calls pn532_transact

Fint pn532_sam_configuration(struct pn532 *p)

modules/woz_nfc/src/pn532.c:294

SAMConfiguration, normal mode: mandatory once after power-up.

calls pn532_transact

Fint pn532_rf_field(struct pn532 *p, bool on)

modules/woz_nfc/src/pn532.c:307

Enable or disable the PN532 RF field; return PN532_OK on success or error code if the command fails.

calls pn532_transact

Fint pn532_set_retries(struct pn532 *p, uint8_t atr, uint8_t psl, uint8_t passive)

modules/woz_nfc/src/pn532.c:315

RFConfiguration item 5: MxRtyATR, MxRtyPSL, MxRtyPassiveActivation.

calls pn532_transact

Fint pn532_set_rf_timeouts(struct pn532 *p, uint8_t atr_res_code, uint8_t retry_code)

modules/woz_nfc/src/pn532.c:323

RFConfiguration item 2: fATR_RES_Timeout and fRetryTimeout codes (timeout = 100 us * 2^(code - 1); 0x0B = 102 ms, 0x10 = 3.28 s).

calls pn532_transact

Fint pn532_write_register(struct pn532 *p, uint16_t addr, uint8_t value)

modules/woz_nfc/src/pn532.c:335

Write a single byte value to a PN532 register at the given 16-bit address; return PN532_OK on success or error code if the command fails.

calls pn532_transact

Fint pn532_comm_thru(struct pn532 *p, const uint8_t *tx, size_t tx_len, uint8_t *rx, size_t rx_cap, size_t *rx_len, int timeout_ms)

modules/woz_nfc/src/pn532.c:343

Raw transceive via InCommunicateThru. The frame goes out exactly as given (configure CIU_TX_MODE/CIU_RX_MODE first for CRC-less operation). Returns PN532_ERR_STATUS with last_status = PN532_STATUS_TIMEOUT when nothing answers — the expected outcome for a fire-and-forget ECP broadcast.

calls pn532_transact

Fint pn532_list_passive_target_106a(struct pn532 *p, struct pn532_target *out, int timeout_ms)

modules/woz_nfc/src/pn532.c:373

Poll for one ISO14443A target at 106 kbps (InListPassiveTarget, BrTy 0). Returns 1 with *out filled on activation, 0 when no target answered.

calls pn532_transact

Fint pn532_in_data_exchange(struct pn532 *p, uint8_t tg, const uint8_t *tx, size_t tx_len, uint8_t *rx, size_t rx_cap, size_t *rx_len, int timeout_ms)

modules/woz_nfc/src/pn532.c:423

One APDU round trip against an activated target. Handles ISO-DEP chaining in both directions: requests larger than PN532_XFER_CHUNK go out via the MI bit, and chained responses are reassembled into rx.

calls frame_error, pn532_transact

Fint pn532_in_release(struct pn532 *p)

modules/woz_nfc/src/pn532.c:502

Release all activated targets (InRelease 0).

calls pn532_transact

Fuint16_t pn532_crc_a(const uint8_t *data, size_t len)

modules/woz_nfc/src/pn532.c:516

ISO/IEC 14443-3 CRC_A (init 0x6363), appended little-endian on the wire.