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