[Session restore] Rename group name Enabled to Restore.
[chromium-blink-merge.git] / chromeos / network / onc / onc_translation_tables.cc
blob564b9dc3f8340175705cdd9edec76c7e678c4178
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"
7 #include <cstddef>
9 #include "base/logging.h"
10 #include "components/onc/onc_constants.h"
11 #include "third_party/cros_system_api/dbus/service_constants.h"
13 namespace chromeos {
14 namespace onc {
16 // CertificatePattern is converted with function CreateUIData(...) to UIData
17 // stored in Shill.
19 // Proxy settings are converted to Shill by function
20 // ConvertOncProxySettingsToProxyConfig(...).
22 namespace {
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},
36 {NULL}};
38 const FieldTranslationEntry ipsec_fields[] = {
39 // This field is converted during translation, see onc_translator_*.
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 // This field is converted during translation, see onc_translator_*.
47 // { ::onc::vpn::kSaveCredentials, shill::kSaveCredentialsProperty},
48 {::onc::ipsec::kServerCAPEMs, shill::kL2tpIpsecCaCertPemProperty},
49 {NULL}};
51 const FieldTranslationEntry xauth_fields[] = {
52 {::onc::vpn::kPassword, shill::kL2tpIpsecXauthPasswordProperty},
53 {::onc::vpn::kUsername, shill::kL2tpIpsecXauthUserProperty},
54 {NULL}};
56 const FieldTranslationEntry l2tp_fields[] = {
57 {::onc::l2tp::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::l2tp::kSaveCredentials, &kBoolSignature },
61 {::onc::l2tp::kUsername, shill::kL2tpIpsecUserProperty},
62 {::onc::l2tp::kLcpEchoDisabled, shill::kL2tpIpsecLcpEchoDisabledProperty},
63 {NULL}};
65 const FieldTranslationEntry openvpn_fields[] = {
66 {::onc::openvpn::kAuth, shill::kOpenVPNAuthProperty},
67 {::onc::openvpn::kAuthNoCache, shill::kOpenVPNAuthNoCacheProperty},
68 {::onc::openvpn::kAuthRetry, shill::kOpenVPNAuthRetryProperty},
69 {::onc::openvpn::kCipher, shill::kOpenVPNCipherProperty},
70 {::onc::openvpn::kCompLZO, shill::kOpenVPNCompLZOProperty},
71 {::onc::openvpn::kCompNoAdapt, shill::kOpenVPNCompNoAdaptProperty},
72 {::onc::openvpn::kIgnoreDefaultRoute,
73 shill::kOpenVPNIgnoreDefaultRouteProperty},
74 {::onc::openvpn::kKeyDirection, shill::kOpenVPNKeyDirectionProperty},
75 {::onc::openvpn::kNsCertType, shill::kOpenVPNNsCertTypeProperty},
76 // This field is converted during translation, see onc_translator_*.
77 // { ::onc::vpn::kOTP, shill::kOpenVPNTokenProperty or kOpenVPNOTPProperty},
78 // This field is converted during translation, see onc_translator_*.
79 // { ::onc::vpn::kPassword, shill::kOpenVPNPasswordProperty},
80 {::onc::openvpn::kPort, shill::kOpenVPNPortProperty},
81 {::onc::openvpn::kProto, shill::kOpenVPNProtoProperty},
82 {::onc::openvpn::kPushPeerInfo, shill::kOpenVPNPushPeerInfoProperty},
83 {::onc::openvpn::kRemoteCertEKU, shill::kOpenVPNRemoteCertEKUProperty},
84 // This field is converted during translation, see onc_translator_*.
85 // { ::onc::openvpn::kRemoteCertKU, shill::kOpenVPNRemoteCertKUProperty },
86 {::onc::openvpn::kRemoteCertTLS, shill::kOpenVPNRemoteCertTLSProperty},
87 {::onc::openvpn::kRenegSec, shill::kOpenVPNRenegSecProperty},
88 // This field is converted during translation, see onc_translator_*.
89 // { ::onc::vpn::kSaveCredentials, shill::kSaveCredentialsProperty},
90 {::onc::openvpn::kServerCAPEMs, shill::kOpenVPNCaCertPemProperty},
91 {::onc::openvpn::kServerPollTimeout,
92 shill::kOpenVPNServerPollTimeoutProperty},
93 {::onc::openvpn::kShaper, shill::kOpenVPNShaperProperty},
94 {::onc::openvpn::kStaticChallenge, shill::kOpenVPNStaticChallengeProperty},
95 {::onc::openvpn::kTLSAuthContents, shill::kOpenVPNTLSAuthContentsProperty},
96 {::onc::openvpn::kTLSRemote, shill::kOpenVPNTLSRemoteProperty},
97 {::onc::vpn::kUsername, shill::kOpenVPNUserProperty},
98 {::onc::openvpn::kVerifyHash, shill::kOpenVPNVerifyHashProperty},
99 {NULL}};
101 const FieldTranslationEntry verify_x509_fields[] = {
102 {::onc::verify_x509::kName, shill::kOpenVPNVerifyX509NameProperty},
103 {::onc::verify_x509::kType, shill::kOpenVPNVerifyX509TypeProperty},
104 {NULL}};
106 const FieldTranslationEntry vpn_fields[] = {
107 {::onc::vpn::kAutoConnect, shill::kAutoConnectProperty},
108 // These fields are converted during translation, see onc_translator_*.
109 // { ::onc::vpn::kHost, shill::kProviderHostProperty},
110 // { ::onc::vpn::kType, shill::kProviderTypeProperty },
111 {NULL}};
113 const FieldTranslationEntry wifi_fields[] = {
114 {::onc::wifi::kAutoConnect, shill::kAutoConnectProperty},
115 {::onc::wifi::kBSSID, shill::kWifiBSsid},
116 // This dictionary is converted during translation, see onc_translator_*.
117 // { ::onc::wifi::kEAP, shill::kEap*},
118 {::onc::wifi::kFrequency, shill::kWifiFrequency},
119 {::onc::wifi::kFrequencyList, shill::kWifiFrequencyListProperty},
120 {::onc::wifi::kHexSSID, shill::kWifiHexSsid},
121 {::onc::wifi::kHiddenSSID, shill::kWifiHiddenSsid},
122 {::onc::wifi::kPassphrase, shill::kPassphraseProperty},
123 // This field is converted during translation, see onc_translator_*.
124 // { ::onc::wifi::kSecurity, shill::kSecurityClassProperty },
125 {::onc::wifi::kSignalStrength, shill::kSignalStrengthProperty},
126 {NULL}};
128 const FieldTranslationEntry wimax_fields[] = {
129 {::onc::wimax::kAutoConnect, shill::kAutoConnectProperty},
130 // This dictionary is converted during translation, see onc_translator_*.
131 // { ::onc::wimax::kEAP, shill::kEap*},
132 {::onc::wimax::kSignalStrength, shill::kSignalStrengthProperty},
133 {NULL}};
135 const FieldTranslationEntry cellular_apn_fields[] = {
136 {::onc::cellular_apn::kAccessPointName, shill::kApnProperty},
137 {::onc::cellular_apn::kName, shill::kApnNameProperty},
138 {::onc::cellular_apn::kUsername, shill::kApnUsernameProperty},
139 {::onc::cellular_apn::kPassword, shill::kApnPasswordProperty},
140 {::onc::cellular_apn::kLocalizedName, shill::kApnLocalizedNameProperty},
141 {::onc::cellular_apn::kLanguage, shill::kApnLanguageProperty},
142 {NULL}};
144 const FieldTranslationEntry cellular_found_network_fields[] = {
145 {::onc::cellular_found_network::kNetworkId, shill::kNetworkIdProperty},
146 {::onc::cellular_found_network::kStatus, shill::kStatusProperty},
147 {::onc::cellular_found_network::kTechnology, shill::kTechnologyProperty},
148 {::onc::cellular_found_network::kShortName, shill::kShortNameProperty},
149 {::onc::cellular_found_network::kLongName, shill::kLongNameProperty},
150 {NULL}};
152 const FieldTranslationEntry cellular_provider_fields[] = {
153 {::onc::cellular_provider::kCode, shill::kOperatorCodeKey},
154 {::onc::cellular_provider::kCountry, shill::kOperatorCountryKey},
155 {::onc::cellular_provider::kName, shill::kOperatorNameKey},
156 {NULL}};
158 const FieldTranslationEntry sim_lock_status_fields[] = {
159 {::onc::sim_lock_status::kLockEnabled, shill::kSIMLockEnabledProperty},
160 {::onc::sim_lock_status::kLockType, shill::kSIMLockTypeProperty},
161 {::onc::sim_lock_status::kRetriesLeft, shill::kSIMLockRetriesLeftProperty},
162 {NULL}};
164 // This must only contain Service properties and not Device properties.
165 // For Device properties see kCellularDeviceTable.
166 const FieldTranslationEntry cellular_fields[] = {
167 {::onc::cellular::kActivationType, shill::kActivationTypeProperty},
168 // This field is converted during translation, see onc_translator_*.
169 // { ::onc::cellular::kActivationState, shill::kActivationStateProperty},
170 {::onc::cellular::kAutoConnect, shill::kAutoConnectProperty},
171 // This field is converted during translation, see onc_translator_*.
172 // { ::onc::cellular::kNetworkTechnology,
173 // shill::kNetworkTechnologyProperty},
174 // This field is converted during translation, see onc_translator_*.
175 // { ::onc::cellular::kRoamingState, shill::kRoamingStateProperty},
176 {::onc::cellular::kSignalStrength, shill::kSignalStrengthProperty},
177 {NULL}};
179 const FieldTranslationEntry network_fields[] = {
180 {::onc::network_config::kGUID, shill::kGuidProperty},
181 {::onc::network_config::kConnectable, shill::kConnectableProperty},
182 {::onc::network_config::kErrorState, shill::kErrorProperty},
183 {::onc::network_config::kPriority, shill::kPriorityProperty},
185 // Shill doesn't allow setting the name for non-VPN networks.
186 // Name is conditionally translated, see onc_translator_*.
187 // { ::onc::network_config::kName, shill::kNameProperty },
189 // Type is converted during translation, see onc_translator_*.
190 // { ::onc::network_config::kType, shill::kTypeProperty },
192 // These fields are converted during translation, see
193 // onc_translator_shill_to_onc.cc. They are only converted when going from
194 // Shill->ONC, and ignored otherwise.
195 // { ::onc::network_config::kConnectionState, shill::kStateProperty },
196 // { ::onc::network_config::kRestrictedConnectivity,
197 // shill::kStateProperty },
198 // { ::onc::network_config::kSource, shill::kProfileProperty },
199 // { ::onc::network_config::kMacAddress, shill::kAddressProperty },
200 {NULL}};
202 const FieldTranslationEntry ipconfig_fields[] = {
203 {::onc::ipconfig::kIPAddress, shill::kAddressProperty},
204 {::onc::ipconfig::kGateway, shill::kGatewayProperty},
205 {::onc::ipconfig::kRoutingPrefix, shill::kPrefixlenProperty},
206 {::onc::ipconfig::kNameServers, shill::kNameServersProperty},
207 // This field is converted during translation, see ShillToONCTranslator::
208 // TranslateIPConfig. It is only converted from Shill->ONC.
209 // { ::onc::ipconfig::kType, shill::kMethodProperty},
210 {::onc::ipconfig::kWebProxyAutoDiscoveryUrl,
211 shill::kWebProxyAutoDiscoveryUrlProperty},
212 {NULL}};
214 const FieldTranslationEntry static_or_saved_ipconfig_fields[] = {
215 {::onc::ipconfig::kIPAddress, shill::kAddressProperty},
216 {::onc::ipconfig::kGateway, shill::kGatewayProperty},
217 {::onc::ipconfig::kRoutingPrefix, shill::kPrefixlenProperty},
218 {::onc::ipconfig::kNameServers, shill::kNameServersProperty},
219 {NULL}};
221 struct OncValueTranslationEntry {
222 const OncValueSignature* onc_signature;
223 const FieldTranslationEntry* field_translation_table;
226 const OncValueTranslationEntry onc_value_translation_table[] = {
227 {&kEAPSignature, eap_fields},
228 {&kIPsecSignature, ipsec_fields},
229 {&kL2TPSignature, l2tp_fields},
230 {&kXAUTHSignature, xauth_fields},
231 {&kOpenVPNSignature, openvpn_fields},
232 {&kVerifyX509Signature, verify_x509_fields},
233 {&kVPNSignature, vpn_fields},
234 {&kWiFiSignature, wifi_fields},
235 {&kWiFiWithStateSignature, wifi_fields},
236 {&kWiMAXSignature, wimax_fields},
237 {&kWiMAXWithStateSignature, wimax_fields},
238 {&kCellularApnSignature, cellular_apn_fields},
239 {&kCellularFoundNetworkSignature, cellular_found_network_fields},
240 {&kCellularProviderSignature, cellular_provider_fields},
241 {&kSIMLockStatusSignature, sim_lock_status_fields},
242 {&kCellularSignature, cellular_fields},
243 {&kCellularWithStateSignature, cellular_fields},
244 {&kNetworkWithStateSignature, network_fields},
245 {&kNetworkConfigurationSignature, network_fields},
246 {&kIPConfigSignature, ipconfig_fields},
247 {&kSavedIPConfigSignature, static_or_saved_ipconfig_fields},
248 {&kStaticIPConfigSignature, static_or_saved_ipconfig_fields},
249 {NULL}};
251 struct NestedShillDictionaryEntry {
252 const OncValueSignature* onc_signature;
253 // NULL terminated list of Shill property keys.
254 const char* const* shill_property_path;
257 const char* cellular_apn_path_entries[] = {shill::kCellularApnProperty, NULL};
259 const char* static_ip_config_path_entries[] = {shill::kStaticIPConfigProperty,
260 NULL};
262 const NestedShillDictionaryEntry nested_shill_dictionaries[] = {
263 {&kCellularApnSignature, cellular_apn_path_entries},
264 {&kStaticIPConfigSignature, static_ip_config_path_entries},
265 {NULL}};
267 } // namespace
269 const StringTranslationEntry kNetworkTypeTable[] = {
270 // This mapping is ensured in the translation code.
271 // { network_type::kEthernet, shill::kTypeEthernet },
272 // { network_type::kEthernet, shill::kTypeEthernetEap },
273 {::onc::network_type::kWiFi, shill::kTypeWifi},
274 {::onc::network_type::kWimax, shill::kTypeWimax},
275 {::onc::network_type::kCellular, shill::kTypeCellular},
276 {::onc::network_type::kVPN, shill::kTypeVPN},
277 {NULL}};
279 const StringTranslationEntry kVPNTypeTable[] = {
280 {::onc::vpn::kTypeL2TP_IPsec, shill::kProviderL2tpIpsec},
281 {::onc::vpn::kOpenVPN, shill::kProviderOpenVpn},
282 {::onc::vpn::kThirdPartyVpn, shill::kProviderThirdPartyVpn},
283 {NULL}};
285 const StringTranslationEntry kWiFiSecurityTable[] = {
286 {::onc::wifi::kSecurityNone, shill::kSecurityNone},
287 {::onc::wifi::kWEP_PSK, shill::kSecurityWep},
288 {::onc::wifi::kWPA_PSK, shill::kSecurityPsk},
289 {::onc::wifi::kWPA_EAP, shill::kSecurity8021x},
290 {NULL}};
292 const StringTranslationEntry kEAPOuterTable[] = {
293 {::onc::eap::kPEAP, shill::kEapMethodPEAP},
294 {::onc::eap::kEAP_TLS, shill::kEapMethodTLS},
295 {::onc::eap::kEAP_TTLS, shill::kEapMethodTTLS},
296 {::onc::eap::kLEAP, shill::kEapMethodLEAP},
297 {NULL}};
299 // Translation of the EAP.Inner field in case of EAP.Outer == PEAP
300 const StringTranslationEntry kEAP_PEAP_InnerTable[] = {
301 {::onc::eap::kMD5, shill::kEapPhase2AuthPEAPMD5},
302 {::onc::eap::kMSCHAPv2, shill::kEapPhase2AuthPEAPMSCHAPV2},
303 {NULL}};
305 // Translation of the EAP.Inner field in case of EAP.Outer == TTLS
306 const StringTranslationEntry kEAP_TTLS_InnerTable[] = {
307 {::onc::eap::kMD5, shill::kEapPhase2AuthTTLSMD5},
308 {::onc::eap::kMSCHAPv2, shill::kEapPhase2AuthTTLSMSCHAPV2},
309 {::onc::eap::kPAP, shill::kEapPhase2AuthTTLSPAP},
310 {NULL}};
312 const StringTranslationEntry kActivationStateTable[] = {
313 {::onc::cellular::kActivated, shill::kActivationStateActivated},
314 {::onc::cellular::kActivating, shill::kActivationStateActivating},
315 {::onc::cellular::kNotActivated, shill::kActivationStateNotActivated},
316 {::onc::cellular::kPartiallyActivated,
317 shill::kActivationStatePartiallyActivated},
318 {NULL}};
320 const StringTranslationEntry kNetworkTechnologyTable[] = {
321 {::onc::cellular::kTechnologyCdma1Xrtt, shill::kNetworkTechnology1Xrtt},
322 {::onc::cellular::kTechnologyGsm, shill::kNetworkTechnologyGsm},
323 {::onc::cellular::kTechnologyEdge, shill::kNetworkTechnologyEdge},
324 {::onc::cellular::kTechnologyEvdo, shill::kNetworkTechnologyEvdo},
325 {::onc::cellular::kTechnologyGprs, shill::kNetworkTechnologyGprs},
326 {::onc::cellular::kTechnologyHspa, shill::kNetworkTechnologyHspa},
327 {::onc::cellular::kTechnologyHspaPlus, shill::kNetworkTechnologyHspaPlus},
328 {::onc::cellular::kTechnologyLte, shill::kNetworkTechnologyLte},
329 {::onc::cellular::kTechnologyLteAdvanced,
330 shill::kNetworkTechnologyLteAdvanced},
331 {::onc::cellular::kTechnologyUmts, shill::kNetworkTechnologyUmts},
332 {NULL}};
334 const StringTranslationEntry kRoamingStateTable[] = {
335 {::onc::cellular::kRoamingHome, shill::kRoamingStateHome},
336 {::onc::cellular::kRoamingRoaming, shill::kRoamingStateRoaming},
337 {NULL}};
339 // This must contain only Shill Device properties and no Service properties.
340 // For Service properties see cellular_fields.
341 const FieldTranslationEntry kCellularDeviceTable[] = {
342 // This field is converted during translation, see onc_translator_*.
343 // { ::onc::cellular::kAPNList, shill::kCellularApnListProperty},
344 {::onc::cellular::kAllowRoaming, shill::kCellularAllowRoamingProperty},
345 {::onc::cellular::kCarrier, shill::kCarrierProperty},
346 {::onc::cellular::kESN, shill::kEsnProperty},
347 {::onc::cellular::kFamily, shill::kTechnologyFamilyProperty},
348 {::onc::cellular::kFirmwareRevision, shill::kFirmwareRevisionProperty},
349 // This field is converted during translation, see onc_translator_*.
350 // { ::onc::cellular::kFoundNetworks, shill::kFoundNetworksProperty},
351 {::onc::cellular::kHardwareRevision, shill::kHardwareRevisionProperty},
352 // This field is converted during translation, see onc_translator_*.
353 // { ::onc::cellular::kHomeProvider, shill::kHomeProviderProperty},
354 {::onc::cellular::kICCID, shill::kIccidProperty},
355 {::onc::cellular::kIMEI, shill::kImeiProperty},
356 {::onc::cellular::kIMSI, shill::kImsiProperty},
357 {::onc::cellular::kManufacturer, shill::kManufacturerProperty},
358 {::onc::cellular::kMDN, shill::kMdnProperty},
359 {::onc::cellular::kMEID, shill::kMeidProperty},
360 {::onc::cellular::kMIN, shill::kMinProperty},
361 {::onc::cellular::kModelID, shill::kModelIDProperty},
362 {::onc::cellular::kPRLVersion, shill::kPRLVersionProperty},
363 // This field is converted during translation, see onc_translator_*.
364 // { ::onc::cellular::kSIMLockStatus, shill::kSIMLockStatusProperty},
365 {::onc::cellular::kSIMPresent, shill::kSIMPresentProperty},
366 {::onc::cellular::kSupportedCarriers, shill::kSupportedCarriersProperty},
367 {::onc::cellular::kSupportNetworkScan, shill::kSupportNetworkScanProperty},
368 {NULL}};
370 const FieldTranslationEntry* GetFieldTranslationTable(
371 const OncValueSignature& onc_signature) {
372 for (const OncValueTranslationEntry* it = onc_value_translation_table;
373 it->onc_signature != NULL; ++it) {
374 if (it->onc_signature == &onc_signature)
375 return it->field_translation_table;
377 return NULL;
380 std::vector<std::string> GetPathToNestedShillDictionary(
381 const OncValueSignature& onc_signature) {
382 std::vector<std::string> shill_property_path;
383 for (const NestedShillDictionaryEntry* it = nested_shill_dictionaries;
384 it->onc_signature != NULL; ++it) {
385 if (it->onc_signature == &onc_signature) {
386 for (const char* const* key = it->shill_property_path; *key != NULL;
387 ++key) {
388 shill_property_path.push_back(std::string(*key));
390 break;
393 return shill_property_path;
396 bool GetShillPropertyName(const std::string& onc_field_name,
397 const FieldTranslationEntry table[],
398 std::string* shill_property_name) {
399 for (const FieldTranslationEntry* it = table; it->onc_field_name != NULL;
400 ++it) {
401 if (it->onc_field_name != onc_field_name)
402 continue;
403 *shill_property_name = it->shill_property_name;
404 return true;
406 return false;
409 bool TranslateStringToShill(const StringTranslationEntry table[],
410 const std::string& onc_value,
411 std::string* shill_value) {
412 for (int i = 0; table[i].onc_value != NULL; ++i) {
413 if (onc_value != table[i].onc_value)
414 continue;
415 *shill_value = table[i].shill_value;
416 return true;
418 LOG(ERROR) << "Value '" << onc_value << "' cannot be translated to Shill";
419 return false;
422 bool TranslateStringToONC(const StringTranslationEntry table[],
423 const std::string& shill_value,
424 std::string* onc_value) {
425 for (int i = 0; table[i].shill_value != NULL; ++i) {
426 if (shill_value != table[i].shill_value)
427 continue;
428 *onc_value = table[i].onc_value;
429 return true;
431 LOG(ERROR) << "Value '" << shill_value << "' cannot be translated to ONC";
432 return false;
435 } // namespace onc
436 } // namespace chromeos