comparison uicc/sysmo.c @ 159:a5e2b6e3bdf7

fc-uicc-tool: fix-sysmo-msisdn command ported over
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 07 Feb 2021 04:07:24 +0000
parents
children
comparison
equal deleted inserted replaced
158:65a2a96386cd 159:a5e2b6e3bdf7
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 unsigned record_len, record_count;
23
24 rc = select_op(FILEID_MF);
25 if (rc < 0)
26 return(rc);
27 rc = select_op(DF_TELECOM);
28 if (rc < 0)
29 return(rc);
30 rc = select_op(EF_MSISDN);
31 if (rc < 0)
32 return(rc);
33 rc = select_resp_get_linear_fixed(&record_len, &record_count);
34 if (rc < 0)
35 return(rc);
36 if (record_len != 34) {
37 fprintf(stderr,
38 "error: expected EF_MSISDN record length of 34 bytes, got %u\n",
39 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 }