diff options
-rw-r--r-- | firmware/include/lib_AT91SAM7.h | 16 | ||||
-rw-r--r-- | firmware/src/simtrace.h | 10 | ||||
-rw-r--r-- | firmware/src/simtrace/main_simtrace.c | 48 | ||||
-rw-r--r-- | firmware/src/simtrace/sim_switch.c | 8 |
4 files changed, 74 insertions, 8 deletions
diff --git a/firmware/include/lib_AT91SAM7.h b/firmware/include/lib_AT91SAM7.h index f26ac54..2aa7df6 100644 --- a/firmware/include/lib_AT91SAM7.h +++ b/firmware/include/lib_AT91SAM7.h @@ -444,6 +444,22 @@ static inline void AT91F_PIO_CfgPullup( pPio->PIO_PPUER = pullupEnable; } +static inline void AT91F_PIO_CfgPullupEn( + AT91PS_PIO pPio, // \arg pointer to a PIO controller + unsigned int pullupEnable) // \arg enable pullup on PIO +{ + // Connect or not Pullup + pPio->PIO_PPUER = pullupEnable; +} + +static inline void AT91F_PIO_CfgPullupDis( + AT91PS_PIO pPio, // \arg pointer to a PIO controller + unsigned int pullupEnable) // \arg enable pullup on PIO +{ + // Connect or not Pullup + pPio->PIO_PPUDR = pullupEnable; +} + //*---------------------------------------------------------------------------- //* \fn AT91F_PIO_CfgDirectDrive //* \brief Enable direct drive on PIO diff --git a/firmware/src/simtrace.h b/firmware/src/simtrace.h index d7faa96..6b8f753 100644 --- a/firmware/src/simtrace.h +++ b/firmware/src/simtrace.h @@ -13,19 +13,25 @@ /* 7816 UART for SIM-card side */ #define SIMTRACE_PIO_CLK AT91C_PA2_SCK0 +#define SIMTRACE_PIO_CLK_T AT91C_PA4_TCLK0 #define SIMTRACE_PIO_IO AT91C_PA6_TXD0 +#define SIMTRACE_PIO_IO_T AT91C_PA1_TIOB0 #define SIMTRACE_PIO_nRST AT91C_PIO_PA7 #define SIMTRACE_PIO_SW_SIM AT91C_PIO_PA8 /* 7816 UART for phone side */ #define SIMTRACE_PIO_nRST_PH AT91C_PIO_PA24 -#define SIMTRACE_PIO_CLK_PH AT91C_PIO_PA23 -#define SIMTRACE_PIO_IO_PH AT91C_PIO_PA22 +#define SIMTRACE_PIO_CLK_PH AT91C_PA23_SCK1 +#define SIMTRACE_PIO_CLK_PH_T AT91C_PA28_TCLK1 +#define SIMTRACE_PIO_IO_PH_TX AT91C_PA22_TXD1 +#define SIMTRACE_PIO_IO_PH_RX AT91C_PA21_RXD1 /* bus switch for SIM card connection */ #define SIMTRACE_PIO_SC_SW AT91C_PIO_PA20 #define SIMTRACE_PIO_IO_SW AT91C_PIO_PA19 +#define SIMTRACE_PIO_VCC_SIM AT91C_PIO_PA5 + /* SPI flash */ #define PIO_SPIF_nWP AT91C_PIO_PA15 #define PIO_SPIF_SCK AT91C_PIO_PA14 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) |