Merge the libnfc-less-bitutils-more-ponies branch into trunk.
This commit is contained in:
commit
b28abd77b0
23 changed files with 330 additions and 65 deletions
|
|
@ -18,7 +18,8 @@ nfc_poll_LDADD = $(top_builddir)/libnfc/libnfc.la \
|
|||
$(top_builddir)/examples/libnfcutils.a
|
||||
|
||||
nfc_anticol_SOURCES = nfc-anticol.c
|
||||
nfc_anticol_LDADD = $(top_builddir)/libnfc/libnfc.la
|
||||
nfc_anticol_LDADD = $(top_builddir)/libnfc/libnfc.la \
|
||||
$(top_builddir)/examples/libnfcutils.a
|
||||
|
||||
nfc_list_SOURCES = nfc-list.c
|
||||
nfc_list_LDADD = $(top_builddir)/libnfc/libnfc.la \
|
||||
|
|
@ -31,10 +32,12 @@ nfc_mfclassic_SOURCES = nfc-mfclassic.c mifaretag.h
|
|||
nfc_mfclassic_LDADD = $(top_builddir)/libnfc/libnfc.la
|
||||
|
||||
nfc_relay_SOURCES = nfc-relay.c
|
||||
nfc_relay_LDADD = $(top_builddir)/libnfc/libnfc.la
|
||||
nfc_relay_LDADD = $(top_builddir)/libnfc/libnfc.la \
|
||||
$(top_builddir)/examples/libnfcutils.a
|
||||
|
||||
nfc_emulate_SOURCES = nfc-emulate.c
|
||||
nfc_emulate_LDADD = $(top_builddir)/libnfc/libnfc.la
|
||||
nfc_emulate_LDADD = $(top_builddir)/libnfc/libnfc.la \
|
||||
$(top_builddir)/examples/libnfcutils.a
|
||||
|
||||
nfcip_target_SOURCES = nfcip-target.c
|
||||
nfcip_target_LDADD = $(top_builddir)/libnfc/libnfc.la
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@
|
|||
#include <nfc/nfc.h>
|
||||
|
||||
#include <nfc/nfc-messages.h>
|
||||
#include "bitutils.h"
|
||||
#include "nfc-utils.h"
|
||||
|
||||
#define SAK_FLAG_ATS_SUPPORTED 0x20
|
||||
|
||||
|
|
@ -198,12 +198,10 @@ int main(int argc,char* argv[])
|
|||
transmit_bytes(abtHalt,4);
|
||||
|
||||
printf("\nFound tag with UID: ");
|
||||
if (szUidLen == 4)
|
||||
{
|
||||
printf("%08x\n",swap_endian32(abtUid));
|
||||
} else {
|
||||
printf("%014llx\n",swap_endian64(abtUid)&0x00ffffffffffffffull);
|
||||
if (szUidLen == 7) {
|
||||
printf("%02x%02x%02x", abtUid[6], abtUid[5], abtUid[4]);
|
||||
}
|
||||
printf("%02x%02x%02x%02x\n", abtUid[3], abtUid[2], abtUid[1], abtUid[0]);
|
||||
|
||||
nfc_disconnect(pnd);
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@
|
|||
#include <nfc/nfc.h>
|
||||
|
||||
#include <nfc/nfc-messages.h>
|
||||
#include "bitutils.h"
|
||||
#include "nfc-utils.h"
|
||||
|
||||
#define MAX_FRAME_LEN 264
|
||||
|
||||
|
|
|
|||
|
|
@ -42,7 +42,6 @@
|
|||
#include <nfc/nfc.h>
|
||||
#include <nfc/nfc-messages.h>
|
||||
#include "nfc-utils.h"
|
||||
#include "bitutils.h"
|
||||
|
||||
#define MAX_DEVICE_COUNT 16
|
||||
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@
|
|||
#include <nfc/nfc.h>
|
||||
|
||||
#include "mifaretag.h"
|
||||
#include "bitutils.h"
|
||||
#include "nfc-utils.h"
|
||||
|
||||
static nfc_device_t* pnd;
|
||||
static nfc_target_info_t nti;
|
||||
|
|
@ -464,14 +464,14 @@ int main(int argc, const char* argv[])
|
|||
// Compare if key dump UID is the same as the current tag UID
|
||||
if (memcmp(nti.nai.abtUid,pbtUID,4) != 0)
|
||||
{
|
||||
printf("Expected MIFARE Classic %cK card with UID: %08x\n",b4K?'4':'1',swap_endian32(pbtUID));
|
||||
printf("Expected MIFARE Classic %cK card with UID: %02x%02x%02x%02x\n",b4K?'4':'1', pbtUID[3], pbtUID[2], pbtUID[1], pbtUID[0]);
|
||||
}
|
||||
}
|
||||
|
||||
// Get the info from the current tag
|
||||
pbtUID = nti.nai.abtUid;
|
||||
b4K = (nti.nai.abtAtqa[1] == 0x02);
|
||||
printf("Found MIFARE Classic %cK card with UID: %08x\n",b4K?'4':'1',swap_endian32(pbtUID));
|
||||
printf("Found MIFARE Classic %cK card with UID: %02x%02x%02x%02x\n",b4K?'4':'1', pbtUID[3], pbtUID[2], pbtUID[1], pbtUID[0]);
|
||||
|
||||
uiBlocks = (b4K)?0xff:0x3f;
|
||||
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@
|
|||
#include <nfc/nfc.h>
|
||||
|
||||
#include "mifareultag.h"
|
||||
#include "bitutils.h"
|
||||
#include "nfc-utils.h"
|
||||
|
||||
static nfc_device_t* pnd;
|
||||
static nfc_target_info_t nti;
|
||||
|
|
@ -215,9 +215,9 @@ int main(int argc, const char* argv[])
|
|||
}
|
||||
|
||||
|
||||
// Get the info from the current tag
|
||||
// Get the info from the current tag (UID is stored little-endian)
|
||||
pbtUID = nti.nai.abtUid;
|
||||
printf("Found MIFARE Ultralight card with uid: %08x\n", swap_endian32(pbtUID));
|
||||
printf("Found MIFARE Ultralight card with uid: %02x%02x%02x%02x\n", pbtUID[3], pbtUID[2], pbtUID[1], pbtUID[0]);
|
||||
|
||||
if (bReadAction)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -35,7 +35,6 @@
|
|||
#include <nfc/nfc.h>
|
||||
#include <nfc/nfc-types.h>
|
||||
#include <nfc/nfc-messages.h>
|
||||
#include "bitutils.h"
|
||||
#include "nfc-utils.h"
|
||||
|
||||
#define MAX_DEVICE_COUNT 16
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@
|
|||
#include <nfc/nfc.h>
|
||||
|
||||
#include <nfc/nfc-messages.h>
|
||||
#include "bitutils.h"
|
||||
#include "nfc-utils.h"
|
||||
|
||||
#define MAX_FRAME_LEN 264
|
||||
#define MAX_DEVICE_COUNT 2
|
||||
|
|
|
|||
|
|
@ -1,8 +1,89 @@
|
|||
#include <nfc/nfc.h>
|
||||
|
||||
#include "bitutils.h"
|
||||
#include "nfc-utils.h"
|
||||
|
||||
static const byte_t OddParity[256] = {
|
||||
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
|
||||
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
|
||||
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
|
||||
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
|
||||
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
|
||||
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
|
||||
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
|
||||
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
|
||||
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
|
||||
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
|
||||
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
|
||||
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
|
||||
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
|
||||
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
|
||||
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
|
||||
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1
|
||||
};
|
||||
|
||||
void print_hex(const byte_t* pbtData, const size_t szBytes)
|
||||
{
|
||||
size_t szPos;
|
||||
|
||||
for (szPos=0; szPos < szBytes; szPos++)
|
||||
{
|
||||
printf("%02x ",pbtData[szPos]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void print_hex_bits(const byte_t* pbtData, const size_t szBits)
|
||||
{
|
||||
uint8_t uRemainder;
|
||||
size_t szPos;
|
||||
size_t szBytes = szBits/8;
|
||||
|
||||
for (szPos=0; szPos < szBytes; szPos++)
|
||||
{
|
||||
printf("%02x ",pbtData[szPos]);
|
||||
}
|
||||
|
||||
uRemainder = szBits % 8;
|
||||
// Print the rest bits
|
||||
if (uRemainder != 0)
|
||||
{
|
||||
if (uRemainder < 5)
|
||||
printf("%01x (%d bits)",pbtData[szBytes], uRemainder);
|
||||
else
|
||||
printf("%02x (%d bits)",pbtData[szBytes], uRemainder);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void print_hex_par(const byte_t* pbtData, const size_t szBits, const byte_t* pbtDataPar)
|
||||
{
|
||||
uint8_t uRemainder;
|
||||
size_t szPos;
|
||||
size_t szBytes = szBits/8;
|
||||
|
||||
for (szPos=0; szPos < szBytes; szPos++)
|
||||
{
|
||||
printf("%02x",pbtData[szPos]);
|
||||
if (OddParity[pbtData[szPos]] != pbtDataPar[szPos])
|
||||
{
|
||||
printf("! ");
|
||||
} else {
|
||||
printf(" ");
|
||||
}
|
||||
}
|
||||
|
||||
uRemainder = szBits % 8;
|
||||
// Print the rest bits, these cannot have parity bit
|
||||
if (uRemainder != 0)
|
||||
{
|
||||
if (uRemainder < 5)
|
||||
printf("%01x (%d bits)",pbtData[szBytes], uRemainder);
|
||||
else
|
||||
printf("%02x (%d bits)",pbtData[szBytes], uRemainder);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void print_nfc_iso14443a_info(const nfc_iso14443a_info_t nai)
|
||||
{
|
||||
printf(" ATQA (SENS_RES): "); print_hex(nai.abtAtqa,2);
|
||||
|
|
@ -13,3 +94,4 @@ void print_nfc_iso14443a_info(const nfc_iso14443a_info_t nai)
|
|||
print_hex(nai.abtAts, nai.szAtsLen);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,6 +24,9 @@
|
|||
#ifndef _EXAMPLES_NFC_UTILS_H_
|
||||
#define _EXAMPLES_NFC_UTILS_H_
|
||||
|
||||
void print_hex(const byte_t* pbtData, const size_t szLen);
|
||||
void print_hex_bits(const byte_t* pbtData, const size_t szBits);
|
||||
void print_hex_par(const byte_t* pbtData, const size_t szBits, const byte_t* pbtDataPar);
|
||||
void print_nfc_iso14443a_info(const nfc_iso14443a_info_t nai);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue