Project

General

Profile

Wiki » History » Version 52

fixeria, 08/29/2022 05:46 PM
add missing dependencies from README.md

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 38 wirelesss
<pre>
75 37 wirelesss
 sudo apt-get install pcscd pcsc-tools libccid libpcsclite-dev python-pyscard
76 36 neels
</pre>
77 37 wirelesss
78 16 wirelesss
* Connect SIM card reader.
79 37 wirelesss
80 1 laforge
* Insert programmable SIM card
81 37 wirelesss
82 1 laforge
h3. Check the status of connection by entering the following command:
83 37 wirelesss
84 34 wirelesss
<pre>
85 37 wirelesss
 pcsc_scan
86 5 wirelesss
</pre>
87 37 wirelesss
88 32 wirelesss
* If SIM card reader is recognised then we can expect something similar to the below output:
89 37 wirelesss
90 5 wirelesss
<pre>
91
 $ pcsc_scan
92
 PC/SC device scanner
93
 V 1.4.25 (c) 2001-2011, Ludovic Rousseau ludovic.rousseau@free.fr
94
 Compiled with PC/SC lite version: 1.8.14
95
 Using reader plug'n play mechanism
96
 Scanning present readers...
97
 0: SCM Microsystems Inc. SCR 3310 [CCID Interface] 00 00 
98
 Tue Oct 18 11:48:08 2016
99
 Reader 0: SCM Microsystems Inc. SCR 3310 [CCID Interface] 00 00
100
 Card state: Card inserted, 
101
 ATR: 3B 99 18 00 11 88 22 33 44 55 66 77 60
102
 + TS = 3B --> Direct Convention
103 20 wirelesss
 + T0 = 99, Y(1): 1001, K: 9 (historical bytes)
104 1 laforge
  TA(1) = 18 --> Fi=372, Di=12, 31 cycles/ETU
105 20 wirelesss
  129032 bits/s at 4 MHz, fMax for Fi = 5 MHz => 161290 bits/s
106 1 laforge
  TD(1) = 00 --> Y(i+1) = 0000, Protocol T = 0 
107
 -----
108 20 wirelesss
 + Historical bytes: 11 88 22 33 44 55 66 77 60
109 1 laforge
 Category indicator byte: 11 (proprietary format)
110
 Possibly identified card (using /usr/share/pcsc/smartcard_list.txt):
111
 3B 99 18 00 11 88 22 33 44 55 66 77 60
112 20 wirelesss
 sysmocom sysmoSIM-GR1
113 37 wirelesss
114 20 wirelesss
</pre>
115 37 wirelesss
116 20 wirelesss
** Exit pcsc_scan : _Ctrl+C_
117 1 laforge
118 37 wirelesss
119
h3. Get the code of PySIM by entering command:
120
121 1 laforge
<pre>
122 51 laforge
 git clone https://gitea.osmocom.org/sim-card/pysim
123 1 laforge
</pre>
124 37 wirelesss
125 5 wirelesss
<pre>
126 37 wirelesss
 cd pysim
127 32 wirelesss
</pre>
128 37 wirelesss
129 5 wirelesss
h3. Read your SIM card
130
131 32 wirelesss
 ./pySim-read.py -p0 or ./pySim-read.py -p1 
132 37 wirelesss
133 1 laforge
* Using sysmoSIM-GR1 and if everything is done correctly, you will see something similar to:
134 37 wirelesss
 
135 1 laforge
<pre>
136 5 wirelesss
 $ ./pySim-read.py -p0 
137
 Reading ...
138
 ICCID: 1791198229180000071
139
 IMSI: 001640000000071
140
 SMSP: ffffffffffffffffffffffffe1ffffffffffffffffffffffff0581005155f5ffffffffffff000000
141
 ACC: ffff
142
 MSISDN: Not available
143
 Done !
144 37 wirelesss
145 5 wirelesss
</pre>
146 37 wirelesss
147 17 wirelesss
h3. Program your SIM card
148 37 wirelesss
149 1 laforge
* Enter   @./pySim-prog.py -help@   to get overview of possible options. 
150 7 wirelesss
151 5 wirelesss
Similar result should appear: 
152
153
 $ ./pySim-prog.py -help
154
 Usage: pySim-prog.py [options]
155
 Options:
156
   -h, --help            show this help message and exit
157
   -d DEV, --device=DEV  Serial Device for SIM access [default: /dev/ttyUSB0]
158
   -b BAUD, --baud=BAUD  Baudrate used for SIM access [default: 9600]
159
   -p PCSC, --pcsc-device=PCSC
160
                         Which PC/SC reader number for SIM access
161
   -t TYPE, --type=TYPE  Card type (user -t list to view) [default: auto]
162
   -a PIN_ADM, --pin-adm=PIN_ADM
163
                         ADM PIN used for provisioning (overwrites default)
164
   -e, --erase           Erase beforehand [default: False]
165
   -S SOURCE, --source=SOURCE
166
                         Data Source[default: cmdline]
167
   -n NAME, --name=NAME  Operator name [default: Magic]
168
   -c CC, --country=CC   Country code [default: 1]
169
   -x MCC, --mcc=MCC     Mobile Country Code [default: 901]
170
   -y MNC, --mnc=MNC     Mobile Network Code [default: 55]
171
   -m SMSC, --smsc=SMSC  SMSP [default: '00 + country code + 5555']
172
   -M SMSP, --smsp=SMSP  Raw SMSP content in hex [default: auto from SMSC]
173
   -s ID, --iccid=ID     Integrated Circuit Card ID
174 1 laforge
   -i IMSI, --imsi=IMSI  International Mobile Subscriber Identity
175 5 wirelesss
   -k KI, --ki=KI        Ki (default is to randomize)
176
   -o OPC, --opc=OPC     OPC (default is to randomize)
177
   --op=OP               Set OP to derive OPC from OP and KI
178
   --acc=ACC             Set ACC bits (Access Control Code). not all card types
179
                         are supported
180
   -z STR, --secret=STR  Secret used for ICCID/IMSI autogen
181
   -j NUM, --num=NUM     Card # used for ICCID/IMSI autogen
182
   --batch               Enable batch mode [default: False]
183
   --batch-state=FILE    Optional batch state file
184
   --read-csv=FILE       Read parameters from CSV file rather than command line
185
   --write-csv=FILE      Append generated parameters in CSV file
186
   --write-hlr=FILE      Append generated parameters to OpenBSC HLR sqlite3
187 32 wirelesss
   --dry-run             Perform a 'dry run', don't actually program the card
188 37 wirelesss
189 18 wirelesss
h3. Example of how to program a sysmoSIM-GR1 card 
190 5 wirelesss
191
The GRcard SIM is a programmable GSM SIM card. It uses a mixture of TS11.11 / ISO7816-4 and proprietary commands for programming.
192 1 laforge
193
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.
194 25 wirelesss
 
195 5 wirelesss
 $ ./pySim-prog.py -p 0 -n OpenBSC -t sysmosim-gr1 -i 901700000003080 -c 001 -x 001 -y 02 -s 1791198229180000075
196
 Insert card now (or CTRL-C to cancel)
197
 Generated card parameters :
198
  > Name    : OpenBSC
199
  > SMSP    : e1ffffffffffffffffffffffff0581005155f5ffffffffffff000000
200
  > ICCID   : 1791198229180000075
201
  > MCC/MNC : 1/2
202
  > IMSI    : 901700000003080
203
  > Ki      : 7edaeb6addbd72d2b2cc6ed7bfecc9c9
204
  > OPC     : 23f075ab9b1a113d4db822d8195ea20c
205 1 laforge
  > ACC     : None
206 5 wirelesss
 Programming ...
207 32 wirelesss
 Done !
208 37 wirelesss
209 31 wirelesss
h3. Example of how to program a sysmoUSIM-SJS1 card
210 5 wirelesss
211
(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.
212
213
214 13 wirelesss
Provisioning of different identities or keys.
215 5 wirelesss
 
216
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).
217 1 laforge
218 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.
219 5 wirelesss
220 11 wirelesss
 $ ./pySim-prog.py -p 0 -t sysmoUSIM-SJS1 -a 58001006  -x 901 -y 71 -i 901700000010659 -s 8988211000000110000 -o 398153093661279FB1FC74BE07059FEF -k 1D8B2562B992549F20D0F42113EAA6FA
221 5 wirelesss
 Insert card now (or CTRL-C to cancel)
222
 Generated card parameters :
223
  > Name    : Magic
224
  > SMSP    : e1ffffffffffffffffffffffff0581005155f5ffffffffffff000000
225
  > ICCID   : 8988211000000110000
226 6 wirelesss
  > MCC/MNC : 901/71
227 5 wirelesss
  > IMSI    : 901700000010659
228
  > Ki      : 1D8B2562B992549F20D0F42113EAA6FA
229
  > OPC     : 398153093661279FB1FC74BE07059FEF
230 6 wirelesss
  > ACC     : None
231 5 wirelesss
 Programming ...
232
 Done !
233 37 wirelesss
234 5 wirelesss
h3. Example of how to program a Magic SIM / SuperSIM 16-in-1 / X-sim card
235
236
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.
237 1 laforge
238
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.
239 5 wirelesss
240
 $ ./pySim-prog.py -p 0 -x 801 -y 71 -i 901990000000018 -s 8988211000000110000 -o 398153093661279FB1FC74BE07059FEF -k 1D8B2562B992549F20D0F42113EAA6FA
241
 Insert card now (or CTRL-C to cancel)
242
 Autodetected card type fakemagicsim
243
 Generated card parameters :
244
  > Name    : Magic
245
  > SMSP    : e1ffffffffffffffffffffffff0581005155f5ffffffffffff000000
246
  > ICCID   : 8988211000000110000
247 1 laforge
  > MCC/MNC : 801/71
248 5 wirelesss
  > IMSI    : 901990000000018
249 1 laforge
  > Ki      : 1D8B2562B992549F20D0F42113EAA6FA
250 5 wirelesss
  > OPC     : 398153093661279FB1FC74BE07059FEF
251
  > ACC     : None
252
 Programming ...
253
 Done !
254 37 wirelesss
255 6 wirelesss
h3. README 
256 37 wirelesss
257 51 laforge
pySim comes with following README file: https://gitea.osmocom.org/sim-card/pysim/src/branch/master/README.md
258 43 laforge
259 44 roh
260
h3. Testing
261 45 laforge
262 44 roh
pySim is continuously and automatically tested by a [[TestRig]] run by sysmocom
263 45 laforge
264 1 laforge
{{include(cellular-infrastructure:MacroCommercialSupport)}}
Add picture from clipboard (Maximum size: 48.8 MB)