FreeCalypso > hg > fc-sim-tools
changeset 79:2a24e94400e8
fcsim1-program utility written
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 09 Apr 2021 03:25:40 +0000 |
parents | f6d5cff989d6 |
children | 711f1641b19c |
files | .hgignore utils/Makefile utils/fcsim1-program.c |
diffstat | 3 files changed, 108 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/.hgignore Fri Apr 09 02:47:21 2021 +0000 +++ b/.hgignore Fri Apr 09 03:25:40 2021 +0000 @@ -17,6 +17,7 @@ ^uicc/fc-uicc-tool$ ^utils/fcsim1-mkprov$ +^utils/fcsim1-program$ ^utils/sim-iccid-mkfull$ ^utils/sim-iccid-mkrange$ ^utils/sws-card-lookup$
--- a/utils/Makefile Fri Apr 09 02:47:21 2021 +0000 +++ b/utils/Makefile Fri Apr 09 03:25:40 2021 +0000 @@ -1,7 +1,7 @@ CC= gcc CFLAGS= -O2 -PROGS= fcsim1-mkprov sim-iccid-mkfull sim-iccid-mkrange sws-card-lookup \ - sws-email2db +PROGS= fcsim1-mkprov fcsim1-program sim-iccid-mkfull sim-iccid-mkrange \ + sws-card-lookup sws-email2db LIBUTIL=../libutil/libutil.a INSTALL_PREFIX= /opt/freecalypso @@ -13,6 +13,9 @@ fcsim1-mkprov: fcsim1-mkprov.o ${LIBUTIL} ${CC} ${CFLAGS} -o $@ $@.o ${LIBUTIL} +fcsim1-program: fcsim1-program.o ${LIBUTIL} + ${CC} ${CFLAGS} -o $@ $@.o ${LIBUTIL} + sim-iccid-mkfull: sim-iccid-mkfull.o ${LIBUTIL} ${CC} ${CFLAGS} -o $@ $@.o ${LIBUTIL}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/utils/fcsim1-program.c Fri Apr 09 03:25:40 2021 +0000 @@ -0,0 +1,102 @@ +/* + * This utility takes an ICCID number on the command line (needs to be + * read from the plastic with human eyeballs and entered by the operator), + * reads card provisioning data from fcsim1-prov-db, and generates + * an fc-simtool command script for programming one FCSIM1 card. The + * intent is that the output of this program will be piped directly + * into fc-simtool. + */ + +#include <sys/types.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include "../libutil/dbread.h" + +static char prov_db_file[] = "/opt/freecalypso/sim-data/fcsim1-prov-db"; + +static char *adm_key = "88888888"; +static int adm_hex; +static char *common_script; +static char iccid_fullstr[20]; +static struct dbread_state dbs; +static char *prov_imsi, *prov_acc, *prov_ki, *prov_msisdn; + +static void +preen_iccid(arg) + char *arg; +{ + u_char nibbles[19]; + + if (parse_decimal_shorthand(arg, nibbles, 19) < 0) + exit(1); /* error msg already printed */ + if (nibbles[18] != compute_iccid_luhn(nibbles)) { + fprintf(stderr, "error: Luhn check digit mismatch\n"); + exit(1); + } + nibbles_to_ascii(nibbles, 19, iccid_fullstr); +} + +static void +parse_cmdline(argc, argv) + char **argv; +{ + extern int optind; + extern char *optarg; + int c; + + while ((c = getopt(argc, argv, "a:A:c:")) != EOF) { + switch (c) { + case 'a': + adm_key = optarg; + continue; + case 'A': + adm_key = optarg; + adm_hex = 1; + continue; + case 'c': + common_script = optarg; + continue; + case '?': + default: +usage: fprintf(stderr, "usage: %s [options] iccid\n", argv[0]); + exit(1); + } + } + if (argc - optind != 1) + goto usage; + preen_iccid(argv[optind]); +} + +main(argc, argv) + char **argv; +{ + int rc; + + parse_cmdline(argc, argv); + rc = dbread_find_record(prov_db_file, &dbs, "ICCID", iccid_fullstr); + if (rc < 0) + exit(1); /* error msg already printed */ + prov_imsi = dbread_find_key_req(&dbs, "IMSI"); + if (!prov_imsi) + exit(1); /* error msg already printed */ + prov_acc = dbread_find_key_req(&dbs, "ACC"); + if (!prov_acc) + exit(1); /* error msg already printed */ + prov_ki = dbread_find_key_req(&dbs, "Ki"); + if (!prov_ki) + exit(1); /* error msg already printed */ + prov_msisdn = dbread_find_key(&dbs, "MSISDN"); + + /* emit the script! */ + printf("verify-%s 11 %s\n", adm_hex ? "hex" : "ext", adm_key); + if (common_script) + printf("exec %s\n", common_script); + printf("write-iccid %s\n", iccid_fullstr); + printf("write-imsi %s\n", prov_imsi); + printf("write-acc %s\n", prov_acc); + printf("grcard2-set-ki %s\n", prov_ki); + if (prov_msisdn) + printf("pb-update-imm msisdn 1 %s\n", prov_msisdn); + exit(0); +}