It now compile using Autotools.

This commit is contained in:
Romuald Conty 2009-11-04 10:14:17 +00:00
parent 4a5945e67d
commit 14a9112dea
32 changed files with 193 additions and 192 deletions

17
src/lib/Makefile.am Normal file
View file

@ -0,0 +1,17 @@
SUBDIRS = buses drivers .
# set the include path found by configure
INCLUDES= $(all_includes)
nfcinclude_HEADERS = nfc.h defines.h types.h buses.h drivers.h messages.h bitutils.h
nfcincludedir = $(includedir)/nfc
lib_LTLIBRARIES = libnfc.la
libnfc_la_SOURCES = nfc.c bitutils.c
libnfc_la_LDFLAGS = -no-undefined -version-info=0:0:0
libnfc_la_CFLAGS =
libnfc_la_LIBADD = \
$(top_builddir)/src/lib/buses/libnfcbuses.la \
$(top_builddir)/src/lib/drivers/libnfcdrivers.la
DISTCLEANFILES = Makefile.in

190
src/lib/bitutils.c Normal file
View file

@ -0,0 +1,190 @@
/**
* 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 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 Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*
* @file bitutils.c
* @brief
*/
#include <stdio.h>
#include "bitutils.h"
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,
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,
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
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,
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1
};
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,
0xe4, 0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4, 0x0c, 0x8c, 0x4c, 0xcc,
0x2c, 0xac, 0x6c, 0xec, 0x1c, 0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc, 0x02,
0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2, 0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2,
0x72, 0xf2, 0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea, 0x1a, 0x9a, 0x5a,
0xda, 0x3a, 0xba, 0x7a, 0xfa, 0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6,
0x16, 0x96, 0x56, 0xd6, 0x36, 0xb6, 0x76, 0xf6, 0x0e, 0x8e, 0x4e, 0xce, 0x2e,
0xae, 0x6e, 0xee, 0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe, 0x01, 0x81,
0x41, 0xc1, 0x21, 0xa1, 0x61, 0xe1, 0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71,
0xf1, 0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9, 0x69, 0xe9, 0x19, 0x99, 0x59, 0xd9,
0x39, 0xb9, 0x79, 0xf9, 0x05, 0x85, 0x45, 0xc5, 0x25, 0xa5, 0x65, 0xe5, 0x15,
0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5, 0x0d, 0x8d, 0x4d, 0xcd, 0x2d, 0xad,
0x6d, 0xed, 0x1d, 0x9d, 0x5d, 0xdd, 0x3d, 0xbd, 0x7d, 0xfd, 0x03, 0x83, 0x43,
0xc3, 0x23, 0xa3, 0x63, 0xe3, 0x13, 0x93, 0x53, 0xd3, 0x33, 0xb3, 0x73, 0xf3,
0x0b, 0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb, 0x1b, 0x9b, 0x5b, 0xdb, 0x3b,
0xbb, 0x7b, 0xfb, 0x07, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7, 0x17, 0x97,
0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7, 0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f,
0xef, 0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff
};
byte_t oddparity(const byte_t bt)
{
return OddParity[bt];
}
void oddparity_bytes(const byte_t* pbtData, const size_t szLen, byte_t* pbtPar)
{
size_t szByteNr;
// Calculate the parity bits for the command
for (szByteNr=0; szByteNr<szLen; szByteNr++)
{
pbtPar[szByteNr] = OddParity[pbtData[szByteNr]];
}
}
byte_t mirror(byte_t bt)
{
return ByteMirror[bt];
}
void mirror_bytes(byte_t *pbts, size_t szLen)
{
size_t szByteNr;
for (szByteNr=0; szByteNr<szLen; szByteNr++)
{
*pbts = ByteMirror[*pbts];
pbts++;
}
}
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);
return (((ui32N&0xFF)<<24)+((ui32N&0xFF00)<<8)+((ui32N&0xFF0000)>>8)+((ui32N&0xFF000000)>>24));
}
uint64_t swap_endian64(const void* 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_t* pbtData, size_t szLen)
{
byte_t bt;
uint32_t wCrc = 0x6363;
do {
bt = *pbtData++;
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 (--szLen);
*pbtData++ = (byte_t) (wCrc & 0xFF);
*pbtData = (byte_t) ((wCrc >> 8) & 0xFF);
}
void print_hex(const byte_t* pbtData, const size_t szBytes)
{
size_t szPos;
for (szPos=0; szPos < szBytes; szPos++)
{
printf("%02x ",pbtData[szPos]);
}
printf("\n");
}
void print_hex_bits(const byte_t* pbtData, const size_t szBits)
{
size_t szPos;
size_t szBytes = szBits/8;
for (szPos=0; szPos < szBytes; szPos++)
{
printf("%02x ",pbtData[szPos]);
}
// Print the rest bits, these cannot have no parity bit
if (szBits%8 != 0) printf("%02x",pbtData[szBytes]);
printf("\n");
}
void print_hex_par(const byte_t* pbtData, const size_t szBits, const byte_t* pbtDataPar)
{
size_t szPos;
size_t szBytes = szBits/8;
for (szPos=0; szPos < szBytes; szPos++)
{
printf("%02x",pbtData[szPos]);
if (OddParity[pbtData[szPos]] != pbtDataPar[szPos])
{
printf("! ");
} else {
printf(" ");
}
}
// Print the rest bits, these cannot have no parity bit
if (szBits%8 != 0) printf("%02x",pbtData[szBytes]);
printf("\n");
}

49
src/lib/bitutils.h Normal file
View file

@ -0,0 +1,49 @@
/**
* 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 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 Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*
* @file bitutils.h
* @brief
*/
#ifndef _LIBNFC_BITUTILS_H_
#define _LIBNFC_BITUTILS_H_
#include <stdint.h>
#include "types.h"
byte_t oddparity(const byte_t bt);
void oddparity_byte_ts(const byte_t* pbtData, const size_t szLen, byte_t* pbtPar);
byte_t mirror(byte_t bt);
uint32_t mirror32(uint32_t ui32Bits);
uint64_t mirror64(uint64_t ui64Bits);
void mirror_byte_ts(byte_t *pbts, size_t szLen);
uint32_t swap_endian32(const void* pui32);
uint64_t swap_endian64(const void* pui64);
void append_iso14443a_crc(byte_t* pbtData, size_t szLen);
void print_hex(const byte_t* pbtData, const size_t szLen);
void print_hex_bits(const byte_t* pbtData, const size_t szBits);
void print_hex_par(const byte_t* pbtData, const size_t szBits, const byte_t* pbtDataPar);
#endif // _LIBNFC_BITUTILS_H_

View file

@ -5,5 +5,6 @@ INCLUDES= $(all_includes)
noinst_HEADERS = uart.h
noinst_LTLIBRARIES = libnfcbuses.la
libnfcbuses_la_SOURCES = uart.c
libnfcbuses_la_CFLAGS = -I$(top_srcdir)/src/lib
DISTCLEANFILES = Makefile.in

View file

@ -17,17 +17,17 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*
* @file rs232.c
* @file uart.c
* @brief
*/
/*
Based on rs232-code written by Teunis van Beelen available:
Based on uart-code written by Teunis van Beelen available:
http://www.teuniz.net/RS-232/index.html
*/
#include "rs232.h"
#include "uart.h"
#include "messages.h"
@ -48,10 +48,10 @@ struct timeval tv = {
.tv_usec = 30000 // 30,000 micro seconds
};
// Work-around to claim rs232 interface using the c_iflag (software input processing) from the termios struct
// Work-around to claim uart interface using the c_iflag (software input processing) from the termios struct
#define CCLAIMED 0x80000000
serial_port rs232_open(const char* pcPortName)
serial_port uart_open(const char* pcPortName)
{
serial_port_unix* sp = malloc(sizeof(serial_port_unix));
@ -60,20 +60,20 @@ serial_port rs232_open(const char* pcPortName)
sp->fd = open(pcPortName, O_RDWR | O_NOCTTY | O_NDELAY | O_NONBLOCK);
if(sp->fd == -1)
{
rs232_close(sp);
uart_close(sp);
return INVALID_SERIAL_PORT;
}
if(tcgetattr(sp->fd,&sp->tiOld) == -1)
{
rs232_close(sp);
uart_close(sp);
return INVALID_SERIAL_PORT;
}
// Make sure the port is not claimed already
if (sp->tiOld.c_iflag & CCLAIMED)
{
rs232_close(sp);
uart_close(sp);
return CLAIMED_SERIAL_PORT;
}
@ -90,7 +90,7 @@ serial_port rs232_open(const char* pcPortName)
if(tcsetattr(sp->fd,TCSANOW,&sp->tiNew) == -1)
{
rs232_close(sp);
uart_close(sp);
return INVALID_SERIAL_PORT;
}
@ -98,7 +98,7 @@ serial_port rs232_open(const char* pcPortName)
return sp;
}
void rs232_set_speed(serial_port sp, const uint32_t uiPortSpeed)
void uart_set_speed(serial_port sp, const uint32_t uiPortSpeed)
{
DBG("Serial port speed requested to be set to %d bauds.", uiPortSpeed);
// Set port speed (Input and Output)
@ -136,7 +136,7 @@ void rs232_set_speed(serial_port sp, const uint32_t uiPortSpeed)
}
}
uint32_t rs232_get_speed(const serial_port sp)
uint32_t uart_get_speed(const serial_port sp)
{
uint32_t uiPortSpeed = 0;
const serial_port_unix* spu = (serial_port_unix*)sp;
@ -163,21 +163,21 @@ uint32_t rs232_get_speed(const serial_port sp)
return uiPortSpeed;
}
void rs232_close(const serial_port sp)
void uart_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)
bool uart_cts(const serial_port sp)
{
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_t* pbtRx, size_t* pszRxLen)
bool uart_receive(const serial_port sp, byte_t* pbtRx, size_t* pszRxLen)
{
int iResult;
int byteCount;
@ -217,7 +217,7 @@ bool rs232_receive(const serial_port sp, byte_t* pbtRx, size_t* pszRxLen)
return (*pszRxLen > 0);
}
bool rs232_send(const serial_port sp, const byte_t* pbtTx, const size_t szTxLen)
bool uart_send(const serial_port sp, const byte_t* pbtTx, const size_t szTxLen)
{
int iResult;
iResult = write(((serial_port_unix*)sp)->fd,pbtTx,szTxLen);
@ -233,7 +233,7 @@ typedef struct {
COMMTIMEOUTS ct; // Serial port time-out configuration
} serial_port_windows;
serial_port rs232_open(const char* pcPortName)
serial_port uart_open(const char* pcPortName)
{
char acPortName[255];
serial_port_windows* sp = malloc(sizeof(serial_port_windows));
@ -246,7 +246,7 @@ serial_port rs232_open(const char* pcPortName)
sp->hPort = CreateFileA(acPortName,GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,0,NULL);
if (sp->hPort == INVALID_HANDLE_VALUE)
{
rs232_close(sp);
uart_close(sp);
return INVALID_SERIAL_PORT;
}
@ -255,14 +255,14 @@ serial_port rs232_open(const char* pcPortName)
sp->dcb.DCBlength = sizeof(DCB);
if(!BuildCommDCBA("baud=9600 data=8 parity=N stop=1",&sp->dcb))
{
rs232_close(sp);
uart_close(sp);
return INVALID_SERIAL_PORT;
}
// Update the active serial port
if(!SetCommState(sp->hPort,&sp->dcb))
{
rs232_close(sp);
uart_close(sp);
return INVALID_SERIAL_PORT;
}
@ -274,7 +274,7 @@ serial_port rs232_open(const char* pcPortName)
if(!SetCommTimeouts(sp->hPort,&sp->ct))
{
rs232_close(sp);
uart_close(sp);
return INVALID_SERIAL_PORT;
}
@ -283,13 +283,13 @@ serial_port rs232_open(const char* pcPortName)
return sp;
}
void rs232_close(const serial_port sp)
void uart_close(const serial_port sp)
{
CloseHandle(((serial_port_windows*)sp)->hPort);
free(sp);
}
void rs232_set_speed(serial_port sp, const uint32_t uiPortSpeed)
void uart_set_speed(serial_port sp, const uint32_t uiPortSpeed)
{
serial_port_windows* spw;
@ -316,7 +316,7 @@ void rs232_set_speed(serial_port sp, const uint32_t uiPortSpeed)
}
}
uint32_t rs232_get_speed(const serial_port sp)
uint32_t uart_get_speed(const serial_port sp)
{
const serial_port_windows* spw = (serial_port_windows*)sp;
if (!GetCommState(spw->hPort, (serial_port)&spw->dcb))
@ -325,20 +325,13 @@ uint32_t rs232_get_speed(const serial_port sp)
return 0;
}
bool rs232_cts(const serial_port sp)
{
DWORD dwStatus;
if (!GetCommModemStatus(((serial_port_windows*)sp)->hPort,&dwStatus)) return false;
return (dwStatus & MS_CTS_ON);
}
bool rs232_receive(const serial_port sp, byte_t* pbtRx, size_t* pszRxLen)
bool uart_receive(const serial_port sp, byte_t* pbtRx, size_t* pszRxLen)
{
ReadFile(((serial_port_windows*)sp)->hPort,pbtRx,*pszRxLen,(LPDWORD)pszRxLen,NULL);
return (*pszRxLen != 0);
}
bool rs232_send(const serial_port sp, const byte_t* pbtTx, const size_t szTxLen)
bool uart_send(const serial_port sp, const byte_t* pbtTx, const size_t szTxLen)
{
DWORD dwTxLen = 0;
return WriteFile(((serial_port_windows*)sp)->hPort,pbtTx,szTxLen,&dwTxLen,NULL);

View file

@ -17,7 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*
* @file rs232.h
* @file uart.h
* @brief
*/
@ -49,16 +49,14 @@ 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);
serial_port uart_open(const char* pcPortName);
void uart_close(const serial_port sp);
void rs232_set_speed(serial_port sp, const uint32_t uiPortSpeed);
uint32_t rs232_get_speed(const serial_port sp);
void uart_set_speed(serial_port sp, const uint32_t uiPortSpeed);
uint32_t uart_get_speed(const serial_port sp);
bool rs232_cts(const serial_port sp);
bool rs232_receive(const serial_port sp, byte_t* pbtRx, size_t* pszRxLen);
bool rs232_send(const serial_port sp, const byte_t* pbtTx, const size_t szTxLen);
bool uart_receive(const serial_port sp, byte_t* pbtRx, size_t* pszRxLen);
bool uart_send(const serial_port sp, const byte_t* pbtTx, const size_t szTxLen);
#endif // _LIBNFC_RS232_H_

