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 CELLULAR_DATA_CONSTANT_H
17 #define CELLULAR_DATA_CONSTANT_H
18 
19 #include <array>
20 #include <string>
21 #include <vector>
22 
23 #include "cellular_data_types.h"
24 
25 namespace OHOS {
26 namespace Telephony {
27 enum ApnProfileState {
28     PROFILE_STATE_IDLE,
29     PROFILE_STATE_CONNECTING,
30     PROFILE_STATE_CONNECTED,
31     PROFILE_STATE_DISCONNECTING,
32     PROFILE_STATE_FAILED,
33     PROFILE_STATE_RETRYING
34 };
35 
36 enum class RecoveryState : int32_t {
37     STATE_REQUEST_CONTEXT_LIST,
38     STATE_CLEANUP_CONNECTIONS,
39     STATE_REREGISTER_NETWORK,
40     STATE_RADIO_STATUS_RESTART
41 };
42 
43 struct AddressInfo {
44     std::string ip = "";
45     std::string netMask = "";
46     uint8_t type = 0;
47     uint8_t prefixLen = 0;
48 };
49 
50 struct RouteInfo {
51     std::string ip = "";
52     uint8_t type = 0;
53     std::string destination = "";
54 };
55 
56 struct NetSupplier {
57     uint32_t supplierId = 0;
58     uint64_t capability = 0;
59     int32_t slotId = 0;
60     int32_t simId = 0;
61     int32_t regState = -1;
62 };
63 enum RegisterType {
64     UNKOWN,
65     REGISTER,
66     REQUEST
67 };
68 struct NetRequest {
69     uint64_t capability = 0;
70     std::string ident = "";
71     int32_t registerType = UNKOWN;
72     uint64_t bearTypes = 0;
73     uint32_t uid = 0;
74 };
75 
76 static const uint32_t DEFAULT_BANDWIDTH = 14;
77 struct LinkBandwidthInfo {
78     uint32_t upBandwidth = DEFAULT_BANDWIDTH;
79     uint32_t downBandwidth = DEFAULT_BANDWIDTH;
80 };
81 
CellularDataStateAdapter(ApnProfileState state)82 constexpr int32_t CellularDataStateAdapter(ApnProfileState state)
83 {
84     switch (state) {
85         case PROFILE_STATE_CONNECTING:
86             return static_cast<int32_t>(DataConnectionStatus::DATA_STATE_CONNECTING);
87         case PROFILE_STATE_CONNECTED:
88             [[fallthrough]]; // fall_through
89         case PROFILE_STATE_DISCONNECTING:
90             return static_cast<int32_t>(DataConnectionStatus::DATA_STATE_CONNECTED);
91         case PROFILE_STATE_FAILED:
92             [[fallthrough]]; // fall_through
93         case PROFILE_STATE_RETRYING:
94             [[fallthrough]]; // fall_through
95         case PROFILE_STATE_IDLE:
96             return static_cast<int32_t>(DataConnectionStatus::DATA_STATE_DISCONNECTED);
97         default:
98             return static_cast<int32_t>(DataConnectionStatus::DATA_STATE_DISCONNECTED);
99     }
100 }
101 
WrapCellularDataState(const int32_t cellularDataState)102 constexpr int32_t WrapCellularDataState(const int32_t cellularDataState)
103 {
104     switch (cellularDataState) {
105         case static_cast<int32_t>(DataConnectionStatus::DATA_STATE_DISCONNECTED): {
106             return static_cast<int32_t>(DataConnectState::DATA_STATE_DISCONNECTED);
107         }
108         case static_cast<int32_t>(DataConnectionStatus::DATA_STATE_CONNECTING): {
109             return static_cast<int32_t>(DataConnectState::DATA_STATE_CONNECTING);
110         }
111         case static_cast<int32_t>(DataConnectionStatus::DATA_STATE_CONNECTED): {
112             return static_cast<int32_t>(DataConnectState::DATA_STATE_CONNECTED);
113         }
114         case static_cast<int32_t>(DataConnectionStatus::DATA_STATE_SUSPENDED): {
115             return static_cast<int32_t>(DataConnectState::DATA_STATE_SUSPENDED);
116         }
117         default: {
118             return static_cast<int32_t>(DataConnectState::DATA_STATE_UNKNOWN);
119         }
120     }
121 }
122 
123 enum DataContextRolesId {
124     DATA_CONTEXT_ROLE_INVALID_ID = -1,
125     DATA_CONTEXT_ROLE_ALL_ID = 0,
126     DATA_CONTEXT_ROLE_DEFAULT_ID = 1,
127     DATA_CONTEXT_ROLE_MMS_ID = 2,
128     DATA_CONTEXT_ROLE_SUPL_ID = 3,
129     DATA_CONTEXT_ROLE_DUN_ID = 4,
130     DATA_CONTEXT_ROLE_IMS_ID = 5,
131     DATA_CONTEXT_ROLE_IA_ID = 6,
132     DATA_CONTEXT_ROLE_EMERGENCY_ID = 7,
133     DATA_CONTEXT_ROLE_INTERNAL_DEFAULT_ID = 8,
134     DATA_CONTEXT_ROLE_XCAP_ID = 9
135 };
136 
137 enum class DataContextPriority : int32_t { PRIORITY_NONE, PRIORITY_LOW, PRIORITY_NORMAL, PRIORITY_HIGH };
138 
139 enum TelCallStatus {
140     CALL_STATUS_UNKNOWN = -1,
141     CALL_STATUS_ACTIVE = 0,
142     CALL_STATUS_HOLDING = 1,
143     CALL_STATUS_DIALING = 2,
144     CALL_STATUS_ALERTING = 3,
145     CALL_STATUS_INCOMING = 4,
146     CALL_STATUS_WAITING = 5,
147     CALL_STATUS_DISCONNECTED = 6,
148     CALL_STATUS_DISCONNECTING = 7,
149     CALL_STATUS_IDLE = 8,
150 };
151 
152 enum class DisConnectionReason : int32_t {
153     REASON_NORMAL,
154     REASON_GSM_AND_CALLING_ONLY,
155     REASON_RETRY_CONNECTION,
156     REASON_CLEAR_CONNECTION,
157     REASON_CHANGE_CONNECTION,
158     REASON_PERMANENT_REJECT
159 };
160 
161 enum class ApnTypes : int32_t {
162     NONETYPE = 0,
163     DEFAULT = 1,
164     MMS = 2,
165     SUPL = 4,
166     DUN = 8,
167     HIPRI = 16,
168     FOTA = 32,
169     IMS = 64,
170     CBS = 128,
171     IA = 256,
172     EMERGENCY = 512,
173     MCX = 1024,
174     XCAP = 2048,
175     INTERNAL_DEFAULT = 4096,
176     ALL = 8191,
177 };
178 
179 enum class RetryScene : int32_t {
180     RETRY_SCENE_SETUP_DATA = 0,
181     RETRY_SCENE_MODEM_DEACTIVATE = 1,
182     RETRY_SCENE_OTHERS = 2,
183 };
184 
185 static constexpr const char *DATA_CONTEXT_ROLE_ALL = "*";
186 static constexpr const char *DATA_CONTEXT_ROLE_DEFAULT = "default";
187 static constexpr const char *DATA_CONTEXT_ROLE_MMS = "mms";
188 static constexpr const char *DATA_CONTEXT_ROLE_SUPL = "supl";
189 static constexpr const char *DATA_CONTEXT_ROLE_DUN = "dun";
190 static constexpr const char *DATA_CONTEXT_ROLE_IMS = "ims";
191 static constexpr const char *DATA_CONTEXT_ROLE_IA = "ia";
192 static constexpr const char *DATA_CONTEXT_ROLE_EMERGENCY = "emergency";
193 static constexpr const char *DATA_CONTEXT_ROLE_INTERNAL_DEFAULT = "internal_default";
194 static constexpr const char *DATA_CONTEXT_ROLE_XCAP = "xcap";
195 static const int32_t DATA_PROFILE_DEFAULT = 0;
196 static const int32_t DATA_PROFILE_MMS = 1;
197 static const int32_t DATA_PROFILE_INTERNAL_DEFAULT = 2;
198 static const int32_t DATA_PROFILE_SUPL = 3;
199 static const int32_t DATA_PROFILE_DUN = 4;
200 static const int32_t DATA_PROFILE_IA = 5;
201 static const int32_t DATA_PROFILE_XCAP = 6;
202 static const int32_t CMCC_MCC_MNC = 46002;
203 static const int32_t DEFAULT_AUTH_TYPE = 0;
204 static const int32_t DEFAULT_MTU = 1500;
205 static const uint8_t DEFAULT_STRENGTH = 20;
206 static const uint32_t DEFAULT_FREQUENCY = 50;
207 static const int64_t CORE_INIT_DELAY_TIME = 1000;
208 static const int32_t MASK_BYTE_BIT = 8;
209 static const int32_t IPV4_BIT = 32;
210 static const int32_t IPV6_BIT = 128;
211 static const int32_t MIN_IPV6_ITEM = 16;
212 static const int32_t MAX_IPV4_ITEM = 8;
213 static const int32_t MIN_IPV4_ITEM = 4;
214 static constexpr const char *DEFAULT_OPERATOR_NUMERIC = "46001";
215 static constexpr const char *DATA_METERED_CONTEXT_ROLES = "default";
216 static constexpr const char *IS_CELLULAR_DATA_ENABLE = "isCellularDataEnable";
217 static constexpr const char *IS_ROAMING = "isRoaming";
218 static constexpr const char *SETTING_SWITCH = "settingSwitch";
219 static constexpr const char *IDENT_PREFIX = "simId";
220 static constexpr const char *DEFAULT_HOSTNAME = "";
221 static constexpr const char *DEFAULT_MASK = "";
222 static constexpr const char *CELLULAR_DATA_RDB_URI = "datashare:///com.ohos.pdpprofileability";
223 static constexpr const char *CELLULAR_DATA_RDB_SELECTION =
224     "datashare:///com.ohos.pdpprofileability/net/pdp_profile";
225 static constexpr const char *CELLULAR_DATA_RDB_RESET =
226     "datashare:///com.ohos.pdpprofileability/net/pdp_profile/reset";
227 static constexpr const char *CELLULAR_DATA_RDB_PREFER =
228     "datashare:///com.ohos.pdpprofileability/net/pdp_profile/preferapn";
229 static constexpr const char *CELLULAR_DATA_RDB_INIT =
230     "datashare:///com.ohos.pdpprofileability/net/pdp_profile/init";
231 static constexpr const char *CELLULAR_DATA_SETTING_URI =
232     "datashare:///com.ohos.settingsdata/entry/settingsdata/SETTINGSDATA?Proxy=true";
233 static constexpr const char *CELLULAR_DATA_SETTING_EXT_URI = "datashare:///com.ohos.settingsdata.DataAbility";
234 static constexpr const char *CELLULAR_DATA_SETTING_DATA_ENABLE_URI =
235     "datashare:///com.ohos.settingsdata/entry/settingsdata/SETTINGSDATA?Proxy=true&key=cellular_data_enable";
236 static constexpr const char *CELLULAR_DATA_SETTING_DATA_ROAMING_URI =
237     "datashare:///com.ohos.settingsdata/entry/settingsdata/SETTINGSDATA?Proxy=true&key=cellular_data_roaming_enable";
238 static constexpr const char *CELLULAR_DATA_SETTING_DATA_INCALL_URI =
239     "datashare:///com.ohos.settingsdata/entry/settingsdata/SETTINGSDATA?Proxy=true&key=cellular_data_incall_enable";
240 static constexpr const char *CELLULAR_DATA_SETTING_INTELLIGENCE_SWITCH_URI =
241     "datashare:///com.ohos.settingsdata/entry/settingsdata/SETTINGSDATA?"
242     "Proxy=true&key=intelligence_card_switch_enable";
243 static const int32_t DEFAULT_NET_STATISTICS_PERIOD = 3 * 1000;
244 static const int32_t DATA_STALL_ALARM_NON_AGGRESSIVE_DELAY_IN_MS_DEFAULT = 1000 * 60 * 10;
245 static const int32_t DATA_STALL_ALARM_AGGRESSIVE_DELAY_IN_MS_DEFAULT = 1000 * 10;
246 static const int32_t ESTABLISH_DATA_CONNECTION_DELAY = 1 * 1000;
247 static const int32_t CONNECTION_DISCONNECTION_TIMEOUT = 180 * 1000;
248 static const int32_t RECOVERY_TRIGGER_PACKET = 10;
249 static const int32_t ERROR_APN_ID = -1;
250 static const int32_t VALID_IP_SIZE = 2;
251 static const int32_t TYPE_REQUEST_NET = 1;
252 static const int32_t TYPE_RELEASE_NET = 0;
253 static const int32_t DEFAULT_READ_APN_TIME = 2;
254 static const int32_t DEFAULT_MCC_SIZE = 3;
255 static const int32_t NULL_POINTER_EXCEPTION = -1;
256 static const int32_t PATH_PARAMETER_SIZE = 128;
257 static constexpr const char *ROUTED_IPV4 = "0.0.0.0";
258 static constexpr const char *ROUTED_IPV6 = "::";
259 static constexpr const char *CONFIG_DOWNLINK_THRESHOLDS = "persist.sys.data.downlink";
260 static constexpr const char *CONFIG_UPLINK_THRESHOLDS = "persist.sys.data.uplink";
261 static constexpr const char *CONFIG_TCP_BUFFER = "persist.sys.data.tcpbuffer";
262 static constexpr const char *CONFIG_PREFERAPN = "persist.sys.data.preferapn";
263 static constexpr const char *CONFIG_MOBILE_MTU = "persist.sys.data.mobilemtu";
264 static constexpr const char *CONFIG_DATA_SERVICE_EXT_PATH = "persist.sys.data.dataextpath";
265 static constexpr const char *CONFIG_MULTIPLE_CONNECTIONS = "persist.sys.data.multiple.connections";
266 static constexpr const char *CAPACITY_THRESHOLDS_FOR_DOWNLINK = "100,500,1000,5000,10000,20000,50000,75000,"
267                                                                 "100000,200000,500000,1000000,1500000,2000000";
268 static constexpr const char *CAPACITY_THRESHOLDS_FOR_UPLINK = "100,500,1000,5000,10000,20000,50000,75000,"
269                                                               "100000,200000,500000";
270 static constexpr const char *DEFAULT_TCP_BUFFER_CONFIG = "UMTS:58254,349525,1048576,58254,349525,1048576;"
271                                                          "HSPA:40778,244668,734003,16777,100663,301990;"
272                                                          "HSUPA:131072,262144,2441216,4096,16384,399360;"
273                                                          "HSDPA:61167,367002,1101005,8738,52429,262114;"
274                                                          "HSPAP:122334,734003,2202010,32040,192239,576717;"
275                                                          "EDGE:4093,26280,70800,4096,16384,70800;"
276                                                          "eHRPD:131072,262144,1048576,4096,16384,524288;"
277                                                          "1xRTT:16384,32768,131072,4096,16384,102400;"
278                                                          "GPRS:4092,8760,48000,4096,8760,48000;"
279                                                          "EVDO:4094,87380,262144,4096,16384,262144;"
280                                                          "LTE:524288,4194304,8388608,262144,524288,1048576;"
281                                                          "NR:2097152,6291456,16777216,512000,2097152,8388608;"
282                                                          "LTE_CA:4096,6291456,12582912,4096,1048576,2097152";
283 constexpr const char *DEFAULT_BANDWIDTH_CONFIG =
284     "GPRS:24,24;EDGE:70,18;UMTS:115,115;CDMA-IS95A:14,14;"
285     "CDMA-IS95B:14,14;1xRTT:30,30;EvDo-rev.0:750,48;EvDo-rev.A:950,550;HSDPA:4300,620;"
286     "HSUPA:4300,1800;HSPA:4300,1800;EvDo-rev.B:1500,550;eHRPD:750,48;HSPAP:13000,3400;"
287     "TD-SCDMA:115,115;LTE:30000,15000;NR_NSA:47000,18000;NR_NSA_MMWAVE:145000,60000;"
288     "NR_SA:145000,60000";
289 static constexpr const char *DEFAULT_PREFER_APN = "1";
290 static constexpr const char *DEFAULT_MOBILE_MTU = "1500";
291 static constexpr const char *DEFAULT_MULTIPLE_CONNECTIONS = "1";
292 static const int MAX_BUFFER_SIZE = 1024;
293 static const int MIN_BUFFER_SIZE = 5;
294 static const int UP_DOWN_LINK_SIZE = 100;
295 static const int32_t VALID_VECTOR_SIZE = 2;
296 static const int32_t DELAY_SET_RIL_BANDWIDTH_MS = 3000;
297 static const int32_t DELAY_SET_RIL_UP_DOWN_BANDWIDTH_MS = 50;
298 static constexpr const char *CELLULAR_DATA_COLUMN_ENABLE = "cellular_data_enable";
299 static constexpr const char *CELLULAR_DATA_COLUMN_ROAMING = "cellular_data_roaming_enable";
300 static constexpr const char *CELLULAR_DATA_COLUMN_INCALL = "cellular_data_incall_enable";
301 static constexpr const char *INTELLIGENCE_SWITCH_COLUMN_ENABLE = "intelligence_card_switch_enable";
302 static constexpr const char *CELLULAR_DATA_COLUMN_KEYWORD = "KEYWORD";
303 static constexpr const char *CELLULAR_DATA_COLUMN_VALUE = "VALUE";
304 static const int32_t INVALID_SIM_ID = 0;
305 static const int32_t INVALID_SLOT_ID = -1;
306 static const int32_t CELLULAR_DATA_VSIM_SLOT_ID = 2;
307 static const int32_t SUPPLIER_INVALID_REG_STATE = -1;
308 static const int32_t INVALID_DELAY_NO_RETRY = -1;
309 } // namespace Telephony
310 } // namespace OHOS
311 #endif // CELLULAR_DATA_CONSTANT_H
312