ReactOS  0.4.15-dev-2329-g3ad573f
usbdlib.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _USBD_INTERFACE_LIST_ENTRY
 

Macros

#define DECLSPEC_EXPORT   __declspec(dllexport)
 
#define UsbBuildInterruptOrBulkTransferRequest(urb, length, pipeHandle, transferBuffer, transferBufferMDL, transferBufferLength, transferFlags, link)
 
#define UsbBuildGetDescriptorRequest(urb, length, descriptorType, descriptorIndex, languageId, transferBuffer, transferBufferMDL, transferBufferLength, link)
 
#define UsbBuildGetStatusRequest(urb, op, index, transferBuffer, transferBufferMDL, link)
 
#define UsbBuildFeatureRequest(urb, op, featureSelector, index, link)
 
#define UsbBuildSelectConfigurationRequest(urb, length, configurationDescriptor)
 
#define UsbBuildSelectInterfaceRequest(urb, length, configurationHandle, interfaceNumber, alternateSetting)
 
#define UsbBuildVendorRequest(urb, cmd, length, transferFlags, reservedbits, request, value, index, transferBuffer, transferBufferMDL, transferBufferLength, link)
 
#define UsbBuildOsFeatureDescriptorRequest(urb, length, interface, index, transferBuffer, transferBufferMDL, transferBufferLength, link)
 
#define USBD_CLIENT_CONTRACT_VERSION_INVALID   0xFFFFFFFF
 
#define USBD_CLIENT_CONTRACT_VERSION_602   0x602
 
#define USBD_INTERFACE_VERSION_600   0x600
 
#define USBD_INTERFACE_VERSION_602   0x602
 
#define USBD_INTERFACE_VERSION_603   0x603
 
#define URB_STATUS(urb)   ((urb)->UrbHeader.Status)
 
#define GET_SELECT_CONFIGURATION_REQUEST_SIZE(totalInterfaces, totalPipes)
 
#define GET_SELECT_INTERFACE_REQUEST_SIZE(totalPipes)
 
#define GET_USBD_INTERFACE_SIZE(numEndpoints)
 
#define GET_ISO_URB_SIZE(n)
 

Typedefs

typedef struct _USBD_INTERFACE_LIST_ENTRY USBD_INTERFACE_LIST_ENTRY
 
typedef struct _USBD_INTERFACE_LIST_ENTRYPUSBD_INTERFACE_LIST_ENTRY
 

Functions

 DECLARE_HANDLE (USBD_HANDLE)
 
 _IRQL_requires_max_ (DISPATCH_LEVEL) DECLSPEC_IMPORT VOID NTAPI USBD_GetUSBDIVersion(_Out_ PUSBD_VERSION_INFORMATION VersionInformation)
 
DECLSPEC_IMPORT PUSB_INTERFACE_DESCRIPTOR NTAPI USBD_ParseConfigurationDescriptor (_In_ PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor, _In_ UCHAR InterfaceNumber, _In_ UCHAR AlternateSetting)
 
DECLSPEC_IMPORT PURB NTAPI USBD_CreateConfigurationRequest (_In_ PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor, _Out_ PUSHORT Siz)
 
 _IRQL_requires_max_ (APC_LEVEL) DECLSPEC_IMPORT PUSB_COMMON_DESCRIPTOR NTAPI USBD_ParseDescriptors(_In_ PVOID DescriptorBuffer
 
 _IRQL_requires_max_ (PASSIVE_LEVEL) DECLSPEC_EXPORT ULONG NTAPI USBD_GetInterfaceLength(_In_ PUSB_INTERFACE_DESCRIPTOR InterfaceDescriptor
 
 _Inout_updates_bytes_ (ParameterLength) PVOID Parameter
 
_In_ ULONG _In_reads_bytes_ (KeyNameLength) PWSTR KeyName
 
DECLSPEC_EXPORT NTSTATUS NTAPI USBD_QueryBusTime (_In_ PDEVICE_OBJECT RootHubPdo, _Out_ PULONG CurrentFrame)
 

Variables

_In_ ULONG TotalLength
 
_In_ ULONG _In_ PVOID StartPosition
 
_In_ ULONG _In_ PVOID _In_ LONG DescriptorType
 
_In_ PVOID _In_ LONG InterfaceNumber
 
_In_ PVOID _In_ LONG _In_ LONG AlternateSetting
 
_In_ PVOID _In_ LONG _In_ LONG _In_ LONG InterfaceClass
 
_In_ PVOID _In_ LONG _In_ LONG _In_ LONG _In_ LONG InterfaceSubClass
 
_In_ PVOID _In_ LONG _In_ LONG _In_ LONG _In_ LONG _In_ LONG InterfaceProtocol
 
_In_ PUSBD_INTERFACE_LIST_ENTRY InterfaceList
 
_In_ PUCHAR BufferEnd
 
_In_ PDEVICE_OBJECT FilterDeviceObject
 
_In_ ULONG ParameterLength
 
_In_ ULONG _In_ ULONG KeyNameLength
 
_In_ UCHAR EndpointType
 
_In_ UCHAR _In_ BOOLEAN LowSpeed
 
_In_ ULONG BufferLength
 
_In_ ULONG _In_ USHORT Level
 
_In_ ULONG _In_ USHORT _Out_ PUCHAROffset
 
_In_ ULONG _In_ USHORT _Out_ PUCHAR _In_opt_ ULONG Tag
 

Macro Definition Documentation

◆ DECLSPEC_EXPORT

#define DECLSPEC_EXPORT   __declspec(dllexport)

Definition at line 4 of file usbdlib.h.

◆ GET_ISO_URB_SIZE

#define GET_ISO_URB_SIZE (   n)
Value:
(sizeof(struct _URB_ISOCH_TRANSFER)+ \
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList
GLdouble n
Definition: glext.h:7729

Definition at line 125 of file usbdlib.h.

◆ GET_SELECT_CONFIGURATION_REQUEST_SIZE

#define GET_SELECT_CONFIGURATION_REQUEST_SIZE (   totalInterfaces,
  totalPipes 
)
Value:
(sizeof(struct _URB_SELECT_CONFIGURATION) + \
((totalInterfaces-1) * sizeof(USBD_INTERFACE_INFORMATION)) + \
((totalPipes-totalInterfaces)*sizeof(USBD_PIPE_INFORMATION)))
struct _USBD_INTERFACE_INFORMATION USBD_INTERFACE_INFORMATION

Definition at line 112 of file usbdlib.h.

◆ GET_SELECT_INTERFACE_REQUEST_SIZE

#define GET_SELECT_INTERFACE_REQUEST_SIZE (   totalPipes)
Value:
(sizeof(struct _URB_SELECT_INTERFACE) + \
((totalPipes-1)*sizeof(USBD_PIPE_INFORMATION)))
struct _USBD_PIPE_INFORMATION USBD_PIPE_INFORMATION

Definition at line 117 of file usbdlib.h.

◆ GET_USBD_INTERFACE_SIZE

#define GET_USBD_INTERFACE_SIZE (   numEndpoints)
Value:
(sizeof(USBD_PIPE_INFORMATION)*(numEndpoints)) - sizeof(USBD_PIPE_INFORMATION))
struct _USBD_INTERFACE_INFORMATION USBD_INTERFACE_INFORMATION
struct _USBD_PIPE_INFORMATION USBD_PIPE_INFORMATION

Definition at line 121 of file usbdlib.h.

◆ URB_STATUS

#define URB_STATUS (   urb)    ((urb)->UrbHeader.Status)

Definition at line 110 of file usbdlib.h.

◆ UsbBuildFeatureRequest

#define UsbBuildFeatureRequest (   urb,
  op,
  featureSelector,
  index,
  link 
)
Value:
{ \
(urb)->UrbHeader.Function = (op); \
(urb)->UrbHeader.Length = sizeof(struct _URB_CONTROL_FEATURE_REQUEST); \
(urb)->UrbControlFeatureRequest.FeatureSelector = (featureSelector); \
(urb)->UrbControlFeatureRequest.Index = (index); \
(urb)->UrbControlFeatureRequest.UrbLink = (link); \
}
GLuint index
Definition: glext.h:6031
UINT op
Definition: effect.c:236
const WCHAR * link
Definition: db.cpp:989

