Indent whole code using make indent. (Fixes issue 84).
This commit is contained in:
parent
f93b4939f4
commit
18cc86a613
42 changed files with 2613 additions and 2479 deletions
|
|
@ -23,7 +23,7 @@
|
|||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
# include "config.h"
|
||||
#endif // HAVE_CONFIG_H
|
||||
|
||||
#include <stdio.h>
|
||||
|
|
@ -47,152 +47,143 @@ static size_t szRxBits;
|
|||
static size_t szRxLen;
|
||||
static byte_t abtUid[10];
|
||||
static size_t szUidLen = 4;
|
||||
static nfc_device_t* pnd;
|
||||
static nfc_device_t *pnd;
|
||||
|
||||
bool quiet_output = false;
|
||||
bool quiet_output = false;
|
||||
|
||||
// ISO14443A Anti-Collision Commands
|
||||
byte_t abtReqa [1] = { 0x26 };
|
||||
byte_t abtSelectAll [2] = { 0x93,0x20 };
|
||||
byte_t abtSelectTag [9] = { 0x93,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00 };
|
||||
byte_t abtRats [4] = { 0xe0,0x50,0xbc,0xa5 };
|
||||
byte_t abtHalt [4] = { 0x50,0x00,0x57,0xcd };
|
||||
byte_t abtReqa[1] = { 0x26 };
|
||||
byte_t abtSelectAll[2] = { 0x93, 0x20 };
|
||||
byte_t abtSelectTag[9] = { 0x93, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
byte_t abtRats[4] = { 0xe0, 0x50, 0xbc, 0xa5 };
|
||||
byte_t abtHalt[4] = { 0x50, 0x00, 0x57, 0xcd };
|
||||
|
||||
static bool transmit_bits(const byte_t* pbtTx, const size_t szTxBits)
|
||||
static bool
|
||||
transmit_bits (const byte_t * pbtTx, const size_t szTxBits)
|
||||
{
|
||||
// Show transmitted command
|
||||
if(!quiet_output)
|
||||
{
|
||||
printf("R: ");
|
||||
print_hex_bits(pbtTx,szTxBits);
|
||||
if (!quiet_output) {
|
||||
printf ("R: ");
|
||||
print_hex_bits (pbtTx, szTxBits);
|
||||
}
|
||||
|
||||
// Transmit the bit frame command, we don't use the arbitrary parity feature
|
||||
if (!nfc_initiator_transceive_bits(pnd,pbtTx,szTxBits,NULL,abtRx,&szRxBits,NULL)) return false;
|
||||
if (!nfc_initiator_transceive_bits (pnd, pbtTx, szTxBits, NULL, abtRx, &szRxBits, NULL))
|
||||
return false;
|
||||
|
||||
// Show received answer
|
||||
if(!quiet_output)
|
||||
{
|
||||
printf("T: ");
|
||||
print_hex_bits(abtRx,szRxBits);
|
||||
if (!quiet_output) {
|
||||
printf ("T: ");
|
||||
print_hex_bits (abtRx, szRxBits);
|
||||
}
|
||||
|
||||
// Succesful transfer
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
static bool transmit_bytes(const byte_t* pbtTx, const size_t szTxLen)
|
||||
static bool
|
||||
transmit_bytes (const byte_t * pbtTx, const size_t szTxLen)
|
||||
{
|
||||
// Show transmitted command
|
||||
if(!quiet_output)
|
||||
{
|
||||
printf("R: ");
|
||||
print_hex(pbtTx,szTxLen);
|
||||
if (!quiet_output) {
|
||||
printf ("R: ");
|
||||
print_hex (pbtTx, szTxLen);
|
||||
}
|
||||
|
||||
// Transmit the command bytes
|
||||
if (!nfc_initiator_transceive_bytes(pnd,pbtTx,szTxLen,abtRx,&szRxLen)) return false;
|
||||
if (!nfc_initiator_transceive_bytes (pnd, pbtTx, szTxLen, abtRx, &szRxLen))
|
||||
return false;
|
||||
|
||||
// Show received answer
|
||||
if(!quiet_output)
|
||||
{
|
||||
printf("T: ");
|
||||
print_hex(abtRx,szRxLen);
|
||||
if (!quiet_output) {
|
||||
printf ("T: ");
|
||||
print_hex (abtRx, szRxLen);
|
||||
}
|
||||
|
||||
// Succesful transfer
|
||||
return true;
|
||||
}
|
||||
|
||||
static void print_usage(char* argv[])
|
||||
static void
|
||||
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[])
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
int arg;
|
||||
int arg;
|
||||
|
||||
// Get commandline options
|
||||
for (arg=1;arg<argc;arg++) {
|
||||
if (0 == strcmp(argv[arg], "-h")) {
|
||||
print_usage(argv);
|
||||
for (arg = 1; arg < argc; arg++) {
|
||||
if (0 == strcmp (argv[arg], "-h")) {
|
||||
print_usage (argv);
|
||||
return 0;
|
||||
} else if (0 == strcmp(argv[arg], "-q")) {
|
||||
INFO("%s", "Quiet mode.");
|
||||
} else if (0 == strcmp (argv[arg], "-q")) {
|
||||
INFO ("%s", "Quiet mode.");
|
||||
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 -1;
|
||||
}
|
||||
}
|
||||
|
||||
// Try to open the NFC reader
|
||||
pnd = nfc_connect(NULL);
|
||||
pnd = nfc_connect (NULL);
|
||||
|
||||
if (!pnd)
|
||||
{
|
||||
printf("Error connecting NFC reader\n");
|
||||
if (!pnd) {
|
||||
printf ("Error connecting NFC reader\n");
|
||||
return 1;
|
||||
}
|
||||
nfc_initiator_init(pnd);
|
||||
nfc_initiator_init (pnd);
|
||||
|
||||
// Drop the field for a while
|
||||
if (!nfc_configure(pnd,NDO_ACTIVATE_FIELD,false)) {
|
||||
if (!nfc_configure (pnd, NDO_ACTIVATE_FIELD, false)) {
|
||||
nfc_perror (pnd, "nfc_configure");
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
// Configure the CRC
|
||||
if (!nfc_configure(pnd,NDO_HANDLE_CRC,false)) {
|
||||
if (!nfc_configure (pnd, NDO_HANDLE_CRC, false)) {
|
||||
nfc_perror (pnd, "nfc_configure");
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
// Configure parity settings
|
||||
if (!nfc_configure(pnd,NDO_HANDLE_PARITY,true)) {
|
||||
if (!nfc_configure (pnd, NDO_HANDLE_PARITY, true)) {
|
||||
nfc_perror (pnd, "nfc_configure");
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
// Enable field so more power consuming cards can power themselves up
|
||||
if (!nfc_configure(pnd,NDO_ACTIVATE_FIELD,true)) {
|
||||
if (!nfc_configure (pnd, NDO_ACTIVATE_FIELD, true)) {
|
||||
nfc_perror (pnd, "nfc_configure");
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (!nfc_configure(pnd, NDO_EASY_FRAMING, false)) {
|
||||
nfc_perror (pnd, "nfc_configure");
|
||||
exit (EXIT_FAILURE);
|
||||
if (!nfc_configure (pnd, NDO_EASY_FRAMING, false)) {
|
||||
nfc_perror (pnd, "nfc_configure");
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
printf("\nConnected to NFC reader: %s\n\n",pnd->acName);
|
||||
printf ("\nConnected to NFC reader: %s\n\n", pnd->acName);
|
||||
|
||||
// Send the 7 bits request command specified in ISO 14443A (0x26)
|
||||
if (!transmit_bits(abtReqa,7))
|
||||
{
|
||||
printf("Error: No tag available\n");
|
||||
nfc_disconnect(pnd);
|
||||
if (!transmit_bits (abtReqa, 7)) {
|
||||
printf ("Error: No tag available\n");
|
||||
nfc_disconnect (pnd);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Anti-collision
|
||||
transmit_bytes(abtSelectAll,2);
|
||||
transmit_bytes (abtSelectAll, 2);
|
||||
|
||||
// Save the UID
|
||||
memcpy(abtUid,abtRx,4);
|
||||
memcpy(abtSelectTag+2,abtRx,5);
|
||||
append_iso14443a_crc(abtSelectTag,7);
|
||||
transmit_bytes(abtSelectTag,9);
|
||||
memcpy (abtUid, abtRx, 4);
|
||||
memcpy (abtSelectTag + 2, abtRx, 5);
|
||||
append_iso14443a_crc (abtSelectTag, 7);
|
||||
transmit_bytes (abtSelectTag, 9);
|
||||
|
||||
// Test if we are dealing with a 4 bytes uid
|
||||
if (abtUid[0]!= 0x88)
|
||||
{
|
||||
if (abtUid[0] != 0x88) {
|
||||
szUidLen = 4;
|
||||
} else {
|
||||
// We have to do the anti-collision for cascade level 2
|
||||
|
|
@ -200,28 +191,29 @@ int main(int argc,char* argv[])
|
|||
abtSelectTag[0] = 0x95;
|
||||
|
||||
// Anti-collision
|
||||
transmit_bytes(abtSelectAll,2);
|
||||
transmit_bytes (abtSelectAll, 2);
|
||||
|
||||
// Save the UID
|
||||
memcpy(abtUid+4,abtRx,4);
|
||||
memcpy(abtSelectTag+2,abtRx,5);
|
||||
append_iso14443a_crc(abtSelectTag,7);
|
||||
transmit_bytes(abtSelectTag,9);
|
||||
memcpy (abtUid + 4, abtRx, 4);
|
||||
memcpy (abtSelectTag + 2, abtRx, 5);
|
||||
append_iso14443a_crc (abtSelectTag, 7);
|
||||
transmit_bytes (abtSelectTag, 9);
|
||||
szUidLen = 7;
|
||||
}
|
||||
|
||||
// Request ATS, this only applies to tags that support ISO 14443A-4
|
||||
if (abtRx[0] & SAK_FLAG_ATS_SUPPORTED) transmit_bytes(abtRats,4);
|
||||
if (abtRx[0] & SAK_FLAG_ATS_SUPPORTED)
|
||||
transmit_bytes (abtRats, 4);
|
||||
|
||||
// Done, halt the tag now
|
||||
transmit_bytes(abtHalt,4);
|
||||
transmit_bytes (abtHalt, 4);
|
||||
|
||||
printf("\nFound tag with UID: ");
|
||||
printf ("\nFound tag with UID: ");
|
||||
if (szUidLen == 7) {
|
||||
printf("%02x%02x%02x", abtUid[6], abtUid[5], abtUid[4]);
|
||||
printf ("%02x%02x%02x", abtUid[6], abtUid[5], abtUid[4]);
|
||||
}
|
||||
printf("%02x%02x%02x%02x\n", abtUid[3], abtUid[2], abtUid[1], abtUid[0]);
|
||||
printf ("%02x%02x%02x%02x\n", abtUid[3], abtUid[2], abtUid[1], abtUid[0]);
|
||||
|
||||
nfc_disconnect(pnd);
|
||||
nfc_disconnect (pnd);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue