usb_printer: support for alternate interfaces, not just the default one.

* Tested with a Profilic USB-Parallel adapter and a Laserjet printer.
This commit is contained in:
Jérôme Duval
2011-11-24 18:59:42 +01:00
parent 6b41836304
commit dea8f9c766
2 changed files with 26 additions and 15 deletions
@@ -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");
@@ -6,10 +6,10 @@
* Michael Lotz <[email protected]>
* Michael Pfeiffer <[email protected]>
*/
#ifndef _USB_PRINTER_H_
#define _USB_PRINTER_H_
#include <lock.h>
#include <USB3.h>
@@ -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