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