ReactOS  0.4.13-dev-698-g77671f0
urb.c File Reference
#include "usbport.h"
#include <debug.h>
#include "usbdebug.h"
Include dependency graph for urb.c:

Go to the source code of this file.

Macros

#define NDEBUG
 
#define NDEBUG_USBPORT_URB
 

Functions

NTSTATUS NTAPI USBPORT_HandleGetConfiguration (IN PURB Urb)
 
NTSTATUS NTAPI USBPORT_HandleGetCurrentFrame (IN PDEVICE_OBJECT FdoDevice, IN PIRP Irp, IN PURB Urb)
 
NTSTATUS NTAPI USBPORT_AbortPipe (IN PDEVICE_OBJECT FdoDevice, IN PIRP Irp, IN PURB Urb)
 
NTSTATUS NTAPI USBPORT_ResetPipe (IN PDEVICE_OBJECT FdoDevice, IN PIRP Irp, IN PURB Urb)
 
NTSTATUS NTAPI USBPORT_ClearStall (IN PDEVICE_OBJECT FdoDevice, IN PIRP Irp, IN PURB Urb)
 
NTSTATUS NTAPI USBPORT_SyncResetPipeAndClearStall (IN PDEVICE_OBJECT FdoDevice, IN PIRP Irp, IN PURB Urb)
 
NTSTATUS NTAPI USBPORT_HandleSetOrClearFeature (IN PURB Urb)
 
NTSTATUS NTAPI USBPORT_HandleDataTransfers (IN PURB Urb)
 
NTSTATUS NTAPI USBPORT_HandleGetStatus (IN PIRP Irp, IN PURB Urb)
 
NTSTATUS NTAPI USBPORT_HandleVendorOrClass (IN PIRP Irp, IN PURB Urb)
 
NTSTATUS NTAPI USBPORT_HandleGetSetDescriptor (IN PIRP Irp, IN PURB Urb)
 
NTSTATUS NTAPI USBPORT_ValidateTransferParametersURB (IN PURB Urb)
 
NTSTATUS NTAPI USBPORT_ValidateURB (IN PDEVICE_OBJECT FdoDevice, IN PIRP Irp, IN PURB Urb, IN BOOLEAN IsControlTransfer, IN BOOLEAN IsNullTransfer)
 
NTSTATUS NTAPI USBPORT_HandleSubmitURB (IN PDEVICE_OBJECT PdoDevice, IN PIRP Irp, IN PURB Urb)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 10 of file urb.c.

◆ NDEBUG_USBPORT_URB

#define NDEBUG_USBPORT_URB

Definition at line 13 of file urb.c.

Function Documentation

◆ USBPORT_AbortPipe()

NTSTATUS NTAPI USBPORT_AbortPipe ( IN PDEVICE_OBJECT  FdoDevice,
IN PIRP  Irp,
IN PURB  Urb 
)

Definition at line 71 of file urb.c.

74 {
75  PUSBPORT_ENDPOINT Endpoint;
79 
80  DPRINT_URB("USBPORT_AbortPipe: ... \n");
81 
82  PipeHandle = Urb->UrbPipeRequest.PipeHandle;
83  DeviceHandle = Urb->UrbHeader.UsbdDeviceHandle;
84 
86  {
88  {
89  Endpoint = PipeHandle->Endpoint;
90 
92 
93  Irp->IoStatus.Status = Status;
95 
96  USBPORT_AbortEndpoint(FdoDevice, Endpoint, Irp);
97 
98  return Status;
99  }
100 
102  }
103  else
104  {
107  }
108 
109  return Status;
110 }
VOID NTAPI USBPORT_AbortEndpoint(IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_ENDPOINT Endpoint, IN PIRP Irp)
Definition: queue.c:1353
_Inout_ PUSB_DEVICE_HANDLE DeviceHandle
Definition: hubbusif.h:121
#define PIPE_HANDLE_FLAG_NULL_PACKET_SIZE
Definition: usbport.h:126
_In_ PIRP Irp
Definition: csq.h:116
#define DPRINT_URB(...)
Definition: usbdebug.h:145
LONG NTSTATUS
Definition: precomp.h:26
#define STATUS_PENDING
Definition: ntstatus.h:82
#define USBD_STATUS_SUCCESS
Definition: usb.h:170
NTSTATUS NTAPI USBPORT_USBDStatusToNtStatus(IN PURB Urb, IN USBD_STATUS USBDStatus)
Definition: usbport.c:485
BOOLEAN NTAPI USBPORT_ValidatePipeHandle(IN PUSBPORT_DEVICE_HANDLE DeviceHandle, IN PUSBPORT_PIPE_HANDLE PipeHandle)
Definition: endpoint.c:469
Status
Definition: gdiplustypes.h:24
static HANDLE PipeHandle
Definition: dhcpcsvc.c:21
#define USBD_STATUS_INVALID_PIPE_HANDLE
Definition: usb.h:194
IoMarkIrpPending(Irp)

Referenced by USBPORT_HandleSubmitURB().

◆ USBPORT_ClearStall()

NTSTATUS NTAPI USBPORT_ClearStall ( IN PDEVICE_OBJECT  FdoDevice,
IN PIRP  Irp,
IN PURB  Urb 
)

Definition at line 177 of file urb.c.

180 {
183  USBD_STATUS USBDStatus;
184  PUSBPORT_ENDPOINT Endpoint;
186  USB_DEFAULT_PIPE_SETUP_PACKET SetupPacket;
187 
188  DPRINT_URB("USBPORT_ClearStall: ... \n");
189 
190  PipeHandle = Urb->UrbPipeRequest.PipeHandle;
191  DeviceHandle = Urb->UrbHeader.UsbdDeviceHandle;
192 
194  {
195  return USBPORT_USBDStatusToNtStatus(Urb,
197  }
198 
199  Endpoint = PipeHandle->Endpoint;
200 
201  RtlZeroMemory(&SetupPacket, sizeof(USB_DEFAULT_PIPE_SETUP_PACKET));
202 
203  SetupPacket.bmRequestType.Recipient = BMREQUEST_TO_ENDPOINT;
204  SetupPacket.bRequest = USB_REQUEST_CLEAR_FEATURE;
205  SetupPacket.wValue.W = 0;
206  SetupPacket.wIndex.W = Endpoint->EndpointProperties.EndpointAddress;
207  SetupPacket.wLength = 0;
208 
210  FdoDevice,
211  &SetupPacket,
212  NULL,
213  0,
214  NULL,
215  &USBDStatus);
216 
217  Status = USBPORT_USBDStatusToNtStatus(Urb, USBDStatus);
218 
219  return Status;
220 }
_Inout_ PUSB_DEVICE_HANDLE DeviceHandle
Definition: hubbusif.h:121
NTSTATUS NTAPI USBPORT_SendSetupPacket(IN PUSBPORT_DEVICE_HANDLE DeviceHandle, IN PDEVICE_OBJECT FdoDevice, IN PUSB_DEFAULT_PIPE_SETUP_PACKET SetupPacket, IN PVOID Buffer, IN ULONG Length, IN OUT PULONG TransferedLen, IN OUT PUSBD_STATUS pUSBDStatus)
Definition: device.c:15
#define DPRINT_URB(...)
Definition: usbdebug.h:145
union _USB_DEFAULT_PIPE_SETUP_PACKET::_wIndex wIndex
LONG NTSTATUS
Definition: precomp.h:26
smooth NULL
Definition: ftsmooth.c:416
#define USB_REQUEST_CLEAR_FEATURE
Definition: usb100.h:79
LONG USBD_STATUS
Definition: usb.h:165
NTSTATUS NTAPI USBPORT_USBDStatusToNtStatus(IN PURB Urb, IN USBD_STATUS USBDStatus)
Definition: usbport.c:485
BOOLEAN NTAPI USBPORT_ValidatePipeHandle(IN PUSBPORT_DEVICE_HANDLE DeviceHandle, IN PUSBPORT_PIPE_HANDLE PipeHandle)
Definition: endpoint.c:469
USBPORT_ENDPOINT_PROPERTIES EndpointProperties
Definition: usbport.h:210
Status
Definition: gdiplustypes.h:24
static HANDLE PipeHandle
Definition: dhcpcsvc.c:21
union _USB_DEFAULT_PIPE_SETUP_PACKET::_wValue wValue
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define USBD_STATUS_INVALID_PIPE_HANDLE
Definition: usb.h:194
#define BMREQUEST_TO_ENDPOINT
Definition: usb100.h:40
BM_REQUEST_TYPE bmRequestType
Definition: usb200.h:72

Referenced by USBPORT_HandleSubmitURB(), and USBPORT_SyncResetPipeAndClearStall().

◆ USBPORT_HandleDataTransfers()

NTSTATUS NTAPI USBPORT_HandleDataTransfers ( IN PURB  Urb)

Definition at line 384 of file urb.c.

