]> git.zerfleddert.de Git - proxmark3-svn/blame - client/scripts/test_t55x7_psk.lua
Merge pull request #969 from pwpiwi/gcc10_fixes
[proxmark3-svn] / client / scripts / test_t55x7_psk.lua
CommitLineData
81740aa5 1local cmds = require('commands')
2local getopt = require('getopt')
3local bin = require('bin')
4local utils = require('utils')
81740aa5 5
6example =[[
13d77ef9 7 1. script run test_t55x7_psk
8 2. script run test_t55x7_psk -o
81740aa5 9
10]]
11author = "Iceman"
13d77ef9 12usage = "script run test_t55x7_psk"
81740aa5 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
81740aa5 41]]
42
43local TIMEOUT = 2000 -- Shouldn't take longer than 2 seconds
44local DEBUG = true -- the debug flag
1fbf8956 45
81740aa5 46
13d77ef9 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
1fbf8956 58 -- -----------
59 -- 08------- bitrate
60 -- 8----- modulation PSK1
61 -- 0---- PSK ClockRate
62 -- 40 max 2 blocks
13d77ef9 63
81740aa5 64local procedurecmds = {
13d77ef9 65 [1] = '00%02X%X%X40',
66 [2] = 'lf t55xx detect',
81740aa5 67 --[3] = '',
13d77ef9 68 [3] = 'lf t55xx info',
81740aa5 69}
81740aa5 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
13d77ef9 108function test(modulation)
109 local bitrate
110 local clockrate
224ce36e 111 local block = "00"
13d77ef9 112 for bitrate = 0x0, 0x1d, 0x4 do
113
114 for clockrate = 0,8,4 do
13d77ef9 115
1fbf8956 116 for _ = 1, #procedurecmds do
117 local cmd = procedurecmds[_]
81740aa5 118
1fbf8956 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)
224ce36e 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())
1fbf8956 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
81740aa5 137 end
1fbf8956 138 core.clearCommandBuffer()
81740aa5 139 end
81740aa5 140 end
141 print( string.rep('--',20) )
81740aa5 142end
143
144local function main(args)
145
146 print( string.rep('--',20) )
147 print( string.rep('--',20) )
148
81740aa5 149 -- Arguments for the script
13d77ef9 150 for o, arg in getopt.getopt(args, 'h') do
81740aa5 151 if o == "h" then return help() end
81740aa5 152 end
153
154 core.clearCommandBuffer()
155
1fbf8956 156 test(1) -- PSK1
157 --test(2) -- PSK2
158 --test(3) -- PSK3
81740aa5 159
160 print( string.rep('--',20) )
161end
162main(args)
1fbf8956 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