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.
This commit is contained in:
Romuald Conty 2009-06-11 10:16:27 +00:00
parent d74f0d13dd
commit eccb9d3d3b
8 changed files with 56 additions and 55 deletions

View file

@ -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

View file

@ -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

View file

@ -24,26 +24,26 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifdef _WIN32
#define SERIAL_STRING "COM"
#endif
#ifdef _LINUX
#define SERIAL_STRING "/dev/ttyusb"
#endif
#ifdef __APPLE__
#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;

View file

@ -25,11 +25,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#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_

View file

@ -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;

View file

@ -25,11 +25,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#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_

View file

@ -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);

View file

@ -36,6 +36,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <sys/types.h>
#include <sys/stat.h>
#include <limits.h>
#include <sys/time.h>
#else
#include <windows.h>
#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_