VOID
EnumerateHostController (
HTREEITEM hTreeParent,
HANDLE hHCDev,
__in PTSTR leafName
)
{
PTSTR driverKeyName;
PTSTR deviceDesc;
PTSTR deviceId;
HTREEITEM hHCItem;
PTSTR rootHubName;
PLIST_ENTRY listEntry;
PUSBHOSTCONTROLLERINFO hcInfo;
PUSBHOSTCONTROLLERINFO hcInfoInList;
// Allocate a structure to hold information about this host controller.
//
hcInfo = (PUSBHOSTCONTROLLERINFO)ALLOC(sizeof(USBHOSTCONTROLLERINFO));
if (hcInfo != NULL)
{
hcInfo->DeviceInfoType = HostControllerInfo;
// Obtain the driver key name for this host controller.
//
driverKeyName = GetHCDDriverKeyName(hHCDev);
if (driverKeyName)
{
// Don't enumerate this host controller again if it already
// on the list of enumerated host controllers.
//
listEntry = EnumeratedHCListHead.Flink;
while (listEntry != &EnumeratedHCListHead)
{
hcInfoInList = CONTAINING_RECORD(listEntry,
USBHOSTCONTROLLERINFO,
ListEntry);
if (_tcscmp(driverKeyName, hcInfoInList->DriverKey) == 0)
{
// Already on the list, exit
//
FREE(driverKeyName);
FREE(hcInfo);
return;
}
listEntry = listEntry->Flink;
}
// Obtain the device id string for this host controller.
// (Note: this a tmp global string buffer, make a copy of
// this string if it will used later.)
//
deviceId = DriverNameToDeviceDesc(driverKeyName, TRUE);
if (deviceId)
{
ULONG ven, dev, subsys, rev;
if (_stscanf_s(deviceId,
_T("PCI\\VEN_%x&DEV_%x&SUBSYS_%x&REV_%x"),
&ven, &dev, &subsys, &rev) != 4)
{
OOPS();
}
hcInfo->DriverKey = driverKeyName;
hcInfo->VendorID = ven;
hcInfo->DeviceID = dev;
hcInfo->SubSysID = subsys;
hcInfo->Revision = rev;
}
else
{
OOPS();
}
// Obtain the device description string for this host controller.
// (Note, this a tmp global string buffer, make a copy of
// this string if it will be used later.)
//
deviceDesc = DriverNameToDeviceDesc(driverKeyName, FALSE);
if (deviceDesc)
{
leafName = deviceDesc;
}
else
{
OOPS();
}
// Add this host controller to the USB device tree view.
//
hHCItem = AddLeaf(hTreeParent,
(LPARAM)hcInfo,
leafName,
GoodDeviceIcon);
if (hHCItem)
{
// Add this host controller to the list of enumerated
// host controllers.
//
InsertTailList(&EnumeratedHCListHead,
&hcInfo->ListEntry);
// Get the name of the root hub for this host
// controller and then enumerate the root hub.
//
rootHubName = GetRootHubName(hHCDev);
if (rootHubName != NULL)
{
if (EnumerateHub(hHCItem,
rootHubName,
NULL, // ConnectionInfo
NULL, // ConfigDesc
NULL, // StringDescs
_T("RootHub") // DeviceDesc
) == FALSE)
{
FREE(rootHubName);
}
}
else
{
// Failure obtaining root hub name.
OOPS();
}
}
else
{
// Failure adding host controller to USB device tree
// view.
OOPS();
FREE(driverKeyName);
FREE(hcInfo);
}
}
else
{
// Failure obtaining driver key name.
OOPS();
FREE(hcInfo);
}
}
}