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
|
|
|
|
2016-08-15 11:09:06 +03:00
|
|
|
#ifndef __nsWifiAccessPoint__
|
|
|
|
#define __nsWifiAccessPoint__
|
|
|
|
|
2016-08-23 00:37:42 +03:00
|
|
|
#include <algorithm>
|
2009-03-17 03:30:58 +03:00
|
|
|
#include "nsWifiMonitor.h"
|
|
|
|
#include "nsIWifiAccessPoint.h"
|
|
|
|
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsCOMArray.h"
|
2013-12-09 06:52:54 +04:00
|
|
|
#include "mozilla/ArrayUtils.h" // ArrayLength
|
2012-06-06 07:18:25 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2016-08-15 11:09:06 +03:00
|
|
|
#include "mozilla/Sprintf.h"
|
2009-03-17 03:30:58 +03:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class nsWifiAccessPoint final : public nsIWifiAccessPoint {
|
2018-04-30 19:46:04 +03:00
|
|
|
~nsWifiAccessPoint() = default;
|
2014-06-24 20:36:44 +04:00
|
|
|
|
2009-03-17 03:30:58 +03:00
|
|
|
public:
|
2013-07-19 06:24:13 +04:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2009-03-17 03:30:58 +03:00
|
|
|
NS_DECL_NSIWIFIACCESSPOINT
|
|
|
|
|
|
|
|
nsWifiAccessPoint();
|
|
|
|
|
2021-06-04 15:35:16 +03:00
|
|
|
char mMac[18]{0};
|
2009-03-17 03:30:58 +03:00
|
|
|
int mSignal;
|
2021-06-04 15:35:16 +03:00
|
|
|
char mSsid[33]{0};
|
2009-03-17 03:30:58 +03:00
|
|
|
int mSsidLen;
|
|
|
|
|
|
|
|
void setSignal(int signal) { mSignal = signal; }
|
|
|
|
|
2012-10-10 05:40:11 +04:00
|
|
|
void setMacRaw(const char* aString) {
|
|
|
|
memcpy(mMac, aString, mozilla::ArrayLength(mMac));
|
|
|
|
}
|
|
|
|
|
2009-09-17 00:08:15 +04:00
|
|
|
void setMac(const unsigned char mac_as_int[6]) {
|
2009-03-17 03:30:58 +03:00
|
|
|
// mac_as_int is big-endian. Write in byte chunks.
|
|
|
|
// Format is XX-XX-XX-XX-XX-XX.
|
|
|
|
|
2011-05-10 23:44:17 +04:00
|
|
|
const unsigned char holder[6] = {0};
|
|
|
|
if (!mac_as_int) {
|
|
|
|
mac_as_int = holder;
|
|
|
|
}
|
|
|
|
|
2009-03-17 03:30:58 +03:00
|
|
|
static const char* kMacFormatString = ("%02x-%02x-%02x-%02x-%02x-%02x");
|
2009-09-17 00:08:15 +04:00
|
|
|
|
2016-08-15 11:09:06 +03:00
|
|
|
SprintfLiteral(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-17 00:08:15 +04:00
|
|
|
|
2009-03-17 03:30:58 +03:00
|
|
|
mMac[17] = 0;
|
2012-07-10 20:55:08 +04:00
|
|
|
}
|
2009-03-17 03:30:58 +03:00
|
|
|
|
2016-08-23 00:37:42 +03:00
|
|
|
void setSSIDRaw(const char* aSSID, size_t len) {
|
|
|
|
mSsidLen = std::min(len, mozilla::ArrayLength(mSsid));
|
|
|
|
memcpy(mSsid, aSSID, mSsidLen);
|
2012-10-10 05:40:11 +04:00
|
|
|
}
|
|
|
|
|
2009-03-17 03:30:58 +03:00
|
|
|
void setSSID(const char* aSSID, unsigned long len) {
|
2011-05-10 23:44:17 +04:00
|
|
|
if (aSSID && (len < sizeof(mSsid))) {
|
2009-03-17 03:30:58 +03:00
|
|
|
strncpy(mSsid, aSSID, len);
|
|
|
|
mSsid[len] = 0;
|
|
|
|
mSsidLen = len;
|
|
|
|
} else {
|
|
|
|
mSsid[0] = 0;
|
|
|
|
mSsidLen = 0;
|
|
|
|
}
|
2012-07-10 20:55:08 +04:00
|
|
|
}
|
2009-03-17 03:30:58 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
// 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
|
|
|
void ReplaceArray(nsCOMArray<nsWifiAccessPoint>& a,
|
|
|
|
nsCOMArray<nsWifiAccessPoint>& b);
|
|
|
|
|
|
|
|
#endif
|