From 784a2f86a212afba5f6625a4fa8bfd19d26d48b6 Mon Sep 17 00:00:00 2001 From: Audrey Diacre Date: Thu, 24 Nov 2011 10:54:42 +0000 Subject: [PATCH] Change byte_t type to uint8_t (Fixes Issue 147) --- examples/nfc-anticol.c | 26 ++-- examples/nfc-dep-initiator.c | 4 +- examples/nfc-dep-target.c | 4 +- examples/nfc-emulate-forum-tag2.c | 2 +- examples/nfc-emulate-tag.c | 6 +- examples/nfc-emulate-uid.c | 14 +- examples/nfc-relay.c | 8 +- examples/pn53x-diagnose.c | 8 +- examples/pn53x-sam.c | 2 +- examples/pn53x-tamashell.c | 8 +- include/nfc/nfc-emulation.h | 2 +- include/nfc/nfc-types.h | 62 +++++---- include/nfc/nfc.h | 26 ++-- libnfc/buses/uart.h | 4 +- libnfc/buses/uart_posix.c | 4 +- libnfc/buses/uart_win32.c | 4 +- libnfc/chips/pn53x.c | 214 +++++++++++++++--------------- libnfc/chips/pn53x.h | 78 +++++------ libnfc/drivers/acr122.c | 20 +-- libnfc/drivers/acr122.h | 4 +- libnfc/drivers/arygon.c | 32 ++--- libnfc/drivers/arygon.h | 4 +- libnfc/drivers/pn532_uart.c | 16 +-- libnfc/drivers/pn532_uart.h | 4 +- libnfc/drivers/pn53x_usb.c | 26 ++-- libnfc/drivers/pn53x_usb.h | 4 +- libnfc/iso14443-subr.c | 18 +-- libnfc/mirror-subr.c | 12 +- libnfc/mirror-subr.h | 4 +- libnfc/nfc-emulation.c | 4 +- libnfc/nfc-internal.c | 12 +- libnfc/nfc-internal.h | 24 ++-- libnfc/nfc.c | 28 ++-- test/test_dep.c | 14 +- utils/mifare.c | 6 +- utils/mifare.h | 46 +++---- utils/nfc-emulate-forum-tag4.c | 2 +- utils/nfc-mfclassic.c | 18 +-- utils/nfc-mfsetuid.c | 38 +++--- utils/nfc-read-forum-tag3.c | 22 +-- utils/nfc-relay-picc.c | 12 +- utils/nfc-utils.c | 30 ++--- utils/nfc-utils.h | 10 +- 43 files changed, 442 insertions(+), 444 deletions(-) diff --git a/examples/nfc-anticol.c b/examples/nfc-anticol.c index 4566c98..f6b4ca4 100644 --- a/examples/nfc-anticol.c +++ b/examples/nfc-anticol.c @@ -51,14 +51,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; @@ -67,15 +67,15 @@ bool force_rats = 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 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) { @@ -97,7 +97,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) { diff --git a/examples/nfc-dep-initiator.c b/examples/nfc-dep-initiator.c index 37cf78c..d3ca65e 100644 --- a/examples/nfc-dep-initiator.c +++ b/examples/nfc-dep-initiator.c @@ -63,9 +63,9 @@ int main (int argc, const char *argv[]) { nfc_target nt; - byte_t abtRx[MAX_FRAME_LEN]; + uint8_t abtRx[MAX_FRAME_LEN]; size_t szRx = sizeof(abtRx); - byte_t abtTx[] = "Hello World!"; + uint8_t abtTx[] = "Hello World!"; if (argc > 1) { printf ("Usage: %s\n", argv[0]); diff --git a/examples/nfc-dep-target.c b/examples/nfc-dep-target.c index a46bf45..2195ea8 100644 --- a/examples/nfc-dep-target.c +++ b/examples/nfc-dep-target.c @@ -61,10 +61,10 @@ void stop_dep_communication (int sig) int main (int argc, const char *argv[]) { - byte_t abtRx[MAX_FRAME_LEN]; + uint8_t abtRx[MAX_FRAME_LEN]; size_t szRx = sizeof(abtRx); size_t szDeviceFound; - byte_t abtTx[] = "Hello Mars!"; + uint8_t abtTx[] = "Hello Mars!"; #define MAX_DEVICE_COUNT 2 nfc_connstring connstrings[MAX_DEVICE_COUNT]; nfc_list_devices (connstrings, MAX_DEVICE_COUNT, &szDeviceFound); diff --git a/examples/nfc-emulate-forum-tag2.c b/examples/nfc-emulate-forum-tag2.c index c514152..5289269 100644 --- a/examples/nfc-emulate-forum-tag2.c +++ b/examples/nfc-emulate-forum-tag2.c @@ -112,7 +112,7 @@ static uint8_t __nfcforum_tag2_memory_area[] = { #define HALT 0x50 int -nfcforum_tag2_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_tag2_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; diff --git a/examples/nfc-emulate-tag.c b/examples/nfc-emulate-tag.c index 133701d..e75b569 100644 --- a/examples/nfc-emulate-tag.c +++ b/examples/nfc-emulate-tag.c @@ -54,7 +54,7 @@ #define MAX_FRAME_LEN (264) #define SAK_ISO14443_4_COMPLIANT 0x20 -static byte_t abtRx[MAX_FRAME_LEN]; +static uint8_t abtRx[MAX_FRAME_LEN]; static size_t szRx = sizeof(abtRx); static nfc_device *pnd; static bool quiet_output = false; @@ -71,7 +71,7 @@ intr_hdlr (void) } bool -target_io( nfc_target * pnt, const byte_t * pbtInput, const size_t szInput, byte_t * pbtOutput, size_t *pszOutput ) +target_io( nfc_target * pnt, const uint8_t * pbtInput, const size_t szInput, uint8_t * pbtOutput, size_t *pszOutput ) { bool loop = true; *pszOutput = 0; @@ -137,7 +137,7 @@ bool nfc_target_emulate_tag(nfc_device* pnd, nfc_target * pnt) { size_t szTx; - byte_t abtTx[MAX_FRAME_LEN]; + uint8_t abtTx[MAX_FRAME_LEN]; bool loop = true; if (!nfc_target_init (pnd, pnt, abtRx, &szRx)) { diff --git a/examples/nfc-emulate-uid.c b/examples/nfc-emulate-uid.c index a6f8387..4100ee8 100644 --- a/examples/nfc-emulate-uid.c +++ b/examples/nfc-emulate-uid.c @@ -56,14 +56,14 @@ #define MAX_FRAME_LEN 264 -static byte_t abtRecv[MAX_FRAME_LEN]; +static uint8_t abtRecv[MAX_FRAME_LEN]; static size_t szRecvBits; static nfc_device *pnd; // ISO14443A Anti-Collision response -byte_t abtAtqa[2] = { 0x04, 0x00 }; -byte_t abtUidBcc[5] = { 0xDE, 0xAD, 0xBE, 0xEF, 0x62 }; -byte_t abtSak[9] = { 0x08, 0xb6, 0xdd }; +uint8_t abtAtqa[2] = { 0x04, 0x00 }; +uint8_t abtUidBcc[5] = { 0xDE, 0xAD, 0xBE, 0xEF, 0x62 }; +uint8_t abtSak[9] = { 0x08, 0xb6, 0xdd }; void intr_hdlr (void) @@ -88,7 +88,7 @@ print_usage (char *argv[]) int main (int argc, char *argv[]) { - byte_t *pbtTx = NULL; + uint8_t *pbtTx = NULL; size_t szTxBits; bool quiet_output = false; @@ -104,12 +104,12 @@ main (int argc, char *argv[]) printf ("Quiet mode.\n"); quiet_output = true; } else if ((arg == argc - 1) && (strlen (argv[arg]) == 8)) { // See if UID was specified as HEX string - byte_t abtTmp[3] = { 0x00, 0x00, 0x00 }; + uint8_t abtTmp[3] = { 0x00, 0x00, 0x00 }; printf ("[+] Using UID: %s\n", argv[arg]); abtUidBcc[4] = 0x00; for (i = 0; i < 4; ++i) { memcpy (abtTmp, argv[arg] + i * 2, 2); - abtUidBcc[i] = (byte_t) strtol ((char *) abtTmp, NULL, 16); + abtUidBcc[i] = (uint8_t) strtol ((char *) abtTmp, NULL, 16); abtUidBcc[4] ^= abtUidBcc[i]; } } else { diff --git a/examples/nfc-relay.c b/examples/nfc-relay.c index 631a63a..d94da4b 100644 --- a/examples/nfc-relay.c +++ b/examples/nfc-relay.c @@ -50,11 +50,11 @@ #define MAX_FRAME_LEN 264 #define MAX_DEVICE_COUNT 2 -static byte_t abtReaderRx[MAX_FRAME_LEN]; -static byte_t abtReaderRxPar[MAX_FRAME_LEN]; +static uint8_t abtReaderRx[MAX_FRAME_LEN]; +static uint8_t abtReaderRxPar[MAX_FRAME_LEN]; static size_t szReaderRxBits; -static byte_t abtTagRx[MAX_FRAME_LEN]; -static byte_t abtTagRxPar[MAX_FRAME_LEN]; +static uint8_t abtTagRx[MAX_FRAME_LEN]; +static uint8_t abtTagRxPar[MAX_FRAME_LEN]; static size_t szTagRxBits; static nfc_device *pndReader; static nfc_device *pndTag; diff --git a/examples/pn53x-diagnose.c b/examples/pn53x-diagnose.c index 0bf53c6..5ff4bc1 100644 --- a/examples/pn53x-diagnose.c +++ b/examples/pn53x-diagnose.c @@ -58,11 +58,11 @@ main (int argc, const char *argv[]) const char *acLibnfcVersion; bool result; - byte_t abtRx[PN53x_EXTENDED_FRAME__DATA_MAX_LEN]; + uint8_t abtRx[PN53x_EXTENDED_FRAME__DATA_MAX_LEN]; size_t szRx = sizeof(abtRx); - const byte_t pncmd_diagnose_communication_line_test[] = { Diagnose, 0x00, 0x06, 'l', 'i', 'b', 'n', 'f', 'c' }; - const byte_t pncmd_diagnose_rom_test[] = { Diagnose, 0x01 }; - const byte_t pncmd_diagnose_ram_test[] = { Diagnose, 0x02 }; + const uint8_t pncmd_diagnose_communication_line_test[] = { Diagnose, 0x00, 0x06, 'l', 'i', 'b', 'n', 'f', 'c' }; + const uint8_t pncmd_diagnose_rom_test[] = { Diagnose, 0x01 }; + const uint8_t pncmd_diagnose_ram_test[] = { Diagnose, 0x02 }; if (argc > 1) { errx (1, "usage: %s", argv[0]); diff --git a/examples/pn53x-sam.c b/examples/pn53x-sam.c index 113cac0..11a4c29 100644 --- a/examples/pn53x-sam.c +++ b/examples/pn53x-sam.c @@ -153,7 +153,7 @@ main (int argc, const char *argv[]) case PSM_DUAL_CARD: { - byte_t abtRx[MAX_FRAME_LEN]; + uint8_t abtRx[MAX_FRAME_LEN]; size_t szRx = sizeof(abtRx); nfc_target nt = { diff --git a/examples/pn53x-tamashell.c b/examples/pn53x-tamashell.c index 1929697..3621d2c 100644 --- a/examples/pn53x-tamashell.c +++ b/examples/pn53x-tamashell.c @@ -72,8 +72,8 @@ int main(int argc, const char* argv[]) { nfc_device* pnd; - byte_t abtRx[MAX_FRAME_LEN]; - byte_t abtTx[MAX_FRAME_LEN]; + uint8_t abtRx[MAX_FRAME_LEN]; + uint8_t abtTx[MAX_FRAME_LEN]; size_t szRx = sizeof(abtRx); size_t szTx; extern FILE* stdin; @@ -154,7 +154,7 @@ int main(int argc, const char* argv[]) szTx = 0; for(int i = 0; i # include -typedef uint8_t byte_t; - # define DEVICE_NAME_LENGTH 256 # define DEVICE_PORT_LENGTH 64 @@ -59,7 +57,7 @@ typedef struct { selecting tags supporting it? */ bool bAutoIso14443_4; /** Supported modulation encoded in a byte */ - byte_t btSupportByte; + uint8_t btSupportByte; /** Last error reported by the PCD / encountered by the PCD driver * MSB LSB * | 00 | 00 | @@ -73,7 +71,7 @@ typedef struct { typedef char nfc_connstring[1024]; -// 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) /** @@ -155,19 +153,19 @@ typedef enum { */ typedef struct { /** NFCID3 */ - byte_t abtNFCID3[10]; + uint8_t abtNFCID3[10]; /** DID */ - byte_t btDID; + uint8_t btDID; /** Supported send-bit rate */ - byte_t btBS; + uint8_t btBS; /** Supported receive-bit rate */ - byte_t btBR; + uint8_t btBR; /** Timeout value */ - byte_t btTO; + uint8_t btTO; /** PP Parameters */ - byte_t btPP; + uint8_t btPP; /** General Bytes */ - byte_t abtGB[48]; + uint8_t abtGB[48]; size_t szGB; /** DEP mode */ nfc_dep_mode ndm; @@ -178,12 +176,12 @@ typedef struct { * @brief NFC ISO14443A tag (MIFARE) information */ typedef struct { - byte_t abtAtqa[2]; - byte_t btSak; + uint8_t abtAtqa[2]; + uint8_t btSak; size_t szUidLen; - byte_t abtUid[10]; + uint8_t abtUid[10]; size_t szAtsLen; - byte_t abtAts[254]; // Maximal theoretical ATS is FSD-2, FSD=256 for FSDI=8 in RATS + uint8_t abtAts[254]; // Maximal theoretical ATS is FSD-2, FSD=256 for FSDI=8 in RATS } nfc_iso14443a_info; /** @@ -192,10 +190,10 @@ typedef struct { */ typedef struct { size_t szLen; - byte_t btResCode; - byte_t abtId[8]; - byte_t abtPad[8]; - byte_t abtSysCode[2]; + uint8_t btResCode; + uint8_t abtId[8]; + uint8_t abtPad[8]; + uint8_t abtSysCode[2]; } nfc_felica_info; /** @@ -204,11 +202,11 @@ typedef struct { */ typedef struct { /** abtPupi store PUPI contained in ATQB (Answer To reQuest of type B) (see ISO14443-3) */ - byte_t abtPupi[4]; + uint8_t abtPupi[4]; /** abtApplicationData store Application Data contained in ATQB (see ISO14443-3) */ - byte_t abtApplicationData[4]; + uint8_t abtApplicationData[4]; /** abtProtocolInfo store Protocol Info contained in ATQB (see ISO14443-3) */ - byte_t abtProtocolInfo[3]; + uint8_t abtProtocolInfo[3]; /** ui8CardIdentifier store CID (Card Identifier) attributted by PCD to the PICC */ uint8_t ui8CardIdentifier; } nfc_iso14443b_info; @@ -219,14 +217,14 @@ typedef struct { */ typedef struct { /** DIV: 4 LSBytes of tag serial number */ - byte_t abtDIV[4]; + uint8_t abtDIV[4]; /** Software version & type of REPGEN */ - byte_t btVerLog; + uint8_t btVerLog; /** Config Byte, present if long REPGEN */ - byte_t btConfig; + uint8_t btConfig; /** ATR, if any */ size_t szAtrLen; - byte_t abtAtr[33]; + uint8_t abtAtr[33]; } nfc_iso14443bi_info; /** @@ -234,7 +232,7 @@ typedef struct { * @brief NFC ISO14443-2B ST SRx tag information */ typedef struct { - byte_t abtUID[8]; + uint8_t abtUID[8]; } nfc_iso14443b2sr_info; /** @@ -242,9 +240,9 @@ typedef struct { * @brief NFC ISO14443-2B ASK CTx tag information */ typedef struct { - byte_t abtUID[4]; - byte_t btProdCode; - byte_t btFabCode; + uint8_t abtUID[4]; + uint8_t btProdCode; + uint8_t btFabCode; } nfc_iso14443b2ct_info; /** @@ -252,8 +250,8 @@ typedef struct { * @brief NFC Jewel tag information */ typedef struct { - byte_t btSensRes[2]; - byte_t btId[4]; + uint8_t btSensRes[2]; + uint8_t btId[4]; } nfc_jewel_info; /** diff --git a/include/nfc/nfc.h b/include/nfc/nfc.h index c90fa17..3babb1b 100644 --- a/include/nfc/nfc.h +++ b/include/nfc/nfc.h @@ -73,22 +73,22 @@ extern "C" { /* NFC initiator: act as "reader" */ NFC_EXPORT bool nfc_initiator_init (nfc_device * pnd); - NFC_EXPORT bool nfc_initiator_select_passive_target (nfc_device * pnd, const nfc_modulation nm, const byte_t * pbtInitData, const size_t szInitData, nfc_target * pnt); + NFC_EXPORT bool nfc_initiator_select_passive_target (nfc_device * pnd, const nfc_modulation nm, const uint8_t * pbtInitData, const size_t szInitData, nfc_target * pnt); NFC_EXPORT bool nfc_initiator_list_passive_targets (nfc_device * pnd, const nfc_modulation nm, nfc_target ant[], const size_t szTargets, size_t * pszTargetFound); NFC_EXPORT bool nfc_initiator_poll_target (nfc_device * pnd, const nfc_modulation * pnmTargetTypes, const size_t szTargetTypes, const uint8_t uiPollNr, const uint8_t uiPeriod, nfc_target * pnt); NFC_EXPORT bool nfc_initiator_select_dep_target (nfc_device * pnd, const nfc_dep_mode ndm, const nfc_baud_rate nbr, const nfc_dep_info * pndiInitiator, nfc_target * pnt); NFC_EXPORT bool nfc_initiator_deselect_target (nfc_device * pnd); - NFC_EXPORT bool nfc_initiator_transceive_bytes (nfc_device * pnd, const byte_t * pbtTx, const size_t szTx, byte_t * pbtRx, size_t * pszRx, struct timeval *timeout); - NFC_EXPORT bool nfc_initiator_transceive_bits (nfc_device * pnd, const byte_t * pbtTx, const size_t szTxBits, const byte_t * pbtTxPar, byte_t * pbtRx, size_t * pszRxBits, byte_t * pbtRxPar); - NFC_EXPORT bool nfc_initiator_transceive_bytes_timed (nfc_device * pnd, const byte_t * pbtTx, const size_t szTx, byte_t * pbtRx, size_t * pszRx, uint32_t * cycles); - NFC_EXPORT bool nfc_initiator_transceive_bits_timed (nfc_device * pnd, const byte_t * pbtTx, const size_t szTxBits, const byte_t * pbtTxPar, byte_t * pbtRx, size_t * pszRxBits, byte_t * pbtRxPar, uint32_t * cycles); + NFC_EXPORT bool nfc_initiator_transceive_bytes (nfc_device * pnd, const uint8_t * pbtTx, const size_t szTx, uint8_t * pbtRx, size_t * pszRx, struct timeval *timeout); + NFC_EXPORT bool nfc_initiator_transceive_bits (nfc_device * pnd, const uint8_t * pbtTx, const size_t szTxBits, const uint8_t * pbtTxPar, uint8_t * pbtRx, size_t * pszRxBits, uint8_t * pbtRxPar); + NFC_EXPORT bool nfc_initiator_transceive_bytes_timed (nfc_device * pnd, const uint8_t * pbtTx, const size_t szTx, uint8_t * pbtRx, size_t * pszRx, uint32_t * cycles); + NFC_EXPORT bool nfc_initiator_transceive_bits_timed (nfc_device * pnd, const uint8_t * pbtTx, const size_t szTxBits, const uint8_t * pbtTxPar, uint8_t * pbtRx, size_t * pszRxBits, uint8_t * pbtRxPar, uint32_t * cycles); /* NFC target: act as tag (i.e. MIFARE Classic) or NFC target device. */ - NFC_EXPORT bool nfc_target_init (nfc_device * pnd, nfc_target * pnt, byte_t * pbtRx, size_t * pszRx); - NFC_EXPORT bool nfc_target_send_bytes (nfc_device * pnd, const byte_t * pbtTx, const size_t szTx, struct timeval *timout); - NFC_EXPORT bool nfc_target_receive_bytes (nfc_device * pnd, byte_t * pbtRx, size_t * pszRx, struct timeval *timout); - NFC_EXPORT bool nfc_target_send_bits (nfc_device * pnd, const byte_t * pbtTx, const size_t szTxBits, const byte_t * pbtTxPar); - NFC_EXPORT bool nfc_target_receive_bits (nfc_device * pnd, byte_t * pbtRx, size_t * pszRxBits, byte_t * pbtRxPar); + NFC_EXPORT bool nfc_target_init (nfc_device * pnd, nfc_target * pnt, uint8_t * pbtRx, size_t * pszRx); + NFC_EXPORT bool nfc_target_send_bytes (nfc_device * pnd, const uint8_t * pbtTx, const size_t szTx, struct timeval *timout); + NFC_EXPORT bool nfc_target_receive_bytes (nfc_device * pnd, uint8_t * pbtRx, size_t * pszRx, struct timeval *timout); + NFC_EXPORT bool nfc_target_send_bits (nfc_device * pnd, const uint8_t * pbtTx, const size_t szTxBits, const uint8_t * pbtTxPar); + NFC_EXPORT bool nfc_target_receive_bits (nfc_device * pnd, uint8_t * pbtRx, size_t * pszRxBits, uint8_t * pbtRxPar); /* Error reporting */ NFC_EXPORT const char *nfc_strerror (const nfc_device * pnd); @@ -99,9 +99,9 @@ extern "C" { NFC_EXPORT const char *nfc_device_name (nfc_device * pnd); /* Misc. functions */ - NFC_EXPORT void iso14443a_crc (byte_t * pbtData, size_t szLen, byte_t * pbtCrc); - NFC_EXPORT void iso14443a_crc_append (byte_t * pbtData, size_t szLen); - NFC_EXPORT byte_t * iso14443a_locate_historical_bytes (byte_t * pbtAts, size_t szAts, size_t * pszTk); + NFC_EXPORT void iso14443a_crc (uint8_t * pbtData, size_t szLen, uint8_t * pbtCrc); + NFC_EXPORT void iso14443a_crc_append (uint8_t * pbtData, size_t szLen); + NFC_EXPORT uint8_t * iso14443a_locate_historical_bytes (uint8_t * pbtAts, size_t szAts, size_t * pszTk); NFC_EXPORT const char *nfc_version (void); /* PN53x specific errors */ diff --git a/libnfc/buses/uart.h b/libnfc/buses/uart.h index a2fbd96..24b4924 100644 --- a/libnfc/buses/uart.h +++ b/libnfc/buses/uart.h @@ -49,8 +49,8 @@ void uart_flush_input (const serial_port sp); void uart_set_speed (serial_port sp, const uint32_t uiPortSpeed); uint32_t uart_get_speed (const serial_port sp); -int uart_receive (serial_port sp, byte_t * pbtRx, const size_t szRx, void * abort_p, struct timeval *timeout); -int uart_send (serial_port sp, const byte_t * pbtTx, const size_t szTx, struct timeval *timeout); +int uart_receive (serial_port sp, uint8_t * pbtRx, const size_t szRx, void * abort_p, struct timeval *timeout); +int uart_send (serial_port sp, const uint8_t * pbtTx, const size_t szTx, struct timeval *timeout); char **uart_list_ports (void); diff --git a/libnfc/buses/uart_posix.c b/libnfc/buses/uart_posix.c index 9af33e4..e74b9b3 100644 --- a/libnfc/buses/uart_posix.c +++ b/libnfc/buses/uart_posix.c @@ -249,7 +249,7 @@ uart_close (const serial_port sp) * @return 0 on success, otherwise driver error code */ int -uart_receive (serial_port sp, byte_t * pbtRx, const size_t szRx, void * abort_p, struct timeval *timeout) +uart_receive (serial_port sp, uint8_t * pbtRx, const size_t szRx, void * abort_p, struct timeval *timeout) { int iAbortFd = abort_p ? *((int*)abort_p) : 0; int received_bytes_count = 0; @@ -327,7 +327,7 @@ select: * @return 0 on success, otherwise a driver error is returned */ int -uart_send (serial_port sp, const byte_t * pbtTx, const size_t szTx, struct timeval *timeout) +uart_send (serial_port sp, const uint8_t * pbtTx, const size_t szTx, struct timeval *timeout) { (void) timeout; LOG_HEX ("TX", pbtTx, szTx); diff --git a/libnfc/buses/uart_win32.c b/libnfc/buses/uart_win32.c index 339be57..4a886bc 100644 --- a/libnfc/buses/uart_win32.c +++ b/libnfc/buses/uart_win32.c @@ -139,7 +139,7 @@ uart_get_speed (const serial_port sp) } int -uart_receive (serial_port sp, byte_t * pbtRx, const size_t szRx, void * abort_p, struct timeval *timeout) +uart_receive (serial_port sp, uint8_t * pbtRx, const size_t szRx, void * abort_p, struct timeval *timeout) { DWORD dwBytesToGet = (DWORD)szRx; DWORD dwBytesReceived = 0; @@ -194,7 +194,7 @@ uart_receive (serial_port sp, byte_t * pbtRx, const size_t szRx, void * abort_p, } int -uart_send (serial_port sp, const byte_t * pbtTx, const size_t szTx, struct timeval *timeout) +uart_send (serial_port sp, const uint8_t * pbtTx, const size_t szTx, struct timeval *timeout) { DWORD dwTxLen = 0; diff --git a/libnfc/chips/pn53x.c b/libnfc/chips/pn53x.c index 7de9520..4e4b058 100644 --- a/libnfc/chips/pn53x.c +++ b/libnfc/chips/pn53x.c @@ -46,9 +46,9 @@ #define LOG_CATEGORY "libnfc.chip.pn53x" -const byte_t pn53x_ack_frame[] = { 0x00, 0x00, 0xff, 0x00, 0xff, 0x00 }; -const byte_t pn53x_nack_frame[] = { 0x00, 0x00, 0xff, 0xff, 0x00, 0x00 }; -static const byte_t pn53x_error_frame[] = { 0x00, 0x00, 0xff, 0x01, 0xff, 0x7f, 0x81, 0x00 }; +const uint8_t pn53x_ack_frame[] = { 0x00, 0x00, 0xff, 0x00, 0xff, 0x00 }; +const uint8_t pn53x_nack_frame[] = { 0x00, 0x00, 0xff, 0xff, 0x00, 0x00 }; +static const uint8_t pn53x_error_frame[] = { 0x00, 0x00, 0xff, 0x01, 0xff, 0x7f, 0x81, 0x00 }; /* prototypes */ bool pn53x_reset_settings (nfc_device * pnd); @@ -100,7 +100,7 @@ pn53x_reset_settings(nfc_device * pnd) } bool -pn53x_transceive (nfc_device * pnd, const byte_t * pbtTx, const size_t szTx, byte_t * pbtRx, size_t *pszRx, struct timeval *timeout) +pn53x_transceive (nfc_device * pnd, const uint8_t * pbtTx, const size_t szTx, uint8_t * pbtRx, size_t *pszRx, struct timeval *timeout) { if (CHIP_DATA (pnd)->wb_trigged) { if (!pn53x_writeback_register (pnd)) { @@ -112,7 +112,7 @@ pn53x_transceive (nfc_device * pnd, const byte_t * pbtTx, const size_t szTx, byt if (timeout) log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "Timeout values: %li s, %li us", timeout->tv_sec, timeout->tv_usec); - byte_t abtRx[PN53x_EXTENDED_FRAME__DATA_MAX_LEN]; + uint8_t abtRx[PN53x_EXTENDED_FRAME__DATA_MAX_LEN]; size_t szRx = sizeof(abtRx); // Check if receiving buffers are available, if not, replace them @@ -215,11 +215,11 @@ pn53x_set_tx_bits (nfc_device * pnd, const uint8_t ui8Bits) } bool -pn53x_wrap_frame (const byte_t * pbtTx, const size_t szTxBits, const byte_t * pbtTxPar, - byte_t * pbtFrame, size_t * pszFrameBits) +pn53x_wrap_frame (const uint8_t * pbtTx, const size_t szTxBits, const uint8_t * pbtTxPar, + uint8_t * pbtFrame, size_t * pszFrameBits) { - byte_t btFrame; - byte_t btData; + uint8_t btFrame; + uint8_t btData; uint32_t uiBitPos; uint32_t uiDataPos = 0; size_t szBitsLeft = szTxBits; @@ -271,14 +271,14 @@ pn53x_wrap_frame (const byte_t * pbtTx, const size_t szTxBits, const byte_t * pb } bool -pn53x_unwrap_frame (const byte_t * pbtFrame, const size_t szFrameBits, byte_t * pbtRx, size_t * pszRxBits, - byte_t * pbtRxPar) +pn53x_unwrap_frame (const uint8_t * pbtFrame, const size_t szFrameBits, uint8_t * pbtRx, size_t * pszRxBits, + uint8_t * pbtRxPar) { - byte_t btFrame; - byte_t btData; + uint8_t btFrame; + uint8_t btData; uint8_t uiBitPos; uint32_t uiDataPos = 0; - byte_t *pbtFramePos = (byte_t *) pbtFrame; + uint8_t *pbtFramePos = (uint8_t *) pbtFrame; size_t szBitsLeft = szFrameBits; // Make sure we should frame at least something @@ -318,7 +318,7 @@ pn53x_unwrap_frame (const byte_t * pbtFrame, const size_t szFrameBits, byte_t * } bool -pn53x_decode_target_data (const byte_t * pbtRawData, size_t szRawData, pn53x_type type, nfc_modulationype nmt, +pn53x_decode_target_data (const uint8_t * pbtRawData, size_t szRawData, pn53x_type type, nfc_modulationype nmt, nfc_target_info * pnti) { uint8_t szAttribRes; @@ -464,8 +464,8 @@ pn53x_decode_target_data (const byte_t * pbtRawData, size_t szRawData, pn53x_typ bool pn53x_ReadRegister (nfc_device * pnd, uint16_t ui16RegisterAddress, uint8_t * ui8Value) { - byte_t abtCmd[] = { ReadRegister, ui16RegisterAddress >> 8, ui16RegisterAddress & 0xff }; - byte_t abtRegValue[2]; + uint8_t abtCmd[] = { ReadRegister, ui16RegisterAddress >> 8, ui16RegisterAddress & 0xff }; + uint8_t abtRegValue[2]; size_t szRegValue = sizeof (abtRegValue); PNREG_TRACE (ui16RegisterAddress); @@ -489,7 +489,7 @@ bool pn53x_read_register (nfc_device * pnd, uint16_t ui16RegisterAddress, uint8_ bool pn53x_WriteRegister (nfc_device * pnd, const uint16_t ui16RegisterAddress, const uint8_t ui8Value) { - byte_t abtCmd[] = { WriteRegister, ui16RegisterAddress >> 8, ui16RegisterAddress & 0xff, ui8Value }; + uint8_t abtCmd[] = { WriteRegister, ui16RegisterAddress >> 8, ui16RegisterAddress & 0xff, ui8Value }; PNREG_TRACE (ui16RegisterAddress); return pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), NULL, NULL, NULL); } @@ -591,8 +591,8 @@ pn53x_writeback_register (nfc_device * pnd) bool pn53x_get_firmware_version (nfc_device * pnd, char abtFirmwareText[22]) { - const byte_t abtCmd[] = { GetFirmwareVersion }; - byte_t abtFw[4]; + const uint8_t abtCmd[] = { GetFirmwareVersion }; + uint8_t abtFw[4]; size_t szFwLen = sizeof (abtFw); if (!pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), abtFw, &szFwLen, NULL)) { return false; @@ -642,7 +642,7 @@ pn53x_get_firmware_version (nfc_device * pnd, char abtFirmwareText[22]) bool pn53x_configure (nfc_device * pnd, const nfc_device_option ndo, const bool bEnable) { - byte_t btValue; + uint8_t btValue; switch (ndo) { case NDO_HANDLE_CRC: // Enable or disable automatic receiving/sending of CRC bytes @@ -827,9 +827,9 @@ pn53x_idle (nfc_device *pnd) bool pn53x_check_communication (nfc_device *pnd) { - const byte_t abtCmd[] = { Diagnose, 0x00, 'l', 'i', 'b', 'n', 'f', 'c' }; - const byte_t abtExpectedRx[] = { 0x00, 'l', 'i', 'b', 'n', 'f', 'c' }; - byte_t abtRx[sizeof(abtExpectedRx)]; + const uint8_t abtCmd[] = { Diagnose, 0x00, 'l', 'i', 'b', 'n', 'f', 'c' }; + const uint8_t abtExpectedRx[] = { 0x00, 'l', 'i', 'b', 'n', 'f', 'c' }; + uint8_t abtRx[sizeof(abtExpectedRx)]; size_t szRx = sizeof (abtRx); struct timeval timeout; @@ -858,11 +858,11 @@ pn53x_initiator_init (nfc_device * pnd) bool pn53x_initiator_select_passive_target_ext (nfc_device * pnd, const nfc_modulation nm, - const byte_t * pbtInitData, const size_t szInitData, + const uint8_t * pbtInitData, const size_t szInitData, nfc_target * pnt, struct timeval* timeout) { - byte_t abtTargetsData[PN53x_EXTENDED_FRAME__DATA_MAX_LEN]; + uint8_t abtTargetsData[PN53x_EXTENDED_FRAME__DATA_MAX_LEN]; size_t szTargetsData = sizeof(abtTargetsData); if (nm.nmt == NMT_ISO14443BI || nm.nmt == NMT_ISO14443B2SR || nm.nmt == NMT_ISO14443B2CT) { @@ -884,11 +884,11 @@ pn53x_initiator_select_passive_target_ext (nfc_device * pnd, pnd->bEasyFraming = false; if (nm.nmt == NMT_ISO14443B2SR) { // Some work to do before getting the UID... - byte_t abtInitiate[]="\x06\x00"; + uint8_t abtInitiate[]="\x06\x00"; size_t szInitiateLen = 2; - byte_t abtSelect[]="\x0e\x00"; + uint8_t abtSelect[]="\x0e\x00"; size_t szSelectLen = 2; - byte_t abtRx[1]; + uint8_t abtRx[1]; size_t szRxLen = 1; // Getting random Chip_ID if (!pn53x_initiator_transceive_bytes (pnd, abtInitiate, szInitiateLen, abtRx, &szRxLen, timeout)) { @@ -901,7 +901,7 @@ pn53x_initiator_select_passive_target_ext (nfc_device * pnd, } else if (nm.nmt == NMT_ISO14443B2CT) { // Some work to do before getting the UID... - byte_t abtReqt[]="\x10"; + uint8_t abtReqt[]="\x10"; size_t szReqtLen = 1; // Getting product code / fab code & store it in output buffer after the serial nr we'll obtain later if (!pn53x_initiator_transceive_bytes (pnd, abtReqt, szReqtLen, abtTargetsData+2, &szTargetsData, timeout) || szTargetsData != 2) { @@ -914,7 +914,7 @@ pn53x_initiator_select_passive_target_ext (nfc_device * pnd, if (nm.nmt == NMT_ISO14443B2CT) { if (szTargetsData != 2) return false; - byte_t abtRead[]="\xC4"; // Reading UID_MSB (Read address 4) + uint8_t abtRead[]="\xC4"; // Reading UID_MSB (Read address 4) size_t szReadLen = 1; if (!pn53x_initiator_transceive_bytes (pnd, abtRead, szReadLen, abtTargetsData+4, &szTargetsData, timeout) || szTargetsData != 2) { return false; @@ -930,7 +930,7 @@ pn53x_initiator_select_passive_target_ext (nfc_device * pnd, } if (nm.nmt == NMT_ISO14443BI) { // Select tag - byte_t abtAttrib[6]; + uint8_t abtAttrib[6]; size_t szAttribLen = sizeof(abtAttrib); memcpy(abtAttrib, abtTargetsData, szAttribLen); abtAttrib[1] = 0x0f; // ATTRIB @@ -968,7 +968,7 @@ pn53x_initiator_select_passive_target_ext (nfc_device * pnd, bool pn53x_initiator_select_passive_target (nfc_device * pnd, const nfc_modulation nm, - const byte_t * pbtInitData, const size_t szInitData, + const uint8_t * pbtInitData, const size_t szInitData, nfc_target * pnt) { return pn53x_initiator_select_passive_target_ext (pnd, nm, pbtInitData, szInitData, pnt, NULL); @@ -1020,7 +1020,7 @@ pn53x_initiator_poll_target (nfc_device * pnd, do { for (size_t p=0; pbPar) { @@ -1103,7 +1103,7 @@ pn53x_initiator_transceive_bits (nfc_device * pnd, const byte_t * pbtTx, const s // Send the frame to the PN53X chip and get the answer // We have to give the amount of bytes + (the command byte 0x42) - byte_t abtRx[PN53x_EXTENDED_FRAME__DATA_MAX_LEN]; + uint8_t abtRx[PN53x_EXTENDED_FRAME__DATA_MAX_LEN]; size_t szRx = sizeof(abtRx); if (!pn53x_transceive (pnd, abtCmd, szFrameBytes + 1, abtRx, &szRx, NULL)) return false; @@ -1134,11 +1134,11 @@ pn53x_initiator_transceive_bits (nfc_device * pnd, const byte_t * pbtTx, const s } bool -pn53x_initiator_transceive_bytes (nfc_device * pnd, const byte_t * pbtTx, const size_t szTx, byte_t * pbtRx, +pn53x_initiator_transceive_bytes (nfc_device * pnd, const uint8_t * pbtTx, const size_t szTx, uint8_t * pbtRx, size_t * pszRx, struct timeval *timeout) { size_t szExtraTxLen; - byte_t abtCmd[PN53x_EXTENDED_FRAME__DATA_MAX_LEN]; + uint8_t abtCmd[PN53x_EXTENDED_FRAME__DATA_MAX_LEN]; // We can not just send bytes without parity if while the PN53X expects we handled them if (!pnd->bPar) { @@ -1164,7 +1164,7 @@ pn53x_initiator_transceive_bytes (nfc_device * pnd, const byte_t * pbtTx, const // Send the frame to the PN53X chip and get the answer // We have to give the amount of bytes + (the two command bytes 0xD4, 0x42) - byte_t abtRx[PN53x_EXTENDED_FRAME__DATA_MAX_LEN]; + uint8_t abtRx[PN53x_EXTENDED_FRAME__DATA_MAX_LEN]; size_t szRx = sizeof(abtRx); if (!pn53x_transceive (pnd, abtCmd, szTx + szExtraTxLen, abtRx, &szRx, timeout)) return false; @@ -1262,8 +1262,8 @@ uint32_t __pn53x_get_timer(nfc_device * pnd, const uint8_t last_cmd_byte) } bool -pn53x_initiator_transceive_bits_timed (nfc_device * pnd, const byte_t * pbtTx, const size_t szTxBits, - const byte_t * pbtTxPar, byte_t * pbtRx, size_t * pszRxBits, byte_t * pbtRxPar, uint32_t * cycles) +pn53x_initiator_transceive_bits_timed (nfc_device * pnd, const uint8_t * pbtTx, const size_t szTxBits, + const uint8_t * pbtTxPar, uint8_t * pbtRx, size_t * pszRxBits, uint8_t * pbtRxPar, uint32_t * cycles) { // TODO Do something with these bytes... (void) pbtTxPar; @@ -1364,7 +1364,7 @@ pn53x_initiator_transceive_bits_timed (nfc_device * pnd, const byte_t * pbtTx, c } bool -pn53x_initiator_transceive_bytes_timed (nfc_device * pnd, const byte_t * pbtTx, const size_t szTx, byte_t * pbtRx, +pn53x_initiator_transceive_bytes_timed (nfc_device * pnd, const uint8_t * pbtTx, const size_t szTx, uint8_t * pbtRx, size_t * pszRx, uint32_t * cycles) { uint16_t i; @@ -1475,7 +1475,7 @@ pn53x_initiator_deselect_target (nfc_device * pnd) #define SAK_ISO14443_4_COMPLIANT 0x20 #define SAK_ISO18092_COMPLIANT 0x40 bool -pn53x_target_init (nfc_device * pnd, nfc_target * pnt, byte_t * pbtRx, size_t * pszRx) +pn53x_target_init (nfc_device * pnd, nfc_target * pnt, uint8_t * pbtRx, size_t * pszRx) { pn53x_reset_settings(pnd); @@ -1525,16 +1525,16 @@ pn53x_target_init (nfc_device * pnd, nfc_target * pnt, byte_t * pbtRx, size_t * if (!pn53x_write_register (pnd, PN53X_REG_CIU_TxAuto, SYMBOL_INITIAL_RF_ON, 0x04)) return false; - byte_t abtMifareParams[6]; - byte_t * pbtMifareParams = NULL; - byte_t * pbtTkt = NULL; + uint8_t abtMifareParams[6]; + uint8_t * pbtMifareParams = NULL; + uint8_t * pbtTkt = NULL; size_t szTkt = 0; - byte_t abtFeliCaParams[18]; - byte_t * pbtFeliCaParams = NULL; + uint8_t abtFeliCaParams[18]; + uint8_t * pbtFeliCaParams = NULL; - const byte_t * pbtNFCID3t = NULL; - const byte_t * pbtGBt = NULL; + const uint8_t * pbtNFCID3t = NULL; + const uint8_t * pbtGBt = NULL; size_t szGBt = 0; switch(pnt->nm.nmt) { @@ -1625,7 +1625,7 @@ pn53x_target_init (nfc_device * pnd, nfc_target * pnt, byte_t * pbtRx, size_t * bool targetActivated = false; while (!targetActivated) { - byte_t btActivatedMode; + uint8_t btActivatedMode; if(!pn53x_TgInitAsTarget(pnd, ptm, pbtMifareParams, pbtTkt, szTkt, pbtFeliCaParams, pbtNFCID3t, pbtGBt, szGBt, pbtRx, pszRx, &btActivatedMode)) { return false; @@ -1696,11 +1696,11 @@ pn53x_target_init (nfc_device * pnd, nfc_target * pnt, byte_t * pbtRx, size_t * } bool -pn53x_target_receive_bits (nfc_device * pnd, byte_t * pbtRx, size_t * pszRxBits, byte_t * pbtRxPar) +pn53x_target_receive_bits (nfc_device * pnd, uint8_t * pbtRx, size_t * pszRxBits, uint8_t * pbtRxPar) { - byte_t abtCmd[] = { TgGetInitiatorCommand }; + uint8_t abtCmd[] = { TgGetInitiatorCommand }; - byte_t abtRx[PN53x_EXTENDED_FRAME__DATA_MAX_LEN]; + uint8_t abtRx[PN53x_EXTENDED_FRAME__DATA_MAX_LEN]; size_t szRx = sizeof (abtRx); // Try to gather a received frame from the reader if (!pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), abtRx, &szRx, NULL)) @@ -1731,9 +1731,9 @@ pn53x_target_receive_bits (nfc_device * pnd, byte_t * pbtRx, size_t * pszRxBits, } bool -pn53x_target_receive_bytes (nfc_device * pnd, byte_t * pbtRx, size_t * pszRx, struct timeval *timeout) +pn53x_target_receive_bytes (nfc_device * pnd, uint8_t * pbtRx, size_t * pszRx, struct timeval *timeout) { - byte_t abtCmd[1]; + uint8_t abtCmd[1]; // XXX I think this is not a clean way to provide some kind of "EasyFraming" // but at the moment I have no more better than this @@ -1764,7 +1764,7 @@ pn53x_target_receive_bytes (nfc_device * pnd, byte_t * pbtRx, size_t * pszRx, st } // Try to gather a received frame from the reader - byte_t abtRx[PN53x_EXTENDED_FRAME__DATA_MAX_LEN]; + uint8_t abtRx[PN53x_EXTENDED_FRAME__DATA_MAX_LEN]; size_t szRx = sizeof (abtRx); if (!pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), abtRx, &szRx, timeout)) return false; @@ -1780,12 +1780,12 @@ pn53x_target_receive_bytes (nfc_device * pnd, byte_t * pbtRx, size_t * pszRx, st } bool -pn53x_target_send_bits (nfc_device * pnd, const byte_t * pbtTx, const size_t szTxBits, const byte_t * pbtTxPar) +pn53x_target_send_bits (nfc_device * pnd, const uint8_t * pbtTx, const size_t szTxBits, const uint8_t * pbtTxPar) { size_t szFrameBits = 0; size_t szFrameBytes = 0; uint8_t ui8Bits = 0; - byte_t abtCmd[PN53x_EXTENDED_FRAME__DATA_MAX_LEN] = { TgResponseToInitiator }; + uint8_t abtCmd[PN53x_EXTENDED_FRAME__DATA_MAX_LEN] = { TgResponseToInitiator }; // Check if we should prepare the parity bits ourself if (!pnd->bPar) { @@ -1818,9 +1818,9 @@ pn53x_target_send_bits (nfc_device * pnd, const byte_t * pbtTx, const size_t szT } bool -pn53x_target_send_bytes (nfc_device * pnd, const byte_t * pbtTx, const size_t szTx, struct timeval *timeout) +pn53x_target_send_bytes (nfc_device * pnd, const uint8_t * pbtTx, const size_t szTx, struct timeval *timeout) { - byte_t abtCmd[PN53x_EXTENDED_FRAME__DATA_MAX_LEN]; + uint8_t abtCmd[PN53x_EXTENDED_FRAME__DATA_MAX_LEN]; // We can not just send bytes without parity if while the PN53X expects we handled them if (!pnd->bPar) @@ -1935,14 +1935,14 @@ pn53x_strerror (const nfc_device * pnd) bool pn53x_RFConfiguration__RF_field (nfc_device * pnd, bool bEnable) { - byte_t abtCmd[] = { RFConfiguration, RFCI_FIELD, (bEnable) ? 0x01 : 0x00 }; + uint8_t abtCmd[] = { RFConfiguration, RFCI_FIELD, (bEnable) ? 0x01 : 0x00 }; return pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), NULL, NULL, NULL); } bool pn53x_RFConfiguration__Various_timings (nfc_device * pnd, const uint8_t fATR_RES_Timeout, const uint8_t fRetryTimeout) { - byte_t abtCmd[] = { + uint8_t abtCmd[] = { RFConfiguration, RFCI_TIMING, 0x00, // RFU @@ -1955,7 +1955,7 @@ pn53x_RFConfiguration__Various_timings (nfc_device * pnd, const uint8_t fATR_RES bool pn53x_RFConfiguration__MaxRtyCOM (nfc_device * pnd, const uint8_t MaxRtyCOM) { - byte_t abtCmd[] = { + uint8_t abtCmd[] = { RFConfiguration, RFCI_RETRY_DATA, MaxRtyCOM // MaxRtyCOM, default: 0x00 (no retry, only one try), inifite: 0xff @@ -1967,7 +1967,7 @@ bool pn53x_RFConfiguration__MaxRetries (nfc_device * pnd, const uint8_t MxRtyATR, const uint8_t MxRtyPSL, const uint8_t MxRtyPassiveActivation) { // Retry format: 0x00 means only 1 try, 0xff means infinite - byte_t abtCmd[] = { + uint8_t abtCmd[] = { RFConfiguration, RFCI_RETRY_SELECT, MxRtyATR, // MxRtyATR, default: active = 0xff, passive = 0x02 @@ -1980,7 +1980,7 @@ pn53x_RFConfiguration__MaxRetries (nfc_device * pnd, const uint8_t MxRtyATR, con bool pn53x_SetParameters (nfc_device * pnd, const uint8_t ui8Value) { - byte_t abtCmd[] = { SetParameters, ui8Value }; + uint8_t abtCmd[] = { SetParameters, ui8Value }; if(!pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), NULL, NULL, NULL)) { return false; @@ -1993,7 +1993,7 @@ pn53x_SetParameters (nfc_device * pnd, const uint8_t ui8Value) bool pn53x_SAMConfiguration (nfc_device * pnd, const pn532_sam_mode ui8Mode, struct timeval *timeout) { - byte_t abtCmd[] = { SAMConfiguration, ui8Mode, 0x00, 0x00 }; + uint8_t abtCmd[] = { SAMConfiguration, ui8Mode, 0x00, 0x00 }; size_t szCmd = sizeof(abtCmd); if (CHIP_DATA(pnd)->type != PN532) { @@ -2022,7 +2022,7 @@ pn53x_SAMConfiguration (nfc_device * pnd, const pn532_sam_mode ui8Mode, struct t bool pn53x_PowerDown (nfc_device * pnd) { - byte_t abtCmd[] = { PowerDown, 0xf0 }; + uint8_t abtCmd[] = { PowerDown, 0xf0 }; return (pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), NULL, NULL, NULL)); } @@ -2042,12 +2042,12 @@ pn53x_PowerDown (nfc_device * pnd) */ bool pn53x_InListPassiveTarget (nfc_device * pnd, - const pn53x_modulation pmInitModulation, const byte_t szMaxTargets, - const byte_t * pbtInitiatorData, const size_t szInitiatorData, - byte_t * pbtTargetsData, size_t * pszTargetsData, + const pn53x_modulation pmInitModulation, const uint8_t szMaxTargets, + const uint8_t * pbtInitiatorData, const size_t szInitiatorData, + uint8_t * pbtTargetsData, size_t * pszTargetsData, struct timeval* timeout) { - byte_t abtCmd[15] = { InListPassiveTarget }; + uint8_t abtCmd[15] = { InListPassiveTarget }; abtCmd[1] = szMaxTargets; // MaxTg @@ -2098,9 +2098,9 @@ pn53x_InDeselect (nfc_device * pnd, const uint8_t ui8Target) { if (CHIP_DATA(pnd)->type == RCS360) { // We should do act here *only* if a target was previously selected - byte_t abtStatus[PN53x_EXTENDED_FRAME__DATA_MAX_LEN]; + uint8_t abtStatus[PN53x_EXTENDED_FRAME__DATA_MAX_LEN]; size_t szStatus = sizeof(abtStatus); - byte_t abtCmdGetStatus[] = { GetGeneralStatus }; + uint8_t abtCmdGetStatus[] = { GetGeneralStatus }; if (!pn53x_transceive (pnd, abtCmdGetStatus, sizeof (abtCmdGetStatus), abtStatus, &szStatus, NULL)) { return false; } @@ -2108,10 +2108,10 @@ pn53x_InDeselect (nfc_device * pnd, const uint8_t ui8Target) return true; } // No much choice what to deselect actually... - byte_t abtCmdRcs360[] = { InDeselect, 0x01, 0x01 }; + uint8_t abtCmdRcs360[] = { InDeselect, 0x01, 0x01 }; return (pn53x_transceive (pnd, abtCmdRcs360, sizeof (abtCmdRcs360), NULL, NULL, NULL)); } - byte_t abtCmd[] = { InDeselect, ui8Target }; + uint8_t abtCmd[] = { InDeselect, ui8Target }; return (pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), NULL, NULL, NULL)); } @@ -2120,9 +2120,9 @@ pn53x_InRelease (nfc_device * pnd, const uint8_t ui8Target) { if (CHIP_DATA(pnd)->type == RCS360) { // We should do act here *only* if a target was previously selected - byte_t abtStatus[PN53x_EXTENDED_FRAME__DATA_MAX_LEN]; + uint8_t abtStatus[PN53x_EXTENDED_FRAME__DATA_MAX_LEN]; size_t szStatus = sizeof(abtStatus); - byte_t abtCmdGetStatus[] = { GetGeneralStatus }; + uint8_t abtCmdGetStatus[] = { GetGeneralStatus }; if (!pn53x_transceive (pnd, abtCmdGetStatus, sizeof (abtCmdGetStatus), abtStatus, &szStatus, NULL)) { return false; } @@ -2130,17 +2130,17 @@ pn53x_InRelease (nfc_device * pnd, const uint8_t ui8Target) return true; } // No much choice what to release actually... - byte_t abtCmdRcs360[] = { InRelease, 0x01, 0x01 }; + uint8_t abtCmdRcs360[] = { InRelease, 0x01, 0x01 }; return (pn53x_transceive (pnd, abtCmdRcs360, sizeof (abtCmdRcs360), NULL, NULL, NULL)); } - byte_t abtCmd[] = { InRelease, ui8Target }; + uint8_t abtCmd[] = { InRelease, ui8Target }; return (pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), NULL, NULL, NULL)); } bool pn53x_InAutoPoll (nfc_device * pnd, const pn53x_target_type * ppttTargetTypes, const size_t szTargetTypes, - const byte_t btPollNr, const byte_t btPeriod, nfc_target * pntTargets, size_t * pszTargetFound) + const uint8_t btPollNr, const uint8_t btPeriod, nfc_target * pntTargets, size_t * pszTargetFound) { if (CHIP_DATA(pnd)->type != PN532) { // This function is not supported by pn531 neither pn533 @@ -2150,12 +2150,12 @@ pn53x_InAutoPoll (nfc_device * pnd, // InAutoPoll frame looks like this { 0xd4, 0x60, 0x0f, 0x01, 0x00 } => { direction, command, pollnr, period, types... } size_t szTxInAutoPoll = 3 + szTargetTypes; - byte_t abtCmd[3+15] = { InAutoPoll, btPollNr, btPeriod }; + uint8_t abtCmd[3+15] = { InAutoPoll, btPollNr, btPeriod }; for (size_t n = 0; n < szTargetTypes; n++) { abtCmd[3 + n] = ppttTargetTypes[n]; } - byte_t abtRx[PN53x_EXTENDED_FRAME__DATA_MAX_LEN]; + uint8_t abtRx[PN53x_EXTENDED_FRAME__DATA_MAX_LEN]; size_t szRx = sizeof(abtRx); bool res = pn53x_transceive (pnd, abtCmd, szTxInAutoPoll, abtRx, &szRx, NULL); @@ -2165,7 +2165,7 @@ pn53x_InAutoPoll (nfc_device * pnd, *pszTargetFound = abtRx[0]; if (*pszTargetFound) { uint8_t ln; - byte_t *pbt = abtRx + 1; + uint8_t *pbt = abtRx + 1; /* 1st target */ // Target type pn53x_target_type ptt = *(pbt++); @@ -2203,13 +2203,13 @@ bool pn53x_InJumpForDEP (nfc_device * pnd, const nfc_dep_mode ndm, const nfc_baud_rate nbr, - const byte_t * pbtPassiveInitiatorData, - const byte_t * pbtNFCID3i, - const byte_t * pbtGBi, const size_t szGBi, + const uint8_t * pbtPassiveInitiatorData, + const uint8_t * pbtNFCID3i, + const uint8_t * pbtGBi, const size_t szGBi, nfc_target * pnt) { // Max frame size = 1 (Command) + 1 (ActPass) + 1 (Baud rate) + 1 (Next) + 5 (PassiveInitiatorData) + 10 (NFCID3) + 48 (General bytes) = 67 bytes - byte_t abtCmd[67] = { InJumpForDEP, (ndm == NDM_ACTIVE) ? 0x01 : 0x00 }; + uint8_t abtCmd[67] = { InJumpForDEP, (ndm == NDM_ACTIVE) ? 0x01 : 0x00 }; size_t offset = 4; // 1 byte for command, 1 byte for DEP mode (Active/Passive), 1 byte for baud rate, 1 byte for following parameters flag @@ -2263,7 +2263,7 @@ pn53x_InJumpForDEP (nfc_device * pnd, offset += szGBi; } - byte_t abtRx[PN53x_EXTENDED_FRAME__DATA_MAX_LEN]; + uint8_t abtRx[PN53x_EXTENDED_FRAME__DATA_MAX_LEN]; size_t szRx = sizeof (abtRx); // Try to find a target, call the transceive callback function of the current device if (!pn53x_transceive (pnd, abtCmd, offset, abtRx, &szRx, NULL)) @@ -2295,13 +2295,13 @@ pn53x_InJumpForDEP (nfc_device * pnd, bool pn53x_TgInitAsTarget (nfc_device * pnd, pn53x_target_mode ptm, - const byte_t * pbtMifareParams, - const byte_t * pbtTkt, size_t szTkt, - const byte_t * pbtFeliCaParams, - const byte_t * pbtNFCID3t, const byte_t * pbtGBt, const size_t szGBt, - byte_t * pbtRx, size_t * pszRx, byte_t * pbtModeByte) + const uint8_t * pbtMifareParams, + const uint8_t * pbtTkt, size_t szTkt, + const uint8_t * pbtFeliCaParams, + const uint8_t * pbtNFCID3t, const uint8_t * pbtGBt, const size_t szGBt, + uint8_t * pbtRx, size_t * pszRx, uint8_t * pbtModeByte) { - byte_t abtCmd[39 + 47 + 48] = { TgInitAsTarget }; // Worst case: 39-byte base, 47 bytes max. for General Bytes, 48 bytes max. for Historical Bytes + uint8_t abtCmd[39 + 47 + 48] = { TgInitAsTarget }; // Worst case: 39-byte base, 47 bytes max. for General Bytes, 48 bytes max. for Historical Bytes size_t szOptionalBytes = 0; // Clear the target init struct, reset to all zeros @@ -2329,7 +2329,7 @@ pn53x_TgInitAsTarget (nfc_device * pnd, pn53x_target_mode ptm, szOptionalBytes = szGBt; } } else { - abtCmd[36] = (byte_t)(szGBt); + abtCmd[36] = (uint8_t)(szGBt); if (szGBt) { memcpy (abtCmd+37, pbtGBt, szGBt); } @@ -2337,7 +2337,7 @@ pn53x_TgInitAsTarget (nfc_device * pnd, pn53x_target_mode ptm, } // Historical bytes (ISO/IEC 14443-4) if ((CHIP_DATA(pnd)->type != PN531) && (CHIP_DATA(pnd)->type != RCS360)) { // PN531 does not handle Historical Bytes - abtCmd[36+szOptionalBytes] = (byte_t)(szTkt); + abtCmd[36+szOptionalBytes] = (uint8_t)(szTkt); if (szTkt) { memcpy (abtCmd+37+szOptionalBytes, pbtTkt, szTkt); } @@ -2345,7 +2345,7 @@ pn53x_TgInitAsTarget (nfc_device * pnd, pn53x_target_mode ptm, } // Request the initialization as a target - byte_t abtRx[PN53x_EXTENDED_FRAME__DATA_MAX_LEN]; + uint8_t abtRx[PN53x_EXTENDED_FRAME__DATA_MAX_LEN]; size_t szRx = sizeof (abtRx); if (!pn53x_transceive (pnd, abtCmd, 36 + szOptionalBytes, abtRx, &szRx, NULL)) return false; @@ -2365,7 +2365,7 @@ pn53x_TgInitAsTarget (nfc_device * pnd, pn53x_target_mode ptm, } bool -pn53x_check_ack_frame (nfc_device * pnd, const byte_t * pbtRxFrame, const size_t szRxFrameLen) +pn53x_check_ack_frame (nfc_device * pnd, const uint8_t * pbtRxFrame, const size_t szRxFrameLen) { if (szRxFrameLen >= sizeof (pn53x_ack_frame)) { if (0 == memcmp (pbtRxFrame, pn53x_ack_frame, sizeof (pn53x_ack_frame))) { @@ -2379,7 +2379,7 @@ pn53x_check_ack_frame (nfc_device * pnd, const byte_t * pbtRxFrame, const size_t } bool -pn53x_check_error_frame (nfc_device * pnd, const byte_t * pbtRxFrame, const size_t szRxFrameLen) +pn53x_check_error_frame (nfc_device * pnd, const uint8_t * pbtRxFrame, const size_t szRxFrameLen) { if (szRxFrameLen >= sizeof (pn53x_error_frame)) { if (0 == memcmp (pbtRxFrame, pn53x_error_frame, sizeof (pn53x_error_frame))) { @@ -2398,7 +2398,7 @@ pn53x_check_error_frame (nfc_device * pnd, const byte_t * pbtRxFrame, const size * @note The first byte of pbtData is the Command Code (CC) */ bool -pn53x_build_frame (byte_t * pbtFrame, size_t * pszFrame, const byte_t * pbtData, const size_t szData) +pn53x_build_frame (uint8_t * pbtFrame, size_t * pszFrame, const uint8_t * pbtData, const size_t szData) { if (szData <= PN53x_NORMAL_FRAME__DATA_MAX_LEN) { // LEN - Packet length = data length (len) + checksum (1) + end of stream marker (1) @@ -2411,7 +2411,7 @@ pn53x_build_frame (byte_t * pbtFrame, size_t * pszFrame, const byte_t * pbtData, memcpy (pbtFrame + 6, pbtData, szData); // DCS - Calculate data payload checksum - byte_t btDCS = (256 - 0xD4); + uint8_t btDCS = (256 - 0xD4); for (size_t szPos = 0; szPos < szData; szPos++) { btDCS -= pbtData[szPos]; } @@ -2437,7 +2437,7 @@ pn53x_build_frame (byte_t * pbtFrame, size_t * pszFrame, const byte_t * pbtData, memcpy (pbtFrame + 9, pbtData, szData); // DCS - Calculate data payload checksum - byte_t btDCS = (256 - 0xD4); + uint8_t btDCS = (256 - 0xD4); for (size_t szPos = 0; szPos < szData; szPos++) { btDCS -= pbtData[szPos]; } diff --git a/libnfc/chips/pn53x.h b/libnfc/chips/pn53x.h index 4e1a53b..6a1d229 100644 --- a/libnfc/chips/pn53x.h +++ b/libnfc/chips/pn53x.h @@ -127,8 +127,8 @@ typedef enum { } pn53x_operating_mode; struct pn53x_io { - bool (*send)(nfc_device * pnd, const byte_t * pbtData, const size_t szData, struct timeval *timeout); - int (*receive)(nfc_device * pnd, byte_t * pbtData, const size_t szDataLen, struct timeval *timeout); + bool (*send)(nfc_device * pnd, const uint8_t * pbtData, const size_t szData, struct timeval *timeout); + int (*receive)(nfc_device * pnd, uint8_t * pbtData, const size_t szDataLen, struct timeval *timeout); }; /* defines */ @@ -252,19 +252,19 @@ typedef enum { PTM_ISO14443_4_PICC_ONLY = 0x04 } pn53x_target_mode; -extern const byte_t pn53x_ack_frame[6]; -extern const byte_t pn53x_nack_frame[6]; +extern const uint8_t pn53x_ack_frame[6]; +extern const uint8_t pn53x_nack_frame[6]; bool pn53x_init(nfc_device * pnd); -bool pn53x_transceive (nfc_device * pnd, const byte_t * pbtTx, const size_t szTx, byte_t * pbtRx, size_t *pszRx, struct timeval *timeout); +bool pn53x_transceive (nfc_device * pnd, const uint8_t * pbtTx, const size_t szTx, uint8_t * pbtRx, size_t *pszRx, struct timeval *timeout); bool pn53x_set_parameters (nfc_device * pnd, const uint8_t ui8Value, const bool bEnable); bool pn53x_set_tx_bits (nfc_device * pnd, const uint8_t ui8Bits); -bool pn53x_wrap_frame (const byte_t * pbtTx, const size_t szTxBits, const byte_t * pbtTxPar, byte_t * pbtFrame, +bool pn53x_wrap_frame (const uint8_t * pbtTx, const size_t szTxBits, const uint8_t * pbtTxPar, uint8_t * pbtFrame, size_t * pszFrameBits); -bool pn53x_unwrap_frame (const byte_t * pbtFrame, const size_t szFrameBits, byte_t * pbtRx, size_t * pszRxBits, - byte_t * pbtRxPar); -bool pn53x_decode_target_data (const byte_t * pbtRawData, size_t szRawData, +bool pn53x_unwrap_frame (const uint8_t * pbtFrame, const size_t szFrameBits, uint8_t * pbtRx, size_t * pszRxBits, + uint8_t * pbtRxPar); +bool pn53x_decode_target_data (const uint8_t * pbtRawData, size_t szRawData, pn53x_type chip_type, nfc_modulationype nmt, nfc_target_info * pnti); bool pn53x_read_register (nfc_device * pnd, uint16_t ui16Reg, uint8_t * ui8Value); @@ -278,7 +278,7 @@ bool pn53x_idle (nfc_device * pnd); bool pn53x_initiator_init (nfc_device * pnd); bool pn53x_initiator_select_passive_target (nfc_device * pnd, const nfc_modulation nm, - const byte_t * pbtInitData, const size_t szInitData, + const uint8_t * pbtInitData, const size_t szInitData, nfc_target * pnt); bool pn53x_initiator_poll_target (nfc_device * pnd, const nfc_modulation * pnmModulations, const size_t szModulations, @@ -288,24 +288,24 @@ bool pn53x_initiator_select_dep_target (nfc_device * pnd, const nfc_dep_mode ndm, const nfc_baud_rate nbr, const nfc_dep_info * pndiInitiator, nfc_target * pnt); -bool pn53x_initiator_transceive_bits (nfc_device * pnd, const byte_t * pbtTx, const size_t szTxBits, - const byte_t * pbtTxPar, byte_t * pbtRx, size_t * pszRxBits, - byte_t * pbtRxPar); -bool pn53x_initiator_transceive_bytes (nfc_device * pnd, const byte_t * pbtTx, const size_t szTx, - byte_t * pbtRx, size_t * pszRx, struct timeval *timeout); -bool pn53x_initiator_transceive_bits_timed (nfc_device * pnd, const byte_t * pbtTx, const size_t szTxBits, - const byte_t * pbtTxPar, byte_t * pbtRx, size_t * pszRxBits, - byte_t * pbtRxPar, uint32_t * cycles); -bool pn53x_initiator_transceive_bytes_timed (nfc_device * pnd, const byte_t * pbtTx, const size_t szTx, - byte_t * pbtRx, size_t * pszRx, uint32_t * cycles); +bool pn53x_initiator_transceive_bits (nfc_device * pnd, const uint8_t * pbtTx, const size_t szTxBits, + const uint8_t * pbtTxPar, uint8_t * pbtRx, size_t * pszRxBits, + uint8_t * pbtRxPar); +bool pn53x_initiator_transceive_bytes (nfc_device * pnd, const uint8_t * pbtTx, const size_t szTx, + uint8_t * pbtRx, size_t * pszRx, struct timeval *timeout); +bool pn53x_initiator_transceive_bits_timed (nfc_device * pnd, const uint8_t * pbtTx, const size_t szTxBits, + const uint8_t * pbtTxPar, uint8_t * pbtRx, size_t * pszRxBits, + uint8_t * pbtRxPar, uint32_t * cycles); +bool pn53x_initiator_transceive_bytes_timed (nfc_device * pnd, const uint8_t * pbtTx, const size_t szTx, + uint8_t * pbtRx, size_t * pszRx, uint32_t * cycles); bool pn53x_initiator_deselect_target (nfc_device * pnd); // NFC device as Target functions -bool pn53x_target_init (nfc_device * pnd, nfc_target * pnt, byte_t * pbtRx, size_t * pszRx); -bool pn53x_target_receive_bits (nfc_device * pnd, byte_t * pbtRx, size_t * pszRxBits, byte_t * pbtRxPar); -bool pn53x_target_receive_bytes (nfc_device * pnd, byte_t * pbtRx, size_t * pszRx, struct timeval *timeout); -bool pn53x_target_send_bits (nfc_device * pnd, const byte_t * pbtTx, const size_t szTxBits, const byte_t * pbtTxPar); -bool pn53x_target_send_bytes (nfc_device * pnd, const byte_t * pbtTx, const size_t szTx, struct timeval *timeout); +bool pn53x_target_init (nfc_device * pnd, nfc_target * pnt, uint8_t * pbtRx, size_t * pszRx); +bool pn53x_target_receive_bits (nfc_device * pnd, uint8_t * pbtRx, size_t * pszRxBits, uint8_t * pbtRxPar); +bool pn53x_target_receive_bytes (nfc_device * pnd, uint8_t * pbtRx, size_t * pszRx, struct timeval *timeout); +bool pn53x_target_send_bits (nfc_device * pnd, const uint8_t * pbtTx, const size_t szTxBits, const uint8_t * pbtTxPar); +bool pn53x_target_send_bytes (nfc_device * pnd, const uint8_t * pbtTx, const size_t szTx, struct timeval *timeout); // Error handling functions const char *pn53x_strerror (const nfc_device * pnd); @@ -315,26 +315,26 @@ bool pn53x_SetParameters (nfc_device * pnd, const uint8_t ui8Value); bool pn53x_SAMConfiguration (nfc_device * pnd, const pn532_sam_mode mode, struct timeval *timeout); bool pn53x_PowerDown (nfc_device * pnd); bool pn53x_InListPassiveTarget (nfc_device * pnd, const pn53x_modulation pmInitModulation, - const byte_t szMaxTargets, const byte_t * pbtInitiatorData, - const size_t szInitiatorDataLen, byte_t * pbtTargetsData, size_t * pszTargetsData, + const uint8_t szMaxTargets, const uint8_t * pbtInitiatorData, + const size_t szInitiatorDataLen, uint8_t * pbtTargetsData, size_t * pszTargetsData, struct timeval *timeout); bool pn53x_InDeselect (nfc_device * pnd, const uint8_t ui8Target); bool pn53x_InRelease (nfc_device * pnd, const uint8_t ui8Target); bool pn53x_InAutoPoll (nfc_device * pnd, const pn53x_target_type * ppttTargetTypes, const size_t szTargetTypes, - const byte_t btPollNr, const byte_t btPeriod, nfc_target * pntTargets, + const uint8_t btPollNr, const uint8_t btPeriod, nfc_target * pntTargets, size_t * pszTargetFound); bool pn53x_InJumpForDEP (nfc_device * pnd, const nfc_dep_mode ndm, const nfc_baud_rate nbr, - const byte_t * pbtPassiveInitiatorData, - const byte_t * pbtNFCID3i, - const byte_t * pbtGB, const size_t szGB, + const uint8_t * pbtPassiveInitiatorData, + const uint8_t * pbtNFCID3i, + const uint8_t * pbtGB, const size_t szGB, nfc_target * pnt); bool pn53x_TgInitAsTarget (nfc_device * pnd, pn53x_target_mode ptm, - const byte_t * pbtMifareParams, - const byte_t * pbtTkt, size_t szTkt, - const byte_t * pbtFeliCaParams, - const byte_t * pbtNFCID3t, const byte_t * pbtGB, const size_t szGB, - byte_t * pbtRx, size_t * pszRx, byte_t * pbtModeByte); + const uint8_t * pbtMifareParams, + const uint8_t * pbtTkt, size_t szTkt, + const uint8_t * pbtFeliCaParams, + const uint8_t * pbtNFCID3t, const uint8_t * pbtGB, const size_t szGB, + uint8_t * pbtRx, size_t * pszRx, uint8_t * pbtModeByte); // RFConfiguration bool pn53x_RFConfiguration__RF_field (nfc_device * pnd, bool bEnable); @@ -343,9 +343,9 @@ bool pn53x_RFConfiguration__MaxRtyCOM (nfc_device * pnd, const uint8_t MaxRty bool pn53x_RFConfiguration__MaxRetries (nfc_device * pnd, const uint8_t MxRtyATR, const uint8_t MxRtyPSL, const uint8_t MxRtyPassiveActivation); // Misc -bool pn53x_check_ack_frame (nfc_device * pnd, const byte_t * pbtRxFrame, const size_t szRxFrameLen); -bool pn53x_check_error_frame (nfc_device * pnd, const byte_t * pbtRxFrame, const size_t szRxFrameLen); -bool pn53x_build_frame (byte_t * pbtFrame, size_t * pszFrame, const byte_t * pbtData, const size_t szData); +bool pn53x_check_ack_frame (nfc_device * pnd, const uint8_t * pbtRxFrame, const size_t szRxFrameLen); +bool pn53x_check_error_frame (nfc_device * pnd, const uint8_t * pbtRxFrame, const size_t szRxFrameLen); +bool pn53x_build_frame (uint8_t * pbtFrame, size_t * pszFrame, const uint8_t * pbtData, const size_t szData); void pn53x_data_new (nfc_device * pnd, const struct pn53x_io* io); void pn53x_data_free (nfc_device * pnd); diff --git a/libnfc/drivers/acr122.c b/libnfc/drivers/acr122.c index 3c3f349..15bc719 100644 --- a/libnfc/drivers/acr122.c +++ b/libnfc/drivers/acr122.c @@ -89,7 +89,7 @@ const char *supported_devices[] = { struct acr122_data { SCARDHANDLE hCard; SCARD_IO_REQUEST ioCard; - byte_t abtRx[ACR122_RESPONSE_LEN]; + uint8_t abtRx[ACR122_RESPONSE_LEN]; size_t szRx; }; @@ -310,7 +310,7 @@ acr122_disconnect (nfc_device * pnd) } bool -acr122_send (nfc_device * pnd, const byte_t * pbtData, const size_t szData, struct timeval *timeout) +acr122_send (nfc_device * pnd, const uint8_t * pbtData, const size_t szData, struct timeval *timeout) { // FIXME: timeout is not handled (void) timeout; @@ -323,7 +323,7 @@ acr122_send (nfc_device * pnd, const byte_t * pbtData, const size_t szData, stru // Prepare and transmit the send buffer const size_t szTxBuf = szData + 6; - byte_t abtTxBuf[ACR122_WRAP_LEN + ACR122_COMMAND_LEN] = { 0xFF, 0x00, 0x00, 0x00, szData + 1, 0xD4 }; + uint8_t abtTxBuf[ACR122_WRAP_LEN + ACR122_COMMAND_LEN] = { 0xFF, 0x00, 0x00, 0x00, szData + 1, 0xD4 }; memcpy (abtTxBuf + 6, pbtData, szData); LOG_HEX ("TX", abtTxBuf, szTxBuf); @@ -381,13 +381,13 @@ acr122_send (nfc_device * pnd, const byte_t * pbtData, const size_t szData, stru } int -acr122_receive (nfc_device * pnd, byte_t * pbtData, const size_t szData, struct timeval *timeout) +acr122_receive (nfc_device * pnd, uint8_t * pbtData, const size_t szData, struct timeval *timeout) { // FIXME: timeout is not handled (void) timeout; int len; - byte_t abtRxCmd[5] = { 0xFF, 0xC0, 0x00, 0x00 }; + uint8_t abtRxCmd[5] = { 0xFF, 0xC0, 0x00, 0x00 }; if (DRIVER_DATA (pnd)->ioCard.dwProtocol == SCARD_PROTOCOL_T0) { /* @@ -424,16 +424,16 @@ acr122_receive (nfc_device * pnd, byte_t * pbtData, const size_t szData, struct char * acr122_firmware (nfc_device *pnd) { - byte_t abtGetFw[5] = { 0xFF, 0x00, 0x48, 0x00, 0x00 }; + uint8_t abtGetFw[5] = { 0xFF, 0x00, 0x48, 0x00, 0x00 }; uint32_t uiResult; static char abtFw[11]; DWORD dwFwLen = sizeof (abtFw); memset (abtFw, 0x00, sizeof (abtFw)); if (DRIVER_DATA (pnd)->ioCard.dwProtocol == SCARD_PROTOCOL_UNDEFINED) { - uiResult = SCardControl (DRIVER_DATA (pnd)->hCard, IOCTL_CCID_ESCAPE_SCARD_CTL_CODE, abtGetFw, sizeof (abtGetFw), (byte_t *) abtFw, dwFwLen-1, &dwFwLen); + uiResult = SCardControl (DRIVER_DATA (pnd)->hCard, IOCTL_CCID_ESCAPE_SCARD_CTL_CODE, abtGetFw, sizeof (abtGetFw), (uint8_t *) abtFw, dwFwLen-1, &dwFwLen); } else { - uiResult = SCardTransmit (DRIVER_DATA (pnd)->hCard, &(DRIVER_DATA (pnd)->ioCard), abtGetFw, sizeof (abtGetFw), NULL, (byte_t *) abtFw, &dwFwLen); + uiResult = SCardTransmit (DRIVER_DATA (pnd)->hCard, &(DRIVER_DATA (pnd)->ioCard), abtGetFw, sizeof (abtGetFw), NULL, (uint8_t *) abtFw, &dwFwLen); } if (uiResult != SCARD_S_SUCCESS) { @@ -447,8 +447,8 @@ acr122_firmware (nfc_device *pnd) bool acr122_led_red (nfc_device *pnd, bool bOn) { - byte_t abtLed[9] = { 0xFF, 0x00, 0x40, 0x05, 0x04, 0x00, 0x00, 0x00, 0x00 }; - byte_t abtBuf[2]; + uint8_t abtLed[9] = { 0xFF, 0x00, 0x40, 0x05, 0x04, 0x00, 0x00, 0x00, 0x00 }; + uint8_t abtBuf[2]; DWORD dwBufLen = sizeof (abtBuf); (void) bOn; if (DRIVER_DATA (pnd)->ioCard.dwProtocol == SCARD_PROTOCOL_UNDEFINED) { diff --git a/libnfc/drivers/acr122.h b/libnfc/drivers/acr122.h index a139cb2..3f91047 100644 --- a/libnfc/drivers/acr122.h +++ b/libnfc/drivers/acr122.h @@ -30,8 +30,8 @@ bool acr122_probe (nfc_connstring connstrings[], size_t connstrings_len, size // Functions used by developer to handle connection to this device nfc_device *acr122_connect (const nfc_connstring connstring); -bool acr122_send (nfc_device * pnd, const byte_t * pbtData, const size_t szData, struct timeval *timeout); -int acr122_receive (nfc_device * pnd, byte_t * pbtData, const size_t szData, struct timeval *timeout); +bool acr122_send (nfc_device * pnd, const uint8_t * pbtData, const size_t szData, struct timeval *timeout); +int acr122_receive (nfc_device * pnd, uint8_t * pbtData, const size_t szData, struct timeval *timeout); void acr122_disconnect (nfc_device * pnd); extern const struct nfc_driver_t acr122_driver; diff --git a/libnfc/drivers/arygon.c b/libnfc/drivers/arygon.c index d39cd07..b90f124 100644 --- a/libnfc/drivers/arygon.c +++ b/libnfc/drivers/arygon.c @@ -84,9 +84,9 @@ struct arygon_data { #endif }; -static const byte_t arygon_error_none[] = "FF000000\x0d\x0a"; -static const byte_t arygon_error_incomplete_command[] = "FF0C0000\x0d\x0a"; -static const byte_t arygon_error_unknown_mode[] = "FF060000\x0d\x0a"; +static const uint8_t arygon_error_none[] = "FF000000\x0d\x0a"; +static const uint8_t arygon_error_incomplete_command[] = "FF0C0000\x0d\x0a"; +static const uint8_t arygon_error_unknown_mode[] = "FF060000\x0d\x0a"; bool arygon_reset_tama (nfc_device * pnd); void arygon_firmware (nfc_device * pnd, char * str); @@ -304,12 +304,12 @@ arygon_disconnect (nfc_device * pnd) #define ARYGON_TX_BUFFER_LEN (PN53x_NORMAL_FRAME__DATA_MAX_LEN + PN53x_NORMAL_FRAME__OVERHEAD + 1) #define ARYGON_RX_BUFFER_LEN (PN53x_EXTENDED_FRAME__DATA_MAX_LEN + PN53x_EXTENDED_FRAME__OVERHEAD) bool -arygon_tama_send (nfc_device * pnd, const byte_t * pbtData, const size_t szData, struct timeval *timeout) +arygon_tama_send (nfc_device * pnd, const uint8_t * pbtData, const size_t szData, struct timeval *timeout) { // Before sending anything, we need to discard from any junk bytes uart_flush_input (DRIVER_DATA(pnd)->port); - byte_t abtFrame[ARYGON_TX_BUFFER_LEN] = { DEV_ARYGON_PROTOCOL_TAMA, 0x00, 0x00, 0xff }; // Every packet must start with "0x32 0x00 0x00 0xff" + uint8_t abtFrame[ARYGON_TX_BUFFER_LEN] = { DEV_ARYGON_PROTOCOL_TAMA, 0x00, 0x00, 0xff }; // Every packet must start with "0x32 0x00 0x00 0xff" size_t szFrame = 0; if (szData > PN53x_NORMAL_FRAME__DATA_MAX_LEN) { @@ -331,7 +331,7 @@ arygon_tama_send (nfc_device * pnd, const byte_t * pbtData, const size_t szData, return false; } - byte_t abtRxBuf[6]; + uint8_t abtRxBuf[6]; res = uart_receive (DRIVER_DATA (pnd)->port, abtRxBuf, sizeof (abtRxBuf), 0, timeout); if (res != 0) { log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Unable to read ACK"); @@ -357,7 +357,7 @@ int arygon_abort (nfc_device *pnd) { // Send a valid TAMA packet to wakup the PN53x (we will not have an answer, according to Arygon manual) - byte_t dummy[] = { 0x32, 0x00, 0x00, 0xff, 0x09, 0xf7, 0xd4, 0x00, 0x00, 0x6c, 0x69, 0x62, 0x6e, 0x66, 0x63, 0xbe, 0x00 }; + uint8_t dummy[] = { 0x32, 0x00, 0x00, 0xff, 0x09, 0xf7, 0xd4, 0x00, 0x00, 0x6c, 0x69, 0x62, 0x6e, 0x66, 0x63, 0xbe, 0x00 }; uart_send (DRIVER_DATA (pnd)->port, dummy, sizeof (dummy), NULL); @@ -366,9 +366,9 @@ arygon_abort (nfc_device *pnd) } int -arygon_tama_receive (nfc_device * pnd, byte_t * pbtData, const size_t szDataLen, struct timeval *timeout) +arygon_tama_receive (nfc_device * pnd, uint8_t * pbtData, const size_t szDataLen, struct timeval *timeout) { - byte_t abtRxBuf[5]; + uint8_t abtRxBuf[5]; size_t len; void * abort_p = NULL; @@ -393,7 +393,7 @@ arygon_tama_receive (nfc_device * pnd, byte_t * pbtData, const size_t szDataLen, return -1; } - const byte_t pn53x_preamble[3] = { 0x00, 0x00, 0xff }; + const uint8_t pn53x_preamble[3] = { 0x00, 0x00, 0xff }; if (0 != (memcmp (abtRxBuf, pn53x_preamble, 3))) { log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Frame preamble+start code mismatch"); pnd->iLastError = ECOMIO; @@ -462,7 +462,7 @@ arygon_tama_receive (nfc_device * pnd, byte_t * pbtData, const size_t szDataLen, return -1; } - byte_t btDCS = (256 - 0xD5); + uint8_t btDCS = (256 - 0xD5); btDCS -= CHIP_DATA (pnd)->ui8LastCommand + 1; for (size_t szPos = 0; szPos < len; szPos++) { btDCS -= pbtData[szPos]; @@ -486,8 +486,8 @@ arygon_tama_receive (nfc_device * pnd, byte_t * pbtData, const size_t szDataLen, void arygon_firmware (nfc_device * pnd, char * str) { - const byte_t arygon_firmware_version_cmd[] = { DEV_ARYGON_PROTOCOL_ARYGON_ASCII, 'a', 'v' }; - byte_t abtRx[16]; + const uint8_t arygon_firmware_version_cmd[] = { DEV_ARYGON_PROTOCOL_ARYGON_ASCII, 'a', 'v' }; + uint8_t abtRx[16]; size_t szRx = sizeof(abtRx); @@ -503,7 +503,7 @@ arygon_firmware (nfc_device * pnd, char * str) } if ( 0 == memcmp (abtRx, arygon_error_none, 6)) { - byte_t * p = abtRx + 6; + uint8_t * p = abtRx + 6; unsigned int szData; sscanf ((const char*)p, "%02x%s", &szData, p); memcpy (str, p, szData); @@ -514,8 +514,8 @@ arygon_firmware (nfc_device * pnd, char * str) bool arygon_reset_tama (nfc_device * pnd) { - const byte_t arygon_reset_tama_cmd[] = { DEV_ARYGON_PROTOCOL_ARYGON_ASCII, 'a', 'r' }; - byte_t abtRx[10]; // Attempted response is 10 bytes long + const uint8_t arygon_reset_tama_cmd[] = { DEV_ARYGON_PROTOCOL_ARYGON_ASCII, 'a', 'r' }; + uint8_t abtRx[10]; // Attempted response is 10 bytes long size_t szRx = sizeof(abtRx); int res; diff --git a/libnfc/drivers/arygon.h b/libnfc/drivers/arygon.h index 482a97b..f5014b3 100644 --- a/libnfc/drivers/arygon.h +++ b/libnfc/drivers/arygon.h @@ -35,8 +35,8 @@ bool arygon_probe (nfc_connstring connstrings[], size_t connstrings_len, size nfc_device *arygon_connect (const nfc_connstring connstring); void arygon_disconnect (nfc_device * pnd); -bool arygon_tama_send (nfc_device * pnd, const byte_t * pbtData, const size_t szData, struct timeval *timeout); -int arygon_tama_receive (nfc_device * pnd, byte_t * pbtData, const size_t szDat, struct timeval *timeouta); +bool arygon_tama_send (nfc_device * pnd, const uint8_t * pbtData, const size_t szData, struct timeval *timeout); +int arygon_tama_receive (nfc_device * pnd, uint8_t * pbtData, const size_t szDat, struct timeval *timeouta); extern const struct nfc_driver_t arygon_driver; diff --git a/libnfc/drivers/pn532_uart.c b/libnfc/drivers/pn532_uart.c index 45ec262..47b7027 100644 --- a/libnfc/drivers/pn532_uart.c +++ b/libnfc/drivers/pn532_uart.c @@ -281,7 +281,7 @@ int pn532_uart_wakeup (nfc_device * pnd) { /* High Speed Unit (HSU) wake up consist to send 0x55 and wait a "long" delay for PN532 being wakeup. */ - const byte_t pn532_wakeup_preamble[] = { 0x55, 0x55, 0x00, 0x00, 0x00 }; + const uint8_t pn532_wakeup_preamble[] = { 0x55, 0x55, 0x00, 0x00, 0x00 }; int res = uart_send (DRIVER_DATA(pnd)->port, pn532_wakeup_preamble, sizeof (pn532_wakeup_preamble), NULL); CHIP_DATA(pnd)->power_mode = NORMAL; // PN532 should now be awake return res; @@ -289,7 +289,7 @@ pn532_uart_wakeup (nfc_device * pnd) #define PN532_BUFFER_LEN (PN53x_EXTENDED_FRAME__DATA_MAX_LEN + PN53x_EXTENDED_FRAME__OVERHEAD) bool -pn532_uart_send (nfc_device * pnd, const byte_t * pbtData, const size_t szData, struct timeval *timeout) +pn532_uart_send (nfc_device * pnd, const uint8_t * pbtData, const size_t szData, struct timeval *timeout) { // Before sending anything, we need to discard from any junk bytes uart_flush_input (DRIVER_DATA(pnd)->port); @@ -320,7 +320,7 @@ pn532_uart_send (nfc_device * pnd, const byte_t * pbtData, const size_t szData, break; }; - byte_t abtFrame[PN532_BUFFER_LEN] = { 0x00, 0x00, 0xff }; // Every packet must start with "00 00 ff" + uint8_t abtFrame[PN532_BUFFER_LEN] = { 0x00, 0x00, 0xff }; // Every packet must start with "00 00 ff" size_t szFrame = 0; if (!pn53x_build_frame (abtFrame, &szFrame, pbtData, szData)) { @@ -335,7 +335,7 @@ pn532_uart_send (nfc_device * pnd, const byte_t * pbtData, const size_t szData, return false; } - byte_t abtRxBuf[6]; + uint8_t abtRxBuf[6]; res = uart_receive (DRIVER_DATA(pnd)->port, abtRxBuf, 6, 0, timeout); if (res != 0) { log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Unable to read ACK"); @@ -352,9 +352,9 @@ pn532_uart_send (nfc_device * pnd, const byte_t * pbtData, const size_t szData, } int -pn532_uart_receive (nfc_device * pnd, byte_t * pbtData, const size_t szDataLen, struct timeval *timeout) +pn532_uart_receive (nfc_device * pnd, uint8_t * pbtData, const size_t szDataLen, struct timeval *timeout) { - byte_t abtRxBuf[5]; + uint8_t abtRxBuf[5]; size_t len; void * abort_p = NULL; @@ -376,7 +376,7 @@ pn532_uart_receive (nfc_device * pnd, byte_t * pbtData, const size_t szDataLen, return -1; } - const byte_t pn53x_preamble[3] = { 0x00, 0x00, 0xff }; + const uint8_t pn53x_preamble[3] = { 0x00, 0x00, 0xff }; if (0 != (memcmp (abtRxBuf, pn53x_preamble, 3))) { log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Frame preamble+start code mismatch"); pnd->iLastError = ECOMIO; @@ -454,7 +454,7 @@ pn532_uart_receive (nfc_device * pnd, byte_t * pbtData, const size_t szDataLen, return -1; } - byte_t btDCS = (256 - 0xD5); + uint8_t btDCS = (256 - 0xD5); btDCS -= CHIP_DATA (pnd)->ui8LastCommand + 1; for (size_t szPos = 0; szPos < len; szPos++) { btDCS -= pbtData[szPos]; diff --git a/libnfc/drivers/pn532_uart.h b/libnfc/drivers/pn532_uart.h index 20e0ca6..6f89541 100644 --- a/libnfc/drivers/pn532_uart.h +++ b/libnfc/drivers/pn532_uart.h @@ -33,8 +33,8 @@ bool pn532_uart_probe (nfc_connstring connstrings[], size_t connstrings_len, nfc_device *pn532_uart_connect (const nfc_connstring connstring); void pn532_uart_disconnect (nfc_device * pnd); -bool pn532_uart_send (nfc_device * pnd, const byte_t * pbtData, const size_t szData, struct timeval *timeout); -int pn532_uart_receive (nfc_device * pnd, byte_t * pbtData, const size_t szData, struct timeval *timeout); +bool pn532_uart_send (nfc_device * pnd, const uint8_t * pbtData, const size_t szData, struct timeval *timeout); +int pn532_uart_receive (nfc_device * pnd, uint8_t * pbtData, const size_t szData, struct timeval *timeout); extern const struct nfc_driver_t pn532_uart_driver; diff --git a/libnfc/drivers/pn53x_usb.c b/libnfc/drivers/pn53x_usb.c index 41e92ca..c76bee9 100644 --- a/libnfc/drivers/pn53x_usb.c +++ b/libnfc/drivers/pn53x_usb.c @@ -121,7 +121,7 @@ bool pn53x_usb_get_usb_device_name (struct usb_device *dev, usb_dev_handle *udev bool pn53x_usb_init (nfc_device *pnd); int -pn53x_usb_bulk_read (struct pn53x_usb_data *data, byte_t abtRx[], const size_t szRx, struct timeval *timeout) +pn53x_usb_bulk_read (struct pn53x_usb_data *data, uint8_t abtRx[], const size_t szRx, struct timeval *timeout) { int timeout_ms = USB_INFINITE_TIMEOUT; if (timeout) { @@ -143,7 +143,7 @@ pn53x_usb_bulk_read (struct pn53x_usb_data *data, byte_t abtRx[], const size_t s } int -pn53x_usb_bulk_write (struct pn53x_usb_data *data, byte_t abtTx[], const size_t szTx, struct timeval *timeout) +pn53x_usb_bulk_write (struct pn53x_usb_data *data, uint8_t abtTx[], const size_t szTx, struct timeval *timeout) { LOG_HEX ("TX", abtTx, szTx); int timeout_ms = USB_INFINITE_TIMEOUT; @@ -519,9 +519,9 @@ pn53x_usb_disconnect (nfc_device * pnd) #define PN53X_USB_BUFFER_LEN (PN53x_EXTENDED_FRAME__DATA_MAX_LEN + PN53x_EXTENDED_FRAME__OVERHEAD) bool -pn53x_usb_send (nfc_device * pnd, const byte_t * pbtData, const size_t szData, struct timeval *timeout) +pn53x_usb_send (nfc_device * pnd, const uint8_t * pbtData, const size_t szData, struct timeval *timeout) { - byte_t abtFrame[PN53X_USB_BUFFER_LEN] = { 0x00, 0x00, 0xff }; // Every packet must start with "00 00 ff" + uint8_t abtFrame[PN53X_USB_BUFFER_LEN] = { 0x00, 0x00, 0xff }; // Every packet must start with "00 00 ff" size_t szFrame = 0; pn53x_build_frame (abtFrame, &szFrame, pbtData, szData); @@ -533,7 +533,7 @@ pn53x_usb_send (nfc_device * pnd, const byte_t * pbtData, const size_t szData, s return false; } - byte_t abtRxBuf[PN53X_USB_BUFFER_LEN]; + uint8_t abtRxBuf[PN53X_USB_BUFFER_LEN]; res = pn53x_usb_bulk_read (DRIVER_DATA (pnd), abtRxBuf, sizeof (abtRxBuf), timeout); if (res < 0) { pnd->iLastError = ECOMIO; @@ -552,7 +552,7 @@ pn53x_usb_send (nfc_device * pnd, const byte_t * pbtData, const size_t szData, s // pn53x_usb_receive()) will be able to retreive the correct response // packet. // FIXME Sony reader is also affected by this bug but NACK is not supported - int res = pn53x_usb_bulk_write (DRIVER_DATA (pnd), (byte_t *)pn53x_nack_frame, sizeof(pn53x_nack_frame), timeout); + int res = pn53x_usb_bulk_write (DRIVER_DATA (pnd), (uint8_t *)pn53x_nack_frame, sizeof(pn53x_nack_frame), timeout); if (res < 0) { pnd->iLastError = ECOMIO; // try to interrupt current device state @@ -565,12 +565,12 @@ pn53x_usb_send (nfc_device * pnd, const byte_t * pbtData, const size_t szData, s } int -pn53x_usb_receive (nfc_device * pnd, byte_t * pbtData, const size_t szDataLen, struct timeval *timeout) +pn53x_usb_receive (nfc_device * pnd, uint8_t * pbtData, const size_t szDataLen, struct timeval *timeout) { size_t len; off_t offset = 0; - byte_t abtRxBuf[PN53X_USB_BUFFER_LEN]; + uint8_t abtRxBuf[PN53X_USB_BUFFER_LEN]; int res; /* @@ -627,7 +627,7 @@ read: return -1; } - const byte_t pn53x_preamble[3] = { 0x00, 0x00, 0xff }; + const uint8_t pn53x_preamble[3] = { 0x00, 0x00, 0xff }; if (0 != (memcmp (abtRxBuf, pn53x_preamble, 3))) { log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Frame preamble+start code mismatch"); pnd->iLastError = ECOMIO; @@ -691,7 +691,7 @@ read: memcpy (pbtData, abtRxBuf + offset, len); offset += len; - byte_t btDCS = (256 - 0xD5); + uint8_t btDCS = (256 - 0xD5); btDCS -= CHIP_DATA (pnd)->ui8LastCommand + 1; for (size_t szPos = 0; szPos < len; szPos++) { btDCS -= pbtData[szPos]; @@ -717,7 +717,7 @@ read: int pn53x_usb_ack (nfc_device * pnd) { - return pn53x_usb_bulk_write (DRIVER_DATA (pnd), (byte_t *) pn53x_ack_frame, sizeof (pn53x_ack_frame), NULL); + return pn53x_usb_bulk_write (DRIVER_DATA (pnd), (uint8_t *) pn53x_ack_frame, sizeof (pn53x_ack_frame), NULL); } bool @@ -725,13 +725,13 @@ pn53x_usb_init (nfc_device *pnd) { // Sometimes PN53x USB doesn't reply ACK one the first frame, so we need to send a dummy one... //pn53x_check_communication (pnd); // Sony RC-S360 doesn't support this command for now so let's use a get_firmware_version instead: - const byte_t abtCmd[] = { GetFirmwareVersion }; + const uint8_t abtCmd[] = { GetFirmwareVersion }; pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), NULL, NULL, NULL); // ...and we don't care about error pnd->iLastError = 0; if (SONY_RCS360 == DRIVER_DATA (pnd)->model) { log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "SONY RC-S360 initialization."); - const byte_t abtCmd2[] = { 0x18, 0x01 }; + const uint8_t abtCmd2[] = { 0x18, 0x01 }; pn53x_transceive (pnd, abtCmd2, sizeof (abtCmd2), NULL, NULL, NULL); pn53x_usb_ack (pnd); } diff --git a/libnfc/drivers/pn53x_usb.h b/libnfc/drivers/pn53x_usb.h index 9d8b637..83661b8 100644 --- a/libnfc/drivers/pn53x_usb.h +++ b/libnfc/drivers/pn53x_usb.h @@ -31,8 +31,8 @@ bool pn53x_usb_probe (nfc_connstring connstrings[], size_t connstrings_len, size_t * pszDeviceFound); nfc_device *pn53x_usb_connect (const nfc_connstring connstring); -bool pn53x_usb_send (nfc_device * pnd, const byte_t * pbtData, const size_t szData, struct timeval *timeout); -int pn53x_usb_receive (nfc_device * pnd, byte_t * pbtData, const size_t szData, struct timeval *timeout); +bool pn53x_usb_send (nfc_device * pnd, const uint8_t * pbtData, const size_t szData, struct timeval *timeout); +int pn53x_usb_receive (nfc_device * pnd, uint8_t * pbtData, const size_t szData, struct timeval *timeout); void pn53x_usb_disconnect (nfc_device * pnd); extern const struct nfc_driver_t pn53x_usb_driver; diff --git a/libnfc/iso14443-subr.c b/libnfc/iso14443-subr.c index 97afbd1..42e291e 100644 --- a/libnfc/iso14443-subr.c +++ b/libnfc/iso14443-subr.c @@ -32,30 +32,30 @@ #include void -iso14443a_crc (byte_t * pbtData, size_t szLen, byte_t * pbtCrc) +iso14443a_crc (uint8_t * pbtData, size_t szLen, uint8_t * pbtCrc) { - byte_t bt; + uint8_t bt; uint32_t wCrc = 0x6363; do { bt = *pbtData++; - bt = (bt ^ (byte_t) (wCrc & 0x00FF)); + bt = (bt ^ (uint8_t) (wCrc & 0x00FF)); bt = (bt ^ (bt << 4)); wCrc = (wCrc >> 8) ^ ((uint32_t) bt << 8) ^ ((uint32_t) bt << 3) ^ ((uint32_t) bt >> 4); } while (--szLen); - *pbtCrc++ = (byte_t) (wCrc & 0xFF); - *pbtCrc = (byte_t) ((wCrc >> 8) & 0xFF); + *pbtCrc++ = (uint8_t) (wCrc & 0xFF); + *pbtCrc = (uint8_t) ((wCrc >> 8) & 0xFF); } void -iso14443a_crc_append (byte_t * pbtData, size_t szLen) +iso14443a_crc_append (uint8_t * pbtData, size_t szLen) { iso14443a_crc (pbtData, szLen, pbtData + szLen); } -byte_t * -iso14443a_locate_historical_bytes (byte_t * pbtAts, size_t szAts, size_t * pszTk) +uint8_t * +iso14443a_locate_historical_bytes (uint8_t * pbtAts, size_t szAts, size_t * pszTk) { if (szAts) { size_t offset = 1; @@ -82,7 +82,7 @@ iso14443a_locate_historical_bytes (byte_t * pbtAts, size_t szAts, size_t * pszTk * @see ISO/IEC 14443-3 (6.4.4 UID contents and cascade levels) */ void -iso14443_cascade_uid (const byte_t abtUID[], const size_t szUID, byte_t * pbtCascadedUID, size_t * pszCascadedUID) +iso14443_cascade_uid (const uint8_t abtUID[], const size_t szUID, uint8_t * pbtCascadedUID, size_t * pszCascadedUID) { switch (szUID) { case 7: diff --git a/libnfc/mirror-subr.c b/libnfc/mirror-subr.c index 7b5953b..d85ef88 100644 --- a/libnfc/mirror-subr.c +++ b/libnfc/mirror-subr.c @@ -30,7 +30,7 @@ #include "mirror-subr.h" -static const byte_t ByteMirror[256] = { +static const uint8_t ByteMirror[256] = { 0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0, 0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0, 0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8, 0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8, 0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, @@ -53,14 +53,14 @@ static const byte_t ByteMirror[256] = { 0xef, 0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff }; -byte_t -mirror (byte_t bt) +uint8_t +mirror (uint8_t bt) { return ByteMirror[bt]; } void -mirror_bytes (byte_t * pbts, size_t szLen) +mirror_bytes (uint8_t * pbts, size_t szLen) { size_t szByteNr; @@ -73,13 +73,13 @@ mirror_bytes (byte_t * pbts, size_t szLen) uint32_t mirror32 (uint32_t ui32Bits) { - mirror_bytes ((byte_t *) & ui32Bits, 4); + mirror_bytes ((uint8_t *) & ui32Bits, 4); return ui32Bits; } uint64_t mirror64 (uint64_t ui64Bits) { - mirror_bytes ((byte_t *) & ui64Bits, 8); + mirror_bytes ((uint8_t *) & ui64Bits, 8); return ui64Bits; } diff --git a/libnfc/mirror-subr.h b/libnfc/mirror-subr.h index c795f7e..0560053 100644 --- a/libnfc/mirror-subr.h +++ b/libnfc/mirror-subr.h @@ -29,9 +29,9 @@ # include -byte_t mirror (byte_t bt); +uint8_t mirror (uint8_t bt); uint32_t mirror32 (uint32_t ui32Bits); uint64_t mirror64 (uint64_t ui64Bits); -void mirror_byte_ts (byte_t * pbts, size_t szLen); +void mirror_uint8_ts (uint8_t * pbts, size_t szLen); #endif // _LIBNFC_MIRROR_SUBR_H_ diff --git a/libnfc/nfc-emulation.c b/libnfc/nfc-emulation.c index d9b622c..52e9cc3 100644 --- a/libnfc/nfc-emulation.c +++ b/libnfc/nfc-emulation.c @@ -30,9 +30,9 @@ int nfc_emulate_target (nfc_device* pnd, struct nfc_emulator *emulator) { - byte_t abtRx[ISO7816_SHORT_R_APDU_MAX_LEN]; + uint8_t abtRx[ISO7816_SHORT_R_APDU_MAX_LEN]; size_t szRx = sizeof(abtRx); - byte_t abtTx[ISO7816_SHORT_C_APDU_MAX_LEN]; + uint8_t abtTx[ISO7816_SHORT_C_APDU_MAX_LEN]; int res = 0; if (!nfc_target_init (pnd, emulator->target, abtRx, &szRx)) { diff --git a/libnfc/nfc-internal.c b/libnfc/nfc-internal.c index bd74b30..6f84d84 100644 --- a/libnfc/nfc-internal.c +++ b/libnfc/nfc-internal.c @@ -25,36 +25,36 @@ #include void -prepare_initiator_data (const nfc_modulation nm, byte_t **ppbtInitiatorData, size_t * pszInitiatorData) +prepare_initiator_data (const nfc_modulation nm, uint8_t **ppbtInitiatorData, size_t * pszInitiatorData) { switch (nm.nmt) { case NMT_ISO14443B: { // Application Family Identifier (AFI) must equals 0x00 in order to wakeup all ISO14443-B PICCs (see ISO/IEC 14443-3) - *ppbtInitiatorData = (byte_t *) "\x00"; + *ppbtInitiatorData = (uint8_t *) "\x00"; *pszInitiatorData = 1; } break; case NMT_ISO14443BI: { // APGEN - *ppbtInitiatorData = (byte_t *) "\x01\x0b\x3f\x80"; + *ppbtInitiatorData = (uint8_t *) "\x01\x0b\x3f\x80"; *pszInitiatorData = 4; } break; case NMT_ISO14443B2SR: { // Get_UID - *ppbtInitiatorData = (byte_t *) "\x0b"; + *ppbtInitiatorData = (uint8_t *) "\x0b"; *pszInitiatorData = 1; } break; case NMT_ISO14443B2CT: { // SELECT-ALL - *ppbtInitiatorData = (byte_t *) "\x9F\xFF\xFF"; + *ppbtInitiatorData = (uint8_t *) "\x9F\xFF\xFF"; *pszInitiatorData = 3; } break; case NMT_FELICA: { // polling payload must be present (see ISO/IEC 18092 11.2.2.5) - *ppbtInitiatorData = (byte_t *) "\x00\xff\xff\x01\x00"; + *ppbtInitiatorData = (uint8_t *) "\x00\xff\xff\x01\x00"; *pszInitiatorData = 5; } break; diff --git a/libnfc/nfc-internal.h b/libnfc/nfc-internal.h index 1617286..e3f16b0 100644 --- a/libnfc/nfc-internal.h +++ b/libnfc/nfc-internal.h @@ -132,20 +132,20 @@ struct nfc_driver_t { const char *(*strerror) (const nfc_device * pnd); bool (*initiator_init) (nfc_device * pnd); - bool (*initiator_select_passive_target) (nfc_device * pnd, const nfc_modulation nm, const byte_t * pbtInitData, const size_t szInitData, nfc_target * pnt); + bool (*initiator_select_passive_target) (nfc_device * pnd, const nfc_modulation nm, const uint8_t * pbtInitData, const size_t szInitData, nfc_target * pnt); bool (*initiator_poll_target) (nfc_device * pnd, const nfc_modulation * pnmModulations, const size_t szModulations, const uint8_t uiPollNr, const uint8_t btPeriod, nfc_target * pnt); bool (*initiator_select_dep_target) (nfc_device * pnd, const nfc_dep_mode ndm, const nfc_baud_rate nbr, const nfc_dep_info * pndiInitiator, nfc_target * pnt); bool (*initiator_deselect_target) (nfc_device * pnd); - bool (*initiator_transceive_bytes) (nfc_device * pnd, const byte_t * pbtTx, const size_t szTx, byte_t * pbtRx, size_t * pszRx, struct timeval *timeout); - bool (*initiator_transceive_bits) (nfc_device * pnd, const byte_t * pbtTx, const size_t szTxBits, const byte_t * pbtTxPar, byte_t * pbtRx, size_t * pszRxBits, byte_t * pbtRxPar); - bool (*initiator_transceive_bytes_timed) (nfc_device * pnd, const byte_t * pbtTx, const size_t szTx, byte_t * pbtRx, size_t * pszRx, uint32_t * cycles); - bool (*initiator_transceive_bits_timed) (nfc_device * pnd, const byte_t * pbtTx, const size_t szTxBits, const byte_t * pbtTxPar, byte_t * pbtRx, size_t * pszRxBits, byte_t * pbtRxPar, uint32_t * cycles); + bool (*initiator_transceive_bytes) (nfc_device * pnd, const uint8_t * pbtTx, const size_t szTx, uint8_t * pbtRx, size_t * pszRx, struct timeval *timeout); + bool (*initiator_transceive_bits) (nfc_device * pnd, const uint8_t * pbtTx, const size_t szTxBits, const uint8_t * pbtTxPar, uint8_t * pbtRx, size_t * pszRxBits, uint8_t * pbtRxPar); + bool (*initiator_transceive_bytes_timed) (nfc_device * pnd, const uint8_t * pbtTx, const size_t szTx, uint8_t * pbtRx, size_t * pszRx, uint32_t * cycles); + bool (*initiator_transceive_bits_timed) (nfc_device * pnd, const uint8_t * pbtTx, const size_t szTxBits, const uint8_t * pbtTxPar, uint8_t * pbtRx, size_t * pszRxBits, uint8_t * pbtRxPar, uint32_t * cycles); - bool (*target_init) (nfc_device * pnd, nfc_target * pnt, byte_t * pbtRx, size_t * pszRx); - bool (*target_send_bytes) (nfc_device * pnd, const byte_t * pbtTx, const size_t szTx, struct timeval *timeout); - bool (*target_receive_bytes) (nfc_device * pnd, byte_t * pbtRx, size_t * pszRx, struct timeval *timeout); - bool (*target_send_bits) (nfc_device * pnd, const byte_t * pbtTx, const size_t szTxBits, const byte_t * pbtTxPar); - bool (*target_receive_bits) (nfc_device * pnd, byte_t * pbtRx, size_t * pszRxBits, byte_t * pbtRxPar); + bool (*target_init) (nfc_device * pnd, nfc_target * pnt, uint8_t * pbtRx, size_t * pszRx); + bool (*target_send_bytes) (nfc_device * pnd, const uint8_t * pbtTx, const size_t szTx, struct timeval *timeout); + bool (*target_receive_bytes) (nfc_device * pnd, uint8_t * pbtRx, size_t * pszRx, struct timeval *timeout); + bool (*target_send_bits) (nfc_device * pnd, const uint8_t * pbtTx, const size_t szTxBits, const uint8_t * pbtTxPar); + bool (*target_receive_bits) (nfc_device * pnd, uint8_t * pbtRx, size_t * pszRxBits, uint8_t * pbtRxPar); bool (*configure) (nfc_device * pnd, const nfc_device_option ndo, const bool bEnable); @@ -156,8 +156,8 @@ struct nfc_driver_t { nfc_device *nfc_device_new (void); void nfc_device_free (nfc_device *nfc_device); -void iso14443_cascade_uid (const byte_t abtUID[], const size_t szUID, byte_t * pbtCascadedUID, size_t * pszCascadedUID); +void iso14443_cascade_uid (const uint8_t abtUID[], const size_t szUID, uint8_t * pbtCascadedUID, size_t * pszCascadedUID); -void prepare_initiator_data (const nfc_modulation nm, byte_t **ppbtInitiatorData, size_t * pszInitiatorData); +void prepare_initiator_data (const nfc_modulation nm, uint8_t **ppbtInitiatorData, size_t * pszInitiatorData); #endif // __NFC_INTERNAL_H__ diff --git a/libnfc/nfc.c b/libnfc/nfc.c index aeea3da..95b4db8 100644 --- a/libnfc/nfc.c +++ b/libnfc/nfc.c @@ -306,10 +306,10 @@ nfc_initiator_init (nfc_device * pnd) bool nfc_initiator_select_passive_target (nfc_device * pnd, const nfc_modulation nm, - const byte_t * pbtInitData, const size_t szInitData, + const uint8_t * pbtInitData, const size_t szInitData, nfc_target * pnt) { - byte_t abtInit[MAX(12, szInitData)]; + uint8_t abtInit[MAX(12, szInitData)]; size_t szInit; switch (nm.nmt) { @@ -350,7 +350,7 @@ nfc_initiator_list_passive_targets (nfc_device * pnd, { nfc_target nt; size_t szTargetFound = 0; - byte_t *pbtInitData = NULL; + uint8_t *pbtInitData = NULL; size_t szInitDataLen = 0; pnd->iLastError = 0; @@ -479,7 +479,7 @@ nfc_initiator_deselect_target (nfc_device * pnd) * @warning The configuration option \a NDO_HANDLE_PARITY must be set to \c true (the default value). */ bool -nfc_initiator_transceive_bytes (nfc_device * pnd, const byte_t * pbtTx, const size_t szTx, byte_t * pbtRx, +nfc_initiator_transceive_bytes (nfc_device * pnd, const uint8_t * pbtTx, const size_t szTx, uint8_t * pbtRx, size_t * pszRx, struct timeval *timeout) { HAL (initiator_transceive_bytes, pnd, pbtTx, szTx, pbtRx, pszRx, timeout) @@ -521,8 +521,8 @@ nfc_initiator_transceive_bytes (nfc_device * pnd, const byte_t * pbtTx, const si * CRC bytes. Using this feature you are able to simulate these frames. */ bool -nfc_initiator_transceive_bits (nfc_device * pnd, const byte_t * pbtTx, const size_t szTxBits, const byte_t * pbtTxPar, - byte_t * pbtRx, size_t * pszRxBits, byte_t * pbtRxPar) +nfc_initiator_transceive_bits (nfc_device * pnd, const uint8_t * pbtTx, const size_t szTxBits, const uint8_t * pbtTxPar, + uint8_t * pbtRx, size_t * pszRxBits, uint8_t * pbtRxPar) { HAL (initiator_transceive_bits, pnd, pbtTx, szTxBits, pbtTxPar, pbtRx, pszRxBits, pbtRxPar); } @@ -548,7 +548,7 @@ nfc_initiator_transceive_bits (nfc_device * pnd, const byte_t * pbtTx, const siz * @warning The configuration option \a NDO_HANDLE_PARITY must be set to \c true (the default value). */ bool -nfc_initiator_transceive_bytes_timed (nfc_device * pnd, const byte_t * pbtTx, const size_t szTx, byte_t * pbtRx, +nfc_initiator_transceive_bytes_timed (nfc_device * pnd, const uint8_t * pbtTx, const size_t szTx, uint8_t * pbtRx, size_t * pszRx, uint32_t * cycles) { HAL (initiator_transceive_bytes_timed, pnd, pbtTx, szTx, pbtRx, pszRx, cycles) @@ -576,8 +576,8 @@ nfc_initiator_transceive_bytes_timed (nfc_device * pnd, const byte_t * pbtTx, co * @warning The configuration option \a NDO_HANDLE_PARITY must be set to \c true (the default value). */ bool -nfc_initiator_transceive_bits_timed (nfc_device * pnd, const byte_t * pbtTx, const size_t szTxBits, const byte_t * pbtTxPar, - byte_t * pbtRx, size_t * pszRxBits, byte_t * pbtRxPar, uint32_t * cycles) +nfc_initiator_transceive_bits_timed (nfc_device * pnd, const uint8_t * pbtTx, const size_t szTxBits, const uint8_t * pbtTxPar, + uint8_t * pbtRx, size_t * pszRxBits, uint8_t * pbtRxPar, uint32_t * cycles) { HAL (initiator_transceive_bits_timed, pnd, pbtTx, szTxBits, pbtTxPar, pbtRx, pszRxBits, pbtRxPar, cycles); } @@ -613,7 +613,7 @@ nfc_initiator_transceive_bits_timed (nfc_device * pnd, const byte_t * pbtTx, con * receive functions can be used. */ bool -nfc_target_init (nfc_device * pnd, nfc_target * pnt, byte_t * pbtRx, size_t * pszRx) +nfc_target_init (nfc_device * pnd, nfc_target * pnt, uint8_t * pbtRx, size_t * pszRx) { // Disallow invalid frame if (!nfc_configure (pnd, NDO_ACCEPT_INVALID_FRAMES, false)) @@ -691,7 +691,7 @@ nfc_abort_command (nfc_device * pnd) * If timeout is a null pointer, the function blocks indefinitely (until an error is raised or function is completed). */ bool -nfc_target_send_bytes (nfc_device * pnd, const byte_t * pbtTx, const size_t szTx, struct timeval *timeout) +nfc_target_send_bytes (nfc_device * pnd, const uint8_t * pbtTx, const size_t szTx, struct timeval *timeout) { HAL (target_send_bytes, pnd, pbtTx, szTx, timeout); } @@ -711,7 +711,7 @@ nfc_target_send_bytes (nfc_device * pnd, const byte_t * pbtTx, const size_t szTx * If timeout is a null pointer, the function blocks indefinitely (until an error is raised or function is completed). */ bool -nfc_target_receive_bytes (nfc_device * pnd, byte_t * pbtRx, size_t * pszRx, struct timeval *timeout) +nfc_target_receive_bytes (nfc_device * pnd, uint8_t * pbtRx, size_t * pszRx, struct timeval *timeout) { HAL (target_receive_bytes, pnd, pbtRx, pszRx, timeout); } @@ -724,7 +724,7 @@ nfc_target_receive_bytes (nfc_device * pnd, byte_t * pbtRx, size_t * pszRx, stru * using the specified NFC device (configured as \e target). */ bool -nfc_target_send_bits (nfc_device * pnd, const byte_t * pbtTx, const size_t szTxBits, const byte_t * pbtTxPar) +nfc_target_send_bits (nfc_device * pnd, const uint8_t * pbtTx, const size_t szTxBits, const uint8_t * pbtTxPar) { HAL (target_send_bits, pnd, pbtTx, szTxBits, pbtTxPar); } @@ -741,7 +741,7 @@ nfc_target_send_bits (nfc_device * pnd, const byte_t * pbtTx, const size_t szTxB * frames. */ bool -nfc_target_receive_bits (nfc_device * pnd, byte_t * pbtRx, size_t * pszRxBits, byte_t * pbtRxPar) +nfc_target_receive_bits (nfc_device * pnd, uint8_t * pbtRx, size_t * pszRxBits, uint8_t * pbtRxPar) { HAL (target_receive_bits, pnd, pbtRx, pszRxBits, pbtRxPar); } diff --git a/test/test_dep.c b/test/test_dep.c index 0c84678..3c7312a 100644 --- a/test/test_dep.c +++ b/test/test_dep.c @@ -80,21 +80,21 @@ target_thread (void *arg) }, }; - byte_t abtRx[1024]; + uint8_t abtRx[1024]; size_t szRx = sizeof (abtRx); bool res = nfc_target_init (device, &nt, abtRx, &szRx); // cut_assert_true (res, cut_message ("Can't initialize NFC device as target")); - byte_t abtAtrRes[] = "\x11\xd4\x00\x01\xfe\x12\x34\x56\x78\x90\x12\x00\x00\x00\x00\x00\x00"; + uint8_t abtAtrRes[] = "\x11\xd4\x00\x01\xfe\x12\x34\x56\x78\x90\x12\x00\x00\x00\x00\x00\x00"; // cut_assert_equal_memory (abtAtrRes, sizeof (abtAtrRes) - 1, abtRx, szRx, cut_message ("Invalid received ATR_RES")); res = nfc_target_receive_bytes (device, abtRx, &szRx); // cut_assert_true (res, cut_message ("Can't receive bytes from initiator")); - byte_t abtAttRx[] = "Hello DEP target!"; + uint8_t abtAttRx[] = "Hello DEP target!"; // cut_assert_equal_memory (abtAttRx, sizeof (abtAttRx), abtRx, szRx, cut_message ("Invalid received data")); - byte_t abtTx[] = "Hello DEP initiator!"; + uint8_t abtTx[] = "Hello DEP initiator!"; res = nfc_target_send_bytes (device, abtTx, sizeof(abtTx)); // cut_assert_true (res, cut_message ("Can't send bytes to initiator")); #endif @@ -133,13 +133,13 @@ initiator_thread (void *arg) // cut_assert_equal_int (NDM_PASSIVE, nt.nti.ndi.ndm, cut_message ("Invalid target DEP mode")); // cut_assert_equal_memory ("\x12\x34\x56\x78", 4, nt.nti.ndi.abtGB, nt.nti.ndi.szGB, cut_message ("Invalid target general bytes")); - byte_t abtTx[] = "Hello DEP target!"; - byte_t abtRx[1024]; + uint8_t abtTx[] = "Hello DEP target!"; + uint8_t abtRx[1024]; size_t szRx = sizeof (abtRx); res = nfc_initiator_transceive_bytes (device, abtTx, sizeof (abtTx), abtRx, &szRx); // cut_assert_true (res, cut_message ("Can't transceive bytes to target")); - byte_t abtAttRx[] = "Hello DEP initiator!"; + uint8_t abtAttRx[] = "Hello DEP initiator!"; // cut_assert_equal_memory (abtAttRx, sizeof (abtAttRx), abtRx, szRx, cut_message ("Invalid received data")); res = nfc_initiator_deselect_target (device); diff --git a/utils/mifare.c b/utils/mifare.c index 32679c1..a074d3a 100644 --- a/utils/mifare.c +++ b/utils/mifare.c @@ -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)) { diff --git a/utils/mifare.h b/utils/mifare.h index 2b44f9e..726d669 100644 --- a/utils/mifare.h +++ b/utils/mifare.h @@ -38,7 +38,7 @@ # include -// 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 { diff --git a/utils/nfc-emulate-forum-tag4.c b/utils/nfc-emulate-forum-tag4.c index 51ea535..b2f4bd1 100644 --- a/utils/nfc-emulate-forum-tag4.c +++ b/utils/nfc-emulate-forum-tag4.c @@ -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; diff --git a/utils/nfc-mfclassic.c b/utils/nfc-mfclassic.c index 440e6f2..a7a3907 100644 --- a/utils/nfc-mfclassic.c +++ b/utils/nfc-mfclassic.c @@ -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) { diff --git a/utils/nfc-mfsetuid.c b/utils/nfc-mfsetuid.c index 79f398f..63dcd2c 100644 --- a/utils/nfc-mfsetuid.c +++ b/utils/nfc-mfsetuid.c @@ -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) { diff --git a/utils/nfc-read-forum-tag3.c b/utils/nfc-read-forum-tag3.c index c634ea5..7d96966 100644 --- a/utils/nfc-read-forum-tag3.c +++ b/utils/nfc-read-forum-tag3.c @@ -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; diff --git a/utils/nfc-relay-picc.c b/utils/nfc-relay-picc.c index 82b26a0..4f0b9d9 100644 --- a/utils/nfc-relay-picc.c +++ b/utils/nfc-relay-picc.c @@ -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; diff --git a/utils/nfc-utils.c b/utils/nfc-utils.c index 9b87844..51c4a1f 100644 --- a/utils/nfc-utils.c +++ b/utils/nfc-utils.c @@ -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) { diff --git a/utils/nfc-utils.h b/utils/nfc-utils.h index f0ae97f..86c5d08 100644 --- a/utils/nfc-utils.h +++ b/utils/nfc-utils.h @@ -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);