iso14a reader patches [Hagen Fritsch]

This commit is contained in:
adam@algroup.co.uk 2010-07-13 13:39:30 +00:00
commit 534983d735
12 changed files with 255 additions and 95 deletions

View file

@ -45,6 +45,7 @@ CMDSRCS = \
data.c \
graph.c \
ui.c \
util.c \
cmddata.c \
cmdhf.c \
cmdhf14a.c \

View file

@ -1,5 +1,5 @@
//-----------------------------------------------------------------------------
// Copyright (C) 2010 iZsh <izsh at fail0verflow.com>
// Copyright (C) 2010 iZsh <izsh at fail0verflow.com>, Hagen Fritsch
//
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
// at your option, any later version. See the LICENSE.txt file for the text of
@ -17,6 +17,7 @@
#include "ui.h"
#include "cmdparser.h"
#include "cmdhf14a.h"
#include "common.h"
static int CmdHelp(const char *Cmd);
@ -147,6 +148,11 @@ int CmdHF14AList(const char *Cmd)
return 0;
}
void iso14a_set_timeout(uint32_t timeout) {
UsbCommand c = {CMD_READER_ISO_14443a, {ISO14A_SET_TIMEOUT, 0, timeout}};
SendCommand(&c);
}
int CmdHF14AMifare(const char *Cmd)
{
UsbCommand c = {CMD_READER_MIFARE, {strtol(Cmd, NULL, 0), 0, 0}};
@ -156,9 +162,26 @@ int CmdHF14AMifare(const char *Cmd)
int CmdHF14AReader(const char *Cmd)
{
UsbCommand c = {CMD_READER_ISO_14443a, {strtol(Cmd, NULL, 0), 0, 0}};
SendCommand(&c);
return 0;
UsbCommand c = {CMD_READER_ISO_14443a, {ISO14A_CONNECT, 0, 0}};
SendCommand(&c);
UsbCommand * resp = WaitForResponse(CMD_ACK);
uint8_t * uid = resp->d.asBytes;
iso14a_card_select_t * card = uid + 12;
if(resp->arg[0] == 0) {
PrintAndLog("iso14443a card select failed");
return 0;
}
PrintAndLog("ATQA : %02x %02x", card->atqa[0], card->atqa[1]);
PrintAndLog(" UID : %s", sprint_hex(uid, 12));
PrintAndLog(" SAK : %02x [%d]", card->sak, resp->arg[0]);
if(resp->arg[0] == 1)
PrintAndLog(" ATS : %s", sprint_hex(card->ats, card->ats_len));
else
PrintAndLog("proprietary non-iso14443a card found, RATS not supported");
return resp->arg[0];
}
// ## simulate iso14443a tag

View file

@ -25,6 +25,7 @@
unsigned int current_command = CMD_UNKNOWN;
unsigned int received_command = CMD_UNKNOWN;
UsbCommand current_response;
static int CmdHelp(const char *Cmd);
static int CmdQuit(const char *Cmd);
@ -53,12 +54,25 @@ int CmdQuit(const char *Cmd)
return 0;
}
void WaitForResponse(uint32_t response_type)
UsbCommand * WaitForResponseTimeout(uint32_t response_type, uint32_t ms_timeout) {
UsbCommand * ret = &current_response;
int i=0;
for(i=0; received_command != response_type && i < ms_timeout / 10; i++) {
msleep(10); // XXX ugh
}
if(received_command != response_type)
ret = NULL;
received_command = CMD_UNKNOWN;
return ret;
}
UsbCommand * WaitForResponse(uint32_t response_type)
{
while (received_command != response_type) {
msleep(10); // XXX ugh
}
received_command = CMD_UNKNOWN;
return WaitForResponseTimeout(response_type, -1);
}
//-----------------------------------------------------------------------------
@ -137,7 +151,11 @@ void UsbCommandReceived(UsbCommand *UC)
return;
default:
unexpected_response:
PrintAndLog("unrecognized command %08x\n", UC->cmd);
break;
if(UC->cmd != CMD_ACK)
PrintAndLog("unrecognized command %08x\n", UC->cmd);
else
memcpy(&current_response, UC, sizeof(UsbCommand));
received_command = UC->cmd;
}
}

View file

@ -15,6 +15,7 @@
void UsbCommandReceived(UsbCommand *UC);
void CommandReceived(char *Cmd);
void WaitForResponse(uint32_t response_type);
UsbCommand * WaitForResponseTimeout(uint32_t response_type, uint32_t ms_timeout);
UsbCommand * WaitForResponse(uint32_t response_type);
#endif

View file

@ -151,9 +151,10 @@ usb_dev_handle* findProxmark(int verbose, unsigned int *iface)
fprintf(stdout, "\nConnected units:\n");
for (int i = 0; i < iUnit; i++)
fprintf(stdout, "\t%d. SN: %s\n", i+1, units[i].serial_number);
for (int i = 0; i < iUnit; i++) {
struct usb_device * dev = usb_device(units[i].handle);
fprintf(stdout, "\t%d. SN: %s [%s/%s]\n", i+1, units[i].serial_number, dev->bus->dirname, dev->filename);
}
if (iUnit > 1) {
while (iSelection < 1 || iSelection > iUnit) {
fprintf(stdout, "Which unit do you want to connect to? ");

23
client/util.c Normal file
View file

@ -0,0 +1,23 @@
#include <stdio.h>
#include <stdint.h>
void print_hex(const uint8_t * data, const size_t len)
{
size_t i;
for (i=0; i < len; i++)
printf("%02x ", data[i]);
printf("\n");
}
char * sprint_hex(const uint8_t * data, const size_t len) {
static char buf[1024];
char * tmp = buf;
size_t i;
for (i=0; i < len && i < 1024/3; i++, tmp += 3)
sprintf(tmp, "%02x ", data[i]);
return buf;
}

1
client/util.h Normal file
View file

@ -0,0 +1 @@
void print_hex(const uint8_t * data, const size_t len);