xref: /reactos/drivers/usb/usbport/debug.c (revision 50cf16b3)
1 /*
2  * PROJECT:     ReactOS USB Port Driver
3  * LICENSE:     GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4  * PURPOSE:     USBPort debugging functions
5  * COPYRIGHT:   Copyright 2017 Vadim Galyant <vgal@rambler.ru>
6  */
7 
8 #include "usbport.h"
9 
10 #define NDEBUG
11 #include <debug.h>
12 
13 #define NDEBUG_USBPORT_MINIPORT
14 #define NDEBUG_USBPORT_URB
15 //#define NDEBUG_USBPORT_USB2
16 #include "usbdebug.h"
17 
18 ULONG
19 NTAPI
20 USBPORT_DbgPrint(IN PVOID MiniPortExtension,
21                  IN ULONG Level,
22                  IN PCH Format,
23                  ...)
24 {
25     DPRINT("USBPORT_DbgPrint: UNIMPLEMENTED. FIXME. \n");
26     return 0;
27 }
28 
29 ULONG
30 NTAPI
31 USBPORT_TestDebugBreak(IN PVOID MiniPortExtension)
32 {
33     DPRINT("USBPORT_TestDebugBreak: UNIMPLEMENTED. FIXME. \n");
34     return 0;
35 }
36 
37 ULONG
38 NTAPI
39 USBPORT_AssertFailure(PVOID MiniPortExtension,
40                       PVOID FailedAssertion,
41                       PVOID FileName,
42                       ULONG LineNumber,
43                       PCHAR Message)
44 {
45     DPRINT("USBPORT_AssertFailure: ... \n");
46     RtlAssert(FailedAssertion, FileName, LineNumber, Message);
47     return 0;
48 }
49 
50 VOID
51 NTAPI
52 USBPORT_BugCheck(IN PVOID MiniPortExtension)
53 {
54     DPRINT1("USBPORT_BugCheck: FIXME \n");
55     //KeBugCheckEx(BUGCODE_USB_DRIVER, ...);
56     ASSERT(FALSE);
57 }
58 
59 ULONG
60 NTAPI
61 USBPORT_LogEntry(IN PVOID MiniPortExtension,
62                  IN ULONG DriverTag,
63                  IN ULONG EnumTag,
64                  IN ULONG P1,
65                  IN ULONG P2,
66                  IN ULONG P3)
67 {
68     DPRINT_MINIPORT("USBPORT_LogEntry: MiniPortExtension - %p, EnumTag - %lx, P1 - %lx, P2 - %lx, P3 - %lx\n",
69            MiniPortExtension,
70            EnumTag,
71            P1,
72            P2,
73            P3);
74 
75     return 0;
76 }
77 
78 VOID
79 NTAPI
80 USBPORT_DumpingDeviceDescriptor(IN PUSB_DEVICE_DESCRIPTOR DeviceDescriptor)
81 {
82     if (!DeviceDescriptor)
83     {
84         return;
85     }
86 
87     DPRINT_URB("Dumping Device Descriptor - %p\n", DeviceDescriptor);
88     DPRINT_URB("bLength             - %x\n", DeviceDescriptor->bLength);
89     DPRINT_URB("bDescriptorType     - %x\n", DeviceDescriptor->bDescriptorType);
90     DPRINT_URB("bcdUSB              - %x\n", DeviceDescriptor->bcdUSB);
91     DPRINT_URB("bDeviceClass        - %x\n", DeviceDescriptor->bDeviceClass);
92     DPRINT_URB("bDeviceSubClass     - %x\n", DeviceDescriptor->bDeviceSubClass);
93     DPRINT_URB("bDeviceProtocol     - %x\n", DeviceDescriptor->bDeviceProtocol);
94     DPRINT_URB("bMaxPacketSize0     - %x\n", DeviceDescriptor->bMaxPacketSize0);
95     DPRINT_URB("idVendor            - %x\n", DeviceDescriptor->idVendor);
96     DPRINT_URB("idProduct           - %x\n", DeviceDescriptor->idProduct);
97     DPRINT_URB("bcdDevice           - %x\n", DeviceDescriptor->bcdDevice);
98     DPRINT_URB("iManufacturer       - %x\n", DeviceDescriptor->iManufacturer);
99     DPRINT_URB("iProduct            - %x\n", DeviceDescriptor->iProduct);
100     DPRINT_URB("iSerialNumber       - %x\n", DeviceDescriptor->iSerialNumber);
101     DPRINT_URB("bNumConfigurations  - %x\n", DeviceDescriptor->bNumConfigurations);
102 }
103 
104 VOID
105 NTAPI
106 USBPORT_DumpingConfiguration(IN PUSB_CONFIGURATION_DESCRIPTOR ConfigDescriptor)
107 {
108     PUSB_INTERFACE_DESCRIPTOR iDescriptor;
109     PUSB_ENDPOINT_DESCRIPTOR Descriptor;
110     ULONG ix;
111 
112     if (!ConfigDescriptor ||
113         ConfigDescriptor->bLength < sizeof(USB_CONFIGURATION_DESCRIPTOR))
114     {
115         return;
116     }
117 
118     DPRINT_URB("Dumping ConfigDescriptor - %p\n", ConfigDescriptor);
119     DPRINT_URB("bLength             - %x\n", ConfigDescriptor->bLength);
120     DPRINT_URB("bDescriptorType     - %x\n", ConfigDescriptor->bDescriptorType);
121     DPRINT_URB("wTotalLength        - %x\n", ConfigDescriptor->wTotalLength);
122     DPRINT_URB("bNumInterfaces      - %x\n", ConfigDescriptor->bNumInterfaces);
123     DPRINT_URB("bConfigurationValue - %x\n", ConfigDescriptor->bConfigurationValue);
124     DPRINT_URB("iConfiguration      - %x\n", ConfigDescriptor->iConfiguration);
125     DPRINT_URB("bmAttributes        - %x\n", ConfigDescriptor->bmAttributes);
126     DPRINT_URB("MaxPower            - %x\n", ConfigDescriptor->MaxPower);
127 
128     iDescriptor = (PUSB_INTERFACE_DESCRIPTOR)((ULONG_PTR)ConfigDescriptor +
129                                                          ConfigDescriptor->bLength);
130 
131     if (iDescriptor->bLength < sizeof(USB_INTERFACE_DESCRIPTOR))
132     {
133         return;
134     }
135 
136     DPRINT_URB("Dumping iDescriptor - %p\n", iDescriptor);
137     DPRINT_URB("bLength             - %x\n", iDescriptor->bLength);
138     DPRINT_URB("bDescriptorType     - %x\n", iDescriptor->bDescriptorType);
139     DPRINT_URB("bInterfaceNumber    - %x\n", iDescriptor->bInterfaceNumber);
140     DPRINT_URB("bAlternateSetting   - %x\n", iDescriptor->bAlternateSetting);
141     DPRINT_URB("bNumEndpoints       - %x\n", iDescriptor->bNumEndpoints);
142     DPRINT_URB("bInterfaceClass     - %x\n", iDescriptor->bInterfaceClass);
143     DPRINT_URB("bInterfaceSubClass  - %x\n", iDescriptor->bInterfaceSubClass);
144     DPRINT_URB("bInterfaceProtocol  - %x\n", iDescriptor->bInterfaceProtocol);
145     DPRINT_URB("iInterface          - %x\n", iDescriptor->iInterface);
146 
147     Descriptor = (PUSB_ENDPOINT_DESCRIPTOR)((ULONG_PTR)iDescriptor +
148                                                        iDescriptor->bLength);
149 
150     for (ix = 0; ix < iDescriptor->bNumEndpoints; ix++)
151     {
152         if (Descriptor->bLength < sizeof(USB_ENDPOINT_DESCRIPTOR))
153         {
154             return;
155         }
156 
157         DPRINT_URB("Dumping Descriptor  - %p\n", Descriptor);
158         DPRINT_URB("bLength             - %x\n", Descriptor->bLength);
159         DPRINT_URB("bDescriptorType     - %x\n", Descriptor->bDescriptorType);
160         DPRINT_URB("bEndpointAddress    - %x\n", Descriptor->bEndpointAddress);
161         DPRINT_URB("bmAttributes        - %x\n", Descriptor->bmAttributes);
162         DPRINT_URB("wMaxPacketSize      - %x\n", Descriptor->wMaxPacketSize);
163         DPRINT_URB("bInterval           - %x\n", Descriptor->bInterval);
164 
165         Descriptor += 1;
166     }
167 }
168 
169 VOID
170 NTAPI
171 USBPORT_DumpingCapabilities(IN PDEVICE_CAPABILITIES Capabilities)
172 {
173     if (!Capabilities)
174     {
175         return;
176     }
177 
178     DPRINT("Capabilities->Size              - %x\n", Capabilities->Size);
179     DPRINT("Capabilities->Version           - %x\n", Capabilities->Version);
180 
181     DPRINT("Capabilities->DeviceD1          - %x\n", Capabilities->DeviceD1);
182     DPRINT("Capabilities->DeviceD2          - %x\n", Capabilities->DeviceD2);
183     DPRINT("Capabilities->LockSupported     - %x\n", Capabilities->LockSupported);
184     DPRINT("Capabilities->EjectSupported    - %x\n", Capabilities->EjectSupported);
185     DPRINT("Capabilities->Removable         - %x\n", Capabilities->Removable);
186     DPRINT("Capabilities->DockDevice        - %x\n", Capabilities->DockDevice);
187     DPRINT("Capabilities->UniqueID          - %x\n", Capabilities->UniqueID);
188     DPRINT("Capabilities->SilentInstall     - %x\n", Capabilities->SilentInstall);
189     DPRINT("Capabilities->RawDeviceOK       - %x\n", Capabilities->RawDeviceOK);
190     DPRINT("Capabilities->SurpriseRemovalOK - %x\n", Capabilities->SurpriseRemovalOK);
191 
192     DPRINT("Capabilities->Address           - %x\n", Capabilities->Address);
193     DPRINT("Capabilities->UINumber          - %x\n", Capabilities->UINumber);
194 
195     DPRINT("Capabilities->DeviceState[0]    - %x\n", Capabilities->DeviceState[0]);
196     DPRINT("Capabilities->DeviceState[1]    - %x\n", Capabilities->DeviceState[1]);
197     DPRINT("Capabilities->DeviceState[2]    - %x\n", Capabilities->DeviceState[2]);
198     DPRINT("Capabilities->DeviceState[3]    - %x\n", Capabilities->DeviceState[3]);
199     DPRINT("Capabilities->DeviceState[4]    - %x\n", Capabilities->DeviceState[4]);
200     DPRINT("Capabilities->DeviceState[5]    - %x\n", Capabilities->DeviceState[5]);
201     DPRINT("Capabilities->DeviceState[6]    - %x\n", Capabilities->DeviceState[6]);
202 
203     DPRINT("Capabilities->SystemWake        - %x\n", Capabilities->SystemWake);
204     DPRINT("Capabilities->DeviceWake        - %x\n", Capabilities->DeviceWake);
205 
206     DPRINT("Capabilities->D1Latency         - %x\n", Capabilities->D1Latency);
207     DPRINT("Capabilities->D2Latency         - %x\n", Capabilities->D2Latency);
208     DPRINT("Capabilities->D3Latency         - %x\n", Capabilities->D3Latency);
209 }
210 
211 VOID
212 NTAPI
213 USBPORT_DumpingSetupPacket(IN PUSB_DEFAULT_PIPE_SETUP_PACKET SetupPacket)
214 {
215     DPRINT("SetupPacket->bmRequestType.B - %x\n", SetupPacket->bmRequestType.B);
216     DPRINT("SetupPacket->bRequest        - %x\n", SetupPacket->bRequest);
217     DPRINT("SetupPacket->wValue.LowByte  - %x\n", SetupPacket->wValue.LowByte);
218     DPRINT("SetupPacket->wValue.HiByte   - %x\n", SetupPacket->wValue.HiByte);
219     DPRINT("SetupPacket->wIndex.W        - %x\n", SetupPacket->wIndex.W);
220     DPRINT("SetupPacket->wLength         - %x\n", SetupPacket->wLength);
221 }
222 
223 VOID
224 NTAPI
225 USBPORT_DumpingURB(IN PURB Urb)
226 {
227     PUSB_DEFAULT_PIPE_SETUP_PACKET SetupPacket;
228 
229     DPRINT_URB("UrbHeader.Length           - %x\n", Urb->UrbHeader.Length);
230     DPRINT_URB("UrbHeader.Function         - %x\n", Urb->UrbHeader.Function);
231     DPRINT_URB("UrbHeader.Status           - %x\n", Urb->UrbHeader.Status);
232     DPRINT_URB("UrbHeader.UsbdDeviceHandle - %p\n", Urb->UrbHeader.UsbdDeviceHandle);
233     DPRINT_URB("UrbHeader.UsbdFlags        - %x\n", Urb->UrbHeader.UsbdFlags);
234 
235     if (Urb->UrbHeader.Length < 0x48)
236     {
237         return;
238     }
239 
240     DPRINT_URB("PipeHandle                - %p\n", Urb->UrbControlTransfer.PipeHandle);
241     DPRINT_URB("TransferFlags             - %x\n", Urb->UrbControlTransfer.TransferFlags);
242     DPRINT_URB("TransferBufferLength      - %x\n", Urb->UrbControlTransfer.TransferBufferLength);
243     DPRINT_URB("TransferBuffer            - %p\n", Urb->UrbControlTransfer.TransferBuffer);
244     DPRINT_URB("TransferBufferMDL         - %p\n", Urb->UrbControlTransfer.TransferBufferMDL);
245     DPRINT_URB("UrbLink                   - %p\n", Urb->UrbControlTransfer.UrbLink);
246 
247     if (Urb->UrbHeader.Length < 0x50)
248     {
249         return;
250     }
251 
252     SetupPacket = (PUSB_DEFAULT_PIPE_SETUP_PACKET)&Urb->UrbControlTransfer.SetupPacket;
253     USBPORT_DumpingSetupPacket(SetupPacket);
254 }
255 
256 VOID
257 NTAPI
258 USBPORT_DumpingIDs(IN PVOID Buffer)
259 {
260     PWSTR Ptr;
261     ULONG Length;
262     ULONG TotalLength = 0;
263 
264     Ptr = (PWSTR)Buffer;
265 
266     while (*Ptr)
267     {
268         DPRINT("  %S\n", Ptr);
269         Length = (ULONG)wcslen(Ptr) + 1;
270 
271         Ptr += Length;
272         TotalLength += Length;
273     }
274 
275     DPRINT("TotalLength: %hu\n", TotalLength);
276     DPRINT("\n");
277 }
278 
279 VOID
280 NTAPI
281 USBPORT_DumpingEndpointProperties(IN PUSBPORT_ENDPOINT_PROPERTIES EndpointProperties)
282 {
283     DPRINT_USB2("DeviceAddress         - %X\n", EndpointProperties->DeviceAddress);
284     DPRINT_USB2("EndpointAddress       - %X\n", EndpointProperties->EndpointAddress);
285     DPRINT_USB2("TotalMaxPacketSize    - %X\n", EndpointProperties->TotalMaxPacketSize);
286     DPRINT_USB2("Period                - %X\n", EndpointProperties->Period);
287     DPRINT_USB2("DeviceSpeed           - %X\n", EndpointProperties->DeviceSpeed);
288     DPRINT_USB2("UsbBandwidth          - %X\n", EndpointProperties->UsbBandwidth);
289     DPRINT_USB2("ScheduleOffset        - %X\n", EndpointProperties->ScheduleOffset);
290     DPRINT_USB2("TransferType          - %X\n", EndpointProperties->TransferType);
291     DPRINT_USB2("MaxTransferSize       - %X\n", EndpointProperties->MaxTransferSize);
292     DPRINT_USB2("HubAddr               - %X\n", EndpointProperties->HubAddr);
293     DPRINT_USB2("PortNumber            - %X\n", EndpointProperties->PortNumber);
294     DPRINT_USB2("InterruptScheduleMask - %X\n", EndpointProperties->InterruptScheduleMask);
295     DPRINT_USB2("SplitCompletionMask   - %X\n", EndpointProperties->SplitCompletionMask);
296     DPRINT_USB2("MaxPacketSize         - %X\n", EndpointProperties->MaxPacketSize);
297 }
298 
299 VOID
300 NTAPI
301 USBPORT_DumpingTtEndpoint(IN PUSB2_TT_ENDPOINT TtEndpoint)
302 {
303     DPRINT_USB2("MaxPacketSize   - %X\n", TtEndpoint->MaxPacketSize);
304     DPRINT_USB2("Period          - %X\n", TtEndpoint->Period);
305     DPRINT_USB2("TtEndpointParams- %X\n", TtEndpoint->TtEndpointParams.AsULONG);
306     DPRINT_USB2("CalcBusTime     - %X\n", TtEndpoint->CalcBusTime);
307     DPRINT_USB2("StartTime       - %X\n", TtEndpoint->StartTime);
308     DPRINT_USB2("ActualPeriod    - %X\n", TtEndpoint->ActualPeriod);
309     DPRINT_USB2("StartFrame      - %X\n", TtEndpoint->StartFrame);
310     DPRINT_USB2("StartMicroframe - %X\n", TtEndpoint->StartMicroframe);
311     DPRINT_USB2("Nums            - %X\n", TtEndpoint->Nums.AsULONG);
312     DPRINT_USB2("nextTtEndpoint  - %X\n", TtEndpoint->NextTtEndpoint);
313 }
314 
315