onc_translation_tables.cc revision 116680a4aac90f2aa7413d9095a592090648e557
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 {NULL}}; 126 127const FieldTranslationEntry cellular_provider_fields[] = { 128 { ::onc::cellular_provider::kCode, shill::kOperatorCodeKey}, 129 { ::onc::cellular_provider::kCountry, shill::kOperatorCountryKey}, 130 { ::onc::cellular_provider::kName, shill::kOperatorNameKey}, 131 {NULL}}; 132 133// This must only contain Service properties and not Device properties. 134// For Device properties see kCellularDeviceTable. 135const FieldTranslationEntry cellular_fields[] = { 136 { ::onc::cellular::kActivateOverNonCellularNetwork, 137 shill::kActivateOverNonCellularNetworkProperty}, 138 { ::onc::cellular::kActivationState, shill::kActivationStateProperty}, 139 { ::onc::cellular::kNetworkTechnology, shill::kNetworkTechnologyProperty}, 140 { ::onc::cellular::kRoamingState, shill::kRoamingStateProperty}, 141 {NULL}}; 142 143const FieldTranslationEntry network_fields[] = { 144 { ::onc::network_config::kGUID, shill::kGuidProperty}, 145 { ::onc::network_config::kConnectable, shill::kConnectableProperty }, 146 { ::onc::network_config::kErrorState, shill::kErrorProperty }, 147 148 // Shill doesn't allow setting the name for non-VPN networks. 149 // Name is conditionally translated, see onc_translator_*. 150 // { ::onc::network_config::kName, shill::kNameProperty }, 151 152 // Type is converted during translation, see onc_translator_*. 153 // { ::onc::network_config::kType, shill::kTypeProperty }, 154 155 // These fields are converted during translation, see 156 // onc_translator_shill_to_onc.cc. They are only converted when going from 157 // Shill->ONC, and ignored otherwise. 158 // { ::onc::network_config::kConnectionState, shill::kStateProperty }, 159 // { ::onc::network_config::kMacAddress, shill::kAddressProperty }, 160 {NULL}}; 161 162const FieldTranslationEntry ipconfig_fields[] = { 163 { ::onc::ipconfig::kIPAddress, shill::kAddressProperty}, 164 { ::onc::ipconfig::kGateway, shill::kGatewayProperty}, 165 { ::onc::ipconfig::kRoutingPrefix, shill::kPrefixlenProperty}, 166 { ::onc::ipconfig::kNameServers, shill::kNameServersProperty}, 167 // This field is converted during translation, see ShillToONCTranslator:: 168 // TranslateIPConfig. It is only converted from Shill->ONC. 169 // { ::onc::ipconfig::kType, shill::kMethodProperty}, 170 {NULL}}; 171 172struct OncValueTranslationEntry { 173 const OncValueSignature* onc_signature; 174 const FieldTranslationEntry* field_translation_table; 175}; 176 177const OncValueTranslationEntry onc_value_translation_table[] = { 178 { &kEAPSignature, eap_fields }, 179 { &kIPsecSignature, ipsec_fields }, 180 { &kL2TPSignature, l2tp_fields }, 181 { &kXAUTHSignature, xauth_fields }, 182 { &kOpenVPNSignature, openvpn_fields }, 183 { &kVerifyX509Signature, verify_x509_fields }, 184 { &kVPNSignature, vpn_fields }, 185 { &kWiFiSignature, wifi_fields }, 186 { &kWiFiWithStateSignature, wifi_fields }, 187 { &kCellularApnSignature, cellular_apn_fields }, 188 { &kCellularProviderSignature, cellular_provider_fields }, 189 { &kCellularSignature, cellular_fields }, 190 { &kCellularWithStateSignature, cellular_fields }, 191 { &kNetworkWithStateSignature, network_fields }, 192 { &kNetworkConfigurationSignature, network_fields }, 193 { &kIPConfigSignature, ipconfig_fields }, 194 { NULL } 195}; 196 197struct NestedShillDictionaryEntry { 198 const OncValueSignature* onc_signature; 199 // NULL terminated list of Shill property keys. 200 const char* const* shill_property_path; 201}; 202 203const char* cellular_apn_property_path_entries[] = { 204 shill::kCellularApnProperty, 205 NULL 206}; 207 208const NestedShillDictionaryEntry nested_shill_dictionaries[] = { 209 { &kCellularApnSignature, cellular_apn_property_path_entries }, 210 { NULL } 211}; 212 213} // namespace 214 215const StringTranslationEntry kNetworkTypeTable[] = { 216 // This mapping is ensured in the translation code. 217 // { network_type::kEthernet, shill::kTypeEthernet }, 218 // { network_type::kEthernet, shill::kTypeEthernetEap }, 219 { ::onc::network_type::kWiFi, shill::kTypeWifi}, 220 { ::onc::network_type::kWimax, shill::kTypeWimax}, 221 { ::onc::network_type::kCellular, shill::kTypeCellular}, 222 { ::onc::network_type::kVPN, shill::kTypeVPN}, 223 {NULL}}; 224 225const StringTranslationEntry kVPNTypeTable[] = { 226 { ::onc::vpn::kTypeL2TP_IPsec, shill::kProviderL2tpIpsec}, 227 { ::onc::vpn::kOpenVPN, shill::kProviderOpenVpn}, {NULL}}; 228 229// The first matching line is chosen. 230const StringTranslationEntry kWiFiSecurityTable[] = { 231 { ::onc::wifi::kSecurityNone, shill::kSecurityNone}, 232 { ::onc::wifi::kWEP_PSK, shill::kSecurityWep}, 233 { ::onc::wifi::kWPA_PSK, shill::kSecurityPsk}, 234 { ::onc::wifi::kWPA_EAP, shill::kSecurity8021x}, 235 { ::onc::wifi::kWPA_PSK, shill::kSecurityRsn}, 236 { ::onc::wifi::kWPA_PSK, shill::kSecurityWpa}, 237 {NULL}}; 238 239const StringTranslationEntry kEAPOuterTable[] = { 240 { ::onc::eap::kPEAP, shill::kEapMethodPEAP}, 241 { ::onc::eap::kEAP_TLS, shill::kEapMethodTLS}, 242 { ::onc::eap::kEAP_TTLS, shill::kEapMethodTTLS}, 243 { ::onc::eap::kLEAP, shill::kEapMethodLEAP}, 244 {NULL}}; 245 246// Translation of the EAP.Inner field in case of EAP.Outer == PEAP 247const StringTranslationEntry kEAP_PEAP_InnerTable[] = { 248 { ::onc::eap::kMD5, shill::kEapPhase2AuthPEAPMD5}, 249 { ::onc::eap::kMSCHAPv2, shill::kEapPhase2AuthPEAPMSCHAPV2}, {NULL}}; 250 251// Translation of the EAP.Inner field in case of EAP.Outer == TTLS 252const StringTranslationEntry kEAP_TTLS_InnerTable[] = { 253 { ::onc::eap::kMD5, shill::kEapPhase2AuthTTLSMD5}, 254 { ::onc::eap::kMSCHAPv2, shill::kEapPhase2AuthTTLSMSCHAPV2}, 255 { ::onc::eap::kPAP, shill::kEapPhase2AuthTTLSPAP}, 256 {NULL}}; 257 258// This must contain only Shill Device properties and no Service properties. 259// For Service properties see cellular_fields. 260const FieldTranslationEntry kCellularDeviceTable[] = { 261 { ::onc::cellular::kAllowRoaming, shill::kCellularAllowRoamingProperty}, 262 { ::onc::cellular::kCarrier, shill::kCarrierProperty}, 263 { ::onc::cellular::kESN, shill::kEsnProperty}, 264 { ::onc::cellular::kFamily, shill::kTechnologyFamilyProperty}, 265 { ::onc::cellular::kFirmwareRevision, shill::kFirmwareRevisionProperty}, 266 { ::onc::cellular::kFoundNetworks, shill::kFoundNetworksProperty}, 267 { ::onc::cellular::kHardwareRevision, shill::kHardwareRevisionProperty}, 268 { ::onc::cellular::kHomeProvider, shill::kHomeProviderProperty}, 269 { ::onc::cellular::kICCID, shill::kIccidProperty}, 270 { ::onc::cellular::kIMEI, shill::kImeiProperty}, 271 { ::onc::cellular::kIMSI, shill::kImsiProperty}, 272 { ::onc::cellular::kManufacturer, shill::kManufacturerProperty}, 273 { ::onc::cellular::kMDN, shill::kMdnProperty}, 274 { ::onc::cellular::kMEID, shill::kMeidProperty}, 275 { ::onc::cellular::kMIN, shill::kMinProperty}, 276 { ::onc::cellular::kModelID, shill::kModelIDProperty}, 277 { ::onc::cellular::kPRLVersion, shill::kPRLVersionProperty}, 278 { ::onc::cellular::kProviderRequiresRoaming, 279 shill::kProviderRequiresRoamingProperty}, 280 { ::onc::cellular::kSelectedNetwork, shill::kSelectedNetworkProperty}, 281 { ::onc::cellular::kSIMLockEnabled, shill::kSIMLockEnabledProperty}, 282 { ::onc::cellular::kSIMLockStatus, shill::kSIMLockStatusProperty}, 283 { ::onc::cellular::kSIMLockType, shill::kSIMLockTypeProperty}, 284 { ::onc::cellular::kSIMPresent, shill::kSIMPresentProperty}, 285 { ::onc::cellular::kSupportedCarriers, shill::kSupportedCarriersProperty}, 286 { ::onc::cellular::kSupportNetworkScan, shill::kSupportNetworkScanProperty}, 287 {NULL}}; 288 289const FieldTranslationEntry* GetFieldTranslationTable( 290 const OncValueSignature& onc_signature) { 291 for (const OncValueTranslationEntry* it = onc_value_translation_table; 292 it->onc_signature != NULL; ++it) { 293 if (it->onc_signature == &onc_signature) 294 return it->field_translation_table; 295 } 296 return NULL; 297} 298 299std::vector<std::string> GetPathToNestedShillDictionary( 300 const OncValueSignature& onc_signature) { 301 std::vector<std::string> shill_property_path; 302 for (const NestedShillDictionaryEntry* it = nested_shill_dictionaries; 303 it->onc_signature != NULL; ++it) { 304 if (it->onc_signature == &onc_signature) { 305 for (const char* const* key = it->shill_property_path; *key != NULL; 306 ++key) { 307 shill_property_path.push_back(std::string(*key)); 308 } 309 break; 310 } 311 } 312 return shill_property_path; 313} 314 315bool GetShillPropertyName(const std::string& onc_field_name, 316 const FieldTranslationEntry table[], 317 std::string* shill_property_name) { 318 for (const FieldTranslationEntry* it = table; 319 it->onc_field_name != NULL; ++it) { 320 if (it->onc_field_name != onc_field_name) 321 continue; 322 *shill_property_name = it->shill_property_name; 323 return true; 324 } 325 return false; 326} 327 328bool TranslateStringToShill(const StringTranslationEntry table[], 329 const std::string& onc_value, 330 std::string* shill_value) { 331 for (int i = 0; table[i].onc_value != NULL; ++i) { 332 if (onc_value != table[i].onc_value) 333 continue; 334 *shill_value = table[i].shill_value; 335 return true; 336 } 337 LOG(ERROR) << "Value '" << onc_value << "' cannot be translated to Shill"; 338 return false; 339} 340 341bool TranslateStringToONC(const StringTranslationEntry table[], 342 const std::string& shill_value, 343 std::string* onc_value) { 344 for (int i = 0; table[i].shill_value != NULL; ++i) { 345 if (shill_value != table[i].shill_value) 346 continue; 347 *onc_value = table[i].onc_value; 348 return true; 349 } 350 LOG(ERROR) << "Value '" << shill_value << "' cannot be translated to ONC"; 351 return false; 352} 353 354} // namespace onc 355} // namespace chromeos 356