blob: cb3061c74fbb5f3654e1e559e0bfc0360f28543e [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 Welte55f12b82022-01-16 14:34:12 +010064*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
76 which this bankd shall establish its RSPRO control connection
Harald Welte5bae20b2019-04-01 09:36:42 +020077*-p, --server-port <1-65535>*::
Harald Welte51cfec02019-04-03 09:18:44 +020078 Specify the remote TCP port number of the `osmo-remsim-server` to which
79 this bankd shall establish its RSPRO control connection
Harald Welte55f12b82022-01-16 14:34:12 +010080*-b, --bank-id <1-1023>*::
Harald Welte51cfec02019-04-03 09:18:44 +020081 Specify the numeric bank identifier of the SIM bank this bankd
82 instance operates. Must be unique among all banks connecting to the
83 same `osmo-remsim-server`.
Harald Welte55f12b82022-01-16 14:34:12 +010084*-n, --num-slots <1-1023>*::
Harald Welte2513d812019-04-01 21:03:02 +020085 Specify the number of slots that this bankd handles.
Harald Welte5bae20b2019-04-01 09:36:42 +020086*-I, --bind-IP A.B.C.D*::
87 Specify the local IP address to which the socket for incoming connections
Harald Welte51cfec02019-04-03 09:18:44 +020088 from `osmo-remsim-clients` is bound to.
Harald Welte5bae20b2019-04-01 09:36:42 +020089*-P, --bind-port <1-65535>*::
Harald Welte6a93cfb2021-12-09 12:56:27 +010090 Specify the local TCP port to which the socket for incoming connections
Harald Welte51cfec02019-04-03 09:18:44 +020091 from `osmo-remsim-client`s is bound to.
Harald Welte628672b2022-07-13 15:20:13 +020092*-s, --permit-shared-pcsc*::
93 Specify whether the PC/SC readers should be accessed in SCARD_SHARE_SHARED
94 mode, instead of the default (SCARD_SHARE_EXCLUSIVE). Shared mode would
95 permit multiple application programs to access a single reader/slot/card
96 concurrently. This is potentially dangerous as the two programs operate
97 without knowledge of each other, and either of them might modify the card
98 state (such as the currently selected file, validated PIN, etc.) in a
99 way not expected by the other application.
100
Harald Welte5bae20b2019-04-01 09:36:42 +0200101
Joachim Steiger68f95102019-07-03 19:03:24 +0200102==== Examples
103.remsim-server is on 10.2.3.4, cardreader has 5 slots:
104----
105osmo-remsim-bankd -i 10.2.3.4 -n 5
106----
107.remsim-server is on 10.2.3.4, cardreader has 4 slots, local ip is 10.5.4.3
108----
109osmo-remsim-bankd -i 10.2.3.4 -n 4 -I 10.5.4.3
110----
111
Harald Welte5bae20b2019-04-01 09:36:42 +0200112=== Logging
113
Harald Welte51cfec02019-04-03 09:18:44 +0200114`osmo-remsim-bankd` currently logs to stdout only, and the logging
115verbosity is not yet configurable. However, as the libosmocore logging
116framework is used, extending this is an easy modification.
Harald Welte5bae20b2019-04-01 09:36:42 +0200117
118=== `bankd_pcsc_slots.csv` CSV file
119
120bankd expects a CSV file `bankd_pcsc_slots.csv` in the current working directory at startup.
121
122This CSV file specifies the mapping between the string names of the PCSC
Harald Welte0138bb42019-04-01 11:04:04 +0200123readers and the RSPRO bandk/slot numbers. The format is as follows:
Harald Weltea06d77f2021-02-19 19:04:12 +0100124
Harald Welte753c8aa2020-10-20 23:04:59 +0200125* first column: bankd number
126* second column: slot number within bankd
127* third column: extended POSIX regular expression matching the slot
Harald Welte5bae20b2019-04-01 09:36:42 +0200128
129.Example: CSV file mapping bankd slots 0..4 to an ACS ACR33U-A1 reader slots
130----
131"1","0","ACS ACR33 ICC Reader 00 00"
132"1","1","ACS ACR33 ICC Reader 00 01"
133"1","2","ACS ACR33 ICC Reader 00 02"
134"1","3","ACS ACR33 ICC Reader 00 03"
135"1","4","ACS ACR33 ICC Reader 00 04"
136----
Harald Welte33a3e872019-05-29 20:12:32 +0200137
138You can obtain the exact string to use as PC/SC reader name from the output of the
139`pcsc_scan` utility (part of pcsc-lite package). The tool will produce output like:
140
141.Example: Output of `pcsc_scan` utility on a system with a single reader installed
142----
143Scanning present readers...
1440: Alcor Micro AU9560 00 00
145----
146
147In this example, there's only a single PC/SC reader available, and it has a string of
Harald Welte753c8aa2020-10-20 23:04:59 +0200148"Alcor Micro AU9560 00 00" which needs to be used in the CSV file.
149
150NOTE:: If the reader name contains any special characters, they might need to be escaped according
151to the extended POSIX regular expression syntax. See `man 7 regex` for a reference.
152
153.Example: CSV file mapping bankd slots 0..7 to a sysmoOCTSIM:
154----
155"1","0","sysmocom sysmoOCTSIM \[CCID\] \(ab19180f3335355320202034463a15ff\) [0-9]{2} 00"
156"1","1","sysmocom sysmoOCTSIM \[CCID\] \(ab19180f3335355320202034463a15ff\) [0-9]{2} 01"
157"1","2","sysmocom sysmoOCTSIM \[CCID\] \(ab19180f3335355320202034463a15ff\) [0-9]{2} 02"
158"1","3","sysmocom sysmoOCTSIM \[CCID\] \(ab19180f3335355320202034463a15ff\) [0-9]{2} 03"
159"1","4","sysmocom sysmoOCTSIM \[CCID\] \(ab19180f3335355320202034463a15ff\) [0-9]{2} 04"
160"1","5","sysmocom sysmoOCTSIM \[CCID\] \(ab19180f3335355320202034463a15ff\) [0-9]{2} 05"
161"1","6","sysmocom sysmoOCTSIM \[CCID\] \(ab19180f3335355320202034463a15ff\) [0-9]{2} 06"
162"1","7","sysmocom sysmoOCTSIM \[CCID\] \(ab19180f3335355320202034463a15ff\) [0-9]{2} 07"
163----
164
165In the above example, the +\[CCID\]+ and the +\(serialnumber\)+ both had to be escaped.
166
167The +[0-9]\{2\}+ construct exists to perform wildcard matching, no matter which particular two-digit number
168pcscd decides to use.