Commit 6acb5759 authored by jiangj's avatar jiangj Committed by Commit bot

Fix wifi_component build with 10.9+ SDK

Use forward declaration to build on both 10.6 and 10.9 SDK and
runtime checking to make sure we don't call the wrong API.

BUG=390212

Review URL: https://codereview.chromium.org/530193004

Cr-Commit-Position: refs/heads/master@{#293911}
parent cc587db8
...@@ -257,6 +257,51 @@ typedef NSUInteger NSWindowOcclusionState; ...@@ -257,6 +257,51 @@ typedef NSUInteger NSWindowOcclusionState;
- (NSWindowOcclusionState)occlusionState; - (NSWindowOcclusionState)occlusionState;
@end @end
// 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 both need to be forward declared and use
// runtime checks to ensure correct methods are used on different OS X versions.
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 (MavericksSDK)
@property(readonly) NSInteger rssiValue;
- (BOOL)supportsSecurity:(CWSecurity)security;
@end
#else // !MAC_OS_X_VERSION_10_9
typedef enum {
kCWSecurityModeOpen = 0,
kCWSecurityModeWEP,
kCWSecurityModeWPA_PSK,
kCWSecurityModeWPA2_PSK,
kCWSecurityModeWPA_Enterprise,
kCWSecurityModeWPA2_Enterprise,
kCWSecurityModeWPS,
kCWSecurityModeDynamicWEP
} CWSecurityMode;
@interface CWNetwork (SnowLeopardSDK)
@property(readonly) NSNumber* rssi;
@property(readonly) NSNumber* securityMode;
@end
BASE_EXPORT extern "C" NSString* const kCWSSIDDidChangeNotification;
#endif // MAC_OS_X_VERSION_10_9 #endif // MAC_OS_X_VERSION_10_9
#if !defined(MAC_OS_X_VERSION_10_10) || \ #if !defined(MAC_OS_X_VERSION_10_10) || \
......
...@@ -100,6 +100,10 @@ class WiFiServiceMac : public WiFiService { ...@@ -100,6 +100,10 @@ class WiFiServiceMac : public WiFiService {
// Converts |CWSecurityMode| into onc::wifi::k{WPA|WEP}* security constant. // Converts |CWSecurityMode| into onc::wifi::k{WPA|WEP}* security constant.
std::string SecurityFromCWSecurityMode(CWSecurityMode security) const; 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. // Converts |CWChannelBand| into Frequency constant.
Frequency FrequencyFromCWChannelBand(CWChannelBand band) const; Frequency FrequencyFromCWChannelBand(CWChannelBand band) const;
...@@ -505,9 +509,25 @@ void WiFiServiceMac::NetworkPropertiesFromCWNetwork( ...@@ -505,9 +509,25 @@ void WiFiServiceMac::NetworkPropertiesFromCWNetwork(
properties->frequency = FrequencyFromCWChannelBand( properties->frequency = FrequencyFromCWChannelBand(
static_cast<CWChannelBand>([[network wlanChannel] channelBand])); static_cast<CWChannelBand>([[network wlanChannel] channelBand]));
properties->frequency_set.insert(properties->frequency); properties->frequency_set.insert(properties->frequency);
// -[CWNetwork supportsSecurity:] is available from 10.7 SDK while
// -[CWNetwork securityMode] is deprecated and hidden as private since
// 10.9 SDK. The latter is kept for now to support running on 10.6. It
// should be removed when 10.6 support is dropped.
if ([network respondsToSelector:@selector(supportsSecurity:)]) {
properties->security = SecurityFromCWNetwork(network);
} else {
properties->security = SecurityFromCWSecurityMode( properties->security = SecurityFromCWSecurityMode(
static_cast<CWSecurityMode>([[network securityMode] intValue])); static_cast<CWSecurityMode>([[network securityMode] intValue]));
}
// rssiValue property of CWNetwork is available from 10.7 SDK while
// -[CWNetwork rssi] is deprecated and hidden as private since 10.9 SDK.
// The latter is kept for now to support running on 10.6. It should be
// removed when 10.6 support is dropped.
if ([network respondsToSelector:@selector(rssiValue)])
properties->signal_strength = [network rssiValue];
else
properties->signal_strength = [[network rssi] intValue]; properties->signal_strength = [[network rssi] intValue];
} }
...@@ -532,6 +552,31 @@ std::string WiFiServiceMac::SecurityFromCWSecurityMode( ...@@ -532,6 +552,31 @@ std::string WiFiServiceMac::SecurityFromCWSecurityMode(
return onc::wifi::kWPA_EAP; 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 { Frequency WiFiServiceMac::FrequencyFromCWChannelBand(CWChannelBand band) const {
return band == kCWChannelBand2GHz ? kFrequency2400 : kFrequency5000; return band == kCWChannelBand2GHz ? kFrequency2400 : kFrequency5000;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment