ReactOS 0.4.16-dev-106-g10b08aa
roothub.c File Reference
#include "usbport.h"
#include <debug.h>
#include "usbdebug.h"
Include dependency graph for roothub.c:

Go to the source code of this file.

Macros

#define NDEBUG
 
#define NDEBUG_USBPORT_CORE
 

Functions

RHSTATUS NTAPI USBPORT_MPStatusToRHStatus (IN MPSTATUS MPStatus)
 
MPSTATUS NTAPI USBPORT_RH_SetFeatureUSB2PortPower (IN PDEVICE_OBJECT FdoDevice, IN USHORT Port)
 
RHSTATUS NTAPI USBPORT_RootHubClassCommand (IN PDEVICE_OBJECT FdoDevice, IN PUSB_DEFAULT_PIPE_SETUP_PACKET SetupPacket, IN PVOID Buffer, IN PULONG BufferLength)
 
RHSTATUS NTAPI USBPORT_RootHubStandardCommand (IN PDEVICE_OBJECT FdoDevice, IN PUSB_DEFAULT_PIPE_SETUP_PACKET SetupPacket, IN PVOID Buffer, IN OUT PULONG TransferLength)
 
RHSTATUS NTAPI USBPORT_RootHubEndpoint0 (IN PUSBPORT_TRANSFER Transfer)
 
RHSTATUS NTAPI USBPORT_RootHubSCE (IN PUSBPORT_TRANSFER Transfer)
 
VOID NTAPI USBPORT_RootHubEndpointWorker (IN PUSBPORT_ENDPOINT Endpoint)
 
NTSTATUS NTAPI USBPORT_RootHubCreateDevice (IN PDEVICE_OBJECT FdoDevice, IN PDEVICE_OBJECT PdoDevice)
 
ULONG NTAPI USBPORT_InvalidateRootHub (PVOID MiniPortExtension)
 
VOID NTAPI USBPORT_RootHubPowerAndChirpAllCcPorts (IN PDEVICE_OBJECT FdoDevice)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 10 of file roothub.c.

◆ NDEBUG_USBPORT_CORE

#define NDEBUG_USBPORT_CORE

Definition at line 13 of file roothub.c.

Function Documentation

◆ USBPORT_InvalidateRootHub()

ULONG NTAPI USBPORT_InvalidateRootHub ( PVOID  MiniPortExtension)

Definition at line 917 of file roothub.c.

918{
920 PDEVICE_OBJECT FdoDevice;
921 PDEVICE_OBJECT PdoDevice;
923 PUSBPORT_ENDPOINT Endpoint = NULL;
924
925 DPRINT("USBPORT_InvalidateRootHub ... \n");
926
927 FdoExtension = (PUSBPORT_DEVICE_EXTENSION)((ULONG_PTR)MiniPortExtension -
929
930 FdoDevice = FdoExtension->CommonExtension.SelfDevice;
931
934 FdoExtension->MiniPortFlags & USBPORT_MPFLAG_SUSPENDED &&
935 FdoExtension->TimerFlags & USBPORT_TMFLAG_WAKE)
936 {
937 USBPORT_HcQueueWakeDpc(FdoDevice);
938 return 0;
939 }
940
941 FdoExtension->MiniPortInterface->Packet.RH_DisableIrq(FdoExtension->MiniPortExt);
942
943 PdoDevice = FdoExtension->RootHubPdo;
944
945 if (PdoDevice)
946 {
947 PdoExtension = PdoDevice->DeviceExtension;
948 Endpoint = PdoExtension->Endpoint;
949
950 if (Endpoint)
951 {
953 PdoExtension->Endpoint,
955 }
956 }
957
958 return 0;
959}
#define NULL
Definition: types.h:112
@ PdoExtension
Definition: precomp.h:49
@ FdoExtension
Definition: precomp.h:48
VOID NTAPI USBPORT_HcQueueWakeDpc(IN PDEVICE_OBJECT FdoDevice)
Definition: power.c:63
VOID NTAPI USBPORT_InvalidateEndpointHandler(IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_ENDPOINT Endpoint, IN ULONG Type)
Definition: endpoint.c:1317
#define DPRINT
Definition: sndvol32.h:73
PVOID DeviceExtension
Definition: env_spec_w32.h:418
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define USBPORT_FLAG_HC_WAKE_SUPPORT
Definition: usbport.h:76
#define USBPORT_TMFLAG_WAKE
Definition: usbport.h:98
struct _USBPORT_DEVICE_EXTENSION * PUSBPORT_DEVICE_EXTENSION
#define INVALIDATE_ENDPOINT_WORKER_THREAD
Definition: usbport.h:37
#define USBPORT_FLAG_HC_SUSPEND
Definition: usbport.h:71
struct _USBPORT_DEVICE_EXTENSION USBPORT_DEVICE_EXTENSION
#define USBPORT_MPFLAG_SUSPENDED
Definition: usbport.h:103

Referenced by USBPORT_RegisterUSBPortDriver().

◆ USBPORT_MPStatusToRHStatus()

RHSTATUS NTAPI USBPORT_MPStatusToRHStatus ( IN MPSTATUS  MPStatus)

Definition at line 18 of file roothub.c.

19{
20 RHSTATUS RHStatus = RH_STATUS_SUCCESS;
21
22 //DPRINT("USBPORT_MPStatusToRHStatus: MPStatus - %x\n", MPStatus);
23
24 if (MPStatus)
25 {
26 RHStatus = (MPStatus != MP_STATUS_FAILURE);
27 ++RHStatus;
28 }
29
30 return RHStatus;
31}
#define RH_STATUS_SUCCESS
Definition: usbmport.h:144
ULONG RHSTATUS
Definition: usbmport.h:132
#define MP_STATUS_FAILURE
Definition: usbmport.h:135

Referenced by USBPORT_RootHubClassCommand(), and USBPORT_RootHubStandardCommand().

◆ USBPORT_RH_SetFeatureUSB2PortPower()

MPSTATUS NTAPI USBPORT_RH_SetFeatureUSB2PortPower ( IN PDEVICE_OBJECT  FdoDevice,
IN USHORT  Port 
)

Definition at line 35 of file roothub.c.

