FreeCalypso > hg > fc-pcsc-tools
comparison simtool/miscadm.c @ 181:63b640562e21
simtool/miscadm.c: code refactoring in preparation for
adding shorthand ICCID and IMSI write commands
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 06 Mar 2021 04:51:56 +0000 |
parents | 105aa3d1a494 |
children | f4edccd4b583 |
comparison
equal
deleted
inserted
replaced
180:ba8c35ecf796 | 181:63b640562e21 |
---|---|
7 #include <sys/types.h> | 7 #include <sys/types.h> |
8 #include <stdio.h> | 8 #include <stdio.h> |
9 #include "curfile.h" | 9 #include "curfile.h" |
10 #include "file_id.h" | 10 #include "file_id.h" |
11 | 11 |
12 cmd_write_iccid(argc, argv) | 12 static |
13 char **argv; | 13 write_iccid_bin(binrec) |
14 u_char *binrec; | |
14 { | 15 { |
15 int rc; | 16 int rc; |
16 u_char nibbles[20], binrec[10]; | |
17 | 17 |
18 rc = parse_decimal_string_arg(argv[1], nibbles, 20); | |
19 if (rc < 0) | |
20 return(rc); | |
21 pack_reversed_nibbles(nibbles, binrec, 10); | |
22 rc = select_op(FILEID_MF); | 18 rc = select_op(FILEID_MF); |
23 if (rc < 0) | 19 if (rc < 0) |
24 return(rc); | 20 return(rc); |
25 rc = select_op(EF_ICCID); | 21 rc = select_op(EF_ICCID); |
26 if (rc < 0) | 22 if (rc < 0) |
32 fprintf(stderr, | 28 fprintf(stderr, |
33 "error: EF_ICCID is not a transparent EF of 10 bytes\n"); | 29 "error: EF_ICCID is not a transparent EF of 10 bytes\n"); |
34 return(-1); | 30 return(-1); |
35 } | 31 } |
36 return update_bin_op(0, binrec, 10); | 32 return update_bin_op(0, binrec, 10); |
33 } | |
34 | |
35 cmd_write_iccid(argc, argv) | |
36 char **argv; | |
37 { | |
38 int rc; | |
39 u_char nibbles[20], binrec[10]; | |
40 | |
41 rc = parse_decimal_string_arg(argv[1], nibbles, 20); | |
42 if (rc < 0) | |
43 return(rc); | |
44 pack_reversed_nibbles(nibbles, binrec, 10); | |
45 return write_iccid_bin(binrec); | |
46 } | |
47 | |
48 static | |
49 write_imsi_bin(binrec) | |
50 u_char *binrec; | |
51 { | |
52 int rc; | |
53 | |
54 rc = select_op(DF_GSM); | |
55 if (rc < 0) | |
56 return(rc); | |
57 rc = select_op(EF_IMSI); | |
58 if (rc < 0) | |
59 return(rc); | |
60 rc = parse_ef_select_response(); | |
61 if (rc < 0) | |
62 return(rc); | |
63 if (curfile_structure != 0x00 || curfile_total_size != 9) { | |
64 fprintf(stderr, | |
65 "error: EF_IMSI is not a transparent EF of 9 bytes\n"); | |
66 return(-1); | |
67 } | |
68 return update_bin_op(0, binrec, 9); | |
37 } | 69 } |
38 | 70 |
39 cmd_write_imsi(argc, argv) | 71 cmd_write_imsi(argc, argv) |
40 char **argv; | 72 char **argv; |
41 { | 73 { |
51 nibbles[0] = 9; | 83 nibbles[0] = 9; |
52 else | 84 else |
53 nibbles[0] = 1; | 85 nibbles[0] = 1; |
54 binrec[0] = (ndig + 2) >> 1; | 86 binrec[0] = (ndig + 2) >> 1; |
55 pack_reversed_nibbles(nibbles, binrec + 1, 8); | 87 pack_reversed_nibbles(nibbles, binrec + 1, 8); |
56 rc = select_op(DF_GSM); | 88 return write_imsi_bin(binrec); |
57 if (rc < 0) | |
58 return(rc); | |
59 rc = select_op(EF_IMSI); | |
60 if (rc < 0) | |
61 return(rc); | |
62 rc = parse_ef_select_response(); | |
63 if (rc < 0) | |
64 return(rc); | |
65 if (curfile_structure != 0x00 || curfile_total_size != 9) { | |
66 fprintf(stderr, | |
67 "error: EF_IMSI is not a transparent EF of 9 bytes\n"); | |
68 return(-1); | |
69 } | |
70 return update_bin_op(0, binrec, 9); | |
71 } | 89 } |