annotate uicc/hlread.c @ 144:60411fd4b803

simtool code: cmd_get_response() factored out of stktest.c
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 25 Feb 2021 05:44:27 +0000
parents ede661d78730
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
22
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This module implements some high-level or user-friendly read commands.
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 */
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <sys/types.h>
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <stdio.h>
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include "simresp.h"
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include "file_id.h"
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9
133
ede661d78730 fc-uicc-tool: command shell features match fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents: 56
diff changeset
10 cmd_iccid(argc, argv, outf)
ede661d78730 fc-uicc-tool: command shell features match fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents: 56
diff changeset
11 char **argv;
ede661d78730 fc-uicc-tool: command shell features match fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents: 56
diff changeset
12 FILE *outf;
22
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 {
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 int rc;
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 unsigned len;
56
d4b5a6e547ca fc-uicc-tool iccid command: same change as in fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents: 22
diff changeset
16 char buf[21], *cp;
22
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 rc = select_op(FILEID_MF);
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 if (rc < 0)
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 return(rc);
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 rc = select_op(EF_ICCID);
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 if (rc < 0)
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 return(rc);
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 rc = select_resp_get_transparent(&len);
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 if (rc < 0)
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 return(rc);
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 if (len != 10) {
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 fprintf(stderr, "error: expected transparent EF of 10 bytes\n");
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 return(-1);
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 }
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 rc = readbin_op(0, 10);
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 if (rc < 0)
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 return(rc);
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 decode_reversed_nibbles(sim_resp_data, 10, buf);
56
d4b5a6e547ca fc-uicc-tool iccid command: same change as in fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents: 22
diff changeset
35 for (cp = buf + 20; (cp > buf + 1) && (cp[-1] == 'F'); cp--)
d4b5a6e547ca fc-uicc-tool iccid command: same change as in fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents: 22
diff changeset
36 ;
d4b5a6e547ca fc-uicc-tool iccid command: same change as in fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents: 22
diff changeset
37 *cp = '\0';
133
ede661d78730 fc-uicc-tool: command shell features match fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents: 56
diff changeset
38 fprintf(outf, "%s\n", buf);
22
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 return(0);
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 }