blob: e87de52f6ea4baa8969401843c3ab920da948e7f [file] [log] [blame]
Harald Welte5103ea02020-03-04 15:31:58 +01001[[remsim-bankd]]
Harald Welte51cfec02019-04-03 09:18:44 +02002== osmo-remsim-bankd
Harald Welte5bae20b2019-04-01 09:36:42 +02003
Harald Welte51cfec02019-04-03 09:18:44 +02004The `osmo-remsim-bankd` (SIM Bank Daemon) manages one given SIM bank.
5The initial implementation supports a PC/SC driver to expose any PC/SC
Harald Welte35f2b202019-04-01 11:01:51 +02006compatible card readers as SIM bank.
7
Harald Welte51cfec02019-04-03 09:18:44 +02008`osmo-remsim-bankd` initially connects via a RSPRO control connection to
9`osmo-remsim-server` at startup, and will in turn receive a set of
10initial [client,slot]:[bankd,slot] mappings. These mappings determine
11which slot on the client (corresponding to a modem) is mapped to which
12slot on the SIM bank. Mappings can be updated by `osmo-remsim-server`
13at any given point in time.
Harald Welte35f2b202019-04-01 11:01:51 +020014
Harald Welte51cfec02019-04-03 09:18:44 +020015`osmo-remsim-bankd` implements a RSPRO server, where it listens to
16connections from `osmo-remsim-clients`.
Harald Welte35f2b202019-04-01 11:01:51 +020017
18As PC/SC only offers a blocking API, there is one thread per PC/SC slot.
19This thread will perform blocking I/O on the socket towards the client,
20and blocking API calls on PC/SC.
21
22In terms of thread handling, we do:
23
24* accept() handling in [spare] worker threads
25** this means blocking I/O can be used, as each worker thread only has
26 one TCP connection
27** client identifies itself with client:slot
28** lookup mapping based on client:slot (using mutex for protection)
29** open the reader based on the lookup result
30
31The worker threads initially don't have any mapping to a specific
32reader, and that mapping is only established at a later point after the
33client has identified itself. The advantage is that the entire bankd
34can live without any non-blocking I/O.
35
Harald Welte51cfec02019-04-03 09:18:44 +020036The main thread handles the connection to `osmo-remsim-server`, where it
37can also use non-blocking I/O. However, re-connection would be
38required, to avoid stalling all banks/cards in the event of a connection
39loss to the server.
Harald Welte35f2b202019-04-01 11:01:51 +020040
41worker threads have the following states:
42* INIT (just started)
43* ACCEPTING (they're blocking in the accept() call on the server socket fd)
44* CONNECTED_WAIT_ID (TCP established, but peer not yet identified itself)
45* CONNECTED_CLIENT (TCP established, client has identified itself, no mapping)
46* CONNECTED_CLIENT_MAPPED (TCP established, client has identified itself, mapping exists)
47* CONNECTED_CLIENT_MAPPED_CARD (TCP established, client identified, mapping exists, card opened)
48* CONNECTED_SERVER (TCP established, server has identified itself)
49
50Once the client disconnects, or any other error occurs (such as card I/O
51errors), the worker thread either returns to INIT state (closing client
52socket and reader), or it terminates. Termination would mean that the
53main thread would have to do non-blocking join to detect client
54termination and then re-spawn clients, so the "return to INIT state"
55approach seems to make more sense.
56
57
Harald Welte5bae20b2019-04-01 09:36:42 +020058=== Running
59
Harald Welte51cfec02019-04-03 09:18:44 +020060`osmo-remsim-bankd` currently has the following command-line options:
Harald Welte5bae20b2019-04-01 09:36:42 +020061
62==== SYNOPSIS
63
Harald Weltebfcca522023-07-18 19:55:43 +020064*osmo-remsim-bankd* [-h] [-V] [-d LOGOPT] -i A.B.C.D [-p <1-65535>] [-b <1-1023>] [-n <1-1023>] [-I A.B.C.D] [-P <1-65535> ]
Harald Welte5bae20b2019-04-01 09:36:42 +020065
66==== OPTIONS
67
68*-h, --help*::
69 Print a short help message about the supported options
Harald Welte6a93cfb2021-12-09 12:56:27 +010070*-V, --version*::
71 Print the software version number
72*-d, --debug LOGOPT*::
73 Configure the logging verbosity, see <<remsim_logging>>.
Harald Welte3c4d0062019-03-31 18:55:18 +020074*-i, --server-host A.B.C.D*::
Harald Welte51cfec02019-04-03 09:18:44 +020075 Specify the remote IP address/hostname of the `osmo-remsim-server` to
Harald Weltebfcca522023-07-18 19:55:43 +020076 which this bankd shall establish its RSPRO control connection. Do not specify a loopback
77 address or localhost, as this would in most cases result in a broken configuration where
78 a [usually remote] remsim-client attempts to reach the bankd via loopback, which doesn't work.
Harald Welte5bae20b2019-04-01 09:36:42 +020079*-p, --server-port <1-65535>*::
Harald Welte51cfec02019-04-03 09:18:44 +020080 Specify the remote TCP port number of the `osmo-remsim-server` to which
81 this bankd shall establish its RSPRO control connection
Harald Welte55f12b82022-01-16 14:34:12 +010082*-b, --bank-id <1-1023>*::
Harald Welte51cfec02019-04-03 09:18:44 +020083 Specify the numeric bank identifier of the SIM bank this bankd
84 instance operates. Must be unique among all banks connecting to the
85 same `osmo-remsim-server`.
Harald Welte55f12b82022-01-16 14:34:12 +010086*-n, --num-slots <1-1023>*::
Harald Welte2513d812019-04-01 21:03:02 +020087 Specify the number of slots that this bankd handles.
Harald Welte5bae20b2019-04-01 09:36:42 +020088*-I, --bind-IP A.B.C.D*::
89 Specify the local IP address to which the socket for incoming connections
Harald Welte51cfec02019-04-03 09:18:44 +020090 from `osmo-remsim-clients` is bound to.
Harald Welte5bae20b2019-04-01 09:36:42 +020091*-P, --bind-port <1-65535>*::
Harald Welte6a93cfb2021-12-09 12:56:27 +010092 Specify the local TCP port to which the socket for incoming connections
Harald Welte51cfec02019-04-03 09:18:44 +020093 from `osmo-remsim-client`s is bound to.
Harald Welte628672b2022-07-13 15:20:13 +020094*-s, --permit-shared-pcsc*::
95 Specify whether the PC/SC readers should be accessed in SCARD_SHARE_SHARED
96 mode, instead of the default (SCARD_SHARE_EXCLUSIVE). Shared mode would
97 permit multiple application programs to access a single reader/slot/card
98 concurrently. This is potentially dangerous as the two programs operate
99 without knowledge of each other, and either of them might modify the card
100 state (such as the currently selected file, validated PIN, etc.) in a
101 way not expected by the other application.
102
Harald Welte5bae20b2019-04-01 09:36:42 +0200103
Joachim Steiger68f95102019-07-03 19:03:24 +0200104==== Examples
105.remsim-server is on 10.2.3.4, cardreader has 5 slots:
106----
107osmo-remsim-bankd -i 10.2.3.4 -n 5
108----
109.remsim-server is on 10.2.3.4, cardreader has 4 slots, local ip is 10.5.4.3
110----
111osmo-remsim-bankd -i 10.2.3.4 -n 4 -I 10.5.4.3
112----
113
Harald Welte5bae20b2019-04-01 09:36:42 +0200114=== Logging
115
Harald Welte51cfec02019-04-03 09:18:44 +0200116`osmo-remsim-bankd` currently logs to stdout only, and the logging
117verbosity is not yet configurable. However, as the libosmocore logging
118framework is used, extending this is an easy modification.
Harald Welte5bae20b2019-04-01 09:36:42 +0200119
120=== `bankd_pcsc_slots.csv` CSV file
121
122bankd expects a CSV file `bankd_pcsc_slots.csv` in the current working directory at startup.
123
124This CSV file specifies the mapping between the string names of the PCSC
Harald Welte0138bb42019-04-01 11:04:04 +0200125readers and the RSPRO bandk/slot numbers. The format is as follows:
Harald Weltea06d77f2021-02-19 19:04:12 +0100126
Harald Welte753c8aa2020-10-20 23:04:59 +0200127* first column: bankd number
128* second column: slot number within bankd
129* third column: extended POSIX regular expression matching the slot
Harald Welte5bae20b2019-04-01 09:36:42 +0200130
131.Example: CSV file mapping bankd slots 0..4 to an ACS ACR33U-A1 reader slots
132----
133"1","0","ACS ACR33 ICC Reader 00 00"
134"1","1","ACS ACR33 ICC Reader 00 01"
135"1","2","ACS ACR33 ICC Reader 00 02"
136"1","3","ACS ACR33 ICC Reader 00 03"
137"1","4","ACS ACR33 ICC Reader 00 04"
138----
Harald Welte33a3e872019-05-29 20:12:32 +0200139
140You can obtain the exact string to use as PC/SC reader name from the output of the
141`pcsc_scan` utility (part of pcsc-lite package). The tool will produce output like:
142
143.Example: Output of `pcsc_scan` utility on a system with a single reader installed
144----
145Scanning present readers...
1460: Alcor Micro AU9560 00 00
147----
148
149In this example, there's only a single PC/SC reader available, and it has a string of
Harald Welte753c8aa2020-10-20 23:04:59 +0200150"Alcor Micro AU9560 00 00" which needs to be used in the CSV file.
151
152NOTE:: If the reader name contains any special characters, they might need to be escaped according
153to the extended POSIX regular expression syntax. See `man 7 regex` for a reference.
154
155.Example: CSV file mapping bankd slots 0..7 to a sysmoOCTSIM:
156----
157"1","0","sysmocom sysmoOCTSIM \[CCID\] \(ab19180f3335355320202034463a15ff\) [0-9]{2} 00"
158"1","1","sysmocom sysmoOCTSIM \[CCID\] \(ab19180f3335355320202034463a15ff\) [0-9]{2} 01"
159"1","2","sysmocom sysmoOCTSIM \[CCID\] \(ab19180f3335355320202034463a15ff\) [0-9]{2} 02"
160"1","3","sysmocom sysmoOCTSIM \[CCID\] \(ab19180f3335355320202034463a15ff\) [0-9]{2} 03"
161"1","4","sysmocom sysmoOCTSIM \[CCID\] \(ab19180f3335355320202034463a15ff\) [0-9]{2} 04"
162"1","5","sysmocom sysmoOCTSIM \[CCID\] \(ab19180f3335355320202034463a15ff\) [0-9]{2} 05"
163"1","6","sysmocom sysmoOCTSIM \[CCID\] \(ab19180f3335355320202034463a15ff\) [0-9]{2} 06"
164"1","7","sysmocom sysmoOCTSIM \[CCID\] \(ab19180f3335355320202034463a15ff\) [0-9]{2} 07"
165----
166
167In the above example, the +\[CCID\]+ and the +\(serialnumber\)+ both had to be escaped.
168
169The +[0-9]\{2\}+ construct exists to perform wildcard matching, no matter which particular two-digit number
170pcscd decides to use.
Stephan Skrodzki239458e2023-05-15 17:32:45 +0200171
172.Example: CSV file mapping bankd slot 0 to a OMNIKEY 3x21 Smart Card Reader:
173----
174"1","0","HID Global OMNIKEY 3x21 Smart Card Reader \[OMNIKEY 3x21 Smart Card Reader\] 00 00"
175----
176