37{
40 PDEVICE_RELATIONS CompanionControllersList;
41 PUSBPORT_REGISTRATION_PACKET CompanionPacket;
42 PDEVICE_OBJECT CompanionFdoDevice;
43 PUSBPORT_DEVICE_EXTENSION CompanionFdoExtension;
45 USHORT ix;
47 ULONG NumController = 0;
48
49 DPRINT("USBPORT_RootHub_PowerUsb2Port: FdoDevice - %p, Port - %p\n",
50 FdoDevice,
51 Port);
52
53 FdoExtension = FdoDevice->DeviceExtension;
54 Packet = &FdoExtension->MiniPortInterface->Packet;
55
56 CompanionControllersList = USBPORT_FindCompanionControllers(FdoDevice,
57 FALSE,
58 TRUE);
59
60 if (!CompanionControllersList)
61 {
62 Packet->RH_SetFeaturePortPower(FdoExtension->MiniPortExt, Port);
63 return MP_STATUS_SUCCESS;
64 }
65
66 Entry = &CompanionControllersList->Objects[0];
67
68 while (NumController < CompanionControllersList->Count)
69 {
70 CompanionFdoDevice = *Entry;
71
72 CompanionFdoExtension = CompanionFdoDevice->DeviceExtension;
73 CompanionPacket = &CompanionFdoExtension->MiniPortInterface->Packet;
74
75 PdoExtension = CompanionFdoExtension->RootHubPdo->DeviceExtension;
76
77 for (ix = 0;
78 (PdoExtension->CommonExtension.PnpStateFlags & USBPORT_PNP_STATE_STARTED) &&
79 ix < PdoExtension->RootHubDescriptors->Descriptor.bNumberOfPorts;
80 ++ix)
81 {
82 CompanionPacket->RH_SetFeaturePortPower(CompanionFdoExtension->MiniPortExt,
83 ix + 1);
84 }
85
86 ++NumController;
87 ++Entry;
88 }
89
90 Packet->RH_SetFeaturePortPower(FdoExtension->MiniPortExt, Port);
91
92 if (CompanionControllersList)
93 {
94 ExFreePoolWithTag(CompanionControllersList, USB_PORT_TAG);
95 }
96
97 return MP_STATUS_SUCCESS;
98}
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
CPPORT Port[4]
Definition: headless.c:35
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1549
int Count
Definition: noreturn.cpp:7
unsigned short USHORT
Definition: pedump.c:61
base of all file and directory entries
Definition: entries.h:83
PDEVICE_OBJECT Objects[1]
Definition: iotypes.h:2163
PUSBPORT_MINIPORT_INTERFACE MiniPortInterface
Definition: usbport.h:307
PDEVICE_OBJECT RootHubPdo
Definition: usbport.h:294
USBPORT_REGISTRATION_PACKET Packet
Definition: usbmport.h:644
PHCI_RH_SET_FEATURE_PORT_POWER RH_SetFeaturePortPower
Definition: usbmport.h:590
uint32_t ULONG
Definition: typedefs.h:59
#define MP_STATUS_SUCCESS
Definition: usbmport.h:134
PDEVICE_RELATIONS NTAPI USBPORT_FindCompanionControllers(IN PDEVICE_OBJECT USB2FdoDevice, IN BOOLEAN IsObRefer, IN BOOLEAN IsFDOsReturned)
Definition: usbport.c:136
#define USB_PORT_TAG
Definition: usbport.h:44
#define USBPORT_PNP_STATE_STARTED
Definition: usbport.h:88

Referenced by USBPORT_RootHubClassCommand().

◆ USBPORT_RootHubClassCommand()

RHSTATUS NTAPI USBPORT_RootHubClassCommand ( IN PDEVICE_OBJECT  FdoDevice,
IN PUSB_DEFAULT_PIPE_SETUP_PACKET  SetupPacket,
IN PVOID  Buffer,
IN PULONG  BufferLength 
)

Definition at line 102 of file roothub.c.

