ReactOS  0.4.15-dev-1206-g731eddf
sndblst.c
Go to the documentation of this file.
1 /*
2  *
3  * COPYRIGHT: See COPYING in the top level directory
4  * PROJECT: ReactOS Sound System
5  * FILE: drivers/multimedia/audio/sndblst/sndblst.c
6  * PURPOSE: Sound Blaster / Pro / 16 driver
7  * PROGRAMMER: Andrew Greenwood (silverblade@reactos.org)
8  *
9  * UPDATE HISTORY: Feb 25, 2009: New rewrite started
10  *
11  */
12 
13 /* DEFINES AND INCLUDES ******************************************************/
14 
15 #include <ntddk.h>
16 #include <windef.h>
17 #include <mmsystem.h>
18 #include <debug.h>
19 
20 #define CompleteIrpAndReturn(irp, status) \
21  irp->IoStatus.Status = status; \
22  irp->IoStatus.Information = 0; \
23  IoCompleteRequest(Irp, IO_NO_INCREMENT); \
24  return status;
25 
26 
27 /* FORWARD DECLARATIONS *****************************************************/
28 
29 static VOID NTAPI
31 
32 
33 /* DEVICE "DISCOVERY" *******************************************************/
34 /* Nb: These need to go in the helper lib */
35 
37  IN PUNICODE_STRING DeviceRegistryPath);
38 
42  IN PWSTR RegistrySubKey,
44 {
46  OBJECT_ATTRIBUTES RegAttributes;
47  HKEY MainKeyHandle, ChildKeyHandle;
48  UNICODE_STRING UnicodeSubkeyName, DeviceKeyName;
49  KEY_BASIC_INFORMATION KeyInfo, *FinalKeyInfo;
50  ULONG i = 0, NeededDataLength = 0, FinalDataLength = 0, NameLength = 0;
51 
52  /* Turn the subkey name into a Unicode string */
53  RtlInitUnicodeString(&UnicodeSubkeyName, RegistrySubKey);
54 
55  /* Open the registry key for the service */
56  InitializeObjectAttributes(&RegAttributes,
59  NULL,
61 
62  Status = ZwOpenKey(&MainKeyHandle, KEY_READ, &RegAttributes);
63 
64  if ( ! NT_SUCCESS(Status) )
65  {
66  DPRINT("Failed to open registry key\n");
67  return Status;
68  }
69 
70  /* Open the subkey usually named "Parameters" */
71  InitializeObjectAttributes(&RegAttributes,
72  &UnicodeSubkeyName,
74  MainKeyHandle,
76 
77  Status = ZwOpenKey(&ChildKeyHandle, KEY_ENUMERATE_SUB_KEYS, &RegAttributes);
78 
79  /* We're done with the main key now */
80  ZwClose(MainKeyHandle);
81 
82  if ( ! NT_SUCCESS(Status) )
83  {
84  DPRINT("Failed to open registry subkeys for enumeration\n");
85  return Status;
86  }
87 
88  /* Enumerate through the device keys */
89  while ( ( Status = ZwEnumerateKey(ChildKeyHandle,
90  i,
92  &KeyInfo,
93  sizeof(KEY_BASIC_INFORMATION),
94  &NeededDataLength) ) != STATUS_NO_MORE_ENTRIES )
95  {
96  PWSTR EnumeratedKeyName, StartOfEnumeratedKeyName;
97 
98  DPRINT("Found subkey %d\n", i);
99 
100  FinalDataLength = NeededDataLength + FIELD_OFFSET(KEY_BASIC_INFORMATION, Name[0]);
101  DPRINT("Allocating %d bytes\n", FinalDataLength);
102 
103  FinalKeyInfo = (PKEY_BASIC_INFORMATION) ExAllocatePool(PagedPool, FinalDataLength);
104 
105  if ( ! FinalKeyInfo )
106  {
108  break;
109  }
110 
111  /* This time we get the real info */
112  Status = ZwEnumerateKey(ChildKeyHandle,
113  i,
115  FinalKeyInfo,
116  FinalDataLength,
117  &NeededDataLength);
118 
119  if ( ! NT_SUCCESS(Status) )
120  {
121  DPRINT("FAILED to enumerate key!\n");
122  }
123  else
124  {
125  NameLength = RegistryPath->Length + sizeof(WCHAR) +
126  UnicodeSubkeyName.Length + sizeof(WCHAR) +
127  FinalKeyInfo->NameLength + sizeof(UNICODE_NULL);
128 
129  DPRINT("Allocating memory for name (%d bytes)\n", NameLength);
130 
131  EnumeratedKeyName = (PWSTR) ExAllocatePool(PagedPool, NameLength);
132 
133  if ( ! EnumeratedKeyName )
134  {
135  ExFreePool((PVOID)FinalKeyInfo);
137  break;
138  }
139 
140  StartOfEnumeratedKeyName = EnumeratedKeyName;
141 
142  /* Start building the registry path using the service key */
143  RtlCopyMemory(EnumeratedKeyName,
144  RegistryPath->Buffer,
145  RegistryPath->Length);
146 
147  EnumeratedKeyName += RegistryPath->Length / sizeof(WCHAR);
148  EnumeratedKeyName[0] = '\\';
149  ++ EnumeratedKeyName;
150 
151  /* Append the parameters subkey */
152  RtlCopyMemory(EnumeratedKeyName,
153  RegistrySubKey,
154  UnicodeSubkeyName.Length);
155 
156  EnumeratedKeyName += UnicodeSubkeyName.Length / sizeof(WCHAR);
157  EnumeratedKeyName[0] = '\\';
158  ++ EnumeratedKeyName;
159 
160  /* And finally append the enumerated key name */
161  RtlCopyMemory(EnumeratedKeyName,
162  FinalKeyInfo->Name,
163  FinalKeyInfo->NameLength);
164 
165  EnumeratedKeyName += FinalKeyInfo->NameLength / sizeof(WCHAR);
166  EnumeratedKeyName[0] = UNICODE_NULL;
167 
168  /* Reset pointer */
169  EnumeratedKeyName = StartOfEnumeratedKeyName;
170 
171  /* Convert into a Unicode string for the callback */
172  RtlInitUnicodeString(&DeviceKeyName, EnumeratedKeyName);
173 
174  Callback(&DeviceKeyName);
175 
176  /* No longer need the key name */
177  ExFreePool((PVOID)EnumeratedKeyName);
178  EnumeratedKeyName = NULL;
179  }
180 
181  /* No longer need the key info */
182  ExFreePool((PVOID)FinalKeyInfo);
183  FinalKeyInfo = NULL;
184 
185  ++ i;
186  }
187 
188  /* We're done with enumeration so close this */
189  ZwClose(ChildKeyHandle);
190 
191  /* This isn't an error */
193  {
195  }
196 
197  /* No devices configured? */
198  if ( i == 0 && Status == STATUS_NO_MORE_ENTRIES )
199  {
201  }
202 
203  return Status;
204 }
205 
206 NTSTATUS
208  IN DWORD HardwareDeviceIndex,
209  IN PWSTR BaseDeviceName,
210  IN DWORD DeviceIndex,
212 {
213  return STATUS_SUCCESS;
214 }
215 
216 
217 typedef struct _SOUND_BLASTER_DEVICE
218 {
221 
223 
226 
228 
232 
233 
234 NTSTATUS
236 {
237  return STATUS_NOT_IMPLEMENTED;
238 }
239 
240 /* callback */
241 /*
242  Configuration options within the registry:
243  REG_DWORD Actual Dma Buffer Size 0x00004000
244  REG_DWORD Configuration Error 0xffffffff
245  REG_DWORD Dma Buffer Size 0x00004000
246  REG_DWORD DmaChannel 0x00000001
247  REG_DWORD DmaChannel16 0x00000005
248  REG_DWORD DSP Version 0x00000405
249  REG_DWORD Interrupt 0x00000005
250  REG_DWORD Load Type 0x00000000
251  REG_BINARY Mixer Settings ??
252  REG_DWORD MPU401 Port 0xffffffff
253  REG_DWORD Port 0x00000220
254 */
255 
256 NTSTATUS
258 {
259  OBJECT_ATTRIBUTES RegAttributes;
261  HKEY ConfigKeyHandle;
262 
263  DPRINT("Configuring Sound Blaster (config at %S)\n", DeviceRegistryPath->Buffer);
264 
265  if ( ! DeviceRegistryPath )
266  {
268  }
269 
270  /* Open the registry key */
271  InitializeObjectAttributes(&RegAttributes,
272  DeviceRegistryPath,
274  NULL,
276 
277  Status = ZwOpenKey(&ConfigKeyHandle, KEY_READ, &RegAttributes);
278 
279  if ( ! NT_SUCCESS(Status) )
280  {
281  DPRINT("Failed to open config registry key\n");
282  return Status;
283  }
284 
285  /* Read configuration */
286  DPRINT("Reading configuration\n");
287 
288  //Status = ZwQueryValueKey(ConfigKeyHandle,
289 
290  return Status;
291 }
292 
293 
294 /* IRP DISPATCHERS **********************************************************/
295 
296 static NTSTATUS NTAPI
299  IN PIRP Irp)
300 {
301  DPRINT("Sound Blaster driver received IRP_MJ_CREATE\n");
302 
304 }
305 
306 static NTSTATUS NTAPI
309  IN PIRP Irp)
310 {
311  DPRINT("Sound Blaster driver received IRP_MJ_CLOSE\n");
312 
314 }
315 
316 static NTSTATUS NTAPI
319  IN PIRP Irp)
320 {
321  DPRINT("Sound Blaster driver received IRP_MJ_CLEANUP\n");
322 
324 }
325 
326 static NTSTATUS NTAPI
329  IN PIRP Irp)
330 {
331  DPRINT("Sound Blaster driver received IRP_MJ_CONTROL\n");
332 
334 }
335 
336 static NTSTATUS NTAPI
339  IN PIRP Irp)
340 {
341  DPRINT("Sound Blaster driver received IRP_MJ_WRITE\n");
342 
344 }
345 
346 
347 /* DRIVER ENTRYPOINT ********************************************************/
348 
353 {
355 
356  DPRINT("Sound Blaster driver by silverblade\n");
357 
358  DriverObject->Flags = 0;
365 
367 
368  return Status;
369 }
370 
371 static VOID NTAPI
373 {
374  DPRINT("Sound Blaster driver is being unloaded\n");
375 }
NTSTATUS AllocateSoundBlasterStructure(OUT SOUND_BLASTER_DEVICE *SoundBlasterDevice)
Definition: sndblst.c:235
#define IN
Definition: typedefs.h:39
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define STATUS_NO_MORE_ENTRIES
Definition: ntstatus.h:205
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
static NTSTATUS NTAPI CleanupSoundBlaster(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: sndblst.c:317
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:239
static VOID NTAPI UnloadSoundBlaster(PDRIVER_OBJECT DriverObject)
Definition: main.c:117
_In_ PIRP Irp
Definition: csq.h:116
#define KEY_READ
Definition: nt_native.h:1023
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
uint16_t * PWSTR
Definition: typedefs.h:56
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
Definition: sndblst.c:420
static NTSTATUS NTAPI CreateSoundBlaster(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: sndblst.c:297
DWORD ActualDmaBufferSize
Definition: sndblst.c:229
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
#define UNICODE_NULL
_Must_inspect_result_ typedef _Out_ PHIDP_CAPS Capabilities
Definition: hidclass.h:103
struct _KEY_BASIC_INFORMATION * PKEY_BASIC_INFORMATION
smooth NULL
Definition: ftsmooth.c:416
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
void DPRINT(...)
Definition: polytest.cpp:61
_In_z_ PWSTR RegistryPath
Definition: classp.h:1930
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS PublishWaveOutDevice(IN DWORD HardwareDeviceIndex, IN PWSTR BaseDeviceName, IN DWORD DeviceIndex, IN LPWAVEOUTCAPS Capabilities)
Definition: sndblst.c:207
unsigned long DWORD
Definition: ntddk_ex.h:95
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
Status
Definition: gdiplustypes.h:24
static const WCHAR L[]
Definition: oid.c:1250
static NTSTATUS NTAPI CloseSoundBlaster(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: sndblst.c:307
PDRIVER_UNLOAD DriverUnload
Definition: iotypes.h:2268
#define NTSTATUS
Definition: precomp.h:20
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
_In_ PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2464
NTSTATUS(* SOUNDDEVICEENUMERATIONCALLBACK)(IN PUNICODE_STRING DeviceRegistryPath)
Definition: sndblst.c:36
static NTSTATUS NTAPI WriteToSoundBlaster(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: sndblst.c:337
static NTSTATUS NTAPI ControlSoundBlaster(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: sndblst.c:327
#define IRP_MJ_CLEANUP
#define OUT
Definition: typedefs.h:40
PDRIVER_DISPATCH MajorFunction[IRP_MJ_MAXIMUM_FUNCTION+1]
Definition: iotypes.h:2269
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
NTSTATUS ConfigureSoundBlasterDevice(IN PUNICODE_STRING DeviceRegistryPath)
Definition: sndblst.c:257
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
NTSTATUS EnumerateSoundDevices(IN PUNICODE_STRING RegistryPath, IN PWSTR RegistrySubKey, IN SOUNDDEVICEENUMERATIONCALLBACK Callback)
Definition: sndblst.c:40
struct _SOUND_BLASTER_DEVICE SOUND_BLASTER_DEVICE
#define IRP_MJ_WRITE
Definition: rdpdr.c:47
#define CompleteIrpAndReturn(irp, status)
Definition: sndblst.c:20
#define STATUS_DEVICE_CONFIGURATION_ERROR
Definition: ntstatus.h:619
return STATUS_SUCCESS
Definition: btrfs.c:3014
LPFNPSPCALLBACK Callback
Definition: desk.c:112
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52
#define KEY_ENUMERATE_SUB_KEYS
Definition: nt_native.h:1019