| 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 <CoreWLAN/CoreWLAN.h> | 7 #import <CoreWLAN/CoreWLAN.h> |
| 8 #import <netinet/in.h> | 8 #import <netinet/in.h> |
| 9 #import <SystemConfiguration/SystemConfiguration.h> | 9 #import <SystemConfiguration/SystemConfiguration.h> |
| 10 | 10 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 | 94 |
| 95 // Gets unique |network_guid| string based on |ssid|. | 95 // Gets unique |network_guid| string based on |ssid|. |
| 96 std::string GUIDFromSSID(NSString* ssid) const { | 96 std::string GUIDFromSSID(NSString* ssid) const { |
| 97 return base::SysNSStringToUTF8(ssid); | 97 return base::SysNSStringToUTF8(ssid); |
| 98 } | 98 } |
| 99 | 99 |
| 100 // Populates |properties| from |network|. | 100 // Populates |properties| from |network|. |
| 101 void NetworkPropertiesFromCWNetwork(const CWNetwork* network, | 101 void NetworkPropertiesFromCWNetwork(const CWNetwork* network, |
| 102 NetworkProperties* properties) const; | 102 NetworkProperties* properties) const; |
| 103 | 103 |
| 104 // Converts |CWSecurityMode| into onc::wifi::k{WPA|WEP}* security constant. | |
| 105 std::string SecurityFromCWSecurityMode(CWSecurityMode security) const; | |
| 106 | |
| 107 // Returns onc::wifi::k{WPA|WEP}* security constant supported by the | 104 // Returns onc::wifi::k{WPA|WEP}* security constant supported by the |
| 108 // |CWNetwork|. | 105 // |CWNetwork|. |
| 109 std::string SecurityFromCWNetwork(const CWNetwork* network) const; | 106 std::string SecurityFromCWNetwork(const CWNetwork* network) const; |
| 110 | 107 |
| 111 // Converts |CWChannelBand| into Frequency constant. | 108 // Converts |CWChannelBand| into Frequency constant. |
| 112 Frequency FrequencyFromCWChannelBand(CWChannelBand band) const; | 109 Frequency FrequencyFromCWChannelBand(CWChannelBand band) const; |
| 113 | 110 |
| 114 // Gets current |onc::connection_state| for given |network_guid|. | 111 // Gets current |onc::connection_state| for given |network_guid|. |
| 115 std::string GetNetworkConnectionState(const std::string& network_guid) const; | 112 std::string GetNetworkConnectionState(const std::string& network_guid) const; |
| 116 | 113 |
| (...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 514 properties->ssid = base::SysNSStringToUTF8([network ssid]); | 511 properties->ssid = base::SysNSStringToUTF8([network ssid]); |
| 515 properties->name = properties->ssid; | 512 properties->name = properties->ssid; |
| 516 properties->guid = network_guid; | 513 properties->guid = network_guid; |
| 517 properties->type = onc::network_type::kWiFi; | 514 properties->type = onc::network_type::kWiFi; |
| 518 | 515 |
| 519 properties->bssid = base::SysNSStringToUTF8([network bssid]); | 516 properties->bssid = base::SysNSStringToUTF8([network bssid]); |
| 520 properties->frequency = FrequencyFromCWChannelBand( | 517 properties->frequency = FrequencyFromCWChannelBand( |
| 521 static_cast<CWChannelBand>([[network wlanChannel] channelBand])); | 518 static_cast<CWChannelBand>([[network wlanChannel] channelBand])); |
| 522 properties->frequency_set.insert(properties->frequency); | 519 properties->frequency_set.insert(properties->frequency); |
| 523 | 520 |
| 524 // -[CWNetwork supportsSecurity:] is available from 10.7 SDK while | 521 properties->security = SecurityFromCWNetwork(network); |
| 525 // -[CWNetwork securityMode] is deprecated and hidden as private since | 522 properties->signal_strength = [network rssiValue]; |
| 526 // 10.9 SDK. The latter is kept for now to support running on 10.6. It | |
| 527 // should be removed when 10.6 support is dropped. | |
| 528 if ([network respondsToSelector:@selector(supportsSecurity:)]) { | |
| 529 properties->security = SecurityFromCWNetwork(network); | |
| 530 } else { | |
| 531 properties->security = SecurityFromCWSecurityMode( | |
| 532 static_cast<CWSecurityMode>([[network securityMode] intValue])); | |
| 533 } | |
| 534 | |
| 535 // rssiValue property of CWNetwork is available from 10.7 SDK while | |
| 536 // -[CWNetwork rssi] is deprecated and hidden as private since 10.9 SDK. | |
| 537 // The latter is kept for now to support running on 10.6. It should be | |
| 538 // removed when 10.6 support is dropped. | |
| 539 if ([network respondsToSelector:@selector(rssiValue)]) | |
| 540 properties->signal_strength = [network rssiValue]; | |
| 541 else | |
| 542 properties->signal_strength = [[network rssi] intValue]; | |
| 543 } | |
| 544 | |
| 545 std::string WiFiServiceMac::SecurityFromCWSecurityMode( | |
| 546 CWSecurityMode security) const { | |
| 547 switch (security) { | |
| 548 case kCWSecurityModeWPA_Enterprise: | |
| 549 case kCWSecurityModeWPA2_Enterprise: | |
| 550 return onc::wifi::kWPA_EAP; | |
| 551 case kCWSecurityModeWPA_PSK: | |
| 552 case kCWSecurityModeWPA2_PSK: | |
| 553 return onc::wifi::kWPA_PSK; | |
| 554 case kCWSecurityModeWEP: | |
| 555 return onc::wifi::kWEP_PSK; | |
| 556 case kCWSecurityModeOpen: | |
| 557 return onc::wifi::kSecurityNone; | |
| 558 // TODO(mef): Figure out correct mapping. | |
| 559 case kCWSecurityModeWPS: | |
| 560 case kCWSecurityModeDynamicWEP: | |
| 561 return onc::wifi::kWPA_EAP; | |
| 562 } | |
| 563 return onc::wifi::kWPA_EAP; | |
| 564 } | 523 } |
| 565 | 524 |
| 566 std::string WiFiServiceMac::SecurityFromCWNetwork( | 525 std::string WiFiServiceMac::SecurityFromCWNetwork( |
| 567 const CWNetwork* network) const { | 526 const CWNetwork* network) const { |
| 568 if ([network supportsSecurity:kCWSecurityWPAEnterprise] || | 527 if ([network supportsSecurity:kCWSecurityWPAEnterprise] || |
| 569 [network supportsSecurity:kCWSecurityWPA2Enterprise]) { | 528 [network supportsSecurity:kCWSecurityWPA2Enterprise]) { |
| 570 return onc::wifi::kWPA_EAP; | 529 return onc::wifi::kWPA_EAP; |
| 571 } | 530 } |
| 572 | 531 |
| 573 if ([network supportsSecurity:kCWSecurityWPAPersonal] || | 532 if ([network supportsSecurity:kCWSecurityWPAPersonal] || |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 654 DVLOG(1) << "NotifyNetworkChanged: " << network_guid; | 613 DVLOG(1) << "NotifyNetworkChanged: " << network_guid; |
| 655 NetworkGuidList changed_networks(1, network_guid); | 614 NetworkGuidList changed_networks(1, network_guid); |
| 656 event_task_runner_->PostTask( | 615 event_task_runner_->PostTask( |
| 657 FROM_HERE, base::Bind(networks_changed_observer_, changed_networks)); | 616 FROM_HERE, base::Bind(networks_changed_observer_, changed_networks)); |
| 658 } | 617 } |
| 659 | 618 |
| 660 // static | 619 // static |
| 661 WiFiService* WiFiService::Create() { return new WiFiServiceMac(); } | 620 WiFiService* WiFiService::Create() { return new WiFiServiceMac(); } |
| 662 | 621 |
| 663 } // namespace wifi | 622 } // namespace wifi |
| OLD | NEW |