FreeCalypso > hg > freecalypso-hwlab
annotate uicc/writecmd.c @ 151:d515cfbb3f39
fc-simtool: hex string parsing: add minimum length parameter
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 07 Feb 2021 00:18:30 +0000 |
parents | 14dee03e9675 |
children | 65a2a96386cd |
rev | line source |
---|---|
145
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 #include <sys/types.h> |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 #include <stdio.h> |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 #include <stdlib.h> |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 #include <pcsclite.h> |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <winscard.h> |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include "globals.h" |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 cmd_update_bin(argc, argv) |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 char **argv; |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 { |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 unsigned offset, len; |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 u_char data[255]; |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 int rc; |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 offset = strtoul(argv[1], 0, 0); |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 if (offset > 0x7FFF) { |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 fprintf(stderr, "error: offset argument is out of range\n"); |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 return(-1); |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 } |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 rc = read_hex_data_file(argv[2], data); |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 if (rc < 0) |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 return(rc); |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 len = rc; |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 return update_bin_op(offset, data, len); |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 } |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 cmd_update_bin_imm(argc, argv) |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 char **argv; |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 { |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 unsigned offset, len; |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 u_char data[255]; |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 int rc; |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 offset = strtoul(argv[1], 0, 0); |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 if (offset > 0x7FFF) { |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 fprintf(stderr, "error: offset argument is out of range\n"); |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 return(-1); |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 } |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 rc = decode_hex_data_from_string(argv[2], data, 255); |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 if (rc < 0) |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 return(rc); |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 len = rc; |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 return update_bin_op(offset, data, len); |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 } |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 cmd_update_rec(argc, argv) |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 char **argv; |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 { |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 unsigned recno; |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 u_char data[255]; |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 int rc; |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 if (!last_sel_file_record_len) { |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 fprintf(stderr, "error: no record-based file selected\n"); |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 return(-1); |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 } |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 recno = strtoul(argv[1], 0, 0); |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 if (recno < 1 || recno > 255) { |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 fprintf(stderr, |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 "error: record number argument is out of range\n"); |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 return(-1); |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 } |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 rc = read_hex_data_file(argv[2], data); |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 if (rc < 0) |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 return(rc); |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 if (rc != last_sel_file_record_len) { |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 fprintf(stderr, "error: hex data length != EF record length\n"); |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 return(-1); |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 } |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 return update_rec_op(recno, 0x04, data, last_sel_file_record_len); |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 } |