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

/*
 * This module implements some commands for testing SIM Toolkit functionality,
 * initially just enough to be able to simulate SMS-PP SIM data download
 * operations, but now also extending into basic exploration of proactive SIMs.
 */

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

cmd_terminal_profile(argc, argv)
	char **argv;
{
	u_char cmd[260];
	int rc;
	unsigned len;

	rc = decode_hex_data_from_string(argv[1], cmd + 5, 1, 255);
	if (rc < 0)
		return(rc);
	len = rc;
	/* TERMINAL PROFILE command APDU */
	cmd[0] = 0xA0;
	cmd[1] = 0x10;
	cmd[2] = 0;
	cmd[3] = 0;
	cmd[4] = len;
	rc = apdu_exchange(cmd, len + 5);
	if (rc < 0)
		return(rc);
	printf("%04X\n", sim_resp_sw);
	return(0);
}

cmd_envelope(argc, argv)
	char **argv;
{
	u_char cmd[260];
	int rc;
	unsigned len;

	rc = read_hex_data_file(argv[1], cmd + 5, 255);
	if (rc < 0)
		return(rc);
	len = rc;
	/* ENVELOPE command APDU */
	cmd[0] = 0xA0;
	cmd[1] = 0xC2;
	cmd[2] = 0;
	cmd[3] = 0;
	cmd[4] = len;
	rc = apdu_exchange(cmd, len + 5);
	if (rc < 0)
		return(rc);
	printf("%04X\n", sim_resp_sw);
	return(0);
}

cmd_envelope_imm(argc, argv)
	char **argv;
{
	u_char cmd[260];
	int rc;
	unsigned len;

	rc = decode_hex_data_from_string(argv[1], cmd + 5, 1, 255);
	if (rc < 0)
		return(rc);
	len = rc;
	/* ENVELOPE command APDU */
	cmd[0] = 0xA0;
	cmd[1] = 0xC2;
	cmd[2] = 0;
	cmd[3] = 0;
	cmd[4] = len;
	rc = apdu_exchange(cmd, len + 5);
	if (rc < 0)
		return(rc);
	printf("%04X\n", sim_resp_sw);
	return(0);
}

cmd_fetch(argc, argv, outf)
	char **argv;
	FILE *outf;
{
	u_char cmd[5];
	int rc;
	unsigned len;

	len = strtoul(argv[1], 0, 0);
	if (len < 1 || len > 256) {
		fprintf(stderr, "error: length argument is out of range\n");
		return(-1);
	}
	/* FETCH command APDU */
	cmd[0] = 0xA0;
	cmd[1] = 0x12;
	cmd[2] = 0;
	cmd[3] = 0;
	cmd[4] = len;
	rc = apdu_exchange(cmd, 5);
	if (rc < 0)
		return(rc);
	if (sim_resp_sw != 0x9000) {
		fprintf(stderr, "bad SW resp: %04X\n", sim_resp_sw);
		return(-1);
	}
	display_sim_resp_in_hex(outf);
	return(0);
}

cmd_terminal_resp(argc, argv)
	char **argv;
{
	u_char cmd[260];
	int rc;
	unsigned len;

	rc = decode_hex_data_from_string(argv[1], cmd + 5, 1, 255);
	if (rc < 0)
		return(rc);
	len = rc;
	/* TERMINAL RESPONSE command APDU */
	cmd[0] = 0xA0;
	cmd[1] = 0x14;
	cmd[2] = 0;
	cmd[3] = 0;
	cmd[4] = len;
	rc = apdu_exchange(cmd, len + 5);
	if (rc < 0)
		return(rc);
	printf("%04X\n", sim_resp_sw);
	return(0);
}