Commit Graph

51 Commits

Author SHA1 Message Date
Harald Welte 7703150eaf user_simtrace2: Fix uninitialized ifm->path
Let's memset the entire ifm before calling
osmo_libusb_open_claim_interface()

Fixes: CID#307510: Uninitialized scalar variable (UNINIT)
Change-Id: I2bd0dac76b6d028d10f12f3f58a2aee123ca8562
2023-07-18 20:00:48 +02:00
Harald Welte 958ae50de1 user_shell: Fix unchecked return value of osmo_fd_register()
Fixes: CID#307519: Unchecked return value (CHECKED_RETURN)
Change-Id: I68ed44464573b9a6fecd07cf13fd2d6f4a1013bb
2023-07-18 13:38:07 +02:00
Harald Welte 58eebe13c7 user_ifdhandler: Fix missing check of osmo_fd_register return val
Fixes: CID#307514: Unchecked return value (CHECKED_RETURN)
Change-Id: I99d7254b6cc3bf5ead800dafabc77a965857911c
2023-07-18 13:36:05 +02:00
Daniel Willmann e78bc32791 remsim_client: Fix custom ATR '-a' option
So far the option only parsed the hexstring into the atr buffer, but
failed to update the length (from the default value of 2). Also set
atr.len so sending custom ATRs works.

Change-Id: I5deb0a432c05ab0bab5081a2812f6718d4a2ac33
2023-05-31 18:34:54 +02:00
James Tavares e206e6a2e2 bankd, client, server: add -L option to disable log coloring
When the stderr of these services is sent to syslog, for example by
using systemd's StandardError=syslog, syslog's escaping of ANSI color
ESC sequences in log messages really clutter the log files. This
option allows log coloring to be disabled on the command line.

Change-Id: I6955b0af1ceb11a4029383e32bb298ee8da7503f
2022-11-19 09:18:16 +00:00
Harald Welte 7da85411e3 remsim-client-st2: Proper error if not all endpoints can be found
Let's avoid a segfault and rather print a proper error message in case
we cannot find all the required USB endpoints when opening the
user-specified interface/config/device.

This can happen if the device is currently in DFU mode, or a completely
wrong device/interface was specified.

Before this patch:
Assert failed rc == 0 user_simtrace2.c:305

After this patch:
DMAIN ERROR user_simtrace2.c:448 specified USB dev/config/interface doesn't have at least one IN, OUT and IRQ_IN endpoint

Closes: OS#5416
Change-Id: Icfcc482fff106a232c5125ed8ab463ecc13824ae
2022-11-15 00:59:40 +01:00
James Tavares 11d84c761c client: set the local/remote mode before inserting card
- avoids a race with the modem

Change-Id: I7b0640b929e174e8dfdcc86947fa409e4acf338f
2022-11-14 10:47:35 +00:00
Harald Welte c8c77e08ee client: Option to ignore any ATR sent by bankd
This introduces an --atr-ignore-rspro command line argument, which
will make the remsim-client ignore any RSPRO setAtrReq it receives
from the remote bankd.

The purpose of this is to modify the capabilities advertised by the card
towards the UE (modem/phone).  For example, by modifying the ATR
one can disable/constrain the UE from using higher bit rate support, or
disable the use of logical channels.

Change-Id: I930293f7b637dba60d9dd6d2254f4524f831b491
2022-07-24 13:01:07 +02:00
Harald Welte 445d284dfa client: Fix '-a' command-line argument for ATR
The argument existed (as a long option), and was documented in the
user manual - but it wasn't printed in the help message, nor was it
present in the getopt_long() string.

Let's fix that.

Change-Id: Icfb74597dd813cee8b48b8dcf520fdd1c954338a
2022-07-24 13:00:38 +02:00
Harald Welte 1f51279887 client: Log TPDU/ATR/PTS/slotStatus at INFO or NOTICE level
Closes: OS#5615
Change-Id: I9b54a53ef2809c9bfd110636a9ccb0c0d8c90cda
2022-07-15 08:22:29 +02:00
Harald Welte e5ed100fd2 main_fsm: Log bankd config (ip/port/bank_id/slot_nr) + disconnect
Closes: OS#6513
Change-Id: I30a814ba95eb9c545220a1513805f41ccb5acb42
2022-07-11 22:54:43 +02:00
Harald Welte a9bb9a9348 cosmetic: various typo/spelling fixes
Change-Id: Idc4db138d83be0c7c0b0ff6dfbb9f094b21d6fa9
2022-05-03 18:09:14 +02:00
Harald Welte eea631bff0 encode actual hostname in RSPRO
The RSPRO ComponentIdentity includes a 'name' for each remsim component.

