Commit Graph

47 Commits

Author SHA1 Message Date
arehbein 56ef474988 bankd: Use gsmtap_inst_fd2()
- Use gsmtap_inst_fd2() because gsmtap_inst_fd() is deprecated
 - Add TODO-RELEASE file

Related: OS#6213
Change-Id: I2a7736d6fba795b2c479b2a0bc371b90f838ed61
2023-10-30 12:13:10 +01:00
Harald Welte bfcca52af3 bankd: Don't use 127.0.0.1 as default IP address for the server
If remsim-bankd connects via 127.0.0.1 or any other loopback-routed
IP address to the remsim-server, then the getpername() of remsim-server
for the bankd will also render 127.0.0.1, and subsequently that IP
address will be provided to remsim-client as address to connect to.

In almost all setups, remsim-client will be running on a remote node and
hence not able to reach remsim-bankd at 127.0.0.1.

Let's turn the server-IP into a mandatory command line argument of
remsim-bankd and not use a problematic default value.

Change-Id: I3deb05e31cdf35232cf9a118d5a5fcdb5d0ab601
2023-07-21 11:10:15 +00:00
Harald Welte a4f1914501 bankd_main: Avoid uninitialized variable
There's not really any ResultCode for the kind of error we encounter,
but sending some uninitialized memory clearly is not the right way
either.

>>>     CID 307528:  Uninitialized variables  (UNINIT)
>>>     Using uninitialized value "res".

Closes: CID#307528
Change-Id: I29f911cb2c8ad67cf1ce4486e1583612fb0b98a6
2023-02-06 13:16:49 +01: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
James Tavares 31e8bd786b bankd: Add GSMTAP functionality for SIM traffic
If a --gsmtap-host (-g) address is specified on the command line, trace
SIM ATRs and APDUs to the given IP. If --gsmtap-slot (-G) is provided,
limit tracing to the specified bank slot number. This feature may be
useful when diagnosing issues with the remote SIM framework.

Added new log category: DGSMTAP

Also, cleaned up alignment in bankd --help output and removed unused -o option.

Change-Id: I05b599858d8758633aa56c3f12f258c27cf42d08
2022-11-19 09:18:16 +00:00
James Tavares f74d1dab7a bankd: edge detect RESET and VCC indications
- perform edge detection on RESET and VCC client indications to filter
out duplicate resets
- prior to this change, unrelated changes in the client slot status
indication (such as CLK change) could trigger duplicate resets
- these resets could happen in rapid succession and lead to reader
libusb communication errors that lock-up the PC/SC daemon
- a drop in VCC will always induce a cold reset, even if a warm
reset is already in progress.
- overall, this change better matches what the hardware would do

Change-Id: I36d30d176c0a03d97554112ca712d658d986c752
2022-11-14 10:46:43 +00:00
James Tavares 2c0a51205d bankd: add missing -p short form option
Change-Id: I44969c70612a25184fc51b695c7dbf97865fb116
2022-11-13 23:22:22 -05:00
Harald Welte f4be5e16f2 bankd: Don't log an "Error" if slotmap is removed
removing a slotmap and the related client disconnect are perfectly
normal operation. Don't print the word Error in the log in such cases,
it just confuses the user.

Closes: OS#5629
Change-Id: Ie39d35fd348fdf3dd53c860dc830aac794a3ead5
2022-07-24 13:38:16 +02:00
Harald Welte 628672bc72 bankd: Open PC/SC by default in EXCLUSIVE mode
Let's open the cards in EXCLUSIVE mode, we don't want other applications
tinkering with the card state while we have a bankd worker running on
it.  This change also means that no two bankd workers can trip on
each other accidentially anymore.

Related: OS#5527
Change-Id: I43a1c8c7bd1c0124ee5f605e2e5b04ed8f7836ab
2022-07-15 08:22:29 +02:00
Harald Welte 001884c5c1 bankd: Log not just ModemToCard but also CardToModem
This way we'll get a full trace of commands and repsonses.

