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