Commit Graph

277 Commits

Author SHA1 Message Date
Harald Welte 7293e7bcec logging: Replace remaining fprintf() calls with libosmocore logging
Change-Id: I2a772b3180131923d4e2ee7311670b938cb50fe0
2021-12-09 07:58:15 +01:00
Harald Welte a9d7ad1175 switch to libosmocore multihread-logging
When osmo-remsim was originally developed, libosmocore logging was
not yet thread-safe.  This meant that the worker threads of remsim-bankd
and remsim-server could not log via the libosmocore logging framework
but directly used stderr/stdout, which produced rather inconsistent log
output.

However, since 1.3.0, libosmocore has received support for
multi-threaded applications.  Let's make use of this and consistently
use it in remsim-server and remsim-bankd.  This obviously also means
adding some more log categories.

Change-Id: I7bd5264c559b756927046563a2d00c54826bee9b
2021-12-08 21:17:15 +01:00
Harald Welte 46122ab94e Add separate log category for RSPRO protocol
Change-Id: I2e158f5181a24ae2256aae12d26865c4907eabad
2021-12-08 21:16:00 +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 f8c6eeb5cd [cosmetic] bankd: mark handle_options() as static
Change-Id: I991542d8fb52cc86e850bf5d20352c802f77c392
2021-12-08 20:45:30 +01:00
Harald Welte 0c7f7d45ca Change default log level to INFO
this will drop printing DEBUG level messages by default.

Change-Id: I8ecb17674d480988847d7fa23b586b66fa52010a
2021-12-08 20:45:26 +01:00
Harald Welte 8934412ce5 rspro_client_fsm: Differentiate different log levels
Raw Rx/Tx of messages should be LOGL_DEBUG, while connection
establishment/loss should be something like LOGL_NOTICE.

Change-Id: I1bc6d491a8a748cbd729cbdeede60d32bd760a15
2021-12-08 20:44:26 +01:00
Harald Welte 50a0972a87 bankd_pcsc: Don't log every successful SCardTransmit
Contrary to other operations, SCardTransmit has a much higher frequency
and the logs should not be clobbered with "OK" lines all over the place.

Change-Id: Icf87b61d71722b2998ae78f9aee7c4ad94c46da7
2021-12-08 20:44:23 +01:00
Harald Welte 9f7ca61bb5 bankd_main: Improve log usefulness
Right now we get duplicate log lines like

[000 CONN_CLIENT_MAPPED_CARD] bankd_main.c:662 Rx RSPRO tpduModemToCard
[000 CONN_CLIENT_MAPPED_CARD] bankd_main.c:623 tpduModemToCard(0070000001)

Where the first line is printed by the generic receive handler for RSPRO
messages, while the second line is from the specific handler function
handling the specific message type.

Let's only print from the generic message handler if no specific
handler function exists.

Change-Id: I992c847e0081bd1cd8a0b70212618c4980d9db81
2021-12-08 15:57:57 +01:00
Harald Welte 168d72478e bankd_pcsc: Improve logging in non-error case
Before this commit, the PCSC operation (e.g. SCardStatus) is only
printed in the error case, but not in the debug case.  Let's fix that.

[000 CONN_CLIENT_MAPPED_CARD] bankd_pcsc.c:196 : OK

	will become

[000 CONN_CLIENT_MAPPED_CARD] bankd_pcsc.c:196 SCardTransmit: OK

Change-Id: I3c77655c5d1f76be778cb8873d8acf1343c87b05
2021-12-08 15:57:52 +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 753c8aa87a bankd: regex matching of reader names
So far, bankd did a 1:1 string match of the CSV file line against
the reader name.  As pcsc-lite reader names unfortunately tend to
change at times, we introduce matching by regular expressions in
this patch.

Change-Id: I58b71f9562e152e7ed21b55d7b876bba481b01f8
2021-02-03 08:46:21 +00: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 a5daec426e Use OSMO_FD_* instead of deprecated BSC_FD_*
Change-Id: Ice73ab253ae038848c791871693ba2e5c3352ffc
2020-10-18 22:40:42 +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 afc6c6881d rspro_util.c: Use %zu for size_t
Fix the following warning in 32bit builds on ARM:

rspro_util.c:92:53: warning: format '%lu' expects argument of type 'long unsigned int', but argument 4 has type 'size_t {aka unsigned int}' [-Wformat=]

Change-Id: I7ea17f8b9fdd68cdac442bf4d4e518f92292f6fc
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 7cd8b76577 bankd: Avoid useless dependency to libosmosim
Change-Id: I015b1a49dbdd19d030acd929b5a935021b77cefa
dpkg-shlibdeps: warning: package could avoid a useless dependency if debian/osmo-remsim-bankd/usr/bin/osmo-remsim-bankd was not linked against libosmosim.so.0 (it uses none of the library's symbols)
2020-03-04 19:15:32 +01:00
Harald Welte f14f337d06 libosmo-rspro: Avoid useless dependency to libosmo-abis
Change-Id: I124003dafb7b90664e6614965990243771be62a9
dpkg-shlibdeps: warning: package could avoid a useless dependency if debian/libosmo-rspro1/usr/lib/x86_64-linux-gnu/libosmo-rspro.so.1.0.0 was not linked against libosmoabis.so.6 (it uses none of the library's symbols)
2020-03-04 19:15:32 +01:00
Harald Welte 73b6d703ad Avoid useless dependency on libcsv
We don't want to link everything against libvsv.  Only bankd needs it.

Change-Id: I288c27611b042fef76101e247b41c7a2f6c7483b
dpkg-shlibdeps: warning: package could avoid a useless dependency if debian/libosmo-rspro1/usr/lib/x86_64-linux-gnu/libosmo-rspro.so.1.0.0 was not linked against libcsv.so.3 (it uses none of the library's symbols)
dpkg-shlibdeps: warning: package could avoid a useless dependency if debian/osmo-remsim-server/usr/bin/osmo-remsim-server was not linked against libcsv.so.3 (it uses none of the library's symbols)
dpkg-shlibdeps: warning: package could avoid a useless dependency if debian/osmo-remsim-client/usr/bin/osmo-remsim-client-shell debian/osmo-remsim-client/usr/bin/osmo-remsim-client-st2 were not linked against libcsv.so.3 (they use none of the library's symbols)
dpkg-shlibdeps: warning: package could avoid a useless dependency if debian/libifd-osmo-remsim-client0/usr/lib/pcsc/drivers/libifd-osmo-remsim-client.bundle/Contents/Linux/libifd_remsim_client.so.0.0.0 was not linked against libcsv.so.3 (it uses none of the library's symbols)
2020-03-04 19:15:32 +01:00
Harald Welte 2a5f44750d libosmo-rspro: Avoid useless dependency to libosmogsm
dpkg-shlibdeps: warning: package could avoid a useless dependency if debian/libosmo-rspro1/usr/lib/x86_64-linux-gnu/libosmo-rspro.so.1.0.0 was not linked against libosmogsm.so.13 (it uses none of the library's symbols)

Change-Id: I6ed59e4b1a23625653be2647f271a5d993535800
2020-03-04 19:15:32 +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 b266d508be rspro_client_fsm: Add optional notifiation of parent on connect/disconnect
This will be useful once we introduce a 'main' client FSM that is a
parent to the rspro_client_fsms.

Change-Id: Ifddb8e0b5c991e5348392c9e44612669ce207bc4
2020-03-04 16:21:34 +01:00
Harald Welte 8da220911d rspro_client_fsm: Migrate to ipa_client_conn_create2()
libosmo-abis 0.8.0 has deprecated ipa_client_conn_create() and this
follow-up patch avoids the related deprecation compiler warnings.

Change-Id: I0057c5b6a79e7226e87983c14eb2b0ed2af2a131
2020-03-04 16:21:34 +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 d938e4344f src/Makefile.am: Build src directory (libosmo-rspro) before sub-directories
This ensures that libosmo-rspro is first built/installed, before the
programs that depend on it are.

This resolves warnings like
libtool: warning: '../../src/libosmo-rspro.la' has not been installed in '/tmp/osmo-remsim/osmo-remsim-0.2.2.59-2f5c/_inst/lib'
during the build process.

Change-Id: I928ff36406986cd0d3fe493f258864a38ce37798
2020-03-04 11:21:09 +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 f43babac56 server: Don't accept out-of-range bank/client/slot numbers on REST
Change-Id: Id0c9dcda58d1f85df431a74bbfba06cfaa0af69d
2020-02-20 18:52:24 +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 16c81ea52b rspro_client_fsm: Add SRVC_E_DISCONNECT to disconnect from RSPRO server
This is in preparation of other patches which will actually issue the
SRVC_E_DISCONNET event towards this FSM.

Related: OS#4399
Change-Id: I080f9e85987bbbe7aef84c32ce84b69d949ff561
2020-02-18 23:02:51 +01:00
Harald Welte 3598c58eb8 server: Send ConfigClientBankReq with bankd_port == 0 on map delete
If a slotmap is deleted via the REST API, don't only remove it from
the bankd, but also remove it from the client.

Change-Id: Ia2fc2a098471add56cb35e74639417d865704989
Closes: OS#4399
2020-02-16 15:46:19 +01:00
Harald Welte ea3eefe433 server: don't dereference map before OSMO_ASSERT() in _update_client_for_slotmap()
Change-Id: Ib36d2ba7928ea17a508cb68748e6c50f22784227
2020-02-16 15:46:19 +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