111fccf17Sopenharmony_ci/*
211fccf17Sopenharmony_ci * Copyright (C) 2021 Huawei Device Co., Ltd.
311fccf17Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
411fccf17Sopenharmony_ci * you may not use this file except in compliance with the License.
511fccf17Sopenharmony_ci * You may obtain a copy of the License at
611fccf17Sopenharmony_ci *
711fccf17Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
811fccf17Sopenharmony_ci *
911fccf17Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1011fccf17Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1111fccf17Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1211fccf17Sopenharmony_ci * See the License for the specific language governing permissions and
1311fccf17Sopenharmony_ci * limitations under the License.
1411fccf17Sopenharmony_ci */
1511fccf17Sopenharmony_ci
1611fccf17Sopenharmony_ci#include "hril_sim.h"
1711fccf17Sopenharmony_ci
1811fccf17Sopenharmony_ci#include "hril_notification.h"
1911fccf17Sopenharmony_ci#include "hril_request.h"
2011fccf17Sopenharmony_cinamespace OHOS {
2111fccf17Sopenharmony_cinamespace Telephony {
2211fccf17Sopenharmony_ciHRilSim::HRilSim(int32_t slotId) : HRilBase(slotId)
2311fccf17Sopenharmony_ci{
2411fccf17Sopenharmony_ci    AddNotificationHandlerToMap();
2511fccf17Sopenharmony_ci    AddBasicHandlerToMap();
2611fccf17Sopenharmony_ci    AddSimLockHandlerToMap();
2711fccf17Sopenharmony_ci    AddStkHandlerToMap();
2811fccf17Sopenharmony_ci}
2911fccf17Sopenharmony_ci
3011fccf17Sopenharmony_cibool HRilSim::IsSimRespOrNotify(uint32_t code)
3111fccf17Sopenharmony_ci{
3211fccf17Sopenharmony_ci    return IsSimResponse(code) || IsSimNotification(code);
3311fccf17Sopenharmony_ci}
3411fccf17Sopenharmony_ci
3511fccf17Sopenharmony_civoid HRilSim::RegisterSimFuncs(const HRilSimReq *simFuncs)
3611fccf17Sopenharmony_ci{
3711fccf17Sopenharmony_ci    simFuncs_ = simFuncs;
3811fccf17Sopenharmony_ci}
3911fccf17Sopenharmony_ci
4011fccf17Sopenharmony_civoid HRilSim::AddBasicHandlerToMap()
4111fccf17Sopenharmony_ci{
4211fccf17Sopenharmony_ci    // response
4311fccf17Sopenharmony_ci    respMemberFuncMap_[HREQ_SIM_GET_SIM_IO] =
4411fccf17Sopenharmony_ci        [this](int32_t requestNum, HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response,
4511fccf17Sopenharmony_ci        size_t responseLen) { return GetSimIOResponse(requestNum, responseInfo, response, responseLen); };
4611fccf17Sopenharmony_ci    respMemberFuncMap_[HREQ_SIM_GET_SIM_STATUS] =
4711fccf17Sopenharmony_ci        [this](int32_t requestNum, HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response,
4811fccf17Sopenharmony_ci        size_t responseLen) { return GetSimCardStatusResponse(requestNum, responseInfo, response, responseLen); };
4911fccf17Sopenharmony_ci    respMemberFuncMap_[HREQ_SIM_GET_IMSI] =
5011fccf17Sopenharmony_ci        [this](int32_t requestNum, HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response,
5111fccf17Sopenharmony_ci        size_t responseLen) { return GetImsiResponse(requestNum, responseInfo, response, responseLen); };
5211fccf17Sopenharmony_ci    respMemberFuncMap_[HREQ_SIM_SET_ACTIVE_SIM] =
5311fccf17Sopenharmony_ci        [this](int32_t requestNum, HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response,
5411fccf17Sopenharmony_ci        size_t responseLen) { return SetActiveSimResponse(requestNum, responseInfo, response, responseLen); };
5511fccf17Sopenharmony_ci    respMemberFuncMap_[HREQ_SIM_GET_RADIO_PROTOCOL] =
5611fccf17Sopenharmony_ci        [this](int32_t requestNum, HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response,
5711fccf17Sopenharmony_ci        size_t responseLen) { return GetRadioProtocolResponse(requestNum, responseInfo, response, responseLen); };
5811fccf17Sopenharmony_ci    respMemberFuncMap_[HREQ_SIM_SET_RADIO_PROTOCOL] =
5911fccf17Sopenharmony_ci        [this](int32_t requestNum, HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response,
6011fccf17Sopenharmony_ci        size_t responseLen) { return SetRadioProtocolResponse(requestNum, responseInfo, response, responseLen); };
6111fccf17Sopenharmony_ci    respMemberFuncMap_[HREQ_SIM_OPEN_LOGICAL_CHANNEL] =
6211fccf17Sopenharmony_ci        [this](int32_t requestNum, HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response,
6311fccf17Sopenharmony_ci        size_t responseLen) { return SimOpenLogicalChannelResponse(requestNum, responseInfo, response, responseLen); };
6411fccf17Sopenharmony_ci    respMemberFuncMap_[HREQ_SIM_CLOSE_LOGICAL_CHANNEL] =
6511fccf17Sopenharmony_ci        [this](int32_t requestNum, HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response,
6611fccf17Sopenharmony_ci        size_t responseLen) { return SimCloseLogicalChannelResponse(requestNum, responseInfo, response, responseLen); };
6711fccf17Sopenharmony_ci    respMemberFuncMap_[HREQ_SIM_TRANSMIT_APDU_LOGICAL_CHANNEL] = [this](int32_t requestNum,
6811fccf17Sopenharmony_ci        HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response, size_t responseLen) {
6911fccf17Sopenharmony_ci        return SimTransmitApduLogicalChannelResponse(requestNum, responseInfo, response, responseLen);
7011fccf17Sopenharmony_ci    };
7111fccf17Sopenharmony_ci    respMemberFuncMap_[HREQ_SIM_TRANSMIT_APDU_BASIC_CHANNEL] = [this](int32_t requestNum,
7211fccf17Sopenharmony_ci        HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response, size_t responseLen) {
7311fccf17Sopenharmony_ci        return SimTransmitApduBasicChannelResponse(requestNum, responseInfo, response, responseLen);
7411fccf17Sopenharmony_ci    };
7511fccf17Sopenharmony_ci    respMemberFuncMap_[HREQ_SIM_SEND_NCFG_OPER_INFO] = [this](int32_t requestNum,
7611fccf17Sopenharmony_ci        HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response, size_t responseLen) {
7711fccf17Sopenharmony_ci        return SendSimMatchedOperatorInfoResponse(requestNum, responseInfo, response, responseLen);
7811fccf17Sopenharmony_ci    };
7911fccf17Sopenharmony_ci}
8011fccf17Sopenharmony_ci
8111fccf17Sopenharmony_civoid HRilSim::AddSimLockHandlerToMap()
8211fccf17Sopenharmony_ci{
8311fccf17Sopenharmony_ci    respMemberFuncMap_[HREQ_SIM_GET_SIM_LOCK_STATUS] =
8411fccf17Sopenharmony_ci        [this](int32_t requestNum, HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response,
8511fccf17Sopenharmony_ci        size_t responseLen) { return GetSimLockStatusResponse(requestNum, responseInfo, response, responseLen); };
8611fccf17Sopenharmony_ci    respMemberFuncMap_[HREQ_SIM_SET_SIM_LOCK] =
8711fccf17Sopenharmony_ci        [this](int32_t requestNum, HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response,
8811fccf17Sopenharmony_ci        size_t responseLen) { return SetSimLockResponse(requestNum, responseInfo, response, responseLen); };
8911fccf17Sopenharmony_ci    respMemberFuncMap_[HREQ_SIM_CHANGE_SIM_PASSWORD] =
9011fccf17Sopenharmony_ci        [this](int32_t requestNum, HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response,
9111fccf17Sopenharmony_ci        size_t responseLen) { return ChangeSimPasswordResponse(requestNum, responseInfo, response, responseLen); };
9211fccf17Sopenharmony_ci    respMemberFuncMap_[HREQ_SIM_UNLOCK_PIN] =
9311fccf17Sopenharmony_ci        [this](int32_t requestNum, HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response,
9411fccf17Sopenharmony_ci        size_t responseLen) { return UnlockPinResponse(requestNum, responseInfo, response, responseLen); };
9511fccf17Sopenharmony_ci    respMemberFuncMap_[HREQ_SIM_UNLOCK_PUK] =
9611fccf17Sopenharmony_ci        [this](int32_t requestNum, HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response,
9711fccf17Sopenharmony_ci        size_t responseLen) { return UnlockPukResponse(requestNum, responseInfo, response, responseLen); };
9811fccf17Sopenharmony_ci    respMemberFuncMap_[HREQ_SIM_UNLOCK_PIN2] =
9911fccf17Sopenharmony_ci        [this](int32_t requestNum, HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response,
10011fccf17Sopenharmony_ci        size_t responseLen) { return UnlockPin2Response(requestNum, responseInfo, response, responseLen); };
10111fccf17Sopenharmony_ci    respMemberFuncMap_[HREQ_SIM_UNLOCK_PUK2] =
10211fccf17Sopenharmony_ci        [this](int32_t requestNum, HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response,
10311fccf17Sopenharmony_ci        size_t responseLen) { return UnlockPuk2Response(requestNum, responseInfo, response, responseLen); };
10411fccf17Sopenharmony_ci    respMemberFuncMap_[HREQ_SIM_AUTHENTICATION] =
10511fccf17Sopenharmony_ci        [this](int32_t requestNum, HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response,
10611fccf17Sopenharmony_ci        size_t responseLen) { return SimAuthenticationResponse(requestNum, responseInfo, response, responseLen); };
10711fccf17Sopenharmony_ci    respMemberFuncMap_[HREQ_SIM_UNLOCK_SIM_LOCK] =
10811fccf17Sopenharmony_ci        [this](int32_t requestNum, HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response,
10911fccf17Sopenharmony_ci        size_t responseLen) { return UnlockSimLockResponse(requestNum, responseInfo, response, responseLen); };
11011fccf17Sopenharmony_ci}
11111fccf17Sopenharmony_ci
11211fccf17Sopenharmony_civoid HRilSim::AddStkHandlerToMap()
11311fccf17Sopenharmony_ci{
11411fccf17Sopenharmony_ci    respMemberFuncMap_[HREQ_SIM_STK_SEND_TERMINAL_RESPONSE] = [this](int32_t requestNum,
11511fccf17Sopenharmony_ci        HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response, size_t responseLen) {
11611fccf17Sopenharmony_ci        return SimStkSendTerminalResponseResponse(requestNum, responseInfo, response, responseLen);
11711fccf17Sopenharmony_ci    };
11811fccf17Sopenharmony_ci    respMemberFuncMap_[HREQ_SIM_STK_SEND_ENVELOPE] =
11911fccf17Sopenharmony_ci        [this](int32_t requestNum, HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response,
12011fccf17Sopenharmony_ci        size_t responseLen) { return SimStkSendEnvelopeResponse(requestNum, responseInfo, response, responseLen); };
12111fccf17Sopenharmony_ci    respMemberFuncMap_[HREQ_SIM_STK_SEND_CALL_SETUP_REQUEST_RESULT] = [this](int32_t requestNum,
12211fccf17Sopenharmony_ci        HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response, size_t responseLen) {
12311fccf17Sopenharmony_ci        return SimStkSendCallSetupRequestResultResponse(requestNum, responseInfo, response, responseLen);
12411fccf17Sopenharmony_ci    };
12511fccf17Sopenharmony_ci    respMemberFuncMap_[HREQ_SIM_STK_IS_READY] =
12611fccf17Sopenharmony_ci        [this](int32_t requestNum, HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response,
12711fccf17Sopenharmony_ci        size_t responseLen) { return SimStkIsReadyResponse(requestNum, responseInfo, response, responseLen); };
12811fccf17Sopenharmony_ci}
12911fccf17Sopenharmony_ci
13011fccf17Sopenharmony_civoid HRilSim::AddNotificationHandlerToMap()
13111fccf17Sopenharmony_ci{
13211fccf17Sopenharmony_ci    // Notification
13311fccf17Sopenharmony_ci    notiMemberFuncMap_[HNOTI_SIM_STATUS_CHANGED] =
13411fccf17Sopenharmony_ci        [this](int32_t notifyType, HRilErrNumber error, const void *response,
13511fccf17Sopenharmony_ci        size_t responseLen) { return SimStateUpdated(notifyType, error, response, responseLen); };
13611fccf17Sopenharmony_ci    notiMemberFuncMap_[HNOTI_SIM_STK_SESSION_END_NOTIFY] =
13711fccf17Sopenharmony_ci        [this](int32_t notifyType, HRilErrNumber error, const void *response,
13811fccf17Sopenharmony_ci        size_t responseLen) { return SimStkSessionEndNotify(notifyType, error, response, responseLen); };
13911fccf17Sopenharmony_ci    notiMemberFuncMap_[HNOTI_SIM_STK_PROACTIVE_NOTIFY] =
14011fccf17Sopenharmony_ci        [this](int32_t notifyType, HRilErrNumber error, const void *response,
14111fccf17Sopenharmony_ci        size_t responseLen) { return SimStkProactiveNotify(notifyType, error, response, responseLen); };
14211fccf17Sopenharmony_ci    notiMemberFuncMap_[HNOTI_SIM_STK_ALPHA_NOTIFY] =
14311fccf17Sopenharmony_ci        [this](int32_t notifyType, HRilErrNumber error, const void *response,
14411fccf17Sopenharmony_ci        size_t responseLen) { return SimStkAlphaNotify(notifyType, error, response, responseLen); };
14511fccf17Sopenharmony_ci    notiMemberFuncMap_[HNOTI_SIM_STK_EVENT_NOTIFY] =
14611fccf17Sopenharmony_ci        [this](int32_t notifyType, HRilErrNumber error, const void *response,
14711fccf17Sopenharmony_ci        size_t responseLen) { return SimStkEventNotify(notifyType, error, response, responseLen); };
14811fccf17Sopenharmony_ci    notiMemberFuncMap_[HNOTI_SIM_STK_CALL_SETUP_NOTIFY] =
14911fccf17Sopenharmony_ci        [this](int32_t notifyType, HRilErrNumber error, const void *response,
15011fccf17Sopenharmony_ci        size_t responseLen) { return SimStkCallSetupNotify(notifyType, error, response, responseLen); };
15111fccf17Sopenharmony_ci    notiMemberFuncMap_[HNOTI_SIM_REFRESH_NOTIFY] =
15211fccf17Sopenharmony_ci        [this](int32_t notifyType, HRilErrNumber error, const void *response,
15311fccf17Sopenharmony_ci        size_t responseLen) { return SimRefreshNotify(notifyType, error, response, responseLen); };
15411fccf17Sopenharmony_ci    notiMemberFuncMap_[HNOTI_SIM_RADIO_PROTOCOL_UPDATED] =
15511fccf17Sopenharmony_ci        [this](int32_t notifyType, HRilErrNumber error, const void *response,
15611fccf17Sopenharmony_ci        size_t responseLen) { return SimRadioProtocolUpdated(notifyType, error, response, responseLen); };
15711fccf17Sopenharmony_ci}
15811fccf17Sopenharmony_ci
15911fccf17Sopenharmony_ciint32_t HRilSim::GetSimIO(int32_t serialId, const OHOS::HDI::Ril::V1_1::SimIoRequestInfo &simIO)
16011fccf17Sopenharmony_ci{
16111fccf17Sopenharmony_ci    std::unique_ptr<HRilSimIO> rilSimIO = std::make_unique<HRilSimIO>();
16211fccf17Sopenharmony_ci    CopyToHRilSimIO(rilSimIO, simIO);
16311fccf17Sopenharmony_ci    int32_t ret = RequestVendor(
16411fccf17Sopenharmony_ci        serialId, HREQ_SIM_GET_SIM_IO, simFuncs_, &HRilSimReq::GetSimIO, rilSimIO.get(), sizeof(*rilSimIO));
16511fccf17Sopenharmony_ci    SafeFrees(rilSimIO->data, rilSimIO->pathid, rilSimIO->pin2);
16611fccf17Sopenharmony_ci    return ret;
16711fccf17Sopenharmony_ci}
16811fccf17Sopenharmony_ci
16911fccf17Sopenharmony_ciint32_t HRilSim::GetSimStatus(int32_t serialId)
17011fccf17Sopenharmony_ci{
17111fccf17Sopenharmony_ci    return RequestVendor(serialId, HREQ_SIM_GET_SIM_STATUS, simFuncs_, &HRilSimReq::GetSimStatus);
17211fccf17Sopenharmony_ci}
17311fccf17Sopenharmony_ci
17411fccf17Sopenharmony_ciint32_t HRilSim::GetImsi(int32_t serialId)
17511fccf17Sopenharmony_ci{
17611fccf17Sopenharmony_ci    return RequestVendor(serialId, HREQ_SIM_GET_IMSI, simFuncs_, &HRilSimReq::GetSimImsi);
17711fccf17Sopenharmony_ci}
17811fccf17Sopenharmony_ci
17911fccf17Sopenharmony_ciint32_t HRilSim::GetSimLockStatus(int32_t serialId, const OHOS::HDI::Ril::V1_1::SimLockInfo &simLockInfo)
18011fccf17Sopenharmony_ci{
18111fccf17Sopenharmony_ci    std::unique_ptr<HRilSimClock> rilSimLock = std::make_unique<HRilSimClock>();
18211fccf17Sopenharmony_ci    CopyToHRilSimLock(rilSimLock, simLockInfo);
18311fccf17Sopenharmony_ci    int32_t ret = RequestVendor(serialId, HREQ_SIM_GET_SIM_LOCK_STATUS, simFuncs_, &HRilSimReq::GetSimLockStatus,
18411fccf17Sopenharmony_ci        rilSimLock.get(), sizeof(*rilSimLock));
18511fccf17Sopenharmony_ci    SafeFrees(rilSimLock->fac, rilSimLock->passwd);
18611fccf17Sopenharmony_ci    return ret;
18711fccf17Sopenharmony_ci}
18811fccf17Sopenharmony_ci
18911fccf17Sopenharmony_ciint32_t HRilSim::SetSimLock(int32_t serialId, const OHOS::HDI::Ril::V1_1::SimLockInfo &simLockInfo)
19011fccf17Sopenharmony_ci{
19111fccf17Sopenharmony_ci    std::unique_ptr<HRilSimClock> rilSimLock = std::make_unique<HRilSimClock>();
19211fccf17Sopenharmony_ci    CopyToHRilSimLock(rilSimLock, simLockInfo);
19311fccf17Sopenharmony_ci    int32_t ret = RequestVendor(
19411fccf17Sopenharmony_ci        serialId, HREQ_SIM_SET_SIM_LOCK, simFuncs_, &HRilSimReq::SetSimLock, rilSimLock.get(), sizeof(*rilSimLock));
19511fccf17Sopenharmony_ci    SafeFrees(rilSimLock->fac, rilSimLock->passwd);
19611fccf17Sopenharmony_ci    return ret;
19711fccf17Sopenharmony_ci}
19811fccf17Sopenharmony_ci
19911fccf17Sopenharmony_ciint32_t HRilSim::ChangeSimPassword(int32_t serialId, const OHOS::HDI::Ril::V1_1::SimPasswordInfo &simPassword)
20011fccf17Sopenharmony_ci{
20111fccf17Sopenharmony_ci    std::unique_ptr<HRilSimPassword> rilSimPassword = std::make_unique<HRilSimPassword>();
20211fccf17Sopenharmony_ci    CopyToHRilSimPassword(rilSimPassword, simPassword);
20311fccf17Sopenharmony_ci    int32_t ret = RequestVendor(serialId, HREQ_SIM_CHANGE_SIM_PASSWORD, simFuncs_, &HRilSimReq::ChangeSimPassword,
20411fccf17Sopenharmony_ci        rilSimPassword.get(), sizeof(*rilSimPassword));
20511fccf17Sopenharmony_ci    SafeFrees(rilSimPassword->fac, rilSimPassword->oldPassword, rilSimPassword->newPassword);
20611fccf17Sopenharmony_ci    return ret;
20711fccf17Sopenharmony_ci}
20811fccf17Sopenharmony_ci
20911fccf17Sopenharmony_ciint32_t HRilSim::UnlockPin(int32_t serialId, const std::string &pin)
21011fccf17Sopenharmony_ci{
21111fccf17Sopenharmony_ci    char *pinPoint = nullptr;
21211fccf17Sopenharmony_ci    CopyToCharPoint(&pinPoint, pin);
21311fccf17Sopenharmony_ci    int32_t ret = RequestVendor(serialId, HREQ_SIM_UNLOCK_PIN, simFuncs_, &HRilSimReq::UnlockPin, pinPoint);
21411fccf17Sopenharmony_ci    SafeFrees(pinPoint);
21511fccf17Sopenharmony_ci    return ret;
21611fccf17Sopenharmony_ci}
21711fccf17Sopenharmony_ci
21811fccf17Sopenharmony_ciint32_t HRilSim::UnlockPuk(int32_t serialId, const std::string &puk, const std::string &pin)
21911fccf17Sopenharmony_ci{
22011fccf17Sopenharmony_ci    char *pukPoint = nullptr;
22111fccf17Sopenharmony_ci    CopyToCharPoint(&pukPoint, puk);
22211fccf17Sopenharmony_ci    char *pinPoint = nullptr;
22311fccf17Sopenharmony_ci    CopyToCharPoint(&pinPoint, pin);
22411fccf17Sopenharmony_ci    int32_t ret = RequestVendor(serialId, HREQ_SIM_UNLOCK_PUK, simFuncs_, &HRilSimReq::UnlockPuk, pukPoint, pinPoint);
22511fccf17Sopenharmony_ci    SafeFrees(pukPoint, pinPoint);
22611fccf17Sopenharmony_ci    return ret;
22711fccf17Sopenharmony_ci}
22811fccf17Sopenharmony_ci
22911fccf17Sopenharmony_ciint32_t HRilSim::UnlockPin2(int32_t serialId, const std::string &pin2)
23011fccf17Sopenharmony_ci{
23111fccf17Sopenharmony_ci    char *pin2Point = nullptr;
23211fccf17Sopenharmony_ci    CopyToCharPoint(&pin2Point, pin2);
23311fccf17Sopenharmony_ci    int32_t ret = RequestVendor(serialId, HREQ_SIM_UNLOCK_PIN2, simFuncs_, &HRilSimReq::UnlockPin2, pin2Point);
23411fccf17Sopenharmony_ci    SafeFrees(pin2Point);
23511fccf17Sopenharmony_ci    return ret;
23611fccf17Sopenharmony_ci}
23711fccf17Sopenharmony_ci
23811fccf17Sopenharmony_ciint32_t HRilSim::UnlockPuk2(int32_t serialId, const std::string &puk2, const std::string &pin2)
23911fccf17Sopenharmony_ci{
24011fccf17Sopenharmony_ci    char *puk2Point = nullptr;
24111fccf17Sopenharmony_ci    CopyToCharPoint(&puk2Point, puk2);
24211fccf17Sopenharmony_ci    char *pin2Point = nullptr;
24311fccf17Sopenharmony_ci    CopyToCharPoint(&pin2Point, pin2);
24411fccf17Sopenharmony_ci    int32_t ret =
24511fccf17Sopenharmony_ci        RequestVendor(serialId, HREQ_SIM_UNLOCK_PUK2, simFuncs_, &HRilSimReq::UnlockPuk2, puk2Point, pin2Point);
24611fccf17Sopenharmony_ci    SafeFrees(puk2Point, pin2Point);
24711fccf17Sopenharmony_ci    return ret;
24811fccf17Sopenharmony_ci}
24911fccf17Sopenharmony_ci
25011fccf17Sopenharmony_ciint32_t HRilSim::SetActiveSim(int32_t serialId, int32_t index, int32_t enable)
25111fccf17Sopenharmony_ci{
25211fccf17Sopenharmony_ci    return RequestVendor(serialId, HREQ_SIM_SET_ACTIVE_SIM, simFuncs_, &HRilSimReq::SetActiveSim, index, enable);
25311fccf17Sopenharmony_ci}
25411fccf17Sopenharmony_ci
25511fccf17Sopenharmony_ciint32_t HRilSim::SimStkSendTerminalResponse(int32_t serialId, const std::string &strCmd)
25611fccf17Sopenharmony_ci{
25711fccf17Sopenharmony_ci    char *strCmdPoint = nullptr;
25811fccf17Sopenharmony_ci    CopyToCharPoint(&strCmdPoint, strCmd);
25911fccf17Sopenharmony_ci    int32_t ret = RequestVendor(
26011fccf17Sopenharmony_ci        serialId, HREQ_SIM_STK_SEND_TERMINAL_RESPONSE, simFuncs_, &HRilSimReq::SimStkSendTerminalResponse, strCmdPoint);
26111fccf17Sopenharmony_ci    SafeFrees(strCmdPoint);
26211fccf17Sopenharmony_ci    return ret;
26311fccf17Sopenharmony_ci}
26411fccf17Sopenharmony_ci
26511fccf17Sopenharmony_ciint32_t HRilSim::SimStkSendEnvelope(int32_t serialId, const std::string &strCmd)
26611fccf17Sopenharmony_ci{
26711fccf17Sopenharmony_ci    char *strCmdPoint = nullptr;
26811fccf17Sopenharmony_ci    CopyToCharPoint(&strCmdPoint, strCmd);
26911fccf17Sopenharmony_ci    int32_t ret =
27011fccf17Sopenharmony_ci        RequestVendor(serialId, HREQ_SIM_STK_SEND_ENVELOPE, simFuncs_, &HRilSimReq::SimStkSendEnvelope, strCmdPoint);
27111fccf17Sopenharmony_ci    SafeFrees(strCmdPoint);
27211fccf17Sopenharmony_ci    return ret;
27311fccf17Sopenharmony_ci}
27411fccf17Sopenharmony_ci
27511fccf17Sopenharmony_ciint32_t HRilSim::SimStkSendCallSetupRequestResult(int32_t serialId, int32_t accept)
27611fccf17Sopenharmony_ci{
27711fccf17Sopenharmony_ci    return RequestVendor(serialId, HREQ_SIM_STK_SEND_CALL_SETUP_REQUEST_RESULT, simFuncs_,
27811fccf17Sopenharmony_ci        &HRilSimReq::SimStkSendCallSetupRequestResult, accept);
27911fccf17Sopenharmony_ci}
28011fccf17Sopenharmony_ci
28111fccf17Sopenharmony_ciint32_t HRilSim::SimStkIsReady(int32_t serialId)
28211fccf17Sopenharmony_ci{
28311fccf17Sopenharmony_ci    return RequestVendor(serialId, HREQ_SIM_STK_IS_READY, simFuncs_, &HRilSimReq::SimStkIsReady);
28411fccf17Sopenharmony_ci}
28511fccf17Sopenharmony_ci
28611fccf17Sopenharmony_ciint32_t HRilSim::GetRadioProtocol(int32_t serialId)
28711fccf17Sopenharmony_ci{
28811fccf17Sopenharmony_ci    TELEPHONY_LOGI("HRilSim::GetRadioProtocol slotId:%{public}d", GetSlotId());
28911fccf17Sopenharmony_ci    return RequestVendor(serialId, HREQ_SIM_GET_RADIO_PROTOCOL, simFuncs_, &HRilSimReq::GetRadioProtocol);
29011fccf17Sopenharmony_ci}
29111fccf17Sopenharmony_ci
29211fccf17Sopenharmony_ciint32_t HRilSim::SetRadioProtocol(int32_t serialId, const HDI::Ril::V1_1::RadioProtocol &radioProtocol)
29311fccf17Sopenharmony_ci{
29411fccf17Sopenharmony_ci    HRilRadioProtocol hrilRadioProtocol = {};
29511fccf17Sopenharmony_ci    hrilRadioProtocol.sessionId = radioProtocol.sessionId;
29611fccf17Sopenharmony_ci    hrilRadioProtocol.phase = static_cast<HRilRadioProtocolPhase>(radioProtocol.phase);
29711fccf17Sopenharmony_ci    hrilRadioProtocol.technology = radioProtocol.technology;
29811fccf17Sopenharmony_ci    hrilRadioProtocol.modemId = radioProtocol.modemId;
29911fccf17Sopenharmony_ci    hrilRadioProtocol.status = static_cast<HRilRadioProtocolStatus>(radioProtocol.status);
30011fccf17Sopenharmony_ci    TELEPHONY_LOGI("HRilSim::SetRadioProtocol slotId:%{public}d, serialId:%{public}d"
30111fccf17Sopenharmony_ci        "sessionId:%{public}d, phase:%{public}d, technology:%{public}d, modemId:%{public}d, status:%{public}d",
30211fccf17Sopenharmony_ci        GetSlotId(), serialId, hrilRadioProtocol.sessionId, hrilRadioProtocol.phase, hrilRadioProtocol.technology,
30311fccf17Sopenharmony_ci        hrilRadioProtocol.modemId, hrilRadioProtocol.status);
30411fccf17Sopenharmony_ci    return RequestVendor(serialId, HREQ_SIM_SET_RADIO_PROTOCOL, simFuncs_,
30511fccf17Sopenharmony_ci        &HRilSimReq::SetRadioProtocol, &hrilRadioProtocol);
30611fccf17Sopenharmony_ci}
30711fccf17Sopenharmony_ci
30811fccf17Sopenharmony_ciint32_t HRilSim::SimOpenLogicalChannel(int32_t serialId, const std::string &appID, int32_t p2)
30911fccf17Sopenharmony_ci{
31011fccf17Sopenharmony_ci    char *appIDPoint = nullptr;
31111fccf17Sopenharmony_ci    CopyToCharPoint(&appIDPoint, appID);
31211fccf17Sopenharmony_ci    int32_t ret = RequestVendor(
31311fccf17Sopenharmony_ci        serialId, HREQ_SIM_OPEN_LOGICAL_CHANNEL, simFuncs_, &HRilSimReq::SimOpenLogicalChannel, appIDPoint, p2);
31411fccf17Sopenharmony_ci    SafeFrees(appIDPoint);
31511fccf17Sopenharmony_ci    return ret;
31611fccf17Sopenharmony_ci}
31711fccf17Sopenharmony_ci
31811fccf17Sopenharmony_ciint32_t HRilSim::SimCloseLogicalChannel(int32_t serialId, int32_t channelId)
31911fccf17Sopenharmony_ci{
32011fccf17Sopenharmony_ci    return RequestVendor(
32111fccf17Sopenharmony_ci        serialId, HREQ_SIM_CLOSE_LOGICAL_CHANNEL, simFuncs_, &HRilSimReq::SimCloseLogicalChannel, channelId);
32211fccf17Sopenharmony_ci}
32311fccf17Sopenharmony_ci
32411fccf17Sopenharmony_ciint32_t HRilSim::SimTransmitApduLogicalChannel(
32511fccf17Sopenharmony_ci    int32_t serialId, const OHOS::HDI::Ril::V1_1::ApduSimIORequestInfo &apduSimIO)
32611fccf17Sopenharmony_ci{
32711fccf17Sopenharmony_ci    std::unique_ptr<HRilApduSimIO> rilApduSimIO = std::make_unique<HRilApduSimIO>();
32811fccf17Sopenharmony_ci    CopyToHRilApduSimIO(rilApduSimIO, apduSimIO);
32911fccf17Sopenharmony_ci    int32_t ret = RequestVendor(serialId, HREQ_SIM_TRANSMIT_APDU_LOGICAL_CHANNEL, simFuncs_,
33011fccf17Sopenharmony_ci        &HRilSimReq::SimTransmitApduLogicalChannel, rilApduSimIO.get(), sizeof(*rilApduSimIO));
33111fccf17Sopenharmony_ci    SafeFrees(rilApduSimIO->data);
33211fccf17Sopenharmony_ci    return ret;
33311fccf17Sopenharmony_ci}
33411fccf17Sopenharmony_ci
33511fccf17Sopenharmony_ciint32_t HRilSim::SimTransmitApduBasicChannel(
33611fccf17Sopenharmony_ci    int32_t serialId, const OHOS::HDI::Ril::V1_1::ApduSimIORequestInfo &apduSimIO)
33711fccf17Sopenharmony_ci{
33811fccf17Sopenharmony_ci    std::unique_ptr<HRilApduSimIO> rilApduSimIO = std::make_unique<HRilApduSimIO>();
33911fccf17Sopenharmony_ci    CopyToHRilApduSimIO(rilApduSimIO, apduSimIO);
34011fccf17Sopenharmony_ci    int32_t ret = RequestVendor(serialId, HREQ_SIM_TRANSMIT_APDU_BASIC_CHANNEL, simFuncs_,
34111fccf17Sopenharmony_ci        &HRilSimReq::SimTransmitApduBasicChannel, rilApduSimIO.get(), sizeof(*rilApduSimIO));
34211fccf17Sopenharmony_ci    SafeFrees(rilApduSimIO->data);
34311fccf17Sopenharmony_ci    return ret;
34411fccf17Sopenharmony_ci}
34511fccf17Sopenharmony_ci
34611fccf17Sopenharmony_ciint32_t HRilSim::SimAuthentication(
34711fccf17Sopenharmony_ci    int32_t serialId, const OHOS::HDI::Ril::V1_1::SimAuthenticationRequestInfo &simAuthInfo)
34811fccf17Sopenharmony_ci{
34911fccf17Sopenharmony_ci    std::unique_ptr<HRilSimAuthenticationRequestInfo> rilSimAuthInfo =
35011fccf17Sopenharmony_ci        std::make_unique<HRilSimAuthenticationRequestInfo>();
35111fccf17Sopenharmony_ci    CopyToHRilSimAuthentication(rilSimAuthInfo, simAuthInfo);
35211fccf17Sopenharmony_ci    int32_t ret = RequestVendor(serialId, HREQ_SIM_AUTHENTICATION, simFuncs_, &HRilSimReq::SimAuthentication,
35311fccf17Sopenharmony_ci        rilSimAuthInfo.get(), sizeof(*rilSimAuthInfo));
35411fccf17Sopenharmony_ci    SafeFrees(rilSimAuthInfo->aid, rilSimAuthInfo->data);
35511fccf17Sopenharmony_ci    return ret;
35611fccf17Sopenharmony_ci}
35711fccf17Sopenharmony_ci
35811fccf17Sopenharmony_ciint32_t HRilSim::UnlockSimLock(int32_t serialId, int32_t lockType, const std::string &key)
35911fccf17Sopenharmony_ci{
36011fccf17Sopenharmony_ci    char *keyPoint = nullptr;
36111fccf17Sopenharmony_ci    CopyToCharPoint(&keyPoint, key);
36211fccf17Sopenharmony_ci    int32_t ret =
36311fccf17Sopenharmony_ci        RequestVendor(serialId, HREQ_SIM_UNLOCK_SIM_LOCK, simFuncs_, &HRilSimReq::UnlockSimLock, lockType, keyPoint);
36411fccf17Sopenharmony_ci    SafeFrees(keyPoint);
36511fccf17Sopenharmony_ci    return ret;
36611fccf17Sopenharmony_ci}
36711fccf17Sopenharmony_ci
36811fccf17Sopenharmony_ciint32_t HRilSim::SendSimMatchedOperatorInfo(
36911fccf17Sopenharmony_ci    int32_t serialId, const OHOS::HDI::Ril::V1_2::NcfgOperatorInfo &ncfgOperatorInfo)
37011fccf17Sopenharmony_ci{
37111fccf17Sopenharmony_ci    std::unique_ptr<HRilNcfgOperatorInfo> rilNcfgOperatorInfo =
37211fccf17Sopenharmony_ci        std::make_unique<HRilNcfgOperatorInfo>();
37311fccf17Sopenharmony_ci    CopyToHRilNcfgOperatorInfo(rilNcfgOperatorInfo, ncfgOperatorInfo);
37411fccf17Sopenharmony_ci    int32_t ret = RequestVendor(serialId, HREQ_SIM_SEND_NCFG_OPER_INFO, simFuncs_,
37511fccf17Sopenharmony_ci        &HRilSimReq::SendSimMatchedOperatorInfo, rilNcfgOperatorInfo.get(), sizeof(*rilNcfgOperatorInfo));
37611fccf17Sopenharmony_ci    SafeFrees(rilNcfgOperatorInfo->operName, rilNcfgOperatorInfo->operKey, rilNcfgOperatorInfo->reserve);
37711fccf17Sopenharmony_ci    return ret;
37811fccf17Sopenharmony_ci}
37911fccf17Sopenharmony_ci
38011fccf17Sopenharmony_ciint32_t HRilSim::GetSimIOResponse(
38111fccf17Sopenharmony_ci    int32_t requestNum, HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response, size_t responseLen)
38211fccf17Sopenharmony_ci{
38311fccf17Sopenharmony_ci    HDI::Ril::V1_1::IccIoResultInfo result = {};
38411fccf17Sopenharmony_ci    int32_t ret = BuildSimIOResp(result, responseInfo, response, responseLen);
38511fccf17Sopenharmony_ci    if (ret != HRIL_ERR_SUCCESS) {
38611fccf17Sopenharmony_ci        return ret;
38711fccf17Sopenharmony_ci    }
38811fccf17Sopenharmony_ci    return Response(responseInfo, &HDI::Ril::V1_1::IRilCallback::GetSimIOResponse, result);
38911fccf17Sopenharmony_ci}
39011fccf17Sopenharmony_ci
39111fccf17Sopenharmony_ciint32_t HRilSim::GetSimCardStatusResponse(
39211fccf17Sopenharmony_ci    int32_t requestNum, HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response, size_t responseLen)
39311fccf17Sopenharmony_ci{
39411fccf17Sopenharmony_ci    HDI::Ril::V1_3::SimCardStatusInfo rilCardStatus = {};
39511fccf17Sopenharmony_ci    if ((response == nullptr && responseLen != 0) ||
39611fccf17Sopenharmony_ci        (response != nullptr && responseLen != sizeof(HRilCardState))) {
39711fccf17Sopenharmony_ci        TELEPHONY_LOGE("Invalid response: Vendor exception!");
39811fccf17Sopenharmony_ci        return HRIL_ERR_INVALID_PARAMETER;
39911fccf17Sopenharmony_ci    }
40011fccf17Sopenharmony_ci    if (response == nullptr && responseLen == 0) {
40111fccf17Sopenharmony_ci        TELEPHONY_LOGE("response is null");
40211fccf17Sopenharmony_ci        if (responseInfo.error == HDI::Ril::V1_1::RilErrType::NONE) {
40311fccf17Sopenharmony_ci            responseInfo.error = HDI::Ril::V1_1::RilErrType::RIL_ERR_INVALID_RESPONSE;
40411fccf17Sopenharmony_ci        }
40511fccf17Sopenharmony_ci        return Response(responseInfo, &HDI::Ril::V1_3::IRilCallback::GetSimCardStatusResponse, rilCardStatus);
40611fccf17Sopenharmony_ci    }
40711fccf17Sopenharmony_ci    const HRilCardState *curPtr = static_cast<const HRilCardState *>(response);
40811fccf17Sopenharmony_ci    if (curPtr != nullptr) {
40911fccf17Sopenharmony_ci        rilCardStatus.index = curPtr->index;
41011fccf17Sopenharmony_ci        rilCardStatus.simType = curPtr->simType;
41111fccf17Sopenharmony_ci        rilCardStatus.simState = curPtr->simState;
41211fccf17Sopenharmony_ci        rilCardStatus.iccid = (curPtr->iccid == nullptr) ? "" :  curPtr->iccid;
41311fccf17Sopenharmony_ci    }
41411fccf17Sopenharmony_ci    return Response(responseInfo, &HDI::Ril::V1_3::IRilCallback::GetSimCardStatusResponse, rilCardStatus);
41511fccf17Sopenharmony_ci}
41611fccf17Sopenharmony_ci
41711fccf17Sopenharmony_ciint32_t HRilSim::GetImsiResponse(
41811fccf17Sopenharmony_ci    int32_t requestNum, HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response, size_t responseLen)
41911fccf17Sopenharmony_ci{
42011fccf17Sopenharmony_ci    int32_t ret = CheckCharData(response, responseLen);
42111fccf17Sopenharmony_ci    if (ret != HRIL_ERR_SUCCESS) {
42211fccf17Sopenharmony_ci        return ret;
42311fccf17Sopenharmony_ci    }
42411fccf17Sopenharmony_ci    return Response(responseInfo, &HDI::Ril::V1_1::IRilCallback::GetImsiResponse, (const char *)response);
42511fccf17Sopenharmony_ci}
42611fccf17Sopenharmony_ci
42711fccf17Sopenharmony_ciint32_t HRilSim::GetSimLockStatusResponse(
42811fccf17Sopenharmony_ci    int32_t requestNum, HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response, size_t responseLen)
42911fccf17Sopenharmony_ci{
43011fccf17Sopenharmony_ci    int32_t simLockStatus = 0;
43111fccf17Sopenharmony_ci    if (response == nullptr || responseLen != sizeof(int32_t)) {
43211fccf17Sopenharmony_ci        TELEPHONY_LOGE("GetSimStatusResponse: Invalid response");
43311fccf17Sopenharmony_ci        if (responseInfo.error == HDI::Ril::V1_1::RilErrType::NONE) {
43411fccf17Sopenharmony_ci            responseInfo.error = HDI::Ril::V1_1::RilErrType::RIL_ERR_INVALID_RESPONSE;
43511fccf17Sopenharmony_ci        }
43611fccf17Sopenharmony_ci        return Response(responseInfo, &HDI::Ril::V1_1::IRilCallback::GetSimLockStatusResponse, simLockStatus);
43711fccf17Sopenharmony_ci    }
43811fccf17Sopenharmony_ci    simLockStatus = *(static_cast<const int32_t *>(response));
43911fccf17Sopenharmony_ci    return Response(responseInfo, &HDI::Ril::V1_1::IRilCallback::GetSimLockStatusResponse, simLockStatus);
44011fccf17Sopenharmony_ci}
44111fccf17Sopenharmony_ci
44211fccf17Sopenharmony_ciint32_t HRilSim::SetSimLockResponse(
44311fccf17Sopenharmony_ci    int32_t requestNum, HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response, size_t responseLen)
44411fccf17Sopenharmony_ci{
44511fccf17Sopenharmony_ci    HDI::Ril::V1_1::LockStatusResp result = {};
44611fccf17Sopenharmony_ci    ResponseLockStatus(result, responseInfo, response, responseLen);
44711fccf17Sopenharmony_ci    return Response(responseInfo, &HDI::Ril::V1_1::IRilCallback::SetSimLockResponse, result);
44811fccf17Sopenharmony_ci}
44911fccf17Sopenharmony_ci
45011fccf17Sopenharmony_ciint32_t HRilSim::ChangeSimPasswordResponse(
45111fccf17Sopenharmony_ci    int32_t requestNum, HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response, size_t responseLen)
45211fccf17Sopenharmony_ci{
45311fccf17Sopenharmony_ci    HDI::Ril::V1_1::LockStatusResp result = {};
45411fccf17Sopenharmony_ci    ResponseLockStatus(result, responseInfo, response, responseLen);
45511fccf17Sopenharmony_ci    return Response(responseInfo, &HDI::Ril::V1_1::IRilCallback::ChangeSimPasswordResponse, result);
45611fccf17Sopenharmony_ci}
45711fccf17Sopenharmony_ci
45811fccf17Sopenharmony_ciint32_t HRilSim::UnlockPinResponse(
45911fccf17Sopenharmony_ci    int32_t requestNum, HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response, size_t responseLen)
46011fccf17Sopenharmony_ci{
46111fccf17Sopenharmony_ci    HDI::Ril::V1_1::LockStatusResp result = {};
46211fccf17Sopenharmony_ci    ResponseLockStatus(result, responseInfo, response, responseLen);
46311fccf17Sopenharmony_ci    return Response(responseInfo, &HDI::Ril::V1_1::IRilCallback::UnlockPinResponse, result);
46411fccf17Sopenharmony_ci}
46511fccf17Sopenharmony_ci
46611fccf17Sopenharmony_ciint32_t HRilSim::UnlockPukResponse(
46711fccf17Sopenharmony_ci    int32_t requestNum, HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response, size_t responseLen)
46811fccf17Sopenharmony_ci{
46911fccf17Sopenharmony_ci    HDI::Ril::V1_1::LockStatusResp result = {};
47011fccf17Sopenharmony_ci    ResponseLockStatus(result, responseInfo, response, responseLen);
47111fccf17Sopenharmony_ci    return Response(responseInfo, &HDI::Ril::V1_1::IRilCallback::UnlockPukResponse, result);
47211fccf17Sopenharmony_ci}
47311fccf17Sopenharmony_ci
47411fccf17Sopenharmony_ciint32_t HRilSim::UnlockPin2Response(
47511fccf17Sopenharmony_ci    int32_t requestNum, HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response, size_t responseLen)
47611fccf17Sopenharmony_ci{
47711fccf17Sopenharmony_ci    HDI::Ril::V1_1::LockStatusResp result = {};
47811fccf17Sopenharmony_ci    ResponseLockStatus(result, responseInfo, response, responseLen);
47911fccf17Sopenharmony_ci    return Response(responseInfo, &HDI::Ril::V1_1::IRilCallback::UnlockPin2Response, result);
48011fccf17Sopenharmony_ci}
48111fccf17Sopenharmony_ci
48211fccf17Sopenharmony_ciint32_t HRilSim::UnlockPuk2Response(
48311fccf17Sopenharmony_ci    int32_t requestNum, HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response, size_t responseLen)
48411fccf17Sopenharmony_ci{
48511fccf17Sopenharmony_ci    HDI::Ril::V1_1::LockStatusResp result = {};
48611fccf17Sopenharmony_ci    ResponseLockStatus(result, responseInfo, response, responseLen);
48711fccf17Sopenharmony_ci    return Response(responseInfo, &HDI::Ril::V1_1::IRilCallback::UnlockPuk2Response, result);
48811fccf17Sopenharmony_ci}
48911fccf17Sopenharmony_ci
49011fccf17Sopenharmony_ciint32_t HRilSim::SetActiveSimResponse(
49111fccf17Sopenharmony_ci    int32_t requestNum, HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response, size_t responseLen)
49211fccf17Sopenharmony_ci{
49311fccf17Sopenharmony_ci    return Response(responseInfo, &HDI::Ril::V1_1::IRilCallback::SetActiveSimResponse);
49411fccf17Sopenharmony_ci}
49511fccf17Sopenharmony_ci
49611fccf17Sopenharmony_ciint32_t HRilSim::SimStkSendTerminalResponseResponse(
49711fccf17Sopenharmony_ci    int32_t requestNum, HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response, size_t responseLen)
49811fccf17Sopenharmony_ci{
49911fccf17Sopenharmony_ci    return Response(responseInfo, &HDI::Ril::V1_1::IRilCallback::SimStkSendTerminalResponseResponse);
50011fccf17Sopenharmony_ci}
50111fccf17Sopenharmony_ci
50211fccf17Sopenharmony_ciint32_t HRilSim::SimStkSendEnvelopeResponse(
50311fccf17Sopenharmony_ci    int32_t requestNum, HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response, size_t responseLen)
50411fccf17Sopenharmony_ci{
50511fccf17Sopenharmony_ci    return Response(responseInfo, &HDI::Ril::V1_1::IRilCallback::SimStkSendEnvelopeResponse);
50611fccf17Sopenharmony_ci}
50711fccf17Sopenharmony_ci
50811fccf17Sopenharmony_ciint32_t HRilSim::SimStkSendCallSetupRequestResultResponse(
50911fccf17Sopenharmony_ci    int32_t requestNum, HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response, size_t responseLen)
51011fccf17Sopenharmony_ci{
51111fccf17Sopenharmony_ci    return Response(responseInfo, &HDI::Ril::V1_1::IRilCallback::SimStkSendCallSetupRequestResultResponse);
51211fccf17Sopenharmony_ci}
51311fccf17Sopenharmony_ci
51411fccf17Sopenharmony_ciint32_t HRilSim::SimStkIsReadyResponse(
51511fccf17Sopenharmony_ci    int32_t requestNum, HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response, size_t responseLen)
51611fccf17Sopenharmony_ci{
51711fccf17Sopenharmony_ci    return Response(responseInfo, &HDI::Ril::V1_1::IRilCallback::SimStkIsReadyResponse);
51811fccf17Sopenharmony_ci}
51911fccf17Sopenharmony_ci
52011fccf17Sopenharmony_ciint32_t HRilSim::GetRadioProtocolResponse(
52111fccf17Sopenharmony_ci    int32_t requestNum, HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response, size_t responseLen)
52211fccf17Sopenharmony_ci{
52311fccf17Sopenharmony_ci    HDI::Ril::V1_1::RadioProtocol radioProtocol = {};
52411fccf17Sopenharmony_ci    if (response == nullptr || responseLen != sizeof(HRilRadioProtocol)) {
52511fccf17Sopenharmony_ci        TELEPHONY_LOGE("GetRadioProtocolResponse response is invalid");
52611fccf17Sopenharmony_ci        if (responseInfo.error == HDI::Ril::V1_1::RilErrType::NONE) {
52711fccf17Sopenharmony_ci            responseInfo.error = HDI::Ril::V1_1::RilErrType::RIL_ERR_INVALID_RESPONSE;
52811fccf17Sopenharmony_ci        }
52911fccf17Sopenharmony_ci    } else {
53011fccf17Sopenharmony_ci        BuildRadioProtocol(radioProtocol, response);
53111fccf17Sopenharmony_ci        TELEPHONY_LOGI("HRilSim::GetRadioProtocolResponse slotId:%{public}d, serial:%{public}d"
53211fccf17Sopenharmony_ci            "sessionId:%{public}d, phase:%{public}d, technology:%{public}d, modemId:%{public}d, status:%{public}d",
53311fccf17Sopenharmony_ci            GetSlotId(), responseInfo.serial, radioProtocol.sessionId, radioProtocol.phase, radioProtocol.technology,
53411fccf17Sopenharmony_ci            radioProtocol.modemId, radioProtocol.status);
53511fccf17Sopenharmony_ci    }
53611fccf17Sopenharmony_ci    return Response(responseInfo, &HDI::Ril::V1_1::IRilCallback::GetRadioProtocolResponse, radioProtocol);
53711fccf17Sopenharmony_ci}
53811fccf17Sopenharmony_ci
53911fccf17Sopenharmony_ciint32_t HRilSim::SetRadioProtocolResponse(
54011fccf17Sopenharmony_ci    int32_t requestNum, HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response, size_t responseLen)
54111fccf17Sopenharmony_ci{
54211fccf17Sopenharmony_ci    HDI::Ril::V1_1::RadioProtocol radioProtocol = {};
54311fccf17Sopenharmony_ci    if (response == nullptr || responseLen != sizeof(HRilRadioProtocol)) {
54411fccf17Sopenharmony_ci        TELEPHONY_LOGE("SetRadioProtocolResponse response is invalid");
54511fccf17Sopenharmony_ci        if (responseInfo.error == HDI::Ril::V1_1::RilErrType::NONE) {
54611fccf17Sopenharmony_ci            responseInfo.error = HDI::Ril::V1_1::RilErrType::RIL_ERR_INVALID_RESPONSE;
54711fccf17Sopenharmony_ci        }
54811fccf17Sopenharmony_ci    } else {
54911fccf17Sopenharmony_ci        BuildRadioProtocol(radioProtocol, response);
55011fccf17Sopenharmony_ci        TELEPHONY_LOGI("HRilSim::SetRadioProtocolResponse slotId:%{public}d, serial:%{public}d"
55111fccf17Sopenharmony_ci            "sessionId:%{public}d, phase:%{public}d, technology:%{public}d, modemId:%{public}d, status:%{public}d",
55211fccf17Sopenharmony_ci            GetSlotId(), responseInfo.serial, radioProtocol.sessionId, radioProtocol.phase, radioProtocol.technology,
55311fccf17Sopenharmony_ci            radioProtocol.modemId, radioProtocol.status);
55411fccf17Sopenharmony_ci    }
55511fccf17Sopenharmony_ci    return Response(responseInfo, &HDI::Ril::V1_1::IRilCallback::SetRadioProtocolResponse, radioProtocol);
55611fccf17Sopenharmony_ci}
55711fccf17Sopenharmony_ci
55811fccf17Sopenharmony_ciint32_t HRilSim::SimOpenLogicalChannelResponse(
55911fccf17Sopenharmony_ci    int32_t requestNum, HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response, size_t responseLen)
56011fccf17Sopenharmony_ci{
56111fccf17Sopenharmony_ci    HDI::Ril::V1_1::OpenLogicalChannelResponse pOpenLogicalChannelResponse = {};
56211fccf17Sopenharmony_ci    if (response == nullptr || responseLen != sizeof(HRilOpenLogicalChannelResponse)) {
56311fccf17Sopenharmony_ci        TELEPHONY_LOGE("Invalid response: response is nullptr");
56411fccf17Sopenharmony_ci        return HRIL_ERR_INVALID_PARAMETER;
56511fccf17Sopenharmony_ci    }
56611fccf17Sopenharmony_ci    const HRilOpenLogicalChannelResponse *pRilResponse = static_cast<const HRilOpenLogicalChannelResponse *>(response);
56711fccf17Sopenharmony_ci    pOpenLogicalChannelResponse.sw1 = pRilResponse->sw1;
56811fccf17Sopenharmony_ci    pOpenLogicalChannelResponse.sw2 = pRilResponse->sw2;
56911fccf17Sopenharmony_ci    pOpenLogicalChannelResponse.channelId = pRilResponse->channelId;
57011fccf17Sopenharmony_ci    pOpenLogicalChannelResponse.response = (pRilResponse->response == nullptr) ? "" :  pRilResponse->response;
57111fccf17Sopenharmony_ci    return Response(
57211fccf17Sopenharmony_ci        responseInfo, &HDI::Ril::V1_1::IRilCallback::SimOpenLogicalChannelResponse, pOpenLogicalChannelResponse);
57311fccf17Sopenharmony_ci}
57411fccf17Sopenharmony_ci
57511fccf17Sopenharmony_ciint32_t HRilSim::SimCloseLogicalChannelResponse(
57611fccf17Sopenharmony_ci    int32_t requestNum, HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response, size_t responseLen)
57711fccf17Sopenharmony_ci{
57811fccf17Sopenharmony_ci    return Response(responseInfo, &HDI::Ril::V1_1::IRilCallback::SimCloseLogicalChannelResponse);
57911fccf17Sopenharmony_ci}
58011fccf17Sopenharmony_ci
58111fccf17Sopenharmony_ciint32_t HRilSim::SimTransmitApduLogicalChannelResponse(
58211fccf17Sopenharmony_ci    int32_t requestNum, HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response, size_t responseLen)
58311fccf17Sopenharmony_ci{
58411fccf17Sopenharmony_ci    HDI::Ril::V1_1::IccIoResultInfo result = {};
58511fccf17Sopenharmony_ci    int32_t ret = BuildSimIOResp(result, responseInfo, response, responseLen);
58611fccf17Sopenharmony_ci    if (ret != HRIL_ERR_SUCCESS) {
58711fccf17Sopenharmony_ci        return ret;
58811fccf17Sopenharmony_ci    }
58911fccf17Sopenharmony_ci    return Response(responseInfo, &HDI::Ril::V1_1::IRilCallback::SimTransmitApduLogicalChannelResponse, result);
59011fccf17Sopenharmony_ci}
59111fccf17Sopenharmony_ci
59211fccf17Sopenharmony_ciint32_t HRilSim::SimTransmitApduBasicChannelResponse(
59311fccf17Sopenharmony_ci    int32_t requestNum, HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response, size_t responseLen)
59411fccf17Sopenharmony_ci{
59511fccf17Sopenharmony_ci    HDI::Ril::V1_1::IccIoResultInfo result = {};
59611fccf17Sopenharmony_ci    int32_t ret = BuildSimIOResp(result, responseInfo, response, responseLen);
59711fccf17Sopenharmony_ci    if (ret != HRIL_ERR_SUCCESS) {
59811fccf17Sopenharmony_ci        return ret;
59911fccf17Sopenharmony_ci    }
60011fccf17Sopenharmony_ci    return Response(responseInfo, &HDI::Ril::V1_1::IRilCallback::SimTransmitApduBasicChannelResponse, result);
60111fccf17Sopenharmony_ci}
60211fccf17Sopenharmony_ci
60311fccf17Sopenharmony_ciint32_t HRilSim::SimAuthenticationResponse(
60411fccf17Sopenharmony_ci    int32_t requestNum, HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response, size_t responseLen)
60511fccf17Sopenharmony_ci{
60611fccf17Sopenharmony_ci    HDI::Ril::V1_1::IccIoResultInfo result = {};
60711fccf17Sopenharmony_ci    int32_t ret = BuildSimIOResp(result, responseInfo, response, responseLen);
60811fccf17Sopenharmony_ci    if (ret != HRIL_ERR_SUCCESS) {
60911fccf17Sopenharmony_ci        return ret;
61011fccf17Sopenharmony_ci    }
61111fccf17Sopenharmony_ci    return Response(responseInfo, &HDI::Ril::V1_1::IRilCallback::SimAuthenticationResponse, result);
61211fccf17Sopenharmony_ci}
61311fccf17Sopenharmony_ci
61411fccf17Sopenharmony_ciint32_t HRilSim::UnlockSimLockResponse(
61511fccf17Sopenharmony_ci    int32_t requestNum, HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response, size_t responseLen)
61611fccf17Sopenharmony_ci{
61711fccf17Sopenharmony_ci    HDI::Ril::V1_1::LockStatusResp result = {};
61811fccf17Sopenharmony_ci    ResponseLockStatus(result, responseInfo, response, responseLen);
61911fccf17Sopenharmony_ci    return Response(responseInfo, &HDI::Ril::V1_1::IRilCallback::UnlockSimLockResponse, result);
62011fccf17Sopenharmony_ci}
62111fccf17Sopenharmony_ci
62211fccf17Sopenharmony_ciHDI::Ril::V1_1::IccIoResultInfo HRilSim::ProcessIccIoResponse(
62311fccf17Sopenharmony_ci    HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response, size_t responseLen)
62411fccf17Sopenharmony_ci{
62511fccf17Sopenharmony_ci    HDI::Ril::V1_1::IccIoResultInfo result = {};
62611fccf17Sopenharmony_ci    if (response == nullptr || responseLen != sizeof(HRilSimIOResponse)) {
62711fccf17Sopenharmony_ci        if (responseInfo.error == HDI::Ril::V1_1::RilErrType::NONE) {
62811fccf17Sopenharmony_ci            responseInfo.error = HDI::Ril::V1_1::RilErrType::RIL_ERR_INVALID_RESPONSE;
62911fccf17Sopenharmony_ci        }
63011fccf17Sopenharmony_ci        result.response = std::string("");
63111fccf17Sopenharmony_ci        return result;
63211fccf17Sopenharmony_ci    }
63311fccf17Sopenharmony_ci    const HRilSimIOResponse *resp = static_cast<const HRilSimIOResponse *>(response);
63411fccf17Sopenharmony_ci    result.sw1 = resp->sw1;
63511fccf17Sopenharmony_ci    result.sw2 = resp->sw2;
63611fccf17Sopenharmony_ci    result.response = (resp->response == nullptr) ? "" : std::string(resp->response);
63711fccf17Sopenharmony_ci    return result;
63811fccf17Sopenharmony_ci}
63911fccf17Sopenharmony_ci
64011fccf17Sopenharmony_ciint32_t HRilSim::SendSimMatchedOperatorInfoResponse(
64111fccf17Sopenharmony_ci    int32_t requestNum, HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response, size_t responseLen)
64211fccf17Sopenharmony_ci{
64311fccf17Sopenharmony_ci    return Response(responseInfo, &HDI::Ril::V1_2::IRilCallback::SendSimMatchedOperatorInfoResponse);
64411fccf17Sopenharmony_ci}
64511fccf17Sopenharmony_ci
64611fccf17Sopenharmony_ciint32_t HRilSim::SimStateUpdated(
64711fccf17Sopenharmony_ci    int32_t notifyType, const HRilErrNumber error, const void *response, size_t responseLen)
64811fccf17Sopenharmony_ci{
64911fccf17Sopenharmony_ci    return Notify(notifyType, error, &HDI::Ril::V1_1::IRilCallback::SimStateUpdated);
65011fccf17Sopenharmony_ci}
65111fccf17Sopenharmony_ci
65211fccf17Sopenharmony_ciint32_t HRilSim::SimStkSessionEndNotify(
65311fccf17Sopenharmony_ci    int32_t notifyType, const HRilErrNumber error, const void *response, size_t responseLen)
65411fccf17Sopenharmony_ci{
65511fccf17Sopenharmony_ci    return Notify(notifyType, error, &HDI::Ril::V1_1::IRilCallback::SimStkSessionEndNotify);
65611fccf17Sopenharmony_ci}
65711fccf17Sopenharmony_ci
65811fccf17Sopenharmony_ciint32_t HRilSim::SimStkProactiveNotify(
65911fccf17Sopenharmony_ci    int32_t notifyType, const HRilErrNumber error, const void *response, size_t responseLen)
66011fccf17Sopenharmony_ci{
66111fccf17Sopenharmony_ci    int32_t ret = CheckCharData(response, responseLen);
66211fccf17Sopenharmony_ci    if (ret != HRIL_ERR_SUCCESS) {
66311fccf17Sopenharmony_ci        return ret;
66411fccf17Sopenharmony_ci    }
66511fccf17Sopenharmony_ci    return Notify(notifyType, error, &HDI::Ril::V1_1::IRilCallback::SimStkProactiveNotify, (const char *)response);
66611fccf17Sopenharmony_ci}
66711fccf17Sopenharmony_ci
66811fccf17Sopenharmony_ciint32_t HRilSim::SimStkAlphaNotify(
66911fccf17Sopenharmony_ci    int32_t notifyType, const HRilErrNumber error, const void *response, size_t responseLen)
67011fccf17Sopenharmony_ci{
67111fccf17Sopenharmony_ci    int32_t ret = CheckCharData(response, responseLen);
67211fccf17Sopenharmony_ci    if (ret != HRIL_ERR_SUCCESS) {
67311fccf17Sopenharmony_ci        return ret;
67411fccf17Sopenharmony_ci    }
67511fccf17Sopenharmony_ci    return Notify(notifyType, error, &HDI::Ril::V1_1::IRilCallback::SimStkAlphaNotify, (const char *)response);
67611fccf17Sopenharmony_ci}
67711fccf17Sopenharmony_ci
67811fccf17Sopenharmony_ciint32_t HRilSim::SimStkEventNotify(
67911fccf17Sopenharmony_ci    int32_t notifyType, const HRilErrNumber error, const void *response, size_t responseLen)
68011fccf17Sopenharmony_ci{
68111fccf17Sopenharmony_ci    int32_t ret = CheckCharData(response, responseLen);
68211fccf17Sopenharmony_ci    if (ret != HRIL_ERR_SUCCESS) {
68311fccf17Sopenharmony_ci        return ret;
68411fccf17Sopenharmony_ci    }
68511fccf17Sopenharmony_ci    return Notify(notifyType, error, &HDI::Ril::V1_1::IRilCallback::SimStkEventNotify, (const char *)response);
68611fccf17Sopenharmony_ci}
68711fccf17Sopenharmony_ci
68811fccf17Sopenharmony_ciint32_t HRilSim::SimStkCallSetupNotify(
68911fccf17Sopenharmony_ci    int32_t notifyType, const HRilErrNumber error, const void *response, size_t responseLen)
69011fccf17Sopenharmony_ci{
69111fccf17Sopenharmony_ci    return Notify(notifyType, error, &HDI::Ril::V1_1::IRilCallback::SimStkCallSetupNotify);
69211fccf17Sopenharmony_ci}
69311fccf17Sopenharmony_ci
69411fccf17Sopenharmony_ciint32_t HRilSim::SimRefreshNotify(
69511fccf17Sopenharmony_ci    int32_t notifyType, const HRilErrNumber error, const void *response, size_t responseLen)
69611fccf17Sopenharmony_ci{
69711fccf17Sopenharmony_ci    return Notify(notifyType, error, &HDI::Ril::V1_1::IRilCallback::SimRefreshNotify);
69811fccf17Sopenharmony_ci}
69911fccf17Sopenharmony_ci
70011fccf17Sopenharmony_ciint32_t HRilSim::SimRadioProtocolUpdated(
70111fccf17Sopenharmony_ci    int32_t notifyType, const HRilErrNumber error, const void *response, size_t responseLen)
70211fccf17Sopenharmony_ci{
70311fccf17Sopenharmony_ci    if (response == nullptr || responseLen != sizeof(HRilRadioProtocol)) {
70411fccf17Sopenharmony_ci        TELEPHONY_LOGE("SimRadioProtocolUpdated response is invalid");
70511fccf17Sopenharmony_ci        return HRIL_ERR_INVALID_PARAMETER;
70611fccf17Sopenharmony_ci    }
70711fccf17Sopenharmony_ci    HDI::Ril::V1_1::RadioProtocol radioProtocol = {};
70811fccf17Sopenharmony_ci    BuildRadioProtocol(radioProtocol, response);
70911fccf17Sopenharmony_ci    TELEPHONY_LOGI("SimRadioProtocolUpdated slotId:%{public}d, sessionId:%{public}d, phase:%{public}d, "
71011fccf17Sopenharmony_ci        "technology:%{public}d, modemId:%{public}d, status:%{public}d",
71111fccf17Sopenharmony_ci        radioProtocol.slotId, radioProtocol.sessionId, static_cast<int32_t>(radioProtocol.phase),
71211fccf17Sopenharmony_ci        radioProtocol.technology, radioProtocol.modemId, static_cast<int32_t>(radioProtocol.status));
71311fccf17Sopenharmony_ci    return Notify(notifyType, error, &HDI::Ril::V1_1::IRilCallback::SimRadioProtocolUpdated, radioProtocol);
71411fccf17Sopenharmony_ci}
71511fccf17Sopenharmony_ci
71611fccf17Sopenharmony_cibool HRilSim::IsSimResponse(uint32_t code)
71711fccf17Sopenharmony_ci{
71811fccf17Sopenharmony_ci    return ((code >= HREQ_SIM_BASE) && (code < HREQ_DATA_BASE));
71911fccf17Sopenharmony_ci}
72011fccf17Sopenharmony_ci
72111fccf17Sopenharmony_cibool HRilSim::IsSimNotification(uint32_t code)
72211fccf17Sopenharmony_ci{
72311fccf17Sopenharmony_ci    return ((code >= HNOTI_SIM_BASE) && (code < HNOTI_DATA_BASE));
72411fccf17Sopenharmony_ci}
72511fccf17Sopenharmony_ci
72611fccf17Sopenharmony_civoid HRilSim::CopyToHRilSimIO(std::unique_ptr<HRilSimIO> &rilSimIO, const OHOS::HDI::Ril::V1_1::SimIoRequestInfo &simIO)
72711fccf17Sopenharmony_ci{
72811fccf17Sopenharmony_ci    rilSimIO->command = simIO.command;
72911fccf17Sopenharmony_ci    rilSimIO->fileid = simIO.fileId;
73011fccf17Sopenharmony_ci    rilSimIO->p1 = simIO.p1;
73111fccf17Sopenharmony_ci    rilSimIO->p2 = simIO.p2;
73211fccf17Sopenharmony_ci    rilSimIO->p3 = simIO.p3;
73311fccf17Sopenharmony_ci    TELEPHONY_LOGD("CopyToHRilSimIO.data: %{public}zu, path: %{public}zu, pin2: %{public}zu", simIO.data.length(),
73411fccf17Sopenharmony_ci        simIO.path.length(), simIO.pin2.length());
73511fccf17Sopenharmony_ci    CopyToCharPoint(&(rilSimIO->data), simIO.data);
73611fccf17Sopenharmony_ci    CopyToCharPoint(&(rilSimIO->pathid), simIO.path);
73711fccf17Sopenharmony_ci    CopyToCharPoint(&(rilSimIO->pin2), simIO.pin2);
73811fccf17Sopenharmony_ci}
73911fccf17Sopenharmony_ci
74011fccf17Sopenharmony_civoid HRilSim::CopyToHRilSimLock(
74111fccf17Sopenharmony_ci    std::unique_ptr<HRilSimClock> &rilSimLock, const OHOS::HDI::Ril::V1_1::SimLockInfo &simLockInfo)
74211fccf17Sopenharmony_ci{
74311fccf17Sopenharmony_ci    rilSimLock->mode = simLockInfo.mode;
74411fccf17Sopenharmony_ci    rilSimLock->status = simLockInfo.status;
74511fccf17Sopenharmony_ci    rilSimLock->classx = simLockInfo.classx;
74611fccf17Sopenharmony_ci    CopyToCharPoint(&(rilSimLock->fac), simLockInfo.fac);
74711fccf17Sopenharmony_ci    CopyToCharPoint(&(rilSimLock->passwd), simLockInfo.passwd);
74811fccf17Sopenharmony_ci}
74911fccf17Sopenharmony_ci
75011fccf17Sopenharmony_civoid HRilSim::CopyToHRilSimPassword(
75111fccf17Sopenharmony_ci    std::unique_ptr<HRilSimPassword> &rilSimPassword, const OHOS::HDI::Ril::V1_1::SimPasswordInfo &simPassword)
75211fccf17Sopenharmony_ci{
75311fccf17Sopenharmony_ci    CopyToCharPoint(&(rilSimPassword->fac), simPassword.fac);
75411fccf17Sopenharmony_ci    CopyToCharPoint(&(rilSimPassword->oldPassword), simPassword.oldPassword);
75511fccf17Sopenharmony_ci    CopyToCharPoint(&(rilSimPassword->newPassword), simPassword.newPassword);
75611fccf17Sopenharmony_ci    rilSimPassword->passwordLength = simPassword.passwordLength;
75711fccf17Sopenharmony_ci}
75811fccf17Sopenharmony_ci
75911fccf17Sopenharmony_civoid HRilSim::CopyToHRilApduSimIO(
76011fccf17Sopenharmony_ci    std::unique_ptr<HRilApduSimIO> &rilApduSimIO, const OHOS::HDI::Ril::V1_1::ApduSimIORequestInfo &apduSimIO)
76111fccf17Sopenharmony_ci{
76211fccf17Sopenharmony_ci    rilApduSimIO->channelId = apduSimIO.channelId;
76311fccf17Sopenharmony_ci    rilApduSimIO->type = apduSimIO.type;
76411fccf17Sopenharmony_ci    rilApduSimIO->instruction = apduSimIO.instruction;
76511fccf17Sopenharmony_ci    rilApduSimIO->p1 = apduSimIO.p1;
76611fccf17Sopenharmony_ci    rilApduSimIO->p2 = apduSimIO.p2;
76711fccf17Sopenharmony_ci    rilApduSimIO->p3 = apduSimIO.p3;
76811fccf17Sopenharmony_ci    CopyToCharPoint(&(rilApduSimIO->data), apduSimIO.data);
76911fccf17Sopenharmony_ci}
77011fccf17Sopenharmony_ci
77111fccf17Sopenharmony_civoid HRilSim::CopyToHRilSimAuthentication(std::unique_ptr<HRilSimAuthenticationRequestInfo> &rilSimAuthInfo,
77211fccf17Sopenharmony_ci    const OHOS::HDI::Ril::V1_1::SimAuthenticationRequestInfo &simAuthInfo)
77311fccf17Sopenharmony_ci{
77411fccf17Sopenharmony_ci    rilSimAuthInfo->serial = simAuthInfo.serial;
77511fccf17Sopenharmony_ci    CopyToCharPoint(&(rilSimAuthInfo->aid), simAuthInfo.aid);
77611fccf17Sopenharmony_ci    CopyToCharPoint(&(rilSimAuthInfo->data), simAuthInfo.authData);
77711fccf17Sopenharmony_ci}
77811fccf17Sopenharmony_ci
77911fccf17Sopenharmony_civoid HRilSim::CopyToHRilNcfgOperatorInfo(std::unique_ptr<HRilNcfgOperatorInfo> &rilNcfgOperatorInfo,
78011fccf17Sopenharmony_ci    const OHOS::HDI::Ril::V1_2::NcfgOperatorInfo &ncfgOperatorInfo)
78111fccf17Sopenharmony_ci{
78211fccf17Sopenharmony_ci    CopyToCharPoint(&(rilNcfgOperatorInfo->operName), ncfgOperatorInfo.operName);
78311fccf17Sopenharmony_ci    CopyToCharPoint(&(rilNcfgOperatorInfo->operKey), ncfgOperatorInfo.operKey);
78411fccf17Sopenharmony_ci    rilNcfgOperatorInfo->state = ncfgOperatorInfo.state;
78511fccf17Sopenharmony_ci    CopyToCharPoint(&(rilNcfgOperatorInfo->reserve), ncfgOperatorInfo.reserve);
78611fccf17Sopenharmony_ci}
78711fccf17Sopenharmony_ci
78811fccf17Sopenharmony_cibool HRilSim::BuildLockStatusResp(const void *response, size_t responseLen, HDI::Ril::V1_1::LockStatusResp &lockStatus)
78911fccf17Sopenharmony_ci{
79011fccf17Sopenharmony_ci    if (response == nullptr || responseLen != sizeof(HRilLockStatus)) {
79111fccf17Sopenharmony_ci        return false;
79211fccf17Sopenharmony_ci    }
79311fccf17Sopenharmony_ci    const HRilLockStatus *resp = static_cast<const HRilLockStatus *>(response);
79411fccf17Sopenharmony_ci    lockStatus.result = resp->result;
79511fccf17Sopenharmony_ci    lockStatus.remain = resp->remain;
79611fccf17Sopenharmony_ci    return true;
79711fccf17Sopenharmony_ci}
79811fccf17Sopenharmony_ci
79911fccf17Sopenharmony_civoid HRilSim::ResponseLockStatus(HDI::Ril::V1_1::LockStatusResp &lockStatus,
80011fccf17Sopenharmony_ci    HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response, size_t responseLen)
80111fccf17Sopenharmony_ci{
80211fccf17Sopenharmony_ci    if (!BuildLockStatusResp(response, responseLen, lockStatus)) {
80311fccf17Sopenharmony_ci        TELEPHONY_LOGE("Invalid ResponseLockStatus: response is error");
80411fccf17Sopenharmony_ci        if (responseInfo.error == HDI::Ril::V1_1::RilErrType::NONE) {
80511fccf17Sopenharmony_ci            responseInfo.error = HDI::Ril::V1_1::RilErrType::RIL_ERR_INVALID_RESPONSE;
80611fccf17Sopenharmony_ci        }
80711fccf17Sopenharmony_ci    }
80811fccf17Sopenharmony_ci}
80911fccf17Sopenharmony_ci
81011fccf17Sopenharmony_ciint32_t HRilSim::BuildSimIOResp(HDI::Ril::V1_1::IccIoResultInfo &result,
81111fccf17Sopenharmony_ci    HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response, size_t responseLen)
81211fccf17Sopenharmony_ci{
81311fccf17Sopenharmony_ci    if ((response == nullptr && responseLen != 0) ||
81411fccf17Sopenharmony_ci        (response != nullptr && responseLen != sizeof(HRilSimIOResponse))) {
81511fccf17Sopenharmony_ci        TELEPHONY_LOGE("Invalid BuildSimIOResp: Vendor exception!");
81611fccf17Sopenharmony_ci        return HRIL_ERR_INVALID_PARAMETER;
81711fccf17Sopenharmony_ci    }
81811fccf17Sopenharmony_ci    if (response == nullptr && responseLen == 0) {
81911fccf17Sopenharmony_ci        TELEPHONY_LOGE("BuildSimIOResp response is null");
82011fccf17Sopenharmony_ci        if (responseInfo.error == HDI::Ril::V1_1::RilErrType::NONE) {
82111fccf17Sopenharmony_ci            responseInfo.error = HDI::Ril::V1_1::RilErrType::RIL_ERR_INVALID_RESPONSE;
82211fccf17Sopenharmony_ci        }
82311fccf17Sopenharmony_ci    }
82411fccf17Sopenharmony_ci    result = ProcessIccIoResponse(responseInfo, response, responseLen);
82511fccf17Sopenharmony_ci    return HRIL_ERR_SUCCESS;
82611fccf17Sopenharmony_ci}
82711fccf17Sopenharmony_ci
82811fccf17Sopenharmony_ciint32_t HRilSim::CheckCharData(const void *response, size_t responseLen)
82911fccf17Sopenharmony_ci{
83011fccf17Sopenharmony_ci    if ((response == nullptr && responseLen != 0) || (responseLen % sizeof(char)) != 0) {
83111fccf17Sopenharmony_ci        TELEPHONY_LOGE("Invalid parameter, responseLen:%{public}zu", responseLen);
83211fccf17Sopenharmony_ci        return HRIL_ERR_INVALID_PARAMETER;
83311fccf17Sopenharmony_ci    }
83411fccf17Sopenharmony_ci    if (response == nullptr && responseLen == 0) {
83511fccf17Sopenharmony_ci        TELEPHONY_LOGE("response is null");
83611fccf17Sopenharmony_ci        return HRIL_ERR_NULL_POINT;
83711fccf17Sopenharmony_ci    }
83811fccf17Sopenharmony_ci    return HRIL_ERR_SUCCESS;
83911fccf17Sopenharmony_ci}
84011fccf17Sopenharmony_ci
84111fccf17Sopenharmony_civoid HRilSim::BuildRadioProtocol(HDI::Ril::V1_1::RadioProtocol &radioProtocol, const void *response)
84211fccf17Sopenharmony_ci{
84311fccf17Sopenharmony_ci    const HRilRadioProtocol *hrilRadioProtocol = static_cast<const HRilRadioProtocol *>(response);
84411fccf17Sopenharmony_ci    radioProtocol.slotId = GetSlotId();
84511fccf17Sopenharmony_ci    radioProtocol.sessionId = hrilRadioProtocol->sessionId;
84611fccf17Sopenharmony_ci    radioProtocol.phase = static_cast<HDI::Ril::V1_1::RadioProtocolPhase>(hrilRadioProtocol->phase);
84711fccf17Sopenharmony_ci    radioProtocol.technology = ConvertRadioProtocolTech(hrilRadioProtocol->technology);
84811fccf17Sopenharmony_ci    radioProtocol.modemId = hrilRadioProtocol->modemId;
84911fccf17Sopenharmony_ci    radioProtocol.status = static_cast<HDI::Ril::V1_1::RadioProtocolStatus>(hrilRadioProtocol->status);
85011fccf17Sopenharmony_ci}
85111fccf17Sopenharmony_ci
85211fccf17Sopenharmony_ciint32_t HRilSim::ConvertRadioProtocolTech(int32_t tech)
85311fccf17Sopenharmony_ci{
85411fccf17Sopenharmony_ci    uint32_t radioProtocolTech = HRIL_RADIO_PROTOCOL_TECH_UNKNOWN;
85511fccf17Sopenharmony_ci    for (uint32_t radioTech = RADIO_TECHNOLOGY_GSM; radioTech <= RADIO_TECHNOLOGY_NR; radioTech++) {
85611fccf17Sopenharmony_ci        uint32_t protocolTech = 1 << radioTech;
85711fccf17Sopenharmony_ci        if ((static_cast<uint32_t>(tech) & protocolTech) != 0) {
85811fccf17Sopenharmony_ci            radioProtocolTech |= protocolTech;
85911fccf17Sopenharmony_ci        }
86011fccf17Sopenharmony_ci    }
86111fccf17Sopenharmony_ci    return static_cast<int32_t>(radioProtocolTech);
86211fccf17Sopenharmony_ci}
86311fccf17Sopenharmony_ci} // namespace Telephony
86411fccf17Sopenharmony_ci} // namespace OHOS
865