local getopt = require('getopt')
local lib14a = require('read14a')
-example = "script run writerraw -x 6000F57b"
+example = "script run 14araw -x 6000F57b"
author = "Martin Holst Swende"
-p stay connected - dont inactivate the field
-x <payload> Data to send (NO SPACES!)
-d Debug flag
+ -t Topaz mode
+ -3 Skip ISO14443-4 select
Examples :
# 1. Connect and don't disconnect
-script run writeraw -p
+script run 14araw -p
# 2. Send mf auth, read response (nonce)
-script run writeraw -o -x 6000F57b -p
+script run 14araw -o -x 6000F57b -p
# 3. disconnect
-script run writeraw -o
+script run 14araw -o
# All three steps in one go:
-script run writeraw -x 6000F57b
+script run 14araw -x 6000F57b
]]
--[[
-- A debug printout-function
function dbg(args)
if DEBUG then
- print("# ", args)
+ print("###", args)
end
end
---
print(example)
end
+
---
-- The main entry point
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, 'orcpx:dt3') 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
dbg("doconnect")
-- We reuse the connect functionality from a
-- common library
- info, err = lib14a.read1443a(true)
+ info, err = lib14a.read14443a(true, no_rats)
if err then return oops(err) end
print(("Connected to card, uid = %s"):format(info.uid))
-- 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
end
-
function sendRaw(rawdata, options)
print(">> ", rawdata)
local flags = lib14a.ISO14A_COMMAND.ISO14A_NO_DISCONNECT + lib14a.ISO14A_COMMAND.ISO14A_RAW
+ if options.topaz_mode == true then flags = flags + lib14a.ISO14A_COMMAND.ISO14A_TOPAZMODE end
local command = Command:new{cmd = cmds.CMD_READER_ISO_14443a,
arg1 = flags, -- Send raw
-- Testing
-------------------------
function selftest()
+ DEBUG = true
+ dbg("Performing test")
+ main()
main("-p")
main(" -o -x 6000F57b -p")
main("-o")
main("-x 6000F57b")
+ dbg("Tests done")
end
-- Flip the switch here to perform a sanity check.
-- It read a nonce in two different ways, as specified in the usage-section
-if false then
+if "--test"==args then
selftest()
else
-- Call the main