Bug 654725 - Changes in OS X 10.7 break our Wi-Fi monitor code, causing crashes. r=josh
authorSteven Michaud <smichaud@pobox.com>
Tue, 10 May 2011 14:44:17 -0500
changeset 69271 fbe2374e7ea036cf0fde97a43c2e603cc8a472ac
parent 69270 aa889d945ef9a97fdb2451f4c8f370944a9da731
child 69272 ead4ec7de0325c44e416b28cfcc1c090fd1e72b4
push idunknown
push userunknown
push dateunknown
reviewersjosh
bugs654725
milestone6.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 654725 - Changes in OS X 10.7 break our Wi-Fi monitor code, causing crashes. r=josh
netwerk/wifi/nsWifiAccessPoint.h
netwerk/wifi/osx_corewlan.mm
--- a/netwerk/wifi/nsWifiAccessPoint.h
+++ b/netwerk/wifi/nsWifiAccessPoint.h
@@ -65,27 +65,32 @@ public:
     mSignal = signal;
   };
 
   void setMac(const unsigned char mac_as_int[6])
   {
     // mac_as_int is big-endian. Write in byte chunks.
     // Format is XX-XX-XX-XX-XX-XX.
 
+    const unsigned char holder[6] = {0};
+    if (!mac_as_int) {
+      mac_as_int = holder;
+    }
+
     static const char *kMacFormatString = ("%02x-%02x-%02x-%02x-%02x-%02x");
 
     sprintf(mMac, kMacFormatString,
             mac_as_int[0], mac_as_int[1], mac_as_int[2],
             mac_as_int[3], mac_as_int[4], mac_as_int[5]);
 
     mMac[17] = 0;
   };
 
   void setSSID(const char* aSSID, unsigned long len) {
-    if (len < sizeof(mSsid)) {
+    if (aSSID && (len < sizeof(mSsid))) {
         strncpy(mSsid, aSSID, len);
         mSsid[len] = 0;
         mSsidLen = len;
     }
     else
     {
       mSsid[0] = 0;
       mSsidLen = 0;
--- a/netwerk/wifi/osx_corewlan.mm
+++ b/netwerk/wifi/osx_corewlan.mm
@@ -92,19 +92,47 @@ GetAccessPointsFromWLAN(nsCOMArray<nsWif
     NSEnumerator *enumerator = [scan objectEnumerator];
 
     while (id anObject = [enumerator nextObject]) {
       nsWifiAccessPoint* ap = new nsWifiAccessPoint();
       if (!ap) {
         [pool release];
         return NS_ERROR_OUT_OF_MEMORY;
       }
-      NSData* data = [anObject bssidData];
-      ap->setMac((unsigned char*)[data bytes]);
-      ap->setSignal([[anObject rssi] intValue]);
+
+      // [CWInterface bssidData] is deprecated on OS X 10.7 and up.  Which is
+      // is a pain, so we'll use it for as long as it's available.
+      unsigned char macData[6] = {0};
+      if ([anObject respondsToSelector:@selector(bssidData)]) {
+        NSData* data = [anObject bssidData];
+        if (data) {
+          memcpy(macData, [data bytes], 6);
+        }
+      } else {
+        // [CWInterface bssid] returns a string formatted "00:00:00:00:00:00".
+        NSString* macString = [anObject bssid];
+        if (macString && ([macString length] == 17)) {
+          for (NSUInteger i = 0; i < 6; ++i) {
+            NSString* part = [macString substringWithRange:NSMakeRange(i * 3, 2)];
+            macData[i] = (unsigned char) [part integerValue];
+          }
+        }
+      }
+
+      // [CWInterface rssiValue] is available on OS X 10.7 and up (and
+      // [CWInterface rssi] is deprecated).
+      int signal = 0;
+      if ([anObject respondsToSelector:@selector(rssiValue)]) {
+        signal = (int) ((NSInteger) [anObject rssiValue]);
+      } else {
+        signal = [[anObject rssi] intValue];
+      }
+
+      ap->setMac(macData);
+      ap->setSignal(signal);
       ap->setSSID([[anObject ssid] UTF8String], 32);
 
       accessPoints.AppendObject(ap);
     }
   }
   @catch(NSException *_exn) {
     [pool release];
     return NS_ERROR_NOT_AVAILABLE;