blob: 8f85246d96d2632e5a1cfb56c417b687d6fdc277 [file] [log] [blame]
Harald Welte94e87352021-04-02 13:38:00 +02001pySim-shell
2===========
Harald Weltebe9516f2021-04-03 11:30:10 +02003
4pySim-shell is an interactive command line shell for all kind of interactions with SIM cards.
5
6The interactive shell provides command for
7
8* navigating the on-card filesystem hierarchy
9* authenticating with PINs such as ADM1
10* CHV/PIN management (VERIFY, ENABLE, DISABLE, UNBLOCK)
11* decoding of SELECT response (file control parameters)
12* reading and writing of files and records in raw, hex-encoded binary format
13* for some files where related support has been developed:
14
15 * decoded reading (display file data in JSON format)
16 * decoded writing (encode from JSON to binary format, then write)
17
18By means of using the python ``cmd2`` module, various useful features improve usability:
19
20* history of commands (persistent across restarts)
21* output re-direction to files on your computer
22* output piping through external tools like 'grep'
23* tab completion of commands and SELECT-able files/directories
24* interactive help for all commands
25
Harald Weltef2e761c2021-04-11 11:56:44 +020026Running pySim-shell
27-------------------
28
29pySim-shell has a variety of command line arguments to control
30
31* which transport to use (how to use a reader to talk to the SIM card)
32* whether to automatically verify an ADM pin (and in which format)
33* whether to execute a start-up script
34
35.. argparse::
36 :module: pySim-shell
37 :func: option_parser
38
Merlin Chlosta69b69d42023-05-11 12:59:01 +020039Usage Examples
40--------------
41.. toctree::
42 :maxdepth: 1
43 :caption: Tutorials for pySIM-shell:
44
45 suci-tutorial
Harald Weltef2e761c2021-04-11 11:56:44 +020046
Harald Weltebe9516f2021-04-03 11:30:10 +020047
48cmd2 basics
49-----------
50
51FIXME
52
53
54
55ISO7816 commands
56----------------
57
58This category of commands relates to commands that originate in the ISO 7861-4 specifications,
59most of them have a 1:1 resemblance in the specification.
60
61select
62~~~~~~
63
64The ``select`` command is used to select a file, either by its FID, AID or by its symbolic name.
65
66Try ``select`` with tab-completion to get a list of all current selectable items:
67
68::
69
70 pySIM-shell (MF)> select
71 .. 2fe2 a0000000871004 EF.ARR MF
72 2f00 3f00 ADF.ISIM EF.DIR
73 2f05 7f10 ADF.USIM EF.ICCID
74 2f06 7f20 DF.GSM EF.PL
75 2f08 a0000000871002 DF.TELECOM EF.UMPC
76
77Use ``select`` with a specific FID or name to select the new file.
78
79This will
80
81* output the [JSON decoded, if possible] select response
82* change the prompt to the newly selected file
83* enable any commands specific to the newly-selected file
84
85::
86
87 pySIM-shell (MF)> select ADF.USIM
88 {
89 "file_descriptor": {
Harald Welte747a9782022-02-13 17:52:28 +010090 "file_descriptor_byte": {
91 "shareable": true,
92 "file_type": "df",
93 "structure": "no_info_given"
94 }
Harald Weltebe9516f2021-04-03 11:30:10 +020095 },
96 "df_name": "A0000000871002FFFFFFFF8907090000",
97 "proprietary_info": {
98 "uicc_characteristics": "71",
99 "available_memory": 101640
100 },
101 "life_cycle_status_int": "operational_activated",
102 "security_attrib_compact": "00",
103 "pin_status_template_do": "90017083010183018183010A83010B"
104 }
105 pySIM-shell (MF/ADF.USIM)>
106
107
Harald Welted01bd362022-02-15 15:56:48 +0100108status
109~~~~~~
110
111The ``status`` command [re-]obtains the File Control Template of the
112currently-selected file and print its decoded output.
113
114Example:
115
116::
117
118 pySIM-shell (MF/ADF.ISIM)> status
119 {
120 "file_descriptor": {
121 "file_descriptor_byte": {
122 "shareable": true,
123 "file_type": "df",
124 "structure": "no_info_given"
125 },
126 "record_len": null,
127 "num_of_rec": null
128 },
129 "file_identifier": "ff01",
130 "df_name": "a0000000871004ffffffff8907090000",
131 "proprietary_information": {
132 "uicc_characteristics": "71",
133 "available_memory": 101640
134 },
135 "life_cycle_status_integer": "operational_activated",
136 "security_attrib_compact": "00",
137 "pin_status_template_do": {
138 "ps_do": "70",
139 "key_reference": 11
140 }
141 }
142
Harald Weltebe9516f2021-04-03 11:30:10 +0200143
144change_chv
145~~~~~~~~~~
Harald Welted36f6942021-04-04 14:37:55 +0200146.. argparse::
147 :module: pySim-shell
148 :func: Iso7816Commands.change_chv_parser
Harald Weltebe9516f2021-04-03 11:30:10 +0200149
150
151disable_chv
152~~~~~~~~~~~
Harald Welted36f6942021-04-04 14:37:55 +0200153.. argparse::
154 :module: pySim-shell
155 :func: Iso7816Commands.disable_chv_parser
Harald Weltebe9516f2021-04-03 11:30:10 +0200156
Harald Weltebe9516f2021-04-03 11:30:10 +0200157
158enable_chv
159~~~~~~~~~~
Harald Welted36f6942021-04-04 14:37:55 +0200160.. argparse::
161 :module: pySim-shell
162 :func: Iso7816Commands.enable_chv_parser
Harald Weltebe9516f2021-04-03 11:30:10 +0200163
164
165unblock_chv
166~~~~~~~~~~~
Harald Welted36f6942021-04-04 14:37:55 +0200167.. argparse::
168 :module: pySim-shell
169 :func: Iso7816Commands.unblock_chv_parser
Harald Weltebe9516f2021-04-03 11:30:10 +0200170
Harald Weltebe9516f2021-04-03 11:30:10 +0200171
172verify_chv
173~~~~~~~~~~
Harald Welted36f6942021-04-04 14:37:55 +0200174.. argparse::
175 :module: pySim-shell
176 :func: Iso7816Commands.verify_chv_parser
177
Harald Weltea4631612021-04-10 18:17:55 +0200178deactivate_file
179~~~~~~~~~~~~~~~
180Deactivate the currently selected file. This used to be called INVALIDATE in TS 11.11.
181
182
183activate_file
184~~~~~~~~~~~~~
Harald Welte799c3542022-02-15 15:56:28 +0100185.. argparse::
186 :module: pySim-shell
187 :func: Iso7816Commands.activate_file_parser
Harald Weltebe9516f2021-04-03 11:30:10 +0200188
Harald Welte703f9332021-04-10 18:39:32 +0200189open_channel
190~~~~~~~~~~~~
191.. argparse::
192 :module: pySim-shell
193 :func: Iso7816Commands.open_chan_parser
194
195close_channel
196~~~~~~~~~~~~~
197.. argparse::
198 :module: pySim-shell
199 :func: Iso7816Commands.close_chan_parser
200
Harald Weltebe9516f2021-04-03 11:30:10 +0200201
Harald Welte659781c2023-06-06 17:00:51 +0200202TS 102 221 commands
203-------------------
204
205These are commands as specified in ETSI TS 102 221, the core UICC specification.
206
Harald Welteec950532021-10-20 13:09:00 +0200207suspend_uicc
208~~~~~~~~~~~~
209This command allows you to perform the SUSPEND UICC command on the card. This is a relatively
210recent power-saving addition to the UICC specifications, allowing for suspend/resume while maintaining
211state, as opposed to a full power-off (deactivate) and power-on (activate) of the card.
212
213The pySim command just sends that SUSPEND UICC command and doesn't perform the full related sequence
214including the electrical power down.
215
216.. argparse::
Harald Welte659781c2023-06-06 17:00:51 +0200217 :module: pySim.ts_102_221
218 :func: CardProfileUICC.AddlShellCommands.suspend_uicc_parser
Harald Welteec950532021-10-20 13:09:00 +0200219
220
Harald Welte12af7932022-02-15 16:39:08 +0100221
Harald Weltebe9516f2021-04-03 11:30:10 +0200222pySim commands
223--------------
224
225Commands in this category are pySim specific; they do not have a 1:1 correspondence to ISO 7816
226or 3GPP commands. Mostly they will operate either only on local (in-memory) state, or execute
227a complex sequence of card-commands.
228
229desc
230~~~~
Harald Weltebe9516f2021-04-03 11:30:10 +0200231Display human readable file description for the currently selected file.
232
233
234dir
235~~~
Harald Welted36f6942021-04-04 14:37:55 +0200236.. argparse::
237 :module: pySim-shell
238 :func: PySimCommands.dir_parser
Harald Weltebe9516f2021-04-03 11:30:10 +0200239
Harald Welte12af7932022-02-15 16:39:08 +0100240Example:
241::
242
243 pySIM-shell (MF)> dir
244 MF
245 3f00
246 .. ADF.USIM DF.SYSTEM EF.DIR EF.UMPC
247 ADF.ARA-M DF.EIRENE DF.TELECOM EF.ICCID MF
248 ADF.ISIM DF.GSM EF.ARR EF.PL
249 14 files
250
Harald Weltebe9516f2021-04-03 11:30:10 +0200251
252export
253~~~~~~
Harald Welted36f6942021-04-04 14:37:55 +0200254.. argparse::
255 :module: pySim-shell
256 :func: PySimCommands.export_parser
257
Harald Weltebd02f842021-10-21 14:40:39 +0200258Please note that `export` works relative to the current working
259directory, so if you are in `MF`, then the export will contain all known
260files on the card. However, if you are in `ADF.ISIM`, only files below
261that ADF will be part of the export.
262
263Furthermore, it is strongly advised to first enter the ADM1 pin
264(`verify_adm`) to maximize the chance of having permission to read
265all/most files.
266
Harald Weltebe9516f2021-04-03 11:30:10 +0200267
268tree
269~~~~
Harald Welte7743c202021-05-03 23:30:11 +0200270Display a tree of the card filesystem. It is important to note that this displays a tree
271of files that might potentially exist (based on the card profile). In order to determine if
272a given file really exists on a given card, you have to try to select that file.
Harald Welted36f6942021-04-04 14:37:55 +0200273
Harald Welte12af7932022-02-15 16:39:08 +0100274Example:
275::
276
277 pySIM-shell (MF)> tree --help
278 EF.DIR 2f00 Application Directory
279 EF.ICCID 2fe2 ICC Identification
280 EF.PL 2f05 Preferred Languages
281 EF.ARR 2f06 Access Rule Reference
282 EF.UMPC 2f08 UICC Maximum Power Consumption
283 DF.TELECOM 7f10 None
284 EF.ADN 6f3a Abbreviated Dialing Numbers
285 ...
286
287
Harald Weltebe9516f2021-04-03 11:30:10 +0200288
289verify_adm
290~~~~~~~~~~
Harald Welte7743c202021-05-03 23:30:11 +0200291Verify the ADM (Administrator) PIN specified as argument. This is typically needed in order
292to get write/update permissions to most of the files on SIM cards.
293
294Currently only ADM1 is supported.
Harald Weltebe9516f2021-04-03 11:30:10 +0200295
296
Harald Weltedaf2b392021-05-03 23:17:29 +0200297reset
298~~~~~
Harald Weltedaf2b392021-05-03 23:17:29 +0200299Perform card reset and display the card ATR.
300
Harald Weltebd02f842021-10-21 14:40:39 +0200301intro
302~~~~~
303[Re-]Display the introductory banner
304
305
306equip
307~~~~~
308Equip pySim-shell with a card; particularly useful if the program was
309started before a card was present, or after a card has been replaced by
310the user while pySim-shell was kept running.
311
312bulk_script
313~~~~~~~~~~~
314.. argparse::
315 :module: pySim-shell
316 :func: PysimApp.bulk_script_parser
317
Harald Weltebd02f842021-10-21 14:40:39 +0200318
319echo
320~~~~
321.. argparse::
322 :module: pySim-shell
323 :func: PysimApp.echo_parser
324
325
Harald Welte12af7932022-02-15 16:39:08 +0100326apdu
327~~~~
328.. argparse::
329 :module: pySim-shell
330 :func: PySimCommands.apdu_cmd_parser
331
332
Harald Weltedaf2b392021-05-03 23:17:29 +0200333
Harald Weltebe9516f2021-04-03 11:30:10 +0200334Linear Fixed EF commands
335------------------------
336
337These commands become enabled only when your currently selected file is of *Linear Fixed EF* type.
338
339read_record
340~~~~~~~~~~~
Harald Welted36f6942021-04-04 14:37:55 +0200341.. argparse::
342 :module: pySim.filesystem
343 :func: LinFixedEF.ShellCommands.read_rec_parser
344
Harald Weltebe9516f2021-04-03 11:30:10 +0200345
346read_record_decoded
347~~~~~~~~~~~~~~~~~~~
Harald Welted36f6942021-04-04 14:37:55 +0200348.. argparse::
349 :module: pySim.filesystem
350 :func: LinFixedEF.ShellCommands.read_rec_dec_parser
351
Harald Weltebe9516f2021-04-03 11:30:10 +0200352
Harald Welte850b72a2021-04-07 09:33:03 +0200353read_records
354~~~~~~~~~~~~
355.. argparse::
356 :module: pySim.filesystem
357 :func: LinFixedEF.ShellCommands.read_recs_parser
358
359
360read_records_decoded
361~~~~~~~~~~~~~~~~~~~~
362.. argparse::
363 :module: pySim.filesystem
364 :func: LinFixedEF.ShellCommands.read_recs_dec_parser
365
366
Harald Weltebe9516f2021-04-03 11:30:10 +0200367update_record
368~~~~~~~~~~~~~
Harald Welted36f6942021-04-04 14:37:55 +0200369.. argparse::
370 :module: pySim.filesystem
371 :func: LinFixedEF.ShellCommands.upd_rec_parser
372
Harald Weltebe9516f2021-04-03 11:30:10 +0200373
374update_record_decoded
375~~~~~~~~~~~~~~~~~~~~~
Harald Welted36f6942021-04-04 14:37:55 +0200376.. argparse::
377 :module: pySim.filesystem
378 :func: LinFixedEF.ShellCommands.upd_rec_dec_parser
Harald Weltebe9516f2021-04-03 11:30:10 +0200379
380
Harald Welte4145d3c2021-04-08 20:34:13 +0200381edit_record_decoded
382~~~~~~~~~~~~~~~~~~~
383.. argparse::
384 :module: pySim.filesystem
385 :func: LinFixedEF.ShellCommands.edit_rec_dec_parser
386
387This command will read the selected record, decode it to its JSON representation, save
388that JSON to a temporary file on your computer, and launch your configured text editor.
389
390You may then perform whatever modifications to the JSON representation, save + leave your
391text editor.
392
393Afterwards, the modified JSON will be re-encoded to the binary format, and the result written
394back to the record on the SIM card.
395
396This allows for easy interactive modification of records.
397
398
Harald Welteaefd0642022-02-25 15:26:37 +0100399decode_hex
400~~~~~~~~~~
401.. argparse::
402 :module: pySim.filesystem
403 :func: LinFixedEF.ShellCommands.dec_hex_parser
404
405
Harald Weltebe9516f2021-04-03 11:30:10 +0200406
407Transparent EF commands
408-----------------------
409
410These commands become enabled only when your currently selected file is of *Transparent EF* type.
411
412
413read_binary
414~~~~~~~~~~~
Harald Welted36f6942021-04-04 14:37:55 +0200415.. argparse::
416 :module: pySim.filesystem
417 :func: TransparentEF.ShellCommands.read_bin_parser
418
Harald Weltebe9516f2021-04-03 11:30:10 +0200419
420read_binary_decoded
421~~~~~~~~~~~~~~~~~~~
Harald Welted36f6942021-04-04 14:37:55 +0200422.. argparse::
423 :module: pySim.filesystem
424 :func: TransparentEF.ShellCommands.read_bin_dec_parser
425
Harald Weltebe9516f2021-04-03 11:30:10 +0200426
427update_binary
428~~~~~~~~~~~~~
Harald Welted36f6942021-04-04 14:37:55 +0200429.. argparse::
430 :module: pySim.filesystem
431 :func: TransparentEF.ShellCommands.upd_bin_parser
432
Harald Weltebe9516f2021-04-03 11:30:10 +0200433
434update_binary_decoded
435~~~~~~~~~~~~~~~~~~~~~
Harald Welted36f6942021-04-04 14:37:55 +0200436.. argparse::
437 :module: pySim.filesystem
438 :func: TransparentEF.ShellCommands.upd_bin_dec_parser
Harald Weltebe9516f2021-04-03 11:30:10 +0200439
Harald Welte0d4e98a2021-04-07 00:14:40 +0200440In normal operation, update_binary_decoded needs a JSON document representing the entire file contents as
441input. This can be inconvenient if you want to keep 99% of the content but just toggle one specific
442parameter. That's where the JSONpath support comes in handy: You can specify a JSONpath to an element
443inside the document as well as a new value for tat field:
444
445Th below example demonstrates this by modifying the ofm field within EF.AD:
446
447::
448
449 pySIM-shell (MF/ADF.USIM/EF.AD)> read_binary_decoded
450 {
451 "ms_operation_mode": "normal",
452 "specific_facilities": {
453 "ofm": true
454 },
455 "len_of_mnc_in_imsi": 2
456 }
457 pySIM-shell (MF/ADF.USIM/EF.AD)> update_binary_decoded --json-path specific_facilities.ofm false
458 pySIM-shell (MF/ADF.USIM/EF.AD)> read_binary_decoded
459 {
460 "ms_operation_mode": "normal",
461 "specific_facilities": {
462 "ofm": false
463 },
464 "len_of_mnc_in_imsi": 2
465 }
466
Harald Weltebe9516f2021-04-03 11:30:10 +0200467
Harald Welte4145d3c2021-04-08 20:34:13 +0200468edit_binary_decoded
469~~~~~~~~~~~~~~~~~~~
470This command will read the selected binary EF, decode it to its JSON representation, save
471that JSON to a temporary file on your computer, and launch your configured text editor.
472
473You may then perform whatever modifications to the JSON representation, save + leave your
474text editor.
475
476Afterwards, the modified JSON will be re-encoded to the binary format, and the result written
477to the SIM card.
478
479This allows for easy interactive modification of file contents.
480
Harald Weltebe9516f2021-04-03 11:30:10 +0200481
Harald Welteaefd0642022-02-25 15:26:37 +0100482decode_hex
483~~~~~~~~~~
484.. argparse::
485 :module: pySim.filesystem
486 :func: TransparentEF.ShellCommands.dec_hex_parser
487
488
Harald Welte917d98c2021-04-21 11:51:25 +0200489
490BER-TLV EF commands
491-------------------
492
493BER-TLV EFs are files that contain BER-TLV structured data. Every file can contain any number
494of variable-length IEs (DOs). The tag within a BER-TLV EF must be unique within the file.
495
496The commands below become enabled only when your currently selected file is of *BER-TLV EF* type.
497
498retrieve_tags
499~~~~~~~~~~~~~
500
501Retrieve a list of all tags present in the currently selected file.
502
503
504retrieve_data
505~~~~~~~~~~~~~
506.. argparse::
507 :module: pySim.filesystem
508 :func: BerTlvEF.ShellCommands.retrieve_data_parser
509
510
511set_data
512~~~~~~~~
513.. argparse::
514 :module: pySim.filesystem
515 :func: BerTlvEF.ShellCommands.set_data_parser
516
517
518del_data
519~~~~~~~~
520.. argparse::
521 :module: pySim.filesystem
522 :func: BerTlvEF.ShellCommands.del_data_parser
523
524
525
Harald Welte15fae982021-04-10 10:22:27 +0200526USIM commands
527-------------
528
Harald Welte577312a2023-02-23 09:51:30 +0100529These commands are available only while ADF.USIM (or ADF.ISIM, respectively) is selected.
530
Harald Welte15fae982021-04-10 10:22:27 +0200531authenticate
532~~~~~~~~~~~~
533.. argparse::
534 :module: pySim.ts_31_102
535 :func: ADF_USIM.AddlShellCommands.authenticate_parser
536
Harald Welte12af7932022-02-15 16:39:08 +0100537terminal_profile
538~~~~~~~~~~~~~~~~
539.. argparse::
540 :module: pySim.ts_31_102
541 :func: ADF_USIM.AddlShellCommands.term_prof_parser
542
543envelope
544~~~~~~~~
545.. argparse::
546 :module: pySim.ts_31_102
547 :func: ADF_USIM.AddlShellCommands.envelope_parser
548
549envelope_sms
550~~~~~~~~~~~~
551.. argparse::
552 :module: pySim.ts_31_102
553 :func: ADF_USIM.AddlShellCommands.envelope_sms_parser
554
555
Harald Welte577312a2023-02-23 09:51:30 +0100556File-specific commands
557----------------------
558
559These commands are valid only if the respective file is currently selected. They perform some
560operation that's specific to this file only.
561
562EF.ARR: read_arr_record
563~~~~~~~~~~~~~~~~~~~~~~~
564Read one EF.ARR record in flattened, human-friendly form.
565
566EF.ARR: read_arr_records
567~~~~~~~~~~~~~~~~~~~~~~~~
568Read + decode all EF.ARR records in flattened, human-friendly form.
569
Harald Weltec224b3b2023-05-23 18:44:44 +0200570DF.GSM/EF.SST: sst_service_allocate
571~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
572Mark a given single service as allocated in EF.SST. Requires service number as argument.
573
574DF.GSM/EF.SST: sst_service_activate
575~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
576Mark a given single service as activated in EF.SST. Requires service number as argument.
577
578DF.GSM/EF.SST: sst_service_deallocate
579~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
580Mark a given single service as deallocated in EF.SST. Requires service number as argument.
581
582DF.GSM/EF.SST: sst_service_deactivate
583~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
584Mark a given single service as deactivated in EF.SST. Requires service number as argument.
585
Harald Weltea07d5092023-02-23 10:02:49 +0100586ADF.USIM/EF.EST: est_service_enable
587~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
588Enables a single service in EF.EST. Requires service number as argument.
589
590ADF.USIM/EF.EST: est_service_disable
591~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
592Disables a single service in EF.EST. Requires service number as argument.
593
Harald Welte577312a2023-02-23 09:51:30 +0100594EF.IMSI: update_imsi_plmn
595~~~~~~~~~~~~~~~~~~~~~~~~~
596Change the PLMN part (MCC+MNC) of the IMSI. Requires a single argument consisting of 5/6 digits of
597concatenated MCC+MNC.
598
599ADF.USIM/EF.UST: ust_service_activate
600~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
601Activates a single service in EF.UST. Requires service number as argument.
602
603ADF.USIM/EF.UST: ust_service_deactivate
604~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
605Deactivates a single service in EF.UST. Requires service number as argument.
606
607ADF.USIM/EF.UST: ust_service_check
608~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
609Check consistency between services of this file and files present/activated.
610Many services determine if one or multiple files shall be present/activated or if they shall be
611absent/deactivated. This performs a consistency check to ensure that no services are activated
612for files that are not - and vice-versa, no files are activated for services that are not. Error
613messages are printed for every inconsistency found.
614
615ADF.ISIM/EF.IST: ist_service_activate
616~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
617Activates a single service in EF.IST. Requires service number as argument.
618
619ADF.ISIM/EF.IST: ist_service_deactivate
620~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
621Deactivates a single service in EF.UST. Requires service number as argument.
622
623ADF.ISIM/EF.IST: ist_service_check
624~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
625Check consistency between services of this file and files present/activated.
626Many services determine if one or multiple files shall be present/activated or if they shall be
627absent/deactivated. This performs a consistency check to ensure that no services are activated
628for files that are not - and vice-versa, no files are activated for services that are not. Error
629messages are printed for every inconsistency found.
630
631
632UICC Administrative commands
633----------------------------
634
635ETSI TS 102 222 specifies a set of *Administrative Commands*, which can
636be used by the card issuer / operator to modify the file system structure
637(delete files, create files) or even to terminate individual files or the
638entire card.
639
640pySim-shell supports those commands, but **use extreme caution**.
641Unless you know exactly what you're doing, it's very easy to render your
642card unusable. You've been warned!
643
644delete_file
645~~~~~~~~~~~
646.. argparse::
647 :module: pySim.ts_102_222
648 :func: Ts102222Commands.delfile_parser
649
650
651terminate_df
652~~~~~~~~~~~~
653.. argparse::
654 :module: pySim.ts_102_222
655 :func: Ts102222Commands.termdf_parser
656
657terminate_ef
658~~~~~~~~~~~~
659.. argparse::
660 :module: pySim.ts_102_222
661 :func: Ts102222Commands.termdf_parser
662
663terminate_card
664~~~~~~~~~~~~~~
665.. argparse::
666 :module: pySim.ts_102_222
667 :func: Ts102222Commands.tcard_parser
668
669create_ef
670~~~~~~~~~
671.. argparse::
672 :module: pySim.ts_102_222
673 :func: Ts102222Commands.create_parser
674
675create_df
676~~~~~~~~~
677.. argparse::
678 :module: pySim.ts_102_222
679 :func: Ts102222Commands.createdf_parser
Harald Welte12af7932022-02-15 16:39:08 +0100680
Harald Welte0707b802023-03-07 11:43:37 +0100681resize_ef
682~~~~~~~~~
683.. argparse::
684 :module: pySim.ts_102_222
685 :func: Ts102222Commands.resize_ef_parser
686
Harald Welte15fae982021-04-10 10:22:27 +0200687
Harald Welte95ce6b12021-10-20 18:40:54 +0200688ARA-M commands
689--------------
690
691The ARA-M commands exist to manage the access rules stored in an ARA-M applet on the card.
692
693ARA-M in the context of SIM cards is primarily used to enable Android UICC Carrier Privileges,
694please see https://source.android.com/devices/tech/config/uicc for more details on the background.
695
696
697aram_get_all
698~~~~~~~~~~~~
699
700Obtain and decode all access rules from the ARA-M applet on the card.
701
702NOTE: if the total size of the access rules exceeds 255 bytes, this command will fail, as
703it doesn't yet implement fragmentation/reassembly on rule retrieval. YMMV
704
705::
706
707 pySIM-shell (MF/ADF.ARA-M)> aram_get_all
708 [
709 {
710 "ResponseAllRefArDO": [
711 {
712 "RefArDO": [
713 {
714 "RefDO": [
715 {
716 "AidRefDO": "ffffffffffff"
717 },
718 {
719 "DevAppIdRefDO": "e46872f28b350b7e1f140de535c2a8d5804f0be3"
720 }
721 ]
722 },
723 {
724 "ArDO": [
725 {
726 "ApduArDO": {
727 "generic_access_rule": "always"
728 }
729 },
730 {
731 "PermArDO": {
732 "permissions": "0000000000000001"
733 }
734 }
735 ]
736 }
737 ]
738 }
739 ]
740 }
741 ]
742
743aram_get_config
744~~~~~~~~~~~~~~~
745Perform Config handshake with ARA-M applet: Tell it our version and retrieve its version.
746
747NOTE: Not supported in all ARA-M implementations.
748
Harald Welte95ce6b12021-10-20 18:40:54 +0200749
750aram_store_ref_ar_do
751~~~~~~~~~~~~~~~~~~~~
Harald Welte95ce6b12021-10-20 18:40:54 +0200752.. argparse::
753 :module: pySim.ara_m
754 :func: ADF_ARAM.AddlShellCommands.store_ref_ar_do_parse
755
756For example, to store an Android UICC carrier privilege rule for the SHA1 hash of the certificate used to sign the CoIMS android app of Supreeth Herle (https://github.com/herlesupreeth/CoIMS_Wiki) you can use the following command:
Harald Welte95ce6b12021-10-20 18:40:54 +0200757::
758
759 pySIM-shell (MF/ADF.ARA-M)> aram_store_ref_ar_do --aid FFFFFFFFFFFF --device-app-id E46872F28B350B7E1F140DE535C2A8D5804F0BE3 --android-permissions 0000000000000001 --apdu-always
760
761
762aram_delete_all
763~~~~~~~~~~~~~~~
764This command will request deletion of all access rules stored within the
765ARA-M applet. Use it with caution, there is no undo. Any rules later
766intended must be manually inserted again using `aram_store_ref_ar_do`
767
768
Harald Welte577312a2023-02-23 09:51:30 +0100769GlobalPlatform commands
770-----------------------
771
772pySim-shell has only the mots rudimentary support for GlobalPlatform at this point. Please use dedicated
773projects like GlobalPlatformPro meanwhile.
774
775get_data
776~~~~~~~~
777Performs the GET DATA command as specified by GlobalPlatform.
778
Harald Welte15fae982021-04-10 10:22:27 +0200779
Harald Weltebe9516f2021-04-03 11:30:10 +0200780cmd2 settable parameters
781------------------------
782
783``cmd2`` has the concept of *settable parameters* which act a bit like environment variables in an OS-level
784shell: They can be read and set, and they will influence the behavior somehow.
785
786conserve_write
787~~~~~~~~~~~~~~
788
789If enabled, pySim will (when asked to write to a card) always first read the respective file/record and
790verify if the to-be-written value differs from the current on-card value. If not, the write will be skipped.
791Writes will only be performed if the new value is different from the current on-card value.
792
793If disabled, pySim will always write irrespective of the current/new value.
794
Harald Welte1748b932021-04-06 21:12:25 +0200795json_pretty_print
796~~~~~~~~~~~~~~~~~
797
798This parameter determines if generated JSON output should (by default) be pretty-printed (multi-line
799output with indent level of 4 spaces) or not.
800
801The default value of this parameter is 'true'.
802
Harald Weltebe9516f2021-04-03 11:30:10 +0200803debug
804~~~~~
805
806If enabled, full python back-traces will be displayed in case of exceptions
807
Harald Welte7829d8a2021-04-10 11:28:53 +0200808apdu_trace
809~~~~~~~~~~
810
811Boolean variable that determines if a hex-dump of the command + response APDU shall be printed.
812
Harald Weltebe9516f2021-04-03 11:30:10 +0200813numeric_path
814~~~~~~~~~~~~
815
816Boolean variable that determines if path (e.g. in prompt) is displayed with numeric FIDs or string names.
817
818::
819
820 pySIM-shell (MF/EF.ICCID)> set numeric_path True
821 numeric_path - was: False
822 now: True
823 pySIM-shell (3f00/2fe2)> set numeric_path False
824 numeric_path - was: True
825 now: False
826 pySIM-shell (MF/EF.ICCID)> help set