Project

General

Profile

Wiki » History » Version 53

fixeria, 08/29/2022 06:18 PM
update installation instructions

1 40 fixeria
h1. pySim WiKi
2 4 wirelesss
3 40 fixeria
{{>toc}}
4 1 laforge
5 49 laforge
pySim is a suite of programs (develped in python) for interfacing with SIM/UICC/USIM/ISIM cards.
6 1 laforge
7 50 laforge
* @pySim-shell@ is an interactive command line tool for navigating around the card file system, reading/writing data to the files as well as administrative commands. It is the most sophisticated general purpose tool of the pySim suite and has long surpassed the capabilities of its older cousins like @pySim-prog@.
8 49 laforge
* @pySim-prog@ is a small command line utility for programming a small subset of parameters like IMSI, K, OP[c], SMSP in (batches of) various programmable SIM/USIM cards.
9
* @pySim-read@ is a small command line utility for reading some commonly used fields of a SIM card
10
11 39 laforge
Such SIM/USIM cards are special cards, which - unlike those issued by regular commercial operators - come with the kind of keys that allow you to write the files/fields that normally only an operator can program.
12 1 laforge
13
This is useful particularly if you are running your own cellular network, and want to issue your own SIM/USIM cards for that network.
14
15
h2. Supported Cards
16
17 49 laforge
* Generic SIM/UICC/USIM/ISIM card
18
** only ETSI/3GPP standard files supported on generic cards
19
** writing of most fields is typically not possible as nobody except the card-issuing operator posesses the keys / ADM1 PIN to write
20
* Actively supported, fully programmable cards
21
** [[cellular-infrastructure:sysmoISIM-SJA2]] (SIM + USIM + ISIM)
22
* Older fully programmable cards
23
** [[cellular-infrastructure:sysmoUSIM-SJS1]] (SIM + USIM)
24
* Older much less configurable cards
25
** [[cellular-infrastructure:GrcardSIM]] (SIM)
26
** [[cellular-infrastructure:GrcardSIM2]] (SIM)
27
** [[cellular-infrastructure:MagicSIM]] (SIM)
28 1 laforge
29 49 laforge
h2. Supported Card Interfaces ("Readers")
30 1 laforge
31 49 laforge
The best-supported/recommended configuration is to use a Smart Card Interface device compliant with the _USB CCID_ specification, using the libccid/pcsc-lite driver stack.
32 41 laforge
33 49 laforge
However, pySim supports multiple card interface back-ends:
34
35
* @pcsc@: any reader suppored by "pcsc-lite":https://pcsclite.apdu.fr/
36 41 laforge
** pcsc-lite supports any reader that provides a so-called @ifd_handler@ driver. Those could come e.g. from reader vendors, but
37
** pcsc-lite is very well integrated with "libccid":https://ccid.apdu.fr/ccid, whose reader support status is indicated at https://ccid.apdu.fr/ccid/section.html
38 49 laforge
* @serial@: simple serial/UART based readers, as sometimes shipped with GRcard SIMs
39
* @calypso@: A calypso chipset based mobile phone runnung [[OsmocomBB:]]
40
* @modem_atcmd@: Any cellular modem offering the @AT+CSIM@ command
41 47 laforge
42
h2. Documentation
43
44
h3. User Manual
45
46
The manual / documentation can be built from the source code by @(cd docs && make html latexpdf)@.
47 48 laforge
48 47 laforge
Pre-rendered versions of the current @master@ branch are available as "PDF":https://ftp.osmocom.org/docs/latest/osmopysim-usermanual.pdf and "HTML":https://downloads.osmocom.org/docs/latest/pysim/
49
50
h3. Video on pySim-shell usage
51
52
On April 9. 2021 @laforge gave a presentation on @pySim-shell@, a video recording can be found at 
53
https://people.osmocom.org/tnt/osmodevcall/osmodevcall-20210409-laforge-pysim-shell_h264_420.mp4
54
55 37 wirelesss
56 1 laforge
h2. Usage instructions
57
58
h3. Install dependencies:
59 52 fixeria
60
pySim requires the following dependencies:
61
62
* pyscard
63
* serial
64
* pytlv
65
* cmd2 >= 1.3.0 but < 2.0.0
66
* jsonpath-ng
67
* construct >= 2.9.51
68
* bidict
69
* gsm0338
70
* pyyaml >= 5.1
71
* termcolor
72
* colorlog
73 37 wirelesss
74 53 fixeria
h4. Example for Debian/Ubuntu
75
76
<pre><code class="shell">
77
sudo apt-get install --no-install-recommends \
78
        pcscd libpcsclite-dev \
