win-pvdrivers

view xenusb/xenusb_huburb.c @ 965:63bdd096d8d1

Fix KeInitializeCrashDumpHeader - buffer was too small under newer systems
author James Harper <james.harper@bendigoit.com.au>
date Tue Jan 10 12:11:30 2012 +1100 (2012-01-10)
parents 19d7c9dd9f5c
children 1306945ecc59
line source
1 /*
2 PV Drivers for Windows Xen HVM Domains
3 Copyright (C) 2007 James Harper
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
20 #include "xenusb.h"
22 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 xenusb_endpoint_t *endpoint;
40 //USB_DEFAULT_PIPE_SETUP_PACKET setup_packet;
41 urb_decode_t decode_data;
42 ULONG decode_retval;
44 UNREFERENCED_PARAMETER(input_buffer_length);
45 UNREFERENCED_PARAMETER(output_buffer_length);
46 UNREFERENCED_PARAMETER(io_control_code);
48 //FUNCTION_ENTER();
50 WDF_REQUEST_PARAMETERS_INIT(&wrp);
51 WdfRequestGetParameters(request, &wrp);
53 urb = (PURB)wrp.Parameters.Others.Arg1;
54 ASSERT(urb);
55 #if 0
56 KdPrint((__DRIVER_NAME " urb = %p\n", urb));
57 KdPrint((__DRIVER_NAME " Length = %d\n", urb->UrbHeader.Length));
58 KdPrint((__DRIVER_NAME " Function = %d\n", urb->UrbHeader.Function));
59 KdPrint((__DRIVER_NAME " Status = %d\n", urb->UrbHeader.Status));
60 KdPrint((__DRIVER_NAME " UsbdDeviceHandle = %p\n", urb->UrbHeader.UsbdDeviceHandle));
61 KdPrint((__DRIVER_NAME " UsbdFlags = %08x\n", urb->UrbHeader.UsbdFlags));
62 #endif
63 usb_device = urb->UrbHeader.UsbdDeviceHandle;
65 if (!usb_device)
66 usb_device = xupdd->usb_device;
68 decode_retval = XenUsb_DecodeControlUrb(urb, &decode_data);
69 if (decode_retval == URB_DECODE_UNKNOWN)
70 {
71 FUNCTION_MSG("Unknown URB - Calling WdfRequestCompletestatus with status = %08x\n", STATUS_UNSUCCESSFUL); //STATUS_UNSUCCESSFUL));
72 urb->UrbHeader.Status = USBD_STATUS_INVALID_URB_FUNCTION;
73 WdfRequestComplete(request, STATUS_UNSUCCESSFUL);
74 return;
75 }
77 urb->UrbHeader.Status = USBD_STATUS_INVALID_URB_FUNCTION;
79 if (decode_retval != URB_DECODE_NOT_CONTROL)
80 {
81 FUNCTION_MSG("bmRequestType = %02x\n", decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.B);
82 FUNCTION_MSG(" Recipient = %x\n", decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.Recipient);
83 FUNCTION_MSG(" Type = %x\n", decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.Type);
84 FUNCTION_MSG(" Dir = %x\n", decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.Dir);
85 FUNCTION_MSG("bRequest = %02x\n", decode_data.setup_packet.default_pipe_setup_packet.bRequest);
86 FUNCTION_MSG("wValue = %04x\n", decode_data.setup_packet.default_pipe_setup_packet.wValue.W);
87 FUNCTION_MSG(" Low = %02x\n", decode_data.setup_packet.default_pipe_setup_packet.wValue.LowByte);
88 FUNCTION_MSG(" High = %02x\n", decode_data.setup_packet.default_pipe_setup_packet.wValue.HiByte);
89 FUNCTION_MSG("wIndex = %04x\n", decode_data.setup_packet.default_pipe_setup_packet.wIndex);
90 FUNCTION_MSG(" Low = %02x\n", decode_data.setup_packet.default_pipe_setup_packet.wIndex.LowByte);
91 FUNCTION_MSG(" High = %02x\n", decode_data.setup_packet.default_pipe_setup_packet.wIndex.HiByte);
92 FUNCTION_MSG("wLength = %04x\n", decode_data.setup_packet.default_pipe_setup_packet.wLength);
93 }
95 switch(urb->UrbHeader.Function)
96 {
97 case URB_FUNCTION_SELECT_CONFIGURATION:
98 KdPrint((__DRIVER_NAME " URB_FUNCTION_SELECT_CONFIGURATION\n"));
99 KdPrint((__DRIVER_NAME " ConfigurationDescriptor = %p\n", urb->UrbSelectConfiguration.ConfigurationDescriptor));
100 if (urb->UrbSelectConfiguration.ConfigurationDescriptor)
101 {
102 KdPrint((__DRIVER_NAME " bLength = %d\n", urb->UrbSelectConfiguration.ConfigurationDescriptor->bLength));
103 KdPrint((__DRIVER_NAME " bDescriptorType = %d\n", urb->UrbSelectConfiguration.ConfigurationDescriptor->bDescriptorType));
104 KdPrint((__DRIVER_NAME " wTotalLength = %d\n", urb->UrbSelectConfiguration.ConfigurationDescriptor->wTotalLength));
105 KdPrint((__DRIVER_NAME " bNumInterfaces = %d\n", urb->UrbSelectConfiguration.ConfigurationDescriptor->bNumInterfaces));
106 KdPrint((__DRIVER_NAME " bConfigurationValue = %d\n", urb->UrbSelectConfiguration.ConfigurationDescriptor->bConfigurationValue));
107 KdPrint((__DRIVER_NAME " iConfiguration = %d\n", urb->UrbSelectConfiguration.ConfigurationDescriptor->iConfiguration));
108 KdPrint((__DRIVER_NAME " bmAttributes = %04x\n", urb->UrbSelectConfiguration.ConfigurationDescriptor->bmAttributes));
109 KdPrint((__DRIVER_NAME " MaxPower = %d\n", urb->UrbSelectConfiguration.ConfigurationDescriptor->MaxPower));
110 }
111 KdPrint((__DRIVER_NAME " ConfigurationHandle = %p\n", urb->UrbSelectConfiguration.ConfigurationHandle));
112 if (urb->UrbSelectConfiguration.ConfigurationDescriptor)
113 {
114 urb->UrbSelectConfiguration.ConfigurationHandle = xupdd->usb_device->configs[0];
115 interface_information = &urb->UrbSelectConfiguration.Interface;
116 for (i = 0; i < urb->UrbSelectConfiguration.ConfigurationDescriptor->bNumInterfaces; i++)
117 {
118 KdPrint((__DRIVER_NAME " InterfaceInformation[%d]\n", i));
119 KdPrint((__DRIVER_NAME " Length = %d\n", interface_information->Length));
120 KdPrint((__DRIVER_NAME " InterfaceNumber = %d\n", interface_information->InterfaceNumber));
121 KdPrint((__DRIVER_NAME " AlternateSetting = %d\n", interface_information->AlternateSetting));
122 KdPrint((__DRIVER_NAME " Class = %02x\n", (ULONG)interface_information->Class));
123 KdPrint((__DRIVER_NAME " SubClass = %02x\n", (ULONG)interface_information->SubClass));
124 KdPrint((__DRIVER_NAME " Protocol = %02x\n", (ULONG)interface_information->Protocol));
125 KdPrint((__DRIVER_NAME " Reserved = %02x\n", (ULONG)interface_information->Reserved));
126 KdPrint((__DRIVER_NAME " InterfaceHandle = %p\n", interface_information->InterfaceHandle));
127 KdPrint((__DRIVER_NAME " NumberOfPipes = %d\n", interface_information->NumberOfPipes));
128 interface_information->InterfaceHandle = xupdd->usb_device->configs[0]->interfaces[0];
129 interface_information->Class = 0x09;
130 interface_information->SubClass = 0x00;
131 interface_information->SubClass = 0x00;
132 for (j = 0; j < interface_information->NumberOfPipes; j++)
133 {
134 KdPrint((__DRIVER_NAME " Pipe[%d]\n", i));
135 KdPrint((__DRIVER_NAME " MaximumPacketSize = %d\n", interface_information->Pipes[j].MaximumPacketSize));
136 KdPrint((__DRIVER_NAME " EndpointAddress = %d\n", interface_information->Pipes[j].EndpointAddress));
137 KdPrint((__DRIVER_NAME " Interval = %d\n", interface_information->Pipes[j].Interval));
138 KdPrint((__DRIVER_NAME " PipeType = %d\n", interface_information->Pipes[j].PipeType));
139 KdPrint((__DRIVER_NAME " PipeHandle = %d\n", interface_information->Pipes[j].PipeHandle));
140 KdPrint((__DRIVER_NAME " MaximumTransferSize = %d\n", interface_information->Pipes[j].MaximumTransferSize));
141 KdPrint((__DRIVER_NAME " PipeFlags = %08x\n", interface_information->Pipes[j].PipeFlags));
142 interface_information->Pipes[j].MaximumPacketSize = 2;
143 interface_information->Pipes[j].EndpointAddress = 0x81;
144 interface_information->Pipes[j].Interval = 12;
145 interface_information->Pipes[j].PipeType = UsbdPipeTypeInterrupt;
146 interface_information->Pipes[j].PipeHandle = xupdd->usb_device->configs[0]->interfaces[0]->endpoints[j];
147 interface_information->Pipes[j].MaximumTransferSize = 4096; /* made up number - possibly not used */
148 // this is input actually interface_information->Pipes[j].PipeFlags = 0;
149 }
150 interface_information = (PUSBD_INTERFACE_INFORMATION)((PUCHAR)interface_information + interface_information->Length);
151 }
152 }
153 urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
154 break;
155 case URB_FUNCTION_SELECT_INTERFACE:
156 KdPrint((__DRIVER_NAME " URB_FUNCTION_SELECT_INTERFACE\n"));
157 interface_information = &urb->UrbSelectInterface.Interface;
158 KdPrint((__DRIVER_NAME " InterfaceInformation\n"));
159 KdPrint((__DRIVER_NAME " Length = %d\n", interface_information->Length));
160 KdPrint((__DRIVER_NAME " InterfaceNumber = %d\n", interface_information->InterfaceNumber));
161 KdPrint((__DRIVER_NAME " AlternateSetting = %d\n", interface_information->AlternateSetting));
162 KdPrint((__DRIVER_NAME " Class = %02x\n", (ULONG)interface_information->Class));
163 KdPrint((__DRIVER_NAME " SubClass = %02x\n", (ULONG)interface_information->SubClass));
164 KdPrint((__DRIVER_NAME " Protocol = %02x\n", (ULONG)interface_information->Protocol));
165 KdPrint((__DRIVER_NAME " Reserved = %02x\n", (ULONG)interface_information->Reserved));
166 KdPrint((__DRIVER_NAME " InterfaceHandle = %p\n", interface_information->InterfaceHandle));
167 KdPrint((__DRIVER_NAME " NumberOfPipes = %d\n", interface_information->NumberOfPipes));
168 for (i = 0; i < interface_information->NumberOfPipes; i++)
169 {
170 KdPrint((__DRIVER_NAME " Pipe[%d]\n", i));
171 KdPrint((__DRIVER_NAME " MaximumPacketSize = %d\n", interface_information->Pipes[i].MaximumPacketSize));
172 KdPrint((__DRIVER_NAME " EndpointAddress = %d\n", interface_information->Pipes[i].EndpointAddress));
173 KdPrint((__DRIVER_NAME " Interval = %d\n", interface_information->Pipes[i].Interval));
174 KdPrint((__DRIVER_NAME " PipeType = %d\n", interface_information->Pipes[i].PipeType));
175 KdPrint((__DRIVER_NAME " PipeHandle = %d\n", interface_information->Pipes[i].PipeHandle));
176 KdPrint((__DRIVER_NAME " MaximumTransferSize = %d\n", interface_information->Pipes[i].MaximumTransferSize));
177 KdPrint((__DRIVER_NAME " PipeFlags = %08x\n", interface_information->Pipes[i].PipeFlags));
178 }
179 urb->UrbHeader.Status = USBD_STATUS_INVALID_URB_FUNCTION;
180 break;
181 #if (NTDDI_VERSION >= NTDDI_VISTA)
182 case URB_FUNCTION_CONTROL_TRANSFER_EX:
183 #endif
184 case URB_FUNCTION_CONTROL_TRANSFER:
185 case URB_FUNCTION_CLASS_DEVICE:
186 case URB_FUNCTION_CLASS_OTHER:
187 case URB_FUNCTION_CLASS_INTERFACE:
188 case URB_FUNCTION_GET_DESCRIPTOR_FROM_DEVICE:
189 case URB_FUNCTION_GET_DESCRIPTOR_FROM_INTERFACE:
190 case URB_FUNCTION_GET_STATUS_FROM_DEVICE:
191 switch(decode_data.setup_packet.default_pipe_setup_packet.bRequest)
192 {
193 case USB_REQUEST_GET_STATUS:
194 // switch device, interface, endpoint
195 switch (decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.Type)
196 {
197 case BMREQUEST_STANDARD:
198 FUNCTION_MSG(" USB_REQUEST_GET_STATUS\n");
199 FUNCTION_MSG(" Type=Standard\n");
200 switch (decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.Recipient)
201 {
202 case BMREQUEST_TO_DEVICE:
203 KdPrint((__DRIVER_NAME " Recipient=Device\n"));
204 ((PUSHORT)decode_data.buffer)[0] = 0x0001; /* self powered */
205 urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
206 break;
207 default:
208 FUNCTION_MSG(" Recipient=%d\n", decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.Recipient);
209 break;
210 }
211 break;
212 case BMREQUEST_CLASS:
213 switch (decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.Recipient)
214 {
215 case BMREQUEST_TO_DEVICE:
216 ((PUSHORT)decode_data.buffer)[0] = 0x0000;
217 ((PUSHORT)decode_data.buffer)[1] = 0x0000;
218 urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
219 break;
220 case BMREQUEST_TO_OTHER:
221 FUNCTION_MSG(" USB_REQUEST_GET_STATUS\n");
222 FUNCTION_MSG(" Type=Class\n");
223 KdPrint((__DRIVER_NAME " Recipient=Other (port = %d)\n", decode_data.setup_packet.default_pipe_setup_packet.wIndex.LowByte));
224 ((PUSHORT)decode_data.buffer)[0] = xudd->ports[decode_data.setup_packet.default_pipe_setup_packet.wIndex.LowByte - 1].port_status;
225 ((PUSHORT)decode_data.buffer)[1] = xudd->ports[decode_data.setup_packet.default_pipe_setup_packet.wIndex.LowByte - 1].port_change;
226 urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
227 FUNCTION_MSG(" status = %04x, change = %04x\n",
228 xudd->ports[decode_data.setup_packet.default_pipe_setup_packet.wIndex.LowByte - 1].port_status,
229 xudd->ports[decode_data.setup_packet.default_pipe_setup_packet.wIndex.LowByte - 1].port_change);
230 break;
231 default:
232 FUNCTION_MSG(" USB_REQUEST_GET_STATUS\n");
233 FUNCTION_MSG(" Type=Class\n");
234 FUNCTION_MSG(" Recipient=%d\n", decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.Recipient);
235 break;
236 }
237 break;
238 default:
239 FUNCTION_MSG(" USB_REQUEST_GET_STATUS\n");
240 FUNCTION_MSG(" Type=%d\n", decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.Type);
241 break;
242 }
243 break;
244 case USB_REQUEST_GET_DESCRIPTOR:
245 FUNCTION_MSG(" USB_REQUEST_GET_DESCRIPTOR\n");
246 // should separate into Standard and Class
247 switch (decode_data.setup_packet.default_pipe_setup_packet.wValue.HiByte)
248 {
249 case USB_DEVICE_DESCRIPTOR_TYPE:
250 FUNCTION_MSG(" USB_DEVICE_DESCRIPTOR_TYPE\n");
251 FUNCTION_MSG(" length = %d\n", *decode_data.length);
252 memcpy(decode_data.buffer, &usb_device->device_descriptor, sizeof(USB_DEVICE_DESCRIPTOR));
253 *decode_data.length = sizeof(USB_DEVICE_DESCRIPTOR);
254 urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
255 break;
256 case USB_CONFIGURATION_DESCRIPTOR_TYPE:
257 {
258 xenusb_config_t *usb_config;
259 PUCHAR ptr;
261 FUNCTION_MSG(" USB_CONFIGURATION_DESCRIPTOR_TYPE\n");
262 FUNCTION_MSG(" length = %d\n", *decode_data.length);
263 usb_config = usb_device->active_config;
264 ptr = (PUCHAR)decode_data.buffer;
265 memcpy(ptr, &usb_config->config_descriptor, sizeof(USB_CONFIGURATION_DESCRIPTOR));
266 ptr += sizeof(USB_CONFIGURATION_DESCRIPTOR);
267 ((PUSB_CONFIGURATION_DESCRIPTOR)decode_data.buffer)->wTotalLength = sizeof(USB_CONFIGURATION_DESCRIPTOR);
268 if (*decode_data.length > 9)
269 {
270 for (i = 0; i < usb_config->config_descriptor.bNumInterfaces; i++)
271 {
272 memcpy(ptr, &usb_config->interfaces[i]->interface_descriptor, sizeof(USB_INTERFACE_DESCRIPTOR));
273 ptr += sizeof(USB_INTERFACE_DESCRIPTOR);
274 ((PUSB_CONFIGURATION_DESCRIPTOR)decode_data.buffer)->wTotalLength += sizeof(USB_INTERFACE_DESCRIPTOR);
275 for (j = 0; j < usb_config->interfaces[i]->interface_descriptor.bNumEndpoints; j++)
276 {
277 memcpy(ptr, &usb_config->interfaces[i]->endpoints[j]->endpoint_descriptor, sizeof(USB_ENDPOINT_DESCRIPTOR));
278 ptr += sizeof(USB_ENDPOINT_DESCRIPTOR);
279 ((PUSB_CONFIGURATION_DESCRIPTOR)decode_data.buffer)->wTotalLength += sizeof(USB_ENDPOINT_DESCRIPTOR);
280 }
281 }
282 }
283 *decode_data.length = ((PUSB_CONFIGURATION_DESCRIPTOR)decode_data.buffer)->wTotalLength;
284 //if (urb->UrbControlDescriptorRequest.TransferBufferLength == 9)
285 // ((PUSB_CONFIGURATION_DESCRIPTOR)decode_data.buffer)->wTotalLength = 32;
286 urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
287 break;
288 }
289 case 0x00: // unknown... doing the same as 0x29 seems to work
290 FUNCTION_MSG(" USB_00_DESCRIPTOR_TYPE (doesn't exist)\n");
291 urb->UrbHeader.Status = USBD_STATUS_BAD_DESCRIPTOR;
292 break;
293 case 0x29: // Hub Descriptor
294 {
295 PUSB_HUB_DESCRIPTOR uhd;
297 FUNCTION_MSG(" USB_HUB_DESCRIPTOR_TYPE\n", decode_data.setup_packet.default_pipe_setup_packet.wValue.HiByte);
298 FUNCTION_MSG(" length = %d\n", *decode_data.length);
299 uhd = decode_data.buffer;
300 // TODO adjust for real number of ports
301 *decode_data.length = FIELD_OFFSET(USB_HUB_DESCRIPTOR, bRemoveAndPowerMask[0]) + 2 + 1;
302 uhd->bDescriptorLength = (UCHAR)*decode_data.length;
303 uhd->bDescriptorType = 0x29;
304 uhd->bNumberOfPorts = (UCHAR)xudd->num_ports;
305 uhd->wHubCharacteristics = 0x0012; // no power switching no overcurrent protection
306 uhd->bPowerOnToPowerGood = 1; // 2ms units
307 uhd->bHubControlCurrent = 0;
308 // DeviceRemovable bits (includes an extra bit at the start)
309 uhd->bRemoveAndPowerMask[0] = 0;
310 uhd->bRemoveAndPowerMask[1] = 0;
311 // PortPwrCtrlMask
312 uhd->bRemoveAndPowerMask[2] = 0xFF;
313 urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
314 break;
315 }
316 default:
317 FUNCTION_MSG(" USB_%02x_DESCRIPTOR_TYPE\n", (ULONG)decode_data.setup_packet.default_pipe_setup_packet.wValue.HiByte);
318 FUNCTION_MSG("bmRequestType = %02x\n", decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.B);
319 FUNCTION_MSG(" Recipient = %x\n", decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.Recipient);
320 FUNCTION_MSG(" Type = %x\n", decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.Type);
321 FUNCTION_MSG(" Dir = %x\n", decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.Dir);
322 FUNCTION_MSG("bRequest = %02x\n", decode_data.setup_packet.default_pipe_setup_packet.bRequest);
323 FUNCTION_MSG("wValue = %04x\n", decode_data.setup_packet.default_pipe_setup_packet.wValue.W);
324 FUNCTION_MSG(" Low = %02x\n", decode_data.setup_packet.default_pipe_setup_packet.wValue.LowByte);
325 FUNCTION_MSG(" High = %02x\n", decode_data.setup_packet.default_pipe_setup_packet.wValue.HiByte);
326 FUNCTION_MSG("wIndex = %04x\n", decode_data.setup_packet.default_pipe_setup_packet.wIndex);
327 FUNCTION_MSG(" Low = %02x\n", decode_data.setup_packet.default_pipe_setup_packet.wIndex.LowByte);
328 FUNCTION_MSG(" High = %02x\n", decode_data.setup_packet.default_pipe_setup_packet.wIndex.HiByte);
329 FUNCTION_MSG("wLength = %04x\n", decode_data.setup_packet.default_pipe_setup_packet.wLength);
330 break;
331 }
332 break;
333 case USB_REQUEST_CLEAR_FEATURE:
334 FUNCTION_MSG(" USB_REQUEST_CLEAR_FEATURE\n");
335 switch (decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.Type)
336 {
337 case BMREQUEST_STANDARD: /* Standard */
338 KdPrint((__DRIVER_NAME " Type=Standard\n"));
339 switch (decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.Recipient)
340 {
341 case BMREQUEST_TO_DEVICE:
342 KdPrint((__DRIVER_NAME " Recipient=Device\n"));
343 switch (decode_data.setup_packet.default_pipe_setup_packet.wValue.W)
344 {
345 case 1: /* DEVICE_REMOTE_WAKEUP */
346 KdPrint((__DRIVER_NAME " Feature=DEVICE_REMOTE_WAKEUP\n"));
347 /* fake this */
348 urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
349 break;
350 default:
351 FUNCTION_MSG(__DRIVER_NAME " Feature=%d (not valid)\n", decode_data.setup_packet.default_pipe_setup_packet.wValue.W);
352 break;
353 }
354 break;
355 default:
356 FUNCTION_MSG(__DRIVER_NAME " Recipient=%d (not valid)\n", decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.Recipient);
357 break;
358 }
359 break;
360 break;
361 case BMREQUEST_CLASS: /* Class */
362 KdPrint((__DRIVER_NAME " Type=Class\n"));
363 switch (decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.Recipient)
364 {
365 case BMREQUEST_TO_OTHER:
366 KdPrint((__DRIVER_NAME " Recipient=Other (port = %d)\n", decode_data.setup_packet.default_pipe_setup_packet.wIndex.LowByte));
367 switch (urb->UrbControlVendorClassRequest.Value)
368 {
369 case PORT_ENABLE:
370 KdPrint((__DRIVER_NAME " PORT_ENABLE\n"));
371 xudd->ports[decode_data.setup_packet.default_pipe_setup_packet.wIndex.LowByte - 1].port_status &= ~(1 << PORT_ENABLE);
372 urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
373 break;
374 case PORT_SUSPEND:
375 KdPrint((__DRIVER_NAME " PORT_SUSPEND (NOOP)\n"));
376 /* do something here */
377 urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
378 break;
379 case C_PORT_CONNECTION:
380 KdPrint((__DRIVER_NAME " C_PORT_CONNECTION\n"));
381 xudd->ports[decode_data.setup_packet.default_pipe_setup_packet.wIndex.LowByte - 1].port_change &= ~(1 << PORT_CONNECTION);
382 urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
383 break;
384 case C_PORT_RESET:
385 KdPrint((__DRIVER_NAME " C_PORT_RESET\n"));
386 xudd->ports[decode_data.setup_packet.default_pipe_setup_packet.wIndex.LowByte - 1].port_change &= ~(1 << PORT_RESET);
387 urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
388 break;
389 default:
390 KdPrint((__DRIVER_NAME " Unknown Value %04X\n", urb->UrbControlVendorClassRequest.Value));
391 break;
392 }
393 KdPrint((__DRIVER_NAME " status = %04x, change = %04x\n",
394 xudd->ports[decode_data.setup_packet.default_pipe_setup_packet.wIndex.LowByte - 1].port_status,
395 xudd->ports[decode_data.setup_packet.default_pipe_setup_packet.wIndex.LowByte - 1].port_change));
396 break;
397 default:
398 FUNCTION_MSG(" Recipient=%d\n", decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.Recipient);
399 break;
400 }
401 break;
402 default:
403 KdPrint((__DRIVER_NAME " Type=%d\n", decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.Type));
404 break;
405 }
406 break;
407 case USB_REQUEST_SET_FEATURE:
408 KdPrint((__DRIVER_NAME " USB_REQUEST_SET_FEATURE\n"));
409 KdPrint((__DRIVER_NAME " SetPortFeature\n"));
410 switch (decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.Type)
411 {
412 case 0: /* Standard */
413 KdPrint((__DRIVER_NAME " Type=Standard\n"));
414 switch (decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.Recipient)
415 {
416 case BMREQUEST_TO_DEVICE:
417 KdPrint((__DRIVER_NAME " Recipient=Device\n"));
418 switch (decode_data.setup_packet.default_pipe_setup_packet.wValue.W)
419 {
420 case 1: /* DEVICE_REMOTE_WAKEUP */
421 KdPrint((__DRIVER_NAME " Feature=DEVICE_REMOTE_WAKEUP\n"));
422 /* fake this */
423 urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
424 break;
425 default:
426 FUNCTION_MSG(__DRIVER_NAME " Feature=%d (not valid)\n", decode_data.setup_packet.default_pipe_setup_packet.wValue.W);
427 break;
428 }
429 break;
430 default:
431 FUNCTION_MSG(__DRIVER_NAME " Recipient=%d (not valid)\n", decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.Recipient);
432 break;
433 }
434 break;
435 case 1: /* Class */
436 KdPrint((__DRIVER_NAME " Type=Class\n"));
437 switch (decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.Recipient)
438 {
439 case BMREQUEST_TO_OTHER:
440 KdPrint((__DRIVER_NAME " Recipient=Other (port = %d)\n", decode_data.setup_packet.default_pipe_setup_packet.wIndex.LowByte));
441 switch (decode_data.setup_packet.default_pipe_setup_packet.wValue.W)
442 {
443 case PORT_ENABLE:
444 KdPrint((__DRIVER_NAME " PORT_ENABLE (NOOP)\n"));
445 /* do something here */
446 urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
447 break;
448 case PORT_SUSPEND:
449 KdPrint((__DRIVER_NAME " PORT_SUSPEND (NOOP)\n"));
450 /* do something here */
451 urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
452 break;
453 case PORT_RESET:
454 KdPrint((__DRIVER_NAME " PORT_RESET\n"));
455 /* just fake the reset by setting the status bit to indicate that the reset is complete*/
456 //xudd->ports[decode_data.setup_packet.default_pipe_setup_packet.wIndex.LowByte - 1].port_status |= (1 << PORT_RESET);
457 //xudd->ports[decode_data.setup_packet.default_pipe_setup_packet.wIndex.LowByte - 1].reset_counter = 10;
458 // TODO: maybe fake a 10ms time here...
459 xudd->ports[decode_data.setup_packet.default_pipe_setup_packet.wIndex.LowByte - 1].port_status &= ~(1 << PORT_RESET);
460 xudd->ports[decode_data.setup_packet.default_pipe_setup_packet.wIndex.LowByte - 1].port_status |= (1 << PORT_ENABLE);
461 xudd->ports[decode_data.setup_packet.default_pipe_setup_packet.wIndex.LowByte - 1].port_change |= (1 << PORT_RESET);
462 urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
463 endpoint = xupdd->usb_device->configs[0]->interfaces[0]->endpoints[0];
464 XenUsbHub_ProcessHubInterruptEvent(endpoint);
465 break;
466 case PORT_POWER:
467 KdPrint((__DRIVER_NAME " PORT_POWER\n"));
468 xudd->ports[decode_data.setup_packet.default_pipe_setup_packet.wIndex.LowByte - 1].port_status |= (1 << PORT_POWER);
469 urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
470 break;
471 default:
472 KdPrint((__DRIVER_NAME " PORT_%04X\n", decode_data.setup_packet.default_pipe_setup_packet.wValue.W));
473 break;
474 }
475 KdPrint((__DRIVER_NAME " status = %04x, change = %04x\n",
476 xudd->ports[urb->UrbControlVendorClassRequest.Index - 1].port_status,
477 xudd->ports[urb->UrbControlVendorClassRequest.Index - 1].port_change));
478 break;
479 default:
480 FUNCTION_MSG(__DRIVER_NAME " Recipient=%d (not valid)\n", decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.Recipient);
481 break;
482 }
483 break;
484 }
485 break;
486 default:
487 FUNCTION_MSG(" USB_REQUEST_%02x\n", (ULONG)decode_data.setup_packet.default_pipe_setup_packet.bRequest);
488 KdPrint((__DRIVER_NAME " TransferBufferLength returned = %d\n", urb->UrbControlDescriptorRequest.TransferBufferLength));
489 break;
490 }
491 break;
492 case URB_FUNCTION_SYNC_RESET_PIPE_AND_CLEAR_STALL:
493 KdPrint((__DRIVER_NAME " URB_FUNCTION_SYNC_RESET_PIPE_AND_CLEAR_STALL\n"));
494 KdPrint((__DRIVER_NAME " PipeHandle = %p\n", urb->UrbPipeRequest.PipeHandle));
495 urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
496 break;
497 case URB_FUNCTION_ABORT_PIPE:
498 KdPrint((__DRIVER_NAME " URB_FUNCTION_ABORT_PIPE\n"));
499 KdPrint((__DRIVER_NAME " PipeHandle = %p\n", urb->UrbPipeRequest.PipeHandle));
500 urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
501 break;
502 case URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER: /* 11.12.4 */
503 #if 0
504 KdPrint((__DRIVER_NAME " URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER\n"));
505 KdPrint((__DRIVER_NAME " PipeHandle = %p\n", urb->UrbBulkOrInterruptTransfer.PipeHandle));
506 KdPrint((__DRIVER_NAME " TransferFlags = %08x\n", urb->UrbBulkOrInterruptTransfer.TransferFlags));
507 KdPrint((__DRIVER_NAME " TransferBufferLength = %d\n", urb->UrbBulkOrInterruptTransfer.TransferBufferLength));
508 KdPrint((__DRIVER_NAME " TransferBuffer = %p\n", urb->UrbBulkOrInterruptTransfer.TransferBuffer));
509 KdPrint((__DRIVER_NAME " TransferBufferMdl = %p\n", urb->UrbBulkOrInterruptTransfer.TransferBufferMDL));
510 #endif
511 endpoint = urb->UrbBulkOrInterruptTransfer.PipeHandle;
512 //WdfSpinLockAcquire(endpoint->lock);
513 WdfRequestForwardToIoQueue(request, endpoint->queue);
514 XenUsbHub_ProcessHubInterruptEvent(endpoint);
515 //WdfSpinLockRelease(endpoint->lock);
516 //FUNCTION_EXIT();
517 return;
519 #if 0 // not using this bit
520 case URB_FUNCTION_GET_DESCRIPTOR_FROM_DEVICE:
521 //case URB_FUNCTION_GET_DESCRIPTOR_FROM_ENDPOINT:
522 //case URB_FUNCTION_GET_DESCRIPTOR_FROM_INTERFACE:
523 KdPrint((__DRIVER_NAME " URB_FUNCTION_GET_DESCRIPTOR_FROM_XXX\n"));
524 KdPrint((__DRIVER_NAME " Reserved = %p\n", urb->UrbControlDescriptorRequest.Reserved));
525 KdPrint((__DRIVER_NAME " Reserved0 = %08X\n", urb->UrbControlDescriptorRequest.Reserved0));
526 KdPrint((__DRIVER_NAME " TransferBufferLength = %d\n", urb->UrbControlDescriptorRequest.TransferBufferLength));
527 KdPrint((__DRIVER_NAME " TransferBuffer = %p\n", urb->UrbControlDescriptorRequest.TransferBuffer));
528 KdPrint((__DRIVER_NAME " TransferBufferMDL = %p\n", urb->UrbControlDescriptorRequest.TransferBufferMDL));
529 KdPrint((__DRIVER_NAME " UrbLink = %p\n", urb->UrbControlDescriptorRequest.UrbLink));
530 KdPrint((__DRIVER_NAME " Index = %d\n", (int)urb->UrbControlDescriptorRequest.Index));
531 KdPrint((__DRIVER_NAME " DescriptorType = %d\n", (int)urb->UrbControlDescriptorRequest.DescriptorType));
532 KdPrint((__DRIVER_NAME " LanguageId = %04x\n", urb->UrbControlDescriptorRequest.LanguageId));
533 KdPrint((__DRIVER_NAME " Reserved2 = %04X\n", urb->UrbControlDescriptorRequest.Reserved2));
534 switch (urb->UrbControlDescriptorRequest.DescriptorType)
535 {
536 case USB_DEVICE_DESCRIPTOR_TYPE:
537 KdPrint((__DRIVER_NAME " USB_DEVICE_DESCRIPTOR_TYPE\n"));
538 memcpy(urb->UrbControlDescriptorRequest.TransferBuffer, &usb_device->device_descriptor, sizeof(USB_DEVICE_DESCRIPTOR));
539 urb->UrbControlDescriptorRequest.TransferBufferLength = sizeof(USB_DEVICE_DESCRIPTOR);
540 KdPrint((__DRIVER_NAME " TransferBufferLength returned = %d\n", urb->UrbControlDescriptorRequest.TransferBufferLength));
541 break;
542 case USB_CONFIGURATION_DESCRIPTOR_TYPE:
543 {
544 xenusb_config_t *usb_config;
545 PUCHAR ptr;
547 KdPrint((__DRIVER_NAME " USB_CONFIGURATION_DESCRIPTOR_TYPE\n"));
548 usb_config = usb_device->active_config;
549 ptr = (PUCHAR)decode_data.buffer;
550 memcpy(ptr, &usb_config->config_descriptor, sizeof(USB_CONFIGURATION_DESCRIPTOR));
551 ptr += sizeof(USB_CONFIGURATION_DESCRIPTOR);
552 ((PUSB_CONFIGURATION_DESCRIPTOR)decode_data.buffer)->wTotalLength = sizeof(USB_CONFIGURATION_DESCRIPTOR);
553 if (urb->UrbControlDescriptorRequest.TransferBufferLength > 9)
554 {
555 for (i = 0; i < usb_config->config_descriptor.bNumInterfaces; i++)
556 {
557 memcpy(ptr, &usb_config->interfaces[i]->interface_descriptor, sizeof(USB_INTERFACE_DESCRIPTOR));
558 KdPrint((__DRIVER_NAME " bInterfaceClass = %02x\n", ((PUSB_INTERFACE_DESCRIPTOR)ptr)->bInterfaceClass));
559 ptr += sizeof(USB_INTERFACE_DESCRIPTOR);
560 ((PUSB_CONFIGURATION_DESCRIPTOR)decode_data.buffer)->wTotalLength += sizeof(USB_INTERFACE_DESCRIPTOR);
561 for (j = 0; j < usb_config->interfaces[i]->interface_descriptor.bNumEndpoints; j++)
562 {
563 memcpy(ptr, &usb_config->interfaces[i]->endpoints[j]->endpoint_descriptor, sizeof(USB_ENDPOINT_DESCRIPTOR));
564 ptr += sizeof(USB_ENDPOINT_DESCRIPTOR);
565 ((PUSB_CONFIGURATION_DESCRIPTOR)decode_data.buffer)->wTotalLength += sizeof(USB_ENDPOINT_DESCRIPTOR);
566 }
567 }
568 }
569 *decode_data.length = ((PUSB_CONFIGURATION_DESCRIPTOR)decode_data.buffer)->wTotalLength;
570 if (*decode_data.length == 9)
571 ((PUSB_CONFIGURATION_DESCRIPTOR)decode_data.buffer)->wTotalLength = 32;
572 KdPrint((__DRIVER_NAME " TransferBufferLength returned = %d\n", urb->UrbControlDescriptorRequest.TransferBufferLength));
573 break;
574 }
575 default:
576 KdPrint((__DRIVER_NAME " UNKNOWN_DESCRIPTOR_TYPE\n"));
577 break;
578 }
579 urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
580 break;
581 case URB_FUNCTION_GET_STATUS_FROM_DEVICE:
582 KdPrint((__DRIVER_NAME " URB_FUNCTION_GET_STATUS_FROM_DEVICE\n"));
583 KdPrint((__DRIVER_NAME " TransferBufferLength = %d\n", urb->UrbControlGetStatusRequest.TransferBufferLength));
584 KdPrint((__DRIVER_NAME " TransferBuffer = %p\n", urb->UrbControlGetStatusRequest.TransferBuffer));
585 KdPrint((__DRIVER_NAME " TransferBufferMDL = %p\n", urb->UrbControlGetStatusRequest.TransferBufferMDL));
586 KdPrint((__DRIVER_NAME " Index = %04x\n", urb->UrbControlGetStatusRequest.Index));
587 if (urb->UrbControlGetStatusRequest.Index == 0)
588 {
589 urb->UrbControlGetStatusRequest.TransferBufferLength = 2;
590 *(PUSHORT)urb->UrbControlGetStatusRequest.TransferBuffer = 0x0003;
591 urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
592 }
593 else
594 {
595 KdPrint((__DRIVER_NAME " Unknown Index\n"));
596 urb->UrbHeader.Status = USBD_STATUS_INVALID_URB_FUNCTION;
597 }
598 break;
599 case URB_FUNCTION_CLASS_DEVICE:
600 #if 1
601 KdPrint((__DRIVER_NAME " URB_FUNCTION_CLASS_DEVICE\n"));
602 KdPrint((__DRIVER_NAME " TransferBufferLength = %d\n", urb->UrbControlVendorClassRequest.TransferBufferLength));
603 KdPrint((__DRIVER_NAME " TransferBuffer = %p\n", urb->UrbControlVendorClassRequest.TransferBuffer));
604 KdPrint((__DRIVER_NAME " TransferBufferMDL = %p\n", urb->UrbControlVendorClassRequest.TransferBufferMDL));
605 KdPrint((__DRIVER_NAME " RequestTypeReservedBits = %02x\n", urb->UrbControlVendorClassRequest.RequestTypeReservedBits));
606 KdPrint((__DRIVER_NAME " Request = %02x\n", urb->UrbControlVendorClassRequest.Request));
607 KdPrint((__DRIVER_NAME " Value = %04x\n", urb->UrbControlVendorClassRequest.Value));
608 KdPrint((__DRIVER_NAME " Index = %04x\n", urb->UrbControlVendorClassRequest.Index));
609 #endif
610 switch (urb->UrbControlVendorClassRequest.Request)
611 {
612 case USB_REQUEST_GET_DESCRIPTOR:
613 KdPrint((__DRIVER_NAME " URB_FUNCTION_CLASS_DEVICE\n"));
614 KdPrint((__DRIVER_NAME " TransferBufferLength = %d\n", urb->UrbControlVendorClassRequest.TransferBufferLength));
615 KdPrint((__DRIVER_NAME " TransferBuffer = %p\n", urb->UrbControlVendorClassRequest.TransferBuffer));
616 KdPrint((__DRIVER_NAME " TransferBufferMDL = %p\n", urb->UrbControlVendorClassRequest.TransferBufferMDL));
617 KdPrint((__DRIVER_NAME " RequestTypeReservedBits = %02x\n", urb->UrbControlVendorClassRequest.RequestTypeReservedBits));
618 KdPrint((__DRIVER_NAME " Request = %02x\n", urb->UrbControlVendorClassRequest.Request));
619 KdPrint((__DRIVER_NAME " Value = %04x\n", urb->UrbControlVendorClassRequest.Value));
620 KdPrint((__DRIVER_NAME " Index = %04x\n", urb->UrbControlVendorClassRequest.Index));
621 KdPrint((__DRIVER_NAME " USB_REQUEST_GET_DESCRIPTOR\n"));
622 switch (urb->UrbControlVendorClassRequest.Value >> 8)
623 {
624 case 0x00:
625 #if 0
626 memcpy(urb->UrbControlVendorClassRequest.TransferBuffer, &usb_device->device_descriptor, sizeof(USB_DEVICE_DESCRIPTOR));
627 urb->UrbControlVendorClassRequest.TransferBufferLength = sizeof(USB_DEVICE_DESCRIPTOR);
628 urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
629 break;
630 #endif
631 case 0x29: // Hub Descriptor
632 KdPrint((__DRIVER_NAME " HUB_DESCRIPTOR\n"));
633 uhd = urb->UrbControlVendorClassRequest.TransferBuffer;
634 urb->UrbControlVendorClassRequest.TransferBufferLength = FIELD_OFFSET(USB_HUB_DESCRIPTOR, bRemoveAndPowerMask[0]) + 2 + 1;
635 uhd->bDescriptorLength = (UCHAR)urb->UrbControlVendorClassRequest.TransferBufferLength;
636 uhd->bDescriptorType = 0x29;
637 uhd->bNumberOfPorts = xudd->num_ports;
638 uhd->wHubCharacteristics = 0x0012; // no power switching no overcurrent protection
639 uhd->bPowerOnToPowerGood = 1; // 2ms units
640 uhd->bHubControlCurrent = 0;
641 // DeviceRemovable bits (includes an extra bit at the start)
642 uhd->bRemoveAndPowerMask[0] = 0;
643 uhd->bRemoveAndPowerMask[1] = 0;
644 // PortPwrCtrlMask
645 uhd->bRemoveAndPowerMask[2] = 0xFF;
646 urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
647 break;
648 default:
649 KdPrint((__DRIVER_NAME " Unknown Value %02x\n", urb->UrbControlVendorClassRequest.Value >> 8));
650 urb->UrbHeader.Status = USBD_STATUS_INVALID_URB_FUNCTION;
651 break;
652 }
653 break;
654 case USB_REQUEST_GET_STATUS:
655 KdPrint((__DRIVER_NAME " TransferFlags = %08x\n", urb->UrbControlVendorClassRequest.TransferFlags));
656 KdPrint((__DRIVER_NAME " TransferBufferLength = %d\n", urb->UrbControlVendorClassRequest.TransferBufferLength));
657 KdPrint((__DRIVER_NAME " TransferBuffer = %p\n", urb->UrbControlVendorClassRequest.TransferBuffer));
658 KdPrint((__DRIVER_NAME " TransferBufferMDL = %p\n", urb->UrbControlVendorClassRequest.TransferBufferMDL));
659 KdPrint((__DRIVER_NAME " RequestTypeReservedBits = %02x\n", urb->UrbControlVendorClassRequest.RequestTypeReservedBits));
660 KdPrint((__DRIVER_NAME " Request = %02x\n", urb->UrbControlVendorClassRequest.Request));
661 KdPrint((__DRIVER_NAME " Value = %04x\n", urb->UrbControlVendorClassRequest.Value));
662 KdPrint((__DRIVER_NAME " Index = %04x\n", urb->UrbControlVendorClassRequest.Index));
663 KdPrint((__DRIVER_NAME " USB_REQUEST_GET_STATUS\n"));
664 // Check that RequestTypeReservedBits == 0xA0
665 KdPrint((__DRIVER_NAME " GetHubStatus\n"));
666 /* hub status */
667 // shoud be able to get this field from somewhere else...
668 ((PUSHORT)urb->UrbControlVendorClassRequest.TransferBuffer)[0] = 0x0000;
669 ((PUSHORT)urb->UrbControlVendorClassRequest.TransferBuffer)[1] = 0x0000; /* no change occurred */
670 urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
671 break;
672 case USB_REQUEST_CLEAR_FEATURE:
673 KdPrint((__DRIVER_NAME " TransferFlags = %08x\n", urb->UrbControlVendorClassRequest.TransferFlags));
674 KdPrint((__DRIVER_NAME " TransferBufferLength = %d\n", urb->UrbControlVendorClassRequest.TransferBufferLength));
675 KdPrint((__DRIVER_NAME " TransferBuffer = %p\n", urb->UrbControlVendorClassRequest.TransferBuffer));
676 KdPrint((__DRIVER_NAME " TransferBufferMDL = %p\n", urb->UrbControlVendorClassRequest.TransferBufferMDL));
677 KdPrint((__DRIVER_NAME " RequestTypeReservedBits = %02x\n", urb->UrbControlVendorClassRequest.RequestTypeReservedBits));
678 KdPrint((__DRIVER_NAME " Request = %02x\n", urb->UrbControlVendorClassRequest.Request));
679 KdPrint((__DRIVER_NAME " Value = %04x\n", urb->UrbControlVendorClassRequest.Value));
680 KdPrint((__DRIVER_NAME " Index = %04x\n", urb->UrbControlVendorClassRequest.Index));
681 KdPrint((__DRIVER_NAME " USB_REQUEST_CLEAR_FEATURE\n"));
682 urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
683 break;
684 default:
685 KdPrint((__DRIVER_NAME " TransferFlags = %08x\n", urb->UrbControlVendorClassRequest.TransferFlags));
686 KdPrint((__DRIVER_NAME " TransferBufferLength = %d\n", urb->UrbControlVendorClassRequest.TransferBufferLength));
687 KdPrint((__DRIVER_NAME " TransferBuffer = %p\n", urb->UrbControlVendorClassRequest.TransferBuffer));
688 KdPrint((__DRIVER_NAME " TransferBufferMDL = %p\n", urb->UrbControlVendorClassRequest.TransferBufferMDL));
689 KdPrint((__DRIVER_NAME " RequestTypeReservedBits = %02x\n", urb->UrbControlVendorClassRequest.RequestTypeReservedBits));
690 KdPrint((__DRIVER_NAME " Request = %02x\n", urb->UrbControlVendorClassRequest.Request));
691 KdPrint((__DRIVER_NAME " Value = %04x\n", urb->UrbControlVendorClassRequest.Value));
692 KdPrint((__DRIVER_NAME " Index = %04x\n", urb->UrbControlVendorClassRequest.Index));
693 KdPrint((__DRIVER_NAME " USB_REQUEST_%02x\n", urb->UrbControlVendorClassRequest.Request));
694 urb->UrbHeader.Status = USBD_STATUS_INVALID_URB_FUNCTION;
695 break;
696 }
697 break;
698 case URB_FUNCTION_CLASS_OTHER:
699 KdPrint((__DRIVER_NAME " URB_FUNCTION_CLASS_OTHER\n"));
700 KdPrint((__DRIVER_NAME " TransferFlags = %08x\n", urb->UrbControlVendorClassRequest.TransferFlags));
701 KdPrint((__DRIVER_NAME " TransferBufferLength = %d\n", urb->UrbControlVendorClassRequest.TransferBufferLength));
702 KdPrint((__DRIVER_NAME " TransferBuffer = %p\n", urb->UrbControlVendorClassRequest.TransferBuffer));
703 KdPrint((__DRIVER_NAME " TransferBufferMdl = %p\n", urb->UrbControlVendorClassRequest.TransferBufferMDL));
704 KdPrint((__DRIVER_NAME " RequestTypeReservedBits = %02x\n", urb->UrbControlVendorClassRequest.RequestTypeReservedBits));
705 KdPrint((__DRIVER_NAME " Request = %02x\n", urb->UrbControlVendorClassRequest.Request));
706 KdPrint((__DRIVER_NAME " Value = %04x\n", urb->UrbControlVendorClassRequest.Value));
707 KdPrint((__DRIVER_NAME " Index = %04x\n", urb->UrbControlVendorClassRequest.Index));
708 switch (urb->UrbControlVendorClassRequest.Request)
709 {
710 case USB_REQUEST_GET_STATUS:
711 /* port status - 11.24.2.7.1 */
712 KdPrint((__DRIVER_NAME " USB_REQUEST_GET_STATUS\n"));
713 KdPrint((__DRIVER_NAME " GetHubStatus\n"));
714 ((PUSHORT)urb->UrbControlVendorClassRequest.TransferBuffer)[0] = xudd->ports[urb->UrbControlVendorClassRequest.Index - 1].port_status;
715 ((PUSHORT)urb->UrbControlVendorClassRequest.TransferBuffer)[1] = xudd->ports[urb->UrbControlVendorClassRequest.Index - 1].port_change;
716 break;
717 case USB_REQUEST_SET_FEATURE:
718 KdPrint((__DRIVER_NAME " USB_REQUEST_SET_FEATURE\n"));
719 KdPrint((__DRIVER_NAME " SetPortFeature\n"));
720 switch (urb->UrbControlVendorClassRequest.Value)
721 {
722 case PORT_ENABLE:
723 KdPrint((__DRIVER_NAME " PORT_ENABLE\n"));
724 /* do something here */
725 break;
726 case PORT_RESET:
727 KdPrint((__DRIVER_NAME " PORT_RESET\n"));
728 /* just fake the reset */
729 xudd->ports[urb->UrbControlVendorClassRequest.Index - 1].port_change |= (1 << PORT_RESET);
730 break;
731 default:
732 KdPrint((__DRIVER_NAME " Unknown Value %04X\n", urb->UrbControlVendorClassRequest.Value));
733 break;
734 }
735 KdPrint((__DRIVER_NAME " status = %04x, change = %04x\n",
736 xudd->ports[urb->UrbControlVendorClassRequest.Index - 1].port_status,
737 xudd->ports[urb->UrbControlVendorClassRequest.Index - 1].port_change));
738 break;
739 case USB_REQUEST_CLEAR_FEATURE:
740 KdPrint((__DRIVER_NAME " USB_REQUEST_CLEAR_FEATURE\n"));
741 KdPrint((__DRIVER_NAME " ClearPortFeature\n"));
742 switch (urb->UrbControlVendorClassRequest.Value)
743 {
744 case C_PORT_CONNECTION:
745 KdPrint((__DRIVER_NAME " C_PORT_CONNECTION\n"));
746 xudd->ports[urb->UrbControlVendorClassRequest.Index - 1].port_change &= ~(1 << PORT_CONNECTION);
747 break;
748 case C_PORT_RESET:
749 KdPrint((__DRIVER_NAME " C_PORT_RESET\n"));
750 xudd->ports[urb->UrbControlVendorClassRequest.Index - 1].port_change &= ~(1 << PORT_RESET);
751 break;
752 default:
753 KdPrint((__DRIVER_NAME " Unknown Value %04X\n", urb->UrbControlVendorClassRequest.Value));
754 break;
755 }
756 KdPrint((__DRIVER_NAME " status = %04x, change = %04x\n",
757 xudd->ports[urb->UrbControlVendorClassRequest.Index - 1].port_status,
758 xudd->ports[urb->UrbControlVendorClassRequest.Index - 1].port_change));
759 break;
760 default:
761 KdPrint((__DRIVER_NAME " USB_REQUEST_%02x\n", urb->UrbControlVendorClassRequest.Request));
762 break;
763 }
764 //urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
765 urb->UrbHeader.Status = USBD_STATUS_INVALID_URB_FUNCTION;
766 break;
767 #endif
768 default:
769 FUNCTION_MSG("URB_FUNCTION_%04x\n", urb->UrbHeader.Function);
770 if (decode_retval != URB_DECODE_NOT_CONTROL)
771 {
772 FUNCTION_MSG("bmRequestType = %02x\n", decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.B);
773 FUNCTION_MSG(" Recipient = %x\n", decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.Recipient);
774 FUNCTION_MSG(" Type = %x\n", decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.Type);
775 FUNCTION_MSG(" Dir = %x\n", decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.Dir);
776 FUNCTION_MSG("bRequest = %02x\n", decode_data.setup_packet.default_pipe_setup_packet.bRequest);
777 FUNCTION_MSG("wValue = %04x\n", decode_data.setup_packet.default_pipe_setup_packet.wValue.W);
778 FUNCTION_MSG(" Low = %02x\n", decode_data.setup_packet.default_pipe_setup_packet.wValue.LowByte);
779 FUNCTION_MSG(" High = %02x\n", decode_data.setup_packet.default_pipe_setup_packet.wValue.HiByte);
780 FUNCTION_MSG("wIndex = %04x\n", decode_data.setup_packet.default_pipe_setup_packet.wIndex);
781 FUNCTION_MSG(" Low = %02x\n", decode_data.setup_packet.default_pipe_setup_packet.wIndex.LowByte);
782 FUNCTION_MSG(" High = %02x\n", decode_data.setup_packet.default_pipe_setup_packet.wIndex.HiByte);
783 FUNCTION_MSG("wLength = %04x\n", decode_data.setup_packet.default_pipe_setup_packet.wLength);
784 }
785 urb->UrbHeader.Status = USBD_STATUS_INVALID_URB_FUNCTION;
786 break;
787 }
788 if (urb->UrbHeader.Status == USBD_STATUS_SUCCESS)
789 {
790 //FUNCTION_MSG("Calling WdfRequestCompletestatus with status = %08x\n", STATUS_SUCCESS);
791 WdfRequestComplete(request, STATUS_SUCCESS);
792 }
793 else
794 {
795 FUNCTION_MSG("Calling WdfRequestCompletestatus with status = %08x\n", STATUS_UNSUCCESSFUL);
796 WdfRequestComplete(request, STATUS_UNSUCCESSFUL);
797 }
799 //FUNCTION_EXIT();
800 return;
801 }