1 | #ifndef __USBFilter_h__
|
---|
2 | #define __USBFilter_h__
|
---|
3 |
|
---|
4 | /*******************************************************************************
|
---|
5 | * Header Files *
|
---|
6 | *******************************************************************************/
|
---|
7 | #include <VBox/cdefs.h>
|
---|
8 | #include <VBox/types.h>
|
---|
9 | #include <iprt/assert.h>
|
---|
10 | #include <VBox/sup.h>
|
---|
11 | #include <iprt/asm.h>
|
---|
12 |
|
---|
13 | RT_C_DECLS_BEGIN
|
---|
14 | #if (_MSC_VER >= 1400) && !defined(VBOX_WITH_PATCHED_DDK)
|
---|
15 | # define _InterlockedExchange _InterlockedExchange_StupidDDKVsCompilerCrap
|
---|
16 | # define _InterlockedExchangeAdd _InterlockedExchangeAdd_StupidDDKVsCompilerCrap
|
---|
17 | # define _InterlockedCompareExchange _InterlockedCompareExchange_StupidDDKVsCompilerCrap
|
---|
18 | # define _InterlockedAddLargeStatistic _InterlockedAddLargeStatistic_StupidDDKVsCompilerCrap
|
---|
19 | # pragma warning(disable : 4163)
|
---|
20 | #endif
|
---|
21 | #if (_MSC_VER >= 1600) && !defined(VBOX_WITH_PATCHED_DDK)
|
---|
22 | # define _interlockedbittestandset _interlockedbittestandset_StillStupidDdkVsCompilerCrap
|
---|
23 | # define _interlockedbittestandreset _interlockedbittestandreset_StillStupidDdkVsCompilerCrap
|
---|
24 | # define _interlockedbittestandset64 _interlockedbittestandset64_StillStupidDdkVsCompilerCrap
|
---|
25 | # define _interlockedbittestandreset64 _interlockedbittestandreset64_StillStupidDdkVsCompilerCrap
|
---|
26 | # pragma warning(disable : 4163)
|
---|
27 | #endif
|
---|
28 |
|
---|
29 | #include <initguid.h>
|
---|
30 | #include <wdm.h>
|
---|
31 | #include <wmilib.h>
|
---|
32 | #include <wmistr.h>
|
---|
33 |
|
---|
34 | #if (_MSC_VER >= 1400) && !defined(VBOX_WITH_PATCHED_DDK)
|
---|
35 | # pragma warning(default : 4163)
|
---|
36 | # undef _InterlockedExchange
|
---|
37 | # undef _InterlockedExchangeAdd
|
---|
38 | # undef _InterlockedCompareExchange
|
---|
39 | # undef _InterlockedAddLargeStatistic
|
---|
40 | #endif
|
---|
41 | #if (_MSC_VER >= 1600) && !defined(VBOX_WITH_PATCHED_DDK)
|
---|
42 | # pragma warning(default : 4163)
|
---|
43 | # undef _interlockedbittestandset
|
---|
44 | # undef _interlockedbittestandreset
|
---|
45 | # undef _interlockedbittestandset64
|
---|
46 | # undef _interlockedbittestandreset64
|
---|
47 | #endif
|
---|
48 | RT_C_DECLS_END
|
---|
49 |
|
---|
50 | extern "C" {
|
---|
51 | /* from ntddk.h */
|
---|
52 | NTSYSAPI
|
---|
53 | CHAR
|
---|
54 | NTAPI
|
---|
55 | RtlUpperChar (
|
---|
56 | CHAR Character
|
---|
57 | );
|
---|
58 | }
|
---|
59 |
|
---|
60 | #ifdef DEBUG
|
---|
61 | #define DebugPrint(_x_) DbgPrint _x_
|
---|
62 |
|
---|
63 | #define TRAP() DbgBreakPoint()
|
---|
64 |
|
---|
65 | #else
|
---|
66 | #define DebugPrint(_x_)
|
---|
67 | #define TRAP()
|
---|
68 | #endif
|
---|
69 |
|
---|
70 |
|
---|
71 | #ifndef STATUS_CONTINUE_COMPLETION
|
---|
72 | #define STATUS_CONTINUE_COMPLETION STATUS_SUCCESS
|
---|
73 | #endif
|
---|
74 |
|
---|
75 | #define POOL_TAG 'VBox'
|
---|
76 |
|
---|
77 | typedef struct _DEVICE_EXTENSION
|
---|
78 | {
|
---|
79 | //
|
---|
80 | // Removelock to track IRPs so that device can be removed and
|
---|
81 | // the driver can be unloaded safely.
|
---|
82 | //
|
---|
83 | IO_REMOVE_LOCK RemoveLock;
|
---|
84 |
|
---|
85 |
|
---|
86 | /* Number of times the device was opened. */
|
---|
87 | LONG cOpened;
|
---|
88 |
|
---|
89 | BOOLEAN fHookDevice;
|
---|
90 | } DEVICE_EXTENSION, *PDEVICE_EXTENSION;
|
---|
91 |
|
---|
92 |
|
---|
93 | #ifdef __cplusplus
|
---|
94 | extern "C" {
|
---|
95 | #endif
|
---|
96 |
|
---|
97 | #ifdef DEBUG
|
---|
98 | PCHAR
|
---|
99 | PnPMinorFunctionString (
|
---|
100 | UCHAR MinorFunction
|
---|
101 | );
|
---|
102 |
|
---|
103 | void DebugPrintUnicodeString(PUNICODE_STRING pString);
|
---|
104 | #else
|
---|
105 |
|
---|
106 | #define DebugPrintUnicodeString(x)
|
---|
107 |
|
---|
108 | #endif
|
---|
109 |
|
---|
110 | NTSTATUS _stdcall
|
---|
111 | VBoxUSBMonAddDevice(
|
---|
112 | IN PDRIVER_OBJECT DriverObject,
|
---|
113 | IN PDEVICE_OBJECT PhysicalDeviceObject
|
---|
114 | );
|
---|
115 |
|
---|
116 |
|
---|
117 | NTSTATUS _stdcall
|
---|
118 | VBoxUSBMonDispatchPnp (
|
---|
119 | IN PDEVICE_OBJECT DeviceObject,
|
---|
120 | IN PIRP pIrp
|
---|
121 | );
|
---|
122 |
|
---|
123 | NTSTATUS _stdcall
|
---|
124 | VBoxUSBMonDispatchPower(
|
---|
125 | IN PDEVICE_OBJECT DeviceObject,
|
---|
126 | IN PIRP pIrp
|
---|
127 | );
|
---|
128 |
|
---|
129 | /**
|
---|
130 | * Unload the driver.
|
---|
131 | *
|
---|
132 | * @param pDrvObj Driver object.
|
---|
133 | */
|
---|
134 | void _stdcall VBoxUSBMonUnload(PDRIVER_OBJECT pDrvObj);
|
---|
135 |
|
---|
136 |
|
---|
137 | /**
|
---|
138 | * Driver entry point.
|
---|
139 | *
|
---|
140 | * @returns appropriate status code.
|
---|
141 | * @param pDrvObj Pointer to driver object.
|
---|
142 | * @param pRegPath Registry base path.
|
---|
143 | */
|
---|
144 | NTSTATUS _stdcall DriverEntry(PDRIVER_OBJECT pDrvObj, PUNICODE_STRING pRegPath);
|
---|
145 |
|
---|
146 | /**
|
---|
147 | * Device I/O Control entry point.
|
---|
148 | *
|
---|
149 | * @param pDevObj Device object.
|
---|
150 | * @param pIrp Request packet.
|
---|
151 | */
|
---|
152 | NTSTATUS _stdcall VBoxUSBMonDeviceControl(PDEVICE_OBJECT pDevObj, PIRP pIrp);
|
---|
153 |
|
---|
154 | /**
|
---|
155 | * Pass on or refuse entry point
|
---|
156 | *
|
---|
157 | * @param pDevObj Device object.
|
---|
158 | * @param pIrp Request packet.
|
---|
159 | */
|
---|
160 | NTSTATUS _stdcall VBoxUSBMonStub(IN PDEVICE_OBJECT DeviceObject, IN PIRP pIrp);
|
---|
161 |
|
---|
162 | /**
|
---|
163 | * Create (i.e. Open) file entry point.
|
---|
164 | *
|
---|
165 | * @param pDevObj Device object.
|
---|
166 | * @param pIrp Request packet.
|
---|
167 | */
|
---|
168 | NTSTATUS _stdcall VBoxUSBMonCreate(PDEVICE_OBJECT pDevObj, PIRP pIrp);
|
---|
169 |
|
---|
170 | /**
|
---|
171 | * Close file entry point.
|
---|
172 | *
|
---|
173 | * @param pDevObj Device object.
|
---|
174 | * @param pIrp Request packet.
|
---|
175 | */
|
---|
176 | NTSTATUS _stdcall VBoxUSBMonClose(PDEVICE_OBJECT pDevObj, PIRP pIrp);
|
---|
177 |
|
---|
178 | /**
|
---|
179 | * Device PnP hook
|
---|
180 | *
|
---|
181 | * @param pDevObj Device object.
|
---|
182 | * @param pIrp Request packet.
|
---|
183 | */
|
---|
184 | NTSTATUS _stdcall VBoxUSBMonPnPHook(IN PDEVICE_OBJECT DeviceObject, IN PIRP pIrp);
|
---|
185 |
|
---|
186 | /**
|
---|
187 | * Send IRP_MN_QUERY_DEVICE_RELATIONS
|
---|
188 | *
|
---|
189 | * @returns NT Status
|
---|
190 | * @param pDevObj USB device pointer
|
---|
191 | * @param pFileObj Valid file object pointer
|
---|
192 | * @param pDevRelations Pointer to DEVICE_RELATIONS pointer (out)
|
---|
193 | */
|
---|
194 | NTSTATUS VBoxUSBQueryBusRelations(PDEVICE_OBJECT pDevObj, PFILE_OBJECT pFileObj, PDEVICE_RELATIONS *pDevRelations);
|
---|
195 |
|
---|
196 |
|
---|
197 |
|
---|
198 | NTSTATUS _stdcall VBoxUSBPnPCompletion(DEVICE_OBJECT *fido, IRP *pIrp, void *context);
|
---|
199 | NTSTATUS _stdcall VBoxUSBDispatchIO(PDEVICE_OBJECT DeviceObject, PIRP pIrp);
|
---|
200 | NTSTATUS _stdcall VBoxUSBCreate();
|
---|
201 | NTSTATUS _stdcall VBoxUSBClose();
|
---|
202 | NTSTATUS _stdcall VBoxUSBInit();
|
---|
203 | NTSTATUS _stdcall VBoxUSBTerm();
|
---|
204 |
|
---|
205 | /**
|
---|
206 | * Capture specified USB device
|
---|
207 | *
|
---|
208 | * @returns NT status code
|
---|
209 | * @param usVendorId Vendor id
|
---|
210 | * @param usProductId Product id
|
---|
211 | * @param usRevision Revision
|
---|
212 | */
|
---|
213 | NTSTATUS VBoxUSBGrabDevice(USHORT usVendorId, USHORT usProductId, USHORT usRevision);
|
---|
214 |
|
---|
215 | /**
|
---|
216 | * Capture specified USB device
|
---|
217 | *
|
---|
218 | * @returns NT status code
|
---|
219 | * @param usVendorId Vendor id
|
---|
220 | * @param usProductId Product id
|
---|
221 | * @param usRevision Revision
|
---|
222 | */
|
---|
223 | NTSTATUS VBoxUSBReleaseDevice(USHORT usVendorId, USHORT usProductId, USHORT usRevision);
|
---|
224 |
|
---|
225 | bool VBoxMatchFilter(PDEVICE_OBJECT pdo);
|
---|
226 |
|
---|
227 | bool VBoxUSBAddDevice(PDEVICE_OBJECT pdo);
|
---|
228 | int VBoxUSBIsKnownPDO(PDEVICE_OBJECT pdo);
|
---|
229 | bool VBoxUSBRemoveDevice(PDEVICE_OBJECT pdo);
|
---|
230 | void VBoxUSBDeviceArrived(PDEVICE_OBJECT pdo);
|
---|
231 | bool VBoxUSBDeviceIsCaptured(PDEVICE_OBJECT pdo);
|
---|
232 | void VBoxUSBSignalChange();
|
---|
233 | bool VBoxUSBCaptureDevice(PDEVICE_OBJECT pdo);
|
---|
234 |
|
---|
235 |
|
---|
236 | #ifdef __cplusplus
|
---|
237 | }
|
---|
238 | #endif
|
---|
239 |
|
---|
240 | #endif /* __USBFilter_h__ */
|
---|
241 |
|
---|