apdu decoding works

This commit is contained in:
merlokk 2019-07-04 17:27:03 +03:00
parent 88a8eba424
commit 26bc8a2889
2 changed files with 17 additions and 5 deletions

View File

@ -44,8 +44,8 @@ int apdu_decode(uint8_t *data, size_t len, APDU_STRUCT *apdu)
// case 3S (Lc + data)
if (len == 5U + b0 && b0 != 0)
{
apdu->case_type = 0x13;
apdu->lc = (hapdu->lc[1] << 8) + hapdu->lc[2];
apdu->case_type = 0x03;
apdu->lc = b0;
}
// case 4S (Lc + data + Le)

View File

@ -440,12 +440,24 @@ void nfc_process_iblock(uint8_t * buf, int len)
int status;
uint16_t reslen;
APDU_STRUCT apdu;
apdu_decode(buf + 1, len - 1, &apdu);
printf1(TAG_NFC,"Iblock: ");
dump_hex1(TAG_NFC, buf, len);
uint8_t apdu_offset = 1;
// NAD following
if (buf[0] & 0x04) apdu_offset++;
// CID following
if (buf[0] & 0x08) apdu_offset++;
APDU_STRUCT apdu;
if (apdu_decode(buf + apdu_offset, len - apdu_offset, &apdu)) {
printf1(TAG_NFC,"apdu decode error\n");
nfc_write_response(buf[0], SW_COND_USE_NOT_SATISFIED);
return;
}
printf1(TAG_NFC,"apdu ok. %scase=%02x cla=%02x ins=%02x p1=%02x p2=%02x lc=%d le=%d\n",
apdu.extended_apdu ? "[e]":"", apdu.case_type, apdu.cla, apdu.ins, apdu.p1, apdu.p2, apdu.lc, apdu.le);
// TODO this needs to be organized better
switch(apdu.ins)
{