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