Project

General

Profile

Wiki » History » Version 55

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