Definition at line 45 of file usbdlib.h.

◆ UsbBuildGetDescriptorRequest

#define UsbBuildGetDescriptorRequest (   urb,
  length,
  descriptorType,
  descriptorIndex,
  languageId,
  transferBuffer,
  transferBufferMDL,
  transferBufferLength,
  link 
)
Value:
{ \
(urb)->UrbHeader.Function = URB_FUNCTION_GET_DESCRIPTOR_FROM_DEVICE; \
(urb)->UrbHeader.Length = (length); \
(urb)->UrbControlDescriptorRequest.TransferBufferLength = (transferBufferLength); \
(urb)->UrbControlDescriptorRequest.TransferBufferMDL = (transferBufferMDL); \
(urb)->UrbControlDescriptorRequest.TransferBuffer = (transferBuffer); \
(urb)->UrbControlDescriptorRequest.DescriptorType = (descriptorType); \
(urb)->UrbControlDescriptorRequest.Index = (descriptorIndex); \
(urb)->UrbControlDescriptorRequest.LanguageId = (languageId); \
(urb)->UrbControlDescriptorRequest.UrbLink = (link); \
}
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
#define URB_FUNCTION_GET_DESCRIPTOR_FROM_DEVICE
Definition: usb.h:97
const WCHAR * link
Definition: db.cpp:989

Definition at line 23 of file usbdlib.h.

◆ UsbBuildGetStatusRequest

#define UsbBuildGetStatusRequest (   urb,
  op,
  index,
  transferBuffer,
  transferBufferMDL,
  link 
)
Value:
{ \
(urb)->UrbHeader.Function = (op); \
(urb)->UrbHeader.Length = sizeof(struct _URB_CONTROL_GET_STATUS_REQUEST); \
(urb)->UrbControlGetStatusRequest.TransferBufferLength = sizeof(USHORT); \
(urb)->UrbControlGetStatusRequest.TransferBufferMDL = (transferBufferMDL); \
(urb)->UrbControlGetStatusRequest.TransferBuffer = (transferBuffer); \
(urb)->UrbControlGetStatusRequest.Index = (index); \
(urb)->UrbControlGetStatusRequest.UrbLink = (link); \
}
GLuint index
Definition: glext.h:6031
UINT op
Definition: effect.c:236
unsigned short USHORT
Definition: pedump.c:61
const WCHAR * link
Definition: db.cpp:989

Definition at line 35 of file usbdlib.h.

◆ UsbBuildInterruptOrBulkTransferRequest

#define UsbBuildInterruptOrBulkTransferRequest (   urb,
  length,
  pipeHandle,
  transferBuffer,
  transferBufferMDL,
  transferBufferLength,
  transferFlags,
  link 
)
Value:
{ \
(urb)->UrbHeader.Function = URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER; \
(urb)->UrbHeader.Length = (length); \
(urb)->UrbBulkOrInterruptTransfer.PipeHandle = (pipeHandle); \
(urb)->UrbBulkOrInterruptTransfer.TransferBufferLength = (transferBufferLength); \
(urb)->UrbBulkOrInterruptTransfer.TransferBufferMDL = (transferBufferMDL); \
(urb)->UrbBulkOrInterruptTransfer.TransferBuffer = (transferBuffer); \
(urb)->UrbBulkOrInterruptTransfer.TransferFlags = (transferFlags); \
(urb)->UrbBulkOrInterruptTransfer.UrbLink = (link); \
}
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
const WCHAR * link
Definition: db.cpp:989
#define URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER
Definition: usb.h:95

Definition at line 12 of file usbdlib.h.

◆ UsbBuildOsFeatureDescriptorRequest

