# HG changeset patch # User Mychaela Falconia # Date 1613100806 0 # Node ID 72a24b8538eb585e3374a7c2d3649113bbf2552f # Parent 2ef261371347ef2295aeff82d19ba57de364a620 meaty function of pb-dump moved back into simtool, out of libcommon Upon further reflection, I am not going to keep any of the pb-* commands in the new version of fc-uicc-tool: they are logically incorrect for UICC/USIM anyway, as they access phonebook files via old classic SIM paths, rather than their USIM paths. OTOH, I am going to implement new SMSP commands in fc-simtool, and I do not plan to replicate them in fc-uicc-tool either. Guts of fc-simtool pb-dump belong in simtool/pbdump.c, not in libcommon, just like the guts of the future smsp-dump command will belong in its own respective implementation module. diff -r 2ef261371347 -r 72a24b8538eb libcommon/Makefile --- a/libcommon/Makefile Fri Feb 12 03:21:39 2021 +0000 +++ b/libcommon/Makefile Fri Feb 12 03:33:26 2021 +0000 @@ -3,7 +3,7 @@ OBJS= alpha_decode.o alpha_fromfile.o alpha_valid.o apdu.o atr.o \ cardconnect.o chkblank.o dumpdirfunc.o exit.o gsm7_encode.o \ gsm7_encode_table.o hexdump.o hexread.o hexstr.o names.o \ - number_decode.o number_encode.o pbdumpfunc.o pinentry.o revnibbles.o + number_decode.o number_encode.o pinentry.o revnibbles.o LIB= libcommon.a all: ${LIB} diff -r 2ef261371347 -r 72a24b8538eb libcommon/pbdumpfunc.c --- a/libcommon/pbdumpfunc.c Fri Feb 12 03:21:39 2021 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,57 +0,0 @@ -/* - * This module implements the meaty function for pb-dump commands. - */ - -#include -#include -#include "simresp.h" - -static -check_blank_area(dp, endp) - u_char *dp, *endp; -{ - while (dp < endp) - if (*dp++ != 0xFF) - return(-1); - return(0); -} - -void -dump_phonebook_record(recno, outf) - unsigned recno; - FILE *outf; -{ - int rc; - unsigned textlen; - u_char *fixp; - char digits[21]; - - fprintf(outf, "#%u: ", recno); - if (sim_resp_data_len > 14) { - rc = validate_alpha_field(sim_resp_data, - sim_resp_data_len - 14, - &textlen); - if (rc < 0) { -malformed: fprintf(outf, "malformed record\n"); - return; - } - } else - textlen = 0; - fixp = sim_resp_data + sim_resp_data_len - 14; - if (fixp[0] < 2 || fixp[0] > 11) - goto malformed; - rc = decode_phone_number(fixp + 2, fixp[0] - 1, digits); - if (rc < 0) - goto malformed; - rc = check_blank_area(fixp + 1 + fixp[0], fixp + 12); - if (rc < 0) - goto malformed; - /* all checks passed */ - fprintf(outf, "%s,0x%02X ", digits, fixp[1]); - if (fixp[12] != 0xFF) - fprintf(outf, "CCP=%u ", fixp[12]); - if (fixp[13] != 0xFF) - fprintf(outf, "EXT=%u ", fixp[13]); - print_alpha_field(sim_resp_data, textlen, outf); - putc('\n', outf); -} diff -r 2ef261371347 -r 72a24b8538eb simtool/pbdump.c --- a/simtool/pbdump.c Fri Feb 12 03:21:39 2021 +0000 +++ b/simtool/pbdump.c Fri Feb 12 03:33:26 2021 +0000 @@ -5,8 +5,59 @@ #include #include #include +#include "simresp.h" #include "curfile.h" +static +check_blank_area(dp, endp) + u_char *dp, *endp; +{ + while (dp < endp) + if (*dp++ != 0xFF) + return(-1); + return(0); +} + +static void +dump_record(recno, outf) + unsigned recno; + FILE *outf; +{ + int rc; + unsigned textlen; + u_char *fixp; + char digits[21]; + + fprintf(outf, "#%u: ", recno); + if (sim_resp_data_len > 14) { + rc = validate_alpha_field(sim_resp_data, + sim_resp_data_len - 14, + &textlen); + if (rc < 0) { +malformed: fprintf(outf, "malformed record\n"); + return; + } + } else + textlen = 0; + fixp = sim_resp_data + sim_resp_data_len - 14; + if (fixp[0] < 2 || fixp[0] > 11) + goto malformed; + rc = decode_phone_number(fixp + 2, fixp[0] - 1, digits); + if (rc < 0) + goto malformed; + rc = check_blank_area(fixp + 1 + fixp[0], fixp + 12); + if (rc < 0) + goto malformed; + /* all checks passed */ + fprintf(outf, "%s,0x%02X ", digits, fixp[1]); + if (fixp[12] != 0xFF) + fprintf(outf, "CCP=%u ", fixp[12]); + if (fixp[13] != 0xFF) + fprintf(outf, "EXT=%u ", fixp[13]); + print_alpha_field(sim_resp_data, textlen, outf); + putc('\n', outf); +} + cmd_pb_dump(argc, argv) char **argv; { @@ -34,7 +85,7 @@ } if (check_simresp_all_blank()) continue; - dump_phonebook_record(recno, outf); + dump_record(recno, outf); } if (argv[2]) fclose(outf); @@ -76,7 +127,7 @@ return(rc); if (check_simresp_all_blank()) continue; - dump_phonebook_record(recno, stdout); + dump_record(recno, stdout); } return(0); }