1/* 2 * Copyright (C) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16#include "mmi_code_message.h" 17 18#include "cellular_call_data_struct.h" 19#include "ims_error.h" 20#include "securec.h" 21#include "telephony_types.h" 22 23namespace OHOS { 24namespace Telephony { 25void CreateGetCallWaitingResultMessage(std::string &resultMessage, CallWaitResponse response) 26{ 27 if (response.result == TELEPHONY_SUCCESS) { 28 resultMessage.append("\n"); 29 if (response.status == 1) { 30 resultMessage.append(SERVICE_ENABLE_FOR); 31 CreateServiceClassMessage(resultMessage, response.classCw); 32 } else { 33 resultMessage.append(SERVICE_DISABLE); 34 } 35 } 36} 37 38void CreateSuppSvcQueryResultMessage(std::string &resultMessage, int32_t result, int32_t status) 39{ 40 if (result == TELEPHONY_SUCCESS) { 41 resultMessage.append("\n"); 42 if (status == SS_ENABLED) { 43 resultMessage.append(SERVICE_ENABLE); 44 } else if (status == SS_DISABLED) { 45 resultMessage.append(SERVICE_DISABLE); 46 } 47 } 48} 49 50void CreateGetCallTransferResultMessage(std::string &resultMessage, CallTransferResponse response) 51{ 52 if (response.result == TELEPHONY_SUCCESS) { 53 resultMessage.append("\n"); 54 for (uint32_t classMask = 1; classMask <= ServiceClassType::DEDICATED_PAD_ACCESS; classMask <<= 1) { 55 if (response.classx > 0 && (static_cast<uint32_t>(response.classx) & classMask) != 0) { 56 MakeCallTransferMessageEx(resultMessage, response, static_cast<uint32_t>(response.classx) & classMask); 57 } 58 } 59 } 60} 61 62void MakeCallTransferMessageEx(std::string &resultMessage, CallTransferResponse response, int32_t classex) 63{ 64 char tempMessage[MAX_MESSAGE_NUMBER] = {0}; 65 bool needTime = response.reason == TRANSFER_REASON_TYPE_NO_REPLY; 66 std::string className = GetServiceClassName(classex); 67 if (response.status == SS_ENABLED) { 68 if (needTime) { 69 if (sprintf_s(tempMessage, sizeof(tempMessage), CF_FORWARDED_TIME.c_str(), className.c_str(), 70 response.number, response.time) != -1) { 71 resultMessage.append(tempMessage); 72 } 73 } else { 74 if (sprintf_s(tempMessage, sizeof(tempMessage), CF_FORWARDED.c_str(), className.c_str(), 75 response.number) != -1) { 76 resultMessage.append(tempMessage); 77 } 78 } 79 } else { 80 if (sprintf_s(tempMessage, sizeof(tempMessage), CF_NOT_FORWARDED.c_str(), className.c_str()) != -1) { 81 resultMessage.append(tempMessage); 82 } 83 } 84} 85 86void CreateGetClirResultMessage(std::string &resultMessage, ClirResponse response) 87{ 88 if (response.result == TELEPHONY_SUCCESS) { 89 resultMessage.append("\n"); 90 int32_t clirInfoN = response.action; 91 int32_t clirInfoM = response.clirStat; 92 switch (clirInfoM) { 93 case CLIR_STATUS_NOT_PROVISIONED: 94 resultMessage.append(SERVICE_NOT_PROVISIONED); 95 break; 96 case CLIR_STATUS_PROVISIONED_PERMANENT: 97 resultMessage.append(CLIR_PERMANENT); 98 break; 99 case CLIR_STATUS_TEMPORARILY_RESTRICTED: 100 // 'n' parameter. 101 switch (clirInfoN) { 102 case CLIR_OUTGOING_DEFAULT: 103 case CLIR_OUTGOING_INVOCATION: 104 resultMessage.append(CLIR_DEFAULT_ON_NEXT_ON); 105 break; 106 case CLIR_OUTGOING_SUPPRESSION: 107 resultMessage.append(CLIR_DEFAULT_ON_NEXT_OFF); 108 break; 109 default: 110 resultMessage.append(SERVICE_NOT_PROVISIONED); 111 } 112 break; 113 case CLIR_STATUS_TEMPORARILY_ALLOWED: 114 // 'n' parameter. 115 switch (clirInfoN) { 116 case CLIR_OUTGOING_SUPPRESSION: 117 case CLIR_OUTGOING_DEFAULT: 118 resultMessage.append(CLIR_DEFAULT_OFF_NEXT_OFF); 119 break; 120 case CLIR_OUTGOING_INVOCATION: 121 resultMessage.append(CLIR_DEFAULT_OFF_NEXT_ON); 122 break; 123 default: 124 resultMessage.append(SERVICE_NOT_PROVISIONED); 125 } 126 break; 127 default: 128 resultMessage.append(SERVICE_NOT_PROVISIONED); 129 } 130 } 131} 132 133void CreateServiceClassMessage(std::string &resultMessage, int32_t classex) 134{ 135 for (uint32_t classMask = 1; classMask <= ServiceClassType::DEDICATED_PAD_ACCESS; classMask <<= 1) { 136 if (classex > 0 && (static_cast<uint32_t>(classex) & classMask) != 0) { 137 resultMessage.append("\n"); 138 resultMessage.append(GetServiceClassName(static_cast<uint32_t>(classex) & classMask)); 139 } 140 } 141} 142 143std::string GetServiceClassName(int32_t classex) 144{ 145 switch (classex) { 146 case ServiceClassType::VOICE: 147 return "Voice"; 148 case ServiceClassType::FAX: 149 return "Fax"; 150 case ServiceClassType::SHORT_MESSAGE_SERVICE: 151 return "Message"; 152 case ServiceClassType::DATA_CIRCUIT_SYNC: 153 return "Sync"; 154 case ServiceClassType::DATA_CIRCUIT_ASYNC: 155 return "Async"; 156 case ServiceClassType::DEDICATED_PACKET_ACCESS: 157 return "Package"; 158 case ServiceClassType::DEDICATED_PAD_ACCESS: 159 return "Pad"; 160 default: 161 return "Unknow"; 162 } 163} 164 165} // namespace Telephony 166} // namespace OHOS