(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
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue