blob: c0ef62029ad1094f4303274e0d9d3022d2e0880a [file] [log] [blame]
Harald Welte06348362019-05-19 00:45:17 +02001#pragma once
Harald Weltea67be5f2020-09-03 10:04:36 +02002/* ISO7816-3 Finite State Machine
3 *
4 * (C) 2019-2020 by Harald Welte <laforge@gnumonks.org>
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 Welte06348362019-05-19 00:45:17 +020020
21#include <osmocom/core/fsm.h>
22struct card_uart;
23
24enum iso7816_3_event {
25 ISO7816_E_RX_SINGLE, /*!< single-byte data received on UART */
26 ISO7816_E_RX_COMPL, /*!< data receive complete on UART */
27 ISO7816_E_TX_COMPL, /*!< data transmit complete on UART */
28 ISO7816_E_POWER_UP_IND, /*!< Card powered up */
29 ISO7816_E_RESET_REL_IND, /*!< Reset released */
30 ISO7816_E_RX_ERR_IND, /*!< Uncorrectable Rx [parity] error */
31 ISO7816_E_TX_ERR_IND, /*!< Uncorrectable Rx [parity] error */
32 ISO7816_E_XCEIVE_TPDU_CMD, /*!< Ask for start of TPDU transmission */
33 /* allstate events */
34 ISO7816_E_WTIME_EXP, /*!< WTIME expired */
35 ISO7816_E_HW_ERR_IND, /*!< Hardware error (overcurrent, ...) */
36 ISO7816_E_SW_ERR_IND, /*!< Software error */
37 ISO7816_E_CARD_REMOVAL, /*!< card has been removed from slot */
38 ISO7816_E_POWER_DN_IND, /*!< Card powered down */
39 ISO7816_E_RESET_ACT_IND, /*!< Reset activated */
40 ISO7816_E_ABORT_REQ, /*!< Abort request (e.g. from CCID) */
41 /* TODO: PPS request */
Eric Wildad1edce2019-11-27 16:51:08 +010042 ISO7816_E_XCEIVE_PPS_CMD,
43 ISO7816_E_PPS_DONE_IND,
44 ISO7816_E_PPS_FAILED_IND,
Harald Welte06348362019-05-19 00:45:17 +020045 /* TODO: Clock stop request */
46 /* TODO: Rx FIFO overrun */
47 /* TODO: Rx buffer overrun */
48
49 /* internal events between FSMs in this file */
50 ISO7816_E_ATR_DONE_IND, /*!< ATR Done indication from ATR child FSM */
Harald Welte1ac9ef92019-10-09 22:20:16 +020051 ISO7816_E_ATR_ERR_IND, /*!< ATR Error indication from ATR child FSM */
Harald Welte06348362019-05-19 00:45:17 +020052 ISO7816_E_TPDU_DONE_IND, /*!< TPDU Done indication from TPDU child FSM */
Eric Wild9e622dc2019-11-27 14:43:16 +010053 ISO7816_E_TPDU_FAILED_IND, /*!< TPDU Failed indication from TPDU child FSM */
Harald Welte06348362019-05-19 00:45:17 +020054 ISO7816_E_TPDU_CLEAR_REQ, /*!< Return TPDU FSM to TPDU_S_INIT */
55};
56
57typedef void (*iso7816_user_cb)(struct osmo_fsm_inst *fi, int event, int cause, void *data);
58
59struct osmo_fsm_inst *iso7816_fsm_alloc(void *ctx, int log_level, const char *id,
60 struct card_uart *cuart, iso7816_user_cb user_cb,
61 void *ussr_priv);
62
63void *iso7816_fsm_get_user_priv(struct osmo_fsm_inst *fi);