Commit Graph

1020 Commits

Author SHA1 Message Date
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
Harald Welte f620c3978c qmod: Don't print EEPROM operations in help when not supported
As of Change-Id I1c8cca2f7f0f0070d7bf1ade676e035c45e4d5ab, a firmware
compiled without ALLOW_PEER_ERASE will not support resetting the hub or
writing to its EEPROM.  Let's make sure to remove those options also
from the menu.

Change-Id: I3071332d85e6168947384ddc230298d3293e4668
2019-12-14 23:07:04 +01:00
Harald Welte a14616c096 usb_buf: Limit the maximum queue length to 3 elements
If there are already three elements in the to-be-transmitted queue
for the EP, let's free the first element of the queue.  This is a
clear indication that the USB host is not polling the endpoint
regularly.  Maybe there's no host application running at all?

This should obsolete Change-Id Ie9ebdd2ff966f67c9afd1ed760f106558f0091ad

Change-Id: Ie15183f16b22193ffdaf01845db2eae4c7f43c17
Closes: OS#4251
2019-12-14 21:51:05 +01:00
Harald Welte f4a625be53 usb_buf: count number of elements in queue
This is in preparation for limiting the maximum queue length

Change-Id: I7cb184d7a1ccb519010a2f3e3295cc3a5fbf8052
Related: OS#4251
2019-12-14 21:50:59 +01:00
Harald Welte 271be9d181 more comments in host_communication.c.
Change-Id: I8b0124ec96b56b7c89e4c7033a11cc93c4fa2d26
2019-12-14 21:13:37 +01:00
Harald Welte 342a7fe039 Add missing CR to achieve CRLF at end of log lines
Change-Id: Ic4afb2981f68811fddb272e64dbddd3397a12642
2019-12-14 17:26:21 +00:00
Harald Welte 3c003cc2fa Fix format string related warnings (int vs. long)
Change-Id: I924a16f03e2a099b9f8eb56746bff2b9101c6802
2019-12-14 11:47:06 +01:00
Harald Welte 37055b9286 stdio: Add support for %p format string (pointer address)
We actually llready had plrenty of code using %p, despite our stdio
not implementing it ;)

Change-Id: Iecf6c849ce5ef72a8fed9b19a18e215c61c3d09f
2019-12-14 11:47:06 +01:00
Kevin Redon 75a5f224c0 minor: improve trace output
the USB trace now respects the global setting.
the verbosity is also decreased, not showing USB activity unless
debugging.
this also saves some space.

the reset cause is now printed.
the strings increase the bootloader size, but it already exceeded
the 16 kB limit when trace level is set to info.

Change-Id: I9ba08d4bb4f188f6e7a202ea86acb7a42a2054f3
2019-12-11 16:58:07 +01:00
Kevin Redon 198c3fb21b improve shared bootloader/application memory
now both partitions (bootloader and application) use a commonly
defined memory location to shared the DFU state (which includes
the magic value to know which part to start), instead of using
a hard coded value.

the bootloader size has now also been restricted to 16 kB.
this limitation is enforced so to not be able to create larger
images, which could be corrupted when flashing the application.

bootloader and application flashing have been successfully tested
on qmod st12 and st34.

Change-Id: I204bed7e9391602672ed894decec1fc12e879275
2019-12-11 16:35:31 +01:00
Kevin Redon 98cf47adba Makefile: add linker option showing memory usage
this will help seeing how much free space is available for the
bootloader (which is restricted to 16 kB)

Change-Id: Ie74a1480c2f340765046be9bdfc3a8c4ba851e9b
2019-12-11 16:13:58 +01:00
Harald Welte 87940f1f83 Build only 'reasonable' combinations of APP/MEMORY
There's no point in building a DFU loeader that is to be flashed
via DFU - nor is there really any need for regular cardem/trace
that can be flahsed directly without DFU.  If anyone needs those,
they can still build them - but let's not confuse the average other
user.

