• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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, bool bStatusReport);
47 
48     std::shared_ptr<struct EncodeInfo> GetSubmitEncodeInfo(const std::string &sc, bool bMore);
49     std::shared_ptr<struct EncodeInfo> GetSubmitEncodeInfoPartData(
50         uint8_t *encodeSmscAddr, uint8_t encodeSmscLen, bool bMore);
51     std::shared_ptr<struct SmsTpdu> CreateDeliverSmsTpdu();
52     std::shared_ptr<struct SmsTpdu> CreateDeliverReportSmsTpdu();
53     std::shared_ptr<struct SmsTpdu> CreateStatusReportSmsTpdu();
54     static std::shared_ptr<GsmSmsMessage> CreateMessage(const std::string &pdu);
55 
56     bool PduAnalysis(const std::string &pdu);
57     void ConvertMessageDcs();
58     void ConvertUserData();
59     bool GetIsTypeZeroInd() const;
60     bool GetIsSIMDataTypeDownload() const;
61     void ConvertMsgTimeStamp(const struct SmsTimeStamp &times);
62     bool IsSpecialMessage() const;
63 
64     static constexpr uint16_t TAPI_NETTEXT_SMDATA_SIZE_MAX = 255;
65     static constexpr uint8_t TAPI_SIM_SMSP_ADDRESS_LEN = 20;
66 
67 private:
68     static constexpr uint16_t DEFAULT_PORT = -1;
69     static constexpr uint8_t MAX_GSM_7BIT_DATA_LEN = 160;
70     static constexpr uint8_t MAX_SMSC_LEN = 20;
71     static constexpr uint16_t MAX_TPDU_DATA_LEN = 255;
72     static constexpr uint16_t TAPI_TEXT_SIZE_MAX = 520;
73     static constexpr uint8_t GSM_BEAR_DATA_LEN = 140;
74     static constexpr uint8_t BYTE_BITS = 8;
75     static constexpr uint8_t CHARSET_7BIT_BITS = 7;
76 
77     std::string fullText_;
78     std::string destAddress_;
79     std::string replyAddress_;
80     uint16_t destPort_ = -1;
81     bool bSmsText_ = false;
82     std::shared_ptr<struct SmsTpdu> smsTpdu_;
83 
84     void AnalysisMsgDeliver(const SmsDeliver &deliver);
85     void AnalysisMsgStatusReport(const SmsStatusReport &statusRep);
86     void AnalysisMsgSubmit(const SmsSubmit &submit);
87     void CreateDefaultSubmit(bool bStatusReport, const DataCodingScheme codingScheme);
88     int SetSmsTpduDestAddress(std::shared_ptr<struct SmsTpdu> &tPdu, const std::string &desAddr);
89     uint8_t CalcReplyEncodeAddress(const std::string &replyAddress);
90     virtual int DecodeMessage(uint8_t *decodeData, unsigned int length, DataCodingScheme &codingType,
91         const std::string &msgText, bool &bAbnormal, MSG_LANGUAGE_ID_T &langId);
92 };
93 
94 struct EncodeInfo {
95     char tpduData_[GsmSmsMessage::TAPI_NETTEXT_SMDATA_SIZE_MAX + 1] = { 0 };
96     char smcaData_[GsmSmsMessage::TAPI_SIM_SMSP_ADDRESS_LEN + 1] = { 0 };
97     uint16_t tpduLen = 0;
98     uint8_t smcaLen = 0;
99     bool isMore_ = false;
100 };
101 } // namespace Telephony
102 } // namespace OHOS
103 #endif
104