Index: components/wifi/wifi_service_mac.mm |
diff --git a/components/wifi/wifi_service_mac.mm b/components/wifi/wifi_service_mac.mm |
index 65414371277ce19900fe014def4681b8e45b8d44..b51bca43ccf7cfc2a1eae7c573753259837ca567 100644 |
--- a/components/wifi/wifi_service_mac.mm |
+++ b/components/wifi/wifi_service_mac.mm |
@@ -4,6 +4,7 @@ |
#include "components/wifi/wifi_service.h" |
+#include <dlfcn.h> |
#import <netinet/in.h> |
#import <CoreWLAN/CoreWLAN.h> |
#import <SystemConfiguration/SystemConfiguration.h> |
@@ -100,6 +101,10 @@ class WiFiServiceMac : public WiFiService { |
// Converts |CWSecurityMode| into onc::wifi::k{WPA|WEP}* security constant. |
std::string SecurityFromCWSecurityMode(CWSecurityMode security) const; |
+ // Returns onc::wifi::k{WPA|WEP}* security constant supported by the |
+ // |CWNetwork|. |
+ std::string SecurityFromCWNetwork(const CWNetwork* network) const; |
+ |
// Converts |CWChannelBand| into Frequency constant. |
Frequency FrequencyFromCWChannelBand(CWChannelBand band) const; |
@@ -400,8 +405,23 @@ void WiFiServiceMac::SetEventObservers( |
base::Unretained(this))); |
}; |
+ NSBundle* bundle = [NSBundle |
mef
2014/09/05 17:56:22
If anything I'd move this out into separate method
|
+ bundleWithPath:@"/System/Library/Frameworks/CoreWLAN.framework"]; |
+ const char* path = [[bundle executablePath] fileSystemRepresentation]; |
+ CHECK(path); |
+ void* library_handle = dlopen(path, RTLD_LAZY | RTLD_LOCAL); |
+ CHECK(library_handle) << dlerror(); |
+ |
+ // Try out the symbol name for 10.7+ first, if not found use the one from |
+ // 10.6 SDK. |
+ void* symbol = dlsym(library_handle, "CWSSIDDidChangeNotification"); |
+ if (!symbol) |
+ symbol = dlsym(library_handle, "kCWSSIDDidChangeNotification"); |
mef
2014/09/05 17:56:23
Is kCWSSIDDidChangeNotification actually causing i
|
+ CHECK(symbol) << dlerror(); |
+ NSString* notification_name = *reinterpret_cast<NSString**>(symbol); |
+ |
wlan_observer_ = [[NSNotificationCenter defaultCenter] |
- addObserverForName:kCWSSIDDidChangeNotification |
+ addObserverForName:notification_name |
object:nil |
queue:nil |
usingBlock:ns_observer]; |
@@ -505,10 +525,18 @@ void WiFiServiceMac::NetworkPropertiesFromCWNetwork( |
properties->frequency = FrequencyFromCWChannelBand( |
static_cast<CWChannelBand>([[network wlanChannel] channelBand])); |
properties->frequency_set.insert(properties->frequency); |
- properties->security = SecurityFromCWSecurityMode( |
- static_cast<CWSecurityMode>([[network securityMode] intValue])); |
- properties->signal_strength = [[network rssi] intValue]; |
+ if ([network respondsToSelector:@selector(supportsSecurity:)]) { |
+ properties->security = SecurityFromCWNetwork(network); |
+ } else { |
+ properties->security = SecurityFromCWSecurityMode( |
+ static_cast<CWSecurityMode>([[network securityMode] intValue])); |
+ } |
+ |
+ if ([network respondsToSelector:@selector(rssiValue:)]) |
+ properties->signal_strength = [network rssiValue]; |
+ else |
+ properties->signal_strength = [[network rssi] intValue]; |
} |
std::string WiFiServiceMac::SecurityFromCWSecurityMode( |
@@ -532,6 +560,31 @@ std::string WiFiServiceMac::SecurityFromCWSecurityMode( |
return onc::wifi::kWPA_EAP; |
} |
+std::string WiFiServiceMac::SecurityFromCWNetwork( |
+ const CWNetwork* network) const { |
+ if ([network supportsSecurity:kCWSecurityWPAEnterprise] || |
+ [network supportsSecurity:kCWSecurityWPA2Enterprise]) { |
+ return onc::wifi::kWPA_EAP; |
+ } |
+ |
+ if ([network supportsSecurity:kCWSecurityWPAPersonal] || |
+ [network supportsSecurity:kCWSecurityWPA2Personal]) { |
+ return onc::wifi::kWPA_PSK; |
+ } |
+ |
+ if ([network supportsSecurity:kCWSecurityWEP]) |
+ return onc::wifi::kWEP_PSK; |
+ |
+ if ([network supportsSecurity:kCWSecurityNone]) |
+ return onc::wifi::kSecurityNone; |
+ |
+ // TODO(mef): Figure out correct mapping. |
+ if ([network supportsSecurity:kCWSecurityDynamicWEP]) |
+ return onc::wifi::kWPA_EAP; |
+ |
+ return onc::wifi::kWPA_EAP; |
+} |
+ |
Frequency WiFiServiceMac::FrequencyFromCWChannelBand(CWChannelBand band) const { |
return band == kCWChannelBand2GHz ? kFrequency2400 : kFrequency5000; |
} |