Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(170)

Side by Side Diff: components/wifi/wifi_service_mac.mm

Issue 226883002: WiFi client for GCD bootstrapping (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 return base::SysNSStringToUTF8(ssid); 120 return base::SysNSStringToUTF8(ssid);
120 } 121 }
121 122
122 // Populates |properties| from |network|. 123 // Populates |properties| from |network|.
123 void NetworkPropertiesFromCWNetwork(const CWNetwork* network, 124 void NetworkPropertiesFromCWNetwork(const CWNetwork* network,
124 NetworkProperties* properties) const; 125 NetworkProperties* properties) const;
125 126
126 // Converts |CWSecurityMode| into onc::wifi::k{WPA|WEP}* security constant. 127 // Converts |CWSecurityMode| into onc::wifi::k{WPA|WEP}* security constant.
127 std::string SecurityFromCWSecurityMode(CWSecurityMode security) const; 128 std::string SecurityFromCWSecurityMode(CWSecurityMode security) const;
128 129
129 // Converts |CWChannelBand| into WiFiService::Frequency constant. 130 // Converts |CWChannelBand| into Frequency constant.
130 Frequency FrequencyFromCWChannelBand(CWChannelBand band) const; 131 Frequency FrequencyFromCWChannelBand(CWChannelBand band) const;
131 132
132 // Gets current |onc::connection_state| for given |network_guid|. 133 // Gets current |onc::connection_state| for given |network_guid|.
133 std::string GetNetworkConnectionState(const std::string& network_guid) const; 134 std::string GetNetworkConnectionState(const std::string& network_guid) const;
134 135
135 // Updates |networks_| with the list of visible wireless networks. 136 // Updates |networks_| with the list of visible wireless networks.
136 void UpdateNetworks(); 137 void UpdateNetworks();
137 138
138 // Find network by |network_guid| and return iterator to its entry in 139 // Find network by |network_guid| and return iterator to its entry in
139 // |networks_|. 140 // |networks_|.
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 network_properties_.SetWithoutPathExpansion(network_guid, 246 network_properties_.SetWithoutPathExpansion(network_guid,
246 properties.release()); 247 properties.release());
247 } 248 }
248 } 249 }
249 250
250 void WiFiServiceMac::CreateNetwork( 251 void WiFiServiceMac::CreateNetwork(
251 bool shared, 252 bool shared,
252 scoped_ptr<base::DictionaryValue> properties, 253 scoped_ptr<base::DictionaryValue> properties,
253 std::string* network_guid, 254 std::string* network_guid,
254 std::string* error) { 255 std::string* error) {
255 WiFiService::NetworkProperties network_properties; 256 NetworkProperties network_properties;
256 if (!network_properties.UpdateFromValue(*properties)) { 257 if (!network_properties.UpdateFromValue(*properties)) {
257 *error = kErrorInvalidData; 258 *error = kErrorInvalidData;
258 return; 259 return;
259 } 260 }
260 261
261 std::string guid = network_properties.ssid; 262 std::string guid = network_properties.ssid;
262 if (FindNetwork(guid) != networks_.end()) { 263 if (FindNetwork(guid) != networks_.end()) {
263 *error = kErrorInvalidData; 264 *error = kErrorInvalidData;
264 return; 265 return;
265 } 266 }
266 network_properties_.SetWithoutPathExpansion(guid, 267 network_properties_.SetWithoutPathExpansion(guid,
267 properties.release()); 268 properties.release());
268 *network_guid = guid; 269 *network_guid = guid;
269 } 270 }
270 271
271 void WiFiServiceMac::GetVisibleNetworks(const std::string& network_type, 272 void WiFiServiceMac::GetVisibleNetworks(const std::string& network_type,
272 base::ListValue* network_list) { 273 base::ListValue* network_list) {
273 if (!network_type.empty() && 274 if (!network_type.empty() &&
274 network_type != onc::network_type::kAllTypes && 275 network_type != onc::network_type::kAllTypes &&
275 network_type != onc::network_type::kWiFi) { 276 network_type != onc::network_type::kWiFi) {
276 return; 277 return;
277 } 278 }
278 279
279 if (networks_.empty()) 280 if (networks_.empty())
280 UpdateNetworks(); 281 UpdateNetworks();
281 282
282 for (WiFiService::NetworkList::const_iterator it = networks_.begin(); 283 for (NetworkList::const_iterator it = networks_.begin();
283 it != networks_.end(); 284 it != networks_.end();
284 ++it) { 285 ++it) {
285 scoped_ptr<base::DictionaryValue> network(it->ToValue(true)); 286 scoped_ptr<base::DictionaryValue> network(it->ToValue(true));
286 network_list->Append(network.release()); 287 network_list->Append(network.release());
287 } 288 }
288 } 289 }
289 290
290 void WiFiServiceMac::RequestNetworkScan() { 291 void WiFiServiceMac::RequestNetworkScan() {
291 DVLOG(1) << "*** RequestNetworkScan"; 292 DVLOG(1) << "*** RequestNetworkScan";
292 UpdateNetworks(); 293 UpdateNetworks();
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 case kCWSecurityModeOpen: 551 case kCWSecurityModeOpen:
551 return onc::wifi::kNone; 552 return onc::wifi::kNone;
552 // TODO(mef): Figure out correct mapping. 553 // TODO(mef): Figure out correct mapping.
553 case kCWSecurityModeWPS: 554 case kCWSecurityModeWPS:
554 case kCWSecurityModeDynamicWEP: 555 case kCWSecurityModeDynamicWEP:
555 return onc::wifi::kWPA_EAP; 556 return onc::wifi::kWPA_EAP;
556 } 557 }
557 return onc::wifi::kWPA_EAP; 558 return onc::wifi::kWPA_EAP;
558 } 559 }
559 560
560 561 Frequency WiFiServiceMac::FrequencyFromCWChannelBand(CWChannelBand band) const {
561 WiFiService::Frequency WiFiServiceMac::FrequencyFromCWChannelBand(
562 CWChannelBand band) const {
563 return band == kCWChannelBand2GHz ? kFrequency2400 : kFrequency5000; 562 return band == kCWChannelBand2GHz ? kFrequency2400 : kFrequency5000;
564 } 563 }
565 564
566 WiFiService::NetworkList::iterator WiFiServiceMac::FindNetwork( 565 NetworkList::iterator WiFiServiceMac::FindNetwork(
567 const std::string& network_guid) { 566 const std::string& network_guid) {
568 for (NetworkList::iterator it = networks_.begin(); 567 for (NetworkList::iterator it = networks_.begin();
569 it != networks_.end(); 568 it != networks_.end();
570 ++it) { 569 ++it) {
571 if (it->guid == network_guid) 570 if (it->guid == network_guid)
572 return it; 571 return it;
573 } 572 }
574 return networks_.end(); 573 return networks_.end();
575 } 574 }
576 575
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 NetworkGuidList changed_networks(1, network_guid); 626 NetworkGuidList changed_networks(1, network_guid);
628 message_loop_proxy_->PostTask( 627 message_loop_proxy_->PostTask(
629 FROM_HERE, 628 FROM_HERE,
630 base::Bind(networks_changed_observer_, changed_networks)); 629 base::Bind(networks_changed_observer_, changed_networks));
631 } 630 }
632 631
633 // static 632 // static
634 WiFiService* WiFiService::Create() { return new WiFiServiceMac(); } 633 WiFiService* WiFiService::Create() { return new WiFiServiceMac(); }
635 634
636 } // namespace wifi 635 } // namespace wifi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698