comparison simtool/sysmo.c @ 114:34c090f35515

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