Chromium Code Reviews| 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 if ([network respondsToSelector:@selector(supportsSecurity:)]) { |
|
mef
2014/09/05 18:22:50
Maybe add comment why do we need respondsToSelecto
Jiang Jiang
2014/09/06 06:42:57
Done.
| |
| 514 properties->security = SecurityFromCWNetwork(network); | |
| 515 } else { | |
| 516 properties->security = SecurityFromCWSecurityMode( | |
| 517 static_cast<CWSecurityMode>([[network securityMode] intValue])); | |
| 518 } | |
| 519 | |
| 520 if ([network respondsToSelector:@selector(rssiValue:)]) | |
| 521 properties->signal_strength = [network rssiValue]; | |
| 522 else | |
| 523 properties->signal_strength = [[network rssi] intValue]; | |
| 512 } | 524 } |
| 513 | 525 |
| 514 std::string WiFiServiceMac::SecurityFromCWSecurityMode( | 526 std::string WiFiServiceMac::SecurityFromCWSecurityMode( |
| 515 CWSecurityMode security) const { | 527 CWSecurityMode security) const { |
| 516 switch (security) { | 528 switch (security) { |
| 517 case kCWSecurityModeWPA_Enterprise: | 529 case kCWSecurityModeWPA_Enterprise: |
| 518 case kCWSecurityModeWPA2_Enterprise: | 530 case kCWSecurityModeWPA2_Enterprise: |
| 519 return onc::wifi::kWPA_EAP; | 531 return onc::wifi::kWPA_EAP; |
| 520 case kCWSecurityModeWPA_PSK: | 532 case kCWSecurityModeWPA_PSK: |
| 521 case kCWSecurityModeWPA2_PSK: | 533 case kCWSecurityModeWPA2_PSK: |
| 522 return onc::wifi::kWPA_PSK; | 534 return onc::wifi::kWPA_PSK; |
| 523 case kCWSecurityModeWEP: | 535 case kCWSecurityModeWEP: |
| 524 return onc::wifi::kWEP_PSK; | 536 return onc::wifi::kWEP_PSK; |
| 525 case kCWSecurityModeOpen: | 537 case kCWSecurityModeOpen: |
| 526 return onc::wifi::kSecurityNone; | 538 return onc::wifi::kSecurityNone; |
| 527 // TODO(mef): Figure out correct mapping. | 539 // TODO(mef): Figure out correct mapping. |
| 528 case kCWSecurityModeWPS: | 540 case kCWSecurityModeWPS: |
| 529 case kCWSecurityModeDynamicWEP: | 541 case kCWSecurityModeDynamicWEP: |
| 530 return onc::wifi::kWPA_EAP; | 542 return onc::wifi::kWPA_EAP; |
| 531 } | 543 } |
| 532 return onc::wifi::kWPA_EAP; | 544 return onc::wifi::kWPA_EAP; |
| 533 } | 545 } |
| 534 | 546 |
| 547 std::string WiFiServiceMac::SecurityFromCWNetwork( | |
| 548 const CWNetwork* network) const { | |
| 549 if ([network supportsSecurity:kCWSecurityWPAEnterprise] || | |
| 550 [network supportsSecurity:kCWSecurityWPA2Enterprise]) { | |
| 551 return onc::wifi::kWPA_EAP; | |
| 552 } | |
| 553 | |
| 554 if ([network supportsSecurity:kCWSecurityWPAPersonal] || | |
| 555 [network supportsSecurity:kCWSecurityWPA2Personal]) { | |
| 556 return onc::wifi::kWPA_PSK; | |
| 557 } | |
| 558 | |
| 559 if ([network supportsSecurity:kCWSecurityWEP]) | |
| 560 return onc::wifi::kWEP_PSK; | |
| 561 | |
| 562 if ([network supportsSecurity:kCWSecurityNone]) | |
| 563 return onc::wifi::kSecurityNone; | |
| 564 | |
| 565 // TODO(mef): Figure out correct mapping. | |
| 566 if ([network supportsSecurity:kCWSecurityDynamicWEP]) | |
| 567 return onc::wifi::kWPA_EAP; | |
| 568 | |
| 569 return onc::wifi::kWPA_EAP; | |
| 570 } | |
| 571 | |
| 535 Frequency WiFiServiceMac::FrequencyFromCWChannelBand(CWChannelBand band) const { | 572 Frequency WiFiServiceMac::FrequencyFromCWChannelBand(CWChannelBand band) const { |
| 536 return band == kCWChannelBand2GHz ? kFrequency2400 : kFrequency5000; | 573 return band == kCWChannelBand2GHz ? kFrequency2400 : kFrequency5000; |
| 537 } | 574 } |
| 538 | 575 |
| 539 NetworkList::iterator WiFiServiceMac::FindNetwork( | 576 NetworkList::iterator WiFiServiceMac::FindNetwork( |
| 540 const std::string& network_guid) { | 577 const std::string& network_guid) { |
| 541 for (NetworkList::iterator it = networks_.begin(); | 578 for (NetworkList::iterator it = networks_.begin(); |
| 542 it != networks_.end(); | 579 it != networks_.end(); |
| 543 ++it) { | 580 ++it) { |
| 544 if (it->guid == network_guid) | 581 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); | 637 NetworkGuidList changed_networks(1, network_guid); |
| 601 message_loop_proxy_->PostTask( | 638 message_loop_proxy_->PostTask( |
| 602 FROM_HERE, | 639 FROM_HERE, |
| 603 base::Bind(networks_changed_observer_, changed_networks)); | 640 base::Bind(networks_changed_observer_, changed_networks)); |
| 604 } | 641 } |
| 605 | 642 |
| 606 // static | 643 // static |
| 607 WiFiService* WiFiService::Create() { return new WiFiServiceMac(); } | 644 WiFiService* WiFiService::Create() { return new WiFiServiceMac(); } |
| 608 | 645 |
| 609 } // namespace wifi | 646 } // namespace wifi |
| OLD | NEW |