USB transport addon: support for alternate interfaces.

* Tested with a Profilic USB-Parallel adapter and a Laserjet printer.
This commit is contained in:
Jérôme Duval 2012-05-03 22:22:33 +02:00
parent 408c7ab11d
commit 91bc463512
1 changed files with 36 additions and 28 deletions

View File

@ -112,16 +112,22 @@ USBPrinterRoster::DeviceAdded(BUSBDevice *dev)
// Try to find a working printer interface in this device
if (config) {
for (uint32 idx = 0; printer == NULL && idx < config->CountInterfaces(); idx++) {
for (uint32 idx = 0; printer == NULL
&& idx < config->CountInterfaces(); idx++) {
const BUSBInterface *interface = config->InterfaceAt(idx);
if (interface->Class() == PRINTER_INTERFACE_CLASS
&& interface->Subclass() == PRINTER_INTERFACE_SUBCLASS
&& (interface->Protocol() == PIT_UNIDIRECTIONAL
|| interface->Protocol() == PIT_BIDIRECTIONAL
|| interface->Protocol() == PIT_1284_4_COMPATIBLE)) {
for (uint32 alt = 0; alt < interface->CountAlternates(); alt++) {
const BUSBInterface *alternate = interface->AlternateAt(alt);
if (alternate->Class() == PRINTER_INTERFACE_CLASS
&& alternate->Subclass() == PRINTER_INTERFACE_SUBCLASS
&& (alternate->Protocol() == PIT_UNIDIRECTIONAL
|| alternate->Protocol() == PIT_BIDIRECTIONAL
|| alternate->Protocol() == PIT_1284_4_COMPATIBLE)) {
// Found a usable Printer interface!
for (uint32 endpointIdx = 0; endpointIdx < interface->CountEndpoints(); endpointIdx++) {
const BUSBEndpoint *endpoint = interface->EndpointAt(endpointIdx);
for (uint32 endpointIdx = 0;
endpointIdx < alternate->CountEndpoints();
endpointIdx++) {
const BUSBEndpoint *endpoint =
alternate->EndpointAt(endpointIdx);
if (!endpoint->IsBulk())
continue;
@ -133,12 +139,14 @@ USBPrinterRoster::DeviceAdded(BUSBDevice *dev)
if (!in || !out)
continue;
printer = interface;
printer = alternate;
((BUSBInterface*)interface)->SetAlternate(alt);
break;
}
}
}
}
}
if (printer != NULL) {
// We found a working printer interface, lets determine a unique ID