FreeCalypso > hg > freecalypso-hwlab
annotate uicc/hexread.c @ 154:ed34c8b7e2c9
fc-simtool: grcard2-set-pin[12] commands implemented
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 07 Feb 2021 02:29:07 +0000 |
parents | 14dee03e9675 |
children |
rev | line source |
---|---|
145
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This module contains the function for reading hex files, |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * to be used in the implementation of manual write commands. |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 */ |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <sys/types.h> |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <ctype.h> |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <string.h> |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <strings.h> |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <stdio.h> |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <stdlib.h> |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 read_hex_data_file(filename, databuf) |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 char *filename; |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 u_char *databuf; |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 { |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 FILE *inf; |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 unsigned count; |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 int c, c2; |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 inf = fopen(filename, "r"); |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 if (!inf) { |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 perror(filename); |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 return(-1); |
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 for (count = 0; ; count++) { |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 do |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 c = getc(inf); |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 while (isspace(c)); |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 if (c < 0) |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 break; |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 if (!isxdigit(c)) { |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 inv_input: fprintf(stderr, "%s: invalid hex file input\n", |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 filename); |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 fclose(inf); |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 return(-1); |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 } |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 c2 = getc(inf); |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 if (!isxdigit(c2)) |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 goto inv_input; |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 if (count >= 255) { |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 fprintf(stderr, "%s: hex input data is too long\n", |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 filename); |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 fclose(inf); |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 return(-1); |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 } |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 databuf[count] = (decode_hex_digit(c) << 4) | |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 decode_hex_digit(c2); |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 } |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 fclose(inf); |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 if (!count) { |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 fprintf(stderr, "%s: no hex data input found\n", filename); |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 return(-1); |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 } |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 return(count); |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 } |