ReactOS  0.4.14-dev-293-g2b39b42
deviface.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS Kernel Streaming
4  * FILE: drivers/wdm/audio/legacy/wdmaud/deviface.c
5  * PURPOSE: System Audio graph builder
6  * PROGRAMMER: Andrew Greenwood
7  * Johannes Anderwald
8  */
9 
10 #include "wdmaud.h"
11 
12 #define NDEBUG
13 #include <debug.h>
14 
19 {
24 
27 
32  NULL,
33  0,
34  0,
35  FILE_OPEN,
37  NULL,
38  0,
40  NULL,
42 
43  return Status;
44 }
45 
47 NTAPI
51 {
53 
54  DPRINT1("DeviceInterfaceChangeCallback called %p\n", Event);
55  DbgBreakPoint();
56  return STATUS_SUCCESS;
57 }
58 
61  IN PWDMAUD_DEVICE_EXTENSION DeviceExtension,
63 {
65  ULONG Length;
66 
67  DPRINT1("WdmAudOpenSysAudioDeviceInterfaces called\n");
68 
69  while(*SymbolicLinkList)
70  {
73  if (!Entry)
74  {
76  }
77 
78  Entry->SymbolicLink.Length = Length * sizeof(WCHAR);
79  Entry->SymbolicLink.MaximumLength = Length * sizeof(WCHAR);
80  Entry->SymbolicLink.Buffer = (LPWSTR) (Entry + 1);
81  wcscpy(Entry->SymbolicLink.Buffer, SymbolicLinkList);
82 
83  InsertTailList(&DeviceExtension->SysAudioDeviceList, &Entry->Entry);
84 
85  DeviceExtension->NumSysAudioDevices++;
87  }
88  return STATUS_SUCCESS;
89 }
90 
91 
95  IN PWDMAUD_DEVICE_EXTENSION DeviceExtension)
96 {
100  ULONG Length;
101  HANDLE hSysAudio;
103  UNICODE_STRING DeviceName = RTL_CONSTANT_STRING(L"\\Device\\sysaudio\\GLOBAL");
104 
105  if (DeviceExtension->DeviceInterfaceSupport)
106  {
108  NULL,
109  0,
111 
112  if (NT_SUCCESS(Status))
113  {
116  }
117 
118 
122  DeviceObject->DriverObject,
124  (PVOID)DeviceExtension,
125  &DeviceExtension->SysAudioNotification);
126  }
127  else
128  {
130  if (!Entry)
131  {
133  }
134 
135 
136  Length = wcslen(DeviceName.Buffer) + 1;
137  Entry->SymbolicLink.Length = 0;
138  Entry->SymbolicLink.MaximumLength = Length * sizeof(WCHAR);
139  Entry->SymbolicLink.Buffer = AllocateItem(NonPagedPool, Entry->SymbolicLink.MaximumLength);
140 
141  if (!Entry->SymbolicLink.Buffer)
142  {
143  FreeItem(Entry);
145  }
146 
148 
149  if (!NT_SUCCESS(Status))
150  {
151  FreeItem(Entry->SymbolicLink.Buffer);
152  FreeItem(Entry);
153  return Status;
154  }
155 
156  DPRINT("Opening device %S\n", Entry->SymbolicLink.Buffer);
157  Status = WdmAudOpenSysAudioDevice(Entry->SymbolicLink.Buffer, &hSysAudio);
158  if (!NT_SUCCESS(Status))
159  {
160  DPRINT1("Failed to open sysaudio %x\n", Status);
161  FreeItem(Entry->SymbolicLink.Buffer);
162  FreeItem(Entry);
163  return Status;
164  }
165 
166  InsertTailList(&DeviceExtension->SysAudioDeviceList, &Entry->Entry);
167  DeviceExtension->NumSysAudioDevices++;
168 
169  /* get the file object */
171  if (!NT_SUCCESS(Status))
172  {
173  DPRINT1("Failed to reference FileObject %x\n", Status);
174  ZwClose(hSysAudio);
175  return Status;
176  }
178  DeviceExtension->hSysAudio = hSysAudio;
179  DeviceExtension->FileObject = FileObject;
180  }
181 
182  return Status;
183 }
184 
185 NTSTATUS
188  IN PWDMAUD_DEVICE_EXTENSION DeviceExtension)
189 {
191  UNICODE_STRING SymbolicLinkName;
192 
194  if (NT_SUCCESS(Status))
195  {
196  IoSetDeviceInterfaceState(&SymbolicLinkName, TRUE);
197  RtlFreeUnicodeString(&SymbolicLinkName);
198  //DeviceExtension->DeviceInterfaceSupport = TRUE;
199  return Status;
200  }
201 
202  return Status;
203 }
204 
205 NTSTATUS
208  IN PWDMAUD_CLIENT *pClient)
209 {
211  PWDMAUD_DEVICE_EXTENSION DeviceExtension;
212 
213  /* get device extension */
215 
216  if (!DeviceExtension->NumSysAudioDevices)
217  {
218  /* wdmaud failed to open sysaudio */
219  return STATUS_UNSUCCESSFUL;
220  }
221 
222  /* sanity check */
223  ASSERT(!IsListEmpty(&DeviceExtension->SysAudioDeviceList));
224 
225  /* allocate client context struct */
227 
228  /* check for allocation failure */
229  if (!Client)
230  {
231  /* not enough memory */
233  }
234 
235  /* zero client context struct */
237 
238  /* initialize mixer event list */
239  InitializeListHead(&Client->MixerEventList);
240 
241  /* store result */
242  *pClient = Client;
243 
244  /* insert client into list */
245  ExInterlockedInsertTailList(&DeviceExtension->WdmAudClientList, &Client->Entry, &DeviceExtension->Lock);
246 
247  /* done */
248  return STATUS_SUCCESS;
249 }
_In_ PVOID NotificationStructure
Definition: iofuncs.h:1203
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define IN
Definition: typedefs.h:38
#define TRUE
Definition: types.h:120
Definition: client.c:29
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_opt_ PDEVICE_OBJECT _In_ ULONG _Outptr_result_nullonfailure_ _At_ * SymbolicLinkList(return==0, __drv_allocatesMem(Mem))) PZZWSTR *SymbolicLinkList
#define IO_FORCE_ACCESS_CHECK
Definition: iotypes.h:508
struct _Entry Entry
Definition: kefuncs.h:640
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
PLIST_ENTRY NTAPI ExInterlockedInsertTailList(IN OUT PLIST_ENTRY ListHead, IN OUT PLIST_ENTRY ListEntry, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:140
PVOID AllocateItem(IN POOL_TYPE PoolType, IN SIZE_T NumberOfBytes)
Definition: misc.c:30
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI IoGetDeviceInterfaces(IN CONST GUID *InterfaceClassGuid, IN PDEVICE_OBJECT PhysicalDeviceObject OPTIONAL, IN ULONG Flags, OUT PWSTR *SymbolicLinkList)
Definition: deviface.c:454
#define PNPNOTIFY_DEVICE_INTERFACE_INCLUDE_EXISTING_INTERFACES
Definition: iotypes.h:1196
PDEVICE_OBJECT PhysicalDeviceObject
Definition: btrfs_drv.h:1114
WCHAR DeviceName[]
Definition: adapter.cpp:21
#define InsertTailList(ListHead, Entry)
void DbgBreakPoint()
Definition: mach.c:553
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
const GUID KSCATEGORY_WDMAUD
Definition: entry.c:16
#define OBJ_OPENIF
Definition: winternl.h:229
VOID FreeItem(IN PVOID Item)
Definition: misc.c:43
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
Definition: obref.c:496
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
#define IO_NO_PARAMETER_CHECKING
Definition: iotypes.h:509
#define FILE_READ_DATA
Definition: nt_native.h:628
Entry(ENTRY_TYPE etype)
Definition: entries.cpp:35
#define GENERIC_WRITE
Definition: nt_native.h:90
struct WDMAUD_DEVICE_EXTENSION * PWDMAUD_DEVICE_EXTENSION
NTSTATUS WdmAudOpenSysaudio(IN PDEVICE_OBJECT DeviceObject, IN PWDMAUD_CLIENT *pClient)
Definition: deviface.c:206
ULONG NumSysAudioDevices
Definition: wdmaud.h:59
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
NTSTATUS NTAPI IoSetDeviceInterfaceState(IN PUNICODE_STRING SymbolicLinkName, IN BOOLEAN Enable)
Definition: deviface.c:1311
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
#define FILE_WRITE_DATA
Definition: nt_native.h:631
NTSTATUS NTAPI DeviceInterfaceChangeCallback(IN PVOID NotificationStructure, IN PVOID Context)
Definition: deviface.c:48
#define KSCATEGORY_SYSAUDIO
Definition: ksmedia.h:217
NTSTATUS WdmAudOpenSysAudioDevice(IN LPWSTR DeviceName, OUT PHANDLE Handle)
Definition: deviface.c:16
_In_ HANDLE Handle
Definition: extypes.h:390
if(!(yy_init))
Definition: macro.lex.yy.c:714
Definition: wdmaud.h:45
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
* PFILE_OBJECT
Definition: iotypes.h:1955
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
static const WCHAR L[]
Definition: oid.c:1250
LIST_ENTRY SysAudioDeviceList
Definition: wdmaud.h:60
PVOID *typedef PHANDLE
Definition: ntsecpkg.h:414
NTSTATUS NTAPI IoRegisterPlugPlayNotification(IN IO_NOTIFICATION_EVENT_CATEGORY EventCategory, IN ULONG EventCategoryFlags, IN PVOID EventCategoryData OPTIONAL, IN PDRIVER_OBJECT DriverObject, IN PDRIVER_NOTIFICATION_CALLBACK_ROUTINE CallbackRoutine, IN PVOID Context, OUT PVOID *NotificationEntry)
Definition: pnpnotify.c:249
#define GENERIC_READ
Definition: compat.h:124
#define SYNCHRONIZE
Definition: nt_native.h:61
POBJECT_TYPE IoFileObjectType
Definition: iomgr.c:36
NTSTATUS WdmAudOpenSysAudioDevices(IN PDEVICE_OBJECT DeviceObject, IN PWDMAUD_DEVICE_EXTENSION DeviceExtension)
Definition: deviface.c:93
NTSTATUS WdmAudOpenSysAudioDeviceInterfaces(IN PWDMAUD_DEVICE_EXTENSION DeviceExtension, IN LPWSTR SymbolicLinkList)
Definition: deviface.c:60
KSPIN_LOCK Lock
Definition: wdmaud.h:58
Status
Definition: gdiplustypes.h:24
#define FILE_OPEN
Definition: from_kernel.h:54
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
NTSTATUS NTAPI IoRegisterDeviceInterface(IN PDEVICE_OBJECT PhysicalDeviceObject, IN CONST GUID *InterfaceClassGuid, IN PUNICODE_STRING ReferenceString OPTIONAL, OUT PUNICODE_STRING SymbolicLinkName)
Definition: deviface.c:955
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
NTSYSAPI NTSTATUS NTAPI RtlAppendUnicodeStringToString(PUNICODE_STRING Destination, PUNICODE_STRING Source)
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define DPRINT1
Definition: precomp.h:8
NTSTATUS NTAPI IoCreateFile(OUT PHANDLE FileHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, OUT PIO_STATUS_BLOCK IoStatusBlock, IN PLARGE_INTEGER AllocationSize OPTIONAL, IN ULONG FileAttributes, IN ULONG ShareAccess, IN ULONG Disposition, IN ULONG CreateOptions, IN PVOID EaBuffer OPTIONAL, IN ULONG EaLength, IN CREATE_FILE_TYPE CreateFileType, IN PVOID ExtraCreateParameters OPTIONAL, IN ULONG Options)
Definition: file.c:3009
#define FILE_SYNCHRONOUS_IO_NONALERT
Definition: from_kernel.h:31
#define OUT
Definition: typedefs.h:39
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
WCHAR * LPWSTR
Definition: xmlstorage.h:184
return STATUS_SUCCESS
Definition: btrfs.c:2966
LIST_ENTRY WdmAudClientList
Definition: wdmaud.h:63
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
NTSTATUS WdmAudRegisterDeviceInterface(IN PDEVICE_OBJECT PhysicalDeviceObject, IN PWDMAUD_DEVICE_EXTENSION DeviceExtension)
Definition: deviface.c:186
base of all file and directory entries
Definition: entries.h:82
static const WCHAR SymbolicLink[]
Definition: interface.c:31
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14