changeset 152:77832c9f2001

fc-uicc-tool: elem_select_op() implemented like in fc-simtool
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 25 Feb 2021 17:22:20 +0000
parents d9dd52bc403b
children 2ef31306be22
files uicc/select.c
diffstat 1 files changed, 29 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/uicc/select.c	Thu Feb 25 17:06:38 2021 +0000
+++ b/uicc/select.c	Thu Feb 25 17:22:20 2021 +0000
@@ -11,6 +11,35 @@
 
 unsigned last_sel_file_record_len;
 
+elem_select_op(file_id)
+	unsigned file_id;
+{
+	u_char cmd[7];
+	int rc;
+	unsigned expect_resp_len;
+
+	last_sel_file_record_len = 0;
+	/* SELECT command APDU */
+	cmd[0] = 0x00;
+	cmd[1] = 0xA4;
+	cmd[2] = 0x00;
+	cmd[3] = 0x04;
+	cmd[4] = 2;
+	cmd[5] = file_id >> 8;
+	cmd[6] = file_id;
+	rc = apdu_exchange(cmd, 7);
+	if (rc < 0)
+		return(rc);
+	if (sim_resp_sw == 0x6A82)
+		return(0);
+	if ((sim_resp_sw & 0xFF00) == 0x6100)
+		return(1);
+	fprintf(stderr,
+		"error or unexpected SW response to SELECT of 0x%04X: %04X\n",
+		file_id, sim_resp_sw);
+	return(-1);
+}
+
 select_op(file_id)
 	unsigned file_id;
 {