win-pvdrivers

view xenusb/xenusb_huburb.c @ 980:ea3c61839ff5

fix usb-detach hang
author James Harper <james.harper@bendigoit.com.au>
date Sun Apr 15 23:41:21 2012 +1000 (2012-04-15)
parents 1306945ecc59
children 329b9b9d47ec
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 xenusb_endpoint_t *endpoint;
40 //USB_DEFAULT_PIPE_SETUP_PACKET setup_packet;
41 urb_decode_t decode_data;
42 ULONG decode_retval;
44 UNREFERENCED_PARAMETER(input_buffer_length);
45 UNREFERENCED_PARAMETER(output_buffer_length);
46 UNREFERENCED_PARAMETER(io_control_code);
48 //FUNCTION_ENTER();
50 WDF_REQUEST_PARAMETERS_INIT(&wrp);
51 WdfRequestGetParameters(request, &wrp);
53 urb = (PURB)wrp.Parameters.Others.Arg1;
54 ASSERT(urb);
55 #if 0
56 KdPrint((__DRIVER_NAME " urb = %p\n", urb));
57 KdPrint((__DRIVER_NAME " Length = %d\n", urb->UrbHeader.Length));
58 KdPrint((__DRIVER_NAME " Function = %d\n", urb->UrbHeader.Function));
59 KdPrint((__DRIVER_NAME " Status = %d\n", urb->UrbHeader.Status));
60 KdPrint((__DRIVER_NAME " UsbdDeviceHandle = %p\n", urb->UrbHeader.UsbdDeviceHandle));
61 KdPrint((__DRIVER_NAME " UsbdFlags = %08x\n", urb->UrbHeader.UsbdFlags));
62 #endif
63 usb_device = urb->UrbHeader.UsbdDeviceHandle;
65 if (!usb_device)
66 usb_device = xupdd->usb_device;
68 decode_retval = XenUsb_DecodeControlUrb(urb, &decode_data);
69 if (decode_retval == URB_DECODE_UNKNOWN)
70 {
71 FUNCTION_MSG("Unknown URB - Calling WdfRequestCompletestatus with status = %08x\n", STATUS_UNSUCCESSFUL); //STATUS_UNSUCCESSFUL));
72 urb->UrbHeader.Status = USBD_STATUS_INVALID_URB_FUNCTION;
73 WdfRequestComplete(request, STATUS_UNSUCCESSFUL);
74 return;
75 }
77 urb->UrbHeader.Status = USBD_STATUS_INVALID_URB_FUNCTION;
79 if (decode_retval != URB_DECODE_NOT_CONTROL)
80 {
81 FUNCTION_MSG("bmRequestType = %02x\n", decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.B);
82 FUNCTION_MSG(" Recipient = %x\n", decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.Recipient);
83 FUNCTION_MSG(" Type = %x\n", decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.Type);
84 FUNCTION_MSG(" Dir = %x\n", decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.Dir);
85 FUNCTION_MSG("bRequest = %02x\n", decode_data.setup_packet.default_pipe_setup_packet.bRequest);
86 FUNCTION_MSG("wValue = %04x\n", decode_data.setup_packet.default_pipe_setup_packet.wValue.W);
87 FUNCTION_MSG(" Low = %02x\n", decode_data.setup_packet.default_pipe_setup_packet.wValue.LowByte);
88 FUNCTION_MSG(" High = %02x\n", decode_data.setup_packet.default_pipe_setup_packet.wValue.HiByte);
89 FUNCTION_MSG("wIndex = %04x\n", decode_data.setup_packet.default_pipe_setup_packet.wIndex);
90 FUNCTION_MSG(" Low = %02x\n", decode_data.setup_packet.default_pipe_setup_packet.wIndex.LowByte);
91 FUNCTION_MSG(" High = %02x\n", decode_data.setup_packet.default_pipe_setup_packet.wIndex.HiByte);
92 FUNCTION_MSG("wLength = %04x\n", decode_data.setup_packet.default_pipe_setup_packet.wLength);
93 }
95 switch(urb->UrbHeader.Function)
96 {
97 case URB_FUNCTION_SELECT_CONFIGURATION:
98 KdPrint((__DRIVER_NAME " URB_FUNCTION_SELECT_CONFIGURATION\n"));
99 KdPrint((__DRIVER_NAME " ConfigurationDescriptor = %p\n", urb->UrbSelectConfiguration.ConfigurationDescriptor));
100 if (urb->UrbSelectConfiguration.ConfigurationDescriptor)
101 {
102 KdPrint((__DRIVER_NAME " bLength = %d\n", urb->UrbSelectConfiguration.ConfigurationDescriptor->bLength));
103 KdPrint((__DRIVER_NAME " bDescriptorType = %d\n", urb->UrbSelectConfiguration.ConfigurationDescriptor->bDescriptorType));
104 KdPrint((__DRIVER_NAME " wTotalLength = %d\n", urb->UrbSelectConfiguration.ConfigurationDescriptor->wTotalLength));
105 KdPrint((__DRIVER_NAME " bNumInterfaces = %d\n", urb->UrbSelectConfiguration.ConfigurationDescriptor->bNumInterfaces));
106 KdPrint((__DRIVER_NAME " bConfigurationValue = %d\n", urb->UrbSelectConfiguration.ConfigurationDescriptor->bConfigurationValue));
107 KdPrint((__DRIVER_NAME " iConfiguration = %d\n", urb->UrbSelectConfiguration.ConfigurationDescriptor->iConfiguration));
108 KdPrint((__DRIVER_NAME " bmAttributes = %04x\n", urb->UrbSelectConfiguration.ConfigurationDescriptor->bmAttributes));
109 KdPrint((__DRIVER_NAME " MaxPower = %d\n", urb->UrbSelectConfiguration.ConfigurationDescriptor->MaxPower));
110 }
111 KdPrint((__DRIVER_NAME " ConfigurationHandle = %p\n", urb->UrbSelectConfiguration.ConfigurationHandle));
112 if (urb->UrbSelectConfiguration.ConfigurationDescriptor)
113 {
114 urb->UrbSelectConfiguration.ConfigurationHandle = xupdd->usb_device->configs[0];
115 interface_information = &urb->UrbSelectConfiguration.Interface;
116 for (i = 0; i < urb->UrbSelectConfiguration.ConfigurationDescriptor->bNumInterfaces; i++)
117 {
118 KdPrint((__DRIVER_NAME " InterfaceInformation[%d]\n", i));
119 KdPrint((__DRIVER_NAME " Length = %d\n", interface_information->Length));
120 KdPrint((__DRIVER_NAME " InterfaceNumber = %d\n", interface_information->InterfaceNumber));
121 KdPrint((__DRIVER_NAME " AlternateSetting = %d\n", interface_information->AlternateSetting));
122 KdPrint((__DRIVER_NAME " Class = %02x\n", (ULONG)interface_information->Class));
123 KdPrint((__DRIVER_NAME " SubClass = %02x\n", (ULONG)interface_information->SubClass));
124 KdPrint((__DRIVER_NAME " Protocol = %02x\n", (ULONG)interface_information->Protocol));
125 KdPrint((__DRIVER_NAME " Reserved = %02x\n", (ULONG)interface_information->Reserved));
126 KdPrint((__DRIVER_NAME " InterfaceHandle = %p\n", interface_information->InterfaceHandle));
127 KdPrint((__DRIVER_NAME " NumberOfPipes = %d\n", interface_information->NumberOfPipes));
128 interface_information->InterfaceHandle = xupdd->usb_device->configs[0]->interfaces[0];
129 interface_information->Class = 0x09;
130 interface_information->SubClass = 0x00;
131 interface_information->SubClass = 0x00;
132 for (j = 0; j < interface_information->NumberOfPipes; j++)
133 {
134 KdPrint((__DRIVER_NAME " Pipe[%d]\n", i));
135 KdPrint((__DRIVER_NAME " MaximumPacketSize = %d\n", interface_information->Pipes[j].MaximumPacketSize));
136 KdPrint((__DRIVER_NAME " EndpointAddress = %d\n", interface_information->Pipes[j].EndpointAddress));
137 KdPrint((__DRIVER_NAME " Interval = %d\n", interface_information->Pipes[j].Interval));
138 KdPrint((__DRIVER_NAME " PipeType = %d\n", interface_information->Pipes[j].PipeType));
139 KdPrint((__DRIVER_NAME " PipeHandle = %d\n", interface_information->Pipes[j].PipeHandle));
140 KdPrint((__DRIVER_NAME " MaximumTransferSize = %d\n", interface_information->Pipes[j].MaximumTransferSize));
141 KdPrint((__DRIVER_NAME " PipeFlags = %08x\n", interface_information->Pipes[j].PipeFlags));
142 interface_information->Pipes[j].MaximumPacketSize = 2;
143 interface_information->Pipes[j].EndpointAddress = 0x81;
144 interface_information->Pipes[j].Interval = 12;
145 interface_information->Pipes[j].PipeType = UsbdPipeTypeInterrupt;
146 interface_information->Pipes[j].PipeHandle = xupdd->usb_device->configs[0]->interfaces[0]->endpoints[j];
147 interface_information->Pipes[j].MaximumTransferSize = 4096; /* made up number - possibly not used */
148 // this is input actually interface_information->Pipes[j].PipeFlags = 0;
149 }
150 interface_information = (PUSBD_INTERFACE_INFORMATION)((PUCHAR)interface_information + interface_information->Length);
151 }
152 }
153 urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
154 break;
155 case URB_FUNCTION_SELECT_INTERFACE:
156 KdPrint((__DRIVER_NAME " URB_FUNCTION_SELECT_INTERFACE\n"));
157 interface_information = &urb->UrbSelectInterface.Interface;
158 KdPrint((__DRIVER_NAME " InterfaceInformation\n"));
159 KdPrint((__DRIVER_NAME " Length = %d\n", interface_information->Length));
160 KdPrint((__DRIVER_NAME " InterfaceNumber = %d\n", interface_information->InterfaceNumber));
161 KdPrint((__DRIVER_NAME " AlternateSetting = %d\n", interface_information->AlternateSetting));
162 KdPrint((__DRIVER_NAME " Class = %02x\n", (ULONG)interface_information->Class));
163 KdPrint((__DRIVER_NAME " SubClass = %02x\n", (ULONG)interface_information->SubClass));
164 KdPrint((__DRIVER_NAME " Protocol = %02x\n", (ULONG)interface_information->Protocol));
165 KdPrint((__DRIVER_NAME " Reserved = %02x\n", (ULONG)interface_information->Reserved));
166 KdPrint((__DRIVER_NAME " InterfaceHandle = %p\n", interface_information->InterfaceHandle));
167 KdPrint((__DRIVER_NAME " NumberOfPipes = %d\n", interface_information->NumberOfPipes));
168 for (i = 0; i < interface_information->NumberOfPipes; i++)
169 {
170 KdPrint((__DRIVER_NAME " Pipe[%d]\n", i));
171 KdPrint((__DRIVER_NAME " MaximumPacketSize = %d\n", interface_information->Pipes[i].MaximumPacketSize));
172 KdPrint((__DRIVER_NAME " EndpointAddress = %d\n", interface_information->Pipes[i].EndpointAddress));
173 KdPrint((__DRIVER_NAME " Interval = %d\n", interface_information->Pipes[i].Interval));
174 KdPrint((__DRIVER_NAME " PipeType = %d\n", interface_information->Pipes[i].PipeType));
175 KdPrint((__DRIVER_NAME " PipeHandle = %d\n", interface_information->Pipes[i].PipeHandle));
176 KdPrint((__DRIVER_NAME " MaximumTransferSize = %d\n", interface_information->Pipes[i].MaximumTransferSize));
177 KdPrint((__DRIVER_NAME " PipeFlags = %08x\n", interface_information->Pipes[i].PipeFlags));
178 }
179 urb->UrbHeader.Status = USBD_STATUS_INVALID_URB_FUNCTION;
180 break;
181 #if (NTDDI_VERSION >= NTDDI_VISTA)
182 case URB_FUNCTION_CONTROL_TRANSFER_EX:
183 #endif
184 case URB_FUNCTION_CONTROL_TRANSFER:
185 case URB_FUNCTION_CLASS_DEVICE:
186 case URB_FUNCTION_CLASS_OTHER:
187 case URB_FUNCTION_CLASS_INTERFACE:
188 case URB_FUNCTION_GET_DESCRIPTOR_FROM_DEVICE:
189 case URB_FUNCTION_GET_DESCRIPTOR_FROM_INTERFACE:
190 case URB_FUNCTION_GET_STATUS_FROM_DEVICE:
191 switch(decode_data.setup_packet.default_pipe_setup_packet.bRequest)
192 {
193 case USB_REQUEST_GET_STATUS:
194 // switch device, interface, endpoint
195 switch (decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.Type)
196 {
197 case BMREQUEST_STANDARD:
198 FUNCTION_MSG(" USB_REQUEST_GET_STATUS\n");
199 FUNCTION_MSG(" Type=Standard\n");
200 switch (decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.Recipient)
201 {
202 case BMREQUEST_TO_DEVICE:
203 KdPrint((__DRIVER_NAME " Recipient=Device\n"));
204 ((PUSHORT)decode_data.buffer)[0] = 0x0001; /* self powered */
205 urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
206 break;
207 default:
208 FUNCTION_MSG(" Recipient=%d\n", decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.Recipient);
209 break;
210 }
211 break;
212 case BMREQUEST_CLASS:
213 switch (decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.Recipient)
214 {
215 case BMREQUEST_TO_DEVICE:
216 ((PUSHORT)decode_data.buffer)[0] = 0x0000;
217 ((PUSHORT)decode_data.buffer)[1] = 0x0000;
218 urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
219 break;
220 case BMREQUEST_TO_OTHER:
221 FUNCTION_MSG(" USB_REQUEST_GET_STATUS\n");
222 FUNCTION_MSG(" Type=Class\n");
223 KdPrint((__DRIVER_NAME " Recipient=Other (port = %d)\n", decode_data.setup_packet.default_pipe_setup_packet.wIndex.LowByte));
224 ((PUSHORT)decode_data.buffer)[0] = xudd->ports[decode_data.setup_packet.default_pipe_setup_packet.wIndex.LowByte - 1].port_status;
225 ((PUSHORT)decode_data.buffer)[1] = xudd->ports[decode_data.setup_packet.default_pipe_setup_packet.wIndex.LowByte - 1].port_change;
226 urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
227 FUNCTION_MSG(" status = %04x, change = %04x\n",
228 xudd->ports[decode_data.setup_packet.default_pipe_setup_packet.wIndex.LowByte - 1].port_status,
229 xudd->ports[decode_data.setup_packet.default_pipe_setup_packet.wIndex.LowByte - 1].port_change);
230 break;
231 default:
232 FUNCTION_MSG(" USB_REQUEST_GET_STATUS\n");
233 FUNCTION_MSG(" Type=Class\n");
234 FUNCTION_MSG(" Recipient=%d\n", decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.Recipient);
235 break;
236 }
237 break;
238 default:
239 FUNCTION_MSG(" USB_REQUEST_GET_STATUS\n");
240 FUNCTION_MSG(" Type=%d\n", decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.Type);
241 break;
242 }
243 break;
244 case USB_REQUEST_GET_DESCRIPTOR:
245 FUNCTION_MSG(" USB_REQUEST_GET_DESCRIPTOR\n");
246 // should separate into Standard and Class
247 switch (decode_data.setup_packet.default_pipe_setup_packet.wValue.HiByte)
248 {
249 case USB_DEVICE_DESCRIPTOR_TYPE:
250 FUNCTION_MSG(" USB_DEVICE_DESCRIPTOR_TYPE\n");
251 FUNCTION_MSG(" length = %d\n", *decode_data.length);
252 memcpy(decode_data.buffer, &usb_device->device_descriptor, sizeof(USB_DEVICE_DESCRIPTOR));
253 *decode_data.length = sizeof(USB_DEVICE_DESCRIPTOR);
254 urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
255 break;
256 case USB_CONFIGURATION_DESCRIPTOR_TYPE:
257 {
258 xenusb_config_t *usb_config;
259 PUCHAR ptr;
261 FUNCTION_MSG(" USB_CONFIGURATION_DESCRIPTOR_TYPE\n");
262 FUNCTION_MSG(" length = %d\n", *decode_data.length);
263 usb_config = usb_device->active_config;
264 ptr = (PUCHAR)decode_data.buffer;
265 memcpy(ptr, &usb_config->config_descriptor, sizeof(USB_CONFIGURATION_DESCRIPTOR));
266 ptr += sizeof(USB_CONFIGURATION_DESCRIPTOR);
267 ((PUSB_CONFIGURATION_DESCRIPTOR)decode_data.buffer)->wTotalLength = sizeof(USB_CONFIGURATION_DESCRIPTOR);
268 if (*decode_data.length > 9)
269 {
270 for (i = 0; i < usb_config->config_descriptor.bNumInterfaces; i++)
271 {
272 memcpy(ptr, &usb_config->interfaces[i]->interface_descriptor, sizeof(USB_INTERFACE_DESCRIPTOR));
273 ptr += sizeof(USB_INTERFACE_DESCRIPTOR);
274 ((PUSB_CONFIGURATION_DESCRIPTOR)decode_data.buffer)->wTotalLength += sizeof(USB_INTERFACE_DESCRIPTOR);
275 for (j = 0; j < usb_config->interfaces[i]->interface_descriptor.bNumEndpoints; j++)
276 {
277 memcpy(ptr, &usb_config->interfaces[i]->endpoints[j]->endpoint_descriptor, sizeof(USB_ENDPOINT_DESCRIPTOR));
278 ptr += sizeof(USB_ENDPOINT_DESCRIPTOR);
279 ((PUSB_CONFIGURATION_DESCRIPTOR)decode_data.buffer)->wTotalLength += sizeof(USB_ENDPOINT_DESCRIPTOR);
280 }
281 }
282 }
283 *decode_data.length = ((PUSB_CONFIGURATION_DESCRIPTOR)decode_data.buffer)->wTotalLength;
284 //if (urb->UrbControlDescriptorRequest.TransferBufferLength == 9)
285 // ((PUSB_CONFIGURATION_DESCRIPTOR)decode_data.buffer)->wTotalLength = 32;
286 urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
287 break;
288 }
289 case 0x00: // unknown... doing the same as 0x29 seems to work
290 FUNCTION_MSG(" USB_00_DESCRIPTOR_TYPE (doesn't exist)\n");
291 urb->UrbHeader.Status = USBD_STATUS_BAD_DESCRIPTOR;
292 break;
293 case 0x29: // Hub Descriptor
294 {
295 PUSB_HUB_DESCRIPTOR uhd;
297 FUNCTION_MSG(" USB_HUB_DESCRIPTOR_TYPE\n", decode_data.setup_packet.default_pipe_setup_packet.wValue.HiByte);
298 FUNCTION_MSG(" length = %d\n", *decode_data.length);
299 uhd = decode_data.buffer;
300 // TODO adjust for real number of ports
301 *decode_data.length = FIELD_OFFSET(USB_HUB_DESCRIPTOR, bRemoveAndPowerMask[0]) + 2 + 1;
302 uhd->bDescriptorLength = (UCHAR)*decode_data.length;
303 uhd->bDescriptorType = 0x29;
304 uhd->bNumberOfPorts = (UCHAR)xudd->num_ports;
305 uhd->wHubCharacteristics = 0x0012; // no power switching no overcurrent protection
306 uhd->bPowerOnToPowerGood = 1; // 2ms units
307 uhd->bHubControlCurrent = 0;
308 // DeviceRemovable bits (includes an extra bit at the start)
309 uhd->bRemoveAndPowerMask[0] = 0;
310 uhd->bRemoveAndPowerMask[1] = 0;
311 // PortPwrCtrlMask
312 uhd->bRemoveAndPowerMask[2] = 0xFF;
313 urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
314 break;
315 }
316 default:
317 FUNCTION_MSG(" USB_%02x_DESCRIPTOR_TYPE\n", (ULONG)decode_data.setup_packet.default_pipe_setup_packet.wValue.HiByte);
318 FUNCTION_MSG("bmRequestType = %02x\n", decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.B);
319 FUNCTION_MSG(" Recipient = %x\n", decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.Recipient);
320 FUNCTION_MSG(" Type = %x\n", decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.Type);
321 FUNCTION_MSG(" Dir = %x\n", decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.Dir);
322 FUNCTION_MSG("bRequest = %02x\n", decode_data.setup_packet.default_pipe_setup_packet.bRequest);
323 FUNCTION_MSG("wValue = %04x\n", decode_data.setup_packet.default_pipe_setup_packet.wValue.W);
324 FUNCTION_MSG(" Low = %02x\n", decode_data.setup_packet.default_pipe_setup_packet.wValue.LowByte);
325 FUNCTION_MSG(" High = %02x\n", decode_data.setup_packet.default_pipe_setup_packet.wValue.HiByte);
326 FUNCTION_MSG("wIndex = %04x\n", decode_data.setup_packet.default_pipe_setup_packet.wIndex);
327 FUNCTION_MSG(" Low = %02x\n", decode_data.setup_packet.default_pipe_setup_packet.wIndex.LowByte);
328 FUNCTION_MSG(" High = %02x\n", decode_data.setup_packet.default_pipe_setup_packet.wIndex.HiByte);
329 FUNCTION_MSG("wLength = %04x\n", decode_data.setup_packet.default_pipe_setup_packet.wLength);
330 break;
331 }
332 break;
333 case USB_REQUEST_CLEAR_FEATURE:
334 FUNCTION_MSG(" USB_REQUEST_CLEAR_FEATURE\n");
335 switch (decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.Type)
336 {
337 case BMREQUEST_STANDARD: /* Standard */
338 KdPrint((__DRIVER_NAME " Type=Standard\n"));
339 switch (decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.Recipient)
340 {
341 case BMREQUEST_TO_DEVICE:
342 KdPrint((__DRIVER_NAME " Recipient=Device\n"));
343 switch (decode_data.setup_packet.default_pipe_setup_packet.wValue.W)
344 {
345 case 1: /* DEVICE_REMOTE_WAKEUP */
346 KdPrint((__DRIVER_NAME " Feature=DEVICE_REMOTE_WAKEUP\n"));
347 /* fake this */
348 urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
349 break;
350 default:
351 FUNCTION_MSG(__DRIVER_NAME " Feature=%d (not valid)\n", decode_data.setup_packet.default_pipe_setup_packet.wValue.W);
352 break;
353 }
354 break;
355 default:
356 FUNCTION_MSG(__DRIVER_NAME " Recipient=%d (not valid)\n", decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.Recipient);
357 break;
358 }
359 break;
360 break;
361 case BMREQUEST_CLASS: /* Class */
362 KdPrint((__DRIVER_NAME " Type=Class\n"));
363 switch (decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.Recipient)
364 {
365 case BMREQUEST_TO_OTHER:
366 KdPrint((__DRIVER_NAME " Recipient=Other (port = %d)\n", decode_data.setup_packet.default_pipe_setup_packet.wIndex.LowByte));
367 switch (urb->UrbControlVendorClassRequest.Value)
368 {
369 case PORT_ENABLE:
370 KdPrint((__DRIVER_NAME " PORT_ENABLE\n"));
371 xudd->ports[decode_data.setup_packet.default_pipe_setup_packet.wIndex.LowByte - 1].port_status &= ~(1 << PORT_ENABLE);
372 urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
373 break;
374 case PORT_SUSPEND:
375 KdPrint((__DRIVER_NAME " PORT_SUSPEND (NOOP)\n"));
376 /* do something here */
377 urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
378 break;
379 case C_PORT_CONNECTION:
380 KdPrint((__DRIVER_NAME " C_PORT_CONNECTION\n"));
381 xudd->ports[decode_data.setup_packet.default_pipe_setup_packet.wIndex.LowByte - 1].port_change &= ~(1 << PORT_CONNECTION);
382 urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
383 break;
384 case C_PORT_ENABLE:
385 KdPrint((__DRIVER_NAME " C_PORT_ENABLE\n"));
386 xudd->ports[decode_data.setup_packet.default_pipe_setup_packet.wIndex.LowByte - 1].port_change &= ~(1 << PORT_ENABLE);
387 urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
388 break;
389 case C_PORT_RESET:
390 KdPrint((__DRIVER_NAME " C_PORT_RESET\n"));
391 xudd->ports[decode_data.setup_packet.default_pipe_setup_packet.wIndex.LowByte - 1].port_change &= ~(1 << PORT_RESET);
392 urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
393 break;
394 default:
395 KdPrint((__DRIVER_NAME " Unknown Value %04X\n", urb->UrbControlVendorClassRequest.Value));
396 break;
397 }
398 KdPrint((__DRIVER_NAME " status = %04x, change = %04x\n",
399 xudd->ports[decode_data.setup_packet.default_pipe_setup_packet.wIndex.LowByte - 1].port_status,
400 xudd->ports[decode_data.setup_packet.default_pipe_setup_packet.wIndex.LowByte - 1].port_change));
401 break;
402 default:
403 FUNCTION_MSG(" Recipient=%d\n", decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.Recipient);
404 break;
405 }
406 break;
407 default:
408 KdPrint((__DRIVER_NAME " Type=%d\n", decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.Type));
409 break;
410 }
411 break;
412 case USB_REQUEST_SET_FEATURE:
413 KdPrint((__DRIVER_NAME " USB_REQUEST_SET_FEATURE\n"));
414 KdPrint((__DRIVER_NAME " SetPortFeature\n"));
415 switch (decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.Type)
416 {
417 case 0: /* Standard */
418 KdPrint((__DRIVER_NAME " Type=Standard\n"));
419 switch (decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.Recipient)
420 {
421 case BMREQUEST_TO_DEVICE:
422 KdPrint((__DRIVER_NAME " Recipient=Device\n"));
423 switch (decode_data.setup_packet.default_pipe_setup_packet.wValue.W)
424 {
425 case 1: /* DEVICE_REMOTE_WAKEUP */
426 KdPrint((__DRIVER_NAME " Feature=DEVICE_REMOTE_WAKEUP\n"));
427 /* fake this */
428 urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
429 break;
430 default:
431 FUNCTION_MSG(__DRIVER_NAME " Feature=%d (not valid)\n", decode_data.setup_packet.default_pipe_setup_packet.wValue.W);
432 break;
433 }
434 break;
435 default:
436 FUNCTION_MSG(__DRIVER_NAME " Recipient=%d (not valid)\n", decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.Recipient);
437 break;
438 }
439 break;
440 case 1: /* Class */
441 KdPrint((__DRIVER_NAME " Type=Class\n"));
442 switch (decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.Recipient)
443 {
444 case BMREQUEST_TO_OTHER:
445 KdPrint((__DRIVER_NAME " Recipient=Other (port = %d)\n", decode_data.setup_packet.default_pipe_setup_packet.wIndex.LowByte));
446 switch (decode_data.setup_packet.default_pipe_setup_packet.wValue.W)
447 {
448 case PORT_ENABLE:
449 KdPrint((__DRIVER_NAME " PORT_ENABLE (NOOP)\n"));
450 /* do something here */
451 urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
452 break;
453 case PORT_SUSPEND:
454 KdPrint((__DRIVER_NAME " PORT_SUSPEND (NOOP)\n"));
455 /* do something here */
456 urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
457 break;
458 case PORT_RESET:
459 KdPrint((__DRIVER_NAME " PORT_RESET\n"));
460 /* just fake the reset by setting the status bit to indicate that the reset is complete*/
461 //xudd->ports[decode_data.setup_packet.default_pipe_setup_packet.wIndex.LowByte - 1].port_status |= (1 << PORT_RESET);
462 //xudd->ports[decode_data.setup_packet.default_pipe_setup_packet.wIndex.LowByte - 1].reset_counter = 10;
463 // TODO: maybe fake a 10ms time here...
464 xudd->ports[decode_data.setup_packet.default_pipe_setup_packet.wIndex.LowByte - 1].port_status &= ~(1 << PORT_RESET);
465 xudd->ports[decode_data.setup_packet.default_pipe_setup_packet.wIndex.LowByte - 1].port_status |= (1 << PORT_ENABLE);
466 xudd->ports[decode_data.setup_packet.default_pipe_setup_packet.wIndex.LowByte - 1].port_change |= (1 << PORT_RESET);
467 urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
468 endpoint = xupdd->usb_device->configs[0]->interfaces[0]->endpoints[0];
469 XenUsbHub_ProcessHubInterruptEvent(endpoint);
470 break;
471 case PORT_POWER:
472 KdPrint((__DRIVER_NAME " PORT_POWER\n"));
473 xudd->ports[decode_data.setup_packet.default_pipe_setup_packet.wIndex.LowByte - 1].port_status |= (1 << PORT_POWER);
474 urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
475 break;
476 default:
477 KdPrint((__DRIVER_NAME " PORT_%04X\n", decode_data.setup_packet.default_pipe_setup_packet.wValue.W));
478 break;
479 }
480 KdPrint((__DRIVER_NAME " status = %04x, change = %04x\n",
481 xudd->ports[urb->UrbControlVendorClassRequest.Index - 1].port_status,
482 xudd->ports[urb->UrbControlVendorClassRequest.Index - 1].port_change));
483 break;
484 default:
485 FUNCTION_MSG(__DRIVER_NAME " Recipient=%d (not valid)\n", decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.Recipient);
486 break;
487 }
488 break;
489 }
490 break;
491 default:
492 FUNCTION_MSG(" USB_REQUEST_%02x\n", (ULONG)decode_data.setup_packet.default_pipe_setup_packet.bRequest);
493 KdPrint((__DRIVER_NAME " TransferBufferLength returned = %d\n", urb->UrbControlDescriptorRequest.TransferBufferLength));
494 break;
495 }
496 break;
497 case URB_FUNCTION_SYNC_RESET_PIPE_AND_CLEAR_STALL:
498 KdPrint((__DRIVER_NAME " URB_FUNCTION_SYNC_RESET_PIPE_AND_CLEAR_STALL\n"));
499 KdPrint((__DRIVER_NAME " PipeHandle = %p\n", urb->UrbPipeRequest.PipeHandle));
500 urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
501 break;
502 case URB_FUNCTION_ABORT_PIPE:
503 KdPrint((__DRIVER_NAME " URB_FUNCTION_ABORT_PIPE\n"));
504 KdPrint((__DRIVER_NAME " PipeHandle = %p\n", urb->UrbPipeRequest.PipeHandle));
505 urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
506 break;
507 case URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER: /* 11.12.4 */
508 #if 0
509 KdPrint((__DRIVER_NAME " URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER\n"));
510 KdPrint((__DRIVER_NAME " PipeHandle = %p\n", urb->UrbBulkOrInterruptTransfer.PipeHandle));
511 KdPrint((__DRIVER_NAME " TransferFlags = %08x\n", urb->UrbBulkOrInterruptTransfer.TransferFlags));
512 KdPrint((__DRIVER_NAME " TransferBufferLength = %d\n", urb->UrbBulkOrInterruptTransfer.TransferBufferLength));
513 KdPrint((__DRIVER_NAME " TransferBuffer = %p\n", urb->UrbBulkOrInterruptTransfer.TransferBuffer));
514 KdPrint((__DRIVER_NAME " TransferBufferMdl = %p\n", urb->UrbBulkOrInterruptTransfer.TransferBufferMDL));
515 #endif
516 endpoint = urb->UrbBulkOrInterruptTransfer.PipeHandle;
517 //WdfSpinLockAcquire(endpoint->lock);
518 WdfRequestForwardToIoQueue(request, endpoint->queue);
519 XenUsbHub_ProcessHubInterruptEvent(endpoint);
520 //WdfSpinLockRelease(endpoint->lock);
521 //FUNCTION_EXIT();
522 return;
524 default:
525 FUNCTION_MSG("URB_FUNCTION_%04x\n", urb->UrbHeader.Function);
526 if (decode_retval != URB_DECODE_NOT_CONTROL)
527 {
528 FUNCTION_MSG("bmRequestType = %02x\n", decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.B);
529 FUNCTION_MSG(" Recipient = %x\n", decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.Recipient);
530 FUNCTION_MSG(" Type = %x\n", decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.Type);
531 FUNCTION_MSG(" Dir = %x\n", decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.Dir);
532 FUNCTION_MSG("bRequest = %02x\n", decode_data.setup_packet.default_pipe_setup_packet.bRequest);
533 FUNCTION_MSG("wValue = %04x\n", decode_data.setup_packet.default_pipe_setup_packet.wValue.W);
534 FUNCTION_MSG(" Low = %02x\n", decode_data.setup_packet.default_pipe_setup_packet.wValue.LowByte);
535 FUNCTION_MSG(" High = %02x\n", decode_data.setup_packet.default_pipe_setup_packet.wValue.HiByte);
536 FUNCTION_MSG("wIndex = %04x\n", decode_data.setup_packet.default_pipe_setup_packet.wIndex);
537 FUNCTION_MSG(" Low = %02x\n", decode_data.setup_packet.default_pipe_setup_packet.wIndex.LowByte);
538 FUNCTION_MSG(" High = %02x\n", decode_data.setup_packet.default_pipe_setup_packet.wIndex.HiByte);
539 FUNCTION_MSG("wLength = %04x\n", decode_data.setup_packet.default_pipe_setup_packet.wLength);
540 }
541 urb->UrbHeader.Status = USBD_STATUS_INVALID_URB_FUNCTION;
542 break;
543 }
544 if (urb->UrbHeader.Status == USBD_STATUS_SUCCESS)
545 {
546 //FUNCTION_MSG("Calling WdfRequestCompletestatus with status = %08x\n", STATUS_SUCCESS);
547 WdfRequestComplete(request, STATUS_SUCCESS);
548 }
549 else
550 {
551 FUNCTION_MSG("Calling WdfRequestCompletestatus with status = %08x\n", STATUS_UNSUCCESSFUL);
552 WdfRequestComplete(request, STATUS_UNSUCCESSFUL);
553 }
555 //FUNCTION_EXIT();
556 return;
557 }