Right now the log only shows one direction which is a bit odd.

Related: OS#5615
Change-Id: Ia2de0b850ce78074a411cf0edebfb3ad19253d34
2022-07-11 23:58:03 +02:00
Harald Welte bc2e6e3385 bankd: log BankID:SlotNr in every log line
It's relatively inconvenient having to mentally map the slot-number to a
thread-id on every (re)connect to correlate the logs.

The logs should contain the Bank/Slot number they relate to.

Closes: OS#5611
Change-Id: I84879609781a301338dacde7ff495632e3af08b9
2022-07-11 22:14:17 +02:00
Harald Welte 7f8bce4f06 bankd: Log more clearly if we fail to open a PC/SC reader
Related: SYS#5950
Change-Id: I424f585a8a37f21806898e59e350201119645a21
2022-05-05 19:08:13 +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 e9e505c7c5 bankd: Better error messages during start-up
If something goes wrong during startup (missing CSV file, ...)
let's print a more human-readable error message than just asserting.

Change-Id: I95222d44eefc60ad3857fa70ccebbacce60820df
2022-05-03 18:09:14 +02:00
Harald Welte 079c068467 bankd: Differentiate log levels, not everything is DEBUG
Change-Id: If3699642fee2d5d92fb164f7f9c41ccff02007cc
2022-04-27 09:26:52 +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 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 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 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 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 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 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 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 f7598fe417 remsim-client: move from common 'src' directory to 'src/client'
As both the bankd and the server already are in src/bankd and
src/server, respectively: Let's unify this and have the client
also in its own sub-directory.

Change-Id: I67a3a5941434f09f7099c2cdb19c126cea305a73
2020-02-16 15:41:12 +01:00
Harald Welte bbd18bd7fe bankd: Implement card reset based on clientSlotStatusInd
If a client is sending us a clientSlotStatusInd indicating that
the modem has switched off VCC or activated RST, bankd will
now issue a respective PC/SC command to perform a cold or warm
reset of the card.

Change-Id: Ifa615d239ec3ad6daebd8e99e4f7d5b99d32c0e1
Closes: OS#4330
2019-12-17 13:31:20 +01:00
Harald Welte 0fd77a5790 bankd: Introduce SIGMAPADD to tell worker about new mapping
So far the wokrer used to sleep 10s and only check in those intervals
if [finally] a mapping had arrived.  Using SIGMAPADD, we can
directly break the worker out of its select() call and hence make
it pick up a new mapping instantaneously.

This also makes RemsimBankd_Tests.TC_removeMapping_connected() pass

Change-Id: If0130ab4b49ffcae6ab7a8b9926a6d9477eb3981
2019-12-15 00:11:43 +01:00
Harald Welte a49678309d bankd: Factor out signal-sending from bankd_srvc_remove_mapping()
This way we can also deliver other signals to workers.

Change-Id: I86744554187d5bcee75592427990d404889f29fe
2019-12-15 00:11:43 +01:00
Harald Welte d2192e27ce rspro_client_fsm: Disable automatic connect on FSM allocation
So far, the rspor_client_fsm immediately attempted to establish a
TCP connection to the RSPRO server when calling server_conn_fsm_alloc().

Let's make this implicit auto-connect an explicit request to connect
using the newly-introduced SRVC_E_ESTABLISH.

Let's also change all three existing users of server_conn_fsm_alloc()
to send SRVC_E_ESTABLISH after calling it.

The rationale of this change is to use the same rspro_client_fsm also
for the client->bankd RSPRO connection, where we don't want to
automatically connect at startup, but connect only at a later point, after the
server a has told us to do so.

