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.
5 #include "chromeos/network/onc/onc_translation_tables.h"
9 #include "base/logging.h"
10 #include "components/onc/onc_constants.h"
11 #include "third_party/cros_system_api/dbus/service_constants.h"
16 // CertificatePattern is converted with function CreateUIData(...) to UIData
19 // Proxy settings are converted to Shill by function
20 // ConvertOncProxySettingsToProxyConfig(...).
24 const 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 },
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},
38 const FieldTranslationEntry ipsec_fields[] = {
39 // This field is converted during translation, see onc_translator_*.
40 // { ::onc::ipsec::kAuthenticationType, shill::kL2tpIpsecAuthenticationType
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 // This field is converted during translation, see onc_translator_*.
47 // { ::onc::vpn::kSaveCredentials, shill::kSaveCredentialsProperty},
48 { ::onc::ipsec::kServerCAPEMs, shill::kL2tpIpsecCaCertPemProperty},
51 const FieldTranslationEntry xauth_fields[] = {
52 { ::onc::vpn::kPassword, shill::kL2tpIpsecXauthPasswordProperty},
53 { ::onc::vpn::kUsername, shill::kL2tpIpsecXauthUserProperty},
56 const FieldTranslationEntry l2tp_fields[] = {
57 { ::onc::vpn::kPassword, shill::kL2tpIpsecPasswordProperty},
58 // We don't synchronize l2tp's SaveCredentials field for now, as Shill
59 // doesn't support separate settings for ipsec and l2tp.
60 // { ::onc::vpn::kSaveCredentials, &kBoolSignature },
61 { ::onc::vpn::kUsername, shill::kL2tpIpsecUserProperty}, {NULL}};
63 const 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 // This field is converted during translation, see onc_translator_*.
75 // { ::onc::vpn::kOTP, shill::kOpenVPNTokenProperty or kOpenVPNOTPProperty},
76 // This field is converted during translation, see onc_translator_*.
77 // { ::onc::vpn::kPassword, shill::kOpenVPNPasswordProperty},
78 { ::onc::openvpn::kPort, shill::kOpenVPNPortProperty},
79 { ::onc::openvpn::kProto, shill::kOpenVPNProtoProperty},
80 { ::onc::openvpn::kPushPeerInfo, shill::kOpenVPNPushPeerInfoProperty},
81 { ::onc::openvpn::kRemoteCertEKU, shill::kOpenVPNRemoteCertEKUProperty},
82 // This field is converted during translation, see onc_translator_*.
83 // { ::onc::openvpn::kRemoteCertKU, shill::kOpenVPNRemoteCertKUProperty },
84 { ::onc::openvpn::kRemoteCertTLS, shill::kOpenVPNRemoteCertTLSProperty},
85 { ::onc::openvpn::kRenegSec, shill::kOpenVPNRenegSecProperty},
86 // This field is converted during translation, see onc_translator_*.
87 // { ::onc::vpn::kSaveCredentials, shill::kSaveCredentialsProperty},
88 { ::onc::openvpn::kServerCAPEMs, shill::kOpenVPNCaCertPemProperty},
89 { ::onc::openvpn::kServerPollTimeout,
90 shill::kOpenVPNServerPollTimeoutProperty},
91 { ::onc::openvpn::kShaper, shill::kOpenVPNShaperProperty},
92 { ::onc::openvpn::kStaticChallenge, shill::kOpenVPNStaticChallengeProperty},
93 { ::onc::openvpn::kTLSAuthContents, shill::kOpenVPNTLSAuthContentsProperty},
94 { ::onc::openvpn::kTLSRemote, shill::kOpenVPNTLSRemoteProperty},
95 { ::onc::vpn::kUsername, shill::kOpenVPNUserProperty},
96 { ::onc::openvpn::kVerifyHash, shill::kOpenVPNVerifyHashProperty},
99 const FieldTranslationEntry verify_x509_fields[] = {
100 { ::onc::verify_x509::kName, shill::kOpenVPNVerifyX509NameProperty},
101 { ::onc::verify_x509::kType, shill::kOpenVPNVerifyX509TypeProperty},
104 const FieldTranslationEntry vpn_fields[] = {
105 { ::onc::vpn::kAutoConnect, shill::kAutoConnectProperty},
106 // These fields are converted during translation, see onc_translator_*.
107 // { ::onc::vpn::kHost, shill::kProviderHostProperty},
108 // { ::onc::vpn::kType, shill::kProviderTypeProperty },
111 const FieldTranslationEntry wifi_fields[] = {
112 { ::onc::wifi::kAutoConnect, shill::kAutoConnectProperty},
113 { ::onc::wifi::kBSSID, shill::kWifiBSsid},
114 // This dictionary is converted during translation, see onc_translator_*.
115 // { ::onc::wifi::kEAP, shill::kEap*},
116 { ::onc::wifi::kFrequency, shill::kWifiFrequency},
117 { ::onc::wifi::kFrequencyList, shill::kWifiFrequencyListProperty},
118 { ::onc::wifi::kHiddenSSID, shill::kWifiHiddenSsid},
119 { ::onc::wifi::kPassphrase, shill::kPassphraseProperty},
120 // This field is converted during translation, see onc_translator_*.
121 // { ::onc::wifi::kSSID, shill::kWifiHexSsid},
122 // This field is converted during translation, see onc_translator_*.
123 // { ::onc::wifi::kSecurity, shill::kSecurityProperty },
124 { ::onc::wifi::kSignalStrength, shill::kSignalStrengthProperty},
127 const FieldTranslationEntry wimax_fields[] = {
128 { ::onc::wimax::kAutoConnect, shill::kAutoConnectProperty},
129 // This dictionary is converted during translation, see onc_translator_*.
130 // { ::onc::wimax::kEAP, shill::kEap*},
131 { ::onc::wimax::kSignalStrength, shill::kSignalStrengthProperty},
134 const FieldTranslationEntry cellular_apn_fields[] = {
135 { ::onc::cellular_apn::kAccessPointName, shill::kApnProperty},
136 { ::onc::cellular_apn::kName, shill::kApnNameProperty},
137 { ::onc::cellular_apn::kUsername, shill::kApnUsernameProperty},
138 { ::onc::cellular_apn::kPassword, shill::kApnPasswordProperty},
139 { ::onc::cellular_apn::kLocalizedName, shill::kApnLocalizedNameProperty},
140 { ::onc::cellular_apn::kLanguage, shill::kApnLanguageProperty},
143 const FieldTranslationEntry cellular_found_network_fields[] = {
144 { ::onc::cellular_found_network::kNetworkId, shill::kNetworkIdProperty},
145 { ::onc::cellular_found_network::kStatus, shill::kStatusProperty},
146 { ::onc::cellular_found_network::kTechnology, shill::kTechnologyProperty},
147 { ::onc::cellular_found_network::kShortName, shill::kShortNameProperty},
148 { ::onc::cellular_found_network::kLongName, shill::kLongNameProperty},
151 const FieldTranslationEntry cellular_provider_fields[] = {
152 { ::onc::cellular_provider::kCode, shill::kOperatorCodeKey},
153 { ::onc::cellular_provider::kCountry, shill::kOperatorCountryKey},
154 { ::onc::cellular_provider::kName, shill::kOperatorNameKey},
157 const FieldTranslationEntry sim_lock_status_fields[] = {
158 { ::onc::sim_lock_status::kLockEnabled, shill::kSIMLockEnabledProperty},
159 { ::onc::sim_lock_status::kLockType, shill::kSIMLockTypeProperty},
160 { ::onc::sim_lock_status::kRetriesLeft, shill::kSIMLockRetriesLeftProperty},
163 // This must only contain Service properties and not Device properties.
164 // For Device properties see kCellularDeviceTable.
165 const FieldTranslationEntry cellular_fields[] = {
166 { ::onc::cellular::kActivationType, shill::kActivationTypeProperty},
167 // This field is converted during translation, see onc_translator_*.
168 // { ::onc::cellular::kActivationState, shill::kActivationStateProperty},
169 { ::onc::vpn::kAutoConnect, shill::kAutoConnectProperty},
170 { ::onc::cellular::kNetworkTechnology, shill::kNetworkTechnologyProperty},
171 // This field is converted during translation, see onc_translator_*.
172 // { ::onc::cellular::kRoamingState, shill::kRoamingStateProperty},
175 const FieldTranslationEntry network_fields[] = {
176 { ::onc::network_config::kGUID, shill::kGuidProperty},
177 { ::onc::network_config::kConnectable, shill::kConnectableProperty },
178 { ::onc::network_config::kErrorState, shill::kErrorProperty },
179 { ::onc::network_config::kPriority, shill::kPriorityProperty },
181 // Shill doesn't allow setting the name for non-VPN networks.
182 // Name is conditionally translated, see onc_translator_*.
183 // { ::onc::network_config::kName, shill::kNameProperty },
185 // Type is converted during translation, see onc_translator_*.
186 // { ::onc::network_config::kType, shill::kTypeProperty },
188 // These fields are converted during translation, see
189 // onc_translator_shill_to_onc.cc. They are only converted when going from
190 // Shill->ONC, and ignored otherwise.
191 // { ::onc::network_config::kConnectionState, shill::kStateProperty },
192 // { ::onc::network_config::kRestrictedConnectivity,
193 // shill::kStateProperty },
194 // { ::onc::network_config::kSource, shill::kProfileProperty },
195 // { ::onc::network_config::kMacAddress, shill::kAddressProperty },
198 const FieldTranslationEntry ipconfig_fields[] = {
199 { ::onc::ipconfig::kIPAddress, shill::kAddressProperty},
200 { ::onc::ipconfig::kGateway, shill::kGatewayProperty},
201 { ::onc::ipconfig::kRoutingPrefix, shill::kPrefixlenProperty},
202 { ::onc::ipconfig::kNameServers, shill::kNameServersProperty},
203 // This field is converted during translation, see ShillToONCTranslator::
204 // TranslateIPConfig. It is only converted from Shill->ONC.
205 // { ::onc::ipconfig::kType, shill::kMethodProperty},
206 { ::onc::ipconfig::kWebProxyAutoDiscoveryUrl,
207 shill::kWebProxyAutoDiscoveryUrlProperty},
210 const FieldTranslationEntry saved_ipconfig_fields[] = {
211 { ::onc::ipconfig::kIPAddress, shill::kSavedIPAddressProperty},
212 { ::onc::ipconfig::kGateway, shill::kSavedIPGatewayProperty},
213 { ::onc::ipconfig::kRoutingPrefix, shill::kSavedIPPrefixlenProperty},
214 // NameServers are converted during translation, see onc_translator_*.
215 // { ::onc::ipconfig::kNameServers, shill::kSavedIPNameServersProperty},
218 const FieldTranslationEntry static_ipconfig_fields[] = {
219 { ::onc::ipconfig::kIPAddress, shill::kStaticIPAddressProperty},
220 { ::onc::ipconfig::kGateway, shill::kStaticIPGatewayProperty},
221 { ::onc::ipconfig::kRoutingPrefix, shill::kStaticIPPrefixlenProperty},
222 // NameServers are converted during translation, see onc_translator_*.
223 // { ::onc::ipconfig::kNameServers, shill::kStaticIPNameServersProperty},
226 struct OncValueTranslationEntry {
227 const OncValueSignature* onc_signature;
228 const FieldTranslationEntry* field_translation_table;
231 const OncValueTranslationEntry onc_value_translation_table[] = {
232 { &kEAPSignature, eap_fields },
233 { &kIPsecSignature, ipsec_fields },
234 { &kL2TPSignature, l2tp_fields },
235 { &kXAUTHSignature, xauth_fields },
236 { &kOpenVPNSignature, openvpn_fields },
237 { &kVerifyX509Signature, verify_x509_fields },
238 { &kVPNSignature, vpn_fields },
239 { &kWiFiSignature, wifi_fields },
240 { &kWiFiWithStateSignature, wifi_fields },
241 { &kWiMAXSignature, wimax_fields },
242 { &kWiMAXWithStateSignature, wimax_fields },
243 { &kCellularApnSignature, cellular_apn_fields },
244 { &kCellularFoundNetworkSignature, cellular_found_network_fields },
245 { &kCellularProviderSignature, cellular_provider_fields },
246 { &kSIMLockStatusSignature, sim_lock_status_fields },
247 { &kCellularSignature, cellular_fields },
248 { &kCellularWithStateSignature, cellular_fields },
249 { &kNetworkWithStateSignature, network_fields },
250 { &kNetworkConfigurationSignature, network_fields },
251 { &kIPConfigSignature, ipconfig_fields },
252 { &kSavedIPConfigSignature, saved_ipconfig_fields },
253 { &kStaticIPConfigSignature, static_ipconfig_fields },
257 struct NestedShillDictionaryEntry {
258 const OncValueSignature* onc_signature;
259 // NULL terminated list of Shill property keys.
260 const char* const* shill_property_path;
263 const char* cellular_apn_property_path_entries[] = {
264 shill::kCellularApnProperty,
268 const NestedShillDictionaryEntry nested_shill_dictionaries[] = {
269 { &kCellularApnSignature, cellular_apn_property_path_entries },
275 const StringTranslationEntry kNetworkTypeTable[] = {
276 // This mapping is ensured in the translation code.
277 // { network_type::kEthernet, shill::kTypeEthernet },
278 // { network_type::kEthernet, shill::kTypeEthernetEap },
279 { ::onc::network_type::kWiFi, shill::kTypeWifi},
280 { ::onc::network_type::kWimax, shill::kTypeWimax},
281 { ::onc::network_type::kCellular, shill::kTypeCellular},
282 { ::onc::network_type::kVPN, shill::kTypeVPN},
285 const StringTranslationEntry kVPNTypeTable[] = {
286 { ::onc::vpn::kTypeL2TP_IPsec, shill::kProviderL2tpIpsec},
287 { ::onc::vpn::kOpenVPN, shill::kProviderOpenVpn}, {NULL}};
289 // The first matching line is chosen.
290 const StringTranslationEntry kWiFiSecurityTable[] = {
291 { ::onc::wifi::kSecurityNone, shill::kSecurityNone},
292 { ::onc::wifi::kWEP_PSK, shill::kSecurityWep},
293 { ::onc::wifi::kWPA_PSK, shill::kSecurityPsk},
294 { ::onc::wifi::kWPA_EAP, shill::kSecurity8021x},
295 { ::onc::wifi::kWPA_PSK, shill::kSecurityRsn},
296 { ::onc::wifi::kWPA_PSK, shill::kSecurityWpa},
299 const StringTranslationEntry kEAPOuterTable[] = {
300 { ::onc::eap::kPEAP, shill::kEapMethodPEAP},
301 { ::onc::eap::kEAP_TLS, shill::kEapMethodTLS},
302 { ::onc::eap::kEAP_TTLS, shill::kEapMethodTTLS},
303 { ::onc::eap::kLEAP, shill::kEapMethodLEAP},
306 // Translation of the EAP.Inner field in case of EAP.Outer == PEAP
307 const StringTranslationEntry kEAP_PEAP_InnerTable[] = {
308 { ::onc::eap::kMD5, shill::kEapPhase2AuthPEAPMD5},
309 { ::onc::eap::kMSCHAPv2, shill::kEapPhase2AuthPEAPMSCHAPV2}, {NULL}};
311 // Translation of the EAP.Inner field in case of EAP.Outer == TTLS
312 const StringTranslationEntry kEAP_TTLS_InnerTable[] = {
313 { ::onc::eap::kMD5, shill::kEapPhase2AuthTTLSMD5},
314 { ::onc::eap::kMSCHAPv2, shill::kEapPhase2AuthTTLSMSCHAPV2},
315 { ::onc::eap::kPAP, shill::kEapPhase2AuthTTLSPAP},
318 const StringTranslationEntry kActivationStateTable[] = {
319 { ::onc::cellular::kActivated, shill::kActivationStateActivated},
320 { ::onc::cellular::kActivating, shill::kActivationStateActivating},
321 { ::onc::cellular::kNotActivated, shill::kActivationStateNotActivated},
322 { ::onc::cellular::kPartiallyActivated,
323 shill::kActivationStatePartiallyActivated},
326 const StringTranslationEntry kRoamingStateTable[] = {
327 { ::onc::cellular::kHome, shill::kRoamingStateHome},
328 { ::onc::cellular::kRoaming, shill::kRoamingStateRoaming},
331 // This must contain only Shill Device properties and no Service properties.
332 // For Service properties see cellular_fields.
333 const FieldTranslationEntry kCellularDeviceTable[] = {
334 // This field is converted during translation, see onc_translator_*.
335 // { ::onc::cellular::kAPNList, shill::kCellularApnListProperty},
336 { ::onc::cellular::kAllowRoaming, shill::kCellularAllowRoamingProperty},
337 { ::onc::cellular::kCarrier, shill::kCarrierProperty},
338 { ::onc::cellular::kESN, shill::kEsnProperty},
339 { ::onc::cellular::kFamily, shill::kTechnologyFamilyProperty},
340 { ::onc::cellular::kFirmwareRevision, shill::kFirmwareRevisionProperty},
341 // This field is converted during translation, see onc_translator_*.
342 // { ::onc::cellular::kFoundNetworks, shill::kFoundNetworksProperty},
343 { ::onc::cellular::kHardwareRevision, shill::kHardwareRevisionProperty},
344 { ::onc::cellular::kHomeProvider, shill::kHomeProviderProperty},
345 { ::onc::cellular::kICCID, shill::kIccidProperty},
346 { ::onc::cellular::kIMEI, shill::kImeiProperty},
347 { ::onc::cellular::kIMSI, shill::kImsiProperty},
348 { ::onc::cellular::kManufacturer, shill::kManufacturerProperty},
349 { ::onc::cellular::kMDN, shill::kMdnProperty},
350 { ::onc::cellular::kMEID, shill::kMeidProperty},
351 { ::onc::cellular::kMIN, shill::kMinProperty},
352 { ::onc::cellular::kModelID, shill::kModelIDProperty},
353 { ::onc::cellular::kPRLVersion, shill::kPRLVersionProperty},
354 { ::onc::cellular::kProviderRequiresRoaming,
355 shill::kProviderRequiresRoamingProperty},
356 // This field is converted during translation, see onc_translator_*.
357 // { ::onc::cellular::kSIMLockStatus, shill::kSIMLockStatusProperty},
358 { ::onc::cellular::kSIMPresent, shill::kSIMPresentProperty},
359 { ::onc::cellular::kSupportedCarriers, shill::kSupportedCarriersProperty},
360 { ::onc::cellular::kSupportNetworkScan, shill::kSupportNetworkScanProperty},
363 const FieldTranslationEntry* GetFieldTranslationTable(
364 const OncValueSignature& onc_signature) {
365 for (const OncValueTranslationEntry* it = onc_value_translation_table;
366 it->onc_signature != NULL; ++it) {
367 if (it->onc_signature == &onc_signature)
368 return it->field_translation_table;
373 std::vector<std::string> GetPathToNestedShillDictionary(
374 const OncValueSignature& onc_signature) {
375 std::vector<std::string> shill_property_path;
376 for (const NestedShillDictionaryEntry* it = nested_shill_dictionaries;
377 it->onc_signature != NULL; ++it) {
378 if (it->onc_signature == &onc_signature) {
379 for (const char* const* key = it->shill_property_path; *key != NULL;
381 shill_property_path.push_back(std::string(*key));
386 return shill_property_path;
389 bool GetShillPropertyName(const std::string& onc_field_name,
390 const FieldTranslationEntry table[],
391 std::string* shill_property_name) {
392 for (const FieldTranslationEntry* it = table;
393 it->onc_field_name != NULL; ++it) {
394 if (it->onc_field_name != onc_field_name)
396 *shill_property_name = it->shill_property_name;
402 bool TranslateStringToShill(const StringTranslationEntry table[],
403 const std::string& onc_value,
404 std::string* shill_value) {
405 for (int i = 0; table[i].onc_value != NULL; ++i) {
406 if (onc_value != table[i].onc_value)
408 *shill_value = table[i].shill_value;
411 LOG(ERROR) << "Value '" << onc_value << "' cannot be translated to Shill";
415 bool TranslateStringToONC(const StringTranslationEntry table[],
416 const std::string& shill_value,
417 std::string* onc_value) {
418 for (int i = 0; table[i].shill_value != NULL; ++i) {
419 if (shill_value != table[i].shill_value)
421 *onc_value = table[i].onc_value;
424 LOG(ERROR) << "Value '" << shill_value << "' cannot be translated to ONC";
429 } // namespace chromeos