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