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 <libradiocompat/RadioSim.h>
18
19 #include "commonStructs.h"
20 #include "debug.h"
21 #include "structs.h"
22
23 #include "collections.h"
24
25 #define RADIO_MODULE "Sim"
26
27 namespace android::hardware::radio::compat {
28
29 using ::ndk::ScopedAStatus;
30 namespace aidl = ::aidl::android::hardware::radio::sim;
31 constexpr auto ok = &ScopedAStatus::ok;
32
respond()33 std::shared_ptr<aidl::IRadioSimResponse> RadioSim::respond() {
34 return mCallbackManager->response().simCb();
35 }
36
areUiccApplicationsEnabled(int32_t serial)37 ScopedAStatus RadioSim::areUiccApplicationsEnabled(int32_t serial) {
38 LOG_CALL << serial;
39 mHal1_5->areUiccApplicationsEnabled(serial);
40 return ok();
41 }
42
changeIccPin2ForApp(int32_t serial,const std::string & oldPin2,const std::string & newPin2,const std::string & aid)43 ScopedAStatus RadioSim::changeIccPin2ForApp(int32_t serial, const std::string& oldPin2,
44 const std::string& newPin2, const std::string& aid) {
45 LOG_CALL << serial;
46 mHal1_5->changeIccPin2ForApp(serial, oldPin2, newPin2, aid);
47 return ok();
48 }
49
changeIccPinForApp(int32_t serial,const std::string & oldPin,const std::string & newPin,const std::string & aid)50 ScopedAStatus RadioSim::changeIccPinForApp(int32_t serial, const std::string& oldPin,
51 const std::string& newPin, const std::string& aid) {
52 LOG_CALL << serial;
53 mHal1_5->changeIccPinForApp(serial, oldPin, newPin, aid);
54 return ok();
55 }
56
enableUiccApplications(int32_t serial,bool enable)57 ScopedAStatus RadioSim::enableUiccApplications(int32_t serial, bool enable) {
58 LOG_CALL << serial;
59 mHal1_5->enableUiccApplications(serial, enable);
60 return ok();
61 }
62
getAllowedCarriers(int32_t serial)63 ScopedAStatus RadioSim::getAllowedCarriers(int32_t serial) {
64 LOG_CALL << serial;
65 mHal1_5->getAllowedCarriers_1_4(serial);
66 return ok();
67 }
68
getCdmaSubscription(int32_t serial)69 ScopedAStatus RadioSim::getCdmaSubscription(int32_t serial) {
70 LOG_CALL << serial;
71 mHal1_5->getCDMASubscription(serial);
72 return ok();
73 }
74
getCdmaSubscriptionSource(int32_t serial)75 ScopedAStatus RadioSim::getCdmaSubscriptionSource(int32_t serial) {
76 LOG_CALL << serial;
77 mHal1_5->getCdmaSubscriptionSource(serial);
78 return ok();
79 }
80
getFacilityLockForApp(int32_t serial,const std::string & facility,const std::string & password,int32_t serviceClass,const std::string & appId)81 ScopedAStatus RadioSim::getFacilityLockForApp( //
82 int32_t serial, const std::string& facility, const std::string& password,
83 int32_t serviceClass, const std::string& appId) {
84 LOG_CALL << serial;
85 mHal1_5->getFacilityLockForApp(serial, facility, password, serviceClass, appId);
86 return ok();
87 }
88
getIccCardStatus(int32_t serial)89 ScopedAStatus RadioSim::getIccCardStatus(int32_t serial) {
90 LOG_CALL << serial;
91 mHal1_5->getIccCardStatus(serial);
92 return ok();
93 }
94
getImsiForApp(int32_t serial,const std::string & aid)95 ScopedAStatus RadioSim::getImsiForApp(int32_t serial, const std::string& aid) {
96 LOG_CALL << serial;
97 mHal1_5->getImsiForApp(serial, aid);
98 return ok();
99 }
100
getSimPhonebookCapacity(int32_t serial)101 ScopedAStatus RadioSim::getSimPhonebookCapacity(int32_t serial) {
102 LOG_CALL << serial;
103 if (mHal1_6) {
104 mHal1_6->getSimPhonebookCapacity(serial);
105 } else {
106 respond()->getSimPhonebookCapacityResponse(notSupported(serial), {});
107 }
108 return ok();
109 }
110
getSimPhonebookRecords(int32_t serial)111 ScopedAStatus RadioSim::getSimPhonebookRecords(int32_t serial) {
112 LOG_CALL << serial;
113 if (mHal1_6) {
114 mHal1_6->getSimPhonebookRecords(serial);
115 } else {
116 respond()->getSimPhonebookRecordsResponse(notSupported(serial));
117 }
118 return ok();
119 }
120
iccCloseLogicalChannel(int32_t serial,int32_t channelId)121 ScopedAStatus RadioSim::iccCloseLogicalChannel(int32_t serial, int32_t channelId) {
122 LOG_CALL << serial;
123 mHal1_5->iccCloseLogicalChannel(serial, channelId);
124 return ok();
125 }
126
iccCloseLogicalChannelWithSessionInfo(int32_t serial,const aidl::SessionInfo &)127 ScopedAStatus RadioSim::iccCloseLogicalChannelWithSessionInfo(int32_t serial,
128 const aidl::SessionInfo& /*SessionInfo*/) {
129 LOG_CALL << serial;
130 LOG(ERROR) << " iccCloseLogicalChannelWithSessionInfo is unsupported by HIDL HALs";
131 respond()->iccCloseLogicalChannelWithSessionInfoResponse(notSupported(serial));
132 return ok();
133 }
134
iccIoForApp(int32_t serial,const aidl::IccIo & iccIo)135 ScopedAStatus RadioSim::iccIoForApp(int32_t serial, const aidl::IccIo& iccIo) {
136 LOG_CALL << serial;
137 mHal1_5->iccIOForApp(serial, toHidl(iccIo));
138 return ok();
139 }
140
iccOpenLogicalChannel(int32_t serial,const std::string & aid,int32_t p2)141 ScopedAStatus RadioSim::iccOpenLogicalChannel(int32_t serial, const std::string& aid, int32_t p2) {
142 LOG_CALL << serial;
143 mHal1_5->iccOpenLogicalChannel(serial, aid, p2);
144 return ok();
145 }
146
iccTransmitApduBasicChannel(int32_t serial,const aidl::SimApdu & message)147 ScopedAStatus RadioSim::iccTransmitApduBasicChannel(int32_t serial, const aidl::SimApdu& message) {
148 LOG_CALL << serial;
149 mHal1_5->iccTransmitApduBasicChannel(serial, toHidl(message));
150 return ok();
151 }
152
iccTransmitApduLogicalChannel(int32_t serial,const aidl::SimApdu & message)153 ScopedAStatus RadioSim::iccTransmitApduLogicalChannel(int32_t serial,
154 const aidl::SimApdu& message) {
155 LOG_CALL << serial;
156 mHal1_5->iccTransmitApduLogicalChannel(serial, toHidl(message));
157 return ok();
158 }
159
reportStkServiceIsRunning(int32_t serial)160 ScopedAStatus RadioSim::reportStkServiceIsRunning(int32_t serial) {
161 LOG_CALL << serial;
162 mHal1_5->reportStkServiceIsRunning(serial);
163 return ok();
164 }
165
requestIccSimAuthentication(int32_t serial,int32_t authContext,const std::string & authData,const std::string & aid)166 ScopedAStatus RadioSim::requestIccSimAuthentication( //
167 int32_t serial, int32_t authContext, const std::string& authData, const std::string& aid) {
168 LOG_CALL << serial;
169 mHal1_5->requestIccSimAuthentication(serial, authContext, authData, aid);
170 return ok();
171 }
172
responseAcknowledgement()173 ScopedAStatus RadioSim::responseAcknowledgement() {
174 LOG_CALL;
175 mHal1_5->responseAcknowledgement();
176 return ok();
177 }
178
sendEnvelope(int32_t serial,const std::string & command)179 ScopedAStatus RadioSim::sendEnvelope(int32_t serial, const std::string& command) {
180 LOG_CALL << serial;
181 mHal1_5->sendEnvelope(serial, command);
182 return ok();
183 }
184
sendEnvelopeWithStatus(int32_t serial,const std::string & contents)185 ScopedAStatus RadioSim::sendEnvelopeWithStatus(int32_t serial, const std::string& contents) {
186 LOG_CALL << serial;
187 mHal1_5->sendEnvelopeWithStatus(serial, contents);
188 return ok();
189 }
190
sendTerminalResponseToSim(int32_t serial,const std::string & commandResponse)191 ScopedAStatus RadioSim::sendTerminalResponseToSim(int32_t serial,
192 const std::string& commandResponse) {
193 LOG_CALL << serial;
194 mHal1_5->sendTerminalResponseToSim(serial, commandResponse);
195 return ok();
196 }
197
setAllowedCarriers(int32_t serial,const aidl::CarrierRestrictions & carriers,aidl::SimLockMultiSimPolicy mp)198 ScopedAStatus RadioSim::setAllowedCarriers( //
199 int32_t serial, const aidl::CarrierRestrictions& carriers, aidl::SimLockMultiSimPolicy mp) {
200 LOG_CALL << serial;
201 mHal1_5->setAllowedCarriers_1_4(serial, toHidl(carriers), V1_4::SimLockMultiSimPolicy(mp));
202 return ok();
203 }
204
setCarrierInfoForImsiEncryption(int32_t serial,const aidl::ImsiEncryptionInfo & imsiEncryptionInfo)205 ScopedAStatus RadioSim::setCarrierInfoForImsiEncryption(
206 int32_t serial, const aidl::ImsiEncryptionInfo& imsiEncryptionInfo) {
207 LOG_CALL << serial;
208 if (mHal1_6) {
209 mHal1_6->setCarrierInfoForImsiEncryption_1_6(serial, toHidl_1_6(imsiEncryptionInfo));
210 } else {
211 mHal1_5->setCarrierInfoForImsiEncryption(serial, toHidl(imsiEncryptionInfo));
212 }
213 return ok();
214 }
215
setCdmaSubscriptionSource(int32_t serial,aidl::CdmaSubscriptionSource cdmaSub)216 ScopedAStatus RadioSim::setCdmaSubscriptionSource(int32_t serial,
217 aidl::CdmaSubscriptionSource cdmaSub) {
218 LOG_CALL << serial;
219 mHal1_5->setCdmaSubscriptionSource(serial, V1_0::CdmaSubscriptionSource(cdmaSub));
220 return ok();
221 }
222
setFacilityLockForApp(int32_t serial,const std::string & facility,bool lockState,const std::string & password,int32_t serviceClass,const std::string & appId)223 ScopedAStatus RadioSim::setFacilityLockForApp( //
224 int32_t serial, const std::string& facility, bool lockState, const std::string& password,
225 int32_t serviceClass, const std::string& appId) {
226 LOG_CALL << serial;
227 mHal1_5->setFacilityLockForApp(serial, facility, lockState, password, serviceClass, appId);
228 return ok();
229 }
230
setResponseFunctions(const std::shared_ptr<aidl::IRadioSimResponse> & response,const std::shared_ptr<aidl::IRadioSimIndication> & indication)231 ScopedAStatus RadioSim::setResponseFunctions(
232 const std::shared_ptr<aidl::IRadioSimResponse>& response,
233 const std::shared_ptr<aidl::IRadioSimIndication>& indication) {
234 LOG_CALL << response << ' ' << indication;
235 mCallbackManager->setResponseFunctions(response, indication);
236 return ok();
237 }
238
setSimCardPower(int32_t serial,aidl::CardPowerState powerUp)239 ScopedAStatus RadioSim::setSimCardPower(int32_t serial, aidl::CardPowerState powerUp) {
240 LOG_CALL << serial;
241 if (mHal1_6) {
242 mHal1_6->setSimCardPower_1_6(serial, V1_1::CardPowerState(powerUp));
243 } else {
244 mHal1_5->setSimCardPower_1_1(serial, V1_1::CardPowerState(powerUp));
245 }
246 return ok();
247 }
248
setUiccSubscription(int32_t serial,const aidl::SelectUiccSub & uiccSub)249 ScopedAStatus RadioSim::setUiccSubscription(int32_t serial, const aidl::SelectUiccSub& uiccSub) {
250 LOG_CALL << serial;
251 mHal1_5->setUiccSubscription(serial, toHidl(uiccSub));
252 return ok();
253 }
254
supplyIccPin2ForApp(int32_t serial,const std::string & pin2,const std::string & aid)255 ScopedAStatus RadioSim::supplyIccPin2ForApp(int32_t serial, const std::string& pin2,
256 const std::string& aid) {
257 LOG_CALL << serial;
258 mHal1_5->supplyIccPin2ForApp(serial, pin2, aid);
259 return ok();
260 }
261
supplyIccPinForApp(int32_t serial,const std::string & pin,const std::string & aid)262 ScopedAStatus RadioSim::supplyIccPinForApp(int32_t serial, const std::string& pin,
263 const std::string& aid) {
264 LOG_CALL << serial;
265 mHal1_5->supplyIccPinForApp(serial, pin, aid);
266 return ok();
267 }
268
supplyIccPuk2ForApp(int32_t serial,const std::string & puk2,const std::string & pin2,const std::string & aid)269 ScopedAStatus RadioSim::supplyIccPuk2ForApp(int32_t serial, const std::string& puk2,
270 const std::string& pin2, const std::string& aid) {
271 LOG_CALL << serial;
272 mHal1_5->supplyIccPuk2ForApp(serial, puk2, pin2, aid);
273 return ok();
274 }
275
supplyIccPukForApp(int32_t serial,const std::string & puk,const std::string & pin,const std::string & aid)276 ScopedAStatus RadioSim::supplyIccPukForApp(int32_t serial, const std::string& puk,
277 const std::string& pin, const std::string& aid) {
278 LOG_CALL << serial;
279 mHal1_5->supplyIccPukForApp(serial, puk, pin, aid);
280 return ok();
281 }
282
supplySimDepersonalization(int32_t serial,aidl::PersoSubstate pss,const std::string & controlKey)283 ScopedAStatus RadioSim::supplySimDepersonalization(int32_t serial, aidl::PersoSubstate pss,
284 const std::string& controlKey) {
285 LOG_CALL << serial;
286 mHal1_5->supplySimDepersonalization(serial, V1_5::PersoSubstate(pss), controlKey);
287 return ok();
288 }
289
updateSimPhonebookRecords(int32_t serial,const aidl::PhonebookRecordInfo & recordInfo)290 ScopedAStatus RadioSim::updateSimPhonebookRecords(int32_t serial,
291 const aidl::PhonebookRecordInfo& recordInfo) {
292 LOG_CALL << serial;
293 if (mHal1_6) {
294 mHal1_6->updateSimPhonebookRecords(serial, toHidl(recordInfo));
295 } else {
296 respond()->updateSimPhonebookRecordsResponse(notSupported(serial), 0);
297 }
298 return ok();
299 }
300 } // namespace android::hardware::radio::compat
301