diff options
author | Harald Welte <laforge@gnumonks.org> | 2011-06-17 09:55:18 +0200 |
---|---|---|
committer | Harald Welte <laforge@gnumonks.org> | 2011-06-17 09:55:18 +0200 |
commit | ebaba1be96a6970705eb805dc3afc1d54f489ac8 (patch) | |
tree | 66b4006838f5e6ee63a39550f44c88ebe34d0bf4 /firmware/src/simtrace | |
parent | cda126a7ef6fbb54a18a4786c15117800a13f7b3 (diff) |
simtrace: introduce mode sniffer / mitm switching
Diffstat (limited to 'firmware/src/simtrace')
-rw-r--r-- | firmware/src/simtrace/main_simtrace.c | 48 | ||||
-rw-r--r-- | firmware/src/simtrace/sim_switch.c | 8 |
2 files changed, 50 insertions, 6 deletions
diff --git a/firmware/src/simtrace/main_simtrace.c b/firmware/src/simtrace/main_simtrace.c index 581fd59..8945a56 100644 --- a/firmware/src/simtrace/main_simtrace.c +++ b/firmware/src/simtrace/main_simtrace.c @@ -26,6 +26,7 @@ #include <os/pcd_enumerate.h> #include <os/usb_handler.h> #include "../openpcd.h" +#include "../simtrace.h" #include <os/main.h> #include <os/pio_irq.h> @@ -51,6 +52,49 @@ void _init_func(void) iso_uart_rx_mode(); } +enum simtrace_md { + SIMTRACE_MD_OFF, + SIMTRACE_MD_SNIFFER, + SIMTRACE_MD_MITM, +}; + +#define UART1_PINS (SIMTRACE_PIO_nRST_PH | \ + SIMTRACE_PIO_CLK_PH | \ + SIMTRACE_PIO_CLK_PH_T | \ + SIMTRACE_PIO_IO_PH_RX | \ + SIMTRACE_PIO_IO_PH_TX) + +#define UART0_PINS (SIMTRACE_PIO_nRST | \ + SIMTRACE_PIO_CLK | \ + SIMTRACE_PIO_CLK_T | \ + SIMTRACE_PIO_IO | \ + SIMTRACE_PIO_IO_T) + +static void simtrace_set_mode(enum simtrace_md mode) +{ + switch (mode) { + case SIMTRACE_MD_SNIFFER: + DEBUGPCR("MODE: SNIFFER\n"); + /* switch UART1 pins to input, no pull-up */ + AT91F_PIO_CfgInput(AT91C_BASE_PIOA, UART1_PINS); + AT91F_PIO_CfgPullupDis(AT91C_BASE_PIOA, UART1_PINS); + AT91F_PIO_CfgInput(AT91C_BASE_PIOA, SIMTRACE_PIO_VCC_SIM); + AT91F_PIO_CfgPullupDis(AT91C_BASE_PIOA, SIMTRACE_PIO_VCC_SIM); + /* switch UART0 pins to 'ISO7816 card mode' */ + AT91F_PIO_CfgInput(AT91C_BASE_PIOA, UART0_PINS); + AT91F_PIO_CfgPullupDis(AT91C_BASE_PIOA, UART0_PINS); + AT91F_PIO_CfgPeriph(AT91C_BASE_PIOA, SIMTRACE_PIO_IO, SIMTRACE_PIO_CLK); + sim_switch_mode(1, 1); + break; + case SIMTRACE_MD_MITM: + DEBUGPCR("MODE: MITM\n"); + /* switch UART1 pins to 'ISO7816 card mode' */ + /* switch UART0 pins to 'ISO7816 reader mode' */ + sim_switch_mode(0, 0); + break; + } +} + static void help(void) { DEBUGPCR("r: iso uart Rx mode\r\n" @@ -69,10 +113,10 @@ int _main_dbgu(char key) switch (key) { case 's': - sim_switch_mode(0, 0); + simtrace_set_mode(SIMTRACE_MD_MITM); break; case 'S': - sim_switch_mode(1, 1); + simtrace_set_mode(SIMTRACE_MD_SNIFFER); case 'r': iso_uart_rx_mode(); break; diff --git a/firmware/src/simtrace/sim_switch.c b/firmware/src/simtrace/sim_switch.c index 4f5621c..118437a 100644 --- a/firmware/src/simtrace/sim_switch.c +++ b/firmware/src/simtrace/sim_switch.c @@ -38,14 +38,14 @@ void sim_switch_mode(int connect_io, int connect_misc) { if (connect_io) - AT91F_PIO_SetOutput(AT91C_BASE_PIOA, SIMTRACE_PIO_IO_SW); - else AT91F_PIO_ClearOutput(AT91C_BASE_PIOA, SIMTRACE_PIO_IO_SW); + else + AT91F_PIO_SetOutput(AT91C_BASE_PIOA, SIMTRACE_PIO_IO_SW); if (connect_misc) - AT91F_PIO_SetOutput(AT91C_BASE_PIOA, SIMTRACE_PIO_SC_SW); - else AT91F_PIO_ClearOutput(AT91C_BASE_PIOA, SIMTRACE_PIO_SC_SW); + else + AT91F_PIO_SetOutput(AT91C_BASE_PIOA, SIMTRACE_PIO_SC_SW); } static void sw_sim_irq(u_int32_t pio) |