(libnfc-less-bitutils-more-ponies) Get rid of bitutils.[hc] (part 1).
- New API function append_iso14443a_crc(); - Add a PRINT_HEX macro for driver debugging (replaces print_hex function from bitutils.c); - Move bit-mirroring related functions to libnfc/mirror-subr.[hc]; - Move iso14443 related functions to libnfc/iso14443-subr.c; - Move libnfc/bitutils.c hex-dumping code to examples/nfc-utils.c; - Replace calls to swap_endian32() and swap_endian64() functions with calls to bswap32() and bswap64 provided by endian.h. And while I am here: - Fix the DBG macro so that it does not throw warning at compile time.
This commit is contained in:
parent
5302930b09
commit
10baef235f
24 changed files with 328 additions and 343 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
|
||||
|
|
|
|||
|
|
@ -33,10 +33,12 @@
|
|||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <sys/endian.h>
|
||||
|
||||
#include <nfc/nfc.h>
|
||||
|
||||
#include <nfc/nfc-messages.h>
|
||||
#include "bitutils.h"
|
||||
#include "nfc-utils.h"
|
||||
|
||||
#define SAK_FLAG_ATS_SUPPORTED 0x20
|
||||
|
||||
|
|
@ -200,9 +202,9 @@ int main(int argc,char* argv[])
|
|||
printf("\nFound tag with UID: ");
|
||||
if (szUidLen == 4)
|
||||
{
|
||||
printf("%08x\n",swap_endian32(abtUid));
|
||||
printf("%08x\n", bswap32( *((uint32_t *)&abtUid)));
|
||||
} else {
|
||||
printf("%014llx\n",swap_endian64(abtUid)&0x00ffffffffffffffull);
|
||||
printf("%014llx\n",bswap64(*((uint64_t *) &abtUid))&0x00ffffffffffffffull);
|
||||
}
|
||||
|
||||
nfc_disconnect(pnd);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -35,10 +35,12 @@
|
|||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include <sys/endian.h>
|
||||
|
||||
#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 +466,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: %08x\n",b4K?'4':'1',bswap32(*((uint32_t *)&pbtUID)));
|
||||
}
|
||||
}
|
||||
|
||||
// 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: %08x\n",b4K?'4':'1',bswap32(*((uint32_t *)&pbtUID)));
|
||||
|
||||
uiBlocks = (b4K)?0xff:0x3f;
|
||||
|
||||
|
|
|
|||
|
|
@ -35,10 +35,12 @@
|
|||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include <sys/endian.h>
|
||||
|
||||
#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;
|
||||
|
|
@ -217,7 +219,7 @@ int main(int argc, const char* argv[])
|
|||
|
||||
// Get the info from the current tag
|
||||
pbtUID = nti.nai.abtUid;
|
||||
printf("Found MIFARE Ultralight card with uid: %08x\n", swap_endian32(pbtUID));
|
||||
printf("Found MIFARE Ultralight card with uid: %08x\n", bswap32(*((uint32_t *)&pbtUID)));
|
||||
|
||||
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