2006-03-10 23:32:46 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: ReactOS Universal Serial Bus Driver/Helper Library
|
|
|
|
* LICENSE: GPL - See COPYING in the top level directory
|
|
|
|
* FILE: drivers/usb/usbd/usbd.c
|
|
|
|
* PURPOSE: Helper Library for USB
|
|
|
|
* PROGRAMMERS:
|
|
|
|
* Filip Navara <xnavara@volny.cz>
|
2010-09-19 00:30:49 +00:00
|
|
|
* Michael Martin <michael.martin@reactos.org>
|
2006-03-10 23:32:46 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2005-07-31 12:11:56 +00:00
|
|
|
/*
|
|
|
|
* Universal Serial Bus Driver/Helper Library
|
|
|
|
*
|
|
|
|
* Written by Filip Navara <xnavara@volny.cz>
|
|
|
|
*
|
|
|
|
* Notes:
|
|
|
|
* This driver was obsoleted in Windows XP and most functions
|
|
|
|
* became pure stubs. But some of them were retained for backward
|
|
|
|
* compatibilty with existing drivers.
|
|
|
|
*
|
|
|
|
* Preserved functions:
|
|
|
|
*
|
|
|
|
* USBD_Debug_GetHeap (implemented)
|
|
|
|
* USBD_Debug_RetHeap (implemented)
|
|
|
|
* USBD_CalculateUsbBandwidth (implemented, tested)
|
|
|
|
* USBD_CreateConfigurationRequestEx (implemented)
|
|
|
|
* USBD_CreateConfigurationRequest
|
|
|
|
* USBD_GetInterfaceLength (implemented)
|
2005-11-26 04:07:39 +00:00
|
|
|
* USBD_ParseConfigurationDescriptorEx (implemented)
|
|
|
|
* USBD_ParseDescriptors (implemented)
|
2005-07-31 12:11:56 +00:00
|
|
|
* USBD_GetPdoRegistryParameters (implemented)
|
|
|
|
*/
|
|
|
|
|
2005-12-01 21:37:19 +00:00
|
|
|
#include <ntddk.h>
|
|
|
|
#include <usbdi.h>
|
2010-09-19 00:30:49 +00:00
|
|
|
#include <debug.h>
|
2005-07-31 12:11:56 +00:00
|
|
|
#ifndef PLUGPLAY_REGKEY_DRIVER
|
|
|
|
#define PLUGPLAY_REGKEY_DRIVER 2
|
|
|
|
#endif
|
|
|
|
typedef struct _USBD_INTERFACE_LIST_ENTRY {
|
|
|
|
PUSB_INTERFACE_DESCRIPTOR InterfaceDescriptor;
|
|
|
|
PUSBD_INTERFACE_INFORMATION Interface;
|
|
|
|
} USBD_INTERFACE_LIST_ENTRY, *PUSBD_INTERFACE_LIST_ENTRY;
|
|
|
|
|
2008-11-30 11:16:55 +00:00
|
|
|
NTSTATUS NTAPI
|
2005-07-31 12:11:56 +00:00
|
|
|
DriverEntry(PDRIVER_OBJECT DriverObject,
|
|
|
|
PUNICODE_STRING RegistryPath)
|
|
|
|
{
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2010-06-12 12:20:41 +00:00
|
|
|
ULONG NTAPI
|
|
|
|
DllInitialize(ULONG Unknown)
|
2005-07-31 12:11:56 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2010-06-12 12:20:41 +00:00
|
|
|
ULONG NTAPI
|
2005-07-31 12:11:56 +00:00
|
|
|
DllUnload(VOID)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2008-11-30 11:16:55 +00:00
|
|
|
PVOID NTAPI
|
2010-06-12 12:20:41 +00:00
|
|
|
USBD_Debug_GetHeap(ULONG Unknown1, POOL_TYPE PoolType, ULONG NumberOfBytes,
|
2010-09-19 00:30:49 +00:00
|
|
|
ULONG Tag)
|
2005-07-31 12:11:56 +00:00
|
|
|
{
|
|
|
|
return ExAllocatePoolWithTag(PoolType, NumberOfBytes, Tag);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2008-11-30 11:16:55 +00:00
|
|
|
VOID NTAPI
|
2010-06-12 12:20:41 +00:00
|
|
|
USBD_Debug_RetHeap(PVOID Heap, ULONG Unknown2, ULONG Unknown3)
|
2005-07-31 12:11:56 +00:00
|
|
|
{
|
|
|
|
ExFreePool(Heap);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2008-11-30 11:16:55 +00:00
|
|
|
VOID NTAPI
|
2005-07-31 12:11:56 +00:00
|
|
|
USBD_Debug_LogEntry(PCHAR Name, ULONG_PTR Info1, ULONG_PTR Info2,
|
|
|
|
ULONG_PTR Info3)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2008-11-30 11:16:55 +00:00
|
|
|
PVOID NTAPI
|
2010-06-12 12:20:41 +00:00
|
|
|
USBD_AllocateDeviceName(ULONG Unknown)
|
2005-07-31 12:11:56 +00:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2010-06-12 12:20:41 +00:00
|
|
|
ULONG NTAPI
|
2005-07-31 12:11:56 +00:00
|
|
|
USBD_CalculateUsbBandwidth(
|
|
|
|
ULONG MaxPacketSize,
|
|
|
|
UCHAR EndpointType,
|
|
|
|
BOOLEAN LowSpeed
|
|
|
|
)
|
|
|
|
{
|
2010-06-12 12:20:41 +00:00
|
|
|
ULONG OverheadTable[] = {
|
2005-07-31 12:11:56 +00:00
|
|
|
0x00, /* UsbdPipeTypeControl */
|
|
|
|
0x09, /* UsbdPipeTypeIsochronous */
|
|
|
|
0x00, /* UsbdPipeTypeBulk */
|
|
|
|
0x0d /* UsbdPipeTypeInterrupt */
|
|
|
|
};
|
2010-06-12 12:20:41 +00:00
|
|
|
ULONG Result;
|
2007-10-19 23:21:45 +00:00
|
|
|
|
2005-07-31 12:11:56 +00:00
|
|
|
if (OverheadTable[EndpointType] != 0)
|
|
|
|
{
|
|
|
|
Result = ((MaxPacketSize + OverheadTable[EndpointType]) * 8 * 7) / 6;
|
|
|
|
if (LowSpeed)
|
|
|
|
return Result << 3;
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2010-06-12 12:20:41 +00:00
|
|
|
ULONG NTAPI
|
|
|
|
USBD_Dispatch(ULONG Unknown1, ULONG Unknown2, ULONG Unknown3, ULONG Unknown4)
|
2005-07-31 12:11:56 +00:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2008-11-30 11:16:55 +00:00
|
|
|
VOID NTAPI
|
2005-07-31 12:11:56 +00:00
|
|
|
USBD_FreeDeviceMutex(PVOID Unknown)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2008-11-30 11:16:55 +00:00
|
|
|
VOID NTAPI
|
2005-07-31 12:11:56 +00:00
|
|
|
USBD_FreeDeviceName(PVOID Unknown)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2008-11-30 11:16:55 +00:00
|
|
|
VOID NTAPI
|
2005-07-31 12:11:56 +00:00
|
|
|
USBD_WaitDeviceMutex(PVOID Unknown)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2010-06-12 12:20:41 +00:00
|
|
|
ULONG NTAPI
|
|
|
|
USBD_GetSuspendPowerState(ULONG Unknown1)
|
2005-07-31 12:11:56 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2008-11-30 11:16:55 +00:00
|
|
|
NTSTATUS NTAPI
|
2010-06-12 12:20:41 +00:00
|
|
|
USBD_InitializeDevice(ULONG Unknown1, ULONG Unknown2, ULONG Unknown3,
|
|
|
|
ULONG Unknown4, ULONG Unknown5, ULONG Unknown6)
|
2005-07-31 12:11:56 +00:00
|
|
|
{
|
|
|
|
return STATUS_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2008-11-30 11:16:55 +00:00
|
|
|
NTSTATUS NTAPI
|
2010-06-12 12:20:41 +00:00
|
|
|
USBD_RegisterHostController(ULONG Unknown1, ULONG Unknown2, ULONG Unknown3,
|
|
|
|
ULONG Unknown4, ULONG Unknown5, ULONG Unknown6, ULONG Unknown7,
|
|
|
|
ULONG Unknown8, ULONG Unknown9, ULONG Unknown10)
|
2005-07-31 12:11:56 +00:00
|
|
|
{
|
|
|
|
return STATUS_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2008-11-30 11:16:55 +00:00
|
|
|
NTSTATUS NTAPI
|
2010-06-12 12:20:41 +00:00
|
|
|
USBD_GetDeviceInformation(ULONG Unknown1, ULONG Unknown2, ULONG Unknown3)
|
2005-07-31 12:11:56 +00:00
|
|
|
{
|
|
|
|
return STATUS_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2008-11-30 11:16:55 +00:00
|
|
|
NTSTATUS NTAPI
|
2010-06-12 12:20:41 +00:00
|
|
|
USBD_CreateDevice(ULONG Unknown1, ULONG Unknown2, ULONG Unknown3,
|
|
|
|
ULONG Unknown4, ULONG Unknown5)
|
2005-07-31 12:11:56 +00:00
|
|
|
{
|
|
|
|
return STATUS_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2008-11-30 11:16:55 +00:00
|
|
|
NTSTATUS NTAPI
|
2010-06-12 12:20:41 +00:00
|
|
|
USBD_RemoveDevice(ULONG Unknown1, ULONG Unknown2, ULONG Unknown3)
|
2005-07-31 12:11:56 +00:00
|
|
|
{
|
|
|
|
return STATUS_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2008-11-30 11:16:55 +00:00
|
|
|
VOID NTAPI
|
2010-06-12 12:20:41 +00:00
|
|
|
USBD_CompleteRequest(ULONG Unknown1, ULONG Unknown2)
|
2005-07-31 12:11:56 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2008-11-30 11:16:55 +00:00
|
|
|
VOID NTAPI
|
2005-07-31 12:11:56 +00:00
|
|
|
USBD_RegisterHcFilter(
|
2007-10-19 23:21:45 +00:00
|
|
|
PDEVICE_OBJECT DeviceObject,
|
2005-07-31 12:11:56 +00:00
|
|
|
PDEVICE_OBJECT FilterDeviceObject
|
|
|
|
)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2008-11-30 11:16:55 +00:00
|
|
|
VOID NTAPI
|
2010-06-12 12:20:41 +00:00
|
|
|
USBD_SetSuspendPowerState(ULONG Unknown1, ULONG Unknown2)
|
2005-07-31 12:11:56 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2008-11-30 11:16:55 +00:00
|
|
|
NTSTATUS NTAPI
|
2010-06-12 12:20:41 +00:00
|
|
|
USBD_MakePdoName(ULONG Unknown1, ULONG Unknown2)
|
2005-07-31 12:11:56 +00:00
|
|
|
{
|
|
|
|
return STATUS_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2008-11-30 11:16:55 +00:00
|
|
|
NTSTATUS NTAPI
|
2005-07-31 12:11:56 +00:00
|
|
|
USBD_QueryBusTime(
|
|
|
|
PDEVICE_OBJECT RootHubPdo,
|
|
|
|
PULONG CurrentFrame
|
|
|
|
)
|
|
|
|
{
|
|
|
|
return STATUS_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2008-11-30 11:16:55 +00:00
|
|
|
VOID NTAPI
|
2005-07-31 12:11:56 +00:00
|
|
|
USBD_GetUSBDIVersion(
|
|
|
|
PUSBD_VERSION_INFORMATION Version
|
|
|
|
)
|
|
|
|
{
|
|
|
|
if (Version != NULL)
|
|
|
|
{
|
|
|
|
Version->USBDI_Version = USBDI_VERSION;
|
|
|
|
Version->Supported_USB_Version = 0x100;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2008-11-30 11:16:55 +00:00
|
|
|
NTSTATUS NTAPI
|
2010-06-12 12:20:41 +00:00
|
|
|
USBD_RestoreDevice(ULONG Unknown1, ULONG Unknown2, ULONG Unknown3)
|
2005-07-31 12:11:56 +00:00
|
|
|
{
|
|
|
|
return STATUS_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2008-11-30 11:16:55 +00:00
|
|
|
VOID NTAPI
|
2010-06-12 12:20:41 +00:00
|
|
|
USBD_RegisterHcDeviceCapabilities(ULONG Unknown1, ULONG Unknown2,
|
|
|
|
ULONG Unknown3)
|
2005-07-31 12:11:56 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2010-09-19 00:30:49 +00:00
|
|
|
PURB NTAPI
|
2005-07-31 12:11:56 +00:00
|
|
|
USBD_CreateConfigurationRequestEx(
|
|
|
|
PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor,
|
|
|
|
PUSBD_INTERFACE_LIST_ENTRY InterfaceList
|
|
|
|
)
|
|
|
|
{
|
|
|
|
PURB Urb;
|
2010-09-19 00:30:49 +00:00
|
|
|
ULONG UrbSize = 0;
|
2010-06-12 12:20:41 +00:00
|
|
|
ULONG InterfaceCount;
|
2010-09-19 00:30:49 +00:00
|
|
|
ULONG InterfaceNumber, EndPointNumber;
|
|
|
|
PUSBD_INTERFACE_INFORMATION InterfaceInfo;
|
2005-07-31 12:11:56 +00:00
|
|
|
|
|
|
|
for (InterfaceCount = 0;
|
|
|
|
InterfaceList[InterfaceCount].InterfaceDescriptor != NULL;
|
2010-09-19 00:30:49 +00:00
|
|
|
InterfaceCount++)
|
|
|
|
{
|
|
|
|
UrbSize += sizeof(USBD_INTERFACE_INFORMATION);
|
|
|
|
UrbSize += (InterfaceList[InterfaceCount].InterfaceDescriptor->bNumEndpoints - 1) * sizeof(USBD_PIPE_INFORMATION);
|
|
|
|
}
|
|
|
|
|
|
|
|
UrbSize += sizeof(URB) + sizeof(USBD_INTERFACE_INFORMATION);
|
2005-07-31 12:11:56 +00:00
|
|
|
|
|
|
|
Urb = ExAllocatePool(NonPagedPool, UrbSize);
|
2010-09-19 00:30:49 +00:00
|
|
|
RtlZeroMemory(Urb, UrbSize);
|
|
|
|
Urb->UrbSelectConfiguration.Hdr.Function = URB_FUNCTION_SELECT_CONFIGURATION;
|
|
|
|
Urb->UrbSelectConfiguration.Hdr.Length = sizeof(Urb->UrbSelectConfiguration);
|
|
|
|
Urb->UrbSelectConfiguration.ConfigurationDescriptor = ConfigurationDescriptor;
|
|
|
|
|
|
|
|
InterfaceInfo = &Urb->UrbSelectConfiguration.Interface;
|
|
|
|
for (InterfaceNumber = 0; InterfaceNumber < InterfaceCount; InterfaceNumber++)
|
|
|
|
{
|
|
|
|
InterfaceList[InterfaceNumber].Interface = InterfaceInfo;
|
|
|
|
InterfaceInfo->Length = sizeof(USBD_INTERFACE_INFORMATION) +
|
|
|
|
((InterfaceList[InterfaceNumber].InterfaceDescriptor->bNumEndpoints - 1) * sizeof(USBD_PIPE_INFORMATION));
|
|
|
|
InterfaceInfo->InterfaceNumber = InterfaceList[InterfaceNumber].InterfaceDescriptor->bInterfaceNumber;
|
|
|
|
InterfaceInfo->AlternateSetting = InterfaceList[InterfaceNumber].InterfaceDescriptor->bAlternateSetting;
|
|
|
|
InterfaceInfo->NumberOfPipes = InterfaceList[InterfaceNumber].InterfaceDescriptor->bNumEndpoints;
|
|
|
|
for (EndPointNumber = 0; EndPointNumber < InterfaceInfo->NumberOfPipes; EndPointNumber++)
|
|
|
|
{
|
|
|
|
InterfaceInfo->Pipes[EndPointNumber].MaximumTransferSize = PAGE_SIZE;
|
|
|
|
}
|
|
|
|
InterfaceInfo = (PUSBD_INTERFACE_INFORMATION) ((ULONG_PTR)InterfaceInfo + InterfaceInfo->Length);
|
|
|
|
}
|
2005-07-31 12:11:56 +00:00
|
|
|
|
|
|
|
return Urb;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2010-09-19 00:30:49 +00:00
|
|
|
* @implemented
|
2005-07-31 12:11:56 +00:00
|
|
|
*/
|
2008-11-30 11:16:55 +00:00
|
|
|
PURB NTAPI
|
2005-07-31 12:11:56 +00:00
|
|
|
USBD_CreateConfigurationRequest(
|
|
|
|
PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor,
|
|
|
|
PUSHORT Size
|
|
|
|
)
|
|
|
|
{
|
2010-09-19 00:30:49 +00:00
|
|
|
/* WindowsXP returns NULL */
|
2005-07-31 12:11:56 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2010-09-19 00:30:49 +00:00
|
|
|
* @implemented
|
2005-07-31 12:11:56 +00:00
|
|
|
*/
|
2008-11-30 11:16:55 +00:00
|
|
|
ULONG NTAPI
|
2005-07-31 12:11:56 +00:00
|
|
|
USBD_GetInterfaceLength(
|
|
|
|
PUSB_INTERFACE_DESCRIPTOR InterfaceDescriptor,
|
|
|
|
PUCHAR BufferEnd
|
|
|
|
)
|
|
|
|
{
|
|
|
|
ULONG_PTR Current;
|
|
|
|
PUSB_INTERFACE_DESCRIPTOR CurrentDescriptor = InterfaceDescriptor;
|
2010-09-19 00:30:49 +00:00
|
|
|
ULONG Length = 0;
|
|
|
|
BOOLEAN InterfaceFound = FALSE;
|
2005-07-31 12:11:56 +00:00
|
|
|
|
2010-09-19 00:30:49 +00:00
|
|
|
for (Current = (ULONG_PTR)CurrentDescriptor;
|
|
|
|
Current < (ULONG_PTR)BufferEnd;
|
|
|
|
Current += CurrentDescriptor->bLength)
|
2005-07-31 12:11:56 +00:00
|
|
|
{
|
2010-09-19 00:30:49 +00:00
|
|
|
CurrentDescriptor = (PUSB_INTERFACE_DESCRIPTOR)Current;
|
2005-07-31 12:11:56 +00:00
|
|
|
|
2010-09-19 00:30:49 +00:00
|
|
|
if ((CurrentDescriptor->bDescriptorType == USB_INTERFACE_DESCRIPTOR_TYPE) && (InterfaceFound))
|
|
|
|
break;
|
|
|
|
else if (CurrentDescriptor->bDescriptorType == USB_INTERFACE_DESCRIPTOR_TYPE)
|
|
|
|
InterfaceFound = TRUE;
|
|
|
|
|
|
|
|
Length += CurrentDescriptor->bLength;
|
2005-07-31 12:11:56 +00:00
|
|
|
}
|
2010-09-19 00:30:49 +00:00
|
|
|
|
2005-07-31 12:11:56 +00:00
|
|
|
return Length;
|
|
|
|
}
|
|
|
|
|
2005-08-14 13:18:50 +00:00
|
|
|
/*
|
2005-11-26 04:07:39 +00:00
|
|
|
* @implemented
|
2005-08-14 13:18:50 +00:00
|
|
|
*/
|
2008-11-30 11:16:55 +00:00
|
|
|
PUSB_COMMON_DESCRIPTOR NTAPI
|
2005-08-14 13:18:50 +00:00
|
|
|
USBD_ParseDescriptors(
|
|
|
|
PVOID DescriptorBuffer,
|
|
|
|
ULONG TotalLength,
|
|
|
|
PVOID StartPosition,
|
|
|
|
LONG DescriptorType
|
|
|
|
)
|
|
|
|
{
|
|
|
|
PUSB_COMMON_DESCRIPTOR PComDes = StartPosition;
|
|
|
|
|
|
|
|
while(PComDes)
|
|
|
|
{
|
|
|
|
if (PComDes >= (PUSB_COMMON_DESCRIPTOR)
|
|
|
|
((PLONG)DescriptorBuffer + TotalLength) ) break;
|
|
|
|
if (PComDes->bDescriptorType == DescriptorType) return PComDes;
|
|
|
|
if (PComDes->bLength == 0) break;
|
2010-09-19 00:30:49 +00:00
|
|
|
PComDes = (PUSB_COMMON_DESCRIPTOR)((ULONG_PTR)PComDes + PComDes->bLength);
|
2005-08-14 13:18:50 +00:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-07-31 12:11:56 +00:00
|
|
|
/*
|
2005-11-26 04:07:39 +00:00
|
|
|
* @implemented
|
2005-07-31 12:11:56 +00:00
|
|
|
*/
|
2008-11-30 11:16:55 +00:00
|
|
|
PUSB_INTERFACE_DESCRIPTOR NTAPI
|
2005-07-31 12:11:56 +00:00
|
|
|
USBD_ParseConfigurationDescriptorEx(
|
|
|
|
PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor,
|
|
|
|
PVOID StartPosition,
|
|
|
|
LONG InterfaceNumber,
|
|
|
|
LONG AlternateSetting,
|
|
|
|
LONG InterfaceClass,
|
|
|
|
LONG InterfaceSubClass,
|
|
|
|
LONG InterfaceProtocol
|
|
|
|
)
|
|
|
|
{
|
2005-08-14 13:18:50 +00:00
|
|
|
int x = 0;
|
|
|
|
PUSB_INTERFACE_DESCRIPTOR UsbInterfaceDesc = StartPosition;
|
|
|
|
|
|
|
|
while(UsbInterfaceDesc)
|
|
|
|
{
|
|
|
|
UsbInterfaceDesc = (PUSB_INTERFACE_DESCRIPTOR)
|
|
|
|
USBD_ParseDescriptors(ConfigurationDescriptor,
|
|
|
|
ConfigurationDescriptor->wTotalLength,
|
|
|
|
UsbInterfaceDesc,
|
|
|
|
USB_INTERFACE_DESCRIPTOR_TYPE);
|
|
|
|
|
|
|
|
if (!UsbInterfaceDesc) break;
|
|
|
|
|
|
|
|
if(InterfaceNumber != -1)
|
|
|
|
{
|
|
|
|
if(InterfaceNumber != UsbInterfaceDesc->bInterfaceNumber) x = 1;
|
|
|
|
}
|
|
|
|
if(AlternateSetting != -1)
|
|
|
|
{
|
|
|
|
if(AlternateSetting != UsbInterfaceDesc->bAlternateSetting) x = 1;
|
|
|
|
}
|
|
|
|
if(InterfaceClass != -1)
|
|
|
|
{
|
|
|
|
if(InterfaceClass != UsbInterfaceDesc->bInterfaceClass) x = 1;
|
|
|
|
}
|
|
|
|
if(InterfaceSubClass != -1)
|
|
|
|
{
|
|
|
|
if(InterfaceSubClass != UsbInterfaceDesc->bInterfaceSubClass) x = 1;
|
|
|
|
}
|
|
|
|
if(InterfaceProtocol != -1)
|
|
|
|
{
|
|
|
|
if(InterfaceProtocol != UsbInterfaceDesc->bInterfaceProtocol) x = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!x) return UsbInterfaceDesc;
|
|
|
|
|
|
|
|
if (UsbInterfaceDesc->bLength == 0) break;
|
|
|
|
UsbInterfaceDesc = UsbInterfaceDesc + UsbInterfaceDesc->bLength;
|
2007-10-19 23:21:45 +00:00
|
|
|
}
|
|
|
|
return NULL;
|
2005-07-31 12:11:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2008-11-30 11:16:55 +00:00
|
|
|
PUSB_INTERFACE_DESCRIPTOR NTAPI
|
2005-07-31 12:11:56 +00:00
|
|
|
USBD_ParseConfigurationDescriptor(
|
|
|
|
PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor,
|
|
|
|
UCHAR InterfaceNumber,
|
|
|
|
UCHAR AlternateSetting
|
|
|
|
)
|
|
|
|
{
|
|
|
|
return USBD_ParseConfigurationDescriptorEx(ConfigurationDescriptor,
|
|
|
|
(PVOID)ConfigurationDescriptor, InterfaceNumber, AlternateSetting,
|
|
|
|
-1, -1, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2010-06-12 12:20:41 +00:00
|
|
|
ULONG NTAPI
|
2005-07-31 12:11:56 +00:00
|
|
|
USBD_GetPdoRegistryParameter(
|
|
|
|
PDEVICE_OBJECT PhysicalDeviceObject,
|
|
|
|
PVOID Parameter,
|
|
|
|
ULONG ParameterLength,
|
|
|
|
PWCHAR KeyName,
|
|
|
|
ULONG KeyNameLength
|
|
|
|
)
|
|
|
|
{
|
|
|
|
NTSTATUS Status;
|
|
|
|
HANDLE DevInstRegKey;
|
|
|
|
|
|
|
|
Status = IoOpenDeviceRegistryKey(PhysicalDeviceObject,
|
|
|
|
PLUGPLAY_REGKEY_DRIVER, STANDARD_RIGHTS_ALL, &DevInstRegKey);
|
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
PKEY_VALUE_FULL_INFORMATION FullInfo;
|
|
|
|
UNICODE_STRING ValueName;
|
|
|
|
ULONG Length;
|
|
|
|
|
|
|
|
RtlInitUnicodeString(&ValueName, KeyName);
|
|
|
|
Length = ParameterLength + KeyNameLength + sizeof(KEY_VALUE_FULL_INFORMATION);
|
|
|
|
FullInfo = ExAllocatePool(PagedPool, Length);
|
|
|
|
if (FullInfo)
|
|
|
|
{
|
|
|
|
Status = ZwQueryValueKey(DevInstRegKey, &ValueName,
|
|
|
|
KeyValueFullInformation, FullInfo, Length, &Length);
|
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
RtlCopyMemory(Parameter,
|
|
|
|
((PUCHAR)FullInfo) + FullInfo->DataOffset,
|
|
|
|
ParameterLength /*FullInfo->DataLength*/);
|
|
|
|
}
|
|
|
|
ExFreePool(FullInfo);
|
|
|
|
} else
|
|
|
|
Status = STATUS_NO_MEMORY;
|
|
|
|
ZwClose(DevInstRegKey);
|
|
|
|
}
|
|
|
|
return Status;
|
|
|
|
}
|