Project

General

Profile

Wiki » History » Version 39

laforge, 03/17/2017 05:00 PM

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