106{
110 USHORT Port;
112 MPSTATUS MPStatus;
115
116 DPRINT("USBPORT_RootHubClassCommand: USB command - %x, *BufferLength - %x\n",
117 SetupPacket->bRequest,
118 *BufferLength);
119
120 FdoExtension = FdoDevice->DeviceExtension;
121 PdoExtension = FdoExtension->RootHubPdo->DeviceExtension;
122 Packet = &FdoExtension->MiniPortInterface->Packet;
123
124 Port = SetupPacket->wIndex.W;
125
126 switch (SetupPacket->bRequest)
127 {
129 {
130 if (!Buffer)
131 {
132 return RHStatus;
133 }
134
135 *(PULONG)Buffer = 0;
136
137 if (SetupPacket->bmRequestType.Recipient == BMREQUEST_TO_OTHER)
138 {
139 ASSERT(*BufferLength >= 4);
140
141 if (Port > PdoExtension->RootHubDescriptors->Descriptor.bNumberOfPorts ||
142 Port <= 0 ||
143 SetupPacket->wLength < 4)
144 {
145 return RHStatus;
146 }
147
148 KeAcquireSpinLock(&FdoExtension->MiniportSpinLock, &OldIrql);
149
150 MPStatus = Packet->RH_GetPortStatus(FdoExtension->MiniPortExt,
151 SetupPacket->wIndex.W,
152 Buffer);
153
154 KeReleaseSpinLock(&FdoExtension->MiniportSpinLock, OldIrql);
155 }
156 else
157 {
158 KeAcquireSpinLock(&FdoExtension->MiniportSpinLock, &OldIrql);
159
160 MPStatus = Packet->RH_GetHubStatus(FdoExtension->MiniPortExt,
161 Buffer);
162
163 KeReleaseSpinLock(&FdoExtension->MiniportSpinLock, OldIrql);
164 }
165
166 RHStatus = USBPORT_MPStatusToRHStatus(MPStatus);
167 break;
168 }
169
171 Feature = SetupPacket->wValue.W;
172
173 if ((SetupPacket->bmRequestType.Recipient) != USBPORT_RECIPIENT_PORT)
174 {
176 {
177 RHStatus = RH_STATUS_SUCCESS;
178 return RHStatus;
179 }
180
182 {
183 MPStatus = Packet->RH_ClearFeaturePortOvercurrentChange(FdoExtension->MiniPortExt,
184 0);
185 RHStatus = USBPORT_MPStatusToRHStatus(MPStatus);
186 return RHStatus;
187 }
188
190 return RHStatus;
191 }
192
193 switch (Feature)
194 {
196 MPStatus = Packet->RH_ClearFeaturePortEnable(FdoExtension->MiniPortExt,
197 Port);
198 break;
199
201 MPStatus = Packet->RH_ClearFeaturePortSuspend(FdoExtension->MiniPortExt,
202 Port);
203 break;
204
206 MPStatus = Packet->RH_ClearFeaturePortPower(FdoExtension->MiniPortExt,
207 Port);
208 break;
209
211 MPStatus = Packet->RH_ClearFeaturePortConnectChange(FdoExtension->MiniPortExt,
212 Port);
213 break;
214
216 MPStatus = Packet->RH_ClearFeaturePortEnableChange(FdoExtension->MiniPortExt,
217 Port);
218 break;
219
221 MPStatus = Packet->RH_ClearFeaturePortSuspendChange(FdoExtension->MiniPortExt,
222 Port);
223 break;
224
226 MPStatus = Packet->RH_ClearFeaturePortOvercurrentChange(FdoExtension->MiniPortExt,
227 Port);
228 break;
229
231 MPStatus = Packet->RH_ClearFeaturePortResetChange(FdoExtension->MiniPortExt,
232 Port);
233 break;
234
235 default:
236 DPRINT1("USBPORT_RootHubClassCommand: Not supported feature - %x\n",
237 Feature);
238 return RHStatus;
239 }
240
241 RHStatus = USBPORT_MPStatusToRHStatus(MPStatus);
242 break;
243
245 if (SetupPacket->bmRequestType.Recipient != USBPORT_RECIPIENT_PORT)
246 {
247 return RHStatus;
248 }
249
250 Feature = SetupPacket->wValue.W;
251
252 switch (Feature)
253 {
255 MPStatus = Packet->RH_SetFeaturePortEnable(FdoExtension->MiniPortExt,
256 Port);
257 break;
258
260 MPStatus = Packet->RH_SetFeaturePortSuspend(FdoExtension->MiniPortExt,
261 Port);
262 break;
263
265 MPStatus = Packet->RH_SetFeaturePortReset(FdoExtension->MiniPortExt,
266 Port);
267 break;
268
270 if (Packet->MiniPortFlags & USB_MINIPORT_FLAGS_USB2)
271 {
272 MPStatus = USBPORT_RH_SetFeatureUSB2PortPower(FdoDevice, Port);
273 }
274 else
275 {
276 MPStatus = Packet->RH_SetFeaturePortPower(FdoExtension->MiniPortExt,
277 Port);
278 }
279
280 break;
281
282 default:
283 DPRINT1("USBPORT_RootHubClassCommand: Not supported feature - %x\n",
284 Feature);
285 return RHStatus;
286 }
287
288 RHStatus = USBPORT_MPStatusToRHStatus(MPStatus);
289 break;
290
292 if (Buffer &&
293 SetupPacket->wValue.W == 0 &&
294 SetupPacket->bmRequestType.Dir == BMREQUEST_DEVICE_TO_HOST)
295 {
296 SIZE_T DescriptorLength;
297
298 DescriptorLength = PdoExtension->RootHubDescriptors->Descriptor.bDescriptorLength;
299
300 if (*BufferLength < DescriptorLength)
301 DescriptorLength = *BufferLength;
302
304 &PdoExtension->RootHubDescriptors->Descriptor,
305 DescriptorLength);
306
307 *BufferLength = DescriptorLength;
308 RHStatus = RH_STATUS_SUCCESS;
309 }
310
311 break;
312
313 default:
314 DPRINT1("USBPORT_RootHubClassCommand: Not supported USB request - %x\n",
315 SetupPacket->bRequest);
316 //USB_REQUEST_SET_ADDRESS 0x05
317 //USB_REQUEST_SET_DESCRIPTOR 0x07
318 //USB_REQUEST_GET_CONFIGURATION 0x08
319 //USB_REQUEST_SET_CONFIGURATION 0x09
320 //USB_REQUEST_GET_INTERFACE 0x0A
321 //USB_REQUEST_SET_INTERFACE 0x0B
322 //USB_REQUEST_SYNC_FRAME 0x0C
323 break;
324 }
325
326 return RHStatus;
327}
#define DPRINT1
Definition: precomp.h:8
_In_ ULONG const _In_ FEATURE_NUMBER const Feature
Definition: cdrom.h:1077
Definition: bufpool.h:45
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
NTSYSAPI void WINAPI DbgBreakPoint(void)
#define ASSERT(a)
Definition: mode.c:44
uint32_t * PULONG
Definition: typedefs.h:59
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define USB_REQUEST_GET_STATUS
Definition: usb100.h:78
#define USB_REQUEST_GET_DESCRIPTOR
Definition: usb100.h:82
#define BMREQUEST_TO_OTHER
Definition: usb100.h:41
#define USB_REQUEST_SET_FEATURE
Definition: usb100.h:80
#define USB_REQUEST_CLEAR_FEATURE
Definition: usb100.h:79
#define BMREQUEST_DEVICE_TO_HOST
Definition: usb100.h:32
#define USB_MINIPORT_FLAGS_USB2
Definition: usbmport.h:534
#define RH_STATUS_UNSUCCESSFUL
Definition: usbmport.h:146
ULONG MPSTATUS
Definition: usbmport.h:131
RHSTATUS NTAPI USBPORT_MPStatusToRHStatus(IN MPSTATUS MPStatus)
Definition: roothub.c:18
MPSTATUS NTAPI USBPORT_RH_SetFeatureUSB2PortPower(IN PDEVICE_OBJECT FdoDevice, IN USHORT Port)
Definition: roothub.c:35
#define FEATURE_C_PORT_ENABLE
Definition: usbport.h:56
#define FEATURE_PORT_SUSPEND
Definition: usbport.h:50
#define USBPORT_RECIPIENT_PORT
Definition: usbport.h:34
#define FEATURE_C_HUB_OVER_CURRENT
Definition: usbport.h:63
#define FEATURE_C_PORT_RESET
Definition: usbport.h:59
#define FEATURE_C_PORT_OVER_CURRENT
Definition: usbport.h:58
#define FEATURE_C_PORT_SUSPEND
Definition: usbport.h:57
#define FEATURE_PORT_ENABLE
Definition: usbport.h:49
#define FEATURE_C_HUB_LOCAL_POWER
Definition: usbport.h:62
#define FEATURE_PORT_RESET
Definition: usbport.h:52
#define FEATURE_PORT_POWER
Definition: usbport.h:53
#define FEATURE_C_PORT_CONNECTION
Definition: usbport.h:55
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG BufferLength
Definition: wdfdevice.h:3771
_Must_inspect_result_ _In_ WDFUSBDEVICE _In_opt_ WDFREQUEST _In_opt_ PWDF_REQUEST_SEND_OPTIONS _In_ PWDF_USB_CONTROL_SETUP_PACKET SetupPacket
Definition: wdfusb.h:1337
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:778

Referenced by USBPORT_RootHubEndpoint0().

◆ USBPORT_RootHubCreateDevice()

NTSTATUS NTAPI USBPORT_RootHubCreateDevice ( IN PDEVICE_OBJECT  FdoDevice,
IN PDEVICE_OBJECT  PdoDevice 
)

Definition at line 747 of file roothub.c.

