FreeCalypso > hg > fc-pcsc-tools
changeset 103:9b2cb2b9c910
fc-simtool fplmn-* commands implemented
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 18 Feb 2021 00:17:14 +0000 |
parents | 9ce95d9c5c34 |
children | 4709cff90a58 |
files | simtool/Makefile simtool/dispatch.c simtool/fplmn.c |
diffstat | 3 files changed, 157 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/simtool/Makefile Wed Feb 17 23:25:47 2021 +0000 +++ b/simtool/Makefile Thu Feb 18 00:17:14 2021 +0000 @@ -1,12 +1,12 @@ CC= gcc CFLAGS= -O2 -I/usr/include/PCSC -I../libcommon PROG= fc-simtool -OBJS= a38.o chv.o chvext.o curfile.o dispatch.o dumpdir.o grcard1.o grcard2.o\ - hlread.o lndwrite.o main.o miscadm.o opldump.o pbcommon.o pbdump.o \ - pberase.o pbrestore.o pbupd_imm.o pbupd_immhex.o plmnsel.o pnndump.o \ - readcmd.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 sysmo.o telsum.o usersum.o writecmd.o writeops.o +OBJS= a38.o chv.o chvext.o curfile.o dispatch.o dumpdir.o fplmn.o grcard1.o \ + grcard2.o hlread.o lndwrite.o main.o miscadm.o opldump.o pbcommon.o \ + pbdump.o pberase.o pbrestore.o pbupd_imm.o pbupd_immhex.o plmnsel.o \ + pnndump.o readcmd.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 sysmo.o telsum.o usersum.o writecmd.o writeops.o LIBS= ../libcommon/libcommon.a INSTBIN=/opt/freecalypso/bin
--- a/simtool/dispatch.c Wed Feb 17 23:25:47 2021 +0000 +++ b/simtool/dispatch.c Thu Feb 18 00:17:14 2021 +0000 @@ -14,6 +14,10 @@ extern int cmd_enable_chv(); extern int cmd_exec(); extern int cmd_fix_sysmo_msisdn(); +extern int cmd_fplmn_dump(); +extern int cmd_fplmn_erase(); +extern int cmd_fplmn_erase_all(); +extern int cmd_fplmn_write(); extern int cmd_grcard1_set_adm(); extern int cmd_grcard1_set_ki(); extern int cmd_grcard1_set_pin(); @@ -104,6 +108,10 @@ {"exec", 1, 1, cmd_exec}, {"exit", 0, 0, good_exit}, {"fix-sysmo-msisdn", 0, 0, cmd_fix_sysmo_msisdn}, + {"fplmn-dump", 0, 0, cmd_fplmn_dump}, + {"fplmn-erase", 1, 2, cmd_fplmn_erase}, + {"fplmn-erase-all", 0, 0, cmd_fplmn_erase_all}, + {"fplmn-write", 2, 2, cmd_fplmn_write}, {"grcard1-set-adm1", 2, 2, cmd_grcard1_set_adm}, {"grcard1-set-adm2", 2, 2, cmd_grcard1_set_adm}, {"grcard1-set-ki", 1, 1, cmd_grcard1_set_ki},
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/simtool/fplmn.c Thu Feb 18 00:17:14 2021 +0000 @@ -0,0 +1,143 @@ +/* + * This module implements commands for working with EF_FPLMN. + */ + +#include <sys/types.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <strings.h> +#include "simresp.h" +#include "curfile.h" +#include "file_id.h" + +static +select_ef_fplmn() +{ + int rc; + + rc = select_op(DF_GSM); + if (rc < 0) + return(rc); + rc = select_op(EF_FPLMN); + if (rc < 0) + return(rc); + rc = parse_ef_select_response(); + if (rc < 0) + return(rc); + if (curfile_structure != 0x00) { + fprintf(stderr, "error: EF_FPLMN is not transparent\n"); + return(-1); + } + if (curfile_total_size != 12) { + fprintf(stderr, + "error: EF_FPLMN size does not equal 12 bytes\n"); + return(-1); + } + return(0); +} + +cmd_fplmn_dump(argc, argv) + char **argv; +{ + int rc; + u_char *dp; + char ascbuf[8]; + unsigned idx; + + rc = select_ef_fplmn(); + if (rc < 0) + return(rc); + rc = readbin_op(0, 12); + if (rc < 0) + return(rc); + dp = sim_resp_data; + for (idx = 0; idx < 4; idx++, dp += 3) { + if (idx) + putchar(' '); + if (dp[0] == 0xFF && dp[1] == 0xFF && dp[2] == 0xFF) + fputs("-blank-", stdout); + else { + decode_plmn_3bytes(dp, ascbuf, 1); + fputs(ascbuf, stdout); + } + } + putchar('\n'); + return(0); +} + +cmd_fplmn_write(argc, argv) + char **argv; +{ + int rc; + unsigned idx; + u_char rec[3]; + + rc = select_ef_fplmn(); + if (rc < 0) + return(rc); + idx = strtoul(argv[1], 0, 0); + if (idx >= 4) { + fprintf(stderr, "error: specified index is out of range\n"); + return(-1); + } + rc = encode_plmn_3bytes(argv[2], rec); + if (rc < 0) + return(rc); + return update_bin_op(idx * 3, rec, 3); +} + +cmd_fplmn_erase(argc, argv) + char **argv; +{ + int rc; + unsigned idx, start, end; + u_char rec[3]; + + rc = select_ef_fplmn(); + if (rc < 0) + return(rc); + start = strtoul(argv[1], 0, 0); + if (start >= 4) { + fprintf(stderr, + "error: specified starting index is out of range\n"); + return(-1); + } + if (!argv[2]) + end = start; + else if (!strcmp(argv[2], "end")) + end = 3; + else { + end = strtoul(argv[1], 0, 0); + if (end >= 4) { + fprintf(stderr, + "error: specified ending index is out of range\n"); + return(-1); + } + if (start > end) { + fprintf(stderr, + "error: reverse index range specified\n"); + return(-1); + } + } + memset(rec, 0xFF, 3); + for (idx = start; idx <= end; idx++) { + rc = update_bin_op(idx * 3, rec, 3); + if (rc < 0) + return(rc); + } + return(0); +} + +cmd_fplmn_erase_all(argc, argv) + char **argv; +{ + int rc; + u_char ffbuf[12]; + + rc = select_ef_fplmn(); + if (rc < 0) + return(rc); + memset(ffbuf, 0xFF, 12); + return update_bin_op(0, ffbuf, 12); +}