View file

@ -27,26 +27,26 @@
#include "defines.h"
#include "types.h"
#ifdef HAVE_PCSC_LITE
#include "dev_acr122.h"
#include <drivers/acr122.h>
#endif /* HAVE_PCSC_LITE */
#ifdef HAVE_LIBUSB
#include "dev_pn531.h"
#include "dev_pn533.h"
#include <drivers/pn531.h>
#include <drivers/pn533.h>
#endif /* HAVE_LIBUSB */
#include "dev_arygon.h"
#include "dev_pn532_uart.h"
#include <drivers/arygon.h>
#include <drivers/pn532_uart.h>
const static struct dev_callbacks dev_callbacks_list[] = {
const static struct driver_callbacks drivers_callbacks_list[] = {
// Driver Name Connect Transceive Disconnect
#ifdef HAVE_PCSC_LITE
{ "ACR122", dev_acr122_connect, dev_acr122_transceive, dev_acr122_disconnect },
{ "ACR122", acr122_connect, acr122_transceive, acr122_disconnect },
#endif /* HAVE_PCSC_LITE */
#ifdef HAVE_LIBUSB
{ "PN531USB", dev_pn531_connect, dev_pn531_transceive, dev_pn531_disconnect },
{ "PN533USB", dev_pn533_connect, dev_pn533_transceive, dev_pn533_disconnect },
{ "PN531USB", pn531_connect, pn531_transceive, pn531_disconnect },
{ "PN533USB", pn533_connect, pn533_transceive, pn533_disconnect },
#endif /* HAVE_LIBUSB */
{ "PN532_UART", dev_pn532_uart_connect, dev_pn532_uart_transceive, dev_pn532_uart_disconnect },
{ "ARYGON", dev_arygon_connect, dev_arygon_transceive, dev_arygon_disconnect }
{ "PN532_UART", pn532_uart_connect, pn532_uart_transceive, pn532_uart_disconnect },
{ "ARYGON", arygon_connect, arygon_transceive, arygon_disconnect }
};
#endif // _LIBNFC_DEVICES_H_

View file

@ -0,0 +1,24 @@
# set the include path found by configure
INCLUDES= $(all_includes)
noinst_HEADERS = arygon.h pn532_uart.h
noinst_LTLIBRARIES = libnfcdrivers.la
libnfcdrivers_la_SOURCES = arygon.c pn532_uart.c
libnfcdrivers_la_CFLAGS = -I$(top_srcdir)/src/lib -I$(top_srcdir)/src/lib/buses
libnfcdrivers_la_LIBADD =
if PCSC_LITE_ENABLED
noinst_HEADERS += acr122.h
libnfcdrivers_la_CFLAGS += @LIBPCSCLITE_CFLAGS@ -DHAVE_PCSC_LITE
libnfcdrivers_la_SOURCES += acr122.c
libnfcdrivers_la_LIBADD += @LIBPCSCLITE_LIBS@
endif
if LIBUSB_ENABLED
noinst_HEADERS += pn531.h pn533.h
libnfcdrivers_la_CFLAGS += @LIBUSB_CFLAGS@ -DHAVE_LIBUSB
libnfcdrivers_la_SOURCES += pn531.c pn533.c
libnfcdrivers_la_LIBADD += @LIBUSB_LIBS@
endif
DISTCLEANFILES = Makefile.in

View file

@ -17,11 +17,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*
* @file dev_acr122.c
* @file acr122.c
* @brief
*/
#include "dev_acr122.h"
#include "acr122.h"
#include <stdio.h>
#include <stdlib.h>
@ -35,7 +35,6 @@
#include "defines.h"
#include "messages.h"
#include "bitutils.h"
// WINDOWS: #define IOCTL_CCID_ESCAPE_SCARD_CTL_CODE SCARD_CTL_CODE(3500)
#define IOCTL_CCID_ESCAPE_SCARD_CTL_CODE (((0x31) << 16) | ((3500) << 2))
@ -58,7 +57,7 @@ typedef struct {
SCARD_IO_REQUEST ioCard;
} dev_spec_acr122;
dev_info* dev_acr122_connect(const nfc_device_desc_t* pndd)
dev_info* acr122_connect(const nfc_device_desc_t* pndd)
{
char* pacReaders[MAX_DEVICES];
char acList[256+64*MAX_DEVICES];
@ -131,7 +130,7 @@ dev_info* dev_acr122_connect(const nfc_device_desc_t* pndd)
dsa.ioCard.cbPciLength = sizeof(SCARD_IO_REQUEST);
// Retrieve the current firmware version
pcFirmware = dev_acr122_firmware((dev_info*)&dsa);
pcFirmware = acr122_firmware((dev_info*)&dsa);
if (strstr(pcFirmware,FIRMWARE_TEXT) != NULL)
{
// We found a occurence, test if it has the right index
@ -163,7 +162,7 @@ dev_info* dev_acr122_connect(const nfc_device_desc_t* pndd)
return INVALID_DEVICE_INFO;
}
void dev_acr122_disconnect(dev_info* pdi)
void acr122_disconnect(dev_info* pdi)
{
dev_spec_acr122* pdsa = (dev_spec_acr122*)pdi->ds;
SCardDisconnect(pdsa->hCard,SCARD_LEAVE_CARD);
@ -172,7 +171,7 @@ void dev_acr122_disconnect(dev_info* pdi)
free(pdi);
}
bool dev_acr122_transceive(const dev_spec ds, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen)
bool acr122_transceive(const dev_spec ds, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen)
{
byte_t abtRxCmd[5] = { 0xFF,0xC0,0x00,0x00 };
size_t szRxCmdLen = sizeof(abtRxCmd);
@ -234,7 +233,7 @@ bool dev_acr122_transceive(const dev_spec ds, const byte_t* pbtTx, const size_t
return true;
}
char* dev_acr122_firmware(const dev_spec ds)
char* acr122_firmware(const dev_spec ds)
{
byte_t abtGetFw[5] = { 0xFF,0x00,0x48,0x00,0x00 };
uint32_t uiResult;
@ -260,7 +259,7 @@ char* dev_acr122_firmware(const dev_spec ds)
return abtFw;
}
bool dev_acr122_led_red(const dev_spec ds, bool bOn)
bool acr122_led_red(const dev_spec ds, bool bOn)
{
byte_t abtLed[9] = { 0xFF,0x00,0x40,0x05,0x04,0x00,0x00,0x00,0x00 };
dev_spec_acr122* pdsa = (dev_spec_acr122*)ds;

View file

@ -17,7 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*
* @file dev_acr122.h
* @file acr122.h
* @brief
*/
@ -31,15 +31,15 @@
#include "types.h"
// Functions used by developer to handle connection to this device
dev_info* dev_acr122_connect(const nfc_device_desc_t* pndd);
void dev_acr122_disconnect(dev_info* pdi);
dev_info* acr122_connect(const nfc_device_desc_t* pndd);
void 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_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen);
bool acr122_transceive(const dev_spec ds, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen);
// Various additional features this device supports
char* dev_acr122_firmware(const dev_spec ds);
bool dev_acr122_led_red(const dev_spec ds, bool bOn);
char* acr122_firmware(const dev_spec ds);
bool acr122_led_red(const dev_spec ds, bool bOn);
#endif // _LIBNFC_DEV_ACR122_H_

View file

@ -17,14 +17,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*
* @file dev_arygon.c
* @file arygon.c
* @brief
*/
#include "dev_arygon.h"
#include "arygon.h"
#include "rs232.h"
#include "bitutils.h"
#include "uart.h"
#include "messages.h"
#ifdef _WIN32
@ -73,7 +72,7 @@
* @note ARYGON-APDB2UA33 (PN532 + ARYGON µC): 9600,n,8,1
*/
dev_info* dev_arygon_connect(const nfc_device_desc_t* pndd)
dev_info* arygon_connect(const nfc_device_desc_t* pndd)
{
uint32_t uiDevNr;
serial_port sp;
@ -95,10 +94,10 @@ dev_info* dev_arygon_connect(const nfc_device_desc_t* pndd)
sprintf(acConnect,"%s%d",SERIAL_STRING,uiDevNr);
#endif /* __APPLE__ */
sp = rs232_open(acConnect);
sp = uart_open(acConnect);
if ((sp != INVALID_SERIAL_PORT) && (sp != CLAIMED_SERIAL_PORT))
{
rs232_set_speed(sp, SERIAL_DEFAULT_PORT_SPEED);
uart_set_speed(sp, SERIAL_DEFAULT_PORT_SPEED);
break;
}
#ifdef DEBUG
@ -112,12 +111,12 @@ dev_info* dev_arygon_connect(const nfc_device_desc_t* pndd)
} else {
DBG("Connecting to: %s at %d bauds.",pndd->pcPort, pndd->uiSpeed);
strcpy(acConnect,pndd->pcPort);
sp = rs232_open(acConnect);
sp = uart_open(acConnect);
if (sp == INVALID_SERIAL_PORT) ERR("Invalid serial port: %s",acConnect);
if (sp == CLAIMED_SERIAL_PORT) ERR("Serial port already claimed: %s",acConnect);
if ((sp == CLAIMED_SERIAL_PORT) || (sp == INVALID_SERIAL_PORT)) return INVALID_DEVICE_INFO;
rs232_set_speed(sp, pndd->uiSpeed);
uart_set_speed(sp, pndd->uiSpeed);
}
DBG("Successfully connected to: %s",acConnect);
@ -134,13 +133,13 @@ dev_info* dev_arygon_connect(const nfc_device_desc_t* pndd)
return pdi;
}
void dev_arygon_disconnect(dev_info* pdi)
void arygon_disconnect(dev_info* pdi)
{
rs232_close((serial_port)pdi->ds);
uart_close((serial_port)pdi->ds);
free(pdi);
}
bool dev_arygon_transceive(const dev_spec ds, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen)
bool arygon_transceive(const dev_spec ds, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen)
{
byte_t abtTxBuf[BUFFER_LENGTH] = { DEV_ARYGON_PROTOCOL_TAMA, 0x00, 0x00, 0xff }; // Every packet must start with "00 00 ff"
byte_t abtRxBuf[BUFFER_LENGTH];
@ -168,7 +167,7 @@ bool dev_arygon_transceive(const dev_spec ds, const byte_t* pbtTx, const size_t
printf(" TX: ");
print_hex(abtTxBuf,szTxLen+8);
#endif
if (!rs232_send((serial_port)ds,abtTxBuf,szTxLen+8)) {
if (!uart_send((serial_port)ds,abtTxBuf,szTxLen+8)) {
ERR("Unable to transmit data. (TX)");
return false;
}
@ -188,7 +187,7 @@ bool dev_arygon_transceive(const dev_spec ds, const byte_t* pbtTx, const size_t
* For more information, see Issue 23 on development site : http://code.google.com/p/libnfc/issues/detail?id=23
*/
if (!rs232_receive((serial_port)ds,abtRxBuf,&szRxBufLen)) {
if (!uart_receive((serial_port)ds,abtRxBuf,&szRxBufLen)) {
ERR("Unable to receive data. (RX)");
return false;
}

View file

@ -17,7 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*
* @file dev_arygon.h
* @file arygon.h
* @brief
*/
@ -28,11 +28,11 @@
#include "types.h"
// Functions used by developer to handle connection to this device
dev_info* dev_arygon_connect(const nfc_device_desc_t* pndd);
void dev_arygon_disconnect(dev_info* pdi);
dev_info* arygon_connect(const nfc_device_desc_t* pndd);
void 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_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen);
bool arygon_transceive(const dev_spec ds, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen);
#endif // _LIBNFC_DEV_ARYGON_H_

View file

@ -17,7 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*
* @file dev_pn531.c
* @file pn531.c
* @brief
*/
@ -32,8 +32,7 @@ Thanks to d18c7db and Okko for example code
#include <string.h>
#include "defines.h"
#include "dev_pn531.h"
#include "bitutils.h"
#include "pn531.h"
#include "messages.h"
#define BUFFER_LENGTH 256
@ -81,7 +80,7 @@ static void get_end_points(struct usb_device *dev, dev_spec_pn531* pdsp)
}
}
dev_info* dev_pn531_connect(const nfc_device_desc_t* pndd)
dev_info* pn531_connect(const nfc_device_desc_t* pndd)
{
int idvendor = 0x04CC;
int idproduct = 0x0531;
@ -163,7 +162,7 @@ dev_info* dev_pn531_connect(const nfc_device_desc_t* pndd)
return pdi;
}
void dev_pn531_disconnect(dev_info* pdi)
void pn531_disconnect(dev_info* pdi)
{
dev_spec_pn531* pdsp = (dev_spec_pn531*)pdi->ds;
usb_release_interface(pdsp->pudh,0);
@ -172,7 +171,7 @@ void dev_pn531_disconnect(dev_info* pdi)
free(pdi);
}
bool dev_pn531_transceive(const dev_spec ds, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen)
bool pn531_transceive(const dev_spec ds, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen)
{
size_t uiPos = 0;
int ret = 0;

View file

@ -17,7 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*
* @file dev_pn531.h
* @file pn531.h
* @brief
*/
@ -31,11 +31,11 @@
#include "types.h"
// Functions used by developer to handle connection to this device
dev_info* dev_pn531_connect(const nfc_device_desc_t* pndd);
void dev_pn531_disconnect(dev_info* pdi);
dev_info* pn531_connect(const nfc_device_desc_t* pndd);
void 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_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen);
bool pn531_transceive(const dev_spec ds, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen);
#endif // _LIBNFC_DEV_PN531_H_

View file

@ -17,14 +17,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*
* @file dev_pn532_uart.c
* @file pn532_uart.c
* @brief
*/
#include "dev_pn532_uart.h"
#include "pn532_uart.h"
#include "rs232.h"
#include "bitutils.h"
#include "uart.h"
#include "messages.h"
#ifdef _WIN32
@ -48,7 +47,7 @@
#define SERIAL_DEFAULT_PORT_SPEED 115200
dev_info* dev_pn532_uart_connect(const nfc_device_desc_t* pndd)
dev_info* pn532_uart_connect(const nfc_device_desc_t* pndd)
{
uint32_t uiDevNr;
serial_port sp;
@ -70,10 +69,10 @@ dev_info* dev_pn532_uart_connect(const nfc_device_desc_t* pndd)
sprintf(acConnect,"%s%d",SERIAL_STRING,uiDevNr);
#endif /* __APPLE__ */
sp = rs232_open(acConnect);
sp = uart_open(acConnect);
if ((sp != INVALID_SERIAL_PORT) && (sp != CLAIMED_SERIAL_PORT))
{
rs232_set_speed(sp, SERIAL_DEFAULT_PORT_SPEED);
uart_set_speed(sp, SERIAL_DEFAULT_PORT_SPEED);
break;
}
#ifdef DEBUG
@ -87,12 +86,12 @@ dev_info* dev_pn532_uart_connect(const nfc_device_desc_t* pndd)
} else {
DBG("Connecting to: %s at %d bauds.",pndd->pcPort, pndd->uiSpeed);
strcpy(acConnect,pndd->pcPort);
sp = rs232_open(acConnect);
sp = uart_open(acConnect);
if (sp == INVALID_SERIAL_PORT) ERR("Invalid serial port: %s",acConnect);
if (sp == CLAIMED_SERIAL_PORT) ERR("Serial port already claimed: %s",acConnect);
if ((sp == CLAIMED_SERIAL_PORT) || (sp == INVALID_SERIAL_PORT)) return INVALID_DEVICE_INFO;
rs232_set_speed(sp, pndd->uiSpeed);
uart_set_speed(sp, pndd->uiSpeed);
}
/** @info PN532C106 wakeup. */
/** @todo Put this command in pn53x init process */
@ -100,10 +99,10 @@ dev_info* dev_pn532_uart_connect(const nfc_device_desc_t* pndd)
size_t szRxBufLen;
const byte_t pncmd_pn532c106_wakeup[] = { 0x55,0x55,0x00,0x00,0x00,0x00,0x00,0xFF,0x03,0xFD,0xD4,0x14,0x01,0x17,0x00 };
rs232_send(sp, pncmd_pn532c106_wakeup, sizeof(pncmd_pn532c106_wakeup));
uart_send(sp, pncmd_pn532c106_wakeup, sizeof(pncmd_pn532c106_wakeup));
delay_ms(10);
if (!rs232_receive(sp,abtRxBuf,&szRxBufLen)) {
if (!uart_receive(sp,abtRxBuf,&szRxBufLen)) {
ERR("Unable to receive data. (RX)");
return NULL;
}
@ -126,13 +125,13 @@ dev_info* dev_pn532_uart_connect(const nfc_device_desc_t* pndd)
return pdi;
}
void dev_pn532_uart_disconnect(dev_info* pdi)
void pn532_uart_disconnect(dev_info* pdi)
{
rs232_close((serial_port)pdi->ds);
uart_close((serial_port)pdi->ds);
free(pdi);
}
bool dev_pn532_uart_transceive(const dev_spec ds, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen)
bool pn532_uart_transceive(const dev_spec ds, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen)
{
byte_t abtTxBuf[BUFFER_LENGTH] = { 0x00, 0x00, 0xff }; // Every packet must start with "00 00 ff"
byte_t abtRxBuf[BUFFER_LENGTH];
@ -160,7 +159,7 @@ bool dev_pn532_uart_transceive(const dev_spec ds, const byte_t* pbtTx, const siz
printf(" TX: ");
print_hex(abtTxBuf,szTxLen+7);
#endif
if (!rs232_send((serial_port)ds,abtTxBuf,szTxLen+7)) {
if (!uart_send((serial_port)ds,abtTxBuf,szTxLen+7)) {
ERR("Unable to transmit data. (TX)");
return false;
}
@ -175,7 +174,7 @@ bool dev_pn532_uart_transceive(const dev_spec ds, const byte_t* pbtTx, const siz
*/
delay_ms(30);
if (!rs232_receive((serial_port)ds,abtRxBuf,&szRxBufLen)) {
if (!uart_receive((serial_port)ds,abtRxBuf,&szRxBufLen)) {
ERR("Unable to receive data. (RX)");
return false;
}

View file

@ -17,7 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*
* @file dev_pn532_uart.h
* @file pn532_uart.h
* @brief
*/
@ -28,11 +28,11 @@
#include "types.h"
// Functions used by developer to handle connection to this device
dev_info* dev_pn532_uart_connect(const nfc_device_desc_t* pndd);
void dev_pn532_uart_disconnect(dev_info* pdi);
dev_info* pn532_uart_connect(const nfc_device_desc_t* pndd);
void pn532_uart_disconnect(dev_info* pdi);
// Callback function used by libnfc to transmit commands to the PN53X chip
bool dev_pn532_uart_transceive(const dev_spec ds, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen);
bool pn532_uart_transceive(const dev_spec ds, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen);
#endif // _LIBNFC_DEV_PN532_UART_H_

View file

@ -17,21 +17,20 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*
* @file dev_pn533.c
* @file pn533.c
* @brief
*/
/*
Thanks to d18c7db and Okko for example code
*/
#include "dev_pn533.h"
#include "pn533.h"
#include <usb.h>
#include <stdio.h>
#include <string.h>
#include "defines.h"
#include "bitutils.h"
#include "messages.h"
#define BUFFER_LENGTH 256
@ -79,7 +78,7 @@ static void get_end_points(struct usb_device *dev, dev_spec_pn533* pdsp)
}
}
dev_info* dev_pn533_connect(const nfc_device_desc_t* pndd)
dev_info* pn533_connect(const nfc_device_desc_t* pndd)
{
int idvendor = 0x04e6;
int idproduct = 0x5591;
@ -158,7 +157,7 @@ dev_info* dev_pn533_connect(const nfc_device_desc_t* pndd)
return pdi;
}
void dev_pn533_disconnect(dev_info* pdi)
void pn533_disconnect(dev_info* pdi)
{
dev_spec_pn533* pdsp = (dev_spec_pn533*)pdi->ds;
usb_release_interface(pdsp->pudh,0);
@ -167,7 +166,7 @@ void dev_pn533_disconnect(dev_info* pdi)
free(pdi);
}
bool dev_pn533_transceive(const dev_spec ds, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen)
bool pn533_transceive(const dev_spec ds, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen)
{
size_t uiPos = 0;
int ret = 0;

View file

@ -17,7 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*
* @file dev_pn533.h
* @file pn533.h
* @brief
*/
@ -28,11 +28,11 @@
#include "types.h"
// Functions used by developer to handle connection to this device
dev_info* dev_pn533_connect(const nfc_device_desc_t* pndd);
void dev_pn533_disconnect(dev_info* pdi);
dev_info* pn533_connect(const nfc_device_desc_t* pndd);
void 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_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen);
bool pn533_transceive(const dev_spec ds, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen);
#endif // _LIBNFC_DEV_PN533_H_

View file

@ -17,22 +17,21 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*
* @file libnfc.c
* @file nfc.c
* @brief
*/
#include "libnfc.h"
#include "nfc.h"
#include <stdio.h>
#include <stddef.h>
#include <string.h>
#include "devices.h"
#include "drivers.h"
#include "bitutils.h"
#include "messages.h"
#include "../config.h"
#include "../../config.h"
// Registers and symbols masks used to covers parts within a register
#define REG_CIU_TX_MODE 0x6302
@ -285,20 +284,20 @@ dev_info* nfc_connect(nfc_device_desc_t* pndd)
size_t szFwLen = sizeof(abtFw);
// Search through the device list for an available device
for (uiDev=0; uiDev<sizeof(dev_callbacks_list)/sizeof(dev_callbacks_list[0]); uiDev++)
for (uiDev=0; uiDev<sizeof(drivers_callbacks_list)/sizeof(drivers_callbacks_list[0]); uiDev++)
{
if (pndd == NULL) {
// No device description specified: try to automatically claim a device
pdi = dev_callbacks_list[uiDev].connect(pndd);
pdi = drivers_callbacks_list[uiDev].connect(pndd);
} else {
// Specific device is requested: using device description pndd
if( 0 != strcmp(dev_callbacks_list[uiDev].acDriver, pndd->pcDriver ) )
if( 0 != strcmp(drivers_callbacks_list[uiDev].acDriver, pndd->pcDriver ) )
{
DBG("Looking for %s, found %s... Skip it.", pndd->pcDriver, dev_callbacks_list[uiDev].acDriver);
DBG("Looking for %s, found %s... Skip it.", pndd->pcDriver, drivers_callbacks_list[uiDev].acDriver);
continue;
} else {
DBG("Looking for %s, found %s... Use it.", pndd->pcDriver, dev_callbacks_list[uiDev].acDriver);
pdi = dev_callbacks_list[uiDev].connect(pndd);
DBG("Looking for %s, found %s... Use it.", pndd->pcDriver, drivers_callbacks_list[uiDev].acDriver);
pdi = drivers_callbacks_list[uiDev].connect(pndd);
}
}
@ -307,7 +306,7 @@ dev_info* nfc_connect(nfc_device_desc_t* pndd)
{
DBG("[%s] has been claimed.", pdi->acName);
// Great we have claimed a device
pdi->pdc = &(dev_callbacks_list[uiDev]);
pdi->pdc = &(drivers_callbacks_list[uiDev]);
// Try to retrieve PN53x chip revision
// We can not use pn53x_transceive() because abtRx[0] gives no status info
@ -339,7 +338,7 @@ dev_info* nfc_connect(nfc_device_desc_t* pndd)
return pdi;
} else {
DBG("No device found using driver: %s", dev_callbacks_list[uiDev].acDriver);
DBG("No device found using driver: %s", drivers_callbacks_list[uiDev].acDriver);
}
}
// To bad, no reader is ready to be claimed

View file

@ -44,7 +44,7 @@ typedef enum {
CT_PN533 = 0x30,
} chip_type;
struct dev_callbacks; // Prototype the callback struct
struct driver_callbacks; // Prototype the callback struct
/**
* @struct dev_info
@ -52,7 +52,7 @@ struct dev_callbacks; // Prototype the callback struct
*/
typedef struct {
/** Callback functions for handling device specific wrapping */
const struct dev_callbacks* pdc;
const struct driver_callbacks* pdc;
/** Device name string, including device wrapper firmware */
char acName[DEVICE_NAME_LENGTH];
/** PN53X chip type, this is useful for some "bug" work-arounds */
@ -87,10 +87,10 @@ typedef struct {
} nfc_device_desc_t;
/**
* @struct dev_callbacks
* @struct driver_callbacks
* @brief NFC defice callbacks
*/
struct dev_callbacks {
struct driver_callbacks {
/** Driver name */
const char* acDriver;
/** Connect callback */