| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chromeos/network/onc/onc_translation_tables.h" | 5 #include "chromeos/network/onc/onc_translation_tables.h" |
| 6 | 6 |
| 7 #include <cstddef> | 7 #include <cstddef> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "chromeos/network/onc/onc_constants.h" | 10 #include "chromeos/network/onc/onc_constants.h" |
| 11 #include "third_party/cros_system_api/dbus/service_constants.h" | 11 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 12 | 12 |
| 13 namespace chromeos { | 13 namespace chromeos { |
| 14 namespace onc { | 14 namespace onc { |
| 15 | 15 |
| 16 // CertificatePattern is converted with function CreateUIData(...) to UIData |
| 17 // stored in Shill. |
| 18 // |
| 19 // Proxy settings are converted to Shill by function |
| 20 // ConvertOncProxySettingsToProxyConfig(...). |
| 21 // |
| 22 // Translation of IPConfig objects is not supported, yet. |
| 23 |
| 24 namespace { |
| 25 |
| 26 const FieldTranslationEntry eap_fields[] = { |
| 27 { eap::kAnonymousIdentity, flimflam::kEapAnonymousIdentityProperty }, |
| 28 { eap::kIdentity, flimflam::kEapIdentityProperty }, |
| 29 // This field is converted during translation, see onc_translator_*. |
| 30 // { eap::kInner, flimflam::kEapPhase2AuthProperty }, |
| 31 |
| 32 // This field is converted during translation, see onc_translator_*. |
| 33 // { eap::kOuter, flimflam::kEapMethodProperty }, |
| 34 { eap::kPassword, flimflam::kEapPasswordProperty }, |
| 35 { eap::kSaveCredentials, flimflam::kSaveCredentialsProperty }, |
| 36 { eap::kServerCARef, flimflam::kEapCaCertNssProperty }, |
| 37 { eap::kUseSystemCAs, flimflam::kEapUseSystemCasProperty }, |
| 38 { NULL } |
| 39 }; |
| 40 |
| 41 const FieldTranslationEntry ipsec_fields[] = { |
| 42 // Ignored by Shill, not necessary to synchronize. |
| 43 // { vpn::kAuthenticationType, flimflam::kL2tpIpsecAuthenticationType }, |
| 44 { vpn::kGroup, flimflam::kL2tpIpsecGroupNameProperty }, |
| 45 // Ignored by Shill, not necessary to synchronize. |
| 46 // { vpn::kIKEVersion, flimflam::kL2tpIpsecIkeVersion }, |
| 47 { vpn::kPSK, flimflam::kL2tpIpsecPskProperty }, |
| 48 { vpn::kSaveCredentials, flimflam::kSaveCredentialsProperty }, |
| 49 { vpn::kServerCARef, flimflam::kL2tpIpsecCaCertNssProperty }, |
| 50 { NULL } |
| 51 }; |
| 52 |
| 53 const FieldTranslationEntry l2tp_fields[] = { |
| 54 { vpn::kPassword, flimflam::kL2tpIpsecPasswordProperty }, |
| 55 // We don't synchronize l2tp's SaveCredentials field for now, as Shill doesn't |
| 56 // support separate settings for ipsec and l2tp. |
| 57 // { vpn::kSaveCredentials, &kBoolSignature }, |
| 58 { vpn::kUsername, flimflam::kL2tpIpsecUserProperty }, |
| 59 { NULL } |
| 60 }; |
| 61 |
| 62 const FieldTranslationEntry openvpn_fields[] = { |
| 63 { vpn::kAuth, flimflam::kOpenVPNAuthProperty }, |
| 64 { vpn::kAuthNoCache, flimflam::kOpenVPNAuthNoCacheProperty }, |
| 65 { vpn::kAuthRetry, flimflam::kOpenVPNAuthRetryProperty }, |
| 66 { vpn::kCipher, flimflam::kOpenVPNCipherProperty }, |
| 67 { vpn::kCompLZO, flimflam::kOpenVPNCompLZOProperty }, |
| 68 { vpn::kCompNoAdapt, flimflam::kOpenVPNCompNoAdaptProperty }, |
| 69 { vpn::kKeyDirection, flimflam::kOpenVPNKeyDirectionProperty }, |
| 70 { vpn::kNsCertType, flimflam::kOpenVPNNsCertTypeProperty }, |
| 71 { vpn::kPassword, flimflam::kOpenVPNPasswordProperty }, |
| 72 { vpn::kPort, flimflam::kOpenVPNPortProperty }, |
| 73 { vpn::kProto, flimflam::kOpenVPNProtoProperty }, |
| 74 { vpn::kPushPeerInfo, flimflam::kOpenVPNPushPeerInfoProperty }, |
| 75 { vpn::kRemoteCertEKU, flimflam::kOpenVPNRemoteCertEKUProperty }, |
| 76 // This field is converted during translation, see onc_translator_*. |
| 77 // { vpn::kRemoteCertKU, flimflam::kOpenVPNRemoteCertKUProperty }, |
| 78 { vpn::kRemoteCertTLS, flimflam::kOpenVPNRemoteCertTLSProperty }, |
| 79 { vpn::kRenegSec, flimflam::kOpenVPNRenegSecProperty }, |
| 80 { vpn::kSaveCredentials, flimflam::kSaveCredentialsProperty }, |
| 81 { vpn::kServerCARef, flimflam::kOpenVPNCaCertNSSProperty }, |
| 82 { vpn::kServerPollTimeout, flimflam::kOpenVPNServerPollTimeoutProperty }, |
| 83 { vpn::kShaper, flimflam::kOpenVPNShaperProperty }, |
| 84 { vpn::kStaticChallenge, flimflam::kOpenVPNStaticChallengeProperty }, |
| 85 { vpn::kTLSAuthContents, flimflam::kOpenVPNTLSAuthContentsProperty }, |
| 86 { vpn::kTLSRemote, flimflam::kOpenVPNTLSRemoteProperty }, |
| 87 { vpn::kUsername, flimflam::kOpenVPNUserProperty }, |
| 88 { NULL } |
| 89 }; |
| 90 |
| 91 const FieldTranslationEntry vpn_fields[] = { |
| 92 { vpn::kAutoConnect, flimflam::kAutoConnectProperty }, |
| 93 { vpn::kHost, flimflam::kProviderHostProperty }, |
| 94 // This field is converted during translation, see onc_translator_*. |
| 95 // { vpn::kType, flimflam::kProviderTypeProperty }, |
| 96 { NULL } |
| 97 }; |
| 98 |
| 99 const FieldTranslationEntry wifi_fields[] = { |
| 100 { wifi::kAutoConnect, flimflam::kAutoConnectProperty }, |
| 101 { wifi::kBSSID, flimflam::kWifiBSsid }, |
| 102 { wifi::kHiddenSSID, flimflam::kWifiHiddenSsid }, |
| 103 { wifi::kPassphrase, flimflam::kPassphraseProperty }, |
| 104 { wifi::kSSID, flimflam::kSSIDProperty }, |
| 105 // This field is converted during translation, see onc_translator_*. |
| 106 // { wifi::kSecurity, flimflam::kSecurityProperty }, |
| 107 { wifi::kSignalStrength, flimflam::kSignalStrengthProperty }, |
| 108 { NULL } |
| 109 }; |
| 110 |
| 111 const FieldTranslationEntry cellular_with_state_fields[] = { |
| 112 { cellular::kActivateOverNonCellularNetwork, |
| 113 shill::kActivateOverNonCellularNetworkProperty }, |
| 114 { cellular::kActivationState, flimflam::kActivationStateProperty }, |
| 115 { cellular::kAllowRoaming, flimflam::kCellularAllowRoamingProperty }, |
| 116 { cellular::kAPN, flimflam::kApnProperty }, |
| 117 { cellular::kCarrier, flimflam::kCarrierProperty }, |
| 118 { cellular::kESN, flimflam::kEsnProperty }, |
| 119 { cellular::kFamily, flimflam::kTechnologyFamilyProperty }, |
| 120 { cellular::kFirmwareRevision, flimflam::kFirmwareRevisionProperty }, |
| 121 { cellular::kFoundNetworks, flimflam::kFoundNetworksProperty }, |
| 122 { cellular::kHardwareRevision, flimflam::kHardwareRevisionProperty }, |
| 123 { cellular::kHomeProvider, flimflam::kHomeProviderProperty }, |
| 124 { cellular::kICCID, flimflam::kIccidProperty }, |
| 125 { cellular::kIMEI, flimflam::kImeiProperty }, |
| 126 { cellular::kIMSI, flimflam::kImsiProperty }, |
| 127 { cellular::kManufacturer, flimflam::kManufacturerProperty }, |
| 128 { cellular::kMDN, flimflam::kMdnProperty }, |
| 129 { cellular::kMEID, flimflam::kMeidProperty }, |
| 130 { cellular::kMIN, flimflam::kMinProperty }, |
| 131 { cellular::kModelID, flimflam::kModelIDProperty }, |
| 132 { cellular::kNetworkTechnology, flimflam::kNetworkTechnologyProperty }, |
| 133 { cellular::kOperatorCode, flimflam::kOperatorCodeProperty }, |
| 134 { cellular::kOperatorName, flimflam::kOperatorNameProperty }, |
| 135 { cellular::kPRLVersion, flimflam::kPRLVersionProperty }, |
| 136 { cellular::kProviderRequiresRoaming, |
| 137 shill::kProviderRequiresRoamingProperty }, |
| 138 { cellular::kRoamingState, flimflam::kRoamingStateProperty }, |
| 139 { cellular::kSelectedNetwork, flimflam::kSelectedNetworkProperty }, |
| 140 { cellular::kServingOperator, flimflam::kServingOperatorProperty }, |
| 141 { cellular::kSIMLockStatus, flimflam::kSIMLockStatusProperty }, |
| 142 { cellular::kSIMPresent, shill::kSIMPresentProperty }, |
| 143 { cellular::kSupportedCarriers, shill::kSupportedCarriersProperty }, |
| 144 { cellular::kSupportNetworkScan, flimflam::kSupportNetworkScanProperty }, |
| 145 { NULL } |
| 146 }; |
| 147 |
| 148 const FieldTranslationEntry network_fields[] = { |
| 149 // Shill doesn't allow setting the name for non-VPN networks. |
| 150 // This field is conditionally translated, see onc_translator_*. |
| 151 // { network_config::kName, flimflam::kNameProperty }, |
| 152 { network_config::kGUID, flimflam::kGuidProperty }, |
| 153 // This field is converted during translation, see onc_translator_*. |
| 154 // { network_config::kType, flimflam::kTypeProperty }, |
| 155 |
| 156 // This field is converted during translation, see |
| 157 // onc_translator_shill_to_onc.cc. It is only converted when going from |
| 158 // Shill->ONC, and ignored otherwise. |
| 159 // { network_config::kConnectionState, flimflam::kStateProperty }, |
| 160 { NULL } |
| 161 }; |
| 162 |
| 163 const OncValueTranslationEntry onc_value_translation_table[] = { |
| 164 { &kEAPSignature, eap_fields }, |
| 165 { &kIPsecSignature, ipsec_fields }, |
| 166 { &kL2TPSignature, l2tp_fields }, |
| 167 { &kOpenVPNSignature, openvpn_fields }, |
| 168 { &kVPNSignature, vpn_fields }, |
| 169 { &kWiFiSignature, wifi_fields }, |
| 170 { &kWiFiWithStateSignature, wifi_fields }, |
| 171 { &kCellularWithStateSignature, cellular_with_state_fields }, |
| 172 { &kNetworkWithStateSignature, network_fields }, |
| 173 { &kNetworkConfigurationSignature, network_fields }, |
| 174 { NULL } |
| 175 }; |
| 176 |
| 177 } // namespace |
| 178 |
| 16 const StringTranslationEntry kNetworkTypeTable[] = { | 179 const StringTranslationEntry kNetworkTypeTable[] = { |
| 17 { network_type::kEthernet, flimflam::kTypeEthernet }, | 180 { network_type::kEthernet, flimflam::kTypeEthernet }, |
| 18 { network_type::kWiFi, flimflam::kTypeWifi }, | 181 { network_type::kWiFi, flimflam::kTypeWifi }, |
| 19 { network_type::kCellular, flimflam::kTypeCellular }, | 182 { network_type::kCellular, flimflam::kTypeCellular }, |
| 20 { network_type::kVPN, flimflam::kTypeVPN }, | 183 { network_type::kVPN, flimflam::kTypeVPN }, |
| 21 { NULL } | 184 { NULL } |
| 22 }; | 185 }; |
| 23 | 186 |
| 24 const StringTranslationEntry kVPNTypeTable[] = { | 187 const StringTranslationEntry kVPNTypeTable[] = { |
| 25 { vpn::kTypeL2TP_IPsec, flimflam::kProviderL2tpIpsec }, | 188 { vpn::kTypeL2TP_IPsec, flimflam::kProviderL2tpIpsec }, |
| (...skipping 25 matching lines...) Expand all Loading... |
| 51 }; | 214 }; |
| 52 | 215 |
| 53 // Translation of the EAP.Inner field in case of EAP.Outer == TTLS | 216 // Translation of the EAP.Inner field in case of EAP.Outer == TTLS |
| 54 const StringTranslationEntry kEAP_TTLS_InnerTable[] = { | 217 const StringTranslationEntry kEAP_TTLS_InnerTable[] = { |
| 55 { eap::kMD5, flimflam::kEapPhase2AuthTTLSMD5 }, | 218 { eap::kMD5, flimflam::kEapPhase2AuthTTLSMD5 }, |
| 56 { eap::kMSCHAPv2, flimflam::kEapPhase2AuthTTLSMSCHAPV2 }, | 219 { eap::kMSCHAPv2, flimflam::kEapPhase2AuthTTLSMSCHAPV2 }, |
| 57 { eap::kPAP, flimflam::kEapPhase2AuthTTLSPAP }, | 220 { eap::kPAP, flimflam::kEapPhase2AuthTTLSPAP }, |
| 58 { NULL } | 221 { NULL } |
| 59 }; | 222 }; |
| 60 | 223 |
| 224 const FieldTranslationEntry* GetFieldTranslationTable( |
| 225 const OncValueSignature& onc_signature) { |
| 226 for (const OncValueTranslationEntry* it = onc_value_translation_table; |
| 227 it->onc_signature != NULL; ++it) { |
| 228 if (it->onc_signature != &onc_signature) |
| 229 continue; |
| 230 return it->field_translation_table; |
| 231 } |
| 232 return NULL; |
| 233 } |
| 234 |
| 235 bool GetShillPropertyName(const std::string& onc_field_name, |
| 236 const FieldTranslationEntry table[], |
| 237 std::string* shill_property_name) { |
| 238 for (const FieldTranslationEntry* it = table; |
| 239 it->onc_field_name != NULL; ++it) { |
| 240 if (it->onc_field_name != onc_field_name) |
| 241 continue; |
| 242 *shill_property_name = it->shill_property_name; |
| 243 return true; |
| 244 } |
| 245 return false; |
| 246 } |
| 247 |
| 61 bool TranslateStringToShill(const StringTranslationEntry table[], | 248 bool TranslateStringToShill(const StringTranslationEntry table[], |
| 62 const std::string& onc_value, | 249 const std::string& onc_value, |
| 63 std::string* shill_value) { | 250 std::string* shill_value) { |
| 64 for (int i = 0; table[i].onc_value != NULL; ++i) { | 251 for (int i = 0; table[i].onc_value != NULL; ++i) { |
| 65 if (onc_value != table[i].onc_value) | 252 if (onc_value != table[i].onc_value) |
| 66 continue; | 253 continue; |
| 67 *shill_value = table[i].shill_value; | 254 *shill_value = table[i].shill_value; |
| 68 return true; | 255 return true; |
| 69 } | 256 } |
| 70 LOG(ERROR) << "Value '" << onc_value << "cannot be translated to Shill"; | 257 LOG(ERROR) << "Value '" << onc_value << "' cannot be translated to Shill"; |
| 71 return false; | 258 return false; |
| 72 } | 259 } |
| 73 | 260 |
| 74 bool TranslateStringToONC(const StringTranslationEntry table[], | 261 bool TranslateStringToONC(const StringTranslationEntry table[], |
| 75 const std::string& shill_value, | 262 const std::string& shill_value, |
| 76 std::string* onc_value) { | 263 std::string* onc_value) { |
| 77 for (int i = 0; table[i].shill_value != NULL; ++i) { | 264 for (int i = 0; table[i].shill_value != NULL; ++i) { |
| 78 if (shill_value != table[i].shill_value) | 265 if (shill_value != table[i].shill_value) |
| 79 continue; | 266 continue; |
| 80 *onc_value = table[i].onc_value; | 267 *onc_value = table[i].onc_value; |
| 81 return true; | 268 return true; |
| 82 } | 269 } |
| 83 LOG(ERROR) << "Value '" << shill_value << "cannot be translated to ONC"; | 270 LOG(ERROR) << "Value '" << shill_value << "' cannot be translated to ONC"; |
| 84 return false; | 271 return false; |
| 85 } | 272 } |
| 86 | 273 |
| 87 } // namespace onc | 274 } // namespace onc |
| 88 } // namespace chromeos | 275 } // namespace chromeos |
| OLD | NEW |