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