# HG changeset patch # User Mychaela Falconia # Date 1615085292 0 # Node ID 3bde063234aa0f3ba9b05a3f346a58514d083c53 # Parent 3ddbc3fea5f0742160f3f26539fb6a4dbdebeae1 fc-simtool plmnsel-write-list command implemented diff -r 3ddbc3fea5f0 -r 3bde063234aa libutil/Makefile --- a/libutil/Makefile Sun Mar 07 02:36:27 2021 +0000 +++ b/libutil/Makefile Sun Mar 07 02:48:12 2021 +0000 @@ -3,8 +3,8 @@ OBJS= alpha_decode.o alpha_fromfile.o alpha_valid.o decimal_str.o \ filesearch.o gsm7_decode.o gsm7_encode.o gsm7_encode_table.o \ gsm7_unpack.o hexdigits.o hexread.o hexstr.o iccid_luhn.o nibbles2asc.o\ - number_decode.o number_encode.o pinentry.o plmncodes.o revnibbles.o \ - shorthand.o + number_decode.o number_encode.o pinentry.o plmncodes.o plmnlist.o \ + revnibbles.o shorthand.o LIB= libutil.a all: ${LIB} diff -r 3ddbc3fea5f0 -r 3bde063234aa libutil/plmnlist.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libutil/plmnlist.c Sun Mar 07 02:48:12 2021 +0000 @@ -0,0 +1,69 @@ +/* + * This module implements a function for reading PLMN lists from files. + */ + +#include +#include +#include +#include +#include +#include + +extern FILE *open_script_input_file(); + +read_plmn_list_from_file(filename, buf, ef_len) + char *filename; + u_char *buf; + unsigned ef_len; +{ + FILE *inf; + int lineno, rc; + char linebuf[1024], *cp, *np; + u_char *dp, *endp; + + inf = open_script_input_file(filename); + if (!inf) { + perror(filename); + return(-1); + } + dp = buf; + endp = buf + ef_len; + for (lineno = 1; fgets(linebuf, sizeof linebuf, inf); lineno++) { + if (!index(linebuf, '\n')) { + fprintf(stderr, + "%s line %d: too long or missing newline\n", + filename, lineno); + fclose(inf); + return(-1); + } + for (cp = linebuf; ; ) { + while (isspace(*cp)) + cp++; + if (*cp == '\0' || *cp == '#') + break; + for (np = cp; *cp && !isspace(*cp); cp++) + ; + if (*cp) + *cp++ = '\0'; + if (dp >= endp) { + fprintf(stderr, + "%s line %d: number of PLMN codes exceeds EF size\n", + filename, lineno); + fclose(inf); + return(-1); + } + rc = encode_plmn_3bytes(np, dp); + if (rc < 0) { + fprintf(stderr, "%s line %d: invalid MCC-MNC\n", + filename, lineno); + fclose(inf); + return(-1); + } + dp += 3; + } + } + fclose(inf); + while (dp < endp) + *dp++ = 0xFF; + return(0); +} diff -r 3ddbc3fea5f0 -r 3bde063234aa simtool/dispatch.c --- a/simtool/dispatch.c Sun Mar 07 02:36:27 2021 +0000 +++ b/simtool/dispatch.c Sun Mar 07 02:48:12 2021 +0000 @@ -59,6 +59,7 @@ extern int cmd_plmnsel_erase(); extern int cmd_plmnsel_erase_all(); extern int cmd_plmnsel_write(); +extern int cmd_plmnsel_write_list(); extern int cmd_pnn_dump(); extern int cmd_readbin(); extern int cmd_readef(); @@ -181,6 +182,7 @@ {"plmnsel-erase", 1, 2, 0, cmd_plmnsel_erase}, {"plmnsel-erase-all", 0, 0, 0, cmd_plmnsel_erase_all}, {"plmnsel-write", 2, 2, 0, cmd_plmnsel_write}, + {"plmnsel-write-list", 1, 1, 0, cmd_plmnsel_write_list}, {"pnn-dump", 0, 0, 1, cmd_pnn_dump}, {"quit", 0, 0, 0, good_exit}, {"readbin", 2, 2, 1, cmd_readbin}, diff -r 3ddbc3fea5f0 -r 3bde063234aa simtool/plmnsel.c --- a/simtool/plmnsel.c Sun Mar 07 02:36:27 2021 +0000 +++ b/simtool/plmnsel.c Sun Mar 07 02:48:12 2021 +0000 @@ -117,6 +117,21 @@ return update_bin_op(idx * 3, rec, 3); } +cmd_plmnsel_write_list(argc, argv) + char **argv; +{ + int rc; + u_char buf[255]; + + rc = select_ef_plmnsel(); + if (rc < 0) + return(rc); + rc = read_plmn_list_from_file(argv[1], buf, curfile_total_size); + if (rc < 0) + return(rc); + return update_bin_op(0, buf, curfile_total_size); +} + cmd_plmnsel_erase(argc, argv) char **argv; {