ReactOS  0.4.14-dev-41-g31d7680
misc.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS Universal Serial Bus Hub Driver
3  * LICENSE: GPL - See COPYING in the top level directory
4  * FILE: drivers/usb/usbhub/misc.c
5  * PURPOSE: Misc helper functions
6  * PROGRAMMERS:
7  * Michael Martin (michael.martin@reactos.org)
8  * Johannes Anderwald (johannes.anderwald@reactos.org)
9  */
10 
11 #include "usbhub.h"
12 
13 #define NDEBUG
14 #include <debug.h>
15 
16 VOID
18 {
19  DPRINT1("Dumping Device Descriptor %x\n", DeviceDescriptor);
20  DPRINT1("bLength %x\n", DeviceDescriptor->bLength);
21  DPRINT1("bDescriptorType %x\n", DeviceDescriptor->bDescriptorType);
22  DPRINT1("bcdUSB %x\n", DeviceDescriptor->bcdUSB);
23  DPRINT1("bDeviceClass %x\n", DeviceDescriptor->bDeviceClass);
24  DPRINT1("bDeviceSubClass %x\n", DeviceDescriptor->bDeviceSubClass);
25  DPRINT1("bDeviceProtocol %x\n", DeviceDescriptor->bDeviceProtocol);
26  DPRINT1("bMaxPacketSize0 %x\n", DeviceDescriptor->bMaxPacketSize0);
27  DPRINT1("idVendor %x\n", DeviceDescriptor->idVendor);
28  DPRINT1("idProduct %x\n", DeviceDescriptor->idProduct);
29  DPRINT1("bcdDevice %x\n", DeviceDescriptor->bcdDevice);
30  DPRINT1("iManufacturer %x\n", DeviceDescriptor->iManufacturer);
31  DPRINT1("iProduct %x\n", DeviceDescriptor->iProduct);
32  DPRINT1("iSerialNumber %x\n", DeviceDescriptor->iSerialNumber);
33  DPRINT1("bNumConfigurations %x\n", DeviceDescriptor->bNumConfigurations);
34 }
35 
36 //----------------------------------------------------------------------------------------
37 VOID
39 {
40  DPRINT1("Dumping ConfigurationDescriptor %x\n", ConfigurationDescriptor);
41  DPRINT1("bLength %x\n", ConfigurationDescriptor->bLength);
42  DPRINT1("bDescriptorType %x\n", ConfigurationDescriptor->bDescriptorType);
43  DPRINT1("wTotalLength %x\n", ConfigurationDescriptor->wTotalLength);
44  DPRINT1("bNumInterfaces %x\n", ConfigurationDescriptor->bNumInterfaces);
45  DPRINT1("bConfigurationValue %x\n", ConfigurationDescriptor->bConfigurationValue);
46  DPRINT1("iConfiguration %x\n", ConfigurationDescriptor->iConfiguration);
47  DPRINT1("bmAttributes %x\n", ConfigurationDescriptor->bmAttributes);
48  DPRINT1("MaxPower %x\n", ConfigurationDescriptor->MaxPower);
49 }
50 
51 VOID
53 {
54  PUSB_INTERFACE_DESCRIPTOR InterfaceDescriptor;
55  PUSB_ENDPOINT_DESCRIPTOR EndpointDescriptor;
56  LONG i, j;
57 
58  DPRINT1("Dumping ConfigurationDescriptor %x\n", ConfigurationDescriptor);
59  DPRINT1("bLength %x\n", ConfigurationDescriptor->bLength);
60  DPRINT1("bDescriptorType %x\n", ConfigurationDescriptor->bDescriptorType);
61  DPRINT1("wTotalLength %x\n", ConfigurationDescriptor->wTotalLength);
62  DPRINT1("bNumInterfaces %x\n", ConfigurationDescriptor->bNumInterfaces);
63  DPRINT1("bConfigurationValue %x\n", ConfigurationDescriptor->bConfigurationValue);
64  DPRINT1("iConfiguration %x\n", ConfigurationDescriptor->iConfiguration);
65  DPRINT1("bmAttributes %x\n", ConfigurationDescriptor->bmAttributes);
66  DPRINT1("MaxPower %x\n", ConfigurationDescriptor->MaxPower);
67 
68  InterfaceDescriptor = (PUSB_INTERFACE_DESCRIPTOR) ((ULONG_PTR)ConfigurationDescriptor + sizeof(USB_CONFIGURATION_DESCRIPTOR));
69 
70  for (i=0; i < ConfigurationDescriptor->bNumInterfaces; i++)
71  {
72  DPRINT1("- Dumping InterfaceDescriptor %x\n", InterfaceDescriptor);
73  DPRINT1(" bLength %x\n", InterfaceDescriptor->bLength);
74  DPRINT1(" bDescriptorType %x\n", InterfaceDescriptor->bDescriptorType);
75  DPRINT1(" bInterfaceNumber %x\n", InterfaceDescriptor->bInterfaceNumber);
76  DPRINT1(" bAlternateSetting %x\n", InterfaceDescriptor->bAlternateSetting);
77  DPRINT1(" bNumEndpoints %x\n", InterfaceDescriptor->bNumEndpoints);
78  DPRINT1(" bInterfaceClass %x\n", InterfaceDescriptor->bInterfaceClass);
79  DPRINT1(" bInterfaceSubClass %x\n", InterfaceDescriptor->bInterfaceSubClass);
80  DPRINT1(" bInterfaceProtocol %x\n", InterfaceDescriptor->bInterfaceProtocol);
81  DPRINT1(" iInterface %x\n", InterfaceDescriptor->iInterface);
82 
83  EndpointDescriptor = (PUSB_ENDPOINT_DESCRIPTOR) ((ULONG_PTR)InterfaceDescriptor + sizeof(USB_INTERFACE_DESCRIPTOR));
84 
85  for (j=0; j < InterfaceDescriptor->bNumEndpoints; j++)
86  {
87  DPRINT1(" bLength %x\n", EndpointDescriptor->bLength);
88  DPRINT1(" bDescriptorType %x\n", EndpointDescriptor->bDescriptorType);
89  DPRINT1(" bEndpointAddress %x\n", EndpointDescriptor->bEndpointAddress);
90  DPRINT1(" bmAttributes %x\n", EndpointDescriptor->bmAttributes);
91  DPRINT1(" wMaxPacketSize %x\n", EndpointDescriptor->wMaxPacketSize);
92  DPRINT1(" bInterval %x\n", EndpointDescriptor->bInterval);
93  EndpointDescriptor = (PUSB_ENDPOINT_DESCRIPTOR) ((ULONG_PTR)EndpointDescriptor + sizeof(USB_ENDPOINT_DESCRIPTOR));
94  }
95  InterfaceDescriptor = (PUSB_INTERFACE_DESCRIPTOR)(ULONG_PTR)EndpointDescriptor;
96  }
97 }
98 
100 NTAPI
103  IN PIRP Irp,
104  IN PVOID Context)
105 {
106  if (Irp->PendingReturned)
108 
110 }
111 
112 NTSTATUS
115  IN PIRP Irp)
116 {
117  KEVENT Event;
119 
122 
124 
126  if (Status == STATUS_PENDING)
127  {
129  if (NT_SUCCESS(Status))
130  Status = Irp->IoStatus.Status;
131  }
132 
133  return Status;
134 }
135 
136 NTSTATUS
139  IN PIRP Irp)
140 {
141  PDEVICE_OBJECT LowerDevice = ((PHUB_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->LowerDeviceObject;
142 
143  ASSERT(LowerDevice);
144 
146  return IoCallDriver(LowerDevice, Irp);
147 }
148 
149 NTSTATUS
151  IN PDEVICE_OBJECT RootHubDeviceObject,
153  OUT PVOID OutParameter1,
154  OUT PVOID OutParameter2)
155 {
156  KEVENT Event;
157  PIRP Irp;
160  PIO_STACK_LOCATION Stack = NULL;
161 
163 
164  //
165  // Build Control Request
166  //
168  RootHubDeviceObject,
169  NULL, 0,
170  NULL, 0,
171  TRUE,
172  &Event,
173  &IoStatus);
174 
175  if (Irp == NULL)
176  {
177  DPRINT("Usbhub: IoBuildDeviceIoControlRequest() failed\n");
179  }
180 
181  //
182  // Initialize the status block before sending the IRP
183  //
185  IoStatus.Information = 0;
186 
187  //
188  // Get Next Stack Location and Initialize it
189  //
191  Stack->Parameters.Others.Argument1 = OutParameter1;
192  Stack->Parameters.Others.Argument2 = OutParameter2;
193 
194  //
195  // Call RootHub
196  //
197  Status = IoCallDriver(RootHubDeviceObject, Irp);
198 
199  //
200  // Its ok to block here as this function is called in an nonarbitrary thread
201  //
202  if (Status == STATUS_PENDING)
203  {
205  Status = IoStatus.Status;
206  }
207 
208  //
209  // The IO Manager will free the IRP
210  //
211 
212  return Status;
213 }
VOID DumpFullConfigurationDescriptor(PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor)
Definition: misc.c:52
#define IN
Definition: typedefs.h:38
#define TRUE
Definition: types.h:120
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG IoControlCode
Definition: fltkernel.h:1383
#define STATUS_MORE_PROCESSING_REQUIRED
Definition: shellext.h:63
IN PLARGE_INTEGER IN ULONG IN BOOLEAN IN ULONG IN BOOLEAN OUT PIO_STATUS_BLOCK IoStatus
Definition: fatprocs.h:2650
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
struct _USB_INTERFACE_DESCRIPTOR * PUSB_INTERFACE_DESCRIPTOR
struct _HUB_DEVICE_EXTENSION * PHUB_DEVICE_EXTENSION
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
NTSTATUS NTAPI ForwardIrpAndWait(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: misc.c:33
VOID DumpConfigurationDescriptor(PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor)
Definition: misc.c:38
NTSTATUS NTAPI ForwardIrpAndWaitCompletion(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context)
Definition: misc.c:101
#define IoSetCompletionRoutine(_Irp, _CompletionRoutine, _Context, _InvokeOnSuccess, _InvokeOnError, _InvokeOnCancel)
Definition: irp.cpp:515
uint32_t ULONG_PTR
Definition: typedefs.h:63
FORCEINLINE VOID IoCopyCurrentIrpStackLocationToNext(_Inout_ PIRP Irp)
Definition: iofuncs.h:2820
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
long LONG
Definition: pedump.c:60
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:435
struct _USB_INTERFACE_DESCRIPTOR USB_INTERFACE_DESCRIPTOR
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
struct _USB_ENDPOINT_DESCRIPTOR * PUSB_ENDPOINT_DESCRIPTOR
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
const KSDEVICE_DESCRIPTOR DeviceDescriptor
Definition: splitter.c:257
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
struct _USB_ENDPOINT_DESCRIPTOR USB_ENDPOINT_DESCRIPTOR
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
VOID DumpDeviceDescriptor(PUSB_DEVICE_DESCRIPTOR DeviceDescriptor)
Definition: misc.c:17
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2647
struct _USB_CONFIGURATION_DESCRIPTOR USB_CONFIGURATION_DESCRIPTOR
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
NTSTATUS NTAPI ForwardIrpAndForget(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: misc.c:59
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
PIRP NTAPI IoBuildDeviceIoControlRequest(IN ULONG IoControlCode, IN PDEVICE_OBJECT DeviceObject, IN PVOID InputBuffer, IN ULONG InputBufferLength, IN PVOID OutputBuffer, IN ULONG OutputBufferLength, IN BOOLEAN InternalDeviceIoControl, IN PKEVENT Event, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:881
#define DPRINT1
Definition: precomp.h:8
#define OUT
Definition: typedefs.h:39
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:409
unsigned int ULONG
Definition: retypes.h:1
#define IO_NO_INCREMENT
Definition: iotypes.h:566
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
NTSTATUS SubmitRequestToRootHub(IN PDEVICE_OBJECT RootHubDeviceObject, IN ULONG IoControlCode, OUT PVOID OutParameter1, OUT PVOID OutParameter2)
Definition: misc.c:150