111fccf17Sopenharmony_ci/* 211fccf17Sopenharmony_ci * Copyright (C) 2021 Huawei Device Co., Ltd. 311fccf17Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 411fccf17Sopenharmony_ci * you may not use this file except in compliance with the License. 511fccf17Sopenharmony_ci * You may obtain a copy of the License at 611fccf17Sopenharmony_ci * 711fccf17Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 811fccf17Sopenharmony_ci * 911fccf17Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1011fccf17Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1111fccf17Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1211fccf17Sopenharmony_ci * See the License for the specific language governing permissions and 1311fccf17Sopenharmony_ci * limitations under the License. 1411fccf17Sopenharmony_ci */ 1511fccf17Sopenharmony_ci 1611fccf17Sopenharmony_ci#include "hril_sms.h" 1711fccf17Sopenharmony_ci 1811fccf17Sopenharmony_ci#include <regex> 1911fccf17Sopenharmony_ci 2011fccf17Sopenharmony_ci#include "hril_notification.h" 2111fccf17Sopenharmony_ci#include "hril_request.h" 2211fccf17Sopenharmony_ci 2311fccf17Sopenharmony_cinamespace OHOS { 2411fccf17Sopenharmony_cinamespace Telephony { 2511fccf17Sopenharmony_cinamespace { 2611fccf17Sopenharmony_ciconst size_t HEX_WIDTH = 2; 2711fccf17Sopenharmony_ciconst size_t MAX_PDU_LEN = 255; 2811fccf17Sopenharmony_ciconst size_t MAX_LEN = 100; 2911fccf17Sopenharmony_ciconst size_t MAX_CHN_LEN = 50000; 3011fccf17Sopenharmony_ciconst int32_t MSG_DEFAULT_INDEX = -1; 3111fccf17Sopenharmony_ciconst int32_t BYTE_LEN = 1; 3211fccf17Sopenharmony_ciconst int32_t INT_LEN = 4; 3311fccf17Sopenharmony_ciconst int32_t NUM_2 = 2; 3411fccf17Sopenharmony_ciconst int32_t NUM_3 = 3; 3511fccf17Sopenharmony_ciconst int32_t NUM_4 = 4; 3611fccf17Sopenharmony_ciconst int32_t NUM_5 = 5; 3711fccf17Sopenharmony_ciconst int HEXADECIMAL = 16; 3811fccf17Sopenharmony_ciconstexpr const char *COMMA_STR = ","; 3911fccf17Sopenharmony_ci} // namespace 4011fccf17Sopenharmony_ci 4111fccf17Sopenharmony_ciHRilSms::HRilSms(int32_t slotId) : HRilBase(slotId) 4211fccf17Sopenharmony_ci{ 4311fccf17Sopenharmony_ci AddHandlerToMap(); 4411fccf17Sopenharmony_ci AddNotificationToMap(); 4511fccf17Sopenharmony_ci} 4611fccf17Sopenharmony_ci 4711fccf17Sopenharmony_cibool HRilSms::IsSmsRespOrNotify(uint32_t code) 4811fccf17Sopenharmony_ci{ 4911fccf17Sopenharmony_ci return IsSmsResponse(code) || IsSmsNotification(code); 5011fccf17Sopenharmony_ci} 5111fccf17Sopenharmony_ci 5211fccf17Sopenharmony_civoid HRilSms::RegisterSmsFuncs(const HRilSmsReq *smsFuncs) 5311fccf17Sopenharmony_ci{ 5411fccf17Sopenharmony_ci smsFuncs_ = smsFuncs; 5511fccf17Sopenharmony_ci} 5611fccf17Sopenharmony_ci 5711fccf17Sopenharmony_civoid HRilSms::AddHandlerToMap() 5811fccf17Sopenharmony_ci{ 5911fccf17Sopenharmony_ci // Response 6011fccf17Sopenharmony_ci respMemberFuncMap_[HREQ_SMS_SEND_GSM_SMS] = 6111fccf17Sopenharmony_ci [this](int32_t requestNum, HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response, 6211fccf17Sopenharmony_ci size_t responseLen) { return SendGsmSmsResponse(requestNum, responseInfo, response, responseLen); }; 6311fccf17Sopenharmony_ci respMemberFuncMap_[HREQ_SMS_SEND_SMS_MORE_MODE] = 6411fccf17Sopenharmony_ci [this](int32_t requestNum, HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response, 6511fccf17Sopenharmony_ci size_t responseLen) { return SendSmsMoreModeResponse(requestNum, responseInfo, response, responseLen); }; 6611fccf17Sopenharmony_ci respMemberFuncMap_[HREQ_SMS_SEND_SMS_ACK] = 6711fccf17Sopenharmony_ci [this](int32_t requestNum, HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response, 6811fccf17Sopenharmony_ci size_t responseLen) { return SendSmsAckResponse(requestNum, responseInfo, response, responseLen); }; 6911fccf17Sopenharmony_ci respMemberFuncMap_[HREQ_SMS_ADD_SIM_MESSAGE] = 7011fccf17Sopenharmony_ci [this](int32_t requestNum, HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response, 7111fccf17Sopenharmony_ci size_t responseLen) { return AddSimMessageResponse(requestNum, responseInfo, response, responseLen); }; 7211fccf17Sopenharmony_ci respMemberFuncMap_[HREQ_SMS_DEL_SIM_MESSAGE] = 7311fccf17Sopenharmony_ci [this](int32_t requestNum, HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response, 7411fccf17Sopenharmony_ci size_t responseLen) { return DelSimMessageResponse(requestNum, responseInfo, response, responseLen); }; 7511fccf17Sopenharmony_ci respMemberFuncMap_[HREQ_SMS_UPDATE_SIM_MESSAGE] = 7611fccf17Sopenharmony_ci [this](int32_t requestNum, HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response, 7711fccf17Sopenharmony_ci size_t responseLen) { return UpdateSimMessageResponse(requestNum, responseInfo, response, responseLen); }; 7811fccf17Sopenharmony_ci respMemberFuncMap_[HREQ_SMS_SET_SMSC_ADDR] = 7911fccf17Sopenharmony_ci [this](int32_t requestNum, HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response, 8011fccf17Sopenharmony_ci size_t responseLen) { return SetSmscAddrResponse(requestNum, responseInfo, response, responseLen); }; 8111fccf17Sopenharmony_ci respMemberFuncMap_[HREQ_SMS_GET_SMSC_ADDR] = 8211fccf17Sopenharmony_ci [this](int32_t requestNum, HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response, 8311fccf17Sopenharmony_ci size_t responseLen) { return GetSmscAddrResponse(requestNum, responseInfo, response, responseLen); }; 8411fccf17Sopenharmony_ci respMemberFuncMap_[HREQ_SMS_SET_CB_CONFIG] = 8511fccf17Sopenharmony_ci [this](int32_t requestNum, HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response, 8611fccf17Sopenharmony_ci size_t responseLen) { return SetCBConfigResponse(requestNum, responseInfo, response, responseLen); }; 8711fccf17Sopenharmony_ci respMemberFuncMap_[HREQ_SMS_GET_CB_CONFIG] = 8811fccf17Sopenharmony_ci [this](int32_t requestNum, HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response, 8911fccf17Sopenharmony_ci size_t responseLen) { return GetCBConfigResponse(requestNum, responseInfo, response, responseLen); }; 9011fccf17Sopenharmony_ci respMemberFuncMap_[HREQ_SMS_GET_CDMA_CB_CONFIG] = 9111fccf17Sopenharmony_ci [this](int32_t requestNum, HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response, 9211fccf17Sopenharmony_ci size_t responseLen) { return GetCdmaCBConfigResponse(requestNum, responseInfo, response, responseLen); }; 9311fccf17Sopenharmony_ci respMemberFuncMap_[HREQ_SMS_SET_CDMA_CB_CONFIG] = 9411fccf17Sopenharmony_ci [this](int32_t requestNum, HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response, 9511fccf17Sopenharmony_ci size_t responseLen) { return SetCdmaCBConfigResponse(requestNum, responseInfo, response, responseLen); }; 9611fccf17Sopenharmony_ci respMemberFuncMap_[HREQ_SMS_SEND_CDMA_SMS] = 9711fccf17Sopenharmony_ci [this](int32_t requestNum, HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response, 9811fccf17Sopenharmony_ci size_t responseLen) { return SendCdmaSmsResponse(requestNum, responseInfo, response, responseLen); }; 9911fccf17Sopenharmony_ci respMemberFuncMap_[HREQ_SMS_ADD_CDMA_SIM_MESSAGE] = 10011fccf17Sopenharmony_ci [this](int32_t requestNum, HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response, 10111fccf17Sopenharmony_ci size_t responseLen) { return AddCdmaSimMessageResponse(requestNum, responseInfo, response, responseLen); }; 10211fccf17Sopenharmony_ci respMemberFuncMap_[HREQ_SMS_DEL_CDMA_SIM_MESSAGE] = 10311fccf17Sopenharmony_ci [this](int32_t requestNum, HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response, 10411fccf17Sopenharmony_ci size_t responseLen) { return DelCdmaSimMessageResponse(requestNum, responseInfo, response, responseLen); }; 10511fccf17Sopenharmony_ci respMemberFuncMap_[HREQ_SMS_UPDATE_CDMA_SIM_MESSAGE] = 10611fccf17Sopenharmony_ci [this](int32_t requestNum, HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response, 10711fccf17Sopenharmony_ci size_t responseLen) { return UpdateCdmaSimMessageResponse(requestNum, responseInfo, response, responseLen); }; 10811fccf17Sopenharmony_ci} 10911fccf17Sopenharmony_ci 11011fccf17Sopenharmony_civoid HRilSms::AddNotificationToMap() 11111fccf17Sopenharmony_ci{ 11211fccf17Sopenharmony_ci // Notification 11311fccf17Sopenharmony_ci notiMemberFuncMap_[HNOTI_SMS_NEW_SMS] = 11411fccf17Sopenharmony_ci [this](int32_t notifyType, HRilErrNumber error, const void *response, 11511fccf17Sopenharmony_ci size_t responseLen) { return NewSmsNotify(notifyType, error, response, responseLen); }; 11611fccf17Sopenharmony_ci notiMemberFuncMap_[HNOTI_SMS_NEW_CDMA_SMS] = 11711fccf17Sopenharmony_ci [this](int32_t notifyType, HRilErrNumber error, const void *response, 11811fccf17Sopenharmony_ci size_t responseLen) { return NewCdmaSmsNotify(notifyType, error, response, responseLen); }; 11911fccf17Sopenharmony_ci notiMemberFuncMap_[HNOTI_SMS_STATUS_REPORT] = 12011fccf17Sopenharmony_ci [this](int32_t notifyType, HRilErrNumber error, const void *response, 12111fccf17Sopenharmony_ci size_t responseLen) { return SmsStatusReportNotify(notifyType, error, response, responseLen); }; 12211fccf17Sopenharmony_ci notiMemberFuncMap_[HNOTI_SMS_NEW_SMS_STORED_ON_SIM] = 12311fccf17Sopenharmony_ci [this](int32_t notifyType, HRilErrNumber error, const void *response, 12411fccf17Sopenharmony_ci size_t responseLen) { return NewSmsStoredOnSimNotify(notifyType, error, response, responseLen); }; 12511fccf17Sopenharmony_ci notiMemberFuncMap_[HNOTI_CB_CONFIG_REPORT] = 12611fccf17Sopenharmony_ci [this](int32_t notifyType, HRilErrNumber error, const void *response, 12711fccf17Sopenharmony_ci size_t responseLen) { return CBConfigNotify(notifyType, error, response, responseLen); }; 12811fccf17Sopenharmony_ci} 12911fccf17Sopenharmony_ci 13011fccf17Sopenharmony_ciint32_t HRilSms::SendGsmSms(int32_t serialId, const OHOS::HDI::Ril::V1_1::GsmSmsMessageInfo &gsmSmsMessageInfo) 13111fccf17Sopenharmony_ci{ 13211fccf17Sopenharmony_ci const int32_t COUNT_STRINGS_VALUE = 2; 13311fccf17Sopenharmony_ci return RequestWithStrings(serialId, HREQ_SMS_SEND_GSM_SMS, COUNT_STRINGS_VALUE, gsmSmsMessageInfo.smscPdu.c_str(), 13411fccf17Sopenharmony_ci gsmSmsMessageInfo.pdu.c_str()); 13511fccf17Sopenharmony_ci} 13611fccf17Sopenharmony_ci 13711fccf17Sopenharmony_ciint32_t HRilSms::SendCdmaSms(int32_t serialId, const OHOS::HDI::Ril::V1_1::SendCdmaSmsMessageInfo &cdmaSmsMessageInfo) 13811fccf17Sopenharmony_ci{ 13911fccf17Sopenharmony_ci return RequestVendor(serialId, HREQ_SMS_SEND_CDMA_SMS, smsFuncs_, &HRilSmsReq::SendCdmaSms, 14011fccf17Sopenharmony_ci cdmaSmsMessageInfo.smscPdu.c_str(), cdmaSmsMessageInfo.smscPdu.size()); 14111fccf17Sopenharmony_ci} 14211fccf17Sopenharmony_ci 14311fccf17Sopenharmony_ciint32_t HRilSms::AddSimMessage(int32_t serialId, const OHOS::HDI::Ril::V1_1::SmsMessageIOInfo &message) 14411fccf17Sopenharmony_ci{ 14511fccf17Sopenharmony_ci HRilSmsWriteSms msg = {}; 14611fccf17Sopenharmony_ci msg.state = message.state; 14711fccf17Sopenharmony_ci msg.index = MSG_DEFAULT_INDEX; 14811fccf17Sopenharmony_ci size_t pduLen = message.pdu.length(); 14911fccf17Sopenharmony_ci if (pduLen > MAX_PDU_LEN) { 15011fccf17Sopenharmony_ci return HRIL_ERR_INVALID_PARAMETER; 15111fccf17Sopenharmony_ci } 15211fccf17Sopenharmony_ci CopyToCharPoint(&msg.pdu, message.pdu); 15311fccf17Sopenharmony_ci size_t smscPduLen = message.smscPdu.length() + 1; 15411fccf17Sopenharmony_ci if (smscPduLen > MAX_PDU_LEN) { 15511fccf17Sopenharmony_ci SafeFrees(msg.pdu); 15611fccf17Sopenharmony_ci return HRIL_ERR_INVALID_PARAMETER; 15711fccf17Sopenharmony_ci } 15811fccf17Sopenharmony_ci CopyToCharPoint(&msg.smsc, message.smscPdu); 15911fccf17Sopenharmony_ci int32_t result = RequestVendor( 16011fccf17Sopenharmony_ci serialId, HREQ_SMS_ADD_SIM_MESSAGE, smsFuncs_, &HRilSmsReq::AddSimMessage, &msg, sizeof(HRilSmsWriteSms)); 16111fccf17Sopenharmony_ci TELEPHONY_LOGI("AddSimMessage result is: %{public}d", result); 16211fccf17Sopenharmony_ci SafeFrees(msg.pdu, msg.smsc); 16311fccf17Sopenharmony_ci return result; 16411fccf17Sopenharmony_ci} 16511fccf17Sopenharmony_ci 16611fccf17Sopenharmony_ciint32_t HRilSms::DelSimMessage(int32_t serialId, int32_t index) 16711fccf17Sopenharmony_ci{ 16811fccf17Sopenharmony_ci if ((smsFuncs_ == nullptr) || (smsFuncs_->DelSimMessage == nullptr)) { 16911fccf17Sopenharmony_ci TELEPHONY_LOGE("smsFuncs_ or smsFuncs_->DelSimMessage is null"); 17011fccf17Sopenharmony_ci return HRIL_ERR_NULL_POINT; 17111fccf17Sopenharmony_ci } 17211fccf17Sopenharmony_ci ReqDataInfo *requestInfo = CreateHRilRequest(serialId, HREQ_SMS_DEL_SIM_MESSAGE); 17311fccf17Sopenharmony_ci if (requestInfo == nullptr) { 17411fccf17Sopenharmony_ci return HRIL_ERR_INVALID_PARAMETER; 17511fccf17Sopenharmony_ci } 17611fccf17Sopenharmony_ci int32_t *pBuff = nullptr; 17711fccf17Sopenharmony_ci RequestWithInts(&pBuff, requestInfo, 1, index); 17811fccf17Sopenharmony_ci smsFuncs_->DelSimMessage(requestInfo, pBuff, sizeof(int32_t)); 17911fccf17Sopenharmony_ci if (pBuff != nullptr) { 18011fccf17Sopenharmony_ci SafeFrees(pBuff); 18111fccf17Sopenharmony_ci } 18211fccf17Sopenharmony_ci return HRIL_ERR_SUCCESS; 18311fccf17Sopenharmony_ci} 18411fccf17Sopenharmony_ci 18511fccf17Sopenharmony_ciint32_t HRilSms::UpdateSimMessage(int32_t serialId, const OHOS::HDI::Ril::V1_1::SmsMessageIOInfo &message) 18611fccf17Sopenharmony_ci{ 18711fccf17Sopenharmony_ci HRilSmsWriteSms msg = {}; 18811fccf17Sopenharmony_ci msg.state = message.state; 18911fccf17Sopenharmony_ci msg.index = message.index; 19011fccf17Sopenharmony_ci size_t len = message.pdu.size() + 1; 19111fccf17Sopenharmony_ci if (len > MAX_PDU_LEN) { 19211fccf17Sopenharmony_ci return HRIL_ERR_INVALID_PARAMETER; 19311fccf17Sopenharmony_ci } 19411fccf17Sopenharmony_ci CopyToCharPoint(&msg.pdu, message.pdu); 19511fccf17Sopenharmony_ci size_t smscPduLen = message.smscPdu.length() + 1; 19611fccf17Sopenharmony_ci if (smscPduLen > MAX_PDU_LEN) { 19711fccf17Sopenharmony_ci SafeFrees(msg.pdu); 19811fccf17Sopenharmony_ci return HRIL_ERR_INVALID_PARAMETER; 19911fccf17Sopenharmony_ci } 20011fccf17Sopenharmony_ci CopyToCharPoint(&msg.smsc, message.smscPdu); 20111fccf17Sopenharmony_ci int32_t result = RequestVendor( 20211fccf17Sopenharmony_ci serialId, HREQ_SMS_UPDATE_SIM_MESSAGE, smsFuncs_, &HRilSmsReq::UpdateSimMessage, &msg, sizeof(HRilSmsWriteSms)); 20311fccf17Sopenharmony_ci TELEPHONY_LOGI("UpdateSimMessage result is: %{public}d", result); 20411fccf17Sopenharmony_ci SafeFrees(msg.pdu, msg.smsc); 20511fccf17Sopenharmony_ci return result; 20611fccf17Sopenharmony_ci} 20711fccf17Sopenharmony_ci 20811fccf17Sopenharmony_ciint32_t HRilSms::SetSmscAddr(int32_t serialId, const OHOS::HDI::Ril::V1_1::ServiceCenterAddress &serCenterAddress) 20911fccf17Sopenharmony_ci{ 21011fccf17Sopenharmony_ci HRilServiceCenterAddress address; 21111fccf17Sopenharmony_ci size_t len = 0; 21211fccf17Sopenharmony_ci len = strlen(serCenterAddress.address.c_str()) + 1; 21311fccf17Sopenharmony_ci address.tosca = serCenterAddress.tosca; 21411fccf17Sopenharmony_ci if (len > MAX_LEN) { 21511fccf17Sopenharmony_ci return HRIL_ERR_INVALID_PARAMETER; 21611fccf17Sopenharmony_ci } 21711fccf17Sopenharmony_ci CopyToCharPoint(&address.address, serCenterAddress.address); 21811fccf17Sopenharmony_ci int32_t result = RequestVendor(serialId, HREQ_SMS_SET_SMSC_ADDR, smsFuncs_, &HRilSmsReq::SetSmscAddr, &address, 21911fccf17Sopenharmony_ci sizeof(HRilServiceCenterAddress)); 22011fccf17Sopenharmony_ci TELEPHONY_LOGI("SetSmscAddr result is: %{public}d", result); 22111fccf17Sopenharmony_ci SafeFrees(address.address); 22211fccf17Sopenharmony_ci return result; 22311fccf17Sopenharmony_ci} 22411fccf17Sopenharmony_ci 22511fccf17Sopenharmony_ciint32_t HRilSms::GetSmscAddr(int32_t serialId) 22611fccf17Sopenharmony_ci{ 22711fccf17Sopenharmony_ci return RequestVendor(serialId, HREQ_SMS_GET_SMSC_ADDR, smsFuncs_, &HRilSmsReq::GetSmscAddr); 22811fccf17Sopenharmony_ci} 22911fccf17Sopenharmony_ci 23011fccf17Sopenharmony_ciint32_t HRilSms::SetCBConfig(int32_t serialId, const OHOS::HDI::Ril::V1_1::CBConfigInfo &broadcastInfo) 23111fccf17Sopenharmony_ci{ 23211fccf17Sopenharmony_ci size_t midsLen = broadcastInfo.mids.size() + 1; 23311fccf17Sopenharmony_ci if (midsLen == 0 || midsLen > MAX_CHN_LEN) { 23411fccf17Sopenharmony_ci return HRIL_ERR_INVALID_PARAMETER; 23511fccf17Sopenharmony_ci } 23611fccf17Sopenharmony_ci 23711fccf17Sopenharmony_ci size_t dcssLen = broadcastInfo.dcss.size(); 23811fccf17Sopenharmony_ci if (dcssLen == 0) { 23911fccf17Sopenharmony_ci return HRIL_ERR_INVALID_PARAMETER; 24011fccf17Sopenharmony_ci } 24111fccf17Sopenharmony_ci int32_t result; 24211fccf17Sopenharmony_ci std::vector<HRilCBConfigInfo> configInfo; 24311fccf17Sopenharmony_ci if (!GetHRilCBConfigInfo(configInfo, broadcastInfo)) { 24411fccf17Sopenharmony_ci return HRIL_ERR_INVALID_PARAMETER; 24511fccf17Sopenharmony_ci } 24611fccf17Sopenharmony_ci if (configInfo.size() == 0 || configInfo.size() > MAX_CHN_LEN) { 24711fccf17Sopenharmony_ci return HRIL_ERR_INVALID_PARAMETER; 24811fccf17Sopenharmony_ci } 24911fccf17Sopenharmony_ci HRilCBConfigInfo *info = new HRilCBConfigInfo[configInfo.size()]; 25011fccf17Sopenharmony_ci std::size_t locate = 0; 25111fccf17Sopenharmony_ci while (locate < configInfo.size()) { 25211fccf17Sopenharmony_ci info[locate].startOfServiceId = configInfo[locate].startOfServiceId; 25311fccf17Sopenharmony_ci info[locate].endOfServiceId = configInfo[locate].endOfServiceId; 25411fccf17Sopenharmony_ci info[locate].startOfCodeScheme = configInfo[locate].startOfCodeScheme; 25511fccf17Sopenharmony_ci info[locate].endOfCodeScheme = configInfo[locate].endOfCodeScheme; 25611fccf17Sopenharmony_ci info[locate].selected = configInfo[locate].selected; 25711fccf17Sopenharmony_ci locate++; 25811fccf17Sopenharmony_ci } 25911fccf17Sopenharmony_ci uint32_t len = sizeof(HRilCBConfigInfo) * configInfo.size(); 26011fccf17Sopenharmony_ci result = RequestVendor(serialId, HREQ_SMS_SET_CB_CONFIG, smsFuncs_, &HRilSmsReq::SetCBConfig, info, len); 26111fccf17Sopenharmony_ci if (result != HRIL_ERR_SUCCESS) { 26211fccf17Sopenharmony_ci TELEPHONY_LOGE("SetCBConfig fail, result is: %{public}d", result); 26311fccf17Sopenharmony_ci } 26411fccf17Sopenharmony_ci delete[] info; 26511fccf17Sopenharmony_ci return result; 26611fccf17Sopenharmony_ci} 26711fccf17Sopenharmony_ci 26811fccf17Sopenharmony_cibool HRilSms::GetHRilCBConfigInfo( 26911fccf17Sopenharmony_ci std::vector<HRilCBConfigInfo> &cellBroadcastInfo, const OHOS::HDI::Ril::V1_1::CBConfigInfo &broadcastInfo) 27011fccf17Sopenharmony_ci{ 27111fccf17Sopenharmony_ci std::vector<std::string> mids; 27211fccf17Sopenharmony_ci SplitMids(broadcastInfo.mids, mids, COMMA_STR); 27311fccf17Sopenharmony_ci for (auto mid : mids) { 27411fccf17Sopenharmony_ci std::string startMid; 27511fccf17Sopenharmony_ci std::string endMid; 27611fccf17Sopenharmony_ci if (!SplitValue(mid, startMid, endMid, "-")) { 27711fccf17Sopenharmony_ci TELEPHONY_LOGE("cb channel invalid"); 27811fccf17Sopenharmony_ci return false; 27911fccf17Sopenharmony_ci } 28011fccf17Sopenharmony_ci std::string startDcs; 28111fccf17Sopenharmony_ci std::string endDcs; 28211fccf17Sopenharmony_ci if (!SplitValue(broadcastInfo.dcss, startDcs, endDcs, "-")) { 28311fccf17Sopenharmony_ci TELEPHONY_LOGE("cb dcs invalid"); 28411fccf17Sopenharmony_ci return false; 28511fccf17Sopenharmony_ci } 28611fccf17Sopenharmony_ci HRilCBConfigInfo info; 28711fccf17Sopenharmony_ci info.startOfServiceId = std::stoi(startMid); 28811fccf17Sopenharmony_ci info.endOfServiceId = std::stoi(endMid); 28911fccf17Sopenharmony_ci info.startOfCodeScheme = std::stoi(startDcs); 29011fccf17Sopenharmony_ci info.endOfCodeScheme = std::stoi(endDcs); 29111fccf17Sopenharmony_ci info.selected = broadcastInfo.mode; 29211fccf17Sopenharmony_ci cellBroadcastInfo.push_back(info); 29311fccf17Sopenharmony_ci } 29411fccf17Sopenharmony_ci return true; 29511fccf17Sopenharmony_ci} 29611fccf17Sopenharmony_ci 29711fccf17Sopenharmony_civoid HRilSms::SplitMids(std::string src, std::vector<std::string> &dest, const std::string delimiter) 29811fccf17Sopenharmony_ci{ 29911fccf17Sopenharmony_ci if (src.empty()) { 30011fccf17Sopenharmony_ci return; 30111fccf17Sopenharmony_ci } 30211fccf17Sopenharmony_ci size_t pos = src.find(delimiter); 30311fccf17Sopenharmony_ci while (pos != std::string::npos) { 30411fccf17Sopenharmony_ci dest.push_back(src.substr(0, pos)); 30511fccf17Sopenharmony_ci src.erase(0, pos + delimiter.length()); 30611fccf17Sopenharmony_ci pos = src.find(delimiter); 30711fccf17Sopenharmony_ci } 30811fccf17Sopenharmony_ci dest.push_back(src); 30911fccf17Sopenharmony_ci} 31011fccf17Sopenharmony_ci 31111fccf17Sopenharmony_cibool HRilSms::SplitValue(std::string value, std::string &start, std::string &end, const std::string delimiter) 31211fccf17Sopenharmony_ci{ 31311fccf17Sopenharmony_ci if (value.empty()) { 31411fccf17Sopenharmony_ci return false; 31511fccf17Sopenharmony_ci } 31611fccf17Sopenharmony_ci size_t pos = value.find(delimiter); 31711fccf17Sopenharmony_ci if (pos == 0 || pos == value.size() - 1) { 31811fccf17Sopenharmony_ci return false; 31911fccf17Sopenharmony_ci } else if (pos == std::string::npos) { 32011fccf17Sopenharmony_ci start = value; 32111fccf17Sopenharmony_ci end = value; 32211fccf17Sopenharmony_ci return true; 32311fccf17Sopenharmony_ci } 32411fccf17Sopenharmony_ci start = value.substr(0, pos); 32511fccf17Sopenharmony_ci end = value.substr(pos + 1); 32611fccf17Sopenharmony_ci return true; 32711fccf17Sopenharmony_ci} 32811fccf17Sopenharmony_ci 32911fccf17Sopenharmony_ciint32_t HRilSms::GetCBConfig(int32_t serialId) 33011fccf17Sopenharmony_ci{ 33111fccf17Sopenharmony_ci return RequestVendor(serialId, HREQ_SMS_GET_CB_CONFIG, smsFuncs_, &HRilSmsReq::GetCBConfig); 33211fccf17Sopenharmony_ci} 33311fccf17Sopenharmony_ci 33411fccf17Sopenharmony_ciint32_t HRilSms::SetCdmaCBConfig( 33511fccf17Sopenharmony_ci int32_t serialId, const OHOS::HDI::Ril::V1_1::CdmaCBConfigInfoList &cellBroadcastInfoList) 33611fccf17Sopenharmony_ci{ 33711fccf17Sopenharmony_ci if ((smsFuncs_ == nullptr) || (smsFuncs_->SetCdmaCBConfig == nullptr)) { 33811fccf17Sopenharmony_ci TELEPHONY_LOGE("(smsFuncs_ or msFuncs_->SetCdmaCBConfig is null"); 33911fccf17Sopenharmony_ci return HRIL_ERR_NULL_POINT; 34011fccf17Sopenharmony_ci } 34111fccf17Sopenharmony_ci ReqDataInfo *requestInfo = CreateHRilRequest(serialId, HREQ_SMS_SET_CDMA_CB_CONFIG); 34211fccf17Sopenharmony_ci if (requestInfo == nullptr) { 34311fccf17Sopenharmony_ci return HRIL_ERR_INVALID_PARAMETER; 34411fccf17Sopenharmony_ci } 34511fccf17Sopenharmony_ci auto size = cellBroadcastInfoList.size; 34611fccf17Sopenharmony_ci std::unique_ptr<HRilCdmaCBConfigInfo[]> list = std::make_unique<HRilCdmaCBConfigInfo[]>(size); 34711fccf17Sopenharmony_ci CopyToHRilCdmaCBConfigInfo(list.get(), cellBroadcastInfoList); 34811fccf17Sopenharmony_ci smsFuncs_->SetCdmaCBConfig(requestInfo, list.get(), cellBroadcastInfoList.size * sizeof(HRilCdmaCBConfigInfo)); 34911fccf17Sopenharmony_ci return HRIL_ERR_SUCCESS; 35011fccf17Sopenharmony_ci} 35111fccf17Sopenharmony_ci 35211fccf17Sopenharmony_ciint32_t HRilSms::GetCdmaCBConfig(int32_t serialId) 35311fccf17Sopenharmony_ci{ 35411fccf17Sopenharmony_ci return RequestVendor(serialId, HREQ_SMS_GET_CDMA_CB_CONFIG, smsFuncs_, &HRilSmsReq::GetCdmaCBConfig); 35511fccf17Sopenharmony_ci} 35611fccf17Sopenharmony_ci 35711fccf17Sopenharmony_ciint32_t HRilSms::SendSmsMoreMode(int32_t serialId, const OHOS::HDI::Ril::V1_1::GsmSmsMessageInfo &gsmSmsMessageInfo) 35811fccf17Sopenharmony_ci{ 35911fccf17Sopenharmony_ci const int32_t COUNT_STRINGS_VALUE = 2; 36011fccf17Sopenharmony_ci return RequestWithStrings(serialId, HREQ_SMS_SEND_SMS_MORE_MODE, COUNT_STRINGS_VALUE, 36111fccf17Sopenharmony_ci gsmSmsMessageInfo.smscPdu.c_str(), gsmSmsMessageInfo.pdu.c_str()); 36211fccf17Sopenharmony_ci} 36311fccf17Sopenharmony_ci 36411fccf17Sopenharmony_ciint32_t HRilSms::SendSmsAck(int32_t serialId, const OHOS::HDI::Ril::V1_1::ModeData &modeData) 36511fccf17Sopenharmony_ci{ 36611fccf17Sopenharmony_ci if ((smsFuncs_ == nullptr) || (smsFuncs_->SendSmsAck == nullptr)) { 36711fccf17Sopenharmony_ci TELEPHONY_LOGE("smsFuncs_ or smsFuncs_->SendSmsAck is null"); 36811fccf17Sopenharmony_ci return HRIL_ERR_NULL_POINT; 36911fccf17Sopenharmony_ci } 37011fccf17Sopenharmony_ci ReqDataInfo *requestInfo = CreateHRilRequest(serialId, HREQ_SMS_SEND_SMS_ACK); 37111fccf17Sopenharmony_ci if (requestInfo == nullptr) { 37211fccf17Sopenharmony_ci return HRIL_ERR_INVALID_PARAMETER; 37311fccf17Sopenharmony_ci } 37411fccf17Sopenharmony_ci int32_t *pBuff = nullptr; 37511fccf17Sopenharmony_ci const int32_t COUNT_INTS_VALUE = 2; 37611fccf17Sopenharmony_ci RequestWithInts(&pBuff, requestInfo, COUNT_INTS_VALUE, static_cast<int32_t>(modeData.result), modeData.mode); 37711fccf17Sopenharmony_ci smsFuncs_->SendSmsAck(requestInfo, pBuff, sizeof(int32_t)); 37811fccf17Sopenharmony_ci if (pBuff != nullptr) { 37911fccf17Sopenharmony_ci SafeFrees(pBuff); 38011fccf17Sopenharmony_ci } 38111fccf17Sopenharmony_ci return HRIL_ERR_SUCCESS; 38211fccf17Sopenharmony_ci} 38311fccf17Sopenharmony_ci 38411fccf17Sopenharmony_ciint32_t HRilSms::AddCdmaSimMessage(int32_t serialId, const OHOS::HDI::Ril::V1_1::SmsMessageIOInfo &message) 38511fccf17Sopenharmony_ci{ 38611fccf17Sopenharmony_ci HRilSmsWriteCdmaSms msg = {}; 38711fccf17Sopenharmony_ci msg.state = message.state; 38811fccf17Sopenharmony_ci if (!CreateCdmaMessageInfo(msg.cdmaMessageInfo, message.pdu)) { 38911fccf17Sopenharmony_ci TELEPHONY_LOGE("CreateCdmaMessageInfo failed"); 39011fccf17Sopenharmony_ci return HRIL_ERR_INVALID_PARAMETER; 39111fccf17Sopenharmony_ci } 39211fccf17Sopenharmony_ci int32_t result = RequestVendor(serialId, HREQ_SMS_ADD_CDMA_SIM_MESSAGE, smsFuncs_, &HRilSmsReq::AddCdmaSimMessageV2, 39311fccf17Sopenharmony_ci &msg, sizeof(HRilSmsWriteCdmaSms)); 39411fccf17Sopenharmony_ci TELEPHONY_LOGI("AddCdmaSimMessageV2 result is: %{public}d", result); 39511fccf17Sopenharmony_ci return result; 39611fccf17Sopenharmony_ci} 39711fccf17Sopenharmony_ci 39811fccf17Sopenharmony_cibool HRilSms::CreateCdmaMessageInfo(HRilCdmaSmsMessageInfo &cdmaSmsInfo, const std::string &pdu) 39911fccf17Sopenharmony_ci{ 40011fccf17Sopenharmony_ci if (!CheckCdmaPduLength(cdmaSmsInfo, pdu)) { 40111fccf17Sopenharmony_ci TELEPHONY_LOGE("pdu is invalid"); 40211fccf17Sopenharmony_ci return false; 40311fccf17Sopenharmony_ci } 40411fccf17Sopenharmony_ci cdmaSmsInfo.serviceId = stoi(pdu.substr(0, INT_LEN), 0, HEXADECIMAL); 40511fccf17Sopenharmony_ci cdmaSmsInfo.isExist = stoi(pdu.substr(INT_LEN + BYTE_LEN * NUM_3, BYTE_LEN), 0, HEXADECIMAL); 40611fccf17Sopenharmony_ci cdmaSmsInfo.type = stoi(pdu.substr(INT_LEN + INT_LEN, INT_LEN), 0, HEXADECIMAL); 40711fccf17Sopenharmony_ci int32_t index = INT_LEN * NUM_3; 40811fccf17Sopenharmony_ci // adress 40911fccf17Sopenharmony_ci cdmaSmsInfo.address.digitMode = stoi(pdu.substr(index, BYTE_LEN), 0, HEXADECIMAL); 41011fccf17Sopenharmony_ci cdmaSmsInfo.address.mode = stoi(pdu.substr(index + BYTE_LEN, BYTE_LEN), 0, HEXADECIMAL); 41111fccf17Sopenharmony_ci cdmaSmsInfo.address.type = stoi(pdu.substr(index + BYTE_LEN * NUM_2, BYTE_LEN), 0, HEXADECIMAL); 41211fccf17Sopenharmony_ci cdmaSmsInfo.address.plan = stoi(pdu.substr(index + BYTE_LEN * NUM_3, BYTE_LEN), 0, HEXADECIMAL); 41311fccf17Sopenharmony_ci cdmaSmsInfo.address.number = stoi(pdu.substr(index + BYTE_LEN * NUM_4, BYTE_LEN), 0, HEXADECIMAL); 41411fccf17Sopenharmony_ci std::string addByte = pdu.substr(index + BYTE_LEN * NUM_5, BYTE_LEN * cdmaSmsInfo.address.number); 41511fccf17Sopenharmony_ci char *addressByte = reinterpret_cast<char *>(cdmaSmsInfo.address.bytes); 41611fccf17Sopenharmony_ci if (strcpy_s(addressByte, cdmaSmsInfo.address.number + 1, addByte.c_str()) != EOK) { 41711fccf17Sopenharmony_ci TELEPHONY_LOGE("strcpy_s fail."); 41811fccf17Sopenharmony_ci return false; 41911fccf17Sopenharmony_ci } 42011fccf17Sopenharmony_ci index += BYTE_LEN * NUM_5 + BYTE_LEN * cdmaSmsInfo.address.number; 42111fccf17Sopenharmony_ci // subAdress 42211fccf17Sopenharmony_ci cdmaSmsInfo.subAddress.type = stoi(pdu.substr(index, BYTE_LEN), 0, HEXADECIMAL); 42311fccf17Sopenharmony_ci cdmaSmsInfo.subAddress.odd = stoi(pdu.substr(index + BYTE_LEN, BYTE_LEN), 0, HEXADECIMAL); 42411fccf17Sopenharmony_ci cdmaSmsInfo.subAddress.number = stoi(pdu.substr(index + BYTE_LEN * NUM_2, BYTE_LEN), 0, HEXADECIMAL); 42511fccf17Sopenharmony_ci std::string subAddByte = pdu.substr(index + BYTE_LEN * NUM_3, BYTE_LEN * cdmaSmsInfo.subAddress.number); 42611fccf17Sopenharmony_ci char *subAddressByte = reinterpret_cast<char *>(cdmaSmsInfo.subAddress.bytes); 42711fccf17Sopenharmony_ci if (strcpy_s(subAddressByte, cdmaSmsInfo.subAddress.number + 1, subAddByte.c_str()) != EOK) { 42811fccf17Sopenharmony_ci TELEPHONY_LOGE("strcpy_s fail."); 42911fccf17Sopenharmony_ci return false; 43011fccf17Sopenharmony_ci } 43111fccf17Sopenharmony_ci index += BYTE_LEN * NUM_3 + BYTE_LEN * cdmaSmsInfo.subAddress.number; 43211fccf17Sopenharmony_ci // bearer Data 43311fccf17Sopenharmony_ci cdmaSmsInfo.size = stoi(pdu.substr(index, BYTE_LEN), 0, HEXADECIMAL); 43411fccf17Sopenharmony_ci std::string byte = pdu.substr(index + BYTE_LEN, BYTE_LEN * cdmaSmsInfo.size); 43511fccf17Sopenharmony_ci char *byteInfo = reinterpret_cast<char *>(cdmaSmsInfo.bytes); 43611fccf17Sopenharmony_ci if (strcpy_s(byteInfo, cdmaSmsInfo.size + 1, byte.c_str()) != EOK) { 43711fccf17Sopenharmony_ci TELEPHONY_LOGE("strcpy_s fail."); 43811fccf17Sopenharmony_ci return false; 43911fccf17Sopenharmony_ci } 44011fccf17Sopenharmony_ci return true; 44111fccf17Sopenharmony_ci} 44211fccf17Sopenharmony_ci 44311fccf17Sopenharmony_cibool HRilSms::CheckCdmaPduLength(HRilCdmaSmsMessageInfo &cdmaSmsInfo, const std::string &pdu) 44411fccf17Sopenharmony_ci{ 44511fccf17Sopenharmony_ci int32_t index = INT_LEN * NUM_3 + BYTE_LEN * NUM_5; 44611fccf17Sopenharmony_ci // adress 44711fccf17Sopenharmony_ci if (pdu.length() < static_cast<size_t>(index)) { 44811fccf17Sopenharmony_ci TELEPHONY_LOGE("pdu length invalid."); 44911fccf17Sopenharmony_ci return false; 45011fccf17Sopenharmony_ci } 45111fccf17Sopenharmony_ci if (!regex_match(pdu, std::regex("[0-9a-fA-F]+"))) { 45211fccf17Sopenharmony_ci TELEPHONY_LOGE("pdu invalid."); 45311fccf17Sopenharmony_ci return false; 45411fccf17Sopenharmony_ci } 45511fccf17Sopenharmony_ci cdmaSmsInfo.address.number = stoi(pdu.substr(index - BYTE_LEN, BYTE_LEN), 0, HEXADECIMAL); 45611fccf17Sopenharmony_ci index += BYTE_LEN * cdmaSmsInfo.address.number + BYTE_LEN * NUM_3; 45711fccf17Sopenharmony_ci if (pdu.length() < static_cast<size_t>(index)) { 45811fccf17Sopenharmony_ci TELEPHONY_LOGE("pdu length invalid."); 45911fccf17Sopenharmony_ci return false; 46011fccf17Sopenharmony_ci } 46111fccf17Sopenharmony_ci // subAdress 46211fccf17Sopenharmony_ci cdmaSmsInfo.subAddress.number = stoi(pdu.substr(index - BYTE_LEN, BYTE_LEN), 0, HEXADECIMAL); 46311fccf17Sopenharmony_ci index += BYTE_LEN * cdmaSmsInfo.subAddress.number + BYTE_LEN; 46411fccf17Sopenharmony_ci if (pdu.length() < static_cast<size_t>(index)) { 46511fccf17Sopenharmony_ci TELEPHONY_LOGE("pdu length invalid."); 46611fccf17Sopenharmony_ci return false; 46711fccf17Sopenharmony_ci } 46811fccf17Sopenharmony_ci // bearer Data 46911fccf17Sopenharmony_ci cdmaSmsInfo.size = stoi(pdu.substr(index - BYTE_LEN, BYTE_LEN), 0, HEXADECIMAL); 47011fccf17Sopenharmony_ci index += BYTE_LEN * cdmaSmsInfo.size; 47111fccf17Sopenharmony_ci if (pdu.length() < static_cast<size_t>(index)) { 47211fccf17Sopenharmony_ci TELEPHONY_LOGE("pdu length invalid."); 47311fccf17Sopenharmony_ci return false; 47411fccf17Sopenharmony_ci } 47511fccf17Sopenharmony_ci return true; 47611fccf17Sopenharmony_ci} 47711fccf17Sopenharmony_ci 47811fccf17Sopenharmony_ciint32_t HRilSms::DelCdmaSimMessage(int32_t serialId, int32_t index) 47911fccf17Sopenharmony_ci{ 48011fccf17Sopenharmony_ci if ((smsFuncs_ == nullptr) || (smsFuncs_->DelCdmaSimMessage == nullptr)) { 48111fccf17Sopenharmony_ci TELEPHONY_LOGE("smsFuncs_ or smsFuncs_->DelCdmaSimMessage is null"); 48211fccf17Sopenharmony_ci return HRIL_ERR_NULL_POINT; 48311fccf17Sopenharmony_ci } 48411fccf17Sopenharmony_ci ReqDataInfo *requestInfo = CreateHRilRequest(serialId, HREQ_SMS_DEL_CDMA_SIM_MESSAGE); 48511fccf17Sopenharmony_ci if (requestInfo == nullptr) { 48611fccf17Sopenharmony_ci return HRIL_ERR_INVALID_PARAMETER; 48711fccf17Sopenharmony_ci } 48811fccf17Sopenharmony_ci int32_t *pBuff = nullptr; 48911fccf17Sopenharmony_ci RequestWithInts(&pBuff, requestInfo, 1, index); 49011fccf17Sopenharmony_ci smsFuncs_->DelCdmaSimMessage(requestInfo, pBuff, sizeof(int32_t)); 49111fccf17Sopenharmony_ci if (pBuff != nullptr) { 49211fccf17Sopenharmony_ci SafeFrees(pBuff); 49311fccf17Sopenharmony_ci } 49411fccf17Sopenharmony_ci return HRIL_ERR_SUCCESS; 49511fccf17Sopenharmony_ci} 49611fccf17Sopenharmony_ci 49711fccf17Sopenharmony_ciint32_t HRilSms::UpdateCdmaSimMessage(int32_t serialId, const OHOS::HDI::Ril::V1_1::SmsMessageIOInfo &message) 49811fccf17Sopenharmony_ci{ 49911fccf17Sopenharmony_ci HRilSmsWriteSms msg = {}; 50011fccf17Sopenharmony_ci size_t len = 0; 50111fccf17Sopenharmony_ci len = message.pdu.size() + 1; 50211fccf17Sopenharmony_ci msg.state = message.state; 50311fccf17Sopenharmony_ci if (len > MAX_CHN_LEN) { 50411fccf17Sopenharmony_ci return HRIL_ERR_INVALID_PARAMETER; 50511fccf17Sopenharmony_ci } 50611fccf17Sopenharmony_ci CopyToCharPoint(&msg.pdu, message.pdu); 50711fccf17Sopenharmony_ci msg.index = message.index; 50811fccf17Sopenharmony_ci RequestVendor(serialId, HREQ_SMS_UPDATE_CDMA_SIM_MESSAGE, smsFuncs_, &HRilSmsReq::UpdateCdmaSimMessage, &msg, 50911fccf17Sopenharmony_ci sizeof(HRilSmsWriteSms)); 51011fccf17Sopenharmony_ci SafeFrees(msg.pdu); 51111fccf17Sopenharmony_ci return HRIL_ERR_SUCCESS; 51211fccf17Sopenharmony_ci} 51311fccf17Sopenharmony_ci 51411fccf17Sopenharmony_ciint32_t HRilSms::SendGsmSmsResponse( 51511fccf17Sopenharmony_ci int32_t requestNum, HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response, size_t responseLen) 51611fccf17Sopenharmony_ci{ 51711fccf17Sopenharmony_ci HDI::Ril::V1_1::SendSmsResultInfo result = 51811fccf17Sopenharmony_ci MakeSendSmsResult(responseInfo, responseInfo.serial, response, responseLen); 51911fccf17Sopenharmony_ci return Response(responseInfo, &HDI::Ril::V1_1::IRilCallback::SendGsmSmsResponse, result); 52011fccf17Sopenharmony_ci} 52111fccf17Sopenharmony_ci 52211fccf17Sopenharmony_ciint32_t HRilSms::SendCdmaSmsResponse( 52311fccf17Sopenharmony_ci int32_t requestNum, HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response, size_t responseLen) 52411fccf17Sopenharmony_ci{ 52511fccf17Sopenharmony_ci HDI::Ril::V1_1::SendSmsResultInfo result = 52611fccf17Sopenharmony_ci MakeSendSmsResult(responseInfo, responseInfo.serial, response, responseLen); 52711fccf17Sopenharmony_ci return Response(responseInfo, &HDI::Ril::V1_1::IRilCallback::SendCdmaSmsResponse, result); 52811fccf17Sopenharmony_ci} 52911fccf17Sopenharmony_ci 53011fccf17Sopenharmony_ciint32_t HRilSms::AddSimMessageResponse( 53111fccf17Sopenharmony_ci int32_t requestNum, HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response, size_t responseLen) 53211fccf17Sopenharmony_ci{ 53311fccf17Sopenharmony_ci TELEPHONY_LOGI("AddSimMessageResponse send"); 53411fccf17Sopenharmony_ci return Response(responseInfo, &HDI::Ril::V1_1::IRilCallback::AddSimMessageResponse); 53511fccf17Sopenharmony_ci} 53611fccf17Sopenharmony_ci 53711fccf17Sopenharmony_ciint32_t HRilSms::DelSimMessageResponse( 53811fccf17Sopenharmony_ci int32_t requestNum, HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response, size_t responseLen) 53911fccf17Sopenharmony_ci{ 54011fccf17Sopenharmony_ci return Response(responseInfo, &HDI::Ril::V1_1::IRilCallback::DelSimMessageResponse); 54111fccf17Sopenharmony_ci} 54211fccf17Sopenharmony_ci 54311fccf17Sopenharmony_ciint32_t HRilSms::UpdateSimMessageResponse( 54411fccf17Sopenharmony_ci int32_t requestNum, HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response, size_t responseLen) 54511fccf17Sopenharmony_ci{ 54611fccf17Sopenharmony_ci return Response(responseInfo, &HDI::Ril::V1_1::IRilCallback::UpdateSimMessageResponse); 54711fccf17Sopenharmony_ci} 54811fccf17Sopenharmony_ci 54911fccf17Sopenharmony_ciint32_t HRilSms::SetSmscAddrResponse( 55011fccf17Sopenharmony_ci int32_t requestNum, HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response, size_t responseLen) 55111fccf17Sopenharmony_ci{ 55211fccf17Sopenharmony_ci return Response(responseInfo, &HDI::Ril::V1_1::IRilCallback::SetSmscAddrResponse); 55311fccf17Sopenharmony_ci} 55411fccf17Sopenharmony_ci 55511fccf17Sopenharmony_ciint32_t HRilSms::GetSmscAddrResponse( 55611fccf17Sopenharmony_ci int32_t requestNum, HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response, size_t responseLen) 55711fccf17Sopenharmony_ci{ 55811fccf17Sopenharmony_ci HDI::Ril::V1_1::ServiceCenterAddress result; 55911fccf17Sopenharmony_ci if (response == nullptr || responseLen != sizeof(HRilServiceCenterAddress)) { 56011fccf17Sopenharmony_ci TELEPHONY_LOGE("Invalid response: response is nullptr"); 56111fccf17Sopenharmony_ci if (responseInfo.error == HDI::Ril::V1_1::RilErrType::NONE) { 56211fccf17Sopenharmony_ci responseInfo.error = HDI::Ril::V1_1::RilErrType::RIL_ERR_INVALID_RESPONSE; 56311fccf17Sopenharmony_ci } 56411fccf17Sopenharmony_ci result.address = std::string(""); 56511fccf17Sopenharmony_ci } else { 56611fccf17Sopenharmony_ci const HRilServiceCenterAddress *address = static_cast<const HRilServiceCenterAddress *>(response); 56711fccf17Sopenharmony_ci result.tosca = address->tosca; 56811fccf17Sopenharmony_ci if (address->address == nullptr) { 56911fccf17Sopenharmony_ci result.address = std::string(""); 57011fccf17Sopenharmony_ci TELEPHONY_LOGE("address is nullptr"); 57111fccf17Sopenharmony_ci } else { 57211fccf17Sopenharmony_ci result.address = std::string(address->address); 57311fccf17Sopenharmony_ci } 57411fccf17Sopenharmony_ci TELEPHONY_LOGI("result address:%{private}s, tosca:%{private}d", result.address.c_str(), result.tosca); 57511fccf17Sopenharmony_ci } 57611fccf17Sopenharmony_ci return Response(responseInfo, &HDI::Ril::V1_1::IRilCallback::GetSmscAddrResponse, result); 57711fccf17Sopenharmony_ci} 57811fccf17Sopenharmony_ci 57911fccf17Sopenharmony_ciint32_t HRilSms::SetCBConfigResponse( 58011fccf17Sopenharmony_ci int32_t requestNum, HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response, size_t responseLen) 58111fccf17Sopenharmony_ci{ 58211fccf17Sopenharmony_ci return Response(responseInfo, &HDI::Ril::V1_1::IRilCallback::SetCBConfigResponse); 58311fccf17Sopenharmony_ci} 58411fccf17Sopenharmony_ci 58511fccf17Sopenharmony_ciint32_t HRilSms::GetCBConfigResponse( 58611fccf17Sopenharmony_ci int32_t requestNum, HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response, size_t responseLen) 58711fccf17Sopenharmony_ci{ 58811fccf17Sopenharmony_ci HDI::Ril::V1_1::CBConfigInfo broadcastInfo; 58911fccf17Sopenharmony_ci if (response == nullptr) { 59011fccf17Sopenharmony_ci TELEPHONY_LOGE("Invalid response: response is nullptr"); 59111fccf17Sopenharmony_ci broadcastInfo.mode = -1; 59211fccf17Sopenharmony_ci broadcastInfo.mids = std::string(""); 59311fccf17Sopenharmony_ci broadcastInfo.dcss = std::string(""); 59411fccf17Sopenharmony_ci } else { 59511fccf17Sopenharmony_ci HRilCBConfigInfo *cellBroadcastInfo = (HRilCBConfigInfo *)response; 59611fccf17Sopenharmony_ci size_t len = responseLen / sizeof(HRilCBConfigInfo); 59711fccf17Sopenharmony_ci if (len != 0) { 59811fccf17Sopenharmony_ci if (!GetCBConfigInfo(cellBroadcastInfo, len, broadcastInfo)) { 59911fccf17Sopenharmony_ci TELEPHONY_LOGE("result is invalid"); 60011fccf17Sopenharmony_ci } 60111fccf17Sopenharmony_ci } 60211fccf17Sopenharmony_ci TELEPHONY_LOGD("mode:%{public}d, mids:%{public}s, dcss:%{public}s", broadcastInfo.mode, 60311fccf17Sopenharmony_ci broadcastInfo.mids.c_str(), broadcastInfo.dcss.c_str()); 60411fccf17Sopenharmony_ci } 60511fccf17Sopenharmony_ci return Response(responseInfo, &HDI::Ril::V1_1::IRilCallback::GetCBConfigResponse, broadcastInfo); 60611fccf17Sopenharmony_ci} 60711fccf17Sopenharmony_ci 60811fccf17Sopenharmony_cibool HRilSms::GetCBConfigInfo( 60911fccf17Sopenharmony_ci HRilCBConfigInfo *cellBroadcastInfo, size_t len, OHOS::HDI::Ril::V1_1::CBConfigInfo &broadcastInfo) 61011fccf17Sopenharmony_ci{ 61111fccf17Sopenharmony_ci broadcastInfo.mode = cellBroadcastInfo[0].selected; 61211fccf17Sopenharmony_ci std::string mids; 61311fccf17Sopenharmony_ci std::string dcss; 61411fccf17Sopenharmony_ci for (size_t locate = 0; locate < len; locate++) { 61511fccf17Sopenharmony_ci if (cellBroadcastInfo[locate].startOfServiceId > cellBroadcastInfo[locate].endOfServiceId) { 61611fccf17Sopenharmony_ci TELEPHONY_LOGE("result.mids is invalid"); 61711fccf17Sopenharmony_ci return false; 61811fccf17Sopenharmony_ci } else if (cellBroadcastInfo[locate].startOfServiceId < cellBroadcastInfo[locate].endOfServiceId) { 61911fccf17Sopenharmony_ci mids += std::to_string(cellBroadcastInfo[locate].startOfServiceId) + "-" + 62011fccf17Sopenharmony_ci std::to_string(cellBroadcastInfo[locate].endOfServiceId) + COMMA_STR; 62111fccf17Sopenharmony_ci } else { 62211fccf17Sopenharmony_ci mids += std::to_string(cellBroadcastInfo[locate].startOfServiceId) + COMMA_STR; 62311fccf17Sopenharmony_ci } 62411fccf17Sopenharmony_ci if (cellBroadcastInfo[locate].startOfCodeScheme > cellBroadcastInfo[locate].endOfCodeScheme) { 62511fccf17Sopenharmony_ci TELEPHONY_LOGE("result.dcss is invalid"); 62611fccf17Sopenharmony_ci return false; 62711fccf17Sopenharmony_ci } else if (cellBroadcastInfo[locate].startOfCodeScheme < cellBroadcastInfo[locate].endOfCodeScheme) { 62811fccf17Sopenharmony_ci dcss += std::to_string(cellBroadcastInfo[locate].startOfCodeScheme) + "-" + 62911fccf17Sopenharmony_ci std::to_string(cellBroadcastInfo[locate].endOfCodeScheme) + COMMA_STR; 63011fccf17Sopenharmony_ci } else { 63111fccf17Sopenharmony_ci dcss += std::to_string(cellBroadcastInfo[locate].startOfCodeScheme) + COMMA_STR; 63211fccf17Sopenharmony_ci } 63311fccf17Sopenharmony_ci } 63411fccf17Sopenharmony_ci broadcastInfo.mids = mids; 63511fccf17Sopenharmony_ci broadcastInfo.dcss = dcss; 63611fccf17Sopenharmony_ci return true; 63711fccf17Sopenharmony_ci} 63811fccf17Sopenharmony_ci 63911fccf17Sopenharmony_ciint32_t HRilSms::SetCdmaCBConfigResponse( 64011fccf17Sopenharmony_ci int32_t requestNum, HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response, size_t responseLen) 64111fccf17Sopenharmony_ci{ 64211fccf17Sopenharmony_ci return Response(responseInfo, &HDI::Ril::V1_1::IRilCallback::SetCdmaCBConfigResponse); 64311fccf17Sopenharmony_ci} 64411fccf17Sopenharmony_ci 64511fccf17Sopenharmony_ciint32_t HRilSms::GetCdmaCBConfigResponse( 64611fccf17Sopenharmony_ci int32_t requestNum, HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response, size_t responseLen) 64711fccf17Sopenharmony_ci{ 64811fccf17Sopenharmony_ci HDI::Ril::V1_1::CdmaCBConfigInfo broadcastInfo; 64911fccf17Sopenharmony_ci if (response == nullptr || responseLen != sizeof(HRilCdmaCBConfigInfo)) { 65011fccf17Sopenharmony_ci TELEPHONY_LOGE("Invalid response: response is nullptr"); 65111fccf17Sopenharmony_ci broadcastInfo.checked = -1; 65211fccf17Sopenharmony_ci broadcastInfo.language = -1; 65311fccf17Sopenharmony_ci broadcastInfo.service = -1; 65411fccf17Sopenharmony_ci } else { 65511fccf17Sopenharmony_ci const HRilCdmaCBConfigInfo *cellBroadcastInfo = static_cast<const HRilCdmaCBConfigInfo *>(response); 65611fccf17Sopenharmony_ci broadcastInfo.checked = cellBroadcastInfo->checked; 65711fccf17Sopenharmony_ci broadcastInfo.language = cellBroadcastInfo->language; 65811fccf17Sopenharmony_ci broadcastInfo.service = cellBroadcastInfo->service; 65911fccf17Sopenharmony_ci TELEPHONY_LOGE("checked:%{public}c, language:%{public}d, service:%{public}d", cellBroadcastInfo->checked, 66011fccf17Sopenharmony_ci cellBroadcastInfo->language, cellBroadcastInfo->service); 66111fccf17Sopenharmony_ci } 66211fccf17Sopenharmony_ci return Response(responseInfo, &HDI::Ril::V1_1::IRilCallback::GetCdmaCBConfigResponse, broadcastInfo); 66311fccf17Sopenharmony_ci} 66411fccf17Sopenharmony_ci 66511fccf17Sopenharmony_ciint32_t HRilSms::SendSmsMoreModeResponse( 66611fccf17Sopenharmony_ci int32_t requestNum, HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response, size_t responseLen) 66711fccf17Sopenharmony_ci{ 66811fccf17Sopenharmony_ci HDI::Ril::V1_1::SendSmsResultInfo result = 66911fccf17Sopenharmony_ci MakeSendSmsResult(responseInfo, responseInfo.serial, response, responseLen); 67011fccf17Sopenharmony_ci return Response(responseInfo, &HDI::Ril::V1_1::IRilCallback::SendSmsMoreModeResponse, result); 67111fccf17Sopenharmony_ci} 67211fccf17Sopenharmony_ci 67311fccf17Sopenharmony_ciint32_t HRilSms::SendSmsAckResponse( 67411fccf17Sopenharmony_ci int32_t requestNum, HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response, size_t responseLen) 67511fccf17Sopenharmony_ci{ 67611fccf17Sopenharmony_ci return Response(responseInfo, &HDI::Ril::V1_1::IRilCallback::SendSmsAckResponse); 67711fccf17Sopenharmony_ci} 67811fccf17Sopenharmony_ci 67911fccf17Sopenharmony_ciint32_t HRilSms::AddCdmaSimMessageResponse( 68011fccf17Sopenharmony_ci int32_t requestNum, HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response, size_t responseLen) 68111fccf17Sopenharmony_ci{ 68211fccf17Sopenharmony_ci TELEPHONY_LOGI("receive response"); 68311fccf17Sopenharmony_ci return Response(responseInfo, &HDI::Ril::V1_1::IRilCallback::AddCdmaSimMessageResponse); 68411fccf17Sopenharmony_ci} 68511fccf17Sopenharmony_ci 68611fccf17Sopenharmony_ciint32_t HRilSms::DelCdmaSimMessageResponse( 68711fccf17Sopenharmony_ci int32_t requestNum, HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response, size_t responseLen) 68811fccf17Sopenharmony_ci{ 68911fccf17Sopenharmony_ci return Response(responseInfo, &HDI::Ril::V1_1::IRilCallback::DelCdmaSimMessageResponse); 69011fccf17Sopenharmony_ci} 69111fccf17Sopenharmony_ci 69211fccf17Sopenharmony_ciint32_t HRilSms::UpdateCdmaSimMessageResponse( 69311fccf17Sopenharmony_ci int32_t requestNum, HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, const void *response, size_t responseLen) 69411fccf17Sopenharmony_ci{ 69511fccf17Sopenharmony_ci return Response(responseInfo, &HDI::Ril::V1_1::IRilCallback::UpdateCdmaSimMessageResponse); 69611fccf17Sopenharmony_ci} 69711fccf17Sopenharmony_ci 69811fccf17Sopenharmony_ciint32_t HRilSms::SmsStatusReportNotify( 69911fccf17Sopenharmony_ci int32_t indType, const HRilErrNumber error, const void *response, size_t responseLen) 70011fccf17Sopenharmony_ci{ 70111fccf17Sopenharmony_ci if (response == nullptr || responseLen == 0) { 70211fccf17Sopenharmony_ci TELEPHONY_LOGE("invalid response"); 70311fccf17Sopenharmony_ci return HRIL_ERR_GENERIC_FAILURE; 70411fccf17Sopenharmony_ci } 70511fccf17Sopenharmony_ci HDI::Ril::V1_1::SmsMessageInfo smsMessageInfo; 70611fccf17Sopenharmony_ci uint8_t *bytes = ConvertHexStringToBytes(response, responseLen); 70711fccf17Sopenharmony_ci if (bytes == nullptr) { 70811fccf17Sopenharmony_ci TELEPHONY_LOGE("ConvertHexStringToBytes in SmsStatusReportNotify is failed!"); 70911fccf17Sopenharmony_ci return HRIL_ERR_GENERIC_FAILURE; 71011fccf17Sopenharmony_ci } 71111fccf17Sopenharmony_ci const size_t MESSAGE_SIZE = responseLen / HEX_WIDTH; 71211fccf17Sopenharmony_ci smsMessageInfo.size = MESSAGE_SIZE; 71311fccf17Sopenharmony_ci smsMessageInfo.indicationType = static_cast<int32_t>(ConvertIntToRadioNoticeType(indType)); 71411fccf17Sopenharmony_ci uint8_t *temp = bytes; 71511fccf17Sopenharmony_ci for (int32_t i = 0; i < smsMessageInfo.size; i++) { 71611fccf17Sopenharmony_ci smsMessageInfo.pdu.push_back(*temp); 71711fccf17Sopenharmony_ci temp++; 71811fccf17Sopenharmony_ci } 71911fccf17Sopenharmony_ci SafeFrees(bytes); 72011fccf17Sopenharmony_ci return Notify(indType, error, &HDI::Ril::V1_1::IRilCallback::SmsStatusReportNotify, smsMessageInfo); 72111fccf17Sopenharmony_ci} 72211fccf17Sopenharmony_ci 72311fccf17Sopenharmony_ciint32_t HRilSms::NewSmsStoredOnSimNotify( 72411fccf17Sopenharmony_ci int32_t indType, const HRilErrNumber error, const void *response, size_t responseLen) 72511fccf17Sopenharmony_ci{ 72611fccf17Sopenharmony_ci if (response == nullptr || responseLen != sizeof(int32_t)) { 72711fccf17Sopenharmony_ci TELEPHONY_LOGE("invalid response"); 72811fccf17Sopenharmony_ci return HRIL_ERR_SUCCESS; 72911fccf17Sopenharmony_ci } 73011fccf17Sopenharmony_ci int32_t recordNumber = *(static_cast<const int32_t *>(response)); 73111fccf17Sopenharmony_ci indType = static_cast<int32_t>(ConvertIntToRadioNoticeType(indType)); 73211fccf17Sopenharmony_ci return Notify(indType, error, &HDI::Ril::V1_1::IRilCallback::NewSmsStoredOnSimNotify, recordNumber, indType); 73311fccf17Sopenharmony_ci} 73411fccf17Sopenharmony_ci 73511fccf17Sopenharmony_ciint32_t HRilSms::NewSmsNotify(int32_t indType, const HRilErrNumber error, const void *response, size_t responseLen) 73611fccf17Sopenharmony_ci{ 73711fccf17Sopenharmony_ci HRilSmsResponse *smsResponse = nullptr; 73811fccf17Sopenharmony_ci if (response == nullptr || responseLen == 0) { 73911fccf17Sopenharmony_ci TELEPHONY_LOGE("NewSmsNotify: invalid response"); 74011fccf17Sopenharmony_ci return HDF_FAILURE; 74111fccf17Sopenharmony_ci } else { 74211fccf17Sopenharmony_ci smsResponse = (HRilSmsResponse *)response; 74311fccf17Sopenharmony_ci } 74411fccf17Sopenharmony_ci uint8_t *bytes = ConvertHexStringToBytes(smsResponse->pdu, responseLen); 74511fccf17Sopenharmony_ci if (bytes == nullptr) { 74611fccf17Sopenharmony_ci TELEPHONY_LOGE("NewSmsNotify: ConvertHexStringToBytes failed"); 74711fccf17Sopenharmony_ci return HRIL_ERR_GENERIC_FAILURE; 74811fccf17Sopenharmony_ci } 74911fccf17Sopenharmony_ci HDI::Ril::V1_1::SmsMessageInfo smsMessageInfo; 75011fccf17Sopenharmony_ci const size_t NEW_SMS_SIZE = responseLen / HEX_WIDTH; 75111fccf17Sopenharmony_ci smsMessageInfo.size = NEW_SMS_SIZE; 75211fccf17Sopenharmony_ci smsMessageInfo.indicationType = indType; 75311fccf17Sopenharmony_ci uint8_t *temp = bytes; 75411fccf17Sopenharmony_ci for (int32_t i = 0; i < static_cast<int32_t>(smsMessageInfo.size); i++) { 75511fccf17Sopenharmony_ci smsMessageInfo.pdu.push_back(*temp); 75611fccf17Sopenharmony_ci temp++; 75711fccf17Sopenharmony_ci } 75811fccf17Sopenharmony_ci SafeFrees(bytes); 75911fccf17Sopenharmony_ci return Notify(indType, error, &HDI::Ril::V1_1::IRilCallback::NewSmsNotify, smsMessageInfo); 76011fccf17Sopenharmony_ci} 76111fccf17Sopenharmony_ci 76211fccf17Sopenharmony_ciint32_t HRilSms::NewCdmaSmsNotify(int32_t indType, const HRilErrNumber error, const void *response, size_t responseLen) 76311fccf17Sopenharmony_ci{ 76411fccf17Sopenharmony_ci HRilSmsResponse *message = nullptr; 76511fccf17Sopenharmony_ci if (response == nullptr || responseLen == 0) { 76611fccf17Sopenharmony_ci TELEPHONY_LOGE("invalid response"); 76711fccf17Sopenharmony_ci return HRIL_ERR_GENERIC_FAILURE; 76811fccf17Sopenharmony_ci } else { 76911fccf17Sopenharmony_ci message = (HRilSmsResponse *)response; 77011fccf17Sopenharmony_ci } 77111fccf17Sopenharmony_ci HDI::Ril::V1_1::SmsMessageInfo messageInfo; 77211fccf17Sopenharmony_ci messageInfo.indicationType = indType; 77311fccf17Sopenharmony_ci if (message->pdu != nullptr) { 77411fccf17Sopenharmony_ci messageInfo.size = strlen(message->pdu) / HEX_WIDTH; 77511fccf17Sopenharmony_ci uint8_t *bytes = ConvertHexStringToBytes(message->pdu, strlen(message->pdu)); 77611fccf17Sopenharmony_ci if (bytes == nullptr) { 77711fccf17Sopenharmony_ci TELEPHONY_LOGE("bytes is nullptr"); 77811fccf17Sopenharmony_ci return HRIL_ERR_GENERIC_FAILURE; 77911fccf17Sopenharmony_ci } 78011fccf17Sopenharmony_ci uint8_t *temp = bytes; 78111fccf17Sopenharmony_ci for (int32_t i = 0; i < messageInfo.size; i++) { 78211fccf17Sopenharmony_ci messageInfo.pdu.push_back(*temp); 78311fccf17Sopenharmony_ci temp++; 78411fccf17Sopenharmony_ci } 78511fccf17Sopenharmony_ci SafeFrees(bytes); 78611fccf17Sopenharmony_ci } 78711fccf17Sopenharmony_ci return Notify(indType, error, &HDI::Ril::V1_1::IRilCallback::NewCdmaSmsNotify, messageInfo); 78811fccf17Sopenharmony_ci} 78911fccf17Sopenharmony_ci 79011fccf17Sopenharmony_ciint32_t HRilSms::CBConfigNotify(int32_t indType, const HRilErrNumber error, const void *response, size_t responseLen) 79111fccf17Sopenharmony_ci{ 79211fccf17Sopenharmony_ci HDI::Ril::V1_1::CBConfigReportInfo result = MakeCBConfigResult(response, responseLen); 79311fccf17Sopenharmony_ci result.indicationType = indType; 79411fccf17Sopenharmony_ci return Notify(indType, error, &HDI::Ril::V1_1::IRilCallback::CBConfigNotify, result); 79511fccf17Sopenharmony_ci} 79611fccf17Sopenharmony_ci 79711fccf17Sopenharmony_cibool HRilSms::IsSmsResponse(uint32_t code) 79811fccf17Sopenharmony_ci{ 79911fccf17Sopenharmony_ci return ((code >= HREQ_SMS_BASE) && (code < HREQ_SIM_BASE)); 80011fccf17Sopenharmony_ci} 80111fccf17Sopenharmony_ci 80211fccf17Sopenharmony_cibool HRilSms::IsSmsNotification(uint32_t code) 80311fccf17Sopenharmony_ci{ 80411fccf17Sopenharmony_ci return ((code >= HNOTI_SMS_BASE) && (code < HNOTI_SIM_BASE)); 80511fccf17Sopenharmony_ci} 80611fccf17Sopenharmony_ci 80711fccf17Sopenharmony_ciint32_t HRilSms::RequestWithInts(int32_t **p, ReqDataInfo *requestInfo, int32_t argCount, ...) 80811fccf17Sopenharmony_ci{ 80911fccf17Sopenharmony_ci size_t len = sizeof(int32_t); 81011fccf17Sopenharmony_ci if (len <= 0 || argCount <= 0) { 81111fccf17Sopenharmony_ci return false; 81211fccf17Sopenharmony_ci } 81311fccf17Sopenharmony_ci *p = static_cast<int32_t *>(malloc(argCount * len)); 81411fccf17Sopenharmony_ci if (*p == nullptr) { 81511fccf17Sopenharmony_ci TELEPHONY_LOGE("req: [%{public}d,%{public}d,%{public}d], malloc fail", requestInfo->serial, 81611fccf17Sopenharmony_ci static_cast<int32_t>(requestInfo->slotId), requestInfo->request); 81711fccf17Sopenharmony_ci return false; 81811fccf17Sopenharmony_ci } 81911fccf17Sopenharmony_ci if (memset_s(*p, argCount * len, 0, argCount * len) != EOK) { 82011fccf17Sopenharmony_ci TELEPHONY_LOGE("RequestWithInts memset_s failed"); 82111fccf17Sopenharmony_ci SafeFrees(*p); 82211fccf17Sopenharmony_ci return false; 82311fccf17Sopenharmony_ci } 82411fccf17Sopenharmony_ci va_list list; 82511fccf17Sopenharmony_ci va_start(list, argCount); 82611fccf17Sopenharmony_ci int32_t i = 0; 82711fccf17Sopenharmony_ci while (i < argCount) { 82811fccf17Sopenharmony_ci (*p)[i] = va_arg(list, int32_t); 82911fccf17Sopenharmony_ci i++; 83011fccf17Sopenharmony_ci } 83111fccf17Sopenharmony_ci va_end(list); 83211fccf17Sopenharmony_ci return true; 83311fccf17Sopenharmony_ci} 83411fccf17Sopenharmony_ci 83511fccf17Sopenharmony_ciint32_t HRilSms::RequestWithStrings(int32_t serial, int32_t request, int32_t count, ...) 83611fccf17Sopenharmony_ci{ 83711fccf17Sopenharmony_ci if ((smsFuncs_ == nullptr) || (smsFuncs_->SendGsmSms == nullptr)) { 83811fccf17Sopenharmony_ci TELEPHONY_LOGE("smsFuncs_ or smsFuncs_->SendGsmSms is null"); 83911fccf17Sopenharmony_ci return HRIL_ERR_NULL_POINT; 84011fccf17Sopenharmony_ci } 84111fccf17Sopenharmony_ci char **pBuff = nullptr; 84211fccf17Sopenharmony_ci if (count <= 0) { 84311fccf17Sopenharmony_ci return HRIL_ERR_NULL_POINT; 84411fccf17Sopenharmony_ci } 84511fccf17Sopenharmony_ci int32_t len = count * sizeof(char *); 84611fccf17Sopenharmony_ci pBuff = (char **)malloc(len); 84711fccf17Sopenharmony_ci if (pBuff == nullptr) { 84811fccf17Sopenharmony_ci TELEPHONY_LOGE("req: [%{public}d,%{public}d], malloc fail", serial, request); 84911fccf17Sopenharmony_ci return HRIL_ERR_NULL_POINT; 85011fccf17Sopenharmony_ci } 85111fccf17Sopenharmony_ci if (memset_s(pBuff, len, 0, len) != EOK) { 85211fccf17Sopenharmony_ci TELEPHONY_LOGE("RequestWithInts memset_s failed"); 85311fccf17Sopenharmony_ci SafeFrees(pBuff); 85411fccf17Sopenharmony_ci return HRIL_ERR_NULL_POINT; 85511fccf17Sopenharmony_ci } 85611fccf17Sopenharmony_ci va_list list; 85711fccf17Sopenharmony_ci va_start(list, count); 85811fccf17Sopenharmony_ci int32_t i = 0; 85911fccf17Sopenharmony_ci while (i < count) { 86011fccf17Sopenharmony_ci const char *str = va_arg(list, const char *); 86111fccf17Sopenharmony_ci if (!ConvertToString(&pBuff[i], str)) { 86211fccf17Sopenharmony_ci TELEPHONY_LOGE("ConvertToString in RequestWithStrings is failed!"); 86311fccf17Sopenharmony_ci va_end(list); 86411fccf17Sopenharmony_ci for (int32_t j = 0; j < i; j++) { 86511fccf17Sopenharmony_ci SafeFrees(pBuff[j]); 86611fccf17Sopenharmony_ci } 86711fccf17Sopenharmony_ci SafeFrees(pBuff); 86811fccf17Sopenharmony_ci return HRIL_ERR_NULL_POINT; 86911fccf17Sopenharmony_ci } 87011fccf17Sopenharmony_ci i++; 87111fccf17Sopenharmony_ci } 87211fccf17Sopenharmony_ci va_end(list); 87311fccf17Sopenharmony_ci int32_t result = RequestVendor(serial, request, smsFuncs_, &HRilSmsReq::SendGsmSms, pBuff, count); 87411fccf17Sopenharmony_ci if (pBuff != nullptr) { 87511fccf17Sopenharmony_ci i = 0; 87611fccf17Sopenharmony_ci while (i < count) { 87711fccf17Sopenharmony_ci SafeFrees(pBuff[i]); 87811fccf17Sopenharmony_ci i++; 87911fccf17Sopenharmony_ci } 88011fccf17Sopenharmony_ci SafeFrees(pBuff); 88111fccf17Sopenharmony_ci } 88211fccf17Sopenharmony_ci return result; 88311fccf17Sopenharmony_ci} 88411fccf17Sopenharmony_ci 88511fccf17Sopenharmony_ciHDI::Ril::V1_1::CBConfigReportInfo HRilSms::MakeCBConfigResult(const void *response, const size_t responseLen) 88611fccf17Sopenharmony_ci{ 88711fccf17Sopenharmony_ci HDI::Ril::V1_1::CBConfigReportInfo result; 88811fccf17Sopenharmony_ci if (response == nullptr || responseLen != sizeof(HRilCBConfigReportInfo)) { 88911fccf17Sopenharmony_ci TELEPHONY_LOGE("Invalid response: response is nullptr"); 89011fccf17Sopenharmony_ci result.data = std::string(""); 89111fccf17Sopenharmony_ci result.pdu = std::string(""); 89211fccf17Sopenharmony_ci result.dcs = std::string(""); 89311fccf17Sopenharmony_ci } else { 89411fccf17Sopenharmony_ci const HRilCBConfigReportInfo *cellBroadcastReportInfo = static_cast<const HRilCBConfigReportInfo *>(response); 89511fccf17Sopenharmony_ci result.mid = cellBroadcastReportInfo->mid; 89611fccf17Sopenharmony_ci result.length = cellBroadcastReportInfo->length; 89711fccf17Sopenharmony_ci result.page = cellBroadcastReportInfo->page; 89811fccf17Sopenharmony_ci result.pages = cellBroadcastReportInfo->pages; 89911fccf17Sopenharmony_ci result.sn = cellBroadcastReportInfo->sn; 90011fccf17Sopenharmony_ci if (cellBroadcastReportInfo->data == nullptr) { 90111fccf17Sopenharmony_ci result.data = std::string(""); 90211fccf17Sopenharmony_ci TELEPHONY_LOGE("result.data is nullptr"); 90311fccf17Sopenharmony_ci } else { 90411fccf17Sopenharmony_ci TELEPHONY_LOGI("result.data :%{private}s", cellBroadcastReportInfo->data); 90511fccf17Sopenharmony_ci result.data = std::string(cellBroadcastReportInfo->data); 90611fccf17Sopenharmony_ci } 90711fccf17Sopenharmony_ci if (cellBroadcastReportInfo->pdu == nullptr) { 90811fccf17Sopenharmony_ci result.pdu = std::string(""); 90911fccf17Sopenharmony_ci TELEPHONY_LOGE("result.pdu is nullptr"); 91011fccf17Sopenharmony_ci } else { 91111fccf17Sopenharmony_ci TELEPHONY_LOGI("result.pdu :%{private}s", cellBroadcastReportInfo->pdu); 91211fccf17Sopenharmony_ci result.pdu = StringToHex(cellBroadcastReportInfo->pdu, cellBroadcastReportInfo->length); 91311fccf17Sopenharmony_ci } 91411fccf17Sopenharmony_ci if (cellBroadcastReportInfo->dcs == nullptr) { 91511fccf17Sopenharmony_ci result.dcs = std::string(""); 91611fccf17Sopenharmony_ci TELEPHONY_LOGE("result.dcs is nullptr"); 91711fccf17Sopenharmony_ci } else { 91811fccf17Sopenharmony_ci TELEPHONY_LOGI("result.dcs :%{private}s", cellBroadcastReportInfo->dcs); 91911fccf17Sopenharmony_ci result.dcs = std::string(cellBroadcastReportInfo->dcs); 92011fccf17Sopenharmony_ci } 92111fccf17Sopenharmony_ci } 92211fccf17Sopenharmony_ci return result; 92311fccf17Sopenharmony_ci} 92411fccf17Sopenharmony_ci 92511fccf17Sopenharmony_ciHDI::Ril::V1_1::SendSmsResultInfo HRilSms::MakeSendSmsResult( 92611fccf17Sopenharmony_ci HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo, int32_t serial, const void *response, const size_t responseLen) 92711fccf17Sopenharmony_ci{ 92811fccf17Sopenharmony_ci HDI::Ril::V1_1::SendSmsResultInfo result; 92911fccf17Sopenharmony_ci if (response == nullptr || responseLen != sizeof(HRilSmsResponse)) { 93011fccf17Sopenharmony_ci TELEPHONY_LOGE("Invalid response: response is nullptr"); 93111fccf17Sopenharmony_ci if (responseInfo.error == HDI::Ril::V1_1::RilErrType::NONE) { 93211fccf17Sopenharmony_ci responseInfo.error = HDI::Ril::V1_1::RilErrType::RIL_ERR_INVALID_RESPONSE; 93311fccf17Sopenharmony_ci } 93411fccf17Sopenharmony_ci result.pdu = std::string(""); 93511fccf17Sopenharmony_ci } else { 93611fccf17Sopenharmony_ci const HRilSmsResponse *smsResponse = static_cast<const HRilSmsResponse *>(response); 93711fccf17Sopenharmony_ci result.msgRef = smsResponse->msgRef; 93811fccf17Sopenharmony_ci if (smsResponse->pdu == nullptr) { 93911fccf17Sopenharmony_ci result.pdu = std::string(""); 94011fccf17Sopenharmony_ci TELEPHONY_LOGE("result.pdu is nullptr"); 94111fccf17Sopenharmony_ci } else { 94211fccf17Sopenharmony_ci result.pdu = std::string(smsResponse->pdu); 94311fccf17Sopenharmony_ci } 94411fccf17Sopenharmony_ci result.errCode = smsResponse->errCode; 94511fccf17Sopenharmony_ci } 94611fccf17Sopenharmony_ci return result; 94711fccf17Sopenharmony_ci} 94811fccf17Sopenharmony_ci 94911fccf17Sopenharmony_civoid HRilSms::CopyToHRilCdmaCBConfigInfo( 95011fccf17Sopenharmony_ci HRilCdmaCBConfigInfo *list, OHOS::HDI::Ril::V1_1::CdmaCBConfigInfoList cellBroadcastInfoList) 95111fccf17Sopenharmony_ci{ 95211fccf17Sopenharmony_ci for (int32_t i = 0; i < cellBroadcastInfoList.size; i++) { 95311fccf17Sopenharmony_ci list[i].service = cellBroadcastInfoList.list[i].service; 95411fccf17Sopenharmony_ci list[i].language = cellBroadcastInfoList.list[i].language; 95511fccf17Sopenharmony_ci list[i].checked = cellBroadcastInfoList.list[i].checked; 95611fccf17Sopenharmony_ci } 95711fccf17Sopenharmony_ci} 95811fccf17Sopenharmony_ci} // namespace Telephony 95911fccf17Sopenharmony_ci} // namespace OHOS 960