onc_translation_tables.cc revision 2a99a7e74a7f215066514fe81d2bfa6639d9eddd
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 "chromeos/network/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// 22// Translation of IPConfig objects is not supported, yet. 23 24namespace { 25 26const 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 41const 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 53const 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 62const 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 91const 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 99const 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 111const 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 148const 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 163const 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 179const StringTranslationEntry kNetworkTypeTable[] = { 180 { network_type::kEthernet, flimflam::kTypeEthernet }, 181 { network_type::kWiFi, flimflam::kTypeWifi }, 182 { network_type::kCellular, flimflam::kTypeCellular }, 183 { network_type::kVPN, flimflam::kTypeVPN }, 184 { NULL } 185}; 186 187const StringTranslationEntry kVPNTypeTable[] = { 188 { vpn::kTypeL2TP_IPsec, flimflam::kProviderL2tpIpsec }, 189 { vpn::kOpenVPN, flimflam::kProviderOpenVpn }, 190 { NULL } 191}; 192 193const StringTranslationEntry kWiFiSecurityTable[] = { 194 { wifi::kNone, flimflam::kSecurityNone }, 195 { wifi::kWEP_PSK, flimflam::kSecurityWep }, 196 { wifi::kWPA_PSK, flimflam::kSecurityPsk }, 197 { wifi::kWPA_EAP, flimflam::kSecurity8021x }, 198 { NULL } 199}; 200 201const StringTranslationEntry kEAPOuterTable[] = { 202 { eap::kPEAP, flimflam::kEapMethodPEAP }, 203 { eap::kEAP_TLS, flimflam::kEapMethodTLS }, 204 { eap::kEAP_TTLS, flimflam::kEapMethodTTLS }, 205 { eap::kLEAP, flimflam::kEapMethodLEAP }, 206 { NULL } 207}; 208 209// Translation of the EAP.Inner field in case of EAP.Outer == PEAP 210const StringTranslationEntry kEAP_PEAP_InnerTable[] = { 211 { eap::kMD5, flimflam::kEapPhase2AuthPEAPMD5 }, 212 { eap::kMSCHAPv2, flimflam::kEapPhase2AuthPEAPMSCHAPV2 }, 213 { NULL } 214}; 215 216// Translation of the EAP.Inner field in case of EAP.Outer == TTLS 217const StringTranslationEntry kEAP_TTLS_InnerTable[] = { 218 { eap::kMD5, flimflam::kEapPhase2AuthTTLSMD5 }, 219 { eap::kMSCHAPv2, flimflam::kEapPhase2AuthTTLSMSCHAPV2 }, 220 { eap::kPAP, flimflam::kEapPhase2AuthTTLSPAP }, 221 { NULL } 222}; 223 224const 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 235bool 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 248bool TranslateStringToShill(const StringTranslationEntry table[], 249 const std::string& onc_value, 250 std::string* shill_value) { 251 for (int i = 0; table[i].onc_value != NULL; ++i) { 252 if (onc_value != table[i].onc_value) 253 continue; 254 *shill_value = table[i].shill_value; 255 return true; 256 } 257 LOG(ERROR) << "Value '" << onc_value << "' cannot be translated to Shill"; 258 return false; 259} 260 261bool TranslateStringToONC(const StringTranslationEntry table[], 262 const std::string& shill_value, 263 std::string* onc_value) { 264 for (int i = 0; table[i].shill_value != NULL; ++i) { 265 if (shill_value != table[i].shill_value) 266 continue; 267 *onc_value = table[i].onc_value; 268 return true; 269 } 270 LOG(ERROR) << "Value '" << shill_value << "' cannot be translated to ONC"; 271 return false; 272} 273 274} // namespace onc 275} // namespace chromeos 276