#define UsbBuildOsFeatureDescriptorRequest (   urb,
  length,
  interface,
  index,
  transferBuffer,
  transferBufferMDL,
  transferBufferLength,
  link 
)
Value:
{ \
(urb)->UrbHeader.Function = URB_FUNCTION_GET_MS_FEATURE_DESCRIPTOR; \
(urb)->UrbHeader.Length = (length); \
(urb)->UrbOSFeatureDescriptorRequest.TransferBufferLength = (transferBufferLength); \
(urb)->UrbOSFeatureDescriptorRequest.TransferBufferMDL = (transferBufferMDL); \
(urb)->UrbOSFeatureDescriptorRequest.TransferBuffer = (transferBuffer); \
(urb)->UrbOSFeatureDescriptorRequest.InterfaceNumber = (interface); \
(urb)->UrbOSFeatureDescriptorRequest.MS_FeatureDescriptorIndex = (index); \
(urb)->UrbOSFeatureDescriptorRequest.UrbLink = (link); \
}
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
GLuint index
Definition: glext.h:6031
#define interface
Definition: basetyps.h:61
const WCHAR * link
Definition: db.cpp:989

Definition at line 84 of file usbdlib.h.

◆ UsbBuildSelectConfigurationRequest

#define UsbBuildSelectConfigurationRequest (   urb,
  length,
  configurationDescriptor 
)
Value:
{ \
(urb)->UrbHeader.Function = URB_FUNCTION_SELECT_CONFIGURATION; \
(urb)->UrbHeader.Length = (length); \
(urb)->UrbSelectConfiguration.ConfigurationDescriptor = (configurationDescriptor); \
}
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
#define URB_FUNCTION_SELECT_CONFIGURATION
Definition: usb.h:86

Definition at line 53 of file usbdlib.h.

◆ UsbBuildSelectInterfaceRequest

#define UsbBuildSelectInterfaceRequest (   urb,
  length,
  configurationHandle,
  interfaceNumber,
  alternateSetting 
)
Value:
{ \
(urb)->UrbHeader.Function = URB_FUNCTION_SELECT_INTERFACE; \
(urb)->UrbHeader.Length = (length); \
(urb)->UrbSelectInterface.Interface.AlternateSetting = (alternateSetting); \
(urb)->UrbSelectInterface.Interface.InterfaceNumber = (interfaceNumber); \
(urb)->UrbSelectInterface.Interface.Length = (length - sizeof(struct _URB_HEADER) - sizeof(USBD_CONFIGURATION_HANDLE)); \
(urb)->UrbSelectInterface.ConfigurationHandle = (configurationHandle); \
}
PVOID USBD_CONFIGURATION_HANDLE
Definition: usb.h:230
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
#define URB_FUNCTION_SELECT_INTERFACE
Definition: usb.h:87

Definition at line 59 of file usbdlib.h.

◆ UsbBuildVendorRequest

#define UsbBuildVendorRequest (   urb,
  cmd,
  length,
  transferFlags,
  reservedbits,
  request,
  value,
  index,
  transferBuffer,
  transferBufferMDL,
  transferBufferLength,
  link 
)
Value:
{ \
(urb)->UrbHeader.Function = cmd; \
(urb)->UrbHeader.Length = (length); \
(urb)->UrbControlVendorClassRequest.TransferBufferLength = (transferBufferLength); \
(urb)->UrbControlVendorClassRequest.TransferBufferMDL = (transferBufferMDL); \
(urb)->UrbControlVendorClassRequest.TransferBuffer = (transferBuffer); \
(urb)->UrbControlVendorClassRequest.RequestTypeReservedBits = (reservedbits); \
(urb)->UrbControlVendorClassRequest.Request = (request); \
(urb)->UrbControlVendorClassRequest.Value = (value); \
(urb)->UrbControlVendorClassRequest.Index = (index); \
(urb)->UrbControlVendorClassRequest.TransferFlags = (transferFlags); \
(urb)->UrbControlVendorClassRequest.UrbLink = (link); \
}
Definition: pdh_main.c:93
Definition: ftp_var.h:139
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
GLuint index
Definition: glext.h:6031
Definition: tftpd.h:85
const WCHAR * link
Definition: db.cpp:989

Definition at line 68 of file usbdlib.h.

◆ USBD_CLIENT_CONTRACT_VERSION_602

#define USBD_CLIENT_CONTRACT_VERSION_602   0x602

Definition at line 100 of file usbdlib.h.

◆ USBD_CLIENT_CONTRACT_VERSION_INVALID

#define USBD_CLIENT_CONTRACT_VERSION_INVALID   0xFFFFFFFF

Definition at line 99 of file usbdlib.h.

◆ USBD_INTERFACE_VERSION_600

#define USBD_INTERFACE_VERSION_600   0x600

Definition at line 102 of file usbdlib.h.

◆ USBD_INTERFACE_VERSION_602

#define USBD_INTERFACE_VERSION_602   0x602

Definition at line 103 of file usbdlib.h.

◆ USBD_INTERFACE_VERSION_603

#define USBD_INTERFACE_VERSION_603   0x603

Definition at line 104 of file usbdlib.h.

Typedef Documentation

◆ PUSBD_INTERFACE_LIST_ENTRY

◆ USBD_INTERFACE_LIST_ENTRY

Function Documentation

◆ _In_reads_bytes_()

_In_ ULONG _In_reads_bytes_ ( KeyNameLength  )

◆ _Inout_updates_bytes_()

_Inout_updates_bytes_ ( ParameterLength  )

◆ _IRQL_requires_max_() [1/3]

_IRQL_requires_max_ ( DISPATCH_LEVEL  )

Definition at line 3557 of file common.c.

