summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYang You (UU) <[email protected]>2025-11-16 12:38:39 -0800
committerYang You (UU) <[email protected]>2025-11-16 12:38:39 -0800
commit90a7fc175216f84a11cda994958cd1634341783f (patch)
treeb6dfba03bcc44b190ff18b5264adeac7f60f5926
parentc9aa1b84b884282ea161c528cb00d1417c0cdb50 (diff)
have the wifiHAL living with the wdfdevice addtional context memory
-rw-r--r--network/wlan/WIFICX/drivercode/adapter.cpp18
-rw-r--r--network/wlan/WIFICX/drivercode/adapter.h13
-rw-r--r--network/wlan/WIFICX/drivercode/device.cpp71
-rw-r--r--network/wlan/WIFICX/drivercode/device.h3
-rw-r--r--network/wlan/WIFICX/drivercode/driver.cpp2
-rw-r--r--network/wlan/WIFICX/drivercode/wifihal.cpp31
-rw-r--r--network/wlan/WIFICX/drivercode/wifihal.h32
-rw-r--r--network/wlan/WIFICX/drivercode/wifirequest.h3
8 files changed, 88 insertions, 85 deletions
diff --git a/network/wlan/WIFICX/drivercode/adapter.cpp b/network/wlan/WIFICX/drivercode/adapter.cpp
index e0ea86e6..f532ae02 100644
--- a/network/wlan/WIFICX/drivercode/adapter.cpp
+++ b/network/wlan/WIFICX/drivercode/adapter.cpp
@@ -7,7 +7,23 @@
#include "adapter.tmh"
_Use_decl_annotations_
-NTSTATUS WifiCxTestAdapterStart(NETADAPTER netAdapter)
+NTSTATUS WifiIhvInitAdapterContext(_In_ WDFDEVICE Device, _In_ NETADAPTER NetAdapter)
+{
+ PWIFI_IHV_DEVICE_CONTEXT deviceContext = WifiGetIhvDeviceContext(Device);
+ PWIFI_IHV_NETADAPTER_CONTEXT netAdapterContext = WifiGetIhvNetAdapterContext(NetAdapter);
+
+ if (deviceContext->primaryStaAdapter == WDF_NO_HANDLE)
+ {
+ deviceContext->primaryStaAdapter = NetAdapter;
+ }
+
+ netAdapterContext->WifiDeviceContext = deviceContext;
+
+ return STATUS_SUCCESS;
+}
+
+_Use_decl_annotations_
+NTSTATUS WifiIhvAdapterStart(NETADAPTER netAdapter)
{
TraceEntry();
diff --git a/network/wlan/WIFICX/drivercode/adapter.h b/network/wlan/WIFICX/drivercode/adapter.h
index 65e7e023..eb39dee1 100644
--- a/network/wlan/WIFICX/drivercode/adapter.h
+++ b/network/wlan/WIFICX/drivercode/adapter.h
@@ -9,17 +9,8 @@
// maximum link speed for send and recv in bps
#define WIFI_MEDIA_MAX_SPEED 1'000'000'000
-//
-// NetAdapter functions
-//
-
-EVT_NET_ADAPTER_CREATE_TXQUEUE EvtAdapterCreateTxQueue;
-EVT_NET_ADAPTER_CREATE_RXQUEUE EvtAdapterCreateRxQueue;
-
-EVT_WDF_DEVICE_CONTEXT_DESTROY MbbDestroyAdapterContext;
-
-NTSTATUS WifiCxTestAdapterStart(_In_ NETADAPTER netAdapter);
-
+NTSTATUS WifiIhvInitAdapterContext(_In_ WDFDEVICE Device, _In_ NETADAPTER NetAdapter);
+NTSTATUS WifiIhvAdapterStart(_In_ NETADAPTER netAdapter);
// Context for each "Wdi Port"[NetAdapter] instance.
// Each NetAdapter instance corresponds to an IP interface
diff --git a/network/wlan/WIFICX/drivercode/device.cpp b/network/wlan/WIFICX/drivercode/device.cpp
index a0614807..9ea10fd1 100644
--- a/network/wlan/WIFICX/drivercode/device.cpp
+++ b/network/wlan/WIFICX/drivercode/device.cpp
@@ -11,25 +11,18 @@ NTSTATUS EvtDevicePrepareHardware(WDFDEVICE device, WDFCMRESLIST resourcesRaw, W
{
UNREFERENCED_PARAMETER(resourcesRaw);
UNREFERENCED_PARAMETER(resourcesTranslated);
- UNREFERENCED_PARAMETER(device);
- NTSTATUS status = STATUS_SUCCESS;
- //status = WifiCxTestSetDeviceCapabilities(device);
-
- if (!NT_SUCCESS(status))
- {
- WFCError("%!FUNC!: WifiCxTestSetDeviceCapabilities failed with %!STATUS!", status);
- return status;
- }
+ WX_RETURN_NTSTATUS_IF_NOT_NT_SUCCESS_MSG(
+ WifiHAL::_Create(device),
+ "WifiHAL::_Create failed");
WFCInfo("Device=0x%p", device);
- return status;
+ return STATUS_SUCCESS;
}
_Use_decl_annotations_
NTSTATUS EvtDeviceReleaseHardware(WDFDEVICE device, WDFCMRESLIST resourcesTranslated)
{
- UNREFERENCED_PARAMETER(device);
UNREFERENCED_PARAMETER(resourcesTranslated);
WFCInfo("Device=0x%p", device);
@@ -40,24 +33,9 @@ NTSTATUS EvtDeviceReleaseHardware(WDFDEVICE device, WDFCMRESLIST resourcesTransl
_Use_decl_annotations_
void EvtDeviceSurpriseRemoval(WDFDEVICE device)
{
- UNREFERENCED_PARAMETER(device);
WFCInfo("Device=0x%p is surprise removed", device);
}
-static NTSTATUS WifiInitAdapterContext(_In_ WDFDEVICE Device, _In_ NETADAPTER NetAdapter)
-{
- PWIFI_IHV_DEVICE_CONTEXT deviceContext = WifiGetIhvDeviceContext(Device);
- PWIFI_IHV_NETADAPTER_CONTEXT netAdapterContext = WifiGetIhvNetAdapterContext(NetAdapter);
- NTSTATUS status = STATUS_SUCCESS;
- if (deviceContext->primaryStaAdapter == WDF_NO_HANDLE)
- {
- deviceContext->primaryStaAdapter = NetAdapter;
- }
-
- netAdapterContext->WifiDeviceContext = deviceContext;
-
- return status;
-}
_Use_decl_annotations_
NTSTATUS EvtWifiDeviceCreateAdapter(WDFDEVICE Device, NETADAPTER_INIT* AdapterInit)
@@ -73,39 +51,20 @@ NTSTATUS EvtWifiDeviceCreateAdapter(WDFDEVICE Device, NETADAPTER_INIT* AdapterIn
WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&adapterAttributes, WIFI_IHV_NETADAPTER_CONTEXT);
adapterAttributes.EvtCleanupCallback = EvtAdapterCleanup;
- NETADAPTER netAdapter;
- NTSTATUS ntStatus = NetAdapterCreate(AdapterInit, &adapterAttributes, &netAdapter);
- if (!NT_SUCCESS(ntStatus))
- {
- WFCError("%!FUNC!: NetAdapterCreate failed, status=0x%x", ntStatus);
- return ntStatus;
- }
+ NETADAPTER netAdapter{};
+ WX_RETURN_NTSTATUS_IF_NOT_NT_SUCCESS_MSG(
+ NetAdapterCreate(AdapterInit, &adapterAttributes, &netAdapter), "Failed to create NetAdapter");
- ntStatus = WifiAdapterInitialize(netAdapter);
- ASSERT(NT_SUCCESS(ntStatus));
- if (!NT_SUCCESS(ntStatus))
- {
- WFCError("%!FUNC!: WifiAdapterInitialize failed with %!STATUS!", ntStatus);
- return ntStatus;
- }
+ WX_RETURN_NTSTATUS_IF_NOT_NT_SUCCESS_MSG(
+ WifiAdapterInitialize(netAdapter), "Failed to initialize WifiAdapter");
- ntStatus = WifiInitAdapterContext(Device, netAdapter);
- ASSERT(NT_SUCCESS(ntStatus));
- if (!NT_SUCCESS(ntStatus))
- {
- WFCError("%!FUNC!: WifiInitAdapterContext failed with %!STATUS!", ntStatus);
- return ntStatus;
- }
+ WX_RETURN_NTSTATUS_IF_NOT_NT_SUCCESS_MSG(
+ WifiIhvInitAdapterContext(Device, netAdapter), "Failed to initialize WifiAdapterContext");
+
+ WX_RETURN_NTSTATUS_IF_NOT_NT_SUCCESS_MSG(
+ WifiIhvAdapterStart(netAdapter), "Failed to start WifiIhvAdapter");
- ntStatus = WifiCxTestAdapterStart(netAdapter);
- ASSERT(NT_SUCCESS(ntStatus));
- if (!NT_SUCCESS(ntStatus))
- {
- WFCError("%!FUNC!: WifiCxTestAdapterStart failed with %!STATUS!", ntStatus);
- return ntStatus;
- }
-
- return ntStatus;
+ return STATUS_SUCCESS;
}
_Use_decl_annotations_
diff --git a/network/wlan/WIFICX/drivercode/device.h b/network/wlan/WIFICX/drivercode/device.h
index 57de18f3..8c00515e 100644
--- a/network/wlan/WIFICX/drivercode/device.h
+++ b/network/wlan/WIFICX/drivercode/device.h
@@ -18,10 +18,7 @@ typedef struct _WIFI_IHV_DEVICE_CONTEXT
//
void* WdfTriageInfoPtr;
WDFDEVICE WdfDevice;
- WDI_GET_ADAPTER_CAPABILITIES_PARAMETERS AdapterCapabilities;
TLV_CONTEXT TlvContext;
- UINT32 LastConnectTransactionId;
- WDI_AUTH_ALGORITHM LastAuthAlgo;
NETADAPTER primaryStaAdapter;
WifiHAL* wifiHAL;
} WIFI_IHV_DEVICE_CONTEXT, * PWIFI_IHV_DEVICE_CONTEXT;
diff --git a/network/wlan/WIFICX/drivercode/driver.cpp b/network/wlan/WIFICX/drivercode/driver.cpp
index 562769ef..f25cc7b5 100644
--- a/network/wlan/WIFICX/drivercode/driver.cpp
+++ b/network/wlan/WIFICX/drivercode/driver.cpp
@@ -65,7 +65,7 @@ Return Value:
return status;
}
- //TraceExit(status);
+ TraceExit(status);
return status;
}
diff --git a/network/wlan/WIFICX/drivercode/wifihal.cpp b/network/wlan/WIFICX/drivercode/wifihal.cpp
index bbfa04e0..4619e87c 100644
--- a/network/wlan/WIFICX/drivercode/wifihal.cpp
+++ b/network/wlan/WIFICX/drivercode/wifihal.cpp
@@ -6,10 +6,35 @@
#include "WifiHal.h"
#include "WifiHal.tmh"
-WifiHAL::WifiHAL(WDFDEVICE Device)
+_Use_decl_annotations_
+NTSTATUS WifiHAL::_Create(WDFDEVICE Device)
+{
+ // Download firmware, initialize hardware, etc.
+
+ // Create WifiHAL object and associate it with Device context after FW ready
+ WDF_OBJECT_ATTRIBUTES attributes;
+ WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&attributes, WifiHAL);
+ attributes.EvtCleanupCallback = WifiHAL::_OnCleanup;
+ attributes.ParentObject = Device;
+
+ void* memory = nullptr;
+ WX_RETURN_NTSTATUS_IF_NOT_NT_SUCCESS_MSG(
+ WdfObjectAllocateContext(Device, &attributes, &memory), "Failed to allocate WifiHAL context. Device=%p", Device);
+
+ // Obtain the context and initialize it
+ auto* wifiHal = reinterpret_cast<WifiHAL*>(memory);
+ wifiHal->Initialize(Device, &WifiGetIhvDeviceContext(Device)->TlvContext);
+
+ WX_RETURN_NTSTATUS_IF_NOT_NT_SUCCESS_MSG(
+ wifiHal->WifiIhvSetDeviceCapabilities(),
+ "Failed to set device capabilities. Device=%p", Device);
+
+ return STATUS_SUCCESS;
+}
+
+void WifiHAL::_OnCleanup(WDFOBJECT Object)
{
- m_Device = Device;
- m_TlvContext = &WifiGetIhvDeviceContext(Device)->TlvContext;
+ UNREFERENCED_PARAMETER(Object);
}
NTSTATUS WifiHAL::WifiIhvIsDeviceReadyForRequest()
diff --git a/network/wlan/WIFICX/drivercode/wifihal.h b/network/wlan/WIFICX/drivercode/wifihal.h
index 844a9ccb..75c7d94d 100644
--- a/network/wlan/WIFICX/drivercode/wifihal.h
+++ b/network/wlan/WIFICX/drivercode/wifihal.h
@@ -5,7 +5,27 @@
class WifiHAL
{
public:
- WifiHAL(_In_ WDFDEVICE Device);
+ static NTSTATUS _Create(_In_ WDFDEVICE Device);
+ static void _OnCleanup(_In_ WDFOBJECT Object);
+
+ // Default ctor so context memory can be zeroed by WDF without placement new
+ WifiHAL() = default;
+
+ // Initialization routine replacing the previous parameterized ctor usage
+ void Initialize(_In_ WDFDEVICE Device, _In_ PCTLV_CONTEXT TlvContext)
+ {
+ m_Device = Device;
+ m_TlvContext = TlvContext;
+ m_CurrentRadioState = 0;
+ m_LastConnectEntryId = 0;
+ m_LastConnectTransactionId = 0;
+ m_LastAuthAlgo = WDI_AUTH_ALGO_UNKNOWN;
+ RtlZeroMemory(&m_ConnectedPeer, sizeof(m_ConnectedPeer));
+ // Initialize link addresses and supported bands (previously in-class const init)
+ m_LocalLinkAddresses[0] = {0x11, 0x01, 0x02, 0x03, 0x04, 0x21};
+ m_LocalLinkAddresses[1] = {0x11, 0x01, 0x02, 0x03, 0x04, 0x22};
+ m_SupportedBands = (WDI_BAND_ID_2400 | WDI_BAND_ID_5000 | WDI_BAND_ID_6000);
+ }
// Wifi request M3 working condition verification function
NTSTATUS WifiIhvIsDeviceReadyForRequest();
@@ -34,10 +54,8 @@ private:
WDI_AUTH_ALGORITHM m_LastAuthAlgo{};
DOT11_MAC_ADDRESS m_ConnectedPeer{};
- const WDI_MAC_ADDRESS m_LocalLinkAddresses[2] = {
- {0x11, 0x01, 0x02, 0x03, 0x04, 0x21},
- {0x11, 0x01, 0x02, 0x03, 0x04, 0x22},
- };
-
- const ULONG m_SupportedBands = (WDI_BAND_ID_2400 | WDI_BAND_ID_5000 | WDI_BAND_ID_6000);
+ // Removed const so we can initialize without running a constructor via placement new
+ WDI_MAC_ADDRESS m_LocalLinkAddresses[2];
+ ULONG m_SupportedBands;
};
+WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(WifiHAL, GetWifiHalFromHandle);
diff --git a/network/wlan/WIFICX/drivercode/wifirequest.h b/network/wlan/WIFICX/drivercode/wifirequest.h
index c3317eb3..74380548 100644
--- a/network/wlan/WIFICX/drivercode/wifirequest.h
+++ b/network/wlan/WIFICX/drivercode/wifirequest.h
@@ -4,9 +4,6 @@
EVT_WIFI_DEVICE_SEND_COMMAND EvtWifiDeviceSendCommand;
-static NTSTATUS ProcessWifiRequest(
- _In_ WDFDEVICE Device, _In_ UINT16 MessageId, _In_ void* Buffer, _In_ UINT InBufferLen, _In_ UINT OutBufferLen, _In_ UINT* pBytesWritten);
-
void WifiIhvSendUnsolicitedIndicationToOs(
_In_ WDFDEVICE Device,
_In_ PWDI_MESSAGE_HEADER pWdiHeader,