ReactOS  0.4.14-dev-342-gdc047f9
hub_fdo.c File Reference
#include "usbhub.h"
#include <debug.h>
Include dependency graph for hub_fdo.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

NTSTATUS USBHUB_ParentFDOStartDevice (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 13 of file hub_fdo.c.

Function Documentation

◆ USBHUB_ParentFDOStartDevice()

NTSTATUS USBHUB_ParentFDOStartDevice ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 17 of file hub_fdo.c.

20 {
21  PHUB_DEVICE_EXTENSION HubDeviceExtension;
22  PURB Urb, ConfigurationUrb;
23  PUSB_INTERFACE_DESCRIPTOR InterfaceDescriptor;
25  ULONG Index;
27 
28  // get hub device extension
29  HubDeviceExtension = (PHUB_DEVICE_EXTENSION) DeviceObject->DeviceExtension;
30 
31  // Send the StartDevice to lower device object
32  Status = ForwardIrpAndWait(HubDeviceExtension->LowerDeviceObject, Irp);
33 
34  if (!NT_SUCCESS(Status))
35  {
36  // failed to start pdo
37  DPRINT1("Failed to start the RootHub PDO\n");
38  return Status;
39  }
40 
41  // FIXME get capabilities
42 
43  Urb = ExAllocatePool(NonPagedPool, sizeof(URB));
44  if (!Urb)
45  {
46  // no memory
47  DPRINT1("No memory\n");
49  }
50 
51 
52  // lets get device descriptor
54  sizeof(Urb->UrbControlDescriptorRequest),
56  0,
57  0,
58  &HubDeviceExtension->HubDeviceDescriptor,
59  NULL,
60  sizeof(USB_DEVICE_DESCRIPTOR),
61  NULL);
62 
63 
64  // get hub device descriptor
65  Status = SubmitRequestToRootHub(HubDeviceExtension->LowerDeviceObject,
67  Urb,
68  NULL);
69 
70  if (!NT_SUCCESS(Status))
71  {
72  // failed to get device descriptor of hub
73  DPRINT1("Failed to get hub device descriptor with Status %x!\n", Status);
74  ExFreePool(Urb);
75  return Status;
76  }
77 
78  // now get configuration descriptor
80  sizeof(Urb->UrbControlDescriptorRequest),
82  0,
83  0,
84  &HubDeviceExtension->HubConfigDescriptor,
85  NULL,
87  NULL);
88 
89  // request configuration descriptor
90  Status = SubmitRequestToRootHub(HubDeviceExtension->LowerDeviceObject,
92  Urb,
93  NULL);
94 
95  if (!NT_SUCCESS(Status))
96  {
97  // failed to get configuration descriptor
98  DPRINT1("Failed to get hub configuration descriptor with status %x\n", Status);
99  ExFreePool(Urb);
100  return Status;
101  }
102 
103  // sanity checks
106  ASSERT(HubDeviceExtension->HubConfigDescriptor.bLength == sizeof(USB_CONFIGURATION_DESCRIPTOR));
107  ASSERT(HubDeviceExtension->HubConfigDescriptor.bNumInterfaces == 1);
108  ASSERT(HubDeviceExtension->HubInterfaceDescriptor.bLength == sizeof(USB_INTERFACE_DESCRIPTOR));
110  ASSERT(HubDeviceExtension->HubInterfaceDescriptor.bNumEndpoints == 1);
112  ASSERT(HubDeviceExtension->HubEndPointDescriptor.bLength == sizeof(USB_ENDPOINT_DESCRIPTOR));
114  ASSERT(HubDeviceExtension->HubEndPointDescriptor.bEndpointAddress == 0x81); // interrupt in
115 
116  // Build hub descriptor request
119  sizeof(Urb->UrbControlVendorClassRequest),
121  0,
124  0,
125  &HubDeviceExtension->HubDescriptor,
126  NULL,
127  sizeof(USB_HUB_DESCRIPTOR),
128  NULL);
129 
130  // send request
131  Status = SubmitRequestToRootHub(HubDeviceExtension->LowerDeviceObject,
133  Urb,
134  NULL);
135 
136  if (!NT_SUCCESS(Status))
137  {
138  DPRINT1("Failed to get Hub Descriptor Status %x!\n", Status);
139  ExFreePool(Urb);
140  return STATUS_UNSUCCESSFUL;
141  }
142 
143  // sanity checks
144  ASSERT(HubDeviceExtension->HubDescriptor.bDescriptorLength == sizeof(USB_HUB_DESCRIPTOR));
145  ASSERT(HubDeviceExtension->HubDescriptor.bNumberOfPorts);
146  ASSERT(HubDeviceExtension->HubDescriptor.bDescriptorType == 0x29);
147 
148  // store number of ports
149  DPRINT1("NumberOfPorts %lu\n", HubDeviceExtension->HubDescriptor.bNumberOfPorts);
150  HubDeviceExtension->UsbExtHubInfo.NumberOfPorts = HubDeviceExtension->HubDescriptor.bNumberOfPorts;
151 
152  // allocate interface list
154  if (!InterfaceList)
155  {
156  // no memory
157  DPRINT1("No memory\n");
159  }
160 
161  // zero list
163 
164  // grab all interface descriptors
165  for(Index = 0; Index < HubDeviceExtension->HubConfigDescriptor.bNumInterfaces; Index++)
166  {
167  // Get the first Configuration Descriptor
168  InterfaceDescriptor = USBD_ParseConfigurationDescriptorEx(&HubDeviceExtension->HubConfigDescriptor,
169  &HubDeviceExtension->HubConfigDescriptor,
170  Index, 0, -1, -1, -1);
171 
172  // store in list
173  InterfaceList[Index].InterfaceDescriptor = InterfaceDescriptor;
174  }
175 
176  // now create configuration request
177  ConfigurationUrb = USBD_CreateConfigurationRequestEx(&HubDeviceExtension->HubConfigDescriptor,
179  if (ConfigurationUrb == NULL)
180  {
181  // failed to build urb
182  DPRINT1("Failed to build configuration urb\n");
183  ExFreePool(Urb);
185  }
186 
187  // send request
188  Status = SubmitRequestToRootHub(HubDeviceExtension->LowerDeviceObject,
190  ConfigurationUrb,
191  NULL);
192 
193  if (!NT_SUCCESS(Status))
194  {
195  DPRINT1("Failed to get Hub Descriptor Status %x!\n", Status);
196  ExFreePool(Urb);
197  ExFreePool(ConfigurationUrb);
198  return STATUS_UNSUCCESSFUL;
199  }
200 
201  // store configuration & pipe handle
202  HubDeviceExtension->ConfigurationHandle = ConfigurationUrb->UrbSelectConfiguration.ConfigurationHandle;
203  HubDeviceExtension->PipeHandle = ConfigurationUrb->UrbSelectConfiguration.Interface.Pipes[0].PipeHandle;
204  DPRINT("Hub Configuration Handle %x\n", HubDeviceExtension->ConfigurationHandle);
205 
206  // free urb
207  ExFreePool(ConfigurationUrb);
208  ExFreePool(Urb);
209 
210  // FIXME build SCE interrupt request
211 
212  // FIXME create pdos
213 
214  return Status;
215 }
struct _URB_CONTROL_VENDOR_OR_CLASS_REQUEST UrbControlVendorClassRequest
Definition: usb.h:548
USB_DEVICE_DESCRIPTOR HubDeviceDescriptor
Definition: usbhub.h:122
UCHAR bDescriptorLength
Definition: usb100.h:171
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
USB_HUB_DESCRIPTOR HubDescriptor
Definition: usbhub.h:121
#define IOCTL_INTERNAL_USB_SUBMIT_URB
Definition: usbioctl.h:32
_In_ PIRP Irp
Definition: csq.h:116
_In_ PUSBD_INTERFACE_LIST_ENTRY InterfaceList
Definition: usbdlib.h:168
USB_ENDPOINT_DESCRIPTOR HubEndPointDescriptor
Definition: usbhub.h:125
LONG NTSTATUS
Definition: precomp.h:26
#define USBD_TRANSFER_DIRECTION_IN
Definition: usb.h:160
PDEVICE_OBJECT LowerDeviceObject
Definition: usbhub.h:103
struct _HUB_DEVICE_EXTENSION * PHUB_DEVICE_EXTENSION
#define UsbBuildGetDescriptorRequest(urb, length, descriptorType, descriptorIndex, languageId, transferBuffer, transferBufferMDL, transferBufferLength, link)
Definition: usbdlib.h:23
#define UsbBuildVendorRequest(urb, cmd, length, transferFlags, reservedbits, request, value, index, transferBuffer, transferBufferMDL, transferBufferLength, link)
Definition: usbdlib.h:68
#define URB_FUNCTION_CLASS_DEVICE
Definition: usb.h:112
Definition: usbdlib.h:7
#define USB_DEVICE_DESCRIPTOR_TYPE
Definition: usb100.h:49
#define USB_CONFIGURATION_DESCRIPTOR_TYPE
Definition: usb100.h:50
PVOID DeviceExtension
Definition: env_spec_w32.h:418
#define USB_INTERFACE_DESCRIPTOR_TYPE
Definition: usb100.h:52
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
PUSB_INTERFACE_DESCRIPTOR NTAPI USBD_ParseConfigurationDescriptorEx(PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor, PVOID StartPosition, LONG InterfaceNumber, LONG AlternateSetting, LONG InterfaceClass, LONG InterfaceSubClass, LONG InterfaceProtocol)
Definition: usbd.c:496
UCHAR bNumberOfPorts
Definition: usb100.h:173
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static const UCHAR Index[8]
Definition: usbohci.c:18
DRIVER_DISPATCH ForwardIrpAndWait
Definition: i8042prt.h:343
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define USB_REQUEST_GET_DESCRIPTOR
Definition: usb100.h:82
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
#define USB_ENDPOINT_DESCRIPTOR_TYPE
Definition: usb100.h:53
#define USB_DEVICE_CLASS_RESERVED
Definition: usb100.h:90
Status
Definition: gdiplustypes.h:24
USBD_PIPE_HANDLE PipeHandle
Definition: usbhub.h:131
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
USB_CONFIGURATION_DESCRIPTOR HubConfigDescriptor
Definition: usbhub.h:123
#define USBD_SHORT_TRANSFER_OK
Definition: usb.h:154
struct _URB_SELECT_CONFIGURATION UrbSelectConfiguration
Definition: usb.h:533
PUSB_INTERFACE_DESCRIPTOR InterfaceDescriptor
Definition: usbdlib.h:8
Definition: usb.h:529
USB_INTERFACE_DESCRIPTOR HubInterfaceDescriptor
Definition: usbhub.h:124
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
USBD_CONFIGURATION_HANDLE ConfigurationHandle
Definition: usbhub.h:130
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
struct _URB_CONTROL_DESCRIPTOR_REQUEST UrbControlDescriptorRequest
Definition: usb.h:545
PURB NTAPI USBD_CreateConfigurationRequestEx(PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor, PUSBD_INTERFACE_LIST_ENTRY InterfaceList)
Definition: usbd.c:329
USB_EXTHUB_INFORMATION_0 UsbExtHubInfo
Definition: usbhub.h:127
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
UCHAR bDescriptorType
Definition: usb100.h:172
NTSTATUS SubmitRequestToRootHub(IN PDEVICE_OBJECT RootHubDeviceObject, IN ULONG IoControlCode, OUT PVOID OutParameter1, OUT PVOID OutParameter2)
Definition: misc.c:150
#define USB_ENDPOINT_TYPE_INTERRUPT
Definition: usb100.h:65

Referenced by USBHUB_FdoHandlePnp().