Move the quirky device detection out of the HIDDevice constructor and into the

usb_hid_device_added hook so that we can actually detect non-HID devices at all.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@42002 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Michael Lotz 2011-06-07 00:25:58 +00:00
parent 575517e617
commit 4ca60b965f
3 changed files with 44 additions and 23 deletions

View File

@ -82,10 +82,33 @@ usb_hid_device_added(usb_device device, void **cookie)
i, interfaceClass, interface->descr->interface_subclass, i, interfaceClass, interface->descr->interface_subclass,
interface->descr->interface_protocol); interface->descr->interface_protocol);
if (interfaceClass == USB_INTERFACE_CLASS_HID) { // check for quirky devices first
int32 quirkyIndex = -1;
for (int32 j = 0; j < gQuirkyDeviceCount; j++) {
usb_hid_quirky_device &quirky = gQuirkyDevices[j];
if ((quirky.vendor_id != 0
&& deviceDescriptor->vendor_id != quirky.vendor_id)
|| (quirky.product_id != 0
&& deviceDescriptor->product_id != quirky.product_id)
|| (quirky.device_class != 0
&& interfaceClass != quirky.device_class)
|| (quirky.device_subclass != 0
&& interface->descr->interface_subclass
!= quirky.device_subclass)
|| (quirky.device_protocol != 0
&& interface->descr->interface_protocol
!= quirky.device_protocol)) {
continue;
}
quirkyIndex = j;
break;
}
if (quirkyIndex >= 0 || interfaceClass == USB_INTERFACE_CLASS_HID) {
mutex_lock(&sDriverLock); mutex_lock(&sDriverLock);
HIDDevice *hidDevice HIDDevice *hidDevice
= new(std::nothrow) HIDDevice(device, config, i); = new(std::nothrow) HIDDevice(device, config, i, quirkyIndex);
if (hidDevice != NULL && hidDevice->InitCheck() == B_OK) { if (hidDevice != NULL && hidDevice->InitCheck() == B_OK) {
hidDevice->SetParentCookie(parentCookie); hidDevice->SetParentCookie(parentCookie);

View File

@ -24,7 +24,7 @@
HIDDevice::HIDDevice(usb_device device, const usb_configuration_info *config, HIDDevice::HIDDevice(usb_device device, const usb_configuration_info *config,
size_t interfaceIndex) size_t interfaceIndex, int32 quirkyIndex)
: fStatus(B_NO_INIT), : fStatus(B_NO_INIT),
fDevice(device), fDevice(device),
fInterfaceIndex(interfaceIndex), fInterfaceIndex(interfaceIndex),
@ -44,26 +44,19 @@ HIDDevice::HIDDevice(usb_device device, const usb_configuration_info *config,
const usb_device_descriptor *deviceDescriptor const usb_device_descriptor *deviceDescriptor
= gUSBModule->get_device_descriptor(device); = gUSBModule->get_device_descriptor(device);
// check for quirky devices first and don't bother in that case
HIDWriter descriptorWriter; HIDWriter descriptorWriter;
bool hasFixedDescriptor = false; bool hasFixedDescriptor = false;
quirky_init_function quirkyInit = NULL; if (quirkyIndex >= 0) {
for (int32 i = 0; i < gQuirkyDeviceCount; i++) { quirky_build_descriptor quirkyBuildDescriptor
usb_hid_quirky_device &quirky = gQuirkyDevices[i]; = gQuirkyDevices[quirkyIndex].build_descriptor;
if (deviceDescriptor->vendor_id == quirky.vendor_id
&& deviceDescriptor->product_id == quirky.product_id) {
quirkyInit = quirky.init_function; if (quirkyBuildDescriptor != NULL
if (quirky.build_descriptor != NULL && quirkyBuildDescriptor(descriptorWriter) == B_OK) {
&& quirky.build_descriptor(descriptorWriter) == B_OK) {
reportDescriptor = (uint8 *)descriptorWriter.Buffer(); reportDescriptor = (uint8 *)descriptorWriter.Buffer();
descriptorLength = descriptorWriter.BufferLength(); descriptorLength = descriptorWriter.BufferLength();
hasFixedDescriptor = true; hasFixedDescriptor = true;
} }
break;
}
} }
if (!hasFixedDescriptor) { if (!hasFixedDescriptor) {
@ -176,11 +169,16 @@ HIDDevice::HIDDevice(usb_device device, const usb_configuration_info *config,
return; return;
} }
if (quirkyIndex >= 0) {
quirky_init_function quirkyInit
= gQuirkyDevices[quirkyIndex].init_function;
if (quirkyInit != NULL) { if (quirkyInit != NULL) {
fStatus = quirkyInit(device, config, interfaceIndex); fStatus = quirkyInit(device, config, interfaceIndex);
if (fStatus != B_OK) if (fStatus != B_OK)
return; return;
} }
}
ProtocolHandler::AddHandlers(*this, fProtocolHandlerList, ProtocolHandler::AddHandlers(*this, fProtocolHandlerList,
fProtocolHandlerCount); fProtocolHandlerCount);

View File

@ -18,7 +18,7 @@ class HIDDevice {
public: public:
HIDDevice(usb_device device, HIDDevice(usb_device device,
const usb_configuration_info *config, const usb_configuration_info *config,
size_t interfaceIndex); size_t interfaceIndex, int32 quirkyIndex);
~HIDDevice(); ~HIDDevice();
void SetParentCookie(int32 cookie); void SetParentCookie(int32 cookie);