pn532_apdu.c
Overview
@file pn532_apdu.c PN532 APDU command planner: parse ISO 7816-4 APDU structure (Case 1-4, short/extended), emit passthrough or fragmented transport frames, handle GetResponse for extended data retrieval.
depends on pn532_apdu.h
API
Cstruct parsed_apdu
Parsed APDU command: data_offset/data_length (position in input, size in bytes), le (response max size, 256/65536 if encoded as 0), extended (long form), has_data/has_le (flags).
Fstatic bool parse_apdu(const uint8_t *input, size_t length, struct parsed_apdu *parsed)
Parse APDU structure (ISO 7816-4 Case 1-4, short/extended form): identifies CLA/INS/P1/P2, optional Lc (data length) and data, optional Le (response length). Returns true on valid syntax, false otherwise.
woz_pn532_apdu_plan_initFint woz_pn532_apdu_plan_init(const uint8_t *input, size_t input_length, struct woz_pn532_apdu_plan *plan)
Parse an APDU and prepare its transport representation. Unsupported or malformed APDUs are deliberately passed through so the peer remains the authority that returns an ISO 7816 status word.
parse_apduFstatic int emit_passthrough(struct woz_pn532_apdu_plan *plan, uint8_t *output, size_t output_capacity, size_t *output_length)
Emit a passthrough (raw APDU command): copy input as-is. Returns 0 on success, -2 if buffer too small or already emitted.
woz_pn532_apdu_plan_nextFstatic int emit_get_response(struct woz_pn532_apdu_plan *plan, uint8_t *output, size_t output_capacity, size_t *output_length)
Emit a GetResponse command (00 C0 00 00 [Le]): copy input, adjust Le for extended if needed. Returns 0 on success, -2 if buffer too small or already emitted.
woz_pn532_apdu_plan_nextFstatic int emit_envelope(struct woz_pn532_apdu_plan *plan, uint8_t *output, size_t output_capacity, size_t *output_length, bool *more_internal)
Emit one chunk of an APDU command: fragments data if needed (WOZ_PN532_ENVELOPE_DATA_MAX per frame), sets more bit if more chunks follow, appends Le if this is the last chunk. Returns 0 on success, -2 if buffer too small or data exhausted.
woz_pn532_apdu_plan_nextFint woz_pn532_apdu_plan_next(struct woz_pn532_apdu_plan *plan, uint8_t *output, size_t output_capacity, size_t *output_length, bool *more_internal)
Emit the next wire APDU. more_internal is true only when the transport must consume a 9000 response and send another fragment before notifying Aliro.
emit_envelope, emit_get_response, emit_passthrough