385 {
386  PUSBPORT_ENDPOINT Endpoint;
387 
388  DPRINT_URB("USBPORT_HandleDataTransfers: Urb - %p\n", Urb);
389 
390  Endpoint = ((PUSBPORT_PIPE_HANDLE)
391  (Urb->UrbBulkOrInterruptTransfer.PipeHandle))->Endpoint;
392 
394  {
396  {
397  Urb->UrbBulkOrInterruptTransfer.TransferFlags &= ~USBD_TRANSFER_DIRECTION_IN;
398  }
399  else
400  {
401  Urb->UrbBulkOrInterruptTransfer.TransferFlags |= USBD_TRANSFER_DIRECTION_IN;
402  }
403  }
404 
406 
407  return STATUS_PENDING;
408 }
#define USBPORT_TRANSFER_DIRECTION_OUT
Definition: usbmport.h:649
#define DPRINT_URB(...)
Definition: usbdebug.h:145
#define USBD_TRANSFER_DIRECTION_IN
Definition: usb.h:160
#define USBPORT_TRANSFER_TYPE_CONTROL
Definition: usbmport.h:8
#define STATUS_PENDING
Definition: ntstatus.h:82
VOID NTAPI USBPORT_QueueTransferUrb(IN PURB Urb)
Definition: queue.c:1085
struct _USBPORT_PIPE_HANDLE * PUSBPORT_PIPE_HANDLE
USBPORT_ENDPOINT_PROPERTIES EndpointProperties
Definition: usbport.h:210

Referenced by USBPORT_HandleSubmitURB().

◆ USBPORT_HandleGetConfiguration()

NTSTATUS NTAPI USBPORT_HandleGetConfiguration ( IN PURB  Urb)

Definition at line 18 of file urb.c.

19 {
21 
22  DPRINT_URB("USBPORT_HandleGetConfiguration: Urb - %p\n", Urb);
23 
24  SetupPacket = (PUSB_DEFAULT_PIPE_SETUP_PACKET)
25  &Urb->UrbControlGetConfigurationRequest.Reserved1;
26 
27  SetupPacket->bmRequestType.Dir = BMREQUEST_DEVICE_TO_HOST;
29  SetupPacket->wValue.W = 0;
30  SetupPacket->wIndex.W = 0;
31  SetupPacket->wLength = Urb->UrbControlGetConfigurationRequest.TransferBufferLength;
32 
33  Urb->UrbControlGetConfigurationRequest.Reserved0 |= USBD_TRANSFER_DIRECTION_IN; // 1;
34  Urb->UrbControlGetConfigurationRequest.Reserved0 |= USBD_SHORT_TRANSFER_OK; // 2
35 
36  USBPORT_DumpingSetupPacket(SetupPacket);
37 
39 
40  return STATUS_PENDING;
41 }
VOID NTAPI USBPORT_DumpingSetupPacket(IN PUSB_DEFAULT_PIPE_SETUP_PACKET SetupPacket)
Definition: debug.c:213
#define DPRINT_URB(...)
Definition: usbdebug.h:145
union _USB_DEFAULT_PIPE_SETUP_PACKET::_wIndex wIndex
#define USBD_TRANSFER_DIRECTION_IN
Definition: usb.h:160
#define USB_REQUEST_GET_CONFIGURATION
Definition: usb100.h:84
#define BMREQUEST_DEVICE_TO_HOST
Definition: usb100.h:32
#define STATUS_PENDING
Definition: ntstatus.h:82
VOID NTAPI USBPORT_QueueTransferUrb(IN PURB Urb)
Definition: queue.c:1085
#define USBD_SHORT_TRANSFER_OK
Definition: usb.h:154
struct _USB_DEFAULT_PIPE_SETUP_PACKET * PUSB_DEFAULT_PIPE_SETUP_PACKET
union _USB_DEFAULT_PIPE_SETUP_PACKET::_wValue wValue
BM_REQUEST_TYPE bmRequestType
Definition: usb200.h:72

Referenced by USBPORT_HandleSubmitURB().

◆ USBPORT_HandleGetCurrentFrame()

NTSTATUS NTAPI USBPORT_HandleGetCurrentFrame ( IN PDEVICE_OBJECT  FdoDevice,
IN PIRP  Irp,
IN PURB  Urb 
)

Definition at line 45 of file urb.c.

48 {
51  ULONG FrameNumber;
52  KIRQL OldIrql;
53 
54  FdoExtension = FdoDevice->DeviceExtension;
55  Packet = &FdoExtension->MiniPortInterface->Packet;
56 
57  KeAcquireSpinLock(&FdoExtension->MiniportSpinLock, &OldIrql);
58  FrameNumber = Packet->Get32BitFrameNumber(FdoExtension->MiniPortExt);
59  KeReleaseSpinLock(&FdoExtension->MiniportSpinLock, OldIrql);
60 
61  Urb->UrbGetCurrentFrameNumber.FrameNumber = FrameNumber;
62 
63  DPRINT_URB("USBPORT_HandleGetCurrentFrame: FrameNumber - %p\n",
64  FrameNumber);
65 
67 }
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1548
#define DPRINT_URB(...)
Definition: usbdebug.h:145
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
#define USBD_STATUS_SUCCESS
Definition: usb.h:170
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
NTSTATUS NTAPI USBPORT_USBDStatusToNtStatus(IN PURB Urb, IN USBD_STATUS USBDStatus)
Definition: usbport.c:485
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
unsigned int ULONG
Definition: retypes.h:1

Referenced by USBPORT_HandleSubmitURB().

◆ USBPORT_HandleGetSetDescriptor()

NTSTATUS NTAPI USBPORT_HandleGetSetDescriptor ( IN PIRP  Irp,
IN PURB  Urb 
)

Definition at line 560 of file urb.c.

562 {
563  PUSB_DEFAULT_PIPE_SETUP_PACKET SetupPacket;
564 
565  SetupPacket = (PUSB_DEFAULT_PIPE_SETUP_PACKET)
566  &Urb->UrbControlDescriptorRequest.Reserved1;
567 
568  SetupPacket->wLength = Urb->UrbControlDescriptorRequest.TransferBufferLength;
569  SetupPacket->bmRequestType.B = 0; // Clear bmRequestType
570  SetupPacket->bmRequestType.Type = BMREQUEST_STANDARD;
571 
572  switch (Urb->UrbHeader.Function)
573  {
575  DPRINT_URB("USBPORT_HandleGetSetDescriptor: URB_FUNCTION_GET_DESCRIPTOR_FROM_DEVICE\n");
576  SetupPacket->bRequest = USB_REQUEST_GET_DESCRIPTOR;
577  SetupPacket->bmRequestType.Dir = BMREQUEST_DEVICE_TO_HOST;
578  SetupPacket->bmRequestType.Recipient = BMREQUEST_TO_DEVICE;
579  break;
580 
582  DPRINT_URB("USBPORT_HandleGetSetDescriptor: URB_FUNCTION_SET_DESCRIPTOR_TO_DEVICE\n");
583  SetupPacket->bRequest = USB_REQUEST_SET_DESCRIPTOR;
584  SetupPacket->bmRequestType.Dir = BMREQUEST_HOST_TO_DEVICE;
585  SetupPacket->bmRequestType.Recipient = BMREQUEST_TO_DEVICE;
586  break;
587 
589  DPRINT_URB("USBPORT_HandleGetSetDescriptor: URB_FUNCTION_GET_DESCRIPTOR_FROM_ENDPOINT\n");
590  SetupPacket->bRequest = USB_REQUEST_GET_DESCRIPTOR;
591  SetupPacket->bmRequestType.Dir = BMREQUEST_DEVICE_TO_HOST;
592  SetupPacket->bmRequestType.Recipient = BMREQUEST_TO_ENDPOINT;
593  break;
594 
596  DPRINT_URB("USBPORT_HandleGetSetDescriptor: URB_FUNCTION_SET_DESCRIPTOR_TO_ENDPOINT\n");
597  SetupPacket->bRequest = USB_REQUEST_SET_DESCRIPTOR;
598  SetupPacket->bmRequestType.Dir = BMREQUEST_HOST_TO_DEVICE;
599  SetupPacket->bmRequestType.Recipient = BMREQUEST_TO_ENDPOINT;
600  break;
601 
603  DPRINT_URB("USBPORT_HandleGetSetDescriptor: URB_FUNCTION_GET_DESCRIPTOR_FROM_INTERFACE\n");
604  SetupPacket->bRequest = USB_REQUEST_GET_DESCRIPTOR;
605  SetupPacket->bmRequestType.Dir = BMREQUEST_DEVICE_TO_HOST;
606  SetupPacket->bmRequestType.Recipient = BMREQUEST_TO_INTERFACE;
607  break;
608 
610  DPRINT_URB("USBPORT_HandleGetSetDescriptor: URB_FUNCTION_SET_DESCRIPTOR_TO_INTERFACE\n");
611  SetupPacket->bRequest = USB_REQUEST_SET_DESCRIPTOR;
612  SetupPacket->bmRequestType.Dir = BMREQUEST_HOST_TO_DEVICE;
613  SetupPacket->bmRequestType.Recipient = BMREQUEST_TO_INTERFACE;
614  break;
615  }
616 
617  Urb->UrbControlTransfer.TransferFlags |= USBD_SHORT_TRANSFER_OK;
618 
619  if (SetupPacket->bmRequestType.Dir)
620  Urb->UrbControlTransfer.TransferFlags |= USBD_TRANSFER_DIRECTION_IN;
621  else
622  Urb->UrbControlTransfer.TransferFlags &= ~USBD_TRANSFER_DIRECTION_IN;
623 
624  USBPORT_DumpingSetupPacket(SetupPacket);
625 
627 
628  return STATUS_PENDING;
629 }
VOID NTAPI USBPORT_DumpingSetupPacket(IN PUSB_DEFAULT_PIPE_SETUP_PACKET SetupPacket)
Definition: debug.c:213
#define DPRINT_URB(...)
Definition: usbdebug.h:145
#define USBD_TRANSFER_DIRECTION_IN
Definition: usb.h:160
#define BMREQUEST_TO_INTERFACE
Definition: usb100.h:39
#define BMREQUEST_HOST_TO_DEVICE
Definition: usb100.h:31
#define BMREQUEST_DEVICE_TO_HOST
Definition: usb100.h:32
#define URB_FUNCTION_SET_DESCRIPTOR_TO_INTERFACE
Definition: usb.h:127
switch(r->id)
Definition: btrfs.c:2743
#define URB_FUNCTION_GET_DESCRIPTOR_FROM_INTERFACE
Definition: usb.h:126
#define STATUS_PENDING
Definition: ntstatus.h:82
VOID NTAPI USBPORT_QueueTransferUrb(IN PURB Urb)
Definition: queue.c:1085
#define USB_REQUEST_GET_DESCRIPTOR
Definition: usb100.h:82
#define URB_FUNCTION_GET_DESCRIPTOR_FROM_DEVICE
Definition: usb.h:97
#define BMREQUEST_STANDARD
Definition: usb100.h:34
#define USBD_SHORT_TRANSFER_OK
Definition: usb.h:154
#define URB_FUNCTION_SET_DESCRIPTOR_TO_ENDPOINT
Definition: usb.h:123
struct _USB_DEFAULT_PIPE_SETUP_PACKET * PUSB_DEFAULT_PIPE_SETUP_PACKET
#define URB_FUNCTION_GET_DESCRIPTOR_FROM_ENDPOINT
Definition: usb.h:122
#define URB_FUNCTION_SET_DESCRIPTOR_TO_DEVICE
Definition: usb.h:98
#define BMREQUEST_TO_ENDPOINT
Definition: usb100.h:40
BM_REQUEST_TYPE bmRequestType
Definition: usb200.h:72
#define USB_REQUEST_SET_DESCRIPTOR
Definition: usb100.h:83
#define BMREQUEST_TO_DEVICE
Definition: usb100.h:38

