annotate uicc/sysmo.c @ 170:f9ca05460238

rm eeproms/dumps: moved to fc-usbser-tools/artifacts
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 11 Sep 2023 05:13:54 +0000
parents a5e2b6e3bdf7
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
159
a5e2b6e3bdf7 fc-uicc-tool: fix-sysmo-msisdn command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
a5e2b6e3bdf7 fc-uicc-tool: fix-sysmo-msisdn command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This module implements special commands for programmable and
a5e2b6e3bdf7 fc-uicc-tool: fix-sysmo-msisdn command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * semi-programmable (made-up term for the version without ADM keys)
a5e2b6e3bdf7 fc-uicc-tool: fix-sysmo-msisdn command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 * SIM cards made by Sysmocom.
a5e2b6e3bdf7 fc-uicc-tool: fix-sysmo-msisdn command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 */
a5e2b6e3bdf7 fc-uicc-tool: fix-sysmo-msisdn command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6
a5e2b6e3bdf7 fc-uicc-tool: fix-sysmo-msisdn command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <sys/types.h>
a5e2b6e3bdf7 fc-uicc-tool: fix-sysmo-msisdn command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <string.h>
a5e2b6e3bdf7 fc-uicc-tool: fix-sysmo-msisdn command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <strings.h>
a5e2b6e3bdf7 fc-uicc-tool: fix-sysmo-msisdn command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <stdio.h>
a5e2b6e3bdf7 fc-uicc-tool: fix-sysmo-msisdn command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <stdlib.h>
a5e2b6e3bdf7 fc-uicc-tool: fix-sysmo-msisdn command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include <pcsclite.h>
a5e2b6e3bdf7 fc-uicc-tool: fix-sysmo-msisdn command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include <winscard.h>
a5e2b6e3bdf7 fc-uicc-tool: fix-sysmo-msisdn command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 #include "globals.h"
a5e2b6e3bdf7 fc-uicc-tool: fix-sysmo-msisdn command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 #include "file_id.h"
a5e2b6e3bdf7 fc-uicc-tool: fix-sysmo-msisdn command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16
a5e2b6e3bdf7 fc-uicc-tool: fix-sysmo-msisdn command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 cmd_fix_sysmo_msisdn()
a5e2b6e3bdf7 fc-uicc-tool: fix-sysmo-msisdn command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 {
a5e2b6e3bdf7 fc-uicc-tool: fix-sysmo-msisdn command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 int rc;
a5e2b6e3bdf7 fc-uicc-tool: fix-sysmo-msisdn command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 unsigned n;
a5e2b6e3bdf7 fc-uicc-tool: fix-sysmo-msisdn command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 u_char newrec[34];
a5e2b6e3bdf7 fc-uicc-tool: fix-sysmo-msisdn command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 unsigned record_len, record_count;
a5e2b6e3bdf7 fc-uicc-tool: fix-sysmo-msisdn command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23
a5e2b6e3bdf7 fc-uicc-tool: fix-sysmo-msisdn command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 rc = select_op(FILEID_MF);
a5e2b6e3bdf7 fc-uicc-tool: fix-sysmo-msisdn command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 if (rc < 0)
a5e2b6e3bdf7 fc-uicc-tool: fix-sysmo-msisdn command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 return(rc);
a5e2b6e3bdf7 fc-uicc-tool: fix-sysmo-msisdn command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 rc = select_op(DF_TELECOM);
a5e2b6e3bdf7 fc-uicc-tool: fix-sysmo-msisdn command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 if (rc < 0)
a5e2b6e3bdf7 fc-uicc-tool: fix-sysmo-msisdn command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 return(rc);
a5e2b6e3bdf7 fc-uicc-tool: fix-sysmo-msisdn command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 rc = select_op(EF_MSISDN);
a5e2b6e3bdf7 fc-uicc-tool: fix-sysmo-msisdn command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 if (rc < 0)
a5e2b6e3bdf7 fc-uicc-tool: fix-sysmo-msisdn command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 return(rc);
a5e2b6e3bdf7 fc-uicc-tool: fix-sysmo-msisdn command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 rc = select_resp_get_linear_fixed(&record_len, &record_count);
a5e2b6e3bdf7 fc-uicc-tool: fix-sysmo-msisdn command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 if (rc < 0)
a5e2b6e3bdf7 fc-uicc-tool: fix-sysmo-msisdn command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 return(rc);
a5e2b6e3bdf7 fc-uicc-tool: fix-sysmo-msisdn command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 if (record_len != 34) {
a5e2b6e3bdf7 fc-uicc-tool: fix-sysmo-msisdn command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 fprintf(stderr,
a5e2b6e3bdf7 fc-uicc-tool: fix-sysmo-msisdn command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 "error: expected EF_MSISDN record length of 34 bytes, got %u\n",
a5e2b6e3bdf7 fc-uicc-tool: fix-sysmo-msisdn command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 record_len);
a5e2b6e3bdf7 fc-uicc-tool: fix-sysmo-msisdn command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 return(-1);
a5e2b6e3bdf7 fc-uicc-tool: fix-sysmo-msisdn command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 }
a5e2b6e3bdf7 fc-uicc-tool: fix-sysmo-msisdn command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 rc = readrec_op(1, 0x04, 34);
a5e2b6e3bdf7 fc-uicc-tool: fix-sysmo-msisdn command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 if (rc < 0)
a5e2b6e3bdf7 fc-uicc-tool: fix-sysmo-msisdn command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 return(rc);
a5e2b6e3bdf7 fc-uicc-tool: fix-sysmo-msisdn command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 for (n = 0; n < 18; n++) {
a5e2b6e3bdf7 fc-uicc-tool: fix-sysmo-msisdn command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 if (sim_resp_data[n] != 0xFF) {
a5e2b6e3bdf7 fc-uicc-tool: fix-sysmo-msisdn command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 fprintf(stderr,
a5e2b6e3bdf7 fc-uicc-tool: fix-sysmo-msisdn command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 "error: non-FF data in the first 18 bytes of alpha tag area\n");
a5e2b6e3bdf7 fc-uicc-tool: fix-sysmo-msisdn command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 return(-1);
a5e2b6e3bdf7 fc-uicc-tool: fix-sysmo-msisdn command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 }
a5e2b6e3bdf7 fc-uicc-tool: fix-sysmo-msisdn command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 }
a5e2b6e3bdf7 fc-uicc-tool: fix-sysmo-msisdn command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 if (sim_resp_data[18] == 0xFF && sim_resp_data[19] == 0xFF) {
a5e2b6e3bdf7 fc-uicc-tool: fix-sysmo-msisdn command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 printf(
a5e2b6e3bdf7 fc-uicc-tool: fix-sysmo-msisdn command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 "last 2 bytes of alpha tag area are clear - already fixed?\n");
a5e2b6e3bdf7 fc-uicc-tool: fix-sysmo-msisdn command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 return(0);
a5e2b6e3bdf7 fc-uicc-tool: fix-sysmo-msisdn command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 }
a5e2b6e3bdf7 fc-uicc-tool: fix-sysmo-msisdn command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 if (sim_resp_data[18] != 0x07 || sim_resp_data[19] != 0x91) {
a5e2b6e3bdf7 fc-uicc-tool: fix-sysmo-msisdn command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 fprintf(stderr,
a5e2b6e3bdf7 fc-uicc-tool: fix-sysmo-msisdn command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 "error: bytes 18 & 19 don't match expected bogus programming\n");
a5e2b6e3bdf7 fc-uicc-tool: fix-sysmo-msisdn command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 return(-1);
a5e2b6e3bdf7 fc-uicc-tool: fix-sysmo-msisdn command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 }
a5e2b6e3bdf7 fc-uicc-tool: fix-sysmo-msisdn command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 memset(newrec, 0xFF, 34);
a5e2b6e3bdf7 fc-uicc-tool: fix-sysmo-msisdn command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 memcpy(newrec + 20, sim_resp_data + 18, 8);
a5e2b6e3bdf7 fc-uicc-tool: fix-sysmo-msisdn command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 return update_rec_op(1, 0x04, newrec, 34);
a5e2b6e3bdf7 fc-uicc-tool: fix-sysmo-msisdn command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 }