So far we always used "fixme-name" instead of something meaningful.
Let's use the hostname of the system instead.

Change-Id: I14925f16ae242dae89fa853a2fe31c5c1b32981d
2022-05-03 18:09:14 +02:00
Harald Welte 5ae0f31c31 Check RSPRO component type; print error if type doesn't match
If one component connects to another component, verify that the
remote component type (bank/server/client) matches our expectation.

This is important in order to detect a misconfiguration of port numbers,
for example.

Closes: OS#5548
Change-Id: I89a4fc4331e8a0622f8f146c7fc235d34d990497
2022-04-25 16:15:41 +02:00
Harald Welte 55f12b8e38 Fix client_id/bank_id/slot_nr range in manual + --help output
The RSPRO.asn protocol defines the ranges 0..1023 for slot, bank
and client IDs.  Don't make misleading claims in manual and/or
help messages.

Change-Id: Id383b2bea4c014e7b61ae02e7062ba4db5c2dc20
2022-01-16 14:35:25 +01:00
Oliver Smith 0c832fe737 treewide: remove FSF address
Remove the paragraph about writing to the Free Software Foundation's
mailing address. The FSF has changed addresses in the past, and may do
so again. In 2021 this is not useful, let's rather have a bit less
boilerplate at the start of source files.

Change-Id: I2e98f89f6738d03c45a2106820af0912692093f3
2021-12-14 12:20:35 +01:00
Harald Welte 7293e7bcec logging: Replace remaining fprintf() calls with libosmocore logging
Change-Id: I2a772b3180131923d4e2ee7311670b938cb50fe0
2021-12-09 07:58:15 +01:00
Harald Welte 73bbd54cdb logging: Print category + level, disable category-hex
Change-Id: I9ae27b78b965d173146583b030fd93e2d70b845e
2021-12-08 21:15:49 +01:00
Harald Welte 7b87ba1e38 client: request card-remove and sim-local when no bankd/slot is set
When the client leaves the OPERATIONAL state, do the inverse of what
happens when entering that state:
* request "card insert" no longer to be generated towards modem
* request switch back to local SIM
* reset the modem to notice the change

This way entering remote-sim operation due to adding a slotmap
and leaving remote-sim due to removing the slotmap should be
symmetrical.

Change-Id: Ifaa4b60474bf8585bfbe0288062f581821bd3faa
Closes: OS#5216
2021-09-08 21:50:28 +02:00
Harald Welte dc34764648 remsim-client: Avoid zombies when scripts terminate
This avoids the OS from keeping terminated children (scripts) around
as zombies.

Change-Id: If7d45bda160987a26c7b101db6152142dc432fe7
2020-10-20 19:16:09 +02:00
Harald Welte 3f65972ed6 remsim-client-shell: Terminate if STDIN has been closed
Change-Id: I39937224b06b6bb6f23c002023141882797ee6a6
2020-07-19 09:54:37 +02:00
Harald Welte 57b21d479b user_simtrace2: Fix typo in frontend_handle_card2modem()
this typo was breaking operating with simtrace2 for all responses
that contained more than just a status word.

Change-Id: Id8195d6650c3306e1a39f59d78d1348671ad062d
2020-05-28 16:29:39 +02:00
Harald Welte aa66d91eda user_shell: Dispatch all events via main_fsm.c
... avoid calling server_conn_send_rspro() directly from user code.

Change-Id: I7f589ea1b1610e6d716ed0d9f4078b185bc6401d
2020-05-25 23:07:04 +02:00
Harald Welte dd33725c8f Enable async use of libosmo-simtrace2
libosmo-simtrace2 traditionally had only supported blocking, synchronous
I/O, while 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 switch OUT also to async.

Depends: simtrace2.git Ib8939bdb7f533cd20a34a30a97f12b782b9816c2
Change-Id: I18bf166a95bd4318d700b3e93401b2db5188acfc
2020-05-25 22:56:41 +02:00
Harald Welte 1eec53dbfb simtrace2: use correct event when dispatching modem data to main_fsm
Change-Id: I35e20a577544bde7ad7440a617dc3ed4d2572abf
2020-05-25 22:56:41 +02:00
Harald Welte e04382610b simtrace2: Set transp->udp_fd to -1 to indicate USB transport
Change-Id: Ie97f1d449509777661f7fcc2bd0c799711861184
2020-05-25 18:16:01 +02:00
Harald Welte 06fff2aec1 simtrace2: Fix missing LF at end of log output in process_do_rx_da()
Change-Id: I9ecda9f47711e24bf5d3d57e3d9e117add29f4cc
2020-05-25 18:16:01 +02:00
Harald Welte 80a0110f77 add '-d' command line argument to configure stderr logging verbosity
The '-d' option is pretty much tradition in most osmocom programs,
particularly for those without a VTY / config file it is the only
option to configure per-subsystem logging verbosity.

