Merge tag 'v1.0.24' into tizen 41/281241/1
authorKarol Lewandowski <k.lewandowsk@samsung.com>
Wed, 14 Sep 2022 22:22:59 +0000 (00:22 +0200)
committerKarol Lewandowski <k.lewandowsk@samsung.com>
Wed, 14 Sep 2022 22:35:59 +0000 (00:35 +0200)
Change-Id: I1d8ba762cb8f1afdbf7c6f39f0f1e6de98c1ce19

LICENSE.LGPL-2.1+ [moved from COPYING with 98% similarity]
LICENSE.MIT [new file with mode: 0644]
configure.ac
libusb/Makefile.am
libusb/os/linux_usbfs.c
packaging/baselibs.conf [new file with mode: 0644]
packaging/libusb.changes [new file with mode: 0644]
packaging/libusb.manifest [new file with mode: 0644]
packaging/libusb.spec [new file with mode: 0755]
udev/99-usbhost.rules [new file with mode: 0755]

similarity index 98%
rename from COPYING
rename to LICENSE.LGPL-2.1+
index 5ab7695..4362b49 100644 (file)
--- a/COPYING
@@ -1,5 +1,5 @@
-                 GNU LESSER GENERAL PUBLIC LICENSE
-                      Version 2.1, February 1999
+                  GNU LESSER GENERAL PUBLIC LICENSE
+                       Version 2.1, February 1999
 
  Copyright (C) 1991, 1999 Free Software Foundation, Inc.
  51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
@@ -10,7 +10,7 @@
  as the successor of the GNU Library Public License, version 2, hence
  the version number 2.1.]
 
-                           Preamble
+                            Preamble
 
   The licenses for most software are designed to take away your
 freedom to share and change it.  By contrast, the GNU General Public
@@ -112,7 +112,7 @@ modification follow.  Pay close attention to the difference between a
 former contains code derived from the library, whereas the latter must
 be combined with the library in order to run.
 \f
-                 GNU LESSER GENERAL PUBLIC LICENSE
+                  GNU LESSER GENERAL PUBLIC LICENSE
    TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
 
   0. This License Agreement applies to any software library or other
@@ -146,7 +146,7 @@ such a program is covered only if its contents constitute a work based
 on the Library (independent of the use of the Library in a tool for
 writing it).  Whether that is true depends on what the Library does
 and what the program that uses the Library does.
-  
+
   1. You may copy and distribute verbatim copies of the Library's
 complete source code as you receive it, in any medium, provided that
 you conspicuously and appropriately publish on each copy an
@@ -432,7 +432,7 @@ decision will be guided by the two goals of preserving the free status
 of all derivatives of our free software and of promoting the sharing
 and reuse of software generally.
 
-                           NO WARRANTY
+                            NO WARRANTY
 
   15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
 WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
@@ -455,7 +455,7 @@ FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
 SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
 DAMAGES.
 
-                    END OF TERMS AND CONDITIONS
+                     END OF TERMS AND CONDITIONS
 \f
            How to Apply These Terms to Your New Libraries
 
@@ -500,5 +500,3 @@ necessary.  Here is a sample; alter the names:
   Ty Coon, President of Vice
 
 That's all there is to it!
-
-
diff --git a/LICENSE.MIT b/LICENSE.MIT
new file mode 100644 (file)
index 0000000..6e09dc8
--- /dev/null
@@ -0,0 +1,9 @@
+The MIT License
+
+Copyright (c) <year> <copyright holders>
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
index 5b880f6..05f87cd 100644 (file)
@@ -167,6 +167,16 @@ haiku)
        LIBS="${LIBS} -lbe"
        ;;
 linux)
