diff options
Diffstat (limited to 'reader_yhy.c')
-rw-r--r-- | reader_yhy.c | 52 |
1 files changed, 45 insertions, 7 deletions
diff --git a/reader_yhy.c b/reader_yhy.c index 7e0d8c3..41f20d8 100644 --- a/reader_yhy.c +++ b/reader_yhy.c @@ -48,18 +48,56 @@ int scan(){ uint16_t atqa = 0; uint8_t sak = 0; + uint8_t data[16]; + uint8_t bytes; for(yhy_sync_request(reader_fd, 1, &atqa); atqa; yhy_sync_request(reader_fd, 0, &atqa)){ - card.uid_length = yhy_sync_anticoll(reader_fd, card.uid, sizeof(card.uid)); - if(!card.uid_length){ - return 0; + sak = 0; + //ATQA should normally not be used as an indicator for UID length + //However, the YHY UL_SELECT command does not seem to work after CL1 anticollision for some reason + + //extended length UIDs + if(atqa & 0x00C0){ + card.uid_length = yhy_sync_ulselect(reader_fd, card.uid, sizeof(card.uid)); + //since we dont get either the CL2 SAK or any other method of identifying the particular type of PICC, just guess whether it's an NTAG + card.type = tag_unknown; + if(atqa == 0x0044){ + card.type = tag_ntag; + card.bytes_available = 140; + card.granularity = 4; + } + else{ + printf("PICC Parameters: ATQA %04X\n", atqa); + } + } + else{ + card.uid_length = yhy_sync_anticoll(reader_fd, card.uid, sizeof(card.uid)); + yhy_sync_select(reader_fd, card.uid, card.uid_length, &sak); + + card.type = tag_unknown; + if(atqa == 0x0004 && sak == 0x08){ + card.type = tag_mifare1; + card.bytes_available = 752; + card.granularity = 16; + } + else{ + printf("PICC Parameters: ATQA %04X SAK %02X\n", atqa, sak); + } } - - yhy_sync_select(reader_fd, card.uid, card.uid_length, &sak); - //TODO parse ATQA and SAK to detect tag type if(reader_tag_present(0, card) == TAG_READ_REQUESTED){ - //TODO read card data + //read card data + if(card.type == tag_ntag){ + //capability container in page 3, byte 2 + // + // //0x12 -> ntag213 + // //0x3e -> ntag215 + // //0x6d -> ntag216 + //user data in pages 4 trough 39 + bytes = yhy_sync_read(reader_fd, 3, data, sizeof(data)); + } + else if(card.type == tag_mifare1){ + } reader_tag_present(FLAG_TAG_LOCKED, card); } |