mirror of
https://gitea.osmocom.org/sim-card/simtrace2.git
synced 2026-03-17 21:58:33 +03:00
I couldn't help but to spend my sunday on working towards card emulation, including * various state machines in the target about ISO7816 states * tc_etu timer import from simtrace1 * req_ctx import from simtrace1 (needs renaming and simplifiation) * USB protocol description as cardemu_prot.h * some host-based testing code to test the state machines The code seems to work fine throughout card reset, sending ATR and receiving the TPDU header of the first APDU, up to the point where it marks the TPDU header as to-be-transmitted over th bulk-in endpoint. Sending the ATR must be done inside the firmware for timing requirements. From that point onwards, the host needs to respond at the very least with a procedure byte, and some indication whether or not the card emulator should continue to transmit data (card->reader), or receive data (reader->card). The code is intentionally not hooked up yet with the USB logic nor with the UART. I want host-based testing completed before doing that.
34 lines
980 B
C
34 lines
980 B
C
#pragma once
|
|
|
|
#include <stdint.h>
|
|
|
|
struct card_handle;
|
|
|
|
enum card_io {
|
|
CARD_IO_VCC,
|
|
CARD_IO_RST,
|
|
CARD_IO_CLK,
|
|
};
|
|
|
|
struct card_handle *card_emu_init(uint8_t slot_num, uint8_t tc_chan, uint8_t uart_chan);
|
|
|
|
/* process a single byte received from the reader */
|
|
void card_emu_process_rx_byte(struct card_handle *ch, uint8_t byte);
|
|
|
|
/* return a single byte to be transmitted to the reader */
|
|
int card_emu_get_tx_byte(struct card_handle *ch, uint8_t *byte);
|
|
|
|
/* hardware driver informs us that a card I/O signal has changed */
|
|
void card_emu_io_statechg(struct card_handle *ch, enum card_io io, int active);
|
|
|
|
/* User sets a new ATR to be returned during next card reset */
|
|
int card_emu_set_atr(struct card_handle *ch, const uint8_t *atr, uint8_t len);
|
|
|
|
|
|
#define ENABLE_TX 0x01
|
|
#define ENABLE_RX 0x02
|
|
|
|
int card_emu_uart_update_fidi(uint8_t uart_chan, unsigned int fidi);
|
|
int card_emu_uart_tx(uint8_t uart_chan, uint8_t byte);
|
|
void card_emu_uart_enable(uint8_t uart_chan, uint8_t rxtx);
|