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 sptr<State> GetCurrentState() const; 51 void SetCapability(uint64_t capability); 52 uint64_t GetCapability() const; 53 int32_t GetCid() const; 54 int32_t GetSlotId() const; 55 std::string GetIpType(); 56 sptr<ApnItem> GetApnItem() const; 57 void Init(); 58 void UpdateHttpProxy(const std::string &proxyIpAddress); 59 void UpdateNetworkInfo(const SetupDataCallResultInfo &dataCallInfo); 60 void UpdateNetworkInfo(); 61 void SetConnectionBandwidth(const uint32_t upBandwidth, const uint32_t downBandwidth); 62 void SetConnectionTcpBuffer(const std::string &tcpBuffer); 63 void SplitProxyIpAddress(const std::string &proxyIpAddress, std::string &host, uint16_t &port); 64 65 protected: 66 sptr<State> activeState_; 67 sptr<State> inActiveState_; 68 sptr<State> activatingState_; 69 sptr<State> disconnectingState_; 70 sptr<State> defaultState_; 71 sptr<State> currentState_; 72 sptr<DataConnectionManager> cdConnectionManager_; 73 std::shared_ptr<TelEventHandler> cellularDataHandler_; 74 sptr<NetManagerStandard::NetLinkInfo> netLinkInfo_; 75 sptr<NetManagerStandard::NetSupplierInfo> netSupplierInfo_; 76 77 private: 78 void SetCurrentState(const sptr<State> &&state); 79 void SetCid(const int32_t cid); 80 void DoConnect(const DataConnectionParams &connectionParams); 81 void FreeConnection(const DataDisconnectParams ¶ms); 82 void ResolveIp(std::vector<AddressInfo> &ipInfoArray); 83 void ResolveDns(std::vector<AddressInfo> &dnsInfoArray); 84 void ResolveRoute(std::vector<AddressInfo> &routeInfoArray, const std::string &name); 85 void GetMtuSizeFromOpCfg(int32_t &mtuSize, int32_t slotId); 86 std::string GetIpType(std::vector<AddressInfo> ipInfoArray); 87 bool HasMatchedIpTypeAddrs(uint8_t ipType, uint8_t ipInfoArraySize, std::vector<AddressInfo> ipInfoArray); 88 89 private: 90 friend class Active; 91 friend class Activating; 92 friend class Inactive; 93 friend class Default; 94 friend class Disconnecting; 95 int32_t cid_; 96 uint64_t capability_; 97 RadioTech rilRat_; 98 sptr<ApnItem> apnItem_; 99 int32_t apnId_; 100 std::mutex mtx_; 101 uint32_t upBandwidth_ = 0; 102 uint32_t downBandwidth_ = 0; 103 std::string tcpBuffer_; 104 int32_t connectId_ = 0; 105 int32_t cause_ = 0; 106 std::string ipType_ = ""; 107 }; 108 } // namespace Telephony 109 } // namespace OHOS 110 #endif // CELLULAR_DATA_STATE_MACHINE_H 111