From 8b2ca5da1c9dcde47988b3396c00aab0e4c7ddf5 Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Wed, 27 May 2009 08:54:50 +0000 Subject: [PATCH 01/29] Use DEBUG define instead of _LIBNFC_VERBOSE_ to enable debug messages. Add --enable-debug option to ./configure --- configure.ac | 13 +++++++++++++ src/defines.h | 2 +- src/dev_acr122.c | 10 +++++----- src/dev_pn531.c | 22 +++++++++++----------- 4 files changed, 30 insertions(+), 17 deletions(-) diff --git a/configure.ac b/configure.ac index 73042c3..da0d2df 100644 --- a/configure.ac +++ b/configure.ac @@ -32,6 +32,19 @@ fi AC_SUBST(LIBPCSCLITE_LIBS) AC_SUBST(LIBPCSCLITE_CFLAGS) +# --enable-debug support +AC_ARG_ENABLE([debug],AS_HELP_STRING([--enable-debug],[Debug flags]),[enable_debug=$enableval],[enable_debug="no"]) + +AC_MSG_CHECKING(debug) +AC_MSG_RESULT($enable_debug) + +if test "x$enable_debug" = "xyes" +then + CFLAGS="$CFLAGS -g -Wall -DDEBUG" +fi +AC_SUBST([DEBUG_CFLAGS]) + + AC_CONFIG_FILES([ Makefile src/Makefile diff --git a/src/defines.h b/src/defines.h index 6ec18e2..2c63865 100644 --- a/src/defines.h +++ b/src/defines.h @@ -21,7 +21,7 @@ along with this program. If not, see . #ifndef _LIBNFC_DEFINES_H_ #define _LIBNFC_DEFINES_H_ -// #define _LIBNFC_VERBOSE_ +// #define DEBUG typedef unsigned char byte; typedef unsigned char ui8; diff --git a/src/dev_acr122.c b/src/dev_acr122.c index b8bb640..cb2495a 100644 --- a/src/dev_acr122.c +++ b/src/dev_acr122.c @@ -80,7 +80,7 @@ dev_info* dev_acr122_connect(const ui32 uiIndex) // Retrieve the string array of all available pcsc readers if (SCardListReaders(dsa.hCtx,null,acList,(void*)&ulListLen) != SCARD_S_SUCCESS) return INVALID_DEVICE_INFO; - #ifdef _LIBNFC_VERBOSE_ + #ifdef DEBUG printf("Found the following PCSC device(s)\n"); printf("- %s\n",acList); #endif @@ -105,7 +105,7 @@ dev_info* dev_acr122_connect(const ui32 uiIndex) uiReaderCount++; // Debug info - #ifdef _LIBNFC_VERBOSE_ + #ifdef DEBUG printf("- %s\n",acList+uiPos+1); #endif } @@ -185,7 +185,7 @@ bool dev_acr122_transceive(const dev_spec ds, const byte* pbtTx, const ui32 uiTx // Prepare and transmit the send buffer memcpy(abtTxBuf+5,pbtTx,uiTxLen); ulRxBufLen = sizeof(abtRxBuf); - #ifdef _LIBNFC_VERBOSE_ + #ifdef DEBUG printf("Tx: "); print_hex(abtTxBuf,uiTxLen+5); #endif @@ -211,7 +211,7 @@ bool dev_acr122_transceive(const dev_spec ds, const byte* pbtTx, const ui32 uiTx if (SCardTransmit(pdsa->hCard,&(pdsa->ioCard),abtRxCmd,uiRxCmdLen,null,abtRxBuf,(void*)&ulRxBufLen) != SCARD_S_SUCCESS) return false; } - #ifdef _LIBNFC_VERBOSE_ + #ifdef DEBUG printf("Rx: "); print_hex(abtRxBuf,ulRxBufLen); #endif @@ -244,7 +244,7 @@ char* dev_acr122_firmware(const dev_spec ds) uiResult = SCardTransmit(pdsa->hCard,&(pdsa->ioCard),abtGetFw,sizeof(abtGetFw),null,(byte*)abtFw,(void*)&ulFwLen); } - #ifdef _LIBNFC_VERBOSE_ + #ifdef DEBUG if (uiResult != SCARD_S_SUCCESS) { printf("No ACR122 firmware received, Error: %08x\n",uiResult); diff --git a/src/dev_pn531.c b/src/dev_pn531.c index 0a8a1b8..a6d3bd0 100644 --- a/src/dev_pn531.c +++ b/src/dev_pn531.c @@ -57,7 +57,7 @@ void get_end_points(struct usb_device *dev, dev_spec_pn531* pdsp) // Test if we dealing with a bulk IN endpoint if((uiEndPoint & USB_ENDPOINT_DIR_MASK) == USB_ENDPOINT_IN) { - #ifdef _LIBNFC_VERBOSE_ + #ifdef DEBUG printf("Bulk endpoint in : 0x%02X\n", uiEndPoint); #endif pdsp->uiEndPointIn = uiEndPoint; @@ -66,7 +66,7 @@ void get_end_points(struct usb_device *dev, dev_spec_pn531* pdsp) // Test if we dealing with a bulk OUT endpoint if((uiEndPoint & USB_ENDPOINT_DIR_MASK) == USB_ENDPOINT_OUT) { - #ifdef _LIBNFC_VERBOSE_ + #ifdef DEBUG printf("Bulk endpoint in : 0x%02X\n", uiEndPoint); #endif pdsp->uiEndPointOut = uiEndPoint; @@ -112,7 +112,7 @@ dev_info* dev_pn531_connect(const ui32 uiIndex) uiDevIndex--; continue; } - #ifdef _LIBNFC_VERBOSE_ + #ifdef DEBUG printf("Found PN531 device\n"); #endif @@ -122,7 +122,7 @@ dev_info* dev_pn531_connect(const ui32 uiIndex) get_end_points(dev,&dsp); if(usb_set_configuration(dsp.pudh,1) < 0) { - #ifdef _LIBNFC_VERBOSE_ + #ifdef DEBUG printf("Setting config failed\n"); #endif usb_close(dsp.pudh); @@ -131,7 +131,7 @@ dev_info* dev_pn531_connect(const ui32 uiIndex) if(usb_claim_interface(dsp.pudh,0) < 0) { - #ifdef _LIBNFC_VERBOSE_ + #ifdef DEBUG printf("Can't claim interface\n"); #endif usb_close(dsp.pudh); @@ -188,7 +188,7 @@ bool dev_pn531_transceive(const dev_spec ds, const byte* pbtTx, const ui32 uiTxL // End of stream marker buffer[uiTxLen+6] = 0; - #ifdef _LIBNFC_VERBOSE_ + #ifdef DEBUG printf("Tx: "); print_hex((byte*)buffer,uiTxLen+7); #endif @@ -196,7 +196,7 @@ bool dev_pn531_transceive(const dev_spec ds, const byte* pbtTx, const ui32 uiTxL ret = usb_bulk_write(pdsp->pudh, pdsp->uiEndPointOut, buffer, uiTxLen+7, USB_TIMEOUT); if( ret < 0 ) { - #ifdef _LIBNFC_VERBOSE_ + #ifdef DEBUG printf("usb_bulk_write failed with error %d\n", ret); #endif return false; @@ -205,13 +205,13 @@ bool dev_pn531_transceive(const dev_spec ds, const byte* pbtTx, const ui32 uiTxL ret = usb_bulk_read(pdsp->pudh, pdsp->uiEndPointIn, buf, BUFFER_LENGTH, USB_TIMEOUT); if( ret < 0 ) { - #ifdef _LIBNFC_VERBOSE_ + #ifdef DEBUG printf( "usb_bulk_read failed with error %d\n", ret); #endif return false; } - #ifdef _LIBNFC_VERBOSE_ + #ifdef DEBUG printf("Rx: "); print_hex((byte*)buf,ret); #endif @@ -221,13 +221,13 @@ bool dev_pn531_transceive(const dev_spec ds, const byte* pbtTx, const ui32 uiTxL ret = usb_bulk_read(pdsp->pudh, pdsp->uiEndPointIn, buf, BUFFER_LENGTH, USB_TIMEOUT); if( ret < 0 ) { - #ifdef _LIBNFC_VERBOSE_ + #ifdef DEBUG printf("usb_bulk_read failed with error %d\n", ret); #endif return false; } - #ifdef _LIBNFC_VERBOSE_ + #ifdef DEBUG printf("Rx: "); print_hex((byte*)buf,ret); #endif From d32d57f2375dd739b138f7674a6b4f4ee60313f4 Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Wed, 27 May 2009 08:59:09 +0000 Subject: [PATCH 02/29] Remove unused linux Makefile. Merge README and README.TXT. --- README | 24 ++++++++++++++++++++++++ README.TXT | 24 ------------------------ linux/Makefile | 41 ----------------------------------------- 3 files changed, 24 insertions(+), 65 deletions(-) delete mode 100644 README.TXT delete mode 100644 linux/Makefile diff --git a/README b/README index e69de29..01ce245 100644 --- a/README +++ b/README @@ -0,0 +1,24 @@ +------------------------------------------------------------------------ +Public platform independent Near Field Communication (NFC) library +Copyright (C) 2009, Roel Verdult + +------------------------------------------------------------------------ +Welcome to the developers community of libnfc. + +Since it is hard to keep all information up to date +we decided to only maintain the online documentation. +Please visit the official website for more info: +http://www.libnfc.org + +If you have questions, remarks, bug-reports, we encourage you to +post this in the developers community: +http://www.libnfc.org/community + +------------------------------------------------------------------------ +Proprietary Notes: + +FeliCa is s registered trademark of Sony Corporation. MIFARE is a +trademark of NXP Semiconductors. Jewel Topaz is a trademark of Innovision +Research & Technology. All other trademarks are the property of their +respective owners. + diff --git a/README.TXT b/README.TXT deleted file mode 100644 index 01ce245..0000000 --- a/README.TXT +++ /dev/null @@ -1,24 +0,0 @@ ------------------------------------------------------------------------- -Public platform independent Near Field Communication (NFC) library -Copyright (C) 2009, Roel Verdult - ------------------------------------------------------------------------- -Welcome to the developers community of libnfc. - -Since it is hard to keep all information up to date -we decided to only maintain the online documentation. -Please visit the official website for more info: -http://www.libnfc.org - -If you have questions, remarks, bug-reports, we encourage you to -post this in the developers community: -http://www.libnfc.org/community - ------------------------------------------------------------------------- -Proprietary Notes: - -FeliCa is s registered trademark of Sony Corporation. MIFARE is a -trademark of NXP Semiconductors. Jewel Topaz is a trademark of Innovision -Research & Technology. All other trademarks are the property of their -respective owners. - diff --git a/linux/Makefile b/linux/Makefile deleted file mode 100644 index ee677a9..0000000 --- a/linux/Makefile +++ /dev/null @@ -1,41 +0,0 @@ -############################################### -# Linux settings -############################################### -LIBPCSC_HEADERS=`pkg-config --cflags libpcsclite` -LIBPCSC_LIB=`pkg-config --libs libpcsclite` -LIBUSB_HEADERS=`pkg-config --cflags libusb` -LIBUSB_LIB=`pkg-config --libs libusb` -LIBNFC_TYPE=so -LIBNFC_CFLAGS=-shared -LIBNFC_LINK=-Wl,-rpath,. - -############################################### -# General settings -############################################### -LIBNFC_LDFLAGS=$(LIBPCSC_LIB) $(LIBUSB_LIB) -LIBNFC_PATH=.. -VPATH=$(LIBNFC_PATH) - -############################################### -# Compiler settings -############################################### -CC = gcc -LD = gcc -CFLAGS = -fPIC -Wall -O4 $(LIBPCSC_HEADERS) $(LIBUSB_HEADERS) -LDFLAGS = -fPIC -Wall -O4 - -OBJS = dev_pn531.o dev_acr122.o bitutils.o libnfc.o -HEADERS = devices.h bitutils.h defines.h libnfc.h -LIBNFC = libnfc.$(LIBNFC_TYPE) -EXES = anticol emulate list mftool relay - -all: $(LIBNFC) $(EXES) - -libnfc.$(LIBNFC_TYPE): $(OBJS) - $(LD) $(LDFLAGS) -o $(LIBNFC) $(LIBNFC_CFLAGS) $(LIBNFC_LDFLAGS) $(OBJS) - -% : %.c $(LIBNFC) - $(LD) $(LDFLAGS) -o $@ $< -L. -lnfc $(LIBNFC_LINK) - -clean: - rm -f $(OBJS) $(LIBNFC) $(EXES) From ab3664b05639a3ccdc1518329365ead0578a2bb6 Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Wed, 27 May 2009 10:13:19 +0000 Subject: [PATCH 03/29] Switch types to C99 standard using stdint.h Add stdint.h header check to ./configure Add -std=c99 to CFLAGS. --- configure.ac | 5 ++-- src/anticol.c | 12 ++++---- src/bitutils.c | 43 ++++++++++++++-------------- src/bitutils.h | 22 +++++++------- src/defines.h | 7 ----- src/dev_acr122.c | 14 ++++----- src/dev_acr122.h | 6 ++-- src/dev_pn531.c | 16 +++++------ src/dev_pn531.h | 6 ++-- src/emulate.c | 6 ++-- src/libnfc.c | 74 ++++++++++++++++++++++++------------------------ src/libnfc.h | 20 +++++++------ src/mftool.c | 15 +++++----- src/relay.c | 6 ++-- src/types.h | 16 ++++++----- 15 files changed, 140 insertions(+), 128 deletions(-) diff --git a/configure.ac b/configure.ac index da0d2df..47e3279 100644 --- a/configure.ac +++ b/configure.ac @@ -13,7 +13,7 @@ AC_PATH_PROG(PKG_CONFIG, pkg-config) # Checks for header files. AC_HEADER_STDC -AC_CHECK_HEADERS([stdlib.h]) +AC_CHECK_HEADERS([stdlib.h stdint.h]) # libusb @@ -40,10 +40,11 @@ AC_MSG_RESULT($enable_debug) if test "x$enable_debug" = "xyes" then - CFLAGS="$CFLAGS -g -Wall -DDEBUG" + CFLAGS="$CFLAGS -g -Wall -DDEBUG -pedantic" fi AC_SUBST([DEBUG_CFLAGS]) +CFLAGS="$CFLAGS -std=c99" AC_CONFIG_FILES([ Makefile diff --git a/src/anticol.c b/src/anticol.c index e4e4e34..f05908f 100644 --- a/src/anticol.c +++ b/src/anticol.c @@ -20,16 +20,18 @@ along with this program. If not, see . #include #include +#include #include + #include "libnfc.h" #define SAK_FLAG_ATS_SUPPORTED 0x20 static byte abtRx[MAX_FRAME_LEN]; -static ui32 uiRxBits; -static ui32 uiRxLen; +static uint32_t uiRxBits; +static uint32_t uiRxLen; static byte abtUid[10]; -static ui32 uiUidLen = 4; +static uint32_t uiUidLen = 4; static dev_info* pdi; // 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 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 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 printf("R: "); print_hex(pbtTx,uiTxLen); diff --git a/src/bitutils.c b/src/bitutils.c index 5fda4b1..6ce6e19 100644 --- a/src/bitutils.c +++ b/src/bitutils.c @@ -19,6 +19,7 @@ along with this program. If not, see . */ #include + #include "bitutils.h" const static byte OddParity[256] = { @@ -68,9 +69,9 @@ byte oddparity(const byte 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 for (uiByteNr=0; uiByteNr>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)); } -void append_iso14443a_crc(byte* pbtData, ui32 uiLen) +void append_iso14443a_crc(byte* pbtData, uint32_t uiLen) { byte bt; - ui32 wCrc = 0x6363; + uint32_t wCrc = 0x6363; do { bt = *pbtData++; bt = (bt^(byte)(wCrc & 0x00FF)); 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); *pbtData++ = (byte) (wCrc & 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++) { @@ -146,10 +147,10 @@ void print_hex(const byte* pbtData, const ui32 uiBytes) 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; - ui32 uiBytes = uiBits/8; + uint32_t uiPos; + uint32_t uiBytes = uiBits/8; for (uiPos=0; uiPos < uiBytes; uiPos++) { @@ -162,10 +163,10 @@ void print_hex_bits(const byte* pbtData, const ui32 uiBits) 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; - ui32 uiBytes = uiBits/8; + uint32_t uiPos; + uint32_t uiBytes = uiBits/8; for (uiPos=0; uiPos < uiBytes; uiPos++) { diff --git a/src/bitutils.h b/src/bitutils.h index 312c968..8cd6d97 100644 --- a/src/bitutils.h +++ b/src/bitutils.h @@ -21,24 +21,26 @@ along with this program. If not, see . #ifndef _LIBNFC_BITUTILS_H_ #define _LIBNFC_BITUTILS_H_ +#include + #include "defines.h" 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); -ui32 mirror32(ui32 ui32Bits); -ui64 mirror64(ui64 ui64Bits); -void mirror_bytes(byte *pbts, ui32 uiLen); +uint32_t mirror32(uint32_t ui32Bits); +uint64_t mirror64(uint64_t ui64Bits); +void mirror_bytes(byte *pbts, uint32_t uiLen); -ui32 swap_endian32(const void* pui32); -ui64 swap_endian64(const void* pui64); +uint32_t swap_endian32(const void* pui32); +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_bits(const byte* pbtData, const ui32 uiBits); -void print_hex_par(const byte* pbtData, const ui32 uiBits, const byte* pbtDataPar); +void print_hex(const byte* pbtData, const uint32_t uiLen); +void print_hex_bits(const byte* pbtData, const uint32_t uiBits); +void print_hex_par(const byte* pbtData, const uint32_t uiBits, const byte* pbtDataPar); #endif // _LIBNFC_BITUTILS_H_ diff --git a/src/defines.h b/src/defines.h index 2c63865..cddea0e 100644 --- a/src/defines.h +++ b/src/defines.h @@ -24,14 +24,7 @@ along with this program. If not, see . // #define DEBUG 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 char i8; -typedef short i16; -typedef int i32; #define null 0 diff --git a/src/dev_acr122.c b/src/dev_acr122.c index cb2495a..18e6181 100644 --- a/src/dev_acr122.c +++ b/src/dev_acr122.c @@ -57,15 +57,15 @@ static ulong ulRxBufLen; static byte abtGetFw[5] = { 0xFF,0x00,0x48,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 acList[256+64*MAX_READERS]; ulong ulListLen = sizeof(acList); - ui32 uiPos; - ui32 uiReaderCount; - ui32 uiReader; - ui32 uiDevIndex; + uint32_t uiPos; + uint32_t uiReaderCount; + uint32_t uiReader; + uint32_t uiDevIndex; dev_info* pdi; dev_spec_acr122* pdsa; dev_spec_acr122 dsa; @@ -172,7 +172,7 @@ void dev_acr122_disconnect(dev_info* 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; @@ -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) { - ui32 uiResult; + uint32_t uiResult; dev_spec_acr122* pdsa = (dev_spec_acr122*)ds; static char abtFw[11]; diff --git a/src/dev_acr122.h b/src/dev_acr122.h index 95c763d..02e1b50 100644 --- a/src/dev_acr122.h +++ b/src/dev_acr122.h @@ -21,15 +21,17 @@ along with this program. If not, see . #ifndef _LIBNFC_DEV_ACR122_H_ #define _LIBNFC_DEV_ACR122_H_ +#include + #include "defines.h" #include "types.h" // 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); // 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 char* dev_acr122_firmware(const dev_spec ds); diff --git a/src/dev_pn531.c b/src/dev_pn531.c index a6d3bd0..67791e9 100644 --- a/src/dev_pn531.c +++ b/src/dev_pn531.c @@ -34,15 +34,15 @@ static char buffer[BUFFER_LENGTH] = { 0x00, 0x00, 0xff }; // Every packet must s typedef struct { usb_dev_handle* pudh; - ui32 uiEndPointIn; - ui32 uiEndPointOut; + uint32_t uiEndPointIn; + uint32_t uiEndPointOut; } dev_spec_pn531; // Find transfer endpoints for bulk transfers void get_end_points(struct usb_device *dev, dev_spec_pn531* pdsp) { - ui32 uiIndex; - ui32 uiEndPoint; + uint32_t uiIndex; + uint32_t uiEndPoint; struct usb_interface_descriptor* puid = dev->config->interface->altsetting; // 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 idproduct = 0x0531; @@ -83,7 +83,7 @@ dev_info* dev_pn531_connect(const ui32 uiIndex) dev_info* pdi = INVALID_DEVICE_INFO; dev_spec_pn531* pdsp; dev_spec_pn531 dsp; - ui32 uiDevIndex; + uint32_t uiDevIndex; dsp.uiEndPointIn = 0; dsp.uiEndPointOut = 0; @@ -164,9 +164,9 @@ void dev_pn531_disconnect(dev_info* 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; char buf[BUFFER_LENGTH]; dev_spec_pn531* pdsp = (dev_spec_pn531*)ds; diff --git a/src/dev_pn531.h b/src/dev_pn531.h index 65419c4..33ab49e 100644 --- a/src/dev_pn531.h +++ b/src/dev_pn531.h @@ -21,15 +21,17 @@ along with this program. If not, see . #ifndef _LIBNFC_DEV_PN531_H_ #define _LIBNFC_DEV_PN531_H_ +#include + #include "defines.h" #include "types.h" // 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); // 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_ diff --git a/src/emulate.c b/src/emulate.c index 5153ba9..134912a 100644 --- a/src/emulate.c +++ b/src/emulate.c @@ -20,11 +20,13 @@ along with this program. If not, see . #include #include +#include #include + #include "libnfc.h" static byte abtRecv[MAX_FRAME_LEN]; -static ui32 uiRecvBits; +static uint32_t uiRecvBits; static dev_info* pdi; // ISO14443A Anti-Collision response @@ -35,7 +37,7 @@ byte abtSak [9] = { 0x08,0xb6,0xdd }; int main(int argc, const char* argv[]) { byte* pbtTx = null; - ui32 uiTxBits; + uint32_t uiTxBits; // Try to open the NFC reader pdi = nfc_connect(); diff --git a/src/libnfc.c b/src/libnfc.c index 8d87140..f83dcd6 100644 --- a/src/libnfc.c +++ b/src/libnfc.c @@ -88,9 +88,9 @@ byte pncmd_exchange_raw_data [266] = { 0xD4,0x42 }; // Global buffers used for communication with the PN53X chip #define MAX_FRAME_LEN 264 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 uiRxLen = MAX_FRAME_LEN; @@ -105,17 +105,17 @@ bool pn53x_transceive(const dev_info* pdi, const byte* pbtTx, const ui32 uiTxLen 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; - ui32 uiValueLen = 1; + uint8_t ui8Value; + uint32_t uiValueLen = 1; pncmd_get_register[2] = ui16Reg >> 8; pncmd_get_register[3] = ui16Reg & 0xff; pdi->pdc->transceive(pdi->ds,pncmd_get_register,4,&ui8Value,&uiValueLen); 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[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); } -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; 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 if (pdi->ui8TxBits != ui8Bits) @@ -143,13 +143,13 @@ bool pn53x_set_tx_bits(const dev_info* pdi, ui8 ui8Bits) 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 btData; - ui32 uiBitPos; - ui32 uiDataPos = 0; - ui32 uiBitsLeft = uiTxBits; + uint32_t uiBitPos; + uint32_t uiDataPos = 0; + uint32_t uiBitsLeft = uiTxBits; // Make sure we should frame at least something 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 btData; - ui8 uiBitPos; - ui32 uiDataPos = 0; + uint8_t uiBitPos; + uint32_t uiDataPos = 0; byte* pbtFramePos = (byte*) pbtFrame; - ui32 uiBitsLeft = uiFrameBits; + uint32_t uiBitsLeft = uiFrameBits; // Make sure we should frame at least something 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* pdi; - ui32 uiDev; + uint32_t uiDev; byte abtFw[4]; - ui32 uiFwLen = sizeof(abtFw); + uint32_t uiFwLen = sizeof(abtFw); // Search through the device list for an available device for (uiDev=0; uiDevbActive) 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)); } -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; - ui32 uiFrameBytes = 0; - ui8 ui8Bits = 0; + uint32_t uiFrameBits = 0; + uint32_t uiFrameBytes = 0; + uint8_t ui8Bits = 0; // Check if we should prepare the parity bits ourself if (!pdi->bPar) @@ -534,7 +534,7 @@ bool nfc_reader_transceive_bits(const dev_info* pdi, const byte* pbtTx, const ui 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 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; } -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 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; } -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 bool bCrc = pdi->bCrc; @@ -665,10 +665,10 @@ bool nfc_target_init(const dev_info* pdi, byte* pbtRx, ui32* puiRxBits) 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; - ui8 ui8Bits; + uint32_t uiFrameBits; + uint8_t ui8Bits; // Try to gather a received frame from the reader 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; } -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 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; } -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; - ui32 uiFrameBytes = 0; - ui8 ui8Bits = 0; + uint32_t uiFrameBits = 0; + uint32_t uiFrameBytes = 0; + uint8_t ui8Bits = 0; // Check if we should prepare the parity bits ourself 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 if (!pdi->bPar) return false; diff --git a/src/libnfc.h b/src/libnfc.h index f122137..04a50e9 100644 --- a/src/libnfc.h +++ b/src/libnfc.h @@ -21,6 +21,8 @@ along with this program. If not, see . #ifndef _LIBNFC_H_ #define _LIBNFC_H_ +#include + #include "defines.h" #include "types.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_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_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_bytes(const dev_info* pdi, const byte* pbtTx, const ui32 uiTxLen, byte* pbtRx, ui32* puiRxLen); -bool nfc_reader_mifare_cmd(const dev_info* pdi, const mifare_cmd mc, const ui8 ui8Block, mifare_param* pmp); +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 uint32_t uiTxLen, byte* pbtRx, uint32_t* puiRxLen); +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_receive_bits(const dev_info* pdi, byte* pbtRx, ui32* puiRxBits, byte* pbtRxPar); -bool nfc_target_receive_bytes(const dev_info* pdi, byte* pbtRx, ui32* puiRxLen); -bool nfc_target_send_bits(const dev_info* pdi, const byte* pbtTx, const ui32 uiTxBits, const byte* pbtTxPar); -bool nfc_target_send_bytes(const dev_info* pdi, const byte* pbtTx, const ui32 uiTxLen); +bool nfc_target_init(const dev_info* pdi, byte* pbtRx, uint32_t* puiRxBits); +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, uint32_t* puiRxLen); +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 uint32_t uiTxLen); #endif // _LIBNFC_H_ diff --git a/src/mftool.c b/src/mftool.c index fb390d2..39c2229 100644 --- a/src/mftool.c +++ b/src/mftool.c @@ -20,6 +20,7 @@ along with this program. If not, see . #include #include +#include #include #include @@ -32,21 +33,21 @@ static mifare_param mp; static mifare_tag mtKeys; static mifare_tag mtDump; 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 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 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 if (uiFirstBlock<128) return uiFirstBlock+3; else return uiFirstBlock+15; @@ -54,7 +55,7 @@ ui32 get_trailer_block(ui32 uiFirstBlock) bool read_card() { - i32 iBlock; + int32_t iBlock; mifare_cmd mc; bool bFailure = false; @@ -136,8 +137,8 @@ bool read_card() bool write_card() { - ui32 uiBlock; - ui32 uiTrailerBlock; + uint32_t uiBlock; + uint32_t uiTrailerBlock; bool bFailure = false; mifare_cmd mc; diff --git a/src/relay.c b/src/relay.c index 65c1566..a942cc7 100644 --- a/src/relay.c +++ b/src/relay.c @@ -20,15 +20,17 @@ along with this program. If not, see . #include #include +#include #include + #include "libnfc.h" static byte abtReaderRx[MAX_FRAME_LEN]; static byte abtReaderRxPar[MAX_FRAME_LEN]; -static ui32 uiReaderRxBits; +static uint32_t uiReaderRxBits; static byte abtTagRx[MAX_FRAME_LEN]; static byte abtTagRxPar[MAX_FRAME_LEN]; -static ui32 uiTagRxBits; +static uint32_t uiTagRxBits; static dev_info* pdiReader; static dev_info* pdiTag; diff --git a/src/types.h b/src/types.h index ab3c02d..e0b1b28 100644 --- a/src/types.h +++ b/src/types.h @@ -21,6 +21,8 @@ along with this program. If not, see . #ifndef _LIBNFC_TYPES_H_ #define _LIBNFC_TYPES_H_ +#include + #include "defines.h" // 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 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 - 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; struct dev_callbacks { const char* acDriver; // Driver description - dev_info* (*connect)(const ui32 uiIndex); - bool (*transceive)(const dev_spec ds, const byte* pbtTx, const ui32 uiTxLen, byte* pbtRx, ui32* puiRxLen); + dev_info* (*connect)(const uint32_t uiIndex); + bool (*transceive)(const dev_spec ds, const byte* pbtTx, const uint32_t uiTxLen, byte* pbtRx, uint32_t* puiRxLen); void (*disconnect)(dev_info* pdi); }; @@ -81,14 +83,14 @@ typedef enum { typedef struct { byte abtAtqa[2]; byte btSak; - ui32 uiUidLen; + uint32_t uiUidLen; byte abtUid[10]; - ui32 uiAtsLen; + uint32_t uiAtsLen; byte abtAts[36]; }tag_info_iso14443a; typedef struct { - ui32 uiLen; + uint32_t uiLen; byte btResCode; byte abtId[8]; byte abtPad[8]; @@ -103,7 +105,7 @@ typedef struct { byte btParam3; byte btParam4; byte btCid; - ui32 uiInfLen; + uint32_t uiInfLen; byte abtInf[64]; }tag_info_iso14443b; From f34857487dc20ae7532d789f447256f6a89d7b46 Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Wed, 27 May 2009 12:18:21 +0000 Subject: [PATCH 04/29] Replace locally defined "null" to standard library defined "NULL" (stddef.h). Replace "ulong" usage by "size_t" from standard library (since ulong type was only used to store sizeof() result). --- configure.ac | 2 +- src/anticol.c | 3 +- src/defines.h | 7 +- src/dev_acr122.c | 36 ++++----- src/dev_pn531.c | 10 ++- src/emulate.c | 7 +- src/libnfc.c | 19 +++-- src/list.c | 191 ++++++++++++++++++++++++----------------------- src/mftool.c | 14 ++-- 9 files changed, 150 insertions(+), 139 deletions(-) diff --git a/configure.ac b/configure.ac index 47e3279..0e45289 100644 --- a/configure.ac +++ b/configure.ac @@ -13,7 +13,7 @@ AC_PATH_PROG(PKG_CONFIG, pkg-config) # Checks for header files. AC_HEADER_STDC -AC_CHECK_HEADERS([stdlib.h stdint.h]) +AC_CHECK_HEADERS([stdio.h stdlib.h stdint.h stddef.h]) # libusb diff --git a/src/anticol.c b/src/anticol.c index f05908f..1969dc3 100644 --- a/src/anticol.c +++ b/src/anticol.c @@ -20,6 +20,7 @@ along with this program. If not, see . #include #include +#include #include #include @@ -47,7 +48,7 @@ bool transmit_bits(const byte* pbtTx, const uint32_t uiTxBits) printf("R: "); print_hex_bits(pbtTx,uiTxBits); // Transmit the bit frame command, we don't use the arbitrary parity feature - if (!nfc_reader_transceive_bits(pdi,pbtTx,uiTxBits,null,abtRx,&uiRxBits,null)) return false; + if (!nfc_reader_transceive_bits(pdi,pbtTx,uiTxBits,NULL,abtRx,&uiRxBits,NULL)) return false; // Show received answer printf("T: "); print_hex_bits(abtRx,uiRxBits); diff --git a/src/defines.h b/src/defines.h index cddea0e..122ac25 100644 --- a/src/defines.h +++ b/src/defines.h @@ -21,15 +21,12 @@ along with this program. If not, see . #ifndef _LIBNFC_DEFINES_H_ #define _LIBNFC_DEFINES_H_ -// #define DEBUG +// #define DEBUG /* DEBUG flag can also be enabled using ./configure --enable-debug */ typedef unsigned char byte; -typedef unsigned long ulong; - -#define null 0 typedef void* dev_spec; // Device connection specification -#define INVALID_DEVICE_INFO null +#define INVALID_DEVICE_INFO 0 #define MAX_FRAME_LEN 264 #define DEVICE_NAME_LENGTH 256 diff --git a/src/dev_acr122.c b/src/dev_acr122.c index 18e6181..80b8363 100644 --- a/src/dev_acr122.c +++ b/src/dev_acr122.c @@ -17,14 +17,16 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +#include "dev_acr122.h" -#include "defines.h" +#include +#include +#include +#include #include -#include -#include -#include -#include "dev_acr122.h" + +#include "defines.h" #include "bitutils.h" // WINDOWS: #define IOCTL_CCID_ESCAPE_SCARD_CTL_CODE SCARD_CTL_CODE(3500) @@ -53,7 +55,7 @@ static byte abtTxBuf[ACR122_WRAP_LEN+ACR122_COMMAND_LEN] = { 0xFF, 0x00, 0x00, 0 static byte abtRxCmd[5] = { 0xFF,0xC0,0x00,0x00 }; static byte uiRxCmdLen = sizeof(abtRxCmd); static byte abtRxBuf[ACR122_RESPONSE_LEN]; -static ulong ulRxBufLen; +static size_t ulRxBufLen; static byte abtGetFw[5] = { 0xFF,0x00,0x48,0x00,0x00 }; static byte abtLed[9] = { 0xFF,0x00,0x40,0x05,0x04,0x00,0x00,0x00,0x00 }; @@ -61,7 +63,7 @@ dev_info* dev_acr122_connect(const uint32_t uiIndex) { char* pacReaders[MAX_READERS]; char acList[256+64*MAX_READERS]; - ulong ulListLen = sizeof(acList); + size_t ulListLen = sizeof(acList); uint32_t uiPos; uint32_t uiReaderCount; uint32_t uiReader; @@ -75,10 +77,10 @@ dev_info* dev_acr122_connect(const uint32_t uiIndex) memset(acList,0x00,ulListLen); // Test if context succeeded - if (SCardEstablishContext(SCARD_SCOPE_USER,null,null,&(dsa.hCtx)) != SCARD_S_SUCCESS) return INVALID_DEVICE_INFO; + if (SCardEstablishContext(SCARD_SCOPE_USER,NULL,NULL,&(dsa.hCtx)) != SCARD_S_SUCCESS) return INVALID_DEVICE_INFO; // Retrieve the string array of all available pcsc readers - if (SCardListReaders(dsa.hCtx,null,acList,(void*)&ulListLen) != SCARD_S_SUCCESS) return INVALID_DEVICE_INFO; + if (SCardListReaders(dsa.hCtx,NULL,acList,(void*)&ulListLen) != SCARD_S_SUCCESS) return INVALID_DEVICE_INFO; #ifdef DEBUG printf("Found the following PCSC device(s)\n"); @@ -132,7 +134,7 @@ dev_info* dev_acr122_connect(const uint32_t uiIndex) // Retrieve the current firmware version pcFirmware = dev_acr122_firmware((dev_info*)&dsa); - if (strstr(pcFirmware,FIRMWARE_TEXT) != null) + if (strstr(pcFirmware,FIRMWARE_TEXT) != NULL) { // We found a occurence, test if it has the right index if (uiDevIndex != 0) @@ -194,7 +196,7 @@ bool dev_acr122_transceive(const dev_spec ds, const byte* pbtTx, const uint32_t { if (SCardControl(pdsa->hCard,IOCTL_CCID_ESCAPE_SCARD_CTL_CODE,abtTxBuf,uiTxLen+5,abtRxBuf,ulRxBufLen,(void*)&ulRxBufLen) != SCARD_S_SUCCESS) return false; } else { - if (SCardTransmit(pdsa->hCard,&(pdsa->ioCard),abtTxBuf,uiTxLen+5,null,abtRxBuf,(void*)&ulRxBufLen) != SCARD_S_SUCCESS) return false; + if (SCardTransmit(pdsa->hCard,&(pdsa->ioCard),abtTxBuf,uiTxLen+5,NULL,abtRxBuf,(void*)&ulRxBufLen) != SCARD_S_SUCCESS) return false; } if (pdsa->ioCard.dwProtocol == SCARD_PROTOCOL_T0) @@ -208,7 +210,7 @@ bool dev_acr122_transceive(const dev_spec ds, const byte* pbtTx, const uint32_t // Retrieve the response bytes abtRxCmd[4] = abtRxBuf[1]; ulRxBufLen = sizeof(abtRxBuf); - if (SCardTransmit(pdsa->hCard,&(pdsa->ioCard),abtRxCmd,uiRxCmdLen,null,abtRxBuf,(void*)&ulRxBufLen) != SCARD_S_SUCCESS) return false; + if (SCardTransmit(pdsa->hCard,&(pdsa->ioCard),abtRxCmd,uiRxCmdLen,NULL,abtRxBuf,(void*)&ulRxBufLen) != SCARD_S_SUCCESS) return false; } #ifdef DEBUG @@ -217,7 +219,7 @@ bool dev_acr122_transceive(const dev_spec ds, const byte* pbtTx, const uint32_t #endif // When the answer should be ignored, just return a succesful result - if (pbtRx == null || puiRxLen == null) return true; + if (pbtRx == NULL || puiRxLen == NULL) return true; // Make sure we have an emulated answer that fits the return buffer if (ulRxBufLen < 4 || (ulRxBufLen-4) > *puiRxLen) return false; @@ -235,13 +237,13 @@ char* dev_acr122_firmware(const dev_spec ds) dev_spec_acr122* pdsa = (dev_spec_acr122*)ds; static char abtFw[11]; - ulong ulFwLen = sizeof(abtFw); + size_t ulFwLen = sizeof(abtFw); memset(abtFw,0x00,ulFwLen); if (pdsa->ioCard.dwProtocol == SCARD_PROTOCOL_UNDEFINED) { uiResult = SCardControl(pdsa->hCard,IOCTL_CCID_ESCAPE_SCARD_CTL_CODE,abtGetFw,sizeof(abtGetFw),abtFw,ulFwLen,(void*)&ulFwLen); } else { - uiResult = SCardTransmit(pdsa->hCard,&(pdsa->ioCard),abtGetFw,sizeof(abtGetFw),null,(byte*)abtFw,(void*)&ulFwLen); + uiResult = SCardTransmit(pdsa->hCard,&(pdsa->ioCard),abtGetFw,sizeof(abtGetFw),NULL,(byte*)abtFw,(void*)&ulFwLen); } #ifdef DEBUG @@ -258,12 +260,12 @@ bool dev_acr122_led_red(const dev_spec ds, bool bOn) { dev_spec_acr122* pdsa = (dev_spec_acr122*)ds; byte abtBuf[2]; - ulong ulBufLen = sizeof(abtBuf); + size_t ulBufLen = sizeof(abtBuf); if (pdsa->ioCard.dwProtocol == SCARD_PROTOCOL_UNDEFINED) { return (SCardControl(pdsa->hCard,IOCTL_CCID_ESCAPE_SCARD_CTL_CODE,abtLed,sizeof(abtLed),abtBuf,ulBufLen,(void*)&ulBufLen) == SCARD_S_SUCCESS); } else { - return (SCardTransmit(pdsa->hCard,&(pdsa->ioCard),abtLed,sizeof(abtLed),null,(byte*)abtBuf,(void*)&ulBufLen) == SCARD_S_SUCCESS); + return (SCardTransmit(pdsa->hCard,&(pdsa->ioCard),abtLed,sizeof(abtLed),NULL,(byte*)abtBuf,(void*)&ulBufLen) == SCARD_S_SUCCESS); } } diff --git a/src/dev_pn531.c b/src/dev_pn531.c index 67791e9..ba84cfd 100644 --- a/src/dev_pn531.c +++ b/src/dev_pn531.c @@ -20,11 +20,13 @@ Thanks to d18c7db and Okko for example code */ -#include "defines.h" +#include +#include #include -#include #include + +#include "defines.h" #include "dev_pn531.h" #include "bitutils.h" @@ -87,7 +89,7 @@ dev_info* dev_pn531_connect(const uint32_t uiIndex) dsp.uiEndPointIn = 0; dsp.uiEndPointOut = 0; - dsp.pudh = null; + dsp.pudh = NULL; usb_init(); if (usb_find_busses() < 0) return INVALID_DEVICE_INFO; @@ -234,7 +236,7 @@ bool dev_pn531_transceive(const dev_spec ds, const byte* pbtTx, const uint32_t u } // When the answer should be ignored, just return a succesful result - if(pbtRx == null || puiRxLen == null) return true; + if(pbtRx == NULL || puiRxLen == NULL) return true; // Only succeed when the result is at least 00 00 FF xx Fx Dx xx .. .. .. xx 00 (x = variable) if(ret < 9) return false; diff --git a/src/emulate.c b/src/emulate.c index 134912a..029ca8f 100644 --- a/src/emulate.c +++ b/src/emulate.c @@ -20,6 +20,7 @@ along with this program. If not, see . #include #include +#include #include #include @@ -36,7 +37,7 @@ byte abtSak [9] = { 0x08,0xb6,0xdd }; int main(int argc, const char* argv[]) { - byte* pbtTx = null; + byte* pbtTx = NULL; uint32_t uiTxBits; // Try to open the NFC reader @@ -68,7 +69,7 @@ int main(int argc, const char* argv[]) while(true) { // Test if we received a frame - if (nfc_target_receive_bits(pdi,abtRecv,&uiRecvBits,null)) + if (nfc_target_receive_bits(pdi,abtRecv,&uiRecvBits,NULL)) { // Prepare the command to send back for the anti-collision request switch(uiRecvBits) @@ -102,7 +103,7 @@ int main(int argc, const char* argv[]) if(uiTxBits) { // Send and print the command to the screen - nfc_target_send_bits(pdi,pbtTx,uiTxBits,null); + nfc_target_send_bits(pdi,pbtTx,uiTxBits,NULL); printf("T: "); print_hex_bits(pbtTx,uiTxBits); } diff --git a/src/libnfc.c b/src/libnfc.c index f83dcd6..c737449 100644 --- a/src/libnfc.c +++ b/src/libnfc.c @@ -19,10 +19,13 @@ along with this program. If not, see . */ #include "libnfc.h" -#include "bitutils.h" + #include +#include #include +#include "bitutils.h" + // Registers and symbols masks used to covers parts within a register #define REG_CIU_TX_MODE 0x6302 #define SYMBOL_TX_CRC_ENABLE 0x80 @@ -120,13 +123,13 @@ bool pn53x_set_reg(const dev_info* pdi, uint16_t ui16Reg, uint8_t ui8SybmolMask, pncmd_set_register[2] = ui16Reg >> 8; pncmd_set_register[3] = ui16Reg & 0xff; pncmd_set_register[4] = ui8Value | (pn53x_get_reg(pdi,ui16Reg) & (~ui8SybmolMask)); - 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, uint8_t 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, uint8_t ui8Bits) @@ -233,7 +236,7 @@ bool pn53x_unwrap_frame(const byte* pbtFrame, const uint32_t uiFrameBits, byte* btFrame = mirror(pbtFramePos[uiDataPos+1]); btData |= (btFrame >> (8-uiBitPos)); pbtRx[uiDataPos] = mirror(btData); - if(pbtRxPar != null) pbtRxPar[uiDataPos] = ((btFrame >> (7-uiBitPos)) & 0x01); + if(pbtRxPar != NULL) pbtRxPar[uiDataPos] = ((btFrame >> (7-uiBitPos)) & 0x01); // Increase the data (without parity bit) position uiDataPos++; // Test if we are done @@ -263,7 +266,7 @@ dev_info* nfc_connect() { // Great we have claimed a device pdi->pdc = &(dev_callbacks_list[uiDev]); - pdi->pdc->transceive(pdi->ds,pncmd_get_register,4,null,null); + pdi->pdc->transceive(pdi->ds,pncmd_get_register,4,NULL,NULL); // Try to retrieve PN53x chip revision if (!pdi->pdc->transceive(pdi->ds,pncmd_get_firmware_version,2,abtFw,&uiFwLen)) @@ -332,7 +335,7 @@ bool nfc_configure(dev_info* pdi, const dev_config_option dco, const bool bEnabl case DCO_ACTIVATE_FIELD: pncmd_rf_configure_field[3] = (bEnable) ? 1 : 0; - if (!pdi->pdc->transceive(pdi->ds,pncmd_rf_configure_field,4,null,null)) return false; + if (!pdi->pdc->transceive(pdi->ds,pncmd_rf_configure_field,4,NULL,NULL)) return false; break; case DCO_ACTIVATE_CRYPTO1: @@ -345,7 +348,7 @@ bool nfc_configure(dev_info* pdi, const dev_config_option dco, const bool bEnabl pncmd_rf_configure_retry_select[3] = (bEnable) ? 0xff : 0x00; // MxRtyATR, default: active = 0xff, passive = 0x02 pncmd_rf_configure_retry_select[4] = (bEnable) ? 0xff : 0x00; // MxRtyPSL, default: 0x01 pncmd_rf_configure_retry_select[5] = (bEnable) ? 0xff : 0x00; // MxRtyPassiveActivation, default: 0xff - if(!pdi->pdc->transceive(pdi->ds,pncmd_rf_configure_retry_select,6,null,null)) return false; + if(!pdi->pdc->transceive(pdi->ds,pncmd_rf_configure_retry_select,6,NULL,NULL)) return false; break; case DCO_ACCEPT_INVALID_FRAMES: @@ -477,7 +480,7 @@ bool nfc_reader_select(const dev_info* pdi, const init_modulation im, const byte 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 uint32_t uiTxBits, const byte* pbtTxPar, byte* pbtRx, uint32_t* puiRxBits, byte* pbtRxPar) diff --git a/src/list.c b/src/list.c index be02e9b..742cdc7 100644 --- a/src/list.c +++ b/src/list.c @@ -1,96 +1,99 @@ -/* - -Public platform independent Near Field Communication (NFC) library -Copyright (C) 2009, Roel Verdult - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . - -*/ - -#include -#include -#include -#include "libnfc.h" - -static dev_info* pdi; -static byte abtFelica[5] = { 0x00, 0xff, 0xff, 0x00, 0x00 }; - -int main(int argc, const char* argv[]) -{ - tag_info ti; - - // Try to open the NFC reader - pdi = nfc_connect(); - - if (pdi == INVALID_DEVICE_INFO) - { - printf("Error connecting NFC reader\n"); - return 1; - } - nfc_reader_init(pdi); - +/* + +Public platform independent Near Field Communication (NFC) library +Copyright (C) 2009, Roel Verdult + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . + +*/ + +#include +#include +#include + +#include + +#include "libnfc.h" + +static dev_info* pdi; +static byte abtFelica[5] = { 0x00, 0xff, 0xff, 0x00, 0x00 }; + +int main(int argc, const char* argv[]) +{ + tag_info ti; + + // Try to open the NFC reader + pdi = nfc_connect(); + + if (pdi == INVALID_DEVICE_INFO) + { + printf("Error connecting NFC reader\n"); + return 1; + } + nfc_reader_init(pdi); + // Drop the field for a while nfc_configure(pdi,DCO_ACTIVATE_FIELD,false); - - // Let the reader only try once to find a tag - nfc_configure(pdi,DCO_INFINITE_SELECT,false); - - // Configure the CRC and Parity settings - nfc_configure(pdi,DCO_HANDLE_CRC,true); - nfc_configure(pdi,DCO_HANDLE_PARITY,true); - - // Enable field so more power consuming cards can power themselves up - nfc_configure(pdi,DCO_ACTIVATE_FIELD,true); - - printf("\nConnected to NFC reader: %s\n\n",pdi->acName); - - // Poll for a ISO14443A (MIFARE) tag - if (nfc_reader_select(pdi,IM_ISO14443A_106,null,null,&ti)) - { - printf("The following (NFC) ISO14443A tag was found:\n\n"); - printf(" ATQA (SENS_RES): "); print_hex(ti.tia.abtAtqa,2); - printf(" UID (NFCID%c): ",(ti.tia.abtUid[0]==0x08?'3':'1')); print_hex(ti.tia.abtUid,ti.tia.uiUidLen); - printf(" SAK (SEL_RES): "); print_hex(&ti.tia.btSak,1); - if (ti.tia.uiAtsLen) - { - printf(" ATS (ATR): "); - print_hex(ti.tia.abtAts,ti.tia.uiAtsLen); - } - } - - // Poll for a Felica tag - if (nfc_reader_select(pdi,IM_FELICA_212,abtFelica,5,&ti) || nfc_reader_select(pdi,IM_FELICA_424,abtFelica,5,&ti)) - { - printf("The following (NFC) Felica tag was found:\n\n"); - printf("%18s","ID (NFCID2): "); print_hex(ti.tif.abtId,8); - printf("%18s","Parameter (PAD): "); print_hex(ti.tif.abtPad,8); - } - - // Poll for a ISO14443B tag - if (nfc_reader_select(pdi,IM_ISO14443B_106,null,null,&ti)) - { - // No test results yet - printf("iso14443b\n"); - } - - // Poll for a Jewel tag - if (nfc_reader_select(pdi,IM_JEWEL_106,null,null,&ti)) - { - // No test results yet - printf("jewel\n"); - } - - nfc_disconnect(pdi); - return 1; -} + + // Let the reader only try once to find a tag + nfc_configure(pdi,DCO_INFINITE_SELECT,false); + + // Configure the CRC and Parity settings + nfc_configure(pdi,DCO_HANDLE_CRC,true); + nfc_configure(pdi,DCO_HANDLE_PARITY,true); + + // Enable field so more power consuming cards can power themselves up + nfc_configure(pdi,DCO_ACTIVATE_FIELD,true); + + printf("\nConnected to NFC reader: %s\n\n",pdi->acName); + + // Poll for a ISO14443A (MIFARE) tag + if (nfc_reader_select(pdi,IM_ISO14443A_106,NULL,NULL,&ti)) + { + printf("The following (NFC) ISO14443A tag was found:\n\n"); + printf(" ATQA (SENS_RES): "); print_hex(ti.tia.abtAtqa,2); + printf(" UID (NFCID%c): ",(ti.tia.abtUid[0]==0x08?'3':'1')); print_hex(ti.tia.abtUid,ti.tia.uiUidLen); + printf(" SAK (SEL_RES): "); print_hex(&ti.tia.btSak,1); + if (ti.tia.uiAtsLen) + { + printf(" ATS (ATR): "); + print_hex(ti.tia.abtAts,ti.tia.uiAtsLen); + } + } + + // Poll for a Felica tag + if (nfc_reader_select(pdi,IM_FELICA_212,abtFelica,5,&ti) || nfc_reader_select(pdi,IM_FELICA_424,abtFelica,5,&ti)) + { + printf("The following (NFC) Felica tag was found:\n\n"); + printf("%18s","ID (NFCID2): "); print_hex(ti.tif.abtId,8); + printf("%18s","Parameter (PAD): "); print_hex(ti.tif.abtPad,8); + } + + // Poll for a ISO14443B tag + if (nfc_reader_select(pdi,IM_ISO14443B_106,NULL,NULL,&ti)) + { + // No test results yet + printf("iso14443b\n"); + } + + // Poll for a Jewel tag + if (nfc_reader_select(pdi,IM_JEWEL_106,NULL,NULL,&ti)) + { + // No test results yet + printf("jewel\n"); + } + + nfc_disconnect(pdi); + return 1; +} diff --git a/src/mftool.c b/src/mftool.c index 39c2229..c52874d 100644 --- a/src/mftool.c +++ b/src/mftool.c @@ -21,6 +21,8 @@ along with this program. If not, see . #include #include #include +#include + #include #include @@ -72,7 +74,7 @@ bool read_card() { printf("x"); // When a failure occured we need to redo the anti-collision - if (!nfc_reader_select(pdi,IM_ISO14443A_106,null,null,&ti)) + if (!nfc_reader_select(pdi,IM_ISO14443A_106,NULL,NULL,&ti)) { printf("!\nError: tag was removed\n"); return 1; @@ -155,7 +157,7 @@ bool write_card() { printf("x"); // When a failure occured we need to redo the anti-collision - if (!nfc_reader_select(pdi,IM_ISO14443A_106,null,null,&ti)) + if (!nfc_reader_select(pdi,IM_ISO14443A_106,NULL,NULL,&ti)) { printf("!\nError: tag was removed\n"); return false; @@ -251,7 +253,7 @@ int main(int argc, const char* argv[]) bUseKeyA = (tolower(*(argv[2])) == 'a'); pfKeys = fopen(argv[3],"rb"); - if (pfKeys == null) + if (pfKeys == NULL) { printf("Could not open file: %s\n",argv[3]); return 1; @@ -270,7 +272,7 @@ int main(int argc, const char* argv[]) } else { pfDump = fopen(argv[4],"rb"); - if (pfDump == null) + if (pfDump == NULL) { printf("Could not open dump file: %s\n",argv[4]); return 1; @@ -310,7 +312,7 @@ int main(int argc, const char* argv[]) printf("Connected to NFC reader: %s\n",pdi->acName); // Try to find a MIFARE Classic tag - if (!nfc_reader_select(pdi,IM_ISO14443A_106,null,null,&ti)) + if (!nfc_reader_select(pdi,IM_ISO14443A_106,NULL,NULL,&ti)) { printf("Error: no tag was found\n"); nfc_disconnect(pdi); @@ -349,7 +351,7 @@ int main(int argc, const char* argv[]) printf("Writing data to file: %s\n",argv[4]); fflush(stdout); pfDump = fopen(argv[4],"wb"); - if (pfKeys == null) + if (pfKeys == NULL) { printf("Could not open file: %s\n",argv[4]); return 1; From 1dcb53dc4dd578fcaa2b5e76aabda8027933ccbe Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Wed, 27 May 2009 14:05:07 +0000 Subject: [PATCH 05/29] Use C99 standard bool type instead of locally defined one. Check for types in configure pass. Fix a warning related to nfc_reader_select() (a length - uiInitDataLen - was set by NULL instead of 0). --- configure.ac | 46 ++++++++++++++++++++++++++++------------------ src/anticol.c | 2 ++ src/dev_acr122.h | 1 + src/dev_pn531.h | 1 + src/libnfc.h | 1 + src/list.c | 6 +++--- src/mftool.c | 7 ++++--- src/types.h | 6 +----- 8 files changed, 41 insertions(+), 29 deletions(-) diff --git a/configure.ac b/configure.ac index 0e45289..f941c14 100644 --- a/configure.ac +++ b/configure.ac @@ -13,29 +13,21 @@ AC_PATH_PROG(PKG_CONFIG, pkg-config) # Checks for header files. AC_HEADER_STDC -AC_CHECK_HEADERS([stdio.h stdlib.h stdint.h stddef.h]) +AC_HEADER_STDBOOL +AC_CHECK_HEADERS([stdio.h stdlib.h stdint.h stddef.h stdbool.h]) - -# libusb -PKG_CHECK_MODULES(LIBUSB, libusb, [WITH_USB=1], [WITH_USB=0]) -if test "$WITH_USB" == "0" ; then - AC_MSG_ERROR([libusb is mandatory.]) -fi -AC_SUBST(LIBUSB_LIBS) -AC_SUBST(LIBUSB_CFLAGS) - -# libpcsclite -PKG_CHECK_MODULES(LIBPCSCLITE, libpcsclite, [WITH_PCSC=1], [WITH_PCSC=0]) -if test "$WITH_PCSC" == "0" ; then - AC_MSG_ERROR([libpcsclite is mandatory.]) -fi -AC_SUBST(LIBPCSCLITE_LIBS) -AC_SUBST(LIBPCSCLITE_CFLAGS) +# Checks for types +AC_TYPE_SIZE_T +AC_TYPE_UINT8_T +AC_TYPE_UINT16_T +AC_TYPE_UINT32_T +AC_TYPE_UINT64_T +AC_TYPE_INT32_T # --enable-debug support AC_ARG_ENABLE([debug],AS_HELP_STRING([--enable-debug],[Debug flags]),[enable_debug=$enableval],[enable_debug="no"]) -AC_MSG_CHECKING(debug) +AC_MSG_CHECKING(for debug flag) AC_MSG_RESULT($enable_debug) if test "x$enable_debug" = "xyes" @@ -44,6 +36,24 @@ then fi AC_SUBST([DEBUG_CFLAGS]) +# pkg-config check for +## libusb +PKG_CHECK_MODULES(LIBUSB, libusb, [WITH_USB=1], [WITH_USB=0]) +if test "$WITH_USB" == "0" ; then + AC_MSG_ERROR([libusb is mandatory.]) +fi +AC_SUBST(LIBUSB_LIBS) +AC_SUBST(LIBUSB_CFLAGS) + +## libpcsclite +PKG_CHECK_MODULES(LIBPCSCLITE, libpcsclite, [WITH_PCSC=1], [WITH_PCSC=0]) +if test "$WITH_PCSC" == "0" ; then + AC_MSG_ERROR([libpcsclite is mandatory.]) +fi +AC_SUBST(LIBPCSCLITE_LIBS) +AC_SUBST(LIBPCSCLITE_CFLAGS) + +# Set C standard to C99 CFLAGS="$CFLAGS -std=c99" AC_CONFIG_FILES([ diff --git a/src/anticol.c b/src/anticol.c index 1969dc3..24e1d98 100644 --- a/src/anticol.c +++ b/src/anticol.c @@ -22,6 +22,8 @@ along with this program. If not, see . #include #include #include +#include + #include #include "libnfc.h" diff --git a/src/dev_acr122.h b/src/dev_acr122.h index 02e1b50..4771b3e 100644 --- a/src/dev_acr122.h +++ b/src/dev_acr122.h @@ -22,6 +22,7 @@ along with this program. If not, see . #define _LIBNFC_DEV_ACR122_H_ #include +#include #include "defines.h" #include "types.h" diff --git a/src/dev_pn531.h b/src/dev_pn531.h index 33ab49e..14dcf4f 100644 --- a/src/dev_pn531.h +++ b/src/dev_pn531.h @@ -22,6 +22,7 @@ along with this program. If not, see . #define _LIBNFC_DEV_PN531_H_ #include +#include #include "defines.h" #include "types.h" diff --git a/src/libnfc.h b/src/libnfc.h index 04a50e9..b191908 100644 --- a/src/libnfc.h +++ b/src/libnfc.h @@ -22,6 +22,7 @@ along with this program. If not, see . #define _LIBNFC_H_ #include +#include #include "defines.h" #include "types.h" diff --git a/src/list.c b/src/list.c index 742cdc7..4fdd151 100644 --- a/src/list.c +++ b/src/list.c @@ -59,7 +59,7 @@ int main(int argc, const char* argv[]) printf("\nConnected to NFC reader: %s\n\n",pdi->acName); // Poll for a ISO14443A (MIFARE) tag - if (nfc_reader_select(pdi,IM_ISO14443A_106,NULL,NULL,&ti)) + if (nfc_reader_select(pdi,IM_ISO14443A_106,NULL,0,&ti)) { printf("The following (NFC) ISO14443A tag was found:\n\n"); printf(" ATQA (SENS_RES): "); print_hex(ti.tia.abtAtqa,2); @@ -81,14 +81,14 @@ int main(int argc, const char* argv[]) } // Poll for a ISO14443B tag - if (nfc_reader_select(pdi,IM_ISO14443B_106,NULL,NULL,&ti)) + if (nfc_reader_select(pdi,IM_ISO14443B_106,NULL,0,&ti)) { // No test results yet printf("iso14443b\n"); } // Poll for a Jewel tag - if (nfc_reader_select(pdi,IM_JEWEL_106,NULL,NULL,&ti)) + if (nfc_reader_select(pdi,IM_JEWEL_106,NULL,0,&ti)) { // No test results yet printf("jewel\n"); diff --git a/src/mftool.c b/src/mftool.c index c52874d..ec8ff69 100644 --- a/src/mftool.c +++ b/src/mftool.c @@ -22,6 +22,7 @@ along with this program. If not, see . #include #include #include +#include #include #include @@ -74,7 +75,7 @@ bool read_card() { printf("x"); // When a failure occured we need to redo the anti-collision - if (!nfc_reader_select(pdi,IM_ISO14443A_106,NULL,NULL,&ti)) + if (!nfc_reader_select(pdi,IM_ISO14443A_106,NULL,0,&ti)) { printf("!\nError: tag was removed\n"); return 1; @@ -157,7 +158,7 @@ bool write_card() { printf("x"); // When a failure occured we need to redo the anti-collision - if (!nfc_reader_select(pdi,IM_ISO14443A_106,NULL,NULL,&ti)) + if (!nfc_reader_select(pdi,IM_ISO14443A_106,NULL,0,&ti)) { printf("!\nError: tag was removed\n"); return false; @@ -312,7 +313,7 @@ int main(int argc, const char* argv[]) printf("Connected to NFC reader: %s\n",pdi->acName); // Try to find a MIFARE Classic tag - if (!nfc_reader_select(pdi,IM_ISO14443A_106,NULL,NULL,&ti)) + if (!nfc_reader_select(pdi,IM_ISO14443A_106,NULL,0,&ti)) { printf("Error: no tag was found\n"); nfc_disconnect(pdi); diff --git a/src/types.h b/src/types.h index e0b1b28..0b69de5 100644 --- a/src/types.h +++ b/src/types.h @@ -22,17 +22,13 @@ along with this program. If not, see . #define _LIBNFC_TYPES_H_ #include +#include #include "defines.h" // Compiler directive, set struct alignment to 1 byte for compatibility #pragma pack(1) -typedef enum { - false = 0x00, - true = 0x01 -} bool; - typedef enum { CT_PN531 = 0x10, CT_PN532 = 0x20, From 7536d79d7392c4f2373599179510bef20ab8336b Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Wed, 3 Jun 2009 07:32:43 +0000 Subject: [PATCH 06/29] Fix function prototype. Check for usb.h in ./configure . --- configure.ac | 2 +- src/libnfc.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index f941c14..8f2a64f 100644 --- a/configure.ac +++ b/configure.ac @@ -14,7 +14,7 @@ AC_PATH_PROG(PKG_CONFIG, pkg-config) # Checks for header files. AC_HEADER_STDC AC_HEADER_STDBOOL -AC_CHECK_HEADERS([stdio.h stdlib.h stdint.h stddef.h stdbool.h]) +AC_CHECK_HEADERS([stdio.h stdlib.h stdint.h stddef.h stdbool.h usb.h]) # Checks for types AC_TYPE_SIZE_T diff --git a/src/libnfc.h b/src/libnfc.h index b191908..39e4393 100644 --- a/src/libnfc.h +++ b/src/libnfc.h @@ -29,7 +29,7 @@ along with this program. If not, see . #include "bitutils.h" #include "devices.h" -dev_info* nfc_connect(); +dev_info* nfc_connect(void); void nfc_disconnect(dev_info* pdi); bool nfc_configure(dev_info* pdi, const dev_config_option dco, const bool bEnable); From 7b82eb10a006fbd738f9e74aeb4b66f45c08b85d Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Thu, 11 Jun 2009 08:30:49 +0000 Subject: [PATCH 07/29] Add --disable-pcsc-lite option. Fix pkg-config file. --- configure.ac | 27 +++++++++++++++++++++------ libnfc.pc.in | 2 +- src/Makefile.am | 16 ++++++++++++---- 3 files changed, 34 insertions(+), 11 deletions(-) diff --git a/configure.ac b/configure.ac index 8f2a64f..0a60684 100644 --- a/configure.ac +++ b/configure.ac @@ -24,13 +24,25 @@ AC_TYPE_UINT32_T AC_TYPE_UINT64_T AC_TYPE_INT32_T +# --enable-pcsc-lite support (default: yes) +AC_ARG_ENABLE([pcsc-lite],AS_HELP_STRING([--enable-pcsc-lite],[pcsc-lite feature flag]),[enable_pcsc_lite=$enableval],[enable_pcsc_lite="yes"]) + +AC_MSG_CHECKING(for pcsc-lite support) +AC_MSG_RESULT($enable_pcsc_lite) + +if test x"$enable_pcsc_lite" = "xno" +then + WITH_PCSC=0 +fi +AM_CONDITIONAL(PCSC_LITE_ENABLED, [test x"$enable_pcsc_lite" = xyes]) + # --enable-debug support AC_ARG_ENABLE([debug],AS_HELP_STRING([--enable-debug],[Debug flags]),[enable_debug=$enableval],[enable_debug="no"]) AC_MSG_CHECKING(for debug flag) AC_MSG_RESULT($enable_debug) -if test "x$enable_debug" = "xyes" +if test x"$enable_debug" = "xyes" then CFLAGS="$CFLAGS -g -Wall -DDEBUG -pedantic" fi @@ -46,12 +58,15 @@ AC_SUBST(LIBUSB_LIBS) AC_SUBST(LIBUSB_CFLAGS) ## libpcsclite -PKG_CHECK_MODULES(LIBPCSCLITE, libpcsclite, [WITH_PCSC=1], [WITH_PCSC=0]) -if test "$WITH_PCSC" == "0" ; then - AC_MSG_ERROR([libpcsclite is mandatory.]) +if test "x$enable_pcsc_lite" = "xyes" +then + PKG_CHECK_MODULES(LIBPCSCLITE, libpcsclite, [WITH_PCSC=1], [WITH_PCSC=0]) + if test "$WITH_PCSC" == "0" ; then + AC_MSG_ERROR([libpcsclite is mandatory.]) + fi + AC_SUBST(LIBPCSCLITE_LIBS) + AC_SUBST(LIBPCSCLITE_CFLAGS) fi -AC_SUBST(LIBPCSCLITE_LIBS) -AC_SUBST(LIBPCSCLITE_CFLAGS) # Set C standard to C99 CFLAGS="$CFLAGS -std=c99" diff --git a/libnfc.pc.in b/libnfc.pc.in index 1edf5b4..a09e1d5 100644 --- a/libnfc.pc.in +++ b/libnfc.pc.in @@ -6,5 +6,5 @@ Name: libnfc Description: Near Field Communication (NFC) library Version: @VERSION@ Requires: libusb, libpcsclite -Libs: -L${libdir} -lmytoolkit +Libs: -L${libdir} -lnfc Cflags: -I${includedir} diff --git a/src/Makefile.am b/src/Makefile.am index 3836b9f..716ff04 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,16 +1,24 @@ +enable_pcsc_lite = @enable_pcsc_lite@ + bin_PROGRAMS = nfc-anticol nfc-list nfc-mftool nfc-relay nfc-emulate # set the include path found by configure INCLUDES= $(all_includes) -nfcinclude_HEADERS = libnfc.h bitutils.h defines.h dev_acr122.h dev_pn531.h types.h mifaretag.h devices.h +nfcinclude_HEADERS = libnfc.h bitutils.h defines.h types.h mifaretag.h devices.h nfcincludedir = $(includedir)/libnfc lib_LTLIBRARIES = libnfc.la +libnfc_la_SOURCES = bitutils.c libnfc.c +libnfc_la_CFLAGS = +libnfc_la_LIBADD = -libnfc_la_CFLAGS = @LIBUSB_CFLAGS@ @LIBPCSCLITE_CFLAGS@ -libnfc_la_SOURCES = dev_pn531.c dev_acr122.c bitutils.c libnfc.c -libnfc_la_LIBADD = @LIBUSB_LIBS@ @LIBPCSCLITE_LIBS@ +if PCSC_LITE_ENABLED + nfcinclude_HEADERS += dev_acr122.h dev_pn531.h + libnfc_la_CFLAGS += @LIBUSB_CFLAGS@ @LIBPCSCLITE_CFLAGS@ + libnfc_la_SOURCES += dev_pn531.c dev_acr122.c + libnfc_la_LIBADD += @LIBUSB_LIBS@ @LIBPCSCLITE_LIBS@ +endif nfc_anticol_SOURCES = anticol.c nfc_anticol_LDADD = libnfc.la From 5391dfc902422e6431e4cc4abeda3b681bd4f0ed Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Thu, 11 Jun 2009 08:34:43 +0000 Subject: [PATCH 08/29] MERGE: svn merge -r 19:20 trunk/src branches/portability/src --- src/defines.h | 1 + src/dev_acr122.c | 7 +++---- src/devices.h | 4 +++- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/defines.h b/src/defines.h index 122ac25..4641be7 100644 --- a/src/defines.h +++ b/src/defines.h @@ -29,6 +29,7 @@ typedef void* dev_spec; // Device connection specification #define INVALID_DEVICE_INFO 0 #define MAX_FRAME_LEN 264 #define DEVICE_NAME_LENGTH 256 +#define MAX_DEVICES 16 // Useful macros #define MIN(a,b) (((a) < (b)) ? (a) : (b)) diff --git a/src/dev_acr122.c b/src/dev_acr122.c index 80b8363..22b6eb1 100644 --- a/src/dev_acr122.c +++ b/src/dev_acr122.c @@ -43,7 +43,6 @@ along with this program. If not, see . #define ACR122_WRAP_LEN 5 #define ACR122_COMMAND_LEN 266 #define ACR122_RESPONSE_LEN 268 -#define MAX_READERS 16 typedef struct { SCARDCONTEXT hCtx; @@ -61,8 +60,8 @@ static byte abtLed[9] = { 0xFF,0x00,0x40,0x05,0x04,0x00,0x00,0x00,0x00 }; dev_info* dev_acr122_connect(const uint32_t uiIndex) { - char* pacReaders[MAX_READERS]; - char acList[256+64*MAX_READERS]; + char* pacReaders[MAX_DEVICES]; + char acList[256+64*MAX_DEVICES]; size_t ulListLen = sizeof(acList); uint32_t uiPos; uint32_t uiReaderCount; @@ -92,7 +91,7 @@ dev_info* dev_acr122_connect(const uint32_t uiIndex) for (uiPos=0; uiPos. #include "types.h" #include "dev_acr122.h" #include "dev_pn531.h" +#include "dev_arygon.h" const static struct dev_callbacks dev_callbacks_list[] = { // Driver Name Connect Transceive Disconect { "ACR122", dev_acr122_connect, dev_acr122_transceive, dev_acr122_disconnect }, - { "PN531USB", dev_pn531_connect, dev_pn531_transceive, dev_pn531_disconnect } + { "PN531USB", dev_pn531_connect, dev_pn531_transceive, dev_pn531_disconnect }, + { "ARYGON", dev_arygon_connect, dev_arygon_transceive, dev_arygon_disconnect } }; #endif // _LIBNFC_DEVICES_H_ From d74f0d13dd50712745cba69579d799e0f9db792f Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Thu, 11 Jun 2009 09:12:00 +0000 Subject: [PATCH 09/29] MERGE: svn merge -r 20:23 trunk/src branches/portability/src --- src/dev_arygon.c | 139 ++++++++++++++++++++++ src/dev_arygon.h | 35 ++++++ src/dev_pn531.c | 7 +- src/dev_pn533.c | 256 +++++++++++++++++++++++++++++++++++++++ src/dev_pn533.h | 35 ++++++ src/devices.h | 2 + src/rs232.c | 304 +++++++++++++++++++++++++++++++++++++++++++++++ src/rs232.h | 56 +++++++++ 8 files changed, 832 insertions(+), 2 deletions(-) create mode 100644 src/dev_arygon.c create mode 100644 src/dev_arygon.h create mode 100644 src/dev_pn533.c create mode 100644 src/dev_pn533.h create mode 100644 src/rs232.c create mode 100644 src/rs232.h diff --git a/src/dev_arygon.c b/src/dev_arygon.c new file mode 100644 index 0000000..63da211 --- /dev/null +++ b/src/dev_arygon.c @@ -0,0 +1,139 @@ +/* + +Public platform independent Near Field Communication (NFC) library +Copyright (C) 2009, Roel Verdult + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . + +*/ + +#include "dev_arygon.h" +#include "rs232.h" +#include "bitutils.h" + +#ifdef _WIN32 + #define SERIAL_STRING "COM" +#endif +#ifdef _LINUX + #define SERIAL_STRING "/dev/ttyusb" +#endif +#ifdef __APPLE__ + #define SERIAL_STRING "/dev/tty.SLAB_USBtoUART" +#endif + +#define BUFFER_LENGTH 256 +#define USB_TIMEOUT 30000 +static byte abtTxBuf[BUFFER_LENGTH] = { 0x32, 0x00, 0x00, 0xff }; // Every packet must start with "00 00 ff" + +dev_info* dev_arygon_connect(const ui32 uiIndex) +{ + ui32 uiDevNr; + serial_port sp; + char acConnect[BUFFER_LENGTH]; + dev_info* pdi = INVALID_DEVICE_INFO; + +#ifdef _LIBNFC_VERBOSE_ + printf("Trying to find ARYGON device on serial port: %s#\n",SERIAL_STRING); +#endif + + // I have no idea how MAC OS X deals with multiple devices, so a quick workaround + for (uiDevNr=0; uiDevNracName,"ARYGON"); + pdi->ct = CT_PN532; + pdi->ds = (dev_spec)sp; + pdi->bActive = true; + pdi->bCrc = true; + pdi->bPar = true; + pdi->ui8TxBits = 0; + return pdi; +} + +void dev_arygon_disconnect(dev_info* pdi) +{ + rs232_close((serial_port)pdi->ds); + free(pdi); +} + +bool dev_arygon_transceive(const dev_spec ds, const byte* pbtTx, const ui32 uiTxLen, byte* pbtRx, ui32* puiRxLen) +{ + byte abtRxBuf[BUFFER_LENGTH]; + ui32 uiRxBufLen = BUFFER_LENGTH; + ui32 uiPos; + + // Packet length = data length (len) + checksum (1) + end of stream marker (1) + abtTxBuf[4] = uiTxLen; + // Packet length checksum + abtTxBuf[5] = BUFFER_LENGTH - abtTxBuf[4]; + // Copy the PN53X command into the packet buffer + memmove(abtTxBuf+6,pbtTx,uiTxLen); + + // Calculate data payload checksum + abtTxBuf[uiTxLen+6] = 0; + for(uiPos=0; uiPos < uiTxLen; uiPos++) + { + abtTxBuf[uiTxLen+6] -= abtTxBuf[uiPos+6]; + } + + // End of stream marker + abtTxBuf[uiTxLen+7] = 0; + +#ifdef _LIBNFC_VERBOSE_ + printf("Tx: "); + print_hex(abtTxBuf,uiTxLen+8); +#endif + if (!rs232_send((serial_port)ds,abtTxBuf,uiTxLen+8)) return false; + + if (!rs232_receive((serial_port)ds,abtRxBuf,&uiRxBufLen)) return false; + + +#ifdef _LIBNFC_VERBOSE_ + printf("Rx: "); + print_hex(abtRxBuf,uiRxBufLen); +#endif + + // When the answer should be ignored, just return a succesful result + if(pbtRx == null || puiRxLen == null) return true; + + // Only succeed when the result is at least 00 00 ff 00 ff 00 00 00 FF xx Fx Dx xx .. .. .. xx 00 (x = variable) + if(uiRxBufLen < 15) return false; + + // Remove the preceding and appending bytes 00 00 ff 00 ff 00 00 00 FF xx Fx .. .. .. xx 00 (x = variable) + *puiRxLen = uiRxBufLen - 15; + memcpy(pbtRx, abtRxBuf+13, *puiRxLen); + + return true; +} diff --git a/src/dev_arygon.h b/src/dev_arygon.h new file mode 100644 index 0000000..a1dfd2d --- /dev/null +++ b/src/dev_arygon.h @@ -0,0 +1,35 @@ +/* + +Public platform independent Near Field Communication (NFC) library +Copyright (C) 2009, Roel Verdult + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . + +*/ + +#ifndef _LIBNFC_DEV_ARYGON_H_ +#define _LIBNFC_DEV_ARYGON_H_ + +#include "defines.h" +#include "types.h" + +// Functions used by developer to handle connection to this device +dev_info* dev_arygon_connect(const ui32 uiIndex); +void dev_arygon_disconnect(dev_info* pdi); + +// Callback function used by libnfc to transmit commands to the PN53X chip +bool dev_arygon_transceive(const dev_spec ds, const byte* pbtTx, const ui32 uiTxLen, byte* pbtRx, ui32* puiRxLen); + +#endif // _LIBNFC_DEV_ARYGON_H_ + diff --git a/src/dev_pn531.c b/src/dev_pn531.c index ba84cfd..ad2d5fd 100644 --- a/src/dev_pn531.c +++ b/src/dev_pn531.c @@ -41,7 +41,7 @@ typedef struct { } dev_spec_pn531; // Find transfer endpoints for bulk transfers -void get_end_points(struct usb_device *dev, dev_spec_pn531* pdsp) +static void get_end_points(struct usb_device *dev, dev_spec_pn531* pdsp) { uint32_t uiIndex; uint32_t uiEndPoint; @@ -80,6 +80,8 @@ dev_info* dev_pn531_connect(const uint32_t uiIndex) { int idvendor = 0x04CC; int idproduct = 0x0531; + int idvendor_alt = 0x054c; + int idproduct_alt = 0x0193; struct usb_bus *bus; struct usb_device *dev; dev_info* pdi = INVALID_DEVICE_INFO; @@ -102,7 +104,8 @@ dev_info* dev_pn531_connect(const uint32_t uiIndex) { for (dev = bus->devices; dev; dev = dev->next) { - if (idvendor==dev->descriptor.idVendor && idproduct==dev->descriptor.idProduct) + if ((idvendor==dev->descriptor.idVendor && idproduct==dev->descriptor.idProduct) || + (idvendor_alt==dev->descriptor.idVendor && idproduct_alt==dev->descriptor.idProduct)) { // Make sure there are 2 endpoints available if (dev->config->interface->altsetting->bNumEndpoints < 2) return pdi; diff --git a/src/dev_pn533.c b/src/dev_pn533.c new file mode 100644 index 0000000..9493994 --- /dev/null +++ b/src/dev_pn533.c @@ -0,0 +1,256 @@ +/* + +Public platform independent Near Field Communication (NFC) library +Copyright (C) 2009, Roel Verdult + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . + +Thanks to d18c7db and Okko for example code + +*/ + +#include "defines.h" + +#include +#include +#include +#include "dev_pn533.h" +#include "bitutils.h" + +#define BUFFER_LENGTH 256 +#define USB_TIMEOUT 30000 +static char buffer[BUFFER_LENGTH] = { 0x00, 0x00, 0xff }; // Every packet must start with "00 00 ff" + +typedef struct { + usb_dev_handle* pudh; + ui32 uiEndPointIn; + ui32 uiEndPointOut; +} dev_spec_pn533; + +// Find transfer endpoints for bulk transfers +static void get_end_points(struct usb_device *dev, dev_spec_pn533* pdsp) +{ + ui32 uiIndex; + ui32 uiEndPoint; + struct usb_interface_descriptor* puid = dev->config->interface->altsetting; + + // 3 Endpoints maximum: Interrupt In, Bulk In, Bulk Out + for(uiIndex = 0; uiIndex < puid->bNumEndpoints; uiIndex++) + { + // Only accept bulk transfer endpoints (ignore interrupt endpoints) + if(puid->endpoint[uiIndex].bmAttributes != USB_ENDPOINT_TYPE_BULK) continue; + + // Copy the endpoint to a local var, makes it more readable code + uiEndPoint = puid->endpoint[uiIndex].bEndpointAddress; + + // Test if we dealing with a bulk IN endpoint + if((uiEndPoint & USB_ENDPOINT_DIR_MASK) == USB_ENDPOINT_IN) + { + #ifdef _LIBNFC_VERBOSE_ + printf("Bulk endpoint in : 0x%02X\n", uiEndPoint); + #endif + pdsp->uiEndPointIn = uiEndPoint; + } + + // Test if we dealing with a bulk OUT endpoint + if((uiEndPoint & USB_ENDPOINT_DIR_MASK) == USB_ENDPOINT_OUT) + { + #ifdef _LIBNFC_VERBOSE_ + printf("Bulk endpoint in : 0x%02X\n", uiEndPoint); + #endif + pdsp->uiEndPointOut = uiEndPoint; + } + } +} + +dev_info* dev_pn533_connect(const ui32 uiIndex) +{ + int idvendor = 0x04e6; + int idproduct = 0x5591; + struct usb_bus *bus; + struct usb_device *dev; + dev_info* pdi = INVALID_DEVICE_INFO; + dev_spec_pn533* pdsp; + dev_spec_pn533 dsp; + ui32 uiDevIndex; + + dsp.uiEndPointIn = 0; + dsp.uiEndPointOut = 0; + dsp.pudh = null; + + usb_init(); + if (usb_find_busses() < 0) return INVALID_DEVICE_INFO; + if (usb_find_devices() < 0) return INVALID_DEVICE_INFO; + + // Initialize the device index we are seaching for + uiDevIndex = uiIndex; + + for (bus = usb_get_busses(); bus; bus = bus->next) + { + for (dev = bus->devices; dev; dev = dev->next) + { + if (idvendor==dev->descriptor.idVendor && idproduct==dev->descriptor.idProduct) + { + // Make sure there are 2 endpoints available + if (dev->config->interface->altsetting->bNumEndpoints < 2) return pdi; + + // Test if we are looking for this device according to the current index + if (uiDevIndex != 0) + { + // Nope, we maybe want the next one, let's try to find another + uiDevIndex--; + continue; + } + #ifdef _LIBNFC_VERBOSE_ + printf("Found PN533 device\n"); + #endif + + // Open the PN533 USB device + dsp.pudh = usb_open(dev); + + get_end_points(dev,&dsp); + if(usb_set_configuration(dsp.pudh,1) < 0) + { + #ifdef _LIBNFC_VERBOSE_ + printf("Setting config failed\n"); + #endif + usb_close(dsp.pudh); + return INVALID_DEVICE_INFO; + } + + if(usb_claim_interface(dsp.pudh,0) < 0) + { + #ifdef _LIBNFC_VERBOSE_ + printf("Can't claim interface\n"); + #endif + usb_close(dsp.pudh); + return INVALID_DEVICE_INFO; + } + // Allocate memory for the device info and specification, fill it and return the info + pdsp = malloc(sizeof(dev_spec_pn533)); + *pdsp = dsp; + pdi = malloc(sizeof(dev_info)); + strcpy(pdi->acName,"PN533USB"); + pdi->ct = CT_PN533; + pdi->ds = (dev_spec)pdsp; + pdi->bActive = true; + pdi->bCrc = true; + pdi->bPar = true; + pdi->ui8TxBits = 0; + return pdi; + } + } + } + return pdi; +} + +void dev_pn533_disconnect(dev_info* pdi) +{ + dev_spec_pn533* pdsp = (dev_spec_pn533*)pdi->ds; + usb_release_interface(pdsp->pudh,0); + usb_close(pdsp->pudh); + free(pdi->ds); + free(pdi); +} + +bool dev_pn533_transceive(const dev_spec ds, const byte* pbtTx, const ui32 uiTxLen, byte* pbtRx, ui32* puiRxLen) +{ + ui32 uiPos = 0; + int ret = 0; + char buf[BUFFER_LENGTH]; + dev_spec_pn533* pdsp = (dev_spec_pn533*)ds; + + // Packet length = data length (len) + checksum (1) + end of stream marker (1) + buffer[3] = uiTxLen; + // Packet length checksum + buffer[4] = BUFFER_LENGTH - buffer[3]; + // Copy the PN53X command into the packet buffer + memmove(buffer+5,pbtTx,uiTxLen); + + // Calculate data payload checksum + buffer[uiTxLen+5] = 0; + for(uiPos=0; uiPos < uiTxLen; uiPos++) + { + buffer[uiTxLen+5] -= buffer[uiPos+5]; + } + + // End of stream marker + buffer[uiTxLen+6] = 0; + + #ifdef _LIBNFC_VERBOSE_ + printf("Tx: "); + print_hex((byte*)buffer,uiTxLen+7); + #endif + + ret = usb_bulk_write(pdsp->pudh, pdsp->uiEndPointOut, buffer, uiTxLen+7, USB_TIMEOUT); + if( ret < 0 ) + { + #ifdef _LIBNFC_VERBOSE_ + printf("usb_bulk_write failed with error %d\n", ret); + #endif + return false; + } + + ret = usb_bulk_read(pdsp->pudh, pdsp->uiEndPointIn, buf, BUFFER_LENGTH, USB_TIMEOUT); + if( ret < 0 ) + { + #ifdef _LIBNFC_VERBOSE_ + printf( "usb_bulk_read failed with error %d\n", ret); + #endif + return false; + } + + #ifdef _LIBNFC_VERBOSE_ + printf("Rx: "); + print_hex((byte*)buf,ret); + #endif + + if( ret == 6 ) + { + ret = usb_bulk_read(pdsp->pudh, pdsp->uiEndPointIn, buf, BUFFER_LENGTH, USB_TIMEOUT); + if( ret < 0 ) + { + #ifdef _LIBNFC_VERBOSE_ + printf("usb_bulk_read failed with error %d\n", ret); + #endif + return false; + } + + #ifdef _LIBNFC_VERBOSE_ + printf("Rx: "); + print_hex((byte*)buf,ret); + #endif + } + + // When the answer should be ignored, just return a succesful result + if(pbtRx == null || puiRxLen == null) return true; + + // Only succeed when the result is at least 00 00 FF xx Fx Dx xx .. .. .. xx 00 (x = variable) + if(ret < 9) return false; + + // Remove the preceding and appending bytes 00 00 FF xx Fx .. .. .. xx 00 (x = variable) + *puiRxLen = ret - 7 - 2; + + // Get register: nuke extra byte (awful hack) + if ((buf[5]==(char)0xd5) && (buf[6]==(char)0x07) && (*puiRxLen==2)) { + // printf("Got %02x %02x, keep %02x\n", buf[7], buf[8], buf[8]); + *puiRxLen = (*puiRxLen) - 1; + memcpy( pbtRx, buf + 8, *puiRxLen); + return true; + } + + memcpy( pbtRx, buf + 7, *puiRxLen); + + return true; +} diff --git a/src/dev_pn533.h b/src/dev_pn533.h new file mode 100644 index 0000000..387c549 --- /dev/null +++ b/src/dev_pn533.h @@ -0,0 +1,35 @@ +/* + +Public platform independent Near Field Communication (NFC) library +Copyright (C) 2009, Roel Verdult + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . + +*/ + +#ifndef _LIBNFC_DEV_PN533_H_ +#define _LIBNFC_DEV_PN533_H_ + +#include "defines.h" +#include "types.h" + +// Functions used by developer to handle connection to this device +dev_info* dev_pn533_connect(const ui32 uiIndex); +void dev_pn533_disconnect(dev_info* pdi); + +// Callback function used by libnfc to transmit commands to the PN53X chip +bool dev_pn533_transceive(const dev_spec ds, const byte* pbtTx, const ui32 uiTxLen, byte* pbtRx, ui32* puiRxLen); + +#endif // _LIBNFC_DEV_PN533_H_ + diff --git a/src/devices.h b/src/devices.h index 0104d5a..15f8333 100644 --- a/src/devices.h +++ b/src/devices.h @@ -25,12 +25,14 @@ along with this program. If not, see . #include "types.h" #include "dev_acr122.h" #include "dev_pn531.h" +#include "dev_pn533.h" #include "dev_arygon.h" const static struct dev_callbacks dev_callbacks_list[] = { // Driver Name Connect Transceive Disconect { "ACR122", dev_acr122_connect, dev_acr122_transceive, dev_acr122_disconnect }, { "PN531USB", dev_pn531_connect, dev_pn531_transceive, dev_pn531_disconnect }, + { "PN533USB", dev_pn533_connect, dev_pn533_transceive, dev_pn533_disconnect }, { "ARYGON", dev_arygon_connect, dev_arygon_transceive, dev_arygon_disconnect } }; diff --git a/src/rs232.c b/src/rs232.c new file mode 100644 index 0000000..bbe9a0e --- /dev/null +++ b/src/rs232.c @@ -0,0 +1,304 @@ +/* + +Public platform independent Near Field Communication (NFC) library +Copyright (C) 2009, Roel Verdult + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . + + Based on rs232-code written by Teunis van Beelen + available: http://www.teuniz.net/RS-232/index.html + +*/ + + +#include "rs232.h" + +#ifndef _WIN32 /* Linux */ + +typedef struct termios term_info; +typedef struct { + int fd; // Serial port file descriptor + term_info tiOld; // Terminal info before using the port + term_info tiNew; // Terminal info during the transaction +} serial_port_unix; + +// Set time-out on 30 miliseconds +struct timeval tv = { + .tv_sec = 0, // No seconds + .tv_usec = 30000 // 30,000 micro seconds +}; + +// Work-around to claim rs232 interface using the c_iflag (software input processing) from the termios struct +#define CCLAIMED 0x80000000 + +serial_port rs232_open(const char* pcPortName) +{ + serial_port_unix* sp = malloc(sizeof(serial_port_unix)); + + if (sp == 0) return INVALID_SERIAL_PORT; + + sp->fd = open(pcPortName, O_RDWR | O_NOCTTY | O_NDELAY | O_NONBLOCK); + if(sp->fd == -1) + { + rs232_close(sp); + return INVALID_SERIAL_PORT; + } + + if(tcgetattr(sp->fd,&sp->tiOld) == -1) + { + rs232_close(sp); + return INVALID_SERIAL_PORT; + } + + // Make sure the port is not claimed already + if (sp->tiOld.c_iflag & CCLAIMED) + { + rs232_close(sp); + return CLAIMED_SERIAL_PORT; + } + + // Copy the old terminal info struct + sp->tiNew = sp->tiOld; + sp->tiNew.c_cflag = CS8 | CLOCAL | CREAD; + sp->tiNew.c_iflag = CCLAIMED | IGNPAR; + sp->tiNew.c_oflag = 0; + sp->tiNew.c_lflag = 0; + sp->tiNew.c_cc[VMIN] = 0; // block untill n bytes are received + sp->tiNew.c_cc[VTIME] = 0; // block untill a timer expires (n * 100 mSec.) + if(tcsetattr(sp->fd,TCSANOW,&sp->tiNew) == -1) + { + rs232_close(sp); + return INVALID_SERIAL_PORT; + } + return sp; +} + +void rs232_close(const serial_port sp) +{ + tcsetattr(((serial_port_unix*)sp)->fd,TCSANOW,&((serial_port_unix*)sp)->tiOld); + close(((serial_port_unix*)sp)->fd); + free(sp); +} + +bool rs232_cts(const serial_port sp) +{ + ulong ulStatus; + if (ioctl(((serial_port_unix*)sp)->fd,TIOCMGET,&ulStatus) < 0) return false; + return (ulStatus & TIOCM_CTS); +} + +bool rs232_receive(const serial_port sp, byte* pbtRx, ui32* puiRxLen) +{ + int iResult; + ui32 uiCount = 0; + fd_set rfds; + + while (true) + { + // Reset file descriptor + FD_ZERO(&rfds); + FD_SET(((serial_port_unix*)sp)->fd,&rfds); + iResult = select(((serial_port_unix*)sp)->fd+1, &rfds, NULL, NULL, &tv); + + // Read error + if (iResult < 0) return false; + + // Read time-out + if (iResult == 0) + { + // Test if we at least have received something + if (uiCount == 0) return false; + // Store the received byte count and return succesful + *puiRxLen = uiCount; + return true; + } + + // There is something available, read the data + uiCount += read(((serial_port_unix*)sp)->fd,pbtRx+uiCount,*puiRxLen-uiCount); + } +} + +bool rs232_send(const serial_port sp, const byte* pbtTx, const ui32 uiTxLen) +{ + int iResult; + iResult = write(((serial_port_unix*)sp)->fd,pbtTx,uiTxLen); + return (iResult >= 0); +} + +#else /* windows */ + + +HANDLE Cport[16]; + + +char comports[16][10]={"\\\\.\\COM1", "\\\\.\\COM2", "\\\\.\\COM3", "\\\\.\\COM4", + "\\\\.\\COM5", "\\\\.\\COM6", "\\\\.\\COM7", "\\\\.\\COM8", + "\\\\.\\COM9", "\\\\.\\COM10", "\\\\.\\COM11", "\\\\.\\COM12", + "\\\\.\\COM13", "\\\\.\\COM14", "\\\\.\\COM15", "\\\\.\\COM16"}; + +char baudr[64]; + + +int OpenComport(int comport_number, int baudrate) +{ + if((comport_number>15)||(comport_number<0)) + { + printf("illegal comport number\n"); + return(1); + } + + switch(baudrate) + { + sscanf(baudr,"baud=%d data=8 parity=N stop=1",baudrate); +/* + case 110 : strcpy(baudr, "baud=110 data=8 parity=N stop=1"); + break; + case 300 : strcpy(baudr, "baud=300 data=8 parity=N stop=1"); + break; + case 600 : strcpy(baudr, "baud=600 data=8 parity=N stop=1"); + break; + case 1200 : strcpy(baudr, "baud=1200 data=8 parity=N stop=1"); + break; + case 2400 : strcpy(baudr, "baud=2400 data=8 parity=N stop=1"); + break; + case 4800 : strcpy(baudr, "baud=4800 data=8 parity=N stop=1"); + break; + case 9600 : strcpy(baudr, "baud=9600 data=8 parity=N stop=1"); + break; + case 19200 : strcpy(baudr, "baud=19200 data=8 parity=N stop=1"); + break; + case 38400 : strcpy(baudr, "baud=38400 data=8 parity=N stop=1"); + break; + case 57600 : strcpy(baudr, "baud=57600 data=8 parity=N stop=1"); + break; + case 115200 : strcpy(baudr, "baud=115200 data=8 parity=N stop=1"); + break; + case 128000 : strcpy(baudr, "baud=128000 data=8 parity=N stop=1"); + break; + case 256000 : strcpy(baudr, "baud=256000 data=8 parity=N stop=1"); + break; + default : printf("invalid baudrate\n"); + return(1); + break; +*/ + } + + Cport[comport_number] = CreateFileA(comports[comport_number], + GENERIC_READ|GENERIC_WRITE, + 0, /* no share */ + NULL, /* no security */ + OPEN_EXISTING, + 0, /* no threads */ + NULL); /* no templates */ + + if(Cport[comport_number]==INVALID_HANDLE_VALUE) + { + printf("unable to open comport\n"); + return(1); + } + + DCB port_settings; + memset(&port_settings, 0, sizeof(port_settings)); /* clear the new struct */ + port_settings.DCBlength = sizeof(port_settings); + + if(!BuildCommDCBA(baudr, &port_settings)) + { + printf("unable to set comport dcb settings\n"); + CloseHandle(Cport[comport_number]); + return(1); + } + + if(!SetCommState(Cport[comport_number], &port_settings)) + { + printf("unable to set comport cfg settings\n"); + CloseHandle(Cport[comport_number]); + return(1); + } + + COMMTIMEOUTS Cptimeouts; + + Cptimeouts.ReadIntervalTimeout = MAXDWORD; + Cptimeouts.ReadTotalTimeoutMultiplier = 0; + Cptimeouts.ReadTotalTimeoutConstant = 0; + Cptimeouts.WriteTotalTimeoutMultiplier = 0; + Cptimeouts.WriteTotalTimeoutConstant = 0; + + if(!SetCommTimeouts(Cport[comport_number], &Cptimeouts)) + { + printf("unable to set comport time-out settings\n"); + CloseHandle(Cport[comport_number]); + return(1); + } + + return(0); +} + + +int PollComport(int comport_number, unsigned char *buf, int size) +{ + int n; + + if(size>4096) size = 4096; + +/* added the void pointer cast, otherwise gcc will complain about */ +/* "warning: dereferencing type-punned pointer will break strict aliasing rules" */ + + ReadFile(Cport[comport_number], buf, size, (LPDWORD)((void *)&n), NULL); + + return(n); +} + + +int SendByte(int comport_number, unsigned char byte) +{ + int n; + + WriteFile(Cport[comport_number], &byte, 1, (LPDWORD)((void *)&n), NULL); + + if(n<0) return(1); + + return(0); +} + + +int SendBuf(int comport_number, unsigned char *buf, int size) +{ + int n; + + if(WriteFile(Cport[comport_number], buf, size, (LPDWORD)((void *)&n), NULL)) + { + return(n); + } + + return(-1); +} + +bool rs232_cts(const serial_port sp); +{ + int status; + + GetCommModemStatus(Cport[comport_number], (LPDWORD)((void *)&status)); + + if(status&MS_CTS_ON) return(1); + else return(0); +} + + +void CloseComport(int comport_number) +{ + CloseHandle(Cport[comport_number]); +} + + +#endif diff --git a/src/rs232.h b/src/rs232.h new file mode 100644 index 0000000..3a5b95d --- /dev/null +++ b/src/rs232.h @@ -0,0 +1,56 @@ +/* + +Public platform independent Near Field Communication (NFC) library +Copyright (C) 2009, Roel Verdult + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . + +*/ + +#ifndef _LIBNFC_RS232_H_ +#define _LIBNFC_RS232_H_ + +#include +#include +#include +#include "defines.h" +#include "types.h" + +// Handle platform specific includes +#ifndef _WIN32 + #include + #include + #include + #include + #include + #include + #include +#else + #include +#endif + +// Define shortcut to types to make code more readable +typedef void* serial_port; +#define INVALID_SERIAL_PORT (void*)(~1) +#define CLAIMED_SERIAL_PORT (void*)(~2) + +serial_port rs232_open(const char* pcPortName); +void rs232_close(const serial_port sp); +bool rs232_cts(const serial_port sp); +bool rs232_receive(const serial_port sp, byte* pbtRx, ui32* puiRxLen); +bool rs232_send(const serial_port sp, const byte* pbtTx, const ui32 uiTxLen); + +#endif // _LIBNFC_RS232_H_ + + From eccb9d3d3b8c01fece6031438e1054579b3f76b7 Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Thu, 11 Jun 2009 10:16:27 +0000 Subject: [PATCH 10/29] Fix rs232.* under linux. Fix merged code to be C99 compiliant. Try to fix dev_arygon under linux (could not be tested here, sorry). Try to fix MacOSX makefile (could not be tested here, sorry). Adjust src/Makefile.am to compile/dist all new files. --- macosx/Makefile | 2 +- src/Makefile.am | 8 ++++---- src/dev_arygon.c | 34 +++++++++++++++++----------------- src/dev_arygon.h | 4 ++-- src/dev_pn533.c | 42 +++++++++++++++++++++--------------------- src/dev_pn533.h | 4 ++-- src/rs232.c | 12 ++++++------ src/rs232.h | 5 +++-- 8 files changed, 56 insertions(+), 55 deletions(-) diff --git a/macosx/Makefile b/macosx/Makefile index cab8233..6c01605 100644 --- a/macosx/Makefile +++ b/macosx/Makefile @@ -24,7 +24,7 @@ LD = gcc CFLAGS = -fPIC -Wall -O4 $(LIBPCSC_HEADERS) $(LIBUSB_HEADERS) LDFLAGS = -fPIC -Wall -O4 -OBJS = dev_pn531.o dev_acr122.o bitutils.o libnfc.o +OBJS = dev_pn531.o dev_pn533.o dev_acr122.o dev_arygon.o bitutils.o libnfc.o rs232.o HEADERS = devices.h bitutils.h defines.h libnfc.h LIBNFC = libnfc.$(LIBNFC_TYPE) EXES = anticol emulate list mftool relay diff --git a/src/Makefile.am b/src/Makefile.am index 716ff04..38d711a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -5,18 +5,18 @@ bin_PROGRAMS = nfc-anticol nfc-list nfc-mftool nfc-relay nfc-emulate # set the include path found by configure INCLUDES= $(all_includes) -nfcinclude_HEADERS = libnfc.h bitutils.h defines.h types.h mifaretag.h devices.h +nfcinclude_HEADERS = libnfc.h bitutils.h defines.h types.h mifaretag.h devices.h rs232.h dev_arygon.h nfcincludedir = $(includedir)/libnfc lib_LTLIBRARIES = libnfc.la -libnfc_la_SOURCES = bitutils.c libnfc.c +libnfc_la_SOURCES = bitutils.c libnfc.c rs232.c dev_arygon.c libnfc_la_CFLAGS = libnfc_la_LIBADD = if PCSC_LITE_ENABLED - nfcinclude_HEADERS += dev_acr122.h dev_pn531.h + nfcinclude_HEADERS += dev_acr122.h dev_pn531.h dev_pn533.h libnfc_la_CFLAGS += @LIBUSB_CFLAGS@ @LIBPCSCLITE_CFLAGS@ - libnfc_la_SOURCES += dev_pn531.c dev_acr122.c + libnfc_la_SOURCES += dev_acr122.c dev_pn531.c dev_pn533.c libnfc_la_LIBADD += @LIBUSB_LIBS@ @LIBPCSCLITE_LIBS@ endif diff --git a/src/dev_arygon.c b/src/dev_arygon.c index 63da211..d93a814 100644 --- a/src/dev_arygon.c +++ b/src/dev_arygon.c @@ -24,26 +24,26 @@ along with this program. If not, see . #ifdef _WIN32 #define SERIAL_STRING "COM" -#endif -#ifdef _LINUX - #define SERIAL_STRING "/dev/ttyusb" -#endif -#ifdef __APPLE__ - #define SERIAL_STRING "/dev/tty.SLAB_USBtoUART" +#else + #ifdef __APPLE__ + #define SERIAL_STRING "/dev/tty.SLAB_USBtoUART" + #else + #define SERIAL_STRING "/dev/ttyUSB" + #endif #endif #define BUFFER_LENGTH 256 #define USB_TIMEOUT 30000 static byte abtTxBuf[BUFFER_LENGTH] = { 0x32, 0x00, 0x00, 0xff }; // Every packet must start with "00 00 ff" -dev_info* dev_arygon_connect(const ui32 uiIndex) +dev_info* dev_arygon_connect(const uint32_t uiIndex) { - ui32 uiDevNr; + uint32_t uiDevNr; serial_port sp; char acConnect[BUFFER_LENGTH]; dev_info* pdi = INVALID_DEVICE_INFO; -#ifdef _LIBNFC_VERBOSE_ +#ifdef DEBUG printf("Trying to find ARYGON device on serial port: %s#\n",SERIAL_STRING); #endif @@ -58,7 +58,7 @@ dev_info* dev_arygon_connect(const ui32 uiIndex) sp = rs232_open(acConnect); #endif if ((sp != INVALID_SERIAL_PORT) && (sp != CLAIMED_SERIAL_PORT)) break; - #ifdef _LIBNFC_VERBOSE_ + #ifdef DEBUG if (sp == INVALID_SERIAL_PORT) printf("invalid serial port: %s\n",acConnect); if (sp == CLAIMED_SERIAL_PORT) printf("serial port already claimed: %s\n",acConnect); #endif @@ -66,7 +66,7 @@ dev_info* dev_arygon_connect(const ui32 uiIndex) // Test if we have found a device if (uiDevNr == MAX_DEVICES) return INVALID_DEVICE_INFO; -#ifdef _LIBNFC_VERBOSE_ +#ifdef DEBUG printf("Succesfully connected to: %s\n",acConnect); #endif @@ -88,11 +88,11 @@ void dev_arygon_disconnect(dev_info* pdi) free(pdi); } -bool dev_arygon_transceive(const dev_spec ds, const byte* pbtTx, const ui32 uiTxLen, byte* pbtRx, ui32* puiRxLen) +bool dev_arygon_transceive(const dev_spec ds, const byte* pbtTx, const uint32_t uiTxLen, byte* pbtRx, uint32_t* puiRxLen) { byte abtRxBuf[BUFFER_LENGTH]; - ui32 uiRxBufLen = BUFFER_LENGTH; - ui32 uiPos; + uint32_t uiRxBufLen = BUFFER_LENGTH; + uint32_t uiPos; // Packet length = data length (len) + checksum (1) + end of stream marker (1) abtTxBuf[4] = uiTxLen; @@ -111,7 +111,7 @@ bool dev_arygon_transceive(const dev_spec ds, const byte* pbtTx, const ui32 uiTx // End of stream marker abtTxBuf[uiTxLen+7] = 0; -#ifdef _LIBNFC_VERBOSE_ +#ifdef DEBUG printf("Tx: "); print_hex(abtTxBuf,uiTxLen+8); #endif @@ -120,13 +120,13 @@ bool dev_arygon_transceive(const dev_spec ds, const byte* pbtTx, const ui32 uiTx if (!rs232_receive((serial_port)ds,abtRxBuf,&uiRxBufLen)) return false; -#ifdef _LIBNFC_VERBOSE_ +#ifdef DEBUG printf("Rx: "); print_hex(abtRxBuf,uiRxBufLen); #endif // When the answer should be ignored, just return a succesful result - if(pbtRx == null || puiRxLen == null) return true; + if(pbtRx == NULL || puiRxLen == NULL) return true; // Only succeed when the result is at least 00 00 ff 00 ff 00 00 00 FF xx Fx Dx xx .. .. .. xx 00 (x = variable) if(uiRxBufLen < 15) return false; diff --git a/src/dev_arygon.h b/src/dev_arygon.h index a1dfd2d..1a5cc8f 100644 --- a/src/dev_arygon.h +++ b/src/dev_arygon.h @@ -25,11 +25,11 @@ along with this program. If not, see . #include "types.h" // Functions used by developer to handle connection to this device -dev_info* dev_arygon_connect(const ui32 uiIndex); +dev_info* dev_arygon_connect(const uint32_t uiIndex); void dev_arygon_disconnect(dev_info* pdi); // Callback function used by libnfc to transmit commands to the PN53X chip -bool dev_arygon_transceive(const dev_spec ds, const byte* pbtTx, const ui32 uiTxLen, byte* pbtRx, ui32* puiRxLen); +bool dev_arygon_transceive(const dev_spec ds, const byte* pbtTx, const uint32_t uiTxLen, byte* pbtRx, uint32_t* puiRxLen); #endif // _LIBNFC_DEV_ARYGON_H_ diff --git a/src/dev_pn533.c b/src/dev_pn533.c index 9493994..148b3b8 100644 --- a/src/dev_pn533.c +++ b/src/dev_pn533.c @@ -34,15 +34,15 @@ static char buffer[BUFFER_LENGTH] = { 0x00, 0x00, 0xff }; // Every packet must s typedef struct { usb_dev_handle* pudh; - ui32 uiEndPointIn; - ui32 uiEndPointOut; + uint32_t uiEndPointIn; + uint32_t uiEndPointOut; } dev_spec_pn533; // Find transfer endpoints for bulk transfers static void get_end_points(struct usb_device *dev, dev_spec_pn533* pdsp) { - ui32 uiIndex; - ui32 uiEndPoint; + uint32_t uiIndex; + uint32_t uiEndPoint; struct usb_interface_descriptor* puid = dev->config->interface->altsetting; // 3 Endpoints maximum: Interrupt In, Bulk In, Bulk Out @@ -57,7 +57,7 @@ static void get_end_points(struct usb_device *dev, dev_spec_pn533* pdsp) // Test if we dealing with a bulk IN endpoint if((uiEndPoint & USB_ENDPOINT_DIR_MASK) == USB_ENDPOINT_IN) { - #ifdef _LIBNFC_VERBOSE_ + #ifdef DEBUG printf("Bulk endpoint in : 0x%02X\n", uiEndPoint); #endif pdsp->uiEndPointIn = uiEndPoint; @@ -66,7 +66,7 @@ static void get_end_points(struct usb_device *dev, dev_spec_pn533* pdsp) // Test if we dealing with a bulk OUT endpoint if((uiEndPoint & USB_ENDPOINT_DIR_MASK) == USB_ENDPOINT_OUT) { - #ifdef _LIBNFC_VERBOSE_ + #ifdef DEBUG printf("Bulk endpoint in : 0x%02X\n", uiEndPoint); #endif pdsp->uiEndPointOut = uiEndPoint; @@ -74,7 +74,7 @@ static void get_end_points(struct usb_device *dev, dev_spec_pn533* pdsp) } } -dev_info* dev_pn533_connect(const ui32 uiIndex) +dev_info* dev_pn533_connect(const uint32_t uiIndex) { int idvendor = 0x04e6; int idproduct = 0x5591; @@ -83,11 +83,11 @@ dev_info* dev_pn533_connect(const ui32 uiIndex) dev_info* pdi = INVALID_DEVICE_INFO; dev_spec_pn533* pdsp; dev_spec_pn533 dsp; - ui32 uiDevIndex; + uint32_t uiDevIndex; dsp.uiEndPointIn = 0; dsp.uiEndPointOut = 0; - dsp.pudh = null; + dsp.pudh = NULL; usb_init(); if (usb_find_busses() < 0) return INVALID_DEVICE_INFO; @@ -112,7 +112,7 @@ dev_info* dev_pn533_connect(const ui32 uiIndex) uiDevIndex--; continue; } - #ifdef _LIBNFC_VERBOSE_ + #ifdef DEBUG printf("Found PN533 device\n"); #endif @@ -122,7 +122,7 @@ dev_info* dev_pn533_connect(const ui32 uiIndex) get_end_points(dev,&dsp); if(usb_set_configuration(dsp.pudh,1) < 0) { - #ifdef _LIBNFC_VERBOSE_ + #ifdef DEBUG printf("Setting config failed\n"); #endif usb_close(dsp.pudh); @@ -131,7 +131,7 @@ dev_info* dev_pn533_connect(const ui32 uiIndex) if(usb_claim_interface(dsp.pudh,0) < 0) { - #ifdef _LIBNFC_VERBOSE_ + #ifdef DEBUG printf("Can't claim interface\n"); #endif usb_close(dsp.pudh); @@ -164,9 +164,9 @@ void dev_pn533_disconnect(dev_info* pdi) free(pdi); } -bool dev_pn533_transceive(const dev_spec ds, const byte* pbtTx, const ui32 uiTxLen, byte* pbtRx, ui32* puiRxLen) +bool dev_pn533_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; char buf[BUFFER_LENGTH]; dev_spec_pn533* pdsp = (dev_spec_pn533*)ds; @@ -188,7 +188,7 @@ bool dev_pn533_transceive(const dev_spec ds, const byte* pbtTx, const ui32 uiTxL // End of stream marker buffer[uiTxLen+6] = 0; - #ifdef _LIBNFC_VERBOSE_ + #ifdef DEBUG printf("Tx: "); print_hex((byte*)buffer,uiTxLen+7); #endif @@ -196,7 +196,7 @@ bool dev_pn533_transceive(const dev_spec ds, const byte* pbtTx, const ui32 uiTxL ret = usb_bulk_write(pdsp->pudh, pdsp->uiEndPointOut, buffer, uiTxLen+7, USB_TIMEOUT); if( ret < 0 ) { - #ifdef _LIBNFC_VERBOSE_ + #ifdef DEBUG printf("usb_bulk_write failed with error %d\n", ret); #endif return false; @@ -205,13 +205,13 @@ bool dev_pn533_transceive(const dev_spec ds, const byte* pbtTx, const ui32 uiTxL ret = usb_bulk_read(pdsp->pudh, pdsp->uiEndPointIn, buf, BUFFER_LENGTH, USB_TIMEOUT); if( ret < 0 ) { - #ifdef _LIBNFC_VERBOSE_ + #ifdef DEBUG printf( "usb_bulk_read failed with error %d\n", ret); #endif return false; } - #ifdef _LIBNFC_VERBOSE_ + #ifdef DEBUG printf("Rx: "); print_hex((byte*)buf,ret); #endif @@ -221,20 +221,20 @@ bool dev_pn533_transceive(const dev_spec ds, const byte* pbtTx, const ui32 uiTxL ret = usb_bulk_read(pdsp->pudh, pdsp->uiEndPointIn, buf, BUFFER_LENGTH, USB_TIMEOUT); if( ret < 0 ) { - #ifdef _LIBNFC_VERBOSE_ + #ifdef DEBUG printf("usb_bulk_read failed with error %d\n", ret); #endif return false; } - #ifdef _LIBNFC_VERBOSE_ + #ifdef DEBUG printf("Rx: "); print_hex((byte*)buf,ret); #endif } // When the answer should be ignored, just return a succesful result - if(pbtRx == null || puiRxLen == null) return true; + if(pbtRx == NULL || puiRxLen == NULL) return true; // Only succeed when the result is at least 00 00 FF xx Fx Dx xx .. .. .. xx 00 (x = variable) if(ret < 9) return false; diff --git a/src/dev_pn533.h b/src/dev_pn533.h index 387c549..3ceb975 100644 --- a/src/dev_pn533.h +++ b/src/dev_pn533.h @@ -25,11 +25,11 @@ along with this program. If not, see . #include "types.h" // Functions used by developer to handle connection to this device -dev_info* dev_pn533_connect(const ui32 uiIndex); +dev_info* dev_pn533_connect(const uint32_t uiIndex); void dev_pn533_disconnect(dev_info* pdi); // Callback function used by libnfc to transmit commands to the PN53X chip -bool dev_pn533_transceive(const dev_spec ds, const byte* pbtTx, const ui32 uiTxLen, byte* pbtRx, ui32* puiRxLen); +bool dev_pn533_transceive(const dev_spec ds, const byte* pbtTx, const uint32_t uiTxLen, byte* pbtRx, uint32_t* puiRxLen); #endif // _LIBNFC_DEV_PN533_H_ diff --git a/src/rs232.c b/src/rs232.c index bbe9a0e..533c2f1 100644 --- a/src/rs232.c +++ b/src/rs232.c @@ -93,15 +93,15 @@ void rs232_close(const serial_port sp) bool rs232_cts(const serial_port sp) { - ulong ulStatus; - if (ioctl(((serial_port_unix*)sp)->fd,TIOCMGET,&ulStatus) < 0) return false; - return (ulStatus & TIOCM_CTS); + char status; + if (ioctl(((serial_port_unix*)sp)->fd,TIOCMGET,&status) < 0) return false; + return (status & TIOCM_CTS); } -bool rs232_receive(const serial_port sp, byte* pbtRx, ui32* puiRxLen) +bool rs232_receive(const serial_port sp, byte* pbtRx, uint32_t* puiRxLen) { int iResult; - ui32 uiCount = 0; + uint32_t uiCount = 0; fd_set rfds; while (true) @@ -129,7 +129,7 @@ bool rs232_receive(const serial_port sp, byte* pbtRx, ui32* puiRxLen) } } -bool rs232_send(const serial_port sp, const byte* pbtTx, const ui32 uiTxLen) +bool rs232_send(const serial_port sp, const byte* pbtTx, const uint32_t uiTxLen) { int iResult; iResult = write(((serial_port_unix*)sp)->fd,pbtTx,uiTxLen); diff --git a/src/rs232.h b/src/rs232.h index 3a5b95d..b78dc4c 100644 --- a/src/rs232.h +++ b/src/rs232.h @@ -36,6 +36,7 @@ along with this program. If not, see . #include #include #include + #include #else #include #endif @@ -48,8 +49,8 @@ typedef void* serial_port; serial_port rs232_open(const char* pcPortName); void rs232_close(const serial_port sp); bool rs232_cts(const serial_port sp); -bool rs232_receive(const serial_port sp, byte* pbtRx, ui32* puiRxLen); -bool rs232_send(const serial_port sp, const byte* pbtTx, const ui32 uiTxLen); +bool rs232_receive(const serial_port sp, byte* pbtRx, uint32_t* puiRxLen); +bool rs232_send(const serial_port sp, const byte* pbtTx, const uint32_t uiTxLen); #endif // _LIBNFC_RS232_H_ From bf5848e7a14ff813fd47bb12e9ebe73c7e09c774 Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Thu, 11 Jun 2009 11:57:36 +0000 Subject: [PATCH 11/29] libnfc can now be compiled without pcsc-lite (but it removes acr122 device support) --- configure.ac | 2 +- src/Makefile.am | 16 ++++++++-------- src/devices.h | 6 +++++- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/configure.ac b/configure.ac index 0a60684..a1701c9 100644 --- a/configure.ac +++ b/configure.ac @@ -36,7 +36,7 @@ then fi AM_CONDITIONAL(PCSC_LITE_ENABLED, [test x"$enable_pcsc_lite" = xyes]) -# --enable-debug support +# --enable-debug support (default:no) AC_ARG_ENABLE([debug],AS_HELP_STRING([--enable-debug],[Debug flags]),[enable_debug=$enableval],[enable_debug="no"]) AC_MSG_CHECKING(for debug flag) diff --git a/src/Makefile.am b/src/Makefile.am index 38d711a..5b8eaf2 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -5,19 +5,19 @@ bin_PROGRAMS = nfc-anticol nfc-list nfc-mftool nfc-relay nfc-emulate # set the include path found by configure INCLUDES= $(all_includes) -nfcinclude_HEADERS = libnfc.h bitutils.h defines.h types.h mifaretag.h devices.h rs232.h dev_arygon.h +nfcinclude_HEADERS = libnfc.h bitutils.h defines.h types.h mifaretag.h devices.h rs232.h dev_arygon.h dev_pn531.h dev_pn533.h nfcincludedir = $(includedir)/libnfc lib_LTLIBRARIES = libnfc.la -libnfc_la_SOURCES = bitutils.c libnfc.c rs232.c dev_arygon.c -libnfc_la_CFLAGS = -libnfc_la_LIBADD = +libnfc_la_SOURCES = bitutils.c libnfc.c rs232.c dev_arygon.c dev_pn531.c dev_pn533.c +libnfc_la_CFLAGS = @LIBUSB_CFLAGS@ +libnfc_la_LIBADD = @LIBUSB_LIBS@ if PCSC_LITE_ENABLED - nfcinclude_HEADERS += dev_acr122.h dev_pn531.h dev_pn533.h - libnfc_la_CFLAGS += @LIBUSB_CFLAGS@ @LIBPCSCLITE_CFLAGS@ - libnfc_la_SOURCES += dev_acr122.c dev_pn531.c dev_pn533.c - libnfc_la_LIBADD += @LIBUSB_LIBS@ @LIBPCSCLITE_LIBS@ + nfcinclude_HEADERS += dev_acr122.h + libnfc_la_CFLAGS += @LIBPCSCLITE_CFLAGS@ -DHAVE_PCSC_LITE + libnfc_la_SOURCES += dev_acr122.c + libnfc_la_LIBADD += @LIBPCSCLITE_LIBS@ endif nfc_anticol_SOURCES = anticol.c diff --git a/src/devices.h b/src/devices.h index 15f8333..8a98d68 100644 --- a/src/devices.h +++ b/src/devices.h @@ -23,14 +23,18 @@ along with this program. If not, see . #include "defines.h" #include "types.h" -#include "dev_acr122.h" +#ifdef HAVE_PCSC_LITE + #include "dev_acr122.h" +#endif #include "dev_pn531.h" #include "dev_pn533.h" #include "dev_arygon.h" const static struct dev_callbacks dev_callbacks_list[] = { // Driver Name Connect Transceive Disconect +#ifdef HAVE_PCSC_LITE { "ACR122", dev_acr122_connect, dev_acr122_transceive, dev_acr122_disconnect }, +#endif { "PN531USB", dev_pn531_connect, dev_pn531_transceive, dev_pn531_disconnect }, { "PN533USB", dev_pn533_connect, dev_pn533_transceive, dev_pn533_disconnect }, { "ARYGON", dev_arygon_connect, dev_arygon_transceive, dev_arygon_disconnect } From f29fd29e645c04e8bd2ac5ba8c10090d76a44689 Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Tue, 16 Jun 2009 08:03:49 +0000 Subject: [PATCH 12/29] Add debian files. --- debian/changelog | 12 ++++++++++++ debian/compat | 1 + debian/control | 30 ++++++++++++++++++++++++++++++ debian/copyright | 28 ++++++++++++++++++++++++++++ debian/libnfc-dev.install | 3 +++ debian/libnfc0.install | 1 + debian/nfc-tools.install | 1 + debian/rules | 4 ++++ 8 files changed, 80 insertions(+) create mode 100644 debian/changelog create mode 100644 debian/compat create mode 100644 debian/control create mode 100644 debian/copyright create mode 100644 debian/libnfc-dev.install create mode 100644 debian/libnfc0.install create mode 100644 debian/nfc-tools.install create mode 100755 debian/rules diff --git a/debian/changelog b/debian/changelog new file mode 100644 index 0000000..154b4a8 --- /dev/null +++ b/debian/changelog @@ -0,0 +1,12 @@ +libnfc (1.1.1-0) unstable; urgency=low + + * New upstream version. + + -- Romuald Conty Wed, 29 Apr 2009 16:42:42 +0100 + +libnfc (1.1.0-0) unstable; urgency=low + + * Initial debian package. + + -- Romuald Conty Wed, 22 Apr 2009 10:42:42 +0100 + diff --git a/debian/compat b/debian/compat new file mode 100644 index 0000000..7ed6ff8 --- /dev/null +++ b/debian/compat @@ -0,0 +1 @@ +5 diff --git a/debian/control b/debian/control new file mode 100644 index 0000000..1d52e0b --- /dev/null +++ b/debian/control @@ -0,0 +1,30 @@ +Source: libnfc +Section: devel +Priority: optional +Maintainer: Romuald Conty +Build-Depends: debhelper (>= 5.0.37.2), cdbs (>= 0.4.43), libusb-dev, libpcsclite-dev +Standards-Version: 3.7.3 +Homepage: http://www.libnfc.org/ + +Package: libnfc0 +Architecture: any +Depends: ${shlibs:Depends}, libusb-0.1-4, libpcsclite1 (>= 1.5), libccid (>= 1.3.10) +Description: Near Field Communication (NFC) library + libnfc is a Free Software NFC library. The supported NFC hardware devices are + the ACS ACR122(U) NFC reader and various NFC-dongles. In principle all + hardware based on the NXP PN53x NFC Controller chip is supported. + +Package: libnfc-dev +Architecture: any +Depends: libnfc0, libusb-dev, libpcsclite-dev +Description: Near Field Communication library (development files) + libnfc is a Free Software NFC library. The supported NFC hardware devices are + the ACS ACR122(U) NFC reader and various NFC-dongles. In principle all + hardware based on the NXP PN53x NFC Controller chip is supported. + +Package: nfc-tools +Architecture: any +Depends: libnfc0 +Description: Near Field Communication tools + NFC tools are provide by libnfc team to be able to use NFC devices + "out-of-the-box". diff --git a/debian/copyright b/debian/copyright new file mode 100644 index 0000000..ce98d8a --- /dev/null +++ b/debian/copyright @@ -0,0 +1,28 @@ +This package was debianized by Romuald Conty on +Wed, 22 Apr 2009 10:42:42 +0100. + +It was downloaded from: http://www.libnfc.org/ + +Copyright (C) 2005-2007 by Harald Welte +Copyright (C) 2009 by Roel Verdult + +License: GNU General Public License version 3 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License version 3 + as published by the Free Software Foundation + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +On Debian GNU/Linux systems, the complete text of the GNU General Public +License, version 3, can be found in `/usr/share/common-licenses/GPL-3'. + +The Debian packaging is (C) 2009, Romuald Conty and +is licensed under the GPL, see `/usr/share/common-licenses/GPL'. diff --git a/debian/libnfc-dev.install b/debian/libnfc-dev.install new file mode 100644 index 0000000..35dfe53 --- /dev/null +++ b/debian/libnfc-dev.install @@ -0,0 +1,3 @@ +debian/tmp/usr/include/libnfc +debian/tmp/usr/lib/libnfc.{a,la,so} +debian/tmp/usr/lib/pkgconfig/libnfc.pc diff --git a/debian/libnfc0.install b/debian/libnfc0.install new file mode 100644 index 0000000..5ae0ff4 --- /dev/null +++ b/debian/libnfc0.install @@ -0,0 +1 @@ +debian/tmp/usr/lib/libnfc.so.* diff --git a/debian/nfc-tools.install b/debian/nfc-tools.install new file mode 100644 index 0000000..7459505 --- /dev/null +++ b/debian/nfc-tools.install @@ -0,0 +1 @@ +debian/tmp/usr/bin/nfc-* diff --git a/debian/rules b/debian/rules new file mode 100755 index 0000000..114ab44 --- /dev/null +++ b/debian/rules @@ -0,0 +1,4 @@ +#!/usr/bin/make -f +include /usr/share/cdbs/1/rules/debhelper.mk +include /usr/share/cdbs/1/class/autotools.mk + From 3b452f01859383a308034537137fc71806c438b4 Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Wed, 17 Jun 2009 16:07:32 +0000 Subject: [PATCH 13/29] =?UTF-8?q?Fix=20configure=20script=20on=20FreeBSD?= =?UTF-8?q?=20(Many=20thanks=20to=20Romain=20Tarti=C3=A8re)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- configure.ac | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index a1701c9..422e22c 100644 --- a/configure.ac +++ b/configure.ac @@ -1,4 +1,4 @@ -AC_INIT(libnfc, 1.1.1, roel@libnfc.org) +AC_INIT(libnfc, 1.1.1, info@libnfc.org) AC_CONFIG_HEADER(config.h) AM_INIT_AUTOMAKE @@ -51,7 +51,7 @@ AC_SUBST([DEBUG_CFLAGS]) # pkg-config check for ## libusb PKG_CHECK_MODULES(LIBUSB, libusb, [WITH_USB=1], [WITH_USB=0]) -if test "$WITH_USB" == "0" ; then +if test "$WITH_USB" = "0" ; then AC_MSG_ERROR([libusb is mandatory.]) fi AC_SUBST(LIBUSB_LIBS) @@ -61,7 +61,7 @@ AC_SUBST(LIBUSB_CFLAGS) if test "x$enable_pcsc_lite" = "xyes" then PKG_CHECK_MODULES(LIBPCSCLITE, libpcsclite, [WITH_PCSC=1], [WITH_PCSC=0]) - if test "$WITH_PCSC" == "0" ; then + if test "$WITH_PCSC" = "0" ; then AC_MSG_ERROR([libpcsclite is mandatory.]) fi AC_SUBST(LIBPCSCLITE_LIBS) From 645796d0b2623914684aaaaf5ef349602b409ee8 Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Thu, 25 Jun 2009 14:53:48 +0000 Subject: [PATCH 14/29] Add a simple script to simplify releases creation. --- make_release.sh | 58 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100755 make_release.sh diff --git a/make_release.sh b/make_release.sh new file mode 100755 index 0000000..3c6fc7e --- /dev/null +++ b/make_release.sh @@ -0,0 +1,58 @@ +#! /bin/sh + +# Stop script on first error. +set -e + +# Retrieve libnfc version from configure.ac +LIBNFC_VERSION=$(grep AC_INIT configure.ac | sed 's/^.*(\(.*\))/\1/g' | awk -F', ' '{ print $2 }') + +## Easiest part: GNU/linux, BSD and other POSIX systems. +LIBNFC_AUTOTOOLS_ARCHIVE=libnfc-$LIBNFC_VERSION.tar.gz + +if [ ! -f $LIBNFC_AUTOTOOLS_ARCHIVE ]; then + # First, we can test archive using "distcheck" + ./autogen.sh && make distcheck && make distclean + + # We are ready to make a good autotools release. + ./autogen.sh && make dist +else + echo "Autotooled archive (GNU/Linux, BSD, etc.) is already done: skipped." +fi + +# MacOSX part (will be removed if we can use autotools under MacOSX) +LIBNFC_MACOSX_DIR=libnfc-$LIBNFC_VERSION-macosx +LIBNFC_MACOSX_ARCHIVE=$LIBNFC_MACOSX_DIR.tgz + +if [ ! -f $LIBNFC_MACOSX_ARCHIVE ]; then + if [ -d $LIBNFC_MACOSX_DIR ]; then + rm -rf $LIBNFC_MACOSX_DIR + fi + mkdir -p $LIBNFC_MACOSX_DIR + cp src/*.c $LIBNFC_MACOSX_DIR/ + cp src/*.h $LIBNFC_MACOSX_DIR/ + cp macosx/* $LIBNFC_MACOSX_DIR/ + tar cvzf $LIBNFC_MACOSX_DIR.tgz $LIBNFC_MACOSX_DIR + rm -rf $LIBNFC_MACOSX_DIR +else + echo "MacOSX archive is already done: skipped." +fi + +# Windows part +LIBNFC_WINDOWS_DIR=libnfc-$LIBNFC_VERSION-windows +LIBNFC_WINDOWS_ARCHIVE=$LIBNFC_WINDOWS_DIR.zip + +if [ ! -f $LIBNFC_WINDOWS_ARCHIVE ]; then + if [ -d $LIBNFC_WINDOWS_DIR ]; then + rm -rf $LIBNFC_WINDOWS_DIR + fi + mkdir -p $LIBNFC_WINDOWS_DIR + cp src/*.c $LIBNFC_WINDOWS_DIR/ + cp src/*.h $LIBNFC_WINDOWS_DIR/ + cp -r win32 $LIBNFC_WINDOWS_DIR/vc-project + find $LIBNFC_WINDOWS_DIR -name ".svn" -type d | xargs rm -rf + zip -r $LIBNFC_WINDOWS_ARCHIVE $LIBNFC_WINDOWS_DIR + rm -rf $LIBNFC_WINDOWS_DIR +else + echo "Windows archive is already done: skipped." +fi + From b110b5b5a904fc48db27edc7d71569e5fe17acd7 Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Thu, 25 Jun 2009 15:17:00 +0000 Subject: [PATCH 15/29] RS232 code rewrote: now we can use it on Windows. --- src/rs232.c | 211 ++++++++++++++++------------------------------------ 1 file changed, 64 insertions(+), 147 deletions(-) diff --git a/src/rs232.c b/src/rs232.c index 533c2f1..e53a7c2 100644 --- a/src/rs232.c +++ b/src/rs232.c @@ -24,7 +24,8 @@ along with this program. If not, see . #include "rs232.h" -#ifndef _WIN32 /* Linux */ +// Test if we are dealing with unix operating systems +#ifndef _WIN32 typedef struct termios term_info; typedef struct { @@ -136,169 +137,85 @@ bool rs232_send(const serial_port sp, const byte* pbtTx, const uint32_t uiTxLen) return (iResult >= 0); } -#else /* windows */ +#else +// The windows serial port implementation +typedef struct { + HANDLE hPort; // Serial port handle + DCB dcb; // Device control settings + COMMTIMEOUTS ct; // Serial port time-out configuration +} serial_port_windows; -HANDLE Cport[16]; - - -char comports[16][10]={"\\\\.\\COM1", "\\\\.\\COM2", "\\\\.\\COM3", "\\\\.\\COM4", - "\\\\.\\COM5", "\\\\.\\COM6", "\\\\.\\COM7", "\\\\.\\COM8", - "\\\\.\\COM9", "\\\\.\\COM10", "\\\\.\\COM11", "\\\\.\\COM12", - "\\\\.\\COM13", "\\\\.\\COM14", "\\\\.\\COM15", "\\\\.\\COM16"}; - -char baudr[64]; - - -int OpenComport(int comport_number, int baudrate) +serial_port rs232_open(const char* pcPortName) { - if((comport_number>15)||(comport_number<0)) + char acPortName[255]; + serial_port_windows* sp = malloc(sizeof(serial_port_windows)); + + // Copy the input "com?" to "\\.\COM?" format + sprintf(acPortName,"\\\\.\\%s",pcPortName); + _strupr(acPortName); + + // Try to open the serial port + sp->hPort = CreateFileA(acPortName,GENERIC_READ|GENERIC_WRITE,NULL,NULL,OPEN_EXISTING,NULL,NULL); + if (sp->hPort == INVALID_HANDLE_VALUE) { - printf("illegal comport number\n"); - return(1); + rs232_close(sp); + return INVALID_SERIAL_PORT; } - switch(baudrate) + // Prepare the device control + memset(&sp->dcb, 0, sizeof(DCB)); + sp->dcb.DCBlength = sizeof(DCB); + if(!BuildCommDCBA("baud=9600 data=8 parity=N stop=1",&sp->dcb)) { - sscanf(baudr,"baud=%d data=8 parity=N stop=1",baudrate); -/* - case 110 : strcpy(baudr, "baud=110 data=8 parity=N stop=1"); - break; - case 300 : strcpy(baudr, "baud=300 data=8 parity=N stop=1"); - break; - case 600 : strcpy(baudr, "baud=600 data=8 parity=N stop=1"); - break; - case 1200 : strcpy(baudr, "baud=1200 data=8 parity=N stop=1"); - break; - case 2400 : strcpy(baudr, "baud=2400 data=8 parity=N stop=1"); - break; - case 4800 : strcpy(baudr, "baud=4800 data=8 parity=N stop=1"); - break; - case 9600 : strcpy(baudr, "baud=9600 data=8 parity=N stop=1"); - break; - case 19200 : strcpy(baudr, "baud=19200 data=8 parity=N stop=1"); - break; - case 38400 : strcpy(baudr, "baud=38400 data=8 parity=N stop=1"); - break; - case 57600 : strcpy(baudr, "baud=57600 data=8 parity=N stop=1"); - break; - case 115200 : strcpy(baudr, "baud=115200 data=8 parity=N stop=1"); - break; - case 128000 : strcpy(baudr, "baud=128000 data=8 parity=N stop=1"); - break; - case 256000 : strcpy(baudr, "baud=256000 data=8 parity=N stop=1"); - break; - default : printf("invalid baudrate\n"); - return(1); - break; -*/ + rs232_close(sp); + return INVALID_SERIAL_PORT; } - Cport[comport_number] = CreateFileA(comports[comport_number], - GENERIC_READ|GENERIC_WRITE, - 0, /* no share */ - NULL, /* no security */ - OPEN_EXISTING, - 0, /* no threads */ - NULL); /* no templates */ - - if(Cport[comport_number]==INVALID_HANDLE_VALUE) + // Update the active serial port + if(!SetCommState(sp->hPort,&sp->dcb)) { - printf("unable to open comport\n"); - return(1); + rs232_close(sp); + return INVALID_SERIAL_PORT; } - DCB port_settings; - memset(&port_settings, 0, sizeof(port_settings)); /* clear the new struct */ - port_settings.DCBlength = sizeof(port_settings); - - if(!BuildCommDCBA(baudr, &port_settings)) - { - printf("unable to set comport dcb settings\n"); - CloseHandle(Cport[comport_number]); - return(1); - } - - if(!SetCommState(Cport[comport_number], &port_settings)) - { - printf("unable to set comport cfg settings\n"); - CloseHandle(Cport[comport_number]); - return(1); - } - - COMMTIMEOUTS Cptimeouts; - - Cptimeouts.ReadIntervalTimeout = MAXDWORD; - Cptimeouts.ReadTotalTimeoutMultiplier = 0; - Cptimeouts.ReadTotalTimeoutConstant = 0; - Cptimeouts.WriteTotalTimeoutMultiplier = 0; - Cptimeouts.WriteTotalTimeoutConstant = 0; - - if(!SetCommTimeouts(Cport[comport_number], &Cptimeouts)) - { - printf("unable to set comport time-out settings\n"); - CloseHandle(Cport[comport_number]); - return(1); - } - - return(0); -} - - -int PollComport(int comport_number, unsigned char *buf, int size) -{ - int n; - - if(size>4096) size = 4096; - -/* added the void pointer cast, otherwise gcc will complain about */ -/* "warning: dereferencing type-punned pointer will break strict aliasing rules" */ - - ReadFile(Cport[comport_number], buf, size, (LPDWORD)((void *)&n), NULL); - - return(n); -} - - -int SendByte(int comport_number, unsigned char byte) -{ - int n; - - WriteFile(Cport[comport_number], &byte, 1, (LPDWORD)((void *)&n), NULL); - - if(n<0) return(1); - - return(0); -} - - -int SendBuf(int comport_number, unsigned char *buf, int size) -{ - int n; - - if(WriteFile(Cport[comport_number], buf, size, (LPDWORD)((void *)&n), NULL)) - { - return(n); - } - - return(-1); -} - -bool rs232_cts(const serial_port sp); -{ - int status; + sp->ct.ReadIntervalTimeout = 30; + sp->ct.ReadTotalTimeoutMultiplier = 0; + sp->ct.ReadTotalTimeoutConstant = 0; + sp->ct.WriteTotalTimeoutMultiplier = 0; + sp->ct.WriteTotalTimeoutConstant = 0; - GetCommModemStatus(Cport[comport_number], (LPDWORD)((void *)&status)); - - if(status&MS_CTS_ON) return(1); - else return(0); + if(!SetCommTimeouts(sp->hPort,&sp->ct)) + { + rs232_close(sp); + return INVALID_SERIAL_PORT; + } + + return sp; } - -void CloseComport(int comport_number) +void rs232_close(const serial_port sp) { - CloseHandle(Cport[comport_number]); + CloseHandle(((serial_port_windows*)sp)->hPort); + free(sp); } +bool rs232_cts(const serial_port sp) +{ + DWORD dwStatus; + if (GetCommModemStatus(((serial_port_windows*)sp)->hPort,&dwStatus) == NULL) return false; + return (dwStatus & MS_CTS_ON); +} + +bool rs232_receive(const serial_port sp, byte* pbtRx, uint32_t* puiRxLen) +{ + return (ReadFile(((serial_port_windows*)sp)->hPort,pbtRx,*puiRxLen,(LPDWORD)puiRxLen,NULL) != NULL); +} + +bool rs232_send(const serial_port sp, const byte* pbtTx, const uint32_t uiTxLen) +{ + DWORD dwTxLen; + return (WriteFile(((serial_port_windows*)sp)->hPort,pbtTx,uiTxLen,&dwTxLen,NULL) != NULL); +} #endif From c8adb1036af250e4f9704938bab3e57489da44fd Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Fri, 26 Jun 2009 09:05:25 +0000 Subject: [PATCH 16/29] License have changed from GPLv3 to LGPLv3. --- LICENSE | 165 ++++++++++++ LICENSE.TXT | 674 ----------------------------------------------- src/anticol.c | 6 +- src/bitutils.c | 6 +- src/bitutils.h | 6 +- src/defines.h | 6 +- src/dev_acr122.c | 7 +- src/dev_acr122.h | 6 +- src/dev_arygon.c | 6 +- src/dev_arygon.h | 6 +- src/dev_pn531.c | 10 +- src/dev_pn531.h | 6 +- src/dev_pn533.c | 10 +- src/dev_pn533.h | 6 +- src/devices.h | 6 +- src/emulate.c | 6 +- src/libnfc.c | 6 +- src/libnfc.h | 6 +- src/list.c | 6 +- src/mftool.c | 6 +- src/mifaretag.h | 6 +- src/relay.c | 6 +- src/rs232.c | 20 +- src/rs232.h | 12 +- src/types.h | 6 +- 25 files changed, 252 insertions(+), 754 deletions(-) create mode 100644 LICENSE delete mode 100644 LICENSE.TXT diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..cca7fc2 --- /dev/null +++ b/LICENSE @@ -0,0 +1,165 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. diff --git a/LICENSE.TXT b/LICENSE.TXT deleted file mode 100644 index 818433e..0000000 --- a/LICENSE.TXT +++ /dev/null @@ -1,674 +0,0 @@ - GNU GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The GNU General Public License is a free, copyleft license for -software and other kinds of works. - - The licenses for most software and other practical works are designed -to take away your freedom to share and change the works. By contrast, -the GNU General Public License is intended to guarantee your freedom to -share and change all versions of a program--to make sure it remains free -software for all its users. We, the Free Software Foundation, use the -GNU General Public License for most of our software; it applies also to -any other work released this way by its authors. You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -them if you wish), that you receive source code or can get it if you -want it, that you can change the software or use pieces of it in new -free programs, and that you know you can do these things. - - To protect your rights, we need to prevent others from denying you -these rights or asking you to surrender the rights. Therefore, you have -certain responsibilities if you distribute copies of the software, or if -you modify it: responsibilities to respect the freedom of others. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must pass on to the recipients the same -freedoms that you received. You must make sure that they, too, receive -or can get the source code. And you must show them these terms so they -know their rights. - - Developers that use the GNU GPL protect your rights with two steps: -(1) assert copyright on the software, and (2) offer you this License -giving you legal permission to copy, distribute and/or modify it. - - For the developers' and authors' protection, the GPL clearly explains -that there is no warranty for this free software. For both users' and -authors' sake, the GPL requires that modified versions be marked as -changed, so that their problems will not be attributed erroneously to -authors of previous versions. - - Some devices are designed to deny users access to install or run -modified versions of the software inside them, although the manufacturer -can do so. This is fundamentally incompatible with the aim of -protecting users' freedom to change the software. The systematic -pattern of such abuse occurs in the area of products for individuals to -use, which is precisely where it is most unacceptable. Therefore, we -have designed this version of the GPL to prohibit the practice for those -products. If such problems arise substantially in other domains, we -stand ready to extend this provision to those domains in future versions -of the GPL, as needed to protect the freedom of users. - - Finally, every program is threatened constantly by software patents. -States should not allow patents to restrict development and use of -software on general-purpose computers, but in those that do, we wish to -avoid the special danger that patents applied to a free program could -make it effectively proprietary. To prevent this, the GPL assures that -patents cannot be used to render the program non-free. - - The precise terms and conditions for copying, distribution and -modification follow. - - TERMS AND CONDITIONS - - 0. Definitions. - - "This License" refers to version 3 of the GNU General Public License. - - "Copyright" also means copyright-like laws that apply to other kinds of -works, such as semiconductor masks. - - "The Program" refers to any copyrightable work licensed under this -License. Each licensee is addressed as "you". "Licensees" and -"recipients" may be individuals or organizations. - - To "modify" a work means to copy from or adapt all or part of the work -in a fashion requiring copyright permission, other than the making of an -exact copy. The resulting work is called a "modified version" of the -earlier work or a work "based on" the earlier work. - - A "covered work" means either the unmodified Program or a work based -on the Program. - - To "propagate" a work means to do anything with it that, without -permission, would make you directly or secondarily liable for -infringement under applicable copyright law, except executing it on a -computer or modifying a private copy. Propagation includes copying, -distribution (with or without modification), making available to the -public, and in some countries other activities as well. - - To "convey" a work means any kind of propagation that enables other -parties to make or receive copies. Mere interaction with a user through -a computer network, with no transfer of a copy, is not conveying. - - An interactive user interface displays "Appropriate Legal Notices" -to the extent that it includes a convenient and prominently visible -feature that (1) displays an appropriate copyright notice, and (2) -tells the user that there is no warranty for the work (except to the -extent that warranties are provided), that licensees may convey the -work under this License, and how to view a copy of this License. If -the interface presents a list of user commands or options, such as a -menu, a prominent item in the list meets this criterion. - - 1. Source Code. - - The "source code" for a work means the preferred form of the work -for making modifications to it. "Object code" means any non-source -form of a work. - - A "Standard Interface" means an interface that either is an official -standard defined by a recognized standards body, or, in the case of -interfaces specified for a particular programming language, one that -is widely used among developers working in that language. - - The "System Libraries" of an executable work include anything, other -than the work as a whole, that (a) is included in the normal form of -packaging a Major Component, but which is not part of that Major -Component, and (b) serves only to enable use of the work with that -Major Component, or to implement a Standard Interface for which an -implementation is available to the public in source code form. A -"Major Component", in this context, means a major essential component -(kernel, window system, and so on) of the specific operating system -(if any) on which the executable work runs, or a compiler used to -produce the work, or an object code interpreter used to run it. - - The "Corresponding Source" for a work in object code form means all -the source code needed to generate, install, and (for an executable -work) run the object code and to modify the work, including scripts to -control those activities. However, it does not include the work's -System Libraries, or general-purpose tools or generally available free -programs which are used unmodified in performing those activities but -which are not part of the work. For example, Corresponding Source -includes interface definition files associated with source files for -the work, and the source code for shared libraries and dynamically -linked subprograms that the work is specifically designed to require, -such as by intimate data communication or control flow between those -subprograms and other parts of the work. - - The Corresponding Source need not include anything that users -can regenerate automatically from other parts of the Corresponding -Source. - - The Corresponding Source for a work in source code form is that -same work. - - 2. Basic Permissions. - - All rights granted under this License are granted for the term of -copyright on the Program, and are irrevocable provided the stated -conditions are met. This License explicitly affirms your unlimited -permission to run the unmodified Program. The output from running a -covered work is covered by this License only if the output, given its -content, constitutes a covered work. This License acknowledges your -rights of fair use or other equivalent, as provided by copyright law. - - You may make, run and propagate covered works that you do not -convey, without conditions so long as your license otherwise remains -in force. You may convey covered works to others for the sole purpose -of having them make modifications exclusively for you, or provide you -with facilities for running those works, provided that you comply with -the terms of this License in conveying all material for which you do -not control copyright. Those thus making or running the covered works -for you must do so exclusively on your behalf, under your direction -and control, on terms that prohibit them from making any copies of -your copyrighted material outside their relationship with you. - - Conveying under any other circumstances is permitted solely under -the conditions stated below. Sublicensing is not allowed; section 10 -makes it unnecessary. - - 3. Protecting Users' Legal Rights From Anti-Circumvention Law. - - No covered work shall be deemed part of an effective technological -measure under any applicable law fulfilling obligations under article -11 of the WIPO copyright treaty adopted on 20 December 1996, or -similar laws prohibiting or restricting circumvention of such -measures. - - When you convey a covered work, you waive any legal power to forbid -circumvention of technological measures to the extent such circumvention -is effected by exercising rights under this License with respect to -the covered work, and you disclaim any intention to limit operation or -modification of the work as a means of enforcing, against the work's -users, your or third parties' legal rights to forbid circumvention of -technological measures. - - 4. Conveying Verbatim Copies. - - You may convey verbatim copies of the Program's source code as you -receive it, in any medium, provided that you conspicuously and -appropriately publish on each copy an appropriate copyright notice; -keep intact all notices stating that this License and any -non-permissive terms added in accord with section 7 apply to the code; -keep intact all notices of the absence of any warranty; and give all -recipients a copy of this License along with the Program. - - You may charge any price or no price for each copy that you convey, -and you may offer support or warranty protection for a fee. - - 5. Conveying Modified Source Versions. - - You may convey a work based on the Program, or the modifications to -produce it from the Program, in the form of source code under the -terms of section 4, provided that you also meet all of these conditions: - - a) The work must carry prominent notices stating that you modified - it, and giving a relevant date. - - b) The work must carry prominent notices stating that it is - released under this License and any conditions added under section - 7. This requirement modifies the requirement in section 4 to - "keep intact all notices". - - c) You must license the entire work, as a whole, under this - License to anyone who comes into possession of a copy. This - License will therefore apply, along with any applicable section 7 - additional terms, to the whole of the work, and all its parts, - regardless of how they are packaged. This License gives no - permission to license the work in any other way, but it does not - invalidate such permission if you have separately received it. - - d) If the work has interactive user interfaces, each must display - Appropriate Legal Notices; however, if the Program has interactive - interfaces that do not display Appropriate Legal Notices, your - work need not make them do so. - - A compilation of a covered work with other separate and independent -works, which are not by their nature extensions of the covered work, -and which are not combined with it such as to form a larger program, -in or on a volume of a storage or distribution medium, is called an -"aggregate" if the compilation and its resulting copyright are not -used to limit the access or legal rights of the compilation's users -beyond what the individual works permit. Inclusion of a covered work -in an aggregate does not cause this License to apply to the other -parts of the aggregate. - - 6. Conveying Non-Source Forms. - - You may convey a covered work in object code form under the terms -of sections 4 and 5, provided that you also convey the -machine-readable Corresponding Source under the terms of this License, -in one of these ways: - - a) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by the - Corresponding Source fixed on a durable physical medium - customarily used for software interchange. - - b) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by a - written offer, valid for at least three years and valid for as - long as you offer spare parts or customer support for that product - model, to give anyone who possesses the object code either (1) a - copy of the Corresponding Source for all the software in the - product that is covered by this License, on a durable physical - medium customarily used for software interchange, for a price no - more than your reasonable cost of physically performing this - conveying of source, or (2) access to copy the - Corresponding Source from a network server at no charge. - - c) Convey individual copies of the object code with a copy of the - written offer to provide the Corresponding Source. This - alternative is allowed only occasionally and noncommercially, and - only if you received the object code with such an offer, in accord - with subsection 6b. - - d) Convey the object code by offering access from a designated - place (gratis or for a charge), and offer equivalent access to the - Corresponding Source in the same way through the same place at no - further charge. You need not require recipients to copy the - Corresponding Source along with the object code. If the place to - copy the object code is a network server, the Corresponding Source - may be on a different server (operated by you or a third party) - that supports equivalent copying facilities, provided you maintain - clear directions next to the object code saying where to find the - Corresponding Source. Regardless of what server hosts the - Corresponding Source, you remain obligated to ensure that it is - available for as long as needed to satisfy these requirements. - - e) Convey the object code using peer-to-peer transmission, provided - you inform other peers where the object code and Corresponding - Source of the work are being offered to the general public at no - charge under subsection 6d. - - A separable portion of the object code, whose source code is excluded -from the Corresponding Source as a System Library, need not be -included in conveying the object code work. - - A "User Product" is either (1) a "consumer product", which means any -tangible personal property which is normally used for personal, family, -or household purposes, or (2) anything designed or sold for incorporation -into a dwelling. In determining whether a product is a consumer product, -doubtful cases shall be resolved in favor of coverage. For a particular -product received by a particular user, "normally used" refers to a -typical or common use of that class of product, regardless of the status -of the particular user or of the way in which the particular user -actually uses, or expects or is expected to use, the product. A product -is a consumer product regardless of whether the product has substantial -commercial, industrial or non-consumer uses, unless such uses represent -the only significant mode of use of the product. - - "Installation Information" for a User Product means any methods, -procedures, authorization keys, or other information required to install -and execute modified versions of a covered work in that User Product from -a modified version of its Corresponding Source. The information must -suffice to ensure that the continued functioning of the modified object -code is in no case prevented or interfered with solely because -modification has been made. - - If you convey an object code work under this section in, or with, or -specifically for use in, a User Product, and the conveying occurs as -part of a transaction in which the right of possession and use of the -User Product is transferred to the recipient in perpetuity or for a -fixed term (regardless of how the transaction is characterized), the -Corresponding Source conveyed under this section must be accompanied -by the Installation Information. But this requirement does not apply -if neither you nor any third party retains the ability to install -modified object code on the User Product (for example, the work has -been installed in ROM). - - The requirement to provide Installation Information does not include a -requirement to continue to provide support service, warranty, or updates -for a work that has been modified or installed by the recipient, or for -the User Product in which it has been modified or installed. Access to a -network may be denied when the modification itself materially and -adversely affects the operation of the network or violates the rules and -protocols for communication across the network. - - Corresponding Source conveyed, and Installation Information provided, -in accord with this section must be in a format that is publicly -documented (and with an implementation available to the public in -source code form), and must require no special password or key for -unpacking, reading or copying. - - 7. Additional Terms. - - "Additional permissions" are terms that supplement the terms of this -License by making exceptions from one or more of its conditions. -Additional permissions that are applicable to the entire Program shall -be treated as though they were included in this License, to the extent -that they are valid under applicable law. If additional permissions -apply only to part of the Program, that part may be used separately -under those permissions, but the entire Program remains governed by -this License without regard to the additional permissions. - - When you convey a copy of a covered work, you may at your option -remove any additional permissions from that copy, or from any part of -it. (Additional permissions may be written to require their own -removal in certain cases when you modify the work.) You may place -additional permissions on material, added by you to a covered work, -for which you have or can give appropriate copyright permission. - - Notwithstanding any other provision of this License, for material you -add to a covered work, you may (if authorized by the copyright holders of -that material) supplement the terms of this License with terms: - - a) Disclaiming warranty or limiting liability differently from the - terms of sections 15 and 16 of this License; or - - b) Requiring preservation of specified reasonable legal notices or - author attributions in that material or in the Appropriate Legal - Notices displayed by works containing it; or - - c) Prohibiting misrepresentation of the origin of that material, or - requiring that modified versions of such material be marked in - reasonable ways as different from the original version; or - - d) Limiting the use for publicity purposes of names of licensors or - authors of the material; or - - e) Declining to grant rights under trademark law for use of some - trade names, trademarks, or service marks; or - - f) Requiring indemnification of licensors and authors of that - material by anyone who conveys the material (or modified versions of - it) with contractual assumptions of liability to the recipient, for - any liability that these contractual assumptions directly impose on - those licensors and authors. - - All other non-permissive additional terms are considered "further -restrictions" within the meaning of section 10. If the Program as you -received it, or any part of it, contains a notice stating that it is -governed by this License along with a term that is a further -restriction, you may remove that term. If a license document contains -a further restriction but permits relicensing or conveying under this -License, you may add to a covered work material governed by the terms -of that license document, provided that the further restriction does -not survive such relicensing or conveying. - - If you add terms to a covered work in accord with this section, you -must place, in the relevant source files, a statement of the -additional terms that apply to those files, or a notice indicating -where to find the applicable terms. - - Additional terms, permissive or non-permissive, may be stated in the -form of a separately written license, or stated as exceptions; -the above requirements apply either way. - - 8. Termination. - - You may not propagate or modify a covered work except as expressly -provided under this License. Any attempt otherwise to propagate or -modify it is void, and will automatically terminate your rights under -this License (including any patent licenses granted under the third -paragraph of section 11). - - However, if you cease all violation of this License, then your -license from a particular copyright holder is reinstated (a) -provisionally, unless and until the copyright holder explicitly and -finally terminates your license, and (b) permanently, if the copyright -holder fails to notify you of the violation by some reasonable means -prior to 60 days after the cessation. - - Moreover, your license from a particular copyright holder is -reinstated permanently if the copyright holder notifies you of the -violation by some reasonable means, this is the first time you have -received notice of violation of this License (for any work) from that -copyright holder, and you cure the violation prior to 30 days after -your receipt of the notice. - - Termination of your rights under this section does not terminate the -licenses of parties who have received copies or rights from you under -this License. If your rights have been terminated and not permanently -reinstated, you do not qualify to receive new licenses for the same -material under section 10. - - 9. Acceptance Not Required for Having Copies. - - You are not required to accept this License in order to receive or -run a copy of the Program. Ancillary propagation of a covered work -occurring solely as a consequence of using peer-to-peer transmission -to receive a copy likewise does not require acceptance. However, -nothing other than this License grants you permission to propagate or -modify any covered work. These actions infringe copyright if you do -not accept this License. Therefore, by modifying or propagating a -covered work, you indicate your acceptance of this License to do so. - - 10. Automatic Licensing of Downstream Recipients. - - Each time you convey a covered work, the recipient automatically -receives a license from the original licensors, to run, modify and -propagate that work, subject to this License. You are not responsible -for enforcing compliance by third parties with this License. - - An "entity transaction" is a transaction transferring control of an -organization, or substantially all assets of one, or subdividing an -organization, or merging organizations. If propagation of a covered -work results from an entity transaction, each party to that -transaction who receives a copy of the work also receives whatever -licenses to the work the party's predecessor in interest had or could -give under the previous paragraph, plus a right to possession of the -Corresponding Source of the work from the predecessor in interest, if -the predecessor has it or can get it with reasonable efforts. - - You may not impose any further restrictions on the exercise of the -rights granted or affirmed under this License. For example, you may -not impose a license fee, royalty, or other charge for exercise of -rights granted under this License, and you may not initiate litigation -(including a cross-claim or counterclaim in a lawsuit) alleging that -any patent claim is infringed by making, using, selling, offering for -sale, or importing the Program or any portion of it. - - 11. Patents. - - A "contributor" is a copyright holder who authorizes use under this -License of the Program or a work on which the Program is based. The -work thus licensed is called the contributor's "contributor version". - - A contributor's "essential patent claims" are all patent claims -owned or controlled by the contributor, whether already acquired or -hereafter acquired, that would be infringed by some manner, permitted -by this License, of making, using, or selling its contributor version, -but do not include claims that would be infringed only as a -consequence of further modification of the contributor version. For -purposes of this definition, "control" includes the right to grant -patent sublicenses in a manner consistent with the requirements of -this License. - - Each contributor grants you a non-exclusive, worldwide, royalty-free -patent license under the contributor's essential patent claims, to -make, use, sell, offer for sale, import and otherwise run, modify and -propagate the contents of its contributor version. - - In the following three paragraphs, a "patent license" is any express -agreement or commitment, however denominated, not to enforce a patent -(such as an express permission to practice a patent or covenant not to -sue for patent infringement). To "grant" such a patent license to a -party means to make such an agreement or commitment not to enforce a -patent against the party. - - If you convey a covered work, knowingly relying on a patent license, -and the Corresponding Source of the work is not available for anyone -to copy, free of charge and under the terms of this License, through a -publicly available network server or other readily accessible means, -then you must either (1) cause the Corresponding Source to be so -available, or (2) arrange to deprive yourself of the benefit of the -patent license for this particular work, or (3) arrange, in a manner -consistent with the requirements of this License, to extend the patent -license to downstream recipients. "Knowingly relying" means you have -actual knowledge that, but for the patent license, your conveying the -covered work in a country, or your recipient's use of the covered work -in a country, would infringe one or more identifiable patents in that -country that you have reason to believe are valid. - - If, pursuant to or in connection with a single transaction or -arrangement, you convey, or propagate by procuring conveyance of, a -covered work, and grant a patent license to some of the parties -receiving the covered work authorizing them to use, propagate, modify -or convey a specific copy of the covered work, then the patent license -you grant is automatically extended to all recipients of the covered -work and works based on it. - - A patent license is "discriminatory" if it does not include within -the scope of its coverage, prohibits the exercise of, or is -conditioned on the non-exercise of one or more of the rights that are -specifically granted under this License. You may not convey a covered -work if you are a party to an arrangement with a third party that is -in the business of distributing software, under which you make payment -to the third party based on the extent of your activity of conveying -the work, and under which the third party grants, to any of the -parties who would receive the covered work from you, a discriminatory -patent license (a) in connection with copies of the covered work -conveyed by you (or copies made from those copies), or (b) primarily -for and in connection with specific products or compilations that -contain the covered work, unless you entered into that arrangement, -or that patent license was granted, prior to 28 March 2007. - - Nothing in this License shall be construed as excluding or limiting -any implied license or other defenses to infringement that may -otherwise be available to you under applicable patent law. - - 12. No Surrender of Others' Freedom. - - If conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot convey a -covered work so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you may -not convey it at all. For example, if you agree to terms that obligate you -to collect a royalty for further conveying from those to whom you convey -the Program, the only way you could satisfy both those terms and this -License would be to refrain entirely from conveying the Program. - - 13. Use with the GNU Affero General Public License. - - Notwithstanding any other provision of this License, you have -permission to link or combine any covered work with a work licensed -under version 3 of the GNU Affero General Public License into a single -combined work, and to convey the resulting work. The terms of this -License will continue to apply to the part which is the covered work, -but the special requirements of the GNU Affero General Public License, -section 13, concerning interaction through a network will apply to the -combination as such. - - 14. Revised Versions of this License. - - The Free Software Foundation may publish revised and/or new versions of -the GNU General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - - Each version is given a distinguishing version number. If the -Program specifies that a certain numbered version of the GNU General -Public License "or any later version" applies to it, you have the -option of following the terms and conditions either of that numbered -version or of any later version published by the Free Software -Foundation. If the Program does not specify a version number of the -GNU General Public License, you may choose any version ever published -by the Free Software Foundation. - - If the Program specifies that a proxy can decide which future -versions of the GNU General Public License can be used, that proxy's -public statement of acceptance of a version permanently authorizes you -to choose that version for the Program. - - Later license versions may give you additional or different -permissions. However, no additional obligations are imposed on any -author or copyright holder as a result of your choosing to follow a -later version. - - 15. Disclaimer of Warranty. - - THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY -APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT -HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY -OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, -THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM -IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF -ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. Limitation of Liability. - - IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS -THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY -GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE -USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF -DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD -PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), -EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF -SUCH DAMAGES. - - 17. Interpretation of Sections 15 and 16. - - If the disclaimer of warranty and limitation of liability provided -above cannot be given local legal effect according to their terms, -reviewing courts shall apply local law that most closely approximates -an absolute waiver of all civil liability in connection with the -Program, unless a warranty or assumption of liability accompanies a -copy of the Program in return for a fee. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -state the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . - -Also add information on how to contact you by electronic and paper mail. - - If the program does terminal interaction, make it output a short -notice like this when it starts in an interactive mode: - - Copyright (C) - This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, your program's commands -might be different; for a GUI interface, you would use an "about box". - - You should also get your employer (if you work as a programmer) or school, -if any, to sign a "copyright disclaimer" for the program, if necessary. -For more information on this, and how to apply and follow the GNU GPL, see -. - - The GNU General Public License does not permit incorporating your program -into proprietary programs. If your program is a subroutine library, you -may consider it more useful to permit linking proprietary applications with -the library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. But first, please read -. diff --git a/src/anticol.c b/src/anticol.c index 24e1d98..4bc8d83 100644 --- a/src/anticol.c +++ b/src/anticol.c @@ -4,7 +4,7 @@ Public platform independent Near Field Communication (NFC) library Copyright (C) 2009, Roel Verdult This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by +it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. @@ -13,8 +13,8 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with this program. If not, see . +You should have received a copy of the GNU Lesser General Public License +along with this program. If not, see */ diff --git a/src/bitutils.c b/src/bitutils.c index 6ce6e19..a2aa292 100644 --- a/src/bitutils.c +++ b/src/bitutils.c @@ -4,7 +4,7 @@ Public platform independent Near Field Communication (NFC) library Copyright (C) 2009, Roel Verdult This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by +it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. @@ -13,8 +13,8 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with this program. If not, see . +You should have received a copy of the GNU Lesser General Public License +along with this program. If not, see */ diff --git a/src/bitutils.h b/src/bitutils.h index 8cd6d97..b8021e0 100644 --- a/src/bitutils.h +++ b/src/bitutils.h @@ -4,7 +4,7 @@ Public platform independent Near Field Communication (NFC) library Copyright (C) 2009, Roel Verdult This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by +it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. @@ -13,8 +13,8 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with this program. If not, see . +You should have received a copy of the GNU Lesser General Public License +along with this program. If not, see */ diff --git a/src/defines.h b/src/defines.h index 4641be7..8792560 100644 --- a/src/defines.h +++ b/src/defines.h @@ -4,7 +4,7 @@ Public platform independent Near Field Communication (NFC) library Copyright (C) 2009, Roel Verdult This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by +it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. @@ -13,8 +13,8 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with this program. If not, see . +You should have received a copy of the GNU Lesser General Public License +along with this program. If not, see */ diff --git a/src/dev_acr122.c b/src/dev_acr122.c index 22b6eb1..bfab8ff 100644 --- a/src/dev_acr122.c +++ b/src/dev_acr122.c @@ -4,7 +4,7 @@ Public platform independent Near Field Communication (NFC) library Copyright (C) 2009, Roel Verdult This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by +it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. @@ -13,10 +13,11 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with this program. If not, see . +You should have received a copy of the GNU Lesser General Public License +along with this program. If not, see */ + #include "dev_acr122.h" #include diff --git a/src/dev_acr122.h b/src/dev_acr122.h index 4771b3e..3fd6b48 100644 --- a/src/dev_acr122.h +++ b/src/dev_acr122.h @@ -4,7 +4,7 @@ Public platform independent Near Field Communication (NFC) library Copyright (C) 2009, Roel Verdult This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by +it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. @@ -13,8 +13,8 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with this program. If not, see . +You should have received a copy of the GNU Lesser General Public License +along with this program. If not, see */ diff --git a/src/dev_arygon.c b/src/dev_arygon.c index d93a814..717427c 100644 --- a/src/dev_arygon.c +++ b/src/dev_arygon.c @@ -4,7 +4,7 @@ Public platform independent Near Field Communication (NFC) library Copyright (C) 2009, Roel Verdult This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by +it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. @@ -13,8 +13,8 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with this program. If not, see . +You should have received a copy of the GNU Lesser General Public License +along with this program. If not, see */ diff --git a/src/dev_arygon.h b/src/dev_arygon.h index 1a5cc8f..8408dea 100644 --- a/src/dev_arygon.h +++ b/src/dev_arygon.h @@ -4,7 +4,7 @@ Public platform independent Near Field Communication (NFC) library Copyright (C) 2009, Roel Verdult This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by +it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. @@ -13,8 +13,8 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with this program. If not, see . +You should have received a copy of the GNU Lesser General Public License +along with this program. If not, see */ diff --git a/src/dev_pn531.c b/src/dev_pn531.c index ad2d5fd..f83ff35 100644 --- a/src/dev_pn531.c +++ b/src/dev_pn531.c @@ -4,7 +4,7 @@ Public platform independent Near Field Communication (NFC) library Copyright (C) 2009, Roel Verdult This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by +it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. @@ -13,11 +13,13 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with this program. If not, see . +You should have received a copy of the GNU Lesser General Public License +along with this program. If not, see +*/ + +/* Thanks to d18c7db and Okko for example code - */ #include diff --git a/src/dev_pn531.h b/src/dev_pn531.h index 14dcf4f..5b7ed98 100644 --- a/src/dev_pn531.h +++ b/src/dev_pn531.h @@ -4,7 +4,7 @@ Public platform independent Near Field Communication (NFC) library Copyright (C) 2009, Roel Verdult This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by +it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. @@ -13,8 +13,8 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with this program. If not, see . +You should have received a copy of the GNU Lesser General Public License +along with this program. If not, see */ diff --git a/src/dev_pn533.c b/src/dev_pn533.c index 148b3b8..97f24f7 100644 --- a/src/dev_pn533.c +++ b/src/dev_pn533.c @@ -4,7 +4,7 @@ Public platform independent Near Field Communication (NFC) library Copyright (C) 2009, Roel Verdult This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by +it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. @@ -13,11 +13,13 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with this program. If not, see . +You should have received a copy of the GNU Lesser General Public License +along with this program. If not, see +*/ + +/* Thanks to d18c7db and Okko for example code - */ #include "defines.h" diff --git a/src/dev_pn533.h b/src/dev_pn533.h index 3ceb975..619247c 100644 --- a/src/dev_pn533.h +++ b/src/dev_pn533.h @@ -4,7 +4,7 @@ Public platform independent Near Field Communication (NFC) library Copyright (C) 2009, Roel Verdult This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by +it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. @@ -13,8 +13,8 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with this program. If not, see . +You should have received a copy of the GNU Lesser General Public License +along with this program. If not, see */ diff --git a/src/devices.h b/src/devices.h index 8a98d68..330cebc 100644 --- a/src/devices.h +++ b/src/devices.h @@ -4,7 +4,7 @@ Public platform independent Near Field Communication (NFC) library Copyright (C) 2009, Roel Verdult This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by +it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. @@ -13,8 +13,8 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with this program. If not, see . +You should have received a copy of the GNU Lesser General Public License +along with this program. If not, see */ diff --git a/src/emulate.c b/src/emulate.c index 029ca8f..afd1348 100644 --- a/src/emulate.c +++ b/src/emulate.c @@ -4,7 +4,7 @@ Public platform independent Near Field Communication (NFC) library Copyright (C) 2009, Roel Verdult This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by +it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. @@ -13,8 +13,8 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with this program. If not, see . +You should have received a copy of the GNU Lesser General Public License +along with this program. If not, see */ diff --git a/src/libnfc.c b/src/libnfc.c index c737449..d857a2a 100644 --- a/src/libnfc.c +++ b/src/libnfc.c @@ -4,7 +4,7 @@ Public platform independent Near Field Communication (NFC) library Copyright (C) 2009, Roel Verdult This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by +it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. @@ -13,8 +13,8 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with this program. If not, see . +You should have received a copy of the GNU Lesser General Public License +along with this program. If not, see */ diff --git a/src/libnfc.h b/src/libnfc.h index 39e4393..48b3a69 100644 --- a/src/libnfc.h +++ b/src/libnfc.h @@ -4,7 +4,7 @@ Public platform independent Near Field Communication (NFC) library Copyright (C) 2009, Roel Verdult This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by +it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. @@ -13,8 +13,8 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with this program. If not, see . +You should have received a copy of the GNU Lesser General Public License +along with this program. If not, see */ diff --git a/src/list.c b/src/list.c index 4fdd151..808c886 100644 --- a/src/list.c +++ b/src/list.c @@ -4,7 +4,7 @@ Public platform independent Near Field Communication (NFC) library Copyright (C) 2009, Roel Verdult This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by +it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. @@ -13,8 +13,8 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with this program. If not, see . +You should have received a copy of the GNU Lesser General Public License +along with this program. If not, see */ diff --git a/src/mftool.c b/src/mftool.c index ec8ff69..315c0aa 100644 --- a/src/mftool.c +++ b/src/mftool.c @@ -4,7 +4,7 @@ Public platform independent Near Field Communication (NFC) library Copyright (C) 2009, Roel Verdult This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by +it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. @@ -13,8 +13,8 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with this program. If not, see . +You should have received a copy of the GNU Lesser General Public License +along with this program. If not, see */ diff --git a/src/mifaretag.h b/src/mifaretag.h index b07e43d..ae62c0a 100644 --- a/src/mifaretag.h +++ b/src/mifaretag.h @@ -4,7 +4,7 @@ Public platform independent Near Field Communication (NFC) library Copyright (C) 2009, Roel Verdult This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by +it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. @@ -13,8 +13,8 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with this program. If not, see . +You should have received a copy of the GNU Lesser General Public License +along with this program. If not, see */ diff --git a/src/relay.c b/src/relay.c index a942cc7..092f39c 100644 --- a/src/relay.c +++ b/src/relay.c @@ -4,7 +4,7 @@ Public platform independent Near Field Communication (NFC) library Copyright (C) 2009, Roel Verdult This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by +it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. @@ -13,8 +13,8 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with this program. If not, see . +You should have received a copy of the GNU Lesser General Public License +along with this program. If not, see */ diff --git a/src/rs232.c b/src/rs232.c index e53a7c2..ffe395f 100644 --- a/src/rs232.c +++ b/src/rs232.c @@ -4,21 +4,23 @@ Public platform independent Near Field Communication (NFC) library Copyright (C) 2009, Roel Verdult This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by +it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . - - Based on rs232-code written by Teunis van Beelen - available: http://www.teuniz.net/RS-232/index.html - + +You should have received a copy of the GNU Lesser General Public License +along with this program. If not, see + +*/ + +/* +Based on rs232-code written by Teunis van Beelen +available: http://www.teuniz.net/RS-232/index.html */ diff --git a/src/rs232.h b/src/rs232.h index b78dc4c..c4280f2 100644 --- a/src/rs232.h +++ b/src/rs232.h @@ -4,18 +4,18 @@ Public platform independent Near Field Communication (NFC) library Copyright (C) 2009, Roel Verdult This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by +it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . - + +You should have received a copy of the GNU Lesser General Public License +along with this program. If not, see + */ #ifndef _LIBNFC_RS232_H_ diff --git a/src/types.h b/src/types.h index 0b69de5..1e5c452 100644 --- a/src/types.h +++ b/src/types.h @@ -4,7 +4,7 @@ Public platform independent Near Field Communication (NFC) library Copyright (C) 2009, Roel Verdult This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by +it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. @@ -13,8 +13,8 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with this program. If not, see . +You should have received a copy of the GNU Lesser General Public License +along with this program. If not, see */ From 0da43b6731fa76cf80a71c5c901a507ec734e7c3 Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Fri, 26 Jun 2009 09:22:26 +0000 Subject: [PATCH 17/29] Add LICENSE and README files to releases produce by make_release.sh script. Fix MacOSX Makefile embedded in MacOSX archive by make_release.sh. Replace COPYING content with LGPLv3. --- COPYING | 827 ++++++++++-------------------------------------- make_release.sh | 26 ++ 2 files changed, 185 insertions(+), 668 deletions(-) diff --git a/COPYING b/COPYING index 94a9ed0..cca7fc2 100644 --- a/COPYING +++ b/COPYING @@ -1,674 +1,165 @@ - GNU GENERAL PUBLIC LICENSE + GNU LESSER GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. - Preamble - - The GNU General Public License is a free, copyleft license for -software and other kinds of works. - - The licenses for most software and other practical works are designed -to take away your freedom to share and change the works. By contrast, -the GNU General Public License is intended to guarantee your freedom to -share and change all versions of a program--to make sure it remains free -software for all its users. We, the Free Software Foundation, use the -GNU General Public License for most of our software; it applies also to -any other work released this way by its authors. You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -them if you wish), that you receive source code or can get it if you -want it, that you can change the software or use pieces of it in new -free programs, and that you know you can do these things. - - To protect your rights, we need to prevent others from denying you -these rights or asking you to surrender the rights. Therefore, you have -certain responsibilities if you distribute copies of the software, or if -you modify it: responsibilities to respect the freedom of others. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must pass on to the recipients the same -freedoms that you received. You must make sure that they, too, receive -or can get the source code. And you must show them these terms so they -know their rights. - - Developers that use the GNU GPL protect your rights with two steps: -(1) assert copyright on the software, and (2) offer you this License -giving you legal permission to copy, distribute and/or modify it. - - For the developers' and authors' protection, the GPL clearly explains -that there is no warranty for this free software. For both users' and -authors' sake, the GPL requires that modified versions be marked as -changed, so that their problems will not be attributed erroneously to -authors of previous versions. - - Some devices are designed to deny users access to install or run -modified versions of the software inside them, although the manufacturer -can do so. This is fundamentally incompatible with the aim of -protecting users' freedom to change the software. The systematic -pattern of such abuse occurs in the area of products for individuals to -use, which is precisely where it is most unacceptable. Therefore, we -have designed this version of the GPL to prohibit the practice for those -products. If such problems arise substantially in other domains, we -stand ready to extend this provision to those domains in future versions -of the GPL, as needed to protect the freedom of users. - - Finally, every program is threatened constantly by software patents. -States should not allow patents to restrict development and use of -software on general-purpose computers, but in those that do, we wish to -avoid the special danger that patents applied to a free program could -make it effectively proprietary. To prevent this, the GPL assures that -patents cannot be used to render the program non-free. - - The precise terms and conditions for copying, distribution and -modification follow. - - TERMS AND CONDITIONS - - 0. Definitions. - - "This License" refers to version 3 of the GNU General Public License. - - "Copyright" also means copyright-like laws that apply to other kinds of -works, such as semiconductor masks. - - "The Program" refers to any copyrightable work licensed under this -License. Each licensee is addressed as "you". "Licensees" and -"recipients" may be individuals or organizations. - - To "modify" a work means to copy from or adapt all or part of the work -in a fashion requiring copyright permission, other than the making of an -exact copy. The resulting work is called a "modified version" of the -earlier work or a work "based on" the earlier work. - - A "covered work" means either the unmodified Program or a work based -on the Program. - - To "propagate" a work means to do anything with it that, without -permission, would make you directly or secondarily liable for -infringement under applicable copyright law, except executing it on a -computer or modifying a private copy. Propagation includes copying, -distribution (with or without modification), making available to the -public, and in some countries other activities as well. - - To "convey" a work means any kind of propagation that enables other -parties to make or receive copies. Mere interaction with a user through -a computer network, with no transfer of a copy, is not conveying. - - An interactive user interface displays "Appropriate Legal Notices" -to the extent that it includes a convenient and prominently visible -feature that (1) displays an appropriate copyright notice, and (2) -tells the user that there is no warranty for the work (except to the -extent that warranties are provided), that licensees may convey the -work under this License, and how to view a copy of this License. If -the interface presents a list of user commands or options, such as a -menu, a prominent item in the list meets this criterion. - - 1. Source Code. - - The "source code" for a work means the preferred form of the work -for making modifications to it. "Object code" means any non-source -form of a work. - - A "Standard Interface" means an interface that either is an official -standard defined by a recognized standards body, or, in the case of -interfaces specified for a particular programming language, one that -is widely used among developers working in that language. - - The "System Libraries" of an executable work include anything, other -than the work as a whole, that (a) is included in the normal form of -packaging a Major Component, but which is not part of that Major -Component, and (b) serves only to enable use of the work with that -Major Component, or to implement a Standard Interface for which an -implementation is available to the public in source code form. A -"Major Component", in this context, means a major essential component -(kernel, window system, and so on) of the specific operating system -(if any) on which the executable work runs, or a compiler used to -produce the work, or an object code interpreter used to run it. - - The "Corresponding Source" for a work in object code form means all -the source code needed to generate, install, and (for an executable -work) run the object code and to modify the work, including scripts to -control those activities. However, it does not include the work's -System Libraries, or general-purpose tools or generally available free -programs which are used unmodified in performing those activities but -which are not part of the work. For example, Corresponding Source -includes interface definition files associated with source files for -the work, and the source code for shared libraries and dynamically -linked subprograms that the work is specifically designed to require, -such as by intimate data communication or control flow between those -subprograms and other parts of the work. - - The Corresponding Source need not include anything that users -can regenerate automatically from other parts of the Corresponding -Source. - - The Corresponding Source for a work in source code form is that -same work. - - 2. Basic Permissions. - - All rights granted under this License are granted for the term of -copyright on the Program, and are irrevocable provided the stated -conditions are met. This License explicitly affirms your unlimited -permission to run the unmodified Program. The output from running a -covered work is covered by this License only if the output, given its -content, constitutes a covered work. This License acknowledges your -rights of fair use or other equivalent, as provided by copyright law. - - You may make, run and propagate covered works that you do not -convey, without conditions so long as your license otherwise remains -in force. You may convey covered works to others for the sole purpose -of having them make modifications exclusively for you, or provide you -with facilities for running those works, provided that you comply with -the terms of this License in conveying all material for which you do -not control copyright. Those thus making or running the covered works -for you must do so exclusively on your behalf, under your direction -and control, on terms that prohibit them from making any copies of -your copyrighted material outside their relationship with you. - - Conveying under any other circumstances is permitted solely under -the conditions stated below. Sublicensing is not allowed; section 10 -makes it unnecessary. - - 3. Protecting Users' Legal Rights From Anti-Circumvention Law. - - No covered work shall be deemed part of an effective technological -measure under any applicable law fulfilling obligations under article -11 of the WIPO copyright treaty adopted on 20 December 1996, or -similar laws prohibiting or restricting circumvention of such -measures. - - When you convey a covered work, you waive any legal power to forbid -circumvention of technological measures to the extent such circumvention -is effected by exercising rights under this License with respect to -the covered work, and you disclaim any intention to limit operation or -modification of the work as a means of enforcing, against the work's -users, your or third parties' legal rights to forbid circumvention of -technological measures. - - 4. Conveying Verbatim Copies. - - You may convey verbatim copies of the Program's source code as you -receive it, in any medium, provided that you conspicuously and -appropriately publish on each copy an appropriate copyright notice; -keep intact all notices stating that this License and any -non-permissive terms added in accord with section 7 apply to the code; -keep intact all notices of the absence of any warranty; and give all -recipients a copy of this License along with the Program. - - You may charge any price or no price for each copy that you convey, -and you may offer support or warranty protection for a fee. - - 5. Conveying Modified Source Versions. - - You may convey a work based on the Program, or the modifications to -produce it from the Program, in the form of source code under the -terms of section 4, provided that you also meet all of these conditions: - - a) The work must carry prominent notices stating that you modified - it, and giving a relevant date. - - b) The work must carry prominent notices stating that it is - released under this License and any conditions added under section - 7. This requirement modifies the requirement in section 4 to - "keep intact all notices". - - c) You must license the entire work, as a whole, under this - License to anyone who comes into possession of a copy. This - License will therefore apply, along with any applicable section 7 - additional terms, to the whole of the work, and all its parts, - regardless of how they are packaged. This License gives no - permission to license the work in any other way, but it does not - invalidate such permission if you have separately received it. - - d) If the work has interactive user interfaces, each must display - Appropriate Legal Notices; however, if the Program has interactive - interfaces that do not display Appropriate Legal Notices, your - work need not make them do so. - - A compilation of a covered work with other separate and independent -works, which are not by their nature extensions of the covered work, -and which are not combined with it such as to form a larger program, -in or on a volume of a storage or distribution medium, is called an -"aggregate" if the compilation and its resulting copyright are not -used to limit the access or legal rights of the compilation's users -beyond what the individual works permit. Inclusion of a covered work -in an aggregate does not cause this License to apply to the other -parts of the aggregate. - - 6. Conveying Non-Source Forms. - - You may convey a covered work in object code form under the terms -of sections 4 and 5, provided that you also convey the -machine-readable Corresponding Source under the terms of this License, -in one of these ways: - - a) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by the - Corresponding Source fixed on a durable physical medium - customarily used for software interchange. - - b) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by a - written offer, valid for at least three years and valid for as - long as you offer spare parts or customer support for that product - model, to give anyone who possesses the object code either (1) a - copy of the Corresponding Source for all the software in the - product that is covered by this License, on a durable physical - medium customarily used for software interchange, for a price no - more than your reasonable cost of physically performing this - conveying of source, or (2) access to copy the - Corresponding Source from a network server at no charge. - - c) Convey individual copies of the object code with a copy of the - written offer to provide the Corresponding Source. This - alternative is allowed only occasionally and noncommercially, and - only if you received the object code with such an offer, in accord - with subsection 6b. - - d) Convey the object code by offering access from a designated - place (gratis or for a charge), and offer equivalent access to the - Corresponding Source in the same way through the same place at no - further charge. You need not require recipients to copy the - Corresponding Source along with the object code. If the place to - copy the object code is a network server, the Corresponding Source - may be on a different server (operated by you or a third party) - that supports equivalent copying facilities, provided you maintain - clear directions next to the object code saying where to find the - Corresponding Source. Regardless of what server hosts the - Corresponding Source, you remain obligated to ensure that it is - available for as long as needed to satisfy these requirements. - - e) Convey the object code using peer-to-peer transmission, provided - you inform other peers where the object code and Corresponding - Source of the work are being offered to the general public at no - charge under subsection 6d. - - A separable portion of the object code, whose source code is excluded -from the Corresponding Source as a System Library, need not be -included in conveying the object code work. - - A "User Product" is either (1) a "consumer product", which means any -tangible personal property which is normally used for personal, family, -or household purposes, or (2) anything designed or sold for incorporation -into a dwelling. In determining whether a product is a consumer product, -doubtful cases shall be resolved in favor of coverage. For a particular -product received by a particular user, "normally used" refers to a -typical or common use of that class of product, regardless of the status -of the particular user or of the way in which the particular user -actually uses, or expects or is expected to use, the product. A product -is a consumer product regardless of whether the product has substantial -commercial, industrial or non-consumer uses, unless such uses represent -the only significant mode of use of the product. - - "Installation Information" for a User Product means any methods, -procedures, authorization keys, or other information required to install -and execute modified versions of a covered work in that User Product from -a modified version of its Corresponding Source. The information must -suffice to ensure that the continued functioning of the modified object -code is in no case prevented or interfered with solely because -modification has been made. - - If you convey an object code work under this section in, or with, or -specifically for use in, a User Product, and the conveying occurs as -part of a transaction in which the right of possession and use of the -User Product is transferred to the recipient in perpetuity or for a -fixed term (regardless of how the transaction is characterized), the -Corresponding Source conveyed under this section must be accompanied -by the Installation Information. But this requirement does not apply -if neither you nor any third party retains the ability to install -modified object code on the User Product (for example, the work has -been installed in ROM). - - The requirement to provide Installation Information does not include a -requirement to continue to provide support service, warranty, or updates -for a work that has been modified or installed by the recipient, or for -the User Product in which it has been modified or installed. Access to a -network may be denied when the modification itself materially and -adversely affects the operation of the network or violates the rules and -protocols for communication across the network. - - Corresponding Source conveyed, and Installation Information provided, -in accord with this section must be in a format that is publicly -documented (and with an implementation available to the public in -source code form), and must require no special password or key for -unpacking, reading or copying. - - 7. Additional Terms. - - "Additional permissions" are terms that supplement the terms of this -License by making exceptions from one or more of its conditions. -Additional permissions that are applicable to the entire Program shall -be treated as though they were included in this License, to the extent -that they are valid under applicable law. If additional permissions -apply only to part of the Program, that part may be used separately -under those permissions, but the entire Program remains governed by -this License without regard to the additional permissions. - - When you convey a copy of a covered work, you may at your option -remove any additional permissions from that copy, or from any part of -it. (Additional permissions may be written to require their own -removal in certain cases when you modify the work.) You may place -additional permissions on material, added by you to a covered work, -for which you have or can give appropriate copyright permission. - - Notwithstanding any other provision of this License, for material you -add to a covered work, you may (if authorized by the copyright holders of -that material) supplement the terms of this License with terms: - - a) Disclaiming warranty or limiting liability differently from the - terms of sections 15 and 16 of this License; or - - b) Requiring preservation of specified reasonable legal notices or - author attributions in that material or in the Appropriate Legal - Notices displayed by works containing it; or - - c) Prohibiting misrepresentation of the origin of that material, or - requiring that modified versions of such material be marked in - reasonable ways as different from the original version; or - - d) Limiting the use for publicity purposes of names of licensors or - authors of the material; or - - e) Declining to grant rights under trademark law for use of some - trade names, trademarks, or service marks; or - - f) Requiring indemnification of licensors and authors of that - material by anyone who conveys the material (or modified versions of - it) with contractual assumptions of liability to the recipient, for - any liability that these contractual assumptions directly impose on - those licensors and authors. - - All other non-permissive additional terms are considered "further -restrictions" within the meaning of section 10. If the Program as you -received it, or any part of it, contains a notice stating that it is -governed by this License along with a term that is a further -restriction, you may remove that term. If a license document contains -a further restriction but permits relicensing or conveying under this -License, you may add to a covered work material governed by the terms -of that license document, provided that the further restriction does -not survive such relicensing or conveying. - - If you add terms to a covered work in accord with this section, you -must place, in the relevant source files, a statement of the -additional terms that apply to those files, or a notice indicating -where to find the applicable terms. - - Additional terms, permissive or non-permissive, may be stated in the -form of a separately written license, or stated as exceptions; -the above requirements apply either way. - - 8. Termination. - - You may not propagate or modify a covered work except as expressly -provided under this License. Any attempt otherwise to propagate or -modify it is void, and will automatically terminate your rights under -this License (including any patent licenses granted under the third -paragraph of section 11). - - However, if you cease all violation of this License, then your -license from a particular copyright holder is reinstated (a) -provisionally, unless and until the copyright holder explicitly and -finally terminates your license, and (b) permanently, if the copyright -holder fails to notify you of the violation by some reasonable means -prior to 60 days after the cessation. - - Moreover, your license from a particular copyright holder is -reinstated permanently if the copyright holder notifies you of the -violation by some reasonable means, this is the first time you have -received notice of violation of this License (for any work) from that -copyright holder, and you cure the violation prior to 30 days after -your receipt of the notice. - - Termination of your rights under this section does not terminate the -licenses of parties who have received copies or rights from you under -this License. If your rights have been terminated and not permanently -reinstated, you do not qualify to receive new licenses for the same -material under section 10. - - 9. Acceptance Not Required for Having Copies. - - You are not required to accept this License in order to receive or -run a copy of the Program. Ancillary propagation of a covered work -occurring solely as a consequence of using peer-to-peer transmission -to receive a copy likewise does not require acceptance. However, -nothing other than this License grants you permission to propagate or -modify any covered work. These actions infringe copyright if you do -not accept this License. Therefore, by modifying or propagating a -covered work, you indicate your acceptance of this License to do so. - - 10. Automatic Licensing of Downstream Recipients. - - Each time you convey a covered work, the recipient automatically -receives a license from the original licensors, to run, modify and -propagate that work, subject to this License. You are not responsible -for enforcing compliance by third parties with this License. - - An "entity transaction" is a transaction transferring control of an -organization, or substantially all assets of one, or subdividing an -organization, or merging organizations. If propagation of a covered -work results from an entity transaction, each party to that -transaction who receives a copy of the work also receives whatever -licenses to the work the party's predecessor in interest had or could -give under the previous paragraph, plus a right to possession of the -Corresponding Source of the work from the predecessor in interest, if -the predecessor has it or can get it with reasonable efforts. - - You may not impose any further restrictions on the exercise of the -rights granted or affirmed under this License. For example, you may -not impose a license fee, royalty, or other charge for exercise of -rights granted under this License, and you may not initiate litigation -(including a cross-claim or counterclaim in a lawsuit) alleging that -any patent claim is infringed by making, using, selling, offering for -sale, or importing the Program or any portion of it. - - 11. Patents. - - A "contributor" is a copyright holder who authorizes use under this -License of the Program or a work on which the Program is based. The -work thus licensed is called the contributor's "contributor version". - - A contributor's "essential patent claims" are all patent claims -owned or controlled by the contributor, whether already acquired or -hereafter acquired, that would be infringed by some manner, permitted -by this License, of making, using, or selling its contributor version, -but do not include claims that would be infringed only as a -consequence of further modification of the contributor version. For -purposes of this definition, "control" includes the right to grant -patent sublicenses in a manner consistent with the requirements of -this License. - - Each contributor grants you a non-exclusive, worldwide, royalty-free -patent license under the contributor's essential patent claims, to -make, use, sell, offer for sale, import and otherwise run, modify and -propagate the contents of its contributor version. - - In the following three paragraphs, a "patent license" is any express -agreement or commitment, however denominated, not to enforce a patent -(such as an express permission to practice a patent or covenant not to -sue for patent infringement). To "grant" such a patent license to a -party means to make such an agreement or commitment not to enforce a -patent against the party. - - If you convey a covered work, knowingly relying on a patent license, -and the Corresponding Source of the work is not available for anyone -to copy, free of charge and under the terms of this License, through a -publicly available network server or other readily accessible means, -then you must either (1) cause the Corresponding Source to be so -available, or (2) arrange to deprive yourself of the benefit of the -patent license for this particular work, or (3) arrange, in a manner -consistent with the requirements of this License, to extend the patent -license to downstream recipients. "Knowingly relying" means you have -actual knowledge that, but for the patent license, your conveying the -covered work in a country, or your recipient's use of the covered work -in a country, would infringe one or more identifiable patents in that -country that you have reason to believe are valid. - - If, pursuant to or in connection with a single transaction or -arrangement, you convey, or propagate by procuring conveyance of, a -covered work, and grant a patent license to some of the parties -receiving the covered work authorizing them to use, propagate, modify -or convey a specific copy of the covered work, then the patent license -you grant is automatically extended to all recipients of the covered -work and works based on it. - - A patent license is "discriminatory" if it does not include within -the scope of its coverage, prohibits the exercise of, or is -conditioned on the non-exercise of one or more of the rights that are -specifically granted under this License. You may not convey a covered -work if you are a party to an arrangement with a third party that is -in the business of distributing software, under which you make payment -to the third party based on the extent of your activity of conveying -the work, and under which the third party grants, to any of the -parties who would receive the covered work from you, a discriminatory -patent license (a) in connection with copies of the covered work -conveyed by you (or copies made from those copies), or (b) primarily -for and in connection with specific products or compilations that -contain the covered work, unless you entered into that arrangement, -or that patent license was granted, prior to 28 March 2007. - - Nothing in this License shall be construed as excluding or limiting -any implied license or other defenses to infringement that may -otherwise be available to you under applicable patent law. - - 12. No Surrender of Others' Freedom. - - If conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot convey a -covered work so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you may -not convey it at all. For example, if you agree to terms that obligate you -to collect a royalty for further conveying from those to whom you convey -the Program, the only way you could satisfy both those terms and this -License would be to refrain entirely from conveying the Program. - - 13. Use with the GNU Affero General Public License. - - Notwithstanding any other provision of this License, you have -permission to link or combine any covered work with a work licensed -under version 3 of the GNU Affero General Public License into a single -combined work, and to convey the resulting work. The terms of this -License will continue to apply to the part which is the covered work, -but the special requirements of the GNU Affero General Public License, -section 13, concerning interaction through a network will apply to the -combination as such. - - 14. Revised Versions of this License. - - The Free Software Foundation may publish revised and/or new versions of -the GNU General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - - Each version is given a distinguishing version number. If the -Program specifies that a certain numbered version of the GNU General -Public License "or any later version" applies to it, you have the -option of following the terms and conditions either of that numbered -version or of any later version published by the Free Software -Foundation. If the Program does not specify a version number of the -GNU General Public License, you may choose any version ever published -by the Free Software Foundation. - - If the Program specifies that a proxy can decide which future -versions of the GNU General Public License can be used, that proxy's -public statement of acceptance of a version permanently authorizes you -to choose that version for the Program. - - Later license versions may give you additional or different -permissions. However, no additional obligations are imposed on any -author or copyright holder as a result of your choosing to follow a -later version. - - 15. Disclaimer of Warranty. - - THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY -APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT -HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY -OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, -THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM -IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF -ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. Limitation of Liability. - - IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS -THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY -GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE -USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF -DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD -PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), -EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF -SUCH DAMAGES. - - 17. Interpretation of Sections 15 and 16. - - If the disclaimer of warranty and limitation of liability provided -above cannot be given local legal effect according to their terms, -reviewing courts shall apply local law that most closely approximates -an absolute waiver of all civil liability in connection with the -Program, unless a warranty or assumption of liability accompanies a -copy of the Program in return for a fee. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -state the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . - -Also add information on how to contact you by electronic and paper mail. - - If the program does terminal interaction, make it output a short -notice like this when it starts in an interactive mode: - - Copyright (C) - This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, your program's commands -might be different; for a GUI interface, you would use an "about box". - - You should also get your employer (if you work as a programmer) or school, -if any, to sign a "copyright disclaimer" for the program, if necessary. -For more information on this, and how to apply and follow the GNU GPL, see -. - - The GNU General Public License does not permit incorporating your program -into proprietary programs. If your program is a subroutine library, you -may consider it more useful to permit linking proprietary applications with -the library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. But first, please read -. + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. diff --git a/make_release.sh b/make_release.sh index 3c6fc7e..e427628 100755 --- a/make_release.sh +++ b/make_release.sh @@ -27,10 +27,23 @@ if [ ! -f $LIBNFC_MACOSX_ARCHIVE ]; then if [ -d $LIBNFC_MACOSX_DIR ]; then rm -rf $LIBNFC_MACOSX_DIR fi + mkdir -p $LIBNFC_MACOSX_DIR + + # Copy sources cp src/*.c $LIBNFC_MACOSX_DIR/ cp src/*.h $LIBNFC_MACOSX_DIR/ + + # Copy important files + cp LICENSE $LIBNFC_MACOSX_DIR/ + cp README $LIBNFC_MACOSX_DIR/ + + # Copy MacOSX specific files cp macosx/* $LIBNFC_MACOSX_DIR/ + # Fix MacOSX Makefile + sed -i 's/LIBNFC_PATH=\.\./LIBNFC_PATH=./' Makefile + + # Build archive tar cvzf $LIBNFC_MACOSX_DIR.tgz $LIBNFC_MACOSX_DIR rm -rf $LIBNFC_MACOSX_DIR else @@ -45,11 +58,24 @@ if [ ! -f $LIBNFC_WINDOWS_ARCHIVE ]; then if [ -d $LIBNFC_WINDOWS_DIR ]; then rm -rf $LIBNFC_WINDOWS_DIR fi + mkdir -p $LIBNFC_WINDOWS_DIR + + # Copy sources cp src/*.c $LIBNFC_WINDOWS_DIR/ cp src/*.h $LIBNFC_WINDOWS_DIR/ + + # Copy important files + cp LICENSE $LIBNFC_WINDOWS_DIR/ + cp README $LIBNFC_WINDOWS_DIR/ + + # Copy Visual C++ project files cp -r win32 $LIBNFC_WINDOWS_DIR/vc-project + + # Remove svn stuff find $LIBNFC_WINDOWS_DIR -name ".svn" -type d | xargs rm -rf + + # Build archive zip -r $LIBNFC_WINDOWS_ARCHIVE $LIBNFC_WINDOWS_DIR rm -rf $LIBNFC_WINDOWS_DIR else From bb4d79735af005d08bf59774b39cbb0d13bc85e0 Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Fri, 26 Jun 2009 15:10:01 +0000 Subject: [PATCH 18/29] Add manpages for nfc-tools. --- man/nfc-anticol.1 | 30 +++++++++++++++++++++++++ man/nfc-emulate.1 | 31 ++++++++++++++++++++++++++ man/nfc-list.1 | 27 ++++++++++++++++++++++ man/nfc-mftool.1 | 57 +++++++++++++++++++++++++++++++++++++++++++++++ man/nfc-relay.1 | 28 +++++++++++++++++++++++ 5 files changed, 173 insertions(+) create mode 100644 man/nfc-anticol.1 create mode 100644 man/nfc-emulate.1 create mode 100644 man/nfc-list.1 create mode 100644 man/nfc-mftool.1 create mode 100644 man/nfc-relay.1 diff --git a/man/nfc-anticol.1 b/man/nfc-anticol.1 new file mode 100644 index 0000000..83f47be --- /dev/null +++ b/man/nfc-anticol.1 @@ -0,0 +1,30 @@ +.TH NFC-ANTICOL 1 "June 26, 2009" +.SH NAME +nfc-anticol \- Demonstration NFC anti-collison command line tool based on libnfc +.SH SYNOPSIS +.B nfc-anticol +.SH DESCRIPTION +.B nfc-anticol +is an anti-collision demonstration tool for ISO/IEC 14443-A tags, performed +by custom constructed frames. The first frame must be a short frame which +is only 7 bits long. Commercial SDK's often don't support a feature to send +frames that are not a multiple of 8 bits (1 byte) long. +This makes it impossible to do the anti-collision yourself. +The developer has to rely on closed proprietary software and should hope it does not contain vulnerabilities during the anti-collision phase. +Performing the anti-collision using custom frames could protect against a malicious tag that, for example, violates the standard by sending frames with unsupported lengths. + +.SH BUGS +Please report any bugs on the +.B libnfc +forum at +.BR http://www.libnfc.org/community/ "." +.SH LICENCE +.B libnfc +and +.B nfc-tools +are covered by the GNU Lesser General Public License (LGPL), version 3. +.SH AUTHORS +Roel Verdult +.PP +This manual page was written by Romuald Conty . +It is licensed under the terms of the GNU GPL (version 2 or later). diff --git a/man/nfc-emulate.1 b/man/nfc-emulate.1 new file mode 100644 index 0000000..543b81e --- /dev/null +++ b/man/nfc-emulate.1 @@ -0,0 +1,31 @@ +.TH NFC-EMULATE 1 "June 26, 2009" +.SH NAME +nfc-emulate \- NFC target emulation command line tool based on libnfc +.SH SYNOPSIS +.B nfc-emulate +.SH DESCRIPTION +.B nfc-emulate +is an tag emulatation tool. Tag emulation is one of the main added features in NFC. +To avoid abuse of existing systems, manufacturers of the NFC controller intentionally did not +support emulation of custom UID numbers. +The emulate tool demonstrates that this can still be done using transmission of raw-frames. +Fast communication is necessary to in time to respond during the anti-collision protocol. +Using the USB interface gives some timing issues but an embedded microprocessor could +be fast enough to emulate a tag with any UID. This makes it a serious thread +for security systems that rely only on the uniqueness of the UID. + +.SH BUGS +Please report any bugs on the +.B libnfc +forum at +.BR http://www.libnfc.org/community/ "." +.SH LICENCE +.B libnfc +and +.B nfc-tools +are covered by the GNU Lesser General Public License (LGPL), version 3. +.SH AUTHORS +Roel Verdult +.PP +This manual page was written by Romuald Conty . +It is licensed under the terms of the GNU GPL (version 2 or later). diff --git a/man/nfc-list.1 b/man/nfc-list.1 new file mode 100644 index 0000000..673def9 --- /dev/null +++ b/man/nfc-list.1 @@ -0,0 +1,27 @@ +.TH NFC-LIST 1 "June 26, 2009" +.SH NAME +nfc-list \- List NFC targets command line tool based on libnfc +.SH SYNOPSIS +.B nfc-list +.SH DESCRIPTION +.B nfc-list +utility attempts to select available tags in the field. The NFC +controller is used to perform the selection procedure. This is different for each modulation type. +It tries to find a ISO/IEC 14443 type A, type B, Felica or Jewel Topaz tags. +This tool demonstrates that it is possible to setup a simple NFC system using less than 10 lines of code. + +.SH BUGS +Please report any bugs on the +.B libnfc +forum at +.BR http://www.libnfc.org/community/ "." +.SH LICENCE +.B libnfc +and +.B nfc-tools +are covered by the GNU Lesser General Public License (LGPL), version 3. +.SH AUTHORS +Roel Verdult +.PP +This manual page was written by Romuald Conty . +It is licensed under the terms of the GNU GPL (version 2 or later). diff --git a/man/nfc-mftool.1 b/man/nfc-mftool.1 new file mode 100644 index 0000000..c3c17e3 --- /dev/null +++ b/man/nfc-mftool.1 @@ -0,0 +1,57 @@ +.TH NFC-MFTOOL 1 "June 26, 2009" +.SH NAME +nfc-mftool \- Mifare Classic command line tool based on libnfc +.SH SYNOPSIS +.B nfc-mftool +.RI \fR\fBr\fR|\fBw\fR +.RI \fR\fBa\fR|\fBb\fR +.IR KEYS +.IR DUMP + +.SH DESCRIPTION +.B nfc-mftool +is an Mifare Classic tool that allow to read or write +.IR DUMP +file using Mifare keys provide in +.IR KEYS +file. + +The Mifare Classic tag is one of the most widely used RFID tags. +The firmware in the NFC controller supports authenticating, reading and writing to/from Mifare Classic tags. +This tool demonstrate the speed of this library and its easy-of-use. +It possible to read and write the complete content of a Mifare Classic 4KB tag within 1 second. +It uses a binary Mifare Dump File to store the keys and date for all sectors. + +.SH OPTIONS +.BR r " | " w +Perform read from ( +.B r +) or write to ( +.B w +)card. +.TP +.BR a " | " b +Use A or B Mifare keys. +.TP +.IR KEYS +Mifare dump that contain Mifare keys. +.TP +.IR DUMP +Used to write card to file ( r ) or file to card ( w ) + + +.SH BUGS +Please report any bugs on the +.B libnfc +forum at +.BR http://www.libnfc.org/community/ "." +.SH LICENCE +.B libnfc +and +.B nfc-tools +are covered by the GNU Lesser General Public License (LGPL), version 3. +.SH AUTHORS +Roel Verdult +.PP +This manual page was written by Romuald Conty . +It is licensed under the terms of the GNU GPL (version 2 or later). diff --git a/man/nfc-relay.1 b/man/nfc-relay.1 new file mode 100644 index 0000000..559f79b --- /dev/null +++ b/man/nfc-relay.1 @@ -0,0 +1,28 @@ +.TH NFC-RELAY 1 "June 26, 2009" +.SH NAME +nfc-relay \- Relay attack command line tool based on libnfc +.SH SYNOPSIS +.B nfc-relay +.SH DESCRIPTION +.B nfc-relay +is an utility that demonstrates an relay attack. For this it requires two +NFC devices. One will emulate an ISO/IEC 14443 type A tag, while the 2nd +device will act as a reader. The genuine tag can be placed on the 2nd reader and +the tag emulator can be placed close to the original reader. All communication +is now relayed and shown in the screen on real-time. + +.SH BUGS +Please report any bugs on the +.B libnfc +forum at +.BR http://www.libnfc.org/community/ "." +.SH LICENCE +.B libnfc +and +.B nfc-tools +are covered by the GNU Lesser General Public License (LGPL), version 3. +.SH AUTHORS +Roel Verdult +.PP +This manual page was written by Romuald Conty . +It is licensed under the terms of the GNU GPL (version 2 or later). From 3c6f9c3a8c67e340136d44054849d2b768db1718 Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Mon, 29 Jun 2009 06:55:17 +0000 Subject: [PATCH 19/29] Install man pages with binaries. --- configure.ac | 1 + src/Makefile.am | 5 +++++ {man => src}/nfc-anticol.1 | 0 {man => src}/nfc-emulate.1 | 0 {man => src}/nfc-list.1 | 0 {man => src}/nfc-mftool.1 | 0 {man => src}/nfc-relay.1 | 0 7 files changed, 6 insertions(+) rename {man => src}/nfc-anticol.1 (100%) rename {man => src}/nfc-emulate.1 (100%) rename {man => src}/nfc-list.1 (100%) rename {man => src}/nfc-mftool.1 (100%) rename {man => src}/nfc-relay.1 (100%) diff --git a/configure.ac b/configure.ac index 422e22c..c8b20b8 100644 --- a/configure.ac +++ b/configure.ac @@ -74,6 +74,7 @@ CFLAGS="$CFLAGS -std=c99" AC_CONFIG_FILES([ Makefile src/Makefile + man/Makefile libnfc.pc ]) diff --git a/src/Makefile.am b/src/Makefile.am index 5b8eaf2..3b0c88e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -34,3 +34,8 @@ nfc_relay_LDADD = libnfc.la nfc_emulate_SOURCES = emulate.c nfc_emulate_LDADD = libnfc.la + +dist_man_MANS = nfc-anticol.1 nfc-emulate.1 nfc-list.1 nfc-mftool.1 nfc-relay.1 +#dist_man_MANS = $(man_MANS) +#EXTRA_DIST = $(man_MANS) + diff --git a/man/nfc-anticol.1 b/src/nfc-anticol.1 similarity index 100% rename from man/nfc-anticol.1 rename to src/nfc-anticol.1 diff --git a/man/nfc-emulate.1 b/src/nfc-emulate.1 similarity index 100% rename from man/nfc-emulate.1 rename to src/nfc-emulate.1 diff --git a/man/nfc-list.1 b/src/nfc-list.1 similarity index 100% rename from man/nfc-list.1 rename to src/nfc-list.1 diff --git a/man/nfc-mftool.1 b/src/nfc-mftool.1 similarity index 100% rename from man/nfc-mftool.1 rename to src/nfc-mftool.1 diff --git a/man/nfc-relay.1 b/src/nfc-relay.1 similarity index 100% rename from man/nfc-relay.1 rename to src/nfc-relay.1 From d5b1ccea6d60e6808a89483c4a552313e71ea444 Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Mon, 29 Jun 2009 06:58:40 +0000 Subject: [PATCH 20/29] Fix configure.ac --- configure.ac | 1 - 1 file changed, 1 deletion(-) diff --git a/configure.ac b/configure.ac index c8b20b8..422e22c 100644 --- a/configure.ac +++ b/configure.ac @@ -74,7 +74,6 @@ CFLAGS="$CFLAGS -std=c99" AC_CONFIG_FILES([ Makefile src/Makefile - man/Makefile libnfc.pc ]) From 658f24ba3ec8b957e618e52fdbad263b8543208e Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Mon, 29 Jun 2009 08:32:07 +0000 Subject: [PATCH 21/29] Improve MacOSX portability: many thanks to Daniel Macks from #fink irc channel. --- configure.ac | 8 ++++++++ src/dev_acr122.c | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/configure.ac b/configure.ac index 422e22c..dc08e6d 100644 --- a/configure.ac +++ b/configure.ac @@ -60,10 +60,18 @@ AC_SUBST(LIBUSB_CFLAGS) ## libpcsclite if test "x$enable_pcsc_lite" = "xyes" then +case "$host" in + *darwin*) + AC_MSG_WARN(Using darwin PCSC Framework) + LIBPCSCLITE_LIBS=-Wl,-framework,PCSC + ;; + *) PKG_CHECK_MODULES(LIBPCSCLITE, libpcsclite, [WITH_PCSC=1], [WITH_PCSC=0]) if test "$WITH_PCSC" = "0" ; then AC_MSG_ERROR([libpcsclite is mandatory.]) fi + ;; +esac AC_SUBST(LIBPCSCLITE_LIBS) AC_SUBST(LIBPCSCLITE_CFLAGS) fi diff --git a/src/dev_acr122.c b/src/dev_acr122.c index bfab8ff..91c5e0d 100644 --- a/src/dev_acr122.c +++ b/src/dev_acr122.c @@ -25,7 +25,11 @@ along with this program. If not, see #include #include +#ifndef __APPLE__ #include +#else +#include +#endif #include "defines.h" #include "bitutils.h" From db6375511d6e4e216d912390979dc9e492658c84 Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Mon, 29 Jun 2009 08:47:19 +0000 Subject: [PATCH 22/29] Improve MacOSX portability (again): many thanks to Daniel Macks from #fink irc channel. --- configure.ac | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/configure.ac b/configure.ac index dc08e6d..7f4fda1 100644 --- a/configure.ac +++ b/configure.ac @@ -44,7 +44,7 @@ AC_MSG_RESULT($enable_debug) if test x"$enable_debug" = "xyes" then - CFLAGS="$CFLAGS -g -Wall -DDEBUG -pedantic" + CFLAGS="$CFLAGS -g -Wall -DDEBUG -pedantic" fi AC_SUBST([DEBUG_CFLAGS]) @@ -52,7 +52,13 @@ AC_SUBST([DEBUG_CFLAGS]) ## libusb PKG_CHECK_MODULES(LIBUSB, libusb, [WITH_USB=1], [WITH_USB=0]) if test "$WITH_USB" = "0" ; then - AC_MSG_ERROR([libusb is mandatory.]) + AC_PATH_PROG(LIBUSB_CONFIG,libusb-config) + if test "$LIBUSB_CONFIG" = "" ; then + AC_MSG_ERROR([libusb is mandatory.]) + fi + WITH_USB=1 + LIBUSB_CFLAGS=`$LIBUSB_CONFIG --cflags` + LIBUSB_LIBS=`$LIBUSB_CONFIG --libs` fi AC_SUBST(LIBUSB_LIBS) AC_SUBST(LIBUSB_CFLAGS) @@ -66,10 +72,10 @@ case "$host" in LIBPCSCLITE_LIBS=-Wl,-framework,PCSC ;; *) - PKG_CHECK_MODULES(LIBPCSCLITE, libpcsclite, [WITH_PCSC=1], [WITH_PCSC=0]) - if test "$WITH_PCSC" = "0" ; then - AC_MSG_ERROR([libpcsclite is mandatory.]) - fi + PKG_CHECK_MODULES(LIBPCSCLITE, libpcsclite, [WITH_PCSC=1], [WITH_PCSC=0]) + if test "$WITH_PCSC" = "0" ; then + AC_MSG_ERROR([libpcsclite is mandatory.]) + fi ;; esac AC_SUBST(LIBPCSCLITE_LIBS) From 51720401a1093996ce15b5de65a7741ea352895f Mon Sep 17 00:00:00 2001 From: Roel Verdult Date: Tue, 30 Jun 2009 10:53:53 +0000 Subject: [PATCH 23/29] FIX (under MacOSX) ./autogen.sh: line 11: libtoolize: command not found --- autogen.sh | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/autogen.sh b/autogen.sh index 0846992..ca3bdee 100755 --- a/autogen.sh +++ b/autogen.sh @@ -5,10 +5,22 @@ rm -f aclocal.m4 ltmain.sh touch README +LIBTOOLIZE=libtoolize +case `uname -s` in +Darwin) + LIBTOOLIZE=glibtoolize + ACLOCAL_ARGS="-I /opt/local/share/aclocal/" + # SKIP_PCSC="1" + ;; +FreeBSD) + ACLOCAL_ARGS="-I /usr/local/share/aclocal/" + ;; +esac + echo "Running aclocal..." ; aclocal $ACLOCAL_FLAGS || exit 1 echo "Running autoheader..." ; autoheader || exit 1 echo "Running autoconf..." ; autoconf || exit 1 -echo "Running libtoolize..." ; (libtoolize --copy --automake || glibtoolize --automake) || exit 1 +echo "Running libtoolize..." ; $LIBTOOLIZE --copy --automake || exit 1 echo "Running automake..." ; automake --add-missing --copy --gnu || exit 1 if [ -z "$NOCONFIGURE" ]; then From 45b2cfa258e4d9d0c09020305970cdbfd642fc31 Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Tue, 30 Jun 2009 13:30:31 +0000 Subject: [PATCH 24/29] Improve libusb detection if pkg-config is not present. --- configure.ac | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/configure.ac b/configure.ac index 7f4fda1..f769331 100644 --- a/configure.ac +++ b/configure.ac @@ -48,17 +48,22 @@ then fi AC_SUBST([DEBUG_CFLAGS]) -# pkg-config check for ## libusb -PKG_CHECK_MODULES(LIBUSB, libusb, [WITH_USB=1], [WITH_USB=0]) -if test "$WITH_USB" = "0" ; then +if test x"$PKG_CONFIG" = "x"; then AC_PATH_PROG(LIBUSB_CONFIG,libusb-config) - if test "$LIBUSB_CONFIG" = "" ; then - AC_MSG_ERROR([libusb is mandatory.]) + if test x"$LIBUSB_CONFIG" = "x" ; then + WITH_USB=0 + else + LIBUSB_CFLAGS=`$LIBUSB_CONFIG --cflags` + LIBUSB_LIBS=`$LIBUSB_CONFIG --libs` + WITH_USB=1 fi - WITH_USB=1 - LIBUSB_CFLAGS=`$LIBUSB_CONFIG --cflags` - LIBUSB_LIBS=`$LIBUSB_CONFIG --libs` +else + PKG_CHECK_MODULES(LIBUSB, libusb, [WITH_USB=1], [WITH_USB=0]) +fi + +if test x"$WITH_USB" = "x0"; then + AC_MSG_ERROR([libusb is mandatory.]) fi AC_SUBST(LIBUSB_LIBS) AC_SUBST(LIBUSB_CFLAGS) From 3b8a414cd22923357aa987655b3029fcb80ef01d Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Wed, 15 Jul 2009 17:45:38 +0000 Subject: [PATCH 25/29] dev_callbacks_list should only get compiled into the libnfc library, not in every client application. (Thanks to snapdev) --- src/libnfc.c | 2 ++ src/libnfc.h | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libnfc.c b/src/libnfc.c index d857a2a..6026f0f 100644 --- a/src/libnfc.c +++ b/src/libnfc.c @@ -24,6 +24,8 @@ along with this program. If not, see #include #include +#include "devices.h" + #include "bitutils.h" // Registers and symbols masks used to covers parts within a register diff --git a/src/libnfc.h b/src/libnfc.h index 48b3a69..051b603 100644 --- a/src/libnfc.h +++ b/src/libnfc.h @@ -27,7 +27,6 @@ along with this program. If not, see #include "defines.h" #include "types.h" #include "bitutils.h" -#include "devices.h" dev_info* nfc_connect(void); void nfc_disconnect(dev_info* pdi); From e98e7d9415b3f65dfaa1f8e333e9516be4facca0 Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Thu, 16 Jul 2009 12:09:06 +0000 Subject: [PATCH 26/29] Rename "byte" type into "byte_t" type. --- src/anticol.c | 18 +++++----- src/bitutils.c | 52 ++++++++++++++-------------- src/bitutils.h | 18 +++++----- src/defines.h | 6 ++-- src/dev_acr122.c | 20 +++++------ src/dev_acr122.h | 2 +- src/dev_arygon.c | 6 ++-- src/dev_arygon.h | 2 +- src/dev_pn531.c | 18 +++++----- src/dev_pn531.h | 2 +- src/dev_pn533.c | 8 ++--- src/dev_pn533.h | 2 +- src/emulate.c | 10 +++--- src/libnfc.c | 88 ++++++++++++++++++++++++------------------------ src/libnfc.h | 16 ++++----- src/list.c | 2 +- src/mftool.c | 2 +- src/mifaretag.h | 18 +++++----- src/relay.c | 8 ++--- src/rs232.c | 8 ++--- src/rs232.h | 4 +-- src/types.h | 50 ++++++++++++++------------- 22 files changed, 180 insertions(+), 180 deletions(-) diff --git a/src/anticol.c b/src/anticol.c index 4bc8d83..3b7c3ba 100644 --- a/src/anticol.c +++ b/src/anticol.c @@ -30,21 +30,21 @@ along with this program. If not, see #define SAK_FLAG_ATS_SUPPORTED 0x20 -static byte abtRx[MAX_FRAME_LEN]; +static byte_t abtRx[MAX_FRAME_LEN]; static uint32_t uiRxBits; static uint32_t uiRxLen; -static byte abtUid[10]; +static byte_t abtUid[10]; static uint32_t uiUidLen = 4; static dev_info* pdi; // ISO14443A Anti-Collision Commands -byte abtReqa [1] = { 0x26 }; -byte abtSelectAll [2] = { 0x93,0x20 }; -byte abtSelectTag [9] = { 0x93,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }; -byte abtRats [4] = { 0xe0,0x50,0xbc,0xa5 }; -byte abtHalt [4] = { 0x50,0x00,0x57,0xcd }; +byte_t abtReqa [1] = { 0x26 }; +byte_t abtSelectAll [2] = { 0x93,0x20 }; +byte_t abtSelectTag [9] = { 0x93,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }; +byte_t abtRats [4] = { 0xe0,0x50,0xbc,0xa5 }; +byte_t abtHalt [4] = { 0x50,0x00,0x57,0xcd }; -bool transmit_bits(const byte* pbtTx, const uint32_t uiTxBits) +bool transmit_bits(const byte_t* pbtTx, const uint32_t uiTxBits) { // Show transmitted command printf("R: "); print_hex_bits(pbtTx,uiTxBits); @@ -60,7 +60,7 @@ bool transmit_bits(const byte* pbtTx, const uint32_t uiTxBits) } -bool transmit_bytes(const byte* pbtTx, const uint32_t uiTxLen) +bool transmit_bytes(const byte_t* pbtTx, const uint32_t uiTxLen) { // Show transmitted command printf("R: "); print_hex(pbtTx,uiTxLen); diff --git a/src/bitutils.c b/src/bitutils.c index a2aa292..03cf72a 100644 --- a/src/bitutils.c +++ b/src/bitutils.c @@ -22,7 +22,7 @@ along with this program. If not, see #include "bitutils.h" -const static byte OddParity[256] = { +const static byte_t OddParity[256] = { 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, @@ -41,7 +41,7 @@ const static byte OddParity[256] = { 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1 }; -const static byte ByteMirror[256] = { +const static byte_t ByteMirror[256] = { 0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0, 0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0, 0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8, 0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8, 0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, @@ -64,12 +64,12 @@ const static byte ByteMirror[256] = { 0xef, 0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff }; -byte oddparity(const byte bt) +byte_t oddparity(const byte_t bt) { return OddParity[bt]; } -void oddparity_bytes(const byte* pbtData, const uint32_t uiLen, byte* pbtPar) +void oddparity_bytes(const byte_t* pbtData, const uint32_t uiLen, byte_t* pbtPar) { uint32_t uiByteNr; @@ -80,24 +80,12 @@ void oddparity_bytes(const byte* pbtData, const uint32_t uiLen, byte* pbtPar) } } -byte mirror(byte bt) +byte_t mirror(byte_t bt) { return ByteMirror[bt]; } -uint32_t mirror32(uint32_t ui32Bits) -{ - mirror_bytes((byte*)&ui32Bits,4); - return ui32Bits; -} - -uint64_t mirror64(uint64_t ui64Bits) -{ - mirror_bytes((byte*)&ui64Bits,8); - return ui64Bits; -} - -void mirror_bytes(byte *pbts, uint32_t uiLen) +void mirror_bytes(byte_t *pbts, uint32_t uiLen) { uint32_t btNr; @@ -108,6 +96,18 @@ void mirror_bytes(byte *pbts, uint32_t uiLen) } } +uint32_t mirror32(uint32_t ui32Bits) +{ + mirror_bytes((byte_t*)&ui32Bits,4); + return ui32Bits; +} + +uint64_t mirror64(uint64_t ui64Bits) +{ + mirror_bytes((byte_t*)&ui64Bits,8); + return ui64Bits; +} + uint32_t swap_endian32(const void* pui32) { uint32_t ui32N = *((uint32_t*)pui32); @@ -120,23 +120,23 @@ uint64_t swap_endian64(const void* 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)); } -void append_iso14443a_crc(byte* pbtData, uint32_t uiLen) +void append_iso14443a_crc(byte_t* pbtData, uint32_t uiLen) { - byte bt; + byte_t bt; uint32_t wCrc = 0x6363; do { bt = *pbtData++; - bt = (bt^(byte)(wCrc & 0x00FF)); + bt = (bt^(byte_t)(wCrc & 0x00FF)); bt = (bt^(bt<<4)); wCrc = (wCrc >> 8)^((uint32_t)bt << 8)^((uint32_t)bt<<3)^((uint32_t)bt>>4); } while (--uiLen); - *pbtData++ = (byte) (wCrc & 0xFF); - *pbtData = (byte) ((wCrc >> 8) & 0xFF); + *pbtData++ = (byte_t) (wCrc & 0xFF); + *pbtData = (byte_t) ((wCrc >> 8) & 0xFF); } -void print_hex(const byte* pbtData, const uint32_t uiBytes) +void print_hex(const byte_t* pbtData, const uint32_t uiBytes) { uint32_t uiPos; @@ -147,7 +147,7 @@ void print_hex(const byte* pbtData, const uint32_t uiBytes) printf("\n"); } -void print_hex_bits(const byte* pbtData, const uint32_t uiBits) +void print_hex_bits(const byte_t* pbtData, const uint32_t uiBits) { uint32_t uiPos; uint32_t uiBytes = uiBits/8; @@ -163,7 +163,7 @@ void print_hex_bits(const byte* pbtData, const uint32_t uiBits) printf("\n"); } -void print_hex_par(const byte* pbtData, const uint32_t uiBits, const byte* pbtDataPar) +void print_hex_par(const byte_t* pbtData, const uint32_t uiBits, const byte_t* pbtDataPar) { uint32_t uiPos; uint32_t uiBytes = uiBits/8; diff --git a/src/bitutils.h b/src/bitutils.h index b8021e0..97bdb16 100644 --- a/src/bitutils.h +++ b/src/bitutils.h @@ -23,24 +23,24 @@ along with this program. If not, see #include -#include "defines.h" +#include "types.h" -byte oddparity(const byte bt); -void oddparity_bytes(const byte* pbtData, const uint32_t uiLen, byte* pbtPar); +byte_t oddparity(const byte_t bt); +void oddparity_byte_ts(const byte_t* pbtData, const uint32_t uiLen, byte_t* pbtPar); -byte mirror(byte bt); +byte_t mirror(byte_t bt); uint32_t mirror32(uint32_t ui32Bits); uint64_t mirror64(uint64_t ui64Bits); -void mirror_bytes(byte *pbts, uint32_t uiLen); +void mirror_byte_ts(byte_t *pbts, uint32_t uiLen); uint32_t swap_endian32(const void* pui32); uint64_t swap_endian64(const void* pui64); -void append_iso14443a_crc(byte* pbtData, uint32_t uiLen); +void append_iso14443a_crc(byte_t* pbtData, uint32_t uiLen); -void print_hex(const byte* pbtData, const uint32_t uiLen); -void print_hex_bits(const byte* pbtData, const uint32_t uiBits); -void print_hex_par(const byte* pbtData, const uint32_t uiBits, const byte* pbtDataPar); +void print_hex(const byte_t* pbtData, const uint32_t uiLen); +void print_hex_bits(const byte_t* pbtData, const uint32_t uiBits); +void print_hex_par(const byte_t* pbtData, const uint32_t uiBits, const byte_t* pbtDataPar); #endif // _LIBNFC_BITUTILS_H_ diff --git a/src/defines.h b/src/defines.h index 8792560..a604a7b 100644 --- a/src/defines.h +++ b/src/defines.h @@ -23,8 +23,6 @@ along with this program. If not, see // #define DEBUG /* DEBUG flag can also be enabled using ./configure --enable-debug */ -typedef unsigned char byte; - typedef void* dev_spec; // Device connection specification #define INVALID_DEVICE_INFO 0 #define MAX_FRAME_LEN 264 @@ -32,8 +30,8 @@ typedef void* dev_spec; // Device connection specification #define MAX_DEVICES 16 // Useful macros -#define MIN(a,b) (((a) < (b)) ? (a) : (b)) -#define MAX(a,b) (((a) > (b)) ? (a) : (b)) +//#define MIN(a,b) (((a) < (b)) ? (a) : (b)) +//#define MAX(a,b) (((a) > (b)) ? (a) : (b)) #define INNER_XOR8(n) {n ^= (n >> 4); n ^= (n >> 2); n ^= (n >> 1); n &= 0x01; } #define INNER_XOR32(n) {n ^= (n >> 16); n ^= (n >> 8); INNER_XOR8(n); } #define INNER_XOR64(n) {n ^= (n >> 32); INNER_XOR32(n); } diff --git a/src/dev_acr122.c b/src/dev_acr122.c index 91c5e0d..6ed013b 100644 --- a/src/dev_acr122.c +++ b/src/dev_acr122.c @@ -55,13 +55,13 @@ typedef struct { SCARD_IO_REQUEST ioCard; } dev_spec_acr122; -static byte abtTxBuf[ACR122_WRAP_LEN+ACR122_COMMAND_LEN] = { 0xFF, 0x00, 0x00, 0x00 }; -static byte abtRxCmd[5] = { 0xFF,0xC0,0x00,0x00 }; -static byte uiRxCmdLen = sizeof(abtRxCmd); -static byte abtRxBuf[ACR122_RESPONSE_LEN]; +static byte_t abtTxBuf[ACR122_WRAP_LEN+ACR122_COMMAND_LEN] = { 0xFF, 0x00, 0x00, 0x00 }; +static byte_t abtRxCmd[5] = { 0xFF,0xC0,0x00,0x00 }; +static byte_t uiRxCmdLen = sizeof(abtRxCmd); +static byte_t abtRxBuf[ACR122_RESPONSE_LEN]; static size_t ulRxBufLen; -static byte abtGetFw[5] = { 0xFF,0x00,0x48,0x00,0x00 }; -static byte abtLed[9] = { 0xFF,0x00,0x40,0x05,0x04,0x00,0x00,0x00,0x00 }; +static byte_t abtGetFw[5] = { 0xFF,0x00,0x48,0x00,0x00 }; +static byte_t abtLed[9] = { 0xFF,0x00,0x40,0x05,0x04,0x00,0x00,0x00,0x00 }; dev_info* dev_acr122_connect(const uint32_t uiIndex) { @@ -178,7 +178,7 @@ void dev_acr122_disconnect(dev_info* pdi) free(pdi); } -bool dev_acr122_transceive(const dev_spec ds, const byte* pbtTx, const uint32_t uiTxLen, byte* pbtRx, uint32_t* puiRxLen) +bool dev_acr122_transceive(const dev_spec ds, const byte_t* pbtTx, const uint32_t uiTxLen, byte_t* pbtRx, uint32_t* puiRxLen) { dev_spec_acr122* pdsa = (dev_spec_acr122*)ds; @@ -247,7 +247,7 @@ char* dev_acr122_firmware(const dev_spec ds) { uiResult = SCardControl(pdsa->hCard,IOCTL_CCID_ESCAPE_SCARD_CTL_CODE,abtGetFw,sizeof(abtGetFw),abtFw,ulFwLen,(void*)&ulFwLen); } else { - uiResult = SCardTransmit(pdsa->hCard,&(pdsa->ioCard),abtGetFw,sizeof(abtGetFw),NULL,(byte*)abtFw,(void*)&ulFwLen); + uiResult = SCardTransmit(pdsa->hCard,&(pdsa->ioCard),abtGetFw,sizeof(abtGetFw),NULL,(byte_t*)abtFw,(void*)&ulFwLen); } #ifdef DEBUG @@ -263,13 +263,13 @@ char* dev_acr122_firmware(const dev_spec ds) bool dev_acr122_led_red(const dev_spec ds, bool bOn) { dev_spec_acr122* pdsa = (dev_spec_acr122*)ds; - byte abtBuf[2]; + byte_t abtBuf[2]; size_t ulBufLen = sizeof(abtBuf); if (pdsa->ioCard.dwProtocol == SCARD_PROTOCOL_UNDEFINED) { return (SCardControl(pdsa->hCard,IOCTL_CCID_ESCAPE_SCARD_CTL_CODE,abtLed,sizeof(abtLed),abtBuf,ulBufLen,(void*)&ulBufLen) == SCARD_S_SUCCESS); } else { - return (SCardTransmit(pdsa->hCard,&(pdsa->ioCard),abtLed,sizeof(abtLed),NULL,(byte*)abtBuf,(void*)&ulBufLen) == SCARD_S_SUCCESS); + return (SCardTransmit(pdsa->hCard,&(pdsa->ioCard),abtLed,sizeof(abtLed),NULL,(byte_t*)abtBuf,(void*)&ulBufLen) == SCARD_S_SUCCESS); } } diff --git a/src/dev_acr122.h b/src/dev_acr122.h index 3fd6b48..3f9c9dc 100644 --- a/src/dev_acr122.h +++ b/src/dev_acr122.h @@ -32,7 +32,7 @@ dev_info* dev_acr122_connect(const uint32_t uiIndex); void dev_acr122_disconnect(dev_info* pdi); // Callback function used by libnfc to transmit commands to the PN53X chip -bool dev_acr122_transceive(const dev_spec ds, const byte* pbtTx, const uint32_t uiTxLen, byte* pbtRx, uint32_t* puiRxLen); +bool dev_acr122_transceive(const dev_spec ds, const byte_t* pbtTx, const uint32_t uiTxLen, byte_t* pbtRx, uint32_t* puiRxLen); // Various additional features this device supports char* dev_acr122_firmware(const dev_spec ds); diff --git a/src/dev_arygon.c b/src/dev_arygon.c index 717427c..997ac41 100644 --- a/src/dev_arygon.c +++ b/src/dev_arygon.c @@ -34,7 +34,7 @@ along with this program. If not, see #define BUFFER_LENGTH 256 #define USB_TIMEOUT 30000 -static byte abtTxBuf[BUFFER_LENGTH] = { 0x32, 0x00, 0x00, 0xff }; // Every packet must start with "00 00 ff" +static byte_t abtTxBuf[BUFFER_LENGTH] = { 0x32, 0x00, 0x00, 0xff }; // Every packet must start with "00 00 ff" dev_info* dev_arygon_connect(const uint32_t uiIndex) { @@ -88,9 +88,9 @@ void dev_arygon_disconnect(dev_info* pdi) free(pdi); } -bool dev_arygon_transceive(const dev_spec ds, const byte* pbtTx, const uint32_t uiTxLen, byte* pbtRx, uint32_t* puiRxLen) +bool dev_arygon_transceive(const dev_spec ds, const byte_t* pbtTx, const uint32_t uiTxLen, byte_t* pbtRx, uint32_t* puiRxLen) { - byte abtRxBuf[BUFFER_LENGTH]; + byte_t abtRxBuf[BUFFER_LENGTH]; uint32_t uiRxBufLen = BUFFER_LENGTH; uint32_t uiPos; diff --git a/src/dev_arygon.h b/src/dev_arygon.h index 8408dea..885b7dc 100644 --- a/src/dev_arygon.h +++ b/src/dev_arygon.h @@ -29,7 +29,7 @@ dev_info* dev_arygon_connect(const uint32_t uiIndex); void dev_arygon_disconnect(dev_info* pdi); // Callback function used by libnfc to transmit commands to the PN53X chip -bool dev_arygon_transceive(const dev_spec ds, const byte* pbtTx, const uint32_t uiTxLen, byte* pbtRx, uint32_t* puiRxLen); +bool dev_arygon_transceive(const dev_spec ds, const byte_t* pbtTx, const uint32_t uiTxLen, byte_t* pbtRx, uint32_t* puiRxLen); #endif // _LIBNFC_DEV_ARYGON_H_ diff --git a/src/dev_pn531.c b/src/dev_pn531.c index f83ff35..82e7620 100644 --- a/src/dev_pn531.c +++ b/src/dev_pn531.c @@ -171,7 +171,7 @@ void dev_pn531_disconnect(dev_info* pdi) free(pdi); } -bool dev_pn531_transceive(const dev_spec ds, const byte* pbtTx, const uint32_t uiTxLen, byte* pbtRx, uint32_t* puiRxLen) +bool dev_pn531_transceive(const dev_spec ds, const byte_t* pbtTx, const uint32_t uiTxLen, byte_t* pbtRx, uint32_t* puiRxLen) { uint32_t uiPos = 0; int ret = 0; @@ -179,25 +179,25 @@ bool dev_pn531_transceive(const dev_spec ds, const byte* pbtTx, const uint32_t u dev_spec_pn531* pdsp = (dev_spec_pn531*)ds; // Packet length = data length (len) + checksum (1) + end of stream marker (1) - buffer[3] = uiTxLen; - // Packet length checksum - buffer[4] = BUFFER_LENGTH - buffer[3]; + buffer[3] = uiTxLen; + // Packet length checksum + buffer[4] = BUFFER_LENGTH - buffer[3]; // Copy the PN53X command into the packet buffer memmove(buffer+5,pbtTx,uiTxLen); // Calculate data payload checksum - buffer[uiTxLen+5] = 0; + buffer[uiTxLen+5] = 0; for(uiPos=0; uiPos < uiTxLen; uiPos++) { buffer[uiTxLen+5] -= buffer[uiPos+5]; } // End of stream marker - buffer[uiTxLen+6] = 0; + buffer[uiTxLen+6] = 0; #ifdef DEBUG printf("Tx: "); - print_hex((byte*)buffer,uiTxLen+7); + print_hex((byte_t*)buffer,uiTxLen+7); #endif ret = usb_bulk_write(pdsp->pudh, pdsp->uiEndPointOut, buffer, uiTxLen+7, USB_TIMEOUT); @@ -220,7 +220,7 @@ bool dev_pn531_transceive(const dev_spec ds, const byte* pbtTx, const uint32_t u #ifdef DEBUG printf("Rx: "); - print_hex((byte*)buf,ret); + print_hex((byte_t*)buf,ret); #endif if( ret == 6 ) @@ -236,7 +236,7 @@ bool dev_pn531_transceive(const dev_spec ds, const byte* pbtTx, const uint32_t u #ifdef DEBUG printf("Rx: "); - print_hex((byte*)buf,ret); + print_hex((byte_t*)buf,ret); #endif } diff --git a/src/dev_pn531.h b/src/dev_pn531.h index 5b7ed98..51279e8 100644 --- a/src/dev_pn531.h +++ b/src/dev_pn531.h @@ -32,7 +32,7 @@ dev_info* dev_pn531_connect(const uint32_t uiIndex); void dev_pn531_disconnect(dev_info* pdi); // Callback function used by libnfc to transmit commands to the PN53X chip -bool dev_pn531_transceive(const dev_spec ds, const byte* pbtTx, const uint32_t uiTxLen, byte* pbtRx, uint32_t* puiRxLen); +bool dev_pn531_transceive(const dev_spec ds, const byte_t* pbtTx, const uint32_t uiTxLen, byte_t* pbtRx, uint32_t* puiRxLen); #endif // _LIBNFC_DEV_PN531_H_ diff --git a/src/dev_pn533.c b/src/dev_pn533.c index 97f24f7..d73897a 100644 --- a/src/dev_pn533.c +++ b/src/dev_pn533.c @@ -166,7 +166,7 @@ void dev_pn533_disconnect(dev_info* pdi) free(pdi); } -bool dev_pn533_transceive(const dev_spec ds, const byte* pbtTx, const uint32_t uiTxLen, byte* pbtRx, uint32_t* puiRxLen) +bool dev_pn533_transceive(const dev_spec ds, const byte_t* pbtTx, const uint32_t uiTxLen, byte_t* pbtRx, uint32_t* puiRxLen) { uint32_t uiPos = 0; int ret = 0; @@ -192,7 +192,7 @@ bool dev_pn533_transceive(const dev_spec ds, const byte* pbtTx, const uint32_t u #ifdef DEBUG printf("Tx: "); - print_hex((byte*)buffer,uiTxLen+7); + print_hex((byte_t*)buffer,uiTxLen+7); #endif ret = usb_bulk_write(pdsp->pudh, pdsp->uiEndPointOut, buffer, uiTxLen+7, USB_TIMEOUT); @@ -215,7 +215,7 @@ bool dev_pn533_transceive(const dev_spec ds, const byte* pbtTx, const uint32_t u #ifdef DEBUG printf("Rx: "); - print_hex((byte*)buf,ret); + print_hex((byte_t*)buf,ret); #endif if( ret == 6 ) @@ -231,7 +231,7 @@ bool dev_pn533_transceive(const dev_spec ds, const byte* pbtTx, const uint32_t u #ifdef DEBUG printf("Rx: "); - print_hex((byte*)buf,ret); + print_hex((byte_t*)buf,ret); #endif } diff --git a/src/dev_pn533.h b/src/dev_pn533.h index 619247c..8bf0587 100644 --- a/src/dev_pn533.h +++ b/src/dev_pn533.h @@ -29,7 +29,7 @@ dev_info* dev_pn533_connect(const uint32_t uiIndex); void dev_pn533_disconnect(dev_info* pdi); // Callback function used by libnfc to transmit commands to the PN53X chip -bool dev_pn533_transceive(const dev_spec ds, const byte* pbtTx, const uint32_t uiTxLen, byte* pbtRx, uint32_t* puiRxLen); +bool dev_pn533_transceive(const dev_spec ds, const byte_t* pbtTx, const uint32_t uiTxLen, byte_t* pbtRx, uint32_t* puiRxLen); #endif // _LIBNFC_DEV_PN533_H_ diff --git a/src/emulate.c b/src/emulate.c index afd1348..d501fae 100644 --- a/src/emulate.c +++ b/src/emulate.c @@ -26,18 +26,18 @@ along with this program. If not, see #include "libnfc.h" -static byte abtRecv[MAX_FRAME_LEN]; +static byte_t abtRecv[MAX_FRAME_LEN]; static uint32_t uiRecvBits; static dev_info* pdi; // ISO14443A Anti-Collision response -byte abtAtqa [2] = { 0x04,0x00 }; -byte abtUidBcc [5] = { 0xDE,0xAD,0xBE,0xAF,0x62 }; -byte abtSak [9] = { 0x08,0xb6,0xdd }; +byte_t abtAtqa [2] = { 0x04,0x00 }; +byte_t abtUidBcc [5] = { 0xDE,0xAD,0xBE,0xAF,0x62 }; +byte_t abtSak [9] = { 0x08,0xb6,0xdd }; int main(int argc, const char* argv[]) { - byte* pbtTx = NULL; + byte_t* pbtTx = NULL; uint32_t uiTxBits; // Try to open the NFC reader diff --git a/src/libnfc.c b/src/libnfc.c index 6026f0f..8aa1b40 100644 --- a/src/libnfc.c +++ b/src/libnfc.c @@ -58,44 +58,44 @@ along with this program. If not, see #define PARAM_NO_AMBLE 0x40 // PN53X configuration -byte pncmd_get_firmware_version [ 2] = { 0xD4,0x02 }; -byte pncmd_get_general_status [ 2] = { 0xD4,0x04 }; -byte pncmd_get_register [ 4] = { 0xD4,0x06 }; -byte pncmd_set_register [ 5] = { 0xD4,0x08 }; -byte pncmd_set_parameters [ 3] = { 0xD4,0x12 }; +byte_t pncmd_get_firmware_version [ 2] = { 0xD4,0x02 }; +byte_t pncmd_get_general_status [ 2] = { 0xD4,0x04 }; +byte_t pncmd_get_register [ 4] = { 0xD4,0x06 }; +byte_t pncmd_set_register [ 5] = { 0xD4,0x08 }; +byte_t pncmd_set_parameters [ 3] = { 0xD4,0x12 }; // RF field configuration -byte pncmd_rf_configure_field [ 4] = { 0xD4,0x32,0x01 }; -byte pncmd_rf_configure_timing [ 4] = { 0xD4,0x32,0x02 }; -byte pncmd_rf_configure_retry_data [ 4] = { 0xD4,0x32,0x04 }; -byte pncmd_rf_configure_retry_select [ 6] = { 0xD4,0x32,0x05 }; +byte_t pncmd_rf_configure_field [ 4] = { 0xD4,0x32,0x01 }; +byte_t pncmd_rf_configure_timing [ 4] = { 0xD4,0x32,0x02 }; +byte_t pncmd_rf_configure_retry_data [ 4] = { 0xD4,0x32,0x04 }; +byte_t pncmd_rf_configure_retry_select [ 6] = { 0xD4,0x32,0x05 }; // Reader -byte pncmd_reader_list_passive [264] = { 0xD4,0x4A }; -byte pncmd_reader_select [ 3] = { 0xD4,0x54 }; -byte pncmd_reader_deselect [ 3] = { 0xD4,0x44,0x00 }; -byte pncmd_reader_release [ 3] = { 0xD4,0x52,0x00 }; -byte pncmd_reader_set_baud_rate [ 5] = { 0xD4,0x4E }; -byte pncmd_reader_exchange_data [265] = { 0xD4,0x40 }; -byte pncmd_reader_auto_poll [ 5] = { 0xD4,0x60 }; +byte_t pncmd_reader_list_passive [264] = { 0xD4,0x4A }; +byte_t pncmd_reader_select [ 3] = { 0xD4,0x54 }; +byte_t pncmd_reader_deselect [ 3] = { 0xD4,0x44,0x00 }; +byte_t pncmd_reader_release [ 3] = { 0xD4,0x52,0x00 }; +byte_t pncmd_reader_set_baud_rate [ 5] = { 0xD4,0x4E }; +byte_t pncmd_reader_exchange_data [265] = { 0xD4,0x40 }; +byte_t pncmd_reader_auto_poll [ 5] = { 0xD4,0x60 }; // Target -byte pncmd_target_get_data [ 2] = { 0xD4,0x86 }; -byte pncmd_target_init [ 39] = { 0xD4,0x8C }; -byte pncmd_target_virtual_card [ 4] = { 0xD4,0x14 }; -byte pncmd_target_receive [ 2] = { 0xD4,0x88 }; -byte pncmd_target_send [264] = { 0xD4,0x90 }; -byte pncmd_target_get_status [ 2] = { 0xD4,0x8A }; +byte_t pncmd_target_get_data [ 2] = { 0xD4,0x86 }; +byte_t pncmd_target_init [ 39] = { 0xD4,0x8C }; +byte_t pncmd_target_virtual_card [ 4] = { 0xD4,0x14 }; +byte_t pncmd_target_receive [ 2] = { 0xD4,0x88 }; +byte_t pncmd_target_send [264] = { 0xD4,0x90 }; +byte_t pncmd_target_get_status [ 2] = { 0xD4,0x8A }; // Exchange raw data frames -byte pncmd_exchange_raw_data [266] = { 0xD4,0x42 }; +byte_t pncmd_exchange_raw_data [266] = { 0xD4,0x42 }; // Global buffers used for communication with the PN53X chip #define MAX_FRAME_LEN 264 -static byte abtRx[MAX_FRAME_LEN]; +static byte_t abtRx[MAX_FRAME_LEN]; static uint32_t uiRxLen; -bool pn53x_transceive(const dev_info* pdi, const byte* pbtTx, const uint32_t uiTxLen) +bool pn53x_transceive(const dev_info* pdi, const byte_t* pbtTx, const uint32_t uiTxLen) { // Reset the receiving buffer uiRxLen = MAX_FRAME_LEN; @@ -110,7 +110,7 @@ bool pn53x_transceive(const dev_info* pdi, const byte* pbtTx, const uint32_t uiT return true; } -byte pn53x_get_reg(const dev_info* pdi, uint16_t ui16Reg) +byte_t pn53x_get_reg(const dev_info* pdi, uint16_t ui16Reg) { uint8_t ui8Value; uint32_t uiValueLen = 1; @@ -148,10 +148,10 @@ bool pn53x_set_tx_bits(const dev_info* pdi, uint8_t ui8Bits) return true; } -bool pn53x_wrap_frame(const byte* pbtTx, const uint32_t uiTxBits, const byte* pbtTxPar, byte* pbtFrame, uint32_t* puiFrameBits) +bool pn53x_wrap_frame(const byte_t* pbtTx, const uint32_t uiTxBits, const byte_t* pbtTxPar, byte_t* pbtFrame, uint32_t* puiFrameBits) { - byte btFrame; - byte btData; + byte_t btFrame; + byte_t btData; uint32_t uiBitPos; uint32_t uiDataPos = 0; uint32_t uiBitsLeft = uiTxBits; @@ -204,13 +204,13 @@ bool pn53x_wrap_frame(const byte* pbtTx, const uint32_t uiTxBits, const byte* pb } } -bool pn53x_unwrap_frame(const byte* pbtFrame, const uint32_t uiFrameBits, byte* pbtRx, uint32_t* puiRxBits, byte* pbtRxPar) +bool pn53x_unwrap_frame(const byte_t* pbtFrame, const uint32_t uiFrameBits, byte_t* pbtRx, uint32_t* puiRxBits, byte_t* pbtRxPar) { - byte btFrame; - byte btData; + byte_t btFrame; + byte_t btData; uint8_t uiBitPos; uint32_t uiDataPos = 0; - byte* pbtFramePos = (byte*) pbtFrame; + byte_t* pbtFramePos = (byte_t*) pbtFrame; uint32_t uiBitsLeft = uiFrameBits; // Make sure we should frame at least something @@ -254,7 +254,7 @@ dev_info* nfc_connect() { dev_info* pdi; uint32_t uiDev; - byte abtFw[4]; + byte_t abtFw[4]; uint32_t uiFwLen = sizeof(abtFw); // Search through the device list for an available device @@ -312,7 +312,7 @@ void nfc_disconnect(dev_info* pdi) bool nfc_configure(dev_info* pdi, const dev_config_option dco, const bool bEnable) { - byte btValue; + byte_t btValue; // Make sure we are dealing with a active device if (!pdi->bActive) return false; @@ -384,7 +384,7 @@ bool nfc_reader_init(const dev_info* pdi) return true; } -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_select(const dev_info* pdi, const init_modulation im, const byte_t* pbtInitData, const uint32_t uiInitDataLen, tag_info* pti) { // Make sure we are dealing with a active device if (!pdi->bActive) return false; @@ -485,7 +485,7 @@ bool nfc_reader_deselect(const dev_info* pdi) 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 uint32_t uiTxBits, const byte* pbtTxPar, byte* pbtRx, uint32_t* puiRxBits, byte* pbtRxPar) +bool nfc_reader_transceive_bits(const dev_info* pdi, const byte_t* pbtTx, const uint32_t uiTxBits, const byte_t* pbtTxPar, byte_t* pbtRx, uint32_t* puiRxBits, byte_t* pbtRxPar) { uint32_t uiFrameBits = 0; uint32_t uiFrameBytes = 0; @@ -539,7 +539,7 @@ bool nfc_reader_transceive_bits(const dev_info* pdi, const byte* pbtTx, const ui return true; } -bool nfc_reader_transceive_bytes(const dev_info* pdi, const byte* pbtTx, const uint32_t uiTxLen, byte* pbtRx, uint32_t* puiRxLen) +bool nfc_reader_transceive_bytes(const dev_info* pdi, const byte_t* pbtTx, const uint32_t uiTxLen, byte_t* pbtRx, uint32_t* puiRxLen) { // We can not just send bytes without parity if while the PN53X expects we handled them if (!pdi->bPar) return false; @@ -608,7 +608,7 @@ bool nfc_reader_mifare_cmd(const dev_info* pdi, const mifare_cmd mc, const uint8 } // When available, copy the parameter bytes - if (uiParamLen) memcpy(pncmd_reader_exchange_data+5,(byte*)pmp,uiParamLen); + if (uiParamLen) memcpy(pncmd_reader_exchange_data+5,(byte_t*)pmp,uiParamLen); // Fire the mifare command if (!pn53x_transceive(pdi,pncmd_reader_exchange_data,5+uiParamLen)) return false; @@ -620,7 +620,7 @@ bool nfc_reader_mifare_cmd(const dev_info* pdi, const mifare_cmd mc, const uint8 return true; } -bool nfc_target_init(const dev_info* pdi, byte* pbtRx, uint32_t* puiRxBits) +bool nfc_target_init(const dev_info* pdi, byte_t* pbtRx, uint32_t* puiRxBits) { uint8_t ui8Bits; @@ -670,7 +670,7 @@ bool nfc_target_init(const dev_info* pdi, byte* pbtRx, uint32_t* puiRxBits) return true; } -bool nfc_target_receive_bits(const dev_info* pdi, byte* pbtRx, uint32_t* puiRxBits, byte* pbtRxPar) +bool nfc_target_receive_bits(const dev_info* pdi, byte_t* pbtRx, uint32_t* puiRxBits, byte_t* pbtRxPar) { uint32_t uiFrameBits; uint8_t ui8Bits; @@ -700,7 +700,7 @@ bool nfc_target_receive_bits(const dev_info* pdi, byte* pbtRx, uint32_t* puiRxBi return true; } -bool nfc_target_receive_bytes(const dev_info* pdi, byte* pbtRx, uint32_t* puiRxLen) +bool nfc_target_receive_bytes(const dev_info* pdi, byte_t* pbtRx, uint32_t* puiRxLen) { // Try to gather a received frame from the reader if (!pn53x_transceive(pdi,pncmd_target_receive,2)) return false; @@ -715,7 +715,7 @@ bool nfc_target_receive_bytes(const dev_info* pdi, byte* pbtRx, uint32_t* puiRxL return true; } -bool nfc_target_send_bits(const dev_info* pdi, const byte* pbtTx, const uint32_t uiTxBits, const byte* pbtTxPar) +bool nfc_target_send_bits(const dev_info* pdi, const byte_t* pbtTx, const uint32_t uiTxBits, const byte_t* pbtTxPar) { uint32_t uiFrameBits = 0; uint32_t uiFrameBytes = 0; @@ -750,7 +750,7 @@ bool nfc_target_send_bits(const dev_info* pdi, const byte* pbtTx, const uint32_t } -bool nfc_target_send_bytes(const dev_info* pdi, const byte* pbtTx, const uint32_t uiTxLen) +bool nfc_target_send_bytes(const dev_info* pdi, const byte_t* pbtTx, const uint32_t uiTxLen) { // We can not just send bytes without parity if while the PN53X expects we handled them if (!pdi->bPar) return false; diff --git a/src/libnfc.h b/src/libnfc.h index 051b603..b5d9822 100644 --- a/src/libnfc.h +++ b/src/libnfc.h @@ -33,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_reader_init(const dev_info* pdi); -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_select(const dev_info* pdi, const init_modulation im, const byte_t* pbtInitData, const uint32_t uiInitDataLen, tag_info* pti); bool nfc_reader_deselect(const dev_info* pdi); -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 uint32_t uiTxLen, byte* pbtRx, uint32_t* puiRxLen); +bool nfc_reader_transceive_bits(const dev_info* pdi, const byte_t* pbtTx, const uint32_t uiTxBits, const byte_t* pbtTxPar, byte_t* pbtRx, uint32_t* puiRxBits, byte_t* pbtRxPar); +bool nfc_reader_transceive_bytes(const dev_info* pdi, const byte_t* pbtTx, const uint32_t uiTxLen, byte_t* pbtRx, uint32_t* puiRxLen); 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, uint32_t* puiRxBits); -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, uint32_t* puiRxLen); -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 uint32_t uiTxLen); +bool nfc_target_init(const dev_info* pdi, byte_t* pbtRx, uint32_t* puiRxBits); +bool nfc_target_receive_bits(const dev_info* pdi, byte_t* pbtRx, uint32_t* puiRxBits, byte_t* pbtRxPar); +bool nfc_target_receive_bytes(const dev_info* pdi, byte_t* pbtRx, uint32_t* puiRxLen); +bool nfc_target_send_bits(const dev_info* pdi, const byte_t* pbtTx, const uint32_t uiTxBits, const byte_t* pbtTxPar); +bool nfc_target_send_bytes(const dev_info* pdi, const byte_t* pbtTx, const uint32_t uiTxLen); #endif // _LIBNFC_H_ diff --git a/src/list.c b/src/list.c index 808c886..649939b 100644 --- a/src/list.c +++ b/src/list.c @@ -27,7 +27,7 @@ along with this program. If not, see #include "libnfc.h" static dev_info* pdi; -static byte abtFelica[5] = { 0x00, 0xff, 0xff, 0x00, 0x00 }; +static byte_t abtFelica[5] = { 0x00, 0xff, 0xff, 0x00, 0x00 }; int main(int argc, const char* argv[]) { diff --git a/src/mftool.c b/src/mftool.c index 315c0aa..fbeb4ce 100644 --- a/src/mftool.c +++ b/src/mftool.c @@ -231,7 +231,7 @@ int main(int argc, const char* argv[]) { bool b4K; bool bReadAction; - byte* pbtUID; + byte_t* pbtUID; FILE* pfKeys; FILE* pfDump; diff --git a/src/mifaretag.h b/src/mifaretag.h index ae62c0a..dcea842 100644 --- a/src/mifaretag.h +++ b/src/mifaretag.h @@ -24,21 +24,21 @@ along with this program. If not, see #include "defines.h" typedef struct { - byte abtUID[4]; - byte btBCC; - byte btUnknown; - byte abtATQA[2]; - byte abtUnknown[8]; + byte_t abtUID[4]; + byte_t btBCC; + byte_t btUnknown; + byte_t abtATQA[2]; + byte_t abtUnknown[8]; } mifare_block_manufacturer; typedef struct { - byte abtData[16]; + byte_t abtData[16]; } mifare_block_data; typedef struct { - byte abtKeyA[6]; - byte abtAccessBits[4]; - byte abtKeyB[6]; + byte_t abtKeyA[6]; + byte_t abtAccessBits[4]; + byte_t abtKeyB[6]; } mifare_block_trailer; typedef union { diff --git a/src/relay.c b/src/relay.c index 092f39c..aca9b8c 100644 --- a/src/relay.c +++ b/src/relay.c @@ -25,11 +25,11 @@ along with this program. If not, see #include "libnfc.h" -static byte abtReaderRx[MAX_FRAME_LEN]; -static byte abtReaderRxPar[MAX_FRAME_LEN]; +static byte_t abtReaderRx[MAX_FRAME_LEN]; +static byte_t abtReaderRxPar[MAX_FRAME_LEN]; static uint32_t uiReaderRxBits; -static byte abtTagRx[MAX_FRAME_LEN]; -static byte abtTagRxPar[MAX_FRAME_LEN]; +static byte_t abtTagRx[MAX_FRAME_LEN]; +static byte_t abtTagRxPar[MAX_FRAME_LEN]; static uint32_t uiTagRxBits; static dev_info* pdiReader; static dev_info* pdiTag; diff --git a/src/rs232.c b/src/rs232.c index ffe395f..a8be31f 100644 --- a/src/rs232.c +++ b/src/rs232.c @@ -101,7 +101,7 @@ bool rs232_cts(const serial_port sp) return (status & TIOCM_CTS); } -bool rs232_receive(const serial_port sp, byte* pbtRx, uint32_t* puiRxLen) +bool rs232_receive(const serial_port sp, byte_t* pbtRx, uint32_t* puiRxLen) { int iResult; uint32_t uiCount = 0; @@ -132,7 +132,7 @@ bool rs232_receive(const serial_port sp, byte* pbtRx, uint32_t* puiRxLen) } } -bool rs232_send(const serial_port sp, const byte* pbtTx, const uint32_t uiTxLen) +bool rs232_send(const serial_port sp, const byte_t* pbtTx, const uint32_t uiTxLen) { int iResult; iResult = write(((serial_port_unix*)sp)->fd,pbtTx,uiTxLen); @@ -209,12 +209,12 @@ bool rs232_cts(const serial_port sp) return (dwStatus & MS_CTS_ON); } -bool rs232_receive(const serial_port sp, byte* pbtRx, uint32_t* puiRxLen) +bool rs232_receive(const serial_port sp, byte_t* pbtRx, uint32_t* puiRxLen) { return (ReadFile(((serial_port_windows*)sp)->hPort,pbtRx,*puiRxLen,(LPDWORD)puiRxLen,NULL) != NULL); } -bool rs232_send(const serial_port sp, const byte* pbtTx, const uint32_t uiTxLen) +bool rs232_send(const serial_port sp, const byte_t* pbtTx, const uint32_t uiTxLen) { DWORD dwTxLen; return (WriteFile(((serial_port_windows*)sp)->hPort,pbtTx,uiTxLen,&dwTxLen,NULL) != NULL); diff --git a/src/rs232.h b/src/rs232.h index c4280f2..e1c6518 100644 --- a/src/rs232.h +++ b/src/rs232.h @@ -49,8 +49,8 @@ typedef void* serial_port; serial_port rs232_open(const char* pcPortName); void rs232_close(const serial_port sp); bool rs232_cts(const serial_port sp); -bool rs232_receive(const serial_port sp, byte* pbtRx, uint32_t* puiRxLen); -bool rs232_send(const serial_port sp, const byte* pbtTx, const uint32_t uiTxLen); +bool rs232_receive(const serial_port sp, byte_t* pbtRx, uint32_t* puiRxLen); +bool rs232_send(const serial_port sp, const byte_t* pbtTx, const uint32_t uiTxLen); #endif // _LIBNFC_RS232_H_ diff --git a/src/types.h b/src/types.h index 1e5c452..0babe2a 100644 --- a/src/types.h +++ b/src/types.h @@ -26,7 +26,9 @@ along with this program. If not, see #include "defines.h" -// Compiler directive, set struct alignment to 1 byte for compatibility +typedef uint8_t byte_t; + +// Compiler directive, set struct alignment to 1 byte_t for compatibility #pragma pack(1) typedef enum { @@ -51,7 +53,7 @@ typedef struct { struct dev_callbacks { const char* acDriver; // Driver description dev_info* (*connect)(const uint32_t uiIndex); - bool (*transceive)(const dev_spec ds, const byte* pbtTx, const uint32_t uiTxLen, byte* pbtRx, uint32_t* puiRxLen); + bool (*transceive)(const dev_spec ds, const byte_t* pbtTx, const uint32_t uiTxLen, byte_t* pbtRx, uint32_t* puiRxLen); void (*disconnect)(dev_info* pdi); }; @@ -77,37 +79,37 @@ typedef enum { }init_modulation; typedef struct { - byte abtAtqa[2]; - byte btSak; + byte_t abtAtqa[2]; + byte_t btSak; uint32_t uiUidLen; - byte abtUid[10]; + byte_t abtUid[10]; uint32_t uiAtsLen; - byte abtAts[36]; + byte_t abtAts[36]; }tag_info_iso14443a; typedef struct { uint32_t uiLen; - byte btResCode; - byte abtId[8]; - byte abtPad[8]; - byte abtSysCode[2]; + byte_t btResCode; + byte_t abtId[8]; + byte_t abtPad[8]; + byte_t abtSysCode[2]; }tag_info_felica; typedef struct { - byte abtAtqb[12]; - byte abtId[4]; - byte btParam1; - byte btParam2; - byte btParam3; - byte btParam4; - byte btCid; + byte_t abtAtqb[12]; + byte_t abtId[4]; + byte_t btParam1; + byte_t btParam2; + byte_t btParam3; + byte_t btParam4; + byte_t btCid; uint32_t uiInfLen; - byte abtInf[64]; + byte_t abtInf[64]; }tag_info_iso14443b; typedef struct { - byte btSensRes[2]; - byte btId[4]; + byte_t btSensRes[2]; + byte_t btId[4]; }tag_info_jewel; typedef union { @@ -133,16 +135,16 @@ typedef enum { // MIFARE Classic command params typedef struct { - byte abtKey[6]; - byte abtUid[4]; + byte_t abtKey[6]; + byte_t abtUid[4]; }mifare_param_auth; typedef struct { - byte abtData[16]; + byte_t abtData[16]; }mifare_param_data; typedef struct { - byte abtValue[4]; + byte_t abtValue[4]; }mifare_param_value; typedef union { From c0bcce387e744c2b1d4eedac711df7aa2a19e939 Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Wed, 22 Jul 2009 09:27:59 +0000 Subject: [PATCH 27/29] Fix stupid mistake in autogen.sh. MacOSX users can now run ./configure without problem. Add ChangeLog information for next release. --- ChangeLog | 13 +++++++++++++ autogen.sh | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index e69de29..d4c7144 100644 --- a/ChangeLog +++ b/ChangeLog @@ -0,0 +1,13 @@ +Jul 22, 2009 - 1.1.1 + - License changed from GPLv3 to LGPLv3 + - ARYGON ADRA-USB/ADRB-USB reader support + - PN533 support + - C99 standard (all custom defined types have been renamed) + - Autotoolized for GNU/Linux, *BSD + - nfc tools (emulate, relay, list, mftool) are now prefixed by nfc in GNU/Linux and *BSD + +Mar 27, 2009 - 1.1.0 + - Next generation, support for ACR122v2 and PN531 USB devices + +Feb 12, 2009 - 1.0.0 + - Initial release diff --git a/autogen.sh b/autogen.sh index ca3bdee..fbf0634 100755 --- a/autogen.sh +++ b/autogen.sh @@ -17,7 +17,7 @@ FreeBSD) ;; esac -echo "Running aclocal..." ; aclocal $ACLOCAL_FLAGS || exit 1 +echo "Running aclocal..." ; aclocal $ACLOCAL_ARGS || exit 1 echo "Running autoheader..." ; autoheader || exit 1 echo "Running autoconf..." ; autoconf || exit 1 echo "Running libtoolize..." ; $LIBTOOLIZE --copy --automake || exit 1 From 440fa388895be83584b1e4bea038faec21015c56 Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Wed, 22 Jul 2009 09:35:48 +0000 Subject: [PATCH 28/29] Fix PCSC headers path on MacOS. --- configure.ac | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index f769331..9642d78 100644 --- a/configure.ac +++ b/configure.ac @@ -74,7 +74,8 @@ then case "$host" in *darwin*) AC_MSG_WARN(Using darwin PCSC Framework) - LIBPCSCLITE_LIBS=-Wl,-framework,PCSC + LIBPCSCLITE_LIBS="-Wl,-framework,PCSC" + LIBPCSCLITE_CFLAGS="-I/System/Library/Frameworks/PCSC.framework/Headers" ;; *) PKG_CHECK_MODULES(LIBPCSCLITE, libpcsclite, [WITH_PCSC=1], [WITH_PCSC=0]) From 452e4b31bf24963384cb1d650fcb8b575b0f4fcf Mon Sep 17 00:00:00 2001 From: Roel Verdult Date: Wed, 22 Jul 2009 10:02:28 +0000 Subject: [PATCH 29/29] mac pcsc compilation --- src/dev_acr122.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/dev_acr122.c b/src/dev_acr122.c index 6ed013b..fa297a0 100644 --- a/src/dev_acr122.c +++ b/src/dev_acr122.c @@ -28,7 +28,8 @@ along with this program. If not, see #ifndef __APPLE__ #include #else -#include +#include +#include #endif #include "defines.h"