Blame SOURCES/0006-Add-Null-POSIX-backend.patch

311d97
From 23557c82fd09b4ab7b106c13287a3ec8291f42dc Mon Sep 17 00:00:00 2001
311d97
From: Pino Toscano <toscano.pino@tiscali.it>
311d97
Date: Fri, 27 Dec 2019 18:41:28 +0100
311d97
Subject: [PATCH 06/10] Add Null POSIX backend
311d97
311d97
Add a simple null backend for POSIX platforms that reports no available
311d97
devices, and provides no capabilities. Make use of this new backend on
311d97
all the OSes without an existing backend, so libusb can be built even on
311d97
OSes without USB support.
311d97
311d97
(cherry picked from commit 53572d7e5eee79266139399924c7491174be1670)
311d97
---
311d97
 configure.ac          |  13 +++-
311d97
 libusb/Makefile.am    |   7 +-
311d97
 libusb/libusbi.h      |   2 +-
311d97
 libusb/os/null_usb.c  | 176 ++++++++++++++++++++++++++++++++++++++++++
311d97
 libusb/version_nano.h |   2 +-
311d97
 5 files changed, 196 insertions(+), 4 deletions(-)
311d97
 create mode 100644 libusb/os/null_usb.c
311d97
311d97
diff --git a/configure.ac b/configure.ac
311d97
index da8a158..ddde325 100644
311d97
--- a/configure.ac
311d97
+++ b/configure.ac
311d97
@@ -100,7 +100,9 @@ case $host in
311d97
 	threads=posix
311d97
 	;;
311d97
 *)
311d97
-	AC_MSG_ERROR([unsupported operating system $host])
311d97
+	AC_MSG_RESULT([Null])
311d97
+	backend="null"
311d97
+	threads="posix"
311d97
 esac
311d97
 
311d97
 case $backend in
311d97
@@ -186,6 +188,14 @@ haiku)
311d97
 	AC_CHECK_HEADERS([poll.h])
311d97
 	AC_DEFINE([POLL_NFDS_TYPE],[nfds_t],[type of second poll() argument])
311d97
 	;;
311d97
+null)
311d97
+	AC_DEFINE(OS_NULL, 1, [Null backend])
311d97
+	AC_SUBST(OS_NULL)
311d97
+	THREAD_CFLAGS="-pthread"
311d97
+	LIBS="-pthread"
311d97
+	AC_CHECK_HEADERS([poll.h])
311d97
+	AC_DEFINE([POLL_NFDS_TYPE],[nfds_t],[type of second poll() argument])
311d97
+	;;
311d97
 esac
311d97
 
311d97
 AC_SUBST(LIBS)
311d97
@@ -197,6 +207,7 @@ AM_CONDITIONAL(OS_SUNOS, test "x$backend" = xsunos)
311d97
 AM_CONDITIONAL(OS_NETBSD, test "x$backend" = xnetbsd)
311d97
 AM_CONDITIONAL(OS_WINDOWS, test "x$backend" = xwindows)
311d97
 AM_CONDITIONAL(OS_HAIKU, test "x$backend" = xhaiku)
311d97
+AM_CONDITIONAL(OS_NULL, test "x$backend" = xnull)
311d97
 AM_CONDITIONAL(THREADS_POSIX, test "x$threads" = xposix)
311d97
 AM_CONDITIONAL(CREATE_IMPORT_LIB, test "x$create_import_lib" = xyes)
311d97
 AM_CONDITIONAL(USE_UDEV, test "x$enable_udev" = xyes)
311d97
diff --git a/libusb/Makefile.am b/libusb/Makefile.am
311d97
index e4da62e..466b633 100644
311d97
--- a/libusb/Makefile.am
311d97
+++ b/libusb/Makefile.am
311d97
@@ -22,13 +22,14 @@ WINDOWS_USB_SRC = libusb-1.0.def libusb-1.0.rc \
311d97
 WINCE_USB_SRC = os/wince_usb.h os/wince_usb.c
311d97
 HAIKU_USB_SRC = os/haiku_usb.h os/haiku_usb_backend.cpp \
311d97
 		os/haiku_usb_raw.h os/haiku_usb_raw.cpp os/haiku_pollfs.cpp
311d97
+NULL_USB_SRC = os/null_usb.c
311d97
 
311d97
 EXTRA_DIST = $(POSIX_POLL_SRC) $(POSIX_THREADS_SRC) \
311d97
 	$(WINDOWS_POLL_SRC) $(WINDOWS_THREADS_SRC) \
311d97
 	$(LINUX_USBFS_SRC) $(DARWIN_USB_SRC) \
311d97
 	$(OPENBSD_USB_SRC) $(NETBSD_USB_SRC) \
311d97
 	$(WINDOWS_USB_SRC) $(WINCE_USB_SRC) \
