Change byte_t type to uint8_t (Fixes Issue 147)

This commit is contained in:
Audrey Diacre 2011-11-24 10:54:42 +00:00
parent ce846931bc
commit 784a2f86a2
43 changed files with 442 additions and 444 deletions

View file

@ -50,10 +50,10 @@
bool
nfc_initiator_mifare_cmd (nfc_device * pnd, const mifare_cmd mc, const uint8_t ui8Block, mifare_param * pmp)
{
byte_t abtRx[265];
uint8_t abtRx[265];
size_t szRx = sizeof(abtRx);
size_t szParamLen;
byte_t abtCmd[265];
uint8_t abtCmd[265];
bool bEasyFraming;
abtCmd[0] = mc; // The MIFARE Classic command
@ -92,7 +92,7 @@ nfc_initiator_mifare_cmd (nfc_device * pnd, const mifare_cmd mc, const uint8_t u
// When available, copy the parameter bytes
if (szParamLen)
memcpy (abtCmd + 2, (byte_t *) pmp, szParamLen);
memcpy (abtCmd + 2, (uint8_t *) pmp, szParamLen);
bEasyFraming = pnd->bEasyFraming;
if (!nfc_configure (pnd, NDO_EASY_FRAMING, true)) {

View file

@ -38,7 +38,7 @@
# include <nfc/nfc-types.h>
// Compiler directive, set struct alignment to 1 byte_t for compatibility
// Compiler directive, set struct alignment to 1 uint8_t for compatibility
# pragma pack(1)
typedef enum {
@ -54,16 +54,16 @@ typedef enum {
// MIFARE command params
struct mifare_param_auth {
byte_t abtKey[6];
byte_t abtUid[4];
uint8_t abtKey[6];
uint8_t abtUid[4];
};
struct mifare_param_data {
byte_t abtData[16];
uint8_t abtData[16];
};
struct mifare_param_value {
byte_t abtValue[4];
uint8_t abtValue[4];
};
typedef union {
@ -77,26 +77,26 @@ typedef union {
bool nfc_initiator_mifare_cmd (nfc_device * pnd, const mifare_cmd mc, const uint8_t ui8Block, mifare_param * pmp);
// Compiler directive, set struct alignment to 1 byte_t for compatibility
// Compiler directive, set struct alignment to 1 uint8_t for compatibility
# pragma pack(1)
// MIFARE Classic
typedef struct {
byte_t abtUID[4];
byte_t btBCC;
byte_t btUnknown;
byte_t abtATQA[2];
byte_t abtUnknown[8];
uint8_t abtUID[4];
uint8_t btBCC;
uint8_t btUnknown;
uint8_t abtATQA[2];
uint8_t abtUnknown[8];
} mifare_classic_block_manufacturer;
typedef struct {
byte_t abtData[16];
uint8_t abtData[16];
} mifare_classic_block_data;
typedef struct {
byte_t abtKeyA[6];
byte_t abtAccessBits[4];
byte_t abtKeyB[6];
uint8_t abtKeyA[6];
uint8_t abtAccessBits[4];
uint8_t abtKeyB[6];
} mifare_classic_block_trailer;
typedef union {
@ -111,17 +111,17 @@ typedef struct {
// MIFARE Ultralight
typedef struct {
byte_t sn0[3];
byte_t btBCC0;
byte_t sn1[4];
byte_t btBCC1;
byte_t internal;
byte_t lock[2];
byte_t otp[4];
uint8_t sn0[3];
uint8_t btBCC0;
uint8_t sn1[4];
uint8_t btBCC1;
uint8_t internal;
uint8_t lock[2];
uint8_t otp[4];
} mifareul_block_manufacturer;
typedef struct {
byte_t abtData[16];
uint8_t abtData[16];
} mifareul_block_data;
typedef union {

View file

@ -113,7 +113,7 @@ uint8_t nfcforum_capability_container[] = {
#define ISO144434A_RATS 0xE0
int
nfcforum_tag4_io (struct nfc_emulator *emulator, const byte_t *data_in, const size_t data_in_len, byte_t *data_out, const size_t data_out_len)
nfcforum_tag4_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;

View file

@ -60,7 +60,7 @@ static mifare_classic_tag mtDump;
static bool bUseKeyA;
static bool bUseKeyFile;
static uint8_t uiBlocks;
static byte_t keys[] = {
static uint8_t keys[] = {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xd3, 0xf7, 0xd3, 0xf7, 0xd3, 0xf7,
0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5,
@ -81,18 +81,18 @@ static size_t num_keys = sizeof (keys) / 6;
#define MAX_FRAME_LEN 264
static byte_t abtRx[MAX_FRAME_LEN];
static uint8_t abtRx[MAX_FRAME_LEN];
static size_t szRxBits;
static size_t szRx = sizeof(abtRx);
byte_t abtHalt[4] = { 0x50, 0x00, 0x00, 0x00 };
uint8_t abtHalt[4] = { 0x50, 0x00, 0x00, 0x00 };
// special unlock command
byte_t abtUnlock1[1] = { 0x40 };
byte_t abtUnlock2[1] = { 0x43 };
uint8_t abtUnlock1[1] = { 0x40 };
uint8_t abtUnlock2[1] = { 0x43 };
static bool
transmit_bits (const byte_t * pbtTx, const size_t szTxBits)
transmit_bits (const uint8_t * pbtTx, const size_t szTxBits)
{
// Show transmitted command
printf ("Sent bits: ");
@ -110,7 +110,7 @@ transmit_bits (const byte_t * pbtTx, const size_t szTxBits)
static bool
transmit_bytes (const byte_t * pbtTx, const size_t szTx)
transmit_bytes (const uint8_t * pbtTx, const size_t szTx)
{
// Show transmitted command
printf ("Sent bits: ");
@ -458,7 +458,7 @@ int
main (int argc, const char *argv[])
{
action_t atAction = ACTION_USAGE;
byte_t *pbtUID;
uint8_t *pbtUID;
FILE *pfKeys = NULL;
FILE *pfDump = NULL;
int unlock= 0;
@ -571,7 +571,7 @@ main (int argc, const char *argv[])
pbtUID = nt.nti.nai.abtUid;
if (bUseKeyFile) {
byte_t fileUid[4];
uint8_t fileUid[4];
memcpy (fileUid, mtKeys.amb[0].mbm.abtUID, 4);
// Compare if key dump UID is the same as the current tag UID, at least for the first 4 bytes
if (memcmp (nt.nti.nai.abtUid, fileUid, 4) != 0) {

View file

@ -56,14 +56,14 @@
#define MAX_FRAME_LEN 264
static byte_t abtRx[MAX_FRAME_LEN];
static uint8_t abtRx[MAX_FRAME_LEN];
static size_t szRxBits;
static size_t szRx = sizeof(abtRx);
static byte_t abtRawUid[12];
static byte_t abtAtqa[2];
static byte_t abtSak;
static byte_t abtAts[MAX_FRAME_LEN];
static byte_t szAts = 0;
static uint8_t abtRawUid[12];
static uint8_t abtAtqa[2];
static uint8_t abtSak;
static uint8_t abtAts[MAX_FRAME_LEN];
static uint8_t szAts = 0;
static size_t szCL = 1;//Always start with Cascade Level 1 (CL1)
static nfc_device *pnd;
@ -71,24 +71,24 @@ bool quiet_output = false;
bool iso_ats_supported = 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, 0x00, 0x00 };
byte_t abtHalt[4] = { 0x50, 0x00, 0x00, 0x00 };
uint8_t abtReqa[1] = { 0x26 };
uint8_t abtSelectAll[2] = { 0x93, 0x20 };
uint8_t abtSelectTag[9] = { 0x93, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
uint8_t abtRats[4] = { 0xe0, 0x50, 0x00, 0x00 };
uint8_t abtHalt[4] = { 0x50, 0x00, 0x00, 0x00 };
#define CASCADE_BIT 0x04
// special unlock command
byte_t abtUnlock1[1] = { 0x40 };
byte_t abtUnlock2[1] = { 0x43 };
byte_t abtWipe[1] = { 0x41 };
byte_t abtWrite[4] = { 0xa0, 0x00, 0x5f, 0xb1 };
byte_t abtData[18] = { 0x01, 0x23, 0x45, 0x67, 0x00, 0x08, 0x04, 0x00, 0x46, 0x59, 0x25, 0x58, 0x49, 0x10, 0x23, 0x02, 0x23, 0xeb };
byte_t abtBlank[18] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x07, 0x80, 0x69, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x36, 0xCC };
uint8_t abtUnlock1[1] = { 0x40 };
uint8_t abtUnlock2[1] = { 0x43 };
uint8_t abtWipe[1] = { 0x41 };
uint8_t abtWrite[4] = { 0xa0, 0x00, 0x5f, 0xb1 };
uint8_t abtData[18] = { 0x01, 0x23, 0x45, 0x67, 0x00, 0x08, 0x04, 0x00, 0x46, 0x59, 0x25, 0x58, 0x49, 0x10, 0x23, 0x02, 0x23, 0xeb };
uint8_t abtBlank[18] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x07, 0x80, 0x69, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x36, 0xCC };
static bool
transmit_bits (const byte_t * pbtTx, const size_t szTxBits)
transmit_bits (const uint8_t * pbtTx, const size_t szTxBits)
{
// Show transmitted command
if (!quiet_output) {
@ -110,7 +110,7 @@ transmit_bits (const byte_t * pbtTx, const size_t szTxBits)
static bool
transmit_bytes (const byte_t * pbtTx, const size_t szTx)
transmit_bytes (const uint8_t * pbtTx, const size_t szTx)
{
// Show transmitted command
if (!quiet_output) {

View file

@ -77,7 +77,7 @@ void stop_select (int sig)
}
void
build_felica_frame(const nfc_felica_info nfi, const byte_t command, const byte_t* payload, const size_t payload_len, byte_t * frame, size_t * frame_len)
build_felica_frame(const nfc_felica_info nfi, const uint8_t command, const uint8_t* payload, const size_t payload_len, uint8_t * frame, size_t * frame_len)
{
frame[0] = 1 + 1 + 8 + payload_len;
*frame_len = frame[0];
@ -88,9 +88,9 @@ build_felica_frame(const nfc_felica_info nfi, const byte_t command, const byte_t
#define CHECK 0x06
int
nfc_forum_tag_type3_check (nfc_device *pnd, const nfc_target nt, const uint16_t block, const uint8_t block_count, byte_t * data, size_t * data_len)
nfc_forum_tag_type3_check (nfc_device *pnd, const nfc_target nt, const uint16_t block, const uint8_t block_count, uint8_t * data, size_t * data_len)
{
byte_t payload[1024] = {
uint8_t payload[1024] = {
1, // Services
0x0B, 0x00, // NFC Forum Tag Type 3's Service code
block_count,
@ -109,11 +109,11 @@ nfc_forum_tag_type3_check (nfc_device *pnd, const nfc_target nt, const uint16_t
}
}
byte_t frame[1024];
uint8_t frame[1024];
size_t frame_len = sizeof(frame);
build_felica_frame (nt.nti.nfi, CHECK, payload, payload_len, frame, &frame_len);
byte_t res[1024];
uint8_t res[1024];
size_t res_len;
if (!nfc_initiator_transceive_bytes (pnd, frame, frame_len, res, &res_len, NULL)) {
@ -137,8 +137,8 @@ nfc_forum_tag_type3_check (nfc_device *pnd, const nfc_target nt, const uint16_t
// NFCID2 does not match
return -1;
}
const byte_t status_flag1 = res[10];
const byte_t status_flag2 = res[11];
const uint8_t status_flag1 = res[10];
const uint8_t status_flag2 = res[11];
if ((status_flag1) || (status_flag2)) {
// Felica card's error
fprintf (stderr, "Status bytes: %02x, %02x\n", status_flag1, status_flag2);
@ -218,7 +218,7 @@ main(int argc, char *argv[])
int error = EXIT_SUCCESS;
// Polling payload (SENSF_REQ) must be present (see NFC Digital Protol)
const byte_t *pbtSensfReq = (byte_t*)"\x00\xff\xff\x01\x00";
const uint8_t *pbtSensfReq = (uint8_t*)"\x00\xff\xff\x01\x00";
if (!nfc_initiator_select_passive_target(pnd, nm, pbtSensfReq, 5, &nt)) {
nfc_perror (pnd, "nfc_initiator_select_passive_target");
error = EXIT_FAILURE;
@ -226,10 +226,10 @@ main(int argc, char *argv[])
}
// Check if System Code equals 0x12fc
const byte_t abtNfcForumSysCode[] = { 0x12, 0xfc };
const uint8_t abtNfcForumSysCode[] = { 0x12, 0xfc };
if (0 != memcmp (nt.nti.nfi.abtSysCode, abtNfcForumSysCode, 2)) {
// Retry with special polling
const byte_t *pbtSensfReqNfcForum = (byte_t*)"\x00\x12\xfc\x01\x00";
const uint8_t *pbtSensfReqNfcForum = (uint8_t*)"\x00\x12\xfc\x01\x00";
if (!nfc_initiator_select_passive_target(pnd, nm, pbtSensfReqNfcForum, 5, &nt)) {
nfc_perror (pnd, "nfc_initiator_select_passive_target");
error = EXIT_FAILURE;
@ -251,7 +251,7 @@ main(int argc, char *argv[])
goto error;
}
byte_t data[1024];
uint8_t data[1024];
size_t data_len = sizeof(data);
int len;

View file

@ -57,9 +57,9 @@
#define MAX_FRAME_LEN 264
#define MAX_DEVICE_COUNT 2
static byte_t abtCapdu[MAX_FRAME_LEN];
static uint8_t abtCapdu[MAX_FRAME_LEN];
static size_t szCapduLen;
static byte_t abtRapdu[MAX_FRAME_LEN];
static uint8_t abtRapdu[MAX_FRAME_LEN];
static size_t szRapduLen;
static nfc_device *pndInitiator;
static nfc_device *pndTarget;
@ -92,7 +92,7 @@ print_usage (char *argv[])
printf ("\t-n N\tAdds a waiting time of N seconds (integer) in the relay to mimic long distance.\n");
}
bool print_hex_fd4 (const byte_t * pbtData, const size_t szBytes, const char * pchPrefix)
bool print_hex_fd4 (const uint8_t * pbtData, const size_t szBytes, const char * pchPrefix)
{
size_t szPos;
if (szBytes > MAX_FRAME_LEN) {
@ -114,7 +114,7 @@ bool print_hex_fd4 (const byte_t * pbtData, const size_t szBytes, const char * p
return EXIT_SUCCESS;
}
bool scan_hex_fd3 (byte_t *pbtData, size_t *pszBytes, const char * pchPrefix)
bool scan_hex_fd3 (uint8_t *pbtData, size_t *pszBytes, const char * pchPrefix)
{
size_t szPos;
unsigned int uiBytes;
@ -326,11 +326,11 @@ main (int argc, char *argv[])
// PC/SC pseudo-ATR = 3B 80 80 01 01 if there is no historical bytes
// Creates ATS and copy max 48 bytes of Tk:
byte_t * pbtTk;
uint8_t * pbtTk;
size_t szTk;
pbtTk = iso14443a_locate_historical_bytes (ntEmulatedTarget.nti.nai.abtAts, ntEmulatedTarget.nti.nai.szAtsLen, &szTk);
szTk = (szTk > 48) ? 48 : szTk;
byte_t pbtTkt[48];
uint8_t pbtTkt[48];
memcpy(pbtTkt, pbtTk, szTk);
ntEmulatedTarget.nti.nai.abtAts[0] = 0x75;
ntEmulatedTarget.nti.nai.abtAts[1] = 0x33;

View file

@ -33,7 +33,7 @@
#include "nfc-utils.h"
static const byte_t OddParity[256] = {
static const uint8_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,
@ -52,14 +52,14 @@ static const byte_t OddParity[256] = {
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1
};
byte_t
oddparity (const byte_t bt)
uint8_t
oddparity (const uint8_t bt)
{
return OddParity[bt];
}
void
oddparity_bytes_ts (const byte_t * pbtData, const size_t szLen, byte_t * pbtPar)
oddparity_bytes_ts (const uint8_t * pbtData, const size_t szLen, uint8_t * pbtPar)
{
size_t szByteNr;
// Calculate the parity bits for the command
@ -69,7 +69,7 @@ oddparity_bytes_ts (const byte_t * pbtData, const size_t szLen, byte_t * pbtPar)
}
void
print_hex (const byte_t * pbtData, const size_t szBytes)
print_hex (const uint8_t * pbtData, const size_t szBytes)
{
size_t szPos;
@ -80,7 +80,7 @@ print_hex (const byte_t * pbtData, const size_t szBytes)
}
void
print_hex_bits (const byte_t * pbtData, const size_t szBits)
print_hex_bits (const uint8_t * pbtData, const size_t szBits)
{
uint8_t uRemainder;
size_t szPos;
@ -102,7 +102,7 @@ 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)
print_hex_par (const uint8_t * pbtData, const size_t szBits, const uint8_t * pbtDataPar)
{
uint8_t uRemainder;
size_t szPos;
@ -202,7 +202,7 @@ print_nfc_iso14443a_info (const nfc_iso14443a_info nai, bool verbose)
size_t offset = 1;
if (nai.abtAts[0] & 0x10) { // TA(1) present
byte_t TA = nai.abtAts[offset];
uint8_t TA = nai.abtAts[offset];
offset++;
printf ("* Bit Rate Capability:\n");
if (TA == 0) {
@ -234,7 +234,7 @@ print_nfc_iso14443a_info (const nfc_iso14443a_info nai, bool verbose)
}
}
if (nai.abtAts[0] & 0x20) { // TB(1) present
byte_t TB= nai.abtAts[offset];
uint8_t TB= nai.abtAts[offset];
offset++;
printf ("* Frame Waiting Time: %.4g ms\n",256.0*16.0*(1<<((TB & 0xf0) >> 4))/13560.0);
if ((TB & 0x0f) == 0) {
@ -244,7 +244,7 @@ print_nfc_iso14443a_info (const nfc_iso14443a_info nai, bool verbose)
}
}
if (nai.abtAts[0] & 0x40) { // TC(1) present
byte_t TC = nai.abtAts[offset];
uint8_t TC = nai.abtAts[offset];
offset++;
if (TC & 0x1) {
printf("* Node ADdress supported\n");
@ -260,20 +260,20 @@ print_nfc_iso14443a_info (const nfc_iso14443a_info nai, bool verbose)
if (nai.szAtsLen > offset) {
printf ("* Historical bytes Tk: " );
print_hex (nai.abtAts + offset, (nai.szAtsLen - offset));
byte_t CIB = nai.abtAts[offset];
uint8_t CIB = nai.abtAts[offset];
offset++;
if (CIB != 0x00 && CIB != 0x10 && (CIB & 0xf0) != 0x80) {
printf(" * Proprietary format\n");
if (CIB == 0xc1) {
printf(" * Tag byte: Mifare or virtual cards of various types\n");
byte_t L = nai.abtAts[offset];
uint8_t L = nai.abtAts[offset];
offset++;
if (L != (nai.szAtsLen - offset)) {
printf(" * Warning: Type Identification Coding length (%i)", L);
printf(" not matching Tk length (%zi)\n", (nai.szAtsLen - offset));
}
if ((nai.szAtsLen - offset - 2) > 0) { // Omit 2 CRC bytes
byte_t CTC = nai.abtAts[offset];
uint8_t CTC = nai.abtAts[offset];
offset++;
printf(" * Chip Type: ");
switch (CTC & 0xf0) {
@ -316,7 +316,7 @@ print_nfc_iso14443a_info (const nfc_iso14443a_info nai, bool verbose)
}
}
if ((nai.szAtsLen - offset) > 0) { // Omit 2 CRC bytes
byte_t CVC = nai.abtAts[offset];
uint8_t CVC = nai.abtAts[offset];
offset++;
printf(" * Chip Status: ");
switch (CVC & 0xf0) {
@ -350,7 +350,7 @@ print_nfc_iso14443a_info (const nfc_iso14443a_info nai, bool verbose)
}
}
if ((nai.szAtsLen - offset) > 0) { // Omit 2 CRC bytes
byte_t VCS = nai.abtAts[offset];
uint8_t VCS = nai.abtAts[offset];
offset++;
printf(" * Specifics (Virtual Card Selection):\n");
if ((VCS & 0x09) == 0x00) {

View file

@ -79,12 +79,12 @@
# define ERR(...) warnx ("ERROR: " __VA_ARGS__ )
#endif
byte_t oddparity (const byte_t bt);
void oddparity_byte_ts (const byte_t * pbtData, const size_t szLen, byte_t * pbtPar);
uint8_t oddparity (const uint8_t bt);
void oddparity_uint8_ts (const uint8_t * pbtData, const size_t szLen, uint8_t * pbtPar);
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_hex (const uint8_t * pbtData, const size_t szLen);
void print_hex_bits (const uint8_t * pbtData, const size_t szBits);
void print_hex_par (const uint8_t * pbtData, const size_t szBits, const uint8_t * pbtDataPar);
void print_nfc_iso14443a_info (const nfc_iso14443a_info nai, bool verbose);
void print_nfc_iso14443b_info (const nfc_iso14443b_info nbi, bool verbose);