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