astyle --formatted --mode=c --indent=spaces=2 --indent-switches --indent-preprocessor --keep-one-line-blocks --max-instatement-indent=60 --brackets=linux --pad-oper --unpad-paren --pad-header
This commit is contained in:
parent
562205cc14
commit
01303fab0d
59 changed files with 3178 additions and 3178 deletions
|
|
@ -61,77 +61,77 @@ static nfc_device *pndTag;
|
|||
static bool quitting = false;
|
||||
|
||||
static void
|
||||
intr_hdlr (int sig)
|
||||
intr_hdlr(int sig)
|
||||
{
|
||||
(void) sig;
|
||||
printf ("\nQuitting...\n");
|
||||
printf("\nQuitting...\n");
|
||||
quitting = true;
|
||||
return;
|
||||
}
|
||||
|
||||
static void
|
||||
print_usage (char *argv[])
|
||||
print_usage(char *argv[])
|
||||
{
|
||||
printf ("Usage: %s [OPTIONS]\n", argv[0]);
|
||||
printf ("Options:\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("Usage: %s [OPTIONS]\n", argv[0]);
|
||||
printf("Options:\n");
|
||||
printf("\t-h\tHelp. Print this message.\n");
|
||||
printf("\t-q\tQuiet mode. Suppress output of READER and EMULATOR data (improves timing).\n");
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int arg;
|
||||
bool quiet_output = false;
|
||||
const char *acLibnfcVersion = nfc_version ();
|
||||
const char *acLibnfcVersion = nfc_version();
|
||||
|
||||
// Get commandline options
|
||||
for (arg = 1; arg < argc; arg++) {
|
||||
if (0 == strcmp (argv[arg], "-h")) {
|
||||
print_usage (argv);
|
||||
if (0 == strcmp(argv[arg], "-h")) {
|
||||
print_usage(argv);
|
||||
return EXIT_SUCCESS;
|
||||
} else if (0 == strcmp (argv[arg], "-q")) {
|
||||
} else if (0 == strcmp(argv[arg], "-q")) {
|
||||
quiet_output = true;
|
||||
} else {
|
||||
ERR ("%s is not supported option.", argv[arg]);
|
||||
print_usage (argv);
|
||||
ERR("%s is not supported option.", argv[arg]);
|
||||
print_usage(argv);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
// Display libnfc version
|
||||
printf ("%s uses libnfc %s\n", argv[0], acLibnfcVersion);
|
||||
printf("%s uses libnfc %s\n", argv[0], acLibnfcVersion);
|
||||
|
||||
#ifdef WIN32
|
||||
signal (SIGINT, (void (__cdecl *) (int)) intr_hdlr);
|
||||
signal(SIGINT, (void (__cdecl *)(int)) intr_hdlr);
|
||||
#else
|
||||
signal (SIGINT, intr_hdlr);
|
||||
signal(SIGINT, intr_hdlr);
|
||||
#endif
|
||||
|
||||
nfc_connstring connstrings[MAX_DEVICE_COUNT];
|
||||
// List available devices
|
||||
size_t szFound = nfc_list_devices (NULL, connstrings, MAX_DEVICE_COUNT);
|
||||
size_t szFound = nfc_list_devices(NULL, connstrings, MAX_DEVICE_COUNT);
|
||||
|
||||
if (szFound < 2) {
|
||||
ERR ("%zd device found but two opened devices are needed to relay NFC.", szFound);
|
||||
ERR("%zd device found but two opened devices are needed to relay NFC.", szFound);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
nfc_init (NULL);
|
||||
nfc_init(NULL);
|
||||
|
||||
// Try to open the NFC emulator device
|
||||
pndTag = nfc_open (NULL, connstrings[0]);
|
||||
pndTag = nfc_open(NULL, connstrings[0]);
|
||||
if (pndTag == NULL) {
|
||||
printf ("Error opening NFC emulator device\n");
|
||||
printf("Error opening NFC emulator device\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
printf ("Hint: tag <---> initiator (relay) <---> target (relay) <---> original reader\n\n");
|
||||
printf("Hint: tag <---> initiator (relay) <---> target (relay) <---> original reader\n\n");
|
||||
|
||||
printf ("NFC emulator device: %s opened\n", nfc_device_get_name (pndTag));
|
||||
printf ("[+] Try to break out the auto-emulation, this requires a second reader!\n");
|
||||
printf ("[+] To do this, please send any command after the anti-collision\n");
|
||||
printf ("[+] For example, send a RATS command or use the \"nfc-anticol\" tool\n");
|
||||
printf("NFC emulator device: %s opened\n", nfc_device_get_name(pndTag));
|
||||
printf("[+] Try to break out the auto-emulation, this requires a second reader!\n");
|
||||
printf("[+] To do this, please send any command after the anti-collision\n");
|
||||
printf("[+] For example, send a RATS command or use the \"nfc-anticol\" tool\n");
|
||||
|
||||
nfc_target nt = {
|
||||
.nm = {
|
||||
|
|
@ -149,79 +149,79 @@ main (int argc, char *argv[])
|
|||
},
|
||||
};
|
||||
|
||||
if ((szReaderRxBits = nfc_target_init (pndTag, &nt, abtReaderRx, sizeof (abtReaderRx), 0)) < 0) {
|
||||
ERR ("%s", "Initialization of NFC emulator failed");
|
||||
nfc_close (pndTag);
|
||||
nfc_exit (NULL);
|
||||
if ((szReaderRxBits = nfc_target_init(pndTag, &nt, abtReaderRx, sizeof(abtReaderRx), 0)) < 0) {
|
||||
ERR("%s", "Initialization of NFC emulator failed");
|
||||
nfc_close(pndTag);
|
||||
nfc_exit(NULL);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
printf ("%s", "Configuring emulator settings...");
|
||||
if ((nfc_device_set_property_bool (pndTag, NP_HANDLE_CRC, false) < 0) ||
|
||||
(nfc_device_set_property_bool (pndTag, NP_HANDLE_PARITY, false) < 0) || (nfc_device_set_property_bool (pndTag, NP_ACCEPT_INVALID_FRAMES, true)) < 0) {
|
||||
nfc_perror (pndTag, "nfc_device_set_property_bool");
|
||||
exit (EXIT_FAILURE);
|
||||
printf("%s", "Configuring emulator settings...");
|
||||
if ((nfc_device_set_property_bool(pndTag, NP_HANDLE_CRC, false) < 0) ||
|
||||
(nfc_device_set_property_bool(pndTag, NP_HANDLE_PARITY, false) < 0) || (nfc_device_set_property_bool(pndTag, NP_ACCEPT_INVALID_FRAMES, true)) < 0) {
|
||||
nfc_perror(pndTag, "nfc_device_set_property_bool");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
printf ("%s", "Done, emulated tag is initialized");
|
||||
printf("%s", "Done, emulated tag is initialized");
|
||||
|
||||
// Try to open the NFC reader
|
||||
pndReader = nfc_open (NULL, connstrings[1]);
|
||||
pndReader = nfc_open(NULL, connstrings[1]);
|
||||
|
||||
printf ("NFC reader device: %s opened", nfc_device_get_name (pndReader));
|
||||
printf ("%s", "Configuring NFC reader settings...");
|
||||
printf("NFC reader device: %s opened", nfc_device_get_name(pndReader));
|
||||
printf("%s", "Configuring NFC reader settings...");
|
||||
|
||||
if (nfc_initiator_init (pndReader) < 0) {
|
||||
nfc_perror (pndReader, "nfc_initiator_init");
|
||||
exit (EXIT_FAILURE);
|
||||
if (nfc_initiator_init(pndReader) < 0) {
|
||||
nfc_perror(pndReader, "nfc_initiator_init");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if ((nfc_device_set_property_bool (pndReader, NP_HANDLE_CRC, false) < 0) ||
|
||||
(nfc_device_set_property_bool (pndReader, NP_HANDLE_PARITY, false) < 0) ||
|
||||
(nfc_device_set_property_bool (pndReader, NP_ACCEPT_INVALID_FRAMES, true)) < 0) {
|
||||
nfc_perror (pndReader, "nfc_device_set_property_bool");
|
||||
exit (EXIT_FAILURE);
|
||||
if ((nfc_device_set_property_bool(pndReader, NP_HANDLE_CRC, false) < 0) ||
|
||||
(nfc_device_set_property_bool(pndReader, NP_HANDLE_PARITY, false) < 0) ||
|
||||
(nfc_device_set_property_bool(pndReader, NP_ACCEPT_INVALID_FRAMES, true)) < 0) {
|
||||
nfc_perror(pndReader, "nfc_device_set_property_bool");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
printf ("%s", "Done, relaying frames now!");
|
||||
printf("%s", "Done, relaying frames now!");
|
||||
|
||||
while (!quitting) {
|
||||
// Test if we received a frame from the reader
|
||||
if ((szReaderRxBits = nfc_target_receive_bits (pndTag, abtReaderRx, sizeof (abtReaderRx), abtReaderRxPar)) > 0) {
|
||||
if ((szReaderRxBits = nfc_target_receive_bits(pndTag, abtReaderRx, sizeof(abtReaderRx), abtReaderRxPar)) > 0) {
|
||||
// Drop down the field before sending a REQA command and start a new session
|
||||
if (szReaderRxBits == 7 && abtReaderRx[0] == 0x26) {
|
||||
// Drop down field for a very short time (original tag will reboot)
|
||||
if (nfc_device_set_property_bool (pndReader, NP_ACTIVATE_FIELD, false) < 0) {
|
||||
nfc_perror (pndReader, "nfc_device_set_property_bool");
|
||||
exit (EXIT_FAILURE);
|
||||
if (nfc_device_set_property_bool(pndReader, NP_ACTIVATE_FIELD, false) < 0) {
|
||||
nfc_perror(pndReader, "nfc_device_set_property_bool");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (!quiet_output)
|
||||
printf ("\n");
|
||||
if (nfc_device_set_property_bool (pndReader, NP_ACTIVATE_FIELD, true) < 0) {
|
||||
nfc_perror (pndReader, "nfc_device_set_property_bool");
|
||||
exit (EXIT_FAILURE);
|
||||
printf("\n");
|
||||
if (nfc_device_set_property_bool(pndReader, NP_ACTIVATE_FIELD, true) < 0) {
|
||||
nfc_perror(pndReader, "nfc_device_set_property_bool");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
// Print the reader frame to the screen
|
||||
if (!quiet_output) {
|
||||
printf ("R: ");
|
||||
print_hex_par (abtReaderRx, (size_t) szReaderRxBits, abtReaderRxPar);
|
||||
printf("R: ");
|
||||
print_hex_par(abtReaderRx, (size_t) szReaderRxBits, abtReaderRxPar);
|
||||
}
|
||||
// Forward the frame to the original tag
|
||||
if ((szTagRxBits = nfc_initiator_transceive_bits
|
||||
(pndReader, abtReaderRx, (size_t) szReaderRxBits, abtReaderRxPar, abtTagRx, abtTagRxPar)) > 0) {
|
||||
// Redirect the answer back to the reader
|
||||
if (nfc_target_send_bits (pndTag, abtTagRx, szTagRxBits, abtTagRxPar) < 0) {
|
||||
nfc_perror (pndTag, "nfc_target_send_bits");
|
||||
exit (EXIT_FAILURE);
|
||||
if (nfc_target_send_bits(pndTag, abtTagRx, szTagRxBits, abtTagRxPar) < 0) {
|
||||
nfc_perror(pndTag, "nfc_target_send_bits");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
// Print the tag frame to the screen
|
||||
if (!quiet_output) {
|
||||
printf ("T: ");
|
||||
print_hex_par (abtTagRx, szTagRxBits, abtTagRxPar);
|
||||
printf("T: ");
|
||||
print_hex_par(abtTagRx, szTagRxBits, abtTagRxPar);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nfc_close (pndTag);
|
||||
nfc_close (pndReader);
|
||||
nfc_exit (NULL);
|
||||
exit (EXIT_SUCCESS);
|
||||
nfc_close(pndTag);
|
||||
nfc_close(pndReader);
|
||||
nfc_exit(NULL);
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue