Commit Graph

447 Commits

Author SHA1 Message Date
Harald Welte 02d5096b31 add host .o and executables to .gitignore 2016-03-19 21:38:59 +01:00
Harald Welte 2315e6ba07 ensure git version ends up in firmware image 2016-03-19 21:37:55 +01:00
Harald Welte 236caf68eb remote-sim host tools: Auto-discover the endpoint addresses
We now auto-discover the end-point addresses based on the interface
descriptor.  The user can also use the new "--interface" command line
argument to set a non-zero intrerface.  In combination, this should
enable support for the remote-sim functionality on the second UART
on OWHW.
2016-03-19 21:28:09 +01:00
Harald Welte 095ac6cbe2 Add simtrace2-remsim applications 2016-03-19 13:52:31 +01:00
Harald Welte b26d0038f6 split/segment multiple commands from single USB transfer
UDP end-points are streams, so when we receive data on the OUT
endpoint callback, the buffer might contain several commands.  When
dispatching the messages, split (segment) them again before dispatching
them to their respective handlers.
2016-03-19 13:33:02 +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 b8f9450c18 shrink ringbuffer size to 128 bytes
We only use it to implemet a software FIFO between the UART Rx IRQ
and the code that processes it.  1k is way too large for that.
2016-03-18 10:33:31 +01:00
Harald Welte 9f240b6d34 use irq-safe version of llist operations between USB callback and main 2016-03-18 10:32:56 +01:00
Harald Welte da15ca01bf mode_cardemu: mask the USART status register with mask register
otherwise it might be reacting on stale bits in CSR, which actually are
no longer able to cause any interrupts.
2016-03-17 21:14:04 +01:00
Harald Welte 3d27c84635 host_comm: Fix race condition in handling OUT USB transfers 2016-03-17 20:07:45 +01:00
Harald Welte 250cd2c062 host_communication: set rctx->tot_len after receiving USB transfer 2016-03-17 18:19:39 +01:00
Harald Welte 372f4cc7ba board_lowlevel: Use LED definitions from board.h
... this is more portable.
2016-03-16 22:22:57 +01:00
Harald Welte 5820ea9327 dispatch_usb_command: Ensure list consistency + avoid mem leaks
When iterating over the queue of req_ctx, make sure to unlink each
buffer before processing it.  And during processing, ensure all buffers
are reelased back to the memory management.
2016-03-16 22:22:57 +01:00
Harald Welte 0eaa992682 cardem: Add support for USB host based set/clear of card_insert
This way the application on the USB host can control whether the
emulator should emulate that the card be inserted or not.  We change the
reset-default back to 'not inserted' (GPIO output 0) and wait for the
application to explicitly request this by issuing
CEMU_USB_MSGT_DT_CARDINSERT.
2016-03-16 22:22:57 +01:00
Harald Welte 7abdb51f8f ringbuffer: Make ring buffer access irq-save
We have to temporarily disable nterrupts when performing rinbuffer
operations, as the ring buffer is used both from IRQ as well as process
context.
2016-03-16 22:22:54 +01:00
Harald Welte 7dd3dfd992 convert all src_simtrace code to kernel coding style
Let's use the Osmocom standard, based on the Linux kernel standard:
tab-indent and 8-charracter tab width.
2016-03-16 20:45:10 +01:00
Harald Welte 1605564489 ensure USB config numbers always start from 1
Depending on which features (and thus USB configurations) are included
in the firmware, we need to re-define the ordering of the configuration
numbers, as the Atmel USBD driver simply assumes that configurations are
numbered 1..N without any gaps in the sequence.
2016-03-16 20:45:10 +01:00
Harald Welte 072daddf98 main.c: Only call the configure() function of a configuration if it exists 2016-03-16 20:45:10 +01:00
Harald Welte 40901a0f14 various printf/debug output improvements
... among those is a rotor (\|/-) that is printed by the main loop,
so one can observe if the main loop is still executing or the system
is somehow stuck.
2016-03-16 20:45:09 +01:00
Harald Welte 57b3a250d4 Add Card-Emulation for second UART/USIM to USB descriptors 2016-03-16 20:45:09 +01:00
Harald Welte 13e8202c81 mode_cardem: Prepare for full support of second UART/USIM
So far we have only been working with a single UART/USIM. Let's
make things more data structure driven and pass around handles to
the data structures rather than hardcoding...
2016-03-16 20:45:09 +01:00
Harald Welte 06b27f64a2 mode_cardemu: Implement CEMU_USB_MSGT_DT_SET_ATR
This way the host PC can set the ATR of the emulated card
2016-03-16 20:45:09 +01:00
Harald Welte ebb80eda19 introduce 'main' queue between USB receive and UART TX
In order to handle other USB commands like GET_STATUS, SET_ATR
or GET_STATS, we introduce an intermediary queue.  The USB receive
completion call-back puts the command on that intermediate 'main'
queue.  From that intermediate queue, the are further
dispatched/processed according to their mesage type.
2016-03-16 20:45:09 +01:00
Harald Welte ad43440d93 card_emu: Fix various compiler warnings by switch/default/break 2016-03-16 20:45:09 +01:00
Harald Welte 5e00400a05 board_lowlevel.c: Improve main oscillator initialization
* ensure the PB8/PB9 pins are actually not in GPIO mode, which they
  apparently are on boot-up
