Project

General

Profile

Wiki » History » Version 56

laforge, 10/30/2023 04:05 PM

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 55 laforge
* @piSim-trace@ is a high-level decoder of SIM card protocol traces (for example, traces generated by [[SIMtrace2:]])
11 49 laforge
12 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.
13 1 laforge
14
This is useful particularly if you are running your own cellular network, and want to issue your own SIM/USIM cards for that network.
15
16
h2. Supported Cards
17
18 49 laforge
* Generic SIM/UICC/USIM/ISIM card
19
** only ETSI/3GPP standard files supported on generic cards
20
** writing of most fields is typically not possible as nobody except the card-issuing operator posesses the keys / ADM1 PIN to write
21
* Actively supported, fully programmable cards
22 56 laforge
** [[cellular-infrastructure:sysmoISIM-SJA2]] (3GPP Release 16 SIM + USIM + ISIM)
23
** [[cellular-infrastructure:sysmoISIM-SJA5]] (3GPP Release 17 SIM + USIM + ISIM + HPSIM)
24 49 laforge
* Older fully programmable cards
25
** [[cellular-infrastructure:sysmoUSIM-SJS1]] (SIM + USIM)
26
* Older much less configurable cards
27
** [[cellular-infrastructure:GrcardSIM]] (SIM)
28
** [[cellular-infrastructure:GrcardSIM2]] (SIM)
29
** [[cellular-infrastructure:MagicSIM]] (SIM)
30 1 laforge
31 49 laforge
h2. Supported Card Interfaces ("Readers")
32 1 laforge
33 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.
34 41 laforge
35 49 laforge
However, pySim supports multiple card interface back-ends:
36
37
* @pcsc@: any reader suppored by "pcsc-lite":https://pcsclite.apdu.fr/
38 41 laforge
** pcsc-lite supports any reader that provides a so-called @ifd_handler@ driver. Those could come e.g. from reader vendors, but
39 54 laforge
** pcsc-lite is very well integrated with "libccid":https://ccid.apdu.fr/, whose reader support status is indicated at https://ccid.apdu.fr/ccid/section.html
40 49 laforge
* @serial@: simple serial/UART based readers, as sometimes shipped with GRcard SIMs
41
* @calypso@: A calypso chipset based mobile phone runnung [[OsmocomBB:]]
42
* @modem_atcmd@: Any cellular modem offering the @AT+CSIM@ command
43 47 laforge
44 55 laforge
The pySim developers as well as the continuous integration / automatic testing are utilizing USB-CCID readers via pcsc-lite.  Your milage with other backends (not used much, not automatically tested) may vary!
45
46 47 laforge
h2. Documentation
47
48
h3. User Manual
49
50
The manual / documentation can be built from the source code by @(cd docs && make html latexpdf)@.
51 48 laforge
52 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/
53
54
h3. Video on pySim-shell usage
55
56
On April 9. 2021 @laforge gave a presentation on @pySim-shell@, a video recording can be found at 
57
https://people.osmocom.org/tnt/osmodevcall/osmodevcall-20210409-laforge-pysim-shell_h264_420.mp4
58
59 1 laforge
60 53 fixeria
h2. Usage instructions
61 1 laforge
62 55 laforge
*Installation:* Please follow the instructions provided in [source:README.md]
63 37 wirelesss
64 16 wirelesss
* Connect SIM card reader.
65 37 wirelesss
66 1 laforge
* Insert programmable SIM card
67 37 wirelesss
68 1 laforge
h3. Check the status of connection by entering the following command:
69 37 wirelesss
70 34 wirelesss
<pre>
71 37 wirelesss
 pcsc_scan
72 5 wirelesss
</pre>
73 37 wirelesss
74 32 wirelesss
* If SIM card reader is recognised then we can expect something similar to the below output:
75 37 wirelesss
76 5 wirelesss
<pre>
77
 $ pcsc_scan
78 1 laforge
 PC/SC device scanner
79 5 wirelesss
 V 1.4.25 (c) 2001-2011, Ludovic Rousseau ludovic.rousseau@free.fr
80
 Compiled with PC/SC lite version: 1.8.14
81
 Using reader plug'n play mechanism
82
 Scanning present readers...
83
 0: SCM Microsystems Inc. SCR 3310 [CCID Interface] 00 00 
84
 Tue Oct 18 11:48:08 2016
85
 Reader 0: SCM Microsystems Inc. SCR 3310 [CCID Interface] 00 00
86
 Card state: Card inserted, 
87
 ATR: 3B 99 18 00 11 88 22 33 44 55 66 77 60
