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-16 17:30:58 -07:00
|
|
|
|
|
|
|
#include "nsWifiAccessPoint.h"
|
2009-07-22 13:32:40 -07:00
|
|
|
#include "nsString.h"
|
2009-03-16 17:30:58 -07:00
|
|
|
#include "nsMemory.h"
|
|
|
|
#include "prlog.h"
|
|
|
|
|
|
|
|
#if defined(PR_LOGGING)
|
|
|
|
extern PRLogModuleInfo *gWifiMonitorLog;
|
|
|
|
#endif
|
|
|
|
#define LOG(args) PR_LOG(gWifiMonitorLog, PR_LOG_DEBUG, args)
|
|
|
|
|
|
|
|
|
2014-04-27 00:06:00 -07:00
|
|
|
NS_IMPL_ISUPPORTS(nsWifiAccessPoint, nsIWifiAccessPoint)
|
2009-03-16 17:30:58 -07:00
|
|
|
|
|
|
|
nsWifiAccessPoint::nsWifiAccessPoint()
|
|
|
|
{
|
|
|
|
// make sure these are null terminated (because we are paranoid)
|
2012-07-20 04:16:17 -07:00
|
|
|
mMac[0] = '\0';
|
|
|
|
mSsid[0] = '\0';
|
2009-03-16 17:30:58 -07:00
|
|
|
mSsidLen = 0;
|
2014-06-08 22:52:53 -07:00
|
|
|
mSignal = -1000;
|
2009-03-16 17:30:58 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsWifiAccessPoint::~nsWifiAccessPoint()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
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.
|
2009-07-22 13:32:40 -07:00
|
|
|
CopyASCIItoUTF16(mSsid, aSsid);
|
2009-03-16 17:30:58 -07: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 08:56:38 -07:00
|
|
|
NS_IMETHODIMP nsWifiAccessPoint::GetSignal(int32_t *aSignal)
|
2009-03-16 17:30:58 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG(aSignal);
|
|
|
|
*aSignal = mSignal;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Helper functions:
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool AccessPointsEqual(nsCOMArray<nsWifiAccessPoint>& a, nsCOMArray<nsWifiAccessPoint>& b)
|
2009-03-16 17:30:58 -07:00
|
|
|
{
|
|
|
|
if (a.Count() != b.Count()) {
|
|
|
|
LOG(("AccessPoint lists have different lengths\n"));
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2009-03-16 17:30:58 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
for (int32_t i = 0; i < a.Count(); i++) {
|
2009-03-16 17:30:58 -07:00
|
|
|
LOG(("++ Looking for %s\n", a[i]->mSsid));
|
2011-09-28 23:19:26 -07:00
|
|
|
bool found = false;
|
2012-08-22 08:56:38 -07:00
|
|
|
for (int32_t j = 0; j < b.Count(); j++) {
|
2009-03-16 17:30:58 -07: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-08 22:52:53 -07:00
|
|
|
!strcmp(a[i]->mMac, b[j]->mMac) &&
|
|
|
|
a[i]->mSignal == b[j]->mSignal) {
|
2011-10-17 07:59:28 -07:00
|
|
|
found = true;
|
2009-03-16 17:30:58 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!found)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2009-03-16 17:30:58 -07:00
|
|
|
}
|
|
|
|
LOG((" match!\n"));
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2009-03-16 17:30:58 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void ReplaceArray(nsCOMArray<nsWifiAccessPoint>& a, nsCOMArray<nsWifiAccessPoint>& b)
|
|
|
|
{
|
|
|
|
a.Clear();
|
|
|
|
|
|
|
|
// better way to copy?
|
2012-08-22 08:56:38 -07:00
|
|
|
for (int32_t i = 0; i < b.Count(); i++) {
|
2009-03-16 17:30:58 -07:00
|
|
|
a.AppendObject(b[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
b.Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
|