2009-02-20 17:52:47 +00:00
|
|
|
/*
|
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
|
|
* PROJECT: ReactOS Kernel Streaming
|
|
|
|
* FILE: drivers/wdm/audio/sysaudio/dispatcher.c
|
|
|
|
* PURPOSE: System Audio graph builder
|
|
|
|
* PROGRAMMER: Johannes Anderwald
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "sysaudio.h"
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
Dispatch_fnDeviceIoControl(
|
|
|
|
PDEVICE_OBJECT DeviceObject,
|
|
|
|
PIRP Irp)
|
|
|
|
{
|
|
|
|
PIO_STACK_LOCATION IoStack;
|
|
|
|
|
|
|
|
IoStack = IoGetCurrentIrpStackLocation(Irp);
|
|
|
|
if (IoStack->Parameters.DeviceIoControl.IoControlCode == IOCTL_KS_PROPERTY)
|
|
|
|
{
|
|
|
|
return SysAudioHandleProperty(DeviceObject, Irp);
|
|
|
|
}
|
|
|
|
|
2009-03-25 19:14:04 +00:00
|
|
|
/* unsupported request */
|
2009-02-23 23:24:58 +00:00
|
|
|
Irp->IoStatus.Status = STATUS_UNSUCCESSFUL;
|
|
|
|
Irp->IoStatus.Information = 0;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
return STATUS_UNSUCCESSFUL;
|
2009-02-20 17:52:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
Dispatch_fnRead(
|
|
|
|
PDEVICE_OBJECT DeviceObject,
|
|
|
|
PIRP Irp)
|
|
|
|
{
|
2009-03-25 19:14:04 +00:00
|
|
|
/* unsupported request */
|
2009-02-23 23:24:58 +00:00
|
|
|
Irp->IoStatus.Status = STATUS_UNSUCCESSFUL;
|
|
|
|
Irp->IoStatus.Information = 0;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
return STATUS_UNSUCCESSFUL;
|
2009-02-20 17:52:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
Dispatch_fnWrite(
|
|
|
|
PDEVICE_OBJECT DeviceObject,
|
|
|
|
PIRP Irp)
|
|
|
|
{
|
2009-03-25 19:14:04 +00:00
|
|
|
/* unsupported request */
|
2009-02-23 23:24:58 +00:00
|
|
|
Irp->IoStatus.Status = STATUS_UNSUCCESSFUL;
|
|
|
|
Irp->IoStatus.Information = 0;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
return STATUS_UNSUCCESSFUL;
|
2009-02-20 17:52:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
Dispatch_fnFlush(
|
|
|
|
PDEVICE_OBJECT DeviceObject,
|
|
|
|
PIRP Irp)
|
|
|
|
{
|
2009-02-22 18:58:51 +00:00
|
|
|
Irp->IoStatus.Status = STATUS_SUCCESS;
|
|
|
|
Irp->IoStatus.Information = 0;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
2009-02-20 17:52:47 +00:00
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
Dispatch_fnClose(
|
|
|
|
PDEVICE_OBJECT DeviceObject,
|
|
|
|
PIRP Irp)
|
|
|
|
{
|
2009-06-10 18:28:15 +00:00
|
|
|
DPRINT("Dispatch_fnClose called DeviceObject %p Irp %p\n", DeviceObject);
|
2009-02-22 18:58:51 +00:00
|
|
|
|
|
|
|
Irp->IoStatus.Status = STATUS_SUCCESS;
|
|
|
|
Irp->IoStatus.Information = 0;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
2009-02-20 17:52:47 +00:00
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
Dispatch_fnQuerySecurity(
|
|
|
|
PDEVICE_OBJECT DeviceObject,
|
|
|
|
PIRP Irp)
|
|
|
|
{
|
2009-04-19 22:01:57 +00:00
|
|
|
DPRINT("Dispatch_fnQuerySecurity called DeviceObject %p Irp %p\n", DeviceObject);
|
2009-02-20 17:52:47 +00:00
|
|
|
|
2009-02-23 23:24:58 +00:00
|
|
|
Irp->IoStatus.Status = STATUS_UNSUCCESSFUL;
|
|
|
|
Irp->IoStatus.Information = 0;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
return STATUS_UNSUCCESSFUL;
|
2009-02-20 17:52:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
Dispatch_fnSetSecurity(
|
|
|
|
PDEVICE_OBJECT DeviceObject,
|
|
|
|
PIRP Irp)
|
|
|
|
{
|
|
|
|
|
2009-04-19 22:01:57 +00:00
|
|
|
DPRINT("Dispatch_fnSetSecurity called DeviceObject %p Irp %p\n", DeviceObject);
|
2009-02-20 17:52:47 +00:00
|
|
|
|
2009-02-23 23:24:58 +00:00
|
|
|
Irp->IoStatus.Status = STATUS_UNSUCCESSFUL;
|
|
|
|
Irp->IoStatus.Information = 0;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
return STATUS_UNSUCCESSFUL;
|
2009-02-20 17:52:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOLEAN
|
|
|
|
NTAPI
|
|
|
|
Dispatch_fnFastDeviceIoControl(
|
|
|
|
PFILE_OBJECT FileObject,
|
|
|
|
BOOLEAN Wait,
|
|
|
|
PVOID InputBuffer,
|
|
|
|
ULONG InputBufferLength,
|
|
|
|
PVOID OutputBuffer,
|
|
|
|
ULONG OutputBufferLength,
|
|
|
|
ULONG IoControlCode,
|
|
|
|
PIO_STATUS_BLOCK IoStatus,
|
|
|
|
PDEVICE_OBJECT DeviceObject)
|
|
|
|
{
|
2009-04-19 22:01:57 +00:00
|
|
|
DPRINT("Dispatch_fnFastDeviceIoControl called DeviceObject %p Irp %p\n", DeviceObject);
|
2009-02-20 17:52:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BOOLEAN
|
|
|
|
NTAPI
|
|
|
|
Dispatch_fnFastRead(
|
|
|
|
PFILE_OBJECT FileObject,
|
|
|
|
PLARGE_INTEGER FileOffset,
|
|
|
|
ULONG Length,
|
|
|
|
BOOLEAN Wait,
|
|
|
|
ULONG LockKey,
|
|
|
|
PVOID Buffer,
|
|
|
|
PIO_STATUS_BLOCK IoStatus,
|
|
|
|
PDEVICE_OBJECT DeviceObject)
|
|
|
|
{
|
2009-04-19 22:01:57 +00:00
|
|
|
DPRINT("Dispatch_fnFastRead called DeviceObject %p Irp %p\n", DeviceObject);
|
2009-02-20 17:52:47 +00:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOLEAN
|
|
|
|
NTAPI
|
|
|
|
Dispatch_fnFastWrite(
|
|
|
|
PFILE_OBJECT FileObject,
|
|
|
|
PLARGE_INTEGER FileOffset,
|
|
|
|
ULONG Length,
|
|
|
|
BOOLEAN Wait,
|
|
|
|
ULONG LockKey,
|
|
|
|
PVOID Buffer,
|
|
|
|
PIO_STATUS_BLOCK IoStatus,
|
|
|
|
PDEVICE_OBJECT DeviceObject)
|
|
|
|
{
|
2009-04-19 22:01:57 +00:00
|
|
|
DPRINT("Dispatch_fnFastWrite called DeviceObject %p Irp %p\n", DeviceObject);
|
2009-02-20 17:52:47 +00:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static KSDISPATCH_TABLE DispatchTable =
|
|
|
|
{
|
|
|
|
Dispatch_fnDeviceIoControl,
|
|
|
|
Dispatch_fnRead,
|
|
|
|
Dispatch_fnWrite,
|
|
|
|
Dispatch_fnFlush,
|
|
|
|
Dispatch_fnClose,
|
|
|
|
Dispatch_fnQuerySecurity,
|
|
|
|
Dispatch_fnSetSecurity,
|
|
|
|
Dispatch_fnFastDeviceIoControl,
|
|
|
|
Dispatch_fnFastRead,
|
|
|
|
Dispatch_fnFastWrite,
|
|
|
|
};
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
DispatchCreateSysAudio(
|
|
|
|
IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PIRP Irp)
|
|
|
|
{
|
|
|
|
NTSTATUS Status;
|
|
|
|
KSOBJECT_HEADER ObjectHeader;
|
|
|
|
PKSOBJECT_CREATE_ITEM CreateItem;
|
2009-02-21 20:18:44 +00:00
|
|
|
PIO_STACK_LOCATION IoStatus;
|
|
|
|
LPWSTR Buffer;
|
2009-03-25 19:14:04 +00:00
|
|
|
PSYSAUDIODEVEXT DeviceExtension;
|
2009-02-21 20:18:44 +00:00
|
|
|
static LPWSTR KS_NAME_PIN = L"{146F1A80-4791-11D0-A5D6-28DB04C10000}";
|
|
|
|
|
|
|
|
IoStatus = IoGetCurrentIrpStackLocation(Irp);
|
|
|
|
Buffer = IoStatus->FileObject->FileName.Buffer;
|
2009-02-20 17:52:47 +00:00
|
|
|
|
2009-04-03 17:06:16 +00:00
|
|
|
DPRINT("DispatchCreateSysAudio entered\n");
|
2009-02-21 20:18:44 +00:00
|
|
|
|
|
|
|
if (Buffer)
|
|
|
|
{
|
|
|
|
/* is the request for a new pin */
|
|
|
|
if (!wcsncmp(KS_NAME_PIN, Buffer, wcslen(KS_NAME_PIN)))
|
|
|
|
{
|
2009-02-22 18:58:51 +00:00
|
|
|
Status = CreateDispatcher(Irp);
|
2009-04-14 14:59:51 +00:00
|
|
|
DPRINT("Virtual pin Status %x FileObject %p\n", Status, IoStatus->FileObject);
|
2009-02-25 22:30:20 +00:00
|
|
|
|
2009-02-21 20:18:44 +00:00
|
|
|
Irp->IoStatus.Information = 0;
|
2009-02-22 18:58:51 +00:00
|
|
|
Irp->IoStatus.Status = Status;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
return Status;
|
2009-02-21 20:18:44 +00:00
|
|
|
}
|
|
|
|
}
|
2009-02-20 17:52:47 +00:00
|
|
|
|
|
|
|
/* allocate create item */
|
|
|
|
CreateItem = ExAllocatePool(NonPagedPool, sizeof(KSOBJECT_CREATE_ITEM));
|
|
|
|
if (!CreateItem)
|
2009-03-25 19:14:04 +00:00
|
|
|
{
|
|
|
|
Irp->IoStatus.Information = 0;
|
|
|
|
Irp->IoStatus.Status = STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
2009-02-20 17:52:47 +00:00
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
2009-03-25 19:14:04 +00:00
|
|
|
}
|
2009-02-20 17:52:47 +00:00
|
|
|
|
2009-03-25 19:14:04 +00:00
|
|
|
/* get device extension */
|
|
|
|
DeviceExtension = (PSYSAUDIODEVEXT) DeviceObject->DeviceExtension;
|
|
|
|
|
2009-02-20 17:52:47 +00:00
|
|
|
/* zero create struct */
|
|
|
|
RtlZeroMemory(CreateItem, sizeof(KSOBJECT_CREATE_ITEM));
|
|
|
|
|
|
|
|
/* store create context */
|
2009-06-09 14:50:24 +00:00
|
|
|
RtlInitUnicodeString(&CreateItem->ObjectClass, L"SysAudio");
|
2009-02-20 17:52:47 +00:00
|
|
|
|
|
|
|
/* allocate object header */
|
|
|
|
Status = KsAllocateObjectHeader(&ObjectHeader, 1, CreateItem, Irp, &DispatchTable);
|
|
|
|
|
2009-04-19 22:01:57 +00:00
|
|
|
DPRINT("KsAllocateObjectHeader result %x\n", Status);
|
2009-02-22 18:58:51 +00:00
|
|
|
/* complete the irp */
|
|
|
|
Irp->IoStatus.Information = 0;
|
|
|
|
Irp->IoStatus.Status = Status;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
2009-02-20 17:52:47 +00:00
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
SysAudioAllocateDeviceHeader(
|
|
|
|
IN SYSAUDIODEVEXT *DeviceExtension)
|
|
|
|
{
|
|
|
|
NTSTATUS Status;
|
|
|
|
PKSOBJECT_CREATE_ITEM CreateItem;
|
|
|
|
|
|
|
|
/* allocate create item */
|
|
|
|
CreateItem = ExAllocatePool(NonPagedPool, sizeof(KSOBJECT_CREATE_ITEM));
|
|
|
|
if (!CreateItem)
|
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
|
|
|
|
/* initialize create item struct */
|
|
|
|
RtlZeroMemory(CreateItem, sizeof(KSOBJECT_CREATE_ITEM));
|
|
|
|
CreateItem->Create = DispatchCreateSysAudio;
|
|
|
|
RtlInitUnicodeString(&CreateItem->ObjectClass, L"SysAudio");
|
|
|
|
|
|
|
|
Status = KsAllocateDeviceHeader(&DeviceExtension->KsDeviceHeader,
|
|
|
|
1,
|
|
|
|
CreateItem);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2009-03-11 09:30:33 +00:00
|
|
|
NTSTATUS
|
|
|
|
SysAudioOpenKMixer(
|
|
|
|
IN SYSAUDIODEVEXT *DeviceExtension)
|
|
|
|
{
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
|
|
|
UNICODE_STRING DeviceName = RTL_CONSTANT_STRING(L"\\Device\\kmixer");
|
|
|
|
UNICODE_STRING DevicePath = RTL_CONSTANT_STRING(L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\kmixer");
|
|
|
|
|
|
|
|
Status = ZwLoadDriver(&DevicePath);
|
|
|
|
|
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
Status = OpenDevice(&DeviceName, &DeviceExtension->KMixerHandle, &DeviceExtension->KMixerFileObject);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
DeviceExtension->KMixerHandle = NULL;
|
|
|
|
DeviceExtension->KMixerFileObject = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DPRINT("Status %lx KMixerHandle %p KMixerFileObject %p\n", Status, DeviceExtension->KMixerHandle, DeviceExtension->KMixerFileObject);
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|