FreeCalypso > hg > fc-sim-tools
comparison simtool/hlread.c @ 10:ddd767f6e15b
fc-simtool ported over
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Sun, 14 Mar 2021 07:11:25 +0000 |
| parents | |
| children | aefc9fe653d3 |
comparison
equal
deleted
inserted
replaced
| 9:c9ef9e91dd8e | 10:ddd767f6e15b |
|---|---|
| 1 /* | |
| 2 * This module implements some high-level or user-friendly read commands. | |
| 3 */ | |
| 4 | |
| 5 #include <sys/types.h> | |
| 6 #include <stdio.h> | |
| 7 #include "simresp.h" | |
| 8 #include "curfile.h" | |
| 9 #include "file_id.h" | |
| 10 | |
| 11 cmd_iccid(argc, argv, outf) | |
| 12 char **argv; | |
| 13 FILE *outf; | |
| 14 { | |
| 15 int rc; | |
| 16 char buf[21], *cp; | |
| 17 | |
| 18 rc = select_op(FILEID_MF); | |
| 19 if (rc < 0) | |
| 20 return(rc); | |
| 21 rc = select_op(EF_ICCID); | |
| 22 if (rc < 0) | |
| 23 return(rc); | |
| 24 rc = parse_ef_select_response(); | |
| 25 if (rc < 0) | |
| 26 return(rc); | |
| 27 if (curfile_structure != 0x00 || curfile_total_size != 10) { | |
| 28 fprintf(stderr, "error: expected transparent EF of 10 bytes\n"); | |
| 29 return(-1); | |
| 30 } | |
| 31 rc = readbin_op(0, 10); | |
| 32 if (rc < 0) | |
| 33 return(rc); | |
| 34 decode_reversed_nibbles(sim_resp_data, 10, buf); | |
| 35 for (cp = buf + 20; (cp > buf + 1) && (cp[-1] == 'F'); cp--) | |
| 36 ; | |
| 37 *cp = '\0'; | |
| 38 fprintf(outf, "%s\n", buf); | |
| 39 return(0); | |
| 40 } | |
| 41 | |
| 42 cmd_imsi(argc, argv, outf) | |
| 43 char **argv; | |
| 44 FILE *outf; | |
| 45 { | |
| 46 int rc; | |
| 47 char buf[17], *endp; | |
| 48 | |
| 49 rc = select_op(DF_GSM); | |
| 50 if (rc < 0) | |
| 51 return(rc); | |
| 52 rc = select_op(EF_IMSI); | |
| 53 if (rc < 0) | |
| 54 return(rc); | |
| 55 rc = parse_ef_select_response(); | |
| 56 if (rc < 0) | |
| 57 return(rc); | |
| 58 if (curfile_structure != 0x00 || curfile_total_size != 9) { | |
| 59 fprintf(stderr, "error: expected transparent EF of 9 bytes\n"); | |
| 60 return(-1); | |
| 61 } | |
| 62 rc = readbin_op(0, 9); | |
| 63 if (rc < 0) | |
| 64 return(rc); | |
| 65 if (sim_resp_data[0] < 1 || sim_resp_data[0] > 8) { | |
| 66 malformed: fprintf(stderr, "error: malformed EF_IMSI record\n"); | |
| 67 return(-1); | |
| 68 } | |
| 69 decode_reversed_nibbles(sim_resp_data + 1, sim_resp_data[0], buf); | |
| 70 endp = buf + (sim_resp_data[0] << 1); | |
| 71 switch (buf[0]) { | |
| 72 case '1': | |
| 73 if (sim_resp_data[0] == 1) | |
| 74 goto malformed; | |
| 75 *--endp = '\0'; | |
| 76 break; | |
| 77 case '9': | |
| 78 *endp = '\0'; | |
| 79 break; | |
| 80 default: | |
| 81 goto malformed; | |
| 82 } | |
| 83 fprintf(outf, "%s\n", buf + 1); | |
| 84 return(0); | |
| 85 } | |
| 86 | |
| 87 cmd_imsi_raw(argc, argv, outf) | |
| 88 char **argv; | |
| 89 FILE *outf; | |
| 90 { | |
| 91 int rc; | |
| 92 char buf[17]; | |
| 93 | |
| 94 rc = select_op(DF_GSM); | |
| 95 if (rc < 0) | |
| 96 return(rc); | |
| 97 rc = select_op(EF_IMSI); | |
| 98 if (rc < 0) | |
| 99 return(rc); | |
| 100 rc = parse_ef_select_response(); | |
| 101 if (rc < 0) | |
| 102 return(rc); | |
| 103 if (curfile_structure != 0x00 || curfile_total_size != 9) { | |
| 104 fprintf(stderr, "error: expected transparent EF of 9 bytes\n"); | |
| 105 return(-1); | |
| 106 } | |
| 107 rc = readbin_op(0, 9); | |
| 108 if (rc < 0) | |
| 109 return(rc); | |
| 110 decode_reversed_nibbles(sim_resp_data + 1, 8, buf); | |
| 111 buf[16] = '\0'; | |
| 112 fprintf(outf, "%s parity=%c len=%u\n", buf + 1, buf[0], | |
| 113 sim_resp_data[0]); | |
| 114 return(0); | |
| 115 } | |
| 116 | |
| 117 cmd_spn(argc, argv, outf) | |
| 118 char **argv; | |
| 119 FILE *outf; | |
| 120 { | |
| 121 int rc; | |
| 122 unsigned textlen; | |
| 123 | |
| 124 rc = select_op(DF_GSM); | |
| 125 if (rc < 0) | |
| 126 return(rc); | |
| 127 rc = select_op(EF_SPN); | |
| 128 if (rc < 0) | |
| 129 return(rc); | |
| 130 rc = parse_ef_select_response(); | |
| 131 if (rc < 0) | |
| 132 return(rc); | |
| 133 if (curfile_structure != 0x00 || curfile_total_size != 17) { | |
| 134 fprintf(stderr, "error: expected transparent EF of 17 bytes\n"); | |
| 135 return(-1); | |
| 136 } | |
| 137 rc = readbin_op(0, 17); | |
| 138 if (rc < 0) | |
| 139 return(rc); | |
| 140 fprintf(outf, "Display condition: %02X\n", sim_resp_data[0]); | |
| 141 fputs("SPN: ", outf); | |
| 142 rc = validate_alpha_field(sim_resp_data + 1, 16, &textlen); | |
| 143 if (rc >= 0) | |
| 144 print_alpha_field(sim_resp_data + 1, textlen, outf); | |
| 145 else | |
| 146 fputs("malformed alpha field", outf); | |
| 147 putc('\n', outf); | |
| 148 return(0); | |
| 149 } |
