ReactOS 0.4.16-dev-197-g92996da
swenum.c
Go to the documentation of this file.
1/*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Kernel Streaming
4 * FILE: drivers/ksfilter/swenum/swenum.c
5 * PURPOSE: KS Allocator functions
6 * PROGRAMMER: Johannes Anderwald
7 */
8
9
10#include "precomp.h"
11
12const GUID KSMEDIUMSETID_Standard = {0x4747B320L, 0x62CE, 0x11CF, {0xA5, 0xD6, 0x28, 0xDB, 0x04, 0xC1, 0x00, 0x00}};
13
18 IN PIRP Irp)
19{
20 NTSTATUS Status, PnpStatus;
21 BOOLEAN ChildDevice;
22 PIO_STACK_LOCATION IoStack;
23 PDEVICE_OBJECT PnpDeviceObject = NULL;
24
25 /* get current stack location */
27
28 /* check if the device object is a child device */
30
31 /* get bus enum pnp object */
32 PnpStatus = KsGetBusEnumPnpDeviceObject(DeviceObject, &PnpDeviceObject);
33
34 /* check for success */
35 if (!NT_SUCCESS(Status) || !NT_SUCCESS(PnpStatus))
36 {
37 /* start next power irp */
39
40 /* just complete the irp */
41 Irp->IoStatus.Status = STATUS_SUCCESS;
42
43 /* complete the irp */
45
46 /* done */
47 return STATUS_SUCCESS;
48 }
49
51 {
52 /* fake success */
53 Irp->IoStatus.Status = STATUS_SUCCESS;
54 }
55
56 if (!ChildDevice)
57 {
58 /* forward to pnp device object */
60
61 /* skip current location */
63
64 /* done */
65 return PoCallDriver(PnpDeviceObject, Irp);
66 }
67
68 /* start next power irp */
70
71 /* just complete the irp */
72 Irp->IoStatus.Status = STATUS_SUCCESS;
73
74 /* complete the irp */
76
77 /* done */
78 return STATUS_SUCCESS;
79}
80
85 IN PIRP Irp)
86{
88 BOOLEAN ChildDevice;
89 PIO_STACK_LOCATION IoStack;
90 PDEVICE_OBJECT PnpDeviceObject = NULL;
91
92 /* get current stack location */
94
95 /* check if the device object is a child device */
97
98 /* check for success */
99 if (!NT_SUCCESS(Status))
100 {
101 /* failed */
102 Irp->IoStatus.Status = Status;
104 return Status;
105 }
106
107 DPRINT("SwDispatchPnp ChildDevice %u Request %x\n", ChildDevice, IoStack->MinorFunction);
108
109 /* let ks handle it */
111
112 /* check if the request was for a pdo */
113 if (ChildDevice)
114 {
116 {
117 /* store result */
118 Irp->IoStatus.Status = Status;
119 }
120
121 /* complete request */
123
124 /* done */
125 return Status;
126 }
127
128 DPRINT("SwDispatchPnp KsServiceBusEnumPnpRequest Status %x\n", Status);
129
130 if (NT_SUCCESS(Status))
131 {
132 /* invalid request or not supported */
133 Irp->IoStatus.Status = Status;
135 return Status;
136 }
137
138 /* get bus enum pnp object */
140
141 DPRINT("SwDispatchPnp KsGetBusEnumPnpDeviceObject Status %x\n", Status);
142
143 /* check for success */
144 if (!NT_SUCCESS(Status))
145 {
146 /* failed to get pnp object */
147 Irp->IoStatus.Status = STATUS_NOT_SUPPORTED;
150 }
151
152 /* sanity check */
153 ASSERT(PnpDeviceObject);
154
155 /* get current stack location */
157
158 if (IoStack->MinorFunction == IRP_MN_REMOVE_DEVICE)
159 {
160 /* delete the device */
162 }
163 else
164 {
166 {
167 /* no resources required */
168 Irp->IoStatus.Information = 0;
169 Irp->IoStatus.Status = STATUS_SUCCESS;
170
171 /* skip current location */
173
174 /* call the pnp device object */
175 return IoCallDriver(PnpDeviceObject, Irp);
176 }
177
179 {
180 /* device cannot be disabled */
181 Irp->IoStatus.Information |= PNP_DEVICE_NOT_DISABLEABLE;
182 Irp->IoStatus.Status = STATUS_SUCCESS;
183
184 /* skip current location */
186
187 /* call the pnp device object */
188 return IoCallDriver(PnpDeviceObject, Irp);
189 }
190
192 {
193 /* skip current location */
195
196 /* call the pnp device object */
197 return IoCallDriver(PnpDeviceObject, Irp);
198 }
199 }
200
201 /* complete the request */
202 Irp->IoStatus.Status = Status;
204
205 return Status;
206}
207
209NTAPI
212 IN PIRP Irp)
213{
215 BOOLEAN ChildDevice;
216 PDEVICE_OBJECT PnpDeviceObject;
217
218 /* check if the device object is a child device */
220
221 /* check for success */
222 if (NT_SUCCESS(Status))
223 {
224 if (!ChildDevice)
225 {
226 /* bus devices dont support internal requests */
227 Irp->IoStatus.Status = STATUS_SUCCESS;
229 return STATUS_SUCCESS;
230 }
231
232 /* get bus enum pnp object */
234
235 /* check for success */
236 if (NT_SUCCESS(Status))
237 {
238 /* skip current location */
240 /* call the pnp device object */
241 return IoCallDriver(PnpDeviceObject, Irp);
242 }
243
244 }
245
246 /* complete the request */
247 Irp->IoStatus.Status = Status;
249
250 return Status;
251
252}
253
255NTAPI
258 IN PIRP Irp)
259{
260 PIO_STACK_LOCATION IoStack;
262
263 /* get current stack location */
265
266 if (IoStack->Parameters.DeviceIoControl.IoControlCode == IOCTL_SWENUM_INSTALL_INTERFACE)
267 {
268 /* install interface */
270 DPRINT("SwDispatchDeviceControl IOCTL_SWENUM_INSTALL_INTERFACE %x\n", Status);
271 }
272 else if (IoStack->Parameters.DeviceIoControl.IoControlCode == IOCTL_SWENUM_REMOVE_INTERFACE)
273 {
274 /* remove interface */
276 DPRINT("SwDispatchDeviceControl IOCTL_SWENUM_REMOVE_INTERFACE %x\n", Status);
277
278 }
279 else if (IoStack->Parameters.DeviceIoControl.IoControlCode == IOCTL_SWENUM_GET_BUS_ID)
280 {
281 /* get bus id */
283 DPRINT("SwDispatchDeviceControl IOCTL_SWENUM_GET_BUS_ID %x\n", Status);
284 }
285 else
286 {
287 DPRINT("SwDispatchDeviceControl Unknown IOCTL %x\n", IoStack->Parameters.DeviceIoControl.IoControlCode);
289 }
290
291 /* store result */
292 Irp->IoStatus.Status = Status;
293
294 /* complete irp */
296
297 /* done */
298 return Status;
299}
300
301
303NTAPI
306 IN PIRP Irp)
307{
309 BOOLEAN ChildDevice;
310
311 /* check if the device object is a child device */
313
314 DPRINT("SwDispatchCreate %x\n", Status);
315
316 /* check for success */
317 if (NT_SUCCESS(Status))
318 {
319 if (ChildDevice)
320 {
321 /* child devices cant create devices */
322 Irp->IoStatus.Status = STATUS_OBJECT_NAME_NOT_FOUND;
325 }
326 /* perform the create request */
328 DPRINT("SwDispatchCreate %x\n", Status);
329 }
330
331 /* check the irp is pending */
332 if (Status != STATUS_PENDING)
333 {
334 /* irp is ok to complete */
335 Irp->IoStatus.Status = Status;
337 }
338
339 return Status;
340}
341
342
344NTAPI
347 IN PIRP Irp)
348{
349 /* just complete the irp */
350 Irp->IoStatus.Status = STATUS_SUCCESS;
351
352 /* complete the irp */
354
355 /* done */
356 return STATUS_SUCCESS;
357
358}
359
361NTAPI
365{
368
369 DPRINT("SWENUM AddDevice\n");
370 /* create the device */
372
373 if (!NT_SUCCESS(Status))
374 {
375 /* failed */
376 return Status;
377 }
378
379 /* create the bus enum object */
381
382 /* check for success */
383 if (NT_SUCCESS(Status))
384 {
385 /* set device flags */
387 FunctionalDeviceObject->Flags &= ~ DO_DEVICE_INITIALIZING;
388 }
389 else
390 {
391 /* failed to create bus enum object */
393 }
394
395 /* done */
396 return Status;
397}
398
399VOID
400NTAPI
403{
404 /* nop */
405}
406
408NTAPI
411 IN PUNICODE_STRING RegistryPathName)
412{
413
414 /* setup add device routine */
415 DriverObject->DriverExtension->AddDevice = SwAddDevice;
416
417 /* setup unload routine */
418 DriverObject->DriverUnload = SwUnload;
419
420 /* misc irp handling routines */
422 DriverObject->MajorFunction[IRP_MJ_CLOSE] = SwDispatchClose;
423 DriverObject->MajorFunction[IRP_MJ_PNP] = SwDispatchPnp;
424 DriverObject->MajorFunction[IRP_MJ_POWER] = SwDispatchPower;
427
428 DPRINT("SWENUM loaded\n");
429 return STATUS_SUCCESS;
430}
431
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
unsigned char BOOLEAN
LONG NTSTATUS
Definition: precomp.h:26
PDEVICE_OBJECT PhysicalDeviceObject
Definition: btrfs_drv.h:1157
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_PENDING
Definition: d3dkmdt.h:43
#define STATUS_NOT_SUPPORTED
Definition: d3dkmdt.h:48
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
DRIVER_INITIALIZE DriverEntry
Definition: condrv.c:21
Status
Definition: gdiplustypes.h:25
KSDDKAPI NTSTATUS NTAPI KsInstallBusEnumInterface(PIRP Irp)
Definition: swenum.c:1805
KSDDKAPI NTSTATUS NTAPI KsIsBusEnumChildDevice(IN PDEVICE_OBJECT DeviceObject, OUT PBOOLEAN ChildDevice)
Definition: swenum.c:1864
KSDDKAPI NTSTATUS NTAPI KsGetBusEnumPnpDeviceObject(IN PDEVICE_OBJECT DeviceObject, IN PDEVICE_OBJECT *PnpDeviceObject)
Definition: swenum.c:1751
KSDDKAPI NTSTATUS NTAPI KsGetBusEnumIdentifier(IN PIRP Irp)
Definition: swenum.c:1403
KSDDKAPI NTSTATUS NTAPI KsServiceBusEnumPnpRequest(IN PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp)
Definition: swenum.c:2026
KSDDKAPI NTSTATUS NTAPI KsServiceBusEnumCreateRequest(IN PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp)
Definition: swenum.c:1897
KSDDKAPI NTSTATUS NTAPI KsRemoveBusEnumInterface(IN PIRP Irp)
Definition: swenum.c:2210
KSDDKAPI NTSTATUS NTAPI KsCreateBusEnumObject(IN PWCHAR BusIdentifier, IN PDEVICE_OBJECT BusDeviceObject, IN PDEVICE_OBJECT PhysicalDeviceObject, IN PDEVICE_OBJECT PnpDeviceObject OPTIONAL, IN REFGUID InterfaceGuid OPTIONAL, IN PWCHAR ServiceRelativePath OPTIONAL)
Definition: swenum.c:1521
#define KSMEDIUMSETID_Standard
Definition: ks.h:306
#define ASSERT(a)
Definition: mode.c:44
_Inout_opt_ PDEVICE_OBJECT _Inout_opt_ PDEVICE_OBJECT * FunctionalDeviceObject
Definition: ndis.h:4641
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
NTSTATUS NTAPI IoCreateDevice(IN PDRIVER_OBJECT DriverObject, IN ULONG DeviceExtensionSize, IN PUNICODE_STRING DeviceName, IN DEVICE_TYPE DeviceType, IN ULONG DeviceCharacteristics, IN BOOLEAN Exclusive, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1031
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
#define IoCompleteRequest
Definition: irp.c:1240
#define IoCallDriver
Definition: irp.c:1225
VOID NTAPI PoStartNextPowerIrp(IN PIRP Irp)
Definition: power.c:758
#define L(x)
Definition: ntvdm.h:50
#define FILE_DEVICE_BUS_EXTENDER
Definition: winioctl.h:87
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:73
struct _IO_STACK_LOCATION::@1575::@1576 DeviceIoControl
union _IO_STACK_LOCATION::@1575 Parameters
NTSTATUS NTAPI SwDispatchDeviceControl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: swenum.c:256
NTSTATUS NTAPI SwDispatchPnp(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: swenum.c:83
NTSTATUS NTAPI SwDispatchSystemControl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: swenum.c:210
NTSTATUS NTAPI SwDispatchPower(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: swenum.c:16
NTSTATUS NTAPI SwDispatchCreate(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: swenum.c:304
NTSTATUS NTAPI SwAddDevice(IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT PhysicalDeviceObject)
Definition: swenum.c:362
VOID NTAPI SwUnload(IN PDRIVER_OBJECT DriverObject)
Definition: swenum.c:401
NTSTATUS NTAPI SwDispatchClose(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: swenum.c:345
#define IOCTL_SWENUM_GET_BUS_ID
Definition: swenum.h:12
#define IOCTL_SWENUM_REMOVE_INTERFACE
Definition: swenum.h:9
#define IOCTL_SWENUM_INSTALL_INTERFACE
Definition: swenum.h:6
#define NTAPI
Definition: typedefs.h:36
#define IN
Definition: typedefs.h:39
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
#define IRP_MN_QUERY_PNP_DEVICE_STATE
#define PNP_DEVICE_NOT_DISABLEABLE
Definition: iotypes.h:1006
#define IO_NO_INCREMENT
Definition: iotypes.h:598
#define IRP_MN_QUERY_RESOURCE_REQUIREMENTS
#define IRP_MN_REMOVE_DEVICE
#define DO_POWER_PAGABLE
#define IRP_MJ_SYSTEM_CONTROL
#define IRP_MN_QUERY_RESOURCES
#define IRP_MN_SET_POWER
#define IRP_MJ_POWER
#define IRP_MN_QUERY_POWER