onc_translation_tables.cc revision 03b57e008b61dfcb1fbad3aea950ae0e001748b0
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 3// found in the LICENSE file. 4 5#include "chromeos/network/onc/onc_translation_tables.h" 6 7#include <cstddef> 8 9#include "base/logging.h" 10#include "components/onc/onc_constants.h" 11#include "third_party/cros_system_api/dbus/service_constants.h" 12 13namespace chromeos { 14namespace onc { 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 22namespace { 23 24const FieldTranslationEntry eap_fields[] = { 25 { ::onc::eap::kAnonymousIdentity, shill::kEapAnonymousIdentityProperty}, 26 { ::onc::eap::kIdentity, shill::kEapIdentityProperty}, 27 // This field is converted during translation, see onc_translator_*. 28 // { ::onc::eap::kInner, shill::kEapPhase2AuthProperty }, 29 30 // This field is converted during translation, see onc_translator_*. 31 // { ::onc::eap::kOuter, shill::kEapMethodProperty }, 32 { ::onc::eap::kPassword, shill::kEapPasswordProperty}, 33 { ::onc::eap::kSaveCredentials, shill::kSaveCredentialsProperty}, 34 { ::onc::eap::kServerCAPEMs, shill::kEapCaCertPemProperty}, 35 { ::onc::eap::kUseSystemCAs, shill::kEapUseSystemCasProperty}, 36 {NULL}}; 37 38const FieldTranslationEntry ipsec_fields[] = { 39 // Ignored by Shill, not necessary to synchronize. 40 // { ::onc::ipsec::kAuthenticationType, shill::kL2tpIpsecAuthenticationType 41 // }, 42 { ::onc::ipsec::kGroup, shill::kL2tpIpsecTunnelGroupProperty}, 43 // Ignored by Shill, not necessary to synchronize. 44 // { ::onc::ipsec::kIKEVersion, shill::kL2tpIpsecIkeVersion }, 45 { ::onc::ipsec::kPSK, shill::kL2tpIpsecPskProperty}, 46 // This field is converted during translation, see onc_translator_*. 47 // { ::onc::vpn::kSaveCredentials, shill::kSaveCredentialsProperty}, 48 { ::onc::ipsec::kServerCAPEMs, shill::kL2tpIpsecCaCertPemProperty}, 49 {NULL}}; 50 51const FieldTranslationEntry xauth_fields[] = { 52 { ::onc::vpn::kPassword, shill::kL2tpIpsecXauthPasswordProperty}, 53 { ::onc::vpn::kUsername, shill::kL2tpIpsecXauthUserProperty}, 54 {NULL}}; 55 56const FieldTranslationEntry l2tp_fields[] = { 57 { ::onc::vpn::kPassword, shill::kL2tpIpsecPasswordProperty}, 58 // We don't synchronize l2tp's SaveCredentials field for now, as Shill 59 // doesn't support separate settings for ipsec and l2tp. 60 // { ::onc::vpn::kSaveCredentials, &kBoolSignature }, 61 { ::onc::vpn::kUsername, shill::kL2tpIpsecUserProperty}, {NULL}}; 62 63const FieldTranslationEntry openvpn_fields[] = { 64 { ::onc::openvpn::kAuth, shill::kOpenVPNAuthProperty}, 65 { ::onc::openvpn::kAuthNoCache, shill::kOpenVPNAuthNoCacheProperty}, 66 { ::onc::openvpn::kAuthRetry, shill::kOpenVPNAuthRetryProperty}, 67 { ::onc::openvpn::kCipher, shill::kOpenVPNCipherProperty}, 68 { ::onc::openvpn::kCompLZO, shill::kOpenVPNCompLZOProperty}, 69 { ::onc::openvpn::kCompNoAdapt, shill::kOpenVPNCompNoAdaptProperty}, 70 { ::onc::openvpn::kIgnoreDefaultRoute, 71 shill::kOpenVPNIgnoreDefaultRouteProperty}, 72 { ::onc::openvpn::kKeyDirection, shill::kOpenVPNKeyDirectionProperty}, 73 { ::onc::openvpn::kNsCertType, shill::kOpenVPNNsCertTypeProperty}, 74 { ::onc::vpn::kPassword, shill::kOpenVPNPasswordProperty}, 75 { ::onc::openvpn::kPort, shill::kOpenVPNPortProperty}, 76 { ::onc::openvpn::kProto, shill::kOpenVPNProtoProperty}, 77 { ::onc::openvpn::kPushPeerInfo, shill::kOpenVPNPushPeerInfoProperty}, 78 { ::onc::openvpn::kRemoteCertEKU, shill::kOpenVPNRemoteCertEKUProperty}, 79 // This field is converted during translation, see onc_translator_*. 80 // { ::onc::openvpn::kRemoteCertKU, shill::kOpenVPNRemoteCertKUProperty }, 81 { ::onc::openvpn::kRemoteCertTLS, shill::kOpenVPNRemoteCertTLSProperty}, 82 { ::onc::openvpn::kRenegSec, shill::kOpenVPNRenegSecProperty}, 83 // This field is converted during translation, see onc_translator_*. 84 // { ::onc::vpn::kSaveCredentials, shill::kSaveCredentialsProperty}, 85 { ::onc::openvpn::kServerCAPEMs, shill::kOpenVPNCaCertPemProperty}, 86 { ::onc::openvpn::kServerPollTimeout, 87 shill::kOpenVPNServerPollTimeoutProperty}, 88 { ::onc::openvpn::kShaper, shill::kOpenVPNShaperProperty}, 89 { ::onc::openvpn::kStaticChallenge, shill::kOpenVPNStaticChallengeProperty}, 90 { ::onc::openvpn::kTLSAuthContents, shill::kOpenVPNTLSAuthContentsProperty}, 91 { ::onc::openvpn::kTLSRemote, shill::kOpenVPNTLSRemoteProperty}, 92 { ::onc::vpn::kUsername, shill::kOpenVPNUserProperty}, 93 { ::onc::openvpn::kVerifyHash, shill::kOpenVPNVerifyHashProperty}, 94 {NULL}}; 95 96const FieldTranslationEntry verify_x509_fields[] = { 97 { ::onc::verify_x509::kName, shill::kOpenVPNVerifyX509NameProperty}, 98 { ::onc::verify_x509::kType, shill::kOpenVPNVerifyX509TypeProperty}, 99 {NULL}}; 100 101const FieldTranslationEntry vpn_fields[] = { 102 { ::onc::vpn::kAutoConnect, shill::kAutoConnectProperty}, 103 // These fields are converted during translation, see onc_translator_*. 104 // { ::onc::vpn::kHost, shill::kProviderHostProperty}, 105 // { ::onc::vpn::kType, shill::kProviderTypeProperty }, 106 {NULL}}; 107 108const FieldTranslationEntry wifi_fields[] = { 109 { ::onc::wifi::kAutoConnect, shill::kAutoConnectProperty}, 110 { ::onc::wifi::kBSSID, shill::kWifiBSsid}, 111 { ::onc::wifi::kFrequency, shill::kWifiFrequency}, 112 { ::onc::wifi::kFrequencyList, shill::kWifiFrequencyListProperty}, 113 { ::onc::wifi::kHiddenSSID, shill::kWifiHiddenSsid}, 114 { ::onc::wifi::kPassphrase, shill::kPassphraseProperty}, 115 // This field is converted during translation, see onc_translator_*. 116 // { ::onc::wifi::kSSID, shill::kWifiHexSsid}, 117 // This field is converted during translation, see onc_translator_*. 118 // { ::onc::wifi::kSecurity, shill::kSecurityProperty }, 119 { ::onc::wifi::kSignalStrength, shill::kSignalStrengthProperty}, 120 {NULL}}; 121 122const FieldTranslationEntry cellular_apn_fields[] = { 123 { ::onc::cellular_apn::kName, shill::kApnProperty}, 124 { ::onc::cellular_apn::kUsername, shill::kApnUsernameProperty}, 125 { ::onc::cellular_apn::kPassword, shill::kApnPasswordProperty}, 126 { ::onc::cellular_apn::kLocalizedName, shill::kApnLocalizedNameProperty}, 127 { ::onc::cellular_apn::kLanguage, shill::kApnLanguageProperty}, 128 {NULL}}; 129 130const FieldTranslationEntry cellular_found_network_fields[] = { 131 { ::onc::cellular_found_network::kNetworkId, shill::kNetworkIdProperty}, 132 { ::onc::cellular_found_network::kStatus, shill::kStatusProperty}, 133 { ::onc::cellular_found_network::kTechnology, shill::kTechnologyProperty}, 134 { ::onc::cellular_found_network::kShortName, shill::kShortNameProperty}, 135 { ::onc::cellular_found_network::kLongName, shill::kLongNameProperty}, 136 {NULL}}; 137 138const FieldTranslationEntry cellular_provider_fields[] = { 139 { ::onc::cellular_provider::kCode, shill::kOperatorCodeKey}, 140 { ::onc::cellular_provider::kCountry, shill::kOperatorCountryKey}, 141 { ::onc::cellular_provider::kName, shill::kOperatorNameKey}, 142 {NULL}}; 143 144const FieldTranslationEntry sim_lock_status_fields[] = { 145 { ::onc::sim_lock_status::kLockEnabled, shill::kSIMLockEnabledProperty}, 146 { ::onc::sim_lock_status::kLockType, shill::kSIMLockTypeProperty}, 147 { ::onc::sim_lock_status::kRetriesLeft, shill::kSIMLockRetriesLeftProperty}, 148 {NULL}}; 149 150// This must only contain Service properties and not Device properties. 151// For Device properties see kCellularDeviceTable. 152const FieldTranslationEntry cellular_fields[] = { 153 { ::onc::cellular::kActivationType, shill::kActivationTypeProperty}, 154 { ::onc::cellular::kActivationState, shill::kActivationStateProperty}, 155 { ::onc::cellular::kNetworkTechnology, shill::kNetworkTechnologyProperty}, 156 { ::onc::cellular::kRoamingState, shill::kRoamingStateProperty}, 157 {NULL}}; 158 159const FieldTranslationEntry network_fields[] = { 160 { ::onc::network_config::kGUID, shill::kGuidProperty}, 161 { ::onc::network_config::kConnectable, shill::kConnectableProperty }, 162 { ::onc::network_config::kErrorState, shill::kErrorProperty }, 163 { ::onc::network_config::kPriority, shill::kPriorityProperty }, 164 165 // Shill doesn't allow setting the name for non-VPN networks. 166 // Name is conditionally translated, see onc_translator_*. 167 // { ::onc::network_config::kName, shill::kNameProperty }, 168 169 // Type is converted during translation, see onc_translator_*. 170 // { ::onc::network_config::kType, shill::kTypeProperty }, 171 172 // These fields are converted during translation, see 173 // onc_translator_shill_to_onc.cc. They are only converted when going from 174 // Shill->ONC, and ignored otherwise. 175 // { ::onc::network_config::kConnectionState, shill::kStateProperty }, 176 // { ::onc::network_config::kMacAddress, shill::kAddressProperty }, 177 {NULL}}; 178 179const FieldTranslationEntry ipconfig_fields[] = { 180 { ::onc::ipconfig::kIPAddress, shill::kAddressProperty}, 181 { ::onc::ipconfig::kGateway, shill::kGatewayProperty}, 182 { ::onc::ipconfig::kRoutingPrefix, shill::kPrefixlenProperty}, 183 { ::onc::ipconfig::kNameServers, shill::kNameServersProperty}, 184 // This field is converted during translation, see ShillToONCTranslator:: 185 // TranslateIPConfig. It is only converted from Shill->ONC. 186 // { ::onc::ipconfig::kType, shill::kMethodProperty}, 187 {NULL}}; 188 189struct OncValueTranslationEntry { 190 const OncValueSignature* onc_signature; 191 const FieldTranslationEntry* field_translation_table; 192}; 193 194const OncValueTranslationEntry onc_value_translation_table[] = { 195 { &kEAPSignature, eap_fields }, 196 { &kIPsecSignature, ipsec_fields }, 197 { &kL2TPSignature, l2tp_fields }, 198 { &kXAUTHSignature, xauth_fields }, 199 { &kOpenVPNSignature, openvpn_fields }, 200 { &kVerifyX509Signature, verify_x509_fields }, 201 { &kVPNSignature, vpn_fields }, 202 { &kWiFiSignature, wifi_fields }, 203 { &kWiFiWithStateSignature, wifi_fields }, 204 { &kCellularApnSignature, cellular_apn_fields }, 205 { &kCellularFoundNetworkSignature, cellular_found_network_fields }, 206 { &kCellularProviderSignature, cellular_provider_fields }, 207 { &kSIMLockStatusSignature, sim_lock_status_fields }, 208 { &kCellularSignature, cellular_fields }, 209 { &kCellularWithStateSignature, cellular_fields }, 210 { &kNetworkWithStateSignature, network_fields }, 211 { &kNetworkConfigurationSignature, network_fields }, 212 { &kIPConfigSignature, ipconfig_fields }, 213 { NULL } 214}; 215 216struct NestedShillDictionaryEntry { 217 const OncValueSignature* onc_signature; 218 // NULL terminated list of Shill property keys. 219 const char* const* shill_property_path; 220}; 221 222const char* cellular_apn_property_path_entries[] = { 223 shill::kCellularApnProperty, 224 NULL 225}; 226 227const NestedShillDictionaryEntry nested_shill_dictionaries[] = { 228 { &kCellularApnSignature, cellular_apn_property_path_entries }, 229 { NULL } 230}; 231 232} // namespace 233 234const StringTranslationEntry kNetworkTypeTable[] = { 235 // This mapping is ensured in the translation code. 236 // { network_type::kEthernet, shill::kTypeEthernet }, 237 // { network_type::kEthernet, shill::kTypeEthernetEap }, 238 { ::onc::network_type::kWiFi, shill::kTypeWifi}, 239 { ::onc::network_type::kWimax, shill::kTypeWimax}, 240 { ::onc::network_type::kCellular, shill::kTypeCellular}, 241 { ::onc::network_type::kVPN, shill::kTypeVPN}, 242 {NULL}}; 243 244const StringTranslationEntry kVPNTypeTable[] = { 245 { ::onc::vpn::kTypeL2TP_IPsec, shill::kProviderL2tpIpsec}, 246 { ::onc::vpn::kOpenVPN, shill::kProviderOpenVpn}, {NULL}}; 247 248// The first matching line is chosen. 249const StringTranslationEntry kWiFiSecurityTable[] = { 250 { ::onc::wifi::kSecurityNone, shill::kSecurityNone}, 251 { ::onc::wifi::kWEP_PSK, shill::kSecurityWep}, 252 { ::onc::wifi::kWPA_PSK, shill::kSecurityPsk}, 253 { ::onc::wifi::kWPA_EAP, shill::kSecurity8021x}, 254 { ::onc::wifi::kWPA_PSK, shill::kSecurityRsn}, 255 { ::onc::wifi::kWPA_PSK, shill::kSecurityWpa}, 256 {NULL}}; 257 258const StringTranslationEntry kEAPOuterTable[] = { 259 { ::onc::eap::kPEAP, shill::kEapMethodPEAP}, 260 { ::onc::eap::kEAP_TLS, shill::kEapMethodTLS}, 261 { ::onc::eap::kEAP_TTLS, shill::kEapMethodTTLS}, 262 { ::onc::eap::kLEAP, shill::kEapMethodLEAP}, 263 {NULL}}; 264 265// Translation of the EAP.Inner field in case of EAP.Outer == PEAP 266const StringTranslationEntry kEAP_PEAP_InnerTable[] = { 267 { ::onc::eap::kMD5, shill::kEapPhase2AuthPEAPMD5}, 268 { ::onc::eap::kMSCHAPv2, shill::kEapPhase2AuthPEAPMSCHAPV2}, {NULL}}; 269 270// Translation of the EAP.Inner field in case of EAP.Outer == TTLS 271const StringTranslationEntry kEAP_TTLS_InnerTable[] = { 272 { ::onc::eap::kMD5, shill::kEapPhase2AuthTTLSMD5}, 273 { ::onc::eap::kMSCHAPv2, shill::kEapPhase2AuthTTLSMSCHAPV2}, 274 { ::onc::eap::kPAP, shill::kEapPhase2AuthTTLSPAP}, 275 {NULL}}; 276 277// This must contain only Shill Device properties and no Service properties. 278// For Service properties see cellular_fields. 279const FieldTranslationEntry kCellularDeviceTable[] = { 280 // This field is converted during translation, see onc_translator_*. 281 // { ::onc::cellular::kAPNList, shill::kCellularApnListProperty}, 282 { ::onc::cellular::kAllowRoaming, shill::kCellularAllowRoamingProperty}, 283 { ::onc::cellular::kCarrier, shill::kCarrierProperty}, 284 { ::onc::cellular::kESN, shill::kEsnProperty}, 285 { ::onc::cellular::kFamily, shill::kTechnologyFamilyProperty}, 286 { ::onc::cellular::kFirmwareRevision, shill::kFirmwareRevisionProperty}, 287 // This field is converted during translation, see onc_translator_*. 288 // { ::onc::cellular::kFoundNetworks, shill::kFoundNetworksProperty}, 289 { ::onc::cellular::kHardwareRevision, shill::kHardwareRevisionProperty}, 290 { ::onc::cellular::kHomeProvider, shill::kHomeProviderProperty}, 291 { ::onc::cellular::kICCID, shill::kIccidProperty}, 292 { ::onc::cellular::kIMEI, shill::kImeiProperty}, 293 { ::onc::cellular::kIMSI, shill::kImsiProperty}, 294 { ::onc::cellular::kManufacturer, shill::kManufacturerProperty}, 295 { ::onc::cellular::kMDN, shill::kMdnProperty}, 296 { ::onc::cellular::kMEID, shill::kMeidProperty}, 297 { ::onc::cellular::kMIN, shill::kMinProperty}, 298 { ::onc::cellular::kModelID, shill::kModelIDProperty}, 299 { ::onc::cellular::kPRLVersion, shill::kPRLVersionProperty}, 300 { ::onc::cellular::kProviderRequiresRoaming, 301 shill::kProviderRequiresRoamingProperty}, 302 { ::onc::cellular::kSelectedNetwork, shill::kSelectedNetworkProperty}, 303 // This field is converted during translation, see onc_translator_*. 304 // { ::onc::cellular::kSIMLockStatus, shill::kSIMLockStatusProperty}, 305 { ::onc::cellular::kSIMPresent, shill::kSIMPresentProperty}, 306 { ::onc::cellular::kSupportedCarriers, shill::kSupportedCarriersProperty}, 307 { ::onc::cellular::kSupportNetworkScan, shill::kSupportNetworkScanProperty}, 308 {NULL}}; 309 310const FieldTranslationEntry* GetFieldTranslationTable( 311 const OncValueSignature& onc_signature) { 312 for (const OncValueTranslationEntry* it = onc_value_translation_table; 313 it->onc_signature != NULL; ++it) { 314 if (it->onc_signature == &onc_signature) 315 return it->field_translation_table; 316 } 317 return NULL; 318} 319 320std::vector<std::string> GetPathToNestedShillDictionary( 321 const OncValueSignature& onc_signature) { 322 std::vector<std::string> shill_property_path; 323 for (const NestedShillDictionaryEntry* it = nested_shill_dictionaries; 324 it->onc_signature != NULL; ++it) { 325 if (it->onc_signature == &onc_signature) { 326 for (const char* const* key = it->shill_property_path; *key != NULL; 327 ++key) { 328 shill_property_path.push_back(std::string(*key)); 329 } 330 break; 331 } 332 } 333 return shill_property_path; 334} 335 336bool GetShillPropertyName(const std::string& onc_field_name, 337 const FieldTranslationEntry table[], 338 std::string* shill_property_name) { 339 for (const FieldTranslationEntry* it = table; 340 it->onc_field_name != NULL; ++it) { 341 if (it->onc_field_name != onc_field_name) 342 continue; 343 *shill_property_name = it->shill_property_name; 344 return true; 345 } 346 return false; 347} 348 349bool TranslateStringToShill(const StringTranslationEntry table[], 350 const std::string& onc_value, 351 std::string* shill_value) { 352 for (int i = 0; table[i].onc_value != NULL; ++i) { 353 if (onc_value != table[i].onc_value) 354 continue; 355 *shill_value = table[i].shill_value; 356 return true; 357 } 358 LOG(ERROR) << "Value '" << onc_value << "' cannot be translated to Shill"; 359 return false; 360} 361 362bool TranslateStringToONC(const StringTranslationEntry table[], 363 const std::string& shill_value, 364 std::string* onc_value) { 365 for (int i = 0; table[i].shill_value != NULL; ++i) { 366 if (shill_value != table[i].shill_value) 367 continue; 368 *onc_value = table[i].onc_value; 369 return true; 370 } 371 LOG(ERROR) << "Value '" << shill_value << "' cannot be translated to ONC"; 372 return false; 373} 374 375} // namespace onc 376} // namespace chromeos 377