88
 + TS = 3B --> Direct Convention
89
 + T0 = 99, Y(1): 1001, K: 9 (historical bytes)
90 20 wirelesss
  TA(1) = 18 --> Fi=372, Di=12, 31 cycles/ETU
91 1 laforge
  129032 bits/s at 4 MHz, fMax for Fi = 5 MHz => 161290 bits/s
92 20 wirelesss
  TD(1) = 00 --> Y(i+1) = 0000, Protocol T = 0 
93 1 laforge
 -----
94
 + Historical bytes: 11 88 22 33 44 55 66 77 60
95 20 wirelesss
 Category indicator byte: 11 (proprietary format)
96 1 laforge
 Possibly identified card (using /usr/share/pcsc/smartcard_list.txt):
97
 3B 99 18 00 11 88 22 33 44 55 66 77 60
98
 sysmocom sysmoSIM-GR1
99
100 20 wirelesss
</pre>
101 37 wirelesss
102 20 wirelesss
** Exit pcsc_scan : _Ctrl+C_
103 37 wirelesss
104 20 wirelesss
105 1 laforge
h3. Get the code of PySIM by entering command:
106 37 wirelesss
107
<pre>
108
 git clone https://gitea.osmocom.org/sim-card/pysim
109 1 laforge
</pre>
110 51 laforge
111 37 wirelesss
<pre>
112 5 wirelesss
 cd pysim
113 37 wirelesss
</pre>
114 32 wirelesss
115 55 laforge
h3. Read (a few fields of) your SIM card
116 5 wirelesss
117
 ./pySim-read.py -p0 or ./pySim-read.py -p1 
118 32 wirelesss
119 37 wirelesss
* Using sysmoSIM-GR1 and if everything is done correctly, you will see something similar to:
120 1 laforge
 
121 37 wirelesss
<pre>
122 1 laforge
 $ ./pySim-read.py -p0 
123 5 wirelesss
 Reading ...
124
 ICCID: 1791198229180000071
125
 IMSI: 001640000000071
126
 SMSP: ffffffffffffffffffffffffe1ffffffffffffffffffffffff0581005155f5ffffffffffff000000
127
 ACC: ffff
128
 MSISDN: Not available
129
 Done !
130 37 wirelesss
131 5 wirelesss
</pre>
132 37 wirelesss
133 55 laforge
h3. Program (very few fields of) your SIM card using legacy pySim-prog
134 37 wirelesss
135 1 laforge
* Enter   @./pySim-prog.py -help@   to get overview of possible options. 
136 7 wirelesss
137 5 wirelesss
Similar result should appear: 
138
139
 $ ./pySim-prog.py -help
140
 Usage: pySim-prog.py [options]
141
 Options:
142
   -h, --help            show this help message and exit
143
   -d DEV, --device=DEV  Serial Device for SIM access [default: /dev/ttyUSB0]
144
   -b BAUD, --baud=BAUD  Baudrate used for SIM access [default: 9600]
145
   -p PCSC, --pcsc-device=PCSC
146
                         Which PC/SC reader number for SIM access
147
   -t TYPE, --type=TYPE  Card type (user -t list to view) [default: auto]
148
   -a PIN_ADM, --pin-adm=PIN_ADM
149
                         ADM PIN used for provisioning (overwrites default)
150
   -e, --erase           Erase beforehand [default: False]
151
   -S SOURCE, --source=SOURCE
152
                         Data Source[default: cmdline]
153
   -n NAME, --name=NAME  Operator name [default: Magic]
154
   -c CC, --country=CC   Country code [default: 1]
155
   -x MCC, --mcc=MCC     Mobile Country Code [default: 901]
156
   -y MNC, --mnc=MNC     Mobile Network Code [default: 55]
157
   -m SMSC, --smsc=SMSC  SMSP [default: '00 + country code + 5555']
158
   -M SMSP, --smsp=SMSP  Raw SMSP content in hex [default: auto from SMSC]
159
   -s ID, --iccid=ID     Integrated Circuit Card ID
160 1 laforge
   -i IMSI, --imsi=IMSI  International Mobile Subscriber Identity
161 5 wirelesss
   -k KI, --ki=KI        Ki (default is to randomize)
162
   -o OPC, --opc=OPC     OPC (default is to randomize)
163
   --op=OP               Set OP to derive OPC from OP and KI
164
   --acc=ACC             Set ACC bits (Access Control Code). not all card types
165
                         are supported
166
   -z STR, --secret=STR  Secret used for ICCID/IMSI autogen
167
   -j NUM, --num=NUM     Card # used for ICCID/IMSI autogen
