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/network_type_pattern.h"
11 #include "chromeos/network/tether_constants.h"
12 #include "components/onc/onc_constants.h"
13 #include "third_party/cros_system_api/dbus/service_constants.h"
14
15 namespace chromeos {
16 namespace onc {
17
18 // CertificatePattern is converted with function CreateUIData(...) to UIData
19 // stored in Shill.
20
21 namespace {
22
23 const FieldTranslationEntry eap_fields[] = {
24 {::onc::eap::kAnonymousIdentity, shill::kEapAnonymousIdentityProperty},
25 // This field is converted during translation, see onc_translator_*.
26 // { ::onc::client_cert::kClientCertPKCS11Id, shill::kEapCertIdProperty },
27 {::onc::eap::kIdentity, shill::kEapIdentityProperty},
28 // This field is converted during translation, see onc_translator_*.
29 // { ::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::kSubjectMatch, shill::kEapSubjectMatchProperty},
36 // This field is converted during translation, see onc_translator_*.
37 // {::onc::eap::kSubjectAlternativeNameMatch,
38 // shill::kEapSubjectAlternativeNameMatchProperty},
39 {::onc::eap::kTLSVersionMax, shill::kEapTLSVersionMaxProperty},
40 {::onc::eap::kUseSystemCAs, shill::kEapUseSystemCasProperty},
41 {::onc::eap::kUseProactiveKeyCaching,
42 shill::kEapUseProactiveKeyCachingProperty},
43 {nullptr}};
44
45 const FieldTranslationEntry ipsec_fields[] = {
46 // This field is converted during translation, see onc_translator_*.
47 // { ::onc::ipsec::kAuthenticationType, shill::kL2tpIpsecAuthenticationType
48 // },
49 // {::onc::client_cert::kClientCertPKCS11Id,
50 // shill::kL2tpIpsecClientCertIdProperty},
51 {::onc::ipsec::kGroup, shill::kL2tpIpsecTunnelGroupProperty},
52 // Ignored by Shill, not necessary to synchronize.
53 // { ::onc::ipsec::kIKEVersion, shill::kL2tpIpsecIkeVersion },
54 {::onc::ipsec::kPSK, shill::kL2tpIpsecPskProperty},
55 // This field is converted during translation, see onc_translator_*.
56 // { ::onc::vpn::kSaveCredentials, shill::kSaveCredentialsProperty},
57 {::onc::ipsec::kServerCAPEMs, shill::kL2tpIpsecCaCertPemProperty},
58 {nullptr}};
59
60 const FieldTranslationEntry xauth_fields[] = {
61 {::onc::vpn::kPassword, shill::kL2tpIpsecXauthPasswordProperty},
62 {::onc::vpn::kUsername, shill::kL2tpIpsecXauthUserProperty},
63 {nullptr}};
64
65 const FieldTranslationEntry l2tp_fields[] = {
66 {::onc::l2tp::kPassword, shill::kL2tpIpsecPasswordProperty},
67 // We don't synchronize l2tp's SaveCredentials field for now, as Shill
68 // doesn't support separate settings for ipsec and l2tp.
69 // { ::onc::l2tp::kSaveCredentials, &kBoolSignature },
70 {::onc::l2tp::kUsername, shill::kL2tpIpsecUserProperty},
71 // kLcpEchoDisabled is a bool in ONC and a string in Shill.
72 // {::onc::l2tp::kLcpEchoDisabled,
73 // shill::kL2tpIpsecLcpEchoDisabledProperty},
74 {nullptr}};
75
76 const FieldTranslationEntry openvpn_fields[] = {
77 {::onc::openvpn::kAuth, shill::kOpenVPNAuthProperty},
78 {::onc::openvpn::kAuthNoCache, shill::kOpenVPNAuthNoCacheProperty},
79 {::onc::openvpn::kAuthRetry, shill::kOpenVPNAuthRetryProperty},
80 {::onc::openvpn::kCipher, shill::kOpenVPNCipherProperty},
81 // This field is converted during translation, see onc_translator_*.
82 // {::onc::client_cert::kClientCertPKCS11Id,
83 // shill::kOpenVPNClientCertIdProperty},
84 {::onc::openvpn::kCompLZO, shill::kOpenVPNCompLZOProperty},
85 {::onc::openvpn::kCompNoAdapt, shill::kOpenVPNCompNoAdaptProperty},
86 // This field is converted during translation, see onc_translator_*
87 // {::onc::openvpn::kCompressionAlgorithm, shill::kOpenVPNCompressProperty},
88 {::onc::openvpn::kExtraHosts, shill::kOpenVPNExtraHostsProperty},
89 {::onc::openvpn::kIgnoreDefaultRoute,
90 shill::kOpenVPNIgnoreDefaultRouteProperty},
91 {::onc::openvpn::kKeyDirection, shill::kOpenVPNKeyDirectionProperty},
92 {::onc::openvpn::kNsCertType, shill::kOpenVPNNsCertTypeProperty},
93 // This field is converted during translation, see onc_translator_*.
94 // { ::onc::vpn::kOTP, shill::kOpenVPNTokenProperty or kOpenVPNOTPProperty},
95 // This field is converted during translation, see onc_translator_*.
96 // { ::onc::vpn::kPassword, shill::kOpenVPNPasswordProperty},
97 {::onc::openvpn::kPort, shill::kOpenVPNPortProperty},
98 {::onc::openvpn::kProto, shill::kOpenVPNProtoProperty},
99 {::onc::openvpn::kPushPeerInfo, shill::kOpenVPNPushPeerInfoProperty},
100 {::onc::openvpn::kRemoteCertEKU, shill::kOpenVPNRemoteCertEKUProperty},
101 // This field is converted during translation, see onc_translator_*.
102 // { ::onc::openvpn::kRemoteCertKU, shill::kOpenVPNRemoteCertKUProperty },
103 {::onc::openvpn::kRemoteCertTLS, shill::kOpenVPNRemoteCertTLSProperty},
104 {::onc::openvpn::kRenegSec, shill::kOpenVPNRenegSecProperty},
105 // This field is converted during translation, see onc_translator_*.
106 // { ::onc::vpn::kSaveCredentials, shill::kSaveCredentialsProperty},
107 {::onc::openvpn::kServerCAPEMs, shill::kOpenVPNCaCertPemProperty},
108 {::onc::openvpn::kServerPollTimeout,
109 shill::kOpenVPNServerPollTimeoutProperty},
110 {::onc::openvpn::kShaper, shill::kOpenVPNShaperProperty},
111 {::onc::openvpn::kStaticChallenge, shill::kOpenVPNStaticChallengeProperty},
112 {::onc::openvpn::kTLSAuthContents, shill::kOpenVPNTLSAuthContentsProperty},
113 {::onc::openvpn::kTLSRemote, shill::kOpenVPNTLSRemoteProperty},
114 {::onc::openvpn::kTLSVersionMin, shill::kOpenVPNTLSVersionMinProperty},
115 {::onc::vpn::kUsername, shill::kOpenVPNUserProperty},
116 {::onc::openvpn::kVerb, shill::kOpenVPNVerbProperty},
117 {::onc::openvpn::kVerifyHash, shill::kOpenVPNVerifyHashProperty},
118 {nullptr}};
119
120 const FieldTranslationEntry arc_vpn_fields[] = {
121 {::onc::arc_vpn::kTunnelChrome, shill::kArcVpnTunnelChromeProperty},
122 {nullptr}};
123
124 const FieldTranslationEntry verify_x509_fields[] = {
125 {::onc::verify_x509::kName, shill::kOpenVPNVerifyX509NameProperty},
126 {::onc::verify_x509::kType, shill::kOpenVPNVerifyX509TypeProperty},
127 {nullptr}};
128
129 const FieldTranslationEntry vpn_fields[] = {
130 {::onc::vpn::kAutoConnect, shill::kAutoConnectProperty},
131 // These fields are converted during translation, see onc_translator_*.
132 // { ::onc::vpn::kHost, shill::kProviderHostProperty},
133 // { ::onc::vpn::kType, shill::kProviderTypeProperty },
134 {nullptr}};
135
136 const FieldTranslationEntry tether_fields[] = {
137 {::onc::tether::kBatteryPercentage, kTetherBatteryPercentage},
138 {::onc::tether::kCarrier, kTetherCarrier},
139 {::onc::tether::kHasConnectedToHost, kTetherHasConnectedToHost},
140 {::onc::tether::kSignalStrength, kTetherSignalStrength},
141 {nullptr}};
142
143 const FieldTranslationEntry wifi_fields[] = {
144 {::onc::wifi::kAutoConnect, shill::kAutoConnectProperty},
145 {::onc::wifi::kBSSID, shill::kWifiBSsid},
146 // This dictionary is converted during translation, see onc_translator_*.
147 // { ::onc::wifi::kEAP, shill::kEap*},
148 {::onc::wifi::kFrequency, shill::kWifiFrequency},
149 {::onc::wifi::kFrequencyList, shill::kWifiFrequencyListProperty},
150 {::onc::wifi::kHexSSID, shill::kWifiHexSsid},
151 {::onc::wifi::kHiddenSSID, shill::kWifiHiddenSsid},
152 {::onc::wifi::kPassphrase, shill::kPassphraseProperty},
153 // This field is converted during translation, see onc_translator_*.
154 // { ::onc::wifi::kSecurity, shill::kSecurityClassProperty },
155 {::onc::wifi::kSignalStrength, shill::kSignalStrengthProperty},
156 {::onc::wifi::kTetheringState, shill::kTetheringProperty},
157 {nullptr}};
158
159 const FieldTranslationEntry cellular_apn_fields[] = {
160 {::onc::cellular_apn::kAccessPointName, shill::kApnProperty},
161 {::onc::cellular_apn::kName, shill::kApnNameProperty},
162 {::onc::cellular_apn::kUsername, shill::kApnUsernameProperty},
163 {::onc::cellular_apn::kPassword, shill::kApnPasswordProperty},
164 {::onc::cellular_apn::kAuthentication, shill::kApnAuthenticationProperty},
165 {::onc::cellular_apn::kLocalizedName, shill::kApnLocalizedNameProperty},
166 {::onc::cellular_apn::kLanguage, shill::kApnLanguageProperty},
167 {nullptr}};
168
169 const FieldTranslationEntry cellular_found_network_fields[] = {
170 {::onc::cellular_found_network::kNetworkId, shill::kNetworkIdProperty},
171 {::onc::cellular_found_network::kStatus, shill::kStatusProperty},
172 {::onc::cellular_found_network::kTechnology, shill::kTechnologyProperty},
173 {::onc::cellular_found_network::kShortName, shill::kShortNameProperty},
174 {::onc::cellular_found_network::kLongName, shill::kLongNameProperty},
175 {nullptr}};
176
177 const FieldTranslationEntry cellular_payment_portal_fields[] = {
178 {::onc::cellular_payment_portal::kMethod, shill::kPaymentPortalMethod},
179 {::onc::cellular_payment_portal::kPostData, shill::kPaymentPortalPostData},
180 {::onc::cellular_payment_portal::kUrl, shill::kPaymentPortalURL},
181 {nullptr}};
182
183 const FieldTranslationEntry cellular_provider_fields[] = {
184 {::onc::cellular_provider::kCode, shill::kOperatorCodeKey},
185 {::onc::cellular_provider::kCountry, shill::kOperatorCountryKey},
186 {::onc::cellular_provider::kName, shill::kOperatorNameKey},
187 {nullptr}};
188
189 const FieldTranslationEntry sim_lock_status_fields[] = {
190 {::onc::sim_lock_status::kLockEnabled, shill::kSIMLockEnabledProperty},
191 {::onc::sim_lock_status::kLockType, shill::kSIMLockTypeProperty},
192 {::onc::sim_lock_status::kRetriesLeft, shill::kSIMLockRetriesLeftProperty},
193 {nullptr}};
194
195 // This must only contain Service properties and not Device properties.
196 // For Device properties see kCellularDeviceTable.
197 const FieldTranslationEntry cellular_fields[] = {
198 {::onc::cellular::kActivationType, shill::kActivationTypeProperty},
199 // This field is converted during translation, see onc_translator_*.
200 // { ::onc::cellular::kActivationState, shill::kActivationStateProperty},
201 {::onc::cellular::kAutoConnect, shill::kAutoConnectProperty},
202 {::onc::cellular::kICCID, shill::kIccidProperty},
203 {::onc::cellular::kIMSI, shill::kImsiProperty},
204 // This field is converted during translation, see onc_translator_*.
205 // { ::onc::cellular::kNetworkTechnology,
206 // shill::kNetworkTechnologyProperty},
207 // This field is converted during translation, see onc_translator_*.
208 // { ::onc::cellular::kPaymentPortal, shill::kPaymentPortal},
209 // This field is converted during translation, see onc_translator_*.
210 // { ::onc::cellular::kRoamingState, shill::kRoamingStateProperty},
211 {::onc::cellular::kSignalStrength, shill::kSignalStrengthProperty},
212 {nullptr}};
213
214 const FieldTranslationEntry network_fields[] = {
215 {::onc::network_config::kGUID, shill::kGuidProperty},
216 {::onc::network_config::kConnectable, shill::kConnectableProperty},
217 {::onc::network_config::kMetered, shill::kMeteredProperty},
218 {::onc::network_config::kPriority, shill::kPriorityProperty},
219
220 // Shill doesn't allow setting the name for non-VPN networks.
221 // Name is conditionally translated, see onc_translator_*.
222 // {::onc::network_config::kName, shill::kNameProperty },
223
224 // Type is converted during translation, see onc_translator_*.
225 // {::onc::network_config::kType, shill::kTypeProperty },
226 // {::onc::network_config::kProxySettings, shill::ProxyConfig},
227
228 // These fields are converted during translation, see
229 // onc_translator_shill_to_onc.cc. They are only converted when going from
230 // Shill->ONC, and ignored otherwise.
231 // {::onc::network_config::kConnectionState, shill::kStateProperty },
232 // {::onc::network_config::kErrorState, shill::kErrorProperty},
233 // {::onc::network_config::kRestrictedConnectivity, shill::kStateProperty },
234 // {::onc::network_config::kSource, shill::kProfileProperty },
235 // {::onc::network_config::kMacAddress, shill::kAddressProperty },
236 {nullptr}};
237
238 const FieldTranslationEntry ipconfig_fields[] = {
239 {::onc::ipconfig::kIPAddress, shill::kAddressProperty},
240 {::onc::ipconfig::kGateway, shill::kGatewayProperty},
241 {::onc::ipconfig::kRoutingPrefix, shill::kPrefixlenProperty},
242 {::onc::ipconfig::kNameServers, shill::kNameServersProperty},
243 // This field is converted during translation, see ShillToONCTranslator::
244 // TranslateIPConfig. It is only converted from Shill->ONC.
245 // { ::onc::ipconfig::kType, shill::kMethodProperty},
246 {::onc::ipconfig::kWebProxyAutoDiscoveryUrl,
247 shill::kWebProxyAutoDiscoveryUrlProperty},
248 {nullptr}};
249
250 const FieldTranslationEntry static_or_saved_ipconfig_fields[] = {
251 {::onc::ipconfig::kIPAddress, shill::kAddressProperty},
252 {::onc::ipconfig::kGateway, shill::kGatewayProperty},
253 {::onc::ipconfig::kRoutingPrefix, shill::kPrefixlenProperty},
254 {::onc::ipconfig::kNameServers, shill::kNameServersProperty},
255 {::onc::ipconfig::kSearchDomains, shill::kSearchDomainsProperty},
256 {::onc::ipconfig::kIncludedRoutes, shill::kIncludedRoutesProperty},
257 {::onc::ipconfig::kExcludedRoutes, shill::kExcludedRoutesProperty},
258 {nullptr}};
259
260 struct OncValueTranslationEntry {
261 const OncValueSignature* onc_signature;
262 const FieldTranslationEntry* field_translation_table;
263 };
264
265 const OncValueTranslationEntry onc_value_translation_table[] = {
266 {&kEAPSignature, eap_fields},
267 {&kIPsecSignature, ipsec_fields},
268 {&kL2TPSignature, l2tp_fields},
269 {&kXAUTHSignature, xauth_fields},
270 {&kOpenVPNSignature, openvpn_fields},
271 {&kARCVPNSignature, arc_vpn_fields},
272 {&kVerifyX509Signature, verify_x509_fields},
273 {&kVPNSignature, vpn_fields},
274 {&kTetherSignature, tether_fields},
275 {&kTetherWithStateSignature, tether_fields},
276 {&kWiFiSignature, wifi_fields},
277 {&kWiFiWithStateSignature, wifi_fields},
278 {&kCellularApnSignature, cellular_apn_fields},
279 {&kCellularFoundNetworkSignature, cellular_found_network_fields},
280 {&kCellularPaymentPortalSignature, cellular_payment_portal_fields},
281 {&kCellularProviderSignature, cellular_provider_fields},
282 {&kSIMLockStatusSignature, sim_lock_status_fields},
283 {&kCellularSignature, cellular_fields},
284 {&kCellularWithStateSignature, cellular_fields},
285 {&kNetworkWithStateSignature, network_fields},
286 {&kNetworkConfigurationSignature, network_fields},
287 {&kIPConfigSignature, ipconfig_fields},
288 {&kSavedIPConfigSignature, static_or_saved_ipconfig_fields},
289 {&kStaticIPConfigSignature, static_or_saved_ipconfig_fields},
290 {nullptr}};
291
292 struct NestedShillDictionaryEntry {
293 const OncValueSignature* onc_signature;
294 // nullptr terminated list of Shill property keys.
295 const char* const* shill_property_path;
296 };
297
298 const char* cellular_apn_path_entries[] = {shill::kCellularApnProperty,
299 nullptr};
300
301 const char* static_ip_config_path_entries[] = {shill::kStaticIPConfigProperty,
302 nullptr};
303
304 const NestedShillDictionaryEntry nested_shill_dictionaries[] = {
305 {&kCellularApnSignature, cellular_apn_path_entries},
306 {&kStaticIPConfigSignature, static_ip_config_path_entries},
307 {nullptr}};
308
309 } // namespace
310
311 const StringTranslationEntry kNetworkTypeTable[] = {
312 {::onc::network_type::kEthernet, shill::kTypeEthernet},
313 // kTypeEthernetEap is set in onc_translator_onc_to_shill.cc.
314 // { ::onc::network_type::kEthernet, shill::kTypeEthernetEap },
315 {::onc::network_type::kWiFi, shill::kTypeWifi},
316 // wimax entries are ignored in onc_translator_onc_to_shill.cc.
317 // {::onc::network_type::kWimax, shill::kTypeWimax},
318 {::onc::network_type::kCellular, shill::kTypeCellular},
319 {::onc::network_type::kVPN, shill::kTypeVPN},
320 {::onc::network_type::kTether, kTypeTether},
321 {nullptr}};
322
323 const StringTranslationEntry kVPNTypeTable[] = {
324 {::onc::vpn::kTypeL2TP_IPsec, shill::kProviderL2tpIpsec},
325 {::onc::vpn::kOpenVPN, shill::kProviderOpenVpn},
326 {::onc::vpn::kThirdPartyVpn, shill::kProviderThirdPartyVpn},
327 {::onc::vpn::kArcVpn, shill::kProviderArcVpn},
328 {nullptr}};
329
330 const StringTranslationEntry kWiFiSecurityTable[] = {
331 {::onc::wifi::kSecurityNone, shill::kSecurityNone},
332 {::onc::wifi::kWEP_PSK, shill::kSecurityWep},
333 {::onc::wifi::kWPA_PSK, shill::kSecurityPsk},
334 {::onc::wifi::kWPA_EAP, shill::kSecurity8021x},
335 {::onc::wifi::kWEP_8021X, shill::kSecurityWep},
336 {nullptr}};
337
338 const StringTranslationEntry kEAPOuterTable[] = {
339 {::onc::eap::kPEAP, shill::kEapMethodPEAP},
340 {::onc::eap::kEAP_TLS, shill::kEapMethodTLS},
341 {::onc::eap::kEAP_TTLS, shill::kEapMethodTTLS},
342 {::onc::eap::kLEAP, shill::kEapMethodLEAP},
343 {nullptr}};
344
345 // Translation of the EAP.Inner field in case of EAP.Outer == PEAP
346 const StringTranslationEntry kEAP_PEAP_InnerTable[] = {
347 {::onc::eap::kGTC, shill::kEapPhase2AuthPEAPGTC},
348 {::onc::eap::kMD5, shill::kEapPhase2AuthPEAPMD5},
349 {::onc::eap::kMSCHAPv2, shill::kEapPhase2AuthPEAPMSCHAPV2},
350 {nullptr}};
351
352 // Translation of the EAP.Inner field in case of EAP.Outer == TTLS
353 const StringTranslationEntry kEAP_TTLS_InnerTable[] = {
354 {::onc::eap::kGTC, shill::kEapPhase2AuthTTLSGTC},
355 {::onc::eap::kMD5, shill::kEapPhase2AuthTTLSMD5},
356 {::onc::eap::kMSCHAP, shill::kEapPhase2AuthTTLSMSCHAP},
357 {::onc::eap::kMSCHAPv2, shill::kEapPhase2AuthTTLSMSCHAPV2},
358 {::onc::eap::kPAP, shill::kEapPhase2AuthTTLSPAP},
359 {nullptr}};
360
361 const StringTranslationEntry kActivationStateTable[] = {
362 {::onc::cellular::kActivated, shill::kActivationStateActivated},
363 {::onc::cellular::kActivating, shill::kActivationStateActivating},
364 {::onc::cellular::kNotActivated, shill::kActivationStateNotActivated},
365 {::onc::cellular::kPartiallyActivated,
366 shill::kActivationStatePartiallyActivated},
367 {nullptr}};
368
369 const StringTranslationEntry kNetworkTechnologyTable[] = {
370 {::onc::cellular::kTechnologyCdma1Xrtt, shill::kNetworkTechnology1Xrtt},
371 {::onc::cellular::kTechnologyGsm, shill::kNetworkTechnologyGsm},
372 {::onc::cellular::kTechnologyEdge, shill::kNetworkTechnologyEdge},
373 {::onc::cellular::kTechnologyEvdo, shill::kNetworkTechnologyEvdo},
374 {::onc::cellular::kTechnologyGprs, shill::kNetworkTechnologyGprs},
375 {::onc::cellular::kTechnologyHspa, shill::kNetworkTechnologyHspa},
376 {::onc::cellular::kTechnologyHspaPlus, shill::kNetworkTechnologyHspaPlus},
377 {::onc::cellular::kTechnologyLte, shill::kNetworkTechnologyLte},
378 {::onc::cellular::kTechnologyLteAdvanced,
379 shill::kNetworkTechnologyLteAdvanced},
380 {::onc::cellular::kTechnologyUmts, shill::kNetworkTechnologyUmts},
381 {nullptr}};
382
383 const StringTranslationEntry kRoamingStateTable[] = {
384 {::onc::cellular::kRoamingHome, shill::kRoamingStateHome},
385 {::onc::cellular::kRoamingRoaming, shill::kRoamingStateRoaming},
386 {nullptr}};
387
388 const StringTranslationEntry kTetheringStateTable[] = {
389 {::onc::tethering_state::kTetheringConfirmedState,
390 shill::kTetheringConfirmedState},
391 {::onc::tethering_state::kTetheringNotDetectedState,
392 shill::kTetheringNotDetectedState},
393 {::onc::tethering_state::kTetheringSuspectedState,
394 shill::kTetheringSuspectedState},
395 {nullptr}};
396
397 const StringTranslationEntry kOpenVpnCompressionAlgorithmTable[] = {
398 {::onc::openvpn_compression_algorithm::kFramingOnly,
399 shill::kOpenVPNCompressFramingOnly},
400 {::onc::openvpn_compression_algorithm::kLz4, shill::kOpenVPNCompressLz4},
401 {::onc::openvpn_compression_algorithm::kLz4V2,
402 shill::kOpenVPNCompressLz4V2},
403 {::onc::openvpn_compression_algorithm::kLzo, shill::kOpenVPNCompressLzo},
404 {nullptr}};
405
406 // This must contain only Shill Device properties and no Service properties.
407 // For Service properties see cellular_fields.
408 const FieldTranslationEntry kCellularDeviceTable[] = {
409 // This field is converted during translation, see onc_translator_*.
410 // { ::onc::cellular::kAPNList, shill::kCellularApnListProperty},
411 {::onc::cellular::kAllowRoaming, shill::kCellularAllowRoamingProperty},
412 {::onc::cellular::kESN, shill::kEsnProperty},
413 {::onc::cellular::kFamily, shill::kTechnologyFamilyProperty},
414 {::onc::cellular::kFirmwareRevision, shill::kFirmwareRevisionProperty},
415 // This field is converted during translation, see onc_translator_*.
416 // { ::onc::cellular::kFoundNetworks, shill::kFoundNetworksProperty},
417 {::onc::cellular::kHardwareRevision, shill::kHardwareRevisionProperty},
418 // This field is converted during translation, see onc_translator_*.
419 // { ::onc::cellular::kHomeProvider, shill::kHomeProviderProperty},
420 // ICCID is only copied from the Device if not provided by the Service.
421 // {::onc::cellular::kICCID, shill::kIccidProperty},
422 {::onc::cellular::kIMEI, shill::kImeiProperty},
423 // IMSI is only copied from the Device if not provided by the Service.
424 // {::onc::cellular::kIMSI, shill::kImsiProperty},
425 {::onc::cellular::kManufacturer, shill::kManufacturerProperty},
426 {::onc::cellular::kMDN, shill::kMdnProperty},
427 {::onc::cellular::kMEID, shill::kMeidProperty},
428 {::onc::cellular::kMIN, shill::kMinProperty},
429 {::onc::cellular::kModelID, shill::kModelIdProperty},
430 {::onc::cellular::kScanning, shill::kScanningProperty},
431 // This field is converted during translation, see onc_translator_*.
432 // { ::onc::cellular::kSIMLockStatus, shill::kSIMLockStatusProperty},
433 {::onc::cellular::kSIMPresent, shill::kSIMPresentProperty},
434 {::onc::cellular::kSupportNetworkScan, shill::kSupportNetworkScanProperty},
435 {nullptr}};
436
GetFieldTranslationTable(const OncValueSignature & onc_signature)437 const FieldTranslationEntry* GetFieldTranslationTable(
438 const OncValueSignature& onc_signature) {
439 for (const OncValueTranslationEntry* it = onc_value_translation_table;
440 it->onc_signature != nullptr; ++it) {
441 if (it->onc_signature == &onc_signature)
442 return it->field_translation_table;
443 }
444 return nullptr;
445 }
446
GetPathToNestedShillDictionary(const OncValueSignature & onc_signature)447 std::vector<std::string> GetPathToNestedShillDictionary(
448 const OncValueSignature& onc_signature) {
449 std::vector<std::string> shill_property_path;
450 for (const NestedShillDictionaryEntry* it = nested_shill_dictionaries;
451 it->onc_signature != nullptr; ++it) {
452 if (it->onc_signature == &onc_signature) {
453 for (const char* const* key = it->shill_property_path; *key != nullptr;
454 ++key) {
455 shill_property_path.push_back(std::string(*key));
456 }
457 break;
458 }
459 }
460 return shill_property_path;
461 }
462
GetShillPropertyName(const std::string & onc_field_name,const FieldTranslationEntry table[],std::string * shill_property_name)463 bool GetShillPropertyName(const std::string& onc_field_name,
464 const FieldTranslationEntry table[],
465 std::string* shill_property_name) {
466 for (const FieldTranslationEntry* it = table; it->onc_field_name != nullptr;
467 ++it) {
468 if (it->onc_field_name != onc_field_name)
469 continue;
470 *shill_property_name = it->shill_property_name;
471 return true;
472 }
473 return false;
474 }
475
TranslateStringToShill(const StringTranslationEntry table[],const std::string & onc_value,std::string * shill_value)476 bool TranslateStringToShill(const StringTranslationEntry table[],
477 const std::string& onc_value,
478 std::string* shill_value) {
479 for (int i = 0; table[i].onc_value != nullptr; ++i) {
480 if (onc_value != table[i].onc_value)
481 continue;
482 *shill_value = table[i].shill_value;
483 return true;
484 }
485 LOG(ERROR) << "Value '" << onc_value << "' cannot be translated to Shill"
486 << " table[0]: " << table[0].onc_value << " => "
487 << table[0].shill_value;
488 return false;
489 }
490
TranslateStringToONC(const StringTranslationEntry table[],const std::string & shill_value,std::string * onc_value)491 bool TranslateStringToONC(const StringTranslationEntry table[],
492 const std::string& shill_value,
493 std::string* onc_value) {
494 for (int i = 0; table[i].shill_value != nullptr; ++i) {
495 if (shill_value != table[i].shill_value)
496 continue;
497 *onc_value = table[i].onc_value;
498 return true;
499 }
500 LOG(ERROR) << "Value '" << shill_value << "' cannot be translated to ONC"
501 << " table[0]: " << table[0].shill_value << " => "
502 << table[0].onc_value;
503 return false;
504 }
505
506 } // namespace onc
507 } // namespace chromeos
508