view simtool/sstprog.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 ddd767f6e15b
children
line wrap: on
line source

/*
 * This module implements the write-sst command for admin-level
 * programming of SIM cards.
 */

#include <sys/types.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include "curfile.h"
#include "file_id.h"

extern FILE *open_script_input_file();

cmd_write_sst(argc, argv)
	char **argv;
{
	u_char sst[255];
	FILE *inf;
	int lineno, rc;
	char linebuf[1024], *cp, *np;
	unsigned num, code, max_serv;

	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);
	}
	if (curfile_total_size > 255) {
		fprintf(stderr,
			"error: EF_SST is longer than our 255 byte limit\n");
		return(-1);
	}
	memset(sst, 0, curfile_total_size);
	max_serv = curfile_total_size * 4;
	inf = open_script_input_file(argv[1]);
	if (!inf) {
		perror(argv[1]);
		return(-1);
	}
	for (lineno = 1; fgets(linebuf, sizeof linebuf, inf); lineno++) {
		if (!index(linebuf, '\n')) {
			fprintf(stderr,
				"%s line %d: too long or missing newline\n",
				argv[1], lineno);
			fclose(inf);
			return(-1);
		}
		for (cp = linebuf; ; ) {
			while (isspace(*cp))
				cp++;
			if (*cp == '\0' || *cp == '#')
				break;
			if (!isdigit(*cp)) {
inv_syntax:			fprintf(stderr, "%s line %d: invalid syntax\n",
					argv[1], lineno);
				fclose(inf);
				return(-1);
			}
			num = strtoul(cp, 0, 10);
			while (isdigit(*cp))
				cp++;
			if (*cp == '^') {
				cp++;
				code = 1;
			} else
				code = 3;
			if (*cp && !isspace(*cp))
				goto inv_syntax;
			if (num < 1 || num > max_serv) {
				fprintf(stderr,
				"%s line %d: service number is out of range\n",
					argv[1], lineno);
				fclose(inf);
				return(-1);
			}
			num--;
			sst[num >> 2] |= code << ((num & 3) << 1);
		}
	}
	fclose(inf);
	return update_bin_op(0, sst, curfile_total_size);
}