blob: be9b2c0b8e497cfa22fc16383bc2733433a60917 [file] [log] [blame]
Harald Welte51cfec02019-04-03 09:18:44 +02001== osmo-remsim-bankd
Harald Welte5bae20b2019-04-01 09:36:42 +02002
Harald Welte51cfec02019-04-03 09:18:44 +02003The `osmo-remsim-bankd` (SIM Bank Daemon) manages one given SIM bank.
4The initial implementation supports a PC/SC driver to expose any PC/SC
Harald Welte35f2b202019-04-01 11:01:51 +02005compatible card readers as SIM bank.
6
Harald Welte51cfec02019-04-03 09:18:44 +02007`osmo-remsim-bankd` initially connects via a RSPRO control connection to
8`osmo-remsim-server` at startup, and will in turn receive a set of
9initial [client,slot]:[bankd,slot] mappings. These mappings determine
10which slot on the client (corresponding to a modem) is mapped to which
11slot on the SIM bank. Mappings can be updated by `osmo-remsim-server`
12at any given point in time.
Harald Welte35f2b202019-04-01 11:01:51 +020013
Harald Welte51cfec02019-04-03 09:18:44 +020014`osmo-remsim-bankd` implements a RSPRO server, where it listens to
15connections from `osmo-remsim-clients`.
Harald Welte35f2b202019-04-01 11:01:51 +020016
17As PC/SC only offers a blocking API, there is one thread per PC/SC slot.
18This thread will perform blocking I/O on the socket towards the client,
19and blocking API calls on PC/SC.
20
21In terms of thread handling, we do:
22
23* accept() handling in [spare] worker threads
24** this means blocking I/O can be used, as each worker thread only has
25 one TCP connection
26** client identifies itself with client:slot
27** lookup mapping based on client:slot (using mutex for protection)
28** open the reader based on the lookup result
29
30The worker threads initially don't have any mapping to a specific
31reader, and that mapping is only established at a later point after the
32client has identified itself. The advantage is that the entire bankd
33can live without any non-blocking I/O.
34
Harald Welte51cfec02019-04-03 09:18:44 +020035The main thread handles the connection to `osmo-remsim-server`, where it
36can also use non-blocking I/O. However, re-connection would be
37required, to avoid stalling all banks/cards in the event of a connection
38loss to the server.
Harald Welte35f2b202019-04-01 11:01:51 +020039
40worker threads have the following states:
41* INIT (just started)
42* ACCEPTING (they're blocking in the accept() call on the server socket fd)
43* CONNECTED_WAIT_ID (TCP established, but peer not yet identified itself)
44* CONNECTED_CLIENT (TCP established, client has identified itself, no mapping)
45* CONNECTED_CLIENT_MAPPED (TCP established, client has identified itself, mapping exists)
46* CONNECTED_CLIENT_MAPPED_CARD (TCP established, client identified, mapping exists, card opened)
47* CONNECTED_SERVER (TCP established, server has identified itself)
48
49Once the client disconnects, or any other error occurs (such as card I/O
50errors), the worker thread either returns to INIT state (closing client
51socket and reader), or it terminates. Termination would mean that the
52main thread would have to do non-blocking join to detect client
53termination and then re-spawn clients, so the "return to INIT state"
54approach seems to make more sense.
55
56
Harald Welte5bae20b2019-04-01 09:36:42 +020057=== Running
58
Harald Welte51cfec02019-04-03 09:18:44 +020059`osmo-remsim-bankd` currently has the following command-line options:
Harald Welte5bae20b2019-04-01 09:36:42 +020060
61==== SYNOPSIS
62
Harald Welte51cfec02019-04-03 09:18:44 +020063*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 +020064
65==== OPTIONS
66
67*-h, --help*::
68 Print a short help message about the supported options
Harald Welte3c4d0062019-03-31 18:55:18 +020069*-i, --server-host A.B.C.D*::
Harald Welte51cfec02019-04-03 09:18:44 +020070 Specify the remote IP address/hostname of the `osmo-remsim-server` to
71 which this bankd shall establish its RSPRO control connection
Harald Welte5bae20b2019-04-01 09:36:42 +020072*-p, --server-port <1-65535>*::
Harald Welte51cfec02019-04-03 09:18:44 +020073 Specify the remote TCP port number of the `osmo-remsim-server` to which
74 this bankd shall establish its RSPRO control connection
Harald Welte5bae20b2019-04-01 09:36:42 +020075*-b, --bank-id <1-65535>*::
Harald Welte51cfec02019-04-03 09:18:44 +020076 Specify the numeric bank identifier of the SIM bank this bankd
77 instance operates. Must be unique among all banks connecting to the
78 same `osmo-remsim-server`.
Harald Welte2513d812019-04-01 21:03:02 +020079*-n, --num-slots <1-65535>*::
80 Specify the number of slots that this bankd handles.
Harald Welte5bae20b2019-04-01 09:36:42 +020081*-I, --bind-IP A.B.C.D*::
82 Specify the local IP address to which the socket for incoming connections
Harald Welte51cfec02019-04-03 09:18:44 +020083 from `osmo-remsim-clients` is bound to.
Harald Welte5bae20b2019-04-01 09:36:42 +020084*-P, --bind-port <1-65535>*::
85 Specify the local TCP port to whicc the socket for incoming connections
Harald Welte51cfec02019-04-03 09:18:44 +020086 from `osmo-remsim-client`s is bound to.
Harald Welte5bae20b2019-04-01 09:36:42 +020087
88=== Logging
89
Harald Welte51cfec02019-04-03 09:18:44 +020090`osmo-remsim-bankd` currently logs to stdout only, and the logging
91verbosity is not yet configurable. However, as the libosmocore logging
92framework is used, extending this is an easy modification.
Harald Welte5bae20b2019-04-01 09:36:42 +020093
94=== `bankd_pcsc_slots.csv` CSV file
95
96bankd expects a CSV file `bankd_pcsc_slots.csv` in the current working directory at startup.
97
98This CSV file specifies the mapping between the string names of the PCSC
Harald Welte0138bb42019-04-01 11:04:04 +020099readers and the RSPRO bandk/slot numbers. The format is as follows:
Harald Welte5bae20b2019-04-01 09:36:42 +0200100
101.Example: CSV file mapping bankd slots 0..4 to an ACS ACR33U-A1 reader slots
102----
103"1","0","ACS ACR33 ICC Reader 00 00"
104"1","1","ACS ACR33 ICC Reader 00 01"
105"1","2","ACS ACR33 ICC Reader 00 02"
106"1","3","ACS ACR33 ICC Reader 00 03"
107"1","4","ACS ACR33 ICC Reader 00 04"
108----
Harald Welte33a3e872019-05-29 20:12:32 +0200109
110You can obtain the exact string to use as PC/SC reader name from the output of the
111`pcsc_scan` utility (part of pcsc-lite package). The tool will produce output like:
112
113.Example: Output of `pcsc_scan` utility on a system with a single reader installed
114----
115Scanning present readers...
1160: Alcor Micro AU9560 00 00
117----
118
119In this example, there's only a single PC/SC reader available, and it has a string of
120"Alcor Micro AU9560 00 00" whcih needs to be copy-pasted into the CSV file.