# HG changeset patch # User Mychaela Falconia # Date 1617938740 0 # Node ID 2a24e94400e8dbf28f6ee2515277b62c0f3334be # Parent f6d5cff989d6d611cd301900d5722e972f63e9f3 fcsim1-program utility written diff -r f6d5cff989d6 -r 2a24e94400e8 .hgignore --- 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$ diff -r f6d5cff989d6 -r 2a24e94400e8 utils/Makefile --- 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} diff -r f6d5cff989d6 -r 2a24e94400e8 utils/fcsim1-program.c --- /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 +#include +#include +#include +#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); +}