Harald Welte | 5103ea0 | 2020-03-04 15:31:58 +0100 | [diff] [blame] | 1 | [[remsim-bankd]] |
Harald Welte | 51cfec0 | 2019-04-03 09:18:44 +0200 | [diff] [blame] | 2 | == osmo-remsim-bankd |
Harald Welte | 5bae20b | 2019-04-01 09:36:42 +0200 | [diff] [blame] | 3 | |
Harald Welte | 51cfec0 | 2019-04-03 09:18:44 +0200 | [diff] [blame] | 4 | The `osmo-remsim-bankd` (SIM Bank Daemon) manages one given SIM bank. |
| 5 | The initial implementation supports a PC/SC driver to expose any PC/SC |
Harald Welte | 35f2b20 | 2019-04-01 11:01:51 +0200 | [diff] [blame] | 6 | compatible card readers as SIM bank. |
| 7 | |
Harald Welte | 51cfec0 | 2019-04-03 09:18:44 +0200 | [diff] [blame] | 8 | `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 |
| 10 | initial [client,slot]:[bankd,slot] mappings. These mappings determine |
| 11 | which slot on the client (corresponding to a modem) is mapped to which |
| 12 | slot on the SIM bank. Mappings can be updated by `osmo-remsim-server` |
| 13 | at any given point in time. |
Harald Welte | 35f2b20 | 2019-04-01 11:01:51 +0200 | [diff] [blame] | 14 | |
Harald Welte | 51cfec0 | 2019-04-03 09:18:44 +0200 | [diff] [blame] | 15 | `osmo-remsim-bankd` implements a RSPRO server, where it listens to |
| 16 | connections from `osmo-remsim-clients`. |
Harald Welte | 35f2b20 | 2019-04-01 11:01:51 +0200 | [diff] [blame] | 17 | |
| 18 | As PC/SC only offers a blocking API, there is one thread per PC/SC slot. |
| 19 | This thread will perform blocking I/O on the socket towards the client, |
| 20 | and blocking API calls on PC/SC. |
| 21 | |
| 22 | In 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 | |
| 31 | The worker threads initially don't have any mapping to a specific |
| 32 | reader, and that mapping is only established at a later point after the |
| 33 | client has identified itself. The advantage is that the entire bankd |
| 34 | can live without any non-blocking I/O. |
| 35 | |
Harald Welte | 51cfec0 | 2019-04-03 09:18:44 +0200 | [diff] [blame] | 36 | The main thread handles the connection to `osmo-remsim-server`, where it |
| 37 | can also use non-blocking I/O. However, re-connection would be |
| 38 | required, to avoid stalling all banks/cards in the event of a connection |
| 39 | loss to the server. |
Harald Welte | 35f2b20 | 2019-04-01 11:01:51 +0200 | [diff] [blame] | 40 | |
| 41 | worker 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 | |
| 50 | Once the client disconnects, or any other error occurs (such as card I/O |
| 51 | errors), the worker thread either returns to INIT state (closing client |
| 52 | socket and reader), or it terminates. Termination would mean that the |
| 53 | main thread would have to do non-blocking join to detect client |
| 54 | termination and then re-spawn clients, so the "return to INIT state" |
| 55 | approach seems to make more sense. |
| 56 | |
| 57 | |
Harald Welte | 5bae20b | 2019-04-01 09:36:42 +0200 | [diff] [blame] | 58 | === Running |
| 59 | |
Harald Welte | 51cfec0 | 2019-04-03 09:18:44 +0200 | [diff] [blame] | 60 | `osmo-remsim-bankd` currently has the following command-line options: |
Harald Welte | 5bae20b | 2019-04-01 09:36:42 +0200 | [diff] [blame] | 61 | |
| 62 | ==== SYNOPSIS |
| 63 | |
Harald Welte | bfcca52 | 2023-07-18 19:55:43 +0200 | [diff] [blame^] | 64 | *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 Welte | 5bae20b | 2019-04-01 09:36:42 +0200 | [diff] [blame] | 65 | |
| 66 | ==== OPTIONS |
| 67 | |
| 68 | *-h, --help*:: |
| 69 | Print a short help message about the supported options |
Harald Welte | 6a93cfb | 2021-12-09 12:56:27 +0100 | [diff] [blame] | 70 | *-V, --version*:: |
| 71 | Print the software version number |
| 72 | *-d, --debug LOGOPT*:: |
| 73 | Configure the logging verbosity, see <<remsim_logging>>. |
Harald Welte | 3c4d006 | 2019-03-31 18:55:18 +0200 | [diff] [blame] | 74 | *-i, --server-host A.B.C.D*:: |
Harald Welte | 51cfec0 | 2019-04-03 09:18:44 +0200 | [diff] [blame] | 75 | Specify the remote IP address/hostname of the `osmo-remsim-server` to |
Harald Welte | bfcca52 | 2023-07-18 19:55:43 +0200 | [diff] [blame^] | 76 | 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 Welte | 5bae20b | 2019-04-01 09:36:42 +0200 | [diff] [blame] | 79 | *-p, --server-port <1-65535>*:: |
Harald Welte | 51cfec0 | 2019-04-03 09:18:44 +0200 | [diff] [blame] | 80 | Specify the remote TCP port number of the `osmo-remsim-server` to which |
| 81 | this bankd shall establish its RSPRO control connection |
Harald Welte | 55f12b8 | 2022-01-16 14:34:12 +0100 | [diff] [blame] | 82 | *-b, --bank-id <1-1023>*:: |
Harald Welte | 51cfec0 | 2019-04-03 09:18:44 +0200 | [diff] [blame] | 83 | 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 Welte | 55f12b8 | 2022-01-16 14:34:12 +0100 | [diff] [blame] | 86 | *-n, --num-slots <1-1023>*:: |
Harald Welte | 2513d81 | 2019-04-01 21:03:02 +0200 | [diff] [blame] | 87 | Specify the number of slots that this bankd handles. |
Harald Welte | 5bae20b | 2019-04-01 09:36:42 +0200 | [diff] [blame] | 88 | *-I, --bind-IP A.B.C.D*:: |
| 89 | Specify the local IP address to which the socket for incoming connections |
Harald Welte | 51cfec0 | 2019-04-03 09:18:44 +0200 | [diff] [blame] | 90 | from `osmo-remsim-clients` is bound to. |
Harald Welte | 5bae20b | 2019-04-01 09:36:42 +0200 | [diff] [blame] | 91 | *-P, --bind-port <1-65535>*:: |
Harald Welte | 6a93cfb | 2021-12-09 12:56:27 +0100 | [diff] [blame] | 92 | Specify the local TCP port to which the socket for incoming connections |
Harald Welte | 51cfec0 | 2019-04-03 09:18:44 +0200 | [diff] [blame] | 93 | from `osmo-remsim-client`s is bound to. |
Harald Welte | 628672b | 2022-07-13 15:20:13 +0200 | [diff] [blame] | 94 | *-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 Welte | 5bae20b | 2019-04-01 09:36:42 +0200 | [diff] [blame] | 103 | |
Joachim Steiger | 68f9510 | 2019-07-03 19:03:24 +0200 | [diff] [blame] | 104 | ==== Examples |
| 105 | .remsim-server is on 10.2.3.4, cardreader has 5 slots: |
| 106 | ---- |
| 107 | osmo-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 | ---- |
| 111 | osmo-remsim-bankd -i 10.2.3.4 -n 4 -I 10.5.4.3 |
| 112 | ---- |
| 113 | |
Harald Welte | 5bae20b | 2019-04-01 09:36:42 +0200 | [diff] [blame] | 114 | === Logging |
| 115 | |
Harald Welte | 51cfec0 | 2019-04-03 09:18:44 +0200 | [diff] [blame] | 116 | `osmo-remsim-bankd` currently logs to stdout only, and the logging |
| 117 | verbosity is not yet configurable. However, as the libosmocore logging |
| 118 | framework is used, extending this is an easy modification. |
Harald Welte | 5bae20b | 2019-04-01 09:36:42 +0200 | [diff] [blame] | 119 | |
| 120 | === `bankd_pcsc_slots.csv` CSV file |
| 121 | |
| 122 | bankd expects a CSV file `bankd_pcsc_slots.csv` in the current working directory at startup. |
| 123 | |
| 124 | This CSV file specifies the mapping between the string names of the PCSC |
Harald Welte | 0138bb4 | 2019-04-01 11:04:04 +0200 | [diff] [blame] | 125 | readers and the RSPRO bandk/slot numbers. The format is as follows: |
Harald Welte | a06d77f | 2021-02-19 19:04:12 +0100 | [diff] [blame] | 126 | |
Harald Welte | 753c8aa | 2020-10-20 23:04:59 +0200 | [diff] [blame] | 127 | * first column: bankd number |
| 128 | * second column: slot number within bankd |
| 129 | * third column: extended POSIX regular expression matching the slot |
Harald Welte | 5bae20b | 2019-04-01 09:36:42 +0200 | [diff] [blame] | 130 | |
| 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 Welte | 33a3e87 | 2019-05-29 20:12:32 +0200 | [diff] [blame] | 139 | |
| 140 | You 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 | ---- |
| 145 | Scanning present readers... |
| 146 | 0: Alcor Micro AU9560 00 00 |
| 147 | ---- |
| 148 | |
| 149 | In this example, there's only a single PC/SC reader available, and it has a string of |
Harald Welte | 753c8aa | 2020-10-20 23:04:59 +0200 | [diff] [blame] | 150 | "Alcor Micro AU9560 00 00" which needs to be used in the CSV file. |
| 151 | |
| 152 | NOTE:: If the reader name contains any special characters, they might need to be escaped according |
| 153 | to 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 | |
| 167 | In the above example, the +\[CCID\]+ and the +\(serialnumber\)+ both had to be escaped. |
| 168 | |
| 169 | The +[0-9]\{2\}+ construct exists to perform wildcard matching, no matter which particular two-digit number |
| 170 | pcscd decides to use. |
Stephan Skrodzki | 239458e | 2023-05-15 17:32:45 +0200 | [diff] [blame] | 171 | |
| 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 | |