annotate uicc/savebin.c @ 93:6041c601304d

fcsim1-mkprov: revert OTA key addition It appears that GrcardSIM2 cards (which is what we got for FCSIM1) do not support OTA after all, contrary to what we were previously led to believe by some tech support emails from Grcard - apparently those support emails and OTA descriptions referred to some other card model(s).
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 21 Apr 2021 05:38:39 +0000
parents 3afa61d98961
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
90
3afa61d98961 fc-uicc-tool: savebin ported over from fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
2 * This module implements the savebin command for saving SIM file content
10
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * in UNIX host files.
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 */
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <sys/types.h>
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <ctype.h>
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdio.h>
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <stdlib.h>
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include "simresp.h"
90
3afa61d98961 fc-uicc-tool: savebin ported over from fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
11 #include "efstruct.h"
10
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 static
90
3afa61d98961 fc-uicc-tool: savebin ported over from fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
14 savebin_transparent(efs, outf)
3afa61d98961 fc-uicc-tool: savebin ported over from fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
15 struct ef_struct *efs;
10
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 FILE *outf;
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 {
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 unsigned off, cc;
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 int rc;
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20
90
3afa61d98961 fc-uicc-tool: savebin ported over from fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
21 for (off = 0; off < efs->total_size; off += cc) {
3afa61d98961 fc-uicc-tool: savebin ported over from fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
22 cc = efs->total_size - off;
10
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 if (cc > 256)
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 cc = 256;
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 rc = readbin_op(off, cc);
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 if (rc < 0)
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 return(rc);
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 fwrite(sim_resp_data, 1, cc, outf);
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 }
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 return(0);
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 }
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 static
90
3afa61d98961 fc-uicc-tool: savebin ported over from fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
34 savebin_records(efs, outf)
3afa61d98961 fc-uicc-tool: savebin ported over from fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
35 struct ef_struct *efs;
10
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 FILE *outf;
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 {
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 unsigned recno;
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 int rc;
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40
90
3afa61d98961 fc-uicc-tool: savebin ported over from fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
41 for (recno = 1; recno <= efs->record_count; recno++) {
3afa61d98961 fc-uicc-tool: savebin ported over from fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
42 rc = readrec_op(recno, 0x04, efs->record_len);
10
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 if (rc < 0)
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 return(rc);
90
3afa61d98961 fc-uicc-tool: savebin ported over from fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
45 fwrite(sim_resp_data, efs->record_len, 1, outf);
10
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 }
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 return(0);
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 }
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 cmd_savebin(argc, argv)
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 char **argv;
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 {
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 int file_id, rc;
90
3afa61d98961 fc-uicc-tool: savebin ported over from fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
54 struct ef_struct efs;
10
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 FILE *of;
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 if (isxdigit(argv[1][0]) && isxdigit(argv[1][1]) &&
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 isxdigit(argv[1][2]) && isxdigit(argv[1][3]) && !argv[1][4])
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 file_id = strtoul(argv[1], 0, 16);
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 else
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 file_id = find_symbolic_file_name(argv[1]);
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 if (file_id < 0) {
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 fprintf(stderr,
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 "error: file ID argument is not a hex value or a recognized symbolic name\n");
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 return(-1);
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 }
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 rc = select_op(file_id);
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 if (rc < 0)
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 return(rc);
90
3afa61d98961 fc-uicc-tool: savebin ported over from fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
70 rc = select_resp_get_ef_struct(&efs);
10
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 if (rc < 0)
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 return(rc);
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 of = fopen(argv[2], "w");
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 if (!of) {
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 perror(argv[2]);
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 return(-1);
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 }
90
3afa61d98961 fc-uicc-tool: savebin ported over from fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
78 switch (efs.structure) {
3afa61d98961 fc-uicc-tool: savebin ported over from fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
79 case 0x01:
10
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 /* transparent */
90
3afa61d98961 fc-uicc-tool: savebin ported over from fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
81 rc = savebin_transparent(&efs, of);
10
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 break;
90
3afa61d98961 fc-uicc-tool: savebin ported over from fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
83 case 0x02:
3afa61d98961 fc-uicc-tool: savebin ported over from fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
84 case 0x06:
10
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 /* record-based */
90
3afa61d98961 fc-uicc-tool: savebin ported over from fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
86 rc = savebin_records(&efs, of);
10
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 break;
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 }
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 fclose(of);
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 return(rc);
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 }