Reactos
1/*
2 * PROJECT: ReactOS Drivers
3 * LICENSE: BSD - See COPYING.ARM in the top level directory
4 * FILE: drivers/sac/driver/dispatch.c
5 * PURPOSE: Driver for the Server Administration Console (SAC) for EMS
6 * PROGRAMMERS: ReactOS Portable Systems Group
7 */
8
9/* INCLUDES *******************************************************************/
10
11#include "sacdrv.h"
12
13/* GLOBALS ********************************************************************/
14
15LONG TimerDpcCount;
16
17/* FUNCTIONS ******************************************************************/
18
19NTSTATUS
20NTAPI
21DispatchDeviceControl(IN PDEVICE_OBJECT DeviceObject,
22 IN PIRP Irp)
23{
24 return STATUS_NOT_IMPLEMENTED;
25}
26
27NTSTATUS
28NTAPI
29DispatchShutdownControl(IN PDEVICE_OBJECT DeviceObject,
30 IN PIRP Irp)
31{
32 return STATUS_NOT_IMPLEMENTED;
33}
34
35NTSTATUS
36NTAPI
37DispatchCreate(IN PSAC_DEVICE_EXTENSION DeviceExtension,
38 IN PIRP Irp)
39{
40 return STATUS_NOT_IMPLEMENTED;
41}
42
43NTSTATUS
44NTAPI
45DispatchClose(IN PSAC_DEVICE_EXTENSION DeviceExtension,
46 IN PIRP Irp)
47{
48 return STATUS_NOT_IMPLEMENTED;
49}
50
51NTSTATUS
52NTAPI
53Dispatch(IN PDEVICE_OBJECT DeviceObject,
54 IN PIRP Irp)
55{
56 return STATUS_NOT_IMPLEMENTED;
57}
58
59VOID
60NTAPI
61TimerDpcRoutine(IN PKDPC Dpc,
62 IN PVOID DeferredContext,
63 IN PVOID SystemArgument1,
64 IN PVOID SystemArgument2)
65{
66 HEADLESS_RSP_GET_BYTE ByteValue;
67 SIZE_T ValueSize;
68 BOOLEAN GotChar;
69 NTSTATUS Status;
70 PSAC_DEVICE_EXTENSION SacExtension;
71
72 /* Update our counter */
73 _InterlockedExchangeAdd(&TimerDpcCount, 1);
74
75 /* Set defaults and loop for new characters */
76 GotChar = FALSE;
77 ValueSize = sizeof(ByteValue);
78 do
79 {
80 /* Ask the kernel for a byte */
81 Status = HeadlessDispatch(HeadlessCmdGetByte,
82 NULL,
83 0,
84 &ByteValue,
85 &ValueSize);
86
87 /* Break out if there's nothing interesting */
88 if (!NT_SUCCESS(Status)) break;
89 if (!ByteValue.Value) break;
90
91 /* Update the serial port buffer */
92 SerialPortBuffer[SerialPortProducerIndex] = ByteValue.Value;
93 GotChar = TRUE;
94
95 /* Update the index, let it roll-over if needed */
96 _InterlockedExchange(&SerialPortProducerIndex,
97 (SerialPortProducerIndex + 1) &
98 (SAC_SERIAL_PORT_BUFFER_SIZE - 1));
99 } while (ByteValue.Value);
100
101 /* Did we get anything */
102 if (GotChar)
103 {
104 /* Signal the worker thread that there is work to do */
105 SacExtension = DeferredContext;
106 KeSetEvent(&SacExtension->Event, SacExtension->PriorityBoost, FALSE);
107 }
108}
109
110VOID
111NTAPI
112UnloadHandler(IN PDRIVER_OBJECT DriverObject)
113{
114 PDEVICE_OBJECT DeviceObject, NextDevice;
115 SAC_DBG(SAC_DBG_ENTRY_EXIT, "SAC UnloadHandler: Entering.\n");
116
117 /* Go over every device part of the driver */
118 DeviceObject = DriverObject->DeviceObject;
119 while (DeviceObject)
120 {
121 /* Free and delete the information about this device */
122 NextDevice = DeviceObject->NextDevice;
123 FreeDeviceData(DeviceObject);
124 IoDeleteDevice(DeviceObject);
125
126 /* Move on to the next one */
127 DeviceObject = NextDevice;
128 }
129
130 /* Free the driver data and exit */
131 FreeGlobalData();
132 SAC_DBG(SAC_DBG_ENTRY_EXIT, "SAC UnloadHandler: Exiting.\n");
133}