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 |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..3536eddd47a5749a0e946c26ace72c8329186a84 |
| --- /dev/null |
| +++ b/components/wifi/wifi_service_mac.mm |
| @@ -0,0 +1,612 @@ |
| +// Copyright 2013 The Chromium Authors. All rights reserved. |
|
tbarzic
2014/01/08 23:06:23
the copyright header is out of date :P
mef
2014/01/09 22:41:46
Done.
|
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "components/wifi/wifi_service.h" |
| + |
| +#import <netinet/in.h> |
| +#import <CoreWLAN/CoreWLAN.h> |
| +#import <SystemConfiguration/SystemConfiguration.h> |
| + |
| +#include "base/bind.h" |
| +#include "base/mac/scoped_cftyperef.h" |
| +#include "base/mac/scoped_nsautorelease_pool.h" |
| +#include "base/mac/scoped_nsobject.h" |
| +#include "base/message_loop/message_loop.h" |
| +#include "base/strings/sys_string_conversions.h" |
| +#include "components/onc/onc_constants.h" |
| + |
| +namespace { |
| +// Declare notification names from the 10.7 SDK. |
| +const char* kCWSSIDDidChangeNotification_chrome = |
| + "com.apple.coreWLAN.notification.ssid"; |
| +} // namespace |
| + |
| +#if !defined(MAC_OS_X_VERSION_10_7) || \ |
| + MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 |
| + |
| +// Local definitions of API added in Mac OS X 10.7 |
| + |
| +@interface CWInterface (LionAPI) |
| +- (BOOL)associateToNetwork:(CWNetwork*)network |
| + password:(NSString*)password |
| + error:(NSError**)error; |
| +- (NSSet*)scanForNetworksWithName:(NSString*)networkName |
| + error:(NSError**)error; |
| +@end |
| + |
| +enum CWChannelBand { |
| + kCWChannelBandUnknown = 0, |
| + kCWChannelBand2GHz = 1, |
| + kCWChannelBand5GHz = 2, |
| +}; |
| + |
| +@interface CWChannel : NSObject |
| +@property(readonly) CWChannelBand channelBand; |
| +@end |
| + |
| +@interface CWNetwork (LionAPI) |
| +@property(readonly) CWChannel* wlanChannel; |
| +@end |
| + |
| +#endif // 10.7 |
| + |
| +namespace wifi { |
| + |
| +const char kErrorAssociateToNetwork[] = "Error.AssociateToNetwork"; |
| +const char kErrorGetProperties[] = "Error.GetProperties"; |
| +const char kErrorNotConnected[] = "Error.NotConnected"; |
| +const char kErrorNotFound[] = "Error.NotFound"; |
| +const char kErrorNotImplemented[] = "Error.NotImplemented"; |
| +const char kErrorScanForNetworksWithName[] = "Error.ScanForNetworksWithName"; |
| + |
| +// Implementation of WiFiService for Mac OS X. |
| +class WiFiServiceMac : public WiFiService { |
| + public: |
| + WiFiServiceMac(); |
| + virtual ~WiFiServiceMac(); |
| + |
| + // WiFiService interface implementation. |
| + virtual void Initialize( |
| + scoped_refptr<base::SequencedTaskRunner> task_runner) OVERRIDE; |
| + |
| + virtual void UnInitialize() OVERRIDE; |
| + |
| + virtual void GetProperties(const std::string& network_guid, |
| + base::DictionaryValue* properties, |
| + std::string* error) OVERRIDE; |
| + |
| + virtual void GetManagedProperties(const std::string& network_guid, |
| + base::DictionaryValue* managed_properties, |
| + std::string* error) OVERRIDE; |
| + |
| + virtual void GetState(const std::string& network_guid, |
| + base::DictionaryValue* properties, |
| + std::string* error) OVERRIDE; |
| + |
| + virtual void SetProperties(const std::string& network_guid, |
| + scoped_ptr<base::DictionaryValue> properties, |
| + std::string* error) OVERRIDE; |
| + |
| + virtual void CreateNetwork(bool shared, |
| + scoped_ptr<base::DictionaryValue> properties, |
| + std::string* network_guid, |
| + std::string* error) OVERRIDE; |
| + |
| + virtual void GetVisibleNetworks(const std::string& network_type, |
| + base::ListValue* network_list) OVERRIDE; |
| + |
| + virtual void RequestNetworkScan() OVERRIDE; |
| + |
| + virtual void StartConnect(const std::string& network_guid, |
| + std::string* error) OVERRIDE; |
| + |
| + virtual void StartDisconnect(const std::string& network_guid, |
| + std::string* error) OVERRIDE; |
| + |
| + virtual void SetEventObservers( |
| + scoped_refptr<base::MessageLoopProxy> message_loop_proxy, |
| + const NetworkGuidListCallback& networks_changed_observer, |
| + const NetworkGuidListCallback& network_list_changed_observer) OVERRIDE; |
| + |
| + private: |
| + // Check |ns_error| and if is not |nil|, then store |error_name| |
| + // into |error|. |
| + bool CheckError(NSError* ns_error, |
| + const char* error_name, |
| + std::string* error) const; |
| + |
| + // Get |ssid| from unique |network_guid|. |
| + NSString* SSIDFromGUID(const std::string& network_guid) const { |
| + return base::SysUTF8ToNSString(network_guid); |
| + } |
| + |
| + // Get unique |network_guid| string based on |ssid|. |
| + std::string GUIDFromSSID(NSString* ssid) const { |
| + return base::SysNSStringToUTF8(ssid); |
| + } |
| + |
| + // Populate |properties| from |network|. |
| + void NetworkPropertiesFromCWNetwork(const CWNetwork* network, |
| + NetworkProperties* properties) const; |
| + |
| + // Convert |CWSecurityMode| into onc::wifi::k{WPA|WEP}* security constant. |
| + std::string SecurityFromCWSecurityMode(CWSecurityMode security) const; |
| + |
| + // Wait up to |kMaxAttempts| with |kAttemptDelayMs| delay for connection |
| + // to network with |network_guid|. Notify that |NetworkChanged| upon success. |
| + void WaitForNetworkConnect(const std::string& network_guid, int attempt); |
| + |
| + // Get the list of visible wireless networks. If |network_guid| is not empty, |
| + // then only return that network. |
| + NSError* GetVisibleNetworkList(const std::string& network_guid, |
| + NetworkList* network_list); |
| + |
| + // Handle notification from |wlan_observer_|; |
|
tbarzic
2014/01/08 23:06:23
end comment with . instead of ;
Here and througho
mef
2014/01/09 22:41:46
Done.
|
| + void OnWlanObserverNotification(); |
| + |
| + // Notify |network_list_changed_observer_| that list of visible networks has |
| + // changed to |networks|. |
| + void NotifyNetworkListChanged(const NetworkList& networks); |
| + |
| + // Notify |networks_changed_observer_| that network |network_guid| status has |
| + // changed. |
| + void NotifyNetworkChanged(const std::string& network_guid); |
| + |
| + // CoreWLAN.Framework bundle. |
| + base::scoped_nsobject<NSBundle> bundle_; |
| + // Default interface. |
| + base::scoped_nsobject<CWInterface> interface_; |
| + // WLAN Notifications observer. |
| + base::scoped_nsobject<NSObject> wlan_observer_; |
| + |
| + // Observer to get notified when network(s) have changed (e.g. connect). |
| + NetworkGuidListCallback networks_changed_observer_; |
| + // Observer to get notified when network list has changed (scan complete). |
| + NetworkGuidListCallback network_list_changed_observer_; |
| + // MessageLoopProxy to post events on UI thread. |
| + scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; |
| + // Task runner for worker tasks. |
| + scoped_refptr<base::SequencedTaskRunner> task_runner_; |
| + // Cache of network list collected by GetVisibleNetworks. |
| + NetworkList networks_; |
| + // Temporary storage of network properties indexed by |network_guid|. |
| + base::DictionaryValue network_properties_; |
| + // If |false|, then |networks_changed_observer_| is not notified. |
| + bool enable_notify_network_changed_; |
| + // Number of attempts to check that network has connected successfully. |
| + static const int kConnectionCheckMaxAttempts = 200; |
| + // Delay between attempts to check that network has connected successfully. |
| + static const int kConnectionCheckAttemptDelayMs = 100; |
| +}; |
| + |
| +WiFiServiceMac::WiFiServiceMac() : enable_notify_network_changed_(true) { |
| +} |
| + |
| +WiFiServiceMac::~WiFiServiceMac() { |
| +} |
| + |
| +void WiFiServiceMac::Initialize( |
| + scoped_refptr<base::SequencedTaskRunner> task_runner) { |
| + // As the WLAN api binding runs on its own thread, we need to provide our own |
| + // auto release pool. It's simplest to do this as an automatic variable in |
| + // each method that needs it, to ensure the scoping is correct and does not |
| + // interfere with any other code using autorelease pools on the thread. |
| + base::mac::ScopedNSAutoreleasePool auto_pool; |
| + |
| + task_runner_.swap(task_runner); |
| + |
| + bundle_.reset([[NSBundle alloc] |
| + initWithPath:@"/System/Library/Frameworks/CoreWLAN.framework"]); |
| + if (!bundle_) { |
| + DVLOG(1) << "Failed to load the CoreWLAN framework bundle"; |
| + return; |
| + } |
| + |
| + Class cw_interface_class = [bundle_ classNamed:@"CWInterface"]; |
| + interface_.reset([[cw_interface_class interface] retain]); |
| + if (!bundle_) { |
| + DVLOG(1) << "Failed to initialize default interface"; |
| + return; |
| + } |
| + |
| +} |
| + |
| +void WiFiServiceMac::UnInitialize() { |
| + [[NSNotificationCenter defaultCenter] removeObserver:wlan_observer_]; |
| +} |
| + |
| +void WiFiServiceMac::GetProperties(const std::string& network_guid, |
| + base::DictionaryValue* properties, |
| + std::string* error) { |
| + base::mac::ScopedNSAutoreleasePool auto_pool; |
| + |
| + if (networks_.empty()) { |
|
tbarzic
2014/01/08 23:06:23
I don't think this block is needed (at least if Re
mef
2014/01/09 22:41:46
Done.
|
| + DVLOG(1) << "GetProperties"; |
| + NSError* ns_error = GetVisibleNetworkList(std::string(), &networks_); |
| + if (CheckError(ns_error, kErrorGetProperties, error)) |
| + return; |
| + } |
| + |
| + for (WiFiService::NetworkList::iterator it = networks_.begin(); |
| + it != networks_.end(); |
| + ++it) { |
| + if (it->guid == network_guid) { |
|
tbarzic
2014/01/08 23:06:23
the network's properties should probably be rescan
mef
2014/01/09 22:41:46
Done.
|
| + bool is_connected = network_guid == GUIDFromSSID([interface_ ssid]); |
| + it->connection_state = |
| + is_connected ? onc::connection_state::kConnected : |
| + onc::connection_state::kNotConnected; |
| + scoped_ptr<base::DictionaryValue> network(it->ToValue(false)); |
| + properties->Swap(network.get()); |
| + DVLOG(1) << *properties; |
| + return; |
| + } |
| + } |
| + |
| + *error = kErrorNotFound; |
| +} |
| + |
| +void WiFiServiceMac::GetManagedProperties( |
| + const std::string& network_guid, |
| + base::DictionaryValue* managed_properties, |
| + std::string* error) { |
| + *error = kErrorNotImplemented; |
| +} |
| + |
| +void WiFiServiceMac::GetState(const std::string& network_guid, |
| + base::DictionaryValue* properties, |
| + std::string* error) { |
| + *error = kErrorNotImplemented; |
| +} |
| + |
| +void WiFiServiceMac::SetProperties( |
| + const std::string& network_guid, |
| + scoped_ptr<base::DictionaryValue> properties, |
| + std::string* error) { |
| + base::mac::ScopedNSAutoreleasePool auto_pool; |
| + network_properties_.SetWithoutPathExpansion(network_guid, |
| + properties.release()); |
| +} |
| + |
| +void WiFiServiceMac::CreateNetwork( |
| + bool shared, |
| + scoped_ptr<base::DictionaryValue> properties, |
| + std::string* network_guid, |
| + std::string* error) { |
| + *error = kErrorNotImplemented; |
| +} |
| + |
| +void WiFiServiceMac::GetVisibleNetworks(const std::string& network_type, |
| + base::ListValue* network_list) { |
| + if (!network_type.empty() && |
| + network_type != onc::network_type::kAllTypes && |
| + network_type != onc::network_type::kWiFi) { |
| + return; |
| + } |
| + |
| + base::mac::ScopedNSAutoreleasePool auto_pool; |
| + |
| + GetVisibleNetworkList(std::string(), &networks_); |
| + |
| + // Sort networks, so connected/connecting is up front. |
| + networks_.sort(NetworkProperties::OrderByType); |
| + |
| + for (WiFiService::NetworkList::const_iterator it = networks_.begin(); |
| + it != networks_.end(); |
| + ++it) { |
| + scoped_ptr<base::DictionaryValue> network(it->ToValue(true)); |
| + network_list->Append(network.release()); |
| + } |
| +} |
| + |
| +void WiFiServiceMac::RequestNetworkScan() { |
| + base::mac::ScopedNSAutoreleasePool auto_pool; |
| + NetworkList networks; |
| + |
| + NSError* ns_error = GetVisibleNetworkList(std::string(), &networks); |
| + if (ns_error == nil && !networks.empty()) { |
| + NotifyNetworkListChanged(networks); |
| + } |
| +} |
| + |
| +void WiFiServiceMac::StartConnect(const std::string& network_guid, |
| + std::string* error) { |
| + base::mac::ScopedNSAutoreleasePool auto_pool; |
| + NSError* ns_error = nil; |
| + |
| + DVLOG(1) << "*** StartConnect: " << network_guid; |
| + // Remember previously connected network. |
| + std::string connected_network_guid = GUIDFromSSID([interface_ ssid]); |
| + // Check, whether desired network is already connected. |
| + if (network_guid == connected_network_guid) { |
| + NotifyNetworkChanged(connected_network_guid); |
| + return; |
| + } |
| + |
| + NSSet* networks = [interface_ |
| + scanForNetworksWithName:SSIDFromGUID(network_guid) |
| + error:&ns_error]; |
| + |
| + if (CheckError(ns_error, kErrorScanForNetworksWithName, error)) |
| + return; |
| + |
| + CWNetwork* network = [networks anyObject]; |
| + if (network == nil) { |
| + *error = kErrorNotFound; |
| + return; |
| + } |
| + |
| + // Check whether WiFi Password is set in |network_properties_| |
| + base::DictionaryValue* properties; |
| + base::DictionaryValue* wifi; |
| + std::string passphrase; |
| + NSString* ns_password = nil; |
| + if (network_properties_.GetDictionaryWithoutPathExpansion(network_guid, |
| + &properties) && |
| + properties->GetDictionary(onc::network_type::kWiFi, &wifi) && |
| + wifi->GetString(onc::wifi::kPassphrase, &passphrase)) { |
| + ns_password = base::SysUTF8ToNSString(passphrase); |
| + } |
| + |
| + // Disable automatic network change notifications as they get fired |
| + // when network is just connected, but not yet accessible (doesn't |
| + // have valid IP address). |
| + enable_notify_network_changed_ = false; |
| + // Number of attempts to associate to network. |
| + static const int kMaxAssociationAttempts = 3; |
| + // Try to associate to network several times if timeout or PMK error occurs. |
| + for (int i = 0; i < kMaxAssociationAttempts; ++i) { |
| + // Nil out the PMK to prevent stale data from causing invalid PMK error |
| + // (CoreWLANTypes -3924). |
| + [interface_ setPairwiseMasterKey:nil error:&ns_error]; |
| + if ([interface_ associateToNetwork:network |
| + password:ns_password |
| + error:&ns_error]) { |
| + // Notify that previously connected network has changed. |
| + NotifyNetworkChanged(connected_network_guid); |
| + |
| + // Start waiting for network connection state change. WaiForNetworkConnect |
| + // is async and it'll reset enable_notify_network_changed_. |
| + if (!networks_changed_observer_.is_null()) { |
| + WaitForNetworkConnect(network_guid, 0); |
| + return; |
| + } |
| + } else { |
| + NSInteger error_code = [ns_error code]; |
| + if (error_code != kCWTimeoutErr && error_code != kCWInvalidPMKErr) { |
| + break; |
| + } |
| + } |
| + } |
| + enable_notify_network_changed_ = true; |
| + CheckError(ns_error, kErrorAssociateToNetwork, error); |
| +} |
| + |
| +void WiFiServiceMac::StartDisconnect(const std::string& network_guid, |
| + std::string* error) { |
| + base::mac::ScopedNSAutoreleasePool auto_pool; |
| + DVLOG(1) << "*** StartDisconnect: " << network_guid; |
| + |
| + if (network_guid == GUIDFromSSID([interface_ ssid])) { |
| + [interface_ disassociate]; |
| + } else { |
| + *error = kErrorNotConnected; |
| + } |
| +} |
| + |
| +void WiFiServiceMac::SetEventObservers( |
| + scoped_refptr<base::MessageLoopProxy> message_loop_proxy, |
| + const NetworkGuidListCallback& networks_changed_observer, |
| + const NetworkGuidListCallback& network_list_changed_observer) { |
| + base::mac::ScopedNSAutoreleasePool auto_pool; |
| + message_loop_proxy_.swap(message_loop_proxy); |
| + networks_changed_observer_ = networks_changed_observer; |
| + network_list_changed_observer_ = network_list_changed_observer; |
| + |
| + // Subscribe to OS notifications. |
| + wlan_observer_.reset([[NSNotificationCenter defaultCenter] |
| + addObserverForName:base::SysUTF8ToNSString( |
| + kCWSSIDDidChangeNotification_chrome) |
| + object:nil |
| + queue:nil |
| + usingBlock:^(NSNotification* notification) { |
| + task_runner_->PostTask( |
| + FROM_HERE, |
| + base::Bind(&WiFiServiceMac::OnWlanObserverNotification, |
| + base::Unretained(this))); |
| + }]); |
| +} |
| + |
| +void WiFiServiceMac::WaitForNetworkConnect(const std::string& network_guid, |
| + int attempt) { |
| + // If network didn't get connected in |kMaxAttempts|, then restore automatic |
| + // network change notifications and stop waiting. |
| + if (attempt > kConnectionCheckMaxAttempts) { |
| + DLOG(ERROR) << kConnectionCheckMaxAttempts |
| + << " attempts exceeded waiting for connect to " |
| + << network_guid; |
| + // Restore previously suppressed notifications. |
| + enable_notify_network_changed_ = true; |
| + return; |
| + } |
| + |
| + // Check whether WiFi network is reachable. |
| + struct sockaddr_in local_wifi_address; |
| + bzero(&local_wifi_address, sizeof(local_wifi_address)); |
| + local_wifi_address.sin_len = sizeof(local_wifi_address); |
| + local_wifi_address.sin_family = AF_INET; |
| + local_wifi_address.sin_addr.s_addr = htonl(IN_LINKLOCALNETNUM); |
| + |
| + base::ScopedCFTypeRef<SCNetworkReachabilityRef> reachability( |
| + SCNetworkReachabilityCreateWithAddress( |
| + kCFAllocatorDefault, |
| + reinterpret_cast<const struct sockaddr*>(&local_wifi_address))); |
| + SCNetworkReachabilityFlags flags = 0u; |
| + if (SCNetworkReachabilityGetFlags(reachability, &flags) && |
| + (flags & kSCNetworkReachabilityFlagsReachable) && |
| + (flags & kSCNetworkReachabilityFlagsIsDirect)) { |
| + DVLOG(1) << "WiFi Connected, Reachable: " << network_guid; |
| + // Restore previously suppressed notifications. |
| + enable_notify_network_changed_ = true; |
| + NotifyNetworkChanged(network_guid); |
| + } else { |
| + DVLOG(1) << "Attempt:" << attempt << ", reachability:" << flags; |
| + // Continue waiting for network connection state change. |
| + task_runner_->PostDelayedTask( |
| + FROM_HERE, |
| + base::Bind(&WiFiServiceMac::WaitForNetworkConnect, |
| + base::Unretained(this), |
| + network_guid, |
| + ++attempt), |
| + base::TimeDelta::FromMilliseconds(kConnectionCheckAttemptDelayMs)); |
| + } |
| +} |
| + |
| + |
| +NSError* WiFiServiceMac::GetVisibleNetworkList(const std::string& network_guid, |
|
tbarzic
2014/01/08 23:06:23
Instead of returning network_list here, why don't
mef
2014/01/09 22:41:46
Done.
|
| + NetworkList* network_list) { |
| + |
| + NSError* ns_error = nil; |
| + NSString* network_name = nil; |
| + |
| + DVLOG(1) << "<<< GetVisibleNetworkList: " << network_guid; |
| + |
| + if (!network_guid.empty()) |
| + network_name = SSIDFromGUID(network_guid); |
| + |
| + NSSet* networks = [interface_ scanForNetworksWithName:network_name |
| + error:&ns_error]; |
| + if (ns_error != nil) |
| + return ns_error; |
| + |
| + std::map<std::string, NetworkProperties*> network_properties_map; |
| + |
| + CWNetwork* network; |
| + // There is one |network| per BSS in |networks|, so go through the set and |
| + // combine them, paying attention to supported frequencies. |
| + for (network in networks) { |
|
tbarzic
2014/01/08 23:06:23
should network_list be cleared before the loop?
mef
2014/01/09 22:41:46
Done.
|
| + NetworkProperties network_properties; |
| + NetworkPropertiesFromCWNetwork(network, &network_properties); |
| + |
| + if (network_properties_map.find(network_properties.guid) == |
| + network_properties_map.end()) { |
| + network_list->push_back(network_properties); |
| + network_properties_map[network_properties.guid] = &network_list->back(); |
| + } else { |
| + NetworkProperties* existing = network_properties_map.at( |
| + network_properties.guid); |
| + existing->frequency_set.insert(*network_properties.frequency_set.begin()); |
| + } |
| + } |
| + DVLOG(1) << ">>> GetVisibleNetworkList: " << network_guid; |
| + |
| + return nil; |
| +} |
| + |
| +bool WiFiServiceMac::CheckError(NSError* ns_error, |
| + const char* error_name, |
| + std::string* error) const { |
| + if (ns_error != nil) { |
| + DLOG(ERROR) << "*** Error:" << error_name << ":" << [ns_error code]; |
| + *error = error_name; |
| + return true; |
| + } |
| + return false; |
| +} |
| + |
| +void WiFiServiceMac::NetworkPropertiesFromCWNetwork( |
| + const CWNetwork* network, |
| + NetworkProperties* properties) const { |
| + |
| + if ([[network ssid] compare:[interface_ ssid]] == NSOrderedSame) |
| + properties->connection_state = onc::connection_state::kConnected; |
| + else |
| + properties->connection_state = onc::connection_state::kNotConnected; |
| + |
| + properties->ssid = base::SysNSStringToUTF8([network ssid]); |
| + properties->name = properties->ssid; |
| + properties->guid = GUIDFromSSID([network ssid]); |
| + properties->type = onc::network_type::kWiFi; |
| + |
| + properties->bssid = base::SysNSStringToUTF8([network bssid]); |
| + if ([[network wlanChannel] channelBand] == kCWChannelBand2GHz) |
| + properties->frequency = kFrequency2400; |
| + else |
| + properties->frequency = kFrequency5000; |
| + properties->frequency_set.insert(properties->frequency); |
| + properties->security = SecurityFromCWSecurityMode( |
| + static_cast<CWSecurityMode>([[network securityMode] intValue])); |
| + |
| + properties->signal_strength = [[network rssi] intValue]; |
| +} |
| + |
| +std::string WiFiServiceMac::SecurityFromCWSecurityMode( |
| + CWSecurityMode security) const { |
| + switch (security) { |
| + case kCWSecurityModeWPA_Enterprise: |
| + case kCWSecurityModeWPA2_Enterprise: |
| + return onc::wifi::kWPA_EAP; |
| + case kCWSecurityModeWPA_PSK: |
| + case kCWSecurityModeWPA2_PSK: |
| + return onc::wifi::kWPA_PSK; |
| + case kCWSecurityModeWEP: |
| + return onc::wifi::kWEP_PSK; |
| + case kCWSecurityModeOpen: |
| + return onc::wifi::kNone; |
| + // TODO(mef): Figure out correct mapping. |
| + case kCWSecurityModeWPS: |
| + case kCWSecurityModeDynamicWEP: |
| + return onc::wifi::kWPA_EAP; |
| + } |
| + return onc::wifi::kWPA_EAP; |
| +} |
| + |
| +void WiFiServiceMac::OnWlanObserverNotification() { |
| + std::string connected_network_guid = GUIDFromSSID([interface_ ssid]); |
| + DVLOG(1) << " *** Got Notification: " << connected_network_guid; |
| + if (connected_network_guid.empty()) { |
| + // Find previously connected network and notify that it is disconnected. |
| + for (WiFiService::NetworkList::iterator it = networks_.begin(); |
| + it != networks_.end(); |
| + ++it) { |
| + if (it->connection_state == onc::connection_state::kConnected) { |
| + it->connection_state = onc::connection_state::kNotConnected; |
| + NotifyNetworkChanged(it->guid); |
| + } |
| + } |
| + } else { |
| + NotifyNetworkChanged(connected_network_guid); |
|
tbarzic
2014/01/08 23:06:23
You should make sure that networks_ contains the c
mef
2014/01/09 22:41:46
Done.
|
| + } |
| +} |
| + |
| +void WiFiServiceMac::NotifyNetworkListChanged(const NetworkList& networks) { |
| + if (network_list_changed_observer_.is_null()) |
| + return; |
| + |
| + NetworkGuidList current_networks; |
| + for (NetworkList::const_iterator it = networks.begin(); |
| + it != networks.end(); |
| + ++it) { |
| + current_networks.push_back(it->guid); |
| + } |
| + |
| + message_loop_proxy_->PostTask( |
| + FROM_HERE, |
| + base::Bind(network_list_changed_observer_, current_networks)); |
| +} |
| + |
| +void WiFiServiceMac::NotifyNetworkChanged(const std::string& network_guid) { |
| + if (!enable_notify_network_changed_ || networks_changed_observer_.is_null()) |
| + return; |
| + |
| + DVLOG(1) << "NotifyNetworkChanged: " << network_guid; |
| + NetworkGuidList changed_networks(1, network_guid); |
| + message_loop_proxy_->PostTask( |
| + FROM_HERE, |
| + base::Bind(networks_changed_observer_, changed_networks)); |
| +} |
| + |
| +// static |
| +WiFiService* WiFiService::Create() { return new WiFiServiceMac(); } |
| + |
| +} // namespace wifi |