Line data Source code
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 : {
20 : ~nsWifiAccessPoint();
21 :
22 : public:
23 : NS_DECL_THREADSAFE_ISUPPORTS
24 : NS_DECL_NSIWIFIACCESSPOINT
25 :
26 : nsWifiAccessPoint();
27 :
28 : char mMac[18];
29 : int mSignal;
30 : char mSsid[33];
31 : int mSsidLen;
32 :
33 0 : void setSignal(int signal)
34 : {
35 0 : mSignal = signal;
36 0 : }
37 :
38 : void setMacRaw(const char* aString)
39 : {
40 : memcpy(mMac, aString, mozilla::ArrayLength(mMac));
41 : }
42 :
43 0 : void setMac(const unsigned char mac_as_int[6])
44 : {
45 : // mac_as_int is big-endian. Write in byte chunks.
46 : // Format is XX-XX-XX-XX-XX-XX.
47 :
48 0 : const unsigned char holder[6] = {0};
49 0 : if (!mac_as_int) {
50 0 : mac_as_int = holder;
51 : }
52 :
53 : static const char *kMacFormatString = ("%02x-%02x-%02x-%02x-%02x-%02x");
54 :
55 0 : SprintfLiteral(mMac, kMacFormatString,
56 0 : mac_as_int[0], mac_as_int[1], mac_as_int[2],
57 0 : mac_as_int[3], mac_as_int[4], mac_as_int[5]);
58 :
59 0 : mMac[17] = 0;
60 0 : }
61 :
62 : void setSSIDRaw(const char* aSSID, size_t len) {
63 : mSsidLen = std::min(len, mozilla::ArrayLength(mSsid));
64 : memcpy(mSsid, aSSID, mSsidLen);
65 : }
66 :
67 0 : void setSSID(const char* aSSID, unsigned long len) {
68 0 : if (aSSID && (len < sizeof(mSsid))) {
69 0 : strncpy(mSsid, aSSID, len);
70 0 : mSsid[len] = 0;
71 0 : mSsidLen = len;
72 : }
73 : else
74 : {
75 0 : mSsid[0] = 0;
76 0 : mSsidLen = 0;
77 : }
78 0 : }
79 : };
80 :
81 : // Helper functions
82 :
83 : bool AccessPointsEqual(nsCOMArray<nsWifiAccessPoint>& a, nsCOMArray<nsWifiAccessPoint>& b);
84 : void ReplaceArray(nsCOMArray<nsWifiAccessPoint>& a, nsCOMArray<nsWifiAccessPoint>& b);
85 :
86 : #endif
|