Change-Id: I0abe86c6a942a59e5b2417d0532dffae654d7a18
Closes: OS#4087
2019-12-06 20:08:33 +01:00
Harald Welte 36f888f8b5 Patch actual board name into the USB iProduct string descriptor
"SIMtrace 2 compatible device" is pretty generic.  Let's have the
actual board name inside the string descriptors, giving a more
user friendly experience in case users are issuing 'lsusb' and the
like.

Change-Id: Ibcc338b504bd2a1605e31d7f5eadb7161f547c6a
2019-12-06 19:19:23 +01:00
Harald Welte 0a7c691b90 usb_strings.txt: s/SIMtrace Phone/SIMtrace Card Emulation/
This string dates back to some very early naming; let's reflect how
we have been calling this in reality for quite some time now.

Change-Id: I5a7497188385706a1e924784073c619fa9bfdd60
2019-12-06 19:19:23 +01:00
Harald Welte c9af72dccb qmod DFU: Don't overwrite memory beyond end of usb_strings[]
The code in board_main_top() for QMOD blindly re-assigned some
members of the usb_strings[] array, writing to index 7 and 8.

However, that array only has those entries in the main firmware,
while in DFU that array has only 6 entries.  Depending on whatever
the linker has decided to put in the next memory location after
that array, we would overwrite that very early during boot-up.

Change-Id: I59e4e1a54e819808d5a8259a6d14f4b970a90020
Related: OS#4302
2019-12-06 18:47:25 +01:00
Kevin Redon d70836f965 DFU: restart bootloader when USB conf failed
when starting the DFU bootloader, but USB configuration (e.g.
enumeration) failed, the MCU restarted in the main application.
this occured after a DFU detach and were the USB host missed the
USB reset.
now after MCU reset, the bootloader is started again, since this
is what was requested to begin with.
the bootloader will always restart in the bootloader until USB
enumeration succeeded.
this boot loop can be stopped by unplugging/removing power from
the device.

Change-Id: I4062a7d8a7934af2119c169759b614dc45990651
2019-12-03 15:51:52 +00:00
Kevin Redon ed3ceec56f DFU: increase USB reset duration to 50 ms
the specification requires a reset duration of at least 10 ms.
reset is indicated by the device to the host by removing the
pull-up on D+ (host to device reset is a USB packet).
we used 20 ms, but on some setups (USB host, stack, hub, and load
dependent), this does not seem to be enough (no USB enumeration
was performed afterward, at least for the DFU bootloader).
increasing to 50 ms solved the issue on the affected setups.

instead of USB suspend, the more proper USB disconnect is used.
this mainly disables the pull-up provided by the USB peripheral.
USB activate is not required since the follow up initialisation
takes care of it.

Change-Id: If5ceb3b8f7a8f134d4439fdd138dd12b46589f97
2019-12-03 15:51:52 +00:00
Kevin Redon 15f48b2e89 minor: fix typo
Change-Id: I462291078fe9b05bfdf6fb7ab0f96b1edeecdac6
2019-12-03 15:48:51 +00:00
Kevin Redon 503e184157 cardem: use simplest ATR as default ATR
This is the shortest and simplest ATR possible according to the
ISO 7816-3 spec.

It does not offer any non-default parameters (F, D, WI, ...)

Change-Id: I4ff41b5120bcadca652296f9d3691f7606be2bd2
2019-12-02 19:38:45 +01:00
Kevin Redon 24c6fe21ab simtrace2-remsim: Use simplest ATR
this ATR does not encode any data and uses all defaults.
the lower default speed is also better handled by the hardware.
handling faster speeds is upcoming.

Change-Id: I5a4f2f94bea1a15aedbef5a6f2f49344387dc11d
2019-12-02 19:35:45 +01:00
Kevin Redon 8cbede7067 minor: ignore usbstring binary
Change-Id: I18fc3179f8b7f3f1272d26853007876156fc1e03
2019-12-02 19:30:37 +01:00
Kevin Redon 8b6991c18c better detect VCC and nRST changes on simtrace2 board
monitoring the state changes of the VCC and nRST lines is required
to correctly detect warm and cold reset

