Change byte_t type to uint8_t (Fixes Issue 147)

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

View file

@ -51,14 +51,14 @@
#define MAX_FRAME_LEN 264 #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 szRxBits;
static size_t szRx = sizeof(abtRx); static size_t szRx = sizeof(abtRx);
static byte_t abtRawUid[12]; static uint8_t abtRawUid[12];
static byte_t abtAtqa[2]; static uint8_t abtAtqa[2];
static byte_t abtSak; static uint8_t abtSak;
static byte_t abtAts[MAX_FRAME_LEN]; static uint8_t abtAts[MAX_FRAME_LEN];
static byte_t szAts = 0; static uint8_t szAts = 0;
static size_t szCL = 1;//Always start with Cascade Level 1 (CL1) static size_t szCL = 1;//Always start with Cascade Level 1 (CL1)
static nfc_device *pnd; static nfc_device *pnd;
@ -67,15 +67,15 @@ bool force_rats = false;
bool iso_ats_supported = false; bool iso_ats_supported = false;
// ISO14443A Anti-Collision Commands // ISO14443A Anti-Collision Commands
byte_t abtReqa[1] = { 0x26 }; uint8_t abtReqa[1] = { 0x26 };
byte_t abtSelectAll[2] = { 0x93, 0x20 }; uint8_t abtSelectAll[2] = { 0x93, 0x20 };
byte_t abtSelectTag[9] = { 0x93, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; uint8_t abtSelectTag[9] = { 0x93, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
byte_t abtRats[4] = { 0xe0, 0x50, 0x00, 0x00 }; uint8_t abtRats[4] = { 0xe0, 0x50, 0x00, 0x00 };
byte_t abtHalt[4] = { 0x50, 0x00, 0x00, 0x00 }; uint8_t abtHalt[4] = { 0x50, 0x00, 0x00, 0x00 };
#define CASCADE_BIT 0x04 #define CASCADE_BIT 0x04
static bool 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 // Show transmitted command
if (!quiet_output) { if (!quiet_output) {
@ -97,7 +97,7 @@ transmit_bits (const byte_t * pbtTx, const size_t szTxBits)
static bool 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 // Show transmitted command
if (!quiet_output) { if (!quiet_output) {

View file

@ -63,9 +63,9 @@ int
main (int argc, const char *argv[]) main (int argc, const char *argv[])
{ {
nfc_target nt; nfc_target nt;
byte_t abtRx[MAX_FRAME_LEN]; uint8_t abtRx[MAX_FRAME_LEN];
size_t szRx = sizeof(abtRx); size_t szRx = sizeof(abtRx);
byte_t abtTx[] = "Hello World!"; uint8_t abtTx[] = "Hello World!";
if (argc > 1) { if (argc > 1) {
printf ("Usage: %s\n", argv[0]); printf ("Usage: %s\n", argv[0]);

View file

@ -61,10 +61,10 @@ void stop_dep_communication (int sig)
int int
main (int argc, const char *argv[]) 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 szRx = sizeof(abtRx);
size_t szDeviceFound; size_t szDeviceFound;
byte_t abtTx[] = "Hello Mars!"; uint8_t abtTx[] = "Hello Mars!";
#define MAX_DEVICE_COUNT 2 #define MAX_DEVICE_COUNT 2
nfc_connstring connstrings[MAX_DEVICE_COUNT]; nfc_connstring connstrings[MAX_DEVICE_COUNT];
nfc_list_devices (connstrings, MAX_DEVICE_COUNT, &szDeviceFound); nfc_list_devices (connstrings, MAX_DEVICE_COUNT, &szDeviceFound);

View file

@ -112,7 +112,7 @@ static uint8_t __nfcforum_tag2_memory_area[] = {
#define HALT 0x50 #define HALT 0x50
int 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; int res = 0;

View file

@ -54,7 +54,7 @@
#define MAX_FRAME_LEN (264) #define MAX_FRAME_LEN (264)
#define SAK_ISO14443_4_COMPLIANT 0x20 #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 size_t szRx = sizeof(abtRx);
static nfc_device *pnd; static nfc_device *pnd;
static bool quiet_output = false; static bool quiet_output = false;
@ -71,7 +71,7 @@ intr_hdlr (void)
} }
bool 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; bool loop = true;
*pszOutput = 0; *pszOutput = 0;
@ -137,7 +137,7 @@ bool
nfc_target_emulate_tag(nfc_device* pnd, nfc_target * pnt) nfc_target_emulate_tag(nfc_device* pnd, nfc_target * pnt)
{ {
size_t szTx; size_t szTx;
byte_t abtTx[MAX_FRAME_LEN]; uint8_t abtTx[MAX_FRAME_LEN];
bool loop = true; bool loop = true;
if (!nfc_target_init (pnd, pnt, abtRx, &szRx)) { if (!nfc_target_init (pnd, pnt, abtRx, &szRx)) {

View file

@ -56,14 +56,14 @@
#define MAX_FRAME_LEN 264 #define MAX_FRAME_LEN 264
static byte_t abtRecv[MAX_FRAME_LEN]; static uint8_t abtRecv[MAX_FRAME_LEN];
static size_t szRecvBits; static size_t szRecvBits;
static nfc_device *pnd; static nfc_device *pnd;
// ISO14443A Anti-Collision response // ISO14443A Anti-Collision response
byte_t abtAtqa[2] = { 0x04, 0x00 }; uint8_t abtAtqa[2] = { 0x04, 0x00 };
byte_t abtUidBcc[5] = { 0xDE, 0xAD, 0xBE, 0xEF, 0x62 }; uint8_t abtUidBcc[5] = { 0xDE, 0xAD, 0xBE, 0xEF, 0x62 };
byte_t abtSak[9] = { 0x08, 0xb6, 0xdd }; uint8_t abtSak[9] = { 0x08, 0xb6, 0xdd };
void void
intr_hdlr (void) intr_hdlr (void)
@ -88,7 +88,7 @@ print_usage (char *argv[])
int int
main (int argc, char *argv[]) main (int argc, char *argv[])
{ {
byte_t *pbtTx = NULL; uint8_t *pbtTx = NULL;
size_t szTxBits; size_t szTxBits;
bool quiet_output = false; bool quiet_output = false;
@ -104,12 +104,12 @@ main (int argc, char *argv[])
printf ("Quiet mode.\n"); printf ("Quiet mode.\n");
quiet_output = true; quiet_output = true;
} else if ((arg == argc - 1) && (strlen (argv[arg]) == 8)) { // See if UID was specified as HEX string } 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]); printf ("[+] Using UID: %s\n", argv[arg]);
abtUidBcc[4] = 0x00; abtUidBcc[4] = 0x00;
for (i = 0; i < 4; ++i) { for (i = 0; i < 4; ++i) {
memcpy (abtTmp, argv[arg] + i * 2, 2); 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]; abtUidBcc[4] ^= abtUidBcc[i];
} }
} else { } else {

View file

@ -50,11 +50,11 @@
#define MAX_FRAME_LEN 264 #define MAX_FRAME_LEN 264
#define MAX_DEVICE_COUNT 2 #define MAX_DEVICE_COUNT 2
static byte_t abtReaderRx[MAX_FRAME_LEN]; static uint8_t abtReaderRx[MAX_FRAME_LEN];
static byte_t abtReaderRxPar[MAX_FRAME_LEN]; static uint8_t abtReaderRxPar[MAX_FRAME_LEN];
static size_t szReaderRxBits; static size_t szReaderRxBits;
static byte_t abtTagRx[MAX_FRAME_LEN]; static uint8_t abtTagRx[MAX_FRAME_LEN];
static byte_t abtTagRxPar[MAX_FRAME_LEN]; static uint8_t abtTagRxPar[MAX_FRAME_LEN];
static size_t szTagRxBits; static size_t szTagRxBits;
static nfc_device *pndReader; static nfc_device *pndReader;
static nfc_device *pndTag; static nfc_device *pndTag;

View file

@ -58,11 +58,11 @@ main (int argc, const char *argv[])
const char *acLibnfcVersion; const char *acLibnfcVersion;
bool result; 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); size_t szRx = sizeof(abtRx);
const byte_t pncmd_diagnose_communication_line_test[] = { Diagnose, 0x00, 0x06, 'l', 'i', 'b', 'n', 'f', 'c' }; const uint8_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 uint8_t pncmd_diagnose_rom_test[] = { Diagnose, 0x01 };
const byte_t pncmd_diagnose_ram_test[] = { Diagnose, 0x02 }; const uint8_t pncmd_diagnose_ram_test[] = { Diagnose, 0x02 };
if (argc > 1) { if (argc > 1) {
errx (1, "usage: %s", argv[0]); errx (1, "usage: %s", argv[0]);

View file

@ -153,7 +153,7 @@ main (int argc, const char *argv[])
case PSM_DUAL_CARD: case PSM_DUAL_CARD:
{ {
byte_t abtRx[MAX_FRAME_LEN]; uint8_t abtRx[MAX_FRAME_LEN];
size_t szRx = sizeof(abtRx); size_t szRx = sizeof(abtRx);
nfc_target nt = { nfc_target nt = {

View file

@ -72,8 +72,8 @@
int main(int argc, const char* argv[]) int main(int argc, const char* argv[])
{ {
nfc_device* pnd; nfc_device* pnd;
byte_t abtRx[MAX_FRAME_LEN]; uint8_t abtRx[MAX_FRAME_LEN];
byte_t abtTx[MAX_FRAME_LEN]; uint8_t abtTx[MAX_FRAME_LEN];
size_t szRx = sizeof(abtRx); size_t szRx = sizeof(abtRx);
size_t szTx; size_t szTx;
extern FILE* stdin; extern FILE* stdin;
@ -154,7 +154,7 @@ int main(int argc, const char* argv[])
szTx = 0; szTx = 0;
for(int i = 0; i<MAX_FRAME_LEN-10; i++) { for(int i = 0; i<MAX_FRAME_LEN-10; i++) {
int size; int size;
byte_t byte; uint8_t byte;
while (isspace(cmd[offset])) { while (isspace(cmd[offset])) {
offset++; offset++;
} }
@ -175,7 +175,7 @@ int main(int argc, const char* argv[])
continue; continue;
} }
printf("Tx: "); printf("Tx: ");
print_hex((byte_t*)abtTx,szTx); print_hex((uint8_t*)abtTx,szTx);
szRx = sizeof(abtRx); szRx = sizeof(abtRx);
if (!pn53x_transceive (pnd, abtTx, szTx, abtRx, &szRx, NULL)) { if (!pn53x_transceive (pnd, abtTx, szTx, abtRx, &szRx, NULL)) {

View file

@ -38,7 +38,7 @@ struct nfc_emulator {
}; };
struct nfc_emulation_state_machine { struct nfc_emulation_state_machine {
int (*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); int (*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);
void *data; void *data;
}; };

View file

@ -32,8 +32,6 @@
# include <stdbool.h> # include <stdbool.h>
# include <stdio.h> # include <stdio.h>
typedef uint8_t byte_t;
# define DEVICE_NAME_LENGTH 256 # define DEVICE_NAME_LENGTH 256
# define DEVICE_PORT_LENGTH 64 # define DEVICE_PORT_LENGTH 64
@ -59,7 +57,7 @@ typedef struct {
selecting tags supporting it? */ selecting tags supporting it? */
bool bAutoIso14443_4; bool bAutoIso14443_4;
/** Supported modulation encoded in a byte */ /** Supported modulation encoded in a byte */
byte_t btSupportByte; uint8_t btSupportByte;
/** Last error reported by the PCD / encountered by the PCD driver /** Last error reported by the PCD / encountered by the PCD driver
* MSB LSB * MSB LSB
* | 00 | 00 | * | 00 | 00 |
@ -73,7 +71,7 @@ typedef struct {
typedef char nfc_connstring[1024]; 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) # pragma pack(1)
/** /**
@ -155,19 +153,19 @@ typedef enum {
*/ */
typedef struct { typedef struct {
/** NFCID3 */ /** NFCID3 */
byte_t abtNFCID3[10]; uint8_t abtNFCID3[10];
/** DID */ /** DID */
byte_t btDID; uint8_t btDID;
/** Supported send-bit rate */ /** Supported send-bit rate */
byte_t btBS; uint8_t btBS;
/** Supported receive-bit rate */ /** Supported receive-bit rate */
byte_t btBR; uint8_t btBR;
/** Timeout value */ /** Timeout value */
byte_t btTO; uint8_t btTO;
/** PP Parameters */ /** PP Parameters */
byte_t btPP; uint8_t btPP;
/** General Bytes */ /** General Bytes */
byte_t abtGB[48]; uint8_t abtGB[48];
size_t szGB; size_t szGB;
/** DEP mode */ /** DEP mode */
nfc_dep_mode ndm; nfc_dep_mode ndm;
@ -178,12 +176,12 @@ typedef struct {
* @brief NFC ISO14443A tag (MIFARE) information * @brief NFC ISO14443A tag (MIFARE) information
*/ */
typedef struct { typedef struct {
byte_t abtAtqa[2]; uint8_t abtAtqa[2];
byte_t btSak; uint8_t btSak;
size_t szUidLen; size_t szUidLen;
byte_t abtUid[10]; uint8_t abtUid[10];
size_t szAtsLen; 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; } nfc_iso14443a_info;
/** /**
@ -192,10 +190,10 @@ typedef struct {
*/ */
typedef struct { typedef struct {
size_t szLen; size_t szLen;
byte_t btResCode; uint8_t btResCode;
byte_t abtId[8]; uint8_t abtId[8];
byte_t abtPad[8]; uint8_t abtPad[8];
byte_t abtSysCode[2]; uint8_t abtSysCode[2];
} nfc_felica_info; } nfc_felica_info;
/** /**
@ -204,11 +202,11 @@ typedef struct {
*/ */
typedef struct { typedef struct {
/** abtPupi store PUPI contained in ATQB (Answer To reQuest of type B) (see ISO14443-3) */ /** 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) */ /** 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) */ /** 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 */ /** ui8CardIdentifier store CID (Card Identifier) attributted by PCD to the PICC */
uint8_t ui8CardIdentifier; uint8_t ui8CardIdentifier;
} nfc_iso14443b_info; } nfc_iso14443b_info;
@ -219,14 +217,14 @@ typedef struct {
*/ */
typedef struct { typedef struct {
/** DIV: 4 LSBytes of tag serial number */ /** DIV: 4 LSBytes of tag serial number */
byte_t abtDIV[4]; uint8_t abtDIV[4];
/** Software version & type of REPGEN */ /** Software version & type of REPGEN */
byte_t btVerLog; uint8_t btVerLog;
/** Config Byte, present if long REPGEN */ /** Config Byte, present if long REPGEN */
byte_t btConfig; uint8_t btConfig;
/** ATR, if any */ /** ATR, if any */
size_t szAtrLen; size_t szAtrLen;
byte_t abtAtr[33]; uint8_t abtAtr[33];
} nfc_iso14443bi_info; } nfc_iso14443bi_info;
/** /**
@ -234,7 +232,7 @@ typedef struct {
* @brief NFC ISO14443-2B ST SRx tag information * @brief NFC ISO14443-2B ST SRx tag information
*/ */
typedef struct { typedef struct {
byte_t abtUID[8]; uint8_t abtUID[8];
} nfc_iso14443b2sr_info; } nfc_iso14443b2sr_info;
/** /**
@ -242,9 +240,9 @@ typedef struct {
* @brief NFC ISO14443-2B ASK CTx tag information * @brief NFC ISO14443-2B ASK CTx tag information
*/ */
typedef struct { typedef struct {
byte_t abtUID[4]; uint8_t abtUID[4];
byte_t btProdCode; uint8_t btProdCode;
byte_t btFabCode; uint8_t btFabCode;
} nfc_iso14443b2ct_info; } nfc_iso14443b2ct_info;
/** /**
@ -252,8 +250,8 @@ typedef struct {
* @brief NFC Jewel tag information * @brief NFC Jewel tag information
*/ */
typedef struct { typedef struct {
byte_t btSensRes[2]; uint8_t btSensRes[2];
byte_t btId[4]; uint8_t btId[4];
} nfc_jewel_info; } nfc_jewel_info;
/** /**

View file

@ -73,22 +73,22 @@ extern "C" {
/* NFC initiator: act as "reader" */ /* NFC initiator: act as "reader" */
NFC_EXPORT bool nfc_initiator_init (nfc_device * pnd); 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_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_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_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_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_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 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_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 byte_t * pbtTx, const size_t szTx, byte_t * pbtRx, size_t * pszRx, uint32_t * cycles); 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 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_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 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_init (nfc_device * pnd, nfc_target * pnt, uint8_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_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, byte_t * pbtRx, size_t * pszRx, 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 byte_t * pbtTx, const size_t szTxBits, const byte_t * pbtTxPar); 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, byte_t * pbtRx, size_t * pszRxBits, byte_t * pbtRxPar); NFC_EXPORT bool nfc_target_receive_bits (nfc_device * pnd, uint8_t * pbtRx, size_t * pszRxBits, uint8_t * pbtRxPar);
/* Error reporting */ /* Error reporting */
NFC_EXPORT const char *nfc_strerror (const nfc_device * pnd); 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); NFC_EXPORT const char *nfc_device_name (nfc_device * pnd);
/* Misc. functions */ /* Misc. functions */
NFC_EXPORT void iso14443a_crc (byte_t * pbtData, size_t szLen, byte_t * pbtCrc); NFC_EXPORT void iso14443a_crc (uint8_t * pbtData, size_t szLen, uint8_t * pbtCrc);
NFC_EXPORT void iso14443a_crc_append (byte_t * pbtData, size_t szLen); NFC_EXPORT void iso14443a_crc_append (uint8_t * pbtData, size_t szLen);
NFC_EXPORT byte_t * iso14443a_locate_historical_bytes (byte_t * pbtAts, size_t szAts, size_t * pszTk); NFC_EXPORT uint8_t * iso14443a_locate_historical_bytes (uint8_t * pbtAts, size_t szAts, size_t * pszTk);
NFC_EXPORT const char *nfc_version (void); NFC_EXPORT const char *nfc_version (void);
/* PN53x specific errors */ /* PN53x specific errors */

View file

@ -49,8 +49,8 @@ void uart_flush_input (const serial_port sp);
void uart_set_speed (serial_port sp, const uint32_t uiPortSpeed); void uart_set_speed (serial_port sp, const uint32_t uiPortSpeed);
uint32_t uart_get_speed (const serial_port sp); 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_receive (serial_port sp, uint8_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_send (serial_port sp, const uint8_t * pbtTx, const size_t szTx, struct timeval *timeout);
char **uart_list_ports (void); char **uart_list_ports (void);

View file

@ -249,7 +249,7 @@ uart_close (const serial_port sp)
* @return 0 on success, otherwise driver error code * @return 0 on success, otherwise driver error code
*/ */
int 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 iAbortFd = abort_p ? *((int*)abort_p) : 0;
int received_bytes_count = 0; int received_bytes_count = 0;
@ -327,7 +327,7 @@ select:
* @return 0 on success, otherwise a driver error is returned * @return 0 on success, otherwise a driver error is returned
*/ */
int 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; (void) timeout;
LOG_HEX ("TX", pbtTx, szTx); LOG_HEX ("TX", pbtTx, szTx);

View file

@ -139,7 +139,7 @@ uart_get_speed (const serial_port sp)
} }
int 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 dwBytesToGet = (DWORD)szRx;
DWORD dwBytesReceived = 0; DWORD dwBytesReceived = 0;
@ -194,7 +194,7 @@ uart_receive (serial_port sp, byte_t * pbtRx, const size_t szRx, void * abort_p,
} }
int 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; DWORD dwTxLen = 0;

View file

@ -46,9 +46,9 @@
#define LOG_CATEGORY "libnfc.chip.pn53x" #define LOG_CATEGORY "libnfc.chip.pn53x"
const byte_t pn53x_ack_frame[] = { 0x00, 0x00, 0xff, 0x00, 0xff, 0x00 }; const uint8_t pn53x_ack_frame[] = { 0x00, 0x00, 0xff, 0x00, 0xff, 0x00 };
const byte_t pn53x_nack_frame[] = { 0x00, 0x00, 0xff, 0xff, 0x00, 0x00 }; const uint8_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 }; static const uint8_t pn53x_error_frame[] = { 0x00, 0x00, 0xff, 0x01, 0xff, 0x7f, 0x81, 0x00 };
/* prototypes */ /* prototypes */
bool pn53x_reset_settings (nfc_device * pnd); bool pn53x_reset_settings (nfc_device * pnd);
@ -100,7 +100,7 @@ pn53x_reset_settings(nfc_device * pnd)
} }
bool 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 (CHIP_DATA (pnd)->wb_trigged) {
if (!pn53x_writeback_register (pnd)) { 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) if (timeout)
log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "Timeout values: %li s, %li us", timeout->tv_sec, timeout->tv_usec); 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); size_t szRx = sizeof(abtRx);
// Check if receiving buffers are available, if not, replace them // 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 bool
pn53x_wrap_frame (const byte_t * pbtTx, const size_t szTxBits, const byte_t * pbtTxPar, pn53x_wrap_frame (const uint8_t * pbtTx, const size_t szTxBits, const uint8_t * pbtTxPar,
byte_t * pbtFrame, size_t * pszFrameBits) uint8_t * pbtFrame, size_t * pszFrameBits)
{ {
byte_t btFrame; uint8_t btFrame;
byte_t btData; uint8_t btData;
uint32_t uiBitPos; uint32_t uiBitPos;
uint32_t uiDataPos = 0; uint32_t uiDataPos = 0;
size_t szBitsLeft = szTxBits; size_t szBitsLeft = szTxBits;
@ -271,14 +271,14 @@ pn53x_wrap_frame (const byte_t * pbtTx, const size_t szTxBits, const byte_t * pb
} }
bool bool
pn53x_unwrap_frame (const byte_t * pbtFrame, const size_t szFrameBits, byte_t * pbtRx, size_t * pszRxBits, pn53x_unwrap_frame (const uint8_t * pbtFrame, const size_t szFrameBits, uint8_t * pbtRx, size_t * pszRxBits,
byte_t * pbtRxPar) uint8_t * pbtRxPar)
{ {
byte_t btFrame; uint8_t btFrame;
byte_t btData; uint8_t btData;
uint8_t uiBitPos; uint8_t uiBitPos;
uint32_t uiDataPos = 0; uint32_t uiDataPos = 0;
byte_t *pbtFramePos = (byte_t *) pbtFrame; uint8_t *pbtFramePos = (uint8_t *) pbtFrame;
size_t szBitsLeft = szFrameBits; size_t szBitsLeft = szFrameBits;
// Make sure we should frame at least something // 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 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) nfc_target_info * pnti)
{ {
uint8_t szAttribRes; uint8_t szAttribRes;
@ -464,8 +464,8 @@ pn53x_decode_target_data (const byte_t * pbtRawData, size_t szRawData, pn53x_typ
bool bool
pn53x_ReadRegister (nfc_device * pnd, uint16_t ui16RegisterAddress, uint8_t * ui8Value) pn53x_ReadRegister (nfc_device * pnd, uint16_t ui16RegisterAddress, uint8_t * ui8Value)
{ {
byte_t abtCmd[] = { ReadRegister, ui16RegisterAddress >> 8, ui16RegisterAddress & 0xff }; uint8_t abtCmd[] = { ReadRegister, ui16RegisterAddress >> 8, ui16RegisterAddress & 0xff };
byte_t abtRegValue[2]; uint8_t abtRegValue[2];
size_t szRegValue = sizeof (abtRegValue); size_t szRegValue = sizeof (abtRegValue);
PNREG_TRACE (ui16RegisterAddress); PNREG_TRACE (ui16RegisterAddress);
@ -489,7 +489,7 @@ bool pn53x_read_register (nfc_device * pnd, uint16_t ui16RegisterAddress, uint8_
bool bool
pn53x_WriteRegister (nfc_device * pnd, const uint16_t ui16RegisterAddress, const uint8_t ui8Value) 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); PNREG_TRACE (ui16RegisterAddress);
return pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), NULL, NULL, NULL); return pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), NULL, NULL, NULL);
} }
@ -591,8 +591,8 @@ pn53x_writeback_register (nfc_device * pnd)
bool bool
pn53x_get_firmware_version (nfc_device * pnd, char abtFirmwareText[22]) pn53x_get_firmware_version (nfc_device * pnd, char abtFirmwareText[22])
{ {
const byte_t abtCmd[] = { GetFirmwareVersion }; const uint8_t abtCmd[] = { GetFirmwareVersion };
byte_t abtFw[4]; uint8_t abtFw[4];
size_t szFwLen = sizeof (abtFw); size_t szFwLen = sizeof (abtFw);
if (!pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), abtFw, &szFwLen, NULL)) { if (!pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), abtFw, &szFwLen, NULL)) {
return false; return false;
@ -642,7 +642,7 @@ pn53x_get_firmware_version (nfc_device * pnd, char abtFirmwareText[22])
bool bool
pn53x_configure (nfc_device * pnd, const nfc_device_option ndo, const bool bEnable) pn53x_configure (nfc_device * pnd, const nfc_device_option ndo, const bool bEnable)
{ {
byte_t btValue; uint8_t btValue;
switch (ndo) { switch (ndo) {
case NDO_HANDLE_CRC: case NDO_HANDLE_CRC:
// Enable or disable automatic receiving/sending of CRC bytes // Enable or disable automatic receiving/sending of CRC bytes
@ -827,9 +827,9 @@ pn53x_idle (nfc_device *pnd)
bool bool
pn53x_check_communication (nfc_device *pnd) pn53x_check_communication (nfc_device *pnd)
{ {
const byte_t abtCmd[] = { Diagnose, 0x00, 'l', 'i', 'b', 'n', 'f', 'c' }; const uint8_t abtCmd[] = { Diagnose, 0x00, 'l', 'i', 'b', 'n', 'f', 'c' };
const byte_t abtExpectedRx[] = { 0x00, 'l', 'i', 'b', 'n', 'f', 'c' }; const uint8_t abtExpectedRx[] = { 0x00, 'l', 'i', 'b', 'n', 'f', 'c' };
byte_t abtRx[sizeof(abtExpectedRx)]; uint8_t abtRx[sizeof(abtExpectedRx)];
size_t szRx = sizeof (abtRx); size_t szRx = sizeof (abtRx);
struct timeval timeout; struct timeval timeout;
@ -858,11 +858,11 @@ pn53x_initiator_init (nfc_device * pnd)
bool bool
pn53x_initiator_select_passive_target_ext (nfc_device * pnd, pn53x_initiator_select_passive_target_ext (nfc_device * pnd,
const nfc_modulation nm, const nfc_modulation nm,
const byte_t * pbtInitData, const size_t szInitData, const uint8_t * pbtInitData, const size_t szInitData,
nfc_target * pnt, nfc_target * pnt,
struct timeval* timeout) 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); size_t szTargetsData = sizeof(abtTargetsData);
if (nm.nmt == NMT_ISO14443BI || nm.nmt == NMT_ISO14443B2SR || nm.nmt == NMT_ISO14443B2CT) { 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; pnd->bEasyFraming = false;
if (nm.nmt == NMT_ISO14443B2SR) { if (nm.nmt == NMT_ISO14443B2SR) {
// Some work to do before getting the UID... // Some work to do before getting the UID...
byte_t abtInitiate[]="\x06\x00"; uint8_t abtInitiate[]="\x06\x00";
size_t szInitiateLen = 2; size_t szInitiateLen = 2;
byte_t abtSelect[]="\x0e\x00"; uint8_t abtSelect[]="\x0e\x00";
size_t szSelectLen = 2; size_t szSelectLen = 2;
byte_t abtRx[1]; uint8_t abtRx[1];
size_t szRxLen = 1; size_t szRxLen = 1;
// Getting random Chip_ID // Getting random Chip_ID
if (!pn53x_initiator_transceive_bytes (pnd, abtInitiate, szInitiateLen, abtRx, &szRxLen, timeout)) { 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) { else if (nm.nmt == NMT_ISO14443B2CT) {
// Some work to do before getting the UID... // Some work to do before getting the UID...
byte_t abtReqt[]="\x10"; uint8_t abtReqt[]="\x10";
size_t szReqtLen = 1; size_t szReqtLen = 1;
// Getting product code / fab code & store it in output buffer after the serial nr we'll obtain later // 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) { 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 (nm.nmt == NMT_ISO14443B2CT) {
if (szTargetsData != 2) if (szTargetsData != 2)
return false; 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; size_t szReadLen = 1;
if (!pn53x_initiator_transceive_bytes (pnd, abtRead, szReadLen, abtTargetsData+4, &szTargetsData, timeout) || szTargetsData != 2) { if (!pn53x_initiator_transceive_bytes (pnd, abtRead, szReadLen, abtTargetsData+4, &szTargetsData, timeout) || szTargetsData != 2) {
return false; return false;
@ -930,7 +930,7 @@ pn53x_initiator_select_passive_target_ext (nfc_device * pnd,
} }
if (nm.nmt == NMT_ISO14443BI) { if (nm.nmt == NMT_ISO14443BI) {
// Select tag // Select tag
byte_t abtAttrib[6]; uint8_t abtAttrib[6];
size_t szAttribLen = sizeof(abtAttrib); size_t szAttribLen = sizeof(abtAttrib);
memcpy(abtAttrib, abtTargetsData, szAttribLen); memcpy(abtAttrib, abtTargetsData, szAttribLen);
abtAttrib[1] = 0x0f; // ATTRIB abtAttrib[1] = 0x0f; // ATTRIB
@ -968,7 +968,7 @@ pn53x_initiator_select_passive_target_ext (nfc_device * pnd,
bool bool
pn53x_initiator_select_passive_target (nfc_device * pnd, pn53x_initiator_select_passive_target (nfc_device * pnd,
const nfc_modulation nm, const nfc_modulation nm,
const byte_t * pbtInitData, const size_t szInitData, const uint8_t * pbtInitData, const size_t szInitData,
nfc_target * pnt) nfc_target * pnt)
{ {
return pn53x_initiator_select_passive_target_ext (pnd, nm, pbtInitData, szInitData, pnt, NULL); 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 { do {
for (size_t p=0; p<uiPollNr; p++) { for (size_t p=0; p<uiPollNr; p++) {
for (size_t n=0; n<szModulations; n++) { for (size_t n=0; n<szModulations; n++) {
byte_t *pbtInitiatorData; uint8_t *pbtInitiatorData;
size_t szInitiatorData; size_t szInitiatorData;
prepare_initiator_data (pnmModulations[n], &pbtInitiatorData, &szInitiatorData); prepare_initiator_data (pnmModulations[n], &pbtInitiatorData, &szInitiatorData);
const int timeout_ms = uiPeriod * 150; const int timeout_ms = uiPeriod * 150;
@ -1047,8 +1047,8 @@ pn53x_initiator_select_dep_target(nfc_device * pnd,
const nfc_dep_info * pndiInitiator, const nfc_dep_info * pndiInitiator,
nfc_target * pnt) nfc_target * pnt)
{ {
const byte_t abtPassiveInitiatorData[] = { 0x00, 0xff, 0xff, 0x00, 0x00 }; // Only for 212/424 kpbs: First 4 bytes shall be set like this according to NFCIP-1, last byte is TSN (Time Slot Number) const uint8_t abtPassiveInitiatorData[] = { 0x00, 0xff, 0xff, 0x00, 0x00 }; // Only for 212/424 kpbs: First 4 bytes shall be set like this according to NFCIP-1, last byte is TSN (Time Slot Number)
const byte_t * pbtPassiveInitiatorData = NULL; const uint8_t * pbtPassiveInitiatorData = NULL;
switch (nbr) { switch (nbr) {
case NBR_212: case NBR_212:
@ -1070,14 +1070,14 @@ pn53x_initiator_select_dep_target(nfc_device * pnd,
} }
bool bool
pn53x_initiator_transceive_bits (nfc_device * pnd, const byte_t * pbtTx, const size_t szTxBits, pn53x_initiator_transceive_bits (nfc_device * pnd, const uint8_t * pbtTx, const size_t szTxBits,
const byte_t * pbtTxPar, byte_t * pbtRx, size_t * pszRxBits, byte_t * pbtRxPar) const uint8_t * pbtTxPar, uint8_t * pbtRx, size_t * pszRxBits, uint8_t * pbtRxPar)
{ {
size_t szFrameBits = 0; size_t szFrameBits = 0;
size_t szFrameBytes = 0; size_t szFrameBytes = 0;
uint8_t ui8rcc; uint8_t ui8rcc;
uint8_t ui8Bits = 0; uint8_t ui8Bits = 0;
byte_t abtCmd[PN53x_EXTENDED_FRAME__DATA_MAX_LEN] = { InCommunicateThru }; uint8_t abtCmd[PN53x_EXTENDED_FRAME__DATA_MAX_LEN] = { InCommunicateThru };
// Check if we should prepare the parity bits ourself // Check if we should prepare the parity bits ourself
if (!pnd->bPar) { if (!pnd->bPar) {
@ -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 // Send the frame to the PN53X chip and get the answer
// We have to give the amount of bytes + (the command byte 0x42) // 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); size_t szRx = sizeof(abtRx);
if (!pn53x_transceive (pnd, abtCmd, szFrameBytes + 1, abtRx, &szRx, NULL)) if (!pn53x_transceive (pnd, abtCmd, szFrameBytes + 1, abtRx, &szRx, NULL))
return false; return false;
@ -1134,11 +1134,11 @@ pn53x_initiator_transceive_bits (nfc_device * pnd, const byte_t * pbtTx, const s
} }
bool 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 * pszRx, struct timeval *timeout)
{ {
size_t szExtraTxLen; 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 // We can not just send bytes without parity if while the PN53X expects we handled them
if (!pnd->bPar) { 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 // 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) // 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); size_t szRx = sizeof(abtRx);
if (!pn53x_transceive (pnd, abtCmd, szTx + szExtraTxLen, abtRx, &szRx, timeout)) if (!pn53x_transceive (pnd, abtCmd, szTx + szExtraTxLen, abtRx, &szRx, timeout))
return false; return false;
@ -1262,8 +1262,8 @@ uint32_t __pn53x_get_timer(nfc_device * pnd, const uint8_t last_cmd_byte)
} }
bool bool
pn53x_initiator_transceive_bits_timed (nfc_device * pnd, const byte_t * pbtTx, const size_t szTxBits, pn53x_initiator_transceive_bits_timed (nfc_device * pnd, const uint8_t * pbtTx, const size_t szTxBits,
const byte_t * pbtTxPar, byte_t * pbtRx, size_t * pszRxBits, byte_t * pbtRxPar, uint32_t * cycles) const uint8_t * pbtTxPar, uint8_t * pbtRx, size_t * pszRxBits, uint8_t * pbtRxPar, uint32_t * cycles)
{ {
// TODO Do something with these bytes... // TODO Do something with these bytes...
(void) pbtTxPar; (void) pbtTxPar;
@ -1364,7 +1364,7 @@ pn53x_initiator_transceive_bits_timed (nfc_device * pnd, const byte_t * pbtTx, c
} }
bool 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) size_t * pszRx, uint32_t * cycles)
{ {
uint16_t i; uint16_t i;
@ -1475,7 +1475,7 @@ pn53x_initiator_deselect_target (nfc_device * pnd)
#define SAK_ISO14443_4_COMPLIANT 0x20 #define SAK_ISO14443_4_COMPLIANT 0x20
#define SAK_ISO18092_COMPLIANT 0x40 #define SAK_ISO18092_COMPLIANT 0x40
bool 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); 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)) if (!pn53x_write_register (pnd, PN53X_REG_CIU_TxAuto, SYMBOL_INITIAL_RF_ON, 0x04))
return false; return false;
byte_t abtMifareParams[6]; uint8_t abtMifareParams[6];
byte_t * pbtMifareParams = NULL; uint8_t * pbtMifareParams = NULL;
byte_t * pbtTkt = NULL; uint8_t * pbtTkt = NULL;
size_t szTkt = 0; size_t szTkt = 0;
byte_t abtFeliCaParams[18]; uint8_t abtFeliCaParams[18];
byte_t * pbtFeliCaParams = NULL; uint8_t * pbtFeliCaParams = NULL;
const byte_t * pbtNFCID3t = NULL; const uint8_t * pbtNFCID3t = NULL;
const byte_t * pbtGBt = NULL; const uint8_t * pbtGBt = NULL;
size_t szGBt = 0; size_t szGBt = 0;
switch(pnt->nm.nmt) { 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; bool targetActivated = false;
while (!targetActivated) { while (!targetActivated) {
byte_t btActivatedMode; uint8_t btActivatedMode;
if(!pn53x_TgInitAsTarget(pnd, ptm, pbtMifareParams, pbtTkt, szTkt, pbtFeliCaParams, pbtNFCID3t, pbtGBt, szGBt, pbtRx, pszRx, &btActivatedMode)) { if(!pn53x_TgInitAsTarget(pnd, ptm, pbtMifareParams, pbtTkt, szTkt, pbtFeliCaParams, pbtNFCID3t, pbtGBt, szGBt, pbtRx, pszRx, &btActivatedMode)) {
return false; return false;
@ -1696,11 +1696,11 @@ pn53x_target_init (nfc_device * pnd, nfc_target * pnt, byte_t * pbtRx, size_t *
} }
bool 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); size_t szRx = sizeof (abtRx);
// Try to gather a received frame from the reader // Try to gather a received frame from the reader
if (!pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), abtRx, &szRx, NULL)) 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 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" // 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 // 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 // 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); size_t szRx = sizeof (abtRx);
if (!pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), abtRx, &szRx, timeout)) if (!pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), abtRx, &szRx, timeout))
return false; return false;
@ -1780,12 +1780,12 @@ pn53x_target_receive_bytes (nfc_device * pnd, byte_t * pbtRx, size_t * pszRx, st
} }
bool 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 szFrameBits = 0;
size_t szFrameBytes = 0; size_t szFrameBytes = 0;
uint8_t ui8Bits = 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 // Check if we should prepare the parity bits ourself
if (!pnd->bPar) { if (!pnd->bPar) {
@ -1818,9 +1818,9 @@ pn53x_target_send_bits (nfc_device * pnd, const byte_t * pbtTx, const size_t szT
} }
bool 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 // We can not just send bytes without parity if while the PN53X expects we handled them
if (!pnd->bPar) if (!pnd->bPar)
@ -1935,14 +1935,14 @@ pn53x_strerror (const nfc_device * pnd)
bool bool
pn53x_RFConfiguration__RF_field (nfc_device * pnd, bool bEnable) 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); return pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), NULL, NULL, NULL);
} }
bool bool
pn53x_RFConfiguration__Various_timings (nfc_device * pnd, const uint8_t fATR_RES_Timeout, const uint8_t fRetryTimeout) pn53x_RFConfiguration__Various_timings (nfc_device * pnd, const uint8_t fATR_RES_Timeout, const uint8_t fRetryTimeout)
{ {
byte_t abtCmd[] = { uint8_t abtCmd[] = {
RFConfiguration, RFConfiguration,
RFCI_TIMING, RFCI_TIMING,
0x00, // RFU 0x00, // RFU
@ -1955,7 +1955,7 @@ pn53x_RFConfiguration__Various_timings (nfc_device * pnd, const uint8_t fATR_RES
bool bool
pn53x_RFConfiguration__MaxRtyCOM (nfc_device * pnd, const uint8_t MaxRtyCOM) pn53x_RFConfiguration__MaxRtyCOM (nfc_device * pnd, const uint8_t MaxRtyCOM)
{ {
byte_t abtCmd[] = { uint8_t abtCmd[] = {
RFConfiguration, RFConfiguration,
RFCI_RETRY_DATA, RFCI_RETRY_DATA,
MaxRtyCOM // MaxRtyCOM, default: 0x00 (no retry, only one try), inifite: 0xff 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) 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 // Retry format: 0x00 means only 1 try, 0xff means infinite
byte_t abtCmd[] = { uint8_t abtCmd[] = {
RFConfiguration, RFConfiguration,
RFCI_RETRY_SELECT, RFCI_RETRY_SELECT,
MxRtyATR, // MxRtyATR, default: active = 0xff, passive = 0x02 MxRtyATR, // MxRtyATR, default: active = 0xff, passive = 0x02
@ -1980,7 +1980,7 @@ pn53x_RFConfiguration__MaxRetries (nfc_device * pnd, const uint8_t MxRtyATR, con
bool bool
pn53x_SetParameters (nfc_device * pnd, const uint8_t ui8Value) 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)) { if(!pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), NULL, NULL, NULL)) {
return false; return false;
@ -1993,7 +1993,7 @@ pn53x_SetParameters (nfc_device * pnd, const uint8_t ui8Value)
bool bool
pn53x_SAMConfiguration (nfc_device * pnd, const pn532_sam_mode ui8Mode, struct timeval *timeout) 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); size_t szCmd = sizeof(abtCmd);
if (CHIP_DATA(pnd)->type != PN532) { if (CHIP_DATA(pnd)->type != PN532) {
@ -2022,7 +2022,7 @@ pn53x_SAMConfiguration (nfc_device * pnd, const pn532_sam_mode ui8Mode, struct t
bool bool
pn53x_PowerDown (nfc_device * pnd) 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)); return (pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), NULL, NULL, NULL));
} }
@ -2042,12 +2042,12 @@ pn53x_PowerDown (nfc_device * pnd)
*/ */
bool bool
pn53x_InListPassiveTarget (nfc_device * pnd, pn53x_InListPassiveTarget (nfc_device * pnd,
const pn53x_modulation pmInitModulation, const byte_t szMaxTargets, const pn53x_modulation pmInitModulation, const uint8_t szMaxTargets,
const byte_t * pbtInitiatorData, const size_t szInitiatorData, const uint8_t * pbtInitiatorData, const size_t szInitiatorData,
byte_t * pbtTargetsData, size_t * pszTargetsData, uint8_t * pbtTargetsData, size_t * pszTargetsData,
struct timeval* timeout) struct timeval* timeout)
{ {
byte_t abtCmd[15] = { InListPassiveTarget }; uint8_t abtCmd[15] = { InListPassiveTarget };
abtCmd[1] = szMaxTargets; // MaxTg abtCmd[1] = szMaxTargets; // MaxTg
@ -2098,9 +2098,9 @@ pn53x_InDeselect (nfc_device * pnd, const uint8_t ui8Target)
{ {
if (CHIP_DATA(pnd)->type == RCS360) { if (CHIP_DATA(pnd)->type == RCS360) {
// We should do act here *only* if a target was previously selected // 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); size_t szStatus = sizeof(abtStatus);
byte_t abtCmdGetStatus[] = { GetGeneralStatus }; uint8_t abtCmdGetStatus[] = { GetGeneralStatus };
if (!pn53x_transceive (pnd, abtCmdGetStatus, sizeof (abtCmdGetStatus), abtStatus, &szStatus, NULL)) { if (!pn53x_transceive (pnd, abtCmdGetStatus, sizeof (abtCmdGetStatus), abtStatus, &szStatus, NULL)) {
return false; return false;
} }
@ -2108,10 +2108,10 @@ pn53x_InDeselect (nfc_device * pnd, const uint8_t ui8Target)
return true; return true;
} }
// No much choice what to deselect actually... // 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)); 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)); 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) { if (CHIP_DATA(pnd)->type == RCS360) {
// We should do act here *only* if a target was previously selected // 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); size_t szStatus = sizeof(abtStatus);
byte_t abtCmdGetStatus[] = { GetGeneralStatus }; uint8_t abtCmdGetStatus[] = { GetGeneralStatus };
if (!pn53x_transceive (pnd, abtCmdGetStatus, sizeof (abtCmdGetStatus), abtStatus, &szStatus, NULL)) { if (!pn53x_transceive (pnd, abtCmdGetStatus, sizeof (abtCmdGetStatus), abtStatus, &szStatus, NULL)) {
return false; return false;
} }
@ -2130,17 +2130,17 @@ pn53x_InRelease (nfc_device * pnd, const uint8_t ui8Target)
return true; return true;
} }
// No much choice what to release actually... // 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)); 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)); return (pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), NULL, NULL, NULL));
} }
bool bool
pn53x_InAutoPoll (nfc_device * pnd, pn53x_InAutoPoll (nfc_device * pnd,
const pn53x_target_type * ppttTargetTypes, const size_t szTargetTypes, 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) { if (CHIP_DATA(pnd)->type != PN532) {
// This function is not supported by pn531 neither pn533 // 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... } // InAutoPoll frame looks like this { 0xd4, 0x60, 0x0f, 0x01, 0x00 } => { direction, command, pollnr, period, types... }
size_t szTxInAutoPoll = 3 + szTargetTypes; 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++) { for (size_t n = 0; n < szTargetTypes; n++) {
abtCmd[3 + n] = ppttTargetTypes[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); size_t szRx = sizeof(abtRx);
bool res = pn53x_transceive (pnd, abtCmd, szTxInAutoPoll, abtRx, &szRx, NULL); bool res = pn53x_transceive (pnd, abtCmd, szTxInAutoPoll, abtRx, &szRx, NULL);
@ -2165,7 +2165,7 @@ pn53x_InAutoPoll (nfc_device * pnd,
*pszTargetFound = abtRx[0]; *pszTargetFound = abtRx[0];
if (*pszTargetFound) { if (*pszTargetFound) {
uint8_t ln; uint8_t ln;
byte_t *pbt = abtRx + 1; uint8_t *pbt = abtRx + 1;
/* 1st target */ /* 1st target */
// Target type // Target type
pn53x_target_type ptt = *(pbt++); pn53x_target_type ptt = *(pbt++);
@ -2203,13 +2203,13 @@ bool
pn53x_InJumpForDEP (nfc_device * pnd, pn53x_InJumpForDEP (nfc_device * pnd,
const nfc_dep_mode ndm, const nfc_dep_mode ndm,
const nfc_baud_rate nbr, const nfc_baud_rate nbr,
const byte_t * pbtPassiveInitiatorData, const uint8_t * pbtPassiveInitiatorData,
const byte_t * pbtNFCID3i, const uint8_t * pbtNFCID3i,
const byte_t * pbtGBi, const size_t szGBi, const uint8_t * pbtGBi, const size_t szGBi,
nfc_target * pnt) nfc_target * pnt)
{ {
// Max frame size = 1 (Command) + 1 (ActPass) + 1 (Baud rate) + 1 (Next) + 5 (PassiveInitiatorData) + 10 (NFCID3) + 48 (General bytes) = 67 bytes // 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 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; 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); size_t szRx = sizeof (abtRx);
// Try to find a target, call the transceive callback function of the current device // Try to find a target, call the transceive callback function of the current device
if (!pn53x_transceive (pnd, abtCmd, offset, abtRx, &szRx, NULL)) if (!pn53x_transceive (pnd, abtCmd, offset, abtRx, &szRx, NULL))
@ -2295,13 +2295,13 @@ pn53x_InJumpForDEP (nfc_device * pnd,
bool bool
pn53x_TgInitAsTarget (nfc_device * pnd, pn53x_target_mode ptm, pn53x_TgInitAsTarget (nfc_device * pnd, pn53x_target_mode ptm,
const byte_t * pbtMifareParams, const uint8_t * pbtMifareParams,
const byte_t * pbtTkt, size_t szTkt, const uint8_t * pbtTkt, size_t szTkt,
const byte_t * pbtFeliCaParams, const uint8_t * pbtFeliCaParams,
const byte_t * pbtNFCID3t, const byte_t * pbtGBt, const size_t szGBt, const uint8_t * pbtNFCID3t, const uint8_t * pbtGBt, const size_t szGBt,
byte_t * pbtRx, size_t * pszRx, byte_t * pbtModeByte) 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; size_t szOptionalBytes = 0;
// Clear the target init struct, reset to all zeros // Clear the target init struct, reset to all zeros
@ -2329,7 +2329,7 @@ pn53x_TgInitAsTarget (nfc_device * pnd, pn53x_target_mode ptm,
szOptionalBytes = szGBt; szOptionalBytes = szGBt;
} }
} else { } else {
abtCmd[36] = (byte_t)(szGBt); abtCmd[36] = (uint8_t)(szGBt);
if (szGBt) { if (szGBt) {
memcpy (abtCmd+37, pbtGBt, 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) // Historical bytes (ISO/IEC 14443-4)
if ((CHIP_DATA(pnd)->type != PN531) && (CHIP_DATA(pnd)->type != RCS360)) { // PN531 does not handle Historical Bytes 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) { if (szTkt) {
memcpy (abtCmd+37+szOptionalBytes, pbtTkt, 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 // 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); size_t szRx = sizeof (abtRx);
if (!pn53x_transceive (pnd, abtCmd, 36 + szOptionalBytes, abtRx, &szRx, NULL)) if (!pn53x_transceive (pnd, abtCmd, 36 + szOptionalBytes, abtRx, &szRx, NULL))
return false; return false;
@ -2365,7 +2365,7 @@ pn53x_TgInitAsTarget (nfc_device * pnd, pn53x_target_mode ptm,
} }
bool 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 (szRxFrameLen >= sizeof (pn53x_ack_frame)) {
if (0 == memcmp (pbtRxFrame, pn53x_ack_frame, 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 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 (szRxFrameLen >= sizeof (pn53x_error_frame)) {
if (0 == memcmp (pbtRxFrame, pn53x_error_frame, 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) * @note The first byte of pbtData is the Command Code (CC)
*/ */
bool 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) { if (szData <= PN53x_NORMAL_FRAME__DATA_MAX_LEN) {
// LEN - Packet length = data length (len) + checksum (1) + end of stream marker (1) // 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); memcpy (pbtFrame + 6, pbtData, szData);
// DCS - Calculate data payload checksum // DCS - Calculate data payload checksum
byte_t btDCS = (256 - 0xD4); uint8_t btDCS = (256 - 0xD4);
for (size_t szPos = 0; szPos < szData; szPos++) { for (size_t szPos = 0; szPos < szData; szPos++) {
btDCS -= pbtData[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); memcpy (pbtFrame + 9, pbtData, szData);
// DCS - Calculate data payload checksum // DCS - Calculate data payload checksum
byte_t btDCS = (256 - 0xD4); uint8_t btDCS = (256 - 0xD4);
for (size_t szPos = 0; szPos < szData; szPos++) { for (size_t szPos = 0; szPos < szData; szPos++) {
btDCS -= pbtData[szPos]; btDCS -= pbtData[szPos];
} }

View file

@ -127,8 +127,8 @@ typedef enum {
} pn53x_operating_mode; } pn53x_operating_mode;
struct pn53x_io { struct pn53x_io {
bool (*send)(nfc_device * pnd, const byte_t * pbtData, const size_t szData, struct timeval *timeout); bool (*send)(nfc_device * pnd, const uint8_t * pbtData, const size_t szData, struct timeval *timeout);
int (*receive)(nfc_device * pnd, byte_t * pbtData, const size_t szDataLen, struct timeval *timeout); int (*receive)(nfc_device * pnd, uint8_t * pbtData, const size_t szDataLen, struct timeval *timeout);
}; };
/* defines */ /* defines */
@ -252,19 +252,19 @@ typedef enum {
PTM_ISO14443_4_PICC_ONLY = 0x04 PTM_ISO14443_4_PICC_ONLY = 0x04
} pn53x_target_mode; } pn53x_target_mode;
extern const byte_t pn53x_ack_frame[6]; extern const uint8_t pn53x_ack_frame[6];
extern const byte_t pn53x_nack_frame[6]; extern const uint8_t pn53x_nack_frame[6];
bool pn53x_init(nfc_device * pnd); 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_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_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); size_t * pszFrameBits);
bool pn53x_unwrap_frame (const byte_t * pbtFrame, const size_t szFrameBits, byte_t * pbtRx, size_t * pszRxBits, bool pn53x_unwrap_frame (const uint8_t * pbtFrame, const size_t szFrameBits, uint8_t * pbtRx, size_t * pszRxBits,
byte_t * pbtRxPar); uint8_t * pbtRxPar);
bool pn53x_decode_target_data (const byte_t * pbtRawData, size_t szRawData, bool pn53x_decode_target_data (const uint8_t * pbtRawData, size_t szRawData,
pn53x_type chip_type, nfc_modulationype nmt, pn53x_type chip_type, nfc_modulationype nmt,
nfc_target_info * pnti); nfc_target_info * pnti);
bool pn53x_read_register (nfc_device * pnd, uint16_t ui16Reg, uint8_t * ui8Value); 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_init (nfc_device * pnd);
bool pn53x_initiator_select_passive_target (nfc_device * pnd, bool pn53x_initiator_select_passive_target (nfc_device * pnd,
const nfc_modulation nm, const nfc_modulation nm,
const byte_t * pbtInitData, const size_t szInitData, const uint8_t * pbtInitData, const size_t szInitData,
nfc_target * pnt); nfc_target * pnt);
bool pn53x_initiator_poll_target (nfc_device * pnd, bool pn53x_initiator_poll_target (nfc_device * pnd,
const nfc_modulation * pnmModulations, const size_t szModulations, 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_mode ndm, const nfc_baud_rate nbr,
const nfc_dep_info * pndiInitiator, const nfc_dep_info * pndiInitiator,
nfc_target * pnt); nfc_target * pnt);
bool pn53x_initiator_transceive_bits (nfc_device * pnd, const byte_t * pbtTx, const size_t szTxBits, bool pn53x_initiator_transceive_bits (nfc_device * pnd, const uint8_t * pbtTx, const size_t szTxBits,
const byte_t * pbtTxPar, byte_t * pbtRx, size_t * pszRxBits, const uint8_t * pbtTxPar, uint8_t * pbtRx, size_t * pszRxBits,
byte_t * pbtRxPar); uint8_t * pbtRxPar);
bool pn53x_initiator_transceive_bytes (nfc_device * pnd, const byte_t * pbtTx, const size_t szTx, bool pn53x_initiator_transceive_bytes (nfc_device * pnd, const uint8_t * pbtTx, const size_t szTx,
byte_t * pbtRx, size_t * pszRx, struct timeval *timeout); uint8_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, bool pn53x_initiator_transceive_bits_timed (nfc_device * pnd, const uint8_t * pbtTx, const size_t szTxBits,
const byte_t * pbtTxPar, byte_t * pbtRx, size_t * pszRxBits, const uint8_t * pbtTxPar, uint8_t * pbtRx, size_t * pszRxBits,
byte_t * pbtRxPar, uint32_t * cycles); uint8_t * pbtRxPar, uint32_t * cycles);
bool pn53x_initiator_transceive_bytes_timed (nfc_device * pnd, const byte_t * pbtTx, const size_t szTx, bool pn53x_initiator_transceive_bytes_timed (nfc_device * pnd, const uint8_t * pbtTx, const size_t szTx,
byte_t * pbtRx, size_t * pszRx, uint32_t * cycles); uint8_t * pbtRx, size_t * pszRx, uint32_t * cycles);
bool pn53x_initiator_deselect_target (nfc_device * pnd); bool pn53x_initiator_deselect_target (nfc_device * pnd);
// NFC device as Target functions // NFC device as Target functions
bool pn53x_target_init (nfc_device * pnd, nfc_target * pnt, byte_t * pbtRx, size_t * pszRx); bool pn53x_target_init (nfc_device * pnd, nfc_target * pnt, uint8_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_bits (nfc_device * pnd, uint8_t * pbtRx, size_t * pszRxBits, uint8_t * pbtRxPar);
bool pn53x_target_receive_bytes (nfc_device * pnd, byte_t * pbtRx, size_t * pszRx, struct timeval *timeout); 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 byte_t * pbtTx, const size_t szTxBits, const byte_t * pbtTxPar); 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 byte_t * pbtTx, const size_t szTx, struct timeval *timeout); bool pn53x_target_send_bytes (nfc_device * pnd, const uint8_t * pbtTx, const size_t szTx, struct timeval *timeout);
// Error handling functions // Error handling functions
const char *pn53x_strerror (const nfc_device * pnd); 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_SAMConfiguration (nfc_device * pnd, const pn532_sam_mode mode, struct timeval *timeout);
bool pn53x_PowerDown (nfc_device * pnd); bool pn53x_PowerDown (nfc_device * pnd);
bool pn53x_InListPassiveTarget (nfc_device * pnd, const pn53x_modulation pmInitModulation, bool pn53x_InListPassiveTarget (nfc_device * pnd, const pn53x_modulation pmInitModulation,
const byte_t szMaxTargets, const byte_t * pbtInitiatorData, const uint8_t szMaxTargets, const uint8_t * pbtInitiatorData,
const size_t szInitiatorDataLen, byte_t * pbtTargetsData, size_t * pszTargetsData, const size_t szInitiatorDataLen, uint8_t * pbtTargetsData, size_t * pszTargetsData,
struct timeval *timeout); struct timeval *timeout);
bool pn53x_InDeselect (nfc_device * pnd, const uint8_t ui8Target); bool pn53x_InDeselect (nfc_device * pnd, const uint8_t ui8Target);
bool pn53x_InRelease (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, 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); size_t * pszTargetFound);
bool pn53x_InJumpForDEP (nfc_device * pnd, bool pn53x_InJumpForDEP (nfc_device * pnd,
const nfc_dep_mode ndm, const nfc_baud_rate nbr, const nfc_dep_mode ndm, const nfc_baud_rate nbr,
const byte_t * pbtPassiveInitiatorData, const uint8_t * pbtPassiveInitiatorData,
const byte_t * pbtNFCID3i, const uint8_t * pbtNFCID3i,
const byte_t * pbtGB, const size_t szGB, const uint8_t * pbtGB, const size_t szGB,
nfc_target * pnt); nfc_target * pnt);
bool pn53x_TgInitAsTarget (nfc_device * pnd, pn53x_target_mode ptm, bool pn53x_TgInitAsTarget (nfc_device * pnd, pn53x_target_mode ptm,
const byte_t * pbtMifareParams, const uint8_t * pbtMifareParams,
const byte_t * pbtTkt, size_t szTkt, const uint8_t * pbtTkt, size_t szTkt,
const byte_t * pbtFeliCaParams, const uint8_t * pbtFeliCaParams,
const byte_t * pbtNFCID3t, const byte_t * pbtGB, const size_t szGB, const uint8_t * pbtNFCID3t, const uint8_t * pbtGB, const size_t szGB,
byte_t * pbtRx, size_t * pszRx, byte_t * pbtModeByte); uint8_t * pbtRx, size_t * pszRx, uint8_t * pbtModeByte);
// RFConfiguration // RFConfiguration
bool pn53x_RFConfiguration__RF_field (nfc_device * pnd, bool bEnable); 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); bool pn53x_RFConfiguration__MaxRetries (nfc_device * pnd, const uint8_t MxRtyATR, const uint8_t MxRtyPSL, const uint8_t MxRtyPassiveActivation);
// Misc // Misc
bool pn53x_check_ack_frame (nfc_device * pnd, const byte_t * pbtRxFrame, const size_t szRxFrameLen); 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 byte_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 (byte_t * pbtFrame, size_t * pszFrame, const byte_t * pbtData, const size_t szData); 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_new (nfc_device * pnd, const struct pn53x_io* io);
void pn53x_data_free (nfc_device * pnd); void pn53x_data_free (nfc_device * pnd);

View file

@ -89,7 +89,7 @@ const char *supported_devices[] = {
struct acr122_data { struct acr122_data {
SCARDHANDLE hCard; SCARDHANDLE hCard;
SCARD_IO_REQUEST ioCard; SCARD_IO_REQUEST ioCard;
byte_t abtRx[ACR122_RESPONSE_LEN]; uint8_t abtRx[ACR122_RESPONSE_LEN];
size_t szRx; size_t szRx;
}; };
@ -310,7 +310,7 @@ acr122_disconnect (nfc_device * pnd)
} }
bool 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 // FIXME: timeout is not handled
(void) timeout; (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 // Prepare and transmit the send buffer
const size_t szTxBuf = szData + 6; 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); memcpy (abtTxBuf + 6, pbtData, szData);
LOG_HEX ("TX", abtTxBuf, szTxBuf); LOG_HEX ("TX", abtTxBuf, szTxBuf);
@ -381,13 +381,13 @@ acr122_send (nfc_device * pnd, const byte_t * pbtData, const size_t szData, stru
} }
int 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 // FIXME: timeout is not handled
(void) timeout; (void) timeout;
int len; 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) { 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 * char *
acr122_firmware (nfc_device *pnd) 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; uint32_t uiResult;
static char abtFw[11]; static char abtFw[11];
DWORD dwFwLen = sizeof (abtFw); DWORD dwFwLen = sizeof (abtFw);
memset (abtFw, 0x00, sizeof (abtFw)); memset (abtFw, 0x00, sizeof (abtFw));
if (DRIVER_DATA (pnd)->ioCard.dwProtocol == SCARD_PROTOCOL_UNDEFINED) { 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 { } 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) { if (uiResult != SCARD_S_SUCCESS) {
@ -447,8 +447,8 @@ acr122_firmware (nfc_device *pnd)
bool bool
acr122_led_red (nfc_device *pnd, bool bOn) acr122_led_red (nfc_device *pnd, bool bOn)
{ {
byte_t abtLed[9] = { 0xFF, 0x00, 0x40, 0x05, 0x04, 0x00, 0x00, 0x00, 0x00 }; uint8_t abtLed[9] = { 0xFF, 0x00, 0x40, 0x05, 0x04, 0x00, 0x00, 0x00, 0x00 };
byte_t abtBuf[2]; uint8_t abtBuf[2];
DWORD dwBufLen = sizeof (abtBuf); DWORD dwBufLen = sizeof (abtBuf);
(void) bOn; (void) bOn;
if (DRIVER_DATA (pnd)->ioCard.dwProtocol == SCARD_PROTOCOL_UNDEFINED) { if (DRIVER_DATA (pnd)->ioCard.dwProtocol == SCARD_PROTOCOL_UNDEFINED) {

View file

@ -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 // Functions used by developer to handle connection to this device
nfc_device *acr122_connect (const nfc_connstring connstring); 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); bool acr122_send (nfc_device * pnd, const uint8_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); int acr122_receive (nfc_device * pnd, uint8_t * pbtData, const size_t szData, struct timeval *timeout);
void acr122_disconnect (nfc_device * pnd); void acr122_disconnect (nfc_device * pnd);
extern const struct nfc_driver_t acr122_driver; extern const struct nfc_driver_t acr122_driver;

View file

@ -84,9 +84,9 @@ struct arygon_data {
#endif #endif
}; };
static const byte_t arygon_error_none[] = "FF000000\x0d\x0a"; static const uint8_t arygon_error_none[] = "FF000000\x0d\x0a";
static const byte_t arygon_error_incomplete_command[] = "FF0C0000\x0d\x0a"; static const uint8_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_unknown_mode[] = "FF060000\x0d\x0a";
bool arygon_reset_tama (nfc_device * pnd); bool arygon_reset_tama (nfc_device * pnd);
void arygon_firmware (nfc_device * pnd, char * str); 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_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) #define ARYGON_RX_BUFFER_LEN (PN53x_EXTENDED_FRAME__DATA_MAX_LEN + PN53x_EXTENDED_FRAME__OVERHEAD)
bool 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 // Before sending anything, we need to discard from any junk bytes
uart_flush_input (DRIVER_DATA(pnd)->port); 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; size_t szFrame = 0;
if (szData > PN53x_NORMAL_FRAME__DATA_MAX_LEN) { 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; return false;
} }
byte_t abtRxBuf[6]; uint8_t abtRxBuf[6];
res = uart_receive (DRIVER_DATA (pnd)->port, abtRxBuf, sizeof (abtRxBuf), 0, timeout); res = uart_receive (DRIVER_DATA (pnd)->port, abtRxBuf, sizeof (abtRxBuf), 0, timeout);
if (res != 0) { if (res != 0) {
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Unable to read ACK"); log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Unable to read ACK");
@ -357,7 +357,7 @@ int
arygon_abort (nfc_device *pnd) arygon_abort (nfc_device *pnd)
{ {
// Send a valid TAMA packet to wakup the PN53x (we will not have an answer, according to Arygon manual) // 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); uart_send (DRIVER_DATA (pnd)->port, dummy, sizeof (dummy), NULL);
@ -366,9 +366,9 @@ arygon_abort (nfc_device *pnd)
} }
int 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; size_t len;
void * abort_p = NULL; void * abort_p = NULL;
@ -393,7 +393,7 @@ arygon_tama_receive (nfc_device * pnd, byte_t * pbtData, const size_t szDataLen,
return -1; 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))) { if (0 != (memcmp (abtRxBuf, pn53x_preamble, 3))) {
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Frame preamble+start code mismatch"); log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Frame preamble+start code mismatch");
pnd->iLastError = ECOMIO; pnd->iLastError = ECOMIO;
@ -462,7 +462,7 @@ arygon_tama_receive (nfc_device * pnd, byte_t * pbtData, const size_t szDataLen,
return -1; return -1;
} }
byte_t btDCS = (256 - 0xD5); uint8_t btDCS = (256 - 0xD5);
btDCS -= CHIP_DATA (pnd)->ui8LastCommand + 1; btDCS -= CHIP_DATA (pnd)->ui8LastCommand + 1;
for (size_t szPos = 0; szPos < len; szPos++) { for (size_t szPos = 0; szPos < len; szPos++) {
btDCS -= pbtData[szPos]; btDCS -= pbtData[szPos];
@ -486,8 +486,8 @@ arygon_tama_receive (nfc_device * pnd, byte_t * pbtData, const size_t szDataLen,
void void
arygon_firmware (nfc_device * pnd, char * str) arygon_firmware (nfc_device * pnd, char * str)
{ {
const byte_t arygon_firmware_version_cmd[] = { DEV_ARYGON_PROTOCOL_ARYGON_ASCII, 'a', 'v' }; const uint8_t arygon_firmware_version_cmd[] = { DEV_ARYGON_PROTOCOL_ARYGON_ASCII, 'a', 'v' };
byte_t abtRx[16]; uint8_t abtRx[16];
size_t szRx = sizeof(abtRx); size_t szRx = sizeof(abtRx);
@ -503,7 +503,7 @@ arygon_firmware (nfc_device * pnd, char * str)
} }
if ( 0 == memcmp (abtRx, arygon_error_none, 6)) { if ( 0 == memcmp (abtRx, arygon_error_none, 6)) {
byte_t * p = abtRx + 6; uint8_t * p = abtRx + 6;
unsigned int szData; unsigned int szData;
sscanf ((const char*)p, "%02x%s", &szData, p); sscanf ((const char*)p, "%02x%s", &szData, p);
memcpy (str, p, szData); memcpy (str, p, szData);
@ -514,8 +514,8 @@ arygon_firmware (nfc_device * pnd, char * str)
bool bool
arygon_reset_tama (nfc_device * pnd) arygon_reset_tama (nfc_device * pnd)
{ {
const byte_t arygon_reset_tama_cmd[] = { DEV_ARYGON_PROTOCOL_ARYGON_ASCII, 'a', 'r' }; const uint8_t arygon_reset_tama_cmd[] = { DEV_ARYGON_PROTOCOL_ARYGON_ASCII, 'a', 'r' };
byte_t abtRx[10]; // Attempted response is 10 bytes long uint8_t abtRx[10]; // Attempted response is 10 bytes long
size_t szRx = sizeof(abtRx); size_t szRx = sizeof(abtRx);
int res; int res;

View file

@ -35,8 +35,8 @@ bool arygon_probe (nfc_connstring connstrings[], size_t connstrings_len, size
nfc_device *arygon_connect (const nfc_connstring connstring); nfc_device *arygon_connect (const nfc_connstring connstring);
void arygon_disconnect (nfc_device * pnd); void arygon_disconnect (nfc_device * pnd);
bool arygon_tama_send (nfc_device * pnd, const byte_t * pbtData, const size_t szData, struct timeval *timeout); 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, byte_t * pbtData, const size_t szDat, struct timeval *timeouta); 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; extern const struct nfc_driver_t arygon_driver;

View file

@ -281,7 +281,7 @@ int
pn532_uart_wakeup (nfc_device * pnd) 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. */ /* 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); 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 CHIP_DATA(pnd)->power_mode = NORMAL; // PN532 should now be awake
return res; 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) #define PN532_BUFFER_LEN (PN53x_EXTENDED_FRAME__DATA_MAX_LEN + PN53x_EXTENDED_FRAME__OVERHEAD)
bool 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 // Before sending anything, we need to discard from any junk bytes
uart_flush_input (DRIVER_DATA(pnd)->port); 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; 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; size_t szFrame = 0;
if (!pn53x_build_frame (abtFrame, &szFrame, pbtData, szData)) { 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; return false;
} }
byte_t abtRxBuf[6]; uint8_t abtRxBuf[6];
res = uart_receive (DRIVER_DATA(pnd)->port, abtRxBuf, 6, 0, timeout); res = uart_receive (DRIVER_DATA(pnd)->port, abtRxBuf, 6, 0, timeout);
if (res != 0) { if (res != 0) {
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Unable to read ACK"); 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 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; size_t len;
void * abort_p = NULL; void * abort_p = NULL;
@ -376,7 +376,7 @@ pn532_uart_receive (nfc_device * pnd, byte_t * pbtData, const size_t szDataLen,
return -1; 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))) { if (0 != (memcmp (abtRxBuf, pn53x_preamble, 3))) {
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Frame preamble+start code mismatch"); log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Frame preamble+start code mismatch");
pnd->iLastError = ECOMIO; pnd->iLastError = ECOMIO;
@ -454,7 +454,7 @@ pn532_uart_receive (nfc_device * pnd, byte_t * pbtData, const size_t szDataLen,
return -1; return -1;
} }
byte_t btDCS = (256 - 0xD5); uint8_t btDCS = (256 - 0xD5);
btDCS -= CHIP_DATA (pnd)->ui8LastCommand + 1; btDCS -= CHIP_DATA (pnd)->ui8LastCommand + 1;
for (size_t szPos = 0; szPos < len; szPos++) { for (size_t szPos = 0; szPos < len; szPos++) {
btDCS -= pbtData[szPos]; btDCS -= pbtData[szPos];

View file

@ -33,8 +33,8 @@ bool pn532_uart_probe (nfc_connstring connstrings[], size_t connstrings_len,
nfc_device *pn532_uart_connect (const nfc_connstring connstring); nfc_device *pn532_uart_connect (const nfc_connstring connstring);
void pn532_uart_disconnect (nfc_device * pnd); 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); 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, byte_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; extern const struct nfc_driver_t pn532_uart_driver;

View file

@ -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); bool pn53x_usb_init (nfc_device *pnd);
int 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; int timeout_ms = USB_INFINITE_TIMEOUT;
if (timeout) { if (timeout) {
@ -143,7 +143,7 @@ pn53x_usb_bulk_read (struct pn53x_usb_data *data, byte_t abtRx[], const size_t s
} }
int 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); LOG_HEX ("TX", abtTx, szTx);
int timeout_ms = USB_INFINITE_TIMEOUT; 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) #define PN53X_USB_BUFFER_LEN (PN53x_EXTENDED_FRAME__DATA_MAX_LEN + PN53x_EXTENDED_FRAME__OVERHEAD)
bool 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; size_t szFrame = 0;
pn53x_build_frame (abtFrame, &szFrame, pbtData, szData); 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; 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); res = pn53x_usb_bulk_read (DRIVER_DATA (pnd), abtRxBuf, sizeof (abtRxBuf), timeout);
if (res < 0) { if (res < 0) {
pnd->iLastError = ECOMIO; 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 // pn53x_usb_receive()) will be able to retreive the correct response
// packet. // packet.
// FIXME Sony reader is also affected by this bug but NACK is not supported // 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) { if (res < 0) {
pnd->iLastError = ECOMIO; pnd->iLastError = ECOMIO;
// try to interrupt current device state // 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 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; size_t len;
off_t offset = 0; off_t offset = 0;
byte_t abtRxBuf[PN53X_USB_BUFFER_LEN]; uint8_t abtRxBuf[PN53X_USB_BUFFER_LEN];
int res; int res;
/* /*
@ -627,7 +627,7 @@ read:
return -1; 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))) { if (0 != (memcmp (abtRxBuf, pn53x_preamble, 3))) {
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Frame preamble+start code mismatch"); log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Frame preamble+start code mismatch");
pnd->iLastError = ECOMIO; pnd->iLastError = ECOMIO;
@ -691,7 +691,7 @@ read:
memcpy (pbtData, abtRxBuf + offset, len); memcpy (pbtData, abtRxBuf + offset, len);
offset += len; offset += len;
byte_t btDCS = (256 - 0xD5); uint8_t btDCS = (256 - 0xD5);
btDCS -= CHIP_DATA (pnd)->ui8LastCommand + 1; btDCS -= CHIP_DATA (pnd)->ui8LastCommand + 1;
for (size_t szPos = 0; szPos < len; szPos++) { for (size_t szPos = 0; szPos < len; szPos++) {
btDCS -= pbtData[szPos]; btDCS -= pbtData[szPos];
@ -717,7 +717,7 @@ read:
int int
pn53x_usb_ack (nfc_device * pnd) 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 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... // 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: //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); pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), NULL, NULL, NULL);
// ...and we don't care about error // ...and we don't care about error
pnd->iLastError = 0; pnd->iLastError = 0;
if (SONY_RCS360 == DRIVER_DATA (pnd)->model) { if (SONY_RCS360 == DRIVER_DATA (pnd)->model) {
log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "SONY RC-S360 initialization."); 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_transceive (pnd, abtCmd2, sizeof (abtCmd2), NULL, NULL, NULL);
pn53x_usb_ack (pnd); pn53x_usb_ack (pnd);
} }

View file

@ -31,8 +31,8 @@
bool pn53x_usb_probe (nfc_connstring connstrings[], size_t connstrings_len, size_t * pszDeviceFound); bool pn53x_usb_probe (nfc_connstring connstrings[], size_t connstrings_len, size_t * pszDeviceFound);
nfc_device *pn53x_usb_connect (const nfc_connstring connstring); 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); 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, byte_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); void pn53x_usb_disconnect (nfc_device * pnd);
extern const struct nfc_driver_t pn53x_usb_driver; extern const struct nfc_driver_t pn53x_usb_driver;

View file

@ -32,30 +32,30 @@
#include <nfc/nfc.h> #include <nfc/nfc.h>
void 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; uint32_t wCrc = 0x6363;
do { do {
bt = *pbtData++; bt = *pbtData++;
bt = (bt ^ (byte_t) (wCrc & 0x00FF)); bt = (bt ^ (uint8_t) (wCrc & 0x00FF));
bt = (bt ^ (bt << 4)); bt = (bt ^ (bt << 4));
wCrc = (wCrc >> 8) ^ ((uint32_t) bt << 8) ^ ((uint32_t) bt << 3) ^ ((uint32_t) bt >> 4); wCrc = (wCrc >> 8) ^ ((uint32_t) bt << 8) ^ ((uint32_t) bt << 3) ^ ((uint32_t) bt >> 4);
} while (--szLen); } while (--szLen);
*pbtCrc++ = (byte_t) (wCrc & 0xFF); *pbtCrc++ = (uint8_t) (wCrc & 0xFF);
*pbtCrc = (byte_t) ((wCrc >> 8) & 0xFF); *pbtCrc = (uint8_t) ((wCrc >> 8) & 0xFF);
} }
void 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); iso14443a_crc (pbtData, szLen, pbtData + szLen);
} }
byte_t * uint8_t *
iso14443a_locate_historical_bytes (byte_t * pbtAts, size_t szAts, size_t * pszTk) iso14443a_locate_historical_bytes (uint8_t * pbtAts, size_t szAts, size_t * pszTk)
{ {
if (szAts) { if (szAts) {
size_t offset = 1; 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) * @see ISO/IEC 14443-3 (6.4.4 UID contents and cascade levels)
*/ */
void 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) { switch (szUID) {
case 7: case 7:

View file

@ -30,7 +30,7 @@
#include "mirror-subr.h" #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, 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, 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, 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 0xef, 0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff
}; };
byte_t uint8_t
mirror (byte_t bt) mirror (uint8_t bt)
{ {
return ByteMirror[bt]; return ByteMirror[bt];
} }
void void
mirror_bytes (byte_t * pbts, size_t szLen) mirror_bytes (uint8_t * pbts, size_t szLen)
{ {
size_t szByteNr; size_t szByteNr;
@ -73,13 +73,13 @@ mirror_bytes (byte_t * pbts, size_t szLen)
uint32_t uint32_t
mirror32 (uint32_t ui32Bits) mirror32 (uint32_t ui32Bits)
{ {
mirror_bytes ((byte_t *) & ui32Bits, 4); mirror_bytes ((uint8_t *) & ui32Bits, 4);
return ui32Bits; return ui32Bits;
} }
uint64_t uint64_t
mirror64 (uint64_t ui64Bits) mirror64 (uint64_t ui64Bits)
{ {
mirror_bytes ((byte_t *) & ui64Bits, 8); mirror_bytes ((uint8_t *) & ui64Bits, 8);
return ui64Bits; return ui64Bits;
} }

View file

@ -29,9 +29,9 @@
# include <nfc/nfc-types.h> # include <nfc/nfc-types.h>
byte_t mirror (byte_t bt); uint8_t mirror (uint8_t bt);
uint32_t mirror32 (uint32_t ui32Bits); uint32_t mirror32 (uint32_t ui32Bits);
uint64_t mirror64 (uint64_t ui64Bits); 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_ #endif // _LIBNFC_MIRROR_SUBR_H_

View file

@ -30,9 +30,9 @@
int int
nfc_emulate_target (nfc_device* pnd, struct nfc_emulator *emulator) 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); 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; int res = 0;
if (!nfc_target_init (pnd, emulator->target, abtRx, &szRx)) { if (!nfc_target_init (pnd, emulator->target, abtRx, &szRx)) {

View file

@ -25,36 +25,36 @@
#include <nfc/nfc.h> #include <nfc/nfc.h>
void 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) { switch (nm.nmt) {
case NMT_ISO14443B: { case NMT_ISO14443B: {
// Application Family Identifier (AFI) must equals 0x00 in order to wakeup all ISO14443-B PICCs (see ISO/IEC 14443-3) // 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; *pszInitiatorData = 1;
} }
break; break;
case NMT_ISO14443BI: { case NMT_ISO14443BI: {
// APGEN // APGEN
*ppbtInitiatorData = (byte_t *) "\x01\x0b\x3f\x80"; *ppbtInitiatorData = (uint8_t *) "\x01\x0b\x3f\x80";
*pszInitiatorData = 4; *pszInitiatorData = 4;
} }
break; break;
case NMT_ISO14443B2SR: { case NMT_ISO14443B2SR: {
// Get_UID // Get_UID
*ppbtInitiatorData = (byte_t *) "\x0b"; *ppbtInitiatorData = (uint8_t *) "\x0b";
*pszInitiatorData = 1; *pszInitiatorData = 1;
} }
break; break;
case NMT_ISO14443B2CT: { case NMT_ISO14443B2CT: {
// SELECT-ALL // SELECT-ALL
*ppbtInitiatorData = (byte_t *) "\x9F\xFF\xFF"; *ppbtInitiatorData = (uint8_t *) "\x9F\xFF\xFF";
*pszInitiatorData = 3; *pszInitiatorData = 3;
} }
break; break;
case NMT_FELICA: { case NMT_FELICA: {
// polling payload must be present (see ISO/IEC 18092 11.2.2.5) // 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; *pszInitiatorData = 5;
} }
break; break;

View file

@ -132,20 +132,20 @@ struct nfc_driver_t {
const char *(*strerror) (const nfc_device * pnd); const char *(*strerror) (const nfc_device * pnd);
bool (*initiator_init) (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_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_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_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_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 byte_t * pbtTx, const size_t szTxBits, const byte_t * pbtTxPar, byte_t * pbtRx, size_t * pszRxBits, byte_t * pbtRxPar); 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 byte_t * pbtTx, const size_t szTx, byte_t * pbtRx, size_t * pszRx, uint32_t * cycles); 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 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_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_init) (nfc_device * pnd, nfc_target * pnt, uint8_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_send_bytes) (nfc_device * pnd, const uint8_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_receive_bytes) (nfc_device * pnd, uint8_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_send_bits) (nfc_device * pnd, const uint8_t * pbtTx, const size_t szTxBits, const uint8_t * pbtTxPar);
bool (*target_receive_bits) (nfc_device * pnd, byte_t * pbtRx, size_t * pszRxBits, byte_t * pbtRxPar); 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); 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); nfc_device *nfc_device_new (void);
void nfc_device_free (nfc_device *nfc_device); 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__ #endif // __NFC_INTERNAL_H__

View file

@ -306,10 +306,10 @@ nfc_initiator_init (nfc_device * pnd)
bool bool
nfc_initiator_select_passive_target (nfc_device * pnd, nfc_initiator_select_passive_target (nfc_device * pnd,
const nfc_modulation nm, const nfc_modulation nm,
const byte_t * pbtInitData, const size_t szInitData, const uint8_t * pbtInitData, const size_t szInitData,
nfc_target * pnt) nfc_target * pnt)
{ {
byte_t abtInit[MAX(12, szInitData)]; uint8_t abtInit[MAX(12, szInitData)];
size_t szInit; size_t szInit;
switch (nm.nmt) { switch (nm.nmt) {
@ -350,7 +350,7 @@ nfc_initiator_list_passive_targets (nfc_device * pnd,
{ {
nfc_target nt; nfc_target nt;
size_t szTargetFound = 0; size_t szTargetFound = 0;
byte_t *pbtInitData = NULL; uint8_t *pbtInitData = NULL;
size_t szInitDataLen = 0; size_t szInitDataLen = 0;
pnd->iLastError = 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). * @warning The configuration option \a NDO_HANDLE_PARITY must be set to \c true (the default value).
*/ */
bool 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) size_t * pszRx, struct timeval *timeout)
{ {
HAL (initiator_transceive_bytes, pnd, pbtTx, szTx, pbtRx, pszRx, 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. * CRC bytes. Using this feature you are able to simulate these frames.
*/ */
bool bool
nfc_initiator_transceive_bits (nfc_device * pnd, const byte_t * pbtTx, const size_t szTxBits, const byte_t * pbtTxPar, nfc_initiator_transceive_bits (nfc_device * pnd, const uint8_t * pbtTx, const size_t szTxBits, const uint8_t * pbtTxPar,
byte_t * pbtRx, size_t * pszRxBits, byte_t * pbtRxPar) uint8_t * pbtRx, size_t * pszRxBits, uint8_t * pbtRxPar)
{ {
HAL (initiator_transceive_bits, pnd, pbtTx, szTxBits, pbtTxPar, pbtRx, pszRxBits, 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). * @warning The configuration option \a NDO_HANDLE_PARITY must be set to \c true (the default value).
*/ */
bool 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) size_t * pszRx, uint32_t * cycles)
{ {
HAL (initiator_transceive_bytes_timed, pnd, pbtTx, szTx, pbtRx, pszRx, 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). * @warning The configuration option \a NDO_HANDLE_PARITY must be set to \c true (the default value).
*/ */
bool bool
nfc_initiator_transceive_bits_timed (nfc_device * pnd, const byte_t * pbtTx, const size_t szTxBits, const byte_t * pbtTxPar, nfc_initiator_transceive_bits_timed (nfc_device * pnd, const uint8_t * pbtTx, const size_t szTxBits, const uint8_t * pbtTxPar,
byte_t * pbtRx, size_t * pszRxBits, byte_t * pbtRxPar, uint32_t * cycles) 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); 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. * receive functions can be used.
*/ */
bool 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 // Disallow invalid frame
if (!nfc_configure (pnd, NDO_ACCEPT_INVALID_FRAMES, false)) 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). * If timeout is a null pointer, the function blocks indefinitely (until an error is raised or function is completed).
*/ */
bool 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); 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). * If timeout is a null pointer, the function blocks indefinitely (until an error is raised or function is completed).
*/ */
bool 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); 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). * using the specified NFC device (configured as \e target).
*/ */
bool 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); 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. * frames.
*/ */
bool 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); HAL (target_receive_bits, pnd, pbtRx, pszRxBits, pbtRxPar);
} }

View file

@ -80,21 +80,21 @@ target_thread (void *arg)
}, },
}; };
byte_t abtRx[1024]; uint8_t abtRx[1024];
size_t szRx = sizeof (abtRx); size_t szRx = sizeof (abtRx);
bool res = nfc_target_init (device, &nt, abtRx, &szRx); bool res = nfc_target_init (device, &nt, abtRx, &szRx);
// cut_assert_true (res, cut_message ("Can't initialize NFC device as target")); // 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")); // cut_assert_equal_memory (abtAtrRes, sizeof (abtAtrRes) - 1, abtRx, szRx, cut_message ("Invalid received ATR_RES"));
res = nfc_target_receive_bytes (device, abtRx, &szRx); res = nfc_target_receive_bytes (device, abtRx, &szRx);
// cut_assert_true (res, cut_message ("Can't receive bytes from initiator")); // 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")); // 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)); res = nfc_target_send_bytes (device, abtTx, sizeof(abtTx));
// cut_assert_true (res, cut_message ("Can't send bytes to initiator")); // cut_assert_true (res, cut_message ("Can't send bytes to initiator"));
#endif #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_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")); // 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!"; uint8_t abtTx[] = "Hello DEP target!";
byte_t abtRx[1024]; uint8_t abtRx[1024];
size_t szRx = sizeof (abtRx); size_t szRx = sizeof (abtRx);
res = nfc_initiator_transceive_bytes (device, abtTx, sizeof (abtTx), abtRx, &szRx); res = nfc_initiator_transceive_bytes (device, abtTx, sizeof (abtTx), abtRx, &szRx);
// cut_assert_true (res, cut_message ("Can't transceive bytes to target")); // 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")); // cut_assert_equal_memory (abtAttRx, sizeof (abtAttRx), abtRx, szRx, cut_message ("Invalid received data"));
res = nfc_initiator_deselect_target (device); res = nfc_initiator_deselect_target (device);

View file

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

View file

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

View file

@ -113,7 +113,7 @@ uint8_t nfcforum_capability_container[] = {
#define ISO144434A_RATS 0xE0 #define ISO144434A_RATS 0xE0
int 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; int res = 0;

View file

@ -60,7 +60,7 @@ static mifare_classic_tag mtDump;
static bool bUseKeyA; static bool bUseKeyA;
static bool bUseKeyFile; static bool bUseKeyFile;
static uint8_t uiBlocks; static uint8_t uiBlocks;
static byte_t keys[] = { static uint8_t keys[] = {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xd3, 0xf7, 0xd3, 0xf7, 0xd3, 0xf7, 0xd3, 0xf7, 0xd3, 0xf7, 0xd3, 0xf7,
0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5,
@ -81,18 +81,18 @@ static size_t num_keys = sizeof (keys) / 6;
#define MAX_FRAME_LEN 264 #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 szRxBits;
static size_t szRx = sizeof(abtRx); 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 // special unlock command
byte_t abtUnlock1[1] = { 0x40 }; uint8_t abtUnlock1[1] = { 0x40 };
byte_t abtUnlock2[1] = { 0x43 }; uint8_t abtUnlock2[1] = { 0x43 };
static bool 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 // Show transmitted command
printf ("Sent bits: "); printf ("Sent bits: ");
@ -110,7 +110,7 @@ transmit_bits (const byte_t * pbtTx, const size_t szTxBits)
static bool 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 // Show transmitted command
printf ("Sent bits: "); printf ("Sent bits: ");
@ -458,7 +458,7 @@ int
main (int argc, const char *argv[]) main (int argc, const char *argv[])
{ {
action_t atAction = ACTION_USAGE; action_t atAction = ACTION_USAGE;
byte_t *pbtUID; uint8_t *pbtUID;
FILE *pfKeys = NULL; FILE *pfKeys = NULL;
FILE *pfDump = NULL; FILE *pfDump = NULL;
int unlock= 0; int unlock= 0;
@ -571,7 +571,7 @@ main (int argc, const char *argv[])
pbtUID = nt.nti.nai.abtUid; pbtUID = nt.nti.nai.abtUid;
if (bUseKeyFile) { if (bUseKeyFile) {
byte_t fileUid[4]; uint8_t fileUid[4];
memcpy (fileUid, mtKeys.amb[0].mbm.abtUID, 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 // 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) { if (memcmp (nt.nti.nai.abtUid, fileUid, 4) != 0) {

View file

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

View file

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

View file

@ -57,9 +57,9 @@
#define MAX_FRAME_LEN 264 #define MAX_FRAME_LEN 264
#define MAX_DEVICE_COUNT 2 #define MAX_DEVICE_COUNT 2
static byte_t abtCapdu[MAX_FRAME_LEN]; static uint8_t abtCapdu[MAX_FRAME_LEN];
static size_t szCapduLen; static size_t szCapduLen;
static byte_t abtRapdu[MAX_FRAME_LEN]; static uint8_t abtRapdu[MAX_FRAME_LEN];
static size_t szRapduLen; static size_t szRapduLen;
static nfc_device *pndInitiator; static nfc_device *pndInitiator;
static nfc_device *pndTarget; 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"); 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; size_t szPos;
if (szBytes > MAX_FRAME_LEN) { 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; 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; size_t szPos;
unsigned int uiBytes; 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 // PC/SC pseudo-ATR = 3B 80 80 01 01 if there is no historical bytes
// Creates ATS and copy max 48 bytes of Tk: // Creates ATS and copy max 48 bytes of Tk:
byte_t * pbtTk; uint8_t * pbtTk;
size_t szTk; size_t szTk;
pbtTk = iso14443a_locate_historical_bytes (ntEmulatedTarget.nti.nai.abtAts, ntEmulatedTarget.nti.nai.szAtsLen, &szTk); pbtTk = iso14443a_locate_historical_bytes (ntEmulatedTarget.nti.nai.abtAts, ntEmulatedTarget.nti.nai.szAtsLen, &szTk);
szTk = (szTk > 48) ? 48 : szTk; szTk = (szTk > 48) ? 48 : szTk;
byte_t pbtTkt[48]; uint8_t pbtTkt[48];
memcpy(pbtTkt, pbtTk, szTk); memcpy(pbtTkt, pbtTk, szTk);
ntEmulatedTarget.nti.nai.abtAts[0] = 0x75; ntEmulatedTarget.nti.nai.abtAts[0] = 0x75;
ntEmulatedTarget.nti.nai.abtAts[1] = 0x33; ntEmulatedTarget.nti.nai.abtAts[1] = 0x33;

View file

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

View file

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