/*++
Copyright (c) 1997-1998 Microsoft Corporation
Module Name:
ENUM.C
Abstract:
This source file contains the routines which enumerate the USB bus
and populate the TreeView control.
The enumeration process goes like this:
(1) Enumerate Host Controllers and Root Hubs
Host controllers currently have symbolic link names of the form HCDx,
where x starts at 0. Use CreateFile() to open each host controller
symbolic link. Create a node in the TreeView to represent each host
controller.
After a host controller has been opened, send the host controller an
IOCTL_USB_GET_ROOT_HUB_NAME request to get the symbolic link name of
the root hub that is part of the host controller.
(2) Enumerate Hubs (Root Hubs and External Hubs)
Given the name of a hub, use CreateFile() to hub the hub. Send the
hub an IOCTL_USB_GET_NODE_INFORMATION request to get info about the
hub, such as the number of downstream ports. Create a node in the
TreeView to represent each hub.
(3) Enumerate Downstream Ports
Given an handle to an open hub and the number of downstream ports on
the hub, send the hub an IOCTL_USB_GET_NODE_CONNECTION_INFORMATION
request for each downstream port of the hub to get info about the
device (if any) attached to each port. If there is a device attached
to a port, send the hub an IOCTL_USB_GET_NODE_CONNECTION_NAME request
to get the symbolic link name of the hub attached to the downstream
port. If there is a hub attached to the downstream port, recurse to
step (2). Create a node in the TreeView to represent each hub port
and attached device.
Environment:
user mode
Revision History:
04-25-97 : created
--*/
//*****************************************************************************
// I N C L U D E S
//*****************************************************************************
#include <windows.h>
#include <basetyps.h>
#include <winioctl.h>
#include <string.h>
#include "usbview.h"
//*****************************************************************************
// D E F I N E S
//*****************************************************************************
#define NUM_HCS_TO_CHECK 10
//*****************************************************************************
// L O C A L F U N C T I O N P R O T O T Y P E S
//*****************************************************************************
VOID
EnumerateHub (
HTREEITEM hTreeParent,
PCHAR HubName,
PUSB_NODE_CONNECTION_INFORMATION ConnectionInfo,
PUSB_DESCRIPTOR_REQUEST ConfigDesc,
PSTRING_DESCRIPTOR_NODE StringDescs,
PCHAR DeviceDesc
);
VOID
EnumerateHubPorts (
HTREEITEM hTreeParent,
HANDLE hHubDevice,
ULONG NumPorts
);
PCHAR GetRootHubName (
HANDLE HostController
);
PCHAR GetExternalHubName (
HANDLE Hub,
ULONG ConnectionIndex
);
PCHAR GetHCDDriverKeyName (
HANDLE HCD
);
PCHAR GetDriverKeyName (
HANDLE Hub,
ULONG ConnectionIndex
);
PUSB_DESCRIPTOR_REQUEST
GetConfigDescriptor (
HANDLE hHubDevice,
ULONG ConnectionIndex,
UCHAR DescriptorIndex
);
BOOL
AreThereStringDescriptors (
PUSB_DEVICE_DESCRIPTOR DeviceDesc,
PUSB_CONFIGURATION_DESCRIPTOR ConfigDesc
);
PSTRING_DESCRIPTOR_NODE
GetAllStringDescriptors (
HANDLE hHubDevice,
ULONG ConnectionIndex,
PUSB_DEVICE_DESCRIPTOR DeviceDesc,
PUSB_CONFIGURATION_DESCRIPTOR ConfigDesc
);
PSTRING_DESCRIPTOR_NODE
GetStringDescriptor (
HANDLE hHubDevice,
ULONG ConnectionIndex,
UCHAR DescriptorIndex,
USHORT LanguageID
);
PSTRING_DESCRIPTOR_NODE
GetStringDescriptors (
HANDLE hHubDevice,
ULONG ConnectionIndex,
UCHAR DescriptorIndex,
ULONG NumLanguageIDs,
USHORT *LanguageIDs,
PSTRING_DESCRIPTOR_NODE StringDescNodeTail
);
//*****************************************************************************
// G L O B A L S P R I V A T E T O T H I S F I L E
//*****************************************************************************
PCHAR ConnectionStatuses[] =
{
"NoDeviceConnected",
"DeviceConnected",
"DeviceFailedEnumeration",
"DeviceGeneralFailure",
"DeviceCausedOvercurrent",
"DeviceNotEnoughPower"
};
ULONG TotalDevicesConnected;
//*****************************************************************************
//
// EnumerateHostControllers()
//
// hTreeParent - Handle of the TreeView item under which host controllers
// should be added.
//
//*****************************************************************************
VOID
EnumerateHostControllers (
HTREEITEM hTreeParent,
ULONG *DevicesConnected
)
{
char HCName[16];
int HCNum;
HANDLE hHCDev;
HTREEITEM hHCItem;
PCHAR rootHubName;
PCHAR leafName;
TotalDevicesConnected = 0;
TotalHubs = 0;
// Iterate over some Host Controller names and try to open them.
//
for (HCNum = 0; HCNum < NUM_HCS_TO_CHECK; HCNum++)
{
wsprintf(HCName, "\\\\.\\HCD%d", HCNum);
hHCDev = CreateFile(HCName,
GENERIC_WRITE,
FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
0,
NULL);
// If the handle is valid, then we've successfully opened a Host
// Controller. Display some info about the Host Controller itself,
// then enumerate the Root Hub attached to the Host Controller.
//
if (hHCDev != INVALID_HANDLE_VALUE)
{
PCHAR driverKeyName, deviceDesc;
driverKeyName = GetHCDDriverKeyName(hHCDev);
leafName = HCName + sizeof("\\\\.\\") - sizeof("");
if (driverKeyName)
{
deviceDesc = DriverNameToDeviceDesc(driverKeyName);
if (deviceDesc)
{
leafName = deviceDesc;
}
FREE(driverKeyName);
}
hHCItem = AddLeaf(hTreeParent,
0,
leafName
);
if (hHCItem)
{
rootHubName = GetRootHubName(hHCDev);
if (rootHubName != NULL)
{
EnumerateHub(hHCItem,
rootHubName,
NULL, // ConnectionInfo
NULL, // ConfigDesc
NULL, // StringDescs
"RootHub" // DeviceDesc
);
}
}
CloseHandle(hHCDev);
}
}
*DevicesConnected = TotalDevicesConnected;
}
//*****************************************************************************
//
// EnumerateHub()
//
// hTreeParent - Handle of the TreeView item under which this hub should be
// added.
//
// HubName - Name of this hub. This pointer is kept so the caller can neither
// free nor reuse this memory.
//
// ConnectionInfo - NULL if this is a root hub, else this is the connection
// info for an external hub. This pointer is kept so the caller can neither
// free nor reuse this memory.
//
// ConfigDesc - NULL if this is a root hub, else this is the Configuration
// Descriptor for an external hub. This pointer is kept so th
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
usbview.rar (33个子文件)
USBView
USBView.ncb 105KB
bang.ico 2KB
usb100.h 7KB
enum.c 50KB
monitor.ico 10KB
devioctl.h 4KB
USBView.plg 2KB
cfgmgr32.h 83KB
usbview.rc 3KB
hub.ico 766B
cfgmgr32.lib 52KB
dispaud.c 33KB
usbview.h 6KB
usbview.htm 7KB
port.ico 766B
devnode.c 4KB
COMCTL32.LIB 71KB
display.c 32KB
resource.h 978B
usbioctl.h 19KB
usb.ico 766B
USBView.dsp 4KB
debug.c 4KB
split.cur 326B
vndrlist.h 21KB
usbdesc.h 9KB
cfg.h 5KB
Debug
USBView.exe 228KB
USBView.opt 58KB
usbview.c 25KB
sources 526B
winuser.h 238KB
USBView.dsw 537B
共 33 条
- 1
leajian
- 粉丝: 11
- 资源: 80
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页