311d97
-	$(HAIKU_USB_SRC) \
311d97
+	$(HAIKU_USB_SRC) $(NULL_USB_SRC) \
311d97
 	os/linux_udev.c os/linux_netlink.c
311d97
 
311d97
 if OS_LINUX
311d97
@@ -64,6 +65,10 @@ libusb_haiku_la_SOURCES = $(HAIKU_USB_SRC)
311d97
 libusb_1_0_la_LIBADD = libusb_haiku.la
311d97
 endif
311d97
 
311d97
+if OS_NULL
311d97
+OS_SRC = $(NULL_USB_SRC)
311d97
+endif
311d97
+
311d97
 if OS_WINDOWS
311d97
 OS_SRC = $(WINDOWS_USB_SRC)
311d97
 
311d97
diff --git a/libusb/libusbi.h b/libusb/libusbi.h
311d97
index 0a677bd..4cb6141 100644
311d97
--- a/libusb/libusbi.h
311d97
+++ b/libusb/libusbi.h
311d97
@@ -575,7 +575,7 @@ int usbi_clear_event(struct libusb_context *ctx);
311d97
 
311d97
 /* Internal abstraction for poll (needs struct usbi_transfer on Windows) */
311d97
 #if defined(OS_LINUX) || defined(OS_DARWIN) || defined(OS_OPENBSD) || defined(OS_NETBSD) ||\
311d97
-	defined(OS_HAIKU) || defined(OS_SUNOS)
311d97
+	defined(OS_HAIKU) || defined(OS_SUNOS) || defined(OS_NULL)
311d97
 #include <unistd.h>
311d97
 #include "os/poll_posix.h"
311d97
 #elif defined(OS_WINDOWS) || defined(OS_WINCE)
