diff --git a/reactos/drivers/usb/usbehci/common.c b/reactos/drivers/usb/usbehci/common.c index 7ed7421d8d8..22740b3537f 100644 --- a/reactos/drivers/usb/usbehci/common.c +++ b/reactos/drivers/usb/usbehci/common.c @@ -4,7 +4,7 @@ * FILE: drivers/usb/usbehci/common.c * PURPOSE: Common operations in FDO/PDO. * PROGRAMMERS: - * Michael Martin + * Michael Martin (mjmartin@reactos.org) */ #define INITGUID @@ -135,7 +135,7 @@ DuplicateUnicodeString(ULONG Flags, PCUNICODE_STRING SourceString, PUNICODE_STRI if (Flags & RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE) DestMaxLength += sizeof(UNICODE_NULL); - DestinationString->Buffer = ExAllocatePool(PagedPool, DestMaxLength); + DestinationString->Buffer = ExAllocatePoolWithTag(NonPagedPool, DestMaxLength, USB_POOL_TAG); if (DestinationString->Buffer == NULL) return STATUS_NO_MEMORY; diff --git a/reactos/drivers/usb/usbehci/misc.c b/reactos/drivers/usb/usbehci/misc.c index 520c1c7aa8f..fb361e4f8f3 100644 --- a/reactos/drivers/usb/usbehci/misc.c +++ b/reactos/drivers/usb/usbehci/misc.c @@ -8,6 +8,8 @@ */ #include "usbehci.h" +#include +#include /* Get SymblicName from Parameters in Registry Key @@ -121,3 +123,14 @@ GetPhysicalDeviceObjectName(PDEVICE_OBJECT DeviceObject) return ObjectName; } +PUSB_DEVICE DeviceHandleToUsbDevice(PPDO_DEVICE_EXTENSION PdoDeviceExtension, PUSB_DEVICE_HANDLE DeviceHandle) +{ + LONG i; + + for (i=0; i<127; i++) + { + if (PdoDeviceExtension->UsbDevices[i] == (PUSB_DEVICE)DeviceHandle) + return (PUSB_DEVICE)DeviceHandle; + } + return NULL; +} diff --git a/reactos/drivers/usb/usbehci/pdo.c b/reactos/drivers/usb/usbehci/pdo.c index d0cf3072b62..19e75345fd1 100644 --- a/reactos/drivers/usb/usbehci/pdo.c +++ b/reactos/drivers/usb/usbehci/pdo.c @@ -446,7 +446,6 @@ PdoDispatchPnp( else { Status = IoSetDeviceInterfaceState(&InterfaceSymLinkName, TRUE); - DPRINT1("Set interface state %x\n", Status); if (!NT_SUCCESS(Status)) ASSERT(FALSE); } diff --git a/reactos/drivers/usb/usbehci/urbreq.c b/reactos/drivers/usb/usbehci/urbreq.c index e5af47ee954..86a88a899ea 100644 --- a/reactos/drivers/usb/usbehci/urbreq.c +++ b/reactos/drivers/usb/usbehci/urbreq.c @@ -82,7 +82,10 @@ IntializeHeadQueueForStandardRequest(PQUEUE_HEAD QueueHead, (*CtrlTD2)->NextPointer = TERMINATE_POINTER; (*CtrlTD2)->AlternateNextPointer = TERMINATE_POINTER; - (*CtrlTD2)->BufferPointer[0] = (ULONG)MmGetPhysicalAddress((PVOID) (*CtrlData)).LowPart; + if (Size == 0) + (*CtrlTD2)->BufferPointer[0] = 0; + else + (*CtrlTD2)->BufferPointer[0] = (ULONG)MmGetPhysicalAddress((PVOID) (*CtrlData)).LowPart; (*CtrlTD2)->Token.Bits.DataToggle = TRUE; (*CtrlTD2)->Token.Bits.InterruptOnComplete = TRUE; (*CtrlTD2)->Token.Bits.TotalBytesToTransfer = Size; @@ -98,6 +101,7 @@ IntializeHeadQueueForStandardRequest(PQUEUE_HEAD QueueHead, (*CtrlTD3)->Token.Bits.Active = TRUE; (*CtrlTD3)->Token.Bits.PIDCode = PID_CODE_OUT_TOKEN; (*CtrlTD3)->Token.Bits.InterruptOnComplete = TRUE; + (*CtrlTD3)->Token.Bits.TotalBytesToTransfer = 0; (*CtrlTD3)->Token.Bits.DataToggle = TRUE; (*CtrlTD3)->Token.Bits.ErrorCounter = 0x03; (*CtrlTD2)->NextPointer = (ULONG) MmGetPhysicalAddress((PVOID)(*CtrlTD3)).LowPart; @@ -185,12 +189,15 @@ ExecuteControlRequest(PFDO_DEVICE_EXTENSION DeviceExtension, PUSB_DEFAULT_PIPE_S for (;;) { - KeStallExecutionProcessor(10); + KeStallExecutionProcessor(100); DPRINT("Waiting for completion!\n"); if (DeviceExtension->AsyncComplete == TRUE) break; } + UsbCmd->Run = FALSE; + WRITE_REGISTER_ULONG((PULONG)(Base + EHCI_USBCMD), tmp); + if (CtrlSetup->bmRequestType._BM.Dir == BMREQUEST_DEVICE_TO_HOST) { if ((Buffer) && (BufferLength)) diff --git a/reactos/drivers/usb/usbehci/usbehci.h b/reactos/drivers/usb/usbehci/usbehci.h index f5977412db7..1867763de20 100644 --- a/reactos/drivers/usb/usbehci/usbehci.h +++ b/reactos/drivers/usb/usbehci/usbehci.h @@ -419,14 +419,6 @@ typedef struct _PDO_DEVICE_EXTENSION FAST_MUTEX ListLock; } PDO_DEVICE_EXTENSION, *PPDO_DEVICE_EXTENSION; -typedef struct _WORKITEM_DATA -{ - PIO_WORKITEM IoWorkItem; - PPDO_DEVICE_EXTENSION PdoDeviceExtension; - PDEVICE_OBJECT PortDeviceObject; -} WORKITEM_DATA, *PWORKITEM_DATA; - - VOID NTAPI UrbWorkerThread(PVOID Context); @@ -478,5 +470,5 @@ CompletePendingURBRequest(PPDO_DEVICE_EXTENSION DeviceExtension); VOID URBRequestCancel (PDEVICE_OBJECT DeviceObject, PIRP Irp); -VOID NTAPI -DeviceArrivalWorkItem(PDEVICE_OBJECT DeviceObject, PVOID Context); +PUSB_DEVICE +DeviceHandleToUsbDevice(PPDO_DEVICE_EXTENSION PdoDeviceExtension, PUSB_DEVICE_HANDLE DeviceHandle); diff --git a/reactos/drivers/usb/usbehci/usbehci.rbuild b/reactos/drivers/usb/usbehci/usbehci.rbuild index 3f6f1e6c8f3..c5ace344e51 100644 --- a/reactos/drivers/usb/usbehci/usbehci.rbuild +++ b/reactos/drivers/usb/usbehci/usbehci.rbuild @@ -11,4 +11,5 @@ irp.c usbiffn.c urbreq.c + usbehci.rc diff --git a/reactos/drivers/usb/usbehci/usbiffn.c b/reactos/drivers/usb/usbehci/usbiffn.c index 95cbbaab156..5b4c5b4555c 100644 --- a/reactos/drivers/usb/usbehci/usbiffn.c +++ b/reactos/drivers/usb/usbehci/usbiffn.c @@ -38,27 +38,6 @@ PVOID InternalCreateUsbDevice(UCHAR DeviceNumber, ULONG Port, PUSB_DEVICE Parent return UsbDevicePointer; } -BOOLEAN -IsHandleValid(PVOID BusContext, - PUSB_DEVICE_HANDLE DeviceHandle) -{ - PPDO_DEVICE_EXTENSION PdoDeviceExtension; - LONG i; - - PdoDeviceExtension = (PPDO_DEVICE_EXTENSION) BusContext; - - if (!DeviceHandle) - return FALSE; - - for (i = 0; i < 128; i++) - { - if (PdoDeviceExtension->UsbDevices[i] == DeviceHandle) - return TRUE; - } - - return FALSE; -} - VOID USB_BUSIFFN InterfaceReference(PVOID BusContext) @@ -86,10 +65,19 @@ CreateUsbDevice(PVOID BusContext, PUSB_DEVICE UsbDevice; LONG i = 0; PdoDeviceExtension = (PPDO_DEVICE_EXTENSION)((PDEVICE_OBJECT)BusContext)->DeviceExtension; - DPRINT1("CreateUsbDevice: HubDeviceHandle %x, PortStatus %x, PortNumber %x\n", HubDeviceHandle, PortStatus, PortNumber); + DPRINT("CreateUsbDevice: HubDeviceHandle %x, PortStatus %x, PortNumber %x\n", HubDeviceHandle, PortStatus, PortNumber); + + if (PdoDeviceExtension->UsbDevices[0] != HubDeviceHandle) + { + DPRINT1("Not a valid HubDeviceHandle\n"); + return STATUS_DEVICE_NOT_CONNECTED; + } UsbDevice = InternalCreateUsbDevice(PdoDeviceExtension->ChildDeviceCount, PortNumber, HubDeviceHandle, FALSE); + if (!UsbDevice) + return STATUS_INSUFFICIENT_RESOURCES; + /* Add it to the list */ while (TRUE) { @@ -131,7 +119,14 @@ InitializeUsbDevice(PVOID BusContext, PUSB_DEVICE_HANDLE DeviceHandle) DPRINT1("InitializeUsbDevice called, device %x\n", DeviceHandle); PdoDeviceExtension = (PPDO_DEVICE_EXTENSION)((PDEVICE_OBJECT)BusContext)->DeviceExtension; FdoDeviceExtension = (PFDO_DEVICE_EXTENSION)PdoDeviceExtension->ControllerFdo->DeviceExtension; - UsbDevice = (PUSB_DEVICE) DeviceHandle; + + UsbDevice = DeviceHandleToUsbDevice(BusContext, DeviceHandle); + + if (!UsbDevice) + { + DPRINT1("Invalid DeviceHandle or device not connected\n"); + return STATUS_DEVICE_NOT_CONNECTED; + } Buffer = ExAllocatePoolWithTag(NonPagedPool, PAGE_SIZE, USB_POOL_TAG); @@ -153,7 +148,7 @@ InitializeUsbDevice(PVOID BusContext, PUSB_DEVICE_HANDLE DeviceHandle) CtrlSetup.wLength = 0; DPRINT1("Setting Address to %x\n", UsbDevice->Address); - ResultOk = ExecuteControlRequest(FdoDeviceExtension, &CtrlSetup, 0, 0, NULL, 0); + ResultOk = ExecuteControlRequest(FdoDeviceExtension, &CtrlSetup, 0, UsbDevice->Port, NULL, 0); /* Get the Device Descriptor */ CtrlSetup.bmRequestType._BM.Recipient = BMREQUEST_TO_DEVICE; @@ -177,7 +172,10 @@ InitializeUsbDevice(PVOID BusContext, PUSB_DEVICE_HANDLE DeviceHandle) DPRINT1("bNumDescriptors %x\n", UsbDevice->DeviceDescriptor.bNumConfigurations); if (UsbDevice->DeviceDescriptor.bNumConfigurations == 0) + { + DPRINT1("No Configurations. That cant be good!\n"); return STATUS_DEVICE_DATA_ERROR; + } UsbDevice->Configs = ExAllocatePoolWithTag(NonPagedPool, sizeof(PVOID) * UsbDevice->DeviceDescriptor.bNumConfigurations, @@ -256,8 +254,14 @@ GetUsbDescriptors(PVOID BusContext, PUSB_DEVICE UsbDevice; DPRINT1("GetUsbDescriptor %x, %x, %x, %x\n", DeviceDescriptorBuffer, *DeviceDescriptorBufferLength, ConfigDescriptorBuffer, *ConfigDescriptorBufferLength); - UsbDevice = (PUSB_DEVICE) DeviceHandle; - DPRINT1("DeviceHandle %x\n", UsbDevice); + UsbDevice = DeviceHandleToUsbDevice(BusContext, DeviceHandle); + + if (!UsbDevice) + { + DPRINT1("Invalid DeviceHandle or device not connected\n"); + return STATUS_DEVICE_NOT_CONNECTED; + } + if ((DeviceDescriptorBuffer) && (DeviceDescriptorBufferLength)) { RtlCopyMemory(DeviceDescriptorBuffer, &UsbDevice->DeviceDescriptor, sizeof(USB_DEVICE_DESCRIPTOR)); @@ -284,13 +288,13 @@ RemoveUsbDevice(PVOID BusContext, PUSB_DEVICE_HANDLE DeviceHandle, ULONG Flags) PdoDeviceExtension = (PPDO_DEVICE_EXTENSION)((PDEVICE_OBJECT)BusContext)->DeviceExtension; - /* FIXME: Implement DeviceHandleToUsbDevice to validate handles */ - //UsbDevice = DeviceHandleToUsbDevice(PdoDeviceExtension, DeviceHandle); + UsbDevice = DeviceHandleToUsbDevice(BusContext, DeviceHandle); - UsbDevice = (PUSB_DEVICE) DeviceHandle; - - if (!UsbDevice) + if (!UsbDevice) + { + DPRINT1("Invalid DeviceHandle or device not connected\n"); return STATUS_DEVICE_NOT_CONNECTED; + } switch (Flags) { @@ -320,11 +324,11 @@ RemoveUsbDevice(PVOID BusContext, PUSB_DEVICE_HANDLE DeviceHandle, ULONG Flags) /* DeConfig Device */ break; case USBD_KEEP_DEVICE_DATA: - DPRINT("USBD_KEEP_DEVICE_DATA Not implemented!\n"); + DPRINT1("USBD_KEEP_DEVICE_DATA Not implemented!\n"); break; case USBD_MARK_DEVICE_BUSY: - DPRINT("USBD_MARK_DEVICE_BUSY Not implemented!\n"); + DPRINT1("USBD_MARK_DEVICE_BUSY Not implemented!\n"); break; default: DPRINT1("Unknown Remove Flags %x\n", Flags); @@ -357,17 +361,18 @@ QueryDeviceInformation(PVOID BusContext, PULONG LengthReturned) { PUSB_DEVICE_INFORMATION_0 DeviceInfo = DeviceInformationBuffer; - PUSB_DEVICE UsbDevice = (PUSB_DEVICE) DeviceHandle; + PUSB_DEVICE UsbDevice; ULONG SizeNeeded; LONG i; DPRINT1("QueryDeviceInformation (%x, %x, %x, %d, %x\n", BusContext, DeviceHandle, DeviceInformationBuffer, DeviceInformationBufferLength, LengthReturned); - /* Search for a valid usb device in this BusContext */ - if (!IsHandleValid(BusContext, DeviceHandle)) + UsbDevice = DeviceHandleToUsbDevice(BusContext, DeviceHandle); + + if (!UsbDevice) { - DPRINT1("Not a valid DeviceHandle\n"); - return STATUS_INVALID_PARAMETER; + DPRINT1("Invalid DeviceHandle or device not connected\n"); + return STATUS_DEVICE_NOT_CONNECTED; } SizeNeeded = FIELD_OFFSET(USB_DEVICE_INFORMATION_0, PipeList[UsbDevice->ActiveInterface->InterfaceDescriptor.bNumEndpoints]); @@ -505,7 +510,17 @@ PVOID USB_BUSIFFN GetDeviceBusContext(PVOID HubBusContext, PVOID DeviceHandle) { + PUSB_DEVICE UsbDevice; + DPRINT1("GetDeviceBusContext called\n"); + UsbDevice = DeviceHandleToUsbDevice(HubBusContext, DeviceHandle); + + if (!UsbDevice) + { + DPRINT1("Invalid DeviceHandle or device not connected\n"); + return NULL; + } + return NULL; } @@ -549,6 +564,14 @@ VOID USB_BUSIFFN FlushTransfers(PVOID BusContext, PVOID DeviceHandle) { + PUSB_DEVICE UsbDevice; + UsbDevice = DeviceHandleToUsbDevice(BusContext, DeviceHandle); + + if (!UsbDevice) + { + DPRINT1("Invalid DeviceHandle or device not connected\n"); + } + DPRINT1("FlushTransfers\n"); } @@ -611,5 +634,5 @@ USB_BUSIFFN EnumLogEntry(PVOID BusContext, ULONG DriverTag, ULONG EnumTag, ULONG P1, ULONG P2) { DPRINT1("EnumLogEntry called\n"); - return STATUS_NOT_SUPPORTED; + return STATUS_SUCCESS; }