-
Notifications
You must be signed in to change notification settings - Fork 5
/
property.cpp
357 lines (297 loc) · 12.3 KB
/
property.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
/* 1010 PCI/PCIe Audio Driver
Copyright (c) Eugene Gavrilov, 2002-2016
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "common.h"
#include "debug.h"
#include "property.h"
#include "topology.h"
#include "dsp.h"
#define KSPROPERTY_TYPE_ALL KSPROPERTY_TYPE_BASICSUPPORT | \
KSPROPERTY_TYPE_GET | \
KSPROPERTY_TYPE_SET
#pragma code_seg("PAGE")
NTSTATUS Property::PropertyCpuResources(IN PPCPROPERTY_REQUEST PropertyRequest)
{
PAGED_CODE();
NTSTATUS ntStatus = STATUS_INVALID_DEVICE_REQUEST;
if (PropertyRequest->Verb & KSPROPERTY_TYPE_GET)
{
ntStatus = ValidatePropertyParams(PropertyRequest, sizeof(ULONG));
if (NT_SUCCESS(ntStatus))
{
*(PLONG(PropertyRequest->Value)) = KSAUDIO_CPU_RESOURCES_NOT_HOST_CPU;
PropertyRequest->ValueSize = sizeof(LONG);
}
}
else
if (PropertyRequest->Verb & KSPROPERTY_TYPE_BASICSUPPORT)
{
ntStatus = PropertyHandler_BasicSupport( PropertyRequest, KSPROPERTY_TYPE_GET | KSPROPERTY_TYPE_BASICSUPPORT, VT_ILLEGAL, FALSE);
}
return ntStatus;
}
#pragma code_seg("PAGE")
NTSTATUS Property::PropertyMute(IN PPCPROPERTY_REQUEST PropertyRequest)
{
PAGED_CODE();
NTSTATUS ntStatus = STATUS_INVALID_DEVICE_REQUEST;
LONG lChannel;
PBOOL pfMute;
if (PropertyRequest->Verb & KSPROPERTY_TYPE_BASICSUPPORT)
{
ntStatus = PropertyHandler_BasicSupport(PropertyRequest,KSPROPERTY_TYPE_ALL,VT_BOOL,TRUE);
}
else
{
ntStatus = ValidatePropertyParams(PropertyRequest, sizeof(BOOL), sizeof(LONG));
if (NT_SUCCESS(ntStatus))
{
lChannel = * PLONG (PropertyRequest->Instance);
pfMute = PBOOL (PropertyRequest->Value);
Topology *obj = ((Topology *)((PMINIPORTTOPOLOGY)(PropertyRequest->MajorTarget)));
if(!valid_object(obj,Topology)) { debug("!! PropertyMute: invalid major target\n"); return STATUS_INVALID_PARAMETER; }
if (PropertyRequest->Verb & KSPROPERTY_TYPE_GET)
{
ntStatus=obj->GetMute(PropertyRequest->Node,lChannel, pfMute);
PropertyRequest->ValueSize = sizeof(BOOL);
}
else if (PropertyRequest->Verb & KSPROPERTY_TYPE_SET)
{
ntStatus=obj->SetMute(PropertyRequest->Node, lChannel, *pfMute);
}
}
}
return ntStatus;
}
#pragma code_seg("PAGE")
NTSTATUS Property::PropertyVolume(IN PPCPROPERTY_REQUEST PropertyRequest)
{
PAGED_CODE();
NTSTATUS ntStatus = STATUS_INVALID_DEVICE_REQUEST;
LONG lChannel;
PULONG pulVolume;
if (PropertyRequest->Verb & KSPROPERTY_TYPE_BASICSUPPORT)
{
ntStatus = PropertyHandlerBasicSupportVolume(PropertyRequest);
}
else
{
ntStatus = ValidatePropertyParams(PropertyRequest, sizeof(ULONG), sizeof(LONG));
if (NT_SUCCESS(ntStatus))
{
lChannel = * (PLONG (PropertyRequest->Instance));
pulVolume = PULONG (PropertyRequest->Value);
Topology *obj = ((Topology *)((PMINIPORTTOPOLOGY)(PropertyRequest->MajorTarget)));
if(!valid_object(obj,Topology)) { debug("!! PropertyVolume: invalid major target\n"); return STATUS_INVALID_PARAMETER; }
if (PropertyRequest->Verb & KSPROPERTY_TYPE_GET)
{
ntStatus=obj->GetVolume(PropertyRequest->Node,lChannel,pulVolume);
PropertyRequest->ValueSize = sizeof(ULONG);
}
else if (PropertyRequest->Verb & KSPROPERTY_TYPE_SET)
{
ntStatus=obj->SetVolume(PropertyRequest->Node,lChannel,*pulVolume);
}
}
}
return ntStatus;
}
#pragma code_seg("PAGE")
NTSTATUS Property::ValidatePropertyParams(IN PPCPROPERTY_REQUEST PropertyRequest, IN ULONG cbSize,IN ULONG cbInstanceSize)
{
PAGED_CODE();
NTSTATUS ntStatus = STATUS_UNSUCCESSFUL;
if (PropertyRequest && cbSize)
{
// If the caller is asking for ValueSize.
if (PropertyRequest->ValueSize == 0)
{
PropertyRequest->ValueSize = cbSize;
ntStatus = STATUS_BUFFER_OVERFLOW;
}
// If the caller passed an invalid ValueSize.
else if (PropertyRequest->ValueSize < cbSize)
{
ntStatus = STATUS_BUFFER_TOO_SMALL;
}
else if (PropertyRequest->InstanceSize < cbInstanceSize)
{
ntStatus = STATUS_BUFFER_TOO_SMALL;
}
// If all parameters are OK.
//
else if (PropertyRequest->ValueSize == cbSize)
{
if (PropertyRequest->Value)
{
ntStatus = STATUS_SUCCESS;
//
// Caller should set ValueSize, if the property
// call is successful.
//
}
}
}
else
{
ntStatus = STATUS_INVALID_PARAMETER;
}
// Clear the ValueSize if unsuccessful.
//
if (PropertyRequest &&
STATUS_SUCCESS != ntStatus &&
STATUS_BUFFER_OVERFLOW != ntStatus)
{
PropertyRequest->ValueSize = 0;
}
return ntStatus;
}
#pragma code_seg("PAGE")
NTSTATUS Property::PropertyHandler_BasicSupport(IN PPCPROPERTY_REQUEST PropertyRequest,IN ULONG Flags,IN DWORD PropTypeSetId,BOOL Multichannel)
// Default basic support handler. Basic processing depends on the size of data.
// For ULONG it only returns Flags. For KSPROPERTY_DESCRIPTION, the structure
// is filled.
{
PAGED_CODE();
ASSERT(Flags & KSPROPERTY_TYPE_BASICSUPPORT);
NTSTATUS ntStatus = STATUS_INVALID_PARAMETER;
Topology *obj = ((Topology *)((PMINIPORTTOPOLOGY)PropertyRequest->MajorTarget));
if(!valid_object(obj,Topology)) { debug("!! PropertyHandler_BasicSupport: invalid major target\n"); return STATUS_INVALID_PARAMETER; }
int num_channels=obj->get_n_channels();
ULONG cbFullProperty = sizeof(KSPROPERTY_DESCRIPTION)
+ (Multichannel?(sizeof(KSPROPERTY_MEMBERSHEADER) + sizeof(KSPROPERTY_STEPPING_LONG)*num_channels):0);
if (PropertyRequest->ValueSize >= sizeof(KSPROPERTY_DESCRIPTION))
{
// if return buffer can hold a KSPROPERTY_DESCRIPTION, return it
//
PKSPROPERTY_DESCRIPTION PropDesc = PKSPROPERTY_DESCRIPTION(PropertyRequest->Value);
PropDesc->AccessFlags = Flags;
PropDesc->DescriptionSize = cbFullProperty;
if (PropTypeSetId != VT_ILLEGAL)
{
PropDesc->PropTypeSet.Set = KSPROPTYPESETID_General;
PropDesc->PropTypeSet.Id = PropTypeSetId;
}
else
{
PropDesc->PropTypeSet.Set = GUID_NULL;
PropDesc->PropTypeSet.Id = 0;
}
PropDesc->PropTypeSet.Flags = 0;
PropDesc->MembersListCount = Multichannel?1:0;
PropDesc->Reserved = 0;
// if return buffer can also hold a range description, return it too
if(PropertyRequest->ValueSize >= cbFullProperty && Multichannel)
{
// fill in the members header
PKSPROPERTY_MEMBERSHEADER Members = PKSPROPERTY_MEMBERSHEADER(PropDesc + 1);
Members->MembersFlags = KSPROPERTY_MEMBER_STEPPEDRANGES;
Members->MembersSize = sizeof(KSPROPERTY_STEPPING_LONG);
Members->MembersCount = num_channels;
Members->Flags = KSPROPERTY_MEMBER_FLAG_BASICSUPPORT_MULTICHANNEL;
// fill in the stepped range
PKSPROPERTY_STEPPING_LONG Range = PKSPROPERTY_STEPPING_LONG(Members + 1);
for(int i=0;i<num_channels;i++)
{
Range->Bounds.SignedMaximum = 1;
Range->Bounds.SignedMinimum = 0;
Range->SteppingDelta = 1;
Range->Reserved = 0;
}
// set the return value size
PropertyRequest->ValueSize = cbFullProperty;
}
else
{
PropertyRequest->ValueSize = sizeof(KSPROPERTY_DESCRIPTION);
}
ntStatus = STATUS_SUCCESS;
}
else if (PropertyRequest->ValueSize >= sizeof(ULONG))
{
// if return buffer can hold a ULONG, return the access flags
//
*(PULONG(PropertyRequest->Value)) = Flags;
PropertyRequest->ValueSize = sizeof(ULONG);
ntStatus = STATUS_SUCCESS;
}
else
{
PropertyRequest->ValueSize = 0;
ntStatus = STATUS_BUFFER_TOO_SMALL;
}
return ntStatus;
}
#pragma code_seg("PAGE")
NTSTATUS Property::PropertyHandlerBasicSupportVolume(IN PPCPROPERTY_REQUEST PropertyRequest)
{
PAGED_CODE();
Topology *obj = ((Topology *)((PMINIPORTTOPOLOGY)PropertyRequest->MajorTarget));
if(!valid_object(obj,Topology)) { debug("!! PropertyHandlerBasicSupportVolume: invalid major target\n"); return STATUS_INVALID_PARAMETER; }
int num_channels=obj->get_n_channels();
NTSTATUS ntStatus = STATUS_SUCCESS;
ULONG cbFullProperty = sizeof(KSPROPERTY_DESCRIPTION) + sizeof(KSPROPERTY_MEMBERSHEADER) + sizeof(KSPROPERTY_STEPPING_LONG)*num_channels;
if (PropertyRequest->ValueSize >= (sizeof(KSPROPERTY_DESCRIPTION)))
{
PKSPROPERTY_DESCRIPTION PropDesc = PKSPROPERTY_DESCRIPTION(PropertyRequest->Value);
PropDesc->AccessFlags = KSPROPERTY_TYPE_ALL;
PropDesc->DescriptionSize = cbFullProperty;
PropDesc->PropTypeSet.Set = KSPROPTYPESETID_General;
PropDesc->PropTypeSet.Id = VT_I4;
PropDesc->PropTypeSet.Flags = 0;
PropDesc->MembersListCount = 1;
PropDesc->Reserved = 0;
// if return buffer can also hold a range description, return it too
if(PropertyRequest->ValueSize >= cbFullProperty)
{
// fill in the members header
PKSPROPERTY_MEMBERSHEADER Members =
PKSPROPERTY_MEMBERSHEADER(PropDesc + 1);
Members->MembersFlags = KSPROPERTY_MEMBER_STEPPEDRANGES;
Members->MembersSize = sizeof(KSPROPERTY_STEPPING_LONG);
Members->MembersCount = num_channels;
Members->Flags = KSPROPERTY_MEMBER_FLAG_BASICSUPPORT_MULTICHANNEL;
// fill in the stepped range
PKSPROPERTY_STEPPING_LONG Range = PKSPROPERTY_STEPPING_LONG(Members + 1);
for(int i=0;i<num_channels;i++)
{
Range->Bounds.SignedMaximum = DSP::MAX_VOLUME;
Range->Bounds.SignedMinimum = DSP::MIN_VOLUME;
Range->SteppingDelta = DSP::VOLUME_STEP;
Range->Reserved = 0;
}
// set the return value size
PropertyRequest->ValueSize = cbFullProperty;
}
else
{
PropertyRequest->ValueSize = sizeof(KSPROPERTY_DESCRIPTION);
}
}
else if(PropertyRequest->ValueSize >= sizeof(ULONG))
{
// if return buffer can hold a ULONG, return the access flags
PULONG AccessFlags = PULONG(PropertyRequest->Value);
PropertyRequest->ValueSize = sizeof(ULONG);
*AccessFlags = KSPROPERTY_TYPE_ALL;
}
else
{
PropertyRequest->ValueSize = 0;
ntStatus = STATUS_BUFFER_TOO_SMALL;
}
return ntStatus;
}