ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / chromeos / network / onc / onc_translation_tables.cc
blob94af3ecc42f0a66757627ba78e189bd1cef0bf3e
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::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},
97 {NULL}};
99 const FieldTranslationEntry verify_x509_fields[] = {
100 { ::onc::verify_x509::kName, shill::kOpenVPNVerifyX509NameProperty},
101 { ::onc::verify_x509::kType, shill::kOpenVPNVerifyX509TypeProperty},
102 {NULL}};
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 },
109 {NULL}};
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::kHexSSID, shill::kWifiHexSsid},
119 { ::onc::wifi::kHiddenSSID, shill::kWifiHiddenSsid},
120 { ::onc::wifi::kPassphrase, shill::kPassphraseProperty},
121 // This field is converted during translation, see onc_translator_*.
122 // { ::onc::wifi::kSecurity, shill::kSecurityClassProperty },
123 { ::onc::wifi::kSignalStrength, shill::kSignalStrengthProperty},
124 {NULL}};
126 const FieldTranslationEntry wimax_fields[] = {
127 { ::onc::wimax::kAutoConnect, shill::kAutoConnectProperty},
128 // This dictionary is converted during translation, see onc_translator_*.
129 // { ::onc::wimax::kEAP, shill::kEap*},
130 { ::onc::wimax::kSignalStrength, shill::kSignalStrengthProperty},
131 {NULL}};
133 const FieldTranslationEntry cellular_apn_fields[] = {
134 { ::onc::cellular_apn::kAccessPointName, shill::kApnProperty},
135 { ::onc::cellular_apn::kName, shill::kApnNameProperty},
136 { ::onc::cellular_apn::kUsername, shill::kApnUsernameProperty},
137 { ::onc::cellular_apn::kPassword, shill::kApnPasswordProperty},
138 { ::onc::cellular_apn::kLocalizedName, shill::kApnLocalizedNameProperty},
139 { ::onc::cellular_apn::kLanguage, shill::kApnLanguageProperty},
140 {NULL}};
142 const FieldTranslationEntry cellular_found_network_fields[] = {
143 { ::onc::cellular_found_network::kNetworkId, shill::kNetworkIdProperty},
144 { ::onc::cellular_found_network::kStatus, shill::kStatusProperty},
145 { ::onc::cellular_found_network::kTechnology, shill::kTechnologyProperty},
146 { ::onc::cellular_found_network::kShortName, shill::kShortNameProperty},
147 { ::onc::cellular_found_network::kLongName, shill::kLongNameProperty},
148 {NULL}};
150 const FieldTranslationEntry cellular_provider_fields[] = {
151 { ::onc::cellular_provider::kCode, shill::kOperatorCodeKey},
152 { ::onc::cellular_provider::kCountry, shill::kOperatorCountryKey},
153 { ::onc::cellular_provider::kName, shill::kOperatorNameKey},
154 {NULL}};
156 const FieldTranslationEntry sim_lock_status_fields[] = {
157 { ::onc::sim_lock_status::kLockEnabled, shill::kSIMLockEnabledProperty},
158 { ::onc::sim_lock_status::kLockType, shill::kSIMLockTypeProperty},
159 { ::onc::sim_lock_status::kRetriesLeft, shill::kSIMLockRetriesLeftProperty},
160 {NULL}};
162 // This must only contain Service properties and not Device properties.
163 // For Device properties see kCellularDeviceTable.
164 const FieldTranslationEntry cellular_fields[] = {
165 { ::onc::cellular::kActivationType, shill::kActivationTypeProperty},
166 // This field is converted during translation, see onc_translator_*.
167 // { ::onc::cellular::kActivationState, shill::kActivationStateProperty},
168 { ::onc::vpn::kAutoConnect, shill::kAutoConnectProperty},
169 { ::onc::cellular::kNetworkTechnology, shill::kNetworkTechnologyProperty},
170 // This field is converted during translation, see onc_translator_*.
171 // { ::onc::cellular::kRoamingState, shill::kRoamingStateProperty},
172 { ::onc::cellular::kSignalStrength, shill::kSignalStrengthProperty},
173 {NULL}};
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 },
196 {NULL}};
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},
208 {NULL}};
210 const FieldTranslationEntry static_or_saved_ipconfig_fields[] = {
211 { ::onc::ipconfig::kIPAddress, shill::kAddressProperty},
212 { ::onc::ipconfig::kGateway, shill::kGatewayProperty},
213 { ::onc::ipconfig::kRoutingPrefix, shill::kPrefixlenProperty},
214 { ::onc::ipconfig::kNameServers, shill::kNameServersProperty},
215 {NULL}};
217 struct OncValueTranslationEntry {
218 const OncValueSignature* onc_signature;
219 const FieldTranslationEntry* field_translation_table;
222 const OncValueTranslationEntry onc_value_translation_table[] = {
223 { &kEAPSignature, eap_fields },
224 { &kIPsecSignature, ipsec_fields },
225 { &kL2TPSignature, l2tp_fields },
226 { &kXAUTHSignature, xauth_fields },
227 { &kOpenVPNSignature, openvpn_fields },
228 { &kVerifyX509Signature, verify_x509_fields },
229 { &kVPNSignature, vpn_fields },
230 { &kWiFiSignature, wifi_fields },
231 { &kWiFiWithStateSignature, wifi_fields },
232 { &kWiMAXSignature, wimax_fields },
233 { &kWiMAXWithStateSignature, wimax_fields },
234 { &kCellularApnSignature, cellular_apn_fields },
235 { &kCellularFoundNetworkSignature, cellular_found_network_fields },
236 { &kCellularProviderSignature, cellular_provider_fields },
237 { &kSIMLockStatusSignature, sim_lock_status_fields },
238 { &kCellularSignature, cellular_fields },
239 { &kCellularWithStateSignature, cellular_fields },
240 { &kNetworkWithStateSignature, network_fields },
241 { &kNetworkConfigurationSignature, network_fields },
242 { &kIPConfigSignature, ipconfig_fields },
243 { &kSavedIPConfigSignature, static_or_saved_ipconfig_fields },
244 { &kStaticIPConfigSignature, static_or_saved_ipconfig_fields },
245 { NULL }
248 struct NestedShillDictionaryEntry {
249 const OncValueSignature* onc_signature;
250 // NULL terminated list of Shill property keys.
251 const char* const* shill_property_path;
254 const char* cellular_apn_path_entries[] = {
255 shill::kCellularApnProperty,
256 NULL
259 const char* static_ip_config_path_entries[] = {
260 shill::kStaticIPConfigProperty,
261 NULL
264 const NestedShillDictionaryEntry nested_shill_dictionaries[] = {
265 { &kCellularApnSignature, cellular_apn_path_entries },
266 { &kStaticIPConfigSignature, static_ip_config_path_entries },
267 { NULL }
270 } // namespace
272 const StringTranslationEntry kNetworkTypeTable[] = {
273 // This mapping is ensured in the translation code.
274 // { network_type::kEthernet, shill::kTypeEthernet },
275 // { network_type::kEthernet, shill::kTypeEthernetEap },
276 { ::onc::network_type::kWiFi, shill::kTypeWifi},
277 { ::onc::network_type::kWimax, shill::kTypeWimax},
278 { ::onc::network_type::kCellular, shill::kTypeCellular},
279 { ::onc::network_type::kVPN, shill::kTypeVPN},
280 {NULL}};
282 const StringTranslationEntry kVPNTypeTable[] = {
283 { ::onc::vpn::kTypeL2TP_IPsec, shill::kProviderL2tpIpsec},
284 { ::onc::vpn::kOpenVPN, shill::kProviderOpenVpn},
285 { ::onc::vpn::kThirdPartyVpn, shill::kProviderThirdPartyVpn},
286 {NULL}};
288 const StringTranslationEntry kWiFiSecurityTable[] = {
289 { ::onc::wifi::kSecurityNone, shill::kSecurityNone},
290 { ::onc::wifi::kWEP_PSK, shill::kSecurityWep},
291 { ::onc::wifi::kWPA_PSK, shill::kSecurityPsk},
292 { ::onc::wifi::kWPA_EAP, shill::kSecurity8021x},
293 {NULL}};
295 const StringTranslationEntry kEAPOuterTable[] = {
296 { ::onc::eap::kPEAP, shill::kEapMethodPEAP},
297 { ::onc::eap::kEAP_TLS, shill::kEapMethodTLS},
298 { ::onc::eap::kEAP_TTLS, shill::kEapMethodTTLS},
299 { ::onc::eap::kLEAP, shill::kEapMethodLEAP},
300 {NULL}};
302 // Translation of the EAP.Inner field in case of EAP.Outer == PEAP
303 const StringTranslationEntry kEAP_PEAP_InnerTable[] = {
304 { ::onc::eap::kMD5, shill::kEapPhase2AuthPEAPMD5},
305 { ::onc::eap::kMSCHAPv2, shill::kEapPhase2AuthPEAPMSCHAPV2}, {NULL}};
307 // Translation of the EAP.Inner field in case of EAP.Outer == TTLS
308 const StringTranslationEntry kEAP_TTLS_InnerTable[] = {
309 { ::onc::eap::kMD5, shill::kEapPhase2AuthTTLSMD5},
310 { ::onc::eap::kMSCHAPv2, shill::kEapPhase2AuthTTLSMSCHAPV2},
311 { ::onc::eap::kPAP, shill::kEapPhase2AuthTTLSPAP},
312 {NULL}};
314 const StringTranslationEntry kActivationStateTable[] = {
315 { ::onc::cellular::kActivated, shill::kActivationStateActivated},
316 { ::onc::cellular::kActivating, shill::kActivationStateActivating},
317 { ::onc::cellular::kNotActivated, shill::kActivationStateNotActivated},
318 { ::onc::cellular::kPartiallyActivated,
319 shill::kActivationStatePartiallyActivated},
320 {NULL}};
322 const StringTranslationEntry kRoamingStateTable[] = {
323 { ::onc::cellular::kRoamingHome, shill::kRoamingStateHome},
324 { ::onc::cellular::kRoamingRoaming, shill::kRoamingStateRoaming},
325 {NULL}};
327 // This must contain only Shill Device properties and no Service properties.
328 // For Service properties see cellular_fields.
329 const FieldTranslationEntry kCellularDeviceTable[] = {
330 // This field is converted during translation, see onc_translator_*.
331 // { ::onc::cellular::kAPNList, shill::kCellularApnListProperty},
332 { ::onc::cellular::kAllowRoaming, shill::kCellularAllowRoamingProperty},
333 { ::onc::cellular::kCarrier, shill::kCarrierProperty},
334 { ::onc::cellular::kESN, shill::kEsnProperty},
335 { ::onc::cellular::kFamily, shill::kTechnologyFamilyProperty},
336 { ::onc::cellular::kFirmwareRevision, shill::kFirmwareRevisionProperty},
337 // This field is converted during translation, see onc_translator_*.
338 // { ::onc::cellular::kFoundNetworks, shill::kFoundNetworksProperty},
339 { ::onc::cellular::kHardwareRevision, shill::kHardwareRevisionProperty},
340 // This field is converted during translation, see onc_translator_*.
341 // { ::onc::cellular::kHomeProvider, shill::kHomeProviderProperty},
342 { ::onc::cellular::kICCID, shill::kIccidProperty},
343 { ::onc::cellular::kIMEI, shill::kImeiProperty},
344 { ::onc::cellular::kIMSI, shill::kImsiProperty},
345 { ::onc::cellular::kManufacturer, shill::kManufacturerProperty},
346 { ::onc::cellular::kMDN, shill::kMdnProperty},
347 { ::onc::cellular::kMEID, shill::kMeidProperty},
348 { ::onc::cellular::kMIN, shill::kMinProperty},
349 { ::onc::cellular::kModelID, shill::kModelIDProperty},
350 { ::onc::cellular::kPRLVersion, shill::kPRLVersionProperty},
351 // This field is converted during translation, see onc_translator_*.
352 // { ::onc::cellular::kSIMLockStatus, shill::kSIMLockStatusProperty},
353 { ::onc::cellular::kSIMPresent, shill::kSIMPresentProperty},
354 { ::onc::cellular::kSupportedCarriers, shill::kSupportedCarriersProperty},
355 { ::onc::cellular::kSupportNetworkScan, shill::kSupportNetworkScanProperty},
356 {NULL}};
358 const FieldTranslationEntry* GetFieldTranslationTable(
359 const OncValueSignature& onc_signature) {
360 for (const OncValueTranslationEntry* it = onc_value_translation_table;
361 it->onc_signature != NULL; ++it) {
362 if (it->onc_signature == &onc_signature)
363 return it->field_translation_table;
365 return NULL;
368 std::vector<std::string> GetPathToNestedShillDictionary(
369 const OncValueSignature& onc_signature) {
370 std::vector<std::string> shill_property_path;
371 for (const NestedShillDictionaryEntry* it = nested_shill_dictionaries;
372 it->onc_signature != NULL; ++it) {
373 if (it->onc_signature == &onc_signature) {
374 for (const char* const* key = it->shill_property_path; *key != NULL;
375 ++key) {
376 shill_property_path.push_back(std::string(*key));
378 break;
381 return shill_property_path;
384 bool GetShillPropertyName(const std::string& onc_field_name,
385 const FieldTranslationEntry table[],
386 std::string* shill_property_name) {
387 for (const FieldTranslationEntry* it = table;
388 it->onc_field_name != NULL; ++it) {
389 if (it->onc_field_name != onc_field_name)
390 continue;
391 *shill_property_name = it->shill_property_name;
392 return true;
394 return false;
397 bool TranslateStringToShill(const StringTranslationEntry table[],
398 const std::string& onc_value,
399 std::string* shill_value) {
400 for (int i = 0; table[i].onc_value != NULL; ++i) {
401 if (onc_value != table[i].onc_value)
402 continue;
403 *shill_value = table[i].shill_value;
404 return true;
406 LOG(ERROR) << "Value '" << onc_value << "' cannot be translated to Shill";
407 return false;
410 bool TranslateStringToONC(const StringTranslationEntry table[],
411 const std::string& shill_value,
412 std::string* onc_value) {
413 for (int i = 0; table[i].shill_value != NULL; ++i) {
414 if (shill_value != table[i].shill_value)
415 continue;
416 *onc_value = table[i].onc_value;
417 return true;
419 LOG(ERROR) << "Value '" << shill_value << "' cannot be translated to ONC";
420 return false;
423 } // namespace onc
424 } // namespace chromeos