From 81d6ebf9e3af1af27f68d6c4e6a9129b6efff33c Mon Sep 17 00:00:00 2001 From: Aleksey Bragin Date: Fri, 4 Feb 2005 16:49:17 +0000 Subject: [PATCH] usbd.sys implementation - done long time ago by Filip, I just added .def and changed .rc (I think he doesn't mind it :)) svn path=/trunk/; revision=13404 --- reactos/drivers/usb/usbd/makefile | 17 ++ reactos/drivers/usb/usbd/test.c | 33 +++ reactos/drivers/usb/usbd/usbd.c | 457 ++++++++++++++++++++++++++++++ reactos/drivers/usb/usbd/usbd.def | 13 + reactos/drivers/usb/usbd/usbd.rc | 5 + 5 files changed, 525 insertions(+) create mode 100644 reactos/drivers/usb/usbd/makefile create mode 100644 reactos/drivers/usb/usbd/test.c create mode 100644 reactos/drivers/usb/usbd/usbd.c create mode 100644 reactos/drivers/usb/usbd/usbd.def create mode 100644 reactos/drivers/usb/usbd/usbd.rc diff --git a/reactos/drivers/usb/usbd/makefile b/reactos/drivers/usb/usbd/makefile new file mode 100644 index 00000000000..4e3ba95dc41 --- /dev/null +++ b/reactos/drivers/usb/usbd/makefile @@ -0,0 +1,17 @@ +# $Id: $ + +PATH_TO_TOP = ../../.. + +TARGET_TYPE = export_driver + +TARGET_NAME = usbd + +TARGET_OBJECTS = usbd.o + +TARGET_GCCLIBS = gcc + +TARGET_CFLAGS = -D__USE_W32API -O3 -s + +include $(PATH_TO_TOP)/rules.mak + +include $(TOOLS_PATH)/helper.mk diff --git a/reactos/drivers/usb/usbd/test.c b/reactos/drivers/usb/usbd/test.c new file mode 100644 index 00000000000..193a9200ba1 --- /dev/null +++ b/reactos/drivers/usb/usbd/test.c @@ -0,0 +1,33 @@ +#include +#include +#include + +typedef ULONG STDCALL +(*USBD_GetInterfaceLengthTYPE)( + PUSB_INTERFACE_DESCRIPTOR InterfaceDescriptor, + PUCHAR BufferEnd + ); + +int main() +{ + HMODULE Lib; + USB_INTERFACE_DESCRIPTOR InterfaceDescriptor; + USBD_GetInterfaceLengthTYPE USBD_GetInterfaceLength; + + InterfaceDescriptor.bLength = 10; + InterfaceDescriptor.bNumEndpoints = 2; + InterfaceDescriptor.bDescriptorType = /*USB_INTERFACE_DESCRIPTOR_TYPE*/2; + InterfaceDescriptor.iInterface = 0x1; + + Lib = LoadLibraryEx("usbd.sys", NULL, DONT_RESOLVE_DLL_REFERENCES); + USBD_GetInterfaceLength = (USBD_GetInterfaceLengthTYPE)GetProcAddress(Lib, "USBD_GetInterfaceLength"); + printf("%X\n", USBD_GetInterfaceLength(&InterfaceDescriptor, (PUCHAR)((DWORD)&InterfaceDescriptor + sizeof(InterfaceDescriptor)))); + FreeLibrary(Lib); + + Lib = LoadLibraryEx("usbd.ms", NULL, DONT_RESOLVE_DLL_REFERENCES); + USBD_GetInterfaceLength = (USBD_GetInterfaceLengthTYPE)GetProcAddress(Lib, "USBD_GetInterfaceLength"); + printf("%X\n", USBD_GetInterfaceLength(&InterfaceDescriptor, (PUCHAR)((DWORD)&InterfaceDescriptor + sizeof(InterfaceDescriptor)))); + FreeLibrary(Lib); + return 0; +} + diff --git a/reactos/drivers/usb/usbd/usbd.c b/reactos/drivers/usb/usbd/usbd.c new file mode 100644 index 00000000000..66ae4a1fb4c --- /dev/null +++ b/reactos/drivers/usb/usbd/usbd.c @@ -0,0 +1,457 @@ +/* + * Universal Serial Bus Driver/Helper Library + * + * Written by Filip Navara + * + * 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) + * USBD_ParseConfigurationDescriptorEx + * USBD_ParseDescriptors + * USBD_GetPdoRegistryParameters (implemented) + */ + +#include +#include +#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; + +NTSTATUS STDCALL +DriverEntry(PDRIVER_OBJECT DriverObject, + PUNICODE_STRING RegistryPath) +{ + return STATUS_SUCCESS; +} + +/* + * @implemented + */ +DWORD STDCALL +DllInitialize(DWORD Unknown) +{ + return 0; +} + +/* + * @implemented + */ +DWORD STDCALL +DllUnload(VOID) +{ + return 0; +} + +/* + * @implemented + */ +PVOID STDCALL +USBD_Debug_GetHeap(DWORD Unknown1, POOL_TYPE PoolType, ULONG NumberOfBytes, + ULONG Tag) +{ + return ExAllocatePoolWithTag(PoolType, NumberOfBytes, Tag); +} + +/* + * @implemented + */ +VOID STDCALL +USBD_Debug_RetHeap(PVOID Heap, DWORD Unknown2, DWORD Unknown3) +{ + ExFreePool(Heap); +} + +/* + * @implemented + */ +VOID STDCALL +USBD_Debug_LogEntry(PCHAR Name, ULONG_PTR Info1, ULONG_PTR Info2, + ULONG_PTR Info3) +{ +} + +/* + * @implemented + */ +PVOID STDCALL +USBD_AllocateDeviceName(DWORD Unknown) +{ + return NULL; +} + +/* + * @implemented + */ +DWORD STDCALL +USBD_CalculateUsbBandwidth( + ULONG MaxPacketSize, + UCHAR EndpointType, + BOOLEAN LowSpeed + ) +{ + DWORD OverheadTable[] = { + 0x00, /* UsbdPipeTypeControl */ + 0x09, /* UsbdPipeTypeIsochronous */ + 0x00, /* UsbdPipeTypeBulk */ + 0x0d /* UsbdPipeTypeInterrupt */ + }; + DWORD Result; + + if (OverheadTable[EndpointType] != 0) + { + Result = ((MaxPacketSize + OverheadTable[EndpointType]) * 8 * 7) / 6; + if (LowSpeed) + return Result << 3; + return Result; + } + return 0; +} + +/* + * @implemented + */ +DWORD STDCALL +USBD_Dispatch(DWORD Unknown1, DWORD Unknown2, DWORD Unknown3, DWORD Unknown4) +{ + return 1; +} + +/* + * @implemented + */ +VOID STDCALL +USBD_FreeDeviceMutex(PVOID Unknown) +{ +} + +/* + * @implemented + */ +VOID STDCALL +USBD_FreeDeviceName(PVOID Unknown) +{ +} + +/* + * @implemented + */ +VOID STDCALL +USBD_WaitDeviceMutex(PVOID Unknown) +{ +} + +/* + * @implemented + */ +DWORD STDCALL +USBD_GetSuspendPowerState(DWORD Unknown1) +{ + return 0; +} + +/* + * @implemented + */ +NTSTATUS STDCALL +USBD_InitializeDevice(DWORD Unknown1, DWORD Unknown2, DWORD Unknown3, + DWORD Unknown4, DWORD Unknown5, DWORD Unknown6) +{ + return STATUS_NOT_SUPPORTED; +} + +/* + * @implemented + */ +NTSTATUS STDCALL +USBD_RegisterHostController(DWORD Unknown1, DWORD Unknown2, DWORD Unknown3, + DWORD Unknown4, DWORD Unknown5, DWORD Unknown6, DWORD Unknown7, + DWORD Unknown8, DWORD Unknown9, DWORD Unknown10) +{ + return STATUS_NOT_SUPPORTED; +} + +/* + * @implemented + */ +NTSTATUS STDCALL +USBD_GetDeviceInformation(DWORD Unknown1, DWORD Unknown2, DWORD Unknown3) +{ + return STATUS_NOT_SUPPORTED; +} + +/* + * @implemented + */ +NTSTATUS STDCALL +USBD_CreateDevice(DWORD Unknown1, DWORD Unknown2, DWORD Unknown3, + DWORD Unknown4, DWORD Unknown5) +{ + return STATUS_NOT_SUPPORTED; +} + +/* + * @implemented + */ +NTSTATUS STDCALL +USBD_RemoveDevice(DWORD Unknown1, DWORD Unknown2, DWORD Unknown3) +{ + return STATUS_NOT_SUPPORTED; +} + +/* + * @implemented + */ +VOID STDCALL +USBD_CompleteRequest(DWORD Unknown1, DWORD Unknown2) +{ +} + +/* + * @implemented + */ +VOID STDCALL +USBD_RegisterHcFilter( + PDEVICE_OBJECT DeviceObject, + PDEVICE_OBJECT FilterDeviceObject + ) +{ +} + +/* + * @implemented + */ +VOID STDCALL +USBD_SetSuspendPowerState(DWORD Unknown1, DWORD Unknown2) +{ +} + +/* + * @implemented + */ +NTSTATUS STDCALL +USBD_MakePdoName(DWORD Unknown1, DWORD Unknown2) +{ + return STATUS_NOT_SUPPORTED; +} + +/* + * @implemented + */ +NTSTATUS STDCALL +USBD_QueryBusTime( + PDEVICE_OBJECT RootHubPdo, + PULONG CurrentFrame + ) +{ + return STATUS_NOT_SUPPORTED; +} + +/* + * @implemented + */ +VOID STDCALL +USBD_GetUSBDIVersion( + PUSBD_VERSION_INFORMATION Version + ) +{ + if (Version != NULL) + { + Version->USBDI_Version = USBDI_VERSION; + Version->Supported_USB_Version = 0x100; + } +} + +/* + * @implemented + */ +NTSTATUS STDCALL +USBD_RestoreDevice(DWORD Unknown1, DWORD Unknown2, DWORD Unknown3) +{ + return STATUS_NOT_SUPPORTED; +} + +/* + * @implemented + */ +VOID STDCALL +USBD_RegisterHcDeviceCapabilities(DWORD Unknown1, DWORD Unknown2, + DWORD Unknown3) +{ +} + +/* + * @implemented + * FIXME: Test + */ +PURB +STDCALL +USBD_CreateConfigurationRequestEx( + PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor, + PUSBD_INTERFACE_LIST_ENTRY InterfaceList + ) +{ + PURB Urb; + DWORD UrbSize; + DWORD InterfaceCount; + + for (InterfaceCount = 0; + InterfaceList[InterfaceCount].InterfaceDescriptor != NULL; + ++InterfaceCount) + ; + /* Include the NULL entry */ + ++InterfaceCount; + + UrbSize = sizeof(Urb->UrbSelectConfiguration) + + (InterfaceCount * sizeof(PUSBD_INTERFACE_LIST_ENTRY)); + Urb = ExAllocatePool(NonPagedPool, UrbSize); + Urb->UrbSelectConfiguration.Hdr.Function = + URB_FUNCTION_SELECT_CONFIGURATION; + Urb->UrbSelectConfiguration.Hdr.Length = + sizeof(Urb->UrbSelectConfiguration); + Urb->UrbSelectConfiguration.ConfigurationDescriptor = + ConfigurationDescriptor; + memcpy((PVOID)&Urb->UrbSelectConfiguration.Interface, (PVOID)InterfaceList, + InterfaceCount * sizeof(PUSBD_INTERFACE_LIST_ENTRY)); + + return Urb; +} + +/* + * @unimplemented + */ +PURB STDCALL +USBD_CreateConfigurationRequest( + PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor, + PUSHORT Size + ) +{ + return NULL; +} + +/* + * @unimplemented + */ +ULONG STDCALL +USBD_GetInterfaceLength( + PUSB_INTERFACE_DESCRIPTOR InterfaceDescriptor, + PUCHAR BufferEnd + ) +{ + PUSB_INTERFACE_DESCRIPTOR CurrentDescriptor = InterfaceDescriptor; + DWORD Length = CurrentDescriptor->bLength; + + // USB_ENDPOINT_DESCRIPTOR_TYPE + if (CurrentDescriptor->bDescriptorType == USB_INTERFACE_DESCRIPTOR_TYPE) + { + for (; + (PUCHAR)CurrentDescriptor < BufferEnd; + (PVOID)CurrentDescriptor += CurrentDescriptor->bLength) + Length += CurrentDescriptor->bLength; + + } + return Length; +} + +/* + * @unimplemented + */ +PUSB_INTERFACE_DESCRIPTOR STDCALL +USBD_ParseConfigurationDescriptorEx( + PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor, + PVOID StartPosition, + LONG InterfaceNumber, + LONG AlternateSetting, + LONG InterfaceClass, + LONG InterfaceSubClass, + LONG InterfaceProtocol + ) +{ + return NULL; +} + +/* + * @implemented + */ +PUSB_INTERFACE_DESCRIPTOR STDCALL +USBD_ParseConfigurationDescriptor( + PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor, + UCHAR InterfaceNumber, + UCHAR AlternateSetting + ) +{ + return USBD_ParseConfigurationDescriptorEx(ConfigurationDescriptor, + (PVOID)ConfigurationDescriptor, InterfaceNumber, AlternateSetting, + -1, -1, -1); +} + +/* + * @unimplemented + */ +PUSB_COMMON_DESCRIPTOR STDCALL +USBD_ParseDescriptors( + PVOID DescriptorBuffer, + ULONG TotalLength, + PVOID StartPosition, + LONG DescriptorType + ) +{ + return NULL; +} + +/* + * @implemented + */ +DWORD STDCALL +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; +} diff --git a/reactos/drivers/usb/usbd/usbd.def b/reactos/drivers/usb/usbd/usbd.def new file mode 100644 index 00000000000..249dca88b66 --- /dev/null +++ b/reactos/drivers/usb/usbd/usbd.def @@ -0,0 +1,13 @@ +; +; Exports definition file for usbd.sys +; +EXPORTS +USBD_Debug_GetHeap@16 +USBD_Debug_RetHeap@12 +USBD_CalculateUsbBandwidth@12 +USBD_CreateConfigurationRequestEx@8 +USBD_CreateConfigurationRequest@8 +USBD_GetInterfaceLength@8 +USBD_ParseConfigurationDescriptorEx@28 +USBD_ParseDescriptors@16 +;USBD_GetPdoRegistryParameters diff --git a/reactos/drivers/usb/usbd/usbd.rc b/reactos/drivers/usb/usbd/usbd.rc new file mode 100644 index 00000000000..ee8239384d8 --- /dev/null +++ b/reactos/drivers/usb/usbd/usbd.rc @@ -0,0 +1,5 @@ +#define REACTOS_VERSION_DLL +#define REACTOS_STR_FILE_DESCRIPTION "USBD Legacy Driver\0" +#define REACTOS_STR_INTERNAL_NAME "usbd\0" +#define REACTOS_STR_ORIGINAL_FILENAME "usbd.sys\0" +#include