79
        python3 \
80
        python3-setuptools \
81
        python3-pyscard \
82
        python3-pip
83
pip3 install --user -r requirements.txt
84
</code></pre>
85
86
h4. ArchLinux Package
87
88
Archlinux users may install the package @python-pysim-git@ from the "Arch User Repository (AUR)":https://aur.archlinux.org. The most convenient way is the use of an "AUR Helper":https://wiki.archlinux.org/index.php/AUR_helpers, e.g. "yay":https://aur.archlinux.org/packages/yay or "pacaur":https://aur.archlinux.org/packages/pacaur.
89
90
The following example shows the installation with @yay@:
91
92
<pre><code class="shell">
93
yay -Sy python-pysim-git
94
</code></pre>
95 37 wirelesss
96 16 wirelesss
* Connect SIM card reader.
97 37 wirelesss
98 1 laforge
* Insert programmable SIM card
99 37 wirelesss
100 1 laforge
h3. Check the status of connection by entering the following command:
101 37 wirelesss
102 34 wirelesss
<pre>
103 37 wirelesss
 pcsc_scan
104 5 wirelesss
</pre>
105 37 wirelesss
106 32 wirelesss
* If SIM card reader is recognised then we can expect something similar to the below output:
107 37 wirelesss
108 5 wirelesss
<pre>
109
 $ pcsc_scan
110
 PC/SC device scanner
111
 V 1.4.25 (c) 2001-2011, Ludovic Rousseau ludovic.rousseau@free.fr
112
 Compiled with PC/SC lite version: 1.8.14
113
 Using reader plug'n play mechanism
114
 Scanning present readers...
115
 0: SCM Microsystems Inc. SCR 3310 [CCID Interface] 00 00 
116
 Tue Oct 18 11:48:08 2016
117
 Reader 0: SCM Microsystems Inc. SCR 3310 [CCID Interface] 00 00
118
 Card state: Card inserted, 
119
 ATR: 3B 99 18 00 11 88 22 33 44 55 66 77 60
120
 + TS = 3B --> Direct Convention
121 20 wirelesss
 + T0 = 99, Y(1): 1001, K: 9 (historical bytes)
122 1 laforge
  TA(1) = 18 --> Fi=372, Di=12, 31 cycles/ETU
123 20 wirelesss
  129032 bits/s at 4 MHz, fMax for Fi = 5 MHz => 161290 bits/s
124 1 laforge
  TD(1) = 00 --> Y(i+1) = 0000, Protocol T = 0 
125
 -----
126 20 wirelesss
 + Historical bytes: 11 88 22 33 44 55 66 77 60
127 1 laforge
 Category indicator byte: 11 (proprietary format)
128
 Possibly identified card (using /usr/share/pcsc/smartcard_list.txt):
129
 3B 99 18 00 11 88 22 33 44 55 66 77 60
130 20 wirelesss
 sysmocom sysmoSIM-GR1
131 37 wirelesss
132 20 wirelesss
</pre>
133 37 wirelesss
134 20 wirelesss
** Exit pcsc_scan : _Ctrl+C_
135 1 laforge
136 37 wirelesss
137
h3. Get the code of PySIM by entering command:
138
139 1 laforge
<pre>
140 51 laforge
 git clone https://gitea.osmocom.org/sim-card/pysim
141 1 laforge
</pre>
142 37 wirelesss
143 5 wirelesss
<pre>
144 37 wirelesss
 cd pysim
145 32 wirelesss
</pre>
146 37 wirelesss
147 5 wirelesss
h3. Read your SIM card
148
149 32 wirelesss
 ./pySim-read.py -p0 or ./pySim-read.py -p1 
150 37 wirelesss
151 1 laforge
* Using sysmoSIM-GR1 and if everything is done correctly, you will see something similar to:
152 37 wirelesss
 
153 1 laforge
<pre>
154 5 wirelesss
 $ ./pySim-read.py -p0 
155
 Reading ...
156
 ICCID: 1791198229180000071
157
 IMSI: 001640000000071
