Commit Graph

704 Commits

Author SHA1 Message Date
Kevin Redon d24e9bde26 DFU: re-enable UART after testing forced bootloader
The qmod does not have a separate force button as simtrace has.
Instead it check is TX and RX of UART are shorted using PIO.
If the pins are not set back to the UART peripheral, the TRACE/debug
console output will not work anymore.

Change-Id: Id434b49909d6395a2f93a00f39d2d770a5725466
2018-07-07 14:56:50 +02:00
Kevin Redon 2bdaa73aff UART: remove unused code
PutChar already takes care of enabling the IRQ

Change-Id: I63af5eba27c9a6f3e23412060028e817e4d9f233
2018-07-07 14:53:50 +02:00
Kevin Redon fcf2743552 UART: make IRQ/ISR enabling simpler
Change-Id: Id3742850eb5bac91559e0c2b4144bd7b1ae5b07b
2018-07-07 14:51:35 +02:00
Kevin Redon d44cb80bc5 DFU: disable configured console UART before starting main app
The DFU uses the UART peripheral (with IRQ/ISR) for the debug output
console. Before starting the main application we should make sure
this configuration is reset to avoid interference (particularly the
IRQ/ISR).
This is not too important though since the main application
reconfigures the UART for console output.
Other peripheral could also be disabled (e.g. all other PIO used
by DFU), but most of them also get configured by the main application.

Change-Id: I8234d1b85938ad6393094c08183f613ad09ee01b
2018-07-07 14:43:50 +02:00
Kevin Redon 9e29a3eb37 DFU: set stack pointer before starting main app
The stack size is fixed. The linker script puts the stack section
after the bss section. The initial stack pointer is not at the
end of the RAM (as often seen).
Thus the initial stack pointer address of the main application
is different than the one from DFU. When starting the main
application the stack pointer needs to be set to the new value.
If this is not done the main application stack may overwrite the
data in bss, even without exceeding the fixed stack size.

Change-Id: Ie354d603fe302d3d5bdfa9c31575411de722323b
2018-07-07 14:18:58 +02:00
Kevin Redon bf6b1b1a3e buffer: increase buffer size to 512 to cope with fast and long TPDUs
Change-Id: I194c90cf09306a982d80c5bf1222397af6e658a9
2018-07-04 17:55:20 +02:00
King Kévin 4cbdc7cf18 fix LED switching on/off
In the SIMtrace and QMOD schematics the LEDs are connected to +3.3V.
Thus to switch the LED on we need to set the pin low.

Change-Id: Id8cc27e6f0b6556ba5e7ea4d254dd0fe59042a0c
2018-07-04 17:55:20 +02:00
King Kévin 86f48fc962 minor style change: use ARRAY_SIZE
Change-Id: Ia5243c342535963a3800849cd5a7d183a510d2d6
2018-07-04 17:55:20 +02:00
King Kévin 1200a5228f sniffer: add waiting time WT update
the waiting time (WT) is used to detect timeouts (e.g. for
unresponsive card or just to signal an error/NAK). it is essential
to detect to timeout to end current data transfer (e.g. change state).
by default (after a reset) to timeout is 9600 ETU, but this can change
at two places:
- after the ATR using the value of TC2 (if present)
- after a PPS (only F is used, and not D)

because the timeout value can be larger than the 16-bit of the USART
TO register, an external variable needs to be used for the count down.

Change-Id: I9735660ffce161cec8d4e63fa60a66fc8ef57525
2018-07-04 17:55:20 +02:00
Kevin Redon fe763b7698 sniffing: decrease USB IRQ prioprity to prevent USART overrun
Handling the USB message queue is done in an ISR and take quite some time.
This can cause a USART/SIM sniffing buffer overrun, resulting in data loss.
By setting the USB IRQ lower than the USART IRQ, the USB ISR can be
interrupted (for short) and no data gets lost.

Change-Id: I870a0aa8e251bbb53249c54bfcaa45de5b5a9486
2018-07-04 17:55:20 +02:00
Kevin Redon c9bd715289 sniffing: fix procedure byte handling and make TPDU parsing more strict
Change-Id: If991152f11c4b864ab1386f21dc13c335e6b281f
2018-07-04 17:55:20 +02:00
Kevin Redon 35e8bdf879 sniffer: also send incomplete (e.g. timeout) data (PPS/ATR/TPDU)
Change-Id: Ib070aca181042b477f1ffec48d63dc56c1e4609a
2018-07-04 17:55:20 +02:00
Kevin Redon 709a431ab9 sniffing: move conversion convertion and flag processing from ISR to main loop to keep ISR fast and focus on data capture
Change-Id: Ieefa8a5f81dbcc12c1ad3059660dbffa0c1a4961
2018-07-04 17:55:20 +02:00
Kevin Redon 30f90a78fc console: drop data to be send when buffer is already full
don't wait for space to be available in the buffer since since would
prevent from processing non-console (e.g. debug) more important data

