Commit Graph

20 Commits

Author SHA1 Message Date
Harald Welte 87c5bdf329 assert: Use printf_sync() to ensure printing of assert / panic
Change-Id: Icc202e60445d9be1cdcd61176db5ed1704d583e7
2021-06-01 18:38:25 +02:00
Harald Welte 752bc7f4b5 card_emu: Use USART timeout for waiting time
Instead of using the timer/counter peripheral to handle the waiting time
and corresponding timeout, the USART peripheral internal timeout
mechanism is used.

This is particularly important for the SIMtrace board since there
(contrary to other boards) the I/O signal is not wired to a TIO pin
of the timer/counter block, and hence Rx/Tx data cannot reset that
timer/counter.

As a result of this migration, cardem is now supported not only on
owhw + qmod, but also on the simtrace board.

The guts of this change have been lifted out of Change-Id
Ibcb2c8cace9137695adf5fb3de43566f7cfb93b5 by Kevin Redon, which was
unfortunately touching various different topics at the same time and
hence was split up. Some improvements are the introduction of the
ENABLE_TX_TIMER_ONLY mode, which avoids the USART interrupt handler
getting hammered with TXRDY between release of RST and start of the ATR.

Change-Id: Ibcb2c8cace9137695adf5fb3de43566f7cfb93b5
Related: OS#1704
2021-04-08 21:28:37 +00:00
Harald Welte f4a625be53 usb_buf: count number of elements in queue
This is in preparation for limiting the maximum queue length

Change-Id: I7cb184d7a1ccb519010a2f3e3295cc3a5fbf8052
Related: OS#4251
2019-12-14 21:50:59 +01:00
Harald Welte d401b12136 card_emu_tests: Cosmetic changes (re-order code; more comments)
Change-Id: I36aefc824187ee99d83a451d869b137c13334d91
2019-11-24 23:12:04 +01:00
Kevin Redon 7233cf803a initialize VCC, RST, and VCC with actual values
previously the card RST, VCC, and CLK signal states have been initialized with
default values corresponding to an inactive reader.
this worked fine for actual inactive readers since the default values match
and would be updated when the signal changes (edge detection).
but if the reader is in another state, card activation detection could fail.
this is fixed since the actual signal values are now used during initialisation.

at the same time I changed the variable type from uint8_t to boolean since they
have only two possible states, and understanding the actual state when coding
is simpler (no need to check which integer corresponds to which state).

this change has been successfully tested on the 2 slots of OWHW board.

Change-Id: Ie9245d75d48ae93d16f97897d4fa5ad6cd402e73
2019-11-14 19:54:17 +01:00
Kevin Redon ebe672e926 cardem: use TC_ETU to trigger ATR sending
this changes how ATR is handled.
the ATR is also printed when set (as important debug information).
the test is also updated to correspond to the new mechanism (
simulating the timeout before sending the ATR)

Change-Id: I69df797e2feadffa9f5f977cb71b69386cee7cd0
2018-07-30 15:02:35 +02:00
Harald Welte 25a9a80ff5 Convert to new generalized SIMTRACE2 USB protocol
The current protocol was card-emulation specific.  The new protocol is
generic/flexible enough to accommodate both tracing and card emulation,
as well as modem control and other future extensions.
2017-05-09 13:24:23 +02:00
Harald Welte 8e7fca3255 migrate from req_ctx to msgb
We now generalize the USB communiction and abandon the 'req_ctx'
structure inherited from openpcd.  Instead we use the libosmocore 'msgb'
structure to handle incoming and outgoing USB tranfers.  We also use
linuxlist-based msgb-queues for each endpoint.
2017-05-07 23:09:56 +02:00
Harald Welte a1cd0f31c8 fix compilation of card_emu_tests 2017-02-27 14:29:07 +01:00
Harald Welte d295b92192 ensure usb_msg_hdr contains raw message length
we want to ensure that the length of every (current or future) message
can be determined by looking at cardemu_usb_msg_hdr.msg_len, rather than
having a length that is relative to the respective specific command.
2016-03-18 21:01:36 +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 86d047b8f4 card_emu_test: Verify content of emulator->reader bytes 2016-02-25 00:26:17 +01:00
Harald Welte 0ab6fcd173 card_emu_tests: Verify context of USB request contexts
when the emulator has received some data, don't just check that
we see it coming up on teh USB side, but actually also check
the content of those messages
2016-02-25 00:08:22 +01:00
Harald Welte c043e64ef1 card_emu_tests: move test cases into functions 2016-02-24 23:26:55 +01:00
Harald Welte eef6c2a46c card_emu_test: Add test for card-TX (reader-RX) APDU 2016-02-24 22:19:03 +01:00
Harald Welte 6bf8c12b13 update card_emu_tests to recent card_emu changes 2016-02-24 21:04:08 +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 84ec252ff4 card_emu_test: test APDUs with both Rx and Tx data phase 2015-11-14 23:05:13 +01:00
Harald Welte b436286ed6 card_emu_tests: extend first TPDU test to sending PB + SW in response 2015-11-14 19:02:33 +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