749{
754 USBPORT_ROOT_HUB_DATA RootHubData;
755 ULONG NumMaskByte;
756 ULONG DescriptorsLength;
757 PUSBPORT_RH_DESCRIPTORS Descriptors;
758 PUSB_DEVICE_DESCRIPTOR RH_DeviceDescriptor;
759 PUSB_CONFIGURATION_DESCRIPTOR RH_ConfigurationDescriptor;
760 PUSB_INTERFACE_DESCRIPTOR RH_InterfaceDescriptor;
761 PUSB_ENDPOINT_DESCRIPTOR RH_EndPointDescriptor;
762 PUSB_HUB_DESCRIPTOR RH_HubDescriptor;
763 ULONG ix;
764 PUSB_ENDPOINT_DESCRIPTOR EndpointDescriptor;
766
767 DPRINT("USBPORT_RootHubCreateDevice: FdoDevice - %p, PdoDevice - %p\n",
768 FdoDevice,
769 PdoDevice);
770
771 FdoExtension = FdoDevice->DeviceExtension;
772 PdoExtension = PdoDevice->DeviceExtension;
773 Packet = &FdoExtension->MiniPortInterface->Packet;
774
775 DeviceHandle = &PdoExtension->DeviceHandle;
777
778 InitializeListHead(&DeviceHandle->PipeHandleList);
779
780 DeviceHandle->IsRootHub = TRUE;
781 DeviceHandle->DeviceSpeed = UsbFullSpeed;
783
784 RtlZeroMemory(&RootHubData, sizeof(RootHubData));
785
786 Packet->RH_GetRootHubData(FdoExtension->MiniPortExt, &RootHubData);
787
788 ASSERT(RootHubData.NumberOfPorts != 0);
789 NumMaskByte = (RootHubData.NumberOfPorts - 1) / 8 + 1;
790
791 DescriptorsLength = sizeof(USB_DEVICE_DESCRIPTOR) +
795 (sizeof(USB_HUB_DESCRIPTOR) + 2 * NumMaskByte);
796
798 DescriptorsLength,
800
801 if (Descriptors)
802 {
803 RtlZeroMemory(Descriptors, DescriptorsLength);
804
805 PdoExtension->RootHubDescriptors = Descriptors;
806
807 RH_DeviceDescriptor = &PdoExtension->RootHubDescriptors->DeviceDescriptor;
808
809 RH_DeviceDescriptor->bLength = sizeof(USB_DEVICE_DESCRIPTOR);
810 RH_DeviceDescriptor->bDescriptorType = USB_DEVICE_DESCRIPTOR_TYPE;
811 RH_DeviceDescriptor->bcdUSB = 0x100;
812 RH_DeviceDescriptor->bDeviceClass = USB_DEVICE_CLASS_HUB;
813 RH_DeviceDescriptor->bDeviceSubClass = 0x01;
814 RH_DeviceDescriptor->bDeviceProtocol = 0x00;
815 RH_DeviceDescriptor->bMaxPacketSize0 = 0x08;
816 RH_DeviceDescriptor->idVendor = FdoExtension->VendorID;
817 RH_DeviceDescriptor->idProduct = FdoExtension->DeviceID;
818 RH_DeviceDescriptor->bcdDevice = FdoExtension->RevisionID;
819 RH_DeviceDescriptor->iManufacturer = 0x00;
820 RH_DeviceDescriptor->iProduct = 0x00;
821 RH_DeviceDescriptor->iSerialNumber = 0x00;
822 RH_DeviceDescriptor->bNumConfigurations = 0x01;
823
824 RH_ConfigurationDescriptor = &PdoExtension->RootHubDescriptors->ConfigDescriptor;
825
826 RH_ConfigurationDescriptor->bLength = sizeof(USB_CONFIGURATION_DESCRIPTOR);
827 RH_ConfigurationDescriptor->bDescriptorType = USB_CONFIGURATION_DESCRIPTOR_TYPE;
828
829 RH_ConfigurationDescriptor->wTotalLength = sizeof(USB_CONFIGURATION_DESCRIPTOR) +
832
833 RH_ConfigurationDescriptor->bNumInterfaces = 0x01;
834 RH_ConfigurationDescriptor->bConfigurationValue = 0x01;
835 RH_ConfigurationDescriptor->iConfiguration = 0x00;
836 RH_ConfigurationDescriptor->bmAttributes = USB_CONFIG_SELF_POWERED;
837 RH_ConfigurationDescriptor->MaxPower = 0x00;
838
839 RH_InterfaceDescriptor = &PdoExtension->RootHubDescriptors->InterfaceDescriptor;
840
841 RH_InterfaceDescriptor->bLength = sizeof(USB_INTERFACE_DESCRIPTOR);
842 RH_InterfaceDescriptor->bDescriptorType = USB_INTERFACE_DESCRIPTOR_TYPE;
843 RH_InterfaceDescriptor->bInterfaceNumber = 0x00;
844 RH_InterfaceDescriptor->bAlternateSetting = 0x00;
845 RH_InterfaceDescriptor->bNumEndpoints = 0x01;
846 RH_InterfaceDescriptor->bInterfaceClass = USB_DEVICE_CLASS_HUB;
847 RH_InterfaceDescriptor->bInterfaceSubClass = 0x01;
848 RH_InterfaceDescriptor->bInterfaceProtocol = 0x00;
849 RH_InterfaceDescriptor->iInterface = 0x00;
850
851 RH_EndPointDescriptor = &PdoExtension->RootHubDescriptors->EndPointDescriptor;
852
853 RH_EndPointDescriptor->bLength = sizeof(USB_ENDPOINT_DESCRIPTOR);
854 RH_EndPointDescriptor->bDescriptorType = USB_ENDPOINT_DESCRIPTOR_TYPE;
855 RH_EndPointDescriptor->bEndpointAddress = 0x81;
856 RH_EndPointDescriptor->bmAttributes = USB_ENDPOINT_TYPE_INTERRUPT; // SCE endpoint
857 RH_EndPointDescriptor->wMaxPacketSize = 0x0008;
858 RH_EndPointDescriptor->bInterval = 0x0C; // 12 msec
859
860 RH_HubDescriptor = &PdoExtension->RootHubDescriptors->Descriptor;
861
862 RH_HubDescriptor->bDescriptorLength = FIELD_OFFSET(USB_HUB_DESCRIPTOR, bRemoveAndPowerMask) + 2 * NumMaskByte;
863
864 if (Packet->MiniPortVersion == USB_MINIPORT_VERSION_OHCI ||
865 Packet->MiniPortVersion == USB_MINIPORT_VERSION_UHCI ||
866 Packet->MiniPortVersion == USB_MINIPORT_VERSION_EHCI)
867 {
869 }
870 else if (Packet->MiniPortVersion == USB_MINIPORT_VERSION_XHCI)
871 {
873 }
874 else
875 {
876 DPRINT1("USBPORT_RootHubCreateDevice: Unknown MiniPortVersion - %x\n",
877 Packet->MiniPortVersion);
878
880 }
881
882 RH_HubDescriptor->bNumberOfPorts = RootHubData.NumberOfPorts;
883 RH_HubDescriptor->wHubCharacteristics = RootHubData.HubCharacteristics.AsUSHORT;
884 RH_HubDescriptor->bPowerOnToPowerGood = RootHubData.PowerOnToPowerGood;
885 RH_HubDescriptor->bHubControlCurrent = RootHubData.HubControlCurrent;
886
887 for (ix = 0; ix < NumMaskByte; ix += 2)
888 {
889 RH_HubDescriptor->bRemoveAndPowerMask[ix] = 0;
890 RH_HubDescriptor->bRemoveAndPowerMask[ix + 1] = -1;
891 }
892
893 EndpointDescriptor = &DeviceHandle->PipeHandle.EndpointDescriptor;
894
895 EndpointDescriptor->bLength = sizeof(USB_ENDPOINT_DESCRIPTOR);
896 EndpointDescriptor->bDescriptorType = USB_ENDPOINT_DESCRIPTOR_TYPE;
897 EndpointDescriptor->bEndpointAddress = 0x00;
898 EndpointDescriptor->bmAttributes = USB_ENDPOINT_TYPE_CONTROL;
899 EndpointDescriptor->wMaxPacketSize = 0x0040;
900 EndpointDescriptor->bInterval = 0x00;
901
902 Status = USBPORT_OpenPipe(FdoDevice,
904 &DeviceHandle->PipeHandle,
905 NULL);
906 }
907 else
908 {
910 }
911
912 return Status;
913}
LONG NTSTATUS
Definition: precomp.h:26
VOID NTAPI USBPORT_AddDeviceHandle(IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_DEVICE_HANDLE DeviceHandle)
Definition: device.c:769
NTSTATUS NTAPI USBPORT_OpenPipe(IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_DEVICE_HANDLE DeviceHandle, IN PUSBPORT_PIPE_HANDLE PipeHandle, IN OUT PUSBD_STATUS UsbdStatus)
Definition: endpoint.c:763
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define NonPagedPool
Definition: env_spec_w32.h:307
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
Status
Definition: gdiplustypes.h:25
_Inout_ PUSB_DEVICE_HANDLE DeviceHandle
Definition: hubbusif.h:121
USBPORT_HUB_CHARACTERISTICS HubCharacteristics
Definition: usbmport.h:697
UCHAR bNumConfigurations
Definition: usb100.h:124
USHORT wHubCharacteristics
Definition: usb100.h:174
UCHAR bNumberOfPorts
Definition: usb100.h:173
UCHAR bHubControlCurrent
Definition: usb100.h:176
UCHAR bRemoveAndPowerMask[64]
Definition: usb100.h:177
UCHAR bDescriptorType
Definition: usb100.h:172
UCHAR bDescriptorLength
Definition: usb100.h:171
UCHAR bPowerOnToPowerGood
Definition: usb100.h:175
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
struct _USB_CONFIGURATION_DESCRIPTOR USB_CONFIGURATION_DESCRIPTOR
#define USB_ENDPOINT_TYPE_INTERRUPT
Definition: usb100.h:65
#define USB_CONFIGURATION_DESCRIPTOR_TYPE
Definition: usb100.h:50
#define USB_ENDPOINT_DESCRIPTOR_TYPE
Definition: usb100.h:53
struct _USB_ENDPOINT_DESCRIPTOR USB_ENDPOINT_DESCRIPTOR
#define USB_ENDPOINT_TYPE_CONTROL
Definition: usb100.h:62
struct _USB_HUB_DESCRIPTOR USB_HUB_DESCRIPTOR
#define USB_DEVICE_DESCRIPTOR_TYPE
Definition: usb100.h:49
struct _USB_DEVICE_DESCRIPTOR USB_DEVICE_DESCRIPTOR
#define USB_CONFIG_SELF_POWERED
Definition: usb100.h:70
#define USB_DEVICE_CLASS_HUB
Definition: usb100.h:99
struct _USB_INTERFACE_DESCRIPTOR USB_INTERFACE_DESCRIPTOR
#define USB_INTERFACE_DESCRIPTOR_TYPE
Definition: usb100.h:52
@ UsbFullSpeed
Definition: usb200.h:43
#define USB_20_HUB_DESCRIPTOR_TYPE
Definition: usb200.h:279
#define USB_30_HUB_DESCRIPTOR_TYPE
Definition: usb200.h:280
#define USB_MINIPORT_VERSION_EHCI
Definition: usbmport.h:528
#define USB_MINIPORT_VERSION_XHCI
Definition: usbmport.h:529
#define USB_MINIPORT_VERSION_UHCI
Definition: usbmport.h:527
#define USB_MINIPORT_VERSION_OHCI
Definition: usbmport.h:526
#define DEVICE_HANDLE_FLAG_ROOTHUB
Definition: usbport.h:106

