Christina Quast | c0aa769 | 2015-02-25 14:02:01 +0100 | [diff] [blame] | 1 | #ifndef SIMTRACE_H |
| 2 | #define SIMTRACE_H |
Christina Quast | 32906bb | 2015-02-24 11:35:19 +0100 | [diff] [blame] | 3 | |
Christina Quast | 4db82e0 | 2015-04-11 18:14:41 +0200 | [diff] [blame] | 4 | #include "ringbuffer.h" |
| 5 | |
Christina Quast | 4ba4d22 | 2015-03-02 16:14:09 +0100 | [diff] [blame] | 6 | /* Endpoint numbers */ |
| 7 | #define DATAOUT 1 |
| 8 | #define DATAIN 2 |
| 9 | #define INT 3 |
| 10 | |
Christina Quast | 4db82e0 | 2015-04-11 18:14:41 +0200 | [diff] [blame] | 11 | #define BUFLEN 64 |
Christina Quast | 7123425 | 2015-04-03 11:35:59 +0200 | [diff] [blame] | 12 | |
Christina Quast | b65b881 | 2015-04-04 10:51:37 +0200 | [diff] [blame] | 13 | #define PHONE_DATAOUT 4 |
| 14 | #define PHONE_DATAIN 5 |
| 15 | #define PHONE_INT 6 |
Christina Quast | 7123425 | 2015-04-03 11:35:59 +0200 | [diff] [blame] | 16 | |
Christina Quast | ec9c09e | 2015-04-16 10:45:39 +0200 | [diff] [blame] | 17 | #define CLK_MASTER true |
| 18 | #define CLK_SLAVE false |
| 19 | |
| 20 | /* ===================================================*/ |
| 21 | /* Taken from iso7816_4.c */ |
| 22 | /* ===================================================*/ |
| 23 | /** Flip flop for send and receive char */ |
| 24 | #define USART_SEND 0 |
| 25 | #define USART_RCV 1 |
| 26 | |
Christina Quast | 3eab56e | 2015-04-10 15:38:49 +0200 | [diff] [blame] | 27 | |
Christina Quast | 4db82e0 | 2015-04-11 18:14:41 +0200 | [diff] [blame] | 28 | extern volatile ringbuf sim_rcv_buf; |
Christina Quast | 95d6616 | 2015-04-09 22:38:47 +0200 | [diff] [blame] | 29 | |
| 30 | extern volatile bool rcvdChar; |
| 31 | extern volatile uint32_t char_stat; |
| 32 | extern volatile enum confNum simtrace_config; |
Christina Quast | 4ba4d22 | 2015-03-02 16:14:09 +0100 | [diff] [blame] | 33 | |
Christina Quast | e4cbfe6 | 2015-04-20 13:07:28 +0200 | [diff] [blame] | 34 | extern const Pin pinPhoneRST; |
| 35 | |
Christina Quast | 10b2e5a | 2015-02-25 18:40:15 +0100 | [diff] [blame] | 36 | enum confNum { |
Christina Quast | db7b1ab | 2015-03-03 12:34:36 +0100 | [diff] [blame] | 37 | CFG_NUM_SNIFF = 1, CFG_NUM_CCID, CFG_NUM_PHONE, CFG_NUM_MITM, NUM_CONF |
Christina Quast | 10b2e5a | 2015-02-25 18:40:15 +0100 | [diff] [blame] | 38 | }; |
| 39 | |
Christina Quast | db7b1ab | 2015-03-03 12:34:36 +0100 | [diff] [blame] | 40 | /// CCIDDriverConfiguration Descriptors |
| 41 | /// List of descriptors that make up the configuration descriptors of a |
| 42 | /// device using the CCID driver. |
| 43 | typedef struct { |
| 44 | |
| 45 | /// Configuration descriptor |
| 46 | USBConfigurationDescriptor configuration; |
| 47 | /// Interface descriptor |
| 48 | USBInterfaceDescriptor interface; |
| 49 | /// CCID descriptor |
| 50 | CCIDDescriptor ccid; |
| 51 | /// Bulk OUT endpoint descriptor |
| 52 | USBEndpointDescriptor bulkOut; |
| 53 | /// Bulk IN endpoint descriptor |
| 54 | USBEndpointDescriptor bulkIn; |
| 55 | /// Interrupt OUT endpoint descriptor |
| 56 | USBEndpointDescriptor interruptIn; |
| 57 | } __attribute__ ((packed)) CCIDDriverConfigurationDescriptors; |
| 58 | |
Christina Quast | 4b1e98d | 2015-04-06 23:28:02 +0200 | [diff] [blame] | 59 | extern const USBConfigurationDescriptor *configurationDescriptorsArr[]; |
| 60 | |
Christina Quast | be23527 | 2015-05-02 17:56:32 +0200 | [diff] [blame^] | 61 | /*** PTS parsing ***/ |
| 62 | /* detailed sub-states of ISO7816_S_IN_PTS */ |
| 63 | enum pts_state { |
| 64 | PTS_S_WAIT_REQ_PTSS, |
| 65 | PTS_S_WAIT_REQ_PTS0, |
| 66 | PTS_S_WAIT_REQ_PTS1, |
| 67 | PTS_S_WAIT_REQ_PTS2, |
| 68 | PTS_S_WAIT_REQ_PTS3, |
| 69 | PTS_S_WAIT_REQ_PCK, |
| 70 | PTS_S_WAIT_RESP_PTSS = PTS_S_WAIT_REQ_PTSS | 0x10, |
| 71 | PTS_S_WAIT_RESP_PTS0 = PTS_S_WAIT_REQ_PTS0 | 0x10, |
| 72 | PTS_S_WAIT_RESP_PTS1 = PTS_S_WAIT_REQ_PTS1 | 0x10, |
| 73 | PTS_S_WAIT_RESP_PTS2 = PTS_S_WAIT_REQ_PTS2 | 0x10, |
| 74 | PTS_S_WAIT_RESP_PTS3 = PTS_S_WAIT_REQ_PTS3 | 0x10, |
| 75 | PTS_S_WAIT_RESP_PCK = PTS_S_WAIT_REQ_PCK | 0x10, |
| 76 | PTS_END |
| 77 | }; |
| 78 | |
| 79 | struct iso7816_3_handle { |
| 80 | uint8_t fi; |
| 81 | uint8_t di; |
| 82 | |
| 83 | enum pts_state pts_state; |
| 84 | uint8_t pts_req[6]; |
| 85 | uint8_t pts_resp[6]; |
| 86 | uint8_t pts_bytes_processed; |
| 87 | }; |
| 88 | |
Christina Quast | 2b8a18b | 2015-04-12 09:31:36 +0200 | [diff] [blame] | 89 | int check_data_from_phone(); |
Christina Quast | be23527 | 2015-05-02 17:56:32 +0200 | [diff] [blame^] | 90 | enum pts_state process_byte_pts(struct iso7816_3_handle *ih, uint8_t byte); |
| 91 | |
Christina Quast | e4cbfe6 | 2015-04-20 13:07:28 +0200 | [diff] [blame] | 92 | void ISR_PhoneRST( const Pin *pPin); |
Christina Quast | db7b1ab | 2015-03-03 12:34:36 +0100 | [diff] [blame] | 93 | |
Christina Quast | 95d6616 | 2015-04-09 22:38:47 +0200 | [diff] [blame] | 94 | /* Configure functions */ |
| 95 | extern void Sniffer_configure( void ); |
| 96 | extern void CCID_configure( void ); |
| 97 | extern void Phone_configure( void ); |
| 98 | extern void MITM_configure( void ); |
| 99 | |
Christina Quast | 1edf350 | 2015-02-27 13:33:52 +0100 | [diff] [blame] | 100 | /* Init functions */ |
Christina Quast | 95d6616 | 2015-04-09 22:38:47 +0200 | [diff] [blame] | 101 | extern void Sniffer_init( void ); |
Christina Quast | db7b1ab | 2015-03-03 12:34:36 +0100 | [diff] [blame] | 102 | extern void CCID_init( void ); |
Christina Quast | 95d6616 | 2015-04-09 22:38:47 +0200 | [diff] [blame] | 103 | extern void Phone_init( void ); |
Christina Quast | 1edf350 | 2015-02-27 13:33:52 +0100 | [diff] [blame] | 104 | extern void MITM_init( void ); |
Christina Quast | 27c643d | 2015-02-24 19:09:08 +0100 | [diff] [blame] | 105 | |
Christina Quast | c0aa769 | 2015-02-25 14:02:01 +0100 | [diff] [blame] | 106 | extern void SIMtrace_USB_Initialize( void ); |
Christina Quast | c0aa769 | 2015-02-25 14:02:01 +0100 | [diff] [blame] | 107 | |
Christina Quast | 95d6616 | 2015-04-09 22:38:47 +0200 | [diff] [blame] | 108 | /* Exit functions */ |
| 109 | extern void Sniffer_exit( void ); |
| 110 | extern void CCID_exit( void ); |
| 111 | extern void Phone_exit( void ); |
| 112 | extern void MITM_exit( void ); |
| 113 | |
Christina Quast | 1edf350 | 2015-02-27 13:33:52 +0100 | [diff] [blame] | 114 | /* Run functions */ |
| 115 | extern void Sniffer_run( void ); |
Christina Quast | db7b1ab | 2015-03-03 12:34:36 +0100 | [diff] [blame] | 116 | extern void CCID_run( void ); |
Christina Quast | 1edf350 | 2015-02-27 13:33:52 +0100 | [diff] [blame] | 117 | extern void Phone_run( void ); |
| 118 | extern void MITM_run( void ); |
| 119 | |
Christina Quast | 531d10b | 2015-03-19 19:27:04 +0100 | [diff] [blame] | 120 | /* Timer helper function */ |
| 121 | void Timer_Init( void ); |
| 122 | void TC0_Counter_Reset( void ); |
| 123 | |
Christina Quast | 1edf350 | 2015-02-27 13:33:52 +0100 | [diff] [blame] | 124 | #endif /* SIMTRACE_H */ |