blob: 67f398895a6fbd7a0c34f020c27b52100abac17f [file] [log] [blame]
Kévin Redon9a12d682018-07-08 13:21:16 +02001/* SIMtrace 2 mode definitions
2 *
Kévin Redone0265462019-08-06 15:41:31 +02003 * Copyright (c) 2015-2017 by Harald Welte <hwelte@hmw-consulting.de>
4 * Copyright (c) 2018-2019, sysmocom -s.f.m.c. GmbH, Author: Kevin Redon <kredon@sysmocom.de>
Kévin Redon9a12d682018-07-08 13:21:16 +02005 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
19 */
Christina Quastc0aa7692015-02-25 14:02:01 +010020#ifndef SIMTRACE_H
21#define SIMTRACE_H
Christina Quast32906bb2015-02-24 11:35:19 +010022
Christina Quast4db82e02015-04-11 18:14:41 +020023#include "ringbuffer.h"
Harald Welte16055642016-03-03 11:02:45 +010024#include "board.h"
Harald Welte5e6e8dc2017-11-28 20:58:06 +010025#include <usb/device/dfu/dfu.h>
Christina Quast4db82e02015-04-11 18:14:41 +020026
Christina Quast235409a2015-06-24 16:05:09 +020027#define BUFLEN 512
Christina Quast71234252015-04-03 11:35:59 +020028
Christina Quastec9c09e2015-04-16 10:45:39 +020029#define CLK_MASTER true
30#define CLK_SLAVE false
31
32/* ===================================================*/
33/* Taken from iso7816_4.c */
34/* ===================================================*/
35/** Flip flop for send and receive char */
36#define USART_SEND 0
37#define USART_RCV 1
38
Christina Quast3eab56e2015-04-10 15:38:49 +020039
Christina Quast4db82e02015-04-11 18:14:41 +020040extern volatile ringbuf sim_rcv_buf;
Christina Quast95d66162015-04-09 22:38:47 +020041
42extern volatile bool rcvdChar;
43extern volatile uint32_t char_stat;
Christina Quast4ba4d222015-03-02 16:14:09 +010044
Christina Quaste4cbfe62015-04-20 13:07:28 +020045extern const Pin pinPhoneRST;
46
Christina Quast10b2e5a2015-02-25 18:40:15 +010047enum confNum {
Harald Welte16055642016-03-03 11:02:45 +010048 CFG_NUM_NONE = 0,
49#ifdef HAVE_SNIFFER
50 CFG_NUM_SNIFF,
51#endif
52#ifdef HAVE_CCID
53 CFG_NUM_CCID,
54#endif
55#ifdef HAVE_CARDEM
56 CFG_NUM_PHONE,
57#endif
58#ifdef HAVE_MITM
59 CFG_NUM_MITM,
60#endif
Kévin Redone0265462019-08-06 15:41:31 +020061 CFG_NUM_VERSION,
Harald Welte16055642016-03-03 11:02:45 +010062 NUM_CONF
Christina Quast10b2e5a2015-02-25 18:40:15 +010063};
64
Christina Quastdb7b1ab2015-03-03 12:34:36 +010065/// CCIDDriverConfiguration Descriptors
66/// List of descriptors that make up the configuration descriptors of a
67/// device using the CCID driver.
68typedef struct {
69
Kévin Redon33d1eb72018-07-08 13:58:12 +020070 /// Configuration descriptor
71 USBConfigurationDescriptor configuration;
72 /// Interface descriptor
73 USBInterfaceDescriptor interface;
74 /// CCID descriptor
75 CCIDDescriptor ccid;
76 /// Bulk OUT endpoint descriptor
77 USBEndpointDescriptor bulkOut;
78 /// Bulk IN endpoint descriptor
79 USBEndpointDescriptor bulkIn;
80 /// Interrupt OUT endpoint descriptor
81 USBEndpointDescriptor interruptIn;
82 DFURT_IF_DESCRIPTOR_STRUCT
Christina Quastdb7b1ab2015-03-03 12:34:36 +010083} __attribute__ ((packed)) CCIDDriverConfigurationDescriptors;
84
Christina Quast4b1e98d2015-04-06 23:28:02 +020085extern const USBConfigurationDescriptor *configurationDescriptorsArr[];
86
Kévin Redon4fe99fa2018-06-25 15:53:19 +020087/*! Update USART baud rate to Fi/Di ratio
88 * @param[io] usart USART peripheral base address
89 * @param[in] fidi FiDi value as provided in TA interface byte
90 */
91void update_fidi(Usart_info *usart, uint8_t fidi);
Christina Quastbe235272015-05-02 17:56:32 +020092
Christina Quaste4cbfe62015-04-20 13:07:28 +020093void ISR_PhoneRST( const Pin *pPin);
Christina Quastdb7b1ab2015-03-03 12:34:36 +010094
Christina Quast95d66162015-04-09 22:38:47 +020095/* Configure functions */
96extern void Sniffer_configure( void );
97extern void CCID_configure( void );
Harald Welte2a6d3af2016-02-28 19:29:14 +010098extern void mode_cardemu_configure(void);
Christina Quast95d66162015-04-09 22:38:47 +020099extern void MITM_configure( void );
100
Christina Quast1edf3502015-02-27 13:33:52 +0100101/* Init functions */
Christina Quast95d66162015-04-09 22:38:47 +0200102extern void Sniffer_init( void );
Christina Quastdb7b1ab2015-03-03 12:34:36 +0100103extern void CCID_init( void );
Harald Welte2a6d3af2016-02-28 19:29:14 +0100104extern void mode_cardemu_init(void);
Christina Quast1edf3502015-02-27 13:33:52 +0100105extern void MITM_init( void );
Christina Quast27c643d2015-02-24 19:09:08 +0100106
Christina Quastc0aa7692015-02-25 14:02:01 +0100107extern void SIMtrace_USB_Initialize( void );
Christina Quastc0aa7692015-02-25 14:02:01 +0100108
Christina Quast95d66162015-04-09 22:38:47 +0200109/* Exit functions */
110extern void Sniffer_exit( void );
111extern void CCID_exit( void );
Harald Welte2a6d3af2016-02-28 19:29:14 +0100112extern void mode_cardemu_exit(void);
Christina Quast95d66162015-04-09 22:38:47 +0200113extern void MITM_exit( void );
114
Christina Quast1edf3502015-02-27 13:33:52 +0100115/* Run functions */
116extern void Sniffer_run( void );
Christina Quastdb7b1ab2015-03-03 12:34:36 +0100117extern void CCID_run( void );
Harald Welte2a6d3af2016-02-28 19:29:14 +0100118extern void mode_cardemu_run(void);
Christina Quast1edf3502015-02-27 13:33:52 +0100119extern void MITM_run( void );
120
Kévin Redon7b734622018-06-06 16:13:48 +0200121/* IRQ functions */
Kévin Redon45ad62d2018-06-07 18:56:41 +0200122extern void Sniffer_usart0_irq(void);
Kévin Redon353351d2018-06-11 13:45:16 +0200123extern void Sniffer_usart1_irq(void);
Harald Welte3bafe432016-03-20 16:43:12 +0100124extern void mode_cardemu_usart0_irq(void);
125extern void mode_cardemu_usart1_irq(void);
126
Christina Quast531d10b2015-03-19 19:27:04 +0100127/* Timer helper function */
128void Timer_Init( void );
129void TC0_Counter_Reset( void );
130
Christina Quast1edf3502015-02-27 13:33:52 +0100131#endif /* SIMTRACE_H */