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
|
|
@ -14,52 +14,52 @@
|
|||
#include "libnfc/chips/pn53x.h"
|
||||
|
||||
int
|
||||
main (int argc, const char *argv[])
|
||||
main(int argc, const char *argv[])
|
||||
{
|
||||
nfc_device *pnd;
|
||||
nfc_target nt;
|
||||
|
||||
nfc_init (NULL);
|
||||
nfc_init(NULL);
|
||||
|
||||
// Display libnfc version
|
||||
const char *acLibnfcVersion = nfc_version ();
|
||||
printf ("%s uses libnfc %s\n", argv[0], acLibnfcVersion);
|
||||
const char *acLibnfcVersion = nfc_version();
|
||||
printf("%s uses libnfc %s\n", argv[0], acLibnfcVersion);
|
||||
|
||||
// Open, using the first available NFC device
|
||||
pnd = nfc_open (NULL, NULL);
|
||||
pnd = nfc_open(NULL, NULL);
|
||||
|
||||
if (pnd == NULL) {
|
||||
ERR ("%s", "Unable to open NFC device.");
|
||||
ERR("%s", "Unable to open NFC device.");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
// Set opened NFC device to initiator mode
|
||||
if (nfc_initiator_init (pnd) < 0) {
|
||||
nfc_perror (pnd, "nfc_initiator_init");
|
||||
exit (EXIT_FAILURE);
|
||||
if (nfc_initiator_init(pnd) < 0) {
|
||||
nfc_perror(pnd, "nfc_initiator_init");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
printf ("NFC reader: %s opened\n", nfc_device_get_name (pnd));
|
||||
printf("NFC reader: %s opened\n", nfc_device_get_name(pnd));
|
||||
|
||||
// Poll for a ISO14443A (MIFARE) tag
|
||||
const nfc_modulation nmMifare = {
|
||||
.nmt = NMT_ISO14443A,
|
||||
.nbr = NBR_106,
|
||||
};
|
||||
if (nfc_initiator_select_passive_target (pnd, nmMifare, NULL, 0, &nt) > 0) {
|
||||
printf ("The following (NFC) ISO14443A tag was found:\n");
|
||||
printf (" ATQA (SENS_RES): ");
|
||||
print_hex (nt.nti.nai.abtAtqa, 2);
|
||||
printf (" UID (NFCID%c): ", (nt.nti.nai.abtUid[0] == 0x08 ? '3' : '1'));
|
||||
print_hex (nt.nti.nai.abtUid, nt.nti.nai.szUidLen);
|
||||
printf (" SAK (SEL_RES): ");
|
||||
print_hex (&nt.nti.nai.btSak, 1);
|
||||
if (nfc_initiator_select_passive_target(pnd, nmMifare, NULL, 0, &nt) > 0) {
|
||||
printf("The following (NFC) ISO14443A tag was found:\n");
|
||||
printf(" ATQA (SENS_RES): ");
|
||||
print_hex(nt.nti.nai.abtAtqa, 2);
|
||||
printf(" UID (NFCID%c): ", (nt.nti.nai.abtUid[0] == 0x08 ? '3' : '1'));
|
||||
print_hex(nt.nti.nai.abtUid, nt.nti.nai.szUidLen);
|
||||
printf(" SAK (SEL_RES): ");
|
||||
print_hex(&nt.nti.nai.btSak, 1);
|
||||
if (nt.nti.nai.szAtsLen) {
|
||||
printf (" ATS (ATR): ");
|
||||
print_hex (nt.nti.nai.abtAts, nt.nti.nai.szAtsLen);
|
||||
printf(" ATS (ATR): ");
|
||||
print_hex(nt.nti.nai.abtAts, nt.nti.nai.szAtsLen);
|
||||
}
|
||||
}
|
||||
// Close NFC device
|
||||
nfc_close (pnd);
|
||||
nfc_exit (NULL);
|
||||
nfc_close(pnd);
|
||||
nfc_exit(NULL);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -75,21 +75,21 @@ uint8_t abtHalt[4] = { 0x50, 0x00, 0x00, 0x00 };
|
|||
#define CASCADE_BIT 0x04
|
||||
|
||||
static bool
|
||||
transmit_bits (const uint8_t *pbtTx, const size_t szTxBits)
|
||||
transmit_bits(const uint8_t *pbtTx, const size_t szTxBits)
|
||||
{
|
||||
// Show transmitted command
|
||||
if (!quiet_output) {
|
||||
printf ("Sent bits: ");
|
||||
print_hex_bits (pbtTx, szTxBits);
|
||||
printf("Sent bits: ");
|
||||
print_hex_bits(pbtTx, szTxBits);
|
||||
}
|
||||
// Transmit the bit frame command, we don't use the arbitrary parity feature
|
||||
if ((szRxBits = nfc_initiator_transceive_bits (pnd, pbtTx, szTxBits, NULL, abtRx, NULL)) < 0)
|
||||
if ((szRxBits = nfc_initiator_transceive_bits(pnd, pbtTx, szTxBits, NULL, abtRx, NULL)) < 0)
|
||||
return false;
|
||||
|
||||
// Show received answer
|
||||
if (!quiet_output) {
|
||||
printf ("Received bits: ");
|
||||
print_hex_bits (abtRx, szRxBits);
|
||||
printf("Received bits: ");
|
||||
print_hex_bits(abtRx, szRxBits);
|
||||
}
|
||||
// Succesful transfer
|
||||
return true;
|
||||
|
|
@ -97,103 +97,103 @@ transmit_bits (const uint8_t *pbtTx, const size_t szTxBits)
|
|||
|
||||
|
||||
static bool
|
||||
transmit_bytes (const uint8_t *pbtTx, const size_t szTx)
|
||||
transmit_bytes(const uint8_t *pbtTx, const size_t szTx)
|
||||
{
|
||||
// Show transmitted command
|
||||
if (!quiet_output) {
|
||||
printf ("Sent bits: ");
|
||||
print_hex (pbtTx, szTx);
|
||||
printf("Sent bits: ");
|
||||
print_hex(pbtTx, szTx);
|
||||
}
|
||||
int res;
|
||||
// Transmit the command bytes
|
||||
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;
|
||||
|
||||
// Show received answer
|
||||
if (!quiet_output) {
|
||||
printf ("Received bits: ");
|
||||
print_hex (abtRx, res);
|
||||
printf("Received bits: ");
|
||||
print_hex(abtRx, res);
|
||||
}
|
||||
// Succesful transfer
|
||||
return true;
|
||||
}
|
||||
|
||||
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 ("\t-f\tForce RATS.\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");
|
||||
printf("\t-f\tForce RATS.\n");
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int arg;
|
||||
|
||||
// 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);
|
||||
exit(EXIT_SUCCESS);
|
||||
} else if (0 == strcmp (argv[arg], "-q")) {
|
||||
} else if (0 == strcmp(argv[arg], "-q")) {
|
||||
quiet_output = true;
|
||||
} else if (0 == strcmp (argv[arg], "-f")) {
|
||||
} else if (0 == strcmp(argv[arg], "-f")) {
|
||||
force_rats = true;
|
||||
} else {
|
||||
ERR ("%s is not supported option.", argv[arg]);
|
||||
print_usage (argv);
|
||||
ERR("%s is not supported option.", argv[arg]);
|
||||
print_usage(argv);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
nfc_init (NULL);
|
||||
nfc_init(NULL);
|
||||
|
||||
// Try to open the NFC reader
|
||||
pnd = nfc_open (NULL, NULL);
|
||||
pnd = nfc_open(NULL, NULL);
|
||||
|
||||
if (!pnd) {
|
||||
printf ("Error opening NFC reader\n");
|
||||
printf("Error opening NFC reader\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
// Initialise NFC device as "initiator"
|
||||
if (nfc_initiator_init (pnd) < 0) {
|
||||
nfc_perror (pnd, "nfc_initiator_init");
|
||||
exit (EXIT_FAILURE);
|
||||
if (nfc_initiator_init(pnd) < 0) {
|
||||
nfc_perror(pnd, "nfc_initiator_init");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
// Configure the CRC
|
||||
if (nfc_device_set_property_bool (pnd, NP_HANDLE_CRC, false) < 0) {
|
||||
nfc_perror (pnd, "nfc_device_set_property_bool");
|
||||
exit (EXIT_FAILURE);
|
||||
if (nfc_device_set_property_bool(pnd, NP_HANDLE_CRC, false) < 0) {
|
||||
nfc_perror(pnd, "nfc_device_set_property_bool");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
// Use raw send/receive methods
|
||||
if (nfc_device_set_property_bool (pnd, NP_EASY_FRAMING, false) < 0) {
|
||||
nfc_perror (pnd, "nfc_device_set_property_bool");
|
||||
exit (EXIT_FAILURE);
|
||||
if (nfc_device_set_property_bool(pnd, NP_EASY_FRAMING, false) < 0) {
|
||||
nfc_perror(pnd, "nfc_device_set_property_bool");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
// Disable 14443-4 autoswitching
|
||||
if (nfc_device_set_property_bool (pnd, NP_AUTO_ISO14443_4, false) < 0) {
|
||||
nfc_perror (pnd, "nfc_device_set_property_bool");
|
||||
exit (EXIT_FAILURE);
|
||||
if (nfc_device_set_property_bool(pnd, NP_AUTO_ISO14443_4, false) < 0) {
|
||||
nfc_perror(pnd, "nfc_device_set_property_bool");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
printf ("NFC reader: %s opened\n\n", nfc_device_get_name (pnd));
|
||||
printf("NFC reader: %s opened\n\n", nfc_device_get_name(pnd));
|
||||
|
||||
// Send the 7 bits request command specified in ISO 14443A (0x26)
|
||||
if (!transmit_bits (abtReqa, 7)) {
|
||||
printf ("Error: No tag available\n");
|
||||
nfc_close (pnd);
|
||||
nfc_exit (NULL);
|
||||
if (!transmit_bits(abtReqa, 7)) {
|
||||
printf("Error: No tag available\n");
|
||||
nfc_close(pnd);
|
||||
nfc_exit(NULL);
|
||||
return 1;
|
||||
}
|
||||
memcpy (abtAtqa, abtRx, 2);
|
||||
memcpy(abtAtqa, abtRx, 2);
|
||||
|
||||
// Anti-collision
|
||||
transmit_bytes (abtSelectAll, 2);
|
||||
transmit_bytes(abtSelectAll, 2);
|
||||
|
||||
// Check answer
|
||||
if ((abtRx[0] ^ abtRx[1] ^ abtRx[2] ^ abtRx[3] ^ abtRx[4]) != 0) {
|
||||
|
|
@ -201,12 +201,12 @@ main (int argc, char *argv[])
|
|||
}
|
||||
|
||||
// Save the UID CL1
|
||||
memcpy (abtRawUid, abtRx, 4);
|
||||
memcpy(abtRawUid, abtRx, 4);
|
||||
|
||||
//Prepare and send CL1 Select-Command
|
||||
memcpy (abtSelectTag + 2, abtRx, 5);
|
||||
iso14443a_crc_append (abtSelectTag, 7);
|
||||
transmit_bytes (abtSelectTag, 9);
|
||||
memcpy(abtSelectTag + 2, abtRx, 5);
|
||||
iso14443a_crc_append(abtSelectTag, 7);
|
||||
transmit_bytes(abtSelectTag, 9);
|
||||
abtSak = abtRx[0];
|
||||
|
||||
// Test if we are dealing with a CL2
|
||||
|
|
@ -218,14 +218,14 @@ main (int argc, char *argv[])
|
|||
}
|
||||
}
|
||||
|
||||
if(szCL == 2) {
|
||||
if (szCL == 2) {
|
||||
// We have to do the anti-collision for cascade level 2
|
||||
|
||||
// Prepare CL2 commands
|
||||
abtSelectAll[0] = 0x95;
|
||||
|
||||
// Anti-collision
|
||||
transmit_bytes (abtSelectAll, 2);
|
||||
transmit_bytes(abtSelectAll, 2);
|
||||
|
||||
// Check answer
|
||||
if ((abtRx[0] ^ abtRx[1] ^ abtRx[2] ^ abtRx[3] ^ abtRx[4]) != 0) {
|
||||
|
|
@ -233,13 +233,13 @@ main (int argc, char *argv[])
|
|||
}
|
||||
|
||||
// Save UID CL2
|
||||
memcpy (abtRawUid + 4, abtRx, 4);
|
||||
memcpy(abtRawUid + 4, abtRx, 4);
|
||||
|
||||
// Selection
|
||||
abtSelectTag[0] = 0x95;
|
||||
memcpy (abtSelectTag + 2, abtRx, 5);
|
||||
iso14443a_crc_append (abtSelectTag, 7);
|
||||
transmit_bytes (abtSelectTag, 9);
|
||||
memcpy(abtSelectTag + 2, abtRx, 5);
|
||||
iso14443a_crc_append(abtSelectTag, 7);
|
||||
transmit_bytes(abtSelectTag, 9);
|
||||
abtSak = abtRx[0];
|
||||
|
||||
// Test if we are dealing with a CL3
|
||||
|
|
@ -251,12 +251,12 @@ main (int argc, char *argv[])
|
|||
}
|
||||
}
|
||||
|
||||
if ( szCL == 3) {
|
||||
if (szCL == 3) {
|
||||
// We have to do the anti-collision for cascade level 3
|
||||
|
||||
// Prepare and send CL3 AC-Command
|
||||
abtSelectAll[0] = 0x97;
|
||||
transmit_bytes (abtSelectAll, 2);
|
||||
transmit_bytes(abtSelectAll, 2);
|
||||
|
||||
// Check answer
|
||||
if ((abtRx[0] ^ abtRx[1] ^ abtRx[2] ^ abtRx[3] ^ abtRx[4]) != 0) {
|
||||
|
|
@ -264,13 +264,13 @@ main (int argc, char *argv[])
|
|||
}
|
||||
|
||||
// Save UID CL3
|
||||
memcpy (abtRawUid + 8, abtRx, 4);
|
||||
memcpy(abtRawUid + 8, abtRx, 4);
|
||||
|
||||
// Prepare and send final Select-Command
|
||||
abtSelectTag[0] = 0x97;
|
||||
memcpy (abtSelectTag + 2, abtRx, 5);
|
||||
iso14443a_crc_append (abtSelectTag, 7);
|
||||
transmit_bytes (abtSelectTag, 9);
|
||||
memcpy(abtSelectTag + 2, abtRx, 5);
|
||||
iso14443a_crc_append(abtSelectTag, 7);
|
||||
transmit_bytes(abtSelectTag, 9);
|
||||
abtSak = abtRx[0];
|
||||
}
|
||||
}
|
||||
|
|
@ -281,29 +281,29 @@ main (int argc, char *argv[])
|
|||
}
|
||||
if ((abtRx[0] & SAK_FLAG_ATS_SUPPORTED) || force_rats) {
|
||||
iso14443a_crc_append(abtRats, 2);
|
||||
if (transmit_bytes (abtRats, 4)) {
|
||||
memcpy (abtAts, abtRx, szRx);
|
||||
if (transmit_bytes(abtRats, 4)) {
|
||||
memcpy(abtAts, abtRx, szRx);
|
||||
szAts = szRx;
|
||||
}
|
||||
}
|
||||
|
||||
// Done, halt the tag now
|
||||
iso14443a_crc_append(abtHalt, 2);
|
||||
transmit_bytes (abtHalt, 4);
|
||||
transmit_bytes(abtHalt, 4);
|
||||
|
||||
printf ("\nFound tag with\n UID: ");
|
||||
printf("\nFound tag with\n UID: ");
|
||||
switch (szCL) {
|
||||
case 1:
|
||||
printf ("%02x%02x%02x%02x", abtRawUid[0], abtRawUid[1], abtRawUid[2], abtRawUid[3]);
|
||||
printf("%02x%02x%02x%02x", abtRawUid[0], abtRawUid[1], abtRawUid[2], abtRawUid[3]);
|
||||
break;
|
||||
case 2:
|
||||
printf ("%02x%02x%02x", abtRawUid[1], abtRawUid[2], abtRawUid[3]);
|
||||
printf ("%02x%02x%02x%02x", abtRawUid[4], abtRawUid[5], abtRawUid[6], abtRawUid[7]);
|
||||
printf("%02x%02x%02x", abtRawUid[1], abtRawUid[2], abtRawUid[3]);
|
||||
printf("%02x%02x%02x%02x", abtRawUid[4], abtRawUid[5], abtRawUid[6], abtRawUid[7]);
|
||||
break;
|
||||
case 3:
|
||||
printf ("%02x%02x%02x", abtRawUid[1], abtRawUid[2], abtRawUid[3]);
|
||||
printf ("%02x%02x%02x", abtRawUid[5], abtRawUid[6], abtRawUid[7]);
|
||||
printf ("%02x%02x%02x%02x", abtRawUid[8], abtRawUid[9], abtRawUid[10], abtRawUid[11]);
|
||||
printf("%02x%02x%02x", abtRawUid[1], abtRawUid[2], abtRawUid[3]);
|
||||
printf("%02x%02x%02x", abtRawUid[5], abtRawUid[6], abtRawUid[7]);
|
||||
printf("%02x%02x%02x%02x", abtRawUid[8], abtRawUid[9], abtRawUid[10], abtRawUid[11]);
|
||||
break;
|
||||
}
|
||||
printf("\n");
|
||||
|
|
@ -313,10 +313,10 @@ main (int argc, char *argv[])
|
|||
printf(" RATS forced\n");
|
||||
}
|
||||
printf(" ATS: ");
|
||||
print_hex (abtAts, szAts);
|
||||
print_hex(abtAts, szAts);
|
||||
}
|
||||
|
||||
nfc_close (pnd);
|
||||
nfc_exit (NULL);
|
||||
nfc_close(pnd);
|
||||
nfc_exit(NULL);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,66 +50,66 @@
|
|||
|
||||
static nfc_device *pnd;
|
||||
|
||||
static void stop_dep_communication (int sig)
|
||||
static void stop_dep_communication(int sig)
|
||||
{
|
||||
(void) sig;
|
||||
if (pnd)
|
||||
nfc_abort_command (pnd);
|
||||
nfc_abort_command(pnd);
|
||||
else
|
||||
exit (EXIT_FAILURE);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, const char *argv[])
|
||||
main(int argc, const char *argv[])
|
||||
{
|
||||
nfc_target nt;
|
||||
uint8_t abtRx[MAX_FRAME_LEN];
|
||||
uint8_t abtTx[] = "Hello World!";
|
||||
|
||||
if (argc > 1) {
|
||||
printf ("Usage: %s\n", argv[0]);
|
||||
printf("Usage: %s\n", argv[0]);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
nfc_init (NULL);
|
||||
nfc_init(NULL);
|
||||
|
||||
pnd = nfc_open (NULL, NULL);
|
||||
pnd = nfc_open(NULL, NULL);
|
||||
if (!pnd) {
|
||||
printf("Unable to open NFC device.\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
printf ("NFC device: %s\n opened", nfc_device_get_name (pnd));
|
||||
printf("NFC device: %s\n opened", nfc_device_get_name(pnd));
|
||||
|
||||
signal (SIGINT, stop_dep_communication);
|
||||
signal(SIGINT, stop_dep_communication);
|
||||
|
||||
if (nfc_initiator_init (pnd) < 0) {
|
||||
if (nfc_initiator_init(pnd) < 0) {
|
||||
nfc_perror(pnd, "nfc_initiator_init");
|
||||
goto error;
|
||||
}
|
||||
|
||||
if(nfc_initiator_select_dep_target (pnd, NDM_PASSIVE, NBR_212, NULL, &nt, 1000) < 0) {
|
||||
if (nfc_initiator_select_dep_target(pnd, NDM_PASSIVE, NBR_212, NULL, &nt, 1000) < 0) {
|
||||
nfc_perror(pnd, "nfc_initiator_select_dep_target");
|
||||
goto error;
|
||||
}
|
||||
print_nfc_target (nt, false);
|
||||
print_nfc_target(nt, false);
|
||||
|
||||
printf ("Sending: %s\n", abtTx);
|
||||
printf("Sending: %s\n", abtTx);
|
||||
int res;
|
||||
if ((res = nfc_initiator_transceive_bytes (pnd, abtTx, sizeof(abtTx), abtRx, sizeof(abtRx), 0)) < 0) {
|
||||
if ((res = nfc_initiator_transceive_bytes(pnd, abtTx, sizeof(abtTx), abtRx, sizeof(abtRx), 0)) < 0) {
|
||||
nfc_perror(pnd, "nfc_initiator_transceive_bytes");
|
||||
goto error;
|
||||
}
|
||||
|
||||
abtRx[res] = 0;
|
||||
printf ("Received: %s\n", abtRx);
|
||||
printf("Received: %s\n", abtRx);
|
||||
|
||||
if (nfc_initiator_deselect_target (pnd) < 0) {
|
||||
if (nfc_initiator_deselect_target(pnd) < 0) {
|
||||
nfc_perror(pnd, "nfc_initiator_deselect_target");
|
||||
goto error;
|
||||
}
|
||||
|
||||
error:
|
||||
nfc_close (pnd);
|
||||
nfc_exit (NULL);
|
||||
nfc_close(pnd);
|
||||
nfc_exit(NULL);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,40 +49,40 @@
|
|||
|
||||
static nfc_device *pnd;
|
||||
|
||||
static void stop_dep_communication (int sig)
|
||||
static void stop_dep_communication(int sig)
|
||||
{
|
||||
(void) sig;
|
||||
if (pnd)
|
||||
nfc_abort_command (pnd);
|
||||
nfc_abort_command(pnd);
|
||||
else
|
||||
exit (EXIT_FAILURE);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, const char *argv[])
|
||||
main(int argc, const char *argv[])
|
||||
{
|
||||
uint8_t abtRx[MAX_FRAME_LEN];
|
||||
int szRx;
|
||||
uint8_t abtTx[] = "Hello Mars!";
|
||||
#define MAX_DEVICE_COUNT 2
|
||||
nfc_connstring connstrings[MAX_DEVICE_COUNT];
|
||||
size_t szDeviceFound = nfc_list_devices (NULL, connstrings, MAX_DEVICE_COUNT);
|
||||
size_t szDeviceFound = nfc_list_devices(NULL, connstrings, MAX_DEVICE_COUNT);
|
||||
// Little hack to allow using nfc-dep-initiator & nfc-dep-target from
|
||||
// the same machine: if there is more than one readers opened
|
||||
// nfc-dep-target will open the second reader
|
||||
// (we hope they're always detected in the same order)
|
||||
nfc_init (NULL);
|
||||
nfc_init(NULL);
|
||||
if (szDeviceFound == 1) {
|
||||
pnd = nfc_open (NULL, connstrings[0]);
|
||||
pnd = nfc_open(NULL, connstrings[0]);
|
||||
} else if (szDeviceFound > 1) {
|
||||
pnd = nfc_open (NULL, connstrings[1]);
|
||||
pnd = nfc_open(NULL, connstrings[1]);
|
||||
} else {
|
||||
printf("No device found.\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (argc > 1) {
|
||||
printf ("Usage: %s\n", argv[0]);
|
||||
printf("Usage: %s\n", argv[0]);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
|
|
@ -111,36 +111,36 @@ main (int argc, const char *argv[])
|
|||
printf("Unable to open NFC device.\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
printf ("NFC device: %s opened\n", nfc_device_get_name (pnd));
|
||||
printf("NFC device: %s opened\n", nfc_device_get_name(pnd));
|
||||
|
||||
signal (SIGINT, stop_dep_communication);
|
||||
signal(SIGINT, stop_dep_communication);
|
||||
|
||||
printf ("NFC device will now act as: ");
|
||||
print_nfc_target (nt, false);
|
||||
printf("NFC device will now act as: ");
|
||||
print_nfc_target(nt, false);
|
||||
|
||||
printf ("Waiting for initiator request...\n");
|
||||
if ((szRx = nfc_target_init (pnd, &nt, abtRx, sizeof(abtRx), 0)) < 0) {
|
||||
printf("Waiting for initiator request...\n");
|
||||
if ((szRx = nfc_target_init(pnd, &nt, abtRx, sizeof(abtRx), 0)) < 0) {
|
||||
nfc_perror(pnd, "nfc_target_init");
|
||||
goto error;
|
||||
}
|
||||
|
||||
printf("Initiator request received. Waiting for data...\n");
|
||||
if ((szRx = nfc_target_receive_bytes (pnd, abtRx, sizeof (abtRx), 0)) < 0) {
|
||||
if ((szRx = nfc_target_receive_bytes(pnd, abtRx, sizeof(abtRx), 0)) < 0) {
|
||||
nfc_perror(pnd, "nfc_target_receive_bytes");
|
||||
goto error;
|
||||
}
|
||||
abtRx[(size_t) szRx] = '\0';
|
||||
printf ("Received: %s\n", abtRx);
|
||||
printf("Received: %s\n", abtRx);
|
||||
|
||||
printf ("Sending: %s\n", abtTx);
|
||||
if (nfc_target_send_bytes (pnd, abtTx, sizeof(abtTx), 0) < 0) {
|
||||
printf("Sending: %s\n", abtTx);
|
||||
if (nfc_target_send_bytes(pnd, abtTx, sizeof(abtTx), 0) < 0) {
|
||||
nfc_perror(pnd, "nfc_target_send_bytes");
|
||||
goto error;
|
||||
}
|
||||
printf("Data sent.\n");
|
||||
|
||||
error:
|
||||
nfc_close (pnd);
|
||||
nfc_exit (NULL);
|
||||
nfc_close(pnd);
|
||||
nfc_exit(NULL);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -74,13 +74,13 @@
|
|||
static nfc_device *pnd;
|
||||
|
||||
static void
|
||||
stop_emulation (int sig)
|
||||
stop_emulation(int sig)
|
||||
{
|
||||
(void)sig;
|
||||
if (pnd) {
|
||||
nfc_abort_command(pnd);
|
||||
} else {
|
||||
exit (EXIT_FAILURE);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -112,14 +112,14 @@ static uint8_t __nfcforum_tag2_memory_area[] = {
|
|||
|
||||
#define HALT 0x50
|
||||
static int
|
||||
nfcforum_tag2_io (struct nfc_emulator *emulator, const uint8_t *data_in, const size_t data_in_len, uint8_t *data_out, const size_t data_out_len)
|
||||
nfcforum_tag2_io(struct nfc_emulator *emulator, const uint8_t *data_in, const size_t data_in_len, uint8_t *data_out, const size_t data_out_len)
|
||||
{
|
||||
int res = 0;
|
||||
|
||||
uint8_t *nfcforum_tag2_memory_area = (uint8_t *)(emulator->user_data);
|
||||
|
||||
printf (" In: ");
|
||||
print_hex (data_in, data_in_len);
|
||||
printf(" In: ");
|
||||
print_hex(data_in, data_in_len);
|
||||
|
||||
switch (data_in[0]) {
|
||||
case READ:
|
||||
|
|
@ -131,19 +131,19 @@ nfcforum_tag2_io (struct nfc_emulator *emulator, const uint8_t *data_in, const s
|
|||
}
|
||||
break;
|
||||
case HALT:
|
||||
printf ("HALT sent\n");
|
||||
printf("HALT sent\n");
|
||||
res = -ECONNABORTED;
|
||||
break;
|
||||
default:
|
||||
printf ("Unknown command: 0x%02x\n", data_in[0]);
|
||||
printf("Unknown command: 0x%02x\n", data_in[0]);
|
||||
res = -ENOTSUP;
|
||||
}
|
||||
|
||||
if (res < 0) {
|
||||
ERR ("%s (%d)", strerror (-res), -res);
|
||||
ERR("%s (%d)", strerror(-res), -res);
|
||||
} else {
|
||||
printf (" Out: ");
|
||||
print_hex (data_out, res);
|
||||
printf(" Out: ");
|
||||
print_hex(data_out, res);
|
||||
}
|
||||
|
||||
return res;
|
||||
|
|
@ -181,31 +181,31 @@ main(int argc, char *argv[])
|
|||
.user_data = __nfcforum_tag2_memory_area,
|
||||
};
|
||||
|
||||
signal (SIGINT, stop_emulation);
|
||||
nfc_init (NULL);
|
||||
pnd = nfc_open (NULL, NULL);
|
||||
signal(SIGINT, stop_emulation);
|
||||
nfc_init(NULL);
|
||||
pnd = nfc_open(NULL, NULL);
|
||||
|
||||
if (pnd == NULL) {
|
||||
ERR("Unable to open NFC device");
|
||||
exit (EXIT_FAILURE);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
printf ("NFC device: %s opened\n", nfc_device_get_name (pnd));
|
||||
printf ("Emulating NDEF tag now, please touch it with a second NFC device\n");
|
||||
printf("NFC device: %s opened\n", nfc_device_get_name(pnd));
|
||||
printf("Emulating NDEF tag now, please touch it with a second NFC device\n");
|
||||
|
||||
if (nfc_emulate_target (pnd, &emulator) < 0) {
|
||||
if (nfc_emulate_target(pnd, &emulator) < 0) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
nfc_close(pnd);
|
||||
nfc_exit (NULL);
|
||||
nfc_exit(NULL);
|
||||
|
||||
exit (EXIT_SUCCESS);
|
||||
exit(EXIT_SUCCESS);
|
||||
|
||||
error:
|
||||
if (pnd) {
|
||||
nfc_perror (pnd, argv[0]);
|
||||
nfc_close (pnd);
|
||||
nfc_exit (NULL);
|
||||
nfc_perror(pnd, argv[0]);
|
||||
nfc_close(pnd);
|
||||
nfc_exit(NULL);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -61,30 +61,30 @@ static bool quiet_output = false;
|
|||
static bool init_mfc_auth = false;
|
||||
|
||||
static void
|
||||
intr_hdlr (int sig)
|
||||
intr_hdlr(int sig)
|
||||
{
|
||||
(void) sig;
|
||||
printf ("\nQuitting...\n");
|
||||
printf("\nQuitting...\n");
|
||||
if (pnd != NULL) {
|
||||
nfc_close(pnd);
|
||||
}
|
||||
nfc_exit (NULL);
|
||||
exit (EXIT_FAILURE);
|
||||
nfc_exit(NULL);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
static bool
|
||||
target_io( nfc_target *pnt, const uint8_t *pbtInput, const size_t szInput, uint8_t *pbtOutput, size_t *pszOutput )
|
||||
target_io(nfc_target *pnt, const uint8_t *pbtInput, const size_t szInput, uint8_t *pbtOutput, size_t *pszOutput)
|
||||
{
|
||||
bool loop = true;
|
||||
*pszOutput = 0;
|
||||
|
||||
// Show transmitted command
|
||||
if (!quiet_output) {
|
||||
printf (" In: ");
|
||||
print_hex (pbtInput, szInput);
|
||||
printf(" In: ");
|
||||
print_hex(pbtInput, szInput);
|
||||
}
|
||||
if(szInput) {
|
||||
switch(pbtInput[0]) {
|
||||
if (szInput) {
|
||||
switch (pbtInput[0]) {
|
||||
case 0x30: // Mifare read
|
||||
// block address is in pbtInput[1]
|
||||
*pszOutput = 15;
|
||||
|
|
@ -110,7 +110,7 @@ target_io( nfc_target *pnt, const uint8_t *pbtInput, const size_t szInput, uint8
|
|||
// Send ATS
|
||||
*pszOutput = pnt->nti.nai.szAtsLen + 1;
|
||||
pbtOutput[0] = pnt->nti.nai.szAtsLen + 1; // ISO14443-4 says that ATS contains ATS_Length as first byte
|
||||
if(pnt->nti.nai.szAtsLen) {
|
||||
if (pnt->nti.nai.szAtsLen) {
|
||||
memcpy(pbtOutput + 1, pnt->nti.nai.abtAts, pnt->nti.nai.szAtsLen);
|
||||
}
|
||||
break;
|
||||
|
|
@ -129,8 +129,8 @@ target_io( nfc_target *pnt, const uint8_t *pbtInput, const size_t szInput, uint8
|
|||
}
|
||||
// Show transmitted command
|
||||
if ((!quiet_output) && *pszOutput) {
|
||||
printf (" Out: ");
|
||||
print_hex (pbtOutput, *pszOutput);
|
||||
printf(" Out: ");
|
||||
print_hex(pbtOutput, *pszOutput);
|
||||
}
|
||||
return loop;
|
||||
}
|
||||
|
|
@ -142,26 +142,26 @@ nfc_target_emulate_tag(nfc_device *dev, nfc_target *pnt)
|
|||
uint8_t abtTx[MAX_FRAME_LEN];
|
||||
bool loop = true;
|
||||
|
||||
if ((szRx = nfc_target_init (dev, pnt, abtRx, sizeof(abtRx), 0)) < 0) {
|
||||
nfc_perror (dev, "nfc_target_init");
|
||||
if ((szRx = nfc_target_init(dev, pnt, abtRx, sizeof(abtRx), 0)) < 0) {
|
||||
nfc_perror(dev, "nfc_target_init");
|
||||
return false;
|
||||
}
|
||||
|
||||
while ( loop ) {
|
||||
loop = target_io( pnt, abtRx, (size_t) szRx, abtTx, &szTx );
|
||||
while (loop) {
|
||||
loop = target_io(pnt, abtRx, (size_t) szRx, abtTx, &szTx);
|
||||
if (szTx) {
|
||||
if (nfc_target_send_bytes(dev, abtTx, szTx, 0) < 0) {
|
||||
nfc_perror (dev, "nfc_target_send_bytes");
|
||||
nfc_perror(dev, "nfc_target_send_bytes");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if ( loop ) {
|
||||
if ( init_mfc_auth ) {
|
||||
nfc_device_set_property_bool (dev, NP_HANDLE_CRC, false);
|
||||
if (loop) {
|
||||
if (init_mfc_auth) {
|
||||
nfc_device_set_property_bool(dev, NP_HANDLE_CRC, false);
|
||||
init_mfc_auth = false;
|
||||
}
|
||||
if ((szRx = nfc_target_receive_bytes(dev, abtRx, sizeof (abtRx), 0)) < 0) {
|
||||
nfc_perror (dev, "nfc_target_receive_bytes");
|
||||
if ((szRx = nfc_target_receive_bytes(dev, abtRx, sizeof(abtRx), 0)) < 0) {
|
||||
nfc_perror(dev, "nfc_target_receive_bytes");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -170,32 +170,32 @@ nfc_target_emulate_tag(nfc_device *dev, nfc_target *pnt)
|
|||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
(void) argc;
|
||||
const char *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_init (NULL);
|
||||
nfc_init(NULL);
|
||||
|
||||
// Try to open the NFC reader
|
||||
pnd = nfc_open (NULL, NULL);
|
||||
pnd = nfc_open(NULL, NULL);
|
||||
|
||||
// Display libnfc version
|
||||
acLibnfcVersion = nfc_version ();
|
||||
printf ("%s uses libnfc %s\n", argv[0], acLibnfcVersion);
|
||||
acLibnfcVersion = nfc_version();
|
||||
printf("%s uses libnfc %s\n", argv[0], acLibnfcVersion);
|
||||
|
||||
if (pnd == NULL) {
|
||||
ERR("Unable to open NFC device");
|
||||
exit (EXIT_FAILURE);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
printf ("NFC device: %s opened\n", nfc_device_get_name (pnd));
|
||||
printf("NFC device: %s opened\n", nfc_device_get_name(pnd));
|
||||
|
||||
// Notes for ISO14443-A emulated tags:
|
||||
// * Only short UIDs are supported
|
||||
|
|
@ -258,19 +258,19 @@ main (int argc, char *argv[])
|
|||
};
|
||||
*/
|
||||
|
||||
printf ("%s will emulate this ISO14443-A tag:\n", argv[0]);
|
||||
print_nfc_iso14443a_info (nt.nti.nai, true);
|
||||
printf("%s will emulate this ISO14443-A tag:\n", argv[0]);
|
||||
print_nfc_iso14443a_info(nt.nti.nai, true);
|
||||
|
||||
// Switch off NP_EASY_FRAMING if target is not ISO14443-4
|
||||
nfc_device_set_property_bool (pnd, NP_EASY_FRAMING, (nt.nti.nai.btSak & SAK_ISO14443_4_COMPLIANT));
|
||||
printf ("NFC device (configured as target) is now emulating the tag, please touch it with a second NFC device (initiator)\n");
|
||||
if (!nfc_target_emulate_tag (pnd, &nt)) {
|
||||
nfc_perror (pnd, "nfc_target_emulate_tag");
|
||||
exit (EXIT_FAILURE);
|
||||
nfc_device_set_property_bool(pnd, NP_EASY_FRAMING, (nt.nti.nai.btSak & SAK_ISO14443_4_COMPLIANT));
|
||||
printf("NFC device (configured as target) is now emulating the tag, please touch it with a second NFC device (initiator)\n");
|
||||
if (!nfc_target_emulate_tag(pnd, &nt)) {
|
||||
nfc_perror(pnd, "nfc_target_emulate_tag");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
nfc_close(pnd);
|
||||
nfc_exit (NULL);
|
||||
exit (EXIT_SUCCESS);
|
||||
nfc_exit(NULL);
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -66,28 +66,28 @@ uint8_t abtUidBcc[5] = { 0xDE, 0xAD, 0xBE, 0xEF, 0x62 };
|
|||
uint8_t abtSak[9] = { 0x08, 0xb6, 0xdd };
|
||||
|
||||
static void
|
||||
intr_hdlr (int sig)
|
||||
intr_hdlr(int sig)
|
||||
{
|
||||
(void) sig;
|
||||
if (pnd != NULL) {
|
||||
printf ("\nAborting current command...\n");
|
||||
nfc_abort_command (pnd);
|
||||
printf("\nAborting current command...\n");
|
||||
nfc_abort_command(pnd);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
print_usage (char *argv[])
|
||||
print_usage(char *argv[])
|
||||
{
|
||||
printf ("Usage: %s [OPTIONS] [UID]\n", argv[0]);
|
||||
printf ("Options:\n");
|
||||
printf ("\t-h\tHelp. Print this message.\n");
|
||||
printf ("\t-q\tQuiet mode. Silent output: received and sent frames will not be shown (improves timing).\n");
|
||||
printf ("\n");
|
||||
printf ("\t[UID]\tUID to emulate, specified as 8 HEX digits (default is DEADBEEF).\n");
|
||||
printf("Usage: %s [OPTIONS] [UID]\n", argv[0]);
|
||||
printf("Options:\n");
|
||||
printf("\t-h\tHelp. Print this message.\n");
|
||||
printf("\t-q\tQuiet mode. Silent output: received and sent frames will not be shown (improves timing).\n");
|
||||
printf("\n");
|
||||
printf("\t[UID]\tUID to emulate, specified as 8 HEX digits (default is DEADBEEF).\n");
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
uint8_t *pbtTx = NULL;
|
||||
size_t szTxBits;
|
||||
|
|
@ -98,49 +98,49 @@ main (int argc, char *argv[])
|
|||
|
||||
// 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);
|
||||
exit(EXIT_SUCCESS);
|
||||
} else if (0 == strcmp (argv[arg], "-q")) {
|
||||
printf ("Quiet mode.\n");
|
||||
} else if (0 == strcmp(argv[arg], "-q")) {
|
||||
printf("Quiet mode.\n");
|
||||
quiet_output = true;
|
||||
} else if ((arg == argc - 1) && (strlen (argv[arg]) == 8)) { // See if UID was specified as HEX string
|
||||
} else if ((arg == argc - 1) && (strlen(argv[arg]) == 8)) { // See if UID was specified as HEX string
|
||||
uint8_t abtTmp[3] = { 0x00, 0x00, 0x00 };
|
||||
printf ("[+] Using UID: %s\n", argv[arg]);
|
||||
printf("[+] Using UID: %s\n", argv[arg]);
|
||||
abtUidBcc[4] = 0x00;
|
||||
for (i = 0; i < 4; ++i) {
|
||||
memcpy (abtTmp, argv[arg] + i * 2, 2);
|
||||
abtUidBcc[i] = (uint8_t) strtol ((char *) abtTmp, NULL, 16);
|
||||
memcpy(abtTmp, argv[arg] + i * 2, 2);
|
||||
abtUidBcc[i] = (uint8_t) strtol((char *) abtTmp, NULL, 16);
|
||||
abtUidBcc[4] ^= abtUidBcc[i];
|
||||
}
|
||||
} else {
|
||||
ERR ("%s is not supported option.", argv[arg]);
|
||||
print_usage (argv);
|
||||
ERR("%s is not supported option.", argv[arg]);
|
||||
print_usage(argv);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
#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_init (NULL);
|
||||
nfc_init(NULL);
|
||||
|
||||
// Try to open the NFC device
|
||||
pnd = nfc_open (NULL, NULL);
|
||||
pnd = nfc_open(NULL, NULL);
|
||||
|
||||
if (pnd == NULL) {
|
||||
printf ("Unable to open NFC device\n");
|
||||
printf("Unable to open NFC device\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
printf ("\n");
|
||||
printf ("NFC device: %s opened\n", nfc_device_get_name (pnd));
|
||||
printf ("[+] Try to break out the auto-emulation, this requires a second NFC device!\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\" or \"nfc-list\" tool.\n");
|
||||
printf("\n");
|
||||
printf("NFC device: %s opened\n", nfc_device_get_name(pnd));
|
||||
printf("[+] Try to break out the auto-emulation, this requires a second NFC device!\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\" or \"nfc-list\" tool.\n");
|
||||
|
||||
// Note: We have to build a "fake" nfc_target in order to do exactly the same that was done before the new nfc_target_init() was introduced.
|
||||
nfc_target nt = {
|
||||
|
|
@ -158,24 +158,24 @@ main (int argc, char *argv[])
|
|||
},
|
||||
},
|
||||
};
|
||||
if ((szRecvBits = nfc_target_init (pnd, &nt, abtRecv, sizeof (abtRecv), 0)) < 0) {
|
||||
nfc_perror (pnd, "nfc_target_init");
|
||||
ERR ("Could not come out of auto-emulation, no command was received");
|
||||
if ((szRecvBits = nfc_target_init(pnd, &nt, abtRecv, sizeof(abtRecv), 0)) < 0) {
|
||||
nfc_perror(pnd, "nfc_target_init");
|
||||
ERR("Could not come out of auto-emulation, no command was received");
|
||||
goto error;
|
||||
}
|
||||
printf ("[+] Received initiator command: ");
|
||||
print_hex_bits (abtRecv, (size_t) szRecvBits);
|
||||
printf ("[+] Configuring communication\n");
|
||||
if ((nfc_device_set_property_bool (pnd, NP_HANDLE_CRC, false) < 0) || (nfc_device_set_property_bool (pnd, NP_HANDLE_PARITY, true) < 0)) {
|
||||
nfc_perror (pnd, "nfc_device_set_property_bool");
|
||||
exit (EXIT_FAILURE);
|
||||
printf("[+] Received initiator command: ");
|
||||
print_hex_bits(abtRecv, (size_t) szRecvBits);
|
||||
printf("[+] Configuring communication\n");
|
||||
if ((nfc_device_set_property_bool(pnd, NP_HANDLE_CRC, false) < 0) || (nfc_device_set_property_bool(pnd, NP_HANDLE_PARITY, true) < 0)) {
|
||||
nfc_perror(pnd, "nfc_device_set_property_bool");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
printf ("[+] Done, the emulated tag is initialized with UID: %02X%02X%02X%02X\n\n", abtUidBcc[0], abtUidBcc[1],
|
||||
abtUidBcc[2], abtUidBcc[3]);
|
||||
printf("[+] Done, the emulated tag is initialized with UID: %02X%02X%02X%02X\n\n", abtUidBcc[0], abtUidBcc[1],
|
||||
abtUidBcc[2], abtUidBcc[3]);
|
||||
|
||||
while (true) {
|
||||
// Test if we received a frame
|
||||
if ((szRecvBits = nfc_target_receive_bits (pnd, abtRecv, sizeof (abtRecv), 0)) > 0) {
|
||||
if ((szRecvBits = nfc_target_receive_bits(pnd, abtRecv, sizeof(abtRecv), 0)) > 0) {
|
||||
// Prepare the command to send back for the anti-collision request
|
||||
switch (szRecvBits) {
|
||||
case 7: // Request or Wakeup
|
||||
|
|
@ -183,7 +183,7 @@ main (int argc, char *argv[])
|
|||
szTxBits = 16;
|
||||
// New anti-collsion session started
|
||||
if (!quiet_output)
|
||||
printf ("\n");
|
||||
printf("\n");
|
||||
break;
|
||||
|
||||
case 16: // Select All
|
||||
|
|
@ -202,29 +202,29 @@ main (int argc, char *argv[])
|
|||
}
|
||||
|
||||
if (!quiet_output) {
|
||||
printf ("R: ");
|
||||
print_hex_bits (abtRecv, (size_t) szRecvBits);
|
||||
printf("R: ");
|
||||
print_hex_bits(abtRecv, (size_t) szRecvBits);
|
||||
}
|
||||
// Test if we know how to respond
|
||||
if (szTxBits) {
|
||||
// Send and print the command to the screen
|
||||
if (nfc_target_send_bits (pnd, pbtTx, szTxBits, NULL) < 0) {
|
||||
nfc_perror (pnd, "nfc_target_send_bits");
|
||||
if (nfc_target_send_bits(pnd, pbtTx, szTxBits, NULL) < 0) {
|
||||
nfc_perror(pnd, "nfc_target_send_bits");
|
||||
goto error;
|
||||
}
|
||||
if (!quiet_output) {
|
||||
printf ("T: ");
|
||||
print_hex_bits (pbtTx, szTxBits);
|
||||
printf("T: ");
|
||||
print_hex_bits(pbtTx, szTxBits);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
nfc_close (pnd);
|
||||
nfc_exit (NULL);
|
||||
exit (EXIT_SUCCESS);
|
||||
nfc_close(pnd);
|
||||
nfc_exit(NULL);
|
||||
exit(EXIT_SUCCESS);
|
||||
|
||||
error:
|
||||
nfc_close (pnd);
|
||||
nfc_exit (NULL);
|
||||
exit (EXIT_FAILURE);
|
||||
nfc_close(pnd);
|
||||
nfc_exit(NULL);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -87,21 +87,21 @@ uint8_t abtBlank[18] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x07, 0x80, 0
|
|||
|
||||
|
||||
static bool
|
||||
transmit_bits (const uint8_t *pbtTx, const size_t szTxBits)
|
||||
transmit_bits(const uint8_t *pbtTx, const size_t szTxBits)
|
||||
{
|
||||
// Show transmitted command
|
||||
if (!quiet_output) {
|
||||
printf ("Sent bits: ");
|
||||
print_hex_bits (pbtTx, szTxBits);
|
||||
printf("Sent bits: ");
|
||||
print_hex_bits(pbtTx, szTxBits);
|
||||
}
|
||||
// Transmit the bit frame command, we don't use the arbitrary parity feature
|
||||
if ((szRxBits = nfc_initiator_transceive_bits (pnd, pbtTx, szTxBits, NULL, abtRx, NULL)) < 0)
|
||||
if ((szRxBits = nfc_initiator_transceive_bits(pnd, pbtTx, szTxBits, NULL, abtRx, NULL)) < 0)
|
||||
return false;
|
||||
|
||||
// Show received answer
|
||||
if (!quiet_output) {
|
||||
printf ("Received bits: ");
|
||||
print_hex_bits (abtRx, szRxBits);
|
||||
printf("Received bits: ");
|
||||
print_hex_bits(abtRx, szRxBits);
|
||||
}
|
||||
// Succesful transfer
|
||||
return true;
|
||||
|
|
@ -109,43 +109,43 @@ transmit_bits (const uint8_t *pbtTx, const size_t szTxBits)
|
|||
|
||||
|
||||
static bool
|
||||
transmit_bytes (const uint8_t *pbtTx, const size_t szTx)
|
||||
transmit_bytes(const uint8_t *pbtTx, const size_t szTx)
|
||||
{
|
||||
// Show transmitted command
|
||||
if (!quiet_output) {
|
||||
printf ("Sent bits: ");
|
||||
print_hex (pbtTx, szTx);
|
||||
printf("Sent bits: ");
|
||||
print_hex(pbtTx, szTx);
|
||||
}
|
||||
int res;
|
||||
// Transmit the command bytes
|
||||
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;
|
||||
|
||||
// Show received answer
|
||||
if (!quiet_output) {
|
||||
printf ("Received bits: ");
|
||||
print_hex (abtRx, res);
|
||||
printf("Received bits: ");
|
||||
print_hex(abtRx, res);
|
||||
}
|
||||
// Succesful transfer
|
||||
return true;
|
||||
}
|
||||
|
||||
static void
|
||||
print_usage (char *argv[])
|
||||
print_usage(char *argv[])
|
||||
{
|
||||
printf ("Usage: %s [OPTIONS] [UID]\n", argv[0]);
|
||||
printf ("Options:\n");
|
||||
printf ("\t-h\tHelp. Print this message.\n");
|
||||
printf ("\t-f\tFormat. Delete all data (set to 0xFF) and reset ACLs to default.\n");
|
||||
printf ("\t-q\tQuiet mode. Suppress output of READER and CARD data (improves timing).\n");
|
||||
printf ("\n\tSpecify UID (4 HEX bytes) to set UID, or leave blank for default '01234567'.\n");
|
||||
printf ("\tThis utility can be used to recover cards that have been damaged by writing bad\n");
|
||||
printf ("\tdata (e.g. wrong BCC), thus making them non-selectable by most tools/readers.\n");
|
||||
printf ("\n\t*** Note: this utility only works with special Mifare 1K cards (Chinese clones).\n\n");
|
||||
printf("Usage: %s [OPTIONS] [UID]\n", argv[0]);
|
||||
printf("Options:\n");
|
||||
printf("\t-h\tHelp. Print this message.\n");
|
||||
printf("\t-f\tFormat. Delete all data (set to 0xFF) and reset ACLs to default.\n");
|
||||
printf("\t-q\tQuiet mode. Suppress output of READER and CARD data (improves timing).\n");
|
||||
printf("\n\tSpecify UID (4 HEX bytes) to set UID, or leave blank for default '01234567'.\n");
|
||||
printf("\tThis utility can be used to recover cards that have been damaged by writing bad\n");
|
||||
printf("\tdata (e.g. wrong BCC), thus making them non-selectable by most tools/readers.\n");
|
||||
printf("\n\t*** Note: this utility only works with special Mifare 1K cards (Chinese clones).\n\n");
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int arg, i;
|
||||
bool format = false;
|
||||
|
|
@ -155,73 +155,73 @@ main (int argc, char *argv[])
|
|||
|
||||
// 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);
|
||||
exit(EXIT_SUCCESS);
|
||||
} else if (0 == strcmp (argv[arg], "-f")) {
|
||||
} else if (0 == strcmp(argv[arg], "-f")) {
|
||||
format = true;
|
||||
} else if (0 == strcmp (argv[arg], "-q")) {
|
||||
} else if (0 == strcmp(argv[arg], "-q")) {
|
||||
quiet_output = true;
|
||||
} else if (strlen(argv[arg]) == 8) {
|
||||
for(i = 0 ; i < 4 ; ++i) {
|
||||
for (i = 0 ; i < 4 ; ++i) {
|
||||
memcpy(tmp, argv[arg] + i * 2, 2);
|
||||
sscanf(tmp, "%02x", &c);
|
||||
abtData[i] = (char) c;
|
||||
}
|
||||
abtData[4] = abtData[0] ^ abtData[1] ^ abtData[2] ^ abtData[3];
|
||||
iso14443a_crc_append (abtData, 16);
|
||||
iso14443a_crc_append(abtData, 16);
|
||||
} else {
|
||||
ERR ("%s is not supported option.", argv[arg]);
|
||||
print_usage (argv);
|
||||
ERR("%s is not supported option.", argv[arg]);
|
||||
print_usage(argv);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
nfc_init (NULL);
|
||||
nfc_init(NULL);
|
||||
|
||||
// Try to open the NFC reader
|
||||
pnd = nfc_open (NULL, NULL);
|
||||
pnd = nfc_open(NULL, NULL);
|
||||
|
||||
if (!pnd) {
|
||||
printf ("Error opening NFC reader\n");
|
||||
printf("Error opening NFC reader\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
// Initialise NFC device as "initiator"
|
||||
if (nfc_initiator_init (pnd) < 0) {
|
||||
nfc_perror (pnd, "nfc_initiator_init");
|
||||
exit (EXIT_FAILURE);
|
||||
if (nfc_initiator_init(pnd) < 0) {
|
||||
nfc_perror(pnd, "nfc_initiator_init");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
// Configure the CRC
|
||||
if (nfc_device_set_property_bool (pnd, NP_HANDLE_CRC, false) < 0) {
|
||||
nfc_perror (pnd, "nfc_device_set_property_bool");
|
||||
exit (EXIT_FAILURE);
|
||||
if (nfc_device_set_property_bool(pnd, NP_HANDLE_CRC, false) < 0) {
|
||||
nfc_perror(pnd, "nfc_device_set_property_bool");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
// Use raw send/receive methods
|
||||
if (nfc_device_set_property_bool (pnd, NP_EASY_FRAMING, false) < 0) {
|
||||
nfc_perror (pnd, "nfc_device_set_property_bool");
|
||||
exit (EXIT_FAILURE);
|
||||
if (nfc_device_set_property_bool(pnd, NP_EASY_FRAMING, false) < 0) {
|
||||
nfc_perror(pnd, "nfc_device_set_property_bool");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
// Disable 14443-4 autoswitching
|
||||
if (nfc_device_set_property_bool (pnd, NP_AUTO_ISO14443_4, false) < 0) {
|
||||
nfc_perror (pnd, "nfc_device_set_property_bool");
|
||||
exit (EXIT_FAILURE);
|
||||
if (nfc_device_set_property_bool(pnd, NP_AUTO_ISO14443_4, false) < 0) {
|
||||
nfc_perror(pnd, "nfc_device_set_property_bool");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
printf ("NFC reader: %s opened\n", nfc_device_get_name (pnd));
|
||||
printf("NFC reader: %s opened\n", nfc_device_get_name(pnd));
|
||||
|
||||
// Send the 7 bits request command specified in ISO 14443A (0x26)
|
||||
if (!transmit_bits (abtReqa, 7)) {
|
||||
printf ("Error: No tag available\n");
|
||||
nfc_close (pnd);
|
||||
nfc_exit (NULL);
|
||||
if (!transmit_bits(abtReqa, 7)) {
|
||||
printf("Error: No tag available\n");
|
||||
nfc_close(pnd);
|
||||
nfc_exit(NULL);
|
||||
return 1;
|
||||
}
|
||||
memcpy (abtAtqa, abtRx, 2);
|
||||
memcpy(abtAtqa, abtRx, 2);
|
||||
|
||||
// Anti-collision
|
||||
transmit_bytes (abtSelectAll, 2);
|
||||
transmit_bytes(abtSelectAll, 2);
|
||||
|
||||
// Check answer
|
||||
if ((abtRx[0] ^ abtRx[1] ^ abtRx[2] ^ abtRx[3] ^ abtRx[4]) != 0) {
|
||||
|
|
@ -229,12 +229,12 @@ main (int argc, char *argv[])
|
|||
}
|
||||
|
||||
// Save the UID CL1
|
||||
memcpy (abtRawUid, abtRx, 4);
|
||||
memcpy(abtRawUid, abtRx, 4);
|
||||
|
||||
//Prepare and send CL1 Select-Command
|
||||
memcpy (abtSelectTag + 2, abtRx, 5);
|
||||
iso14443a_crc_append (abtSelectTag, 7);
|
||||
transmit_bytes (abtSelectTag, 9);
|
||||
memcpy(abtSelectTag + 2, abtRx, 5);
|
||||
iso14443a_crc_append(abtSelectTag, 7);
|
||||
transmit_bytes(abtSelectTag, 9);
|
||||
abtSak = abtRx[0];
|
||||
|
||||
// Test if we are dealing with a CL2
|
||||
|
|
@ -246,14 +246,14 @@ main (int argc, char *argv[])
|
|||
}
|
||||
}
|
||||
|
||||
if(szCL == 2) {
|
||||
if (szCL == 2) {
|
||||
// We have to do the anti-collision for cascade level 2
|
||||
|
||||
// Prepare CL2 commands
|
||||
abtSelectAll[0] = 0x95;
|
||||
|
||||
// Anti-collision
|
||||
transmit_bytes (abtSelectAll, 2);
|
||||
transmit_bytes(abtSelectAll, 2);
|
||||
|
||||
// Check answer
|
||||
if ((abtRx[0] ^ abtRx[1] ^ abtRx[2] ^ abtRx[3] ^ abtRx[4]) != 0) {
|
||||
|
|
@ -261,13 +261,13 @@ main (int argc, char *argv[])
|
|||
}
|
||||
|
||||
// Save UID CL2
|
||||
memcpy (abtRawUid + 4, abtRx, 4);
|
||||
memcpy(abtRawUid + 4, abtRx, 4);
|
||||
|
||||
// Selection
|
||||
abtSelectTag[0] = 0x95;
|
||||
memcpy (abtSelectTag + 2, abtRx, 5);
|
||||
iso14443a_crc_append (abtSelectTag, 7);
|
||||
transmit_bytes (abtSelectTag, 9);
|
||||
memcpy(abtSelectTag + 2, abtRx, 5);
|
||||
iso14443a_crc_append(abtSelectTag, 7);
|
||||
transmit_bytes(abtSelectTag, 9);
|
||||
abtSak = abtRx[0];
|
||||
|
||||
// Test if we are dealing with a CL3
|
||||
|
|
@ -279,12 +279,12 @@ main (int argc, char *argv[])
|
|||
}
|
||||
}
|
||||
|
||||
if ( szCL == 3) {
|
||||
if (szCL == 3) {
|
||||
// We have to do the anti-collision for cascade level 3
|
||||
|
||||
// Prepare and send CL3 AC-Command
|
||||
abtSelectAll[0] = 0x97;
|
||||
transmit_bytes (abtSelectAll, 2);
|
||||
transmit_bytes(abtSelectAll, 2);
|
||||
|
||||
// Check answer
|
||||
if ((abtRx[0] ^ abtRx[1] ^ abtRx[2] ^ abtRx[3] ^ abtRx[4]) != 0) {
|
||||
|
|
@ -292,13 +292,13 @@ main (int argc, char *argv[])
|
|||
}
|
||||
|
||||
// Save UID CL3
|
||||
memcpy (abtRawUid + 8, abtRx, 4);
|
||||
memcpy(abtRawUid + 8, abtRx, 4);
|
||||
|
||||
// Prepare and send final Select-Command
|
||||
abtSelectTag[0] = 0x97;
|
||||
memcpy (abtSelectTag + 2, abtRx, 5);
|
||||
iso14443a_crc_append (abtSelectTag, 7);
|
||||
transmit_bytes (abtSelectTag, 9);
|
||||
memcpy(abtSelectTag + 2, abtRx, 5);
|
||||
iso14443a_crc_append(abtSelectTag, 7);
|
||||
transmit_bytes(abtSelectTag, 9);
|
||||
abtSak = abtRx[0];
|
||||
}
|
||||
}
|
||||
|
|
@ -308,52 +308,52 @@ main (int argc, char *argv[])
|
|||
iso_ats_supported = true;
|
||||
}
|
||||
|
||||
printf ("\nFound tag with\n UID: ");
|
||||
printf("\nFound tag with\n UID: ");
|
||||
switch (szCL) {
|
||||
case 1:
|
||||
printf ("%02x%02x%02x%02x", abtRawUid[0], abtRawUid[1], abtRawUid[2], abtRawUid[3]);
|
||||
printf("%02x%02x%02x%02x", abtRawUid[0], abtRawUid[1], abtRawUid[2], abtRawUid[3]);
|
||||
break;
|
||||
case 2:
|
||||
printf ("%02x%02x%02x", abtRawUid[1], abtRawUid[2], abtRawUid[3]);
|
||||
printf ("%02x%02x%02x%02x", abtRawUid[4], abtRawUid[5], abtRawUid[6], abtRawUid[7]);
|
||||
printf("%02x%02x%02x", abtRawUid[1], abtRawUid[2], abtRawUid[3]);
|
||||
printf("%02x%02x%02x%02x", abtRawUid[4], abtRawUid[5], abtRawUid[6], abtRawUid[7]);
|
||||
break;
|
||||
case 3:
|
||||
printf ("%02x%02x%02x", abtRawUid[1], abtRawUid[2], abtRawUid[3]);
|
||||
printf ("%02x%02x%02x", abtRawUid[5], abtRawUid[6], abtRawUid[7]);
|
||||
printf ("%02x%02x%02x%02x", abtRawUid[8], abtRawUid[9], abtRawUid[10], abtRawUid[11]);
|
||||
printf("%02x%02x%02x", abtRawUid[1], abtRawUid[2], abtRawUid[3]);
|
||||
printf("%02x%02x%02x", abtRawUid[5], abtRawUid[6], abtRawUid[7]);
|
||||
printf("%02x%02x%02x%02x", abtRawUid[8], abtRawUid[9], abtRawUid[10], abtRawUid[11]);
|
||||
break;
|
||||
}
|
||||
printf("\n");
|
||||
printf("ATQA: %02x%02x\n SAK: %02x\n", abtAtqa[1], abtAtqa[0], abtSak);
|
||||
if (szAts > 1) { // if = 1, it's not actual ATS but error code
|
||||
printf(" ATS: ");
|
||||
print_hex (abtAts, szAts);
|
||||
print_hex(abtAts, szAts);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
// now reset UID
|
||||
iso14443a_crc_append(abtHalt, 2);
|
||||
transmit_bytes (abtHalt, 4);
|
||||
transmit_bits (abtUnlock1, 7);
|
||||
if(format) {
|
||||
transmit_bytes (abtWipe, 1);
|
||||
transmit_bytes (abtHalt, 4);
|
||||
transmit_bits (abtUnlock1, 7);
|
||||
transmit_bytes(abtHalt, 4);
|
||||
transmit_bits(abtUnlock1, 7);
|
||||
if (format) {
|
||||
transmit_bytes(abtWipe, 1);
|
||||
transmit_bytes(abtHalt, 4);
|
||||
transmit_bits(abtUnlock1, 7);
|
||||
}
|
||||
transmit_bytes (abtUnlock2, 1);
|
||||
transmit_bytes (abtWrite, 4);
|
||||
transmit_bytes (abtData, 18);
|
||||
if(format) {
|
||||
for(i = 3 ; i < 64 ; i += 4) {
|
||||
transmit_bytes(abtUnlock2, 1);
|
||||
transmit_bytes(abtWrite, 4);
|
||||
transmit_bytes(abtData, 18);
|
||||
if (format) {
|
||||
for (i = 3 ; i < 64 ; i += 4) {
|
||||
abtWrite[1] = (char) i;
|
||||
iso14443a_crc_append (abtWrite, 2);
|
||||
transmit_bytes (abtWrite, 4);
|
||||
transmit_bytes (abtBlank, 18);
|
||||
iso14443a_crc_append(abtWrite, 2);
|
||||
transmit_bytes(abtWrite, 4);
|
||||
transmit_bytes(abtBlank, 18);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
nfc_close (pnd);
|
||||
nfc_exit (NULL);
|
||||
nfc_close(pnd);
|
||||
nfc_exit(NULL);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,39 +53,39 @@
|
|||
|
||||
static nfc_device *pnd = NULL;
|
||||
|
||||
static void stop_polling (int sig)
|
||||
static void stop_polling(int sig)
|
||||
{
|
||||
(void) sig;
|
||||
if (pnd)
|
||||
nfc_abort_command (pnd);
|
||||
nfc_abort_command(pnd);
|
||||
else
|
||||
exit (EXIT_FAILURE);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
static void
|
||||
print_usage (const char* progname)
|
||||
print_usage(const char* progname)
|
||||
{
|
||||
printf ("usage: %s [-v]\n", progname);
|
||||
printf (" -v\t verbose display\n");
|
||||
printf("usage: %s [-v]\n", progname);
|
||||
printf(" -v\t verbose display\n");
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, const char *argv[])
|
||||
main(int argc, const char *argv[])
|
||||
{
|
||||
bool verbose = false;
|
||||
|
||||
signal (SIGINT, stop_polling);
|
||||
signal(SIGINT, stop_polling);
|
||||
|
||||
// Display libnfc version
|
||||
const char *acLibnfcVersion = nfc_version ();
|
||||
const char *acLibnfcVersion = nfc_version();
|
||||
|
||||
printf ("%s uses libnfc %s\n", argv[0], acLibnfcVersion);
|
||||
printf("%s uses libnfc %s\n", argv[0], acLibnfcVersion);
|
||||
if (argc != 1) {
|
||||
if ((argc == 2) && (0 == strcmp ("-v", argv[1]))) {
|
||||
if ((argc == 2) && (0 == strcmp("-v", argv[1]))) {
|
||||
verbose = true;
|
||||
} else {
|
||||
print_usage (argv[0]);
|
||||
exit (EXIT_FAILURE);
|
||||
print_usage(argv[0]);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -103,35 +103,35 @@ main (int argc, const char *argv[])
|
|||
nfc_target nt;
|
||||
int res = 0;
|
||||
|
||||
nfc_init (NULL);
|
||||
nfc_init(NULL);
|
||||
|
||||
pnd = nfc_open (NULL, NULL);
|
||||
pnd = nfc_open(NULL, NULL);
|
||||
|
||||
if (pnd == NULL) {
|
||||
ERR ("%s", "Unable to open NFC device.");
|
||||
exit (EXIT_FAILURE);
|
||||
ERR("%s", "Unable to open NFC device.");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (nfc_initiator_init (pnd) < 0) {
|
||||
nfc_perror (pnd, "nfc_initiator_init");
|
||||
exit (EXIT_FAILURE);
|
||||
if (nfc_initiator_init(pnd) < 0) {
|
||||
nfc_perror(pnd, "nfc_initiator_init");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
printf ("NFC reader: %s opened\n", nfc_device_get_name (pnd));
|
||||
printf ("NFC device will poll during %ld ms (%u pollings of %lu ms for %zd modulations)\n", (unsigned long) uiPollNr * szModulations * uiPeriod * 150, uiPollNr, (unsigned long) uiPeriod * 150, szModulations);
|
||||
if ((res = nfc_initiator_poll_target (pnd, nmModulations, szModulations, uiPollNr, uiPeriod, &nt)) < 0) {
|
||||
nfc_perror (pnd, "nfc_initiator_poll_target");
|
||||
nfc_close (pnd);
|
||||
nfc_exit (NULL);
|
||||
exit (EXIT_FAILURE);
|
||||
printf("NFC reader: %s opened\n", nfc_device_get_name(pnd));
|
||||
printf("NFC device will poll during %ld ms (%u pollings of %lu ms for %zd modulations)\n", (unsigned long) uiPollNr * szModulations * uiPeriod * 150, uiPollNr, (unsigned long) uiPeriod * 150, szModulations);
|
||||
if ((res = nfc_initiator_poll_target(pnd, nmModulations, szModulations, uiPollNr, uiPeriod, &nt)) < 0) {
|
||||
nfc_perror(pnd, "nfc_initiator_poll_target");
|
||||
nfc_close(pnd);
|
||||
nfc_exit(NULL);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (res > 0) {
|
||||
print_nfc_target ( nt, verbose );
|
||||
print_nfc_target(nt, verbose);
|
||||
} else {
|
||||
printf ("No target found.\n");
|
||||
printf("No target found.\n");
|
||||
}
|
||||
nfc_close (pnd);
|
||||
nfc_exit (NULL);
|
||||
exit (EXIT_SUCCESS);
|
||||
nfc_close(pnd);
|
||||
nfc_exit(NULL);
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@
|
|||
#define MAX_DEVICE_COUNT 16
|
||||
|
||||
int
|
||||
main (int argc, const char *argv[])
|
||||
main(int argc, const char *argv[])
|
||||
{
|
||||
size_t i;
|
||||
nfc_device *pnd;
|
||||
|
|
@ -65,59 +65,59 @@ main (int argc, const char *argv[])
|
|||
const uint8_t pncmd_diagnose_ram_test[] = { Diagnose, 0x02 };
|
||||
|
||||
if (argc > 1) {
|
||||
errx (1, "usage: %s", argv[0]);
|
||||
errx(1, "usage: %s", argv[0]);
|
||||
}
|
||||
|
||||
nfc_init (NULL);
|
||||
nfc_init(NULL);
|
||||
|
||||
// Display libnfc version
|
||||
acLibnfcVersion = nfc_version ();
|
||||
printf ("%s uses libnfc %s\n", argv[0], acLibnfcVersion);
|
||||
acLibnfcVersion = nfc_version();
|
||||
printf("%s uses libnfc %s\n", argv[0], acLibnfcVersion);
|
||||
|
||||
nfc_connstring connstrings[MAX_DEVICE_COUNT];
|
||||
size_t szFound = nfc_list_devices (NULL, connstrings, MAX_DEVICE_COUNT);
|
||||
size_t szFound = nfc_list_devices(NULL, connstrings, MAX_DEVICE_COUNT);
|
||||
|
||||
if (szFound == 0) {
|
||||
printf ("No NFC device found.\n");
|
||||
printf("No NFC device found.\n");
|
||||
}
|
||||
|
||||
for (i = 0; i < szFound; i++) {
|
||||
pnd = nfc_open (NULL, connstrings[i]);
|
||||
pnd = nfc_open(NULL, connstrings[i]);
|
||||
|
||||
if (pnd == NULL) {
|
||||
ERR ("%s", "Unable to open NFC device.");
|
||||
ERR("%s", "Unable to open NFC device.");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
printf ("NFC device [%s] opened.\n", nfc_device_get_name (pnd));
|
||||
printf("NFC device [%s] opened.\n", nfc_device_get_name(pnd));
|
||||
|
||||
res = pn53x_transceive (pnd, pncmd_diagnose_communication_line_test, sizeof (pncmd_diagnose_communication_line_test), abtRx, szRx, 0);
|
||||
res = pn53x_transceive(pnd, pncmd_diagnose_communication_line_test, sizeof(pncmd_diagnose_communication_line_test), abtRx, szRx, 0);
|
||||
if (res > 0) {
|
||||
szRx = (size_t) res;
|
||||
// Result of Diagnose ping for RC-S360 doesn't contain status byte so we've to handle both cases
|
||||
result = (memcmp (pncmd_diagnose_communication_line_test + 1, abtRx, sizeof (pncmd_diagnose_communication_line_test) - 1) == 0) ||
|
||||
(memcmp (pncmd_diagnose_communication_line_test + 2, abtRx, sizeof (pncmd_diagnose_communication_line_test) - 2) == 0);
|
||||
printf (" Communication line test: %s\n", result ? "OK" : "Failed");
|
||||
result = (memcmp(pncmd_diagnose_communication_line_test + 1, abtRx, sizeof(pncmd_diagnose_communication_line_test) - 1) == 0) ||
|
||||
(memcmp(pncmd_diagnose_communication_line_test + 2, abtRx, sizeof(pncmd_diagnose_communication_line_test) - 2) == 0);
|
||||
printf(" Communication line test: %s\n", result ? "OK" : "Failed");
|
||||
} else {
|
||||
nfc_perror (pnd, "pn53x_transceive: cannot diagnose communication line");
|
||||
nfc_perror(pnd, "pn53x_transceive: cannot diagnose communication line");
|
||||
}
|
||||
|
||||
res = pn53x_transceive (pnd, pncmd_diagnose_rom_test, sizeof (pncmd_diagnose_rom_test), abtRx, szRx, 0);
|
||||
res = pn53x_transceive(pnd, pncmd_diagnose_rom_test, sizeof(pncmd_diagnose_rom_test), abtRx, szRx, 0);
|
||||
if (res > 0) {
|
||||
szRx = (size_t) res;
|
||||
result = ((szRx == 1) && (abtRx[0] == 0x00));
|
||||
printf (" ROM test: %s\n", result ? "OK" : "Failed");
|
||||
printf(" ROM test: %s\n", result ? "OK" : "Failed");
|
||||
} else {
|
||||
nfc_perror (pnd, "pn53x_transceive: cannot diagnose ROM");
|
||||
nfc_perror(pnd, "pn53x_transceive: cannot diagnose ROM");
|
||||
}
|
||||
|
||||
res = pn53x_transceive (pnd, pncmd_diagnose_ram_test, sizeof (pncmd_diagnose_ram_test), abtRx, szRx, 0);
|
||||
res = pn53x_transceive(pnd, pncmd_diagnose_ram_test, sizeof(pncmd_diagnose_ram_test), abtRx, szRx, 0);
|
||||
if (res > 0) {
|
||||
szRx = (size_t) res;
|
||||
result = ((szRx == 1) && (abtRx[0] == 0x00));
|
||||
printf (" RAM test: %s\n", result ? "OK" : "Failed");
|
||||
printf(" RAM test: %s\n", result ? "OK" : "Failed");
|
||||
} else {
|
||||
nfc_perror (pnd, "pn53x_transceive: cannot diagnose RAM");
|
||||
nfc_perror(pnd, "pn53x_transceive: cannot diagnose RAM");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,60 +52,60 @@
|
|||
#define TIMEOUT 60 // secs.
|
||||
|
||||
static void
|
||||
wait_one_minute (void)
|
||||
wait_one_minute(void)
|
||||
{
|
||||
int secs = 0;
|
||||
|
||||
printf ("|");
|
||||
fflush (stdout);
|
||||
printf("|");
|
||||
fflush(stdout);
|
||||
|
||||
while (secs < TIMEOUT) {
|
||||
sleep (1);
|
||||
sleep(1);
|
||||
secs++;
|
||||
printf (".");
|
||||
fflush (stdout);
|
||||
printf(".");
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
printf ("|\n");
|
||||
printf("|\n");
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, const char *argv[])
|
||||
main(int argc, const char *argv[])
|
||||
{
|
||||
(void) argc;
|
||||
(void) argv;
|
||||
|
||||
int ret = EXIT_FAILURE;
|
||||
|
||||
nfc_init (NULL);
|
||||
nfc_init(NULL);
|
||||
|
||||
// Display libnfc version
|
||||
const char *acLibnfcVersion = nfc_version ();
|
||||
printf ("%s uses libnfc %s\n", argv[0], acLibnfcVersion);
|
||||
const char *acLibnfcVersion = nfc_version();
|
||||
printf("%s uses libnfc %s\n", argv[0], acLibnfcVersion);
|
||||
|
||||
// Open using the first available NFC device
|
||||
nfc_device *pnd;
|
||||
pnd = nfc_open (NULL, NULL);
|
||||
pnd = nfc_open(NULL, NULL);
|
||||
|
||||
if (pnd == NULL) {
|
||||
ERR ("%s", "Unable to open NFC device.");
|
||||
ERR("%s", "Unable to open NFC device.");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
printf ("NFC device: %s opened\n", nfc_device_get_name (pnd));
|
||||
printf("NFC device: %s opened\n", nfc_device_get_name(pnd));
|
||||
|
||||
// Print the example's menu
|
||||
printf ("\nSelect the communication mode:\n");
|
||||
printf ("[1] Virtual card mode.\n");
|
||||
printf ("[2] Wired card mode.\n");
|
||||
printf ("[3] Dual card mode.\n");
|
||||
printf (">> ");
|
||||
printf("\nSelect the communication mode:\n");
|
||||
printf("[1] Virtual card mode.\n");
|
||||
printf("[2] Wired card mode.\n");
|
||||
printf("[3] Dual card mode.\n");
|
||||
printf(">> ");
|
||||
|
||||
// Take user's choice
|
||||
char input = getchar ();
|
||||
printf ("\n");
|
||||
char input = getchar();
|
||||
printf("\n");
|
||||
if ((input < '1') || (input > '3')) {
|
||||
ERR ("%s", "Invalid selection.");
|
||||
ERR("%s", "Invalid selection.");
|
||||
goto error;
|
||||
}
|
||||
|
||||
|
|
@ -119,15 +119,15 @@ main (int argc, const char *argv[])
|
|||
|
||||
// Connect with the SAM
|
||||
// FIXME: Its a private pn53x function
|
||||
if (pn53x_SAMConfiguration (pnd, mode, 0) < 0) {
|
||||
nfc_perror (pnd, "pn53x_SAMConfiguration");
|
||||
if (pn53x_SAMConfiguration(pnd, mode, 0) < 0) {
|
||||
nfc_perror(pnd, "pn53x_SAMConfiguration");
|
||||
goto error;
|
||||
}
|
||||
|
||||
switch (mode) {
|
||||
case PSM_VIRTUAL_CARD: {
|
||||
printf ("Now the SAM is readable for 1 minute from an external reader.\n");
|
||||
wait_one_minute ();
|
||||
printf("Now the SAM is readable for 1 minute from an external reader.\n");
|
||||
wait_one_minute();
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
@ -135,14 +135,14 @@ main (int argc, const char *argv[])
|
|||
nfc_target nt;
|
||||
|
||||
// Set opened NFC device to initiator mode
|
||||
if (nfc_initiator_init (pnd) < 0) {
|
||||
nfc_perror (pnd, "nfc_initiator_init");
|
||||
if (nfc_initiator_init(pnd) < 0) {
|
||||
nfc_perror(pnd, "nfc_initiator_init");
|
||||
goto error;
|
||||
}
|
||||
|
||||
// Let the reader only try once to find a tag
|
||||
if (nfc_device_set_property_bool (pnd, NP_INFINITE_SELECT, false) < 0) {
|
||||
nfc_perror (pnd, "nfc_device_set_property_bool");
|
||||
if (nfc_device_set_property_bool(pnd, NP_INFINITE_SELECT, false) < 0) {
|
||||
nfc_perror(pnd, "nfc_device_set_property_bool");
|
||||
goto error;
|
||||
}
|
||||
// Read the SAM's info
|
||||
|
|
@ -151,17 +151,17 @@ main (int argc, const char *argv[])
|
|||
.nbr = NBR_106,
|
||||
};
|
||||
int res;
|
||||
if ((res = nfc_initiator_select_passive_target (pnd, nmSAM, NULL, 0, &nt)) < 0) {
|
||||
nfc_perror (pnd, "nfc_initiator_select_passive_target");
|
||||
if ((res = nfc_initiator_select_passive_target(pnd, nmSAM, NULL, 0, &nt)) < 0) {
|
||||
nfc_perror(pnd, "nfc_initiator_select_passive_target");
|
||||
goto error;
|
||||
} else if (res == 0) {
|
||||
ERR ("No SAM found.");
|
||||
ERR("No SAM found.");
|
||||
goto error;
|
||||
} else if (res == 1) {
|
||||
printf ("The following ISO14443A tag (SAM) was found:\n");
|
||||
print_nfc_iso14443a_info (nt.nti.nai, true);
|
||||
printf("The following ISO14443A tag (SAM) was found:\n");
|
||||
print_nfc_iso14443a_info(nt.nti.nai, true);
|
||||
} else {
|
||||
ERR ("%s", "More than one ISO14442 tag found as SAM.");
|
||||
ERR("%s", "More than one ISO14442 tag found as SAM.");
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
|
|
@ -185,9 +185,9 @@ main (int argc, const char *argv[])
|
|||
},
|
||||
},
|
||||
};
|
||||
printf ("Now both, NFC device (configured as target) and SAM are readables from an external NFC initiator.\n");
|
||||
printf ("Please note that NFC device (configured as target) stay in target mode until it receive RATS, ATR_REQ or proprietary command.\n");
|
||||
if (nfc_target_init (pnd, &nt, abtRx, sizeof(abtRx), 0) < 0) {
|
||||
printf("Now both, NFC device (configured as target) and SAM are readables from an external NFC initiator.\n");
|
||||
printf("Please note that NFC device (configured as target) stay in target mode until it receive RATS, ATR_REQ or proprietary command.\n");
|
||||
if (nfc_target_init(pnd, &nt, abtRx, sizeof(abtRx), 0) < 0) {
|
||||
nfc_perror(pnd, "nfc_target_init");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
|
@ -201,11 +201,11 @@ main (int argc, const char *argv[])
|
|||
|
||||
error:
|
||||
// Disconnect from the SAM
|
||||
pn53x_SAMConfiguration (pnd, PSM_NORMAL, 0);
|
||||
pn53x_SAMConfiguration(pnd, PSM_NORMAL, 0);
|
||||
|
||||
// Close NFC device
|
||||
nfc_close (pnd);
|
||||
nfc_exit (NULL);
|
||||
nfc_close(pnd);
|
||||
nfc_exit(NULL);
|
||||
|
||||
exit (ret);
|
||||
exit(ret);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -77,31 +77,31 @@ int main(int argc, const char* argv[])
|
|||
FILE* input = NULL;
|
||||
|
||||
if (argc >= 2) {
|
||||
if((input = fopen(argv[1], "r")) == NULL) {
|
||||
ERR ("%s", "Cannot open file.");
|
||||
if ((input = fopen(argv[1], "r")) == NULL) {
|
||||
ERR("%s", "Cannot open file.");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
nfc_init (NULL);
|
||||
nfc_init(NULL);
|
||||
|
||||
// Try to open the NFC reader
|
||||
pnd = nfc_open(NULL, NULL);
|
||||
|
||||
if (pnd == NULL) {
|
||||
ERR ("%s", "Unable to open NFC device.");
|
||||
ERR("%s", "Unable to open NFC device.");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
printf ("NFC reader: %s opened\n", nfc_device_get_name (pnd));
|
||||
if (nfc_initiator_init (pnd) < 0) {
|
||||
nfc_perror (pnd, "nfc_initiator_init");
|
||||
exit (EXIT_FAILURE);
|
||||
printf("NFC reader: %s opened\n", nfc_device_get_name(pnd));
|
||||
if (nfc_initiator_init(pnd) < 0) {
|
||||
nfc_perror(pnd, "nfc_initiator_init");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
char *cmd;
|
||||
const char *prompt = "> ";
|
||||
while(1) {
|
||||
while (1) {
|
||||
int offset = 0;
|
||||
#if defined(HAVE_READLINE)
|
||||
if (input == NULL) { // means we use stdin
|
||||
|
|
@ -154,14 +154,14 @@ int main(int argc, const char* argv[])
|
|||
continue;
|
||||
}
|
||||
szTx = 0;
|
||||
for(int i = 0; i < MAX_FRAME_LEN - 10; i++) {
|
||||
for (int i = 0; i < MAX_FRAME_LEN - 10; i++) {
|
||||
int size;
|
||||
unsigned int byte;
|
||||
while (isspace(cmd[offset])) {
|
||||
offset++;
|
||||
}
|
||||
size = sscanf(cmd + offset, "%2x", &byte);
|
||||
if (size < 1 ) {
|
||||
if (size < 1) {
|
||||
break;
|
||||
}
|
||||
abtTx[i] = byte;
|
||||
|
|
@ -181,9 +181,9 @@ int main(int argc, const char* argv[])
|
|||
|
||||
szRx = sizeof(abtRx);
|
||||
int res = 0;
|
||||
if ((res = pn53x_transceive (pnd, abtTx, szTx, abtRx, szRx, 0)) < 0) {
|
||||
if ((res = pn53x_transceive(pnd, abtTx, szTx, abtRx, szRx, 0)) < 0) {
|
||||
free(cmd);
|
||||
nfc_perror (pnd, "Rx");
|
||||
nfc_perror(pnd, "Rx");
|
||||
continue;
|
||||
}
|
||||
szRx = (size_t) res;
|
||||
|
|
@ -197,6 +197,6 @@ int main(int argc, const char* argv[])
|
|||
fclose(input);
|
||||
}
|
||||
nfc_close(pnd);
|
||||
nfc_exit (NULL);
|
||||
nfc_exit(NULL);
|
||||
return 1;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue