onc_translation_tables.cc revision 5c02ac1a9c1b504631c0a3d2b6e737b5d738bae1
1f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com// Copyright (c) 2012 The Chromium Authors. All rights reserved.
2f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com// Use of this source code is governed by a BSD-style license that can be
3f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com// found in the LICENSE file.
4f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com
5f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com#include "chromeos/network/onc/onc_translation_tables.h"
6977b9c8af3ef1b9a2fa2a0037cf3734cf2ba13d9robertphillips@google.com
7977b9c8af3ef1b9a2fa2a0037cf3734cf2ba13d9robertphillips@google.com#include <cstddef>
8977b9c8af3ef1b9a2fa2a0037cf3734cf2ba13d9robertphillips@google.com
9977b9c8af3ef1b9a2fa2a0037cf3734cf2ba13d9robertphillips@google.com#include "base/logging.h"
10977b9c8af3ef1b9a2fa2a0037cf3734cf2ba13d9robertphillips@google.com#include "components/onc/onc_constants.h"
11977b9c8af3ef1b9a2fa2a0037cf3734cf2ba13d9robertphillips@google.com#include "third_party/cros_system_api/dbus/service_constants.h"
12977b9c8af3ef1b9a2fa2a0037cf3734cf2ba13d9robertphillips@google.com
13977b9c8af3ef1b9a2fa2a0037cf3734cf2ba13d9robertphillips@google.comnamespace chromeos {
14977b9c8af3ef1b9a2fa2a0037cf3734cf2ba13d9robertphillips@google.comnamespace onc {
154d73ac22a1b99402fc8cff78a4eb4b27aa8fe019robertphillips@google.com
164d73ac22a1b99402fc8cff78a4eb4b27aa8fe019robertphillips@google.com// CertificatePattern is converted with function CreateUIData(...) to UIData
174d73ac22a1b99402fc8cff78a4eb4b27aa8fe019robertphillips@google.com// stored in Shill.
184d73ac22a1b99402fc8cff78a4eb4b27aa8fe019robertphillips@google.com//
194d73ac22a1b99402fc8cff78a4eb4b27aa8fe019robertphillips@google.com// Proxy settings are converted to Shill by function
20977b9c8af3ef1b9a2fa2a0037cf3734cf2ba13d9robertphillips@google.com// ConvertOncProxySettingsToProxyConfig(...).
21b74af872cc1ce45768df3ae03fa86ad3ed76b582robertphillips@google.com
2297fafe1b5ec06b470d36ea5cd98fe7bf2c143491robertphillips@google.comnamespace {
234d73ac22a1b99402fc8cff78a4eb4b27aa8fe019robertphillips@google.com
244d73ac22a1b99402fc8cff78a4eb4b27aa8fe019robertphillips@google.comconst FieldTranslationEntry eap_fields[] = {
25b74af872cc1ce45768df3ae03fa86ad3ed76b582robertphillips@google.com    { ::onc::eap::kAnonymousIdentity, shill::kEapAnonymousIdentityProperty},
26b74af872cc1ce45768df3ae03fa86ad3ed76b582robertphillips@google.com    { ::onc::eap::kIdentity, shill::kEapIdentityProperty},
2797fafe1b5ec06b470d36ea5cd98fe7bf2c143491robertphillips@google.com    // This field is converted during translation, see onc_translator_*.
284d73ac22a1b99402fc8cff78a4eb4b27aa8fe019robertphillips@google.com    // { ::onc::eap::kInner, shill::kEapPhase2AuthProperty },
294d73ac22a1b99402fc8cff78a4eb4b27aa8fe019robertphillips@google.com
304d73ac22a1b99402fc8cff78a4eb4b27aa8fe019robertphillips@google.com    // This field is converted during translation, see onc_translator_*.
314d73ac22a1b99402fc8cff78a4eb4b27aa8fe019robertphillips@google.com    // { ::onc::eap::kOuter, shill::kEapMethodProperty },
3297fafe1b5ec06b470d36ea5cd98fe7bf2c143491robertphillips@google.com    { ::onc::eap::kPassword, shill::kEapPasswordProperty},
3397fafe1b5ec06b470d36ea5cd98fe7bf2c143491robertphillips@google.com    { ::onc::eap::kSaveCredentials, shill::kSaveCredentialsProperty},
344d73ac22a1b99402fc8cff78a4eb4b27aa8fe019robertphillips@google.com    { ::onc::eap::kServerCAPEMs, shill::kEapCaCertPemProperty},
3597fafe1b5ec06b470d36ea5cd98fe7bf2c143491robertphillips@google.com    { ::onc::eap::kUseSystemCAs, shill::kEapUseSystemCasProperty},
364d73ac22a1b99402fc8cff78a4eb4b27aa8fe019robertphillips@google.com    {NULL}};
374d73ac22a1b99402fc8cff78a4eb4b27aa8fe019robertphillips@google.com
384d73ac22a1b99402fc8cff78a4eb4b27aa8fe019robertphillips@google.comconst FieldTranslationEntry ipsec_fields[] = {
394d73ac22a1b99402fc8cff78a4eb4b27aa8fe019robertphillips@google.com    // Ignored by Shill, not necessary to synchronize.
4023579275c7f544763d074d90563c4b1e567ab041robertphillips@google.com    // { ::onc::ipsec::kAuthenticationType, shill::kL2tpIpsecAuthenticationType
414d73ac22a1b99402fc8cff78a4eb4b27aa8fe019robertphillips@google.com    // },
424d73ac22a1b99402fc8cff78a4eb4b27aa8fe019robertphillips@google.com    { ::onc::ipsec::kGroup, shill::kL2tpIpsecTunnelGroupProperty},
434d73ac22a1b99402fc8cff78a4eb4b27aa8fe019robertphillips@google.com    // Ignored by Shill, not necessary to synchronize.
4423579275c7f544763d074d90563c4b1e567ab041robertphillips@google.com    // { ::onc::ipsec::kIKEVersion, shill::kL2tpIpsecIkeVersion },
454d73ac22a1b99402fc8cff78a4eb4b27aa8fe019robertphillips@google.com    { ::onc::ipsec::kPSK, shill::kL2tpIpsecPskProperty},
464d73ac22a1b99402fc8cff78a4eb4b27aa8fe019robertphillips@google.com    { ::onc::vpn::kSaveCredentials, shill::kSaveCredentialsProperty},
474d73ac22a1b99402fc8cff78a4eb4b27aa8fe019robertphillips@google.com    { ::onc::ipsec::kServerCAPEMs, shill::kL2tpIpsecCaCertPemProperty},
484d73ac22a1b99402fc8cff78a4eb4b27aa8fe019robertphillips@google.com    {NULL}};
494d73ac22a1b99402fc8cff78a4eb4b27aa8fe019robertphillips@google.com
504d73ac22a1b99402fc8cff78a4eb4b27aa8fe019robertphillips@google.comconst FieldTranslationEntry xauth_fields[] = {
514d73ac22a1b99402fc8cff78a4eb4b27aa8fe019robertphillips@google.com    { ::onc::vpn::kPassword, shill::kL2tpIpsecXauthPasswordProperty},
524d73ac22a1b99402fc8cff78a4eb4b27aa8fe019robertphillips@google.com    { ::onc::vpn::kUsername, shill::kL2tpIpsecXauthUserProperty},
534d73ac22a1b99402fc8cff78a4eb4b27aa8fe019robertphillips@google.com    {NULL}};
544d73ac22a1b99402fc8cff78a4eb4b27aa8fe019robertphillips@google.com
554d73ac22a1b99402fc8cff78a4eb4b27aa8fe019robertphillips@google.comconst FieldTranslationEntry l2tp_fields[] = {
564d73ac22a1b99402fc8cff78a4eb4b27aa8fe019robertphillips@google.com    { ::onc::vpn::kPassword, shill::kL2tpIpsecPasswordProperty},
574d73ac22a1b99402fc8cff78a4eb4b27aa8fe019robertphillips@google.com    // We don't synchronize l2tp's SaveCredentials field for now, as Shill
584d73ac22a1b99402fc8cff78a4eb4b27aa8fe019robertphillips@google.com    // doesn't
594d73ac22a1b99402fc8cff78a4eb4b27aa8fe019robertphillips@google.com    // support separate settings for ipsec and l2tp.
6023579275c7f544763d074d90563c4b1e567ab041robertphillips@google.com    // { ::onc::vpn::kSaveCredentials, &kBoolSignature },
614d73ac22a1b99402fc8cff78a4eb4b27aa8fe019robertphillips@google.com    { ::onc::vpn::kUsername, shill::kL2tpIpsecUserProperty}, {NULL}};
624d73ac22a1b99402fc8cff78a4eb4b27aa8fe019robertphillips@google.com
634da34e36cb7a07c3a28ae2a135b1837c26fc7aeabsalomon@google.comconst FieldTranslationEntry openvpn_fields[] = {
644da34e36cb7a07c3a28ae2a135b1837c26fc7aeabsalomon@google.com    { ::onc::openvpn::kAuth, shill::kOpenVPNAuthProperty},
654da34e36cb7a07c3a28ae2a135b1837c26fc7aeabsalomon@google.com    { ::onc::openvpn::kAuthNoCache, shill::kOpenVPNAuthNoCacheProperty},
664da34e36cb7a07c3a28ae2a135b1837c26fc7aeabsalomon@google.com    { ::onc::openvpn::kAuthRetry, shill::kOpenVPNAuthRetryProperty},
6797fafe1b5ec06b470d36ea5cd98fe7bf2c143491robertphillips@google.com    { ::onc::openvpn::kCipher, shill::kOpenVPNCipherProperty},
6823579275c7f544763d074d90563c4b1e567ab041robertphillips@google.com    { ::onc::openvpn::kCompLZO, shill::kOpenVPNCompLZOProperty},
6997fafe1b5ec06b470d36ea5cd98fe7bf2c143491robertphillips@google.com    { ::onc::openvpn::kCompNoAdapt, shill::kOpenVPNCompNoAdaptProperty},
7097fafe1b5ec06b470d36ea5cd98fe7bf2c143491robertphillips@google.com    { ::onc::openvpn::kKeyDirection, shill::kOpenVPNKeyDirectionProperty},
7123579275c7f544763d074d90563c4b1e567ab041robertphillips@google.com    { ::onc::openvpn::kNsCertType, shill::kOpenVPNNsCertTypeProperty},
72b74af872cc1ce45768df3ae03fa86ad3ed76b582robertphillips@google.com    { ::onc::vpn::kPassword, shill::kOpenVPNPasswordProperty},
7373e19fb1ba2562048c6987272c8d73eee6a44242reed@google.com    { ::onc::openvpn::kPort, shill::kOpenVPNPortProperty},
7415e9d3e66e161ce23df30bc13f8a0c87d196b463robertphillips@google.com    { ::onc::openvpn::kProto, shill::kOpenVPNProtoProperty},
754d73ac22a1b99402fc8cff78a4eb4b27aa8fe019robertphillips@google.com    { ::onc::openvpn::kPushPeerInfo, shill::kOpenVPNPushPeerInfoProperty},
764d73ac22a1b99402fc8cff78a4eb4b27aa8fe019robertphillips@google.com    { ::onc::openvpn::kRemoteCertEKU, shill::kOpenVPNRemoteCertEKUProperty},
7723579275c7f544763d074d90563c4b1e567ab041robertphillips@google.com    // This field is converted during translation, see onc_translator_*.
7823579275c7f544763d074d90563c4b1e567ab041robertphillips@google.com    // { ::onc::openvpn::kRemoteCertKU, shill::kOpenVPNRemoteCertKUProperty },
7923579275c7f544763d074d90563c4b1e567ab041robertphillips@google.com    { ::onc::openvpn::kRemoteCertTLS, shill::kOpenVPNRemoteCertTLSProperty},
8023579275c7f544763d074d90563c4b1e567ab041robertphillips@google.com    { ::onc::openvpn::kRenegSec, shill::kOpenVPNRenegSecProperty},
8173e19fb1ba2562048c6987272c8d73eee6a44242reed@google.com    { ::onc::vpn::kSaveCredentials, shill::kSaveCredentialsProperty},
8273e19fb1ba2562048c6987272c8d73eee6a44242reed@google.com    { ::onc::openvpn::kServerCAPEMs, shill::kOpenVPNCaCertPemProperty},
8323579275c7f544763d074d90563c4b1e567ab041robertphillips@google.com    { ::onc::openvpn::kServerPollTimeout,
844d73ac22a1b99402fc8cff78a4eb4b27aa8fe019robertphillips@google.com      shill::kOpenVPNServerPollTimeoutProperty},
8573e19fb1ba2562048c6987272c8d73eee6a44242reed@google.com    { ::onc::openvpn::kShaper, shill::kOpenVPNShaperProperty},
86b74af872cc1ce45768df3ae03fa86ad3ed76b582robertphillips@google.com    { ::onc::openvpn::kStaticChallenge, shill::kOpenVPNStaticChallengeProperty},
8773e19fb1ba2562048c6987272c8d73eee6a44242reed@google.com    { ::onc::openvpn::kTLSAuthContents, shill::kOpenVPNTLSAuthContentsProperty},
8873e19fb1ba2562048c6987272c8d73eee6a44242reed@google.com    { ::onc::openvpn::kTLSRemote, shill::kOpenVPNTLSRemoteProperty},
8923579275c7f544763d074d90563c4b1e567ab041robertphillips@google.com    { ::onc::vpn::kUsername, shill::kOpenVPNUserProperty},
9023579275c7f544763d074d90563c4b1e567ab041robertphillips@google.com    { ::onc::openvpn::kVerifyHash, shill::kOpenVPNVerifyHashProperty},
9123579275c7f544763d074d90563c4b1e567ab041robertphillips@google.com    {NULL}};
9223579275c7f544763d074d90563c4b1e567ab041robertphillips@google.com
9373e19fb1ba2562048c6987272c8d73eee6a44242reed@google.comconst FieldTranslationEntry verify_x509_fields[] = {
944d73ac22a1b99402fc8cff78a4eb4b27aa8fe019robertphillips@google.com    { ::onc::verify_x509::kName, shill::kOpenVPNVerifyX509NameProperty},
954d73ac22a1b99402fc8cff78a4eb4b27aa8fe019robertphillips@google.com    { ::onc::verify_x509::kType, shill::kOpenVPNVerifyX509TypeProperty},
964d73ac22a1b99402fc8cff78a4eb4b27aa8fe019robertphillips@google.com    {NULL}};
974d73ac22a1b99402fc8cff78a4eb4b27aa8fe019robertphillips@google.com
9823579275c7f544763d074d90563c4b1e567ab041robertphillips@google.comconst FieldTranslationEntry vpn_fields[] = {
9923579275c7f544763d074d90563c4b1e567ab041robertphillips@google.com    { ::onc::vpn::kAutoConnect, shill::kAutoConnectProperty},
10023579275c7f544763d074d90563c4b1e567ab041robertphillips@google.com    { ::onc::vpn::kHost, shill::kProviderHostProperty},
1014d73ac22a1b99402fc8cff78a4eb4b27aa8fe019robertphillips@google.com    // This field is converted during translation, see onc_translator_*.
102977b9c8af3ef1b9a2fa2a0037cf3734cf2ba13d9robertphillips@google.com    // { ::onc::vpn::kType, shill::kProviderTypeProperty },
103977b9c8af3ef1b9a2fa2a0037cf3734cf2ba13d9robertphillips@google.com    {NULL}};
1044d73ac22a1b99402fc8cff78a4eb4b27aa8fe019robertphillips@google.com
1054d73ac22a1b99402fc8cff78a4eb4b27aa8fe019robertphillips@google.comconst FieldTranslationEntry wifi_fields[] = {
1064d73ac22a1b99402fc8cff78a4eb4b27aa8fe019robertphillips@google.com    { ::onc::wifi::kAutoConnect, shill::kAutoConnectProperty},
10723579275c7f544763d074d90563c4b1e567ab041robertphillips@google.com    { ::onc::wifi::kBSSID, shill::kWifiBSsid},
10823579275c7f544763d074d90563c4b1e567ab041robertphillips@google.com    { ::onc::wifi::kFrequency, shill::kWifiFrequency},
109977b9c8af3ef1b9a2fa2a0037cf3734cf2ba13d9robertphillips@google.com    { ::onc::wifi::kFrequencyList, shill::kWifiFrequencyListProperty},
110977b9c8af3ef1b9a2fa2a0037cf3734cf2ba13d9robertphillips@google.com    { ::onc::wifi::kHiddenSSID, shill::kWifiHiddenSsid},
1114d73ac22a1b99402fc8cff78a4eb4b27aa8fe019robertphillips@google.com    { ::onc::wifi::kPassphrase, shill::kPassphraseProperty},
1124d73ac22a1b99402fc8cff78a4eb4b27aa8fe019robertphillips@google.com    // This field is converted during translation, see onc_translator_*.
1134d73ac22a1b99402fc8cff78a4eb4b27aa8fe019robertphillips@google.com    // { ::onc::wifi::kSSID, shill::kWifiHexSsid},
114977b9c8af3ef1b9a2fa2a0037cf3734cf2ba13d9robertphillips@google.com    // This field is converted during translation, see onc_translator_*.
115977b9c8af3ef1b9a2fa2a0037cf3734cf2ba13d9robertphillips@google.com    // { ::onc::wifi::kSecurity, shill::kSecurityProperty },
116977b9c8af3ef1b9a2fa2a0037cf3734cf2ba13d9robertphillips@google.com    { ::onc::wifi::kSignalStrength, shill::kSignalStrengthProperty},
117    {NULL}};
118
119const FieldTranslationEntry cellular_apn_fields[] = {
120    { ::onc::cellular_apn::kName, shill::kApnProperty},
121    { ::onc::cellular_apn::kUsername, shill::kApnUsernameProperty},
122    { ::onc::cellular_apn::kPassword, shill::kApnPasswordProperty},
123    {NULL}};
124
125const FieldTranslationEntry cellular_provider_fields[] = {
126    { ::onc::cellular_provider::kCode, shill::kOperatorCodeKey},
127    { ::onc::cellular_provider::kCountry, shill::kOperatorCountryKey},
128    { ::onc::cellular_provider::kName, shill::kOperatorNameKey},
129    {NULL}};
130
131const FieldTranslationEntry cellular_fields[] = {
132    { ::onc::cellular::kActivateOverNonCellularNetwork,
133      shill::kActivateOverNonCellularNetworkProperty},
134    { ::onc::cellular::kActivationState, shill::kActivationStateProperty},
135    { ::onc::cellular::kAllowRoaming, shill::kCellularAllowRoamingProperty},
136    { ::onc::cellular::kCarrier, shill::kCarrierProperty},
137    { ::onc::cellular::kESN, shill::kEsnProperty},
138    { ::onc::cellular::kFamily, shill::kTechnologyFamilyProperty},
139    { ::onc::cellular::kFirmwareRevision, shill::kFirmwareRevisionProperty},
140    { ::onc::cellular::kFoundNetworks, shill::kFoundNetworksProperty},
141    { ::onc::cellular::kHardwareRevision, shill::kHardwareRevisionProperty},
142    { ::onc::cellular::kICCID, shill::kIccidProperty},
143    { ::onc::cellular::kIMEI, shill::kImeiProperty},
144    { ::onc::cellular::kIMSI, shill::kImsiProperty},
145    { ::onc::cellular::kManufacturer, shill::kManufacturerProperty},
146    { ::onc::cellular::kMDN, shill::kMdnProperty},
147    { ::onc::cellular::kMEID, shill::kMeidProperty},
148    { ::onc::cellular::kMIN, shill::kMinProperty},
149    { ::onc::cellular::kModelID, shill::kModelIDProperty},
150    { ::onc::cellular::kNetworkTechnology, shill::kNetworkTechnologyProperty},
151    { ::onc::cellular::kPRLVersion, shill::kPRLVersionProperty},
152    { ::onc::cellular::kProviderRequiresRoaming,
153      shill::kProviderRequiresRoamingProperty},
154    { ::onc::cellular::kRoamingState, shill::kRoamingStateProperty},
155    { ::onc::cellular::kSelectedNetwork, shill::kSelectedNetworkProperty},
156    { ::onc::cellular::kSIMLockStatus, shill::kSIMLockStatusProperty},
157    { ::onc::cellular::kSIMPresent, shill::kSIMPresentProperty},
158    { ::onc::cellular::kSupportedCarriers, shill::kSupportedCarriersProperty},
159    { ::onc::cellular::kSupportNetworkScan, shill::kSupportNetworkScanProperty},
160    {NULL}};
161
162const FieldTranslationEntry network_fields[] = {
163    // Shill doesn't allow setting the name for non-VPN networks.
164    // This field is conditionally translated, see onc_translator_*.
165    // { ::onc::network_config::kName, shill::kNameProperty },
166    { ::onc::network_config::kGUID, shill::kGuidProperty},
167    // This field is converted during translation, see onc_translator_*.
168    // { ::onc::network_config::kType, shill::kTypeProperty },
169
170    // This field is converted during translation, see
171    // onc_translator_shill_to_onc.cc. It is only converted when going from
172    // Shill->ONC, and ignored otherwise.
173    // { ::onc::network_config::kConnectionState, shill::kStateProperty },
174    {NULL}};
175
176const FieldTranslationEntry ipconfig_fields[] = {
177    { ::onc::ipconfig::kIPAddress, shill::kAddressProperty},
178    { ::onc::ipconfig::kGateway, shill::kGatewayProperty},
179    { ::onc::ipconfig::kRoutingPrefix, shill::kPrefixlenProperty},
180    { ::onc::ipconfig::kNameServers, shill::kNameServersProperty},
181    {NULL}};
182
183struct OncValueTranslationEntry {
184  const OncValueSignature* onc_signature;
185  const FieldTranslationEntry* field_translation_table;
186};
187
188const OncValueTranslationEntry onc_value_translation_table[] = {
189  { &kEAPSignature, eap_fields },
190  { &kIPsecSignature, ipsec_fields },
191  { &kL2TPSignature, l2tp_fields },
192  { &kXAUTHSignature, xauth_fields },
193  { &kOpenVPNSignature, openvpn_fields },
194  { &kVerifyX509Signature, verify_x509_fields },
195  { &kVPNSignature, vpn_fields },
196  { &kWiFiSignature, wifi_fields },
197  { &kWiFiWithStateSignature, wifi_fields },
198  { &kCellularApnSignature, cellular_apn_fields },
199  { &kCellularProviderSignature, cellular_provider_fields },
200  { &kCellularSignature, cellular_fields },
201  { &kCellularWithStateSignature, cellular_fields },
202  { &kNetworkWithStateSignature, network_fields },
203  { &kNetworkConfigurationSignature, network_fields },
204  { &kIPConfigSignature, ipconfig_fields },
205  { NULL }
206};
207
208struct NestedShillDictionaryEntry {
209  const OncValueSignature* onc_signature;
210  // NULL terminated list of Shill property keys.
211  const char* const* shill_property_path;
212};
213
214const char* cellular_apn_property_path_entries[] = {
215  shill::kCellularApnProperty,
216  NULL
217};
218
219const NestedShillDictionaryEntry nested_shill_dictionaries[] = {
220  { &kCellularApnSignature, cellular_apn_property_path_entries },
221  { NULL }
222};
223
224}  // namespace
225
226const StringTranslationEntry kNetworkTypeTable[] = {
227    // This mapping is ensured in the translation code.
228    //  { network_type::kEthernet, shill::kTypeEthernet },
229    //  { network_type::kEthernet, shill::kTypeEthernetEap },
230    { ::onc::network_type::kWiFi, shill::kTypeWifi},
231    { ::onc::network_type::kCellular, shill::kTypeCellular},
232    { ::onc::network_type::kVPN, shill::kTypeVPN},
233    {NULL}};
234
235const StringTranslationEntry kVPNTypeTable[] = {
236    { ::onc::vpn::kTypeL2TP_IPsec, shill::kProviderL2tpIpsec},
237    { ::onc::vpn::kOpenVPN, shill::kProviderOpenVpn}, {NULL}};
238
239// The first matching line is chosen.
240const StringTranslationEntry kWiFiSecurityTable[] = {
241    { ::onc::wifi::kNone, shill::kSecurityNone},
242    { ::onc::wifi::kWEP_PSK, shill::kSecurityWep},
243    { ::onc::wifi::kWPA_PSK, shill::kSecurityPsk},
244    { ::onc::wifi::kWPA_EAP, shill::kSecurity8021x},
245    { ::onc::wifi::kWPA_PSK, shill::kSecurityRsn},
246    { ::onc::wifi::kWPA_PSK, shill::kSecurityWpa},
247    {NULL}};
248
249const StringTranslationEntry kEAPOuterTable[] = {
250    { ::onc::eap::kPEAP, shill::kEapMethodPEAP},
251    { ::onc::eap::kEAP_TLS, shill::kEapMethodTLS},
252    { ::onc::eap::kEAP_TTLS, shill::kEapMethodTTLS},
253    { ::onc::eap::kLEAP, shill::kEapMethodLEAP},
254    {NULL}};
255
256// Translation of the EAP.Inner field in case of EAP.Outer == PEAP
257const StringTranslationEntry kEAP_PEAP_InnerTable[] = {
258    { ::onc::eap::kMD5, shill::kEapPhase2AuthPEAPMD5},
259    { ::onc::eap::kMSCHAPv2, shill::kEapPhase2AuthPEAPMSCHAPV2}, {NULL}};
260
261// Translation of the EAP.Inner field in case of EAP.Outer == TTLS
262const StringTranslationEntry kEAP_TTLS_InnerTable[] = {
263    { ::onc::eap::kMD5, shill::kEapPhase2AuthTTLSMD5},
264    { ::onc::eap::kMSCHAPv2, shill::kEapPhase2AuthTTLSMSCHAPV2},
265    { ::onc::eap::kPAP, shill::kEapPhase2AuthTTLSPAP},
266    {NULL}};
267
268const FieldTranslationEntry* GetFieldTranslationTable(
269    const OncValueSignature& onc_signature) {
270  for (const OncValueTranslationEntry* it = onc_value_translation_table;
271       it->onc_signature != NULL; ++it) {
272    if (it->onc_signature == &onc_signature)
273      return it->field_translation_table;
274  }
275  return NULL;
276}
277
278std::vector<std::string> GetPathToNestedShillDictionary(
279    const OncValueSignature& onc_signature) {
280  std::vector<std::string> shill_property_path;
281  for (const NestedShillDictionaryEntry* it = nested_shill_dictionaries;
282       it->onc_signature != NULL; ++it) {
283    if (it->onc_signature == &onc_signature) {
284      for (const char* const* key = it->shill_property_path; *key != NULL;
285           ++key) {
286        shill_property_path.push_back(std::string(*key));
287      }
288      break;
289    }
290  }
291  return shill_property_path;
292}
293
294bool GetShillPropertyName(const std::string& onc_field_name,
295                          const FieldTranslationEntry table[],
296                          std::string* shill_property_name) {
297  for (const FieldTranslationEntry* it = table;
298       it->onc_field_name != NULL; ++it) {
299    if (it->onc_field_name != onc_field_name)
300      continue;
301    *shill_property_name = it->shill_property_name;
302    return true;
303  }
304  return false;
305}
306
307bool TranslateStringToShill(const StringTranslationEntry table[],
308                            const std::string& onc_value,
309                            std::string* shill_value) {
310  for (int i = 0; table[i].onc_value != NULL; ++i) {
311    if (onc_value != table[i].onc_value)
312      continue;
313    *shill_value = table[i].shill_value;
314    return true;
315  }
316  LOG(ERROR) << "Value '" << onc_value << "' cannot be translated to Shill";
317  return false;
318}
319
320bool TranslateStringToONC(const StringTranslationEntry table[],
321                          const std::string& shill_value,
322                          std::string* onc_value) {
323  for (int i = 0; table[i].shill_value != NULL; ++i) {
324    if (shill_value != table[i].shill_value)
325      continue;
326    *onc_value = table[i].onc_value;
327    return true;
328  }
329  LOG(ERROR) << "Value '" << shill_value << "' cannot be translated to ONC";
330  return false;
331}
332
333}  // namespace onc
334}  // namespace chromeos
335