-/* // let it be here. it like halt command, but maybe it will work in some strange cases\r
- uint8_t dummy_answer = 0;\r
- ReaderTransmit(&dummy_answer, 1, NULL);\r
- int timeout = GetCountSspClk() + AUTHENTICATION_TIMEOUT;\r
- // wait for the card to become ready again\r
- while(GetCountSspClk() < timeout) {};\r
-*/\r
- // it needs after success authentication\r
- mifare_classic_halt(pcs, *cuid);\r
+ uint8_t receivedAnswer[MAX_MIFARE_FRAME_SIZE];\r
+ uint8_t receivedAnswerPar[MAX_MIFARE_PARITY_SIZE];\r
+ // Transmit MIFARE_CLASSIC_AUTH\r
+ int len = mifare_sendcmd_short(pcs, false, keyType & 0x01 ? MIFARE_AUTH_KEYB : MIFARE_AUTH_KEYA, blockNo, receivedAnswer, receivedAnswerPar, NULL);\r
+ if (len != 4) return -2;\r
+ // Transmit encrypted reader nonce and reader answer\r
+ uint8_t mf_nr_ar[8] = NESTED_FIXED_NR_ENC;\r
+ memcpy(mf_nr_ar + 4, key, 4);\r
+ ReaderTransmitPar(mf_nr_ar, sizeof(mf_nr_ar), key + 4, NULL);\r
+ uint32_t save_timeout = iso14a_get_timeout(); // save standard timeout\r
+ iso14a_set_timeout(*auth_timeout); // set timeout for authentication response\r
+ len = ReaderReceive(receivedAnswer, receivedAnswerPar);\r
+ iso14a_set_timeout(save_timeout); // restore standard timeout\r
+ if (!len) return -2;\r