# HG changeset patch # User Mychaela Falconia # Date 1615006316 0 # Node ID 63b640562e217897c4c77f545b32c0bf95bf4e96 # Parent ba8c35ecf79647982c45b846ba87ad16c3e84906 simtool/miscadm.c: code refactoring in preparation for adding shorthand ICCID and IMSI write commands diff -r ba8c35ecf796 -r 63b640562e21 simtool/miscadm.c --- a/simtool/miscadm.c Sat Mar 06 04:40:43 2021 +0000 +++ b/simtool/miscadm.c Sat Mar 06 04:51:56 2021 +0000 @@ -9,16 +9,12 @@ #include "curfile.h" #include "file_id.h" -cmd_write_iccid(argc, argv) - char **argv; +static +write_iccid_bin(binrec) + u_char *binrec; { int rc; - u_char nibbles[20], binrec[10]; - rc = parse_decimal_string_arg(argv[1], nibbles, 20); - if (rc < 0) - return(rc); - pack_reversed_nibbles(nibbles, binrec, 10); rc = select_op(FILEID_MF); if (rc < 0) return(rc); @@ -36,6 +32,42 @@ return update_bin_op(0, binrec, 10); } +cmd_write_iccid(argc, argv) + char **argv; +{ + int rc; + u_char nibbles[20], binrec[10]; + + rc = parse_decimal_string_arg(argv[1], nibbles, 20); + if (rc < 0) + return(rc); + pack_reversed_nibbles(nibbles, binrec, 10); + return write_iccid_bin(binrec); +} + +static +write_imsi_bin(binrec) + u_char *binrec; +{ + int rc; + + rc = select_op(DF_GSM); + if (rc < 0) + return(rc); + rc = select_op(EF_IMSI); + if (rc < 0) + return(rc); + rc = parse_ef_select_response(); + if (rc < 0) + return(rc); + if (curfile_structure != 0x00 || curfile_total_size != 9) { + fprintf(stderr, + "error: EF_IMSI is not a transparent EF of 9 bytes\n"); + return(-1); + } + return update_bin_op(0, binrec, 9); +} + cmd_write_imsi(argc, argv) char **argv; { @@ -53,19 +85,5 @@ nibbles[0] = 1; binrec[0] = (ndig + 2) >> 1; pack_reversed_nibbles(nibbles, binrec + 1, 8); - rc = select_op(DF_GSM); - if (rc < 0) - return(rc); - rc = select_op(EF_IMSI); - if (rc < 0) - return(rc); - rc = parse_ef_select_response(); - if (rc < 0) - return(rc); - if (curfile_structure != 0x00 || curfile_total_size != 9) { - fprintf(stderr, - "error: EF_IMSI is not a transparent EF of 9 bytes\n"); - return(-1); - } - return update_bin_op(0, binrec, 9); + return write_imsi_bin(binrec); }