Commit Graph

28 Commits

Author SHA1 Message Date
Harald Welte
ad43440d93 card_emu: Fix various compiler warnings by switch/default/break 2016-03-16 20:45:09 +01:00
Harald Welte
fcdd660fb1 card_emu: Don't de-reference a NULL variable 2016-03-02 10:33:58 +01:00
Harald Welte
dda7355306 card_emu: Only transmit NULL byte from the right state
The reader cannot accept a waiting time extension at any time. Rather,
it can only accept it if it is currently  waiting for a procedure byte.
2016-03-02 10:29:55 +01:00
Harald Welte
f1697e2dd9 card_emu: Only allocate a new buffer if needed in send_tpdu_header() 2016-03-02 10:28:54 +01:00
Harald Welte
acae412b2a explicitly inform card_emu once data to transmit has arrived 2016-03-02 10:27:58 +01:00
Harald Welte
54cb3d017f host_communication/card_emu: adapt to nwe req_ctx / queuing paradignm 2016-02-29 14:12:40 +01:00
Harald Welte
22bf67fc9c card_emu: Use \r\n instead of \n
When printing over the actual serial port (as opposed to the unit
tests) we need CR+LF, and not just LF.
2016-02-29 10:18:59 +01:00
Harald Welte
47ee283d14 card_emu_io_statechg(): properly determine edges from levels
The caller might not have edge triggering and just gives us the
current state.  we have to use that informtaion to determine the
edges when something is actually switched on or off.
2016-02-29 10:09:46 +01:00
Harald Welte
43f7949fe0 card_emu: Add TRACE_DEBUG once TPDU header is sent to USB 2016-02-29 10:06:54 +01:00
Harald Welte
8c49636127 card_emu.c: avoid re-defining update_fidi() symbol 2016-02-27 16:24:09 +01:00
Harald Welte
17db2f1112 card_emu: Fix PTS checksum verification
If the checksum doesn't match, the card should not apply any Fi/Di
changes, not respond anything and simply expect the next TPDU.
2016-02-26 09:48:57 +01:00
Harald Welte
4ba66d0098 implement forwarding of PTS/PPS from emulator to host PC + test case 2016-02-26 09:40:34 +01:00
Harald Welte
0ef96d5735 card_emu: Ensure the length is properly set on a TPDU header rctx 2016-02-25 00:09:17 +01:00
Harald Welte
f16b618755 card_emu: Fix the length checks for transmit beyond rctx->tot_len 2016-02-24 22:18:46 +01:00
Harald Welte
22cdf2af59 card_sim: fix passing handle to tc_etu_*() functions 2016-02-24 22:18:11 +01:00
Harald Welte
855ba9e168 card_emu: Ensure TX happens synchronously before state changes
we cannot first chage the state and then transmit the byte
asynchronously later, this introduces race conditions.  Do it
in-line by explicit calls to the UART Tx function.
2016-02-24 21:00:46 +01:00
Harald Welte
61bb30e4ea card_emu: Correctly handle SW after reader -> card data phase 2015-11-14 23:44:14 +01:00
Harald Welte
4d8046743e card_emu: Fix state transitions for both Rx and Tx data phase
We now use the P3 value to determine how many characters to
receive (in case of Reader->Card payload phase).
2015-11-14 23:05:13 +01:00
Harald Welte
b5288e8ac4 card_emu: Introduce new flush_rx_buffer() function and use it 2015-11-14 23:05:13 +01:00
Harald Welte
e7194abb9e card_emu: Ensure to re-set PTS state when coming out of reset 2015-11-14 23:05:10 +01:00
Harald Welte
52922ffa32 card_emu: Properly handle end of a procedure-byte carrying REQ_CTX
how we proceed changes depending on whether we should continue to
receive or transmit...
2015-11-14 20:59:56 +01:00
Harald Welte
05b41c62f6 card_emu: fix set_tpdu_state()
* don't enter a state we are already in
* enable the UART receiver not only when waiting for CLA, but also
  generally when we're waiting for more data from the reader
2015-11-14 20:58:48 +01:00
Harald Welte
2935b3c479 card_emu: detect end of TX data from CEMU_DATA_F_FINAL
When the USB host software sets this flag, we terminate the
TPDU transmission after the last character in this frame and
transition again to the WAIT_TPDU state.
2015-11-14 20:00:14 +01:00
Harald Welte
d79dc4f6f2 card_emu: Implement get_byte_pts() 2015-11-14 13:33:10 +01:00
Harald Welte
4c473dad30 card_emu: Fail with assert in case next_tpdu_state from wrong state 2015-11-14 13:32:05 +01:00
Harald Welte
612d65ad62 card_emu: Make update_fidi() void 2015-11-14 13:30:43 +01:00
Harald Welte
16cf408a49 card_emu.c: More comments about data structures 2015-11-11 19:02:48 +01:00
Harald Welte
9d3e38242c initial commit of more code towards card emulation
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.
2015-11-09 00:50:54 +01:00