Make it possible for a card/application class to specify the P1 used for SELECT in the file case

Add an Application class (and AID) for NFC Forum Tag Type 4


git-svn-id: svn+ssh://localhost/home/henryk/svn/cyberflex-shell/trunk@261 f711b948-2313-0410-aaa9-d29f33439f0b
This commit is contained in:
hploetz 2008-06-10 03:34:21 +00:00
parent 6ea70a8403
commit 424a3c14c5
4 changed files with 43 additions and 2 deletions

View File

@ -66,6 +66,8 @@ class Card:
"\xD2\x76\x00\x00\x25\x46\x53\x02\x00": ("DF_FAHRSCHEIN_NEU", "Fahrschein", {"fid": "\xB0\x00"}),
"\xD2\x76\x00\x00\x25\x48\x42\x02\x00": ("DF_BANKING_20" , "HBCI", {"fid": "\xA6\x00"}),
"\xD2\x76\x00\x00\x25\x4E\x50\x01\x00": ("DF_NOTEPAD", "Notepad", {"fid": "\xA6\x10"}),
"\xd2\x76\x00\x00\x85\x01\x00": ("NFC_TYPE_4", "NFC NDEF Application on tag type 4", {"alias": ("nfc",)}, ),
}
# Alias for DF_BOERSE_NEU
APPLICATIONS["\xA0\x00\x00\x00\x59\x50\x41\x43\x45\x01\x00"] = APPLICATIONS["\xD2\x76\x00\x00\x25\x45\x50\x02\x00"]

View File

@ -11,6 +11,7 @@ class ISO_7816_4_Card(building_blocks.Card_with_read_binary,Card):
DRIVER_NAME = ["ISO 7816-4"]
FID_MF = "\x3f\x00"
SELECT_FILE_P1 = 0x02
SELECT_P2 = 0x0
## def can_handle(cls, card):
@ -47,7 +48,7 @@ class ISO_7816_4_Card(building_blocks.Card_with_read_binary,Card):
def open_file(self, fid, p2 = None):
"Open an EF under the current DF"
if p2 is None: p2 = self.SELECT_P2
return self.select_file(0x02, p2, fid)
return self.select_file(self.SELECT_FILE_P1, p2, fid)
def cmd_open(self, file):
"Open a file"

37
cards/nfc_application.py Normal file
View File

@ -0,0 +1,37 @@
from generic_application import Application
import struct, sha, binascii, os, datetime, sys, utils
class NFC_Application(Application):
DRIVER_NAME = ["NFC Type 4"]
SELECT_FILE_P1 = 0
AID_LIST = [
"d2760000850100"
]
def cmd_parse_cc(self):
"Read and parse the CC (Capability Container) EF"
result = self.open_file("\xe1\x03")
if self.check_sw(result.sw):
contents, sw = self.read_binary_file()
if len(contents) > 0:
print utils.hexdump(contents,linelen=self.HEXDUMP_LINELEN)
if len(contents) < 0xf:
print "Invalid CC EF, can't parse (too short: 0x%x bytes)" % len(contents)
else:
cclen, version, MLe, MLc, ndef_control_tlv = struct.unpack('>HBHH8s', contents[:0xf])
print " CC length: %i (0x%x)%s" % (cclen, cclen, cclen == 0xffff and ", RFU" or "")
print "Mapping version: %i.%i" % (version >> 4, version & 0xf)
print " Maximum Le: %i (0x%x)%s" % (MLe, MLe, MLe <= 0xe and ", RFU" or "")
print " Maximum Lc: %i (0x%x)%s" % (MLc, MLc, MLc == 0x0 and ", RFU" or "")
print "NDEF File Control TLV: %s" % utils.hexdump(ndef_control_tlv, short=True)
if len(contents) > 0xf:
print "More TLV blocks: %s" % utils.hexdump(contents[0xf:], short=True)
COMMANDS = {
"parse_cc": cmd_parse_cc,
}

View File

@ -217,7 +217,8 @@ class Cyberflex_Shell(Shell):
"Parse a fancy APDU and print the result"
apdu = utils.C_APDU.parse_fancy_apdu(*args)
data = apdu.render()
self.card.last_result = utils.R_APDU(data+"\x00\x00")
if hasattr(self, "card"):
self.card.last_result = utils.R_APDU(data+"\x00\x00")
print utils.hexdump(data)
def _update_prompt(self):