maur keys
[RRG-proxmark3.git] / client / luascripts / tests / lf_t55xx_defaultfsk.lua
blob9aa50f641b7dc65b110d63187b68e0804dd7f4ad
1 local cmds = require('commands')
2 local getopt = require('getopt')
3 local bin = require('bin')
4 local utils = require('utils')
5 local ansicolors = require('ansicolors')
7 copyright = ''
8 author = 'Iceman'
9 version = 'v1.0.2'
10 desc = [[
11 This script will program a T55x7 TAG with the configuration: block 0x00 data 0x000100
12 The outlined procedure is as following:
14 --ASK
15 00 00 80 40
16 -- max 2 blocks
17 -- FSK1
18 -- bit rate
20 "lf t55xx write -b 0 -d 00007040"
21 "lf t55xx detect"
22 "lf t55xx info"
24 Loop:
25 change the configuretion block 0 with:
26 -xx 00 xxxx = RF/8
27 -xx 04 xxxx = RF/16
28 -xx 08 xxxx = RF/32
29 -xx 0C xxxx = RF/40
30 -xx 10 xxxx = RF/50
31 -xx 14 xxxx = RF/64
32 -xx 18 xxxx = RF/100
33 -xx 1C xxxx = RF/128
35 testsuit for the ASK/MANCHESTER demod
37 example = [[
38 1. script run lf_t55xx_defaultfsk
40 usage = [[
41 script run lf_t55xx_defaultfsk [-h]
43 arguments = [[
44 -h : this help
47 local DEBUG = true -- the debug flag
48 local TIMEOUT = 1500
50 --BLOCK 0 = 00008040 FSK
51 local config1 = '00'
52 local config2 = '040'
54 local procedurecmds = {
55 [1] = '%s%02X%X%s',
56 [2] = 'lf t55xx detect',
57 [3] = 'lf t55xx info',
59 ---
60 -- A debug printout-function
61 local function dbg(args)
62 if not DEBUG then return end
63 if type(args) == 'table' then
64 local i = 1
65 while args[i] do
66 dbg(args[i])
67 i = i+1
68 end
69 else
70 print('###', args)
71 end
72 end
73 ---
74 -- This is only meant to be used when errors occur
75 local function oops(err)
76 print('ERROR:', err)
77 core.clearCommandBuffer()
78 return nil, err
79 end
80 ---
81 -- Usage help
82 local function help()
83 print(copyright)
84 print(author)
85 print(version)
86 print(desc)
87 print(ansicolors.cyan..'Usage'..ansicolors.reset)
88 print(usage)
89 print(ansicolors.cyan..'Arguments'..ansicolors.reset)
90 print(arguments)
91 print(ansicolors.cyan..'Example usage'..ansicolors.reset)
92 print(example)
93 end
95 -- Exit message
96 local function ExitMsg(msg)
97 print( string.rep('--',20) )
98 print( string.rep('--',20) )
99 print(msg)
100 print()
103 local function test(modulation)
104 local y
105 local password = '00000000'
106 local block = '00'
107 local flags = '00'
108 for y = 0x0, 0x1d, 0x4 do
109 for _ = 1, #procedurecmds do
110 local pcmd = procedurecmds[_]
112 if #pcmd == 0 then
114 elseif _ == 1 then
116 local config = pcmd:format(config1, y, modulation, config2)
117 dbg(('lf t55xx write -b 0 -d %s'):format(config))
118 local data = ('%s%s%s%s'):format(utils.SwapEndiannessStr(config, 32), password, block, flags)
120 local wc = Command:newNG{cmd = cmds.CMD_LF_T55XX_WRITEBL, data = data}
121 local response, err = wc:sendNG(false, TIMEOUT)
122 if not response then return oops(err) end
123 else
124 dbg(pcmd)
125 core.console( pcmd )
128 core.clearCommandBuffer()
130 print( string.rep('--',20) )
133 local function main(args)
135 print( string.rep('--',20) )
136 print( string.rep('--',20) )
138 -- Arguments for the script
139 for o, arg in getopt.getopt(args, 'h') do
140 if o == 'h' then return help() end
143 core.clearCommandBuffer()
144 test(4)
145 test(5)
146 test(6)
147 test(7)
148 print( string.rep('--',20) )
150 main(args)