view uicc/createfile.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 b70d35f5476f
children
line wrap: on
line source

/*
 * This module implements commands that exercise ETSI TS 102 222
 * CREATE FILE and DELETE FILE operations.
 */

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

cmd_create_file(argc, argv)
	char **argv;
{
	u_char apdu[260], inbuf[252], *dp;
	unsigned len1, len2;
	int rc;

	rc = read_hex_data_file(argv[1], inbuf, 252);
	if (rc < 0)
		return(rc);
	len1 = rc;
	dp = apdu + 5;
	*dp++ = 0x62;
	if (len1 < 0x80) {
		*dp++ = len1;
		len2 = len1 + 2;
	} else {
		*dp++ = 0x81;
		*dp++ = len1;
		len2 = len1 + 3;
	}
	bcopy(inbuf, dp, len1);
	/* command header */
	apdu[0] = 0x00;
	apdu[1] = 0xE0;
	apdu[2] = 0;
	apdu[3] = 0;
	apdu[4] = len2;
	rc = apdu_exchange(apdu, len2 + 5);
	if (rc < 0)
		return(rc);
	if (sim_resp_sw != 0x9000) {
		fprintf(stderr, "bad SW response: %04X\n", sim_resp_sw);
		return(-1);
	}
	return(0);
}

cmd_delete_file(argc, argv)
	char **argv;
{
	u_char apdu[7];
	unsigned file_id;
	int rc;

	if (!isxdigit(argv[1][0]) || !isxdigit(argv[1][1]) ||
	    !isxdigit(argv[1][2]) || !isxdigit(argv[1][3]) || argv[1][4]) {
		fprintf(stderr, "error: 4-digit hex argument required\n");
		return(-1);
	}
	file_id = strtoul(argv[1], 0, 16);
	/* form command APDU */
	apdu[0] = 0x00;
	apdu[1] = 0xE4;
	apdu[2] = 0;
	apdu[3] = 0;
	apdu[4] = 2;
	apdu[5] = file_id >> 8;
	apdu[6] = file_id;
	rc = apdu_exchange(apdu, 7);
	if (rc < 0)
		return(rc);
	if (sim_resp_sw != 0x9000) {
		fprintf(stderr, "bad SW response: %04X\n", sim_resp_sw);
		return(-1);
	}
	return(0);
}