158
 SMSP: ffffffffffffffffffffffffe1ffffffffffffffffffffffff0581005155f5ffffffffffff000000
159
 ACC: ffff
160
 MSISDN: Not available
161
 Done !
162 37 wirelesss
163 5 wirelesss
</pre>
164 37 wirelesss
165 17 wirelesss
h3. Program your SIM card
166 37 wirelesss
167 1 laforge
* Enter   @./pySim-prog.py -help@   to get overview of possible options. 
168 7 wirelesss
169 5 wirelesss
Similar result should appear: 
170
171
 $ ./pySim-prog.py -help
172
 Usage: pySim-prog.py [options]
173
 Options:
174
   -h, --help            show this help message and exit
175
   -d DEV, --device=DEV  Serial Device for SIM access [default: /dev/ttyUSB0]
176
   -b BAUD, --baud=BAUD  Baudrate used for SIM access [default: 9600]
177
   -p PCSC, --pcsc-device=PCSC
178
                         Which PC/SC reader number for SIM access
179
   -t TYPE, --type=TYPE  Card type (user -t list to view) [default: auto]
180
   -a PIN_ADM, --pin-adm=PIN_ADM
181
                         ADM PIN used for provisioning (overwrites default)
182
   -e, --erase           Erase beforehand [default: False]
183
   -S SOURCE, --source=SOURCE
184
                         Data Source[default: cmdline]
185
   -n NAME, --name=NAME  Operator name [default: Magic]
186
   -c CC, --country=CC   Country code [default: 1]
187
   -x MCC, --mcc=MCC     Mobile Country Code [default: 901]
188
   -y MNC, --mnc=MNC     Mobile Network Code [default: 55]
189
   -m SMSC, --smsc=SMSC  SMSP [default: '00 + country code + 5555']
190
   -M SMSP, --smsp=SMSP  Raw SMSP content in hex [default: auto from SMSC]
191
   -s ID, --iccid=ID     Integrated Circuit Card ID
192 1 laforge
   -i IMSI, --imsi=IMSI  International Mobile Subscriber Identity
193 5 wirelesss
   -k KI, --ki=KI        Ki (default is to randomize)
194
   -o OPC, --opc=OPC     OPC (default is to randomize)
195
   --op=OP               Set OP to derive OPC from OP and KI
196
   --acc=ACC             Set ACC bits (Access Control Code). not all card types
197
                         are supported
198
   -z STR, --secret=STR  Secret used for ICCID/IMSI autogen
199
   -j NUM, --num=NUM     Card # used for ICCID/IMSI autogen
200
   --batch               Enable batch mode [default: False]
201
   --batch-state=FILE    Optional batch state file
202
   --read-csv=FILE       Read parameters from CSV file rather than command line
203
   --write-csv=FILE      Append generated parameters in CSV file
204
   --write-hlr=FILE      Append generated parameters to OpenBSC HLR sqlite3
205 32 wirelesss
   --dry-run             Perform a 'dry run', don't actually program the card
206 37 wirelesss
207 18 wirelesss
h3. Example of how to program a sysmoSIM-GR1 card 
208 5 wirelesss
209
The GRcard SIM is a programmable GSM SIM card. It uses a mixture of TS11.11 / ISO7816-4 and proprietary commands for programming.
210 1 laforge
211
In the below example, we are changing the card’s IMSI to 901700000003080 (option -i) and we are specifying a new set of -n NAME (Operator name), -t TYPE (Card type), -c CC (Country code), -x MCC (Mobile Country Code), -y MNC (Mobile Network Code) and -s ID (Integrated Circuit Card ID) values.
212 25 wirelesss
 
213 5 wirelesss
 $ ./pySim-prog.py -p 0 -n OpenBSC -t sysmosim-gr1 -i 901700000003080 -c 001 -x 001 -y 02 -s 1791198229180000075
214
 Insert card now (or CTRL-C to cancel)
215
 Generated card parameters :
216
  > Name    : OpenBSC
217
  > SMSP    : e1ffffffffffffffffffffffff0581005155f5ffffffffffff000000
218
  > ICCID   : 1791198229180000075
219
  > MCC/MNC : 1/2
220
  > IMSI    : 901700000003080
221
  > Ki      : 7edaeb6addbd72d2b2cc6ed7bfecc9c9
222
  > OPC     : 23f075ab9b1a113d4db822d8195ea20c
223 1 laforge
  > ACC     : None
