mirror of
https://github.com/reactos/reactos.git
synced 2025-08-02 17:45:40 +00:00
[FORMATTING][USBSTOR] Remove Captain Obvious and line-wasting comments.
Now the driver conforms with our current Coding Style. No functional changes
This commit is contained in:
parent
33604e0147
commit
d17d15ab6c
9 changed files with 271 additions and 2439 deletions
|
@ -1,12 +1,10 @@
|
|||
/*
|
||||
* PROJECT: ReactOS Universal Serial Bus Bulk Storage Driver
|
||||
* LICENSE: GPL - See COPYING in the top level directory
|
||||
* FILE: drivers/usb/usbstor/descriptor.c
|
||||
* LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
|
||||
* PURPOSE: USB block storage device driver.
|
||||
* PROGRAMMERS:
|
||||
* James Tabor
|
||||
* Michael Martin (michael.martin@reactos.org)
|
||||
* Johannes Anderwald (johannes.anderwald@reactos.org)
|
||||
* COPYRIGHT: 2005-2006 James Tabor
|
||||
* 2011-2012 Michael Martin (michael.martin@reactos.org)
|
||||
* 2011-2013 Johannes Anderwald (johannes.anderwald@reactos.org)
|
||||
*/
|
||||
|
||||
#include "usbstor.h"
|
||||
|
@ -14,6 +12,7 @@
|
|||
#define NDEBUG
|
||||
#include <debug.h>
|
||||
|
||||
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
USBSTOR_GetDescriptor(
|
||||
|
@ -28,41 +27,27 @@ USBSTOR_GetDescriptor(
|
|||
NTSTATUS Status;
|
||||
PVOID Descriptor;
|
||||
|
||||
//
|
||||
// sanity checks
|
||||
//
|
||||
ASSERT(DeviceObject);
|
||||
ASSERT(OutDescriptor);
|
||||
ASSERT(DescriptorLength);
|
||||
|
||||
//
|
||||
// first allocate descriptor buffer
|
||||
//
|
||||
Descriptor = AllocateItem(NonPagedPool, DescriptorLength);
|
||||
if (!Descriptor)
|
||||
{
|
||||
//
|
||||
// no memory
|
||||
//
|
||||
return STATUS_INSUFFICIENT_RESOURCES;
|
||||
}
|
||||
|
||||
//
|
||||
// allocate urb
|
||||
//
|
||||
Urb = (PURB) AllocateItem(NonPagedPool, sizeof(URB));
|
||||
if (!Urb)
|
||||
{
|
||||
//
|
||||
// no memory
|
||||
//
|
||||
FreeItem(Descriptor);
|
||||
return STATUS_INSUFFICIENT_RESOURCES;
|
||||
}
|
||||
|
||||
//
|
||||
// initialize urb
|
||||
//
|
||||
UsbBuildGetDescriptorRequest(Urb,
|
||||
sizeof(Urb->UrbControlDescriptorRequest),
|
||||
DescriptorType,
|
||||
|
@ -73,31 +58,19 @@ USBSTOR_GetDescriptor(
|
|||
DescriptorLength,
|
||||
NULL);
|
||||
|
||||
//
|
||||
// submit urb
|
||||
//
|
||||
Status = USBSTOR_SyncUrbRequest(DeviceObject, Urb);
|
||||
|
||||
//
|
||||
// free urb
|
||||
//
|
||||
FreeItem(Urb);
|
||||
|
||||
if (NT_SUCCESS(Status))
|
||||
{
|
||||
//
|
||||
// store result
|
||||
//
|
||||
*OutDescriptor = Descriptor;
|
||||
}
|
||||
|
||||
//
|
||||
// done
|
||||
//
|
||||
return Status;
|
||||
}
|
||||
|
||||
|
||||
NTSTATUS
|
||||
USBSTOR_GetDescriptors(
|
||||
IN PDEVICE_OBJECT DeviceObject)
|
||||
|
@ -106,89 +79,54 @@ USBSTOR_GetDescriptors(
|
|||
PFDO_DEVICE_EXTENSION DeviceExtension;
|
||||
USHORT DescriptorLength;
|
||||
|
||||
//
|
||||
// get device extension
|
||||
//
|
||||
DeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
|
||||
|
||||
//
|
||||
// first get device descriptor
|
||||
//
|
||||
Status = USBSTOR_GetDescriptor(DeviceExtension->LowerDeviceObject, USB_DEVICE_DESCRIPTOR_TYPE, sizeof(USB_DEVICE_DESCRIPTOR), 0, 0, (PVOID*)&DeviceExtension->DeviceDescriptor);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
//
|
||||
// failed to get device descriptor
|
||||
//
|
||||
DeviceExtension->DeviceDescriptor = NULL;
|
||||
return Status;
|
||||
}
|
||||
|
||||
//
|
||||
// now get basic configuration descriptor
|
||||
//
|
||||
Status = USBSTOR_GetDescriptor(DeviceExtension->LowerDeviceObject, USB_CONFIGURATION_DESCRIPTOR_TYPE, sizeof(USB_CONFIGURATION_DESCRIPTOR), 0, 0, (PVOID*)&DeviceExtension->ConfigurationDescriptor);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
//
|
||||
// failed to get configuration descriptor
|
||||
//
|
||||
FreeItem(DeviceExtension->DeviceDescriptor);
|
||||
DeviceExtension->DeviceDescriptor = NULL;
|
||||
return Status;
|
||||
}
|
||||
|
||||
//
|
||||
// backup length
|
||||
//
|
||||
DescriptorLength = DeviceExtension->ConfigurationDescriptor->wTotalLength;
|
||||
|
||||
//
|
||||
// release basic descriptor
|
||||
//
|
||||
FreeItem(DeviceExtension->ConfigurationDescriptor);
|
||||
DeviceExtension->ConfigurationDescriptor = NULL;
|
||||
|
||||
//
|
||||
// allocate full descriptor
|
||||
//
|
||||
Status = USBSTOR_GetDescriptor(DeviceExtension->LowerDeviceObject, USB_CONFIGURATION_DESCRIPTOR_TYPE, DescriptorLength, 0, 0, (PVOID*)&DeviceExtension->ConfigurationDescriptor);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
//
|
||||
// failed to get configuration descriptor
|
||||
//
|
||||
FreeItem(DeviceExtension->DeviceDescriptor);
|
||||
DeviceExtension->DeviceDescriptor = NULL;
|
||||
return Status;
|
||||
}
|
||||
|
||||
//
|
||||
// check if there is a serial number provided
|
||||
//
|
||||
if (DeviceExtension->DeviceDescriptor->iSerialNumber)
|
||||
{
|
||||
//
|
||||
// get serial number
|
||||
//
|
||||
Status = USBSTOR_GetDescriptor(DeviceExtension->LowerDeviceObject, USB_STRING_DESCRIPTOR_TYPE, 100 * sizeof(WCHAR), DeviceExtension->DeviceDescriptor->iSerialNumber, 0x0409, (PVOID*)&DeviceExtension->SerialNumber);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
//
|
||||
// failed to get serial number descriptor, free device descriptor
|
||||
//
|
||||
FreeItem(DeviceExtension->DeviceDescriptor);
|
||||
DeviceExtension->DeviceDescriptor = NULL;
|
||||
|
||||
//
|
||||
// free configuration descriptor
|
||||
//
|
||||
FreeItem(DeviceExtension->ConfigurationDescriptor);
|
||||
DeviceExtension->ConfigurationDescriptor = NULL;
|
||||
|
||||
//
|
||||
// set serial number to zero
|
||||
//
|
||||
DeviceExtension->SerialNumber = NULL;
|
||||
return Status;
|
||||
}
|
||||
|
@ -201,133 +139,80 @@ NTSTATUS
|
|||
NTAPI
|
||||
USBSTOR_ScanConfigurationDescriptor(
|
||||
IN PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor,
|
||||
OUT PUSB_INTERFACE_DESCRIPTOR * OutInterfaceDescriptor,
|
||||
OUT PUSB_ENDPOINT_DESCRIPTOR * InEndpointDescriptor,
|
||||
OUT PUSB_ENDPOINT_DESCRIPTOR * OutEndpointDescriptor)
|
||||
OUT PUSB_INTERFACE_DESCRIPTOR *OutInterfaceDescriptor,
|
||||
OUT PUSB_ENDPOINT_DESCRIPTOR *InEndpointDescriptor,
|
||||
OUT PUSB_ENDPOINT_DESCRIPTOR *OutEndpointDescriptor)
|
||||
{
|
||||
PUSB_CONFIGURATION_DESCRIPTOR CurrentDescriptor;
|
||||
PUSB_ENDPOINT_DESCRIPTOR EndpointDescriptor;
|
||||
|
||||
//
|
||||
// sanity checks
|
||||
//
|
||||
ASSERT(ConfigurationDescriptor);
|
||||
ASSERT(OutInterfaceDescriptor);
|
||||
ASSERT(InEndpointDescriptor);
|
||||
ASSERT(OutEndpointDescriptor);
|
||||
|
||||
//
|
||||
// nullify pointers
|
||||
//
|
||||
*OutInterfaceDescriptor = NULL;
|
||||
*InEndpointDescriptor = NULL;
|
||||
*OutEndpointDescriptor = NULL;
|
||||
|
||||
//
|
||||
// start scanning
|
||||
//
|
||||
CurrentDescriptor = ConfigurationDescriptor;
|
||||
|
||||
do
|
||||
{
|
||||
//
|
||||
// check current descriptor type
|
||||
//
|
||||
if (CurrentDescriptor->bDescriptorType == USB_INTERFACE_DESCRIPTOR_TYPE)
|
||||
{
|
||||
//
|
||||
// found interface descriptor
|
||||
//
|
||||
if (*OutInterfaceDescriptor)
|
||||
{
|
||||
//
|
||||
// we only process the first interface descriptor as ms does -> see documentation
|
||||
//
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
// store interface descriptor
|
||||
//
|
||||
*OutInterfaceDescriptor = (PUSB_INTERFACE_DESCRIPTOR)CurrentDescriptor;
|
||||
}
|
||||
else if (CurrentDescriptor->bDescriptorType == USB_ENDPOINT_DESCRIPTOR_TYPE)
|
||||
{
|
||||
//
|
||||
// convert to endpoint descriptor
|
||||
//
|
||||
EndpointDescriptor = (PUSB_ENDPOINT_DESCRIPTOR)CurrentDescriptor;
|
||||
|
||||
//
|
||||
// sanity check
|
||||
//
|
||||
ASSERT(*OutInterfaceDescriptor);
|
||||
|
||||
//
|
||||
// get endpoint type
|
||||
//
|
||||
if ((EndpointDescriptor->bmAttributes & USB_ENDPOINT_TYPE_MASK) == USB_ENDPOINT_TYPE_BULK)
|
||||
{
|
||||
//
|
||||
// bulk endpoint type
|
||||
//
|
||||
if (USB_ENDPOINT_DIRECTION_IN(EndpointDescriptor->bEndpointAddress))
|
||||
{
|
||||
//
|
||||
// bulk in
|
||||
//
|
||||
*InEndpointDescriptor = EndpointDescriptor;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// bulk out
|
||||
//
|
||||
*OutEndpointDescriptor = EndpointDescriptor;
|
||||
}
|
||||
if (USB_ENDPOINT_DIRECTION_IN(EndpointDescriptor->bEndpointAddress))
|
||||
{
|
||||
*InEndpointDescriptor = EndpointDescriptor;
|
||||
}
|
||||
else
|
||||
{
|
||||
*OutEndpointDescriptor = EndpointDescriptor;
|
||||
}
|
||||
}
|
||||
else if ((EndpointDescriptor->bmAttributes & USB_ENDPOINT_TYPE_MASK) == USB_ENDPOINT_TYPE_INTERRUPT)
|
||||
{
|
||||
//
|
||||
// interrupt endpoint type
|
||||
//
|
||||
UNIMPLEMENTED;
|
||||
UNIMPLEMENTED;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// move to next descriptor
|
||||
//
|
||||
CurrentDescriptor = (PUSB_CONFIGURATION_DESCRIPTOR)((ULONG_PTR)CurrentDescriptor + CurrentDescriptor->bLength);
|
||||
|
||||
//
|
||||
// was it the last descriptor
|
||||
//
|
||||
if ((ULONG_PTR)CurrentDescriptor >= ((ULONG_PTR)ConfigurationDescriptor + ConfigurationDescriptor->wTotalLength))
|
||||
{
|
||||
//
|
||||
// reached last descriptor
|
||||
//
|
||||
break;
|
||||
}
|
||||
|
||||
}while(TRUE);
|
||||
} while(TRUE);
|
||||
|
||||
//
|
||||
// check if everything has been found
|
||||
//
|
||||
if (*OutInterfaceDescriptor == NULL || *InEndpointDescriptor == NULL || *OutEndpointDescriptor == NULL)
|
||||
{
|
||||
//
|
||||
// failed to find interface / endpoint descriptor
|
||||
//
|
||||
DPRINT1("USBSTOR_ScanConfigurationDescriptor: Failed to find InterfaceDescriptor %p InEndpointDescriptor %p OutEndpointDescriptor %p\n", *OutInterfaceDescriptor, *InEndpointDescriptor, *OutEndpointDescriptor);
|
||||
return STATUS_UNSUCCESSFUL;
|
||||
}
|
||||
|
||||
//
|
||||
// completed successfully
|
||||
//
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -356,128 +241,77 @@ USBSTOR_SelectConfigurationAndInterface(
|
|||
PURB Urb;
|
||||
PUSBD_INTERFACE_LIST_ENTRY InterfaceList;
|
||||
|
||||
//
|
||||
// now scan configuration descriptors
|
||||
//
|
||||
Status = USBSTOR_ScanConfigurationDescriptor(DeviceExtension->ConfigurationDescriptor, &InterfaceDescriptor, &InEndpointDescriptor, &OutEndpointDescriptor);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
//
|
||||
// failed to scan
|
||||
//
|
||||
return Status;
|
||||
}
|
||||
|
||||
//
|
||||
// now allocate one interface entry and terminating null entry
|
||||
//
|
||||
InterfaceList = (PUSBD_INTERFACE_LIST_ENTRY)AllocateItem(PagedPool, sizeof(USBD_INTERFACE_LIST_ENTRY) * 2);
|
||||
if (!InterfaceList)
|
||||
{
|
||||
//
|
||||
// no memory
|
||||
//
|
||||
return STATUS_INSUFFICIENT_RESOURCES;
|
||||
}
|
||||
|
||||
//
|
||||
// initialize interface list entry
|
||||
//
|
||||
InterfaceList[0].InterfaceDescriptor = InterfaceDescriptor;
|
||||
|
||||
//
|
||||
// now allocate the urb
|
||||
//
|
||||
Urb = USBD_CreateConfigurationRequestEx(DeviceExtension->ConfigurationDescriptor, InterfaceList);
|
||||
if (!Urb)
|
||||
{
|
||||
//
|
||||
// no memory
|
||||
//
|
||||
FreeItem(InterfaceList);
|
||||
return STATUS_INSUFFICIENT_RESOURCES;
|
||||
}
|
||||
|
||||
//
|
||||
// sanity check
|
||||
//
|
||||
|
||||
ASSERT(InterfaceList[0].Interface);
|
||||
|
||||
//
|
||||
// submit urb
|
||||
//
|
||||
Status = USBSTOR_SyncUrbRequest(DeviceExtension->LowerDeviceObject, Urb);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
//
|
||||
// failed to set configuration
|
||||
//
|
||||
DPRINT1("USBSTOR_SelectConfiguration failed to set interface %x\n", Status);
|
||||
FreeItem(InterfaceList);
|
||||
ExFreePoolWithTag(Urb, 0);
|
||||
return Status;
|
||||
}
|
||||
|
||||
//
|
||||
// backup interface information
|
||||
//
|
||||
DeviceExtension->InterfaceInformation = (PUSBD_INTERFACE_INFORMATION)AllocateItem(NonPagedPool, Urb->UrbSelectConfiguration.Interface.Length);
|
||||
if (!DeviceExtension->InterfaceInformation)
|
||||
{
|
||||
//
|
||||
// failed to allocate interface information structure
|
||||
//
|
||||
FreeItem(InterfaceList);
|
||||
ExFreePoolWithTag(Urb, 0);
|
||||
return STATUS_INSUFFICIENT_RESOURCES;
|
||||
}
|
||||
|
||||
//
|
||||
// copy interface information
|
||||
//
|
||||
RtlCopyMemory(DeviceExtension->InterfaceInformation, &Urb->UrbSelectConfiguration.Interface, Urb->UrbSelectConfiguration.Interface.Length);
|
||||
|
||||
//
|
||||
// store pipe handle
|
||||
//
|
||||
DeviceExtension->ConfigurationHandle = Urb->UrbSelectConfiguration.ConfigurationHandle;
|
||||
|
||||
//
|
||||
// now prepare interface urb
|
||||
//
|
||||
UsbBuildSelectInterfaceRequest(Urb, GET_SELECT_INTERFACE_REQUEST_SIZE(InterfaceDescriptor->bNumEndpoints), DeviceExtension->ConfigurationHandle, InterfaceDescriptor->bInterfaceNumber, InterfaceDescriptor->bAlternateSetting);
|
||||
|
||||
//
|
||||
// copy interface information structure back - as offset for SelectConfiguration / SelectInterface request do differ
|
||||
//
|
||||
RtlCopyMemory(&Urb->UrbSelectInterface.Interface, DeviceExtension->InterfaceInformation, DeviceExtension->InterfaceInformation->Length);
|
||||
|
||||
//
|
||||
// now select the interface
|
||||
//
|
||||
Status = USBSTOR_SyncUrbRequest(DeviceExtension->LowerDeviceObject, Urb);
|
||||
|
||||
//
|
||||
// did it succeed
|
||||
//
|
||||
if (NT_SUCCESS(Status))
|
||||
{
|
||||
//
|
||||
// update configuration info
|
||||
//
|
||||
ASSERT(Urb->UrbSelectInterface.Interface.Length == DeviceExtension->InterfaceInformation->Length);
|
||||
RtlCopyMemory(DeviceExtension->InterfaceInformation, &Urb->UrbSelectInterface.Interface, Urb->UrbSelectInterface.Interface.Length);
|
||||
}
|
||||
|
||||
//
|
||||
// free interface list & urb
|
||||
//
|
||||
FreeItem(InterfaceList);
|
||||
ExFreePoolWithTag(Urb, 0);
|
||||
|
||||
//
|
||||
// done
|
||||
//
|
||||
return Status;
|
||||
}
|
||||
|
||||
|
@ -488,62 +322,36 @@ USBSTOR_GetPipeHandles(
|
|||
ULONG Index;
|
||||
BOOLEAN BulkInFound = FALSE, BulkOutFound = FALSE;
|
||||
|
||||
//
|
||||
// no enumerate all pipes and extract bulk-in / bulk-out pipe handle
|
||||
//
|
||||
for(Index = 0; Index < DeviceExtension->InterfaceInformation->NumberOfPipes; Index++)
|
||||
// enumerate all pipes and extract bulk-in / bulk-out pipe handle
|
||||
for (Index = 0; Index < DeviceExtension->InterfaceInformation->NumberOfPipes; Index++)
|
||||
{
|
||||
//
|
||||
// check pipe type
|
||||
//
|
||||
if (DeviceExtension->InterfaceInformation->Pipes[Index].PipeType == UsbdPipeTypeBulk)
|
||||
{
|
||||
//
|
||||
// check direction
|
||||
//
|
||||
if (USB_ENDPOINT_DIRECTION_IN(DeviceExtension->InterfaceInformation->Pipes[Index].EndpointAddress))
|
||||
{
|
||||
//
|
||||
// bulk in pipe
|
||||
//
|
||||
DeviceExtension->BulkInPipeIndex = Index;
|
||||
|
||||
//
|
||||
// there should not be another bulk in pipe
|
||||
//
|
||||
ASSERT(BulkInFound == FALSE);
|
||||
BulkInFound = TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// bulk out pipe
|
||||
//
|
||||
DeviceExtension->BulkOutPipeIndex = Index;
|
||||
|
||||
//
|
||||
// there should not be another bulk out pipe
|
||||
//
|
||||
ASSERT(BulkOutFound == FALSE);
|
||||
BulkOutFound = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// check if both bulk pipes have been found
|
||||
//
|
||||
if (!BulkInFound || !BulkOutFound)
|
||||
{
|
||||
//
|
||||
// WTF? usb port driver does not give us bulk pipe access
|
||||
//
|
||||
DPRINT1("USBSTOR_GetPipeHandles> BulkInFound %c BulkOutFound %c missing!!!\n", BulkInFound, BulkOutFound);
|
||||
return STATUS_DEVICE_CONFIGURATION_ERROR;
|
||||
}
|
||||
|
||||
//
|
||||
// device is configured
|
||||
//
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue