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"
|
|
|
|
|
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
|
|
|
|
2009-03-21 04:49:51 -07: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-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;
|
|
|
|
HANDLE wlan_handle = NULL;
|
|
|
|
// 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,
|
|
|
|
NULL,
|
|
|
|
&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.
|
|
|
|
WLAN_INTERFACE_INFO_LIST *interface_list = NULL;
|
|
|
|
if ((*WlanEnumInterfaces)(wlan_handle, NULL, &interface_list) != ERROR_SUCCESS) {
|
|
|
|
// try again later
|
|
|
|
(*WlanCloseHandle)(wlan_handle, NULL);
|
|
|
|
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,
|
|
|
|
NULL, // Use all SSIDs.
|
|
|
|
DOT11_BSS_TYPE_UNUSED,
|
|
|
|
false, // bSecurityEnabled - unused
|
|
|
|
NULL, // reserved
|
|
|
|
&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.
|
|
|
|
(*WlanCloseHandle)(wlan_handle, NULL);
|
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
|
|
|
}
|