diff target-utils/simagent/byterx.c @ 783:c136a1a2474b

simagent: initial implementation of APDU exchange
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 13 Mar 2021 22:06:08 +0000
parents badc5399d641
children
line wrap: on
line diff
--- a/target-utils/simagent/byterx.c	Sat Mar 13 21:39:34 2021 +0000
+++ b/target-utils/simagent/byterx.c	Sat Mar 13 22:06:08 2021 +0000
@@ -1,6 +1,7 @@
 #include <stdlib.h>
 #include "types.h"
 #include "simregs.h"
+#include "timeout.h"
 
 rx_sim_byte(count)
 	unsigned count;
@@ -12,6 +13,24 @@
 	return(-1);
 }
 
+rx_sim_byte_hl()
+{
+	int rc;
+	unsigned parcnt;
+
+	for (parcnt = 0; parcnt < 3; parcnt++) {
+		rc = rx_sim_byte(SIM_WAIT_TIMEOUT);
+		if (rc < 0) {
+			printf("ERROR: timeout waiting for SIM response\n");
+			return(-1);
+		}
+		if (rc & 0x100)
+			return rc & 0xFF;
+	}
+	printf("ERROR: received bad parity 3 times in a row\n");
+	return(-1);
+}
+
 flush_rx_fifo()
 {
 	unsigned count;