view libcommon/apducmd.c @ 57:bccf028921bb

apdu-checksw command added to both fc-simtool and fc-uicc-tool
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 22 Mar 2021 23:58:11 +0000
parents c9ef9e91dd8e
children
line wrap: on
line source

/*
 * This module implements a low-level debug command
 * for users to manually send arbitrary APDUs.
 */

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

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

	rc = decode_hex_data_from_string(argv[1], cmd, 5, 260);
	if (rc < 0)
		return(rc);
	len = rc;
	rc = apdu_exchange(cmd, len);
	if (rc < 0)
		return(rc);
	printf("%04X\n", sim_resp_sw);
	return(0);
}

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

	rc = decode_hex_data_from_string(argv[1], cmd, 5, 260);
	if (rc < 0)
		return(rc);
	len = rc;
	expect_sw = strtoul(argv[2], 0, 16);
	rc = apdu_exchange(cmd, len);
	if (rc < 0)
		return(rc);
	if (sim_resp_sw == expect_sw)
		return(0);
	else {
		fprintf(stderr,
			"SW response mismatch: expected %04X, got %04X\n",
			expect_sw, sim_resp_sw);
		return(-1);
	}
}