Commit Graph

321 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 as default IP address for the server
If remsim-bankd connects via or any other loopback-routed
IP address to the remsim-server, then the getpername() of remsim-server
for the bankd will also render, 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

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 7703150eaf user_simtrace2: Fix uninitialized ifm->path
Let's memset the entire ifm before calling

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
Harald Welte 189515f199 rspro_client_fsm: Fix integer overflow calculating re-establishment delay
Fixes: CID#307493: Unintentional integer overflow (OVERFLOW_BEFORE_WIDEN)
Change-Id: Ib1cca5ac0d27807936a52e0c013f0442350ecc00
2023-07-18 13:34:14 +02:00
Oliver Smith c7287ce580 src/rspro: regenerate to fix misleading indents
After upgrading our CI environment to use Debian 12 with
GCC 12, it complains about the following misleading indentations.
Regenerate the rspro code with asn1c
I2260df8f8ab8eaf5c2aac3c330f87dba4691c01e to be able to compile with
--enable-werror again.

The asn_internal.h file is left unchanged to preserve changes from

Related: OS#6057
Change-Id: Icc2e8da7232a93b04ac8f23800380ca9317bd60f
2023-07-17 11:52:47 +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
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

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

Closes: CID#307528
Change-Id: I29f911cb2c8ad67cf1ce4486e1583612fb0b98a6
2023-02-06 13:16:49 +01:00
Harald Welte 5426124dc7 rspro_server: Handle ipa_server_link_open() error case
>>>     CID 307530:  Error handling issues  (CHECKED_RETURN)
>>>     Calling "ipa_server_link_open" without checking return value (as is done elsewhere 4 out of 5

while at it, also add a missing pthread_rwlock_destroy() call which was
missing in the existing ipa_server_link_create() error path.

Closes: CID#307530
Change-Id: Ic32d53a236b80711651fb4ee196ac3b95148e61f
2023-02-06 13:16:02 +01:00
Harald Welte ae0d9d2e60 remsim_server: handle osmo_fd_register() failure case
>>>     CID 307531:  Error handling issues  (CHECKED_RETURN)
>>>     Calling "osmo_fd_register" without checking return value (as is done elsewhere 83 out of 97 times).

Closes: CID#307531
Change-Id: I7c2448303fba7caa27df65ac5f4d91ddf232ceb6
2023-02-06 13:14:02 +01:00
Harald Welte 2d5d4c3bee rest_api: strtoul canot return negative
>>>     CID 307538:  Control flow issues  (NO_EFFECT)
>>>     This less-than-zero comparison of an unsigned value is never true. "map_id < 0UL".

Closes: CID#307538
Change-Id: Ic5019e216dd7b26be0bd988df218a2cb5775e411
2023-02-06 13:13:53 +01:00
Harald Welte 99ea365ce7 Fix various 'uninitialized variable' bugs reported by coverity
The asn1c-generated struct definitions have an automatic _asn_ctx
member, and we never initialize that so far.  Let's do an explicit

Closes: CID#307545, CID#307543, CID#307541, CID#307536, CID#307536
Closes: CID#307534
Change-Id: I217ebbc92935aefaf55d19a14c93a24e5b8fce64
2023-02-03 20:19:44 +01:00
James Tavares b890018456 rspro_client: implement re-establish delay
- add new SRVC_ST_REESTABLISH_DELAY state with delay stipulated by table
k_reestablish_delay_s[], that implements a simple exponential-like back-off
with an upper bound.
- new function srvc_do_reestablish() is used to initiate a reestablish, and
apply the appropriate delay, if any.
- takes external delays (such as TCP connect() delay) into account, and does
not double-penalize.
- delay is reset to shortest possible if there has been no reestablish
initiated in a long time (2x greater than our longest delay). Allows for
fast reconnects even if a delay was used to connect.
- addresses issues and

Change-Id: I86cdc3ba37482e6577b429194d273a2399f32208
2022-11-19 09:21:04 +00: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
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
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 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 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 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 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 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 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 f5f5805f0c rspro_client_fsm: Log clientConnectResult != ok
This should aid debugging.

Related: SYS#5950
Change-Id: I8f584640758be0cceab61dcb333c81374da3288b
2022-05-05 19:19:33 +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 a04ff860c1 server: Fix various error paths if startup fails
Don't segfault or use heap after free if osmo-remsim-server cannot
fully initialize, e.g. due to ports already in use.

Change-Id: I558e6a0ea089a779f916aa5576341d1c55da1271
2022-05-03 18:09:14 +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 65006583c1 server: Detect duplicate client/bankd connection; drop new ones
we're dropping the current (new) connection as we don't really know which
is the "right" one. Dropping the new gives the old connection time to
timeout, or to continue to operate.  If we were to drop the old
connection, this could interrupt a perfectly working connection and opens
some kind of DoS.

Related: OS#5527
Change-Id: I00387dbc19d689415470e2f08df08a47a78b81c0
2022-05-03 18:09:14 +02:00
Harald Welte 900ee725b5 server: Fix segfault in error path (client component ID != client)
When we terminate the FSM instance, we must immediately return.

Change-Id: I8dff45daa6584ed111a8469e7b3bf90e7c939612
2022-05-03 16:28:52 +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 15e8b7f79c server: Differentiate log levels, not everything is DEBUG
Change-Id: Iee1e2f66e8675146883a6f5e355460608fe6d547
2022-04-27 09:24:21 +02:00
Harald Welte e1590df408 server: Log keep-alive timeout and TCP disconnects
Change-Id: I9912fee7fb892c724a0277d1fa52d056c11c9b73
2022-04-27 09:19:48 +02:00
Harald Welte fb48de8968 server: Log connection establishment from bankd/client; warn on localhost
If a bankd connects to the server from, then clients will
not be able to reach it unless they also run on localhost.  Warn the

Change-Id: I5446752961b039dad54aec981c1df4814779f765
2022-04-27 09:15:43 +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 5a3a0b16a0 Bump version: → 1.0.0
Change-Id: I069535801e32d045e7e42796b8ba28fa7d97e0c3
2021-12-09 09:09:49 +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

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