blob: a3c1cf23d1d6cae049c6030553a0b6305cda2669 [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
Harald Welte8e7fca32017-05-07 16:14:33 +020032struct card_handle *card_emu_init(uint8_t slot_num, uint8_t tc_chan, uint8_t uart_chan,
33 uint8_t in_ep, uint8_t irq_ep);
Harald Welte9d3e3822015-11-09 00:50:54 +010034
35/* process a single byte received from the reader */
36void card_emu_process_rx_byte(struct card_handle *ch, uint8_t byte);
37
Harald Welte855ba9e2016-02-24 21:00:46 +010038/* transmit a single byte to the reader */
39int card_emu_tx_byte(struct card_handle *ch);
Harald Welte9d3e3822015-11-09 00:50:54 +010040
41/* hardware driver informs us that a card I/O signal has changed */
42void card_emu_io_statechg(struct card_handle *ch, enum card_io io, int active);
43
44/* User sets a new ATR to be returned during next card reset */
45int card_emu_set_atr(struct card_handle *ch, const uint8_t *atr, uint8_t len);
46
Harald Welte54cb3d02016-02-29 14:12:40 +010047struct llist_head *card_emu_get_uart_tx_queue(struct card_handle *ch);
Harald Welteacae4122016-03-02 10:27:58 +010048void card_emu_have_new_uart_tx(struct card_handle *ch);
Harald Welteff160652016-03-19 21:59:06 +010049void card_emu_report_status(struct card_handle *ch);
Harald Welte9d3e3822015-11-09 00:50:54 +010050
51#define ENABLE_TX 0x01
52#define ENABLE_RX 0x02
53
54int card_emu_uart_update_fidi(uint8_t uart_chan, unsigned int fidi);
55int card_emu_uart_tx(uint8_t uart_chan, uint8_t byte);
56void card_emu_uart_enable(uint8_t uart_chan, uint8_t rxtx);
Harald Weltec58bba02016-03-20 14:57:53 +010057void card_emu_uart_wait_tx_idle(uint8_t uart_chan);
Kévin Redonebe672e2018-07-29 00:18:12 +020058void card_emu_uart_interrupt(uint8_t uart_chan);