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 | ec95053 | 2021-10-20 13:09:00 +0200 | [diff] [blame] | 202 | suspend_uicc |
| 203 | ~~~~~~~~~~~~ |
| 204 | This command allows you to perform the SUSPEND UICC command on the card. This is a relatively |
| 205 | recent power-saving addition to the UICC specifications, allowing for suspend/resume while maintaining |
| 206 | state, as opposed to a full power-off (deactivate) and power-on (activate) of the card. |
| 207 | |
| 208 | The pySim command just sends that SUSPEND UICC command and doesn't perform the full related sequence |
| 209 | including the electrical power down. |
| 210 | |
| 211 | .. argparse:: |
| 212 | :module: pySim-shell |
| 213 | :func: Iso7816Commands.suspend_uicc_parser |
| 214 | |
| 215 | |
Harald Welte | 12af793 | 2022-02-15 16:39:08 +0100 | [diff] [blame] | 216 | |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 217 | pySim commands |
| 218 | -------------- |
| 219 | |
| 220 | Commands in this category are pySim specific; they do not have a 1:1 correspondence to ISO 7816 |
| 221 | or 3GPP commands. Mostly they will operate either only on local (in-memory) state, or execute |
| 222 | a complex sequence of card-commands. |
| 223 | |
| 224 | desc |
| 225 | ~~~~ |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 226 | Display human readable file description for the currently selected file. |
| 227 | |
| 228 | |
| 229 | dir |
| 230 | ~~~ |
Harald Welte | d36f694 | 2021-04-04 14:37:55 +0200 | [diff] [blame] | 231 | .. argparse:: |
| 232 | :module: pySim-shell |
| 233 | :func: PySimCommands.dir_parser |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 234 | |
Harald Welte | 12af793 | 2022-02-15 16:39:08 +0100 | [diff] [blame] | 235 | Example: |
| 236 | :: |
| 237 | |
| 238 | pySIM-shell (MF)> dir |
| 239 | MF |
| 240 | 3f00 |
| 241 | .. ADF.USIM DF.SYSTEM EF.DIR EF.UMPC |
| 242 | ADF.ARA-M DF.EIRENE DF.TELECOM EF.ICCID MF |
| 243 | ADF.ISIM DF.GSM EF.ARR EF.PL |
| 244 | 14 files |
| 245 | |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 246 | |
| 247 | export |
| 248 | ~~~~~~ |
Harald Welte | d36f694 | 2021-04-04 14:37:55 +0200 | [diff] [blame] | 249 | .. argparse:: |
| 250 | :module: pySim-shell |
| 251 | :func: PySimCommands.export_parser |
| 252 | |
Harald Welte | bd02f84 | 2021-10-21 14:40:39 +0200 | [diff] [blame] | 253 | Please note that `export` works relative to the current working |
| 254 | directory, so if you are in `MF`, then the export will contain all known |
| 255 | files on the card. However, if you are in `ADF.ISIM`, only files below |
| 256 | that ADF will be part of the export. |
| 257 | |
| 258 | Furthermore, it is strongly advised to first enter the ADM1 pin |
| 259 | (`verify_adm`) to maximize the chance of having permission to read |
| 260 | all/most files. |
| 261 | |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 262 | |
| 263 | tree |
| 264 | ~~~~ |
Harald Welte | 7743c20 | 2021-05-03 23:30:11 +0200 | [diff] [blame] | 265 | Display a tree of the card filesystem. It is important to note that this displays a tree |
| 266 | of files that might potentially exist (based on the card profile). In order to determine if |
| 267 | 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] | 268 | |
Harald Welte | 12af793 | 2022-02-15 16:39:08 +0100 | [diff] [blame] | 269 | Example: |
| 270 | :: |
| 271 | |
| 272 | pySIM-shell (MF)> tree --help |
| 273 | EF.DIR 2f00 Application Directory |
| 274 | EF.ICCID 2fe2 ICC Identification |
| 275 | EF.PL 2f05 Preferred Languages |
| 276 | EF.ARR 2f06 Access Rule Reference |
| 277 | EF.UMPC 2f08 UICC Maximum Power Consumption |
| 278 | DF.TELECOM 7f10 None |
| 279 | EF.ADN 6f3a Abbreviated Dialing Numbers |
| 280 | ... |
| 281 | |
| 282 | |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 283 | |
| 284 | verify_adm |
| 285 | ~~~~~~~~~~ |
Harald Welte | 7743c20 | 2021-05-03 23:30:11 +0200 | [diff] [blame] | 286 | Verify the ADM (Administrator) PIN specified as argument. This is typically needed in order |
| 287 | to get write/update permissions to most of the files on SIM cards. |
| 288 | |
| 289 | Currently only ADM1 is supported. |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 290 | |
| 291 | |
Harald Welte | daf2b39 | 2021-05-03 23:17:29 +0200 | [diff] [blame] | 292 | reset |
| 293 | ~~~~~ |
Harald Welte | daf2b39 | 2021-05-03 23:17:29 +0200 | [diff] [blame] | 294 | Perform card reset and display the card ATR. |
| 295 | |
Harald Welte | bd02f84 | 2021-10-21 14:40:39 +0200 | [diff] [blame] | 296 | intro |
| 297 | ~~~~~ |
| 298 | [Re-]Display the introductory banner |
| 299 | |
| 300 | |
| 301 | equip |
| 302 | ~~~~~ |
| 303 | Equip pySim-shell with a card; particularly useful if the program was |
| 304 | started before a card was present, or after a card has been replaced by |
| 305 | the user while pySim-shell was kept running. |
| 306 | |
| 307 | bulk_script |
| 308 | ~~~~~~~~~~~ |
| 309 | .. argparse:: |
| 310 | :module: pySim-shell |
| 311 | :func: PysimApp.bulk_script_parser |
| 312 | |
Harald Welte | bd02f84 | 2021-10-21 14:40:39 +0200 | [diff] [blame] | 313 | |
| 314 | echo |
| 315 | ~~~~ |
| 316 | .. argparse:: |
| 317 | :module: pySim-shell |
| 318 | :func: PysimApp.echo_parser |
| 319 | |
| 320 | |
Harald Welte | 12af793 | 2022-02-15 16:39:08 +0100 | [diff] [blame] | 321 | apdu |
| 322 | ~~~~ |
| 323 | .. argparse:: |
| 324 | :module: pySim-shell |
| 325 | :func: PySimCommands.apdu_cmd_parser |
| 326 | |
| 327 | |
Harald Welte | daf2b39 | 2021-05-03 23:17:29 +0200 | [diff] [blame] | 328 | |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 329 | Linear Fixed EF commands |
| 330 | ------------------------ |
| 331 | |
| 332 | These commands become enabled only when your currently selected file is of *Linear Fixed EF* type. |
| 333 | |
| 334 | read_record |
| 335 | ~~~~~~~~~~~ |
Harald Welte | d36f694 | 2021-04-04 14:37:55 +0200 | [diff] [blame] | 336 | .. argparse:: |
| 337 | :module: pySim.filesystem |
| 338 | :func: LinFixedEF.ShellCommands.read_rec_parser |
| 339 | |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 340 | |
| 341 | read_record_decoded |
| 342 | ~~~~~~~~~~~~~~~~~~~ |
Harald Welte | d36f694 | 2021-04-04 14:37:55 +0200 | [diff] [blame] | 343 | .. argparse:: |
| 344 | :module: pySim.filesystem |
| 345 | :func: LinFixedEF.ShellCommands.read_rec_dec_parser |
| 346 | |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 347 | |
Harald Welte | 850b72a | 2021-04-07 09:33:03 +0200 | [diff] [blame] | 348 | read_records |
| 349 | ~~~~~~~~~~~~ |
| 350 | .. argparse:: |
| 351 | :module: pySim.filesystem |
| 352 | :func: LinFixedEF.ShellCommands.read_recs_parser |
| 353 | |
| 354 | |
| 355 | read_records_decoded |
| 356 | ~~~~~~~~~~~~~~~~~~~~ |
| 357 | .. argparse:: |
| 358 | :module: pySim.filesystem |
| 359 | :func: LinFixedEF.ShellCommands.read_recs_dec_parser |
| 360 | |
| 361 | |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 362 | update_record |
| 363 | ~~~~~~~~~~~~~ |
Harald Welte | d36f694 | 2021-04-04 14:37:55 +0200 | [diff] [blame] | 364 | .. argparse:: |
| 365 | :module: pySim.filesystem |
| 366 | :func: LinFixedEF.ShellCommands.upd_rec_parser |
| 367 | |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 368 | |
| 369 | update_record_decoded |
| 370 | ~~~~~~~~~~~~~~~~~~~~~ |
Harald Welte | d36f694 | 2021-04-04 14:37:55 +0200 | [diff] [blame] | 371 | .. argparse:: |
| 372 | :module: pySim.filesystem |
| 373 | :func: LinFixedEF.ShellCommands.upd_rec_dec_parser |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 374 | |
| 375 | |
Harald Welte | 4145d3c | 2021-04-08 20:34:13 +0200 | [diff] [blame] | 376 | edit_record_decoded |
| 377 | ~~~~~~~~~~~~~~~~~~~ |
| 378 | .. argparse:: |
| 379 | :module: pySim.filesystem |
| 380 | :func: LinFixedEF.ShellCommands.edit_rec_dec_parser |
| 381 | |
| 382 | This command will read the selected record, decode it to its JSON representation, save |
| 383 | that JSON to a temporary file on your computer, and launch your configured text editor. |
| 384 | |
| 385 | You may then perform whatever modifications to the JSON representation, save + leave your |
| 386 | text editor. |
| 387 | |
| 388 | Afterwards, the modified JSON will be re-encoded to the binary format, and the result written |
| 389 | back to the record on the SIM card. |
| 390 | |
| 391 | This allows for easy interactive modification of records. |
| 392 | |
| 393 | |
Harald Welte | aefd064 | 2022-02-25 15:26:37 +0100 | [diff] [blame] | 394 | decode_hex |
| 395 | ~~~~~~~~~~ |
| 396 | .. argparse:: |
| 397 | :module: pySim.filesystem |
| 398 | :func: LinFixedEF.ShellCommands.dec_hex_parser |
| 399 | |
| 400 | |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 401 | |
| 402 | Transparent EF commands |
| 403 | ----------------------- |
| 404 | |
| 405 | These commands become enabled only when your currently selected file is of *Transparent EF* type. |
| 406 | |
| 407 | |
| 408 | read_binary |
| 409 | ~~~~~~~~~~~ |
Harald Welte | d36f694 | 2021-04-04 14:37:55 +0200 | [diff] [blame] | 410 | .. argparse:: |
| 411 | :module: pySim.filesystem |
| 412 | :func: TransparentEF.ShellCommands.read_bin_parser |
| 413 | |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 414 | |
| 415 | read_binary_decoded |
| 416 | ~~~~~~~~~~~~~~~~~~~ |
Harald Welte | d36f694 | 2021-04-04 14:37:55 +0200 | [diff] [blame] | 417 | .. argparse:: |
| 418 | :module: pySim.filesystem |
| 419 | :func: TransparentEF.ShellCommands.read_bin_dec_parser |
| 420 | |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 421 | |
| 422 | update_binary |
| 423 | ~~~~~~~~~~~~~ |
Harald Welte | d36f694 | 2021-04-04 14:37:55 +0200 | [diff] [blame] | 424 | .. argparse:: |
| 425 | :module: pySim.filesystem |
| 426 | :func: TransparentEF.ShellCommands.upd_bin_parser |
| 427 | |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 428 | |
| 429 | update_binary_decoded |
| 430 | ~~~~~~~~~~~~~~~~~~~~~ |
Harald Welte | d36f694 | 2021-04-04 14:37:55 +0200 | [diff] [blame] | 431 | .. argparse:: |
| 432 | :module: pySim.filesystem |
| 433 | :func: TransparentEF.ShellCommands.upd_bin_dec_parser |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 434 | |
Harald Welte | 0d4e98a | 2021-04-07 00:14:40 +0200 | [diff] [blame] | 435 | In normal operation, update_binary_decoded needs a JSON document representing the entire file contents as |
| 436 | input. This can be inconvenient if you want to keep 99% of the content but just toggle one specific |
| 437 | parameter. That's where the JSONpath support comes in handy: You can specify a JSONpath to an element |
| 438 | inside the document as well as a new value for tat field: |
| 439 | |
| 440 | Th below example demonstrates this by modifying the ofm field within EF.AD: |
| 441 | |
| 442 | :: |
| 443 | |
| 444 | pySIM-shell (MF/ADF.USIM/EF.AD)> read_binary_decoded |
| 445 | { |
| 446 | "ms_operation_mode": "normal", |
| 447 | "specific_facilities": { |
| 448 | "ofm": true |
| 449 | }, |
| 450 | "len_of_mnc_in_imsi": 2 |
| 451 | } |
| 452 | pySIM-shell (MF/ADF.USIM/EF.AD)> update_binary_decoded --json-path specific_facilities.ofm false |
| 453 | pySIM-shell (MF/ADF.USIM/EF.AD)> read_binary_decoded |
| 454 | { |
| 455 | "ms_operation_mode": "normal", |
| 456 | "specific_facilities": { |
| 457 | "ofm": false |
| 458 | }, |
| 459 | "len_of_mnc_in_imsi": 2 |
| 460 | } |
| 461 | |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 462 | |
Harald Welte | 4145d3c | 2021-04-08 20:34:13 +0200 | [diff] [blame] | 463 | edit_binary_decoded |
| 464 | ~~~~~~~~~~~~~~~~~~~ |
| 465 | This command will read the selected binary EF, decode it to its JSON representation, save |
| 466 | that JSON to a temporary file on your computer, and launch your configured text editor. |
| 467 | |
| 468 | You may then perform whatever modifications to the JSON representation, save + leave your |
| 469 | text editor. |
| 470 | |
| 471 | Afterwards, the modified JSON will be re-encoded to the binary format, and the result written |
| 472 | to the SIM card. |
| 473 | |
| 474 | This allows for easy interactive modification of file contents. |
| 475 | |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 476 | |
Harald Welte | aefd064 | 2022-02-25 15:26:37 +0100 | [diff] [blame] | 477 | decode_hex |
| 478 | ~~~~~~~~~~ |
| 479 | .. argparse:: |
| 480 | :module: pySim.filesystem |
| 481 | :func: TransparentEF.ShellCommands.dec_hex_parser |
| 482 | |
| 483 | |
Harald Welte | 917d98c | 2021-04-21 11:51:25 +0200 | [diff] [blame] | 484 | |
| 485 | BER-TLV EF commands |
| 486 | ------------------- |
| 487 | |
| 488 | BER-TLV EFs are files that contain BER-TLV structured data. Every file can contain any number |
| 489 | of variable-length IEs (DOs). The tag within a BER-TLV EF must be unique within the file. |
| 490 | |
| 491 | The commands below become enabled only when your currently selected file is of *BER-TLV EF* type. |
| 492 | |
| 493 | retrieve_tags |
| 494 | ~~~~~~~~~~~~~ |
| 495 | |
| 496 | Retrieve a list of all tags present in the currently selected file. |
| 497 | |
| 498 | |
| 499 | retrieve_data |
| 500 | ~~~~~~~~~~~~~ |
| 501 | .. argparse:: |
| 502 | :module: pySim.filesystem |
| 503 | :func: BerTlvEF.ShellCommands.retrieve_data_parser |
| 504 | |
| 505 | |
| 506 | set_data |
| 507 | ~~~~~~~~ |
| 508 | .. argparse:: |
| 509 | :module: pySim.filesystem |
| 510 | :func: BerTlvEF.ShellCommands.set_data_parser |
| 511 | |
| 512 | |
| 513 | del_data |
| 514 | ~~~~~~~~ |
| 515 | .. argparse:: |
| 516 | :module: pySim.filesystem |
| 517 | :func: BerTlvEF.ShellCommands.del_data_parser |
| 518 | |
| 519 | |
| 520 | |
Harald Welte | 15fae98 | 2021-04-10 10:22:27 +0200 | [diff] [blame] | 521 | USIM commands |
| 522 | ------------- |
| 523 | |
Harald Welte | 577312a | 2023-02-23 09:51:30 +0100 | [diff] [blame] | 524 | These commands are available only while ADF.USIM (or ADF.ISIM, respectively) is selected. |
| 525 | |
Harald Welte | 15fae98 | 2021-04-10 10:22:27 +0200 | [diff] [blame] | 526 | authenticate |
| 527 | ~~~~~~~~~~~~ |
| 528 | .. argparse:: |
| 529 | :module: pySim.ts_31_102 |
| 530 | :func: ADF_USIM.AddlShellCommands.authenticate_parser |
| 531 | |
Harald Welte | 12af793 | 2022-02-15 16:39:08 +0100 | [diff] [blame] | 532 | terminal_profile |
| 533 | ~~~~~~~~~~~~~~~~ |
| 534 | .. argparse:: |
| 535 | :module: pySim.ts_31_102 |
| 536 | :func: ADF_USIM.AddlShellCommands.term_prof_parser |
| 537 | |
| 538 | envelope |
| 539 | ~~~~~~~~ |
| 540 | .. argparse:: |
| 541 | :module: pySim.ts_31_102 |
| 542 | :func: ADF_USIM.AddlShellCommands.envelope_parser |
| 543 | |
| 544 | envelope_sms |
| 545 | ~~~~~~~~~~~~ |
| 546 | .. argparse:: |
| 547 | :module: pySim.ts_31_102 |
| 548 | :func: ADF_USIM.AddlShellCommands.envelope_sms_parser |
| 549 | |
| 550 | |
Harald Welte | 577312a | 2023-02-23 09:51:30 +0100 | [diff] [blame] | 551 | File-specific commands |
| 552 | ---------------------- |
| 553 | |
| 554 | These commands are valid only if the respective file is currently selected. They perform some |
| 555 | operation that's specific to this file only. |
| 556 | |
| 557 | EF.ARR: read_arr_record |
| 558 | ~~~~~~~~~~~~~~~~~~~~~~~ |
| 559 | Read one EF.ARR record in flattened, human-friendly form. |
| 560 | |
| 561 | EF.ARR: read_arr_records |
| 562 | ~~~~~~~~~~~~~~~~~~~~~~~~ |
| 563 | Read + decode all EF.ARR records in flattened, human-friendly form. |
| 564 | |
Harald Welte | c224b3b | 2023-05-23 18:44:44 +0200 | [diff] [blame] | 565 | DF.GSM/EF.SST: sst_service_allocate |
| 566 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 567 | Mark a given single service as allocated in EF.SST. Requires service number as argument. |
| 568 | |
| 569 | DF.GSM/EF.SST: sst_service_activate |
| 570 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 571 | Mark a given single service as activated in EF.SST. Requires service number as argument. |
| 572 | |
| 573 | DF.GSM/EF.SST: sst_service_deallocate |
| 574 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 575 | Mark a given single service as deallocated in EF.SST. Requires service number as argument. |
| 576 | |
| 577 | DF.GSM/EF.SST: sst_service_deactivate |
| 578 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 579 | Mark a given single service as deactivated in EF.SST. Requires service number as argument. |
| 580 | |
Harald Welte | a07d509 | 2023-02-23 10:02:49 +0100 | [diff] [blame] | 581 | ADF.USIM/EF.EST: est_service_enable |
| 582 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 583 | Enables a single service in EF.EST. Requires service number as argument. |
| 584 | |
| 585 | ADF.USIM/EF.EST: est_service_disable |
| 586 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 587 | Disables a single service in EF.EST. Requires service number as argument. |
| 588 | |
Harald Welte | 577312a | 2023-02-23 09:51:30 +0100 | [diff] [blame] | 589 | EF.IMSI: update_imsi_plmn |
| 590 | ~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 591 | Change the PLMN part (MCC+MNC) of the IMSI. Requires a single argument consisting of 5/6 digits of |
| 592 | concatenated MCC+MNC. |
| 593 | |
| 594 | ADF.USIM/EF.UST: ust_service_activate |
| 595 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 596 | Activates a single service in EF.UST. Requires service number as argument. |
| 597 | |
| 598 | ADF.USIM/EF.UST: ust_service_deactivate |
| 599 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 600 | Deactivates a single service in EF.UST. Requires service number as argument. |
| 601 | |
| 602 | ADF.USIM/EF.UST: ust_service_check |
| 603 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 604 | Check consistency between services of this file and files present/activated. |
| 605 | Many services determine if one or multiple files shall be present/activated or if they shall be |
| 606 | absent/deactivated. This performs a consistency check to ensure that no services are activated |
| 607 | for files that are not - and vice-versa, no files are activated for services that are not. Error |
| 608 | messages are printed for every inconsistency found. |
| 609 | |
| 610 | ADF.ISIM/EF.IST: ist_service_activate |
| 611 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 612 | Activates a single service in EF.IST. Requires service number as argument. |
| 613 | |
| 614 | ADF.ISIM/EF.IST: ist_service_deactivate |
| 615 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 616 | Deactivates a single service in EF.UST. Requires service number as argument. |
| 617 | |
| 618 | ADF.ISIM/EF.IST: ist_service_check |
| 619 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 620 | Check consistency between services of this file and files present/activated. |
| 621 | Many services determine if one or multiple files shall be present/activated or if they shall be |
| 622 | absent/deactivated. This performs a consistency check to ensure that no services are activated |
| 623 | for files that are not - and vice-versa, no files are activated for services that are not. Error |
| 624 | messages are printed for every inconsistency found. |
| 625 | |
| 626 | |
| 627 | UICC Administrative commands |
| 628 | ---------------------------- |
| 629 | |
| 630 | ETSI TS 102 222 specifies a set of *Administrative Commands*, which can |
| 631 | be used by the card issuer / operator to modify the file system structure |
| 632 | (delete files, create files) or even to terminate individual files or the |
| 633 | entire card. |
| 634 | |
| 635 | pySim-shell supports those commands, but **use extreme caution**. |
| 636 | Unless you know exactly what you're doing, it's very easy to render your |
| 637 | card unusable. You've been warned! |
| 638 | |
| 639 | delete_file |
| 640 | ~~~~~~~~~~~ |
| 641 | .. argparse:: |
| 642 | :module: pySim.ts_102_222 |
| 643 | :func: Ts102222Commands.delfile_parser |
| 644 | |
| 645 | |
| 646 | terminate_df |
| 647 | ~~~~~~~~~~~~ |
| 648 | .. argparse:: |
| 649 | :module: pySim.ts_102_222 |
| 650 | :func: Ts102222Commands.termdf_parser |
| 651 | |
| 652 | terminate_ef |
| 653 | ~~~~~~~~~~~~ |
| 654 | .. argparse:: |
| 655 | :module: pySim.ts_102_222 |
| 656 | :func: Ts102222Commands.termdf_parser |
| 657 | |
| 658 | terminate_card |
| 659 | ~~~~~~~~~~~~~~ |
| 660 | .. argparse:: |
| 661 | :module: pySim.ts_102_222 |
| 662 | :func: Ts102222Commands.tcard_parser |
| 663 | |
| 664 | create_ef |
| 665 | ~~~~~~~~~ |
| 666 | .. argparse:: |
| 667 | :module: pySim.ts_102_222 |
| 668 | :func: Ts102222Commands.create_parser |
| 669 | |
| 670 | create_df |
| 671 | ~~~~~~~~~ |
| 672 | .. argparse:: |
| 673 | :module: pySim.ts_102_222 |
| 674 | :func: Ts102222Commands.createdf_parser |
Harald Welte | 12af793 | 2022-02-15 16:39:08 +0100 | [diff] [blame] | 675 | |
Harald Welte | 0707b80 | 2023-03-07 11:43:37 +0100 | [diff] [blame] | 676 | resize_ef |
| 677 | ~~~~~~~~~ |
| 678 | .. argparse:: |
| 679 | :module: pySim.ts_102_222 |
| 680 | :func: Ts102222Commands.resize_ef_parser |
| 681 | |
Harald Welte | 15fae98 | 2021-04-10 10:22:27 +0200 | [diff] [blame] | 682 | |
Harald Welte | 95ce6b1 | 2021-10-20 18:40:54 +0200 | [diff] [blame] | 683 | ARA-M commands |
| 684 | -------------- |
| 685 | |
| 686 | The ARA-M commands exist to manage the access rules stored in an ARA-M applet on the card. |
| 687 | |
| 688 | ARA-M in the context of SIM cards is primarily used to enable Android UICC Carrier Privileges, |
| 689 | please see https://source.android.com/devices/tech/config/uicc for more details on the background. |
| 690 | |
| 691 | |
| 692 | aram_get_all |
| 693 | ~~~~~~~~~~~~ |
| 694 | |
| 695 | Obtain and decode all access rules from the ARA-M applet on the card. |
| 696 | |
| 697 | NOTE: if the total size of the access rules exceeds 255 bytes, this command will fail, as |
| 698 | it doesn't yet implement fragmentation/reassembly on rule retrieval. YMMV |
| 699 | |
| 700 | :: |
| 701 | |
| 702 | pySIM-shell (MF/ADF.ARA-M)> aram_get_all |
| 703 | [ |
| 704 | { |
| 705 | "ResponseAllRefArDO": [ |
| 706 | { |
| 707 | "RefArDO": [ |
| 708 | { |
| 709 | "RefDO": [ |
| 710 | { |
| 711 | "AidRefDO": "ffffffffffff" |
| 712 | }, |
| 713 | { |
| 714 | "DevAppIdRefDO": "e46872f28b350b7e1f140de535c2a8d5804f0be3" |
| 715 | } |
| 716 | ] |
| 717 | }, |
| 718 | { |
| 719 | "ArDO": [ |
| 720 | { |
| 721 | "ApduArDO": { |
| 722 | "generic_access_rule": "always" |
| 723 | } |
| 724 | }, |
| 725 | { |
| 726 | "PermArDO": { |
| 727 | "permissions": "0000000000000001" |
| 728 | } |
| 729 | } |
| 730 | ] |
| 731 | } |
| 732 | ] |
| 733 | } |
| 734 | ] |
| 735 | } |
| 736 | ] |
| 737 | |
| 738 | aram_get_config |
| 739 | ~~~~~~~~~~~~~~~ |
| 740 | Perform Config handshake with ARA-M applet: Tell it our version and retrieve its version. |
| 741 | |
| 742 | NOTE: Not supported in all ARA-M implementations. |
| 743 | |
Harald Welte | 95ce6b1 | 2021-10-20 18:40:54 +0200 | [diff] [blame] | 744 | |
| 745 | aram_store_ref_ar_do |
| 746 | ~~~~~~~~~~~~~~~~~~~~ |
Harald Welte | 95ce6b1 | 2021-10-20 18:40:54 +0200 | [diff] [blame] | 747 | .. argparse:: |
| 748 | :module: pySim.ara_m |
| 749 | :func: ADF_ARAM.AddlShellCommands.store_ref_ar_do_parse |
| 750 | |
| 751 | 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] | 752 | :: |
| 753 | |
| 754 | pySIM-shell (MF/ADF.ARA-M)> aram_store_ref_ar_do --aid FFFFFFFFFFFF --device-app-id E46872F28B350B7E1F140DE535C2A8D5804F0BE3 --android-permissions 0000000000000001 --apdu-always |
| 755 | |
| 756 | |
| 757 | aram_delete_all |
| 758 | ~~~~~~~~~~~~~~~ |
| 759 | This command will request deletion of all access rules stored within the |
| 760 | ARA-M applet. Use it with caution, there is no undo. Any rules later |
| 761 | intended must be manually inserted again using `aram_store_ref_ar_do` |
| 762 | |
| 763 | |
Harald Welte | 577312a | 2023-02-23 09:51:30 +0100 | [diff] [blame] | 764 | GlobalPlatform commands |
| 765 | ----------------------- |
| 766 | |
| 767 | pySim-shell has only the mots rudimentary support for GlobalPlatform at this point. Please use dedicated |
| 768 | projects like GlobalPlatformPro meanwhile. |
| 769 | |
| 770 | get_data |
| 771 | ~~~~~~~~ |
| 772 | Performs the GET DATA command as specified by GlobalPlatform. |
| 773 | |
Harald Welte | 15fae98 | 2021-04-10 10:22:27 +0200 | [diff] [blame] | 774 | |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 775 | cmd2 settable parameters |
| 776 | ------------------------ |
| 777 | |
| 778 | ``cmd2`` has the concept of *settable parameters* which act a bit like environment variables in an OS-level |
| 779 | shell: They can be read and set, and they will influence the behavior somehow. |
| 780 | |
| 781 | conserve_write |
| 782 | ~~~~~~~~~~~~~~ |
| 783 | |
| 784 | If enabled, pySim will (when asked to write to a card) always first read the respective file/record and |
| 785 | verify if the to-be-written value differs from the current on-card value. If not, the write will be skipped. |
| 786 | Writes will only be performed if the new value is different from the current on-card value. |
| 787 | |
| 788 | If disabled, pySim will always write irrespective of the current/new value. |
| 789 | |
Harald Welte | 1748b93 | 2021-04-06 21:12:25 +0200 | [diff] [blame] | 790 | json_pretty_print |
| 791 | ~~~~~~~~~~~~~~~~~ |
| 792 | |
| 793 | This parameter determines if generated JSON output should (by default) be pretty-printed (multi-line |
| 794 | output with indent level of 4 spaces) or not. |
| 795 | |
| 796 | The default value of this parameter is 'true'. |
| 797 | |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 798 | debug |
| 799 | ~~~~~ |
| 800 | |
| 801 | If enabled, full python back-traces will be displayed in case of exceptions |
| 802 | |
Harald Welte | 7829d8a | 2021-04-10 11:28:53 +0200 | [diff] [blame] | 803 | apdu_trace |
| 804 | ~~~~~~~~~~ |
| 805 | |
| 806 | Boolean variable that determines if a hex-dump of the command + response APDU shall be printed. |
| 807 | |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 808 | numeric_path |
| 809 | ~~~~~~~~~~~~ |
| 810 | |
| 811 | Boolean variable that determines if path (e.g. in prompt) is displayed with numeric FIDs or string names. |
| 812 | |
| 813 | :: |
| 814 | |
| 815 | pySIM-shell (MF/EF.ICCID)> set numeric_path True |
| 816 | numeric_path - was: False |
| 817 | now: True |
| 818 | pySIM-shell (3f00/2fe2)> set numeric_path False |
| 819 | numeric_path - was: True |
| 820 | now: False |
| 821 | pySIM-shell (MF/EF.ICCID)> help set |