Harald Welte | 94e8735 | 2021-04-02 13:38:00 +0200 | [diff] [blame] | 1 | pySim-shell |
| 2 | =========== |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 3 | |
| 4 | pySim-shell is an interactive command line shell for all kind of interactions with SIM cards. |
| 5 | |
| 6 | The 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 | |
| 18 | By 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 Welte | f2e761c | 2021-04-11 11:56:44 +0200 | [diff] [blame] | 26 | Running pySim-shell |
| 27 | ------------------- |
| 28 | |
| 29 | pySim-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 Chlosta | 69b69d4 | 2023-05-11 12:59:01 +0200 | [diff] [blame] | 39 | Usage Examples |
| 40 | -------------- |
| 41 | .. toctree:: |
| 42 | :maxdepth: 1 |
| 43 | :caption: Tutorials for pySIM-shell: |
| 44 | |
| 45 | suci-tutorial |
Harald Welte | f2e761c | 2021-04-11 11:56:44 +0200 | [diff] [blame] | 46 | |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 47 | |
| 48 | cmd2 basics |
| 49 | ----------- |
| 50 | |
| 51 | FIXME |
| 52 | |
| 53 | |
| 54 | |
| 55 | ISO7816 commands |
| 56 | ---------------- |
| 57 | |
| 58 | This category of commands relates to commands that originate in the ISO 7861-4 specifications, |
| 59 | most of them have a 1:1 resemblance in the specification. |
| 60 | |
| 61 | select |
| 62 | ~~~~~~ |
| 63 | |
| 64 | The ``select`` command is used to select a file, either by its FID, AID or by its symbolic name. |
| 65 | |
| 66 | Try ``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 | |
| 77 | Use ``select`` with a specific FID or name to select the new file. |
| 78 | |
| 79 | This 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 Welte | 747a978 | 2022-02-13 17:52:28 +0100 | [diff] [blame] | 90 | "file_descriptor_byte": { |
| 91 | "shareable": true, |
| 92 | "file_type": "df", |
| 93 | "structure": "no_info_given" |
| 94 | } |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 95 | }, |
| 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 Welte | d01bd36 | 2022-02-15 15:56:48 +0100 | [diff] [blame] | 108 | status |
| 109 | ~~~~~~ |
| 110 | |
| 111 | The ``status`` command [re-]obtains the File Control Template of the |
| 112 | currently-selected file and print its decoded output. |
| 113 | |
| 114 | Example: |
| 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 Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 143 | |
| 144 | change_chv |
| 145 | ~~~~~~~~~~ |
Harald Welte | d36f694 | 2021-04-04 14:37:55 +0200 | [diff] [blame] | 146 | .. argparse:: |
| 147 | :module: pySim-shell |
| 148 | :func: Iso7816Commands.change_chv_parser |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 149 | |
| 150 | |
| 151 | disable_chv |
| 152 | ~~~~~~~~~~~ |
Harald Welte | d36f694 | 2021-04-04 14:37:55 +0200 | [diff] [blame] | 153 | .. argparse:: |
| 154 | :module: pySim-shell |
| 155 | :func: Iso7816Commands.disable_chv_parser |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 156 | |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 157 | |
| 158 | enable_chv |
| 159 | ~~~~~~~~~~ |
Harald Welte | d36f694 | 2021-04-04 14:37:55 +0200 | [diff] [blame] | 160 | .. argparse:: |
| 161 | :module: pySim-shell |
| 162 | :func: Iso7816Commands.enable_chv_parser |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 163 | |
| 164 | |
| 165 | unblock_chv |
| 166 | ~~~~~~~~~~~ |
Harald Welte | d36f694 | 2021-04-04 14:37:55 +0200 | [diff] [blame] | 167 | .. argparse:: |
| 168 | :module: pySim-shell |
| 169 | :func: Iso7816Commands.unblock_chv_parser |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 170 | |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 171 | |
| 172 | verify_chv |
| 173 | ~~~~~~~~~~ |
Harald Welte | d36f694 | 2021-04-04 14:37:55 +0200 | [diff] [blame] | 174 | .. argparse:: |
| 175 | :module: pySim-shell |
| 176 | :func: Iso7816Commands.verify_chv_parser |
| 177 | |
Harald Welte | a463161 | 2021-04-10 18:17:55 +0200 | [diff] [blame] | 178 | deactivate_file |
| 179 | ~~~~~~~~~~~~~~~ |
| 180 | Deactivate the currently selected file. This used to be called INVALIDATE in TS 11.11. |
| 181 | |
| 182 | |
| 183 | activate_file |
| 184 | ~~~~~~~~~~~~~ |
Harald Welte | 799c354 | 2022-02-15 15:56:28 +0100 | [diff] [blame] | 185 | .. argparse:: |
| 186 | :module: pySim-shell |
| 187 | :func: Iso7816Commands.activate_file_parser |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 188 | |
Harald Welte | 703f933 | 2021-04-10 18:39:32 +0200 | [diff] [blame] | 189 | open_channel |
| 190 | ~~~~~~~~~~~~ |
| 191 | .. argparse:: |
| 192 | :module: pySim-shell |
| 193 | :func: Iso7816Commands.open_chan_parser |
| 194 | |
| 195 | close_channel |
| 196 | ~~~~~~~~~~~~~ |
| 197 | .. argparse:: |
| 198 | :module: pySim-shell |
| 199 | :func: Iso7816Commands.close_chan_parser |
| 200 | |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 201 | |
Harald Welte | 659781c | 2023-06-06 17:00:51 +0200 | [diff] [blame^] | 202 | TS 102 221 commands |
| 203 | ------------------- |
| 204 | |
| 205 | These are commands as specified in ETSI TS 102 221, the core UICC specification. |
| 206 | |
Harald Welte | ec95053 | 2021-10-20 13:09:00 +0200 | [diff] [blame] | 207 | suspend_uicc |
| 208 | ~~~~~~~~~~~~ |
| 209 | This command allows you to perform the SUSPEND UICC command on the card. This is a relatively |
| 210 | recent power-saving addition to the UICC specifications, allowing for suspend/resume while maintaining |
| 211 | state, as opposed to a full power-off (deactivate) and power-on (activate) of the card. |
| 212 | |
| 213 | The pySim command just sends that SUSPEND UICC command and doesn't perform the full related sequence |
| 214 | including the electrical power down. |
| 215 | |
| 216 | .. argparse:: |
Harald Welte | 659781c | 2023-06-06 17:00:51 +0200 | [diff] [blame^] | 217 | :module: pySim.ts_102_221 |
| 218 | :func: CardProfileUICC.AddlShellCommands.suspend_uicc_parser |
Harald Welte | ec95053 | 2021-10-20 13:09:00 +0200 | [diff] [blame] | 219 | |
| 220 | |
Harald Welte | 12af793 | 2022-02-15 16:39:08 +0100 | [diff] [blame] | 221 | |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 222 | pySim commands |
| 223 | -------------- |
| 224 | |
| 225 | Commands in this category are pySim specific; they do not have a 1:1 correspondence to ISO 7816 |
| 226 | or 3GPP commands. Mostly they will operate either only on local (in-memory) state, or execute |
| 227 | a complex sequence of card-commands. |
| 228 | |
| 229 | desc |
| 230 | ~~~~ |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 231 | Display human readable file description for the currently selected file. |
| 232 | |
| 233 | |
| 234 | dir |
| 235 | ~~~ |
Harald Welte | d36f694 | 2021-04-04 14:37:55 +0200 | [diff] [blame] | 236 | .. argparse:: |
| 237 | :module: pySim-shell |
| 238 | :func: PySimCommands.dir_parser |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 239 | |
Harald Welte | 12af793 | 2022-02-15 16:39:08 +0100 | [diff] [blame] | 240 | Example: |
| 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 Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 251 | |
| 252 | export |
| 253 | ~~~~~~ |
Harald Welte | d36f694 | 2021-04-04 14:37:55 +0200 | [diff] [blame] | 254 | .. argparse:: |
| 255 | :module: pySim-shell |
| 256 | :func: PySimCommands.export_parser |
| 257 | |
Harald Welte | bd02f84 | 2021-10-21 14:40:39 +0200 | [diff] [blame] | 258 | Please note that `export` works relative to the current working |
| 259 | directory, so if you are in `MF`, then the export will contain all known |
| 260 | files on the card. However, if you are in `ADF.ISIM`, only files below |
| 261 | that ADF will be part of the export. |
| 262 | |
| 263 | Furthermore, it is strongly advised to first enter the ADM1 pin |
| 264 | (`verify_adm`) to maximize the chance of having permission to read |
| 265 | all/most files. |
| 266 | |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 267 | |
| 268 | tree |
| 269 | ~~~~ |
Harald Welte | 7743c20 | 2021-05-03 23:30:11 +0200 | [diff] [blame] | 270 | Display a tree of the card filesystem. It is important to note that this displays a tree |
| 271 | of files that might potentially exist (based on the card profile). In order to determine if |
| 272 | a given file really exists on a given card, you have to try to select that file. |
Harald Welte | d36f694 | 2021-04-04 14:37:55 +0200 | [diff] [blame] | 273 | |
Harald Welte | 12af793 | 2022-02-15 16:39:08 +0100 | [diff] [blame] | 274 | Example: |
| 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 Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 288 | |
| 289 | verify_adm |
| 290 | ~~~~~~~~~~ |
Harald Welte | 7743c20 | 2021-05-03 23:30:11 +0200 | [diff] [blame] | 291 | Verify the ADM (Administrator) PIN specified as argument. This is typically needed in order |
| 292 | to get write/update permissions to most of the files on SIM cards. |
| 293 | |
| 294 | Currently only ADM1 is supported. |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 295 | |
| 296 | |
Harald Welte | daf2b39 | 2021-05-03 23:17:29 +0200 | [diff] [blame] | 297 | reset |
| 298 | ~~~~~ |
Harald Welte | daf2b39 | 2021-05-03 23:17:29 +0200 | [diff] [blame] | 299 | Perform card reset and display the card ATR. |
| 300 | |
Harald Welte | bd02f84 | 2021-10-21 14:40:39 +0200 | [diff] [blame] | 301 | intro |
| 302 | ~~~~~ |
| 303 | [Re-]Display the introductory banner |
| 304 | |
| 305 | |
| 306 | equip |
| 307 | ~~~~~ |
| 308 | Equip pySim-shell with a card; particularly useful if the program was |
| 309 | started before a card was present, or after a card has been replaced by |
| 310 | the user while pySim-shell was kept running. |
| 311 | |
| 312 | bulk_script |
| 313 | ~~~~~~~~~~~ |
| 314 | .. argparse:: |
| 315 | :module: pySim-shell |
| 316 | :func: PysimApp.bulk_script_parser |
| 317 | |
Harald Welte | bd02f84 | 2021-10-21 14:40:39 +0200 | [diff] [blame] | 318 | |
| 319 | echo |
| 320 | ~~~~ |
| 321 | .. argparse:: |
| 322 | :module: pySim-shell |
| 323 | :func: PysimApp.echo_parser |
| 324 | |
| 325 | |
Harald Welte | 12af793 | 2022-02-15 16:39:08 +0100 | [diff] [blame] | 326 | apdu |
| 327 | ~~~~ |
| 328 | .. argparse:: |
| 329 | :module: pySim-shell |
| 330 | :func: PySimCommands.apdu_cmd_parser |
| 331 | |
| 332 | |
Harald Welte | daf2b39 | 2021-05-03 23:17:29 +0200 | [diff] [blame] | 333 | |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 334 | Linear Fixed EF commands |
| 335 | ------------------------ |
| 336 | |
| 337 | These commands become enabled only when your currently selected file is of *Linear Fixed EF* type. |
| 338 | |
| 339 | read_record |
| 340 | ~~~~~~~~~~~ |
Harald Welte | d36f694 | 2021-04-04 14:37:55 +0200 | [diff] [blame] | 341 | .. argparse:: |
| 342 | :module: pySim.filesystem |
| 343 | :func: LinFixedEF.ShellCommands.read_rec_parser |
| 344 | |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 345 | |
| 346 | read_record_decoded |
| 347 | ~~~~~~~~~~~~~~~~~~~ |
Harald Welte | d36f694 | 2021-04-04 14:37:55 +0200 | [diff] [blame] | 348 | .. argparse:: |
| 349 | :module: pySim.filesystem |
| 350 | :func: LinFixedEF.ShellCommands.read_rec_dec_parser |
| 351 | |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 352 | |
Harald Welte | 850b72a | 2021-04-07 09:33:03 +0200 | [diff] [blame] | 353 | read_records |
| 354 | ~~~~~~~~~~~~ |
| 355 | .. argparse:: |
| 356 | :module: pySim.filesystem |
| 357 | :func: LinFixedEF.ShellCommands.read_recs_parser |
| 358 | |
| 359 | |
| 360 | read_records_decoded |
| 361 | ~~~~~~~~~~~~~~~~~~~~ |
| 362 | .. argparse:: |
| 363 | :module: pySim.filesystem |
| 364 | :func: LinFixedEF.ShellCommands.read_recs_dec_parser |
| 365 | |
| 366 | |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 367 | update_record |
| 368 | ~~~~~~~~~~~~~ |
Harald Welte | d36f694 | 2021-04-04 14:37:55 +0200 | [diff] [blame] | 369 | .. argparse:: |
| 370 | :module: pySim.filesystem |
| 371 | :func: LinFixedEF.ShellCommands.upd_rec_parser |
| 372 | |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 373 | |
| 374 | update_record_decoded |
| 375 | ~~~~~~~~~~~~~~~~~~~~~ |
Harald Welte | d36f694 | 2021-04-04 14:37:55 +0200 | [diff] [blame] | 376 | .. argparse:: |
| 377 | :module: pySim.filesystem |
| 378 | :func: LinFixedEF.ShellCommands.upd_rec_dec_parser |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 379 | |
| 380 | |
Harald Welte | 4145d3c | 2021-04-08 20:34:13 +0200 | [diff] [blame] | 381 | edit_record_decoded |
| 382 | ~~~~~~~~~~~~~~~~~~~ |
| 383 | .. argparse:: |
| 384 | :module: pySim.filesystem |
| 385 | :func: LinFixedEF.ShellCommands.edit_rec_dec_parser |
| 386 | |
| 387 | This command will read the selected record, decode it to its JSON representation, save |
| 388 | that JSON to a temporary file on your computer, and launch your configured text editor. |
| 389 | |
| 390 | You may then perform whatever modifications to the JSON representation, save + leave your |
| 391 | text editor. |
| 392 | |
| 393 | Afterwards, the modified JSON will be re-encoded to the binary format, and the result written |
| 394 | back to the record on the SIM card. |
| 395 | |
| 396 | This allows for easy interactive modification of records. |
| 397 | |
| 398 | |
Harald Welte | aefd064 | 2022-02-25 15:26:37 +0100 | [diff] [blame] | 399 | decode_hex |
| 400 | ~~~~~~~~~~ |
| 401 | .. argparse:: |
| 402 | :module: pySim.filesystem |
| 403 | :func: LinFixedEF.ShellCommands.dec_hex_parser |
| 404 | |
| 405 | |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 406 | |
| 407 | Transparent EF commands |
| 408 | ----------------------- |
| 409 | |
| 410 | These commands become enabled only when your currently selected file is of *Transparent EF* type. |
| 411 | |
| 412 | |
| 413 | read_binary |
| 414 | ~~~~~~~~~~~ |
Harald Welte | d36f694 | 2021-04-04 14:37:55 +0200 | [diff] [blame] | 415 | .. argparse:: |
| 416 | :module: pySim.filesystem |
| 417 | :func: TransparentEF.ShellCommands.read_bin_parser |
| 418 | |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 419 | |
| 420 | read_binary_decoded |
| 421 | ~~~~~~~~~~~~~~~~~~~ |
Harald Welte | d36f694 | 2021-04-04 14:37:55 +0200 | [diff] [blame] | 422 | .. argparse:: |
| 423 | :module: pySim.filesystem |
| 424 | :func: TransparentEF.ShellCommands.read_bin_dec_parser |
| 425 | |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 426 | |
| 427 | update_binary |
| 428 | ~~~~~~~~~~~~~ |
Harald Welte | d36f694 | 2021-04-04 14:37:55 +0200 | [diff] [blame] | 429 | .. argparse:: |
| 430 | :module: pySim.filesystem |
| 431 | :func: TransparentEF.ShellCommands.upd_bin_parser |
| 432 | |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 433 | |
| 434 | update_binary_decoded |
| 435 | ~~~~~~~~~~~~~~~~~~~~~ |
Harald Welte | d36f694 | 2021-04-04 14:37:55 +0200 | [diff] [blame] | 436 | .. argparse:: |
| 437 | :module: pySim.filesystem |
| 438 | :func: TransparentEF.ShellCommands.upd_bin_dec_parser |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 439 | |
Harald Welte | 0d4e98a | 2021-04-07 00:14:40 +0200 | [diff] [blame] | 440 | In normal operation, update_binary_decoded needs a JSON document representing the entire file contents as |
| 441 | input. This can be inconvenient if you want to keep 99% of the content but just toggle one specific |
| 442 | parameter. That's where the JSONpath support comes in handy: You can specify a JSONpath to an element |
| 443 | inside the document as well as a new value for tat field: |
| 444 | |
| 445 | Th 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 Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 467 | |
Harald Welte | 4145d3c | 2021-04-08 20:34:13 +0200 | [diff] [blame] | 468 | edit_binary_decoded |
| 469 | ~~~~~~~~~~~~~~~~~~~ |
| 470 | This command will read the selected binary EF, decode it to its JSON representation, save |
| 471 | that JSON to a temporary file on your computer, and launch your configured text editor. |
| 472 | |
| 473 | You may then perform whatever modifications to the JSON representation, save + leave your |
| 474 | text editor. |
| 475 | |
| 476 | Afterwards, the modified JSON will be re-encoded to the binary format, and the result written |
| 477 | to the SIM card. |
| 478 | |
| 479 | This allows for easy interactive modification of file contents. |
| 480 | |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 481 | |
Harald Welte | aefd064 | 2022-02-25 15:26:37 +0100 | [diff] [blame] | 482 | decode_hex |
| 483 | ~~~~~~~~~~ |
| 484 | .. argparse:: |
| 485 | :module: pySim.filesystem |
| 486 | :func: TransparentEF.ShellCommands.dec_hex_parser |
| 487 | |
| 488 | |
Harald Welte | 917d98c | 2021-04-21 11:51:25 +0200 | [diff] [blame] | 489 | |
| 490 | BER-TLV EF commands |
| 491 | ------------------- |
| 492 | |
| 493 | BER-TLV EFs are files that contain BER-TLV structured data. Every file can contain any number |
| 494 | of variable-length IEs (DOs). The tag within a BER-TLV EF must be unique within the file. |
| 495 | |
| 496 | The commands below become enabled only when your currently selected file is of *BER-TLV EF* type. |
| 497 | |
| 498 | retrieve_tags |
| 499 | ~~~~~~~~~~~~~ |
| 500 | |
| 501 | Retrieve a list of all tags present in the currently selected file. |
| 502 | |
| 503 | |
| 504 | retrieve_data |
| 505 | ~~~~~~~~~~~~~ |
| 506 | .. argparse:: |
| 507 | :module: pySim.filesystem |
| 508 | :func: BerTlvEF.ShellCommands.retrieve_data_parser |
| 509 | |
| 510 | |
| 511 | set_data |
| 512 | ~~~~~~~~ |
| 513 | .. argparse:: |
| 514 | :module: pySim.filesystem |
| 515 | :func: BerTlvEF.ShellCommands.set_data_parser |
| 516 | |
| 517 | |
| 518 | del_data |
| 519 | ~~~~~~~~ |
| 520 | .. argparse:: |
| 521 | :module: pySim.filesystem |
| 522 | :func: BerTlvEF.ShellCommands.del_data_parser |
| 523 | |
| 524 | |
| 525 | |
Harald Welte | 15fae98 | 2021-04-10 10:22:27 +0200 | [diff] [blame] | 526 | USIM commands |
| 527 | ------------- |
| 528 | |
Harald Welte | 577312a | 2023-02-23 09:51:30 +0100 | [diff] [blame] | 529 | These commands are available only while ADF.USIM (or ADF.ISIM, respectively) is selected. |
| 530 | |
Harald Welte | 15fae98 | 2021-04-10 10:22:27 +0200 | [diff] [blame] | 531 | authenticate |
| 532 | ~~~~~~~~~~~~ |
| 533 | .. argparse:: |
| 534 | :module: pySim.ts_31_102 |
| 535 | :func: ADF_USIM.AddlShellCommands.authenticate_parser |
| 536 | |
Harald Welte | 12af793 | 2022-02-15 16:39:08 +0100 | [diff] [blame] | 537 | terminal_profile |
| 538 | ~~~~~~~~~~~~~~~~ |
| 539 | .. argparse:: |
| 540 | :module: pySim.ts_31_102 |
| 541 | :func: ADF_USIM.AddlShellCommands.term_prof_parser |
| 542 | |
| 543 | envelope |
| 544 | ~~~~~~~~ |
| 545 | .. argparse:: |
| 546 | :module: pySim.ts_31_102 |
| 547 | :func: ADF_USIM.AddlShellCommands.envelope_parser |
| 548 | |
| 549 | envelope_sms |
| 550 | ~~~~~~~~~~~~ |
| 551 | .. argparse:: |
| 552 | :module: pySim.ts_31_102 |
| 553 | :func: ADF_USIM.AddlShellCommands.envelope_sms_parser |
| 554 | |
| 555 | |
Harald Welte | 577312a | 2023-02-23 09:51:30 +0100 | [diff] [blame] | 556 | File-specific commands |
| 557 | ---------------------- |
| 558 | |
| 559 | These commands are valid only if the respective file is currently selected. They perform some |
| 560 | operation that's specific to this file only. |
| 561 | |
| 562 | EF.ARR: read_arr_record |
| 563 | ~~~~~~~~~~~~~~~~~~~~~~~ |
| 564 | Read one EF.ARR record in flattened, human-friendly form. |
| 565 | |
| 566 | EF.ARR: read_arr_records |
| 567 | ~~~~~~~~~~~~~~~~~~~~~~~~ |
| 568 | Read + decode all EF.ARR records in flattened, human-friendly form. |
| 569 | |
Harald Welte | c224b3b | 2023-05-23 18:44:44 +0200 | [diff] [blame] | 570 | DF.GSM/EF.SST: sst_service_allocate |
| 571 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 572 | Mark a given single service as allocated in EF.SST. Requires service number as argument. |
| 573 | |
| 574 | DF.GSM/EF.SST: sst_service_activate |
| 575 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 576 | Mark a given single service as activated in EF.SST. Requires service number as argument. |
| 577 | |
| 578 | DF.GSM/EF.SST: sst_service_deallocate |
| 579 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 580 | Mark a given single service as deallocated in EF.SST. Requires service number as argument. |
| 581 | |
| 582 | DF.GSM/EF.SST: sst_service_deactivate |
| 583 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 584 | Mark a given single service as deactivated in EF.SST. Requires service number as argument. |
| 585 | |
Harald Welte | a07d509 | 2023-02-23 10:02:49 +0100 | [diff] [blame] | 586 | ADF.USIM/EF.EST: est_service_enable |
| 587 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 588 | Enables a single service in EF.EST. Requires service number as argument. |
| 589 | |
| 590 | ADF.USIM/EF.EST: est_service_disable |
| 591 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 592 | Disables a single service in EF.EST. Requires service number as argument. |
| 593 | |
Harald Welte | 577312a | 2023-02-23 09:51:30 +0100 | [diff] [blame] | 594 | EF.IMSI: update_imsi_plmn |
| 595 | ~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 596 | Change the PLMN part (MCC+MNC) of the IMSI. Requires a single argument consisting of 5/6 digits of |
| 597 | concatenated MCC+MNC. |
| 598 | |
| 599 | ADF.USIM/EF.UST: ust_service_activate |
| 600 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 601 | Activates a single service in EF.UST. Requires service number as argument. |
| 602 | |
| 603 | ADF.USIM/EF.UST: ust_service_deactivate |
| 604 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 605 | Deactivates a single service in EF.UST. Requires service number as argument. |
| 606 | |
| 607 | ADF.USIM/EF.UST: ust_service_check |
| 608 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 609 | Check consistency between services of this file and files present/activated. |
| 610 | Many services determine if one or multiple files shall be present/activated or if they shall be |
| 611 | absent/deactivated. This performs a consistency check to ensure that no services are activated |
| 612 | for files that are not - and vice-versa, no files are activated for services that are not. Error |
| 613 | messages are printed for every inconsistency found. |
| 614 | |
| 615 | ADF.ISIM/EF.IST: ist_service_activate |
| 616 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 617 | Activates a single service in EF.IST. Requires service number as argument. |
| 618 | |
| 619 | ADF.ISIM/EF.IST: ist_service_deactivate |
| 620 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 621 | Deactivates a single service in EF.UST. Requires service number as argument. |
| 622 | |
| 623 | ADF.ISIM/EF.IST: ist_service_check |
| 624 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 625 | Check consistency between services of this file and files present/activated. |
| 626 | Many services determine if one or multiple files shall be present/activated or if they shall be |
| 627 | absent/deactivated. This performs a consistency check to ensure that no services are activated |
| 628 | for files that are not - and vice-versa, no files are activated for services that are not. Error |
| 629 | messages are printed for every inconsistency found. |
| 630 | |
| 631 | |
| 632 | UICC Administrative commands |
| 633 | ---------------------------- |
| 634 | |
| 635 | ETSI TS 102 222 specifies a set of *Administrative Commands*, which can |
| 636 | be 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 |
| 638 | entire card. |
| 639 | |
| 640 | pySim-shell supports those commands, but **use extreme caution**. |
| 641 | Unless you know exactly what you're doing, it's very easy to render your |
| 642 | card unusable. You've been warned! |
| 643 | |
| 644 | delete_file |
| 645 | ~~~~~~~~~~~ |
| 646 | .. argparse:: |
| 647 | :module: pySim.ts_102_222 |
| 648 | :func: Ts102222Commands.delfile_parser |
| 649 | |
| 650 | |
| 651 | terminate_df |
| 652 | ~~~~~~~~~~~~ |
| 653 | .. argparse:: |
| 654 | :module: pySim.ts_102_222 |
| 655 | :func: Ts102222Commands.termdf_parser |
| 656 | |
| 657 | terminate_ef |
| 658 | ~~~~~~~~~~~~ |
| 659 | .. argparse:: |
| 660 | :module: pySim.ts_102_222 |
| 661 | :func: Ts102222Commands.termdf_parser |
| 662 | |
| 663 | terminate_card |
| 664 | ~~~~~~~~~~~~~~ |
| 665 | .. argparse:: |
| 666 | :module: pySim.ts_102_222 |
| 667 | :func: Ts102222Commands.tcard_parser |
| 668 | |
| 669 | create_ef |
| 670 | ~~~~~~~~~ |
| 671 | .. argparse:: |
| 672 | :module: pySim.ts_102_222 |
| 673 | :func: Ts102222Commands.create_parser |
| 674 | |
| 675 | create_df |
| 676 | ~~~~~~~~~ |
| 677 | .. argparse:: |
| 678 | :module: pySim.ts_102_222 |
| 679 | :func: Ts102222Commands.createdf_parser |
Harald Welte | 12af793 | 2022-02-15 16:39:08 +0100 | [diff] [blame] | 680 | |
Harald Welte | 0707b80 | 2023-03-07 11:43:37 +0100 | [diff] [blame] | 681 | resize_ef |
| 682 | ~~~~~~~~~ |
| 683 | .. argparse:: |
| 684 | :module: pySim.ts_102_222 |
| 685 | :func: Ts102222Commands.resize_ef_parser |
| 686 | |
Harald Welte | 15fae98 | 2021-04-10 10:22:27 +0200 | [diff] [blame] | 687 | |
Harald Welte | 95ce6b1 | 2021-10-20 18:40:54 +0200 | [diff] [blame] | 688 | ARA-M commands |
| 689 | -------------- |
| 690 | |
| 691 | The ARA-M commands exist to manage the access rules stored in an ARA-M applet on the card. |
| 692 | |
| 693 | ARA-M in the context of SIM cards is primarily used to enable Android UICC Carrier Privileges, |
| 694 | please see https://source.android.com/devices/tech/config/uicc for more details on the background. |
| 695 | |
| 696 | |
| 697 | aram_get_all |
| 698 | ~~~~~~~~~~~~ |
| 699 | |
| 700 | Obtain and decode all access rules from the ARA-M applet on the card. |
| 701 | |
| 702 | NOTE: if the total size of the access rules exceeds 255 bytes, this command will fail, as |
| 703 | it 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 | |
| 743 | aram_get_config |
| 744 | ~~~~~~~~~~~~~~~ |
| 745 | Perform Config handshake with ARA-M applet: Tell it our version and retrieve its version. |
| 746 | |
| 747 | NOTE: Not supported in all ARA-M implementations. |
| 748 | |
Harald Welte | 95ce6b1 | 2021-10-20 18:40:54 +0200 | [diff] [blame] | 749 | |
| 750 | aram_store_ref_ar_do |
| 751 | ~~~~~~~~~~~~~~~~~~~~ |
Harald Welte | 95ce6b1 | 2021-10-20 18:40:54 +0200 | [diff] [blame] | 752 | .. argparse:: |
| 753 | :module: pySim.ara_m |
| 754 | :func: ADF_ARAM.AddlShellCommands.store_ref_ar_do_parse |
| 755 | |
| 756 | For 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 Welte | 95ce6b1 | 2021-10-20 18:40:54 +0200 | [diff] [blame] | 757 | :: |
| 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 | |
| 762 | aram_delete_all |
| 763 | ~~~~~~~~~~~~~~~ |
| 764 | This command will request deletion of all access rules stored within the |
| 765 | ARA-M applet. Use it with caution, there is no undo. Any rules later |
| 766 | intended must be manually inserted again using `aram_store_ref_ar_do` |
| 767 | |
| 768 | |
Harald Welte | 577312a | 2023-02-23 09:51:30 +0100 | [diff] [blame] | 769 | GlobalPlatform commands |
| 770 | ----------------------- |
| 771 | |
| 772 | pySim-shell has only the mots rudimentary support for GlobalPlatform at this point. Please use dedicated |
| 773 | projects like GlobalPlatformPro meanwhile. |
| 774 | |
| 775 | get_data |
| 776 | ~~~~~~~~ |
| 777 | Performs the GET DATA command as specified by GlobalPlatform. |
| 778 | |
Harald Welte | 15fae98 | 2021-04-10 10:22:27 +0200 | [diff] [blame] | 779 | |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 780 | cmd2 settable parameters |
| 781 | ------------------------ |
| 782 | |
| 783 | ``cmd2`` has the concept of *settable parameters* which act a bit like environment variables in an OS-level |
| 784 | shell: They can be read and set, and they will influence the behavior somehow. |
| 785 | |
| 786 | conserve_write |
| 787 | ~~~~~~~~~~~~~~ |
| 788 | |
| 789 | If enabled, pySim will (when asked to write to a card) always first read the respective file/record and |
| 790 | verify if the to-be-written value differs from the current on-card value. If not, the write will be skipped. |
| 791 | Writes will only be performed if the new value is different from the current on-card value. |
| 792 | |
| 793 | If disabled, pySim will always write irrespective of the current/new value. |
| 794 | |
Harald Welte | 1748b93 | 2021-04-06 21:12:25 +0200 | [diff] [blame] | 795 | json_pretty_print |
| 796 | ~~~~~~~~~~~~~~~~~ |
| 797 | |
| 798 | This parameter determines if generated JSON output should (by default) be pretty-printed (multi-line |
| 799 | output with indent level of 4 spaces) or not. |
| 800 | |
| 801 | The default value of this parameter is 'true'. |
| 802 | |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 803 | debug |
| 804 | ~~~~~ |
| 805 | |
| 806 | If enabled, full python back-traces will be displayed in case of exceptions |
| 807 | |
Harald Welte | 7829d8a | 2021-04-10 11:28:53 +0200 | [diff] [blame] | 808 | apdu_trace |
| 809 | ~~~~~~~~~~ |
| 810 | |
| 811 | Boolean variable that determines if a hex-dump of the command + response APDU shall be printed. |
| 812 | |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 813 | numeric_path |
| 814 | ~~~~~~~~~~~~ |
| 815 | |
| 816 | Boolean 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 |