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 { ::onc::vpn::kPassword
, shill::kOpenVPNPasswordProperty
},
75 { ::onc::openvpn::kPort
, shill::kOpenVPNPortProperty
},
76 { ::onc::openvpn::kProto
, shill::kOpenVPNProtoProperty
},
77 { ::onc::openvpn::kPushPeerInfo
, shill::kOpenVPNPushPeerInfoProperty
},
78 { ::onc::openvpn::kRemoteCertEKU
, shill::kOpenVPNRemoteCertEKUProperty
},
79 // This field is converted during translation, see onc_translator_*.
80 // { ::onc::openvpn::kRemoteCertKU, shill::kOpenVPNRemoteCertKUProperty },
81 { ::onc::openvpn::kRemoteCertTLS
, shill::kOpenVPNRemoteCertTLSProperty
},
82 { ::onc::openvpn::kRenegSec
, shill::kOpenVPNRenegSecProperty
},
83 // This field is converted during translation, see onc_translator_*.
84 // { ::onc::vpn::kSaveCredentials, shill::kSaveCredentialsProperty},
85 { ::onc::openvpn::kServerCAPEMs
, shill::kOpenVPNCaCertPemProperty
},
86 { ::onc::openvpn::kServerPollTimeout
,
87 shill::kOpenVPNServerPollTimeoutProperty
},
88 { ::onc::openvpn::kShaper
, shill::kOpenVPNShaperProperty
},
89 { ::onc::openvpn::kStaticChallenge
, shill::kOpenVPNStaticChallengeProperty
},
90 { ::onc::openvpn::kTLSAuthContents
, shill::kOpenVPNTLSAuthContentsProperty
},
91 { ::onc::openvpn::kTLSRemote
, shill::kOpenVPNTLSRemoteProperty
},
92 { ::onc::vpn::kUsername
, shill::kOpenVPNUserProperty
},
93 { ::onc::openvpn::kVerifyHash
, shill::kOpenVPNVerifyHashProperty
},
96 const FieldTranslationEntry verify_x509_fields
[] = {
97 { ::onc::verify_x509::kName
, shill::kOpenVPNVerifyX509NameProperty
},
98 { ::onc::verify_x509::kType
, shill::kOpenVPNVerifyX509TypeProperty
},
101 const FieldTranslationEntry vpn_fields
[] = {
102 { ::onc::vpn::kAutoConnect
, shill::kAutoConnectProperty
},
103 // These fields are converted during translation, see onc_translator_*.
104 // { ::onc::vpn::kHost, shill::kProviderHostProperty},
105 // { ::onc::vpn::kType, shill::kProviderTypeProperty },
108 const FieldTranslationEntry wifi_fields
[] = {
109 { ::onc::wifi::kAutoConnect
, shill::kAutoConnectProperty
},
110 { ::onc::wifi::kBSSID
, shill::kWifiBSsid
},
111 { ::onc::wifi::kFrequency
, shill::kWifiFrequency
},
112 { ::onc::wifi::kFrequencyList
, shill::kWifiFrequencyListProperty
},
113 { ::onc::wifi::kHiddenSSID
, shill::kWifiHiddenSsid
},
114 { ::onc::wifi::kPassphrase
, shill::kPassphraseProperty
},
115 // This field is converted during translation, see onc_translator_*.
116 // { ::onc::wifi::kSSID, shill::kWifiHexSsid},
117 // This field is converted during translation, see onc_translator_*.
118 // { ::onc::wifi::kSecurity, shill::kSecurityProperty },
119 { ::onc::wifi::kSignalStrength
, shill::kSignalStrengthProperty
},
122 const FieldTranslationEntry cellular_apn_fields
[] = {
123 { ::onc::cellular_apn::kAccessPointName
, shill::kApnProperty
},
124 { ::onc::cellular_apn::kName
, shill::kApnNameProperty
},
125 { ::onc::cellular_apn::kUsername
, shill::kApnUsernameProperty
},
126 { ::onc::cellular_apn::kPassword
, shill::kApnPasswordProperty
},
127 { ::onc::cellular_apn::kLocalizedName
, shill::kApnLocalizedNameProperty
},
128 { ::onc::cellular_apn::kLanguage
, shill::kApnLanguageProperty
},
131 const FieldTranslationEntry cellular_found_network_fields
[] = {
132 { ::onc::cellular_found_network::kNetworkId
, shill::kNetworkIdProperty
},
133 { ::onc::cellular_found_network::kStatus
, shill::kStatusProperty
},
134 { ::onc::cellular_found_network::kTechnology
, shill::kTechnologyProperty
},
135 { ::onc::cellular_found_network::kShortName
, shill::kShortNameProperty
},
136 { ::onc::cellular_found_network::kLongName
, shill::kLongNameProperty
},
139 const FieldTranslationEntry cellular_provider_fields
[] = {
140 { ::onc::cellular_provider::kCode
, shill::kOperatorCodeKey
},
141 { ::onc::cellular_provider::kCountry
, shill::kOperatorCountryKey
},
142 { ::onc::cellular_provider::kName
, shill::kOperatorNameKey
},
145 const FieldTranslationEntry sim_lock_status_fields
[] = {
146 { ::onc::sim_lock_status::kLockEnabled
, shill::kSIMLockEnabledProperty
},
147 { ::onc::sim_lock_status::kLockType
, shill::kSIMLockTypeProperty
},
148 { ::onc::sim_lock_status::kRetriesLeft
, shill::kSIMLockRetriesLeftProperty
},
151 // This must only contain Service properties and not Device properties.
152 // For Device properties see kCellularDeviceTable.
153 const FieldTranslationEntry cellular_fields
[] = {
154 { ::onc::cellular::kActivationType
, shill::kActivationTypeProperty
},
155 // This field is converted during translation, see onc_translator_*.
156 // { ::onc::cellular::kActivationState, shill::kActivationStateProperty},
157 { ::onc::cellular::kNetworkTechnology
, shill::kNetworkTechnologyProperty
},
158 // This field is converted during translation, see onc_translator_*.
159 // { ::onc::cellular::kRoamingState, shill::kRoamingStateProperty},
162 const FieldTranslationEntry network_fields
[] = {
163 { ::onc::network_config::kGUID
, shill::kGuidProperty
},
164 { ::onc::network_config::kConnectable
, shill::kConnectableProperty
},
165 { ::onc::network_config::kErrorState
, shill::kErrorProperty
},
166 { ::onc::network_config::kPriority
, shill::kPriorityProperty
},
168 // Shill doesn't allow setting the name for non-VPN networks.
169 // Name is conditionally translated, see onc_translator_*.
170 // { ::onc::network_config::kName, shill::kNameProperty },
172 // Type is converted during translation, see onc_translator_*.
173 // { ::onc::network_config::kType, shill::kTypeProperty },
175 // These fields are converted during translation, see
176 // onc_translator_shill_to_onc.cc. They are only converted when going from
177 // Shill->ONC, and ignored otherwise.
178 // { ::onc::network_config::kConnectionState, shill::kStateProperty },
179 // { ::onc::network_config::kRestrictedConnectivity,
180 // shill::kStateProperty },
181 // { ::onc::network_config::kSource, shill::kProfileProperty },
182 // { ::onc::network_config::kMacAddress, shill::kAddressProperty },
185 const FieldTranslationEntry ipconfig_fields
[] = {
186 { ::onc::ipconfig::kIPAddress
, shill::kAddressProperty
},
187 { ::onc::ipconfig::kGateway
, shill::kGatewayProperty
},
188 { ::onc::ipconfig::kRoutingPrefix
, shill::kPrefixlenProperty
},
189 { ::onc::ipconfig::kNameServers
, shill::kNameServersProperty
},
190 // This field is converted during translation, see ShillToONCTranslator::
191 // TranslateIPConfig. It is only converted from Shill->ONC.
192 // { ::onc::ipconfig::kType, shill::kMethodProperty},
193 { ::onc::ipconfig::kWebProxyAutoDiscoveryUrl
,
194 shill::kWebProxyAutoDiscoveryUrlProperty
},
197 const FieldTranslationEntry saved_ipconfig_fields
[] = {
198 { ::onc::ipconfig::kIPAddress
, shill::kSavedIPAddressProperty
},
199 { ::onc::ipconfig::kGateway
, shill::kSavedIPGatewayProperty
},
200 { ::onc::ipconfig::kRoutingPrefix
, shill::kSavedIPPrefixlenProperty
},
201 // NameServers are converted during translation, see onc_translator_*.
202 // { ::onc::ipconfig::kNameServers, shill::kSavedIPNameServersProperty},
205 const FieldTranslationEntry static_ipconfig_fields
[] = {
206 { ::onc::ipconfig::kIPAddress
, shill::kStaticIPAddressProperty
},
207 { ::onc::ipconfig::kGateway
, shill::kStaticIPGatewayProperty
},
208 { ::onc::ipconfig::kRoutingPrefix
, shill::kStaticIPPrefixlenProperty
},
209 // NameServers are converted during translation, see onc_translator_*.
210 // { ::onc::ipconfig::kNameServers, shill::kStaticIPNameServersProperty},
213 struct OncValueTranslationEntry
{
214 const OncValueSignature
* onc_signature
;
215 const FieldTranslationEntry
* field_translation_table
;
218 const OncValueTranslationEntry onc_value_translation_table
[] = {
219 { &kEAPSignature
, eap_fields
},
220 { &kIPsecSignature
, ipsec_fields
},
221 { &kL2TPSignature
, l2tp_fields
},
222 { &kXAUTHSignature
, xauth_fields
},
223 { &kOpenVPNSignature
, openvpn_fields
},
224 { &kVerifyX509Signature
, verify_x509_fields
},
225 { &kVPNSignature
, vpn_fields
},
226 { &kWiFiSignature
, wifi_fields
},
227 { &kWiFiWithStateSignature
, wifi_fields
},
228 { &kCellularApnSignature
, cellular_apn_fields
},
229 { &kCellularFoundNetworkSignature
, cellular_found_network_fields
},
230 { &kCellularProviderSignature
, cellular_provider_fields
},
231 { &kSIMLockStatusSignature
, sim_lock_status_fields
},
232 { &kCellularSignature
, cellular_fields
},
233 { &kCellularWithStateSignature
, cellular_fields
},
234 { &kNetworkWithStateSignature
, network_fields
},
235 { &kNetworkConfigurationSignature
, network_fields
},
236 { &kIPConfigSignature
, ipconfig_fields
},
237 { &kSavedIPConfigSignature
, saved_ipconfig_fields
},
238 { &kStaticIPConfigSignature
, static_ipconfig_fields
},
242 struct NestedShillDictionaryEntry
{
243 const OncValueSignature
* onc_signature
;
244 // NULL terminated list of Shill property keys.
245 const char* const* shill_property_path
;
248 const char* cellular_apn_property_path_entries
[] = {
249 shill::kCellularApnProperty
,
253 const NestedShillDictionaryEntry nested_shill_dictionaries
[] = {
254 { &kCellularApnSignature
, cellular_apn_property_path_entries
},
260 const StringTranslationEntry kNetworkTypeTable
[] = {
261 // This mapping is ensured in the translation code.
262 // { network_type::kEthernet, shill::kTypeEthernet },
263 // { network_type::kEthernet, shill::kTypeEthernetEap },
264 { ::onc::network_type::kWiFi
, shill::kTypeWifi
},
265 { ::onc::network_type::kWimax
, shill::kTypeWimax
},
266 { ::onc::network_type::kCellular
, shill::kTypeCellular
},
267 { ::onc::network_type::kVPN
, shill::kTypeVPN
},
270 const StringTranslationEntry kVPNTypeTable
[] = {
271 { ::onc::vpn::kTypeL2TP_IPsec
, shill::kProviderL2tpIpsec
},
272 { ::onc::vpn::kOpenVPN
, shill::kProviderOpenVpn
}, {NULL
}};
274 // The first matching line is chosen.
275 const StringTranslationEntry kWiFiSecurityTable
[] = {
276 { ::onc::wifi::kSecurityNone
, shill::kSecurityNone
},
277 { ::onc::wifi::kWEP_PSK
, shill::kSecurityWep
},
278 { ::onc::wifi::kWPA_PSK
, shill::kSecurityPsk
},
279 { ::onc::wifi::kWPA_EAP
, shill::kSecurity8021x
},
280 { ::onc::wifi::kWPA_PSK
, shill::kSecurityRsn
},
281 { ::onc::wifi::kWPA_PSK
, shill::kSecurityWpa
},
284 const StringTranslationEntry kEAPOuterTable
[] = {
285 { ::onc::eap::kPEAP
, shill::kEapMethodPEAP
},
286 { ::onc::eap::kEAP_TLS
, shill::kEapMethodTLS
},
287 { ::onc::eap::kEAP_TTLS
, shill::kEapMethodTTLS
},
288 { ::onc::eap::kLEAP
, shill::kEapMethodLEAP
},
291 // Translation of the EAP.Inner field in case of EAP.Outer == PEAP
292 const StringTranslationEntry kEAP_PEAP_InnerTable
[] = {
293 { ::onc::eap::kMD5
, shill::kEapPhase2AuthPEAPMD5
},
294 { ::onc::eap::kMSCHAPv2
, shill::kEapPhase2AuthPEAPMSCHAPV2
}, {NULL
}};
296 // Translation of the EAP.Inner field in case of EAP.Outer == TTLS
297 const StringTranslationEntry kEAP_TTLS_InnerTable
[] = {
298 { ::onc::eap::kMD5
, shill::kEapPhase2AuthTTLSMD5
},
299 { ::onc::eap::kMSCHAPv2
, shill::kEapPhase2AuthTTLSMSCHAPV2
},
300 { ::onc::eap::kPAP
, shill::kEapPhase2AuthTTLSPAP
},
303 const StringTranslationEntry kActivationStateTable
[] = {
304 { ::onc::cellular::kActivated
, shill::kActivationStateActivated
},
305 { ::onc::cellular::kActivating
, shill::kActivationStateActivating
},
306 { ::onc::cellular::kNotActivated
, shill::kActivationStateNotActivated
},
307 { ::onc::cellular::kPartiallyActivated
,
308 shill::kActivationStatePartiallyActivated
},
311 const StringTranslationEntry kRoamingStateTable
[] = {
312 { ::onc::cellular::kHome
, shill::kRoamingStateHome
},
313 { ::onc::cellular::kRoaming
, shill::kRoamingStateRoaming
},
316 // This must contain only Shill Device properties and no Service properties.
317 // For Service properties see cellular_fields.
318 const FieldTranslationEntry kCellularDeviceTable
[] = {
319 // This field is converted during translation, see onc_translator_*.
320 // { ::onc::cellular::kAPNList, shill::kCellularApnListProperty},
321 { ::onc::cellular::kAllowRoaming
, shill::kCellularAllowRoamingProperty
},
322 { ::onc::cellular::kCarrier
, shill::kCarrierProperty
},
323 { ::onc::cellular::kESN
, shill::kEsnProperty
},
324 { ::onc::cellular::kFamily
, shill::kTechnologyFamilyProperty
},
325 { ::onc::cellular::kFirmwareRevision
, shill::kFirmwareRevisionProperty
},
326 // This field is converted during translation, see onc_translator_*.
327 // { ::onc::cellular::kFoundNetworks, shill::kFoundNetworksProperty},
328 { ::onc::cellular::kHardwareRevision
, shill::kHardwareRevisionProperty
},
329 { ::onc::cellular::kHomeProvider
, shill::kHomeProviderProperty
},
330 { ::onc::cellular::kICCID
, shill::kIccidProperty
},
331 { ::onc::cellular::kIMEI
, shill::kImeiProperty
},
332 { ::onc::cellular::kIMSI
, shill::kImsiProperty
},
333 { ::onc::cellular::kManufacturer
, shill::kManufacturerProperty
},
334 { ::onc::cellular::kMDN
, shill::kMdnProperty
},
335 { ::onc::cellular::kMEID
, shill::kMeidProperty
},
336 { ::onc::cellular::kMIN
, shill::kMinProperty
},
337 { ::onc::cellular::kModelID
, shill::kModelIDProperty
},
338 { ::onc::cellular::kPRLVersion
, shill::kPRLVersionProperty
},
339 { ::onc::cellular::kProviderRequiresRoaming
,
340 shill::kProviderRequiresRoamingProperty
},
341 { ::onc::cellular::kSelectedNetwork
, shill::kSelectedNetworkProperty
},
342 // This field is converted during translation, see onc_translator_*.
343 // { ::onc::cellular::kSIMLockStatus, shill::kSIMLockStatusProperty},
344 { ::onc::cellular::kSIMPresent
, shill::kSIMPresentProperty
},
345 { ::onc::cellular::kSupportedCarriers
, shill::kSupportedCarriersProperty
},
346 { ::onc::cellular::kSupportNetworkScan
, shill::kSupportNetworkScanProperty
},
349 const FieldTranslationEntry
* GetFieldTranslationTable(
350 const OncValueSignature
& onc_signature
) {
351 for (const OncValueTranslationEntry
* it
= onc_value_translation_table
;
352 it
->onc_signature
!= NULL
; ++it
) {
353 if (it
->onc_signature
== &onc_signature
)
354 return it
->field_translation_table
;
359 std::vector
<std::string
> GetPathToNestedShillDictionary(
360 const OncValueSignature
& onc_signature
) {
361 std::vector
<std::string
> shill_property_path
;
362 for (const NestedShillDictionaryEntry
* it
= nested_shill_dictionaries
;
363 it
->onc_signature
!= NULL
; ++it
) {
364 if (it
->onc_signature
== &onc_signature
) {
365 for (const char* const* key
= it
->shill_property_path
; *key
!= NULL
;
367 shill_property_path
.push_back(std::string(*key
));
372 return shill_property_path
;
375 bool GetShillPropertyName(const std::string
& onc_field_name
,
376 const FieldTranslationEntry table
[],
377 std::string
* shill_property_name
) {
378 for (const FieldTranslationEntry
* it
= table
;
379 it
->onc_field_name
!= NULL
; ++it
) {
380 if (it
->onc_field_name
!= onc_field_name
)
382 *shill_property_name
= it
->shill_property_name
;
388 bool TranslateStringToShill(const StringTranslationEntry table
[],
389 const std::string
& onc_value
,
390 std::string
* shill_value
) {
391 for (int i
= 0; table
[i
].onc_value
!= NULL
; ++i
) {
392 if (onc_value
!= table
[i
].onc_value
)
394 *shill_value
= table
[i
].shill_value
;
397 LOG(ERROR
) << "Value '" << onc_value
<< "' cannot be translated to Shill";
401 bool TranslateStringToONC(const StringTranslationEntry table
[],
402 const std::string
& shill_value
,
403 std::string
* onc_value
) {
404 for (int i
= 0; table
[i
].shill_value
!= NULL
; ++i
) {
405 if (shill_value
!= table
[i
].shill_value
)
407 *onc_value
= table
[i
].onc_value
;
410 LOG(ERROR
) << "Value '" << shill_value
<< "' cannot be translated to ONC";
415 } // namespace chromeos