Referenced by USBPORT_PdoPnP().

◆ USBPORT_RootHubEndpoint0()

RHSTATUS NTAPI USBPORT_RootHubEndpoint0 ( IN PUSBPORT_TRANSFER  Transfer)

Definition at line 485 of file roothub.c.

486{
487 PDEVICE_OBJECT FdoDevice;
488 ULONG TransferLength;
490 PURB Urb;
492 UCHAR Type;
493 RHSTATUS RHStatus;
494
495 DPRINT("USBPORT_RootHubEndpoint0: Transfer - %p\n", Transfer);
496
497 TransferLength = Transfer->TransferParameters.TransferBufferLength;
498 Urb = Transfer->Urb;
499 FdoDevice = Transfer->Endpoint->FdoDevice;
500
501 if (TransferLength > 0)
502 Buffer = Urb->UrbControlTransfer.TransferBufferMDL->MappedSystemVa;
503 else
504 Buffer = NULL;
505
507
508 Type = SetupPacket->bmRequestType.Type;
509
511 {
512 RHStatus = USBPORT_RootHubStandardCommand(FdoDevice,
514 Buffer,
515 &TransferLength);
516 }
517 else if (Type == BMREQUEST_CLASS)
518 {
519 RHStatus = USBPORT_RootHubClassCommand(FdoDevice,
521 Buffer,
522 &TransferLength);
523 }
524 else
525 {
527 }
528
529 if (RHStatus == RH_STATUS_SUCCESS)
530 Transfer->CompletedTransferLen = TransferLength;
531
532 return RHStatus;
533}
Type
Definition: Type.h:7
if(dx< 0)
Definition: linetemp.h:194
Definition: usb.h:529
struct _URB_CONTROL_TRANSFER UrbControlTransfer
Definition: usb.h:539
#define BMREQUEST_CLASS
Definition: usb100.h:35
#define BMREQUEST_STANDARD
Definition: usb100.h:34
struct _USB_DEFAULT_PIPE_SETUP_PACKET * PUSB_DEFAULT_PIPE_SETUP_PACKET
RHSTATUS NTAPI USBPORT_RootHubStandardCommand(IN PDEVICE_OBJECT FdoDevice, IN PUSB_DEFAULT_PIPE_SETUP_PACKET SetupPacket, IN PVOID Buffer, IN OUT PULONG TransferLength)
Definition: roothub.c:331
RHSTATUS NTAPI USBPORT_RootHubClassCommand(IN PDEVICE_OBJECT FdoDevice, IN PUSB_DEFAULT_PIPE_SETUP_PACKET SetupPacket, IN PVOID Buffer, IN PULONG BufferLength)
Definition: roothub.c:102
unsigned char UCHAR
Definition: xmlstorage.h:181

