Kévin Redon has uploaded this change for review. ( https://gerrit.osmocom.org/10311
Change subject: cardem: use TC2 as WI and update WT after ATR ...................................................................... cardem: use TC2 as WI and update WT after ATR Change-Id: I3e51b16d557bc664f87563e1a3dce6642de474d2 --- M firmware/libcommon/source/card_emu.c 1 file changed, 33 insertions(+), 5 deletions(-) git pull ssh://gerrit.osmocom.org:29418/simtrace2 refs/changes/11/10311/1 diff --git a/firmware/libcommon/source/card_emu.c b/firmware/libcommon/source/card_emu.c index 51fd923..ad6b4d9 100644 --- a/firmware/libcommon/source/card_emu.c +++ b/firmware/libcommon/source/card_emu.c @@ -363,11 +363,39 @@ TRACE_DEBUG("%u: ATR TX: %02x\n\r", ch->num, byte); return 1; } else { /* The ATR has been completely transmitted */ - /* TODO update WI using optional TC2 and then update WT */ - //ch->wi = ISO7816_3_DEFAULT_WI; - /* update waiting time */ - //ch->waiting_time = ISO7816_3_INIT_WTIME; - //tc_etu_set_wtime(ch->tc_chan, ch->waiting_time); + /* search for TC2 to updated WI */ + ch->wi = ISO7816_3_DEFAULT_WI; + if (ch->atr.len >= 2 && ch->atr.atr[1] & 0xf0) { /* Y1 has some data */ + uint8_t atr_td1 = 2; + if (ch->atr.atr[1] & 0x10) { /* TA1 is present */ + atr_td1++; + } + if (ch->atr.atr[1] & 0x20) { /* TB1 is present */ + atr_td1++; + } + if (ch->atr.atr[1] & 0x40) { /* TC1 is present */ + atr_td1++; + } + if (ch->atr.atr[1] & 0x80) { /* TD1 is present */ + if (ch->atr.len > atr_td1 && ch->atr.atr[atr_td1] & 0xf0) { /* Y2 has some data */ + uint8_t atr_tc2 = atr_td1+1; + if (ch->atr.atr[atr_td1] & 0x10) { /* TA2 is present */ + atr_tc2++; + } + if (ch->atr.atr[atr_td1] & 0x20) { /* TB2 is present */ + atr_tc2++; + } + if (ch->atr.atr[atr_td1] & 0x40) { /* TC2 is present */ + if (ch->atr.len > atr_tc2 && ch->atr.atr[atr_tc2]) { /* TC2 encodes WI */ + ch->wi = ch->atr.atr[atr_tc2]; /* set WI */ + } + } + } + } + } + /* update waiting time (see ISO 7816-3 10.2) */ + ch->waiting_time = ch->wi * 960 * ch->fi; + tc_etu_set_wtime(ch->tc_chan, ch->waiting_time); /* reset PTS to initial state */ set_pts_state(ch, PTS_S_WAIT_REQ_PTSS); /* go to next state */ -- To view, visit https://gerrit.osmocom.org/10311 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: simtrace2 Gerrit-Branch: master Gerrit-MessageType: newchange Gerrit-Change-Id: I3e51b16d557bc664f87563e1a3dce6642de474d2 Gerrit-Change-Number: 10311 Gerrit-PatchSet: 1 Gerrit-Owner: Kévin Redon <kre...@sysmocom.de>