win-pvdrivers

view xenusb/xenusb_devurb.c @ 840:c750a369bce5

Added tag 0.11.0.252 for changeset e48c6f765e5f
author James Harper <james.harper@bendigoit.com.au>
date Thu Feb 03 14:26:04 2011 +1100 (2011-02-03)
parents 7b5ccd2632d9
children 3aa213de2a31
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_BULK_OR_INTERRUPT_TRANSFER:
92 if (shadow->rsp.status)
93 {
94 KdPrint((__DRIVER_NAME " rsp id = %d\n", shadow->rsp.id));
95 KdPrint((__DRIVER_NAME " rsp start_frame = %d\n", shadow->rsp.start_frame));
96 KdPrint((__DRIVER_NAME " rsp status = %d\n", shadow->rsp.status));
97 KdPrint((__DRIVER_NAME " rsp actual_length = %d\n", shadow->rsp.actual_length));
98 KdPrint((__DRIVER_NAME " rsp error_count = %d\n", shadow->rsp.error_count));
99 KdPrint((__DRIVER_NAME " total_length = %d\n", shadow->total_length));
100 KdPrint((__DRIVER_NAME " URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER\n"));
101 }
102 shadow->urb->UrbBulkOrInterruptTransfer.TransferBufferLength = shadow->total_length;
103 break;
104 default:
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 " Unknown function %x\n", shadow->urb->UrbHeader.Function));
112 break;
113 }
114 switch (shadow->rsp.status)
115 {
116 case 0:
117 shadow->urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
118 break;
119 case -EPROTO: /* ? */
120 shadow->urb->UrbHeader.Status = USBD_STATUS_CRC;
121 KdPrint((__DRIVER_NAME " rsp status = -EPROTO\n"));
122 break;
123 #if 0
124 case -EPIPE:
125 shadow->urb->UrbHeader.Status USBD_STATUS_ENDPOINT_HALTED;
126 break;
127 case -EOVERFLOW:
128 shadow->urb->UrbHeader.Status USBD_STATUS_DATA_OVERRUN;
129 break;
130 case -EREMOTEIO:
131 shadow->urb->UrbHeader.Status USBD_STATUS_ERROR_SHORT_TRANSFER;
132 break;
133 #endif
134 default:
135 //shadow->urb->UrbHeader.Status = USBD_STATUS_ENDPOINT_HALTED;
136 shadow->urb->UrbHeader.Status = USBD_STATUS_INTERNAL_HC_ERROR;
137 KdPrint((__DRIVER_NAME " rsp status = %d\n", shadow->rsp.status));
138 break;
139 }
140 WdfRequestComplete(shadow->request, STATUS_SUCCESS);
141 put_shadow_on_freelist(xudd, shadow);
143 //FUNCTION_EXIT();
144 }
146 VOID
147 XenUsb_EvtIoInternalDeviceControl_DEVICE_SUBMIT_URB(
148 WDFQUEUE queue,
149 WDFREQUEST request,
150 size_t output_buffer_length,
151 size_t input_buffer_length,
152 ULONG io_control_code)
153 {
154 NTSTATUS status;
155 WDFDEVICE device = WdfIoQueueGetDevice(queue);
156 PXENUSB_DEVICE_DATA xudd = GetXudd(device);
157 WDF_REQUEST_PARAMETERS wrp;
158 PURB urb;
159 usbif_shadow_t *shadow;
160 PUSB_DEFAULT_PIPE_SETUP_PACKET setup_packet;
161 //PMDL mdl;
162 PUSBD_INTERFACE_INFORMATION interface_information;
163 ULONG i, j;
164 xenusb_device_t *usb_device;
165 //PUSB_HUB_DESCRIPTOR uhd;
166 xenusb_endpoint_t *endpoint;
168 UNREFERENCED_PARAMETER(input_buffer_length);
169 UNREFERENCED_PARAMETER(output_buffer_length);
170 UNREFERENCED_PARAMETER(io_control_code);
172 //FUNCTION_ENTER();
174 ASSERT(io_control_code == IOCTL_INTERNAL_USB_SUBMIT_URB);
176 status = STATUS_UNSUCCESSFUL;
178 WDF_REQUEST_PARAMETERS_INIT(&wrp);
179 WdfRequestGetParameters(request, &wrp);
181 urb = (PURB)wrp.Parameters.Others.Arg1;
182 ASSERT(urb);
183 #if 0
184 KdPrint((__DRIVER_NAME " urb = %p\n", urb));
185 KdPrint((__DRIVER_NAME " Length = %d\n", urb->UrbHeader.Length));
186 KdPrint((__DRIVER_NAME " Function = %d\n", urb->UrbHeader.Function));
187 KdPrint((__DRIVER_NAME " Status = %d\n", urb->UrbHeader.Status));
188 KdPrint((__DRIVER_NAME " UsbdDeviceHandle = %p\n", urb->UrbHeader.UsbdDeviceHandle));
189 KdPrint((__DRIVER_NAME " UsbdFlags = %08x\n", urb->UrbHeader.UsbdFlags));
190 #endif
191 usb_device = urb->UrbHeader.UsbdDeviceHandle;
193 ASSERT(usb_device);
195 switch(urb->UrbHeader.Function)
196 {
197 case URB_FUNCTION_SELECT_CONFIGURATION:
198 KdPrint((__DRIVER_NAME " URB_FUNCTION_SELECT_CONFIGURATION\n"));
199 KdPrint((__DRIVER_NAME " ConfigurationDescriptor = %p\n", urb->UrbSelectConfiguration.ConfigurationDescriptor));
200 if (urb->UrbSelectConfiguration.ConfigurationDescriptor)
201 {
202 KdPrint((__DRIVER_NAME " bLength = %d\n", urb->UrbSelectConfiguration.ConfigurationDescriptor->bLength));
203 KdPrint((__DRIVER_NAME " bDescriptorType = %d\n", urb->UrbSelectConfiguration.ConfigurationDescriptor->bDescriptorType));
204 KdPrint((__DRIVER_NAME " wTotalLength = %d\n", urb->UrbSelectConfiguration.ConfigurationDescriptor->wTotalLength));
205 KdPrint((__DRIVER_NAME " bNumInterfaces = %d\n", urb->UrbSelectConfiguration.ConfigurationDescriptor->bNumInterfaces));
206 KdPrint((__DRIVER_NAME " bConfigurationValue = %d\n", urb->UrbSelectConfiguration.ConfigurationDescriptor->bConfigurationValue));
207 KdPrint((__DRIVER_NAME " iConfiguration = %d\n", urb->UrbSelectConfiguration.ConfigurationDescriptor->iConfiguration));
208 KdPrint((__DRIVER_NAME " bmAttributes = %04x\n", urb->UrbSelectConfiguration.ConfigurationDescriptor->bmAttributes));
209 KdPrint((__DRIVER_NAME " MaxPower = %d\n", urb->UrbSelectConfiguration.ConfigurationDescriptor->MaxPower));
210 }
211 if (urb->UrbSelectConfiguration.ConfigurationDescriptor)
212 {
213 xenusb_config_t *usb_config = NULL;
214 for (i = 0; i < usb_device->device_descriptor.bNumConfigurations; i++)
215 {
216 if (usb_device->configs[i]->config_descriptor.bConfigurationValue == urb->UrbSelectConfiguration.ConfigurationDescriptor->bConfigurationValue)
217 usb_config = usb_device->configs[i];
218 }
219 urb->UrbSelectConfiguration.ConfigurationHandle = usb_config;
220 interface_information = &urb->UrbSelectConfiguration.Interface;
221 /* configuration is fully populated */
222 for (i = 0; i < urb->UrbSelectConfiguration.ConfigurationDescriptor->bNumInterfaces; i++)
223 {
224 /* i think we need to pay attention to the alt setting here .. */
225 xenusb_interface_t *usb_interface = usb_config->interfaces[i];
226 interface_information->InterfaceNumber = usb_interface->interface_descriptor.bInterfaceNumber;
227 interface_information->AlternateSetting = usb_interface->interface_descriptor.bAlternateSetting;
228 interface_information->Class = usb_interface->interface_descriptor.bInterfaceClass;
229 interface_information->SubClass = usb_interface->interface_descriptor.bInterfaceSubClass;
230 interface_information->Protocol = usb_interface->interface_descriptor.bInterfaceProtocol;
231 interface_information->InterfaceHandle = usb_interface;
232 KdPrint((__DRIVER_NAME " InterfaceInformation[%d]\n", i));
233 KdPrint((__DRIVER_NAME " Length = %d\n", interface_information->Length));
234 KdPrint((__DRIVER_NAME " InterfaceNumber = %d\n", interface_information->InterfaceNumber));
235 KdPrint((__DRIVER_NAME " AlternateSetting = %d\n", interface_information->AlternateSetting));
236 KdPrint((__DRIVER_NAME " Class = %02x\n", (ULONG)interface_information->Class));
237 KdPrint((__DRIVER_NAME " SubClass = %02x\n", (ULONG)interface_information->SubClass));
238 KdPrint((__DRIVER_NAME " Protocol = %02x\n", (ULONG)interface_information->Protocol));
239 KdPrint((__DRIVER_NAME " InterfaceHandle = %p\n", interface_information->InterfaceHandle));
240 KdPrint((__DRIVER_NAME " NumberOfPipes = %d\n", interface_information->NumberOfPipes));
241 for (j = 0; j < interface_information->NumberOfPipes; j++)
242 {
243 xenusb_endpoint_t *usb_endpoint = usb_interface->endpoints[j];
244 KdPrint((__DRIVER_NAME " Pipe[%d] (before)\n", j));
245 KdPrint((__DRIVER_NAME " MaximumPacketSize = %d\n", interface_information->Pipes[j].MaximumPacketSize));
246 KdPrint((__DRIVER_NAME " EndpointAddress = %d\n", interface_information->Pipes[j].EndpointAddress));
247 KdPrint((__DRIVER_NAME " Interval = %d\n", interface_information->Pipes[j].Interval));
248 KdPrint((__DRIVER_NAME " PipeType = %d\n", interface_information->Pipes[j].PipeType));
249 KdPrint((__DRIVER_NAME " PipeHandle = %p\n", interface_information->Pipes[j].PipeHandle));
250 KdPrint((__DRIVER_NAME " MaximumTransferSize = %d\n", interface_information->Pipes[j].MaximumTransferSize));
251 KdPrint((__DRIVER_NAME " PipeFlags = %08x\n", interface_information->Pipes[j].PipeFlags));
252 interface_information->Pipes[j].MaximumPacketSize = usb_endpoint->endpoint_descriptor.wMaxPacketSize;
253 interface_information->Pipes[j].EndpointAddress = usb_endpoint->endpoint_descriptor.bEndpointAddress;
254 interface_information->Pipes[j].Interval = usb_endpoint->endpoint_descriptor.bInterval;
255 switch (usb_endpoint->endpoint_descriptor.bmAttributes & USB_ENDPOINT_TYPE_MASK)
256 {
257 case USB_ENDPOINT_TYPE_CONTROL:
258 interface_information->Pipes[j].PipeType = UsbdPipeTypeControl;
259 break;
260 case USB_ENDPOINT_TYPE_ISOCHRONOUS:
261 interface_information->Pipes[j].PipeType = UsbdPipeTypeIsochronous;
262 break;
263 case USB_ENDPOINT_TYPE_BULK:
264 interface_information->Pipes[j].PipeType = UsbdPipeTypeBulk;
265 break;
266 case USB_ENDPOINT_TYPE_INTERRUPT:
267 interface_information->Pipes[j].PipeType = UsbdPipeTypeInterrupt;
268 break;
269 }
270 interface_information->Pipes[j].PipeHandle = usb_endpoint;
271 KdPrint((__DRIVER_NAME " Pipe[%d] (after)\n", j));
272 KdPrint((__DRIVER_NAME " MaximumPacketSize = %d\n", interface_information->Pipes[j].MaximumPacketSize));
273 KdPrint((__DRIVER_NAME " EndpointAddress = %d\n", interface_information->Pipes[j].EndpointAddress));
274 KdPrint((__DRIVER_NAME " Interval = %d\n", interface_information->Pipes[j].Interval));
275 KdPrint((__DRIVER_NAME " PipeType = %d\n", interface_information->Pipes[j].PipeType));
276 KdPrint((__DRIVER_NAME " PipeHandle = %p\n", interface_information->Pipes[j].PipeHandle));
277 KdPrint((__DRIVER_NAME " MaximumTransferSize = %d\n", interface_information->Pipes[j].MaximumTransferSize));
278 KdPrint((__DRIVER_NAME " PipeFlags = %08x\n", interface_information->Pipes[j].PipeFlags));
279 }
280 interface_information = (PUSBD_INTERFACE_INFORMATION)((PUCHAR)interface_information + interface_information->Length);
281 }
282 }
283 else
284 {
285 // ? unconfigure device here
286 }
287 shadow = get_shadow_from_freelist(xudd);
288 shadow->request = request;
289 shadow->urb = urb;
290 shadow->mdl = NULL;
291 shadow->dma_transaction = NULL;
292 shadow->callback = XenUsb_UrbCallback;
293 shadow->req.id = shadow->id;
294 shadow->req.pipe = LINUX_PIPE_TYPE_CTRL | (usb_device->address << 8) | usb_device->port_number;
295 shadow->req.transfer_flags = 0;
296 setup_packet = (PUSB_DEFAULT_PIPE_SETUP_PACKET)shadow->req.u.ctrl;
297 setup_packet->bmRequestType.Recipient = BMREQUEST_TO_DEVICE;
298 setup_packet->bmRequestType.Type = BMREQUEST_STANDARD;
299 setup_packet->bmRequestType.Dir = BMREQUEST_HOST_TO_DEVICE;
300 setup_packet->bRequest = USB_REQUEST_SET_CONFIGURATION;
301 setup_packet->wLength = 0;
302 setup_packet->wValue.W = urb->UrbSelectConfiguration.ConfigurationDescriptor->bConfigurationValue;
303 setup_packet->wIndex.W = 0;
304 status = XenUsb_ExecuteRequest(xudd, shadow, NULL, NULL, 0);
305 if (!NT_SUCCESS(status))
306 {
307 KdPrint((__DRIVER_NAME " XenUsb_ExecuteRequest status = %08x\n", status));
308 }
309 break;
310 case URB_FUNCTION_SELECT_INTERFACE:
311 KdPrint((__DRIVER_NAME " URB_FUNCTION_SELECT_INTERFACE\n"));
312 interface_information = &urb->UrbSelectInterface.Interface;
313 KdPrint((__DRIVER_NAME " InterfaceInformation\n"));
314 KdPrint((__DRIVER_NAME " Length = %d\n", interface_information->Length));
315 KdPrint((__DRIVER_NAME " InterfaceNumber = %d\n", interface_information->InterfaceNumber));
316 KdPrint((__DRIVER_NAME " AlternateSetting = %d\n", interface_information->AlternateSetting));
317 KdPrint((__DRIVER_NAME " Class = %02x\n", (ULONG)interface_information->Class));
318 KdPrint((__DRIVER_NAME " SubClass = %02x\n", (ULONG)interface_information->SubClass));
319 KdPrint((__DRIVER_NAME " Protocol = %02x\n", (ULONG)interface_information->Protocol));
320 KdPrint((__DRIVER_NAME " Reserved = %02x\n", (ULONG)interface_information->Reserved));
321 KdPrint((__DRIVER_NAME " InterfaceHandle = %p\n", interface_information->InterfaceHandle));
322 KdPrint((__DRIVER_NAME " NumberOfPipes = %d\n", interface_information->NumberOfPipes));
323 for (i = 0; i < interface_information->NumberOfPipes; i++)
324 {
325 KdPrint((__DRIVER_NAME " Pipe[%d]\n", i));
326 KdPrint((__DRIVER_NAME " MaximumPacketSize = %d\n", interface_information->Pipes[i].MaximumPacketSize));
327 KdPrint((__DRIVER_NAME " EndpointAddress = %d\n", interface_information->Pipes[i].EndpointAddress));
328 KdPrint((__DRIVER_NAME " Interval = %d\n", interface_information->Pipes[i].Interval));
329 KdPrint((__DRIVER_NAME " PipeType = %d\n", interface_information->Pipes[i].PipeType));
330 KdPrint((__DRIVER_NAME " PipeHandle = %p\n", interface_information->Pipes[i].PipeHandle));
331 KdPrint((__DRIVER_NAME " MaximumTransferSize = %d\n", interface_information->Pipes[i].MaximumTransferSize));
332 KdPrint((__DRIVER_NAME " PipeFlags = %08x\n", interface_information->Pipes[i].PipeFlags));
333 }
335 shadow = get_shadow_from_freelist(xudd);
336 shadow->request = request;
337 shadow->urb = urb;
338 shadow->mdl = NULL;
339 shadow->dma_transaction = NULL;
340 shadow->callback = XenUsb_UrbCallback;
341 shadow->req.id = shadow->id;
342 shadow->req.pipe = LINUX_PIPE_TYPE_CTRL | (usb_device->address << 8) | usb_device->port_number;
343 shadow->req.transfer_flags = 0;
344 setup_packet = (PUSB_DEFAULT_PIPE_SETUP_PACKET)shadow->req.u.ctrl;
345 setup_packet->bmRequestType.Recipient = BMREQUEST_TO_INTERFACE;
346 setup_packet->bmRequestType.Type = BMREQUEST_STANDARD;
347 setup_packet->bmRequestType.Dir = BMREQUEST_HOST_TO_DEVICE;
348 setup_packet->bRequest = USB_REQUEST_SET_INTERFACE;
349 setup_packet->wLength = 0;
350 setup_packet->wValue.W = urb->UrbSelectInterface.Interface.AlternateSetting;
351 setup_packet->wIndex.W = urb->UrbSelectInterface.Interface.InterfaceNumber;
352 status = XenUsb_ExecuteRequest(xudd, shadow, NULL, NULL, 0);
353 if (!NT_SUCCESS(status))
354 {
355 KdPrint((__DRIVER_NAME " XenUsb_ExecuteRequest status = %08x\n", status));
356 }
357 break;
358 case URB_FUNCTION_GET_DESCRIPTOR_FROM_DEVICE:
359 KdPrint((__DRIVER_NAME " URB_FUNCTION_GET_DESCRIPTOR_FROM_DEVICE\n"));
360 KdPrint((__DRIVER_NAME " TransferBufferLength = %d\n", urb->UrbControlDescriptorRequest.TransferBufferLength));
361 KdPrint((__DRIVER_NAME " TransferBuffer = %p\n", urb->UrbControlDescriptorRequest.TransferBuffer));
362 KdPrint((__DRIVER_NAME " TransferBufferMDL = %p\n", urb->UrbControlDescriptorRequest.TransferBufferMDL));
363 KdPrint((__DRIVER_NAME " Index = %d\n", (int)urb->UrbControlDescriptorRequest.Index));
364 KdPrint((__DRIVER_NAME " DescriptorType = %d\n", (int)urb->UrbControlDescriptorRequest.DescriptorType));
365 KdPrint((__DRIVER_NAME " LanguageId = %04x\n", urb->UrbControlDescriptorRequest.LanguageId));
366 shadow = get_shadow_from_freelist(xudd);
367 shadow->request = request;
368 shadow->urb = urb;
369 shadow->callback = XenUsb_UrbCallback;
370 shadow->req.id = shadow->id;
371 shadow->req.pipe = LINUX_PIPE_DIRECTION_IN | LINUX_PIPE_TYPE_CTRL | (usb_device->address << 8) | usb_device->port_number;
372 shadow->req.transfer_flags = 0;
373 setup_packet = (PUSB_DEFAULT_PIPE_SETUP_PACKET)shadow->req.u.ctrl;
374 setup_packet->bmRequestType.Recipient = BMREQUEST_TO_DEVICE;
375 setup_packet->bmRequestType.Type = BMREQUEST_STANDARD;
376 setup_packet->bmRequestType.Dir = BMREQUEST_DEVICE_TO_HOST;
377 setup_packet->bRequest = USB_REQUEST_GET_DESCRIPTOR;
378 setup_packet->wValue.LowByte = urb->UrbControlDescriptorRequest.Index;
379 setup_packet->wValue.HiByte = urb->UrbControlDescriptorRequest.DescriptorType;
380 switch(urb->UrbControlDescriptorRequest.DescriptorType)
381 {
382 case USB_STRING_DESCRIPTOR_TYPE:
383 setup_packet->wIndex.W = urb->UrbControlDescriptorRequest.LanguageId;
384 break;
385 default:
386 setup_packet->wIndex.W = 0;
387 break;
388 }
389 setup_packet->wLength = (USHORT)urb->UrbControlDescriptorRequest.TransferBufferLength;
390 status = XenUsb_ExecuteRequest(xudd, shadow, urb->UrbControlDescriptorRequest.TransferBuffer, urb->UrbControlDescriptorRequest.TransferBufferMDL, urb->UrbControlDescriptorRequest.TransferBufferLength);
391 if (!NT_SUCCESS(status))
392 {
393 KdPrint((__DRIVER_NAME " XenUsb_ExecuteRequest status = %08x\n", status));
394 }
395 break;
396 case URB_FUNCTION_GET_DESCRIPTOR_FROM_INTERFACE:
397 KdPrint((__DRIVER_NAME " URB_FUNCTION_GET_DESCRIPTOR_FROM_INTERFACE\n"));
398 KdPrint((__DRIVER_NAME " TransferBufferLength = %d\n", urb->UrbControlDescriptorRequest.TransferBufferLength));
399 KdPrint((__DRIVER_NAME " TransferBuffer = %p\n", urb->UrbControlDescriptorRequest.TransferBuffer));
400 KdPrint((__DRIVER_NAME " TransferBufferMDL = %p\n", urb->UrbControlDescriptorRequest.TransferBufferMDL));
401 KdPrint((__DRIVER_NAME " Index = %d\n", (int)urb->UrbControlDescriptorRequest.Index));
402 KdPrint((__DRIVER_NAME " DescriptorType = %d\n", (int)urb->UrbControlDescriptorRequest.DescriptorType));
403 KdPrint((__DRIVER_NAME " LanguageId = %04x\n", urb->UrbControlDescriptorRequest.LanguageId));
404 shadow = get_shadow_from_freelist(xudd);
405 shadow->request = request;
406 shadow->urb = urb;
407 shadow->callback = XenUsb_UrbCallback;
408 shadow->req.id = shadow->id;
409 shadow->req.pipe = LINUX_PIPE_DIRECTION_IN | LINUX_PIPE_TYPE_CTRL | (usb_device->address << 8) | usb_device->port_number;
410 shadow->req.transfer_flags = 0;
411 setup_packet = (PUSB_DEFAULT_PIPE_SETUP_PACKET)shadow->req.u.ctrl;
412 setup_packet->bmRequestType.Recipient = BMREQUEST_TO_INTERFACE;
413 setup_packet->bmRequestType.Type = BMREQUEST_STANDARD;
414 setup_packet->bmRequestType.Dir = BMREQUEST_DEVICE_TO_HOST;
415 setup_packet->bRequest = USB_REQUEST_GET_DESCRIPTOR;
416 setup_packet->wValue.LowByte = urb->UrbControlDescriptorRequest.Index;
417 setup_packet->wValue.HiByte = urb->UrbControlDescriptorRequest.DescriptorType;
418 switch(urb->UrbControlDescriptorRequest.DescriptorType)
419 {
420 case USB_STRING_DESCRIPTOR_TYPE:
421 setup_packet->wIndex.W = urb->UrbControlDescriptorRequest.LanguageId;
422 break;
423 default:
424 setup_packet->wIndex.W = 0;
425 break;
426 }
427 setup_packet->wLength = (USHORT)urb->UrbControlDescriptorRequest.TransferBufferLength;
428 status = XenUsb_ExecuteRequest(xudd, shadow, urb->UrbControlDescriptorRequest.TransferBuffer, urb->UrbControlDescriptorRequest.TransferBufferMDL, urb->UrbControlDescriptorRequest.TransferBufferLength);
429 if (!NT_SUCCESS(status))
430 {
431 KdPrint((__DRIVER_NAME " XenUsb_ExecuteRequest status = %08x\n", status));
432 }
433 break;
434 case URB_FUNCTION_CLASS_INTERFACE:
435 KdPrint((__DRIVER_NAME " URB_FUNCTION_CLASS_INTERFACE\n"));
436 KdPrint((__DRIVER_NAME " TransferFlags = %08x\n", urb->UrbControlVendorClassRequest.TransferFlags));
437 KdPrint((__DRIVER_NAME " TransferBufferLength = %d\n", urb->UrbControlVendorClassRequest.TransferBufferLength));
438 KdPrint((__DRIVER_NAME " TransferBuffer = %p\n", urb->UrbControlVendorClassRequest.TransferBuffer));
439 KdPrint((__DRIVER_NAME " TransferBufferMDL = %p\n", urb->UrbControlVendorClassRequest.TransferBufferMDL));
440 KdPrint((__DRIVER_NAME " RequestTypeReservedBits = %02x\n", urb->UrbControlVendorClassRequest.RequestTypeReservedBits));
441 KdPrint((__DRIVER_NAME " Request = %02x\n", urb->UrbControlVendorClassRequest.Request));
442 KdPrint((__DRIVER_NAME " Value = %04x\n", urb->UrbControlVendorClassRequest.Value));
443 KdPrint((__DRIVER_NAME " Index = %04x\n", urb->UrbControlVendorClassRequest.Index));
445 shadow = get_shadow_from_freelist(xudd);
446 shadow->request = request;
447 shadow->urb = urb;
448 shadow->callback = XenUsb_UrbCallback;
449 shadow->req.id = shadow->id;
450 shadow->req.pipe = LINUX_PIPE_TYPE_CTRL | (usb_device->address << 8) | usb_device->port_number;
451 shadow->req.transfer_flags = 0;
452 if (!(urb->UrbControlVendorClassRequest.TransferFlags & USBD_SHORT_TRANSFER_OK))
453 shadow->req.transfer_flags |= LINUX_URB_SHORT_NOT_OK;
454 setup_packet = (PUSB_DEFAULT_PIPE_SETUP_PACKET)shadow->req.u.ctrl;
455 setup_packet->bmRequestType.B = urb->UrbControlVendorClassRequest.RequestTypeReservedBits;
456 if (urb->UrbControlVendorClassRequest.TransferFlags & (USBD_TRANSFER_DIRECTION_IN | USBD_SHORT_TRANSFER_OK))
457 {
458 setup_packet->bmRequestType.Dir = BMREQUEST_DEVICE_TO_HOST;
459 shadow->req.pipe |= LINUX_PIPE_DIRECTION_IN;
460 }
461 else
462 {
463 setup_packet->bmRequestType.Dir = BMREQUEST_HOST_TO_DEVICE;
464 shadow->req.pipe |= LINUX_PIPE_DIRECTION_OUT;
465 }
466 setup_packet->bmRequestType.Recipient = BMREQUEST_TO_INTERFACE;
467 setup_packet->bmRequestType.Type = BMREQUEST_CLASS;
468 setup_packet->bRequest = urb->UrbControlVendorClassRequest.Request;
469 setup_packet->wValue.W = urb->UrbControlVendorClassRequest.Value;
470 setup_packet->wIndex.W = urb->UrbControlVendorClassRequest.Index;
471 status = XenUsb_ExecuteRequest(xudd, shadow, urb->UrbControlVendorClassRequest.TransferBuffer, urb->UrbControlVendorClassRequest.TransferBufferMDL, urb->UrbControlVendorClassRequest.TransferBufferLength);
472 if (!NT_SUCCESS(status))
473 {
474 KdPrint((__DRIVER_NAME " XenUsb_ExecuteRequest status = %08x\n", status));
475 }
476 break;
477 #if 0
478 case URB_FUNCTION_GET_STATUS_FROM_DEVICE:
479 KdPrint((__DRIVER_NAME " URB_FUNCTION_GET_STATUS_FROM_DEVICE\n"));
480 KdPrint((__DRIVER_NAME " TransferBufferLength = %d\n", urb->UrbControlGetStatusRequest.TransferBufferLength));
481 KdPrint((__DRIVER_NAME " TransferBuffer = %p\n", urb->UrbControlGetStatusRequest.TransferBuffer));
482 KdPrint((__DRIVER_NAME " TransferBufferMDL = %p\n", urb->UrbControlGetStatusRequest.TransferBufferMDL));
483 KdPrint((__DRIVER_NAME " Index = %04x\n", urb->UrbControlGetStatusRequest.Index));
484 if (urb->UrbControlGetStatusRequest.Index == 0)
485 {
486 urb->UrbControlGetStatusRequest.TransferBufferLength = 2;
487 *(PUSHORT)urb->UrbControlGetStatusRequest.TransferBuffer = 0x0003;
488 urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
489 WdfRequestComplete(request, STATUS_SUCCESS);
490 }
491 else
492 {
493 KdPrint((__DRIVER_NAME " Unknown Index\n"));
494 urb->UrbHeader.Status = USBD_STATUS_INVALID_URB_FUNCTION;
495 WdfRequestComplete(request, STATUS_UNSUCCESSFUL);
496 }
497 break;
498 case URB_FUNCTION_CLASS_DEVICE:
499 #if 0
500 KdPrint((__DRIVER_NAME " URB_FUNCTION_CLASS_DEVICE\n"));
501 KdPrint((__DRIVER_NAME " TransferBufferLength = %d\n", urb->UrbControlVendorClassRequest.TransferBufferLength));
502 KdPrint((__DRIVER_NAME " TransferBuffer = %p\n", urb->UrbControlVendorClassRequest.TransferBuffer));
503 KdPrint((__DRIVER_NAME " TransferBufferMDL = %p\n", urb->UrbControlVendorClassRequest.TransferBufferMDL));
504 KdPrint((__DRIVER_NAME " RequestTypeReservedBits = %02x\n", urb->UrbControlVendorClassRequest.RequestTypeReservedBits));
505 KdPrint((__DRIVER_NAME " Request = %02x\n", urb->UrbControlVendorClassRequest.Request));
506 KdPrint((__DRIVER_NAME " Value = %04x\n", urb->UrbControlVendorClassRequest.Value));
507 KdPrint((__DRIVER_NAME " Index = %04x\n", urb->UrbControlVendorClassRequest.Index));
508 #endif
509 switch (urb->UrbControlVendorClassRequest.Request)
510 {
511 case USB_REQUEST_GET_DESCRIPTOR:
512 KdPrint((__DRIVER_NAME " URB_FUNCTION_CLASS_DEVICE\n"));
513 KdPrint((__DRIVER_NAME " TransferBufferLength = %d\n", urb->UrbControlVendorClassRequest.TransferBufferLength));
514 KdPrint((__DRIVER_NAME " TransferBuffer = %p\n", urb->UrbControlVendorClassRequest.TransferBuffer));
515 KdPrint((__DRIVER_NAME " TransferBufferMDL = %p\n", urb->UrbControlVendorClassRequest.TransferBufferMDL));
516 KdPrint((__DRIVER_NAME " RequestTypeReservedBits = %02x\n", urb->UrbControlVendorClassRequest.RequestTypeReservedBits));
517 KdPrint((__DRIVER_NAME " Request = %02x\n", urb->UrbControlVendorClassRequest.Request));
518 KdPrint((__DRIVER_NAME " Value = %04x\n", urb->UrbControlVendorClassRequest.Value));
519 KdPrint((__DRIVER_NAME " Index = %04x\n", urb->UrbControlVendorClassRequest.Index));
520 KdPrint((__DRIVER_NAME " USB_REQUEST_GET_DESCRIPTOR\n"));
521 switch (urb->UrbControlVendorClassRequest.Value >> 8)
522 {
523 case 0x00:
524 #if 0
525 memcpy(urb->UrbControlVendorClassRequest.TransferBuffer, &usb_device->device_descriptor, sizeof(USB_DEVICE_DESCRIPTOR));
526 urb->UrbControlVendorClassRequest.TransferBufferLength = sizeof(USB_DEVICE_DESCRIPTOR);
527 urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
528 WdfRequestComplete(request, STATUS_SUCCESS);
529 break;
530 #endif
531 case 0x29: // Hub Descriptor
532 KdPrint((__DRIVER_NAME " HUB_DESCRIPTOR\n"));
533 uhd = urb->UrbControlVendorClassRequest.TransferBuffer;
534 urb->UrbControlVendorClassRequest.TransferBufferLength = FIELD_OFFSET(USB_HUB_DESCRIPTOR, bRemoveAndPowerMask[0]) + 2 + 1;
535 uhd->bDescriptorLength = (UCHAR)urb->UrbControlVendorClassRequest.TransferBufferLength;
536 uhd->bDescriptorType = 0x29;
537 uhd->bNumberOfPorts = 8;
538 uhd->wHubCharacteristics = 0x0012; // no power switching no overcurrent protection
539 uhd->bPowerOnToPowerGood = 1; // 2ms units
540 uhd->bHubControlCurrent = 0;
541 // DeviceRemovable bits (includes an extra bit at the start)
542 uhd->bRemoveAndPowerMask[0] = 0;
543 uhd->bRemoveAndPowerMask[1] = 0;
544 // PortPwrCtrlMask
545 uhd->bRemoveAndPowerMask[2] = 0xFF;
546 urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
547 WdfRequestComplete(request, STATUS_SUCCESS);
548 break;
549 default:
550 KdPrint((__DRIVER_NAME " Unknown Value %02x\n", urb->UrbControlVendorClassRequest.Value >> 8));
551 urb->UrbHeader.Status = USBD_STATUS_INVALID_URB_FUNCTION;
552 WdfRequestComplete(request, STATUS_UNSUCCESSFUL);
553 break;
554 }
555 break;
556 case USB_REQUEST_GET_STATUS:
557 KdPrint((__DRIVER_NAME " TransferFlags = %08x\n", urb->UrbControlVendorClassRequest.TransferFlags));
558 KdPrint((__DRIVER_NAME " TransferBufferLength = %d\n", urb->UrbControlVendorClassRequest.TransferBufferLength));
559 KdPrint((__DRIVER_NAME " TransferBuffer = %p\n", urb->UrbControlVendorClassRequest.TransferBuffer));
560 KdPrint((__DRIVER_NAME " TransferBufferMDL = %p\n", urb->UrbControlVendorClassRequest.TransferBufferMDL));
561 KdPrint((__DRIVER_NAME " RequestTypeReservedBits = %02x\n", urb->UrbControlVendorClassRequest.RequestTypeReservedBits));
562 KdPrint((__DRIVER_NAME " Request = %02x\n", urb->UrbControlVendorClassRequest.Request));
563 KdPrint((__DRIVER_NAME " Value = %04x\n", urb->UrbControlVendorClassRequest.Value));
564 KdPrint((__DRIVER_NAME " Index = %04x\n", urb->UrbControlVendorClassRequest.Index));
565 KdPrint((__DRIVER_NAME " USB_REQUEST_GET_STATUS\n"));
566 // Check that RequestTypeReservedBits == 0xA0
567 KdPrint((__DRIVER_NAME " GetHubStatus\n"));
568 /* hub status */
569 // shoud be able to get this field from somewhere else...
570 ((PUSHORT)urb->UrbControlVendorClassRequest.TransferBuffer)[0] = 0x0000;
571 ((PUSHORT)urb->UrbControlVendorClassRequest.TransferBuffer)[1] = 0x0000; /* no change occurred */
572 urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
573 WdfRequestComplete(request, STATUS_SUCCESS);
574 break;
575 case USB_REQUEST_CLEAR_FEATURE:
576 KdPrint((__DRIVER_NAME " TransferFlags = %08x\n", urb->UrbControlVendorClassRequest.TransferFlags));
577 KdPrint((__DRIVER_NAME " TransferBufferLength = %d\n", urb->UrbControlVendorClassRequest.TransferBufferLength));
578 KdPrint((__DRIVER_NAME " TransferBuffer = %p\n", urb->UrbControlVendorClassRequest.TransferBuffer));
579 KdPrint((__DRIVER_NAME " TransferBufferMDL = %p\n", urb->UrbControlVendorClassRequest.TransferBufferMDL));
580 KdPrint((__DRIVER_NAME " RequestTypeReservedBits = %02x\n", urb->UrbControlVendorClassRequest.RequestTypeReservedBits));
581 KdPrint((__DRIVER_NAME " Request = %02x\n", urb->UrbControlVendorClassRequest.Request));
582 KdPrint((__DRIVER_NAME " Value = %04x\n", urb->UrbControlVendorClassRequest.Value));
583 KdPrint((__DRIVER_NAME " Index = %04x\n", urb->UrbControlVendorClassRequest.Index));
584 KdPrint((__DRIVER_NAME " USB_REQUEST_CLEAR_FEATURE\n"));
585 urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
586 WdfRequestComplete(request, STATUS_SUCCESS);
587 break;
588 default:
589 URB_FUNCTION_GET_DESCRIPTOR_FROM_DEVICE KdPrint((__DRIVER_NAME " TransferFlags = %08x\n", urb->UrbControlVendorClassRequest.TransferFlags));
590 KdPrint((__DRIVER_NAME " TransferBufferLength = %d\n", urb->UrbControlVendorClassRequest.TransferBufferLength));
591 KdPrint((__DRIVER_NAME " TransferBuffer = %p\n", urb->UrbControlVendorClassRequest.TransferBuffer));
592 KdPrint((__DRIVER_NAME " TransferBufferMDL = %p\n", urb->UrbControlVendorClassRequest.TransferBufferMDL));
593 KdPrint((__DRIVER_NAME " RequestTypeReservedBits = %02x\n", urb->UrbControlVendorClassRequest.RequestTypeReservedBits));
594 KdPrint((__DRIVER_NAME " Request = %02x\n", urb->UrbControlVendorClassRequest.Request));
595 KdPrint((__DRIVER_NAME " Value = %04x\n", urb->UrbControlVendorClassRequest.Value));
596 KdPrint((__DRIVER_NAME " Index = %04x\n", urb->UrbControlVendorClassRequest.Index));
597 KdPrint((__DRIVER_NAME " USB_REQUEST_%02x\n", urb->UrbControlVendorClassRequest.Request));
598 urb->UrbHeader.Status = USBD_STATUS_INVALID_URB_FUNCTION;
599 WdfRequestComplete(request, STATUS_UNSUCCESSFUL);
600 break;
601 }
602 #if 0
603 shadow = get_shadow_from_freelist(xudd);
604 shadow->request = request;
605 shadow->urb = urb;
606 shadow->callback = XenUsb_UrbCallback;
607 shadow->req.id = shadow->id;
608 shadow->req.pipe = PIPE_TYPE_CTRL | (1 << 8) | usb_device->port_number;
609 if (urb->UrbControlVendorClassRequest.TransferFlags & (USBD_TRANSFER_DIRECTION_IN | USBD_SHORT_TRANSFER_OK))
610 shadow->req.pipe |= PIPE_DIRECTION_IN;
611 #if 0
612 if (urb->UrbControlVendorClassRequest.TransferFlags & USBD_SHORT_TRANSFER_OK)
613 shadow->req.transfer_flags = ;
614 #endif
615 setup_packet = (PUSB_DEFAULT_PIPE_SETUP_PACKET)shadow->req.u.ctrl;
616 setup_packet->bmRequestType.Recipient = BMREQUEST_TO_DEVICE;
617 setup_packet->bmRequestType.Type = BMREQUEST_CLASS;
618 if (urb->UrbControlVendorClassRequest.TransferFlags & (USBD_TRANSFER_DIRECTION_IN | USBD_SHORT_TRANSFER_OK))
619 setup_packet->bmRequestType.Dir = BMREQUEST_DEVICE_TO_HOST;
620 else
621 setup_packet->bmRequestType.Dir = BMREQUEST_HOST_TO_DEVICE;
622 setup_packet->bmRequestType.B |= urb->UrbControlVendorClassRequest.RequestTypeReservedBits;
623 setup_packet->bRequest = urb->UrbControlVendorClassRequest.Request;
624 setup_packet->wValue.W = urb->UrbControlVendorClassRequest.Value;
625 setup_packet->wIndex.W = urb->UrbControlVendorClassRequest.Index;
626 setup_packet->wLength = shadow->req.buffer_lengthxxx;
627 if (!urb->UrbControlVendorClassRequest.TransferBufferMDL)
628 {
629 mdl = IoAllocateMdl(urb->UrbControlVendorClassRequest.TransferBuffer, urb->UrbControlVendorClassRequest.TransferBufferLength, FALSE, FALSE, NULL);
630 MmBuildMdlForNonPagedPool(mdl);
631 shadow->mdl = mdl;
632 }
633 else
634 {
635 mdl = urb->UrbControlVendorClassRequest.TransferBufferMDL;
636 shadow->mdl = NULL;
637 }
638 KdPrint((__DRIVER_NAME " VA = %p\n", MmGetMdlVirtualAddress(mdl)));
639 KdPrint((__DRIVER_NAME " phys = %08x\n", MmGetPhysicalAddress(urb->UrbControlVendorClassRequest.TransferBuffer).LowPart));
640 KdPrint((__DRIVER_NAME " PFN[0] = %08x\n", MmGetMdlPfnArray(mdl)[0]));
642 status = WdfDmaTransactionCreate(xudd->dma_enabler, WDF_NO_OBJECT_ATTRIBUTES, &shadow->dma_transaction);
643 if (!status)
644 {
645 KdPrint((__DRIVER_NAME " WdfDmaTransactionCreate status = %08x\n", status));
646 }
647 status = WdfDmaTransactionInitialize(
648 shadow->dma_transaction,
649 XenUsb_FillShadowSegs,
650 (shadow->req.pipe & PIPE_DIRECTION_IN)?WdfDmaDirectionReadFromDevice:WdfDmaDirectionWriteToDevice,
651 mdl,
652 MmGetMdlVirtualAddress(mdl),
653 urb->UrbControlVendorClassRequest.TransferBufferLength);
654 if (!status)
655 {
656 KdPrint((__DRIVER_NAME " WdfDmaTransactionInitialize status = %08x\n", status));
657 }
658 status = WdfDmaTransactionExecute(shadow->dma_transaction, shadow);
659 if (!status)
660 {
661 KdPrint((__DRIVER_NAME " WdfDmaTransactionExecute status = %08x\n", status));
662 }
663 #endif
664 break;
665 case URB_FUNCTION_CLASS_OTHER:
666 KdPrint((__DRIVER_NAME " URB_FUNCTION_CLASS_OTHER\n"));
667 KdPrint((__DRIVER_NAME " TransferFlags = %08x\n", urb->UrbControlVendorClassRequest.TransferFlags));
668 KdPrint((__DRIVER_NAME " TransferBufferLength = %d\n", urb->UrbControlVendorClassRequest.TransferBufferLength));
669 KdPrint((__DRIVER_NAME " TransferBuffer = %p\n", urb->UrbControlVendorClassRequest.TransferBuffer));
670 KdPrint((__DRIVER_NAME " TransferBufferMdl = %p\n", urb->UrbControlVendorClassRequest.TransferBufferMDL));
671 KdPrint((__DRIVER_NAME " RequestTypeReservedBits = %02x\n", urb->UrbControlVendorClassRequest.RequestTypeReservedBits));
672 KdPrint((__DRIVER_NAME " Request = %02x\n", urb->UrbControlVendorClassRequest.Request));
673 KdPrint((__DRIVER_NAME " Value = %04x\n", urb->UrbControlVendorClassRequest.Value));
674 KdPrint((__DRIVER_NAME " Index = %04x\n", urb->UrbControlVendorClassRequest.Index));
675 switch (urb->UrbControlVendorClassRequest.Request)
676 {
677 case USB_REQUEST_GET_STATUS:
678 /* port status - 11.24.2.7.1 */
679 KdPrint((__DRIVER_NAME " USB_REQUEST_GET_STATUS\n"));
680 KdPrint((__DRIVER_NAME " GetHubStatus\n"));
681 ((PUSHORT)urb->UrbControlVendorClassRequest.TransferBuffer)[0] = xudd->ports[urb->UrbControlVendorClassRequest.Index - 1].port_status;
682 ((PUSHORT)urb->UrbControlVendorClassRequest.TransferBuffer)[1] = xudd->ports[urb->UrbControlVendorClassRequest.Index - 1].port_change;
683 break;
684 case USB_REQUEST_SET_FEATURE:
685 KdPrint((__DRIVER_NAME " USB_REQUEST_SET_FEATURE\n"));
686 KdPrint((__DRIVER_NAME " SetPortFeature\n"));
687 switch (urb->UrbControlVendorClassRequest.Value)
688 {
689 case PORT_ENABLE:
690 KdPrint((__DRIVER_NAME " PORT_ENABLE\n"));
691 /* do something here */
692 break;
693 case PORT_RESET:
694 KdPrint((__DRIVER_NAME " PORT_RESET\n"));
695 /* just fake the reset */
696 xudd->ports[urb->UrbControlVendorClassRequest.Index - 1].port_change |= (1 << PORT_RESET);
697 break;
698 default:
699 KdPrint((__DRIVER_NAME " Unknown Value %04X\n", urb->UrbControlVendorClassRequest.Value));
700 break;
701 }
702 KdPrint((__DRIVER_NAME " status = %04x, change = %04x\n",
703 xudd->ports[urb->UrbControlVendorClassRequest.Index - 1].port_status,
704 xudd->ports[urb->UrbControlVendorClassRequest.Index - 1].port_change));
705 break;
706 case USB_REQUEST_CLEAR_FEATURE:
707 KdPrint((__DRIVER_NAME " USB_REQUEST_CLEAR_FEATURE\n"));
708 KdPrint((__DRIVER_NAME " ClearPortFeature\n"));
709 switch (urb->UrbControlVendorClassRequest.Value)
710 {
711 case C_PORT_CONNECTION:
712 KdPrint((__DRIVER_NAME " C_PORT_CONNECTION\n"));
713 xudd->ports[urb->UrbControlVendorClassRequest.Index - 1].port_change &= ~(1 << PORT_CONNECTION);
714 break;
715 case C_PORT_RESET:
716 KdPrint((__DRIVER_NAME " C_PORT_RESET\n"));
717 xudd->ports[urb->UrbControlVendorClassRequest.Index - 1].port_change &= ~(1 << PORT_RESET);
718 break;
719 default:
720 KdPrint((__DRIVER_NAME " Unknown Value %04X\n", urb->UrbControlVendorClassRequest.Value));
721 break;
722 }
723 KdPrint((__DRIVER_NAME " status = %04x, change = %04x\n",
724 xudd->ports[urb->UrbControlVendorClassRequest.Index - 1].port_status,
725 xudd->ports[urb->UrbControlVendorClassRequest.Index - 1].port_change));
726 break;
727 default:
728 KdPrint((__DRIVER_NAME " USB_REQUEST_%02x\n", urb->UrbControlVendorClassRequest.Request));
729 break;
730 }
731 urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
732 WdfRequestComplete(request, STATUS_SUCCESS);
733 //urb->UrbHeader.Status = USBD_STATUS_INVALID_URB_FUNCTION;
734 //WdfRequestComplete(request, STATUS_UNSUCCESSFUL);
735 break;
736 #endif
737 case URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER: /* 11.12.4 */
738 endpoint = urb->UrbBulkOrInterruptTransfer.PipeHandle;
739 // KdPrint((__DRIVER_NAME " pipe_value = %08x\n", endpoint->pipe_value));
740 shadow = get_shadow_from_freelist(xudd);
741 //KdPrint((__DRIVER_NAME " id = %d\n", shadow->id));
742 shadow->request = request;
743 shadow->urb = urb;
744 shadow->callback = XenUsb_UrbCallback;
745 shadow->req.id = shadow->id;
746 shadow->req.pipe = endpoint->pipe_value;
747 shadow->req.transfer_flags = 0;
748 if (!(urb->UrbBulkOrInterruptTransfer.TransferFlags & USBD_SHORT_TRANSFER_OK) && (endpoint->pipe_value & LINUX_PIPE_DIRECTION_IN))
749 shadow->req.transfer_flags |= LINUX_URB_SHORT_NOT_OK;
750 switch(endpoint->endpoint_descriptor.bmAttributes & USB_ENDPOINT_TYPE_MASK)
751 {
752 case USB_ENDPOINT_TYPE_BULK:
753 //KdPrint((__DRIVER_NAME " USB_ENDPOINT_TYPE_BULK\n"));
754 break;
755 case USB_ENDPOINT_TYPE_INTERRUPT:
756 KdPrint((__DRIVER_NAME " USB_ENDPOINT_TYPE_INTERRUPT\n"));
757 break;
758 default:
759 KdPrint((__DRIVER_NAME " USB_ENDPOINT_TYPE_%d\n", endpoint->endpoint_descriptor.bmAttributes));
760 break;
761 }
762 status = XenUsb_ExecuteRequest(xudd, shadow, urb->UrbBulkOrInterruptTransfer.TransferBuffer, urb->UrbBulkOrInterruptTransfer.TransferBufferMDL, urb->UrbBulkOrInterruptTransfer.TransferBufferLength);
763 if (!NT_SUCCESS(status))
764 {
765 KdPrint((__DRIVER_NAME " XenUsb_ExecuteRequest status = %08x\n", status));
766 }
767 break;
768 #if 0
769 case URB_FUNCTION_SYNC_RESET_PIPE_AND_CLEAR_STALL:
770 KdPrint((__DRIVER_NAME " URB_FUNCTION_SYNC_RESET_PIPE_AND_CLEAR_STALL\n"));
771 KdPrint((__DRIVER_NAME " PipeHandle = %p\n", urb->UrbPipeRequest.PipeHandle));
772 urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
773 WdfRequestComplete(request, STATUS_SUCCESS);
774 break;
775 #endif
776 case URB_FUNCTION_ABORT_PIPE:
777 KdPrint((__DRIVER_NAME " URB_FUNCTION_ABORT_PIPE\n"));
778 KdPrint((__DRIVER_NAME " PipeHandle = %p\n", urb->UrbPipeRequest.PipeHandle));
779 break;
780 default:
781 KdPrint((__DRIVER_NAME " URB_FUNCTION_%04x\n", urb->UrbHeader.Function));
782 KdPrint((__DRIVER_NAME " Calling WdfRequestCompletestatus with status = %08x\n", status));
783 urb->UrbHeader.Status = USBD_STATUS_INVALID_URB_FUNCTION;
784 WdfRequestComplete(request, STATUS_UNSUCCESSFUL);
785 break;
786 }
787 //FUNCTION_EXIT();
788 }