Commit Graph

950 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
Kevin Redon 76c73aaa99 card_emu: use edge-triggered VCC ADC logic
Before this patch, we used to st ci->vcc_active depending on the
instantaneous ADC reading of VCC.  Is it > .5v, we claim VCC is active,
and if it's below, VCC is inactive.

With this patch we move to an edge triggered approach: Only change
ci->vcc_active if the previous reading was different from the current
reading.

FIXME: why?

Change-Id: I71b703162219484e43638f1f2f692e9dd554ef55
2021-06-01 18:38:25 +02:00
Harald Welte e33c2907bc jenkins.sh: build 'cardem' firmware also for simtrace board
Now that it is supported, we should also build + publish the related
binaries.

Change-Id: I9231503b865adc863959d74d98e7f24f83c293e9
2021-06-01 18:38:25 +02:00
Harald Welte 0f75d6ef1e simtrace board.h: Enable HAVE_CARDEM if we build the cardem firmware
likewise, enable HAVE_SNIFFER currently only if we build the sniffer
firmware.

It's been many years too long to finally get those all merged in one
firmware :(

Change-Id: Ib433f180746f75458a44f4988643465bd846b04b
2021-06-01 18:38:21 +02:00
Harald Welte c690a1f130 st2-cardem-pcsc: Use ATR of real card by default
Before this patch, we would always use either a hard-coded default
ATR from the source code, or we would use one that the user specified
on the command line.

The more sane default is to pass-through the real ATR of the card.

Change-Id: I75bf618a6b0d983727de4c2f19b4b48ec3e12af8
Closes: OS#5107
Requires: libosmocore.git 22117a7164012d6d88fc202cd63df79c6068484d
2021-04-25 21:30:47 +02:00
Harald Welte 8e6ba005d4 st2-cardem-pcsc: Fix goto-in-while mess
There's some code that wasnts to goto within the while loop, and there's
some other code that wants to goto after the while loop.  Don't jump
from outside the while loop into the while loop.

Change-Id: Ic2a94ad034dd259f15712687443b569f0d18ff3f
2021-04-25 21:30:47 +02:00
Harald Welte 206d613b4d contrib/jenkins.sh: Switch from rita -> ftp.osmocom.org
We should use service-aliases and not the primary host name, as
that makes migration between machines hard.

Change-Id: I34b18457268ae6f8ae3a053c5424210074a4d52e
2021-04-22 11:21:12 +02:00
Harald Welte 7b681981ea card_emu: Fix computation of waiting time
As we store the waiting time (WT) in 'etu', we must adjust the formula
from ISO 7816-3.  The 'Fi' component in the formula only exists to
compute clock cycles from the etu, which we don't need here.

Without this patch, the waiting time would be way too large (by a factor
of 372 in the default case).

Change-Id: Ia21bc7303f9b38834b5b1753983ed2a99bfc7d95
Related: OS#1704
2021-04-08 21:28:37 +00:00
Harald Welte e410842d8e card_emu: Fix USART timer, particularly in re-start situations
The existing code started the timer once (and expired once) but didn't
properly handle re-starting of the timer.  Neither did it handle
the 'half time expiration' case.  If we want to call a function after
half the WT expiring, we must of course program the hardware for half
the timeout, and not the full timeout...

Change-Id: Ia999d97f835c27597fcd1cf7ac78bac0ab9c98c1
Related: OS#1704
2021-04-08 21:28:37 +00: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 7f421ef014 card_emu: explicitly initialize PTS and TPDU states
Those are already initialized at various transitions of the master
7816 FSM, but let's properly initialize them at start-up, too.

Change-Id: I81b2a8ef3284559164700d94717e4ccf008f53df
2021-04-08 21:28:37 +00:00
Harald Welte a708ea1d99 card_emu: improve reset detection conditions
* enter ISO_S_WAIT_RST when RST is asserted
* enter ISO_S_WAIT_ATR only when we RST is released while in state ISO_S_WAIT_RST

Change-Id: I620333aa8d45561a8028b948955a27f667b58406
2021-04-08 21:28:37 +00:00
Harald Welte c1ffc8a603 iso7816_fidi: Add iso7816_3_ prefix to symbols; fix terminology
Fi/Di are not the index into the table, but the contents of the table
as resolved by Fi_index / Di_index.  Let's clarify the terminology.

Change-Id: If364e08e7c9a3a9707e6d54b9267c6a7c088e415
2021-04-08 21:28:37 +00:00
Harald Welte 79f0ea73a2 card_emu: Clarify and differentiate F/Fi/F_index/Fi_index
The ISO7816 spec terms are well-defined, let's not abuse them. We used
to consider "Fi" as the "index into the table of F values", while the
spec actually considers Fi as the initial value for F.

Let's make sure we use the terms quite clearly:
* Fi and Di are the initial values for F and D
* F*_index and D*_index are the indexes into the ISO7816-3 Tables

Furthermore, let's track Fi separately from F, as e.g. the waiting
time definition only considers Fi as indicated in the ATR, despite
an actually different F value might have been negotiated via PTS
meanwhile.

Change-Id: Ieb2425e8380a81b79df7b2bd072902994e9c3ee7
Related: OS##1704
2021-04-08 21:28:37 +00:00
Harald Welte 9454a062b5 card_emu: Rename fi to Fi and di to Di
As we will soon introduce the distinction between Fi and F, we should
use uppercase letters, as lower-case 'f' is defined in ISO7816-3 as
the frequency, which is different from the upper-case 'F'.

Change-Id: Iaede621551520576e9b9af878fa46fbc88e59c2a
2021-04-08 21:28:37 +00:00
Kevin Redon 6b7f8d142f make sim switch board specific
the simtrace board uses a bus switch not used on qmod and owhw to
switch the SIM between physical and virtual

Change-Id: Ieaf2ed4761fc3e04f33f9aac5c04a768c9a6f71e
Related: OS#1704
2021-04-08 21:28:37 +00:00
Harald Welte 9c95162d5c card_emu: waiting_time is stored in etu, not clocks.
The comment didn't reflect the source.  I checked all users and
the code consistently stores the waiting time in units of 'etu'.

Change-Id: I2bc4a7c19cee5fb487ad639ee48ecaea706f6172
2021-04-08 21:28:37 +00:00
Oliver Smith 878fadd74f firmware: disable stack protector by default
Disable stack protector for all boards/apps by default, not only
qmod-dfu. Use 'make STACK_PROTECTOR=1' to enable.

This was recommened by Eric:
"I'd argue that we do not want this in general, since it adds canaries
to all functions that deal with buffers, and therefore impacts the
overall timing in a non determinstic way depending on inlining and
optimizations, while contributing nothing in non debug builds."

Related: OS#5081
Change-Id: I30ad97f231ea5b401def650bc9adc7e9f2770df0
2021-04-08 12:04:47 +02:00
Oliver Smith 9e0e0ddd5a firmware: qmod-dfu: disable stack protector
Prevent build failure on debian 9, ubuntu 20.04, 20.10, where
bin/qmod-dfu-flash.elf does not fit the ROM.

Fixes: OS#5081
Change-Id: I9fffe4c323094679062428f41a4246b1c1b30ca2
2021-04-07 15:23:55 +02:00
Harald Welte 7a3d93682f Revert "add library providing ISO 7816-3 utilities"
This reverts commit 4a29f64cbe.

The code replicates to a large extent what is already present in iso7816_fidi.c
and I have serious doubts about the correctness of the computation in
its iso7816_3_calculate_wt() function.

Change-Id: I80dab4401d13306d573a6a35ce8729d2acc141e4
2021-04-06 02:17:38 +02:00
Harald Welte 01868775ba Revert "add ISO 7816-3 library to remsim project"
This reverts commit 4a58c08d67.

The code replicates to a large extent what is already present in iso7816_fidi.c
and I have serious doubts about the correctness of the computation in
its iso7816_3_calculate_wt() function.

Change-Id: I3f26da4e9aa8d7b0f4b4b7992269cf365a643ec7
2021-04-06 02:17:37 +02:00
Harald Welte 9ec3de9346 simtrace2-cardem-pcsc: Make it work again
* support Interrupt STATUS notifications
* use osmocom libusb abstraction
* use asynchronous URBs for interrupt + bulk

Change-Id: Ib04798572295f25477719124530b6584780c5b75
2021-04-05 20:37:00 +02:00
Kevin Redon b218cc38d0 minor add comments
this is just to better understand the flow

Change-Id: I045286836176da729cc8c863866d6f6aa3836592
2021-04-04 23:01:41 +02:00
Kevin Redon 50360e0706 rename PIN_PHONE_{CLK,IO} to PIN_USIM1_{CLK,IO}
While this differs from tha naming in the schematics ({CLK,IO}_PHONE),
this matches the naming scheme used for USIM2 and the naming on other
boards.

Change-Id: I486b14260faec897e8c8698c4b7987bf36492497
2021-04-04 23:00:54 +02:00
Kevin Redon 4a58c08d67 add ISO 7816-3 library to remsim project
Change-Id: I99f3fecbc00d2379c3a6dc457b047c6fee41c292
2021-04-04 21:02:27 +02:00
Kevin Redon 4a29f64cbe add library providing ISO 7816-3 utilities
this will become part of libosmocore since it it common to smart
card related projects (such as osmo-ccid-firmware)

Change-Id: I3d4c65d137fc4555fcb256443feadd1c695de73d
2021-04-04 21:02:10 +02:00
Kevin Redon debbf3c6fa cardem: currently simtrace does not support cardem
the SIMtrace board does not support the current card emulation
application because this uses a timer counter to handle the
timeouts, but on the SIMtrace board this is not connected to the
CLK signal

Change-Id: Idd09ea534179f0ede705573e1373dbd045c9828a
2021-04-04 18:06:51 +00:00
Eric Wild 0b1a3b4105 cardem: choose a more reasonable default ATR
PCSCd does not like invalid ATRs

Change-Id: I1eebfdc06be55931c2e80e2b515ac3a559737c38
2021-04-04 19:54:19 +02:00
Eric Wild 9316890a39 firmware: allow verbose builds
make V=1 can be used to echo all compilation commands, which is useful
because it allows IDEs to parse the gcc output in oder to properly index
the source files using the actual defines passed to the compiler.

Change-Id: I25c41dff89302a73ddd2a4aaba7cb14912fac3b8
2021-04-04 16:16:24 +00:00
Eric Wild 19cd3b0f71 firmware: do not allow undefined symbols
For some reason undefined symbols were downgraded to warnings, which
means building a firmware that calls missing functions  (= address zero)
was perfectly fine, which of course made development more exciting....

This applies to builtins, too, printf of one char gets downgraded to
putchar, which we don't have, so disable builtins.

Change-Id: I492f41ad4162b9d07b1881ae4aed019db2dff8b5
2021-04-04 16:16:24 +00:00
Kevin Redon a1579ff4b0 minor: use same LED pattern for cardem as other applications
Change-Id: I5608c3312b648c0d59f79338ef1f97b6fe08f5b9
2021-04-04 15:02:19 +00:00
Oliver Smith 62ad58ad56 contrib/prepare_upload.sh: fix cd problems
Call the script from the proper directory, and cd into the topdir on top
of the script. Fixes:
/build/contrib/jenkins.sh: line 71: contrib/prepare_upload.sh: No such file or directory

Related: OS#4413
Change-Id: Icbfaa5579aab887830ca90b24a2e322df8d98f4f
2021-03-08 08:37:06 +01:00
Oliver Smith 1031d9b884 firmware: create duplicate files for upload only
Don't create copies of firmware files with version strings appended in
the normal build. Only do this before uploading the firmware files.

I have verified that "make" before this change and
"make; contrib/prepare_upload.sh" after produce the same files.

Close: OS#4413
Change-Id: I118a4ff397a178281c26a6b98112fa66b6f049ab
2021-03-05 15:38:48 +01:00
Oliver Smith 199cd431f3 gitignore: add firmware/apps/*/usb_strings.txt.patched
Change-Id: Ic99a5ae69ed755e6f74a1392678dcf71ab69e0d8
2021-03-05 15:04:06 +01:00
Oliver Smith 90e351f4a7 host: use git-version-gen/tarball-v. from topdir
Use .tarball-version from the topdir, because it only gets written there
when generating the OBS package. Remove the duplicate git-version-gen
script and use the one from the topdir to generate a version string if
building from the git tree.

Related: OS#4413
Change-Id: I4b197a218ab44632ff182ffbd72e15c2b20db341
2021-03-05 12:41:22 +01:00
Oliver Smith 09c3d45d6e firmware/Makefile: fix UNKNOWN in OBS packages
Fix having the version set to UNKNOWN in all packages built by OBS. The
osmo-ci.git scripts generating the source packages to be built by OBS
generate a ".tarball-version" file with a version string like
"0.7.0.70-657c", but it did not get used because the path was wrong.

Related: OS#4413
Related: https://osmocom.org/projects/cellular-infrastructure/wiki/Git-version-gen
Change-Id: Ic0b06011a604beec7c1c907c2c6e4ae927456e2e
2021-03-05 12:41:22 +01:00
Oliver Smith 810ecc5374 d/source/format: new file
Fixes:
  dpkg-source: warning: no source format specified in debian/source/format, see dpkg-source(1)

Related: OS#4413
Change-Id: I4c474547233ebb87a1246b01fbd7ff8879921c21
2021-03-05 12:41:22 +01:00
Eric Wild 657cce1817 dfu: let the device reset itself
dfu flashing the ST12 was easy, but i was never able to
get ST34 into dfu mode. Changing the firmware so it resets
itself just like the octsim instead of starting a timer and
waiting for a reset from the host made it work every time for me.

Change-Id: Ida636ec925f40d6d56551f170150181350d03bbd
2021-01-29 11:02:27 +00:00
Harald Welte aadd995664 remove old pre-autoconf makefile
Change-Id: Icd519a69a5cb1950daa79df4d9864e8dea091289
2020-10-27 15:55:07 +01:00
Harald Welte 0bb58e0b3c Update README
it has been long out of date.

Change-Id: I1137f33c5647f4d57a44224ee7259f3496edf1c4
2020-10-27 15:55:07 +01:00
Harald Welte b1a56e0f77 rename simtrace2-remsim to simtrace2-cardem-pcsc
This renaming is to avoid any confusion with the osmo-remsim
project, living in its separate git repository.

The simtrace2-cardem-pcsc doesn't feature any 'remote' part.  Rather,
it emulates the SIM card interface towards the device/phone/modem,
and forwards it to a local PC/SC card reader.

Change-Id: Ic15f0a89964a72fe3ab7a5145a073720f6207e24
2020-10-27 15:48:37 +01:00
Harald Welte 80b8877a23 remove usb2udp
The UDP based forwarding really only ever was a quick hack to
demonstrate the capabilities.

Meanwhile, we've had the proper osmo-remsim project implemented,
which provides a much more reliable and comprehensive way of
managing SIM card emulation devices (SIMtrace2, sysmoQMOD, ...)
and collection of card readers (sysmoOCTSIM or any other PC/SC
supported readers).

Hence, remove the "UDP forwarding part.

Change-Id: Ia4b9447b95872b6e0dda6dca644f1ed4a87355a0
2020-10-27 15:48:35 +01:00
Leonard Hübner 1372aca28e remsim: adding cli argument to set the atr
Change-Id: I554b515e7954148f9ca5ba29417699da70b0945b
2020-10-27 15:34:36 +01:00
Harald Welte a124c1714e migrate from BSC_FD_* to OSMO_FD_*
Change-Id: I01c834537e18eacdd1658f88a4b4a6d4690d87a6
2020-10-18 22:32:24 +02:00
Harald Welte 3907085239 dfu: Save another 60 bytes by changing the way we print horizontal lines
Change-Id: I1660a04fb3e42200bc2fdd23aa114119620125a1
2020-08-16 15:51:14 +02:00
Harald Welte 9866c7373c dfu: Shrink code by 144 bytes (by not calling PIO_InitializeInterrupts)
We are not using any PIO interrupts from DFU mode.  It's only used in
the main application firmware (verified by "git grep PIO_ConfigureIt")

Change-Id: Id1447af519df3183061f3d3f156a8dd84789af16
2020-08-16 15:47:00 +02:00
Harald Welte 1afb70a69d firmware: fix builds with gcc stack smashing protection enabled
On Ubuntu 20.04 when builiding dpkg packages, even when cross-compiling
firmware, gcc stack smashing protection is enabled.  Let's provide what
is minimally required in order to sucessfully complete builds on such
platforms.

Change-Id: Ic2f68f16b0730e7b5db17c30effc29a2909d1997
Closes: OS#4687
2020-08-05 11:59:26 +02:00
Harald Welte 859f1b0974 Introduce support for asynchronous USB transmission
libosmo-simtrace2 traditionally had only supported blocking, synchronous
I/O, while other osmocom programs such as remsim-client used
asynchronous USB I/O.

Using async USB I/O for IRQ + IN transfers while using blocking I/O for
OUT transfers doesn't seem to work reliably, so we have to offer a way
to perform the OUT transfers generated within libosmo-simtrace2 in async
mode.

Change-Id: Ib8939bdb7f533cd20a34a30a97f12b782b9816c2
2020-05-25 23:00:20 +02:00
Oliver Smith 4e73aaeba8 contrib: integrate RPM spec
Remove OpenSUSE bug report link, set version to 0.0.0, make it build with CentOS 8 etc.

Related: OS#4550
Change-Id: I8595642bc07bf3044720942a0f1802448920cb50
2020-05-19 15:59:01 +02:00
Oliver Smith 45e34c69de contrib: import RPM spec
Copy the RPM spec file from:
https://build.opensuse.org/project/show/home:mnhauke:osmocom:nightly

Related: OS#4550
Change-Id: I47ae01afb38fb18c462bf73501b49d6dc5d9f57f
2020-05-19 15:58:59 +02:00