win-pvdrivers

view xenusb/xenusb_hub.c @ 939:b132eda21caa

Fix compile warnings under x32
author James Harper <james.harper@bendigoit.com.au>
date Mon Jun 27 00:05:47 2011 +1000 (2011-06-27)
parents f03bcaa67233
children 05c557d14752
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"
21 #include <stdlib.h>
22 #include <usbioctl.h>
24 typedef struct _USB_START_FAILDATA {
25 ULONG LengthInBytes;
26 NTSTATUS NtStatus;
27 USBD_STATUS UsbdStatus;
28 ULONG ConnectStatus;
29 UCHAR DriverData[4];
30 } USB_START_FAILDATA, *PUSB_START_FAILDATA;
32 #pragma warning(disable: 4127) // conditional expression is constant
34 static EVT_WDF_DEVICE_D0_ENTRY XenUsbHub_EvtDeviceD0Entry;
35 static EVT_WDF_DEVICE_D0_EXIT XenUsbHub_EvtDeviceD0Exit;
36 static EVT_WDF_DEVICE_PREPARE_HARDWARE XenUsbHub_EvtDevicePrepareHardware;
37 static EVT_WDF_DEVICE_RELEASE_HARDWARE XenUsbHub_EvtDeviceReleaseHardware;
38 static EVT_WDF_DEVICE_USAGE_NOTIFICATION XenUsbHub_EvtDeviceUsageNotification;
39 static EVT_WDF_TIMER XenUsbHub_HubInterruptTimer;
40 static EVT_WDF_IO_QUEUE_IO_INTERNAL_DEVICE_CONTROL XenUsbHub_EvtIoInternalDeviceControl;
41 static EVT_WDF_IO_QUEUE_IO_DEVICE_CONTROL XenUsbHub_EvtIoDeviceControl;
42 static EVT_WDF_IO_QUEUE_IO_DEFAULT XenUsbHub_EvtIoDefault;
43 static USB_BUSIFFN_CREATE_USB_DEVICE XenUsbHub_UBIH_CreateUsbDevice;
44 static USB_BUSIFFN_INITIALIZE_USB_DEVICE XenUsbHub_UBIH_InitializeUsbDevice;
45 static USB_BUSIFFN_GET_USB_DESCRIPTORS XenUsbHub_UBIH_GetUsbDescriptors;
46 static USB_BUSIFFN_REMOVE_USB_DEVICE XenUsbHub_UBIH_RemoveUsbDevice;
47 static USB_BUSIFFN_RESTORE_DEVICE XenUsbHub_UBIH_RestoreUsbDevice;
48 static USB_BUSIFFN_GET_POTRTHACK_FLAGS XenUsbHub_UBIH_GetPortHackFlags;
49 static USB_BUSIFFN_GET_DEVICE_INFORMATION XenUsbHub_UBIH_QueryDeviceInformation;
50 static USB_BUSIFFN_GET_CONTROLLER_INFORMATION XenUsbHub_UBIH_GetControllerInformation;
51 static USB_BUSIFFN_CONTROLLER_SELECTIVE_SUSPEND XenUsbHub_UBIH_ControllerSelectiveSuspend;
52 static USB_BUSIFFN_GET_EXTENDED_HUB_INFO XenUsbHub_UBIH_GetExtendedHubInformation;
53 static USB_BUSIFFN_GET_ROOTHUB_SYM_NAME XenUsbHub_UBIH_GetRootHubSymbolicName;
54 static USB_BUSIFFN_GET_DEVICE_BUSCONTEXT XenUsbHub_UBIH_GetDeviceBusContext;
55 static USB_BUSIFFN_INITIALIZE_20HUB XenUsbHub_UBIH_Initialize20Hub;
56 static USB_BUSIFFN_ROOTHUB_INIT_NOTIFY XenUsbHub_UBIH_RootHubInitNotification;
57 static USB_BUSIFFN_FLUSH_TRANSFERS XenUsbHub_UBIH_FlushTransfers;
58 static USB_BUSIFFN_SET_DEVHANDLE_DATA XenUsbHub_UBIH_SetDeviceHandleData;
60 static VOID
61 XenUsbHub_EvtIoDefault(
62 WDFQUEUE queue,
63 WDFREQUEST request)
64 {
65 NTSTATUS status;
66 WDF_REQUEST_PARAMETERS parameters;
68 FUNCTION_ENTER();
70 UNREFERENCED_PARAMETER(queue);
72 status = STATUS_UNSUCCESSFUL;
74 WDF_REQUEST_PARAMETERS_INIT(&parameters);
75 WdfRequestGetParameters(request, &parameters);
77 switch (parameters.Type)
78 {
79 case WdfRequestTypeCreate:
80 KdPrint((__DRIVER_NAME " WdfRequestTypeCreate\n"));
81 break;
82 case WdfRequestTypeClose:
83 KdPrint((__DRIVER_NAME " WdfRequestTypeClose\n"));
84 break;
85 case WdfRequestTypeRead:
86 KdPrint((__DRIVER_NAME " WdfRequestTypeRead\n"));
87 break;
88 case WdfRequestTypeWrite:
89 KdPrint((__DRIVER_NAME " WdfRequestTypeWrite\n"));
90 break;
91 case WdfRequestTypeDeviceControl:
92 KdPrint((__DRIVER_NAME " WdfRequestTypeDeviceControl\n"));
94 break;
95 case WdfRequestTypeDeviceControlInternal:
96 KdPrint((__DRIVER_NAME " WdfRequestTypeDeviceControlInternal\n"));
97 break;
98 default:
99 KdPrint((__DRIVER_NAME " Unknown type %x\n", parameters.Type));
100 break;
101 }
102 FUNCTION_MSG("Calling WdfRequestComplete with status = %08x\n");
103 WdfRequestComplete(request, status);
105 FUNCTION_EXIT();
106 }
108 static NTSTATUS
109 XenUsbHub_BusIrpCompletionRoutine(
110 PDEVICE_OBJECT device_object,
111 PIRP irp,
112 PVOID context)
113 {
114 WDFREQUEST request = context;
116 UNREFERENCED_PARAMETER(device_object);
118 FUNCTION_ENTER();
120 FUNCTION_MSG("Calling WdfRequestComplete with status = %08x\n");
121 WdfRequestCompleteWithInformation(request, irp->IoStatus.Status, irp->IoStatus.Information);
122 IoFreeIrp(irp);
124 FUNCTION_EXIT();
126 return STATUS_MORE_PROCESSING_REQUIRED;
127 }
129 static VOID
130 XenUsbHub_EvtIoDeviceControl(
131 WDFQUEUE queue,
132 WDFREQUEST request,
133 size_t output_buffer_length,
134 size_t input_buffer_length,
135 ULONG io_control_code)
136 {
137 NTSTATUS status;
138 //WDFDEVICE device = WdfIoQueueGetDevice(queue);
139 //PXENUSB_PDO_DEVICE_DATA xupdd = GetXupdd(device);
140 //WDF_REQUEST_PARAMETERS wrp;
141 //PURB urb;
142 //xenusb_device_t *usb_device;
144 UNREFERENCED_PARAMETER(queue);
145 UNREFERENCED_PARAMETER(input_buffer_length);
146 UNREFERENCED_PARAMETER(output_buffer_length);
148 FUNCTION_ENTER();
150 status = STATUS_UNSUCCESSFUL;
152 //WDF_REQUEST_PARAMETERS_INIT(&wrp);
153 //WdfRequestGetParameters(request, &wrp);
155 // these are in api\usbioctl.h
156 switch(io_control_code)
157 {
158 case IOCTL_USB_GET_NODE_INFORMATION:
159 KdPrint((__DRIVER_NAME " IOCTL_USB_GET_NODE_INFORMATION\n"));
160 break;
161 case IOCTL_USB_GET_NODE_CONNECTION_INFORMATION:
162 KdPrint((__DRIVER_NAME " IOCTL_USB_GET_NODE_CONNECTION_INFORMATION\n"));
163 break;
164 case IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION:
165 KdPrint((__DRIVER_NAME " IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION\n"));
166 break;
167 case IOCTL_USB_GET_NODE_CONNECTION_NAME:
168 KdPrint((__DRIVER_NAME " IOCTL_USB_GET_NODE_CONNECTION_NAME\n"));
169 break;
170 case IOCTL_USB_DIAG_IGNORE_HUBS_ON:
171 KdPrint((__DRIVER_NAME " IOCTL_USB_DIAG_IGNORE_HUBS_ON\n"));
172 break;
173 case IOCTL_USB_DIAG_IGNORE_HUBS_OFF:
174 KdPrint((__DRIVER_NAME " IOCTL_USB_DIAG_IGNORE_HUBS_OFF\n"));
175 break;
176 case IOCTL_USB_GET_NODE_CONNECTION_DRIVERKEY_NAME:
177 KdPrint((__DRIVER_NAME " IOCTL_USB_GET_NODE_CONNECTION_DRIVERKEY_NAME\n"));
178 break;
179 case IOCTL_USB_GET_HUB_CAPABILITIES:
180 KdPrint((__DRIVER_NAME " IOCTL_USB_GET_HUB_CAPABILITIES\n"));
181 break;
182 case IOCTL_USB_HUB_CYCLE_PORT:
183 KdPrint((__DRIVER_NAME " IOCTL_USB_HUB_CYCLE_PORT\n"));
184 break;
185 case IOCTL_USB_GET_NODE_CONNECTION_ATTRIBUTES:
186 KdPrint((__DRIVER_NAME " IOCTL_USB_GET_NODE_CONNECTION_ATTRIBUTES\n"));
187 break;
188 case IOCTL_USB_GET_NODE_CONNECTION_INFORMATION_EX:
189 KdPrint((__DRIVER_NAME " IOCTL_USB_GET_NODE_CONNECTION_INFORMATION_EX\n"));
190 break;
191 case IOCTL_GET_HCD_DRIVERKEY_NAME:
192 KdPrint((__DRIVER_NAME " IOCTL_GET_HCD_DRIVERKEY_NAME (***)\n"));
193 break;
194 default:
195 KdPrint((__DRIVER_NAME " Unknown IOCTL %08x\n", io_control_code));
196 break;
197 }
198 FUNCTION_MSG("Calling WdfRequestComplete with status = %08x\n");
199 WdfRequestComplete(request, status);
201 FUNCTION_EXIT();
202 }
204 static VOID
205 XenUsbHub_EvtIoInternalDeviceControl(
206 WDFQUEUE queue,
207 WDFREQUEST request,
208 size_t output_buffer_length,
209 size_t input_buffer_length,
210 ULONG io_control_code)
211 {
212 NTSTATUS status;
213 WDFDEVICE device = WdfIoQueueGetDevice(queue);
214 PXENUSB_PDO_DEVICE_DATA xupdd = GetXupdd(device);
215 WDF_REQUEST_PARAMETERS wrp;
216 PURB urb;
217 #if (NTDDI_VERSION >= NTDDI_VISTA)
218 PUSB_START_FAILDATA usfd;
219 PHUB_DEVICE_CONFIG_INFO hdci;
220 PUSB_TOPOLOGY_ADDRESS uta;
221 PUSB_HUB_NAME uhn;
222 size_t length;
223 #endif
224 xenusb_device_t *usb_device;
226 UNREFERENCED_PARAMETER(input_buffer_length);
227 UNREFERENCED_PARAMETER(output_buffer_length);
229 //FUNCTION_ENTER();
231 status = STATUS_UNSUCCESSFUL;
233 WDF_REQUEST_PARAMETERS_INIT(&wrp);
234 WdfRequestGetParameters(request, &wrp);
236 // these are in api\usbioctl.h
237 switch(io_control_code)
238 {
239 case IOCTL_INTERNAL_USB_CYCLE_PORT:
240 KdPrint((__DRIVER_NAME " IOCTL_INTERNAL_USB_CYCLE_PORT\n"));
241 break;
242 case IOCTL_INTERNAL_USB_ENABLE_PORT:
243 KdPrint((__DRIVER_NAME " IOCTL_INTERNAL_USB_ENABLE_PORT\n"));
244 break;
245 case IOCTL_INTERNAL_USB_GET_BUS_INFO:
246 KdPrint((__DRIVER_NAME " IOCTL_INTERNAL_USB_GET_BUS_INFO\n"));
247 break;
248 case IOCTL_INTERNAL_USB_GET_CONTROLLER_NAME:
249 KdPrint((__DRIVER_NAME " IOCTL_INTERNAL_USB_GET_CONTROLLER_NAME\n"));
250 break;
251 case IOCTL_INTERNAL_USB_GET_HUB_COUNT:
252 KdPrint((__DRIVER_NAME " IOCTL_INTERNAL_USB_GET_HUB_COUNT\n"));
253 KdPrint((__DRIVER_NAME " Count before increment = %p\n", *(PULONG)wrp.Parameters.Others.Arg1));
254 (*(PULONG)wrp.Parameters.Others.Arg1)++;
255 status = STATUS_SUCCESS;
256 break;
257 #if (NTDDI_VERSION >= NTDDI_VISTA)
258 case IOCTL_INTERNAL_USB_GET_HUB_NAME:
259 KdPrint((__DRIVER_NAME " IOCTL_INTERNAL_USB_GET_HUB_NAME\n"));
260 status = WdfRequestRetrieveOutputBuffer(request, output_buffer_length, (PVOID *)&uhn, &length);
261 uhn->ActualLength = sizeof(USB_HUB_NAME);
262 uhn->HubName[0] = 0;
263 status = STATUS_SUCCESS;
264 break;
265 #endif
266 case IOCTL_INTERNAL_USB_GET_PORT_STATUS:
267 //FUNCTION_MSG("IOCTL_INTERNAL_USB_GET_PORT_STATUS\n");
268 *(PULONG)wrp.Parameters.Others.Arg1 = USBD_PORT_ENABLED | USBD_PORT_CONNECTED; /* enabled and connected */
269 status = STATUS_SUCCESS;
270 break;
271 case IOCTL_INTERNAL_USB_GET_ROOTHUB_PDO:
272 KdPrint((__DRIVER_NAME " IOCTL_INTERNAL_USB_GET_ROOTHUB_PDO\n"));
273 KdPrint((__DRIVER_NAME " WdfDeviceWdmGetPhysicalDevice(device) = %p\n", WdfDeviceWdmGetPhysicalDevice(device)));
274 //KdPrint((__DRIVER_NAME " IoGetAttachedDevice(WdfDeviceWdmGetDeviceObject(device)) = %p\n", IoGetAttachedDevice(WdfDeviceWdmGetDeviceObject(device))));
275 *(PVOID *)wrp.Parameters.Others.Arg1 = WdfDeviceWdmGetPhysicalDevice(device);
276 //*(PVOID *)wrp.Parameters.Others.Arg2 = IoGetAttachedDevice(WdfDeviceWdmGetDeviceObject(device));
277 *(PVOID *)wrp.Parameters.Others.Arg2 = IoGetAttachedDevice(WdfDeviceWdmGetDeviceObject(xupdd->wdf_device_bus_fdo));
278 status = STATUS_SUCCESS;
279 break;
280 case IOCTL_INTERNAL_USB_RESET_PORT:
281 KdPrint((__DRIVER_NAME " IOCTL_INTERNAL_USB_RESET_PORT\n"));
282 break;
283 case IOCTL_INTERNAL_USB_SUBMIT_IDLE_NOTIFICATION:
284 KdPrint((__DRIVER_NAME " IOCTL_INTERNAL_USB_SUBMIT_IDLE_NOTIFICATION\n"));
285 break;
286 case IOCTL_INTERNAL_USB_SUBMIT_URB:
287 //KdPrint((__DRIVER_NAME " IOCTL_INTERNAL_USB_SUBMIT_URB\n"));
288 urb = (PURB)wrp.Parameters.Others.Arg1;
289 ASSERT(urb);
290 usb_device = urb->UrbHeader.UsbdDeviceHandle;
291 if (!usb_device)
292 usb_device = xupdd->usb_device;
293 WdfRequestForwardToIoQueue(request, usb_device->urb_queue);
294 return;
295 case IOCTL_INTERNAL_USB_GET_DEVICE_HANDLE:
296 FUNCTION_MSG("IOCTL_INTERNAL_USB_GET_DEVICE_HANDLE (returning %p)\n", xupdd->usb_device);
297 *(PVOID *)wrp.Parameters.Others.Arg1 = xupdd->usb_device;
298 status = STATUS_SUCCESS;
299 break;
300 #if (NTDDI_VERSION >= NTDDI_VISTA)
301 case IOCTL_INTERNAL_USB_GET_DEVICE_HANDLE_EX: /* incomplete probably */
302 FUNCTION_MSG("IOCTL_INTERNAL_USB_GET_DEVICE_HANDLE_EX (returning %p)\n", xupdd->usb_device);
303 *(PVOID *)wrp.Parameters.Others.Arg1 = xupdd->usb_device;
304 *(ULONG_PTR *)wrp.Parameters.Others.Arg2 = (ULONG_PTR)0x12345678;
305 status = STATUS_SUCCESS;
306 break;
307 case IOCTL_INTERNAL_USB_GET_TOPOLOGY_ADDRESS:
308 FUNCTION_MSG("IOCTL_INTERNAL_USB_GET_TOPOLOGY_ADDRESS\n");
309 uta = (PUSB_TOPOLOGY_ADDRESS)wrp.Parameters.Others.Arg1;
310 uta->PciBusNumber = 0;
311 uta->PciDeviceNumber = 0;
312 uta->PciFunctionNumber = 0;
313 uta->RootHubPortNumber = 0;
314 uta->HubPortNumber[1] = 0;
315 uta->HubPortNumber[2] = 0;
316 uta->HubPortNumber[3] = 0;
317 uta->HubPortNumber[4] = 0;
318 status = STATUS_SUCCESS;
319 break;
320 case IOCTL_INTERNAL_USB_GET_DEVICE_CONFIG_INFO:
321 FUNCTION_MSG("IOCTL_INTERNAL_USB_GET_DEVICE_CONFIG_INFO\n");
322 hdci = (PHUB_DEVICE_CONFIG_INFO)wrp.Parameters.Others.Arg1;
323 hdci->Version = 1;
324 hdci->Length = 192;
325 hdci->HubFlags.ul = 0;
326 hdci->HubFlags.HubIsHighSpeedCapable = 1;
327 hdci->HubFlags.HubIsHighSpeed = 1;
328 hdci->HubFlags.HubIsMultiTtCapable = 0;
329 hdci->HubFlags.HubIsMultiTt = 0;
330 hdci->HubFlags.HubIsRoot = 1;
331 hdci->HubFlags.HubIsArmedWakeOnConnect = 1;
332 hdci->HubFlags.HubIsBusPowered = 1;
333 //hdci->HardwareIds = ?;
334 //hdci->CompatibleIds = ?;
335 //hdci->DeviceDescription = ?;
336 status = STATUS_SUCCESS;
337 break;
338 case IOCTL_INTERNAL_USB_RECORD_FAILURE:
339 FUNCTION_MSG("IOCTL_INTERNAL_USB_RECORD_FAILURE\n");
340 usfd = (PUSB_START_FAILDATA)wrp.Parameters.Others.Arg1;
341 FUNCTION_MSG(" LengthInBytes = %d\n", usfd->LengthInBytes);
342 FUNCTION_MSG(" NtStatus = %08x\n", usfd->NtStatus);
343 FUNCTION_MSG(" UsbdStatus = %08x\n", usfd->UsbdStatus);
344 FUNCTION_MSG(" ConnectStatus = %08x\n", usfd->ConnectStatus);
345 FUNCTION_MSG(" DriverData[0] = %s\n", usfd->DriverData);
346 FUNCTION_MSG(" DriverData[0] = %S\n", usfd->DriverData);
347 FUNCTION_MSG(" DriverData[5] = %s\n", &usfd->DriverData[5]);
348 FUNCTION_MSG(" DriverData[5] = %S\n", &usfd->DriverData[5]);
349 status = STATUS_SUCCESS;
350 break;
351 #endif
352 default:
353 FUNCTION_MSG("Unknown IOCTL %08x\n", io_control_code);
354 break;
355 }
357 if (status != STATUS_SUCCESS)
358 FUNCTION_MSG("Calling WdfRequestComplete with status = %08x\n", status);
359 WdfRequestComplete(request, status);
361 //FUNCTION_EXIT();
362 }
364 static NTSTATUS
365 XenUsbHub_EvtDeviceD0Entry(WDFDEVICE device, WDF_POWER_DEVICE_STATE previous_state)
366 {
367 NTSTATUS status = STATUS_SUCCESS;
368 DECLARE_CONST_UNICODE_STRING(symbolicname_name, L"SymbolicName");
369 WDFSTRING symbolicname_value_wdfstring;
370 WDFKEY device_key;
371 UNICODE_STRING symbolicname_value;
373 UNREFERENCED_PARAMETER(device);
375 FUNCTION_ENTER();
377 switch (previous_state)
378 {
379 case WdfPowerDeviceD0:
380 KdPrint((__DRIVER_NAME " WdfPowerDeviceD1\n"));
381 break;
382 case WdfPowerDeviceD1:
383 KdPrint((__DRIVER_NAME " WdfPowerDeviceD1\n"));
384 break;
385 case WdfPowerDeviceD2:
386 KdPrint((__DRIVER_NAME " WdfPowerDeviceD2\n"));
387 break;
388 case WdfPowerDeviceD3:
389 KdPrint((__DRIVER_NAME " WdfPowerDeviceD3\n"));
390 break;
391 case WdfPowerDeviceD3Final:
392 KdPrint((__DRIVER_NAME " WdfPowerDeviceD3Final\n"));
393 break;
394 case WdfPowerDevicePrepareForHibernation:
395 KdPrint((__DRIVER_NAME " WdfPowerDevicePrepareForHibernation\n"));
396 break;
397 default:
398 KdPrint((__DRIVER_NAME " Unknown WdfPowerDevice state %d\n", previous_state));
399 break;
400 }
402 /* USB likes to have a registry key with the symbolic link name in it. Have to wait until D0Entry as this is the PDO */
403 status = WdfStringCreate(NULL, WDF_NO_OBJECT_ATTRIBUTES, &symbolicname_value_wdfstring);
404 status = WdfDeviceRetrieveDeviceInterfaceString(device, &GUID_DEVINTERFACE_USB_HUB, NULL, symbolicname_value_wdfstring);
405 FUNCTION_MSG("WdfDeviceREtrieveDeviceInterfaceString = %08x\n", status);
406 if (!NT_SUCCESS(status))
407 return status;
408 WdfStringGetUnicodeString(symbolicname_value_wdfstring, &symbolicname_value);
409 FUNCTION_MSG("ROOT_HUB SymbolicName = %S\n", symbolicname_value.Buffer);
410 status = WdfDeviceOpenRegistryKey(device, PLUGPLAY_REGKEY_DEVICE, KEY_SET_VALUE, WDF_NO_OBJECT_ATTRIBUTES, &device_key);
411 WdfRegistryAssignUnicodeString(device_key, &symbolicname_name, &symbolicname_value);
413 FUNCTION_EXIT();
415 return status;
416 }
418 static NTSTATUS
419 XenUsbHub_EvtDeviceD0Exit(WDFDEVICE device, WDF_POWER_DEVICE_STATE target_state)
420 {
421 NTSTATUS status = STATUS_SUCCESS;
422 //PXENUSB_PDO_DEVICE_DATA xupdd = GetXupdd(device);
423 //PXENUSB_DEVICE_DATA xudd = GetXudd(xupdd->wdf_device_bus_fdo);
425 UNREFERENCED_PARAMETER(device);
427 FUNCTION_ENTER();
429 switch (target_state)
430 {
431 case WdfPowerDeviceD0:
432 KdPrint((__DRIVER_NAME " WdfPowerDeviceD1\n"));
433 break;
434 case WdfPowerDeviceD1:
435 KdPrint((__DRIVER_NAME " WdfPowerDeviceD1\n"));
436 break;
437 case WdfPowerDeviceD2:
438 KdPrint((__DRIVER_NAME " WdfPowerDeviceD2\n"));
439 break;
440 case WdfPowerDeviceD3:
441 KdPrint((__DRIVER_NAME " WdfPowerDeviceD3\n"));
442 break;
443 case WdfPowerDeviceD3Final:
444 KdPrint((__DRIVER_NAME " WdfPowerDeviceD3Final\n"));
445 break;
446 case WdfPowerDevicePrepareForHibernation:
447 KdPrint((__DRIVER_NAME " WdfPowerDevicePrepareForHibernation\n"));
448 break;
449 default:
450 KdPrint((__DRIVER_NAME " Unknown WdfPowerDevice state %d\n", target_state));
451 break;
452 }
454 FUNCTION_EXIT();
456 return status;
457 }
459 static NTSTATUS
460 XenUsbHub_EvtDevicePrepareHardware(WDFDEVICE device, WDFCMRESLIST resources_raw, WDFCMRESLIST resources_translated)
461 {
462 NTSTATUS status = STATUS_SUCCESS;
464 UNREFERENCED_PARAMETER(device);
465 UNREFERENCED_PARAMETER(resources_raw);
466 UNREFERENCED_PARAMETER(resources_translated);
468 FUNCTION_ENTER();
469 FUNCTION_EXIT();
471 return status;
472 }
474 static NTSTATUS
475 XenUsbHub_EvtDeviceReleaseHardware(WDFDEVICE device, WDFCMRESLIST resources_translated)
476 {
477 NTSTATUS status = STATUS_SUCCESS;
479 UNREFERENCED_PARAMETER(device);
480 UNREFERENCED_PARAMETER(resources_translated);
482 FUNCTION_ENTER();
483 FUNCTION_EXIT();
485 return status;
486 }
488 static VOID
489 XenUsbHub_EvtDeviceUsageNotification(WDFDEVICE device, WDF_SPECIAL_FILE_TYPE notification_type, BOOLEAN is_in_notification_path)
490 {
491 PXENUSB_PDO_DEVICE_DATA xupdd = GetXupdd(device);
493 UNREFERENCED_PARAMETER(xupdd);
494 UNREFERENCED_PARAMETER(is_in_notification_path);
496 FUNCTION_ENTER();
498 switch (notification_type)
499 {
500 case WdfSpecialFilePaging:
501 KdPrint((__DRIVER_NAME " notification_type = Paging, flag = %d\n", is_in_notification_path));
502 break;
503 case WdfSpecialFileHibernation:
504 KdPrint((__DRIVER_NAME " notification_type = Hibernation, flag = %d\n", is_in_notification_path));
505 break;
506 case WdfSpecialFileDump:
507 KdPrint((__DRIVER_NAME " notification_type = Dump, flag = %d\n", is_in_notification_path));
508 break;
509 default:
510 KdPrint((__DRIVER_NAME " notification_type = %d, flag = %d\n", notification_type, is_in_notification_path));
511 break;
512 }
514 FUNCTION_EXIT();
515 }
517 static NTSTATUS
518 XenUsb_SubmitCompletionRoutine(
519 PDEVICE_OBJECT device_object,
520 PIRP irp,
521 PVOID context)
522 {
523 UNREFERENCED_PARAMETER(device_object);
525 FUNCTION_ENTER();
527 if (irp->PendingReturned)
528 {
529 KeSetEvent ((PKEVENT)context, IO_NO_INCREMENT, FALSE);
530 }
532 FUNCTION_EXIT();
534 return STATUS_MORE_PROCESSING_REQUIRED;
535 }
537 static NTSTATUS
538 XenUsbHub_UBIH_CreateUsbDevice(
539 PVOID BusContext,
540 PUSB_DEVICE_HANDLE *DeviceHandle,
541 PUSB_DEVICE_HANDLE *HubDeviceHandle,
542 USHORT PortStatus,
543 USHORT PortNumber)
544 {
545 NTSTATUS status = STATUS_SUCCESS;
546 xenusb_device_t *usb_device;
548 UNREFERENCED_PARAMETER(BusContext);
549 UNREFERENCED_PARAMETER(HubDeviceHandle);
550 UNREFERENCED_PARAMETER(PortStatus);
552 FUNCTION_ENTER();
554 KdPrint((__DRIVER_NAME " BusContext = %p\n", BusContext));
555 KdPrint((__DRIVER_NAME " DeviceHandle = %p\n", DeviceHandle));
556 KdPrint((__DRIVER_NAME " *DeviceHandle = %p\n", *DeviceHandle));
557 KdPrint((__DRIVER_NAME " HubDeviceHandle = %p\n", HubDeviceHandle));
558 KdPrint((__DRIVER_NAME " *HubDeviceHandle = %p\n", *HubDeviceHandle));
559 KdPrint((__DRIVER_NAME " PortStatus = %04X\n", PortStatus));
560 KdPrint((__DRIVER_NAME " PortNumber = %d\n", PortNumber));
561 usb_device = ExAllocatePoolWithTag(NonPagedPool, sizeof(xenusb_device_t), XENUSB_POOL_TAG);
562 usb_device->port_number = PortNumber;
563 *DeviceHandle = usb_device;
565 FUNCTION_EXIT();
566 return status;
567 }
569 static VOID
570 XenUsb_SetEventCallback(usbif_shadow_t *shadow)
571 {
572 FUNCTION_ENTER();
573 KeSetEvent(&shadow->event, IO_NO_INCREMENT, FALSE);
574 FUNCTION_EXIT();
575 }
577 static NTSTATUS
578 XenUsbHub_UBIH_InitializeUsbDevice(
579 PVOID BusContext,
580 PUSB_DEVICE_HANDLE DeviceHandle)
581 {
582 NTSTATUS status = STATUS_SUCCESS;
583 WDFDEVICE device = BusContext;
584 PXENUSB_PDO_DEVICE_DATA xupdd = GetXupdd(device);
585 PXENUSB_DEVICE_DATA xudd = GetXudd(xupdd->wdf_device_bus_fdo);
586 WDF_IO_QUEUE_CONFIG queue_config;
587 xenusb_device_t *usb_device = DeviceHandle;
588 PUCHAR ptr;
589 PVOID buf;
590 PMDL mdl;
591 usbif_shadow_t *shadow;
592 PUSB_DEVICE_DESCRIPTOR device_descriptor;
593 PUSB_CONFIGURATION_DESCRIPTOR config_descriptor;
594 PUSB_INTERFACE_DESCRIPTOR interface_descriptor;
595 PUSB_ENDPOINT_DESCRIPTOR endpoint_descriptor;
596 int i, j, k;
597 PUSB_DEFAULT_PIPE_SETUP_PACKET setup_packet;
599 FUNCTION_ENTER();
601 KdPrint((__DRIVER_NAME " device = %p\n", device));
602 KdPrint((__DRIVER_NAME " usb_device = %p\n", usb_device));
603 usb_device->pdo_device = BusContext;
605 // TODO: get address from freelist and assign it to the device...
606 usb_device->address = 2;
607 // TODO: get this stuff properly ...
608 xupdd->usb_device->device_speed = UsbHighSpeed;
609 xupdd->usb_device->device_type = Usb20Device;
611 buf = ExAllocatePoolWithTag(NonPagedPool, PAGE_SIZE, XENUSB_POOL_TAG);
612 mdl = IoAllocateMdl(buf, PAGE_SIZE, FALSE, FALSE, NULL);
613 MmBuildMdlForNonPagedPool(mdl);
614 shadow = get_shadow_from_freelist(xudd);
616 /* set the address */
617 KeInitializeEvent(&shadow->event, NotificationEvent, FALSE);
618 shadow->callback = XenUsb_SetEventCallback;
619 shadow->req.id = shadow->id;
620 shadow->req.pipe = LINUX_PIPE_TYPE_CTRL | usb_device->port_number;
621 shadow->req.transfer_flags = 0;
622 shadow->req.buffer_length = 0;
623 setup_packet = (PUSB_DEFAULT_PIPE_SETUP_PACKET)shadow->req.u.ctrl;
624 setup_packet->bmRequestType.Recipient = BMREQUEST_TO_DEVICE;
625 setup_packet->bmRequestType.Type = BMREQUEST_STANDARD;
626 setup_packet->bmRequestType.Dir = BMREQUEST_HOST_TO_DEVICE;
627 setup_packet->bRequest = USB_REQUEST_SET_ADDRESS;
628 setup_packet->wValue.W = usb_device->address;
629 setup_packet->wIndex.W = 0;
630 setup_packet->wLength = shadow->req.buffer_length;
631 status = XenUsb_ExecuteRequest(xudd, shadow, NULL, NULL, 0);
632 //TODO: Handle failure here
633 KeWaitForSingleObject(&shadow->event, Executive, KernelMode, FALSE, NULL);
634 KdPrint((__DRIVER_NAME " rsp id = %d\n", shadow->rsp.id));
635 KdPrint((__DRIVER_NAME " rsp start_frame = %d\n", shadow->rsp.start_frame));
636 KdPrint((__DRIVER_NAME " rsp status = %d\n", shadow->rsp.status));
637 KdPrint((__DRIVER_NAME " rsp actual_length = %d\n", shadow->rsp.actual_length));
638 KdPrint((__DRIVER_NAME " rsp error_count = %d\n", shadow->rsp.error_count));
640 /* get the device descriptor */
641 KeInitializeEvent(&shadow->event, NotificationEvent, FALSE);
642 shadow->callback = XenUsb_SetEventCallback;
643 shadow->req.id = shadow->id;
644 shadow->req.pipe = LINUX_PIPE_DIRECTION_IN | LINUX_PIPE_TYPE_CTRL | (usb_device->address << 8) | usb_device->port_number;
645 shadow->req.transfer_flags = 0;
646 shadow->req.buffer_length = PAGE_SIZE;
647 setup_packet = (PUSB_DEFAULT_PIPE_SETUP_PACKET)shadow->req.u.ctrl;
648 setup_packet->bmRequestType.Recipient = BMREQUEST_TO_DEVICE;
649 setup_packet->bmRequestType.Type = BMREQUEST_STANDARD;
650 setup_packet->bmRequestType.Dir = BMREQUEST_DEVICE_TO_HOST;
651 setup_packet->bRequest = USB_REQUEST_GET_DESCRIPTOR;
652 setup_packet->wValue.LowByte = 0;
653 setup_packet->wValue.HiByte = USB_DEVICE_DESCRIPTOR_TYPE; //device descriptor
654 setup_packet->wIndex.W = 0;
655 setup_packet->wLength = shadow->req.buffer_length;
656 status = XenUsb_ExecuteRequest(xudd, shadow, NULL, mdl, PAGE_SIZE);
657 //TODO: Handle failure here
658 KeWaitForSingleObject(&shadow->event, Executive, KernelMode, FALSE, NULL);
659 KdPrint((__DRIVER_NAME " rsp id = %d\n", shadow->rsp.id));
660 KdPrint((__DRIVER_NAME " rsp start_frame = %d\n", shadow->rsp.start_frame));
661 KdPrint((__DRIVER_NAME " rsp status = %d\n", shadow->rsp.status));
662 KdPrint((__DRIVER_NAME " rsp actual_length = %d\n", shadow->rsp.actual_length));
663 KdPrint((__DRIVER_NAME " rsp error_count = %d\n", shadow->rsp.error_count));
664 ptr = buf;
665 device_descriptor = (PUSB_DEVICE_DESCRIPTOR)ptr;
666 KdPrint((__DRIVER_NAME " bLength = %d\n", device_descriptor->bLength));
667 KdPrint((__DRIVER_NAME " bNumConfigurations = %d\n", device_descriptor->bNumConfigurations));
668 memcpy(&usb_device->device_descriptor, device_descriptor, device_descriptor->bLength);
669 usb_device->configs = ExAllocatePoolWithTag(NonPagedPool, sizeof(PVOID) * device_descriptor->bNumConfigurations, XENUSB_POOL_TAG);
670 KdPrint((__DRIVER_NAME " bLength = %d\n", device_descriptor->bLength));
671 KdPrint((__DRIVER_NAME " bDescriptorType = %d\n", device_descriptor->bDescriptorType));
672 KdPrint((__DRIVER_NAME " bcdUSB = %04x\n", device_descriptor->bcdUSB));
673 KdPrint((__DRIVER_NAME " bDeviceClass = %02x\n", device_descriptor->bDeviceClass));
674 KdPrint((__DRIVER_NAME " bDeviceSubClass = %02x\n", device_descriptor->bDeviceSubClass));
675 KdPrint((__DRIVER_NAME " bDeviceProtocol = %02x\n", device_descriptor->bDeviceProtocol));
676 KdPrint((__DRIVER_NAME " idVendor = %04x\n", device_descriptor->idVendor));
677 KdPrint((__DRIVER_NAME " idProduct = %04x\n", device_descriptor->idProduct));
678 KdPrint((__DRIVER_NAME " bcdDevice = %04x\n", device_descriptor->bcdDevice));
679 KdPrint((__DRIVER_NAME " bNumConfigurations = %04x\n", device_descriptor->bNumConfigurations));
681 /* get the config descriptor */
682 for (i = 0; i < device_descriptor->bNumConfigurations; i++)
683 {
684 KeInitializeEvent(&shadow->event, NotificationEvent, FALSE);
685 shadow->callback = XenUsb_SetEventCallback;
686 shadow->req.id = shadow->id;
687 shadow->req.pipe = LINUX_PIPE_DIRECTION_IN | LINUX_PIPE_TYPE_CTRL | (usb_device->address << 8) | usb_device->port_number;
688 shadow->req.transfer_flags = 0;
689 shadow->req.buffer_length = PAGE_SIZE;
690 setup_packet = (PUSB_DEFAULT_PIPE_SETUP_PACKET)shadow->req.u.ctrl;
691 setup_packet->bmRequestType.Recipient = BMREQUEST_TO_DEVICE;
692 setup_packet->bmRequestType.Type = BMREQUEST_STANDARD;
693 setup_packet->bmRequestType.Dir = BMREQUEST_DEVICE_TO_HOST;
694 setup_packet->bRequest = USB_REQUEST_GET_DESCRIPTOR;
695 setup_packet->wValue.LowByte = (UCHAR)(i + 1);
696 setup_packet->wValue.HiByte = USB_CONFIGURATION_DESCRIPTOR_TYPE; //device descriptor
697 setup_packet->wIndex.W = 0;
698 setup_packet->wLength = shadow->req.buffer_length;
699 status = XenUsb_ExecuteRequest(xudd, shadow, buf, NULL, PAGE_SIZE);
700 //TODO: Handle failure here
701 KeWaitForSingleObject(&shadow->event, Executive, KernelMode, FALSE, NULL);
702 KdPrint((__DRIVER_NAME " rsp id = %d\n", shadow->rsp.id));
703 KdPrint((__DRIVER_NAME " rsp start_frame = %d\n", shadow->rsp.start_frame));
704 KdPrint((__DRIVER_NAME " rsp status = %d\n", shadow->rsp.status));
705 KdPrint((__DRIVER_NAME " rsp actual_length = %d\n", shadow->rsp.actual_length));
706 KdPrint((__DRIVER_NAME " rsp error_count = %d\n", shadow->rsp.error_count));
707 ptr = buf;
708 config_descriptor = (PUSB_CONFIGURATION_DESCRIPTOR)ptr;
709 KdPrint((__DRIVER_NAME " Config %d\n", i));
710 KdPrint((__DRIVER_NAME " bLength = %d\n", config_descriptor->bLength));
711 KdPrint((__DRIVER_NAME " bDescriptorType = %d\n", config_descriptor->bDescriptorType));
712 KdPrint((__DRIVER_NAME " wTotalLength = %d\n", config_descriptor->wTotalLength));
713 KdPrint((__DRIVER_NAME " bNumInterfaces = %d\n", config_descriptor->bNumInterfaces));
714 KdPrint((__DRIVER_NAME " iConfiguration = %d\n", config_descriptor->iConfiguration));
715 KdPrint((__DRIVER_NAME " bConfigurationValue = %d\n", config_descriptor->bConfigurationValue));
716 KdPrint((__DRIVER_NAME " bmAttributes = %02x\n", config_descriptor->bmAttributes));
717 KdPrint((__DRIVER_NAME " MaxPower = %d\n", config_descriptor->MaxPower));
718 usb_device->configs[i] = ExAllocatePoolWithTag(NonPagedPool, sizeof(xenusb_config_t) + sizeof(PVOID) * config_descriptor->bNumInterfaces, XENUSB_POOL_TAG);
719 usb_device->configs[i]->device = usb_device;
720 memcpy(&usb_device->configs[i]->config_descriptor, config_descriptor, sizeof(USB_CONFIGURATION_DESCRIPTOR));
721 ptr += config_descriptor->bLength;
722 for (j = 0; j < config_descriptor->bNumInterfaces; j++)
723 {
724 interface_descriptor = (PUSB_INTERFACE_DESCRIPTOR)ptr;
725 KdPrint((__DRIVER_NAME " Interface %d\n", j));
726 KdPrint((__DRIVER_NAME " bLength = %d\n", interface_descriptor->bLength));
727 KdPrint((__DRIVER_NAME " bDescriptorType = %d\n", interface_descriptor->bDescriptorType));
728 KdPrint((__DRIVER_NAME " bInterfaceNumber = %d\n", interface_descriptor->bInterfaceNumber));
729 KdPrint((__DRIVER_NAME " bAlternateSetting = %d\n", interface_descriptor->bAlternateSetting));
730 KdPrint((__DRIVER_NAME " bNumEndpoints = %d\n", interface_descriptor->bNumEndpoints));
731 KdPrint((__DRIVER_NAME " bInterfaceClass = %d\n", interface_descriptor->bInterfaceClass));
732 KdPrint((__DRIVER_NAME " bInterfaceSubClass = %d\n", interface_descriptor->bInterfaceSubClass));
733 KdPrint((__DRIVER_NAME " bInterfaceProtocol = %d\n", interface_descriptor->bInterfaceProtocol));
734 KdPrint((__DRIVER_NAME " iInterface = %d\n", interface_descriptor->iInterface));
735 ptr += interface_descriptor->bLength;
736 usb_device->configs[i]->interfaces[j] = ExAllocatePoolWithTag(NonPagedPool, sizeof(xenusb_interface_t) + sizeof(PVOID) * interface_descriptor->bNumEndpoints, XENUSB_POOL_TAG);
737 usb_device->configs[i]->interfaces[j]->config = usb_device->configs[i];
738 memcpy(&usb_device->configs[i]->interfaces[j]->interface_descriptor, interface_descriptor, sizeof(USB_INTERFACE_DESCRIPTOR));
739 for (k = 0; k < interface_descriptor->bNumEndpoints; k++)
740 {
741 endpoint_descriptor = (PUSB_ENDPOINT_DESCRIPTOR)ptr;
742 KdPrint((__DRIVER_NAME " Endpoint %d\n", k));
743 KdPrint((__DRIVER_NAME " bLength = %d\n", endpoint_descriptor->bLength));
744 KdPrint((__DRIVER_NAME " bDescriptorType = %d\n", endpoint_descriptor->bDescriptorType));
745 KdPrint((__DRIVER_NAME " bEndpointAddress = %02x\n", endpoint_descriptor->bEndpointAddress));
746 KdPrint((__DRIVER_NAME " bmAttributes = %02x\n", endpoint_descriptor->bmAttributes));
747 KdPrint((__DRIVER_NAME " wMaxPacketSize = %d\n", endpoint_descriptor->wMaxPacketSize));
748 KdPrint((__DRIVER_NAME " bInterval = %d\n", endpoint_descriptor->bInterval));
749 ptr += endpoint_descriptor->bLength;
750 usb_device->configs[i]->interfaces[j]->endpoints[k] = ExAllocatePoolWithTag(NonPagedPool, sizeof(xenusb_endpoint_t), XENUSB_POOL_TAG);
751 usb_device->configs[i]->interfaces[j]->endpoints[k]->interface = usb_device->configs[i]->interfaces[j];
752 usb_device->configs[i]->interfaces[j]->endpoints[k]->pipe_value = (usb_device->address << 8) | usb_device->port_number;
753 /* linux uses nonstandard endpoint type identifiers... */
754 switch(endpoint_descriptor->bmAttributes & USB_ENDPOINT_TYPE_MASK)
755 {
756 case USB_ENDPOINT_TYPE_CONTROL:
757 usb_device->configs[i]->interfaces[j]->endpoints[k]->pipe_value |= LINUX_PIPE_TYPE_CTRL;
758 break;
759 case USB_ENDPOINT_TYPE_ISOCHRONOUS:
760 usb_device->configs[i]->interfaces[j]->endpoints[k]->pipe_value |= LINUX_PIPE_TYPE_ISOC;
761 break;
762 case USB_ENDPOINT_TYPE_BULK:
763 usb_device->configs[i]->interfaces[j]->endpoints[k]->pipe_value |= LINUX_PIPE_TYPE_BULK;
764 break;
765 case USB_ENDPOINT_TYPE_INTERRUPT:
766 usb_device->configs[i]->interfaces[j]->endpoints[k]->pipe_value |= LINUX_PIPE_TYPE_INTR;
767 break;
768 }
769 usb_device->configs[i]->interfaces[j]->endpoints[k]->pipe_value |= (endpoint_descriptor->bEndpointAddress & 0x80);
770 usb_device->configs[i]->interfaces[j]->endpoints[k]->pipe_value |= (endpoint_descriptor->bEndpointAddress & 0x0F) << 15;
771 memcpy(&usb_device->configs[i]->interfaces[j]->endpoints[k]->endpoint_descriptor, endpoint_descriptor, sizeof(USB_ENDPOINT_DESCRIPTOR));
772 }
773 }
774 }
775 usb_device->active_config = usb_device->configs[0];
776 usb_device->active_interface = usb_device->configs[0]->interfaces[0];
778 WDF_IO_QUEUE_CONFIG_INIT(&queue_config, WdfIoQueueDispatchParallel); // should this be serial?
779 queue_config.EvtIoInternalDeviceControl = XenUsb_EvtIoInternalDeviceControl_DEVICE_SUBMIT_URB;
780 queue_config.PowerManaged = TRUE; /* power managed queue for SUBMIT_URB */
781 status = WdfIoQueueCreate(xupdd->wdf_device_bus_fdo, &queue_config, WDF_NO_OBJECT_ATTRIBUTES, &usb_device->urb_queue);
782 if (!NT_SUCCESS(status)) {
783 KdPrint((__DRIVER_NAME " Error creating urb_queue 0x%x\n", status));
784 return status;
785 }
787 put_shadow_on_freelist(xudd, shadow);
789 FUNCTION_EXIT();
790 return status;
791 }
793 static NTSTATUS
794 XenUsbHub_UBIH_GetUsbDescriptors(
795 PVOID BusContext,
796 PUSB_DEVICE_HANDLE DeviceHandle,
797 PUCHAR DeviceDescriptorBuffer,
798 PULONG DeviceDescriptorBufferLength,
799 PUCHAR ConfigDescriptorBuffer,
800 PULONG ConfigDescriptorBufferLength
801 )
802 {
803 NTSTATUS status = STATUS_SUCCESS;
804 xenusb_device_t *usb_device = DeviceHandle;
805 xenusb_config_t *usb_config;
806 PUCHAR ptr;
808 UNREFERENCED_PARAMETER(BusContext);
810 FUNCTION_ENTER();
812 KdPrint((__DRIVER_NAME " BusContext = %p\n", BusContext));
813 KdPrint((__DRIVER_NAME " DeviceHandle = %p\n", DeviceHandle));
814 KdPrint((__DRIVER_NAME " DeviceDescriptorBuffer = %p\n", DeviceDescriptorBuffer));
815 KdPrint((__DRIVER_NAME " DeviceDescriptorBufferLength = %d\n", *DeviceDescriptorBufferLength));
816 KdPrint((__DRIVER_NAME " ConfigDescriptorBuffer = %p\n", ConfigDescriptorBuffer));
817 KdPrint((__DRIVER_NAME " ConfigDescriptorBufferLength = %d\n", *ConfigDescriptorBufferLength));
819 memcpy(DeviceDescriptorBuffer, &usb_device->device_descriptor, usb_device->device_descriptor.bLength);
820 *DeviceDescriptorBufferLength = usb_device->device_descriptor.bLength;
822 usb_config = usb_device->active_config;
823 ptr = ConfigDescriptorBuffer;
824 KdPrint((__DRIVER_NAME " memcpy(%p, %p, %d)\n", ptr, &usb_config->config_descriptor, sizeof(USB_CONFIGURATION_DESCRIPTOR)));
825 memcpy(ptr, &usb_config->config_descriptor, sizeof(USB_CONFIGURATION_DESCRIPTOR));
826 ptr += sizeof(USB_CONFIGURATION_DESCRIPTOR);
827 ((PUSB_CONFIGURATION_DESCRIPTOR)ConfigDescriptorBuffer)->wTotalLength += 1;
828 #if 0
829 for (i = 0; i < usb_config->config_descriptor.bNumInterfaces; i++)
830 {
831 memcpy(ptr, &usb_config->interfaces[i]->interface_descriptor, sizeof(USB_INTERFACE_DESCRIPTOR));
832 ptr += sizeof(USB_INTERFACE_DESCRIPTOR);
833 ((PUSB_CONFIGURATION_DESCRIPTOR)ConfigDescriptorBuffer)->wTotalLength += sizeof(USB_INTERFACE_DESCRIPTOR);
834 for (j = 0; j < usb_config->interfaces[i]->interface_descriptor.bNumEndpoints; j++)
835 {
836 memcpy(ptr, &usb_config->interfaces[i]->endpoints[j]->endpoint_descriptor, sizeof(USB_ENDPOINT_DESCRIPTOR));
837 ptr += sizeof(USB_ENDPOINT_DESCRIPTOR);
838 ((PUSB_CONFIGURATION_DESCRIPTOR)ConfigDescriptorBuffer)->wTotalLength += sizeof(USB_ENDPOINT_DESCRIPTOR);
839 }
840 }
841 #endif
842 *ConfigDescriptorBufferLength = sizeof(USB_CONFIGURATION_DESCRIPTOR); //((PUSB_CONFIGURATION_DESCRIPTOR)ConfigDescriptorBuffer)->wTotalLength;
844 FUNCTION_EXIT();
845 return status;
846 }
848 static NTSTATUS
849 XenUsbHub_UBIH_RemoveUsbDevice (
850 PVOID BusContext,
851 PUSB_DEVICE_HANDLE DeviceHandle,
852 ULONG Flags)
853 {
854 NTSTATUS status = STATUS_SUCCESS;
856 UNREFERENCED_PARAMETER(BusContext);
857 UNREFERENCED_PARAMETER(DeviceHandle);
859 FUNCTION_ENTER();
861 if (Flags & USBD_KEEP_DEVICE_DATA)
862 KdPrint((__DRIVER_NAME " USBD_KEEP_DEVICE_DATA\n"));
864 if (Flags & USBD_MARK_DEVICE_BUSY)
865 KdPrint((__DRIVER_NAME " USBD_MARK_DEVICE_BUSY\n"));
867 FUNCTION_EXIT();
868 return status;
869 }
871 static NTSTATUS
872 XenUsbHub_UBIH_RestoreUsbDevice(
873 PVOID BusContext,
874 PUSB_DEVICE_HANDLE OldDeviceHandle,
875 PUSB_DEVICE_HANDLE NewDeviceHandle)
876 {
877 NTSTATUS status = STATUS_UNSUCCESSFUL;
879 UNREFERENCED_PARAMETER(BusContext);
880 UNREFERENCED_PARAMETER(OldDeviceHandle);
881 UNREFERENCED_PARAMETER(NewDeviceHandle);
883 FUNCTION_ENTER();
885 FUNCTION_EXIT();
886 return status;
887 }
889 static NTSTATUS
890 XenUsbHub_UBIH_GetPortHackFlags(
891 PVOID BusContext,
892 PULONG HackFlags)
893 {
894 NTSTATUS status = STATUS_UNSUCCESSFUL;
896 UNREFERENCED_PARAMETER(BusContext);
897 UNREFERENCED_PARAMETER(HackFlags);
899 FUNCTION_ENTER();
901 FUNCTION_EXIT();
902 return status;
903 }
905 static NTSTATUS
906 XenUsbHub_UBIH_QueryDeviceInformation(
907 PVOID BusContext,
908 PUSB_DEVICE_HANDLE DeviceHandle,
909 PVOID DeviceInformationBuffer,
910 ULONG DeviceInformationBufferLength,
911 PULONG LengthOfDataReturned)
912 {
913 PUSB_DEVICE_INFORMATION_0 udi = DeviceInformationBuffer;
914 xenusb_device_t *usb_device = DeviceHandle;
915 ULONG i;
916 ULONG required_size;
918 UNREFERENCED_PARAMETER(BusContext);
920 FUNCTION_ENTER();
922 KdPrint((__DRIVER_NAME " BusContext = %p\n", BusContext));
923 KdPrint((__DRIVER_NAME " DeviceHandle = %p\n", DeviceHandle));
924 KdPrint((__DRIVER_NAME " DeviceInformationBuffer = %p\n", DeviceInformationBuffer));
925 KdPrint((__DRIVER_NAME " DeviceInformationBufferLength = %d\n", DeviceInformationBufferLength));
926 KdPrint((__DRIVER_NAME " ->InformationLevel = %d\n", udi->InformationLevel));
927 required_size = (ULONG)FIELD_OFFSET(USB_DEVICE_INFORMATION_0, PipeList[usb_device->active_interface->interface_descriptor.bNumEndpoints]);
928 KdPrint((__DRIVER_NAME " required_size = %d\n", required_size));
929 *LengthOfDataReturned = required_size;
930 udi->ActualLength = required_size;
931 if (DeviceInformationBufferLength < required_size)
932 {
933 KdPrint((__DRIVER_NAME " STATUS_BUFFER_TOO_SMALL\n"));
934 FUNCTION_EXIT();
935 return STATUS_BUFFER_TOO_SMALL;
936 }
937 if (udi->InformationLevel != 0)
938 {
939 KdPrint((__DRIVER_NAME " STATUS_NOT_SUPPORTED\n"));
940 FUNCTION_EXIT();
941 return STATUS_NOT_SUPPORTED;
942 }
943 udi->PortNumber = 1;
944 memcpy(&udi->DeviceDescriptor, &usb_device->device_descriptor, sizeof(USB_DEVICE_DESCRIPTOR));
945 udi->CurrentConfigurationValue = usb_device->active_config->config_descriptor.bConfigurationValue;
946 udi->DeviceAddress = usb_device->address;
947 udi->HubAddress = 1; // ?
948 udi->DeviceSpeed = usb_device->device_speed;
949 udi->DeviceType = usb_device->device_type;
950 udi->NumberOfOpenPipes = usb_device->active_interface->interface_descriptor.bNumEndpoints;
951 for (i = 0; i < usb_device->active_interface->interface_descriptor.bNumEndpoints; i++)
952 {
953 memcpy(&udi->PipeList[i].EndpointDescriptor, &usb_device->active_interface->endpoints[i]->endpoint_descriptor, sizeof(USB_ENDPOINT_DESCRIPTOR));
954 udi->PipeList[0].ScheduleOffset = 0; // not necessarily right
955 }
956 FUNCTION_EXIT();
957 return STATUS_SUCCESS;
958 }
960 static NTSTATUS
961 XenUsbHub_UBIH_GetControllerInformation (
962 PVOID BusContext,
963 PVOID ControllerInformationBuffer,
964 ULONG ControllerInformationBufferLength,
965 PULONG LengthOfDataReturned)
966 {
967 NTSTATUS status = STATUS_UNSUCCESSFUL;
968 PUSB_CONTROLLER_INFORMATION_0 uci = ControllerInformationBuffer;
969 //WDFDEVICE device = BusContext;
970 //xenusb_device_t *usb_device = DeviceHandle;
972 UNREFERENCED_PARAMETER(BusContext);
974 FUNCTION_ENTER();
976 KdPrint((__DRIVER_NAME " BusContext = %p\n", BusContext));
977 KdPrint((__DRIVER_NAME " ControllerInformationBuffer = %p\n", ControllerInformationBuffer));
978 KdPrint((__DRIVER_NAME " ControllerInformationBufferLength = %d\n", ControllerInformationBufferLength));
979 KdPrint((__DRIVER_NAME " ->InformationLevel = %d\n", uci->InformationLevel));
980 if (ControllerInformationBufferLength < sizeof(USB_CONTROLLER_INFORMATION_0))
981 {
982 KdPrint((__DRIVER_NAME " STATUS_BUFFER_TOO_SMALL\n"));
983 FUNCTION_EXIT();
984 return STATUS_BUFFER_TOO_SMALL;
985 }
986 if (uci->InformationLevel != 0)
987 {
988 KdPrint((__DRIVER_NAME " STATUS_NOT_SUPPORTED\n"));
989 FUNCTION_EXIT();
990 return STATUS_NOT_SUPPORTED;
991 }
993 uci->ActualLength = sizeof(USB_CONTROLLER_INFORMATION_0);
994 uci->SelectiveSuspendEnabled = FALSE;
995 uci->IsHighSpeedController = TRUE;
996 *LengthOfDataReturned = uci->ActualLength;
998 FUNCTION_EXIT();
999 return status;
1002 static NTSTATUS
1003 XenUsbHub_UBIH_ControllerSelectiveSuspend (
1004 PVOID BusContext,
1005 BOOLEAN Enable)
1007 NTSTATUS status = STATUS_UNSUCCESSFUL;
1009 UNREFERENCED_PARAMETER(BusContext);
1010 UNREFERENCED_PARAMETER(Enable);
1012 FUNCTION_ENTER();
1014 FUNCTION_EXIT();
1015 return status;
1018 static NTSTATUS
1019 XenUsbHub_UBIH_GetExtendedHubInformation (
1020 PVOID BusContext,
1021 PDEVICE_OBJECT HubPhysicalDeviceObject,
1022 PVOID HubInformationBuffer,
1023 ULONG HubInformationBufferLength,
1024 PULONG LengthOfDataReturned)
1026 PUSB_EXTHUB_INFORMATION_0 hib = HubInformationBuffer;
1027 ULONG i;
1029 UNREFERENCED_PARAMETER(BusContext);
1030 UNREFERENCED_PARAMETER(HubPhysicalDeviceObject);
1032 FUNCTION_ENTER();
1034 KdPrint((__DRIVER_NAME " BusContext = %p\n", BusContext));
1035 KdPrint((__DRIVER_NAME " HubPhysicalDeviceObject = %p\n", HubPhysicalDeviceObject));
1036 KdPrint((__DRIVER_NAME " HubInformationBuffer = %p\n", HubInformationBuffer));
1037 KdPrint((__DRIVER_NAME " HubInformationBufferLength = %d\n", HubInformationBufferLength));
1038 KdPrint((__DRIVER_NAME " ->InformationLevel = %d\n", hib->InformationLevel));
1039 if (HubInformationBufferLength < (ULONG)FIELD_OFFSET(USB_EXTHUB_INFORMATION_0, Port[8]))
1041 KdPrint((__DRIVER_NAME " STATUS_BUFFER_TOO_SMALL\n"));
1042 FUNCTION_EXIT();
1043 return STATUS_BUFFER_TOO_SMALL;
1045 #if 0
1046 if (hib->InformationLevel != 0)
1048 KdPrint((__DRIVER_NAME " STATUS_NOT_SUPPORTED\n"));
1049 FUNCTION_EXIT();
1050 return STATUS_NOT_SUPPORTED;
1052 #endif
1053 hib->InformationLevel = 0;
1054 hib->NumberOfPorts = 8;
1055 for (i = 0; i < hib->NumberOfPorts; i++)
1057 hib->Port[i].PhysicalPortNumber = i + 1;
1058 hib->Port[i].PortLabelNumber = i + 1;
1059 hib->Port[i].VidOverride = 0;
1060 hib->Port[i].PidOverride = 0;
1061 hib->Port[i].PortAttributes = USB_PORTATTR_SHARED_USB2; // | USB_PORTATTR_NO_OVERCURRENT_UI;
1063 *LengthOfDataReturned = FIELD_OFFSET(USB_EXTHUB_INFORMATION_0, Port[8]);
1064 FUNCTION_EXIT();
1065 return STATUS_SUCCESS;
1068 static NTSTATUS
1069 XenUsbHub_UBIH_GetRootHubSymbolicName(
1070 PVOID BusContext,
1071 PVOID HubInformationBuffer,
1072 ULONG HubInformationBufferLength,
1073 PULONG HubNameActualLength)
1075 NTSTATUS status = STATUS_SUCCESS;
1076 FUNCTION_ENTER();
1078 UNREFERENCED_PARAMETER(BusContext);
1080 KdPrint((__DRIVER_NAME " BusContext = %p\n", BusContext));
1081 KdPrint((__DRIVER_NAME " HubInformationBuffer = %p\n", HubInformationBuffer));
1082 KdPrint((__DRIVER_NAME " HubInformationBufferLength = %d\n", HubInformationBufferLength));
1083 RtlStringCbCopyW(HubInformationBuffer, HubInformationBufferLength, L"ROOT_HUB");
1084 *HubNameActualLength = 16;
1086 FUNCTION_EXIT();
1087 return status;
1090 static PVOID
1091 XenUsbHub_UBIH_GetDeviceBusContext(
1092 PVOID BusContext,
1093 PVOID DeviceHandle)
1095 UNREFERENCED_PARAMETER(BusContext);
1096 UNREFERENCED_PARAMETER(DeviceHandle);
1098 FUNCTION_ENTER();
1100 FUNCTION_EXIT();
1101 return NULL;
1104 static NTSTATUS
1105 XenUsbHub_UBIH_Initialize20Hub (
1106 PVOID BusContext,
1107 PUSB_DEVICE_HANDLE HubDeviceHandle,
1108 ULONG TtCount)
1110 NTSTATUS status = STATUS_SUCCESS;
1112 UNREFERENCED_PARAMETER(BusContext);
1113 UNREFERENCED_PARAMETER(HubDeviceHandle);
1114 UNREFERENCED_PARAMETER(TtCount);
1116 FUNCTION_ENTER();
1117 KdPrint((__DRIVER_NAME " BusContext = %p\n", BusContext));
1118 KdPrint((__DRIVER_NAME " HubDeviceHandle = %p\n", HubDeviceHandle));
1119 KdPrint((__DRIVER_NAME " TtCount = %d\n", TtCount));
1120 FUNCTION_EXIT();
1121 return status;
1124 static NTSTATUS
1125 XenUsbHub_UBIH_RootHubInitNotification(
1126 PVOID BusContext,
1127 PVOID CallbackContext,
1128 PRH_INIT_CALLBACK CallbackFunction)
1130 NTSTATUS status = STATUS_SUCCESS;
1131 WDFDEVICE device = BusContext;
1132 PXENUSB_PDO_DEVICE_DATA xupdd = GetXupdd(device);
1134 FUNCTION_ENTER();
1136 xupdd->BusCallbackFunction = CallbackFunction;
1137 xupdd->BusCallbackContext = CallbackContext;
1139 xupdd->BusCallbackFunction(xupdd->BusCallbackContext);
1141 FUNCTION_EXIT();
1142 return status;
1145 /* This definition is incorrect in the docs */
1146 static VOID
1147 XenUsbHub_UBIH_FlushTransfers(
1148 PVOID BusContext,
1149 PVOID DeviceHandle)
1151 UNREFERENCED_PARAMETER(BusContext);
1152 UNREFERENCED_PARAMETER(DeviceHandle);
1154 FUNCTION_ENTER();
1156 FUNCTION_EXIT();
1159 static VOID
1160 XenUsbHub_UBIH_SetDeviceHandleData(
1161 PVOID BusContext,
1162 PUSB_DEVICE_HANDLE DeviceHandle,
1163 PDEVICE_OBJECT UsbDevicePdo)
1165 UNREFERENCED_PARAMETER(BusContext);
1166 UNREFERENCED_PARAMETER(DeviceHandle);
1167 UNREFERENCED_PARAMETER(UsbDevicePdo);
1169 FUNCTION_ENTER();
1170 FUNCTION_EXIT();
1173 static NTSTATUS
1174 XenUsbHub_UBIH_CreateUsbDeviceEx(
1175 PVOID BusContext,
1176 PUSB_DEVICE_HANDLE *DeviceHandle,
1177 PUSB_DEVICE_HANDLE *HubDeviceHandle,
1178 USHORT PortStatus,
1179 USHORT PortNumber,
1180 PUSB_CD_ERROR_INFORMATION CdErrorInfo,
1181 USHORT TtPortNumber)
1183 NTSTATUS status = STATUS_SUCCESS;
1185 UNREFERENCED_PARAMETER(CdErrorInfo);
1186 UNREFERENCED_PARAMETER(TtPortNumber);
1188 FUNCTION_ENTER();
1190 status = XenUsbHub_UBIH_CreateUsbDevice(BusContext, DeviceHandle, HubDeviceHandle, PortStatus, PortNumber);
1192 KdPrint((__DRIVER_NAME " CdErrorInfo = %p\n", CdErrorInfo));
1193 KdPrint((__DRIVER_NAME " TtPortNumber = %d\n", TtPortNumber));
1195 FUNCTION_EXIT();
1196 return status;
1199 static NTSTATUS
1200 XenUsbHub_UBIH_InitializeUsbDeviceEx(
1201 PVOID BusContext,
1202 PUSB_DEVICE_HANDLE DeviceHandle,
1203 PUSB_ID_ERROR_INFORMATION IdErrInfo)
1205 NTSTATUS status;
1207 UNREFERENCED_PARAMETER(BusContext);
1208 UNREFERENCED_PARAMETER(DeviceHandle);
1209 UNREFERENCED_PARAMETER(IdErrInfo);
1210 FUNCTION_ENTER();
1211 FUNCTION_MSG("IdErrInfo->Version = %d\n", IdErrInfo->Version);
1212 FUNCTION_MSG("IdErrInfo->PathError = %d\n", IdErrInfo->PathError);
1213 FUNCTION_MSG("IdErrInfo->Arg1 = %08x\n", IdErrInfo->Arg1);
1214 FUNCTION_MSG("IdErrInfo->UsbAddress = %d\n", IdErrInfo->UsbAddress);
1215 FUNCTION_MSG("IdErrInfo->NtStatus = %08x\n", IdErrInfo->NtStatus);
1216 FUNCTION_MSG("IdErrInfo->UsbdStatus = %08x\n", IdErrInfo->UsbdStatus);
1217 FUNCTION_MSG("IdErrInfo->XtraInfo = %s\n", IdErrInfo->XtraInfo);
1218 status = XenUsbHub_UBIH_InitializeUsbDevice(BusContext, DeviceHandle);
1219 FUNCTION_EXIT();
1220 return status;
1223 static BOOLEAN
1224 XenUsbHub_UBIH_HubIsRoot(
1225 PVOID BusContext,
1226 PVOID DeviceObject)
1228 UNREFERENCED_PARAMETER(BusContext);
1229 UNREFERENCED_PARAMETER(DeviceObject);
1231 FUNCTION_ENTER();
1232 FUNCTION_EXIT();
1233 return TRUE;
1236 static VOID
1237 XenUsbHub_UBIH_AcquireBusSemaphore(
1238 PVOID BusContext)
1240 UNREFERENCED_PARAMETER(BusContext);
1241 FUNCTION_ENTER();
1242 FUNCTION_EXIT();
1243 return;
1246 static VOID
1247 XenUsbHub_UBIH_ReleaseBusSemaphore(
1248 PVOID BusContext)
1250 UNREFERENCED_PARAMETER(BusContext);
1251 FUNCTION_ENTER();
1252 FUNCTION_EXIT();
1253 return;
1256 static ULONG
1257 XenUsbHub_UBIH_CaculatePipeBandwidth(
1258 PVOID BusContext,
1259 PUSBD_PIPE_INFORMATION PipeInfo,
1260 USB_DEVICE_SPEED DeviceSpeed)
1262 UNREFERENCED_PARAMETER(BusContext);
1263 UNREFERENCED_PARAMETER(PipeInfo);
1264 UNREFERENCED_PARAMETER(DeviceSpeed);
1265 FUNCTION_ENTER();
1266 FUNCTION_EXIT();
1267 return (ULONG)-1;
1270 static VOID
1271 XenUsbHub_UBIH_SetBusSystemWakeMode(
1272 PVOID BusContext,
1273 ULONG Mode)
1275 UNREFERENCED_PARAMETER(BusContext);
1276 UNREFERENCED_PARAMETER(Mode);
1277 FUNCTION_ENTER();
1278 FUNCTION_EXIT();
1279 return;
1282 static VOID
1283 XenUsbHub_UBIH_SetDeviceFlag(
1284 PVOID BusContext,
1285 GUID *DeviceFlagGuid,
1286 PVOID ValueData,
1287 ULONG ValueLength)
1289 UNREFERENCED_PARAMETER(BusContext);
1290 UNREFERENCED_PARAMETER(DeviceFlagGuid);
1291 UNREFERENCED_PARAMETER(ValueData);
1292 UNREFERENCED_PARAMETER(ValueLength);
1293 FUNCTION_ENTER();
1294 FUNCTION_EXIT();
1295 return;
1298 static NTSTATUS
1299 XenUsbHub_UBIH_HubTestPoint(
1300 PVOID bus_context,
1301 PVOID device_handle,
1302 ULONG op_code,
1303 PVOID test_data)
1305 UNREFERENCED_PARAMETER(bus_context);
1306 UNREFERENCED_PARAMETER(device_handle);
1307 UNREFERENCED_PARAMETER(op_code);
1308 UNREFERENCED_PARAMETER(test_data);
1309 FUNCTION_ENTER();
1310 FUNCTION_MSG("device_handle = %p\n", device_handle);
1311 FUNCTION_MSG("op_code = %p\n", op_code);
1312 FUNCTION_MSG("test_data = %p\n", test_data);
1313 FUNCTION_EXIT();
1314 return STATUS_SUCCESS;
1317 static NTSTATUS
1318 XenUsbHub_UBIH_GetDevicePerformanceInfo(
1319 PVOID BusContext,
1320 PUSB_DEVICE_HANDLE DeviceHandle,
1321 PVOID DeviceInformationBuffer,
1322 ULONG DeviceInformationBufferLength,
1323 PULONG LengthOfDataCopied)
1325 UNREFERENCED_PARAMETER(BusContext);
1326 UNREFERENCED_PARAMETER(DeviceHandle);
1327 UNREFERENCED_PARAMETER(DeviceInformationBuffer);
1328 UNREFERENCED_PARAMETER(DeviceInformationBufferLength);
1329 UNREFERENCED_PARAMETER(LengthOfDataCopied);
1330 FUNCTION_ENTER();
1331 FUNCTION_EXIT();
1332 return STATUS_UNSUCCESSFUL;
1335 static NTSTATUS
1336 XenUsbHub_UBIH_WaitAsyncPowerUp(
1337 PVOID BusContext)
1339 UNREFERENCED_PARAMETER(BusContext);
1340 FUNCTION_ENTER();
1341 FUNCTION_EXIT();
1342 return STATUS_UNSUCCESSFUL;
1345 static NTSTATUS
1346 XenUsbHub_UBIH_GetDeviceAddress(
1347 PVOID BusContext,
1348 PUSB_DEVICE_HANDLE DeviceHandle,
1349 PUSHORT DeviceAddress)
1351 UNREFERENCED_PARAMETER(BusContext);
1352 UNREFERENCED_PARAMETER(DeviceHandle);
1353 UNREFERENCED_PARAMETER(DeviceAddress);
1354 FUNCTION_ENTER();
1355 FUNCTION_EXIT();
1356 return STATUS_UNSUCCESSFUL;
1359 static NTSTATUS
1360 XenUsbHub_UBIH_RefDeviceHandle(
1361 PVOID BusContext,
1362 PUSB_DEVICE_HANDLE DeviceHandle,
1363 PVOID Object,
1364 ULONG Tag)
1366 UNREFERENCED_PARAMETER(BusContext);
1367 UNREFERENCED_PARAMETER(DeviceHandle);
1368 UNREFERENCED_PARAMETER(Object);
1369 UNREFERENCED_PARAMETER(Tag);
1370 FUNCTION_ENTER();
1371 FUNCTION_EXIT();
1372 return STATUS_UNSUCCESSFUL;
1375 static NTSTATUS
1376 XenUsbHub_UBIH_DerefDeviceHandle(
1377 PVOID BusContext,
1378 PUSB_DEVICE_HANDLE DeviceHandle,
1379 PVOID Object,
1380 ULONG Tag)
1382 UNREFERENCED_PARAMETER(BusContext);
1383 UNREFERENCED_PARAMETER(DeviceHandle);
1384 UNREFERENCED_PARAMETER(Object);
1385 UNREFERENCED_PARAMETER(Tag);
1386 FUNCTION_ENTER();
1387 FUNCTION_MSG("This should do something\n");
1388 FUNCTION_EXIT();
1389 return STATUS_SUCCESS;
1392 static ULONG
1393 XenUsbHub_UBIH_SetDeviceHandleIdleReadyState(
1394 PVOID BusContext,
1395 PUSB_DEVICE_HANDLE DeviceHandle,
1396 ULONG NewIdleReadyState)
1398 UNREFERENCED_PARAMETER(BusContext);
1399 UNREFERENCED_PARAMETER(DeviceHandle);
1400 UNREFERENCED_PARAMETER(NewIdleReadyState);
1401 FUNCTION_ENTER();
1402 FUNCTION_EXIT();
1403 return (ULONG)-1;
1406 static NTSTATUS
1407 XenUsbHub_UBIH_CreateUsbDeviceV7(
1408 PVOID BusContext,
1409 PUSB_DEVICE_HANDLE *NewDeviceHandle,
1410 PUSB_DEVICE_HANDLE HsHubDeviceHandle,
1411 USHORT PortStatus,
1412 PUSB_PORT_PATH PortPath,
1413 PUSB_CD_ERROR_INFORMATION CdErrorInfo,
1414 USHORT TtPortNumber,
1415 PDEVICE_OBJECT PdoDeviceObject,
1416 PUNICODE_STRING PhysicalDeviceObjectName)
1418 UNREFERENCED_PARAMETER(BusContext);
1419 UNREFERENCED_PARAMETER(NewDeviceHandle);
1420 UNREFERENCED_PARAMETER(HsHubDeviceHandle);
1421 UNREFERENCED_PARAMETER(PortStatus);
1422 UNREFERENCED_PARAMETER(PortPath);
1423 UNREFERENCED_PARAMETER(CdErrorInfo);
1424 UNREFERENCED_PARAMETER(TtPortNumber);
1425 UNREFERENCED_PARAMETER(PdoDeviceObject);
1426 UNREFERENCED_PARAMETER(PhysicalDeviceObjectName);
1427 FUNCTION_ENTER();
1428 FUNCTION_EXIT();
1429 return STATUS_UNSUCCESSFUL;
1432 static NTSTATUS
1433 XenUsbHub_UBIH_GetContainerIdForPort(
1434 PVOID BusContext,
1435 USHORT PortNumber,
1436 LPGUID ContainerId)
1438 UNREFERENCED_PARAMETER(BusContext);
1439 UNREFERENCED_PARAMETER(PortNumber);
1440 UNREFERENCED_PARAMETER(ContainerId);
1441 FUNCTION_ENTER();
1442 FUNCTION_EXIT();
1443 return STATUS_UNSUCCESSFUL;
1446 static NTSTATUS
1447 XenUsbHub_UBIH_SetContainerIdForPort(
1448 PVOID BusContext,
1449 USHORT PortNumber,
1450 LPGUID ContainerId)
1452 UNREFERENCED_PARAMETER(BusContext);
1453 UNREFERENCED_PARAMETER(PortNumber);
1454 UNREFERENCED_PARAMETER(ContainerId);
1455 FUNCTION_ENTER();
1456 FUNCTION_EXIT();
1457 return STATUS_UNSUCCESSFUL;
1460 static NTSTATUS
1461 XenUsbHub_UBIH_AbortAllDevicePipes(
1462 PVOID BusContext,
1463 PUSB_DEVICE_HANDLE DeviceHandle)
1465 UNREFERENCED_PARAMETER(BusContext);
1466 UNREFERENCED_PARAMETER(DeviceHandle);
1467 FUNCTION_ENTER();
1468 FUNCTION_EXIT();
1469 return STATUS_UNSUCCESSFUL;
1472 static VOID
1473 XenUsbHub_UBIH_SetDeviceErrataFlag(
1474 PVOID BusContext,
1475 PUSB_DEVICE_HANDLE DeviceHandle,
1476 ULONG DeviceErrataFlag)
1478 UNREFERENCED_PARAMETER(BusContext);
1479 UNREFERENCED_PARAMETER(DeviceHandle);
1480 UNREFERENCED_PARAMETER(DeviceErrataFlag);
1481 FUNCTION_ENTER();
1482 FUNCTION_EXIT();
1483 return;
1486 static NTSTATUS
1487 XenUsbHub_UBIU_GetUSBDIVersion(
1488 PVOID BusContext,
1489 PUSBD_VERSION_INFORMATION VersionInformation,
1490 PULONG HcdCapabilities
1493 NTSTATUS status = STATUS_UNSUCCESSFUL;
1495 UNREFERENCED_PARAMETER(BusContext);
1496 UNREFERENCED_PARAMETER(VersionInformation);
1497 UNREFERENCED_PARAMETER(HcdCapabilities);
1499 FUNCTION_ENTER();
1501 FUNCTION_EXIT();
1502 return status;
1505 static NTSTATUS
1506 XenUsbHub_UBIU_QueryBusTime(
1507 PVOID BusContext,
1508 PULONG CurrentFrame
1511 NTSTATUS status = STATUS_SUCCESS;
1512 static ULONG frame_no = 0;
1514 UNREFERENCED_PARAMETER(BusContext);
1515 UNREFERENCED_PARAMETER(CurrentFrame);
1517 FUNCTION_ENTER();
1518 *CurrentFrame = frame_no++;
1519 FUNCTION_EXIT();
1520 return status;
1523 static NTSTATUS
1524 XenUsbHub_UBIU_SubmitIsoOutUrb(
1525 PVOID BusContext,
1526 PURB Urb
1529 NTSTATUS status = STATUS_UNSUCCESSFUL;
1531 UNREFERENCED_PARAMETER(BusContext);
1532 UNREFERENCED_PARAMETER(Urb);
1534 FUNCTION_ENTER();
1536 FUNCTION_EXIT();
1537 return status;
1540 static NTSTATUS
1541 XenUsbHub_UBIU_QueryBusInformation(
1542 PVOID BusContext,
1543 ULONG Level,
1544 PVOID BusInformationBuffer,
1545 PULONG BusInformationBufferLength,
1546 PULONG BusInformationActualLength)
1548 NTSTATUS status = STATUS_UNSUCCESSFUL;
1550 UNREFERENCED_PARAMETER(BusContext);
1551 UNREFERENCED_PARAMETER(Level);
1552 UNREFERENCED_PARAMETER(BusInformationBuffer);
1553 UNREFERENCED_PARAMETER(BusInformationBufferLength);
1554 UNREFERENCED_PARAMETER(BusInformationActualLength);
1556 FUNCTION_ENTER();
1558 FUNCTION_EXIT();
1559 return status;
1562 static BOOLEAN
1563 XenUsbHub_UBIU_IsDeviceHighSpeed(PVOID BusContext)
1565 UNREFERENCED_PARAMETER(BusContext);
1567 FUNCTION_ENTER();
1569 FUNCTION_EXIT();
1570 return TRUE; //TODO: get port value
1573 static NTSTATUS
1574 XenUsbHub_UBIU_EnumLogEntry(
1575 PVOID BusContext,
1576 ULONG DriverTag,
1577 ULONG EnumTag,
1578 ULONG P1,
1579 ULONG P2
1582 NTSTATUS status = STATUS_SUCCESS;
1583 FUNCTION_ENTER();
1585 UNREFERENCED_PARAMETER(BusContext);
1586 UNREFERENCED_PARAMETER(DriverTag);
1587 UNREFERENCED_PARAMETER(EnumTag);
1588 UNREFERENCED_PARAMETER(P1);
1589 UNREFERENCED_PARAMETER(P2);
1591 KdPrint((__DRIVER_NAME " DriverTag = %08x\n", DriverTag));
1592 KdPrint((__DRIVER_NAME " EnumTag = %08x\n", EnumTag));
1593 KdPrint((__DRIVER_NAME " P1 = %08x\n", P1));
1594 KdPrint((__DRIVER_NAME " P2 = %08x\n", P2));
1596 FUNCTION_EXIT();
1597 return status;
1600 static NTSTATUS
1601 XenUsbHub_UBIU_QueryBusTimeEx(
1602 PVOID BusContext,
1603 PULONG HighSpeedFrameCounter)
1605 UNREFERENCED_PARAMETER(BusContext);
1606 UNREFERENCED_PARAMETER(HighSpeedFrameCounter);
1607 FUNCTION_ENTER();
1608 FUNCTION_EXIT();
1609 return STATUS_UNSUCCESSFUL;
1612 static NTSTATUS
1613 XenUsbHub_UBIU_QueryControllerType(
1614 PVOID BusContext,
1615 PULONG HcdiOptionFlags,
1616 PUSHORT PciVendorId,
1617 PUSHORT PciDeviceId,
1618 PUCHAR PciClass,
1619 PUCHAR PciSubClass,
1620 PUCHAR PciRevisionId,
1621 PUCHAR PciProgIf)
1623 UNREFERENCED_PARAMETER(BusContext);
1624 UNREFERENCED_PARAMETER(HcdiOptionFlags);
1625 UNREFERENCED_PARAMETER(PciVendorId);
1626 UNREFERENCED_PARAMETER(PciDeviceId);
1627 UNREFERENCED_PARAMETER(PciClass);
1628 UNREFERENCED_PARAMETER(PciSubClass);
1629 UNREFERENCED_PARAMETER(PciRevisionId);
1630 UNREFERENCED_PARAMETER(PciProgIf);
1631 FUNCTION_ENTER();
1632 FUNCTION_EXIT();
1633 return STATUS_UNSUCCESSFUL;
1636 static NTSTATUS
1637 XenUsbHub_UBIHSS_SuspendHub(
1638 PVOID BusContext)
1640 UNREFERENCED_PARAMETER(BusContext);
1641 FUNCTION_ENTER();
1642 FUNCTION_EXIT();
1643 return STATUS_UNSUCCESSFUL;
1646 static NTSTATUS
1647 XenUsbHub_UBIHSS_ResumeHub(
1648 PVOID BusContext)
1650 UNREFERENCED_PARAMETER(BusContext);
1651 FUNCTION_ENTER();
1652 FUNCTION_EXIT();
1653 return STATUS_UNSUCCESSFUL;
1656 VOID
1657 XenUsbHub_ProcessHubInterruptEvent(xenusb_endpoint_t *endpoint)
1659 NTSTATUS status;
1660 WDFDEVICE pdo_device = endpoint->interface->config->device->pdo_device;
1661 PXENUSB_PDO_DEVICE_DATA xupdd = GetXupdd(pdo_device);
1662 PXENUSB_DEVICE_DATA xudd = GetXudd(xupdd->wdf_device_bus_fdo);
1663 WDF_REQUEST_PARAMETERS wrp;
1664 WDFREQUEST request;
1665 PURB urb;
1666 ULONG i;
1667 BOOLEAN port_change_flag = FALSE;
1669 FUNCTION_ENTER();
1670 WdfSpinLockAcquire(endpoint->lock);
1671 status = WdfIoQueueRetrieveNextRequest(endpoint->queue, &request);
1672 if (status == STATUS_NO_MORE_ENTRIES)
1674 WdfSpinLockRelease(endpoint->lock);
1675 KdPrint((__DRIVER_NAME " No More Entries\n", status));
1676 FUNCTION_EXIT();
1677 return;
1679 if (!NT_SUCCESS(status))
1681 WdfSpinLockRelease(endpoint->lock);
1682 KdPrint((__DRIVER_NAME " Failed to get request from queue %08x\n", status));
1683 FUNCTION_EXIT();
1684 return;
1687 WDF_REQUEST_PARAMETERS_INIT(&wrp);
1688 WdfRequestGetParameters(request, &wrp);
1690 urb = (PURB)wrp.Parameters.Others.Arg1;
1691 ASSERT(urb);
1692 ASSERT(urb->UrbHeader.Function == URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER);
1693 RtlZeroMemory(urb->UrbBulkOrInterruptTransfer.TransferBuffer, urb->UrbBulkOrInterruptTransfer.TransferBufferLength);
1695 for (i = 0; i < xudd->num_ports; i++)
1697 if (xudd->ports[i].port_change)
1699 FUNCTION_MSG("Port change on port %d - status = %04x, change = %04x\n",
1700 xudd->ports[i].port_number, xudd->ports[i].port_status, xudd->ports[i].port_change);
1701 ((PUCHAR)urb->UrbBulkOrInterruptTransfer.TransferBuffer)[xudd->ports[i].port_number >> 3] |= 1 << (xudd->ports[i].port_number & 7);
1702 port_change_flag = TRUE;
1705 WdfSpinLockRelease(endpoint->lock);
1706 if (port_change_flag)
1708 FUNCTION_MSG("Completing request %p\n", request);
1709 urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
1710 WdfRequestComplete(request, STATUS_SUCCESS);
1712 else
1714 FUNCTION_MSG("Requeuing request %p\n", request);
1715 WdfRequestRequeue(request);
1717 FUNCTION_EXIT();
1718 return;
1721 static NTSTATUS
1722 XenUsbHub_EvtDeviceWdmIrpPreprocessQUERY_INTERFACE(WDFDEVICE device, PIRP irp)
1724 PIO_STACK_LOCATION stack;
1725 union {
1726 USB_BUS_INTERFACE_HUB_V5 ubih5;
1727 #if (NTDDI_VERSION >= NTDDI_VISTA)
1728 USB_BUS_INTERFACE_HUB_V7 ubih6;
1729 USB_BUS_INTERFACE_HUB_V7 ubih7;
1730 #endif
1731 } ubih;
1732 union {
1733 USB_BUS_INTERFACE_USBDI_V1 ubiu0;
1734 USB_BUS_INTERFACE_USBDI_V1 ubiu1;
1735 USB_BUS_INTERFACE_USBDI_V2 ubiu2;
1736 #if (NTDDI_VERSION >= NTDDI_VISTA)
1737 USB_BUS_INTERFACE_USBDI_V3 ubiu3;
1738 #endif
1739 } *ubiu;
1741 FUNCTION_ENTER();
1743 stack = IoGetCurrentIrpStackLocation(irp);
1745 if (memcmp(stack->Parameters.QueryInterface.InterfaceType, &USB_BUS_INTERFACE_HUB_GUID, sizeof(GUID)) == 0)
1747 KdPrint((__DRIVER_NAME " USB_BUS_INTERFACE_HUB_GUID\n"));
1748 if ((stack->Parameters.QueryInterface.Version == USB_BUSIF_HUB_VERSION_5 && stack->Parameters.QueryInterface.Size == sizeof(USB_BUS_INTERFACE_HUB_V5))
1749 #if (NTDDI_VERSION >= NTDDI_VISTA)
1750 || (stack->Parameters.QueryInterface.Version == USB_BUSIF_HUB_VERSION_6 && stack->Parameters.QueryInterface.Size == sizeof(USB_BUS_INTERFACE_HUB_V6))
1751 || (stack->Parameters.QueryInterface.Version == USB_BUSIF_HUB_VERSION_7 && stack->Parameters.QueryInterface.Size == sizeof(USB_BUS_INTERFACE_HUB_V7))
1752 #endif
1755 ubih.ubih5.Size = stack->Parameters.QueryInterface.Size;
1756 ubih.ubih5.Version = stack->Parameters.QueryInterface.Version;
1757 ubih.ubih5.BusContext = device;
1758 ubih.ubih5.InterfaceReference = WdfDeviceInterfaceReferenceNoOp;
1759 ubih.ubih5.InterfaceDereference = WdfDeviceInterfaceDereferenceNoOp;
1760 /* these two were changed to the Ex functions in v6 so we set them here so they don't get overwritten */
1761 ubih.ubih5.CreateUsbDevice = XenUsbHub_UBIH_CreateUsbDevice;
1762 ubih.ubih5.InitializeUsbDevice = XenUsbHub_UBIH_InitializeUsbDevice;
1763 switch (stack->Parameters.QueryInterface.Version)
1765 #if (NTDDI_VERSION >= NTDDI_VISTA)
1766 case USB_BUSIF_HUB_VERSION_7:
1767 ubih.ubih7.HubTestPoint = XenUsbHub_UBIH_HubTestPoint;
1768 ubih.ubih7.GetDevicePerformanceInfo = XenUsbHub_UBIH_GetDevicePerformanceInfo;
1769 ubih.ubih7.WaitAsyncPowerUp = XenUsbHub_UBIH_WaitAsyncPowerUp;
1770 ubih.ubih7.GetDeviceAddress = XenUsbHub_UBIH_GetDeviceAddress;
1771 ubih.ubih7.RefDeviceHandle = XenUsbHub_UBIH_RefDeviceHandle;
1772 ubih.ubih7.DerefDeviceHandle = XenUsbHub_UBIH_DerefDeviceHandle;
1773 ubih.ubih7.SetDeviceHandleIdleReadyState = XenUsbHub_UBIH_SetDeviceHandleIdleReadyState;
1774 ubih.ubih7.HubIsRoot = XenUsbHub_UBIH_HubIsRoot;
1775 ubih.ubih7.AcquireBusSemaphore = XenUsbHub_UBIH_AcquireBusSemaphore;
1776 ubih.ubih7.ReleaseBusSemaphore = XenUsbHub_UBIH_ReleaseBusSemaphore;
1777 ubih.ubih7.CaculatePipeBandwidth = XenUsbHub_UBIH_CaculatePipeBandwidth;
1778 ubih.ubih7.SetBusSystemWakeMode = XenUsbHub_UBIH_SetBusSystemWakeMode;
1779 ubih.ubih7.SetDeviceFlag = XenUsbHub_UBIH_SetDeviceFlag;
1780 ubih.ubih7.HubTestPoint = XenUsbHub_UBIH_HubTestPoint;
1781 ubih.ubih7.GetDevicePerformanceInfo = XenUsbHub_UBIH_GetDevicePerformanceInfo;
1782 ubih.ubih7.WaitAsyncPowerUp = XenUsbHub_UBIH_WaitAsyncPowerUp;
1783 ubih.ubih7.GetDeviceAddress = XenUsbHub_UBIH_GetDeviceAddress;
1784 ubih.ubih7.RefDeviceHandle = XenUsbHub_UBIH_RefDeviceHandle;
1785 ubih.ubih7.DerefDeviceHandle = XenUsbHub_UBIH_DerefDeviceHandle;
1786 ubih.ubih7.SetDeviceHandleIdleReadyState = XenUsbHub_UBIH_SetDeviceHandleIdleReadyState;
1787 ubih.ubih7.CreateUsbDeviceV7 = XenUsbHub_UBIH_CreateUsbDeviceV7;
1788 ubih.ubih7.GetContainerIdForPort = XenUsbHub_UBIH_GetContainerIdForPort;
1789 ubih.ubih7.SetContainerIdForPort = XenUsbHub_UBIH_SetContainerIdForPort;
1790 ubih.ubih7.AbortAllDevicePipes = XenUsbHub_UBIH_AbortAllDevicePipes;
1791 ubih.ubih7.SetDeviceErrataFlag = XenUsbHub_UBIH_SetDeviceErrataFlag;
1792 /* fall through */
1793 case USB_BUSIF_HUB_VERSION_6:
1794 ubih.ubih6.CreateUsbDevice = XenUsbHub_UBIH_CreateUsbDeviceEx;
1795 ubih.ubih6.InitializeUsbDevice = XenUsbHub_UBIH_InitializeUsbDeviceEx;
1796 ubih.ubih6.HubIsRoot = XenUsbHub_UBIH_HubIsRoot;
1797 ubih.ubih6.AcquireBusSemaphore = XenUsbHub_UBIH_AcquireBusSemaphore;
1798 ubih.ubih6.ReleaseBusSemaphore = XenUsbHub_UBIH_ReleaseBusSemaphore;
1799 ubih.ubih6.CaculatePipeBandwidth = XenUsbHub_UBIH_CaculatePipeBandwidth;
1800 ubih.ubih6.SetBusSystemWakeMode = XenUsbHub_UBIH_SetBusSystemWakeMode;
1801 ubih.ubih6.SetDeviceFlag = XenUsbHub_UBIH_SetDeviceFlag;
1802 /* fall through */
1803 #endif
1804 case USB_BUSIF_HUB_VERSION_5:
1805 ubih.ubih5.GetUsbDescriptors = XenUsbHub_UBIH_GetUsbDescriptors;
1806 ubih.ubih5.RemoveUsbDevice = XenUsbHub_UBIH_RemoveUsbDevice;
1807 ubih.ubih5.RestoreUsbDevice = XenUsbHub_UBIH_RestoreUsbDevice;
1808 ubih.ubih5.GetPortHackFlags = XenUsbHub_UBIH_GetPortHackFlags;
1809 ubih.ubih5.QueryDeviceInformation = XenUsbHub_UBIH_QueryDeviceInformation;
1810 ubih.ubih5.GetControllerInformation = XenUsbHub_UBIH_GetControllerInformation;
1811 ubih.ubih5.ControllerSelectiveSuspend = XenUsbHub_UBIH_ControllerSelectiveSuspend;
1812 ubih.ubih5.GetExtendedHubInformation = XenUsbHub_UBIH_GetExtendedHubInformation;
1813 ubih.ubih5.GetRootHubSymbolicName = XenUsbHub_UBIH_GetRootHubSymbolicName;
1814 ubih.ubih5.GetDeviceBusContext = XenUsbHub_UBIH_GetDeviceBusContext;
1815 ubih.ubih5.Initialize20Hub = XenUsbHub_UBIH_Initialize20Hub;
1816 ubih.ubih5.RootHubInitNotification = XenUsbHub_UBIH_RootHubInitNotification;
1817 ubih.ubih5.FlushTransfers = XenUsbHub_UBIH_FlushTransfers;
1818 ubih.ubih5.SetDeviceHandleData = XenUsbHub_UBIH_SetDeviceHandleData;
1820 irp->IoStatus.Information = 0;
1821 irp->IoStatus.Status = STATUS_SUCCESS;
1824 else if (memcmp(stack->Parameters.QueryInterface.InterfaceType, &USB_BUS_INTERFACE_USBDI_GUID, sizeof(GUID)) == 0)
1826 KdPrint((__DRIVER_NAME " USB_BUS_INTERFACE_USBDI_GUID\n"));
1827 if ((stack->Parameters.QueryInterface.Version == USB_BUSIF_USBDI_VERSION_0 && stack->Parameters.QueryInterface.Size == sizeof(USB_BUS_INTERFACE_USBDI_V0))
1828 || (stack->Parameters.QueryInterface.Version == USB_BUSIF_USBDI_VERSION_1 && stack->Parameters.QueryInterface.Size == sizeof(USB_BUS_INTERFACE_USBDI_V1))
1829 || (stack->Parameters.QueryInterface.Version == USB_BUSIF_USBDI_VERSION_2 && stack->Parameters.QueryInterface.Size == sizeof(USB_BUS_INTERFACE_USBDI_V2))
1830 #if (NTDDI_VERSION >= NTDDI_VISTA)
1831 || (stack->Parameters.QueryInterface.Version == USB_BUSIF_USBDI_VERSION_3 && stack->Parameters.QueryInterface.Size == sizeof(USB_BUS_INTERFACE_USBDI_V3))
1832 #endif
1835 ubiu = (PVOID)stack->Parameters.QueryInterface.Interface;
1836 ubiu->ubiu0.Size = stack->Parameters.QueryInterface.Size;
1837 ubiu->ubiu0.Version = stack->Parameters.QueryInterface.Version;
1838 ubiu->ubiu0.BusContext = device;
1839 ubiu->ubiu0.InterfaceReference = WdfDeviceInterfaceReferenceNoOp;
1840 ubiu->ubiu0.InterfaceDereference = WdfDeviceInterfaceDereferenceNoOp;
1841 switch (stack->Parameters.QueryInterface.Version)
1843 #if (NTDDI_VERSION >= NTDDI_VISTA)
1844 case USB_BUSIF_USBDI_VERSION_3:
1845 ubiu->ubiu3.QueryBusTimeEx = XenUsbHub_UBIU_QueryBusTimeEx;
1846 ubiu->ubiu3.QueryControllerType = XenUsbHub_UBIU_QueryControllerType;
1847 /* fall through */
1848 #endif
1849 case USB_BUSIF_USBDI_VERSION_2:
1850 ubiu->ubiu2.EnumLogEntry = XenUsbHub_UBIU_EnumLogEntry;
1851 /* fall through */
1852 case USB_BUSIF_USBDI_VERSION_1:
1853 ubiu->ubiu1.IsDeviceHighSpeed = XenUsbHub_UBIU_IsDeviceHighSpeed;
1854 /* fall through */
1855 case USB_BUSIF_USBDI_VERSION_0:
1856 ubiu->ubiu0.GetUSBDIVersion = XenUsbHub_UBIU_GetUSBDIVersion;
1857 ubiu->ubiu0.QueryBusTime = XenUsbHub_UBIU_QueryBusTime;
1858 ubiu->ubiu0.SubmitIsoOutUrb = XenUsbHub_UBIU_SubmitIsoOutUrb;
1859 ubiu->ubiu0.QueryBusInformation = XenUsbHub_UBIU_QueryBusInformation;
1861 irp->IoStatus.Information = 0;
1862 irp->IoStatus.Status = STATUS_SUCCESS;
1865 else if (memcmp(stack->Parameters.QueryInterface.InterfaceType, &GUID_TRANSLATOR_INTERFACE_STANDARD, sizeof(GUID)) == 0)
1866 KdPrint((__DRIVER_NAME " GUID_TRANSLATOR_INTERFACE_STANDARD\n"));
1867 #if (NTDDI_VERSION >= NTDDI_VISTA)
1868 else if (memcmp(stack->Parameters.QueryInterface.InterfaceType, &GUID_PNP_LOCATION_INTERFACE, sizeof(GUID)) == 0)
1869 KdPrint((__DRIVER_NAME " GUID_PNP_LOCATION_INTERFACE\n"));
1870 #endif
1871 else if (memcmp(stack->Parameters.QueryInterface.InterfaceType, &USB_BUS_INTERFACE_HUB_MINIDUMP_GUID, sizeof(GUID)) == 0)
1872 KdPrint((__DRIVER_NAME " USB_BUS_INTERFACE_HUB_MINIDUMP_GUID\n"));
1873 else if (memcmp(stack->Parameters.QueryInterface.InterfaceType, &USB_BUS_INTERFACE_HUB_SS_GUID, sizeof(GUID)) == 0)
1874 KdPrint((__DRIVER_NAME " USB_BUS_INTERFACE_HUB_SS_GUID\n"));
1875 else
1876 KdPrint((__DRIVER_NAME " GUID = %08X-%04X-%04X-%04X-%02X%02X%02X%02X%02X%02X\n",
1877 stack->Parameters.QueryInterface.InterfaceType->Data1,
1878 stack->Parameters.QueryInterface.InterfaceType->Data2,
1879 stack->Parameters.QueryInterface.InterfaceType->Data3,
1880 (stack->Parameters.QueryInterface.InterfaceType->Data4[0] << 8) |
1881 stack->Parameters.QueryInterface.InterfaceType->Data4[1],
1882 stack->Parameters.QueryInterface.InterfaceType->Data4[2],
1883 stack->Parameters.QueryInterface.InterfaceType->Data4[3],
1884 stack->Parameters.QueryInterface.InterfaceType->Data4[4],
1885 stack->Parameters.QueryInterface.InterfaceType->Data4[5],
1886 stack->Parameters.QueryInterface.InterfaceType->Data4[6],
1887 stack->Parameters.QueryInterface.InterfaceType->Data4[7]));
1889 KdPrint((__DRIVER_NAME " Size = %d\n", stack->Parameters.QueryInterface.Size));
1890 KdPrint((__DRIVER_NAME " Version = %d\n", stack->Parameters.QueryInterface.Version));
1891 KdPrint((__DRIVER_NAME " Interface = %p\n", stack->Parameters.QueryInterface.Interface));
1893 IoSkipCurrentIrpStackLocation(irp);
1895 FUNCTION_EXIT();
1897 return WdfDeviceWdmDispatchPreprocessedIrp(device, irp);
1900 NTSTATUS
1901 XenUsb_EvtChildListCreateDevice(WDFCHILDLIST child_list,
1902 PWDF_CHILD_IDENTIFICATION_DESCRIPTION_HEADER identification_header,
1903 PWDFDEVICE_INIT child_init)
1905 NTSTATUS status = STATUS_SUCCESS;
1906 WDFDEVICE bus_device = WdfChildListGetDevice(child_list);
1907 WDF_OBJECT_ATTRIBUTES child_attributes;
1908 WDFDEVICE child_device;
1909 PXENUSB_PDO_IDENTIFICATION_DESCRIPTION identification = (PXENUSB_PDO_IDENTIFICATION_DESCRIPTION)identification_header;
1910 WDF_DEVICE_PNP_CAPABILITIES child_pnp_capabilities;
1911 DECLARE_UNICODE_STRING_SIZE(buffer, 512);
1912 DECLARE_CONST_UNICODE_STRING(location, L"Xen Bus");
1913 PXENUSB_PDO_DEVICE_DATA xupdd;
1914 PXENUSB_DEVICE_DATA xudd = GetXudd(bus_device);
1915 WDF_PNPPOWER_EVENT_CALLBACKS child_pnp_power_callbacks;
1916 WDF_DEVICE_POWER_CAPABILITIES child_power_capabilities;
1917 WDF_IO_QUEUE_CONFIG queue_config;
1918 #if (NTDDI_VERSION >= NTDDI_VISTA)
1919 WDF_QUERY_INTERFACE_CONFIG interface_config;
1920 USB_BUS_INTERFACE_HUB_SELECTIVE_SUSPEND ubihss;
1921 #endif
1922 UCHAR pnp_minor_functions[] = { IRP_MN_QUERY_INTERFACE };
1924 FUNCTION_ENTER();
1926 //KdPrint((__DRIVER_NAME " device = %d, port = %d, vendor_id = %04x, product_id = %04x\n",
1928 WdfDeviceInitSetDeviceType(child_init, FILE_DEVICE_UNKNOWN);
1930 status = WdfDeviceInitAssignWdmIrpPreprocessCallback(child_init, XenUsbHub_EvtDeviceWdmIrpPreprocessQUERY_INTERFACE,
1931 IRP_MJ_PNP, pnp_minor_functions, ARRAY_SIZE(pnp_minor_functions));
1932 if (!NT_SUCCESS(status))
1934 return status;
1937 WDF_PNPPOWER_EVENT_CALLBACKS_INIT(&child_pnp_power_callbacks);
1938 child_pnp_power_callbacks.EvtDeviceD0Entry = XenUsbHub_EvtDeviceD0Entry;
1939 child_pnp_power_callbacks.EvtDeviceD0Exit = XenUsbHub_EvtDeviceD0Exit;
1940 child_pnp_power_callbacks.EvtDevicePrepareHardware = XenUsbHub_EvtDevicePrepareHardware;
1941 child_pnp_power_callbacks.EvtDeviceReleaseHardware = XenUsbHub_EvtDeviceReleaseHardware;
1942 child_pnp_power_callbacks.EvtDeviceUsageNotification = XenUsbHub_EvtDeviceUsageNotification;
1943 WdfDeviceInitSetPnpPowerEventCallbacks(child_init, &child_pnp_power_callbacks);
1945 RtlUnicodeStringPrintf(&buffer, L"USB\\ROOT_HUB");
1946 status = WdfPdoInitAssignDeviceID(child_init, &buffer);
1947 status = WdfPdoInitAddHardwareID(child_init, &buffer);
1949 RtlUnicodeStringPrintf(&buffer, L"VUSB_%d", identification->device_number);
1950 status = WdfPdoInitAssignInstanceID(child_init, &buffer);
1951 if (!NT_SUCCESS(status))
1953 return status;
1956 RtlUnicodeStringPrintf(&buffer, L"PVUSB device #%d", identification->device_number, identification);
1957 status = WdfPdoInitAddDeviceText(child_init, &buffer, &location, 0x0409);
1958 if (!NT_SUCCESS(status))
1960 return status;
1962 WdfPdoInitSetDefaultLocale(child_init, 0x0409);
1964 WdfDeviceInitSetPowerNotPageable(child_init);
1966 WdfDeviceInitSetIoType(child_init, WdfDeviceIoDirect);
1968 WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&child_attributes, XENUSB_PDO_DEVICE_DATA);
1969 status = WdfDeviceCreate(&child_init, &child_attributes, &child_device);
1970 if (!NT_SUCCESS(status))
1972 return status;
1975 xupdd = GetXupdd(child_device);
1977 xudd->root_hub_device = child_device;
1979 xupdd->wdf_device = child_device;
1980 xupdd->wdf_device_bus_fdo = WdfChildListGetDevice(child_list);
1982 xupdd->usb_device = ExAllocatePoolWithTag(NonPagedPool, sizeof(xenusb_device_t), XENUSB_POOL_TAG);
1983 // get address from freelist...
1984 xupdd->usb_device->pdo_device = child_device;
1985 xupdd->usb_device->address = 1;
1986 xupdd->usb_device->device_speed = UsbHighSpeed;
1987 xupdd->usb_device->device_type = Usb20Device;
1988 xupdd->usb_device->device_descriptor.bLength = sizeof(USB_DEVICE_DESCRIPTOR);
1989 xupdd->usb_device->device_descriptor.bDescriptorType = USB_DEVICE_DESCRIPTOR_TYPE;
1990 xupdd->usb_device->device_descriptor.bcdUSB = 0x0200;
1991 xupdd->usb_device->device_descriptor.bDeviceClass = 9;
1992 xupdd->usb_device->device_descriptor.bDeviceSubClass = 0;
1993 xupdd->usb_device->device_descriptor.bDeviceProtocol = 1;
1994 xupdd->usb_device->device_descriptor.bMaxPacketSize0 = 64;
1995 xupdd->usb_device->device_descriptor.idVendor = 0x0000;
1996 xupdd->usb_device->device_descriptor.idProduct = 0x0000;
1997 xupdd->usb_device->device_descriptor.bcdDevice = 0x0206;
1998 xupdd->usb_device->device_descriptor.iManufacturer = 3;
1999 xupdd->usb_device->device_descriptor.iProduct = 2;
2000 xupdd->usb_device->device_descriptor.iSerialNumber = 1;
2001 xupdd->usb_device->device_descriptor.bNumConfigurations = 1;
2002 xupdd->usb_device->configs = ExAllocatePoolWithTag(NonPagedPool, sizeof(PVOID) * 1, XENUSB_POOL_TAG);
2003 xupdd->usb_device->configs[0] = ExAllocatePoolWithTag(NonPagedPool, sizeof(xenusb_config_t) + sizeof(PVOID) * 1, XENUSB_POOL_TAG);
2004 xupdd->usb_device->active_config = xupdd->usb_device->configs[0];
2005 xupdd->usb_device->configs[0]->device = xupdd->usb_device;
2006 xupdd->usb_device->configs[0]->config_descriptor.bLength = sizeof(USB_CONFIGURATION_DESCRIPTOR);
2007 xupdd->usb_device->configs[0]->config_descriptor.bDescriptorType = USB_CONFIGURATION_DESCRIPTOR_TYPE;
2008 xupdd->usb_device->configs[0]->config_descriptor.wTotalLength = sizeof(USB_CONFIGURATION_DESCRIPTOR);
2009 xupdd->usb_device->configs[0]->config_descriptor.bNumInterfaces = 1;
2010 xupdd->usb_device->configs[0]->config_descriptor.bConfigurationValue = 1;
2011 xupdd->usb_device->configs[0]->config_descriptor.iConfiguration = 0;
2012 xupdd->usb_device->configs[0]->config_descriptor.bmAttributes = 0xe0;
2013 xupdd->usb_device->configs[0]->config_descriptor.MaxPower = 0;
2014 xupdd->usb_device->configs[0]->interfaces[0] = ExAllocatePoolWithTag(NonPagedPool, sizeof(xenusb_interface_t) + sizeof(PVOID) * 1, XENUSB_POOL_TAG);
2015 xupdd->usb_device->active_interface = xupdd->usb_device->configs[0]->interfaces[0];
2016 xupdd->usb_device->configs[0]->interfaces[0]->config = xupdd->usb_device->configs[0];
2017 xupdd->usb_device->configs[0]->interfaces[0]->interface_descriptor.bLength = 9;
2018 xupdd->usb_device->configs[0]->interfaces[0]->interface_descriptor.bDescriptorType = USB_INTERFACE_DESCRIPTOR_TYPE;
2019 xupdd->usb_device->configs[0]->interfaces[0]->interface_descriptor.bInterfaceNumber = 0;
2020 xupdd->usb_device->configs[0]->interfaces[0]->interface_descriptor.bAlternateSetting = 0;
2021 xupdd->usb_device->configs[0]->interfaces[0]->interface_descriptor.bNumEndpoints = 1;
2022 xupdd->usb_device->configs[0]->interfaces[0]->interface_descriptor.bInterfaceClass = 9;
2023 xupdd->usb_device->configs[0]->interfaces[0]->interface_descriptor.bInterfaceSubClass = 0;
2024 xupdd->usb_device->configs[0]->interfaces[0]->interface_descriptor.bInterfaceProtocol = 0;
2025 xupdd->usb_device->configs[0]->interfaces[0]->interface_descriptor.iInterface = 0;
2026 xupdd->usb_device->configs[0]->interfaces[0]->endpoints[0] = ExAllocatePoolWithTag(NonPagedPool, sizeof(xenusb_endpoint_t), XENUSB_POOL_TAG);
2027 xupdd->usb_device->configs[0]->interfaces[0]->endpoints[0]->interface = xupdd->usb_device->configs[0]->interfaces[0];
2028 xupdd->usb_device->configs[0]->interfaces[0]->endpoints[0]->pipe_value = 0;
2029 xupdd->usb_device->configs[0]->interfaces[0]->endpoints[0]->endpoint_descriptor.bLength = 7;
2030 xupdd->usb_device->configs[0]->interfaces[0]->endpoints[0]->endpoint_descriptor.bDescriptorType = USB_ENDPOINT_DESCRIPTOR_TYPE;
2031 xupdd->usb_device->configs[0]->interfaces[0]->endpoints[0]->endpoint_descriptor.bEndpointAddress = 0x81; // EP 1 IN
2032 xupdd->usb_device->configs[0]->interfaces[0]->endpoints[0]->endpoint_descriptor.bmAttributes = USB_ENDPOINT_TYPE_INTERRUPT;
2033 xupdd->usb_device->configs[0]->interfaces[0]->endpoints[0]->endpoint_descriptor.wMaxPacketSize = 2;
2034 xupdd->usb_device->configs[0]->interfaces[0]->endpoints[0]->endpoint_descriptor.bInterval = 12;
2035 WdfSpinLockCreate(WDF_NO_OBJECT_ATTRIBUTES, &xupdd->usb_device->configs[0]->interfaces[0]->endpoints[0]->lock);
2036 #if 0
2037 WDF_TIMER_CONFIG_INIT(&timer_config, XenUsbHub_HubInterruptTimer);
2038 WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&timer_attributes, pxenusb_endpoint_t);
2039 timer_attributes.ParentObject = child_device;
2040 status = WdfTimerCreate(&timer_config, &timer_attributes, &xupdd->usb_device->configs[0]->interfaces[0]->endpoints[0]->interrupt_timer);
2041 if (!NT_SUCCESS(status)) {
2042 KdPrint((__DRIVER_NAME " Error creating timer 0x%x\n", status));
2043 return status;
2045 *GetEndpoint(xupdd->usb_device->configs[0]->interfaces[0]->endpoints[0]->interrupt_timer) = xupdd->usb_device->configs[0]->interfaces[0]->endpoints[0];
2046 #endif
2048 WDF_IO_QUEUE_CONFIG_INIT(&queue_config, WdfIoQueueDispatchParallel);
2049 queue_config.EvtIoInternalDeviceControl = XenUsb_EvtIoInternalDeviceControl_ROOTHUB_SUBMIT_URB;
2050 queue_config.PowerManaged = TRUE; /* power managed queue for SUBMIT_URB */
2051 status = WdfIoQueueCreate(child_device, &queue_config, WDF_NO_OBJECT_ATTRIBUTES, &xupdd->usb_device->urb_queue);
2052 if (!NT_SUCCESS(status)) {
2053 KdPrint((__DRIVER_NAME " Error creating urb_queue 0x%x\n", status));
2054 return status;
2057 WDF_IO_QUEUE_CONFIG_INIT(&queue_config, WdfIoQueueDispatchManual);
2058 //WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&queue_attributes, pxenusb_endpoint_t);
2059 queue_config.PowerManaged = TRUE;
2060 //queue_config.EvtIoInternalDeviceControl = XenUsb_EvtIoInternalDeviceControl_Interrupt_SUBMIT_URB;
2061 status = WdfIoQueueCreate(child_device, &queue_config, WDF_NO_OBJECT_ATTRIBUTES,
2062 &xupdd->usb_device->configs[0]->interfaces[0]->endpoints[0]->queue);
2063 if (!NT_SUCCESS(status)) {
2064 KdPrint((__DRIVER_NAME " Error creating timer io_queue 0x%x\n", status));
2065 return status;
2067 //*GetEndpoint(xupdd->usb_device->configs[0]->interfaces[0]->endpoints[0]->queue) = xupdd->usb_device->configs[0]->interfaces[0]->endpoints[0];
2069 WDF_IO_QUEUE_CONFIG_INIT_DEFAULT_QUEUE(&queue_config, WdfIoQueueDispatchParallel);
2070 queue_config.EvtIoInternalDeviceControl = XenUsbHub_EvtIoInternalDeviceControl;
2071 queue_config.EvtIoDeviceControl = XenUsbHub_EvtIoDeviceControl;
2072 queue_config.EvtIoDefault = XenUsbHub_EvtIoDefault;
2073 /* can't be power managed or deadlocks occur */
2074 queue_config.PowerManaged = FALSE;
2075 status = WdfIoQueueCreate(child_device, &queue_config, WDF_NO_OBJECT_ATTRIBUTES, &xupdd->io_queue);
2076 if (!NT_SUCCESS(status)) {
2077 KdPrint((__DRIVER_NAME " Error creating io_queue 0x%x\n", status));
2078 return status;
2081 WdfDeviceSetSpecialFileSupport(child_device, WdfSpecialFilePaging, TRUE);
2082 WdfDeviceSetSpecialFileSupport(child_device, WdfSpecialFileHibernation, TRUE);
2083 WdfDeviceSetSpecialFileSupport(child_device, WdfSpecialFileDump, TRUE);
2085 WDF_DEVICE_PNP_CAPABILITIES_INIT(&child_pnp_capabilities);
2086 child_pnp_capabilities.LockSupported = WdfFalse;
2087 child_pnp_capabilities.EjectSupported = WdfTrue;
2088 child_pnp_capabilities.Removable = WdfTrue;
2089 child_pnp_capabilities.DockDevice = WdfFalse;
2090 child_pnp_capabilities.UniqueID = WdfTrue;
2091 child_pnp_capabilities.SilentInstall = WdfTrue;
2092 child_pnp_capabilities.SurpriseRemovalOK = WdfTrue;
2093 child_pnp_capabilities.HardwareDisabled = WdfFalse;
2094 WdfDeviceSetPnpCapabilities(child_device, &child_pnp_capabilities);
2096 WDF_DEVICE_POWER_CAPABILITIES_INIT(&child_power_capabilities);
2097 child_power_capabilities.DeviceD1 = WdfTrue;
2098 child_power_capabilities.WakeFromD1 = WdfTrue;
2099 child_power_capabilities.DeviceWake = PowerDeviceD1;
2100 child_power_capabilities.DeviceState[PowerSystemWorking] = PowerDeviceD0;
2101 child_power_capabilities.DeviceState[PowerSystemSleeping1] = PowerDeviceD1;
2102 child_power_capabilities.DeviceState[PowerSystemSleeping2] = PowerDeviceD2;
2103 child_power_capabilities.DeviceState[PowerSystemSleeping3] = PowerDeviceD2;
2104 child_power_capabilities.DeviceState[PowerSystemHibernate] = PowerDeviceD3;
2105 child_power_capabilities.DeviceState[PowerSystemShutdown] = PowerDeviceD3;
2106 WdfDeviceSetPowerCapabilities(child_device, &child_power_capabilities);
2108 #if (NTDDI_VERSION >= NTDDI_VISTA)
2109 ubihss.BusContext = child_device;
2110 ubihss.Size = sizeof(USB_BUS_INTERFACE_HUB_SELECTIVE_SUSPEND);
2111 ubihss.Version = USB_BUSIF_HUB_SS_VERSION_0;
2112 ubihss.InterfaceReference = WdfDeviceInterfaceReferenceNoOp;
2113 ubihss.InterfaceDereference = WdfDeviceInterfaceDereferenceNoOp;
2114 ubihss.SuspendHub = XenUsbHub_UBIHSS_SuspendHub;
2115 ubihss.ResumeHub = XenUsbHub_UBIHSS_ResumeHub;
2116 WDF_QUERY_INTERFACE_CONFIG_INIT(&interface_config, (PINTERFACE)&ubihss, &USB_BUS_INTERFACE_HUB_SS_GUID, NULL);
2117 status = WdfDeviceAddQueryInterface(child_device, &interface_config);
2118 if (!NT_SUCCESS(status))
2119 return status;
2120 #endif
2122 status = WdfDeviceCreateDeviceInterface(child_device, &GUID_DEVINTERFACE_USB_HUB, NULL);
2123 if (!NT_SUCCESS(status))
2124 return status;
2126 FUNCTION_EXIT();
2128 return status;