2012-05-21 11:12:37 +00: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 11:49:51 +00: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"
|
|
|
|
|
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-04-01 04:29:02 +00:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2009-03-21 11:49:51 +00:00
|
|
|
nsresult
|
|
|
|
nsWifiMonitor::DoScan()
|
|
|
|
{
|
|
|
|
HINSTANCE wlan_library = LoadLibrary("Wlanapi.dll");
|
|
|
|
if (!wlan_library)
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
2010-03-02 05:56:06 +00:00
|
|
|
|
2009-03-21 11:49:51 +00:00
|
|
|
WlanOpenHandleFunction WlanOpenHandle = (WlanOpenHandleFunction) GetProcAddress(wlan_library, "WlanOpenHandle");
|
|
|
|
WlanEnumInterfacesFunction WlanEnumInterfaces = (WlanEnumInterfacesFunction) GetProcAddress(wlan_library, "WlanEnumInterfaces");
|
|
|
|
WlanGetNetworkBssListFunction WlanGetNetworkBssList = (WlanGetNetworkBssListFunction) GetProcAddress(wlan_library, "WlanGetNetworkBssList");
|
|
|
|
WlanFreeMemoryFunction WlanFreeMemory = (WlanFreeMemoryFunction) GetProcAddress(wlan_library, "WlanFreeMemory");
|
|
|
|
WlanCloseHandleFunction WlanCloseHandle = (WlanCloseHandleFunction) GetProcAddress(wlan_library, "WlanCloseHandle");
|
2010-03-02 05:56:06 +00:00
|
|
|
|
2009-03-21 11:49:51 +00:00
|
|
|
if (!WlanOpenHandle ||
|
|
|
|
!WlanEnumInterfaces ||
|
|
|
|
!WlanGetNetworkBssList ||
|
|
|
|
!WlanFreeMemory ||
|
|
|
|
!WlanCloseHandle)
|
|
|
|
return NS_ERROR_FAILURE;
|
2010-03-02 05:56:06 +00:00
|
|
|
|
2009-03-21 11:49:51 +00:00
|
|
|
// Regularly get the access point data.
|
2010-03-02 05:56:06 +00:00
|
|
|
|
2009-03-21 11:49:51 +00:00
|
|
|
nsCOMArray<nsWifiAccessPoint> lastAccessPoints;
|
|
|
|
nsCOMArray<nsWifiAccessPoint> accessPoints;
|
2010-03-02 05:56:06 +00:00
|
|
|
|
2009-03-21 11:49:51 +00:00
|
|
|
do {
|
|
|
|
accessPoints.Clear();
|
2010-03-02 05:56:06 +00:00
|
|
|
|
2009-03-21 11:49:51 +00:00
|
|
|
// Get the handle to the WLAN API.
|
|
|
|
DWORD negotiated_version;
|
2013-09-19 19:29:27 +00:00
|
|
|
HANDLE wlan_handle = nullptr;
|
2009-03-21 11:49:51 +00: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 19:29:27 +00:00
|
|
|
nullptr,
|
2009-03-21 11:49:51 +00:00
|
|
|
&negotiated_version,
|
|
|
|
&wlan_handle) != ERROR_SUCCESS) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
2010-03-02 05:56:06 +00:00
|
|
|
|
2009-03-21 11:49:51 +00:00
|
|
|
// try again later.
|
|
|
|
if (!wlan_handle)
|
|
|
|
return NS_ERROR_FAILURE;
|
2010-03-02 05:56:06 +00:00
|
|
|
|
2009-03-21 11:49:51 +00:00
|
|
|
// Get the list of interfaces. WlanEnumInterfaces allocates interface_list.
|
2013-09-19 19:29:27 +00:00
|
|
|
WLAN_INTERFACE_INFO_LIST *interface_list = nullptr;
|
|
|
|
if ((*WlanEnumInterfaces)(wlan_handle, nullptr, &interface_list) != ERROR_SUCCESS) {
|
2009-03-21 11:49:51 +00:00
|
|
|
// try again later
|
2013-09-19 19:29:27 +00:00
|
|
|
(*WlanCloseHandle)(wlan_handle, nullptr);
|
2009-03-21 11:49:51 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2010-03-02 05:56:06 +00:00
|
|
|
|
2009-03-21 11:49:51 +00: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-02 05:56:06 +00:00
|
|
|
|
2009-03-21 11:49:51 +00:00
|
|
|
WLAN_BSS_LIST *bss_list;
|
|
|
|
HRESULT rv = (*WlanGetNetworkBssList)(wlan_handle,
|
|
|
|
&interface_list->InterfaceInfo[i].InterfaceGuid,
|
2013-09-19 19:29:27 +00:00
|
|
|
nullptr, // Use all SSIDs.
|
2009-03-21 11:49:51 +00:00
|
|
|
DOT11_BSS_TYPE_UNUSED,
|
2013-09-19 19:29:27 +00:00
|
|
|
false, // bSecurityEnabled - unused
|
|
|
|
nullptr, // reserved
|
2009-03-21 11:49:51 +00:00
|
|
|
&bss_list);
|
|
|
|
if (rv != ERROR_SUCCESS) {
|
|
|
|
continue;
|
|
|
|
}
|
2010-03-02 05:56:06 +00:00
|
|
|
|
2009-03-21 11:49:51 +00:00
|
|
|
for (int j = 0; j < static_cast<int>(bss_list->dwNumberOfItems); ++j) {
|
2010-03-02 05:56:06 +00:00
|
|
|
|
2009-03-21 11:49:51 +00:00
|
|
|
nsWifiAccessPoint* ap = new nsWifiAccessPoint();
|
|
|
|
if (!ap)
|
|
|
|
continue;
|
2010-03-02 05:56:06 +00:00
|
|
|
|
2009-03-21 11:49:51 +00:00
|
|
|
const WLAN_BSS_ENTRY bss_entry = bss_list->wlanBssEntries[j];
|
2010-03-02 05:56:06 +00:00
|
|
|
|
2009-03-21 11:49:51 +00:00
|
|
|
ap->setMac(bss_entry.dot11Bssid);
|
|
|
|
ap->setSignal(bss_entry.lRssi);
|
|
|
|
ap->setSSID((char*) bss_entry.dot11Ssid.ucSSID,
|
|
|
|
bss_entry.dot11Ssid.uSSIDLength);
|
2010-03-02 05:56:06 +00:00
|
|
|
|
2009-03-21 11:49:51 +00:00
|
|
|
accessPoints.AppendObject(ap);
|
|
|
|
}
|
|
|
|
(*WlanFreeMemory)(bss_list);
|
|
|
|
}
|
2010-03-02 05:56:06 +00:00
|
|
|
|
2009-03-21 11:49:51 +00:00
|
|
|
// Free interface_list.
|
|
|
|
(*WlanFreeMemory)(interface_list);
|
2010-03-02 05:56:06 +00:00
|
|
|
|
2009-03-21 11:49:51 +00:00
|
|
|
// Close the handle.
|
2013-09-19 19:29:27 +00:00
|
|
|
(*WlanCloseHandle)(wlan_handle, nullptr);
|
2010-03-02 05:56:06 +00:00
|
|
|
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool accessPointsChanged = !AccessPointsEqual(accessPoints, lastAccessPoints);
|
2009-03-21 11:49:51 +00:00
|
|
|
ReplaceArray(lastAccessPoints, accessPoints);
|
2010-03-02 05:56:06 +00:00
|
|
|
|
2011-07-27 16:26:20 +00:00
|
|
|
nsresult rv = CallWifiListeners(lastAccessPoints, accessPointsChanged);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-03-02 05:56:06 +00:00
|
|
|
|
2009-03-21 11:49:51 +00:00
|
|
|
// wait for some reasonable amount of time. pref?
|
|
|
|
LOG(("waiting on monitor\n"));
|
2010-03-02 05:56:06 +00:00
|
|
|
|
2011-04-29 19:21:57 +00:00
|
|
|
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
|
2009-03-21 11:49:51 +00:00
|
|
|
mon.Wait(PR_SecondsToInterval(60));
|
|
|
|
}
|
2010-02-07 15:52:43 +00:00
|
|
|
while (mKeepGoing);
|
2010-09-28 22:07:15 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
2009-03-21 11:49:51 +00:00
|
|
|
}
|