+       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_gettime], [rt], [], [], [])
        AC_CHECK_FUNCS([pthread_setname_np])
        AC_ARG_ENABLE([udev],
@@ -347,6 +357,7 @@ AM_CONDITIONAL([OS_WINDOWS], [test "x$backend" = xwindows])
 AM_CONDITIONAL([PLATFORM_POSIX], [test "x$platform" = xposix])
 AM_CONDITIONAL([PLATFORM_WINDOWS], [test "x$platform" = xwindows])
 AM_CONDITIONAL([USE_UDEV], [test "x$use_udev" = xyes])
+AM_CONDITIONAL([USE_USBHOST_API], [test "x$enable_usbhost_api" = "xyes"])
 
 dnl The -Wcast-function-type warning causes a flurry of warnings when compiling
 dnl Windows with GCC 8 or later because of dynamically loaded functions
index c78006e..9cba3f7 100644 (file)
@@ -85,4 +85,8 @@ libusb_1_0_la_SOURCES = libusbi.h version.h version_nano.h \
        core.c descriptor.c hotplug.h hotplug.c io.c strerror.c sync.c \
        $(PLATFORM_SRC) $(OS_SRC)
 
+if USE_USBHOST_API
+libusb_1_0_la_CFLAGS = $(USBHOST_API_CFLAGS)
+libusb_1_0_la_LIBADD = $(USBHOST_API_LIBS)
+endif
 pkginclude_HEADERS = libusb.h
index fb2ed53..b3e4554 100644 (file)
 #include <sys/vfs.h>
 #include <unistd.h>
 
+/* Tizen specific */
+#ifdef USE_USBHOST_API
+#include <dbus/dbus.h>
+#endif
+
 /* sysfs vs usbfs:
  * opening a usbfs node causes the device to be resumed, so we attempt to
  * avoid this during enumeration.
@@ -169,19 +174,11 @@ struct linux_transfer_priv {
        int iso_packet_offset;
 };
 
-static int get_usbfs_fd(struct libusb_device *dev, mode_t mode, int silent)
+static int _direct_open_device(struct libusb_context *ctx, const char *path,
+                              mode_t mode, int silent)
 {
-       struct libusb_context *ctx = DEVICE_CTX(dev);
-       char path[24];
        int fd;
 
-       if (usbdev_names)
-               sprintf(path, USBDEV_PATH "/usbdev%u.%u",
-                       dev->bus_number, dev->device_address);
-       else
-               sprintf(path, USB_DEVTMPFS_PATH "/%03u/%03u",
-                       dev->bus_number, dev->device_address);
-
        fd = open(path, mode | O_CLOEXEC);
        if (fd != -1)
                return fd; /* Success */
@@ -201,6 +198,164 @@ static int get_usbfs_fd(struct libusb_device *dev, mode_t mode, int silent)
                        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, &param);
+
+       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);
+       char path[24];
+       int fd;
+
+       if (usbdev_names)
+               sprintf(path, USBDEV_PATH "/usbdev%u.%u",
+                       dev->bus_number, dev->device_address);
+       else
+               sprintf(path, USB_DEVTMPFS_PATH "/%03u/%03u",
+                       dev->bus_number, dev->device_address);
+
+       fd = _direct_open_device(ctx, path, mode, silent);
+       if (fd != -1)
+               return fd; /* Success */
+
+#ifdef USE_USBHOST_API
+       /*
+        * If we are here, we were unable to go simple
+        * path and open the device directly. In Tizen
+        * we have USB security daemon (USD) which
+        * manages access rights to USB device nodes.
+        * Now let's ask him to open this device node
+        * for us.
+        */
+
+       /*
+        * USD is applicable only for RW access.
+        */
+       if (mode & O_RDWR) {
+               if (!silent)
+                       usbi_info(ctx, "No direct access to device node: %s. "
+                                 "Trying to use deviced", path);
+
+               fd = _ask_for_open(path, mode, silent);
+               if (fd != -1)
+                       return fd;
+       }
+#endif /* USE_USBHOST_API */
+
        if (!silent) {
                usbi_err(ctx, "libusb couldn't open USB device %s, errno=%d", path, errno);
                if (errno == EACCES && mode == O_RDWR)
diff --git a/packaging/baselibs.conf b/packaging/baselibs.conf
new file mode 100644 (file)
index 0000000..52a6e04
--- /dev/null
@@ -0,0 +1,5 @@
+libusb
+libusb-devel
+  requires -libusb-<targettype>
+  requires "libusb-<targettype> = <version>"
+
diff --git a/packaging/libusb.changes b/packaging/libusb.changes
new file mode 100644 (file)
index 0000000..7c3598d
--- /dev/null
@@ -0,0 +1,3 @@
+* Mon Mar 18 2013 Anas Nashif <anas.nashif@intel.com> upstream/1.0.9@8f72b70
+- Update package groups
+
diff --git a/packaging/libusb.manifest b/packaging/libusb.manifest
new file mode 100644 (file)
index 0000000..017d22d
--- /dev/null
@@ -0,0 +1,5 @@
+<manifest>
+ <request>
+    <domain name="_"/>
+ </request>
+</manifest>
diff --git a/packaging/libusb.spec b/packaging/libusb.spec
new file mode 100755 (executable)
index 0000000..dc2e6bc
--- /dev/null
@@ -0,0 +1,70 @@
+%define TIZEN_FEATURE_USBHOST_API on
+
+Name:           libusb
+Version:        1.0.24
+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
diff --git a/udev/99-usbhost.rules b/udev/99-usbhost.rules
new file mode 100755 (executable)
index 0000000..a719bec
--- /dev/null
@@ -0,0 +1,2 @@
+SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", DEVPATH!="/devices/platform/dummy_hcd.*", MODE="0660", GROUP="system_share", SECLABEL{smack}="*"
+SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", DEVPATH=="/devices/platform/dummy_hcd.*", MODE="0666", GROUP="system_share", SECLABEL{smack}="*"