-
Notifications
You must be signed in to change notification settings - Fork 1
/
wifidevice.cpp
169 lines (129 loc) · 4.39 KB
/
wifidevice.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
#include "precomp.h"
#include "trace.h"
#include "device.h"
#include "wifidevice.h"
#include "adapter.h"
NTSTATUS
MtkRegisterScatterGatherDma(
_In_ MTK_ADAPTER* adapter)
{
TraceEntryMtkAdapter(adapter);
WDF_DMA_ENABLER_CONFIG dmaEnablerConfig;
WDF_DMA_ENABLER_CONFIG_INIT(&dmaEnablerConfig, WdfDmaProfileScatterGather64, MTK_MAX_PACKET_SIZE);
dmaEnablerConfig.Flags |= WDF_DMA_ENABLER_CONFIG_REQUIRE_SINGLE_TRANSFER;
dmaEnablerConfig.WdmDmaVersionOverride = 3;
NTSTATUS status = STATUS_SUCCESS;
GOTO_IF_NOT_NT_SUCCESS(Exit, status,
WdfDmaEnablerCreate(
adapter->WdfDevice,
&dmaEnablerConfig,
WDF_NO_OBJECT_ATTRIBUTES,
&adapter->DmaEnabler),
TraceLoggingMtkAdapter(adapter));
Exit:
TraceExitResult(status);
return status;
}
_Use_decl_annotations_
NTSTATUS
EvtWiFiDeviceCreateAdapter(
_In_ WDFDEVICE WdfDevice,
_Inout_ NETADAPTER_INIT* AdapterInit
)
{
TraceEntry();
NTSTATUS status = STATUS_SUCCESS;
GOTO_WITH_INSUFFICIENT_RESOURCES_IF_NULL(Exit, status, AdapterInit);
NET_ADAPTER_DATAPATH_CALLBACKS datapathCallbacks;
NET_ADAPTER_DATAPATH_CALLBACKS_INIT(
&datapathCallbacks,
EvtAdapterCreateTxQueue,
EvtAdapterCreateRxQueue);
NetAdapterInitSetDatapathCallbacks(
AdapterInit,
&datapathCallbacks);
WDF_OBJECT_ATTRIBUTES adapterAttributes;
WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&adapterAttributes, MTK_ADAPTER);
NETADAPTER netAdapter;
GOTO_IF_NOT_NT_SUCCESS(Exit, status,
NetAdapterCreate(AdapterInit, &adapterAttributes, &netAdapter));
GOTO_IF_NOT_NT_SUCCESS(Exit, status,
WifiAdapterInitialize(netAdapter));
MTK_ADAPTER* adapter = MtkGetAdapterContext(netAdapter);
MTK_DEVICE* device = MtkGetDeviceContext(WdfDevice);
device->Adapter = adapter;
GOTO_IF_NOT_NT_SUCCESS(Exit, status,
MtkInitializeAdapterContext(adapter, WdfDevice, netAdapter));
GOTO_IF_NOT_NT_SUCCESS(Exit, status,
MtkRegisterScatterGatherDma(adapter),
TraceLoggingMtkAdapter(adapter));
{
//Temp for barebones init
NET_ADAPTER_LINK_STATE linkState;
NET_ADAPTER_LINK_STATE_INIT(
&linkState,
NDIS_LINK_SPEED_UNKNOWN,
MediaConnectStateDisconnected,
MediaDuplexStateUnknown,
NetAdapterPauseFunctionTypeUnknown,
NetAdapterAutoNegotiationFlagNone);
NetAdapterSetLinkState(adapter->NetAdapter, &linkState);
}
GOTO_IF_NOT_NT_SUCCESS(Exit, status,
MtkAdapterStart(adapter));
Exit:
TraceExitResult(status);
return status;
}
_Use_decl_annotations_
void
EvtWiFiDeviceSendCommand(
_In_ WDFDEVICE WdfDevice,
_Inout_ WIFIREQUEST Request
)
{
TraceEntry();
UNREFERENCED_PARAMETER(WdfDevice);
typedef struct {
UINT16 Type;
UINT16 Len;
UINT8 Buf[];
} WIFICX_TLV, *PWIFICX_TLV;
UINT16 MessageID = WifiRequestGetMessageId(Request);
UINT InputBufferLen, OutputBufferLen;
PWDI_MESSAGE_HEADER Buffer = (PWDI_MESSAGE_HEADER)WifiRequestGetInOutBuffer(Request, &InputBufferLen, &OutputBufferLen);
TraceLoggingWrite(WiFiCxSampleTraceProvider,
"WiFiCommand",
TraceLoggingHexInt16(MessageID),
TraceLoggingUInt32(InputBufferLen),
TraceLoggingUInt32(OutputBufferLen),
TraceLoggingUInt16(Buffer->PortId),
TraceLoggingUInt32(Buffer->TransactionId));
DbgPrint("Command: 0x%x, Input Len: %d, Output Len: %d\n", MessageID, InputBufferLen, OutputBufferLen);
WifiRequestComplete(Request, STATUS_NOT_IMPLEMENTED, 0);
Exit:
TraceExit();
}
_Use_decl_annotations_
NTSTATUS
EvtWifiDeviceCreateWiFiDirectDevice(
_In_ WDFDEVICE Device,
_In_ WIFIDIRECT_DEVICE_INIT* WfdDeviceInit
)
{
TraceEntry();
NTSTATUS status;
WDF_OBJECT_ATTRIBUTES wfdDeviceAttributes;
WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&wfdDeviceAttributes, MTK_WIFIDIRECTDEVICE);
WIFIDIRECTDEVICE wfdDevice;
GOTO_IF_NOT_NT_SUCCESS(Exit, status,
WifiDirectDeviceCreate(WfdDeviceInit, &wfdDeviceAttributes, &wfdDevice));
GOTO_IF_NOT_NT_SUCCESS(Exit, status,
WifiDirectDeviceInitialize(wfdDevice));
PMTK_WIFIDIRECTDEVICE wfdContext = MtkGetWifiDirectContext(wfdDevice);
wfdContext->WdfDevice = Device;
wfdContext->WifiDirectDevice = wfdDevice;
Exit:
TraceExitResult(status);
return status;
}