Remove nfc-defines.h public header.

Use NULL instead of INVALID_DEVICE_INFO to know if device is valid.
Make distcheck OK
This commit is contained in:
Romuald Conty 2009-11-10 09:47:59 +00:00
parent 9fccd11fc7
commit aa8bb42d9f
27 changed files with 106 additions and 111 deletions

View file

@ -24,8 +24,6 @@
#ifndef _LIBNFC_MIFARE_TAG_H_
#define _LIBNFC_MIFARE_TAG_H_
#include "nfc-defines.h"
typedef struct {
byte_t abtUID[4];
byte_t btBCC;

View file

@ -24,8 +24,6 @@
#ifndef _LIBNFC_MIFARE_UL_TAG_H_
#define _LIBNFC_MIFARE_UL_TAG_H_
#include "nfc-defines.h"
typedef struct {
byte_t sn0[3];
byte_t btBCC0;

View file

@ -35,6 +35,8 @@
#define SAK_FLAG_ATS_SUPPORTED 0x20
#define MAX_FRAME_LEN 264
static byte_t abtRx[MAX_FRAME_LEN];
static size_t szRxBits;
static size_t szRxLen;

View file

@ -32,6 +32,8 @@
#include "nfc-messages.h"
#include "bitutils.h"
#define MAX_FRAME_LEN 264
static byte_t abtRecv[MAX_FRAME_LEN];
static size_t szRecvBits;
static nfc_device_t* pnd;
@ -87,7 +89,7 @@ int main(int argc, char *argv[])
// Try to open the NFC reader
pnd = nfc_connect(NULL);
if (pnd == INVALID_DEVICE_INFO)
if (pnd == NULL)
{
printf("Error connecting NFC reader\n");
return 1;

View file

@ -52,7 +52,7 @@ int main(int argc, const char* argv[])
pnd = nfc_connect(&ndd);
*/
if (pnd == INVALID_DEVICE_INFO)
if (pnd == NULL)
{
ERR("Unable to connect to NFC device.");
return 1;

View file

@ -405,7 +405,7 @@ int main(int argc, const char* argv[])
// Try to open the NFC reader
pnd = nfc_connect(NULL);
if (pnd == INVALID_DEVICE_INFO)
if (pnd == NULL)
{
printf("Error connecting NFC reader\n");
return 1;

View file

@ -149,7 +149,7 @@ int main(int argc, const char* argv[])
// Try to open the NFC reader
pnd = nfc_connect(NULL);
if (pnd == INVALID_DEVICE_INFO)
if (pnd == NULL)
{
printf("Error connecting NFC reader\n");
return 1;

View file

@ -31,6 +31,8 @@
#include "nfc-messages.h"
#include "bitutils.h"
#define MAX_FRAME_LEN 264
static byte_t abtReaderRx[MAX_FRAME_LEN];
static byte_t abtReaderRxPar[MAX_FRAME_LEN];
static size_t szReaderRxBits;
@ -70,7 +72,7 @@ int main(int argc,char* argv[])
// Try to open the NFC emulator device
pndTag = nfc_connect(NULL);
if (pndTag == INVALID_DEVICE_INFO)
if (pndTag == NULL)
{
printf("Error connecting NFC emulator device\n");
return 1;
@ -89,8 +91,8 @@ int main(int argc,char* argv[])
printf("[+] Thank you, the emulated tag is initialized\n");
// Try to open the NFC reader
pndReader = INVALID_DEVICE_INFO;
while (pndReader == INVALID_DEVICE_INFO) pndReader = nfc_connect(NULL);
pndReader = NULL;
while (pndReader == NULL) pndReader = nfc_connect(NULL);
printf("[+] Configuring NFC reader settings\n");
nfc_configure(pndReader,DCO_HANDLE_CRC,false);
nfc_configure(pndReader,DCO_HANDLE_PARITY,false);

View file

@ -25,6 +25,8 @@
#include <string.h>
#include <nfc.h>
#define MAX_FRAME_LEN 264
int main(int argc, const char *argv[])
{
nfc_device_t *pnd;

View file

@ -24,6 +24,8 @@
#include <stdio.h>
#include <nfc.h>
#define MAX_FRAME_LEN 264
int main(int argc, const char *argv[])
{
byte_t abtRecv[MAX_FRAME_LEN];

View file

@ -19,7 +19,7 @@ IF(LIBNFC_USB)
FIND_PACKAGE(LIBUSB REQUIRED)
ADD_DEFINITIONS("-DHAVE_LIBUSB=1")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${LIBUSB_CFLAGS_OTHER}")
SET(DRIVERS_SOURCES ${DRIVERS_SOURCES} "drivers/pn531" "drivers/pn533")
SET(DRIVERS_SOURCES ${DRIVERS_SOURCES} "drivers/pn531_usb" "drivers/pn533_usb")
ENDIF(LIBNFC_USB)

View file

@ -3,7 +3,7 @@ SUBDIRS = buses drivers .
# set the include path found by configure
INCLUDES= $(all_includes)
nfcinclude_HEADERS = nfc.h nfc-defines.h nfc-types.h buses.h drivers.h nfc-messages.h bitutils.h
nfcinclude_HEADERS = nfc.h nfc-types.h buses.h drivers.h nfc-messages.h bitutils.h
nfcincludedir = $(includedir)/nfc
lib_LTLIBRARIES = libnfc.la

View file

@ -28,7 +28,7 @@
#include <string.h>
#include <stdlib.h>
#include "nfc-defines.h"
#include "nfc-types.h"
// Handle platform specific includes

View file

@ -17,33 +17,40 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*
* @file devices.h
* @file drivers.h
* @brief
*/
#ifndef _LIBNFC_DEVICES_H_
#define _LIBNFC_DEVICES_H_
#include "nfc-defines.h"
#include "nfc-types.h"
#ifdef HAVE_PCSC_LITE
#include "drivers/acr122.h"
#endif /* HAVE_PCSC_LITE */
#ifdef HAVE_LIBUSB
#include "drivers/pn531.h"
#include "drivers/pn533.h"
#include "drivers/pn531_usb.h"
#include "drivers/pn533_usb.h"
#endif /* HAVE_LIBUSB */
#include "drivers/arygon.h"
#include "drivers/pn532_uart.h"
#define DRIVERS_MAX_DEVICES 16
#define INVALID_DEVICE_INFO 0
#define MAX_FRAME_LEN 264
const static struct driver_callbacks drivers_callbacks_list[] = {
// Driver Name Connect Transceive Disconnect
#ifdef HAVE_PCSC_LITE
{ "ACR122", acr122_connect, acr122_transceive, acr122_disconnect },
#endif /* HAVE_PCSC_LITE */
#ifdef HAVE_LIBUSB
{ "PN531USB", pn531_connect, pn531_transceive, pn531_disconnect },
{ "PN533USB", pn533_connect, pn533_transceive, pn533_disconnect },
{ "PN531USB", pn531_usb_connect, pn531_usb_transceive, pn531_usb_disconnect },
{ "PN533USB", pn533_usb_connect, pn533_usb_transceive, pn533_usb_disconnect },
#endif /* HAVE_LIBUSB */
{ "PN532_UART", pn532_uart_connect, pn532_uart_transceive, pn532_uart_disconnect },
{ "ARYGON", arygon_connect, arygon_transceive, arygon_disconnect }

View file

@ -15,9 +15,9 @@ if PCSC_LITE_ENABLED
endif
if LIBUSB_ENABLED
noinst_HEADERS += pn531.h pn533.h
noinst_HEADERS += pn531_usb.h pn533_usb.h
libnfcdrivers_la_CFLAGS += @LIBUSB_CFLAGS@ -DHAVE_LIBUSB
libnfcdrivers_la_SOURCES += pn531.c pn533.c
libnfcdrivers_la_SOURCES += pn531_usb.c pn533_usb.c
libnfcdrivers_la_LIBADD += @LIBUSB_LIBS@
endif

View file

@ -27,13 +27,17 @@
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include "../drivers.h"
// Bus
#include <winscard.h>
#ifdef __APPLE__
#include <wintypes.h>
#endif
#include "nfc-defines.h"
#include "nfc-messages.h"
// WINDOWS: #define IOCTL_CCID_ESCAPE_SCARD_CTL_CODE SCARD_CTL_CODE(3500)
@ -59,8 +63,8 @@ typedef struct {
nfc_device_t* acr122_connect(const nfc_device_desc_t* pndd)
{
char* pacReaders[MAX_DEVICES];
char acList[256+64*MAX_DEVICES];
char* pacReaders[DRIVERS_MAX_DEVICES];
char acList[256+64*DRIVERS_MAX_DEVICES];
size_t szListLen = sizeof(acList);
size_t szPos;
uint32_t uiReaderCount;
@ -88,7 +92,7 @@ nfc_device_t* acr122_connect(const nfc_device_desc_t* pndd)
for (szPos=0; szPos<szListLen; szPos++)
{
// Make sure don't break out of our reader array
if (uiReaderCount == MAX_DEVICES) break;
if (uiReaderCount == DRIVERS_MAX_DEVICES) break;
// Test if there is a next reader available
if (acList[szPos] == 0x00)

View file

@ -27,7 +27,7 @@
#include <stdint.h>
#include <stdbool.h>
#include "nfc-defines.h"
#include "nfc-types.h"
// Functions used by developer to handle connection to this device

View file

@ -23,9 +23,12 @@
#include "arygon.h"
#include "uart.h"
#include "nfc-messages.h"
#include "../drivers.h"
// Bus
#include "uart.h"
#ifdef _WIN32
#define SERIAL_STRING "COM"
#define delay_ms( X ) Sleep( X )
@ -86,7 +89,7 @@ nfc_device_t* arygon_connect(const nfc_device_desc_t* pndd)
#else
DBG("Trying to find ARYGON device on serial port: %s# at %d bauds.",SERIAL_STRING, SERIAL_DEFAULT_PORT_SPEED);
// I have no idea how MAC OS X deals with multiple devices, so a quick workaround
for (uiDevNr=0; uiDevNr<MAX_DEVICES; uiDevNr++)
for (uiDevNr=0; uiDevNr<DRIVERS_MAX_DEVICES; uiDevNr++)
{
#ifdef __APPLE__
strcpy(acConnect,SERIAL_STRING);
@ -107,7 +110,7 @@ nfc_device_t* arygon_connect(const nfc_device_desc_t* pndd)
}
#endif
// Test if we have found a device
if (uiDevNr == MAX_DEVICES) return INVALID_DEVICE_INFO;
if (uiDevNr == DRIVERS_MAX_DEVICES) return INVALID_DEVICE_INFO;
} else {
DBG("Connecting to: %s at %d bauds.",pndd->pcPort, pndd->uiSpeed);
strcpy(acConnect,pndd->pcPort);

View file

@ -24,7 +24,7 @@
#ifndef _LIBNFC_DEV_ARYGON_H_
#define _LIBNFC_DEV_ARYGON_H_
#include "nfc-defines.h"
#include "nfc-types.h"
// Functions used by developer to handle connection to this device

View file

@ -17,22 +17,24 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*
* @file pn531.c
* @brief
* @file pn531_usb.c
* @brief Driver for PN531 chip using USB
*/
/*
Thanks to d18c7db and Okko for example code
*/
#include "pn531_usb.h"
#include <stdio.h>
#include <stddef.h>
#include <usb.h>
#include <string.h>
#include "nfc-defines.h"
#include "pn531.h"
#include "../drivers.h"
// Bus
#include <usb.h>
#include "nfc-messages.h"
#define BUFFER_LENGTH 256
@ -42,10 +44,10 @@ typedef struct {
usb_dev_handle* pudh;
uint32_t uiEndPointIn;
uint32_t uiEndPointOut;
} dev_spec_pn531;
} dev_spec_pn531_usb;
// Find transfer endpoints for bulk transfers
static void get_end_points(struct usb_device *dev, dev_spec_pn531* pdsp)
static void get_end_points(struct usb_device *dev, dev_spec_pn531_usb* pdsp)
{
uint32_t uiIndex;
uint32_t uiEndPoint;
@ -80,7 +82,7 @@ static void get_end_points(struct usb_device *dev, dev_spec_pn531* pdsp)
}
}
nfc_device_t* pn531_connect(const nfc_device_desc_t* pndd)
nfc_device_t* pn531_usb_connect(const nfc_device_desc_t* pndd)
{
int idvendor = 0x04CC;
int idproduct = 0x0531;
@ -89,8 +91,8 @@ nfc_device_t* pn531_connect(const nfc_device_desc_t* pndd)
struct usb_bus *bus;
struct usb_device *dev;
nfc_device_t* pnd = INVALID_DEVICE_INFO;
dev_spec_pn531* pdsp;
dev_spec_pn531 dsp;
dev_spec_pn531_usb* pdsp;
dev_spec_pn531_usb dsp;
uint32_t uiDevIndex;
dsp.uiEndPointIn = 0;
@ -145,7 +147,7 @@ nfc_device_t* pn531_connect(const nfc_device_desc_t* pndd)
return INVALID_DEVICE_INFO;
}
// Allocate memory for the device info and specification, fill it and return the info
pdsp = malloc(sizeof(dev_spec_pn531));
pdsp = malloc(sizeof(dev_spec_pn531_usb));
*pdsp = dsp;
pnd = malloc(sizeof(nfc_device_t));
strcpy(pnd->acName,"PN531USB");
@ -162,22 +164,22 @@ nfc_device_t* pn531_connect(const nfc_device_desc_t* pndd)
return pnd;
}
void pn531_disconnect(nfc_device_t* pnd)
void pn531_usb_disconnect(nfc_device_t* pnd)
{
dev_spec_pn531* pdsp = (dev_spec_pn531*)pnd->ds;
dev_spec_pn531_usb* pdsp = (dev_spec_pn531_usb*)pnd->ds;
usb_release_interface(pdsp->pudh,0);
usb_close(pdsp->pudh);
free(pnd->ds);
free(pnd);
}
bool pn531_transceive(const dev_spec ds, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen)
bool pn531_usb_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;
byte_t abtTx[BUFFER_LENGTH] = { 0x00, 0x00, 0xff }; // Every packet must start with "00 00 ff"
byte_t abtRx[BUFFER_LENGTH];
dev_spec_pn531* pdsp = (dev_spec_pn531*)ds;
dev_spec_pn531_usb* pdsp = (dev_spec_pn531_usb*)ds;
// Packet length = data length (len) + checksum (1) + end of stream marker (1)
abtTx[3] = szTxLen;

View file

@ -17,7 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*
* @file pn531.h
* @file pn531_usb.h
* @brief
*/
@ -27,15 +27,15 @@
#include <stdint.h>
#include <stdbool.h>
#include "nfc-defines.h"
#include "nfc-types.h"
// Functions used by developer to handle connection to this device
nfc_device_t* pn531_connect(const nfc_device_desc_t* pndd);
void pn531_disconnect(nfc_device_t* pnd);
nfc_device_t* pn531_usb_connect(const nfc_device_desc_t* pndd);
void pn531_usb_disconnect(nfc_device_t* pnd);
// Callback function used by libnfc to transmit commands to the PN53X chip
bool pn531_transceive(const dev_spec ds, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen);
bool pn531_usb_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

@ -23,9 +23,13 @@
#include "pn532_uart.h"
#include "uart.h"
#include "nfc-messages.h"
#include "../drivers.h"
// Bus
#include "uart.h"
#ifdef _WIN32
#define SERIAL_STRING "COM"
#define delay_ms( X ) Sleep( X )
@ -61,7 +65,7 @@ nfc_device_t* pn532_uart_connect(const nfc_device_desc_t* pndd)
#else
DBG("Trying to find ARYGON device on serial port: %s# at %d bauds.",SERIAL_STRING, SERIAL_DEFAULT_PORT_SPEED);
// I have no idea how MAC OS X deals with multiple devices, so a quick workaround
for (uiDevNr=0; uiDevNr<MAX_DEVICES; uiDevNr++)
for (uiDevNr=0; uiDevNr<DRIVERS_MAX_DEVICES; uiDevNr++)
{
#ifdef __APPLE__
strcpy(acConnect,SERIAL_STRING);
@ -82,7 +86,7 @@ nfc_device_t* pn532_uart_connect(const nfc_device_desc_t* pndd)
}
#endif
// Test if we have found a device
if (uiDevNr == MAX_DEVICES) return INVALID_DEVICE_INFO;
if (uiDevNr == DRIVERS_MAX_DEVICES) return INVALID_DEVICE_INFO;
} else {
DBG("Connecting to: %s at %d bauds.",pndd->pcPort, pndd->uiSpeed);
strcpy(acConnect,pndd->pcPort);

View file

@ -24,7 +24,7 @@
#ifndef _LIBNFC_DEV_PN532_UART_H_
#define _LIBNFC_DEV_PN532_UART_H_
#include "nfc-defines.h"
#include "nfc-types.h"
// Functions used by developer to handle connection to this device

View file

@ -17,20 +17,23 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*
* @file pn533.c
* @brief
* @file pn533_usb.c
* @brief Driver for PN533 chip using USB
*/
/*
Thanks to d18c7db and Okko for example code
*/
#include "pn533.h"
#include "pn533_usb.h"
#include <usb.h>
#include <stdio.h>
#include <string.h>
#include "nfc-defines.h"
#include "../drivers.h"
// Bus
#include <usb.h>
#include "nfc-messages.h"
#define BUFFER_LENGTH 256
@ -40,10 +43,10 @@ typedef struct {
usb_dev_handle* pudh;
uint32_t uiEndPointIn;
uint32_t uiEndPointOut;
} dev_spec_pn533;
} dev_spec_pn533_usb;
// Find transfer endpoints for bulk transfers
static void get_end_points(struct usb_device *dev, dev_spec_pn533* pdsp)
static void get_end_points(struct usb_device *dev, dev_spec_pn533_usb* pdsp)
{
uint32_t uiIndex;
uint32_t uiEndPoint;
@ -78,15 +81,15 @@ static void get_end_points(struct usb_device *dev, dev_spec_pn533* pdsp)
}
}
nfc_device_t* pn533_connect(const nfc_device_desc_t* pndd)
nfc_device_t* pn533_usb_connect(const nfc_device_desc_t* pndd)
{
int idvendor = 0x04e6;
int idproduct = 0x5591;
struct usb_bus *bus;
struct usb_device *dev;
nfc_device_t* pnd = INVALID_DEVICE_INFO;
dev_spec_pn533* pdsp;
dev_spec_pn533 dsp;
dev_spec_pn533_usb* pdsp;
dev_spec_pn533_usb dsp;
uint32_t uiDevIndex;
dsp.uiEndPointIn = 0;
@ -140,7 +143,7 @@ nfc_device_t* pn533_connect(const nfc_device_desc_t* pndd)
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 = malloc(sizeof(dev_spec_pn533_usb));
*pdsp = dsp;
pnd = malloc(sizeof(nfc_device_t));
strcpy(pnd->acName,"PN533USB");
@ -157,22 +160,22 @@ nfc_device_t* pn533_connect(const nfc_device_desc_t* pndd)
return pnd;
}
void pn533_disconnect(nfc_device_t* pnd)
void pn533_usb_disconnect(nfc_device_t* pnd)
{
dev_spec_pn533* pdsp = (dev_spec_pn533*)pnd->ds;
dev_spec_pn533_usb* pdsp = (dev_spec_pn533_usb*)pnd->ds;
usb_release_interface(pdsp->pudh,0);
usb_close(pdsp->pudh);
free(pnd->ds);
free(pnd);
}
bool pn533_transceive(const dev_spec ds, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen)
bool pn533_usb_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;
byte_t abtTx[BUFFER_LENGTH] = { 0x00, 0x00, 0xff }; // Every packet must start with "00 00 ff"
byte_t abtRx[BUFFER_LENGTH];
dev_spec_pn533* pdsp = (dev_spec_pn533*)ds;
dev_spec_pn533_usb* pdsp = (dev_spec_pn533_usb*)ds;
// Packet length = data length (len) + checksum (1) + end of stream marker (1)
abtTx[3] = szTxLen;

View file

@ -17,22 +17,22 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*
* @file pn533.h
* @file pn533_usb.h
* @brief
*/
#ifndef _LIBNFC_DEV_PN533_H_
#define _LIBNFC_DEV_PN533_H_
#include "nfc-defines.h"
#include "nfc-types.h"
// Functions used by developer to handle connection to this device
nfc_device_t* pn533_connect(const nfc_device_desc_t* pndd);
void pn533_disconnect(nfc_device_t* pnd);
nfc_device_t* pn533_usb_connect(const nfc_device_desc_t* pndd);
void pn533_usb_disconnect(nfc_device_t* pnd);
// Callback function used by libnfc to transmit commands to the PN53X chip
bool pn533_transceive(const dev_spec ds, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen);
bool pn533_usb_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

@ -1,34 +0,0 @@
/**
* 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 nfc-defines.h
* @brief
*/
#ifndef __NFC_DEFINES_H__
#define __NFC_DEFINES_H__
/* DEBUG flag can also be enabled using ./configure --enable-debug */
/* #define DEBUG */
#define INVALID_DEVICE_INFO 0
#define MAX_FRAME_LEN 264
#define MAX_DEVICES 16
#endif // _LIBNFC_DEFINES_H_

View file

@ -29,7 +29,7 @@
#include <stdint.h>
#include <stdbool.h>
#include "nfc-defines.h"
#include "nfc-types.h"
#ifdef __cplusplus