Added missing STDCALLs
[reactos.git] / reactos / drivers / dd / beep / beep.c
1 /* $Id: beep.c,v 1.6 2000/10/05 19:17:25 ekohl Exp $
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: services/dd/beep/beep.c
6 * PURPOSE: BEEP device driver
7 * PROGRAMMER: Eric Kohl (ekohl@rz-online.de)
8 * UPDATE HISTORY:
9 * 30/01/99 Created
10 * 16/10/99 Minor fixes
11 */
12
13 /* INCLUDES ****************************************************************/
14
15 #include <ddk/ntddk.h>
16 #include <ddk/ntddbeep.h>
17
18 #define NDEBUG
19 #include <internal/debug.h>
20
21
22 /* TYEPEDEFS ***************************************************************/
23
24 typedef struct tagBEEP_DEVICE_EXTENSION
25 {
26 KDPC Dpc;
27 KTIMER Timer;
28 KEVENT Event;
29 BOOL BeepOn;
30 } DEVICE_EXTENSION, *PDEVICE_EXTENSION;
31
32
33 /* FUNCTIONS ***************************************************************/
34
35
36 VOID BeepDPC (PKDPC Dpc, PVOID DeferredContext, PVOID SystemArgument1, PVOID SystemArgument2)
37 {
38 PDEVICE_EXTENSION DeviceExtension = DeferredContext;
39
40 DPRINT ("BeepDPC() called!\n");
41 HalMakeBeep (0);
42 DeviceExtension->BeepOn = FALSE;
43 KeSetEvent (&(DeviceExtension->Event), 0, TRUE);
44
45 DPRINT ("BeepDPC() finished!\n");
46 }
47
48
49 NTSTATUS STDCALL
50 BeepCreate (PDEVICE_OBJECT DeviceObject, PIRP Irp)
51 /*
52 * FUNCTION: Handles user mode requests
53 * ARGUMENTS:
54 * DeviceObject = Device for request
55 * Irp = I/O request packet describing request
56 * RETURNS: Success or failure
57 */
58 {
59 PIO_STACK_LOCATION Stack = IoGetCurrentIrpStackLocation(Irp);
60 NTSTATUS status;
61
62 if (Stack->MajorFunction == IRP_MJ_CREATE)
63 {
64 DPRINT ("BeepCreate() called!\n");
65 Irp->IoStatus.Information = 0;
66 status = STATUS_SUCCESS;
67 }
68 else
69 status = STATUS_NOT_IMPLEMENTED;
70
71 Irp->IoStatus.Status = status;
72 IoCompleteRequest (Irp,IO_NO_INCREMENT);
73 return (status);
74 }
75
76
77 NTSTATUS STDCALL
78 BeepClose(PDEVICE_OBJECT DeviceObject, PIRP Irp)
79 /*
80 * FUNCTION: Handles user mode requests
81 * ARGUMENTS:
82 * DeviceObject = Device for request
83 * Irp = I/O request packet describing request
84 * RETURNS: Success or failure
85 */
86 {
87 PIO_STACK_LOCATION Stack = IoGetCurrentIrpStackLocation (Irp);
88 NTSTATUS status;
89
90 switch (Stack->MajorFunction)
91 {
92 case IRP_MJ_CLOSE:
93 DPRINT ("BeepClose() called!\n");
94 Irp->IoStatus.Information = 0;
95 status = STATUS_SUCCESS;
96 break;
97
98 default:
99 status = STATUS_NOT_IMPLEMENTED;
100 }
101
102 Irp->IoStatus.Status = status;
103 IoCompleteRequest (Irp, IO_NO_INCREMENT);
104 return (status);
105 }
106
107
108 NTSTATUS STDCALL
109 BeepCleanup(PDEVICE_OBJECT DeviceObject, PIRP Irp)
110 /*
111 * FUNCTION: Handles user mode requests
112 * ARGUMENTS:
113 * DeviceObject = Device for request
114 * Irp = I/O request packet describing request
115 * RETURNS: Success or failure
116 */
117 {
118 PIO_STACK_LOCATION Stack = IoGetCurrentIrpStackLocation (Irp);
119 NTSTATUS status;
120
121 if (Stack->MajorFunction == IRP_MJ_CLEANUP)
122 {
123 DPRINT ("BeepCleanup() called!\n");
124 Irp->IoStatus.Information = 0;
125 status = STATUS_SUCCESS;
126 }
127 else
128 status = STATUS_NOT_IMPLEMENTED;
129
130 Irp->IoStatus.Status = status;
131 IoCompleteRequest (Irp, IO_NO_INCREMENT);
132 return (status);
133 }
134
135
136 NTSTATUS STDCALL
137 BeepDeviceControl (PDEVICE_OBJECT DeviceObject, PIRP Irp)
138 /*
139 * FUNCTION: Handles user mode requests
140 * ARGUMENTS:
141 * DeviceObject = Device for request
142 * Irp = I/O request packet describing request
143 * RETURNS: Success or failure
144 */
145 {
146 PIO_STACK_LOCATION Stack = IoGetCurrentIrpStackLocation(Irp);
147 PDEVICE_EXTENSION DeviceExtension;
148 PBEEP_SET_PARAMETERS pbsp;
149 NTSTATUS status;
150
151 DeviceExtension = DeviceObject->DeviceExtension;
152
153 DPRINT ("BeepDeviceControl() called!\n");
154 if (Stack->Parameters.DeviceIoControl.IoControlCode == IOCTL_BEEP_SET)
155 {
156 Irp->IoStatus.Information = 0;
157 if (Stack->Parameters.DeviceIoControl.InputBufferLength == sizeof(BEEP_SET_PARAMETERS))
158 {
159 pbsp = (PBEEP_SET_PARAMETERS)Irp->AssociatedIrp.SystemBuffer;
160
161 if (pbsp->Frequency >= BEEP_FREQUENCY_MINIMUM &&
162 pbsp->Frequency <= BEEP_FREQUENCY_MAXIMUM)
163 {
164 LARGE_INTEGER DueTime;
165
166 DueTime.QuadPart = 0;
167
168 /* do the beep!! */
169 DPRINT ("Beep:\n Freq: %lu Hz\n Dur: %lu ms\n",
170 pbsp->Frequency, pbsp->Duration);
171
172 if (pbsp->Duration >= 0)
173 {
174 DueTime.QuadPart = (LONGLONG)pbsp->Duration * -10000;
175
176 KeSetTimer (&DeviceExtension->Timer,
177 DueTime,
178 &DeviceExtension->Dpc);
179
180 HalMakeBeep (pbsp->Frequency);
181 DeviceExtension->BeepOn = TRUE;
182 KeWaitForSingleObject (&(DeviceExtension->Event),
183 Executive,
184 KernelMode,
185 FALSE,
186 NULL);
187 }
188 else if (pbsp->Duration == (DWORD)-1)
189 {
190 if (DeviceExtension->BeepOn)
191 {
192 HalMakeBeep (0);
193 DeviceExtension->BeepOn = FALSE;
194 }
195 else
196 {
197 HalMakeBeep (pbsp->Frequency);
198 DeviceExtension->BeepOn = TRUE;
199 }
200 }
201
202 DPRINT ("Did the beep!\n");
203
204 status = STATUS_SUCCESS;
205 }
206 else
207 {
208 status = STATUS_INVALID_PARAMETER;
209 }
210 }
211 else
212 {
213 status = STATUS_INVALID_PARAMETER;
214 }
215 }
216 else
217 {
218 status = STATUS_NOT_IMPLEMENTED;
219 }
220
221 Irp->IoStatus.Status = status;
222 IoCompleteRequest (Irp, IO_NO_INCREMENT);
223 return (status);
224 }
225
226
227 NTSTATUS STDCALL
228 BeepUnload(PDRIVER_OBJECT DriverObject)
229 {
230 DPRINT ("BeepUnload() called!\n");
231 return (STATUS_SUCCESS);
232 }
233
234
235 NTSTATUS STDCALL
236 DriverEntry (PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
237 /*
238 * FUNCTION: Called by the system to initalize the driver
239 * ARGUMENTS:
240 * DriverObject = object describing this driver
241 * RegistryPath = path to our configuration entries
242 * RETURNS: Success or failure
243 */
244 {
245 PDEVICE_EXTENSION DeviceExtension;
246 PDEVICE_OBJECT DeviceObject;
247 UNICODE_STRING DeviceName;
248 UNICODE_STRING SymlinkName;
249 NTSTATUS Status;
250
251 DbgPrint ("Beep Device Driver 0.0.2\n");
252
253 DriverObject->MajorFunction[IRP_MJ_CREATE] = BeepCreate;
254 DriverObject->MajorFunction[IRP_MJ_CLOSE] = BeepClose;
255 DriverObject->MajorFunction[IRP_MJ_CLEANUP] = BeepCleanup;
256 DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = BeepDeviceControl;
257 DriverObject->DriverUnload = BeepUnload;
258
259 /* set up device extension */
260 DeviceExtension = DeviceObject->DeviceExtension;
261 DeviceExtension->BeepOn = FALSE;
262
263 KeInitializeDpc (&(DeviceExtension->Dpc),
264 BeepDPC,
265 DeviceExtension);
266 KeInitializeTimer (&(DeviceExtension->Timer));
267 KeInitializeEvent (&(DeviceExtension->Event),
268 SynchronizationEvent,
269 FALSE);
270
271 RtlInitUnicodeString (&DeviceName, L"\\Device\\Beep");
272 Status = IoCreateDevice (DriverObject,
273 sizeof(DEVICE_EXTENSION),
274 &DeviceName,
275 FILE_DEVICE_BEEP,
276 0,
277 FALSE,
278 &DeviceObject);
279 if (NT_SUCCESS(Status))
280 return Status;
281
282 RtlInitUnicodeString (&SymlinkName, L"\\??\\Beep");
283 IoCreateSymbolicLink (&SymlinkName, &DeviceName);
284
285 return (STATUS_SUCCESS);
286 }
287
288 /* EOF */