comparison uicc/readcmd.c @ 22:1b1468869ccf

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