From 27c643d297e8507278d34e32912d2de78974a4af Mon Sep 17 00:00:00 2001 From: Christina Quast Date: Tue, 24 Feb 2015 19:09:08 +0100 Subject: [PATCH] Sniffer functionality and sniffer bus board config --- sam3s_example/include/board.h | 33 ++++++++++++++++++++++--------- sam3s_example/simtrace/simtrace.h | 4 ++++ sam3s_example/simtrace/sniffer.c | 20 ++----------------- 3 files changed, 30 insertions(+), 27 deletions(-) diff --git a/sam3s_example/include/board.h b/sam3s_example/include/board.h index cb58f159..b7bec1cb 100644 --- a/sam3s_example/include/board.h +++ b/sam3s_example/include/board.h @@ -14,6 +14,9 @@ #include "cciddriver.h" #include "USBD.h" +#include "USBD_Config.h" +#include "USBDDriver.h" + /** Highlevel */ #include "trace.h" #include "stdio.h" @@ -21,6 +24,8 @@ #include "string.h" #include "inttypes.h" +#define MIN(a, b) ((a < b) ? a : b) + #ifdef __GNUC__ #undef __GNUC__ #endif @@ -47,15 +52,24 @@ #define LED_NUM_RED 0 #define LED_NUM_GREEN 1 -/** Phone */ +/** Phone (SIM card emulator)/CCID Reader/MITM configuration **/ +/* Normally the communication lines between phone and SIM card are disconnected */ +// Disconnect SIM card I/O, VPP line from the phone lines +// FIXME: Per default pins are input, therefore high-impedance, therefore they don not activate the bus switch, right? +#define PIN_SC_SW_DEFAULT {PIO_PA20, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT} +// Disconnect SIM card RST, CLK line from the phone lines +#define PIN_IO_SW_DEFAULT {PIO_PA19, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT} +#define PINS_BUS + +/** Sniffer configuration **/ // Connect VPP, CLK and RST lines from smartcard to the phone -//#define PIN_SC_SW {PIO_PA20, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT} -// Temporary fix: do not connect -#define PIN_SC_SW {PIO_PA20, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT} -// Connect SIM card I/O lines to the phone -//#define PIN_IO_SW {PIO_PA19, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT} -// FIXME: Temporary fix: do not connect -#define PIN_IO_SW {PIO_PA19, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT} +#define PIN_SC_SW_SNIFF {PIO_PA20, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT} +#define PIN_IO_SW_SNIFF {PIO_PA19, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT} +#define PINS_BUS_SNIFF PIN_SC_SW_SNIFF, PIN_IO_SW_SNIFF + +#define PINS_SIM_SNIFF_SIM PIN_PHONE_IO, PIN_PHONE_CLK + + /** USART0 pin RX */ #define PIN_USART0_RXD {PIO_PA9A_URXD0, PIOA, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT} @@ -134,7 +148,8 @@ #define PIN_SPI_NPCS0 {1 << 11, PIOA, PIOA, PIO_PERIPH_A, PIO_DEFAULT} //** USB **/ -/// USB pull-up control pin definition (PA16). +// USB pull-up control pin definition (PA16). +// Default: 1 (USB Pullup deactivated) #define PIN_USB_PULLUP {1 << 16, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT} // Board has UDP controller diff --git a/sam3s_example/simtrace/simtrace.h b/sam3s_example/simtrace/simtrace.h index 69892f7e..444e783c 100644 --- a/sam3s_example/simtrace/simtrace.h +++ b/sam3s_example/simtrace/simtrace.h @@ -3,3 +3,7 @@ extern uint32_t _ISO7816_GetChar( uint8_t *pCharToReceive ); extern uint32_t _ISO7816_SendChar( uint8_t CharToSend ); extern void Phone_Master_Init( void ); + +extern void Sniffer_Init( void ); + + diff --git a/sam3s_example/simtrace/sniffer.c b/sam3s_example/simtrace/sniffer.c index 78fc6092..c68ee835 100644 --- a/sam3s_example/simtrace/sniffer.c +++ b/sam3s_example/simtrace/sniffer.c @@ -44,33 +44,17 @@ /** Maximum ATR ucSize in bytes.*/ #define MAX_ATR_SIZE 55 - -/* Sniffer configuration */ -#ifdef PIN_SC_SW -#undef PIN_SC_SW -#endif -#define PIN_SC_SW {PIO_PA20, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT} - -#ifdef PIN_IO_SW -#undef PIN_IO_SW -#endif -#define PIN_IO_SW {PIO_PA19, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT} - -#define PINS_BUS PIN_SC_SW, PIN_IO_SW - -#define PINS_SIM_SNIFF_SIM PIN_PHONE_IO, PIN_PHONE_CLK - /*------------------------------------------------------------------------------ * Internal variables *------------------------------------------------------------------------------*/ /** ISO7816 pins */ static const Pin pinsISO7816_sniff[] = {PINS_SIM_SNIFF_SIM}; -static const Pin pins_bus[] = {PINS_BUS}; +static const Pin pins_bus[] = {PINS_BUS_SNIFF}; static const Pin pPwr[] = { /* Enable power converter 4.5-6V to 3.3V; low: off */ {SIM_PWEN, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT}, - /* Enable second power converter: VCC_PHONE to VCC_SIM; high: off */ + /* Enable second power converter: VCC_PHONE to VCC_SIM; high: on */ {VCC_FWD, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT} };