Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 175 lines (161 sloc) 5.699 kb
447c3847 » Adam Laurie
2011-10-31 first commit
1 #!/usr/bin/python
2
3 # readlfx.py - read all sectors from a LFX reader
4 #
5 # Adam Laurie <adam@algroup.co.uk>
6 # http://rfidiot.org/
7 #
8 # This code is copyright (c) Adam Laurie, 2006, All rights reserved.
9 # For non-commercial use only, the following terms apply - for all other
10 # uses, please contact the author:
11 #
12 # This code is free software; you can redistribute it and/or modify
13 # it under the terms of the GNU General Public License as published by
14 # the Free Software Foundation; either version 2 of the License, or
15 # (at your option) any later version.
16 #
17 # This code is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # GNU General Public License for more details.
21 #
22
23 # usage: readlfx [KEY]
24 #
25 # specifiy KEY for protected tags. If not specified, TRANSPORT key will be tried.
26
271cf40b »
2012-10-04 more package changes - be sure to read INSTALL for small but importan…
27 import rfidiot
447c3847 » Adam Laurie
2011-10-31 first commit
28 import sys
29 import os
30
31 try:
271cf40b »
2012-10-04 more package changes - be sure to read INSTALL for small but importan…
32 card= rfidiot.card
447c3847 » Adam Laurie
2011-10-31 first commit
33 except:
271cf40b »
2012-10-04 more package changes - be sure to read INSTALL for small but importan…
34 print "Couldn't open reader!"
447c3847 » Adam Laurie
2011-10-31 first commit
35 os._exit(True)
36
271cf40b »
2012-10-04 more package changes - be sure to read INSTALL for small but importan…
37 args= rfidiot.args
38 help= rfidiot.help
447c3847 » Adam Laurie
2011-10-31 first commit
39
40 Q5Mod= { '000':'Manchester',\
41 '001':'PSK 1',\
42 '010':'PSK 2',\
43 '011':'PSK 3',\
44 '100':'FSK 1 (a = 0)',\
45 '101':'FSK 2 (a = 0)',\
46 '110':'Biphase',\
47 '111':'NRZ / direct'}
48
49 card.info('readlfx v0.1m')
50
51 # force card type if specified
52 if len(args) > 0:
53 print 'Setting tag type:', args[0]
54 card.settagtype(args[0])
55 else:
56 card.settagtype(card.ALL)
57 card.select()
58 ID= card.uid
59 print 'Card ID: ' + ID
60 print 'Tag type: ' + card.LFXTags[card.tagtype]
61
62 # set key if specified
63 if len(args) > 1:
64 key= args[1]
65 else:
66 key= ''
67
68 # Login to Hitag2
69 if card.tagtype == card.HITAG2 and card.readertype == card.READER_ACG:
70 if not key:
71 key= card.HITAG2_TRANSPORT_RWD
72 print ' Logging in with key: ' + key
73 if not card.login('','',key):
74 print 'Login failed!'
75 os._exit(True)
76
77 # Interpret EM4x05 ID structure
78 if card.tagtype == card.EM4x05:
79 card.FDXBIDPrint(ID)
80
81 # Q5 cards can emulate other cards, so check if this one responds as Q5
82 if card.tagtype == card.EM4x02 or card.tagtype == card.Q5 or card.tagtype == card.EM4x05:
83 print ' Checking for Q5'
84 card.settagtype(card.Q5)
85 card.select()
86 Q5ID= card.uid
87 if card.tagtype == card.Q5:
88 print ' Q5 ID: ' + Q5ID
89 print
90 card.readblock(0)
91 print ' Config Block: ',
92 print card.ToHex(card.binary)
93 print ' Config Binary: ',
94 configbin= card.ToBinaryString(card.binary)
95 print configbin
96 print ' Reserved: ' + configbin[:12]
97 print ' Page Select: ' + configbin[12]
98 print ' Fast Write: ' + configbin[13]
99 print ' Data Bit Rate n5: ' + configbin[14]
100 print ' Data Bit Rate n4: ' + configbin[15]
101 print ' Data Bit Rate n3: ' + configbin[16]
102 print ' Data Bit Rate n2: ' + configbin[17]
103 print ' Data Bit Rate n1: ' + configbin[18]
104 print ' Data Bit Rate n0: ' + configbin[19]
105 print ' (Field Clocks/Bit: %d)' % (2 * int(configbin[14:20],2) + 2)
106 print ' Use AOR: ' + configbin[20]
107 print ' Use PWD: ' + configbin[21]
108 print ' PSK Carrier Freq: ' + configbin[22] + configbin[23]
109 print ' Inverse data out: ' + configbin[24]
110 print ' Modulation: ' + configbin[25] + configbin[26] + configbin[27] + " (%s)" % Q5Mod[configbin[25] + configbin[26] + configbin[27]]
111 print ' Maxblock: ' + configbin[28] + configbin[29] + configbin[30] + " (%d)" % int (configbin[28] + configbin[29] + configbin[30],2)
112 print ' Terminator: ' + configbin[31]
113 print
114 # Emulated ID is contained in 'traceability data'
115 print ' Traceability Data 1: ',
116 card.readblock(1)
117 td1= card.binary
118 # to test a hardwired number, uncomment following line (and td2 below)
119 # td1= chr(0xff) + chr(0x98) + chr(0xa6) + chr(0x4a)
120 print card.ToHex(td1)
121 print ' Traceability Data 2: ',
122 card.readblock(2)
123 td2= card.binary
124 # don't forget to set column parity!
125 # td2= chr(0x98) + chr(0xf8) + chr(0xc8) + chr(0x06)
126 print card.ToHex(td2)
127 print ' Traceability Binary: ',
128 tdbin= card.ToBinaryString(td1 + td2)
129 print tdbin
130 # traceability is broken into 4 bit chunks with even parity
131 print
132 print ' Header:',
133 print tdbin[:9]
134 print ' Parity (even)'
135 print ' D00-D03: ' + tdbin[9:13] + ' ' + tdbin[13]
136 print ' D10-D13: ' + tdbin[14:18] + ' ' + tdbin[18]
137 print ' D20-D23: ' + tdbin[19:23] + ' ' + tdbin[23]
138 print ' D30-D33: ' + tdbin[24:28] + ' ' + tdbin[28]
139 print ' D40-D43: ' + tdbin[29:33] + ' ' + tdbin[33]
140 print ' D50-D53: ' + tdbin[34:38] + ' ' + tdbin[38]
141 print ' D60-D63: ' + tdbin[39:43] + ' ' + tdbin[43]
142 print ' D70-D73: ' + tdbin[44:48] + ' ' + tdbin[48]
143 print ' D80-D83: ' + tdbin[49:53] + ' ' + tdbin[53]
144 print ' D90-D93: ' + tdbin[54:58] + ' ' + tdbin[58]
145 print ' ' + tdbin[59:63] + ' ' + tdbin[63] + ' Column Parity & Stop Bit'
146 # reconstruct data bytes
147 d0= chr(int(tdbin[9:13] + tdbin[14:18],2))
148 d1= chr(int(tdbin[19:23] + tdbin[24:28],2))
149 d2= chr(int(tdbin[29:33] + tdbin[34:38],2))
150 d3= chr(int(tdbin[39:43] + tdbin[44:48],2))
151 d4= chr(int(tdbin[49:53] + tdbin[54:58],2))
152 print
153 print ' Reconstructed data D00-D93 (UNIQUE ID): ',
154 card.HexPrint(d0 + d1 + d2 + d3 + d4)
155 # set ID to Q5ID so block reading works
156 ID= Q5ID
157 print
158 else:
159 print ' Native - UNIQUE ID: ' + card.EMToUnique(ID)
160
161 sector = 0
162 while sector < card.LFXTagBlocks[card.tagtype]:
163 print ' sector %02x: ' % sector,
164 if card.readblock(sector):
165 print card.data
166 else:
167 print 'Read error: ' + card.errorcode
168 sector += 1
169 print
170
171 # set reader back to all cards
172 card.settagtype(card.ALL)
173 card.select()
174 print
175 os._exit(False)
Something went wrong with that request. Please try again.