view uicc/createfile.c @ 139:c13ed9194ecd

fc-uicc-tool create-file implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 24 Feb 2021 17:08:37 +0000
parents
children 13ab44761ea6
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 <stdio.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 = decode_hex_data_from_string(argv[1], inbuf, 1, 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);
}