view simtool/usersum.c @ 10:ddd767f6e15b

fc-simtool ported over
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 14 Mar 2021 07:11:25 +0000
parents
children
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, outf)
	unsigned file_id;
	char *ef_name, *book_name;
	FILE *outf;
{
	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);
	}
	fprintf(outf, "%s: %u entries, %u bytes of alpha tag\n", book_name,
		curfile_record_count, curfile_record_len - 14);
	return(0);
}

static
do_sms_store(outf)
	FILE *outf;
{
	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);
	}
	fprintf(outf, "SMS store: %u entries\n", curfile_record_count);
	return(0);
}

static
do_smsp_store(outf)
	FILE *outf;
{
	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);
	}
	fprintf(outf,
		"SMS parameter store: %u entries, %u bytes of alpha tag\n",
		curfile_record_count, curfile_record_len - 28);
	return(0);
}

cmd_user_sum(argc, argv, outf)
	char **argv;
	FILE *outf;
{
	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", outf);
		if (rc < 0)
			return(rc);
	}
	if ((sst[0] & 0x30) == 0x30) {
		rc = do_phonebook_file(EF_FDN, "EF_FDN", "FDN phonebook", outf);
		if (rc < 0)
			return(rc);
	}
	if ((sst[0] & 0xC0) == 0xC0) {
		rc = do_sms_store(outf);
		if (rc < 0)
			return(rc);
	}
	if ((sst[1] & 0x03) == 0x03)
		fprintf(outf, "AoC service present\n");
	if ((sst[2] & 0x03) == 0x03) {
		rc = do_phonebook_file(EF_MSISDN, "EF_MSISDN", "MSISDN record",
					outf);
		if (rc < 0)
			return(rc);
	}
	if ((sst[2] & 0xC0) == 0xC0) {
		rc = do_smsp_store(outf);
		if (rc < 0)
			return(rc);
	}
	if ((sst[3] & 0x03) == 0x03) {
		rc = do_phonebook_file(EF_LND, "EF_LND", "LND cyclic store",
					outf);
		if (rc < 0)
			return(rc);
	}
	if ((sst[4] & 0x0C) == 0x0C) {
		rc = do_phonebook_file(EF_SDN, "EF_SDN", "SDN phonebook", outf);
		if (rc < 0)
			return(rc);
	}
	if ((sst[13] & 0x03) == 0x03)
		fprintf(outf, "MBDN present\n");
	if ((sst[13] & 0x0C) == 0x0C)
		fprintf(outf, "MWIS present\n");
	return(0);
}