Got rid of unnecessary code which was being used for debugging.

This commit is contained in:
Dom 2018-02-27 20:13:57 +00:00
commit 7b2e196dcb
3 changed files with 35 additions and 69 deletions

View file

@ -111,7 +111,6 @@ local function read14443a(dont_disconnect, no_rats)
end
local result,err = sendToDevice(command)
if result then
print("Currently trying to decode the UsbCommand packet just received (an ACK of the connection).")
local count,cmd,arg0,arg1,arg2 = bin.unpack('LLLL',result)
if arg0 == 0 then
return nil, "iso14443a card select failed"

View file

@ -102,36 +102,35 @@ static int l_WaitForResponseTimeout(lua_State *L){
if(WaitForResponseTimeout(cmd, &response, ms_timeout))
{
//BEGIN ADDED CODE
uint8_t *recv;
char *hexout;
recv = response.d.asBytes;
uint8_t iLen = response.arg[0];
if (0){
iLen = response.arg[1];
if (iLen){
PrintAndLog("Card selected. UID[%i]:", iLen);
} else {
PrintAndLog("Can't select card.");
}
} else {
PrintAndLog("received %i bytes:", iLen);
}
if(!iLen)
return 1;
hexout = (char *)malloc(iLen * 3 + 1);
if (hexout != NULL) {
for (int i = 0; i < iLen; i++) { // data in hex
sprintf(&hexout[i * 3], "%02X ", recv[i]);
}
PrintAndLog("%s", hexout);
free(hexout);
} else {
PrintAndLog("malloc failed your client has low memory?");
return 2;
}
printf("Command response just sent back to Lua script with the bytes which were just printed. Should get sent to read14a.lua.\n");
//END ADDED CODE
/* Uncomment code below to print the bytes which were received from the C code before they get passed to Lua. */
// uint8_t *recv;
// char *hexout;
// recv = response.d.asBytes;
// uint8_t iLen = response.arg[0];
// if (0){
// iLen = response.arg[1];
// if (iLen){
// PrintAndLog("Card selected. UID[%i]:", iLen);
// } else {
// PrintAndLog("Can't select card.");
// }
// } else {
// PrintAndLog("received %i bytes:", iLen);
// }
// if(!iLen)
// return 1;
// hexout = (char *)malloc(iLen * 3 + 1);
// if (hexout != NULL) {
// for (int i = 0; i < iLen; i++) { // data in hex
// sprintf(&hexout[i * 3], "%02X ", recv[i]);
// }
// PrintAndLog("%s", hexout);
// free(hexout);
// } else {
// PrintAndLog("malloc failed your client has low memory?");
// return 2;
// }
// printf("Command response just sent back to Lua script with the bytes which were just printed.\n");
//Push it as a string

View file

@ -11,15 +11,9 @@ end
function sendRaw(rawdata, crc)
print(">> ", rawdata)
-- if crc
-- then local flags = lib14a.ISO14A_COMMAND.ISO14A_NO_DISCONNECT + lib14a.ISO14A_COMMAND.ISO14A_RAW
-- else local flags = lib14a.ISO14A_COMMAND.ISO14A_NO_DISCONNECT + lib14a.ISO14A_COMMAND.ISO14A_RAW + lib14a.ISO14A_APPEND_CRC
-- end
--get rid of the ISO14A_APPEND_CRC flag if we don't want a CRC to be appended to the raw bytes.
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
local command = Command:new{cmd = cmds.CMD_READER_ISO_14443a,
arg1 = flags, -- Send raw
arg2 = string.len(rawdata) / 2, -- arg2 contains the length, which is half the length of the ASCII-string rawdata
@ -32,53 +26,27 @@ end
-- The main entry point
function main(args)
-- Manually send the card the init commands
-- firstcommand = Command:new{cmd = cmds.CMD_READER_ISO_14443a,
-- arg1 = lib14a.ISO14A_COMMAND.ISO14A_CONNECT + lib14a.ISO14A_COMMAND.ISO14A_NO_DISCONNECT,
-- arg2 = 0,
-- data = ""}
-- local restwo,errtwo = lib14a.sendToDevice(firstcommand)
-- print(firstcommand.arg1)
-- Call the program via the command line
-- result = core.console("hf 14a raw -p -b 7 -a 26") --I can do this from the command line, but I can't capture the output easily
-- print(result)
-- Send the card the init commands using the read14a library, reusing the connect functionality from a common library
-- Initialize the card using the read14a library
info,err = lib14a.read14443a(true, no_rats)
if err
then oops(err)
else print(("Connected to card with a UID of %s"):format(info.uid))
end
--Attempt to send raw data
getvers = "0360" -- 0x0360 should begin the "get version" commands
--print(string.byte(getvers, 1, 99999))
--crc = core.crc16(getvers) -- under the hood, calls ComputeCrc14443, which is the same function which is called by "hf 14a raw"
--print(string.byte(crc, 1, 99999))
-- Now that the card is initialized, attempt to send raw data and read the response.
getvers = "0360" -- 0x0360 begins the "get version" commands
local result,err = sendRaw(getvers, true)
if result then
print("Currently trying to decode raw UsbCommand packet received.")
print(result)
local count,cmd,arg1,arg2,arg3,data = bin.unpack('LLLLH512',result)
print(data)
--data = string.sub(result,count)
--local cmd_response = Command.parse(res)
else
err ="No response from card"
end
-- local cmd_response = Command.parse(res)
-- local len = tonumber(cmd_response.arg1) *2
-- print("data length:",len)
-- local data = string.sub(tostring(cmd_response.data), 0, len);
-- print("<< ",data)
err = "No response from sending the card raw data."
oops(err)
end
end
main(args) -- Call the main function