FreeCalypso > hg > fc-pcsc-tools
comparison simtool/sysmo.c @ 1:2071b28cd0c7
simtool: first refactored version
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Thu, 11 Feb 2021 23:04:28 +0000 |
| parents | |
| children | c0cd0d4635bb |
comparison
equal
deleted
inserted
replaced
| 0:f7145c77b7fb | 1:2071b28cd0c7 |
|---|---|
| 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 "simresp.h" | |
| 13 #include "curfile.h" | |
| 14 #include "file_id.h" | |
| 15 | |
| 16 cmd_fix_sysmo_msisdn() | |
| 17 { | |
| 18 int rc; | |
| 19 unsigned n; | |
| 20 u_char newrec[34]; | |
| 21 | |
| 22 rc = select_op(DF_TELECOM); | |
| 23 if (rc < 0) | |
| 24 return(rc); | |
| 25 rc = select_op(EF_MSISDN); | |
| 26 if (rc < 0) | |
| 27 return(rc); | |
| 28 rc = parse_ef_select_response(); | |
| 29 if (rc < 0) | |
| 30 return(rc); | |
| 31 if (curfile_structure != 0x01) { | |
| 32 fprintf(stderr, "error: EF_MSISDN is not linear fixed\n"); | |
| 33 return(-1); | |
| 34 } | |
| 35 if (curfile_record_len != 34) { | |
| 36 fprintf(stderr, | |
| 37 "error: expected EF_MSISDN record length of 34 bytes, got %u\n", | |
| 38 curfile_record_len); | |
| 39 return(-1); | |
| 40 } | |
| 41 rc = readrec_op(1, 0x04, 34); | |
| 42 if (rc < 0) | |
| 43 return(rc); | |
| 44 for (n = 0; n < 18; n++) { | |
| 45 if (sim_resp_data[n] != 0xFF) { | |
| 46 fprintf(stderr, | |
| 47 "error: non-FF data in the first 18 bytes of alpha tag area\n"); | |
| 48 return(-1); | |
| 49 } | |
| 50 } | |
| 51 if (sim_resp_data[18] == 0xFF && sim_resp_data[19] == 0xFF) { | |
| 52 printf( | |
| 53 "last 2 bytes of alpha tag area are clear - already fixed?\n"); | |
| 54 return(0); | |
| 55 } | |
| 56 if (sim_resp_data[18] != 0x07 || sim_resp_data[19] != 0x91) { | |
| 57 fprintf(stderr, | |
| 58 "error: bytes 18 & 19 don't match expected bogus programming\n"); | |
| 59 return(-1); | |
| 60 } | |
| 61 memset(newrec, 0xFF, 34); | |
| 62 memcpy(newrec + 20, sim_resp_data + 18, 8); | |
| 63 return update_rec_op(1, 0x04, newrec, 34); | |
| 64 } |
