1 /* $Id: beep.c,v 1.6 2000/10/05 19:17:25 ekohl 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 #include <ddk/ntddk.h>
16 #include <ddk/ntddbeep.h>
19 #include <internal/debug.h>
22 /* TYEPEDEFS ***************************************************************/
24 typedef struct tagBEEP_DEVICE_EXTENSION
30 } DEVICE_EXTENSION
, *PDEVICE_EXTENSION
;
33 /* FUNCTIONS ***************************************************************/
36 VOID
BeepDPC (PKDPC Dpc
, PVOID DeferredContext
, PVOID SystemArgument1
, PVOID SystemArgument2
)
38 PDEVICE_EXTENSION DeviceExtension
= DeferredContext
;
40 DPRINT ("BeepDPC() called!\n");
42 DeviceExtension
->BeepOn
= FALSE
;
43 KeSetEvent (&(DeviceExtension
->Event
), 0, TRUE
);
45 DPRINT ("BeepDPC() finished!\n");
50 BeepCreate (PDEVICE_OBJECT DeviceObject
, PIRP Irp
)
52 * FUNCTION: Handles user mode requests
54 * DeviceObject = Device for request
55 * Irp = I/O request packet describing request
56 * RETURNS: Success or failure
59 PIO_STACK_LOCATION Stack
= IoGetCurrentIrpStackLocation(Irp
);
62 if (Stack
->MajorFunction
== IRP_MJ_CREATE
)
64 DPRINT ("BeepCreate() called!\n");
65 Irp
->IoStatus
.Information
= 0;
66 status
= STATUS_SUCCESS
;
69 status
= STATUS_NOT_IMPLEMENTED
;
71 Irp
->IoStatus
.Status
= status
;
72 IoCompleteRequest (Irp
,IO_NO_INCREMENT
);
78 BeepClose(PDEVICE_OBJECT DeviceObject
, PIRP Irp
)
80 * FUNCTION: Handles user mode requests
82 * DeviceObject = Device for request
83 * Irp = I/O request packet describing request
84 * RETURNS: Success or failure
87 PIO_STACK_LOCATION Stack
= IoGetCurrentIrpStackLocation (Irp
);
90 switch (Stack
->MajorFunction
)
93 DPRINT ("BeepClose() called!\n");
94 Irp
->IoStatus
.Information
= 0;
95 status
= STATUS_SUCCESS
;
99 status
= STATUS_NOT_IMPLEMENTED
;
102 Irp
->IoStatus
.Status
= status
;
103 IoCompleteRequest (Irp
, IO_NO_INCREMENT
);
109 BeepCleanup(PDEVICE_OBJECT DeviceObject
, PIRP Irp
)
111 * FUNCTION: Handles user mode requests
113 * DeviceObject = Device for request
114 * Irp = I/O request packet describing request
115 * RETURNS: Success or failure
118 PIO_STACK_LOCATION Stack
= IoGetCurrentIrpStackLocation (Irp
);
121 if (Stack
->MajorFunction
== IRP_MJ_CLEANUP
)
123 DPRINT ("BeepCleanup() called!\n");
124 Irp
->IoStatus
.Information
= 0;
125 status
= STATUS_SUCCESS
;
128 status
= STATUS_NOT_IMPLEMENTED
;
130 Irp
->IoStatus
.Status
= status
;
131 IoCompleteRequest (Irp
, IO_NO_INCREMENT
);
137 BeepDeviceControl (PDEVICE_OBJECT DeviceObject
, PIRP Irp
)
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
= IoGetCurrentIrpStackLocation(Irp
);
147 PDEVICE_EXTENSION DeviceExtension
;
148 PBEEP_SET_PARAMETERS pbsp
;
151 DeviceExtension
= DeviceObject
->DeviceExtension
;
153 DPRINT ("BeepDeviceControl() called!\n");
154 if (Stack
->Parameters
.DeviceIoControl
.IoControlCode
== IOCTL_BEEP_SET
)
156 Irp
->IoStatus
.Information
= 0;
157 if (Stack
->Parameters
.DeviceIoControl
.InputBufferLength
== sizeof(BEEP_SET_PARAMETERS
))
159 pbsp
= (PBEEP_SET_PARAMETERS
)Irp
->AssociatedIrp
.SystemBuffer
;
161 if (pbsp
->Frequency
>= BEEP_FREQUENCY_MINIMUM
&&
162 pbsp
->Frequency
<= BEEP_FREQUENCY_MAXIMUM
)
164 LARGE_INTEGER DueTime
;
166 DueTime
.QuadPart
= 0;
169 DPRINT ("Beep:\n Freq: %lu Hz\n Dur: %lu ms\n",
170 pbsp
->Frequency
, pbsp
->Duration
);
172 if (pbsp
->Duration
>= 0)
174 DueTime
.QuadPart
= (LONGLONG
)pbsp
->Duration
* -10000;
176 KeSetTimer (&DeviceExtension
->Timer
,
178 &DeviceExtension
->Dpc
);
180 HalMakeBeep (pbsp
->Frequency
);
181 DeviceExtension
->BeepOn
= TRUE
;
182 KeWaitForSingleObject (&(DeviceExtension
->Event
),
188 else if (pbsp
->Duration
== (DWORD
)-1)
190 if (DeviceExtension
->BeepOn
)
193 DeviceExtension
->BeepOn
= FALSE
;
197 HalMakeBeep (pbsp
->Frequency
);
198 DeviceExtension
->BeepOn
= TRUE
;
202 DPRINT ("Did the beep!\n");
204 status
= STATUS_SUCCESS
;
208 status
= STATUS_INVALID_PARAMETER
;
213 status
= STATUS_INVALID_PARAMETER
;
218 status
= STATUS_NOT_IMPLEMENTED
;
221 Irp
->IoStatus
.Status
= status
;
222 IoCompleteRequest (Irp
, IO_NO_INCREMENT
);
228 BeepUnload(PDRIVER_OBJECT DriverObject
)
230 DPRINT ("BeepUnload() called!\n");
231 return (STATUS_SUCCESS
);
236 DriverEntry (PDRIVER_OBJECT DriverObject
, PUNICODE_STRING RegistryPath
)
238 * FUNCTION: Called by the system to initalize the driver
240 * DriverObject = object describing this driver
241 * RegistryPath = path to our configuration entries
242 * RETURNS: Success or failure
245 PDEVICE_EXTENSION DeviceExtension
;
246 PDEVICE_OBJECT DeviceObject
;
247 UNICODE_STRING DeviceName
;
248 UNICODE_STRING SymlinkName
;
251 DbgPrint ("Beep Device Driver 0.0.2\n");
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
;
259 /* set up device extension */
260 DeviceExtension
= DeviceObject
->DeviceExtension
;
261 DeviceExtension
->BeepOn
= FALSE
;
263 KeInitializeDpc (&(DeviceExtension
->Dpc
),
266 KeInitializeTimer (&(DeviceExtension
->Timer
));
267 KeInitializeEvent (&(DeviceExtension
->Event
),
268 SynchronizationEvent
,
271 RtlInitUnicodeString (&DeviceName
, L
"\\Device\\Beep");
272 Status
= IoCreateDevice (DriverObject
,
273 sizeof(DEVICE_EXTENSION
),
279 if (NT_SUCCESS(Status
))
282 RtlInitUnicodeString (&SymlinkName
, L
"\\??\\Beep");
283 IoCreateSymbolicLink (&SymlinkName
, &DeviceName
);
285 return (STATUS_SUCCESS
);