2013-03-02 01:08:07 +01:00
|
|
|
/*-
|
2013-03-10 16:15:23 +01:00
|
|
|
* Free/Libre Near Field Communication (NFC) library
|
2013-03-02 01:08:07 +01:00
|
|
|
*
|
2013-03-10 16:15:23 +01:00
|
|
|
* Libnfc historical contributors:
|
|
|
|
* Copyright (C) 2009 Roel Verdult
|
|
|
|
* Copyright (C) 2009-2013 Romuald Conty
|
|
|
|
* Copyright (C) 2010-2012 Romain Tartière
|
|
|
|
* Copyright (C) 2010-2013 Philippe Teuwen
|
|
|
|
* Copyright (C) 2012-2013 Ludovic Rousseau
|
2013-07-17 13:57:56 +02:00
|
|
|
* See AUTHORS file for a more comprehensive list of contributors.
|
2013-03-10 16:15:23 +01:00
|
|
|
* Additional contributors of this file:
|
2013-03-02 01:08:07 +01:00
|
|
|
*
|
|
|
|
* 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 usbbus.c
|
|
|
|
* @brief libusb 0.1 driver wrapper
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif // HAVE_CONFIG_H
|
|
|
|
|
2013-05-20 16:58:57 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2013-03-02 01:08:07 +01:00
|
|
|
#include "usbbus.h"
|
|
|
|
#include "log.h"
|
|
|
|
#define LOG_CATEGORY "libnfc.buses.usbbus"
|
|
|
|
#define LOG_GROUP NFC_LOG_GROUP_DRIVER
|
|
|
|
|
2013-03-02 02:52:07 +01:00
|
|
|
int usb_prepare(void)
|
|
|
|
{
|
2013-03-02 12:43:15 +01:00
|
|
|
static bool usb_initialized = false;
|
2013-06-22 20:03:45 +02:00
|
|
|
if (!usb_initialized) {
|
2013-03-02 23:41:43 +01:00
|
|
|
|
|
|
|
#ifdef ENVVARS
|
2013-06-22 20:03:45 +02:00
|
|
|
char *env_log_level = getenv("LIBNFC_LOG_LEVEL");
|
|
|
|
// Set libusb debug only if asked explicitely:
|
|
|
|
// LIBUSB_LOG_LEVEL=12288 (= NFC_LOG_PRIORITY_DEBUG * 2 ^ NFC_LOG_GROUP_LIBUSB)
|
|
|
|
if (env_log_level && (((atoi(env_log_level) >> (NFC_LOG_GROUP_LIBUSB * 2)) & 0x00000003) >= NFC_LOG_PRIORITY_DEBUG)) {
|
|
|
|
setenv("USB_DEBUG", "255", 1);
|
|
|
|
}
|
2013-03-02 23:41:43 +01:00
|
|
|
#endif
|
|
|
|
|
2013-06-22 20:03:45 +02:00
|
|
|
usb_init();
|
|
|
|
usb_initialized = true;
|
|
|
|
}
|
2013-03-02 01:08:07 +01:00
|
|
|
|
|
|
|
int res;
|
|
|
|
// usb_find_busses will find all of the busses on the system. Returns the
|
|
|
|
// number of changes since previous call to this function (total of new
|
|
|
|
// busses and busses removed).
|
|
|
|
if ((res = usb_find_busses()) < 0) {
|
|
|
|
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to find USB busses (%s)", _usb_strerror(res));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
// usb_find_devices will find all of the devices on each bus. This should be
|
|
|
|
// called after usb_find_busses. Returns the number of changes since the
|
|
|
|
// previous call to this function (total of new device and devices removed).
|
|
|
|
if ((res = usb_find_devices()) < 0) {
|
|
|
|
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to find USB devices (%s)", _usb_strerror(res));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|