changeset 155:cb3c40ff443e

fc-uicc-tool bfsearch: handle more weird SW response cases
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 25 Feb 2021 20:17:10 +0000
parents 6d93a51f01dc
children 5f1f3f6fd865
files uicc/bfsearch.c uicc/select.c
diffstat 2 files changed, 15 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/uicc/bfsearch.c	Thu Feb 25 18:40:59 2021 +0000
+++ b/uicc/bfsearch.c	Thu Feb 25 20:17:10 2021 +0000
@@ -25,10 +25,10 @@
 		rc = elem_select_op(path[n]);
 		if (rc < 0)
 			return(rc);
-		if (!rc) {
+		if ((sim_resp_sw & 0xFF00) != 0x6100) {
 			fprintf(stderr,
-				"error selecting 0x%04X: file not found\n",
-				path[n]);
+				"error selecting 0x%04X: SW resp 0x%04X\n",
+				path[n], sim_resp_sw);
 			return(-1);
 		}
 	}
@@ -51,8 +51,15 @@
 		rc = elem_select_op(bfs);
 		if (rc < 0)
 			return(rc);
-		if (!rc)
+		if (sim_resp_sw == 0x6A82)
 			continue;
+		if ((sim_resp_sw & 0xFF00) != 0x6100) {
+			for (n = 0; n < pathlen; n++)
+				fprintf(outf, "%04X/", path[n]);
+			fprintf(outf, "%04X: SW response 0x%04X", bfs,
+				sim_resp_sw);
+			continue;
+		}
 		rc = get_response_op();
 		if (rc < 0)
 			return(rc);
@@ -87,10 +94,10 @@
 		rc = elem_select_op(path[pathlen-1]);
 		if (rc < 0)
 			return(rc);
-		if (!rc) {
+		if ((sim_resp_sw & 0xFF00) != 0x6100) {
 			fprintf(stderr,
-			"reselecting starting file ID 0x%04X not-found error\n",
-				path[pathlen-1]);
+			"reselecting starting file ID 0x%04X: SW resp 0x%04X\n",
+				path[pathlen-1], sim_resp_sw);
 			return(-1);
 		}
 	}
--- a/uicc/select.c	Thu Feb 25 18:40:59 2021 +0000
+++ b/uicc/select.c	Thu Feb 25 20:17:10 2021 +0000
@@ -16,7 +16,6 @@
 {
 	u_char cmd[7];
 	int rc;
-	unsigned expect_resp_len;
 
 	last_sel_file_record_len = 0;
 	/* SELECT command APDU */
@@ -27,17 +26,7 @@
 	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);
+	return apdu_exchange(cmd, 7);
 }
 
 select_op(file_id)