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