From 9701643fdda17a3cc3697c6178ed2d0b0979607d Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Thu, 5 Oct 2017 16:17:09 +0200 Subject: [PATCH] CHG: NO_RATS adjustments to luascripts. --- client/lualibs/read14a.lua | 11 +++++++---- client/scripts/14araw.lua | 22 ++++++++++++++-------- client/scripts/calc_di.lua | 2 +- client/scripts/calc_ev1_it.lua | 2 +- client/scripts/calc_mizip.lua | 2 +- client/scripts/didump.lua | 2 +- client/scripts/formatMifare.lua | 2 +- client/scripts/mfkeys.lua | 2 +- client/scripts/tnp3clone.lua | 2 +- client/scripts/tnp3dump.lua | 2 +- client/scripts/ufodump.lua | 15 ++++++--------- 11 files changed, 35 insertions(+), 29 deletions(-) diff --git a/client/lualibs/read14a.lua b/client/lualibs/read14a.lua index 18339f921..5891c644d 100644 --- a/client/lualibs/read14a.lua +++ b/client/lualibs/read14a.lua @@ -22,7 +22,8 @@ local ISO14A_COMMAND = { ISO14A_APPEND_CRC = 0x20, ISO14A_SET_TIMEOUT = 0x40, ISO14A_NO_SELECT = 0x80, - ISO14A_TOPAZMODE = 0x100 + ISO14A_TOPAZMODE = 0x100, + ISO14A_NO_RATS = 0x200 } local ISO14443a_TYPES = {} @@ -94,14 +95,17 @@ end -- @param dont_disconnect - if true, does not disable the field -- @return if successfull: an table containing card info -- @return if unsuccessfull : nil, error -local function read14443a(dont_disconnect) +local function read14443a(dont_disconnect, no_rats) local command, result, info, err, data command = Command:new{cmd = cmds.CMD_READER_ISO_14443a, - arg1 = ISO14A_COMMAND.ISO14A_CONNECT} + arg1 = ISO14A_COMMAND.ISO14A_CONNECT } if dont_disconnect then command.arg1 = command.arg1 + ISO14A_COMMAND.ISO14A_NO_DISCONNECT end + if no_rats then + command.arg1 = command.arg1 + ISO14A_COMMAND.ISO14A_NO_RATS + end local result,err = sendToDevice(command) if result then local count,cmd,arg0,arg1,arg2 = bin.unpack('LLLL',result) @@ -135,7 +139,6 @@ local function waitFor14443a() return nil, "Aborted by user" end local library = { - read1443a = read14443a, read = read14443a, waitFor14443a = waitFor14443a, diff --git a/client/scripts/14araw.lua b/client/scripts/14araw.lua index 9b1202ca7..1087ec541 100644 --- a/client/scripts/14araw.lua +++ b/client/scripts/14araw.lua @@ -15,6 +15,8 @@ Arguments: -p stay connected - dont inactivate the field -x Data to send (NO SPACES!) -d Debug flag + -t Topaz mode + -3 ISO14443-4 (use RATS) Examples : @@ -78,15 +80,19 @@ function main(args) local stayconnected = false local payload = nil local doconnect = true - + local topaz_mode = false + local no_rats = false + -- Read the parameters - for o, a in getopt.getopt(args, 'corcpx:') do + for o, a in getopt.getopt(args, 'corcpx:t3') do if o == "o" then doconnect = false end if o == "r" then ignore_response = true end if o == "c" then appendcrc = true end if o == "p" then stayconnected = true end if o == "x" then payload = a end if o == "d" then DEBUG = true end + if o == "t" then topaz_mode = true end + if o == "3" then no_rats = true end end -- First of all, connect @@ -94,7 +100,7 @@ function main(args) dbg("doconnect") -- We reuse the connect functionality from a -- common library - info, err = lib14a.read1443a(true) + info, err = lib14a.read1443a(true, no_rats) if err then return oops(err) end print(("Connected to card, uid = %s"):format(info.uid)) @@ -102,7 +108,7 @@ function main(args) -- The actual raw payload, if any if payload then - res,err = sendRaw(payload,{ignore_response = ignore_response}) + res,err = sendRaw(payload,{ignore_response = ignore_response, topaz_mode = topaz_mode}) if err then return oops(err) end if not ignoreresponse then @@ -131,13 +137,15 @@ function showdata(usbpacket) --print("----------------") end - - function sendRaw(rawdata, options) print(">> ", rawdata) local flags = lib14a.ISO14A_COMMAND.ISO14A_NO_DISCONNECT + lib14a.ISO14A_COMMAND.ISO14A_RAW + if options.topaz_mode then + flags = flags + lib14a.ISO14A_COMMAND.ISO14A_TOPAZMODE + end + local command = Command:new{cmd = cmds.CMD_READER_ISO_14443a, arg1 = flags, -- Send raw -- arg2 contains the length, which is half the length @@ -149,14 +157,12 @@ end -- Sends an instruction to do nothing, only disconnect function disconnect() - local command = Command:new{cmd = cmds.CMD_READER_ISO_14443a, arg1 = 0, } -- We can ignore the response here, no ACK is returned for this command -- Check /armsrc/iso14443a.c, ReaderIso14443a() for details return lib14a.sendToDevice(command,true) end - ------------------------- -- Testing ------------------------- diff --git a/client/scripts/calc_di.lua b/client/scripts/calc_di.lua index 83638ebe4..62b126e67 100644 --- a/client/scripts/calc_di.lua +++ b/client/scripts/calc_di.lua @@ -152,7 +152,7 @@ local function main(args) if #uid ~= 14 then return oops('uid wrong length. Should be 7 hex bytes') end else -- GET TAG UID - local tag, err = lib14a.read1443a(false) + local tag, err = lib14a.read1443a(false, true) if not tag then return oops(err) end core.clearCommandBuffer() diff --git a/client/scripts/calc_ev1_it.lua b/client/scripts/calc_ev1_it.lua index d3583732d..a87030962 100644 --- a/client/scripts/calc_ev1_it.lua +++ b/client/scripts/calc_ev1_it.lua @@ -159,7 +159,7 @@ local function main(args) if #uid ~= 14 then return oops('uid wrong length. Should be 7 hex bytes') end else -- GET TAG UID - local tag, err = lib14a.read1443a(false) + local tag, err = lib14a.read1443a(false, true) if not tag then return oops(err) end core.clearCommandBuffer() uid = tag.uid diff --git a/client/scripts/calc_mizip.lua b/client/scripts/calc_mizip.lua index a735f4bc7..e2a09608c 100644 --- a/client/scripts/calc_mizip.lua +++ b/client/scripts/calc_mizip.lua @@ -173,7 +173,7 @@ local function main(args) if #uid ~= 8 then return oops('uid wrong length. Should be 4 hex bytes') end else -- GET TAG UID - local tag, err = lib14a.read1443a(false) + local tag, err = lib14a.read1443a(false, true) if not tag then return oops(err) end core.clearCommandBuffer() diff --git a/client/scripts/didump.lua b/client/scripts/didump.lua index 6e4a10fa4..3663a8429 100644 --- a/client/scripts/didump.lua +++ b/client/scripts/didump.lua @@ -561,7 +561,7 @@ function main(args) setdevicedebug(false) -- GET TAG UID - tag, err = lib14a.read1443a(false) + tag, err = lib14a.read1443a(false, true) if not tag then return oops(err) end core.clearCommandBuffer() diff --git a/client/scripts/formatMifare.lua b/client/scripts/formatMifare.lua index cc3f1e466..bbb6ec32f 100644 --- a/client/scripts/formatMifare.lua +++ b/client/scripts/formatMifare.lua @@ -81,7 +81,7 @@ end -- -- Read information from a card function GetCardInfo() - result, err = lib14a.read1443a(false) + result, err = lib14a.read1443a(false, true) if not result then print(err) return diff --git a/client/scripts/mfkeys.lua b/client/scripts/mfkeys.lua index 9c2b3dbad..e1995b24a 100644 --- a/client/scripts/mfkeys.lua +++ b/client/scripts/mfkeys.lua @@ -259,7 +259,7 @@ local function main( args) end -- identify tag - tag, err = lib14a.read1443a(false) + tag, err = lib14a.read1443a(false, true) if not tag then return oops(err) end -- detect sectors and print taginfo diff --git a/client/scripts/tnp3clone.lua b/client/scripts/tnp3clone.lua index e87c338ea..2a8d2763b 100644 --- a/client/scripts/tnp3clone.lua +++ b/client/scripts/tnp3clone.lua @@ -122,7 +122,7 @@ local function main(args) -- find tag - result, err = lib14a.read1443a(false) + result, err = lib14a.read1443a(false, true) if not result then return oops(err) end -- load keys diff --git a/client/scripts/tnp3dump.lua b/client/scripts/tnp3dump.lua index 613cf5819..9b93aa62a 100644 --- a/client/scripts/tnp3dump.lua +++ b/client/scripts/tnp3dump.lua @@ -126,7 +126,7 @@ local function main(args) local cmdSetDbgOff = "hf mf dbg 0" core.console( cmdSetDbgOff) - result, err = lib14a.read1443a(false) + result, err = lib14a.read1443a(false, true) if not result then return oops(err) end diff --git a/client/scripts/ufodump.lua b/client/scripts/ufodump.lua index 65d779f02..c2e080a09 100644 --- a/client/scripts/ufodump.lua +++ b/client/scripts/ufodump.lua @@ -24,20 +24,20 @@ local TIMEOUT = 2000 -- Shouldn't take longer than 2 seconds local DEBUG = false -- the debug flag --- -- A debug printout-function -function dbg(args) +local function dbg(args) if DEBUG then print("###", args) end end --- -- This is only meant to be used when errors occur -function oops(err) +local function oops(err) print("ERROR: ",err) core.clearCommandBuffer() end --- -- Usage help -function help() +local function help() print(desc) print("Example usage") print(example) @@ -92,7 +92,7 @@ end -- Send a "raw" iso14443a package, ie "hf 14a raw" command function sendRaw(rawdata, options) --print(">> ", rawdata) - local flags = lib14a.ISO14A_COMMAND.ISO14A_NO_DISCONNECT + lib14a.ISO14A_COMMAND.ISO14A_RAW + lib14a.ISO14A_COMMAND.ISO14A_APPEND_CRC + local flags = lib14a.ISO14A_COMMAND.ISO14A_NO_DISCONNECT + lib14a.ISO14A_COMMAND.ISO14A_RAW + lib14a.ISO14A_COMMAND.ISO14A_APPEND_CRC + lib14a.ISO14A_COMMAND.ISO14A_NO_RATS local command = Command:new{cmd = cmds.CMD_READER_ISO_14443a, arg1 = flags, -- Send raw -- arg2 contains the length, which is half the length @@ -125,7 +125,7 @@ function main(args) endblock = endblock or 20 -- First of all, connect - info, err = lib14a.read1443a(true) + info, err = lib14a.read1443a(true, true) if err then disconnect() return oops(err) end core.clearCommandBuffer() @@ -156,10 +156,7 @@ function main(args) print(string.format("\nDumped data into %s", filename)) end - - - - + ------------------------- -- Testing -------------------------