1  /*
2   * Copyright (C) 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_PARAMETER_RECORD_H
17  #define CDMA_SMS_PARAMETER_RECORD_H
18  
19  #include "cdma_sms_common.h"
20  #include "cdma_sms_teleservice_message.h"
21  #include "sms_pdu_buffer.h"
22  
23  namespace OHOS {
24  namespace Telephony {
25  
26  class CdmaSmsParameterRecord {
27  public:
28      virtual ~CdmaSmsParameterRecord() = default;
29      virtual bool Encode(SmsWriteBuffer &pdu) = 0;
30      virtual bool Decode(SmsReadBuffer &pdu) = 0;
31  
32  protected:
33      inline bool IsInvalidPdu(SmsReadBuffer &pdu);
34  
35  public:
36      uint8_t id_ { RESERVED };
37      uint8_t len_ { 0 };
38  
39      enum ParameterId : uint8_t {
40          TELESERVICE_ID = 0x00,
41          SERVICE_CATEGORY = 0x01,
42          ORG_ADDRESS = 0x02,
43          ORG_SUB_ADDRESS = 0x03,
44          DEST_ADDRESS = 0x04,
45          DEST_SUB_ADDRESS = 0x05,
46          BEARER_REPLY_OPTION = 0x06,
47          CAUSE_CODES = 0x07,
48          BEARER_DATA = 0x08,
49          RESERVED
50      };
51  };
52  
53  class CdmaSmsTeleserviceId : public CdmaSmsParameterRecord {
54  public:
55      explicit CdmaSmsTeleserviceId(uint16_t &id);
56      bool Encode(SmsWriteBuffer &pdu) override;
57      bool Decode(SmsReadBuffer &pdu) override;
58  
59  private:
60      uint16_t &teleserviceId_;
61  };
62  
63  class CdmaSmsServiceCategory : public CdmaSmsParameterRecord {
64  public:
65      explicit CdmaSmsServiceCategory(uint16_t &cat);
66      bool Encode(SmsWriteBuffer &pdu) override;
67      bool Decode(SmsReadBuffer &pdu) override;
68  
69  private:
70      uint16_t &serviceCat_;
71  };
72  
73  class CdmaSmsBearerReply : public CdmaSmsParameterRecord {
74  public:
75      explicit CdmaSmsBearerReply(uint8_t &replySeq);
76      bool Encode(SmsWriteBuffer &pdu) override;
77      bool Decode(SmsReadBuffer &pdu) override;
78  
79  private:
80      uint8_t &replySeq_;
81  };
82  
83  class CdmaSmsCauseCodes : public CdmaSmsParameterRecord {
84  public:
85      explicit CdmaSmsCauseCodes(TransportCauseCode &code);
86      bool Encode(SmsWriteBuffer &pdu) override;
87      bool Decode(SmsReadBuffer &pdu) override;
88  
89  private:
90      TransportCauseCode &code_;
91      enum ErrorClass : uint8_t { NONE = 0b00, TEMPORARY = 0b10, PERMANENT = 0b11 };
92  };
93  
94  class CdmaSmsAddressParameter : public CdmaSmsParameterRecord {
95  public:
96      CdmaSmsAddressParameter(TransportAddr &address, uint8_t id);
97      bool Encode(SmsWriteBuffer &pdu) override;
98      bool Decode(SmsReadBuffer &pdu) override;
99  
100  private:
101      bool EncodeAddress(SmsWriteBuffer &pdu);
102      bool DecodeAddress(SmsReadBuffer &pdu);
103  
104  private:
105      TransportAddr &address_;
106      bool isInvalid_ { false };
107  };
108  
109  class CdmaSmsSubaddress : public CdmaSmsParameterRecord {
110  public:
111      CdmaSmsSubaddress(TransportSubAddr &address, uint8_t id);
112      bool Encode(SmsWriteBuffer &pdu) override;
113      bool Decode(SmsReadBuffer &pdu) override;
114  
115  private:
116      TransportSubAddr &address_;
117      bool isInvalid_ { false };
118      enum SubaddressType : uint8_t { NSAP = 0b000, USER = 0b001, RESERVED };
119  };
120  
121  class CdmaSmsBearerData : public CdmaSmsParameterRecord {
122  public:
123      explicit CdmaSmsBearerData(CdmaTeleserviceMsg &msg);
124      CdmaSmsBearerData(CdmaTeleserviceMsg &msg, SmsReadBuffer &pdu, bool isCMAS = false);
125      bool Encode(SmsWriteBuffer &pdu) override;
126      bool Decode(SmsReadBuffer &pdu) override;
127  
128  private:
129      std::unique_ptr<CdmaSmsTeleserviceMessage> teleserviceMessage_ { nullptr };
130  };
131  
132  } // namespace Telephony
133  } // namespace OHOS
134  #endif
135