FreeCalypso > hg > fc-sim-tools
view simtool/grcard2ki.c @ 102:c2f18d7b0a1e
doc/Admin-write-commands: document write-hplmn-timer command
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 14 May 2022 23:20:38 +0000 |
parents | 9f1cc3174e45 |
children |
line wrap: on
line source
/* * This module implements special commands for the grcard.cn card model * which is known in the Osmocom community as GrcardSIM2: * * https://osmocom.org/projects/cellular-infrastructure/wiki/GrcardSIM2 * * FreeCalypso Community SIM model FCSIM1 is GrcardSIM2, and so are * historical sysmoSIM-GR2 and 30C3 cards. */ #include <sys/types.h> #include <stdio.h> #include "simresp.h" #include "curfile.h" #include "file_id.h" static select_ef_weki() { int rc; rc = select_op(DF_GSM); if (rc < 0) return(rc); rc = select_op(0x0001); /* proprietary EF */ if (rc < 0) return(rc); rc = parse_ef_select_response(); if (rc < 0) return(rc); if (curfile_structure != 0x00 || curfile_total_size != 35) { fprintf(stderr, "error: EF_WEKI is not a transparent EF of 35 bytes\n"); return(-1); } return(0); } cmd_grcard2_set_comp128(argc, argv) char **argv; { int rc; unsigned code, upper; u_char magic_byte; if (argv[1][0] < '1' || argv[1][0] > '3' || argv[1][1]) { fprintf(stderr, "error: invalid COMP128 version argument\n"); return(-1); } code = argv[1][0] - '1'; if (argv[2]) { upper = strtoul(argv[2], 0, 16); if ((upper & 3) || (upper > 0xFC)) { fprintf(stderr, "error: invalid upper bits argument\n"); return(-1); } } rc = select_ef_weki(); if (rc < 0) return(rc); if (argv[2]) magic_byte = upper; else { rc = readbin_op(2, 1); if (rc < 0) return(rc); magic_byte = sim_resp_data[0] & 0xFC; } magic_byte |= code; return update_bin_op(2, &magic_byte, 1); } cmd_grcard2_set_ki(argc, argv) char **argv; { u_char ki[16]; int rc; rc = decode_hex_data_from_string(argv[1], ki, 16, 16); if (rc < 0) return(rc); rc = select_ef_weki(); if (rc < 0) return(rc); return update_bin_op(3, ki, 16); }