win-pvdrivers

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