[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; return Status;
} }

View file

@ -240,11 +240,15 @@ USBSTOR_HandleQueryProperty(
PSTORAGE_PROPERTY_QUERY PropertyQuery; PSTORAGE_PROPERTY_QUERY PropertyQuery;
PSTORAGE_DESCRIPTOR_HEADER DescriptorHeader; PSTORAGE_DESCRIPTOR_HEADER DescriptorHeader;
PSTORAGE_ADAPTER_DESCRIPTOR AdapterDescriptor; PSTORAGE_ADAPTER_DESCRIPTOR AdapterDescriptor;
ULONG FieldLengthVendor, FieldLengthProduct, FieldLengthRevision, TotalLength; ULONG FieldLengthVendor, FieldLengthProduct, FieldLengthRevision, TotalLength, FieldLengthSerialNumber;
PPDO_DEVICE_EXTENSION PDODeviceExtension; PPDO_DEVICE_EXTENSION PDODeviceExtension;
PUFI_INQUIRY_RESPONSE InquiryData; PUFI_INQUIRY_RESPONSE InquiryData;
PSTORAGE_DEVICE_DESCRIPTOR DeviceDescriptor; PSTORAGE_DEVICE_DESCRIPTOR DeviceDescriptor;
PUCHAR Buffer; PUCHAR Buffer;
PFDO_DEVICE_EXTENSION FDODeviceExtension;
UNICODE_STRING SerialNumber;
ANSI_STRING AnsiString;
NTSTATUS Status;
DPRINT1("USBSTOR_HandleQueryProperty\n"); DPRINT1("USBSTOR_HandleQueryProperty\n");
@ -307,6 +311,14 @@ USBSTOR_HandleQueryProperty(
// //
PDODeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension; PDODeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
ASSERT(PDODeviceExtension); 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 // get inquiry data
@ -322,14 +334,28 @@ USBSTOR_HandleQueryProperty(
FieldLengthRevision = USBSTOR_GetFieldLength(InquiryData->Revision, 4); 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 // -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 // check if output buffer is long enough
@ -370,8 +396,8 @@ USBSTOR_HandleQueryProperty(
DeviceDescriptor->VendorIdOffset = sizeof(STORAGE_DEVICE_DESCRIPTOR) - sizeof(UCHAR); DeviceDescriptor->VendorIdOffset = sizeof(STORAGE_DEVICE_DESCRIPTOR) - sizeof(UCHAR);
DeviceDescriptor->ProductIdOffset = DeviceDescriptor->VendorIdOffset + FieldLengthVendor + 1; DeviceDescriptor->ProductIdOffset = DeviceDescriptor->VendorIdOffset + FieldLengthVendor + 1;
DeviceDescriptor->ProductRevisionOffset = DeviceDescriptor->ProductIdOffset + FieldLengthProduct + 1; DeviceDescriptor->ProductRevisionOffset = DeviceDescriptor->ProductIdOffset + FieldLengthProduct + 1;
DeviceDescriptor->SerialNumberOffset = 0; //FIXME DeviceDescriptor->SerialNumberOffset = (FieldLengthSerialNumber > 0 ? DeviceDescriptor->ProductRevisionOffset + FieldLengthRevision + 1 : 0);
DeviceDescriptor->RawPropertiesLength = FieldLengthVendor + FieldLengthProduct + FieldLengthRevision + 3; DeviceDescriptor->RawPropertiesLength = FieldLengthVendor + FieldLengthProduct + FieldLengthRevision + FieldLengthSerialNumber + 3 + (FieldLengthSerialNumber > 0 ? + 1 : 0);
// //
// copy descriptors // copy descriptors
@ -400,12 +426,34 @@ USBSTOR_HandleQueryProperty(
Buffer += FieldLengthRevision + 1; 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("Vendor %s\n", (LPCSTR)((ULONG_PTR)DeviceDescriptor + DeviceDescriptor->VendorIdOffset));
DPRINT("Product %s\n", (LPCSTR)((ULONG_PTR)DeviceDescriptor + DeviceDescriptor->ProductIdOffset)); DPRINT("Product %s\n", (LPCSTR)((ULONG_PTR)DeviceDescriptor + DeviceDescriptor->ProductIdOffset));
DPRINT("Revision %s\n", (LPCSTR)((ULONG_PTR)DeviceDescriptor + DeviceDescriptor->ProductRevisionOffset)); DPRINT("Revision %s\n", (LPCSTR)((ULONG_PTR)DeviceDescriptor + DeviceDescriptor->ProductRevisionOffset));
DPRINT("Serial %s\n", (LPCSTR)((ULONG_PTR)DeviceDescriptor + DeviceDescriptor->SerialNumberOffset));
// //
// done // done

View file

@ -638,6 +638,7 @@ USBSTOR_PdoHandleQueryInstanceId(
IN OUT PIRP Irp) IN OUT PIRP Irp)
{ {
PPDO_DEVICE_EXTENSION PDODeviceExtension; PPDO_DEVICE_EXTENSION PDODeviceExtension;
PFDO_DEVICE_EXTENSION FDODeviceExtension;
WCHAR Buffer[100]; WCHAR Buffer[100];
ULONG Length; ULONG Length;
LPWSTR InstanceId; LPWSTR InstanceId;
@ -648,10 +649,27 @@ USBSTOR_PdoHandleQueryInstanceId(
PDODeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension; PDODeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
// //
// format instance id // get FDO device extension
// FIXME: retrieve serial number from string device descriptor
// //
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 // calculate length

View file

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

View file

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

View file

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

View file

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