add quiet mode to improve timing of emulate, relay and anticol commands
This commit is contained in:
parent
44f9cf9dd5
commit
eec2a3c220
3 changed files with 116 additions and 23 deletions
|
@ -37,6 +37,8 @@ static byte_t abtUid[10];
|
||||||
static uint32_t uiUidLen = 4;
|
static uint32_t uiUidLen = 4;
|
||||||
static dev_info* pdi;
|
static dev_info* pdi;
|
||||||
|
|
||||||
|
int Quiet= 0;
|
||||||
|
|
||||||
// ISO14443A Anti-Collision Commands
|
// ISO14443A Anti-Collision Commands
|
||||||
byte_t abtReqa [1] = { 0x26 };
|
byte_t abtReqa [1] = { 0x26 };
|
||||||
byte_t abtSelectAll [2] = { 0x93,0x20 };
|
byte_t abtSelectAll [2] = { 0x93,0x20 };
|
||||||
|
@ -47,13 +49,21 @@ byte_t abtHalt [4] = { 0x50,0x00,0x57,0xcd };
|
||||||
bool transmit_bits(const byte_t* pbtTx, const uint32_t uiTxBits)
|
bool transmit_bits(const byte_t* pbtTx, const uint32_t uiTxBits)
|
||||||
{
|
{
|
||||||
// Show transmitted command
|
// Show transmitted command
|
||||||
printf("R: "); print_hex_bits(pbtTx,uiTxBits);
|
if(!Quiet)
|
||||||
|
{
|
||||||
|
printf("R: ");
|
||||||
|
print_hex_bits(pbtTx,uiTxBits);
|
||||||
|
}
|
||||||
|
|
||||||
// Transmit the bit frame command, we don't use the arbitrary parity feature
|
// Transmit the bit frame command, we don't use the arbitrary parity feature
|
||||||
if (!nfc_initiator_transceive_bits(pdi,pbtTx,uiTxBits,NULL,abtRx,&uiRxBits,NULL)) return false;
|
if (!nfc_initiator_transceive_bits(pdi,pbtTx,uiTxBits,NULL,abtRx,&uiRxBits,NULL)) return false;
|
||||||
|
|
||||||
// Show received answer
|
// Show received answer
|
||||||
printf("T: "); print_hex_bits(abtRx,uiRxBits);
|
if(!Quiet)
|
||||||
|
{
|
||||||
|
printf("T: ");
|
||||||
|
print_hex_bits(abtRx,uiRxBits);
|
||||||
|
}
|
||||||
|
|
||||||
// Succesful transfer
|
// Succesful transfer
|
||||||
return true;
|
return true;
|
||||||
|
@ -63,20 +73,48 @@ bool transmit_bits(const byte_t* pbtTx, const uint32_t uiTxBits)
|
||||||
bool transmit_bytes(const byte_t* pbtTx, const uint32_t uiTxLen)
|
bool transmit_bytes(const byte_t* pbtTx, const uint32_t uiTxLen)
|
||||||
{
|
{
|
||||||
// Show transmitted command
|
// Show transmitted command
|
||||||
printf("R: "); print_hex(pbtTx,uiTxLen);
|
if(!Quiet)
|
||||||
|
{
|
||||||
|
printf("R: ");
|
||||||
|
print_hex(pbtTx,uiTxLen);
|
||||||
|
}
|
||||||
|
|
||||||
// Transmit the command bytes
|
// Transmit the command bytes
|
||||||
if (!nfc_initiator_transceive_bytes(pdi,pbtTx,uiTxLen,abtRx,&uiRxLen)) return false;
|
if (!nfc_initiator_transceive_bytes(pdi,pbtTx,uiTxLen,abtRx,&uiRxLen)) return false;
|
||||||
|
|
||||||
// Show received answer
|
// Show received answer
|
||||||
printf("T: "); print_hex(abtRx,uiRxLen);
|
if(!Quiet)
|
||||||
|
{
|
||||||
|
printf("T: ");
|
||||||
|
print_hex(abtRx,uiRxLen);
|
||||||
|
}
|
||||||
|
|
||||||
// Succesful transfer
|
// Succesful transfer
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, const char* argv[])
|
int main(int argc,char* argv[])
|
||||||
{
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
// Get commandline options
|
||||||
|
while ((i= getopt(argc, argv, "hq")) != -1)
|
||||||
|
switch (i)
|
||||||
|
{
|
||||||
|
case 'q':
|
||||||
|
Quiet= 1;
|
||||||
|
break;
|
||||||
|
case 'h':
|
||||||
|
default:
|
||||||
|
printf("\n\tusage:\n");
|
||||||
|
printf("\t\tnfc-anticol [OPTIONS]\n\n");
|
||||||
|
printf("\toptions:\n");
|
||||||
|
printf("\t\t-h\tHelp. Print this message.\n");
|
||||||
|
printf("\t\t-q\tQuiet mode. Suppress output of READER and EMULATOR data (improves timing).\n");
|
||||||
|
printf("\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
// Try to open the NFC reader
|
// Try to open the NFC reader
|
||||||
pdi = nfc_connect();
|
pdi = nfc_connect();
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <getopt.h>
|
||||||
|
|
||||||
#include "libnfc.h"
|
#include "libnfc.h"
|
||||||
|
|
||||||
|
@ -36,20 +37,41 @@ byte_t abtUidBcc [5] = { 0xDE,0xAD,0xBE,0xAF,0x62 };
|
||||||
byte_t abtSak [9] = { 0x08,0xb6,0xdd };
|
byte_t abtSak [9] = { 0x08,0xb6,0xdd };
|
||||||
byte_t Tmp [3] = { 0x00,0x00,0x00 };
|
byte_t Tmp [3] = { 0x00,0x00,0x00 };
|
||||||
|
|
||||||
int main(int argc, const char* argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
byte_t* pbtTx = NULL;
|
byte_t* pbtTx = NULL;
|
||||||
uint32_t uiTxBits;
|
uint32_t uiTxBits;
|
||||||
int i;
|
int i, quiet= 0;
|
||||||
|
|
||||||
|
// Get commandline options
|
||||||
|
while ((i= getopt(argc, argv, "hq")) != -1)
|
||||||
|
switch (i)
|
||||||
|
{
|
||||||
|
case 'q':
|
||||||
|
quiet= 1;
|
||||||
|
break;
|
||||||
|
case 'h':
|
||||||
|
default:
|
||||||
|
printf("\n\tusage:\n");
|
||||||
|
printf("\t\tnfc-emulate [OPTIONS] [UID]\n\n");
|
||||||
|
printf("\toptions:\n");
|
||||||
|
printf("\t\t-h\tHelp. Print this message.\n");
|
||||||
|
printf("\t\t-q\tQuiet mode. Suppress output of READER and EMULATOR data (improves timing).\n");
|
||||||
|
printf("\n");
|
||||||
|
printf("\targs:\n");
|
||||||
|
printf("\t\t[UID]\tThe UID to emulate, specified as 8 HEX digits. Default is DEADBEAF.\n");
|
||||||
|
printf("\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
// See if UID was specified as HEX string
|
// See if UID was specified as HEX string
|
||||||
if(argc == 2 && strlen(argv[1]) == 8)
|
if(argc > 1 && strlen(argv[optind]) == 8)
|
||||||
{
|
{
|
||||||
printf("[+] Using UID: %s",argv[1]);
|
printf("[+] Using UID: %s\n",argv[optind]);
|
||||||
abtUidBcc[4]= 0x00;
|
abtUidBcc[4]= 0x00;
|
||||||
for(i= 0; i < 4; ++i)
|
for(i= 0; i < 4; ++i)
|
||||||
{
|
{
|
||||||
memcpy(Tmp,argv[1]+i*2,2);
|
memcpy(Tmp,argv[optind]+i*2,2);
|
||||||
abtUidBcc[i]= (byte_t) strtol(Tmp,NULL,16);
|
abtUidBcc[i]= (byte_t) strtol(Tmp,NULL,16);
|
||||||
abtUidBcc[4] ^= abtUidBcc[i];
|
abtUidBcc[4] ^= abtUidBcc[i];
|
||||||
}
|
}
|
||||||
|
@ -93,7 +115,7 @@ int main(int argc, const char* argv[])
|
||||||
pbtTx = abtAtqa;
|
pbtTx = abtAtqa;
|
||||||
uiTxBits = 16;
|
uiTxBits = 16;
|
||||||
// New anti-collsion session started
|
// New anti-collsion session started
|
||||||
printf("\n");
|
if (!quiet) printf("\n");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 16: // Select All
|
case 16: // Select All
|
||||||
|
@ -111,16 +133,22 @@ int main(int argc, const char* argv[])
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("R: ");
|
if(!quiet)
|
||||||
print_hex_bits(abtRecv,uiRecvBits);
|
{
|
||||||
|
printf("R: ");
|
||||||
|
print_hex_bits(abtRecv,uiRecvBits);
|
||||||
|
}
|
||||||
|
|
||||||
// Test if we know how to respond
|
// Test if we know how to respond
|
||||||
if(uiTxBits)
|
if(uiTxBits)
|
||||||
{
|
{
|
||||||
// Send and print the command to the screen
|
// Send and print the command to the screen
|
||||||
nfc_target_send_bits(pdi,pbtTx,uiTxBits,NULL);
|
nfc_target_send_bits(pdi,pbtTx,uiTxBits,NULL);
|
||||||
printf("T: ");
|
if(!quiet)
|
||||||
print_hex_bits(pbtTx,uiTxBits);
|
{
|
||||||
|
printf("T: ");
|
||||||
|
print_hex_bits(pbtTx,uiTxBits);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
43
src/relay.c
43
src/relay.c
|
@ -34,8 +34,29 @@ static uint32_t uiTagRxBits;
|
||||||
static dev_info* pdiReader;
|
static dev_info* pdiReader;
|
||||||
static dev_info* pdiTag;
|
static dev_info* pdiTag;
|
||||||
|
|
||||||
int main(int argc, const char* argv[])
|
int main(int argc,char* argv[])
|
||||||
{
|
{
|
||||||
|
int quiet= 0, i;
|
||||||
|
|
||||||
|
// Get commandline options
|
||||||
|
while ((i= getopt(argc, argv, "hq")) != -1)
|
||||||
|
switch (i)
|
||||||
|
{
|
||||||
|
case 'q':
|
||||||
|
quiet= 1;
|
||||||
|
break;
|
||||||
|
case 'h':
|
||||||
|
default:
|
||||||
|
printf("\n\tusage:\n");
|
||||||
|
printf("\t\tnfc-relay [OPTIONS]\n\n");
|
||||||
|
printf("\toptions:\n");
|
||||||
|
printf("\t\t-h\tHelp. Print this message.\n");
|
||||||
|
printf("\t\t-q\tQuiet mode. Suppress output of READER and EMULATOR data (improves timing).\n");
|
||||||
|
printf("\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Try to open the NFC emulator device
|
// Try to open the NFC emulator device
|
||||||
pdiTag = nfc_connect();
|
pdiTag = nfc_connect();
|
||||||
if (pdiTag == INVALID_DEVICE_INFO)
|
if (pdiTag == INVALID_DEVICE_INFO)
|
||||||
|
@ -75,14 +96,17 @@ int main(int argc, const char* argv[])
|
||||||
{
|
{
|
||||||
// Drop down field for a very short time (original tag will reboot)
|
// Drop down field for a very short time (original tag will reboot)
|
||||||
nfc_configure(pdiReader,DCO_ACTIVATE_FIELD,false);
|
nfc_configure(pdiReader,DCO_ACTIVATE_FIELD,false);
|
||||||
printf("\n");
|
if(!quiet)
|
||||||
|
printf("\n");
|
||||||
nfc_configure(pdiReader,DCO_ACTIVATE_FIELD,true);
|
nfc_configure(pdiReader,DCO_ACTIVATE_FIELD,true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Print the reader frame to the screen
|
// Print the reader frame to the screen
|
||||||
printf("R: ");
|
if(!quiet)
|
||||||
print_hex_par(abtReaderRx,uiReaderRxBits,abtReaderRxPar);
|
{
|
||||||
|
printf("R: ");
|
||||||
|
print_hex_par(abtReaderRx,uiReaderRxBits,abtReaderRxPar);
|
||||||
|
}
|
||||||
// Forward the frame to the original tag
|
// Forward the frame to the original tag
|
||||||
if (nfc_initiator_transceive_bits(pdiReader,abtReaderRx,uiReaderRxBits,abtReaderRxPar,abtTagRx,&uiTagRxBits,abtTagRxPar))
|
if (nfc_initiator_transceive_bits(pdiReader,abtReaderRx,uiReaderRxBits,abtReaderRxPar,abtTagRx,&uiTagRxBits,abtTagRxPar))
|
||||||
{
|
{
|
||||||
|
@ -90,8 +114,11 @@ int main(int argc, const char* argv[])
|
||||||
nfc_target_send_bits(pdiTag,abtTagRx,uiTagRxBits,abtTagRxPar);
|
nfc_target_send_bits(pdiTag,abtTagRx,uiTagRxBits,abtTagRxPar);
|
||||||
|
|
||||||
// Print the tag frame to the screen
|
// Print the tag frame to the screen
|
||||||
printf("T: ");
|
if(!quiet)
|
||||||
print_hex_par(abtTagRx,uiTagRxBits,abtTagRxPar);
|
{
|
||||||
|
printf("T: ");
|
||||||
|
print_hex_par(abtTagRx,uiTagRxBits,abtTagRxPar);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue