blob: ab7a362a4534b2d8672b428900b4dc76a4d60491 [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 Welte51cfec02019-04-03 09:18:44 +020064*osmo-remsim-bankd* [-h] [-i A.B.C.D] [-p <1-65535>] [-b <1-65535>] [-n <1-65535>] [-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 Welte3c4d0062019-03-31 18:55:18 +020070*-i, --server-host A.B.C.D*::
Harald Welte51cfec02019-04-03 09:18:44 +020071 Specify the remote IP address/hostname of the `osmo-remsim-server` to
72 which this bankd shall establish its RSPRO control connection
Harald Welte5bae20b2019-04-01 09:36:42 +020073*-p, --server-port <1-65535>*::
Harald Welte51cfec02019-04-03 09:18:44 +020074 Specify the remote TCP port number of the `osmo-remsim-server` to which
75 this bankd shall establish its RSPRO control connection
Harald Welte5bae20b2019-04-01 09:36:42 +020076*-b, --bank-id <1-65535>*::
Harald Welte51cfec02019-04-03 09:18:44 +020077 Specify the numeric bank identifier of the SIM bank this bankd
78 instance operates. Must be unique among all banks connecting to the
79 same `osmo-remsim-server`.
Harald Welte2513d812019-04-01 21:03:02 +020080*-n, --num-slots <1-65535>*::
81 Specify the number of slots that this bankd handles.
Harald Welte5bae20b2019-04-01 09:36:42 +020082*-I, --bind-IP A.B.C.D*::
83 Specify the local IP address to which the socket for incoming connections
Harald Welte51cfec02019-04-03 09:18:44 +020084 from `osmo-remsim-clients` is bound to.
Harald Welte5bae20b2019-04-01 09:36:42 +020085*-P, --bind-port <1-65535>*::
86 Specify the local TCP port to whicc the socket for incoming connections
Harald Welte51cfec02019-04-03 09:18:44 +020087 from `osmo-remsim-client`s is bound to.
Harald Welte5bae20b2019-04-01 09:36:42 +020088
Joachim Steiger68f95102019-07-03 19:03:24 +020089==== Examples
90.remsim-server is on 10.2.3.4, cardreader has 5 slots:
91----
92osmo-remsim-bankd -i 10.2.3.4 -n 5
93----
94.remsim-server is on 10.2.3.4, cardreader has 4 slots, local ip is 10.5.4.3
95----
96osmo-remsim-bankd -i 10.2.3.4 -n 4 -I 10.5.4.3
97----
98
Harald Welte5bae20b2019-04-01 09:36:42 +020099=== Logging
100
Harald Welte51cfec02019-04-03 09:18:44 +0200101`osmo-remsim-bankd` currently logs to stdout only, and the logging
102verbosity is not yet configurable. However, as the libosmocore logging
103framework is used, extending this is an easy modification.
Harald Welte5bae20b2019-04-01 09:36:42 +0200104
105=== `bankd_pcsc_slots.csv` CSV file
106
107bankd expects a CSV file `bankd_pcsc_slots.csv` in the current working directory at startup.
108
109This CSV file specifies the mapping between the string names of the PCSC
Harald Welte0138bb42019-04-01 11:04:04 +0200110readers and the RSPRO bandk/slot numbers. The format is as follows:
Harald Weltea06d77f2021-02-19 19:04:12 +0100111
Harald Welte753c8aa2020-10-20 23:04:59 +0200112* first column: bankd number
113* second column: slot number within bankd
114* third column: extended POSIX regular expression matching the slot
Harald Welte5bae20b2019-04-01 09:36:42 +0200115
116.Example: CSV file mapping bankd slots 0..4 to an ACS ACR33U-A1 reader slots
117----
118"1","0","ACS ACR33 ICC Reader 00 00"
119"1","1","ACS ACR33 ICC Reader 00 01"
120"1","2","ACS ACR33 ICC Reader 00 02"
121"1","3","ACS ACR33 ICC Reader 00 03"
122"1","4","ACS ACR33 ICC Reader 00 04"
123----
Harald Welte33a3e872019-05-29 20:12:32 +0200124
125You can obtain the exact string to use as PC/SC reader name from the output of the
126`pcsc_scan` utility (part of pcsc-lite package). The tool will produce output like:
127
128.Example: Output of `pcsc_scan` utility on a system with a single reader installed
129----
130Scanning present readers...
1310: Alcor Micro AU9560 00 00
132----
133
134In this example, there's only a single PC/SC reader available, and it has a string of
Harald Welte753c8aa2020-10-20 23:04:59 +0200135"Alcor Micro AU9560 00 00" which needs to be used in the CSV file.
136
137NOTE:: If the reader name contains any special characters, they might need to be escaped according
138to the extended POSIX regular expression syntax. See `man 7 regex` for a reference.
139
140.Example: CSV file mapping bankd slots 0..7 to a sysmoOCTSIM:
141----
142"1","0","sysmocom sysmoOCTSIM \[CCID\] \(ab19180f3335355320202034463a15ff\) [0-9]{2} 00"
143"1","1","sysmocom sysmoOCTSIM \[CCID\] \(ab19180f3335355320202034463a15ff\) [0-9]{2} 01"
144"1","2","sysmocom sysmoOCTSIM \[CCID\] \(ab19180f3335355320202034463a15ff\) [0-9]{2} 02"
145"1","3","sysmocom sysmoOCTSIM \[CCID\] \(ab19180f3335355320202034463a15ff\) [0-9]{2} 03"
146"1","4","sysmocom sysmoOCTSIM \[CCID\] \(ab19180f3335355320202034463a15ff\) [0-9]{2} 04"
147"1","5","sysmocom sysmoOCTSIM \[CCID\] \(ab19180f3335355320202034463a15ff\) [0-9]{2} 05"
148"1","6","sysmocom sysmoOCTSIM \[CCID\] \(ab19180f3335355320202034463a15ff\) [0-9]{2} 06"
149"1","7","sysmocom sysmoOCTSIM \[CCID\] \(ab19180f3335355320202034463a15ff\) [0-9]{2} 07"
150----
151
152In the above example, the +\[CCID\]+ and the +\(serialnumber\)+ both had to be escaped.
153
154The +[0-9]\{2\}+ construct exists to perform wildcard matching, no matter which particular two-digit number
155pcscd decides to use.