Referenced by USBPORT_HandleSubmitURB().

◆ USBPORT_HandleGetStatus()

NTSTATUS NTAPI USBPORT_HandleGetStatus ( IN PIRP  Irp,
IN PURB  Urb 
)

Definition at line 412 of file urb.c.

414 {
415  PUSB_DEFAULT_PIPE_SETUP_PACKET SetupPacket;
417 
418  SetupPacket = (PUSB_DEFAULT_PIPE_SETUP_PACKET)
419  &Urb->UrbControlDescriptorRequest.Reserved1;
420 
421  SetupPacket->bmRequestType.B = 0;
422  SetupPacket->bmRequestType.Dir = BMREQUEST_DEVICE_TO_HOST;
423  SetupPacket->bRequest = USB_REQUEST_GET_STATUS;
424  SetupPacket->wLength = Urb->UrbControlDescriptorRequest.TransferBufferLength;
425  SetupPacket->wValue.W = 0;
426 
427  switch (Urb->UrbHeader.Function)
428  {
430  DPRINT_URB("USBPORT_HandleGetStatus: URB_FUNCTION_GET_STATUS_FROM_DEVICE\n");
431  SetupPacket->bmRequestType.Recipient = BMREQUEST_TO_DEVICE;
432  break;
433 
435  DPRINT_URB("USBPORT_HandleGetStatus: URB_FUNCTION_GET_STATUS_FROM_INTERFACE\n");
436  SetupPacket->bmRequestType.Recipient = BMREQUEST_TO_INTERFACE;
437  break;
438 
440  DPRINT_URB("USBPORT_HandleGetStatus: URB_FUNCTION_GET_STATUS_FROM_ENDPOINT\n");
441  SetupPacket->bmRequestType.Recipient = BMREQUEST_TO_ENDPOINT;
442  break;
443 
445  DPRINT_URB("USBPORT_HandleGetStatus: URB_FUNCTION_GET_STATUS_FROM_OTHER\n");
446  SetupPacket->bmRequestType.Recipient = BMREQUEST_TO_OTHER;
447  break;
448  }
449 
450  if (SetupPacket->wLength == 2)
451  {
452  Urb->UrbControlTransfer.TransferFlags |= USBD_SHORT_TRANSFER_OK;
453 
454  if (SetupPacket->bmRequestType.Dir)
455  Urb->UrbControlTransfer.TransferFlags |= USBD_TRANSFER_DIRECTION_IN;
456  else
457  Urb->UrbControlTransfer.TransferFlags &= ~USBD_TRANSFER_DIRECTION_IN;
458 
459  //USBPORT_DumpingSetupPacket(SetupPacket);
460 
462 
464  }
465  else
466  {
469 
470  DPRINT1("USBPORT_HandleGetStatus: Bad wLength\n");
471  USBPORT_DumpingSetupPacket(SetupPacket);
472  }
473 
474  return Status;
475 }
VOID NTAPI USBPORT_DumpingSetupPacket(IN PUSB_DEFAULT_PIPE_SETUP_PACKET SetupPacket)
Definition: debug.c:213
#define DPRINT_URB(...)
Definition: usbdebug.h:145
LONG NTSTATUS
Definition: precomp.h:26
#define USBD_TRANSFER_DIRECTION_IN
Definition: usb.h:160
#define BMREQUEST_TO_INTERFACE
Definition: usb100.h:39
#define BMREQUEST_DEVICE_TO_HOST
Definition: usb100.h:32
#define BMREQUEST_TO_OTHER
Definition: usb100.h:41
switch(r->id)
Definition: btrfs.c:2743
#define URB_FUNCTION_GET_STATUS_FROM_INTERFACE
Definition: usb.h:106
#define STATUS_PENDING
Definition: ntstatus.h:82
#define URB_FUNCTION_GET_STATUS_FROM_ENDPOINT
Definition: usb.h:107
#define URB_FUNCTION_GET_STATUS_FROM_OTHER
Definition: usb.h:119
VOID NTAPI USBPORT_QueueTransferUrb(IN PURB Urb)
Definition: queue.c:1085
#define USBD_STATUS_INVALID_PARAMETER
Definition: usb.h:192
NTSTATUS NTAPI USBPORT_USBDStatusToNtStatus(IN PURB Urb, IN USBD_STATUS USBDStatus)
Definition: usbport.c:485
Status
Definition: gdiplustypes.h:24
#define USBD_SHORT_TRANSFER_OK
Definition: usb.h:154
#define USB_REQUEST_GET_STATUS
Definition: usb100.h:78
#define URB_FUNCTION_GET_STATUS_FROM_DEVICE
Definition: usb.h:105
struct _USB_DEFAULT_PIPE_SETUP_PACKET * PUSB_DEFAULT_PIPE_SETUP_PACKET
#define DPRINT1
Definition: precomp.h:8
union _USB_DEFAULT_PIPE_SETUP_PACKET::_wValue wValue
#define BMREQUEST_TO_ENDPOINT
Definition: usb100.h:40
BM_REQUEST_TYPE bmRequestType
Definition: usb200.h:72
#define BMREQUEST_TO_DEVICE
Definition: usb100.h:38

Referenced by USBPORT_HandleSubmitURB().

◆ USBPORT_HandleSetOrClearFeature()

NTSTATUS NTAPI USBPORT_HandleSetOrClearFeature ( IN PURB  Urb)

Definition at line 307 of file urb.c.

