Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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