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 #include "cellular_data_state_machine.h"
17
18 #include <cinttypes>
19 #include <string_ex.h>
20
21 #include "activating.h"
22 #include "active.h"
23 #include "apn_manager.h"
24 #include "cellular_data_hisysevent.h"
25 #include "cellular_data_utils.h"
26 #include "core_manager_inner.h"
27 #include "default.h"
28 #include "disconnecting.h"
29 #include "inactive.h"
30 #include "radio_event.h"
31 #include "telephony_common_utils.h"
32 #include "telephony_log_wrapper.h"
33
34 namespace OHOS {
35 using namespace NetManagerStandard;
36 namespace Telephony {
37 static const int32_t INVALID_MTU_VALUE = -1;
IsInactiveState() const38 bool CellularDataStateMachine::IsInactiveState() const
39 {
40 return currentState_ == inActiveState_;
41 }
42
IsActivatingState() const43 bool CellularDataStateMachine::IsActivatingState() const
44 {
45 return currentState_ == activatingState_;
46 }
47
IsDisconnectingState() const48 bool CellularDataStateMachine::IsDisconnectingState() const
49 {
50 return currentState_ == disconnectingState_;
51 }
52
IsActiveState() const53 bool CellularDataStateMachine::IsActiveState() const
54 {
55 return currentState_ == activeState_;
56 }
57
IsDefaultState() const58 bool CellularDataStateMachine::IsDefaultState() const
59 {
60 return currentState_ == defaultState_;
61 }
62
SetCapability(uint64_t capability)63 void CellularDataStateMachine::SetCapability(uint64_t capability)
64 {
65 capability_ = capability;
66 }
67
GetCapability() const68 uint64_t CellularDataStateMachine::GetCapability() const
69 {
70 return capability_;
71 }
72
GetCid() const73 int32_t CellularDataStateMachine::GetCid() const
74 {
75 return cid_;
76 }
77
SetCid(const int32_t cid)78 void CellularDataStateMachine::SetCid(const int32_t cid)
79 {
80 cid_ = cid;
81 }
82
GetSlotId() const83 int32_t CellularDataStateMachine::GetSlotId() const
84 {
85 if (cdConnectionManager_ == nullptr) {
86 TELEPHONY_LOGE("cdConnectionManager_ is null");
87 return DEFAULT_SIM_SLOT_ID;
88 }
89 return cdConnectionManager_->GetSlotId();
90 }
91
GetApnItem() const92 sptr<ApnItem> CellularDataStateMachine::GetApnItem() const
93 {
94 return apnItem_;
95 }
96
DoConnect(const DataConnectionParams & connectionParams)97 void CellularDataStateMachine::DoConnect(const DataConnectionParams &connectionParams)
98 {
99 if (connectionParams.GetApnHolder() == nullptr) {
100 TELEPHONY_LOGE("apnHolder is null");
101 return;
102 }
103 apnId_ = ApnManager::FindApnIdByApnName(connectionParams.GetApnHolder()->GetApnType());
104 sptr<ApnItem> apn = connectionParams.GetApnHolder()->GetCurrentApn();
105 apnItem_ = apn;
106 if (apnItem_ == nullptr) {
107 TELEPHONY_LOGE("apnItem is null");
108 return;
109 }
110 const int32_t slotId = GetSlotId();
111 int32_t radioTech = static_cast<int32_t>(RadioTech::RADIO_TECHNOLOGY_INVALID);
112 CoreManagerInner::GetInstance().GetPsRadioTech(slotId, radioTech);
113 ActivateDataParam activeDataParam;
114 activeDataParam.param = connectId_;
115 activeDataParam.radioTechnology = radioTech;
116 activeDataParam.allowRoaming = connectionParams.GetRoamingState();
117 activeDataParam.isRoaming = connectionParams.GetUserDataRoaming();
118 activeDataParam.dataProfile.profileId = apn->attr_.profileId_;
119 activeDataParam.dataProfile.apn = apn->attr_.apn_;
120 activeDataParam.dataProfile.protocol = apn->attr_.protocol_;
121 activeDataParam.dataProfile.verType = apn->attr_.authType_;
122 activeDataParam.dataProfile.userName = apn->attr_.user_;
123 activeDataParam.dataProfile.password = apn->attr_.password_;
124 activeDataParam.dataProfile.roamingProtocol = apn->attr_.roamingProtocol_;
125 int32_t bitMap = ApnManager::FindApnTypeByApnName(connectionParams.GetApnHolder()->GetApnType());
126 activeDataParam.dataProfile.supportedApnTypesBitmap = bitMap;
127 TELEPHONY_LOGI("Slot%{public}d: Activate PDP context (%{public}d, %{public}s, %{public}s, %{public}s, %{public}d)",
128 slotId, apn->attr_.profileId_, apn->attr_.apn_, apn->attr_.protocol_, apn->attr_.types_, bitMap);
129 int32_t result = CoreManagerInner::GetInstance().ActivatePdpContext(slotId, RadioEvent::RADIO_RIL_SETUP_DATA_CALL,
130 activeDataParam, stateMachineEventHandler_);
131 if (result != TELEPHONY_ERR_SUCCESS) {
132 TELEPHONY_LOGE("Slot%{public}d: Activate PDP context failed", slotId);
133 CellularDataHiSysEvent::WriteDataActivateFaultEvent(
134 slotId, SWITCH_ON, CellularDataErrorCode::DATA_ERROR_PDP_ACTIVATE_FAIL, "Activate PDP context failed");
135 }
136 if (stateMachineEventHandler_ == nullptr) {
137 TELEPHONY_LOGE("stateMachineEventHandler_ is nullptr");
138 return;
139 }
140 startTimeConnectTimeoutTask_ =
141 std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch())
142 .count();
143 stateMachineEventHandler_->SendEvent(
144 CellularDataEventCode::MSG_CONNECT_TIMEOUT_CHECK, connectId_, CONNECTION_DISCONNECTION_TIMEOUT);
145 }
146
FreeConnection(const DataDisconnectParams & params)147 void CellularDataStateMachine::FreeConnection(const DataDisconnectParams ¶ms)
148 {
149 const int32_t slotId = GetSlotId();
150 int32_t apnId = ApnManager::FindApnIdByApnName(params.GetApnType());
151 TELEPHONY_LOGI("Slot%{public}d: Deactivate PDP context cid:%{public}d type:%{public}s id:%{public}d",
152 slotId, cid_, params.GetApnType().c_str(), apnId);
153 DeactivateDataParam deactivateDataParam;
154 deactivateDataParam.param = connectId_;
155 deactivateDataParam.cid = cid_;
156 deactivateDataParam.reason = static_cast<int32_t>(params.GetReason());
157 int32_t result = CoreManagerInner::GetInstance().DeactivatePdpContext(slotId,
158 RadioEvent::RADIO_RIL_DEACTIVATE_DATA_CALL, deactivateDataParam, stateMachineEventHandler_);
159 if (result != TELEPHONY_ERR_SUCCESS) {
160 TELEPHONY_LOGE("Slot%{public}d: Deactivate PDP context failed", slotId);
161 CellularDataHiSysEvent::WriteDataActivateFaultEvent(
162 slotId, SWITCH_OFF, CellularDataErrorCode::DATA_ERROR_PDP_DEACTIVATE_FAIL, "Deactivate PDP context failed");
163 }
164 if (stateMachineEventHandler_ == nullptr) {
165 TELEPHONY_LOGE("stateMachineEventHandler_ is nullptr");
166 return;
167 }
168 stateMachineEventHandler_->SendEvent(
169 CellularDataEventCode::MSG_DISCONNECT_TIMEOUT_CHECK, connectId_, CONNECTION_DISCONNECTION_TIMEOUT);
170 }
171
operator ==(const CellularDataStateMachine & stateMachine) const172 bool CellularDataStateMachine::operator==(const CellularDataStateMachine &stateMachine) const
173 {
174 return this->GetCid() == stateMachine.GetCid();
175 }
176
Init()177 void CellularDataStateMachine::Init()
178 {
179 activeState_ = std::make_unique<Active>(
180 std::weak_ptr<CellularDataStateMachine>(shared_from_this()), "Active").release();
181 inActiveState_ = std::make_unique<Inactive>(
182 std::weak_ptr<CellularDataStateMachine>(shared_from_this()), "Inactive").release();
183 activatingState_ = std::make_unique<Activating>(
184 std::weak_ptr<CellularDataStateMachine>(shared_from_this()), "Activating").release();
185 disconnectingState_ = std::make_unique<Disconnecting>(
186 std::weak_ptr<CellularDataStateMachine>(shared_from_this()), "Disconnecting").release();
187 defaultState_ = std::make_unique<Default>(
188 std::weak_ptr<CellularDataStateMachine>(shared_from_this()), "Default").release();
189 netSupplierInfo_ = std::make_unique<NetSupplierInfo>().release();
190 netLinkInfo_ = std::make_unique<NetLinkInfo>().release();
191 if (activeState_ == nullptr || inActiveState_ == nullptr || activatingState_ == nullptr ||
192 disconnectingState_ == nullptr || defaultState_ == nullptr || netSupplierInfo_ == nullptr ||
193 netLinkInfo_ == nullptr) {
194 TELEPHONY_LOGE("memory allocation failed");
195 return;
196 }
197 activeState_->SetParentState(defaultState_);
198 inActiveState_->SetParentState(defaultState_);
199 activatingState_->SetParentState(defaultState_);
200 disconnectingState_->SetParentState(defaultState_);
201 StateMachine::SetOriginalState(inActiveState_);
202 StateMachine::Start();
203 }
204
SetCurrentState(const sptr<State> && state)205 void CellularDataStateMachine::SetCurrentState(const sptr<State> &&state)
206 {
207 currentState_ = std::move(state);
208 }
209
GetCurrentState() const210 sptr<State> CellularDataStateMachine::GetCurrentState() const
211 {
212 return currentState_;
213 }
214
HasMatchedIpTypeAddrs(uint8_t ipType,uint8_t ipInfoArraySize,std::vector<AddressInfo> ipInfoArray)215 bool CellularDataStateMachine::HasMatchedIpTypeAddrs(uint8_t ipType, uint8_t ipInfoArraySize,
216 std::vector<AddressInfo> ipInfoArray)
217 {
218 for (int i = 0; i < ipInfoArraySize; i++) {
219 if (ipInfoArray[i].type == ipType) {
220 return true;
221 }
222 }
223 return false;
224 }
225
GetIpType(std::vector<AddressInfo> ipInfoArray)226 std::string CellularDataStateMachine::GetIpType(std::vector<AddressInfo> ipInfoArray)
227 {
228 uint8_t ipInfoArraySize = ipInfoArray.size();
229 uint8_t ipv4Type = INetAddr::IpType::IPV4;
230 uint8_t ipv6Type = INetAddr::IpType::IPV6;
231 std::string result;
232 if (HasMatchedIpTypeAddrs(ipv4Type, ipInfoArraySize, ipInfoArray) &&
233 HasMatchedIpTypeAddrs(ipv6Type, ipInfoArraySize, ipInfoArray)) {
234 result = "IPV4V6";
235 } else if (HasMatchedIpTypeAddrs(ipv4Type, ipInfoArraySize, ipInfoArray)) {
236 result = "IPV4";
237 } else if (HasMatchedIpTypeAddrs(ipv6Type, ipInfoArraySize, ipInfoArray)) {
238 result = "IPV6";
239 } else {
240 TELEPHONY_LOGE("Ip type not match");
241 }
242 return result;
243 }
244
GetIpType()245 std::string CellularDataStateMachine::GetIpType()
246 {
247 std::lock_guard<std::mutex> guard(mtx_);
248 return ipType_;
249 }
250
GetMtuSizeFromOpCfg(int32_t & mtuSize,int32_t slotId)251 void CellularDataStateMachine::GetMtuSizeFromOpCfg(int32_t &mtuSize, int32_t slotId)
252 {
253 std::string mtuString = "";
254 int32_t mtuValue = INVALID_MTU_VALUE;
255 OperatorConfig configsForMtuSize;
256 CoreManagerInner::GetInstance().GetOperatorConfigs(slotId, configsForMtuSize);
257 if (configsForMtuSize.stringValue.find(KEY_MTU_SIZE_STRING) != configsForMtuSize.stringValue.end()) {
258 mtuString = configsForMtuSize.stringValue[KEY_MTU_SIZE_STRING];
259 }
260 std::vector<std::string> mtuArray = CellularDataUtils::Split(mtuString, ";");
261 for (std::string &ipTypeArray : mtuArray) {
262 std::vector<std::string> mtuIpTypeArray = CellularDataUtils::Split(ipTypeArray, ":");
263 if (mtuIpTypeArray.size() != VALID_VECTOR_SIZE || mtuIpTypeArray[0].empty() || mtuIpTypeArray[1].empty()) {
264 TELEPHONY_LOGE("mtu size string is invalid");
265 break;
266 }
267 std::string ipTypeString = mtuIpTypeArray[0];
268 StrToInt(mtuIpTypeArray[1], mtuValue);
269 if (mtuValue == INVALID_MTU_VALUE) {
270 TELEPHONY_LOGE("mtu values is invalid");
271 break;
272 }
273 if (!ipTypeString.empty() && ipTypeString == ipType_) {
274 mtuSize = mtuValue;
275 }
276 }
277 return;
278 }
279
SplitProxyIpAddress(const std::string & proxyIpAddress,std::string & host,uint16_t & port)280 void CellularDataStateMachine::SplitProxyIpAddress(const std::string &proxyIpAddress, std::string &host, uint16_t &port)
281 {
282 std::vector<std::string> address;
283 size_t pos = 0;
284 size_t found = 0;
285 while ((found = proxyIpAddress.find(':', pos)) != std::string::npos) {
286 address.push_back(proxyIpAddress.substr(pos, found - pos));
287 pos = found + 1;
288 }
289 address.push_back(proxyIpAddress.substr(pos));
290 if (address.size() == HOST_SIZE) {
291 host = address[0];
292 }
293 if (address.size() == HOST_PORT_SIZE) {
294 host = address[0];
295 if (!address[1].empty() && IsValidDecValue(address[1])) {
296 port = static_cast<uint16_t>(std::stoi(address[1]));
297 }
298 }
299 }
300
UpdateHttpProxy(const std::string & proxyIpAddress)301 void CellularDataStateMachine::UpdateHttpProxy(const std::string &proxyIpAddress)
302 {
303 std::string host = "";
304 uint16_t port = DEFAULT_PORT;
305 SplitProxyIpAddress(proxyIpAddress, host, port);
306 HttpProxy httpProxy = { host, port, {} };
307 netLinkInfo_->httpProxy_ = httpProxy;
308 }
309
GetNetScoreBySlotId(int32_t slotId)310 int32_t CellularDataStateMachine::GetNetScoreBySlotId(int32_t slotId)
311 {
312 int32_t score = DEFAULT_INTERNET_CONNECTION_SCORE;
313 int32_t defaultSlotId = CoreManagerInner::GetInstance().GetDefaultCellularDataSlotId();
314 if (slotId != defaultSlotId) {
315 score = OTHER_CONNECTION_SCORE;
316 }
317 return score;
318 }
319
UpdateNetworkInfo(const SetupDataCallResultInfo & dataCallInfo)320 void CellularDataStateMachine::UpdateNetworkInfo(const SetupDataCallResultInfo &dataCallInfo)
321 {
322 std::lock_guard<std::mutex> guard(mtx_);
323 int32_t slotId = GetSlotId();
324 TELEPHONY_LOGD("Slot%{private}d: dataCall, capability:%{private}" PRIu64", state:%{private}d, addr:%{private}s, "
325 "dns: %{private}s, gw: %{private}s", slotId, capability_, dataCallInfo.reason,
326 dataCallInfo.address.c_str(), dataCallInfo.dns.c_str(), dataCallInfo.gateway.c_str());
327 std::vector<AddressInfo> ipInfoArray = CellularDataUtils::ParseIpAddr(dataCallInfo.address);
328 std::vector<AddressInfo> dnsInfoArray = CellularDataUtils::ParseNormalIpAddr(dataCallInfo.dns);
329 std::vector<AddressInfo> dnsSecArray = CellularDataUtils::ParseNormalIpAddr(dataCallInfo.dnsSec);
330 dnsInfoArray.insert(dnsInfoArray.end(), dnsSecArray.begin(), dnsSecArray.end());
331 std::vector<AddressInfo> routeInfoArray = CellularDataUtils::ParseNormalIpAddr(dataCallInfo.gateway);
332 if (ipInfoArray.empty() || dnsInfoArray.empty() || routeInfoArray.empty()) {
333 TELEPHONY_LOGE("Verifying network Information(ipInfoArray or dnsInfoArray or routeInfoArray empty)");
334 }
335 if (netLinkInfo_ == nullptr || netSupplierInfo_ == nullptr) {
336 TELEPHONY_LOGE("Slot%{public}d: start update net info,but netLinkInfo or netSupplierInfo is null!", slotId);
337 return;
338 }
339 bool roamingState = false;
340 if (CoreManagerInner::GetInstance().GetPsRoamingState(slotId) > 0) {
341 roamingState = true;
342 }
343 int32_t mtuSize = (dataCallInfo.maxTransferUnit == 0) ? DEFAULT_MTU : dataCallInfo.maxTransferUnit;
344 ipType_ = GetIpType(ipInfoArray);
345 GetMtuSizeFromOpCfg(mtuSize, slotId);
346 netLinkInfo_->ifaceName_ = dataCallInfo.netPortName;
347 netLinkInfo_->mtu_ = mtuSize;
348 netLinkInfo_->tcpBufferSizes_ = tcpBuffer_;
349 ResolveIp(ipInfoArray);
350 ResolveDns(dnsInfoArray);
351 ResolveRoute(routeInfoArray, dataCallInfo.netPortName);
352 netSupplierInfo_->isAvailable_ = (dataCallInfo.active > 0);
353 netSupplierInfo_->isRoaming_ = roamingState;
354 netSupplierInfo_->linkUpBandwidthKbps_ = upBandwidth_;
355 netSupplierInfo_->linkDownBandwidthKbps_ = downBandwidth_;
356 netSupplierInfo_->score_ = GetNetScoreBySlotId(slotId);
357 cause_ = dataCallInfo.reason;
358 CellularDataNetAgent &netAgent = CellularDataNetAgent::GetInstance();
359 int32_t supplierId = netAgent.GetSupplierId(slotId, capability_);
360 netAgent.UpdateNetSupplierInfo(supplierId, netSupplierInfo_);
361 if (netSupplierInfo_->isAvailable_) {
362 netAgent.UpdateNetLinkInfo(supplierId, netLinkInfo_);
363 }
364 UpdateReuseApnNetworkInfo(netSupplierInfo_->isAvailable_);
365 }
366
UpdateNetworkInfo()367 void CellularDataStateMachine::UpdateNetworkInfo()
368 {
369 std::lock_guard<std::mutex> guard(mtx_);
370 int32_t slotId = GetSlotId();
371 CellularDataNetAgent &netAgent = CellularDataNetAgent::GetInstance();
372 netLinkInfo_->tcpBufferSizes_ = tcpBuffer_;
373 netSupplierInfo_->linkUpBandwidthKbps_ = upBandwidth_;
374 netSupplierInfo_->linkDownBandwidthKbps_ = downBandwidth_;
375 netSupplierInfo_->score_ = GetNetScoreBySlotId(slotId);
376 int32_t supplierId = netAgent.GetSupplierId(slotId, capability_);
377 netAgent.UpdateNetSupplierInfo(supplierId, netSupplierInfo_);
378 if (netSupplierInfo_->isAvailable_) {
379 netAgent.UpdateNetLinkInfo(supplierId, netLinkInfo_);
380 }
381 UpdateReuseApnNetworkInfo(netSupplierInfo_->isAvailable_);
382 }
383
UpdateReuseApnNetworkInfo(bool isAvailable)384 void CellularDataStateMachine::UpdateReuseApnNetworkInfo(bool isAvailable)
385 {
386 if (reuseApnCap_ == NetManagerStandard::NetCap::NET_CAPABILITY_END) {
387 return;
388 }
389 TELEPHONY_LOGI("UpdateReuseApnNetworkInfo: cap[%{public}d], avail[%{public}d]", static_cast<int32_t>(reuseApnCap_),
390 isAvailable);
391 std::lock_guard<std::mutex> guard(mtx_);
392 int32_t slotId = GetSlotId();
393 CellularDataNetAgent &netAgent = CellularDataNetAgent::GetInstance();
394 bool oldIsAvailable = netSupplierInfo_->isAvailable_;
395 netSupplierInfo_->isAvailable_ = isAvailable;
396 netLinkInfo_->tcpBufferSizes_ = tcpBuffer_;
397 netSupplierInfo_->linkUpBandwidthKbps_ = upBandwidth_;
398 netSupplierInfo_->linkDownBandwidthKbps_ = downBandwidth_;
399 int32_t supplierId = netAgent.GetSupplierId(slotId, reuseApnCap_);
400 netAgent.UpdateNetSupplierInfo(supplierId, netSupplierInfo_);
401 if (isAvailable) {
402 netAgent.UpdateNetLinkInfo(supplierId, netLinkInfo_);
403 }
404 netSupplierInfo_->isAvailable_ = oldIsAvailable;
405 }
406
ResolveIp(std::vector<AddressInfo> & ipInfoArray)407 void CellularDataStateMachine::ResolveIp(std::vector<AddressInfo> &ipInfoArray)
408 {
409 TELEPHONY_LOGD("Resolve Ip ifaceName_: %{private}s, domain_: %{private}s, mtu_: %{private}d, isAvailable_:"
410 " %{private}d, isRoaming_:%{private}d", netLinkInfo_->ifaceName_.c_str(),
411 netLinkInfo_->domain_.c_str(), netLinkInfo_->mtu_,
412 netSupplierInfo_->isAvailable_, netSupplierInfo_->isRoaming_);
413 netLinkInfo_->netAddrList_.clear();
414 for (AddressInfo ipInfo : ipInfoArray) {
415 INetAddr netAddr;
416 netAddr.address_ = ipInfo.ip;
417 netAddr.family_ = ipInfo.type;
418 netAddr.type_ = ipInfo.type;
419 netAddr.hostName_ = DEFAULT_HOSTNAME;
420 netAddr.netMask_ = ipInfo.netMask.length() > 0 ? ipInfo.netMask : DEFAULT_MASK;
421 netAddr.prefixlen_ = ipInfo.prefixLen;
422 netLinkInfo_->netAddrList_.push_back(netAddr);
423 }
424 }
425
ResolveDns(std::vector<AddressInfo> & dnsInfoArray)426 void CellularDataStateMachine::ResolveDns(std::vector<AddressInfo> &dnsInfoArray)
427 {
428 netLinkInfo_->dnsList_.clear();
429 for (AddressInfo dnsInfo : dnsInfoArray) {
430 INetAddr dnsAddr;
431 dnsAddr.address_ = dnsInfo.ip;
432 dnsAddr.family_ = dnsInfo.type;
433 dnsAddr.type_ = dnsInfo.type;
434 dnsAddr.hostName_ = DEFAULT_HOSTNAME;
435 dnsAddr.netMask_ = dnsInfo.netMask;
436 dnsAddr.prefixlen_ = dnsInfo.prefixLen;
437 netLinkInfo_->dnsList_.push_back(dnsAddr);
438 }
439 }
440
ResolveRoute(std::vector<AddressInfo> & routeInfoArray,const std::string & name)441 void CellularDataStateMachine::ResolveRoute(std::vector<AddressInfo> &routeInfoArray, const std::string &name)
442 {
443 netLinkInfo_->routeList_.clear();
444 for (AddressInfo routeInfo : routeInfoArray) {
445 NetManagerStandard::Route route;
446 route.iface_ = name;
447 route.gateway_.address_ = routeInfo.ip;
448 route.gateway_.family_ = routeInfo.type;
449 route.gateway_.type_ = routeInfo.type;
450 route.gateway_.hostName_ = DEFAULT_HOSTNAME;
451 route.gateway_.netMask_ = DEFAULT_MASK;
452 route.gateway_.prefixlen_ = routeInfo.prefixLen;
453 if (routeInfo.type == INetAddr::IpType::IPV4) {
454 route.destination_.address_ = ROUTED_IPV4;
455 } else {
456 route.destination_.address_ = ROUTED_IPV6;
457 }
458 route.destination_.family_ = routeInfo.type;
459 route.destination_.type_ = routeInfo.type;
460 route.destination_.hostName_ = DEFAULT_HOSTNAME;
461 route.destination_.netMask_ = DEFAULT_MASK;
462 route.destination_.prefixlen_ = 0;
463 netLinkInfo_->routeList_.push_back(route);
464 }
465 }
466
SetConnectionBandwidth(const uint32_t upBandwidth,const uint32_t downBandwidth)467 void CellularDataStateMachine::SetConnectionBandwidth(const uint32_t upBandwidth, const uint32_t downBandwidth)
468 {
469 upBandwidth_ = upBandwidth;
470 downBandwidth_ = downBandwidth;
471 }
472
SetConnectionTcpBuffer(const std::string & tcpBuffer)473 void CellularDataStateMachine::SetConnectionTcpBuffer(const std::string &tcpBuffer)
474 {
475 std::lock_guard<std::mutex> guard(mtx_);
476 tcpBuffer_ = tcpBuffer;
477 }
478
UpdateNetworkInfoIfInActive(SetupDataCallResultInfo & info)479 void CellularDataStateMachine::UpdateNetworkInfoIfInActive(SetupDataCallResultInfo &info)
480 {
481 if (cellularDataHandler_ == nullptr) {
482 TELEPHONY_LOGE("stateMachineEventHandler_ is nullptr");
483 return;
484 }
485 auto netInfo = std::make_shared<SetupDataCallResultInfo>(info);
486 netInfo->flag = apnId_;
487 cellularDataHandler_->SendEvent(CellularDataEventCode::MSG_DATA_CALL_LIST_CHANGED, netInfo);
488 }
489
SetReuseApnCap(uint64_t cap)490 void CellularDataStateMachine::SetReuseApnCap(uint64_t cap)
491 {
492 reuseApnCap_ = cap;
493 }
494
GetReuseApnCap() const495 uint64_t CellularDataStateMachine::GetReuseApnCap() const
496 {
497 return reuseApnCap_;
498 }
499 } // namespace Telephony
500 } // namespace OHOS
501