-
Notifications
You must be signed in to change notification settings - Fork 227
/
RFIDIOt-android.patch
108 lines (107 loc) · 3.11 KB
/
RFIDIOt-android.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
--- RFIDIOt.py 2011-10-30 10:05:00.770555688 +1300
+++ RFIDIOt-android.py 2011-10-30 10:04:37.674551272 +1300
@@ -40,7 +40,8 @@
from operator import *
import pynfc
import signal
-
+import socket
+import pyandroid
try:
import smartcard, smartcard.CardRequest
@@ -153,6 +154,10 @@
elif self.readertype == self.READER_LIBNFC:
self.nfc = pynfc.NFC()
self.readername = self.nfc.LIBNFC_READER
+ #Andoid reader
+ elif self.readertype == self.READER_ANDROID:
+ self.android = pyandroid.Android()
+ self.readername = "Android"
elif self.readertype == self.READER_NONE:
self.readername = 'none'
else:
@@ -204,6 +209,7 @@
READER_ACS= 0x07
READER_LIBNFC = 0x08
READER_NONE = 0x09
+ READER_ANDROID = 0x10
# TAG related globals
errorcode= ''
binary= ''
@@ -765,6 +771,8 @@
os._exit(True)
if self.readertype == self.READER_LIBNFC:
print 'LibNFC', self.readername
+ if self.readertype == self.READER_ANDROID:
+ print 'Android Reader'
print
#
# reader functions
@@ -799,6 +807,9 @@
if self.readertype == self.READER_LIBNFC:
self.nfc.powerOff()
self.nfc.powerOn()
+ if self.readertype == self.READER_ANDROID:
+ self.android.reset()
+
def version(self):
if self.readertype == self.READER_ACG:
self.ser.write('v')
@@ -819,6 +830,8 @@
else:
print self.FROSCH_Errors[self.errorcode]
os._exit(True)
+ if self.readertype == self.READER_ANDROID:
+ print 'Android version: ', self.android.VERSION
def id(self):
return self.readEEPROM(0)[:2] + self.readEEPROM(1)[:2] + self.readEEPROM(2)[:2] + self.readEEPROM(3)[:2]
def station(self):
@@ -986,6 +999,23 @@
return False
except ValueError:
self.errorcode = 'Error reading card using LIBNFC' + e
+
+ if self.readertype == self.READER_ANDROID:
+ try:
+ if DEBUG:
+ print 'Reading card using Android'
+ uid = self.android.select()
+ if uid:
+ self.uid = uid
+ if DEBUG:
+ print '\tUID: ' + self.uid
+ return True
+ else:
+ if DEBUG:
+ print 'Error selecting card'
+ return False
+ except ValueError:
+ self.errorcode = 'Error reading card using Android' + e
return False
def h2publicselect(self):
"select Hitag2 from Public Mode A/B/C"
@@ -1007,7 +1037,7 @@
return False
return True
def hsselect(self,speed):
- if self.readertype == self.READER_PCSC or self.readertype == self.READER_LIBNFC:
+ if self.readertype == self.READER_PCSC or self.readertype == self.READER_LIBNFC or self.READER_ANDROID:
# low level takes care of this, so normal select only
if self.select():
#fixme - find true speed/framesize
@@ -1361,7 +1391,14 @@
if self.errorcode == self.ISO_OK:
return True
return False
- dlength= 5
+ if self.readertype == self.READER_ANDROID:
+ result = self.android.sendAPDU(cla+self.ISOAPDU[ins]+p1+p2+lc+data+le)
+ self.data = result[0:-4]
+ self.errorcode = result[len(result)-4:len(result)]
+ if self.errorcode == self.ISO_OK:
+ return True
+ return False
+ dlength= 5
command= pcb+cla+self.ISOAPDU[ins]+p1+p2+lc+data+le
dlength += len(data) / 2
dlength += len(lc) / 2