Change-Id: Ia625b09eb30bb7b43edd3989f697d8ef33200f28
2018-07-04 17:10:08 +02:00
Kevin Redon 7406337a7f sniffer: display F and D values frim PPS
Change-Id: I3641dcb6c24695a6d3dd3a1ee4333f56a07c99f0
2018-07-04 17:10:08 +02:00
Kevin Redon 6e3f1121e6 host USB: add host application to receive and display USB sniffing messages sent by firmware
Change-Id: Idefbf21e0bbd2a1e3647fe9aebaf88d1b62dae2d
2018-07-04 17:10:08 +02:00
Kevin Redon de97fd25bd sniffer USB: implement USB communication and send parsed messages
Change-Id: Ice7817480705f2124b08c1ff9a8826558b6d8b2b
2018-07-04 17:10:08 +02:00
Kevin Redon 012940f48e USB device: add USB message structure for sniffer communication
Change-Id: Id2c6f32ade2fec9b9ef91bd8c5e1fd195f2d7351
2018-07-04 17:10:08 +02:00
Kevin Redon e2f84f6a8b host USB: use central SIMtrace USB ID definition header
Change-Id: Id18e64fba0a2c308a8aef7d3865200bf0237cae9
2018-07-04 17:10:08 +02:00
Kevin Redon 4d6a4b949c host usb_util fix: used provided class, sub-class, and interfave when finding matching interfaces
Change-Id: Ibc06e751e6ca0f9e9a40d82c4eeddfb975240f91
2018-07-04 17:10:08 +02:00
Kevin Redon a1012b170a USB: add central file to define USB IDs, classes, and endpoints
Change-Id: Iba81f32a92c68a973e8e7adbc4c2a1064ba5290f
2018-07-04 17:10:06 +02:00
Kevin Redon 42bd026416 minor: fix typos in comment
Change-Id: I01b49e047a586dff449d4e134751108e391a8822
2018-07-04 16:33:00 +02:00
Kevin Redon 638cec820f sniff: add WT timeout detection using USART timeout (TC is not required)
Change-Id: I4ec6e812e7e1eb91005027d2e864fc315550d79c
2018-07-04 16:33:00 +02:00
Kevin Redon 00ec89d73f sniff: add TPDU parsing (TPDUs become APDUs on the upper layer)
Change-Id: I09d050d95bd2ab140fe6b4926a37278eb08cc347
2018-07-04 16:33:00 +02:00
Kevin Redon cf59919494 sniff: print parsed ATR and PPS; use red LED to show main application is running; use green LED to indicate activity (message parsed)
Change-Id: I8e906bdbf2c91e608757ae442dfb241f981b8f1e
2018-07-04 16:33:00 +02:00
Kevin Redon 11914d9658 LED: add short LED pulse blinking pattern
Change-Id: I0fdc2f902a3b92da6aa9b9c8500abae8a2f79447
2018-07-04 16:32:54 +02:00
Kevin Redon 3113e3d2e5 update_fidi: remove debug output since this function is called in time critical ISR
Change-Id: I08f407d407a18dae3f360ddc64769ddfaeb5b559
2018-07-04 14:29:28 +02:00
Kevin Redon 9def7631ba DFU: switch green LED on to indicate DFU mode, and red LED to indicate flashing activity
Change-Id: I8e34fd869ed94ad122d6a17f5a432f5a09b820bb
2018-07-04 14:29:28 +02:00
Kevin Redon ca9e4bf4ba board: fix LED pin definition
Change-Id: Ia6c80c0268dec708845e1dad281caaa42027f9db
2018-07-04 14:29:28 +02:00
Kevin Redon 8210ec3f62 DFU: remove force bootloader button debug message since the console is output message is not initialized yet
Change-Id: Ibea0105929a8dc38b43dacd9d1e576d7b51d0c6a
2018-07-04 14:29:28 +02:00
Kevin Redon 8fa6ff5979 sniffer: use ISR to store sniffed data in buffer, add ATR and PPS parsing, and PPS related FiDi update
Change-Id: I4b38ce1d80e370fda6aa181e959ba3f1286bb922
2018-07-04 14:29:28 +02:00
Kevin Redon 866d20b10e trace: increase watchdog for 500 to 2000 ms to provide more time handling buffered data
Change-Id: Iacd85525f05e692b44183bd4c4585b9e70865cfe
2018-07-04 14:29:28 +02:00
Kevin Redon 4fe99fad59 ISO7816: change update_fidi to use provided USART
Also disables write protection for USART register if required

