mirror of
https://github.com/Proxmark/proxmark3.git
synced 2025-08-14 10:36:58 -07:00
Merge pull request #407 from pwpiwi/no_rats
Don't do iso14443-4 select for mifare emulations on processor cards (IDPrime, SmartMX, …)
This commit is contained in:
commit
77aecdd286
17 changed files with 88 additions and 65 deletions
|
@ -442,7 +442,7 @@ int CmdHF14ACUIDs(const char *Cmd)
|
|||
// repeat n times
|
||||
for (int i = 0; i < n; i++) {
|
||||
// execute anticollision procedure
|
||||
UsbCommand c = {CMD_READER_ISO_14443a, {ISO14A_CONNECT, 0, 0}};
|
||||
UsbCommand c = {CMD_READER_ISO_14443a, {ISO14A_CONNECT | ISO14A_NO_RATS, 0, 0}};
|
||||
SendCommand(&c);
|
||||
|
||||
UsbCommand resp;
|
||||
|
@ -581,6 +581,7 @@ int CmdHF14ACmdRaw(const char *cmd) {
|
|||
bool power = false;
|
||||
bool active = false;
|
||||
bool active_select = false;
|
||||
bool no_rats = false;
|
||||
uint16_t numbits = 0;
|
||||
bool bTimeout = false;
|
||||
uint32_t timeout = 0;
|
||||
|
@ -601,6 +602,7 @@ int CmdHF14ACmdRaw(const char *cmd) {
|
|||
PrintAndLog(" -b number of bits to send. Useful for send partial byte");
|
||||
PrintAndLog(" -t timeout in ms");
|
||||
PrintAndLog(" -T use Topaz protocol to send command");
|
||||
PrintAndLog(" -3 ISO14443-3 select only (skip RATS)");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -645,6 +647,9 @@ int CmdHF14ACmdRaw(const char *cmd) {
|
|||
case 'T':
|
||||
topazmode = true;
|
||||
break;
|
||||
case '3':
|
||||
no_rats = true;
|
||||
break;
|
||||
default:
|
||||
PrintAndLog("Invalid option");
|
||||
return 0;
|
||||
|
@ -718,6 +723,10 @@ int CmdHF14ACmdRaw(const char *cmd) {
|
|||
c.arg[0] |= ISO14A_TOPAZMODE;
|
||||
}
|
||||
|
||||
if(no_rats) {
|
||||
c.arg[0] |= ISO14A_NO_RATS;
|
||||
}
|
||||
|
||||
// Max buffer is USB_CMD_DATA_SIZE (512)
|
||||
c.arg[1] = (datalen & 0xFFFF) | ((uint32_t)numbits << 16);
|
||||
memcpy(c.d.asBytes,data,datalen);
|
||||
|
|
|
@ -108,7 +108,7 @@ char *getUlev1CardSizeStr( uint8_t fsize ){
|
|||
}
|
||||
|
||||
static void ul_switch_on_field(void) {
|
||||
UsbCommand c = {CMD_READER_ISO_14443a, {ISO14A_CONNECT | ISO14A_NO_DISCONNECT, 0, 0}};
|
||||
UsbCommand c = {CMD_READER_ISO_14443a, {ISO14A_CONNECT | ISO14A_NO_DISCONNECT | ISO14A_NO_RATS, 0, 0}};
|
||||
clearCommandBuffer();
|
||||
SendCommand(&c);
|
||||
}
|
||||
|
|
|
@ -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 = {}
|
||||
|
@ -92,9 +93,10 @@ end
|
|||
|
||||
-- This function does a connect and retrieves som einfo
|
||||
-- @param dont_disconnect - if true, does not disable the field
|
||||
-- @param no_rats - if true, skips ISO14443-4 select (RATS)
|
||||
-- @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,
|
||||
|
@ -102,6 +104,9 @@ local function read14443a(dont_disconnect)
|
|||
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)
|
||||
|
|
|
@ -519,20 +519,20 @@ int mfCIdentify()
|
|||
UsbCommand resp;
|
||||
WaitForResponse(CMD_ACK,&resp);
|
||||
|
||||
iso14a_card_select_t card;
|
||||
memcpy(&card, (iso14a_card_select_t *)resp.d.asBytes, sizeof(iso14a_card_select_t));
|
||||
// iso14a_card_select_t card;
|
||||
// memcpy(&card, (iso14a_card_select_t *)resp.d.asBytes, sizeof(iso14a_card_select_t));
|
||||
|
||||
uint64_t select_status = resp.arg[0]; // 0: couldn't read, 1: OK, with ATS, 2: OK, no ATS, 3: proprietary Anticollision
|
||||
// uint64_t select_status = resp.arg[0]; // 0: couldn't read, 1: OK, with ATS, 2: OK, no ATS, 3: proprietary Anticollision
|
||||
|
||||
if(select_status != 0) {
|
||||
uint8_t rats[] = { 0xE0, 0x80 }; // FSDI=8 (FSD=256), CID=0
|
||||
c.arg[0] = ISO14A_RAW | ISO14A_APPEND_CRC | ISO14A_NO_DISCONNECT;
|
||||
c.arg[1] = 2;
|
||||
c.arg[2] = 0;
|
||||
memcpy(c.d.asBytes, rats, 2);
|
||||
SendCommand(&c);
|
||||
WaitForResponse(CMD_ACK,&resp);
|
||||
}
|
||||
// if(select_status != 0) {
|
||||
// uint8_t rats[] = { 0xE0, 0x80 }; // FSDI=8 (FSD=256), CID=0
|
||||
// c.arg[0] = ISO14A_RAW | ISO14A_APPEND_CRC | ISO14A_NO_DISCONNECT;
|
||||
// c.arg[1] = 2;
|
||||
// c.arg[2] = 0;
|
||||
// memcpy(c.d.asBytes, rats, 2);
|
||||
// SendCommand(&c);
|
||||
// WaitForResponse(CMD_ACK,&resp);
|
||||
// }
|
||||
|
||||
c.cmd = CMD_MIFARE_CIDENT;
|
||||
c.arg[0] = 0;
|
||||
|
|
|
@ -17,6 +17,8 @@ Arguments:
|
|||
-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 :
|
||||
|
||||
|
@ -70,6 +72,7 @@ function help()
|
|||
print(example)
|
||||
end
|
||||
|
||||
|
||||
---
|
||||
-- The main entry point
|
||||
function main(args)
|
||||
|
@ -83,15 +86,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, '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
|
||||
|
@ -99,7 +106,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))
|
||||
|
@ -107,7 +114,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
|
||||
|
@ -137,11 +144,11 @@ function showdata(usbpacket)
|
|||
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
|
||||
|
|
|
@ -406,7 +406,7 @@ function main(args)
|
|||
|
||||
-- GET TAG UID
|
||||
|
||||
result, err = lib14a.read1443a(false)
|
||||
result, err = lib14a.read1443a(false, true)
|
||||
if not result then
|
||||
return oops(err)
|
||||
end
|
||||
|
|
|
@ -71,7 +71,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
|
||||
|
|
|
@ -170,7 +170,7 @@ local function main( args)
|
|||
|
||||
print(desc);
|
||||
|
||||
result, err = reader.read1443a()
|
||||
result, err = reader.read1443a(false, true)
|
||||
if not result then
|
||||
print(err)
|
||||
return
|
||||
|
|
|
@ -56,7 +56,7 @@ end
|
|||
-- @return if unsuccessfull : nil, error
|
||||
function wait_for_mifare()
|
||||
while not core.ukbhit() do
|
||||
res, err = reader.read1443a()
|
||||
res, err = reader.read1443a(false, true)
|
||||
if res then return res end
|
||||
-- err means that there was no response from card
|
||||
end
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -127,7 +127,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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue