blob: e2c43d7f318fca3391317251e1a436ba831dd491 [file] [log] [blame]
Harald Welte51cfec02019-04-03 09:18:44 +02001== osmo-remsim-client-st2
Harald Welte5bae20b2019-04-01 09:36:42 +02002
Harald Welte35f2b202019-04-01 11:01:51 +02003The client interfaces with GSM phones / modems via dedicated "Card
4Emulation" devices such as the Osmocom SIMtrace2 or sysmocom sysmoQMOD
5board + firmware. This hardware implements the ISO7816-3 electrical
6interface and protocol handling and passes any TPDU headers received
Harald Welte51cfec02019-04-03 09:18:44 +02007from the phone/modem to `osmo-remsim-client` for further processing of
8the TPDUs associated to the given APDU transfer.
Harald Welte35f2b202019-04-01 11:01:51 +02009
Harald Welte51cfec02019-04-03 09:18:44 +020010`osmo-remsim-client` connects via a RSPRO control connection to
11`osmo-remsim-server` at startup and registers itself. It will receive
12configuration data such as the `osmo-remsim-bankd` IP+Port and the
13ClientId from `osmo-remsim-server`.
Harald Welte35f2b202019-04-01 11:01:51 +020014
Harald Welte51cfec02019-04-03 09:18:44 +020015After receiving the configuration, `osmo-remsim-client` will establish a
16RSPRO data connection to the `osmo-remsim-bankd` IP:Port.
Harald Welte35f2b202019-04-01 11:01:51 +020017
18As the USB interface for remote SIM in simtrace2.git uses one interface
19per slot, we can implement the client in blocking mode, i.e. use
20blocking I/O on the TCP/RSPRO side. This simplifies the code compared
21to a more complex async implementation.
22
Harald Welte8c0adf62020-03-04 15:16:47 +010023[graphviz]
24.Overall osmo-remsim architecture using osmo-remsim-client-st2
25----
26graph G {
27 rankdir = LR;
28
29 subgraph cluster_0 {
30 label = "Client";
31 modem [label="Phone/Modem",shape="rectangle"];
32 cardem [label="cardem firmware\ne.g. on sysmoQMOD",shape="rectangle"];
33 client [label="remsim-client-st2"];
34 modem -- cardem [label="ISO 7816-3"];
35 cardem -- client [label="USB ST2"];
36 }
37
38 subgraph cluster_2 {
39 label = "SIM Bank";
40 bankd [label="remsim-bankd"];
41 reader [label="Card Reader\ne.g. sysmoOCTSIM",shape="rectangle"];
42 b_pcscd [label="PC/SC Daemon\nlibccid driver"];
43 bankd -- b_pcscd;
44 b_pcscd -- reader [label = "USB CCID"];
45 }
46
47 subgraph cluster_1 {
48 label = "Server/Backend";
49 server [label="remsim-server"];
50 backend [label="Back-End Application"];
51 server -- backend [label="REST Interface"];
52 }
53
54 client -- bankd [label="RSPRO Data"];
55 client -- server [label="RSPRO Control"];
56 bankd -- server [label="RSPRO Control"];
57}
58----
59
60
61
Harald Welte5bae20b2019-04-01 09:36:42 +020062=== Running
63
Harald Welte51cfec02019-04-03 09:18:44 +020064osmo-remsim-client-st2 currently has the following command-line options:
Harald Welte5bae20b2019-04-01 09:36:42 +020065
66==== SYNOPSIS
67
Harald Welte51cfec02019-04-03 09:18:44 +020068*osmo-remsim-client-st2* [...]
Harald Welte5bae20b2019-04-01 09:36:42 +020069
70==== OPTIONS
71
72*-h, --help*::
73 Print a short help message about the supported options
74*-s, --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 client 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 client shall establish its RSPRO control connection
Harald Welte5bae20b2019-04-01 09:36:42 +020080*-c, --client-id <1-65535>*::
81 Specify the numeric client identifier of the SIM bank this bankd
Harald Welte51cfec02019-04-03 09:18:44 +020082 instance operates. The tuple of client-id and client-slot must be
83 unique among all clients connecting to the same `osmo-remsim-server`.
Harald Welte5bae20b2019-04-01 09:36:42 +020084*-n, --client-slot <0-65535>*::
85 Specify the slot number served within this client. The tuple of
86 client-id and client-slot must be unique among all clients connecting
Harald Welte51cfec02019-04-03 09:18:44 +020087 to the same `osmo-remsim-server`.
Harald Welte5bae20b2019-04-01 09:36:42 +020088*-i, --gsmtap-ip A.B.C.D*::
89 Specify the IP address (if any) to which APDU traces are sent in
90 GSMTAP format (useful for debugging; supported by wireshark).
91*-k, --keep-running*::
Harald Welte51cfec02019-04-03 09:18:44 +020092 Specify if the `osmo-remsim-client` should terminate after handling one
Harald Welte5bae20b2019-04-01 09:36:42 +020093 session, or whether it should keep running. Fast respawn (i.e. no
94 --keep-running) is probably the more robust option at this point.
95*-V, --usb-vendor*::
96 Specify the USB Vendor ID of the USB device served by this client,
97 use e.g. 0x1d50 for SIMtrace2, sysmoQMOD and OWHW.
98*-P, --usb-product*::
99 Specify the USB Product ID of the USB device served by this client,
100 use e.g. 0x4004 for sysmoQMOD.
101*-C, --usb-config*::
102 Specify the USB Cofiguration number of the USB device served by this
103 client. Default will use current configuration of the device.
104*-I, --usb-interface*::
105 Specify the USB Interface number (within active configuration) of the
106 USB device served by this client. Default will use FIXME.
107*-S, --usb-altsetting*::
108 Specify the USB Alternate Setting to be used within the USB Interface
109 of the USB device served by this client. Default will use FIXME.
110*-A, --usb-address <0-255>*::
111 Specify the USB Address of the USB device served by this client. This
112 is useful in case multiple identical USB devices are attached to the
113 same host. However, the address changed at every re-enumeration and
114 it's therefor recommended to use the USB path (see below).
115*-H, --usb-path*::
116 Specify the USB path of the USB device served by this client. This is
117 usefule to disambiguate between multiple identical USB devices
118 attached to the same host. You don't need this if you have only one
119 SIM emulation device attached to your system.
120*-a, --atr HEXSTRING*::
121 Specify the initial ATR to be communicated to the modem/phone. Can
Harald Welte51cfec02019-04-03 09:18:44 +0200122 and will later be overridden by the ATR as specified by
123 `osmo-remsim-bankd` once a card has been mapped to this client.
Harald Welte55c7f442019-12-17 01:14:43 +0100124*-e, --event-script COMMAND*::
125 Specify the shell command to be execute when the client wants to call its
126 helper script
127
Harald Welte5bae20b2019-04-01 09:36:42 +0200128
Joachim Steiger68f95102019-07-03 19:03:24 +0200129==== Examples
130.remsim-server is on 10.2.3.4, sysmoQMOD on usb bus, all 4 modems:
131----
132osmo-remsim-client-st2 -s 10.2.3.4 -V 1d50 -P 4004 -C 1 -I 0 -H 2-1.1 -c 0 -n 0
133osmo-remsim-client-st2 -s 10.2.3.4 -V 1d50 -P 4004 -C 1 -I 1 -H 2-1.1 -c 0 -n 1
134osmo-remsim-client-st2 -s 10.2.3.4 -V 1d50 -P 4004 -C 1 -I 0 -H 2-1.4 -c 0 -n 2
135osmo-remsim-client-st2 -s 10.2.3.4 -V 1d50 -P 4004 -C 1 -I 1 -H 2-1.4 -c 0 -n 3
136----
137
Harald Welte5bae20b2019-04-01 09:36:42 +0200138=== Logging
139
Harald Welte51cfec02019-04-03 09:18:44 +0200140`osmo-remsim-client` currently logs to stdout only, and the logging
141verbosity is not yet configurable. However, as the libosmocore logging
142framework is used, extending this is an easy modification.
Harald Welte55c7f442019-12-17 01:14:43 +0100143
144=== Helper Script
145
146`osmo-remsim-client` can call an external shell command / script / program at specific
147instances of time. This serves two purposes:
148
149* To keep external system integration posted about the overall status of remsim-client,
150 such as whether or not it is connected to a server and/or bankd.
151* To request the external system to perform specific actions, such as triggering the reset
152 of the modem - in case the hardware doesn't allow the simtrace2 firmware to do that itself.
153
154==== Script Environment Variables
155
156The environment passed to the helper script contains a number of variables to provide inormation
157to the external script:
158
159.Environment Variables
160[options="header",cols="27%,18%,55%"]
161|===
162| Name | Example Value | Description
163| REMSIM_CLIENT_VERSION | 0.2.2.37-5406a | Compile version of the software
164| REMSIM_SERVER_ADDR | 1.2.3.4:1234 | Address and port of the remsim-server
165| REMSIM_SERVER_STATE | CONNECTED | FSM state of the connection to remsim-server
166| REMSIM_BANKD_ADDR | 1.2.3.4:1234 | Address and port of the remsim-bankd
167| REMSIM_BANKD_STATE | CONNECTED | FSM state of the connection to remsim-bankd
168| REMSIM_CLIENT_SLOT | 23:42 | Client ID and Client Slot Number
169| REMSIM_BANKD_SLOT | 55:33 | Bank ID and Bank Slot Number
170| REMSIM_USB_PATH | 2-1.1 | USB path of the USB device with simtrace2 cardem firmware
171| REMSIM_USB_INTERFACE | 1 | Interface number of the USB device with simtrace2 cardem firmware
172| REMSIM_SIM_VCC | 1 | Whether or not the modem currently applies SIM VCC (0/1)
173| REMSIM_SIM_RST | 1 | Whether or not the modem currently asserts SIM RST (0=inactive, 1=active)
174| REMSIM_CAUSE | request-card-insert | The cause why this script has been called
175|===
176
177==== REMSIM_CAUSE values
178
179The REMSIM_CAUSE environment variable (as well as the first argument) passed to the helper
180script indicated why the script has been called.
181
182[options="header",cols="25%,75%"]
183|===
184| Name | Description
185| event-modem-status | The SIM card interface status has changed (e.g. VCC/RST change)
186| event-bankd-connect | A logical RSPRO connection to a bankd has been established
187| event-server-connect | A logical RSPRO connection to a server has been established
188| event-config-bankd | The server has instructed the client of the bankd address
189| request-card-insert | The client asks the system to simulate SIM card insertion to the modem
190| request-card-remove | The client asks the system to simulate SIM card removal from the modem
191| request-sim-remote | The client asks the system to switch to remote SIM
192| request-sim-local | The client asks the system to switch to local SIM
193| request-modem-reset | The client asks the system to perform a modem reset
194|===
Harald Weltea8e2db92020-03-04 13:11:16 +0100195
196== osmo-remsim-client-shell
197
198This is a remsim-client that's mostly useful for manual debugging/testing or automatic testing.
199
200Instead of using hardware like the SIMtrace with cardem firmware to interface a virtual SIM card
201to a real phone or modem, it simply offers and interactive way to exchange APDUs with a remote
202SIM card via STDIO of the process.
203
204This allows testing of large parts of the osmo-remsim-client code as well as the integration with
205the overall osmo-remsim network including osmo-remsim-server, osmo-remsim-bankd and any external
206backend application driving the REST interface.
207
208=== Running
209
210osmo-remsim-client-shell currently has the following command-line options:
211
212==== SYNOPSIS
213
214*osmo-remsim-client-shell* [...]
215
216==== OPTIONS
217
218*-h, --help*::
219 Print a short help message about the supported options
220*-v, --version*::
221 Print the compile-time version information
222*-i, --server-ip A.B.C.D*::
223 Specify the remote IP address / hostname of the `osmo-remsim-server` to
224 which this client shall establish its RSPRO control connection
225*-p, --server-port <1-65535>*::
226 Specify the remote TCP port number of the `osmo-remsim-server` to which
227 this client shall establish its RSPRO control connection
228*-c, --client-id <1-65535>*::
229 Specify the numeric client identifier of the SIM bank this bankd
230 instance operates. The tuple of client-id and client-slot must be
231 unique among all clients connecting to the same `osmo-remsim-server`.
232*-n, --client-slot <0-65535>*::
233 Specify the slot number served within this client. The tuple of
234 client-id and client-slot must be unique among all clients connecting
235 to the same `osmo-remsim-server`.
236 `osmo-remsim-bankd` once a card has been mapped to this client.
237*-e, --event-script COMMAND*::
238 Specify the shell command to be execute when the client wants to call its
239 helper script
240
241==== Examples
242
243The below example uses stderr-redirection to avoid the log output cluttering the console.
244
245.remsim-server is at 192.168.11.10; we are client 23 slot 0
246----
247./osmo-remsim-client-shell -i 192.168.11.10 -c 23 2>/dev/null
248SET_ATR: 3b 00
249SET_ATR: 3b 7d 94 00 00 55 55 53 0a 74 86 93 0b 24 7c 4d 54 68
250a0a40000023f00
251R-APDU: 9f 17
252----
253
254* The first SET_ATR is performed by osmo-remsim-client locally using a default ATR
255* The second SET_ATR is performed by osmo-remsim-bankd to inform us about the ATR of the real remote card
256* The `a0a40000023f00` is a command TPDU entered on STDIN by the suer
257* The `9f17` is a response TPDU provided by the remote card in response to the command
258
259The program continues in this loop (read command APDU as hex-dump from stdin; provide response on stdout)
260until it is terminated by Ctrl+C or by other means.
Harald Welte9fac4962020-02-14 21:01:23 +0100261
262== libifd_remsim_client
263
264This is a remsim-client implemented as so-called `ifd_handler`, i.e. a card reader driver
265that plugs into the bottom side of the PC/SC daemon of pcsc-lite.
266
267Using this library, you can use normal smart card application programs with remote smart
268cards managed by osmo-remsim. The setup looks like this:
269
270[graphviz]
271.Overall osmo-remsim architecture using libifd_remsim_client
272----
273graph G {
274 rankdir = LR;
275
276 subgraph cluster_0 {
277 label = "Client";
278 application [label="Any application\nusing PC/SC"];
279 pcscd [label="PC/SC Daemon\nlibifd_remsim_client driver"];
280 application -- pcscd;
281 }
282
283 subgraph cluster_2 {
284 label = "SIM Bank";
285 bankd [label="remsim-bankd"];
286 reader [label="Card Reader\ne.g. sysmoOCTSIM",shape="rectangle"];
287 b_pcscd [label="PC/SC Daemon\nlibccid driver"];
288 bankd -- b_pcscd;
289 b_pcscd -- reader [label = "USB CCID"];
290 }
291
292 subgraph cluster_1 {
293 label = "Server/Backend";
294 server [label="remsim-server"];
295 backend [label="Back-End Application"];
296 server -- backend [label="REST Interface"];
297 }
298
299 pcscd -- bankd [label="RSPRO Data"];
300 pcscd -- server [label="RSPRO Control"];
301 bankd -- server [label="RSPRO Control"];
302}
303----
304
305
306=== Configuration
307
308Like all non-USB PC/SC reader drivers, this is happening in `/etc/reader.conf` or, at
309least on Debian GNU/Linux based systems via files in `/etc/reader.conf.d`. The
310osmo-remsim software includes an example configuration file and installs it as
311`osmo-remsim-client-reader_conf` in that directory.
312
313.contents of the configuration example provided by osmo-remsim-client
314----
315#FRIENDLYNAME "osmo-remsim-client"
316#DEVICENAME 0:0:192.168.11.10:9998
317#LIBPATH /usr/lib/pcsc/drivers/libifd-osmo-remsim-client.bundle/Contents/Linux/libifd_remsim_client.so
318----
319
320As you can see, all lines are commented out by default. In order to enable the
321remsim-client virtual reader, you need to
322
323* remove the `#` character on all three lines
324* configure the DEVICNAME according to your local configuration. It is a string with
325 fields separated by colons, in the form of CLIENT_ID:CLIENT_SLOT:SERVER_IP:SERVER_PORRT
326** First part is the Client ID (default: 0)
327** Second part is the Client SlotNumbera (default: 0)
328** Third part is the IP address of the `osmo-resim-server` (default: localhost)
329** Last part is the RSPRO TCP port of the `osmo-remsim-server` (default: 9998)
330
331Once the configuration file has been updated, you should re-start pcscd by issuing
332`systemctl restart pcscd` or whatever command your Linux distribution uses for restarting
333services.
334
335You can check if the driver is loaded by using the `pcsc_scan` tool included with `pcscd`:
336
337----
338$ pcsc_scan
339Using reader plug'n play mechanism
340Scanning present readers...
3410: osmo-remsim-client 00 00
342
343Wed Mar 4 13:31:42 2020
344 Reader 0: osmo-remsim-client 00 00
345 Event number: 0
346 Card state: Card removed,
347 -
348----
349
350Once a proper slotmap to an existing SIM card in a remote bank daemon has been installed
351in the server, you should see something like this:
352
353----
354$ pcsc_scan
355Using reader plug'n play mechanism
356Scanning present readers...
3570: osmo-remsim-client 00 00
358
359Wed Mar 4 13:35:18 2020
360 Reader 0: osmo-remsim-client 00 00
361 Event number: 1
362 Card state: Card inserted,
363 ATR: 3B 7D 94 00 00 55 55 53 0A 74 86 93 0B 24 7C 4D 54 68
364
365ATR: 3B 7D 94 00 00 55 55 53 0A 74 86 93 0B 24 7C 4D 54 68
366+ TS = 3B --> Direct Convention
367+ T0 = 7D, Y(1): 0111, K: 13 (historical bytes)
368 TA(1) = 94 --> Fi=512, Di=8, 64 cycles/ETU
369 62500 bits/s at 4 MHz, fMax for Fi = 5 MHz => 78125 bits/s
370 TB(1) = 00 --> VPP is not electrically connected
371 TC(1) = 00 --> Extra guard time: 0
372+ Historical bytes: 55 55 53 0A 74 86 93 0B 24 7C 4D 54 68
373 Category indicator byte: 55 (proprietary format)
374
375Possibly identified card (using /home/laforge/.cache/smartcard_list.txt):
376 NONE
377----
378
379From now on, you can use any application using PC/SC, whether C, Python or Java with a
380remote SIM card managed by osmo-remsim.