From 686cbf011e8f42f21297f7d9c7b148fe1c03ac8a Mon Sep 17 00:00:00 2001 From: chenzitai Date: Sat, 28 Jul 2018 01:28:55 +0100 Subject: [PATCH] Add decode functions for card response in anti collision phase (cherry picked from commit b4ca798) --- Software/Chameleon/ISO14443.py | 36 +++++++++++++++++++++++++++++----- Software/Chameleon/Log.py | 2 ++ 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/Software/Chameleon/ISO14443.py b/Software/Chameleon/ISO14443.py index 4956232..e5242b8 100644 --- a/Software/Chameleon/ISO14443.py +++ b/Software/Chameleon/ISO14443.py @@ -32,10 +32,15 @@ ReaderTrafficTypes = { 0x7: "FSD:128 ", 0x8: "FSD:256 " }, + } CardTrafficTypes = { - + "SAK":{ + 0x04: "UID NOT Complete ", + 0x20: "UID complete, PICC compliant with 14443-4 ", + 0x00: "UID complete, PICC NOT compliant with 14443-4" + } } def CRC_A(data): @@ -43,9 +48,9 @@ def CRC_A(data): def CRC_A_check(data): datalen = len(data) - # Short frame or no space for CRC skip check - if(datalen < 4 ): - return + # Short frame/SAK or no space for CRC skip check + if(datalen < 3 ): + return True crc = CRC_A(bytearray(data[0:datalen-2])).to_bytes(2,'little') if (data[datalen-2:datalen] == crc): @@ -70,9 +75,10 @@ def parseReader(data): # SELECT Command elif (byteCount== 9 and data[0] in ReaderTrafficTypes["SEL"] and data[1] == 0x70): + # TODO: distinguish CT+uid012+BCC and uid0123+BCC note += "SELECT - " note += ReaderTrafficTypes["SEL"][data[0]] - note += "UID_CLn:" + binascii.hexlify(data[2:7]).decode() + " " + note += "UID_CLn:" + binascii.hexlify(data[2:6]).decode() + " " # Check CRC for SELECT if(not CRC_A_check(data)): note+=" WRONG CRC " @@ -111,4 +117,24 @@ def parseReader(data): return note def parseCard(data): + + byteCount = len(data) + note = "" + + # ATQA: RRRR XXXX XXRX XXXX + if(byteCount == 2 and (data[0] & 0x20 == 0x00) and (data[1] & 0xf0 == 0x00)): + note += "ATQA - " + note += binascii.hexlify(data).decode() + # SAK + elif (byteCount == 3 and (data[0] & (~0x24)) == 0x00): + note += "SAK - " + note += CardTrafficTypes["SAK"][(data[2] & 0x24)] + if not CRC_A_check(data): + note += " WRONG CRC " + # UID + elif (byteCount == 5 and (data[0] ^ data[1] ^ data[2] ^ data[3]) == data[4] ): + note += "UID Resp - CLn " + + return note + pass \ No newline at end of file diff --git a/Software/Chameleon/Log.py b/Software/Chameleon/Log.py index 61d2098..aa0d7a9 100644 --- a/Software/Chameleon/Log.py +++ b/Software/Chameleon/Log.py @@ -142,6 +142,8 @@ def parseBinary(binaryStream, decode=False): # Decode the data from Reader if(event == 0x44 or event == 0x45): note = iso14443_3.parseReader(binascii.a2b_hex(logData)) + elif (event == 0x46 or event == 0x47): + note = iso14443_3.parseCard(binascii.a2b_hex(logData)) # Create log entry as dict and append it to event list logEntry = { 'eventName': eventTypes[event]['name'],