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.
49 lines
1.1 KiB
C
49 lines
1.1 KiB
C
#pragma once
|
|
|
|
#define RCTX_SIZE_LARGE 960
|
|
#define RCTX_SIZE_SMALL 320
|
|
#define MAX_HDRSIZE sizeof(struct openpcd_hdr)
|
|
|
|
#include <stdint.h>
|
|
|
|
#define __ramfunc
|
|
|
|
enum req_ctx_state {
|
|
RCTX_S_FREE,
|
|
/* USB -> UART */
|
|
RCTX_S_USB_RX_BUSY,
|
|
RCTX_S_MAIN_PROCESSING,
|
|
RCTX_S_UART_TX_PENDING,
|
|
RCTX_S_UART_TX_BUSY,
|
|
/* UART -> USB */
|
|
RCTX_S_UART_RX_BUSY,
|
|
RCTX_S_USB_TX_PENDING,
|
|
RCTX_S_USB_TX_BUSY,
|
|
/* number of states */
|
|
RCTX_STATE_COUNT
|
|
};
|
|
|
|
struct req_ctx {
|
|
/* enum req_ctx_state */
|
|
volatile uint32_t state;
|
|
#ifdef REQ_CTX_LISTS
|
|
/* pointers for queues */
|
|
volatile struct req_ctx *prev, *next;
|
|
#endif
|
|
/* size of th 'data' buffer */
|
|
uint16_t size;
|
|
/* total number of used bytes in buffer */
|
|
uint16_t tot_len;
|
|
/* index into the buffer, user specific */
|
|
uint16_t idx;
|
|
/* actual data buffer */
|
|
uint8_t *data;
|
|
};
|
|
|
|
extern struct req_ctx __ramfunc *req_ctx_find_get(int large, uint32_t old_state, uint32_t new_state);
|
|
extern struct req_ctx *req_ctx_find_busy(void);
|
|
extern void req_ctx_set_state(struct req_ctx *ctx, uint32_t new_state);
|
|
extern void req_ctx_put(struct req_ctx *ctx);
|
|
extern uint8_t req_ctx_num(struct req_ctx *ctx);
|
|
unsigned int req_ctx_count(uint32_t state);
|