3587 {
3588  NTSTATUS status;
3589  BOOLEAN requestSent = FALSE;
3590 
3591  BOOLEAN shouldRetry = TRUE;
3592  PCDB cdb = (PCDB)DeviceExtension->PowerContext.Srb.Cdb;
3593  ULONG timeoutValue = DeviceExtension->TimeOutValue;
3594  ULONG retryCount = 1;
3595 
3596  // reset some fields.
3597  DeviceExtension->PowerContext.RetryIntervalIn100ns = 0;
3598  status = PowerContextReuseRequest(DeviceExtension);
3599  RequestClearSendTime(DeviceExtension->PowerContext.PowerRequest);
3600 
3601  if (!NT_SUCCESS(status))
3602  {
3603  return status;
3604  }
3605 
3606  // set proper timeout value and max retry count.
3607  switch(DeviceExtension->PowerContext.PowerChangeState.PowerDown)
3608  {
3612  break;
3613 
3614  case PowerDownDeviceLocked:
3615  // Case of issuing SYNC CACHE command. Do not use power irp timeout remaining time in this case
3616  // as we want to give best try on SYNC CACHE command.
3617  retryCount = MAXIMUM_RETRIES;
3618  timeoutValue = DeviceExtension->TimeOutValue;
3619  break;
3620 
3622  {
3623  // Case of issuing STOP UNIT command
3624  // As "Imme" bit is set to '1', this command should be completed in short time.
3625  // This command is at low importance, failure of this command has very small impact.
3626  ULONG secondsRemaining = 0;
3627 
3628 #if (WINVER >= 0x0601)
3629  // this API is introduced in Windows7
3630  PoQueryWatchdogTime(DeviceExtension->LowerPdo, &secondsRemaining);
3631 #endif
3632 
3633  if (secondsRemaining == 0)
3634  {
3635  // not able to retrieve remaining time from PoQueryWatchdogTime API, use default values.
3636  retryCount = MAXIMUM_RETRIES;
3637  timeoutValue = SCSI_CDROM_TIMEOUT;
3638  }
3639  else
3640  {
3641  // plan to leave about 30 seconds to lower level drivers if possible.
3642  if (secondsRemaining >= 32)
3643  {
3644  retryCount = (secondsRemaining - 30)/SCSI_CDROM_TIMEOUT + 1;
3645  timeoutValue = SCSI_CDROM_TIMEOUT;
3646 
3647  if (retryCount > MAXIMUM_RETRIES)
3648  {
3649  retryCount = MAXIMUM_RETRIES;
3650  }
3651 
3652  if (retryCount == 1)
3653  {
3654  timeoutValue = secondsRemaining - 30;
3655  }
3656  }
3657  else
3658  {
3659  // issue the command with minimal timeout value and do not retry on it.
3660  retryCount = 1;
3661  timeoutValue = 2;
3662  }
3663  }
3664  }
3665  break;
3666  default:
3667  NT_ASSERT( FALSE );
3669  return status;
3670  }
3671 
3672  DeviceExtension->PowerContext.RetryCount = retryCount;
3673 
3674  // issue command.
3675  while (shouldRetry)
3676  {
3677 
3678  // set SRB fields.
3679  DeviceExtension->PowerContext.Srb.SrbFlags = SRB_FLAGS_NO_DATA_TRANSFER |
3684 
3685  DeviceExtension->PowerContext.Srb.Function = SRB_FUNCTION_EXECUTE_SCSI;
3686  DeviceExtension->PowerContext.Srb.TimeOutValue = timeoutValue;
3687 
3688  if (DeviceExtension->PowerContext.PowerChangeState.PowerDown == PowerDownDeviceInitial)
3689  {
3690  DeviceExtension->PowerContext.Srb.Function = SRB_FUNCTION_LOCK_QUEUE;
3691  }
3692  else if (DeviceExtension->PowerContext.PowerChangeState.PowerDown == PowerDownDeviceLocked)
3693  {
3694  DeviceExtension->PowerContext.Srb.Function = SRB_FUNCTION_QUIESCE_DEVICE;
3695  }
3696  else if (DeviceExtension->PowerContext.PowerChangeState.PowerDown == PowerDownDeviceQuiesced)
3697  {
3698  // Case of issuing SYNC CACHE command.
3699  DeviceExtension->PowerContext.Srb.CdbLength = 10;
3700  cdb->SYNCHRONIZE_CACHE10.OperationCode = SCSIOP_SYNCHRONIZE_CACHE;
3701  }
3702  else if (DeviceExtension->PowerContext.PowerChangeState.PowerDown == PowerDownDeviceFlushed)
3703  {
3704  // Case of issuing STOP UNIT command.
3705  DeviceExtension->PowerContext.Srb.CdbLength = 6;
3706  cdb->START_STOP.OperationCode = SCSIOP_START_STOP_UNIT;
3707  cdb->START_STOP.Start = 0;
3708  cdb->START_STOP.Immediate = 1;
3709  }
3710  else if (DeviceExtension->PowerContext.PowerChangeState.PowerDown == PowerDownDeviceStopped)
3711  {
3712  DeviceExtension->PowerContext.Srb.Function = SRB_FUNCTION_UNLOCK_QUEUE;
3713  }
3714 
3715  // Set up completion routine and context if requested
3716  if (CompletionRoutine)
3717  {
3718  WdfRequestSetCompletionRoutine(DeviceExtension->PowerContext.PowerRequest,
3720  Context);
3721  }
3722 
3723  status = RequestSend(DeviceExtension,
3724  DeviceExtension->PowerContext.PowerRequest,
3725  DeviceExtension->IoTarget,
3727  &requestSent);
3728 
3729  if (requestSent)
3730  {
3731  if ((CompletionRoutine == NULL) &&
3732  (SRB_STATUS(DeviceExtension->PowerContext.Srb.SrbStatus) != SRB_STATUS_SUCCESS))
3733  {
3734  TracePrint((TRACE_LEVEL_ERROR,
3735  TRACE_FLAG_POWER,
3736  "%p\tError occured when issuing %s command to device. Srb %p, Status %x\n",
3737  DeviceExtension->PowerContext.PowerRequest,
3738  (DeviceExtension->PowerContext.PowerChangeState.PowerDown == PowerDownDeviceQuiesced) ? "SYNC CACHE" : "STOP UNIT",
3739  &DeviceExtension->PowerContext.Srb,
3740  DeviceExtension->PowerContext.Srb.SrbStatus));
3741 
3742  NT_ASSERT(!(TEST_FLAG(DeviceExtension->PowerContext.Srb.SrbStatus, SRB_STATUS_QUEUE_FROZEN)));
3743 
3744  shouldRetry = RequestSenseInfoInterpret(DeviceExtension,
3745  DeviceExtension->PowerContext.PowerRequest,
3746  &(DeviceExtension->PowerContext.Srb),
3747  retryCount - DeviceExtension->PowerContext.RetryCount,
3748  &status,
3749  &(DeviceExtension->PowerContext.RetryIntervalIn100ns));
3750 
3751  if (shouldRetry && (DeviceExtension->PowerContext.RetryCount-- == 0))
3752  {
3753  shouldRetry = FALSE;
3754  }
3755  }
3756  else
3757  {
3758  // succeeded, do not need to retry.
3759  shouldRetry = FALSE;
3760  }
3761 
3762  }
3763  else
3764  {
3765  // request failed to be sent
3766  shouldRetry = FALSE;
3767  }
3768 
3769  if (shouldRetry)
3770  {
3771  LARGE_INTEGER t;
3772  t.QuadPart = -DeviceExtension->PowerContext.RetryIntervalIn100ns;
3774 
3775  status = PowerContextReuseRequest(DeviceExtension);
3776  if (!NT_SUCCESS(status))
3777  {
3778  shouldRetry = FALSE;
3779  }
3780  }
3781  }
3782 
3783  if (DeviceExtension->PowerContext.PowerChangeState.PowerDown == PowerDownDeviceQuiesced)
3784  {
3785  // record SYNC CACHE command completion time stamp.
3786  KeQueryTickCount(&DeviceExtension->PowerContext.Step1CompleteTime);
3787  }
3788 
3789  return status;
3790 }
#define SRB_FUNCTION_UNLOCK_QUEUE
Definition: srb.h:325
#define SCSIOP_SYNCHRONIZE_CACHE
Definition: cdrw_hw.h:918
#define SRB_FUNCTION_QUIESCE_DEVICE
Definition: srb.h:90
#define SRB_FLAGS_NO_QUEUE_FREEZE
Definition: srb.h:396
#define TRUE
Definition: types.h:120
Definition: cdrw_hw.h:28
LONG NTSTATUS
Definition: precomp.h:26
struct _CDB::_SYNCHRONIZE_CACHE10 SYNCHRONIZE_CACHE10
GLdouble GLdouble t
Definition: gl.h:2047
#define SRB_STATUS(Status)
Definition: srb.h:381
VOID RequestClearSendTime(_In_ WDFREQUEST Request)
Definition: common.c:111
#define MAXIMUM_RETRIES
Definition: cdrom.h:124
return STATUS_NOT_IMPLEMENTED
#define SCSI_CDROM_TIMEOUT
Definition: cdrom.c:170
#define FALSE
Definition: types.h:117
NTSTATUS NTAPI KeDelayExecutionThread(IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Interval OPTIONAL)
Definition: wait.c:283
#define SRB_FLAGS_BYPASS_LOCKED_QUEUE
Definition: srb.h:402
unsigned char BOOLEAN
union _CDB * PCDB
struct _CDB::_START_STOP START_STOP
VOID NTAPI KeQueryTickCount(IN PLARGE_INTEGER TickCount)
Definition: clock.c:165
#define TEST_FLAG(Flags, Bit)
Definition: cdrom.h:1495
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define SRB_FLAGS_DISABLE_SYNCH_TRANSFER
Definition: srb.h:389
#define SRB_FLAGS_NO_DATA_TRANSFER
Definition: srb.h:394
BOOLEAN RequestSenseInfoInterpret(_In_ PCDROM_DEVICE_EXTENSION DeviceExtension, _In_ WDFREQUEST Request, _In_ PSCSI_REQUEST_BLOCK Srb, _In_ ULONG RetriedCount, _Out_ NTSTATUS *Status, _Out_opt_ _Deref_out_range_(0, MAXIMUM_RETRY_FOR_SINGLE_IO_IN_100NS_UNITS) LONGLONG *RetryIntervalIn100ns)
Definition: sense.c:2467
#define SRB_STATUS_QUEUE_FROZEN
Definition: srb.h:378
NTSTATUS RequestSend(_In_ PCDROM_DEVICE_EXTENSION DeviceExtension, _In_ WDFREQUEST Request, _In_ WDFIOTARGET IoTarget, _In_ ULONG Flags, _Out_opt_ PBOOLEAN RequestSent)
Definition: common.c:3793
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
_In_ WDFREQUEST _In_opt_ PFN_WDF_REQUEST_COMPLETION_ROUTINE CompletionRoutine
Definition: wdfrequest.h:893
#define NULL
Definition: types.h:112
#define SRB_FUNCTION_EXECUTE_SCSI
Definition: srb.h:307
unsigned int ULONG
Definition: retypes.h:1
#define SRB_STATUS_SUCCESS
Definition: srb.h:333
#define SRB_FLAGS_D3_PROCESSING
Definition: srb.h:156
static SERVICE_STATUS status
Definition: service.c:31
#define SCSIOP_START_STOP_UNIT
Definition: cdrw_hw.h:897
#define SRB_FUNCTION_LOCK_QUEUE
Definition: srb.h:324
#define NT_ASSERT
Definition: rtlfuncs.h:3312
Definition: ps.c:97

