| 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 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 return base::SysNSStringToUTF8(ssid); | 93 return base::SysNSStringToUTF8(ssid); |
| 94 } | 94 } |
| 95 | 95 |
| 96 // Populates |properties| from |network|. | 96 // Populates |properties| from |network|. |
| 97 void NetworkPropertiesFromCWNetwork(const CWNetwork* network, | 97 void NetworkPropertiesFromCWNetwork(const CWNetwork* network, |
| 98 NetworkProperties* properties) const; | 98 NetworkProperties* properties) const; |
| 99 | 99 |
| 100 // Converts |CWSecurityMode| into onc::wifi::k{WPA|WEP}* security constant. | 100 // Converts |CWSecurityMode| into onc::wifi::k{WPA|WEP}* security constant. |
| 101 std::string SecurityFromCWSecurityMode(CWSecurityMode security) const; | 101 std::string SecurityFromCWSecurityMode(CWSecurityMode security) const; |
| 102 | 102 |
| 103 // Returns onc::wifi::k{WPA|WEP}* security constant supported by the |
| 104 // |CWNetwork|. |
| 105 std::string SecurityFromCWNetwork(const CWNetwork* network) const; |
| 106 |
| 103 // Converts |CWChannelBand| into Frequency constant. | 107 // Converts |CWChannelBand| into Frequency constant. |
| 104 Frequency FrequencyFromCWChannelBand(CWChannelBand band) const; | 108 Frequency FrequencyFromCWChannelBand(CWChannelBand band) const; |
| 105 | 109 |
| 106 // Gets current |onc::connection_state| for given |network_guid|. | 110 // Gets current |onc::connection_state| for given |network_guid|. |
| 107 std::string GetNetworkConnectionState(const std::string& network_guid) const; | 111 std::string GetNetworkConnectionState(const std::string& network_guid) const; |
| 108 | 112 |
| 109 // Updates |networks_| with the list of visible wireless networks. | 113 // Updates |networks_| with the list of visible wireless networks. |
| 110 void UpdateNetworks(); | 114 void UpdateNetworks(); |
| 111 | 115 |
| 112 // Find network by |network_guid| and return iterator to its entry in | 116 // Find network by |network_guid| and return iterator to its entry in |
| (...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 498 properties->connection_state = GetNetworkConnectionState(network_guid); | 502 properties->connection_state = GetNetworkConnectionState(network_guid); |
| 499 properties->ssid = base::SysNSStringToUTF8([network ssid]); | 503 properties->ssid = base::SysNSStringToUTF8([network ssid]); |
| 500 properties->name = properties->ssid; | 504 properties->name = properties->ssid; |
| 501 properties->guid = network_guid; | 505 properties->guid = network_guid; |
| 502 properties->type = onc::network_type::kWiFi; | 506 properties->type = onc::network_type::kWiFi; |
| 503 | 507 |
| 504 properties->bssid = base::SysNSStringToUTF8([network bssid]); | 508 properties->bssid = base::SysNSStringToUTF8([network bssid]); |
| 505 properties->frequency = FrequencyFromCWChannelBand( | 509 properties->frequency = FrequencyFromCWChannelBand( |
| 506 static_cast<CWChannelBand>([[network wlanChannel] channelBand])); | 510 static_cast<CWChannelBand>([[network wlanChannel] channelBand])); |
| 507 properties->frequency_set.insert(properties->frequency); | 511 properties->frequency_set.insert(properties->frequency); |
| 508 properties->security = SecurityFromCWSecurityMode( | |
| 509 static_cast<CWSecurityMode>([[network securityMode] intValue])); | |
| 510 | 512 |
| 511 properties->signal_strength = [[network rssi] intValue]; | 513 // -[CWNetwork supportsSecurity:] is available from 10.7 SDK while |
| 514 // -[CWNetwork securityMode] is deprecated and hidden as private since |
| 515 // 10.9 SDK. The latter is kept for now to support running on 10.6. It |
| 516 // should be removed when 10.6 support is dropped. |
| 517 if ([network respondsToSelector:@selector(supportsSecurity:)]) { |
| 518 properties->security = SecurityFromCWNetwork(network); |
| 519 } else { |
| 520 properties->security = SecurityFromCWSecurityMode( |
| 521 static_cast<CWSecurityMode>([[network securityMode] intValue])); |
| 522 } |
| 523 |
| 524 // rssiValue property of CWNetwork is available from 10.7 SDK while |
| 525 // -[CWNetwork rssi] is deprecated and hidden as private since 10.9 SDK. |
| 526 // The latter is kept for now to support running on 10.6. It should be |
| 527 // removed when 10.6 support is dropped. |
| 528 if ([network respondsToSelector:@selector(rssiValue)]) |
| 529 properties->signal_strength = [network rssiValue]; |
| 530 else |
| 531 properties->signal_strength = [[network rssi] intValue]; |
| 512 } | 532 } |
| 513 | 533 |
| 514 std::string WiFiServiceMac::SecurityFromCWSecurityMode( | 534 std::string WiFiServiceMac::SecurityFromCWSecurityMode( |
| 515 CWSecurityMode security) const { | 535 CWSecurityMode security) const { |
| 516 switch (security) { | 536 switch (security) { |
| 517 case kCWSecurityModeWPA_Enterprise: | 537 case kCWSecurityModeWPA_Enterprise: |
| 518 case kCWSecurityModeWPA2_Enterprise: | 538 case kCWSecurityModeWPA2_Enterprise: |
| 519 return onc::wifi::kWPA_EAP; | 539 return onc::wifi::kWPA_EAP; |
| 520 case kCWSecurityModeWPA_PSK: | 540 case kCWSecurityModeWPA_PSK: |
| 521 case kCWSecurityModeWPA2_PSK: | 541 case kCWSecurityModeWPA2_PSK: |
| 522 return onc::wifi::kWPA_PSK; | 542 return onc::wifi::kWPA_PSK; |
| 523 case kCWSecurityModeWEP: | 543 case kCWSecurityModeWEP: |
| 524 return onc::wifi::kWEP_PSK; | 544 return onc::wifi::kWEP_PSK; |
| 525 case kCWSecurityModeOpen: | 545 case kCWSecurityModeOpen: |
| 526 return onc::wifi::kSecurityNone; | 546 return onc::wifi::kSecurityNone; |
| 527 // TODO(mef): Figure out correct mapping. | 547 // TODO(mef): Figure out correct mapping. |
| 528 case kCWSecurityModeWPS: | 548 case kCWSecurityModeWPS: |
| 529 case kCWSecurityModeDynamicWEP: | 549 case kCWSecurityModeDynamicWEP: |
| 530 return onc::wifi::kWPA_EAP; | 550 return onc::wifi::kWPA_EAP; |
| 531 } | 551 } |
| 532 return onc::wifi::kWPA_EAP; | 552 return onc::wifi::kWPA_EAP; |
| 533 } | 553 } |
| 534 | 554 |
| 555 std::string WiFiServiceMac::SecurityFromCWNetwork( |
| 556 const CWNetwork* network) const { |
| 557 if ([network supportsSecurity:kCWSecurityWPAEnterprise] || |
| 558 [network supportsSecurity:kCWSecurityWPA2Enterprise]) { |
| 559 return onc::wifi::kWPA_EAP; |
| 560 } |
| 561 |
| 562 if ([network supportsSecurity:kCWSecurityWPAPersonal] || |
| 563 [network supportsSecurity:kCWSecurityWPA2Personal]) { |
| 564 return onc::wifi::kWPA_PSK; |
| 565 } |
| 566 |
| 567 if ([network supportsSecurity:kCWSecurityWEP]) |
| 568 return onc::wifi::kWEP_PSK; |
| 569 |
| 570 if ([network supportsSecurity:kCWSecurityNone]) |
| 571 return onc::wifi::kSecurityNone; |
| 572 |
| 573 // TODO(mef): Figure out correct mapping. |
| 574 if ([network supportsSecurity:kCWSecurityDynamicWEP]) |
| 575 return onc::wifi::kWPA_EAP; |
| 576 |
| 577 return onc::wifi::kWPA_EAP; |
| 578 } |
| 579 |
| 535 Frequency WiFiServiceMac::FrequencyFromCWChannelBand(CWChannelBand band) const { | 580 Frequency WiFiServiceMac::FrequencyFromCWChannelBand(CWChannelBand band) const { |
| 536 return band == kCWChannelBand2GHz ? kFrequency2400 : kFrequency5000; | 581 return band == kCWChannelBand2GHz ? kFrequency2400 : kFrequency5000; |
| 537 } | 582 } |
| 538 | 583 |
| 539 NetworkList::iterator WiFiServiceMac::FindNetwork( | 584 NetworkList::iterator WiFiServiceMac::FindNetwork( |
| 540 const std::string& network_guid) { | 585 const std::string& network_guid) { |
| 541 for (NetworkList::iterator it = networks_.begin(); | 586 for (NetworkList::iterator it = networks_.begin(); |
| 542 it != networks_.end(); | 587 it != networks_.end(); |
| 543 ++it) { | 588 ++it) { |
| 544 if (it->guid == network_guid) | 589 if (it->guid == network_guid) |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 600 NetworkGuidList changed_networks(1, network_guid); | 645 NetworkGuidList changed_networks(1, network_guid); |
| 601 message_loop_proxy_->PostTask( | 646 message_loop_proxy_->PostTask( |
| 602 FROM_HERE, | 647 FROM_HERE, |
| 603 base::Bind(networks_changed_observer_, changed_networks)); | 648 base::Bind(networks_changed_observer_, changed_networks)); |
| 604 } | 649 } |
| 605 | 650 |
| 606 // static | 651 // static |
| 607 WiFiService* WiFiService::Create() { return new WiFiServiceMac(); } | 652 WiFiService* WiFiService::Create() { return new WiFiServiceMac(); } |
| 608 | 653 |
| 609 } // namespace wifi | 654 } // namespace wifi |
| OLD | NEW |