...
 
Commits (11)
......@@ -101,7 +101,7 @@ IF(NOT WIN32)
SET(exec_prefix ${CMAKE_INSTALL_PREFIX})
SET(PACKAGE "libnfc")
IF(LIBNFC_DRIVER_PN53X_USB)
SET(PKG_REQ ${PKG_REQ} "libusb")
SET(PKG_REQ ${PKG_REQ} "libusb-1.0")
ENDIF(LIBNFC_DRIVER_PN53X_USB)
IF(LIBNFC_DRIVER_ACR122)
SET(PKG_REQ ${PKG_REQ} "libpcsclite")
......@@ -128,11 +128,11 @@ IF(PCSC_INCLUDE_DIRS)
LINK_DIRECTORIES(${PCSC_LIBRARY_DIRS})
ENDIF(PCSC_INCLUDE_DIRS)
IF(LIBUSB_INCLUDE_DIRS)
INCLUDE_DIRECTORIES(${LIBUSB_INCLUDE_DIRS})
LINK_DIRECTORIES(${LIBUSB_LIBRARY_DIRS})
SET(LIBUSB_FOUND TRUE)
ENDIF(LIBUSB_INCLUDE_DIRS)
IF(LIBUSB_1_INCLUDE_DIRS)
INCLUDE_DIRECTORIES(${LIBUSB_1_INCLUDE_DIRS})
LINK_DIRECTORIES(${LIBUSB_1_LIBRARY_DIRS})
SET(LIBUSB_1_FOUND TRUE)
ENDIF(LIBUSB_1_INCLUDE_DIRS)
# version.rc for Windows
IF(WIN32)
......@@ -148,7 +148,7 @@ IF(WIN32)
SET(RC_COMMENT "${PACKAGE_NAME} library")
SET(RC_INTERNAL_NAME "${PACKAGE_NAME} ${WIN32_MODE}")
SET(RC_ORIGINAL_NAME ${PACKAGE_NAME}.dll)
SET(RC_FILE_TYPE VFT_DLL)
SET(RC_FILE_T`YPE VFT_DLL)
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/contrib/win32/version.rc.in ${CMAKE_CURRENT_BINARY_DIR}/windows/libnfc.rc @ONLY)
ENDIF(WIN32)
......
# This CMake script wants to use libusb functionality, therefore it looks
# for libusb include files and libraries.
#
# Operating Systems Supported:
# - Unix (requires pkg-config)
# Tested with Ubuntu 9.04 and Fedora 11
# - Windows (requires MinGW)
# Tested with Windows XP/Windows 7
#
# This should work for both 32 bit and 64 bit systems.
#
# Author: F. Kooman <fkooman@tuxed.net>
#
# FreeBSD has built-in libusb since 800069
IF(CMAKE_SYSTEM_NAME MATCHES FreeBSD)
EXEC_PROGRAM(sysctl ARGS -n kern.osreldate OUTPUT_VARIABLE FREEBSD_VERSION)
SET(MIN_FREEBSD_VERSION 800068)
IF(FREEBSD_VERSION GREATER ${MIN_FREEBSD_VERSION})
SET(LIBUSB_FOUND TRUE)
SET(LIBUSB_INCLUDE_DIRS "/usr/include")
SET(LIBUSB_LIBRARIES "usb")
SET(LIBUSB_LIBRARY_DIRS "/usr/lib/")
ENDIF(FREEBSD_VERSION GREATER ${MIN_FREEBSD_VERSION})
ENDIF(CMAKE_SYSTEM_NAME MATCHES FreeBSD)
IF(NOT LIBUSB_FOUND)
IF(WIN32)
FIND_PATH(LIBUSB_INCLUDE_DIRS lusb0_usb.h "$ENV{ProgramFiles}/LibUSB-Win32/include" NO_SYSTEM_ENVIRONMENT_PATH)
FIND_LIBRARY(LIBUSB_LIBRARIES NAMES libusb PATHS "$ENV{ProgramFiles}/LibUSB-Win32/lib/gcc")
SET(LIBUSB_LIBRARY_DIR "$ENV{ProgramFiles}/LibUSB-Win32/bin/x86/")
# Must fix up variable to avoid backslashes during packaging
STRING(REGEX REPLACE "\\\\" "/" LIBUSB_LIBRARY_DIR ${LIBUSB_LIBRARY_DIR})
ELSE(WIN32)
# If not under Windows we use PkgConfig
FIND_PACKAGE (PkgConfig)
IF(PKG_CONFIG_FOUND)
PKG_CHECK_MODULES(LIBUSB REQUIRED libusb)
ELSE(PKG_CONFIG_FOUND)
MESSAGE(FATAL_ERROR "Could not find PkgConfig")
ENDIF(PKG_CONFIG_FOUND)
ENDIF(WIN32)
IF(LIBUSB_INCLUDE_DIRS AND LIBUSB_LIBRARIES)
SET(LIBUSB_FOUND TRUE)
ENDIF(LIBUSB_INCLUDE_DIRS AND LIBUSB_LIBRARIES)
ENDIF(NOT LIBUSB_FOUND)
IF(LIBUSB_FOUND)
IF(NOT LIBUSB_FIND_QUIETLY)
MESSAGE(STATUS "Found LIBUSB: ${LIBUSB_LIBRARIES} ${LIBUSB_INCLUDE_DIRS}")
ENDIF (NOT LIBUSB_FIND_QUIETLY)
ELSE(LIBUSB_FOUND)
IF(LIBUSB_FIND_REQUIRED)
MESSAGE(FATAL_ERROR "Could not find LIBUSB")
ENDIF(LIBUSB_FIND_REQUIRED)
ENDIF(LIBUSB_FOUND)
# - Try to find libusb-1.0
# Once done this will define
#
# LIBUSB_1_FOUND - system has libusb
# LIBUSB_1_INCLUDE_DIRS - the libusb include directory
# LIBUSB_1_LIBRARIES - Link these to use libusb
# LIBUSB_1_DEFINITIONS - Compiler switches required for using libusb
#
# Adapted from cmake-modules Google Code project
#
# Copyright (c) 2006 Andreas Schneider <mail@cynapses.org>
#
# (Changes for libusb) Copyright (c) 2008 Kyle Machulis <kyle@nonpolynomial.com>
#
# Redistribution and use is allowed according to the terms of the New BSD license.
#
# CMake-Modules Project New BSD License
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# * Neither the name of the CMake-Modules Project nor the names of its
# contributors may be used to endorse or promote products derived from this
# software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
if (LIBUSB_1_LIBRARIES AND LIBUSB_1_INCLUDE_DIRS)
# in cache already
set(LIBUSB_FOUND TRUE)
else (LIBUSB_1_LIBRARIES AND LIBUSB_1_INCLUDE_DIRS)
find_path(LIBUSB_1_INCLUDE_DIR
NAMES
libusb.h
PATHS
/usr/include
/usr/local/include
/opt/local/include
/sw/include
PATH_SUFFIXES
libusb-1.0
)
find_library(LIBUSB_1_LIBRARY
NAMES
usb-1.0 usb
PATHS
/usr/lib
/usr/local/lib
/opt/local/lib
/sw/lib
)
set(LIBUSB_1_INCLUDE_DIRS
${LIBUSB_1_INCLUDE_DIR}
)
set(LIBUSB_1_LIBRARIES
${LIBUSB_1_LIBRARY}
)
if (LIBUSB_1_INCLUDE_DIRS AND LIBUSB_1_LIBRARIES)
set(LIBUSB_1_FOUND TRUE)
endif (LIBUSB_1_INCLUDE_DIRS AND LIBUSB_1_LIBRARIES)
if (LIBUSB_1_FOUND)
if (NOT libusb_1_FIND_QUIETLY)
message(STATUS "Found libusb-1.0:")
message(STATUS " - Includes: ${LIBUSB_1_INCLUDE_DIRS}")
message(STATUS " - Libraries: ${LIBUSB_1_LIBRARIES}")
endif (NOT libusb_1_FIND_QUIETLY)
else (LIBUSB_1_FOUND)
if (libusb_1_FIND_REQUIRED)
message(FATAL_ERROR "Could not find libusb")
endif (libusb_1_FIND_REQUIRED)
endif (LIBUSB_1_FOUND)
# show the LIBUSB_1_INCLUDE_DIRS and LIBUSB_1_LIBRARIES variables only in the advanced view
mark_as_advanced(LIBUSB_1_INCLUDE_DIRS LIBUSB_1_LIBRARIES)
endif (LIBUSB_1_LIBRARIES AND LIBUSB_1_INCLUDE_DIRS)
......@@ -19,7 +19,7 @@ IF(LIBNFC_DRIVER_ACR122_PCSC)
ENDIF(LIBNFC_DRIVER_ACR122_PCSC)
IF(LIBNFC_DRIVER_ACR122_USB)
FIND_PACKAGE(LIBUSB REQUIRED)
FIND_PACKAGE(libusb-1.0 REQUIRED)
ADD_DEFINITIONS("-DDRIVER_ACR122_USB_ENABLED")
SET(DRIVERS_SOURCES ${DRIVERS_SOURCES} "drivers/acr122_usb")
ENDIF(LIBNFC_DRIVER_ACR122_USB)
......@@ -55,10 +55,10 @@ IF(LIBNFC_DRIVER_PN532_UART)
ENDIF(LIBNFC_DRIVER_PN532_UART)
IF(LIBNFC_DRIVER_PN53X_USB)
FIND_PACKAGE(LIBUSB REQUIRED)
FIND_PACKAGE(libusb-1.0 REQUIRED)
ADD_DEFINITIONS("-DDRIVER_PN53X_USB_ENABLED")
SET(DRIVERS_SOURCES ${DRIVERS_SOURCES} "drivers/pn53x_usb")
SET(USB_REQUIRED TRUE)
SET(USB_1_REQUIRED TRUE)
ENDIF(LIBNFC_DRIVER_PN53X_USB)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/drivers)
libnfc (1.7.1-4) UNRELEASED; urgency=medium
libnfc (1.7.1-4) unstable; urgency=medium
* Update debian/watch to track new upstream releases on github
(the project moved away from code.google.com).
* Update Source section in copyright file.
-- Sophie Brun <sophie@freexian.com> Fri, 10 Jul 2015 11:36:23 +0200
-- Nobuhiro Iwamatsu <iwamatsu@debian.org> Thu, 08 Oct 2015 00:21:44 +0900
libnfc (1.7.1-3) unstable; urgency=medium
......
......@@ -3,11 +3,11 @@ Section: libs
Priority: extra
Maintainer: Nobuhiro Iwamatsu <iwamatsu@debian.org>
Uploaders: Ludovic Rousseau <rousseau@debian.org>
Build-Depends: debhelper (>= 9), dh-autoreconf, libtool, pkg-config, libusb-dev
Build-Depends: debhelper (>= 9), dh-autoreconf, libtool, pkg-config, libusb-1.0-0-dev
Standards-Version: 3.9.6
Homepage: http://www.nfc-tools.org/
Vcs-Git: git://anonscm.debian.org/collab-maint/libnfc.git
Vcs-Browser: http://anonscm.debian.org/gitweb/?p=collab-maint/libnfc.git;a=summary
Vcs-Git: https://salsa.debian.org/debian/libnfc.git
Vcs-Browser: https://salsa.debian.org/debian/libnfc
Package: libnfc5
Architecture: any
......
Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: libnfc
Source: http://libnfc.googlecode.com/
Source: https://github.com/nfc-tools/libnfc
Files: *
Copyright: 2009, Roel Verdult <roel@libnfc.org>
......
......@@ -62,10 +62,10 @@ IF(PCSC_FOUND)
LINK_DIRECTORIES(${PCSC_LIBRARY_DIRS})
ENDIF(PCSC_FOUND)
IF(LIBUSB_FOUND)
INCLUDE_DIRECTORIES(${LIBUSB_INCLUDE_DIRS})
LINK_DIRECTORIES(${LIBUSB_LIBRARY_DIRS})
ENDIF(LIBUSB_FOUND)
IF(LIBUSB_1_FOUND)
INCLUDE_DIRECTORIES(${LIBUSB_1_INCLUDE_DIRS})
LINK_DIRECTORIES(${LIBUSB_1_LIBRARY_DIRS})
ENDIF(LIBUSB_1_FOUND)
# Library
SET(LIBRARY_SOURCES nfc nfc-device nfc-emulation nfc-internal conf iso14443-subr mirror-subr target-subr ${DRIVERS_SOURCES} ${BUSES_SOURCES} ${CHIPS_SOURCES} ${WINDOWS_SOURCES})
......
......@@ -35,7 +35,7 @@
#ifndef _WIN32
// Under POSIX system, we use libusb (>= 0.1.12)
#include <usb.h>
#include <libusb.h>
#define USB_TIMEDOUT ETIMEDOUT
#define _usb_strerror( X ) strerror(-X)
#else
......
This diff is collapsed.
......@@ -72,7 +72,7 @@ typedef enum {
// Internal data struct
struct pn53x_usb_data {
usb_dev_handle *pudh;
libusb_device_handle *pudh;
pn53x_usb_model model;
uint32_t uiEndPointIn;
uint32_t uiEndPointOut;
......@@ -84,36 +84,40 @@ struct pn53x_usb_data {
const struct pn53x_io pn53x_usb_io;
// Prototypes
bool pn53x_usb_get_usb_device_name(struct usb_device *dev, usb_dev_handle *udev, char *buffer, size_t len);
bool pn53x_usb_get_usb_device_name(struct usb_device *dev, libusb_device_handle *udev, char *buffer, size_t len);
int pn53x_usb_init(nfc_device *pnd);
static int
pn53x_usb_bulk_read(struct pn53x_usb_data *data, uint8_t abtRx[], const size_t szRx, const int timeout)
{
int res = usb_bulk_read(data->pudh, data->uiEndPointIn, (char *) abtRx, szRx, timeout);
int msglen = 0;
int res = libusb_bulk_transfer(data-push, data->uiEndPointIn, (char *)abtRx, szRx, &msglen, timeout);
if (res > 0) {
LOG_HEX(NFC_LOG_GROUP_COM, "RX", abtRx, res);
LOG_HEX(NFC_LOG_GROUP_COM, "RX", abtRx, msglen);
} else if (res < 0) {
if (res != -USB_TIMEDOUT)
log_put(NFC_LOG_GROUP_COM, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to read from USB (%s)", _usb_strerror(res));
log_put(NFC_LOG_GROUP_COM, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to read from USB (%s)", libusb_error_name(res));
}
return res;
return msglen;
}
static int
pn53x_usb_bulk_write(struct pn53x_usb_data *data, uint8_t abtTx[], const size_t szTx, const int timeout)
{
LOG_HEX(NFC_LOG_GROUP_COM, "TX", abtTx, szTx);
int res = usb_bulk_write(data->pudh, data->uiEndPointOut, (char *) abtTx, szTx, timeout);
int transferred;
int res = libusb_bulk_transfer(data->pudh, data->uiEndPointOut, (char *)abtTx, szTx, &transferred, timeout);
if (res > 0) {
// HACK This little hack is a well know problem of USB, see http://www.libusb.org/ticket/6 for more details
if ((res % data->uiMaxPacketSize) == 0) {
usb_bulk_write(data->pudh, data->uiEndPointOut, "\0", 0, timeout);
if ((transferred % data->uiMaxPacketSize) == 0) {
int tmpsize;
usb_bulk_write(data->pudh, data->uiEndPointOut, "\0", 0, &tmpsize, timeout);
}
} else {
log_put(NFC_LOG_GROUP_COM, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to write to USB (%s)", _usb_strerror(res));
log_put(NFC_LOG_GROUP_COM, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to write to USB (%s)", libusb_error_name(res));
}
return res;
return transferred;
}
struct pn53x_usb_supported_device {
......@@ -157,19 +161,19 @@ pn53x_usb_get_end_points(struct usb_device *dev, struct pn53x_usb_data *data)
// 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)
if (puid->endpoint[uiIndex].bmAttributes != LIBUSB_TRANSFER_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) {
if ((uiEndPoint & LIBUSB_ENDPOINT_DIR_MASK) == LIBUSB_ENDPOINT_IN) {
data->uiEndPointIn = uiEndPoint;
data->uiMaxPacketSize = puid->endpoint[uiIndex].wMaxPacketSize;
}
// Test if we dealing with a bulk OUT endpoint
if ((uiEndPoint & USB_ENDPOINT_DIR_MASK) == USB_ENDPOINT_OUT) {
if ((uiEndPoint & LIBUSB_ENDPOINT_DIR_MASK) == LIBUSB_ENDPOINT_OUT) {
data->uiEndPointOut = uiEndPoint;
data->uiMaxPacketSize = puid->endpoint[uiIndex].wMaxPacketSize;
}
......@@ -188,6 +192,8 @@ pn53x_usb_scan(const nfc_context *context, nfc_connstring connstrings[], const s
struct usb_bus *bus;
for (bus = usb_get_busses(); bus; bus = bus->next) {
struct usb_device *dev;
libusb_device_handle *udev;
int err;
for (dev = bus->devices; dev; dev = dev->next, uiBusIndex++) {
for (size_t n = 0; n < sizeof(pn53x_usb_supported_devices) / sizeof(struct pn53x_usb_supported_device); n++) {
......@@ -204,8 +210,8 @@ pn53x_usb_scan(const nfc_context *context, nfc_connstring connstrings[], const s
continue;
}
usb_dev_handle *udev = usb_open(dev);
if (udev == NULL)
err = libusb_open(dev, &udev);
if (err < 0)
continue;
// Set configuration
......@@ -240,7 +246,7 @@ struct pn53x_usb_descriptor {
};
bool
pn53x_usb_get_usb_device_name(struct usb_device *dev, usb_dev_handle *udev, char *buffer, size_t len)
pn53x_usb_get_usb_device_name(struct libusb_device *dev, libusb_device_handle *udev, char *buffer, size_t len)
{
*buffer = '\0';
......@@ -277,6 +283,7 @@ pn53x_usb_open(const nfc_context *context, const nfc_connstring connstring)
if (connstring_decode_level < 1) {
goto free_mem;
}
int err;
struct pn53x_usb_data data = {
.pudh = NULL,
......@@ -284,7 +291,7 @@ pn53x_usb_open(const nfc_context *context, const nfc_connstring connstring)
.uiEndPointOut = 0,
};
struct usb_bus *bus;
struct usb_device *dev;
struct libusb_device *dev;
usb_prepare();
......@@ -301,7 +308,8 @@ pn53x_usb_open(const nfc_context *context, const nfc_connstring connstring)
continue;
}
// Open the USB device
if ((data.pudh = usb_open(dev)) == NULL)
err = libusb_open (dev, &data.push);
if (err < 0)
continue;
// Retrieve end points
pn53x_usb_get_end_points(dev, &data);
......@@ -317,7 +325,7 @@ pn53x_usb_open(const nfc_context *context, const nfc_connstring connstring)
goto free_mem;
}
res = usb_claim_interface(data.pudh, 0);
res = libusb_claim_interface(data.pudh, 0);
if (res < 0) {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to claim USB interface (%s)", _usb_strerror(res));
usb_close(data.pudh);
......@@ -331,7 +339,7 @@ pn53x_usb_open(const nfc_context *context, const nfc_connstring connstring)
perror("malloc");
goto error;
}
pn53x_usb_get_usb_device_name(dev, data.pudh, pnd->name, sizeof(pnd->name));
pn53x_usb_get_libusb_device_name(dev, data.pudh, pnd->name, sizeof(pnd->name));
pnd->driver_data = malloc(sizeof(struct pn53x_usb_data));
if (!pnd->driver_data) {
......@@ -408,7 +416,7 @@ pn53x_usb_close(nfc_device *pnd)
pn53x_idle(pnd);
int res;
if ((res = usb_release_interface(DRIVER_DATA(pnd)->pudh, 0)) < 0) {
if ((res = libusb_release_interface(DRIVER_DATA(pnd)->pudh, 0)) < 0) {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to release USB interface (%s)", _usb_strerror(res));
}
......