linux)
AC_DEFINE(OS_LINUX, 1, [Linux backend])
AC_SUBST(OS_LINUX)
- AC_SEARCH_LIBS(clock_gettime, rt, [], [], -pthread)
++
+ AC_ARG_ENABLE([usbhost_api],
+ [AC_HELP_STRING([--enable-usbhost-api], [Request to deviced to obtain dev node fds [default=no]])],
+ [], [enable_usbhost_api="no"])
+ if test "x$enable_usbhost_api" = "xyes"; then
+ PKG_CHECK_MODULES([USBHOST_API], [dbus-1])
+ AC_DEFINE(USE_USBHOST_API, 1, [Request to deviced to obtain dev node fds])
+ fi
+
+ AC_SUBST(USE_USBHOST_API)
+
+ AC_SEARCH_LIBS([clock_gettime2], [rt], [], [], [-pthread])
AC_ARG_ENABLE([udev],
[AC_HELP_STRING([--enable-udev], [use udev for device enumeration and hotplug support (recommended) [default=yes]])],
- [], [enable_udev="yes"])
- if test "x$enable_udev" = "xyes" ; then
+ [], [enable_udev=yes])
+ if test "x$enable_udev" = xyes ; then
# system has udev. use it or fail!
- AC_CHECK_HEADERS([libudev.h],[],[AC_ERROR(["udev support requested but libudev not installed"])])
- AC_CHECK_LIB([udev], [udev_new], [], [AC_ERROR(["udev support requested but libudev not installed"])])
+ AC_CHECK_HEADERS([libudev.h], [], [AC_MSG_ERROR([udev support requested but libudev header not installed])])
+ AC_CHECK_LIB([udev], [udev_new], [], [AC_MSG_ERROR([udev support requested but libudev not installed])])
AC_DEFINE(USE_UDEV, 1, [Use udev for device enumeration/hotplug])
else
AC_CHECK_HEADERS([asm/types.h], [], [])
AM_CONDITIONAL(OS_WINDOWS, test "x$backend" = xwindows)
AM_CONDITIONAL(OS_HAIKU, test "x$backend" = xhaiku)
AM_CONDITIONAL(THREADS_POSIX, test "x$threads" = xposix)
- AM_CONDITIONAL(CREATE_IMPORT_LIB, test "x$create_import_lib" = "xyes")
+ AM_CONDITIONAL(CREATE_IMPORT_LIB, test "x$create_import_lib" = xyes)
AM_CONDITIONAL(USE_UDEV, test "x$enable_udev" = xyes)
- AM_CONDITIONAL(USE_USBDK, test "x$enable_usbdk" = xyes)
+AM_CONDITIONAL(USE_USBHOST_API, test "x$enable_usbhost_api" = xyes)
- if test "$threads" = posix; then
+ if test "x$threads" = xposix; then
AC_DEFINE(THREADS_POSIX, 1, [Use POSIX Threads])
fi
int iso_packet_offset;
};
- fd = open(path, mode);
+ static int _open(const char *path, int flags)
+ {
+ #if defined(O_CLOEXEC)
+ if (supports_flag_cloexec)
+ return open(path, flags | O_CLOEXEC);
+ else
+ #endif
+ return open(path, flags);
+ }
+
+static int _direct_open_device(struct libusb_context *ctx, const char *path,
+ mode_t mode, int silent)
+{
+ int fd;
+ int delay = 10000;
+
- fd = open(path, mode);
++ fd = _open(path, mode);
+ if (fd != -1)
+ return fd; /* Success */
+
+ if (errno == ENOENT) {
+ if (!silent)
+ usbi_err(ctx, "File doesn't exist,"
+ "wait %d ms and try again\n", delay/1000);
+
+ /* Wait 10ms for USB device path creation.*/
+ usleep(delay);
+
++ fd = _open(path, mode);
+ if (fd != -1)
+ return fd; /* Success */
+ }
+
+ return fd;
+}
+
+#ifdef USE_USBHOST_API
+
+#define DEVICED_BUS_NAME "org.tizen.system.deviced"
+#define DEVICED_OBJECT_PATH "/Org/Tizen/System/DeviceD"
+#define DEVICED_INTERFACE_NAME DEVICED_BUS_NAME
+#define DEVICED_PATH_USBHOST DEVICED_OBJECT_PATH"/Usbhost"
+#define DEVICED_INTERFACE_USBHOST DEVICED_INTERFACE_NAME".Usbhost"
+#define METHOD_OPEN_DEVICE "OpenDevice"
+
+DBusMessage *dbus_method_sync_with_reply(const char *dest, const char *path,
+ const char *interface, const char *method, const char *param)
+{
+ DBusConnection *conn;
+ DBusMessage *msg;
+ DBusMessageIter iter;
+ DBusMessage *reply;
+ DBusError err;
+
+ conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
+ if (!conn) {
+ usbi_err(NULL, "dbus_bus_get error");
+ return NULL;
+ }
+
+ msg = dbus_message_new_method_call(dest, path, interface, method);
+ if (!msg) {
+ usbi_err(NULL, "dbus_message_new_method_call(%s:%s-%s)",
+ path, interface, method);
+ dbus_connection_unref (conn);
+ return NULL;
+ }
+
+ dbus_message_iter_init_append(msg, &iter);
+ dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, ¶m);
+
+ dbus_error_init(&err);
+
+ reply = dbus_connection_send_with_reply_and_block(conn, msg, -1, &err);
+ if (!reply) {
+ usbi_err(NULL, "dbus_connection_send error(No reply) %s %s:%s-%s",
+ dest, path, interface, method);
+ }
+
+ if (dbus_error_is_set(&err)) {
+ usbi_err(NULL, "dbus_connection_send error(%s:%s) %s %s:%s-%s",
+ err.name, err.message, dest, path, interface, method);
+ dbus_error_free(&err);
+ reply = NULL;
+ }
+
+ dbus_message_unref(msg);
+ dbus_connection_unref (conn);
+ return reply;
+}
+
+static int open_usb_device(const char *path, int *fd)
+{
+ DBusMessage *reply;
+ DBusError err;
+ int ret, rfd;
+ dbus_bool_t result;
+
+ if (!fd || !path)
+ return -EINVAL;
+
+ dbus_error_init(&err);
+
+ reply = dbus_method_sync_with_reply(DEVICED_BUS_NAME,
+ DEVICED_PATH_USBHOST,
+ DEVICED_INTERFACE_USBHOST,
+ METHOD_OPEN_DEVICE,
+ path);
+
+ if (!reply) {
+ usbi_err(NULL, "Unable to open USB device");
+ return -1;
+ }
+
+ result = dbus_message_get_args(reply, &err,
+ DBUS_TYPE_INT32, &ret,
+ DBUS_TYPE_UNIX_FD, &rfd,
+ DBUS_TYPE_INVALID);
+ if (!result) {
+ usbi_err(NULL, "Failed to get arguments: %s", err.message);
+ return -1;
+ }
+
+ if (ret >= 0)
+ *fd = rfd;
+
+ return ret;
+}
+
+static int _ask_for_open(const char *path, mode_t mode, int silent)
+{
+ int ret;
+ int fd;
+
+ ret = open_usb_device(path, &fd);
+ if (ret < 0) {
+ /*
+ * We have an error so let's set errno correctly
+ * just like open does
+ */
+ errno= -ret;
+ ret = -1;
+ } else {
+ ret = fd;
+ }
+
+ return ret;
+}
+#endif /* USE_USBHOST_API */
+
static int _get_usbfs_fd(struct libusb_device *dev, mode_t mode, int silent)
{
struct libusb_context *ctx = DEVICE_CTX(dev);
--- /dev/null
- Version: 1.0.21
+%define TIZEN_FEATURE_USBHOST_API on
+
+Name: libusb
++Version: 1.0.22
+Release: 0
+License: LGPL-2.1+, MIT
+Summary: USB Library
+Url: http://www.libusb.org/
+Group: Base/Device Management
+Source: %{name}-%{version}.tar.bz2
+Source1: baselibs.conf
+Source1001: libusb.manifest
+BuildRequires: pkg-config
+BuildRequires: systemd-devel
+%if %{?TIZEN_FEATURE_USBHOST_API} == on
+BuildRequires: pkgconfig(dbus-1)
+%endif
+
+%description
+Libusb is a library that allows userspace access to USB devices.
+
+%package devel
+Summary: USB Library
+Group: Development/Libraries
+Requires: glibc-devel
+Requires: libusb = %{version}
+
+%description devel
+Libusb is a library that allows userspace access to USB devices.
+
+%prep
+%setup -q
+cp %{SOURCE1001} .
+
+%build
+%reconfigure\
+ --with-pic\
+%if %{?TIZEN_FEATURE_USBHOST_API} == on
+ --enable-usbhost-api \
+%endif
+ --disable-static
+make %{?_smp_mflags}
+
+%install
+%make_install
+# usbhost_module
+mkdir -p %{buildroot}%{_prefix}/lib/udev/rules.d
+install -m 644 udev/99-usbhost.rules %{buildroot}%{_prefix}/lib/udev/rules.d/99-usbhost.rules
+
+%post -p /sbin/ldconfig
+
+%postun -p /sbin/ldconfig
+
+%files
+%manifest %{name}.manifest
+%defattr(-,root,root)
+%license LICENSE.LGPL-2.1+ LICENSE.MIT
+%{_libdir}/*.so.*
+# usbhost_module
+%{_prefix}/lib/udev/rules.d/99-usbhost.rules
+
+%files devel
+%manifest %{name}.manifest
+%defattr(-,root,root)
+%license LICENSE.LGPL-2.1+ LICENSE.MIT
+%{_includedir}/libusb-1.0
+%{_libdir}/*.so
+%{_libdir}/pkgconfig/*.pc
+
+%changelog