Kévin Redon | 9a12d68 | 2018-07-08 13:21:16 +0200 | [diff] [blame] | 1 | /* 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 Quast | c0aa769 | 2015-02-25 14:02:01 +0100 | [diff] [blame] | 19 | #ifndef SIMTRACE_H |
| 20 | #define SIMTRACE_H |
Christina Quast | 32906bb | 2015-02-24 11:35:19 +0100 | [diff] [blame] | 21 | |
Christina Quast | 4db82e0 | 2015-04-11 18:14:41 +0200 | [diff] [blame] | 22 | #include "ringbuffer.h" |
Harald Welte | 1605564 | 2016-03-03 11:02:45 +0100 | [diff] [blame] | 23 | #include "board.h" |
Harald Welte | 5e6e8dc | 2017-11-28 20:58:06 +0100 | [diff] [blame] | 24 | #include <usb/device/dfu/dfu.h> |
Christina Quast | 4db82e0 | 2015-04-11 18:14:41 +0200 | [diff] [blame] | 25 | |
Christina Quast | 235409a | 2015-06-24 16:05:09 +0200 | [diff] [blame] | 26 | #define BUFLEN 512 |
Christina Quast | 7123425 | 2015-04-03 11:35:59 +0200 | [diff] [blame] | 27 | |
Christina Quast | ec9c09e | 2015-04-16 10:45:39 +0200 | [diff] [blame] | 28 | #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 Quast | 3eab56e | 2015-04-10 15:38:49 +0200 | [diff] [blame] | 38 | |
Christina Quast | 4db82e0 | 2015-04-11 18:14:41 +0200 | [diff] [blame] | 39 | extern volatile ringbuf sim_rcv_buf; |
Christina Quast | 95d6616 | 2015-04-09 22:38:47 +0200 | [diff] [blame] | 40 | |
| 41 | extern volatile bool rcvdChar; |
| 42 | extern volatile uint32_t char_stat; |
Christina Quast | 4ba4d22 | 2015-03-02 16:14:09 +0100 | [diff] [blame] | 43 | |
Christina Quast | e4cbfe6 | 2015-04-20 13:07:28 +0200 | [diff] [blame] | 44 | extern const Pin pinPhoneRST; |
| 45 | |
Christina Quast | 10b2e5a | 2015-02-25 18:40:15 +0100 | [diff] [blame] | 46 | enum confNum { |
Harald Welte | 1605564 | 2016-03-03 11:02:45 +0100 | [diff] [blame] | 47 | 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 Quast | 10b2e5a | 2015-02-25 18:40:15 +0100 | [diff] [blame] | 61 | }; |
| 62 | |
Christina Quast | db7b1ab | 2015-03-03 12:34:36 +0100 | [diff] [blame] | 63 | /// CCIDDriverConfiguration Descriptors |
| 64 | /// List of descriptors that make up the configuration descriptors of a |
| 65 | /// device using the CCID driver. |
| 66 | typedef struct { |
| 67 | |
Kévin Redon | 33d1eb7 | 2018-07-08 13:58:12 +0200 | [diff] [blame] | 68 | /// 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 Quast | db7b1ab | 2015-03-03 12:34:36 +0100 | [diff] [blame] | 81 | } __attribute__ ((packed)) CCIDDriverConfigurationDescriptors; |
| 82 | |
Christina Quast | 4b1e98d | 2015-04-06 23:28:02 +0200 | [diff] [blame] | 83 | extern const USBConfigurationDescriptor *configurationDescriptorsArr[]; |
| 84 | |
Kévin Redon | 4fe99fa | 2018-06-25 15:53:19 +0200 | [diff] [blame] | 85 | /*! 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 | */ |
| 89 | void update_fidi(Usart_info *usart, uint8_t fidi); |
Christina Quast | be23527 | 2015-05-02 17:56:32 +0200 | [diff] [blame] | 90 | |
Christina Quast | e4cbfe6 | 2015-04-20 13:07:28 +0200 | [diff] [blame] | 91 | void ISR_PhoneRST( const Pin *pPin); |
Christina Quast | db7b1ab | 2015-03-03 12:34:36 +0100 | [diff] [blame] | 92 | |
Christina Quast | 95d6616 | 2015-04-09 22:38:47 +0200 | [diff] [blame] | 93 | /* Configure functions */ |
| 94 | extern void Sniffer_configure( void ); |
| 95 | extern void CCID_configure( void ); |
Harald Welte | 2a6d3af | 2016-02-28 19:29:14 +0100 | [diff] [blame] | 96 | extern void mode_cardemu_configure(void); |
Christina Quast | 95d6616 | 2015-04-09 22:38:47 +0200 | [diff] [blame] | 97 | extern void MITM_configure( void ); |
| 98 | |
Christina Quast | 1edf350 | 2015-02-27 13:33:52 +0100 | [diff] [blame] | 99 | /* Init functions */ |
Christina Quast | 95d6616 | 2015-04-09 22:38:47 +0200 | [diff] [blame] | 100 | extern void Sniffer_init( void ); |
Christina Quast | db7b1ab | 2015-03-03 12:34:36 +0100 | [diff] [blame] | 101 | extern void CCID_init( void ); |
Harald Welte | 2a6d3af | 2016-02-28 19:29:14 +0100 | [diff] [blame] | 102 | extern void mode_cardemu_init(void); |
Christina Quast | 1edf350 | 2015-02-27 13:33:52 +0100 | [diff] [blame] | 103 | extern void MITM_init( void ); |
Christina Quast | 27c643d | 2015-02-24 19:09:08 +0100 | [diff] [blame] | 104 | |
Christina Quast | c0aa769 | 2015-02-25 14:02:01 +0100 | [diff] [blame] | 105 | extern void SIMtrace_USB_Initialize( void ); |
Christina Quast | c0aa769 | 2015-02-25 14:02:01 +0100 | [diff] [blame] | 106 | |
Christina Quast | 95d6616 | 2015-04-09 22:38:47 +0200 | [diff] [blame] | 107 | /* Exit functions */ |
| 108 | extern void Sniffer_exit( void ); |
| 109 | extern void CCID_exit( void ); |
Harald Welte | 2a6d3af | 2016-02-28 19:29:14 +0100 | [diff] [blame] | 110 | extern void mode_cardemu_exit(void); |
Christina Quast | 95d6616 | 2015-04-09 22:38:47 +0200 | [diff] [blame] | 111 | extern void MITM_exit( void ); |
| 112 | |
Christina Quast | 1edf350 | 2015-02-27 13:33:52 +0100 | [diff] [blame] | 113 | /* Run functions */ |
| 114 | extern void Sniffer_run( void ); |
Christina Quast | db7b1ab | 2015-03-03 12:34:36 +0100 | [diff] [blame] | 115 | extern void CCID_run( void ); |
Harald Welte | 2a6d3af | 2016-02-28 19:29:14 +0100 | [diff] [blame] | 116 | extern void mode_cardemu_run(void); |
Christina Quast | 1edf350 | 2015-02-27 13:33:52 +0100 | [diff] [blame] | 117 | extern void MITM_run( void ); |
| 118 | |
Kévin Redon | 7b73462 | 2018-06-06 16:13:48 +0200 | [diff] [blame] | 119 | /* IRQ functions */ |
Kévin Redon | 45ad62d | 2018-06-07 18:56:41 +0200 | [diff] [blame] | 120 | extern void Sniffer_usart0_irq(void); |
Kévin Redon | 353351d | 2018-06-11 13:45:16 +0200 | [diff] [blame] | 121 | extern void Sniffer_usart1_irq(void); |
Harald Welte | 3bafe43 | 2016-03-20 16:43:12 +0100 | [diff] [blame] | 122 | extern void mode_cardemu_usart0_irq(void); |
| 123 | extern void mode_cardemu_usart1_irq(void); |
| 124 | |
Christina Quast | 531d10b | 2015-03-19 19:27:04 +0100 | [diff] [blame] | 125 | /* Timer helper function */ |
| 126 | void Timer_Init( void ); |
| 127 | void TC0_Counter_Reset( void ); |
| 128 | |
Christina Quast | 1edf350 | 2015-02-27 13:33:52 +0100 | [diff] [blame] | 129 | #endif /* SIMTRACE_H */ |