1d95e75fdSopenharmony_ci/*
2d95e75fdSopenharmony_ci * Copyright (C) 2021-2022 Huawei Device Co., Ltd.
3d95e75fdSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4d95e75fdSopenharmony_ci * you may not use this file except in compliance with the License.
5d95e75fdSopenharmony_ci * You may obtain a copy of the License at
6d95e75fdSopenharmony_ci *
7d95e75fdSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8d95e75fdSopenharmony_ci *
9d95e75fdSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10d95e75fdSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11d95e75fdSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12d95e75fdSopenharmony_ci * See the License for the specific language governing permissions and
13d95e75fdSopenharmony_ci * limitations under the License.
14d95e75fdSopenharmony_ci */
15d95e75fdSopenharmony_ci
16d95e75fdSopenharmony_ci#include "cellular_call_supplement.h"
17d95e75fdSopenharmony_ci
18d95e75fdSopenharmony_ci#include "cellular_call_register.h"
19d95e75fdSopenharmony_ci#include "cellular_call_service.h"
20d95e75fdSopenharmony_ci#include "ims_error.h"
21d95e75fdSopenharmony_ci#include "mmi_code_message.h"
22d95e75fdSopenharmony_ci#include "securec.h"
23d95e75fdSopenharmony_ci#include "standardize_utils.h"
24d95e75fdSopenharmony_ci#include "telephony_log_wrapper.h"
25d95e75fdSopenharmony_ci
26d95e75fdSopenharmony_cinamespace OHOS {
27d95e75fdSopenharmony_cinamespace Telephony {
28d95e75fdSopenharmony_ciconst int32_t ACTIVATE_ACTION = 1;
29d95e75fdSopenharmony_ciconst int32_t DEACTIVATE_ACTION = 2;
30d95e75fdSopenharmony_ciconst int32_t USSD_MODE_NOTIFY = 0;
31d95e75fdSopenharmony_ciconst int32_t USSD_MODE_REQUEST = 1;
32d95e75fdSopenharmony_ciconst int32_t USSD_MODE_NW_RELEASE = 2;
33d95e75fdSopenharmony_ciconst int32_t USSD_SUCCESS = 0;
34d95e75fdSopenharmony_ciconst int32_t USSD_FAILED = 1;
35d95e75fdSopenharmony_ciconst int32_t RESULT_SUCCESS = 0;
36d95e75fdSopenharmony_ciconst int32_t MMI_CODE_FAILED = 1;
37d95e75fdSopenharmony_ciconst int32_t PIN_PUK_MIN = 4;
38d95e75fdSopenharmony_ciconst int32_t PIN_PUK_MAX = 8;
39d95e75fdSopenharmony_ciconst std::string BARR_ALL_OUTGOING_CALLS = "AO";
40d95e75fdSopenharmony_ciconst std::string BARR_OUTGOING_INTERNATIONAL_CALLS = "OI";
41d95e75fdSopenharmony_ciconst std::string BARR_OUTGOING_INTERNATIONAL_CALLS_EXCLUDING_HOME = "OX";
42d95e75fdSopenharmony_ciconst std::string BARR_ALL_INCOMING_CALLS = "AI";
43d95e75fdSopenharmony_ciconst std::string BARR_INCOMING_CALLS_OUTSIDE_HOME = "IR";
44d95e75fdSopenharmony_ciconst std::string ALL_BARRING_SERVICES = "AB";
45d95e75fdSopenharmony_ciconst std::string ALL_OUTGOING_BARRING_SERVICES = "AG";
46d95e75fdSopenharmony_ciconst std::string ALL_INCOMING_BARRING_SERVICES = "AC";
47d95e75fdSopenharmony_ci
48d95e75fdSopenharmony_ciconstexpr unsigned long long operator"" _hash(char const *p, size_t s)
49d95e75fdSopenharmony_ci{
50d95e75fdSopenharmony_ci    return StandardizeUtils::HashCompileTime(p);
51d95e75fdSopenharmony_ci}
52d95e75fdSopenharmony_ci
53d95e75fdSopenharmony_civoid CellularCallSupplement::HandleClip(int32_t slotId, const MMIData &mmiData)
54d95e75fdSopenharmony_ci{
55d95e75fdSopenharmony_ci    const std::string interrogate = "*#";
56d95e75fdSopenharmony_ci    const std::string activate = "*";
57d95e75fdSopenharmony_ci    const std::string deactivate = "#";
58d95e75fdSopenharmony_ci    if (mmiData.actionString.empty()) {
59d95e75fdSopenharmony_ci        ReportMmiCodeMessage(MMI_CODE_FAILED, "", INVALID_MMI_CODE);
60d95e75fdSopenharmony_ci        TELEPHONY_LOGE("[slot%{public}d] actionString is empty!", slotId);
61d95e75fdSopenharmony_ci        return;
62d95e75fdSopenharmony_ci    }
63d95e75fdSopenharmony_ci    auto handler = DelayedSingleton<CellularCallService>::GetInstance()->GetHandler(slotId);
64d95e75fdSopenharmony_ci    if (handler == nullptr) {
65d95e75fdSopenharmony_ci        ReportMmiCodeMessage(MMI_CODE_FAILED, "", GENERIC_FAILURE);
66d95e75fdSopenharmony_ci        TELEPHONY_LOGE("[slot%{public}d] handler is nullptr!", slotId);
67d95e75fdSopenharmony_ci        return;
68d95e75fdSopenharmony_ci    }
69d95e75fdSopenharmony_ci    int32_t result = TELEPHONY_ERROR;
70d95e75fdSopenharmony_ci    auto utCommand = std::make_shared<SsRequestCommand>();
71d95e75fdSopenharmony_ci    int32_t index;
72d95e75fdSopenharmony_ci    handler->RequestSsRequestCommandIndex(index);
73d95e75fdSopenharmony_ci    if (mmiData.actionString == activate) {
74d95e75fdSopenharmony_ci        utCommand->action = ACTIVATE_ACTION;
75d95e75fdSopenharmony_ci        result = supplementRequestIms_.SetClipRequest(slotId, ACTIVATE_ACTION, index);
76d95e75fdSopenharmony_ci    } else if (mmiData.actionString == deactivate) {
77d95e75fdSopenharmony_ci        utCommand->action = DEACTIVATE_ACTION;
78d95e75fdSopenharmony_ci        result = supplementRequestIms_.SetClipRequest(slotId, DEACTIVATE_ACTION, index);
79d95e75fdSopenharmony_ci    } else if (mmiData.actionString == interrogate) {
80d95e75fdSopenharmony_ci        if (NeedUseImsToHandle(slotId)) {
81d95e75fdSopenharmony_ci            result = supplementRequestIms_.GetClipRequest(slotId, index);
82d95e75fdSopenharmony_ci        } else {
83d95e75fdSopenharmony_ci            result = supplementRequestCs_.GetClipRequest(slotId, index);
84d95e75fdSopenharmony_ci        }
85d95e75fdSopenharmony_ci    }
86d95e75fdSopenharmony_ci    if (result != TELEPHONY_SUCCESS) {
87d95e75fdSopenharmony_ci        ReportMmiCodeMessage(MMI_CODE_FAILED, "", GENERIC_FAILURE);
88d95e75fdSopenharmony_ci    } else {
89d95e75fdSopenharmony_ci        handler->SaveSsRequestCommand(utCommand, index);
90d95e75fdSopenharmony_ci    }
91d95e75fdSopenharmony_ci}
92d95e75fdSopenharmony_ci
93d95e75fdSopenharmony_civoid CellularCallSupplement::HandleClir(int32_t slotId, const MMIData &mmiData)
94d95e75fdSopenharmony_ci{
95d95e75fdSopenharmony_ci    const std::string interrogate = "*#";
96d95e75fdSopenharmony_ci    const std::string activate = "*";
97d95e75fdSopenharmony_ci    const std::string deactivate = "#";
98d95e75fdSopenharmony_ci    if (mmiData.actionString.empty()) {
99d95e75fdSopenharmony_ci        ReportMmiCodeMessage(MMI_CODE_FAILED, "", INVALID_MMI_CODE);
100d95e75fdSopenharmony_ci        TELEPHONY_LOGE("[slot%{public}d] actionString is empty!", slotId);
101d95e75fdSopenharmony_ci        return;
102d95e75fdSopenharmony_ci    }
103d95e75fdSopenharmony_ci    auto handler = DelayedSingleton<CellularCallService>::GetInstance()->GetHandler(slotId);
104d95e75fdSopenharmony_ci    if (handler == nullptr) {
105d95e75fdSopenharmony_ci        ReportMmiCodeMessage(MMI_CODE_FAILED, "", GENERIC_FAILURE);
106d95e75fdSopenharmony_ci        TELEPHONY_LOGE("[slot%{public}d] handler is nullptr!", slotId);
107d95e75fdSopenharmony_ci        return;
108d95e75fdSopenharmony_ci    }
109d95e75fdSopenharmony_ci    int32_t result = TELEPHONY_ERROR;
110d95e75fdSopenharmony_ci    auto utCommand = std::make_shared<SsRequestCommand>();
111d95e75fdSopenharmony_ci    int32_t index;
112d95e75fdSopenharmony_ci    handler->RequestSsRequestCommandIndex(index);
113d95e75fdSopenharmony_ci    if (mmiData.actionString == activate) {
114d95e75fdSopenharmony_ci        utCommand->action = ACTIVATE_ACTION;
115d95e75fdSopenharmony_ci        if (NeedUseImsToHandle(slotId)) {
116d95e75fdSopenharmony_ci            result = supplementRequestIms_.SetClirRequest(slotId, ACTIVATE_ACTION, index);
117d95e75fdSopenharmony_ci        } else {
118d95e75fdSopenharmony_ci            result = supplementRequestCs_.SetClirRequest(slotId, ACTIVATE_ACTION, index);
119d95e75fdSopenharmony_ci        }
120d95e75fdSopenharmony_ci    } else if (mmiData.actionString == deactivate) {
121d95e75fdSopenharmony_ci        utCommand->action = DEACTIVATE_ACTION;
122d95e75fdSopenharmony_ci        if (NeedUseImsToHandle(slotId)) {
123d95e75fdSopenharmony_ci            result = supplementRequestIms_.SetClirRequest(slotId, DEACTIVATE_ACTION, index);
124d95e75fdSopenharmony_ci        } else {
125d95e75fdSopenharmony_ci            result = supplementRequestCs_.SetClirRequest(slotId, DEACTIVATE_ACTION, index);
126d95e75fdSopenharmony_ci        }
127d95e75fdSopenharmony_ci    } else if (mmiData.actionString == interrogate) {
128d95e75fdSopenharmony_ci        if (NeedUseImsToHandle(slotId)) {
129d95e75fdSopenharmony_ci            result = supplementRequestIms_.GetClirRequest(slotId, index);
130d95e75fdSopenharmony_ci        } else {
131d95e75fdSopenharmony_ci            result = supplementRequestCs_.GetClirRequest(slotId, index);
132d95e75fdSopenharmony_ci        }
133d95e75fdSopenharmony_ci    }
134d95e75fdSopenharmony_ci    if (result != TELEPHONY_SUCCESS) {
135d95e75fdSopenharmony_ci        ReportMmiCodeMessage(MMI_CODE_FAILED, "", GENERIC_FAILURE);
136d95e75fdSopenharmony_ci    } else {
137d95e75fdSopenharmony_ci        handler->SaveSsRequestCommand(utCommand, index);
138d95e75fdSopenharmony_ci    }
139d95e75fdSopenharmony_ci}
140d95e75fdSopenharmony_ci
141d95e75fdSopenharmony_civoid CellularCallSupplement::HandleColr(int32_t slotId, const MMIData &mmiData)
142d95e75fdSopenharmony_ci{
143d95e75fdSopenharmony_ci    const std::string interrogate = "*#";
144d95e75fdSopenharmony_ci    const std::string activate = "*";
145d95e75fdSopenharmony_ci    const std::string deactivate = "#";
146d95e75fdSopenharmony_ci    if (mmiData.actionString.empty()) {
147d95e75fdSopenharmony_ci        ReportMmiCodeMessage(MMI_CODE_FAILED, "", INVALID_MMI_CODE);
148d95e75fdSopenharmony_ci        TELEPHONY_LOGE("[slot%{public}d] actionString is empty!", slotId);
149d95e75fdSopenharmony_ci        return;
150d95e75fdSopenharmony_ci    }
151d95e75fdSopenharmony_ci    auto handler = DelayedSingleton<CellularCallService>::GetInstance()->GetHandler(slotId);
152d95e75fdSopenharmony_ci    if (handler == nullptr) {
153d95e75fdSopenharmony_ci        ReportMmiCodeMessage(MMI_CODE_FAILED, "", GENERIC_FAILURE);
154d95e75fdSopenharmony_ci        TELEPHONY_LOGE("[slot%{public}d] handler is nullptr!", slotId);
155d95e75fdSopenharmony_ci        return;
156d95e75fdSopenharmony_ci    }
157d95e75fdSopenharmony_ci    int32_t result = TELEPHONY_ERROR;
158d95e75fdSopenharmony_ci    auto utCommand = std::make_shared<SsRequestCommand>();
159d95e75fdSopenharmony_ci    int32_t index;
160d95e75fdSopenharmony_ci    handler->RequestSsRequestCommandIndex(index);
161d95e75fdSopenharmony_ci    if (mmiData.actionString == activate) {
162d95e75fdSopenharmony_ci        utCommand->action = ACTIVATE_ACTION;
163d95e75fdSopenharmony_ci        if (NeedUseImsToHandle(slotId)) {
164d95e75fdSopenharmony_ci            result = supplementRequestIms_.SetColrRequest(slotId, ACTIVATE_ACTION, index);
165d95e75fdSopenharmony_ci        }
166d95e75fdSopenharmony_ci    } else if (mmiData.actionString == deactivate) {
167d95e75fdSopenharmony_ci        utCommand->action = DEACTIVATE_ACTION;
168d95e75fdSopenharmony_ci        if (NeedUseImsToHandle(slotId)) {
169d95e75fdSopenharmony_ci            result = supplementRequestIms_.SetColrRequest(slotId, DEACTIVATE_ACTION, index);
170d95e75fdSopenharmony_ci        }
171d95e75fdSopenharmony_ci    } else if (mmiData.actionString == interrogate) {
172d95e75fdSopenharmony_ci        if (NeedUseImsToHandle(slotId)) {
173d95e75fdSopenharmony_ci            result = supplementRequestIms_.GetColrRequest(slotId, index);
174d95e75fdSopenharmony_ci        }
175d95e75fdSopenharmony_ci    }
176d95e75fdSopenharmony_ci    if (result != TELEPHONY_SUCCESS) {
177d95e75fdSopenharmony_ci        ReportMmiCodeMessage(MMI_CODE_FAILED, "", GENERIC_FAILURE);
178d95e75fdSopenharmony_ci    } else {
179d95e75fdSopenharmony_ci        handler->SaveSsRequestCommand(utCommand, index);
180d95e75fdSopenharmony_ci    }
181d95e75fdSopenharmony_ci}
182d95e75fdSopenharmony_ci
183d95e75fdSopenharmony_civoid CellularCallSupplement::HandleColp(int32_t slotId, const MMIData &mmiData)
184d95e75fdSopenharmony_ci{
185d95e75fdSopenharmony_ci    const std::string interrogate = "*#";
186d95e75fdSopenharmony_ci    const std::string activate = "*";
187d95e75fdSopenharmony_ci    const std::string deactivate = "#";
188d95e75fdSopenharmony_ci    if (mmiData.actionString.empty()) {
189d95e75fdSopenharmony_ci        ReportMmiCodeMessage(MMI_CODE_FAILED, "", INVALID_MMI_CODE);
190d95e75fdSopenharmony_ci        TELEPHONY_LOGE("[slot%{public}d] actionString is empty!", slotId);
191d95e75fdSopenharmony_ci        return;
192d95e75fdSopenharmony_ci    }
193d95e75fdSopenharmony_ci    auto handler = DelayedSingleton<CellularCallService>::GetInstance()->GetHandler(slotId);
194d95e75fdSopenharmony_ci    if (handler == nullptr) {
195d95e75fdSopenharmony_ci        ReportMmiCodeMessage(MMI_CODE_FAILED, "", GENERIC_FAILURE);
196d95e75fdSopenharmony_ci        TELEPHONY_LOGE("[slot%{public}d] handler is nullptr!", slotId);
197d95e75fdSopenharmony_ci        return;
198d95e75fdSopenharmony_ci    }
199d95e75fdSopenharmony_ci    int32_t result = TELEPHONY_ERROR;
200d95e75fdSopenharmony_ci    auto utCommand = std::make_shared<SsRequestCommand>();
201d95e75fdSopenharmony_ci    int32_t index;
202d95e75fdSopenharmony_ci    handler->RequestSsRequestCommandIndex(index);
203d95e75fdSopenharmony_ci    if (mmiData.actionString == activate) {
204d95e75fdSopenharmony_ci        utCommand->action = ACTIVATE_ACTION;
205d95e75fdSopenharmony_ci        if (NeedUseImsToHandle(slotId)) {
206d95e75fdSopenharmony_ci            result = supplementRequestIms_.SetColpRequest(slotId, ACTIVATE_ACTION, index);
207d95e75fdSopenharmony_ci        }
208d95e75fdSopenharmony_ci    } else if (mmiData.actionString == deactivate) {
209d95e75fdSopenharmony_ci        utCommand->action = DEACTIVATE_ACTION;
210d95e75fdSopenharmony_ci        if (NeedUseImsToHandle(slotId)) {
211d95e75fdSopenharmony_ci            result = supplementRequestIms_.SetColpRequest(slotId, DEACTIVATE_ACTION, index);
212d95e75fdSopenharmony_ci        }
213d95e75fdSopenharmony_ci    } else if (mmiData.actionString == interrogate) {
214d95e75fdSopenharmony_ci        if (NeedUseImsToHandle(slotId)) {
215d95e75fdSopenharmony_ci            result = supplementRequestIms_.GetColpRequest(slotId, index);
216d95e75fdSopenharmony_ci        }
217d95e75fdSopenharmony_ci    }
218d95e75fdSopenharmony_ci    if (result != TELEPHONY_SUCCESS) {
219d95e75fdSopenharmony_ci        ReportMmiCodeMessage(MMI_CODE_FAILED, "", GENERIC_FAILURE);
220d95e75fdSopenharmony_ci    } else {
221d95e75fdSopenharmony_ci        handler->SaveSsRequestCommand(utCommand, index);
222d95e75fdSopenharmony_ci    }
223d95e75fdSopenharmony_ci}
224d95e75fdSopenharmony_ci
225d95e75fdSopenharmony_civoid CellularCallSupplement::HandleCallTransfer(int32_t slotId, const MMIData &mmiData)
226d95e75fdSopenharmony_ci{
227d95e75fdSopenharmony_ci    const std::string interrogate = "*#";
228d95e75fdSopenharmony_ci    int32_t serviceCode = ObtainServiceCode(mmiData.serviceInfoB);
229d95e75fdSopenharmony_ci    int32_t cause = ObtainCause(mmiData.serviceCode);
230d95e75fdSopenharmony_ci    if (!mmiData.actionString.empty() && mmiData.actionString == interrogate) {
231d95e75fdSopenharmony_ci        HandleGetCallTransfer(slotId, cause);
232d95e75fdSopenharmony_ci        return;
233d95e75fdSopenharmony_ci    }
234d95e75fdSopenharmony_ci    std::string phoneNumber = mmiData.serviceInfoA;
235d95e75fdSopenharmony_ci    if (mmiData.actionString.empty()) {
236d95e75fdSopenharmony_ci        ReportMmiCodeMessage(MMI_CODE_FAILED, "", INVALID_MMI_CODE);
237d95e75fdSopenharmony_ci        TELEPHONY_LOGE("[slot%{public}d] actionString is empty!", slotId);
238d95e75fdSopenharmony_ci        return;
239d95e75fdSopenharmony_ci    }
240d95e75fdSopenharmony_ci    CallTransferSettingType callTransferAction;
241d95e75fdSopenharmony_ci    int32_t result = ObtainCallTrasferAction(mmiData.actionString.c_str(), phoneNumber, callTransferAction);
242d95e75fdSopenharmony_ci    if (result != TELEPHONY_SUCCESS) {
243d95e75fdSopenharmony_ci        ReportMmiCodeMessage(MMI_CODE_FAILED, "", GENERIC_FAILURE);
244d95e75fdSopenharmony_ci        return;
245d95e75fdSopenharmony_ci    }
246d95e75fdSopenharmony_ci    HandleSetCallTransfer(slotId, serviceCode, cause, phoneNumber, callTransferAction);
247d95e75fdSopenharmony_ci}
248d95e75fdSopenharmony_ci
249d95e75fdSopenharmony_ciint32_t CellularCallSupplement::ObtainServiceCode(const std::string &serviceInfoB)
250d95e75fdSopenharmony_ci{
251d95e75fdSopenharmony_ci    if (serviceInfoB.empty()) {
252d95e75fdSopenharmony_ci        TELEPHONY_LOGI("serviceInfoB is empty!");
253d95e75fdSopenharmony_ci        return NONE;
254d95e75fdSopenharmony_ci    }
255d95e75fdSopenharmony_ci    int32_t intServiceInfoB = atoi(serviceInfoB.c_str());
256d95e75fdSopenharmony_ci    switch (intServiceInfoB) {
257d95e75fdSopenharmony_ci        case ALL_TELE_SERVICES:
258d95e75fdSopenharmony_ci            return SHORT_MESSAGE_SERVICE + FAX + VOICE;
259d95e75fdSopenharmony_ci        case TELE_SERVICES:
260d95e75fdSopenharmony_ci            return VOICE;
261d95e75fdSopenharmony_ci        case ALL_DATA_TELE_SERVICES:
262d95e75fdSopenharmony_ci            return SHORT_MESSAGE_SERVICE + FAX;
263d95e75fdSopenharmony_ci        case FACSIMILE_SERVICES:
264d95e75fdSopenharmony_ci            return FAX;
265d95e75fdSopenharmony_ci        case SHORT_MESSAGE_SERVICES:
266d95e75fdSopenharmony_ci            return SHORT_MESSAGE_SERVICE;
267d95e75fdSopenharmony_ci        case ALL_TELE_SERVICES_EXCEPT_SMS:
268d95e75fdSopenharmony_ci            return FAX + VOICE;
269d95e75fdSopenharmony_ci        case ALL_BEARER_SERVICES:
270d95e75fdSopenharmony_ci            return DATA_CIRCUIT_ASYNC + DATA_CIRCUIT_SYNC;
271d95e75fdSopenharmony_ci        case ALL_ASYNC_SERVICES:
272d95e75fdSopenharmony_ci            return DEDICATED_PAD_ACCESS + DATA_CIRCUIT_ASYNC;
273d95e75fdSopenharmony_ci        case ALL_SYNC_SERVICES:
274d95e75fdSopenharmony_ci            return DEDICATED_PACKET_ACCESS + DATA_CIRCUIT_SYNC;
275d95e75fdSopenharmony_ci        case ALL_DATA_CIRCUIT_SYNC:
276d95e75fdSopenharmony_ci            return DATA_CIRCUIT_SYNC;
277d95e75fdSopenharmony_ci        case ALL_DATA_CIRCUIT_ASYNC:
278d95e75fdSopenharmony_ci            return DATA_CIRCUIT_ASYNC;
279d95e75fdSopenharmony_ci        case ALL_GPRS_BEARER_SERVICES:
280d95e75fdSopenharmony_ci            return DEDICATED_PACKET_ACCESS;
281d95e75fdSopenharmony_ci        default:
282d95e75fdSopenharmony_ci            TELEPHONY_LOGE("serviceInfoB out of range, please check!");
283d95e75fdSopenharmony_ci            return NONE;
284d95e75fdSopenharmony_ci    }
285d95e75fdSopenharmony_ci}
286d95e75fdSopenharmony_ci
287d95e75fdSopenharmony_ciint32_t CellularCallSupplement::ObtainCallTrasferAction(
288d95e75fdSopenharmony_ci    const char *actionString, const std::string &phoneNumber, CallTransferSettingType &callTransferAction)
289d95e75fdSopenharmony_ci{
290d95e75fdSopenharmony_ci    // 3GPP TS 24.082 V4.0.0 (2001-03) 1 Call Forwarding Unconditional (CFU)
291d95e75fdSopenharmony_ci    // 3GPP TS 24.082 V4.0.0 (2001-03) 2 Call Forwarding on mobile subscriber Busy (CFB)
292d95e75fdSopenharmony_ci    // 3GPP TS 24.082 V4.0.0 (2001-03) 3 Call Forwarding on No Reply (CFNRy)
293d95e75fdSopenharmony_ci    // 3GPP TS 24.082 V4.0.0 (2001-03) 4 Call Forwarding on mobile subscriber Not Reachable (CFNRc)
294d95e75fdSopenharmony_ci    switch (StandardizeUtils::Hash_(actionString)) {
295d95e75fdSopenharmony_ci        case "*"_hash:
296d95e75fdSopenharmony_ci            if (phoneNumber.empty()) {
297d95e75fdSopenharmony_ci                callTransferAction = CallTransferSettingType::CALL_TRANSFER_ENABLE;
298d95e75fdSopenharmony_ci            } else {
299d95e75fdSopenharmony_ci                callTransferAction = CallTransferSettingType::CALL_TRANSFER_REGISTRATION;
300d95e75fdSopenharmony_ci            }
301d95e75fdSopenharmony_ci            break;
302d95e75fdSopenharmony_ci        case "#"_hash:
303d95e75fdSopenharmony_ci            callTransferAction = CallTransferSettingType::CALL_TRANSFER_DISABLE;
304d95e75fdSopenharmony_ci            break;
305d95e75fdSopenharmony_ci        case "**"_hash:
306d95e75fdSopenharmony_ci            callTransferAction = CallTransferSettingType::CALL_TRANSFER_REGISTRATION;
307d95e75fdSopenharmony_ci            break;
308d95e75fdSopenharmony_ci        case "##"_hash:
309d95e75fdSopenharmony_ci            callTransferAction = CallTransferSettingType::CALL_TRANSFER_ERASURE;
310d95e75fdSopenharmony_ci            break;
311d95e75fdSopenharmony_ci        default:
312d95e75fdSopenharmony_ci            TELEPHONY_LOGE("actionString out of range, please check!");
313d95e75fdSopenharmony_ci            return TELEPHONY_ERR_ARGUMENT_MISMATCH;
314d95e75fdSopenharmony_ci    }
315d95e75fdSopenharmony_ci    return TELEPHONY_SUCCESS;
316d95e75fdSopenharmony_ci}
317d95e75fdSopenharmony_ci
318d95e75fdSopenharmony_ciint32_t CellularCallSupplement::ObtainCause(const std::string &actionStr)
319d95e75fdSopenharmony_ci{
320d95e75fdSopenharmony_ci    if (actionStr.empty()) {
321d95e75fdSopenharmony_ci        TELEPHONY_LOGE("actionStr is empty!");
322d95e75fdSopenharmony_ci        return TELEPHONY_ERROR;
323d95e75fdSopenharmony_ci    }
324d95e75fdSopenharmony_ci
325d95e75fdSopenharmony_ci    /*
326d95e75fdSopenharmony_ci     * 3GPP TS 22.030 V4.0.0 (2001-03) Annex B (normative): Codes for defined Supplementary Services
327d95e75fdSopenharmony_ci     * CFU	                21
328d95e75fdSopenharmony_ci     * CF Busy	            67
329d95e75fdSopenharmony_ci     * CF No Reply	        61
330d95e75fdSopenharmony_ci     * CF Not Reachable 	62
331d95e75fdSopenharmony_ci     * all CF		        002
332d95e75fdSopenharmony_ci     * all conditional CF	004
333d95e75fdSopenharmony_ci     */
334d95e75fdSopenharmony_ci    switch (StandardizeUtils::Hash_(actionStr.c_str())) {
335d95e75fdSopenharmony_ci        case "21"_hash:
336d95e75fdSopenharmony_ci            return static_cast<int32_t>(CallTransferType::TRANSFER_TYPE_UNCONDITIONAL);
337d95e75fdSopenharmony_ci        case "67"_hash:
338d95e75fdSopenharmony_ci            return static_cast<int32_t>(CallTransferType::TRANSFER_TYPE_BUSY);
339d95e75fdSopenharmony_ci        case "61"_hash:
340d95e75fdSopenharmony_ci            return static_cast<int32_t>(CallTransferType::TRANSFER_TYPE_NO_REPLY);
341d95e75fdSopenharmony_ci        case "62"_hash:
342d95e75fdSopenharmony_ci            return static_cast<int32_t>(CallTransferType::TRANSFER_TYPE_NOT_REACHABLE);
343d95e75fdSopenharmony_ci        default:
344d95e75fdSopenharmony_ci            TELEPHONY_LOGE("actionStr out of range!");
345d95e75fdSopenharmony_ci            return TELEPHONY_ERROR;
346d95e75fdSopenharmony_ci    }
347d95e75fdSopenharmony_ci}
348d95e75fdSopenharmony_ci
349d95e75fdSopenharmony_civoid CellularCallSupplement::HandleGetCallTransfer(int32_t slotId, int32_t cause)
350d95e75fdSopenharmony_ci{
351d95e75fdSopenharmony_ci    auto handler = DelayedSingleton<CellularCallService>::GetInstance()->GetHandler(slotId);
352d95e75fdSopenharmony_ci    if (handler == nullptr) {
353d95e75fdSopenharmony_ci        ReportMmiCodeMessage(MMI_CODE_FAILED, "", GENERIC_FAILURE);
354d95e75fdSopenharmony_ci        TELEPHONY_LOGE("[slot%{public}d] handler is nullptr!", slotId);
355d95e75fdSopenharmony_ci        return;
356d95e75fdSopenharmony_ci    }
357d95e75fdSopenharmony_ci    auto utCommand = std::make_shared<SsRequestCommand>();
358d95e75fdSopenharmony_ci    utCommand->cfReason = cause;
359d95e75fdSopenharmony_ci    int32_t index;
360d95e75fdSopenharmony_ci    handler->RequestSsRequestCommandIndex(index);
361d95e75fdSopenharmony_ci    int32_t result = TELEPHONY_ERROR;
362d95e75fdSopenharmony_ci    if (NeedUseImsToHandle(slotId)) {
363d95e75fdSopenharmony_ci        result = supplementRequestIms_.GetCallTransferRequest(slotId, cause, index);
364d95e75fdSopenharmony_ci    } else {
365d95e75fdSopenharmony_ci        result = supplementRequestCs_.GetCallTransferRequest(slotId, cause, index);
366d95e75fdSopenharmony_ci    }
367d95e75fdSopenharmony_ci    if (result != TELEPHONY_SUCCESS) {
368d95e75fdSopenharmony_ci        ReportMmiCodeMessage(MMI_CODE_FAILED, "", GENERIC_FAILURE);
369d95e75fdSopenharmony_ci    } else {
370d95e75fdSopenharmony_ci        handler->SaveSsRequestCommand(utCommand, index);
371d95e75fdSopenharmony_ci    }
372d95e75fdSopenharmony_ci}
373d95e75fdSopenharmony_ci
374d95e75fdSopenharmony_civoid CellularCallSupplement::HandleSetCallTransfer(int32_t slotId, int32_t serviceCode, int32_t cause,
375d95e75fdSopenharmony_ci    const std::string &phoneNumber, CallTransferSettingType callTransferAction)
376d95e75fdSopenharmony_ci{
377d95e75fdSopenharmony_ci    auto handler = DelayedSingleton<CellularCallService>::GetInstance()->GetHandler(slotId);
378d95e75fdSopenharmony_ci    if (handler == nullptr) {
379d95e75fdSopenharmony_ci        ReportMmiCodeMessage(MMI_CODE_FAILED, "", GENERIC_FAILURE);
380d95e75fdSopenharmony_ci        TELEPHONY_LOGE("[slot%{public}d] handler is nullptr!", slotId);
381d95e75fdSopenharmony_ci        return;
382d95e75fdSopenharmony_ci    }
383d95e75fdSopenharmony_ci    auto utCommand = std::make_shared<SsRequestCommand>();
384d95e75fdSopenharmony_ci    utCommand->cfReason = cause;
385d95e75fdSopenharmony_ci    utCommand->cfAction = static_cast<int32_t>(callTransferAction);
386d95e75fdSopenharmony_ci    utCommand->number = phoneNumber;
387d95e75fdSopenharmony_ci    int32_t index;
388d95e75fdSopenharmony_ci    handler->RequestSsRequestCommandIndex(index);
389d95e75fdSopenharmony_ci    int32_t result = TELEPHONY_ERROR;
390d95e75fdSopenharmony_ci    if (NeedUseImsToHandle(slotId)) {
391d95e75fdSopenharmony_ci        CallTransferInfo cfInfo;
392d95e75fdSopenharmony_ci        if (memcpy_s(cfInfo.transferNum, kMaxNumberLen, phoneNumber.c_str(), phoneNumber.length()) != EOK) {
393d95e75fdSopenharmony_ci            TELEPHONY_LOGE("[slot%{public}d] memcpy_s failed!", slotId);
394d95e75fdSopenharmony_ci            ReportMmiCodeMessage(MMI_CODE_FAILED, "", GENERIC_FAILURE);
395d95e75fdSopenharmony_ci            return;
396d95e75fdSopenharmony_ci        }
397d95e75fdSopenharmony_ci        cfInfo.settingType = callTransferAction;
398d95e75fdSopenharmony_ci        cfInfo.type = static_cast<CallTransferType>(cause);
399d95e75fdSopenharmony_ci        // set the time as default min, this mean the time will not use at IMS
400d95e75fdSopenharmony_ci        cfInfo.startHour = MIN_HOUR;
401d95e75fdSopenharmony_ci        cfInfo.startMinute = MIN_MINUTE;
402d95e75fdSopenharmony_ci        cfInfo.endHour = MIN_HOUR;
403d95e75fdSopenharmony_ci        cfInfo.endMinute = MIN_MINUTE;
404d95e75fdSopenharmony_ci        result = supplementRequestIms_.SetCallTransferRequest(slotId, cfInfo, serviceCode, index);
405d95e75fdSopenharmony_ci    } else {
406d95e75fdSopenharmony_ci        CallTransferParam callTransferParam;
407d95e75fdSopenharmony_ci        callTransferParam.mode = static_cast<int32_t>(callTransferAction);
408d95e75fdSopenharmony_ci        callTransferParam.reason = cause;
409d95e75fdSopenharmony_ci        callTransferParam.number = phoneNumber;
410d95e75fdSopenharmony_ci        callTransferParam.classx = serviceCode;
411d95e75fdSopenharmony_ci        result = supplementRequestCs_.SetCallTransferRequest(slotId, callTransferParam, index);
412d95e75fdSopenharmony_ci    }
413d95e75fdSopenharmony_ci    if (result != TELEPHONY_SUCCESS) {
414d95e75fdSopenharmony_ci        ReportMmiCodeMessage(MMI_CODE_FAILED, "", GENERIC_FAILURE);
415d95e75fdSopenharmony_ci    } else {
416d95e75fdSopenharmony_ci        handler->SaveSsRequestCommand(utCommand, index);
417d95e75fdSopenharmony_ci    }
418d95e75fdSopenharmony_ci}
419d95e75fdSopenharmony_ci
420d95e75fdSopenharmony_civoid CellularCallSupplement::HandleCallRestriction(int32_t slotId, const MMIData &mmiData)
421d95e75fdSopenharmony_ci{
422d95e75fdSopenharmony_ci    std::string infoA = mmiData.serviceInfoA;
423d95e75fdSopenharmony_ci    std::string facType = ObtainBarringInstallation(mmiData.serviceCode);
424d95e75fdSopenharmony_ci    const std::string interrogate = "*#";
425d95e75fdSopenharmony_ci    const std::string activate = "*";
426d95e75fdSopenharmony_ci    const std::string deactivate = "#";
427d95e75fdSopenharmony_ci    if (mmiData.actionString.empty()) {
428d95e75fdSopenharmony_ci        ReportMmiCodeMessage(MMI_CODE_FAILED, "", INVALID_MMI_CODE);
429d95e75fdSopenharmony_ci        TELEPHONY_LOGE("[slot%{public}d] actionString is empty!", slotId);
430d95e75fdSopenharmony_ci        return;
431d95e75fdSopenharmony_ci    }
432d95e75fdSopenharmony_ci    auto handler = DelayedSingleton<CellularCallService>::GetInstance()->GetHandler(slotId);
433d95e75fdSopenharmony_ci    if (handler == nullptr) {
434d95e75fdSopenharmony_ci        ReportMmiCodeMessage(MMI_CODE_FAILED, "", GENERIC_FAILURE);
435d95e75fdSopenharmony_ci        TELEPHONY_LOGE("[slot%{public}d] handler is nullptr!", slotId);
436d95e75fdSopenharmony_ci        return;
437d95e75fdSopenharmony_ci    }
438d95e75fdSopenharmony_ci    auto utCommand = std::make_shared<SsRequestCommand>();
439d95e75fdSopenharmony_ci    utCommand->facility = facType;
440d95e75fdSopenharmony_ci    int32_t index;
441d95e75fdSopenharmony_ci    handler->RequestSsRequestCommandIndex(index);
442d95e75fdSopenharmony_ci    int32_t result = TELEPHONY_ERROR;
443d95e75fdSopenharmony_ci    if (mmiData.actionString == interrogate) {
444d95e75fdSopenharmony_ci        if (NeedUseImsToHandle(slotId)) {
445d95e75fdSopenharmony_ci            result = supplementRequestIms_.GetCallRestrictionRequest(slotId, facType, index);
446d95e75fdSopenharmony_ci        } else {
447d95e75fdSopenharmony_ci            result = supplementRequestCs_.GetCallRestrictionRequest(slotId, facType, index);
448d95e75fdSopenharmony_ci        }
449d95e75fdSopenharmony_ci    } else if (mmiData.actionString == activate || mmiData.actionString == deactivate) {
450d95e75fdSopenharmony_ci        utCommand->enable = mmiData.actionString == activate;
451d95e75fdSopenharmony_ci        size_t cpyLen = strlen(infoA.c_str()) + 1;
452d95e75fdSopenharmony_ci        size_t maxCpyLen = sizeof(utCommand->password);
453d95e75fdSopenharmony_ci        if (strcpy_s(utCommand->password, cpyLen > maxCpyLen ? maxCpyLen : cpyLen, infoA.c_str()) != EOK) {
454d95e75fdSopenharmony_ci            TELEPHONY_LOGE("[slot%{public}d] strcpy_s fail.", slotId);
455d95e75fdSopenharmony_ci            return;
456d95e75fdSopenharmony_ci        }
457d95e75fdSopenharmony_ci        if (NeedUseImsToHandle(slotId)) {
458d95e75fdSopenharmony_ci            result = supplementRequestIms_.SetCallRestrictionRequest(
459d95e75fdSopenharmony_ci                slotId, facType, mmiData.actionString == activate, infoA, index);
460d95e75fdSopenharmony_ci        } else {
461d95e75fdSopenharmony_ci            result = supplementRequestCs_.SetCallRestrictionRequest(
462d95e75fdSopenharmony_ci                slotId, facType, mmiData.actionString == activate, infoA, index);
463d95e75fdSopenharmony_ci        }
464d95e75fdSopenharmony_ci    }
465d95e75fdSopenharmony_ci    if (result != TELEPHONY_SUCCESS) {
466d95e75fdSopenharmony_ci        ReportMmiCodeMessage(MMI_CODE_FAILED, "", GENERIC_FAILURE);
467d95e75fdSopenharmony_ci    } else {
468d95e75fdSopenharmony_ci        handler->SaveSsRequestCommand(utCommand, index);
469d95e75fdSopenharmony_ci    }
470d95e75fdSopenharmony_ci}
471d95e75fdSopenharmony_ci
472d95e75fdSopenharmony_cistd::string CellularCallSupplement::ObtainBarringInstallation(const std::string &serviceInfoC)
473d95e75fdSopenharmony_ci{
474d95e75fdSopenharmony_ci    if (serviceInfoC.empty()) {
475d95e75fdSopenharmony_ci        TELEPHONY_LOGE("serviceInfoC is empty!");
476d95e75fdSopenharmony_ci        return std::string();
477d95e75fdSopenharmony_ci    }
478d95e75fdSopenharmony_ci
479d95e75fdSopenharmony_ci    /*
480d95e75fdSopenharmony_ci     * 27007-430_2001 7.4	Facility lock +CLCK
481d95e75fdSopenharmony_ci     *  Supplementary	Service Service	Code	SIA	SIB	SIC
482d95e75fdSopenharmony_ci     * 	22.088
483d95e75fdSopenharmony_ci     * 	BAOC	            33	                 PW	BS	-
484d95e75fdSopenharmony_ci     * 	BAOIC	            331	                 PW	BS	-
485d95e75fdSopenharmony_ci     * 	BAOIC exc home	    332	                 PW	BS	-
486d95e75fdSopenharmony_ci     * 	BAIC	            35	                 PW	BS	-
487d95e75fdSopenharmony_ci     * 	BAIC roaming	    351	                 PW	BS	-
488d95e75fdSopenharmony_ci     *  all Barring Serv.   330	                 PW	BS	-
489d95e75fdSopenharmony_ci     *  Outg. Barr. Serv.   333	                 PW	BS
490d95e75fdSopenharmony_ci     *  Inc. Barr. Serv.	353	                 PW	BS
491d95e75fdSopenharmony_ci     */
492d95e75fdSopenharmony_ci    switch (StandardizeUtils::Hash_(serviceInfoC.c_str())) {
493d95e75fdSopenharmony_ci        case "33"_hash:
494d95e75fdSopenharmony_ci            // "AO"	BAOC (Barr All Outgoing Calls) (refer 3GPP TS 22.088 [6] clause 1)
495d95e75fdSopenharmony_ci            return BARR_ALL_OUTGOING_CALLS;
496d95e75fdSopenharmony_ci        case "331"_hash:
497d95e75fdSopenharmony_ci            // "OI"	BOIC (Barr Outgoing International Calls) (refer 3GPP TS 22.088 [6] clause 1)
498d95e75fdSopenharmony_ci            return BARR_OUTGOING_INTERNATIONAL_CALLS;
499d95e75fdSopenharmony_ci        case "332"_hash:
500d95e75fdSopenharmony_ci            // "OX"	BOIC exHC (Barr Outgoing International Calls except to Home Country)
501d95e75fdSopenharmony_ci            // (refer 3GPP TS 22.088 [6] clause 1)
502d95e75fdSopenharmony_ci            return BARR_OUTGOING_INTERNATIONAL_CALLS_EXCLUDING_HOME;
503d95e75fdSopenharmony_ci        case "351"_hash:
504d95e75fdSopenharmony_ci            // "IR"	BIC Roam (Barr Incoming Calls when Roaming outside the home country)
505d95e75fdSopenharmony_ci            // (refer 3GPP TS 22.088 [6] clause 2)
506d95e75fdSopenharmony_ci            return BARR_INCOMING_CALLS_OUTSIDE_HOME;
507d95e75fdSopenharmony_ci        case "35"_hash:
508d95e75fdSopenharmony_ci            // "AI"	BAIC (Barr All Incoming Calls) (refer 3GPP TS 22.088 [6] clause 2)
509d95e75fdSopenharmony_ci            return BARR_ALL_INCOMING_CALLS;
510d95e75fdSopenharmony_ci        case "330"_hash:
511d95e75fdSopenharmony_ci            // "AB"	All Barring services (refer 3GPP TS 22.030 [19]) (applicable only for <mode>=0)
512d95e75fdSopenharmony_ci            return ALL_BARRING_SERVICES;
513d95e75fdSopenharmony_ci        case "333"_hash:
514d95e75fdSopenharmony_ci            // "AG"	All outGoing barring services (refer 3GPP TS 22.030 [19]) (applicable only for <mode>=0)
515d95e75fdSopenharmony_ci            return ALL_OUTGOING_BARRING_SERVICES;
516d95e75fdSopenharmony_ci        case "353"_hash:
517d95e75fdSopenharmony_ci            // "AC"	All inComing barring services (refer 3GPP TS 22.030 [19]) (applicable only for <mode>=0)
518d95e75fdSopenharmony_ci            return ALL_INCOMING_BARRING_SERVICES;
519d95e75fdSopenharmony_ci        default:
520d95e75fdSopenharmony_ci            TELEPHONY_LOGE("serviceInfoC out of range!");
521d95e75fdSopenharmony_ci            return std::string();
522d95e75fdSopenharmony_ci    }
523d95e75fdSopenharmony_ci}
524d95e75fdSopenharmony_ci
525d95e75fdSopenharmony_civoid CellularCallSupplement::HandleCallWaiting(int32_t slotId, const MMIData &mmiData)
526d95e75fdSopenharmony_ci{
527d95e75fdSopenharmony_ci    if (mmiData.actionString.empty()) {
528d95e75fdSopenharmony_ci        ReportMmiCodeMessage(MMI_CODE_FAILED, "", INVALID_MMI_CODE);
529d95e75fdSopenharmony_ci        TELEPHONY_LOGE("[slot%{public}d] actionString is empty!", slotId);
530d95e75fdSopenharmony_ci        return;
531d95e75fdSopenharmony_ci    }
532d95e75fdSopenharmony_ci    auto handler = DelayedSingleton<CellularCallService>::GetInstance()->GetHandler(slotId);
533d95e75fdSopenharmony_ci    if (handler == nullptr) {
534d95e75fdSopenharmony_ci        ReportMmiCodeMessage(MMI_CODE_FAILED, "", GENERIC_FAILURE);
535d95e75fdSopenharmony_ci        TELEPHONY_LOGE("[slot%{public}d] handler is nullptr!", slotId);
536d95e75fdSopenharmony_ci        return;
537d95e75fdSopenharmony_ci    }
538d95e75fdSopenharmony_ci    const std::string activate = "*";
539d95e75fdSopenharmony_ci    const std::string deactivate = "#";
540d95e75fdSopenharmony_ci    const std::string interrogate = "*#";
541d95e75fdSopenharmony_ci    int32_t result = TELEPHONY_ERROR;
542d95e75fdSopenharmony_ci    int32_t classType = ObtainServiceCode(mmiData.serviceInfoA);
543d95e75fdSopenharmony_ci    auto utCommand = std::make_shared<SsRequestCommand>();
544d95e75fdSopenharmony_ci    utCommand->classType = classType;
545d95e75fdSopenharmony_ci    int32_t index;
546d95e75fdSopenharmony_ci    handler->RequestSsRequestCommandIndex(index);
547d95e75fdSopenharmony_ci    if (mmiData.actionString == activate || mmiData.actionString == deactivate) {
548d95e75fdSopenharmony_ci        utCommand->enable = mmiData.actionString == activate;
549d95e75fdSopenharmony_ci        if (NeedUseImsToHandle(slotId)) {
550d95e75fdSopenharmony_ci            result =
551d95e75fdSopenharmony_ci                supplementRequestIms_.SetCallWaitingRequest(slotId, mmiData.actionString == activate, classType, index);
552d95e75fdSopenharmony_ci        } else {
553d95e75fdSopenharmony_ci            result =
554d95e75fdSopenharmony_ci                supplementRequestCs_.SetCallWaitingRequest(slotId, mmiData.actionString == activate, classType, index);
555d95e75fdSopenharmony_ci        }
556d95e75fdSopenharmony_ci    } else if (mmiData.actionString == interrogate) {
557d95e75fdSopenharmony_ci        if (NeedUseImsToHandle(slotId)) {
558d95e75fdSopenharmony_ci            result = supplementRequestIms_.GetCallWaitingRequest(slotId, index);
559d95e75fdSopenharmony_ci        } else {
560d95e75fdSopenharmony_ci            result = supplementRequestCs_.GetCallWaitingRequest(slotId, index);
561d95e75fdSopenharmony_ci        }
562d95e75fdSopenharmony_ci    }
563d95e75fdSopenharmony_ci    if (result != TELEPHONY_SUCCESS) {
564d95e75fdSopenharmony_ci        ReportMmiCodeMessage(MMI_CODE_FAILED, "", GENERIC_FAILURE);
565d95e75fdSopenharmony_ci    } else {
566d95e75fdSopenharmony_ci        handler->SaveSsRequestCommand(utCommand, index);
567d95e75fdSopenharmony_ci    }
568d95e75fdSopenharmony_ci}
569d95e75fdSopenharmony_ci
570d95e75fdSopenharmony_civoid CellularCallSupplement::EventGetCallWaiting(
571d95e75fdSopenharmony_ci    const CallWaitResult &waitingInfo, const std::string &message, int32_t flag)
572d95e75fdSopenharmony_ci{
573d95e75fdSopenharmony_ci    CallWaitResponse callWaitResponse;
574d95e75fdSopenharmony_ci    callWaitResponse.result = waitingInfo.result.result;
575d95e75fdSopenharmony_ci    if (callWaitResponse.result == IMS_ERROR_UT_NO_CONNECTION) {
576d95e75fdSopenharmony_ci        callWaitResponse.result = CALL_ERR_UT_NO_CONNECTION;
577d95e75fdSopenharmony_ci    }
578d95e75fdSopenharmony_ci
579d95e75fdSopenharmony_ci    /*
580d95e75fdSopenharmony_ci     * <n> (sets/shows the result code presentation status in the TA):
581d95e75fdSopenharmony_ci     * 0	disable
582d95e75fdSopenharmony_ci     * 1	enable
583d95e75fdSopenharmony_ci     */
584d95e75fdSopenharmony_ci    callWaitResponse.status = waitingInfo.status;
585d95e75fdSopenharmony_ci    callWaitResponse.classCw = waitingInfo.classCw;
586d95e75fdSopenharmony_ci    auto callRegister = DelayedSingleton<CellularCallRegister>::GetInstance();
587d95e75fdSopenharmony_ci    if (callRegister == nullptr) {
588d95e75fdSopenharmony_ci        TELEPHONY_LOGE("callRegister is null.");
589d95e75fdSopenharmony_ci        return;
590d95e75fdSopenharmony_ci    }
591d95e75fdSopenharmony_ci    if (flag == SS_FROM_MMI_CODE) {
592d95e75fdSopenharmony_ci        std::string successMessage = GET_CALL_WAITING_SUCCESS;
593d95e75fdSopenharmony_ci        CreateGetCallWaitingResultMessage(successMessage, callWaitResponse);
594d95e75fdSopenharmony_ci        ReportMmiCodeMessage(
595d95e75fdSopenharmony_ci            callWaitResponse.result, successMessage, message.empty() ? GET_CALL_WAITING_FAILED : message);
596d95e75fdSopenharmony_ci    } else {
597d95e75fdSopenharmony_ci        callRegister->ReportGetWaitingResult(callWaitResponse);
598d95e75fdSopenharmony_ci    }
599d95e75fdSopenharmony_ci}
600d95e75fdSopenharmony_ci
601d95e75fdSopenharmony_civoid CellularCallSupplement::EventSetCallWaiting(int32_t result, const std::string &message, int32_t flag)
602d95e75fdSopenharmony_ci{
603d95e75fdSopenharmony_ci    auto callRegister = DelayedSingleton<CellularCallRegister>::GetInstance();
604d95e75fdSopenharmony_ci    if (callRegister == nullptr) {
605d95e75fdSopenharmony_ci        TELEPHONY_LOGE("callRegister is null.");
606d95e75fdSopenharmony_ci        return;
607d95e75fdSopenharmony_ci    }
608d95e75fdSopenharmony_ci    if (flag == SS_FROM_MMI_CODE) {
609d95e75fdSopenharmony_ci        ReportMmiCodeMessage(result, SET_CALL_WAITING_SUCCESS, message.empty() ? SET_CALL_WAITING_FAILED : message);
610d95e75fdSopenharmony_ci    } else {
611d95e75fdSopenharmony_ci        callRegister->ReportSetWaitingResult(result);
612d95e75fdSopenharmony_ci    }
613d95e75fdSopenharmony_ci}
614d95e75fdSopenharmony_ci
615d95e75fdSopenharmony_civoid CellularCallSupplement::EventGetCallTransferInfo(
616d95e75fdSopenharmony_ci    const CallForwardQueryInfoList &cFQueryList, const std::string &message, int32_t flag)
617d95e75fdSopenharmony_ci{
618d95e75fdSopenharmony_ci    if (cFQueryList.result.result != TELEPHONY_SUCCESS && cFQueryList.callSize == 0) {
619d95e75fdSopenharmony_ci        CallForwardQueryResult failResult;
620d95e75fdSopenharmony_ci        failResult.result = cFQueryList.result.result;
621d95e75fdSopenharmony_ci        failResult.reason = cFQueryList.result.reason;
622d95e75fdSopenharmony_ci        BuildCallForwardQueryInfo(failResult, message, flag);
623d95e75fdSopenharmony_ci    }
624d95e75fdSopenharmony_ci    for (auto queryResult : cFQueryList.calls) {
625d95e75fdSopenharmony_ci        TELEPHONY_LOGI("data: status %{public}d, classx %{public}d, reason %{public}d", queryResult.status,
626d95e75fdSopenharmony_ci            queryResult.classx, queryResult.reason);
627d95e75fdSopenharmony_ci        if (queryResult.classx > 0 && (static_cast<uint32_t>(queryResult.classx) & ServiceClassType::VOICE) != 0) {
628d95e75fdSopenharmony_ci            BuildCallForwardQueryInfo(queryResult, message, flag);
629d95e75fdSopenharmony_ci        }
630d95e75fdSopenharmony_ci    }
631d95e75fdSopenharmony_ci}
632d95e75fdSopenharmony_ci
633d95e75fdSopenharmony_civoid CellularCallSupplement::BuildCallForwardQueryInfo(
634d95e75fdSopenharmony_ci    const CallForwardQueryResult &queryResult, const std::string &message, int32_t flag)
635d95e75fdSopenharmony_ci{
636d95e75fdSopenharmony_ci    // 3GPP TS 27.007 V3.9.0 (2001-06) 7.11	Call forwarding number and conditions +CCFC
637d95e75fdSopenharmony_ci    CallTransferResponse response;
638d95e75fdSopenharmony_ci    if (memset_s(&response, sizeof(response), 0, sizeof(response)) != EOK) {
639d95e75fdSopenharmony_ci        TELEPHONY_LOGE("memset_s fail.");
640d95e75fdSopenharmony_ci        return;
641d95e75fdSopenharmony_ci    }
642d95e75fdSopenharmony_ci    // <number>: string type phone number of forwarding address in format specified by <type>
643d95e75fdSopenharmony_ci    if (strcpy_s(response.number, sizeof(response.number), queryResult.number.c_str()) != EOK) {
644d95e75fdSopenharmony_ci        TELEPHONY_LOGE(" strcpy_s fail.");
645d95e75fdSopenharmony_ci        return;
646d95e75fdSopenharmony_ci    }
647d95e75fdSopenharmony_ci    response.result = queryResult.result;
648d95e75fdSopenharmony_ci    /*
649d95e75fdSopenharmony_ci     * <status>:0	not active;    1	  active
650d95e75fdSopenharmony_ci     * */
651d95e75fdSopenharmony_ci    response.status = queryResult.status;
652d95e75fdSopenharmony_ci    /*
653d95e75fdSopenharmony_ci     * <classx> is a sum of integers each representing a class of information (default 7):
654d95e75fdSopenharmony_ci     * 1	voice (telephony)
655d95e75fdSopenharmony_ci     * 2	data (refers to all bearer services)
656d95e75fdSopenharmony_ci     * 4	fax (facsimile services)
657d95e75fdSopenharmony_ci     * 8	short message service
658d95e75fdSopenharmony_ci     * 16	data circuit sync
659d95e75fdSopenharmony_ci     * 32	data circuit async
660d95e75fdSopenharmony_ci     * 64	dedicated packet access
661d95e75fdSopenharmony_ci     * 128	dedicated PAD access
662d95e75fdSopenharmony_ci     */
663d95e75fdSopenharmony_ci    response.classx = queryResult.classx;
664d95e75fdSopenharmony_ci    // <type>: type of address octet in integer format (refer GSM 04.08 [8] subclause 10.5.4.7);
665d95e75fdSopenharmony_ci    // default 145 when dialling string includes international access code character "+", otherwise 129
666d95e75fdSopenharmony_ci    response.type = queryResult.type;
667d95e75fdSopenharmony_ci    response.reason = queryResult.reason;
668d95e75fdSopenharmony_ci    response.time = queryResult.time;
669d95e75fdSopenharmony_ci    response.startHour = queryResult.startHour;
670d95e75fdSopenharmony_ci    response.startMinute = queryResult.startMinute;
671d95e75fdSopenharmony_ci    response.endHour = queryResult.endHour;
672d95e75fdSopenharmony_ci    response.endMinute = queryResult.endMinute;
673d95e75fdSopenharmony_ci    if (flag == SS_FROM_MMI_CODE) {
674d95e75fdSopenharmony_ci        std::string successMessage = GET_CALL_TRANSFER_SUCCESS;
675d95e75fdSopenharmony_ci        CreateGetCallTransferResultMessage(successMessage, response);
676d95e75fdSopenharmony_ci        ReportMmiCodeMessage(queryResult.result, successMessage, message.empty() ? GET_CALL_TRANSFER_FAILED : message);
677d95e75fdSopenharmony_ci    } else {
678d95e75fdSopenharmony_ci        auto callRegister = DelayedSingleton<CellularCallRegister>::GetInstance();
679d95e75fdSopenharmony_ci        if (callRegister == nullptr) {
680d95e75fdSopenharmony_ci            TELEPHONY_LOGE("callRegister is null.");
681d95e75fdSopenharmony_ci            return;
682d95e75fdSopenharmony_ci        }
683d95e75fdSopenharmony_ci        callRegister->ReportGetTransferResult(response);
684d95e75fdSopenharmony_ci    }
685d95e75fdSopenharmony_ci}
686d95e75fdSopenharmony_ci
687d95e75fdSopenharmony_civoid CellularCallSupplement::EventSetCallTransferInfo(int32_t result, const std::string &message, int32_t flag)
688d95e75fdSopenharmony_ci{
689d95e75fdSopenharmony_ci    auto callRegister = DelayedSingleton<CellularCallRegister>::GetInstance();
690d95e75fdSopenharmony_ci    if (callRegister == nullptr) {
691d95e75fdSopenharmony_ci        TELEPHONY_LOGE("callRegister is null.");
692d95e75fdSopenharmony_ci        return;
693d95e75fdSopenharmony_ci    }
694d95e75fdSopenharmony_ci
695d95e75fdSopenharmony_ci    if (flag == SS_FROM_MMI_CODE) {
696d95e75fdSopenharmony_ci        ReportMmiCodeMessage(result, SET_CALL_TRANSFER_SUCCESS, message.empty() ? SET_CALL_TRANSFER_FAILED : message);
697d95e75fdSopenharmony_ci    } else {
698d95e75fdSopenharmony_ci        callRegister->ReportSetTransferResult(result);
699d95e75fdSopenharmony_ci    }
700d95e75fdSopenharmony_ci}
701d95e75fdSopenharmony_ci
702d95e75fdSopenharmony_civoid CellularCallSupplement::EventGetCallRestriction(
703d95e75fdSopenharmony_ci    const CallRestrictionResult &result, const std::string &message, int32_t flag)
704d95e75fdSopenharmony_ci{
705d95e75fdSopenharmony_ci    auto callRegister = DelayedSingleton<CellularCallRegister>::GetInstance();
706d95e75fdSopenharmony_ci    if (callRegister == nullptr) {
707d95e75fdSopenharmony_ci        TELEPHONY_LOGE("callRegister is null.");
708d95e75fdSopenharmony_ci        return;
709d95e75fdSopenharmony_ci    }
710d95e75fdSopenharmony_ci    CallRestrictionResponse response;
711d95e75fdSopenharmony_ci    response.result = result.result.result;
712d95e75fdSopenharmony_ci    if (response.result == IMS_ERROR_UT_NO_CONNECTION) {
713d95e75fdSopenharmony_ci        response.result = CALL_ERR_UT_NO_CONNECTION;
714d95e75fdSopenharmony_ci    }
715d95e75fdSopenharmony_ci
716d95e75fdSopenharmony_ci    /*
717d95e75fdSopenharmony_ci     * <status>:0	not active    1	  active
718d95e75fdSopenharmony_ci     */
719d95e75fdSopenharmony_ci    response.status = result.status;
720d95e75fdSopenharmony_ci    response.classCw = result.classCw;
721d95e75fdSopenharmony_ci
722d95e75fdSopenharmony_ci    if (flag == SS_FROM_MMI_CODE) {
723d95e75fdSopenharmony_ci        std::string successMessage = GET_CALL_RESTRICTION_SUCCESS;
724d95e75fdSopenharmony_ci        CreateSuppSvcQueryResultMessage(successMessage, response.result, response.status);
725d95e75fdSopenharmony_ci        ReportMmiCodeMessage(
726d95e75fdSopenharmony_ci            result.result.result, successMessage, message.empty() ? GET_CALL_RESTRICTION_FAILED : message);
727d95e75fdSopenharmony_ci    } else {
728d95e75fdSopenharmony_ci        callRegister->ReportGetRestrictionResult(response);
729d95e75fdSopenharmony_ci    }
730d95e75fdSopenharmony_ci}
731d95e75fdSopenharmony_ci
732d95e75fdSopenharmony_civoid CellularCallSupplement::EventSetCallRestriction(int32_t result, const std::string &message, int32_t flag)
733d95e75fdSopenharmony_ci{
734d95e75fdSopenharmony_ci    auto callRegister = DelayedSingleton<CellularCallRegister>::GetInstance();
735d95e75fdSopenharmony_ci    if (callRegister == nullptr) {
736d95e75fdSopenharmony_ci        TELEPHONY_LOGE("callRegister is null.");
737d95e75fdSopenharmony_ci        return;
738d95e75fdSopenharmony_ci    }
739d95e75fdSopenharmony_ci    if (flag == SS_FROM_MMI_CODE) {
740d95e75fdSopenharmony_ci        ReportMmiCodeMessage(
741d95e75fdSopenharmony_ci            result, SET_CALL_RESTRICTION_SUCCESS, message.empty() ? SET_CALL_RESTRICTION_FAILED : message);
742d95e75fdSopenharmony_ci    } else {
743d95e75fdSopenharmony_ci        callRegister->ReportSetRestrictionResult(result);
744d95e75fdSopenharmony_ci    }
745d95e75fdSopenharmony_ci}
746d95e75fdSopenharmony_ci
747d95e75fdSopenharmony_civoid CellularCallSupplement::EventSetBarringPassword(int32_t result, const std::string &message, int32_t flag)
748d95e75fdSopenharmony_ci{
749d95e75fdSopenharmony_ci    auto callRegister = DelayedSingleton<CellularCallRegister>::GetInstance();
750d95e75fdSopenharmony_ci    if (callRegister == nullptr) {
751d95e75fdSopenharmony_ci        TELEPHONY_LOGE("callRegister is null.");
752d95e75fdSopenharmony_ci        return;
753d95e75fdSopenharmony_ci    }
754d95e75fdSopenharmony_ci    if (flag == SS_FROM_MMI_CODE) {
755d95e75fdSopenharmony_ci        ReportMmiCodeMessage(
756d95e75fdSopenharmony_ci            result, SET_SET_BARRING_PASSWORD_SUCCESS, message.empty() ? SET_SET_BARRING_PASSWORD_FAILED : message);
757d95e75fdSopenharmony_ci    } else {
758d95e75fdSopenharmony_ci        callRegister->ReportSetBarringPasswordResult(result);
759d95e75fdSopenharmony_ci    }
760d95e75fdSopenharmony_ci}
761d95e75fdSopenharmony_ci
762d95e75fdSopenharmony_ciint32_t CellularCallSupplement::SetCallTransferInfo(int32_t slotId, const CallTransferInfo &cfInfo)
763d95e75fdSopenharmony_ci{
764d95e75fdSopenharmony_ci    int32_t result = CheckSetCallTransferInfo(cfInfo);
765d95e75fdSopenharmony_ci    RadioResponseInfo responseInfo;
766d95e75fdSopenharmony_ci    responseInfo.error = ErrType::ERR_GENERIC_FAILURE;
767d95e75fdSopenharmony_ci    if (result != TELEPHONY_SUCCESS) {
768d95e75fdSopenharmony_ci        return result;
769d95e75fdSopenharmony_ci    }
770d95e75fdSopenharmony_ci    auto handler = DelayedSingleton<CellularCallService>::GetInstance()->GetHandler(slotId);
771d95e75fdSopenharmony_ci    if (handler == nullptr) {
772d95e75fdSopenharmony_ci        TELEPHONY_LOGE("[slot%{public}d] handler is nullptr!", slotId);
773d95e75fdSopenharmony_ci        return TELEPHONY_ERR_LOCAL_PTR_NULL;
774d95e75fdSopenharmony_ci    }
775d95e75fdSopenharmony_ci
776d95e75fdSopenharmony_ci    std::string dialString(cfInfo.transferNum);
777d95e75fdSopenharmony_ci    auto utCommand = std::make_shared<SsRequestCommand>();
778d95e75fdSopenharmony_ci    utCommand->flag = SS_FROM_SETTING_MENU;
779d95e75fdSopenharmony_ci    utCommand->number = dialString;
780d95e75fdSopenharmony_ci    utCommand->cfAction = static_cast<int32_t>(cfInfo.settingType);
781d95e75fdSopenharmony_ci    utCommand->cfReason = static_cast<int32_t>(cfInfo.type);
782d95e75fdSopenharmony_ci    utCommand->classType = ServiceClassType::VOICE;
783d95e75fdSopenharmony_ci    if (NeedUseImsToHandle(slotId)) {
784d95e75fdSopenharmony_ci        return SetCallTransferInfoByIms(slotId, cfInfo, utCommand);
785d95e75fdSopenharmony_ci    }
786d95e75fdSopenharmony_ci
787d95e75fdSopenharmony_ci    if (!PhoneTypeGsmOrNot(slotId)) {
788d95e75fdSopenharmony_ci        TELEPHONY_LOGE("[slot%{public}d] network type is not supported!", slotId);
789d95e75fdSopenharmony_ci        return CALL_ERR_UNSUPPORTED_NETWORK_TYPE;
790d95e75fdSopenharmony_ci    }
791d95e75fdSopenharmony_ci
792d95e75fdSopenharmony_ci    CallTransferParam callTransferParam;
793d95e75fdSopenharmony_ci    callTransferParam.mode = static_cast<int32_t>(cfInfo.settingType);
794d95e75fdSopenharmony_ci    callTransferParam.reason = static_cast<int32_t>(cfInfo.type);
795d95e75fdSopenharmony_ci    callTransferParam.number = dialString;
796d95e75fdSopenharmony_ci    callTransferParam.classx = ServiceClassType::VOICE;
797d95e75fdSopenharmony_ci    int32_t index;
798d95e75fdSopenharmony_ci    handler->RequestSsRequestCommandIndex(index);
799d95e75fdSopenharmony_ci    result = supplementRequestCs_.SetCallTransferRequest(slotId, callTransferParam, index);
800d95e75fdSopenharmony_ci    if (result == TELEPHONY_SUCCESS) {
801d95e75fdSopenharmony_ci        handler->SaveSsRequestCommand(utCommand, index);
802d95e75fdSopenharmony_ci    }
803d95e75fdSopenharmony_ci    return result;
804d95e75fdSopenharmony_ci}
805d95e75fdSopenharmony_ci
806d95e75fdSopenharmony_ciint32_t CellularCallSupplement::CheckSetCallTransferInfo(const CallTransferInfo &cfInfo)
807d95e75fdSopenharmony_ci{
808d95e75fdSopenharmony_ci    if (strlen(cfInfo.transferNum) == 0) {
809d95e75fdSopenharmony_ci        TELEPHONY_LOGE("transferNum is empty!");
810d95e75fdSopenharmony_ci        return TELEPHONY_ERR_ARGUMENT_INVALID;
811d95e75fdSopenharmony_ci    }
812d95e75fdSopenharmony_ci
813d95e75fdSopenharmony_ci    /*
814d95e75fdSopenharmony_ci     * <reason>:
815d95e75fdSopenharmony_ci     * 0   unconditional
816d95e75fdSopenharmony_ci     * 1   mobile busy
817d95e75fdSopenharmony_ci     * 2   no reply
818d95e75fdSopenharmony_ci     * 3   not reachable
819d95e75fdSopenharmony_ci     * 4   all call forwarding (refer 3GPP TS 22.030 [19])
820d95e75fdSopenharmony_ci     * 5   all conditional call forwarding (refer 3GPP TS 22.030 [19])
821d95e75fdSopenharmony_ci     * <mode>:
822d95e75fdSopenharmony_ci     * 0   disable
823d95e75fdSopenharmony_ci     * 1   enable
824d95e75fdSopenharmony_ci     * 2   query status
825d95e75fdSopenharmony_ci     * 3   registration
826d95e75fdSopenharmony_ci     * 4   erasure
827d95e75fdSopenharmony_ci     */
828d95e75fdSopenharmony_ci    if (cfInfo.type > CallTransferType::TRANSFER_TYPE_NOT_REACHABLE ||
829d95e75fdSopenharmony_ci        cfInfo.type < CallTransferType::TRANSFER_TYPE_UNCONDITIONAL ||
830d95e75fdSopenharmony_ci        cfInfo.settingType > CallTransferSettingType::CALL_TRANSFER_ERASURE ||
831d95e75fdSopenharmony_ci        cfInfo.settingType < CallTransferSettingType::CALL_TRANSFER_DISABLE) {
832d95e75fdSopenharmony_ci        TELEPHONY_LOGE("parameter out of range!");
833d95e75fdSopenharmony_ci        return CALL_ERR_PARAMETER_OUT_OF_RANGE;
834d95e75fdSopenharmony_ci    }
835d95e75fdSopenharmony_ci    return TELEPHONY_SUCCESS;
836d95e75fdSopenharmony_ci}
837d95e75fdSopenharmony_ci
838d95e75fdSopenharmony_ciint32_t CellularCallSupplement::SetCallTransferInfoByIms(
839d95e75fdSopenharmony_ci    int32_t slotId, const CallTransferInfo &cfInfo, const std::shared_ptr<SsRequestCommand> &command)
840d95e75fdSopenharmony_ci{
841d95e75fdSopenharmony_ci    auto handler = DelayedSingleton<CellularCallService>::GetInstance()->GetHandler(slotId);
842d95e75fdSopenharmony_ci    RadioResponseInfo responseInfo;
843d95e75fdSopenharmony_ci    responseInfo.error = ErrType::ERR_GENERIC_FAILURE;
844d95e75fdSopenharmony_ci    if (handler == nullptr) {
845d95e75fdSopenharmony_ci        TELEPHONY_LOGE("[slot%{public}d] handler is nullptr!", slotId);
846d95e75fdSopenharmony_ci        return TELEPHONY_ERR_LOCAL_PTR_NULL;
847d95e75fdSopenharmony_ci    }
848d95e75fdSopenharmony_ci    int32_t index;
849d95e75fdSopenharmony_ci    handler->RequestSsRequestCommandIndex(index);
850d95e75fdSopenharmony_ci    int32_t result = supplementRequestIms_.SetCallTransferRequest(slotId, cfInfo, ServiceClassType::VOICE, index);
851d95e75fdSopenharmony_ci    if (result == TELEPHONY_SUCCESS) {
852d95e75fdSopenharmony_ci        handler->SaveSsRequestCommand(command, index);
853d95e75fdSopenharmony_ci    }
854d95e75fdSopenharmony_ci    return result;
855d95e75fdSopenharmony_ci}
856d95e75fdSopenharmony_ci
857d95e75fdSopenharmony_ciint32_t CellularCallSupplement::CanSetCallTransferTime(int32_t slotId, bool &result)
858d95e75fdSopenharmony_ci{
859d95e75fdSopenharmony_ci    if (!moduleServiceUtils_.NeedCallImsService()) {
860d95e75fdSopenharmony_ci        return CALL_ERR_RESOURCE_UNAVAILABLE;
861d95e75fdSopenharmony_ci    }
862d95e75fdSopenharmony_ci    int32_t ret = TELEPHONY_SUCCESS;
863d95e75fdSopenharmony_ci    ret = supplementRequestIms_.CanSetCallTransferTime(slotId, result);
864d95e75fdSopenharmony_ci    return ret;
865d95e75fdSopenharmony_ci}
866d95e75fdSopenharmony_ci
867d95e75fdSopenharmony_ciint32_t CellularCallSupplement::GetCallTransferInfo(int32_t slotId, CallTransferType type)
868d95e75fdSopenharmony_ci{
869d95e75fdSopenharmony_ci    auto handler = DelayedSingleton<CellularCallService>::GetInstance()->GetHandler(slotId);
870d95e75fdSopenharmony_ci    if (handler == nullptr) {
871d95e75fdSopenharmony_ci        TELEPHONY_LOGE("[slot%{public}d] handler is nullptr!", slotId);
872d95e75fdSopenharmony_ci        return TELEPHONY_ERR_LOCAL_PTR_NULL;
873d95e75fdSopenharmony_ci    }
874d95e75fdSopenharmony_ci    int32_t result = TELEPHONY_ERROR;
875d95e75fdSopenharmony_ci    auto utCommand = std::make_shared<SsRequestCommand>();
876d95e75fdSopenharmony_ci    utCommand->flag = SS_FROM_SETTING_MENU;
877d95e75fdSopenharmony_ci    utCommand->cfReason = static_cast<int32_t>(type);
878d95e75fdSopenharmony_ci    int32_t index;
879d95e75fdSopenharmony_ci    if (NeedUseImsToHandle(slotId)) {
880d95e75fdSopenharmony_ci        handler->RequestSsRequestCommandIndex(index);
881d95e75fdSopenharmony_ci        result = supplementRequestIms_.GetCallTransferRequest(slotId, static_cast<int32_t>(type), index);
882d95e75fdSopenharmony_ci        if (result == TELEPHONY_SUCCESS) {
883d95e75fdSopenharmony_ci            handler->SaveSsRequestCommand(utCommand, index);
884d95e75fdSopenharmony_ci        }
885d95e75fdSopenharmony_ci        return result;
886d95e75fdSopenharmony_ci    }
887d95e75fdSopenharmony_ci    if (!PhoneTypeGsmOrNot(slotId)) {
888d95e75fdSopenharmony_ci        TELEPHONY_LOGE("[slot%{public}d] network type is not supported!", slotId);
889d95e75fdSopenharmony_ci        return CALL_ERR_UNSUPPORTED_NETWORK_TYPE;
890d95e75fdSopenharmony_ci    }
891d95e75fdSopenharmony_ci
892d95e75fdSopenharmony_ci    /*
893d95e75fdSopenharmony_ci     * When querying the status of a network service (<mode>=2) the response line for 'not active' case
894d95e75fdSopenharmony_ci     * (<status>=0) should be returned only if service is not active for any <class>
895d95e75fdSopenharmony_ci     */
896d95e75fdSopenharmony_ci    handler->RequestSsRequestCommandIndex(index);
897d95e75fdSopenharmony_ci    result = supplementRequestCs_.GetCallTransferRequest(slotId, static_cast<int32_t>(type), index);
898d95e75fdSopenharmony_ci    if (result == TELEPHONY_SUCCESS) {
899d95e75fdSopenharmony_ci        handler->SaveSsRequestCommand(utCommand, index);
900d95e75fdSopenharmony_ci    }
901d95e75fdSopenharmony_ci    return result;
902d95e75fdSopenharmony_ci}
903d95e75fdSopenharmony_ci
904d95e75fdSopenharmony_cibool CellularCallSupplement::PhoneTypeGsmOrNot(int32_t slotId)
905d95e75fdSopenharmony_ci{
906d95e75fdSopenharmony_ci    return moduleServiceUtils_.GetNetworkStatus(slotId) == PhoneType::PHONE_TYPE_IS_GSM;
907d95e75fdSopenharmony_ci}
908d95e75fdSopenharmony_ci
909d95e75fdSopenharmony_cibool CellularCallSupplement::NeedUseImsToHandle(int32_t slotId)
910d95e75fdSopenharmony_ci{
911d95e75fdSopenharmony_ci    return moduleServiceUtils_.NeedCallImsService() && moduleServiceUtils_.GetImsUtSupportState(slotId);
912d95e75fdSopenharmony_ci}
913d95e75fdSopenharmony_ci
914d95e75fdSopenharmony_ciint32_t CellularCallSupplement::SetCallWaiting(int32_t slotId, bool activate)
915d95e75fdSopenharmony_ci{
916d95e75fdSopenharmony_ci    RadioResponseInfo responseInfo;
917d95e75fdSopenharmony_ci    responseInfo.error = ErrType::ERR_GENERIC_FAILURE;
918d95e75fdSopenharmony_ci    auto handler = DelayedSingleton<CellularCallService>::GetInstance()->GetHandler(slotId);
919d95e75fdSopenharmony_ci    if (handler == nullptr) {
920d95e75fdSopenharmony_ci        TELEPHONY_LOGE("[slot%{public}d] handler is nullptr!", slotId);
921d95e75fdSopenharmony_ci        return TELEPHONY_ERR_LOCAL_PTR_NULL;
922d95e75fdSopenharmony_ci    }
923d95e75fdSopenharmony_ci    int32_t classType = ServiceClassType::VOICE;
924d95e75fdSopenharmony_ci    CellularCallConfig config;
925d95e75fdSopenharmony_ci    classType = config.GetCallWaitingServiceClassConfig(slotId);
926d95e75fdSopenharmony_ci    int32_t result = TELEPHONY_ERROR;
927d95e75fdSopenharmony_ci    auto utCommand = std::make_shared<SsRequestCommand>();
928d95e75fdSopenharmony_ci    utCommand->flag = SS_FROM_SETTING_MENU;
929d95e75fdSopenharmony_ci    utCommand->classType = classType;
930d95e75fdSopenharmony_ci    utCommand->enable = activate;
931d95e75fdSopenharmony_ci    int32_t index;
932d95e75fdSopenharmony_ci    if (NeedUseImsToHandle(slotId)) {
933d95e75fdSopenharmony_ci        handler->RequestSsRequestCommandIndex(index);
934d95e75fdSopenharmony_ci        result = supplementRequestIms_.SetCallWaitingRequest(slotId, activate, classType, index);
935d95e75fdSopenharmony_ci        if (result == TELEPHONY_SUCCESS) {
936d95e75fdSopenharmony_ci            handler->SaveSsRequestCommand(utCommand, index);
937d95e75fdSopenharmony_ci        }
938d95e75fdSopenharmony_ci        return result;
939d95e75fdSopenharmony_ci    }
940d95e75fdSopenharmony_ci    /*
941d95e75fdSopenharmony_ci     * <n> (sets/shows the result code presentation status in the TA):
942d95e75fdSopenharmony_ci     * 0	disable
943d95e75fdSopenharmony_ci     * 1	enable
944d95e75fdSopenharmony_ci     */
945d95e75fdSopenharmony_ci    if (!PhoneTypeGsmOrNot(slotId)) {
946d95e75fdSopenharmony_ci        TELEPHONY_LOGE("[slot%{public}d] network type is not supported!", slotId);
947d95e75fdSopenharmony_ci        return CALL_ERR_UNSUPPORTED_NETWORK_TYPE;
948d95e75fdSopenharmony_ci    }
949d95e75fdSopenharmony_ci    handler->RequestSsRequestCommandIndex(index);
950d95e75fdSopenharmony_ci    result = supplementRequestCs_.SetCallWaitingRequest(slotId, activate, classType, index);
951d95e75fdSopenharmony_ci    if (result == TELEPHONY_SUCCESS) {
952d95e75fdSopenharmony_ci        handler->SaveSsRequestCommand(utCommand, index);
953d95e75fdSopenharmony_ci    }
954d95e75fdSopenharmony_ci    return result;
955d95e75fdSopenharmony_ci}
956d95e75fdSopenharmony_ci
957d95e75fdSopenharmony_ciint32_t CellularCallSupplement::GetCallWaiting(int32_t slotId)
958d95e75fdSopenharmony_ci{
959d95e75fdSopenharmony_ci    auto handler = DelayedSingleton<CellularCallService>::GetInstance()->GetHandler(slotId);
960d95e75fdSopenharmony_ci    if (handler == nullptr) {
961d95e75fdSopenharmony_ci        TELEPHONY_LOGE("[slot%{public}d] handler is nullptr!", slotId);
962d95e75fdSopenharmony_ci        return TELEPHONY_ERR_LOCAL_PTR_NULL;
963d95e75fdSopenharmony_ci    }
964d95e75fdSopenharmony_ci    int32_t result = TELEPHONY_ERROR;
965d95e75fdSopenharmony_ci    auto utCommand = std::make_shared<SsRequestCommand>();
966d95e75fdSopenharmony_ci    utCommand->flag = SS_FROM_SETTING_MENU;
967d95e75fdSopenharmony_ci    int32_t index;
968d95e75fdSopenharmony_ci    if (NeedUseImsToHandle(slotId)) {
969d95e75fdSopenharmony_ci        handler->RequestSsRequestCommandIndex(index);
970d95e75fdSopenharmony_ci        result = supplementRequestIms_.GetCallWaitingRequest(slotId, index);
971d95e75fdSopenharmony_ci        if (result == TELEPHONY_SUCCESS) {
972d95e75fdSopenharmony_ci            handler->SaveSsRequestCommand(utCommand, index);
973d95e75fdSopenharmony_ci        }
974d95e75fdSopenharmony_ci        return result;
975d95e75fdSopenharmony_ci    }
976d95e75fdSopenharmony_ci    if (!PhoneTypeGsmOrNot(slotId)) {
977d95e75fdSopenharmony_ci        TELEPHONY_LOGE("[slot%{public}d] network type is not supported!", slotId);
978d95e75fdSopenharmony_ci        return CALL_ERR_UNSUPPORTED_NETWORK_TYPE;
979d95e75fdSopenharmony_ci    }
980d95e75fdSopenharmony_ci    handler->RequestSsRequestCommandIndex(index);
981d95e75fdSopenharmony_ci    result = supplementRequestCs_.GetCallWaitingRequest(slotId, index);
982d95e75fdSopenharmony_ci    if (result == TELEPHONY_SUCCESS) {
983d95e75fdSopenharmony_ci        handler->SaveSsRequestCommand(utCommand, index);
984d95e75fdSopenharmony_ci    }
985d95e75fdSopenharmony_ci    return result;
986d95e75fdSopenharmony_ci}
987d95e75fdSopenharmony_ci
988d95e75fdSopenharmony_ciint32_t CellularCallSupplement::SetCallRestriction(int32_t slotId, const CallRestrictionInfo &cRInfo)
989d95e75fdSopenharmony_ci{
990d95e75fdSopenharmony_ci    RadioResponseInfo responseInfo;
991d95e75fdSopenharmony_ci    responseInfo.error = ErrType::ERR_GENERIC_FAILURE;
992d95e75fdSopenharmony_ci    std::string fac;
993d95e75fdSopenharmony_ci    int32_t result = CheckCallRestrictionType(fac, cRInfo.fac);
994d95e75fdSopenharmony_ci    if (result != TELEPHONY_SUCCESS) {
995d95e75fdSopenharmony_ci        return result;
996d95e75fdSopenharmony_ci    }
997d95e75fdSopenharmony_ci    if (cRInfo.mode < CallRestrictionMode::RESTRICTION_MODE_DEACTIVATION ||
998d95e75fdSopenharmony_ci        cRInfo.mode > CallRestrictionMode::RESTRICTION_MODE_ACTIVATION) {
999d95e75fdSopenharmony_ci        TELEPHONY_LOGE("[slot%{public}d] mode parameter out of range!", slotId);
1000d95e75fdSopenharmony_ci        return CALL_ERR_PARAMETER_OUT_OF_RANGE;
1001d95e75fdSopenharmony_ci    }
1002d95e75fdSopenharmony_ci    auto handler = DelayedSingleton<CellularCallService>::GetInstance()->GetHandler(slotId);
1003d95e75fdSopenharmony_ci    if (handler == nullptr) {
1004d95e75fdSopenharmony_ci        TELEPHONY_LOGE("[slot%{public}d] handler is nullptr!", slotId);
1005d95e75fdSopenharmony_ci        return TELEPHONY_ERR_LOCAL_PTR_NULL;
1006d95e75fdSopenharmony_ci    }
1007d95e75fdSopenharmony_ci    std::string info(cRInfo.password);
1008d95e75fdSopenharmony_ci    auto utCommand = std::make_shared<SsRequestCommand>();
1009d95e75fdSopenharmony_ci    utCommand->flag = SS_FROM_SETTING_MENU;
1010d95e75fdSopenharmony_ci    utCommand->facility = fac;
1011d95e75fdSopenharmony_ci    utCommand->enable = static_cast<int32_t>(cRInfo.mode);
1012d95e75fdSopenharmony_ci    size_t cpyLen = strlen(info.c_str()) + 1;
1013d95e75fdSopenharmony_ci    size_t maxCpyLen = sizeof(utCommand->password);
1014d95e75fdSopenharmony_ci    if (strcpy_s(utCommand->password, cpyLen > maxCpyLen ? maxCpyLen : cpyLen, info.c_str()) != EOK) {
1015d95e75fdSopenharmony_ci        TELEPHONY_LOGE("[slot%{public}d] strcpy_s fail.", slotId);
1016d95e75fdSopenharmony_ci        return TELEPHONY_ERR_STRCPY_FAIL;
1017d95e75fdSopenharmony_ci    }
1018d95e75fdSopenharmony_ci    int32_t index;
1019d95e75fdSopenharmony_ci    if (NeedUseImsToHandle(slotId)) {
1020d95e75fdSopenharmony_ci        return SetCallRestrictionByIms(slotId, fac, static_cast<int32_t>(cRInfo.mode), info, utCommand);
1021d95e75fdSopenharmony_ci    }
1022d95e75fdSopenharmony_ci    if (!PhoneTypeGsmOrNot(slotId)) {
1023d95e75fdSopenharmony_ci        TELEPHONY_LOGE("[slot%{public}d] network type is not supported!", slotId);
1024d95e75fdSopenharmony_ci        return CALL_ERR_UNSUPPORTED_NETWORK_TYPE;
1025d95e75fdSopenharmony_ci    }
1026d95e75fdSopenharmony_ci    handler->RequestSsRequestCommandIndex(index);
1027d95e75fdSopenharmony_ci    result =
1028d95e75fdSopenharmony_ci        supplementRequestCs_.SetCallRestrictionRequest(slotId, fac, static_cast<int32_t>(cRInfo.mode), info, index);
1029d95e75fdSopenharmony_ci    if (result == TELEPHONY_SUCCESS) {
1030d95e75fdSopenharmony_ci        handler->SaveSsRequestCommand(utCommand, index);
1031d95e75fdSopenharmony_ci    }
1032d95e75fdSopenharmony_ci    return result;
1033d95e75fdSopenharmony_ci}
1034d95e75fdSopenharmony_ci
1035d95e75fdSopenharmony_ciint32_t CellularCallSupplement::SetCallRestrictionByIms(
1036d95e75fdSopenharmony_ci    int32_t slotId, std::string &fac, int32_t mode, std::string &pw, const std::shared_ptr<SsRequestCommand> &command)
1037d95e75fdSopenharmony_ci{
1038d95e75fdSopenharmony_ci    RadioResponseInfo responseInfo;
1039d95e75fdSopenharmony_ci    responseInfo.error = ErrType::ERR_GENERIC_FAILURE;
1040d95e75fdSopenharmony_ci    auto handler = DelayedSingleton<CellularCallService>::GetInstance()->GetHandler(slotId);
1041d95e75fdSopenharmony_ci    if (handler == nullptr) {
1042d95e75fdSopenharmony_ci        TELEPHONY_LOGE("[slot%{public}d] handler is nullptr!", slotId);
1043d95e75fdSopenharmony_ci        return TELEPHONY_ERR_LOCAL_PTR_NULL;
1044d95e75fdSopenharmony_ci    }
1045d95e75fdSopenharmony_ci    int32_t index;
1046d95e75fdSopenharmony_ci    handler->RequestSsRequestCommandIndex(index);
1047d95e75fdSopenharmony_ci    int32_t result = supplementRequestIms_.SetCallRestrictionRequest(slotId, fac, mode, pw, index);
1048d95e75fdSopenharmony_ci    if (result == TELEPHONY_SUCCESS) {
1049d95e75fdSopenharmony_ci        handler->SaveSsRequestCommand(command, index);
1050d95e75fdSopenharmony_ci    }
1051d95e75fdSopenharmony_ci    return result;
1052d95e75fdSopenharmony_ci}
1053d95e75fdSopenharmony_ci
1054d95e75fdSopenharmony_ciint32_t CellularCallSupplement::GetCallRestriction(int32_t slotId, CallRestrictionType facType)
1055d95e75fdSopenharmony_ci{
1056d95e75fdSopenharmony_ci    std::string fac;
1057d95e75fdSopenharmony_ci    int32_t result = CheckCallRestrictionType(fac, facType);
1058d95e75fdSopenharmony_ci    if (result != TELEPHONY_SUCCESS) {
1059d95e75fdSopenharmony_ci        return result;
1060d95e75fdSopenharmony_ci    }
1061d95e75fdSopenharmony_ci    auto handler = DelayedSingleton<CellularCallService>::GetInstance()->GetHandler(slotId);
1062d95e75fdSopenharmony_ci    if (handler == nullptr) {
1063d95e75fdSopenharmony_ci        TELEPHONY_LOGE("[slot%{public}d] handler is nullptr!", slotId);
1064d95e75fdSopenharmony_ci        return TELEPHONY_ERR_LOCAL_PTR_NULL;
1065d95e75fdSopenharmony_ci    }
1066d95e75fdSopenharmony_ci    auto utCommand = std::make_shared<SsRequestCommand>();
1067d95e75fdSopenharmony_ci    utCommand->flag = SS_FROM_SETTING_MENU;
1068d95e75fdSopenharmony_ci    utCommand->facility = fac;
1069d95e75fdSopenharmony_ci    int32_t index;
1070d95e75fdSopenharmony_ci    if (NeedUseImsToHandle(slotId)) {
1071d95e75fdSopenharmony_ci        handler->RequestSsRequestCommandIndex(index);
1072d95e75fdSopenharmony_ci        result = supplementRequestIms_.GetCallRestrictionRequest(slotId, fac, index);
1073d95e75fdSopenharmony_ci        if (result == TELEPHONY_SUCCESS) {
1074d95e75fdSopenharmony_ci            handler->SaveSsRequestCommand(utCommand, index);
1075d95e75fdSopenharmony_ci        }
1076d95e75fdSopenharmony_ci        return result;
1077d95e75fdSopenharmony_ci    }
1078d95e75fdSopenharmony_ci    if (!PhoneTypeGsmOrNot(slotId)) {
1079d95e75fdSopenharmony_ci        TELEPHONY_LOGE("[slot%{public}d] network type is not supported!", slotId);
1080d95e75fdSopenharmony_ci        return CALL_ERR_UNSUPPORTED_NETWORK_TYPE;
1081d95e75fdSopenharmony_ci    }
1082d95e75fdSopenharmony_ci    handler->RequestSsRequestCommandIndex(index);
1083d95e75fdSopenharmony_ci    result = supplementRequestCs_.GetCallRestrictionRequest(slotId, fac, index);
1084d95e75fdSopenharmony_ci    if (result == TELEPHONY_SUCCESS) {
1085d95e75fdSopenharmony_ci        handler->SaveSsRequestCommand(utCommand, index);
1086d95e75fdSopenharmony_ci    }
1087d95e75fdSopenharmony_ci    return result;
1088d95e75fdSopenharmony_ci}
1089d95e75fdSopenharmony_ci
1090d95e75fdSopenharmony_ciint32_t CellularCallSupplement::SetBarringPassword(
1091d95e75fdSopenharmony_ci    int32_t slotId, CallRestrictionType facType, const char *oldPassword, const char *newPassword)
1092d95e75fdSopenharmony_ci{
1093d95e75fdSopenharmony_ci    std::string fac;
1094d95e75fdSopenharmony_ci    int32_t result = CheckCallRestrictionType(fac, facType);
1095d95e75fdSopenharmony_ci    if (result != TELEPHONY_SUCCESS) {
1096d95e75fdSopenharmony_ci        return result;
1097d95e75fdSopenharmony_ci    }
1098d95e75fdSopenharmony_ci    auto handler = DelayedSingleton<CellularCallService>::GetInstance()->GetHandler(slotId);
1099d95e75fdSopenharmony_ci    if (handler == nullptr) {
1100d95e75fdSopenharmony_ci        TELEPHONY_LOGE("[slot%{public}d] handler is nullptr!", slotId);
1101d95e75fdSopenharmony_ci        return TELEPHONY_ERR_LOCAL_PTR_NULL;
1102d95e75fdSopenharmony_ci    }
1103d95e75fdSopenharmony_ci    auto utCommand = std::make_shared<SsRequestCommand>();
1104d95e75fdSopenharmony_ci    utCommand->flag = SS_FROM_SETTING_MENU;
1105d95e75fdSopenharmony_ci    utCommand->facility = fac;
1106d95e75fdSopenharmony_ci    if (!PhoneTypeGsmOrNot(slotId)) {
1107d95e75fdSopenharmony_ci        TELEPHONY_LOGE("[slot%{public}d] network type is not supported!", slotId);
1108d95e75fdSopenharmony_ci        return CALL_ERR_UNSUPPORTED_NETWORK_TYPE;
1109d95e75fdSopenharmony_ci    }
1110d95e75fdSopenharmony_ci    int32_t index;
1111d95e75fdSopenharmony_ci    handler->RequestSsRequestCommandIndex(index);
1112d95e75fdSopenharmony_ci    result = supplementRequestCs_.SetBarringPasswordRequest(slotId, fac, index, oldPassword, newPassword);
1113d95e75fdSopenharmony_ci    if (result == TELEPHONY_SUCCESS) {
1114d95e75fdSopenharmony_ci        handler->SaveSsRequestCommand(utCommand, index);
1115d95e75fdSopenharmony_ci    }
1116d95e75fdSopenharmony_ci    return result;
1117d95e75fdSopenharmony_ci}
1118d95e75fdSopenharmony_ci
1119d95e75fdSopenharmony_ciint32_t CellularCallSupplement::CheckCallRestrictionType(std::string &fac, const CallRestrictionType &facType)
1120d95e75fdSopenharmony_ci{
1121d95e75fdSopenharmony_ci    /*
1122d95e75fdSopenharmony_ci     * <fac> values reserved by the present document:
1123d95e75fdSopenharmony_ci     * "SC"	SIM (lock SIM/UICC card) (SIM/UICC asks password in ME power up and when this lock command issued)
1124d95e75fdSopenharmony_ci     * "AO"	BAOC (Barr All Outgoing Calls) (refer 3GPP TS 22.088 [6] clause 1)
1125d95e75fdSopenharmony_ci     * "OI"	BOIC (Barr Outgoing International Calls) (refer 3GPP TS 22.088 [6] clause 1)
1126d95e75fdSopenharmony_ci     * "OX"	BOIC exHC (Barr Outgoing International Calls except to Home Country) (refer 3GPP TS 22.088 [6] clause 1)
1127d95e75fdSopenharmony_ci     * "AI"	BAIC (Barr All Incoming Calls) (refer 3GPP TS 22.088 [6] clause 2)
1128d95e75fdSopenharmony_ci     * "IR"	BIC Roam (Barr Incoming Calls when Roaming outside the home country) (refer 3GPP TS 22.088 [6] clause 2)
1129d95e75fdSopenharmony_ci     * "AB"	All Barring services (refer 3GPP TS 22.030 [19]) (applicable only for <mode>=0)
1130d95e75fdSopenharmony_ci     * "AG"	All outGoing barring services (refer 3GPP TS 22.030 [19]) (applicable only for <mode>=0)
1131d95e75fdSopenharmony_ci     * "AC"	All inComing barring services (refer 3GPP TS 22.030 [19]) (applicable only for <mode>=0)
1132d95e75fdSopenharmony_ci     */
1133d95e75fdSopenharmony_ci    switch (facType) {
1134d95e75fdSopenharmony_ci        case CallRestrictionType::RESTRICTION_TYPE_ALL_OUTGOING:
1135d95e75fdSopenharmony_ci            fac = BARR_ALL_OUTGOING_CALLS;
1136d95e75fdSopenharmony_ci            break;
1137d95e75fdSopenharmony_ci        case CallRestrictionType::RESTRICTION_TYPE_INTERNATIONAL:
1138d95e75fdSopenharmony_ci            fac = BARR_OUTGOING_INTERNATIONAL_CALLS;
1139d95e75fdSopenharmony_ci            break;
1140d95e75fdSopenharmony_ci        case CallRestrictionType::RESTRICTION_TYPE_INTERNATIONAL_EXCLUDING_HOME:
1141d95e75fdSopenharmony_ci            fac = BARR_OUTGOING_INTERNATIONAL_CALLS_EXCLUDING_HOME;
1142d95e75fdSopenharmony_ci            break;
1143d95e75fdSopenharmony_ci        case CallRestrictionType::RESTRICTION_TYPE_ALL_INCOMING:
1144d95e75fdSopenharmony_ci            fac = BARR_ALL_INCOMING_CALLS;
1145d95e75fdSopenharmony_ci            break;
1146d95e75fdSopenharmony_ci        case CallRestrictionType::RESTRICTION_TYPE_ROAMING_INCOMING:
1147d95e75fdSopenharmony_ci            fac = BARR_INCOMING_CALLS_OUTSIDE_HOME;
1148d95e75fdSopenharmony_ci            break;
1149d95e75fdSopenharmony_ci        case CallRestrictionType::RESTRICTION_TYPE_ALL_CALLS:
1150d95e75fdSopenharmony_ci            fac = ALL_BARRING_SERVICES;
1151d95e75fdSopenharmony_ci            break;
1152d95e75fdSopenharmony_ci        case CallRestrictionType::RESTRICTION_TYPE_OUTGOING_SERVICES:
1153d95e75fdSopenharmony_ci            fac = ALL_OUTGOING_BARRING_SERVICES;
1154d95e75fdSopenharmony_ci            break;
1155d95e75fdSopenharmony_ci        case CallRestrictionType::RESTRICTION_TYPE_INCOMING_SERVICES:
1156d95e75fdSopenharmony_ci            fac = ALL_INCOMING_BARRING_SERVICES;
1157d95e75fdSopenharmony_ci            break;
1158d95e75fdSopenharmony_ci        default:
1159d95e75fdSopenharmony_ci            TELEPHONY_LOGE("parameter out of range!");
1160d95e75fdSopenharmony_ci            return CALL_ERR_PARAMETER_OUT_OF_RANGE;
1161d95e75fdSopenharmony_ci    }
1162d95e75fdSopenharmony_ci    return TELEPHONY_SUCCESS;
1163d95e75fdSopenharmony_ci}
1164d95e75fdSopenharmony_ci
1165d95e75fdSopenharmony_civoid CellularCallSupplement::EventGetClip(const GetClipResult &getClipResult, const std::string &message, int32_t flag)
1166d95e75fdSopenharmony_ci{
1167d95e75fdSopenharmony_ci    ClipResponse clipResponse;
1168d95e75fdSopenharmony_ci    clipResponse.result = getClipResult.result.result;
1169d95e75fdSopenharmony_ci    if (clipResponse.result == IMS_ERROR_UT_NO_CONNECTION) {
1170d95e75fdSopenharmony_ci        clipResponse.result = CALL_ERR_UT_NO_CONNECTION;
1171d95e75fdSopenharmony_ci    }
1172d95e75fdSopenharmony_ci    clipResponse.action = getClipResult.action;
1173d95e75fdSopenharmony_ci    clipResponse.clipStat = getClipResult.clipStat;
1174d95e75fdSopenharmony_ci    auto callRegister = DelayedSingleton<CellularCallRegister>::GetInstance();
1175d95e75fdSopenharmony_ci    if (callRegister == nullptr) {
1176d95e75fdSopenharmony_ci        TELEPHONY_LOGE("callRegister is null.");
1177d95e75fdSopenharmony_ci        return;
1178d95e75fdSopenharmony_ci    }
1179d95e75fdSopenharmony_ci
1180d95e75fdSopenharmony_ci    if (flag == SS_FROM_MMI_CODE) {
1181d95e75fdSopenharmony_ci        std::string successMessage = GET_CLIP_SUCCESS;
1182d95e75fdSopenharmony_ci        CreateSuppSvcQueryResultMessage(successMessage, clipResponse.result, clipResponse.clipStat);
1183d95e75fdSopenharmony_ci        ReportMmiCodeMessage(clipResponse.result, successMessage, message.empty() ? GET_CLIP_FAILED : message);
1184d95e75fdSopenharmony_ci    } else {
1185d95e75fdSopenharmony_ci        callRegister->ReportGetClipResult(clipResponse);
1186d95e75fdSopenharmony_ci    }
1187d95e75fdSopenharmony_ci}
1188d95e75fdSopenharmony_ci
1189d95e75fdSopenharmony_civoid CellularCallSupplement::EventSetClip(int32_t result, const std::string &message, int32_t flag)
1190d95e75fdSopenharmony_ci{
1191d95e75fdSopenharmony_ci    if (flag == SS_FROM_MMI_CODE) {
1192d95e75fdSopenharmony_ci        ReportMmiCodeMessage(result, SET_CLIP_SUCCESS, message.empty() ? SET_CLIP_FAILED : message);
1193d95e75fdSopenharmony_ci    } else {
1194d95e75fdSopenharmony_ci        TELEPHONY_LOGE("report the result of GetColp failed since the flag %{public}d was wrong", flag);
1195d95e75fdSopenharmony_ci    }
1196d95e75fdSopenharmony_ci}
1197d95e75fdSopenharmony_ci
1198d95e75fdSopenharmony_civoid CellularCallSupplement::EventGetClir(const GetClirResult &result, const std::string &message, int32_t flag)
1199d95e75fdSopenharmony_ci{
1200d95e75fdSopenharmony_ci    ClirResponse response;
1201d95e75fdSopenharmony_ci    // 3GPP TS 27.007 V3.9.0 (2001-06) 7.7	Calling line identification restriction +CLIR
1202d95e75fdSopenharmony_ci    response.result = result.result.result;
1203d95e75fdSopenharmony_ci    if (response.result == IMS_ERROR_UT_NO_CONNECTION) {
1204d95e75fdSopenharmony_ci        response.result = CALL_ERR_UT_NO_CONNECTION;
1205d95e75fdSopenharmony_ci    }
1206d95e75fdSopenharmony_ci    response.action = result.action;
1207d95e75fdSopenharmony_ci    response.clirStat = result.clirStat;
1208d95e75fdSopenharmony_ci    auto callRegister = DelayedSingleton<CellularCallRegister>::GetInstance();
1209d95e75fdSopenharmony_ci    if (callRegister == nullptr) {
1210d95e75fdSopenharmony_ci        TELEPHONY_LOGE("callRegister is null.");
1211d95e75fdSopenharmony_ci        return;
1212d95e75fdSopenharmony_ci    }
1213d95e75fdSopenharmony_ci    if (flag == SS_FROM_MMI_CODE) {
1214d95e75fdSopenharmony_ci        std::string successMessage = GET_CLIR_SUCCESS;
1215d95e75fdSopenharmony_ci        CreateGetClirResultMessage(successMessage, response);
1216d95e75fdSopenharmony_ci        ReportMmiCodeMessage(response.result, successMessage, message.empty() ? GET_CLIR_FAILED : message);
1217d95e75fdSopenharmony_ci    } else {
1218d95e75fdSopenharmony_ci        callRegister->ReportGetClirResult(response);
1219d95e75fdSopenharmony_ci    }
1220d95e75fdSopenharmony_ci}
1221d95e75fdSopenharmony_ci
1222d95e75fdSopenharmony_civoid CellularCallSupplement::EventSetClir(int32_t result, const std::string &message, int32_t flag)
1223d95e75fdSopenharmony_ci{
1224d95e75fdSopenharmony_ci    auto callRegister = DelayedSingleton<CellularCallRegister>::GetInstance();
1225d95e75fdSopenharmony_ci    if (callRegister == nullptr) {
1226d95e75fdSopenharmony_ci        TELEPHONY_LOGE("callRegister is null.");
1227d95e75fdSopenharmony_ci        return;
1228d95e75fdSopenharmony_ci    }
1229d95e75fdSopenharmony_ci    if (flag == SS_FROM_MMI_CODE) {
1230d95e75fdSopenharmony_ci        ReportMmiCodeMessage(result, SET_CLIR_SUCCESS, message.empty() ? SET_CLIR_FAILED : message);
1231d95e75fdSopenharmony_ci    } else {
1232d95e75fdSopenharmony_ci        callRegister->ReportSetClirResult(result);
1233d95e75fdSopenharmony_ci    }
1234d95e75fdSopenharmony_ci}
1235d95e75fdSopenharmony_ci
1236d95e75fdSopenharmony_civoid CellularCallSupplement::EventGetColr(const GetColrResult &result, const std::string &message, int32_t flag)
1237d95e75fdSopenharmony_ci{
1238d95e75fdSopenharmony_ci    ColrResponse response;
1239d95e75fdSopenharmony_ci    response.result = result.result.result;
1240d95e75fdSopenharmony_ci    if (response.result == IMS_ERROR_UT_NO_CONNECTION) {
1241d95e75fdSopenharmony_ci        response.result = CALL_ERR_UT_NO_CONNECTION;
1242d95e75fdSopenharmony_ci    }
1243d95e75fdSopenharmony_ci    response.action = result.action;
1244d95e75fdSopenharmony_ci    response.colrStat = result.colrStat;
1245d95e75fdSopenharmony_ci    if (flag == SS_FROM_MMI_CODE) {
1246d95e75fdSopenharmony_ci        std::string successMessage = GET_COLR_SUCCESS;
1247d95e75fdSopenharmony_ci        CreateSuppSvcQueryResultMessage(successMessage, response.result, response.colrStat);
1248d95e75fdSopenharmony_ci        ReportMmiCodeMessage(response.result, successMessage, message.empty() ? GET_COLR_FAILED : message);
1249d95e75fdSopenharmony_ci    } else {
1250d95e75fdSopenharmony_ci        TELEPHONY_LOGE("report the result of GetColp failed since the flag %{public}d was wrong", flag);
1251d95e75fdSopenharmony_ci    }
1252d95e75fdSopenharmony_ci}
1253d95e75fdSopenharmony_ci
1254d95e75fdSopenharmony_civoid CellularCallSupplement::EventSetColr(int32_t result, const std::string &message, int32_t flag)
1255d95e75fdSopenharmony_ci{
1256d95e75fdSopenharmony_ci    if (flag == SS_FROM_MMI_CODE) {
1257d95e75fdSopenharmony_ci        ReportMmiCodeMessage(result, SET_COLR_SUCCESS, message.empty() ? SET_COLR_FAILED : message);
1258d95e75fdSopenharmony_ci    } else {
1259d95e75fdSopenharmony_ci        TELEPHONY_LOGE("report the result of GetColp failed since the flag %{public}d was wrong", flag);
1260d95e75fdSopenharmony_ci    }
1261d95e75fdSopenharmony_ci}
1262d95e75fdSopenharmony_ci
1263d95e75fdSopenharmony_civoid CellularCallSupplement::EventGetColp(const GetColpResult &result, const std::string &message, int32_t flag)
1264d95e75fdSopenharmony_ci{
1265d95e75fdSopenharmony_ci    ColpResponse response;
1266d95e75fdSopenharmony_ci    response.result = result.result.result;
1267d95e75fdSopenharmony_ci    if (response.result == IMS_ERROR_UT_NO_CONNECTION) {
1268d95e75fdSopenharmony_ci        response.result = CALL_ERR_UT_NO_CONNECTION;
1269d95e75fdSopenharmony_ci    }
1270d95e75fdSopenharmony_ci    response.action = result.action;
1271d95e75fdSopenharmony_ci    response.colpStat = result.colpStat;
1272d95e75fdSopenharmony_ci    if (flag == SS_FROM_MMI_CODE) {
1273d95e75fdSopenharmony_ci        std::string successMessage = GET_COLP_SUCCESS;
1274d95e75fdSopenharmony_ci        CreateSuppSvcQueryResultMessage(successMessage, response.result, response.colpStat);
1275d95e75fdSopenharmony_ci        ReportMmiCodeMessage(response.result, successMessage, message.empty() ? GET_COLP_FAILED : message);
1276d95e75fdSopenharmony_ci    } else {
1277d95e75fdSopenharmony_ci        TELEPHONY_LOGE("report the result of GetColp failed since the flag %{public}d was wrong", flag);
1278d95e75fdSopenharmony_ci    }
1279d95e75fdSopenharmony_ci}
1280d95e75fdSopenharmony_ci
1281d95e75fdSopenharmony_civoid CellularCallSupplement::EventSetColp(int32_t result, const std::string &message, int32_t flag)
1282d95e75fdSopenharmony_ci{
1283d95e75fdSopenharmony_ci    if (flag == SS_FROM_MMI_CODE) {
1284d95e75fdSopenharmony_ci        ReportMmiCodeMessage(result, SET_COLP_SUCCESS, message.empty() ? SET_COLP_FAILED : message);
1285d95e75fdSopenharmony_ci    } else {
1286d95e75fdSopenharmony_ci        TELEPHONY_LOGE("report the result of GetColp failed since the flag %{public}d was wrong", flag);
1287d95e75fdSopenharmony_ci    }
1288d95e75fdSopenharmony_ci}
1289d95e75fdSopenharmony_ci
1290d95e75fdSopenharmony_ciint32_t CellularCallSupplement::SendUssd(int32_t slotId, const std::string &msg)
1291d95e75fdSopenharmony_ci{
1292d95e75fdSopenharmony_ci    if (!PhoneTypeGsmOrNot(slotId)) {
1293d95e75fdSopenharmony_ci        ReportMmiCodeMessage(MMI_CODE_FAILED, "", GENERIC_FAILURE);
1294d95e75fdSopenharmony_ci        TELEPHONY_LOGE("[slot%{public}d] network type is not supported!", slotId);
1295d95e75fdSopenharmony_ci        return CALL_ERR_UNSUPPORTED_NETWORK_TYPE;
1296d95e75fdSopenharmony_ci    }
1297d95e75fdSopenharmony_ci    int32_t result = TELEPHONY_SUCCESS;
1298d95e75fdSopenharmony_ci    result = supplementRequestCs_.SendUssdRequest(slotId, msg);
1299d95e75fdSopenharmony_ci    if (result != TELEPHONY_SUCCESS) {
1300d95e75fdSopenharmony_ci        ReportMmiCodeMessage(MMI_CODE_FAILED, "", GENERIC_FAILURE);
1301d95e75fdSopenharmony_ci    }
1302d95e75fdSopenharmony_ci    return result;
1303d95e75fdSopenharmony_ci}
1304d95e75fdSopenharmony_ci
1305d95e75fdSopenharmony_civoid CellularCallSupplement::EventSendUssd(const RadioResponseInfo &responseInfo)
1306d95e75fdSopenharmony_ci{
1307d95e75fdSopenharmony_ci    auto callRegister = DelayedSingleton<CellularCallRegister>::GetInstance();
1308d95e75fdSopenharmony_ci    if (callRegister == nullptr) {
1309d95e75fdSopenharmony_ci        TELEPHONY_LOGE("callRegister is null.");
1310d95e75fdSopenharmony_ci        return;
1311d95e75fdSopenharmony_ci    }
1312d95e75fdSopenharmony_ci    callRegister->ReportSendUssdResult(static_cast<int32_t>(responseInfo.error));
1313d95e75fdSopenharmony_ci    ReportMmiCodeMessage(static_cast<int32_t>(responseInfo.error), SEND_USSD_SUCCESS, INVALID_MMI_CODE);
1314d95e75fdSopenharmony_ci}
1315d95e75fdSopenharmony_ci
1316d95e75fdSopenharmony_civoid CellularCallSupplement::EventSsNotify(SsNoticeInfo &ssNoticeInfo)
1317d95e75fdSopenharmony_ci{
1318d95e75fdSopenharmony_ci    MmiCodeInfo mmiCodeInfo;
1319d95e75fdSopenharmony_ci    mmiCodeInfo.result = ssNoticeInfo.result;
1320d95e75fdSopenharmony_ci    switch (ssNoticeInfo.requestType) {
1321d95e75fdSopenharmony_ci        case static_cast<int32_t>(SsRequestType::SS_ACTIVATION):
1322d95e75fdSopenharmony_ci        case static_cast<int32_t>(SsRequestType::SS_DEACTIVATION):
1323d95e75fdSopenharmony_ci        case static_cast<int32_t>(SsRequestType::SS_REGISTRATION):
1324d95e75fdSopenharmony_ci        case static_cast<int32_t>(SsRequestType::SS_ERASURE):
1325d95e75fdSopenharmony_ci        case static_cast<int32_t>(SsRequestType::SS_INTERROGATION):
1326d95e75fdSopenharmony_ci            GetMessage(mmiCodeInfo, ssNoticeInfo);
1327d95e75fdSopenharmony_ci            break;
1328d95e75fdSopenharmony_ci        default:
1329d95e75fdSopenharmony_ci            TELEPHONY_LOGE("Invaid requestType in SS Data!");
1330d95e75fdSopenharmony_ci            return;
1331d95e75fdSopenharmony_ci    }
1332d95e75fdSopenharmony_ci
1333d95e75fdSopenharmony_ci    auto callRegister = DelayedSingleton<CellularCallRegister>::GetInstance();
1334d95e75fdSopenharmony_ci    if (callRegister == nullptr) {
1335d95e75fdSopenharmony_ci        TELEPHONY_LOGE("callRegister is null.");
1336d95e75fdSopenharmony_ci        return;
1337d95e75fdSopenharmony_ci    }
1338d95e75fdSopenharmony_ci    callRegister->ReportMmiCodeResult(mmiCodeInfo);
1339d95e75fdSopenharmony_ci}
1340d95e75fdSopenharmony_ci
1341d95e75fdSopenharmony_civoid CellularCallSupplement::GetMessage(MmiCodeInfo &mmiCodeInfo, const SsNoticeInfo &ssNoticeInfo)
1342d95e75fdSopenharmony_ci{
1343d95e75fdSopenharmony_ci    if (ssNoticeInfo.result != 0) {
1344d95e75fdSopenharmony_ci        if (strcpy_s(mmiCodeInfo.message, sizeof(mmiCodeInfo.message), QUERY_SS_FAILED.c_str()) != EOK) {
1345d95e75fdSopenharmony_ci            TELEPHONY_LOGE("strcpy_s QUERY_SS_FAILED fail.");
1346d95e75fdSopenharmony_ci        }
1347d95e75fdSopenharmony_ci        return;
1348d95e75fdSopenharmony_ci    }
1349d95e75fdSopenharmony_ci    switch (ssNoticeInfo.serviceType) {
1350d95e75fdSopenharmony_ci        case (unsigned int)CallTransferType::TRANSFER_TYPE_UNCONDITIONAL: {
1351d95e75fdSopenharmony_ci            if (strcpy_s(mmiCodeInfo.message, sizeof(mmiCodeInfo.message),
1352d95e75fdSopenharmony_ci                TRANSFER_UNCONDITIONAL_SUCCESS.c_str()) != EOK) {
1353d95e75fdSopenharmony_ci                TELEPHONY_LOGE("strcpy_s TRANSFER_UNCONDITIONAL_SUCCESS fail.");
1354d95e75fdSopenharmony_ci                return;
1355d95e75fdSopenharmony_ci            }
1356d95e75fdSopenharmony_ci            break;
1357d95e75fdSopenharmony_ci        }
1358d95e75fdSopenharmony_ci        case (unsigned int)CallTransferType::TRANSFER_TYPE_BUSY: {
1359d95e75fdSopenharmony_ci            if (strcpy_s(mmiCodeInfo.message, sizeof(mmiCodeInfo.message), TRANSFER_BUSY_SUCCESS.c_str()) != EOK) {
1360d95e75fdSopenharmony_ci                TELEPHONY_LOGE("strcpy_s TRANSFER_BUSY_SUCCESS fail.");
1361d95e75fdSopenharmony_ci                return;
1362d95e75fdSopenharmony_ci            }
1363d95e75fdSopenharmony_ci            break;
1364d95e75fdSopenharmony_ci        }
1365d95e75fdSopenharmony_ci        case (unsigned int)CallTransferType::TRANSFER_TYPE_NO_REPLY: {
1366d95e75fdSopenharmony_ci            if (strcpy_s(mmiCodeInfo.message, sizeof(mmiCodeInfo.message), TRANSFER_NO_REPLYL_SUCCESS.c_str()) != EOK) {
1367d95e75fdSopenharmony_ci                TELEPHONY_LOGE("strcpy_s TRANSFER_NO_REPLYL_SUCCESS fail.");
1368d95e75fdSopenharmony_ci                return;
1369d95e75fdSopenharmony_ci            }
1370d95e75fdSopenharmony_ci            break;
1371d95e75fdSopenharmony_ci        }
1372d95e75fdSopenharmony_ci        case (unsigned int)CallTransferType::TRANSFER_TYPE_NOT_REACHABLE: {
1373d95e75fdSopenharmony_ci            if (strcpy_s(mmiCodeInfo.message, sizeof(mmiCodeInfo.message),
1374d95e75fdSopenharmony_ci                TRANSFER_NOT_REACHABLE_SUCCESS.c_str()) != EOK) {
1375d95e75fdSopenharmony_ci                TELEPHONY_LOGE("strcpy_s TRANSFER_NOT_REACHABLE_SUCCESS fail.");
1376d95e75fdSopenharmony_ci                return;
1377d95e75fdSopenharmony_ci            }
1378d95e75fdSopenharmony_ci            break;
1379d95e75fdSopenharmony_ci        }
1380d95e75fdSopenharmony_ci        default: {
1381d95e75fdSopenharmony_ci            if (strcpy_s(mmiCodeInfo.message, sizeof(mmiCodeInfo.message), QUERY_SS_SUCCESS.c_str()) != EOK) {
1382d95e75fdSopenharmony_ci                TELEPHONY_LOGE("strcpy_s QUERY_SS_SUCCESS fail.");
1383d95e75fdSopenharmony_ci                return;
1384d95e75fdSopenharmony_ci            }
1385d95e75fdSopenharmony_ci        }
1386d95e75fdSopenharmony_ci    }
1387d95e75fdSopenharmony_ci}
1388d95e75fdSopenharmony_ci
1389d95e75fdSopenharmony_civoid CellularCallSupplement::EventUssdNotify(UssdNoticeInfo &ussdNoticeInfo)
1390d95e75fdSopenharmony_ci{
1391d95e75fdSopenharmony_ci    MmiCodeInfo mmiCodeInfo;
1392d95e75fdSopenharmony_ci    bool isUssdError = ussdNoticeInfo.m != USSD_MODE_NOTIFY && ussdNoticeInfo.m != USSD_MODE_REQUEST;
1393d95e75fdSopenharmony_ci    if (!isUssdError && !ussdNoticeInfo.str.empty()) {
1394d95e75fdSopenharmony_ci        mmiCodeInfo.result = USSD_SUCCESS;
1395d95e75fdSopenharmony_ci        if (strcpy_s(mmiCodeInfo.message, sizeof(mmiCodeInfo.message), ussdNoticeInfo.str.c_str()) != EOK) {
1396d95e75fdSopenharmony_ci            TELEPHONY_LOGE("strcpy_s ussdNoticeInfo.str fail.");
1397d95e75fdSopenharmony_ci            return;
1398d95e75fdSopenharmony_ci        }
1399d95e75fdSopenharmony_ci    } else if (isUssdError && !(ussdNoticeInfo.m == USSD_MODE_NW_RELEASE)) {
1400d95e75fdSopenharmony_ci        mmiCodeInfo.result = USSD_FAILED;
1401d95e75fdSopenharmony_ci        if (strcpy_s(mmiCodeInfo.message, sizeof(mmiCodeInfo.message), INVALID_MMI_CODE.c_str()) != EOK) {
1402d95e75fdSopenharmony_ci            TELEPHONY_LOGE("strcpy_s INVALID_MMI_CODE fail.");
1403d95e75fdSopenharmony_ci            return;
1404d95e75fdSopenharmony_ci        }
1405d95e75fdSopenharmony_ci    } else {
1406d95e75fdSopenharmony_ci        TELEPHONY_LOGE("Invaild ussd notify.");
1407d95e75fdSopenharmony_ci    }
1408d95e75fdSopenharmony_ci
1409d95e75fdSopenharmony_ci    auto callRegister = DelayedSingleton<CellularCallRegister>::GetInstance();
1410d95e75fdSopenharmony_ci    if (callRegister == nullptr) {
1411d95e75fdSopenharmony_ci        TELEPHONY_LOGE("callRegister is null.");
1412d95e75fdSopenharmony_ci        return;
1413d95e75fdSopenharmony_ci    }
1414d95e75fdSopenharmony_ci    callRegister->ReportMmiCodeResult(mmiCodeInfo);
1415d95e75fdSopenharmony_ci}
1416d95e75fdSopenharmony_ci
1417d95e75fdSopenharmony_civoid CellularCallSupplement::EventSetPinPuk(const PinPukResponse &pinPukResponse)
1418d95e75fdSopenharmony_ci{
1419d95e75fdSopenharmony_ci    MmiCodeInfo mmiCodeInfo;
1420d95e75fdSopenharmony_ci    mmiCodeInfo.result = pinPukResponse.result;
1421d95e75fdSopenharmony_ci    std::string messageTemp = std::to_string(pinPukResponse.remain);
1422d95e75fdSopenharmony_ci    if (strcpy_s(mmiCodeInfo.message, sizeof(mmiCodeInfo.message), messageTemp.c_str()) != EOK) {
1423d95e75fdSopenharmony_ci        TELEPHONY_LOGE("strcpy_s messageTemp fail.");
1424d95e75fdSopenharmony_ci    }
1425d95e75fdSopenharmony_ci    auto callRegister = DelayedSingleton<CellularCallRegister>::GetInstance();
1426d95e75fdSopenharmony_ci    if (callRegister == nullptr) {
1427d95e75fdSopenharmony_ci        TELEPHONY_LOGE("callRegister is null.");
1428d95e75fdSopenharmony_ci        return;
1429d95e75fdSopenharmony_ci    }
1430d95e75fdSopenharmony_ci    callRegister->ReportMmiCodeResult(mmiCodeInfo);
1431d95e75fdSopenharmony_ci}
1432d95e75fdSopenharmony_ci
1433d95e75fdSopenharmony_civoid CellularCallSupplement::AlterPinPassword(int32_t slotId, const MMIData &mmiData)
1434d95e75fdSopenharmony_ci{
1435d95e75fdSopenharmony_ci    if (mmiData.actionString.empty()) {
1436d95e75fdSopenharmony_ci        TELEPHONY_LOGE("[slot%{public}d] actionString is empty!", slotId);
1437d95e75fdSopenharmony_ci        return;
1438d95e75fdSopenharmony_ci    }
1439d95e75fdSopenharmony_ci
1440d95e75fdSopenharmony_ci    std::string oldPin = mmiData.serviceInfoA;
1441d95e75fdSopenharmony_ci    std::string newPin = mmiData.serviceInfoB;
1442d95e75fdSopenharmony_ci    std::string newPinCheck = mmiData.serviceInfoC;
1443d95e75fdSopenharmony_ci    if (!IsVaildPinOrPuk(newPin, newPinCheck)) {
1444d95e75fdSopenharmony_ci        return;
1445d95e75fdSopenharmony_ci    }
1446d95e75fdSopenharmony_ci    int32_t result = TELEPHONY_SUCCESS;
1447d95e75fdSopenharmony_ci    result = supplementRequestCs_.AlterPinPassword(slotId, newPin, oldPin);
1448d95e75fdSopenharmony_ci    if (result != TELEPHONY_SUCCESS) {
1449d95e75fdSopenharmony_ci        ReportMmiCodeMessage(MMI_CODE_FAILED, "", GENERIC_FAILURE);
1450d95e75fdSopenharmony_ci    }
1451d95e75fdSopenharmony_ci}
1452d95e75fdSopenharmony_ci
1453d95e75fdSopenharmony_civoid CellularCallSupplement::UnlockPuk(int32_t slotId, const MMIData &mmiData)
1454d95e75fdSopenharmony_ci{
1455d95e75fdSopenharmony_ci    if (mmiData.actionString.empty()) {
1456d95e75fdSopenharmony_ci        TELEPHONY_LOGE("[slot%{public}d] actionString is empty!", slotId);
1457d95e75fdSopenharmony_ci        return;
1458d95e75fdSopenharmony_ci    }
1459d95e75fdSopenharmony_ci    std::string puk = mmiData.serviceInfoA;
1460d95e75fdSopenharmony_ci    std::string newPin = mmiData.serviceInfoB;
1461d95e75fdSopenharmony_ci    std::string newPinCheck = mmiData.serviceInfoC;
1462d95e75fdSopenharmony_ci    if (!IsVaildPinOrPuk(newPin, newPinCheck)) {
1463d95e75fdSopenharmony_ci        return;
1464d95e75fdSopenharmony_ci    }
1465d95e75fdSopenharmony_ci    int32_t result = TELEPHONY_SUCCESS;
1466d95e75fdSopenharmony_ci    result = supplementRequestCs_.UnlockPuk(slotId, newPin, puk);
1467d95e75fdSopenharmony_ci    if (result != TELEPHONY_SUCCESS) {
1468d95e75fdSopenharmony_ci        ReportMmiCodeMessage(MMI_CODE_FAILED, "", GENERIC_FAILURE);
1469d95e75fdSopenharmony_ci    }
1470d95e75fdSopenharmony_ci}
1471d95e75fdSopenharmony_ci
1472d95e75fdSopenharmony_civoid CellularCallSupplement::AlterPin2Password(int32_t slotId, const MMIData &mmiData)
1473d95e75fdSopenharmony_ci{
1474d95e75fdSopenharmony_ci    if (mmiData.actionString.empty()) {
1475d95e75fdSopenharmony_ci        TELEPHONY_LOGE("[slot%{public}d] actionString is empty!", slotId);
1476d95e75fdSopenharmony_ci        return;
1477d95e75fdSopenharmony_ci    }
1478d95e75fdSopenharmony_ci
1479d95e75fdSopenharmony_ci    std::string oldPin2 = mmiData.serviceInfoA;
1480d95e75fdSopenharmony_ci    std::string newPin2 = mmiData.serviceInfoB;
1481d95e75fdSopenharmony_ci    std::string newPin2Check = mmiData.serviceInfoC;
1482d95e75fdSopenharmony_ci    if (!IsVaildPinOrPuk(newPin2, newPin2Check)) {
1483d95e75fdSopenharmony_ci        return;
1484d95e75fdSopenharmony_ci    }
1485d95e75fdSopenharmony_ci    int32_t result = TELEPHONY_SUCCESS;
1486d95e75fdSopenharmony_ci    result = supplementRequestCs_.AlterPin2Password(slotId, newPin2, oldPin2);
1487d95e75fdSopenharmony_ci    if (result != TELEPHONY_SUCCESS) {
1488d95e75fdSopenharmony_ci        ReportMmiCodeMessage(MMI_CODE_FAILED, "", GENERIC_FAILURE);
1489d95e75fdSopenharmony_ci    }
1490d95e75fdSopenharmony_ci}
1491d95e75fdSopenharmony_ci
1492d95e75fdSopenharmony_civoid CellularCallSupplement::UnlockPuk2(int32_t slotId, const MMIData &mmiData)
1493d95e75fdSopenharmony_ci{
1494d95e75fdSopenharmony_ci    if (mmiData.actionString.empty()) {
1495d95e75fdSopenharmony_ci        TELEPHONY_LOGE("[slot%{public}d] actionString is empty!", slotId);
1496d95e75fdSopenharmony_ci        return;
1497d95e75fdSopenharmony_ci    }
1498d95e75fdSopenharmony_ci
1499d95e75fdSopenharmony_ci    std::string puk2 = mmiData.serviceInfoA;
1500d95e75fdSopenharmony_ci    std::string newPin2 = mmiData.serviceInfoB;
1501d95e75fdSopenharmony_ci    std::string newPin2Check = mmiData.serviceInfoC;
1502d95e75fdSopenharmony_ci    if (!IsVaildPinOrPuk(newPin2, newPin2Check)) {
1503d95e75fdSopenharmony_ci        return;
1504d95e75fdSopenharmony_ci    }
1505d95e75fdSopenharmony_ci    int32_t result = TELEPHONY_SUCCESS;
1506d95e75fdSopenharmony_ci    result = supplementRequestCs_.UnlockPuk2(slotId, newPin2, puk2);
1507d95e75fdSopenharmony_ci    if (result != TELEPHONY_SUCCESS) {
1508d95e75fdSopenharmony_ci        ReportMmiCodeMessage(MMI_CODE_FAILED, "", GENERIC_FAILURE);
1509d95e75fdSopenharmony_ci    }
1510d95e75fdSopenharmony_ci}
1511d95e75fdSopenharmony_ci
1512d95e75fdSopenharmony_cibool CellularCallSupplement::IsVaildPinOrPuk(std::string newPinOrPuk, std::string newPinOrPukCheck)
1513d95e75fdSopenharmony_ci{
1514d95e75fdSopenharmony_ci    if (newPinOrPuk != newPinOrPukCheck) {
1515d95e75fdSopenharmony_ci        ReportMmiCodeMessage(MMI_CODE_FAILED, "", MIS_MATCH_PIN_PUK);
1516d95e75fdSopenharmony_ci        return false;
1517d95e75fdSopenharmony_ci    } else if (static_cast<int32_t>(newPinOrPuk.length()) < PIN_PUK_MIN ||
1518d95e75fdSopenharmony_ci               static_cast<int32_t>(newPinOrPuk.length()) > PIN_PUK_MAX) {
1519d95e75fdSopenharmony_ci        ReportMmiCodeMessage(MMI_CODE_FAILED, "", INVAILD_PIN_PUK);
1520d95e75fdSopenharmony_ci        return false;
1521d95e75fdSopenharmony_ci    } else {
1522d95e75fdSopenharmony_ci        TELEPHONY_LOGI("Check Pin or Puk success.");
1523d95e75fdSopenharmony_ci    }
1524d95e75fdSopenharmony_ci    return true;
1525d95e75fdSopenharmony_ci}
1526d95e75fdSopenharmony_ci
1527d95e75fdSopenharmony_civoid CellularCallSupplement::ReportMmiCodeMessage(
1528d95e75fdSopenharmony_ci    int32_t result, const std::string successMsg, const std::string failedMsg)
1529d95e75fdSopenharmony_ci{
1530d95e75fdSopenharmony_ci    MmiCodeInfo mmiCodeInfo;
1531d95e75fdSopenharmony_ci    mmiCodeInfo.result = result;
1532d95e75fdSopenharmony_ci    if (result == RESULT_SUCCESS) {
1533d95e75fdSopenharmony_ci        if (strcpy_s(mmiCodeInfo.message, sizeof(mmiCodeInfo.message), successMsg.c_str()) != EOK) {
1534d95e75fdSopenharmony_ci            TELEPHONY_LOGE("strcpy_s fail.");
1535d95e75fdSopenharmony_ci            return;
1536d95e75fdSopenharmony_ci        }
1537d95e75fdSopenharmony_ci    } else {
1538d95e75fdSopenharmony_ci        if (strcpy_s(mmiCodeInfo.message, sizeof(mmiCodeInfo.message), failedMsg.c_str()) != EOK) {
1539d95e75fdSopenharmony_ci            TELEPHONY_LOGE("strcpy_s fail.");
1540d95e75fdSopenharmony_ci            return;
1541d95e75fdSopenharmony_ci        }
1542d95e75fdSopenharmony_ci    }
1543d95e75fdSopenharmony_ci    auto callRegister = DelayedSingleton<CellularCallRegister>::GetInstance();
1544d95e75fdSopenharmony_ci    if (callRegister == nullptr) {
1545d95e75fdSopenharmony_ci        TELEPHONY_LOGE("callRegister is null.");
1546d95e75fdSopenharmony_ci        return;
1547d95e75fdSopenharmony_ci    }
1548d95e75fdSopenharmony_ci    callRegister->ReportMmiCodeResult(mmiCodeInfo);
1549d95e75fdSopenharmony_ci}
1550d95e75fdSopenharmony_ci
1551d95e75fdSopenharmony_ciint32_t CellularCallSupplement::CloseUnFinishedUssd(int32_t slotId)
1552d95e75fdSopenharmony_ci{
1553d95e75fdSopenharmony_ci    if (!PhoneTypeGsmOrNot(slotId)) {
1554d95e75fdSopenharmony_ci        TELEPHONY_LOGE("[slot%{public}d] network type is not supported!", slotId);
1555d95e75fdSopenharmony_ci        return CALL_ERR_UNSUPPORTED_NETWORK_TYPE;
1556d95e75fdSopenharmony_ci    }
1557d95e75fdSopenharmony_ci    return supplementRequestCs_.CloseUnFinishedUssdRequest(slotId);
1558d95e75fdSopenharmony_ci}
1559d95e75fdSopenharmony_ci
1560d95e75fdSopenharmony_civoid CellularCallSupplement::EventCloseUnFinishedUssd(const RadioResponseInfo &responseInfo)
1561d95e75fdSopenharmony_ci{
1562d95e75fdSopenharmony_ci    auto callRegister = DelayedSingleton<CellularCallRegister>::GetInstance();
1563d95e75fdSopenharmony_ci    if (callRegister == nullptr) {
1564d95e75fdSopenharmony_ci        TELEPHONY_LOGE("callRegister is null.");
1565d95e75fdSopenharmony_ci        return;
1566d95e75fdSopenharmony_ci    }
1567d95e75fdSopenharmony_ci    int32_t result = TELEPHONY_ERROR;
1568d95e75fdSopenharmony_ci    if (responseInfo.error == ErrType::NONE) {
1569d95e75fdSopenharmony_ci        result = TELEPHONY_SUCCESS;
1570d95e75fdSopenharmony_ci    } else {
1571d95e75fdSopenharmony_ci        result = TELEPHONY_ERR_RIL_CMD_FAIL;
1572d95e75fdSopenharmony_ci    }
1573d95e75fdSopenharmony_ci    callRegister->ReportCloseUnFinishedUssdResult(result);
1574d95e75fdSopenharmony_ci}
1575d95e75fdSopenharmony_ci} // namespace Telephony
1576d95e75fdSopenharmony_ci} // namespace OHOS
1577