# HG changeset patch # User Mychaela Falconia # Date 1613601798 0 # Node ID d2e800abd257a56bb202cac6848228c65ade64be # Parent 6ba14a9247d251d464fe3b01e9d294cb03f2537e fc-simtool plmnsel-write command implemented diff -r 6ba14a9247d2 -r d2e800abd257 libcommon/plmncodes.c --- a/libcommon/plmncodes.c Wed Feb 17 21:31:32 2021 +0000 +++ b/libcommon/plmncodes.c Wed Feb 17 22:43:18 2021 +0000 @@ -3,6 +3,8 @@ */ #include +#include +#include decode_plmn_3bytes(bin, asc, space_pad) u_char *bin; @@ -23,3 +25,36 @@ asc[6] = '\0'; } } + +encode_plmn_3bytes(asc, bin) + char *asc; + u_char *bin; +{ + u_char mcc[3], mnc[3]; + + if (!isxdigit(asc[0]) || !isxdigit(asc[1]) || !isxdigit(asc[2])) { +inv: fprintf(stderr, "error: invalid MCC-MNC argument\n"); + return(-1); + } + mcc[0] = decode_hex_digit(asc[0]); + mcc[1] = decode_hex_digit(asc[1]); + mcc[2] = decode_hex_digit(asc[2]); + asc += 3; + if (*asc == '-') + asc++; + if (!isxdigit(asc[0]) || !isxdigit(asc[1])) + goto inv; + mnc[0] = decode_hex_digit(asc[0]); + mnc[1] = decode_hex_digit(asc[1]); + asc += 2; + if (*asc == '\0') + mnc[2] = 0xF; + else if (isxdigit(asc[0]) && asc[1] == '\0') + mnc[2] = decode_hex_digit(*asc); + else + goto inv; + bin[0] = (mcc[1] << 4) | mcc[0]; + bin[1] = (mnc[2] << 4) | mcc[2]; + bin[2] = (mnc[1] << 4) | mnc[0]; + return(0); +} diff -r 6ba14a9247d2 -r d2e800abd257 simtool/dispatch.c --- a/simtool/dispatch.c Wed Feb 17 21:31:32 2021 +0000 +++ b/simtool/dispatch.c Wed Feb 17 22:43:18 2021 +0000 @@ -40,6 +40,7 @@ extern int cmd_pb_update_imm(); extern int cmd_pb_update_imm_hex(); extern int cmd_plmnsel_dump(); +extern int cmd_plmnsel_write(); extern int cmd_pnn_dump(); extern int cmd_readbin(); extern int cmd_readef(); @@ -131,6 +132,7 @@ {"pb-update-imm", 3, 4, cmd_pb_update_imm}, {"pb-update-imm-hex", 4, 4, cmd_pb_update_imm_hex}, {"plmnsel-dump", 0, 0, cmd_plmnsel_dump}, + {"plmnsel-write", 2, 2, cmd_plmnsel_write}, {"pnn-dump", 0, 0, cmd_pnn_dump}, {"quit", 0, 0, good_exit}, {"readbin", 2, 2, cmd_readbin}, diff -r 6ba14a9247d2 -r d2e800abd257 simtool/plmnsel.c --- a/simtool/plmnsel.c Wed Feb 17 21:31:32 2021 +0000 +++ b/simtool/plmnsel.c Wed Feb 17 22:43:18 2021 +0000 @@ -4,6 +4,7 @@ #include #include +#include #include "simresp.h" #include "curfile.h" #include "file_id.h" @@ -88,3 +89,24 @@ putchar('\n'); return(0); } + +cmd_plmnsel_write(argc, argv) + char **argv; +{ + int rc; + unsigned idx; + u_char rec[3]; + + rc = select_ef_plmnsel(); + if (rc < 0) + return(rc); + idx = strtoul(argv[1], 0, 0); + if (idx >= curfile_total_size / 3) { + fprintf(stderr, "error: specified index is out of range\n"); + return(-1); + } + rc = encode_plmn_3bytes(argv[2], rec); + if (rc < 0) + return(rc); + return update_bin_op(idx * 3, rec, 3); +}