1 /* $Id: beep.c,v 1.13 2002/09/07 15:11:58 chorns Exp $
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)
10 * 16/10/99 Minor fixes
13 /* INCLUDES ****************************************************************/
15 #define NTOS_KERNEL_MODE
17 #include <ddk/ntddbeep.h>
23 /* TYEPEDEFS ***************************************************************/
25 typedef struct _BEEP_DEVICE_EXTENSION
31 } DEVICE_EXTENSION
, *PDEVICE_EXTENSION
;
34 /* FUNCTIONS ***************************************************************/
38 PVOID DeferredContext
,
39 PVOID SystemArgument1
,
40 PVOID SystemArgument2
)
42 PDEVICE_EXTENSION DeviceExtension
= DeferredContext
;
44 DPRINT("BeepDPC() called!\n");
47 DeviceExtension
->BeepOn
= FALSE
;
48 KeSetEvent(&DeviceExtension
->Event
,
52 DPRINT("BeepDPC() finished!\n");
56 static NTSTATUS STDCALL
57 BeepCreate(PDEVICE_OBJECT DeviceObject
,
60 * FUNCTION: Handles user mode requests
62 * DeviceObject = Device for request
63 * Irp = I/O request packet describing request
64 * RETURNS: Success or failure
67 DPRINT("BeepCreate() called!\n");
69 Irp
->IoStatus
.Status
= STATUS_SUCCESS
;
70 Irp
->IoStatus
.Information
= 0;
71 IoCompleteRequest(Irp
,
74 return(STATUS_SUCCESS
);
78 static NTSTATUS STDCALL
79 BeepClose(PDEVICE_OBJECT DeviceObject
,
82 * FUNCTION: Handles user mode requests
84 * DeviceObject = Device for request
85 * Irp = I/O request packet describing request
86 * RETURNS: Success or failure
89 PDEVICE_EXTENSION DeviceExtension
;
92 DPRINT("BeepClose() called!\n");
94 DeviceExtension
= DeviceObject
->DeviceExtension
;
95 if (DeviceExtension
->BeepOn
== TRUE
)
98 DeviceExtension
->BeepOn
= FALSE
;
99 KeCancelTimer(&DeviceExtension
->Timer
);
102 Status
= STATUS_SUCCESS
;
104 Irp
->IoStatus
.Status
= Status
;
105 Irp
->IoStatus
.Information
= 0;
106 IoCompleteRequest(Irp
,
113 static NTSTATUS STDCALL
114 BeepCleanup(PDEVICE_OBJECT DeviceObject
,
117 * FUNCTION: Handles user mode requests
119 * DeviceObject = Device for request
120 * Irp = I/O request packet describing request
121 * RETURNS: Success or failure
124 DPRINT("BeepCleanup() called!\n");
126 Irp
->IoStatus
.Status
= STATUS_SUCCESS
;
127 Irp
->IoStatus
.Information
= 0;
128 IoCompleteRequest(Irp
,
131 return(STATUS_SUCCESS
);
135 static NTSTATUS STDCALL
136 BeepDeviceControl(PDEVICE_OBJECT DeviceObject
,
139 * FUNCTION: Handles user mode requests
141 * DeviceObject = Device for request
142 * Irp = I/O request packet describing request
143 * RETURNS: Success or failure
146 PIO_STACK_LOCATION Stack
;
147 PDEVICE_EXTENSION DeviceExtension
;
148 PBEEP_SET_PARAMETERS BeepParam
;
149 LARGE_INTEGER DueTime
;
151 DPRINT("BeepDeviceControl() called!\n");
153 DeviceExtension
= DeviceObject
->DeviceExtension
;
154 Stack
= IoGetCurrentIrpStackLocation(Irp
);
155 BeepParam
= (PBEEP_SET_PARAMETERS
)Irp
->AssociatedIrp
.SystemBuffer
;
157 Irp
->IoStatus
.Information
= 0;
159 if (Stack
->Parameters
.DeviceIoControl
.IoControlCode
!= IOCTL_BEEP_SET
)
161 Irp
->IoStatus
.Status
= STATUS_NOT_IMPLEMENTED
;
162 IoCompleteRequest(Irp
,
164 return(STATUS_NOT_IMPLEMENTED
);
167 if ((Stack
->Parameters
.DeviceIoControl
.InputBufferLength
!= sizeof(BEEP_SET_PARAMETERS
))
168 || (BeepParam
->Frequency
< BEEP_FREQUENCY_MINIMUM
)
169 || (BeepParam
->Frequency
> BEEP_FREQUENCY_MAXIMUM
))
171 Irp
->IoStatus
.Status
= STATUS_INVALID_PARAMETER
;
172 IoCompleteRequest(Irp
,
174 return(STATUS_INVALID_PARAMETER
);
177 DueTime
.QuadPart
= 0;
180 DPRINT("Beep:\n Freq: %lu Hz\n Dur: %lu ms\n",
184 if (BeepParam
->Duration
>= 0)
186 DueTime
.QuadPart
= (LONGLONG
)BeepParam
->Duration
* -10000;
188 KeSetTimer(&DeviceExtension
->Timer
,
190 &DeviceExtension
->Dpc
);
192 HalMakeBeep(BeepParam
->Frequency
);
193 DeviceExtension
->BeepOn
= TRUE
;
194 KeWaitForSingleObject(&DeviceExtension
->Event
,
200 else if (BeepParam
->Duration
== (DWORD
)-1)
202 if (DeviceExtension
->BeepOn
== TRUE
)
205 DeviceExtension
->BeepOn
= FALSE
;
209 HalMakeBeep(BeepParam
->Frequency
);
210 DeviceExtension
->BeepOn
= TRUE
;
214 DPRINT("Did the beep!\n");
216 Irp
->IoStatus
.Status
= STATUS_SUCCESS
;
217 IoCompleteRequest(Irp
,
219 return(STATUS_SUCCESS
);
223 static NTSTATUS STDCALL
224 BeepUnload(PDRIVER_OBJECT DriverObject
)
226 DPRINT("BeepUnload() called!\n");
227 return(STATUS_SUCCESS
);
232 DriverEntry(PDRIVER_OBJECT DriverObject
,
233 PUNICODE_STRING RegistryPath
)
235 * FUNCTION: Called by the system to initalize the driver
237 * DriverObject = object describing this driver
238 * RegistryPath = path to our configuration entries
239 * RETURNS: Success or failure
242 PDEVICE_EXTENSION DeviceExtension
;
243 PDEVICE_OBJECT DeviceObject
;
244 UNICODE_STRING DeviceName
= UNICODE_STRING_INITIALIZER(L
"\\Device\\Beep");
245 UNICODE_STRING SymlinkName
= UNICODE_STRING_INITIALIZER(L
"\\??\\Beep");
248 DPRINT("Beep Device Driver 0.0.3\n");
250 DriverObject
->Flags
= 0;
251 DriverObject
->MajorFunction
[IRP_MJ_CREATE
] = BeepCreate
;
252 DriverObject
->MajorFunction
[IRP_MJ_CLOSE
] = BeepClose
;
253 DriverObject
->MajorFunction
[IRP_MJ_CLEANUP
] = BeepCleanup
;
254 DriverObject
->MajorFunction
[IRP_MJ_DEVICE_CONTROL
] = BeepDeviceControl
;
255 DriverObject
->DriverUnload
= BeepUnload
;
257 Status
= IoCreateDevice(DriverObject
,
258 sizeof(DEVICE_EXTENSION
),
264 if (!NT_SUCCESS(Status
))
267 /* set up device extension */
268 DeviceExtension
= DeviceObject
->DeviceExtension
;
269 DeviceExtension
->BeepOn
= FALSE
;
271 KeInitializeDpc(&DeviceExtension
->Dpc
,
274 KeInitializeTimer(&DeviceExtension
->Timer
);
275 KeInitializeEvent(&DeviceExtension
->Event
,
276 SynchronizationEvent
,
279 /* Create the dos device link */
280 IoCreateSymbolicLink(&SymlinkName
,
283 return(STATUS_SUCCESS
);