FreeCalypso > hg > fc-pcsc-tools
changeset 61:633033af6fb8
fc-simtool user-sum command implemented,
a successor to telecom-sum
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 14 Feb 2021 03:27:56 +0000 |
parents | 090704d1ddc1 |
children | 4bb28235f08a |
files | simtool/Makefile simtool/dispatch.c simtool/usersum.c |
diffstat | 3 files changed, 184 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/simtool/Makefile Sun Feb 14 01:45:05 2021 +0000 +++ b/simtool/Makefile Sun Feb 14 03:27:56 2021 +0000 @@ -6,7 +6,7 @@ pbupd_imm.o pbupd_immhex.o plmnsel.o pnndump.o readcmd.o readops.o \ restorebin.o savebin.o script.o select.o smserase.o smsp_common.o \ smsp_dump.o smsp_erase.o smsp_restore.o smsp_set.o sstlist.o sysmo.o \ - telsum.o writecmd.o writeops.o + telsum.o usersum.o writecmd.o writeops.o LIBS= ../libcommon/libcommon.a INSTBIN=/opt/freecalypso/bin
--- a/simtool/dispatch.c Sun Feb 14 01:45:05 2021 +0000 +++ b/simtool/dispatch.c Sun Feb 14 03:27:56 2021 +0000 @@ -60,6 +60,7 @@ extern int cmd_update_bin(); extern int cmd_update_bin_imm(); extern int cmd_update_rec(); +extern int cmd_user_sum(); extern int cmd_verify_chv(); extern int cmd_verify_ext(); extern int cmd_verify_hex(); @@ -142,6 +143,7 @@ {"update-bin", 2, 2, cmd_update_bin}, {"update-bin-imm", 2, 2, cmd_update_bin_imm}, {"update-rec", 2, 2, cmd_update_rec}, + {"user-sum", 0, 0, cmd_user_sum}, {"verify-chv1", 1, 1, cmd_verify_chv}, {"verify-chv2", 1, 1, cmd_verify_chv}, {"verify-ext", 2, 2, cmd_verify_ext},
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/simtool/usersum.c Sun Feb 14 03:27:56 2021 +0000 @@ -0,0 +1,181 @@ +/* + * 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); +}