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::sim;
28
toHidl(const aidl::IccIo & icc)29 V1_0::IccIo toHidl(const aidl::IccIo& icc) {
30 return {
31 .command = icc.command,
32 .fileId = icc.fileId,
33 .path = icc.path,
34 .p1 = icc.p1,
35 .p2 = icc.p2,
36 .p3 = icc.p3,
37 .data = icc.data,
38 .pin2 = icc.pin2,
39 .aid = icc.aid,
40 };
41 }
42
toHidl(const aidl::SimApdu & apdu)43 V1_0::SimApdu toHidl(const aidl::SimApdu& apdu) {
44 return {
45 .sessionId = apdu.sessionId,
46 .cla = apdu.cla,
47 .instruction = apdu.instruction,
48 .p1 = apdu.p1,
49 .p2 = apdu.p2,
50 .p3 = apdu.p3,
51 .data = apdu.data,
52 };
53 }
54
toAidl(const V1_0::Carrier & carrier)55 aidl::Carrier toAidl(const V1_0::Carrier& carrier) {
56 return {
57 .mcc = carrier.mcc,
58 .mnc = carrier.mnc,
59 .matchType = static_cast<int32_t>(carrier.matchType),
60 .matchData = carrier.matchData,
61 };
62 }
63
toHidl(const aidl::Carrier & carrier)64 V1_0::Carrier toHidl(const aidl::Carrier& carrier) {
65 return {
66 .mcc = carrier.mcc,
67 .mnc = carrier.mnc,
68 .matchType = static_cast<V1_0::CarrierMatchType>(carrier.matchType),
69 .matchData = carrier.matchData,
70 };
71 }
72
toAidl(const V1_0::CarrierRestrictions & cr)73 aidl::CarrierRestrictions toAidl(const V1_0::CarrierRestrictions& cr) {
74 return {
75 .allowedCarriers = toAidl(cr.allowedCarriers),
76 .excludedCarriers = toAidl(cr.excludedCarriers),
77 .allowedCarriersPrioritized = true,
78 };
79 }
80
toAidl(const V1_4::CarrierRestrictionsWithPriority & cr)81 aidl::CarrierRestrictions toAidl(const V1_4::CarrierRestrictionsWithPriority& cr) {
82 return {
83 .allowedCarriers = toAidl(cr.allowedCarriers),
84 .excludedCarriers = toAidl(cr.excludedCarriers),
85 .allowedCarriersPrioritized = cr.allowedCarriersPrioritized,
86 };
87 }
88
toHidl(const aidl::CarrierRestrictions & cr)89 V1_4::CarrierRestrictionsWithPriority toHidl(const aidl::CarrierRestrictions& cr) {
90 return {
91 .allowedCarriers = toHidl(cr.allowedCarriers),
92 .excludedCarriers = toHidl(cr.excludedCarriers),
93 .allowedCarriersPrioritized = cr.allowedCarriersPrioritized,
94 };
95 }
96
toHidl(const aidl::ImsiEncryptionInfo & info)97 V1_1::ImsiEncryptionInfo toHidl(const aidl::ImsiEncryptionInfo& info) {
98 return {
99 .mcc = info.mcc,
100 .mnc = info.mnc,
101 .carrierKey = info.carrierKey,
102 .keyIdentifier = info.keyIdentifier,
103 .expirationTime = info.expirationTime,
104 };
105 }
106
toHidl_1_6(const aidl::ImsiEncryptionInfo & info)107 V1_6::ImsiEncryptionInfo toHidl_1_6(const aidl::ImsiEncryptionInfo& info) {
108 return {
109 .base = toHidl(info),
110 .keyType = static_cast<V1_6::PublicKeyType>(info.keyType),
111 };
112 }
113
toHidl(const aidl::SelectUiccSub & sub)114 V1_0::SelectUiccSub toHidl(const aidl::SelectUiccSub& sub) {
115 return {
116 .slot = sub.slot,
117 .appIndex = sub.appIndex,
118 .subType = {},
119 .actStatus = {},
120 };
121 }
122
toAidl(const V1_6::PhonebookRecordInfo & info)123 aidl::PhonebookRecordInfo toAidl(const V1_6::PhonebookRecordInfo& info) {
124 return {
125 .recordId = static_cast<int32_t>(info.recordId),
126 .name = info.name,
127 .number = info.number,
128 .emails = toAidl(info.emails),
129 .additionalNumbers = toAidl(info.additionalNumbers),
130 };
131 }
132
toHidl(const aidl::PhonebookRecordInfo & info)133 V1_6::PhonebookRecordInfo toHidl(const aidl::PhonebookRecordInfo& info) {
134 return {
135 .recordId = static_cast<uint32_t>(info.recordId),
136 .name = info.name,
137 .number = info.number,
138 .emails = toHidl(info.emails),
139 .additionalNumbers = toHidl(info.additionalNumbers),
140 };
141 }
142
toAidl(const V1_0::SimRefreshResult & res)143 aidl::SimRefreshResult toAidl(const V1_0::SimRefreshResult& res) {
144 return {
145 .type = static_cast<int32_t>(res.type),
146 .efId = res.efId,
147 .aid = res.aid,
148 };
149 }
150
toAidl(const V1_0::CardStatus & status)151 aidl::CardStatus toAidl(const V1_0::CardStatus& status) {
152 return toAidl(V1_2::CardStatus{status, 0, "", ""});
153 }
154
toAidl(const V1_2::CardStatus & status)155 aidl::CardStatus toAidl(const V1_2::CardStatus& status) {
156 return toAidl(V1_4::CardStatus{status, ""});
157 }
158
toAidl(const V1_4::CardStatus & status)159 aidl::CardStatus toAidl(const V1_4::CardStatus& status) {
160 auto aidlStatus = toAidl(V1_5::CardStatus{status, {}});
161 aidlStatus.applications = toAidl(status.base.base.applications);
162 return aidlStatus;
163 }
164
toAidl(const V1_5::CardStatus & status)165 aidl::CardStatus toAidl(const V1_5::CardStatus& status) {
166 return {
167 .cardState = static_cast<int32_t>(status.base.base.base.cardState),
168 .universalPinState = aidl::PinState(status.base.base.base.universalPinState),
169 .gsmUmtsSubscriptionAppIndex = status.base.base.base.gsmUmtsSubscriptionAppIndex,
170 .cdmaSubscriptionAppIndex = status.base.base.base.cdmaSubscriptionAppIndex,
171 .imsSubscriptionAppIndex = status.base.base.base.imsSubscriptionAppIndex,
172 .applications = toAidl(status.applications),
173 .atr = status.base.base.atr,
174 .iccid = status.base.base.iccid,
175 .eid = status.base.eid,
176 .slotMap = {static_cast<int32_t>(status.base.base.physicalSlotId), 0},
177 };
178 }
179
toAidl(const V1_0::AppStatus & status)180 aidl::AppStatus toAidl(const V1_0::AppStatus& status) {
181 return toAidl({status, V1_5::PersoSubstate(status.persoSubstate)});
182 }
183
toAidl(const V1_5::AppStatus & status)184 aidl::AppStatus toAidl(const V1_5::AppStatus& status) {
185 return {
186 .appType = static_cast<int32_t>(status.base.appType),
187 .appState = static_cast<int32_t>(status.base.appState),
188 .persoSubstate = aidl::PersoSubstate(status.persoSubstate),
189 .aidPtr = status.base.aidPtr,
190 .appLabelPtr = status.base.appLabelPtr,
191 .pin1Replaced = (status.base.pin1Replaced != 0),
192 .pin1 = aidl::PinState(status.base.pin1),
193 .pin2 = aidl::PinState(status.base.pin2),
194 };
195 }
196
toAidl(const V1_6::PhonebookCapacity & c)197 aidl::PhonebookCapacity toAidl(const V1_6::PhonebookCapacity& c) {
198 return {
199 .maxAdnRecords = c.maxAdnRecords,
200 .usedAdnRecords = c.usedAdnRecords,
201 .maxEmailRecords = c.maxEmailRecords,
202 .usedEmailRecords = c.usedEmailRecords,
203 .maxAdditionalNumberRecords = c.maxAdditionalNumberRecords,
204 .usedAdditionalNumberRecords = c.usedAdditionalNumberRecords,
205 .maxNameLen = c.maxNameLen,
206 .maxNumberLen = c.maxNumberLen,
207 .maxEmailLen = c.maxEmailLen,
208 .maxAdditionalNumberLen = c.maxAdditionalNumberLen,
209 };
210 }
211
toAidl(const V1_0::IccIoResult & iir)212 aidl::IccIoResult toAidl(const V1_0::IccIoResult& iir) {
213 return {
214 .sw1 = iir.sw1,
215 .sw2 = iir.sw2,
216 .simResponse = iir.simResponse,
217 };
218 }
219
220 } // namespace android::hardware::radio::compat
221