ISO7816-3 FSMs as osmo_fsm
This implements ISO 7816-3 T=0 as three finite state machines using osmo_fsm. Change-Id: I0145b77e6165d36d33f18ef3a452f2c37913bd73
This commit is contained in:
parent
6312b444b9
commit
06348367fa
|
@ -3,11 +3,7 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "ccid_proto.h"
|
#include "ccid_proto.h"
|
||||||
|
#include "logging.h"
|
||||||
enum {
|
|
||||||
DCCID,
|
|
||||||
DUSB,
|
|
||||||
};
|
|
||||||
|
|
||||||
#define NR_SLOTS 8
|
#define NR_SLOTS 8
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,40 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <osmocom/core/fsm.h>
|
||||||
|
struct card_uart;
|
||||||
|
|
||||||
|
enum iso7816_3_event {
|
||||||
|
ISO7816_E_RX_SINGLE, /*!< single-byte data received on UART */
|
||||||
|
ISO7816_E_RX_COMPL, /*!< data receive complete on UART */
|
||||||
|
ISO7816_E_TX_COMPL, /*!< data transmit complete on UART */
|
||||||
|
ISO7816_E_POWER_UP_IND, /*!< Card powered up */
|
||||||
|
ISO7816_E_RESET_REL_IND, /*!< Reset released */
|
||||||
|
ISO7816_E_RX_ERR_IND, /*!< Uncorrectable Rx [parity] error */
|
||||||
|
ISO7816_E_TX_ERR_IND, /*!< Uncorrectable Rx [parity] error */
|
||||||
|
ISO7816_E_XCEIVE_TPDU_CMD, /*!< Ask for start of TPDU transmission */
|
||||||
|
/* allstate events */
|
||||||
|
ISO7816_E_WTIME_EXP, /*!< WTIME expired */
|
||||||
|
ISO7816_E_HW_ERR_IND, /*!< Hardware error (overcurrent, ...) */
|
||||||
|
ISO7816_E_SW_ERR_IND, /*!< Software error */
|
||||||
|
ISO7816_E_CARD_REMOVAL, /*!< card has been removed from slot */
|
||||||
|
ISO7816_E_POWER_DN_IND, /*!< Card powered down */
|
||||||
|
ISO7816_E_RESET_ACT_IND, /*!< Reset activated */
|
||||||
|
ISO7816_E_ABORT_REQ, /*!< Abort request (e.g. from CCID) */
|
||||||
|
/* TODO: PPS request */
|
||||||
|
/* TODO: Clock stop request */
|
||||||
|
/* TODO: Rx FIFO overrun */
|
||||||
|
/* TODO: Rx buffer overrun */
|
||||||
|
|
||||||
|
/* internal events between FSMs in this file */
|
||||||
|
ISO7816_E_ATR_DONE_IND, /*!< ATR Done indication from ATR child FSM */
|
||||||
|
ISO7816_E_TPDU_DONE_IND, /*!< TPDU Done indication from TPDU child FSM */
|
||||||
|
ISO7816_E_TPDU_CLEAR_REQ, /*!< Return TPDU FSM to TPDU_S_INIT */
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef void (*iso7816_user_cb)(struct osmo_fsm_inst *fi, int event, int cause, void *data);
|
||||||
|
|
||||||
|
struct osmo_fsm_inst *iso7816_fsm_alloc(void *ctx, int log_level, const char *id,
|
||||||
|
struct card_uart *cuart, iso7816_user_cb user_cb,
|
||||||
|
void *ussr_priv);
|
||||||
|
|
||||||
|
void *iso7816_fsm_get_user_priv(struct osmo_fsm_inst *fi);
|
|
@ -3,6 +3,7 @@ LIBS?=-lasan $(shell pkg-config --libs libosmocore)
|
||||||
|
|
||||||
ccid_functionfs: ccid_main_functionfs.o \
|
ccid_functionfs: ccid_main_functionfs.o \
|
||||||
ccid_slot_sim.o \
|
ccid_slot_sim.o \
|
||||||
|
logging.o \
|
||||||
../ccid_common/ccid_proto.o \
|
../ccid_common/ccid_proto.o \
|
||||||
../ccid_common/ccid_device.o
|
../ccid_common/ccid_device.o
|
||||||
$(CC) $(CFLAGS) -o $@ $^ $(LIBS) -laio
|
$(CC) $(CFLAGS) -o $@ $^ $(LIBS) -laio
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include <linux/usb/functionfs.h>
|
#include <linux/usb/functionfs.h>
|
||||||
|
|
||||||
#include "ccid_proto.h"
|
#include "ccid_proto.h"
|
||||||
|
#include "logging.h"
|
||||||
|
|
||||||
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
||||||
#define cpu_to_le16(x) (x)
|
#define cpu_to_le16(x) (x)
|
||||||
|
@ -504,27 +505,6 @@ static const struct ccid_ops c_ops = {
|
||||||
.send_int = ccid_ops_send_int,
|
.send_int = ccid_ops_send_int,
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct log_info_cat log_info_cat[] = {
|
|
||||||
[DUSB] = {
|
|
||||||
.name = "USB",
|
|
||||||
.description = "USB Transport",
|
|
||||||
.enabled = 1,
|
|
||||||
.loglevel = LOGL_NOTICE,
|
|
||||||
},
|
|
||||||
[DCCID] = {
|
|
||||||
.name = "CCID",
|
|
||||||
.description = "CCID Core",
|
|
||||||
.color = "\033[1;35m",
|
|
||||||
.enabled = 1,
|
|
||||||
.loglevel = LOGL_DEBUG,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
static const struct log_info log_info = {
|
|
||||||
.cat = log_info_cat,
|
|
||||||
.num_cat = ARRAY_SIZE(log_info_cat),
|
|
||||||
};
|
|
||||||
|
|
||||||
static void *tall_main_ctx;
|
static void *tall_main_ctx;
|
||||||
|
|
||||||
static void signal_handler(int signal)
|
static void signal_handler(int signal)
|
||||||
|
|
|
@ -0,0 +1,47 @@
|
||||||
|
#include <osmocom/core/utils.h>
|
||||||
|
#include <osmocom/core/logging.h>
|
||||||
|
#include "logging.h"
|
||||||
|
|
||||||
|
static const struct log_info_cat log_info_cat[] = {
|
||||||
|
[DUSB] = {
|
||||||
|
.name = "USB",
|
||||||
|
.description = "USB Transport",
|
||||||
|
.enabled = 1,
|
||||||
|
.loglevel = LOGL_NOTICE,
|
||||||
|
},
|
||||||
|
[DCCID] = {
|
||||||
|
.name = "CCID",
|
||||||
|
.description = "USB-CCID Protocol",
|
||||||
|
.enabled = 1,
|
||||||
|
.loglevel = LOGL_DEBUG,
|
||||||
|
},
|
||||||
|
[DISO7816] = {
|
||||||
|
.name = "ISO7816",
|
||||||
|
.description = "ISO7816-3 State machines",
|
||||||
|
.enabled = 1,
|
||||||
|
.loglevel = LOGL_DEBUG,
|
||||||
|
},
|
||||||
|
[DATR] = {
|
||||||
|
.name = "ATR",
|
||||||
|
.description = "ATR (Answer To Reset) FSM",
|
||||||
|
.enabled = 1,
|
||||||
|
.loglevel = LOGL_DEBUG,
|
||||||
|
},
|
||||||
|
[DTPDU] = {
|
||||||
|
.name = "TPDU",
|
||||||
|
.description = "TPDU FSM",
|
||||||
|
.enabled = 1,
|
||||||
|
.loglevel = LOGL_DEBUG,
|
||||||
|
},
|
||||||
|
[DPPS] = {
|
||||||
|
.name = "PPS",
|
||||||
|
.description = "PPS (Protocol and Parameter Selection) FSM",
|
||||||
|
.enabled = 1,
|
||||||
|
.loglevel = LOGL_DEBUG,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const struct log_info log_info = {
|
||||||
|
.cat = log_info_cat,
|
||||||
|
.num_cat = ARRAY_SIZE(log_info_cat),
|
||||||
|
};
|
|
@ -0,0 +1,13 @@
|
||||||
|
#pragma once
|
||||||
|
#include <osmocom/core/logging.h>
|
||||||
|
|
||||||
|
enum {
|
||||||
|
DCCID,
|
||||||
|
DUSB,
|
||||||
|
DISO7816,
|
||||||
|
DATR,
|
||||||
|
DTPDU,
|
||||||
|
DPPS,
|
||||||
|
};
|
||||||
|
|
||||||
|
extern const struct log_info log_info;
|
|
@ -46,8 +46,37 @@ static const struct log_info_cat log_info_cat[] = {
|
||||||
},
|
},
|
||||||
[DCCID] = {
|
[DCCID] = {
|
||||||
.name = "CCID",
|
.name = "CCID",
|
||||||
.description = "CCID Core",
|
.description = "USB-CCID Protocol",
|
||||||
.color = "\033[1;35m",
|
.enabled = 1,
|
||||||
|
.loglevel = LOGL_DEBUG,
|
||||||
|
},
|
||||||
|
[DISO7816] = {
|
||||||
|
.name = "ISO7816",
|
||||||
|
.description = "ISO7816-3 State machines",
|
||||||
|
.enabled = 1,
|
||||||
|
.loglevel = LOGL_DEBUG,
|
||||||
|
},
|
||||||
|
[DATR] = {
|
||||||
|
.name = "ATR",
|
||||||
|
.description = "ATR (Answer To Reset) FSM",
|
||||||
|
.enabled = 1,
|
||||||
|
.loglevel = LOGL_DEBUG,
|
||||||
|
},
|
||||||
|
[DTPDU] = {
|
||||||
|
.name = "TPDU",
|
||||||
|
.description = "TPDU FSM",
|
||||||
|
.enabled = 1,
|
||||||
|
.loglevel = LOGL_DEBUG,
|
||||||
|
},
|
||||||
|
[DPPS] = {
|
||||||
|
.name = "PPS",
|
||||||
|
.description = "PPS (Protocol and Parameter Selection) FSM",
|
||||||
|
.enabled = 1,
|
||||||
|
.loglevel = LOGL_DEBUG,
|
||||||
|
},
|
||||||
|
[DCARD] = {
|
||||||
|
.name = "CARD",
|
||||||
|
.description = "Card FSM",
|
||||||
.enabled = 1,
|
.enabled = 1,
|
||||||
.loglevel = LOGL_DEBUG,
|
.loglevel = LOGL_DEBUG,
|
||||||
},
|
},
|
||||||
|
|
|
@ -3,6 +3,11 @@
|
||||||
#include <osmocom/core/logging.h>
|
#include <osmocom/core/logging.h>
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
|
DCCID,
|
||||||
DUSB,
|
DUSB,
|
||||||
DCCID
|
DISO7816,
|
||||||
|
DATR,
|
||||||
|
DTPDU,
|
||||||
|
DPPS,
|
||||||
|
DCARD,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue