view simtool/writecmd.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 3055d5c9e7a3
children
line wrap: on
line source

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

cmd_update_bin(argc, argv)
	char **argv;
{
	unsigned offset, len;
	u_char data[255];
	int rc;

	offset = strtoul(argv[1], 0, 0);
	if (offset > 0xFFFF) {
		fprintf(stderr, "error: offset argument is out of range\n");
		return(-1);
	}
	rc = read_hex_data_file(argv[2], data, 255);
	if (rc < 0)
		return(rc);
	len = rc;
	return update_bin_op(offset, data, len);
}

cmd_update_bin_imm(argc, argv)
	char **argv;
{
	unsigned offset, len;
	u_char data[255];
	int rc;

	offset = strtoul(argv[1], 0, 0);
	if (offset > 0xFFFF) {
		fprintf(stderr, "error: offset argument is out of range\n");
		return(-1);
	}
	rc = decode_hex_data_from_string(argv[2], data, 1, 255);
	if (rc < 0)
		return(rc);
	len = rc;
	return update_bin_op(offset, data, len);
}

cmd_update_rec(argc, argv)
	char **argv;
{
	unsigned recno, mode;
	u_char data[255];
	int rc;

	if (!curfile_record_len) {
		fprintf(stderr, "error: no record-based file selected\n");
		return(-1);
	}
	if (!strcmp(argv[1], "prev")) {
		recno = 0;
		mode = 0x03;
	} else {
		recno = strtoul(argv[1], 0, 0);
		if (recno < 1 || recno > 255) {
			fprintf(stderr,
			"error: record number argument is out of range\n");
			return(-1);
		}
		mode = 0x04;
	}
	rc = read_hex_data_file(argv[2], data, 255);
	if (rc < 0)
		return(rc);
	if (rc != curfile_record_len) {
		fprintf(stderr, "error: hex data length != EF record length\n");
		return(-1);
	}
	return update_rec_op(recno, mode, data, curfile_record_len);
}

cmd_update_rec_imm(argc, argv)
	char **argv;
{
	unsigned recno, mode;
	u_char data[255];
	int rc;

	if (!curfile_record_len) {
		fprintf(stderr, "error: no record-based file selected\n");
		return(-1);
	}
	if (!strcmp(argv[1], "prev")) {
		recno = 0;
		mode = 0x03;
	} else {
		recno = strtoul(argv[1], 0, 0);
		if (recno < 1 || recno > 255) {
			fprintf(stderr,
			"error: record number argument is out of range\n");
			return(-1);
		}
		mode = 0x04;
	}
	rc = decode_hex_data_from_string(argv[2], data, 1, 255);
	if (rc < 0)
		return(rc);
	if (rc != curfile_record_len) {
		fprintf(stderr, "error: hex data length != EF record length\n");
		return(-1);
	}
	return update_rec_op(recno, mode, data, curfile_record_len);
}

cmd_update_rec_fill(argc, argv)
	char **argv;
{
	unsigned recno, mode, fill_byte;
	u_char data[255];

	if (!curfile_record_len) {
		fprintf(stderr, "error: no record-based file selected\n");
		return(-1);
	}
	if (!strcmp(argv[1], "prev")) {
		recno = 0;
		mode = 0x03;
	} else {
		recno = strtoul(argv[1], 0, 0);
		if (recno < 1 || recno > 255) {
			fprintf(stderr,
			"error: record number argument is out of range\n");
			return(-1);
		}
		mode = 0x04;
	}
	fill_byte = strtoul(argv[2], 0, 16);
	if (fill_byte > 0xFF) {
		fprintf(stderr, "error: invalid fill byte argument\n");
		return(-1);
	}
	memset(data, fill_byte, curfile_record_len);
	return update_rec_op(recno, mode, data, curfile_record_len);
}