308 {
309  PUSB_DEFAULT_PIPE_SETUP_PACKET SetupPacket;
310 
311  DPRINT_URB("USBPORT_HandleSetOrClearFeature: Urb - %p\n", Urb);
312 
313  SetupPacket = (PUSB_DEFAULT_PIPE_SETUP_PACKET)
314  &Urb->UrbControlFeatureRequest.Reserved0;
315 
316  SetupPacket->wLength = 0;
317  Urb->UrbControlFeatureRequest.Reserved3 = 0; // TransferBufferLength
318 
319  SetupPacket->bmRequestType.Dir = BMREQUEST_HOST_TO_DEVICE;
320 
321  switch (Urb->UrbHeader.Function)
322  {
324  DPRINT_URB("USBPORT_HandleGetSetDescriptor: URB_FUNCTION_GET_DESCRIPTOR_FROM_DEVICE\n");
325  SetupPacket->bRequest = USB_REQUEST_SET_FEATURE;
326  SetupPacket->bmRequestType.Recipient = BMREQUEST_TO_DEVICE;
327  break;
328 
330  DPRINT_URB("USBPORT_HandleGetSetDescriptor: URB_FUNCTION_SET_DESCRIPTOR_TO_DEVICE\n");
331  SetupPacket->bRequest = USB_REQUEST_SET_FEATURE;
332  SetupPacket->bmRequestType.Recipient = BMREQUEST_TO_INTERFACE;
333  break;
334 
336  DPRINT_URB("USBPORT_HandleGetSetDescriptor: URB_FUNCTION_SET_DESCRIPTOR_TO_DEVICE\n");
337  SetupPacket->bRequest = USB_REQUEST_SET_FEATURE;
338  SetupPacket->bmRequestType.Recipient = BMREQUEST_TO_ENDPOINT;
339  break;
340 
342  DPRINT_URB("USBPORT_HandleGetSetDescriptor: URB_FUNCTION_GET_DESCRIPTOR_FROM_ENDPOINT\n");
343  SetupPacket->bRequest = USB_REQUEST_CLEAR_FEATURE;
344  SetupPacket->bmRequestType.Recipient = BMREQUEST_TO_DEVICE;
345  break;
346 
348  DPRINT_URB("USBPORT_HandleGetSetDescriptor: URB_FUNCTION_SET_DESCRIPTOR_TO_ENDPOINT\n");
349  SetupPacket->bRequest = USB_REQUEST_CLEAR_FEATURE;
350  SetupPacket->bmRequestType.Recipient = BMREQUEST_TO_INTERFACE;
351  break;
352 
354  DPRINT_URB("USBPORT_HandleGetSetDescriptor: URB_FUNCTION_GET_DESCRIPTOR_FROM_INTERFACE\n");
355  SetupPacket->bRequest = USB_REQUEST_CLEAR_FEATURE;
356  SetupPacket->bmRequestType.Recipient = BMREQUEST_TO_ENDPOINT;
357  break;
358 
360  DPRINT_URB("USBPORT_HandleGetSetDescriptor: URB_FUNCTION_SET_DESCRIPTOR_TO_INTERFACE\n");
361  SetupPacket->bRequest = USB_REQUEST_CLEAR_FEATURE;
362  SetupPacket->bmRequestType.Recipient = BMREQUEST_TO_OTHER;
363  break;
364 
366  DPRINT_URB("USBPORT_HandleGetSetDescriptor: URB_FUNCTION_SET_DESCRIPTOR_TO_INTERFACE\n");
367  SetupPacket->bRequest = USB_REQUEST_SET_FEATURE;
368  SetupPacket->bmRequestType.Recipient = BMREQUEST_TO_OTHER;
369  break;
370  }
371 
372  Urb->UrbControlFeatureRequest.Reserved2 &= ~USBD_TRANSFER_DIRECTION_IN;
373  Urb->UrbControlFeatureRequest.Reserved2 |= USBD_SHORT_TRANSFER_OK;
374 
375  USBPORT_DumpingSetupPacket(SetupPacket);
376 
378 
379  return STATUS_PENDING;
380 }
VOID NTAPI USBPORT_DumpingSetupPacket(IN PUSB_DEFAULT_PIPE_SETUP_PACKET SetupPacket)
Definition: debug.c:213
#define URB_FUNCTION_CLEAR_FEATURE_TO_INTERFACE
Definition: usb.h:103
#define DPRINT_URB(...)
Definition: usbdebug.h:145
#define USBD_TRANSFER_DIRECTION_IN
Definition: usb.h:160
#define BMREQUEST_TO_INTERFACE
Definition: usb100.h:39
#define BMREQUEST_HOST_TO_DEVICE
Definition: usb100.h:31
#define URB_FUNCTION_CLEAR_FEATURE_TO_ENDPOINT
Definition: usb.h:104
#define URB_FUNCTION_SET_FEATURE_TO_ENDPOINT
Definition: usb.h:101
#define BMREQUEST_TO_OTHER
Definition: usb100.h:41
#define URB_FUNCTION_SET_FEATURE_TO_DEVICE
Definition: usb.h:99
switch(r->id)
Definition: btrfs.c:2743
#define USB_REQUEST_CLEAR_FEATURE
Definition: usb100.h:79
#define STATUS_PENDING
Definition: ntstatus.h:82
#define URB_FUNCTION_SET_FEATURE_TO_OTHER
Definition: usb.h:121
VOID NTAPI USBPORT_QueueTransferUrb(IN PURB Urb)
Definition: queue.c:1085
#define USBD_SHORT_TRANSFER_OK
Definition: usb.h:154
#define URB_FUNCTION_SET_FEATURE_TO_INTERFACE
Definition: usb.h:100
#define USB_REQUEST_SET_FEATURE
Definition: usb100.h:80
struct _USB_DEFAULT_PIPE_SETUP_PACKET * PUSB_DEFAULT_PIPE_SETUP_PACKET
#define URB_FUNCTION_CLEAR_FEATURE_TO_OTHER
Definition: usb.h:120
#define BMREQUEST_TO_ENDPOINT
Definition: usb100.h:40
#define URB_FUNCTION_CLEAR_FEATURE_TO_DEVICE
Definition: usb.h:102
BM_REQUEST_TYPE bmRequestType
Definition: usb200.h:72
#define BMREQUEST_TO_DEVICE
Definition: usb100.h:38

Referenced by USBPORT_HandleSubmitURB().

◆ USBPORT_HandleSubmitURB()

NTSTATUS NTAPI USBPORT_HandleSubmitURB ( IN PDEVICE_OBJECT  PdoDevice,
IN PIRP  Irp,
IN PURB  Urb 
)

Definition at line 791 of file urb.c.

