ReactOS  0.4.14-dev-614-gbfd8a84
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 
12 const GUID KSMEDIUMSETID_Standard = {0x4747B320L, 0x62CE, 0x11CF, {0xA5, 0xD6, 0x28, 0xDB, 0x04, 0xC1, 0x00, 0x00}};
13 
15 NTAPI
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 
50  if (IoStack->MinorFunction == IRP_MN_SET_POWER || IoStack->MinorFunction == IRP_MN_QUERY_POWER)
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 
82 NTAPI
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 */
139  Status = KsGetBusEnumPnpDeviceObject(DeviceObject, &PnpDeviceObject);
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;
149  return 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 
208 NTSTATUS
209 NTAPI
212  IN PIRP Irp)
213 {
215  BOOLEAN ChildDevice;
216  PDEVICE_OBJECT PnpDeviceObject;
217 
218  /* check if the device object is a child device */
219  Status = KsIsBusEnumChildDevice(DeviceObject, &ChildDevice);
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 */
233  Status = KsGetBusEnumPnpDeviceObject(DeviceObject, &PnpDeviceObject);
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 
254 NTSTATUS
255 NTAPI
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 
302 NTSTATUS
303 NTAPI
306  IN PIRP Irp)
307 {
309  BOOLEAN ChildDevice;
310 
311  /* check if the device object is a child device */
312  Status = KsIsBusEnumChildDevice(DeviceObject, &ChildDevice);
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 
343 NTSTATUS
344 NTAPI
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 
360 NTSTATUS
361 NTAPI
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 */
388  }
389  else
390  {
391  /* failed to create bus enum object */
393  }
394 
395  /* done */
396  return Status;
397 }
398 
399 VOID
400 NTAPI
403 {
404  /* nop */
405 }
406 
407 NTSTATUS
408 NTAPI
411  IN PUNICODE_STRING RegistryPathName)
412 {
413 
414  /* setup add device routine */
416 
417  /* setup unload routine */
419 
420  /* misc irp handling routines */
427 
428  DPRINT("SWENUM loaded\n");
429  return STATUS_SUCCESS;
430 }
431 
#define DO_DEVICE_INITIALIZING
Definition: env_spec_w32.h:399
NTSTATUS NTAPI SwDispatchCreate(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: swenum.c:304
#define DO_POWER_PAGABLE
#define IN
Definition: typedefs.h:38
KSDDKAPI NTSTATUS NTAPI KsRemoveBusEnumInterface(IN PIRP Irp)
Definition: swenum.c:2205
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
#define IRP_MN_QUERY_RESOURCES
#define IRP_MN_REMOVE_DEVICE
#define IOCTL_SWENUM_INSTALL_INTERFACE
Definition: swenum.h:6
NTSTATUS NTAPI SwDispatchSystemControl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: swenum.c:210
NTSTATUS NTAPI DriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPathName)
Definition: swenum.c:409
#define IRP_MN_QUERY_POWER
NTSTATUS NTAPI PoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp)
Definition: power.c:485
NTSTATUS NTAPI SwDispatchPower(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: swenum.c:16
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
NTSTATUS NTAPI SwDispatchClose(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: swenum.c:345
#define IRP_MN_QUERY_RESOURCE_REQUIREMENTS
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI SwDispatchDeviceControl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: swenum.c:256
PDEVICE_OBJECT PhysicalDeviceObject
Definition: btrfs_drv.h:1122
#define IOCTL_SWENUM_GET_BUS_ID
Definition: swenum.h:12
KSDDKAPI NTSTATUS NTAPI KsServiceBusEnumCreateRequest(IN PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp)
Definition: swenum.c:1891
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
PDRIVER_EXTENSION DriverExtension
Definition: iotypes.h:2174
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
#define IoCompleteRequest
Definition: irp.c:1240
void DPRINT(...)
Definition: polytest.cpp:61
KSDDKAPI NTSTATUS NTAPI KsGetBusEnumIdentifier(IN PIRP Irp)
Definition: swenum.c:1397
NTSTATUS NTAPI SwAddDevice(IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT PhysicalDeviceObject)
Definition: swenum.c:362
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
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:1515
#define PNP_DEVICE_NOT_DISABLEABLE
Definition: iotypes.h:969
VOID NTAPI SwUnload(IN PDRIVER_OBJECT DriverObject)
Definition: swenum.c:401
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define IRP_MJ_POWER
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
KSDDKAPI NTSTATUS NTAPI KsServiceBusEnumPnpRequest(IN PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp)
Definition: swenum.c:2020
static const WCHAR L[]
Definition: oid.c:1250
PDRIVER_UNLOAD DriverUnload
Definition: iotypes.h:2180
#define IRP_MN_SET_POWER
KSDDKAPI NTSTATUS NTAPI KsGetBusEnumPnpDeviceObject(IN PDEVICE_OBJECT DeviceObject, IN PDEVICE_OBJECT *PnpDeviceObject)
Definition: swenum.c:1745
#define IRP_MJ_SYSTEM_CONTROL
Status
Definition: gdiplustypes.h:24
KSDDKAPI NTSTATUS NTAPI KsInstallBusEnumInterface(PIRP Irp)
Definition: swenum.c:1799
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
PDRIVER_ADD_DEVICE AddDevice
Definition: iotypes.h:2112
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
VOID NTAPI PoStartNextPowerIrp(IN PIRP Irp)
Definition: power.c:626
KSDDKAPI NTSTATUS NTAPI KsIsBusEnumChildDevice(IN PDEVICE_OBJECT DeviceObject, OUT PBOOLEAN ChildDevice)
Definition: swenum.c:1858
_Inout_opt_ PDEVICE_OBJECT _Inout_opt_ PDEVICE_OBJECT * FunctionalDeviceObject
Definition: ndis.h:4640
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
NTSTATUS NTAPI SwDispatchPnp(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: swenum.c:83
#define IOCTL_SWENUM_REMOVE_INTERFACE
Definition: swenum.h:9
PDRIVER_DISPATCH MajorFunction[IRP_MJ_MAXIMUM_FUNCTION+1]
Definition: iotypes.h:2181
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:409
#define IO_NO_INCREMENT
Definition: iotypes.h:566
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
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define FILE_DEVICE_BUS_EXTENDER
Definition: winioctl.h:147
#define IRP_MN_QUERY_PNP_DEVICE_STATE
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52
const GUID KSMEDIUMSETID_Standard
Definition: swenum.c:12