nfc-anticol: add option -t for timed exchanges
This commit is contained in:
parent
d319e87ff8
commit
fc144fe389
1 changed files with 26 additions and 5 deletions
|
@ -70,6 +70,7 @@ static nfc_device *pnd;
|
||||||
|
|
||||||
bool quiet_output = false;
|
bool quiet_output = false;
|
||||||
bool force_rats = false;
|
bool force_rats = false;
|
||||||
|
bool timed = false;
|
||||||
bool iso_ats_supported = false;
|
bool iso_ats_supported = false;
|
||||||
|
|
||||||
// ISO14443A Anti-Collision Commands
|
// ISO14443A Anti-Collision Commands
|
||||||
|
@ -83,15 +84,23 @@ uint8_t abtHalt[4] = { 0x50, 0x00, 0x00, 0x00 };
|
||||||
static bool
|
static bool
|
||||||
transmit_bits(const uint8_t *pbtTx, const size_t szTxBits)
|
transmit_bits(const uint8_t *pbtTx, const size_t szTxBits)
|
||||||
{
|
{
|
||||||
|
uint32_t cycles = 0;
|
||||||
// Show transmitted command
|
// Show transmitted command
|
||||||
if (!quiet_output) {
|
if (!quiet_output) {
|
||||||
printf("Sent bits: ");
|
printf("Sent bits: ");
|
||||||
print_hex_bits(pbtTx, szTxBits);
|
print_hex_bits(pbtTx, szTxBits);
|
||||||
}
|
}
|
||||||
// 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 (timed) {
|
||||||
|
if ((szRxBits = nfc_initiator_transceive_bits_timed(pnd, pbtTx, szTxBits, NULL, abtRx, sizeof(abtRx), NULL, &cycles)) < 0)
|
||||||
|
return false;
|
||||||
|
if ((!quiet_output) && (szRxBits > 0)) {
|
||||||
|
printf("Response after %u cycles\n", cycles);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
if ((szRxBits = nfc_initiator_transceive_bits(pnd, pbtTx, szTxBits, NULL, abtRx, sizeof(abtRx), NULL)) < 0)
|
if ((szRxBits = nfc_initiator_transceive_bits(pnd, pbtTx, szTxBits, NULL, abtRx, sizeof(abtRx), NULL)) < 0)
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
// Show received answer
|
// Show received answer
|
||||||
if (!quiet_output) {
|
if (!quiet_output) {
|
||||||
printf("Received bits: ");
|
printf("Received bits: ");
|
||||||
|
@ -105,6 +114,7 @@ transmit_bits(const uint8_t *pbtTx, const size_t szTxBits)
|
||||||
static bool
|
static bool
|
||||||
transmit_bytes(const uint8_t *pbtTx, const size_t szTx)
|
transmit_bytes(const uint8_t *pbtTx, const size_t szTx)
|
||||||
{
|
{
|
||||||
|
uint32_t cycles = 0;
|
||||||
// Show transmitted command
|
// Show transmitted command
|
||||||
if (!quiet_output) {
|
if (!quiet_output) {
|
||||||
printf("Sent bits: ");
|
printf("Sent bits: ");
|
||||||
|
@ -112,8 +122,16 @@ transmit_bytes(const uint8_t *pbtTx, const size_t szTx)
|
||||||
}
|
}
|
||||||
int res;
|
int res;
|
||||||
// Transmit the command bytes
|
// Transmit the command bytes
|
||||||
|
if (timed) {
|
||||||
|
if ((res = nfc_initiator_transceive_bytes_timed(pnd, pbtTx, szTx, abtRx, sizeof(abtRx), &cycles)) < 0)
|
||||||
|
return false;
|
||||||
|
if ((!quiet_output) && (res > 0)) {
|
||||||
|
printf("Response after %u cycles\n", cycles);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
if ((res = nfc_initiator_transceive_bytes(pnd, pbtTx, szTx, abtRx, sizeof(abtRx), 0)) < 0)
|
if ((res = nfc_initiator_transceive_bytes(pnd, pbtTx, szTx, abtRx, sizeof(abtRx), 0)) < 0)
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
szRx = res;
|
szRx = res;
|
||||||
// Show received answer
|
// Show received answer
|
||||||
if (!quiet_output) {
|
if (!quiet_output) {
|
||||||
|
@ -132,6 +150,7 @@ print_usage(char *argv[])
|
||||||
printf("\t-h\tHelp. Print this message.\n");
|
printf("\t-h\tHelp. Print this message.\n");
|
||||||
printf("\t-q\tQuiet mode. Suppress output of READER and EMULATOR data (improves timing).\n");
|
printf("\t-q\tQuiet mode. Suppress output of READER and EMULATOR data (improves timing).\n");
|
||||||
printf("\t-f\tForce RATS.\n");
|
printf("\t-f\tForce RATS.\n");
|
||||||
|
printf("\t-t\tMeasure response time (in cycles).\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -148,6 +167,8 @@ main(int argc, char *argv[])
|
||||||
quiet_output = true;
|
quiet_output = true;
|
||||||
} else if (0 == strcmp(argv[arg], "-f")) {
|
} else if (0 == strcmp(argv[arg], "-f")) {
|
||||||
force_rats = true;
|
force_rats = true;
|
||||||
|
} else if (0 == strcmp(argv[arg], "-t")) {
|
||||||
|
timed = true;
|
||||||
} else {
|
} else {
|
||||||
ERR("%s is not supported option.", argv[arg]);
|
ERR("%s is not supported option.", argv[arg]);
|
||||||
print_usage(argv);
|
print_usage(argv);
|
||||||
|
|
Loading…
Add table
Reference in a new issue