home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2004 February
/
Chip_2004-02_cd1.bin
/
zkuste
/
konfig
/
download
/
msic
/
Help
/
Int
/
MiTeC_USB.int
< prev
next >
Wrap
Text File
|
2003-08-26
|
10KB
|
272 lines
{*******************************************************}
{ }
{ MiTeC System Information Component }
{ USB Interface }
{ version 8.3 for Delphi 5,6,7 }
{ }
{ Copyright ⌐ 1997,2003 Michal Mutl }
{ }
{*******************************************************}
{$INCLUDE MITEC_DEF.INC}
unit MiTeC_USB;
interface
uses SysUtils, Windows, MiTeC_WinIOCTL;
const
FILE_DEVICE_USB = FILE_DEVICE_UNKNOWN;
USB_IOCTL_INTERNAL_INDEX = $0000;
USB_IOCTL_INDEX = $00ff;
IOCTL_USB_GET_NODE_INFORMATION = ((FILE_DEVICE_USB shl 16) or
((USB_IOCTL_INDEX+3) shl 2) or
METHOD_BUFFERED or
(FILE_ANY_ACCESS shl 14));
IOCTL_USB_GET_NODE_CONNECTION_INFORMATION = ((FILE_DEVICE_USB shl 16) or
((USB_IOCTL_INDEX+4) shl 2) or
METHOD_BUFFERED or
(FILE_ANY_ACCESS shl 14));
IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION = ((FILE_DEVICE_USB shl 16) or
((USB_IOCTL_INDEX+5) shl 2) or
METHOD_BUFFERED or
(FILE_ANY_ACCESS shl 14));
IOCTL_USB_GET_NODE_CONNECTION_NAME = ((FILE_DEVICE_USB shl 16) or
((USB_IOCTL_INDEX+6) shl 2) or
METHOD_BUFFERED or
(FILE_ANY_ACCESS shl 14));
IOCTL_USB_DIAG_IGNORE_HUBS_ON = ((FILE_DEVICE_USB shl 16) or
((USB_IOCTL_INDEX+7) shl 2) or
METHOD_BUFFERED or
(FILE_ANY_ACCESS shl 14));
IOCTL_USB_DIAG_IGNORE_HUBS_OFF = ((FILE_DEVICE_USB shl 16) or
((USB_IOCTL_INDEX+8) shl 2) or
METHOD_BUFFERED or
(FILE_ANY_ACCESS shl 14));
IOCTL_USB_GET_NODE_CONNECTION_DRIVERKEY_NAME = ((FILE_DEVICE_USB shl 16) or
((USB_IOCTL_INDEX+9) shl 2) or
METHOD_BUFFERED or
(FILE_ANY_ACCESS shl 14));
IOCTL_USB_HCD_GET_STATS_1 = ((FILE_DEVICE_USB shl 16) or
((USB_IOCTL_INDEX) shl 2) or
METHOD_BUFFERED or
(FILE_ANY_ACCESS shl 14));
IOCTL_USB_HCD_GET_STATS_2 = ((FILE_DEVICE_USB shl 16) or
((USB_IOCTL_INDEX+11) shl 2) or
METHOD_BUFFERED or
(FILE_ANY_ACCESS shl 14));
IOCTL_USB_DIAGNOSTIC_MODE_ON = ((FILE_DEVICE_USB shl 16) or
((USB_IOCTL_INDEX+1) shl 2) or
METHOD_BUFFERED or
(FILE_ANY_ACCESS shl 14));
IOCTL_USB_DIAGNOSTIC_MODE_OFF = ((FILE_DEVICE_USB shl 16) or
((USB_IOCTL_INDEX+2) shl 2) or
METHOD_BUFFERED or
(FILE_ANY_ACCESS shl 14));
IOCTL_USB_GET_ROOT_HUB_NAME = ((FILE_DEVICE_USB shl 16) or
((USB_IOCTL_INDEX+3) shl 2) or
METHOD_BUFFERED or
(FILE_ANY_ACCESS shl 14));
IOCTL_GET_HCD_DRIVERKEY_NAME = ((FILE_DEVICE_USB shl 16) or
((USB_IOCTL_INDEX+10) shl 2) or
METHOD_BUFFERED or
(FILE_ANY_ACCESS shl 14));
USB_DEVICE_DESCRIPTOR_TYPE = $01;
USB_CONFIGURATION_DESCRIPTOR_TYPE = $02;
USB_STRING_DESCRIPTOR_TYPE = $03;
USB_INTERFACE_DESCRIPTOR_TYPE = $04;
USB_ENDPOINT_DESCRIPTOR_TYPE = $05;
USB_REQUEST_GET_STATUS = $00;
USB_REQUEST_CLEAR_FEATURE = $01;
USB_REQUEST_SET_FEATURE = $03;
USB_REQUEST_SET_ADDRESS = $05;
USB_REQUEST_GET_DESCRIPTOR = $06;
USB_REQUEST_SET_DESCRIPTOR = $07;
USB_REQUEST_GET_CONFIGURATION = $08;
USB_REQUEST_SET_CONFIGURATION = $09;
USB_REQUEST_GET_INTERFACE = $0A;
USB_REQUEST_SET_INTERFACE = $0B;
USB_REQUEST_SYNC_FRAME = $0C;
type
TUSBHubNode = (usbhnHub,usbhnMIParent);
TUnicodeName = record
Length: DWORD;
UnicodeName: array[0..255] of Byte;
end;
TNodeType = record
ConnectionIndex: DWORD;
Length: DWORD;
UnicodeName: array[0..255] of byte
end;
TSetupPacket = record
bmRequest: Byte;
bRequest: Byte;
wValue: array[0..1] of Byte;
wIndex: array[0..1] of Byte;
wLength: array[0..1] of Byte;
end;
TDescriptorRequest = record
ConnectionIndex: DWORD;
SetupPacket: TSetupPacket;
ConfigurationDescriptor: array[0..2047] of Byte;
end;
TDeviceDescriptor = record
Length: Byte;
DescriptorType: Byte;
USBSpec: array[0..1] of Byte;
DeviceClass: Byte;
DeviceSubClass: Byte;
DeviceProtocol: Byte;
MaxPacketSize0: Byte;
VendorID: array[0..1] of Byte;
ProductID: array[0..1] of Byte;
DeviceRevision: array[0..1] of byte;
ManufacturerStringIndex: byte;
ProductStringIndex: Byte;
SerialNumberStringIndex: Byte;
ConfigurationCount: Byte;
end;
THubDescriptor = record
Length: Byte;
HubType: Byte;
PortCount: Byte;
Characteristics: array[0..1] of Byte;
PowerOnToPowerGood: Byte;
HubControlCurrent: Byte;
RemoveAndPowerMask: array[0..63] of Byte;
end;
TEndPointDescriptor = record
Length: Byte;
DescriptorType: Byte;
EndpointAddress: Byte;
Attributes: Byte;
MaxPacketSize: WORD;
PollingInterval: Byte;
end;
TNodeInformation = record
NodeType: DWORD;
NodeDescriptor: THubDescriptor;
HubIsBusPowered: Byte;
end;
TUSBPipeInfo = record
EndPointDescriptor: TEndpointDescriptor;
ScheduleOffset: DWORD;
end;
TNodeConnectionInformation = record
ConnectionIndex: DWORD;
ThisDevice: TDeviceDescriptor;
CurrentConfiguration: Byte;
LowSpeed: Byte;
DeviceIsHub: Byte;
DeviceAddress: array[0..1] of Byte;
NumberOfOpenEndPoints: array[0..3] of Byte;
ThisConnectionStatus: array[0..3] of Byte;
PipeList: array[0..31] of TUSBPipeInfo;
end;
TCollectedDeviceData = record
DeviceType: DWORD;
DeviceHandle: DWORD;
ConnectionData: TNodeConnectionInformation;
NodeData: TNodeInformation;
end;
TUSBClass = (usbReserved, usbAudio, usbCommunications, usbHID, usbMonitor,
usbPhysicalIntf, usbPower, usbPrinter, usbStorage, usbHub, usbVendorSpec,
// illegal values
usbExternalHub, usbHostController, usbUnknown, usbError);
TUSBDevice = record
Port: DWORD;
DeviceAddress: DWORD;
Manufacturer,
Product,
Serial: shortstring;
ConnectionStatus: Byte;
MaxPower: WORD;
MajorVersion,
MinorVersion: Byte;
end;
TUSBNode = record
ConnectionName: shortstring;
Keyname: ShortString;
USBClass: TUSBClass;
ParentIndex: Integer;
Level: Integer;
USBDevice: TUSBDevice;
end;
TUSBNodes = array of TUSBNode;
const
ClassNames: array[0..14] of string = (
'Reserved',
'Audio',
'Communications',
'Human interface',
'Monitor',
'Physical interface',
'Power',
'Printer',
'Storage',
'Root Hub',
'Vendor Specific',
'External Hub',
'Host Controller',
'<error>',
'<unknown>'
);
ConnectionStates: array[0..5] of string = (
'No device connected',
'Device connected',
'Device FAILED enumeration',
'Device general FAILURE',
'Device caused overcurrent',
'Not enough power for device');
function GetDeviceName1(hDevice: THandle; IOCTL_Code: DWORD): string;
function GetDeviceName2(hDevice: THandle; PortIndex: DWORD; IOCTL_Code: DWORD): string;
function GetNodeInformation(hDevice: THandle; var Information: TNodeInformation): Integer;
function GetNodeConnection(hDevice: THandle; PortIndex: DWORD; var Connection: TNodeConnectionInformation): Integer;
function GetStringDescriptor(HubHandle: THandle; PortIndex: DWORD; var LanguageID: Word; Index: Byte; var Str: shortstring): integer;
function GetConfigurationDescriptor(HubHandle: THandle; PortIndex: DWORD; var MaxPower: WORD; var ClassID: integer): Integer;
function GetPortData(hRootHub: THandle; SA: TSecurityAttributes; PortCount: Byte; ParentIndex: integer; Level: Integer; var USBNodes: TUSBNodes): Integer;
procedure EnumUSBDevices(var USBNodes: TUSBNodes);
implementation