From: <lu...@us...> - 2009-06-09 14:05:18
|
Revision: 287 http://pyscard.svn.sourceforge.net/pyscard/?rev=287&view=rev Author: ludov Date: 2009-06-09 13:56:33 +0000 (Tue, 09 Jun 2009) Log Message: ----------- more debug Modified Paths: -------------- trunk/contrib/parseATR/parseATR.py Modified: trunk/contrib/parseATR/parseATR.py =================================================================== --- trunk/contrib/parseATR/parseATR.py 2009-06-08 13:54:54 UTC (rev 286) +++ trunk/contrib/parseATR/parseATR.py 2009-06-09 13:56:33 UTC (rev 287) @@ -47,6 +47,10 @@ def parseATR(atr_txt): atr_txt = normalize(atr_txt) atr = {} + + # the ATR itself as a list of integers + atr["atr"] = atr_txt + # store TS and T0 atr["TS"] = atr_txt[0] atr["T0"] = TDi = atr_txt[1] @@ -91,7 +95,7 @@ # Store TCK if (atr.has_key("TCK")): - atr["TCK"] = atr_txt[pointer] + atr["TCK"] = atr_txt[-1] return atr @@ -106,16 +110,16 @@ def TA2(v): F = v >> 4 D = v & 0xF - text = "Protocol to be used in spec mode: T=%s" % (D), + text = "Protocol to be used in spec mode: T=%s" % (D) if (F & 0x8): - text = text + " - Unable to change", + text += " - Unable to change" else: - text = text + " - Capable to change", + text += " - Capable to change" if (F & 0x1): - text = text + " - implicity defined" + text += " - implicity defined" else: - text = text + " - defined by interface bytes" + text += " - defined by interface bytes" return text @@ -181,9 +185,9 @@ return text def TC1(v): - text = "Extra guard time:", v, + text = "Extra guard time: %d" % v if (v == 255): - text += "(special value)" + text += " (special value)" return text def TC2(v): @@ -198,9 +202,9 @@ def TCn(i, v): text = "" if (T == 1): - text = "Error detection code: ", + text = "Error detection code: " if (v == 1): - text += "CRC"; + text += "CRC" else: if (v == 0): text += "LRC" @@ -333,7 +337,7 @@ if hb_category == None: return text - text += " Category indicator byte: %02X" % hb_category + text += " Category indicator byte: 0x%02X" % hb_category if hb_category == 0x00: text += " (compact TLV data object)\n"; @@ -372,6 +376,15 @@ return text +def compute_tck(atr): + # do not include TS byte + s = atr["atr"][0]; + for e in atr["atr"]: + s ^= e + # remove TCK + s ^= atr["atr"][-1]; + return s + def atr_display_txt(atr): TS = {0x3B: "Direct Convention", 0x3F: "Inverse Convention"} print "TS = 0x%02X --> %s" % (atr["TS"], TS[atr["TS"]]) @@ -398,8 +411,18 @@ print "0x%02X" % b, print print analyse_histrorical_bytes(atr["hb"]) - + + if (atr.has_key("TCK")): + print ("TCK = 0x%02X" % atr["TCK"]), + tck = compute_tck(atr) + if tck == atr["TCK"]: + print "(correct checksum)" + else: + print "WRONG CHECKSUM, expected 0x%02X" % tck + if __name__ == "__main__": - atr = parseATR("3B A7 00 40 18 80 65 A2 08 01 01 52") - #atr = parseATR("3F FF 95 00 FF 91 81 71 A0 47 00 44 4E 41 53 50 30 31 31 20 52 65 76 42") + #ATR = "3B A7 00 40 18 80 65 A2 08 01 01 52" + ATR = "3F FF 95 00 FF 91 81 71 A0 47 00 44 4E 41 53 50 30 31 31 20 52 65 76 42 30 36 4E" + atr = parseATR(ATR) + print "ATR:", ATR atr_display_txt(atr) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |