• 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 
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(const StaServiceCallback &callback);
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 supplierId network unique identity id returned after network registration
69      * @param netLinkInfo network link data information
70      */
71     void UpdateNetLinkInfo(const std::string &ip, const std::string &mask, const std::string &gateWay,
72         const std::string &strDns, const std::string &strBakDns);
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 DhcpResult dhcp result info
87      */
88     void OnStaMachineUpdateNetLinkInfo(const std::string &strIp, const std::string &strMask,
89         const std::string &strGateWay, const std::string &strDns, const std::string &strBakDns);
90 
91     /**
92      * Add OnStaMachineUpdateNetSupplierInfo
93      *
94      * @param netSupplierInfo net Supplier Info
95      */
96     void OnStaMachineUpdateNetSupplierInfo(const sptr<NetManagerStandard::NetSupplierInfo> &netSupplierInfo);
97 
98     /**
99      * Add OnStaMachineWifiStart
100      *
101      * @param callback callback
102      */
103     void OnStaMachineWifiStart(const StaServiceCallback &callback);
104 
105     /**
106      * Add OnStaMachineNetManagerRestart
107      *
108      * @param netSupplierInfo net Supplier Info
109      * @param callback callback
110      */
111     void OnStaMachineNetManagerRestart(const sptr<NetManagerStandard::NetSupplierInfo> &netSupplierInfo,
112         const StaServiceCallback &callback);
113 public:
114     class NetConnCallback : public NetManagerStandard::NetSupplierCallbackBase {
115     public:
116         /**
117          * @Description : Construct a new NetConn object
118          *
119          */
120         explicit NetConnCallback(const StaServiceCallback &callback);
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     private:
145         StaServiceCallback staCallback;
146     };
147 
148 private:
149     uint32_t supplierId;
150 };
151 } // namespace Wifi
152 } // namespace OHOS
153 #endif // CELLULAR_DATA_NET_AGENT_H
154