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

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