Kévin Redon | 9a12d68 | 2018-07-08 13:21:16 +0200 | [diff] [blame] | 1 | /* ISO7816-3 state machine for the card side |
| 2 | * |
| 3 | * (C) 2010-2017 by Harald Welte <hwelte@hmw-consulting.de> |
Kévin Redon | ebe672e | 2018-07-29 00:18:12 +0200 | [diff] [blame] | 4 | * (C) 2018 by sysmocom -s.f.m.c. GmbH, Author: Kevin Redon <kredon@sysmocom.de> |
Kévin Redon | 9a12d68 | 2018-07-08 13:21:16 +0200 | [diff] [blame] | 5 | * |
| 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 Welte | 9d3e382 | 2015-11-09 00:50:54 +0100 | [diff] [blame] | 20 | #pragma once |
| 21 | |
| 22 | #include <stdint.h> |
| 23 | |
| 24 | struct card_handle; |
| 25 | |
| 26 | enum card_io { |
| 27 | CARD_IO_VCC, |
| 28 | CARD_IO_RST, |
| 29 | CARD_IO_CLK, |
| 30 | }; |
| 31 | |
Kévin Redon | 7233cf8 | 2019-11-14 19:37:32 +0100 | [diff] [blame^] | 32 | /** 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 | */ |
| 43 | struct 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 Welte | 9d3e382 | 2015-11-09 00:50:54 +0100 | [diff] [blame] | 44 | |
| 45 | /* process a single byte received from the reader */ |
| 46 | void card_emu_process_rx_byte(struct card_handle *ch, uint8_t byte); |
| 47 | |
Harald Welte | 855ba9e | 2016-02-24 21:00:46 +0100 | [diff] [blame] | 48 | /* transmit a single byte to the reader */ |
| 49 | int card_emu_tx_byte(struct card_handle *ch); |
Harald Welte | 9d3e382 | 2015-11-09 00:50:54 +0100 | [diff] [blame] | 50 | |
| 51 | /* hardware driver informs us that a card I/O signal has changed */ |
| 52 | void 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 */ |
| 55 | int card_emu_set_atr(struct card_handle *ch, const uint8_t *atr, uint8_t len); |
| 56 | |
Harald Welte | 54cb3d0 | 2016-02-29 14:12:40 +0100 | [diff] [blame] | 57 | struct llist_head *card_emu_get_uart_tx_queue(struct card_handle *ch); |
Harald Welte | acae412 | 2016-03-02 10:27:58 +0100 | [diff] [blame] | 58 | void card_emu_have_new_uart_tx(struct card_handle *ch); |
Harald Welte | ff16065 | 2016-03-19 21:59:06 +0100 | [diff] [blame] | 59 | void card_emu_report_status(struct card_handle *ch); |
Harald Welte | 9d3e382 | 2015-11-09 00:50:54 +0100 | [diff] [blame] | 60 | |
| 61 | #define ENABLE_TX 0x01 |
| 62 | #define ENABLE_RX 0x02 |
| 63 | |
| 64 | int card_emu_uart_update_fidi(uint8_t uart_chan, unsigned int fidi); |
| 65 | int card_emu_uart_tx(uint8_t uart_chan, uint8_t byte); |
| 66 | void card_emu_uart_enable(uint8_t uart_chan, uint8_t rxtx); |
Harald Welte | c58bba0 | 2016-03-20 14:57:53 +0100 | [diff] [blame] | 67 | void card_emu_uart_wait_tx_idle(uint8_t uart_chan); |
Kévin Redon | ebe672e | 2018-07-29 00:18:12 +0200 | [diff] [blame] | 68 | void card_emu_uart_interrupt(uint8_t uart_chan); |