[YAROTOWS] Reintegrate the branch. For a brighter future.
[reactos.git] / rosapps / drivers / green / dispatch.c
1 /*
2 * PROJECT: ReactOS VT100 emulator
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: drivers/base/green/dispatch.c
5 * PURPOSE: Dispatch routines
6 * PROGRAMMERS: Copyright 2005-2006 Hervé Poussineau (hpoussin@reactos.org)
7 */
8
9 #include "green.h"
10
11 #define NDEBUG
12 #include <debug.h>
13
14 NTSTATUS NTAPI
15 GreenDispatch(
16 IN PDEVICE_OBJECT DeviceObject,
17 IN PIRP Irp)
18 {
19 ULONG MajorFunction;
20 GREEN_DEVICE_TYPE DeviceType;
21 ULONG_PTR Information;
22 NTSTATUS Status;
23
24 MajorFunction = IoGetCurrentIrpStackLocation(Irp)->MajorFunction;
25 DeviceType = ((PCOMMON_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->Type;
26
27 Information = Irp->IoStatus.Information;
28 Status = Irp->IoStatus.Status;
29
30 DPRINT("Dispatching major function 0x%lx, DeviceType %u\n",
31 MajorFunction, DeviceType);
32
33 if (DeviceType == PassThroughFDO)
34 {
35 IoSkipCurrentIrpStackLocation(Irp);
36 return IoCallDriver(((PCOMMON_FDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->LowerDevice, Irp);
37 }
38 else if (MajorFunction == IRP_MJ_CREATE && (DeviceType == GreenFDO || DeviceType == KeyboardPDO || DeviceType == ScreenPDO))
39 return GreenCreate(DeviceObject, Irp);
40 else if (MajorFunction == IRP_MJ_CLOSE && (DeviceType == GreenFDO || DeviceType == KeyboardPDO || DeviceType == ScreenPDO))
41 return GreenClose(DeviceObject, Irp);
42 else if ((MajorFunction == IRP_MJ_CREATE || MajorFunction == IRP_MJ_CLOSE || MajorFunction == IRP_MJ_CLEANUP)
43 && (DeviceType == KeyboardFDO || DeviceType == ScreenFDO))
44 {
45 IoSkipCurrentIrpStackLocation(Irp);
46 return IoCallDriver(((PCOMMON_FDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->LowerDevice, Irp);
47 }
48 else if (MajorFunction == IRP_MJ_INTERNAL_DEVICE_CONTROL && DeviceType == GreenFDO)
49 {
50 return KeyboardInternalDeviceControl(
51 ((PGREEN_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->KeyboardFdo,
52 Irp);
53 }
54 else if (MajorFunction == IRP_MJ_INTERNAL_DEVICE_CONTROL && DeviceType == KeyboardFDO)
55 return KeyboardInternalDeviceControl(DeviceObject, Irp);
56 else if (MajorFunction == IRP_MJ_DEVICE_CONTROL && DeviceType == GreenFDO)
57 {
58 return ScreenDeviceControl(
59 ((PGREEN_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->ScreenFdo,
60 Irp);
61 }
62 else if (MajorFunction == IRP_MJ_DEVICE_CONTROL && DeviceType == ScreenFDO)
63 return ScreenDeviceControl(DeviceObject, Irp);
64 else if (MajorFunction == IRP_MJ_WRITE && DeviceType == ScreenFDO)
65 return ScreenWrite(DeviceObject, Irp);
66 else if (MajorFunction == IRP_MJ_PNP && (DeviceType == KeyboardFDO || DeviceType == ScreenFDO))
67 {
68 IoSkipCurrentIrpStackLocation(Irp);
69 return IoCallDriver(((PCOMMON_FDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->LowerDevice, Irp);
70 }
71 else if (MajorFunction == IRP_MJ_PNP && (DeviceType == GreenFDO || DeviceType == KeyboardPDO || DeviceType == ScreenPDO))
72 return GreenPnp(DeviceObject, Irp);
73 else if (MajorFunction == IRP_MJ_POWER && DeviceType == GreenFDO)
74 return GreenPower(DeviceObject, Irp);
75 else
76 {
77 DPRINT1("Unknown combination: MajorFunction 0x%lx, DeviceType %d\n",
78 MajorFunction, DeviceType);
79 switch (DeviceType)
80 {
81 case KeyboardFDO:
82 case ScreenFDO:
83 {
84 IoSkipCurrentIrpStackLocation(Irp);
85 return IoCallDriver(((PCOMMON_FDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->LowerDevice, Irp);
86 }
87 case GreenFDO:
88 {
89 PDRIVER_OBJECT DriverObject;
90 PGREEN_DRIVER_EXTENSION DriverExtension;
91 DriverObject = DeviceObject->DriverObject;
92 DriverExtension = IoGetDriverObjectExtension(DriverObject, DriverObject);
93 IoSkipCurrentIrpStackLocation(Irp);
94 return IoCallDriver(DriverExtension->LowerDevice, Irp);
95 }
96 default:
97 ASSERT(FALSE);
98 }
99 }
100
101 Irp->IoStatus.Information = Information;
102 Irp->IoStatus.Status = Status;
103 IoCompleteRequest (Irp, IO_NO_INCREMENT);
104 return Status;
105 }