• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_SUB_PARAMETER_H
17 #define CDMA_SMS_SUB_PARAMETER_H
18 
19 #include "cdma_sms_common.h"
20 #include "sms_pdu_buffer.h"
21 
22 namespace OHOS {
23 namespace Telephony {
24 
25 class CdmaSmsSubParameter {
26 public:
27     virtual ~CdmaSmsSubParameter() = default;
28     virtual bool Encode(SmsWriteBuffer &pdu) = 0;
29     virtual bool Decode(SmsReadBuffer &pdu) = 0;
30 
31 protected:
32     inline bool IsInvalidPdu(SmsReadBuffer &pdu);
33 
34 public:
35     uint8_t id_ { RESERVED };
36     uint8_t len_ { 0 };
37 
38     enum SubParameterId : uint8_t {
39         MESSAGE_IDENTIFIER = 0x00,
40         USER_DATA = 0x01,
41         USER_RESPONSE_CODE = 0x02,
42         MESSAGE_CENTER_TIME_STAMP = 0x03,
43         VALIDITY_PERIOD_ABSOLUTE = 0x04,
44         VALIDITY_PERIOD_RELATIVE = 0x05,
45         DEFERRED_DELIVERY_TIME_ABSOLUTE = 0x06,
46         DEFERRED_DELIVERY_TIME_RELATIVE = 0x07,
47         PRIORITY_INDICATOR = 0x08,
48         PRIVACY_INDICATOR = 0x09,
49         REPLY_OPTION = 0x0A,
50         NUMBER_OF_MESSAGES = 0x0B,
51         ALERT_ON_MSG_DELIVERY = 0x0C,
52         LANGUAGE_INDICATOR = 0x0D,
53         CALLBACK_NUMBER = 0x0E,
54         MESSAGE_DISPLAY_MODE = 0x0F,
55         MULTI_ENCODING_USER_DATA = 0x10,
56         MESSAGE_DEPOSIT_INDEX = 0x11,
57         SERVICE_CATEGORY_PROGRAM_DATA = 0x12,
58         SERVICE_CATEGORY_PROGRAM_RESULT = 0x13,
59         MESSAGE_STATUS = 0x14,
60         TP_FAILURE_CAUSE = 0x15,
61         ENHANCED_VMN = 0x16,
62         ENHANCED_VMN_ACK = 0x17,
63         RESERVED
64     };
65 };
66 
67 class CdmaSmsBaseParameter : public CdmaSmsSubParameter {
68 public:
69     CdmaSmsBaseParameter(uint8_t id, uint8_t &data);
70     bool Encode(SmsWriteBuffer &pdu) override;
71     bool Decode(SmsReadBuffer &pdu) override;
72 
73 private:
74     uint8_t &data_;
75 };
76 
77 class CdmaSmsReservedParameter : public CdmaSmsSubParameter {
78 public:
79     explicit CdmaSmsReservedParameter(uint8_t id);
80     bool Encode(SmsWriteBuffer &pdu) override;
81     bool Decode(SmsReadBuffer &pdu) override;
82 };
83 
84 class CdmaSmsMessageId : public CdmaSmsSubParameter {
85 public:
86     CdmaSmsMessageId(SmsTeleSvcMsgId &msgId, uint8_t type);
87     bool Encode(SmsWriteBuffer &pdu) override;
88     bool Decode(SmsReadBuffer &pdu) override;
89     uint8_t GetMessageType();
90 
91 private:
92     SmsTeleSvcMsgId &msgId_;
93     uint8_t type_;
94 };
95 
96 class CdmaSmsAbsoluteTime : public CdmaSmsSubParameter {
97 public:
98     CdmaSmsAbsoluteTime(uint8_t id, SmsTimeAbs &time);
99     bool Encode(SmsWriteBuffer &pdu) override;
100     bool Decode(SmsReadBuffer &pdu) override;
101 
102 private:
103     inline uint8_t EncodeBCD(const uint8_t v);
104     inline uint8_t DecodeBCD(const uint8_t v);
105 
106 private:
107     SmsTimeAbs &time_;
108 };
109 
110 class CdmaSmsPriorityInd : public CdmaSmsSubParameter {
111 public:
112     explicit CdmaSmsPriorityInd(SmsPriorityIndicator &priority);
113     bool Encode(SmsWriteBuffer &pdu) override;
114     bool Decode(SmsReadBuffer &pdu) override;
115 
116 private:
117     SmsPriorityIndicator &priority_;
118 };
119 
120 class CdmaSmsPrivacyInd : public CdmaSmsSubParameter {
121 public:
122     explicit CdmaSmsPrivacyInd(SmsPrivacyIndicator &privacy);
123     bool Encode(SmsWriteBuffer &pdu) override;
124     bool Decode(SmsReadBuffer &pdu) override;
125 
126 private:
127     SmsPrivacyIndicator &privacy_;
128 };
129 
130 class CdmaSmsReplyOption : public CdmaSmsSubParameter {
131 public:
132     explicit CdmaSmsReplyOption(SmsReplyOption &replyOpt);
133     bool Encode(SmsWriteBuffer &pdu) override;
134     bool Decode(SmsReadBuffer &pdu) override;
135 
136 private:
137     SmsReplyOption &replyOpt_;
138 };
139 
140 class CdmaSmsUserData : public CdmaSmsSubParameter {
141 public:
142     CdmaSmsUserData(SmsTeleSvcUserData &data, bool &headerInd);
143     bool Encode(SmsWriteBuffer &pdu) override;
144     bool Decode(SmsReadBuffer &pdu) override;
145     static inline SmsEncodingType GetEncodingType(uint8_t v);
146 
147 private:
148     bool EncodeAscii7Bit(SmsWriteBuffer &pdu);
149     bool EncodeGsm7Bit(SmsWriteBuffer &pdu);
150     bool EncodeUnicode(SmsWriteBuffer &pdu);
151     bool Encode8BitData(SmsWriteBuffer &pdu);
152     bool EncodeHeader7Bit(SmsWriteBuffer &pdu);
153     bool EncodeHeaderUnicode(SmsWriteBuffer &pdu);
154     uint8_t DecodeHeader7Bit(SmsReadBuffer &pdu);
155     bool DecodeAscii7Bit(SmsReadBuffer &pdu, uint8_t numFields, uint8_t udhBytes);
156     bool DecodeGsm7Bit(SmsReadBuffer &pdu, uint8_t numFields, uint8_t udhBytes);
157     bool Decode8BitData(SmsReadBuffer &pdu);
158 
159 private:
160     SmsTeleSvcUserData &data_;
161     bool &headerInd_;
162 
163     enum EncodingType : uint8_t {
164         OCTET = 0x0,
165         EPM = 0x1,
166         ASCII7BIT = 0x2,
167         IA5 = 0x3,
168         UNICODE = 0x4,
169         SHIFT_JIS = 0x5,
170         KOREAN = 0x6,
171         LATIN_HEBREW = 0x7,
172         LATIN = 0x8,
173         GSM7BIT = 0x9,
174         GSMDCS = 0xa,
175         EUCKR = 0x10
176     };
177 };
178 
179 class CdmaSmsCmasData : public CdmaSmsSubParameter {
180 public:
181     explicit CdmaSmsCmasData(SmsTeleSvcCmasData &data);
182     bool Encode(SmsWriteBuffer &pdu) override;
183     bool Decode(SmsReadBuffer &pdu) override;
184 
185 private:
186     bool DecodeData(SmsReadBuffer &pdu);
187     bool DecodeType0Data(SmsReadBuffer &pdu);
188     bool DecodeType1Data(SmsReadBuffer &pdu);
189     bool DecodeType2Data(SmsReadBuffer &pdu);
190     bool DecodeAbsTime(SmsReadBuffer &pdu);
191 
192 private:
193     SmsTeleSvcCmasData &data_;
194 };
195 
196 class CdmaSmsAlertPriority : public CdmaSmsSubParameter {
197 public:
198     explicit CdmaSmsAlertPriority(SmsAlertPriority &alertPriority);
199     bool Encode(SmsWriteBuffer &pdu) override;
200     bool Decode(SmsReadBuffer &pdu) override;
201 
202 private:
203     SmsAlertPriority &alertPriority_;
204 };
205 
206 class CdmaSmsLanguageInd : public CdmaSmsSubParameter {
207 public:
208     explicit CdmaSmsLanguageInd(SmsLanguageType &language);
209     bool Encode(SmsWriteBuffer &pdu) override;
210     bool Decode(SmsReadBuffer &pdu) override;
211 
212 private:
213     SmsLanguageType &language_;
214 };
215 
216 class CdmaSmsCallbackNumber : public CdmaSmsSubParameter {
217 public:
218     CdmaSmsCallbackNumber();
219     explicit CdmaSmsCallbackNumber(SmsTeleSvcAddr &address);
220     bool Encode(SmsWriteBuffer &pdu) override;
221     bool Decode(SmsReadBuffer &pdu) override;
222 
223 private:
224     SmsTeleSvcAddr &address_;
225 };
226 
227 class CdmaSmsDepositIndex : public CdmaSmsSubParameter {
228 public:
229     explicit CdmaSmsDepositIndex(uint16_t &index);
230     bool Encode(SmsWriteBuffer &pdu) override;
231     bool Decode(SmsReadBuffer &pdu) override;
232 
233 private:
234     uint16_t &index_;
235 };
236 
237 class CdmaSmsDisplayMode : public CdmaSmsSubParameter {
238 public:
239     explicit CdmaSmsDisplayMode(SmsDisplayMode &mode);
240     bool Encode(SmsWriteBuffer &pdu) override;
241     bool Decode(SmsReadBuffer &pdu) override;
242 
243 private:
244     SmsDisplayMode &mode_;
245 };
246 
247 class CdmaSmsMessageStatus : public CdmaSmsSubParameter {
248 public:
249     explicit CdmaSmsMessageStatus(SmsStatusCode &status);
250     bool Encode(SmsWriteBuffer &pdu) override;
251     bool Decode(SmsReadBuffer &pdu) override;
252 
253 private:
254     SmsStatusCode &status_;
255 };
256 
257 class CdmaSmsNumberMessages : public CdmaSmsSubParameter {
258 public:
259     explicit CdmaSmsNumberMessages(uint32_t &num);
260     bool Encode(SmsWriteBuffer &pdu) override;
261     bool Decode(SmsReadBuffer &pdu) override;
262 
263 private:
264     uint32_t &num_;
265 };
266 
267 class CdmaSmsEnhancedVmn : public CdmaSmsSubParameter {
268 public:
269     explicit CdmaSmsEnhancedVmn(SmsEnhancedVmn &vmn);
270     bool Encode(SmsWriteBuffer &pdu) override;
271     bool Decode(SmsReadBuffer &pdu) override;
272 
273 private:
274     bool DecodeHeader(SmsReadBuffer &pdu);
275     bool DecodeVoiceMail(SmsReadBuffer &pdu);
276     bool DecodeAccessNumber(SmsReadBuffer &pdu);
277     bool DecodeCallingPartyNumber(SmsReadBuffer &pdu);
278 
279 private:
280     SmsEnhancedVmn &vmn_;
281 };
282 
283 class CdmaSmsEnhancedVmnAck : public CdmaSmsSubParameter {
284 public:
285     explicit CdmaSmsEnhancedVmnAck(SmsEnhancedVmnAck &ack);
286     bool Encode(SmsWriteBuffer &pdu) override;
287     bool Decode(SmsReadBuffer &pdu) override;
288 
289 private:
290     SmsEnhancedVmnAck &ack_;
291 };
292 
293 } // namespace Telephony
294 } // namespace OHOS
295 #endif
296