view simtool/inval_rehab.c @ 224:80fc2b2f83c2

doc: admin programming articles added
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 10 Mar 2021 06:56:32 +0000
parents 7faec607500f
children
line wrap: on
line source

/*
 * This module implements the rarely-used INVALIDATE and REHABILITATE
 * SIM protocol commands.
 */

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

current_ef_inval()
{
	u_char cmd[5];
	int rc;

	/* INVALIDATE command APDU */
	cmd[0] = 0xA0;
	cmd[1] = 0x04;
	cmd[2] = 0;
	cmd[3] = 0;
	cmd[4] = 0;
	rc = apdu_exchange(cmd, 5);
	if (rc < 0)
		return(rc);
	if (sim_resp_sw != 0x9000) {
		fprintf(stderr, "bad SW response to INVALIDATE: %04X\n",
			sim_resp_sw);
		return(-1);
	}
	return(0);
}

current_ef_rehab()
{
	u_char cmd[5];
	int rc;

	/* REHABILITATE command APDU */
	cmd[0] = 0xA0;
	cmd[1] = 0x44;
	cmd[2] = 0;
	cmd[3] = 0;
	cmd[4] = 0;
	rc = apdu_exchange(cmd, 5);
	if (rc < 0)
		return(rc);
	if (sim_resp_sw != 0x9000) {
		fprintf(stderr, "bad SW response to REHABILITATE: %04X\n",
			sim_resp_sw);
		return(-1);
	}
	return(0);
}

cmd_inval_adn()
{
	int rc;

	rc = select_op(DF_TELECOM);
	if (rc < 0)
		return(rc);
	rc = select_op(EF_ADN);
	if (rc < 0)
		return(rc);
	return current_ef_inval();
}

cmd_rehab_adn()
{
	int rc;

	rc = select_op(DF_TELECOM);
	if (rc < 0)
		return(rc);
	rc = select_op(EF_ADN);
	if (rc < 0)
		return(rc);
	return current_ef_rehab();
}

cmd_rehab_imsi()
{
	int rc;

	rc = select_op(DF_GSM);
	if (rc < 0)
		return(rc);
	rc = select_op(EF_IMSI);
	if (rc < 0)
		return(rc);
	return current_ef_rehab();
}

cmd_rehab_loci()
{
	int rc;

	rc = select_op(DF_GSM);
	if (rc < 0)
		return(rc);
	rc = select_op(EF_LOCI);
	if (rc < 0)
		return(rc);
	return current_ef_rehab();
}