FreeCalypso > hg > fc-sim-tools
changeset 17:372ecc4aa2c4
off-line utils ported over
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 14 Mar 2021 07:48:55 +0000 |
parents | 53f8a1146a56 |
children | da6e9d0b2ee6 |
files | .hgignore utils/Makefile utils/sim-iccid-mkfull.c utils/sws-email2db.c |
diffstat | 4 files changed, 173 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/.hgignore Sun Mar 14 07:43:51 2021 +0000 +++ b/.hgignore Sun Mar 14 07:48:55 2021 +0000 @@ -12,3 +12,6 @@ ^simtool/fc-simtool$ ^uicc/fc-uicc-tool$ + +^utils/sim-iccid-mkfull$ +^utils/sws-email2db$
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/utils/Makefile Sun Mar 14 07:48:55 2021 +0000 @@ -0,0 +1,23 @@ +CC= gcc +CFLAGS= -O2 +PROGS= sim-iccid-mkfull sws-email2db +LIBS= ../libutil/libutil.a + +INSTALL_PREFIX= /opt/freecalypso + +INSTBIN=${INSTALL_PREFIX}/bin + +all: ${PROGS} + +sim-iccid-mkfull: sim-iccid-mkfull.o ${LIBS} + ${CC} ${CFLAGS} -o $@ $@.o ${LIBS} + +sws-email2db: sws-email2db.c + ${CC} ${CFLAGS} -o $@ $@.c + +install: + mkdir -p ${INSTBIN} + install -c ${PROGS} ${INSTBIN} + +clean: + rm -f ${PROGS} *.o
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/utils/sim-iccid-mkfull.c Sun Mar 14 07:48:55 2021 +0000 @@ -0,0 +1,30 @@ +/* + * This program is a special utility for constructing ICCIDs + * following the 18+1 convention. The argument is an 18-digit ICCID + * base, usually entered in shorthand, and the output is the full + * 19-digit ICCID. + */ + +#include <sys/types.h> +#include <stdio.h> +#include <stdlib.h> + +main(argc, argv) + char **argv; +{ + u_char digits[19]; + char asc[20]; + int rc; + + if (argc != 2) { + fprintf(stderr, "usage: %s shorthand-iccid\n", argv[0]); + exit(1); + } + rc = parse_decimal_shorthand(argv[1], digits, 18); + if (rc < 0) + exit(1); /* error msg already printed */ + digits[18] = compute_iccid_luhn(digits); + nibbles_to_ascii(digits, 19, asc); + puts(asc); + exit(0); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/utils/sws-email2db.c Sun Mar 14 07:48:55 2021 +0000 @@ -0,0 +1,117 @@ +/* + * This program reads extracts from Sysmocom webshop emails containing + * card provisioning data and converts these bits into our sws-card-db + * format. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <strings.h> + +#define MAX_FIELDS 32 +#define MAX_FIELD_KW 7 + +char *infname; +FILE *inf; +char linebuf[128]; +int lineno; + +char field_names[MAX_FIELDS][MAX_FIELD_KW+1]; +unsigned nfields; + +get_input_line() +{ + char *cp; + + if (!fgets(linebuf, sizeof linebuf, inf)) + return(0); + lineno++; + cp = index(linebuf, '\n'); + if (!cp) { + fprintf(stderr, "%s line %d: too long or missing newline\n", + infname, lineno); + exit(1); + } + *cp = '\0'; + return(1); +} + +read_field_names() +{ + for (;;) { + if (!get_input_line()) { + fprintf(stderr, "error: %s EOFs in field name list\n", + infname); + exit(1); + } + if (!linebuf[0]) + break; + if (nfields >= MAX_FIELDS) { + fprintf(stderr, "%s line %d: too many fields\n", + infname, lineno); + exit(1); + } + if (strlen(linebuf) > MAX_FIELD_KW) { + fprintf(stderr, "%s line %d: field name is too long\n", + infname, lineno); + exit(1); + } + strcpy(field_names[nfields], linebuf); + nfields++; + } + if (!nfields) { + fprintf(stderr, "error: %s header defines 0 fields\n", infname); + exit(1); + } +} + +process_one_card() +{ + unsigned nf; + int rc; + + for (nf = 0; nf < nfields; nf++) { + for (;;) { + rc = get_input_line(); + if (!rc) { + if (!nf) + exit(0); + fprintf(stderr, + "error: %s EOFs in the middle of a card data block\n", + infname); + exit(1); + } + if (linebuf[0]) + break; + if (nf) { + fprintf(stderr, + "%s line %d: empty line in the middle of a card data block\n", + infname, lineno); + exit(1); + } + } + if (nf) + putchar(' '); + printf("%s=%s", field_names[nf], linebuf); + } + putchar('\n'); +} + +main(argc, argv) + char **argv; +{ + if (argc != 2) { + fprintf(stderr, "usage: %s email-extract-file\n", argv[0]); + exit(1); + } + infname = argv[1]; + inf = fopen(infname, "r"); + if (!inf) { + perror(infname); + exit(1); + } + read_field_names(); + for (;;) + process_one_card(); +}