FreeCalypso > hg > fc-sim-tools
annotate uicc/hlread.c @ 103:3477438b5706 default tip
new fc-simtool command script: oper-sim-test
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 06 Aug 2022 16:34:43 +0000 |
parents | 97646b363eaa |
children |
rev | line source |
---|---|
15
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This module implements some high-level or user-friendly read commands. |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 */ |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <sys/types.h> |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <stdio.h> |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include "simresp.h" |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include "file_id.h" |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 |
61
97646b363eaa
fc-uicc-tool: sws-lookup and sws-auth-* commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
10 retrieve_iccid(buf) |
97646b363eaa
fc-uicc-tool: sws-lookup and sws-auth-* commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
11 char *buf; |
15
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 { |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 int rc; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 unsigned len; |
61
97646b363eaa
fc-uicc-tool: sws-lookup and sws-auth-* commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
15 char *cp; |
15
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 rc = select_op(FILEID_MF); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 if (rc < 0) |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 return(rc); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 rc = select_op(EF_ICCID); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 if (rc < 0) |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 return(rc); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 rc = select_resp_get_transparent(&len); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 if (rc < 0) |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 return(rc); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 if (len != 10) { |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 fprintf(stderr, "error: expected transparent EF of 10 bytes\n"); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 return(-1); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 } |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 rc = readbin_op(0, 10); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 if (rc < 0) |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 return(rc); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 decode_reversed_nibbles(sim_resp_data, 10, buf); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 for (cp = buf + 20; (cp > buf + 1) && (cp[-1] == 'F'); cp--) |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 ; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 *cp = '\0'; |
61
97646b363eaa
fc-uicc-tool: sws-lookup and sws-auth-* commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
37 return(0); |
97646b363eaa
fc-uicc-tool: sws-lookup and sws-auth-* commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
38 } |
97646b363eaa
fc-uicc-tool: sws-lookup and sws-auth-* commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
39 |
97646b363eaa
fc-uicc-tool: sws-lookup and sws-auth-* commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
40 cmd_iccid(argc, argv, outf) |
97646b363eaa
fc-uicc-tool: sws-lookup and sws-auth-* commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
41 char **argv; |
97646b363eaa
fc-uicc-tool: sws-lookup and sws-auth-* commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
42 FILE *outf; |
97646b363eaa
fc-uicc-tool: sws-lookup and sws-auth-* commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
43 { |
97646b363eaa
fc-uicc-tool: sws-lookup and sws-auth-* commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
44 int rc; |
97646b363eaa
fc-uicc-tool: sws-lookup and sws-auth-* commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
45 char buf[21]; |
97646b363eaa
fc-uicc-tool: sws-lookup and sws-auth-* commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
46 |
97646b363eaa
fc-uicc-tool: sws-lookup and sws-auth-* commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
47 rc = retrieve_iccid(buf); |
97646b363eaa
fc-uicc-tool: sws-lookup and sws-auth-* commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
48 if (rc < 0) |
97646b363eaa
fc-uicc-tool: sws-lookup and sws-auth-* commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
49 return(rc); |
15
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 fprintf(outf, "%s\n", buf); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 return(0); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 } |