2012-05-21 15:12:37 +04: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-17 03:30:58 +03:00
|
|
|
|
|
|
|
#include "nsWifiAccessPoint.h"
|
2009-07-23 00:32:40 +04:00
|
|
|
#include "nsString.h"
|
2009-03-17 03:30:58 +03:00
|
|
|
#include "nsMemory.h"
|
2015-05-19 21:15:34 +03:00
|
|
|
#include "mozilla/Logging.h"
|
2009-03-17 03:30:58 +03:00
|
|
|
|
2015-11-03 07:35:29 +03:00
|
|
|
extern mozilla::LazyLogModule gWifiMonitorLog;
|
2015-06-04 01:25:57 +03:00
|
|
|
#define LOG(args) MOZ_LOG(gWifiMonitorLog, mozilla::LogLevel::Debug, args)
|
2009-03-17 03:30:58 +03:00
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(nsWifiAccessPoint, nsIWifiAccessPoint)
|
2009-03-17 03:30:58 +03:00
|
|
|
|
|
|
|
nsWifiAccessPoint::nsWifiAccessPoint()
|
|
|
|
{
|
|
|
|
// make sure these are null terminated (because we are paranoid)
|
2012-07-20 15:16:17 +04:00
|
|
|
mMac[0] = '\0';
|
|
|
|
mSsid[0] = '\0';
|
2009-03-17 03:30:58 +03:00
|
|
|
mSsidLen = 0;
|
2014-06-09 09:52:53 +04:00
|
|
|
mSignal = -1000;
|
2009-03-17 03:30:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsWifiAccessPoint::GetMac(nsACString& aMac)
|
|
|
|
{
|
|
|
|
aMac.Assign(mMac);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsWifiAccessPoint::GetSsid(nsAString& aSsid)
|
|
|
|
{
|
|
|
|
// just assign and embedded nulls will truncate resulting
|
|
|
|
// in a displayable string.
|
2018-03-26 09:02:32 +03:00
|
|
|
aSsid.AssignASCII(mSsid);
|
2009-03-17 03:30:58 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsWifiAccessPoint::GetRawSSID(nsACString& aRawSsid)
|
|
|
|
{
|
|
|
|
aRawSsid.Assign(mSsid, mSsidLen); // SSIDs are 32 chars long
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
NS_IMETHODIMP nsWifiAccessPoint::GetSignal(int32_t *aSignal)
|
2009-03-17 03:30:58 +03:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG(aSignal);
|
|
|
|
*aSignal = mSignal;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Helper functions:
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool AccessPointsEqual(nsCOMArray<nsWifiAccessPoint>& a, nsCOMArray<nsWifiAccessPoint>& b)
|
2009-03-17 03:30:58 +03:00
|
|
|
{
|
|
|
|
if (a.Count() != b.Count()) {
|
|
|
|
LOG(("AccessPoint lists have different lengths\n"));
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2009-03-17 03:30:58 +03:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
for (int32_t i = 0; i < a.Count(); i++) {
|
2009-03-17 03:30:58 +03:00
|
|
|
LOG(("++ Looking for %s\n", a[i]->mSsid));
|
2011-09-29 10:19:26 +04:00
|
|
|
bool found = false;
|
2012-08-22 19:56:38 +04:00
|
|
|
for (int32_t j = 0; j < b.Count(); j++) {
|
2009-03-17 03:30:58 +03:00
|
|
|
LOG((" %s->%s | %s->%s\n", a[i]->mSsid, b[j]->mSsid, a[i]->mMac, b[j]->mMac));
|
|
|
|
if (!strcmp(a[i]->mSsid, b[j]->mSsid) &&
|
2014-06-09 09:52:53 +04:00
|
|
|
!strcmp(a[i]->mMac, b[j]->mMac) &&
|
|
|
|
a[i]->mSignal == b[j]->mSignal) {
|
2011-10-17 18:59:28 +04:00
|
|
|
found = true;
|
2009-03-17 03:30:58 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!found)
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2009-03-17 03:30:58 +03:00
|
|
|
}
|
|
|
|
LOG((" match!\n"));
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2009-03-17 03:30:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void ReplaceArray(nsCOMArray<nsWifiAccessPoint>& a, nsCOMArray<nsWifiAccessPoint>& b)
|
|
|
|
{
|
|
|
|
a.Clear();
|
|
|
|
|
|
|
|
// better way to copy?
|
2012-08-22 19:56:38 +04:00
|
|
|
for (int32_t i = 0; i < b.Count(); i++) {
|
2009-03-17 03:30:58 +03:00
|
|
|
a.AppendObject(b[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
b.Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
|