annotate uicc/readcmd.c @ 52:2f697a8c5196

fc-simtool pb-* commands support new EF_MBDN phonebook
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 13 Feb 2021 05:33:46 +0000
parents 1b1468869ccf
children f1836c8d36cb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
22
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 #include <sys/types.h>
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 #include <ctype.h>
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 #include <stdio.h>
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 #include <stdlib.h>
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include "simresp.h"
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 extern unsigned last_sel_file_record_len;
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 cmd_readbin(argc, argv)
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 char **argv;
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 {
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 unsigned offset, len;
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 int rc;
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 offset = strtoul(argv[1], 0, 0);
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 if (offset > 0x7FFF) {
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 fprintf(stderr, "error: offset argument is out of range\n");
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 return(-1);
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 }
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 len = strtoul(argv[2], 0, 0);
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 if (len < 1 || len > 256) {
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 fprintf(stderr, "error: length argument is out of range\n");
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 return(-1);
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 }
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 rc = readbin_op(offset, len);
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 if (rc < 0)
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 return(rc);
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 display_sim_resp_in_hex();
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 return(0);
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 }
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 cmd_readrec(argc, argv)
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 char **argv;
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 {
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 unsigned recno, len;
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 int rc;
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 recno = strtoul(argv[1], 0, 0);
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 if (recno < 1 || recno > 255) {
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 fprintf(stderr,
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 "error: record number argument is out of range\n");
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 return(-1);
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 }
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 if (argv[2]) {
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 len = strtoul(argv[2], 0, 0);
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 if (len < 1 || len > 255) {
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 fprintf(stderr,
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 "error: length argument is out of range\n");
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 return(-1);
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 }
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 } else {
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 if (!last_sel_file_record_len) {
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 fprintf(stderr,
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 "error: no current file record length is available\n");
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 return(-1);
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 }
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 len = last_sel_file_record_len;
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 }
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 rc = readrec_op(recno, 0x04, len);
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 if (rc < 0)
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 return(rc);
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 display_sim_resp_in_hex();
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 return(0);
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 }
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 cmd_readef(argc, argv)
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 char **argv;
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 {
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 int file_id, rc;
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 unsigned file_len, readlen;
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 if (isxdigit(argv[1][0]) && isxdigit(argv[1][1]) &&
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 isxdigit(argv[1][2]) && isxdigit(argv[1][3]) && !argv[1][4])
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 file_id = strtoul(argv[1], 0, 16);
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 else
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 file_id = find_symbolic_file_name(argv[1]);
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 if (file_id < 0) {
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 fprintf(stderr,
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 "error: file ID argument is not a hex value or a recognized symbolic name\n");
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 return(-1);
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 }
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 rc = select_op(file_id);
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 if (rc < 0)
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 return(rc);
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 rc = select_resp_get_transparent(&file_len);
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 if (rc < 0)
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 return(rc);
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 printf("Transparent EF of %u byte(s)\n", file_len);
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 if (!file_len)
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 return(0);
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 readlen = file_len;
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 if (readlen > 256)
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 readlen = 256;
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 rc = readbin_op(0, readlen);
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 if (rc < 0)
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 return(rc);
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 display_sim_resp_in_hex();
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 return(0);
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 }