2 * ReactOS USB hub driver
3 * Copyright (C) 2004 Aleksey Bragin
5 * (C) 2005 Hervé Poussineau
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 /* INCLUDES *******************************************************************/
27 /* PUBLIC AND PRIVATE FUNCTIONS ***********************************************/
31 IN PDEVICE_OBJECT Pdo
,
32 OUT PVOID
* RootHubPointer
)
36 IO_STATUS_BLOCK IoStatus
;
39 KeInitializeEvent (&Event
, NotificationEvent
, FALSE
);
41 Irp
= IoBuildDeviceIoControlRequest(IOCTL_INTERNAL_USB_GET_ROOT_USB_DEVICE
,
44 RootHubPointer
, sizeof(*RootHubPointer
),
50 DPRINT("Usbhub: IoBuildDeviceIoControlRequest() failed\n");
51 return STATUS_INSUFFICIENT_RESOURCES
;
54 Status
= IoCallDriver(Pdo
, Irp
);
56 if (Status
== STATUS_PENDING
)
58 DPRINT("Usbhub: Operation pending\n");
59 KeWaitForSingleObject(&Event
, Suspended
, KernelMode
, FALSE
, NULL
);
60 Status
= IoStatus
.Status
;
68 IN PDRIVER_OBJECT DriverObject
,
69 IN PDEVICE_OBJECT Pdo
)
72 PHUB_DEVICE_EXTENSION DeviceExtension
;
75 Status
= IoCreateDevice(DriverObject
,
76 sizeof(HUB_DEVICE_EXTENSION
),
77 NULL
, /* DeviceName */
78 FILE_DEVICE_BUS_EXTENDER
,
82 if (!NT_SUCCESS(Status
))
84 DPRINT1("Usbhub: IoCreateDevice() failed with status 0x%08lx\n", Status
);
88 // zerofill device extension
89 DeviceExtension
= (PHUB_DEVICE_EXTENSION
)Fdo
->DeviceExtension
;
90 RtlZeroMemory(DeviceExtension
, sizeof(HUB_DEVICE_EXTENSION
));
92 /* Get a pointer to the linux structure created by the USB controller,
93 * by sending IOCTL_INTERNAL_USB_GET_ROOT_USB_DEVICE to lower device.
95 Status
= GetRootHubPointer(Pdo
, (PVOID
*)&DeviceExtension
->dev
);
96 if (!NT_SUCCESS(Status
))
98 DPRINT("Usbhub: GetRootHubPointer() failed with status 0x%08lx\n", Status
);
103 DeviceExtension
->IsFDO
= TRUE
;
104 Fdo
->Flags
|= DO_POWER_PAGABLE
;
105 Status
= IoAttachDeviceToDeviceStackSafe(Fdo
, Pdo
, &DeviceExtension
->LowerDevice
);
106 if (!NT_SUCCESS(Status
))
108 DPRINT("Usbhub: IoAttachDeviceToDeviceStackSafe() failed with status 0x%08lx\n", Status
);
112 Fdo
->Flags
|= DO_BUFFERED_IO
;
113 Fdo
->Flags
&= ~DO_DEVICE_INITIALIZING
;
115 return STATUS_SUCCESS
;
118 static NTSTATUS STDCALL
120 IN PDEVICE_OBJECT DeviceObject
,
125 if (((PHUB_DEVICE_EXTENSION
)DeviceObject
->DeviceExtension
)->IsFDO
)
127 DPRINT1("Usbhub: FDO stub for major function 0x%lx\n",
128 IoGetCurrentIrpStackLocation(Irp
)->MajorFunction
);
132 return ForwardIrpAndForget(DeviceObject
, Irp
);
136 /* We can't forward request to the lower driver, because
137 * we are a Pdo, so we don't have lower driver...
139 DPRINT1("Usbhub: PDO stub for major function 0x%lx\n",
140 IoGetCurrentIrpStackLocation(Irp
)->MajorFunction
);
146 Status
= Irp
->IoStatus
.Status
;
147 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
151 static NTSTATUS STDCALL
152 DispatchDeviceControl(PDEVICE_OBJECT DeviceObject
, PIRP Irp
)
154 if (((PHUB_DEVICE_EXTENSION
)DeviceObject
->DeviceExtension
)->IsFDO
)
155 return UsbhubDeviceControlFdo(DeviceObject
, Irp
);
157 return UsbhubDeviceControlPdo(DeviceObject
, Irp
);
160 static NTSTATUS STDCALL
161 DispatchPnp(PDEVICE_OBJECT DeviceObject
, PIRP Irp
)
163 if (((PHUB_DEVICE_EXTENSION
)DeviceObject
->DeviceExtension
)->IsFDO
)
164 return UsbhubPnpFdo(DeviceObject
, Irp
);
166 return UsbhubPnpPdo(DeviceObject
, Irp
);
170 * Standard DriverEntry method.
174 IN PDRIVER_OBJECT DriverObject
,
175 IN PUNICODE_STRING RegistryPath
)
179 DriverObject
->DriverExtension
->AddDevice
= UsbhubAddDevice
;
181 for (i
= 0; i
< IRP_MJ_MAXIMUM_FUNCTION
; i
++)
182 DriverObject
->MajorFunction
[i
] = IrpStub
;
184 DriverObject
->MajorFunction
[IRP_MJ_CREATE
] = UsbhubCreate
;
185 DriverObject
->MajorFunction
[IRP_MJ_CLOSE
] = UsbhubClose
;
186 DriverObject
->MajorFunction
[IRP_MJ_CLEANUP
] = UsbhubCleanup
;
187 DriverObject
->MajorFunction
[IRP_MJ_DEVICE_CONTROL
] = DispatchDeviceControl
;
188 DriverObject
->MajorFunction
[IRP_MJ_PNP
] = DispatchPnp
;
190 return STATUS_SUCCESS
;