1 /*
2  * Copyright (C) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "tel_ril_sim.h"
17 
18 #include "radio_event.h"
19 #include "sim_data_type.h"
20 #include "sim_utils.h"
21 
22 namespace OHOS {
23 namespace Telephony {
TelRilSim(int32_t slotId,sptr<HDI::Ril::V1_3::IRil> rilInterface,std::shared_ptr<ObserverHandler> observerHandler,std::shared_ptr<TelRilHandler> handler)24 TelRilSim::TelRilSim(int32_t slotId, sptr<HDI::Ril::V1_3::IRil> rilInterface,
25     std::shared_ptr<ObserverHandler> observerHandler, std::shared_ptr<TelRilHandler> handler)
26     : TelRilBase(slotId, rilInterface, observerHandler, handler)
27 {}
28 
29 // notification
SimStateUpdated()30 int32_t TelRilSim::SimStateUpdated()
31 {
32     return Notify(TELEPHONY_LOG_FUNC_NAME, RadioEvent::RADIO_SIM_STATE_CHANGE);
33 }
34 
SimStkSessionEndNotify()35 int32_t TelRilSim::SimStkSessionEndNotify()
36 {
37     return Notify(TELEPHONY_LOG_FUNC_NAME, RadioEvent::RADIO_STK_SESSION_END);
38 }
39 
SimStkProactiveNotify(const std::string & response)40 int32_t TelRilSim::SimStkProactiveNotify(const std::string &response)
41 {
42     return Notify<std::string>(
43         TELEPHONY_LOG_FUNC_NAME, std::make_shared<std::string>(response), RadioEvent::RADIO_STK_PROACTIVE_COMMAND);
44 }
45 
SimStkAlphaNotify(const std::string & response)46 int32_t TelRilSim::SimStkAlphaNotify(const std::string &response)
47 {
48     return Notify<std::string>(
49         TELEPHONY_LOG_FUNC_NAME, std::make_shared<std::string>(response), RadioEvent::RADIO_STK_ALPHA_NOTIFY);
50 }
51 
SimStkEventNotify(const std::string & response)52 int32_t TelRilSim::SimStkEventNotify(const std::string &response)
53 {
54     return Notify<std::string>(
55         TELEPHONY_LOG_FUNC_NAME, std::make_shared<std::string>(response), RadioEvent::RADIO_STK_EVENT_NOTIFY);
56 }
57 
SimStkCallSetupNotify()58 int32_t TelRilSim::SimStkCallSetupNotify()
59 {
60     return Notify(TELEPHONY_LOG_FUNC_NAME, RadioEvent::RADIO_STK_CALL_SETUP);
61 }
62 
SimRefreshNotify()63 int32_t TelRilSim::SimRefreshNotify()
64 {
65     return Notify(TELEPHONY_LOG_FUNC_NAME, RadioEvent::RADIO_ICC_REFRESH);
66 }
67 
SimRadioProtocolUpdated(const HDI::Ril::V1_1::RadioProtocol & radioProtocol)68 int32_t TelRilSim::SimRadioProtocolUpdated(const HDI::Ril::V1_1::RadioProtocol &radioProtocol)
69 {
70     std::shared_ptr<RadioProtocol> protocol = std::make_shared<RadioProtocol>();
71     BuildRadioProtocol(protocol, radioProtocol);
72     return Notify<RadioProtocol>(TELEPHONY_LOG_FUNC_NAME, protocol, RADIO_SIM_RADIO_PROTOCOL_NOTIFY);
73 }
74 
75 // response
GetSimIOResponse(const HDI::Ril::V1_1::RilRadioResponseInfo & responseInfo,const HDI::Ril::V1_1::IccIoResultInfo & result)76 int32_t TelRilSim::GetSimIOResponse(
77     const HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const HDI::Ril::V1_1::IccIoResultInfo &result)
78 {
79     return ResponseIccIo(responseInfo, result);
80 }
81 
ErrorIccIoResponse(std::shared_ptr<TelRilRequest> telRilRequest,const RadioResponseInfo & responseInfo)82 int32_t TelRilSim::ErrorIccIoResponse(
83     std::shared_ptr<TelRilRequest> telRilRequest, const RadioResponseInfo &responseInfo)
84 {
85     std::shared_ptr<RadioResponseInfo> respInfo = std::make_shared<RadioResponseInfo>();
86     if (telRilRequest != nullptr && telRilRequest->pointer_ != nullptr) {
87         const std::shared_ptr<OHOS::AppExecFwk::EventHandler> &handler = telRilRequest->pointer_->GetOwner();
88         if (handler == nullptr) {
89             TELEPHONY_LOGE("ERROR: handler == nullptr !!!");
90             return TELEPHONY_ERR_LOCAL_PTR_NULL;
91         }
92         respInfo->serial = responseInfo.serial;
93         respInfo->error = responseInfo.error;
94         respInfo->flag = telRilRequest->pointer_->GetParam();
95 
96         uint32_t eventId = telRilRequest->pointer_->GetInnerEventId();
97         std::unique_ptr<Telephony::IccToRilMsg> toMsg =
98             telRilRequest->pointer_->GetUniqueObject<Telephony::IccToRilMsg>();
99         if (toMsg == nullptr) {
100             TELEPHONY_LOGE("ERROR: toMsg == nullptr !!!");
101             return TELEPHONY_ERR_LOCAL_PTR_NULL;
102         }
103         std::shared_ptr<Telephony::IccFromRilMsg> object =
104             std::make_shared<Telephony::IccFromRilMsg>(toMsg->controlHolder);
105         object->controlHolder = toMsg->controlHolder;
106         object->fileData.exception = static_cast<std::shared_ptr<void>>(respInfo);
107         SendEventData(TELEPHONY_LOG_FUNC_NAME, eventId, handler, object);
108     } else {
109         TELEPHONY_LOGE("ERROR: telRilRequest or telRilRequest->pointer_ == nullptr !!!");
110         return TELEPHONY_ERR_LOCAL_PTR_NULL;
111     }
112     return TELEPHONY_ERR_SUCCESS;
113 }
114 
ProcessIccIoInfo(std::shared_ptr<TelRilRequest> telRilRequest,std::shared_ptr<IccIoResultInfo> iccIoResult)115 int32_t TelRilSim::ProcessIccIoInfo(
116     std::shared_ptr<TelRilRequest> telRilRequest, std::shared_ptr<IccIoResultInfo> iccIoResult)
117 {
118     if (telRilRequest == nullptr) {
119         TELEPHONY_LOGE("ERROR: telRilRequest== nullptr !!!");
120         return TELEPHONY_ERR_LOCAL_PTR_NULL;
121     }
122     if (telRilRequest->pointer_ == nullptr) {
123         TELEPHONY_LOGE("ERROR: telRilRequest->pointer_== nullptr !!!");
124         return TELEPHONY_ERR_LOCAL_PTR_NULL;
125     }
126     if (telRilRequest->pointer_->GetOwner() == nullptr || iccIoResult == nullptr) {
127         TELEPHONY_LOGE("ERROR: telRilRequest->pointer_->GetOwner() or iccIoResult == nullptr !!!");
128         return TELEPHONY_ERR_LOCAL_PTR_NULL;
129     }
130     const std::shared_ptr<OHOS::AppExecFwk::EventHandler> &handler = telRilRequest->pointer_->GetOwner();
131     uint32_t eventId = telRilRequest->pointer_->GetInnerEventId();
132     std::unique_ptr<Telephony::IccToRilMsg> toMsg = telRilRequest->pointer_->GetUniqueObject<Telephony::IccToRilMsg>();
133     if (toMsg == nullptr) {
134         TELEPHONY_LOGE("ERROR: GetUniqueObject<IccToRilMsg>() failed !!!");
135         return TELEPHONY_ERR_LOCAL_PTR_NULL;
136     }
137     std::unique_ptr<Telephony::IccFromRilMsg> object = std::make_unique<Telephony::IccFromRilMsg>(toMsg->controlHolder);
138     object->fileData.resultData = iccIoResult->response;
139     object->fileData.sw1 = iccIoResult->sw1;
140     object->fileData.sw2 = iccIoResult->sw2;
141     object->controlHolder = toMsg->controlHolder;
142     object->arg1 = toMsg->arg1;
143     object->arg2 = toMsg->arg2;
144     SendEventData(TELEPHONY_LOG_FUNC_NAME, eventId, handler, std::move(object));
145     return TELEPHONY_ERR_SUCCESS;
146 }
147 
GetSimStatusResponse(const HDI::Ril::V1_1::RilRadioResponseInfo & responseInfo,const HDI::Ril::V1_1::CardStatusInfo & result)148 int32_t TelRilSim::GetSimStatusResponse(
149     const HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const HDI::Ril::V1_1::CardStatusInfo &result)
150 {
151     std::shared_ptr<CardStatusInfo> cardStatusInfo = std::make_shared<CardStatusInfo>();
152     BuildCardStatusInfo(cardStatusInfo, result);
153     return Response<CardStatusInfo>(TELEPHONY_LOG_FUNC_NAME, responseInfo, cardStatusInfo);
154 }
155 
GetSimCardStatusResponse(const HDI::Ril::V1_1::RilRadioResponseInfo & responseInfo,const HDI::Ril::V1_3::SimCardStatusInfo & result)156 int32_t TelRilSim::GetSimCardStatusResponse(const HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo,
157     const HDI::Ril::V1_3::SimCardStatusInfo &result)
158 {
159     std::shared_ptr<SimCardStatusInfo> simCardStatusInfo = std::make_shared<SimCardStatusInfo>();
160     BuildSimCardStatusInfo(simCardStatusInfo, result);
161     return Response<SimCardStatusInfo>(TELEPHONY_LOG_FUNC_NAME, responseInfo, simCardStatusInfo);
162 }
163 
GetImsiResponse(const HDI::Ril::V1_1::RilRadioResponseInfo & responseInfo,const std::string & result)164 int32_t TelRilSim::GetImsiResponse(const HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const std::string &result)
165 {
166     return Response<std::string>(TELEPHONY_LOG_FUNC_NAME, responseInfo, std::make_shared<std::string>(result));
167 }
168 
GetSimLockStatusResponse(const HDI::Ril::V1_1::RilRadioResponseInfo & responseInfo,int32_t simLockStatus)169 int32_t TelRilSim::GetSimLockStatusResponse(
170     const HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, int32_t simLockStatus)
171 {
172     return Response<int32_t>(TELEPHONY_LOG_FUNC_NAME, responseInfo, std::make_shared<int32_t>(simLockStatus));
173 }
174 
SetSimLockResponse(const HDI::Ril::V1_1::RilRadioResponseInfo & responseInfo,const HDI::Ril::V1_1::LockStatusResp & lockStatus)175 int32_t TelRilSim::SetSimLockResponse(
176     const HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const HDI::Ril::V1_1::LockStatusResp &lockStatus)
177 {
178     std::shared_ptr<LockStatusResp> lockStatusResp = std::make_shared<LockStatusResp>();
179     BuildLockStatusResp(lockStatusResp, lockStatus);
180     return Response<LockStatusResp>(TELEPHONY_LOG_FUNC_NAME, responseInfo, lockStatusResp);
181 }
182 
ChangeSimPasswordResponse(const HDI::Ril::V1_1::RilRadioResponseInfo & responseInfo,const HDI::Ril::V1_1::LockStatusResp & lockStatus)183 int32_t TelRilSim::ChangeSimPasswordResponse(
184     const HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const HDI::Ril::V1_1::LockStatusResp &lockStatus)
185 {
186     std::shared_ptr<LockStatusResp> lockStatusResp = std::make_shared<LockStatusResp>();
187     BuildLockStatusResp(lockStatusResp, lockStatus);
188     return Response<LockStatusResp>(TELEPHONY_LOG_FUNC_NAME, responseInfo, lockStatusResp);
189 }
190 
UnlockPinResponse(const HDI::Ril::V1_1::RilRadioResponseInfo & responseInfo,const HDI::Ril::V1_1::LockStatusResp & lockStatus)191 int32_t TelRilSim::UnlockPinResponse(
192     const HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const HDI::Ril::V1_1::LockStatusResp &lockStatus)
193 {
194     std::shared_ptr<LockStatusResp> lockStatusResp = std::make_shared<LockStatusResp>();
195     BuildLockStatusResp(lockStatusResp, lockStatus);
196     return Response<LockStatusResp>(TELEPHONY_LOG_FUNC_NAME, responseInfo, lockStatusResp);
197 }
198 
UnlockPukResponse(const HDI::Ril::V1_1::RilRadioResponseInfo & responseInfo,const HDI::Ril::V1_1::LockStatusResp & lockStatus)199 int32_t TelRilSim::UnlockPukResponse(
200     const HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const HDI::Ril::V1_1::LockStatusResp &lockStatus)
201 {
202     std::shared_ptr<LockStatusResp> lockStatusResp = std::make_shared<LockStatusResp>();
203     BuildLockStatusResp(lockStatusResp, lockStatus);
204     return Response<LockStatusResp>(TELEPHONY_LOG_FUNC_NAME, responseInfo, lockStatusResp);
205 }
206 
UnlockPin2Response(const HDI::Ril::V1_1::RilRadioResponseInfo & responseInfo,const HDI::Ril::V1_1::LockStatusResp & lockStatus)207 int32_t TelRilSim::UnlockPin2Response(
208     const HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const HDI::Ril::V1_1::LockStatusResp &lockStatus)
209 {
210     std::shared_ptr<LockStatusResp> lockStatusResp = std::make_shared<LockStatusResp>();
211     BuildLockStatusResp(lockStatusResp, lockStatus);
212     return Response<LockStatusResp>(TELEPHONY_LOG_FUNC_NAME, responseInfo, lockStatusResp);
213 }
214 
UnlockPuk2Response(const HDI::Ril::V1_1::RilRadioResponseInfo & responseInfo,const HDI::Ril::V1_1::LockStatusResp & lockStatus)215 int32_t TelRilSim::UnlockPuk2Response(
216     const HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const HDI::Ril::V1_1::LockStatusResp &lockStatus)
217 {
218     std::shared_ptr<LockStatusResp> lockStatusResp = std::make_shared<LockStatusResp>();
219     BuildLockStatusResp(lockStatusResp, lockStatus);
220     return Response<LockStatusResp>(TELEPHONY_LOG_FUNC_NAME, responseInfo, lockStatusResp);
221 }
222 
SetActiveSimResponse(const HDI::Ril::V1_1::RilRadioResponseInfo & responseInfo)223 int32_t TelRilSim::SetActiveSimResponse(const HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo)
224 {
225     return Response(TELEPHONY_LOG_FUNC_NAME, responseInfo);
226 }
227 
SimStkSendTerminalResponseResponse(const HDI::Ril::V1_1::RilRadioResponseInfo & responseInfo)228 int32_t TelRilSim::SimStkSendTerminalResponseResponse(const HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo)
229 {
230     return Response(TELEPHONY_LOG_FUNC_NAME, responseInfo);
231 }
232 
SimStkSendEnvelopeResponse(const HDI::Ril::V1_1::RilRadioResponseInfo & responseInfo)233 int32_t TelRilSim::SimStkSendEnvelopeResponse(const HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo)
234 {
235     return Response(TELEPHONY_LOG_FUNC_NAME, responseInfo);
236 }
237 
SimStkSendCallSetupRequestResultResponse(const HDI::Ril::V1_1::RilRadioResponseInfo & responseInfo)238 int32_t TelRilSim::SimStkSendCallSetupRequestResultResponse(const HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo)
239 {
240     return Response(TELEPHONY_LOG_FUNC_NAME, responseInfo);
241 }
242 
SimStkIsReadyResponse(const HDI::Ril::V1_1::RilRadioResponseInfo & responseInfo)243 int32_t TelRilSim::SimStkIsReadyResponse(const HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo)
244 {
245     return Response(TELEPHONY_LOG_FUNC_NAME, responseInfo);
246 }
247 
GetRadioProtocolResponse(const HDI::Ril::V1_1::RilRadioResponseInfo & responseInfo,const HDI::Ril::V1_1::RadioProtocol & radioProtocol)248 int32_t TelRilSim::GetRadioProtocolResponse(
249     const HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const HDI::Ril::V1_1::RadioProtocol &radioProtocol)
250 {
251     std::shared_ptr<RadioProtocol> protocol = std::make_shared<RadioProtocol>();
252     BuildRadioProtocol(protocol, radioProtocol);
253     return Response<RadioProtocol>(TELEPHONY_LOG_FUNC_NAME, responseInfo, protocol);
254 }
255 
SetRadioProtocolResponse(const HDI::Ril::V1_1::RilRadioResponseInfo & responseInfo,const HDI::Ril::V1_1::RadioProtocol & radioProtocol)256 int32_t TelRilSim::SetRadioProtocolResponse(
257     const HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const HDI::Ril::V1_1::RadioProtocol &radioProtocol)
258 {
259     std::shared_ptr<RadioProtocol> protocol = std::make_shared<RadioProtocol>();
260     BuildRadioProtocol(protocol, radioProtocol);
261     return Response<RadioProtocol>(TELEPHONY_LOG_FUNC_NAME, responseInfo, protocol);
262 }
263 
SimOpenLogicalChannelResponse(const HDI::Ril::V1_1::RilRadioResponseInfo & responseInfo,const HDI::Ril::V1_1::OpenLogicalChannelResponse & pOpenLogicalChannelResponse)264 int32_t TelRilSim::SimOpenLogicalChannelResponse(const HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo,
265     const HDI::Ril::V1_1::OpenLogicalChannelResponse &pOpenLogicalChannelResponse)
266 {
267     std::shared_ptr<OpenLogicalChannelResponse> openLogicalChannelResp = std::make_shared<OpenLogicalChannelResponse>();
268     BuildOpenLogicalChannelResp(openLogicalChannelResp, pOpenLogicalChannelResponse);
269     return Response<OpenLogicalChannelResponse>(TELEPHONY_LOG_FUNC_NAME, responseInfo, openLogicalChannelResp);
270 }
271 
SimCloseLogicalChannelResponse(const HDI::Ril::V1_1::RilRadioResponseInfo & responseInfo)272 int32_t TelRilSim::SimCloseLogicalChannelResponse(const HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo)
273 {
274     return Response(TELEPHONY_LOG_FUNC_NAME, responseInfo);
275 }
276 
SimTransmitApduLogicalChannelResponse(const HDI::Ril::V1_1::RilRadioResponseInfo & responseInfo,const HDI::Ril::V1_1::IccIoResultInfo & result)277 int32_t TelRilSim::SimTransmitApduLogicalChannelResponse(
278     const HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const HDI::Ril::V1_1::IccIoResultInfo &result)
279 {
280     return ResponseIccIo(responseInfo, result);
281 }
282 
SimTransmitApduBasicChannelResponse(const HDI::Ril::V1_1::RilRadioResponseInfo & responseInfo,const HDI::Ril::V1_1::IccIoResultInfo & result)283 int32_t TelRilSim::SimTransmitApduBasicChannelResponse(
284     const HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const HDI::Ril::V1_1::IccIoResultInfo &result)
285 {
286     return ResponseIccIo(responseInfo, result);
287 }
288 
SimAuthenticationResponse(const HDI::Ril::V1_1::RilRadioResponseInfo & responseInfo,const HDI::Ril::V1_1::IccIoResultInfo & result)289 int32_t TelRilSim::SimAuthenticationResponse(
290     const HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const HDI::Ril::V1_1::IccIoResultInfo &result)
291 {
292     std::shared_ptr<IccIoResultInfo> simAuthResp = std::make_shared<IccIoResultInfo>();
293     simAuthResp->sw1 = result.sw1;
294     simAuthResp->sw2 = result.sw2;
295     simAuthResp->response = result.response;
296     return Response<IccIoResultInfo>(TELEPHONY_LOG_FUNC_NAME, responseInfo, simAuthResp);
297 }
298 
UnlockSimLockResponse(const HDI::Ril::V1_1::RilRadioResponseInfo & responseInfo,const HDI::Ril::V1_1::LockStatusResp & lockStatus)299 int32_t TelRilSim::UnlockSimLockResponse(
300     const HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const HDI::Ril::V1_1::LockStatusResp &lockStatus)
301 {
302     std::shared_ptr<LockStatusResp> lockStatusResp = std::make_shared<LockStatusResp>();
303     BuildLockStatusResp(lockStatusResp, lockStatus);
304     return Response<LockStatusResp>(TELEPHONY_LOG_FUNC_NAME, responseInfo, lockStatusResp);
305 }
306 
SendSimMatchedOperatorInfoResponse(const HDI::Ril::V1_1::RilRadioResponseInfo & responseInfo)307 int32_t TelRilSim::SendSimMatchedOperatorInfoResponse(const HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo)
308 {
309     return Response(TELEPHONY_LOG_FUNC_NAME, responseInfo);
310 }
311 
GetSimStatus(const AppExecFwk::InnerEvent::Pointer & result)312 int32_t TelRilSim::GetSimStatus(const AppExecFwk::InnerEvent::Pointer &result)
313 {
314     return Request(TELEPHONY_LOG_FUNC_NAME, result, &HDI::Ril::V1_1::IRil::GetSimStatus);
315 }
316 
GetSimIO(SimIoRequestInfo simIoInfo,const AppExecFwk::InnerEvent::Pointer & response)317 int32_t TelRilSim::GetSimIO(SimIoRequestInfo simIoInfo, const AppExecFwk::InnerEvent::Pointer &response)
318 {
319     OHOS::HDI::Ril::V1_1::SimIoRequestInfo iccIoRequestInfo;
320     iccIoRequestInfo.command = simIoInfo.command;
321     iccIoRequestInfo.fileId = simIoInfo.fileId;
322     iccIoRequestInfo.p1 = simIoInfo.p1;
323     iccIoRequestInfo.p2 = simIoInfo.p2;
324     iccIoRequestInfo.p3 = simIoInfo.p3;
325     iccIoRequestInfo.data = simIoInfo.data;
326     iccIoRequestInfo.path = simIoInfo.path;
327     iccIoRequestInfo.pin2 = simIoInfo.pin2;
328     return Request(TELEPHONY_LOG_FUNC_NAME, response, &HDI::Ril::V1_1::IRil::GetSimIO, iccIoRequestInfo);
329 }
330 
GetImsi(const AppExecFwk::InnerEvent::Pointer & result)331 int32_t TelRilSim::GetImsi(const AppExecFwk::InnerEvent::Pointer &result)
332 {
333     return Request(TELEPHONY_LOG_FUNC_NAME, result, &HDI::Ril::V1_1::IRil::GetImsi);
334 }
335 
GetSimLockStatus(std::string fac,const AppExecFwk::InnerEvent::Pointer & response)336 int32_t TelRilSim::GetSimLockStatus(std::string fac, const AppExecFwk::InnerEvent::Pointer &response)
337 {
338     const int32_t MODE = 2;
339     OHOS::HDI::Ril::V1_1::SimLockInfo simLockInfo;
340     simLockInfo.fac = fac;
341     simLockInfo.mode = MODE;
342     simLockInfo.classx = 0;
343     return Request(TELEPHONY_LOG_FUNC_NAME, response, &HDI::Ril::V1_1::IRil::GetSimLockStatus, simLockInfo);
344 }
345 
SetSimLock(std::string fac,int32_t mode,std::string passwd,const AppExecFwk::InnerEvent::Pointer & response)346 int32_t TelRilSim::SetSimLock(
347     std::string fac, int32_t mode, std::string passwd, const AppExecFwk::InnerEvent::Pointer &response)
348 {
349     OHOS::HDI::Ril::V1_1::SimLockInfo simLockInfo;
350     simLockInfo.fac = fac;
351     simLockInfo.mode = mode;
352     simLockInfo.passwd = passwd;
353     simLockInfo.classx = 0;
354     return Request(TELEPHONY_LOG_FUNC_NAME, response, &HDI::Ril::V1_1::IRil::SetSimLock, simLockInfo);
355 }
356 
ChangeSimPassword(std::string fac,std::string oldPassword,std::string newPassword,int32_t passwordLength,const AppExecFwk::InnerEvent::Pointer & response)357 int32_t TelRilSim::ChangeSimPassword(std::string fac, std::string oldPassword, std::string newPassword,
358     int32_t passwordLength, const AppExecFwk::InnerEvent::Pointer &response)
359 {
360     OHOS::HDI::Ril::V1_1::SimPasswordInfo simPwdInfo;
361     simPwdInfo.fac = fac;
362     simPwdInfo.oldPassword = oldPassword;
363     simPwdInfo.newPassword = newPassword;
364     simPwdInfo.passwordLength = passwordLength;
365     return Request(TELEPHONY_LOG_FUNC_NAME, response, &HDI::Ril::V1_1::IRil::ChangeSimPassword, simPwdInfo);
366 }
367 
UnlockPin(std::string pin,const AppExecFwk::InnerEvent::Pointer & response)368 int32_t TelRilSim::UnlockPin(std::string pin, const AppExecFwk::InnerEvent::Pointer &response)
369 {
370     return Request(TELEPHONY_LOG_FUNC_NAME, response, &HDI::Ril::V1_1::IRil::UnlockPin, pin);
371 }
372 
UnlockPuk(std::string puk,std::string pin,const AppExecFwk::InnerEvent::Pointer & response)373 int32_t TelRilSim::UnlockPuk(std::string puk, std::string pin, const AppExecFwk::InnerEvent::Pointer &response)
374 {
375     return Request(TELEPHONY_LOG_FUNC_NAME, response, &HDI::Ril::V1_1::IRil::UnlockPuk, puk, pin);
376 }
377 
UnlockPin2(std::string pin2,const AppExecFwk::InnerEvent::Pointer & response)378 int32_t TelRilSim::UnlockPin2(std::string pin2, const AppExecFwk::InnerEvent::Pointer &response)
379 {
380     return Request(TELEPHONY_LOG_FUNC_NAME, response, &HDI::Ril::V1_1::IRil::UnlockPin2, pin2);
381 }
382 
UnlockPuk2(std::string puk2,std::string pin2,const AppExecFwk::InnerEvent::Pointer & response)383 int32_t TelRilSim::UnlockPuk2(std::string puk2, std::string pin2, const AppExecFwk::InnerEvent::Pointer &response)
384 {
385     return Request(TELEPHONY_LOG_FUNC_NAME, response, &HDI::Ril::V1_1::IRil::UnlockPuk2, puk2, pin2);
386 }
387 
SetActiveSim(int32_t index,int32_t enable,const AppExecFwk::InnerEvent::Pointer & response)388 int32_t TelRilSim::SetActiveSim(int32_t index, int32_t enable, const AppExecFwk::InnerEvent::Pointer &response)
389 {
390     return Request(TELEPHONY_LOG_FUNC_NAME, response, &HDI::Ril::V1_1::IRil::SetActiveSim, index, enable);
391 }
392 
SimStkSendTerminalResponse(const std::string & strCmd,const AppExecFwk::InnerEvent::Pointer & response)393 int32_t TelRilSim::SimStkSendTerminalResponse(
394     const std::string &strCmd, const AppExecFwk::InnerEvent::Pointer &response)
395 {
396     return Request(TELEPHONY_LOG_FUNC_NAME, response, &HDI::Ril::V1_1::IRil::SimStkSendTerminalResponse, strCmd);
397 }
398 
SimStkSendEnvelope(const std::string & strCmd,const AppExecFwk::InnerEvent::Pointer & response)399 int32_t TelRilSim::SimStkSendEnvelope(const std::string &strCmd, const AppExecFwk::InnerEvent::Pointer &response)
400 {
401     return Request(TELEPHONY_LOG_FUNC_NAME, response, &HDI::Ril::V1_1::IRil::SimStkSendEnvelope, strCmd);
402 }
403 
SimStkSendCallSetupRequestResult(bool accept,const AppExecFwk::InnerEvent::Pointer & response)404 int32_t TelRilSim::SimStkSendCallSetupRequestResult(bool accept, const AppExecFwk::InnerEvent::Pointer &response)
405 {
406     return Request(
407         TELEPHONY_LOG_FUNC_NAME, response, &HDI::Ril::V1_1::IRil::SimStkSendCallSetupRequestResult, (int32_t)accept);
408 }
409 
SimStkIsReady(const AppExecFwk::InnerEvent::Pointer & response)410 int32_t TelRilSim::SimStkIsReady(const AppExecFwk::InnerEvent::Pointer &response)
411 {
412     return Request(TELEPHONY_LOG_FUNC_NAME, response, &HDI::Ril::V1_1::IRil::SimStkIsReady);
413 }
414 
GetRadioProtocol(const AppExecFwk::InnerEvent::Pointer & response)415 int32_t TelRilSim::GetRadioProtocol(const AppExecFwk::InnerEvent::Pointer &response)
416 {
417     return Request(TELEPHONY_LOG_FUNC_NAME, response, &HDI::Ril::V1_1::IRil::GetRadioProtocol);
418 }
419 
SetRadioProtocol(RadioProtocol radioProtocol,const AppExecFwk::InnerEvent::Pointer & response)420 int32_t TelRilSim::SetRadioProtocol(RadioProtocol radioProtocol, const AppExecFwk::InnerEvent::Pointer &response)
421 {
422     HDI::Ril::V1_1::RadioProtocol protocol;
423     protocol.slotId = radioProtocol.slotId;
424     protocol.sessionId = radioProtocol.sessionId;
425     protocol.phase = static_cast<HDI::Ril::V1_1::RadioProtocolPhase>(radioProtocol.phase);
426     protocol.technology = radioProtocol.technology;
427     protocol.modemId = radioProtocol.modemId;
428     protocol.status = static_cast<HDI::Ril::V1_1::RadioProtocolStatus>(radioProtocol.status);
429     return Request(TELEPHONY_LOG_FUNC_NAME, response, &HDI::Ril::V1_1::IRil::SetRadioProtocol, protocol);
430 }
431 
SimOpenLogicalChannel(std::string appID,int32_t p2,const AppExecFwk::InnerEvent::Pointer & response)432 int32_t TelRilSim::SimOpenLogicalChannel(std::string appID, int32_t p2, const AppExecFwk::InnerEvent::Pointer &response)
433 {
434     return Request(TELEPHONY_LOG_FUNC_NAME, response, &HDI::Ril::V1_1::IRil::SimOpenLogicalChannel, appID, p2);
435 }
436 
SimCloseLogicalChannel(int32_t channelId,const AppExecFwk::InnerEvent::Pointer & response)437 int32_t TelRilSim::SimCloseLogicalChannel(int32_t channelId, const AppExecFwk::InnerEvent::Pointer &response)
438 {
439     return Request(TELEPHONY_LOG_FUNC_NAME, response, &HDI::Ril::V1_1::IRil::SimCloseLogicalChannel, channelId);
440 }
441 
SimTransmitApduLogicalChannel(const ApduSimIORequestInfo & reqInfo,const AppExecFwk::InnerEvent::Pointer & response)442 int32_t TelRilSim::SimTransmitApduLogicalChannel(
443     const ApduSimIORequestInfo &reqInfo, const AppExecFwk::InnerEvent::Pointer &response)
444 {
445     OHOS::HDI::Ril::V1_1::ApduSimIORequestInfo ApduRequestInfo;
446     BuildApduRequestInfo(ApduRequestInfo, reqInfo);
447     return Request(
448         TELEPHONY_LOG_FUNC_NAME, response, &HDI::Ril::V1_1::IRil::SimTransmitApduLogicalChannel, ApduRequestInfo);
449 }
450 
SimTransmitApduBasicChannel(const ApduSimIORequestInfo & reqInfo,const AppExecFwk::InnerEvent::Pointer & response)451 int32_t TelRilSim::SimTransmitApduBasicChannel(
452     const ApduSimIORequestInfo &reqInfo, const AppExecFwk::InnerEvent::Pointer &response)
453 {
454     OHOS::HDI::Ril::V1_1::ApduSimIORequestInfo ApduRequestInfo;
455     BuildApduRequestInfo(ApduRequestInfo, reqInfo);
456     return Request(
457         TELEPHONY_LOG_FUNC_NAME, response, &HDI::Ril::V1_1::IRil::SimTransmitApduBasicChannel, ApduRequestInfo);
458 }
459 
SimAuthentication(const SimAuthenticationRequestInfo & reqInfo,const AppExecFwk::InnerEvent::Pointer & response)460 int32_t TelRilSim::SimAuthentication(
461     const SimAuthenticationRequestInfo &reqInfo, const AppExecFwk::InnerEvent::Pointer &response)
462 {
463     OHOS::HDI::Ril::V1_1::SimAuthenticationRequestInfo simAuthInfo;
464     simAuthInfo.serial = reqInfo.serial;
465     simAuthInfo.aid = reqInfo.aid;
466     simAuthInfo.authData = reqInfo.authData;
467     return Request(TELEPHONY_LOG_FUNC_NAME, response, &HDI::Ril::V1_1::IRil::SimAuthentication, simAuthInfo);
468 }
469 
UnlockSimLock(int32_t lockType,std::string password,const AppExecFwk::InnerEvent::Pointer & response)470 int32_t TelRilSim::UnlockSimLock(
471     int32_t lockType, std::string password, const AppExecFwk::InnerEvent::Pointer &response)
472 {
473     return Request(TELEPHONY_LOG_FUNC_NAME, response, &HDI::Ril::V1_1::IRil::UnlockSimLock, lockType, password);
474 }
475 
SendSimMatchedOperatorInfo(const NcfgOperatorInfo & reqInfo,const AppExecFwk::InnerEvent::Pointer & response)476 int32_t TelRilSim::SendSimMatchedOperatorInfo(
477     const NcfgOperatorInfo &reqInfo, const AppExecFwk::InnerEvent::Pointer &response)
478 {
479     OHOS::HDI::Ril::V1_2::NcfgOperatorInfo ncfgOperatorInfo;
480     ncfgOperatorInfo.operName = reqInfo.operName;
481     ncfgOperatorInfo.operKey = reqInfo.operKey;
482     ncfgOperatorInfo.state = reqInfo.state;
483     ncfgOperatorInfo.reserve = reqInfo.reserve;
484     return Request(
485         TELEPHONY_LOG_FUNC_NAME, response, &HDI::Ril::V1_2::IRil::SendSimMatchedOperatorInfo, ncfgOperatorInfo);
486 }
487 
BuildIccIoResult(std::shared_ptr<IccIoResultInfo> iccIoResult,const HDI::Ril::V1_1::IccIoResultInfo & result)488 void TelRilSim::BuildIccIoResult(
489     std::shared_ptr<IccIoResultInfo> iccIoResult, const HDI::Ril::V1_1::IccIoResultInfo &result)
490 {
491     if (iccIoResult == nullptr) {
492         TELEPHONY_LOGE("BuildIccIoResult iccIoResult is nullptr");
493         return;
494     }
495     iccIoResult->response = result.response;
496     iccIoResult->sw1 = result.sw1;
497     iccIoResult->sw2 = result.sw2;
498 }
499 
BuildCardStatusInfo(std::shared_ptr<CardStatusInfo> cardStatusInfo,const HDI::Ril::V1_1::CardStatusInfo & result)500 void TelRilSim::BuildCardStatusInfo(
501     std::shared_ptr<CardStatusInfo> cardStatusInfo, const HDI::Ril::V1_1::CardStatusInfo &result)
502 {
503     if (cardStatusInfo == nullptr) {
504         TELEPHONY_LOGE("BuildCardStatusInfo cardStatusInfo is nullptr");
505         return;
506     }
507     cardStatusInfo->index = result.index;
508     cardStatusInfo->simType = result.simType;
509     cardStatusInfo->simState = result.simState;
510     TELEPHONY_LOGD("cardStatusInfo: index:%{public}d, simType:%{public}d, simState:%{public}d",
511         result.index, result.simType, result.simState);
512 }
513 
BuildSimCardStatusInfo(std::shared_ptr<SimCardStatusInfo> simCardStatusInfo,const HDI::Ril::V1_3::SimCardStatusInfo & result)514 void TelRilSim::BuildSimCardStatusInfo(std::shared_ptr<SimCardStatusInfo> simCardStatusInfo,
515     const HDI::Ril::V1_3::SimCardStatusInfo &result)
516 {
517     if (simCardStatusInfo == nullptr) {
518         TELEPHONY_LOGE("BuildSimCardStatusInfo simCardStatusInfo is nullptr");
519         return;
520     }
521     simCardStatusInfo->index = result.index;
522     simCardStatusInfo->simType = result.simType;
523     simCardStatusInfo->simState = result.simState;
524     simCardStatusInfo->iccid = result.iccid;
525     TELEPHONY_LOGD("simCardStatusInfo: index:%{public}d, simType:%{public}d, simState:%{public}d",
526         result.index, result.simType, result.simState);
527 }
528 
BuildLockStatusResp(std::shared_ptr<LockStatusResp> lockStatusResp,const HDI::Ril::V1_1::LockStatusResp & lockStatus)529 void TelRilSim::BuildLockStatusResp(
530     std::shared_ptr<LockStatusResp> lockStatusResp, const HDI::Ril::V1_1::LockStatusResp &lockStatus)
531 {
532     if (lockStatusResp == nullptr) {
533         TELEPHONY_LOGE("BuildLockStatusResp lockStatusResp is nullptr");
534         return;
535     }
536     lockStatusResp->result = lockStatus.result;
537     lockStatusResp->remain = lockStatus.remain;
538 }
539 
BuildRadioProtocol(std::shared_ptr<RadioProtocol> protocol,const HDI::Ril::V1_1::RadioProtocol & radioProtocol)540 void TelRilSim::BuildRadioProtocol(
541     std::shared_ptr<RadioProtocol> protocol, const HDI::Ril::V1_1::RadioProtocol &radioProtocol)
542 {
543     if (protocol == nullptr) {
544         TELEPHONY_LOGE("BuildRadioProtocol protocol is nullptr");
545         return;
546     }
547     protocol->slotId = radioProtocol.slotId;
548     protocol->sessionId = radioProtocol.sessionId;
549     protocol->phase = static_cast<RadioProtocolPhase>(radioProtocol.phase);
550     protocol->technology = radioProtocol.technology;
551     protocol->modemId = radioProtocol.modemId;
552     protocol->status = static_cast<RadioProtocolStatus>(radioProtocol.status);
553 }
554 
BuildOpenLogicalChannelResp(std::shared_ptr<OpenLogicalChannelResponse> openLogicalChannelResp,const HDI::Ril::V1_1::OpenLogicalChannelResponse & pOpenLogicalChannelResponse)555 void TelRilSim::BuildOpenLogicalChannelResp(std::shared_ptr<OpenLogicalChannelResponse> openLogicalChannelResp,
556     const HDI::Ril::V1_1::OpenLogicalChannelResponse &pOpenLogicalChannelResponse)
557 {
558     if (openLogicalChannelResp == nullptr) {
559         TELEPHONY_LOGE("BuildOpenLogicalChannelResp openLogicalChannelResp is nullptr");
560         return;
561     }
562     openLogicalChannelResp->sw1 = pOpenLogicalChannelResponse.sw1;
563     openLogicalChannelResp->sw2 = pOpenLogicalChannelResponse.sw2;
564     openLogicalChannelResp->channelId = pOpenLogicalChannelResponse.channelId;
565     openLogicalChannelResp->response = pOpenLogicalChannelResponse.response;
566 }
567 
BuildApduRequestInfo(OHOS::HDI::Ril::V1_1::ApduSimIORequestInfo & ApduRequestInfo,const ApduSimIORequestInfo & reqInfo)568 void TelRilSim::BuildApduRequestInfo(
569     OHOS::HDI::Ril::V1_1::ApduSimIORequestInfo &ApduRequestInfo, const ApduSimIORequestInfo &reqInfo)
570 {
571     ApduRequestInfo.channelId = reqInfo.channelId;
572     ApduRequestInfo.type = reqInfo.type;
573     ApduRequestInfo.instruction = reqInfo.instruction;
574     ApduRequestInfo.p1 = reqInfo.p1;
575     ApduRequestInfo.p2 = reqInfo.p2;
576     ApduRequestInfo.p3 = reqInfo.p3;
577     ApduRequestInfo.data = reqInfo.data;
578 }
579 
ResponseIccIo(const HDI::Ril::V1_1::RilRadioResponseInfo & responseInfo,const HDI::Ril::V1_1::IccIoResultInfo & result)580 int32_t TelRilSim::ResponseIccIo(
581     const HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const HDI::Ril::V1_1::IccIoResultInfo &result)
582 {
583     std::shared_ptr<IccIoResultInfo> iccIoResult = std::make_shared<IccIoResultInfo>();
584     BuildIccIoResult(iccIoResult, result);
585     const struct RadioResponseInfo radioResponseInfo = BuildHRilRadioResponseInfo(responseInfo);
586     TELEPHONY_LOGI("radioResponseInfo.serial:%{public}d,radioResponseInfo.error:%{public}d", radioResponseInfo.serial,
587         radioResponseInfo.error);
588     std::shared_ptr<TelRilRequest> telRilRequest = FindTelRilRequest(radioResponseInfo);
589     if (telRilRequest == nullptr || telRilRequest->pointer_ == nullptr) {
590         TELEPHONY_LOGE("ERROR: ResponseIccIo telRilRequest == nullptr || telRilRequest->pointer_ == nullptr");
591         return TELEPHONY_ERR_LOCAL_PTR_NULL;
592     }
593     if (radioResponseInfo.error != ErrType::NONE) {
594         return ErrorIccIoResponse(telRilRequest, radioResponseInfo);
595     }
596     return ProcessIccIoInfo(telRilRequest, iccIoResult);
597 }
598 } // namespace Telephony
599 } // namespace OHOS
600