FreeCalypso > hg > freecalypso-hwlab
comparison simtool/hlread.c @ 96:a5dfab380a90
fc-simtool: iccid high-level read command implemented
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 24 Jan 2021 22:11:34 +0000 |
parents | |
children | 597c4e87a1f4 |
comparison
equal
deleted
inserted
replaced
95:5f826e428641 | 96:a5dfab380a90 |
---|---|
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 <pcsclite.h> | |
9 #include <winscard.h> | |
10 #include "globals.h" | |
11 #include "file_id.h" | |
12 | |
13 encode_hex_digit(d) | |
14 unsigned d; | |
15 { | |
16 if (d <= 9) | |
17 return(d + '0'); | |
18 else | |
19 return(d - 10 + 'A'); | |
20 } | |
21 | |
22 decode_reversed_nibbles(bytes, nbytes, dest) | |
23 u_char *bytes; | |
24 unsigned nbytes; | |
25 char *dest; | |
26 { | |
27 u_char *sp; | |
28 char *dp; | |
29 unsigned n, c; | |
30 | |
31 sp = bytes; | |
32 dp = dest; | |
33 for (n = 0; n < nbytes; n++) { | |
34 c = *sp & 0xF; | |
35 *dp++ = encode_hex_digit(c); | |
36 c = *sp >> 4; | |
37 *dp++ = encode_hex_digit(c); | |
38 sp++; | |
39 } | |
40 } | |
41 | |
42 cmd_iccid() | |
43 { | |
44 int rc; | |
45 char buf[21]; | |
46 | |
47 rc = select_op(FILEID_MF); | |
48 if (rc < 0) | |
49 return(rc); | |
50 rc = select_op(EF_ICCID); | |
51 if (rc < 0) | |
52 return(rc); | |
53 rc = parse_ef_select_response(); | |
54 if (rc < 0) | |
55 return(rc); | |
56 if (curfile_structure != 0x00 || curfile_total_size != 10) { | |
57 fprintf(stderr, "error: expected transparent EF of 10 bytes\n"); | |
58 return(-1); | |
59 } | |
60 rc = readbin_op(0, 10); | |
61 if (rc < 0) | |
62 return(rc); | |
63 decode_reversed_nibbles(sim_resp_data, 10, buf); | |
64 buf[20] = '\0'; | |
65 printf("%s\n", buf); | |
66 return(0); | |
67 } |