annotate uicc/readcmd.c @ 90:3afa61d98961

fc-uicc-tool: savebin ported over from fc-simtool
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 11 Apr 2021 04:32:26 +0000
parents db131929ee96
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
89
db131929ee96 fc-uicc-tool: extended readef ported over from fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
1 /*
db131929ee96 fc-uicc-tool: extended readef ported over from fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
2 * This module implements elementary low-level readbin and readrec commands.
db131929ee96 fc-uicc-tool: extended readef ported over from fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
3 */
db131929ee96 fc-uicc-tool: extended readef ported over from fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
4
15
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <sys/types.h>
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <stdio.h>
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <stdlib.h>
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include "simresp.h"
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 extern unsigned last_sel_file_record_len;
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 cmd_readbin(argc, argv, outf)
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 char **argv;
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 FILE *outf;
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 {
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 unsigned offset, len;
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 int rc;
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 offset = strtoul(argv[1], 0, 0);
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 if (offset > 0x7FFF) {
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 fprintf(stderr, "error: offset argument is out of range\n");
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 return(-1);
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 }
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 len = strtoul(argv[2], 0, 0);
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 if (len < 1 || len > 256) {
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 fprintf(stderr, "error: length argument is out of range\n");
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 return(-1);
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 }
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 rc = readbin_op(offset, len);
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 if (rc < 0)
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 return(rc);
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 display_sim_resp_in_hex(outf);
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 return(0);
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 }
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 cmd_readrec(argc, argv, outf)
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 char **argv;
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 FILE *outf;
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 {
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 unsigned recno, len;
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 int rc;
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 recno = strtoul(argv[1], 0, 0);
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 if (recno < 1 || recno > 255) {
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 fprintf(stderr,
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 "error: record number argument is out of range\n");
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 return(-1);
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 }
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 if (argv[2]) {
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 len = strtoul(argv[2], 0, 0);
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 if (len < 1 || len > 255) {
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 fprintf(stderr,
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 "error: length argument is out of range\n");
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 return(-1);
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 }
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 } else {
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 if (!last_sel_file_record_len) {
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 fprintf(stderr,
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 "error: no current file record length is available\n");
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 return(-1);
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 }
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 len = last_sel_file_record_len;
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 }
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 rc = readrec_op(recno, 0x04, len);
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 if (rc < 0)
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 return(rc);
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 display_sim_resp_in_hex(outf);
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 return(0);
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 }