Commit Graph

903 Commits

Author SHA1 Message Date
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
Harald Welte f46de7b70f simtrace2_siff: getopt_long() returns int, not char
This may be causing unwanted behavior while parsing the command
line arguments, as reported by some Raspi users.

Change-Id: I5b7db0795d16ab071e255c2c689e3b4872a933bb
Related: OS#4223
2020-03-19 09:18:31 +01:00
Harald Welte e42492971e pio_it.c: Permit repeated calls to PIO_ConfigureIt()
The original code assumes that calls to PIO_ConfigureIt() are only
made once e.g. during board start-up.  Hoewever, we call those
at USB SetConfiguration time, when we know which particular hardware
function we are supposed to perform.   This means that after the host
has issued SetConfiguration more than a given number of times, the
code will assert() due to overflow of the static array.

Let's check if we already have allocated an array slot for a given pin
and reuse that allocated array bucket rather than allocating new ones
for the same pin.

Change-Id: I0c46d4b51eeebd58a8786d65e31e7a84e65b6a8e
Related: OS#4454
2020-03-13 15:28:40 +01:00
Harald Welte a625ef0d9b USBD.c: Don't reset EP0 on SetConfiguration(0)
If we do this, the resulting USB code will fail on any of the
USB-IF Chapter 9 tests.  EP0 should not be reset.

Change-Id: I070faf4cb7029d3ccfa6c63f8f04aa0f02657536
2020-03-13 12:56:49 +01:00
Harald Welte 823f453d83 cosmetic: Add missing CR to LF in dispatch_received_usb_msg()
Change-Id: Ie1fc38ed4412b806e37688e0f9719573df06fd9f
2020-03-03 21:09:50 +01:00
Harald Welte 13cb311c06 extend osmo_st2_cardem_inst with fields required by osmo-remsim
Change-Id: Ib568e5212abfd1269a12c9e5672cdf23b4abff91
2020-03-03 21:09:50 +01:00
Harald Welte e6806e58c2 cardem: Fix infinite loop + watchdog reset on long OUT message
In dispatch_received_usb_msg(), we ran into an infinite loop if a
too long messages was received on the OUT EP.  Let's break the loop.

Change-Id: I5325ed15d3dd79a42f8dac34d618e86b9334c301
Closes: OS#4429
2020-03-01 19:19:53 +00:00
Harald Welte 37220cce25 Disable interrupts during EEFC_ReadUniqueID()
Reading the Unique ID from flash is a rather tricky procedure: After the
STUI command has been issued, we cannot read normal flash anymore.
Rather, the unique ID is mapped at 0x00000000. This is unfortuantely
also where the exception vector table is stored.

EEFC_ReadUniqueID() is already linked to RAM, which is good.  Hoewver,
if an Interrupt happens between STUI and SPUI, then we try to access
the vector table and code from flash, which is illegal.  We run into
a hardfault and stay there until the watchdog resets the processor.

Change-Id: I3c4fad55b47e9013f6615a331983b3989ca805a7
Closes: OS#4428
2020-03-01 15:47:42 +01:00
Harald Welte 02712376df simtrace2_api: Add osmo_st2_cardem_request_config()
In Change-Id I7cdd3f9171dbed45de0089defe29d2b59044bd84 we introduced
firmware support for SIMTRACE_MSGT_BD_CEMU_CONFIG.  The respective
host part was so far only implemented in osmo-remsim-client-st2,
but not in libosmo-simtrace2.  Let's fix that.

Change-Id: Ia4822d360a271d2ce9725f761cb95de58663ac3b
2020-02-22 22:13:24 +01:00
Eric Wild baa62777c8 cardem: disable upload for simtrace2
cardem on the st2 has been broken forever and still does not work, so
stop uploading cardem binaries

Change-Id: I33828f799d41386afb3f8dcd9bb510902877e03f
2020-01-30 17:22:40 +01:00
Eric Wild 1fad9229bf remsim: allow selecting pcsc reader number
The number can be queried using pcsc_scan -n

Change-Id: I9d347501a9f181f68e74799ad04a810553eb2c9e
2020-01-30 10:21:36 +00:00
Harald Welte c7173bcc69 increase ringbuffer size from 512 to 1024 bytes
As reported in https://osmocom.org/issues/4335, there appear to
be some cards / use cases in which the 512 byte sized ringbuffer is
insufficient.  As we do have free RAM available, we can easily
increase the buffer size, despite not entirely knowing yet why
it needs to be *that* large.

