mirror of
https://gitea.osmocom.org/sim-card/simtrace2.git
synced 2026-03-16 21:28:33 +03:00
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
This commit is contained in:
@@ -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 |
|
||||
|
||||
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user