◆ _IRQL_requires_max_() [2/3]

_IRQL_requires_max_ ( APC_LEVEL  )

Definition at line 197 of file cddata.c.

254 {
255  THREAD_CONTEXT ThreadContext = {0};
256  PIRP_CONTEXT IrpContext = NULL;
257  BOOLEAN Wait;
258 
259 #ifdef CD_SANITY
260  PVOID PreviousTopLevel;
261 #endif
262 
264 
265 #if DBG
266 
267  KIRQL SaveIrql = KeGetCurrentIrql();
268 
269 #endif
270 
272 
274 
276 
277 #ifdef CD_SANITY
278  PreviousTopLevel = IoGetTopLevelIrp();
279 #endif
280 
281  //
282  // Loop until this request has been completed or posted.
283  //
284 
285  do {
286 
287  //
288  // Use a try-except to handle the exception cases.
289  //
290 
291  _SEH2_TRY {
292 
293  //
294  // If the IrpContext is NULL then this is the first pass through
295  // this loop.
296  //
297 
298  if (IrpContext == NULL) {
299 
300  //
301  // Decide if this request is waitable an allocate the IrpContext.
302  // If the file object in the stack location is NULL then this
303  // is a mount which is always waitable. Otherwise we look at
304  // the file object flags.
305  //
306 
308 
309  Wait = TRUE;
310 
311  } else {
312 
313  Wait = CanFsdWait( Irp );
314  }
315 
316  IrpContext = CdCreateIrpContext( Irp, Wait );
317 
318  //
319  // Update the thread context information.
320  //
321 
322  CdSetThreadContext( IrpContext, &ThreadContext );
323 
324 #ifdef CD_SANITY
325  NT_ASSERT( !CdTestTopLevel ||
326  SafeNodeType( IrpContext->TopLevel ) == CDFS_NTC_IRP_CONTEXT );
327 #endif
328 
329  //
330  // Otherwise cleanup the IrpContext for the retry.
331  //
332 
333  } else {
334 
335  //
336  // Set the MORE_PROCESSING flag to make sure the IrpContext
337  // isn't inadvertently deleted here. Then cleanup the
338  // IrpContext to perform the retry.
339  //
340 
341  SetFlag( IrpContext->Flags, IRP_CONTEXT_FLAG_MORE_PROCESSING );
342  CdCleanupIrpContext( IrpContext, FALSE );
343  }
344 
345  //
346  // Case on the major irp code.
347  //
348 
349  switch (IrpContext->MajorFunction) {
350 
351  case IRP_MJ_CREATE :
352 
353  Status = CdCommonCreate( IrpContext, Irp );
354  break;
355 
356  case IRP_MJ_CLOSE :
357 
358  Status = CdCommonClose( IrpContext, Irp );
359  break;
360 
361  case IRP_MJ_READ :
362 
363  //
364  // If this is an Mdl complete request, don't go through
365  // common read.
366  //
367 
368  if (FlagOn( IrpContext->MinorFunction, IRP_MN_COMPLETE )) {
369 
370  Status = CdCompleteMdl( IrpContext, Irp );
371 
372  } else {
373 
374  Status = CdCommonRead( IrpContext, Irp );
375  }
376 
377  break;
378 
379  case IRP_MJ_WRITE :
380 
381  Status = CdCommonWrite( IrpContext, Irp );
382  break;
383 
385 
386  Status = CdCommonQueryInfo( IrpContext, Irp );
387  break;
388 
390 
391  Status = CdCommonSetInfo( IrpContext, Irp );
392  break;
393 
395 
396  Status = CdCommonQueryVolInfo( IrpContext, Irp );
397  break;
398 
400 
401  Status = CdCommonDirControl( IrpContext, Irp );
402  break;
403 
405 
406  Status = CdCommonFsControl( IrpContext, Irp );
407  break;
408 
409  case IRP_MJ_DEVICE_CONTROL :
410 
411  Status = CdCommonDevControl( IrpContext, Irp );
412  break;
413 
414  case IRP_MJ_LOCK_CONTROL :
415 
416  Status = CdCommonLockControl( IrpContext, Irp );
417  break;
418 
419  case IRP_MJ_CLEANUP :
420 
421  Status = CdCommonCleanup( IrpContext, Irp );
422  break;
423 
424  case IRP_MJ_PNP :
425 
426  Status = CdCommonPnp( IrpContext, Irp );
427  break;
428 
429  case IRP_MJ_SHUTDOWN :
430 
431  Status = CdCommonShutdown( IrpContext, Irp );
432  break;
433 
434  default :
435 
437  CdCompleteRequest( IrpContext, Irp, Status );
438  }
439 
441 
442  Status = CdProcessException( IrpContext, Irp, _SEH2_GetExceptionCode() );
443  } _SEH2_END;
444 
445  } while (Status == STATUS_CANT_WAIT);
446 
447 #ifdef CD_SANITY
448  NT_ASSERT( !CdTestTopLevel ||
449  (PreviousTopLevel == IoGetTopLevelIrp()) );
450 #endif
451 
453 
454  NT_ASSERT( SaveIrql == KeGetCurrentIrql( ));
455 
456  return Status;
457 }
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
VOID CdSetThreadContext(_Inout_ PIRP_CONTEXT IrpContext, _In_ PTHREAD_CONTEXT ThreadContext)
Definition: cddata.c:981
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
#define FsRtlEnterFileSystem
#define FsRtlExitFileSystem
#define IRP_MJ_SHUTDOWN
#define TRUE
Definition: types.h:120
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
#define IRP_CONTEXT_FLAG_MORE_PROCESSING
Definition: cdstruc.h:1214
_In_ WDFDPC _In_ BOOLEAN Wait
Definition: wdfdpc.h:167
#define SafeNodeType(Ptr)
Definition: nodetype.h:54
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
LONG NTSTATUS
Definition: precomp.h:26
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
_SEH2_TRY
Definition: create.c:4226
#define IRP_MN_COMPLETE
Definition: iotypes.h:4419
UCHAR KIRQL
Definition: env_spec_w32.h:591
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
#define FALSE
Definition: types.h:117
_In_ PIRP Irp
Definition: csq.h:116
VOID CdCompleteRequest(_Inout_opt_ PIRP_CONTEXT IrpContext, _Inout_opt_ PIRP Irp, _In_ NTSTATUS Status)
Definition: cddata.c:914
#define _SEH2_GetExceptionInformation()
Definition: pseh2_64.h:11
unsigned char BOOLEAN
#define IRP_MJ_QUERY_VOLUME_INFORMATION
Definition: rdpdr.c:50
#define IRP_MJ_DIRECTORY_CONTROL
Definition: rdpdr.c:51
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:547
Status
Definition: gdiplustypes.h:24
#define IRP_MJ_FILE_SYSTEM_CONTROL
PIRP NTAPI IoGetTopLevelIrp(VOID)
Definition: irp.c:1843
#define CanFsdWait(I)
Definition: cdprocs.h:2001
NTSTATUS CdCompleteMdl(_In_ PIRP_CONTEXT IrpContext, _Inout_ PIRP Irp)
Definition: cachesup.c:411
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
NTSTATUS CdCommonDevControl(_Inout_ PIRP_CONTEXT IrpContext, _Inout_ PIRP Irp)
Definition: devctrl.c:46
#define FlagOn(_F, _SF)
Definition: ext2fs.h:179
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2789
#define SetFlag(_F, _SF)
Definition: ext2fs.h:187
_SEH2_END
Definition: create.c:4400
LONG CdExceptionFilter(_Inout_ PIRP_CONTEXT IrpContext, _In_ PEXCEPTION_POINTERS ExceptionPointer)
Definition: cddata.c:525
#define ASSERT_OPTIONAL_IRP(I)
Definition: cddata.h:251
#define NULL
Definition: types.h:112
VOID CdCleanupIrpContext(_In_ PIRP_CONTEXT IrpContext, _In_ BOOLEAN Post)
Definition: strucsup.c:1733
NTSTATUS CdCommonLockControl(_Inout_ PIRP_CONTEXT IrpContext, _Inout_ PIRP Irp)
Definition: lockctrl.c:35
#define CDFS_NTC_IRP_CONTEXT
Definition: nodetype.h:34
#define IRP_MJ_LOCK_CONTROL
Definition: rdpdr.c:53
#define IRP_MJ_READ
Definition: rdpdr.c:46
#define IRP_MJ_CLEANUP
#define IRP_MJ_SET_INFORMATION
Definition: rdpdr.c:49
#define IRP_MJ_WRITE
Definition: rdpdr.c:47
#define IRP_MJ_QUERY_INFORMATION
Definition: rdpdr.c:48
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
_Ret_valid_ PIRP_CONTEXT CdCreateIrpContext(_In_ PIRP Irp, _In_ BOOLEAN Wait)
Definition: strucsup.c:1573
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52
#define STATUS_CANT_WAIT
Definition: ntstatus.h:452
#define NT_ASSERT
Definition: rtlfuncs.h:3312

