FreeCalypso > hg > fc-pcsc-tools
changeset 209:eb16c8841486
fc-simtool write-sst command implemented
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 07 Mar 2021 06:06:23 +0000 |
parents | ead7e546ad75 |
children | 9797417ececa |
files | simtool/Makefile simtool/dispatch.c simtool/sstprog.c |
diffstat | 3 files changed, 102 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- 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
--- 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} };
--- /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 <sys/types.h> +#include <ctype.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <strings.h> +#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); +}