annotate simtool/sysmo.c @ 176:fb2f6497ba53 default tip

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