311d97
diff --git a/libusb/os/null_usb.c b/libusb/os/null_usb.c
311d97
new file mode 100644
311d97
index 0000000..97fa0b8
311d97
--- /dev/null
311d97
+++ b/libusb/os/null_usb.c
311d97
@@ -0,0 +1,176 @@
311d97
+/*
311d97
+ * Copyright © 2019 Pino Toscano <toscano.pino@tiscali.it>
311d97
+ *
311d97
+ * This library is free software; you can redistribute it and/or
311d97
+ * modify it under the terms of the GNU Lesser General Public
311d97
+ * License as published by the Free Software Foundation; either
311d97
+ * version 2.1 of the License, or (at your option) any later version.
311d97
+ *
311d97
+ * This library is distributed in the hope that it will be useful,
311d97
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
311d97
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
311d97
+ * Lesser General Public License for more details.
311d97
+ *
311d97
+ * You should have received a copy of the GNU Lesser General Public
311d97
+ * License along with this library; if not, write to the Free Software
311d97
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
311d97
+ */
311d97
+
311d97
+#include "libusbi.h"
311d97
+
311d97
+static int
311d97
+null_get_device_list(struct libusb_context * ctx,
311d97
+	struct discovered_devs **discdevs)
311d97
+{
311d97
+	return LIBUSB_SUCCESS;
311d97
+}
311d97
+
311d97
+static int
311d97
+null_open(struct libusb_device_handle *handle)
311d97
+{
311d97
+	return LIBUSB_ERROR_NOT_SUPPORTED;
311d97
+}
311d97
+
311d97
+static void
311d97
+null_close(struct libusb_device_handle *handle)
311d97
+{
311d97
+}
311d97
+
311d97
+static int
311d97
+null_get_device_descriptor(struct libusb_device *dev, unsigned char *buf,
311d97
+    int *host_endian)
311d97
+{
311d97
+	return LIBUSB_ERROR_NOT_SUPPORTED;
311d97
+}
311d97
+
311d97
+static int
311d97
+null_get_active_config_descriptor(struct libusb_device *dev,
311d97
+    unsigned char *buf, size_t len, int *host_endian)
311d97
+{
311d97
+	return LIBUSB_ERROR_NOT_SUPPORTED;
311d97
+}
311d97
+
311d97
+static int
311d97
+null_get_config_descriptor(struct libusb_device *dev, uint8_t idx,
311d97
+    unsigned char *buf, size_t len, int *host_endian)
311d97
+{
311d97
+	return LIBUSB_ERROR_NOT_SUPPORTED;
311d97
+}
311d97
+
311d97
+static int
311d97
+null_set_configuration(struct libusb_device_handle *handle, int config)
311d97
+{
311d97
+	return LIBUSB_ERROR_NOT_SUPPORTED;
311d97
+}
311d97
+
311d97
+static int
311d97
+null_claim_interface(struct libusb_device_handle *handle, int iface)
311d97
+{
311d97
+	return LIBUSB_ERROR_NOT_SUPPORTED;
311d97
+}
311d97
+
311d97
+static int
311d97
+null_release_interface(struct libusb_device_handle *handle, int iface)
311d97
+{
311d97
+	return LIBUSB_ERROR_NOT_SUPPORTED;
311d97
+}
311d97
+
311d97
+static int
311d97
+null_set_interface_altsetting(struct libusb_device_handle *handle, int iface,
311d97
+    int altsetting)
311d97
+{
311d97
+	return LIBUSB_ERROR_NOT_SUPPORTED;
311d97
+}
311d97
+
311d97
+static int
311d97
+null_clear_halt(struct libusb_device_handle *handle, unsigned char endpoint)
311d97
+{
311d97
+	return LIBUSB_ERROR_NOT_SUPPORTED;
311d97
+}
311d97
+
311d97
+static int
311d97
+null_reset_device(struct libusb_device_handle *handle)
311d97
+{
311d97
+	return LIBUSB_ERROR_NOT_SUPPORTED;
311d97
+}
311d97
+
311d97
+static int
311d97
+null_submit_transfer(struct usbi_transfer *itransfer)
311d97
+{
311d97
+	return LIBUSB_ERROR_NOT_SUPPORTED;
311d97
+}
311d97
+
311d97
+static int
311d97
+null_cancel_transfer(struct usbi_transfer *itransfer)
311d97
+{
311d97
+	return LIBUSB_ERROR_NOT_SUPPORTED;
311d97
+}
311d97
+
311d97
+static void
311d97
+null_clear_transfer_priv(struct usbi_transfer *itransfer)
311d97
+{
311d97
+}
311d97
+
311d97
+static int
311d97
+null_handle_transfer_completion(struct usbi_transfer *itransfer)
311d97
+{
311d97
+	return LIBUSB_ERROR_NOT_SUPPORTED;
311d97
+}
311d97
+
311d97
+static int
311d97
+null_clock_gettime(int clkid, struct timespec *tp)
311d97
+{
311d97
+	switch (clkid) {
311d97
+	case USBI_CLOCK_MONOTONIC:
311d97
+		return clock_gettime(CLOCK_REALTIME, tp);
311d97
+	case USBI_CLOCK_REALTIME:
311d97
+		return clock_gettime(CLOCK_REALTIME, tp);
311d97
+	default:
311d97
+		return LIBUSB_ERROR_INVALID_PARAM;
311d97
+	}
311d97
+}
311d97
+
311d97
+const struct usbi_os_backend usbi_backend = {
311d97
+	.name = "Null backend",
311d97
+	.caps = 0,
311d97
+	.init = NULL,
311d97
+	.exit = NULL,
311d97
+	.set_option = NULL,
311d97
+	.get_device_list = null_get_device_list,
311d97
+	.hotplug_poll = NULL,
311d97
+	.wrap_sys_device = NULL,
311d97
+	.open = null_open,
311d97
+	.close = null_close,
311d97
+	.get_device_descriptor = null_get_device_descriptor,
311d97
+	.get_active_config_descriptor = null_get_active_config_descriptor,
311d97
+	.get_config_descriptor = null_get_config_descriptor,
311d97
+	.get_config_descriptor_by_value = NULL,
311d97
+	.get_configuration = NULL,
311d97
+	.set_configuration = null_set_configuration,
311d97
+	.claim_interface = null_claim_interface,
311d97
+	.release_interface = null_release_interface,
311d97
+	.set_interface_altsetting = null_set_interface_altsetting,
311d97
+	.clear_halt = null_clear_halt,
311d97
+	.reset_device = null_reset_device,
311d97
+	.alloc_streams = NULL,
311d97
+	.free_streams = NULL,
311d97
+	.dev_mem_alloc = NULL,
311d97
+	.dev_mem_free = NULL,
311d97
+	.kernel_driver_active = NULL,
311d97
+	.detach_kernel_driver = NULL,
311d97
+	.attach_kernel_driver = NULL,
311d97
+	.destroy_device = NULL,
311d97
+	.submit_transfer = null_submit_transfer,
311d97
+	.cancel_transfer = null_cancel_transfer,
311d97
+	.clear_transfer_priv = null_clear_transfer_priv,
311d97
+	.handle_events = NULL,
311d97
+	.handle_transfer_completion = null_handle_transfer_completion,
311d97
+	.clock_gettime = null_clock_gettime,
311d97
+#ifdef USBI_TIMERFD_AVAILABLE
311d97
+	.get_timerfd_clockid = NULL,
311d97
+#endif
311d97
+	.context_priv_size = 0,
311d97
+	.device_priv_size = 0,
311d97
+	.device_handle_priv_size = 0,
311d97
+	.transfer_priv_size = 0,
311d97
+};
311d97
diff --git a/libusb/version_nano.h b/libusb/version_nano.h
311d97
index 1764dec..4150474 100644
311d97
--- a/libusb/version_nano.h
311d97
+++ b/libusb/version_nano.h
311d97
@@ -1 +1 @@
311d97
-#define LIBUSB_NANO 11413
311d97
+#define LIBUSB_NANO 11415
311d97
-- 
311d97
2.26.1
311d97