From dea8f9c7666e897a50d904ab02ea3f37107f734b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Duval?= Date: Thu, 24 Nov 2011 17:56:08 +0100 Subject: [PATCH] usb_printer: support for alternate interfaces, not just the default one. * Tested with a Profilic USB-Parallel adapter and a Laserjet printer. --- .../drivers/printer/usb/usb_printer.cpp | 38 ++++++++++++------- .../kernel/drivers/printer/usb/usb_printer.h | 3 +- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/src/add-ons/kernel/drivers/printer/usb/usb_printer.cpp b/src/add-ons/kernel/drivers/printer/usb/usb_printer.cpp index c16d4631d1..5514dd2443 100644 --- a/src/add-ons/kernel/drivers/printer/usb/usb_printer.cpp +++ b/src/add-ons/kernel/drivers/printer/usb/usb_printer.cpp @@ -159,25 +159,27 @@ usb_printer_device_added(usb_device newDevice, void **cookie) } for (size_t i = 0; i < configuration->interface_count; i++) { - usb_interface_info *interface = configuration->interface[i].active; - if (interface == NULL) - continue; - - if (interface->descr->interface_class == PRINTER_INTERFACE_CLASS - && interface->descr->interface_subclass == - PRINTER_INTERFACE_SUBCLASS - && (interface->descr->interface_protocol == PIT_UNIDIRECTIONAL - || interface->descr->interface_protocol == PIT_BIDIRECTIONAL - || interface->descr->interface_protocol - == PIT_1284_4_COMPATIBLE)) { + for (size_t j = 0; j < configuration->interface[i].alt_count; j++) { + usb_interface_info *interface = &configuration->interface[i].alt[j]; + if (interface == NULL + || interface->descr->interface_class != PRINTER_INTERFACE_CLASS + || interface->descr->interface_subclass != + PRINTER_INTERFACE_SUBCLASS + || !(interface->descr->interface_protocol == PIT_UNIDIRECTIONAL + || interface->descr->interface_protocol == PIT_BIDIRECTIONAL + || interface->descr->interface_protocol + == PIT_1284_4_COMPATIBLE)) { + continue; + } bool hasIn = false; bool hasOut = false; - for (size_t j = 0; j < interface->endpoint_count; j++) { - usb_endpoint_info *endpoint = &interface->endpoint[j]; + for (size_t k = 0; k < interface->endpoint_count; k++) { + usb_endpoint_info *endpoint = &interface->endpoint[k]; if (endpoint == NULL - || endpoint->descr->attributes != USB_ENDPOINT_ATTR_BULK) + || endpoint->descr->attributes != USB_ENDPOINT_ATTR_BULK) { continue; + } if (!hasIn && (endpoint->descr->endpoint_address & USB_ENDPOINT_ADDR_DIR_IN)) { @@ -197,6 +199,7 @@ usb_printer_device_added(usb_device newDevice, void **cookie) continue; device->interface = interface->descr->interface_number; + device->alternate = j; device->alternate_setting = interface->descr->alternate_setting; break; @@ -209,6 +212,13 @@ usb_printer_device_added(usb_device newDevice, void **cookie) return B_ERROR; } + status_t status = gUSBModule->set_alt_interface(newDevice, + &configuration->interface[device->interface].alt[device->alternate]); + if (status < B_OK) { + free(device); + return B_ERROR; + } + mutex_init(&device->lock, "usb_printer device lock"); device->notify = create_sem(0, "usb_printer callback notify"); diff --git a/src/add-ons/kernel/drivers/printer/usb/usb_printer.h b/src/add-ons/kernel/drivers/printer/usb/usb_printer.h index 4ae6986872..e507aac6db 100644 --- a/src/add-ons/kernel/drivers/printer/usb/usb_printer.h +++ b/src/add-ons/kernel/drivers/printer/usb/usb_printer.h @@ -6,10 +6,10 @@ * Michael Lotz * Michael Pfeiffer */ - #ifndef _USB_PRINTER_H_ #define _USB_PRINTER_H_ + #include #include @@ -45,6 +45,7 @@ typedef struct printer_device_s { usb_pipe bulk_in; usb_pipe bulk_out; uint8 interface; + uint8 alternate; uint8 alternate_setting; // used to store callback information