Skip to content

Commit

Permalink
Fix ISO7816 TCK parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
leonlynch committed Mar 17, 2023
1 parent 98a58e0 commit 407a7c1
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/iso7816.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @file iso7816.c
* @brief ISO/IEC 7816 definitions and helper functions
*
* Copyright (c) 2021 Leon Lynch
* Copyright (c) 2021, 2023 Leon Lynch
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down Expand Up @@ -149,11 +149,14 @@ int iso7816_atr_parse(const uint8_t* atr, size_t atr_len, struct iso7816_atr_inf
return r;
}

// If only T=0 is indicated, TCK is absent; otherwise it is mandatory
// Update protocol from latest TDi interface byte
protocol = *atr_info->TD[i] & ISO7816_ATR_Tx_OTHER_MASK; // T value according to ISO 7816-3:2006, 8.2.3
if (protocol != ISO7816_PROTOCOL_T0 &&
protocol != ISO7816_PROTOCOL_T15
) {

// If only T=0 is indicated, TCK is absent
// If T=0 and T=15 are present, TCK is mandatory
// For all other cases TCK is also mandatory
// See ISO 7816-3:2006, 8.2.5
if (protocol != ISO7816_PROTOCOL_T0) {
tck_mandatory = true;
}
} else {
Expand Down Expand Up @@ -405,12 +408,12 @@ static int iso7816_atr_parse_TC1(uint8_t TC1, struct iso7816_atr_info_t* atr_inf
return 0;
}

static int iso7816_atr_parse_TDi(unsigned int i, uint8_t TD1, struct iso7816_atr_info_t* atr_info)
static int iso7816_atr_parse_TDi(unsigned int i, uint8_t TDi, struct iso7816_atr_info_t* atr_info)
{
unsigned int T = (TD1 & ISO7816_ATR_Tx_OTHER_MASK);
unsigned int T = (TDi & ISO7816_ATR_Tx_OTHER_MASK);

if (i == 1) {
// TD1 only allows T=0 and T=1 as the preferred card protocl
// TD1 only allows T=0 or T=1 as the preferred card protocol
if (T != ISO7816_PROTOCOL_T0 &&
T != ISO7816_PROTOCOL_T1
) {
Expand Down

0 comments on commit 407a7c1

Please sign in to comment.