FreeCalypso > hg > fc-pcsc-tools
changeset 184:8d073ff62c48
fc-simtool: imsi command does higher-level parsing,
the old version is now imsi-raw
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 06 Mar 2021 05:44:17 +0000 |
parents | 2545dd27ca38 |
children | e92ff25199b9 |
files | simtool/dispatch.c simtool/hlread.c |
diffstat | 2 files changed, 47 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/simtool/dispatch.c Sat Mar 06 05:24:26 2021 +0000 +++ b/simtool/dispatch.c Sat Mar 06 05:44:17 2021 +0000 @@ -38,6 +38,7 @@ extern int cmd_grcard2_set_super_hex(); extern int cmd_iccid(); extern int cmd_imsi(); +extern int cmd_imsi_raw(); extern int cmd_inval_adn(); extern int cmd_lnd_dump(); extern int cmd_lnd_erase(); @@ -158,6 +159,7 @@ {"grcard2-set-super-hex", 1, 1, 0, cmd_grcard2_set_super_hex}, {"iccid", 0, 0, 1, cmd_iccid}, {"imsi", 0, 0, 1, cmd_imsi}, + {"imsi-raw", 0, 0, 1, cmd_imsi_raw}, {"inval-adn", 0, 0, 0, cmd_inval_adn}, {"lnd-dump", 0, 0, 1, cmd_lnd_dump}, {"lnd-erase", 0, 0, 0, cmd_lnd_erase},
--- a/simtool/hlread.c Sat Mar 06 05:24:26 2021 +0000 +++ b/simtool/hlread.c Sat Mar 06 05:44:17 2021 +0000 @@ -44,6 +44,51 @@ FILE *outf; { int rc; + char buf[17], *endp; + + rc = select_op(DF_GSM); + if (rc < 0) + return(rc); + rc = select_op(EF_IMSI); + if (rc < 0) + return(rc); + rc = parse_ef_select_response(); + if (rc < 0) + return(rc); + if (curfile_structure != 0x00 || curfile_total_size != 9) { + fprintf(stderr, "error: expected transparent EF of 9 bytes\n"); + return(-1); + } + rc = readbin_op(0, 9); + if (rc < 0) + return(rc); + if (sim_resp_data[0] < 1 || sim_resp_data[0] > 8) { +malformed: fprintf(stderr, "error: malformed EF_IMSI record\n"); + return(-1); + } + decode_reversed_nibbles(sim_resp_data + 1, sim_resp_data[0], buf); + endp = buf + (sim_resp_data[0] << 1); + switch (buf[0]) { + case '1': + if (sim_resp_data[0] == 1) + goto malformed; + *--endp = '\0'; + break; + case '9': + *endp = '\0'; + break; + default: + goto malformed; + } + fprintf(outf, "%s\n", buf + 1); + return(0); +} + +cmd_imsi_raw(argc, argv, outf) + char **argv; + FILE *outf; +{ + int rc; char buf[17]; rc = select_op(DF_GSM);