-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathusbvhci.c
173 lines (142 loc) · 4.65 KB
/
usbvhci.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/*
* PROJECT: ReactOS Virtual USB HCI Driver
* LICENSE: LGPLv2.1+ - See COPYING.LIB in the top level directory
* PURPOSE: Driver entry functions
* PROGRAMMER: Thomas Faber <[email protected]>
*/
#include "usbvhci.h"
/* Globals */
PDRIVER_OBJECT VhciDriverObject = NULL;
/* Prototypes */
_Dispatch_type_(IRP_MJ_PNP)
static DRIVER_DISPATCH_RAISED VhciDispatchPnp;
_Dispatch_type_(IRP_MJ_INTERNAL_DEVICE_CONTROL)
static DRIVER_DISPATCH_PAGED VhciDispatchDeviceControl;
static DRIVER_ADD_DEVICE VhciAddDevice;
static DRIVER_UNLOAD VhciUnload;
DRIVER_INITIALIZE DriverEntry;
/* Section assignment */
#ifdef ALLOC_PRAGMA
#pragma alloc_text(PAGE, VhciAddDevice)
#pragma alloc_text(PAGE, VhciUnload)
#pragma alloc_text(INIT, DriverEntry)
#endif /* ALLOC_PRAGMA */
/* Functions */
_Use_decl_annotations_
static
NTSTATUS
NTAPI
VhciDispatchPnp(
PDEVICE_OBJECT DeviceObject,
PIRP Irp)
{
PVHCI_COMMON_DEVICE_EXTENSION CommonExtension;
CommonExtension = DeviceObject->DeviceExtension;
NT_ASSERT(CommonExtension->DeviceObject == DeviceObject);
if (CommonExtension->PnpState == PnpStateDeleted)
{
Irp->IoStatus.Status = STATUS_NO_SUCH_DEVICE;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return STATUS_NO_SUCH_DEVICE;
}
if (CommonExtension->Signature == VHCI_FDO_SIGNATURE)
{
return VhciFdoPnp(DeviceObject->DeviceExtension, Irp);
}
else
{
return VhciPdoPnp(DeviceObject->DeviceExtension, Irp);
}
}
_Use_decl_annotations_
static
NTSTATUS
NTAPI
VhciDispatchDeviceControl(
PDEVICE_OBJECT DeviceObject,
PIRP Irp)
{
PVHCI_FDO_DEVICE_EXTENSION FdoExtension;
FdoExtension = DeviceObject->DeviceExtension;
NT_ASSERT(FdoExtension->Common.DeviceObject == DeviceObject);
if (FdoExtension->Common.Signature == VHCI_FDO_SIGNATURE)
{
IoSkipCurrentIrpStackLocation(Irp);
return IoCallDriver(FdoExtension->LowerDevice, Irp);
}
NT_ASSERT(FdoExtension->Common.Signature == VHCI_PDO_SIGNATURE);
return VhciPdoDeviceControl(DeviceObject->DeviceExtension, Irp);
}
_Use_decl_annotations_
NTSTATUS
NTAPI
VhciAddDevice(
PDRIVER_OBJECT DriverObject,
PDEVICE_OBJECT PhysicalDeviceObject)
{
NTSTATUS Status;
PDEVICE_OBJECT DeviceObject;
PVHCI_FDO_DEVICE_EXTENSION FdoExtension;
PAGED_CODE();
DPRINT("VhciAddDevice for driver %p, PDO %p\n", DriverObject, PhysicalDeviceObject);
Status = IoCreateDevice(DriverObject,
sizeof(*FdoExtension),
NULL,
FILE_DEVICE_CONTROLLER,
FILE_DEVICE_SECURE_OPEN,
FALSE,
&DeviceObject);
if (!NT_SUCCESS(Status))
{
return Status;
}
FdoExtension = DeviceObject->DeviceExtension;
FdoExtension->Common.Signature = VHCI_FDO_SIGNATURE;
FdoExtension->Common.DeviceObject = DeviceObject;
FdoExtension->Common.PnpState = PnpStateNotStarted;
#if DBG
FdoExtension->Common.PreviousPnpState = PnpStateInvalid;
#endif
FdoExtension->PdoExtension = NULL;
Status = IoAttachDeviceToDeviceStackSafe(DeviceObject,
PhysicalDeviceObject,
&FdoExtension->LowerDevice);
if (!NT_SUCCESS(Status))
{
IoDeleteDevice(DeviceObject);
return Status;
}
if (FdoExtension->LowerDevice->Flags & DO_POWER_PAGABLE)
DeviceObject->Flags |= DO_POWER_PAGABLE;
DeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
return Status;
}
_Use_decl_annotations_
VOID
NTAPI
VhciUnload(
PDRIVER_OBJECT DriverObject)
{
UNREFERENCED_PARAMETER(DriverObject);
PAGED_CODE();
DPRINT("VhciUnload for driver %p\n", DriverObject);
}
_Use_decl_annotations_
NTSTATUS
NTAPI
DriverEntry(
PDRIVER_OBJECT DriverObject,
PUNICODE_STRING RegistryPath)
{
UNREFERENCED_PARAMETER(RegistryPath);
PAGED_CODE();
DPRINT("DriverEntry for driver %p\n", DriverObject);
DriverObject->MajorFunction[IRP_MJ_INTERNAL_DEVICE_CONTROL] = VhciDispatchDeviceControl;
DriverObject->MajorFunction[IRP_MJ_PNP] = VhciDispatchPnp;
DriverObject->MajorFunction[IRP_MJ_POWER] = VhciDispatchPower;
DriverObject->MajorFunction[IRP_MJ_SYSTEM_CONTROL] = VhciDispatchSystemControl;
DriverObject->DriverExtension->AddDevice = VhciAddDevice;
DriverObject->DriverUnload = VhciUnload;
VhciDriverObject = DriverObject;
return STATUS_SUCCESS;
}