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

/*
 * This module implements a functional interface to CHV commands,
 * intended for high-level wrappers like sws-*.
 */

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

verify_chv_func(p2, pin)
	unsigned p2;
	char *pin;
{
	u_char cmd[13];
	int rc;

	/* VERIFY CHV command APDU */
	cmd[0] = 0xA0;
	cmd[1] = 0x20;
	cmd[2] = 0x00;
	cmd[3] = p2;
	cmd[4] = 8;
	rc = encode_pin_entry(pin, cmd + 5);
	if (rc < 0)
		return(rc);
	rc = apdu_exchange(cmd, 13);
	if (rc < 0)
		return(rc);
	if (sim_resp_sw != 0x9000) {
		fprintf(stderr, "bad SW response to VERIFY CHV: %04X\n",
			sim_resp_sw);
		return(-1);
	}
	return(0);
}

disable_chv_func(p2, pin)
	unsigned p2;
	char *pin;
{
	u_char cmd[13];
	int rc;

	/* DISABLE CHV command APDU */
	cmd[0] = 0xA0;
	cmd[1] = 0x26;
	cmd[2] = 0x00;
	cmd[3] = p2;
	cmd[4] = 8;
	rc = encode_pin_entry(pin, cmd + 5);
	if (rc < 0)
		return(rc);
	rc = apdu_exchange(cmd, 13);
	if (rc < 0)
		return(rc);
	if (sim_resp_sw != 0x9000 && sim_resp_sw != 0x9808) {
		fprintf(stderr, "bad SW response to DISABLE CHV: %04X\n",
			sim_resp_sw);
		return(-1);
	}
	return(0);
}

enable_chv_func(p2, pin)
	unsigned p2;
	char *pin;
{
	u_char cmd[13];
	int rc;

	/* ENABLE CHV command APDU */
	cmd[0] = 0xA0;
	cmd[1] = 0x28;
	cmd[2] = 0x00;
	cmd[3] = p2;
	cmd[4] = 8;
	rc = encode_pin_entry(pin, cmd + 5);
	if (rc < 0)
		return(rc);
	rc = apdu_exchange(cmd, 13);
	if (rc < 0)
		return(rc);
	if (sim_resp_sw != 0x9000 && sim_resp_sw != 0x9808) {
		fprintf(stderr, "bad SW response to ENABLE CHV: %04X\n",
			sim_resp_sw);
		return(-1);
	}
	return(0);
}