- uint8_t pos_td = 1;
- if ( (card_ptr->atr[1] & 0x10) == 0x10) pos_td++;
- if ( (card_ptr->atr[1] & 0x20) == 0x20) pos_td++;
- if ( (card_ptr->atr[1] & 0x40) == 0x40) pos_td++;
-
- // T0 indicate presence T=0 vs T=1. T=1 has checksum TCK
- if ( (card_ptr->atr[1] & 0x80) == 0x80) {
-
- pos_td++;
-
- // 1 == T1 , presence of checksum TCK
- if ( (card_ptr->atr[pos_td] & 0x01) == 0x01) {
- uint8_t chksum = 0;
- // xor property. will be zero when xored with chksum.
- for (uint8_t i = 1; i < len; ++i)
- chksum ^= card_ptr->atr[i];
- if ( chksum ) {
- if ( MF_DBGLEVEL > 2) DbpString("Wrong ATR checksum");
- }
- }
- }
-
- // for some reason we only get first byte of atr, if that is so, send dummy command to retrieve the rest of the atr
- if (len == 1) {
-
- uint8_t data[1] = {0};
- I2C_BufferWrite(data, len, I2C_DEVICE_CMD_SEND, I2C_DEVICE_ADDRESS_MAIN);
-
- if ( !I2C_WaitForSim() )
- return false;
-
- uint8_t len2 = I2C_BufferRead(card_ptr->atr + len, sizeof(card_ptr->atr) - len, I2C_DEVICE_CMD_READ, I2C_DEVICE_ADDRESS_MAIN);
- len = len + len2;
- }
-