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