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 ****************************************************************/
23 DriverEntry(PDRIVER_OBJECT DriverObject
,
24 PUNICODE_STRING RegistryPath
);
26 /* TYEPEDEFS ***************************************************************/
28 typedef struct _BEEP_DEVICE_EXTENSION
34 } DEVICE_EXTENSION
, *PDEVICE_EXTENSION
;
37 /* FUNCTIONS ***************************************************************/
41 PVOID DeferredContext
,
42 PVOID SystemArgument1
,
43 PVOID SystemArgument2
)
45 PDEVICE_EXTENSION DeviceExtension
= DeferredContext
;
47 DPRINT("BeepDPC() called!\n");
50 DeviceExtension
->BeepOn
= FALSE
;
51 KeSetEvent(&DeviceExtension
->Event
,
55 DPRINT("BeepDPC() finished!\n");
59 static NTSTATUS STDCALL
61 PDEVICE_OBJECT DeviceObject
,
64 * FUNCTION: Handles user mode requests
66 * DeviceObject = Device for request
67 * Irp = I/O request packet describing request
68 * RETURNS: Success or failure
71 DPRINT("BeepCreate() called!\n");
73 Irp
->IoStatus
.Status
= STATUS_SUCCESS
;
74 Irp
->IoStatus
.Information
= 0;
75 IoCompleteRequest(Irp
,
78 return(STATUS_SUCCESS
);
82 static NTSTATUS STDCALL
83 BeepClose(PDEVICE_OBJECT DeviceObject
,
86 * FUNCTION: Handles user mode requests
88 * DeviceObject = Device for request
89 * Irp = I/O request packet describing request
90 * RETURNS: Success or failure
93 PDEVICE_EXTENSION DeviceExtension
;
96 DPRINT("BeepClose() called!\n");
98 DeviceExtension
= DeviceObject
->DeviceExtension
;
99 if (DeviceExtension
->BeepOn
== TRUE
)
102 DeviceExtension
->BeepOn
= FALSE
;
103 KeCancelTimer(&DeviceExtension
->Timer
);
106 Status
= STATUS_SUCCESS
;
108 Irp
->IoStatus
.Status
= Status
;
109 Irp
->IoStatus
.Information
= 0;
110 IoCompleteRequest(Irp
,
117 static NTSTATUS STDCALL
118 BeepCleanup(PDEVICE_OBJECT DeviceObject
,
121 * FUNCTION: Handles user mode requests
123 * DeviceObject = Device for request
124 * Irp = I/O request packet describing request
125 * RETURNS: Success or failure
128 DPRINT("BeepCleanup() called!\n");
130 Irp
->IoStatus
.Status
= STATUS_SUCCESS
;
131 Irp
->IoStatus
.Information
= 0;
132 IoCompleteRequest(Irp
,
135 return(STATUS_SUCCESS
);
139 static NTSTATUS STDCALL
140 BeepDeviceControl(PDEVICE_OBJECT DeviceObject
,
143 * FUNCTION: Handles user mode requests
145 * DeviceObject = Device for request
146 * Irp = I/O request packet describing request
147 * RETURNS: Success or failure
150 PIO_STACK_LOCATION Stack
;
151 PDEVICE_EXTENSION DeviceExtension
;
152 PBEEP_SET_PARAMETERS BeepParam
;
153 LARGE_INTEGER DueTime
;
155 DPRINT("BeepDeviceControl() called!\n");
157 DeviceExtension
= DeviceObject
->DeviceExtension
;
158 Stack
= IoGetCurrentIrpStackLocation(Irp
);
159 BeepParam
= (PBEEP_SET_PARAMETERS
)Irp
->AssociatedIrp
.SystemBuffer
;
161 Irp
->IoStatus
.Information
= 0;
163 if (Stack
->Parameters
.DeviceIoControl
.IoControlCode
!= IOCTL_BEEP_SET
)
165 Irp
->IoStatus
.Status
= STATUS_NOT_IMPLEMENTED
;
166 IoCompleteRequest(Irp
,
168 return(STATUS_NOT_IMPLEMENTED
);
171 if ((Stack
->Parameters
.DeviceIoControl
.InputBufferLength
!= sizeof(BEEP_SET_PARAMETERS
))
172 || (BeepParam
->Frequency
< BEEP_FREQUENCY_MINIMUM
)
173 || (BeepParam
->Frequency
> BEEP_FREQUENCY_MAXIMUM
))
175 Irp
->IoStatus
.Status
= STATUS_INVALID_PARAMETER
;
176 IoCompleteRequest(Irp
,
178 return(STATUS_INVALID_PARAMETER
);
181 DueTime
.QuadPart
= 0;
184 DPRINT("Beep:\n Freq: %lu Hz\n Dur: %lu ms\n",
185 BeepParam
->Frequency
,
186 BeepParam
->Duration
);
187 if (BeepParam
->Duration
> 0)
189 DueTime
.QuadPart
= (LONGLONG
)BeepParam
->Duration
* -10000;
191 KeSetTimer(&DeviceExtension
->Timer
,
193 &DeviceExtension
->Dpc
);
195 HalMakeBeep(BeepParam
->Frequency
);
196 DeviceExtension
->BeepOn
= TRUE
;
197 KeWaitForSingleObject(&DeviceExtension
->Event
,
203 else if (BeepParam
->Duration
== ULONG_MAX
)
205 if (DeviceExtension
->BeepOn
== TRUE
)
208 DeviceExtension
->BeepOn
= FALSE
;
212 HalMakeBeep(BeepParam
->Frequency
);
213 DeviceExtension
->BeepOn
= TRUE
;
217 DPRINT("Did the beep!\n");
219 Irp
->IoStatus
.Status
= STATUS_SUCCESS
;
220 IoCompleteRequest(Irp
,
222 return(STATUS_SUCCESS
);
227 BeepUnload(PDRIVER_OBJECT DriverObject
)
229 DPRINT("BeepUnload() called!\n");
234 DriverEntry(PDRIVER_OBJECT DriverObject
,
235 PUNICODE_STRING RegistryPath
)
237 * FUNCTION: Called by the system to initalize the driver
239 * DriverObject = object describing this driver
240 * RegistryPath = path to our configuration entries
241 * RETURNS: Success or failure
244 PDEVICE_EXTENSION DeviceExtension
;
245 PDEVICE_OBJECT DeviceObject
;
246 UNICODE_STRING DeviceName
= RTL_CONSTANT_STRING(L
"\\Device\\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 return(STATUS_SUCCESS
);