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 /* TYEPEDEFS ***************************************************************/
24 typedef struct _BEEP_DEVICE_EXTENSION
30 } DEVICE_EXTENSION, *PDEVICE_EXTENSION;
33 /* FUNCTIONS ***************************************************************/
37 PVOID DeferredContext,
38 PVOID SystemArgument1,
39 PVOID SystemArgument2)
41 PDEVICE_EXTENSION DeviceExtension = DeferredContext;
43 DPRINT("BeepDPC() called!\n");
46 DeviceExtension->BeepOn = FALSE;
47 KeSetEvent(&DeviceExtension->Event,
51 DPRINT("BeepDPC() finished!\n");
55 static NTSTATUS STDCALL
56 BeepCreate(PDEVICE_OBJECT DeviceObject,
59 * FUNCTION: Handles user mode requests
61 * DeviceObject = Device for request
62 * Irp = I/O request packet describing request
63 * RETURNS: Success or failure
66 DPRINT("BeepCreate() called!\n");
68 Irp->IoStatus.Status = STATUS_SUCCESS;
69 Irp->IoStatus.Information = 0;
70 IoCompleteRequest(Irp,
73 return(STATUS_SUCCESS);
77 static NTSTATUS STDCALL
78 BeepClose(PDEVICE_OBJECT DeviceObject,
81 * FUNCTION: Handles user mode requests
83 * DeviceObject = Device for request
84 * Irp = I/O request packet describing request
85 * RETURNS: Success or failure
88 PDEVICE_EXTENSION DeviceExtension;
91 DPRINT("BeepClose() called!\n");
93 DeviceExtension = DeviceObject->DeviceExtension;
94 if (DeviceExtension->BeepOn == TRUE)
97 DeviceExtension->BeepOn = FALSE;
98 KeCancelTimer(&DeviceExtension->Timer);
101 Status = STATUS_SUCCESS;
103 Irp->IoStatus.Status = Status;
104 Irp->IoStatus.Information = 0;
105 IoCompleteRequest(Irp,
112 static NTSTATUS STDCALL
113 BeepCleanup(PDEVICE_OBJECT DeviceObject,
116 * FUNCTION: Handles user mode requests
118 * DeviceObject = Device for request
119 * Irp = I/O request packet describing request
120 * RETURNS: Success or failure
123 DPRINT("BeepCleanup() called!\n");
125 Irp->IoStatus.Status = STATUS_SUCCESS;
126 Irp->IoStatus.Information = 0;
127 IoCompleteRequest(Irp,
130 return(STATUS_SUCCESS);
134 static NTSTATUS STDCALL
135 BeepDeviceControl(PDEVICE_OBJECT DeviceObject,
138 * FUNCTION: Handles user mode requests
140 * DeviceObject = Device for request
141 * Irp = I/O request packet describing request
142 * RETURNS: Success or failure
145 PIO_STACK_LOCATION Stack;
146 PDEVICE_EXTENSION DeviceExtension;
147 PBEEP_SET_PARAMETERS BeepParam;
148 LARGE_INTEGER DueTime;
150 DPRINT("BeepDeviceControl() called!\n");
152 DeviceExtension = DeviceObject->DeviceExtension;
153 Stack = IoGetCurrentIrpStackLocation(Irp);
154 BeepParam = (PBEEP_SET_PARAMETERS)Irp->AssociatedIrp.SystemBuffer;
156 Irp->IoStatus.Information = 0;
158 if (Stack->Parameters.DeviceIoControl.IoControlCode != IOCTL_BEEP_SET)
160 Irp->IoStatus.Status = STATUS_NOT_IMPLEMENTED;
161 IoCompleteRequest(Irp,
163 return(STATUS_NOT_IMPLEMENTED);
166 if ((Stack->Parameters.DeviceIoControl.InputBufferLength != sizeof(BEEP_SET_PARAMETERS))
167 || (BeepParam->Frequency < BEEP_FREQUENCY_MINIMUM)
168 || (BeepParam->Frequency > BEEP_FREQUENCY_MAXIMUM))
170 Irp->IoStatus.Status = STATUS_INVALID_PARAMETER;
171 IoCompleteRequest(Irp,
173 return(STATUS_INVALID_PARAMETER);
176 DueTime.QuadPart = 0;
179 DPRINT("Beep:\n Freq: %lu Hz\n Dur: %lu ms\n",
183 if (BeepParam->Duration >= 0)
185 DueTime.QuadPart = (LONGLONG)BeepParam->Duration * -10000;
187 KeSetTimer(&DeviceExtension->Timer,
189 &DeviceExtension->Dpc);
191 HalMakeBeep(BeepParam->Frequency);
192 DeviceExtension->BeepOn = TRUE;
193 KeWaitForSingleObject(&DeviceExtension->Event,
199 else if (BeepParam->Duration == (DWORD)-1)
201 if (DeviceExtension->BeepOn == TRUE)
204 DeviceExtension->BeepOn = FALSE;
208 HalMakeBeep(BeepParam->Frequency);
209 DeviceExtension->BeepOn = TRUE;
213 DPRINT("Did the beep!\n");
215 Irp->IoStatus.Status = STATUS_SUCCESS;
216 IoCompleteRequest(Irp,
218 return(STATUS_SUCCESS);
222 static NTSTATUS STDCALL
223 BeepUnload(PDRIVER_OBJECT DriverObject)
225 DPRINT("BeepUnload() called!\n");
226 return(STATUS_SUCCESS);
231 DriverEntry(PDRIVER_OBJECT DriverObject,
232 PUNICODE_STRING RegistryPath)
234 * FUNCTION: Called by the system to initalize the driver
236 * DriverObject = object describing this driver
237 * RegistryPath = path to our configuration entries
238 * RETURNS: Success or failure
241 PDEVICE_EXTENSION DeviceExtension;
242 PDEVICE_OBJECT DeviceObject;
243 UNICODE_STRING DeviceName = UNICODE_STRING_INITIALIZER(L"\\Device\\Beep");
244 UNICODE_STRING SymlinkName = UNICODE_STRING_INITIALIZER(L"\\??\\Beep");
247 DPRINT("Beep Device Driver 0.0.3\n");
249 DriverObject->Flags = 0;
250 DriverObject->MajorFunction[IRP_MJ_CREATE] = BeepCreate;
251 DriverObject->MajorFunction[IRP_MJ_CLOSE] = BeepClose;
252 DriverObject->MajorFunction[IRP_MJ_CLEANUP] = BeepCleanup;
253 DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = BeepDeviceControl;
254 DriverObject->DriverUnload = BeepUnload;
256 Status = IoCreateDevice(DriverObject,
257 sizeof(DEVICE_EXTENSION),
263 if (!NT_SUCCESS(Status))
266 /* set up device extension */
267 DeviceExtension = DeviceObject->DeviceExtension;
268 DeviceExtension->BeepOn = FALSE;
270 KeInitializeDpc(&DeviceExtension->Dpc,
273 KeInitializeTimer(&DeviceExtension->Timer);
274 KeInitializeEvent(&DeviceExtension->Event,
275 SynchronizationEvent,
278 /* Create the dos device link */
279 IoCreateSymbolicLink(&SymlinkName,
282 return(STATUS_SUCCESS);