◆ _IRQL_requires_max_() [3/3]

_IRQL_requires_max_ ( PASSIVE_LEVEL  )

Definition at line 64 of file Messaging.c.

75 {
76  PFLT_SERVER_PORT_OBJECT PortObject;
78 
79  /* The caller must allow at least one connection */
80  if (MaxConnections == 0)
81  {
83  }
84 
85  /* The request must be for a kernel handle */
86  if (!(ObjectAttributes->Attributes & OBJ_KERNEL_HANDLE))
87  {
89  }
90 
91  /*
92  * Get rundown protection on the target to stop the owner
93  * from unloading whilst this port object is open. It gets
94  * removed in the FltpServerPortClose callback
95  */
97  if (!NT_SUCCESS(Status))
98  {
99  return Status;
100  }
101 
102  /* Create the server port object for this filter */
106  KernelMode,
107  NULL,
108  sizeof(FLT_SERVER_PORT_OBJECT),
109  0,
110  0,
111  (PVOID *)&PortObject);
112  if (NT_SUCCESS(Status))
113  {
114  /* Zero out the struct */
115  RtlZeroMemory(PortObject, sizeof(FLT_SERVER_PORT_OBJECT));
116 
117  /* Increment the ref count on the target filter */
119 
120  /* Setup the filter port object */
121  PortObject->Filter = Filter;
122  PortObject->ConnectNotify = ConnectNotifyCallback;
124  PortObject->MessageNotify = MessageNotifyCallback;
125  PortObject->Cookie = ServerPortCookie;
126  PortObject->MaxConnections = MaxConnections;
127 
128  /* Insert the object */
129  Status = ObInsertObject(PortObject,
130  NULL,
132  0,
133  NULL,
135  if (NT_SUCCESS(Status))
136  {
137  /* Lock the connection list */
139 
140  /* Add the new port object to the connection list and increment the count */
143 
144  /* Unlock the connection list*/
146  }
147  }
148 
149  if (!NT_SUCCESS(Status))
150  {
151  /* Allow the filter to be cleaned up */
153  }
154 
155  return Status;
156 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
_Must_inspect_result_ _Outptr_ PFLT_PORT * ServerPort
Definition: fltkernel.h:1873
PFLT_CONNECT_NOTIFY ConnectNotify
Definition: fltmgrint.h:191
VOID FLTAPI FltObjectDereference(_Inout_ PVOID Object)
Definition: Object.c:53
LONG NTSTATUS
Definition: precomp.h:26
#define InsertTailList(ListHead, Entry)
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
VOID FASTCALL ExReleaseFastMutex(IN PFAST_MUTEX FastMutex)
Definition: fmutex.c:31
ULONG FltpObjectPointerReference(_In_ PFLT_OBJECT Object)
Definition: Object.c:322
LIST_ENTRY mList
Definition: fltmgrint.h:56
_Must_inspect_result_ _In_opt_ PFLT_FILTER Filter
Definition: fltkernel.h:1802
#define FILE_READ_DATA
Definition: nt_native.h:628
NTSTATUS NTAPI ObCreateObject(IN KPROCESSOR_MODE ProbeMode OPTIONAL, IN POBJECT_TYPE Type, IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, IN KPROCESSOR_MODE AccessMode, IN OUT PVOID ParseContext OPTIONAL, IN ULONG ObjectSize, IN ULONG PagedPoolCharge OPTIONAL, IN ULONG NonPagedPoolCharge OPTIONAL, OUT PVOID *Object)
Definition: oblife.c:952
Status
Definition: gdiplustypes.h:24
POBJECT_TYPE ServerPortObjectType
Definition: Messaging.c:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
_Must_inspect_result_ _Outptr_ PFLT_PORT _In_ POBJECT_ATTRIBUTES _In_opt_ PVOID _In_ PFLT_CONNECT_NOTIFY _In_ PFLT_DISCONNECT_NOTIFY DisconnectNotifyCallback
Definition: fltkernel.h:1873
PVOID *typedef PHANDLE
Definition: ntsecpkg.h:454
_Must_inspect_result_ _Outptr_ PFLT_PORT _In_ POBJECT_ATTRIBUTES _In_opt_ PVOID _In_ PFLT_CONNECT_NOTIFY ConnectNotifyCallback
Definition: fltkernel.h:1873
NTSTATUS NTAPI ObInsertObject(IN PVOID Object, IN PACCESS_STATE AccessState OPTIONAL, IN ACCESS_MASK DesiredAccess, IN ULONG ObjectPointerBias, OUT PVOID *NewObject OPTIONAL, OUT PHANDLE Handle)
Definition: obhandle.c:2932
#define STANDARD_RIGHTS_ALL
Definition: nt_native.h:69
VOID FASTCALL ExAcquireFastMutex(IN PFAST_MUTEX FastMutex)
Definition: fmutex.c:23
NTSTATUS FLTAPI FltObjectReference(_Inout_ PVOID Object)
Definition: Object.c:41
_Must_inspect_result_ _Outptr_ PFLT_PORT _In_ POBJECT_ATTRIBUTES _In_opt_ PVOID ServerPortCookie
Definition: fltkernel.h:1873
#define NULL
Definition: types.h:112
FAST_MUTEX mLock
Definition: fltmgrint.h:55
PFLT_MESSAGE_NOTIFY MessageNotify
Definition: fltmgrint.h:193
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
_Must_inspect_result_ _Outptr_ PFLT_PORT _In_ POBJECT_ATTRIBUTES _In_opt_ PVOID _In_ PFLT_CONNECT_NOTIFY _In_ PFLT_DISCONNECT_NOTIFY _In_opt_ PFLT_MESSAGE_NOTIFY _In_ LONG MaxConnections
Definition: fltkernel.h:1873
PFLT_DISCONNECT_NOTIFY DisconnectNotify
Definition: fltmgrint.h:192
_Must_inspect_result_ _Outptr_ PFLT_PORT _In_ POBJECT_ATTRIBUTES _In_opt_ PVOID _In_ PFLT_CONNECT_NOTIFY _In_ PFLT_DISCONNECT_NOTIFY _In_opt_ PFLT_MESSAGE_NOTIFY MessageNotifyCallback
Definition: fltkernel.h:1873
FLT_MUTEX_LIST_HEAD ConnectionList
Definition: fltmgrint.h:121

◆ DECLARE_HANDLE()

DECLARE_HANDLE ( USBD_HANDLE  )

◆ USBD_CreateConfigurationRequest()

DECLSPEC_IMPORT PURB NTAPI USBD_CreateConfigurationRequest ( _In_ PUSB_CONFIGURATION_DESCRIPTOR  ConfigurationDescriptor,
_Out_ PUSHORT  Siz 
)

◆ USBD_ParseConfigurationDescriptor()

DECLSPEC_IMPORT PUSB_INTERFACE_DESCRIPTOR NTAPI USBD_ParseConfigurationDescriptor ( _In_ PUSB_CONFIGURATION_DESCRIPTOR  ConfigurationDescriptor,
_In_ UCHAR  InterfaceNumber,
_In_ UCHAR  AlternateSetting 
)

◆ USBD_QueryBusTime()

DECLSPEC_EXPORT NTSTATUS NTAPI USBD_QueryBusTime ( _In_ PDEVICE_OBJECT  RootHubPdo,
_Out_ PULONG  CurrentFrame 
)

Variable Documentation

◆ AlternateSetting

◆ BufferEnd

◆ BufferLength

Definition at line 238 of file usbdlib.h.

◆ DescriptorType

◆ EndpointType

_In_ UCHAR EndpointType

Definition at line 225 of file usbdlib.h.

Referenced by USBD_CalculateUsbBandwidth().

◆ FilterDeviceObject

_In_ PDEVICE_OBJECT FilterDeviceObject

Definition at line 197 of file usbdlib.h.

◆ InterfaceClass

_In_ PVOID _In_ LONG _In_ LONG _In_ LONG InterfaceClass

Definition at line 168 of file usbdlib.h.

Referenced by USBD_ParseConfigurationDescriptorEx().

◆ InterfaceList

◆ InterfaceNumber

◆ InterfaceProtocol

Definition at line 168 of file usbdlib.h.

Referenced by USBD_ParseConfigurationDescriptorEx().

◆ InterfaceSubClass

_In_ PVOID _In_ LONG _In_ LONG _In_ LONG _In_ LONG InterfaceSubClass

Definition at line 168 of file usbdlib.h.

Referenced by USBD_ParseConfigurationDescriptorEx().

◆ KeyNameLength

_In_ ULONG _In_ ULONG KeyNameLength

Definition at line 208 of file usbdlib.h.

Referenced by IoOpenDeviceRegistryKey(), and USBD_GetPdoRegistryParameter().

◆ Level

Definition at line 238 of file usbdlib.h.

◆ LowSpeed

_In_ UCHAR _In_ BOOLEAN LowSpeed

Definition at line 225 of file usbdlib.h.

Referenced by USBD_CalculateUsbBandwidth().

◆ Offset

Definition at line 238 of file usbdlib.h.

◆ ParameterLength

_In_ ULONG ParameterLength

◆ StartPosition

◆ Tag

Definition at line 238 of file usbdlib.h.

◆ TotalLength