virtual-usb-printer: fixing get device descriptor response

Handling the case where number of a bytes requested in a Get Device
Descriptor request is smaller than the actual device descriptor.

This change also adds canned responses for unsupported control requests.

BUG=None
TEST=Passes printer.AddUSBPrinter test

Change-Id: I9f050e6bbdb78c8984c415d6e58ff2fee68c891e
Reviewed-on: https://chromium-review.googlesource.com/1541883
Commit-Ready: David Valleau <valleau@chromium.org>
Tested-by: David Valleau <valleau@chromium.org>
Reviewed-by: Sean Kau <skau@chromium.org>
2 files changed
tree: 12686b1ea6996d4af8c7cf7c6f9a632818307622
  1. config/
  2. tools/
  3. cups_constants.cc
  4. cups_constants.h
  5. device_descriptors.cc
  6. device_descriptors.h
  7. ipp_test.cc
  8. ipp_util.cc
  9. ipp_util.h
  10. LICENSE
  11. load_config.cc
  12. load_config.h
  13. load_config_test.cc
  14. op_commands.cc
  15. op_commands.h
  16. README.md
  17. server.cc
  18. server.h
  19. smart_buffer.cc
  20. smart_buffer.h
  21. smart_buffer_test.cc
  22. usb_printer.cc
  23. usb_printer.h
  24. usbip.cc
  25. usbip.h
  26. usbip_constants.h
  27. value_util.cc
  28. value_util.h
  29. virtual_usb_printer.cc
  30. virtual_usb_printer.gyp
README.md

Virtual USB Printer

Virtual USB Printer provides a server which can be used with USBIP in order to emulate a USB printing device and bind it to the system as if it were physically connected to a USB port.

Virtual USB Printer supports both regular USB printers as well as IPP-over-USB devices.

Motivation

This project was created in order to make on-device tests which check for any regressions in the native USB printing system.

Requirements

  • USBIP - userspace program for binding virtual device to system
  • USBIP kernel modules:
    • CONFIG_USBIP_CORE
    • CONFIG_USBIP_VHCI_HCD
  • Linux Kernel v4.14 - USBIP currently only works on this kernel version

In order to actually “connect” the virtual printer to the system the USBIP program is used.

USBIP is typically used to export real USB devices over a network so that other systems on the network can bind them and treat them as connected devices.

For the purposes of the virtual printer, only the client portion of USBIP is required so that the virtual device can be bound to the system.

How to Use

Run the virtual-usb-printer program:

virtual-usb-printer --descriptors_path=<path>

(Optional) Check the list of exported printers with USBIP:

usbip list -r localhost

Should return something like this:

Exportable USB devices
======================
 - localhost
        1-1: Canon, Inc. : unknown product (04a9:27e8)
           : /sys/devices/pci0000:00/0000:00:01.2/usb1/1-1
           : (Defined at Interface level) (00/00/00)
           : 0 - Printer / Printer Bidirectional (07/01/02)

Bind the virtual printer to the system:

usbip attach -r localhost -b 1-1

Once the device has been attached it should appear in the list of connected USB devices (lsusb), and can be used with the native printing system in Chrome OS.

Configuration

The printer's USB descriptors and defined IPP attributes can be configured using a JSON file and are loaded at run-time using command line flags. Example configurations can be found in the config/ directory.

The configuration files can be loaded with the following flags:

  • --descriptors_path - full path to the JSON file which defines the USB descriptors
  • --attributes_path - full path to the JSON file which defines the supported IPP attributes
    • Only needed for IPP-over-USB printer configurations
  • --record_doc_path - full path to the file used to record documents received from print jobs