2010-02-21 08:47:22 +08:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Copyright (C) 2010 iZsh <izsh at fail0verflow.com>
|
|
|
|
//
|
|
|
|
// 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
|
|
|
|
// the license.
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// High frequency commands
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
Client cleanup and restructuring. Stage 1...
Next Step is refactoring some of the giant functions which are
just copy/paste of some other ones with just a few line changes,
removing unnecessary 'goto' etc.
The MS Windows version is broken with this commit but will be fixed
soon. Everything can't be done all at once :P
The commands are now hierarchical, for example:
"hf 14a read" vs. "hf 14b read".
You can also request help:
"hf help", "data help", "hf 15 help" etc.
Indents are now space-based, not tab-based anymore. Hopefully
no one will be trolling about it, considering the suicide-prone work
being done here ;)
client/cmdhw.c, client/proxusb.c, client/cmdhw.h, client/proxusb.h,
client/cmdmain.c, client/cmdlfhid.c, client/cmdmain.h, client/cmdlfhid.h,
client/data.c, client/data.h, client/cmdhf.c, client/cmdlf.c,
client/cmdhf.h, client/cmdhf15.c, client/cmdhf14b.c, client/cmdlf.h,
client/cmdhf15.h, client/cmdhf14b.h, client/cmddata.c, client/cmddata.h,
client/ui.c, client/cmdparser.c, client/cmdlfti.c, client/ui.h,
client/cmdlfem4x.c, client/cmdparser.h, client/cmdlfti.h, client/cmdlfem4x.h,
client/graph.c, client/graph.h, client/cmdhf14a.c, client/cmdhf14a.h,
client/cmdhflegic.c, client/cmdhflegic.c: New files.
client/cli.c, client/flasher.c, client/snooper.c, client/proxmark3.c,
client/proxmark3.h, client/Makefile: Update accordingly.
client/flash.h, client/flash.c, client/proxgui.cpp: Cosmetic changes.
client/translate.h, client/command.c, client/gui.c,
client/usb.c, client/prox.h: Remove.
include/usb_cmd.h (CMD_ACQUIRE_RAW_ADC_SAMPLES_ISO_14443_SIM): Remove dead cmd.
common/crc16.h: New file.
common/crc16.c: Modify accordingly.
common/iso14443crc.h: New file.
common/iso14443_crc.c: Rename to
common/iso14443crc.c: and modify accordingly.
armsrc/lfops.c, armsrc/iso14443.c,
armsrc/iso14443a.c: include .h files from
the common directory instead of including the c files.
common/Makefile.common, armsrc/Makefile: Modify accordingly.
2010-02-04 09:27:07 +08:00
|
|
|
#include <stdio.h>
|
2015-01-05 04:22:54 +08:00
|
|
|
#include <string.h>
|
2012-12-05 07:39:18 +08:00
|
|
|
#include "proxmark3.h"
|
Client cleanup and restructuring. Stage 1...
Next Step is refactoring some of the giant functions which are
just copy/paste of some other ones with just a few line changes,
removing unnecessary 'goto' etc.
The MS Windows version is broken with this commit but will be fixed
soon. Everything can't be done all at once :P
The commands are now hierarchical, for example:
"hf 14a read" vs. "hf 14b read".
You can also request help:
"hf help", "data help", "hf 15 help" etc.
Indents are now space-based, not tab-based anymore. Hopefully
no one will be trolling about it, considering the suicide-prone work
being done here ;)
client/cmdhw.c, client/proxusb.c, client/cmdhw.h, client/proxusb.h,
client/cmdmain.c, client/cmdlfhid.c, client/cmdmain.h, client/cmdlfhid.h,
client/data.c, client/data.h, client/cmdhf.c, client/cmdlf.c,
client/cmdhf.h, client/cmdhf15.c, client/cmdhf14b.c, client/cmdlf.h,
client/cmdhf15.h, client/cmdhf14b.h, client/cmddata.c, client/cmddata.h,
client/ui.c, client/cmdparser.c, client/cmdlfti.c, client/ui.h,
client/cmdlfem4x.c, client/cmdparser.h, client/cmdlfti.h, client/cmdlfem4x.h,
client/graph.c, client/graph.h, client/cmdhf14a.c, client/cmdhf14a.h,
client/cmdhflegic.c, client/cmdhflegic.c: New files.
client/cli.c, client/flasher.c, client/snooper.c, client/proxmark3.c,
client/proxmark3.h, client/Makefile: Update accordingly.
client/flash.h, client/flash.c, client/proxgui.cpp: Cosmetic changes.
client/translate.h, client/command.c, client/gui.c,
client/usb.c, client/prox.h: Remove.
include/usb_cmd.h (CMD_ACQUIRE_RAW_ADC_SAMPLES_ISO_14443_SIM): Remove dead cmd.
common/crc16.h: New file.
common/crc16.c: Modify accordingly.
common/iso14443crc.h: New file.
common/iso14443_crc.c: Rename to
common/iso14443crc.c: and modify accordingly.
armsrc/lfops.c, armsrc/iso14443.c,
armsrc/iso14443a.c: include .h files from
the common directory instead of including the c files.
common/Makefile.common, armsrc/Makefile: Modify accordingly.
2010-02-04 09:27:07 +08:00
|
|
|
#include "graph.h"
|
|
|
|
#include "ui.h"
|
|
|
|
#include "cmdparser.h"
|
|
|
|
#include "cmdhf.h"
|
|
|
|
#include "cmdhf14a.h"
|
|
|
|
#include "cmdhf14b.h"
|
|
|
|
#include "cmdhf15.h"
|
2012-08-29 05:39:50 +08:00
|
|
|
#include "cmdhfepa.h"
|
Client cleanup and restructuring. Stage 1...
Next Step is refactoring some of the giant functions which are
just copy/paste of some other ones with just a few line changes,
removing unnecessary 'goto' etc.
The MS Windows version is broken with this commit but will be fixed
soon. Everything can't be done all at once :P
The commands are now hierarchical, for example:
"hf 14a read" vs. "hf 14b read".
You can also request help:
"hf help", "data help", "hf 15 help" etc.
Indents are now space-based, not tab-based anymore. Hopefully
no one will be trolling about it, considering the suicide-prone work
being done here ;)
client/cmdhw.c, client/proxusb.c, client/cmdhw.h, client/proxusb.h,
client/cmdmain.c, client/cmdlfhid.c, client/cmdmain.h, client/cmdlfhid.h,
client/data.c, client/data.h, client/cmdhf.c, client/cmdlf.c,
client/cmdhf.h, client/cmdhf15.c, client/cmdhf14b.c, client/cmdlf.h,
client/cmdhf15.h, client/cmdhf14b.h, client/cmddata.c, client/cmddata.h,
client/ui.c, client/cmdparser.c, client/cmdlfti.c, client/ui.h,
client/cmdlfem4x.c, client/cmdparser.h, client/cmdlfti.h, client/cmdlfem4x.h,
client/graph.c, client/graph.h, client/cmdhf14a.c, client/cmdhf14a.h,
client/cmdhflegic.c, client/cmdhflegic.c: New files.
client/cli.c, client/flasher.c, client/snooper.c, client/proxmark3.c,
client/proxmark3.h, client/Makefile: Update accordingly.
client/flash.h, client/flash.c, client/proxgui.cpp: Cosmetic changes.
client/translate.h, client/command.c, client/gui.c,
client/usb.c, client/prox.h: Remove.
include/usb_cmd.h (CMD_ACQUIRE_RAW_ADC_SAMPLES_ISO_14443_SIM): Remove dead cmd.
common/crc16.h: New file.
common/crc16.c: Modify accordingly.
common/iso14443crc.h: New file.
common/iso14443_crc.c: Rename to
common/iso14443crc.c: and modify accordingly.
armsrc/lfops.c, armsrc/iso14443.c,
armsrc/iso14443a.c: include .h files from
the common directory instead of including the c files.
common/Makefile.common, armsrc/Makefile: Modify accordingly.
2010-02-04 09:27:07 +08:00
|
|
|
#include "cmdhflegic.h"
|
2011-05-18 20:33:32 +08:00
|
|
|
#include "cmdhficlass.h"
|
2011-06-10 21:35:10 +08:00
|
|
|
#include "cmdhfmf.h"
|
2015-01-21 04:23:04 +08:00
|
|
|
#include "cmdhfmfu.h"
|
2015-03-19 00:12:09 +08:00
|
|
|
#include "cmdhftopaz.h"
|
2015-02-19 03:02:44 +08:00
|
|
|
#include "protocols.h"
|
Client cleanup and restructuring. Stage 1...
Next Step is refactoring some of the giant functions which are
just copy/paste of some other ones with just a few line changes,
removing unnecessary 'goto' etc.
The MS Windows version is broken with this commit but will be fixed
soon. Everything can't be done all at once :P
The commands are now hierarchical, for example:
"hf 14a read" vs. "hf 14b read".
You can also request help:
"hf help", "data help", "hf 15 help" etc.
Indents are now space-based, not tab-based anymore. Hopefully
no one will be trolling about it, considering the suicide-prone work
being done here ;)
client/cmdhw.c, client/proxusb.c, client/cmdhw.h, client/proxusb.h,
client/cmdmain.c, client/cmdlfhid.c, client/cmdmain.h, client/cmdlfhid.h,
client/data.c, client/data.h, client/cmdhf.c, client/cmdlf.c,
client/cmdhf.h, client/cmdhf15.c, client/cmdhf14b.c, client/cmdlf.h,
client/cmdhf15.h, client/cmdhf14b.h, client/cmddata.c, client/cmddata.h,
client/ui.c, client/cmdparser.c, client/cmdlfti.c, client/ui.h,
client/cmdlfem4x.c, client/cmdparser.h, client/cmdlfti.h, client/cmdlfem4x.h,
client/graph.c, client/graph.h, client/cmdhf14a.c, client/cmdhf14a.h,
client/cmdhflegic.c, client/cmdhflegic.c: New files.
client/cli.c, client/flasher.c, client/snooper.c, client/proxmark3.c,
client/proxmark3.h, client/Makefile: Update accordingly.
client/flash.h, client/flash.c, client/proxgui.cpp: Cosmetic changes.
client/translate.h, client/command.c, client/gui.c,
client/usb.c, client/prox.h: Remove.
include/usb_cmd.h (CMD_ACQUIRE_RAW_ADC_SAMPLES_ISO_14443_SIM): Remove dead cmd.
common/crc16.h: New file.
common/crc16.c: Modify accordingly.
common/iso14443crc.h: New file.
common/iso14443_crc.c: Rename to
common/iso14443crc.c: and modify accordingly.
armsrc/lfops.c, armsrc/iso14443.c,
armsrc/iso14443a.c: include .h files from
the common directory instead of including the c files.
common/Makefile.common, armsrc/Makefile: Modify accordingly.
2010-02-04 09:27:07 +08:00
|
|
|
|
|
|
|
static int CmdHelp(const char *Cmd);
|
|
|
|
|
|
|
|
int CmdHFTune(const char *Cmd)
|
|
|
|
{
|
|
|
|
UsbCommand c={CMD_MEASURE_ANTENNA_TUNING_HF};
|
|
|
|
SendCommand(&c);
|
|
|
|
return 0;
|
|
|
|
}
|
2015-01-05 04:22:54 +08:00
|
|
|
|
|
|
|
|
|
|
|
void annotateIso14443a(char *exp, size_t size, uint8_t* cmd, uint8_t cmdsize)
|
|
|
|
{
|
|
|
|
switch(cmd[0])
|
|
|
|
{
|
2015-01-17 05:41:19 +08:00
|
|
|
case ISO14443A_CMD_WUPA: snprintf(exp,size,"WUPA"); break;
|
|
|
|
case ISO14443A_CMD_ANTICOLL_OR_SELECT:{
|
2015-01-08 04:14:32 +08:00
|
|
|
// 93 20 = Anticollision (usage: 9320 - answer: 4bytes UID+1byte UID-bytes-xor)
|
|
|
|
// 93 70 = Select (usage: 9370+5bytes 9320 answer - answer: 1byte SAK)
|
2015-01-28 04:55:08 +08:00
|
|
|
if(cmd[1] == 0x70)
|
2015-01-05 04:22:54 +08:00
|
|
|
{
|
|
|
|
snprintf(exp,size,"SELECT_UID"); break;
|
|
|
|
}else
|
|
|
|
{
|
2015-01-08 04:14:32 +08:00
|
|
|
snprintf(exp,size,"ANTICOLL"); break;
|
|
|
|
}
|
|
|
|
}
|
2015-01-17 05:41:19 +08:00
|
|
|
case ISO14443A_CMD_ANTICOLL_OR_SELECT_2:{
|
2015-01-08 04:14:32 +08:00
|
|
|
//95 20 = Anticollision of cascade level2
|
|
|
|
//95 70 = Select of cascade level2
|
|
|
|
if(cmd[2] == 0x70)
|
|
|
|
{
|
|
|
|
snprintf(exp,size,"SELECT_UID-2"); break;
|
|
|
|
}else
|
|
|
|
{
|
|
|
|
snprintf(exp,size,"ANTICOLL-2"); break;
|
2015-01-05 04:22:54 +08:00
|
|
|
}
|
|
|
|
}
|
2015-03-10 04:36:27 +08:00
|
|
|
case ISO14443A_CMD_REQA: snprintf(exp,size,"REQA"); break;
|
|
|
|
case ISO14443A_CMD_READBLOCK: snprintf(exp,size,"READBLOCK(%d)",cmd[1]); break;
|
|
|
|
case ISO14443A_CMD_WRITEBLOCK: snprintf(exp,size,"WRITEBLOCK(%d)",cmd[1]); break;
|
|
|
|
case ISO14443A_CMD_HALT: snprintf(exp,size,"HALT"); break;
|
|
|
|
case ISO14443A_CMD_RATS: snprintf(exp,size,"RATS"); break;
|
|
|
|
case MIFARE_CMD_INC: snprintf(exp,size,"INC(%d)",cmd[1]); break;
|
|
|
|
case MIFARE_CMD_DEC: snprintf(exp,size,"DEC(%d)",cmd[1]); break;
|
|
|
|
case MIFARE_CMD_RESTORE: snprintf(exp,size,"RESTORE(%d)",cmd[1]); break;
|
|
|
|
case MIFARE_CMD_TRANSFER: snprintf(exp,size,"TRANSFER(%d)",cmd[1]); break;
|
2015-05-06 12:55:29 +08:00
|
|
|
case MIFARE_AUTH_KEYA:{
|
|
|
|
if ( cmdsize > 3)
|
|
|
|
snprintf(exp,size,"AUTH-A(%d)",cmd[1]);
|
|
|
|
else
|
|
|
|
// case MIFARE_ULEV1_VERSION : both 0x60.
|
|
|
|
snprintf(exp,size,"EV1 VERSION");
|
|
|
|
break;
|
|
|
|
}
|
2015-03-10 04:36:27 +08:00
|
|
|
case MIFARE_AUTH_KEYB: snprintf(exp,size,"AUTH-B(%d)",cmd[1]); break;
|
|
|
|
case MIFARE_MAGICWUPC1: snprintf(exp,size,"MAGIC WUPC1"); break;
|
|
|
|
case MIFARE_MAGICWUPC2: snprintf(exp,size,"MAGIC WUPC2"); break;
|
|
|
|
case MIFARE_MAGICWIPEC: snprintf(exp,size,"MAGIC WIPEC"); break;
|
2015-05-06 12:55:29 +08:00
|
|
|
case MIFARE_ULC_AUTH_1: snprintf(exp,size,"AUTH "); break;
|
|
|
|
case MIFARE_ULC_AUTH_2: snprintf(exp,size,"AUTH_ANSW"); break;
|
2015-05-13 06:16:55 +08:00
|
|
|
case MIFARE_ULEV1_AUTH:
|
|
|
|
if ( cmdsize == 7 )
|
|
|
|
snprintf(exp,size,"PWD-AUTH KEY: 0x%02x%02x%02x%02x", cmd[1], cmd[2], cmd[3], cmd[4] );
|
|
|
|
else
|
|
|
|
snprintf(exp,size,"PWD-AUTH");
|
|
|
|
break;
|
2015-05-06 12:55:29 +08:00
|
|
|
case MIFARE_ULEV1_FASTREAD:{
|
2015-05-13 04:45:48 +08:00
|
|
|
if ( cmdsize >=3 && cmd[2] <= 0xE6)
|
2015-05-06 12:55:29 +08:00
|
|
|
snprintf(exp,size,"READ RANGE (%d-%d)",cmd[1],cmd[2]);
|
|
|
|
else
|
|
|
|
snprintf(exp,size,"?");
|
|
|
|
break;
|
|
|
|
}
|
2015-05-07 10:15:41 +08:00
|
|
|
case MIFARE_ULC_WRITE:{
|
2015-05-06 12:55:29 +08:00
|
|
|
if ( cmd[1] < 0x21 )
|
|
|
|
snprintf(exp,size,"WRITEBLOCK(%d)",cmd[1]);
|
|
|
|
else
|
|
|
|
snprintf(exp,size,"?");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MIFARE_ULEV1_READ_CNT:{
|
|
|
|
if ( cmd[1] < 5 )
|
|
|
|
snprintf(exp,size,"READ CNT(%d)",cmd[1]);
|
|
|
|
else
|
|
|
|
snprintf(exp,size,"?");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MIFARE_ULEV1_INCR_CNT:{
|
|
|
|
if ( cmd[1] < 5 )
|
|
|
|
snprintf(exp,size,"INCR(%d)",cmd[1]);
|
|
|
|
else
|
|
|
|
snprintf(exp,size,"?");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MIFARE_ULEV1_READSIG: snprintf(exp,size,"READ_SIG"); break;
|
|
|
|
case MIFARE_ULEV1_CHECKTEAR: snprintf(exp,size,"CHK_TEARING(%d)",cmd[1]); break;
|
|
|
|
case MIFARE_ULEV1_VCSL: snprintf(exp,size,"VCSL"); break;
|
2015-03-10 04:36:27 +08:00
|
|
|
default: snprintf(exp,size,"?"); break;
|
2015-01-05 04:22:54 +08:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void annotateIclass(char *exp, size_t size, uint8_t* cmd, uint8_t cmdsize)
|
|
|
|
{
|
|
|
|
switch(cmd[0])
|
|
|
|
{
|
2015-01-05 04:26:10 +08:00
|
|
|
case ICLASS_CMD_ACTALL: snprintf(exp,size,"ACTALL"); break;
|
2015-01-08 04:14:32 +08:00
|
|
|
case ICLASS_CMD_READ_OR_IDENTIFY:{
|
|
|
|
if(cmdsize > 1){
|
|
|
|
snprintf(exp,size,"READ(%d)",cmd[1]);
|
|
|
|
}else{
|
|
|
|
snprintf(exp,size,"IDENTIFY");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2015-01-05 04:26:10 +08:00
|
|
|
case ICLASS_CMD_SELECT: snprintf(exp,size,"SELECT"); break;
|
2015-01-16 06:00:39 +08:00
|
|
|
case ICLASS_CMD_PAGESEL: snprintf(exp,size,"PAGESEL(%d)", cmd[1]); break;
|
|
|
|
case ICLASS_CMD_READCHECK_KC:snprintf(exp,size,"READCHECK[Kc](%d)", cmd[1]); break;
|
|
|
|
case ICLASS_CMD_READCHECK_KD:snprintf(exp,size,"READCHECK[Kd](%d)", cmd[1]); break;
|
2015-01-05 04:26:10 +08:00
|
|
|
case ICLASS_CMD_CHECK: snprintf(exp,size,"CHECK"); break;
|
2015-01-16 06:00:39 +08:00
|
|
|
case ICLASS_CMD_DETECT: snprintf(exp,size,"DETECT"); break;
|
2015-01-05 04:26:10 +08:00
|
|
|
case ICLASS_CMD_HALT: snprintf(exp,size,"HALT"); break;
|
2015-01-16 06:00:39 +08:00
|
|
|
case ICLASS_CMD_UPDATE: snprintf(exp,size,"UPDATE(%d)",cmd[1]); break;
|
|
|
|
case ICLASS_CMD_ACT: snprintf(exp,size,"ACT"); break;
|
|
|
|
case ICLASS_CMD_READ4: snprintf(exp,size,"READ4(%d)",cmd[1]); break;
|
2015-01-05 04:26:10 +08:00
|
|
|
default: snprintf(exp,size,"?"); break;
|
2015-01-05 04:22:54 +08:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-01-08 04:14:32 +08:00
|
|
|
void annotateIso15693(char *exp, size_t size, uint8_t* cmd, uint8_t cmdsize)
|
|
|
|
{
|
|
|
|
|
|
|
|
if(cmd[0] == 0x26)
|
|
|
|
{
|
|
|
|
switch(cmd[1]){
|
|
|
|
case ISO15693_INVENTORY :snprintf(exp, size, "INVENTORY");break;
|
|
|
|
case ISO15693_STAYQUIET :snprintf(exp, size, "STAY_QUIET");break;
|
|
|
|
default: snprintf(exp,size,"?"); break;
|
2015-01-05 04:22:54 +08:00
|
|
|
|
2015-01-08 04:14:32 +08:00
|
|
|
}
|
|
|
|
}else if(cmd[0] == 0x02)
|
|
|
|
{
|
|
|
|
switch(cmd[1])
|
|
|
|
{
|
|
|
|
case ISO15693_READBLOCK :snprintf(exp, size, "READBLOCK");break;
|
|
|
|
case ISO15693_WRITEBLOCK :snprintf(exp, size, "WRITEBLOCK");break;
|
|
|
|
case ISO15693_LOCKBLOCK :snprintf(exp, size, "LOCKBLOCK");break;
|
|
|
|
case ISO15693_READ_MULTI_BLOCK :snprintf(exp, size, "READ_MULTI_BLOCK");break;
|
|
|
|
case ISO15693_SELECT :snprintf(exp, size, "SELECT");break;
|
|
|
|
case ISO15693_RESET_TO_READY :snprintf(exp, size, "RESET_TO_READY");break;
|
|
|
|
case ISO15693_WRITE_AFI :snprintf(exp, size, "WRITE_AFI");break;
|
|
|
|
case ISO15693_LOCK_AFI :snprintf(exp, size, "LOCK_AFI");break;
|
|
|
|
case ISO15693_WRITE_DSFID :snprintf(exp, size, "WRITE_DSFID");break;
|
|
|
|
case ISO15693_LOCK_DSFID :snprintf(exp, size, "LOCK_DSFID");break;
|
|
|
|
case ISO15693_GET_SYSTEM_INFO :snprintf(exp, size, "GET_SYSTEM_INFO");break;
|
|
|
|
case ISO15693_READ_MULTI_SECSTATUS :snprintf(exp, size, "READ_MULTI_SECSTATUS");break;
|
2015-01-17 05:41:19 +08:00
|
|
|
default: snprintf(exp,size,"?"); break;
|
2015-01-08 04:14:32 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-01-27 23:34:45 +08:00
|
|
|
|
2015-03-13 14:36:52 +08:00
|
|
|
|
|
|
|
void annotateTopaz(char *exp, size_t size, uint8_t* cmd, uint8_t cmdsize)
|
|
|
|
{
|
|
|
|
switch(cmd[0]) {
|
|
|
|
case TOPAZ_REQA :snprintf(exp, size, "REQA");break;
|
|
|
|
case TOPAZ_WUPA :snprintf(exp, size, "WUPA");break;
|
|
|
|
case TOPAZ_RID :snprintf(exp, size, "RID");break;
|
|
|
|
case TOPAZ_RALL :snprintf(exp, size, "RALL");break;
|
|
|
|
case TOPAZ_READ :snprintf(exp, size, "READ");break;
|
|
|
|
case TOPAZ_WRITE_E :snprintf(exp, size, "WRITE-E");break;
|
|
|
|
case TOPAZ_WRITE_NE :snprintf(exp, size, "WRITE-NE");break;
|
2015-03-21 04:06:51 +08:00
|
|
|
case TOPAZ_RSEG :snprintf(exp, size, "RSEG");break;
|
|
|
|
case TOPAZ_READ8 :snprintf(exp, size, "READ8");break;
|
|
|
|
case TOPAZ_WRITE_E8 :snprintf(exp, size, "WRITE-E8");break;
|
|
|
|
case TOPAZ_WRITE_NE8 :snprintf(exp, size, "WRITE-NE8");break;
|
2015-03-13 14:36:52 +08:00
|
|
|
default: snprintf(exp,size,"?"); break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-01-27 23:34:45 +08:00
|
|
|
/**
|
|
|
|
06 00 = INITIATE
|
|
|
|
0E xx = SELECT ID (xx = Chip-ID)
|
|
|
|
0B = Get UID
|
|
|
|
08 yy = Read Block (yy = block number)
|
|
|
|
09 yy dd dd dd dd = Write Block (yy = block number; dd dd dd dd = data to be written)
|
|
|
|
0C = Reset to Inventory
|
|
|
|
0F = Completion
|
|
|
|
0A 11 22 33 44 55 66 = Authenticate (11 22 33 44 55 66 = data to authenticate)
|
|
|
|
**/
|
|
|
|
|
2015-01-17 05:41:19 +08:00
|
|
|
void annotateIso14443b(char *exp, size_t size, uint8_t* cmd, uint8_t cmdsize)
|
|
|
|
{
|
|
|
|
switch(cmd[0]){
|
|
|
|
case ISO14443B_REQB : snprintf(exp,size,"REQB");break;
|
|
|
|
case ISO14443B_ATTRIB : snprintf(exp,size,"ATTRIB");break;
|
|
|
|
case ISO14443B_HALT : snprintf(exp,size,"HALT");break;
|
2015-01-27 23:34:45 +08:00
|
|
|
case ISO14443B_INITIATE : snprintf(exp,size,"INITIATE");break;
|
|
|
|
case ISO14443B_SELECT : snprintf(exp,size,"SELECT(%d)",cmd[1]);break;
|
|
|
|
case ISO14443B_GET_UID : snprintf(exp,size,"GET UID");break;
|
|
|
|
case ISO14443B_READ_BLK : snprintf(exp,size,"READ_BLK(%d)", cmd[1]);break;
|
|
|
|
case ISO14443B_WRITE_BLK : snprintf(exp,size,"WRITE_BLK(%d)",cmd[1]);break;
|
|
|
|
case ISO14443B_RESET : snprintf(exp,size,"RESET");break;
|
|
|
|
case ISO14443B_COMPLETION : snprintf(exp,size,"COMPLETION");break;
|
|
|
|
case ISO14443B_AUTHENTICATE : snprintf(exp,size,"AUTHENTICATE");break;
|
|
|
|
default : snprintf(exp,size ,"?");break;
|
2015-01-17 05:41:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-03-17 14:41:08 +08:00
|
|
|
* @brief iso14443A_CRC_check Checks CRC in command or response
|
|
|
|
* @param isResponse
|
|
|
|
* @param data
|
|
|
|
* @param len
|
|
|
|
* @return 0 : CRC-command, CRC not ok
|
|
|
|
* 1 : CRC-command, CRC ok
|
|
|
|
* 2 : Not crc-command
|
|
|
|
*/
|
|
|
|
|
|
|
|
uint8_t iso14443A_CRC_check(bool isResponse, uint8_t* data, uint8_t len)
|
|
|
|
{
|
|
|
|
uint8_t b1,b2;
|
|
|
|
|
|
|
|
if(len <= 2) return 2;
|
|
|
|
|
|
|
|
if(isResponse & (len < 6)) return 2;
|
|
|
|
|
|
|
|
ComputeCrc14443(CRC_14443_A, data, len-2, &b1, &b2);
|
|
|
|
if (b1 != data[len-2] || b2 != data[len-1]) {
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief iso14443B_CRC_check Checks CRC in command or response
|
2015-01-17 05:41:19 +08:00
|
|
|
* @param isResponse
|
|
|
|
* @param data
|
|
|
|
* @param len
|
|
|
|
* @return 0 : CRC-command, CRC not ok
|
|
|
|
* 1 : CRC-command, CRC ok
|
|
|
|
* 2 : Not crc-command
|
|
|
|
*/
|
|
|
|
|
|
|
|
uint8_t iso14443B_CRC_check(bool isResponse, uint8_t* data, uint8_t len)
|
|
|
|
{
|
|
|
|
uint8_t b1,b2;
|
|
|
|
|
|
|
|
if(len <= 2) return 2;
|
|
|
|
|
|
|
|
ComputeCrc14443(CRC_14443_B, data, len-2, &b1, &b2);
|
|
|
|
if(b1 != data[len-2] || b2 != data[len-1]) {
|
2015-03-17 14:41:08 +08:00
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
return 1;
|
2015-01-17 05:41:19 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-16 06:00:39 +08:00
|
|
|
/**
|
|
|
|
* @brief iclass_CRC_Ok Checks CRC in command or response
|
|
|
|
* @param isResponse
|
|
|
|
* @param data
|
|
|
|
* @param len
|
|
|
|
* @return 0 : CRC-command, CRC not ok
|
|
|
|
* 1 : CRC-command, CRC ok
|
|
|
|
* 2 : Not crc-command
|
|
|
|
*/
|
2015-01-17 05:41:19 +08:00
|
|
|
uint8_t iclass_CRC_check(bool isResponse, uint8_t* data, uint8_t len)
|
2015-01-16 06:00:39 +08:00
|
|
|
{
|
|
|
|
if(len < 4) return 2;//CRC commands (and responses) are all at least 4 bytes
|
|
|
|
|
|
|
|
uint8_t b1, b2;
|
|
|
|
|
|
|
|
if(!isResponse)//Commands to tag
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
These commands should have CRC. Total length leftmost
|
|
|
|
4 READ
|
|
|
|
4 READ4
|
|
|
|
12 UPDATE - unsecured, ends with CRC16
|
|
|
|
14 UPDATE - secured, ends with signature instead
|
|
|
|
4 PAGESEL
|
|
|
|
**/
|
|
|
|
if(len == 4 || len == 12)//Covers three of them
|
|
|
|
{
|
|
|
|
//Don't include the command byte
|
|
|
|
ComputeCrc14443(CRC_ICLASS, (data+1), len-3, &b1, &b2);
|
|
|
|
return b1 == data[len -2] && b2 == data[len-1];
|
|
|
|
}
|
|
|
|
return 2;
|
|
|
|
}else{
|
|
|
|
/**
|
|
|
|
These tag responses should have CRC. Total length leftmost
|
|
|
|
|
|
|
|
10 READ data[8] crc[2]
|
|
|
|
34 READ4 data[32]crc[2]
|
|
|
|
10 UPDATE data[8] crc[2]
|
|
|
|
10 SELECT csn[8] crc[2]
|
|
|
|
10 IDENTIFY asnb[8] crc[2]
|
|
|
|
10 PAGESEL block1[8] crc[2]
|
|
|
|
10 DETECT csn[8] crc[2]
|
|
|
|
|
|
|
|
These should not
|
|
|
|
|
|
|
|
4 CHECK chip_response[4]
|
|
|
|
8 READCHECK data[8]
|
|
|
|
1 ACTALL sof[1]
|
|
|
|
1 ACT sof[1]
|
|
|
|
|
|
|
|
In conclusion, without looking at the command; any response
|
|
|
|
of length 10 or 34 should have CRC
|
|
|
|
**/
|
|
|
|
if(len != 10 && len != 34) return true;
|
|
|
|
|
|
|
|
ComputeCrc14443(CRC_ICLASS, data, len-2, &b1, &b2);
|
|
|
|
return b1 == data[len -2] && b2 == data[len-1];
|
|
|
|
}
|
|
|
|
}
|
2015-01-05 04:22:54 +08:00
|
|
|
|
2015-03-13 14:36:52 +08:00
|
|
|
|
2015-03-15 23:40:34 +08:00
|
|
|
bool is_last_record(uint16_t tracepos, uint8_t *trace, uint16_t traceLen)
|
2015-01-05 04:22:54 +08:00
|
|
|
{
|
2015-03-15 23:40:34 +08:00
|
|
|
return(tracepos + sizeof(uint32_t) + sizeof(uint16_t) + sizeof(uint16_t) >= traceLen);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool next_record_is_response(uint16_t tracepos, uint8_t *trace)
|
|
|
|
{
|
|
|
|
uint16_t next_records_datalen = *((uint16_t *)(trace + tracepos + sizeof(uint32_t) + sizeof(uint16_t)));
|
|
|
|
|
|
|
|
return(next_records_datalen & 0x8000);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-17 14:41:08 +08:00
|
|
|
bool merge_topaz_reader_frames(uint32_t timestamp, uint32_t *duration, uint16_t *tracepos, uint16_t traceLen, uint8_t *trace, uint8_t *frame, uint8_t *topaz_reader_command, uint16_t *data_len)
|
2015-03-15 23:40:34 +08:00
|
|
|
{
|
|
|
|
|
2015-03-21 04:06:51 +08:00
|
|
|
#define MAX_TOPAZ_READER_CMD_LEN 16
|
2015-03-15 23:40:34 +08:00
|
|
|
|
|
|
|
uint32_t last_timestamp = timestamp + *duration;
|
|
|
|
|
2015-03-17 14:41:08 +08:00
|
|
|
if ((*data_len != 1) || (frame[0] == TOPAZ_WUPA) || (frame[0] == TOPAZ_REQA)) return false;
|
2015-01-05 04:22:54 +08:00
|
|
|
|
2015-03-17 14:41:08 +08:00
|
|
|
memcpy(topaz_reader_command, frame, *data_len);
|
2015-03-15 23:40:34 +08:00
|
|
|
|
|
|
|
while (!is_last_record(*tracepos, trace, traceLen) && !next_record_is_response(*tracepos, trace)) {
|
|
|
|
uint32_t next_timestamp = *((uint32_t *)(trace + *tracepos));
|
|
|
|
*tracepos += sizeof(uint32_t);
|
2015-03-17 14:41:08 +08:00
|
|
|
uint16_t next_duration = *((uint16_t *)(trace + *tracepos));
|
2015-03-15 23:40:34 +08:00
|
|
|
*tracepos += sizeof(uint16_t);
|
|
|
|
uint16_t next_data_len = *((uint16_t *)(trace + *tracepos)) & 0x7FFF;
|
|
|
|
*tracepos += sizeof(uint16_t);
|
|
|
|
uint8_t *next_frame = (trace + *tracepos);
|
|
|
|
*tracepos += next_data_len;
|
2015-03-17 14:41:08 +08:00
|
|
|
if ((next_data_len == 1) && (*data_len + next_data_len <= MAX_TOPAZ_READER_CMD_LEN)) {
|
2015-03-15 23:40:34 +08:00
|
|
|
memcpy(topaz_reader_command + *data_len, next_frame, next_data_len);
|
|
|
|
*data_len += next_data_len;
|
2015-03-17 14:41:08 +08:00
|
|
|
last_timestamp = next_timestamp + next_duration;
|
|
|
|
} else {
|
|
|
|
// rewind and exit
|
|
|
|
*tracepos = *tracepos - next_data_len - sizeof(uint16_t) - sizeof(uint16_t) - sizeof(uint32_t);
|
|
|
|
break;
|
|
|
|
}
|
2015-03-15 23:40:34 +08:00
|
|
|
uint16_t next_parity_len = (next_data_len-1)/8 + 1;
|
|
|
|
*tracepos += next_parity_len;
|
|
|
|
}
|
|
|
|
|
|
|
|
*duration = last_timestamp - timestamp;
|
2015-03-17 14:41:08 +08:00
|
|
|
|
|
|
|
return true;
|
2015-03-13 14:36:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-19 00:12:09 +08:00
|
|
|
uint16_t printTraceLine(uint16_t tracepos, uint16_t traceLen, uint8_t *trace, uint8_t protocol, bool showWaitCycles, bool markCRCBytes)
|
2015-01-05 04:22:54 +08:00
|
|
|
{
|
|
|
|
bool isResponse;
|
2015-03-15 23:40:34 +08:00
|
|
|
uint16_t data_len, parity_len;
|
|
|
|
uint32_t duration;
|
2015-03-13 14:36:52 +08:00
|
|
|
uint8_t topaz_reader_command[9];
|
2015-01-05 04:22:54 +08:00
|
|
|
uint32_t timestamp, first_timestamp, EndOfTransmissionTimestamp;
|
|
|
|
char explanation[30] = {0};
|
|
|
|
|
2015-01-27 15:34:48 +08:00
|
|
|
if (tracepos + sizeof(uint32_t) + sizeof(uint16_t) + sizeof(uint16_t) > traceLen) return traceLen;
|
|
|
|
|
2015-01-05 04:22:54 +08:00
|
|
|
first_timestamp = *((uint32_t *)(trace));
|
|
|
|
timestamp = *((uint32_t *)(trace + tracepos));
|
|
|
|
|
|
|
|
tracepos += 4;
|
|
|
|
duration = *((uint16_t *)(trace + tracepos));
|
|
|
|
tracepos += 2;
|
|
|
|
data_len = *((uint16_t *)(trace + tracepos));
|
|
|
|
tracepos += 2;
|
|
|
|
|
|
|
|
if (data_len & 0x8000) {
|
|
|
|
data_len &= 0x7fff;
|
|
|
|
isResponse = true;
|
|
|
|
} else {
|
|
|
|
isResponse = false;
|
|
|
|
}
|
|
|
|
parity_len = (data_len-1)/8 + 1;
|
|
|
|
|
2015-01-27 15:34:48 +08:00
|
|
|
if (tracepos + data_len + parity_len > traceLen) {
|
|
|
|
return traceLen;
|
2015-01-05 04:22:54 +08:00
|
|
|
}
|
|
|
|
uint8_t *frame = trace + tracepos;
|
|
|
|
tracepos += data_len;
|
|
|
|
uint8_t *parityBytes = trace + tracepos;
|
|
|
|
tracepos += parity_len;
|
|
|
|
|
2015-03-13 14:36:52 +08:00
|
|
|
if (protocol == TOPAZ && !isResponse) {
|
2015-03-17 14:41:08 +08:00
|
|
|
// topaz reader commands come in 1 or 9 separate frames with 7 or 8 Bits each.
|
2015-03-13 14:36:52 +08:00
|
|
|
// merge them:
|
2015-03-17 14:41:08 +08:00
|
|
|
if (merge_topaz_reader_frames(timestamp, &duration, &tracepos, traceLen, trace, frame, topaz_reader_command, &data_len)) {
|
|
|
|
frame = topaz_reader_command;
|
|
|
|
}
|
2015-03-13 14:36:52 +08:00
|
|
|
}
|
|
|
|
|
2015-03-03 04:05:44 +08:00
|
|
|
//Check the CRC status
|
|
|
|
uint8_t crcStatus = 2;
|
|
|
|
|
|
|
|
if (data_len > 2) {
|
2015-03-13 14:36:52 +08:00
|
|
|
switch (protocol) {
|
|
|
|
case ICLASS:
|
|
|
|
crcStatus = iclass_CRC_check(isResponse, frame, data_len);
|
|
|
|
break;
|
|
|
|
case ISO_14443B:
|
2015-03-17 14:41:08 +08:00
|
|
|
case TOPAZ:
|
2015-03-15 23:40:34 +08:00
|
|
|
crcStatus = iso14443B_CRC_check(isResponse, frame, data_len);
|
2015-03-13 14:36:52 +08:00
|
|
|
break;
|
|
|
|
case ISO_14443A:
|
2015-03-17 14:41:08 +08:00
|
|
|
crcStatus = iso14443A_CRC_check(isResponse, frame, data_len);
|
2015-03-13 14:36:52 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2015-03-03 04:05:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
//0 CRC-command, CRC not ok
|
|
|
|
//1 CRC-command, CRC ok
|
|
|
|
//2 Not crc-command
|
2015-01-22 06:53:40 +08:00
|
|
|
|
2015-01-05 04:22:54 +08:00
|
|
|
//--- Draw the data column
|
2015-01-22 06:53:40 +08:00
|
|
|
//char line[16][110];
|
2015-01-05 04:22:54 +08:00
|
|
|
char line[16][110];
|
2015-01-22 06:53:40 +08:00
|
|
|
|
|
|
|
for (int j = 0; j < data_len && j/16 < 16; j++) {
|
|
|
|
|
2015-01-05 04:22:54 +08:00
|
|
|
int oddparity = 0x01;
|
|
|
|
int k;
|
|
|
|
|
|
|
|
for (k=0 ; k<8 ; k++) {
|
|
|
|
oddparity ^= (((frame[j] & 0xFF) >> k) & 0x01);
|
|
|
|
}
|
|
|
|
uint8_t parityBits = parityBytes[j>>3];
|
2015-07-02 14:49:34 +08:00
|
|
|
if (protocol != ISO_14443B && (isResponse || protocol == ISO_14443A) && (oddparity != ((parityBits >> (7-(j&0x0007))) & 0x01))) {
|
2015-01-22 06:53:40 +08:00
|
|
|
snprintf(line[j/16]+(( j % 16) * 4),110, "%02x! ", frame[j]);
|
2015-01-05 04:22:54 +08:00
|
|
|
} else {
|
2015-03-17 14:41:08 +08:00
|
|
|
snprintf(line[j/16]+(( j % 16) * 4), 110, " %02x ", frame[j]);
|
2015-01-22 06:53:40 +08:00
|
|
|
}
|
2015-03-03 04:05:44 +08:00
|
|
|
|
|
|
|
}
|
2015-03-19 00:12:09 +08:00
|
|
|
|
|
|
|
if (markCRCBytes) {
|
|
|
|
if(crcStatus == 0 || crcStatus == 1)
|
|
|
|
{//CRC-command
|
|
|
|
char *pos1 = line[(data_len-2)/16]+(((data_len-2) % 16) * 4);
|
|
|
|
(*pos1) = '[';
|
|
|
|
char *pos2 = line[(data_len)/16]+(((data_len) % 16) * 4);
|
|
|
|
sprintf(pos2, "%c", ']');
|
|
|
|
}
|
2015-01-22 06:53:40 +08:00
|
|
|
}
|
2015-03-19 00:12:09 +08:00
|
|
|
|
2015-01-22 06:53:40 +08:00
|
|
|
if(data_len == 0)
|
|
|
|
{
|
|
|
|
if(data_len == 0){
|
|
|
|
sprintf(line[0],"<empty trace - possible error>");
|
2015-01-05 04:22:54 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
//--- Draw the CRC column
|
|
|
|
|
2015-01-16 06:00:39 +08:00
|
|
|
char *crc = (crcStatus == 0 ? "!crc" : (crcStatus == 1 ? " ok " : " "));
|
2015-01-05 04:22:54 +08:00
|
|
|
|
|
|
|
EndOfTransmissionTimestamp = timestamp + duration;
|
|
|
|
|
|
|
|
if(!isResponse)
|
|
|
|
{
|
2015-03-13 14:36:52 +08:00
|
|
|
switch(protocol) {
|
|
|
|
case ICLASS: annotateIclass(explanation,sizeof(explanation),frame,data_len); break;
|
|
|
|
case ISO_14443A: annotateIso14443a(explanation,sizeof(explanation),frame,data_len); break;
|
|
|
|
case ISO_14443B: annotateIso14443b(explanation,sizeof(explanation),frame,data_len); break;
|
|
|
|
case TOPAZ: annotateTopaz(explanation,sizeof(explanation),frame,data_len); break;
|
|
|
|
default: break;
|
|
|
|
}
|
2015-01-05 04:22:54 +08:00
|
|
|
}
|
|
|
|
|
2015-01-22 06:53:40 +08:00
|
|
|
int num_lines = MIN((data_len - 1)/16 + 1, 16);
|
|
|
|
for (int j = 0; j < num_lines ; j++) {
|
2015-01-05 04:22:54 +08:00
|
|
|
if (j == 0) {
|
2015-03-21 04:06:51 +08:00
|
|
|
PrintAndLog(" %10d | %10d | %s |%-64s | %s| %s",
|
2015-01-05 04:22:54 +08:00
|
|
|
(timestamp - first_timestamp),
|
|
|
|
(EndOfTransmissionTimestamp - first_timestamp),
|
|
|
|
(isResponse ? "Tag" : "Rdr"),
|
|
|
|
line[j],
|
|
|
|
(j == num_lines-1) ? crc : " ",
|
|
|
|
(j == num_lines-1) ? explanation : "");
|
|
|
|
} else {
|
2015-03-21 04:06:51 +08:00
|
|
|
PrintAndLog(" | | |%-64s | %s| %s",
|
2015-01-05 04:22:54 +08:00
|
|
|
line[j],
|
2015-03-13 14:36:52 +08:00
|
|
|
(j == num_lines-1) ? crc : " ",
|
2015-01-05 04:22:54 +08:00
|
|
|
(j == num_lines-1) ? explanation : "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-15 23:40:34 +08:00
|
|
|
if (is_last_record(tracepos, trace, traceLen)) return traceLen;
|
2015-01-27 15:34:48 +08:00
|
|
|
|
2015-03-15 23:40:34 +08:00
|
|
|
if (showWaitCycles && !isResponse && next_record_is_response(tracepos, trace)) {
|
2015-01-05 04:22:54 +08:00
|
|
|
uint32_t next_timestamp = *((uint32_t *)(trace + tracepos));
|
2015-03-15 23:40:34 +08:00
|
|
|
PrintAndLog(" %9d | %9d | %s | fdt (Frame Delay Time): %d",
|
|
|
|
(EndOfTransmissionTimestamp - first_timestamp),
|
|
|
|
(next_timestamp - first_timestamp),
|
|
|
|
" ",
|
|
|
|
(next_timestamp - EndOfTransmissionTimestamp));
|
2015-01-05 04:22:54 +08:00
|
|
|
}
|
2015-01-27 15:34:48 +08:00
|
|
|
|
2015-01-05 04:22:54 +08:00
|
|
|
return tracepos;
|
|
|
|
}
|
|
|
|
|
2015-01-27 15:34:48 +08:00
|
|
|
|
2015-01-05 04:22:54 +08:00
|
|
|
int CmdHFList(const char *Cmd)
|
|
|
|
{
|
|
|
|
bool showWaitCycles = false;
|
2015-03-19 00:12:09 +08:00
|
|
|
bool markCRCBytes = false;
|
2015-01-05 04:22:54 +08:00
|
|
|
char type[40] = {0};
|
|
|
|
int tlen = param_getstr(Cmd,0,type);
|
2015-03-19 00:12:09 +08:00
|
|
|
char param1 = param_getchar(Cmd, 1);
|
|
|
|
char param2 = param_getchar(Cmd, 2);
|
2015-01-05 04:22:54 +08:00
|
|
|
bool errors = false;
|
2015-01-17 05:48:30 +08:00
|
|
|
uint8_t protocol = 0;
|
2015-01-05 04:22:54 +08:00
|
|
|
//Validate params
|
2015-03-19 00:12:09 +08:00
|
|
|
|
|
|
|
if(tlen == 0) {
|
2015-01-05 04:22:54 +08:00
|
|
|
errors = true;
|
|
|
|
}
|
2015-03-19 00:12:09 +08:00
|
|
|
|
|
|
|
if(param1 == 'h'
|
|
|
|
|| (param1 != 0 && param1 != 'f' && param1 != 'c')
|
|
|
|
|| (param2 != 0 && param2 != 'f' && param2 != 'c')) {
|
2015-01-05 04:22:54 +08:00
|
|
|
errors = true;
|
|
|
|
}
|
2015-03-19 00:12:09 +08:00
|
|
|
|
|
|
|
if(!errors) {
|
2015-03-13 14:36:52 +08:00
|
|
|
if(strcmp(type, "iclass") == 0) {
|
2015-01-17 05:48:30 +08:00
|
|
|
protocol = ICLASS;
|
2015-03-13 14:36:52 +08:00
|
|
|
} else if(strcmp(type, "14a") == 0) {
|
2015-01-17 05:48:30 +08:00
|
|
|
protocol = ISO_14443A;
|
2015-03-13 14:36:52 +08:00
|
|
|
} else if(strcmp(type, "14b") == 0) {
|
2015-01-17 05:48:30 +08:00
|
|
|
protocol = ISO_14443B;
|
2015-03-17 14:41:08 +08:00
|
|
|
} else if(strcmp(type,"topaz")== 0) {
|
2015-03-13 14:36:52 +08:00
|
|
|
protocol = TOPAZ;
|
|
|
|
} else if(strcmp(type,"raw")== 0) {
|
2015-01-17 05:48:30 +08:00
|
|
|
protocol = -1;//No crc, no annotations
|
2015-03-13 14:36:52 +08:00
|
|
|
} else {
|
2015-01-17 05:48:30 +08:00
|
|
|
errors = true;
|
|
|
|
}
|
|
|
|
}
|
2015-01-05 04:22:54 +08:00
|
|
|
|
|
|
|
if (errors) {
|
|
|
|
PrintAndLog("List protocol data in trace buffer.");
|
2015-03-19 00:12:09 +08:00
|
|
|
PrintAndLog("Usage: hf list <protocol> [f][c]");
|
2015-01-30 03:01:30 +08:00
|
|
|
PrintAndLog(" f - show frame delay times as well");
|
2015-03-19 00:12:09 +08:00
|
|
|
PrintAndLog(" c - mark CRC bytes");
|
2015-01-30 03:01:30 +08:00
|
|
|
PrintAndLog("Supported <protocol> values:");
|
|
|
|
PrintAndLog(" raw - just show raw data without annotations");
|
2015-01-05 04:26:10 +08:00
|
|
|
PrintAndLog(" 14a - interpret data as iso14443a communications");
|
2015-01-17 05:41:19 +08:00
|
|
|
PrintAndLog(" 14b - interpret data as iso14443b communications");
|
2015-01-05 04:22:54 +08:00
|
|
|
PrintAndLog(" iclass - interpret data as iclass communications");
|
2015-03-13 14:36:52 +08:00
|
|
|
PrintAndLog(" topaz - interpret data as topaz communications");
|
2015-01-05 04:22:54 +08:00
|
|
|
PrintAndLog("");
|
|
|
|
PrintAndLog("example: hf list 14a f");
|
|
|
|
PrintAndLog("example: hf list iclass");
|
|
|
|
return 0;
|
|
|
|
}
|
2015-01-17 05:48:30 +08:00
|
|
|
|
2015-01-05 04:22:54 +08:00
|
|
|
|
2015-03-19 00:12:09 +08:00
|
|
|
if (param1 == 'f' || param2 == 'f') {
|
2015-01-05 04:22:54 +08:00
|
|
|
showWaitCycles = true;
|
|
|
|
}
|
|
|
|
|
2015-03-19 00:12:09 +08:00
|
|
|
if (param1 == 'c' || param2 == 'c') {
|
|
|
|
markCRCBytes = true;
|
|
|
|
}
|
2015-01-05 04:22:54 +08:00
|
|
|
|
2015-01-27 15:34:48 +08:00
|
|
|
uint8_t *trace;
|
2015-01-05 04:22:54 +08:00
|
|
|
uint16_t tracepos = 0;
|
2015-01-27 15:34:48 +08:00
|
|
|
trace = malloc(USB_CMD_DATA_SIZE);
|
|
|
|
|
|
|
|
// Query for the size of the trace
|
|
|
|
UsbCommand response;
|
|
|
|
GetFromBigBuf(trace, USB_CMD_DATA_SIZE, 0);
|
|
|
|
WaitForResponse(CMD_ACK, &response);
|
|
|
|
uint16_t traceLen = response.arg[2];
|
|
|
|
if (traceLen > USB_CMD_DATA_SIZE) {
|
|
|
|
uint8_t *p = realloc(trace, traceLen);
|
|
|
|
if (p == NULL) {
|
|
|
|
PrintAndLog("Cannot allocate memory for trace");
|
|
|
|
free(trace);
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
trace = p;
|
|
|
|
GetFromBigBuf(trace, traceLen, 0);
|
|
|
|
WaitForResponse(CMD_ACK, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
PrintAndLog("Recorded Activity (TraceLen = %d bytes)", traceLen);
|
2015-01-05 04:22:54 +08:00
|
|
|
PrintAndLog("");
|
|
|
|
PrintAndLog("Start = Start of Start Bit, End = End of last modulation. Src = Source of Transfer");
|
|
|
|
PrintAndLog("iso14443a - All times are in carrier periods (1/13.56Mhz)");
|
|
|
|
PrintAndLog("iClass - Timings are not as accurate");
|
|
|
|
PrintAndLog("");
|
2015-03-24 14:17:00 +08:00
|
|
|
PrintAndLog(" Start | End | Src | Data (! denotes parity error) | CRC | Annotation |");
|
|
|
|
PrintAndLog("------------|------------|-----|-----------------------------------------------------------------|-----|--------------------|");
|
2015-01-05 04:22:54 +08:00
|
|
|
|
2015-01-27 15:34:48 +08:00
|
|
|
while(tracepos < traceLen)
|
2015-01-05 04:22:54 +08:00
|
|
|
{
|
2015-03-19 00:12:09 +08:00
|
|
|
tracepos = printTraceLine(tracepos, traceLen, trace, protocol, showWaitCycles, markCRCBytes);
|
2015-01-05 04:22:54 +08:00
|
|
|
}
|
2015-01-27 15:34:48 +08:00
|
|
|
|
|
|
|
free(trace);
|
2015-01-05 04:22:54 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-05-12 12:19:44 +08:00
|
|
|
int CmdHFSearch(const char *Cmd){
|
|
|
|
int ans = 0;
|
2015-05-13 04:45:48 +08:00
|
|
|
PrintAndLog("");
|
|
|
|
ans = CmdHF14AReader("s");
|
|
|
|
if (ans > 0) {
|
|
|
|
PrintAndLog("\nValid ISO14443A Tag Found - Quiting Search\n");
|
|
|
|
return ans;
|
2015-06-24 05:41:24 +08:00
|
|
|
}
|
2015-07-21 01:41:40 +08:00
|
|
|
ans = HFiClassReader("", false, false);
|
2015-06-24 05:41:24 +08:00
|
|
|
if (ans) {
|
2015-07-21 01:41:40 +08:00
|
|
|
PrintAndLog("\nValid iClass Tag (or PicoPass Tag) Found - Quiting Search\n");
|
2015-06-24 05:41:24 +08:00
|
|
|
return ans;
|
|
|
|
}
|
2015-07-21 01:41:40 +08:00
|
|
|
ans = HF14BInfo(false);
|
2015-05-13 04:45:48 +08:00
|
|
|
if (ans) {
|
2015-07-21 01:41:40 +08:00
|
|
|
PrintAndLog("\nValid ISO14443B Tag Found - Quiting Search\n");
|
2015-05-13 04:45:48 +08:00
|
|
|
return ans;
|
|
|
|
}
|
|
|
|
ans = HF15Reader("", false);
|
|
|
|
if (ans) {
|
|
|
|
PrintAndLog("\nValid ISO15693 Tag Found - Quiting Search\n");
|
|
|
|
return ans;
|
|
|
|
}
|
2015-06-24 05:41:24 +08:00
|
|
|
PrintAndLog("\nno known/supported 13.56 MHz tags found\n");
|
2015-05-12 12:19:44 +08:00
|
|
|
return 0;
|
|
|
|
}
|
Client cleanup and restructuring. Stage 1...
Next Step is refactoring some of the giant functions which are
just copy/paste of some other ones with just a few line changes,
removing unnecessary 'goto' etc.
The MS Windows version is broken with this commit but will be fixed
soon. Everything can't be done all at once :P
The commands are now hierarchical, for example:
"hf 14a read" vs. "hf 14b read".
You can also request help:
"hf help", "data help", "hf 15 help" etc.
Indents are now space-based, not tab-based anymore. Hopefully
no one will be trolling about it, considering the suicide-prone work
being done here ;)
client/cmdhw.c, client/proxusb.c, client/cmdhw.h, client/proxusb.h,
client/cmdmain.c, client/cmdlfhid.c, client/cmdmain.h, client/cmdlfhid.h,
client/data.c, client/data.h, client/cmdhf.c, client/cmdlf.c,
client/cmdhf.h, client/cmdhf15.c, client/cmdhf14b.c, client/cmdlf.h,
client/cmdhf15.h, client/cmdhf14b.h, client/cmddata.c, client/cmddata.h,
client/ui.c, client/cmdparser.c, client/cmdlfti.c, client/ui.h,
client/cmdlfem4x.c, client/cmdparser.h, client/cmdlfti.h, client/cmdlfem4x.h,
client/graph.c, client/graph.h, client/cmdhf14a.c, client/cmdhf14a.h,
client/cmdhflegic.c, client/cmdhflegic.c: New files.
client/cli.c, client/flasher.c, client/snooper.c, client/proxmark3.c,
client/proxmark3.h, client/Makefile: Update accordingly.
client/flash.h, client/flash.c, client/proxgui.cpp: Cosmetic changes.
client/translate.h, client/command.c, client/gui.c,
client/usb.c, client/prox.h: Remove.
include/usb_cmd.h (CMD_ACQUIRE_RAW_ADC_SAMPLES_ISO_14443_SIM): Remove dead cmd.
common/crc16.h: New file.
common/crc16.c: Modify accordingly.
common/iso14443crc.h: New file.
common/iso14443_crc.c: Rename to
common/iso14443crc.c: and modify accordingly.
armsrc/lfops.c, armsrc/iso14443.c,
armsrc/iso14443a.c: include .h files from
the common directory instead of including the c files.
common/Makefile.common, armsrc/Makefile: Modify accordingly.
2010-02-04 09:27:07 +08:00
|
|
|
|
2015-10-23 21:29:12 +08:00
|
|
|
int CmdHFSnoop(const char *Cmd)
|
|
|
|
{
|
|
|
|
char * pEnd;
|
|
|
|
UsbCommand c = {CMD_HF_SNIFFER, {strtol(Cmd, &pEnd,0),strtol(pEnd, &pEnd,0),0}};
|
|
|
|
SendCommand(&c);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
Client cleanup and restructuring. Stage 1...
Next Step is refactoring some of the giant functions which are
just copy/paste of some other ones with just a few line changes,
removing unnecessary 'goto' etc.
The MS Windows version is broken with this commit but will be fixed
soon. Everything can't be done all at once :P
The commands are now hierarchical, for example:
"hf 14a read" vs. "hf 14b read".
You can also request help:
"hf help", "data help", "hf 15 help" etc.
Indents are now space-based, not tab-based anymore. Hopefully
no one will be trolling about it, considering the suicide-prone work
being done here ;)
client/cmdhw.c, client/proxusb.c, client/cmdhw.h, client/proxusb.h,
client/cmdmain.c, client/cmdlfhid.c, client/cmdmain.h, client/cmdlfhid.h,
client/data.c, client/data.h, client/cmdhf.c, client/cmdlf.c,
client/cmdhf.h, client/cmdhf15.c, client/cmdhf14b.c, client/cmdlf.h,
client/cmdhf15.h, client/cmdhf14b.h, client/cmddata.c, client/cmddata.h,
client/ui.c, client/cmdparser.c, client/cmdlfti.c, client/ui.h,
client/cmdlfem4x.c, client/cmdparser.h, client/cmdlfti.h, client/cmdlfem4x.h,
client/graph.c, client/graph.h, client/cmdhf14a.c, client/cmdhf14a.h,
client/cmdhflegic.c, client/cmdhflegic.c: New files.
client/cli.c, client/flasher.c, client/snooper.c, client/proxmark3.c,
client/proxmark3.h, client/Makefile: Update accordingly.
client/flash.h, client/flash.c, client/proxgui.cpp: Cosmetic changes.
client/translate.h, client/command.c, client/gui.c,
client/usb.c, client/prox.h: Remove.
include/usb_cmd.h (CMD_ACQUIRE_RAW_ADC_SAMPLES_ISO_14443_SIM): Remove dead cmd.
common/crc16.h: New file.
common/crc16.c: Modify accordingly.
common/iso14443crc.h: New file.
common/iso14443_crc.c: Rename to
common/iso14443crc.c: and modify accordingly.
armsrc/lfops.c, armsrc/iso14443.c,
armsrc/iso14443a.c: include .h files from
the common directory instead of including the c files.
common/Makefile.common, armsrc/Makefile: Modify accordingly.
2010-02-04 09:27:07 +08:00
|
|
|
static command_t CommandTable[] =
|
|
|
|
{
|
2015-03-19 00:12:09 +08:00
|
|
|
{"help", CmdHelp, 1, "This help"},
|
|
|
|
{"14a", CmdHF14A, 1, "{ ISO14443A RFIDs... }"},
|
|
|
|
{"14b", CmdHF14B, 1, "{ ISO14443B RFIDs... }"},
|
|
|
|
{"15", CmdHF15, 1, "{ ISO15693 RFIDs... }"},
|
|
|
|
{"epa", CmdHFEPA, 1, "{ German Identification Card... }"},
|
|
|
|
{"legic", CmdHFLegic, 0, "{ LEGIC RFIDs... }"},
|
|
|
|
{"iclass", CmdHFiClass, 1, "{ ICLASS RFIDs... }"},
|
|
|
|
{"mf", CmdHFMF, 1, "{ MIFARE RFIDs... }"},
|
|
|
|
{"mfu", CmdHFMFUltra, 1, "{ MIFARE Ultralight RFIDs... }"},
|
|
|
|
{"topaz", CmdHFTopaz, 1, "{ TOPAZ (NFC Type 1) RFIDs... }"},
|
|
|
|
{"tune", CmdHFTune, 0, "Continuously measure HF antenna tuning"},
|
|
|
|
{"list", CmdHFList, 1, "List protocol data in trace buffer"},
|
2015-09-28 14:26:00 +08:00
|
|
|
{"search", CmdHFSearch, 1, "Search for known HF tags [preliminary]"},
|
2015-11-04 04:06:59 +08:00
|
|
|
{"snoop", CmdHFSnoop, 0, "<samples to skip (10000)> <triggers to skip (1)> Generic HF Snoop"},
|
2015-03-19 00:12:09 +08:00
|
|
|
{NULL, NULL, 0, NULL}
|
Client cleanup and restructuring. Stage 1...
Next Step is refactoring some of the giant functions which are
just copy/paste of some other ones with just a few line changes,
removing unnecessary 'goto' etc.
The MS Windows version is broken with this commit but will be fixed
soon. Everything can't be done all at once :P
The commands are now hierarchical, for example:
"hf 14a read" vs. "hf 14b read".
You can also request help:
"hf help", "data help", "hf 15 help" etc.
Indents are now space-based, not tab-based anymore. Hopefully
no one will be trolling about it, considering the suicide-prone work
being done here ;)
client/cmdhw.c, client/proxusb.c, client/cmdhw.h, client/proxusb.h,
client/cmdmain.c, client/cmdlfhid.c, client/cmdmain.h, client/cmdlfhid.h,
client/data.c, client/data.h, client/cmdhf.c, client/cmdlf.c,
client/cmdhf.h, client/cmdhf15.c, client/cmdhf14b.c, client/cmdlf.h,
client/cmdhf15.h, client/cmdhf14b.h, client/cmddata.c, client/cmddata.h,
client/ui.c, client/cmdparser.c, client/cmdlfti.c, client/ui.h,
client/cmdlfem4x.c, client/cmdparser.h, client/cmdlfti.h, client/cmdlfem4x.h,
client/graph.c, client/graph.h, client/cmdhf14a.c, client/cmdhf14a.h,
client/cmdhflegic.c, client/cmdhflegic.c: New files.
client/cli.c, client/flasher.c, client/snooper.c, client/proxmark3.c,
client/proxmark3.h, client/Makefile: Update accordingly.
client/flash.h, client/flash.c, client/proxgui.cpp: Cosmetic changes.
client/translate.h, client/command.c, client/gui.c,
client/usb.c, client/prox.h: Remove.
include/usb_cmd.h (CMD_ACQUIRE_RAW_ADC_SAMPLES_ISO_14443_SIM): Remove dead cmd.
common/crc16.h: New file.
common/crc16.c: Modify accordingly.
common/iso14443crc.h: New file.
common/iso14443_crc.c: Rename to
common/iso14443crc.c: and modify accordingly.
armsrc/lfops.c, armsrc/iso14443.c,
armsrc/iso14443a.c: include .h files from
the common directory instead of including the c files.
common/Makefile.common, armsrc/Makefile: Modify accordingly.
2010-02-04 09:27:07 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
int CmdHF(const char *Cmd)
|
|
|
|
{
|
|
|
|
CmdsParse(CommandTable, Cmd);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CmdHelp(const char *Cmd)
|
|
|
|
{
|
|
|
|
CmdsHelp(CommandTable);
|
|
|
|
return 0;
|
|
|
|
}
|