win-pvdrivers

view xenusb/xenusb_devurb.c @ 670:b59c7dfdee9b

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