Codebase list libfreefare / fc144fe
nfc-anticol: add option -t for timed exchanges Philippe Teuwen 11 years ago
1 changed file(s) with 26 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
6969
7070 bool quiet_output = false;
7171 bool force_rats = false;
72 bool timed = false;
7273 bool iso_ats_supported = false;
7374
7475 // ISO14443A Anti-Collision Commands
8283 static bool
8384 transmit_bits(const uint8_t *pbtTx, const size_t szTxBits)
8485 {
86 uint32_t cycles = 0;
8587 // Show transmitted command
8688 if (!quiet_output) {
8789 printf("Sent bits: ");
8890 print_hex_bits(pbtTx, szTxBits);
8991 }
9092 // Transmit the bit frame command, we don't use the arbitrary parity feature
91 if ((szRxBits = nfc_initiator_transceive_bits(pnd, pbtTx, szTxBits, NULL, abtRx, sizeof(abtRx), NULL)) < 0)
92 return false;
93
93 if (timed) {
94 if ((szRxBits = nfc_initiator_transceive_bits_timed(pnd, pbtTx, szTxBits, NULL, abtRx, sizeof(abtRx), NULL, &cycles)) < 0)
95 return false;
96 if ((!quiet_output) && (szRxBits > 0)) {
97 printf("Response after %u cycles\n", cycles);
98 }
99 } else {
100 if ((szRxBits = nfc_initiator_transceive_bits(pnd, pbtTx, szTxBits, NULL, abtRx, sizeof(abtRx), NULL)) < 0)
101 return false;
102 }
94103 // Show received answer
95104 if (!quiet_output) {
96105 printf("Received bits: ");
104113 static bool
105114 transmit_bytes(const uint8_t *pbtTx, const size_t szTx)
106115 {
116 uint32_t cycles = 0;
107117 // Show transmitted command
108118 if (!quiet_output) {
109119 printf("Sent bits: ");
111121 }
112122 int res;
113123 // Transmit the command bytes
114 if ((res = nfc_initiator_transceive_bytes(pnd, pbtTx, szTx, abtRx, sizeof(abtRx), 0)) < 0)
115 return false;
124 if (timed) {
125 if ((res = nfc_initiator_transceive_bytes_timed(pnd, pbtTx, szTx, abtRx, sizeof(abtRx), &cycles)) < 0)
126 return false;
127 if ((!quiet_output) && (res > 0)) {
128 printf("Response after %u cycles\n", cycles);
129 }
130 } else {
131 if ((res = nfc_initiator_transceive_bytes(pnd, pbtTx, szTx, abtRx, sizeof(abtRx), 0)) < 0)
132 return false;
133 }
116134 szRx = res;
117135 // Show received answer
118136 if (!quiet_output) {
131149 printf("\t-h\tHelp. Print this message.\n");
132150 printf("\t-q\tQuiet mode. Suppress output of READER and EMULATOR data (improves timing).\n");
133151 printf("\t-f\tForce RATS.\n");
152 printf("\t-t\tMeasure response time (in cycles).\n");
134153 }
135154
136155 int
147166 quiet_output = true;
148167 } else if (0 == strcmp(argv[arg], "-f")) {
149168 force_rats = true;
169 } else if (0 == strcmp(argv[arg], "-t")) {
170 timed = true;
150171 } else {
151172 ERR("%s is not supported option.", argv[arg]);
152173 print_usage(argv);