[USB]
[reactos.git] / reactos / drivers / usb / usbhub / misc.c
1 /*
2 * PROJECT: ReactOS Universal Serial Bus Hub Driver
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: drivers/usb/usbhub/fdo.c
5 * PURPOSE: Misc helper functions
6 * PROGRAMMERS:
7 * Michael Martin (michael.martin@reactos.org)
8 * Johannes Anderwald (johannes.anderwald@reactos.org)
9 */
10 #include "usbhub.h"
11 #include <stdarg.h>
12
13 VOID
14 DumpDeviceDescriptor(PUSB_DEVICE_DESCRIPTOR DeviceDescriptor)
15 {
16 DPRINT1("Dumping Device Descriptor %x\n", DeviceDescriptor);
17 DPRINT1("bLength %x\n", DeviceDescriptor->bLength);
18 DPRINT1("bDescriptorType %x\n", DeviceDescriptor->bDescriptorType);
19 DPRINT1("bcdUSB %x\n", DeviceDescriptor->bcdUSB);
20 DPRINT1("bDeviceClass %x\n", DeviceDescriptor->bDeviceClass);
21 DPRINT1("bDeviceSubClass %x\n", DeviceDescriptor->bDeviceSubClass);
22 DPRINT1("bDeviceProtocol %x\n", DeviceDescriptor->bDeviceProtocol);
23 DPRINT1("bMaxPacketSize0 %x\n", DeviceDescriptor->bMaxPacketSize0);
24 DPRINT1("idVendor %x\n", DeviceDescriptor->idVendor);
25 DPRINT1("idProduct %x\n", DeviceDescriptor->idProduct);
26 DPRINT1("bcdDevice %x\n", DeviceDescriptor->bcdDevice);
27 DPRINT1("iManufacturer %x\n", DeviceDescriptor->iManufacturer);
28 DPRINT1("iProduct %x\n", DeviceDescriptor->iProduct);
29 DPRINT1("iSerialNumber %x\n", DeviceDescriptor->iSerialNumber);
30 DPRINT1("bNumConfigurations %x\n", DeviceDescriptor->bNumConfigurations);
31 }
32
33 //----------------------------------------------------------------------------------------
34 VOID
35 DumpConfigurationDescriptor(PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor)
36 {
37 DPRINT1("Dumping ConfigurationDescriptor %x\n", ConfigurationDescriptor);
38 DPRINT1("bLength %x\n", ConfigurationDescriptor->bLength);
39 DPRINT1("bDescriptorType %x\n", ConfigurationDescriptor->bDescriptorType);
40 DPRINT1("wTotalLength %x\n", ConfigurationDescriptor->wTotalLength);
41 DPRINT1("bNumInterfaces %x\n", ConfigurationDescriptor->bNumInterfaces);
42 DPRINT1("bConfigurationValue %x\n", ConfigurationDescriptor->bConfigurationValue);
43 DPRINT1("iConfiguration %x\n", ConfigurationDescriptor->iConfiguration);
44 DPRINT1("bmAttributes %x\n", ConfigurationDescriptor->bmAttributes);
45 DPRINT1("MaxPower %x\n", ConfigurationDescriptor->MaxPower);
46 }
47
48 VOID
49 DumpFullConfigurationDescriptor(PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor)
50 {
51 PUSB_INTERFACE_DESCRIPTOR InterfaceDescriptor;
52 PUSB_ENDPOINT_DESCRIPTOR EndpointDescriptor;
53 LONG i, j;
54
55 DPRINT1("Dumping ConfigurationDescriptor %x\n", ConfigurationDescriptor);
56 DPRINT1("bLength %x\n", ConfigurationDescriptor->bLength);
57 DPRINT1("bDescriptorType %x\n", ConfigurationDescriptor->bDescriptorType);
58 DPRINT1("wTotalLength %x\n", ConfigurationDescriptor->wTotalLength);
59 DPRINT1("bNumInterfaces %x\n", ConfigurationDescriptor->bNumInterfaces);
60 DPRINT1("bConfigurationValue %x\n", ConfigurationDescriptor->bConfigurationValue);
61 DPRINT1("iConfiguration %x\n", ConfigurationDescriptor->iConfiguration);
62 DPRINT1("bmAttributes %x\n", ConfigurationDescriptor->bmAttributes);
63 DPRINT1("MaxPower %x\n", ConfigurationDescriptor->MaxPower);
64
65 InterfaceDescriptor = (PUSB_INTERFACE_DESCRIPTOR) ((ULONG_PTR)ConfigurationDescriptor + sizeof(USB_CONFIGURATION_DESCRIPTOR));
66
67 for (i=0; i < ConfigurationDescriptor->bNumInterfaces; i++)
68 {
69 DPRINT1("- Dumping InterfaceDescriptor %x\n", InterfaceDescriptor);
70 DPRINT1(" bLength %x\n", InterfaceDescriptor->bLength);
71 DPRINT1(" bDescriptorType %x\n", InterfaceDescriptor->bDescriptorType);
72 DPRINT1(" bInterfaceNumber %x\n", InterfaceDescriptor->bInterfaceNumber);
73 DPRINT1(" bAlternateSetting %x\n", InterfaceDescriptor->bAlternateSetting);
74 DPRINT1(" bNumEndpoints %x\n", InterfaceDescriptor->bNumEndpoints);
75 DPRINT1(" bInterfaceClass %x\n", InterfaceDescriptor->bInterfaceClass);
76 DPRINT1(" bInterfaceSubClass %x\n", InterfaceDescriptor->bInterfaceSubClass);
77 DPRINT1(" bInterfaceProtocol %x\n", InterfaceDescriptor->bInterfaceProtocol);
78 DPRINT1(" iInterface %x\n", InterfaceDescriptor->iInterface);
79
80 EndpointDescriptor = (PUSB_ENDPOINT_DESCRIPTOR) ((ULONG_PTR)InterfaceDescriptor + sizeof(USB_INTERFACE_DESCRIPTOR));
81
82 for (j=0; j < InterfaceDescriptor->bNumEndpoints; j++)
83 {
84 DPRINT1(" bLength %x\n", EndpointDescriptor->bLength);
85 DPRINT1(" bDescriptorType %x\n", EndpointDescriptor->bDescriptorType);
86 DPRINT1(" bEndpointAddress %x\n", EndpointDescriptor->bEndpointAddress);
87 DPRINT1(" bmAttributes %x\n", EndpointDescriptor->bmAttributes);
88 DPRINT1(" wMaxPacketSize %x\n", EndpointDescriptor->wMaxPacketSize);
89 DPRINT1(" bInterval %x\n", EndpointDescriptor->bInterval);
90 EndpointDescriptor = (PUSB_ENDPOINT_DESCRIPTOR) ((ULONG_PTR)EndpointDescriptor + sizeof(USB_ENDPOINT_DESCRIPTOR));
91 }
92 InterfaceDescriptor = (PUSB_INTERFACE_DESCRIPTOR)(ULONG_PTR)EndpointDescriptor;
93 }
94 }
95
96 NTSTATUS
97 NTAPI
98 ForwardIrpAndWaitCompletion(
99 IN PDEVICE_OBJECT DeviceObject,
100 IN PIRP Irp,
101 IN PVOID Context)
102 {
103 if (Irp->PendingReturned)
104 KeSetEvent((PKEVENT)Context, IO_NO_INCREMENT, FALSE);
105
106 return STATUS_MORE_PROCESSING_REQUIRED;
107 }
108
109 NTSTATUS
110 ForwardIrpAndWait(
111 IN PDEVICE_OBJECT DeviceObject,
112 IN PIRP Irp)
113 {
114 KEVENT Event;
115 NTSTATUS Status;
116
117 KeInitializeEvent(&Event, NotificationEvent, FALSE);
118 IoCopyCurrentIrpStackLocationToNext(Irp);
119
120 IoSetCompletionRoutine(Irp, ForwardIrpAndWaitCompletion, &Event, TRUE, TRUE, TRUE);
121
122 Status = IoCallDriver(DeviceObject, Irp);
123 if (Status == STATUS_PENDING)
124 {
125 Status = KeWaitForSingleObject(&Event, Suspended, KernelMode, FALSE, NULL);
126 if (NT_SUCCESS(Status))
127 Status = Irp->IoStatus.Status;
128 }
129
130 return Status;
131 }
132
133 NTSTATUS
134 ForwardIrpAndForget(
135 IN PDEVICE_OBJECT DeviceObject,
136 IN PIRP Irp)
137 {
138 PDEVICE_OBJECT LowerDevice = ((PHUB_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->LowerDeviceObject;
139
140 ASSERT(LowerDevice);
141
142 IoSkipCurrentIrpStackLocation(Irp);
143 return IoCallDriver(LowerDevice, Irp);
144 }
145