aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Wild <ewild@sysmocom.de>2019-11-11 14:22:52 +0100
committerEric Wild <ewild@sysmocom.de>2019-11-11 14:22:52 +0100
commit95b7503977bbaea626f7c4a2780e626ccd00c17b (patch)
tree58b673789d6a0832447f874f2d3613ba8dcdc9e4
parent6e1ad837b26bc57a7427b454e591d2d81b13d3f8 (diff)
fsm completion event handling from main loophoernchen/wip_atr
-rw-r--r--ccid_common/ccid_device.h3
-rw-r--r--ccid_common/ccid_slot_fsm.c49
-rw-r--r--sysmoOCTSIM/main.c8
3 files changed, 41 insertions, 19 deletions
diff --git a/ccid_common/ccid_device.h b/ccid_common/ccid_device.h
index 38a71db..41222d4 100644
--- a/ccid_common/ccid_device.h
+++ b/ccid_common/ccid_device.h
@@ -57,6 +57,8 @@ struct ccid_slot {
struct ccid_pars_decoded proposed_pars;
/* default parameters; applied on ResetParameters */
const struct ccid_pars_decoded *default_pars;
+ uint32_t event;
+ void* event_data;
};
/* CCID operations provided by USB transport layer */
@@ -86,6 +88,7 @@ struct ccid_slot_ops {
const struct ccid_pars_decoded *pars_dec);
int (*set_rate_and_clock)(struct ccid_slot *cs, uint32_t freq_hz, uint32_t rate_bps);
void (*icc_set_insertion_status)(struct ccid_slot *cs, bool present);
+ int (*handle_fsm_events)(struct ccid_slot *cs, bool enable);
};
/* An instance of CCID (i.e. a card reader device) */
diff --git a/ccid_common/ccid_slot_fsm.c b/ccid_common/ccid_slot_fsm.c
index 8d38f29..d1b028c 100644
--- a/ccid_common/ccid_slot_fsm.c
+++ b/ccid_common/ccid_slot_fsm.c
@@ -110,12 +110,35 @@ static void iso_fsm_clot_user_cb(struct osmo_fsm_inst *fi, int event, int cause,
{
struct iso_fsm_slot *ss = iso7816_fsm_get_user_priv(fi);
struct ccid_slot *cs = ss->cs;
+
+ switch (event) {
+ case ISO7816_E_ATR_DONE_IND:
+ case ISO7816_E_TPDU_DONE_IND:
+ case ISO7816_E_TPDU_FAILED_IND:
+ case ISO7816_E_PPS_DONE_IND:
+ case ISO7816_E_PPS_FAILED_IND:
+ cs->event = event;
+ cs->event_data = data;
+ delay_us(100);
+ break;
+ default:
+ LOGPCS(cs, LOGL_NOTICE, "%s(event=%d, cause=%d, data=%p) unhandled\n",
+ __func__, event, cause, data);
+ break;
+ }
+}
+
+static int iso_handle_fsm_events(struct ccid_slot *cs, bool enable){
+ struct iso_fsm_slot *ss = ccid_slot2iso_fsm_slot(cs);
struct msgb *tpdu, *resp;
+ uint32_t event = cs->event;
+ void* data = cs->event_data;
+ cs->event = 0;
switch (event) {
case ISO7816_E_ATR_DONE_IND:
tpdu = data;
- LOGPCS(cs, LOGL_DEBUG, "%s(event=%d, cause=%d, data=%s)\n", __func__, event, cause,
+ LOGPCS(cs, LOGL_DEBUG, "%s(event=%d, data=%s)\n", __func__, event,
msgb_hexdump(tpdu));
resp = ccid_gen_data_block(cs, ss->seq, CCID_CMD_STATUS_OK, 0,
msgb_data(tpdu), msgb_length(tpdu));
@@ -124,7 +147,7 @@ static void iso_fsm_clot_user_cb(struct osmo_fsm_inst *fi, int event, int cause,
break;
case ISO7816_E_TPDU_DONE_IND:
tpdu = data;
- LOGPCS(cs, LOGL_DEBUG, "%s(event=%d, cause=%d, data=%s)\n", __func__, event, cause,
+ LOGPCS(cs, LOGL_DEBUG, "%s(event=%d, data=%s)\n", __func__, event,
msgb_hexdump(tpdu));
resp = ccid_gen_data_block(cs, ss->seq, CCID_CMD_STATUS_OK, 0, msgb_l2(tpdu), msgb_l2len(tpdu));
ccid_slot_send_unbusy(cs, resp);
@@ -132,7 +155,7 @@ static void iso_fsm_clot_user_cb(struct osmo_fsm_inst *fi, int event, int cause,
break;
case ISO7816_E_TPDU_FAILED_IND:
tpdu = data;
- LOGPCS(cs, LOGL_DEBUG, "%s(event=%d, cause=%d, data=%s)\n", __func__, event, cause,
+ LOGPCS(cs, LOGL_DEBUG, "%s(event=%d, data=%s)\n", __func__, event,
msgb_hexdump(tpdu));
/* FIXME: other error causes than card removal?*/
resp = ccid_gen_data_block(cs, ss->seq, CCID_CMD_STATUS_FAILED, CCID_ERR_ICC_MUTE, msgb_l2(tpdu), 0);
@@ -167,8 +190,8 @@ static void iso_fsm_clot_user_cb(struct osmo_fsm_inst *fi, int event, int cause,
msgb_free(tpdu);
break;
default:
- LOGPCS(cs, LOGL_NOTICE, "%s(event=%d, cause=%d, data=%p) unhandled\n",
- __func__, event, cause, data);
+ LOGPCS(cs, LOGL_NOTICE, "%s(event=%d, data=%p) unhandled\n",
+ __func__, event, data);
break;
}
}
@@ -177,7 +200,7 @@ static int iso_fsm_slot_xfr_block_async(struct ccid_slot *cs, struct msgb *msg,
const struct ccid_pc_to_rdr_xfr_block *xfb)
{
struct iso_fsm_slot *ss = ccid_slot2iso_fsm_slot(cs);
- struct msgb *tpdu;
+
if(!cs->icc_present)
return -CCID_ERR_ICC_MUTE;
@@ -188,17 +211,10 @@ static int iso_fsm_slot_xfr_block_async(struct ccid_slot *cs, struct msgb *msg,
OSMO_ASSERT(xfb->wLevelParameter == 0x0000);
OSMO_ASSERT(msgb_length(msg) > xfb->hdr.dwLength);
- /* 'msg' contains the raw CCID message as received from USB. We could create
- * a new message buffer for the ISO7816 side here or we could 'strip the CCID
- * header off the start of the message. Let's KISS and do a copy here */
- tpdu = msgb_alloc(512, "TPDU");
- OSMO_ASSERT(tpdu);
- memcpy(msgb_data(tpdu), xfb->abData, xfb->hdr.dwLength);
- msgb_put(tpdu, xfb->hdr.dwLength);
- msgb_free(msg);
+ msgb_pull(msg, 10);
- LOGPCS(cs, LOGL_DEBUG, "scheduling TPDU transfer: %s\n", msgb_hexdump(tpdu));
- osmo_fsm_inst_dispatch(ss->fi, ISO7816_E_XCEIVE_TPDU_CMD, tpdu);
+ LOGPCS(cs, LOGL_DEBUG, "scheduling TPDU transfer: %s\n", msgb_hexdump(msg));
+ osmo_fsm_inst_dispatch(ss->fi, ISO7816_E_XCEIVE_TPDU_CMD, msg);
/* continues in iso_fsm_clot_user_cb once response/error/timeout is received */
return 0;
}
@@ -332,4 +348,5 @@ const struct ccid_slot_ops iso_fsm_slot_ops = {
.set_clock = iso_fsm_slot_set_clock,
.set_params = iso_fsm_slot_set_params,
.set_rate_and_clock = iso_fsm_slot_set_rate_and_clock,
+ .handle_fsm_events = iso_handle_fsm_events,
};
diff --git a/sysmoOCTSIM/main.c b/sysmoOCTSIM/main.c
index b44e362..de19cae 100644
--- a/sysmoOCTSIM/main.c
+++ b/sysmoOCTSIM/main.c
@@ -316,7 +316,7 @@ static struct msgb *ccid_gen_notify_slot_status(uint8_t old_bm, uint8_t new_bm)
{
uint8_t statusbytes[2] = {0};
//struct msgb *msg = ccid_msgb_alloc();
- struct msgb *msg = msgb_alloc(64, "IRQ");
+ struct msgb *msg = msgb_alloc(300,"IRQ");
struct ccid_rdr_to_pc_notify_slot_change *nsc = msgb_put(msg, sizeof(*nsc) + sizeof(statusbytes));
nsc->bMessageType = RDR_to_PC_NotifySlotChange;
@@ -1191,6 +1191,9 @@ int main(void)
command_try_recv();
poll_card_detect();
submit_next_irq();
+ for (int i = 0; i < usb_fs_descs.ccid.class.bMaxSlotIndex; i++){
+ g_ci.slot_ops->handle_fsm_events(&g_ci.slot[i], true);
+ }
feed_ccid();
osmo_timers_update();
int qs = llist_count_at(&g_ccid_s.free_q);
@@ -1201,13 +1204,12 @@ int main(void)
msgb_free(msg);
}
if(qs < NUM_OUT_BUF)
- for (int i= 0; i < qs-NUM_OUT_BUF; i++){
+ for (int i= 0; i < NUM_OUT_BUF-qs; i++){
struct msgb *msg = msgb_alloc(300,"ccid");
OSMO_ASSERT(msg);
/* return the message back to the queue of free message buffers */
llist_add_tail_at(&msg->list, &g_ccid_s.free_q);
}
-
}
}