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 SMS_BASE_MESSAGE__H 17 #define SMS_BASE_MESSAGE__H 18 19 #include <cmath> 20 #include <memory> 21 22 #include "cdma_sms_transport_message.h" 23 #include "gsm_sms_tpdu_codec.h" 24 #include "msg_text_convert_common.h" 25 #include "sms_common_utils.h" 26 #include "string_utils.h" 27 28 namespace OHOS { 29 namespace Telephony { 30 typedef struct { 31 uint16_t msgRef; 32 uint16_t seqNum; 33 uint16_t totalSeg; 34 bool is8Bits; 35 } SmsConcat; 36 37 typedef struct { 38 uint16_t destPort; 39 uint16_t originPort; 40 bool is8Bits; 41 } SmsAppPortAddr; 42 43 typedef struct { 44 bool bStore; 45 uint16_t msgInd; 46 uint16_t waitMsgNum; 47 } SpecialSmsIndication; 48 49 struct SplitInfo { 50 std::string text = ""; 51 std::vector<uint8_t> encodeData {}; 52 DataCodingScheme encodeType = DataCodingScheme::DATA_CODING_7BIT; 53 MSG_LANGUAGE_ID_T langId = 0; 54 }; 55 56 struct LengthInfo { 57 uint8_t dcs = 0; 58 uint8_t msgSegCount = 0; 59 uint16_t msgEncodeCount = 0; 60 uint8_t msgRemainCount = 0; 61 }; 62 63 class SmsBaseMessage { 64 public: 65 SmsBaseMessage() = default; 66 virtual ~SmsBaseMessage() = default; 67 virtual void SetSmscAddr(const std::string &scAddress); 68 virtual std::string GetSmscAddr() const; 69 virtual std::string GetOriginatingAddress() const; 70 virtual std::string GetVisibleOriginatingAddress() const; 71 virtual std::string GetVisibleMessageBody() const; 72 virtual enum SmsMessageClass GetMessageClass() const; 73 std::vector<uint8_t> GetRawPdu() const; 74 std::string GetRawUserData() const; 75 std::string GetRawWapPushUserData() const; 76 virtual int64_t GetScTimestamp() const; 77 virtual int GetStatus() const; 78 virtual int GetProtocolId() const; 79 virtual bool IsReplaceMessage(); 80 virtual bool IsCphsMwi() const; 81 virtual bool IsMwiClear() const; 82 virtual bool IsMwiSet() const; 83 virtual bool IsMwiNotStore() const; 84 virtual bool IsSmsStatusReportMessage() const; 85 virtual bool HasReplyPath() const; 86 virtual std::shared_ptr<SmsConcat> GetConcatMsg(); 87 virtual std::shared_ptr<SmsAppPortAddr> GetPortAddress(); 88 virtual std::shared_ptr<SpecialSmsIndication> GetSpecialSmsInd(); 89 virtual bool IsConcatMsg(); 90 virtual bool IsWapPushMsg(); 91 virtual void ConvertMessageClass(enum SmsMessageClass msgClass); 92 virtual int GetMsgRef(); 93 virtual int GetSegmentSize( 94 DataCodingScheme &codingScheme, int dataLen, bool bPortNum, MSG_LANGUAGE_ID_T &langId, int replyAddrLen) const; 95 virtual void SplitMessage(std::vector<struct SplitInfo> &splitResult, const std::string &text, bool force7BitCode, 96 DataCodingScheme &codingType, bool bPortNum); 97 virtual int32_t GetIndexOnSim() const; 98 virtual void SetIndexOnSim(int32_t index); 99 virtual int32_t GetSmsSegmentsInfo(const std::string &message, bool force7BitCode, LengthInfo &lenInfo); 100 virtual int GetMaxSegmentSize( 101 DataCodingScheme &codingScheme, int dataLen, bool bPortNum, MSG_LANGUAGE_ID_T &langId, int replyAddrLen) const; 102 103 protected: 104 constexpr static int16_t MAX_MSG_TEXT_LEN = 1530; 105 constexpr static int16_t MAX_REPLY_PID = 8; 106 std::string scAddress_; 107 std::string originatingAddress_; 108 std::string visibleMessageBody_; 109 enum SmsMessageClass msgClass_ = SMS_CLASS_UNKNOWN; 110 int64_t scTimestamp_; 111 int status_; 112 int protocolId_; 113 bool bReplaceMessage_; 114 bool bStatusReportMessage_; 115 bool bMwi_; 116 bool bMwiSense_; 117 bool bCphsMwi_; 118 bool bMwiClear_; 119 bool bMwiSet_; 120 bool bMwiNotStore_; 121 bool hasReplyPath_; 122 bool bMoreMsg_; 123 bool bHeaderInd_; 124 int headerCnt_; 125 int headerDataLen_; 126 int msgRef_; 127 bool bCompressed_; 128 bool bIndActive_; 129 int codingScheme_; 130 int codingGroup_; 131 std::vector<uint8_t> rawPdu_; 132 std::string rawUserData_; 133 std::string rawWapPushUserData_; 134 struct SmsUDPackage smsUserData_; 135 struct SmsTpud smsWapPushUserData_; 136 std::shared_ptr<SmsConcat> smsConcat_; 137 std::shared_ptr<SmsAppPortAddr> portAddress_; 138 std::shared_ptr<SpecialSmsIndication> specialSmsInd_; 139 int32_t indexOnSim_ = -1; 140 141 private: 142 virtual int DecodeMessage(uint8_t *decodeData, unsigned int length, DataCodingScheme &codingType, 143 const std::string &msgText, bool &bAbnormal, MSG_LANGUAGE_ID_T &langId) = 0; 144 void ConvertSpiltToUtf8(SplitInfo &split, const DataCodingScheme &codingType); 145 }; 146 } // namespace Telephony 147 } // namespace OHOS 148 #endif 149