Harald Welte | 0634836 | 2019-05-19 00:45:17 +0200 | [diff] [blame] | 1 | #pragma once |
Harald Welte | a67be5f | 2020-09-03 10:04:36 +0200 | [diff] [blame] | 2 | /* 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 Welte | 0634836 | 2019-05-19 00:45:17 +0200 | [diff] [blame] | 20 | |
| 21 | #include <osmocom/core/fsm.h> |
| 22 | struct card_uart; |
| 23 | |
| 24 | enum 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 Wild | ad1edce | 2019-11-27 16:51:08 +0100 | [diff] [blame] | 42 | ISO7816_E_XCEIVE_PPS_CMD, |
| 43 | ISO7816_E_PPS_DONE_IND, |
| 44 | ISO7816_E_PPS_FAILED_IND, |
Harald Welte | 0634836 | 2019-05-19 00:45:17 +0200 | [diff] [blame] | 45 | /* 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 Welte | 1ac9ef9 | 2019-10-09 22:20:16 +0200 | [diff] [blame] | 51 | ISO7816_E_ATR_ERR_IND, /*!< ATR Error indication from ATR child FSM */ |
Harald Welte | 0634836 | 2019-05-19 00:45:17 +0200 | [diff] [blame] | 52 | ISO7816_E_TPDU_DONE_IND, /*!< TPDU Done indication from TPDU child FSM */ |
Eric Wild | 9e622dc | 2019-11-27 14:43:16 +0100 | [diff] [blame] | 53 | ISO7816_E_TPDU_FAILED_IND, /*!< TPDU Failed indication from TPDU child FSM */ |
Harald Welte | 0634836 | 2019-05-19 00:45:17 +0200 | [diff] [blame] | 54 | ISO7816_E_TPDU_CLEAR_REQ, /*!< Return TPDU FSM to TPDU_S_INIT */ |
| 55 | }; |
| 56 | |
| 57 | typedef void (*iso7816_user_cb)(struct osmo_fsm_inst *fi, int event, int cause, void *data); |
| 58 | |
| 59 | struct 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 | |
| 63 | void *iso7816_fsm_get_user_priv(struct osmo_fsm_inst *fi); |