Skip to content

Commit

Permalink
NFC: Add Skylanders support (#1553)
Browse files Browse the repository at this point in the history
* nfc: add skylanders support
* nfc: format sources

Co-authored-by: あく <[email protected]>
  • Loading branch information
gornekich and skotopes authored Aug 7, 2022
1 parent f3d7d7d commit 173c941
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 19 deletions.
3 changes: 2 additions & 1 deletion lib/nfc/parsers/troyka_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ bool troyka_parser_read(NfcWorker* nfc_worker, FuriHalNfcTxRxContext* tx_rx) {

MfClassicReader reader = {};
FuriHalNfcDevData* nfc_data = &nfc_worker->dev_data->nfc_data;
mf_classic_get_type(nfc_data->atqa[0], nfc_data->atqa[1], nfc_data->sak, &reader);
reader.type = mf_classic_get_classic_type(nfc_data->atqa[0], nfc_data->atqa[1], nfc_data->sak);

for(size_t i = 0; i < COUNT_OF(troyka_keys); i++) {
mf_classic_reader_add_sector(
&reader, troyka_keys[i].sector, troyka_keys[i].key_a, troyka_keys[i].key_b);
Expand Down
21 changes: 6 additions & 15 deletions lib/nfc/protocols/mifare_classic.c
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,9 @@ bool mf_classic_check_card_type(uint8_t ATQA0, uint8_t ATQA1, uint8_t SAK) {
UNUSED(ATQA1);
if((ATQA0 == 0x44 || ATQA0 == 0x04) && (SAK == 0x08 || SAK == 0x88 || SAK == 0x09)) {
return true;
} else if((ATQA0 == 0x01) && (ATQA1 == 0x0F) && (SAK == 0x01)) {
//skylanders support
return true;
} else if((ATQA0 == 0x42 || ATQA0 == 0x02) && (SAK == 0x18)) {
return true;
} else {
Expand All @@ -335,27 +338,15 @@ MfClassicType mf_classic_get_classic_type(int8_t ATQA0, uint8_t ATQA1, uint8_t S
UNUSED(ATQA1);
if((ATQA0 == 0x44 || ATQA0 == 0x04) && (SAK == 0x08 || SAK == 0x88 || SAK == 0x09)) {
return MfClassicType1k;
} else if((ATQA0 == 0x01) && (ATQA1 == 0x0F) && (SAK == 0x01)) {
//skylanders support
return MfClassicType1k;
} else if((ATQA0 == 0x42 || ATQA0 == 0x02) && (SAK == 0x18)) {
return MfClassicType4k;
}
return MfClassicType1k;
}

bool mf_classic_get_type(uint8_t ATQA0, uint8_t ATQA1, uint8_t SAK, MfClassicReader* reader) {
UNUSED(ATQA1);
furi_assert(reader);
memset(reader, 0, sizeof(MfClassicReader));

if((ATQA0 == 0x44 || ATQA0 == 0x04) && (SAK == 0x08 || SAK == 0x88 || SAK == 0x09)) {
reader->type = MfClassicType1k;
} else if((ATQA0 == 0x42 || ATQA0 == 0x02) && (SAK == 0x18)) {
reader->type = MfClassicType4k;
} else {
return false;
}
return true;
}

void mf_classic_reader_add_sector(
MfClassicReader* reader,
uint8_t sector,
Expand Down
2 changes: 0 additions & 2 deletions lib/nfc/protocols/mifare_classic.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ bool mf_classic_check_card_type(uint8_t ATQA0, uint8_t ATQA1, uint8_t SAK);

MfClassicType mf_classic_get_classic_type(int8_t ATQA0, uint8_t ATQA1, uint8_t SAK);

bool mf_classic_get_type(uint8_t ATQA0, uint8_t ATQA1, uint8_t SAK, MfClassicReader* reader);

uint8_t mf_classic_get_total_sectors_num(MfClassicType type);

uint8_t mf_classic_get_sector_trailer_block_num_by_sector(uint8_t sector);
Expand Down
3 changes: 2 additions & 1 deletion lib/nfc/protocols/mifare_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ MifareType mifare_common_get_type(uint8_t ATQA0, uint8_t ATQA1, uint8_t SAK) {
type = MifareTypeUltralight;
} else if(
((ATQA0 == 0x44 || ATQA0 == 0x04) && (SAK == 0x08 || SAK == 0x88 || SAK == 0x09)) ||
((ATQA0 == 0x42 || ATQA0 == 0x02) && (SAK == 0x18))) {
((ATQA0 == 0x42 || ATQA0 == 0x02) && (SAK == 0x18)) ||
((ATQA0 == 0x01) && (ATQA1 == 0x0F) && (SAK == 0x01))) {
type = MifareTypeClassic;
} else if(ATQA0 == 0x44 && ATQA1 == 0x03 && SAK == 0x20) {
type = MifareTypeDesfire;
Expand Down

0 comments on commit 173c941

Please sign in to comment.