794 {
796  PDEVICE_OBJECT FdoDevice;
801 
802  ASSERT(Urb);
803 
804  PdoExtension = PdoDevice->DeviceExtension;
805  FdoDevice = PdoExtension->FdoDevice;
806  FdoExtension = FdoDevice->DeviceExtension;
807 
808  Urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
809  Urb->UrbHeader.UsbdFlags = 0;
810 
811  Function = Urb->UrbHeader.Function;
812 
814  {
817 
818  DPRINT1("USBPORT_HandleSubmitURB: Unknown URB function - %x !!!\n",
819  Function);
820 
821  return Status;
822  }
823 
824  if (FdoExtension->TimerFlags & USBPORT_TMFLAG_RH_SUSPENDED)
825  {
826  DPRINT1("USBPORT_HandleSubmitURB: Bad Request\n");
827 
829 
830  Irp->IoStatus.Status = STATUS_PENDING;
832  IoCsqInsertIrp(&FdoExtension->BadRequestIoCsq, Irp, NULL);
833 
834  return STATUS_PENDING;
835  }
836 
837  DeviceHandle = Urb->UrbHeader.UsbdDeviceHandle;
838 
839  if (!DeviceHandle)
840  {
841  DeviceHandle = &PdoExtension->DeviceHandle;
842  Urb->UrbHeader.UsbdDeviceHandle = DeviceHandle;
843  }
844 
846  DeviceHandle))
847  {
848  DPRINT1("USBPORT_HandleSubmitURB: Not valid device handle\n");
849 
850  Irp->IoStatus.Status = STATUS_PENDING;
852  IoCsqInsertIrp(&FdoExtension->BadRequestIoCsq, Irp, NULL);
853 
854  return STATUS_PENDING;
855  }
856 
857  InterlockedIncrement(&DeviceHandle->DeviceHandleLock);
858 
859  DPRINT_URB("USBPORT_HandleSubmitURB: Function - 0x%02X, DeviceHandle - %p\n",
860  Function,
861  Urb->UrbHeader.UsbdDeviceHandle);
862 
863  switch (Function)
864  {
866  DPRINT1("USBPORT_HandleSubmitURB: URB_FUNCTION_ISOCH_TRANSFER UNIMPLEMENTED. FIXME. \n");
867  break;
868 
871  Status = USBPORT_ValidateURB(FdoDevice, Irp, Urb, FALSE, FALSE);
872 
873  if (!NT_SUCCESS(Status))
874  {
875  DPRINT1("USBPORT_HandleSubmitURB: Not valid URB\n");
876  break;
877  }
878 
880  break;
881 
890  Status = USBPORT_ValidateURB(FdoDevice, Irp, Urb, TRUE, FALSE);
891 
892  if (!NT_SUCCESS(Status))
893  {
894  DPRINT1("USBPORT_HandleSubmitURB: Not valid URB\n");
895  break;
896  }
897 
899  break;
900 
907  Status = USBPORT_ValidateURB(FdoDevice, Irp, Urb, TRUE, FALSE);
908 
909  if (!NT_SUCCESS(Status))
910  {
911  DPRINT1("USBPORT_HandleSubmitURB: Not valid URB\n");
912  break;
913  }
914 
916  break;
917 
918  case URB_FUNCTION_GET_MS_FEATURE_DESCRIPTOR:
919  DPRINT1("USBPORT_HandleSubmitURB: URB_FUNCTION_GET_MS_FEATURE_DESCRIPTOR (0x2A) NOT_SUPPORTED\n");
920  return USBPORT_USBDStatusToNtStatus(Urb,
922 
927  Status = USBPORT_ValidateURB(FdoDevice, Irp, Urb, TRUE, FALSE);
928 
929  if (!NT_SUCCESS(Status))
930  {
931  DPRINT1("USBPORT_HandleSubmitURB: Not valid URB\n");
932  break;
933  }
934 
936  break;
937 
940  Irp,
941  Urb);
942  break;
943 
946  Irp,
947  Urb);
948  break;
949 
951  Status = USBPORT_ValidateURB(FdoDevice, Irp, Urb, TRUE, FALSE);
952 
953  if (!NT_SUCCESS(Status))
954  {
955  DPRINT1("USBPORT_HandleSubmitURB: Not valid URB\n");
956  break;
957  }
958 
960  break;
961 
963  DPRINT1("USBPORT_HandleSubmitURB: URB_FUNCTION_GET_INTERFACE (0x27) NOT_SUPPORTED\n");
964  return USBPORT_USBDStatusToNtStatus(Urb,
966 
969  Irp,
970  Urb);
971  break;
972 
973  case URB_FUNCTION_SYNC_RESET_PIPE:
975  Irp,
976  Urb);
977  break;
978 
979  case URB_FUNCTION_SYNC_CLEAR_STALL:
981  Irp,
982  Urb);
983  break;
984 
987  Irp,
988  Urb);
989  break;
990 
998  Status = USBPORT_ValidateURB(FdoDevice, Irp, Urb, TRUE, TRUE);
999 
1000  if (!NT_SUCCESS(Status))
1001  {
1002  DPRINT1("USBPORT_HandleSubmitURB: Not valid URB\n");
1003  break;
1004  }
1005 
1007  break;
1008 
1011  Irp,
1012  Urb);
1013  break;
1014 
1016  DPRINT1("USBPORT_HandleSubmitURB: URB_FUNCTION_TAKE_FRAME_LENGTH_CONTROL (0x03) NOT_SUPPORTED\n");
1018 
1020  DPRINT1("USBPORT_HandleSubmitURB: URB_FUNCTION_RELEASE_FRAME_LENGTH_CONTROL (0x04) NOT_SUPPORTED\n");
1022 
1024  DPRINT1("USBPORT_HandleSubmitURB: URB_FUNCTION_GET_FRAME_LENGTH (0x05) NOT_SUPPORTED\n");
1026 
1028  DPRINT1("USBPORT_HandleSubmitURB: URB_FUNCTION_SET_FRAME_LENGTH (0x06) NOT_SUPPORTED\n");
1030 
1031  default:
1032  DPRINT1("USBPORT_HandleSubmitURB: Unknown URB Function - %x\n",
1033  Function);
1034  //URB_FUNCTION_RESERVED_0X0016
1035  //URB_FUNCTION_RESERVE_0X001D
1036  //URB_FUNCTION_RESERVE_0X002B
1037  //URB_FUNCTION_RESERVE_0X002C
1038  //URB_FUNCTION_RESERVE_0X002D
1039  //URB_FUNCTION_RESERVE_0X002E
1040  //URB_FUNCTION_RESERVE_0X002F
1041  break;
1042  }
1043 
1044  if (Status == STATUS_PENDING)
1045  {
1046  return Status;
1047  }
1048 
1049  if (Urb->UrbHeader.UsbdFlags & USBD_FLAG_ALLOCATED_TRANSFER)
1050  {
1051  PUSBPORT_TRANSFER Transfer;
1052 
1053  Transfer = Urb->UrbControlTransfer.hca.Reserved8[0];
1054  Urb->UrbControlTransfer.hca.Reserved8[0] = NULL;
1055  Urb->UrbHeader.UsbdFlags |= ~USBD_FLAG_ALLOCATED_TRANSFER;
1056  ExFreePoolWithTag(Transfer, USB_PORT_TAG);
1057  }
1058 
1059  InterlockedDecrement(&DeviceHandle->DeviceHandleLock);
1060 
1061  Irp->IoStatus.Status = Status;
1063 
1064  return Status;
1065 }
#define USBD_STATUS_DEVICE_GONE
Definition: usb.h:210
#define URB_FUNCTION_RELEASE_FRAME_LENGTH_CONTROL
Definition: usb.h:90
#define USBD_STATUS_NOT_SUPPORTED
Definition: usb.h:202
#define TRUE
Definition: types.h:120
_Inout_ PUSB_DEVICE_HANDLE DeviceHandle
Definition: hubbusif.h:121
#define URB_FUNCTION_MAX
Definition: usbport.h:45
#define URB_FUNCTION_CLEAR_FEATURE_TO_INTERFACE
Definition: usb.h:103
#define USBD_STATUS_INVALID_URB_FUNCTION
Definition: usb.h:191
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
NTSTATUS NTAPI USBPORT_HandleSetOrClearFeature(IN PURB Urb)
Definition: urb.c:307
_In_ PIRP Irp
Definition: csq.h:116
NTSTATUS NTAPI USBPORT_HandleSelectConfiguration(IN PDEVICE_OBJECT FdoDevice, IN PIRP Irp, IN PURB Urb)
Definition: device.c:574
#define DPRINT_URB(...)
Definition: usbdebug.h:145
NTKERNELAPI VOID NTAPI IoCsqInsertIrp(_Inout_ PIO_CSQ Csq, _Inout_ PIRP Irp, _Out_opt_ PIO_CSQ_IRP_CONTEXT Context)
Insert an IRP into the CSQ.
Definition: csq.c:177
#define URB_FUNCTION_CLASS_ENDPOINT
Definition: usb.h:114
#define URB_FUNCTION_VENDOR_DEVICE
Definition: usb.h:109
LONG NTSTATUS
Definition: precomp.h:26
#define URB_FUNCTION_VENDOR_OTHER
Definition: usb.h:118
#define USBD_FLAG_ALLOCATED_TRANSFER
Definition: usbport.h:122
NTSTATUS NTAPI USBPORT_ClearStall(IN PDEVICE_OBJECT FdoDevice, IN PIRP Irp, IN PURB Urb)
Definition: urb.c:177
NTSTATUS NTAPI USBPORT_HandleSelectInterface(IN PDEVICE_OBJECT FdoDevice, IN PIRP Irp, IN PURB Urb)
Definition: device.c:1486
#define URB_FUNCTION_CLASS_DEVICE
Definition: usb.h:112
#define USB_PORT_TAG
Definition: usbport.h:44
NTSTATUS NTAPI USBPORT_HandleGetStatus(IN PIRP Irp, IN PURB Urb)
Definition: urb.c:412
NTSTATUS NTAPI USBPORT_HandleGetCurrentFrame(IN PDEVICE_OBJECT FdoDevice, IN PIRP Irp, IN PURB Urb)
Definition: urb.c:45
static LPOVERLAPPED_COMPLETION_ROUTINE Function
Definition: sync.c:684
#define URB_FUNCTION_CLEAR_FEATURE_TO_ENDPOINT
Definition: usb.h:104
#define URB_FUNCTION_GET_INTERFACE
Definition: usb.h:125
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
#define URB_FUNCTION_VENDOR_INTERFACE
Definition: usb.h:110
#define IoCompleteRequest
Definition: irp.c:1240
#define URB_FUNCTION_SET_FEATURE_TO_ENDPOINT
Definition: usb.h:101
#define URB_FUNCTION_SET_DESCRIPTOR_TO_INTERFACE
Definition: usb.h:127
#define URB_FUNCTION_SET_FEATURE_TO_DEVICE
Definition: usb.h:99
NTSTATUS NTAPI USBPORT_ResetPipe(IN PDEVICE_OBJECT FdoDevice, IN PIRP Irp, IN PURB Urb)
Definition: urb.c:114
NTSTATUS NTAPI USBPORT_HandleGetConfiguration(IN PURB Urb)
Definition: urb.c:18
#define URB_FUNCTION_SYNC_RESET_PIPE_AND_CLEAR_STALL
Definition: usb.h:116
#define URB_FUNCTION_GET_STATUS_FROM_INTERFACE
Definition: usb.h:106
#define URB_FUNCTION_GET_DESCRIPTOR_FROM_INTERFACE
Definition: usb.h:126
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
#define URB_FUNCTION_GET_STATUS_FROM_ENDPOINT
Definition: usb.h:107
#define URB_FUNCTION_SET_FEATURE_TO_OTHER
Definition: usb.h:121
#define URB_FUNCTION_GET_STATUS_FROM_OTHER
Definition: usb.h:119
#define USBPORT_TMFLAG_RH_SUSPENDED
Definition: usbport.h:95
#define URB_FUNCTION_GET_CONFIGURATION
Definition: usb.h:124
NTSTATUS NTAPI USBPORT_ValidateURB(IN PDEVICE_OBJECT FdoDevice, IN PIRP Irp, IN PURB Urb, IN BOOLEAN IsControlTransfer, IN BOOLEAN IsNullTransfer)
Definition: urb.c:693
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
BOOLEAN NTAPI USBPORT_ValidateDeviceHandle(IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_DEVICE_HANDLE DeviceHandle)
Definition: device.c:801
#define USBD_STATUS_SUCCESS
Definition: usb.h:170
#define URB_FUNCTION_SELECT_CONFIGURATION
Definition: usb.h:86
#define InterlockedDecrement
Definition: armddk.h:52
#define URB_FUNCTION_TAKE_FRAME_LENGTH_CONTROL
Definition: usb.h:89
#define URB_FUNCTION_GET_DESCRIPTOR_FROM_DEVICE
Definition: usb.h:97
NTSTATUS NTAPI USBPORT_USBDStatusToNtStatus(IN PURB Urb, IN USBD_STATUS USBDStatus)
Definition: usbport.c:485
#define URB_FUNCTION_SELECT_INTERFACE
Definition: usb.h:87
Status
Definition: gdiplustypes.h:24
#define InterlockedIncrement
Definition: armddk.h:53
#define URB_FUNCTION_SET_FEATURE_TO_INTERFACE
Definition: usb.h:100
#define URB_FUNCTION_ISOCH_TRANSFER
Definition: usb.h:96
unsigned short USHORT
Definition: pedump.c:61
#define URB_FUNCTION_ABORT_PIPE
Definition: usb.h:88
#define URB_FUNCTION_CLASS_INTERFACE
Definition: usb.h:113
#define URB_FUNCTION_SET_DESCRIPTOR_TO_ENDPOINT
Definition: usb.h:123
#define URB_FUNCTION_GET_STATUS_FROM_DEVICE
Definition: usb.h:105
#define URB_FUNCTION_CLEAR_FEATURE_TO_OTHER
Definition: usb.h:120
#define DPRINT1
Definition: precomp.h:8
NTSTATUS NTAPI USBPORT_HandleGetSetDescriptor(IN PIRP Irp, IN PURB Urb)
Definition: urb.c:560
#define URB_FUNCTION_GET_DESCRIPTOR_FROM_ENDPOINT
Definition: usb.h:122
#define URB_FUNCTION_GET_FRAME_LENGTH
Definition: usb.h:91
#define URB_FUNCTION_CONTROL_TRANSFER
Definition: usb.h:94
#define IO_NO_INCREMENT
Definition: iotypes.h:565
#define URB_FUNCTION_SET_DESCRIPTOR_TO_DEVICE
Definition: usb.h:98
#define URB_FUNCTION_SET_FRAME_LENGTH
Definition: usb.h:92
#define URB_FUNCTION_VENDOR_ENDPOINT
Definition: usb.h:111
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
NTSTATUS NTAPI USBPORT_AbortPipe(IN PDEVICE_OBJECT FdoDevice, IN PIRP Irp, IN PURB Urb)
Definition: urb.c:71
NTSTATUS NTAPI USBPORT_HandleDataTransfers(IN PURB Urb)
Definition: urb.c:384
IoMarkIrpPending(Irp)
NTSTATUS NTAPI USBPORT_HandleVendorOrClass(IN PIRP Irp, IN PURB Urb)
Definition: urb.c:479
#define URB_FUNCTION_CLASS_OTHER
Definition: usb.h:117
#define URB_FUNCTION_GET_CURRENT_FRAME_NUMBER
Definition: usb.h:93
#define URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER
Definition: usb.h:95
NTSTATUS NTAPI USBPORT_SyncResetPipeAndClearStall(IN PDEVICE_OBJECT FdoDevice, IN PIRP Irp, IN PURB Urb)
Definition: urb.c:224

