usb_serial: Probe for USB endpoints on Option device

* More then one serial port is common, for now we only
  work off of the first one detected.
* Still disabled as some setup is needed.
This commit is contained in:
Alexander von Gluck IV
2012-07-22 11:57:25 -05:00
parent b3b04af940
commit 52b7ccf49e
2 changed files with 57 additions and 7 deletions
@@ -24,8 +24,58 @@ OptionDevice::AddDevice(const usb_configuration_info *config)
{
TRACE_FUNCALLS("> OptionDevice::AddDevice(%08x, %08x)\n", this, config);
status_t status = B_OK;
return status;
if (config->interface_count > 0) {
for (size_t index = 0; index < config->interface_count; index++) {
usb_interface_info *interface = config->interface[index].active;
int txEndpointID = -1;
int rxEndpointID = -1;
int irEndpointID = -1;
for (size_t i = 0; i < interface->endpoint_count; i++) {
usb_endpoint_info *endpoint = &interface->endpoint[i];
// Find our Interrupt endpoint
if (endpoint->descr->attributes == USB_ENDPOINT_ATTR_INTERRUPT
&& (endpoint->descr->endpoint_address
& USB_ENDPOINT_ADDR_DIR_IN) != 0) {
irEndpointID = i;
continue;
}
// Find our Transmit / Receive endpoints
if (endpoint->descr->attributes == USB_ENDPOINT_ATTR_BULK) {
if ((endpoint->descr->endpoint_address
& USB_ENDPOINT_ADDR_DIR_IN) != 0) {
rxEndpointID = i;
} else {
txEndpointID = i;
}
continue;
}
}
TRACE("> OptionDevice::%s: endpoint %d, tx: %d, rx: %d, ir: %d\n",
__func__, index, txEndpointID, rxEndpointID, irEndpointID);
if (txEndpointID < 0 || rxEndpointID < 0 || irEndpointID < 0)
continue;
TRACE("> OptionDevice::%s: found at interface %d\n", __func__,
index);
usb_endpoint_info *irEndpoint = &interface->endpoint[irEndpointID];
usb_endpoint_info *txEndpoint = &interface->endpoint[irEndpointID];
usb_endpoint_info *rxEndpoint = &interface->endpoint[irEndpointID];
SetControlPipe(irEndpoint->handle);
SetReadPipe(rxEndpoint->handle);
SetWritePipe(txEndpoint->handle);
// We accept the first found serial interface
// TODO: We should set each matching interface up (can be > 1)
return B_OK;
}
}
return ENODEV;
}
@@ -725,7 +725,7 @@ SerialDevice::MakeDevice(usb_device device, uint16 vendorID,
/ sizeof(kFTDIDevices[0]); i++) {
if (vendorID == kFTDIDevices[i].vendorID
&& productID == kFTDIDevices[i].productID) {
return new(std::nothrow) FTDIDevice(device, vendorID, productID,
return new(std::nothrow) FTDIDevice(device, vendorID, productID,
kFTDIDevices[i].deviceName);
}
}
@@ -735,7 +735,7 @@ SerialDevice::MakeDevice(usb_device device, uint16 vendorID,
/ sizeof(kKLSIDevices[0]); i++) {
if (vendorID == kKLSIDevices[i].vendorID
&& productID == kKLSIDevices[i].productID) {
return new(std::nothrow) KLSIDevice(device, vendorID, productID,
return new(std::nothrow) KLSIDevice(device, vendorID, productID,
kKLSIDevices[i].deviceName);
}
}
@@ -745,7 +745,7 @@ SerialDevice::MakeDevice(usb_device device, uint16 vendorID,
/ sizeof(kProlificDevices[0]); i++) {
if (vendorID == kProlificDevices[i].vendorID
&& productID == kProlificDevices[i].productID) {
return new(std::nothrow) ProlificDevice(device, vendorID, productID,
return new(std::nothrow) ProlificDevice(device, vendorID, productID,
kProlificDevices[i].deviceName);
}
}
@@ -755,7 +755,7 @@ SerialDevice::MakeDevice(usb_device device, uint16 vendorID,
/ sizeof(kSiliconDevices[0]); i++) {
if (vendorID == kSiliconDevices[i].vendorID
&& productID == kSiliconDevices[i].productID) {
return new(std::nothrow) SiliconDevice(device, vendorID, productID,
return new(std::nothrow) SiliconDevice(device, vendorID, productID,
kSiliconDevices[i].deviceName);
}
}
@@ -768,7 +768,7 @@ SerialDevice::MakeDevice(usb_device device, uint16 vendorID,
/ sizeof(kOptionDevices[0]); i++) {
if (vendorID == kOptionDevices[i].vendorID
&& productID == kOptionDevices[i].productID) {
return new(std::nothrow) OptionDevice(device, vendorID, productID,
return new(std::nothrow) OptionDevice(device, vendorID, productID,
kOptionDevices[i].deviceName);
}
}