📄 usbd.cpp
字号:
//#ifdef DEBUG
WCHAR szGroup1[gcMaxDriverString], szGroup2[gcMaxDriverString];
//#endif
LPCUSB_DEVICE pInfo = pDev->pDeviceInfo;
fWork1 = TRUE;
while(fWork1)
{
HKEY hkGroup1;
if(fGroup1)
{
if(CurSettings.dwVendorId == USB_NO_INFO)
CurSettings.dwVendorId = pDriverSettings->dwVendorId;
else if(CurSettings.dwProductId == USB_NO_INFO)
CurSettings.dwProductId = pDriverSettings->dwProductId;
else if(CurSettings.dwReleaseNumber == USB_NO_INFO)
{
CurSettings.dwReleaseNumber =
pDriverSettings->dwReleaseNumber;
// we didn't find anything if we get to the while again
fWork1 = FALSE;
}
}
else
fWork1 = FALSE;
GetSettingString(szTemp, CurSettings.dwVendorId,
CurSettings.dwProductId, CurSettings.dwReleaseNumber);
#ifdef DEBUG
wcscpy(szGroup1, szTemp);
#endif
if(RegOpenKeyEx(hkBase, szTemp, 0, 0, &hkGroup1) == ERROR_SUCCESS)
{
fWork2 = TRUE;
while(fWork2)
{
HKEY hkGroup2;
if(fGroup2)
{
if(CurSettings.dwDeviceClass == USB_NO_INFO)
CurSettings.dwDeviceClass = pDriverSettings->dwDeviceClass;
else if(CurSettings.dwDeviceSubClass == USB_NO_INFO)
CurSettings.dwDeviceSubClass = pDriverSettings->dwDeviceSubClass;
else if(CurSettings.dwDeviceProtocol == USB_NO_INFO)
{
CurSettings.dwDeviceProtocol = pDriverSettings->dwDeviceProtocol;
// we didn't find anything if we get to the while again
fWork2 = FALSE;
}
}
else
fWork2 = FALSE;
GetSettingString(szTemp, CurSettings.dwDeviceClass,
CurSettings.dwDeviceSubClass,
CurSettings.dwDeviceProtocol);
#ifdef DEBUG
wcscpy(szGroup2, szTemp);
#endif
if(RegOpenKeyEx(hkGroup1, szTemp, 0, 0, &hkGroup2)
== ERROR_SUCCESS)
{
fWork3 = TRUE;
while(fWork3)
{
HKEY hkGroup3;
if(fGroup3)
{
if(CurSettings.dwInterfaceClass == USB_NO_INFO)
{
CurSettings.dwInterfaceClass =
pDriverSettings->dwInterfaceClass;
}
else if(CurSettings.dwInterfaceSubClass
== USB_NO_INFO)
{
CurSettings.dwInterfaceSubClass =
pDriverSettings->
dwInterfaceSubClass;
}
else if(CurSettings.dwInterfaceProtocol
== USB_NO_INFO)
{
CurSettings.dwInterfaceProtocol =
pDriverSettings->
dwInterfaceProtocol;
// we didn't find anything if we get to
// the while again
fWork3 = FALSE;
}
}
else
fWork3 = FALSE;
GetSettingString(szTemp, CurSettings.dwInterfaceClass,
CurSettings.dwInterfaceSubClass,
CurSettings.dwInterfaceProtocol);
if(RegOpenKeyEx(hkGroup2, szTemp, 0, 0, &hkGroup3)
== ERROR_SUCCESS)
{
DEBUGMSG(ZONE_LOADER,(TEXT("USBD:LoadGroupDriver(): found driver for LoadClients\\%s\\%s\\%s\r\n"),
szGroup1,szGroup2,szTemp));
fRet = LoadRegisteredDriver(hkGroup3, pDev,
lpInterface, pfLoaded, &CurSettings);
if(*pfLoaded || !fRet)
{
fWork3 = FALSE;
fWork2 = FALSE;
fWork1 = FALSE;
}
RegCloseKey(hkGroup3);
}
else
DEBUGMSG(ZONE_LOADER,(TEXT("1 USBD:LoadGroupDriver(): no key LoadClients\\%s\\%s\\%s\r\n"),
szGroup1,szGroup2,szTemp));
if (!fWork3)
{ // clear the current settings before exiting the loop
CurSettings.dwInterfaceClass = USB_NO_INFO;
CurSettings.dwInterfaceSubClass = USB_NO_INFO;
CurSettings.dwInterfaceProtocol = USB_NO_INFO;
}
}
RegCloseKey(hkGroup2);
}
else
DEBUGMSG(ZONE_LOADER,(TEXT("2 USBD:LoadGroupDriver(): no key LoadClients\\%s\\%s\r\n"),
szGroup1,szTemp));
if (!fWork2)
{ // clear the current settings before exiting the loop
CurSettings.dwDeviceClass = USB_NO_INFO;
CurSettings.dwDeviceSubClass = USB_NO_INFO;
CurSettings.dwDeviceProtocol = USB_NO_INFO;
}
}
RegCloseKey(hkGroup1);
}
else
DEBUGMSG(ZONE_LOADER,(TEXT("3 USBD:LoadGroupDriver(): no key LoadClients\\%s\r\n"),szTemp));
}
return fRet;
}
BOOL LoadUSBClient(SDevice * pDev, BOOL * pfLoaded,
LPCUSB_INTERFACE pInterface)
{
*pfLoaded = FALSE;
BOOL fRet = TRUE;
HKEY hkUsb;
HKEY hkLoadOrder;
USB_DRIVER_SETTINGS DriverSettings;
DriverSettings.dwCount = sizeof(DriverSettings);
DriverSettings.dwVendorId = pDev->pDeviceInfo->Descriptor.idVendor;
DriverSettings.dwProductId = pDev->pDeviceInfo->Descriptor.idProduct;
DriverSettings.dwReleaseNumber = pDev->pDeviceInfo->Descriptor.bcdDevice;
DEBUGMSG(ZONE_LOADER,(TEXT("USBD:LoadUSBClient: pInterface: 0x%X\r\n"),pInterface));
//Device specific
DriverSettings.dwDeviceClass = pDev->pDeviceInfo->Descriptor.bDeviceClass;
DriverSettings.dwDeviceSubClass =
pDev->pDeviceInfo->Descriptor.bDeviceSubClass;
DriverSettings.dwDeviceProtocol =
pDev->pDeviceInfo->Descriptor.bDeviceProtocol;
DriverSettings.dwInterfaceClass = USB_NO_INFO;
DriverSettings.dwInterfaceSubClass = USB_NO_INFO;
DriverSettings.dwInterfaceProtocol = USB_NO_INFO;
if(pInterface)
{
DriverSettings.dwInterfaceClass =
pInterface->Descriptor.bInterfaceClass;
DriverSettings.dwInterfaceSubClass =
pInterface->Descriptor.bInterfaceSubClass;
DriverSettings.dwInterfaceProtocol =
pInterface->Descriptor.bInterfaceProtocol;
DEBUGMSG(ZONE_LOADER,(TEXT("USBD:LoadUSBClient, IFClass: 0x%X, SubClass: 0x%X, Proto: 0x%X\r\n"),
DriverSettings.dwInterfaceClass,DriverSettings.dwInterfaceSubClass,
DriverSettings.dwInterfaceProtocol));
}
if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, gcszUsbRegKey, 0, 0, &hkUsb)
== ERROR_SUCCESS)
{
if(RegOpenKeyEx(hkUsb, gcszLoadClients, 0, 0, &hkLoadOrder)
== ERROR_SUCCESS)
{
if(pInterface == NULL)
{
if(!*pfLoaded)
{
LoadGroupDriver(hkLoadOrder, pDev, pfLoaded,
pInterface, &DriverSettings, FALSE, FALSE,
FALSE);
}
if(!*pfLoaded)
{
LoadGroupDriver(hkLoadOrder, pDev, pfLoaded,
pInterface, &DriverSettings, TRUE, FALSE,
FALSE);
}
if(!*pfLoaded)
{
LoadGroupDriver(hkLoadOrder, pDev, pfLoaded,
pInterface, &DriverSettings, TRUE, TRUE,
FALSE);
}
if(!*pfLoaded)
{
LoadGroupDriver(hkLoadOrder, pDev, pfLoaded,
pInterface, &DriverSettings, FALSE, TRUE,
FALSE);
}
}
else
{
if(!*pfLoaded)
{
LoadGroupDriver(hkLoadOrder, pDev, pfLoaded,
pInterface, &DriverSettings, TRUE, TRUE,
TRUE);
}
if(!*pfLoaded)
{
LoadGroupDriver(hkLoadOrder, pDev, pfLoaded,
pInterface, &DriverSettings, TRUE, FALSE,
TRUE);
}
if(!*pfLoaded)
{
LoadGroupDriver(hkLoadOrder, pDev, pfLoaded,
pInterface, &DriverSettings, FALSE, TRUE,
TRUE);
}
if(!*pfLoaded)
{
LoadGroupDriver(hkLoadOrder, pDev, pfLoaded,
pInterface, &DriverSettings, FALSE, FALSE,
TRUE);
}
}
RegCloseKey(hkLoadOrder);
}
else
DEBUGMSG(ZONE_ERROR,(TEXT("!USBD: Error opening %s key\r\n"),gcszLoadClients));
RegCloseKey(hkUsb);
}
else
DEBUGMSG(ZONE_ERROR,(TEXT("!USBD: Error opening %s key\r\n"),gcszUsbRegKey));
return fRet;
}
/*
Driver Loading Strategy
Client drivers are loaded based on registry keys off of Drivers/BuiltIn/USB/LoadClients.
The key is formatted as follows:
...LoadClients/<Group1 Id>/<Group2 Id>/<Group3 Id>/<Driver Name>
Where each of the group Id strings may be "Default", indicating it should be
checked for all devices, or may be of the form X, X_Y, or X_Y_Z, where the X, Y, and Z
depend on the group:
Group 1) X = Device Vendor ID
Y = Device Product ID
Z = Device Release #
Group 2) X = Device Class Code
Y = Device Sub Class Code
Z = Device Protocol Code
Group 3) X = Interface Class Code
Y = Interface Sub Class Code
Z = Interface Protocol Code
Algorithm:
Search for the default/default/default driver (this driver loaded for every device)
Search for the most general group 1 driver
Search for the most general group 1 + 2 driver
Search for the most general group 2 driver
For each interface now try:
Search for the most general group 1 + 2 + 3 driver
Search for the most general group 1 + 3 driver
Search for the most general group 2 + 3 driver
Search for the most general group 3 driver
Once the most general driver is found, the drivers attach process is called.
If the driver accepts control of the device, then no more drivers are loaded
automatically. It is the responsibility of the client driver to
load all other lower edge drivers, and all interface drivers.
*/
BOOL LoadDeviceDrivers(SDevice * pDev, BOOL * pfLoaded,PBYTE pbActivatedFlag)
{
*pfLoaded = FALSE;
BOOL fRet = TRUE;
DEBUGMSG(ZONE_LOADER,(TEXT("USBD:LoadDeviceDrivers - Device VendorId: %u, ProductId: %u, Release: %u\r\n"),
pDev->pDeviceInfo->Descriptor.idVendor, pDev->pDeviceInfo->Descriptor.idProduct,
pDev->pDeviceInfo->Descriptor.bcdDevice));
fRet = LoadUSBClient(pDev, pfLoaded, NULL);
if(!*pfLoaded)
{
LPCUSB_CONFIGURATION pConfig = pDev->pDeviceInfo->lpActiveConfig;
LPCUSB_INTERFACE pInterface = pConfig->lpInterfaces;
for(UINT iInterface = 0 ; iInterface < pConfig->Descriptor.bNumInterfaces &&
fRet && !*pfLoaded; ++iInterface, ++pInterface)
{
if (pbActivatedFlag==NULL || *(pbActivatedFlag + iInterface)==0) { // This interface has not been activated yet
BOOL bLoaded=FALSE;
DEBUGMSG(ZONE_LOADER,(TEXT("USBD:LoadDeviceDrivers loading driver for interface %u\r\n"),iInterface));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -