annotate uicc/hlread.c @ 176:fb2f6497ba53 default tip

doc/Linux-DTR-RTS-flaw: point to new location of this article
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 11 Dec 2023 19:37:20 +0000
parents 69628bcfec17
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
134
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This module implements some high-level or user-friendly read commands.
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 */
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <sys/types.h>
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <stdio.h>
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <stdlib.h>
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <pcsclite.h>
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <winscard.h>
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include "globals.h"
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include "file_id.h"
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 encode_hex_digit(d)
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 unsigned d;
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 {
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 if (d <= 9)
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 return(d + '0');
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 else
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 return(d - 10 + 'A');
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 }
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 decode_reversed_nibbles(bytes, nbytes, dest)
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 u_char *bytes;
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 unsigned nbytes;
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 char *dest;
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 {
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 u_char *sp;
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 char *dp;
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 unsigned n, c;
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 sp = bytes;
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 dp = dest;
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 for (n = 0; n < nbytes; n++) {
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 c = *sp & 0xF;
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 *dp++ = encode_hex_digit(c);
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 c = *sp >> 4;
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 *dp++ = encode_hex_digit(c);
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 sp++;
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 }
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 }
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 cmd_iccid()
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 {
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 int rc;
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 unsigned len;
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 char buf[21];
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 rc = select_op(FILEID_MF);
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 if (rc < 0)
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 return(rc);
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 rc = select_op(EF_ICCID);
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 if (rc < 0)
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 return(rc);
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 rc = select_resp_get_transparent(&len);
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 if (rc < 0)
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 return(rc);
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 if (len != 10) {
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 fprintf(stderr, "error: expected transparent EF of 10 bytes\n");
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 return(-1);
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 }
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 rc = readbin_op(0, 10);
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 if (rc < 0)
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 return(rc);
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 decode_reversed_nibbles(sim_resp_data, 10, buf);
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 buf[20] = '\0';
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 printf("%s\n", buf);
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 return(0);
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 }