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
|
/*++
Copyright (c) Microsoft Corporation. All rights reserved.
Module Name:
Driver.cpp
Abstract:
Sample soundwire Codec driver
Environment:
Kernel mode only
--*/
#include "private.h"
#ifndef __INTELLISENSE__
#include "driver.tmh"
#endif
RECORDER_LOG g_SDCAVCodecLog{ nullptr };
INIT_CODE_SEG
void
Test_ClientVersionHigherThanFramework()
{
PAGED_CODE();
// example on how to check if a function is available.
/*
if (ACX_IS_FUNCTION_AVAILABLE(AcxCircuitCreate)) {
DbgPrint("Available: AcxCircuitCreate\n");
}
else
{
DbgPrint("Not available: AcxCircuitCreate\n");
ASSERT(FALSE);
}
*/
if (ACX_IS_FIELD_AVAILABLE(ACX_DEVICEINIT_CONFIG, SynchronizationScope)) {
ACX_DEVICEINIT_CONFIG config;
ACX_DEVICEINIT_CONFIG_INIT(&config);
DbgPrint("Available: ACX_DEVICEINIT_CONFIG.SynchronizationScope\n");
}
else
{
DbgPrint("Not available: ACX_DEVICEINIT_CONFIG.SynchronizationScope\n");
ASSERT(FALSE);
}
}
PAGED_CODE_SEG
VOID Codec_DriverUnload(_In_ WDFDRIVER Driver)
{
PAGED_CODE();
if (!Driver)
{
ASSERT(FALSE);
return;
}
WPP_CLEANUP(WdfDriverWdmGetDriverObject(Driver));
if (g_RegistryPath.Buffer != NULL)
{
ExFreePool(g_RegistryPath.Buffer);
RtlZeroMemory(&g_RegistryPath, sizeof(g_RegistryPath));
}
return;
}
INIT_CODE_SEG
NTSTATUS
DriverEntry(
_In_ PDRIVER_OBJECT DriverObject,
_In_ PUNICODE_STRING RegistryPath
)
/*++
Routine Description:
DriverEntry initializes the driver and is the first routine called by the
system after the driver is loaded.
Parameters Description:
DriverObject - represents the instance of the function driver that is loaded
into memory. DriverEntry must initialize members of DriverObject before it
returns to the caller. DriverObject is allocated by the system before the
driver is loaded, and it is released by the system after the system unloads
the function driver from memory.
RegistryPath - represents the driver specific path in the Registry.
The function driver can use the path to store driver related data between
reboots. The path does not store hardware instance specific data.
Return Value:
STATUS_SUCCESS if successful,
STATUS_UNSUCCESSFUL otherwise.
--*/
{
PAGED_CODE();
NTSTATUS status = STATUS_SUCCESS;
WPP_INIT_TRACING(DriverObject, RegistryPath);
auto exit = scope_exit([&status, &DriverObject]() {
if (!NT_SUCCESS(status))
{
if (g_RegistryPath.Buffer != NULL)
{
ExFreePool(g_RegistryPath.Buffer);
RtlZeroMemory(&g_RegistryPath, sizeof(g_RegistryPath));
}
WPP_CLEANUP(DriverObject);
}
else
{
DrvLogInfo(g_SDCAVCodecLog, FLAG_INIT, "ACX SDCA Virtual Codec Driver Init complete, %!STATUS!", status);
}
});
RETURN_NTSTATUS_IF_FAILED(CopyRegistrySettingsPath(RegistryPath));
//
// Initiialize driver config to control the attributes that
// are global to the driver. Note that framework by default
// provides a driver unload routine. If you create any resources
// in the DriverEntry and want to be cleaned in driver unload,
// you can override that by manually setting the EvtDriverUnload in the
// config structure. In general xxx_CONFIG_INIT macros are provided to
// initialize most commonly used members.
//
WDF_DRIVER_CONFIG wdfCfg;
WDF_DRIVER_CONFIG_INIT(&wdfCfg, Codec_EvtBusDeviceAdd);
wdfCfg.EvtDriverUnload = Codec_DriverUnload;
//
// Add a driver context. (for illustration purposes only).
//
WDF_OBJECT_ATTRIBUTES attributes;
WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&attributes, CODEC_DRIVER_CONTEXT);
//
// Create a framework driver object to represent our driver.
//
WDFDRIVER driver;
RETURN_NTSTATUS_IF_FAILED(WdfDriverCreate(
DriverObject,
RegistryPath,
&attributes, // Driver Attributes
&wdfCfg, // Driver Config Info
&driver // hDriver
));
RECORDER_CONFIGURE_PARAMS recorderConfig;
RECORDER_CONFIGURE_PARAMS_INIT(&recorderConfig);
recorderConfig.CreateDefaultLog = FALSE;
WppRecorderConfigure(&recorderConfig);
RECORDER_LOG_CREATE_PARAMS recorderLogCreateParams;
RECORDER_LOG_CREATE_PARAMS_INIT(&recorderLogCreateParams, NULL);
recorderLogCreateParams.TotalBufferSize = WPP_TOTAL_BUFFER_SIZE;
recorderLogCreateParams.ErrorPartitionSize = WPP_ERROR_PARTITION_SIZE;
RtlStringCbPrintfA(recorderLogCreateParams.LogIdentifier,
RECORDER_LOG_IDENTIFIER_MAX_CHARS,
"SDCAVCodec");
RECORDER_LOG logHandle = NULL;
status = WppRecorderLogCreate(&recorderLogCreateParams, &logHandle);
if (!NT_SUCCESS(status))
{
logHandle = NULL;
// Non fatal failure
status = STATUS_SUCCESS;
}
g_SDCAVCodecLog = logHandle;
//
// Post init.
//
ACX_DRIVER_CONFIG acxCfg;
ACX_DRIVER_CONFIG_INIT(&acxCfg);
RETURN_NTSTATUS_IF_FAILED(AcxDriverInitialize(driver, &acxCfg));
//
// Test ACX bindings.
//
ACX_DRIVER_VERSION_AVAILABLE_PARAMS ver;
ACX_DRIVER_VERSION_AVAILABLE_PARAMS_INIT(&ver, 1, 0);
if (!AcxDriverIsVersionAvailable(driver, &ver)) {
status = STATUS_DRIVER_INTERNAL_ERROR;
DbgPrint("Unexpected ACX library version.\n");
ASSERT(FALSE);
}
RETURN_NTSTATUS_IF_FAILED(status);
Test_ClientVersionHigherThanFramework();
return status;
}
|