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_STATE_MACHINE_H 17 #define CELLULAR_DATA_STATE_MACHINE_H 18 19 #include <map> 20 #include <memory> 21 22 #include "apn_item.h" 23 #include "cellular_data_net_agent.h" 24 #include "data_connection_manager.h" 25 #include "data_connection_params.h" 26 #include "data_disconnect_params.h" 27 #include "network_state.h" 28 #include "state_machine.h" 29 #include "tel_event_handler.h" 30 31 namespace OHOS { 32 namespace Telephony { 33 static const uint16_t DEFAULT_PORT = 0; 34 static const size_t HOST_SIZE = 1; 35 static const size_t HOST_PORT_SIZE = 2; 36 37 class DataConnectionManager; 38 class CellularDataStateMachine : public StateMachine, 39 public std::enable_shared_from_this<CellularDataStateMachine> { 40 public: CellularDataStateMachine(sptr<DataConnectionManager> & cdConnectionManager,std::shared_ptr<TelEventHandler> && cellularDataHandler)41 CellularDataStateMachine( 42 sptr<DataConnectionManager> &cdConnectionManager, std::shared_ptr<TelEventHandler> &&cellularDataHandler) 43 : StateMachine("CellularDataStateMachine"), cdConnectionManager_(cdConnectionManager), 44 cellularDataHandler_(std::move(cellularDataHandler)), cid_(0), capability_(0), 45 rilRat_(RadioTech::RADIO_TECHNOLOGY_UNKNOWN), apnId_(0) 46 {} 47 ~CellularDataStateMachine() = default; 48 bool operator==(const CellularDataStateMachine &stateMachine) const; 49 bool IsInactiveState() const; 50 bool IsActivatingState() const; 51 bool IsDisconnectingState() const; 52 bool IsActiveState() const; 53 bool IsDefaultState() const; 54 sptr<State> GetCurrentState() const; 55 void SetCapability(uint64_t capability); 56 uint64_t GetCapability() const; 57 int32_t GetCid() const; 58 int32_t GetSlotId() const; 59 std::string GetIpType(); 60 sptr<ApnItem> GetApnItem() const; 61 void Init(); 62 void UpdateHttpProxy(const std::string &proxyIpAddress); 63 void UpdateNetworkInfo(const SetupDataCallResultInfo &dataCallInfo); 64 void UpdateNetworkInfo(); 65 void SetConnectionBandwidth(const uint32_t upBandwidth, const uint32_t downBandwidth); 66 void SetConnectionTcpBuffer(const std::string &tcpBuffer); 67 void SplitProxyIpAddress(const std::string &proxyIpAddress, std::string &host, uint16_t &port); 68 69 protected: 70 sptr<State> activeState_; 71 sptr<State> inActiveState_; 72 sptr<State> activatingState_; 73 sptr<State> disconnectingState_; 74 sptr<State> defaultState_; 75 sptr<State> currentState_; 76 sptr<DataConnectionManager> cdConnectionManager_; 77 std::shared_ptr<TelEventHandler> cellularDataHandler_; 78 sptr<NetManagerStandard::NetLinkInfo> netLinkInfo_; 79 sptr<NetManagerStandard::NetSupplierInfo> netSupplierInfo_; 80 81 private: 82 void SetCurrentState(const sptr<State> &&state); 83 void SetCid(const int32_t cid); 84 void DoConnect(const DataConnectionParams &connectionParams); 85 void FreeConnection(const DataDisconnectParams ¶ms); 86 void ResolveIp(std::vector<AddressInfo> &ipInfoArray); 87 void ResolveDns(std::vector<AddressInfo> &dnsInfoArray); 88 void ResolveRoute(std::vector<AddressInfo> &routeInfoArray, const std::string &name); 89 void GetMtuSizeFromOpCfg(int32_t &mtuSize, int32_t slotId); 90 std::string GetIpType(std::vector<AddressInfo> ipInfoArray); 91 bool HasMatchedIpTypeAddrs(uint8_t ipType, uint8_t ipInfoArraySize, std::vector<AddressInfo> ipInfoArray); 92 93 private: 94 friend class Active; 95 friend class Activating; 96 friend class Inactive; 97 friend class Default; 98 friend class Disconnecting; 99 int32_t cid_; 100 uint64_t capability_; 101 RadioTech rilRat_; 102 sptr<ApnItem> apnItem_; 103 int32_t apnId_; 104 std::mutex mtx_; 105 uint32_t upBandwidth_ = 0; 106 uint32_t downBandwidth_ = 0; 107 std::string tcpBuffer_; 108 int32_t connectId_ = 0; 109 int32_t cause_ = 0; 110 std::string ipType_ = ""; 111 }; 112 } // namespace Telephony 113 } // namespace OHOS 114 #endif // CELLULAR_DATA_STATE_MACHINE_H 115