onc_translation_tables.cc revision 3551c9c881056c480085172ff9840cab31610854
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
13namespace chromeos {
14namespace 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
24namespace {
25
26const 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
41const 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
53const 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
62const 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
91const 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
99const 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
113const FieldTranslationEntry cellular_provider_fields[] = {
114  { cellular_provider::kCode, flimflam::kOperatorCodeKey },
115  { cellular_provider::kCountry, flimflam::kOperatorCountryKey },
116  { cellular_provider::kName, flimflam::kOperatorNameKey },
117  { NULL }
118};
119
120const FieldTranslationEntry cellular_with_state_fields[] = {
121  { cellular::kActivateOverNonCellularNetwork,
122    shill::kActivateOverNonCellularNetworkProperty },
123  { cellular::kActivationState, flimflam::kActivationStateProperty },
124  { cellular::kAllowRoaming, flimflam::kCellularAllowRoamingProperty },
125  { cellular::kAPN, flimflam::kApnProperty },
126  { cellular::kCarrier, flimflam::kCarrierProperty },
127  { cellular::kESN, flimflam::kEsnProperty },
128  { cellular::kFamily, flimflam::kTechnologyFamilyProperty },
129  { cellular::kFirmwareRevision, flimflam::kFirmwareRevisionProperty },
130  { cellular::kFoundNetworks, flimflam::kFoundNetworksProperty },
131  { cellular::kHardwareRevision, flimflam::kHardwareRevisionProperty },
132  { cellular::kHomeProvider, flimflam::kHomeProviderProperty },
133  { cellular::kICCID, flimflam::kIccidProperty },
134  { cellular::kIMEI, flimflam::kImeiProperty },
135  { cellular::kIMSI, flimflam::kImsiProperty },
136  { cellular::kManufacturer, flimflam::kManufacturerProperty },
137  { cellular::kMDN, flimflam::kMdnProperty },
138  { cellular::kMEID, flimflam::kMeidProperty },
139  { cellular::kMIN, flimflam::kMinProperty },
140  { cellular::kModelID, flimflam::kModelIDProperty },
141  { cellular::kNetworkTechnology, flimflam::kNetworkTechnologyProperty },
142  { cellular::kPRLVersion, flimflam::kPRLVersionProperty },
143  { cellular::kProviderRequiresRoaming,
144    shill::kProviderRequiresRoamingProperty },
145  { cellular::kRoamingState, flimflam::kRoamingStateProperty },
146  { cellular::kSelectedNetwork, flimflam::kSelectedNetworkProperty },
147  { cellular::kServingOperator, flimflam::kServingOperatorProperty },
148  { cellular::kSIMLockStatus, flimflam::kSIMLockStatusProperty },
149  { cellular::kSIMPresent, shill::kSIMPresentProperty },
150  { cellular::kSupportedCarriers, shill::kSupportedCarriersProperty },
151  { cellular::kSupportNetworkScan, flimflam::kSupportNetworkScanProperty },
152  { NULL }
153};
154
155const FieldTranslationEntry network_fields[] = {
156  // Shill doesn't allow setting the name for non-VPN networks.
157  // This field is conditionally translated, see onc_translator_*.
158  // { network_config::kName, flimflam::kNameProperty },
159  { network_config::kGUID, flimflam::kGuidProperty },
160  // This field is converted during translation, see onc_translator_*.
161  // { network_config::kType, flimflam::kTypeProperty },
162
163  // This field is converted during translation, see
164  // onc_translator_shill_to_onc.cc. It is only converted when going from
165  // Shill->ONC, and ignored otherwise.
166  // { network_config::kConnectionState, flimflam::kStateProperty },
167  { NULL }
168};
169
170const OncValueTranslationEntry onc_value_translation_table[] = {
171  { &kEAPSignature, eap_fields },
172  { &kIPsecSignature, ipsec_fields },
173  { &kL2TPSignature, l2tp_fields },
174  { &kOpenVPNSignature, openvpn_fields },
175  { &kVPNSignature, vpn_fields },
176  { &kWiFiSignature, wifi_fields },
177  { &kWiFiWithStateSignature, wifi_fields },
178  { &kCellularProviderSignature, cellular_provider_fields },
179  { &kCellularWithStateSignature, cellular_with_state_fields },
180  { &kNetworkWithStateSignature, network_fields },
181  { &kNetworkConfigurationSignature, network_fields },
182  { NULL }
183};
184
185}  // namespace
186
187const StringTranslationEntry kNetworkTypeTable[] = {
188  { network_type::kEthernet, flimflam::kTypeEthernet },
189  { network_type::kWiFi, flimflam::kTypeWifi },
190  { network_type::kCellular, flimflam::kTypeCellular },
191  { network_type::kVPN, flimflam::kTypeVPN },
192  { NULL }
193};
194
195const StringTranslationEntry kVPNTypeTable[] = {
196  { vpn::kTypeL2TP_IPsec, flimflam::kProviderL2tpIpsec },
197  { vpn::kOpenVPN, flimflam::kProviderOpenVpn },
198  { NULL }
199};
200
201// The first matching line is chosen.
202const StringTranslationEntry kWiFiSecurityTable[] = {
203  { wifi::kNone, flimflam::kSecurityNone },
204  { wifi::kWEP_PSK, flimflam::kSecurityWep },
205  { wifi::kWPA_PSK, flimflam::kSecurityPsk },
206  { wifi::kWPA_EAP, flimflam::kSecurity8021x },
207  { wifi::kWPA_PSK, flimflam::kSecurityRsn },
208  { wifi::kWPA_PSK, flimflam::kSecurityWpa },
209  { NULL }
210};
211
212const StringTranslationEntry kEAPOuterTable[] = {
213  { eap::kPEAP, flimflam::kEapMethodPEAP },
214  { eap::kEAP_TLS, flimflam::kEapMethodTLS },
215  { eap::kEAP_TTLS, flimflam::kEapMethodTTLS },
216  { eap::kLEAP, flimflam::kEapMethodLEAP },
217  { NULL }
218};
219
220// Translation of the EAP.Inner field in case of EAP.Outer == PEAP
221const StringTranslationEntry kEAP_PEAP_InnerTable[] = {
222  { eap::kMD5, flimflam::kEapPhase2AuthPEAPMD5 },
223  { eap::kMSCHAPv2, flimflam::kEapPhase2AuthPEAPMSCHAPV2 },
224  { NULL }
225};
226
227// Translation of the EAP.Inner field in case of EAP.Outer == TTLS
228const StringTranslationEntry kEAP_TTLS_InnerTable[] = {
229  { eap::kMD5, flimflam::kEapPhase2AuthTTLSMD5 },
230  { eap::kMSCHAPv2, flimflam::kEapPhase2AuthTTLSMSCHAPV2 },
231  { eap::kPAP, flimflam::kEapPhase2AuthTTLSPAP },
232  { NULL }
233};
234
235const FieldTranslationEntry* GetFieldTranslationTable(
236    const OncValueSignature& onc_signature) {
237  for (const OncValueTranslationEntry* it = onc_value_translation_table;
238       it->onc_signature != NULL; ++it) {
239    if (it->onc_signature != &onc_signature)
240      continue;
241    return it->field_translation_table;
242  }
243  return NULL;
244}
245
246bool GetShillPropertyName(const std::string& onc_field_name,
247                          const FieldTranslationEntry table[],
248                          std::string* shill_property_name) {
249  for (const FieldTranslationEntry* it = table;
250       it->onc_field_name != NULL; ++it) {
251    if (it->onc_field_name != onc_field_name)
252      continue;
253    *shill_property_name = it->shill_property_name;
254    return true;
255  }
256  return false;
257}
258
259bool TranslateStringToShill(const StringTranslationEntry table[],
260                            const std::string& onc_value,
261                            std::string* shill_value) {
262  for (int i = 0; table[i].onc_value != NULL; ++i) {
263    if (onc_value != table[i].onc_value)
264      continue;
265    *shill_value = table[i].shill_value;
266    return true;
267  }
268  LOG(ERROR) << "Value '" << onc_value << "' cannot be translated to Shill";
269  return false;
270}
271
272bool TranslateStringToONC(const StringTranslationEntry table[],
273                          const std::string& shill_value,
274                          std::string* onc_value) {
275  for (int i = 0; table[i].shill_value != NULL; ++i) {
276    if (shill_value != table[i].shill_value)
277      continue;
278    *onc_value = table[i].onc_value;
279    return true;
280  }
281  LOG(ERROR) << "Value '" << shill_value << "' cannot be translated to ONC";
282  return false;
283}
284
285}  // namespace onc
286}  // namespace chromeos
287