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>
22 DriverEntry(PDRIVER_OBJECT DriverObject
,
23 PUNICODE_STRING RegistryPath
);
25 /* TYEPEDEFS ***************************************************************/
27 typedef struct _BEEP_DEVICE_EXTENSION
33 } DEVICE_EXTENSION
, *PDEVICE_EXTENSION
;
36 /* FUNCTIONS ***************************************************************/
40 PVOID DeferredContext
,
41 PVOID SystemArgument1
,
42 PVOID SystemArgument2
)
44 PDEVICE_EXTENSION DeviceExtension
= DeferredContext
;
46 DPRINT("BeepDPC() called!\n");
49 DeviceExtension
->BeepOn
= FALSE
;
50 KeSetEvent(&DeviceExtension
->Event
,
54 DPRINT("BeepDPC() finished!\n");
58 static NTSTATUS STDCALL
60 PDEVICE_OBJECT DeviceObject
,
63 * FUNCTION: Handles user mode requests
65 * DeviceObject = Device for request
66 * Irp = I/O request packet describing request
67 * RETURNS: Success or failure
70 DPRINT("BeepCreate() called!\n");
72 Irp
->IoStatus
.Status
= STATUS_SUCCESS
;
73 Irp
->IoStatus
.Information
= 0;
74 IoCompleteRequest(Irp
,
77 return(STATUS_SUCCESS
);
81 static NTSTATUS STDCALL
82 BeepClose(PDEVICE_OBJECT DeviceObject
,
85 * FUNCTION: Handles user mode requests
87 * DeviceObject = Device for request
88 * Irp = I/O request packet describing request
89 * RETURNS: Success or failure
92 PDEVICE_EXTENSION DeviceExtension
;
95 DPRINT("BeepClose() called!\n");
97 DeviceExtension
= DeviceObject
->DeviceExtension
;
98 if (DeviceExtension
->BeepOn
== TRUE
)
101 DeviceExtension
->BeepOn
= FALSE
;
102 KeCancelTimer(&DeviceExtension
->Timer
);
105 Status
= STATUS_SUCCESS
;
107 Irp
->IoStatus
.Status
= Status
;
108 Irp
->IoStatus
.Information
= 0;
109 IoCompleteRequest(Irp
,
116 static NTSTATUS STDCALL
117 BeepCleanup(PDEVICE_OBJECT DeviceObject
,
120 * FUNCTION: Handles user mode requests
122 * DeviceObject = Device for request
123 * Irp = I/O request packet describing request
124 * RETURNS: Success or failure
127 DPRINT("BeepCleanup() called!\n");
129 Irp
->IoStatus
.Status
= STATUS_SUCCESS
;
130 Irp
->IoStatus
.Information
= 0;
131 IoCompleteRequest(Irp
,
134 return(STATUS_SUCCESS
);
138 static NTSTATUS STDCALL
139 BeepDeviceControl(PDEVICE_OBJECT DeviceObject
,
142 * FUNCTION: Handles user mode requests
144 * DeviceObject = Device for request
145 * Irp = I/O request packet describing request
146 * RETURNS: Success or failure
149 PIO_STACK_LOCATION Stack
;
150 PDEVICE_EXTENSION DeviceExtension
;
151 PBEEP_SET_PARAMETERS BeepParam
;
152 LARGE_INTEGER DueTime
;
154 DPRINT("BeepDeviceControl() called!\n");
156 DeviceExtension
= DeviceObject
->DeviceExtension
;
157 Stack
= IoGetCurrentIrpStackLocation(Irp
);
158 BeepParam
= (PBEEP_SET_PARAMETERS
)Irp
->AssociatedIrp
.SystemBuffer
;
160 Irp
->IoStatus
.Information
= 0;
162 if (Stack
->Parameters
.DeviceIoControl
.IoControlCode
!= IOCTL_BEEP_SET
)
164 Irp
->IoStatus
.Status
= STATUS_NOT_IMPLEMENTED
;
165 IoCompleteRequest(Irp
,
167 return(STATUS_NOT_IMPLEMENTED
);
170 if ((Stack
->Parameters
.DeviceIoControl
.InputBufferLength
!= sizeof(BEEP_SET_PARAMETERS
))
171 || (BeepParam
->Frequency
< BEEP_FREQUENCY_MINIMUM
)
172 || (BeepParam
->Frequency
> BEEP_FREQUENCY_MAXIMUM
))
174 Irp
->IoStatus
.Status
= STATUS_INVALID_PARAMETER
;
175 IoCompleteRequest(Irp
,
177 return(STATUS_INVALID_PARAMETER
);
180 DueTime
.QuadPart
= 0;
183 DPRINT("Beep:\n Freq: %lu Hz\n Dur: %lu ms\n",
184 BeepParam
->Frequency
,
185 BeepParam
->Duration
);
186 if (BeepParam
->Duration
>= 0)
188 DueTime
.QuadPart
= (LONGLONG
)BeepParam
->Duration
* -10000;
190 KeSetTimer(&DeviceExtension
->Timer
,
192 &DeviceExtension
->Dpc
);
194 HalMakeBeep(BeepParam
->Frequency
);
195 DeviceExtension
->BeepOn
= TRUE
;
196 KeWaitForSingleObject(&DeviceExtension
->Event
,
202 else if (BeepParam
->Duration
== (DWORD
)-1)
204 if (DeviceExtension
->BeepOn
== TRUE
)
207 DeviceExtension
->BeepOn
= FALSE
;
211 HalMakeBeep(BeepParam
->Frequency
);
212 DeviceExtension
->BeepOn
= TRUE
;
216 DPRINT("Did the beep!\n");
218 Irp
->IoStatus
.Status
= STATUS_SUCCESS
;
219 IoCompleteRequest(Irp
,
221 return(STATUS_SUCCESS
);
226 BeepUnload(PDRIVER_OBJECT DriverObject
)
228 DPRINT("BeepUnload() called!\n");
233 DriverEntry(PDRIVER_OBJECT DriverObject
,
234 PUNICODE_STRING RegistryPath
)
236 * FUNCTION: Called by the system to initalize the driver
238 * DriverObject = object describing this driver
239 * RegistryPath = path to our configuration entries
240 * RETURNS: Success or failure
243 PDEVICE_EXTENSION DeviceExtension
;
244 PDEVICE_OBJECT DeviceObject
;
245 UNICODE_STRING DeviceName
= RTL_CONSTANT_STRING(L
"\\Device\\Beep");
246 UNICODE_STRING SymlinkName
= RTL_CONSTANT_STRING(L
"\\??\\Beep");
249 DPRINT("Beep Device Driver 0.0.3\n");
251 DriverObject
->Flags
= 0;
252 DriverObject
->MajorFunction
[IRP_MJ_CREATE
] = BeepCreate
;
253 DriverObject
->MajorFunction
[IRP_MJ_CLOSE
] = BeepClose
;
254 DriverObject
->MajorFunction
[IRP_MJ_CLEANUP
] = BeepCleanup
;
255 DriverObject
->MajorFunction
[IRP_MJ_DEVICE_CONTROL
] = BeepDeviceControl
;
256 DriverObject
->DriverUnload
= BeepUnload
;
258 Status
= IoCreateDevice(DriverObject
,
259 sizeof(DEVICE_EXTENSION
),
265 if (!NT_SUCCESS(Status
))
268 /* set up device extension */
269 DeviceExtension
= DeviceObject
->DeviceExtension
;
270 DeviceExtension
->BeepOn
= FALSE
;
272 KeInitializeDpc(&DeviceExtension
->Dpc
,
275 KeInitializeTimer(&DeviceExtension
->Timer
);
276 KeInitializeEvent(&DeviceExtension
->Event
,
277 SynchronizationEvent
,
280 /* Create the dos device link */
281 IoCreateSymbolicLink(&SymlinkName
,
284 return(STATUS_SUCCESS
);