nfc-anticol: add option -t for timed exchanges
Philippe Teuwen
11 years ago
69 | 69 | |
70 | 70 | bool quiet_output = false; |
71 | 71 | bool force_rats = false; |
72 | bool timed = false; | |
72 | 73 | bool iso_ats_supported = false; |
73 | 74 | |
74 | 75 | // ISO14443A Anti-Collision Commands |
82 | 83 | static bool |
83 | 84 | transmit_bits(const uint8_t *pbtTx, const size_t szTxBits) |
84 | 85 | { |
86 | uint32_t cycles = 0; | |
85 | 87 | // Show transmitted command |
86 | 88 | if (!quiet_output) { |
87 | 89 | printf("Sent bits: "); |
88 | 90 | print_hex_bits(pbtTx, szTxBits); |
89 | 91 | } |
90 | 92 | // 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 | } | |
94 | 103 | // Show received answer |
95 | 104 | if (!quiet_output) { |
96 | 105 | printf("Received bits: "); |
104 | 113 | static bool |
105 | 114 | transmit_bytes(const uint8_t *pbtTx, const size_t szTx) |
106 | 115 | { |
116 | uint32_t cycles = 0; | |
107 | 117 | // Show transmitted command |
108 | 118 | if (!quiet_output) { |
109 | 119 | printf("Sent bits: "); |
111 | 121 | } |
112 | 122 | int res; |
113 | 123 | // 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 | } | |
116 | 134 | szRx = res; |
117 | 135 | // Show received answer |
118 | 136 | if (!quiet_output) { |
131 | 149 | printf("\t-h\tHelp. Print this message.\n"); |
132 | 150 | printf("\t-q\tQuiet mode. Suppress output of READER and EMULATOR data (improves timing).\n"); |
133 | 151 | printf("\t-f\tForce RATS.\n"); |
152 | printf("\t-t\tMeasure response time (in cycles).\n"); | |
134 | 153 | } |
135 | 154 | |
136 | 155 | int |
147 | 166 | quiet_output = true; |
148 | 167 | } else if (0 == strcmp(argv[arg], "-f")) { |
149 | 168 | force_rats = true; |
169 | } else if (0 == strcmp(argv[arg], "-t")) { | |
170 | timed = true; | |
150 | 171 | } else { |
151 | 172 | ERR("%s is not supported option.", argv[arg]); |
152 | 173 | print_usage(argv); |