FreeCalypso > hg > freecalypso-hwlab
annotate uicc/readops.c @ 151:d515cfbb3f39
fc-simtool: hex string parsing: add minimum length parameter
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 07 Feb 2021 00:18:30 +0000 |
parents | f3bdefbeae38 |
children |
rev | line source |
---|---|
133
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 #include <sys/types.h> |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 #include <stdio.h> |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 #include <stdlib.h> |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 #include <pcsclite.h> |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <winscard.h> |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include "globals.h" |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 readbin_op(offset, len) |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 unsigned offset, len; |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 { |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 u_char cmd[5]; |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 int rc; |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 /* READ BINARY command APDU */ |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 cmd[0] = 0x00; |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 cmd[1] = 0xB0; |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 cmd[2] = offset >> 8; |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 cmd[3] = offset; |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 cmd[4] = len; |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 rc = apdu_exchange(cmd, 5); |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 if (rc < 0) |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 return(rc); |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 if (sim_resp_sw != 0x9000) { |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 fprintf(stderr, "bad SW response to READ BINARY: %04X\n", |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 sim_resp_sw); |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 return(-1); |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 } |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 if (sim_resp_data_len != len) { |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 fprintf(stderr, |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 "error: READ BINARY returned %u bytes, expected %u\n", |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 sim_resp_data_len, len); |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 return(-1); |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 } |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 return(0); |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 } |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 readrec_op(recno, mode, len) |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 unsigned recno, mode, len; |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 { |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 u_char cmd[5]; |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 int rc; |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 /* READ RECORD command APDU */ |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 cmd[0] = 0x00; |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 cmd[1] = 0xB2; |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 cmd[2] = recno; |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 cmd[3] = mode; |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 cmd[4] = len; |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 rc = apdu_exchange(cmd, 5); |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 if (rc < 0) |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 return(rc); |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 if (sim_resp_sw != 0x9000) { |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 fprintf(stderr, "bad SW response to READ RECORD: %04X\n", |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 sim_resp_sw); |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 return(-1); |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 } |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 if (sim_resp_data_len != len) { |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 fprintf(stderr, |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 "error: READ RECORD returned %u bytes, expected %u\n", |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 sim_resp_data_len, len); |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 return(-1); |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 } |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 return(0); |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 } |