1 /* 2 * Copyright (C) 2021-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 #ifndef GSM_SMS_MESSAGE_H 17 #define GSM_SMS_MESSAGE_H 18 19 #include "gsm_pdu_code_type.h" 20 #include "sms_base_message.h" 21 22 namespace OHOS { 23 namespace Telephony { 24 class GsmSmsMessage : public SmsBaseMessage { 25 public: 26 GsmSmsMessage() = default; 27 virtual ~GsmSmsMessage() = default; 28 void SetFullText(const std::string &text); 29 void SetDestAddress(const std::string &destAddress); 30 void SetDestPort(uint32_t port); 31 32 std::string GetFullText() const; 33 std::string GetDestAddress() const; 34 uint16_t GetDestPort(); 35 bool GetIsSmsText() const; 36 bool GetGsm() const; 37 std::string GetReplyAddress() const; 38 39 int SetHeaderLang(int index, const DataCodingScheme codingType, const MSG_LANGUAGE_ID_T langId); 40 int SetHeaderConcat(int index, const SmsConcat &concat); 41 int SetHeaderReply(int index); 42 43 std::shared_ptr<struct SmsTpdu> CreateDefaultSubmitSmsTpdu(const std::string &dest, const std::string &sc, 44 const std::string &text, bool bStatusReport, const DataCodingScheme codingScheme); 45 std::shared_ptr<struct SmsTpdu> CreateDataSubmitSmsTpdu(const std::string &desAddr, const std::string &scAddr, 46 int32_t port, const uint8_t *data, uint32_t dataLen, uint8_t msgRef8bit, DataCodingScheme codingType, 47 bool bStatusReport); 48 49 std::shared_ptr<struct EncodeInfo> GetSubmitEncodeInfo(const std::string &sc, bool bMore); 50 std::shared_ptr<struct EncodeInfo> GetSubmitEncodeInfoPartData( 51 uint8_t *encodeSmscAddr, uint8_t encodeSmscLen, bool bMore); 52 std::shared_ptr<struct SmsTpdu> CreateDeliverSmsTpdu(); 53 std::shared_ptr<struct SmsTpdu> CreateDeliverReportSmsTpdu(); 54 std::shared_ptr<struct SmsTpdu> CreateStatusReportSmsTpdu(); 55 static std::shared_ptr<GsmSmsMessage> CreateMessage(const std::string &pdu); 56 57 bool PduAnalysis(const std::string &pdu); 58 void ConvertMessageDcs(); 59 void ConvertUserData(); 60 bool GetIsTypeZeroInd() const; 61 bool GetIsSIMDataTypeDownload() const; 62 void ConvertMsgTimeStamp(const struct SmsTimeStamp ×); 63 bool IsSpecialMessage() const; 64 void SetSmsCodingNationalType(SmsCodingNationalType smsCodingNationalType); 65 66 private: 67 void AnalysisMsgDeliver(const SmsDeliver &deliver); 68 void AnalysisMsgStatusReport(const SmsStatusReport &statusRep); 69 void AnalysisMsgSubmit(const SmsSubmit &submit); 70 void CreateDefaultSubmit(bool bStatusReport, const DataCodingScheme codingScheme); 71 int SetSmsTpduDestAddress(std::shared_ptr<struct SmsTpdu> &tPdu, const std::string &desAddr); 72 uint8_t CalcReplyEncodeAddress(const std::string &replyAddress); 73 virtual int DecodeMessage(uint8_t *decodeData, unsigned int length, DataCodingScheme &codingType, 74 const std::string &msgText, bool &bAbnormal, MSG_LANGUAGE_ID_T &langId); 75 bool PduAnalysisMsg(); 76 void ConvertUserPartData(); 77 78 public: 79 static constexpr uint16_t TAPI_NETTEXT_SMDATA_SIZE_MAX = 255; 80 static constexpr uint8_t TAPI_SIM_SMSP_ADDRESS_LEN = 20; 81 82 private: 83 std::string fullText_; 84 std::string destAddress_; 85 std::string replyAddress_; 86 uint16_t destPort_ = -1; 87 bool bSmsText_ = false; 88 std::shared_ptr<struct SmsTpdu> smsTpdu_; 89 SmsCodingNationalType smsCodingNationalType_ = SMS_CODING_NATIONAL_TYPE_DEFAULT; 90 }; 91 92 struct EncodeInfo { 93 char tpduData_[GsmSmsMessage::TAPI_NETTEXT_SMDATA_SIZE_MAX + 1] = { 0 }; 94 char smcaData_[GsmSmsMessage::TAPI_SIM_SMSP_ADDRESS_LEN + 1] = { 0 }; 95 uint16_t tpduLen = 0; 96 uint8_t smcaLen = 0; 97 bool isMore_ = false; 98 }; 99 } // namespace Telephony 100 } // namespace OHOS 101 #endif 102