win-pvdrivers

view xenusb/xenusb_huburb.c @ 662:21e041d3e07d

Lots of little fixes.
usbview now works.
Advanced properties of HCD in device manager still crashes.
author James Harper <james.harper@bendigoit.com.au>
date Tue Sep 15 20:17:23 2009 +1000 (2009-09-15)
parents 43a106f19847
children b59c7dfdee9b
line source
1 /*
2 PV Drivers for Windows Xen HVM Domains
3 Copyright (C) 2007 James Harper
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
20 #include "xenusb.h"
22 VOID
23 XenUsb_EvtIoInternalDeviceControl_ROOTHUB_SUBMIT_URB(
24 WDFQUEUE queue,
25 WDFREQUEST request,
26 size_t output_buffer_length,
27 size_t input_buffer_length,
28 ULONG io_control_code)
29 {
30 NTSTATUS status;
31 WDFDEVICE device = WdfIoQueueGetDevice(queue);
32 PXENUSB_PDO_DEVICE_DATA xupdd = GetXupdd(device);
33 PXENUSB_DEVICE_DATA xudd = GetXudd(xupdd->wdf_device_bus_fdo);
34 WDF_REQUEST_PARAMETERS wrp;
35 PURB urb;
36 PUSBD_INTERFACE_INFORMATION interface_information;
37 ULONG i, j;
38 xenusb_device_t *usb_device;
39 PUSB_HUB_DESCRIPTOR uhd;
40 xenusb_endpoint_t *endpoint;
42 UNREFERENCED_PARAMETER(input_buffer_length);
43 UNREFERENCED_PARAMETER(output_buffer_length);
45 //FUNCTION_ENTER();
47 ASSERT(io_control_code == IOCTL_INTERNAL_USB_SUBMIT_URB);
49 status = STATUS_UNSUCCESSFUL;
51 WDF_REQUEST_PARAMETERS_INIT(&wrp);
52 WdfRequestGetParameters(request, &wrp);
54 urb = (PURB)wrp.Parameters.Others.Arg1;
55 ASSERT(urb);
56 #if 0
57 KdPrint((__DRIVER_NAME " urb = %p\n", urb));
58 KdPrint((__DRIVER_NAME " Length = %d\n", urb->UrbHeader.Length));
59 KdPrint((__DRIVER_NAME " Function = %d\n", urb->UrbHeader.Function));
60 KdPrint((__DRIVER_NAME " Status = %d\n", urb->UrbHeader.Status));
61 KdPrint((__DRIVER_NAME " UsbdDeviceHandle = %p\n", urb->UrbHeader.UsbdDeviceHandle));
62 KdPrint((__DRIVER_NAME " UsbdFlags = %08x\n", urb->UrbHeader.UsbdFlags));
63 #endif
64 usb_device = urb->UrbHeader.UsbdDeviceHandle;
66 if (!usb_device)
67 usb_device = xupdd->usb_device;
69 switch(urb->UrbHeader.Function)
70 {
71 case URB_FUNCTION_SELECT_CONFIGURATION:
72 KdPrint((__DRIVER_NAME " URB_FUNCTION_SELECT_CONFIGURATION\n"));
73 KdPrint((__DRIVER_NAME " ConfigurationDescriptor = %p\n", urb->UrbSelectConfiguration.ConfigurationDescriptor));
74 if (urb->UrbSelectConfiguration.ConfigurationDescriptor)
75 {
76 KdPrint((__DRIVER_NAME " bLength = %d\n", urb->UrbSelectConfiguration.ConfigurationDescriptor->bLength));
77 KdPrint((__DRIVER_NAME " bDescriptorType = %d\n", urb->UrbSelectConfiguration.ConfigurationDescriptor->bDescriptorType));
78 KdPrint((__DRIVER_NAME " wTotalLength = %d\n", urb->UrbSelectConfiguration.ConfigurationDescriptor->wTotalLength));
79 KdPrint((__DRIVER_NAME " bNumInterfaces = %d\n", urb->UrbSelectConfiguration.ConfigurationDescriptor->bNumInterfaces));
80 KdPrint((__DRIVER_NAME " bConfigurationValue = %d\n", urb->UrbSelectConfiguration.ConfigurationDescriptor->bConfigurationValue));
81 KdPrint((__DRIVER_NAME " iConfiguration = %d\n", urb->UrbSelectConfiguration.ConfigurationDescriptor->iConfiguration));
82 KdPrint((__DRIVER_NAME " bmAttributes = %04x\n", urb->UrbSelectConfiguration.ConfigurationDescriptor->bmAttributes));
83 KdPrint((__DRIVER_NAME " MaxPower = %d\n", urb->UrbSelectConfiguration.ConfigurationDescriptor->MaxPower));
84 }
85 KdPrint((__DRIVER_NAME " ConfigurationHandle = %p\n", urb->UrbSelectConfiguration.ConfigurationHandle));
86 if (urb->UrbSelectConfiguration.ConfigurationDescriptor)
87 {
88 urb->UrbSelectConfiguration.ConfigurationHandle = xupdd->usb_device->configs[0];
89 interface_information = &urb->UrbSelectConfiguration.Interface;
90 for (i = 0; i < urb->UrbSelectConfiguration.ConfigurationDescriptor->bNumInterfaces; i++)
91 {
92 KdPrint((__DRIVER_NAME " InterfaceInformation[%d]\n", i));
93 KdPrint((__DRIVER_NAME " Length = %d\n", interface_information->Length));
94 KdPrint((__DRIVER_NAME " InterfaceNumber = %d\n", interface_information->InterfaceNumber));
95 KdPrint((__DRIVER_NAME " AlternateSetting = %d\n", interface_information->AlternateSetting));
96 KdPrint((__DRIVER_NAME " Class = %02x\n", (ULONG)interface_information->Class));
97 KdPrint((__DRIVER_NAME " SubClass = %02x\n", (ULONG)interface_information->SubClass));
98 KdPrint((__DRIVER_NAME " Protocol = %02x\n", (ULONG)interface_information->Protocol));
99 KdPrint((__DRIVER_NAME " Reserved = %02x\n", (ULONG)interface_information->Reserved));
100 KdPrint((__DRIVER_NAME " InterfaceHandle = %p\n", interface_information->InterfaceHandle));
101 KdPrint((__DRIVER_NAME " NumberOfPipes = %d\n", interface_information->NumberOfPipes));
102 interface_information->InterfaceHandle = xupdd->usb_device->configs[0]->interfaces[0];
103 interface_information->Class = 0x09;
104 interface_information->SubClass = 0x00;
105 interface_information->SubClass = 0x00;
106 for (j = 0; j < interface_information->NumberOfPipes; j++)
107 {
108 KdPrint((__DRIVER_NAME " Pipe[%d]\n", i));
109 KdPrint((__DRIVER_NAME " MaximumPacketSize = %d\n", interface_information->Pipes[j].MaximumPacketSize));
110 KdPrint((__DRIVER_NAME " EndpointAddress = %d\n", interface_information->Pipes[j].EndpointAddress));
111 KdPrint((__DRIVER_NAME " Interval = %d\n", interface_information->Pipes[j].Interval));
112 KdPrint((__DRIVER_NAME " PipeType = %d\n", interface_information->Pipes[j].PipeType));
113 KdPrint((__DRIVER_NAME " PipeHandle = %d\n", interface_information->Pipes[j].PipeHandle));
114 KdPrint((__DRIVER_NAME " MaximumTransferSize = %d\n", interface_information->Pipes[j].MaximumTransferSize));
115 KdPrint((__DRIVER_NAME " PipeFlags = %08x\n", interface_information->Pipes[j].PipeFlags));
116 interface_information->Pipes[j].MaximumPacketSize = 2;
117 interface_information->Pipes[j].EndpointAddress = 0x81;
118 interface_information->Pipes[j].Interval = 12;
119 interface_information->Pipes[j].PipeType = UsbdPipeTypeInterrupt;
120 interface_information->Pipes[j].PipeHandle = xupdd->usb_device->configs[0]->interfaces[0]->endpoints[j];
121 interface_information->Pipes[j].MaximumTransferSize = 4096; /* made up number - possibly not used */
122 // this is input actually interface_information->Pipes[j].PipeFlags = 0;
123 }
124 interface_information = (PUSBD_INTERFACE_INFORMATION)((PUCHAR)interface_information + interface_information->Length);
125 }
126 }
127 urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
128 WdfRequestComplete(request, STATUS_SUCCESS);
129 break;
130 case URB_FUNCTION_SELECT_INTERFACE:
131 KdPrint((__DRIVER_NAME " URB_FUNCTION_SELECT_INTERFACE\n"));
132 interface_information = &urb->UrbSelectInterface.Interface;
133 KdPrint((__DRIVER_NAME " InterfaceInformation\n"));
134 KdPrint((__DRIVER_NAME " Length = %d\n", interface_information->Length));
135 KdPrint((__DRIVER_NAME " InterfaceNumber = %d\n", interface_information->InterfaceNumber));
136 KdPrint((__DRIVER_NAME " AlternateSetting = %d\n", interface_information->AlternateSetting));
137 KdPrint((__DRIVER_NAME " Class = %02x\n", (ULONG)interface_information->Class));
138 KdPrint((__DRIVER_NAME " SubClass = %02x\n", (ULONG)interface_information->SubClass));
139 KdPrint((__DRIVER_NAME " Protocol = %02x\n", (ULONG)interface_information->Protocol));
140 KdPrint((__DRIVER_NAME " Reserved = %02x\n", (ULONG)interface_information->Reserved));
141 KdPrint((__DRIVER_NAME " InterfaceHandle = %p\n", interface_information->InterfaceHandle));
142 KdPrint((__DRIVER_NAME " NumberOfPipes = %d\n", interface_information->NumberOfPipes));
143 for (i = 0; i < interface_information->NumberOfPipes; i++)
144 {
145 KdPrint((__DRIVER_NAME " Pipe[%d]\n", i));
146 KdPrint((__DRIVER_NAME " MaximumPacketSize = %d\n", interface_information->Pipes[i].MaximumPacketSize));
147 KdPrint((__DRIVER_NAME " EndpointAddress = %d\n", interface_information->Pipes[i].EndpointAddress));
148 KdPrint((__DRIVER_NAME " Interval = %d\n", interface_information->Pipes[i].Interval));
149 KdPrint((__DRIVER_NAME " PipeType = %d\n", interface_information->Pipes[i].PipeType));
150 KdPrint((__DRIVER_NAME " PipeHandle = %d\n", interface_information->Pipes[i].PipeHandle));
151 KdPrint((__DRIVER_NAME " MaximumTransferSize = %d\n", interface_information->Pipes[i].MaximumTransferSize));
152 KdPrint((__DRIVER_NAME " PipeFlags = %08x\n", interface_information->Pipes[i].PipeFlags));
153 }
154 urb->UrbHeader.Status = USBD_STATUS_INVALID_URB_FUNCTION;
155 WdfRequestComplete(request, STATUS_UNSUCCESSFUL);
156 break;
157 case URB_FUNCTION_GET_DESCRIPTOR_FROM_DEVICE:
158 //case URB_FUNCTION_GET_DESCRIPTOR_FROM_ENDPOINT:
159 //case URB_FUNCTION_GET_DESCRIPTOR_FROM_INTERFACE:
160 KdPrint((__DRIVER_NAME " URB_FUNCTION_GET_DESCRIPTOR_FROM_XXX\n"));
161 KdPrint((__DRIVER_NAME " Reserved = %p\n", urb->UrbControlDescriptorRequest.Reserved));
162 KdPrint((__DRIVER_NAME " Reserved0 = %08X\n", urb->UrbControlDescriptorRequest.Reserved0));
163 KdPrint((__DRIVER_NAME " TransferBufferLength = %d\n", urb->UrbControlDescriptorRequest.TransferBufferLength));
164 KdPrint((__DRIVER_NAME " TransferBuffer = %p\n", urb->UrbControlDescriptorRequest.TransferBuffer));
165 KdPrint((__DRIVER_NAME " TransferBufferMDL = %p\n", urb->UrbControlDescriptorRequest.TransferBufferMDL));
166 KdPrint((__DRIVER_NAME " UrbLink = %p\n", urb->UrbControlDescriptorRequest.UrbLink));
167 KdPrint((__DRIVER_NAME " hca.Reserved8[0] = %p\n", urb->UrbControlDescriptorRequest.hca.Reserved8[0]));
168 KdPrint((__DRIVER_NAME " hca.Reserved8[1] = %p\n", urb->UrbControlDescriptorRequest.hca.Reserved8[1]));
169 KdPrint((__DRIVER_NAME " hca.Reserved8[2] = %p\n", urb->UrbControlDescriptorRequest.hca.Reserved8[2]));
170 KdPrint((__DRIVER_NAME " hca.Reserved8[3] = %p\n", urb->UrbControlDescriptorRequest.hca.Reserved8[3]));
171 KdPrint((__DRIVER_NAME " hca.Reserved8[4] = %p\n", urb->UrbControlDescriptorRequest.hca.Reserved8[4]));
172 KdPrint((__DRIVER_NAME " hca.Reserved8[5] = %p\n", urb->UrbControlDescriptorRequest.hca.Reserved8[5]));
173 KdPrint((__DRIVER_NAME " hca.Reserved8[6] = %p\n", urb->UrbControlDescriptorRequest.hca.Reserved8[6]));
174 KdPrint((__DRIVER_NAME " hca.Reserved8[7] = %p\n", urb->UrbControlDescriptorRequest.hca.Reserved8[7]));
175 KdPrint((__DRIVER_NAME " Reserved1 = %04x\n", urb->UrbControlDescriptorRequest.Reserved1));
176 KdPrint((__DRIVER_NAME " Index = %d\n", (int)urb->UrbControlDescriptorRequest.Index));
177 KdPrint((__DRIVER_NAME " DescriptorType = %d\n", (int)urb->UrbControlDescriptorRequest.DescriptorType));
178 KdPrint((__DRIVER_NAME " LanguageId = %04x\n", urb->UrbControlDescriptorRequest.LanguageId));
179 KdPrint((__DRIVER_NAME " Reserved2 = %04X\n", urb->UrbControlDescriptorRequest.Reserved2));
180 switch (urb->UrbControlDescriptorRequest.DescriptorType)
181 {
182 case USB_DEVICE_DESCRIPTOR_TYPE:
183 KdPrint((__DRIVER_NAME " USB_DEVICE_DESCRIPTOR_TYPE\n"));
184 memcpy(urb->UrbControlDescriptorRequest.TransferBuffer, &usb_device->device_descriptor, sizeof(USB_DEVICE_DESCRIPTOR));
185 urb->UrbControlDescriptorRequest.TransferBufferLength = sizeof(USB_DEVICE_DESCRIPTOR);
186 KdPrint((__DRIVER_NAME " TransferBufferLength returned = %d\n", urb->UrbControlDescriptorRequest.TransferBufferLength));
187 break;
188 case USB_CONFIGURATION_DESCRIPTOR_TYPE:
189 {
190 xenusb_config_t *usb_config;
191 PUCHAR ptr;
193 KdPrint((__DRIVER_NAME " USB_CONFIGURATION_DESCRIPTOR_TYPE\n"));
194 usb_config = usb_device->active_config;
195 ptr = (PUCHAR)urb->UrbControlDescriptorRequest.TransferBuffer;
196 memcpy(ptr, &usb_config->config_descriptor, sizeof(USB_CONFIGURATION_DESCRIPTOR));
197 ptr += sizeof(USB_CONFIGURATION_DESCRIPTOR);
198 ((PUSB_CONFIGURATION_DESCRIPTOR)urb->UrbControlDescriptorRequest.TransferBuffer)->wTotalLength = sizeof(USB_CONFIGURATION_DESCRIPTOR);
199 if (urb->UrbControlDescriptorRequest.TransferBufferLength > 9)
200 {
201 for (i = 0; i < usb_config->config_descriptor.bNumInterfaces; i++)
202 {
203 memcpy(ptr, &usb_config->interfaces[i]->interface_descriptor, sizeof(USB_INTERFACE_DESCRIPTOR));
204 KdPrint((__DRIVER_NAME " bInterfaceClass = %02x\n", ((PUSB_INTERFACE_DESCRIPTOR)ptr)->bInterfaceClass));
205 ptr += sizeof(USB_INTERFACE_DESCRIPTOR);
206 ((PUSB_CONFIGURATION_DESCRIPTOR)urb->UrbControlDescriptorRequest.TransferBuffer)->wTotalLength += sizeof(USB_INTERFACE_DESCRIPTOR);
207 for (j = 0; j < usb_config->interfaces[i]->interface_descriptor.bNumEndpoints; j++)
208 {
209 memcpy(ptr, &usb_config->interfaces[i]->endpoints[j]->endpoint_descriptor, sizeof(USB_ENDPOINT_DESCRIPTOR));
210 ptr += sizeof(USB_ENDPOINT_DESCRIPTOR);
211 ((PUSB_CONFIGURATION_DESCRIPTOR)urb->UrbControlDescriptorRequest.TransferBuffer)->wTotalLength += sizeof(USB_ENDPOINT_DESCRIPTOR);
212 }
213 }
214 }
215 urb->UrbControlDescriptorRequest.TransferBufferLength = ((PUSB_CONFIGURATION_DESCRIPTOR)urb->UrbControlDescriptorRequest.TransferBuffer)->wTotalLength;
216 if (urb->UrbControlDescriptorRequest.TransferBufferLength == 9)
217 ((PUSB_CONFIGURATION_DESCRIPTOR)urb->UrbControlDescriptorRequest.TransferBuffer)->wTotalLength = 32;
218 KdPrint((__DRIVER_NAME " TransferBufferLength returned = %d\n", urb->UrbControlDescriptorRequest.TransferBufferLength));
219 break;
220 }
221 default:
222 KdPrint((__DRIVER_NAME " UNKNOWN_DESCRIPTOR_TYPE\n"));
223 break;
224 }
225 urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
226 WdfRequestComplete(request, STATUS_SUCCESS);
227 break;
228 case URB_FUNCTION_GET_STATUS_FROM_DEVICE:
229 KdPrint((__DRIVER_NAME " URB_FUNCTION_GET_STATUS_FROM_DEVICE\n"));
230 KdPrint((__DRIVER_NAME " TransferBufferLength = %d\n", urb->UrbControlGetStatusRequest.TransferBufferLength));
231 KdPrint((__DRIVER_NAME " TransferBuffer = %p\n", urb->UrbControlGetStatusRequest.TransferBuffer));
232 KdPrint((__DRIVER_NAME " TransferBufferMDL = %p\n", urb->UrbControlGetStatusRequest.TransferBufferMDL));
233 KdPrint((__DRIVER_NAME " Index = %04x\n", urb->UrbControlGetStatusRequest.Index));
234 if (urb->UrbControlGetStatusRequest.Index == 0)
235 {
236 urb->UrbControlGetStatusRequest.TransferBufferLength = 2;
237 *(PUSHORT)urb->UrbControlGetStatusRequest.TransferBuffer = 0x0003;
238 urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
239 WdfRequestComplete(request, STATUS_SUCCESS);
240 }
241 else
242 {
243 KdPrint((__DRIVER_NAME " Unknown Index\n"));
244 urb->UrbHeader.Status = USBD_STATUS_INVALID_URB_FUNCTION;
245 WdfRequestComplete(request, STATUS_UNSUCCESSFUL);
246 }
247 break;
248 case URB_FUNCTION_CLASS_DEVICE:
249 #if 0
250 KdPrint((__DRIVER_NAME " URB_FUNCTION_CLASS_DEVICE\n"));
251 KdPrint((__DRIVER_NAME " TransferBufferLength = %d\n", urb->UrbControlVendorClassRequest.TransferBufferLength));
252 KdPrint((__DRIVER_NAME " TransferBuffer = %p\n", urb->UrbControlVendorClassRequest.TransferBuffer));
253 KdPrint((__DRIVER_NAME " TransferBufferMDL = %p\n", urb->UrbControlVendorClassRequest.TransferBufferMDL));
254 KdPrint((__DRIVER_NAME " RequestTypeReservedBits = %02x\n", urb->UrbControlVendorClassRequest.RequestTypeReservedBits));
255 KdPrint((__DRIVER_NAME " Request = %02x\n", urb->UrbControlVendorClassRequest.Request));
256 KdPrint((__DRIVER_NAME " Value = %04x\n", urb->UrbControlVendorClassRequest.Value));
257 KdPrint((__DRIVER_NAME " Index = %04x\n", urb->UrbControlVendorClassRequest.Index));
258 #endif
259 switch (urb->UrbControlVendorClassRequest.Request)
260 {
261 case USB_REQUEST_GET_DESCRIPTOR:
262 KdPrint((__DRIVER_NAME " URB_FUNCTION_CLASS_DEVICE\n"));
263 KdPrint((__DRIVER_NAME " TransferBufferLength = %d\n", urb->UrbControlVendorClassRequest.TransferBufferLength));
264 KdPrint((__DRIVER_NAME " TransferBuffer = %p\n", urb->UrbControlVendorClassRequest.TransferBuffer));
265 KdPrint((__DRIVER_NAME " TransferBufferMDL = %p\n", urb->UrbControlVendorClassRequest.TransferBufferMDL));
266 KdPrint((__DRIVER_NAME " RequestTypeReservedBits = %02x\n", urb->UrbControlVendorClassRequest.RequestTypeReservedBits));
267 KdPrint((__DRIVER_NAME " Request = %02x\n", urb->UrbControlVendorClassRequest.Request));
268 KdPrint((__DRIVER_NAME " Value = %04x\n", urb->UrbControlVendorClassRequest.Value));
269 KdPrint((__DRIVER_NAME " Index = %04x\n", urb->UrbControlVendorClassRequest.Index));
270 KdPrint((__DRIVER_NAME " USB_REQUEST_GET_DESCRIPTOR\n"));
271 switch (urb->UrbControlVendorClassRequest.Value >> 8)
272 {
273 case 0x00:
274 #if 0
275 memcpy(urb->UrbControlVendorClassRequest.TransferBuffer, &usb_device->device_descriptor, sizeof(USB_DEVICE_DESCRIPTOR));
276 urb->UrbControlVendorClassRequest.TransferBufferLength = sizeof(USB_DEVICE_DESCRIPTOR);
277 urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
278 WdfRequestComplete(request, STATUS_SUCCESS);
279 break;
280 #endif
281 case 0x29: // Hub Descriptor
282 KdPrint((__DRIVER_NAME " HUB_DESCRIPTOR\n"));
283 uhd = urb->UrbControlVendorClassRequest.TransferBuffer;
284 urb->UrbControlVendorClassRequest.TransferBufferLength = FIELD_OFFSET(USB_HUB_DESCRIPTOR, bRemoveAndPowerMask[0]) + 2 + 1;
285 uhd->bDescriptorLength = (UCHAR)urb->UrbControlVendorClassRequest.TransferBufferLength;
286 uhd->bDescriptorType = 0x29;
287 uhd->bNumberOfPorts = 8;
288 uhd->wHubCharacteristics = 0x0012; // no power switching no overcurrent protection
289 uhd->bPowerOnToPowerGood = 1; // 2ms units
290 uhd->bHubControlCurrent = 0;
291 // DeviceRemovable bits (includes an extra bit at the start)
292 uhd->bRemoveAndPowerMask[0] = 0;
293 uhd->bRemoveAndPowerMask[1] = 0;
294 // PortPwrCtrlMask
295 uhd->bRemoveAndPowerMask[2] = 0xFF;
296 urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
297 WdfRequestComplete(request, STATUS_SUCCESS);
298 break;
299 default:
300 KdPrint((__DRIVER_NAME " Unknown Value %02x\n", urb->UrbControlVendorClassRequest.Value >> 8));
301 urb->UrbHeader.Status = USBD_STATUS_INVALID_URB_FUNCTION;
302 WdfRequestComplete(request, STATUS_UNSUCCESSFUL);
303 break;
304 }
305 break;
306 case USB_REQUEST_GET_STATUS:
307 KdPrint((__DRIVER_NAME " TransferFlags = %08x\n", urb->UrbControlVendorClassRequest.TransferFlags));
308 KdPrint((__DRIVER_NAME " TransferBufferLength = %d\n", urb->UrbControlVendorClassRequest.TransferBufferLength));
309 KdPrint((__DRIVER_NAME " TransferBuffer = %p\n", urb->UrbControlVendorClassRequest.TransferBuffer));
310 KdPrint((__DRIVER_NAME " TransferBufferMDL = %p\n", urb->UrbControlVendorClassRequest.TransferBufferMDL));
311 KdPrint((__DRIVER_NAME " RequestTypeReservedBits = %02x\n", urb->UrbControlVendorClassRequest.RequestTypeReservedBits));
312 KdPrint((__DRIVER_NAME " Request = %02x\n", urb->UrbControlVendorClassRequest.Request));
313 KdPrint((__DRIVER_NAME " Value = %04x\n", urb->UrbControlVendorClassRequest.Value));
314 KdPrint((__DRIVER_NAME " Index = %04x\n", urb->UrbControlVendorClassRequest.Index));
315 KdPrint((__DRIVER_NAME " USB_REQUEST_GET_STATUS\n"));
316 // Check that RequestTypeReservedBits == 0xA0
317 KdPrint((__DRIVER_NAME " GetHubStatus\n"));
318 /* hub status */
319 // shoud be able to get this field from somewhere else...
320 ((PUSHORT)urb->UrbControlVendorClassRequest.TransferBuffer)[0] = 0x0000;
321 ((PUSHORT)urb->UrbControlVendorClassRequest.TransferBuffer)[1] = 0x0000; /* no change occurred */
322 urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
323 WdfRequestComplete(request, STATUS_SUCCESS);
324 break;
325 case USB_REQUEST_CLEAR_FEATURE:
326 KdPrint((__DRIVER_NAME " TransferFlags = %08x\n", urb->UrbControlVendorClassRequest.TransferFlags));
327 KdPrint((__DRIVER_NAME " TransferBufferLength = %d\n", urb->UrbControlVendorClassRequest.TransferBufferLength));
328 KdPrint((__DRIVER_NAME " TransferBuffer = %p\n", urb->UrbControlVendorClassRequest.TransferBuffer));
329 KdPrint((__DRIVER_NAME " TransferBufferMDL = %p\n", urb->UrbControlVendorClassRequest.TransferBufferMDL));
330 KdPrint((__DRIVER_NAME " RequestTypeReservedBits = %02x\n", urb->UrbControlVendorClassRequest.RequestTypeReservedBits));
331 KdPrint((__DRIVER_NAME " Request = %02x\n", urb->UrbControlVendorClassRequest.Request));
332 KdPrint((__DRIVER_NAME " Value = %04x\n", urb->UrbControlVendorClassRequest.Value));
333 KdPrint((__DRIVER_NAME " Index = %04x\n", urb->UrbControlVendorClassRequest.Index));
334 KdPrint((__DRIVER_NAME " USB_REQUEST_CLEAR_FEATURE\n"));
335 urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
336 WdfRequestComplete(request, STATUS_SUCCESS);
337 break;
338 default:
339 KdPrint((__DRIVER_NAME " TransferFlags = %08x\n", urb->UrbControlVendorClassRequest.TransferFlags));
340 KdPrint((__DRIVER_NAME " TransferBufferLength = %d\n", urb->UrbControlVendorClassRequest.TransferBufferLength));
341 KdPrint((__DRIVER_NAME " TransferBuffer = %p\n", urb->UrbControlVendorClassRequest.TransferBuffer));
342 KdPrint((__DRIVER_NAME " TransferBufferMDL = %p\n", urb->UrbControlVendorClassRequest.TransferBufferMDL));
343 KdPrint((__DRIVER_NAME " RequestTypeReservedBits = %02x\n", urb->UrbControlVendorClassRequest.RequestTypeReservedBits));
344 KdPrint((__DRIVER_NAME " Request = %02x\n", urb->UrbControlVendorClassRequest.Request));
345 KdPrint((__DRIVER_NAME " Value = %04x\n", urb->UrbControlVendorClassRequest.Value));
346 KdPrint((__DRIVER_NAME " Index = %04x\n", urb->UrbControlVendorClassRequest.Index));
347 KdPrint((__DRIVER_NAME " USB_REQUEST_%02x\n", urb->UrbControlVendorClassRequest.Request));
348 urb->UrbHeader.Status = USBD_STATUS_INVALID_URB_FUNCTION;
349 WdfRequestComplete(request, STATUS_UNSUCCESSFUL);
350 break;
351 }
352 break;
353 case URB_FUNCTION_CLASS_OTHER:
354 KdPrint((__DRIVER_NAME " URB_FUNCTION_CLASS_OTHER\n"));
355 KdPrint((__DRIVER_NAME " TransferFlags = %08x\n", urb->UrbControlVendorClassRequest.TransferFlags));
356 KdPrint((__DRIVER_NAME " TransferBufferLength = %d\n", urb->UrbControlVendorClassRequest.TransferBufferLength));
357 KdPrint((__DRIVER_NAME " TransferBuffer = %p\n", urb->UrbControlVendorClassRequest.TransferBuffer));
358 KdPrint((__DRIVER_NAME " TransferBufferMdl = %p\n", urb->UrbControlVendorClassRequest.TransferBufferMDL));
359 KdPrint((__DRIVER_NAME " RequestTypeReservedBits = %02x\n", urb->UrbControlVendorClassRequest.RequestTypeReservedBits));
360 KdPrint((__DRIVER_NAME " Request = %02x\n", urb->UrbControlVendorClassRequest.Request));
361 KdPrint((__DRIVER_NAME " Value = %04x\n", urb->UrbControlVendorClassRequest.Value));
362 KdPrint((__DRIVER_NAME " Index = %04x\n", urb->UrbControlVendorClassRequest.Index));
363 switch (urb->UrbControlVendorClassRequest.Request)
364 {
365 case USB_REQUEST_GET_STATUS:
366 /* port status - 11.24.2.7.1 */
367 KdPrint((__DRIVER_NAME " USB_REQUEST_GET_STATUS\n"));
368 KdPrint((__DRIVER_NAME " GetHubStatus\n"));
369 ((PUSHORT)urb->UrbControlVendorClassRequest.TransferBuffer)[0] = xudd->ports[urb->UrbControlVendorClassRequest.Index - 1].port_status;
370 ((PUSHORT)urb->UrbControlVendorClassRequest.TransferBuffer)[1] = xudd->ports[urb->UrbControlVendorClassRequest.Index - 1].port_change;
371 break;
372 case USB_REQUEST_SET_FEATURE:
373 KdPrint((__DRIVER_NAME " USB_REQUEST_SET_FEATURE\n"));
374 KdPrint((__DRIVER_NAME " SetPortFeature\n"));
375 switch (urb->UrbControlVendorClassRequest.Value)
376 {
377 case PORT_ENABLE:
378 KdPrint((__DRIVER_NAME " PORT_ENABLE\n"));
379 /* do something here */
380 break;
381 case PORT_RESET:
382 KdPrint((__DRIVER_NAME " PORT_RESET\n"));
383 /* just fake the reset */
384 xudd->ports[urb->UrbControlVendorClassRequest.Index - 1].port_change |= (1 << PORT_RESET);
385 break;
386 default:
387 KdPrint((__DRIVER_NAME " Unknown Value %04X\n", urb->UrbControlVendorClassRequest.Value));
388 break;
389 }
390 KdPrint((__DRIVER_NAME " status = %04x, change = %04x\n",
391 xudd->ports[urb->UrbControlVendorClassRequest.Index - 1].port_status,
392 xudd->ports[urb->UrbControlVendorClassRequest.Index - 1].port_change));
393 break;
394 case USB_REQUEST_CLEAR_FEATURE:
395 KdPrint((__DRIVER_NAME " USB_REQUEST_CLEAR_FEATURE\n"));
396 KdPrint((__DRIVER_NAME " ClearPortFeature\n"));
397 switch (urb->UrbControlVendorClassRequest.Value)
398 {
399 case C_PORT_CONNECTION:
400 KdPrint((__DRIVER_NAME " C_PORT_CONNECTION\n"));
401 xudd->ports[urb->UrbControlVendorClassRequest.Index - 1].port_change &= ~(1 << PORT_CONNECTION);
402 break;
403 case C_PORT_RESET:
404 KdPrint((__DRIVER_NAME " C_PORT_RESET\n"));
405 xudd->ports[urb->UrbControlVendorClassRequest.Index - 1].port_change &= ~(1 << PORT_RESET);
406 break;
407 default:
408 KdPrint((__DRIVER_NAME " Unknown Value %04X\n", urb->UrbControlVendorClassRequest.Value));
409 break;
410 }
411 KdPrint((__DRIVER_NAME " status = %04x, change = %04x\n",
412 xudd->ports[urb->UrbControlVendorClassRequest.Index - 1].port_status,
413 xudd->ports[urb->UrbControlVendorClassRequest.Index - 1].port_change));
414 break;
415 default:
416 KdPrint((__DRIVER_NAME " USB_REQUEST_%02x\n", urb->UrbControlVendorClassRequest.Request));
417 break;
418 }
419 urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
420 WdfRequestComplete(request, STATUS_SUCCESS);
421 //urb->UrbHeader.Status = USBD_STATUS_INVALID_URB_FUNCTION;
422 //WdfRequestComplete(request, STATUS_UNSUCCESSFUL);
423 break;
424 case URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER: /* 11.12.4 */
425 #if 0
426 KdPrint((__DRIVER_NAME " URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER\n"));
427 KdPrint((__DRIVER_NAME " PipeHandle = %p\n", urb->UrbBulkOrInterruptTransfer.PipeHandle));
428 KdPrint((__DRIVER_NAME " TransferFlags = %08x\n", urb->UrbBulkOrInterruptTransfer.TransferFlags));
429 KdPrint((__DRIVER_NAME " TransferBufferLength = %d\n", urb->UrbBulkOrInterruptTransfer.TransferBufferLength));
430 KdPrint((__DRIVER_NAME " TransferBuffer = %p\n", urb->UrbBulkOrInterruptTransfer.TransferBuffer));
431 KdPrint((__DRIVER_NAME " TransferBufferMdl = %p\n", urb->UrbBulkOrInterruptTransfer.TransferBufferMDL));
432 #endif
433 endpoint = urb->UrbBulkOrInterruptTransfer.PipeHandle;
434 WdfSpinLockAcquire (endpoint->interrupt_lock);
435 // we should synchronise to the timer here to prevent a race
436 if (WdfIoQueueGetState(endpoint->interrupt_queue, NULL, NULL) & WdfIoQueueNoRequests)
437 {
438 status = WdfTimerStart(endpoint->interrupt_timer, WDF_REL_TIMEOUT_IN_MS(100));
439 }
440 status = WdfRequestForwardToIoQueue(request, endpoint->interrupt_queue);
441 WdfSpinLockRelease(endpoint->interrupt_lock);
442 break;
443 case URB_FUNCTION_SYNC_RESET_PIPE_AND_CLEAR_STALL:
444 KdPrint((__DRIVER_NAME " URB_FUNCTION_SYNC_RESET_PIPE_AND_CLEAR_STALL\n"));
445 KdPrint((__DRIVER_NAME " PipeHandle = %p\n", urb->UrbPipeRequest.PipeHandle));
446 urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
447 WdfRequestComplete(request, STATUS_SUCCESS);
448 break;
449 default:
450 KdPrint((__DRIVER_NAME " URB_FUNCTION_%04x\n", urb->UrbHeader.Function));
451 KdPrint((__DRIVER_NAME " Calling WdfRequestCompletestatus with status = %08x\n", status));
452 urb->UrbHeader.Status = USBD_STATUS_INVALID_URB_FUNCTION;
453 WdfRequestComplete(request, STATUS_UNSUCCESSFUL);
454 break;
455 }
457 //FUNCTION_EXIT();
458 }