mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-21 13:53:55 -07:00
first batch of updated scripts to use sendMIX commands instead.
This commit is contained in:
parent
195887487b
commit
819896acf6
7 changed files with 223 additions and 194 deletions
|
@ -4,6 +4,7 @@ Handle Proxmark USB Commands
|
|||
|
||||
local _commands = require('usb_cmd')
|
||||
local util = require('utils')
|
||||
local TIMEOUT = 2000
|
||||
|
||||
local _reverse_lookup,k,v = {}
|
||||
for k, v in pairs(_commands) do
|
||||
|
@ -131,6 +132,14 @@ function Command:__responsetostring()
|
|||
print('package ::', self.resp_response)
|
||||
end
|
||||
|
||||
|
||||
--- Sends a packet to the device
|
||||
-- @param command - the usb packet to send
|
||||
-- @param ignoreresponse - if set to true, we don't read the device answer packet
|
||||
-- which is usually recipe for fail. If not sent, the host will wait 2s for a
|
||||
-- response of type CMD_ACK
|
||||
-- @return packet,nil if successfull
|
||||
-- nil, errormessage if unsuccessfull
|
||||
function Command:sendMIX( ignore_response, timeout )
|
||||
local data = self.data
|
||||
local cmd = self.cmd
|
||||
|
@ -139,7 +148,9 @@ function Command:sendMIX( ignore_response, timeout )
|
|||
local err, msg = core.SendCommandMIX(cmd, arg1, arg2, arg3, data)
|
||||
if err == nil then return err, msg end
|
||||
|
||||
if ignoreresponse then return true, nil end
|
||||
if ignore_response then return true, nil end
|
||||
|
||||
if timeout == nil then timeout = TIMEOUT end
|
||||
|
||||
local response, msg = core.WaitForResponseTimeout(_commands.CMD_ACK, timeout)
|
||||
if response == nil then
|
||||
|
@ -174,8 +185,10 @@ function Command:sendNG( ignore_response, timeout )
|
|||
local err, msg = core.SendCommandNG(cmd, data)
|
||||
if err == nil then return err, msg end
|
||||
|
||||
if ignoreresponse then return true, nil end
|
||||
|
||||
if ignore_response then return true, nil end
|
||||
|
||||
if timeout == nil then timeout = TIMEOUT end
|
||||
|
||||
local response, msg = core.WaitForResponseTimeout(cmd, timeout)
|
||||
if response == nil then
|
||||
return nil, 'Error, waiting for response timed out :: '..msg
|
||||
|
|
|
@ -71,26 +71,6 @@ local function parse14443a(data)
|
|||
return { uid = uid, atqa = atqa, sak = sak, name = tostring_14443a(sak), data = data}
|
||||
end
|
||||
|
||||
--- Sends a USBpacket to the device
|
||||
-- @param command - the usb packet to send
|
||||
-- @param ignoreresponse - if set to true, we don't read the device answer packet
|
||||
-- which is usually recipe for fail. If not sent, the host will wait 2s for a
|
||||
-- response of type CMD_ACK
|
||||
-- @return packet,nil if successfull
|
||||
-- nil, errormessage if unsuccessfull
|
||||
local function sendToDevice(command, ignoreresponse)
|
||||
--core.clearCommandBuffer()
|
||||
local err = core.SendCommand(command:getBytes())
|
||||
if err then
|
||||
print(err)
|
||||
return nil, err
|
||||
end
|
||||
if ignoreresponse then return nil,nil end
|
||||
|
||||
local response = core.WaitForResponseTimeout(cmds.CMD_ACK, TIMEOUT)
|
||||
return response,nil
|
||||
end
|
||||
|
||||
-- This function does a connect and retrieves som einfo
|
||||
-- @param dont_disconnect - if true, does not disable the field
|
||||
-- @return if successfull: an table containing card info
|
||||
|
@ -98,7 +78,10 @@ end
|
|||
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 }
|
||||
command = Command:newMIX{
|
||||
cmd = cmds.CMD_READER_ISO_14443a,
|
||||
arg1 = ISO14A_COMMAND.ISO14A_CONNECT
|
||||
}
|
||||
|
||||
if dont_disconnect then
|
||||
command.arg1 = command.arg1 + ISO14A_COMMAND.ISO14A_NO_DISCONNECT
|
||||
|
@ -106,17 +89,17 @@ local function read14443a(dont_disconnect, no_rats)
|
|||
if no_rats then
|
||||
command.arg1 = command.arg1 + ISO14A_COMMAND.ISO14A_NO_RATS
|
||||
end
|
||||
|
||||
local result,err = sendToDevice(command)
|
||||
|
||||
local result,err = command:sendMIX()
|
||||
if result then
|
||||
local count,cmd,arg0,arg1,arg2 = bin.unpack('LLLL',result)
|
||||
if arg0 == 0 then
|
||||
return nil, "iso14443a card select failed"
|
||||
return nil, 'iso14443a card select failed'
|
||||
end
|
||||
data = string.sub(result,count)
|
||||
info, err = parse14443a(data)
|
||||
else
|
||||
err ="No response from card"
|
||||
err = 'No response from card'
|
||||
end
|
||||
|
||||
if err then
|
||||
|
@ -143,7 +126,6 @@ local library = {
|
|||
read = read14443a,
|
||||
waitFor14443a = waitFor14443a,
|
||||
parse14443a = parse14443a,
|
||||
sendToDevice = sendToDevice,
|
||||
ISO14A_COMMAND = ISO14A_COMMAND,
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue