FreeCalypso > hg > fc-pcsc-tools
view simtool/usersum.c @ 90:8a714fe98aa9
doc/User-oriented-commands: new lnd-* commands
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 17 Feb 2021 18:40:34 +0000 |
parents | 633033af6fb8 |
children | b89bc690dec4 |
line wrap: on
line source
/* * This module implements the user-sum (summary info) command. */ #include <sys/types.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <strings.h> #include "simresp.h" #include "curfile.h" #include "file_id.h" #define SST_BYTES_USED 15 static read_sst(sstbuf) u_char *sstbuf; { int rc; unsigned rdlen; rc = select_op(DF_GSM); if (rc < 0) return(rc); rc = select_op(EF_SST); if (rc < 0) return(rc); rc = parse_ef_select_response(); if (rc < 0) return(rc); if (curfile_structure != 0x00) { fprintf(stderr, "error: EF_SST is not transparent\n"); return(-1); } if (curfile_total_size < 2) { fprintf(stderr, "error: EF_SST is shorter than spec minimum of 2 bytes\n"); return(-1); } rdlen = curfile_total_size; if (rdlen > SST_BYTES_USED) rdlen = SST_BYTES_USED; rc = readbin_op(0, rdlen); if (rc < 0) return(rc); bcopy(sim_resp_data, sstbuf, rdlen); if (rdlen < SST_BYTES_USED) bzero(sstbuf + rdlen, SST_BYTES_USED - rdlen); return(0); } static do_phonebook_file(file_id, ef_name, book_name) unsigned file_id; char *ef_name, *book_name; { int rc; rc = select_op(file_id); if (rc < 0) return(rc); rc = parse_ef_select_response(); if (rc < 0) return(rc); if (curfile_structure != 0x01 && curfile_structure != 0x03) { fprintf(stderr, "error: %s is not record-structured\n", ef_name); return(-1); } if (curfile_record_len < 14) { fprintf(stderr, "error: %s has record length of %u bytes, less than minimum 14\n", ef_name, curfile_record_len); return(-1); } printf("%s: %u entries, %u bytes of alpha tag\n", book_name, curfile_record_count, curfile_record_len - 14); return(0); } static do_sms_store() { int rc; rc = select_op(EF_SMS); if (rc < 0) return(rc); rc = parse_ef_select_response(); if (rc < 0) return(rc); if (curfile_structure != 0x01 || curfile_record_len != 176) { fprintf(stderr, "error: EF_SMS is not linear fixed with 176-byte records\n"); return(-1); } printf("SMS store: %u entries\n", curfile_record_count); return(0); } static do_smsp_store() { int rc; rc = select_op(EF_SMSP); if (rc < 0) return(rc); rc = parse_ef_select_response(); if (rc < 0) return(rc); if (curfile_structure != 0x01) { fprintf(stderr, "error: EF_SMSP is not linear fixed\n"); return(-1); } if (curfile_record_len < 28) { fprintf(stderr, "error: EF_SMSP has record length of %u bytes, less than minimum 14\n", curfile_record_len); return(-1); } printf("SMS parameter store: %u entries, %u bytes of alpha tag\n", curfile_record_count, curfile_record_len - 28); return(0); } cmd_user_sum() { int rc; u_char sst[SST_BYTES_USED]; rc = read_sst(sst); if (rc < 0) return(rc); rc = select_op(DF_TELECOM); if (rc < 0) return(rc); if ((sst[0] & 0x0C) == 0x0C) { rc = do_phonebook_file(EF_ADN, "EF_ADN", "ADN phonebook"); if (rc < 0) return(rc); } if ((sst[0] & 0x30) == 0x30) { rc = do_phonebook_file(EF_FDN, "EF_FDN", "FDN phonebook"); if (rc < 0) return(rc); } if ((sst[0] & 0xC0) == 0xC0) { rc = do_sms_store(); if (rc < 0) return(rc); } if ((sst[1] & 0x03) == 0x03) printf("AoC service present\n"); if ((sst[2] & 0x03) == 0x03) { rc = do_phonebook_file(EF_MSISDN, "EF_MSISDN", "MSISDN record"); if (rc < 0) return(rc); } if ((sst[2] & 0xC0) == 0xC0) { rc = do_smsp_store(); if (rc < 0) return(rc); } if ((sst[3] & 0x03) == 0x03) { rc = do_phonebook_file(EF_LND, "EF_LND", "LND cyclic store"); if (rc < 0) return(rc); } if ((sst[4] & 0x0C) == 0x0C) { rc = do_phonebook_file(EF_SDN, "EF_SDN", "SDN phonebook"); if (rc < 0) return(rc); } if ((sst[13] & 0x03) == 0x03) printf("MBDN present\n"); if ((sst[13] & 0x0C) == 0x0C) printf("MWIS present\n"); return(0); }