OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/wifi/wifi_service.h" | 5 #include "components/wifi/wifi_service.h" |
6 | 6 |
7 #import <netinet/in.h> | 7 #import <netinet/in.h> |
8 #import <CoreWLAN/CoreWLAN.h> | 8 #import <CoreWLAN/CoreWLAN.h> |
9 #import <SystemConfiguration/SystemConfiguration.h> | 9 #import <SystemConfiguration/SystemConfiguration.h> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/mac/foundation_util.h" | 12 #include "base/mac/foundation_util.h" |
13 #include "base/mac/scoped_cftyperef.h" | 13 #include "base/mac/scoped_cftyperef.h" |
14 #include "base/mac/scoped_nsobject.h" | 14 #include "base/mac/scoped_nsobject.h" |
15 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
16 #include "base/strings/sys_string_conversions.h" | 16 #include "base/strings/sys_string_conversions.h" |
17 #include "components/onc/onc_constants.h" | 17 #include "components/onc/onc_constants.h" |
| 18 #include "components/wifi/network_properties.h" |
18 | 19 |
19 #if !defined(MAC_OS_X_VERSION_10_7) || \ | 20 #if !defined(MAC_OS_X_VERSION_10_7) || \ |
20 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 | 21 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 |
21 | 22 |
22 // Local definitions of API added in Mac OS X 10.7 | 23 // Local definitions of API added in Mac OS X 10.7 |
23 | 24 |
24 @interface CWInterface (LionAPI) | 25 @interface CWInterface (LionAPI) |
25 - (BOOL)associateToNetwork:(CWNetwork*)network | 26 - (BOOL)associateToNetwork:(CWNetwork*)network |
26 password:(NSString*)password | 27 password:(NSString*)password |
27 error:(NSError**)error; | 28 error:(NSError**)error; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 virtual void SetProperties(const std::string& network_guid, | 75 virtual void SetProperties(const std::string& network_guid, |
75 scoped_ptr<base::DictionaryValue> properties, | 76 scoped_ptr<base::DictionaryValue> properties, |
76 std::string* error) OVERRIDE; | 77 std::string* error) OVERRIDE; |
77 | 78 |
78 virtual void CreateNetwork(bool shared, | 79 virtual void CreateNetwork(bool shared, |
79 scoped_ptr<base::DictionaryValue> properties, | 80 scoped_ptr<base::DictionaryValue> properties, |
80 std::string* network_guid, | 81 std::string* network_guid, |
81 std::string* error) OVERRIDE; | 82 std::string* error) OVERRIDE; |
82 | 83 |
83 virtual void GetVisibleNetworks(const std::string& network_type, | 84 virtual void GetVisibleNetworks(const std::string& network_type, |
84 base::ListValue* network_list) OVERRIDE; | 85 base::ListValue* network_list, |
| 86 bool include_details) OVERRIDE; |
85 | 87 |
86 virtual void RequestNetworkScan() OVERRIDE; | 88 virtual void RequestNetworkScan() OVERRIDE; |
87 | 89 |
88 virtual void StartConnect(const std::string& network_guid, | 90 virtual void StartConnect(const std::string& network_guid, |
89 std::string* error) OVERRIDE; | 91 std::string* error) OVERRIDE; |
90 | 92 |
91 virtual void StartDisconnect(const std::string& network_guid, | 93 virtual void StartDisconnect(const std::string& network_guid, |
92 std::string* error) OVERRIDE; | 94 std::string* error) OVERRIDE; |
93 | 95 |
94 virtual void GetKeyFromSystem(const std::string& network_guid, | 96 virtual void GetKeyFromSystem(const std::string& network_guid, |
(...skipping 24 matching lines...) Expand all Loading... |
119 return base::SysNSStringToUTF8(ssid); | 121 return base::SysNSStringToUTF8(ssid); |
120 } | 122 } |
121 | 123 |
122 // Populates |properties| from |network|. | 124 // Populates |properties| from |network|. |
123 void NetworkPropertiesFromCWNetwork(const CWNetwork* network, | 125 void NetworkPropertiesFromCWNetwork(const CWNetwork* network, |
124 NetworkProperties* properties) const; | 126 NetworkProperties* properties) const; |
125 | 127 |
126 // Converts |CWSecurityMode| into onc::wifi::k{WPA|WEP}* security constant. | 128 // Converts |CWSecurityMode| into onc::wifi::k{WPA|WEP}* security constant. |
127 std::string SecurityFromCWSecurityMode(CWSecurityMode security) const; | 129 std::string SecurityFromCWSecurityMode(CWSecurityMode security) const; |
128 | 130 |
129 // Converts |CWChannelBand| into WiFiService::Frequency constant. | 131 // Converts |CWChannelBand| into Frequency constant. |
130 Frequency FrequencyFromCWChannelBand(CWChannelBand band) const; | 132 Frequency FrequencyFromCWChannelBand(CWChannelBand band) const; |
131 | 133 |
132 // Gets current |onc::connection_state| for given |network_guid|. | 134 // Gets current |onc::connection_state| for given |network_guid|. |
133 std::string GetNetworkConnectionState(const std::string& network_guid) const; | 135 std::string GetNetworkConnectionState(const std::string& network_guid) const; |
134 | 136 |
135 // Updates |networks_| with the list of visible wireless networks. | 137 // Updates |networks_| with the list of visible wireless networks. |
136 void UpdateNetworks(); | 138 void UpdateNetworks(); |
137 | 139 |
138 // Find network by |network_guid| and return iterator to its entry in | 140 // Find network by |network_guid| and return iterator to its entry in |
139 // |networks_|. | 141 // |networks_|. |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 network_properties_.SetWithoutPathExpansion(network_guid, | 247 network_properties_.SetWithoutPathExpansion(network_guid, |
246 properties.release()); | 248 properties.release()); |
247 } | 249 } |
248 } | 250 } |
249 | 251 |
250 void WiFiServiceMac::CreateNetwork( | 252 void WiFiServiceMac::CreateNetwork( |
251 bool shared, | 253 bool shared, |
252 scoped_ptr<base::DictionaryValue> properties, | 254 scoped_ptr<base::DictionaryValue> properties, |
253 std::string* network_guid, | 255 std::string* network_guid, |
254 std::string* error) { | 256 std::string* error) { |
255 WiFiService::NetworkProperties network_properties; | 257 NetworkProperties network_properties; |
256 if (!network_properties.UpdateFromValue(*properties)) { | 258 if (!network_properties.UpdateFromValue(*properties)) { |
257 *error = kErrorInvalidData; | 259 *error = kErrorInvalidData; |
258 return; | 260 return; |
259 } | 261 } |
260 | 262 |
261 std::string guid = network_properties.ssid; | 263 std::string guid = network_properties.ssid; |
262 if (FindNetwork(guid) != networks_.end()) { | 264 if (FindNetwork(guid) != networks_.end()) { |
263 *error = kErrorInvalidData; | 265 *error = kErrorInvalidData; |
264 return; | 266 return; |
265 } | 267 } |
266 network_properties_.SetWithoutPathExpansion(guid, | 268 network_properties_.SetWithoutPathExpansion(guid, |
267 properties.release()); | 269 properties.release()); |
268 *network_guid = guid; | 270 *network_guid = guid; |
269 } | 271 } |
270 | 272 |
271 void WiFiServiceMac::GetVisibleNetworks(const std::string& network_type, | 273 void WiFiServiceMac::GetVisibleNetworks(const std::string& network_type, |
272 base::ListValue* network_list) { | 274 base::ListValue* network_list, |
| 275 bool include_details) { |
273 if (!network_type.empty() && | 276 if (!network_type.empty() && |
274 network_type != onc::network_type::kAllTypes && | 277 network_type != onc::network_type::kAllTypes && |
275 network_type != onc::network_type::kWiFi) { | 278 network_type != onc::network_type::kWiFi) { |
276 return; | 279 return; |
277 } | 280 } |
278 | 281 |
279 if (networks_.empty()) | 282 if (networks_.empty()) |
280 UpdateNetworks(); | 283 UpdateNetworks(); |
281 | 284 |
282 for (WiFiService::NetworkList::const_iterator it = networks_.begin(); | 285 for (NetworkList::const_iterator it = networks_.begin(); |
283 it != networks_.end(); | 286 it != networks_.end(); |
284 ++it) { | 287 ++it) { |
285 scoped_ptr<base::DictionaryValue> network(it->ToValue(true)); | 288 scoped_ptr<base::DictionaryValue> network(it->ToValue(!include_details)); |
286 network_list->Append(network.release()); | 289 network_list->Append(network.release()); |
287 } | 290 } |
288 } | 291 } |
289 | 292 |
290 void WiFiServiceMac::RequestNetworkScan() { | 293 void WiFiServiceMac::RequestNetworkScan() { |
291 DVLOG(1) << "*** RequestNetworkScan"; | 294 DVLOG(1) << "*** RequestNetworkScan"; |
292 UpdateNetworks(); | 295 UpdateNetworks(); |
293 } | 296 } |
294 | 297 |
295 void WiFiServiceMac::StartConnect(const std::string& network_guid, | 298 void WiFiServiceMac::StartConnect(const std::string& network_guid, |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 case kCWSecurityModeOpen: | 553 case kCWSecurityModeOpen: |
551 return onc::wifi::kNone; | 554 return onc::wifi::kNone; |
552 // TODO(mef): Figure out correct mapping. | 555 // TODO(mef): Figure out correct mapping. |
553 case kCWSecurityModeWPS: | 556 case kCWSecurityModeWPS: |
554 case kCWSecurityModeDynamicWEP: | 557 case kCWSecurityModeDynamicWEP: |
555 return onc::wifi::kWPA_EAP; | 558 return onc::wifi::kWPA_EAP; |
556 } | 559 } |
557 return onc::wifi::kWPA_EAP; | 560 return onc::wifi::kWPA_EAP; |
558 } | 561 } |
559 | 562 |
560 | 563 Frequency WiFiServiceMac::FrequencyFromCWChannelBand(CWChannelBand band) const { |
561 WiFiService::Frequency WiFiServiceMac::FrequencyFromCWChannelBand( | |
562 CWChannelBand band) const { | |
563 return band == kCWChannelBand2GHz ? kFrequency2400 : kFrequency5000; | 564 return band == kCWChannelBand2GHz ? kFrequency2400 : kFrequency5000; |
564 } | 565 } |
565 | 566 |
566 WiFiService::NetworkList::iterator WiFiServiceMac::FindNetwork( | 567 NetworkList::iterator WiFiServiceMac::FindNetwork( |
567 const std::string& network_guid) { | 568 const std::string& network_guid) { |
568 for (NetworkList::iterator it = networks_.begin(); | 569 for (NetworkList::iterator it = networks_.begin(); |
569 it != networks_.end(); | 570 it != networks_.end(); |
570 ++it) { | 571 ++it) { |
571 if (it->guid == network_guid) | 572 if (it->guid == network_guid) |
572 return it; | 573 return it; |
573 } | 574 } |
574 return networks_.end(); | 575 return networks_.end(); |
575 } | 576 } |
576 | 577 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
627 NetworkGuidList changed_networks(1, network_guid); | 628 NetworkGuidList changed_networks(1, network_guid); |
628 message_loop_proxy_->PostTask( | 629 message_loop_proxy_->PostTask( |
629 FROM_HERE, | 630 FROM_HERE, |
630 base::Bind(networks_changed_observer_, changed_networks)); | 631 base::Bind(networks_changed_observer_, changed_networks)); |
631 } | 632 } |
632 | 633 |
633 // static | 634 // static |
634 WiFiService* WiFiService::Create() { return new WiFiServiceMac(); } | 635 WiFiService* WiFiService::Create() { return new WiFiServiceMac(); } |
635 | 636 |
636 } // namespace wifi | 637 } // namespace wifi |
OLD | NEW |