NFC: fix creating MF Classic tags from "Add Manually" menu (BCC calulation and ATQA/SAK writing) (#2342)
* NFC: fix creating MF Classic cards from "Add Manually" menu (BCC calculation and AQTA/SAK writing) * NFC: Fix BCC/SAK/ATQA in unit_tests and SAK in nfc_generate_mf_classic Co-authored-by: gornekich <n.gorbadey@gmail.com>
This commit is contained in:
@@ -348,13 +348,37 @@ static void mf_classic_generator_test(uint8_t uid_len, MfClassicType type) {
|
||||
memcpy(atqa, nfc_dev->dev_data.nfc_data.atqa, 2);
|
||||
|
||||
MfClassicData* mf_data = &nfc_dev->dev_data.mf_classic_data;
|
||||
// Check the manufacturer block (should be uid[uid_len] + 0xFF[rest])
|
||||
// Check the manufacturer block (should be uid[uid_len] + BCC (for 4byte only) + SAK + ATQA0 + ATQA1 + 0xFF[rest])
|
||||
uint8_t manufacturer_block[16] = {0};
|
||||
memcpy(manufacturer_block, nfc_dev->dev_data.mf_classic_data.block[0].value, 16);
|
||||
mu_assert(
|
||||
memcmp(manufacturer_block, uid, uid_len) == 0,
|
||||
"manufacturer_block uid doesn't match the file\r\n");
|
||||
for(uint8_t i = uid_len; i < 16; i++) {
|
||||
|
||||
uint8_t position = 0;
|
||||
if(uid_len == 4) {
|
||||
position = uid_len;
|
||||
|
||||
uint8_t bcc = 0;
|
||||
|
||||
for(int i = 0; i < uid_len; i++) {
|
||||
bcc ^= uid[i];
|
||||
}
|
||||
|
||||
mu_assert(manufacturer_block[position] == bcc, "manufacturer_block bcc assert failed\r\n");
|
||||
} else {
|
||||
position = uid_len - 1;
|
||||
}
|
||||
|
||||
mu_assert(manufacturer_block[position + 1] == sak, "manufacturer_block sak assert failed\r\n");
|
||||
|
||||
mu_assert(
|
||||
manufacturer_block[position + 2] == atqa[0], "manufacturer_block atqa0 assert failed\r\n");
|
||||
|
||||
mu_assert(
|
||||
manufacturer_block[position + 3] == atqa[1], "manufacturer_block atqa1 assert failed\r\n");
|
||||
|
||||
for(uint8_t i = position + 4; i < 16; i++) {
|
||||
mu_assert(
|
||||
manufacturer_block[i] == 0xFF, "manufacturer_block[i] == 0xFF assert failed\r\n");
|
||||
}
|
||||
|
Reference in New Issue
Block a user