224 5 wirelesss
 Programming ...
225 32 wirelesss
 Done !
226 37 wirelesss
227 31 wirelesss
h3. Example of how to program a sysmoUSIM-SJS1 card
228 5 wirelesss
229
(U)SIM cards are Java capable and there is the Globalplatform that specifies standards API. SMS can be addressed directly to the SIM card, the SIM card will get events for network selection and others, it can modify call establishment attempts.
230
231
232 13 wirelesss
Provisioning of different identities or keys.
233 5 wirelesss
 
234
If you have a variant of the card-individual ADM1 key of your sysmoUSIM-SJS1 card,  you can change any identity (IMSI, ICCID, MSISDN) stored on the (U)SIM, as well as the private key data (K, OPC).
235 1 laforge
236 26 wirelesss
In the below example, we are changing the card’s IMSI to 901700000003080 (option -i) and we are specifying a new set of -t TYPE (Card type), - a ADM_PIN (ADM PIN used for provisioning), -x MCC (Mobile Country Code), -y MNC (Mobile Network Code), -s ID (Integrated Circuit Card ID), -o OPC and -k KI (Ki) values.
237 5 wirelesss
238 11 wirelesss
 $ ./pySim-prog.py -p 0 -t sysmoUSIM-SJS1 -a 58001006  -x 901 -y 71 -i 901700000010659 -s 8988211000000110000 -o 398153093661279FB1FC74BE07059FEF -k 1D8B2562B992549F20D0F42113EAA6FA
239 5 wirelesss
 Insert card now (or CTRL-C to cancel)
240
 Generated card parameters :
241
  > Name    : Magic
242
  > SMSP    : e1ffffffffffffffffffffffff0581005155f5ffffffffffff000000
243
  > ICCID   : 8988211000000110000
244 6 wirelesss
  > MCC/MNC : 901/71
245 5 wirelesss
  > IMSI    : 901700000010659
246
  > Ki      : 1D8B2562B992549F20D0F42113EAA6FA
247
  > OPC     : 398153093661279FB1FC74BE07059FEF
248 6 wirelesss
  > ACC     : None
249 5 wirelesss
 Programming ...
250
 Done !
251 37 wirelesss
252 5 wirelesss
h3. Example of how to program a Magic SIM / SuperSIM 16-in-1 / X-sim card
253
254
The 16-in-1 SIM cards are intended for COMP128v1 based cloning and enable the user to aggregate up to 16 SIM card identities in a single card. This multi-IMSI property is not used in the context of Osmocom.
255 1 laforge
256
Below example shows how we can change the card’s IMSI to 901990000000018 (option -i) and at the same time we are specifying a new set of -x MCC (Mobile Country Code), -y MNC (Mobile Network Code), -s ID (Integrated Circuit Card ID) , -o OPC and -k KI (Ki) values.
257 5 wirelesss
258
 $ ./pySim-prog.py -p 0 -x 801 -y 71 -i 901990000000018 -s 8988211000000110000 -o 398153093661279FB1FC74BE07059FEF -k 1D8B2562B992549F20D0F42113EAA6FA
259
 Insert card now (or CTRL-C to cancel)
260
 Autodetected card type fakemagicsim
261
 Generated card parameters :
262
  > Name    : Magic
263
  > SMSP    : e1ffffffffffffffffffffffff0581005155f5ffffffffffff000000
264
  > ICCID   : 8988211000000110000
265 1 laforge
  > MCC/MNC : 801/71
266 5 wirelesss
  > IMSI    : 901990000000018
267 1 laforge
  > Ki      : 1D8B2562B992549F20D0F42113EAA6FA
268 5 wirelesss
  > OPC     : 398153093661279FB1FC74BE07059FEF
269
  > ACC     : None
270
 Programming ...
271
 Done !
272 37 wirelesss
273 6 wirelesss
h3. README 
274 37 wirelesss
275 51 laforge
pySim comes with following README file: https://gitea.osmocom.org/sim-card/pysim/src/branch/master/README.md
276 43 laforge
277 44 roh
278
h3. Testing
279 45 laforge
280 44 roh
pySim is continuously and automatically tested by a [[TestRig]] run by sysmocom
281 45 laforge
282 1 laforge
{{include(cellular-infrastructure:MacroCommercialSupport)}}
Add picture from clipboard (Maximum size: 48.8 MB)