forked from coolstar/wificx-skeleton
-
Notifications
You must be signed in to change notification settings - Fork 0
/
driver.cpp
153 lines (113 loc) · 4.4 KB
/
driver.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
#include "precomp.h"
#include "trace.h"
#include "device.h"
#include "adapter.h"
#include "wifidevice.h"
#include "power.h"
// {3ABD5B77-B0E2-46CC-8C30-7BFBB83B18F3}
TRACELOGGING_DEFINE_PROVIDER(
WiFiCxSampleTraceProvider,
"WiFiCxSample.Trace.Provider",
(0x3abd5b77, 0xb0e2, 0x46cc, 0x8c, 0x30, 0x7b, 0xfb, 0xb8, 0x3b, 0x18, 0xf3));
EXTERN_C __declspec(code_seg("INIT")) DRIVER_INITIALIZE DriverEntry;
EVT_WDF_DRIVER_UNLOAD EvtDriverUnload;
EVT_WDF_DRIVER_DEVICE_ADD EvtDriverDeviceAdd;
_Use_decl_annotations_
__declspec(code_seg("INIT"))
NTSTATUS
DriverEntry(
_In_ PDRIVER_OBJECT driverObject,
_In_ PUNICODE_STRING registryPath)
{
bool traceLoggingRegistered = false;
NTSTATUS status = STATUS_SUCCESS;
GOTO_IF_NOT_NT_SUCCESS(Exit, status,
TraceLoggingRegister(WiFiCxSampleTraceProvider));
traceLoggingRegistered = true;
TraceEntry(TraceLoggingUnicodeString(registryPath));
WDF_DRIVER_CONFIG driverConfig;
WDF_DRIVER_CONFIG_INIT(&driverConfig, EvtDriverDeviceAdd);
driverConfig.DriverPoolTag = 'RTEK';
driverConfig.EvtDriverUnload = EvtDriverUnload;
GOTO_IF_NOT_NT_SUCCESS(Exit, status,
WdfDriverCreate(driverObject, registryPath, WDF_NO_OBJECT_ATTRIBUTES, &driverConfig, NULL));
Exit:
if (traceLoggingRegistered)
{
TraceExitResult(status);
if (!NT_SUCCESS(status))
{
TraceLoggingUnregister(WiFiCxSampleTraceProvider);
}
}
return status;
}
_Use_decl_annotations_
NTSTATUS
#pragma prefast(suppress: __WARNING_EXCESSIVESTACKUSAGE, "TVS:12813961 call stack depth well-defined")
EvtDriverDeviceAdd(
_In_ WDFDRIVER driver,
_Inout_ PWDFDEVICE_INIT deviceInit)
{
UNREFERENCED_PARAMETER((driver));
TraceEntry();
NTSTATUS status = STATUS_SUCCESS;
GOTO_IF_NOT_NT_SUCCESS(Exit, status,
NetDeviceInitConfig(deviceInit));
GOTO_IF_NOT_NT_SUCCESS(Exit, status,
WifiDeviceInitConfig(deviceInit));
WDF_OBJECT_ATTRIBUTES deviceAttributes;
WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&deviceAttributes, MTK_DEVICE);
{
WDF_PNPPOWER_EVENT_CALLBACKS pnpPowerCallbacks;
WDF_PNPPOWER_EVENT_CALLBACKS_INIT(&pnpPowerCallbacks);
pnpPowerCallbacks.EvtDevicePrepareHardware = EvtDevicePrepareHardware;
pnpPowerCallbacks.EvtDeviceReleaseHardware = EvtDeviceReleaseHardware;
pnpPowerCallbacks.EvtDeviceD0Entry = EvtDeviceD0Entry;
pnpPowerCallbacks.EvtDeviceD0Exit = EvtDeviceD0Exit;
WdfDeviceInitSetPnpPowerEventCallbacks(deviceInit, &pnpPowerCallbacks);
}
/* {
WDF_POWER_POLICY_EVENT_CALLBACKS powerPolicyCallbacks;
WDF_POWER_POLICY_EVENT_CALLBACKS_INIT(&powerPolicyCallbacks);
powerPolicyCallbacks.EvtDeviceArmWakeFromSx = EvtDeviceArmWakeFromSx;
powerPolicyCallbacks.EvtDeviceDisarmWakeFromSx = EvtDeviceDisarmWakeFromSx;
WdfDeviceInitSetPowerPolicyEventCallbacks(deviceInit, &powerPolicyCallbacks);
}*/
WDFDEVICE wdfDevice;
GOTO_IF_NOT_NT_SUCCESS(Exit, status,
WdfDeviceCreate(&deviceInit, &deviceAttributes, &wdfDevice));
MTK_DEVICE* devContext = MtkGetDeviceContext(wdfDevice);
devContext->FxDevice = wdfDevice;
WdfDeviceSetAlignmentRequirement(wdfDevice, FILE_256_BYTE_ALIGNMENT);
WDF_DEVICE_POWER_POLICY_IDLE_SETTINGS idleSettings;
WDF_DEVICE_POWER_POLICY_IDLE_SETTINGS_INIT(&idleSettings, IdleCannotWakeFromS0);
idleSettings.UserControlOfIdleSettings = IdleAllowUserControl;
GOTO_IF_NOT_NT_SUCCESS(Exit, status,
WdfDeviceAssignS0IdleSettings(wdfDevice, &idleSettings));
/*WDF_DEVICE_POWER_POLICY_WAKE_SETTINGS wakeSettings;
WDF_DEVICE_POWER_POLICY_WAKE_SETTINGS_INIT(&wakeSettings);
wakeSettings.UserControlOfWakeSettings = WakeAllowUserControl;
GOTO_IF_NOT_NT_SUCCESS(Exit, status,
WdfDeviceAssignSxWakeSettings(wdfDevice, &wakeSettings));*/
WIFI_DEVICE_CONFIG wifiDeviceConfig;
WIFI_DEVICE_CONFIG_INIT(&wifiDeviceConfig,
WDI_VERSION_LATEST,
EvtWiFiDeviceSendCommand,
EvtWiFiDeviceCreateAdapter,
EvtWifiDeviceCreateWiFiDirectDevice);
GOTO_IF_NOT_NT_SUCCESS(Exit, status,
WifiDeviceInitialize(wdfDevice, &wifiDeviceConfig));
Exit:
TraceExitResult(status);
return status;
}
_Use_decl_annotations_
VOID
EvtDriverUnload(
_In_ WDFDRIVER driver)
{
UNREFERENCED_PARAMETER((driver));
TraceEntry();
TraceLoggingUnregister(WiFiCxSampleTraceProvider);
}