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