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 // Converts |CWSecurity| into onc::wifi::k{WPA|WEP}* security constant. | |
|
mef
2014/09/04 15:31:34
Nit: Either change this function to take |CWSecuri
Jiang Jiang
2014/09/04 16:04:21
Done.
| |
| 104 std::string SecurityFromCWNetwork(const CWNetwork* network) const; | |
| 105 | |
| 103 // Converts |CWChannelBand| into Frequency constant. | 106 // Converts |CWChannelBand| into Frequency constant. |
| 104 Frequency FrequencyFromCWChannelBand(CWChannelBand band) const; | 107 Frequency FrequencyFromCWChannelBand(CWChannelBand band) const; |
| 105 | 108 |
| 106 // Gets current |onc::connection_state| for given |network_guid|. | 109 // Gets current |onc::connection_state| for given |network_guid|. |
| 107 std::string GetNetworkConnectionState(const std::string& network_guid) const; | 110 std::string GetNetworkConnectionState(const std::string& network_guid) const; |
| 108 | 111 |
| 109 // Updates |networks_| with the list of visible wireless networks. | 112 // Updates |networks_| with the list of visible wireless networks. |
| 110 void UpdateNetworks(); | 113 void UpdateNetworks(); |
| 111 | 114 |
| 112 // Find network by |network_guid| and return iterator to its entry in | 115 // Find network by |network_guid| and return iterator to its entry in |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 394 void (^ns_observer) (NSNotification* notification) = | 397 void (^ns_observer) (NSNotification* notification) = |
| 395 ^(NSNotification* notification) { | 398 ^(NSNotification* notification) { |
| 396 DVLOG(1) << "Received CWSSIDDidChangeNotification"; | 399 DVLOG(1) << "Received CWSSIDDidChangeNotification"; |
| 397 task_runner_->PostTask( | 400 task_runner_->PostTask( |
| 398 FROM_HERE, | 401 FROM_HERE, |
| 399 base::Bind(&WiFiServiceMac::OnWlanObserverNotification, | 402 base::Bind(&WiFiServiceMac::OnWlanObserverNotification, |
| 400 base::Unretained(this))); | 403 base::Unretained(this))); |
| 401 }; | 404 }; |
| 402 | 405 |
| 403 wlan_observer_ = [[NSNotificationCenter defaultCenter] | 406 wlan_observer_ = [[NSNotificationCenter defaultCenter] |
| 404 addObserverForName:kCWSSIDDidChangeNotification | 407 addObserverForName:CWSSIDDidChangeNotification |
|
mef
2014/09/04 15:31:34
does it compile on 10.6?
Jiang Jiang
2014/09/04 16:04:21
Yes, according to the docs it's declared in 10.6 S
| |
| 405 object:nil | 408 object:nil |
| 406 queue:nil | 409 queue:nil |
| 407 usingBlock:ns_observer]; | 410 usingBlock:ns_observer]; |
| 408 } | 411 } |
| 409 } | 412 } |
| 410 | 413 |
| 411 void WiFiServiceMac::RequestConnectedNetworkUpdate() { | 414 void WiFiServiceMac::RequestConnectedNetworkUpdate() { |
| 412 OnWlanObserverNotification(); | 415 OnWlanObserverNotification(); |
| 413 } | 416 } |
| 414 | 417 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 498 properties->connection_state = GetNetworkConnectionState(network_guid); | 501 properties->connection_state = GetNetworkConnectionState(network_guid); |
| 499 properties->ssid = base::SysNSStringToUTF8([network ssid]); | 502 properties->ssid = base::SysNSStringToUTF8([network ssid]); |
| 500 properties->name = properties->ssid; | 503 properties->name = properties->ssid; |
| 501 properties->guid = network_guid; | 504 properties->guid = network_guid; |
| 502 properties->type = onc::network_type::kWiFi; | 505 properties->type = onc::network_type::kWiFi; |
| 503 | 506 |
| 504 properties->bssid = base::SysNSStringToUTF8([network bssid]); | 507 properties->bssid = base::SysNSStringToUTF8([network bssid]); |
| 505 properties->frequency = FrequencyFromCWChannelBand( | 508 properties->frequency = FrequencyFromCWChannelBand( |
| 506 static_cast<CWChannelBand>([[network wlanChannel] channelBand])); | 509 static_cast<CWChannelBand>([[network wlanChannel] channelBand])); |
| 507 properties->frequency_set.insert(properties->frequency); | 510 properties->frequency_set.insert(properties->frequency); |
| 508 properties->security = SecurityFromCWSecurityMode( | |
| 509 static_cast<CWSecurityMode>([[network securityMode] intValue])); | |
| 510 | 511 |
| 511 properties->signal_strength = [[network rssi] intValue]; | 512 if ([network respondsToSelector:@selector(supportsSecurity:)]) { |
| 513 properties->security = SecurityFromCWNetwork(network); | |
| 514 } else { | |
| 515 properties->security = SecurityFromCWSecurityMode( | |
| 516 static_cast<CWSecurityMode>([[network securityMode] intValue])); | |
| 517 } | |
| 518 | |
| 519 if ([network respondsToSelector:@selector(rssiValue:)]) | |
| 520 properties->signal_strength = [network rssiValue]; | |
| 521 else | |
| 522 properties->signal_strength = [[network rssi] intValue]; | |
| 512 } | 523 } |
| 513 | 524 |
| 514 std::string WiFiServiceMac::SecurityFromCWSecurityMode( | 525 std::string WiFiServiceMac::SecurityFromCWSecurityMode( |
| 515 CWSecurityMode security) const { | 526 CWSecurityMode security) const { |
| 516 switch (security) { | 527 switch (security) { |
| 517 case kCWSecurityModeWPA_Enterprise: | 528 case kCWSecurityModeWPA_Enterprise: |
| 518 case kCWSecurityModeWPA2_Enterprise: | 529 case kCWSecurityModeWPA2_Enterprise: |
| 519 return onc::wifi::kWPA_EAP; | 530 return onc::wifi::kWPA_EAP; |
| 520 case kCWSecurityModeWPA_PSK: | 531 case kCWSecurityModeWPA_PSK: |
| 521 case kCWSecurityModeWPA2_PSK: | 532 case kCWSecurityModeWPA2_PSK: |
| 522 return onc::wifi::kWPA_PSK; | 533 return onc::wifi::kWPA_PSK; |
| 523 case kCWSecurityModeWEP: | 534 case kCWSecurityModeWEP: |
| 524 return onc::wifi::kWEP_PSK; | 535 return onc::wifi::kWEP_PSK; |
| 525 case kCWSecurityModeOpen: | 536 case kCWSecurityModeOpen: |
| 526 return onc::wifi::kSecurityNone; | 537 return onc::wifi::kSecurityNone; |
| 527 // TODO(mef): Figure out correct mapping. | 538 // TODO(mef): Figure out correct mapping. |
| 528 case kCWSecurityModeWPS: | 539 case kCWSecurityModeWPS: |
| 529 case kCWSecurityModeDynamicWEP: | 540 case kCWSecurityModeDynamicWEP: |
| 530 return onc::wifi::kWPA_EAP; | 541 return onc::wifi::kWPA_EAP; |
| 531 } | 542 } |
| 532 return onc::wifi::kWPA_EAP; | 543 return onc::wifi::kWPA_EAP; |
| 533 } | 544 } |
| 534 | 545 |
| 546 std::string WiFiServiceMac::SecurityFromCWNetwork( | |
| 547 const CWNetwork* network) const { | |
| 548 if ([network supportsSecurity:kCWSecurityWPAEnterprise] || | |
| 549 [network supportsSecurity:kCWSecurityWPA2Enterprise]) { | |
| 550 return onc::wifi::kWPA_EAP; | |
| 551 } | |
| 552 | |
| 553 if ([network supportsSecurity:kCWSecurityWPAPersonal] || | |
| 554 [network supportsSecurity:kCWSecurityWPA2Personal]) { | |
| 555 return onc::wifi::kWPA_PSK; | |
| 556 } | |
| 557 | |
| 558 if ([network supportsSecurity:kCWSecurityWEP]) | |
| 559 return onc::wifi::kWEP_PSK; | |
| 560 | |
| 561 if ([network supportsSecurity:kCWSecurityNone]) | |
| 562 return onc::wifi::kSecurityNone; | |
| 563 | |
| 564 // TODO(mef): Figure out correct mapping. | |
| 565 if ([network supportsSecurity:kCWSecurityDynamicWEP]) | |
| 566 return onc::wifi::kWPA_EAP; | |
| 567 | |
| 568 return onc::wifi::kWPA_EAP; | |
| 569 } | |
| 570 | |
| 535 Frequency WiFiServiceMac::FrequencyFromCWChannelBand(CWChannelBand band) const { | 571 Frequency WiFiServiceMac::FrequencyFromCWChannelBand(CWChannelBand band) const { |
| 536 return band == kCWChannelBand2GHz ? kFrequency2400 : kFrequency5000; | 572 return band == kCWChannelBand2GHz ? kFrequency2400 : kFrequency5000; |
| 537 } | 573 } |
| 538 | 574 |
| 539 NetworkList::iterator WiFiServiceMac::FindNetwork( | 575 NetworkList::iterator WiFiServiceMac::FindNetwork( |
| 540 const std::string& network_guid) { | 576 const std::string& network_guid) { |
| 541 for (NetworkList::iterator it = networks_.begin(); | 577 for (NetworkList::iterator it = networks_.begin(); |
| 542 it != networks_.end(); | 578 it != networks_.end(); |
| 543 ++it) { | 579 ++it) { |
| 544 if (it->guid == network_guid) | 580 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); | 636 NetworkGuidList changed_networks(1, network_guid); |
| 601 message_loop_proxy_->PostTask( | 637 message_loop_proxy_->PostTask( |
| 602 FROM_HERE, | 638 FROM_HERE, |
| 603 base::Bind(networks_changed_observer_, changed_networks)); | 639 base::Bind(networks_changed_observer_, changed_networks)); |
| 604 } | 640 } |
| 605 | 641 |
| 606 // static | 642 // static |
| 607 WiFiService* WiFiService::Create() { return new WiFiServiceMac(); } | 643 WiFiService* WiFiService::Create() { return new WiFiServiceMac(); } |
| 608 | 644 |
| 609 } // namespace wifi | 645 } // namespace wifi |
| OLD | NEW |