Source code

Revision control

Other Tools

1
/* This Source Code Form is subject to the terms of the Mozilla Public
2
* License, v. 2.0. If a copy of the MPL was not distributed with this
3
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5
#ifndef __nsWifiAccessPoint__
6
#define __nsWifiAccessPoint__
7
8
#include <algorithm>
9
#include "nsWifiMonitor.h"
10
#include "nsIWifiAccessPoint.h"
11
12
#include "nsString.h"
13
#include "nsCOMArray.h"
14
#include "mozilla/ArrayUtils.h" // ArrayLength
15
#include "mozilla/Attributes.h"
16
#include "mozilla/Sprintf.h"
17
18
class nsWifiAccessPoint final : public nsIWifiAccessPoint {
19
~nsWifiAccessPoint() = default;
20
21
public:
22
NS_DECL_THREADSAFE_ISUPPORTS
23
NS_DECL_NSIWIFIACCESSPOINT
24
25
nsWifiAccessPoint();
26
27
char mMac[18];
28
int mSignal;
29
char mSsid[33];
30
int mSsidLen;
31
32
void setSignal(int signal) { mSignal = signal; }
33
34
void setMacRaw(const char* aString) {
35
memcpy(mMac, aString, mozilla::ArrayLength(mMac));
36
}
37
38
void setMac(const unsigned char mac_as_int[6]) {
39
// mac_as_int is big-endian. Write in byte chunks.
40
// Format is XX-XX-XX-XX-XX-XX.
41
42
const unsigned char holder[6] = {0};
43
if (!mac_as_int) {
44
mac_as_int = holder;
45
}
46
47
static const char* kMacFormatString = ("%02x-%02x-%02x-%02x-%02x-%02x");
48
49
SprintfLiteral(mMac, kMacFormatString, mac_as_int[0], mac_as_int[1],
50
mac_as_int[2], mac_as_int[3], mac_as_int[4], mac_as_int[5]);
51
52
mMac[17] = 0;
53
}
54
55
void setSSIDRaw(const char* aSSID, size_t len) {
56
mSsidLen = std::min(len, mozilla::ArrayLength(mSsid));
57
memcpy(mSsid, aSSID, mSsidLen);
58
}
59
60
void setSSID(const char* aSSID, unsigned long len) {
61
if (aSSID && (len < sizeof(mSsid))) {
62
strncpy(mSsid, aSSID, len);
63
mSsid[len] = 0;
64
mSsidLen = len;
65
} else {
66
mSsid[0] = 0;
67
mSsidLen = 0;
68
}
69
}
70
};
71
72
// Helper functions
73
74
bool AccessPointsEqual(nsCOMArray<nsWifiAccessPoint>& a,
75
nsCOMArray<nsWifiAccessPoint>& b);
76
void ReplaceArray(nsCOMArray<nsWifiAccessPoint>& a,
77
nsCOMArray<nsWifiAccessPoint>& b);
78
79
#endif