blob: 1a1700597a05cfc177efbf79dc1d9ad5386e1bfd [file] [log] [blame]
Christina Quast32906bb2015-02-24 11:35:19 +01001// FIXME: Copyright license here
2/*------------------------------------------------------------------------------
3 * Headers
4 *------------------------------------------------------------------------------*/
5
6#include "board.h"
Christina Quast32906bb2015-02-24 11:35:19 +01007
8/*------------------------------------------------------------------------------
9 * Internal definitions
10 *------------------------------------------------------------------------------*/
Christina Quast1161b272015-02-25 14:15:57 +010011#define CONF_NONE 0
Christina Quast32906bb2015-02-24 11:35:19 +010012#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 Quast1161b272015-02-25 14:15:57 +010021uint8_t simtrace_config = CONF_NONE;
Christina Quastc02571e2015-02-24 19:09:55 +010022uint8_t conf_changed = 1;
23
24uint8_t rcvdChar = 0;
Christina Quast1161b272015-02-25 14:15:57 +010025uint32_t char_stat = 0;
Christina Quast32906bb2015-02-24 11:35:19 +010026
27/*------------------------------------------------------------------------------
28 * Main
29 *------------------------------------------------------------------------------*/
30
31extern int main( void )
32{
Christina Quast1161b272015-02-25 14:15:57 +010033 uint8_t isUsbConnected = 0;
34
Christina Quast32906bb2015-02-24 11:35:19 +010035 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 Quast1161b272015-02-25 14:15:57 +010043 SIMtrace_USB_Initialize();
44
45 printf("%s", "USB init\n\r");
46
47 while(USBD_GetState() < USBD_STATE_CONFIGURED);
Christina Quast32906bb2015-02-24 11:35:19 +010048
49 TRACE_DEBUG("%s", "Start\n\r");
Christina Quast1161b272015-02-25 14:15:57 +010050 printf("%s", "Start\n\r");
Christina Quast32906bb2015-02-24 11:35:19 +010051 while(1) {
Christina Quast1161b272015-02-25 14:15:57 +010052
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 Quast32906bb2015-02-24 11:35:19 +010069/* 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 Quastc02571e2015-02-24 19:09:55 +010073 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 Quast32906bb2015-02-24 11:35:19 +010082 break;
83 case CONF_CCID_READER:
Christina Quastc02571e2015-02-24 19:09:55 +010084 if (conf_changed) {
85 // Init
86 conf_changed = 0;
87 } else {
88 // Receive char
89 }
Christina Quast32906bb2015-02-24 11:35:19 +010090 break;
91 case CONF_SIMCARD_EMUL:
92 if (conf_changed) {
93 Phone_Master_Init();
Christina Quastc02571e2015-02-24 19:09:55 +010094 conf_changed = 0;
Christina Quast32906bb2015-02-24 11:35:19 +010095 /* 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 Quastc02571e2015-02-24 19:09:55 +0100104 if (conf_changed) {
105 // Init
106 conf_changed = 0;
107 } else {
108 // Receive char
109 }
Christina Quast32906bb2015-02-24 11:35:19 +0100110 break;
111 default:
112 break;
113 }
114 }
115}