Chromium Code Reviews| 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..576246e943a245f0dc90b9c98c87e997a2f43288 100644 |
| --- a/components/wifi/wifi_service_mac.mm |
| +++ b/components/wifi/wifi_service_mac.mm |
| @@ -18,6 +18,54 @@ |
| #include "components/onc/onc_constants.h" |
| #include "components/wifi/network_properties.h" |
| +// 10.6 SDK don't have CWSecurity while 10.9 SDK don't have CWSecurityMode, to |
| +// build with SDKs from 10.6 to 10.9 we need to forward declare both and do |
| +// runtime checks to ensure we use correct methods on different OS X versions. |
| +#if !defined(MAC_OS_X_VERSION_10_9) || \ |
|
Robert Sesek
2014/09/04 15:13:30
Move these to base/mac/sdk_forward_declarations.h.
Jiang Jiang
2014/09/04 15:17:49
Done.
|
| + MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_9 |
| + |
| +enum { |
| + kCWSecurityNone = 0, |
| + kCWSecurityWEP = 1, |
| + kCWSecurityWPAPersonal = 2, |
| + kCWSecurityWPAPersonalMixed = 3, |
| + kCWSecurityWPA2Personal = 4, |
| + kCWSecurityPersonal = 5, |
| + kCWSecurityDynamicWEP = 6, |
| + kCWSecurityWPAEnterprise = 7, |
| + kCWSecurityWPAEnterpriseMixed = 8, |
| + kCWSecurityWPA2Enterprise = 9, |
| + kCWSecurityEnterprise = 10, |
| + kCWSecurityUnknown = NSIntegerMax, |
| +}; |
| + |
| +typedef NSInteger CWSecurity; |
| + |
| +@interface CWNetwork (ForwardDeclarations) |
| +@property(readonly) NSInteger rssiValue; |
| +-(BOOL)supportsSecurity:(CWSecurity)security; |
|
Robert Sesek
2014/09/04 15:13:30
nit: space before (
Jiang Jiang
2014/09/04 15:17:49
Done.
|
| +@end |
| + |
| +#else |
| + |
| +typedef enum { |
| + kCWSecurityModeOpen = 0, |
| + kCWSecurityModeWEP, |
| + kCWSecurityModeWPA_PSK, |
| + kCWSecurityModeWPA2_PSK, |
| + kCWSecurityModeWPA_Enterprise, |
| + kCWSecurityModeWPA2_Enterprise, |
| + kCWSecurityModeWPS, |
| + kCWSecurityModeDynamicWEP |
| +} CWSecurityMode; |
| + |
| +@interface CWNetwork (ForwardDeclarations) |
| +@property(readonly) NSNumber* rssi; |
| +@property(readonly) NSNumber* securityMode; |
| +@end |
| + |
| +#endif |
| + |
| namespace wifi { |
| // Implementation of WiFiService for Mac OS X. |
| @@ -100,6 +148,9 @@ class WiFiServiceMac : public WiFiService { |
| // Converts |CWSecurityMode| into onc::wifi::k{WPA|WEP}* security constant. |
| std::string SecurityFromCWSecurityMode(CWSecurityMode security) const; |
| + // Converts |CWSecurity| into onc::wifi::k{WPA|WEP}* security constant. |
| + std::string SecurityFromCWNetwork(const CWNetwork* network) const; |
| + |
| // Converts |CWChannelBand| into Frequency constant. |
| Frequency FrequencyFromCWChannelBand(CWChannelBand band) const; |
| @@ -401,7 +452,7 @@ void WiFiServiceMac::SetEventObservers( |
| }; |
| wlan_observer_ = [[NSNotificationCenter defaultCenter] |
| - addObserverForName:kCWSSIDDidChangeNotification |
| + addObserverForName:CWSSIDDidChangeNotification |
| object:nil |
| queue:nil |
| usingBlock:ns_observer]; |
| @@ -505,10 +556,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:)]) |
|
Robert Sesek
2014/09/04 15:13:30
nit: since the else has curly braces, the if body
Jiang Jiang
2014/09/04 15:17:49
Done.
|
| + 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 +591,29 @@ std::string WiFiServiceMac::SecurityFromCWSecurityMode( |
| return onc::wifi::kWPA_EAP; |
| } |
| +std::string WiFiServiceMac::SecurityFromCWNetwork( |
| + const CWNetwork* network) const { |
| + if ([network supportsSecurity:kCWSecurityWPAEnterprise] || |
| + [network supportsSecurity:kCWSecurityWPA2Enterprise]) |
|
Robert Sesek
2014/09/04 15:13:30
nit: braces needed since condition is multi-line,
Jiang Jiang
2014/09/04 15:17:49
Done.
|
| + 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; |
| } |