]> git.zerfleddert.de Git - proxmark3-svn/blame_incremental - client/scripts/test_t55x7_psk.lua
Update cmdhficlass.h
[proxmark3-svn] / client / scripts / test_t55x7_psk.lua
... / ...
CommitLineData
1local cmds = require('commands')
2local getopt = require('getopt')
3local bin = require('bin')
4local utils = require('utils')
5
6example =[[
7 1. script run test_t55x7_psk
8 2. script run test_t55x7_psk -o
9
10]]
11author = "Iceman"
12usage = "script run test_t55x7_psk"
13desc =[[
14This script will program a T55x7 TAG with the configuration: block 0x00 data 0x00088040
15The outlined procedure is as following:
16
17"lf t55xx write 0 00088040"
18"lf read"
19"data samples"
20"data pskdet"
21"data psknrz"
22"data pskindala"
23"data psknrzraw"
24
25Loop OUTER:
26 change the configuretion block 0 with:
27 -xxxx8xxx = PSK RF/2 with Manchester modulation
28 -xxxx1xxx = PSK RF/2 with PSK1 modulation (phase change when input changes)
29 -xxxx2xxx = PSK RF/2 with PSk2 modulation (phase change on bitclk if input high)
30 -xxxx3xxx = PSK RF/2 with PSk3 modulation (phase change on rising edge of input)
31 Loop INNER
32 for each outer configuration, also do
33 XXXXX0XX = PSK RF/2
34 XXXXX4XX = PSK RF/4
35 XXXXX8XX = PSK RF/8
36
37In all 12 individual test for the PSK demod
38
39Arguments:
40 -h : this help
41]]
42
43local TIMEOUT = 2000 -- Shouldn't take longer than 2 seconds
44local DEBUG = true -- the debug flag
45
46
47-- local procedurecmds = {
48 -- [1] = '%s%s%s%s',
49 -- [2] = 'lf read',
50 -- --[3] = '',
51 -- [3] = 'data samples',
52 -- [4] = 'data pskdetectclock',
53 -- [5] = 'data psknrzrawdemod',
54 -- [6] = 'data pskindalademod',
55-- }
56
57-- --BLOCK 0 = 00 08 80 40 PSK
58 -- -----------
59 -- 08------- bitrate
60 -- 8----- modulation PSK1
61 -- 0---- PSK ClockRate
62 -- 40 max 2 blocks
63
64local procedurecmds = {
65 [1] = '00%02X%X%X40',
66 [2] = 'lf t55xx detect',
67 --[3] = '',
68 [3] = 'lf t55xx info',
69}
70---
71-- A debug printout-function
72function dbg(args)
73 if not DEBUG then
74 return
75 end
76
77 if type(args) == "table" then
78 local i = 1
79 while args[i] do
80 dbg(args[i])
81 i = i+1
82 end
83 else
84 print("###", args)
85 end
86end
87---
88-- This is only meant to be used when errors occur
89function oops(err)
90 print("ERROR: ",err)
91end
92---
93-- Usage help
94function help()
95 print(desc)
96 print("Example usage")
97 print(example)
98end
99--
100-- Exit message
101function ExitMsg(msg)
102 print( string.rep('--',20) )
103 print( string.rep('--',20) )
104 print(msg)
105 print()
106end
107
108function test(modulation)
109 local bitrate
110 local clockrate
111 local block = "00"
112 for bitrate = 0x0, 0x1d, 0x4 do
113
114 for clockrate = 0,8,4 do
115
116 for _ = 1, #procedurecmds do
117 local cmd = procedurecmds[_]
118
119 if #cmd == 0 then
120
121 elseif _ == 1 then
122
123 dbg("Writing to T55x7 TAG")
124
125 local config = cmd:format(bitrate, modulation, clockrate)
126 dbg(('lf t55xx write 0 %s'):format(config))
127
128 config = tonumber(config,16)
129 local writecmd = Command:new{cmd = cmds.CMD_T55XX_WRITE_BLOCK,arg1 = config, arg2 = block, arg3 = "00", data = "00"}
130 local err = core.SendCommand(writecmd:getBytes())
131 if err then return oops(err) end
132 local response = core.WaitForResponseTimeout(cmds.CMD_ACK,TIMEOUT)
133 else
134 dbg(cmd)
135 core.console( cmd )
136 end
137 end
138 core.clearCommandBuffer()
139 end
140 end
141 print( string.rep('--',20) )
142end
143
144local function main(args)
145
146 print( string.rep('--',20) )
147 print( string.rep('--',20) )
148
149 -- Arguments for the script
150 for o, arg in getopt.getopt(args, 'h') do
151 if o == "h" then return help() end
152 end
153
154 core.clearCommandBuffer()
155
156 test(1) -- PSK1
157 --test(2) -- PSK2
158 --test(3) -- PSK3
159
160 print( string.rep('--',20) )
161end
162main(args)
163
164-- Where it iterates over
165 -- xxxx8xxx = PSK RF/2 with Manchester modulation
166 -- xxxx1xxx = PSK RF/2 with PSK1 modulation (phase change when input changes)
167 -- xxxx2xxx = PSK RF/2 with PSk2 modulation (phase change on bitclk if input high)
168 -- xxxx3xxx = PSK RF/2 with PSk3 modulation (phase change on rising edge of input)
169
170 -- XXXXX0XX = PSK RF/2
171 -- XXXXX4XX = PSK RF/4
172 -- XXXXX8XX = PSK RF/8
Impressum, Datenschutz