changeset 144:60411fd4b803

simtool code: cmd_get_response() factored out of stktest.c
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 25 Feb 2021 05:44:27 +0000
parents be1a759453ef
children c2889812788e
files simtool/Makefile simtool/getresp.c simtool/stktest.c
diffstat 3 files changed, 46 insertions(+), 38 deletions(-) [+]
line wrap: on
line diff
--- a/simtool/Makefile	Thu Feb 25 05:40:19 2021 +0000
+++ b/simtool/Makefile	Thu Feb 25 05:44:27 2021 +0000
@@ -1,13 +1,13 @@
 CC=	gcc
 CFLAGS=	-O2 -I/usr/include/PCSC -I../libcommon
 PROG=	fc-simtool
-OBJS=	a38.o chv.o chvext.o curfile.o dispatch.o dumpdir.o fplmn.o grcard1.o \
-	grcard2.o hlread.o inval_rehab.o lndwrite.o main.o miscadm.o opldump.o \
-	pbcommon.o pbdump.o pberase.o pbrestore.o pbupd_imm.o pbupd_immhex.o \
-	plmnsel.o pnndump.o readcmd.o readops.o restorebin.o savebin.o script.o\
-	select.o smserase.o smsp_common.o smsp_dump.o smsp_erase.o \
-	smsp_restore.o smsp_set.o sstlist.o stktest.o sysmo.o telsum.o \
-	usersum.o writecmd.o writeops.o
+OBJS=	a38.o chv.o chvext.o curfile.o dispatch.o dumpdir.o fplmn.o getresp.o \
+	grcard1.o grcard2.o hlread.o inval_rehab.o lndwrite.o main.o miscadm.o \
+	opldump.o pbcommon.o pbdump.o pberase.o pbrestore.o pbupd_imm.o \
+	pbupd_immhex.o plmnsel.o pnndump.o readcmd.o readops.o restorebin.o \
+	savebin.o script.o select.o smserase.o smsp_common.o smsp_dump.o \
+	smsp_erase.o smsp_restore.o smsp_set.o sstlist.o stktest.o sysmo.o \
+	telsum.o usersum.o writecmd.o writeops.o
 LIBS=	../libcommon/libcommon.a
 INSTBIN=/opt/freecalypso/bin
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/simtool/getresp.c	Thu Feb 25 05:44:27 2021 +0000
@@ -0,0 +1,39 @@
+/*
+ * This module implements an elementary GET RESPONSE command
+ */
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include "simresp.h"
+
+cmd_get_response(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);
+	}
+	/* GET RESPONSE command APDU */
+	cmd[0] = 0xA0;
+	cmd[1] = 0xC0;
+	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 to GET RESPONSE: %04X\n",
+			sim_resp_sw);
+		return(-1);
+	}
+	display_sim_resp_in_hex(outf);
+	return(0);
+}
--- a/simtool/stktest.c	Thu Feb 25 05:40:19 2021 +0000
+++ b/simtool/stktest.c	Thu Feb 25 05:44:27 2021 +0000
@@ -79,34 +79,3 @@
 	printf("%04X\n", sim_resp_sw);
 	return(0);
 }
-
-cmd_get_response(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);
-	}
-	/* GET RESPONSE command APDU */
-	cmd[0] = 0xA0;
-	cmd[1] = 0xC0;
-	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 to GET RESPONSE: %04X\n",
-			sim_resp_sw);
-		return(-1);
-	}
-	display_sim_resp_in_hex(outf);
-	return(0);
-}