#include "usb100.h";
#include "usbioctl.h";
#include "usbdi.h";
void CICcard::OnUpdateMachine()
{
PUSB_NODE_CONNECTION_INFORMATION connectionInfo;
HANDLE hHubDevice;
for (HCNum = 0; HCNum < NUM_HCS_TO_CHECK; HCNum++)
{
wsprintf(HCName, "\\\\.\\HCD%d", HCNum);
hHCDev = CreateFile(HCName, //打开USB控制器
GENERIC_WRITE,
FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
0,
NULL);
if(hHCDev=INVALID_HANDLE_VALUE) break;
PCHAR driverKeyName, deviceDesc;
driverKeyName = GetHCDDriverKeyName(hHCDev);
rootHubName =(char*) GetRootHubName(hHCDev);
if(rootHubName==NULL)
goto end;
PUSB_NODE_INFORMATION HubInfo;
HubInfo = (PUSB_NODE_INFORMATION)malloc(sizeof(USB_NODE_INFORMATION));
PCHAR deviceName;
deviceName = (PCHAR)malloc(strlen(rootHubName) + sizeof("\\\\.\\"));
if (rootHubName != NULL)
{
strcpy(deviceName, "\\\\.\\");
strcpy(deviceName + sizeof("\\\\.\\") - 1, rootHubName);
hHubDevice = CreateFile(deviceName, //打开Hub
GENERIC_WRITE,
FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
0,
NULL);
free(deviceName);
if(hHubDevice == INVALID_HANDLE_VALUE)
goto end;
success = DeviceIoControl(hHubDevice,
IOCTL_USB_GET_NODE_INFORMATION,
HubInfo,
sizeof(USB_NODE_INFORMATION),
HubInfo,
sizeof(USB_NODE_INFORMATION),
&nBytes,
NULL);
if (!success)
goto end;
}
int port;
port=HubInfo->u.HubInformation.HubDescriptor.bNumberOfPorts; //读端口数
for(index=1; index <= port; index++)
{
ULONG nBytes;
nBytes = sizeof(USB_NODE_CONNECTION_INFORMATION) +
sizeof(USB_PIPE_INFO)*30;
connectionInfo = (PUSB_NODE_CONNECTION_INFORMATION)malloc(nBytes);
if(connectionInfo == NULL)
goto end;
connectionInfo->ConnectionIndex = index;
success = DeviceIoControl(hHubDevice,
IOCTL_USB_GET_NODE_CONNECTION_INFORMATION,
connectionInfo,
nBytes,
connectionInfo,
nBytes,
&nBytes,
NULL);
if (!success)
{
free(connectionInfo);
goto end;
}
deviceDesc = NULL;
if(connectionInfo->ConnectionStatus != NoDeviceConnected)
{
driverKeyName = GetDriverKeyName(hHubDevice,
index);
if(driverKeyName)
//估计在这里开始加程序吧?
}
}
end:;
}
CloseHandle(hHubDevice);
CloseHandle(hHCDev);
} |