changeset 140:13ab44761ea6

fc-uicc-tool delete-file implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 24 Feb 2021 17:16:04 +0000
parents c13ed9194ecd
children a1aa8ee2da85
files uicc/createfile.c uicc/dispatch.c
diffstat 2 files changed, 35 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/uicc/createfile.c	Wed Feb 24 17:08:37 2021 +0000
+++ b/uicc/createfile.c	Wed Feb 24 17:16:04 2021 +0000
@@ -4,7 +4,9 @@
  */
 
 #include <sys/types.h>
+#include <ctype.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 #include <strings.h>
 #include "simresp.h"
@@ -46,3 +48,34 @@
 	}
 	return(0);
 }
+
+cmd_delete_file(argc, argv)
+	char **argv;
+{
+	u_char apdu[7];
+	unsigned file_id;
+	int rc;
+
+	if (!isxdigit(argv[1][0]) || !isxdigit(argv[1][1]) ||
+	    !isxdigit(argv[1][2]) || !isxdigit(argv[1][3]) || argv[1][4]) {
+		fprintf(stderr, "error: 4-digit hex argument required\n");
+		return(-1);
+	}
+	file_id = strtoul(argv[1], 0, 16);
+	/* form command APDU */
+	apdu[0] = 0x00;
+	apdu[1] = 0xE4;
+	apdu[2] = 0;
+	apdu[3] = 0;
+	apdu[4] = 2;
+	apdu[5] = file_id >> 8;
+	apdu[6] = file_id;
+	rc = apdu_exchange(apdu, 7);
+	if (rc < 0)
+		return(rc);
+	if (sim_resp_sw != 0x9000) {
+		fprintf(stderr, "bad SW response: %04X\n", sim_resp_sw);
+		return(-1);
+	}
+	return(0);
+}
--- a/uicc/dispatch.c	Wed Feb 24 17:08:37 2021 +0000
+++ b/uicc/dispatch.c	Wed Feb 24 17:16:04 2021 +0000
@@ -12,6 +12,7 @@
 extern int cmd_cd();
 extern int cmd_change_pin();
 extern int cmd_create_file();
+extern int cmd_delete_file();
 extern int cmd_dir();
 extern int cmd_disable_pin();
 extern int cmd_enable_pin();
@@ -49,6 +50,7 @@
 	{"cd", 1, 1, 0, cmd_cd},
 	{"change-pin", 3, 3, 0, cmd_change_pin},
 	{"create-file", 1, 1, 0, cmd_create_file},
+	{"delete-file", 1, 1, 0, cmd_delete_file},
 	{"dir", 0, 0, 1, cmd_dir},
 	{"disable-pin", 2, 2, 0, cmd_disable_pin},
 	{"enable-pin", 2, 2, 0, cmd_enable_pin},