Browse files

Merge pull request #19 from vitorio/master

Adding JEWEL support to isotype.py and pynfc.py - sorry it took so long to merge this! Thanks for the pull!
  • Loading branch information...
2 parents ed1732f + f694588 commit 91d9f162f1c3a1284d8cad8f8e911cd10b759f7f @AdamLaurie committed May 14, 2016
Showing with 66 additions and 23 deletions.
  1. +5 −0 isotype.py
  2. +36 −23 rfidiot/RFIDIOt.py
  3. +25 −0 rfidiot/pynfc.py
View
5 isotype.py
@@ -89,6 +89,11 @@
print ' CID: ' + card.cid
print " Tag is ISO 14443B"
typed= True
+ if card.select('JEWEL'):
+ print 'SENSRES: ' + card.btsensres
+ print ' ID: ' + card.btid
+ print " Tag is JEWEL"
+ typed= True
if not typed:
print "Could not determine type"
os._exit(True)
View
59 rfidiot/RFIDIOt.py
@@ -1060,32 +1060,45 @@ def select(self, cardtype='A'):
if self.DEBUG:
print 'Error selecting card'
return False
- else:
- if cardtype == 'B':
- result = self.nfc.selectISO14443B()
- if result:
- self.pupi = result.pupi
- self.atr = result.atr
- self.uid = result.uid
- self.appdata = result.appdata
- self.protocol = result.protocol
- self.cid = result.cid
- if self.DEBUG:
- print 'PUPI: ' + self.pupi
- print 'ATR: ' + self.atr
- print 'UID: ' + self.uid
- print 'APPDATA: ' + self.appdata
- print 'PROTOCOL: ' + self.protocol
- print 'CID: ' + self.cid
- return True
- else:
- if self.DEBUG:
- print 'Error selecting card'
- return False
+ elif cardtype == 'B':
+ result = self.nfc.selectISO14443B()
+ if result:
+ self.pupi = result.pupi
+ self.atr = result.atr
+ self.uid = result.uid
+ self.appdata = result.appdata
+ self.protocol = result.protocol
+ self.cid = result.cid
+ if self.DEBUG:
+ print 'PUPI: ' + self.pupi
+ print 'ATR: ' + self.atr
+ print 'UID: ' + self.uid
+ print 'APPDATA: ' + self.appdata
+ print 'PROTOCOL: ' + self.protocol
+ print 'CID: ' + self.cid
+ return True
+ else:
+ if self.DEBUG:
+ print 'Error selecting card'
+ return False
+ elif cardtype == 'JEWEL':
+ result = self.nfc.selectJEWEL()
+ if result:
+ self.btsensres = result.btSensRes
+ self.btid = result.btId
+ self.uid = result.uid
+ if self.DEBUG:
+ print 'SENSRES: ' + self.btsensres
+ print 'ID: ' + self.btid
+ return True
else:
if self.DEBUG:
- print 'Error: Unknown card type specified: %s' % cardtype
+ print 'Error selecting card'
return False
+ else:
+ if self.DEBUG:
+ print 'Error: Unknown card type specified: %s' % cardtype
+ return False
except ValueError:
self.errorcode = 'Error selecting card using LIBNFC' + e
View
25 rfidiot/pynfc.py
@@ -253,6 +253,17 @@ def __str__(self):
rv = "ISO14443B(pupi='%s')" % (self.pupi)
return rv
+class JEWEL(object):
+ def __init__(self, ti):
+ self.btSensRes = "".join(["%02X" % x for x in ti.btSensRes[:2]])
+ self.btId = "".join(["%02X" % x for x in ti.btId[:4]])
+ self.uid = self.btId
+ self.atr = "" # idem
+
+ def __str__(self):
+ rv = "JEWEL(btSensRes='%s', btId='%s')" % (self.btSensRes, self.btId)
+ return rv
+
class NFC(object):
def __init__(self, nfcreader):
self.LIB = ctypes.util.find_library('nfc')
@@ -426,6 +437,20 @@ def selectISO14443B(self):
return ISO14443B(target[0].nti.nbi)
return None
+ def selectJEWEL(self):
+ """Detect and initialise a JEWEL card, returns a JEWEL() object."""
+ if rfidiotglobals.Debug:
+ self.log.debug("Polling for JEWEL cards")
+ self.powerOff()
+ self.powerOn()
+ nm= NFC_MODULATION()
+ target= (NFC_TARGET * MAX_TARGET_COUNT) ()
+ nm.nmt = NMT_JEWEL
+ nm.nbr = NBR_106
+ if self.libnfc.nfc_initiator_list_passive_targets(self.device, nm, ctypes.byref(target), MAX_TARGET_COUNT):
+ return JEWEL(target[0].nti.nji)
+ return None
+
# set Mifare specific parameters
def configMifare(self):
self.libnfc.nfc_device_set_property_bool(self.device, NP_AUTO_ISO14443_4, False)

0 comments on commit 91d9f16

Please sign in to comment.