blob: 490b07b9f998ada6c7eee54c7f6f0d88e820f35d [file] [log] [blame]
Tomasz Wasilczykfb10e002021-10-28 13:22:47 -07001/*
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
27namespace android::hardware::radio::compat {
28
29using ::ndk::ScopedAStatus;
30namespace aidl = ::aidl::android::hardware::radio::sim;
31constexpr auto ok = &ScopedAStatus::ok;
32
Tomasz Wasilczyk6902a752021-12-13 17:13:48 -080033std::shared_ptr<aidl::IRadioSimResponse> RadioSim::respond() {
Tomasz Wasilczyk8579f1d2021-12-16 12:19:09 -080034 return mCallbackManager->response().simCb();
Tomasz Wasilczyk6902a752021-12-13 17:13:48 -080035}
36
Tomasz Wasilczykfb10e002021-10-28 13:22:47 -070037ScopedAStatus RadioSim::areUiccApplicationsEnabled(int32_t serial) {
38 LOG_CALL << serial;
39 mHal1_5->areUiccApplicationsEnabled(serial);
40 return ok();
41}
42
43ScopedAStatus 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
50ScopedAStatus 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
57ScopedAStatus RadioSim::enableUiccApplications(int32_t serial, bool enable) {
58 LOG_CALL << serial;
59 mHal1_5->enableUiccApplications(serial, enable);
60 return ok();
61}
62
63ScopedAStatus RadioSim::getAllowedCarriers(int32_t serial) {
64 LOG_CALL << serial;
Tomasz Wasilczyk31f6fab2021-12-15 16:15:45 -080065 mHal1_5->getAllowedCarriers_1_4(serial);
Tomasz Wasilczykfb10e002021-10-28 13:22:47 -070066 return ok();
67}
68
69ScopedAStatus RadioSim::getCdmaSubscription(int32_t serial) {
70 LOG_CALL << serial;
71 mHal1_5->getCDMASubscription(serial);
72 return ok();
73}
74
75ScopedAStatus RadioSim::getCdmaSubscriptionSource(int32_t serial) {
76 LOG_CALL << serial;
77 mHal1_5->getCdmaSubscriptionSource(serial);
78 return ok();
79}
80
81ScopedAStatus 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
89ScopedAStatus RadioSim::getIccCardStatus(int32_t serial) {
90 LOG_CALL << serial;
91 mHal1_5->getIccCardStatus(serial);
92 return ok();
93}
94
95ScopedAStatus RadioSim::getImsiForApp(int32_t serial, const std::string& aid) {
96 LOG_CALL << serial;
97 mHal1_5->getImsiForApp(serial, aid);
98 return ok();
99}
100
101ScopedAStatus RadioSim::getSimPhonebookCapacity(int32_t serial) {
102 LOG_CALL << serial;
103 if (mHal1_6) {
104 mHal1_6->getSimPhonebookCapacity(serial);
105 } else {
Tomasz Wasilczyk6902a752021-12-13 17:13:48 -0800106 respond()->getSimPhonebookCapacityResponse(notSupported(serial), {});
Tomasz Wasilczykfb10e002021-10-28 13:22:47 -0700107 }
108 return ok();
109}
110
111ScopedAStatus RadioSim::getSimPhonebookRecords(int32_t serial) {
112 LOG_CALL << serial;
113 if (mHal1_6) {
114 mHal1_6->getSimPhonebookRecords(serial);
115 } else {
Tomasz Wasilczyk6902a752021-12-13 17:13:48 -0800116 respond()->getSimPhonebookRecordsResponse(notSupported(serial));
Tomasz Wasilczykfb10e002021-10-28 13:22:47 -0700117 }
118 return ok();
119}
120
121ScopedAStatus RadioSim::iccCloseLogicalChannel(int32_t serial, int32_t channelId) {
122 LOG_CALL << serial;
123 mHal1_5->iccCloseLogicalChannel(serial, channelId);
124 return ok();
125}
126
Muralidhar Reddyc13d0d62023-01-18 18:45:14 +0000127ScopedAStatus 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
Tomasz Wasilczykfb10e002021-10-28 13:22:47 -0700135ScopedAStatus 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
141ScopedAStatus 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
147ScopedAStatus 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
153ScopedAStatus 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
160ScopedAStatus RadioSim::reportStkServiceIsRunning(int32_t serial) {
161 LOG_CALL << serial;
162 mHal1_5->reportStkServiceIsRunning(serial);
163 return ok();
164}
165
166ScopedAStatus 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
173ScopedAStatus RadioSim::responseAcknowledgement() {
174 LOG_CALL;
175 mHal1_5->responseAcknowledgement();
176 return ok();
177}
178
179ScopedAStatus RadioSim::sendEnvelope(int32_t serial, const std::string& command) {
180 LOG_CALL << serial;
181 mHal1_5->sendEnvelope(serial, command);
182 return ok();
183}
184
185ScopedAStatus RadioSim::sendEnvelopeWithStatus(int32_t serial, const std::string& contents) {
186 LOG_CALL << serial;
187 mHal1_5->sendEnvelopeWithStatus(serial, contents);
188 return ok();
189}
190
191ScopedAStatus 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
198ScopedAStatus 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
205ScopedAStatus 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
216ScopedAStatus 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
223ScopedAStatus 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
231ScopedAStatus RadioSim::setResponseFunctions(
Tomasz Wasilczyk8579f1d2021-12-16 12:19:09 -0800232 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);
Tomasz Wasilczykfb10e002021-10-28 13:22:47 -0700236 return ok();
237}
238
239ScopedAStatus 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
249ScopedAStatus 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
255ScopedAStatus 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
262ScopedAStatus 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
269ScopedAStatus 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
276ScopedAStatus 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
283ScopedAStatus 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
290ScopedAStatus 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 {
Tomasz Wasilczyk6902a752021-12-13 17:13:48 -0800296 respond()->updateSimPhonebookRecordsResponse(notSupported(serial), 0);
Tomasz Wasilczykfb10e002021-10-28 13:22:47 -0700297 }
298 return ok();
299}
Tomasz Wasilczykfb10e002021-10-28 13:22:47 -0700300} // namespace android::hardware::radio::compat