FreeCalypso > hg > fc-pcsc-tools
view simtool/sysmo.c @ 179:efe944a5c4e3
doc/Brute-force-search: update for data directory rename
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Tue, 02 Mar 2021 05:20:19 +0000 |
parents | c0cd0d4635bb |
children |
line wrap: on
line source
/* * This module implements special commands for programmable and * semi-programmable (made-up term for the version without ADM keys) * SIM cards made by Sysmocom. */ #include <sys/types.h> #include <string.h> #include <strings.h> #include <stdio.h> #include <stdlib.h> #include "simresp.h" #include "curfile.h" #include "file_id.h" cmd_verify_sjs1_adm1(argc, argv) char **argv; { u_char cmd[13]; int rc; /* UICC-style VERIFY PIN command APDU */ cmd[0] = 0x00; cmd[1] = 0x20; cmd[2] = 0x00; cmd[3] = 0x0A; cmd[4] = 8; rc = encode_pin_entry(argv[1], cmd + 5); if (rc < 0) return(rc); rc = apdu_exchange(cmd, 13); if (rc < 0) return(rc); if (sim_resp_sw != 0x9000) { fprintf(stderr, "bad SW response: %04X\n", sim_resp_sw); return(-1); } return(0); } cmd_fix_sysmo_msisdn() { int rc; unsigned n; u_char newrec[34]; rc = select_op(DF_TELECOM); if (rc < 0) return(rc); rc = select_op(EF_MSISDN); if (rc < 0) return(rc); rc = parse_ef_select_response(); if (rc < 0) return(rc); if (curfile_structure != 0x01) { fprintf(stderr, "error: EF_MSISDN is not linear fixed\n"); return(-1); } if (curfile_record_len != 34) { fprintf(stderr, "error: expected EF_MSISDN record length of 34 bytes, got %u\n", curfile_record_len); return(-1); } rc = readrec_op(1, 0x04, 34); if (rc < 0) return(rc); for (n = 0; n < 18; n++) { if (sim_resp_data[n] != 0xFF) { fprintf(stderr, "error: non-FF data in the first 18 bytes of alpha tag area\n"); return(-1); } } if (sim_resp_data[18] == 0xFF && sim_resp_data[19] == 0xFF) { printf( "last 2 bytes of alpha tag area are clear - already fixed?\n"); return(0); } if (sim_resp_data[18] != 0x07 || sim_resp_data[19] != 0x91) { fprintf(stderr, "error: bytes 18 & 19 don't match expected bogus programming\n"); return(-1); } memset(newrec, 0xFF, 34); memcpy(newrec + 20, sim_resp_data + 18, 8); return update_rec_op(1, 0x04, newrec, 34); }