blob: ad9b7b536df01c44776665a33313763c68f57876 [file] [log] [blame]
Christina Quastc0aa7692015-02-25 14:02:01 +01001#ifndef SIMTRACE_H
2#define SIMTRACE_H
Christina Quast32906bb2015-02-24 11:35:19 +01003
Christina Quast4db82e02015-04-11 18:14:41 +02004#include "ringbuffer.h"
5
Christina Quast4ba4d222015-03-02 16:14:09 +01006/* Endpoint numbers */
7#define DATAOUT 1
8#define DATAIN 2
9#define INT 3
10
Christina Quast4db82e02015-04-11 18:14:41 +020011#define BUFLEN 64
Christina Quast71234252015-04-03 11:35:59 +020012
Christina Quastb65b8812015-04-04 10:51:37 +020013#define PHONE_DATAOUT 4
14#define PHONE_DATAIN 5
15#define PHONE_INT 6
Christina Quast71234252015-04-03 11:35:59 +020016
Christina Quastec9c09e2015-04-16 10:45:39 +020017#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 Quast3eab56e2015-04-10 15:38:49 +020027
Christina Quast4db82e02015-04-11 18:14:41 +020028extern volatile ringbuf sim_rcv_buf;
Christina Quast95d66162015-04-09 22:38:47 +020029
30extern volatile bool rcvdChar;
31extern volatile uint32_t char_stat;
32extern volatile enum confNum simtrace_config;
Christina Quast4ba4d222015-03-02 16:14:09 +010033
Christina Quaste4cbfe62015-04-20 13:07:28 +020034extern const Pin pinPhoneRST;
35
Christina Quast10b2e5a2015-02-25 18:40:15 +010036enum confNum {
Christina Quastdb7b1ab2015-03-03 12:34:36 +010037 CFG_NUM_SNIFF = 1, CFG_NUM_CCID, CFG_NUM_PHONE, CFG_NUM_MITM, NUM_CONF
Christina Quast10b2e5a2015-02-25 18:40:15 +010038};
39
Christina Quastdb7b1ab2015-03-03 12:34:36 +010040/// CCIDDriverConfiguration Descriptors
41/// List of descriptors that make up the configuration descriptors of a
42/// device using the CCID driver.
43typedef 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 Quast4b1e98d2015-04-06 23:28:02 +020059extern const USBConfigurationDescriptor *configurationDescriptorsArr[];
60
Christina Quastbe235272015-05-02 17:56:32 +020061/*** PTS parsing ***/
62/* detailed sub-states of ISO7816_S_IN_PTS */
63enum 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
79struct 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 Quast2b8a18b2015-04-12 09:31:36 +020089int check_data_from_phone();
Christina Quastbe235272015-05-02 17:56:32 +020090enum pts_state process_byte_pts(struct iso7816_3_handle *ih, uint8_t byte);
91
Christina Quaste4cbfe62015-04-20 13:07:28 +020092void ISR_PhoneRST( const Pin *pPin);
Christina Quastdb7b1ab2015-03-03 12:34:36 +010093
Christina Quast95d66162015-04-09 22:38:47 +020094/* Configure functions */
95extern void Sniffer_configure( void );
96extern void CCID_configure( void );
97extern void Phone_configure( void );
98extern void MITM_configure( void );
99
Christina Quast1edf3502015-02-27 13:33:52 +0100100/* Init functions */
Christina Quast95d66162015-04-09 22:38:47 +0200101extern void Sniffer_init( void );
Christina Quastdb7b1ab2015-03-03 12:34:36 +0100102extern void CCID_init( void );
Christina Quast95d66162015-04-09 22:38:47 +0200103extern void Phone_init( void );
Christina Quast1edf3502015-02-27 13:33:52 +0100104extern void MITM_init( void );
Christina Quast27c643d2015-02-24 19:09:08 +0100105
Christina Quastc0aa7692015-02-25 14:02:01 +0100106extern void SIMtrace_USB_Initialize( void );
Christina Quastc0aa7692015-02-25 14:02:01 +0100107
Christina Quast95d66162015-04-09 22:38:47 +0200108/* Exit functions */
109extern void Sniffer_exit( void );
110extern void CCID_exit( void );
111extern void Phone_exit( void );
112extern void MITM_exit( void );
113
Christina Quast1edf3502015-02-27 13:33:52 +0100114/* Run functions */
115extern void Sniffer_run( void );
Christina Quastdb7b1ab2015-03-03 12:34:36 +0100116extern void CCID_run( void );
Christina Quast1edf3502015-02-27 13:33:52 +0100117extern void Phone_run( void );
118extern void MITM_run( void );
119
Christina Quast531d10b2015-03-19 19:27:04 +0100120/* Timer helper function */
121void Timer_Init( void );
122void TC0_Counter_Reset( void );
123
Christina Quast1edf3502015-02-27 13:33:52 +0100124#endif /* SIMTRACE_H */