FreeCalypso > hg > fc-pcsc-tools
view simtool/plmnsel.c @ 58:1861d9fb7751
fc-simtool dump-lnd command implemented
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 13 Feb 2021 21:40:38 +0000 |
parents | 4eb447be01c0 |
children | d2e800abd257 |
line wrap: on
line source
/* * This module implements commands for working with EF_PLMNsel. */ #include <sys/types.h> #include <stdio.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); }