File: onc_translation_tables.cc

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (613 lines) | stat: -rw-r--r-- 29,628 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif

#include "chromeos/ash/components/network/onc/onc_translation_tables.h"

#include <cstddef>

#include "base/logging.h"
#include "base/memory/raw_ptr_exclusion.h"
#include "chromeos/ash/components/network/network_type_pattern.h"
#include "chromeos/ash/components/network/tether_constants.h"
#include "components/onc/onc_constants.h"
#include "third_party/cros_system_api/dbus/service_constants.h"
#include "third_party/cros_system_api/dbus/shill/dbus-constants.h"

namespace ash::onc {

// CertificatePattern is converted with function CreateUIData(...) to UIData
// stored in Shill.

namespace {

const FieldTranslationEntry eap_fields[] = {
    {::onc::eap::kAnonymousIdentity, shill::kEapAnonymousIdentityProperty},
    // This field is converted during translation, see onc_translator_*.
    // { ::onc::client_cert::kClientCertPKCS11Id, shill::kEapCertIdProperty },
    {::onc::eap::kDomainSuffixMatch, shill::kEapDomainSuffixMatchProperty},
    {::onc::eap::kIdentity, shill::kEapIdentityProperty},
    // This field is converted during translation, see onc_translator_*.
    // { ::onc::eap::kInner, shill::kEapPhase2AuthProperty },
    // This field is converted during translation, see onc_translator_*.
    // { ::onc::eap::kOuter, shill::kEapMethodProperty },
    {::onc::eap::kPassword, shill::kEapPasswordProperty},
    {::onc::eap::kSaveCredentials, shill::kSaveCredentialsProperty},
    // This field is converted during translation, see onc_translator_*.
    // {::onc::eap::kServerCAPEMs, shill::kEapCaCertPemProperty},
    {::onc::eap::kSubjectMatch, shill::kEapSubjectMatchProperty},
    // This field is converted during translation, see onc_translator_*.
    // {::onc::eap::kSubjectAlternativeNameMatch,
    //  shill::kEapSubjectAlternativeNameMatchProperty},
    {::onc::eap::kTLSVersionMax, shill::kEapTLSVersionMaxProperty},
    {::onc::eap::kUseSystemCAs, shill::kEapUseSystemCasProperty},
    {::onc::eap::kUseProactiveKeyCaching,
     shill::kEapUseProactiveKeyCachingProperty},
    {nullptr}};

// This group of fields are for L2TP/IPsec, see |kIPsecIKEv2Table| for IKEv2.
const FieldTranslationEntry ipsec_fields[] = {
    // This field is converted during translation, see onc_translator_*.
    // { ::onc::ipsec::kAuthenticationType, shill::kL2TPIPsecAuthenticationType
    // },
    // {::onc::client_cert::kClientCertPKCS11Id,
    //  shill::kL2TPIPsecClientCertIdProperty},
    {::onc::ipsec::kGroup, shill::kL2TPIPsecTunnelGroupProperty},
    // Ignored by Shill, not necessary to synchronize.
    // { ::onc::ipsec::kIKEVersion, shill::kL2TPIPsecIkeVersion },
    {::onc::ipsec::kPSK, shill::kL2TPIPsecPskProperty},
    // This field is converted during translation, see onc_translator_*.
    // { ::onc::vpn::kSaveCredentials, shill::kSaveCredentialsProperty},
    {::onc::ipsec::kServerCAPEMs, shill::kL2TPIPsecCaCertPemProperty},
    {nullptr}};

const FieldTranslationEntry xauth_fields[] = {
    {::onc::vpn::kPassword, shill::kL2TPIPsecXauthPasswordProperty},
    {::onc::vpn::kUsername, shill::kL2TPIPsecXauthUserProperty},
    {nullptr}};

const FieldTranslationEntry l2tp_fields[] = {
    {::onc::l2tp::kPassword, shill::kL2TPIPsecPasswordProperty},
    // We don't synchronize l2tp's SaveCredentials field for now, as Shill
    // doesn't support separate settings for ipsec and l2tp.
    // { ::onc::l2tp::kSaveCredentials, &kBoolSignature },
    {::onc::l2tp::kUsername, shill::kL2TPIPsecUserProperty},
    // kLcpEchoDisabled is a bool in ONC and a string in Shill.
    // {::onc::l2tp::kLcpEchoDisabled,
    // shill::kL2TPIPsecLcpEchoDisabledProperty},
    {nullptr}};

const FieldTranslationEntry openvpn_fields[] = {
    {::onc::openvpn::kAuth, shill::kOpenVPNAuthProperty},
    {::onc::openvpn::kAuthNoCache, shill::kOpenVPNAuthNoCacheProperty},
    {::onc::openvpn::kAuthRetry, shill::kOpenVPNAuthRetryProperty},
    {::onc::openvpn::kCipher, shill::kOpenVPNCipherProperty},
    // This field is converted during translation, see onc_translator_*.
    // {::onc::client_cert::kClientCertPKCS11Id,
    //  shill::kOpenVPNClientCertIdProperty},
    {::onc::openvpn::kCompLZO, shill::kOpenVPNCompLZOProperty},
    {::onc::openvpn::kCompNoAdapt, shill::kOpenVPNCompNoAdaptProperty},
    // This field is converted during translation, see onc_translator_*
    // {::onc::openvpn::kCompressionAlgorithm, shill::kOpenVPNCompressProperty},
    {::onc::openvpn::kExtraHosts, shill::kOpenVPNExtraHostsProperty},
    {::onc::openvpn::kIgnoreDefaultRoute,
     shill::kOpenVPNIgnoreDefaultRouteProperty},
    {::onc::openvpn::kKeyDirection, shill::kOpenVPNKeyDirectionProperty},
    {::onc::openvpn::kNsCertType, shill::kOpenVPNNsCertTypeProperty},
    // This field is converted during translation, see onc_translator_*.
    // { ::onc::vpn::kOTP, shill::kOpenVPNTokenProperty or kOpenVPNOTPProperty},
    // This field is converted during translation, see onc_translator_*.
    // { ::onc::vpn::kPassword, shill::kOpenVPNPasswordProperty},
    {::onc::openvpn::kPort, shill::kOpenVPNPortProperty},
    {::onc::openvpn::kProto, shill::kOpenVPNProtoProperty},
    {::onc::openvpn::kPushPeerInfo, shill::kOpenVPNPushPeerInfoProperty},
    {::onc::openvpn::kRemoteCertEKU, shill::kOpenVPNRemoteCertEKUProperty},
    // This field is converted during translation, see onc_translator_*.
    // { ::onc::openvpn::kRemoteCertKU, shill::kOpenVPNRemoteCertKUProperty },
    {::onc::openvpn::kRemoteCertTLS, shill::kOpenVPNRemoteCertTLSProperty},
    {::onc::openvpn::kRenegSec, shill::kOpenVPNRenegSecProperty},
    // This field is converted during translation, see onc_translator_*.
    // { ::onc::vpn::kSaveCredentials, shill::kSaveCredentialsProperty},
    {::onc::openvpn::kServerCAPEMs, shill::kOpenVPNCaCertPemProperty},
    {::onc::openvpn::kServerPollTimeout,
     shill::kOpenVPNServerPollTimeoutProperty},
    {::onc::openvpn::kShaper, shill::kOpenVPNShaperProperty},
    {::onc::openvpn::kStaticChallenge, shill::kOpenVPNStaticChallengeProperty},
    {::onc::openvpn::kTLSAuthContents, shill::kOpenVPNTLSAuthContentsProperty},
    {::onc::openvpn::kTLSRemote, shill::kOpenVPNTLSRemoteProperty},
    {::onc::openvpn::kTLSVersionMin, shill::kOpenVPNTLSVersionMinProperty},
    {::onc::vpn::kUsername, shill::kOpenVPNUserProperty},
    {::onc::openvpn::kVerb, shill::kOpenVPNVerbProperty},
    {::onc::openvpn::kVerifyHash, shill::kOpenVPNVerifyHashProperty},
    {nullptr}};

const FieldTranslationEntry wireguard_fields[] = {
    {::onc::wireguard::kIPAddresses, shill::kWireGuardIPAddress},
    {::onc::wireguard::kPublicKey, shill::kWireGuardPublicKey},
    {::onc::wireguard::kPrivateKey, shill::kWireGuardPrivateKey},
    {::onc::wireguard::kPeers, shill::kWireGuardPeers},
    {nullptr}};

const FieldTranslationEntry wireguard_peer_fields[] = {
    {::onc::wireguard::kPublicKey, shill::kWireGuardPeerPublicKey},
    {::onc::wireguard::kPresharedKey, shill::kWireGuardPeerPresharedKey},
    {::onc::wireguard::kEndpoint, shill::kWireGuardPeerEndpoint},
    {::onc::wireguard::kAllowedIPs, shill::kWireGuardPeerAllowedIPs},
    {::onc::wireguard::kPersistentKeepalive,
     shill::kWireGuardPeerPersistentKeepalive},
    {nullptr}};

const FieldTranslationEntry arc_vpn_fields[] = {{nullptr}};

const FieldTranslationEntry verify_x509_fields[] = {
    {::onc::verify_x509::kName, shill::kOpenVPNVerifyX509NameProperty},
    {::onc::verify_x509::kType, shill::kOpenVPNVerifyX509TypeProperty},
    {nullptr}};

const FieldTranslationEntry vpn_fields[] = {
    {::onc::vpn::kAutoConnect, shill::kAutoConnectProperty},
    // These fields are converted during translation, see onc_translator_*.
    // { ::onc::vpn::kHost, shill::kProviderHostProperty},
    // { ::onc::vpn::kType, shill::kProviderTypeProperty },
    {nullptr}};

const FieldTranslationEntry tether_fields[] = {
    {::onc::tether::kBatteryPercentage, kTetherBatteryPercentage},
    {::onc::tether::kCarrier, kTetherCarrier},
    {::onc::tether::kHasConnectedToHost, kTetherHasConnectedToHost},
    {::onc::tether::kSignalStrength, kTetherSignalStrength},
    {nullptr}};

const FieldTranslationEntry wifi_fields[] = {
    {::onc::wifi::kAutoConnect, shill::kAutoConnectProperty},
    {::onc::wifi::kBSSID, shill::kWifiBSsid},
    {::onc::wifi::kBSSIDAllowlist, shill::kWifiBSSIDAllowlist},
    {::onc::wifi::kBSSIDRequested, shill::kWifiBSSIDRequested},
    // This dictionary is converted during translation, see onc_translator_*.
    // { ::onc::wifi::kEAP, shill::kEap*},
    {::onc::wifi::kFrequency, shill::kWifiFrequency},
    {::onc::wifi::kFrequencyList, shill::kWifiFrequencyListProperty},
    {::onc::wifi::kHexSSID, shill::kWifiHexSsid},
    {::onc::wifi::kHiddenSSID, shill::kWifiHiddenSsid},
    {::onc::wifi::kPassphrase, shill::kPassphraseProperty},
    // This field is converted during translation, see onc_translator_*.
    // { ::onc::wifi::kSecurity, shill::kSecurityClassProperty },
    {::onc::wifi::kSignalStrength, shill::kSignalStrengthProperty},
    {::onc::wifi::kSignalStrengthRssi, shill::kWifiSignalStrengthRssiProperty},
    {::onc::wifi::kPasspointId, shill::kPasspointIDProperty},
    {::onc::wifi::kPasspointMatchType, shill::kPasspointMatchTypeProperty},
    {nullptr}};

const FieldTranslationEntry cellular_apn_fields[] = {
    {::onc::cellular_apn::kAccessPointName, shill::kApnProperty},
    {::onc::cellular_apn::kName, shill::kApnNameProperty},
    {::onc::cellular_apn::kUsername, shill::kApnUsernameProperty},
    {::onc::cellular_apn::kPassword, shill::kApnPasswordProperty},
    // This field is converted during translation, see onc_translator_*.
    // {::onc::cellular_apn::kAuthentication,
    // shill::kApnAuthenticationProperty},
    {::onc::cellular_apn::kLocalizedName, shill::kApnLocalizedNameProperty},
    {::onc::cellular_apn::kLanguage, shill::kApnLanguageProperty},
    {::onc::cellular_apn::kAttach, shill::kApnAttachProperty},
    // This field is converted during translation, see onc_translator_*.
    // {::onc::cellular_apn::kIpType, shill::kApnIpTypeProperty},
    {::onc::cellular_apn::kId, shill::kApnIdProperty},
    // This field is converted during translation, see onc_translator_*.
    // {::onc::cellular_apn::kApnTypes, shill::kApnTypesProperty},
    {nullptr}};

const FieldTranslationEntry cellular_found_network_fields[] = {
    {::onc::cellular_found_network::kNetworkId, shill::kNetworkIdProperty},
    {::onc::cellular_found_network::kStatus, shill::kStatusProperty},
    {::onc::cellular_found_network::kTechnology, shill::kTechnologyProperty},
    {::onc::cellular_found_network::kShortName, shill::kShortNameProperty},
    {::onc::cellular_found_network::kLongName, shill::kLongNameProperty},
    {nullptr}};

const FieldTranslationEntry cellular_payment_portal_fields[] = {
    {::onc::cellular_payment_portal::kMethod, shill::kPaymentPortalMethod},
    {::onc::cellular_payment_portal::kPostData, shill::kPaymentPortalPostData},
    {::onc::cellular_payment_portal::kUrl, shill::kPaymentPortalURL},
    {nullptr}};

const FieldTranslationEntry cellular_provider_fields[] = {
    {::onc::cellular_provider::kCode, shill::kOperatorCodeKey},
    {::onc::cellular_provider::kCountry, shill::kOperatorCountryKey},
    {::onc::cellular_provider::kName, shill::kOperatorNameKey},
    {nullptr}};

const FieldTranslationEntry sim_lock_status_fields[] = {
    {::onc::sim_lock_status::kLockEnabled, shill::kSIMLockEnabledProperty},
    {::onc::sim_lock_status::kLockType, shill::kSIMLockTypeProperty},
    {::onc::sim_lock_status::kRetriesLeft, shill::kSIMLockRetriesLeftProperty},
    {nullptr}};

// This must only contain Service properties and not Device properties.
// For Device properties see kCellularDeviceTable.
const FieldTranslationEntry cellular_fields[] = {
    {::onc::cellular::kActivationType, shill::kActivationTypeProperty},
    // This field is converted during translation, see onc_translator_*.
    // { ::onc::cellular::kActivationState, shill::kActivationStateProperty},
    {::onc::cellular::kAllowRoaming, shill::kCellularAllowRoamingProperty},
    {::onc::cellular::kAutoConnect, shill::kAutoConnectProperty},
    {::onc::cellular::kEID, shill::kEidProperty},
    {::onc::cellular::kICCID, shill::kIccidProperty},
    {::onc::cellular::kIMSI, shill::kImsiProperty},
    // This field is converted during translation, see onc_translator_*.
    // { ::onc::cellular::kNetworkTechnology,
    //   shill::kNetworkTechnologyProperty},
    // This field is converted during translation, see onc_translator_*.
    // { ::onc::cellular::kPaymentPortal, shill::kPaymentPortal},
    // This field is converted during translation, see onc_translator_*.
    // { ::onc::cellular::kRoamingState, shill::kRoamingStateProperty},
    {::onc::cellular::kSignalStrength, shill::kSignalStrengthProperty},
    {nullptr}};

const FieldTranslationEntry network_fields[] = {
    {::onc::network_config::kGUID, shill::kGuidProperty},
    {::onc::network_config::kConnectable, shill::kConnectableProperty},
    {::onc::network_config::kMetered, shill::kMeteredProperty},
    {::onc::network_config::kPriority, shill::kPriorityProperty},

    // Shill doesn't allow setting the name for non-VPN networks.
    // Name is conditionally translated, see onc_translator_*.
    // {::onc::network_config::kName, shill::kNameProperty },

    // Type is converted during translation, see onc_translator_*.
    // {::onc::network_config::kType, shill::kTypeProperty },
    // {::onc::network_config::kProxySettings, shill::ProxyConfig},

    // These fields are converted during translation, see
    // onc_translator_shill_to_onc.cc. They are only converted when going from
    // Shill->ONC, and ignored otherwise.
    // {::onc::network_config::kConnectionState, shill::kStateProperty },
    // {::onc::network_config::kErrorState, shill::kErrorProperty},
    // {::onc::network_config::kRestrictedConnectivity, shill::kStateProperty },
    // {::onc::network_config::kSource, shill::kProfileProperty },
    // {::onc::network_config::kMacAddress, shill::kAddressProperty },
    // {::onc::network_config::kTrafficCounterResetTime,
    // shill::kTrafficCountersResetTime },
    {nullptr}};

const FieldTranslationEntry ipconfig_fields[] = {
    {::onc::ipconfig::kIPAddress, shill::kAddressProperty},
    {::onc::ipconfig::kGateway, shill::kGatewayProperty},
    {::onc::ipconfig::kRoutingPrefix, shill::kPrefixlenProperty},
    {::onc::ipconfig::kNameServers, shill::kNameServersProperty},
    // This field is converted during translation, see ShillToONCTranslator::
    // TranslateIPConfig. It is only converted from Shill->ONC.
    // { ::onc::ipconfig::kType, shill::kMethodProperty},
    {::onc::ipconfig::kWebProxyAutoDiscoveryUrl,
     shill::kWebProxyAutoDiscoveryUrlProperty},
    {nullptr}};

const FieldTranslationEntry static_or_saved_ipconfig_fields[] = {
    {::onc::ipconfig::kIPAddress, shill::kAddressProperty},
    {::onc::ipconfig::kGateway, shill::kGatewayProperty},
    {::onc::ipconfig::kRoutingPrefix, shill::kPrefixlenProperty},
    {::onc::ipconfig::kNameServers, shill::kNameServersProperty},
    {::onc::ipconfig::kSearchDomains, shill::kSearchDomainsProperty},
    {::onc::ipconfig::kIncludedRoutes, shill::kIncludedRoutesProperty},
    {::onc::ipconfig::kExcludedRoutes, shill::kExcludedRoutesProperty},
    {::onc::ipconfig::kMTU, shill::kMtuProperty},
    {nullptr}};

struct OncValueTranslationEntry {
  // These fields are not raw_ptr<>s because each layer of pointer only ever
  // points to statically-allocated data which is never freed, and thus can
  // never dangle.
  RAW_PTR_EXCLUSION const chromeos::onc::OncValueSignature* onc_signature;
  RAW_PTR_EXCLUSION const FieldTranslationEntry* field_translation_table;
};

const OncValueTranslationEntry onc_value_translation_table[] = {
    {&chromeos::onc::kEAPSignature, eap_fields},
    {&chromeos::onc::kIPsecSignature, ipsec_fields},
    {&chromeos::onc::kL2TPSignature, l2tp_fields},
    {&chromeos::onc::kXAUTHSignature, xauth_fields},
    {&chromeos::onc::kOpenVPNSignature, openvpn_fields},
    {&chromeos::onc::kWireGuardSignature, wireguard_fields},
    {&chromeos::onc::kWireGuardPeerSignature, wireguard_peer_fields},
    {&chromeos::onc::kARCVPNSignature, arc_vpn_fields},
    {&chromeos::onc::kVerifyX509Signature, verify_x509_fields},
    {&chromeos::onc::kVPNSignature, vpn_fields},
    {&chromeos::onc::kTetherSignature, tether_fields},
    {&chromeos::onc::kTetherWithStateSignature, tether_fields},
    {&chromeos::onc::kWiFiSignature, wifi_fields},
    {&chromeos::onc::kWiFiWithStateSignature, wifi_fields},
    {&chromeos::onc::kCellularApnSignature, cellular_apn_fields},
    {&chromeos::onc::kCellularFoundNetworkSignature,
     cellular_found_network_fields},
    {&chromeos::onc::kCellularPaymentPortalSignature,
     cellular_payment_portal_fields},
    {&chromeos::onc::kCellularProviderSignature, cellular_provider_fields},
    {&chromeos::onc::kSIMLockStatusSignature, sim_lock_status_fields},
    {&chromeos::onc::kCellularSignature, cellular_fields},
    {&chromeos::onc::kCellularWithStateSignature, cellular_fields},
    {&chromeos::onc::kNetworkWithStateSignature, network_fields},
    {&chromeos::onc::kNetworkConfigurationSignature, network_fields},
    {&chromeos::onc::kIPConfigSignature, ipconfig_fields},
    {&chromeos::onc::kSavedIPConfigSignature, static_or_saved_ipconfig_fields},
    {&chromeos::onc::kStaticIPConfigSignature, static_or_saved_ipconfig_fields},
    {nullptr}};

struct NestedShillDictionaryEntry {
  // These fields are not raw_ptr<>s because each layer of pointer only ever
  // points to statically-allocated data which is never freed, and thus can
  // never dangle.
  RAW_PTR_EXCLUSION const chromeos::onc::OncValueSignature* onc_signature;
  // nullptr terminated list of Shill property keys.
  RAW_PTR_EXCLUSION const char* const* shill_property_path;
};

const char* cellular_apn_path_entries[] = {shill::kCellularApnProperty,
                                           nullptr};

const char* static_ip_config_path_entries[] = {shill::kStaticIPConfigProperty,
                                               nullptr};

const NestedShillDictionaryEntry nested_shill_dictionaries[] = {
    {&chromeos::onc::kCellularApnSignature, cellular_apn_path_entries},
    {&chromeos::onc::kStaticIPConfigSignature, static_ip_config_path_entries},
    {nullptr}};

// Translation of the EAP.Inner field in case of EAP.Outer == PEAP
const StringTranslationEntry eap_peap_inner_table[] = {
    {::onc::eap::kGTC, shill::kEapPhase2AuthPEAPGTC},
    {::onc::eap::kMD5, shill::kEapPhase2AuthPEAPMD5},
    {::onc::eap::kMSCHAPv2, shill::kEapPhase2AuthPEAPMSCHAPV2},
    {nullptr}};

// Translation of the EAP.Inner field in case of EAP.Outer == TTLS
const StringTranslationEntry eap_ttls_inner_table[] = {
    {::onc::eap::kGTC, shill::kEapPhase2AuthTTLSGTC},
    {::onc::eap::kMD5, shill::kEapPhase2AuthTTLSMD5},
    {::onc::eap::kMSCHAP, shill::kEapPhase2AuthTTLSMSCHAP},
    {::onc::eap::kMSCHAPv2, shill::kEapPhase2AuthTTLSMSCHAPV2},
    {::onc::eap::kPAP, shill::kEapPhase2AuthTTLSPAP},
    {nullptr}};

}  // namespace

const StringTranslationEntry kNetworkTypeTable[] = {
    {::onc::network_type::kEthernet, shill::kTypeEthernet},
    // kTypeEthernetEap is set in onc_translator_onc_to_shill.cc.
    // {::onc::network_type::kEthernet, shill::kTypeEthernetEap},
    {::onc::network_type::kWiFi, shill::kTypeWifi},
    // wimax entries are ignored in onc_translator_onc_to_shill.cc.
    // {::onc::network_type::kWimax, shill::kTypeWimax},
    {::onc::network_type::kCellular, shill::kTypeCellular},
    {::onc::network_type::kVPN, shill::kTypeVPN},
    {::onc::network_type::kTether, kTypeTether},
    {nullptr}};

const StringTranslationEntry kVPNTypeTable[] = {
    {::onc::vpn::kIPsec, shill::kProviderIKEv2},
    {::onc::vpn::kTypeL2TP_IPsec, shill::kProviderL2tpIpsec},
    {::onc::vpn::kOpenVPN, shill::kProviderOpenVpn},
    {::onc::vpn::kWireGuard, shill::kProviderWireGuard},
    {::onc::vpn::kThirdPartyVpn, shill::kProviderThirdPartyVpn},
    {::onc::vpn::kArcVpn, shill::kProviderArcVpn},
    {nullptr}};

const StringTranslationEntry kWiFiSecurityTable[] = {
    {::onc::wifi::kSecurityNone, shill::kSecurityClassNone},
    {::onc::wifi::kWEP_PSK, shill::kSecurityClassWep},
    {::onc::wifi::kWPA_PSK, shill::kSecurityClassPsk},
    {::onc::wifi::kWPA_EAP, shill::kSecurityClass8021x},
    {::onc::wifi::kWEP_8021X, shill::kSecurityClassWep},
    {nullptr}};

const StringTranslationEntry kEAPOuterTable[] = {
    {::onc::eap::kPEAP, shill::kEapMethodPEAP},
    {::onc::eap::kEAP_TLS, shill::kEapMethodTLS},
    {::onc::eap::kEAP_TTLS, shill::kEapMethodTTLS},
    {::onc::eap::kLEAP, shill::kEapMethodLEAP},
    {::onc::eap::kMSCHAPv2, shill::kEapMethodMSCHAPV2},
    {nullptr}};

const StringTranslationEntry kActivationStateTable[] = {
    {::onc::cellular::kActivated, shill::kActivationStateActivated},
    {::onc::cellular::kActivating, shill::kActivationStateActivating},
    {::onc::cellular::kNotActivated, shill::kActivationStateNotActivated},
    {::onc::cellular::kPartiallyActivated,
     shill::kActivationStatePartiallyActivated},
    {nullptr}};

const StringTranslationEntry kNetworkTechnologyTable[] = {
    {::onc::cellular::kTechnologyCdma1Xrtt, shill::kNetworkTechnology1Xrtt},
    {::onc::cellular::kTechnologyGsm, shill::kNetworkTechnologyGsm},
    {::onc::cellular::kTechnologyEdge, shill::kNetworkTechnologyEdge},
    {::onc::cellular::kTechnologyEvdo, shill::kNetworkTechnologyEvdo},
    {::onc::cellular::kTechnologyGprs, shill::kNetworkTechnologyGprs},
    {::onc::cellular::kTechnologyHspa, shill::kNetworkTechnologyHspa},
    {::onc::cellular::kTechnologyHspaPlus, shill::kNetworkTechnologyHspaPlus},
    {::onc::cellular::kTechnologyLte, shill::kNetworkTechnologyLte},
    {::onc::cellular::kTechnologyLteAdvanced,
     shill::kNetworkTechnologyLteAdvanced},
    {::onc::cellular::kTechnologyUmts, shill::kNetworkTechnologyUmts},
    {::onc::cellular::kTechnology5gNr, shill::kNetworkTechnology5gNr},
    {nullptr}};

const StringTranslationEntry kRoamingStateTable[] = {
    {::onc::cellular::kRoamingHome, shill::kRoamingStateHome},
    {::onc::cellular::kRoamingRoaming, shill::kRoamingStateRoaming},
    {nullptr}};

const StringTranslationEntry kOpenVpnCompressionAlgorithmTable[] = {
    {::onc::openvpn_compression_algorithm::kFramingOnly,
     shill::kOpenVPNCompressFramingOnly},
    {::onc::openvpn_compression_algorithm::kLz4, shill::kOpenVPNCompressLz4},
    {::onc::openvpn_compression_algorithm::kLz4V2,
     shill::kOpenVPNCompressLz4V2},
    {::onc::openvpn_compression_algorithm::kLzo, shill::kOpenVPNCompressLzo},
    {nullptr}};

const StringTranslationEntry kIKEv2AuthenticationTypeTable[] = {
    {::onc::ipsec::kPSK, shill::kIKEv2AuthenticationTypePSK},
    {::onc::ipsec::kCert, shill::kIKEv2AuthenticationTypeCert},
    {::onc::ipsec::kEAP, shill::kIKEv2AuthenticationTypeEAP},
    {nullptr}};

const StringTranslationEntry kApnAuthenticationTranslationTable[] = {
    {::onc::cellular_apn::kAuthenticationAutomatic, ""},
    {::onc::cellular_apn::kAuthenticationPap, shill::kApnAuthenticationPap},
    {::onc::cellular_apn::kAuthenticationChap, shill::kApnAuthenticationChap},
    {nullptr}};

const StringTranslationEntry kApnIpTypeTranslationTable[] = {
    {::onc::cellular_apn::kIpTypeAutomatic, ""},
    {::onc::cellular_apn::kIpTypeIpv4, shill::kApnIpTypeV4},
    {::onc::cellular_apn::kIpTypeIpv6, shill::kApnIpTypeV6},
    {::onc::cellular_apn::kIpTypeIpv4Ipv6, shill::kApnIpTypeV4V6},
    {nullptr}};

const StringTranslationEntry kApnSourceTranslationTable[] = {
    {::onc::cellular_apn::kSourceModem, shill::kApnSourceModem},
    {::onc::cellular_apn::kSourceModb, shill::kApnSourceMoDb},
    {::onc::cellular_apn::kSourceAdmin, shill::kApnSourceAdmin},
    {::onc::cellular_apn::kSourceUi, shill::kApnSourceUi},
    {nullptr}};

const StringTranslationEntry kCheckCaptivePortalTranslationTable[] = {
    {::onc::check_captive_portal::kFalse, "false"},
    {::onc::check_captive_portal::kHTTPOnly, "http-only"},
    {::onc::check_captive_portal::kTrue, "true"},
    {nullptr}};

// This must contain only Shill Device properties and no Service properties.
// For Service properties see cellular_fields.
const FieldTranslationEntry kCellularDeviceTable[] = {
    // This field is converted during translation, see onc_translator_*.
    // { ::onc::cellular::kAPNList, shill::kCellularApnListProperty},
    {::onc::cellular::kESN, shill::kEsnProperty},
    {::onc::cellular::kFamily, shill::kTechnologyFamilyProperty},
    {::onc::cellular::kFirmwareRevision, shill::kFirmwareRevisionProperty},
    // This field is converted during translation, see onc_translator_*.
    // { ::onc::cellular::kFoundNetworks, shill::kFoundNetworksProperty},
    {::onc::cellular::kHardwareRevision, shill::kHardwareRevisionProperty},
    // This field is converted during translation, see onc_translator_*.
    // { ::onc::cellular::kHomeProvider, shill::kHomeProviderProperty},
    {::onc::cellular::kIMEI, shill::kImeiProperty},
    {::onc::cellular::kManufacturer, shill::kManufacturerProperty},
    {::onc::cellular::kMDN, shill::kMdnProperty},
    {::onc::cellular::kMEID, shill::kMeidProperty},
    {::onc::cellular::kMIN, shill::kMinProperty},
    {::onc::cellular::kModelID, shill::kModelIdProperty},
    {::onc::cellular::kScanning, shill::kScanningProperty},
    // This field is converted during translation, see onc_translator_*.
    // { ::onc::cellular::kSIMLockStatus, shill::kSIMLockStatusProperty},
    {::onc::cellular::kSIMPresent, shill::kSIMPresentProperty},
    {::onc::cellular::kSupportNetworkScan, shill::kSupportNetworkScanProperty},
    {nullptr}};

const FieldTranslationEntry kIPsecIKEv2Table[] = {
    {::onc::ipsec::kPSK, shill::kIKEv2PskProperty},
    {::onc::ipsec::kServerCAPEMs, shill::kIKEv2CaCertPemProperty},
    {::onc::ipsec::kLocalIdentity, shill::kIKEv2LocalIdentityProperty},
    {::onc::ipsec::kRemoteIdentity, shill::kIKEv2RemoteIdentityProperty},
    {nullptr}};

const FieldTranslationEntry* GetFieldTranslationTable(
    const chromeos::onc::OncValueSignature& onc_signature) {
  for (const OncValueTranslationEntry* it = onc_value_translation_table;
       it->onc_signature != nullptr; ++it) {
    if (it->onc_signature == &onc_signature) {
      return it->field_translation_table;
    }
  }
  return nullptr;
}

const StringTranslationEntry* GetEapInnerTranslationTableForShillOuter(
    std::string_view shill_eap_outer) {
  if (shill_eap_outer == shill::kEapMethodPEAP) {
    return eap_peap_inner_table;
  }
  if (shill_eap_outer == shill::kEapMethodTTLS) {
    return eap_ttls_inner_table;
  }
  LOG(ERROR) << "No translation table for '" << shill_eap_outer << "'";
  return nullptr;
}

const StringTranslationEntry* GetEapInnerTranslationTableForOncOuter(
    std::string_view onc_eap_outer) {
  if (onc_eap_outer == ::onc::eap::kPEAP) {
    return eap_peap_inner_table;
  }
  if (onc_eap_outer == ::onc::eap::kEAP_TTLS) {
    return eap_ttls_inner_table;
  }
  LOG(ERROR) << "No translation table for '" << onc_eap_outer << "'";
  return nullptr;
}

std::vector<std::string> GetPathToNestedShillDictionary(
    const chromeos::onc::OncValueSignature& onc_signature) {
  std::vector<std::string> shill_property_path;
  for (const NestedShillDictionaryEntry* it = nested_shill_dictionaries;
       it->onc_signature != nullptr; ++it) {
    if (it->onc_signature == &onc_signature) {
      for (const char* const* key = it->shill_property_path; *key != nullptr;
           ++key) {
        shill_property_path.push_back(std::string(*key));
      }
      break;
    }
  }
  return shill_property_path;
}

bool GetShillPropertyName(const std::string& onc_field_name,
                          const FieldTranslationEntry table[],
                          std::string* shill_property_name) {
  for (const FieldTranslationEntry* it = table; it->onc_field_name != nullptr;
       ++it) {
    if (it->onc_field_name != onc_field_name) {
      continue;
    }
    *shill_property_name = it->shill_property_name;
    return true;
  }
  return false;
}

bool TranslateStringToShill(const StringTranslationEntry table[],
                            const std::string& onc_value,
                            std::string* shill_value) {
  for (int i = 0; table[i].onc_value != nullptr; ++i) {
    if (onc_value != table[i].onc_value) {
      continue;
    }
    *shill_value = table[i].shill_value;
    return true;
  }
  LOG(ERROR) << "Value '" << onc_value << "' cannot be translated to Shill"
             << " table[0]: " << table[0].onc_value << " => "
             << table[0].shill_value;
  return false;
}

bool TranslateStringToONC(const StringTranslationEntry table[],
                          const std::string& shill_value,
                          std::string* onc_value) {
  for (int i = 0; table[i].shill_value != nullptr; ++i) {
    if (shill_value != table[i].shill_value) {
      continue;
    }
    *onc_value = table[i].onc_value;
    return true;
  }
  LOG(ERROR) << "Value '" << shill_value << "' cannot be translated to ONC"
             << " table[0]: " << table[0].shill_value << " => "
             << table[0].onc_value;
  return false;
}

}  // namespace ash::onc