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 13 namespace chromeos { 14 namespace 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 24 namespace { 25 26 const 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 41 const 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 53 const 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 62 const 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 91 const 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 99 const 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 113 const 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 150 const 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 165 const 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 181 const 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 189 const StringTranslationEntry kVPNTypeTable[] = { 190 { vpn::kTypeL2TP_IPsec, flimflam::kProviderL2tpIpsec }, 191 { vpn::kOpenVPN, flimflam::kProviderOpenVpn }, 192 { NULL } 193 }; 194 195 // The first matching line is chosen. 196 const 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 { wifi::kWPA_PSK, flimflam::kSecurityWpa }, 203 { NULL } 204 }; 205 206 const StringTranslationEntry kEAPOuterTable[] = { 207 { eap::kPEAP, flimflam::kEapMethodPEAP }, 208 { eap::kEAP_TLS, flimflam::kEapMethodTLS }, 209 { eap::kEAP_TTLS, flimflam::kEapMethodTTLS }, 210 { eap::kLEAP, flimflam::kEapMethodLEAP }, 211 { NULL } 212 }; 213 214 // Translation of the EAP.Inner field in case of EAP.Outer == PEAP 215 const StringTranslationEntry kEAP_PEAP_InnerTable[] = { 216 { eap::kMD5, flimflam::kEapPhase2AuthPEAPMD5 }, 217 { eap::kMSCHAPv2, flimflam::kEapPhase2AuthPEAPMSCHAPV2 }, 218 { NULL } 219 }; 220 221 // Translation of the EAP.Inner field in case of EAP.Outer == TTLS 222 const StringTranslationEntry kEAP_TTLS_InnerTable[] = { 223 { eap::kMD5, flimflam::kEapPhase2AuthTTLSMD5 }, 224 { eap::kMSCHAPv2, flimflam::kEapPhase2AuthTTLSMSCHAPV2 }, 225 { eap::kPAP, flimflam::kEapPhase2AuthTTLSPAP }, 226 { NULL } 227 }; 228 229 const FieldTranslationEntry* GetFieldTranslationTable( 230 const OncValueSignature& onc_signature) { 231 for (const OncValueTranslationEntry* it = onc_value_translation_table; 232 it->onc_signature != NULL; ++it) { 233 if (it->onc_signature != &onc_signature) 234 continue; 235 return it->field_translation_table; 236 } 237 return NULL; 238 } 239 240 bool GetShillPropertyName(const std::string& onc_field_name, 241 const FieldTranslationEntry table[], 242 std::string* shill_property_name) { 243 for (const FieldTranslationEntry* it = table; 244 it->onc_field_name != NULL; ++it) { 245 if (it->onc_field_name != onc_field_name) 246 continue; 247 *shill_property_name = it->shill_property_name; 248 return true; 249 } 250 return false; 251 } 252 253 bool TranslateStringToShill(const StringTranslationEntry table[], 254 const std::string& onc_value, 255 std::string* shill_value) { 256 for (int i = 0; table[i].onc_value != NULL; ++i) { 257 if (onc_value != table[i].onc_value) 258 continue; 259 *shill_value = table[i].shill_value; 260 return true; 261 } 262 LOG(ERROR) << "Value '" << onc_value << "' cannot be translated to Shill"; 263 return false; 264 } 265 266 bool TranslateStringToONC(const StringTranslationEntry table[], 267 const std::string& shill_value, 268 std::string* onc_value) { 269 for (int i = 0; table[i].shill_value != NULL; ++i) { 270 if (shill_value != table[i].shill_value) 271 continue; 272 *onc_value = table[i].onc_value; 273 return true; 274 } 275 LOG(ERROR) << "Value '" << shill_value << "' cannot be translated to ONC"; 276 return false; 277 } 278 279 } // namespace onc 280 } // namespace chromeos 281