Change-Id: I716f4bc3a22800cbce402b146f14ef8b2aab2a98
2018-07-04 14:29:28 +02:00
Kevin Redon 7be52ec1ce SIMtrace: enable interrupt on edge dection for SIM_RST pin to reset the sniffer ISO state
Change-Id: I92ff29abd6a8690dd033d8cf13ad0d1ff9740fe5
2018-07-04 14:29:28 +02:00
Kevin Redon a2b367633c SIMtrace: fix default SIM_RST pin state to allow phone controlled reset
Change-Id: I1942ec6bd499cb2e14f6d7699a2b2d9b4197e654
2018-07-04 14:29:28 +02:00
Kevin Redon 927ffb46eb SIMtrace: only enable main sniffing mode on SIMtrace board
Change-Id: Iff6ebb1d98aa0c31f6d78508afde8f1b05f0f85b
2018-07-04 14:29:28 +02:00
Kevin Redon d7a6de57d2 sniffer: add state definitions, improve IRQ handling, update pins configuration
Change-Id: I6b5dfd6d573ac122a60585a24c8a620642805ad5
2018-07-04 14:29:27 +02:00
Kevin Redon 353351ddf4 simtrace: add support for sniffing on both USART
Change-Id: I69eb458e7cb186c990e5d6fbc780f37fdd0cd884
2018-07-04 14:28:19 +02:00
Kevin Redon 4091d78c4b board: comment USART definitions and add corresponding IRQ numbers
Change-Id: I3c38e7d75bc7b511827c33af69e335e50d0b35d2
2018-07-04 14:28:19 +02:00
Kevin Redon ee62a9da56 simtrace: add dedicated power pins configuration for sniffing
Change-Id: Ie37edbae6ea42d2b0c2a30eb5590afd0be797d39
2018-07-04 14:28:17 +02:00
Kevin Redon 45ad62d8d4 sniff: use USART 0 instead of USART 1
Use USART 0 connected to the SIM card side to sniff the communication.
The card side can also measure ETU times.
Do proper pin initialization.
This code can already capture the ATR communication between phone and card.

Change-Id: I0597ec723cb2225540c89c3821b91d8a45adfcd6
2018-07-04 11:24:13 +00:00
Kevin Redon 2c4e2af21f SIMtrace board: comment and fix pin definition
Change-Id: Ic77ad5bf6c00c9122c6bb0e12b90e6c5406855fd
2018-07-04 11:24:13 +00:00
Kevin Redon 7b73462442 sniff mode: handle USART 1 RX interrupt to show sniffer data
Change-Id: I5504369aed39844b7cf21e5b3ccb542daa6b946e
2018-07-04 11:24:13 +00:00
Kevin Redon 36abece0b1 enable (empty) sniffer support for SIMtrace board
Change-Id: I51619135fd6f5423542f261e7d76bab1a5713e2b
2018-07-04 11:24:13 +00:00
Kevin Redon f9997e9d26 copy working cardem app to trace
because the applications share the board capabilities defined in
libboard/*/include/board.h and USB configurations are enabled according
to the previously defined capabilities in libcommon/source.usb.c, all
applications actually offer the same functions.
thus creating the trace application is only mainly a cosmetic change, as the
sniffer function will also be present and enabled in the cardem application.

Change-Id: I24b3500a0905cbd622507722280b3c7e7f188bde
2018-07-04 11:24:13 +00:00
Harald Welte 05cc7f6531 ringbuffer: Don't print/TRAC from ringbuffer
In commit eac1bec428 we start to use the
ringbuffer inside the console printing code.  As a result, we must not
use TRACE_*() or printf() from within ringbuffer.c code to avoid
infinite recursion.

Instead, let rbuf_write() return a negative return value in case the
ring buffer overflows.  This way, the callers (outside the
console/stdout code) can print an error message themselves.

Change-Id: Ib009f013be119dbad22fa2b7d60ec8dee59baee5
2018-07-04 04:42:22 +02:00
Harald Welte 46893451de echo all command characters entered on serial console
This is required to make python pexpect.fdexpect happy, as it
requires that all characters are echo-ed back in order to detect
when the output of a given command starts.

Change-Id: I73b24e43f6c8b86a2766aba67d8307c184448aa0
2018-07-03 22:30:30 +02:00
Harald Welte cb6e20596e contrib/jenkins.sh: Also run firmware tests + build-test host software
Change-Id: Ie53857164d0a21daac334057c5bafbfd9912bf4b
2018-07-01 16:33:25 +02:00
Harald Welte bb2eb19fb1 firmware/test: Add more include paths
Change-Id: I4287fbae6921ed0605265812df5d7243e8857864
2018-07-01 08:47:39 +02:00
Harald Welte 9d90d284ed Use system include <foo.h> notation for libosmocore headers
the curent local copies of libosmocore headers + source is a temporary
hack anyway. We should instead rely on a system-wide install of
libosmocore cross-compiled for arm-none-eabi.  But leave that as a
second (later) step beyond this patch.

Change-Id: Ia63fd842d45a2b404233b4326050e7eda0604cf0
2018-06-29 22:26:57 +02:00