Commit Graph

292 Commits

Author SHA1 Message Date
Harald Welte 62e18147cc fix compilation with gcc-11
/usr/lib/gcc/arm-none-eabi/11.3.1/../../../arm-none-eabi/bin/ld: cuart_driver_asf4_usart_async.o:/space/home/laforge/projects/git/osmo-ccid-firmware/sysmoOCTSIM/gcc/../atmel_start.h:15: multiple definition of `dma_m2m_complete_flag'; atmel_start.o:/space/home/laforge/projects/git/osmo-ccid-firmware/sysmoOCTSIM/gcc/../atmel_start.h:15: first defined here
/usr/lib/gcc/arm-none-eabi/11.3.1/../../../arm-none-eabi/bin/ld: command.o:/space/home/laforge/projects/git/osmo-ccid-firmware/sysmoOCTSIM/gcc/../atmel_start.h:15: multiple definition of `dma_m2m_complete_flag'; atmel_start.o:/space/home/laforge/projects/git/osmo-ccid-firmware/sysmoOCTSIM/gcc/../atmel_start.h:15: first defined here
/usr/lib/gcc/arm-none-eabi/11.3.1/../../../arm-none-eabi/bin/ld: main.o:/space/home/laforge/projects/git/osmo-ccid-firmware/sysmoOCTSIM/gcc/../atmel_start.h:15: multiple definition of `dma_m2m_complete_flag'; atmel_start.o:/space/home/laforge/projects/git/osmo-ccid-firmware/sysmoOCTSIM/gcc/../atmel_start.h:15: first defined here
/usr/lib/gcc/arm-none-eabi/11.3.1/../../../arm-none-eabi/bin/ld: stdio_start.o:/space/home/laforge/projects/git/osmo-ccid-firmware/sysmoOCTSIM/gcc/../atmel_start.h:15: multiple definition of `dma_m2m_complete_flag'; atmel_start.o:/space/home/laforge/projects/git/osmo-ccid-firmware/sysmoOCTSIM/gcc/../atmel_start.h:15: first defined here
/usr/lib/gcc/arm-none-eabi/11.3.1/../../../arm-none-eabi/bin/ld: usb_start.o:/space/home/laforge/projects/git/osmo-ccid-firmware/sysmoOCTSIM/gcc/../atmel_start.h:15: multiple definition of `dma_m2m_complete_flag'; atmel_start.o:/space/home/laforge/projects/git/osmo-ccid-firmware/sysmoOCTSIM/gcc/../atmel_start.h:15: first defined here

Change-Id: I9a72dc0101de84ce39530c1503b32620b4777b4a
2022-11-18 21:00:25 +01:00
Oliver Smith ca7d3ae864 contrib/jenkins.sh: skip upload if nothing new
The contrib/jenkins.sh script gets triggered daily. Do not upload new
files unless a new commit was added (then the filename changes).
Otherwise the binary and timestamp change on the server each day, which
is confusing and potentially makes catching regressions harder.

I've also considered disabling the daily trigger for this repository,
but I think it's better to keep it so we notice without much delay if
changes in libosmocore or the toolchain cause a build failure.

Change-Id: I3f70d6149b29ec2ff7f185dfae8bc8d4a1953dc2
2022-05-25 18:15:49 +02:00
Eric Wild 90343f9669 slot fsm: fake ccid setparameter response
This secretly disables the PPS exchange to set a different baud rate and
ensures proper multislot operation at the default rate @ 2.5Mhz.

Change-Id: I72bd2bbabe55c00e771626d2e473f6f8e88793d2
2021-12-08 20:32:59 +00:00
Eric Wild a6b35941d2 slot fsm: rearrange fsm cb events to make debugging easier
..and so I can break on the nop.

Change-Id: Idcf076ffbc3fd7698b49b611ac8057939105415b
2021-12-08 20:32:59 +00:00
Joachim Steiger 0ce251517a update test expectations to follow Change-Id: I5f39c0fe82cbfa6f2bc4b84784a7142b461b64fb
Change-Id: I0d4a072d18011ffb00d6251481473b19d5a97c50
2021-11-30 11:41:40 +01:00
Eric Wild 0f614167f9 jenkins: build libosmocore without logging
Depends-On: Ia4c78abe5f198139f96ffa289998855be2477585
Change-Id: I5e8ce681e557c41c920959e3651910203f1d527a
2021-11-30 07:43:04 +00:00
Eric Wild 06f7e92a04 7816 fsm: emphasize the inner workings of the static msgb macro
Change-Id: I37226d1fe2c14adb2b2d97608496dbb1661be543
2021-11-30 07:42:59 +00:00
Eric Wild 51b2facc66 debug usb-cdc uart: disable it.
Currently unused.

Change-Id: I5f39c0fe82cbfa6f2bc4b84784a7142b461b64fb
2021-11-27 14:30:00 +00:00
Eric Wild 648f6309c6 makefile: disable libosmocore logging functions
Change-Id: Ic4a55639cd5ace0ef8325d903b0a6b5b41781073
2021-11-27 14:25:46 +00:00
Eric Wild 2edf356c0a ccid usb handler: fix init flag
Change-Id: I2a1d13b26c578ce3a343e06c2756dd07befcdb7f
2021-11-27 14:25:43 +00:00
Eric Wild 38ac3839b9 sim slots: omit interrupt disabling for status polling
Doesn't matter here, we don't care if we get interrupted.

Change-Id: I8f32ad446438ef7776cc8a4aac1946f1a39a8ceb
2021-11-27 14:25:18 +00:00
Eric Wild 30c26f4ec5 remove unused dmac
Change-Id: I9646220d9864fd8ddc133da58151227c24546cc6
2021-09-27 18:35:00 +02:00
Eric Wild eda2b3e270 proper xosc startup delay
Change-Id: I5063b43cd3973b66963fc946c019f32a0281d1a6
2021-09-27 18:35:00 +02:00
Eric Wild e69b54f9f7 internal ul32k instead of external 32k osc
This should be fine, the slow clock for the uarts is not used for the
modes we're interested in, and the usb clock is derived from the usb sof
anyway, so it's not used as a reference there either.

This will most likely drift, but so did the external one, and a
free-running rtc without any external input was going to drift anyway,
considering the octsim is supposed to just run without being powered
down for a very long time.

Change-Id: I257b8854e1860ed698c4007efeb5d16e842b519a
2021-09-27 18:35:00 +02:00
Eric Wild c92c1e0fb1 sychronize atmel start config with the headers
Change-Id: Ib21847f6726920e3f97600a347f2a16f957a5e8e
2021-09-27 18:34:56 +02:00
Eric Wild bbdaa71bc8 config: adjust dfll48m (usb) to match the docs
hal/documentation/usb_device_async.rst has a few things to say about the
SOF clock recovery mode currently used for usb, so honor those settings.

Additionally Footnote 1 in chapter 54.14 of the SAM D5x/E5x Family Data
Sheet restricts the fine step value.

Change-Id: I5d573859517eab6febda0bac836c4461c0f21bf0
2021-09-16 17:39:55 +02:00
Joachim Steiger 9b82728845 add script to generate a inititial osmo-bankd slotconfig sorted by usb path
Change-Id: Ibb5e7db78c8a2129d2093b0dd5ecaa7c13ab9ee3
2021-07-30 18:29:40 +02:00
Eric Wild 2a78f77ae7 cuart: move generic paramete reset upon powerdown to where it belongs
Change-Id: I784f66cb998fc04ae64312b809fc3a7c42bd6bff
2021-07-01 00:48:55 +02:00
Eric Wild af2827d25a cuart: reset on poweroff
Those settings (ccid setparameters, and internal uart driving) shiuld be
reset upon powering off.

Change-Id: I20bb650d731d54f743d7031fe67916239233ecd3
2021-06-29 00:57:14 +02:00
Eric Wild bcd3a3b9cf 7816 fsm: don't error on card removal in tpdu wait state
This led to a weird failed transfer _after_ poweroff of the slot upon
card removal, which is.... not what should happen, at least in case the
ccid side does not ignore it.

Change-Id: Ibabcc938d64a057ff60a2337a1320d0afb94032b
2021-06-24 16:38:42 +02:00
Harald Welte a09fabb48f 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: I63bac9d6767b21cb738be789f7efce2108804bdf
2021-04-22 11:22:43 +02:00
Ludovic Rousseau e284e48192 Fix typos in README.md
Change-Id: Ia2227b989dee0e57a41764ddfeca10e120c602e4
2021-04-04 14:15:22 +02:00
Harald Welte 26b88cad08 jenkins.sh: Add --disable-libmnl to libosmocore
Libosmocore has a new dependency that doesn't make sense in a 'bare
iron' embedded environment, so let's disable it.

Change-Id: Icfff52601af80d73e61f5c5c3ed89b2d7185ed81
2020-12-06 10:27:45 +01:00
Eric Wild 51a303096a asf4 uart: properly handle uart errors
Uart errors will now lead to a (temporary) deactivation of the uart as well as
the deactivatin of the card + a a proper ccid response to notify the
host if the slot was busy.

Change-Id: Ia0efef03829b68d2b4f25899bb933b14fb9e0bd1
2020-11-20 08:54:19 +00:00
Eric Wild 83e0dd9ba7 sercom: make waiting for the uart safe...
In error cases the uart might already be disabled, so waiting for the
dre bit does not work.

Change-Id: I269cf8ece48df24c9f1fcb262ef4ddd06cbe3d62
2020-11-20 08:54:19 +00:00
Eric Wild 91f1f18b48 7816 fsm/cuart: support inverse condition cards
This does not currently work with "pcsc-lite version 1.8.26." because
the inverse conditon cards I know do not support the PPS exchange, which
according to spec leads to card deactivation, so the slots needs to be
powered up again, which does not happen.

osmo-sim-test works after manually disabling the pps exchange code in
the firmware.

Change-Id: I892e1d883825111cc1e4ea09589c4fdd256da03c
2020-11-20 08:54:19 +00:00
Eric Wild 6b1f1c4e95 ccid/7816 fsm: better pps error handling
This requires a bit of inline explanation because it was not entirely straightforward,
 and there were some unused states that can now be removed to make it more concise.

Change-Id: Id138a600dbe2dd1b8d153b764f73d65e2fd444dd
2020-11-17 10:52:52 +00:00
Eric Wild 9a6e8ceea1 ccid: adjust msgb size
Our transfers are < 300b including the header anyway, no need to have
different allocation sizes.

Change-Id: Ia7b20dc4410f5705d0401bc805cad0ae7a7de406
2020-11-11 21:26:09 +01:00
Eric Wild eff9b91565 7816 fsm: move to static msgb
Error handling was difficult due to the need to pass msgb pointers
attached to the sub fsms back to the cb that is polled from the main
loop to be able free them, while ensuring they never get lost, because
memory leakage is deadly.

This is now fixed by using static pseudo-msgbs for the fsms that are
never deallocated. This only adds one tpdu tx copy, the ccid response
msgbs were already being copied anyway, so memory usage has not changed
except for the "unused slots" case that is not really important since
the octsim was designed around concurrent slot operation anway.

All of this allows convenient error handling in the allstate function
instead of having to spread it all over the sub fsms - in practice
handling errors mostly consists of card deactivation + returning a
proper failure message that matches the ccid command anyway.

Change-Id: I65e77c376aca9ed50e234a0b58a7450a8bbd4fe0
2020-11-11 21:26:09 +01:00
Eric Wild c1555c1360 ccid: do not allow xfers with inactive slots
pcscd tries to do this if the previous command led to a deactivation...

Change-Id: If2659c7d5e8784e5e4393d5b12589e96d517168a
2020-11-09 10:58:03 +00:00
Harald Welte 4c769e9a7d migrate from BSC_FD_* to OSMO_FD_*
Change-Id: I9d341d24527ca739424a68059126a7f789206c42
2020-10-18 21:38:19 +00:00
Eric Wild 099bb860b5 ccid: fix expected xfer length
Closes: OS#4818
Change-Id: I41e13625ca7f85b1a14960a938e807bbbebf656a
2020-10-18 23:17:00 +02:00
Eric Wild b06a90d432 7816 fsm: adjust atr start timeout
The calculation was still expecting timeouts measured in GT instead of
WT, so the actual wait time for empty sim trays (or unresponsive cards)
was 58 seconds instead of ~ 1.5s - a bit longer than necessary.
Total timeout if the atr reception has started is still approximately
45s as per spec (9600 ETU x 32).

Closes: OS#4815
Change-Id: I9f0ae104fac690127ab039ee7d9005e8d3896a1c
2020-10-17 19:23:37 +02:00
Eric Wild 49c5409df3 Revert "HACK: cuart: Artificially extend WTIME by 100ms"
This reverts commit 41177fe084.

Change-Id: I8532465305e9fb902cf1374f9823612773400691
2020-10-17 19:23:37 +02:00
Eric Wild 066489d4e0 t0: fix wtime calculation, for real this time
ETU calculation is 1 etu = fi/di * 1/f as per chapter 7.1.

wtime/WWT is usually mentioned as being 9600 etu in iso 7816-3 - but
it's actually specified for t=0 as WT=WI*960*Fi/f in chapter 10.2 - no
di involved here, so the rightmost fraction is not ETU!

-> as soon as di is not 1 after a pps exchange the timeout value was off
by a factor of di if it was just used as a multiplier for ETU.

Change-Id: Icd4fa83e1177873e90200529331d3a1fce8be1c6
2020-10-17 19:23:37 +02:00
Eric Wild ef393c31e8 ccid: disable handling t1 parameters for now
We don't support t1 yet, so those are errors.

Change-Id: I660246be7846eed46ecb729545658b3b95ad7c3a
2020-10-17 19:23:37 +02:00
Eric Wild 672a96044c ccid xfers: return proper error to host instead of asserting
This could have led to hangs when trying T=1 data blobs where the length
field is not the T=0 length field and is therefore misinterpreted.

Closes: OS#4805
Change-Id: Iacdf60e4401f8e287f60ea148b0944d0a3de491d
2020-10-17 19:23:01 +02:00
Harald Welte 41177fe084 HACK: cuart: Artificially extend WTIME by 100ms
It seems some cards / transactions take longer than we expect, see
https://osmocom.org/issues/4742

With sysmoUSIM-SJS1 a timeout of 12.5ms is sufficient.  But let's better
be tolerant here.

Change-Id: I85a7a0ae6195856fad17f249f0903f144a9aec85
Related: OS#4742
2020-10-16 22:37:05 +02:00
Eric Wild 172b44388e ccid fsm: handle special 0 == 256 byte value
Outgoing (=from the card) transfers have a special 0 == 256 byte
meaning.

Change-Id: Ifb960b3e0f221962e977083f7ddea14dd0c8f29b
2020-09-16 13:49:09 +02:00
Eric Wild 3ef02c0f4a ccid fsm: proper wtime calculation
The timeouts had a minor off by a million problem because WT (in ETU) =
WI * 960 as per 7816-3 10.2, but WI was used as WT without the factor of
960 after the pps exchange, so WT (in ETU) was accidentally set to 10
instead of 9600 for the default WI=10.
Additionally that time was only added once, even though the wait time is
the time between the leading character edge of one character and the
next one, irrespective of direction, so the total wait time is this
multiplied with the number of expected bytes.

In practice this had no real effect due to to a reasonable minimum
timeout value and cards that were much faster than this.

Closes: OS#4742
Change-Id: I9ea0b6b51c8cc6f08a36b48e516c64b5e2bbaf9b
2020-09-16 13:49:09 +02:00
Eric Wild bdaf7220bd usb: reset the device on usb reset if it was previously running
Usb init order is desc read -> reset-> set addr -> use device.

DADD.ADDEN is automatically cleared upon receiving a reset from the
host, at least according to the SAMD51 manual, but DADD.DADD is zero as
well (?) so it can't be used to check if usb was previously running and
the cable was pulled out and plugged in again while the device was
externally powered.
This works around this and ensures a device reset from the host leads to
a proper device restart and reinitialization in this case, there is no
state we want to keep in this case anyway.

Change-Id: I692de3dd98cfc30a010b457be87331e482632fb7
Closes: SYS#4908
2020-09-10 03:21:11 +02:00
Eric Wild 6b8e516491 usb: handle failed transfers
This fixes the crash with external power if usb is disconected and
plugged in again, upon ep reset the completion cbs are called, but we
can obviously not interact with those EPs at that time and resubmit
buffers.

Change-Id: Icff17673b4d1d1616ee733580bdd6b5203b87139
Closes: SYS#4908
2020-09-08 20:17:51 +00:00
Harald Welte 6b2ff3bc08 ccid_host: Migrate to OpenMoko USB VID/PID
We used 0x2342 just for internal testing.  Let's use a proper
unique allocation even for the FunctionFS version of the code.

Change-Id: Idbaf173b0ec1fd80885f26b3df24a4412913c100
2020-09-03 10:18:26 +02:00
Harald Welte 8dd67e3bbb import ccid-control - small hack to send CCID USB control requests
Change-Id: I7d6cf32e91dfd9974d2e28f13a2b062e07d17d6c
2020-09-03 10:18:26 +02:00
Harald Welte 68bc7f4a86 iso7816_fsm: ignore RX_SINGLE events during transmit
When logging is enabled, we get a lot of LOGL_ERROR events
about RX_SINGLE events not being permitted.  This is not very
useful in debugging, so suppress those error messages.

Change-Id: I7aec5fb2eaa76076e1bd0c6b8e8d09dc840c3630
2020-09-03 10:12:36 +02:00
Harald Welte b70bcee73a add README.md to top of repository
Change-Id: Ie90114c0bce84d9d5c05ab03d3858b5c90437017
2020-09-03 10:12:36 +02:00
Harald Welte a67be5ff1e add copyright + license disclaimers to ccid_common + ccid_host
Change-Id: I1b0f876de337c625081dc5b579dd0a88d62c857c
2020-09-03 10:12:36 +02:00
Harald Welte 08c8e1c562 iso7816_fsm: Fix APDU case with P3=0
If P3=0 and we only receive a status word directly, we were
returning a very long mostly zero-initialized buffer instead
of the status word.  Reason: We used msgb_put() instaed of
msgb_put_u8(), so the SW1 determined the size of the message.

Change-Id: I01e688db020b3b8a8735d615e653cc816caa7a13
Closes: OS#4744
2020-09-02 20:09:34 +02:00
Harald Welte 498e9e701e iso7816_fsm: Fix TPDUs wih Le == 1 (single byte reads)
If we expect only a single byte in response to the TPDU header,
the cuart driver sends us RX_SINGLE events, not RX_COMPLETE events.

Change-Id: I3f025bc88b9aacc07ae87307328cec56efbac2ab
Closes: OS#4741
2020-09-02 18:10:13 +02:00
Eric Wild 70f3691a59 proper card powerup handling
Now that the timers work as intended other voltages (that lead to
timeouts) may be used.

Change-Id: I6105ce7f827aaec8ac36b940766fe05d47145edb
2020-08-10 17:38:04 +02:00