|
| 1 | +/* |
| 2 | + * PROJECT: ReactOS Universal Serial Bus Hub Driver |
| 3 | + * LICENSE: GPL - See COPYING in the top level directory |
| 4 | + * FILE: drivers/usb/usbhub/hub_fdo.c |
| 5 | + * PURPOSE: Hub FDO |
| 6 | + * PROGRAMMERS: |
| 7 | + * Michael Martin ([email protected]) |
| 8 | + * Johannes Anderwald ([email protected]) |
| 9 | + */ |
| 10 | +#include "usbhub.h" |
| 11 | + |
| 12 | +NTSTATUS |
| 13 | +USBHUB_ParentFDOStartDevice( |
| 14 | + IN PDEVICE_OBJECT DeviceObject, |
| 15 | + IN PIRP Irp) |
| 16 | +{ |
| 17 | + PHUB_DEVICE_EXTENSION HubDeviceExtension; |
| 18 | + PURB Urb, ConfigurationUrb; |
| 19 | + PUSB_INTERFACE_DESCRIPTOR InterfaceDescriptor; |
| 20 | + PUSBD_INTERFACE_LIST_ENTRY InterfaceList; |
| 21 | + ULONG Index; |
| 22 | + NTSTATUS Status; |
| 23 | + |
| 24 | + // get hub device extension |
| 25 | + HubDeviceExtension = (PHUB_DEVICE_EXTENSION) DeviceObject->DeviceExtension; |
| 26 | + |
| 27 | + // Send the StartDevice to lower device object |
| 28 | + Status = ForwardIrpAndWait(HubDeviceExtension->LowerDeviceObject, Irp); |
| 29 | + |
| 30 | + if (!NT_SUCCESS(Status)) |
| 31 | + { |
| 32 | + // failed to start pdo |
| 33 | + DPRINT1("Failed to start the RootHub PDO\n"); |
| 34 | + return Status; |
| 35 | + } |
| 36 | + |
| 37 | + // FIXME get capabilities |
| 38 | + |
| 39 | + Urb = ExAllocatePool(NonPagedPool, sizeof(URB)); |
| 40 | + if (!Urb) |
| 41 | + { |
| 42 | + // no memory |
| 43 | + DPRINT1("No memory\n"); |
| 44 | + return STATUS_INSUFFICIENT_RESOURCES; |
| 45 | + } |
| 46 | + |
| 47 | + |
| 48 | + // lets get device descriptor |
| 49 | + UsbBuildGetDescriptorRequest(Urb, |
| 50 | + sizeof(Urb->UrbControlDescriptorRequest), |
| 51 | + USB_DEVICE_DESCRIPTOR_TYPE, |
| 52 | + 0, |
| 53 | + 0, |
| 54 | + &HubDeviceExtension->HubDeviceDescriptor, |
| 55 | + NULL, |
| 56 | + sizeof(USB_DEVICE_DESCRIPTOR), |
| 57 | + NULL); |
| 58 | + |
| 59 | + |
| 60 | + // get hub device descriptor |
| 61 | + Status = SubmitRequestToRootHub(HubDeviceExtension->LowerDeviceObject, |
| 62 | + IOCTL_INTERNAL_USB_SUBMIT_URB, |
| 63 | + Urb, |
| 64 | + NULL); |
| 65 | + |
| 66 | + if (!NT_SUCCESS(Status)) |
| 67 | + { |
| 68 | + // failed to get device descriptor of hub |
| 69 | + DPRINT1("Failed to get hub device descriptor with Status %x!\n", Status); |
| 70 | + ExFreePool(Urb); |
| 71 | + return Status; |
| 72 | + } |
| 73 | + |
| 74 | + // now get configuration descriptor |
| 75 | + UsbBuildGetDescriptorRequest(Urb, |
| 76 | + sizeof(Urb->UrbControlDescriptorRequest), |
| 77 | + USB_CONFIGURATION_DESCRIPTOR_TYPE, |
| 78 | + 0, |
| 79 | + 0, |
| 80 | + &HubDeviceExtension->HubConfigDescriptor, |
| 81 | + NULL, |
| 82 | + sizeof(USB_CONFIGURATION_DESCRIPTOR) + sizeof(USB_INTERFACE_DESCRIPTOR) + sizeof(USB_ENDPOINT_DESCRIPTOR), |
| 83 | + NULL); |
| 84 | + |
| 85 | + // request configuration descriptor |
| 86 | + Status = SubmitRequestToRootHub(HubDeviceExtension->LowerDeviceObject, |
| 87 | + IOCTL_INTERNAL_USB_SUBMIT_URB, |
| 88 | + Urb, |
| 89 | + NULL); |
| 90 | + |
| 91 | + if (!NT_SUCCESS(Status)) |
| 92 | + { |
| 93 | + // failed to get configuration descriptor |
| 94 | + DPRINT1("Failed to get hub configuration descriptor with status %x\n", Status); |
| 95 | + ExFreePool(Urb); |
| 96 | + return Status; |
| 97 | + } |
| 98 | + |
| 99 | + // sanity checks |
| 100 | + ASSERT(HubDeviceExtension->HubConfigDescriptor.wTotalLength == sizeof(USB_CONFIGURATION_DESCRIPTOR) + sizeof(USB_INTERFACE_DESCRIPTOR) + sizeof(USB_ENDPOINT_DESCRIPTOR)); |
| 101 | + ASSERT(HubDeviceExtension->HubConfigDescriptor.bDescriptorType == USB_CONFIGURATION_DESCRIPTOR_TYPE); |
| 102 | + ASSERT(HubDeviceExtension->HubConfigDescriptor.bLength == sizeof(USB_CONFIGURATION_DESCRIPTOR)); |
| 103 | + ASSERT(HubDeviceExtension->HubConfigDescriptor.bNumInterfaces == 1); |
| 104 | + ASSERT(HubDeviceExtension->HubInterfaceDescriptor.bLength == sizeof(USB_INTERFACE_DESCRIPTOR)); |
| 105 | + ASSERT(HubDeviceExtension->HubInterfaceDescriptor.bDescriptorType == USB_INTERFACE_DESCRIPTOR_TYPE); |
| 106 | + ASSERT(HubDeviceExtension->HubInterfaceDescriptor.bNumEndpoints == 1); |
| 107 | + ASSERT(HubDeviceExtension->HubEndPointDescriptor.bDescriptorType == USB_ENDPOINT_DESCRIPTOR_TYPE); |
| 108 | + ASSERT(HubDeviceExtension->HubEndPointDescriptor.bLength == sizeof(USB_ENDPOINT_DESCRIPTOR)); |
| 109 | + ASSERT(HubDeviceExtension->HubEndPointDescriptor.bmAttributes == USB_ENDPOINT_TYPE_INTERRUPT); |
| 110 | + ASSERT(HubDeviceExtension->HubEndPointDescriptor.bEndpointAddress == 0x81); // interrupt in |
| 111 | + |
| 112 | + // Build hub descriptor request |
| 113 | + UsbBuildVendorRequest(Urb, |
| 114 | + URB_FUNCTION_CLASS_DEVICE, |
| 115 | + sizeof(Urb->UrbControlVendorClassRequest), |
| 116 | + USBD_TRANSFER_DIRECTION_IN | USBD_SHORT_TRANSFER_OK, |
| 117 | + 0, |
| 118 | + USB_REQUEST_GET_DESCRIPTOR, |
| 119 | + USB_DEVICE_CLASS_RESERVED, |
| 120 | + 0, |
| 121 | + &HubDeviceExtension->HubDescriptor, |
| 122 | + NULL, |
| 123 | + sizeof(USB_HUB_DESCRIPTOR), |
| 124 | + NULL); |
| 125 | + |
| 126 | + // send request |
| 127 | + Status = SubmitRequestToRootHub(HubDeviceExtension->LowerDeviceObject, |
| 128 | + IOCTL_INTERNAL_USB_SUBMIT_URB, |
| 129 | + Urb, |
| 130 | + NULL); |
| 131 | + |
| 132 | + if (!NT_SUCCESS(Status)) |
| 133 | + { |
| 134 | + DPRINT1("Failed to get Hub Descriptor Status %x!\n", Status); |
| 135 | + ExFreePool(Urb); |
| 136 | + return STATUS_UNSUCCESSFUL; |
| 137 | + } |
| 138 | + |
| 139 | + // sanity checks |
| 140 | + ASSERT(HubDeviceExtension->HubDescriptor.bDescriptorLength == sizeof(USB_HUB_DESCRIPTOR)); |
| 141 | + ASSERT(HubDeviceExtension->HubDescriptor.bNumberOfPorts); |
| 142 | + ASSERT(HubDeviceExtension->HubDescriptor.bDescriptorType == 0x29); |
| 143 | + |
| 144 | + // store number of ports |
| 145 | + DPRINT1("NumberOfPorts %lu\n", HubDeviceExtension->HubDescriptor.bNumberOfPorts); |
| 146 | + HubDeviceExtension->UsbExtHubInfo.NumberOfPorts = HubDeviceExtension->HubDescriptor.bNumberOfPorts; |
| 147 | + |
| 148 | + // allocate interface list |
| 149 | + InterfaceList = ExAllocatePool(NonPagedPool, sizeof(USBD_INTERFACE_LIST_ENTRY) * (HubDeviceExtension->HubConfigDescriptor.bNumInterfaces + 1)); |
| 150 | + if (!InterfaceList) |
| 151 | + { |
| 152 | + // no memory |
| 153 | + DPRINT1("No memory\n"); |
| 154 | + return STATUS_INSUFFICIENT_RESOURCES; |
| 155 | + } |
| 156 | + |
| 157 | + // zero list |
| 158 | + RtlZeroMemory(InterfaceList, sizeof(USBD_INTERFACE_LIST_ENTRY) * (HubDeviceExtension->HubConfigDescriptor.bNumInterfaces + 1)); |
| 159 | + |
| 160 | + // grab all interface descriptors |
| 161 | + for(Index = 0; Index < HubDeviceExtension->HubConfigDescriptor.bNumInterfaces; Index++) |
| 162 | + { |
| 163 | + // Get the first Configuration Descriptor |
| 164 | + InterfaceDescriptor = USBD_ParseConfigurationDescriptorEx(&HubDeviceExtension->HubConfigDescriptor, |
| 165 | + &HubDeviceExtension->HubConfigDescriptor, |
| 166 | + Index, 0, -1, -1, -1); |
| 167 | + |
| 168 | + // store in list |
| 169 | + InterfaceList[Index].InterfaceDescriptor = InterfaceDescriptor; |
| 170 | + } |
| 171 | + |
| 172 | + // now create configuration request |
| 173 | + ConfigurationUrb = USBD_CreateConfigurationRequestEx(&HubDeviceExtension->HubConfigDescriptor, |
| 174 | + (PUSBD_INTERFACE_LIST_ENTRY)&InterfaceList); |
| 175 | + if (ConfigurationUrb == NULL) |
| 176 | + { |
| 177 | + // failed to build urb |
| 178 | + DPRINT1("Failed to build configuration urb\n"); |
| 179 | + ExFreePool(Urb); |
| 180 | + return STATUS_INSUFFICIENT_RESOURCES; |
| 181 | + } |
| 182 | + |
| 183 | + // send request |
| 184 | + Status = SubmitRequestToRootHub(HubDeviceExtension->LowerDeviceObject, |
| 185 | + IOCTL_INTERNAL_USB_SUBMIT_URB, |
| 186 | + ConfigurationUrb, |
| 187 | + NULL); |
| 188 | + |
| 189 | + if (!NT_SUCCESS(Status)) |
| 190 | + { |
| 191 | + DPRINT1("Failed to get Hub Descriptor Status %x!\n", Status); |
| 192 | + ExFreePool(Urb); |
| 193 | + ExFreePool(ConfigurationUrb); |
| 194 | + return STATUS_UNSUCCESSFUL; |
| 195 | + } |
| 196 | + |
| 197 | + // store configuration & pipe handle |
| 198 | + HubDeviceExtension->ConfigurationHandle = ConfigurationUrb->UrbSelectConfiguration.ConfigurationHandle; |
| 199 | + HubDeviceExtension->PipeHandle = ConfigurationUrb->UrbSelectConfiguration.Interface.Pipes[0].PipeHandle; |
| 200 | + DPRINT("Hub Configuration Handle %x\n", HubDeviceExtension->ConfigurationHandle); |
| 201 | + |
| 202 | + // free urb |
| 203 | + ExFreePool(ConfigurationUrb); |
| 204 | + ExFreePool(Urb); |
| 205 | + |
| 206 | + // FIXME build SCE interrupt request |
| 207 | + |
| 208 | + // FIXME create pdos |
| 209 | + |
| 210 | + return Status; |
| 211 | +} |
| 212 | + |
0 commit comments