laforge submitted this change.
firmware/sniffer: refactor setting TPDU state
In low-level debugging it might be useful to trace the TPDU state
changes, so let's factor-out the state-setting as a function that
can be amended with printf() or GPIO toggles or the like.
No logical change is introduced here, just assignments replaced with
calling a function that does the assignment. compiler should inline
that.
Change-Id: Ie61321404f3686234c61c68a07d6cb9f5830ddc1
---
M firmware/libcommon/source/sniffer.c
1 file changed, 21 insertions(+), 12 deletions(-)
diff --git a/firmware/libcommon/source/sniffer.c b/firmware/libcommon/source/sniffer.c
index 13ef506..1647e17 100644
--- a/firmware/libcommon/source/sniffer.c
+++ b/firmware/libcommon/source/sniffer.c
@@ -255,6 +255,15 @@
usb_buf_submit(usb_msg);
}
+/*! Update the TPDU state
+ * @param[in] tpdu_state_new new TPDU state to update to
+ */
+static void change_tpdu_state(enum tpdu_sniff_state tpdu_state_new)
+{
+ //TRACE_ERROR("TPDU state %u->%u\n\r", tpdu_state, tpdu_state_new);
+ tpdu_state = tpdu_state_new;
+}
+
/*! Update the ISO 7816-3 state
* @param[in] iso_state_new new ISO 7816-3 state to update to
*/
@@ -286,7 +295,7 @@
pps_state = PPS_S_WAIT_PPSS;
break;
case ISO7816_S_WAIT_TPDU:
- tpdu_state = TPDU_S_CLA;
+ change_tpdu_state(TPDU_S_CLA);
tpdu_packet_i = 0;
break;
default:
@@ -714,7 +723,7 @@
}
tpdu_packet_i = 0;
tpdu_packet[tpdu_packet_i++] = byte;
- tpdu_state = TPDU_S_INS;
+ change_tpdu_state(TPDU_S_INS);
break;
case TPDU_S_INS:
if ((0x60 == (byte & 0xf0)) || (0x90 == (byte & 0xf0))) {
@@ -726,37 +735,37 @@
}
tpdu_packet_i = 1;
tpdu_packet[tpdu_packet_i++] = byte;
- tpdu_state = TPDU_S_P1;
+ change_tpdu_state(TPDU_S_P1);
break;
case TPDU_S_P1:
tpdu_packet_i = 2;
tpdu_packet[tpdu_packet_i++] = byte;
- tpdu_state = TPDU_S_P2;
+ change_tpdu_state(TPDU_S_P2);
break;
case TPDU_S_P2:
tpdu_packet_i = 3;
tpdu_packet[tpdu_packet_i++] = byte;
- tpdu_state = TPDU_S_P3;
+ change_tpdu_state(TPDU_S_P3);
break;
case TPDU_S_P3:
tpdu_packet_i = 4;
tpdu_packet[tpdu_packet_i++] = byte;
- tpdu_state = TPDU_S_PROCEDURE;
+ change_tpdu_state(TPDU_S_PROCEDURE);
break;
case TPDU_S_PROCEDURE:
if (0x60 == byte) { /* wait for next procedure byte */
break;
} else if (tpdu_packet[1] == byte) { /* get all remaining data bytes */
- tpdu_state = TPDU_S_DATA_REMAINING;
+ change_tpdu_state(TPDU_S_DATA_REMAINING);
break;
} else if ((~tpdu_packet[1]) == byte) { /* get single data byte */
- tpdu_state = TPDU_S_DATA_SINGLE;
+ change_tpdu_state(TPDU_S_DATA_SINGLE);
break;
}
case TPDU_S_SW1:
if ((0x60 == (byte & 0xf0)) || (0x90 == (byte & 0xf0))) { /* this procedure byte is SW1 */
tpdu_packet[tpdu_packet_i++] = byte;
- tpdu_state = TPDU_S_SW2;
+ change_tpdu_state(TPDU_S_SW2);
} else {
TRACE_WARNING("invalid SW1 0x%02x\n\r", byte);
led_blink(LED_RED, BLINK_2F_O); /* indicate error to user */
@@ -775,15 +784,15 @@
tpdu_packet[tpdu_packet_i++] = byte;
if (0 == tpdu_packet[4]) {
if (5+256 <= tpdu_packet_i) {
- tpdu_state = TPDU_S_PROCEDURE;
+ change_tpdu_state(TPDU_S_PROCEDURE);
}
} else {
if (5+tpdu_packet[4] <= tpdu_packet_i) {
- tpdu_state = TPDU_S_PROCEDURE;
+ change_tpdu_state(TPDU_S_PROCEDURE);
}
}
if (TPDU_S_DATA_SINGLE == tpdu_state) {
- tpdu_state = TPDU_S_PROCEDURE;
+ change_tpdu_state(TPDU_S_PROCEDURE);
}
break;
default:
To view, visit change 30178. To unsubscribe, or for help writing mail filters, visit settings.