blob: 5fecd8838b09a3329caff177f10d5326a87f90ce [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() {
34 return mRadioResponse->simCb();
35}
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;
65 mHal1_5->getAllowedCarriers(serial);
66 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
127ScopedAStatus RadioSim::iccIoForApp(int32_t serial, const aidl::IccIo& iccIo) {
128 LOG_CALL << serial;
129 mHal1_5->iccIOForApp(serial, toHidl(iccIo));
130 return ok();
131}
132
133ScopedAStatus RadioSim::iccOpenLogicalChannel(int32_t serial, const std::string& aid, int32_t p2) {
134 LOG_CALL << serial;
135 mHal1_5->iccOpenLogicalChannel(serial, aid, p2);
136 return ok();
137}
138
139ScopedAStatus RadioSim::iccTransmitApduBasicChannel(int32_t serial, const aidl::SimApdu& message) {
140 LOG_CALL << serial;
141 mHal1_5->iccTransmitApduBasicChannel(serial, toHidl(message));
142 return ok();
143}
144
145ScopedAStatus RadioSim::iccTransmitApduLogicalChannel(int32_t serial,
146 const aidl::SimApdu& message) {
147 LOG_CALL << serial;
148 mHal1_5->iccTransmitApduLogicalChannel(serial, toHidl(message));
149 return ok();
150}
151
152ScopedAStatus RadioSim::reportStkServiceIsRunning(int32_t serial) {
153 LOG_CALL << serial;
154 mHal1_5->reportStkServiceIsRunning(serial);
155 return ok();
156}
157
158ScopedAStatus RadioSim::requestIccSimAuthentication( //
159 int32_t serial, int32_t authContext, const std::string& authData, const std::string& aid) {
160 LOG_CALL << serial;
161 mHal1_5->requestIccSimAuthentication(serial, authContext, authData, aid);
162 return ok();
163}
164
165ScopedAStatus RadioSim::responseAcknowledgement() {
166 LOG_CALL;
167 mHal1_5->responseAcknowledgement();
168 return ok();
169}
170
171ScopedAStatus RadioSim::sendEnvelope(int32_t serial, const std::string& command) {
172 LOG_CALL << serial;
173 mHal1_5->sendEnvelope(serial, command);
174 return ok();
175}
176
177ScopedAStatus RadioSim::sendEnvelopeWithStatus(int32_t serial, const std::string& contents) {
178 LOG_CALL << serial;
179 mHal1_5->sendEnvelopeWithStatus(serial, contents);
180 return ok();
181}
182
183ScopedAStatus RadioSim::sendTerminalResponseToSim(int32_t serial,
184 const std::string& commandResponse) {
185 LOG_CALL << serial;
186 mHal1_5->sendTerminalResponseToSim(serial, commandResponse);
187 return ok();
188}
189
190ScopedAStatus RadioSim::setAllowedCarriers( //
191 int32_t serial, const aidl::CarrierRestrictions& carriers, aidl::SimLockMultiSimPolicy mp) {
192 LOG_CALL << serial;
193 mHal1_5->setAllowedCarriers_1_4(serial, toHidl(carriers), V1_4::SimLockMultiSimPolicy(mp));
194 return ok();
195}
196
197ScopedAStatus RadioSim::setCarrierInfoForImsiEncryption(
198 int32_t serial, const aidl::ImsiEncryptionInfo& imsiEncryptionInfo) {
199 LOG_CALL << serial;
200 if (mHal1_6) {
201 mHal1_6->setCarrierInfoForImsiEncryption_1_6(serial, toHidl_1_6(imsiEncryptionInfo));
202 } else {
203 mHal1_5->setCarrierInfoForImsiEncryption(serial, toHidl(imsiEncryptionInfo));
204 }
205 return ok();
206}
207
208ScopedAStatus RadioSim::setCdmaSubscriptionSource(int32_t serial,
209 aidl::CdmaSubscriptionSource cdmaSub) {
210 LOG_CALL << serial;
211 mHal1_5->setCdmaSubscriptionSource(serial, V1_0::CdmaSubscriptionSource(cdmaSub));
212 return ok();
213}
214
215ScopedAStatus RadioSim::setFacilityLockForApp( //
216 int32_t serial, const std::string& facility, bool lockState, const std::string& password,
217 int32_t serviceClass, const std::string& appId) {
218 LOG_CALL << serial;
219 mHal1_5->setFacilityLockForApp(serial, facility, lockState, password, serviceClass, appId);
220 return ok();
221}
222
223ScopedAStatus RadioSim::setResponseFunctions(
224 const std::shared_ptr<aidl::IRadioSimResponse>& simResponse,
225 const std::shared_ptr<aidl::IRadioSimIndication>& simIndication) {
226 LOG_CALL << simResponse << ' ' << simIndication;
227
228 CHECK(simResponse);
229 CHECK(simIndication);
230
231 mRadioResponse->setResponseFunction(simResponse);
232 mRadioIndication->setResponseFunction(simIndication);
233
234 return ok();
235}
236
237ScopedAStatus RadioSim::setSimCardPower(int32_t serial, aidl::CardPowerState powerUp) {
238 LOG_CALL << serial;
239 if (mHal1_6) {
240 mHal1_6->setSimCardPower_1_6(serial, V1_1::CardPowerState(powerUp));
241 } else {
242 mHal1_5->setSimCardPower_1_1(serial, V1_1::CardPowerState(powerUp));
243 }
244 return ok();
245}
246
247ScopedAStatus RadioSim::setUiccSubscription(int32_t serial, const aidl::SelectUiccSub& uiccSub) {
248 LOG_CALL << serial;
249 mHal1_5->setUiccSubscription(serial, toHidl(uiccSub));
250 return ok();
251}
252
253ScopedAStatus RadioSim::supplyIccPin2ForApp(int32_t serial, const std::string& pin2,
254 const std::string& aid) {
255 LOG_CALL << serial;
256 mHal1_5->supplyIccPin2ForApp(serial, pin2, aid);
257 return ok();
258}
259
260ScopedAStatus RadioSim::supplyIccPinForApp(int32_t serial, const std::string& pin,
261 const std::string& aid) {
262 LOG_CALL << serial;
263 mHal1_5->supplyIccPinForApp(serial, pin, aid);
264 return ok();
265}
266
267ScopedAStatus RadioSim::supplyIccPuk2ForApp(int32_t serial, const std::string& puk2,
268 const std::string& pin2, const std::string& aid) {
269 LOG_CALL << serial;
270 mHal1_5->supplyIccPuk2ForApp(serial, puk2, pin2, aid);
271 return ok();
272}
273
274ScopedAStatus RadioSim::supplyIccPukForApp(int32_t serial, const std::string& puk,
275 const std::string& pin, const std::string& aid) {
276 LOG_CALL << serial;
277 mHal1_5->supplyIccPukForApp(serial, puk, pin, aid);
278 return ok();
279}
280
281ScopedAStatus RadioSim::supplySimDepersonalization(int32_t serial, aidl::PersoSubstate pss,
282 const std::string& controlKey) {
283 LOG_CALL << serial;
284 mHal1_5->supplySimDepersonalization(serial, V1_5::PersoSubstate(pss), controlKey);
285 return ok();
286}
287
288ScopedAStatus RadioSim::updateSimPhonebookRecords(int32_t serial,
289 const aidl::PhonebookRecordInfo& recordInfo) {
290 LOG_CALL << serial;
291 if (mHal1_6) {
292 mHal1_6->updateSimPhonebookRecords(serial, toHidl(recordInfo));
293 } else {
Tomasz Wasilczyk6902a752021-12-13 17:13:48 -0800294 respond()->updateSimPhonebookRecordsResponse(notSupported(serial), 0);
Tomasz Wasilczykfb10e002021-10-28 13:22:47 -0700295 }
296 return ok();
297}
298
299} // namespace android::hardware::radio::compat