diff options
author | Kévin Redon <kredon@sysmocom.de> | 2018-06-27 16:38:31 +0200 |
---|---|---|
committer | King Kévin <kingkevin@cuvoodoo.info> | 2018-07-04 16:33:00 +0200 |
commit | cf599194947065a6b2c542db272f02e182be529f (patch) | |
tree | 1ef1100b993deee05b89fac7df608b5c9cb80cfa /firmware | |
parent | 11914d96584f860ec343e3380eb8dbc60a6bf555 (diff) |
sniff: print parsed ATR and PPS; use red LED to show main application is running; use green LED to indicate activity (message parsed)
Change-Id: I8e906bdbf2c91e608757ae442dfb241f981b8f1e
Diffstat (limited to 'firmware')
-rw-r--r-- | firmware/apps/trace/main.c | 4 | ||||
-rw-r--r-- | firmware/libcommon/source/sniffer.c | 55 |
2 files changed, 56 insertions, 3 deletions
diff --git a/firmware/apps/trace/main.c b/firmware/apps/trace/main.c index 8c89907..a288a7b 100644 --- a/firmware/apps/trace/main.c +++ b/firmware/apps/trace/main.c @@ -124,8 +124,10 @@ extern int main(void) enum confNum last_simtrace_config = simtrace_config; unsigned int i = 0; + /* Configure LED output (red = on, green = activity */ led_init(); - led_blink(LED_RED, BLINK_3O_5F); + led_blink(LED_RED, BLINK_ALWAYS_ON); + led_blink(LED_GREEN, BLINK_ALWAYS_OFF); /* Enable watchdog for 2000 ms, with no window */ WDT_Enable(WDT, WDT_MR_WDRSTEN | WDT_MR_WDDBGHLT | WDT_MR_WDIDLEHLT | diff --git a/firmware/libcommon/source/sniffer.c b/firmware/libcommon/source/sniffer.c index 66aceab..4b3545f 100644 --- a/firmware/libcommon/source/sniffer.c +++ b/firmware/libcommon/source/sniffer.c @@ -189,7 +189,24 @@ static void change_state(enum iso7816_3_sniff_state iso_state_new) /* save new state */ iso_state = iso_state_new; - TRACE_INFO("Changed to ISO 7816-3 state %u\n\r", iso_state); + //TRACE_INFO("Changed to ISO 7816-3 state %u\n\r", iso_state); /* don't print since this is function is also called by ISRs */ +} + +/*! Print current ATR */ +static void print_atr(void) +{ + if (ISO7816_S_IN_ATR!=iso_state) { + TRACE_WARNING("Can't print ATR in ISO 7816-3 state %u\n\r", iso_state); + return; + } + + led_blink(LED_GREEN, BLINK_2O_F); + printf("ATR: "); + uint8_t i; + for (i = 0; i < atr_i && i < ARRAY_SIZE(atr); i++) { + printf("%02x ", atr[i]); + } + printf("\n\r"); } /*! Process ATR byte @@ -206,7 +223,7 @@ static void process_byte_atr(uint8_t byte) return; } if (atr_i>=ARRAY_SIZE(atr)) { - TRACE_WARNING("ATR data overflow\n\r"); + TRACE_ERROR("ATR data overflow\n\r"); return; } @@ -273,6 +290,7 @@ static void process_byte_atr(uint8_t byte) } case ATR_S_WAIT_TCK: /* see ISO/IEC 7816-3:2006 section 8.2.5 */ /* we could verify the checksum, but we are just here to sniff */ + print_atr(); /* print ATR for info */ change_state(ISO7816_S_WAIT_APDU); /* go to next state */ break; default: @@ -280,6 +298,38 @@ static void process_byte_atr(uint8_t byte) } } +/*! Print current PPS */ +static void print_pps(void) +{ + uint8_t *pps_cur; /* current PPS (request or response) */ + + /* sanity check */ + if (ISO7816_S_IN_PPS_REQ==iso_state) { + pps_cur = pps_req; + } else if (ISO7816_S_IN_PPS_RSP==iso_state) { + pps_cur = pps_rsp; + } else { + TRACE_ERROR("Can't print PPS in ISO 7816-3 state %u\n\r", iso_state); + return; + } + + led_blink(LED_GREEN, BLINK_2O_F); + printf("PPS %s : ", ISO7816_S_IN_PPS_REQ==iso_state ? "REQUEST" : "RESPONSE"); + printf("%02x ", pps_cur[0]); + printf("%02x ", pps_cur[1]); + if (pps_cur[1]&0x10) { + printf("%02x ", pps_cur[2]); + } + if (pps_cur[1]&0x20) { + printf("%02x ", pps_cur[3]); + } + if (pps_cur[1]&0x40) { + printf("%02x ", pps_cur[4]); + } + printf("%02x ", pps_cur[5]); + printf("\n\r"); +} + static void process_byte_pps(uint8_t byte) { uint8_t *pps_cur; /* current PPS (request or response) */ @@ -343,6 +393,7 @@ static void process_byte_pps(uint8_t byte) check ^= pps_cur[4]; } check ^= pps_cur[5]; + print_pps(); /* print PPS for info */ if (ISO7816_S_IN_PPS_REQ==iso_state) { if (0==check) { /* checksum is valid */ change_state(ISO7816_S_WAIT_PPS_RSP); /* go to next state */ |