win-pvdrivers

view xenusb/xenusb_devurb.c @ 965:63bdd096d8d1

Fix KeInitializeCrashDumpHeader - buffer was too small under newer systems
author James Harper <james.harper@bendigoit.com.au>
date Tue Jan 10 12:11:30 2012 +1100 (2012-01-10)
parents 19d7c9dd9f5c
children 1306945ecc59
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 #define EPROTO 71 /* Protocol error */
24 static VOID
25 XenUsb_UrbCallback(usbif_shadow_t *shadow)
26 {
27 WDFQUEUE queue;
28 WDFDEVICE device;
29 PXENUSB_DEVICE_DATA xudd;
30 //ULONG i;
32 FUNCTION_ENTER();
34 ASSERT(shadow->request);
35 queue = WdfRequestGetIoQueue(shadow->request);
36 ASSERT(queue);
37 device = WdfIoQueueGetDevice(queue);
38 ASSERT(device);
39 xudd = GetXudd(device);
41 switch (shadow->urb->UrbHeader.Function)
42 {
43 case URB_FUNCTION_GET_DESCRIPTOR_FROM_DEVICE:
44 KdPrint((__DRIVER_NAME " rsp id = %d\n", shadow->rsp.id));
45 KdPrint((__DRIVER_NAME " rsp start_frame = %d\n", shadow->rsp.start_frame));
46 KdPrint((__DRIVER_NAME " rsp status = %d\n", shadow->rsp.status));
47 KdPrint((__DRIVER_NAME " rsp actual_length = %d\n", shadow->rsp.actual_length));
48 KdPrint((__DRIVER_NAME " rsp error_count = %d\n", shadow->rsp.error_count));
49 KdPrint((__DRIVER_NAME " total_length = %d\n", shadow->total_length));
50 KdPrint((__DRIVER_NAME " URB_FUNCTION_GET_DESCRIPTOR_FROM_DEVICE\n"));
51 shadow->urb->UrbControlDescriptorRequest.TransferBufferLength = shadow->total_length;
52 break;
53 case URB_FUNCTION_GET_DESCRIPTOR_FROM_INTERFACE:
54 KdPrint((__DRIVER_NAME " rsp id = %d\n", shadow->rsp.id));
55 KdPrint((__DRIVER_NAME " rsp start_frame = %d\n", shadow->rsp.start_frame));
56 KdPrint((__DRIVER_NAME " rsp status = %d\n", shadow->rsp.status));
57 KdPrint((__DRIVER_NAME " rsp actual_length = %d\n", shadow->rsp.actual_length));
58 KdPrint((__DRIVER_NAME " rsp error_count = %d\n", shadow->rsp.error_count));
59 KdPrint((__DRIVER_NAME " total_length = %d\n", shadow->total_length));
60 KdPrint((__DRIVER_NAME " URB_FUNCTION_GET_DESCRIPTOR_FROM_INTERFACE\n"));
61 shadow->urb->UrbControlDescriptorRequest.TransferBufferLength = shadow->total_length;
62 break;
63 case URB_FUNCTION_SELECT_CONFIGURATION:
64 KdPrint((__DRIVER_NAME " rsp id = %d\n", shadow->rsp.id));
65 KdPrint((__DRIVER_NAME " rsp start_frame = %d\n", shadow->rsp.start_frame));
66 KdPrint((__DRIVER_NAME " rsp status = %d\n", shadow->rsp.status));
67 KdPrint((__DRIVER_NAME " rsp actual_length = %d\n", shadow->rsp.actual_length));
68 KdPrint((__DRIVER_NAME " rsp error_count = %d\n", shadow->rsp.error_count));
69 KdPrint((__DRIVER_NAME " total_length = %d\n", shadow->total_length));
70 KdPrint((__DRIVER_NAME " URB_FUNCTION_SELECT_CONFIGURATION\n"));
71 break;
72 case URB_FUNCTION_SELECT_INTERFACE:
73 KdPrint((__DRIVER_NAME " rsp id = %d\n", shadow->rsp.id));
74 KdPrint((__DRIVER_NAME " rsp start_frame = %d\n", shadow->rsp.start_frame));
75 KdPrint((__DRIVER_NAME " rsp status = %d\n", shadow->rsp.status));
76 KdPrint((__DRIVER_NAME " rsp actual_length = %d\n", shadow->rsp.actual_length));
77 KdPrint((__DRIVER_NAME " rsp error_count = %d\n", shadow->rsp.error_count));
78 KdPrint((__DRIVER_NAME " total_length = %d\n", shadow->total_length));
79 KdPrint((__DRIVER_NAME " URB_FUNCTION_SELECT_INTERFACE\n"));
80 break;
81 case URB_FUNCTION_CLASS_INTERFACE:
82 KdPrint((__DRIVER_NAME " rsp id = %d\n", shadow->rsp.id));
83 KdPrint((__DRIVER_NAME " rsp start_frame = %d\n", shadow->rsp.start_frame));
84 KdPrint((__DRIVER_NAME " rsp status = %d\n", shadow->rsp.status));
85 KdPrint((__DRIVER_NAME " rsp actual_length = %d\n", shadow->rsp.actual_length));
86 KdPrint((__DRIVER_NAME " rsp error_count = %d\n", shadow->rsp.error_count));
87 KdPrint((__DRIVER_NAME " total_length = %d\n", shadow->total_length));
88 KdPrint((__DRIVER_NAME " URB_FUNCTION_CLASS_INTERFACE\n"));
89 shadow->urb->UrbControlVendorClassRequest.TransferBufferLength = shadow->total_length;
90 break;
91 case URB_FUNCTION_CONTROL_TRANSFER:
92 case URB_FUNCTION_CONTROL_TRANSFER_EX:
93 KdPrint((__DRIVER_NAME " rsp id = %d\n", shadow->rsp.id));
94 KdPrint((__DRIVER_NAME " rsp start_frame = %d\n", shadow->rsp.start_frame));
95 KdPrint((__DRIVER_NAME " rsp status = %d\n", shadow->rsp.status));
96 KdPrint((__DRIVER_NAME " rsp actual_length = %d\n", shadow->rsp.actual_length));
97 KdPrint((__DRIVER_NAME " rsp error_count = %d\n", shadow->rsp.error_count));
98 KdPrint((__DRIVER_NAME " total_length = %d\n", shadow->total_length));
99 KdPrint((__DRIVER_NAME " URB_FUNCTION_CONTROL_TRANSFER (_EX)\n"));
100 shadow->urb->UrbControlTransfer.TransferBufferLength = shadow->total_length;
101 break;
102 case URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER:
103 // if (shadow->rsp.status)
104 {
105 KdPrint((__DRIVER_NAME " rsp id = %d\n", shadow->rsp.id));
106 KdPrint((__DRIVER_NAME " rsp start_frame = %d\n", shadow->rsp.start_frame));
107 KdPrint((__DRIVER_NAME " rsp status = %d\n", shadow->rsp.status));
108 KdPrint((__DRIVER_NAME " rsp actual_length = %d\n", shadow->rsp.actual_length));
109 KdPrint((__DRIVER_NAME " rsp error_count = %d\n", shadow->rsp.error_count));
110 KdPrint((__DRIVER_NAME " total_length = %d\n", shadow->total_length));
111 KdPrint((__DRIVER_NAME " URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER\n"));
112 }
113 shadow->urb->UrbBulkOrInterruptTransfer.TransferBufferLength = shadow->total_length;
114 break;
115 case URB_FUNCTION_SYNC_RESET_PIPE_AND_CLEAR_STALL:
116 KdPrint((__DRIVER_NAME " URB_FUNCTION_SYNC_RESET_PIPE_AND_CLEAR_STALL\n"));
117 break;
118 default:
119 KdPrint((__DRIVER_NAME " rsp id = %d\n", shadow->rsp.id));
120 KdPrint((__DRIVER_NAME " rsp start_frame = %d\n", shadow->rsp.start_frame));
121 KdPrint((__DRIVER_NAME " rsp status = %d\n", shadow->rsp.status));
122 KdPrint((__DRIVER_NAME " rsp actual_length = %d\n", shadow->rsp.actual_length));
123 KdPrint((__DRIVER_NAME " rsp error_count = %d\n", shadow->rsp.error_count));
124 KdPrint((__DRIVER_NAME " total_length = %d\n", shadow->total_length));
125 KdPrint((__DRIVER_NAME " Unknown function %x\n", shadow->urb->UrbHeader.Function));
126 break;
127 }
128 switch (shadow->rsp.status)
129 {
130 case 0:
131 shadow->urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
132 break;
133 case -EPROTO: /* ? */
134 shadow->urb->UrbHeader.Status = USBD_STATUS_CRC;
135 KdPrint((__DRIVER_NAME " rsp status = -EPROTO\n"));
136 break;
137 case -EPIPE: /* see linux code - EPIPE is when the HCD returned a stall */
138 shadow->urb->UrbHeader.Status = USBD_STATUS_STALL_PID;
139 KdPrint((__DRIVER_NAME " rsp status = -EPIPE (USBD_STATUS_STALL_PID)\n"));
140 break;
141 #if 0
142 case -EOVERFLOW:
143 shadow->urb->UrbHeader.Status USBD_STATUS_DATA_OVERRUN;
144 break;
145 case -EREMOTEIO:
146 shadow->urb->UrbHeader.Status USBD_STATUS_ERROR_SHORT_TRANSFER;
147 break;
148 #endif
149 default:
150 //shadow->urb->UrbHeader.Status = USBD_STATUS_ENDPOINT_HALTED;
151 shadow->urb->UrbHeader.Status = USBD_STATUS_INTERNAL_HC_ERROR;
152 KdPrint((__DRIVER_NAME " rsp status = %d\n", shadow->rsp.status));
153 break;
154 }
155 if (shadow->urb->UrbHeader.Status == USBD_STATUS_SUCCESS)
156 WdfRequestComplete(shadow->request, STATUS_SUCCESS);
157 else
158 WdfRequestComplete(shadow->request, STATUS_UNSUCCESSFUL);
159 put_shadow_on_freelist(xudd, shadow);
161 FUNCTION_EXIT();
162 }
164 VOID
165 XenUsb_EvtIoInternalDeviceControl_DEVICE_SUBMIT_URB(
166 WDFQUEUE queue,
167 WDFREQUEST request,
168 size_t output_buffer_length,
169 size_t input_buffer_length,
170 ULONG io_control_code)
171 {
172 NTSTATUS status;
173 WDFDEVICE device = WdfIoQueueGetDevice(queue);
174 PXENUSB_DEVICE_DATA xudd = GetXudd(device);
175 WDF_REQUEST_PARAMETERS wrp;
176 PURB urb;
177 usbif_shadow_t *shadow;
178 PUSB_DEFAULT_PIPE_SETUP_PACKET setup_packet;
179 //PMDL mdl;
180 PUSBD_INTERFACE_INFORMATION interface_information;
181 ULONG i, j;
182 xenusb_device_t *usb_device;
183 //PUSB_HUB_DESCRIPTOR uhd;
184 xenusb_endpoint_t *endpoint;
185 urb_decode_t decode_data;
186 ULONG decode_retval;
188 UNREFERENCED_PARAMETER(input_buffer_length);
189 UNREFERENCED_PARAMETER(output_buffer_length);
190 UNREFERENCED_PARAMETER(io_control_code);
192 FUNCTION_ENTER();
194 ASSERT(io_control_code == IOCTL_INTERNAL_USB_SUBMIT_URB);
196 status = STATUS_ACCESS_VIOLATION; //STATUS_UNSUCCESSFUL;
198 WDF_REQUEST_PARAMETERS_INIT(&wrp);
199 WdfRequestGetParameters(request, &wrp);
201 urb = (PURB)wrp.Parameters.Others.Arg1;
202 ASSERT(urb);
203 #if 0
204 KdPrint((__DRIVER_NAME " urb = %p\n", urb));
205 KdPrint((__DRIVER_NAME " Length = %d\n", urb->UrbHeader.Length));
206 KdPrint((__DRIVER_NAME " Function = %d\n", urb->UrbHeader.Function));
207 KdPrint((__DRIVER_NAME " Status = %d\n", urb->UrbHeader.Status));
208 KdPrint((__DRIVER_NAME " UsbdDeviceHandle = %p\n", urb->UrbHeader.UsbdDeviceHandle));
209 KdPrint((__DRIVER_NAME " UsbdFlags = %08x\n", urb->UrbHeader.UsbdFlags));
210 #endif
211 usb_device = urb->UrbHeader.UsbdDeviceHandle;
213 ASSERT(usb_device);
215 decode_retval = XenUsb_DecodeControlUrb(urb, &decode_data);
216 if (decode_retval == URB_DECODE_UNKNOWN)
217 {
218 FUNCTION_MSG("Calling WdfRequestCompletestatus with status = %08x\n", STATUS_UNSUCCESSFUL);
219 urb->UrbHeader.Status = USBD_STATUS_INVALID_URB_FUNCTION;
220 WdfRequestComplete(request, STATUS_UNSUCCESSFUL);
221 return;
222 }
224 #if 0
225 if (decode_retval != URB_DECODE_NOT_CONTROL)
226 {
227 FUNCTION_MSG("bmRequestType = %02x\n", decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.B);
228 FUNCTION_MSG(" Recipient = %x\n", decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.Recipient);
229 FUNCTION_MSG(" Type = %x\n", decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.Type);
230 FUNCTION_MSG(" Dir = %x\n", decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.Dir);
231 FUNCTION_MSG("bRequest = %02x\n", decode_data.setup_packet.default_pipe_setup_packet.bRequest);
232 FUNCTION_MSG("wValue = %04x\n", decode_data.setup_packet.default_pipe_setup_packet.wValue.W);
233 FUNCTION_MSG(" Low = %02x\n", decode_data.setup_packet.default_pipe_setup_packet.wValue.LowByte);
234 FUNCTION_MSG(" High = %02x\n", decode_data.setup_packet.default_pipe_setup_packet.wValue.HiByte);
235 FUNCTION_MSG("wIndex = %04x\n", decode_data.setup_packet.default_pipe_setup_packet.wIndex);
236 FUNCTION_MSG(" Low = %02x\n", decode_data.setup_packet.default_pipe_setup_packet.wIndex.LowByte);
237 FUNCTION_MSG(" High = %02x\n", decode_data.setup_packet.default_pipe_setup_packet.wIndex.HiByte);
238 FUNCTION_MSG("wLength = %04x\n", decode_data.setup_packet.default_pipe_setup_packet.wLength);
239 }
240 #endif
242 switch(urb->UrbHeader.Function)
243 {
244 case URB_FUNCTION_SELECT_CONFIGURATION:
245 KdPrint((__DRIVER_NAME " URB_FUNCTION_SELECT_CONFIGURATION\n"));
246 KdPrint((__DRIVER_NAME " ConfigurationDescriptor = %p\n", urb->UrbSelectConfiguration.ConfigurationDescriptor));
247 if (urb->UrbSelectConfiguration.ConfigurationDescriptor)
248 {
249 KdPrint((__DRIVER_NAME " bLength = %d\n", urb->UrbSelectConfiguration.ConfigurationDescriptor->bLength));
250 KdPrint((__DRIVER_NAME " bDescriptorType = %d\n", urb->UrbSelectConfiguration.ConfigurationDescriptor->bDescriptorType));
251 KdPrint((__DRIVER_NAME " wTotalLength = %d\n", urb->UrbSelectConfiguration.ConfigurationDescriptor->wTotalLength));
252 KdPrint((__DRIVER_NAME " bNumInterfaces = %d\n", urb->UrbSelectConfiguration.ConfigurationDescriptor->bNumInterfaces));
253 KdPrint((__DRIVER_NAME " bConfigurationValue = %d\n", urb->UrbSelectConfiguration.ConfigurationDescriptor->bConfigurationValue));
254 KdPrint((__DRIVER_NAME " iConfiguration = %d\n", urb->UrbSelectConfiguration.ConfigurationDescriptor->iConfiguration));
255 KdPrint((__DRIVER_NAME " bmAttributes = %04x\n", urb->UrbSelectConfiguration.ConfigurationDescriptor->bmAttributes));
256 KdPrint((__DRIVER_NAME " MaxPower = %d\n", urb->UrbSelectConfiguration.ConfigurationDescriptor->MaxPower));
257 }
258 if (urb->UrbSelectConfiguration.ConfigurationDescriptor)
259 {
260 xenusb_config_t *usb_config = NULL;
261 for (i = 0; i < usb_device->device_descriptor.bNumConfigurations; i++)
262 {
263 if (usb_device->configs[i]->config_descriptor.bConfigurationValue == urb->UrbSelectConfiguration.ConfigurationDescriptor->bConfigurationValue)
264 usb_config = usb_device->configs[i];
265 }
266 urb->UrbSelectConfiguration.ConfigurationHandle = usb_config;
267 interface_information = &urb->UrbSelectConfiguration.Interface;
268 /* configuration is fully populated */
269 for (i = 0; i < urb->UrbSelectConfiguration.ConfigurationDescriptor->bNumInterfaces; i++)
270 {
271 /* i think we need to pay attention to the alt setting here .. */
272 xenusb_interface_t *usb_interface = usb_config->interfaces[i];
273 interface_information->InterfaceNumber = usb_interface->interface_descriptor.bInterfaceNumber;
274 interface_information->AlternateSetting = usb_interface->interface_descriptor.bAlternateSetting;
275 interface_information->Class = usb_interface->interface_descriptor.bInterfaceClass;
276 interface_information->SubClass = usb_interface->interface_descriptor.bInterfaceSubClass;
277 interface_information->Protocol = usb_interface->interface_descriptor.bInterfaceProtocol;
278 interface_information->InterfaceHandle = usb_interface;
279 KdPrint((__DRIVER_NAME " InterfaceInformation[%d]\n", i));
280 KdPrint((__DRIVER_NAME " Length = %d\n", interface_information->Length));
281 KdPrint((__DRIVER_NAME " InterfaceNumber = %d\n", interface_information->InterfaceNumber));
282 KdPrint((__DRIVER_NAME " AlternateSetting = %d\n", interface_information->AlternateSetting));
283 KdPrint((__DRIVER_NAME " Class = %02x\n", (ULONG)interface_information->Class));
284 KdPrint((__DRIVER_NAME " SubClass = %02x\n", (ULONG)interface_information->SubClass));
285 KdPrint((__DRIVER_NAME " Protocol = %02x\n", (ULONG)interface_information->Protocol));
286 KdPrint((__DRIVER_NAME " InterfaceHandle = %p\n", interface_information->InterfaceHandle));
287 KdPrint((__DRIVER_NAME " NumberOfPipes = %d\n", interface_information->NumberOfPipes));
288 for (j = 0; j < interface_information->NumberOfPipes; j++)
289 {
290 xenusb_endpoint_t *usb_endpoint = usb_interface->endpoints[j];
291 KdPrint((__DRIVER_NAME " Pipe[%d] (before)\n", j));
292 KdPrint((__DRIVER_NAME " MaximumPacketSize = %d\n", interface_information->Pipes[j].MaximumPacketSize));
293 KdPrint((__DRIVER_NAME " EndpointAddress = %d\n", interface_information->Pipes[j].EndpointAddress));
294 KdPrint((__DRIVER_NAME " Interval = %d\n", interface_information->Pipes[j].Interval));
295 KdPrint((__DRIVER_NAME " PipeType = %d\n", interface_information->Pipes[j].PipeType));
296 KdPrint((__DRIVER_NAME " PipeHandle = %p\n", interface_information->Pipes[j].PipeHandle));
297 KdPrint((__DRIVER_NAME " MaximumTransferSize = %d\n", interface_information->Pipes[j].MaximumTransferSize));
298 KdPrint((__DRIVER_NAME " PipeFlags = %08x\n", interface_information->Pipes[j].PipeFlags));
299 interface_information->Pipes[j].MaximumPacketSize = usb_endpoint->endpoint_descriptor.wMaxPacketSize;
300 interface_information->Pipes[j].EndpointAddress = usb_endpoint->endpoint_descriptor.bEndpointAddress;
301 interface_information->Pipes[j].Interval = usb_endpoint->endpoint_descriptor.bInterval;
302 switch (usb_endpoint->endpoint_descriptor.bmAttributes & USB_ENDPOINT_TYPE_MASK)
303 {
304 case USB_ENDPOINT_TYPE_CONTROL:
305 FUNCTION_MSG("USB_ENDPOINT_TYPE_CONTROL");
306 interface_information->Pipes[j].PipeType = UsbdPipeTypeControl;
307 break;
308 case USB_ENDPOINT_TYPE_ISOCHRONOUS:
309 FUNCTION_MSG("USB_ENDPOINT_TYPE_ISOCHRONOUS");
310 interface_information->Pipes[j].PipeType = UsbdPipeTypeIsochronous;
311 break;
312 case USB_ENDPOINT_TYPE_BULK:
313 FUNCTION_MSG("USB_ENDPOINT_TYPE_BULK");
314 interface_information->Pipes[j].PipeType = UsbdPipeTypeBulk;
315 break;
316 case USB_ENDPOINT_TYPE_INTERRUPT:
317 FUNCTION_MSG("USB_ENDPOINT_TYPE_INTERRUPT");
318 interface_information->Pipes[j].PipeType = UsbdPipeTypeInterrupt;
319 break;
320 }
321 interface_information->Pipes[j].PipeHandle = usb_endpoint;
322 KdPrint((__DRIVER_NAME " Pipe[%d] (after)\n", j));
323 KdPrint((__DRIVER_NAME " MaximumPacketSize = %d\n", interface_information->Pipes[j].MaximumPacketSize));
324 KdPrint((__DRIVER_NAME " EndpointAddress = %d\n", interface_information->Pipes[j].EndpointAddress));
325 KdPrint((__DRIVER_NAME " Interval = %d\n", interface_information->Pipes[j].Interval));
326 KdPrint((__DRIVER_NAME " PipeType = %d\n", interface_information->Pipes[j].PipeType));
327 KdPrint((__DRIVER_NAME " PipeHandle = %p\n", interface_information->Pipes[j].PipeHandle));
328 KdPrint((__DRIVER_NAME " MaximumTransferSize = %d\n", interface_information->Pipes[j].MaximumTransferSize));
329 KdPrint((__DRIVER_NAME " PipeFlags = %08x\n", interface_information->Pipes[j].PipeFlags));
330 }
331 interface_information = (PUSBD_INTERFACE_INFORMATION)((PUCHAR)interface_information + interface_information->Length);
332 }
333 }
334 else
335 {
336 // ? unconfigure device here
337 }
338 shadow = get_shadow_from_freelist(xudd);
339 shadow->request = request;
340 shadow->urb = urb;
341 shadow->mdl = NULL;
342 //shadow->dma_transaction = NULL;
343 shadow->callback = XenUsb_UrbCallback;
344 shadow->req.id = shadow->id;
345 shadow->req.pipe = LINUX_PIPE_TYPE_CTRL | (usb_device->address << 8) | usb_device->port_number;
346 shadow->req.transfer_flags = 0;
347 setup_packet = (PUSB_DEFAULT_PIPE_SETUP_PACKET)shadow->req.u.ctrl;
348 setup_packet->bmRequestType.Recipient = BMREQUEST_TO_DEVICE;
349 setup_packet->bmRequestType.Type = BMREQUEST_STANDARD;
350 setup_packet->bmRequestType.Dir = BMREQUEST_HOST_TO_DEVICE;
351 setup_packet->bRequest = USB_REQUEST_SET_CONFIGURATION;
352 setup_packet->wLength = 0;
353 setup_packet->wValue.W = urb->UrbSelectConfiguration.ConfigurationDescriptor->bConfigurationValue;
354 setup_packet->wIndex.W = 0;
355 status = XenUsb_ExecuteRequest(xudd, shadow, NULL, NULL, 0);
356 if (!NT_SUCCESS(status))
357 {
358 KdPrint((__DRIVER_NAME " XenUsb_ExecuteRequest status = %08x\n", status));
359 }
360 break;
361 case URB_FUNCTION_SELECT_INTERFACE:
362 KdPrint((__DRIVER_NAME " URB_FUNCTION_SELECT_INTERFACE\n"));
363 interface_information = &urb->UrbSelectInterface.Interface;
364 KdPrint((__DRIVER_NAME " InterfaceInformation\n"));
365 KdPrint((__DRIVER_NAME " Length = %d\n", interface_information->Length));
366 KdPrint((__DRIVER_NAME " InterfaceNumber = %d\n", interface_information->InterfaceNumber));
367 KdPrint((__DRIVER_NAME " AlternateSetting = %d\n", interface_information->AlternateSetting));
368 KdPrint((__DRIVER_NAME " Class = %02x\n", (ULONG)interface_information->Class));
369 KdPrint((__DRIVER_NAME " SubClass = %02x\n", (ULONG)interface_information->SubClass));
370 KdPrint((__DRIVER_NAME " Protocol = %02x\n", (ULONG)interface_information->Protocol));
371 KdPrint((__DRIVER_NAME " Reserved = %02x\n", (ULONG)interface_information->Reserved));
372 KdPrint((__DRIVER_NAME " InterfaceHandle = %p\n", interface_information->InterfaceHandle));
373 KdPrint((__DRIVER_NAME " NumberOfPipes = %d\n", interface_information->NumberOfPipes));
374 for (i = 0; i < interface_information->NumberOfPipes; i++)
375 {
376 KdPrint((__DRIVER_NAME " Pipe[%d]\n", i));
377 KdPrint((__DRIVER_NAME " MaximumPacketSize = %d\n", interface_information->Pipes[i].MaximumPacketSize));
378 KdPrint((__DRIVER_NAME " EndpointAddress = %d\n", interface_information->Pipes[i].EndpointAddress));
379 KdPrint((__DRIVER_NAME " Interval = %d\n", interface_information->Pipes[i].Interval));
380 KdPrint((__DRIVER_NAME " PipeType = %d\n", interface_information->Pipes[i].PipeType));
381 KdPrint((__DRIVER_NAME " PipeHandle = %p\n", interface_information->Pipes[i].PipeHandle));
382 KdPrint((__DRIVER_NAME " MaximumTransferSize = %d\n", interface_information->Pipes[i].MaximumTransferSize));
383 KdPrint((__DRIVER_NAME " PipeFlags = %08x\n", interface_information->Pipes[i].PipeFlags));
384 }
386 shadow = get_shadow_from_freelist(xudd);
387 shadow->request = request;
388 shadow->urb = urb;
389 shadow->mdl = NULL;
390 //shadow->dma_transaction = NULL;
391 shadow->callback = XenUsb_UrbCallback;
392 shadow->req.id = shadow->id;
393 shadow->req.pipe = LINUX_PIPE_TYPE_CTRL | (usb_device->address << 8) | usb_device->port_number;
394 shadow->req.transfer_flags = 0;
395 setup_packet = (PUSB_DEFAULT_PIPE_SETUP_PACKET)shadow->req.u.ctrl;
396 setup_packet->bmRequestType.Recipient = BMREQUEST_TO_INTERFACE;
397 setup_packet->bmRequestType.Type = BMREQUEST_STANDARD;
398 setup_packet->bmRequestType.Dir = BMREQUEST_HOST_TO_DEVICE;
399 setup_packet->bRequest = USB_REQUEST_SET_INTERFACE;
400 setup_packet->wLength = 0;
401 setup_packet->wValue.W = urb->UrbSelectInterface.Interface.AlternateSetting;
402 setup_packet->wIndex.W = urb->UrbSelectInterface.Interface.InterfaceNumber;
403 status = XenUsb_ExecuteRequest(xudd, shadow, NULL, NULL, 0);
404 if (!NT_SUCCESS(status))
405 {
406 KdPrint((__DRIVER_NAME " XenUsb_ExecuteRequest status = %08x\n", status));
407 }
408 break;
409 #if (NTDDI_VERSION >= NTDDI_VISTA)
410 case URB_FUNCTION_CONTROL_TRANSFER_EX:
411 #endif
412 case URB_FUNCTION_CONTROL_TRANSFER:
413 case URB_FUNCTION_CLASS_DEVICE:
414 case URB_FUNCTION_CLASS_INTERFACE:
415 case URB_FUNCTION_CLASS_OTHER:
416 case URB_FUNCTION_GET_DESCRIPTOR_FROM_DEVICE:
417 case URB_FUNCTION_GET_DESCRIPTOR_FROM_INTERFACE:
418 case URB_FUNCTION_GET_STATUS_FROM_DEVICE:
419 FUNCTION_MSG("URB_FUNCTION_%04x\n", urb->UrbHeader.Function);
420 FUNCTION_MSG("bmRequestType = %02x\n", decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.B);
421 FUNCTION_MSG(" Recipient = %x\n", decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.Recipient);
422 FUNCTION_MSG(" Type = %x\n", decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.Type);
423 FUNCTION_MSG(" Dir = %x\n", decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.Dir);
424 FUNCTION_MSG("bRequest = %02x\n", decode_data.setup_packet.default_pipe_setup_packet.bRequest);
425 FUNCTION_MSG("wValue = %04x\n", decode_data.setup_packet.default_pipe_setup_packet.wValue.W);
426 FUNCTION_MSG(" Low = %02x\n", decode_data.setup_packet.default_pipe_setup_packet.wValue.LowByte);
427 FUNCTION_MSG(" High = %02x\n", decode_data.setup_packet.default_pipe_setup_packet.wValue.HiByte);
428 FUNCTION_MSG("wIndex = %04x\n", decode_data.setup_packet.default_pipe_setup_packet.wIndex);
429 FUNCTION_MSG(" Low = %02x\n", decode_data.setup_packet.default_pipe_setup_packet.wIndex.LowByte);
430 FUNCTION_MSG(" High = %02x\n", decode_data.setup_packet.default_pipe_setup_packet.wIndex.HiByte);
431 FUNCTION_MSG("wLength = %04x\n", decode_data.setup_packet.default_pipe_setup_packet.wLength);
432 FUNCTION_MSG("decode_data.transfer_flags = %08x\n", decode_data.transfer_flags);
433 FUNCTION_MSG("*decode_data.length = %04x\n", *decode_data.length);
434 shadow = get_shadow_from_freelist(xudd);
435 shadow->request = request;
436 shadow->urb = urb;
437 shadow->callback = XenUsb_UrbCallback;
438 shadow->req.id = shadow->id;
439 shadow->req.pipe = LINUX_PIPE_TYPE_CTRL | (usb_device->address << 8) | usb_device->port_number;
440 shadow->req.transfer_flags = 0;
441 if (!(decode_data.transfer_flags & USBD_SHORT_TRANSFER_OK))
442 shadow->req.transfer_flags |= LINUX_URB_SHORT_NOT_OK;
443 if (decode_data.transfer_flags & (USBD_TRANSFER_DIRECTION_IN | USBD_SHORT_TRANSFER_OK))
444 shadow->req.pipe |= LINUX_PIPE_DIRECTION_IN;
445 else
446 shadow->req.pipe |= LINUX_PIPE_DIRECTION_OUT;
447 memcpy(shadow->req.u.ctrl, decode_data.setup_packet.raw, 8);
448 FUNCTION_MSG("req.pipe = %08x\n", shadow->req.pipe);
449 FUNCTION_MSG("req.transfer_flags = %08x\n", shadow->req.transfer_flags);
450 status = XenUsb_ExecuteRequest(xudd, shadow, decode_data.buffer, decode_data.mdl, *decode_data.length);
451 if (!NT_SUCCESS(status)) {
452 KdPrint((__DRIVER_NAME " XenUsb_ExecuteRequest status = %08x\n", status));
453 }
454 break;
455 case URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER: /* 11.12.4 */
456 endpoint = urb->UrbBulkOrInterruptTransfer.PipeHandle;
457 KdPrint((__DRIVER_NAME " pipe_handle = %p\n", endpoint));
458 KdPrint((__DRIVER_NAME " pipe_value = %08x\n", endpoint->pipe_value));
459 shadow = get_shadow_from_freelist(xudd);
460 KdPrint((__DRIVER_NAME " id = %d\n", shadow->id));
461 shadow->request = request;
462 shadow->urb = urb;
463 shadow->callback = XenUsb_UrbCallback;
464 shadow->req.id = shadow->id;
465 shadow->req.pipe = endpoint->pipe_value;
466 shadow->req.transfer_flags = 0;
467 shadow->req.u.intr.interval = endpoint->endpoint_descriptor.bInterval; /* check this... maybe there is some overridden value that should be used? */
468 if (!(urb->UrbBulkOrInterruptTransfer.TransferFlags & USBD_SHORT_TRANSFER_OK) && (endpoint->pipe_value & LINUX_PIPE_DIRECTION_IN))
469 shadow->req.transfer_flags |= LINUX_URB_SHORT_NOT_OK;
470 switch(endpoint->endpoint_descriptor.bmAttributes & USB_ENDPOINT_TYPE_MASK)
471 {
472 case USB_ENDPOINT_TYPE_BULK:
473 KdPrint((__DRIVER_NAME " USB_ENDPOINT_TYPE_BULK\n"));
474 break;
475 case USB_ENDPOINT_TYPE_INTERRUPT:
476 KdPrint((__DRIVER_NAME " USB_ENDPOINT_TYPE_INTERRUPT\n"));
477 break;
478 default:
479 KdPrint((__DRIVER_NAME " USB_ENDPOINT_TYPE_%d\n", endpoint->endpoint_descriptor.bmAttributes));
480 break;
481 }
483 FUNCTION_MSG("endpoint address = %02x\n", endpoint->endpoint_descriptor.bEndpointAddress);
484 FUNCTION_MSG("endpoint interval = %02x\n", endpoint->endpoint_descriptor.bInterval);
485 FUNCTION_MSG("pipe_direction_bit = %08x\n", endpoint->pipe_value & LINUX_PIPE_DIRECTION_IN);
486 FUNCTION_MSG("short_ok_bit = %08x\n", urb->UrbBulkOrInterruptTransfer.TransferFlags & USBD_SHORT_TRANSFER_OK);
487 FUNCTION_MSG("flags_direction_bit = %08x\n", urb->UrbBulkOrInterruptTransfer.TransferFlags & USBD_TRANSFER_DIRECTION_IN);
488 status = XenUsb_ExecuteRequest(xudd, shadow, urb->UrbBulkOrInterruptTransfer.TransferBuffer, urb->UrbBulkOrInterruptTransfer.TransferBufferMDL, urb->UrbBulkOrInterruptTransfer.TransferBufferLength);
489 if (!NT_SUCCESS(status))
490 {
491 KdPrint((__DRIVER_NAME " XenUsb_ExecuteRequest status = %08x\n", status));
492 }
493 break;
494 case URB_FUNCTION_SYNC_RESET_PIPE_AND_CLEAR_STALL:
495 KdPrint((__DRIVER_NAME " URB_FUNCTION_SYNC_RESET_PIPE_AND_CLEAR_STALL\n"));
496 KdPrint((__DRIVER_NAME " PipeHandle = %p\n", urb->UrbPipeRequest.PipeHandle));
497 /* we only clear the stall here */
498 endpoint = urb->UrbBulkOrInterruptTransfer.PipeHandle;
499 shadow = get_shadow_from_freelist(xudd);
500 shadow->request = request;
501 shadow->urb = urb;
502 shadow->mdl = NULL;
503 shadow->callback = XenUsb_UrbCallback;
504 shadow->req.id = shadow->id;
505 shadow->req.pipe = LINUX_PIPE_TYPE_CTRL | (usb_device->address << 8) | usb_device->port_number;
506 shadow->req.transfer_flags = 0;
507 setup_packet = (PUSB_DEFAULT_PIPE_SETUP_PACKET)shadow->req.u.ctrl;
508 setup_packet->bmRequestType.Recipient = BMREQUEST_TO_ENDPOINT;
509 setup_packet->bmRequestType.Type = BMREQUEST_STANDARD;
510 setup_packet->bmRequestType.Dir = BMREQUEST_HOST_TO_DEVICE;
511 setup_packet->bRequest = USB_REQUEST_CLEAR_FEATURE;
512 setup_packet->wLength = 0;
513 setup_packet->wValue.W = 0; /* 0 == ENDPOINT_HALT */
514 setup_packet->wIndex.W = endpoint->endpoint_descriptor.bEndpointAddress;
515 status = XenUsb_ExecuteRequest(xudd, shadow, NULL, NULL, 0);
516 if (!NT_SUCCESS(status))
517 {
518 KdPrint((__DRIVER_NAME " XenUsb_ExecuteRequest status = %08x\n", status));
519 }
520 break;
521 case URB_FUNCTION_ABORT_PIPE:
522 KdPrint((__DRIVER_NAME " URB_FUNCTION_ABORT_PIPE\n"));
523 KdPrint((__DRIVER_NAME " PipeHandle = %p\n", urb->UrbPipeRequest.PipeHandle));
524 /* just fake this.... i think we really need to flush any pending requests too */
525 urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
526 WdfRequestComplete(request, STATUS_SUCCESS);
527 break;
528 default:
529 KdPrint((__DRIVER_NAME " URB_FUNCTION_%04x\n", urb->UrbHeader.Function));
530 KdPrint((__DRIVER_NAME " Calling WdfRequestCompletestatus with status = %08x\n", status));
531 urb->UrbHeader.Status = USBD_STATUS_INVALID_URB_FUNCTION;
532 WdfRequestComplete(request, STATUS_ACCESS_VIOLATION); //STATUS_UNSUCCESSFUL);
533 break;
534 }
535 FUNCTION_EXIT();
536 }