* ensure that neither pull-up nor pull-down are enabled on PB8/PB9
* ensure we first start the oscillator, before selecting it

The sum of the above changes seems to make oscillator start-up much more
reliable than before.  The time needed for initialization is now pretty
stable, and the occasional 15-20second clock stabiliziation has not been
observed with this change.
2016-03-16 20:45:09 +01:00
Harald Welte a0cf200695 host_communication: keep track of number of pending/queued req_ctx 2016-03-02 10:35:51 +01:00
Harald Welte acd48c51f2 HACK: always use the USART interrupt handler of mode_cardemu()
This must be fixed in a way that the per-configuration interrupt
handler is called, depending on the USB configuration that is set.
2016-03-02 10:34:24 +01:00
Harald Welte fcdd660fb1 card_emu: Don't de-reference a NULL variable 2016-03-02 10:33:58 +01:00
Harald Welte fde250a54b uart_console.c: Don't redefine constants from board.h 2016-03-02 10:33:11 +01:00
Harald Welte 715bc05f55 Increase serial console sped to 230400 bps
This makes debug printf's twice as fast (half as slow) and thus
has less of an impact on execution speed than the previous 115200
2016-03-02 10:31:59 +01:00
Harald Welte 12d4bdfbb1 mode_cardemu: Process RX interrupts before TX
It's always more important to pull out a received character from
the receive holding register to avoid the risk of overflow, so let's
do that first.
2016-03-02 10:31:03 +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 8a416b1812 mode_cardemu: fix ordering of events when switching rx/tx mode 2016-03-01 00:42:04 +01:00
Harald Welte 45688d4c3b mode_cardemu: Disable UART TXRDY generation if we don't have data to TX
When the ISO7816 state machine requires us to transmit something, but
we don't have data ready to transmit, we should switch off TXRDY
interrupt generation.

What's missing is of course the other part that re-enabls TXRDY
generation once new data is available
2016-02-29 21:35:38 +01:00
Harald Welte 349c54bc3b req_ctx: LF -> CR+LF 2016-02-29 21:35:24 +01:00
Harald Welte 22925ea707 test: Add TRACE_INFO and TRACE_ERROR definitions 2016-02-29 21:14:25 +01:00
Harald Welte 4678388c3c board_lowlevel: More comments about clock initialization 2016-02-29 19:45:59 +01:00
Harald Welte ebbb645f4b req_ctx: Fix allocation (allocate 1 block, not all) and call _init() 2016-02-29 17:57:51 +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 f672e9d63a req_ctx: Convert from hand-coded linked lists to linuxlist.h
This also removes the actual queuing code from req_ctx, and
leaves this to the caller.  Only tw out of the existing states actually
required the ordering requirement enforced by the qeue, and in the
future we will need to have per-endpoint queues anyway.  Both means it
is better to manage queues outside the req_ctx, and leve that as a pure
memory allocator.
2016-02-29 14:10:22 +01:00
Harald Welte b66ce249d0 req_ctx: Add better explanation about the various states 2016-02-29 14:07:07 +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 708d85c085 trace.h: Don't print file/function name in TRACE_DEBUG() 2016-02-29 10:16:05 +01:00
Harald Welte c0bd7f0aaa mode_cardemu: Move GPIO detection to IRQ, use ring buffer for UART RX
We don't want to call into the bulk of card_emu.c from interrupt
context, so let's introduce a ring buffer as a softwre-FIFO between
the USART receiving a byte and the processing of that byte in
card_emu.c, which is then performed from the main loop outside
interrupt context.
2016-02-29 10:13:33 +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 99f62a6def mode_cardemu: update_fidi just needs to execute
the actual translation of the Fi/Di values to the divider is
already made, we just need to update the USART divider here.
2016-02-29 10:08:49 +01:00
Harald Welte 2ad0ca15a8 host_communication: Fix TRACE_ERROR syntax 2016-02-29 10:07:16 +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