win-pvdrivers

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