mirror of
https://github.com/nikdoof/pytikitag.git
synced 2025-12-13 05:02:17 +00:00
Further work and annotations. Correction to the read functions of MiFare
to get the correct bytes
This commit is contained in:
@@ -24,6 +24,7 @@ class MiFareUL():
|
||||
return False
|
||||
|
||||
def read_block(self, block, timeout = 100):
|
||||
"""Reads a full 8 byte page from the RFID tag"""
|
||||
|
||||
d = None
|
||||
t = 0
|
||||
@@ -33,14 +34,16 @@ class MiFareUL():
|
||||
|
||||
while not d:
|
||||
d = self._reader.trans_rfid([0xD4, 0x40, 0x01, 0x30] + [block])
|
||||
time.sleep(0.5)
|
||||
t = t + 1
|
||||
|
||||
if d:
|
||||
return d[3:]
|
||||
return d[3:7]
|
||||
else:
|
||||
return None
|
||||
|
||||
def write_block(self, block, data):
|
||||
"""Write a full 4 byte page to the writable area of the tag"""
|
||||
if block < 0x04:
|
||||
raise ValueError("Invalid block")
|
||||
|
||||
pass
|
||||
d = self._reader.trans_rfid([0xD4, 0x40, 0x01, 0xA0] + [block] + data)
|
||||
|
||||
@@ -18,12 +18,12 @@ class TikiReader():
|
||||
self._connection.connect()
|
||||
|
||||
def trans_raw(self, cmd):
|
||||
"""Transmit a raw APDU command"""
|
||||
"""Transmit a raw APDU command via the RFID interface of the device"""
|
||||
|
||||
return self._connection.transmit(cmd)
|
||||
|
||||
def trans_rfid(self, cmd):
|
||||
"""Transmit command and return data"""
|
||||
"""Transmit command via RFID and return the data"""
|
||||
|
||||
if self._connection:
|
||||
fcmd = self._build_cmd(1, cmd)
|
||||
@@ -44,6 +44,7 @@ class TikiReader():
|
||||
return -3
|
||||
|
||||
def firmware_version(self):
|
||||
"""Retreives the firmware version of the ACR122/Tikitag Reader"""
|
||||
resp, s1, s2 = self._connection.transmit([0xFF, 0x00, 0x00, 0x48, 0x00, 0x00])
|
||||
|
||||
if not s1 == 99:
|
||||
@@ -61,21 +62,5 @@ class TikiReader():
|
||||
fcmd = prefix + cmd
|
||||
|
||||
return fcmd
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
import logging.handlers
|
||||
import string
|
||||
|
||||
t = TikiReader()
|
||||
|
||||
log = logging.getLogger('pytikitag.reader')
|
||||
log.setLevel(logging.DEBUG)
|
||||
hand = logging.StreamHandler(sys.stdout)
|
||||
log.addHandler(hand)
|
||||
|
||||
while t._tag_available() == False:
|
||||
pass
|
||||
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ from smartcard.util import toHexString, toASCIIString
|
||||
|
||||
class TikiTag(mifareul.MiFareUL):
|
||||
|
||||
def tag_id(self):
|
||||
def get_uid(self):
|
||||
d = self.read_block(0)
|
||||
|
||||
return toHexString(d).replace(" ", "")[:16]
|
||||
|
||||
8
test.py
8
test.py
@@ -1,11 +1,13 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
from pytikitag import reader, tikitag
|
||||
from smartcard.util import toHexString, toASCIIString
|
||||
|
||||
m = tikitag.TikiTag()
|
||||
|
||||
print m.tag_id()
|
||||
print m.get_uid()
|
||||
|
||||
#d = m.read_tag()
|
||||
#rint "%s bytes" % len(d)
|
||||
d = m.read_tag()
|
||||
print "%s bytes" % len(d)
|
||||
print toHexString(d)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user