Change-Id: Ie713d614ec5b334e9058d5d430e4bb660f5b8b69
Closes: OS#4335
2020-01-17 16:33:59 +01:00
Harald Welte 02f01e859c host/lib/gsmtap.c: Add GPLv2 disclaimer
Change-Id: Ie163af869c6aa2f3e2bd9007432dc6945384aaf2
2020-01-17 10:29:03 +01:00
Harald Welte 575214f248 host: Add COPYING file for host software (GPLv2)
Change-Id: I0f89a204939b0648eed94cc4f6e7c4f735c118fa
2020-01-17 10:23:31 +01:00
Kevin Redon e88be9e782 add script to flash latest firmware
this python script lists the SIMtrace 2 devices connected to USB
and will flash the latest version of the application (if necessary).
it requires pyusb and dfu-util.
it is intended for end users so they don't need to read the length
and error-prone instructions provided in the wiki.

TODO:
- support updating bootloader (once dfu-ram image exists)
- use python implementation of dfu-util to be python only

Change-Id: I3ebe0f54b6e3b7b45478603cc0a5b56e87b1f461
2020-01-16 20:36:23 +00:00
Kevin Redon b6e2f0f8e7 DFU: add DFU application
this adds the DFU as application, allowing to flash the bootloader.
a USB DFU alternative is added to flash the bootloader partition.

when the DFU is started as bootloader, the partition/alternative
to flash the bootloader is marked as "not available", and
ineffective.
the same happens for the application partition when DFU is started
as application.

this distinction is make at compile time, not at runtime, because
of size restrictions (the bootloader was already close to the
16 kB limit).
*_dfu_flash.bin should not be mixed with *_dfu_dfu.bin.
*_dfu_dfu.bin should be flashed as application using the already
existing DFU bootloader.
once this images is started (as application), the *_dfu_flash.bin
should be flashed as bootloader using the DFU application.

once the DFU bootloader has been flashed, soft resetting
(not re-powering) will cause the bootloader to start, allowing to
flash the application with a normal image (e.g. not DFU),
replacing the DFU application.
this switch to DFU only happens after downloading (e.g. flashing).

it is planned to have the DFU application erase itself after
flashing, but this is currently not implemented.

Change-Id: Ic273bb593a7669111b0219fe301d7897419167c8
2020-01-16 20:35:04 +00:00
Harald Welte 34200e4676 firmware: apps/cardem/main.c: Synchronize with apps/trace/main.c
In the end we want to share most of this, irrespective of the "APP".
Let's avoid unnecessary differences.

Change-Id: Icf063d4ca79edf66ffbe8e87a915deb77dec478a
2020-01-11 17:52:44 +01:00
Harald Welte e3b2de45c4 firmware: move printing of welcome banner to common function print_banner()
This unifies the printing of the welcome banner, and it also ensures
that all modes print all information (serial number, reset cause).

Furthermore the APP and BOARD #defines from the make environment are
also printed.

Change-Id: I7e6bc05cee4b9ec0fd9a05dc90ce0b26a5763e5a
2020-01-11 17:52:36 +01:00
Harald Welte ce4b5c25e8 library: Add osmo_st2_compatible_dev_idsp[]
This is a list of known-compatible USB VID/PID pairs.

Change-Id: I3ef66ebba307899c57077bfd633f84f30190f4dc
2019-12-26 08:07:59 +01:00
Harald Welte 7f7de1ec1d migrate to libosmousb
the code we used to have in libusb_util.c has been migrated to
libosmousb, a new part of libosmocore.git.  Let's remove our historic
copy and use the new shared library instead.

Change-Id: Ib588c08f873c4da8f3a02815ee2767674a6a5061
2019-12-26 08:07:19 +01:00
Harald Welte 8591495d74 Update .gitignore file for host
Change-Id: Id6449ea1c3e918e8c7748b9af7c8c354c1b607d5
2019-12-26 08:07:19 +01:00
Harald Welte b566ea3e83 OSMO_ASSERT() on double-free or invalid pointer
Change-Id: I2ab8fb7b86b6f608bbd9c4f79369c64cbad88bdf
2019-12-25 08:51:44 +01:00
Harald Welte 563601cff2 [lib] apdu_dispatch: Don't print APDU state to stdout
The printing was always only done at the end of osmo_apdu_segment_in(),
so let's leave the decision up to the user if he wants to print the
state at every iteration or not.

We now provide osmo_apdu_dump_context_buf() to the user so he can obtain
a string representation of the internal state for logging at any time he
requires.

Change-Id: Id3e3cf1605dec84077b158c1c5715f8eef2641d5
2019-12-17 12:46:21 +00:00
Harald Welte e9556efe88 [lib] apdu_dispatch: Use DLGLOBAL and don't printf() directly
Change-Id: I2f3ec49d34b6806e13af185fb629cabc486891fb
2019-12-17 12:46:21 +00:00
Harald Welte cdc0853777 jenkins.sh: Add verify_value_string_arrays_are_terminated.py
Change-Id: I15f13e12711b87ce71b38b16ef17620850fd8eb7
2019-12-17 13:28:15 +01:00
Harald Welte bfd27afd5f firmware: Reformat value_string to pass our validation scripts
This is a purely cosmetic change in terms of coding style, but it
fixes an [invalid] detection for unterminated value_string arrays
by our verify_value_string_arrays_are_terminated.py script:

Change-Id: I2f2370a673074f6bf5380106b6254b4aa1e8a792
ERROR: file contains unterminated value_string 'struct value_string iso7816_3_card_state_names[]': './deps/simtrace2/firmware/libcommon/source/card_emu.c'
ERROR: file contains unterminated value_string 'struct value_string tpdu_state_names[]': './deps/simtrace2/firmware/libcommon/source/card_emu.c'
2019-12-17 12:57:09 +01:00
Harald Welte 17cda3db8a simtrace2-sniff: Reformat value_string to pass our validation scripts
This is a purely cosmetic change in terms of coding style, but it
fixes an [invalid] detection for unterminated value_string arrays
by our verify_value_string_arrays_are_terminated.py script:

Change-Id: Iee905c744065df1dc54f04be752a65700897a92c
ERROR: file contains unterminated value_string 'struct value_string change_flags[]': './deps/simtrace2/host/src/simtrace2-sniff.c'
ERROR: file contains unterminated value_string 'struct value_string data_flags[]': './deps/simtrace2/host/src/simtrace2-sniff.c'
2019-12-17 12:04:56 +01:00
Harald Welte e213cc4f59 cardem: Implement support for CEMU_FEAT_F_STATUS_IRQ
If this feature flag is set by the host application, we will start
generating SIMTRACE_MSGT_BD_CEMU_STATUS towards the interrupt endpoint
on any changes to the SIM card status, such as change of VCC/CLK/RST

Change-Id: I832b4ac4aeb6152195d985067ffdd64fa5a7d4cc
Related: OS#4330
2019-12-16 14:51:49 +01:00
Harald Welte a5bbe78d2d cardem: Add SIMTRACE_MSGT_BD_CEMU_CONFIG
The new SIMTRACE_MSGT_BD_CEMU_CONFIG command can be used to set/change
a bitmask of optional features that can be enabled in the simtrace
by the host software.  This is useful for enabling features in the
firmware which are not supported by older host utilities.

The firmware will return the actually set/configured features in
response.

The feature bitmask is not yet used anywhere; it will be by subequent
patches.

Change-Id: I7cdd3f9171dbed45de0089defe29d2b59044bd84
2019-12-16 14:51:49 +01:00
Harald Welte 140f007c3e cardem: Make card_emu_report_status() optionally use IRQ endpoint
This just introduces the capability to report on IRQ, but we don't
actually use it yet.

Change-Id: I83db4463b7010ba243a8adbda3ac9393975b4814
2019-12-16 14:51:49 +01:00
Harald Welte 12c9b7ba02 card_emu: Remove extraneous initialization of ch->pts.state
ch->pts.state is initialized every time we enter ISO_S_WAIT_TPDU
state, so there's no need to reset it at other locations. KISS.

Change-Id: I5ff8b2671c3c893cc5f6542d48b65487ae8c5be1
2019-12-16 14:51:29 +01:00
Harald Welte 4d4405ff3a card_emu: Remove extraneous code
card_set_state(ch, ISO_S_WAIT_ATR) internally calls tc_etu_enable(),
so there's no need for the caller to do the same, too.

Change-Id: I2a2b4d64c40264623313a867957ffcefe57748f9
2019-12-16 14:51:28 +01:00
Harald Welte 6a3a714e2f card_emu: Always print state names in string representation
Change-Id: I81469e40f3720afdcb47048b45c63d6474887640
2019-12-16 14:49:56 +01:00
Harald Welte e9f429d34c card_emu: Avoid recursive calls to card_set_state()
A function that is called to set the state should not in itself
contain logic to issue further state changes.

Let's shift the related block out to the end of card_emu_io_statechg(),
which is the only source of card_set_state() calls for the
WAIT_{POWER,CLK,RST} states anyway.

As an added benefit, the block of statements is now also executed if
there's no state change - something that was prevented by the
"if old == new" state guard at the top of card_set_state().  I believe
this may help us to cover more (non-standard) card activation sequences.

Change-Id: Ieefa1807099eb234cfd994bca83caaa0dcc919b6
2019-12-16 14:49:56 +01:00
Harald Welte 02d0d73cf1 card_emu: Initialize PTSS state every time we start PTS
Let's shift the responsibility from the caller side to the calee side.

Change-Id: I39661ca93c87b2e2071765f69578eec5aaf90ce4
2019-12-16 00:08:46 +01:00
Harald Welte 5b136021d8 host_communication: Send zero-length-packet on wMaxPacketSize
We need to send zero-length packets on bulk endpoints whenever the
transfer size is exactly a multiple of the wMaxPacketSize.

