Switch types to C99 standard using stdint.h

Add stdint.h header check to ./configure
Add -std=c99 to CFLAGS.
This commit is contained in:
Romuald Conty 2009-05-27 10:13:19 +00:00
parent d32d57f237
commit ab3664b056
15 changed files with 140 additions and 128 deletions

View file

@ -13,7 +13,7 @@ AC_PATH_PROG(PKG_CONFIG, pkg-config)
# Checks for header files. # Checks for header files.
AC_HEADER_STDC AC_HEADER_STDC
AC_CHECK_HEADERS([stdlib.h]) AC_CHECK_HEADERS([stdlib.h stdint.h])
# libusb # libusb
@ -40,10 +40,11 @@ AC_MSG_RESULT($enable_debug)
if test "x$enable_debug" = "xyes" if test "x$enable_debug" = "xyes"
then then
CFLAGS="$CFLAGS -g -Wall -DDEBUG" CFLAGS="$CFLAGS -g -Wall -DDEBUG -pedantic"
fi fi
AC_SUBST([DEBUG_CFLAGS]) AC_SUBST([DEBUG_CFLAGS])
CFLAGS="$CFLAGS -std=c99"
AC_CONFIG_FILES([ AC_CONFIG_FILES([
Makefile Makefile

View file

@ -20,16 +20,18 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdint.h>
#include <string.h> #include <string.h>
#include "libnfc.h" #include "libnfc.h"
#define SAK_FLAG_ATS_SUPPORTED 0x20 #define SAK_FLAG_ATS_SUPPORTED 0x20
static byte abtRx[MAX_FRAME_LEN]; static byte abtRx[MAX_FRAME_LEN];
static ui32 uiRxBits; static uint32_t uiRxBits;
static ui32 uiRxLen; static uint32_t uiRxLen;
static byte abtUid[10]; static byte abtUid[10];
static ui32 uiUidLen = 4; static uint32_t uiUidLen = 4;
static dev_info* pdi; static dev_info* pdi;
// ISO14443A Anti-Collision Commands // ISO14443A Anti-Collision Commands
@ -39,7 +41,7 @@ byte abtSelectTag [9] = { 0x93,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00 };
byte abtRats [4] = { 0xe0,0x50,0xbc,0xa5 }; byte abtRats [4] = { 0xe0,0x50,0xbc,0xa5 };
byte abtHalt [4] = { 0x50,0x00,0x57,0xcd }; byte abtHalt [4] = { 0x50,0x00,0x57,0xcd };
bool transmit_bits(const byte* pbtTx, const ui32 uiTxBits) bool transmit_bits(const byte* pbtTx, const uint32_t uiTxBits)
{ {
// Show transmitted command // Show transmitted command
printf("R: "); print_hex_bits(pbtTx,uiTxBits); printf("R: "); print_hex_bits(pbtTx,uiTxBits);
@ -55,7 +57,7 @@ bool transmit_bits(const byte* pbtTx, const ui32 uiTxBits)
} }
bool transmit_bytes(const byte* pbtTx, const ui32 uiTxLen) bool transmit_bytes(const byte* pbtTx, const uint32_t uiTxLen)
{ {
// Show transmitted command // Show transmitted command
printf("R: "); print_hex(pbtTx,uiTxLen); printf("R: "); print_hex(pbtTx,uiTxLen);

View file

@ -19,6 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <stdio.h> #include <stdio.h>
#include "bitutils.h" #include "bitutils.h"
const static byte OddParity[256] = { const static byte OddParity[256] = {
@ -68,9 +69,9 @@ byte oddparity(const byte bt)
return OddParity[bt]; return OddParity[bt];
} }
void oddparity_bytes(const byte* pbtData, const ui32 uiLen, byte* pbtPar) void oddparity_bytes(const byte* pbtData, const uint32_t uiLen, byte* pbtPar)
{ {
ui32 uiByteNr; uint32_t uiByteNr;
// Calculate the parity bits for the command // Calculate the parity bits for the command
for (uiByteNr=0; uiByteNr<uiLen; uiByteNr++) for (uiByteNr=0; uiByteNr<uiLen; uiByteNr++)
@ -84,21 +85,21 @@ byte mirror(byte bt)
return ByteMirror[bt]; return ByteMirror[bt];
} }
ui32 mirror32(ui32 ui32Bits) uint32_t mirror32(uint32_t ui32Bits)
{ {
mirror_bytes((byte*)&ui32Bits,4); mirror_bytes((byte*)&ui32Bits,4);
return ui32Bits; return ui32Bits;
} }
ui64 mirror64(ui64 ui64Bits) uint64_t mirror64(uint64_t ui64Bits)
{ {
mirror_bytes((byte*)&ui64Bits,8); mirror_bytes((byte*)&ui64Bits,8);
return ui64Bits; return ui64Bits;
} }
void mirror_bytes(byte *pbts, ui32 uiLen) void mirror_bytes(byte *pbts, uint32_t uiLen)
{ {
ui32 btNr; uint32_t btNr;
for (btNr=0; btNr<uiLen; btNr++) for (btNr=0; btNr<uiLen; btNr++)
{ {
@ -107,37 +108,37 @@ void mirror_bytes(byte *pbts, ui32 uiLen)
} }
} }
ui32 swap_endian32(const void* pui32) uint32_t swap_endian32(const void* pui32)
{ {
ui32 ui32N = *((ui32*)pui32); uint32_t ui32N = *((uint32_t*)pui32);
return (((ui32N&0xFF)<<24)+((ui32N&0xFF00)<<8)+((ui32N&0xFF0000)>>8)+((ui32N&0xFF000000)>>24)); return (((ui32N&0xFF)<<24)+((ui32N&0xFF00)<<8)+((ui32N&0xFF0000)>>8)+((ui32N&0xFF000000)>>24));
} }
ui64 swap_endian64(const void* pui64) uint64_t swap_endian64(const void* pui64)
{ {
ui64 ui64N = *((ui64*)pui64); uint64_t ui64N = *((uint64_t *)pui64);
return (((ui64N&0xFF)<<56)+((ui64N&0xFF00)<<40)+((ui64N&0xFF0000)<<24)+((ui64N&0xFF000000)<<8)+((ui64N&0xFF00000000ull)>>8)+((ui64N&0xFF0000000000ull)>>24)+((ui64N&0xFF000000000000ull)>>40)+((ui64N&0xFF00000000000000ull)>>56)); return (((ui64N&0xFF)<<56)+((ui64N&0xFF00)<<40)+((ui64N&0xFF0000)<<24)+((ui64N&0xFF000000)<<8)+((ui64N&0xFF00000000ull)>>8)+((ui64N&0xFF0000000000ull)>>24)+((ui64N&0xFF000000000000ull)>>40)+((ui64N&0xFF00000000000000ull)>>56));
} }
void append_iso14443a_crc(byte* pbtData, ui32 uiLen) void append_iso14443a_crc(byte* pbtData, uint32_t uiLen)
{ {
byte bt; byte bt;
ui32 wCrc = 0x6363; uint32_t wCrc = 0x6363;
do { do {
bt = *pbtData++; bt = *pbtData++;
bt = (bt^(byte)(wCrc & 0x00FF)); bt = (bt^(byte)(wCrc & 0x00FF));
bt = (bt^(bt<<4)); bt = (bt^(bt<<4));
wCrc = (wCrc >> 8)^((ui32)bt << 8)^((ui32)bt<<3)^((ui32)bt>>4); wCrc = (wCrc >> 8)^((uint32_t)bt << 8)^((uint32_t)bt<<3)^((uint32_t)bt>>4);
} while (--uiLen); } while (--uiLen);
*pbtData++ = (byte) (wCrc & 0xFF); *pbtData++ = (byte) (wCrc & 0xFF);
*pbtData = (byte) ((wCrc >> 8) & 0xFF); *pbtData = (byte) ((wCrc >> 8) & 0xFF);
} }
void print_hex(const byte* pbtData, const ui32 uiBytes) void print_hex(const byte* pbtData, const uint32_t uiBytes)
{ {
ui32 uiPos; uint32_t uiPos;
for (uiPos=0; uiPos < uiBytes; uiPos++) for (uiPos=0; uiPos < uiBytes; uiPos++)
{ {
@ -146,10 +147,10 @@ void print_hex(const byte* pbtData, const ui32 uiBytes)
printf("\n"); printf("\n");
} }
void print_hex_bits(const byte* pbtData, const ui32 uiBits) void print_hex_bits(const byte* pbtData, const uint32_t uiBits)
{ {
ui32 uiPos; uint32_t uiPos;
ui32 uiBytes = uiBits/8; uint32_t uiBytes = uiBits/8;
for (uiPos=0; uiPos < uiBytes; uiPos++) for (uiPos=0; uiPos < uiBytes; uiPos++)
{ {
@ -162,10 +163,10 @@ void print_hex_bits(const byte* pbtData, const ui32 uiBits)
printf("\n"); printf("\n");
} }
void print_hex_par(const byte* pbtData, const ui32 uiBits, const byte* pbtDataPar) void print_hex_par(const byte* pbtData, const uint32_t uiBits, const byte* pbtDataPar)
{ {
ui32 uiPos; uint32_t uiPos;
ui32 uiBytes = uiBits/8; uint32_t uiBytes = uiBits/8;
for (uiPos=0; uiPos < uiBytes; uiPos++) for (uiPos=0; uiPos < uiBytes; uiPos++)
{ {

View file

@ -21,24 +21,26 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef _LIBNFC_BITUTILS_H_ #ifndef _LIBNFC_BITUTILS_H_
#define _LIBNFC_BITUTILS_H_ #define _LIBNFC_BITUTILS_H_
#include <stdint.h>
#include "defines.h" #include "defines.h"
byte oddparity(const byte bt); byte oddparity(const byte bt);
void oddparity_bytes(const byte* pbtData, const ui32 uiLen, byte* pbtPar); void oddparity_bytes(const byte* pbtData, const uint32_t uiLen, byte* pbtPar);
byte mirror(byte bt); byte mirror(byte bt);
ui32 mirror32(ui32 ui32Bits); uint32_t mirror32(uint32_t ui32Bits);
ui64 mirror64(ui64 ui64Bits); uint64_t mirror64(uint64_t ui64Bits);
void mirror_bytes(byte *pbts, ui32 uiLen); void mirror_bytes(byte *pbts, uint32_t uiLen);
ui32 swap_endian32(const void* pui32); uint32_t swap_endian32(const void* pui32);
ui64 swap_endian64(const void* pui64); uint64_t swap_endian64(const void* pui64);
void append_iso14443a_crc(byte* pbtData, ui32 uiLen); void append_iso14443a_crc(byte* pbtData, uint32_t uiLen);
void print_hex(const byte* pbtData, const ui32 uiLen); void print_hex(const byte* pbtData, const uint32_t uiLen);
void print_hex_bits(const byte* pbtData, const ui32 uiBits); void print_hex_bits(const byte* pbtData, const uint32_t uiBits);
void print_hex_par(const byte* pbtData, const ui32 uiBits, const byte* pbtDataPar); void print_hex_par(const byte* pbtData, const uint32_t uiBits, const byte* pbtDataPar);
#endif // _LIBNFC_BITUTILS_H_ #endif // _LIBNFC_BITUTILS_H_

View file

@ -24,14 +24,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
// #define DEBUG // #define DEBUG
typedef unsigned char byte; typedef unsigned char byte;
typedef unsigned char ui8;
typedef unsigned short ui16;
typedef unsigned int ui32;
typedef unsigned long long ui64;
typedef unsigned long ulong; typedef unsigned long ulong;
typedef char i8;
typedef short i16;
typedef int i32;
#define null 0 #define null 0

View file

@ -57,15 +57,15 @@ static ulong ulRxBufLen;
static byte abtGetFw[5] = { 0xFF,0x00,0x48,0x00,0x00 }; static byte abtGetFw[5] = { 0xFF,0x00,0x48,0x00,0x00 };
static byte abtLed[9] = { 0xFF,0x00,0x40,0x05,0x04,0x00,0x00,0x00,0x00 }; static byte abtLed[9] = { 0xFF,0x00,0x40,0x05,0x04,0x00,0x00,0x00,0x00 };
dev_info* dev_acr122_connect(const ui32 uiIndex) dev_info* dev_acr122_connect(const uint32_t uiIndex)
{ {
char* pacReaders[MAX_READERS]; char* pacReaders[MAX_READERS];
char acList[256+64*MAX_READERS]; char acList[256+64*MAX_READERS];
ulong ulListLen = sizeof(acList); ulong ulListLen = sizeof(acList);
ui32 uiPos; uint32_t uiPos;
ui32 uiReaderCount; uint32_t uiReaderCount;
ui32 uiReader; uint32_t uiReader;
ui32 uiDevIndex; uint32_t uiDevIndex;
dev_info* pdi; dev_info* pdi;
dev_spec_acr122* pdsa; dev_spec_acr122* pdsa;
dev_spec_acr122 dsa; dev_spec_acr122 dsa;
@ -172,7 +172,7 @@ void dev_acr122_disconnect(dev_info* pdi)
free(pdi); free(pdi);
} }
bool dev_acr122_transceive(const dev_spec ds, const byte* pbtTx, const ui32 uiTxLen, byte* pbtRx, ui32* puiRxLen) bool dev_acr122_transceive(const dev_spec ds, const byte* pbtTx, const uint32_t uiTxLen, byte* pbtRx, uint32_t* puiRxLen)
{ {
dev_spec_acr122* pdsa = (dev_spec_acr122*)ds; dev_spec_acr122* pdsa = (dev_spec_acr122*)ds;
@ -231,7 +231,7 @@ bool dev_acr122_transceive(const dev_spec ds, const byte* pbtTx, const ui32 uiTx
char* dev_acr122_firmware(const dev_spec ds) char* dev_acr122_firmware(const dev_spec ds)
{ {
ui32 uiResult; uint32_t uiResult;
dev_spec_acr122* pdsa = (dev_spec_acr122*)ds; dev_spec_acr122* pdsa = (dev_spec_acr122*)ds;
static char abtFw[11]; static char abtFw[11];

View file

@ -21,15 +21,17 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef _LIBNFC_DEV_ACR122_H_ #ifndef _LIBNFC_DEV_ACR122_H_
#define _LIBNFC_DEV_ACR122_H_ #define _LIBNFC_DEV_ACR122_H_
#include <stdint.h>
#include "defines.h" #include "defines.h"
#include "types.h" #include "types.h"
// Functions used by developer to handle connection to this device // Functions used by developer to handle connection to this device
dev_info* dev_acr122_connect(const ui32 uiIndex); dev_info* dev_acr122_connect(const uint32_t uiIndex);
void dev_acr122_disconnect(dev_info* pdi); void dev_acr122_disconnect(dev_info* pdi);
// Callback function used by libnfc to transmit commands to the PN53X chip // Callback function used by libnfc to transmit commands to the PN53X chip
bool dev_acr122_transceive(const dev_spec ds, const byte* pbtTx, const ui32 uiTxLen, byte* pbtRx, ui32* puiRxLen); bool dev_acr122_transceive(const dev_spec ds, const byte* pbtTx, const uint32_t uiTxLen, byte* pbtRx, uint32_t* puiRxLen);
// Various additional features this device supports // Various additional features this device supports
char* dev_acr122_firmware(const dev_spec ds); char* dev_acr122_firmware(const dev_spec ds);

View file

@ -34,15 +34,15 @@ static char buffer[BUFFER_LENGTH] = { 0x00, 0x00, 0xff }; // Every packet must s
typedef struct { typedef struct {
usb_dev_handle* pudh; usb_dev_handle* pudh;
ui32 uiEndPointIn; uint32_t uiEndPointIn;
ui32 uiEndPointOut; uint32_t uiEndPointOut;
} dev_spec_pn531; } dev_spec_pn531;
// Find transfer endpoints for bulk transfers // Find transfer endpoints for bulk transfers
void get_end_points(struct usb_device *dev, dev_spec_pn531* pdsp) void get_end_points(struct usb_device *dev, dev_spec_pn531* pdsp)
{ {
ui32 uiIndex; uint32_t uiIndex;
ui32 uiEndPoint; uint32_t uiEndPoint;
struct usb_interface_descriptor* puid = dev->config->interface->altsetting; struct usb_interface_descriptor* puid = dev->config->interface->altsetting;
// 3 Endpoints maximum: Interrupt In, Bulk In, Bulk Out // 3 Endpoints maximum: Interrupt In, Bulk In, Bulk Out
@ -74,7 +74,7 @@ void get_end_points(struct usb_device *dev, dev_spec_pn531* pdsp)
} }
} }
dev_info* dev_pn531_connect(const ui32 uiIndex) dev_info* dev_pn531_connect(const uint32_t uiIndex)
{ {
int idvendor = 0x04CC; int idvendor = 0x04CC;
int idproduct = 0x0531; int idproduct = 0x0531;
@ -83,7 +83,7 @@ dev_info* dev_pn531_connect(const ui32 uiIndex)
dev_info* pdi = INVALID_DEVICE_INFO; dev_info* pdi = INVALID_DEVICE_INFO;
dev_spec_pn531* pdsp; dev_spec_pn531* pdsp;
dev_spec_pn531 dsp; dev_spec_pn531 dsp;
ui32 uiDevIndex; uint32_t uiDevIndex;
dsp.uiEndPointIn = 0; dsp.uiEndPointIn = 0;
dsp.uiEndPointOut = 0; dsp.uiEndPointOut = 0;
@ -164,9 +164,9 @@ void dev_pn531_disconnect(dev_info* pdi)
free(pdi); free(pdi);
} }
bool dev_pn531_transceive(const dev_spec ds, const byte* pbtTx, const ui32 uiTxLen, byte* pbtRx, ui32* puiRxLen) bool dev_pn531_transceive(const dev_spec ds, const byte* pbtTx, const uint32_t uiTxLen, byte* pbtRx, uint32_t* puiRxLen)
{ {
ui32 uiPos = 0; uint32_t uiPos = 0;
int ret = 0; int ret = 0;
char buf[BUFFER_LENGTH]; char buf[BUFFER_LENGTH];
dev_spec_pn531* pdsp = (dev_spec_pn531*)ds; dev_spec_pn531* pdsp = (dev_spec_pn531*)ds;

View file

@ -21,15 +21,17 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef _LIBNFC_DEV_PN531_H_ #ifndef _LIBNFC_DEV_PN531_H_
#define _LIBNFC_DEV_PN531_H_ #define _LIBNFC_DEV_PN531_H_
#include <stdint.h>
#include "defines.h" #include "defines.h"
#include "types.h" #include "types.h"
// Functions used by developer to handle connection to this device // Functions used by developer to handle connection to this device
dev_info* dev_pn531_connect(const ui32 uiIndex); dev_info* dev_pn531_connect(const uint32_t uiIndex);
void dev_pn531_disconnect(dev_info* pdi); void dev_pn531_disconnect(dev_info* pdi);
// Callback function used by libnfc to transmit commands to the PN53X chip // Callback function used by libnfc to transmit commands to the PN53X chip
bool dev_pn531_transceive(const dev_spec ds, const byte* pbtTx, const ui32 uiTxLen, byte* pbtRx, ui32* puiRxLen); bool dev_pn531_transceive(const dev_spec ds, const byte* pbtTx, const uint32_t uiTxLen, byte* pbtRx, uint32_t* puiRxLen);
#endif // _LIBNFC_DEV_PN531_H_ #endif // _LIBNFC_DEV_PN531_H_

View file

@ -20,11 +20,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdint.h>
#include <string.h> #include <string.h>
#include "libnfc.h" #include "libnfc.h"
static byte abtRecv[MAX_FRAME_LEN]; static byte abtRecv[MAX_FRAME_LEN];
static ui32 uiRecvBits; static uint32_t uiRecvBits;
static dev_info* pdi; static dev_info* pdi;
// ISO14443A Anti-Collision response // ISO14443A Anti-Collision response
@ -35,7 +37,7 @@ byte abtSak [9] = { 0x08,0xb6,0xdd };
int main(int argc, const char* argv[]) int main(int argc, const char* argv[])
{ {
byte* pbtTx = null; byte* pbtTx = null;
ui32 uiTxBits; uint32_t uiTxBits;
// Try to open the NFC reader // Try to open the NFC reader
pdi = nfc_connect(); pdi = nfc_connect();

View file

@ -88,9 +88,9 @@ byte pncmd_exchange_raw_data [266] = { 0xD4,0x42 };
// Global buffers used for communication with the PN53X chip // Global buffers used for communication with the PN53X chip
#define MAX_FRAME_LEN 264 #define MAX_FRAME_LEN 264
static byte abtRx[MAX_FRAME_LEN]; static byte abtRx[MAX_FRAME_LEN];
static ui32 uiRxLen; static uint32_t uiRxLen;
bool pn53x_transceive(const dev_info* pdi, const byte* pbtTx, const ui32 uiTxLen) bool pn53x_transceive(const dev_info* pdi, const byte* pbtTx, const uint32_t uiTxLen)
{ {
// Reset the receiving buffer // Reset the receiving buffer
uiRxLen = MAX_FRAME_LEN; uiRxLen = MAX_FRAME_LEN;
@ -105,17 +105,17 @@ bool pn53x_transceive(const dev_info* pdi, const byte* pbtTx, const ui32 uiTxLen
return true; return true;
} }
byte pn53x_get_reg(const dev_info* pdi, ui16 ui16Reg) byte pn53x_get_reg(const dev_info* pdi, uint16_t ui16Reg)
{ {
ui8 ui8Value; uint8_t ui8Value;
ui32 uiValueLen = 1; uint32_t uiValueLen = 1;
pncmd_get_register[2] = ui16Reg >> 8; pncmd_get_register[2] = ui16Reg >> 8;
pncmd_get_register[3] = ui16Reg & 0xff; pncmd_get_register[3] = ui16Reg & 0xff;
pdi->pdc->transceive(pdi->ds,pncmd_get_register,4,&ui8Value,&uiValueLen); pdi->pdc->transceive(pdi->ds,pncmd_get_register,4,&ui8Value,&uiValueLen);
return ui8Value; return ui8Value;
} }
bool pn53x_set_reg(const dev_info* pdi, ui16 ui16Reg, ui8 ui8SybmolMask, ui8 ui8Value) bool pn53x_set_reg(const dev_info* pdi, uint16_t ui16Reg, uint8_t ui8SybmolMask, uint8_t ui8Value)
{ {
pncmd_set_register[2] = ui16Reg >> 8; pncmd_set_register[2] = ui16Reg >> 8;
pncmd_set_register[3] = ui16Reg & 0xff; pncmd_set_register[3] = ui16Reg & 0xff;
@ -123,13 +123,13 @@ bool pn53x_set_reg(const dev_info* pdi, ui16 ui16Reg, ui8 ui8SybmolMask, ui8 ui8
return pdi->pdc->transceive(pdi->ds,pncmd_set_register,5,null,null); return pdi->pdc->transceive(pdi->ds,pncmd_set_register,5,null,null);
} }
bool pn53x_set_parameters(const dev_info* pdi, ui8 ui8Value) bool pn53x_set_parameters(const dev_info* pdi, uint8_t ui8Value)
{ {
pncmd_set_parameters[2] = ui8Value; pncmd_set_parameters[2] = ui8Value;
return pdi->pdc->transceive(pdi->ds,pncmd_set_parameters,3,null,null); return pdi->pdc->transceive(pdi->ds,pncmd_set_parameters,3,null,null);
} }
bool pn53x_set_tx_bits(const dev_info* pdi, ui8 ui8Bits) bool pn53x_set_tx_bits(const dev_info* pdi, uint8_t ui8Bits)
{ {
// Test if we need to update the transmission bits register setting // Test if we need to update the transmission bits register setting
if (pdi->ui8TxBits != ui8Bits) if (pdi->ui8TxBits != ui8Bits)
@ -143,13 +143,13 @@ bool pn53x_set_tx_bits(const dev_info* pdi, ui8 ui8Bits)
return true; return true;
} }
bool pn53x_wrap_frame(const byte* pbtTx, const ui32 uiTxBits, const byte* pbtTxPar, byte* pbtFrame, ui32* puiFrameBits) bool pn53x_wrap_frame(const byte* pbtTx, const uint32_t uiTxBits, const byte* pbtTxPar, byte* pbtFrame, uint32_t* puiFrameBits)
{ {
byte btFrame; byte btFrame;
byte btData; byte btData;
ui32 uiBitPos; uint32_t uiBitPos;
ui32 uiDataPos = 0; uint32_t uiDataPos = 0;
ui32 uiBitsLeft = uiTxBits; uint32_t uiBitsLeft = uiTxBits;
// Make sure we should frame at least something // Make sure we should frame at least something
if (uiBitsLeft == 0) return false; if (uiBitsLeft == 0) return false;
@ -199,14 +199,14 @@ bool pn53x_wrap_frame(const byte* pbtTx, const ui32 uiTxBits, const byte* pbtTxP
} }
} }
bool pn53x_unwrap_frame(const byte* pbtFrame, const ui32 uiFrameBits, byte* pbtRx, ui32* puiRxBits, byte* pbtRxPar) bool pn53x_unwrap_frame(const byte* pbtFrame, const uint32_t uiFrameBits, byte* pbtRx, uint32_t* puiRxBits, byte* pbtRxPar)
{ {
byte btFrame; byte btFrame;
byte btData; byte btData;
ui8 uiBitPos; uint8_t uiBitPos;
ui32 uiDataPos = 0; uint32_t uiDataPos = 0;
byte* pbtFramePos = (byte*) pbtFrame; byte* pbtFramePos = (byte*) pbtFrame;
ui32 uiBitsLeft = uiFrameBits; uint32_t uiBitsLeft = uiFrameBits;
// Make sure we should frame at least something // Make sure we should frame at least something
if (uiBitsLeft == 0) return false; if (uiBitsLeft == 0) return false;
@ -248,9 +248,9 @@ bool pn53x_unwrap_frame(const byte* pbtFrame, const ui32 uiFrameBits, byte* pbtR
dev_info* nfc_connect() dev_info* nfc_connect()
{ {
dev_info* pdi; dev_info* pdi;
ui32 uiDev; uint32_t uiDev;
byte abtFw[4]; byte abtFw[4];
ui32 uiFwLen = sizeof(abtFw); uint32_t uiFwLen = sizeof(abtFw);
// Search through the device list for an available device // Search through the device list for an available device
for (uiDev=0; uiDev<sizeof(dev_callbacks_list)/sizeof(dev_callbacks_list[0]); uiDev++) for (uiDev=0; uiDev<sizeof(dev_callbacks_list)/sizeof(dev_callbacks_list[0]); uiDev++)
@ -379,7 +379,7 @@ bool nfc_reader_init(const dev_info* pdi)
return true; return true;
} }
bool nfc_reader_select(const dev_info* pdi, const init_modulation im, const byte* pbtInitData, const ui32 uiInitDataLen, tag_info* pti) bool nfc_reader_select(const dev_info* pdi, const init_modulation im, const byte* pbtInitData, const uint32_t uiInitDataLen, tag_info* pti)
{ {
// Make sure we are dealing with a active device // Make sure we are dealing with a active device
if (!pdi->bActive) return false; if (!pdi->bActive) return false;
@ -480,11 +480,11 @@ bool nfc_reader_deselect(const dev_info* pdi)
return (pdi->pdc->transceive(pdi->ds,pncmd_reader_deselect,3,null,null)); return (pdi->pdc->transceive(pdi->ds,pncmd_reader_deselect,3,null,null));
} }
bool nfc_reader_transceive_bits(const dev_info* pdi, const byte* pbtTx, const ui32 uiTxBits, const byte* pbtTxPar, byte* pbtRx, ui32* puiRxBits, byte* pbtRxPar) bool nfc_reader_transceive_bits(const dev_info* pdi, const byte* pbtTx, const uint32_t uiTxBits, const byte* pbtTxPar, byte* pbtRx, uint32_t* puiRxBits, byte* pbtRxPar)
{ {
ui32 uiFrameBits = 0; uint32_t uiFrameBits = 0;
ui32 uiFrameBytes = 0; uint32_t uiFrameBytes = 0;
ui8 ui8Bits = 0; uint8_t ui8Bits = 0;
// Check if we should prepare the parity bits ourself // Check if we should prepare the parity bits ourself
if (!pdi->bPar) if (!pdi->bPar)
@ -534,7 +534,7 @@ bool nfc_reader_transceive_bits(const dev_info* pdi, const byte* pbtTx, const ui
return true; return true;
} }
bool nfc_reader_transceive_bytes(const dev_info* pdi, const byte* pbtTx, const ui32 uiTxLen, byte* pbtRx, ui32* puiRxLen) bool nfc_reader_transceive_bytes(const dev_info* pdi, const byte* pbtTx, const uint32_t uiTxLen, byte* pbtRx, uint32_t* puiRxLen)
{ {
// 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 (!pdi->bPar) return false; if (!pdi->bPar) return false;
@ -559,9 +559,9 @@ bool nfc_reader_transceive_bytes(const dev_info* pdi, const byte* pbtTx, const u
return true; return true;
} }
bool nfc_reader_mifare_cmd(const dev_info* pdi, const mifare_cmd mc, const ui8 ui8Block, mifare_param* pmp) bool nfc_reader_mifare_cmd(const dev_info* pdi, const mifare_cmd mc, const uint8_t ui8Block, mifare_param* pmp)
{ {
ui32 uiParamLen; uint32_t uiParamLen;
// Make sure we are dealing with a active device // Make sure we are dealing with a active device
if (!pdi->bActive) return false; if (!pdi->bActive) return false;
@ -615,9 +615,9 @@ bool nfc_reader_mifare_cmd(const dev_info* pdi, const mifare_cmd mc, const ui8 u
return true; return true;
} }
bool nfc_target_init(const dev_info* pdi, byte* pbtRx, ui32* puiRxBits) bool nfc_target_init(const dev_info* pdi, byte* pbtRx, uint32_t* puiRxBits)
{ {
ui8 ui8Bits; uint8_t ui8Bits;
// Save the current configuration settings // Save the current configuration settings
bool bCrc = pdi->bCrc; bool bCrc = pdi->bCrc;
@ -665,10 +665,10 @@ bool nfc_target_init(const dev_info* pdi, byte* pbtRx, ui32* puiRxBits)
return true; return true;
} }
bool nfc_target_receive_bits(const dev_info* pdi, byte* pbtRx, ui32* puiRxBits, byte* pbtRxPar) bool nfc_target_receive_bits(const dev_info* pdi, byte* pbtRx, uint32_t* puiRxBits, byte* pbtRxPar)
{ {
ui32 uiFrameBits; uint32_t uiFrameBits;
ui8 ui8Bits; uint8_t ui8Bits;
// Try to gather a received frame from the reader // Try to gather a received frame from the reader
if (!pn53x_transceive(pdi,pncmd_target_receive,2)) return false; if (!pn53x_transceive(pdi,pncmd_target_receive,2)) return false;
@ -695,7 +695,7 @@ bool nfc_target_receive_bits(const dev_info* pdi, byte* pbtRx, ui32* puiRxBits,
return true; return true;
} }
bool nfc_target_receive_bytes(const dev_info* pdi, byte* pbtRx, ui32* puiRxLen) bool nfc_target_receive_bytes(const dev_info* pdi, byte* pbtRx, uint32_t* puiRxLen)
{ {
// Try to gather a received frame from the reader // Try to gather a received frame from the reader
if (!pn53x_transceive(pdi,pncmd_target_receive,2)) return false; if (!pn53x_transceive(pdi,pncmd_target_receive,2)) return false;
@ -710,11 +710,11 @@ bool nfc_target_receive_bytes(const dev_info* pdi, byte* pbtRx, ui32* puiRxLen)
return true; return true;
} }
bool nfc_target_send_bits(const dev_info* pdi, const byte* pbtTx, const ui32 uiTxBits, const byte* pbtTxPar) bool nfc_target_send_bits(const dev_info* pdi, const byte* pbtTx, const uint32_t uiTxBits, const byte* pbtTxPar)
{ {
ui32 uiFrameBits = 0; uint32_t uiFrameBits = 0;
ui32 uiFrameBytes = 0; uint32_t uiFrameBytes = 0;
ui8 ui8Bits = 0; uint8_t ui8Bits = 0;
// Check if we should prepare the parity bits ourself // Check if we should prepare the parity bits ourself
if (!pdi->bPar) if (!pdi->bPar)
@ -745,7 +745,7 @@ bool nfc_target_send_bits(const dev_info* pdi, const byte* pbtTx, const ui32 uiT
} }
bool nfc_target_send_bytes(const dev_info* pdi, const byte* pbtTx, const ui32 uiTxLen) bool nfc_target_send_bytes(const dev_info* pdi, const byte* pbtTx, const uint32_t uiTxLen)
{ {
// 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 (!pdi->bPar) return false; if (!pdi->bPar) return false;

View file

@ -21,6 +21,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef _LIBNFC_H_ #ifndef _LIBNFC_H_
#define _LIBNFC_H_ #define _LIBNFC_H_
#include <stdint.h>
#include "defines.h" #include "defines.h"
#include "types.h" #include "types.h"
#include "bitutils.h" #include "bitutils.h"
@ -31,17 +33,17 @@ void nfc_disconnect(dev_info* pdi);
bool nfc_configure(dev_info* pdi, const dev_config_option dco, const bool bEnable); bool nfc_configure(dev_info* pdi, const dev_config_option dco, const bool bEnable);
bool nfc_reader_init(const dev_info* pdi); bool nfc_reader_init(const dev_info* pdi);
bool nfc_reader_select(const dev_info* pdi, const init_modulation im, const byte* pbtInitData, const ui32 uiInitDataLen, tag_info* pti); bool nfc_reader_select(const dev_info* pdi, const init_modulation im, const byte* pbtInitData, const uint32_t uiInitDataLen, tag_info* pti);
bool nfc_reader_deselect(const dev_info* pdi); bool nfc_reader_deselect(const dev_info* pdi);
bool nfc_reader_transceive_bits(const dev_info* pdi, const byte* pbtTx, const ui32 uiTxBits, const byte* pbtTxPar, byte* pbtRx, ui32* puiRxBits, byte* pbtRxPar); bool nfc_reader_transceive_bits(const dev_info* pdi, const byte* pbtTx, const uint32_t uiTxBits, const byte* pbtTxPar, byte* pbtRx, uint32_t* puiRxBits, byte* pbtRxPar);
bool nfc_reader_transceive_bytes(const dev_info* pdi, const byte* pbtTx, const ui32 uiTxLen, byte* pbtRx, ui32* puiRxLen); bool nfc_reader_transceive_bytes(const dev_info* pdi, const byte* pbtTx, const uint32_t uiTxLen, byte* pbtRx, uint32_t* puiRxLen);
bool nfc_reader_mifare_cmd(const dev_info* pdi, const mifare_cmd mc, const ui8 ui8Block, mifare_param* pmp); bool nfc_reader_mifare_cmd(const dev_info* pdi, const mifare_cmd mc, const uint8_t ui8Block, mifare_param* pmp);
bool nfc_target_init(const dev_info* pdi, byte* pbtRx, ui32* puiRxBits); bool nfc_target_init(const dev_info* pdi, byte* pbtRx, uint32_t* puiRxBits);
bool nfc_target_receive_bits(const dev_info* pdi, byte* pbtRx, ui32* puiRxBits, byte* pbtRxPar); bool nfc_target_receive_bits(const dev_info* pdi, byte* pbtRx, uint32_t* puiRxBits, byte* pbtRxPar);
bool nfc_target_receive_bytes(const dev_info* pdi, byte* pbtRx, ui32* puiRxLen); bool nfc_target_receive_bytes(const dev_info* pdi, byte* pbtRx, uint32_t* puiRxLen);
bool nfc_target_send_bits(const dev_info* pdi, const byte* pbtTx, const ui32 uiTxBits, const byte* pbtTxPar); bool nfc_target_send_bits(const dev_info* pdi, const byte* pbtTx, const uint32_t uiTxBits, const byte* pbtTxPar);
bool nfc_target_send_bytes(const dev_info* pdi, const byte* pbtTx, const ui32 uiTxLen); bool nfc_target_send_bytes(const dev_info* pdi, const byte* pbtTx, const uint32_t uiTxLen);
#endif // _LIBNFC_H_ #endif // _LIBNFC_H_

View file

@ -20,6 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdint.h>
#include <string.h> #include <string.h>
#include <ctype.h> #include <ctype.h>
@ -32,21 +33,21 @@ static mifare_param mp;
static mifare_tag mtKeys; static mifare_tag mtKeys;
static mifare_tag mtDump; static mifare_tag mtDump;
static bool bUseKeyA; static bool bUseKeyA;
static ui32 uiBlocks; static uint32_t uiBlocks;
bool is_first_block(ui32 uiBlock) bool is_first_block(uint32_t uiBlock)
{ {
// Test if we are in the small or big sectors // Test if we are in the small or big sectors
if (uiBlock < 128) return ((uiBlock)%4 == 0); else return ((uiBlock)%16 == 0); if (uiBlock < 128) return ((uiBlock)%4 == 0); else return ((uiBlock)%16 == 0);
} }
bool is_trailer_block(ui32 uiBlock) bool is_trailer_block(uint32_t uiBlock)
{ {
// Test if we are in the small or big sectors // Test if we are in the small or big sectors
if (uiBlock < 128) return ((uiBlock+1)%4 == 0); else return ((uiBlock+1)%16 == 0); if (uiBlock < 128) return ((uiBlock+1)%4 == 0); else return ((uiBlock+1)%16 == 0);
} }
ui32 get_trailer_block(ui32 uiFirstBlock) uint32_t get_trailer_block(uint32_t uiFirstBlock)
{ {
// Test if we are in the small or big sectors // Test if we are in the small or big sectors
if (uiFirstBlock<128) return uiFirstBlock+3; else return uiFirstBlock+15; if (uiFirstBlock<128) return uiFirstBlock+3; else return uiFirstBlock+15;
@ -54,7 +55,7 @@ ui32 get_trailer_block(ui32 uiFirstBlock)
bool read_card() bool read_card()
{ {
i32 iBlock; int32_t iBlock;
mifare_cmd mc; mifare_cmd mc;
bool bFailure = false; bool bFailure = false;
@ -136,8 +137,8 @@ bool read_card()
bool write_card() bool write_card()
{ {
ui32 uiBlock; uint32_t uiBlock;
ui32 uiTrailerBlock; uint32_t uiTrailerBlock;
bool bFailure = false; bool bFailure = false;
mifare_cmd mc; mifare_cmd mc;

View file

@ -20,15 +20,17 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdint.h>
#include <string.h> #include <string.h>
#include "libnfc.h" #include "libnfc.h"
static byte abtReaderRx[MAX_FRAME_LEN]; static byte abtReaderRx[MAX_FRAME_LEN];
static byte abtReaderRxPar[MAX_FRAME_LEN]; static byte abtReaderRxPar[MAX_FRAME_LEN];
static ui32 uiReaderRxBits; static uint32_t uiReaderRxBits;
static byte abtTagRx[MAX_FRAME_LEN]; static byte abtTagRx[MAX_FRAME_LEN];
static byte abtTagRxPar[MAX_FRAME_LEN]; static byte abtTagRxPar[MAX_FRAME_LEN];
static ui32 uiTagRxBits; static uint32_t uiTagRxBits;
static dev_info* pdiReader; static dev_info* pdiReader;
static dev_info* pdiTag; static dev_info* pdiTag;

View file

@ -21,6 +21,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef _LIBNFC_TYPES_H_ #ifndef _LIBNFC_TYPES_H_
#define _LIBNFC_TYPES_H_ #define _LIBNFC_TYPES_H_
#include <stdint.h>
#include "defines.h" #include "defines.h"
// Compiler directive, set struct alignment to 1 byte for compatibility // Compiler directive, set struct alignment to 1 byte for compatibility
@ -47,13 +49,13 @@ typedef struct {
bool bActive; // This represents if the PN53X device was initialized succesful bool bActive; // This represents if the PN53X device was initialized succesful
bool bCrc; // Is the crc automaticly added, checked and removed from the frames bool bCrc; // Is the crc automaticly added, checked and removed from the frames
bool bPar; // Does the PN53x chip handles parity bits, all parities are handled as data bool bPar; // Does the PN53x chip handles parity bits, all parities are handled as data
ui8 ui8TxBits; // The last tx bits setting, we need to reset this if it does not apply anymore uint8_t ui8TxBits; // The last tx bits setting, we need to reset this if it does not apply anymore
} dev_info; } dev_info;
struct dev_callbacks { struct dev_callbacks {
const char* acDriver; // Driver description const char* acDriver; // Driver description
dev_info* (*connect)(const ui32 uiIndex); dev_info* (*connect)(const uint32_t uiIndex);
bool (*transceive)(const dev_spec ds, const byte* pbtTx, const ui32 uiTxLen, byte* pbtRx, ui32* puiRxLen); bool (*transceive)(const dev_spec ds, const byte* pbtTx, const uint32_t uiTxLen, byte* pbtRx, uint32_t* puiRxLen);
void (*disconnect)(dev_info* pdi); void (*disconnect)(dev_info* pdi);
}; };
@ -81,14 +83,14 @@ typedef enum {
typedef struct { typedef struct {
byte abtAtqa[2]; byte abtAtqa[2];
byte btSak; byte btSak;
ui32 uiUidLen; uint32_t uiUidLen;
byte abtUid[10]; byte abtUid[10];
ui32 uiAtsLen; uint32_t uiAtsLen;
byte abtAts[36]; byte abtAts[36];
}tag_info_iso14443a; }tag_info_iso14443a;
typedef struct { typedef struct {
ui32 uiLen; uint32_t uiLen;
byte btResCode; byte btResCode;
byte abtId[8]; byte abtId[8];
byte abtPad[8]; byte abtPad[8];
@ -103,7 +105,7 @@ typedef struct {
byte btParam3; byte btParam3;
byte btParam4; byte btParam4;
byte btCid; byte btCid;
ui32 uiInfLen; uint32_t uiInfLen;
byte abtInf[64]; byte abtInf[64];
}tag_info_iso14443b; }tag_info_iso14443b;