ReactOS 0.4.17-dev-1281-g065abb3
userreq.cpp
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS USB Host Controller Extension
3 * LICENSE: MIT (https://spdx.org/licenses/MIT)
4 * PURPOSE: User mode and legacy host controller IOCTLs, and the WMI node info
5 * COPYRIGHT: Copyright 2026 Justin Miller <justin.miller@reactos.org>
6 */
7
8#include "ucx01000.h"
9#include <usbuser.h>
10
11#define NDEBUG
12#include <debug.h>
13
14/* What usbview and friends get told about the port driver */
15#define UCX_DRIVER_TRACKING_CODE 4
16#define UCX_REPORTED_USBDI_VERSION 0x600
17
18/* Fake bus bandwidth: 7000 bytes per frame in bits, times 8 microframes */
19#define UCX_BUS_BANDWIDTH (7000 * 8 * 8)
20
21#define UCX_PASS_THRU_MAX_LENGTH 0x10000
22#define UCX_LEGACY_NAME_ATTEMPTS 5
23#define UCX_SYNTHETIC_FRAME_MASK 0x7FF
24
25/* Header, then the name length; what a name request needs before any text */
26#define UCX_USER_HEADER_SIZE sizeof(USBUSER_REQUEST_HEADER)
27#define UCX_USER_NAME_MIN sizeof(USB_UNICODE_NAME)
28
32
35{
36public:
38 _In_ PUSBUSER_REQUEST_HEADER Header,
42 {
43 }
44
45 template <typename T>
46 T*
47 Payload() const
48 {
49 return (T*)(m_Header + 1);
50 }
51
52 PUSBUSER_REQUEST_HEADER
53 Header() const
54 {
55 return m_Header;
56 }
57
58 ULONG
59 NameSpace() const
60 {
62 }
63
64 VOID
66 _In_ USB_USER_ERROR_CODE Status)
67 {
68 m_Header->UsbUserStatusCode = Status;
69 }
70
75 {
76 m_Header->ActualBufferLength = UCX_USER_HEADER_SIZE + ParameterLength;
77
78 if (m_Header->ActualBufferLength > m_Header->RequestBufferLength)
79 {
80 DPRINT1("USBUSER request 0x%lx needs %lu bytes, got %lu\n",
81 m_Header->UsbUserRequest, m_Header->ActualBufferLength, m_Header->RequestBufferLength);
82 SetStatus(UsbUserBufferTooSmall);
83 return FALSE;
84 }
85
86 return TRUE;
87 }
88
89private:
90 PUSBUSER_REQUEST_HEADER m_Header;
92};
93
94/* Power state maps */
95
96static
97WDMUSB_POWER_STATE
101{
103 return (WDMUSB_POWER_STATE)(WdmUsbPowerDeviceUnspecified + State);
104
105 return WdmUsbPowerNotMapped;
106}
107
108/* Unspecified is not mapped either */
109static
110WDMUSB_POWER_STATE
111NTAPI
114{
116 return (WDMUSB_POWER_STATE)(WdmUsbPowerSystemUnspecified + State);
117
118 return WdmUsbPowerNotMapped;
119}
120
121/* Request handlers */
122
123static
124VOID
125NTAPI
129{
130 PUSB_CONTROLLER_INFO_0 Info = User.Payload<USB_CONTROLLER_INFO_0>();
131 const UCX_CONTROLLER_PCI_INFORMATION* Pci = &Controller->m_Config.PciDeviceInfo;
132
133 Info->PciVendorId = Pci->VendorId;
134 Info->PciDeviceId = Pci->DeviceId;
135 Info->PciRevision = Pci->RevisionId;
136
137 /* USB 2.0 ports only, known once the hub asked for the root hub info */
138 Info->NumberOfRootPorts = Controller->m_RootHub->m_NumberOf20Ports;
139 Info->ControllerFlavor = USB_HcGeneric;
140 Info->HcFeatureFlags = 0;
141
142 User.SetStatus(UsbUserSuccess);
143}
144
145/* Shared by the USBUSER request and the legacy IOCTL */
147static
148VOID
149NTAPI
150UcxUserGetDriverKeyName(
152 _In_ WDFDEVICE Fdo)
153{
154 PUSB_UNICODE_NAME Name = User.Payload<USB_UNICODE_NAME>();
155 ULONG Space = User.NameSpace();
158
160 {
161 User.SetStatus(UsbUserBufferTooSmall);
162 return;
163 }
164
167
168 Status = WdfDeviceQueryProperty(Fdo, DevicePropertyDriverKeyName, Space, Name->String, &ResultLength);
170 {
171 User.SetStatus(UsbUserSuccess);
172 Name->Length = ResultLength + sizeof(WCHAR);
173 }
175 {
176 User.SetStatus(UsbUserBufferTooSmall);
177 }
178 else
179 {
180 DPRINT1("Driver key name query on %p failed 0x%lx\n", Fdo, Status);
181 User.SetStatus(UsbUserInvalidParameter);
182 }
183
184 User.Header()->ActualBufferLength = UCX_USER_HEADER_SIZE + UCX_USER_NAME_MIN + ResultLength;
185}
186
189static
191NTAPI
192UcxGetStrippedRootHubName(
194 _Out_ WDFSTRING* Stripped)
195{
198 WDFSTRING Original;
202
203 *Stripped = NULL;
204
205 if (!NT_SUCCESS(RootHub->ReferenceSymbolicName(&Original)))
206 {
207 DPRINT("Root hub %p has no symbolic name yet\n", RootHub);
208 return STATUS_SUCCESS;
209 }
210
212 Count = Name.Length / sizeof(WCHAR);
213
214 if (Count == 0 || Name.Buffer == NULL)
215 {
216 DPRINT1("Root hub %p symbolic name is empty\n", RootHub);
218 }
219 else
220 {
221 /* Drop "\xxx\"; without a second backslash everything scanned goes */
222 if (Name.Buffer[0] == L'\\')
223 {
224 for (Skip = 1; Skip < Count; Skip++)
225 {
226 if (Name.Buffer[Skip] == L'\\' || Name.Buffer[Skip] == UNICODE_NULL)
227 break;
228 }
229
230 if (Skip < Count && Name.Buffer[Skip] == L'\\')
231 Skip++;
232 }
233
234 Name.Buffer += Skip;
235 Name.Length -= Skip * sizeof(WCHAR);
237
239 Attributes.ParentObject = RootHub->m_Handle;
240
241 Status = WdfStringCreate(&Name, &Attributes, Stripped);
243 DPRINT1("Copying root hub %p name failed 0x%lx\n", RootHub, Status);
244 }
245
247 return Status;
248}
249
250/* A name that does not fit is still copied as far as it goes */
252static
253VOID
254NTAPI
255UcxUserGetRootHubName(
258{
259 PUSB_UNICODE_NAME Name = User.Payload<USB_UNICODE_NAME>();
260 ULONG Space = User.NameSpace();
262 WDFSTRING String;
264
266 {
267 User.SetStatus(UsbUserBufferTooSmall);
268 return;
269 }
270
273
274 if (!NT_SUCCESS(UcxGetStrippedRootHubName(RootHub, &String)))
275 {
276 User.SetStatus(UsbUserInvalidParameter);
277 User.Header()->ActualBufferLength = UCX_USER_HEADER_SIZE + UCX_USER_NAME_MIN;
278 return;
279 }
280
281 /* Not started: success with nothing written */
282 if (String == NULL)
283 return;
284
286 Size = Text.Length;
287
289
290 if (Size > Space)
291 {
292 User.SetStatus(UsbUserBufferTooSmall);
293 }
294 else
295 {
296 User.SetStatus(UsbUserSuccess);
297 Name->Length = Size + sizeof(WCHAR);
298 }
299
300 User.Header()->ActualBufferLength = UCX_USER_HEADER_SIZE + UCX_USER_NAME_MIN + Size;
302}
303
304/* No pass through function is serviced; only the sizes are checked */
305static
306VOID
307NTAPI
310{
311 ULONG Length = User.Payload<USB_PASS_THRU_PARAMETERS>()->ParameterLength;
312
314 {
315 DPRINT1("Pass through parameter length %lu is too large\n", Length);
316 User.SetStatus(UsbUserInvalidParameter);
317 }
318 else if (UCX_USER_HEADER_SIZE + FIELD_OFFSET(USB_PASS_THRU_PARAMETERS, Parameters) + Length >
319 User.Header()->RequestBufferLength)
320 {
321 DPRINT1("Pass through buffer too small for %lu parameter bytes\n", Length);
322 User.SetStatus(UsbUserBufferTooSmall);
323 }
324 else
325 {
326 DPRINT("Pass through request is not serviced\n");
327 User.SetStatus(UsbUserMiniportError);
328 User.Header()->ActualBufferLength = UCX_USER_HEADER_SIZE + sizeof(USB_PASS_THRU_PARAMETERS) + Length;
329 }
330}
331
333static
334VOID
335NTAPI
337 _In_ const DEVICE_CAPABILITIES* HcCaps,
338 _In_ SYSTEM_POWER_STATE SleepState,
339 _Out_ PUSB_POWER_INFO Info)
340{
341 DEVICE_POWER_STATE DeviceState = HcCaps->DeviceState[SleepState];
342
343 if (SleepState <= HcCaps->SystemWake)
344 {
345 Info->CanWakeup = (DeviceState != PowerDeviceUnspecified);
346 Info->IsPowered = Info->CanWakeup;
347 }
348 else
349 {
350 Info->CanWakeup = FALSE;
352 }
353}
354
355/* System states outside Working..Hibernate leave the state fields as sent */
356static
357VOID
358NTAPI
362{
363 PUSB_POWER_INFO Info = User.Payload<USB_POWER_INFO>();
364 UcxRootHub* RootHub = Controller->m_RootHub;
365 const WDF_DEVICE_POWER_CAPABILITIES* RhCaps = &RootHub->m_PowerCaps;
366 const DEVICE_CAPABILITIES* HcCaps = &Controller->m_HcCaps;
368
369 if (!RootHub->m_PdoStarted)
370 {
371 DPRINT1("Power state map requested before root hub %p started\n", RootHub);
372 User.SetStatus(UsbUserDeviceNotStarted);
373 return;
374 }
375
376 Info->RhDeviceWake = UcxMapDevicePowerState(RhCaps->DeviceWake);
377 Info->RhSystemWake = UcxMapSystemPowerState(RhCaps->SystemWake);
378 Info->HcDeviceWake = UcxMapDevicePowerState(HcCaps->DeviceWake);
379 Info->HcSystemWake = UcxMapSystemPowerState(HcCaps->SystemWake);
380 Info->LastSystemSleepState = UcxMapSystemPowerState(RootHub->m_LastSystemSleepState);
381
382 if (Info->SystemState < WdmUsbPowerSystemWorking || Info->SystemState > WdmUsbPowerSystemHibernate)
383 return;
384
385 State = (SYSTEM_POWER_STATE)(Info->SystemState - WdmUsbPowerSystemUnspecified);
386
387 Info->RhDevicePowerState = UcxMapDevicePowerState(RhCaps->DeviceState[State]);
388 Info->HcDevicePowerState = UcxMapDevicePowerState(HcCaps->DeviceState[State]);
389
391 {
392 Info->CanWakeup = FALSE;
393 Info->IsPowered = FALSE;
394 }
395 else
396 {
397 UcxMapWakeAndPower(HcCaps, State, Info);
398 }
399}
400
401/* Constant figures, the controller driver is never asked */
402static
403VOID
404NTAPI
407{
408 PUSB_BANDWIDTH_INFO Info = User.Payload<USB_BANDWIDTH_INFO>();
409
410 RtlZeroMemory(Info, sizeof(*Info));
411 Info->TotalBusBandwidth = UCX_BUS_BANDWIDTH;
412 Info->Total32secBandwidth = UCX_BUS_BANDWIDTH * 32;
413 Info->AllocedBulkAndControl = (UCX_BUS_BANDWIDTH / 5) * 32;
414}
415
417static
418VOID
419NTAPI
422 _Inout_ PULONG Frame)
423{
425
426 if (Controller->m_Config.EvtControllerGetCurrentFrameNumber != NULL)
427 Status = Controller->GetCurrentFrameNumber(Frame);
428
429 if (!NT_SUCCESS(Status))
430 {
431 DPRINT("Frame number read on controller %p failed 0x%lx, faking one\n", Controller, Status);
432 Controller->m_SyntheticFrame = (Controller->m_SyntheticFrame + 1) & UCX_SYNTHETIC_FRAME_MASK;
433 *Frame = Controller->m_SyntheticFrame;
434 }
435}
436
437/* Unused and NameIndex keep whatever the caller sent */
438static
439VOID
440NTAPI
444{
445 PUSB_BUS_STATISTICS_0 Stats = User.Payload<USB_BUS_STATISTICS_0>();
446 UcxRootHub* RootHub = Controller->m_RootHub;
448 ULONG Frame;
449
450 Stats->DeviceCount = Controller->m_ChildDeviceCount;
451
453 RtlCopyMemory(&Stats->CurrentSystemTime, &Now, sizeof(Now));
454
455 Frame = Stats->CurrentUsbFrame;
457 Stats->CurrentUsbFrame = Frame;
458
459 Stats->BulkBytes = 0;
460 Stats->IsoBytes = 0;
461 Stats->InterruptBytes = 0;
462 Stats->ControlDataBytes = 0;
463 Stats->CommonBufferBytes = 0;
464
465 /* Keeps tools from deciding the controller is stuck */
466 Stats->PciInterruptCount = 1;
467
468 Stats->HardResetCount = 0;
469 Stats->WorkerSignalCount = 0;
470 Stats->WorkerIdleTimeMs = 0;
471
472 if (!RootHub->m_PdoStarted)
473 {
474 Stats->RootHubEnabled = FALSE;
475 Stats->RootHubDevicePowerState = 4;
476 }
477 else
478 {
479 Stats->RootHubEnabled = TRUE;
480 Stats->RootHubDevicePowerState = Controller->m_RootHubInD0 ? 0 : 2;
481 }
482}
483
484/* USB_Version is left alone */
485static
486VOID
487NTAPI
490{
491 PUSB_DRIVER_VERSION_PARAMETERS Version = User.Payload<USB_DRIVER_VERSION_PARAMETERS>();
492
493 Version->DriverTrackingCode = UCX_DRIVER_TRACKING_CODE;
494 Version->USBDI_Version = UCX_REPORTED_USBDI_VERSION;
495 Version->USBUSER_Version = USBUSER_VERSION;
496#if DBG
497 Version->CheckedPortDriver = TRUE;
498 Version->CheckedMiniportDriver = TRUE;
499#else
500 Version->CheckedPortDriver = FALSE;
501 Version->CheckedMiniportDriver = FALSE;
502#endif
503}
504
505/* Parameter block sizes the length check enforces */
507{
510};
511
513{
514 { USBUSER_GET_CONTROLLER_INFO_0, sizeof(USB_CONTROLLER_INFO_0) },
515 { USBUSER_GET_CONTROLLER_DRIVER_KEY, sizeof(USB_UNICODE_NAME) },
516 { USBUSER_PASS_THRU, sizeof(USB_PASS_THRU_PARAMETERS) },
517 { USBUSER_GET_POWER_STATE_MAP, sizeof(USB_POWER_INFO) },
518 { USBUSER_GET_BANDWIDTH_INFORMATION, sizeof(USB_BANDWIDTH_INFO) },
519 { USBUSER_GET_BUS_STATISTICS_0, sizeof(USB_BUS_STATISTICS_0) },
520 { USBUSER_GET_ROOTHUB_SYMBOLIC_NAME, sizeof(USB_UNICODE_NAME) },
521 { USBUSER_GET_USB_DRIVER_VERSION, sizeof(USB_DRIVER_VERSION_PARAMETERS) },
522 { USBUSER_USB_REFRESH_HCT_REG, sizeof(ULONG) },
523 { USBUSER_OP_SEND_ONE_PACKET, sizeof(PACKET_PARAMETERS) },
524 { USBUSER_OP_RAW_RESET_PORT, sizeof(RAW_RESET_PORT_PARAMETERS) },
525 { USBUSER_SET_ROOTPORT_FEATURE, sizeof(RAW_ROOTPORT_FEATURE) },
526 { USBUSER_CLEAR_ROOTPORT_FEATURE, sizeof(RAW_ROOTPORT_FEATURE) },
527 { USBUSER_GET_ROOTPORT_STATUS, sizeof(RAW_ROOTPORT_FEATURE) }
528};
529
531static
533NTAPI
537{
538 ULONG Index;
539
541 {
543 {
545 return TRUE;
546 }
547 }
548
549 return FALSE;
550}
551
552static
553VOID
554NTAPI
557 _In_ WDFDEVICE Fdo,
559{
560 switch (User.Header()->UsbUserRequest)
561 {
562 case USBUSER_GET_CONTROLLER_INFO_0:
564 break;
565
566 case USBUSER_GET_CONTROLLER_DRIVER_KEY:
567 UcxUserGetDriverKeyName(User, Fdo);
568 break;
569
570 case USBUSER_PASS_THRU:
572 break;
573
574 case USBUSER_GET_POWER_STATE_MAP:
576 break;
577
578 case USBUSER_GET_BANDWIDTH_INFORMATION:
580 break;
581
582 case USBUSER_GET_BUS_STATISTICS_0:
584 break;
585
586 case USBUSER_GET_ROOTHUB_SYMBOLIC_NAME:
587 UcxUserGetRootHubName(User, Controller->m_RootHub);
588 break;
589
590 case USBUSER_GET_USB_DRIVER_VERSION:
592 break;
593
594 /* Accepted and ignored */
595 case USBUSER_USB_REFRESH_HCT_REG:
596 break;
597
598 /* Unlike the other test operations */
599 case USBUSER_OP_SEND_ONE_PACKET:
600 DPRINT1("USBUSER send one packet is not supported\n");
601 User.SetStatus(UsbUserInvalidHeaderParameter);
602 break;
603
604 case USBUSER_OP_RAW_RESET_PORT:
605 case USBUSER_SET_ROOTPORT_FEATURE:
606 case USBUSER_CLEAR_ROOTPORT_FEATURE:
607 case USBUSER_GET_ROOTPORT_STATUS:
608 DPRINT1("USBUSER test request 0x%lx is disabled\n", User.Header()->UsbUserRequest);
609 User.SetStatus(UsbUserFeatureDisabled);
610 break;
611
612 default:
613 {
614 /* Only consumed by the assert, so it is unused in free builds */
616
617 DPRINT1("Unknown USBUSER request 0x%lx\n", User.Header()->UsbUserRequest);
618 NT_ASSERT(!UcxLookupUserRequestSize(User.Header()->UsbUserRequest, &ParameterLength));
620 User.SetStatus(UsbUserInvalidRequestCode);
621 break;
622 }
623 }
624}
625
626static
627VOID
628NTAPI
630 _In_ WDFDEVICE Fdo,
631 _In_ WDFREQUEST Request,
633 _In_ size_t InputBufferLength)
634{
636 PUSBUSER_REQUEST_HEADER Header;
639
641 {
642 DPRINT1("USBUSER IOCTL input length %Iu differs from output length %Iu\n", InputBufferLength, OutputBufferLength);
644 return;
645 }
646
647 if (!NT_SUCCESS(WdfRequestRetrieveOutputBuffer(Request, UCX_USER_HEADER_SIZE, (PVOID*)&Header, NULL)))
648 {
649 DPRINT1("USBUSER IOCTL buffer of %Iu bytes is too small\n", OutputBufferLength);
651 return;
652 }
653
655
656 /* The request itself succeeds from here; problems go into the header */
657 Header->UsbUserStatusCode = UsbUserSuccess;
658 Header->ActualBufferLength = UCX_USER_HEADER_SIZE;
659
660 if (Header->RequestBufferLength != OutputBufferLength)
661 {
662 DPRINT1("USBUSER header length %lu differs from buffer length %Iu\n",
663 Header->RequestBufferLength, OutputBufferLength);
664 User.SetStatus(UsbUserInvalidHeaderParameter);
666 return;
667 }
668
669 /* A short parameter block reports the needed size but returns only the header */
670 if (UcxLookupUserRequestSize(Header->UsbUserRequest, &ParameterLength) &&
671 !User.CheckParameterLength(ParameterLength))
672 {
674 return;
675 }
676
678
679 Information = min(Header->RequestBufferLength, Header->ActualBufferLength);
681}
682
683/* Legacy name IOCTLs */
684
687static
688VOID
689NTAPI
690UcxHandleLegacyName(
691 _In_ WDFDEVICE Fdo,
692 _In_ WDFREQUEST Request,
695{
697 PUSBUSER_REQUEST_HEADER Block = NULL;
698 PUSB_UNICODE_NAME Name;
704
706
708 !NT_SUCCESS(WdfRequestRetrieveOutputBuffer(Request, OutputBufferLength, (PVOID*)&Output, NULL)))
709 {
710 DPRINT1("Name IOCTL 0x%lx buffer of %Iu bytes is too small\n", IoControlCode, OutputBufferLength);
712 return;
713 }
714
716 {
717 Block = (PUSBUSER_REQUEST_HEADER)ExAllocatePoolZero(PagedPool, Size, UCX_POOL_TAG);
718 if (Block == NULL)
719 {
720 DPRINT1("Name IOCTL 0x%lx could not allocate %lu bytes\n", IoControlCode, Size);
722 return;
723 }
724
725 Block->RequestBufferLength = Size;
726
728
730 {
731 Block->UsbUserRequest = USBUSER_GET_CONTROLLER_DRIVER_KEY;
732 UcxUserGetDriverKeyName(User, Fdo);
733 }
734 else
735 {
736 Block->UsbUserRequest = USBUSER_GET_ROOTHUB_SYMBOLIC_NAME;
737 UcxUserGetRootHubName(User, Controller->m_RootHub);
738 }
739
740 if (Block->UsbUserStatusCode != UsbUserBufferTooSmall)
741 break;
742
743 Size = Block->ActualBufferLength;
745 Block = NULL;
746 }
747
748 if (Block == NULL || Block->UsbUserStatusCode != UsbUserSuccess)
749 {
750 DPRINT1("Name IOCTL 0x%lx failed, USBUSER status %d\n",
751 IoControlCode, Block != NULL ? (INT)Block->UsbUserStatusCode : -1);
752
753 if (Block != NULL)
755
757 return;
758 }
759
760 Name = (PUSB_UNICODE_NAME)(Block + 1);
761
762 /* An overflowing length never fits */
764 {
766 Fits = FALSE;
767 }
768 else
769 {
772 }
773
775
776 if (Fits)
777 {
779 }
780 else
781 {
782 DPRINT("Name IOCTL 0x%lx needs %lu bytes, got %Iu\n", IoControlCode, ActualLength, OutputBufferLength);
785 }
786
789}
790
792NTAPI
794 _In_ WDFDEVICE Fdo,
795 _In_ WDFREQUEST Request,
797 _In_ size_t InputBufferLength,
799{
800 switch (IoControlCode)
801 {
802 /* Accepted, nothing changes */
805 WdfRequestComplete(Request, STATUS_SUCCESS);
806 return TRUE;
807
810 UcxHandleLegacyName(Fdo, Request, OutputBufferLength, IoControlCode);
811 return TRUE;
812
813 case IOCTL_USB_USER_REQUEST:
815 return TRUE;
816
817 default:
818 return FALSE;
819 }
820}
821
822/* WMI node info */
823
824C_ASSERT(FIELD_OFFSET(USB_DEVICE_NODE_INFO, NodeType) == 88);
825C_ASSERT(FIELD_OFFSET(USB_DEVICE_NODE_INFO, BusAddress) == 92);
826C_ASSERT(FIELD_OFFSET(USB_DEVICE_NODE_INFO, ControllerDeviceInfo) == 124);
827C_ASSERT(sizeof(USB_DEVICE_NODE_INFO) == 1202);
828
829/* The ANSI description goes into the WCHAR field byte for byte */
831NTAPI
833 _In_ WDFWMIINSTANCE WmiInstance,
837{
838 UcxController* Controller = UcxController::FromFdo(WdfWmiInstanceGetDevice(WmiInstance));
839 const UCX_CONTROLLER_PCI_INFORMATION* Pci = &Controller->m_Config.PciDeviceInfo;
840 PUSB_DEVICE_NODE_INFO Node = (PUSB_DEVICE_NODE_INFO)OutBuffer;
841 UcxRootHub* RootHub = Controller->m_RootHub;
842
843 *BufferUsed = sizeof(*Node);
844
845 if (OutBufferSize < sizeof(*Node))
846 {
847 DPRINT1("WMI node info buffer of %lu bytes is too small\n", OutBufferSize);
849 }
850
852
853 Node->Sig = USB_NODE_INFO_SIG;
854 Node->LengthInBytes = sizeof(*Node);
855 RtlStringCbCopyA((PSTR)Node->DeviceDescription,
856 sizeof(Node->DeviceDescription),
857 (PCSTR)Controller->m_Config.DeviceDescription);
858
859 Node->NodeType = UsbController;
860 Node->BusAddress.PciBusNumber = Pci->BusNumber;
861 Node->BusAddress.PciDeviceNumber = Pci->DeviceNumber;
862 Node->BusAddress.PciFunctionNumber = Pci->FunctionNumber;
863
864 Node->ControllerDeviceInfo.PciVendorId = Pci->VendorId;
865 Node->ControllerDeviceInfo.PciDeviceId = Pci->DeviceId;
866 Node->ControllerDeviceInfo.PciRevision = Pci->RevisionId;
867 Node->ControllerDeviceInfo.NumberOfRootPorts = RootHub->m_NumberOf20Ports + RootHub->m_NumberOf30Ports;
868 Node->ControllerDeviceInfo.HcFeatureFlags = USB_HC_FEATURE_FLAG_SEL_SUSPEND;
869
870 return STATUS_SUCCESS;
871}
NodeType
Definition: Node.h:6
#define RTL_NUMBER_OF(x)
Definition: RtlRegistry.c:12
unsigned char BOOLEAN
Definition: actypes.h:127
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
Definition: Header.h:9
static UcxController * FromFdo(_In_ WDFDEVICE Fdo)
Definition: hostctl.cpp:21
ULONG m_BufferLength
Definition: userreq.cpp:91
UcxUserRequest(_In_ PUSBUSER_REQUEST_HEADER Header, _In_ ULONG BufferLength)
Definition: userreq.cpp:37
PUSBUSER_REQUEST_HEADER Header() const
Definition: userreq.cpp:53
PUSBUSER_REQUEST_HEADER m_Header
Definition: userreq.cpp:90
T * Payload() const
Definition: userreq.cpp:47
VOID SetStatus(_In_ USB_USER_ERROR_CODE Status)
Definition: userreq.cpp:65
ULONG NameSpace() const
Definition: userreq.cpp:59
BOOLEAN CheckParameterLength(_In_ ULONG ParameterLength)
Definition: userreq.cpp:73
_In_ ULONG Attributes
Definition: dispmprt.h:1077
_In_ HANDLE _In_ CONST PDXGKMDT_OPM_GET_INFO_PARAMETERS Parameters
Definition: dispmprt.h:321
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define L(x)
Definition: resources.c:13
#define _IRQL_requires_(irql)
Definition: driverspecs.h:229
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
#define KeQuerySystemTime(t)
Definition: env_spec_w32.h:570
#define PagedPool
Definition: env_spec_w32.h:308
Status
Definition: gdiplustypes.h:24
#define C_ASSERT(e)
Definition: intsafe.h:73
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
static PVOID ExAllocatePoolZero(ULONG PoolType, SIZE_T NumberOfBytes, ULONG Tag)
Definition: precomp.h:45
#define min(a, b)
Definition: monoChain.cc:55
#define _Inout_
Definition: no_sal2.h:162
#define _Out_writes_bytes_to_(s, c)
Definition: no_sal2.h:190
#define _Out_
Definition: no_sal2.h:160
#define _In_
Definition: no_sal2.h:158
#define UNICODE_NULL
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:329
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
@ PowerSystemShutdown
Definition: ntpoapi.h:41
@ PowerSystemWorking
Definition: ntpoapi.h:36
@ PowerDeviceUnspecified
Definition: ntpoapi.h:48
@ PowerDeviceD3
Definition: ntpoapi.h:52
enum _DEVICE_POWER_STATE DEVICE_POWER_STATE
enum _SYSTEM_POWER_STATE SYSTEM_POWER_STATE
NTSTRSAFEAPI RtlStringCbCopyA(_Out_writes_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PSTR pszDest, _In_ size_t cbDest, _In_ NTSTRSAFE_PCSTR pszSrc)
Definition: ntstrsafe.h:156
short WCHAR
Definition: pedump.c:58
unsigned short USHORT
Definition: pedump.c:61
#define T(num)
Definition: thunks.c:311
_In_ UCHAR _In_ ULONG _Out_ PUCHAR _Outptr_result_bytebuffer_ OutBufferLength PVOID * OutBuffer
Definition: scsi.h:4117
struct tm * Now
Definition: output.c:19
#define STATUS_SUCCESS
Definition: shellext.h:65
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
#define DPRINT
Definition: sndvol32.h:73
USHORT MaximumLength
Definition: env_spec_w32.h:370
WCHAR RootHubName[ANYSIZE_ARRAY]
Definition: usbioctl.h:320
DEVICE_POWER_STATE DeviceWake
Definition: wdfdevice.h:1590
SYSTEM_POWER_STATE SystemWake
Definition: wdfdevice.h:1591
DEVICE_POWER_STATE DeviceState[PowerSystemMaximum]
Definition: wdfdevice.h:1584
#define MAXULONG
Definition: typedefs.h:251
uint32_t * PULONG
Definition: typedefs.h:59
char * PSTR
Definition: typedefs.h:51
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
#define NTAPI
Definition: typedefs.h:36
int32_t INT
Definition: typedefs.h:58
const char * PCSTR
Definition: typedefs.h:52
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
uint32_t ULONG_PTR
Definition: typedefs.h:65
uint32_t ULONG
Definition: typedefs.h:59
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFREQUEST _In_ size_t _In_ size_t _In_ ULONG IoControlCode
_Must_inspect_result_ _In_ WDFDEVICE _In_ PUCX_CONTROLLER_CONFIG _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ UCXCONTROLLER * Controller
_In_ PGUID _In_ ULONG _Out_ PULONG ResultLength
Definition: ucxcontroller.h:83
_In_ PGUID _In_ ULONG OutputBufferLength
Definition: ucxcontroller.h:81
_In_ WDFREQUEST _In_ size_t _In_ size_t InputBufferLength
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFREQUEST Request
_Must_inspect_result_ _In_ UCXCONTROLLER _In_ PUCX_ROOTHUB_CONFIG _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ UCXROOTHUB * RootHub
Definition: ucxroothub.h:299
#define UCX_POOL_TAG
Definition: ucxutil.h:11
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
Definition: dlist.c:348
@ USB_HcGeneric
Definition: usb.h:55
_In_ ULONG ParameterLength
Definition: usbdlib.h:233
#define IOCTL_USB_DIAGNOSTIC_MODE_ON
Definition: usbioctl.h:155
#define IOCTL_GET_HCD_DRIVERKEY_NAME
Definition: usbioctl.h:165
#define IOCTL_USB_DIAGNOSTIC_MODE_OFF
Definition: usbioctl.h:150
struct _USB_ROOT_HUB_NAME USB_ROOT_HUB_NAME
#define IOCTL_USB_GET_ROOT_HUB_NAME
Definition: usbioctl.h:160
static VOID NTAPI UcxHandleUserRequest(_In_ WDFDEVICE Fdo, _In_ WDFREQUEST Request, _In_ size_t OutputBufferLength, _In_ size_t InputBufferLength)
Definition: userreq.cpp:629
Output RootHubName[0]
Definition: userreq.cpp:783
static WDMUSB_POWER_STATE NTAPI UcxMapSystemPowerState(_In_ SYSTEM_POWER_STATE State)
Definition: userreq.cpp:112
#define UCX_DRIVER_TRACKING_CODE
Definition: userreq.cpp:15
USHORT Count
Definition: userreq.cpp:200
#define UCX_LEGACY_NAME_ATTEMPTS
Definition: userreq.cpp:22
ULONG Size
Definition: userreq.cpp:263
UNICODE_STRING Text
Definition: userreq.cpp:261
static VOID NTAPI UcxUserPassThru(_Inout_ UcxUserRequest &User)
Definition: userreq.cpp:308
WdfObjectDelete(String)
ULONG ActualLength
Definition: userreq.cpp:702
static VOID NTAPI UcxUserGetBandwidthInformation(_Inout_ UcxUserRequest &User)
Definition: userreq.cpp:405
WdfRequestCompleteWithInformation(Request, STATUS_SUCCESS, ActualLength)
static VOID NTAPI UcxMapWakeAndPower(_In_ const DEVICE_CAPABILITIES *HcCaps, _In_ SYSTEM_POWER_STATE SleepState, _Out_ PUSB_POWER_INFO Info)
Definition: userreq.cpp:336
static VOID NTAPI UcxUserGetBusStatistics(_Inout_ UcxUserRequest &User, _In_ UcxController *Controller)
Definition: userreq.cpp:441
#define UCX_USER_HEADER_SIZE
Definition: userreq.cpp:26
PUSB_ROOT_HUB_NAME Output
Definition: userreq.cpp:699
#define UCX_PASS_THRU_MAX_LENGTH
Definition: userreq.cpp:21
WdfStringGetUnicodeString(Original, &Name)
static BOOLEAN NTAPI UcxLookupUserRequestSize(_In_ ULONG Request, _Out_ PULONG ParameterLength)
Definition: userreq.cpp:534
#define UCX_USER_NAME_MIN
Definition: userreq.cpp:27
User Header() -> ActualBufferLength=UCX_USER_HEADER_SIZE+UCX_USER_NAME_MIN+ResultLength
PAGED_CODE()
WDFSTRING String
Definition: userreq.cpp:262
ULONG Space
Definition: userreq.cpp:155
ULONG ResultLength
Definition: userreq.cpp:156
BOOLEAN Fits
Definition: userreq.cpp:703
static VOID NTAPI UcxRunUserRequest(_Inout_ UcxUserRequest &User, _In_ WDFDEVICE Fdo, _In_ UcxController *Controller)
Definition: userreq.cpp:555
static VOID NTAPI UcxReadFrameForStatistics(_In_ UcxController *Controller, _Inout_ PULONG Frame)
Definition: userreq.cpp:420
static VOID NTAPI UcxUserGetPowerStateMap(_Inout_ UcxUserRequest &User, _In_ UcxController *Controller)
Definition: userreq.cpp:359
_Out_ WDFSTRING * Stripped
Definition: userreq.cpp:195
static const UcxUserRequestSize UcxUserRequestSizes[]
Definition: userreq.cpp:512
WDFSTRING Original
Definition: userreq.cpp:198
UNICODE_STRING Name
Definition: userreq.cpp:197
BOOLEAN NTAPI UcxDispatchUserIoctl(_In_ WDFDEVICE Fdo, _In_ WDFREQUEST Request, _In_ size_t OutputBufferLength, _In_ size_t InputBufferLength, _In_ ULONG IoControlCode)
Definition: userreq.cpp:793
PUSBUSER_REQUEST_HEADER Block
Definition: userreq.cpp:697
static VOID NTAPI UcxUserGetDriverVersion(_Inout_ UcxUserRequest &User)
Definition: userreq.cpp:488
WDF_OBJECT_ATTRIBUTES_INIT & Attributes
Definition: userreq.cpp:238
#define UCX_SYNTHETIC_FRAME_MASK
Definition: userreq.cpp:23
static VOID NTAPI UcxUserGetControllerInfo(_Inout_ UcxUserRequest &User, _In_ UcxController *Controller)
Definition: userreq.cpp:126
#define UCX_BUS_BANDWIDTH
Definition: userreq.cpp:19
ULONG Attempt
Definition: userreq.cpp:701
#define UCX_REPORTED_USBDI_VERSION
Definition: userreq.cpp:16
NTSTATUS Status
Definition: userreq.cpp:157
static WDMUSB_POWER_STATE NTAPI UcxMapDevicePowerState(_In_ DEVICE_POWER_STATE State)
Definition: userreq.cpp:99
USHORT Skip
Definition: userreq.cpp:199
EVT_WDF_WMI_INSTANCE_QUERY_INSTANCE UcxEvtWmiNodeInfoQueryInstance
Definition: userreq.h:21
_Must_inspect_result_ _In_ WDFCHILDLIST _In_ PWDF_CHILD_LIST_ITERATOR _Out_ WDFDEVICE _Inout_opt_ PWDF_CHILD_RETRIEVE_INFO Info
Definition: wdfchildlist.h:690
_In_ WDFCOLLECTION _In_ ULONG Index
_In_ WDFDEVICE _Out_ PWDF_DEVICE_STATE DeviceState
Definition: wdfdevice.h:2005
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4539
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG BufferLength
Definition: wdfdevice.h:3777
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFSTRING String
Definition: wdfdevice.h:2439
_Must_inspect_result_ _In_ WDFDEVICE Fdo
Definition: wdffdo.h:461
_Must_inspect_result_ _In_ WDFDEVICE _In_ LPCGUID _Out_ PINTERFACE _In_ USHORT _In_ USHORT Version
Definition: wdffdo.h:469
#define WdfObjectDereferenceWithTag(Handle, Tag)
Definition: wdfobject.h:829
FORCEINLINE VOID WDF_OBJECT_ATTRIBUTES_INIT(_Out_ PWDF_OBJECT_ATTRIBUTES Attributes)
Definition: wdfobject.h:147
_In_ WDFREQUEST _In_ NTSTATUS _In_ ULONG_PTR Information
Definition: wdfrequest.h:1049
_In_ ULONG OutBufferSize
Definition: wdfwmi.h:87
_In_ ULONG _Out_ PULONG BufferUsed
Definition: wdfwmi.h:92
_Must_inspect_result_ _In_ WDFWMIINSTANCE WmiInstance
Definition: wdfwmi.h:514
_In_ ULONG _In_ PHYSICAL_ADDRESS BusAddress
Definition: iofuncs.h:2292
DEVICE_CAPABILITIES
Definition: iotypes.h:965
@ DevicePropertyDriverKeyName
Definition: iotypes.h:1202
#define NT_ASSERT
Definition: rtlfuncs.h:3334