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
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
|
//
// This class represents a the Bluetooth Hands-Free Profile SCO Bypass device.
// There is one class for each interface (id = symbolic-link-name).
//
#ifdef SYSVAD_BTH_BYPASS
//=====================================================================
//
// CAdapterCommon: Bluetooth Hands-Free Profile SCO Bypass definitions.
//
class CAdapterCommon;
class BthHfpDevice;
struct BthHfpWorkItemContext
{
CAdapterCommon * Adapter;
};
WDF_DECLARE_CONTEXT_TYPE_WITH_NAME
(
BthHfpWorkItemContext,
GetBthHfpWorkItemContext
)
// start/stop the device
enum eBthHfpTaskAction
{
eBthHfpTaskStart = 1,
eBthHfpTaskStop = 2,
};
struct BthHfpWorkTask
{
LIST_ENTRY ListEntry;
BthHfpDevice * Device;
eBthHfpTaskAction Action;
};
//=====================================================================
//
// Device: Bluetooth Hands-Free Profile SCO Bypass definitions.
//
// BTH HFP device's notification work-item context.
struct BthHfpDeviceNotificationWorkItemContext
{
BthHfpDevice * BthHfpDevice;
};
WDF_DECLARE_CONTEXT_TYPE_WITH_NAME
(
BthHfpDeviceNotificationWorkItemContext,
GetBthHfpDeviceNotificationWorkItemContext
)
// BTH HFP device's notification request context.
union BthHfpDeviceNotificationBuffer
{
BOOL bImmediate;
LONG Volume;
BOOL BoolStatus;
NTSTATUS NtStatus;
};
struct BthHfpDeviceNotificationReqContext
{
BthHfpDevice * BthHfpDevice;
LONG Errors;
BthHfpDeviceNotificationBuffer Buffer;
WDFMEMORY MemIn;
WDFMEMORY MemOut;
};
WDF_DECLARE_CONTEXT_TYPE_WITH_NAME
(
BthHfpDeviceNotificationReqContext,
GetBthHfpDeviceNotificationReqContext
)
enum eBthHfpState
{
eBthHfpStateInvalid = 0,
eBthHfpStateInitializing = 1,
eBthHfpStateRunning = 2,
eBthHfpStateStopping = 3,
eBthHfpStateStopped = 4,
eBthHfpStateFailed = 5,
};
// To support event notification.
struct BthHfpEventCallback
{
PFNEVENTNOTIFICATION Handler;
PVOID Context;
};
//
// This class represents a the Bluetooth Hands-Free Profile SCO Bypass device.
// There is one class for each interface (id = symbolic-link-name).
//
class BthHfpDevice :
ISidebandDeviceCommon,
public CUnknown
{
private:
eBthHfpState m_State;
IAdapterCommon * m_Adapter;
WDFIOTARGET m_WdfIoTarget;
LIST_ENTRY m_ListEntry;
UNICODE_STRING m_SymbolicLinkName;
WCHAR m_SpeakerWaveNameBuffer[BTHHFP_INTERFACE_REFSTRING_MAX_LENGTH];
UNICODE_STRING m_SpeakerWaveRefString;
WCHAR m_SpeakerTopologyNameBuffer[BTHHFP_INTERFACE_REFSTRING_MAX_LENGTH];
UNICODE_STRING m_SpeakerTopologyRefString;
WCHAR m_MicWaveNameBuffer[BTHHFP_INTERFACE_REFSTRING_MAX_LENGTH];
UNICODE_STRING m_MicWaveRefString;
WCHAR m_MicTopologyNameBuffer[BTHHFP_INTERFACE_REFSTRING_MAX_LENGTH];
UNICODE_STRING m_MicTopologyRefString;
//
// The Topo Filter Desc and Topo Pins structures referenced from
// the Miniports structure are deep copies: they start as copies of the
// static structures and are modified to allow per-SCO-Device pin
// categories based on the info obtained from
// IOCTL_BTHHFP_DEVICE_GET_DESCRIPTOR2
//
PENDPOINT_MINIPAIR m_SpeakerMiniports;
PENDPOINT_MINIPAIR m_MicMiniports;
PUNKNOWN m_UnknownSpeakerTopology;
PUNKNOWN m_UnknownSpeakerWave;
PUNKNOWN m_UnknownMicTopology;
PUNKNOWN m_UnknownMicWave;
LONG m_CodecId;
PBTHHFP_DESCRIPTOR2 m_Descriptor;
PKSPROPERTY_VALUES m_VolumePropValues;
LONG m_SpeakerVolumeLevel;
LONG m_MicVolumeLevel;
union {
BOOL m_ConnectionStatus;
LONG m_ConnectionStatusLong;
}; // unnamed.
union {
NTSTATUS m_StreamStatus;
LONG m_StreamStatusLong;
}; // unnamed.
KEVENT m_StreamStatusEvent;
//
// Set to TRUE when the HF (remote device) wants to disable the
// NR + EC of the AG (local system).
//
LONG m_NRECDisableStatusLong;
WDFREQUEST m_StreamReq;
WDFREQUEST m_SpeakerVolumeReq;
WDFREQUEST m_MicVolumeReq;
WDFREQUEST m_ConnectionReq;
WDFREQUEST m_NRECDisableStatusReq;
WDFWORKITEM m_WorkItem;
WDFCOLLECTION m_ReqCollection;
KSPIN_LOCK m_Lock;
LONG m_nStreams; // # of open streams.
BthHfpEventCallback m_SpeakerVolumeCallback;
BthHfpEventCallback m_SpeakerMuteCallback;
BthHfpEventCallback m_SpeakerConnectionStatusCallback;
BthHfpEventCallback m_SpeakerFormatChangeCallback;
BthHfpEventCallback m_MicVolumeCallback;
BthHfpEventCallback m_MicMuteCallback;
BthHfpEventCallback m_MicConnectionStatusCallback;
BthHfpEventCallback m_MicFormatChangeCallback;
public:
//=====================================================================
// Default CUnknown
DECLARE_STD_UNKNOWN();
DEFINE_STD_CONSTRUCTOR(BthHfpDevice);
~BthHfpDevice();
NTSTATUS Init
(
_In_ IAdapterCommon *Adapter,
_In_ PUNICODE_STRING SymbolicLinkName
);
public:
//=====================================================================
//
// Public functions used by CAdapterCommon object.
//
VOID Start();
VOID Stop();
PLIST_ENTRY GetListEntry()
{
return &m_ListEntry;
}
PUNICODE_STRING GetSymbolicLinkName()
{
return &m_SymbolicLinkName;
}
static
BthHfpDevice *
GetBthHfpDevice
(
_In_ PLIST_ENTRY le
)
{
return CONTAINING_RECORD(le, BthHfpDevice, m_ListEntry);
}
public:
//=====================================================================
//
// ISidebandDeviceCommon functions.
//
STDMETHODIMP_(BOOL) IsVolumeSupported
(
_In_ eDeviceType deviceType
);
STDMETHODIMP_(PVOID) GetVolumeSettings
(
_In_ eDeviceType DeviceType,
_Out_ PULONG Size
);
STDMETHODIMP_(NTSTATUS) GetVolume
(
_In_ eDeviceType DeviceType,
_In_ LONG Channel,
_Out_ LONG *pVolume
);
STDMETHODIMP_(NTSTATUS) SetVolume
(
_In_ eDeviceType DeviceType,
_In_ LONG Channel,
_In_ LONG Volume
);
STDMETHODIMP_(BOOL) IsMuteSupported
(
_In_ eDeviceType deviceType
);
STDMETHODIMP_(PVOID) GetMuteSettings
(
_In_ eDeviceType DeviceType,
_Out_ PULONG Size
);
STDMETHODIMP_(LONG) GetMute
(
_In_ eDeviceType DeviceType,
_In_ LONG Channel
);
STDMETHODIMP_(NTSTATUS) SetMute
(
_In_ eDeviceType DeviceType,
_In_ LONG Channel,
_In_ LONG Mute
);
STDMETHODIMP_(BOOL) GetConnectionStatus();
STDMETHODIMP_(NTSTATUS) Connect();
STDMETHODIMP_(NTSTATUS) Disconnect();
STDMETHODIMP_(BOOL) GetStreamStatus(_In_ eDeviceType deviceType);
STDMETHODIMP_(NTSTATUS) StreamOpen(_In_ eDeviceType deviceType);
STDMETHODIMP_(NTSTATUS) StreamStart(_In_ eDeviceType deviceType);
STDMETHODIMP_(NTSTATUS) StreamSuspend(_In_ eDeviceType deviceType);
STDMETHODIMP_(NTSTATUS) StreamClose(_In_ eDeviceType deviceType);
STDMETHODIMP_(GUID) GetContainerId(_In_ eDeviceType deviceType);
STDMETHODIMP_(VOID) SetVolumeHandler
(
_In_ eDeviceType deviceType,
_In_opt_ PFNEVENTNOTIFICATION EventHandler,
_In_opt_ PVOID EventHandlerContext
);
STDMETHODIMP_(VOID) SetMuteHandler
(
_In_ eDeviceType deviceType,
_In_opt_ PFNEVENTNOTIFICATION EventHandler,
_In_opt_ PVOID EventHandlerContext
);
STDMETHODIMP_(VOID) SetConnectionStatusHandler
(
_In_ eDeviceType deviceType,
_In_opt_ PFNEVENTNOTIFICATION EventHandler,
_In_opt_ PVOID EventHandlerContext
);
STDMETHODIMP_(VOID) SetFormatChangeHandler
(
_In_ eDeviceType deviceType,
_In_opt_ PFNEVENTNOTIFICATION EventHandler,
_In_opt_ PVOID EventHandlerContext
);
STDMETHODIMP_(PPIN_DEVICE_FORMATS_AND_MODES) GetFormatsAndModes
(
_In_ eDeviceType deviceType
);
_IRQL_requires_max_(DISPATCH_LEVEL)
STDMETHODIMP_(BOOL) IsNRECSupported();
STDMETHODIMP_(BOOL) GetNRECDisableStatus();
private:
//=====================================================================
//
// Helper functions.
//
NTSTATUS SendIoCtrlSynchronously
(
_In_opt_ WDFREQUEST Request,
_In_ ULONG IoControlCode,
_In_ ULONG InLength,
_In_ ULONG OutLength,
_When_(InLength > 0 || OutLength > 0, _In_)
_When_(InLength == 0 && OutLength == 0, _In_opt_)
PVOID Buffer
);
NTSTATUS SendIoCtrlAsynchronously
(
_In_ WDFREQUEST Request,
_In_ ULONG IoControlCode,
_In_opt_ WDFMEMORY MemIn,
_In_opt_ WDFMEMORY MemOut,
_In_ PFN_WDF_REQUEST_COMPLETION_ROUTINE CompletionRoutine,
_In_ WDFCONTEXT Context
);
NTSTATUS SetBthHfpDeviceCapabilities
(
_In_ BOOL bSupports16kHzSampling
);
NTSTATUS GetBthHfpDescriptor
(
_Out_ PBTHHFP_DESCRIPTOR2 * Descriptor
);
NTSTATUS EnableBthHfpNrecDisableStatusNotification();
NTSTATUS GetBthHfpVolumePropertyValues
(
_In_ ULONG Length,
_Out_ PKSPROPERTY_VALUES * PropValues
);
NTSTATUS SetBthHfpSpeakerVolume
(
_In_ LONG Volume
);
NTSTATUS GetBthHfpSpeakerVolume
(
_Out_ LONG * Volume
);
NTSTATUS EnableBthHfpSpeakerVolumeStatusNotification();
NTSTATUS SetBthHfpMicVolume
(
_In_ LONG Volume
);
NTSTATUS GetBthHfpMicVolume
(
_Out_ LONG * Volume
);
NTSTATUS EnableBthHfpMicVolumeStatusNotification();
NTSTATUS GetBthHfpConnectionStatus
(
_Out_ BOOL * ConnectionStatus
);
NTSTATUS EnableBthHfpConnectionStatusNotification();
static
NTSTATUS CreateCustomEndpointMinipair
(
_In_ PENDPOINT_MINIPAIR pBaseMinipair,
_In_ PUNICODE_STRING FriendlyName,
_In_ PGUID pCategory,
_Outptr_ PENDPOINT_MINIPAIR *ppCustomMinipair
);
static
NTSTATUS UpdateCustomEndpointCategory
(
_In_ PPCFILTER_DESCRIPTOR pCustomMinipairTopoFilter,
_In_ PPCPIN_DESCRIPTOR pCustomMinipairTopoPins,
_In_ PGUID pCategory
);
static
VOID DeleteCustomEndpointMinipair
(
_In_ PENDPOINT_MINIPAIR CustomMinipair
);
NTSTATUS GetBthHfpCodecId
(
_Out_ UCHAR * CodecId
);
NTSTATUS SetBthHfpConnect();
NTSTATUS SetBthHfpDisconnect();
NTSTATUS SetBthHfpStreamOpen();
NTSTATUS SetBthHfpStreamClose();
NTSTATUS EnableBthHfpStreamStatusNotification();
NTSTATUS StopBthHfpStreamStatusNotification();
NTSTATUS CreateFilterNames(
_In_ PUNICODE_STRING HfpDeviceSymbolicLinkName
);
//
// WDF I/O Target callback.
//
static
EVT_WDF_IO_TARGET_QUERY_REMOVE EvtBthHfpTargetQueryRemove;
static
EVT_WDF_IO_TARGET_REMOVE_CANCELED EvtBthHfpTargetRemoveCanceled;
static
EVT_WDF_IO_TARGET_REMOVE_COMPLETE EvtBthHfpTargetRemoveComplete;
//
// Status notifications callbacks.
//
static
EVT_WDF_REQUEST_COMPLETION_ROUTINE EvtBthHfpDeviceStreamStatusCompletion;
static
EVT_WDF_REQUEST_COMPLETION_ROUTINE EvtBthHfpDeviceNotificationStatusCompletion;
static
EVT_WDF_WORKITEM EvtBthHfpDeviceNotificationStatusWorkItem;
};
#endif // SYSVAD_BTH_BYPASS
|