Referenced by USBPORT_RootHubEndpointWorker().

◆ USBPORT_RootHubEndpointWorker()

VOID NTAPI USBPORT_RootHubEndpointWorker ( IN PUSBPORT_ENDPOINT  Endpoint)

Definition at line 664 of file roothub.c.

665{
666 PDEVICE_OBJECT FdoDevice;
669 PUSBPORT_TRANSFER Transfer;
670 RHSTATUS RHStatus;
671 USBD_STATUS USBDStatus;
673
674 DPRINT_CORE("USBPORT_RootHubEndpointWorker: Endpoint - %p\n", Endpoint);
675
676 FdoDevice = Endpoint->FdoDevice;
677 FdoExtension = FdoDevice->DeviceExtension;
678 Packet = &FdoExtension->MiniPortInterface->Packet;
679
680 KeAcquireSpinLock(&FdoExtension->MiniportSpinLock, &OldIrql);
682 {
683 Packet->CheckController(FdoExtension->MiniPortExt);
684 }
685 KeReleaseSpinLock(&FdoExtension->MiniportSpinLock, OldIrql);
686
687 KeAcquireSpinLock(&Endpoint->EndpointSpinLock, &Endpoint->EndpointOldIrql);
688
689 Transfer = CONTAINING_RECORD(Endpoint->TransferList.Flink,
691 TransferLink);
692
693 if (IsListEmpty(&Endpoint->TransferList) ||
694 Endpoint->TransferList.Flink == NULL ||
695 !Transfer)
696 {
697 if (Endpoint->StateLast == USBPORT_ENDPOINT_REMOVE)
698 {
699 ExInterlockedInsertTailList(&FdoExtension->EndpointClosedList,
700 &Endpoint->CloseLink,
701 &FdoExtension->EndpointClosedSpinLock);
702 }
703
704 KeReleaseSpinLock(&Endpoint->EndpointSpinLock, Endpoint->EndpointOldIrql);
705
706 USBPORT_FlushCancelList(Endpoint);
707 return;
708 }
709
711 {
712 RemoveEntryList(&Transfer->TransferLink);
713 InsertTailList(&Endpoint->CancelList, &Transfer->TransferLink);
714
715 KeReleaseSpinLock(&Endpoint->EndpointSpinLock, Endpoint->EndpointOldIrql);
716 USBPORT_FlushCancelList(Endpoint);
717 return;
718 }
719
720 KeReleaseSpinLock(&Endpoint->EndpointSpinLock, Endpoint->EndpointOldIrql);
721
722 if (Endpoint->EndpointProperties.TransferType == USBPORT_TRANSFER_TYPE_CONTROL)
723 RHStatus = USBPORT_RootHubEndpoint0(Transfer);
724 else
725 RHStatus = USBPORT_RootHubSCE(Transfer);
726
727 if (RHStatus != RH_STATUS_NO_CHANGES)
728 {
729 if (RHStatus == RH_STATUS_SUCCESS)
730 USBDStatus = USBD_STATUS_SUCCESS;
731 else
732 USBDStatus = USBD_STATUS_STALL_PID;
733
734 KeAcquireSpinLock(&Endpoint->EndpointSpinLock, &Endpoint->EndpointOldIrql);
735 USBPORT_QueueDoneTransfer(Transfer, USBDStatus);
736 KeReleaseSpinLock(&Endpoint->EndpointSpinLock, Endpoint->EndpointOldIrql);
737
738 USBPORT_FlushCancelList(Endpoint);
739 return;
740 }
741
742 USBPORT_FlushCancelList(Endpoint);
743}
VOID NTAPI USBPORT_FlushCancelList(IN PUSBPORT_ENDPOINT Endpoint)
Definition: queue.c:714
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986
#define InsertTailList(ListHead, Entry)
#define IsListEmpty(ListHead)
Definition: env_spec_w32.h:954
PLIST_ENTRY NTAPI ExInterlockedInsertTailList(IN OUT PLIST_ENTRY ListHead, IN OUT PLIST_ENTRY ListEntry, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:140
LIST_ENTRY TransferLink
Definition: usbport.h:257
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
#define USBD_STATUS_STALL_PID
Definition: usb.h:175
#define USBD_STATUS_SUCCESS
Definition: usb.h:170
LONG USBD_STATUS
Definition: usb.h:165
#define DPRINT_CORE(...)
Definition: usbdebug.h:144
#define USBPORT_ENDPOINT_REMOVE
Definition: usbmport.h:16
#define RH_STATUS_NO_CHANGES
Definition: usbmport.h:145
#define USBPORT_TRANSFER_TYPE_CONTROL
Definition: usbmport.h:8
RHSTATUS NTAPI USBPORT_RootHubEndpoint0(IN PUSBPORT_TRANSFER Transfer)
Definition: roothub.c:485
RHSTATUS NTAPI USBPORT_RootHubSCE(IN PUSBPORT_TRANSFER Transfer)
Definition: roothub.c:537
BOOLEAN NTAPI USBPORT_QueueDoneTransfer(IN PUSBPORT_TRANSFER Transfer, IN USBD_STATUS USBDStatus)
Definition: usbport.c:839
#define TRANSFER_FLAG_CANCELED
Definition: usbport.h:130
#define TRANSFER_FLAG_ABORTED
Definition: usbport.h:134

Referenced by USBPORT_EndpointWorker().

◆ USBPORT_RootHubPowerAndChirpAllCcPorts()

VOID NTAPI USBPORT_RootHubPowerAndChirpAllCcPorts ( IN PDEVICE_OBJECT  FdoDevice)

Definition at line 963 of file roothub.c.

964{
967 USBPORT_ROOT_HUB_DATA RootHubData;
968 ULONG Port;
969 PDEVICE_RELATIONS CompanionControllersList;
970 PUSBPORT_DEVICE_EXTENSION CompanionFdoExtension;
971 PUSBPORT_REGISTRATION_PACKET CompanionPacket;
972 ULONG CompanionPorts;
973 ULONG NumController;
975 ULONG NumPorts;
976
977 DPRINT("USBPORT_RootHub_PowerAndChirpAllCcPorts: FdoDevice - %p\n",
978 FdoDevice);
979
980 FdoExtension = FdoDevice->DeviceExtension;
981
982 Packet = &FdoExtension->MiniPortInterface->Packet;
983
984 RtlZeroMemory(&RootHubData, sizeof(RootHubData));
985
986 Packet->RH_GetRootHubData(FdoExtension->MiniPortExt,
987 &RootHubData);
988
989 NumPorts = RootHubData.NumberOfPorts;
990
991 for (Port = 1; Port <= NumPorts; ++Port)
992 {
993 Packet->RH_SetFeaturePortPower(FdoExtension->MiniPortExt, Port);
994 }
995
996 USBPORT_Wait(FdoDevice, 10);
997
998 CompanionControllersList = USBPORT_FindCompanionControllers(FdoDevice,
999 FALSE,
1000 TRUE);
1001
1002 if (CompanionControllersList)
1003 {
1004 Entry = &CompanionControllersList->Objects[0];
1005
1006 for (NumController = 0;
1007 NumController < CompanionControllersList->Count;
1008 NumController++)
1009 {
1010 CompanionPacket = &FdoExtension->MiniPortInterface->Packet;
1011
1012 CompanionFdoExtension = (*Entry)->DeviceExtension;
1013
1014 CompanionPacket->RH_GetRootHubData(CompanionFdoExtension->MiniPortExt,
1015 &RootHubData);
1016
1017 CompanionPorts = RootHubData.NumberOfPorts;
1018
1019 for (Port = 1; Port <= CompanionPorts; ++Port)
1020 {
1021 CompanionPacket->RH_SetFeaturePortPower(CompanionFdoExtension->MiniPortExt,
1022 Port);
1023 }
1024
1025 ++Entry;
1026 }
1027
1028 ExFreePoolWithTag(CompanionControllersList, USB_PORT_TAG);
1029 }
1030
1031 USBPORT_Wait(FdoDevice, 100);
1032
1033 for (Port = 1; Port <= NumPorts; ++Port)
1034 {
1035 if (FdoExtension->MiniPortInterface->Version < 200)
1036 {
1037 break;
1038 }
1039
1040 InterlockedIncrement((PLONG)&FdoExtension->ChirpRootPortLock);
1041 Packet->RH_ChirpRootPort(FdoExtension->MiniPortExt, Port);
1042 InterlockedDecrement((PLONG)&FdoExtension->ChirpRootPortLock);
1043 }
1044}
#define InterlockedIncrement
Definition: armddk.h:53
#define InterlockedDecrement
Definition: armddk.h:52
PHCI_RH_GET_ROOT_HUB_DATA RH_GetRootHubData
Definition: usbmport.h:585
int32_t * PLONG
Definition: typedefs.h:58
NTSTATUS NTAPI USBPORT_Wait(IN PVOID MiniPortExtension, IN ULONG Milliseconds)
Definition: usbport.c:543

Referenced by USBPORT_SynchronizeRootHubCallback().

◆ USBPORT_RootHubSCE()

RHSTATUS NTAPI USBPORT_RootHubSCE ( IN PUSBPORT_TRANSFER  Transfer)

Definition at line 537 of file roothub.c.

538{
539 PUSBPORT_ENDPOINT Endpoint;
543 ULONG TransferLength;
547 PULONG AddressBitMap;
548 ULONG Port;
549 PURB Urb;
551 PUSB_HUB_DESCRIPTOR HubDescriptor;
553
554 DPRINT("USBPORT_RootHubSCE: Transfer - %p\n", Transfer);
555
556 Endpoint = Transfer->Endpoint;
557
559 PdoExtension = FdoExtension->RootHubPdo->DeviceExtension;
560 Packet = &FdoExtension->MiniPortInterface->Packet;
561
562 HubDescriptor = &PdoExtension->RootHubDescriptors->Descriptor;
563 NumberOfPorts = HubDescriptor->bNumberOfPorts;
564
565 PortStatus.AsUlong32 = 0;
566 HubStatus.AsUlong32 = 0;
567
568 Urb = Transfer->Urb;
569 TransferLength = Transfer->TransferParameters.TransferBufferLength;
570
571 if (TransferLength)
572 {
573 Buffer = Urb->UrbControlTransfer.TransferBufferMDL->MappedSystemVa;
574 }
575 else
576 {
577 Buffer = NULL;
578 }
579
580 /* Check parameters */
581
582 if (!Buffer)
583 {
584 /* Not valid parameter */
585 DPRINT1("USBPORT_RootHubSCE: Error! Buffer is NULL\n");
587 }
588
589 if ((TransferLength < (NumberOfPorts / 8 + 1)))
590 {
591 /* Not valid parameters */
592 DPRINT1("USBPORT_RootHubSCE: Error! TransferLength - %x, NumberOfPorts - %x\n",
593 TransferLength,
595
597 }
598
599 RtlZeroMemory(Buffer, TransferLength);
600
601 AddressBitMap = Buffer;
602
603 /* Scan all the ports for changes */
604 for (Port = 1; Port <= NumberOfPorts; Port++)
605 {
606 DPRINT_CORE("USBPORT_RootHubSCE: Port - %p\n", Port);
607
608 /* Request the port status from miniport */
609 if (Packet->RH_GetPortStatus(FdoExtension->MiniPortExt,
610 Port,
611 &PortStatus))
612 {
613 /* Miniport returned an error */
614 DPRINT1("USBPORT_RootHubSCE: RH_GetPortStatus failed\n");
616 }
617
618 if (PortStatus.PortChange.Usb20PortChange.ConnectStatusChange ||
619 PortStatus.PortChange.Usb20PortChange.PortEnableDisableChange ||
620 PortStatus.PortChange.Usb20PortChange.SuspendChange ||
621 PortStatus.PortChange.Usb20PortChange.OverCurrentIndicatorChange ||
622 PortStatus.PortChange.Usb20PortChange.ResetChange)
623 {
624 /* At the port status there is a change */
625 AddressBitMap[Port >> 5] |= 1 << (Port & 0x1F);
626 RHStatus = RH_STATUS_SUCCESS;
627 }
628 }
629
630 /* Request the hub status from miniport */
631 if (!Packet->RH_GetHubStatus(FdoExtension->MiniPortExt, &HubStatus))
632 {
633 if (HubStatus.HubChange.LocalPowerChange == 1 ||
634 HubStatus.HubChange.OverCurrentChange == 1)
635 {
636 /* At the hub status there is a change */
637 AddressBitMap[0] |= 1;
638 RHStatus = RH_STATUS_SUCCESS;
639 }
640
641 if (RHStatus == RH_STATUS_SUCCESS)
642 {
643 /* Done */
644 Urb->UrbControlTransfer.TransferBufferLength = TransferLength;
645 return RH_STATUS_SUCCESS;
646 }
647
648 if (RHStatus == RH_STATUS_NO_CHANGES)
649 {
650 /* No changes. Enable IRQs for miniport root hub */
651 Packet->RH_EnableIrq(FdoExtension->MiniPortExt);
652 }
653
654 return RHStatus;
655 }
656
657 /* Miniport returned an error */
658 DPRINT1("USBPORT_RootHubSCE: RH_GetHubStatus failed\n");
660}
_Outptr_ PUSB_DEVICE_HANDLE _In_ PUSB_DEVICE_HANDLE _In_ USHORT PortStatus
Definition: hubbusif.h:42
#define NumberOfPorts()
Definition: portcls.h:444
PDEVICE_OBJECT FdoDevice
Definition: usbport.h:206
USHORT OverCurrentChange
Definition: usb200.h:262
USHORT LocalPowerChange
Definition: usb200.h:261
USB_HUB_CHANGE HubChange
Definition: usb200.h:273

Referenced by USBPORT_RootHubEndpointWorker().

◆ USBPORT_RootHubStandardCommand()

RHSTATUS NTAPI USBPORT_RootHubStandardCommand ( IN PDEVICE_OBJECT  FdoDevice,
IN PUSB_DEFAULT_PIPE_SETUP_PACKET  SetupPacket,
IN PVOID  Buffer,
IN OUT PULONG  TransferLength 
)

Definition at line 331 of file roothub.c.

335{
341 SIZE_T DescriptorLength;
342 MPSTATUS MPStatus;
345
346 DPRINT("USBPORT_RootHubStandardCommand: USB command - %x, TransferLength - %p\n",
347 SetupPacket->bRequest,
348 TransferLength);
349
350 FdoExtension = FdoDevice->DeviceExtension;
351 PdoExtension = FdoExtension->RootHubPdo->DeviceExtension;
352 Packet = &FdoExtension->MiniPortInterface->Packet;
353
354 switch (SetupPacket->bRequest)
355 {
357 if (SetupPacket->wValue.LowByte ||
358 !(SetupPacket->bmRequestType.Dir))
359 {
360 return RHStatus;
361 }
362
363 switch (SetupPacket->wValue.HiByte)
364 {
366 Descriptor = &PdoExtension->RootHubDescriptors->DeviceDescriptor;
367 DescriptorLength = sizeof(USB_DEVICE_DESCRIPTOR);
368 break;
369
371 Descriptor = &PdoExtension->RootHubDescriptors->ConfigDescriptor;
372 DescriptorLength = sizeof(USB_CONFIGURATION_DESCRIPTOR) +
375 break;
376
377 default:
378 DPRINT1("USBPORT_RootHubStandardCommand: Not supported Descriptor Type - %x\n",
379 SetupPacket->wValue.HiByte);
380 return RHStatus;
381 }
382
383 if (!Descriptor)
384 {
385 return RHStatus;
386 }
387
388 if (*TransferLength >= DescriptorLength)
389 Length = DescriptorLength;
390 else
391 Length = *TransferLength;
392
394 *TransferLength = Length;
395
396 RHStatus = RH_STATUS_SUCCESS;
397 break;
398
400 if (!SetupPacket->wValue.W &&
401 SetupPacket->wLength == sizeof(USHORT) &&
402 !SetupPacket->wIndex.W &&
403 SetupPacket->bmRequestType.Dir == BMREQUEST_DEVICE_TO_HOST)
404 {
405 KeAcquireSpinLock(&FdoExtension->MiniportSpinLock, &OldIrql);
406
407 MPStatus = Packet->RH_GetStatus(FdoExtension->MiniPortExt,
408 Buffer);
409
410 KeReleaseSpinLock(&FdoExtension->MiniportSpinLock, OldIrql);
411
412 *TransferLength = sizeof(USHORT);
413 RHStatus = USBPORT_MPStatusToRHStatus(MPStatus);
414 }
415
416 break;
417
419 if (SetupPacket->wValue.W ||
420 SetupPacket->wIndex.W ||
421 SetupPacket->wLength != 1 ||
422 SetupPacket->bmRequestType.Dir == BMREQUEST_HOST_TO_DEVICE)
423 {
424 return RHStatus;
425 }
426
427 Length = 0;
428
429 if (*TransferLength >= 1)
430 {
431 Length = 1;
432 RtlCopyMemory(Buffer, &PdoExtension->ConfigurationValue, Length);
433 }
434
435 *TransferLength = Length;
436
437 RHStatus = RH_STATUS_SUCCESS;
438 break;
439
441 if (!SetupPacket->wIndex.W &&
442 !SetupPacket->wLength &&
443 !(SetupPacket->bmRequestType.Dir == BMREQUEST_DEVICE_TO_HOST))
444 {
445 if (SetupPacket->wValue.W == 0 ||
446 SetupPacket->wValue.W ==
447 PdoExtension->RootHubDescriptors->ConfigDescriptor.bConfigurationValue)
448 {
449 PdoExtension->ConfigurationValue = SetupPacket->wValue.LowByte;
450 RHStatus = RH_STATUS_SUCCESS;
451 }
452 }
453
454 break;
455
457 if (!SetupPacket->wIndex.W &&
458 !SetupPacket->wLength &&
459 !(SetupPacket->bmRequestType.Dir))
460 {
461 PdoExtension->DeviceHandle.DeviceAddress = SetupPacket->wValue.LowByte;
462 RHStatus = RH_STATUS_SUCCESS;
463 break;
464 }
465
466 break;
467
468 default:
469 DPRINT1("USBPORT_RootHubStandardCommand: Not supported USB request - %x\n",
470 SetupPacket->bRequest);
471 //USB_REQUEST_CLEAR_FEATURE 0x01
472 //USB_REQUEST_SET_FEATURE 0x03
473 //USB_REQUEST_SET_DESCRIPTOR 0x07
474 //USB_REQUEST_GET_INTERFACE 0x0A
475 //USB_REQUEST_SET_INTERFACE 0x0B
476 //USB_REQUEST_SYNC_FRAME 0x0C
477 break;
478 }
479
480 return RHStatus;
481}
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
#define USB_REQUEST_GET_CONFIGURATION
Definition: usb100.h:84
#define BMREQUEST_HOST_TO_DEVICE
Definition: usb100.h:31
#define USB_REQUEST_SET_CONFIGURATION
Definition: usb100.h:85
#define USB_REQUEST_SET_ADDRESS
Definition: usb100.h:81
_Must_inspect_result_ _In_ WDFIORESLIST _In_ PIO_RESOURCE_DESCRIPTOR Descriptor
Definition: wdfresource.h:342

Referenced by USBPORT_RootHubEndpoint0().