1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #include "win_wlanLibrary.h"
7 // Moz headers (alphabetical)
12 WinWLANLibrary::Load()
14 WinWLANLibrary
*ret
= new WinWLANLibrary();
19 if (!ret
->Initialize()) {
27 WinWLANLibrary::WinWLANLibrary()
28 : mWlanLibrary(nullptr),
30 mWlanEnumInterfacesPtr(nullptr),
31 mWlanGetNetworkBssListPtr(nullptr),
32 mWlanFreeMemoryPtr(nullptr),
33 mWlanCloseHandlePtr(nullptr),
34 mWlanOpenHandlePtr(nullptr),
35 mWlanRegisterNotificationPtr(nullptr),
41 WinWLANLibrary::GetWLANHandle() const
46 decltype(::WlanEnumInterfaces
)*
47 WinWLANLibrary::GetWlanEnumInterfacesPtr() const
49 return mWlanEnumInterfacesPtr
;
52 decltype(::WlanGetNetworkBssList
)*
53 WinWLANLibrary::GetWlanGetNetworkBssListPtr() const
55 return mWlanGetNetworkBssListPtr
;
58 decltype(::WlanFreeMemory
)*
59 WinWLANLibrary::GetWlanFreeMemoryPtr() const
61 return mWlanFreeMemoryPtr
;
64 decltype(::WlanCloseHandle
)*
65 WinWLANLibrary::GetWlanCloseHandlePtr() const
67 return mWlanCloseHandlePtr
;
70 decltype(::WlanOpenHandle
)*
71 WinWLANLibrary::GetWlanOpenHandlePtr() const
73 return mWlanOpenHandlePtr
;
76 decltype(::WlanRegisterNotification
)*
77 WinWLANLibrary::GetWlanRegisterNotificationPtr() const
79 return mWlanRegisterNotificationPtr
;
83 WinWLANLibrary::GetWlanScanPtr() const
89 WinWLANLibrary::Initialize()
91 mWlanLibrary
= LoadLibrary("Wlanapi.dll");
97 (decltype(::WlanOpenHandle
)*) GetProcAddress(mWlanLibrary
,
99 mWlanEnumInterfacesPtr
=
100 (decltype(::WlanEnumInterfaces
)*) GetProcAddress(mWlanLibrary
,
101 "WlanEnumInterfaces");
102 mWlanRegisterNotificationPtr
=
103 (decltype(::WlanRegisterNotification
)*) GetProcAddress(mWlanLibrary
,
104 "WlanRegisterNotification");
106 (decltype(::WlanScan
)*) GetProcAddress(mWlanLibrary
, "WlanScan");
109 (decltype(::WlanFreeMemory
)*) GetProcAddress(mWlanLibrary
,
111 mWlanCloseHandlePtr
=
112 (decltype(::WlanCloseHandle
)*) GetProcAddress(mWlanLibrary
,
114 mWlanGetNetworkBssListPtr
=
115 (decltype(::WlanGetNetworkBssList
)*) GetProcAddress(mWlanLibrary
,
116 "WlanGetNetworkBssList");
118 if (!mWlanOpenHandlePtr
||
119 !mWlanEnumInterfacesPtr
||
120 !mWlanRegisterNotificationPtr
||
121 !mWlanGetNetworkBssListPtr
||
123 !mWlanFreeMemoryPtr
||
124 !mWlanCloseHandlePtr
) {
128 // Get the handle to the WLAN API.
129 DWORD negotiated_version
;
130 // We could be executing on either Windows XP or Windows Vista, so use the
131 // lower version of the client WLAN API. It seems that the negotiated version
132 // is the Vista version irrespective of what we pass!
133 static const int kXpWlanClientVersion
= 1;
135 (*mWlanOpenHandlePtr
)(kXpWlanClientVersion
,
145 WinWLANLibrary::~WinWLANLibrary()
149 (*mWlanCloseHandlePtr
)(mWlanLibrary
, mWlanHandle
);
150 mWlanHandle
= nullptr;
152 ::FreeLibrary(mWlanLibrary
);
153 mWlanLibrary
= nullptr;