1 /*
2  * Copyright (C) 2021 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "structs.h"
18 
19 #include "commonStructs.h"
20 
21 #include "collections.h"
22 
23 #include <android-base/logging.h>
24 
25 namespace android::hardware::radio::compat {
26 
27 namespace aidl = ::aidl::android::hardware::radio::network;
28 using ::aidl::android::hardware::radio::AccessNetwork;
29 using ::aidl::android::hardware::radio::RadioTechnology;
30 
toAidl(V1_0::RadioBandMode mode)31 aidl::RadioBandMode toAidl(V1_0::RadioBandMode mode) {
32     return aidl::RadioBandMode(mode);
33 }
34 
toAidl(V1_1::GeranBands band)35 aidl::GeranBands toAidl(V1_1::GeranBands band) {
36     return aidl::GeranBands(band);
37 }
38 
toHidl(aidl::GeranBands band)39 V1_1::GeranBands toHidl(aidl::GeranBands band) {
40     return V1_1::GeranBands(band);
41 }
42 
toAidl(V1_5::UtranBands band)43 aidl::UtranBands toAidl(V1_5::UtranBands band) {
44     return aidl::UtranBands(band);
45 }
46 
toHidl(aidl::UtranBands band)47 V1_5::UtranBands toHidl(aidl::UtranBands band) {
48     return V1_5::UtranBands(band);
49 }
50 
toAidl(V1_5::EutranBands band)51 aidl::EutranBands toAidl(V1_5::EutranBands band) {
52     return aidl::EutranBands(band);
53 }
54 
toHidl(aidl::EutranBands band)55 V1_5::EutranBands toHidl(aidl::EutranBands band) {
56     return V1_5::EutranBands(band);
57 }
58 
toAidl(V1_5::NgranBands band)59 aidl::NgranBands toAidl(V1_5::NgranBands band) {
60     return aidl::NgranBands(band);
61 }
62 
toHidl(aidl::NgranBands band)63 V1_5::NgranBands toHidl(aidl::NgranBands band) {
64     return V1_5::NgranBands(band);
65 }
66 
toHidl(const aidl::SignalThresholdInfo & info)67 V1_5::SignalThresholdInfo toHidl(const aidl::SignalThresholdInfo& info) {
68     return {
69             .signalMeasurement = static_cast<V1_5::SignalMeasurementType>(info.signalMeasurement),
70             .hysteresisMs = info.hysteresisMs,
71             .hysteresisDb = info.hysteresisDb,
72             .thresholds = info.thresholds,
73             .isEnabled = info.isEnabled,
74     };
75 }
76 
toAidl(const V1_5::RadioAccessSpecifier::Bands & bands)77 static aidl::RadioAccessSpecifierBands toAidl(const V1_5::RadioAccessSpecifier::Bands& bands) {
78     using Discr = V1_5::RadioAccessSpecifier::Bands::hidl_discriminator;
79     const auto discr = bands.getDiscriminator();
80 
81     if (discr == Discr::geranBands) return toAidl(bands.geranBands());
82     if (discr == Discr::utranBands) return toAidl(bands.utranBands());
83     if (discr == Discr::eutranBands) return toAidl(bands.eutranBands());
84     if (discr == Discr::ngranBands) return toAidl(bands.ngranBands());
85 
86     return {};
87 }
88 
toHidl(const aidl::RadioAccessSpecifierBands & bands)89 static V1_5::RadioAccessSpecifier::Bands toHidl(const aidl::RadioAccessSpecifierBands& bands) {
90     V1_5::RadioAccessSpecifier::Bands hidl;
91     using Tag = aidl::RadioAccessSpecifierBands::Tag;
92 
93     if (bands.getTag() == Tag::geranBands) hidl.geranBands(toHidl(bands.get<Tag::geranBands>()));
94     if (bands.getTag() == Tag::utranBands) hidl.utranBands(toHidl(bands.get<Tag::utranBands>()));
95     if (bands.getTag() == Tag::eutranBands) hidl.eutranBands(toHidl(bands.get<Tag::eutranBands>()));
96     if (bands.getTag() == Tag::ngranBands) hidl.ngranBands(toHidl(bands.get<Tag::ngranBands>()));
97 
98     return hidl;
99 }
100 
fromRadioAccessNetwork(V1_5::RadioAccessNetworks ran)101 AccessNetwork fromRadioAccessNetwork(V1_5::RadioAccessNetworks ran) {
102     switch (ran) {
103         case V1_5::RadioAccessNetworks::UNKNOWN:
104             return AccessNetwork::UNKNOWN;
105         case V1_5::RadioAccessNetworks::GERAN:
106             return AccessNetwork::GERAN;
107         case V1_5::RadioAccessNetworks::UTRAN:
108             return AccessNetwork::UTRAN;
109         case V1_5::RadioAccessNetworks::EUTRAN:
110             return AccessNetwork::EUTRAN;
111         case V1_5::RadioAccessNetworks::CDMA2000:
112             return AccessNetwork::CDMA2000;
113         case V1_5::RadioAccessNetworks::NGRAN:
114             return AccessNetwork::NGRAN;
115         default:
116             return AccessNetwork::UNKNOWN;
117     }
118 }
119 
toAidl(const V1_5::RadioAccessSpecifier & spec)120 aidl::RadioAccessSpecifier toAidl(const V1_5::RadioAccessSpecifier& spec) {
121     return {
122             .accessNetwork = fromRadioAccessNetwork(spec.radioAccessNetwork),
123             .bands = toAidl(spec.bands),
124             .channels = spec.channels,
125     };
126 }
127 
toRadioAccessNetworks(AccessNetwork val)128 V1_5::RadioAccessNetworks toRadioAccessNetworks(AccessNetwork val) {
129     switch (val) {
130         case AccessNetwork::UNKNOWN:
131             return V1_5::RadioAccessNetworks::UNKNOWN;
132         case AccessNetwork::GERAN:
133             return V1_5::RadioAccessNetworks::GERAN;
134         case AccessNetwork::UTRAN:
135             return V1_5::RadioAccessNetworks::UTRAN;
136         case AccessNetwork::EUTRAN:
137             return V1_5::RadioAccessNetworks::EUTRAN;
138         case AccessNetwork::CDMA2000:
139             return V1_5::RadioAccessNetworks::CDMA2000;
140         case AccessNetwork::NGRAN:
141             return V1_5::RadioAccessNetworks::NGRAN;
142         case AccessNetwork::IWLAN:
143         default:
144             return V1_5::RadioAccessNetworks::UNKNOWN;
145     }
146 }
147 
toHidl(const aidl::RadioAccessSpecifier & spec)148 V1_5::RadioAccessSpecifier toHidl(const aidl::RadioAccessSpecifier& spec) {
149     return {
150             .radioAccessNetwork = toRadioAccessNetworks(spec.accessNetwork),
151             .bands = toHidl(spec.bands),
152             .channels = spec.channels,
153     };
154 }
155 
toHidl(const aidl::NetworkScanRequest & req)156 V1_5::NetworkScanRequest toHidl(const aidl::NetworkScanRequest& req) {
157     return {
158             .type = static_cast<V1_1::ScanType>(req.type),
159             .interval = req.interval,
160             .specifiers = toHidl(req.specifiers),
161             .maxSearchTime = req.maxSearchTime,
162             .incrementalResults = req.incrementalResults,
163             .incrementalResultsPeriodicity = req.incrementalResultsPeriodicity,
164             .mccMncs = toHidl(req.mccMncs),
165     };
166 }
167 
toAidl(const V1_2::CellIdentityOperatorNames & names)168 static aidl::OperatorInfo toAidl(const V1_2::CellIdentityOperatorNames& names) {
169     return {
170             .alphaLong = names.alphaLong,
171             .alphaShort = names.alphaShort,
172             .operatorNumeric = "",
173             .status = aidl::OperatorInfo::STATUS_UNKNOWN,
174     };
175 }
176 
toAidl(const V1_5::CellIdentityGsm & ci)177 static aidl::CellIdentityGsm toAidl(const V1_5::CellIdentityGsm& ci) {
178     return {
179             .mcc = ci.base.base.mcc,
180             .mnc = ci.base.base.mnc,
181             .lac = ci.base.base.lac,
182             .cid = ci.base.base.cid,
183             .arfcn = ci.base.base.arfcn,
184             .bsic = static_cast<int8_t>(ci.base.base.bsic),
185             .operatorNames = toAidl(ci.base.operatorNames),
186             .additionalPlmns = toAidl(ci.additionalPlmns),
187     };
188 }
189 
toAidl(const V1_5::ClosedSubscriberGroupInfo & info)190 aidl::ClosedSubscriberGroupInfo toAidl(const V1_5::ClosedSubscriberGroupInfo& info) {
191     return {
192             .csgIndication = info.csgIndication,
193             .homeNodebName = info.homeNodebName,
194             .csgIdentity = info.csgIdentity,
195     };
196 }
197 
toAidl(const V1_5::OptionalCsgInfo & opt)198 static std::optional<aidl::ClosedSubscriberGroupInfo> toAidl(const V1_5::OptionalCsgInfo& opt) {
199     using descr = V1_5::OptionalCsgInfo::hidl_discriminator;
200     if (opt.getDiscriminator() == descr::noinit) return std::nullopt;
201     return toAidl(opt.csgInfo());
202 }
203 
toAidl(const V1_5::CellIdentityWcdma & ci)204 static aidl::CellIdentityWcdma toAidl(const V1_5::CellIdentityWcdma& ci) {
205     return {
206             .mcc = ci.base.base.mcc,
207             .mnc = ci.base.base.mnc,
208             .lac = ci.base.base.lac,
209             .cid = ci.base.base.cid,
210             .psc = ci.base.base.psc,
211             .uarfcn = ci.base.base.uarfcn,
212             .operatorNames = toAidl(ci.base.operatorNames),
213             .additionalPlmns = toAidl(ci.additionalPlmns),
214             .csgInfo = toAidl(ci.optionalCsgInfo),
215     };
216 }
217 
toAidl(const V1_5::CellIdentityTdscdma & ci)218 static aidl::CellIdentityTdscdma toAidl(const V1_5::CellIdentityTdscdma& ci) {
219     return {
220             .mcc = ci.base.base.mcc,
221             .mnc = ci.base.base.mnc,
222             .lac = ci.base.base.lac,
223             .cid = ci.base.base.cid,
224             .cpid = ci.base.base.cpid,
225             .uarfcn = ci.base.uarfcn,
226             .operatorNames = toAidl(ci.base.operatorNames),
227             .additionalPlmns = toAidl(ci.additionalPlmns),
228             .csgInfo = toAidl(ci.optionalCsgInfo),
229     };
230 }
231 
toAidl(const V1_2::CellIdentityCdma & ci)232 static aidl::CellIdentityCdma toAidl(const V1_2::CellIdentityCdma& ci) {
233     return {
234             .networkId = ci.base.networkId,
235             .systemId = ci.base.systemId,
236             .baseStationId = ci.base.baseStationId,
237             .longitude = ci.base.longitude,
238             .latitude = ci.base.latitude,
239             .operatorNames = toAidl(ci.operatorNames),
240     };
241 }
242 
toAidl(const V1_5::CellIdentityLte & ci)243 static aidl::CellIdentityLte toAidl(const V1_5::CellIdentityLte& ci) {
244     return {
245             .mcc = ci.base.base.mcc,
246             .mnc = ci.base.base.mnc,
247             .ci = ci.base.base.ci,
248             .pci = ci.base.base.pci,
249             .tac = ci.base.base.tac,
250             .earfcn = ci.base.base.earfcn,
251             .operatorNames = toAidl(ci.base.operatorNames),
252             .bandwidth = ci.base.bandwidth,
253             .additionalPlmns = toAidl(ci.additionalPlmns),
254             .csgInfo = toAidl(ci.optionalCsgInfo),
255             .bands = toAidl(ci.bands),
256     };
257 }
258 
toAidl(const V1_5::CellIdentityNr & ci)259 static aidl::CellIdentityNr toAidl(const V1_5::CellIdentityNr& ci) {
260     return {
261             .mcc = ci.base.mcc,
262             .mnc = ci.base.mnc,
263             .nci = static_cast<int64_t>(ci.base.nci),
264             .pci = static_cast<int32_t>(ci.base.pci),
265             .tac = ci.base.tac,
266             .nrarfcn = ci.base.nrarfcn,
267             .operatorNames = toAidl(ci.base.operatorNames),
268             .additionalPlmns = toAidl(ci.additionalPlmns),
269             .bands = toAidl(ci.bands),
270     };
271 }
272 
toAidl(const V1_5::CellIdentity & ci)273 aidl::CellIdentity toAidl(const V1_5::CellIdentity& ci) {
274     using Discr = V1_5::CellIdentity::hidl_discriminator;
275     const auto discr = ci.getDiscriminator();
276 
277     if (discr == Discr::gsm) return toAidl(ci.gsm());
278     if (discr == Discr::wcdma) return toAidl(ci.wcdma());
279     if (discr == Discr::tdscdma) return toAidl(ci.tdscdma());
280     if (discr == Discr::cdma) return toAidl(ci.cdma());
281     if (discr == Discr::lte) return toAidl(ci.lte());
282     if (discr == Discr::nr) return toAidl(ci.nr());
283 
284     return {};
285 }
286 
287 static std::optional<aidl::BarringTypeSpecificInfo>  //
toAidl(const V1_5::BarringInfo::BarringTypeSpecificInfo & opt)288 toAidl(const V1_5::BarringInfo::BarringTypeSpecificInfo& opt) {
289     using discr = V1_5::BarringInfo::BarringTypeSpecificInfo::hidl_discriminator;
290     if (opt.getDiscriminator() == discr::noinit) return std::nullopt;
291 
292     const auto& info = opt.conditional();
293     return aidl::BarringTypeSpecificInfo{
294             .factor = info.factor,
295             .timeSeconds = info.timeSeconds,
296             .isBarred = info.isBarred,
297     };
298 }
299 
toAidl(const V1_5::BarringInfo & info)300 aidl::BarringInfo toAidl(const V1_5::BarringInfo& info) {
301     return {
302             .serviceType = static_cast<int32_t>(info.serviceType),
303             .barringType = static_cast<int32_t>(info.barringType),
304             .barringTypeSpecificInfo = toAidl(info.barringTypeSpecificInfo),
305     };
306 }
307 
toAidl(const V1_0::GsmSignalStrength & sig)308 static aidl::GsmSignalStrength toAidl(const V1_0::GsmSignalStrength& sig) {
309     return {
310             .signalStrength = static_cast<int32_t>(sig.signalStrength),
311             .bitErrorRate = static_cast<int32_t>(sig.bitErrorRate),
312             .timingAdvance = sig.timingAdvance,
313     };
314 }
315 
toAidl(const V1_5::CellInfoGsm & info)316 static aidl::CellInfoGsm toAidl(const V1_5::CellInfoGsm& info) {
317     return {
318             .cellIdentityGsm = toAidl(info.cellIdentityGsm),
319             .signalStrengthGsm = toAidl(info.signalStrengthGsm),
320     };
321 }
322 
toAidl(const V1_2::WcdmaSignalStrength & sig)323 static aidl::WcdmaSignalStrength toAidl(const V1_2::WcdmaSignalStrength& sig) {
324     return {
325             .signalStrength = sig.base.signalStrength,
326             .bitErrorRate = sig.base.bitErrorRate,
327             .rscp = static_cast<int32_t>(sig.rscp),
328             .ecno = static_cast<int32_t>(sig.ecno),
329     };
330 }
331 
toAidl(const V1_5::CellInfoWcdma & info)332 static aidl::CellInfoWcdma toAidl(const V1_5::CellInfoWcdma& info) {
333     return {
334             .cellIdentityWcdma = toAidl(info.cellIdentityWcdma),
335             .signalStrengthWcdma = toAidl(info.signalStrengthWcdma),
336     };
337 }
338 
toAidl(const V1_2::TdscdmaSignalStrength & sig)339 static aidl::TdscdmaSignalStrength toAidl(const V1_2::TdscdmaSignalStrength& sig) {
340     return {
341             .signalStrength = static_cast<int32_t>(sig.signalStrength),
342             .bitErrorRate = static_cast<int32_t>(sig.bitErrorRate),
343             .rscp = static_cast<int32_t>(sig.rscp),
344     };
345 }
346 
toAidl(const V1_5::CellInfoTdscdma & info)347 static aidl::CellInfoTdscdma toAidl(const V1_5::CellInfoTdscdma& info) {
348     return {
349             .cellIdentityTdscdma = toAidl(info.cellIdentityTdscdma),
350             .signalStrengthTdscdma = toAidl(info.signalStrengthTdscdma),
351     };
352 }
353 
toAidl(const V1_6::LteSignalStrength & sig)354 static aidl::LteSignalStrength toAidl(const V1_6::LteSignalStrength& sig) {
355     return {
356             .signalStrength = static_cast<int32_t>(sig.base.signalStrength),
357             .rsrp = static_cast<int32_t>(sig.base.rsrp),
358             .rsrq = static_cast<int32_t>(sig.base.rsrq),
359             .rssnr = sig.base.rssnr,
360             .cqi = static_cast<int32_t>(sig.base.cqi),
361             .timingAdvance = static_cast<int32_t>(sig.base.timingAdvance),
362             .cqiTableIndex = static_cast<int32_t>(sig.cqiTableIndex),
363     };
364 }
365 
toAidl(const V1_0::LteSignalStrength & sig)366 static aidl::LteSignalStrength toAidl(const V1_0::LteSignalStrength& sig) {
367     return toAidl({sig, 0});
368 }
369 
toAidl(const V1_5::CellInfoLte & info)370 static aidl::CellInfoLte toAidl(const V1_5::CellInfoLte& info) {
371     return {
372             .cellIdentityLte = toAidl(info.cellIdentityLte),
373             .signalStrengthLte = toAidl(info.signalStrengthLte),
374     };
375 }
376 
toAidl(const V1_6::CellInfoLte & info)377 static aidl::CellInfoLte toAidl(const V1_6::CellInfoLte& info) {
378     return {
379             .cellIdentityLte = toAidl(info.cellIdentityLte),
380             .signalStrengthLte = toAidl(info.signalStrengthLte),
381     };
382 }
383 
toAidl(const V1_6::NrSignalStrength & sig)384 static aidl::NrSignalStrength toAidl(const V1_6::NrSignalStrength& sig) {
385     return {
386             .ssRsrp = sig.base.ssRsrp,
387             .ssRsrq = sig.base.ssRsrq,
388             .ssSinr = sig.base.ssSinr,
389             .csiRsrp = sig.base.csiRsrp,
390             .csiRsrq = sig.base.csiRsrq,
391             .csiSinr = sig.base.csiSinr,
392             .csiCqiTableIndex = static_cast<int32_t>(sig.csiCqiTableIndex),
393             .csiCqiReport = sig.csiCqiReport,
394     };
395 }
396 
toAidl(const V1_4::NrSignalStrength & sig)397 static aidl::NrSignalStrength toAidl(const V1_4::NrSignalStrength& sig) {
398     return toAidl({sig, 0, 0});
399 }
400 
toAidl(const V1_5::CellInfoNr & info)401 static aidl::CellInfoNr toAidl(const V1_5::CellInfoNr& info) {
402     return {
403             .cellIdentityNr = toAidl(info.cellIdentityNr),
404             .signalStrengthNr = toAidl(info.signalStrengthNr),
405     };
406 }
407 
toAidl(const V1_6::CellInfoNr & info)408 static aidl::CellInfoNr toAidl(const V1_6::CellInfoNr& info) {
409     return {
410             .cellIdentityNr = toAidl(info.cellIdentityNr),
411             .signalStrengthNr = toAidl(info.signalStrengthNr),
412     };
413 }
414 
toAidl(const V1_0::CdmaSignalStrength & sig)415 static aidl::CdmaSignalStrength toAidl(const V1_0::CdmaSignalStrength& sig) {
416     return {
417             .dbm = static_cast<int32_t>(sig.dbm),
418             .ecio = static_cast<int32_t>(sig.ecio),
419     };
420 }
421 
toAidl(const V1_0::EvdoSignalStrength & sig)422 static aidl::EvdoSignalStrength toAidl(const V1_0::EvdoSignalStrength& sig) {
423     return {
424             .dbm = static_cast<int32_t>(sig.dbm),
425             .ecio = static_cast<int32_t>(sig.ecio),
426             .signalNoiseRatio = static_cast<int32_t>(sig.signalNoiseRatio),
427     };
428 }
429 
toAidl(const V1_2::CellInfoCdma & info)430 static aidl::CellInfoCdma toAidl(const V1_2::CellInfoCdma& info) {
431     return {
432             .cellIdentityCdma = toAidl(info.cellIdentityCdma),
433             .signalStrengthCdma = toAidl(info.signalStrengthCdma),
434             .signalStrengthEvdo = toAidl(info.signalStrengthEvdo),
435     };
436 }
437 
toAidl(const V1_5::CellInfo::CellInfoRatSpecificInfo & ci)438 static aidl::CellInfoRatSpecificInfo toAidl(const V1_5::CellInfo::CellInfoRatSpecificInfo& ci) {
439     using Discr = V1_5::CellInfo::CellInfoRatSpecificInfo::hidl_discriminator;
440     const auto discr = ci.getDiscriminator();
441 
442     if (discr == Discr::gsm) return toAidl(ci.gsm());
443     if (discr == Discr::wcdma) return toAidl(ci.wcdma());
444     if (discr == Discr::tdscdma) return toAidl(ci.tdscdma());
445     if (discr == Discr::lte) return toAidl(ci.lte());
446     if (discr == Discr::nr) return toAidl(ci.nr());
447     if (discr == Discr::cdma) return toAidl(ci.cdma());
448 
449     return {};
450 }
451 
toAidl(const V1_6::CellInfo::CellInfoRatSpecificInfo & ci)452 static aidl::CellInfoRatSpecificInfo toAidl(const V1_6::CellInfo::CellInfoRatSpecificInfo& ci) {
453     using Discr = V1_6::CellInfo::CellInfoRatSpecificInfo::hidl_discriminator;
454     const auto discr = ci.getDiscriminator();
455 
456     if (discr == Discr::gsm) return toAidl(ci.gsm());
457     if (discr == Discr::wcdma) return toAidl(ci.wcdma());
458     if (discr == Discr::tdscdma) return toAidl(ci.tdscdma());
459     if (discr == Discr::lte) return toAidl(ci.lte());
460     if (discr == Discr::nr) return toAidl(ci.nr());
461     if (discr == Discr::cdma) return toAidl(ci.cdma());
462 
463     return {};
464 }
465 
toAidl(const V1_5::CellInfo & info)466 aidl::CellInfo toAidl(const V1_5::CellInfo& info) {
467     return {
468             .registered = info.registered,
469             // ignored: timeStampType and timeStamp
470             .connectionStatus = aidl::CellConnectionStatus(info.connectionStatus),
471             .ratSpecificInfo = toAidl(info.ratSpecificInfo),
472     };
473 }
474 
toAidl(const V1_6::CellInfo & info)475 aidl::CellInfo toAidl(const V1_6::CellInfo& info) {
476     return {
477             .registered = info.registered,
478             .connectionStatus = aidl::CellConnectionStatus(info.connectionStatus),
479             .ratSpecificInfo = toAidl(info.ratSpecificInfo),
480     };
481 }
482 
toAidl(const V1_2::LinkCapacityEstimate & e)483 aidl::LinkCapacityEstimate toAidl(const V1_2::LinkCapacityEstimate& e) {
484     return {
485             .downlinkCapacityKbps = static_cast<int32_t>(e.downlinkCapacityKbps),
486             .uplinkCapacityKbps = static_cast<int32_t>(e.uplinkCapacityKbps),
487     };
488 }
489 
toAidl(const V1_6::LinkCapacityEstimate & e)490 aidl::LinkCapacityEstimate toAidl(const V1_6::LinkCapacityEstimate& e) {
491     return {
492             .downlinkCapacityKbps = static_cast<int32_t>(e.downlinkCapacityKbps),
493             .uplinkCapacityKbps = static_cast<int32_t>(e.uplinkCapacityKbps),
494             .secondaryDownlinkCapacityKbps = static_cast<int32_t>(e.secondaryDownlinkCapacityKbps),
495             .secondaryUplinkCapacityKbps = static_cast<int32_t>(e.secondaryUplinkCapacityKbps),
496     };
497 }
498 
toAidl(const V1_6::PhysicalChannelConfig::Band & band)499 static aidl::PhysicalChannelConfigBand toAidl(const V1_6::PhysicalChannelConfig::Band& band) {
500     using Discr = V1_6::PhysicalChannelConfig::Band::hidl_discriminator;
501     const auto discr = band.getDiscriminator();
502 
503     if (discr == Discr::geranBand) return aidl::GeranBands(band.geranBand());
504     if (discr == Discr::utranBand) return aidl::UtranBands(band.utranBand());
505     if (discr == Discr::eutranBand) return aidl::EutranBands(band.eutranBand());
506     if (discr == Discr::ngranBand) return aidl::NgranBands(band.ngranBand());
507 
508     return {};
509 }
510 
toAidl(const V1_4::PhysicalChannelConfig & cfg)511 aidl::PhysicalChannelConfig toAidl(const V1_4::PhysicalChannelConfig& cfg) {
512     int32_t downlinkChannelNumber = 0;
513     // ignored rfInfo.range
514     using Discr = V1_4::RadioFrequencyInfo::hidl_discriminator;
515     if (cfg.rfInfo.getDiscriminator() == Discr::channelNumber) {
516         downlinkChannelNumber = cfg.rfInfo.channelNumber();
517     }
518 
519     return {
520             .status = aidl::CellConnectionStatus(cfg.base.status),
521             .rat = RadioTechnology(cfg.rat),
522             .downlinkChannelNumber = downlinkChannelNumber,
523             .cellBandwidthDownlinkKhz = cfg.base.cellBandwidthDownlink,
524             .contextIds = cfg.contextIds,
525             .physicalCellId = static_cast<int32_t>(cfg.physicalCellId),
526     };
527 }
528 
toAidl(const V1_6::PhysicalChannelConfig & cfg)529 aidl::PhysicalChannelConfig toAidl(const V1_6::PhysicalChannelConfig& cfg) {
530     return {
531             .status = aidl::CellConnectionStatus(cfg.status),
532             .rat = RadioTechnology(cfg.rat),
533             .downlinkChannelNumber = cfg.downlinkChannelNumber,
534             .uplinkChannelNumber = cfg.uplinkChannelNumber,
535             .cellBandwidthDownlinkKhz = cfg.cellBandwidthDownlinkKhz,
536             .cellBandwidthUplinkKhz = cfg.cellBandwidthUplinkKhz,
537             .contextIds = cfg.contextIds,
538             .physicalCellId = static_cast<int32_t>(cfg.physicalCellId),
539             .band = toAidl(cfg.band),
540     };
541 }
542 
toAidl(const V1_4::SignalStrength & sig)543 aidl::SignalStrength toAidl(const V1_4::SignalStrength& sig) {
544     return {
545             .gsm = toAidl(sig.gsm),
546             .cdma = toAidl(sig.cdma),
547             .evdo = toAidl(sig.evdo),
548             .lte = toAidl(sig.lte),
549             .tdscdma = toAidl(sig.tdscdma),
550             .wcdma = toAidl(sig.wcdma),
551             .nr = toAidl(sig.nr),
552     };
553 }
554 
toAidl(const V1_6::SignalStrength & sig)555 aidl::SignalStrength toAidl(const V1_6::SignalStrength& sig) {
556     return {
557             .gsm = toAidl(sig.gsm),
558             .cdma = toAidl(sig.cdma),
559             .evdo = toAidl(sig.evdo),
560             .lte = toAidl(sig.lte),
561             .tdscdma = toAidl(sig.tdscdma),
562             .wcdma = toAidl(sig.wcdma),
563             .nr = toAidl(sig.nr),
564     };
565 }
566 
toAidl(const V1_5::NetworkScanResult & res)567 aidl::NetworkScanResult toAidl(const V1_5::NetworkScanResult& res) {
568     return {
569             .status = static_cast<int32_t>(res.status),
570             .error = toAidl(res.error),
571             .networkInfos = toAidl(res.networkInfos),
572     };
573 }
574 
toAidl(const V1_6::NetworkScanResult & res)575 aidl::NetworkScanResult toAidl(const V1_6::NetworkScanResult& res) {
576     return {
577             .status = static_cast<int32_t>(res.status),
578             .error = toAidl(res.error),
579             .networkInfos = toAidl(res.networkInfos),
580     };
581 }
582 
toAidl(const V1_0::SuppSvcNotification & svc)583 aidl::SuppSvcNotification toAidl(const V1_0::SuppSvcNotification& svc) {
584     return {
585             .isMT = svc.isMT,
586             .code = svc.code,
587             .index = svc.index,
588             .type = svc.type,
589             .number = svc.number,
590     };
591 }
592 
toAidl(const V1_0::OperatorInfo & info)593 aidl::OperatorInfo toAidl(const V1_0::OperatorInfo& info) {
594     return {
595             .alphaLong = info.alphaLong,
596             .alphaShort = info.alphaShort,
597             .operatorNumeric = info.operatorNumeric,
598             .status = static_cast<int32_t>(info.status),
599     };
600 }
601 
602 static aidl::Cdma2000RegistrationInfo  //
toAidl(const V1_5::RegStateResult::AccessTechnologySpecificInfo::Cdma2000RegistrationInfo & info)603 toAidl(const V1_5::RegStateResult::AccessTechnologySpecificInfo::Cdma2000RegistrationInfo& info) {
604     return {
605             .cssSupported = info.cssSupported,
606             .roamingIndicator = info.roamingIndicator,
607             .systemIsInPrl = static_cast<int32_t>(info.systemIsInPrl),
608             .defaultRoamingIndicator = info.defaultRoamingIndicator,
609     };
610 }
611 
toAidl(const V1_4::LteVopsInfo & info)612 static aidl::LteVopsInfo toAidl(const V1_4::LteVopsInfo& info) {
613     return {
614             .isVopsSupported = info.isVopsSupported,
615             .isEmcBearerSupported = info.isEmcBearerSupported,
616     };
617 }
618 
toAidl(const V1_4::NrIndicators & info)619 static aidl::NrIndicators toAidl(const V1_4::NrIndicators& info) {
620     return {
621             .isEndcAvailable = info.isEndcAvailable,
622             .isDcNrRestricted = info.isDcNrRestricted,
623             .isNrAvailable = info.isNrAvailable,
624     };
625 }
626 
627 static aidl::EutranRegistrationInfo  //
toAidl(const V1_5::RegStateResult::AccessTechnologySpecificInfo::EutranRegistrationInfo & info)628 toAidl(const V1_5::RegStateResult::AccessTechnologySpecificInfo::EutranRegistrationInfo& info) {
629     return {
630             .lteVopsInfo = toAidl(info.lteVopsInfo),
631             .nrIndicators = toAidl(info.nrIndicators),
632     };
633 }
634 
toAidl(const V1_6::NrVopsInfo & info)635 static aidl::NrVopsInfo toAidl(const V1_6::NrVopsInfo& info) {
636     return {
637             .vopsSupported = static_cast<int8_t>(info.vopsSupported),
638             .emcSupported = static_cast<int8_t>(info.emcSupported),
639             .emfSupported = static_cast<int8_t>(info.emfSupported),
640     };
641 }
642 
643 static aidl::AccessTechnologySpecificInfo  //
toAidl(const V1_5::RegStateResult::AccessTechnologySpecificInfo & info)644 toAidl(const V1_5::RegStateResult::AccessTechnologySpecificInfo& info) {
645     using Discr = V1_5::RegStateResult::AccessTechnologySpecificInfo::hidl_discriminator;
646     const auto discr = info.getDiscriminator();
647 
648     if (discr == Discr::cdmaInfo) return toAidl(info.cdmaInfo());
649     if (discr == Discr::eutranInfo) return toAidl(info.eutranInfo());
650 
651     return {};
652 }
653 
654 static aidl::AccessTechnologySpecificInfo  //
toAidl(const V1_6::RegStateResult::AccessTechnologySpecificInfo & info)655 toAidl(const V1_6::RegStateResult::AccessTechnologySpecificInfo& info) {
656     using Discr = V1_6::RegStateResult::AccessTechnologySpecificInfo::hidl_discriminator;
657     const auto discr = info.getDiscriminator();
658 
659     if (discr == Discr::cdmaInfo) return toAidl(info.cdmaInfo());
660     if (discr == Discr::eutranInfo) return toAidl(info.eutranInfo());
661     if (discr == Discr::ngranNrVopsInfo) return toAidl(info.ngranNrVopsInfo());
662     if (discr == Discr::geranDtmSupported) {
663         using T = aidl::AccessTechnologySpecificInfo;
664         return T::make<T::Tag::geranDtmSupported>(info.geranDtmSupported());
665     }
666 
667     return {};
668 }
669 
toAidl(const V1_5::RegStateResult & res)670 aidl::RegStateResult toAidl(const V1_5::RegStateResult& res) {
671     return {
672             .regState = aidl::RegState(res.regState),
673             .rat = RadioTechnology(res.rat),
674             .reasonForDenial = aidl::RegistrationFailCause(res.reasonForDenial),
675             .cellIdentity = toAidl(res.cellIdentity),
676             .registeredPlmn = res.registeredPlmn,
677             .accessTechnologySpecificInfo = toAidl(res.accessTechnologySpecificInfo),
678     };
679 }
680 
toAidl(const V1_6::RegStateResult & res)681 aidl::RegStateResult toAidl(const V1_6::RegStateResult& res) {
682     return {
683             .regState = aidl::RegState(res.regState),
684             .rat = RadioTechnology(res.rat),
685             .reasonForDenial = aidl::RegistrationFailCause(res.reasonForDenial),
686             .cellIdentity = toAidl(res.cellIdentity),
687             .registeredPlmn = res.registeredPlmn,
688             .accessTechnologySpecificInfo = toAidl(res.accessTechnologySpecificInfo),
689     };
690 }
691 
toAidl(const V1_0::LceDataInfo & info)692 aidl::LceDataInfo toAidl(const V1_0::LceDataInfo& info) {
693     return {
694             .lastHopCapacityKbps = static_cast<int32_t>(info.lastHopCapacityKbps),
695             .confidenceLevel = static_cast<int8_t>(info.confidenceLevel),
696             .lceSuspended = info.lceSuspended,
697     };
698 }
699 
700 }  // namespace android::hardware::radio::compat
701