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 CDMA_SMS_SENDER_H
17 #define CDMA_SMS_SENDER_H
18 
19 #include <memory>
20 
21 #include "gsm_sms_message.h"
22 #include "ims_sms_client.h"
23 #include "sms_receive_indexer.h"
24 #include "sms_sender.h"
25 
26 namespace OHOS {
27 namespace Telephony {
28 class CdmaSmsSender : public SmsSender {
29 public:
30     CdmaSmsSender(int32_t slotId, std::function<void(std::shared_ptr<SmsSendIndexer>)> sendRetryFun);
31     ~CdmaSmsSender() override;
32     void TextBasedSmsDelivery(const std::string &desAddr, const std::string &scAddr, const std::string &text,
33         const sptr<ISendShortMessageCallback> &sendCallback,
34         const sptr<IDeliveryShortMessageCallback> &deliveryCallback) override;
35     void TextBasedSmsDeliveryViaIms(const std::string &desAddr, const std::string &scAddr, const std::string &text,
36         const sptr<ISendShortMessageCallback> &sendCallback,
37         const sptr<IDeliveryShortMessageCallback> &deliveryCallback);
38     bool TpduNullOrSmsPageOverNormalOrSmsEncodeFail(std::vector<struct SplitInfo> cellsInfos,
39         std::shared_ptr<struct SmsTpdu> tpdu, std::shared_ptr<uint8_t> unSentCellCount,
40         std::shared_ptr<bool> hasCellFailed, const sptr<ISendShortMessageCallback> &sendCallback);
41     void SendSmsForEveryIndexer(int &i, std::vector<struct SplitInfo> cellsInfos, const std::string &desAddr,
42         const std::string &scAddr, std::shared_ptr<struct SmsTpdu> tpdu, GsmSmsMessage gsmSmsMessage,
43         std::shared_ptr<uint8_t> unSentCellCount, std::shared_ptr<bool> hasCellFailed, DataCodingScheme codingType,
44         uint8_t msgRef8bit, const sptr<ISendShortMessageCallback> &sendCallback,
45         const sptr<IDeliveryShortMessageCallback> &deliveryCallback);
46     void ReadySendSms(GsmSmsMessage gsmSmsMessage, const std::string &scAddr, bool isMore,
47         std::shared_ptr<SmsSendIndexer> indexer, uint8_t msgRef8bit, std::shared_ptr<uint8_t> unSentCellCount,
48         std::shared_ptr<bool> hasCellFailed);
49     void DataBasedSmsDelivery(const std::string &desAddr, const std::string &scAddr, int32_t port, const uint8_t *data,
50         uint32_t dataLen, const sptr<ISendShortMessageCallback> &sendCallback,
51         const sptr<IDeliveryShortMessageCallback> &deliveryCallback) override;
52     void DataBasedSmsDeliveryViaIms(const std::string &desAddr, const std::string &scAddr, int32_t port,
53         const uint8_t *data, uint32_t dataLen, const sptr<ISendShortMessageCallback> &sendCallback,
54         const sptr<IDeliveryShortMessageCallback> &deliveryCallback);
55     void SendSmsToRil(const std::shared_ptr<SmsSendIndexer> &smsIndexer) override;
56     void Init() override;
57     void ReceiveStatusReport(const std::shared_ptr<SmsReceiveIndexer> &smsIndexer);
58     void ResendTextDelivery(const std::shared_ptr<SmsSendIndexer> &smsIndexer) override;
59     void ResendDataDelivery(const std::shared_ptr<SmsSendIndexer> &smsIndexer) override;
60     int32_t IsImsSmsSupported(int32_t slotId, bool &isSupported) override;
61     void StatusReportSetImsSms(const AppExecFwk::InnerEvent::Pointer &event) override;
62     void StatusReportGetImsSms(const AppExecFwk::InnerEvent::Pointer &event) override;
63     void RegisterImsHandler() override;
64     void SetSendIndexerInfo(const std::shared_ptr<SmsSendIndexer> &indexer,
65         const std::shared_ptr<struct EncodeInfo> &encodeInfo, unsigned char msgRef8bit);
66 
67 protected:
68     void StatusReportAnalysis(const AppExecFwk::InnerEvent::Pointer &event) override;
69 
70 private:
71     static constexpr uint16_t TAPI_NETTEXT_SMDATA_SIZE_MAX = 255;
72 
73     void SetConcact(
74         const std::shared_ptr<SmsSendIndexer> &smsIndexer, const std::unique_ptr<CdmaTransportMsg> &transMsg);
75     uint8_t GetSeqNum();
76     uint8_t GetSubmitMsgId();
77     void SetPduSeqInfo(const std::shared_ptr<SmsSendIndexer> &smsIndexer, const std::size_t size,
78         const std::unique_ptr<CdmaTransportMsg> &transMsg, const std::size_t index, const uint8_t msgRef8bit);
79 
80     void SendCsSms(const std::shared_ptr<SmsSendIndexer> &smsIndexer, int64_t &refId, std::string &pdu);
81     void SendImsSms(const std::shared_ptr<SmsSendIndexer> &smsIndexer, int64_t &refId, std::string &pdu);
82     void EncodeMsgData(std::unique_ptr<CdmaTransportMsg> transMsg, std::shared_ptr<SmsSendIndexer> indexer,
83         uint8_t msgRef8bit, const sptr<ISendShortMessageCallback> &sendCallback);
84 
85     std::unique_ptr<std::vector<uint8_t>> EncodeMsg(CdmaTransportMsg &msg);
86     void TextBasedSmsSplitDelivery(const std::string &desAddr, const std::string &scAddr,
87         std::vector<struct SplitInfo> splits, std::unique_ptr<CdmaTransportMsg> transMsg, uint8_t msgRef8bit,
88         uint16_t msgId, long timeStamp, const sptr<ISendShortMessageCallback> &sendCallback,
89         const sptr<IDeliveryShortMessageCallback> &deliveryCallback);
90 
91 private:
92     uint8_t msgSeqNum_ = 0;
93     uint8_t msgSubmitId_ = 0;
94 
95     std::mutex mutex_;
96     bool isImsCdmaHandlerRegistered = false;
97 };
98 } // namespace Telephony
99 } // namespace OHOS
100 #endif
101