ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

swenum.c
Go to the documentation of this file.
00001 /*
00002  * COPYRIGHT:       See COPYING in the top level directory
00003  * PROJECT:         ReactOS Kernel Streaming
00004  * FILE:            drivers/ksfilter/swenum/swenum.c
00005  * PURPOSE:         KS Allocator functions
00006  * PROGRAMMER:      Johannes Anderwald
00007  */
00008 
00009 
00010 #include "precomp.h"
00011 
00012 const GUID KSMEDIUMSETID_Standard = {0x4747B320L, 0x62CE, 0x11CF, {0xA5, 0xD6, 0x28, 0xDB, 0x04, 0xC1, 0x00, 0x00}};
00013 
00014 
00015 NTSTATUS
00016 NTAPI
00017 SwDispatchPower(
00018     IN PDEVICE_OBJECT DeviceObject,
00019     IN PIRP Irp)
00020 {
00021     NTSTATUS Status, PnpStatus;
00022     BOOLEAN ChildDevice;
00023     PIO_STACK_LOCATION IoStack;
00024     PDEVICE_OBJECT PnpDeviceObject = NULL;
00025 
00026     /* get current stack location */
00027     IoStack = IoGetCurrentIrpStackLocation(Irp);
00028 
00029     /* check if the device object is a child device */
00030     Status = KsIsBusEnumChildDevice(DeviceObject, &ChildDevice);
00031 
00032     /* get bus enum pnp object */
00033     PnpStatus = KsGetBusEnumPnpDeviceObject(DeviceObject, &PnpDeviceObject);
00034 
00035     /* check for success */
00036     if (!NT_SUCCESS(Status) || !NT_SUCCESS(PnpStatus))
00037     {
00038         /* start next power irp */
00039         PoStartNextPowerIrp(Irp);
00040 
00041         /* just complete the irp */
00042         Irp->IoStatus.Status = STATUS_SUCCESS;
00043 
00044         /* complete the irp */
00045         IoCompleteRequest(Irp, IO_NO_INCREMENT);
00046 
00047         /* done */
00048         return STATUS_SUCCESS;
00049     }
00050 
00051     if (IoStack->MinorFunction == IRP_MN_SET_POWER || IoStack->MinorFunction == IRP_MN_QUERY_POWER)
00052     {
00053         /* fake success */
00054         Irp->IoStatus.Status = STATUS_SUCCESS;
00055     }
00056 
00057     if (!ChildDevice)
00058     {
00059         /* forward to pnp device object */
00060         PoStartNextPowerIrp(Irp);
00061 
00062         /* skip current location */
00063         IoSkipCurrentIrpStackLocation(Irp);
00064 
00065         /* done */
00066         return PoCallDriver(PnpDeviceObject, Irp);
00067     }
00068 
00069     /* start next power irp */
00070     PoStartNextPowerIrp(Irp);
00071 
00072     /* just complete the irp */
00073     Irp->IoStatus.Status = STATUS_SUCCESS;
00074 
00075     /* complete the irp */
00076     IoCompleteRequest(Irp, IO_NO_INCREMENT);
00077 
00078     /* done */
00079     return STATUS_SUCCESS;
00080 }
00081 
00082 NTSTATUS
00083 NTAPI
00084 SwDispatchPnp(
00085     IN PDEVICE_OBJECT DeviceObject,
00086     IN PIRP Irp)
00087 {
00088     NTSTATUS Status;
00089     BOOLEAN ChildDevice;
00090     PIO_STACK_LOCATION IoStack;
00091     PDEVICE_OBJECT PnpDeviceObject = NULL;
00092 
00093     /* get current stack location */
00094     IoStack = IoGetCurrentIrpStackLocation(Irp);
00095 
00096     /* check if the device object is a child device */
00097     Status = KsIsBusEnumChildDevice(DeviceObject, &ChildDevice);
00098 
00099     /* check for success */
00100     if (!NT_SUCCESS(Status))
00101     {
00102         /* failed */
00103         Irp->IoStatus.Status = Status;
00104         IoCompleteRequest(Irp, IO_NO_INCREMENT);
00105         return Status;
00106     }
00107 
00108     DPRINT("SwDispatchPnp ChildDevice %u Request %x\n", ChildDevice, IoStack->MinorFunction);
00109 
00110     /* let ks handle it */
00111     Status = KsServiceBusEnumPnpRequest(DeviceObject, Irp);
00112 
00113     /* check if the request was for a pdo */
00114     if (!ChildDevice)
00115     {
00116         if (Status != STATUS_NOT_SUPPORTED)
00117         {
00118             /* store result */
00119             Irp->IoStatus.Status = Status;
00120         }
00121 
00122         /* complete request */
00123         IoCompleteRequest(Irp, IO_NO_INCREMENT);
00124 
00125         /* done */
00126         return Status;
00127     }
00128 
00129     DPRINT("SwDispatchPnp KsServiceBusEnumPnpRequest Status %x\n", Status);
00130 
00131     if (NT_SUCCESS(Status))
00132     {
00133         /* invalid request or not supported */
00134         Irp->IoStatus.Status = Status;
00135         IoCompleteRequest(Irp, IO_NO_INCREMENT);
00136         return Status;
00137     }
00138 
00139     /* get bus enum pnp object */
00140     Status = KsGetBusEnumPnpDeviceObject(DeviceObject, &PnpDeviceObject);
00141 
00142     DPRINT("SwDispatchPnp KsGetBusEnumPnpDeviceObject Status %x\n", Status);
00143 
00144     /* check for success */
00145     if (!NT_SUCCESS(Status))
00146     {
00147         /* failed to get pnp object */
00148         Irp->IoStatus.Status = Status;
00149         IoCompleteRequest(Irp, IO_NO_INCREMENT);
00150         return Status;
00151     }
00152 
00153     /* sanity check */
00154     ASSERT(PnpDeviceObject);
00155 
00156     /* get current stack location */
00157     IoStack = IoGetCurrentIrpStackLocation(Irp);
00158 
00159     if (IoStack->MinorFunction == IRP_MN_REMOVE_DEVICE)
00160     {
00161         /* delete the device */
00162         IoDeleteDevice(DeviceObject);
00163     }
00164     else
00165     {
00166         if (IoStack->MinorFunction == IRP_MN_QUERY_RESOURCES || IoStack->MinorFunction == IRP_MN_QUERY_RESOURCE_REQUIREMENTS)
00167         {
00168             /* no resources required */
00169             Irp->IoStatus.Information = 0;
00170             Irp->IoStatus.Status = STATUS_SUCCESS;
00171 
00172             /* skip current location */
00173             IoSkipCurrentIrpStackLocation(Irp);
00174 
00175             /* call the pnp device object */
00176             return IoCallDriver(PnpDeviceObject, Irp);
00177         }
00178 
00179         if (IoStack->MajorFunction == IRP_MN_QUERY_PNP_DEVICE_STATE)
00180         {
00181             /* device cannot be disabled */
00182             Irp->IoStatus.Information |= PNP_DEVICE_NOT_DISABLEABLE;
00183             Irp->IoStatus.Status = STATUS_SUCCESS;
00184 
00185             /* skip current location */
00186             IoSkipCurrentIrpStackLocation(Irp);
00187 
00188             /* call the pnp device object */
00189             return IoCallDriver(PnpDeviceObject, Irp);
00190         }
00191 
00192         if (Status == STATUS_NOT_SUPPORTED)
00193         {
00194             /* skip current location */
00195             IoSkipCurrentIrpStackLocation(Irp);
00196 
00197             /* call the pnp device object */
00198             return IoCallDriver(PnpDeviceObject, Irp);
00199         }
00200     }
00201 
00202     /* complete the request */
00203     Irp->IoStatus.Status = Status;
00204     IoCompleteRequest(Irp, IO_NO_INCREMENT);
00205 
00206     return Status;
00207 }
00208 
00209 NTSTATUS
00210 NTAPI
00211 SwDispatchSystemControl(
00212     IN PDEVICE_OBJECT DeviceObject,
00213     IN PIRP Irp)
00214 {
00215     NTSTATUS Status;
00216     BOOLEAN ChildDevice;
00217     PDEVICE_OBJECT PnpDeviceObject;
00218 
00219     /* check if the device object is a child device */
00220     Status = KsIsBusEnumChildDevice(DeviceObject, &ChildDevice);
00221 
00222     /* check for success */
00223     if (NT_SUCCESS(Status))
00224     {
00225         if (!ChildDevice)
00226         {
00227             /* bus devices dont support internal requests */
00228             Irp->IoStatus.Status = STATUS_SUCCESS;
00229             IoCompleteRequest(Irp, IO_NO_INCREMENT);
00230             return STATUS_SUCCESS;
00231         }
00232 
00233         /* get bus enum pnp object */
00234         Status = KsGetBusEnumPnpDeviceObject(DeviceObject, &PnpDeviceObject);
00235 
00236         /* check for success */
00237         if (NT_SUCCESS(Status))
00238         {
00239             /* skip current location */
00240             IoSkipCurrentIrpStackLocation(Irp);
00241             /* call the pnp device object */
00242             return IoCallDriver(PnpDeviceObject, Irp);
00243         }
00244 
00245     }
00246 
00247     /* complete the request */
00248     Irp->IoStatus.Status = Status;
00249     IoCompleteRequest(Irp, IO_NO_INCREMENT);
00250 
00251     return Status;
00252 
00253 }
00254 
00255 NTSTATUS
00256 NTAPI
00257 SwDispatchDeviceControl(
00258     IN PDEVICE_OBJECT DeviceObject,
00259     IN PIRP Irp)
00260 {
00261     PIO_STACK_LOCATION IoStack;
00262     NTSTATUS Status;
00263 
00264     /* get current stack location */
00265     IoStack = IoGetCurrentIrpStackLocation(Irp);
00266 
00267     if (IoStack->Parameters.DeviceIoControl.IoControlCode == IOCTL_SWENUM_INSTALL_INTERFACE)
00268     {
00269         /* install interface */
00270         Status = KsInstallBusEnumInterface(Irp);
00271         DPRINT("SwDispatchDeviceControl IOCTL_SWENUM_INSTALL_INTERFACE %x\n", Status);
00272     }
00273     else if (IoStack->Parameters.DeviceIoControl.IoControlCode == IOCTL_SWENUM_REMOVE_INTERFACE)
00274     {
00275         /* remove interface */
00276         Status = KsRemoveBusEnumInterface(Irp);
00277         DPRINT("SwDispatchDeviceControl IOCTL_SWENUM_REMOVE_INTERFACE %x\n", Status);
00278 
00279     }
00280     else if (IoStack->Parameters.DeviceIoControl.IoControlCode == IOCTL_SWENUM_GET_BUS_ID)
00281     {
00282         /* get bus id */
00283         Status = KsGetBusEnumIdentifier(Irp);
00284         DPRINT("SwDispatchDeviceControl IOCTL_SWENUM_GET_BUS_ID %x\n", Status);
00285     }
00286     else
00287     {
00288         DPRINT("SwDispatchDeviceControl Unknown IOCTL %x\n", IoStack->Parameters.DeviceIoControl.IoControlCode);
00289         Status = STATUS_INVALID_PARAMETER;
00290     }
00291 
00292     /* store result */
00293     Irp->IoStatus.Status = Status;
00294 
00295     /* complete irp */
00296     IoCompleteRequest(Irp, IO_NO_INCREMENT);
00297 
00298     /* done */
00299     return Status;
00300 }
00301 
00302 
00303 NTSTATUS
00304 NTAPI
00305 SwDispatchCreate(
00306     IN PDEVICE_OBJECT DeviceObject,
00307     IN PIRP Irp)
00308 {
00309     NTSTATUS Status;
00310     BOOLEAN ChildDevice;
00311 
00312     /* check if the device object is a child device */
00313     Status = KsIsBusEnumChildDevice(DeviceObject, &ChildDevice);
00314 
00315     DPRINT("SwDispatchCreate %x\n", Status);
00316 
00317     /* check for success */
00318     if (NT_SUCCESS(Status))
00319     {
00320         if (ChildDevice)
00321         {
00322             /* child devices cant create devices */
00323             Irp->IoStatus.Status = STATUS_OBJECT_NAME_NOT_FOUND;
00324             IoCompleteRequest(Irp, IO_NO_INCREMENT);
00325             return STATUS_OBJECT_NAME_NOT_FOUND;
00326         }
00327         /* perform the create request */
00328         Status = KsServiceBusEnumCreateRequest(DeviceObject, Irp);
00329         DPRINT("SwDispatchCreate %x\n", Status);
00330     }
00331 
00332     /* check the irp is pending */
00333     if (Status != STATUS_PENDING)
00334     {
00335         /* irp is ok to complete */
00336         Irp->IoStatus.Status = Status;
00337         IoCompleteRequest(Irp, IO_NO_INCREMENT);
00338     }
00339 
00340     return Status;
00341 }
00342 
00343 
00344 NTSTATUS
00345 NTAPI
00346 SwDispatchClose(
00347     IN PDEVICE_OBJECT DeviceObject,
00348     IN PIRP Irp)
00349 {
00350     /* just complete the irp */
00351     Irp->IoStatus.Status = STATUS_SUCCESS;
00352 
00353     /* complete the irp */
00354     IoCompleteRequest(Irp, IO_NO_INCREMENT);
00355 
00356     /* done */
00357     return STATUS_SUCCESS;
00358 
00359 }
00360 
00361 NTSTATUS
00362 NTAPI
00363 SwAddDevice(
00364     IN PDRIVER_OBJECT DriverObject,
00365     IN PDEVICE_OBJECT PhysicalDeviceObject)
00366 {
00367     NTSTATUS Status;
00368     PDEVICE_OBJECT FunctionalDeviceObject;
00369 
00370     DPRINT("SWENUM AddDevice\n");
00371     /* create the device */
00372     Status = IoCreateDevice(DriverObject, sizeof(KSDEVICE_HEADER), NULL, FILE_DEVICE_BUS_EXTENDER, 0, FALSE, &FunctionalDeviceObject);
00373 
00374     if (!NT_SUCCESS(Status))
00375     {
00376         /* failed */
00377         return Status;
00378     }
00379 
00380     /* create the bus enum object */
00381     Status = KsCreateBusEnumObject(L"SW", FunctionalDeviceObject, PhysicalDeviceObject, NULL, &KSMEDIUMSETID_Standard, L"Devices");
00382 
00383     /* check for success */
00384     if (NT_SUCCESS(Status))
00385     {
00386         /* set device flags */
00387         FunctionalDeviceObject->Flags |= DO_POWER_PAGABLE;
00388         FunctionalDeviceObject->Flags &= ~ DO_DEVICE_INITIALIZING;
00389     }
00390     else
00391     {
00392         /* failed to create bus enum object */
00393         IoDeleteDevice(FunctionalDeviceObject);
00394     }
00395 
00396     /* done */
00397     return Status;
00398 }
00399 
00400 VOID
00401 NTAPI
00402 SwUnload(
00403     IN  PDRIVER_OBJECT DriverObject)
00404 {
00405     /* nop */
00406 }
00407 
00408 NTSTATUS
00409 NTAPI
00410 DriverEntry(
00411     IN PDRIVER_OBJECT DriverObject,
00412     IN PUNICODE_STRING RegistryPathName)
00413 {
00414 
00415     /* setup add device routine */
00416     DriverObject->DriverExtension->AddDevice = SwAddDevice;
00417 
00418     /* setup unload routine */
00419     DriverObject->DriverUnload = SwUnload;
00420 
00421     /* misc irp handling routines */
00422     DriverObject->MajorFunction[IRP_MJ_CREATE] = SwDispatchCreate;
00423     DriverObject->MajorFunction[IRP_MJ_CLOSE] = SwDispatchClose;
00424     DriverObject->MajorFunction[IRP_MJ_PNP] = SwDispatchPnp;
00425     DriverObject->MajorFunction[IRP_MJ_POWER] = SwDispatchPower;
00426     DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = SwDispatchDeviceControl;
00427     DriverObject->MajorFunction[IRP_MJ_SYSTEM_CONTROL] = SwDispatchSystemControl;
00428 
00429     DPRINT("SWENUM loaded\n");
00430     return STATUS_SUCCESS;
00431 }
00432 

Generated on Fri May 25 2012 04:26:05 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.