<div dir="ltr"><div>Harald,</div><div><br></div><div>I think this is a great idea and I'd love to help out, but I'm new to working on open source projects. What's the best way for me to get started in a way that would be helpful?</div><div><br></div><div>Best,</div><div><br></div><div>Bryan<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Jan 8, 2021 at 5:54 PM Harald Welte <<a href="mailto:laforge@gnumonks.org">laforge@gnumonks.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Dear Osmocom community,<br>
<br>
pySim-prog was nice when there were only 5 parameters on a SIM that we<br>
could program, and where the use case was pretty limited.  Today, we<br>
have SIM/USIM/ISIM cards with hundreds of files and even more parameters<br>
to program.  We cannot add a command line argument for each file to<br>
pySim-prog.<br>
<br>
Instead, this introduces an interactive command-line shell / REPL,<br>
in which one can navigate the file system of the card, read and update<br>
files both in raw format and in decoded/parsed format.<br>
<br>
The idea is primarily inspired by Henryk Ploetz' venerable<br>
cyberflex-shell, but implemented on a more modern basis using<br>
the cmd2 python module.<br>
<br>
You can see the very first prototype in the laforge/shell branch of pysim.git<br>
<br>
You can do things with it like this:<br>
<br>
===> Start-up and authenticate with adm pin<br>
----------------------------------------------------------------------<br>
$ ./pysim-shell.py -p 0<br>
Using PC/SC reader interface<br>
Autodetected card type: sysmoISIM-SJA2<br>
AIDs on card: ['a0000000871002ffffffff8907090000', 'a0000000871004ffffffff8907090000']<br>
Welcome to pySim-shell!<br>
pySIM-shell (3f00)> verify_adm 92990895<br>
----------------------------------------------------------------------<br>
<br>
===> interactive help<br>
----------------------------------------------------------------------<br>
pySIM-shell (3f00)> help<br>
<br>
Documented commands (use 'help -v' for verbose/'help <topic>' for details):<br>
<br>
ISO7816 Commands<br>
================<br>
read_binary  select_adf  select_file  update_binary  update_record  verify_chv<br>
<br>
pySim Commands<br>
==============<br>
intro  verify_adm<br>
<br>
USIM Commands<br>
=============<br>
read_ehplmn  ust_service_activate  ust_service_deactivate<br>
<br>
pySim-shell built-in commands<br>
=============================<br>
alias  help     macro  quit          run_script  shell<br>
edit   history  py     run_pyscript  set         shortcuts<br>
<br>
----------------------------------------------------------------------<br>
<br>
<br>
===> more interactive help<br>
----------------------------------------------------------------------<br>
pySIM-shell (3f00)> help read_binary<br>
usage: read_binary [-h] [--file-id FILE_ID] [--offset OFFSET] [--length LENGTH] [--record-nr RECORD_NR]<br>
<br>
Read binary data from a transparent EF<br>
<br>
optional arguments:<br>
  -h, --help            show this help message and exit<br>
  --file-id FILE_ID     File ID<br>
  --offset OFFSET       Byte offset for start of read<br>
  --length LENGTH       Number of bytes to read<br>
  --record-nr RECORD_NR<br>
                        Number of record to read<br>
----------------------------------------------------------------------<br>
<br>
<br>
===> navigating the FS and reading files<br>
----------------------------------------------------------------------<br>
pySIM-shell (3f00)> select_file 7f20<br>
['622c8202782183027f20a509800171830400018d088a01058b032f0601c60f90017083010183018183010a83010b']<br>
pySIM-shell (3f00/7f20)> read_binary --file-id 6f07<br>
089910070000400310<br>
----------------------------------------------------------------------<br>
<br>
<br>
===> interaction with local filesystem, i.e. I/O redirect + shell commands<br>
----------------------------------------------------------------------<br>
pySIM-shell (3f00)> select_adf a0000000871002<br>
pySIM-shell (a0000000871002)> select_file 5f3b<br>
pySIM-shell (a0000000871002/5f3b)> read_binary --file-id 4f20 > /tmp/f<br>
pySIM-shell (a0000000871002/5f3b)> !cat /tmp/f<br>
ffffffffffffffff07<br>
----------------------------------------------------------------------<br>
<br>
===> piping output through shell tools like grep<br>
----------------------------------------------------------------------<br>
pySIM-shell (3f00)> read_ust  | grep 86<br>
        Service 86 - Allowed CSG Lists and corresponding indications<br>
----------------------------------------------------------------------<br>
<br>
<br>
===> enabling/disabling services<br>
----------------------------------------------------------------------<br>
pySIM-shell (3f00/7f20)> ust_service_activate 123<br>
pySIM-shell (3f00/7f20)> ust_service_deactivate 123<br>
----------------------------------------------------------------------<br>
<br>
It's a very first prototype, but it is really promising.<br>
<br>
The major tasks I see to make this go anywhere is:<br>
<br>
* have "File" class with encoder/decoder methods, which are registered<br>
  automatically with a 'file system' layer that knows about the DF/ADF<br>
  hierarchy<br>
** this allows us to have a "read-decoded" command, which will<br>
   call the decode method of the file, automatically resolved by the<br>
   selected FID/path<br>
* automatic mapping of file-name -> FID and FID -> file name<br>
** when printing (like in the path), use the human-readable names<br>
** allow users to use human-readable names in SELECT<br>
* decode + display the TLVs / FCPs after a SELECT (like cyberflex-shell<br>
* ability to enable/disable APDU trace<br>
* dynamically register/deregster commands based on the path, i.e. offer<br>
  USIM commands only when in ADF_USIM<br>
<br>
We have quite a bit of that infrastructure in the c-language libosmosim,<br>
(part of libosmocore.git), but unfortunately not in python :/<br>
<br>
Let me know if anyone is interested in joining this effort.<br>
<br>
Regards,<br>
        Harald<br>
-- <br>
- Harald Welte <<a href="mailto:laforge@gnumonks.org" target="_blank">laforge@gnumonks.org</a>>           <a href="http://laforge.gnumonks.org/" rel="noreferrer" target="_blank">http://laforge.gnumonks.org/</a><br>
============================================================================<br>
"Privacy in residential applications is a desirable marketing option."<br>
                                                  (ETSI EN 300 175-7 Ch. A6)<br>
</blockquote></div>