[USBSTOR]

- Implement retrieving serial number from device
- Use serial number to format instance id and retrieve in StorageDeviceProperty requests
- Silence traces


svn path=/branches/usb-bringup/; revision=51770
This commit is contained in:
Johannes Anderwald 2011-05-15 17:57:02 +00:00
parent e9a0c8ba68
commit a5d0b5fdef
7 changed files with 118 additions and 26 deletions

View file

@ -161,8 +161,36 @@ USBSTOR_GetDescriptors(
}
//
// FIXME: scan string descriptors
// 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;
}
}
return Status;
}

View file

@ -240,11 +240,15 @@ USBSTOR_HandleQueryProperty(
PSTORAGE_PROPERTY_QUERY PropertyQuery;
PSTORAGE_DESCRIPTOR_HEADER DescriptorHeader;
PSTORAGE_ADAPTER_DESCRIPTOR AdapterDescriptor;
ULONG FieldLengthVendor, FieldLengthProduct, FieldLengthRevision, TotalLength;
ULONG FieldLengthVendor, FieldLengthProduct, FieldLengthRevision, TotalLength, FieldLengthSerialNumber;
PPDO_DEVICE_EXTENSION PDODeviceExtension;
PUFI_INQUIRY_RESPONSE InquiryData;
PSTORAGE_DEVICE_DESCRIPTOR DeviceDescriptor;
PUCHAR Buffer;
PFDO_DEVICE_EXTENSION FDODeviceExtension;
UNICODE_STRING SerialNumber;
ANSI_STRING AnsiString;
NTSTATUS Status;
DPRINT1("USBSTOR_HandleQueryProperty\n");
@ -307,6 +311,14 @@ USBSTOR_HandleQueryProperty(
//
PDODeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
ASSERT(PDODeviceExtension);
ASSERT(PDODeviceExtension->Common.IsFDO == FALSE);
//
// get device extension
//
FDODeviceExtension = (PFDO_DEVICE_EXTENSION)PDODeviceExtension->LowerDeviceObject->DeviceExtension;
ASSERT(FDODeviceExtension);
ASSERT(FDODeviceExtension->Common.IsFDO);
//
// get inquiry data
@ -322,14 +334,28 @@ USBSTOR_HandleQueryProperty(
FieldLengthRevision = USBSTOR_GetFieldLength(InquiryData->Revision, 4);
//
// FIXME handle serial number
// is there a serial number
//
if (FDODeviceExtension->SerialNumber)
{
//
// get length
//
FieldLengthSerialNumber = wcslen(FDODeviceExtension->SerialNumber->bString);
}
else
{
//
// no serial number
//
FieldLengthSerialNumber = 0;
}
//
// total length required is sizeof(STORAGE_DEVICE_DESCRIPTOR) + FieldLength + 3 extra null bytes - 1
// total length required is sizeof(STORAGE_DEVICE_DESCRIPTOR) + FieldLength + 4 extra null bytes - 1
// -1 due STORAGE_DEVICE_DESCRIPTOR contains one byte length of parameter data
//
TotalLength = sizeof(STORAGE_DEVICE_DESCRIPTOR) + FieldLengthVendor + FieldLengthProduct + FieldLengthRevision + 2;
TotalLength = sizeof(STORAGE_DEVICE_DESCRIPTOR) + FieldLengthVendor + FieldLengthProduct + FieldLengthRevision + FieldLengthSerialNumber + 3;
//
// check if output buffer is long enough
@ -370,8 +396,8 @@ USBSTOR_HandleQueryProperty(
DeviceDescriptor->VendorIdOffset = sizeof(STORAGE_DEVICE_DESCRIPTOR) - sizeof(UCHAR);
DeviceDescriptor->ProductIdOffset = DeviceDescriptor->VendorIdOffset + FieldLengthVendor + 1;
DeviceDescriptor->ProductRevisionOffset = DeviceDescriptor->ProductIdOffset + FieldLengthProduct + 1;
DeviceDescriptor->SerialNumberOffset = 0; //FIXME
DeviceDescriptor->RawPropertiesLength = FieldLengthVendor + FieldLengthProduct + FieldLengthRevision + 3;
DeviceDescriptor->SerialNumberOffset = (FieldLengthSerialNumber > 0 ? DeviceDescriptor->ProductRevisionOffset + FieldLengthRevision + 1 : 0);
DeviceDescriptor->RawPropertiesLength = FieldLengthVendor + FieldLengthProduct + FieldLengthRevision + FieldLengthSerialNumber + 3 + (FieldLengthSerialNumber > 0 ? + 1 : 0);
//
// copy descriptors
@ -400,12 +426,34 @@ USBSTOR_HandleQueryProperty(
Buffer += FieldLengthRevision + 1;
//
// TODO: copy revision
// copy serial number
//
if (FieldLengthSerialNumber)
{
//
// init unicode string
//
RtlInitUnicodeString(&SerialNumber, FDODeviceExtension->SerialNumber->bString);
//
// init ansi string
//
AnsiString.Buffer = (PCHAR)Buffer;
AnsiString.Length = 0;
AnsiString.MaximumLength = FieldLengthSerialNumber * sizeof(WCHAR);
//
// convert to ansi code
//
Status = RtlUnicodeStringToAnsiString(&AnsiString, &SerialNumber, FALSE);
ASSERT(Status == STATUS_SUCCESS);
}
DPRINT("Vendor %s\n", (LPCSTR)((ULONG_PTR)DeviceDescriptor + DeviceDescriptor->VendorIdOffset));
DPRINT("Product %s\n", (LPCSTR)((ULONG_PTR)DeviceDescriptor + DeviceDescriptor->ProductIdOffset));
DPRINT("Revision %s\n", (LPCSTR)((ULONG_PTR)DeviceDescriptor + DeviceDescriptor->ProductRevisionOffset));
DPRINT("Serial %s\n", (LPCSTR)((ULONG_PTR)DeviceDescriptor + DeviceDescriptor->SerialNumberOffset));
//
// done

View file

@ -638,6 +638,7 @@ USBSTOR_PdoHandleQueryInstanceId(
IN OUT PIRP Irp)
{
PPDO_DEVICE_EXTENSION PDODeviceExtension;
PFDO_DEVICE_EXTENSION FDODeviceExtension;
WCHAR Buffer[100];
ULONG Length;
LPWSTR InstanceId;
@ -648,10 +649,27 @@ USBSTOR_PdoHandleQueryInstanceId(
PDODeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
//
// format instance id
// FIXME: retrieve serial number from string device descriptor
// get FDO device extension
//
swprintf(Buffer, L"%s&%d", L"09188212515A", PDODeviceExtension->LUN);
FDODeviceExtension = (PFDO_DEVICE_EXTENSION)PDODeviceExtension->LowerDeviceObject->DeviceExtension;
//
// format instance id
//
if (FDODeviceExtension->SerialNumber)
{
//
// using serial number from device
//
swprintf(Buffer, L"%s&%d", FDODeviceExtension->SerialNumber->bString, PDODeviceExtension->LUN);
}
else
{
//
// FIXME: should use some random value
//
swprintf(Buffer, L"%s&%d", L"00000000", PDODeviceExtension->LUN);
}
//
// calculate length

View file

@ -175,7 +175,7 @@ USBSTOR_QueueAddIrp(
//
// if list is freezed, dont start this packet
//
DPRINT1("IrpListFreeze: %lu IrpPendingCount %lu\n", IrpListFreeze, FDODeviceExtension->IrpPendingCount);
DPRINT("IrpListFreeze: %lu IrpPendingCount %lu\n", IrpListFreeze, FDODeviceExtension->IrpPendingCount);
return (IrpListFreeze || SrbProcessing);
}
@ -503,7 +503,7 @@ USBSTOR_StartIo(
NTSTATUS Status;
BOOLEAN ResetInProgress;
DPRINT1("USBSTOR_StartIo\n");
DPRINT("USBSTOR_StartIo\n");
//
// get FDO device extension

View file

@ -103,7 +103,7 @@ USBSTOR_CSWCompletionRoutine(
PREAD_CAPACITY_DATA CapacityData;
PUFI_CAPACITY_RESPONSE Response;
DPRINT1("USBSTOR_CSWCompletionRoutine Irp %p Ctx %p\n", Irp, Ctx);
DPRINT("USBSTOR_CSWCompletionRoutine Irp %p Ctx %p\n", Irp, Ctx);
//
// access context
@ -280,7 +280,7 @@ USBSTOR_DataCompletionRoutine(
PIRP_CONTEXT Context;
PIO_STACK_LOCATION IoStack;
DPRINT1("USBSTOR_DataCompletionRoutine Irp %p Ctx %p\n", Irp, Ctx);
DPRINT("USBSTOR_DataCompletionRoutine Irp %p Ctx %p\n", Irp, Ctx);
//
// access context
@ -345,7 +345,7 @@ USBSTOR_CBWCompletionRoutine(
UCHAR Code;
USBD_PIPE_HANDLE PipeHandle;
DPRINT1("USBSTOR_CBWCompletionRoutine Irp %p Ctx %p\n", Irp, Ctx);
DPRINT("USBSTOR_CBWCompletionRoutine Irp %p Ctx %p\n", Irp, Ctx);
//
// access context
@ -993,7 +993,7 @@ USBSTOR_SendReadWriteCmd(
Cmd.LogicalBlockByte2 = pCDB->CDB10.LogicalBlockByte2;
Cmd.LogicalBlockByte3 = pCDB->CDB10.LogicalBlockByte3;
DPRINT1("USBSTOR_SendReadWriteCmd BlockAddress %x%x%x%x BlockCount %lu BlockLength %lu\n", Cmd.LogicalBlockByte0, Cmd.LogicalBlockByte1, Cmd.LogicalBlockByte2, Cmd.LogicalBlockByte3, BlockCount, PDODeviceExtension->BlockLength);
DPRINT("USBSTOR_SendReadWriteCmd BlockAddress %x%x%x%x BlockCount %lu BlockLength %lu\n", Cmd.LogicalBlockByte0, Cmd.LogicalBlockByte1, Cmd.LogicalBlockByte2, Cmd.LogicalBlockByte3, BlockCount, PDODeviceExtension->BlockLength);
//
// send request
@ -1081,7 +1081,7 @@ USBSTOR_HandleExecuteSCSI(
//
pCDB = (PCDB)Request->Cdb;
DPRINT1("USBSTOR_HandleExecuteSCSI Operation Code %x\n", pCDB->AsByte[0]);
DPRINT("USBSTOR_HandleExecuteSCSI Operation Code %x\n", pCDB->AsByte[0]);
if (pCDB->AsByte[0] == SCSIOP_READ_CAPACITY)
{
@ -1090,7 +1090,7 @@ USBSTOR_HandleExecuteSCSI(
//
ASSERT(Request->DataBuffer);
DPRINT1("SCSIOP_READ_CAPACITY Length %\n", Request->DataTransferLength);
DPRINT("SCSIOP_READ_CAPACITY Length %\n", Request->DataTransferLength);
Status = USBSTOR_SendCapacityCmd(DeviceObject, Irp);
}
else if (pCDB->MODE_SENSE.OperationCode == SCSIOP_MODE_SENSE)
@ -1106,7 +1106,7 @@ USBSTOR_HandleExecuteSCSI(
}
else if (pCDB->MODE_SENSE.OperationCode == SCSIOP_READ || pCDB->MODE_SENSE.OperationCode == SCSIOP_WRITE)
{
DPRINT1("SCSIOP_READ / SCSIOP_WRITE DataTransferLength %lu\n", Request->DataTransferLength);
DPRINT("SCSIOP_READ / SCSIOP_WRITE DataTransferLength %lu\n", Request->DataTransferLength);
//
// send read / write command
@ -1115,7 +1115,7 @@ USBSTOR_HandleExecuteSCSI(
}
else if (pCDB->AsByte[0] == SCSIOP_MEDIUM_REMOVAL)
{
DPRINT1("SCSIOP_MEDIUM_REMOVAL\n");
DPRINT("SCSIOP_MEDIUM_REMOVAL\n");
//
// just complete the request
@ -1139,7 +1139,7 @@ USBSTOR_HandleExecuteSCSI(
}
else if (pCDB->MODE_SENSE.OperationCode == SCSIOP_TEST_UNIT_READY)
{
DPRINT1("SCSIOP_TEST_UNIT_READY\n");
DPRINT("SCSIOP_TEST_UNIT_READY\n");
//
// send test unit command

View file

@ -108,7 +108,7 @@ USBSTOR_DispatchClose(
//
// function always succeeds ;)
//
DPRINT1("USBSTOR_DispatchScsi\n");
DPRINT("USBSTOR_DispatchClose\n");
Irp->IoStatus.Information = 0;
Irp->IoStatus.Status = STATUS_SUCCESS;
IoCompleteRequest(Irp, IO_NO_INCREMENT);

View file

@ -57,6 +57,7 @@ typedef struct
USB_BUS_INTERFACE_USBDI_V2 BusInterface; // bus interface of device
PUSB_DEVICE_DESCRIPTOR DeviceDescriptor; // usb device descriptor
PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor; // usb configuration descriptor
PUSB_STRING_DESCRIPTOR SerialNumber; // usb serial number
PUSBD_INTERFACE_INFORMATION InterfaceInformation; // usb interface information
USBD_CONFIGURATION_HANDLE ConfigurationHandle; // usb configuration handle
UCHAR BulkInPipeIndex; // bulk in pipe index
@ -82,9 +83,6 @@ typedef struct
ULONG LastLogicBlockAddress; // last block address
}PDO_DEVICE_EXTENSION, *PPDO_DEVICE_EXTENSION;
//
// max lun command identifier
//