comparison simtool/readcmd.c @ 1:2071b28cd0c7

simtool: first refactored version
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 11 Feb 2021 23:04:28 +0000
parents
children 5390dce9faa4
comparison
equal deleted inserted replaced
0:f7145c77b7fb 1:2071b28cd0c7
1 #include <sys/types.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include "simresp.h"
5 #include "curfile.h"
6
7 cmd_readbin(argc, argv)
8 char **argv;
9 {
10 unsigned offset, len;
11 int rc;
12
13 offset = strtoul(argv[1], 0, 0);
14 if (offset > 0xFFFF) {
15 fprintf(stderr, "error: offset argument is out of range\n");
16 return(-1);
17 }
18 len = strtoul(argv[2], 0, 0);
19 if (len < 1 || len > 256) {
20 fprintf(stderr, "error: length argument is out of range\n");
21 return(-1);
22 }
23 rc = readbin_op(offset, len);
24 if (rc < 0)
25 return(rc);
26 display_sim_resp_in_hex();
27 return(0);
28 }
29
30 cmd_readrec(argc, argv)
31 char **argv;
32 {
33 unsigned recno, len;
34 int rc;
35
36 recno = strtoul(argv[1], 0, 0);
37 if (recno < 1 || recno > 255) {
38 fprintf(stderr,
39 "error: record number argument is out of range\n");
40 return(-1);
41 }
42 if (argv[2]) {
43 len = strtoul(argv[2], 0, 0);
44 if (len < 1 || len > 255) {
45 fprintf(stderr,
46 "error: length argument is out of range\n");
47 return(-1);
48 }
49 } else {
50 if (!curfile_record_len) {
51 fprintf(stderr,
52 "error: no current file record length is available\n");
53 return(-1);
54 }
55 len = curfile_record_len;
56 }
57 rc = readrec_op(recno, 0x04, len);
58 if (rc < 0)
59 return(rc);
60 display_sim_resp_in_hex();
61 return(0);
62 }
63
64 cmd_readef(argc, argv)
65 char **argv;
66 {
67 int file_id, rc;
68 unsigned readlen;
69
70 if (isxdigit(argv[1][0]) && isxdigit(argv[1][1]) &&
71 isxdigit(argv[1][2]) && isxdigit(argv[1][3]) && !argv[1][4])
72 file_id = strtoul(argv[1], 0, 16);
73 else
74 file_id = find_symbolic_file_name(argv[1]);
75 if (file_id < 0) {
76 fprintf(stderr,
77 "error: file ID argument is not a hex value or a recognized symbolic name\n");
78 return(-1);
79 }
80 rc = select_op(file_id);
81 if (rc < 0)
82 return(rc);
83 rc = parse_ef_select_response();
84 if (rc < 0)
85 return(rc);
86 if (curfile_structure != 0x00) {
87 fprintf(stderr,
88 "error: readef command is only for transparent EFs\n");
89 return(-1);
90 }
91 printf("Transparent EF of %u byte(s)\n", curfile_total_size);
92 printf("File status: %02X\n", sim_resp_data[11]);
93 show_access_conditions("UPDATE", sim_resp_data[8] & 0xF);
94 show_access_conditions("READ & SEEK", sim_resp_data[8] >> 4);
95 show_access_conditions("INCREASE", sim_resp_data[9] >> 4);
96 show_access_conditions("INVALIDATE", sim_resp_data[10] & 0xF);
97 show_access_conditions("REHABILITATE", sim_resp_data[10] >> 4);
98 if (!curfile_total_size)
99 return(0);
100 readlen = curfile_total_size;
101 if (readlen > 256)
102 readlen = 256;
103 rc = readbin_op(0, readlen);
104 if (rc < 0)
105 return(rc);
106 display_sim_resp_in_hex();
107 return(0);
108 }