# HG changeset patch # User Mychaela Falconia # Date 1615097183 0 # Node ID eb16c8841486ec55d3b48fdc64e0352d45faba1a # Parent ead7e546ad75dc3289a0ca2fb71824dadc85025f fc-simtool write-sst command implemented diff -r ead7e546ad75 -r eb16c8841486 simtool/Makefile --- a/simtool/Makefile Sun Mar 07 05:39:23 2021 +0000 +++ b/simtool/Makefile Sun Mar 07 06:06:23 2021 +0000 @@ -7,8 +7,8 @@ pberase.o pbrestore.o pbupd_imm.o pbupd_immhex.o plmnsel.o pnndump.o \ readcmd.o readef.o readops.o restorebin.o savebin.o script.o select.o \ smserase.o smsp_common.o smsp_dump.o smsp_erase.o smsp_restore.o \ - smsp_set.o sstlist.o stktest.o sysmo.o telsum.o usersum.o writecmd.o \ - writeops.o + smsp_set.o sstlist.o sstprog.o stktest.o sysmo.o telsum.o usersum.o \ + writecmd.o writeops.o LIBS= ../libcommon/libcommon.a ../libutil/libutil.a INSTBIN=/opt/freecalypso/bin diff -r ead7e546ad75 -r eb16c8841486 simtool/dispatch.c --- a/simtool/dispatch.c Sun Mar 07 05:39:23 2021 +0000 +++ b/simtool/dispatch.c Sun Mar 07 06:06:23 2021 +0000 @@ -104,6 +104,7 @@ extern int cmd_write_iccid_sh19(); extern int cmd_write_imsi(); extern int cmd_write_imsi_sh(); +extern int cmd_write_sst(); extern int current_ef_inval(); extern int current_ef_rehab(); @@ -236,6 +237,7 @@ {"write-iccid-sh19", 1, 1, 0, cmd_write_iccid_sh19}, {"write-imsi", 1, 1, 0, cmd_write_imsi}, {"write-imsi-sh", 1, 1, 0, cmd_write_imsi_sh}, + {"write-sst", 1, 1, 0, cmd_write_sst}, {0, 0, 0, 0, 0} }; diff -r ead7e546ad75 -r eb16c8841486 simtool/sstprog.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/simtool/sstprog.c Sun Mar 07 06:06:23 2021 +0000 @@ -0,0 +1,98 @@ +/* + * This module implements the write-sst command for admin-level + * programming of SIM cards. + */ + +#include +#include +#include +#include +#include +#include +#include "curfile.h" +#include "file_id.h" + +extern FILE *open_script_input_file(); + +cmd_write_sst(argc, argv) + char **argv; +{ + u_char sst[255]; + FILE *inf; + int lineno, rc; + char linebuf[1024], *cp, *np; + unsigned num, code, max_serv; + + rc = select_op(DF_GSM); + if (rc < 0) + return(rc); + rc = select_op(EF_SST); + if (rc < 0) + return(rc); + rc = parse_ef_select_response(); + if (rc < 0) + return(rc); + if (curfile_structure != 0x00) { + fprintf(stderr, "error: EF_SST is not transparent\n"); + return(-1); + } + if (curfile_total_size < 2) { + fprintf(stderr, + "error: EF_SST is shorter than spec minimum of 2 bytes\n"); + return(-1); + } + if (curfile_total_size > 255) { + fprintf(stderr, + "error: EF_SST is longer than our 255 byte limit\n"); + return(-1); + } + memset(sst, 0, curfile_total_size); + max_serv = curfile_total_size * 4; + inf = open_script_input_file(argv[1]); + if (!inf) { + perror(argv[1]); + return(-1); + } + for (lineno = 1; fgets(linebuf, sizeof linebuf, inf); lineno++) { + if (!index(linebuf, '\n')) { + fprintf(stderr, + "%s line %d: too long or missing newline\n", + argv[1], lineno); + fclose(inf); + return(-1); + } + for (cp = linebuf; ; ) { + while (isspace(*cp)) + cp++; + if (*cp == '\0' || *cp == '#') + break; + if (!isdigit(*cp)) { +inv_syntax: fprintf(stderr, "%s line %d: invalid syntax\n", + argv[1], lineno); + fclose(inf); + return(-1); + } + num = strtoul(cp, 0, 10); + while (isdigit(*cp)) + cp++; + if (*cp == '^') { + cp++; + code = 1; + } else + code = 3; + if (*cp && !isspace(*cp)) + goto inv_syntax; + if (num < 1 || num > max_serv) { + fprintf(stderr, + "%s line %d: service number is out of range\n", + argv[1], lineno); + fclose(inf); + return(-1); + } + num--; + sst[num >> 2] |= code << ((num & 3) << 1); + } + } + fclose(inf); + return update_bin_op(0, sst, curfile_total_size); +}