See USB 2.0 Specification Section 5.8.3 titled "Bulk Transfer Packet
Size constraints."

Change-Id: Ice3842399d5a5c4a18383860f81074497c6e7c9b
Closes: OS#4331
2019-12-16 00:08:46 +01:00
Harald Welte 81f4ef7750 cardem: RST resets all state (including release of buffers)
When the Modem is asserting RST, the emulated card should set all
of its state back to default/initial values and release any buffers
it may still hold in its state.

Change-Id: I66eca6afe4ff7d900c5b75df1e3ec6d52f6ef214
Related: OS#4251
2019-12-15 17:53:01 +01:00
Harald Welte fa197ca343 cardem: Move card_emu_io_statechg() calls out of interrupt context
So far, we called card_emu_io_statechg() from interrupt context, which
was safe with the current code.  However, as we want to trigger a more
comprehensive reset of data structures, including the flushing of
message queues, it is best to shift this processing from interrupt
context to main loop context.

Change-Id: I3983078396538f32bdff55611c41d2163be4d796
Related: OS#4251
2019-12-15 17:52:00 +01:00
Harald Welte e92cb50a6e card_emu: Factor out card_handle_reset() from card_emu_init()
Let's move all initialization of state that may change at runtime
to a separate function: card_handle_reset().

This has the advantage that the related function may also be called
at later/other instances, not just during initialization of card_emu.

Change-Id: I0954d192d001a3af5592010cc84a3a22aaf4b030
Related: OS#4251
2019-12-15 17:51:47 +01:00
Harald Welte 1714679106 pseudo_talloc: Increment number of buffers from 10 to 20
We need at least one per IN/IRQ endpoint, as well as at least 3 for
every OUT endpoint.  Plus some more depending on the application,
in case of cardem there could be one in uart_tx and one in uart_rx.

So for cardem, it should be 7 per slot, resulting 14 for dual-slot
devices like OWHW and QMOD.

Given that we have plenty of RAM available (utilization up from 49%
to 56% with this change), we can be on the comfortable size and
easily have 20 buffers for now.

Future MITM / triple-play applications likely need more.

Change-Id: I022ba3bb3e1f5fd0c364aafe1a23f8fd9b2d8499
Related: OS#4251
2019-12-15 17:39:26 +01:00
Harald Welte a812de808d usb_buf: Properly initialize buffered_endpoint->ep number
The number is used only in print statements, and it's always '0' so far.

Change-Id: Id147e24d9d50c274fec963f00494cb20e2360b33
2019-12-15 17:25:14 +01:00
Harald Welte b0b457df63 USBD_HAL: Don't disable UDP peripheral clock on suspend
Change-Id: I2169e2140762b37661f4567bb148326afd85cddc
Closes: OS#4329
2019-12-15 17:25:13 +01:00
Harald Welte ad117091ca usb_buf: Actually limit queue to 3 elements, not 4
In Change-ID Ie15183f16b22193ffdaf01845db2eae4c7f43c17 we wanted
to limit the number of queue elements to 3, but actually implemented 4.

Change-Id: Ic5fb164f2dfd1c293c51bee8184fc34552267a54
2019-12-15 17:25:13 +01:00
Harald Welte 56be0bf317 cardem: Fix memory leak on unsupported SIMTRACE_MSGT_DT_CEMU_CARDINSERT
Some boards like QMOD cannot simulate a virtual card insert signal
towards the modem (as the mPCIe connector doesn't have that signal).

In these situations, we were aborting processing of the related OUT
endpoint command and forgot to release the related memory.

Change-Id: I489097b7e332004e0f2beca0b22fa36d5d1d31b5
Related: OS#4251
2019-12-14 23:26:02 +01:00
Harald Welte 60118315cc update copyright statement
Change-Id: I6ffced85cf2398bbf6dcc3123accb5610e766f61
2019-12-14 23:07:04 +01:00
Harald Welte 63c9e1f402 implement minimalistic talloc_report(); add 't' command on UART
This helps when debugging the firmware, as it shows the current
utliization of the 10-msgb-talloc pool.

Change-Id: Ib10c4396cd4c9c4a6257cf45886e367214787927
Related: OS#4251
2019-12-14 23:07:04 +01:00
Harald Welte 7c1d85eb4d qmod: Document '!' and '@' commands on UART
Change-Id: I38c69ef45e92fd0aa03907e984cf524331b53d57
2019-12-14 23:07:04 +01:00
Harald Welte 587248404c cosmetic: board_qmod: Annotate #endif with comments
Change-Id: I2e2de6c65d791767637b9c43a1c0ff9cbeabf5e9
2019-12-14 23:07:04 +01:00