Referenced by USBPORT_PdoInternalDeviceControl().

◆ USBPORT_HandleVendorOrClass()

NTSTATUS NTAPI USBPORT_HandleVendorOrClass ( IN PIRP  Irp,
IN PURB  Urb 
)

Definition at line 479 of file urb.c.

481 {
482  PUSB_DEFAULT_PIPE_SETUP_PACKET SetupPacket;
483 
484  /*
485  Specifies a value, from 4 to 31 inclusive,
486  that becomes part of the request type code in the USB-defined setup packet.
487  This value is defined by USB for a class request or the vendor for a vendor request.
488  */
489 
490  SetupPacket = (PUSB_DEFAULT_PIPE_SETUP_PACKET)
491  &Urb->UrbControlDescriptorRequest.Reserved1;
492 
494  (Urb->UrbControlTransfer.TransferFlags);
495 
496  SetupPacket->wLength = Urb->UrbControlDescriptorRequest.TransferBufferLength;
497 
498  Urb->UrbControlTransfer.TransferFlags |= USBD_SHORT_TRANSFER_OK;
499 
500  switch (Urb->UrbHeader.Function)
501  {
503  DPRINT_URB("USBPORT_HandleVendorOrClass: URB_FUNCTION_VENDOR_DEVICE\n");
504  SetupPacket->bmRequestType.Type = BMREQUEST_VENDOR;
505  SetupPacket->bmRequestType.Recipient = BMREQUEST_TO_DEVICE;
506  break;
507 
509  DPRINT_URB("USBPORT_HandleVendorOrClass: URB_FUNCTION_VENDOR_INTERFACE\n");
510  SetupPacket->bmRequestType.Type = BMREQUEST_VENDOR;
511  SetupPacket->bmRequestType.Recipient = BMREQUEST_TO_INTERFACE;
512  break;
513 
515  DPRINT_URB("USBPORT_HandleVendorOrClass: URB_FUNCTION_VENDOR_ENDPOINT\n");
516  SetupPacket->bmRequestType.Type = BMREQUEST_VENDOR;
517  SetupPacket->bmRequestType.Recipient = BMREQUEST_TO_ENDPOINT;
518  break;
519 
521  DPRINT_URB("USBPORT_HandleVendorOrClass: URB_FUNCTION_CLASS_DEVICE\n");
522  SetupPacket->bmRequestType.Type = BMREQUEST_CLASS;
523  SetupPacket->bmRequestType.Recipient = BMREQUEST_TO_DEVICE;
524  break;
525 
527  DPRINT_URB("USBPORT_HandleVendorOrClass: URB_FUNCTION_CLASS_INTERFACE\n");
528  SetupPacket->bmRequestType.Type = BMREQUEST_CLASS;
529  SetupPacket->bmRequestType.Recipient = BMREQUEST_TO_INTERFACE;
530  break;
531 
533  DPRINT_URB("USBPORT_HandleVendorOrClass: URB_FUNCTION_CLASS_ENDPOINT\n");
534  SetupPacket->bmRequestType.Type = BMREQUEST_CLASS;
535  SetupPacket->bmRequestType.Recipient = BMREQUEST_TO_ENDPOINT;
536  break;
537 
539  DPRINT_URB("USBPORT_HandleVendorOrClass: URB_FUNCTION_CLASS_OTHER\n");
540  SetupPacket->bmRequestType.Type = BMREQUEST_CLASS;
541  SetupPacket->bmRequestType.Recipient = BMREQUEST_TO_OTHER;
542  break;
543 
545  DPRINT_URB("USBPORT_HandleVendorOrClass: URB_FUNCTION_VENDOR_OTHER\n");
546  SetupPacket->bmRequestType.Type = BMREQUEST_VENDOR;
547  SetupPacket->bmRequestType.Recipient = BMREQUEST_TO_OTHER;
548  break;
549  }
550 
551  USBPORT_DumpingSetupPacket(SetupPacket);
552 
554 
555  return STATUS_PENDING;
556 }
VOID NTAPI USBPORT_DumpingSetupPacket(IN PUSB_DEFAULT_PIPE_SETUP_PACKET SetupPacket)
Definition: debug.c:213
#define USBD_TRANSFER_DIRECTION_FLAG(flags)
Definition: usb.h:157
#define DPRINT_URB(...)
Definition: usbdebug.h:145
#define URB_FUNCTION_CLASS_ENDPOINT
Definition: usb.h:114
#define URB_FUNCTION_VENDOR_DEVICE
Definition: usb.h:109
#define URB_FUNCTION_VENDOR_OTHER
Definition: usb.h:118
#define BMREQUEST_TO_INTERFACE
Definition: usb100.h:39
#define URB_FUNCTION_CLASS_DEVICE
Definition: usb.h:112
#define URB_FUNCTION_VENDOR_INTERFACE
Definition: usb.h:110
#define BMREQUEST_TO_OTHER
Definition: usb100.h:41
#define STATUS_PENDING
Definition: ntstatus.h:82
VOID NTAPI USBPORT_QueueTransferUrb(IN PURB Urb)
Definition: queue.c:1085
#define BMREQUEST_CLASS
Definition: usb100.h:35
#define USBD_SHORT_TRANSFER_OK
Definition: usb.h:154
#define URB_FUNCTION_CLASS_INTERFACE
Definition: usb.h:113
struct _USB_DEFAULT_PIPE_SETUP_PACKET * PUSB_DEFAULT_PIPE_SETUP_PACKET
#define URB_FUNCTION_VENDOR_ENDPOINT
Definition: usb.h:111
#define BMREQUEST_TO_ENDPOINT
Definition: usb100.h:40
BM_REQUEST_TYPE bmRequestType
Definition: usb200.h:72
#define URB_FUNCTION_CLASS_OTHER
Definition: usb.h:117
#define BMREQUEST_VENDOR
Definition: usb100.h:36
#define BMREQUEST_TO_DEVICE
Definition: usb100.h:38

Referenced by USBPORT_HandleSubmitURB().

◆ USBPORT_ResetPipe()

NTSTATUS NTAPI USBPORT_ResetPipe ( IN PDEVICE_OBJECT  FdoDevice,
IN PIRP  Irp,
IN PURB  Urb 
)

Definition at line 114 of file urb.c.

117 {
121  PUSBPORT_ENDPOINT Endpoint;
123 
124  DPRINT_URB("USBPORT_ResetPipe: ... \n");
125 
126  FdoExtension = FdoDevice->DeviceExtension;
127  Packet = &FdoExtension->MiniPortInterface->Packet;
128 
129  PipeHandle = Urb->UrbPipeRequest.PipeHandle;
130 
131  if (!USBPORT_ValidatePipeHandle((PUSBPORT_DEVICE_HANDLE)Urb->UrbHeader.UsbdDeviceHandle,
132  PipeHandle))
133  {
135  }
136 
137  Endpoint = PipeHandle->Endpoint;
138 
139  KeAcquireSpinLock(&Endpoint->EndpointSpinLock, &Endpoint->EndpointOldIrql);
140 
141  if (IsListEmpty(&Endpoint->TransferList))
142  {
143  if (Urb->UrbHeader.UsbdFlags & USBD_FLAG_NOT_ISO_TRANSFER)
144  {
145  KeAcquireSpinLockAtDpcLevel(&FdoExtension->MiniportSpinLock);
146 
147  Packet->SetEndpointDataToggle(FdoExtension->MiniPortExt,
148  Endpoint + 1,
149  0);
150 
151  KeReleaseSpinLockFromDpcLevel(&FdoExtension->MiniportSpinLock);
152  }
153 
155  }
156  else
157  {
159  }
160 
161  Endpoint->Flags |= ENDPOINT_FLAG_QUEUENE_EMPTY;
162 
163  KeAcquireSpinLockAtDpcLevel(&FdoExtension->MiniportSpinLock);
164 
165  Packet->SetEndpointStatus(FdoExtension->MiniPortExt,
166  Endpoint + 1,
168 
169  KeReleaseSpinLockFromDpcLevel(&FdoExtension->MiniportSpinLock);
170  KeReleaseSpinLock(&Endpoint->EndpointSpinLock, Endpoint->EndpointOldIrql);
171 
172  return Status;
173 }
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1548
#define USBPORT_ENDPOINT_RUN
Definition: usbmport.h:20
#define USBD_STATUS_ERROR_BUSY
Definition: usb.h:193
#define DPRINT_URB(...)
Definition: usbdebug.h:145
#define ENDPOINT_FLAG_QUEUENE_EMPTY
Definition: usbport.h:113
VOID NTAPI KeAcquireSpinLockAtDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:192
LONG NTSTATUS
Definition: precomp.h:26
#define USBD_FLAG_NOT_ISO_TRANSFER
Definition: usbport.h:121
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
LIST_ENTRY TransferList
Definition: usbport.h:227
KIRQL EndpointOldIrql
Definition: usbport.h:215
VOID NTAPI KeReleaseSpinLockFromDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:215
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
#define USBD_STATUS_SUCCESS
Definition: usb.h:170
NTSTATUS NTAPI USBPORT_USBDStatusToNtStatus(IN PURB Urb, IN USBD_STATUS USBDStatus)
Definition: usbport.c:485
BOOLEAN NTAPI USBPORT_ValidatePipeHandle(IN PUSBPORT_DEVICE_HANDLE DeviceHandle, IN PUSBPORT_PIPE_HANDLE PipeHandle)
Definition: endpoint.c:469
Status
Definition: gdiplustypes.h:24
static HANDLE PipeHandle
Definition: dhcpcsvc.c:21
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define USBD_STATUS_INVALID_PIPE_HANDLE
Definition: usb.h:194
KSPIN_LOCK EndpointSpinLock
Definition: usbport.h:214

Referenced by USBPORT_HandleSubmitURB(), and USBPORT_SyncResetPipeAndClearStall().

◆ USBPORT_SyncResetPipeAndClearStall()

NTSTATUS NTAPI USBPORT_SyncResetPipeAndClearStall ( IN PDEVICE_OBJECT  FdoDevice,
IN PIRP  Irp,
IN PURB  Urb 
)

Definition at line 224 of file urb.c.

227 {
230  PUSBPORT_ENDPOINT Endpoint;
231  ULONG EndpointState;
233 
234  DPRINT_URB("USBPORT_SyncResetPipeAndClearStall: ... \n");
235 
236  ASSERT(Urb->UrbHeader.UsbdDeviceHandle);
237  ASSERT(Urb->UrbHeader.Length == sizeof(struct _URB_PIPE_REQUEST));
238  ASSERT(Urb->UrbPipeRequest.PipeHandle);
239 
240  DeviceHandle = Urb->UrbHeader.UsbdDeviceHandle;
241  PipeHandle = Urb->UrbPipeRequest.PipeHandle;
242 
244  {
245  return USBPORT_USBDStatusToNtStatus(Urb,
247  }
248 
250  {
252  }
253 
254  Endpoint = PipeHandle->Endpoint;
255  InterlockedIncrement(&DeviceHandle->DeviceHandleLock);
256 
258  {
259  Urb->UrbHeader.UsbdFlags |= USBD_FLAG_NOT_ISO_TRANSFER;
260  Status = USBPORT_ClearStall(FdoDevice, Irp, Urb);
261  }
262  else
263  {
265  }
266 
267  if (NT_SUCCESS(Status))
268  {
269  Status = USBPORT_ResetPipe(FdoDevice, Irp, Urb);
270 
272  {
273  while (TRUE)
274  {
276  &Endpoint->EndpointOldIrql);
277 
278  EndpointState = USBPORT_GetEndpointState(Endpoint);
279 
280  if (EndpointState == USBPORT_ENDPOINT_PAUSED &&
281  IsListEmpty(&Endpoint->TransferList))
282  {
283  USBPORT_SetEndpointState(Endpoint,
285  }
286 
288  Endpoint->EndpointOldIrql);
289 
290  if (EndpointState == USBPORT_ENDPOINT_ACTIVE)
291  {
292  break;
293  }
294 
295  USBPORT_Wait(FdoDevice, 1);
296  }
297  }
298  }
299 
300  InterlockedDecrement(&DeviceHandle->DeviceHandleLock);
301 
302  return Status;
303 }
#define USBPORT_ENDPOINT_ACTIVE
Definition: usbmport.h:15
#define TRUE
Definition: types.h:120
_Inout_ PUSB_DEVICE_HANDLE DeviceHandle
Definition: hubbusif.h:121
#define PIPE_HANDLE_FLAG_NULL_PACKET_SIZE
Definition: usbport.h:126
_In_ PIRP Irp
Definition: csq.h:116
#define DPRINT_URB(...)
Definition: usbdebug.h:145
LONG NTSTATUS
Definition: precomp.h:26
#define USBD_FLAG_NOT_ISO_TRANSFER
Definition: usbport.h:121
NTSTATUS NTAPI USBPORT_ClearStall(IN PDEVICE_OBJECT FdoDevice, IN PIRP Irp, IN PURB Urb)
Definition: urb.c:177
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
NTSTATUS NTAPI USBPORT_Wait(IN PVOID MiniPortExtension, IN ULONG Milliseconds)
Definition: usbport.c:543
LIST_ENTRY TransferList
Definition: usbport.h:227
KIRQL EndpointOldIrql
Definition: usbport.h:215
#define USBPORT_ENDPOINT_PAUSED
Definition: usbmport.h:14
VOID NTAPI USBPORT_SetEndpointState(IN PUSBPORT_ENDPOINT Endpoint, IN ULONG State)
Definition: endpoint.c:363
NTSTATUS NTAPI USBPORT_ResetPipe(IN PDEVICE_OBJECT FdoDevice, IN PIRP Irp, IN PURB Urb)
Definition: urb.c:114
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define USBD_STATUS_SUCCESS
Definition: usb.h:170
ULONG NTAPI USBPORT_GetEndpointState(IN PUSBPORT_ENDPOINT Endpoint)
Definition: endpoint.c:332
#define InterlockedDecrement
Definition: armddk.h:52
NTSTATUS NTAPI USBPORT_USBDStatusToNtStatus(IN PURB Urb, IN USBD_STATUS USBDStatus)
Definition: usbport.c:485
#define USBPORT_TRANSFER_TYPE_ISOCHRONOUS
Definition: usbmport.h:7
BOOLEAN NTAPI USBPORT_ValidatePipeHandle(IN PUSBPORT_DEVICE_HANDLE DeviceHandle, IN PUSBPORT_PIPE_HANDLE PipeHandle)
Definition: endpoint.c:469
USBPORT_ENDPOINT_PROPERTIES EndpointProperties
Definition: usbport.h:210
Status
Definition: gdiplustypes.h:24
#define InterlockedIncrement
Definition: armddk.h:53
static HANDLE PipeHandle
Definition: dhcpcsvc.c:21
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
unsigned int ULONG
Definition: retypes.h:1
#define USBD_STATUS_INVALID_PIPE_HANDLE
Definition: usb.h:194
KSPIN_LOCK EndpointSpinLock
Definition: usbport.h:214

Referenced by USBPORT_HandleSubmitURB().

◆ USBPORT_ValidateTransferParametersURB()

NTSTATUS NTAPI USBPORT_ValidateTransferParametersURB ( IN PURB  Urb)

Definition at line 633 of file urb.c.

634 {
635  struct _URB_CONTROL_TRANSFER *UrbRequest;
636  PMDL Mdl;
637 
638  DPRINT_URB("USBPORT_ValidateTransferParametersURB: Urb - %p\n", Urb);
639 
640  UrbRequest = &Urb->UrbControlTransfer;
641 
642  if (UrbRequest->TransferBuffer == NULL &&
643  UrbRequest->TransferBufferMDL == NULL &&
644  UrbRequest->TransferBufferLength > 0)
645  {
646  DPRINT1("USBPORT_ValidateTransferParametersURB: Not valid parameter\n");
647  USBPORT_DumpingURB(Urb);
649  }
650 
651  if ((UrbRequest->TransferBuffer != NULL) &&
652  (UrbRequest->TransferBufferMDL != NULL) &&
653  UrbRequest->TransferBufferLength == 0)
654  {
655  DPRINT1("USBPORT_ValidateTransferParametersURB: Not valid parameter\n");
656  USBPORT_DumpingURB(Urb);
658  }
659 
660  if (UrbRequest->TransferBuffer != NULL &&
661  UrbRequest->TransferBufferMDL == NULL &&
662  UrbRequest->TransferBufferLength != 0)
663  {
664  DPRINT_URB("USBPORT_ValidateTransferParametersURB: TransferBuffer - %p, TransferBufferLength - %x\n",
665  UrbRequest->TransferBuffer,
666  UrbRequest->TransferBufferLength);
667 
668  Mdl = IoAllocateMdl(UrbRequest->TransferBuffer,
669  UrbRequest->TransferBufferLength,
670  FALSE,
671  FALSE,
672  NULL);
673 
674  if (!Mdl)
675  {
676  DPRINT1("USBPORT_ValidateTransferParametersURB: Not allocated Mdl\n");
678  }
679 
681 
682  UrbRequest->TransferBufferMDL = Mdl;
683  Urb->UrbHeader.UsbdFlags |= USBD_FLAG_ALLOCATED_MDL;
684 
685  DPRINT_URB("USBPORT_ValidateTransferParametersURB: Mdl - %p\n", Mdl);
686  }
687 
688  return STATUS_SUCCESS;
689 }
VOID NTAPI USBPORT_DumpingURB(IN PURB Urb)
Definition: debug.c:225
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define DPRINT_URB(...)
Definition: usbdebug.h:145
VOID NTAPI MmBuildMdlForNonPagedPool(IN PMDL Mdl)
Definition: mdlsup.c:428
smooth NULL
Definition: ftsmooth.c:416
PMDL TransferBufferMDL
Definition: usb.h:472
#define USBD_FLAG_ALLOCATED_MDL
Definition: usbport.h:120
PMDL NTAPI IoAllocateMdl(IN PVOID VirtualAddress, IN ULONG Length, IN BOOLEAN SecondaryBuffer, IN BOOLEAN ChargeQuota, IN PIRP Irp)
Definition: iomdl.c:22
#define DPRINT1
Definition: precomp.h:8
return STATUS_SUCCESS
Definition: btrfs.c:2777
PVOID TransferBuffer
Definition: usb.h:471
ULONG TransferBufferLength
Definition: usb.h:470

Referenced by USBPORT_ValidateURB().

◆ USBPORT_ValidateURB()

NTSTATUS NTAPI USBPORT_ValidateURB ( IN PDEVICE_OBJECT  FdoDevice,
IN PIRP  Irp,
IN PURB  Urb,
IN BOOLEAN  IsControlTransfer,
IN BOOLEAN  IsNullTransfer 
)

Definition at line 693 of file urb.c.

698 {
699  struct _URB_CONTROL_TRANSFER *UrbRequest;
702  USBD_STATUS USBDStatus;
703 
704  UrbRequest = &Urb->UrbControlTransfer;
705 
706  if (UrbRequest->UrbLink)
707  {
710 
711  DPRINT1("USBPORT_ValidateURB: Not valid parameter\n");
712 
713  USBPORT_DumpingURB(Urb);
714  return Status;
715  }
716 
717  DeviceHandle = Urb->UrbHeader.UsbdDeviceHandle;
718 
719  if (IsControlTransfer)
720  {
722  UrbRequest->PipeHandle = &DeviceHandle->PipeHandle;
723  }
724 
725  if (UrbRequest->TransferFlags & USBD_DEFAULT_PIPE_TRANSFER)
726  {
727  if (UrbRequest->TransferBufferLength > 0x1000)
728  {
731 
732  DPRINT1("USBPORT_ValidateURB: Not valid parameter\n");
733 
734  USBPORT_DumpingURB(Urb);
735  return Status;
736  }
737 
738  if (Urb->UrbHeader.Function == URB_FUNCTION_CONTROL_TRANSFER)
739  {
740  UrbRequest->PipeHandle = &DeviceHandle->PipeHandle;
741  }
742  }
743 
745  {
748 
749  DPRINT1("USBPORT_ValidateURB: Not valid pipe handle\n");
750 
751  USBPORT_DumpingURB(Urb);
752  return Status;
753  }
754 
755  UrbRequest->hca.Reserved8[0] = NULL; // Transfer
756 
757  if (IsNullTransfer)
758  {
759  UrbRequest->TransferBuffer = 0;
760  UrbRequest->TransferBufferMDL = NULL;
761  UrbRequest->TransferBufferLength = 0;
762  }
763  else
764  {
766 
767  if (!NT_SUCCESS(Status))
768  {
769  return Status;
770  }
771  }
772 
773  USBDStatus = USBPORT_AllocateTransfer(FdoDevice,
774  Urb,
775  DeviceHandle,
776  Irp,
777  NULL);
778 
779  Status = USBPORT_USBDStatusToNtStatus(Urb, USBDStatus);
780 
781  if (!NT_SUCCESS(Status))
782  {
783  DPRINT1("USBPORT_ValidateURB: Not allocated transfer\n");
784  }
785 
786  return Status;
787 }
VOID NTAPI USBPORT_DumpingURB(IN PURB Urb)
Definition: debug.c:225
_Inout_ PUSB_DEVICE_HANDLE DeviceHandle
Definition: hubbusif.h:121
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
struct _URB * UrbLink
Definition: usb.h:473
smooth NULL
Definition: ftsmooth.c:416
struct _URB_HCD_AREA hca
Definition: usb.h:474
PMDL TransferBufferMDL
Definition: usb.h:472
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define USBD_STATUS_INVALID_PARAMETER
Definition: usb.h:192
NTSTATUS NTAPI USBPORT_ValidateTransferParametersURB(IN PURB Urb)
Definition: urb.c:633
LONG USBD_STATUS
Definition: usb.h:165
NTSTATUS NTAPI USBPORT_USBDStatusToNtStatus(IN PURB Urb, IN USBD_STATUS USBDStatus)
Definition: usbport.c:485
BOOLEAN NTAPI USBPORT_ValidatePipeHandle(IN PUSBPORT_DEVICE_HANDLE DeviceHandle, IN PUSBPORT_PIPE_HANDLE PipeHandle)
Definition: endpoint.c:469
Status
Definition: gdiplustypes.h:24
USBD_PIPE_HANDLE PipeHandle
Definition: usb.h:468
USBD_STATUS NTAPI USBPORT_AllocateTransfer(IN PDEVICE_OBJECT FdoDevice, IN PURB Urb, IN PUSBPORT_DEVICE_HANDLE DeviceHandle, IN PIRP Irp, IN PRKEVENT Event)
Definition: usbport.c:2521
#define USBD_DEFAULT_PIPE_TRANSFER
Definition: usb.h:156
#define DPRINT1
Definition: precomp.h:8
#define URB_FUNCTION_CONTROL_TRANSFER
Definition: usb.h:94
ULONG TransferFlags
Definition: usb.h:469
#define USBD_STATUS_INVALID_PIPE_HANDLE
Definition: usb.h:194
PVOID TransferBuffer
Definition: usb.h:471
ULONG TransferBufferLength
Definition: usb.h:470

Referenced by USBPORT_HandleSubmitURB().