Christina Quast | 32906bb | 2015-02-24 11:35:19 +0100 | [diff] [blame] | 1 | // FIXME: Copyright license here |
| 2 | /*------------------------------------------------------------------------------ |
| 3 | * Headers |
| 4 | *------------------------------------------------------------------------------*/ |
| 5 | |
| 6 | #include "board.h" |
Christina Quast | 32906bb | 2015-02-24 11:35:19 +0100 | [diff] [blame] | 7 | |
| 8 | /*------------------------------------------------------------------------------ |
| 9 | * Internal definitions |
| 10 | *------------------------------------------------------------------------------*/ |
Christina Quast | 1161b27 | 2015-02-25 14:15:57 +0100 | [diff] [blame^] | 11 | #define CONF_NONE 0 |
Christina Quast | 32906bb | 2015-02-24 11:35:19 +0100 | [diff] [blame] | 12 | #define CONF_SNIFFER 1 |
| 13 | #define CONF_CCID_READER 2 |
| 14 | #define CONF_SIMCARD_EMUL 3 |
| 15 | #define CONF_MITM 4 |
| 16 | |
| 17 | |
| 18 | /*------------------------------------------------------------------------------ |
| 19 | * Internal variables |
| 20 | *------------------------------------------------------------------------------*/ |
Christina Quast | 1161b27 | 2015-02-25 14:15:57 +0100 | [diff] [blame^] | 21 | uint8_t simtrace_config = CONF_NONE; |
Christina Quast | c02571e | 2015-02-24 19:09:55 +0100 | [diff] [blame] | 22 | uint8_t conf_changed = 1; |
| 23 | |
| 24 | uint8_t rcvdChar = 0; |
Christina Quast | 1161b27 | 2015-02-25 14:15:57 +0100 | [diff] [blame^] | 25 | uint32_t char_stat = 0; |
Christina Quast | 32906bb | 2015-02-24 11:35:19 +0100 | [diff] [blame] | 26 | |
| 27 | /*------------------------------------------------------------------------------ |
| 28 | * Main |
| 29 | *------------------------------------------------------------------------------*/ |
| 30 | |
| 31 | extern int main( void ) |
| 32 | { |
Christina Quast | 1161b27 | 2015-02-25 14:15:57 +0100 | [diff] [blame^] | 33 | uint8_t isUsbConnected = 0; |
| 34 | |
Christina Quast | 32906bb | 2015-02-24 11:35:19 +0100 | [diff] [blame] | 35 | LED_Configure(LED_NUM_GREEN); |
| 36 | LED_Set(LED_NUM_GREEN); |
| 37 | |
| 38 | /* Disable watchdog*/ |
| 39 | WDT_Disable( WDT ) ; |
| 40 | |
| 41 | PIO_InitializeInterrupts(0); |
| 42 | |
Christina Quast | 1161b27 | 2015-02-25 14:15:57 +0100 | [diff] [blame^] | 43 | SIMtrace_USB_Initialize(); |
| 44 | |
| 45 | printf("%s", "USB init\n\r"); |
| 46 | |
| 47 | while(USBD_GetState() < USBD_STATE_CONFIGURED); |
Christina Quast | 32906bb | 2015-02-24 11:35:19 +0100 | [diff] [blame] | 48 | |
| 49 | TRACE_DEBUG("%s", "Start\n\r"); |
Christina Quast | 1161b27 | 2015-02-25 14:15:57 +0100 | [diff] [blame^] | 50 | printf("%s", "Start\n\r"); |
Christina Quast | 32906bb | 2015-02-24 11:35:19 +0100 | [diff] [blame] | 51 | while(1) { |
Christina Quast | 1161b27 | 2015-02-25 14:15:57 +0100 | [diff] [blame^] | 52 | |
| 53 | /* Device is not configured */ |
| 54 | if (USBD_GetState() < USBD_STATE_CONFIGURED) { |
| 55 | |
| 56 | if (isUsbConnected) { |
| 57 | isUsbConnected = 0; |
| 58 | // TC_Stop(TC0, 0); |
| 59 | } |
| 60 | } |
| 61 | else if (isUsbConnected == 0) { |
| 62 | printf("USB is now configured\n\r"); |
| 63 | |
| 64 | isUsbConnected = 1; |
| 65 | // TC_Start(TC0, 0); |
| 66 | } |
| 67 | |
| 68 | |
Christina Quast | 32906bb | 2015-02-24 11:35:19 +0100 | [diff] [blame] | 69 | /* FIXME: Or should we move the while loop into every case, and break out |
| 70 | in case the config changes? */ |
| 71 | switch(simtrace_config) { |
| 72 | case CONF_SNIFFER: |
Christina Quast | c02571e | 2015-02-24 19:09:55 +0100 | [diff] [blame] | 73 | if (conf_changed) { |
| 74 | Sniffer_Init(); |
| 75 | conf_changed = 0; |
| 76 | } else { |
| 77 | if (rcvdChar != 0) { |
| 78 | TRACE_DEBUG("Rcvd char _%x_ \n\r", rcvdChar); |
| 79 | rcvdChar = 0; |
| 80 | } |
| 81 | } |
Christina Quast | 32906bb | 2015-02-24 11:35:19 +0100 | [diff] [blame] | 82 | break; |
| 83 | case CONF_CCID_READER: |
Christina Quast | c02571e | 2015-02-24 19:09:55 +0100 | [diff] [blame] | 84 | if (conf_changed) { |
| 85 | // Init |
| 86 | conf_changed = 0; |
| 87 | } else { |
| 88 | // Receive char |
| 89 | } |
Christina Quast | 32906bb | 2015-02-24 11:35:19 +0100 | [diff] [blame] | 90 | break; |
| 91 | case CONF_SIMCARD_EMUL: |
| 92 | if (conf_changed) { |
| 93 | Phone_Master_Init(); |
Christina Quast | c02571e | 2015-02-24 19:09:55 +0100 | [diff] [blame] | 94 | conf_changed = 0; |
Christina Quast | 32906bb | 2015-02-24 11:35:19 +0100 | [diff] [blame] | 95 | /* Configure ISO7816 driver */ |
| 96 | // FIXME: PIO_Configure(pPwr, PIO_LISTSIZE( pPwr )); |
| 97 | } else { |
| 98 | /* Send and receive chars */ |
| 99 | // ISO7816_GetChar(&rcv_char); |
| 100 | // ISO7816_SendChar(char_to_send); |
| 101 | } |
| 102 | break; |
| 103 | case CONF_MITM: |
Christina Quast | c02571e | 2015-02-24 19:09:55 +0100 | [diff] [blame] | 104 | if (conf_changed) { |
| 105 | // Init |
| 106 | conf_changed = 0; |
| 107 | } else { |
| 108 | // Receive char |
| 109 | } |
Christina Quast | 32906bb | 2015-02-24 11:35:19 +0100 | [diff] [blame] | 110 | break; |
| 111 | default: |
| 112 | break; |
| 113 | } |
| 114 | } |
| 115 | } |