FreeCalypso > hg > fc-sim-tools
changeset 30:25530c262137
fc-simtool sws-lookup implemented
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 17 Mar 2021 00:19:18 +0000 |
parents | aefc9fe653d3 |
children | cca7d0528f89 |
files | simtool/Makefile simtool/cmdtab.c simtool/sws.c |
diffstat | 3 files changed, 52 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/simtool/Makefile Wed Mar 17 00:00:15 2021 +0000 +++ b/simtool/Makefile Wed Mar 17 00:19:18 2021 +0000 @@ -9,7 +9,7 @@ plmnsel.o pnndump.o pnnprog.o readcmd.o readef.o readops.o restorebin.o\ savebin.o select.o sjs1_hacks.o smserase.o smsp_common.o smsp_dump.o \ smsp_erase.o smsp_restore.o smsp_set.o sstlist.o sstprog.o stktest.o \ - telsum.o usersum.o writecmd.o writeops.o + sws.o telsum.o usersum.o writecmd.o writeops.o LIBS= ../libcommon/libcommon.a ../libutil/libutil.a INSTALL_PREFIX= /opt/freecalypso
--- a/simtool/cmdtab.c Wed Mar 17 00:00:15 2021 +0000 +++ b/simtool/cmdtab.c Wed Mar 17 00:19:18 2021 +0000 @@ -89,6 +89,7 @@ extern int cmd_smsp_set_tag(); extern int cmd_spn(); extern int cmd_sst(); +extern int cmd_sws_lookup(); extern int cmd_telecom_sum(); extern int cmd_terminal_profile(); extern int cmd_uicc_dir(); @@ -216,6 +217,7 @@ {"smsp-set-tag", 3, 7, 0, cmd_smsp_set_tag}, {"spn", 0, 0, 1, cmd_spn}, {"sst", 0, 0, 1, cmd_sst}, + {"sws-lookup", 1, 18, 1, cmd_sws_lookup}, {"telecom-sum", 0, 0, 0, cmd_telecom_sum}, {"terminal-profile", 1, 1, 0, cmd_terminal_profile}, {"uicc-dir", 0, 0, 1, cmd_uicc_dir},
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/simtool/sws.c Wed Mar 17 00:19:18 2021 +0000 @@ -0,0 +1,49 @@ +/* + * This module implements a few high-level commands for working with + * Sysmocom webshop SIM cards, using sws-card-db to look up per-card data. + */ + +#include <sys/types.h> +#include <stdio.h> +#include "../libutil/dbread.h" + +static char sws_card_db_file[] = "/opt/freecalypso/sim-data/sws-card-db"; + +static +lookup_sws_card(dbs) + struct dbread_state *dbs; +{ + int rc; + char iccid[21]; + + rc = retrieve_iccid(iccid); + if (rc < 0) + return(rc); + return dbread_find_record(sws_card_db_file, dbs, "ICCID", iccid); +} + +cmd_sws_lookup(argc, argv, outf) + char **argv; + FILE *outf; +{ + int rc; + struct dbread_state dbs; + char **kp, *val; + + rc = lookup_sws_card(&dbs); + if (rc < 0) + return(rc); + if (argc == 2) { + val = dbread_find_key_req(&dbs, argv[1]); + if (!val) + return(-1); + fprintf(outf, "%s\n", val); + return(0); + } + for (kp = argv + 1; *kp; kp++) { + val = dbread_find_key(&dbs, *kp); + if (val) + fprintf(outf, "%s=%s\n", *kp, val); + } + return(0); +}