maur keys
[RRG-proxmark3.git] / client / luascripts / tests / lf_t55xx_defaultbi.lua
blob2590dc38b515d23eda432b0036a19124614985c4
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 0x00010040
12 The outlined procedure is as following:
14 --BIPHASE 00010040
17 "lf t55xx write -b 0 -d 00010040"
18 "lf t55xx detect"
19 "lf t55xx info"
21 Loop:
22 change the configuretion block 0 with:
23 -xx01xxxx = RF/8
24 -xx05xxxx = RF/16
25 -xx09xxxx = RF/32
26 -xx0Dxxxx = RF/40
27 -xx11xxxx = RF/50
28 -xx15xxxx = RF/64
29 -xx19xxxx = RF/100
30 -xx1Dxxxx = RF/128
33 testsuit for the BIPHASE demod
35 example = [[
36 1. script run lf_t55xx_defaultbi
38 usage = [[
39 script run lf_t55xx_defaultbi [-h]
41 arguments = [[
42 -h : this help
45 local DEBUG = true -- the debug flag
46 local TIMEOUT = 1500
48 --BLOCK 0 = 00010040 BIPHASE
49 local config1 = '00'
50 local config2 = '0040'
52 local procedurecmds = {
53 [1] = '%s%02X%s',
54 [2] = 'lf t55xx detect',
55 [3] = 'lf t55xx info',
57 ---
58 -- A debug printout-function
59 local function dbg(args)
60 if not DEBUG then return end
61 if type(args) == 'table' then
62 local i = 1
63 while args[i] do
64 dbg(args[i])
65 i = i+1
66 end
67 else
68 print('###', args)
69 end
70 end
71 ---
72 -- This is only meant to be used when errors occur
73 local function oops(err)
74 print('ERROR:', err)
75 core.clearCommandBuffer()
76 return nil, err
77 end
78 ---
79 -- Usage help
80 local function help()
81 print(copyright)
82 print(author)
83 print(version)
84 print(desc)
85 print(ansicolors.cyan..'Usage'..ansicolors.reset)
86 print(usage)
87 print(ansicolors.cyan..'Arguments'..ansicolors.reset)
88 print(arguments)
89 print(ansicolors.cyan..'Example usage'..ansicolors.reset)
90 print(example)
91 end
93 -- Exit message
94 local function ExitMsg(msg)
95 print( string.rep('--',20) )
96 print( string.rep('--',20) )
97 print(msg)
98 print()
99 end
101 local function test()
102 local y
103 local password = '00000000'
104 local block = '00'
105 local flags = '00'
106 for y = 1, 0x1D, 4 do
107 for _ = 1, #procedurecmds do
108 local pcmd = procedurecmds[_]
110 if #pcmd == 0 then
112 elseif _ == 1 then
114 local config = pcmd:format(config1, y, config2)
115 dbg(('lf t55xx write -b 0 -d %s'):format(config))
117 local data = ('%s%s%s%s'):format(utils.SwapEndiannessStr(config, 32), password, block, flags)
119 local wc = Command:newNG{cmd = cmds.CMD_LF_T55XX_WRITEBL, data = data}
120 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) )
134 local function main(args)
136 print( string.rep('--',20) )
137 print( string.rep('--',20) )
139 -- Arguments for the script
140 for o, arg in getopt.getopt(args, 'h') do
141 if o == 'h' then return help() end
144 core.clearCommandBuffer()
145 test()
146 print( string.rep('--',20) )
148 main(args)