FreeCalypso > hg > fc-pcsc-tools
comparison simtool/hlread.c @ 1:2071b28cd0c7
simtool: first refactored version
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 11 Feb 2021 23:04:28 +0000 |
parents | |
children | 4360a7906f34 |
comparison
equal
deleted
inserted
replaced
0:f7145c77b7fb | 1:2071b28cd0c7 |
---|---|
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 <stdlib.h> | |
8 #include "simresp.h" | |
9 #include "curfile.h" | |
10 #include "file_id.h" | |
11 | |
12 encode_hex_digit(d) | |
13 unsigned d; | |
14 { | |
15 if (d <= 9) | |
16 return(d + '0'); | |
17 else | |
18 return(d - 10 + 'A'); | |
19 } | |
20 | |
21 decode_reversed_nibbles(bytes, nbytes, dest) | |
22 u_char *bytes; | |
23 unsigned nbytes; | |
24 char *dest; | |
25 { | |
26 u_char *sp; | |
27 char *dp; | |
28 unsigned n, c; | |
29 | |
30 sp = bytes; | |
31 dp = dest; | |
32 for (n = 0; n < nbytes; n++) { | |
33 c = *sp & 0xF; | |
34 *dp++ = encode_hex_digit(c); | |
35 c = *sp >> 4; | |
36 *dp++ = encode_hex_digit(c); | |
37 sp++; | |
38 } | |
39 } | |
40 | |
41 cmd_iccid() | |
42 { | |
43 int rc; | |
44 char buf[21]; | |
45 | |
46 rc = select_op(FILEID_MF); | |
47 if (rc < 0) | |
48 return(rc); | |
49 rc = select_op(EF_ICCID); | |
50 if (rc < 0) | |
51 return(rc); | |
52 rc = parse_ef_select_response(); | |
53 if (rc < 0) | |
54 return(rc); | |
55 if (curfile_structure != 0x00 || curfile_total_size != 10) { | |
56 fprintf(stderr, "error: expected transparent EF of 10 bytes\n"); | |
57 return(-1); | |
58 } | |
59 rc = readbin_op(0, 10); | |
60 if (rc < 0) | |
61 return(rc); | |
62 decode_reversed_nibbles(sim_resp_data, 10, buf); | |
63 buf[20] = '\0'; | |
64 printf("%s\n", buf); | |
65 return(0); | |
66 } | |
67 | |
68 cmd_imsi() | |
69 { | |
70 int rc; | |
71 char buf[17]; | |
72 | |
73 rc = select_op(DF_GSM); | |
74 if (rc < 0) | |
75 return(rc); | |
76 rc = select_op(EF_IMSI); | |
77 if (rc < 0) | |
78 return(rc); | |
79 rc = parse_ef_select_response(); | |
80 if (rc < 0) | |
81 return(rc); | |
82 if (curfile_structure != 0x00 || curfile_total_size != 9) { | |
83 fprintf(stderr, "error: expected transparent EF of 9 bytes\n"); | |
84 return(-1); | |
85 } | |
86 rc = readbin_op(0, 9); | |
87 if (rc < 0) | |
88 return(rc); | |
89 decode_reversed_nibbles(sim_resp_data + 1, 8, buf); | |
90 buf[16] = '\0'; | |
91 printf("%s parity=%c len=%u\n", buf + 1, buf[0], sim_resp_data[0]); | |
92 return(0); | |
93 } | |
94 | |
95 cmd_spn() | |
96 { | |
97 int rc; | |
98 unsigned textlen; | |
99 | |
100 rc = select_op(DF_GSM); | |
101 if (rc < 0) | |
102 return(rc); | |
103 rc = select_op(EF_SPN); | |
104 if (rc < 0) | |
105 return(rc); | |
106 rc = parse_ef_select_response(); | |
107 if (rc < 0) | |
108 return(rc); | |
109 if (curfile_structure != 0x00 || curfile_total_size != 17) { | |
110 fprintf(stderr, "error: expected transparent EF of 17 bytes\n"); | |
111 return(-1); | |
112 } | |
113 rc = readbin_op(0, 17); | |
114 if (rc < 0) | |
115 return(rc); | |
116 printf("Display condition: %02X\n", sim_resp_data[0]); | |
117 printf("SPN: "); | |
118 rc = validate_alpha_field(sim_resp_data + 1, 16, &textlen); | |
119 if (rc >= 0) | |
120 print_alpha_field(sim_resp_data, textlen, stdout); | |
121 else | |
122 printf("malformed alpha field"); | |
123 putchar('\n'); | |
124 return(0); | |
125 } |