168
   --batch               Enable batch mode [default: False]
169
   --batch-state=FILE    Optional batch state file
170
   --read-csv=FILE       Read parameters from CSV file rather than command line
171
   --write-csv=FILE      Append generated parameters in CSV file
172
   --write-hlr=FILE      Append generated parameters to OpenBSC HLR sqlite3
173 32 wirelesss
   --dry-run             Perform a 'dry run', don't actually program the card
174 37 wirelesss
175 18 wirelesss
h3. Example of how to program a sysmoSIM-GR1 card 
176 5 wirelesss
177
The GRcard SIM is a programmable GSM SIM card. It uses a mixture of TS11.11 / ISO7816-4 and proprietary commands for programming.
178 1 laforge
179
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.
180 25 wirelesss
 
181 5 wirelesss
 $ ./pySim-prog.py -p 0 -n OpenBSC -t sysmosim-gr1 -i 901700000003080 -c 001 -x 001 -y 02 -s 1791198229180000075
182
 Insert card now (or CTRL-C to cancel)
183
 Generated card parameters :
184
  > Name    : OpenBSC
185
  > SMSP    : e1ffffffffffffffffffffffff0581005155f5ffffffffffff000000
186
  > ICCID   : 1791198229180000075
187
  > MCC/MNC : 1/2
188
  > IMSI    : 901700000003080
189
  > Ki      : 7edaeb6addbd72d2b2cc6ed7bfecc9c9
190
  > OPC     : 23f075ab9b1a113d4db822d8195ea20c
191 1 laforge
  > ACC     : None
192 5 wirelesss
 Programming ...
193 32 wirelesss
 Done !
194 37 wirelesss
195 31 wirelesss
h3. Example of how to program a sysmoUSIM-SJS1 card
196 5 wirelesss
197
(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.
198
199
200 13 wirelesss
Provisioning of different identities or keys.
201 5 wirelesss
 
202
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).
203 1 laforge
204
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.
205 26 wirelesss
206 5 wirelesss
 $ ./pySim-prog.py -p 0 -t sysmoUSIM-SJS1 -a 58001006  -x 901 -y 71 -i 901700000010659 -s 8988211000000110000 -o 398153093661279FB1FC74BE07059FEF -k 1D8B2562B992549F20D0F42113EAA6FA
207 11 wirelesss
 Insert card now (or CTRL-C to cancel)
208 5 wirelesss
 Generated card parameters :
209
  > Name    : Magic
210
  > SMSP    : e1ffffffffffffffffffffffff0581005155f5ffffffffffff000000
211
  > ICCID   : 8988211000000110000
212
  > MCC/MNC : 901/71
213 6 wirelesss
  > IMSI    : 901700000010659
214 5 wirelesss
  > Ki      : 1D8B2562B992549F20D0F42113EAA6FA
215
  > OPC     : 398153093661279FB1FC74BE07059FEF
216
  > ACC     : None
217 6 wirelesss
 Programming ...
218 5 wirelesss
 Done !
219
220 37 wirelesss
h3. Example of how to program a Magic SIM / SuperSIM 16-in-1 / X-sim card
221 5 wirelesss
222
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.
223
224 1 laforge
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.
225
226 5 wirelesss
 $ ./pySim-prog.py -p 0 -x 801 -y 71 -i 901990000000018 -s 8988211000000110000 -o 398153093661279FB1FC74BE07059FEF -k 1D8B2562B992549F20D0F42113EAA6FA
227
 Insert card now (or CTRL-C to cancel)
228
 Autodetected card type fakemagicsim
229
 Generated card parameters :
230
  > Name    : Magic
231
  > SMSP    : e1ffffffffffffffffffffffff0581005155f5ffffffffffff000000
232
  > ICCID   : 8988211000000110000
233
  > MCC/MNC : 801/71
234 1 laforge
  > IMSI    : 901990000000018
235
  > Ki      : 1D8B2562B992549F20D0F42113EAA6FA
236 37 wirelesss
  > OPC     : 398153093661279FB1FC74BE07059FEF
237 6 wirelesss
  > ACC     : None
238 37 wirelesss
 Programming ...
239 51 laforge
 Done !
240 43 laforge
241 44 roh
242 55 laforge
h3. Continuous Integration / Automatic Testing
243 45 laforge
244 44 roh
pySim is continuously and automatically tested by a [[TestRig]] run by sysmocom
245 45 laforge
246 1 laforge
{{include(cellular-infrastructure:MacroCommercialSupport)}}
Add picture from clipboard (Maximum size: 48.8 MB)