2 * ReactOS USB hub driver
3 * Copyright (C) 2004 Aleksey Bragin
5 * (C) 2005 Herv� Poussineau
6 * (C) 2010 Michael Martin
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 /* INCLUDES *******************************************************************/
28 /* PUBLIC AND PRIVATE FUNCTIONS ***********************************************/
32 IN PDRIVER_OBJECT DriverObject
,
33 IN PDEVICE_OBJECT Pdo
)
36 PHUB_DEVICE_EXTENSION DeviceExtension
;
39 Status
= IoCreateDevice(DriverObject
,
40 sizeof(HUB_DEVICE_EXTENSION
),
41 NULL
, /* DeviceName */
42 FILE_DEVICE_BUS_EXTENDER
,
43 FILE_AUTOGENERATED_DEVICE_NAME
,
47 if (!NT_SUCCESS(Status
))
49 DPRINT1("Usbhub: IoCreateDevice() failed with status 0x%08lx\n", Status
);
53 // zerofill device extension
54 DeviceExtension
= (PHUB_DEVICE_EXTENSION
)Fdo
->DeviceExtension
;
55 RtlZeroMemory(DeviceExtension
, sizeof(HUB_DEVICE_EXTENSION
));
57 DeviceExtension
->IsFDO
= TRUE
;
58 Fdo
->Flags
|= DO_POWER_PAGABLE
;
59 //Status = IoAttachDeviceToDeviceStackSafe(Fdo, Pdo, &DeviceExtension->LowerDevice);
60 DeviceExtension
->LowerDevice
= IoAttachDeviceToDeviceStack(Fdo
, Pdo
);
61 if (!NT_SUCCESS(Status
))
63 DPRINT("Usbhub: IoAttachDeviceToDeviceStackSafe() failed with status 0x%08lx\n", Status
);
67 Fdo
->Flags
|= DO_BUFFERED_IO
;
69 Fdo
->Flags
&= ~DO_DEVICE_INITIALIZING
;
71 return STATUS_SUCCESS
;
76 IN PDEVICE_OBJECT DeviceObject
,
81 if (((PHUB_DEVICE_EXTENSION
)DeviceObject
->DeviceExtension
)->IsFDO
)
83 DPRINT1("Usbhub: FDO stub for major function 0x%lx\n",
84 IoGetCurrentIrpStackLocation(Irp
)->MajorFunction
);
85 return ForwardIrpAndForget(DeviceObject
, Irp
);
89 /* We can't forward request to the lower driver, because
90 * we are a Pdo, so we don't have lower driver...
92 DPRINT1("Usbhub: PDO stub for major function 0x%lx\n",
93 IoGetCurrentIrpStackLocation(Irp
)->MajorFunction
);
99 Status
= Irp
->IoStatus
.Status
;
100 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
104 static NTSTATUS NTAPI
105 DispatchDeviceControl(PDEVICE_OBJECT DeviceObject
, PIRP Irp
)
107 DPRINT1("Usbhub: DispatchDeviceControl\n");
108 if (((PHUB_DEVICE_EXTENSION
)DeviceObject
->DeviceExtension
)->IsFDO
)
109 return UsbhubDeviceControlFdo(DeviceObject
, Irp
);
111 return IrpStub(DeviceObject
, Irp
);
114 static NTSTATUS NTAPI
115 DispatchInternalDeviceControl(PDEVICE_OBJECT DeviceObject
, PIRP Irp
)
117 DPRINT1("Usbhub: DispatchInternalDeviceControl\n");
118 if (((PHUB_DEVICE_EXTENSION
)DeviceObject
->DeviceExtension
)->IsFDO
)
119 return IrpStub(DeviceObject
, Irp
);
121 return UsbhubInternalDeviceControlPdo(DeviceObject
, Irp
);
124 static NTSTATUS NTAPI
125 DispatchPnp(PDEVICE_OBJECT DeviceObject
, PIRP Irp
)
127 DPRINT1("Usbhub: DispatchPnp\n");
128 if (((PHUB_DEVICE_EXTENSION
)DeviceObject
->DeviceExtension
)->IsFDO
)
129 return UsbhubPnpFdo(DeviceObject
, Irp
);
131 return UsbhubPnpPdo(DeviceObject
, Irp
);
135 * Standard DriverEntry method.
139 IN PDRIVER_OBJECT DriverObject
,
140 IN PUNICODE_STRING RegistryPath
)
144 DriverObject
->DriverExtension
->AddDevice
= UsbhubAddDevice
;
145 DPRINT1("Usbhub: DriverEntry\n");
147 for (i
= 0; i
<= IRP_MJ_MAXIMUM_FUNCTION
; i
++)
148 DriverObject
->MajorFunction
[i
] = IrpStub
;
150 DriverObject
->MajorFunction
[IRP_MJ_CREATE
] = UsbhubCreate
;
151 DriverObject
->MajorFunction
[IRP_MJ_CLOSE
] = UsbhubClose
;
152 DriverObject
->MajorFunction
[IRP_MJ_CLEANUP
] = UsbhubCleanup
;
153 DriverObject
->MajorFunction
[IRP_MJ_DEVICE_CONTROL
] = DispatchDeviceControl
;
154 DriverObject
->MajorFunction
[IRP_MJ_INTERNAL_DEVICE_CONTROL
] = DispatchInternalDeviceControl
;
155 DriverObject
->MajorFunction
[IRP_MJ_PNP
] = DispatchPnp
;
157 return STATUS_SUCCESS
;