Added support for reading serial numbers and manf IDs of MiFare UL tags

This commit is contained in:
2009-02-01 19:56:19 +00:00
parent 874ef3591e
commit 8732e8ff8b
3 changed files with 40 additions and 4 deletions

View File

@@ -1,6 +1,7 @@
import logging
import reader
import time
from smartcard.util import toHexString
class MiFareUltralight():
"""Class to control MiFare Ultralight RFID Tags
@@ -14,6 +15,8 @@ class MiFareUltralight():
_logger = logging.getLogger('pytikitag.mifareul')
_reader = None
_manf_ids = {0x04: "NXP / Phillips"}
def __init__(self, pcscreader=None):
@@ -29,6 +32,31 @@ class MiFareUltralight():
return True
else:
return False
def get_manf(self):
"""Get the IC manufacturer"""
return self.read_block(0x0)[0]
def get_manf_ascii(self):
mid = self.get_manf()
if mid:
return self._manf_ids[mid]
else:
return None
def get_serial(self):
"""Get the serial number of the IC"""
# MiFare Serials are stored in page 0x0 and 0x1, the format is as follows
# MF,S1, S2, C1 S4, S5, S6
#
# Where MF is the manufacturer ID, S is a serial value and C is a check byte
d1 = self.read_block(0x0)
d2 = self.read_block(0x1)
sn = toHexString(d1[1:3] + d2)
return sn.replace(" ", "")
def read_block(self, block, timeout = 100):
"""Reads a full 4 byte page from the RFID tag"""

View File

@@ -8,3 +8,7 @@ class TikiTag(mifareul.MiFareUltralight):
d = d+ self.read_block(1)
return toHexString(d).replace(" ", "")[:16]
def get_tag_url(self):
if toASCIIString(self.read_block(0x6)) == "tag.":
return "http://ttag.be/m/%s" % self.get_uid()

12
test.py
View File

@@ -14,11 +14,15 @@ print r.firmware_version()
m = tikitag.TikiTag(r)
print m.get_uid()
print m.get_tag_url()
#d = m.read_tag()
#d = m.read_block(0x6)
#print "%s bytes" % len(d)
#print toHexString(d)
#print toASCIIString(d)
print m.write_block(0xf, [0xde, 0xad, 0xbe, 0xee])
#print m.write_block(0xf, [0xde, 0xad, 0xbe, 0xee])
print toHexString(m.read_block(0xf))
#print toHexString(m.read_block(0xf))
print m.get_manf_ascii()
print m.get_serial()