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