Minor update

svn path=/trunk/; revision=2097
This commit is contained in:
Eric Kohl 2001-07-25 08:26:06 +00:00
parent b8cfaa435e
commit 74893f61fb
2 changed files with 173 additions and 173 deletions

View file

@ -1,4 +1,4 @@
/* $Id: beep.c,v 1.7 2001/06/07 20:38:53 ea Exp $ /* $Id: beep.c,v 1.8 2001/07/25 08:26:06 ekohl Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -21,33 +21,41 @@
/* TYEPEDEFS ***************************************************************/ /* TYEPEDEFS ***************************************************************/
typedef struct tagBEEP_DEVICE_EXTENSION typedef struct _BEEP_DEVICE_EXTENSION
{ {
KDPC Dpc; KDPC Dpc;
KTIMER Timer; KTIMER Timer;
KEVENT Event; KEVENT Event;
BOOL BeepOn; BOOLEAN BeepOn;
} DEVICE_EXTENSION, *PDEVICE_EXTENSION; } DEVICE_EXTENSION, *PDEVICE_EXTENSION;
/* FUNCTIONS ***************************************************************/ /* FUNCTIONS ***************************************************************/
VOID BeepDPC (PKDPC Dpc, PVOID DeferredContext, PVOID SystemArgument1, PVOID SystemArgument2) static VOID
BeepDPC(PKDPC Dpc,
PVOID DeferredContext,
PVOID SystemArgument1,
PVOID SystemArgument2)
{ {
PDEVICE_EXTENSION DeviceExtension = DeferredContext; PDEVICE_EXTENSION DeviceExtension = DeferredContext;
DPRINT ("BeepDPC() called!\n"); DPRINT("BeepDPC() called!\n");
HalMakeBeep (0);
HalMakeBeep(0);
DeviceExtension->BeepOn = FALSE; DeviceExtension->BeepOn = FALSE;
KeSetEvent (&(DeviceExtension->Event), 0, TRUE); KeSetEvent(&DeviceExtension->Event,
0,
TRUE);
DPRINT ("BeepDPC() finished!\n"); DPRINT("BeepDPC() finished!\n");
} }
NTSTATUS STDCALL static NTSTATUS STDCALL
BeepCreate (PDEVICE_OBJECT DeviceObject, PIRP Irp) BeepCreate(PDEVICE_OBJECT DeviceObject,
PIRP Irp)
/* /*
* FUNCTION: Handles user mode requests * FUNCTION: Handles user mode requests
* ARGUMENTS: * ARGUMENTS:
@ -56,26 +64,20 @@ BeepCreate (PDEVICE_OBJECT DeviceObject, PIRP Irp)
* RETURNS: Success or failure * RETURNS: Success or failure
*/ */
{ {
PIO_STACK_LOCATION Stack = IoGetCurrentIrpStackLocation(Irp); DPRINT("BeepCreate() called!\n");
NTSTATUS status;
if (Stack->MajorFunction == IRP_MJ_CREATE) Irp->IoStatus.Status = STATUS_SUCCESS;
{
DPRINT ("BeepCreate() called!\n");
Irp->IoStatus.Information = 0; Irp->IoStatus.Information = 0;
status = STATUS_SUCCESS; IoCompleteRequest(Irp,
} IO_NO_INCREMENT);
else
status = STATUS_NOT_IMPLEMENTED;
Irp->IoStatus.Status = status; return(STATUS_SUCCESS);
IoCompleteRequest (Irp,IO_NO_INCREMENT);
return (status);
} }
NTSTATUS STDCALL static NTSTATUS STDCALL
BeepClose(PDEVICE_OBJECT DeviceObject, PIRP Irp) BeepClose(PDEVICE_OBJECT DeviceObject,
PIRP Irp)
/* /*
* FUNCTION: Handles user mode requests * FUNCTION: Handles user mode requests
* ARGUMENTS: * ARGUMENTS:
@ -84,156 +86,151 @@ BeepClose(PDEVICE_OBJECT DeviceObject, PIRP Irp)
* RETURNS: Success or failure * RETURNS: Success or failure
*/ */
{ {
PIO_STACK_LOCATION Stack = IoGetCurrentIrpStackLocation (Irp);
NTSTATUS status;
switch (Stack->MajorFunction)
{
case IRP_MJ_CLOSE:
DPRINT ("BeepClose() called!\n");
Irp->IoStatus.Information = 0;
status = STATUS_SUCCESS;
break;
default:
status = STATUS_NOT_IMPLEMENTED;
}
Irp->IoStatus.Status = status;
IoCompleteRequest (Irp, IO_NO_INCREMENT);
return (status);
}
NTSTATUS STDCALL
BeepCleanup(PDEVICE_OBJECT DeviceObject, PIRP Irp)
/*
* FUNCTION: Handles user mode requests
* ARGUMENTS:
* DeviceObject = Device for request
* Irp = I/O request packet describing request
* RETURNS: Success or failure
*/
{
PIO_STACK_LOCATION Stack = IoGetCurrentIrpStackLocation (Irp);
NTSTATUS status;
if (Stack->MajorFunction == IRP_MJ_CLEANUP)
{
DPRINT ("BeepCleanup() called!\n");
Irp->IoStatus.Information = 0;
status = STATUS_SUCCESS;
}
else
status = STATUS_NOT_IMPLEMENTED;
Irp->IoStatus.Status = status;
IoCompleteRequest (Irp, IO_NO_INCREMENT);
return (status);
}
NTSTATUS STDCALL
BeepDeviceControl (PDEVICE_OBJECT DeviceObject, PIRP Irp)
/*
* FUNCTION: Handles user mode requests
* ARGUMENTS:
* DeviceObject = Device for request
* Irp = I/O request packet describing request
* RETURNS: Success or failure
*/
{
PIO_STACK_LOCATION Stack = IoGetCurrentIrpStackLocation(Irp);
PDEVICE_EXTENSION DeviceExtension; PDEVICE_EXTENSION DeviceExtension;
PBEEP_SET_PARAMETERS pbsp; NTSTATUS Status;
NTSTATUS status;
DPRINT("BeepClose() called!\n");
DeviceExtension = DeviceObject->DeviceExtension; DeviceExtension = DeviceObject->DeviceExtension;
if (DeviceObject->BeepOn == TRUE)
DPRINT ("BeepDeviceControl() called!\n");
if (Stack->Parameters.DeviceIoControl.IoControlCode == IOCTL_BEEP_SET)
{ {
HalMakeBeep(0);
DeviceExtension->BeepOn = FALSE;
KeCancelTimer(&DeviceExtension->Timer);
}
Status = STATUS_SUCCESS;
Irp->IoStatus.Status = Status;
Irp->IoStatus.Information = 0; Irp->IoStatus.Information = 0;
if (Stack->Parameters.DeviceIoControl.InputBufferLength == sizeof(BEEP_SET_PARAMETERS)) IoCompleteRequest(Irp,
{ IO_NO_INCREMENT);
pbsp = (PBEEP_SET_PARAMETERS)Irp->AssociatedIrp.SystemBuffer;
if (pbsp->Frequency >= BEEP_FREQUENCY_MINIMUM && return(Status);
pbsp->Frequency <= BEEP_FREQUENCY_MAXIMUM) }
{
static NTSTATUS STDCALL
BeepCleanup(PDEVICE_OBJECT DeviceObject,
PIRP Irp)
/*
* FUNCTION: Handles user mode requests
* ARGUMENTS:
* DeviceObject = Device for request
* Irp = I/O request packet describing request
* RETURNS: Success or failure
*/
{
DPRINT("BeepCleanup() called!\n");
Irp->IoStatus.Status = STATUS_SUCCESS;
Irp->IoStatus.Information = 0;
IoCompleteRequest(Irp,
IO_NO_INCREMENT);
return(STATUS_SUCCESS);
}
static NTSTATUS STDCALL
BeepDeviceControl(PDEVICE_OBJECT DeviceObject,
PIRP Irp)
/*
* FUNCTION: Handles user mode requests
* ARGUMENTS:
* DeviceObject = Device for request
* Irp = I/O request packet describing request
* RETURNS: Success or failure
*/
{
PIO_STACK_LOCATION Stack;
PDEVICE_EXTENSION DeviceExtension;
PBEEP_SET_PARAMETERS BeepParam;
LARGE_INTEGER DueTime; LARGE_INTEGER DueTime;
DPRINT("BeepDeviceControl() called!\n");
DeviceExtension = DeviceObject->DeviceExtension;
Stack = IoGetCurrentIrpStackLocation(Irp);
BeepParam = (PBEEP_SET_PARAMETERS)Irp->AssociatedIrp.SystemBuffer;
Irp->IoStatus.Information = 0;
if (Stack->Parameters.DeviceIoControl.IoControlCode != IOCTL_BEEP_SET)
{
Irp->IoStatus.Status = STATUS_NOT_IMPLEMENTED;
IoCompleteRequest(Irp,
IO_NO_INCREMENT);
return(STATUS_NOT_IMPLEMENTED);
}
if ((Stack->Parameters.DeviceIoControl.InputBufferLength != sizeof(BEEP_SET_PARAMETERS))
|| (BeepParam->Frequency < BEEP_FREQUENCY_MINIMUM)
|| (BeepParam->Frequency > BEEP_FREQUENCY_MAXIMUM))
{
Irp->IoStatus.Status = STATUS_INVALID_PARAMETER;
IoCompleteRequest(Irp,
IO_NO_INCREMENT);
return(STATUS_INVALID_PARAMETER);
}
DueTime.QuadPart = 0; DueTime.QuadPart = 0;
/* do the beep!! */ /* do the beep!! */
DPRINT ("Beep:\n Freq: %lu Hz\n Dur: %lu ms\n", DPRINT("Beep:\n Freq: %lu Hz\n Dur: %lu ms\n",
pbsp->Frequency, pbsp->Duration); pbsp->Frequency,
pbsp->Duration);
if (pbsp->Duration >= 0) if (BeepParam->Duration >= 0)
{ {
DueTime.QuadPart = (LONGLONG)pbsp->Duration * -10000; DueTime.QuadPart = (LONGLONG)BeepParam->Duration * -10000;
KeSetTimer (&DeviceExtension->Timer, KeSetTimer(&DeviceExtension->Timer,
DueTime, DueTime,
&DeviceExtension->Dpc); &DeviceExtension->Dpc);
HalMakeBeep (pbsp->Frequency); HalMakeBeep(BeepParam->Frequency);
DeviceExtension->BeepOn = TRUE; DeviceExtension->BeepOn = TRUE;
KeWaitForSingleObject (&(DeviceExtension->Event), KeWaitForSingleObject(&DeviceExtension->Event,
Executive, Executive,
KernelMode, KernelMode,
FALSE, FALSE,
NULL); NULL);
} }
else if (pbsp->Duration == (DWORD)-1) else if (BeepParam->Duration == (DWORD)-1)
{ {
if (DeviceExtension->BeepOn) if (DeviceExtension->BeepOn == TRUE)
{ {
HalMakeBeep (0); HalMakeBeep(0);
DeviceExtension->BeepOn = FALSE; DeviceExtension->BeepOn = FALSE;
} }
else else
{ {
HalMakeBeep (pbsp->Frequency); HalMakeBeep(BeepParam->Frequency);
DeviceExtension->BeepOn = TRUE; DeviceExtension->BeepOn = TRUE;
} }
} }
DPRINT ("Did the beep!\n"); DPRINT("Did the beep!\n");
status = STATUS_SUCCESS; Irp->IoStatus.Status = STATUS_SUCCESS;
} IoCompleteRequest(Irp,
else IO_NO_INCREMENT);
{ return(STATUS_SUCCESS);
status = STATUS_INVALID_PARAMETER;
}
}
else
{
status = STATUS_INVALID_PARAMETER;
}
}
else
{
status = STATUS_NOT_IMPLEMENTED;
}
Irp->IoStatus.Status = status;
IoCompleteRequest (Irp, IO_NO_INCREMENT);
return (status);
} }
NTSTATUS STDCALL static NTSTATUS STDCALL
BeepUnload(PDRIVER_OBJECT DriverObject) BeepUnload(PDRIVER_OBJECT DriverObject)
{ {
DPRINT ("BeepUnload() called!\n"); DPRINT("BeepUnload() called!\n");
return (STATUS_SUCCESS); return(STATUS_SUCCESS);
} }
NTSTATUS STDCALL NTSTATUS STDCALL
DriverEntry (PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath) DriverEntry(PDRIVER_OBJECT DriverObject,
PUNICODE_STRING RegistryPath)
/* /*
* FUNCTION: Called by the system to initalize the driver * FUNCTION: Called by the system to initalize the driver
* ARGUMENTS: * ARGUMENTS:
@ -248,7 +245,7 @@ DriverEntry (PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
UNICODE_STRING SymlinkName; UNICODE_STRING SymlinkName;
NTSTATUS Status; NTSTATUS Status;
DbgPrint ("Beep Device Driver 0.0.2\n"); DbgPrint("Beep Device Driver 0.0.3\n");
DriverObject->MajorFunction[IRP_MJ_CREATE] = BeepCreate; DriverObject->MajorFunction[IRP_MJ_CREATE] = BeepCreate;
DriverObject->MajorFunction[IRP_MJ_CLOSE] = BeepClose; DriverObject->MajorFunction[IRP_MJ_CLOSE] = BeepClose;
@ -260,29 +257,32 @@ DriverEntry (PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
DeviceExtension = DeviceObject->DeviceExtension; DeviceExtension = DeviceObject->DeviceExtension;
DeviceExtension->BeepOn = FALSE; DeviceExtension->BeepOn = FALSE;
KeInitializeDpc (&(DeviceExtension->Dpc), KeInitializeDpc(&DeviceExtension->Dpc,
BeepDPC, BeepDPC,
DeviceExtension); DeviceExtension);
KeInitializeTimer (&(DeviceExtension->Timer)); KeInitializeTimer(&DeviceExtension->Timer);
KeInitializeEvent (&(DeviceExtension->Event), KeInitializeEvent(&DeviceExtension->Event,
SynchronizationEvent, SynchronizationEvent,
FALSE); FALSE);
RtlInitUnicodeString (&DeviceName, L"\\Device\\Beep"); RtlInitUnicodeString(&DeviceName,
Status = IoCreateDevice (DriverObject, L"\\Device\\Beep");
Status = IoCreateDevice(DriverObject,
sizeof(DEVICE_EXTENSION), sizeof(DEVICE_EXTENSION),
&DeviceName, &DeviceName,
FILE_DEVICE_BEEP, FILE_DEVICE_BEEP,
0, 0,
FALSE, FALSE,
&DeviceObject); &DeviceObject);
if (NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
return Status; return Status;
RtlInitUnicodeString (&SymlinkName, L"\\??\\Beep"); RtlInitUnicodeString(&SymlinkName,
IoCreateSymbolicLink (&SymlinkName, &DeviceName); L"\\??\\Beep");
IoCreateSymbolicLink(&SymlinkName,
&DeviceName);
return (STATUS_SUCCESS); return(STATUS_SUCCESS);
} }
/* EOF */ /* EOF */

View file

@ -23,7 +23,7 @@ BEGIN
BEGIN BEGIN
VALUE "CompanyName", RES_STR_COMPANY_NAME VALUE "CompanyName", RES_STR_COMPANY_NAME
VALUE "FileDescription", "PC Speaker Device Driver\0" VALUE "FileDescription", "PC Speaker Device Driver\0"
VALUE "FileVersion", "0.0.2\0" VALUE "FileVersion", "0.0.3\0"
VALUE "InternalName", "beep\0" VALUE "InternalName", "beep\0"
VALUE "LegalCopyright", RES_STR_LEGAL_COPYRIGHT VALUE "LegalCopyright", RES_STR_LEGAL_COPYRIGHT
VALUE "OriginalFilename", "beep.sys\0" VALUE "OriginalFilename", "beep.sys\0"