netwerk/wifi/nsWifiAccessPoint.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     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/. */
     5 #include "nsWifiMonitor.h"
     6 #include "nsIWifiAccessPoint.h"
     8 #include "nsString.h"
     9 #include "nsCOMArray.h"
    10 #include "mozilla/ArrayUtils.h" // ArrayLength
    11 #include "mozilla/Attributes.h"
    13 #ifndef __nsWifiAccessPoint__
    14 #define __nsWifiAccessPoint__
    16 class nsWifiAccessPoint MOZ_FINAL : public nsIWifiAccessPoint
    17 {
    18 public:
    19   NS_DECL_THREADSAFE_ISUPPORTS
    20   NS_DECL_NSIWIFIACCESSPOINT
    22   nsWifiAccessPoint();
    23   ~nsWifiAccessPoint();
    25   char mMac[18];
    26   int  mSignal;
    27   char mSsid[33];
    28   int  mSsidLen;
    30   void setSignal(int signal)
    31   {
    32     mSignal = signal;
    33   }
    35   void setMacRaw(const char* aString)
    36   {
    37     memcpy(mMac, aString, mozilla::ArrayLength(mMac));
    38   }
    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.
    45     const unsigned char holder[6] = {0};
    46     if (!mac_as_int) {
    47       mac_as_int = holder;
    48     }
    50     static const char *kMacFormatString = ("%02x-%02x-%02x-%02x-%02x-%02x");
    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]);
    56     mMac[17] = 0;
    57   }
    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   }
    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 };
    80 // Helper functions
    82 bool AccessPointsEqual(nsCOMArray<nsWifiAccessPoint>& a, nsCOMArray<nsWifiAccessPoint>& b);
    83 void ReplaceArray(nsCOMArray<nsWifiAccessPoint>& a, nsCOMArray<nsWifiAccessPoint>& b);
    86 #endif

mercurial