view uicc/savebin.c @ 99:97ba63d9361a

scripts/fcsim1-sst: turn off STK & OTA services In the initial unprogrammed state of the cards from Grcard, SST has services 25 through 29 set to allocated and activated. However, these cards appear to not actually support OTA, ENVELOPE commands do nothing (just return SW 9000), and they were never observed issuing any proactive SIM commands, even after a feature-generous TERMINAL PROFILE. Therefore, let's list these STK & OTA services as allocated, but not activated in our FCSIM1 SST.
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 05 May 2021 04:26:07 +0000
parents 3afa61d98961
children
line wrap: on
line source

/*
 * This module implements the savebin command for saving SIM file content
 * in UNIX host files.
 */

#include <sys/types.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include "simresp.h"
#include "efstruct.h"

static
savebin_transparent(efs, outf)
	struct ef_struct *efs;
	FILE *outf;
{
	unsigned off, cc;
	int rc;

	for (off = 0; off < efs->total_size; off += cc) {
		cc = efs->total_size - off;
		if (cc > 256)
			cc = 256;
		rc = readbin_op(off, cc);
		if (rc < 0)
			return(rc);
		fwrite(sim_resp_data, 1, cc, outf);
	}
	return(0);
}

static
savebin_records(efs, outf)
	struct ef_struct *efs;
	FILE *outf;
{
	unsigned recno;
	int rc;

	for (recno = 1; recno <= efs->record_count; recno++) {
		rc = readrec_op(recno, 0x04, efs->record_len);
		if (rc < 0)
			return(rc);
		fwrite(sim_resp_data, efs->record_len, 1, outf);
	}
	return(0);
}

cmd_savebin(argc, argv)
	char **argv;
{
	int file_id, rc;
	struct ef_struct efs;
	FILE *of;

	if (isxdigit(argv[1][0]) && isxdigit(argv[1][1]) &&
	    isxdigit(argv[1][2]) && isxdigit(argv[1][3]) && !argv[1][4])
		file_id = strtoul(argv[1], 0, 16);
	else
		file_id = find_symbolic_file_name(argv[1]);
	if (file_id < 0) {
		fprintf(stderr,
"error: file ID argument is not a hex value or a recognized symbolic name\n");
		return(-1);
	}
	rc = select_op(file_id);
	if (rc < 0)
		return(rc);
	rc = select_resp_get_ef_struct(&efs);
	if (rc < 0)
		return(rc);
	of = fopen(argv[2], "w");
	if (!of) {
		perror(argv[2]);
		return(-1);
	}
	switch (efs.structure) {
	case 0x01:
		/* transparent */
		rc = savebin_transparent(&efs, of);
		break;
	case 0x02:
	case 0x06:
		/* record-based */
		rc = savebin_records(&efs, of);
		break;
	}
	fclose(of);
	return(rc);
}