changeset 86:de23872796cb

fc-uicc-tool: update-rec-imm and update-rec-fill ported over from fc-simtool
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 11 Apr 2021 03:19:22 +0000
parents c179deb9bb39
children 0e46bbb801e0
files uicc/cmdtab.c uicc/writecmd.c
diffstat 2 files changed, 68 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/uicc/cmdtab.c	Sun Apr 11 02:48:22 2021 +0000
+++ b/uicc/cmdtab.c	Sun Apr 11 03:19:22 2021 +0000
@@ -38,6 +38,8 @@
 extern int cmd_update_bin();
 extern int cmd_update_bin_imm();
 extern int cmd_update_rec();
+extern int cmd_update_rec_fill();
+extern int cmd_update_rec_imm();
 extern int cmd_verify_hex();
 extern int cmd_verify_pin();
 
@@ -77,6 +79,8 @@
 	{"update-bin", 2, 2, 0, cmd_update_bin},
 	{"update-bin-imm", 2, 2, 0, cmd_update_bin_imm},
 	{"update-rec", 2, 2, 0, cmd_update_rec},
+	{"update-rec-fill", 2, 2, 0, cmd_update_rec_fill},
+	{"update-rec-imm", 2, 2, 0, cmd_update_rec_imm},
 	{"verify-ext", 2, 2, 0, cmd_verify_pin},
 	{"verify-hex", 2, 2, 0, cmd_verify_hex},
 	{"verify-pin", 2, 2, 0, cmd_verify_pin},
--- a/uicc/writecmd.c	Sun Apr 11 02:48:22 2021 +0000
+++ b/uicc/writecmd.c	Sun Apr 11 03:19:22 2021 +0000
@@ -76,3 +76,67 @@
 	}
 	return update_rec_op(recno, mode, data, last_sel_file_record_len);
 }
+
+cmd_update_rec_imm(argc, argv)
+	char **argv;
+{
+	unsigned recno, mode;
+	u_char data[255];
+	int rc;
+
+	if (!last_sel_file_record_len) {
+		fprintf(stderr, "error: no record-based file selected\n");
+		return(-1);
+	}
+	if (!strcmp(argv[1], "prev")) {
+		recno = 0;
+		mode = 0x03;
+	} else {
+		recno = strtoul(argv[1], 0, 0);
+		if (recno < 1 || recno > 255) {
+			fprintf(stderr,
+			"error: record number argument is out of range\n");
+			return(-1);
+		}
+		mode = 0x04;
+	}
+	rc = decode_hex_data_from_string(argv[2], data, 1, 255);
+	if (rc < 0)
+		return(rc);
+	if (rc != last_sel_file_record_len) {
+		fprintf(stderr, "error: hex data length != EF record length\n");
+		return(-1);
+	}
+	return update_rec_op(recno, mode, data, last_sel_file_record_len);
+}
+
+cmd_update_rec_fill(argc, argv)
+	char **argv;
+{
+	unsigned recno, mode, fill_byte;
+	u_char data[255];
+
+	if (!last_sel_file_record_len) {
+		fprintf(stderr, "error: no record-based file selected\n");
+		return(-1);
+	}
+	if (!strcmp(argv[1], "prev")) {
+		recno = 0;
+		mode = 0x03;
+	} else {
+		recno = strtoul(argv[1], 0, 0);
+		if (recno < 1 || recno > 255) {
+			fprintf(stderr,
+			"error: record number argument is out of range\n");
+			return(-1);
+		}
+		mode = 0x04;
+	}
+	fill_byte = strtoul(argv[2], 0, 16);
+	if (fill_byte > 0xFF) {
+		fprintf(stderr, "error: invalid fill byte argument\n");
+		return(-1);
+	}
+	memset(data, fill_byte, last_sel_file_record_len);
+	return update_rec_op(recno, mode, data, last_sel_file_record_len);
+}