onc_translation_tables.cc revision eb525c5499e34cc9c4b825d6d9e75bb07cc06ace
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::kServerCAPEMs, shill::kEapCaCertPemProperty }, 37 { eap::kUseSystemCAs, flimflam::kEapUseSystemCasProperty }, 38 { NULL } 39}; 40 41const FieldTranslationEntry ipsec_fields[] = { 42 // Ignored by Shill, not necessary to synchronize. 43 // { ipsec::kAuthenticationType, flimflam::kL2tpIpsecAuthenticationType }, 44 { ipsec::kGroup, shill::kL2tpIpsecTunnelGroupProperty }, 45 // Ignored by Shill, not necessary to synchronize. 46 // { ipsec::kIKEVersion, flimflam::kL2tpIpsecIkeVersion }, 47 { ipsec::kPSK, flimflam::kL2tpIpsecPskProperty }, 48 { vpn::kSaveCredentials, flimflam::kSaveCredentialsProperty }, 49 { ipsec::kServerCAPEMs, shill::kL2tpIpsecCaCertPemProperty }, 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 { openvpn::kAuth, flimflam::kOpenVPNAuthProperty }, 64 { openvpn::kAuthNoCache, flimflam::kOpenVPNAuthNoCacheProperty }, 65 { openvpn::kAuthRetry, flimflam::kOpenVPNAuthRetryProperty }, 66 { openvpn::kCipher, flimflam::kOpenVPNCipherProperty }, 67 { openvpn::kCompLZO, flimflam::kOpenVPNCompLZOProperty }, 68 { openvpn::kCompNoAdapt, flimflam::kOpenVPNCompNoAdaptProperty }, 69 { openvpn::kKeyDirection, flimflam::kOpenVPNKeyDirectionProperty }, 70 { openvpn::kNsCertType, flimflam::kOpenVPNNsCertTypeProperty }, 71 { vpn::kPassword, flimflam::kOpenVPNPasswordProperty }, 72 { openvpn::kPort, flimflam::kOpenVPNPortProperty }, 73 { openvpn::kProto, flimflam::kOpenVPNProtoProperty }, 74 { openvpn::kPushPeerInfo, flimflam::kOpenVPNPushPeerInfoProperty }, 75 { openvpn::kRemoteCertEKU, flimflam::kOpenVPNRemoteCertEKUProperty }, 76 // This field is converted during translation, see onc_translator_*. 77 // { openvpn::kRemoteCertKU, flimflam::kOpenVPNRemoteCertKUProperty }, 78 { openvpn::kRemoteCertTLS, flimflam::kOpenVPNRemoteCertTLSProperty }, 79 { openvpn::kRenegSec, flimflam::kOpenVPNRenegSecProperty }, 80 { vpn::kSaveCredentials, flimflam::kSaveCredentialsProperty }, 81 { openvpn::kServerCAPEMs, shill::kOpenVPNCaCertPemProperty }, 82 { openvpn::kServerPollTimeout, flimflam::kOpenVPNServerPollTimeoutProperty }, 83 { openvpn::kShaper, flimflam::kOpenVPNShaperProperty }, 84 { openvpn::kStaticChallenge, flimflam::kOpenVPNStaticChallengeProperty }, 85 { openvpn::kTLSAuthContents, flimflam::kOpenVPNTLSAuthContentsProperty }, 86 { openvpn::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::kFrequency, flimflam::kWifiFrequency }, 103 { wifi::kFrequencyList, shill::kWifiFrequencyListProperty }, 104 { wifi::kHiddenSSID, flimflam::kWifiHiddenSsid }, 105 { wifi::kPassphrase, flimflam::kPassphraseProperty }, 106 { wifi::kSSID, flimflam::kSSIDProperty }, 107 // This field is converted during translation, see onc_translator_*. 108 // { wifi::kSecurity, flimflam::kSecurityProperty }, 109 { wifi::kSignalStrength, flimflam::kSignalStrengthProperty }, 110 { NULL } 111}; 112 113const FieldTranslationEntry cellular_with_state_fields[] = { 114 { cellular::kActivateOverNonCellularNetwork, 115 shill::kActivateOverNonCellularNetworkProperty }, 116 { cellular::kActivationState, flimflam::kActivationStateProperty }, 117 { cellular::kAllowRoaming, flimflam::kCellularAllowRoamingProperty }, 118 { cellular::kAPN, flimflam::kApnProperty }, 119 { cellular::kCarrier, flimflam::kCarrierProperty }, 120 { cellular::kESN, flimflam::kEsnProperty }, 121 { cellular::kFamily, flimflam::kTechnologyFamilyProperty }, 122 { cellular::kFirmwareRevision, flimflam::kFirmwareRevisionProperty }, 123 { cellular::kFoundNetworks, flimflam::kFoundNetworksProperty }, 124 { cellular::kHardwareRevision, flimflam::kHardwareRevisionProperty }, 125 { cellular::kHomeProvider, flimflam::kHomeProviderProperty }, 126 { cellular::kICCID, flimflam::kIccidProperty }, 127 { cellular::kIMEI, flimflam::kImeiProperty }, 128 { cellular::kIMSI, flimflam::kImsiProperty }, 129 { cellular::kManufacturer, flimflam::kManufacturerProperty }, 130 { cellular::kMDN, flimflam::kMdnProperty }, 131 { cellular::kMEID, flimflam::kMeidProperty }, 132 { cellular::kMIN, flimflam::kMinProperty }, 133 { cellular::kModelID, flimflam::kModelIDProperty }, 134 { cellular::kNetworkTechnology, flimflam::kNetworkTechnologyProperty }, 135 { cellular::kOperatorCode, flimflam::kOperatorCodeProperty }, 136 { cellular::kOperatorName, flimflam::kOperatorNameProperty }, 137 { cellular::kPRLVersion, flimflam::kPRLVersionProperty }, 138 { cellular::kProviderRequiresRoaming, 139 shill::kProviderRequiresRoamingProperty }, 140 { cellular::kRoamingState, flimflam::kRoamingStateProperty }, 141 { cellular::kSelectedNetwork, flimflam::kSelectedNetworkProperty }, 142 { cellular::kServingOperator, flimflam::kServingOperatorProperty }, 143 { cellular::kSIMLockStatus, flimflam::kSIMLockStatusProperty }, 144 { cellular::kSIMPresent, shill::kSIMPresentProperty }, 145 { cellular::kSupportedCarriers, shill::kSupportedCarriersProperty }, 146 { cellular::kSupportNetworkScan, flimflam::kSupportNetworkScanProperty }, 147 { NULL } 148}; 149 150const FieldTranslationEntry network_fields[] = { 151 // Shill doesn't allow setting the name for non-VPN networks. 152 // This field is conditionally translated, see onc_translator_*. 153 // { network_config::kName, flimflam::kNameProperty }, 154 { network_config::kGUID, flimflam::kGuidProperty }, 155 // This field is converted during translation, see onc_translator_*. 156 // { network_config::kType, flimflam::kTypeProperty }, 157 158 // This field is converted during translation, see 159 // onc_translator_shill_to_onc.cc. It is only converted when going from 160 // Shill->ONC, and ignored otherwise. 161 // { network_config::kConnectionState, flimflam::kStateProperty }, 162 { NULL } 163}; 164 165const OncValueTranslationEntry onc_value_translation_table[] = { 166 { &kEAPSignature, eap_fields }, 167 { &kIPsecSignature, ipsec_fields }, 168 { &kL2TPSignature, l2tp_fields }, 169 { &kOpenVPNSignature, openvpn_fields }, 170 { &kVPNSignature, vpn_fields }, 171 { &kWiFiSignature, wifi_fields }, 172 { &kWiFiWithStateSignature, wifi_fields }, 173 { &kCellularWithStateSignature, cellular_with_state_fields }, 174 { &kNetworkWithStateSignature, network_fields }, 175 { &kNetworkConfigurationSignature, network_fields }, 176 { NULL } 177}; 178 179} // namespace 180 181const StringTranslationEntry kNetworkTypeTable[] = { 182 { network_type::kEthernet, flimflam::kTypeEthernet }, 183 { network_type::kWiFi, flimflam::kTypeWifi }, 184 { network_type::kCellular, flimflam::kTypeCellular }, 185 { network_type::kVPN, flimflam::kTypeVPN }, 186 { NULL } 187}; 188 189const StringTranslationEntry kVPNTypeTable[] = { 190 { vpn::kTypeL2TP_IPsec, flimflam::kProviderL2tpIpsec }, 191 { vpn::kOpenVPN, flimflam::kProviderOpenVpn }, 192 { NULL } 193}; 194 195// The first matching line is chosen. 196const StringTranslationEntry kWiFiSecurityTable[] = { 197 { wifi::kNone, flimflam::kSecurityNone }, 198 { wifi::kWEP_PSK, flimflam::kSecurityWep }, 199 { wifi::kWPA_PSK, flimflam::kSecurityPsk }, 200 { wifi::kWPA_EAP, flimflam::kSecurity8021x }, 201 { wifi::kWPA_PSK, flimflam::kSecurityRsn }, 202 { NULL } 203}; 204 205const StringTranslationEntry kEAPOuterTable[] = { 206 { eap::kPEAP, flimflam::kEapMethodPEAP }, 207 { eap::kEAP_TLS, flimflam::kEapMethodTLS }, 208 { eap::kEAP_TTLS, flimflam::kEapMethodTTLS }, 209 { eap::kLEAP, flimflam::kEapMethodLEAP }, 210 { NULL } 211}; 212 213// Translation of the EAP.Inner field in case of EAP.Outer == PEAP 214const StringTranslationEntry kEAP_PEAP_InnerTable[] = { 215 { eap::kMD5, flimflam::kEapPhase2AuthPEAPMD5 }, 216 { eap::kMSCHAPv2, flimflam::kEapPhase2AuthPEAPMSCHAPV2 }, 217 { NULL } 218}; 219 220// Translation of the EAP.Inner field in case of EAP.Outer == TTLS 221const StringTranslationEntry kEAP_TTLS_InnerTable[] = { 222 { eap::kMD5, flimflam::kEapPhase2AuthTTLSMD5 }, 223 { eap::kMSCHAPv2, flimflam::kEapPhase2AuthTTLSMSCHAPV2 }, 224 { eap::kPAP, flimflam::kEapPhase2AuthTTLSPAP }, 225 { NULL } 226}; 227 228const FieldTranslationEntry* GetFieldTranslationTable( 229 const OncValueSignature& onc_signature) { 230 for (const OncValueTranslationEntry* it = onc_value_translation_table; 231 it->onc_signature != NULL; ++it) { 232 if (it->onc_signature != &onc_signature) 233 continue; 234 return it->field_translation_table; 235 } 236 return NULL; 237} 238 239bool GetShillPropertyName(const std::string& onc_field_name, 240 const FieldTranslationEntry table[], 241 std::string* shill_property_name) { 242 for (const FieldTranslationEntry* it = table; 243 it->onc_field_name != NULL; ++it) { 244 if (it->onc_field_name != onc_field_name) 245 continue; 246 *shill_property_name = it->shill_property_name; 247 return true; 248 } 249 return false; 250} 251 252bool TranslateStringToShill(const StringTranslationEntry table[], 253 const std::string& onc_value, 254 std::string* shill_value) { 255 for (int i = 0; table[i].onc_value != NULL; ++i) { 256 if (onc_value != table[i].onc_value) 257 continue; 258 *shill_value = table[i].shill_value; 259 return true; 260 } 261 LOG(ERROR) << "Value '" << onc_value << "' cannot be translated to Shill"; 262 return false; 263} 264 265bool TranslateStringToONC(const StringTranslationEntry table[], 266 const std::string& shill_value, 267 std::string* onc_value) { 268 for (int i = 0; table[i].shill_value != NULL; ++i) { 269 if (shill_value != table[i].shill_value) 270 continue; 271 *onc_value = table[i].onc_value; 272 return true; 273 } 274 LOG(ERROR) << "Value '" << shill_value << "' cannot be translated to ONC"; 275 return false; 276} 277 278} // namespace onc 279} // namespace chromeos 280