Change-Id: I0abecc26a5d8b6a5607e1eb8982af4c05909afed
2020-05-25 15:49:33 +02:00
Harald Welte e580c93169 avoid talloc abort in simtrace2 frontend_append_script_env()
talloc requires a valid context for the allocation, we cannot use
env[i] as context.

Change-Id: I82b5e6b91b39d6f5c2a7492adb8c6193083e0d70
2020-05-24 16:06:32 +02:00
Harald Welte b97e2fb573 user_simtrace2: Stop using printf, use libosmocore logging
This way we have consistent logging from all parts of the code via
the common libosmocore logging infrastructure.

Change-Id: I9ace31d781dd3e50f9a5d9239bafa87a01abb0d6
2020-03-14 18:26:26 +01:00
Harald Welte a3ab5f20d7 introduce --disable-remsim-client-{st2,ifdhanndler}
Change-Id: I4aaeeedc9df873f2e7edfbfab587fec2dfad85c4
2020-03-14 18:26:26 +01:00
Harald Welte f50a7520e6 client: Avoid useless depedency to libosmosim
Change-Id: Ic863dc2f7fe7b435c9ea19c9cb97b691411dc0f5
dpkg-shlibdeps: warning: package could avoid a useless dependency if debian/osmo-remsim-client-st2/usr/bin/osmo-remsim-client-st2 was not linked against libosmosim.so.0 (it uses none of the library's symbols)
2020-03-04 19:20:11 +01:00
Harald Welte 9629ba3fb9 client: Fix TODO: add CLK status information to event-script environment
Change-Id: Iecc6002a8effaae7d8c3cab2aa4c6109f83f35b2
2020-03-04 18:02:21 +01:00
Harald Welte 0e968cce38 client: major restructuring around new main_fsm
The remsim_client code already used FSMs for the connections
to both remsim-server and remsim-bankd.  However the 'main' part of the
program was not yet implemented as a FSM, making it somewhat difficult
to perform the right actions in every possible situation.

This commit re-structures the code around a central main_fsm, which
gets notified from the per-connection FSMs and which handles the common
processing.  It also handles the execution of external script commands,
and hence further unifies the code base between the different backends
(simtrace2, ifd_handler, shell)

Closes: #4414

Change-Id: I44a430bc5674dea00ed72a0b28729ac8bcb4e022
2020-03-04 18:02:21 +01:00
Harald Welte 9fac496046 client: ifd_handler (PC/SC reader driver) as remsim-client
This adds a "libifd_remsim_client.so" PC/SC driver that can be
used to make normal PC/SC client programs (like pySim, sysmo-usim-tool,
osmo-sim-test, osmo-usim-auth, ...) talk to a remote SIM bank.

Change-Id: Ib8707c6e0e46407ab39a693adfec2fa71892f6ee
2020-03-04 15:49:37 +01:00
Harald Welte 38d990b0be client: Work around "stock on PTS" problem
I can occasionally see osmo-remsim-client-st2 get stuck when the Modem
(in this case a Quectel EC20) is performing PTS with the card.

In the log of osmo-remsim-client-st2 I can see:

SIMtrace => PTS req: ff 10 94 7b 00 00
SIMtrace -> 01 07 00 00 00 00 15 00 04 ff 10 94 7b 00 00 ff 10 94 7b
SIMtrace => PTS req: ff 10 94 7b 00 00
SIMtrace IRQ 01 04 00 00 00 00 15 00 13 00 00 00 00 00 09 04 0a 80 25 00 00

after which the communication doesn't proceed. After a long time, the
modem seems to retry without PTS and then proceeds with normal SIM card
communication.

Interestingly, both the firmware and a usbmon trace agree that the first
APDU header after the PTS is actually sent in an USB IN transfer:

-I- 0: computed Fi(1) Di(1) ratio: 372
-I- 0: computed Fi(9) Di(4) ratio: 64
-I- 0: send_tpdu_header: 00 a4 00 04 02
-I- 0: flush_rx_buffer (5)

usbmon shows 010600000000130001000000050000a4000402

It's unclear why the host program doesn't get the data from the IN
transfer.  However, if multiple asynchronous IN EP URB are submited,
the problem can be reproducibly avoided.  Let's do that.

Change-Id: I2fa5f71869b124b73e0c312befce1ca268e9a9a2
Closes: OS#4409
2020-02-21 22:09:45 +01:00
Harald Welte 44866d501b client: user_shell.c: Don't echo stdin on stdout
This is a debug statement that shouldn't be in the code anymore

Change-Id: I6601e06c843ee7c8d151011af072186bfc5d3efa
2020-02-18 23:02:51 +01:00
Harald Welte 82368402af client: user_shell.c: fflush() after writes to stdout
This is useful if we have external programs interfacing with
stdin/stdout of osmo-remsim-client-shell.  We don't want that output
to hang in some buffer indefinitely, but rather have the lines flushed
immediately.

Change-Id: I6879f9f186ce87e0644b3d7868fc5ea031b82c62
2020-02-18 23:02:51 +01:00
Harald Welte 1b6696f144 client: Make ConfigClientBankReq with bankd_port == 0 trigger SRVC_E_DISCONNECT
If the server sends us ConfigClientBankReq with bankd_port == 0, then
this means that we shall disconnect from the bankd.  Translate this to
the SRVC_E_DISCONNECT event towards the RSPRO connection FSM.

Change-Id: Idbfbfa0e84fa14dcb913b4dcbd943bc80ec175ac
Related: OS#4399
2020-02-18 23:02:51 +01:00
Harald Welte a9caad86e0 client: Split into remsim_client.c and remsim_client_main.c
Change-Id: Ie1d21c2cd84756d5c8aa2c41bcc37f5951a3a285
2020-02-16 15:41:56 +01:00
Harald Welte 879ee414f0 client: Remove g_client completely; separate 'main' code
We may want to use the entire client code independent of the current
'main' portion, so let's introduce separation via API.

Change-Id: I6456317c3968551cd69ba379c746e4dd9690d02d
2020-02-16 15:41:56 +01:00
Harald Welte 8e46ab6755 client: Work without global g_client variable
We may want to develop programs that include multiple instances of
a remsim_client.  Let's remove the global variable 'g_client' and
instead de-reference the bankd_client using container_of() macros

Change-Id: I456fb633561b88912be2f78c3e0264794d921255
2020-02-16 15:41:56 +01:00
Harald Welte 1200c820f0 client: Add new osmo-remsim-client-shell binary
This is a remsim-client with an interactive 'shell', where the user
can type in C-APDUs in hex formats, which will be sent to the bankd /
SIM-card.  Responses received from SIM Card via bankd will be printed
in return.

Change-Id: I636505fd9741833ccf5cbd1bcac30f7b9aa94425
2020-02-16 15:41:56 +01:00
Harald Welte d5a8729291 client: Adjust to API changes; enable build of remsim-client again
There were quite a bit of API changes that hadn't yet been applied
to remsim_client.c (which was disabled and hence not compiled for
quite some time).

Change-Id: I0b3733f6851a951ee24ae87aa5db0ee8daa7a841
2020-02-16 15:41:56 +01:00
Harald Welte 55c7f44194 remsim-client: Call an external script in specific situations
There are some situations where remsim-client would want to make its
surrounding system aware of, e.g. to take specific action.

This is particularly important on platforms where the simtrace2 firmware
doesn't have direct control over modem reset/poweron or the like.

Change-Id: I61cf4d93c669db137de801f8b147dcffaa6f3abd
Depends: libosmocore.git Ib24ac8a083db32e55402ce496a5eabd8749cc888
Closes: OS#4332
2020-02-16 15:41:56 +01:00
Harald Welte 499e1d90b5 remsim-client: Query + Store the USB device path
While the user may have specified a USB path at the command line
(or not), let's make sure we obtain the actual path after opening
the respective USB device.

Change-Id: I7e707c74647f4c5db06d495d369b2e69e2fc7c97
2020-02-16 15:41:56 +01:00
Harald Welte 943ae6286a remsim-client: store last 'status'
Keep a local copy of the last status message of the cardem
firmware.

Change-Id: I5b348035da8f0905364b67f21f5c7be112b20e70
2020-02-16 15:41:56 +01:00
Harald Welte 6a0248b224 remsim-client: Move client_config from .c to .h file
Change-Id: I158fe0f2791c164adc74cf851d5a139990bce852
2020-02-16 15:41:56 +01:00
Harald Welte 5ed4693a84 remsim-client: Avoid using 'ci' global variable
Rather, pass it around between functions and attach it to other state.

Also, make it a talloc contxt so other objects can be allocated off it.

Change-Id: I25f592581382238d5640c1f6326dec745f8d1d40
2020-02-16 15:41:56 +01:00
Harald Welte a9bc4de83b remsim-client: Fix the -k/ --keep-running option
When introducing asynchronous USB support in Change-Id
Ic18690b3c2cbc5e99de0665c0b68b7555433b3cd, we accidentially
broke the --keep-running behavior, where even a disappearing USB
device will not terminate the remsim-client process.

Change-Id: I19cca9f7953d61058a36856b2fc4c97a3b93e15d
2020-02-16 15:41:56 +01:00