diff --git a/client/scripts/calypso.lua b/client/scripts/calypso.lua index 74de3cb9a..6b0a95151 100644 --- a/client/scripts/calypso.lua +++ b/client/scripts/calypso.lua @@ -4,27 +4,22 @@ local lib14b = require('read14b') local utils = require('utils') local iso7816 = require('7816_error') -example = "script runs 14b raw commands to query a CAPLYPSO tag" -author = "Iceman, 2016" -desc = -[[ +copyright = '' +author = 'Iceman' +version = 'v1.0.1' +desc = [[ This is a script to communicate with a CALYSPO / 14443b tag using the '14b raw' commands +]] +example = [[ + script run calypso -b 11223344 + +]] +usage = [[ +script run calypso -h -b Arguments: - -b 123 -Examples : - script run f -b 11223344 - script run f - -Examples : - -# 1. Connect and don't disconnect -script run f -# 2. Send mf auth, read response -script run f -# 3. disconnect -script run f - + h this helptext + b raw bytes to send ]] --[[ @@ -61,23 +56,34 @@ end --- -- A debug printout-function local function dbg(args) - if DEBUG then - print("###", args) + if not DEBUG then return end + if type(args) == 'table' then + local i = 1 + while args[i] do + dbg(args[i]) + i = i+1 + end + else + print('###', args) end end --- -- This is only meant to be used when errors occur local function oops(err) - print("ERROR: ", err) + print('ERROR: ', err) calypso_switch_off_field() return nil, err end --- -- Usage help local function help() + print(copyright) + print(author) + print(version) print(desc) - print("Example usage") + print('Example usage') print(example) + print(usage)) end -- -- helper function, give current count of items in lua-table. @@ -185,26 +191,26 @@ local _calypso_cmds = { -- Electronic Transaction log file - --["01.Select ICC file"] = '0294 a4 00 0002 3f00', - ["01.Select ICC file"] = '0294 a4 080004 3f00 0002', - ["02.ICC"] = '0394 b2 01 041d', - ["03.Select EnvHol file"] = '0294 a4 080004 2000 2001', - ["04.EnvHol1"] = '0394 b2 01 041d', - ["05.Select EvLog file"] = '0294 a4 080004 2000 2010', - ["06.EvLog1"] = '0394 b2 01 041d', - ["07.EvLog2"] = '0294 b2 02 041d', - ["08.EvLog3"] = '0394 b2 03 041d', - ["09.Select ConList file"]= '0294 a4 080004 2000 2050', - ["10.ConList"] = '0394 b2 01 041d', - ["11.Select Contra file"] = '0294 a4 080004 2000 2020', - ["12.Contra1"] = '0394 b2 01 041d', - ["13.Contra2"] = '0294 b2 02 041d', - ["14.Contra3"] = '0394 b2 03 041d', - ["15.Contra4"] = '0294 b2 04 041d', - ["16.Select Counter file"]= '0394 a4 080004 2000 2069', - ["17.Counter"] = '0294 b2 01 041d', - ["18.Select SpecEv file"] = '0394 a4 080004 2000 2040', - ["19.SpecEv1"] = '0294 b2 01 041d', + --['01.Select ICC file'] = '0294 a4 00 0002 3f00', + ['01.Select ICC file'] = '0294 a4 080004 3f00 0002', + ['02.ICC'] = '0394 b2 01 041d', + ['03.Select EnvHol file'] = '0294 a4 080004 2000 2001', + ['04.EnvHol1'] = '0394 b2 01 041d', + ['05.Select EvLog file'] = '0294 a4 080004 2000 2010', + ['06.EvLog1'] = '0394 b2 01 041d', + ['07.EvLog2'] = '0294 b2 02 041d', + ['08.EvLog3'] = '0394 b2 03 041d', + ['09.Select ConList file']= '0294 a4 080004 2000 2050', + ['10.ConList'] = '0394 b2 01 041d', + ['11.Select Contra file'] = '0294 a4 080004 2000 2020', + ['12.Contra1'] = '0394 b2 01 041d', + ['13.Contra2'] = '0294 b2 02 041d', + ['14.Contra3'] = '0394 b2 03 041d', + ['15.Contra4'] = '0294 b2 04 041d', + ['16.Select Counter file']= '0394 a4 080004 2000 2069', + ['17.Counter'] = '0294 b2 01 041d', + ['18.Select SpecEv file'] = '0394 a4 080004 2000 2040', + ['19.SpecEv1'] = '0294 b2 01 041d', } --- @@ -218,7 +224,8 @@ function main(args) local data, apdu, flags, uid, cid, result, err, card -- Read the parameters for o, a in getopt.getopt(args, 'h') do - if o == "h" then return help() end + if o == 'h' then return help() end + if o == 'b' then bytes = a end end calypso_switch_on_field() @@ -248,7 +255,7 @@ function main(args) --result, err = calypso_send_cmd_raw('0294a40800043f000002',false) --select ICC file for i, apdu in spairs(_calypso_cmds) do print('>>', i ) - apdu = apdu:gsub("%s+","") + apdu = apdu:gsub('%s+', '') result, err = calypso_send_cmd_raw(apdu , false) if result then calypso_apdu_status(result.data) @@ -263,12 +270,12 @@ end -- a simple selftest function, tries to convert function selftest() DEBUG = true - dbg("Performing test") - dbg("Tests done") + dbg('Performing test') + 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 "--test"==args then +if '--test'==args then selftest() else -- Call the main diff --git a/client/scripts/cmdline.lua b/client/scripts/cmdline.lua index 29627afc7..dc1e752c1 100644 --- a/client/scripts/cmdline.lua +++ b/client/scripts/cmdline.lua @@ -1,12 +1,16 @@ +--[[ +A sampe script file on how to implement at cmd line inteface. +--]] + print("This is how a cmd-line interface could be implemented\nPrint 'exit' to exit.\n") local answer repeat io.write("$>") io.flush() - answer=io.read() + answer = io.read() if answer ~= 'exit' then local func = assert(loadstring("return " .. answer)) io.write("\n"..tostring(func() or "").."\n"); end--]] -until answer=="exit" +until answer == "exit" print("Bye\n");