Bumping manifests a=b2g-bump
[gecko.git] / netwerk / wifi / win_wlanLibrary.cpp
blobcf1052788a13a5d0a51e73f6f5bd9c5c599625b0
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)
11 WinWLANLibrary*
12 WinWLANLibrary::Load()
14 WinWLANLibrary *ret = new WinWLANLibrary();
15 if (!ret) {
16 return nullptr;
19 if (!ret->Initialize()) {
20 delete ret;
21 return nullptr;
24 return ret;
27 WinWLANLibrary::WinWLANLibrary()
28 : mWlanLibrary(nullptr),
29 mWlanHandle(nullptr),
30 mWlanEnumInterfacesPtr(nullptr),
31 mWlanGetNetworkBssListPtr(nullptr),
32 mWlanFreeMemoryPtr(nullptr),
33 mWlanCloseHandlePtr(nullptr),
34 mWlanOpenHandlePtr(nullptr),
35 mWlanRegisterNotificationPtr(nullptr),
36 mWlanScanPtr(nullptr)
40 HANDLE
41 WinWLANLibrary::GetWLANHandle() const
43 return mWlanHandle;
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;
82 decltype(::WlanScan)*
83 WinWLANLibrary::GetWlanScanPtr() const
85 return mWlanScanPtr;
88 bool
89 WinWLANLibrary::Initialize()
91 mWlanLibrary = LoadLibrary("Wlanapi.dll");
92 if (!mWlanLibrary) {
93 return false;
96 mWlanOpenHandlePtr =
97 (decltype(::WlanOpenHandle)*) GetProcAddress(mWlanLibrary,
98 "WlanOpenHandle");
99 mWlanEnumInterfacesPtr =
100 (decltype(::WlanEnumInterfaces)*) GetProcAddress(mWlanLibrary,
101 "WlanEnumInterfaces");
102 mWlanRegisterNotificationPtr =
103 (decltype(::WlanRegisterNotification)*) GetProcAddress(mWlanLibrary,
104 "WlanRegisterNotification");
105 mWlanScanPtr =
106 (decltype(::WlanScan)*) GetProcAddress(mWlanLibrary, "WlanScan");
108 mWlanFreeMemoryPtr =
109 (decltype(::WlanFreeMemory)*) GetProcAddress(mWlanLibrary,
110 "WlanFreeMemory");
111 mWlanCloseHandlePtr =
112 (decltype(::WlanCloseHandle)*) GetProcAddress(mWlanLibrary,
113 "WlanCloseHandle");
114 mWlanGetNetworkBssListPtr =
115 (decltype(::WlanGetNetworkBssList)*) GetProcAddress(mWlanLibrary,
116 "WlanGetNetworkBssList");
118 if (!mWlanOpenHandlePtr ||
119 !mWlanEnumInterfacesPtr ||
120 !mWlanRegisterNotificationPtr ||
121 !mWlanGetNetworkBssListPtr ||
122 !mWlanScanPtr ||
123 !mWlanFreeMemoryPtr ||
124 !mWlanCloseHandlePtr) {
125 return false;
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;
134 if (ERROR_SUCCESS !=
135 (*mWlanOpenHandlePtr)(kXpWlanClientVersion,
136 nullptr,
137 &negotiated_version,
138 &mWlanHandle)) {
139 return false;
142 return true;
145 WinWLANLibrary::~WinWLANLibrary()
147 if (mWlanLibrary) {
148 if (mWlanHandle) {
149 (*mWlanCloseHandlePtr)(mWlanLibrary, mWlanHandle);
150 mWlanHandle = nullptr;
152 ::FreeLibrary(mWlanLibrary);
153 mWlanLibrary = nullptr;