blob: 91b569f67832a6dccd3b9706eda3fb15bb0de1d7 [file] [log] [blame]
Harald Welte25a9a802017-05-08 13:30:09 +02001#pragma once
2
3#include <stdint.h>
4
5/* SIMtrace2 USB protocol */
6
7/* (C) 2015-2017 by Harald Welte <hwelte@hmw-consulting.de>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 *
23 */
24
25/***********************************************************************
26 * COMMON HEADER
27 ***********************************************************************/
28
29enum simtrace_msg_class {
30 SIMTRACE_MSGC_GENERIC = 0,
31 /* Card Emulation / Forwarding */
32 SIMTRACE_MSGC_CARDEM,
33 /* Modem Control (if modem is attached next to device */
34 SIMTRACE_MSGC_MODEM,
35 /* SIM protocol tracing */
36 SIMTRACE_MSGC_TRACE,
37
38 /* first vendor-specific request */
39 _SIMTRACE_MGSC_VENDOR_FIRST = 127,
40};
41
42enum simtrace_msg_type_generic {
43 /* Generic Error Message */
44 SIMTRACE_CMD_DO_ERROR = 0,
45 /* Request/Response for simtrace_board_info */
46 SIMTRACE_CMD_BD_BOARD_INFO,
47};
48
49/* SIMTRACE_MSGC_CARDEM */
50enum simtrace_msg_type_cardem {
51 /* TPDU Data to be transmitted to phone */
52 SIMTRACE_MSGT_DT_CEMU_TX_DATA = 1,
53 /* Set the ATR to be returned at phone-SIM reset */
54 SIMTRACE_MSGT_DT_CEMU_SET_ATR,
55 /* Get Statistics Request / Response */
56 SIMTRACE_MSGT_BD_CEMU_STATS,
57 /* Get Status Request / Response */
58 SIMTRACE_MSGT_BD_CEMU_STATUS,
59 /* Request / Confirm emulated card insert */
60 SIMTRACE_MSGT_DT_CEMU_CARDINSERT,
61 /* TPDU Data received from phomne */
62 SIMTRACE_MSGT_DO_CEMU_RX_DATA,
63 /* Indicate PTS request from phone */
64 SIMTRACE_MSGT_DO_CEMU_PTS,
65};
66
67/* SIMTRACE_MSGC_MODEM */
68enum simtrace_msg_type_modem {
69 /* Modem Control: Reset an attached modem */
70 SIMTRACE_MSGT_DT_MODEM_RESET = 1,
71 /* Modem Control: Select local / remote SIM */
72 SIMTRACE_MSGT_DT_MODEM_SIM_SELECT,
73 /* Modem Control: Status (WWAN LED, SIM Presence) */
74 SIMTRACE_MSGT_BD_MODEM_STATUS,
75};
76
77/* SIMTRACE_MSGC_TRACE */
78enum simtrace_msg_type_trace {
79 /* FIXME */
80 _dummy,
81};
82
83/* common message header */
84struct simtrace_msg_hdr {
85 uint8_t msg_class; /* simtrace_msg_class */
86 uint8_t msg_type; /* simtrace_msg_type_xxx */
87 uint8_t seq_nr;
88 uint8_t slot_nr; /* SIM slot number */
89 uint16_t _reserved;
90 uint16_t msg_len; /* length including header */
91 uint8_t payload[0];
92} __attribute__ ((packed));
93
94/***********************************************************************
95 * CARD EMULATOR / FORWARDER
96 ***********************************************************************/
97
98/* generic capabilities */
99enum simtrace_capability_generic {
100 /* compatible with 5V SIM card interface */
101 SIMTRACE_CAP_VOLT_5V,
102 /* compatible with 3.3V SIM card interface */
103 SIMTRACE_CAP_VOLT_3V3,
104 /* compatible with 1.8V SIM card interface */
105 SIMTRACE_CAP_VOLT_1V8,
106 /* Has LED1 */
107 SIMTRACE_CAP_LED_1,
108 /* Has LED2 */
109 SIMTRACE_CAP_LED_2,
110 /* Has Single-Pole Dual-Throw (local/remote SIM */
111 SIMTRACE_CAP_SPDT,
112 /* Has Bus-Switch (trace / MITM) */
113 SIMTRACE_CAP_BUS_SWITCH,
114 /* Can read VSIM via ADC */
115 SIMTRACE_CAP_VSIM_ADC,
116 /* Can read temperature via ADC */
117 SIMTRACE_CAP_TEMP_ADC,
118 /* Supports DFU for firmware update */
119 SIMTRACE_CAP_DFU,
120 /* Supports Ctrl EP command for erasing flash / return to SAM-BA */
121 SIMTRACE_CAP_ERASE_FLASH,
122 /* Can read the status of card insert contact */
123 SIMTRACE_CAP_READ_CARD_DET,
124 /* Can control the status of a simulated card insert */
125 SIMTRACE_CAP_ASSERT_CARD_DET,
126 /* Can toggle the hardware reset of an attached modem */
127 SIMTRACE_CAP_ASSERT_MODEM_RST,
128};
129
130/* vendor-specific capabilities of sysmoocm devices */
131enum simtrace_capability_vendor {
132 /* Can erase a peer SAM3 controller */
133 SIMTRACE_CAP_SYSMO_QMOD_ERASE_PEER,
134 /* Can read/write an attached EEPROM */
135 SIMTRACE_CAP_SYSMO_QMOD_RW_EEPROM,
136 /* can reset an attached USB hub */
137 SIMTRACE_CAP_SYSMO_QMOD_RESET_HUB,
138};
139
140
141/* SIMTRACE_CMD_BD_BOARD_INFO */
142struct simtrace_board_info {
143 struct {
144 char manufacturer[32];
145 char model[32];
146 char version[32];
147 } hardware;
148 struct {
149 /* who provided this software? */
150 char provider[32];
151 /* name of software image */
152 char name[32];
153 /* (git) version at build time */
154 char version[32];
155 /* built on which machine? */
156 char buildhost[32];
157 /* CRC-32 over software image */
158 uint32_t crc;
159 } software;
160 struct {
161 /* Maximum baud rate supported */
162 uint32_t max_baud_rate;
163 } speed;
164 /* number of bytes of generic capability bit-mask */
165 uint8_t cap_generic_bytes;
166 /* number of bytes of vendor capability bit-mask */
167 uint8_t cap_vendor_bytes;
168 uint8_t data[0];
169 /* cap_generic + cap_vendor */
170} __attribute__ ((packed));
171
172/***********************************************************************
173 * CARD EMULATOR / FORWARDER
174 ***********************************************************************/
175
176/* indicates a TPDU header is present in this message */
177#define CEMU_DATA_F_TPDU_HDR 0x00000001
178/* indicates last part of transmission in this direction */
179#define CEMU_DATA_F_FINAL 0x00000002
180/* incdicates a PB is present and we should continue with TX */
181#define CEMU_DATA_F_PB_AND_TX 0x00000004
182/* incdicates a PB is present and we should continue with RX */
183#define CEMU_DATA_F_PB_AND_RX 0x00000008
184
185/* CEMU_USB_MSGT_DT_CARDINSERT */
186struct cardemu_usb_msg_cardinsert {
187 uint8_t card_insert;
188} __attribute__ ((packed));
189
190/* CEMU_USB_MSGT_DT_SET_ATR */
191struct cardemu_usb_msg_set_atr {
192 uint8_t atr_len;
193 /* variable-length ATR data */
194 uint8_t atr[0];
195} __attribute__ ((packed));
196
197/* CEMU_USB_MSGT_DT_TX_DATA */
198struct cardemu_usb_msg_tx_data {
199 uint32_t flags;
200 uint16_t data_len;
201 /* variable-length TPDU data */
202 uint8_t data[0];
203} __attribute__ ((packed));
204
205/* CEMU_USB_MSGT_DO_RX_DATA */
206struct cardemu_usb_msg_rx_data {
207 uint32_t flags;
208 uint16_t data_len;
209 /* variable-length TPDU data */
210 uint8_t data[0];
211} __attribute__ ((packed));
212
213#define CEMU_STATUS_F_VCC_PRESENT 0x00000001
214#define CEMU_STATUS_F_CLK_ACTIVE 0x00000002
215#define CEMU_STATUS_F_RCEMU_ACTIVE 0x00000004
216#define CEMU_STATUS_F_CARD_INSERT 0x00000008
217#define CEMU_STATUS_F_RESET_ACTIVE 0x00000010
218
219/* CEMU_USB_MSGT_DO_STATUS */
220struct cardemu_usb_msg_status {
221 uint32_t flags;
222 /* phone-applied target voltage in mV */
223 uint16_t voltage_mv;
224 /* Fi/Di related information */
225 uint8_t fi;
226 uint8_t di;
227 uint8_t wi;
228 uint32_t waiting_time;
229} __attribute__ ((packed));
230
231/* CEMU_USB_MSGT_DO_PTS */
232struct cardemu_usb_msg_pts_info {
233 uint8_t pts_len;
234 /* PTS request as sent from reader */
235 uint8_t req[6];
236 /* PTS response as sent by card */
237 uint8_t resp[6];
238} __attribute__ ((packed));
239
240/* CEMU_USB_MSGT_DO_ERROR */
241struct cardemu_usb_msg_error {
242 uint8_t severity;
243 uint8_t subsystem;
244 uint16_t code;
245 uint8_t msg_len;
246 /* human-readable error message */
247 uint8_t msg[0];
248} __attribute__ ((packed));
249
250/***********************************************************************
251 * MODEM CONTROL
252 ***********************************************************************/
253
254/* SIMTRACE_MSGT_DT_MODEM_RESET */
255struct st_modem_reset {
256 /* 0: de-assert reset, 1: assert reset, 2: poulse reset */
257 uint8_t asserted;
258 /* if above is '2', duration of pulse in ms */
259 uint16_t pulse_duration_msec;
260} __attribute__((packed));
261
262/* SIMTRACE_MSGT_DT_MODEM_SIM_SELECT */
263struct st_modem_sim_select {
264 /* remote (1), local (0) */
265 uint8_t remote_sim;
266} __attribute__((packed));
267
268/* SIMTRACE_MSGT_BD_MODEM_STATUS */
269#define ST_MDM_STS_BIT_WWAN_LED (1 << 0)
270#define ST_MDM_STS_BIT_CARD_INSERTED (1 << 1)
271struct st_modem_status {
272 /* bit-field of supported status bits */
273 uint8_t supported_mask;
274 /* bit-field of current status bits */
275 uint8_t status_mask;
276 /* bit-field of changed status bits */
277 uint8_t changed_mask;
278} __attribute__((packed));