annotate uicc/readcmd.c @ 158:65a2a96386cd

fc-uicc-tool: hex string parsing with min and max length, matching fc-simtool
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 07 Feb 2021 04:00:27 +0000
parents 429a8f80426e
children 19b96c52348f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 cmd_readbin(argc, argv)
f3bdefbeae38 fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 char **argv;
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 unsigned offset, len;
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 offset = strtoul(argv[1], 0, 0);
f3bdefbeae38 fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 if (offset > 0x7FFF) {
f3bdefbeae38 fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 fprintf(stderr, "error: offset argument is out of range\n");
f3bdefbeae38 fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 return(-1);
f3bdefbeae38 fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 }
f3bdefbeae38 fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 len = strtoul(argv[2], 0, 0);
f3bdefbeae38 fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 if (len < 1 || len > 256) {
f3bdefbeae38 fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 fprintf(stderr, "error: length argument is out of range\n");
f3bdefbeae38 fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 return(-1);
f3bdefbeae38 fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 }
f3bdefbeae38 fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 rc = readbin_op(offset, len);
f3bdefbeae38 fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 if (rc < 0)
f3bdefbeae38 fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 return(rc);
f3bdefbeae38 fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 display_sim_resp_in_hex();
f3bdefbeae38 fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 return(0);
f3bdefbeae38 fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 }
f3bdefbeae38 fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30
f3bdefbeae38 fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 cmd_readrec(argc, argv)
f3bdefbeae38 fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 char **argv;
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 unsigned recno, len;
f3bdefbeae38 fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 int rc;
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 recno = strtoul(argv[1], 0, 0);
f3bdefbeae38 fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 if (recno < 1 || recno > 255) {
f3bdefbeae38 fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 fprintf(stderr,
f3bdefbeae38 fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 "error: record number argument is out of range\n");
f3bdefbeae38 fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 return(-1);
f3bdefbeae38 fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 }
144
429a8f80426e fc-uicc-tool: catch record length from manual select
Mychaela Falconia <falcon@freecalypso.org>
parents: 133
diff changeset
43 if (argv[2]) {
429a8f80426e fc-uicc-tool: catch record length from manual select
Mychaela Falconia <falcon@freecalypso.org>
parents: 133
diff changeset
44 len = strtoul(argv[2], 0, 0);
429a8f80426e fc-uicc-tool: catch record length from manual select
Mychaela Falconia <falcon@freecalypso.org>
parents: 133
diff changeset
45 if (len < 1 || len > 255) {
429a8f80426e fc-uicc-tool: catch record length from manual select
Mychaela Falconia <falcon@freecalypso.org>
parents: 133
diff changeset
46 fprintf(stderr,
429a8f80426e fc-uicc-tool: catch record length from manual select
Mychaela Falconia <falcon@freecalypso.org>
parents: 133
diff changeset
47 "error: length argument is out of range\n");
429a8f80426e fc-uicc-tool: catch record length from manual select
Mychaela Falconia <falcon@freecalypso.org>
parents: 133
diff changeset
48 return(-1);
429a8f80426e fc-uicc-tool: catch record length from manual select
Mychaela Falconia <falcon@freecalypso.org>
parents: 133
diff changeset
49 }
429a8f80426e fc-uicc-tool: catch record length from manual select
Mychaela Falconia <falcon@freecalypso.org>
parents: 133
diff changeset
50 } else {
429a8f80426e fc-uicc-tool: catch record length from manual select
Mychaela Falconia <falcon@freecalypso.org>
parents: 133
diff changeset
51 if (!last_sel_file_record_len) {
429a8f80426e fc-uicc-tool: catch record length from manual select
Mychaela Falconia <falcon@freecalypso.org>
parents: 133
diff changeset
52 fprintf(stderr,
429a8f80426e fc-uicc-tool: catch record length from manual select
Mychaela Falconia <falcon@freecalypso.org>
parents: 133
diff changeset
53 "error: no current file record length is available\n");
429a8f80426e fc-uicc-tool: catch record length from manual select
Mychaela Falconia <falcon@freecalypso.org>
parents: 133
diff changeset
54 return(-1);
429a8f80426e fc-uicc-tool: catch record length from manual select
Mychaela Falconia <falcon@freecalypso.org>
parents: 133
diff changeset
55 }
429a8f80426e fc-uicc-tool: catch record length from manual select
Mychaela Falconia <falcon@freecalypso.org>
parents: 133
diff changeset
56 len = last_sel_file_record_len;
133
f3bdefbeae38 fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 }
f3bdefbeae38 fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 rc = readrec_op(recno, 0x04, len);
f3bdefbeae38 fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 if (rc < 0)
f3bdefbeae38 fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 return(rc);
f3bdefbeae38 fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 display_sim_resp_in_hex();
f3bdefbeae38 fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 return(0);
f3bdefbeae38 fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 }