summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2010-11-21 20:18:23 +0100
committerHarald Welte <laforge@gnumonks.org>2010-11-21 20:18:23 +0100
commitde125b725076e84134d5e9e9d3c56d3ef0bcf075 (patch)
treeb10ba0cf892989be07a6c6bb50163f43e8390b1f
parente50e2f8c62a262c6ee109204b30b485a5bb3c074 (diff)
simtrace: Make sure ATR is sent in its own RCTX and we re-allocate in time
-rw-r--r--firmware/src/simtrace/iso7816_uart.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/firmware/src/simtrace/iso7816_uart.c b/firmware/src/simtrace/iso7816_uart.c
index 12669c4..cd1a2f0 100644
--- a/firmware/src/simtrace/iso7816_uart.c
+++ b/firmware/src/simtrace/iso7816_uart.c
@@ -102,6 +102,7 @@ struct iso7816_3_handle {
struct simtrace_hdr sh;
+ int rctx_must_be_sent;
struct req_ctx *rctx;
};
@@ -325,6 +326,8 @@ process_byte_atr(struct iso7816_3_handle *ih, u_int8_t byte)
case ATR_S_WAIT_TCK:
/* FIXME: process and verify the TCK */
set_atr_state(ih, ATR_S_DONE);
+ /* send off the USB context */
+ ih->rctx_must_be_sent = 1;
/* update the waiting time */
ih->waiting_time = 960 * di_table[ih->di] * ih->wi;
tc_etu_set_wtime(ih->waiting_time);
@@ -469,6 +472,11 @@ static void process_byte(struct iso7816_3_handle *ih, u_int8_t byte)
goto out_silent;
}
+ /* The USB buffer could be gone in case the timer expired or code above
+ * this line explicitly sent it off */
+ if (!ih->rctx)
+ refill_rctx(ih);
+
rctx = ih->rctx;
if (!rctx) {
DEBUGPCR("==> Lost byte, missing rctx");
@@ -479,8 +487,10 @@ static void process_byte(struct iso7816_3_handle *ih, u_int8_t byte)
rctx->data[rctx->tot_len] = byte;
rctx->tot_len++;
- if (rctx->tot_len >= rctx->size)
+ if (rctx->tot_len >= rctx->size || ih->rctx_must_be_sent) {
+ ih->rctx_must_be_sent = 0;
send_rctx(ih);
+ }
out_silent:
if (new_state != -1)
personal git repositories of Harald Welte. Your mileage may vary