blob: aaa07c508ac7287ce5cbb48a09a915c7e6454ad7 [file] [log] [blame]
Kévin Redon9a12d682018-07-08 13:21:16 +02001/* ISO7816-3 state machine for the card side
2 *
3 * (C) 2010-2017 by Harald Welte <hwelte@hmw-consulting.de>
Kévin Redonebe672e2018-07-29 00:18:12 +02004 * (C) 2018 by 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 */
Harald Welte9d3e3822015-11-09 00:50:54 +010020#pragma once
21
22#include <stdint.h>
23
24struct card_handle;
25
26enum card_io {
27 CARD_IO_VCC,
28 CARD_IO_RST,
29 CARD_IO_CLK,
30};
31
Kévin Redon7233cf82019-11-14 19:37:32 +010032/** initialise card slot
33 * @param[in] slot_num slot number (arbitrary number)
34 * @param[in] tc_chan timer counter channel (to measure the ETU)
35 * @param[in] uart_chan UART peripheral channel
36 * @param[in] in_ep USB IN end point number
37 * @param[in] irq_ep USB INTerrupt end point number
38 * @param[in] vcc_active initial VCC signal state (true = on)
39 * @param[in] in_reset initial RST signal state (true = reset asserted)
40 * @param[in] clocked initial CLK signat state (true = active)
41 * @return main card handle reference
42 */
43struct card_handle *card_emu_init(uint8_t slot_num, uint8_t tc_chan, uint8_t uart_chan, uint8_t in_ep, uint8_t irq_ep, bool vcc_active, bool in_reset, bool clocked);
Harald Welte9d3e3822015-11-09 00:50:54 +010044
45/* process a single byte received from the reader */
46void card_emu_process_rx_byte(struct card_handle *ch, uint8_t byte);
47
Harald Welte855ba9e2016-02-24 21:00:46 +010048/* transmit a single byte to the reader */
49int card_emu_tx_byte(struct card_handle *ch);
Harald Welte9d3e3822015-11-09 00:50:54 +010050
51/* hardware driver informs us that a card I/O signal has changed */
52void card_emu_io_statechg(struct card_handle *ch, enum card_io io, int active);
53
54/* User sets a new ATR to be returned during next card reset */
55int card_emu_set_atr(struct card_handle *ch, const uint8_t *atr, uint8_t len);
56
Harald Welte54cb3d02016-02-29 14:12:40 +010057struct llist_head *card_emu_get_uart_tx_queue(struct card_handle *ch);
Harald Welteacae4122016-03-02 10:27:58 +010058void card_emu_have_new_uart_tx(struct card_handle *ch);
Harald Welte140f0072019-12-16 10:23:32 +010059void card_emu_report_status(struct card_handle *ch, bool report_on_irq);
Harald Welte9d3e3822015-11-09 00:50:54 +010060
61#define ENABLE_TX 0x01
62#define ENABLE_RX 0x02
63
64int card_emu_uart_update_fidi(uint8_t uart_chan, unsigned int fidi);
65int card_emu_uart_tx(uint8_t uart_chan, uint8_t byte);
66void card_emu_uart_enable(uint8_t uart_chan, uint8_t rxtx);
Harald Weltec58bba02016-03-20 14:57:53 +010067void card_emu_uart_wait_tx_idle(uint8_t uart_chan);
Kévin Redonebe672e2018-07-29 00:18:12 +020068void card_emu_uart_interrupt(uint8_t uart_chan);