Change-Id: Icd882405f2ef54e10a66054829c089e4985f1d1f
2019-12-05 08:56:27 +01:00
Harald Welte a8d945e191 bankd: No need to handle SIGMAPDEL if we're not mapped yet
Change-Id: I187b833a9b7ec3d3763e21b5c88a3fa39ba0c4c7
2019-12-04 22:25:37 +01:00
Harald Welte f34fb79cc1 bankd: Implement new ResetStateReq
Change-Id: Ib794e605162903a2b2c4f4516887ec91fc8d139a
2019-12-04 22:25:37 +01:00
Harald Welte cd7fcd717c Add "--version" to all executables to print compile-time version info
Change-Id: I9ae504ff95beeefb9e90e02a576861351ea9e143
2019-12-04 21:13:24 +00:00
Harald Welte 602b6f7763 bankd: initialize bank_id/slot_nr to 0xffff for unmapped workers
Otherwise the loop for SIGMAPDEL delivery code will match any
unused worker for bank_id=0/slot_nr=0, which is not what we want.

This also makes repeated RemsimBankd_Tests.TC_removeMapping_connected
runs work reliably.

Change-Id: I6976eb96feae6a3b66bacf787e436a2df29f9ce0
2019-12-04 21:52:58 +01:00
Harald Welte d9fb93991b bankd: Reject removeSlotmap when ClientID doesn't match
It's a bit of a matter of taste whether we should simply log + ignore
if the Client of a removeMappingReq doesn't match what the bankd
currently has configured.  I chose to reject it, as a new createMapping
for the same bandk+slot will overwrite any existing mapping anyway,
at least as of I83e319d22896b881c0d882542842f500075aa546

Change-Id: I892282821f4650614d1d08ed4bdf11eaabf947c0
2019-12-04 21:24:10 +01:00
Harald Welte e6fa46acd5 bankd: createMapping should implicitly delete existing mappings
As explained in OS#4278, a remsim-bankd currently doesn't recover after
a remsim-server resetart, since old mappings remain in the bankd, and
the server has no chance of removing them.

To avoid this problem, a createMapping now always implicitly removes
any existing mapping that may exist for the given bankdSlot.

Change-Id: I83e319d22896b881c0d882542842f500075aa546
Closes: OS#4278
2019-12-04 21:24:10 +01:00
Harald Welte 550b2958d3 bankd: Fix log print during removeMapping
We need to dereference 'rreq' nor 'creq' in the remove handling.

Change-Id: I04e9e2447336f7d1aaeb932928a79bb705aa0c5a
2019-12-04 21:24:10 +01:00
Harald Welte c650a4daec bankd_main: Refactor code: bankd_srvc_remove_mapping()
Change-Id: Iceb1d015e0ea760cce2cd99bc22ae0149bdb42f1
2019-12-04 15:08:10 +01:00
Harald Welte 667d694a38 bankd: send IPA CCM ID_ACK after receiving ID_ACK
It is customary in the IPA protocol that a a server side
responds with an ID_ACK if the client sends an ID_ACK.  Due
to the lack of any protocol specification, it's unclear why
exactly, but we know it does happen.

osmo-remsim-bankd so far failed to implement this, which is
not directly a problem as the only user (osmo-remsim-client)
didn't care.  However, when executing TTCN3 test cases,
the IPA_Emulation expects that ID_ACK and related test fail.

Change-Id: Ie55c9d5c435df786e97ec3900837bb21ab80140a
2019-12-03 16:42:47 +01:00
Joachim Steiger 9c963dca66 osmo-remsim-bankd: Fix typo in help for --num-slots
Change-Id: If09833f0d0ba46d7bb204ac9b3b7f8128b4b3799
2019-05-25 00:49:32 +02:00
Harald Welte e89fecda6a bankd: Don't read CSV file until _after_ handling options
Otherwise "--help" won't work if the CSV cannot be found/read.

Change-Id: I162c40e267ea64a52baf2b5c819d9d2658daf77d
2019-05-08 17:23:58 +02:00
Harald Welte d7468e0b8c configure.ac: Add --disable-remsim-bankd
This allows builds on small/embedded platforms to avoid all the
dependencies required by remsim-bankd, including libpcsc-lite

Change-Id: I29a1a0131fdfea6742ec12d81228879066b1ff7e
2019-04-03 13:11:57 +02:00