• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 Huawei Device Co., Ltd.
3  * Copyright (C) 2014 Samsung Electronics Co., Ltd. All rights reserved
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef GSM_PDU_CODE_TYPE_H
18 #define GSM_PDU_CODE_TYPE_H
19 
20 #include "sms_pdu_code_type.h"
21 
22 #include <cstdint>
23 
24 namespace OHOS {
25 namespace Telephony {
26 static constexpr uint8_t MAX_ADDRESS_LEN = 21;
27 static constexpr uint8_t MAX_SEGMENT_NUM = 15;
28 
29 using SMS_TON_T = unsigned char;
30 using SMS_NPI_T = unsigned char;
31 
32 // from 3GPP TS 23.040 V5.1.0 9.1.2.5 Address fields
33 enum SmsTon {
34     SMS_TON_UNKNOWN = 0, /* unknown */
35     SMS_TON_INTERNATIONAL = 1, /* international number */
36     SMS_TON_NATIONAL = 2, /* national number */
37     SMS_TON_NETWORK_SPECIFIC = 3, /* network specific number */
38     SMS_TON_DEDICATED_ACCESS = 4, /* subscriber number */
39     SMS_TON_ALPHA_NUMERIC = 5, /* alphanumeric, GSM 7-bit default */
40     SMS_TON_ABBREVIATED_NUMBER = 6, /* abbreviated number */
41     SMS_TON_RESERVED_FOR_EXT = 7 /* reserved for extension */
42 };
43 
44 // from 3GPP TS 23.038 V4.3.0 5 CBS Data Coding Scheme
45 enum SmsMessageClass {
46     /** class0 Indicates an instant message, which is displayed immediately after being received. */
47     SMS_INSTANT_MESSAGE = 0,
48     /** class1 Indicates an SMS message that can be stored on the device or SIM card based on the storage status. */
49     SMS_OPTIONAL_MESSAGE,
50     /** class2 Indicates an SMS message containing SIM card information, which is to be stored in a SIM card. */
51     SMS_SIM_MESSAGE,
52     /** class3 Indicates an SMS message to be forwarded to another device. */
53     SMS_FORWARD_MESSAGE,
54     /** Indicates an unknown type. */
55     SMS_CLASS_UNKNOWN,
56 };
57 
58 // from 3GPP TS 23.038 V4.3.0 4 SMS Data Coding Scheme
59 enum SmsCodingGroup {
60     SMS_GENERAL_GROUP = 0, // General Data Coding indication
61     SMS_CODING_CLASS_GROUP, // Data coding/message class
62     SMS_DELETION_GROUP, // Message Marked for Automatic Deletion Group
63     SMS_DISCARD_GROUP, // Message Waiting Indication Group: Discard Message
64     SMS_STORE_GROUP, // Message Waiting Indication Group: Store Message
65     SMS_UNKNOWN_GROUP, // Reserved coding groups
66 };
67 
68 // from 3GPP TS 23.040 V5.1.0 3.2.3 Protocol Identifier
69 enum SmsPid {
70     SMS_NORMAL_PID =
71         0x00, // implicit device type is specific to this SC, or can be concluded on the basis of the address
72 
73     SMS_TELEX_PID = 0x21, // telex (or teletex reduced to telex format)
74     SMS_GROUP3_TELEX_PID = 0x22, // group 3 telefax
75     SMS_GROUP4_TELEX_PID = 0x23, // group 4 telefax
76     SMS_VOICE_PID = 0x24, // voice telephone (i.e. conversion to speech)
77     SMS_ERMES_PID = 0x25, // ERMES (European Radio Messaging System)
78     SMS_NPS_PID = 0x26, // National Paging system (known to the SC)
79     SMS_VIDEO_PID = 0x27, // Videotex (T.100 [20] /T.101 [21])
80     SMS_TELETEX_UNSPEC_PID = 0x28, // teletex, carrier unspecified
81     SMS_TELETEX_PSPDN_PID = 0x29, // teletex, in PSPDN
82     SMS_TELETEX_CSPDN_PID = 0x2A, // teletex, in CSPDN
83     SMS_TELETEX_PSTN_PID = 0x2B, // teletex, in analog PSTN
84     SMS_TELETEX_ISDN_PID = 0x2C, // teletex, in digital ISDN
85     SMS_UCI_PID = 0x2D, // UCI (Universal Computer Interface, ETSI DE/PS 3 01 3)
86     SMS_x400_PID = 0x31, // any public X.400 based message handling system
87     SMS_EMAIL_PID = 0x32, // Internet Electronic Mail
88 
89     SMS_TYPE0_PID = 0x40, // Short Message Type 0
90     SMS_REPLACE_TYPE1_PID = 0x41, // Replace Short Message Type 1
91     SMS_REPLACE_TYPE2_PID = 0x42, // Replace Short Message Type 2
92     SMS_REPLACE_TYPE3_PID = 0x43, // Replace Short Message Type 3
93     SMS_REPLACE_TYPE4_PID = 0x44, // Replace Short Message Type 4
94     SMS_REPLACE_TYPE5_PID = 0x45, // Replace Short Message Type 5
95     SMS_REPLACE_TYPE6_PID = 0x46, // Replace Short Message Type 6
96     SMS_REPLACE_TYPE7_PID = 0x47, // Replace Short Message Type 7
97 
98     SMS_RETURN_CALL_PID = 0x5F,
99 };
100 
101 /**
102  * @brief SmsCodingScheme
103  * from 3GPP TS 23.040 V5.1.0 9.2.3.10 TP Data Coding Scheme (TP DCS)
104  */
105 enum SmsCodingScheme {
106     SMS_CODING_7BIT = 0, // GSM 7 bit default alphabet
107     SMS_CODING_8BIT, // 8 bit data
108     SMS_CODING_UCS2, // UCS2 (16bit) [10]
109     SMS_CODING_AUTO,
110     SMS_CODING_EUCKR,
111     SMS_CODING_ASCII7BIT, // cdma 7 bit defualt alphabet
112 };
113 
114 struct SmsTimeStamp {
115     enum SmsTimeFormat format;
116     union {
117         struct SmsTimeRel relative;
118         struct SmsTimeAbs absolute;
119     } time;
120 };
121 
122 /**
123  * @brief SmsDcs
124  * form 3GPP TS 23.038 V4.3.0 4	SMS Data Coding Scheme
125  */
126 typedef struct SmsDcs {
127     // indicates the text is compressed using the  compression algorithm defined in 3GPP TS 23.042 [13]
128     bool bCompressed;
129     // Message Waiting Indication Group: Discard Message
130     bool bMWI;
131     bool bIndActive;
132     enum SmsMessageClass msgClass;
133     enum SmsCodingScheme codingScheme;
134     enum SmsCodingGroup codingGroup;
135     enum SmsIndicatorType indType;
136 } SmsDcs_;
137 
138 /**
139  * @brief SmsVpf
140  * from 3GPP TS 23.040 V5.1.0 9.2.3.3 TP Validity Period Format (TP VPF)
141  */
142 enum SmsVpf {
143     SMS_VPF_NOT_PRESENT = 0,
144     SMS_VPF_ENHANCED,
145     SMS_VPF_RELATIVE,
146     SMS_VPF_ABSOLUTE,
147 };
148 
149 enum _SMS_REPORT_TYPE_E { SMS_REPORT_POSITIVE = 0, SMS_REPORT_NEGATIVE };
150 
151 /**
152  * @brief SmsSubmit
153  * from 3GPP TS 23.040 V5.1.0 9.2.2.2 SMS SUBMIT type
154  */
155 typedef struct SmsSubmit {
156     bool bRejectDup; // TP Reject Duplicates
157     bool bStatusReport; // TP Status report capabilities
158     bool bHeaderInd; // TP User Data Header Indicator (TP UDHI)
159     bool bReplyPath; // TP Reply Path
160     unsigned char msgRef; // TP Concatenated Short Messages
161     enum SmsVpf vpf; // TP Validity Period Format (TP VPF)
162     struct SmsAddress destAddress; // TP Destination Address (TP DA)
163     enum SmsPid pid; // TP Protocol Identifier (TP PID)
164     struct SmsDcs dcs; // TP Data Coding Scheme (TP DCS)
165     struct SmsTimeStamp validityPeriod; // TP Validity Period Format
166     struct SmsUserData userData; // TP User Data (TP UD)
167 } SmsSubmit_;
168 
169 typedef struct SmsTpud {
170     int udl;
171     char ud[MAX_USER_DATA_LEN + 1];
172 } SmsTpud_;
173 
174 /**
175  * @brief SmsDeliver
176  * from 3GPP TS 23.040 V5.1.0 9.2.2.1 SMS DELIVER type
177  */
178 typedef struct SmsDeliver {
179     bool bMoreMsg; // TP More Messages to Send
180     bool bStatusReport; // TP Status report capabilities
181     bool bHeaderInd; // TP User Data Header Indicator (TP UDHI)
182     bool bReplyPath; // TP Reply Path
183     struct SmsAddress originAddress; // TP Originating Address (TP OA)
184     enum SmsPid pid; // TP Protocol Identifier (TP PID)
185     struct SmsDcs dcs; // TP Data Coding Scheme (TP DCS)
186     struct SmsTimeStamp timeStamp; // TP Service Centre Time Stamp
187     struct SmsUserData userData; // TP User Data (TP UD)
188     struct SmsTpud udData; // TP User Data (TP UD)
189 } SmsDeliver_;
190 
191 using SMS_REPORT_TYPE_T = unsigned char;
192 using SMS_FAIL_CAUSE_T = unsigned char;
193 
194 /**
195  * @brief SmsDeliverReport
196  * from 3GPP TS 23.040 V5.1.0 9.2.2.1a SMS DELIVER REPORT type
197  */
198 typedef struct SmsDeliverReport {
199     SMS_REPORT_TYPE_T reportType; // TP Message Type Indicator
200     bool bHeaderInd; // TP User Data Header Indicator (TP UDHI)
201     SMS_FAIL_CAUSE_T failCause; // TP Failure Cause
202     unsigned char paramInd; // TP Parameter Indicator
203     enum SmsPid pid; // TP Protocol Identifier (TP PID)
204     struct SmsDcs dcs; // TP Data Coding Scheme (TP DCS)
205     struct SmsUserData userData; // TP User Data (TP UD)
206 } SmsDeliverReport_;
207 
208 using SMS_STATUS_T = unsigned char;
209 
210 /**
211  * @brief SmsStatusReport
212  * from 3GPP TS 23.040 V5.1.0 9.2.2.3 SMS STATUS REPORT type
213  */
214 typedef struct SmsStatusReport {
215     bool bMoreMsg; // More Messages to Send
216     bool bStatusReport; // TP Status Report Qualifier
217     bool bHeaderInd; // TP-User-Data-Header-Indication
218     unsigned char msgRef; // TP Message Reference
219     struct SmsAddress recipAddress; // TP Recipient Address
220     struct SmsTimeStamp timeStamp; // TP Service Centre Time Stamp
221     struct SmsTimeStamp dischargeTime; // TP Discharge Time
222     SMS_STATUS_T status; // TP Status
223     unsigned char paramInd; // TP-Parameter-Indicator
224     enum SmsPid pid; // TP-Protocol-Identifier
225     struct SmsDcs dcs; // TP-Data-Coding-Scheme
226     struct SmsUserData userData; // TP-User-Data
227 } SmsStatusReport_;
228 
229 // from 3GPP TS 23.040 V5.1.0 9.2.3.23 TP User Data Header Indicator (TP UDHI)
230 enum SmsTpduType {
231     SMS_TPDU_SUBMIT,
232     SMS_TPDU_DELIVER,
233     SMS_TPDU_DELIVER_REP,
234     SMS_TPDU_STATUS_REP,
235 };
236 
237 typedef struct SmsTpdu {
238     enum SmsTpduType tpduType;
239     union {
240         struct SmsSubmit submit;
241         struct SmsDeliver deliver;
242         struct SmsDeliverReport deliverRep;
243         struct SmsStatusReport statusRep;
244     } data;
245 } SmsTpdu_S;
246 
247 // from 3GPP TS 23.040 V5.1.0 9.2.3.24.6 UDH Source Indicator
248 enum SmsUDHType {
249     SMS_UDH_CONCAT_8BIT = 0x00,
250     SMS_UDH_SPECIAL_SMS = 0x01,
251     /* 0x02, 0x03 - Reserved */
252     SMS_UDH_APP_PORT_8BIT = 0x04,
253     SMS_UDH_APP_PORT_16BIT = 0x05,
254     SMS_UDH_SC_CONTROL = 0x06,
255     SMS_UDH_SRC_IND = 0x07,
256     SMS_UDH_CONCAT_16BIT = 0x08,
257     SMS_UDH_WCMP = 0x09,
258     SMS_UDH_EMS_FIRST = 0x0a,
259     SMS_UDH_EMS_LAST = 0x1f,
260     SMS_UDH_ALTERNATE_REPLY_ADDRESS = 0x22,
261     SMS_UDH_SINGLE_SHIFT = 0x24,
262     SMS_UDH_LOCKING_SHIFT = 0x25,
263     SMS_UDH_NONE = 0xFF,
264 };
265 } // namespace Telephony
266 } // namespace OHOS
267 #endif