/src/mozilla-central/netwerk/wifi/nsWifiAccessPoint.h
Line | Count | Source (jump to first uncovered line) |
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() = default; |
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 | | void setSignal(int signal) |
34 | 0 | { |
35 | 0 | mSignal = signal; |
36 | 0 | } |
37 | | |
38 | | void setMacRaw(const char* aString) |
39 | 0 | { |
40 | 0 | memcpy(mMac, aString, mozilla::ArrayLength(mMac)); |
41 | 0 | } |
42 | | |
43 | | void setMac(const unsigned char mac_as_int[6]) |
44 | 0 | { |
45 | 0 | // mac_as_int is big-endian. Write in byte chunks. |
46 | 0 | // Format is XX-XX-XX-XX-XX-XX. |
47 | 0 |
|
48 | 0 | const unsigned char holder[6] = {0}; |
49 | 0 | if (!mac_as_int) { |
50 | 0 | mac_as_int = holder; |
51 | 0 | } |
52 | 0 |
|
53 | 0 | static const char *kMacFormatString = ("%02x-%02x-%02x-%02x-%02x-%02x"); |
54 | 0 |
|
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 | 0 |
|
59 | 0 | mMac[17] = 0; |
60 | 0 | } |
61 | | |
62 | 0 | void setSSIDRaw(const char* aSSID, size_t len) { |
63 | 0 | mSsidLen = std::min(len, mozilla::ArrayLength(mSsid)); |
64 | 0 | memcpy(mSsid, aSSID, mSsidLen); |
65 | 0 | } |
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 | 0 | } |
73 | 0 | else |
74 | 0 | { |
75 | 0 | mSsid[0] = 0; |
76 | 0 | mSsidLen = 0; |
77 | 0 | } |
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 |