blob: 04865812f934c855d0a1f49dce45ae7d56c79f94 [file] [log] [blame]
Kévin Redon9a12d682018-07-08 13:21:16 +02001/* SIMtrace 2 mode definitions
2 *
3 * (C) 2015-2017 by Harald Welte <hwelte@hmw-consulting.de>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
18 */
Christina Quastc0aa7692015-02-25 14:02:01 +010019#ifndef SIMTRACE_H
20#define SIMTRACE_H
Christina Quast32906bb2015-02-24 11:35:19 +010021
Christina Quast4db82e02015-04-11 18:14:41 +020022#include "ringbuffer.h"
Harald Welte16055642016-03-03 11:02:45 +010023#include "board.h"
Harald Welte5e6e8dc2017-11-28 20:58:06 +010024#include <usb/device/dfu/dfu.h>
Christina Quast4db82e02015-04-11 18:14:41 +020025
Christina Quast235409a2015-06-24 16:05:09 +020026#define BUFLEN 512
Christina Quast71234252015-04-03 11:35:59 +020027
Christina Quastec9c09e2015-04-16 10:45:39 +020028#define CLK_MASTER true
29#define CLK_SLAVE false
30
31/* ===================================================*/
32/* Taken from iso7816_4.c */
33/* ===================================================*/
34/** Flip flop for send and receive char */
35#define USART_SEND 0
36#define USART_RCV 1
37
Christina Quast3eab56e2015-04-10 15:38:49 +020038
Christina Quast4db82e02015-04-11 18:14:41 +020039extern volatile ringbuf sim_rcv_buf;
Christina Quast95d66162015-04-09 22:38:47 +020040
41extern volatile bool rcvdChar;
42extern volatile uint32_t char_stat;
Christina Quast4ba4d222015-03-02 16:14:09 +010043
Christina Quaste4cbfe62015-04-20 13:07:28 +020044extern const Pin pinPhoneRST;
45
Christina Quast10b2e5a2015-02-25 18:40:15 +010046enum confNum {
Harald Welte16055642016-03-03 11:02:45 +010047 CFG_NUM_NONE = 0,
48#ifdef HAVE_SNIFFER
49 CFG_NUM_SNIFF,
50#endif
51#ifdef HAVE_CCID
52 CFG_NUM_CCID,
53#endif
54#ifdef HAVE_CARDEM
55 CFG_NUM_PHONE,
56#endif
57#ifdef HAVE_MITM
58 CFG_NUM_MITM,
59#endif
60 NUM_CONF
Christina Quast10b2e5a2015-02-25 18:40:15 +010061};
62
Christina Quastdb7b1ab2015-03-03 12:34:36 +010063/// CCIDDriverConfiguration Descriptors
64/// List of descriptors that make up the configuration descriptors of a
65/// device using the CCID driver.
66typedef struct {
67
Kévin Redon33d1eb72018-07-08 13:58:12 +020068 /// Configuration descriptor
69 USBConfigurationDescriptor configuration;
70 /// Interface descriptor
71 USBInterfaceDescriptor interface;
72 /// CCID descriptor
73 CCIDDescriptor ccid;
74 /// Bulk OUT endpoint descriptor
75 USBEndpointDescriptor bulkOut;
76 /// Bulk IN endpoint descriptor
77 USBEndpointDescriptor bulkIn;
78 /// Interrupt OUT endpoint descriptor
79 USBEndpointDescriptor interruptIn;
80 DFURT_IF_DESCRIPTOR_STRUCT
Christina Quastdb7b1ab2015-03-03 12:34:36 +010081} __attribute__ ((packed)) CCIDDriverConfigurationDescriptors;
82
Christina Quast4b1e98d2015-04-06 23:28:02 +020083extern const USBConfigurationDescriptor *configurationDescriptorsArr[];
84
Kévin Redon4fe99fa2018-06-25 15:53:19 +020085/*! Update USART baud rate to Fi/Di ratio
86 * @param[io] usart USART peripheral base address
87 * @param[in] fidi FiDi value as provided in TA interface byte
88 */
89void update_fidi(Usart_info *usart, uint8_t fidi);
Christina Quastbe235272015-05-02 17:56:32 +020090
Christina Quaste4cbfe62015-04-20 13:07:28 +020091void ISR_PhoneRST( const Pin *pPin);
Christina Quastdb7b1ab2015-03-03 12:34:36 +010092
Christina Quast95d66162015-04-09 22:38:47 +020093/* Configure functions */
94extern void Sniffer_configure( void );
95extern void CCID_configure( void );
Harald Welte2a6d3af2016-02-28 19:29:14 +010096extern void mode_cardemu_configure(void);
Christina Quast95d66162015-04-09 22:38:47 +020097extern void MITM_configure( void );
98
Christina Quast1edf3502015-02-27 13:33:52 +010099/* Init functions */
Christina Quast95d66162015-04-09 22:38:47 +0200100extern void Sniffer_init( void );
Christina Quastdb7b1ab2015-03-03 12:34:36 +0100101extern void CCID_init( void );
Harald Welte2a6d3af2016-02-28 19:29:14 +0100102extern void mode_cardemu_init(void);
Christina Quast1edf3502015-02-27 13:33:52 +0100103extern void MITM_init( void );
Christina Quast27c643d2015-02-24 19:09:08 +0100104
Christina Quastc0aa7692015-02-25 14:02:01 +0100105extern void SIMtrace_USB_Initialize( void );
Christina Quastc0aa7692015-02-25 14:02:01 +0100106
Christina Quast95d66162015-04-09 22:38:47 +0200107/* Exit functions */
108extern void Sniffer_exit( void );
109extern void CCID_exit( void );
Harald Welte2a6d3af2016-02-28 19:29:14 +0100110extern void mode_cardemu_exit(void);
Christina Quast95d66162015-04-09 22:38:47 +0200111extern void MITM_exit( void );
112
Christina Quast1edf3502015-02-27 13:33:52 +0100113/* Run functions */
114extern void Sniffer_run( void );
Christina Quastdb7b1ab2015-03-03 12:34:36 +0100115extern void CCID_run( void );
Harald Welte2a6d3af2016-02-28 19:29:14 +0100116extern void mode_cardemu_run(void);
Christina Quast1edf3502015-02-27 13:33:52 +0100117extern void MITM_run( void );
118
Kévin Redon7b734622018-06-06 16:13:48 +0200119/* IRQ functions */
Kévin Redon45ad62d2018-06-07 18:56:41 +0200120extern void Sniffer_usart0_irq(void);
Kévin Redon353351d2018-06-11 13:45:16 +0200121extern void Sniffer_usart1_irq(void);
Harald Welte3bafe432016-03-20 16:43:12 +0100122extern void mode_cardemu_usart0_irq(void);
123extern void mode_cardemu_usart1_irq(void);
124
Christina Quast531d10b2015-03-19 19:27:04 +0100125/* Timer helper function */
126void Timer_Init( void );
127void TC0_Counter_Reset( void );
128
Christina Quast1edf3502015-02-27 13:33:52 +0100129#endif /* SIMTRACE_H */