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 "nsWifiMonitor.h"
|
|
|
|
#include "nsIWifiAccessPoint.h"
|
|
|
|
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsCOMArray.h"
|
2013-12-08 18:52:54 -08:00
|
|
|
#include "mozilla/ArrayUtils.h" // ArrayLength
|
2012-06-05 20:18:25 -07:00
|
|
|
#include "mozilla/Attributes.h"
|
2009-03-16 17:30:58 -07:00
|
|
|
|
|
|
|
#ifndef __nsWifiAccessPoint__
|
|
|
|
#define __nsWifiAccessPoint__
|
|
|
|
|
2012-06-05 20:18:25 -07:00
|
|
|
class nsWifiAccessPoint MOZ_FINAL : public nsIWifiAccessPoint
|
2009-03-16 17:30:58 -07:00
|
|
|
{
|
|
|
|
public:
|
2013-07-18 19:24:13 -07:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2009-03-16 17:30:58 -07:00
|
|
|
NS_DECL_NSIWIFIACCESSPOINT
|
|
|
|
|
|
|
|
nsWifiAccessPoint();
|
|
|
|
~nsWifiAccessPoint();
|
|
|
|
|
|
|
|
char mMac[18];
|
|
|
|
int mSignal;
|
|
|
|
char mSsid[33];
|
|
|
|
int mSsidLen;
|
|
|
|
|
|
|
|
void setSignal(int signal)
|
|
|
|
{
|
|
|
|
mSignal = signal;
|
2012-07-10 09:55:08 -07:00
|
|
|
}
|
2009-03-16 17:30:58 -07:00
|
|
|
|
2012-10-09 18:40:11 -07:00
|
|
|
void setMacRaw(const char* aString)
|
|
|
|
{
|
|
|
|
memcpy(mMac, aString, mozilla::ArrayLength(mMac));
|
|
|
|
}
|
|
|
|
|
2009-09-16 13:08:15 -07:00
|
|
|
void setMac(const unsigned char mac_as_int[6])
|
2009-03-16 17:30:58 -07:00
|
|
|
{
|
|
|
|
// mac_as_int is big-endian. Write in byte chunks.
|
|
|
|
// Format is XX-XX-XX-XX-XX-XX.
|
|
|
|
|
2011-05-10 12:44:17 -07:00
|
|
|
const unsigned char holder[6] = {0};
|
|
|
|
if (!mac_as_int) {
|
|
|
|
mac_as_int = holder;
|
|
|
|
}
|
|
|
|
|
2009-03-16 17:30:58 -07:00
|
|
|
static const char *kMacFormatString = ("%02x-%02x-%02x-%02x-%02x-%02x");
|
2009-09-16 13:08:15 -07:00
|
|
|
|
2009-03-16 17:30:58 -07:00
|
|
|
sprintf(mMac, kMacFormatString,
|
|
|
|
mac_as_int[0], mac_as_int[1], mac_as_int[2],
|
|
|
|
mac_as_int[3], mac_as_int[4], mac_as_int[5]);
|
2009-09-16 13:08:15 -07:00
|
|
|
|
2009-03-16 17:30:58 -07:00
|
|
|
mMac[17] = 0;
|
2012-07-10 09:55:08 -07:00
|
|
|
}
|
2009-03-16 17:30:58 -07:00
|
|
|
|
2012-10-09 18:40:11 -07:00
|
|
|
void setSSIDRaw(const char* aSSID, unsigned long len) {
|
|
|
|
memcpy(mSsid, aSSID, mozilla::ArrayLength(mSsid));
|
|
|
|
mSsidLen = PR_MIN(len, mozilla::ArrayLength(mSsid));
|
|
|
|
}
|
|
|
|
|
2009-03-16 17:30:58 -07:00
|
|
|
void setSSID(const char* aSSID, unsigned long len) {
|
2011-05-10 12:44:17 -07:00
|
|
|
if (aSSID && (len < sizeof(mSsid))) {
|
2009-03-16 17:30:58 -07:00
|
|
|
strncpy(mSsid, aSSID, len);
|
|
|
|
mSsid[len] = 0;
|
|
|
|
mSsidLen = len;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mSsid[0] = 0;
|
|
|
|
mSsidLen = 0;
|
|
|
|
}
|
2012-07-10 09:55:08 -07:00
|
|
|
}
|
2009-03-16 17:30:58 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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
|
|
|
void ReplaceArray(nsCOMArray<nsWifiAccessPoint>& a, nsCOMArray<nsWifiAccessPoint>& b);
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|