• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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 WIFI_NET_AGENT_H
17 #define WIFI_NET_AGENT_H
18 
19 #include <memory>
20 #include <string>
21 #include <singleton.h>
22 #include <utility>
23 #include <vector>
24 
25 #include "i_net_conn_service.h"
26 #include "net_all_capabilities.h"
27 #include "net_supplier_callback_base.h"
28 #include "wifi_net_conn_event_handler.h"
29 #include "wifi_internal_msg.h"
30 #include "sta_service_callback.h"
31 #include "wifi_log.h"
32 
33 namespace OHOS {
34 namespace Wifi {
35 class WifiNetAgent : public DelayedRefSingleton<WifiNetAgent> {
36     DECLARE_DELAYED_REF_SINGLETON(WifiNetAgent);
37 
38 public:
39     /**
40      * Register the network information with the network management module
41      *
42      * @return true if register success else return false;
43      */
44     bool RegisterNetSupplier();
45     /**
46      * Register the network callback with the network management module
47      *
48      * @return true if register success else return false;
49      */
50     bool RegisterNetSupplierCallback();
51 
52     /**
53      * Cancel the registration information to the network management
54      */
55     void UnregisterNetSupplier();
56 
57     /**
58      * Update network information
59      *
60      * @param supplierId network unique identity id returned after network registration
61      * @param netSupplierInfo network data information
62      */
63     void UpdateNetSupplierInfo(const sptr<NetManagerStandard::NetSupplierInfo> &netSupplierInfo);
64 
65     /**
66      * Update link information
67      *
68      * @param wifiIpInfo wifi network link data information
69      * @param wifiIpV6Info wifi network link IPV6 data information
70      * @param wifiProxyConfig wifi network link proxy information
71      */
72     void UpdateNetLinkInfo(IpInfo &wifiIpInfo, IpV6Info &wifiIpV6Info, WifiProxyConfig &wifiProxyConfig);
73 
74     /**
75      * Add route
76      *
77      * @param interface interface name
78      * @param ipAddress IP address
79      * @param prefixLength prefix length
80      */
81     bool AddRoute(const std::string interface, const std::string ipAddress, int prefixLength);
82 
83     /**
84      * Add OnStaMachineUpdateNetLinkInfo
85      *
86      * @param wifiIpInfo wifi network link data information
87      * @param wifiIpV6Info wifi ipv6 network link data information
88      * @param wifiProxyConfig wifi network link proxy information
89      */
90     void OnStaMachineUpdateNetLinkInfo(IpInfo &wifiIpInfo, IpV6Info &wifiIpV6Info, WifiProxyConfig &wifiProxyConfig);
91 
92     /**
93      * Add OnStaMachineUpdateNetSupplierInfo
94      *
95      * @param netSupplierInfo net Supplier Info
96      */
97     void OnStaMachineUpdateNetSupplierInfo(const sptr<NetManagerStandard::NetSupplierInfo> &netSupplierInfo);
98 
99     /**
100      * Add OnStaMachineWifiStart
101      *
102      * @param
103      */
104     void OnStaMachineWifiStart();
105 
106     /**
107      * Add OnStaMachineNetManagerRestart
108      *
109      * @param netSupplierInfo net Supplier Info
110      */
111     void OnStaMachineNetManagerRestart(const sptr<NetManagerStandard::NetSupplierInfo> &netSupplierInfo);
112 
113 public:
114     class NetConnCallback : public NetManagerStandard::NetSupplierCallbackBase {
115     public:
116         /**
117          * @Description : Construct a new NetConn object
118          *
119          */
120         explicit NetConnCallback();
121 
122         /**
123          * @Description : Destroy the NetConn object
124          *
125          */
126         ~NetConnCallback() override;
127 
128         /**
129          * @Description : Connection Management triggers the open automatic connection feature.
130          *
131          * @param ident - identity
132          * @param netCaps - Net capability to request a network
133          */
134         int32_t RequestNetwork(const std::string &ident, const std::set<NetManagerStandard::NetCap> &netCaps) override;
135         /**
136          * @Description : Connection Management triggers the close automatic connection feature.
137          *
138          * @param ident - identity
139          * @param netCaps - Net capability to request a network
140          */
141         int32_t ReleaseNetwork(const std::string &ident, const std::set<NetManagerStandard::NetCap> &netCaps) override;
142     private:
143         void LogNetCaps(const std::string &ident, const std::set<NetManagerStandard::NetCap> &netCaps) const;
144     };
145 private:
146     void CreateNetLinkInfo(sptr<NetManagerStandard::NetLinkInfo> &netLinkInfo, IpInfo &wifiIpInfo,
147         IpV6Info &wifiIpV6Info, WifiProxyConfig &wifiProxyConfig);
148 
149     void SetNetLinkIPInfo(sptr<NetManagerStandard::NetLinkInfo> &netLinkInfo, IpInfo &wifiIpInfo,
150         IpV6Info &wifiIpV6Info);
151 
152     void SetNetLinkRouteInfo(sptr<NetManagerStandard::NetLinkInfo> &netLinkInfo, IpInfo &wifiIpInfo,
153         IpV6Info &wifiIpV6Info);
154 
155     void SetNetLinkLocalRouteInfo(sptr<NetManagerStandard::NetLinkInfo> &netLinkInfo, IpInfo &wifiIpInfo,
156         IpV6Info &wifiIpV6Info);
157 
158     void SetNetLinkDnsInfo(sptr<NetManagerStandard::NetLinkInfo> &netLinkInfo, IpInfo &wifiIpInfo,
159         IpV6Info &wifiIpV6Info);
160 private:
161     uint32_t supplierId;
162     std::shared_ptr<AppExecFwk::EventRunner> netConnEventRunner_ = nullptr;
163     std::shared_ptr<WifiNetConnEventHandler> netConnEventHandler_ = nullptr;
164 };
165 } // namespace Wifi
166 } // namespace OHOS
167 #endif // CELLULAR_DATA_NET_AGENT_H
168