diff options
Diffstat (limited to 'chromeos/network/onc')
-rw-r--r-- | chromeos/network/onc/onc_signature.cc | 1 | ||||
-rw-r--r-- | chromeos/network/onc/onc_translation_tables.cc | 4 | ||||
-rw-r--r-- | chromeos/network/onc/onc_translator_onc_to_shill.cc | 26 | ||||
-rw-r--r-- | chromeos/network/onc/onc_translator_shill_to_onc.cc | 33 | ||||
-rw-r--r-- | chromeos/network/onc/onc_translator_unittest.cc | 8 | ||||
-rw-r--r-- | chromeos/network/onc/onc_validator_unittest.cc | 5 |
6 files changed, 64 insertions, 13 deletions
diff --git a/chromeos/network/onc/onc_signature.cc b/chromeos/network/onc/onc_signature.cc index f3e000b..afed3a8 100644 --- a/chromeos/network/onc/onc_signature.cc +++ b/chromeos/network/onc/onc_signature.cc @@ -144,7 +144,6 @@ const OncFieldSignature vpn_fields[] = { const OncFieldSignature ethernet_fields[] = { { kRecommended, &kRecommendedSignature }, - // Not supported, yet. { ethernet::kAuthentication, &kStringSignature }, { ethernet::kEAP, &kEAPSignature }, { NULL } diff --git a/chromeos/network/onc/onc_translation_tables.cc b/chromeos/network/onc/onc_translation_tables.cc index 8a1b29d..0cc2b6b 100644 --- a/chromeos/network/onc/onc_translation_tables.cc +++ b/chromeos/network/onc/onc_translation_tables.cc @@ -212,7 +212,9 @@ const NestedShillDictionaryEntry nested_shill_dictionaries[] = { } // namespace const StringTranslationEntry kNetworkTypeTable[] = { - { network_type::kEthernet, flimflam::kTypeEthernet }, + // This mapping is ensured in the translation code. + // { network_type::kEthernet, flimflam::kTypeEthernet }, + // { network_type::kEthernet, shill::kTypeEthernetEap }, { network_type::kWiFi, flimflam::kTypeWifi }, { network_type::kCellular, flimflam::kTypeCellular }, { network_type::kVPN, flimflam::kTypeVPN }, diff --git a/chromeos/network/onc/onc_translator_onc_to_shill.cc b/chromeos/network/onc/onc_translator_onc_to_shill.cc index 9afae32..8af78d5 100644 --- a/chromeos/network/onc/onc_translator_onc_to_shill.cc +++ b/chromeos/network/onc/onc_translator_onc_to_shill.cc @@ -52,6 +52,7 @@ class LocalTranslator { void TranslateFields(); private: + void TranslateEthernet(); void TranslateOpenVPN(); void TranslateVPN(); void TranslateWiFi(); @@ -86,6 +87,8 @@ class LocalTranslator { void LocalTranslator::TranslateFields() { if (onc_signature_ == &kNetworkConfigurationSignature) TranslateNetworkConfiguration(); + else if (onc_signature_ == &kEthernetSignature) + TranslateEthernet(); else if (onc_signature_ == &kVPNSignature) TranslateVPN(); else if (onc_signature_ == &kOpenVPNSignature) @@ -98,6 +101,20 @@ void LocalTranslator::TranslateFields() { CopyFieldsAccordingToSignature(); } +void LocalTranslator::TranslateEthernet() { + std::string authentication; + onc_object_->GetStringWithoutPathExpansion(ethernet::kAuthentication, + &authentication); + + const char* shill_type = flimflam::kTypeEthernet; + if (authentication == ethernet::k8021X) + shill_type = shill::kTypeEthernetEap; + shill_dictionary_->SetStringWithoutPathExpansion(flimflam::kTypeProperty, + shill_type); + + CopyFieldsAccordingToSignature(); +} + void LocalTranslator::TranslateOpenVPN() { // Shill supports only one RemoteCertKU but ONC a list. // Copy only the first entry if existing. @@ -171,14 +188,17 @@ void LocalTranslator::TranslateEAP() { void LocalTranslator::TranslateNetworkConfiguration() { std::string type; onc_object_->GetStringWithoutPathExpansion(network_config::kType, &type); - TranslateWithTableAndSet(type, kNetworkTypeTable, flimflam::kTypeProperty); + + // Set the type except for Ethernet which is set in TranslateEthernet. + if (type != network_type::kEthernet) + TranslateWithTableAndSet(type, kNetworkTypeTable, flimflam::kTypeProperty); // Shill doesn't allow setting the name for non-VPN networks. if (type == network_type::kVPN) { std::string name; onc_object_->GetStringWithoutPathExpansion(network_config::kName, &name); - shill_dictionary_->SetStringWithoutPathExpansion( - flimflam::kNameProperty, name); + shill_dictionary_->SetStringWithoutPathExpansion(flimflam::kNameProperty, + name); } CopyFieldsAccordingToSignature(); diff --git a/chromeos/network/onc/onc_translator_shill_to_onc.cc b/chromeos/network/onc/onc_translator_shill_to_onc.cc index 0bd82ea..80e00ba 100644 --- a/chromeos/network/onc/onc_translator_shill_to_onc.cc +++ b/chromeos/network/onc/onc_translator_shill_to_onc.cc @@ -58,6 +58,7 @@ class ShillToONCTranslator { scoped_ptr<base::DictionaryValue> CreateTranslatedONCObject(); private: + void TranslateEthernet(); void TranslateOpenVPN(); void TranslateVPN(); void TranslateWiFiWithState(); @@ -109,6 +110,8 @@ ShillToONCTranslator::CreateTranslatedONCObject() { onc_object_.reset(new base::DictionaryValue); if (onc_signature_ == &kNetworkWithStateSignature) { TranslateNetworkWithState(); + } else if (onc_signature_ == &kEthernetSignature) { + TranslateEthernet(); } else if (onc_signature_ == &kVPNSignature) { TranslateVPN(); } else if (onc_signature_ == &kOpenVPNSignature) { @@ -123,6 +126,17 @@ ShillToONCTranslator::CreateTranslatedONCObject() { return onc_object_.Pass(); } +void ShillToONCTranslator::TranslateEthernet() { + std::string shill_network_type; + shill_dictionary_->GetStringWithoutPathExpansion(flimflam::kTypeProperty, + &shill_network_type); + const char* onc_auth = ethernet::kNone; + if (shill_network_type == shill::kTypeEthernetEap) + onc_auth = ethernet::k8021X; + onc_object_->SetStringWithoutPathExpansion(ethernet::kAuthentication, + onc_auth); +} + void ShillToONCTranslator::TranslateOpenVPN() { // Shill supports only one RemoteCertKU but ONC requires a list. If existing, // wraps the value into a list. @@ -219,14 +233,21 @@ void ShillToONCTranslator::TranslateCellularWithState() { } void ShillToONCTranslator::TranslateNetworkWithState() { - TranslateWithTableAndSet(flimflam::kTypeProperty, kNetworkTypeTable, - network_config::kType); CopyPropertiesAccordingToSignature(); - std::string network_type; - if (onc_object_->GetStringWithoutPathExpansion(network_config::kType, - &network_type)) { - TranslateAndAddNestedObject(network_type); + std::string shill_network_type; + shill_dictionary_->GetStringWithoutPathExpansion(flimflam::kTypeProperty, + &shill_network_type); + std::string onc_network_type = network_type::kEthernet; + if (shill_network_type != flimflam::kTypeEthernet && + shill_network_type != shill::kTypeEthernetEap) { + TranslateStringToONC( + kNetworkTypeTable, shill_network_type, &onc_network_type); + } + if (!onc_network_type.empty()) { + onc_object_->SetStringWithoutPathExpansion(network_config::kType, + onc_network_type); + TranslateAndAddNestedObject(onc_network_type); } // Since Name is a read only field in Shill unless it's a VPN, it is copied diff --git a/chromeos/network/onc/onc_translator_unittest.cc b/chromeos/network/onc/onc_translator_unittest.cc index 6bc7b6a..12f952f 100644 --- a/chromeos/network/onc/onc_translator_unittest.cc +++ b/chromeos/network/onc/onc_translator_unittest.cc @@ -42,7 +42,9 @@ INSTANTIATE_TEST_CASE_P( ONCTranslatorOncToShillTest, ONCTranslatorOncToShillTest, ::testing::Values( - std::make_pair("managed_ethernet.onc", "shill_ethernet.json"), + std::make_pair("ethernet.onc", "shill_ethernet.json"), + std::make_pair("ethernet_with_eap_and_cert_pems.onc", + "shill_ethernet_with_eap.json"), std::make_pair("valid_wifi_psk.onc", "shill_wifi_psk.json"), std::make_pair("wifi_clientcert_with_cert_pems.onc", "shill_wifi_clientcert.json"), @@ -86,6 +88,10 @@ INSTANTIATE_TEST_CASE_P( ONCTranslatorShillToOncTest, ONCTranslatorShillToOncTest, ::testing::Values( + std::make_pair("shill_ethernet.json", + "translation_of_shill_ethernet.onc"), + std::make_pair("shill_ethernet_with_eap.json", + "translation_of_shill_ethernet_with_eap.onc"), std::make_pair("shill_wifi_clientcert.json", "translation_of_shill_wifi_clientcert.onc"), std::make_pair("shill_wifi_wpa1.json", diff --git a/chromeos/network/onc/onc_validator_unittest.cc b/chromeos/network/onc/onc_validator_unittest.cc index d839466..3ddd679 100644 --- a/chromeos/network/onc/onc_validator_unittest.cc +++ b/chromeos/network/onc/onc_validator_unittest.cc @@ -154,7 +154,10 @@ INSTANTIATE_TEST_CASE_P( OncParams("managed_vpn.onc", &kNetworkConfigurationSignature, true), - OncParams("managed_ethernet.onc", + OncParams("ethernet.onc", + &kNetworkConfigurationSignature, + true), + OncParams("ethernet_with_eap.onc", &kNetworkConfigurationSignature, true), OncParams("translation_of_shill_wifi_with_state.onc", |