From fdabc3ae5672f8f513b28852a3db199ca8625324 Mon Sep 17 00:00:00 2001 From: Anas Nashif Date: Sun, 4 Nov 2012 07:23:38 -0800 Subject: [PATCH 01/16] fixed packaging Change-Id: Ib4c1433c546a180b9145596c3b986123f60a56bd --- packaging/baselibs.conf | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packaging/baselibs.conf b/packaging/baselibs.conf index e8f427b..52a6e04 100644 --- a/packaging/baselibs.conf +++ b/packaging/baselibs.conf @@ -1,5 +1,5 @@ -libusb-1_0-0 -libusb-1_0-devel - requires -libusb-1_0- - requires "libusb-1_0-0- = " +libusb +libusb-devel + requires -libusb- + requires "libusb- = " -- 2.34.1 From aeec548eccacb036d62674bba493390f3e9e5580 Mon Sep 17 00:00:00 2001 From: Anas Nashif Date: Mon, 18 Mar 2013 13:44:33 -0700 Subject: [PATCH 02/16] Update package groups Change-Id: I7f0cadec585a535be7b6a1c87e6df3f1e6dc8b16 --- packaging/libusb.changes | 3 +++ packaging/libusb.spec | 7 +++---- 2 files changed, 6 insertions(+), 4 deletions(-) create mode 100644 packaging/libusb.changes diff --git a/packaging/libusb.changes b/packaging/libusb.changes new file mode 100644 index 0000000..7c3598d --- /dev/null +++ b/packaging/libusb.changes @@ -0,0 +1,3 @@ +* Mon Mar 18 2013 Anas Nashif upstream/1.0.9@8f72b70 +- Update package groups + diff --git a/packaging/libusb.spec b/packaging/libusb.spec index 24212ef..d540ea2 100644 --- a/packaging/libusb.spec +++ b/packaging/libusb.spec @@ -4,7 +4,7 @@ Release: 0 License: LGPL-2.1+ Summary: USB Library Url: http://www.libusb.org/ -Group: System/Libraries +Group: Base/Device Management Source: %{name}-%{version}.tar.bz2 Source1: baselibs.conf BuildRequires: pkg-config @@ -14,7 +14,7 @@ Libusb is a library that allows userspace access to USB devices. %package devel Summary: USB Library -Group: Development/Libraries/C and C++ +Group: Development/Libraries Requires: glibc-devel Requires: libusb = %{version} @@ -39,12 +39,11 @@ make %{?_smp_mflags} %files %defattr(-,root,root) -%doc COPYING +%license COPYING %{_libdir}/*.so.* %files devel %defattr(-,root,root) -%doc PORTING %{_includedir}/libusb-1.0 %{_libdir}/*.so %{_libdir}/pkgconfig/*.pc -- 2.34.1 From 2c83bf0fffd3c7d8ddac8781cec5afea0a30fb7b Mon Sep 17 00:00:00 2001 From: Alexandru Cornea Date: Mon, 1 Jul 2013 19:46:11 +0300 Subject: [PATCH 03/16] resetting manifest requested domain to floor Change-Id: Ia8bdd7cfc7f730dabf58a1fa3abf68cd0fb73bdf --- packaging/libusb.manifest | 5 +++++ packaging/libusb.spec | 4 ++++ 2 files changed, 9 insertions(+) create mode 100644 packaging/libusb.manifest diff --git a/packaging/libusb.manifest b/packaging/libusb.manifest new file mode 100644 index 0000000..017d22d --- /dev/null +++ b/packaging/libusb.manifest @@ -0,0 +1,5 @@ + + + + + diff --git a/packaging/libusb.spec b/packaging/libusb.spec index d540ea2..5c35ddc 100644 --- a/packaging/libusb.spec +++ b/packaging/libusb.spec @@ -7,6 +7,7 @@ Url: http://www.libusb.org/ Group: Base/Device Management Source: %{name}-%{version}.tar.bz2 Source1: baselibs.conf +Source1001: libusb.manifest BuildRequires: pkg-config %description @@ -23,6 +24,7 @@ Libusb is a library that allows userspace access to USB devices. %prep %setup -q +cp %{SOURCE1001} . %build %configure\ @@ -38,11 +40,13 @@ make %{?_smp_mflags} %postun -p /sbin/ldconfig %files +%manifest %{name}.manifest %defattr(-,root,root) %license COPYING %{_libdir}/*.so.* %files devel +%manifest %{name}.manifest %defattr(-,root,root) %{_includedir}/libusb-1.0 %{_libdir}/*.so -- 2.34.1 From 0f8915455b045c2bff6b4c9dd220912ab450af47 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C5=81ukasz=20Stelmach?= Date: Tue, 16 Jun 2015 13:22:59 +0200 Subject: [PATCH 04/16] Upgrade libusb to version 1.0.19 Change-Id: I39653675c3e57d61ca35f0aafdf14552385e20bf --- packaging/libusb.spec | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packaging/libusb.spec b/packaging/libusb.spec index 5c35ddc..66d064e 100644 --- a/packaging/libusb.spec +++ b/packaging/libusb.spec @@ -1,5 +1,5 @@ Name: libusb -Version: 1.0.9 +Version: 1.0.19 Release: 0 License: LGPL-2.1+ Summary: USB Library @@ -9,6 +9,7 @@ Source: %{name}-%{version}.tar.bz2 Source1: baselibs.conf Source1001: libusb.manifest BuildRequires: pkg-config +BuildRequires: systemd-devel %description Libusb is a library that allows userspace access to USB devices. -- 2.34.1 From 8633dfb3c90dd00abd97ddfe6653d56d94ad997e Mon Sep 17 00:00:00 2001 From: Krzysztof Opasiak Date: Mon, 29 Jun 2015 12:31:05 +0200 Subject: [PATCH 05/16] Allow to obtain fd from USB Security Daemon Tizen don't allow applications to directly open device nodes for communication with USB devices. We have our own daemon (USD - USB Security Daemon) which holds the policy of accessing USB devices. Each app which would like to communicate with device has to ask USD to open suitable file and pass fds to app. This patch updates libusb and first tries to open device node directly and only if it fails asks USD to open fds. This allows to not influence existing libusb users which has root rights and check USD permissions only for external applications. Change-Id: I9dcac37ccc8ae86cef4d22965744781307940e61 Signed-off-by: Krzysztof Opasiak [Rebase patch onto new library version] Signed-off-by: Krzysztof Opasiak --- configure.ac | 11 +++++ libusb/Makefile.am | 7 +++ libusb/os/linux_usbfs.c | 101 +++++++++++++++++++++++++++++++++++----- packaging/libusb.spec | 6 ++- 4 files changed, 112 insertions(+), 13 deletions(-) diff --git a/configure.ac b/configure.ac index c00af33..7eb4628 100644 --- a/configure.ac +++ b/configure.ac @@ -107,6 +107,16 @@ case $backend in linux) AC_DEFINE(OS_LINUX, 1, [Linux backend]) AC_SUBST(OS_LINUX) + AC_ARG_ENABLE([usd], + [AC_HELP_STRING([--enable-usd], [Use USB security daemon to obtain dev node fds [default=no]])], + [], [enable_usd="no"]) + if test "x$enable_usd" = "xyes"; then + PKG_CHECK_MODULES([USD], [capi-system-usbhost-usd]) + AC_DEFINE(USE_USD, 1, [Use USB security daemon to obtain dev node fds]) + fi + + AC_SUBST(USE_USD) + AC_SEARCH_LIBS(clock_gettime, rt, [], [], -pthread) AC_ARG_ENABLE([udev], [AC_HELP_STRING([--enable-udev], [use udev for device enumeration and hotplug support (recommended) [default=yes]])], @@ -213,6 +223,7 @@ AM_CONDITIONAL(THREADS_POSIX, test "x$threads" = xposix) 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_USD, test "x$enable_usd" = xyes) if test "$threads" = posix; then AC_DEFINE(THREADS_POSIX, 1, [Use POSIX Threads]) fi diff --git a/libusb/Makefile.am b/libusb/Makefile.am index b1b892d..2731986 100644 --- a/libusb/Makefile.am +++ b/libusb/Makefile.am @@ -102,3 +102,10 @@ libusb_1_0_la_SOURCES = libusbi.h libusb.h version.h version_nano.h \ hdrdir = $(includedir)/libusb-1.0 hdr_HEADERS = libusb.h + +if OS_LINUX +if USE_USD +libusb_1_0_la_CFLAGS += $(USD_CFLAGS) +libusb_1_0_la_LIBADD = $(USD_LIBS) +endif +endif \ No newline at end of file diff --git a/libusb/os/linux_usbfs.c b/libusb/os/linux_usbfs.c index 9cbeb80..f6ee9a3 100644 --- a/libusb/os/linux_usbfs.c +++ b/libusb/os/linux_usbfs.c @@ -39,6 +39,11 @@ #include #include +/* Tizen specific */ +#ifdef USE_USD +#include +#endif + #include "libusbi.h" #include "linux_usbfs.h" @@ -180,12 +185,74 @@ struct linux_transfer_priv { int iso_packet_offset; }; +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); + 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_USD +static int _ask_for_open(const char *path, mode_t mode, int silent) +{ + int ret; + int fd; + + ret = usd_open_usb_device(path, &fd); + if (ret != USD_API_SUCCESS) { + /* + * We have an error so let's set errno correctly + * just like open does + */ + switch (ret) { + case USD_API_ERROR_ACCESS_DENIED: + case USD_API_ERROR_SOCKET: + case USD_API_ERROR_AUTHENTICATION_FAILED: + errno = EACCES; + break; + + case USD_API_ERROR_INPUT_PARAM: + case USD_API_ERROR_FILE_NOT_EXIST: + errno = ENOENT; + break; + default: + errno = EINVAL; + break; + } + + ret = -1; + } else { + ret = fd; + } + + return ret; +} +#endif /* USE_USD */ + static int _get_usbfs_fd(struct libusb_device *dev, mode_t mode, int silent) { struct libusb_context *ctx = DEVICE_CTX(dev); char path[PATH_MAX]; int fd; - int delay = 10000; if (usbdev_names) snprintf(path, PATH_MAX, "%s/usbdev%d.%d", @@ -194,22 +261,34 @@ static int _get_usbfs_fd(struct libusb_device *dev, mode_t mode, int silent) snprintf(path, PATH_MAX, "%s/%03d/%03d", usbfs_path, dev->bus_number, dev->device_address); - fd = open(path, mode); + fd = _direct_open_device(ctx, path, mode, silent); if (fd != -1) return fd; /* Success */ - if (errno == ENOENT) { - if (!silent) - usbi_err(ctx, "File doesn't exist, wait %d ms and try again", delay/1000); - - /* Wait 10ms for USB device path creation.*/ - nanosleep(&(struct timespec){delay / 1000000, (delay * 1000) % 1000000000UL}, NULL); +#ifdef USE_USD + /* + * 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. + */ - fd = open(path, mode); + /* + * 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 USD", path); + + fd = _ask_for_open(path, mode, silent); if (fd != -1) - return fd; /* Success */ + return fd; } - +#endif /* USE_USD */ + if (!silent) { usbi_err(ctx, "libusb couldn't open USB device %s: %s", path, strerror(errno)); diff --git a/packaging/libusb.spec b/packaging/libusb.spec index 66d064e..1d7a227 100644 --- a/packaging/libusb.spec +++ b/packaging/libusb.spec @@ -10,6 +10,7 @@ Source1: baselibs.conf Source1001: libusb.manifest BuildRequires: pkg-config BuildRequires: systemd-devel +BuildRequires: pkgconfig(capi-system-usbhost-usd) %description Libusb is a library that allows userspace access to USB devices. @@ -28,9 +29,10 @@ Libusb is a library that allows userspace access to USB devices. cp %{SOURCE1001} . %build -%configure\ +%reconfigure\ --with-pic\ - --disable-static + --disable-static\ + --enable-usd make %{?_smp_mflags} %install -- 2.34.1 From 30abdfc69b62d03900f45fac8652173af75e3450 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Pawe=C5=82=20Szewczyk?= Date: Thu, 11 Feb 2016 14:01:09 +0100 Subject: [PATCH 06/16] Use deviced instead of USB Security Daemon MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Change-Id: I507208ee6d4ba2549ce59a1d70ee224f6ee73fc3 Signed-off-by: Paweł Szewczyk [Rebase onto new library version] Signed-off-by: Krzysztof Opasiak --- configure.ac | 16 ++++++++-------- libusb/Makefile.am | 8 ++++---- libusb/os/linux_usbfs.c | 35 ++++++++++------------------------- packaging/libusb.spec | 4 ++-- 4 files changed, 24 insertions(+), 39 deletions(-) diff --git a/configure.ac b/configure.ac index 7eb4628..c822e5b 100644 --- a/configure.ac +++ b/configure.ac @@ -107,15 +107,15 @@ case $backend in linux) AC_DEFINE(OS_LINUX, 1, [Linux backend]) AC_SUBST(OS_LINUX) - AC_ARG_ENABLE([usd], - [AC_HELP_STRING([--enable-usd], [Use USB security daemon to obtain dev node fds [default=no]])], - [], [enable_usd="no"]) - if test "x$enable_usd" = "xyes"; then - PKG_CHECK_MODULES([USD], [capi-system-usbhost-usd]) - AC_DEFINE(USE_USD, 1, [Use USB security daemon to obtain dev node fds]) + AC_ARG_ENABLE([deviced], + [AC_HELP_STRING([--enable-deviced], [Use deviced to obtain dev node fds [default=no]])], + [], [enable_deviced="no"]) + if test "x$enable_deviced" = "xyes"; then + PKG_CHECK_MODULES([DEVICED], [deviced]) + AC_DEFINE(USE_DEVICED, 1, [Use deviced to obtain dev node fds]) fi - AC_SUBST(USE_USD) + AC_SUBST(USE_DEVICED) AC_SEARCH_LIBS(clock_gettime, rt, [], [], -pthread) AC_ARG_ENABLE([udev], @@ -223,7 +223,7 @@ AM_CONDITIONAL(THREADS_POSIX, test "x$threads" = xposix) 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_USD, test "x$enable_usd" = xyes) +AM_CONDITIONAL(USE_DEVICED, test "x$enable_deviced" = xyes) if test "$threads" = posix; then AC_DEFINE(THREADS_POSIX, 1, [Use POSIX Threads]) fi diff --git a/libusb/Makefile.am b/libusb/Makefile.am index 2731986..e6fc154 100644 --- a/libusb/Makefile.am +++ b/libusb/Makefile.am @@ -104,8 +104,8 @@ hdrdir = $(includedir)/libusb-1.0 hdr_HEADERS = libusb.h if OS_LINUX -if USE_USD -libusb_1_0_la_CFLAGS += $(USD_CFLAGS) -libusb_1_0_la_LIBADD = $(USD_LIBS) +if USE_DEVICED +libusb_1_0_la_CFLAGS += $(DEVICED_CFLAGS) +libusb_1_0_la_LIBADD = $(DEVICED_LIBS) +endif endif -endif \ No newline at end of file diff --git a/libusb/os/linux_usbfs.c b/libusb/os/linux_usbfs.c index f6ee9a3..90b80c4 100644 --- a/libusb/os/linux_usbfs.c +++ b/libusb/os/linux_usbfs.c @@ -40,8 +40,8 @@ #include /* Tizen specific */ -#ifdef USE_USD -#include +#ifdef USE_DEVICED +#include #endif #include "libusbi.h" @@ -211,34 +211,19 @@ static int _direct_open_device(struct libusb_context *ctx, const char *path, return fd; } -#ifdef USE_USD +#ifdef USE_DEVICED static int _ask_for_open(const char *path, mode_t mode, int silent) { int ret; int fd; - ret = usd_open_usb_device(path, &fd); - if (ret != USD_API_SUCCESS) { + ret = open_usb_device(path, &fd); + if (ret < 0) { /* * We have an error so let's set errno correctly * just like open does */ - switch (ret) { - case USD_API_ERROR_ACCESS_DENIED: - case USD_API_ERROR_SOCKET: - case USD_API_ERROR_AUTHENTICATION_FAILED: - errno = EACCES; - break; - - case USD_API_ERROR_INPUT_PARAM: - case USD_API_ERROR_FILE_NOT_EXIST: - errno = ENOENT; - break; - default: - errno = EINVAL; - break; - } - + errno= -ret; ret = -1; } else { ret = fd; @@ -246,7 +231,7 @@ static int _ask_for_open(const char *path, mode_t mode, int silent) return ret; } -#endif /* USE_USD */ +#endif /* USE_DEVICED */ static int _get_usbfs_fd(struct libusb_device *dev, mode_t mode, int silent) { @@ -265,7 +250,7 @@ static int _get_usbfs_fd(struct libusb_device *dev, mode_t mode, int silent) if (fd != -1) return fd; /* Success */ -#ifdef USE_USD +#ifdef USE_DEVICED /* * If we are here, we were unable to go simple * path and open the device directly. In Tizen @@ -281,13 +266,13 @@ static int _get_usbfs_fd(struct libusb_device *dev, mode_t mode, int silent) if (mode & O_RDWR) { if (!silent) usbi_info(ctx, "No direct access to device node: %s. " - "Trying to use USD", path); + "Trying to use deviced", path); fd = _ask_for_open(path, mode, silent); if (fd != -1) return fd; } -#endif /* USE_USD */ +#endif /* USE_DEVICED */ if (!silent) { usbi_err(ctx, "libusb couldn't open USB device %s: %s", diff --git a/packaging/libusb.spec b/packaging/libusb.spec index 1d7a227..da4d5d9 100644 --- a/packaging/libusb.spec +++ b/packaging/libusb.spec @@ -10,7 +10,7 @@ Source1: baselibs.conf Source1001: libusb.manifest BuildRequires: pkg-config BuildRequires: systemd-devel -BuildRequires: pkgconfig(capi-system-usbhost-usd) +BuildRequires: pkgconfig(deviced) %description Libusb is a library that allows userspace access to USB devices. @@ -32,7 +32,7 @@ cp %{SOURCE1001} . %reconfigure\ --with-pic\ --disable-static\ - --enable-usd + --enable-deviced make %{?_smp_mflags} %install -- 2.34.1 From c66b367235fe02b9b3b7b9dc2a1d694af5fec31a Mon Sep 17 00:00:00 2001 From: taeyoung Date: Fri, 12 Aug 2016 13:22:59 +0900 Subject: [PATCH 07/16] usbhost api: disable Tizen usb host apicodes on TV profile - TV profile does not support Tizen usbhost api. Thus the codes related with it are removed on TV profile. Change-Id: Id38ea19827b73ee345cbff43cfc0a4cc347773a1 Signed-off-by: taeyoung --- packaging/libusb.spec | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packaging/libusb.spec b/packaging/libusb.spec index da4d5d9..b3430f5 100644 --- a/packaging/libusb.spec +++ b/packaging/libusb.spec @@ -10,7 +10,9 @@ Source1: baselibs.conf Source1001: libusb.manifest BuildRequires: pkg-config BuildRequires: systemd-devel +%if "%{?profile}" != "tv" BuildRequires: pkgconfig(deviced) +%endif %description Libusb is a library that allows userspace access to USB devices. @@ -31,8 +33,10 @@ cp %{SOURCE1001} . %build %reconfigure\ --with-pic\ - --disable-static\ - --enable-deviced +%if "%{?profile}" != "tv" + --enable-deviced\ +%endif + --disable-static make %{?_smp_mflags} %install -- 2.34.1 From 096c36371771934463233b0e664f03c8e020dbea Mon Sep 17 00:00:00 2001 From: taeyoung Date: Tue, 13 Sep 2016 13:02:56 +0900 Subject: [PATCH 08/16] usbhost api: enable deviced feature just for mobile profile usb host api is Mobile profile feature currently. Thus deviced related codes should be applied to mobile profile only. Change-Id: I354c784b32ed37a5834f8adbb5a561e75fa0eb99 Signed-off-by: taeyoung --- packaging/libusb.spec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packaging/libusb.spec b/packaging/libusb.spec index b3430f5..e43ef05 100644 --- a/packaging/libusb.spec +++ b/packaging/libusb.spec @@ -10,7 +10,7 @@ Source1: baselibs.conf Source1001: libusb.manifest BuildRequires: pkg-config BuildRequires: systemd-devel -%if "%{?profile}" != "tv" +%if "%{?profile}" == "mobile" BuildRequires: pkgconfig(deviced) %endif @@ -33,7 +33,7 @@ cp %{SOURCE1001} . %build %reconfigure\ --with-pic\ -%if "%{?profile}" != "tv" +%if "%{?profile}" == "mobile" --enable-deviced\ %endif --disable-static -- 2.34.1 From a91f5d5d8395303b28faaa314c02e99c857784f1 Mon Sep 17 00:00:00 2001 From: taeyoung Date: Wed, 21 Sep 2016 16:54:54 +0900 Subject: [PATCH 09/16] usbhost api: replace libdeviced to dbus method libusb cannot use libdeviced since circular dependency problem exists. libusb -> bluez -> pulseaudio (libpulse) -> efl (ecore) -> deviced -> libusb Thus libdeviced is replaced to the dbus method which is provided by deviced. Change-Id: Ia1ee8b72c17f30c8b4c49526d0101ed9294f230f Signed-off-by: taeyoung [Rebase onto new library version] Signed-off-by: Krzysztof Opasiak --- configure.ac | 16 +++---- libusb/Makefile.am | 6 +-- libusb/os/linux_usbfs.c | 102 +++++++++++++++++++++++++++++++++++++--- packaging/libusb.spec | 4 +- 4 files changed, 109 insertions(+), 19 deletions(-) diff --git a/configure.ac b/configure.ac index c822e5b..72a9d70 100644 --- a/configure.ac +++ b/configure.ac @@ -107,15 +107,15 @@ case $backend in linux) AC_DEFINE(OS_LINUX, 1, [Linux backend]) AC_SUBST(OS_LINUX) - AC_ARG_ENABLE([deviced], - [AC_HELP_STRING([--enable-deviced], [Use deviced to obtain dev node fds [default=no]])], - [], [enable_deviced="no"]) - if test "x$enable_deviced" = "xyes"; then - PKG_CHECK_MODULES([DEVICED], [deviced]) - AC_DEFINE(USE_DEVICED, 1, [Use deviced to obtain dev node fds]) + 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_DEVICED) + AC_SUBST(USE_USBHOST_API) AC_SEARCH_LIBS(clock_gettime, rt, [], [], -pthread) AC_ARG_ENABLE([udev], @@ -223,7 +223,7 @@ AM_CONDITIONAL(THREADS_POSIX, test "x$threads" = xposix) 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_DEVICED, test "x$enable_deviced" = xyes) +AM_CONDITIONAL(USE_USBHOST_API, test "x$enable_usbhost_api" = xyes) if test "$threads" = posix; then AC_DEFINE(THREADS_POSIX, 1, [Use POSIX Threads]) fi diff --git a/libusb/Makefile.am b/libusb/Makefile.am index e6fc154..d2bb864 100644 --- a/libusb/Makefile.am +++ b/libusb/Makefile.am @@ -104,8 +104,8 @@ hdrdir = $(includedir)/libusb-1.0 hdr_HEADERS = libusb.h if OS_LINUX -if USE_DEVICED -libusb_1_0_la_CFLAGS += $(DEVICED_CFLAGS) -libusb_1_0_la_LIBADD = $(DEVICED_LIBS) +if USE_USBHOST_API +libusb_1_0_la_CFLAGS += $(USBHOST_API_CFLAGS) +libusb_1_0_la_LIBADD = $(USBHOST_API_LIBS) endif endif diff --git a/libusb/os/linux_usbfs.c b/libusb/os/linux_usbfs.c index 90b80c4..588435b 100644 --- a/libusb/os/linux_usbfs.c +++ b/libusb/os/linux_usbfs.c @@ -40,8 +40,8 @@ #include /* Tizen specific */ -#ifdef USE_DEVICED -#include +#ifdef USE_USBHOST_API +#include #endif #include "libusbi.h" @@ -211,7 +211,97 @@ static int _direct_open_device(struct libusb_context *ctx, const char *path, return fd; } -#ifdef USE_DEVICED +#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); + return NULL; + } + + dbus_message_iter_init_append(msg, &iter); + dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &path); + + 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); + 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; @@ -231,7 +321,7 @@ static int _ask_for_open(const char *path, mode_t mode, int silent) return ret; } -#endif /* USE_DEVICED */ +#endif /* USE_USBHOST_API */ static int _get_usbfs_fd(struct libusb_device *dev, mode_t mode, int silent) { @@ -250,7 +340,7 @@ static int _get_usbfs_fd(struct libusb_device *dev, mode_t mode, int silent) if (fd != -1) return fd; /* Success */ -#ifdef USE_DEVICED +#ifdef USE_USBHOST_API /* * If we are here, we were unable to go simple * path and open the device directly. In Tizen @@ -272,7 +362,7 @@ static int _get_usbfs_fd(struct libusb_device *dev, mode_t mode, int silent) if (fd != -1) return fd; } -#endif /* USE_DEVICED */ +#endif /* USE_USBHOST_API */ if (!silent) { usbi_err(ctx, "libusb couldn't open USB device %s: %s", diff --git a/packaging/libusb.spec b/packaging/libusb.spec index e43ef05..611b690 100644 --- a/packaging/libusb.spec +++ b/packaging/libusb.spec @@ -11,7 +11,7 @@ Source1001: libusb.manifest BuildRequires: pkg-config BuildRequires: systemd-devel %if "%{?profile}" == "mobile" -BuildRequires: pkgconfig(deviced) +BuildRequires: pkgconfig(dbus-1) %endif %description @@ -34,7 +34,7 @@ cp %{SOURCE1001} . %reconfigure\ --with-pic\ %if "%{?profile}" == "mobile" - --enable-deviced\ + --enable-usbhost-api \ %endif --disable-static make %{?_smp_mflags} -- 2.34.1 From 6814ab13f05bdfa2d4e4d50e8bd2e88f1201bb63 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Pawe=C5=82=20Szewczyk?= Date: Wed, 21 Sep 2016 14:50:36 +0200 Subject: [PATCH 10/16] usbhost api: fix dbus method call to deviced MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Change-Id: If17b9f30e2301bea9558e2899f740e952b1455b1 Signed-off-by: Paweł Szewczyk --- libusb/os/linux_usbfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libusb/os/linux_usbfs.c b/libusb/os/linux_usbfs.c index 588435b..98700eb 100644 --- a/libusb/os/linux_usbfs.c +++ b/libusb/os/linux_usbfs.c @@ -243,7 +243,7 @@ DBusMessage *dbus_method_sync_with_reply(const char *dest, const char *path, } dbus_message_iter_init_append(msg, &iter); - dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &path); + dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, ¶m); dbus_error_init(&err); -- 2.34.1 From 330388d79ad89da4615de5e966e8daa06a0e47e3 Mon Sep 17 00:00:00 2001 From: taeyoung Date: Thu, 23 Feb 2017 13:52:12 +0900 Subject: [PATCH 11/16] usbhost api: remove profile dependency - Only Mobile profile supported usb host api until Tizen 3.0 - To remove the profile dependency, usb host api related codes are enabled. = If usb host api is used, all things are same with Tizen 3.0 = If libusb is used directly, 1) root users can access to usb device like Tizen 3.0 2) normal users cannot open usb device, and thus dbus requests to deviced will be triggered. If deviced supports usb host api, usb permission popup will be launched for the confirmation from user. If deviced does not support usb host api, the requests are rejected. Change-Id: Id72a27d5aa78ebaf8006a649c20d88d2c0e6ca65 Signed-off-by: taeyoung --- packaging/libusb.spec | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packaging/libusb.spec b/packaging/libusb.spec index 611b690..abdf1d1 100644 --- a/packaging/libusb.spec +++ b/packaging/libusb.spec @@ -1,3 +1,5 @@ +%define TIZEN_FEATURE_USBHOST_API on + Name: libusb Version: 1.0.19 Release: 0 @@ -10,7 +12,7 @@ Source1: baselibs.conf Source1001: libusb.manifest BuildRequires: pkg-config BuildRequires: systemd-devel -%if "%{?profile}" == "mobile" +%if %{?TIZEN_FEATURE_USBHOST_API} == on BuildRequires: pkgconfig(dbus-1) %endif @@ -33,7 +35,7 @@ cp %{SOURCE1001} . %build %reconfigure\ --with-pic\ -%if "%{?profile}" == "mobile" +%if %{?TIZEN_FEATURE_USBHOST_API} == on --enable-usbhost-api \ %endif --disable-static -- 2.34.1 From 57de58123b20bfed4ae43f4bef292c7d7175f9be Mon Sep 17 00:00:00 2001 From: Krzysztof Opasiak Date: Thu, 13 Apr 2017 13:23:27 +0200 Subject: [PATCH 12/16] Bump version to v.1.0.21 1) Switch from pristine-tar model to new one (upstream + tizen branch) 2) Drop commits: 59f513e91878a8b87a8462b1cf49b46d55f959ce ("Do not search for usbfs path") a9d76751ed87ae59949aa050a6268a2def70d208 ("usbhost api: do not search the usbfs path for Mobile profile") as there is a suitable fix in mainline 3) Upgrade libusb to v1.0.21 Change-Id: I42ec75e9d3b95c4cbf978125b5d945cf0896b27e Signed-off-by: Krzysztof Opasiak --- packaging/libusb.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/libusb.spec b/packaging/libusb.spec index abdf1d1..6835892 100644 --- a/packaging/libusb.spec +++ b/packaging/libusb.spec @@ -1,7 +1,7 @@ %define TIZEN_FEATURE_USBHOST_API on Name: libusb -Version: 1.0.19 +Version: 1.0.21 Release: 0 License: LGPL-2.1+ Summary: USB Library -- 2.34.1 From dac5d4f13864266e620d85fc1c65a04ba45c1d3a Mon Sep 17 00:00:00 2001 From: INSUN PYO Date: Fri, 23 Jun 2017 17:45:04 +0900 Subject: [PATCH 13/16] dbus: add missing dbus_connection_unref() for shared connection Signed-off-by: INSUN PYO Change-Id: I50c418861daa72fe77339897530df745897068ee --- libusb/os/linux_usbfs.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libusb/os/linux_usbfs.c b/libusb/os/linux_usbfs.c index 98700eb..17d1c90 100644 --- a/libusb/os/linux_usbfs.c +++ b/libusb/os/linux_usbfs.c @@ -239,6 +239,7 @@ DBusMessage *dbus_method_sync_with_reply(const char *dest, const char *path, if (!msg) { usbi_err(NULL, "dbus_message_new_method_call(%s:%s-%s)", path, interface, method); + dbus_connection_unref (conn); return NULL; } @@ -261,6 +262,7 @@ DBusMessage *dbus_method_sync_with_reply(const char *dest, const char *path, } dbus_message_unref(msg); + dbus_connection_unref (conn); return reply; } -- 2.34.1 From f99412bfd13c526be1f42bd9b5aad7b59c79bccb Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Thu, 20 Jul 2017 16:18:39 +0900 Subject: [PATCH 14/16] usbhost : add 99-usbhost.rules file to control usb node Change-Id: I2df224d35e058d0580233a03892d05b67ea04631 Signed-off-by: lokilee73 --- packaging/libusb.spec | 5 +++++ udev/99-usbhost.rules | 2 ++ 2 files changed, 7 insertions(+) mode change 100644 => 100755 packaging/libusb.spec create mode 100755 udev/99-usbhost.rules diff --git a/packaging/libusb.spec b/packaging/libusb.spec old mode 100644 new mode 100755 index 6835892..df9fa10 --- a/packaging/libusb.spec +++ b/packaging/libusb.spec @@ -43,6 +43,9 @@ 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 @@ -53,6 +56,8 @@ make %{?_smp_mflags} %defattr(-,root,root) %license COPYING %{_libdir}/*.so.* +# usbhost_module +%{_prefix}/lib/udev/rules.d/99-usbhost.rules %files devel %manifest %{name}.manifest diff --git a/udev/99-usbhost.rules b/udev/99-usbhost.rules new file mode 100755 index 0000000..a719bec --- /dev/null +++ b/udev/99-usbhost.rules @@ -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}="*" -- 2.34.1 From aaf3894c9953eecfd97a241f3ce1961322b542db Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Fri, 8 Sep 2017 17:25:05 +0900 Subject: [PATCH 15/16] Add a LICENSE.MIT file and it to the build spec. Change-Id: I6777ddcb521f98b1130ae64d89db0f73f03bdcc7 Signed-off-by: Hyotaek Shim (cherry picked from commit 4ae9aa7a8aa203e1e86f3b09320ff695dcca8f0a) --- COPYING => LICENSE.LGPL-2.1+ | 16 +++++++--------- LICENSE.MIT | 9 +++++++++ packaging/libusb.spec | 5 +++-- 3 files changed, 19 insertions(+), 11 deletions(-) rename COPYING => LICENSE.LGPL-2.1+ (98%) create mode 100644 LICENSE.MIT diff --git a/COPYING b/LICENSE.LGPL-2.1+ similarity index 98% rename from COPYING rename to LICENSE.LGPL-2.1+ index 5ab7695..4362b49 100644 --- a/COPYING +++ b/LICENSE.LGPL-2.1+ @@ -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. - 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 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 index 0000000..6e09dc8 --- /dev/null +++ b/LICENSE.MIT @@ -0,0 +1,9 @@ +The MIT License + +Copyright (c) + +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. diff --git a/packaging/libusb.spec b/packaging/libusb.spec index df9fa10..70a8026 100755 --- a/packaging/libusb.spec +++ b/packaging/libusb.spec @@ -3,7 +3,7 @@ Name: libusb Version: 1.0.21 Release: 0 -License: LGPL-2.1+ +License: LGPL-2.1+, MIT Summary: USB Library Url: http://www.libusb.org/ Group: Base/Device Management @@ -54,7 +54,7 @@ install -m 644 udev/99-usbhost.rules %{buildroot}%{_prefix}/lib/udev/rules.d/99- %files %manifest %{name}.manifest %defattr(-,root,root) -%license COPYING +%license LICENSE.LGPL-2.1+ LICENSE.MIT %{_libdir}/*.so.* # usbhost_module %{_prefix}/lib/udev/rules.d/99-usbhost.rules @@ -62,6 +62,7 @@ install -m 644 udev/99-usbhost.rules %{buildroot}%{_prefix}/lib/udev/rules.d/99- %files devel %manifest %{name}.manifest %defattr(-,root,root) +%license LICENSE.LGPL-2.1+ LICENSE.MIT %{_includedir}/libusb-1.0 %{_libdir}/*.so %{_libdir}/pkgconfig/*.pc -- 2.34.1 From 098d1afc0a158542559095b363de76fc843e7433 Mon Sep 17 00:00:00 2001 From: Karol Lewandowski Date: Sat, 18 Jul 2020 01:04:10 +0200 Subject: [PATCH 16/16] Fix memory leak in usb_interface_descriptor error path usbi_reallocf() will leak memory if passed pointer has members to free. Change-Id: I183dce6067905c92a1cf373e67902244c52e9fed Signed-off-by: lokilee73 --- libusb/descriptor.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libusb/descriptor.c b/libusb/descriptor.c index 4c9435f..da34b38 100644 --- a/libusb/descriptor.c +++ b/libusb/descriptor.c @@ -228,7 +228,8 @@ static int parse_interface(libusb_context *ctx, while (size >= INTERFACE_DESC_LENGTH) { struct libusb_interface_descriptor *altsetting = (struct libusb_interface_descriptor *) usb_interface->altsetting; - altsetting = usbi_reallocf(altsetting, + /* can't use usbi_realloc() as we need to free libusb_interface_descriptor members - see clear_interface() */ + altsetting = realloc(altsetting, sizeof(struct libusb_interface_descriptor) * (usb_interface->num_altsetting + 1)); if (!altsetting) { -- 2.34.1