2012-05-21 04:12:37 -07:00
|
|
|
/* 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/. */
|
2009-03-21 04:49:51 -07:00
|
|
|
|
|
|
|
|
|
|
|
#include "windows.h"
|
|
|
|
#include "wlanapi.h"
|
|
|
|
|
|
|
|
#include "stdlib.h"
|
|
|
|
|
|
|
|
#include "nsWifiMonitor.h"
|
|
|
|
#include "nsWifiAccessPoint.h"
|
|
|
|
|
|
|
|
#include "nsServiceManagerUtils.h"
|
|
|
|
#include "nsComponentManagerUtils.h"
|
|
|
|
#include "nsIMutableArray.h"
|
|
|
|
|
2014-02-17 14:32:52 -08:00
|
|
|
#define DOT11_BSS_TYPE_UNUSED static_cast<DOT11_BSS_TYPE>(0)
|
|
|
|
|
Rollup of bug 645263 and bug 646259: Switch to mozilla:: sync primitives. r=cjones,dbaron,doublec,ehsan src=bsmedberg
Bug 645263, part 0: Count sync primitive ctor/dtors. r=dbaron
Bug 645263, part 1: Migrate content/media to mozilla:: sync primitives. r=doublec
Bug 645263, part 2: Migrate modules/plugin to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 3: Migrate nsComponentManagerImpl to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 4: Migrate everything else to mozilla:: sync primitives. r=dbaron
Bug 645263, part 5: Remove nsAutoLock.*. sr=bsmedberg
Bug 645263, part 6: Make editor test be nicer to deadlock detector. r=ehsan
Bug 645263, part 7: Disable tracemalloc backtraces for xpcshell tests. r=dbaron
Bug 646259: Fix nsCacheService to use a CondVar for notifying. r=cjones
2011-03-31 21:29:02 -07:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2009-03-21 04:49:51 -07:00
|
|
|
nsresult
|
|
|
|
nsWifiMonitor::DoScan()
|
|
|
|
{
|
|
|
|
HINSTANCE wlan_library = LoadLibrary("Wlanapi.dll");
|
|
|
|
if (!wlan_library)
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
2010-03-01 21:56:06 -08:00
|
|
|
|
2014-02-17 14:32:52 -08:00
|
|
|
decltype(::WlanOpenHandle)* WlanOpenHandle = (decltype(::WlanOpenHandle)*) GetProcAddress(wlan_library, "WlanOpenHandle");
|
|
|
|
decltype(::WlanEnumInterfaces)* WlanEnumInterfaces = (decltype(::WlanEnumInterfaces)*) GetProcAddress(wlan_library, "WlanEnumInterfaces");
|
|
|
|
decltype(::WlanGetNetworkBssList)* WlanGetNetworkBssList = (decltype(::WlanGetNetworkBssList)*) GetProcAddress(wlan_library, "WlanGetNetworkBssList");
|
|
|
|
decltype(::WlanFreeMemory)* WlanFreeMemory = (decltype(::WlanFreeMemory)*) GetProcAddress(wlan_library, "WlanFreeMemory");
|
|
|
|
decltype(::WlanCloseHandle)* WlanCloseHandle = (decltype(::WlanCloseHandle)*) GetProcAddress(wlan_library, "WlanCloseHandle");
|
2010-03-01 21:56:06 -08:00
|
|
|
|
2009-03-21 04:49:51 -07:00
|
|
|
if (!WlanOpenHandle ||
|
|
|
|
!WlanEnumInterfaces ||
|
|
|
|
!WlanGetNetworkBssList ||
|
|
|
|
!WlanFreeMemory ||
|
|
|
|
!WlanCloseHandle)
|
|
|
|
return NS_ERROR_FAILURE;
|
2010-03-01 21:56:06 -08:00
|
|
|
|
2009-03-21 04:49:51 -07:00
|
|
|
// Regularly get the access point data.
|
2010-03-01 21:56:06 -08:00
|
|
|
|
2009-03-21 04:49:51 -07:00
|
|
|
nsCOMArray<nsWifiAccessPoint> lastAccessPoints;
|
|
|
|
nsCOMArray<nsWifiAccessPoint> accessPoints;
|
2010-03-01 21:56:06 -08:00
|
|
|
|
2009-03-21 04:49:51 -07:00
|
|
|
do {
|
|
|
|
accessPoints.Clear();
|
2010-03-01 21:56:06 -08:00
|
|
|
|
2009-03-21 04:49:51 -07:00
|
|
|
// Get the handle to the WLAN API.
|
|
|
|
DWORD negotiated_version;
|
2013-09-19 12:29:27 -07:00
|
|
|
HANDLE wlan_handle = nullptr;
|
2009-03-21 04:49:51 -07:00
|
|
|
// 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 ((*WlanOpenHandle)(kXpWlanClientVersion,
|
2013-09-19 12:29:27 -07:00
|
|
|
nullptr,
|
2009-03-21 04:49:51 -07:00
|
|
|
&negotiated_version,
|
|
|
|
&wlan_handle) != ERROR_SUCCESS) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
2010-03-01 21:56:06 -08:00
|
|
|
|
2009-03-21 04:49:51 -07:00
|
|
|
// try again later.
|
|
|
|
if (!wlan_handle)
|
|
|
|
return NS_ERROR_FAILURE;
|
2010-03-01 21:56:06 -08:00
|
|
|
|
2009-03-21 04:49:51 -07:00
|
|
|
// Get the list of interfaces. WlanEnumInterfaces allocates interface_list.
|
2013-09-19 12:29:27 -07:00
|
|
|
WLAN_INTERFACE_INFO_LIST *interface_list = nullptr;
|
|
|
|
if ((*WlanEnumInterfaces)(wlan_handle, nullptr, &interface_list) != ERROR_SUCCESS) {
|
2009-03-21 04:49:51 -07:00
|
|
|
// try again later
|
2013-09-19 12:29:27 -07:00
|
|
|
(*WlanCloseHandle)(wlan_handle, nullptr);
|
2009-03-21 04:49:51 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2010-03-01 21:56:06 -08:00
|
|
|
|
2009-03-21 04:49:51 -07:00
|
|
|
// Go through the list of interfaces and get the data for each.
|
|
|
|
for (int i = 0; i < static_cast<int>(interface_list->dwNumberOfItems); ++i) {
|
2010-03-01 21:56:06 -08:00
|
|
|
|
2009-03-21 04:49:51 -07:00
|
|
|
WLAN_BSS_LIST *bss_list;
|
|
|
|
HRESULT rv = (*WlanGetNetworkBssList)(wlan_handle,
|
|
|
|
&interface_list->InterfaceInfo[i].InterfaceGuid,
|
2013-09-19 12:29:27 -07:00
|
|
|
nullptr, // Use all SSIDs.
|
2009-03-21 04:49:51 -07:00
|
|
|
DOT11_BSS_TYPE_UNUSED,
|
2013-09-19 12:29:27 -07:00
|
|
|
false, // bSecurityEnabled - unused
|
|
|
|
nullptr, // reserved
|
2009-03-21 04:49:51 -07:00
|
|
|
&bss_list);
|
|
|
|
if (rv != ERROR_SUCCESS) {
|
|
|
|
continue;
|
|
|
|
}
|
2010-03-01 21:56:06 -08:00
|
|
|
|
2009-03-21 04:49:51 -07:00
|
|
|
for (int j = 0; j < static_cast<int>(bss_list->dwNumberOfItems); ++j) {
|
2010-03-01 21:56:06 -08:00
|
|
|
|
2009-03-21 04:49:51 -07:00
|
|
|
nsWifiAccessPoint* ap = new nsWifiAccessPoint();
|
|
|
|
if (!ap)
|
|
|
|
continue;
|
2010-03-01 21:56:06 -08:00
|
|
|
|
2009-03-21 04:49:51 -07:00
|
|
|
const WLAN_BSS_ENTRY bss_entry = bss_list->wlanBssEntries[j];
|
2010-03-01 21:56:06 -08:00
|
|
|
|
2009-03-21 04:49:51 -07:00
|
|
|
ap->setMac(bss_entry.dot11Bssid);
|
|
|
|
ap->setSignal(bss_entry.lRssi);
|
|
|
|
ap->setSSID((char*) bss_entry.dot11Ssid.ucSSID,
|
|
|
|
bss_entry.dot11Ssid.uSSIDLength);
|
2010-03-01 21:56:06 -08:00
|
|
|
|
2009-03-21 04:49:51 -07:00
|
|
|
accessPoints.AppendObject(ap);
|
|
|
|
}
|
|
|
|
(*WlanFreeMemory)(bss_list);
|
|
|
|
}
|
2010-03-01 21:56:06 -08:00
|
|
|
|
2009-03-21 04:49:51 -07:00
|
|
|
// Free interface_list.
|
|
|
|
(*WlanFreeMemory)(interface_list);
|
2010-03-01 21:56:06 -08:00
|
|
|
|
2009-03-21 04:49:51 -07:00
|
|
|
// Close the handle.
|
2013-09-19 12:29:27 -07:00
|
|
|
(*WlanCloseHandle)(wlan_handle, nullptr);
|
2010-03-01 21:56:06 -08:00
|
|
|
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool accessPointsChanged = !AccessPointsEqual(accessPoints, lastAccessPoints);
|
2009-03-21 04:49:51 -07:00
|
|
|
ReplaceArray(lastAccessPoints, accessPoints);
|
2010-03-01 21:56:06 -08:00
|
|
|
|
2011-07-27 09:26:20 -07:00
|
|
|
nsresult rv = CallWifiListeners(lastAccessPoints, accessPointsChanged);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-03-01 21:56:06 -08:00
|
|
|
|
2009-03-21 04:49:51 -07:00
|
|
|
// wait for some reasonable amount of time. pref?
|
|
|
|
LOG(("waiting on monitor\n"));
|
2010-03-01 21:56:06 -08:00
|
|
|
|
2011-04-29 12:21:57 -07:00
|
|
|
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
|
2009-03-21 04:49:51 -07:00
|
|
|
mon.Wait(PR_SecondsToInterval(60));
|
|
|
|
}
|
2010-02-07 07:52:43 -08:00
|
|
|
while (mKeepGoing);
|
2010-09-28 15:07:15 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
2009-03-21 04:49:51 -07:00
|
|
|
}
|