From 83019ae0c63454b2835f8fc245c7505351cee677 Mon Sep 17 00:00:00 2001 From: "Yang You (UU)" Date: Tue, 2 Dec 2025 13:37:13 -0800 Subject: Have the NetVAdapter Lib buildable with EWDK for both UM and KM --- .../netvadapterlibrary/code/rxqueue.cpp | 191 +++++++++++++++++++++ 1 file changed, 191 insertions(+) create mode 100644 network/netadaptercx/netvadapterlibrary/code/rxqueue.cpp (limited to 'network/netadaptercx/netvadapterlibrary/code/rxqueue.cpp') diff --git a/network/netadaptercx/netvadapterlibrary/code/rxqueue.cpp b/network/netadaptercx/netvadapterlibrary/code/rxqueue.cpp new file mode 100644 index 00000000..61c12ca3 --- /dev/null +++ b/network/netadaptercx/netvadapterlibrary/code/rxqueue.cpp @@ -0,0 +1,191 @@ +// Copyright (c) Microsoft Corporation. All rights reserved + +#include "pch.hpp" +#include "adapter.h" +#include "rxqueue.h" +#include "memory.h" + +static +void +CheckForWakeFrame( + NetvRxQueue * rx +) +{ + NET_RING_FRAGMENT_ITERATOR fi = NetRingGetAllFragments(rx->m_rings); + + if (! NetFragmentIteratorHasAny(&fi)) + { + return; + } + + auto *fragment = NetFragmentIteratorGetFragment(&fi); + auto *rxVirtualAddress = NetExtensionGetFragmentVirtualAddress( + &rx->VirtualAddressExtension, + NetFragmentIteratorGetIndex(&fi)); + + auto *fragmentBuffer = reinterpret_cast(rxVirtualAddress->VirtualAddress) + fragment->Offset; + + fragment->ValidLength = EnlCopyWakeFrame( + NetvEnlMLink[rx->m_adapter.EnlIndex].LinkHandle[0], + fragmentBuffer, + fragment->Capacity); + + // If there was a pending wake frame mark this fragment as complete, the normal advance code will get to it + fragment->Scratch = fragment->ValidLength > 0 ? 1 : 0; + + rx->CheckedWakeFrame = true; +} + + +NetvRxQueue::NetvRxQueue( + NETPACKETQUEUE Handle, + NetvAdapter & Adapter +) + : NetvQueue{Handle, Adapter, NetRxQueueGetRingCollection(Handle)} +{ + NET_EXTENSION_QUERY extension; + + NET_EXTENSION_QUERY_INIT( + &extension, + NET_FRAGMENT_EXTENSION_VIRTUAL_ADDRESS_NAME, + NET_FRAGMENT_EXTENSION_VIRTUAL_ADDRESS_VERSION_1, + NetExtensionTypeFragment); + + NetRxQueueGetExtension(m_handle, &extension, &VirtualAddressExtension); + + NET_EXTENSION_QUERY_INIT( + &extension, + NET_PACKET_EXTENSION_RSC_NAME, + NET_PACKET_EXTENSION_RSC_VERSION_2, + NetExtensionTypePacket); + + NetRxQueueGetExtension(m_handle, &extension, &UdpRscExtension); + + NET_EXTENSION_QUERY_INIT( + &extension, + NET_PACKET_EXTENSION_CHECKSUM_NAME, + NET_PACKET_EXTENSION_CHECKSUM_VERSION_1, + NetExtensionTypePacket); + + NetRxQueueGetExtension(m_handle, &extension, &RxXSumExtension); + + if (Adapter.PreallocatedRxBuffers) + { + NET_EXTENSION_QUERY_INIT( + &extension, + NET_FRAGMENT_EXTENSION_NET_MEMORY_NAME, + NET_FRAGMENT_EXTENSION_NET_MEMORY_VERSION_1, + NetExtensionTypeFragment); + + NetRxQueueGetExtension(m_handle, &extension, &NetMemoryExtension); + + NET_EXTENSION_QUERY_INIT( + &extension, + NET_FRAGMENT_EXTENSION_RETURN_CONTEXT_NAME, + NET_FRAGMENT_EXTENSION_RETURN_CONTEXT_VERSION_1, + NetExtensionTypeFragment); + + NetRxQueueGetExtension(m_handle, &extension, &NetMemoryReturnContextExtensionIn); + } + + EnlQueueHandle = EnlCreateQueue(Handle, RX); +} + +_Use_decl_annotations_ +void +NetvRxQueue::Destroy( + void +) +{ + EnlDestroyQueue(EnlQueueHandle, RX); +} + +void +NetvRxQueue::Start( + void +) +{ + auto link = NetvEnlMLink[m_adapter.EnlIndex].LinkHandle[0]; + auto port = &link->Ports[m_adapter.EnlPortIndex]; + auto queue = &port->RxQueue[0]; + + WDFVERIFY(queue->State == Stopped); + + queue->QueueNext = queue->QueueEnd = 0U; + + EnlIndicateQueueState(EnlQueueHandle, Started); +} + +void +NetvRxQueue::Stop( + void +) +{ + EnlIndicateQueueState(EnlQueueHandle, Stopped); +} + +_Use_decl_annotations_ +void +NetvRxQueue::Advance( + void +) +{ + auto fr = GetFragmentRing(); + NET_RING_PACKET_ITERATOR pi = NetRingGetAllPackets(m_rings); + NET_RING_FRAGMENT_ITERATOR fi = NetRingGetAllFragments(m_rings); + + // Ideally this would run in EvtQueueStart, but at that point the receive buffers are not + // attached to the fragment yet + if (! CheckedWakeFrame) + { + CheckForWakeFrame(this); + } + + // Move begin index forward for all fragments with Scratch == 1, thus returning them to the OS since we're done processing them. + for (; NetFragmentIteratorHasAny(&fi) && NetPacketIteratorHasAny(&pi); NetPacketIteratorAdvance(&pi), NetFragmentIteratorAdvance(&fi)) + { + NET_FRAGMENT const * fragment = NetFragmentIteratorGetFragment(&fi); + if (! fragment->Scratch) + { + break; + } + } + + if (m_adapter.PreallocatedRxBuffers) + { + NET_RING* dataBufferRing = GetNetMemoryReturnRing(); + while (dataBufferRing->BeginIndex != dataBufferRing->EndIndex) + { + NET_FRAGMENT_RETURN_CONTEXT* netMemoryReturnContextOut = + NetRingGetFragmentReturnContextAtIndex( + dataBufferRing, + dataBufferRing->BeginIndex); + + MemoryBuffer* memoryBuffer = reinterpret_cast(netMemoryReturnContextOut->Handle); + GetMemoryFromHandle(m_adapter.m_preallocatedRxBuffers)->ReturnBuffer(memoryBuffer); + dataBufferRing->BeginIndex = NetRingIncrementIndex(dataBufferRing, dataBufferRing->BeginIndex); + } + } + + NetFragmentIteratorSet(&fi); + NetPacketIteratorSet(&pi); + EnlRingDoorBell(EnlQueueHandle, fr->EndIndex); +} + +_Use_decl_annotations_ +void +NetvRxQueue::Cancel( + void +) +{ + CancelRxPackets(m_rings); +} + +_Use_decl_annotations_ +void +NetvRxQueue::SetNotify( + bool NotificationEnabled +) +{ + EnlArmInterrupt(EnlQueueHandle, NotificationEnabled); +} -- cgit v1.3.1 From 977cb2461482a898f96ee08f9cb24eb7f421da03 Mon Sep 17 00:00:00 2001 From: "Yang You (UU)" Date: Thu, 4 Dec 2025 15:03:24 -0800 Subject: intergrate the netvadapterlibrary with wificxsampledriver, cleanup the memory related header -KNEW.H --- .../netvadapterlibrary/Interface/netvadapter.h | 126 +++++++++++++ .../netvadapterlibrary/code/adapter.cpp | 8 +- .../netadaptercx/netvadapterlibrary/code/adapter.h | 141 -------------- .../netvadapterlibrary/code/configuration.cpp | 5 +- .../netadaptercx/netvadapterlibrary/code/enl.cpp | 11 +- network/netadaptercx/netvadapterlibrary/code/enl.h | 13 +- .../netvadapterlibrary/code/memory.cpp | 10 + .../netadaptercx/netvadapterlibrary/code/memory.h | 6 +- .../netvadapterlibrary/code/rtl/KNew.h | 203 --------------------- .../netvadapterlibrary/code/rtl/UmPool.h | 97 ---------- .../netvadapterlibrary/code/rtl/pooltypes.h | 53 ------ .../netvadapterlibrary/code/rxqueue.cpp | 10 +- .../netvadapterlibrary/code/txqueue.cpp | 2 +- .../km/netvadapterlibrarykm.vcxproj | 19 +- .../um/netvadapterlibraryum.vcxproj | 26 +-- network/wlan/WIFICX/drivercode/adapter.cpp | 135 +++++++++++--- network/wlan/WIFICX/drivercode/adapter.h | 32 +++- network/wlan/WIFICX/drivercode/device.cpp | 85 ++++++--- network/wlan/WIFICX/drivercode/device.h | 5 +- .../wlan/WIFICX/drivercode/memorymanagement.cpp | 14 +- network/wlan/WIFICX/drivercode/precomp.h | 5 + network/wlan/WIFICX/drivercode/wifihal.cpp | 4 +- .../wlan/WIFICX/km/wificxsampleclientkm.vcxproj | 25 ++- .../wlan/WIFICX/um/wificxsampleclientum.vcxproj | 21 ++- network/wlan/WIFICX/wificxsampleclient.sln | 34 ++++ 25 files changed, 469 insertions(+), 621 deletions(-) create mode 100644 network/netadaptercx/netvadapterlibrary/Interface/netvadapter.h delete mode 100644 network/netadaptercx/netvadapterlibrary/code/adapter.h delete mode 100644 network/netadaptercx/netvadapterlibrary/code/rtl/KNew.h delete mode 100644 network/netadaptercx/netvadapterlibrary/code/rtl/UmPool.h delete mode 100644 network/netadaptercx/netvadapterlibrary/code/rtl/pooltypes.h (limited to 'network/netadaptercx/netvadapterlibrary/code/rxqueue.cpp') diff --git a/network/netadaptercx/netvadapterlibrary/Interface/netvadapter.h b/network/netadaptercx/netvadapterlibrary/Interface/netvadapter.h new file mode 100644 index 00000000..d8e4294f --- /dev/null +++ b/network/netadaptercx/netvadapterlibrary/Interface/netvadapter.h @@ -0,0 +1,126 @@ +// Copyright (c) Microsoft Corporation. All rights reserved +#pragma once + +#define MAX_MULTICAST_LIST_SIZE 32 +#define MAC_ADDR_LEN 6 +#define MAX_RX_QUEUES 1 +#define MAX_TX_QUEUES 1 +#define MTU_SIZE 1500 + +#define NETV_NUMBER_OF_QUEUES 1 + +// supported filters +#define NETV_SUPPORTED_FILTERS ( \ + NetPacketFilterFlagDirected | \ + NetPacketFilterFlagMulticast | \ + NetPacketFilterFlagBroadcast | \ + NetPacketFilterFlagPromiscuous | \ + NetPacketFilterFlagAllMulticast) + + +NTSTATUS +ConfigureAndStartAdapter( + _In_ NETADAPTER Adapter + ); + +EVT_NET_ADAPTER_CREATE_TXQUEUE + CreateTxQueue; +EVT_NET_ADAPTER_CREATE_RXQUEUE + CreateRxQueue; + +typedef enum _NETV_FLOW_CONTROL +{ + NetvFlowControlDisabled = 0, + NetvFlowControlTxEnabled = 1, + NetvFlowControlRxEnabled = 2, + NetvFlowControlTxRxEnabled = 3, +} NETV_FLOW_CONTROL; + +typedef NTSTATUS(EVT_PDO_WAKE_SIGNAL)(_In_ void* Context); + +class NetvAdapter +{ + +public: + + NetvAdapter( + NETADAPTER Handle, + WDFDEVICE Device + ) noexcept; + + // Public API + void Destroy(); + NTSTATUS Initialize(); + NTSTATUS CreateRxQueue(_Inout_ NETRXQUEUE_INIT* NetRxQueueInit); + NTSTATUS CreateTxQueue(_Inout_ NETTXQUEUE_INIT* NetTxQueueInit); + + // Former INetvAdapter method (kept as regular method) + NTSTATUS ConfigureDataCapabilities(); + + // Existing public API + void SetPdoWakeSignalCallback(_In_ EVT_PDO_WAKE_SIGNAL* evtPdoWakeSignal, _In_ void* context); + void ArmWakeFromS0(void); + void DisarmWakeFromS0(void); + + NETADAPTER m_handle = WDF_NO_HANDLE; + + WDFDEVICE m_device = WDF_NO_HANDLE; + +#if ((NETADAPTER_VERSION_MAJOR == 2) && (NETADAPTER_VERSION_MINOR >= 6)) + BOOLEAN PreallocatedRxBuffers; + NETMEMORYCOLLECTION + m_preallocatedRxBuffers = WDF_NO_HANDLE; +#endif //NETCX 2.6 only + + // configuration + NET_ADAPTER_LINK_LAYER_ADDRESS PermanentAddress; + NET_ADAPTER_LINK_LAYER_ADDRESS CurrentAddress; + ULONG MACLastByte; + BOOLEAN S0Idle; + BOOLEAN EnableUsoUro; + + // Packet Filter and look ahead size. + NET_PACKET_FILTER_FLAGS PacketFilter; + + bool LinkAutoNeg{false}; + NETV_FLOW_CONTROL FlowControl; + + ULONG MtuSize; + ULONG CurrentPacketFilter; + ULONG NumMulticastAddresses; + NET_ADAPTER_LINK_LAYER_ADDRESS MulticastAddressList[MAX_MULTICAST_LIST_SIZE]; + + //ENL + LIST_ENTRY AdapterListLink; + ULONG LinkCount{1}; + ULONG LinkProcIndex; + ULONG EnlIndex; + ULONG EnlPortIndex; + BOOLEAN EnlIndexValid; + BOOLEAN EnlPortCreated; + BOOLEAN LinkPoll; + ULONG64 EnlTxDrops; + + // Offloads + bool UsoEnabled; + bool UroEnabled; + +private: + + _IRQL_requires_(PASSIVE_LEVEL) + void + SetLinkState( + void + ) const; + + + virtual NTSTATUS NetvAdapterReadAddress(); +}; + +extern NetvAdapter* NetvAdapterGetContextFromWDFObject(NETADAPTER netAdapter); + +typedef struct _GLOBAL_CONTEXT +{ +} GLOBAL_CONTEXT; + +extern GLOBAL_CONTEXT NetvGlobalContext; \ No newline at end of file diff --git a/network/netadaptercx/netvadapterlibrary/code/adapter.cpp b/network/netadaptercx/netvadapterlibrary/code/adapter.cpp index 1e6777b8..a047f163 100644 --- a/network/netadaptercx/netvadapterlibrary/code/adapter.cpp +++ b/network/netadaptercx/netvadapterlibrary/code/adapter.cpp @@ -8,7 +8,7 @@ #else #include "net/umxfilter.h" // Copied from Km XFilter.h, NETCX please move this xfilter.h into shared location #endif -#include "adapter.h" +#include "netvadapter.h" #include "rxqueue.h" #include "txqueue.h" #include "configuration.h" @@ -431,6 +431,7 @@ NetvAdapterSetUsoUroOffloadCapabilities( _Use_decl_annotations_ NTSTATUS NetvAdapter::ConfigureDataCapabilities() { +#if ((NETADAPTER_VERSION_MAJOR == 2) && (NETADAPTER_VERSION_MINOR >= 6)) if (PreallocatedRxBuffers) { WDF_OBJECT_ATTRIBUTES attributes; @@ -466,20 +467,21 @@ NTSTATUS NetvAdapter::ConfigureDataCapabilities() MAX_RX_BUFFER_SIZE )); } +#endif //NETCX 2.6 only NET_ADAPTER_TX_CAPABILITIES txCapabilities; NET_ADAPTER_TX_CAPABILITIES_INIT(&txCapabilities, MAX_TX_QUEUES); NET_ADAPTER_RX_CAPABILITIES rxCapabilities; NET_ADAPTER_RX_CAPABILITIES_INIT_SYSTEM_MANAGED(&rxCapabilities, MAX_RX_BUFFER_SIZE, MAX_RX_QUEUES); - +#if ((NETADAPTER_VERSION_MAJOR == 2) && (NETADAPTER_VERSION_MINOR >= 6)) if (PreallocatedRxBuffers) { rxCapabilities.AllocationMode = NetRxFragmentBufferAllocationModeDriverV2; rxCapabilities.AttachmentMode = NetRxFragmentBufferAttachmentModeDriver; rxCapabilities.MemoryCollection = m_preallocatedRxBuffers; } - +#endif //NETCX 2.6 only NET_ADAPTER_LINK_LAYER_CAPABILITIES linkLayerCapabilities; NET_ADAPTER_LINK_LAYER_CAPABILITIES_INIT(&linkLayerCapabilities, MAX_LINK_SPEED, MAX_LINK_SPEED); diff --git a/network/netadaptercx/netvadapterlibrary/code/adapter.h b/network/netadaptercx/netvadapterlibrary/code/adapter.h deleted file mode 100644 index 55c4948d..00000000 --- a/network/netadaptercx/netvadapterlibrary/code/adapter.h +++ /dev/null @@ -1,141 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved - -#pragma once - -#include - -#define MAX_RX_BUFFER_SIZE 65535 -#define MAX_RX_QUEUES 1 -#define MAX_TX_QUEUES 1 -#define MTU_SIZE 1500 -#define MAX_MULTICAST_LIST_SIZE 32 -#define MAC_ADDR_LEN 6 -#define NETV_NUMBER_OF_QUEUES 1 - -// supported filters -#define NETV_SUPPORTED_FILTERS ( \ - NetPacketFilterFlagDirected | \ - NetPacketFilterFlagMulticast | \ - NetPacketFilterFlagBroadcast | \ - NetPacketFilterFlagPromiscuous | \ - NetPacketFilterFlagAllMulticast) - -NTSTATUS -ConfigureAndStartAdapter( - _In_ NETADAPTER Adapter - ); - -EVT_NET_ADAPTER_CREATE_TXQUEUE - CreateTxQueue; -EVT_NET_ADAPTER_CREATE_RXQUEUE - CreateRxQueue; - -typedef enum _NETV_FLOW_CONTROL -{ - NetvFlowControlDisabled = 0, - NetvFlowControlTxEnabled = 1, - NetvFlowControlRxEnabled = 2, - NetvFlowControlTxRxEnabled = 3, -} NETV_FLOW_CONTROL; - -typedef NTSTATUS(EVT_PDO_WAKE_SIGNAL)(_In_ void* Context); - -class NetvAdapter -{ - -public: - - NetvAdapter( - NETADAPTER Handle, - WDFDEVICE Device - ) noexcept; - - void - Destroy( - void - ); - - NTSTATUS - Initialize( - void - ); - - NTSTATUS - CreateRxQueue( - NETRXQUEUE_INIT * NetRxQueueInit - ); - - NTSTATUS - CreateTxQueue( - NETTXQUEUE_INIT * NetTxQueueInit - ); - - NTSTATUS ConfigureDataCapabilities(); - - void SetPdoWakeSignalCallback(_In_ EVT_PDO_WAKE_SIGNAL* evtPdoWakeSignal, _In_ void* context); - - void ArmWakeFromS0(void); - - void DisarmWakeFromS0(void); - - NETADAPTER m_handle = WDF_NO_HANDLE; - - WDFDEVICE m_device = WDF_NO_HANDLE; - - NETMEMORYCOLLECTION - m_preallocatedRxBuffers = WDF_NO_HANDLE; - - // configuration - NET_ADAPTER_LINK_LAYER_ADDRESS PermanentAddress; - NET_ADAPTER_LINK_LAYER_ADDRESS CurrentAddress; - ULONG MACLastByte; - BOOLEAN S0Idle; - BOOLEAN EnableUsoUro; - BOOLEAN PreallocatedRxBuffers; - - // Packet Filter and look ahead size. - NET_PACKET_FILTER_FLAGS PacketFilter; - - bool LinkAutoNeg{false}; - NETV_FLOW_CONTROL FlowControl; - - ULONG MtuSize; - ULONG CurrentPacketFilter; - ULONG NumMulticastAddresses; - NET_ADAPTER_LINK_LAYER_ADDRESS MulticastAddressList[MAX_MULTICAST_LIST_SIZE]; - - //ENL - LIST_ENTRY AdapterListLink; - ULONG LinkCount{1}; - ULONG LinkProcIndex; - ULONG EnlIndex; - ULONG EnlPortIndex; - BOOLEAN EnlIndexValid; - BOOLEAN EnlPortCreated; - BOOLEAN LinkPoll; - ULONG64 EnlTxDrops; - - // Offloads - bool UsoEnabled; - bool UroEnabled; - -private: - - _IRQL_requires_(PASSIVE_LEVEL) - void - SetLinkState( - void - ) const; - - virtual NTSTATUS NetvAdapterReadAddress(); -}; - -extern NetvAdapter* NetvAdapterGetContextFromWDFObject(NETADAPTER netAdapter); - -typedef struct _GLOBAL_CONTEXT -{ -} GLOBAL_CONTEXT; - -extern GLOBAL_CONTEXT NetvGlobalContext; - - diff --git a/network/netadaptercx/netvadapterlibrary/code/configuration.cpp b/network/netadaptercx/netvadapterlibrary/code/configuration.cpp index 52ae7886..360cc43d 100644 --- a/network/netadaptercx/netvadapterlibrary/code/configuration.cpp +++ b/network/netadaptercx/netvadapterlibrary/code/configuration.cpp @@ -1,7 +1,8 @@ #include "pch.hpp" +#include "netvadapter.h" + #include "trace.h" #include "configuration.tmh" -#include "adapter.h" typedef struct _NETVADAPTER_ADVANCED_PROPERTY { @@ -27,7 +28,9 @@ NETVADAPTER_ADVANCED_PROPERTY NetvSupportedProperties[] = { CONSTANT_UNICODE_STRING(L"LinkProcIndex"), NETV_OFFSET(LinkProcIndex), NETV_SIZE(LinkProcIndex), 1000, 0, 1023 }, { CONSTANT_UNICODE_STRING(L"S0Idle"), NETV_OFFSET(S0Idle), NETV_SIZE(S0Idle), 0, 0, 1 }, { CONSTANT_UNICODE_STRING(L"EnableUsoUro"), NETV_OFFSET(EnableUsoUro), NETV_SIZE(EnableUsoUro), 0, 0, 1 }, +#if ((NETADAPTER_VERSION_MAJOR == 2) && (NETADAPTER_VERSION_MINOR >= 6)) { CONSTANT_UNICODE_STRING(L"PreallocatedRxBuffers"), NETV_OFFSET(PreallocatedRxBuffers), NETV_SIZE(PreallocatedRxBuffers), 0, 0, 1 }, +#endif //NETCX 2.6 only }; NTSTATUS diff --git a/network/netadaptercx/netvadapterlibrary/code/enl.cpp b/network/netadaptercx/netvadapterlibrary/code/enl.cpp index 4e19517f..30822900 100644 --- a/network/netadaptercx/netvadapterlibrary/code/enl.cpp +++ b/network/netadaptercx/netvadapterlibrary/code/enl.cpp @@ -1,7 +1,7 @@ +// Copyright (C) Microsoft Corporation. All rights reserved. #include "pch.hpp" #include -//#include -#include "adapter.h" +#include "netvadapter.h" #include "rxqueue.h" #include "txqueue.h" #include "trace.h" @@ -345,7 +345,7 @@ EnlpIterationRoutine( auto fragment = NetFragmentIteratorGetFragment(&rxFi); BYTE* fragmentBuffer = nullptr; - +#if ((NETADAPTER_VERSION_MAJOR == 2) && (NETADAPTER_VERSION_MINOR >= 6)) if (rxq->RxQueue->m_adapter.PreallocatedRxBuffers) { MemoryBuffer* bufferToUse = GetMemoryFromHandle(rxq->RxQueue->m_adapter.m_preallocatedRxBuffers)->PopAvailableBuffer(); @@ -382,6 +382,7 @@ EnlpIterationRoutine( fragment->Scratch = 0; } else +#endif //NETCX 2.6 only { auto const rxVirtualAddress = NetExtensionGetFragmentVirtualAddress( @@ -659,7 +660,7 @@ EnlCreateLink( ) { LogInformation(FLAG_DRIVER, L"ProcessorIndex=%u", ProcessorIndex); - + auto enlLink = wil::make_unique_nothrow(); RETURN_NTSTATUS_IF( STATUS_INSUFFICIENT_RESOURCES, @@ -745,7 +746,7 @@ EnlDeactivateLinkPort( ULONG i; NT_FRE_ASSERT(EnlIsPortActive(EnlLink, PortIndex)); - KLockThisExclusive(EnlLink->Lock); + //KLockThisExclusive(EnlLink->Lock); NT_FRE_ASSERT(!EnlpIsThreadPaused(&EnlLink->EnlThread)); EnlpPauseThread(&EnlLink->EnlThread); diff --git a/network/netadaptercx/netvadapterlibrary/code/enl.h b/network/netadaptercx/netvadapterlibrary/code/enl.h index 6089107e..529c36ac 100644 --- a/network/netadaptercx/netvadapterlibrary/code/enl.h +++ b/network/netadaptercx/netvadapterlibrary/code/enl.h @@ -1,4 +1,4 @@ - +// Copyright (C) Microsoft Corporation. All rights reserved. // // Emulated Network Link (ENL) definitions // @@ -21,16 +21,13 @@ // NBL completions by queueing DPCs to the target processor. // -//#include + #ifndef _KERNEL_MODE #define ASSERT(x) NT_ASSERT(x) -#include "rtl/UmPool.h" + #endif #include "rtl/KWaitEvent.h" -#include "rtl/KLockHolder.h" #include "rtl/KSpinLock.h" -#include "rtl/KPushLock.h" -#include "rtl/KNew.h" #define ENL_MAX_PROC_COUNT 16 #define ENLP_PORT_COUNT 2 @@ -239,10 +236,8 @@ struct DECLSPEC_ALIGN(PAGE_SIZE) ENLP_PORT ENLP_QUEUE RxQueue[ENL_MAX_PROC_COUNT]; }; -struct ENLP_LINK : - public NONPAGED_OBJECT<'LLNE'> +struct ENLP_LINK { - KPushLock Lock{}; ULONG64 Ts{}; ULONG64 BusyTicks{}; ULONG64 EmptyTicks{}; diff --git a/network/netadaptercx/netvadapterlibrary/code/memory.cpp b/network/netadaptercx/netvadapterlibrary/code/memory.cpp index 6d23f3bc..0c010d59 100644 --- a/network/netadaptercx/netvadapterlibrary/code/memory.cpp +++ b/network/netadaptercx/netvadapterlibrary/code/memory.cpp @@ -5,6 +5,8 @@ #include "trace.h" #include "memory.tmh" +#if ((NETADAPTER_VERSION_MAJOR == 2) && (NETADAPTER_VERSION_MINOR >= 6)) + NTSTATUS Memory::Initialize( NETMEMORYCOLLECTION MemoryCollection, @@ -75,3 +77,11 @@ Memory::ReturnBuffer( m_buffersReadyToUse[m_lastBufferToUse++] = Buffer; } +#endif //NETCX 2.6 only + +// for wil::make_unique_nothrow +void* +operator new(size_t s, std::nothrow_t const&) +{ + return operator new(s); +} \ No newline at end of file diff --git a/network/netadaptercx/netvadapterlibrary/code/memory.h b/network/netadaptercx/netvadapterlibrary/code/memory.h index b7ed654d..a07af6b8 100644 --- a/network/netadaptercx/netvadapterlibrary/code/memory.h +++ b/network/netadaptercx/netvadapterlibrary/code/memory.h @@ -1,8 +1,11 @@ // Copyright (C) Microsoft Corporation. All rights reserved. #pragma once -#include "adapter.h" #include +#define MAX_RX_BUFFER_SIZE 65535 + +#if ((NETADAPTER_VERSION_MAJOR == 2) && (NETADAPTER_VERSION_MINOR >= 6)) + static const size_t PREALLOCATED_BUFFERS_COUNT = 128; struct MemoryBuffer @@ -57,3 +60,4 @@ private: }; WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(Memory, GetMemoryFromHandle); +#endif //NETCX 2.6 only \ No newline at end of file diff --git a/network/netadaptercx/netvadapterlibrary/code/rtl/KNew.h b/network/netadaptercx/netvadapterlibrary/code/rtl/KNew.h deleted file mode 100644 index 28c832bd..00000000 --- a/network/netadaptercx/netvadapterlibrary/code/rtl/KNew.h +++ /dev/null @@ -1,203 +0,0 @@ -// Copyright (C) Microsoft Corporation. All rights reserved. - -#pragma once - -#include - -#if UMDF_DRIVER == 0 -#include -#endif - -#include -#include - -// -// KALLOCATOR KALLOCATOR_NONPAGED -// ---------------------------------------+--------------------+--------------------+ -// The object must be allocated at IRQL: | = PASSIVE_LEVEL | = PASSIVE_LEVEL | -// ---------------------------------------+--------------------+--------------------+ -// The object must be freed at IRQL: | = PASSIVE_LEVEL | = PASSIVE_LEVEL | -// ---------------------------------------+--------------------+--------------------+ -// Constructor & destructor run at: | = PASSIVE_LEVEL | = PASSIVE_LEVEL | -// ---------------------------------------+--------------------+--------------------+ -// Member functions default to: | PAGED code segment | .text code segment | -// ---------------------------------------+--------------------+--------------------+ -// Compiler-generated code goes to: | PAGED code segment | .text code segment | -// ---------------------------------------+--------------------+--------------------+ -// The memory is allocated from pool: | paged or nonpaged | paged or nonpaged | -// ---------------------------------------+--------------------+--------------------+ -// - -PAGED void *operator new(size_t s, std::nothrow_t const &, ULONG tag); -PAGED void operator delete(void *p, ULONG tag); -PAGED void *operator new[](size_t s, std::nothrow_t const &, ULONG tag); -PAGED void operator delete[](void *p, ULONG tag); -PAGEDX void __cdecl operator delete[](void *p); -void __cdecl operator delete(void *p); - -template -struct KRTL_CLASS KALLOCATION_TAG -{ - static const ULONG AllocationTag = TAG; - static const ULONG AllocationArena = ARENA; -}; - -template -struct KRTL_CLASS_DPC_ALLOC KALLOCATION_TAG_DPC_ALLOC -{ - static const ULONG AllocationTag = TAG; - static const ULONG AllocationArena = ARENA; -}; - -template -struct KRTL_CLASS KALLOCATOR : public KALLOCATION_TAG -{ - // Scalar new & delete - - PAGED void *operator new(size_t cb, std::nothrow_t const &) - { - PAGED_CODE(); - #pragma warning( suppress : 4996 28751 ) - return ExAllocatePoolWithTag(static_cast(ARENA), cb, TAG); - } - - PAGED void operator delete(void *p) - { - PAGED_CODE(); - - if (p != nullptr) - { - ExFreePoolWithTag(p, TAG); - } - } - - // Scalar new with bonus bytes - - PAGED void *operator new(size_t cb, std::nothrow_t const &, size_t extraBytes) - { - PAGED_CODE(); - - auto size = cb + extraBytes; - - // Overflow check - if (size < cb) - return nullptr; - - #pragma warning( suppress : 4996 28751 ) - return ExAllocatePoolWithTag(static_cast(ARENA), size, TAG); - } - - // Array new & delete - - PAGED void *operator new[](size_t cb, std::nothrow_t const &) - { - PAGED_CODE(); - #pragma warning( suppress : 4996 28751 ) - return ExAllocatePoolWithTag(static_cast(ARENA), cb, TAG); - } - - PAGED void operator delete[](void *p) - { - PAGED_CODE(); - - if (p != nullptr) - { - ExFreePoolWithTag(p, TAG); - } - } - - // Placement new & delete - - PAGED void *operator new(size_t n, void * p) - { - PAGED_CODE(); - UNREFERENCED_PARAMETER((n)); - return p; - } - - PAGED void operator delete(void *p1, void *p2) - { - PAGED_CODE(); - UNREFERENCED_PARAMETER((p1, p2)); - } -}; - -template -struct KRTL_CLASS_DPC_ALLOC KALLOCATOR_NONPAGED : public KALLOCATION_TAG_DPC_ALLOC -{ - // Scalar new & delete - - NONPAGED void *operator new(size_t cb, std::nothrow_t const &) - { - #pragma warning( suppress : 4996 28751 ) - return ExAllocatePoolWithTag(static_cast(ARENA), cb, TAG); - } - - NONPAGED void operator delete(void *p) - { - if (p != nullptr) - { - ExFreePoolWithTag(p, TAG); - } - } - - // Scalar new with bonus bytes - - NONPAGED void *operator new(size_t cb, std::nothrow_t const &, size_t extraBytes) - { - auto size = cb + extraBytes; - - // Overflow check - if (size < cb) - return nullptr; - - #pragma warning( suppress : 4996 28751 ) - return ExAllocatePoolWithTag(static_cast(ARENA), size, TAG); - } - - // Array new & delete - - NONPAGED void *operator new[](size_t cb, std::nothrow_t const &) - { - #pragma warning( suppress : 4996 28751 ) - return ExAllocatePoolWithTag(static_cast(ARENA), cb, TAG); - } - - NONPAGED void operator delete[](void *p) - { - if (p != nullptr) - { - ExFreePoolWithTag(p, TAG); - } - } - - // Placement new & delete - - NONPAGED void *operator new(size_t n, void * p) - { - UNREFERENCED_PARAMETER((n)); - return p; - } - - NONPAGED void operator delete(void *p1, void *p2) - { - UNREFERENCED_PARAMETER((p1, p2)); - } -}; - -template -struct KRTL_CLASS PAGED_OBJECT : - public KALLOCATOR, - public NdisDebugBlock -{ - -}; - -template -struct KRTL_CLASS NONPAGED_OBJECT : - public KALLOCATOR, - public NdisDebugBlock -{ - -}; - diff --git a/network/netadaptercx/netvadapterlibrary/code/rtl/UmPool.h b/network/netadaptercx/netvadapterlibrary/code/rtl/UmPool.h deleted file mode 100644 index 45491006..00000000 --- a/network/netadaptercx/netvadapterlibrary/code/rtl/UmPool.h +++ /dev/null @@ -1,97 +0,0 @@ -// Copyright (C) Microsoft Corporation. All rights reserved. - -#pragma once - -#if UMDF_DRIVER == 0 -#include "pooltypes.h" -#endif - -#ifndef _KERNEL_MODE - -#if (NTDDI_VERSION >= NTDDI_WIN10_VB) && !defined(KRTL_USE_LEGACY_POOL_API) - -typedef _Enum_is_bitflag_ enum _EX_POOL_PRIORITY { - LowPoolPriority, - LowPoolPrioritySpecialPoolOverrun = 8, - LowPoolPrioritySpecialPoolUnderrun = 9, - NormalPoolPriority = 16, - NormalPoolPrioritySpecialPoolOverrun = 24, - NormalPoolPrioritySpecialPoolUnderrun = 25, - HighPoolPriority = 32, - HighPoolPrioritySpecialPoolOverrun = 40, - HighPoolPrioritySpecialPoolUnderrun = 41 -} EX_POOL_PRIORITY; - -typedef enum POOL_EXTENDED_PARAMETER_TYPE { - PoolExtendedParameterInvalidType = 0, - PoolExtendedParameterPriority, - PoolExtendedParameterMax -} POOL_EXTENDED_PARAMETER_TYPE, *PPOOL_EXTENDED_PARAMETER_TYPE; - -#define POOL_EXTENDED_PARAMETER_TYPE_BITS 8 -#define POOL_EXTENDED_PARAMETER_REQUIRED_FIELD_BITS 1 -#define POOL_EXTENDED_PARAMETER_RESERVED_BITS (64 - POOL_EXTENDED_PARAMETER_TYPE_BITS - POOL_EXTENDED_PARAMETER_REQUIRED_FIELD_BITS) - -#pragma warning(push) -#pragma warning(disable: 4201) // nameless struct/union -typedef struct DECLSPEC_ALIGN(8) POOL_EXTENDED_PARAMETER { - struct { - ULONG64 Type : POOL_EXTENDED_PARAMETER_TYPE_BITS; - ULONG64 Optional : POOL_EXTENDED_PARAMETER_REQUIRED_FIELD_BITS; - ULONG64 Reserved : POOL_EXTENDED_PARAMETER_RESERVED_BITS; - } DUMMYSTRUCTNAME; - - union { - ULONG64 Reserved2; - PVOID Reserved3; - EX_POOL_PRIORITY Priority; - } DUMMYUNIONNAME; -} POOL_EXTENDED_PARAMETER, *PPOOL_EXTENDED_PARAMETER; -#pragma warning(pop) - -typedef ULONG64 POOL_FLAGS; - -_Check_return_ -_Ret_maybenull_ -_Post_writable_byte_size_(NumberOfBytes) -PVOID -ExAllocatePool2 ( - _In_ POOL_FLAGS Flags, - _In_ SIZE_T NumberOfBytes, - _In_ ULONG Tag - ); - -_Check_return_ -_Ret_maybenull_ -_Post_writable_byte_size_(NumberOfBytes) -PVOID -ExAllocatePool3 ( - _In_ POOL_FLAGS Flags, - _In_ SIZE_T NumberOfBytes, - _In_ ULONG Tag, - _In_reads_opt_(ExtendedParameterCount) PPOOL_EXTENDED_PARAMETER ExtendedParameters, - _In_ ULONG ExtendedParametersCount - ); - -#endif // (NTDDI_VERSION >= NTDDI_WIN10_VB) && !defined(KRTL_USE_LEGACY_POOL_API) - -PVOID -ExAllocatePoolWithTag( - POOL_TYPE PoolType, - SIZE_T NumberOfBytes, - ULONG Tag - ); - -VOID -ExFreePoolWithTag( - _Pre_notnull_ __drv_freesMem(Mem) PVOID P, - _In_ ULONG Tag - ); - -VOID -ExFreePool( - _Pre_notnull_ __drv_freesMem(Mem) PVOID P - ); - -#endif // _KERNEL_MODE - diff --git a/network/netadaptercx/netvadapterlibrary/code/rtl/pooltypes.h b/network/netadaptercx/netvadapterlibrary/code/rtl/pooltypes.h deleted file mode 100644 index 8bee9a72..00000000 --- a/network/netadaptercx/netvadapterlibrary/code/rtl/pooltypes.h +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright (C) Microsoft Corporation. All rights reserved. - -#pragma once - -#ifndef _KERNEL_MODE - -#include - -// -// Pool Allocation routines (in pool.c) -// -typedef _Enum_is_bitflag_ enum _POOL_TYPE { - NonPagedPool, - NonPagedPoolExecute = NonPagedPool, - PagedPool, - NonPagedPoolMustSucceed = NonPagedPool + 2, - DontUseThisType, - NonPagedPoolCacheAligned = NonPagedPool + 4, - PagedPoolCacheAligned, - NonPagedPoolCacheAlignedMustS = NonPagedPool + 6, - MaxPoolType, - - // - // Define base types for NonPaged (versus Paged) pool, for use in cracking - // the underlying pool type. - // - - NonPagedPoolBase = 0, - NonPagedPoolBaseMustSucceed = NonPagedPoolBase + 2, - NonPagedPoolBaseCacheAligned = NonPagedPoolBase + 4, - NonPagedPoolBaseCacheAlignedMustS = NonPagedPoolBase + 6, - - // - // Note these per session types are carefully chosen so that the appropriate - // masking still applies as well as MaxPoolType above. - // - - NonPagedPoolSession = 32, - PagedPoolSession = NonPagedPoolSession + 1, - NonPagedPoolMustSucceedSession = PagedPoolSession + 1, - DontUseThisTypeSession = NonPagedPoolMustSucceedSession + 1, - NonPagedPoolCacheAlignedSession = DontUseThisTypeSession + 1, - PagedPoolCacheAlignedSession = NonPagedPoolCacheAlignedSession + 1, - NonPagedPoolCacheAlignedMustSSession = PagedPoolCacheAlignedSession + 1, - - NonPagedPoolNx = 512, - NonPagedPoolNxCacheAligned = NonPagedPoolNx + 4, - NonPagedPoolSessionNx = NonPagedPoolNx + 32, - -} POOL_TYPE; - -#endif // _KERNEL_MODE - diff --git a/network/netadaptercx/netvadapterlibrary/code/rxqueue.cpp b/network/netadaptercx/netvadapterlibrary/code/rxqueue.cpp index 61c12ca3..d0b87f9e 100644 --- a/network/netadaptercx/netvadapterlibrary/code/rxqueue.cpp +++ b/network/netadaptercx/netvadapterlibrary/code/rxqueue.cpp @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved #include "pch.hpp" -#include "adapter.h" +#include "netvadapter.h" #include "rxqueue.h" #include "memory.h" @@ -68,7 +68,7 @@ NetvRxQueue::NetvRxQueue( NetExtensionTypePacket); NetRxQueueGetExtension(m_handle, &extension, &RxXSumExtension); - +#if ((NETADAPTER_VERSION_MAJOR == 2) && (NETADAPTER_VERSION_MINOR >= 6)) if (Adapter.PreallocatedRxBuffers) { NET_EXTENSION_QUERY_INIT( @@ -87,7 +87,7 @@ NetvRxQueue::NetvRxQueue( NetRxQueueGetExtension(m_handle, &extension, &NetMemoryReturnContextExtensionIn); } - +#endif //NETCX 2.6 only EnlQueueHandle = EnlCreateQueue(Handle, RX); } @@ -150,7 +150,7 @@ NetvRxQueue::Advance( break; } } - +#if ((NETADAPTER_VERSION_MAJOR == 2) && (NETADAPTER_VERSION_MINOR >= 6)) if (m_adapter.PreallocatedRxBuffers) { NET_RING* dataBufferRing = GetNetMemoryReturnRing(); @@ -166,7 +166,7 @@ NetvRxQueue::Advance( dataBufferRing->BeginIndex = NetRingIncrementIndex(dataBufferRing, dataBufferRing->BeginIndex); } } - +#endif //NETCX 2.6 only NetFragmentIteratorSet(&fi); NetPacketIteratorSet(&pi); EnlRingDoorBell(EnlQueueHandle, fr->EndIndex); diff --git a/network/netadaptercx/netvadapterlibrary/code/txqueue.cpp b/network/netadaptercx/netvadapterlibrary/code/txqueue.cpp index 56424523..b67692b5 100644 --- a/network/netadaptercx/netvadapterlibrary/code/txqueue.cpp +++ b/network/netadaptercx/netvadapterlibrary/code/txqueue.cpp @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved #include "pch.hpp" -#include "adapter.h" +#include "netvadapter.h" #include "txqueue.h" NetvTxQueue::NetvTxQueue( diff --git a/network/netadaptercx/netvadapterlibrary/km/netvadapterlibrarykm.vcxproj b/network/netadaptercx/netvadapterlibrary/km/netvadapterlibrarykm.vcxproj index 5e0be8e5..e1d68f5c 100644 --- a/network/netadaptercx/netvadapterlibrary/km/netvadapterlibrarykm.vcxproj +++ b/network/netadaptercx/netvadapterlibrary/km/netvadapterlibrarykm.vcxproj @@ -38,7 +38,7 @@ 33 true 2 - 6 + 5 Windows10 @@ -51,7 +51,7 @@ 33 true 2 - 6 + 5 Windows10 @@ -64,7 +64,7 @@ 33 true 2 - 6 + 5 Windows10 @@ -77,7 +77,7 @@ 33 true 2 - 6 + 5 @@ -89,19 +89,19 @@ DbgengKernelDebugger - $(MSBuildProjectDirectory)\..\code\rtl;$(IncludePath) + $(MSBuildProjectDirectory)\..\Interface;$(MSBuildProjectDirectory)\..\code\rtl;$(IncludePath) DbgengKernelDebugger - $(MSBuildProjectDirectory)\..\code\rtl;$(IncludePath) + $(MSBuildProjectDirectory)\..\Interface;$(MSBuildProjectDirectory)\..\code\rtl;$(IncludePath) DbgengKernelDebugger - $(MSBuildProjectDirectory)\..\code\rtl;$(IncludePath) + $(MSBuildProjectDirectory)\..\Interface;$(MSBuildProjectDirectory)\..\code\rtl;$(IncludePath) DbgengKernelDebugger - $(MSBuildProjectDirectory)\..\code\rtl;$(IncludePath) + $(MSBuildProjectDirectory)\..\Interface;$(MSBuildProjectDirectory)\..\code\rtl;$(IncludePath) @@ -159,7 +159,6 @@ - @@ -169,6 +168,8 @@ + + diff --git a/network/netadaptercx/netvadapterlibrary/um/netvadapterlibraryum.vcxproj b/network/netadaptercx/netvadapterlibrary/um/netvadapterlibraryum.vcxproj index 99a6e5e9..ce418965 100644 --- a/network/netadaptercx/netvadapterlibrary/um/netvadapterlibraryum.vcxproj +++ b/network/netadaptercx/netvadapterlibrary/um/netvadapterlibraryum.vcxproj @@ -36,10 +36,10 @@ KMDF Universal 2 - 33 + 35 true 2 - 6 + 5 Windows10 @@ -49,10 +49,10 @@ KMDF Universal 2 - 33 + 35 true 2 - 6 + 5 Windows10 @@ -62,10 +62,10 @@ KMDF Universal 2 - 33 + 35 true 2 - 6 + 5 Windows10 @@ -75,10 +75,10 @@ KMDF Universal 2 - 33 + 35 true 2 - 6 + 5 @@ -90,19 +90,19 @@ DbgengKernelDebugger - $(MSBuildProjectDirectory)\..\code\rtl;$(IncludePath) + $(MSBuildProjectDirectory)\..\Interface;$(MSBuildProjectDirectory)\..\code\rtl;$(IncludePath) DbgengKernelDebugger - $(MSBuildProjectDirectory)\..\code\rtl;$(IncludePath) + $(MSBuildProjectDirectory)\..\Interface;$(MSBuildProjectDirectory)\..\code\rtl;$(IncludePath) DbgengKernelDebugger - $(MSBuildProjectDirectory)\..\code\rtl;$(IncludePath) + $(MSBuildProjectDirectory)\..\Interface;$(MSBuildProjectDirectory)\..\code\rtl;$(IncludePath) DbgengKernelDebugger - $(MSBuildProjectDirectory)\..\code\rtl;$(IncludePath) + $(MSBuildProjectDirectory)\..\Interface;$(MSBuildProjectDirectory)\..\code\rtl;$(IncludePath) @@ -160,7 +160,6 @@ - @@ -170,6 +169,7 @@ + diff --git a/network/wlan/WIFICX/drivercode/adapter.cpp b/network/wlan/WIFICX/drivercode/adapter.cpp index 958f69ea..b2f736b9 100644 --- a/network/wlan/WIFICX/drivercode/adapter.cpp +++ b/network/wlan/WIFICX/drivercode/adapter.cpp @@ -6,45 +6,93 @@ #include "adapter.h" #include "adapter.tmh" -_Use_decl_annotations_ -NTSTATUS WifiIhvInitAdapterContext(_In_ WDFDEVICE Device, _In_ NETADAPTER NetAdapter) +extern UCHAR NetvMacAddressBase[MAC_ADDR_LEN]; + +NetvAdapter* NetvAdapterGetContextFromWDFObject(NETADAPTER netAdapter) +{ + WifiNetvAdapter* wifiNetvAdapter = WifiNetvAdapterGetContext(netAdapter); + NetvAdapter* netvAdapter{ wifiNetvAdapter }; + return netvAdapter; +} + +WifiNetvAdapter::WifiNetvAdapter(NETADAPTER Handle, WDFDEVICE Device) : NetvAdapter(Handle, Device) +{ +} + +NTSTATUS WifiNetvAdapter::Initialize() { - PWIFI_IHV_DEVICE_CONTEXT deviceContext = WifiGetIhvDeviceContext(Device); - PWIFI_IHV_NETADAPTER_CONTEXT netAdapterContext = WifiGetIhvNetAdapterContext(NetAdapter); + if (WifiGetIhvDeviceContext(m_device)->netAdapters[WifiAdapterGetPortId(m_handle)] != WDF_NO_HANDLE) + { + return STATUS_SUCCESS; + } + return NetvAdapter::Initialize(); +} + +// the Xfilter.h should be included in the share(currently in km only) +#ifndef _KERNEL_MODE +// +// This macro is used to copy from one network address to +// another. +// +#define ETH_COPY_NETWORK_ADDRESS(_D, _S) \ +{ \ + *((ULONG UNALIGNED *)(_D)) = *((ULONG UNALIGNED *)(_S)); \ + *((USHORT UNALIGNED *)((UCHAR *)(_D)+4)) = *((USHORT UNALIGNED *)((UCHAR *)(_S)+4)); \ +} +// +// ZZZ This is a little-endian specific check. +// +#define ETH_IS_MULTICAST(Address) \ + (BOOLEAN)(((PUCHAR)(Address))[0] & ((UCHAR)0x01)) + +// +// Check whether an address is broadcast. +// +#define ETH_IS_BROADCAST(Address) \ + ((((PUCHAR)(Address))[0] == ((UCHAR)0xff)) && (((PUCHAR)(Address))[1] == ((UCHAR)0xff)) && (((PUCHAR)(Address))[2] == ((UCHAR)0xff)) && (((PUCHAR)(Address))[3] == ((UCHAR)0xff)) && (((PUCHAR)(Address))[4] == ((UCHAR)0xff)) && (((PUCHAR)(Address))[5] == ((UCHAR)0xff))) + +#endif // _KERNEL_MODE + +NTSTATUS WifiNetvAdapter::NetvAdapterReadAddress() +{ + UCHAR MACLastByteFinial = (UCHAR)MACLastByte; + if (MACLastByteFinial == 0) + { + MACLastByteFinial++; + } + + PermanentAddress.Length = MAC_ADDR_LEN; - if (deviceContext->primaryStaAdapter == WDF_NO_HANDLE) + ETH_COPY_NETWORK_ADDRESS(PermanentAddress.Address, NetvMacAddressBase); + PermanentAddress.Address[MAC_ADDR_LEN - 1] = MACLastByteFinial; + if (ETH_IS_MULTICAST(PermanentAddress.Address) || ETH_IS_BROADCAST(PermanentAddress.Address)) { - deviceContext->primaryStaAdapter = NetAdapter; + WFCError("%!FUNC!: Failed with %!STATUS!", STATUS_INVALID_ADDRESS); + return STATUS_INVALID_ADDRESS; } - netAdapterContext->WifiDeviceContext = deviceContext; + RtlCopyMemory(&CurrentAddress, &PermanentAddress, sizeof(PermanentAddress)); + + EnlIndex = (MACLastByteFinial - 1) >> 1; + EnlPortIndex = (MACLastByteFinial - 1) & 1; + EnlIndexValid = TRUE; return STATUS_SUCCESS; } -_Use_decl_annotations_ -NTSTATUS WifiIhvAdapterStart(NETADAPTER netAdapter) +NTSTATUS WifiNetvAdapter::AdapterStart() { TraceEntry(); - static WDI_MAC_ADDRESS STAAddress = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05}; - NET_ADAPTER_LINK_LAYER_ADDRESS permanentLinkLayerAddress; - NET_ADAPTER_LINK_LAYER_ADDRESS_INIT(&permanentLinkLayerAddress, sizeof(WDI_MAC_ADDRESS), STAAddress.Address); - NetAdapterSetCurrentLinkLayerAddress(netAdapter, &permanentLinkLayerAddress); - NetAdapterSetPermanentLinkLayerAddress(netAdapter, &permanentLinkLayerAddress); - - // Sample Phase 1 has no datapath support, so setting those values to the default one. - NET_ADAPTER_TX_CAPABILITIES txCaps; - NET_ADAPTER_RX_CAPABILITIES rxCaps; - NET_ADAPTER_LINK_LAYER_CAPABILITIES linkLayerCaps; - - NET_ADAPTER_TX_CAPABILITIES_INIT(&txCaps, 1); - NET_ADAPTER_RX_CAPABILITIES_INIT_SYSTEM_MANAGED(&rxCaps, 1514, 1); - NET_ADAPTER_LINK_LAYER_CAPABILITIES_INIT(&linkLayerCaps, 0, 0); - - NetAdapterSetLinkLayerMtuSize(netAdapter, 1500); - NetAdapterSetLinkLayerCapabilities(netAdapter, &linkLayerCaps); - NetAdapterSetDataPathCapabilities(netAdapter, &txCaps, &rxCaps); + NTSTATUS status = STATUS_SUCCESS; + + NET_ADAPTER_WAKE_MEDIA_CHANGE_CAPABILITIES wakeMediaChangeCapabilities; + NET_ADAPTER_WAKE_MEDIA_CHANGE_CAPABILITIES_INIT(&wakeMediaChangeCapabilities); + + wakeMediaChangeCapabilities.MediaConnect = TRUE; + wakeMediaChangeCapabilities.MediaDisconnect = TRUE; + + NetAdapterWakeSetMediaChangeCapabilities(m_handle, &wakeMediaChangeCapabilities); WIFI_ADAPTER_WAKE_CAPABILITIES wakeCap{}; WIFI_ADAPTER_WAKE_CAPABILITIES_INIT(&wakeCap); @@ -52,12 +100,39 @@ NTSTATUS WifiIhvAdapterStart(NETADAPTER netAdapter) { wakeCap.ClientDriverDiagnostic = true; } - WifiAdapterSetWakeCapabilities(netAdapter, &wakeCap); + WifiAdapterSetWakeCapabilities(m_handle, &wakeCap); - NTSTATUS status = NetAdapterStart(netAdapter); - ASSERT(STATUS_SUCCESS == status); + status = NetvAdapter::ConfigureDataCapabilities(); + if (!NT_SUCCESS(status)) + { + WFCError("%!FUNC!: NetvAdapter::ConfigureDataCapabilities failed with %!STATUS!", status); + return status; + } + + status = NetAdapterStart(m_handle); + if (!NT_SUCCESS(status)) + { + WFCError("%!FUNC!: NetAdapterStart failed with %!STATUS!", status); + return status; + } + ASSERT(STATUS_SUCCESS == status); TraceExit(status); return status; } + +NTSTATUS WifiNetvAdapter::CreateRxQueue(NETRXQUEUE_INIT* NetRxQueueInit) +{ + return NetvAdapter::CreateRxQueue(NetRxQueueInit); +} + +NTSTATUS WifiNetvAdapter::CreateTxQueue(NETTXQUEUE_INIT* NetTxQueueInit) +{ + return NetvAdapter::CreateTxQueue(NetTxQueueInit); +} + +void WifiNetvAdapter::Destroy(void) +{ + return NetvAdapter::Destroy(); +} \ No newline at end of file diff --git a/network/wlan/WIFICX/drivercode/adapter.h b/network/wlan/WIFICX/drivercode/adapter.h index eb39dee1..ecc597e8 100644 --- a/network/wlan/WIFICX/drivercode/adapter.h +++ b/network/wlan/WIFICX/drivercode/adapter.h @@ -2,6 +2,7 @@ #pragma once #include "device.h" +#include "netvadapter.h" // packet and header sizes #define WIFI_MAX_PACKET_SIZE (1514) @@ -9,9 +10,6 @@ // maximum link speed for send and recv in bps #define WIFI_MEDIA_MAX_SPEED 1'000'000'000 -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 typedef struct _WIFI_IHV_NETADAPTER_CONTEXT @@ -21,3 +19,31 @@ typedef struct _WIFI_IHV_NETADAPTER_CONTEXT } WIFI_IHV_NETADAPTER_CONTEXT, * PWIFI_IHV_NETADAPTER_CONTEXT; WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(WIFI_IHV_NETADAPTER_CONTEXT, WifiGetIhvNetAdapterContext); + +class WifiNetvAdapter : public NetvAdapter +{ +public: + WifiNetvAdapter(NETADAPTER Handle, WDFDEVICE Device); + + NTSTATUS + Initialize(); + + NTSTATUS + AdapterStart(); + + NTSTATUS + CreateRxQueue(NETRXQUEUE_INIT* NetRxQueueInit); + + NTSTATUS + CreateTxQueue(NETTXQUEUE_INIT* NetTxQueueInit); + + void Destroy(void); + + bool CanReportWifiWakeSourceTypeClientDriverDiagnostic; + +private: + NTSTATUS + NetvAdapterReadAddress() override; +}; + +WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(WifiNetvAdapter, WifiNetvAdapterGetContext); \ No newline at end of file diff --git a/network/wlan/WIFICX/drivercode/device.cpp b/network/wlan/WIFICX/drivercode/device.cpp index 0fc17ea4..9404b161 100644 --- a/network/wlan/WIFICX/drivercode/device.cpp +++ b/network/wlan/WIFICX/drivercode/device.cpp @@ -33,33 +33,67 @@ NTSTATUS EvtDeviceReleaseHardware(WDFDEVICE device, WDFCMRESLIST resourcesTransl _Use_decl_annotations_ NTSTATUS EvtWifiDeviceCreateAdapter(WDFDEVICE Device, NETADAPTER_INIT* AdapterInit) { + if (WifiAdapterInitGetType(AdapterInit) != WIFI_ADAPTER_EXTENSIBLE_STATION) + { + WFCError("%!FUNC!: Unsupported adapter type = 0x%x != 0x%x", WifiAdapterInitGetType(AdapterInit), WIFI_ADAPTER_EXTENSIBLE_STATION); + return STATUS_NOT_SUPPORTED; + } - //NET_ADAPTER_DATAPATH_CALLBACKS datapathCallbacks; - //NET_ADAPTER_DATAPATH_CALLBACKS_INIT(&datapathCallbacks, EvtAdapterCreateTxQueue, EvtAdapterCreateRxQueue); + NET_ADAPTER_DATAPATH_CALLBACKS datapathCallbacks; + NET_ADAPTER_DATAPATH_CALLBACKS_INIT(&datapathCallbacks, EvtAdapterCreateTxQueue, EvtAdapterCreateRxQueue); - //NetAdapterInitSetDatapathCallbacks(AdapterInit, &datapathCallbacks); + NetAdapterInitSetDatapathCallbacks(AdapterInit, &datapathCallbacks); WDF_OBJECT_ATTRIBUTES adapterAttributes; WDF_OBJECT_ATTRIBUTES_INIT(&adapterAttributes); - WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&adapterAttributes, WIFI_IHV_NETADAPTER_CONTEXT); + WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&adapterAttributes, WifiNetvAdapter); adapterAttributes.EvtCleanupCallback = EvtAdapterCleanup; - NETADAPTER netAdapter{}; - WX_RETURN_NTSTATUS_IF_NOT_NT_SUCCESS_MSG( - NetAdapterCreate(AdapterInit, &adapterAttributes, &netAdapter), "Failed to create NetAdapter"); - - WX_RETURN_NTSTATUS_IF_NOT_NT_SUCCESS_MSG( - WifiAdapterInitialize(netAdapter), "Failed to initialize WifiAdapter"); - - 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"); + NETADAPTER netAdapter; + NTSTATUS ntStatus = NetAdapterCreate(AdapterInit, &adapterAttributes, &netAdapter); + if (!NT_SUCCESS(ntStatus)) + { + WFCError("%!FUNC!: NetAdapterCreate failed, status=0x%x", ntStatus); + return ntStatus; + } + + ntStatus = WifiAdapterInitialize(netAdapter); + ASSERT(NT_SUCCESS(ntStatus)); + if (!NT_SUCCESS(ntStatus)) + { + WFCError("%!FUNC!: WifiAdapterInitialize failed with %!STATUS!", ntStatus); + return ntStatus; + } + auto wifiNetvAdapter = new (reinterpret_cast(WifiNetvAdapterGetContext(netAdapter))) WifiNetvAdapter(netAdapter, Device); + ntStatus = wifiNetvAdapter->Initialize(); + if (!NT_SUCCESS(ntStatus)) + { + WFCError("%!FUNC!: WifiNetvAdapter::Initialize failed with %!STATUS!", ntStatus); + return ntStatus; + } + + ntStatus = wifiNetvAdapter->AdapterStart(); + ASSERT(NT_SUCCESS(ntStatus)); + if (!NT_SUCCESS(ntStatus)) + { + WFCError("%!FUNC!: WifiNetvAdapter::AdapterStart failed with %!STATUS!", ntStatus); + return ntStatus; + } + + WFCInfo("%!FUNC!: Success!"); + return ntStatus; +} - return STATUS_SUCCESS; +_Use_decl_annotations_ +void EvtAdapterCleanup(_In_ WDFOBJECT NetAdapter) +{ + TraceEntry(); + auto wifiNetvAdapter = WifiNetvAdapterGetContext(NetAdapter); + wifiNetvAdapter->Destroy(); + TraceExit(STATUS_SUCCESS); } + _Use_decl_annotations_ NTSTATUS EvtWifiDeviceCreateWifiDirectDevice(WDFDEVICE, WIFIDIRECT_DEVICE_INIT*) { @@ -69,10 +103,19 @@ NTSTATUS EvtWifiDeviceCreateWifiDirectDevice(WDFDEVICE, WIFIDIRECT_DEVICE_INIT*) return status; } + _Use_decl_annotations_ -void EvtAdapterCleanup(_In_ WDFOBJECT NetAdapter) +NTSTATUS +EvtAdapterCreateTxQueue(NETADAPTER Adapter, NETTXQUEUE_INIT* Init) { - UNREFERENCED_PARAMETER(NetAdapter); TraceEntry(); - TraceExit(STATUS_SUCCESS); -} \ No newline at end of file + return WifiNetvAdapterGetContext(Adapter)->CreateTxQueue(Init); +} + +_Use_decl_annotations_ +NTSTATUS +EvtAdapterCreateRxQueue(NETADAPTER Adapter, NETRXQUEUE_INIT* Init) +{ + TraceEntry(); + return WifiNetvAdapterGetContext(Adapter)->CreateRxQueue(Init); +} diff --git a/network/wlan/WIFICX/drivercode/device.h b/network/wlan/WIFICX/drivercode/device.h index bf70ba7b..c0dfac3c 100644 --- a/network/wlan/WIFICX/drivercode/device.h +++ b/network/wlan/WIFICX/drivercode/device.h @@ -9,6 +9,9 @@ EVT_WIFI_DEVICE_CREATE_WIFIDIRECTDEVICE EvtWifiDeviceCreateWifiDirectDevice; EVT_WIFI_DEVICE_SEND_COMMAND EvtWifiDeviceSendCommand; EVT_WDF_OBJECT_CONTEXT_CLEANUP EvtAdapterCleanup; +EVT_NET_ADAPTER_CREATE_TXQUEUE EvtAdapterCreateTxQueue; +EVT_NET_ADAPTER_CREATE_RXQUEUE EvtAdapterCreateRxQueue; + typedef struct _WIFI_IHV_DEVICE_CONTEXT { // @@ -19,7 +22,7 @@ typedef struct _WIFI_IHV_DEVICE_CONTEXT void* WdfTriageInfoPtr; WDFDEVICE WdfDevice; TLV_CONTEXT TlvContext; - NETADAPTER primaryStaAdapter; + NETADAPTER netAdapters[5]{}; } WIFI_IHV_DEVICE_CONTEXT, * PWIFI_IHV_DEVICE_CONTEXT; WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(WIFI_IHV_DEVICE_CONTEXT, WifiGetIhvDeviceContext); diff --git a/network/wlan/WIFICX/drivercode/memorymanagement.cpp b/network/wlan/WIFICX/drivercode/memorymanagement.cpp index de231d8c..088bad88 100644 --- a/network/wlan/WIFICX/drivercode/memorymanagement.cpp +++ b/network/wlan/WIFICX/drivercode/memorymanagement.cpp @@ -114,12 +114,12 @@ _Ret_writes_bytes_maybenull_(_Size) void* PlacementNewHelper(size_t _Size, PCPLA return nullptr; } -void* __cdecl operator new(size_t Size) +void* __cdecl operator new(size_t Size) noexcept { return AllocateWdfMemoryBuffer(Size, _ReturnAddress()); } -__forceinline void* __cdecl operator new(size_t _Size, ULONG_PTR AllocationContext) throw() +__forceinline void* __cdecl operator new(size_t _Size, ULONG_PTR AllocationContext) noexcept // for WIFICX TLV { if (AllocationContext != 0) { @@ -128,22 +128,22 @@ __forceinline void* __cdecl operator new(size_t _Size, ULONG_PTR AllocationConte return AllocateWdfMemoryBuffer(_Size, _ReturnAddress()); } -void __cdecl operator delete(void* pData) +void __cdecl operator delete(void* pData) noexcept { FreeWdfMemoryBuffer(pData); } -void __cdecl operator delete[](void* pData) +void __cdecl operator delete[](void* pData) noexcept { FreeWdfMemoryBuffer(pData); } -void __cdecl operator delete(void* pData, ULONG_PTR) +void __cdecl operator delete(void* pData, ULONG_PTR) noexcept // For WIFICX TLV { FreeWdfMemoryBuffer(pData); } -void __cdecl operator delete[](void* pData, ULONG_PTR) +void __cdecl operator delete[](void* pData, ULONG_PTR) noexcept // For WIFICX TLV { FreeWdfMemoryBuffer(pData); -} +} \ No newline at end of file diff --git a/network/wlan/WIFICX/drivercode/precomp.h b/network/wlan/WIFICX/drivercode/precomp.h index f6bc3aad..1b0f808e 100644 --- a/network/wlan/WIFICX/drivercode/precomp.h +++ b/network/wlan/WIFICX/drivercode/precomp.h @@ -26,3 +26,8 @@ // WPP Tracing Headers #include "trace.h" + +// Minimal placement-new to match operator new(size_t, void*) +// TLV generator/parser memory interface has the ULONG_PTR version +inline void* operator new(size_t, void* p) noexcept { return p; } +inline void operator delete(void*, void*) noexcept { /* no-op */ } diff --git a/network/wlan/WIFICX/drivercode/wifihal.cpp b/network/wlan/WIFICX/drivercode/wifihal.cpp index 1a5914a6..5283474c 100644 --- a/network/wlan/WIFICX/drivercode/wifihal.cpp +++ b/network/wlan/WIFICX/drivercode/wifihal.cpp @@ -57,13 +57,13 @@ NTSTATUS WifiHAL::WifiIhvIsDeviceReadyForRequest() { NTSTATUS status = ((m_Device != WDF_NO_HANDLE) // Make sure device is initialized (since this is hardware abstraction layer, IHV can replace with firmware state) - && (WifiGetIhvDeviceContext(m_Device)->primaryStaAdapter != WDF_NO_HANDLE) ? STATUS_SUCCESS : STATUS_DEVICE_NOT_READY);// In WIFICX, the logic sits on top of primary STA adapter, make sure it is initialized + && (WifiGetIhvDeviceContext(m_Device)->netAdapters[0] != WDF_NO_HANDLE) ? STATUS_SUCCESS : STATUS_DEVICE_NOT_READY);// In WIFICX, the logic sits on top of primary STA adapter, make sure it is initialized if(NT_SUCCESS(status) == FALSE) { WFCError( "Device not ready for request. Device=%p, primaryStaAdapter=%p", m_Device, - (m_Device != WDF_NO_HANDLE) ? WifiGetIhvDeviceContext(m_Device)->primaryStaAdapter : WDF_NO_HANDLE); + (m_Device != WDF_NO_HANDLE) ? WifiGetIhvDeviceContext(m_Device)->netAdapters[0] : WDF_NO_HANDLE); } return status; } diff --git a/network/wlan/WIFICX/km/wificxsampleclientkm.vcxproj b/network/wlan/WIFICX/km/wificxsampleclientkm.vcxproj index 16842485..0bd8b963 100644 --- a/network/wlan/WIFICX/km/wificxsampleclientkm.vcxproj +++ b/network/wlan/WIFICX/km/wificxsampleclientkm.vcxproj @@ -40,7 +40,7 @@ 33 true 2 - 4 + 5 4 true 1 @@ -59,7 +59,7 @@ 33 true 2 - 4 + 5 4 true 1 @@ -78,7 +78,7 @@ 33 true 2 - 4 + 5 4 true 1 @@ -97,7 +97,7 @@ 33 true 2 - 4 + 5 4 true 1 @@ -138,10 +138,11 @@ true - $(DDK_INC_PATH)wlan\2.0;%(AdditionalIncludeDirectories) + ..\..\..\netadaptercx\netvadapterlibrary\Interface;$(DDK_INC_PATH)wlan\2.0;%(AdditionalIncludeDirectories) true ..\drivercode\trace.h false + _HAS_EXCEPTIONS=0;%(PreprocessorDefinitions) $(DDK_LIB_PATH)wlan\2.0\WificxTLVGenParse.lib;%(AdditionalDependencies) @@ -155,11 +156,12 @@ sha256 - $(DDK_INC_PATH)wlan\2.0;%(AdditionalIncludeDirectories) + ..\..\..\netadaptercx\netvadapterlibrary\Interface;$(DDK_INC_PATH)wlan\2.0;%(AdditionalIncludeDirectories) true true ..\drivercode\trace.h false + _HAS_EXCEPTIONS=0;%(PreprocessorDefinitions) $(DDK_LIB_PATH)wlan\2.0\WificxTLVGenParse.lib;%(AdditionalDependencies) @@ -173,11 +175,12 @@ sha256 - $(DDK_INC_PATH)wlan\2.0;%(AdditionalIncludeDirectories) + ..\..\..\netadaptercx\netvadapterlibrary\Interface;$(DDK_INC_PATH)wlan\2.0;%(AdditionalIncludeDirectories) true true ..\drivercode\trace.h false + _HAS_EXCEPTIONS=0;%(PreprocessorDefinitions) $(DDK_LIB_PATH)wlan\2.0\WificxTLVGenParse.lib;%(AdditionalDependencies) @@ -191,11 +194,12 @@ sha256 - $(DDK_INC_PATH)wlan\2.0;%(AdditionalIncludeDirectories) + ..\..\..\netadaptercx\netvadapterlibrary\Interface;$(DDK_INC_PATH)wlan\2.0;%(AdditionalIncludeDirectories) true true ..\drivercode\trace.h false + _HAS_EXCEPTIONS=0;%(PreprocessorDefinitions) $(DDK_LIB_PATH)wlan\2.0\WificxTLVGenParse.lib;%(AdditionalDependencies) @@ -232,6 +236,11 @@ + + + {e2a65efd-25cc-4af0-b180-0cd56ee277a9} + + diff --git a/network/wlan/WIFICX/um/wificxsampleclientum.vcxproj b/network/wlan/WIFICX/um/wificxsampleclientum.vcxproj index 85e826d5..a0917a35 100644 --- a/network/wlan/WIFICX/um/wificxsampleclientum.vcxproj +++ b/network/wlan/WIFICX/um/wificxsampleclientum.vcxproj @@ -59,7 +59,7 @@ 35 true 2 - 4 + 5 true 1 2 @@ -72,7 +72,7 @@ 35 true 2 - 4 + 5 true 1 2 @@ -85,7 +85,7 @@ 35 true 2 - 4 + 5 true 1 2 @@ -98,7 +98,7 @@ 35 true 2 - 4 + 5 true 1 2 @@ -132,7 +132,7 @@ sha256 - $(WDK_UM_INC_PATH)wlan\2.0;$(KIT_SHARED_INC_PATH_WDK);%(AdditionalIncludeDirectories) + ..\..\..\netadaptercx\netvadapterlibrary\Interface;$(WDK_UM_INC_PATH)wlan\2.0;$(KIT_SHARED_INC_PATH_WDK);%(AdditionalIncludeDirectories) WIFICX_TEMPORARY_REMOVED_FOR_USERMODE;%(PreprocessorDefinitions) true ..\drivercode\trace.h @@ -149,7 +149,7 @@ sha256 - $(WDK_UM_INC_PATH)wlan\2.0;$(KIT_SHARED_INC_PATH_WDK);%(AdditionalIncludeDirectories) + ..\..\..\netadaptercx\netvadapterlibrary\Interface;$(WDK_UM_INC_PATH)wlan\2.0;$(KIT_SHARED_INC_PATH_WDK);%(AdditionalIncludeDirectories) WIFICX_TEMPORARY_REMOVED_FOR_USERMODE;%(PreprocessorDefinitions) true ..\drivercode\trace.h @@ -166,7 +166,7 @@ sha256 - $(WDK_UM_INC_PATH)wlan\2.0;$(KIT_SHARED_INC_PATH_WDK);%(AdditionalIncludeDirectories) + ..\..\..\netadaptercx\netvadapterlibrary\Interface;$(WDK_UM_INC_PATH)wlan\2.0;$(KIT_SHARED_INC_PATH_WDK);%(AdditionalIncludeDirectories) WIFICX_TEMPORARY_REMOVED_FOR_USERMODE;%(PreprocessorDefinitions) true ..\drivercode\trace.h @@ -183,7 +183,7 @@ sha256 - $(WDK_UM_INC_PATH)wlan\2.0;$(KIT_SHARED_INC_PATH_WDK);%(AdditionalIncludeDirectories) + ..\..\..\netadaptercx\netvadapterlibrary\Interface;$(WDK_UM_INC_PATH)wlan\2.0;$(KIT_SHARED_INC_PATH_WDK);%(AdditionalIncludeDirectories) WIFICX_TEMPORARY_REMOVED_FOR_USERMODE;%(PreprocessorDefinitions) true ..\drivercode\trace.h @@ -220,6 +220,11 @@ + + + {612f33ad-430c-4fe7-8000-35e15a5eb757} + + diff --git a/network/wlan/WIFICX/wificxsampleclient.sln b/network/wlan/WIFICX/wificxsampleclient.sln index 0975a4da..d484d08c 100644 --- a/network/wlan/WIFICX/wificxsampleclient.sln +++ b/network/wlan/WIFICX/wificxsampleclient.sln @@ -3,8 +3,18 @@ Microsoft Visual Studio Solution File, Format Version 12.00 VisualStudioVersion = 17.7.34221.43 MinimumVisualStudioVersion = 12.0 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "wificxsampleclientkm", "km\wificxsampleclientkm.vcxproj", "{272D3E7B-C7BA-66D1-E05D-B9723A6F0777}" + ProjectSection(ProjectDependencies) = postProject + {E2A65EFD-25CC-4AF0-B180-0CD56EE277A9} = {E2A65EFD-25CC-4AF0-B180-0CD56EE277A9} + EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "wificxsampleclientum", "um\wificxsampleclientum.vcxproj", "{C804D7D0-80D8-1409-44DA-91EF3260D07F}" + ProjectSection(ProjectDependencies) = postProject + {612F33AD-430C-4FE7-8000-35E15A5EB757} = {612F33AD-430C-4FE7-8000-35E15A5EB757} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "netvadapterlibrarykm", "..\..\netadaptercx\netvadapterlibrary\km\netvadapterlibrarykm.vcxproj", "{E2A65EFD-25CC-4AF0-B180-0CD56EE277A9}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "netvadapterlibraryum", "..\..\netadaptercx\netvadapterlibrary\um\netvadapterlibraryum.vcxproj", "{612F33AD-430C-4FE7-8000-35E15A5EB757}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -38,6 +48,30 @@ Global {C804D7D0-80D8-1409-44DA-91EF3260D07F}.Release|x64.ActiveCfg = Release|x64 {C804D7D0-80D8-1409-44DA-91EF3260D07F}.Release|x64.Build.0 = Release|x64 {C804D7D0-80D8-1409-44DA-91EF3260D07F}.Release|x64.Deploy.0 = Release|x64 + {E2A65EFD-25CC-4AF0-B180-0CD56EE277A9}.Debug|ARM64.ActiveCfg = Debug|ARM64 + {E2A65EFD-25CC-4AF0-B180-0CD56EE277A9}.Debug|ARM64.Build.0 = Debug|ARM64 + {E2A65EFD-25CC-4AF0-B180-0CD56EE277A9}.Debug|ARM64.Deploy.0 = Debug|ARM64 + {E2A65EFD-25CC-4AF0-B180-0CD56EE277A9}.Debug|x64.ActiveCfg = Debug|x64 + {E2A65EFD-25CC-4AF0-B180-0CD56EE277A9}.Debug|x64.Build.0 = Debug|x64 + {E2A65EFD-25CC-4AF0-B180-0CD56EE277A9}.Debug|x64.Deploy.0 = Debug|x64 + {E2A65EFD-25CC-4AF0-B180-0CD56EE277A9}.Release|ARM64.ActiveCfg = Release|ARM64 + {E2A65EFD-25CC-4AF0-B180-0CD56EE277A9}.Release|ARM64.Build.0 = Release|ARM64 + {E2A65EFD-25CC-4AF0-B180-0CD56EE277A9}.Release|ARM64.Deploy.0 = Release|ARM64 + {E2A65EFD-25CC-4AF0-B180-0CD56EE277A9}.Release|x64.ActiveCfg = Release|x64 + {E2A65EFD-25CC-4AF0-B180-0CD56EE277A9}.Release|x64.Build.0 = Release|x64 + {E2A65EFD-25CC-4AF0-B180-0CD56EE277A9}.Release|x64.Deploy.0 = Release|x64 + {612F33AD-430C-4FE7-8000-35E15A5EB757}.Debug|ARM64.ActiveCfg = Debug|ARM64 + {612F33AD-430C-4FE7-8000-35E15A5EB757}.Debug|ARM64.Build.0 = Debug|ARM64 + {612F33AD-430C-4FE7-8000-35E15A5EB757}.Debug|ARM64.Deploy.0 = Debug|ARM64 + {612F33AD-430C-4FE7-8000-35E15A5EB757}.Debug|x64.ActiveCfg = Debug|x64 + {612F33AD-430C-4FE7-8000-35E15A5EB757}.Debug|x64.Build.0 = Debug|x64 + {612F33AD-430C-4FE7-8000-35E15A5EB757}.Debug|x64.Deploy.0 = Debug|x64 + {612F33AD-430C-4FE7-8000-35E15A5EB757}.Release|ARM64.ActiveCfg = Release|ARM64 + {612F33AD-430C-4FE7-8000-35E15A5EB757}.Release|ARM64.Build.0 = Release|ARM64 + {612F33AD-430C-4FE7-8000-35E15A5EB757}.Release|ARM64.Deploy.0 = Release|ARM64 + {612F33AD-430C-4FE7-8000-35E15A5EB757}.Release|x64.ActiveCfg = Release|x64 + {612F33AD-430C-4FE7-8000-35E15A5EB757}.Release|x64.Build.0 = Release|x64 + {612F33AD-430C-4FE7-8000-35E15A5EB757}.Release|x64.Deploy.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE -- cgit v1.3.1 From eb4a87e545f33af410b15c6c86100c165c0eda2a Mon Sep 17 00:00:00 2001 From: "Yang You (UU)" Date: Mon, 8 Dec 2025 15:23:39 -0800 Subject: Remove the TX demx support as ENL limiation. --- .../netvadapterlibrary/Interface/netvadapter.h | 3 ++ .../netadaptercx/netvadapterlibrary/code/enl.cpp | 7 ++-- .../netvadapterlibrary/code/rxqueue.cpp | 37 +--------------------- network/wlan/WIFICX/drivercode/device.cpp | 3 ++ network/wlan/WIFICX/drivercode/wifihal.cpp | 9 ++++-- 5 files changed, 16 insertions(+), 43 deletions(-) (limited to 'network/netadaptercx/netvadapterlibrary/code/rxqueue.cpp') diff --git a/network/netadaptercx/netvadapterlibrary/Interface/netvadapter.h b/network/netadaptercx/netvadapterlibrary/Interface/netvadapter.h index 88976291..b8474a9b 100644 --- a/network/netadaptercx/netvadapterlibrary/Interface/netvadapter.h +++ b/network/netadaptercx/netvadapterlibrary/Interface/netvadapter.h @@ -9,6 +9,9 @@ #define NETV_NUMBER_OF_QUEUES 1 +#define NETV_SUPPORT_RSS FALSE // RSS not supported due to ENL limitations +#define NETV_SUPPORT_TX_DEMUXING FALSE // TX Demuxing not supported due to ENL limitations + // supported filters #define NETV_SUPPORTED_FILTERS ( \ NetPacketFilterFlagDirected | \ diff --git a/network/netadaptercx/netvadapterlibrary/code/enl.cpp b/network/netadaptercx/netvadapterlibrary/code/enl.cpp index 0a7d53d3..fb763330 100644 --- a/network/netadaptercx/netvadapterlibrary/code/enl.cpp +++ b/network/netadaptercx/netvadapterlibrary/code/enl.cpp @@ -668,10 +668,10 @@ EnlIsPortActive( { ENLP_PORT* port = &EnlLink->Ports[PortIndex]; ENLP_QUEUE* txq = &port->TxQueue[0]; - + ENLP_QUEUE* rxq = &port->RxQueue[0]; NT_FRE_ASSERT(PortIndex < ENLP_PORT_COUNT); - return (txq->Queue == nullptr) ? FALSE : TRUE; + return (txq->Queue == nullptr && rxq->Queue == nullptr) ? FALSE : TRUE; } _IRQL_requires_max_(PASSIVE_LEVEL) @@ -718,7 +718,6 @@ EnlDeactivateLinkPort( ENLP_PORT* port = &EnlLink->Ports[PortIndex]; LogInformation(FLAG_DRIVER, L"PortIndex=%u Queue=%p", PortIndex, port->TxQueue[0].Queue); - ULONG i; NT_FRE_ASSERT(EnlIsPortActive(EnlLink, PortIndex)); KLockThisExclusive(EnlLink->Lock); @@ -737,7 +736,7 @@ EnlDeactivateLinkPort( // As long as there's one port with active queues, the EnlThread will run. - for (i = 0; i < ENLP_PORT_COUNT; i++) + for (ULONG i = 0; i < ENLP_PORT_COUNT; i++) { if (EnlIsPortActive(EnlLink, i)) { diff --git a/network/netadaptercx/netvadapterlibrary/code/rxqueue.cpp b/network/netadaptercx/netvadapterlibrary/code/rxqueue.cpp index d0b87f9e..6eed638c 100644 --- a/network/netadaptercx/netvadapterlibrary/code/rxqueue.cpp +++ b/network/netadaptercx/netvadapterlibrary/code/rxqueue.cpp @@ -68,26 +68,7 @@ NetvRxQueue::NetvRxQueue( NetExtensionTypePacket); NetRxQueueGetExtension(m_handle, &extension, &RxXSumExtension); -#if ((NETADAPTER_VERSION_MAJOR == 2) && (NETADAPTER_VERSION_MINOR >= 6)) - if (Adapter.PreallocatedRxBuffers) - { - NET_EXTENSION_QUERY_INIT( - &extension, - NET_FRAGMENT_EXTENSION_NET_MEMORY_NAME, - NET_FRAGMENT_EXTENSION_NET_MEMORY_VERSION_1, - NetExtensionTypeFragment); - - NetRxQueueGetExtension(m_handle, &extension, &NetMemoryExtension); - - NET_EXTENSION_QUERY_INIT( - &extension, - NET_FRAGMENT_EXTENSION_RETURN_CONTEXT_NAME, - NET_FRAGMENT_EXTENSION_RETURN_CONTEXT_VERSION_1, - NetExtensionTypeFragment); - NetRxQueueGetExtension(m_handle, &extension, &NetMemoryReturnContextExtensionIn); - } -#endif //NETCX 2.6 only EnlQueueHandle = EnlCreateQueue(Handle, RX); } @@ -150,23 +131,7 @@ NetvRxQueue::Advance( break; } } -#if ((NETADAPTER_VERSION_MAJOR == 2) && (NETADAPTER_VERSION_MINOR >= 6)) - if (m_adapter.PreallocatedRxBuffers) - { - NET_RING* dataBufferRing = GetNetMemoryReturnRing(); - while (dataBufferRing->BeginIndex != dataBufferRing->EndIndex) - { - NET_FRAGMENT_RETURN_CONTEXT* netMemoryReturnContextOut = - NetRingGetFragmentReturnContextAtIndex( - dataBufferRing, - dataBufferRing->BeginIndex); - - MemoryBuffer* memoryBuffer = reinterpret_cast(netMemoryReturnContextOut->Handle); - GetMemoryFromHandle(m_adapter.m_preallocatedRxBuffers)->ReturnBuffer(memoryBuffer); - dataBufferRing->BeginIndex = NetRingIncrementIndex(dataBufferRing, dataBufferRing->BeginIndex); - } - } -#endif //NETCX 2.6 only + NetFragmentIteratorSet(&fi); NetPacketIteratorSet(&pi); EnlRingDoorBell(EnlQueueHandle, fr->EndIndex); diff --git a/network/wlan/WIFICX/drivercode/device.cpp b/network/wlan/WIFICX/drivercode/device.cpp index d251121d..0e04d562 100644 --- a/network/wlan/WIFICX/drivercode/device.cpp +++ b/network/wlan/WIFICX/drivercode/device.cpp @@ -49,10 +49,13 @@ NTSTATUS EvtWifiDeviceCreateAdapter(WDFDEVICE Device, NETADAPTER_INIT* AdapterIn WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&adapterAttributes, WifiNetvAdapter); adapterAttributes.EvtCleanupCallback = EvtAdapterCleanup; +#ifdef NETV_SUPPORT_TX_DEMUXING WIFI_ADAPTER_TX_DEMUX peerInfoDemux; WIFI_ADAPTER_TX_PEER_ADDRESS_DEMUX_INIT(&peerInfoDemux, MaxNumOfPeers); WifiAdapterInitAddTxDemux(AdapterInit, &peerInfoDemux); +#endif // NETV_SUPPORT_TX_DEMUXING + NETADAPTER netAdapter; NTSTATUS ntStatus = NetAdapterCreate(AdapterInit, &adapterAttributes, &netAdapter); if (!NT_SUCCESS(ntStatus)) diff --git a/network/wlan/WIFICX/drivercode/wifihal.cpp b/network/wlan/WIFICX/drivercode/wifihal.cpp index 29de321b..fead61b3 100644 --- a/network/wlan/WIFICX/drivercode/wifihal.cpp +++ b/network/wlan/WIFICX/drivercode/wifihal.cpp @@ -604,13 +604,14 @@ _Use_decl_annotations_ NTSTATUS WifiHAL::WifiIhvConnect(const WDI_TASK_CONNECT_PARAMETERS& ConnectParameters, const PWDI_MESSAGE_HEADER pWdiHeader, UINT) { NT_ASSERT(m_LastConnectEntryId == 0); +#ifdef NETV_SUPPORT_TX_DEMUXING if (m_LastConnectEntryId != 0) // Not Disconnected State { WifiAdapterRemovePeer( WifiGetIhvDeviceContext(m_Device)->netAdapters[pWdiHeader->PortId], reinterpret_cast(&m_ConnectedPeer)); } - +#endif //NETV_SUPPORT_TX_DEMUXING WX_RETURN_NTSTATUS_IF_NOT_NT_SUCCESS_MSG(WifiIhvPerformAssociation( &ConnectParameters.PreferredBSSEntryList, &ConnectParameters.ConnectParameters.AuthenticationAlgorithms, pWdiHeader), "Failed to perform association"); @@ -724,10 +725,11 @@ NTSTATUS WifiHAL::WifiIhvPerformAssociation( NewConnectEntryId = connectEntry; m_LastConnectTransactionId = pWdiHeader->TransactionId; - +#ifdef NETV_SUPPORT_TX_DEMUXING // add peer on datapath WifiAdapterAddPeer(pDeviceContext->netAdapters[pWdiHeader->PortId], reinterpret_cast(g_ConnectEntries[connectEntry].pMacAddress)); +#endif // NETV_SUPPORT_TX_DEMUXING #ifdef WIFI_IHV_HANDSHAKE // Pretend to recieve M1 on datapath before, the association complete has made it up the control path. RecieveDatapathFrame(0x33, sizeof(pucData), pucData); @@ -971,10 +973,11 @@ NTSTATUS WifiHAL::WifiIhvDisconnect(const WDI_TASK_DISCONNECT_PARAMETERS&, const m_LastConnectEntryId = 0; // Disconnected State +#ifdef NETV_SUPPORT_TX_DEMUXING WifiAdapterRemovePeer( WifiGetIhvDeviceContext(m_Device)->netAdapters[pWdiHeader->PortId], reinterpret_cast(&m_ConnectedPeer)); - +#endif RtlZeroMemory(&m_ConnectedPeer, sizeof(DOT11_MAC_ADDRESS)); return STATUS_SUCCESS; -- cgit v1.3.1