From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- netwerk/wifi/win/WlanLibrary.cpp | 111 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 netwerk/wifi/win/WlanLibrary.cpp (limited to 'netwerk/wifi/win/WlanLibrary.cpp') diff --git a/netwerk/wifi/win/WlanLibrary.cpp b/netwerk/wifi/win/WlanLibrary.cpp new file mode 100644 index 0000000000..0fd36be660 --- /dev/null +++ b/netwerk/wifi/win/WlanLibrary.cpp @@ -0,0 +1,111 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "WlanLibrary.h" + +// Moz headers (alphabetical) + +WinWLANLibrary* WinWLANLibrary::Load() { + WinWLANLibrary* ret = new WinWLANLibrary(); + if (!ret) { + return nullptr; + } + + if (!ret->Initialize()) { + delete ret; + return nullptr; + } + + return ret; +} + +HANDLE +WinWLANLibrary::GetWLANHandle() const { return mWlanHandle; } + +decltype(::WlanEnumInterfaces)* WinWLANLibrary::GetWlanEnumInterfacesPtr() + const { + return mWlanEnumInterfacesPtr; +} + +decltype(::WlanGetNetworkBssList)* WinWLANLibrary::GetWlanGetNetworkBssListPtr() + const { + return mWlanGetNetworkBssListPtr; +} + +decltype(::WlanFreeMemory)* WinWLANLibrary::GetWlanFreeMemoryPtr() const { + return mWlanFreeMemoryPtr; +} + +decltype(::WlanCloseHandle)* WinWLANLibrary::GetWlanCloseHandlePtr() const { + return mWlanCloseHandlePtr; +} + +decltype(::WlanOpenHandle)* WinWLANLibrary::GetWlanOpenHandlePtr() const { + return mWlanOpenHandlePtr; +} + +decltype(::WlanRegisterNotification)* +WinWLANLibrary::GetWlanRegisterNotificationPtr() const { + return mWlanRegisterNotificationPtr; +} + +decltype(::WlanScan)* WinWLANLibrary::GetWlanScanPtr() const { + return mWlanScanPtr; +} + +bool WinWLANLibrary::Initialize() { + mWlanLibrary = LoadLibraryW(L"Wlanapi.dll"); + if (!mWlanLibrary) { + return false; + } + + mWlanOpenHandlePtr = (decltype(::WlanOpenHandle)*)GetProcAddress( + mWlanLibrary, "WlanOpenHandle"); + mWlanEnumInterfacesPtr = (decltype(::WlanEnumInterfaces)*)GetProcAddress( + mWlanLibrary, "WlanEnumInterfaces"); + mWlanRegisterNotificationPtr = + (decltype(::WlanRegisterNotification)*)GetProcAddress( + mWlanLibrary, "WlanRegisterNotification"); + mWlanScanPtr = + (decltype(::WlanScan)*)GetProcAddress(mWlanLibrary, "WlanScan"); + + mWlanFreeMemoryPtr = (decltype(::WlanFreeMemory)*)GetProcAddress( + mWlanLibrary, "WlanFreeMemory"); + mWlanCloseHandlePtr = (decltype(::WlanCloseHandle)*)GetProcAddress( + mWlanLibrary, "WlanCloseHandle"); + mWlanGetNetworkBssListPtr = + (decltype(::WlanGetNetworkBssList)*)GetProcAddress( + mWlanLibrary, "WlanGetNetworkBssList"); + + if (!mWlanOpenHandlePtr || !mWlanEnumInterfacesPtr || + !mWlanRegisterNotificationPtr || !mWlanGetNetworkBssListPtr || + !mWlanScanPtr || !mWlanFreeMemoryPtr || !mWlanCloseHandlePtr) { + return false; + } + + // Get the handle to the WLAN API. + DWORD negotiated_version; + // We could be executing on either Windows XP or Windows Vista, so use the + // lower version of the client WLAN API. It seems that the negotiated version + // is the Vista version irrespective of what we pass! + static const int kXpWlanClientVersion = 1; + if (ERROR_SUCCESS != (*mWlanOpenHandlePtr)(kXpWlanClientVersion, nullptr, + &negotiated_version, + &mWlanHandle)) { + return false; + } + + return true; +} + +WinWLANLibrary::~WinWLANLibrary() { + if (mWlanLibrary) { + if (mWlanHandle) { + (*mWlanCloseHandlePtr)(mWlanLibrary, mWlanHandle); + mWlanHandle = nullptr; + } + ::FreeLibrary(mWlanLibrary); + mWlanLibrary = nullptr; + } +} -- cgit v1.2.3