FreeCalypso > hg > fc-pcsc-tools
view simtool/plmnsel.c @ 99:d2e800abd257
fc-simtool plmnsel-write command implemented
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 17 Feb 2021 22:43:18 +0000 |
parents | 4eb447be01c0 |
children | a75c0aafb367 |
line wrap: on
line source
/* * This module implements commands for working with EF_PLMNsel. */ #include <sys/types.h> #include <stdio.h> #include <stdlib.h> #include "simresp.h" #include "curfile.h" #include "file_id.h" static select_ef_plmnsel() { int rc; rc = select_op(DF_GSM); if (rc < 0) return(rc); rc = select_op(EF_PLMNsel); if (rc < 0) return(rc); rc = parse_ef_select_response(); if (rc < 0) return(rc); if (curfile_structure != 0x00) { fprintf(stderr, "error: EF_PLMNsel is not transparent\n"); return(-1); } if (curfile_total_size < 24) { fprintf(stderr, "error: EF_PLMNsel is shorter than spec minimum of 24 bytes\n"); return(-1); } if (curfile_total_size > 255) { fprintf(stderr, "error: EF_PLMNsel is longer than our 255 byte limit\n"); return(-1); } if (curfile_total_size % 3) { fprintf(stderr, "error: EF_PLMNsel length is not a multiple of 3 bytes\n"); return(-1); } return(0); } cmd_plmnsel_dump() { int rc, gap_flag; u_char *dp, *endp; char ascbuf[8]; unsigned idx, linelen; rc = select_ef_plmnsel(); if (rc < 0) return(rc); rc = readbin_op(0, curfile_total_size); if (rc < 0) return(rc); dp = sim_resp_data; endp = sim_resp_data + sim_resp_data_len; gap_flag = 0; linelen = 0; for (idx = 0; dp < endp; idx++, dp += 3) { if (dp[0] == 0xFF && dp[1] == 0xFF && dp[2] == 0xFF) { gap_flag = 1; continue; } if (gap_flag) { if (linelen) { putchar('\n'); linelen = 0; } printf("GAP, continuing at index %u:\n", idx); gap_flag = 0; } if (linelen >= 10) { putchar('\n'); linelen = 0; } decode_plmn_3bytes(dp, ascbuf, 1); if (linelen) putchar(' '); fputs(ascbuf, stdout); linelen++; } if (linelen) putchar('\n'); return(0); } cmd_plmnsel_write(argc, argv) char **argv; { int rc; unsigned idx; u_char rec[3]; rc = select_ef_plmnsel(); if (rc < 0) return(rc); idx = strtoul(argv[1], 0, 0); if (idx >= curfile_total_size / 3) { fprintf(stderr, "error: specified index is out of range\n"); return(-1); } rc = encode_plmn_3bytes(argv[2], rec); if (rc < 0) return(rc); return update_bin_op(idx * 3, rec, 3); }