Change-Id: I72099956332724f84226e1495fdc5a5b1a034695
2019-12-02 19:28:52 +01:00
Kevin Redon 1cfc25e8c1 minor : fix typo in comment
Change-Id: Ie310143fe713a51fa1adf8bf7599374282341f2e
2019-12-02 19:28:07 +01:00
Kevin Redon 3864a794b4 minor: improve debug output
Change-Id: Ibfc22b95c0be3ac78bd50a40e31cc7d8546d81d9
2019-12-02 19:28:00 +01:00
Kevin Redon e051ddd1f3 minor: move USB debug output from info to debug level
else it's too nosy while debugging other components, not often
used, and break the flow since it does not and a line.

Change-Id: I8920ff7c33b4c9fb174bb31a29334a63fcbede43
2019-12-02 19:27:19 +01:00
Kevin Redon 98fbf23897 dfu: minor: make debug output only verbose in info level
the longer output is to fast and often incomplete.
the shorter version is enough to view the progress when not
debugging.

Change-Id: I97bb84da68d1f3bc14fb7c05400edf1748f55460
2019-12-02 19:26:56 +01:00
Kevin Redon 9b367872c8 minor: updated copyright years
Change-Id: I9254b1ddf6436b5a4964b9124a36ae17bfc22886
2019-12-02 19:26:11 +01:00
Harald Welte 0b7e5f3af0 fix baudrate of 'make log'
Change-Id: Id186a594b1ce3ea0cd38f0cb82a99e5d87101433
2019-12-02 19:25:55 +01:00
Kevin Redon 72a62cfdb9 minor: fix spacing
Change-Id: I2f3127c7b276c9726fd0242e3e29be22f9d6255c
2019-12-02 19:25:37 +01:00
Harald Welte 483a3203fb simtrace2_api: Remove dead code
Change-Id: Iab393a6cf9ae1218e1554d9c0bfb7aab2cc3c35e
2019-12-02 11:23:51 +01:00
Oliver Smith 71cfc2b90d Fix topdir Makefile and debian packaging
Make building the debian packages work again. I've verified that it
works in my own OBS namespace.

This patch also adds missing pkgconf variables in host/Makefile.am, so
libosmo-simtrace2.pc installs properly.

Related: OS#4283
Fixes: 964cda309d ("host: use autotools and split shared code to libosmo-simtrace2")
Change-Id: I2377de1e8b149520922217a1ab16f6e22fe6462a
2019-11-28 11:53:09 +01:00
Oliver Smith 15e943ab8b simtrace2-sniff.c: fix printf usage
Fixes:

simtrace2-sniff.c:113:4: error: format not a string literal and no format arguments [-Werror=format-security]
    printf(flag_meanings[i].str);

Change-Id: I9793c680f070e724ce89272e9e489963c7516d52
2019-11-27 19:10:02 +01:00
Kevin Redon b7f94dcb9f qmod: lower VCC threshold to 2.5V
on the QMOD board the VCC signal from the modem is measured using
an ADC (SIMtrace board just use card detect).
the threshold to consider VCC as activated was set to 2.8V, which
gives a bit of margin for the expected 3.0V.
still, we had one board where the voltage was 2.8V.
to be resilient against lower than expected voltages from
modems (or boards), we lowered the threshold to 2.5V.
this is still save for the SAM3S to correctly identify high/low
levels.

Change-Id: Iac2778903690045e4e63fef29f812205d00c28ed
2019-11-26 13:49:53 +01:00
Kevin Redon c90de6983c free USB buffer when allocation failed
when the reader sends APDU headers (e.g. after multiple reset),
messages are queued for USB transmission.
but if no host software is connected to SIMtrace in card emulation
mode, the USB message queue is not emptied, leading to the memory
getting full and preventing allocation for newer messages (e.g.
more recent APDU).
in this case the oldest queued message is now dropped to free some
memory.

Change-Id: Ie9ebdd2ff966f67c9afd1ed760f106558f0091ad
2019-11-26 09:57:28 +00:00