]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - backend/usb-libusb.c
Update ipp documentation to reflect the behavior of configuring WiFi on IPP USB printers.
[thirdparty/cups.git] / backend / usb-libusb.c
index 31b856da4b9863502019e6c6039590f0657a96db..d7c762392924fcfbd5251d885e13d77d7f4bf6e0 100644 (file)
@@ -1,15 +1,10 @@
 /*
- * "$Id$"
- *
  * LIBUSB interface code for CUPS.
  *
- * Copyright 2007-2014 by Apple Inc.
+ * Copyright 2007-2020 by Apple Inc.
  *
- * These coded instructions, statements, and computer programs are the
- * property of Apple Inc. and are protected by Federal copyright
- * law.  Distribution and use rights are outlined in the file "LICENSE.txt"
- * which should have been included with this file.  If this file is
- * file is missing or damaged, see the license at "http://www.cups.org/".
+ * Licensed under Apache License v2.0.  See the file "LICENSE" for more
+ * information.
  */
 
 /*
@@ -18,6 +13,7 @@
 
 #include <libusb.h>
 #include <cups/cups-private.h>
+#include <cups/ppd-private.h>
 #include <cups/dir.h>
 #include <pthread.h>
 #include <sys/select.h>
@@ -103,6 +99,7 @@ typedef struct usb_globals_s         /* Global USB printer information */
 #define USB_QUIRK_USB_INIT     0x0010  /* Needs vendor USB init string */
 #define USB_QUIRK_VENDOR_CLASS 0x0020  /* Descriptor uses vendor-specific
                                           Class or SubClass */
+#define USB_QUIRK_DELAY_CLOSE  0x0040  /* Delay close */
 #define USB_QUIRK_WHITELIST    0x0000  /* no quirks */
 
 
@@ -641,6 +638,9 @@ print_device(const char *uri,               /* I - Device URI */
   * Close the connection and input file and general clean up...
   */
 
+  if (g.printer->quirks & USB_QUIRK_DELAY_CLOSE)
+    sleep(1);
+
   close_device(g.printer);
 
  /*
@@ -826,8 +826,7 @@ find_device(usb_cb_t   cb,          /* I - Callback function */
   err = libusb_init(NULL);
   if (err)
   {
-    fprintf(stderr, "DEBUG: Unable to initialize USB access via libusb, "
-                    "libusb error %i\n", (int)err);
+    fprintf(stderr, "ERROR: Unable to initialize USB access via libusb, libusb error %i (%s)\n", (int)err, libusb_strerror((int)err));
     return (NULL);
   }
 
@@ -879,7 +878,7 @@ find_device(usb_cb_t   cb,          /* I - Callback function */
           protocol   = 0;
 
          for (altset = 0, altptr = ifaceptr->altsetting;
-              altset < ifaceptr->num_altsetting;
+              altset < ifaceptr->num_altsetting; // lgtm [cpp/comparison-with-wider-type]
               altset ++, altptr ++)
           {
           /*
@@ -1211,6 +1210,9 @@ load_quirks(void)
       if (strstr(line, " blacklist"))
         quirk->quirks |= USB_QUIRK_BLACKLIST;
 
+      if (strstr(line, " delay-close"))
+        quirk->quirks |= USB_QUIRK_DELAY_CLOSE;
+
       if (strstr(line, " no-reattach"))
         quirk->quirks |= USB_QUIRK_NO_REATTACH;
 
@@ -1522,6 +1524,16 @@ open_device(usb_printer_t *printer,      /* I - Printer */
 
       goto error;
     }
+    else if ((errcode = libusb_detach_kernel_driver(printer->handle, printer->iface)) < 0)
+    {
+      fprintf(stderr,
+              "DEBUG: Failed to detach \"usblp\" module from %04x:%04x\n",
+              devdesc.idVendor, devdesc.idProduct);
+
+      goto error;
+    }
+
+    sleep (1);
   }
 
  /*
@@ -1730,8 +1742,7 @@ static void *read_thread(void *reference)
     * Make sure this loop executes no more than once every 250 miliseconds...
     */
 
-    if ((readstatus != LIBUSB_SUCCESS || rbytes == 0) &&
-        (g.wait_eof || !g.read_thread_stop))
+    if ((g.wait_eof || !g.read_thread_stop))
     {
       gettimeofday(&now, NULL);
       if (timercmp(&now, &end, <))
@@ -2001,9 +2012,3 @@ soft_reset_printer(
 
   return (errcode);
 }
-
-
-/*
- * End of "$Id$".
- */
-