• 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(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(std::string &ip, std::string &mask, std::string &gateWay,
72         std::string &strDns, 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 public:
84     class NetConnCallback : public NetManagerStandard::NetSupplierCallbackBase {
85     public:
86         /**
87          * @Description : Construct a new NetConn object
88          *
89          */
90         explicit NetConnCallback(const StaServiceCallback &callback);
91 
92         /**
93          * @Description : Destroy the NetConn object
94          *
95          */
96         ~NetConnCallback() override;
97 
98         /**
99          * @Description : Connection Management triggers the open automatic connection feature.
100          *
101          * @param ident - identity
102          * @param netCaps - Net capability to request a network
103          */
104         int32_t RequestNetwork(const std::string &ident, const std::set<NetManagerStandard::NetCap> &netCaps) override;
105         /**
106          * @Description : Connection Management triggers the close automatic connection feature.
107          *
108          * @param ident - identity
109          * @param netCaps - Net capability to request a network
110          */
111         int32_t ReleaseNetwork(const std::string &ident, const std::set<NetManagerStandard::NetCap> &netCaps) override;
112     private:
113         void LogNetCaps(const std::string &ident, const std::set<NetManagerStandard::NetCap> &netCaps) const;
114     private:
115         StaServiceCallback staCallback;
116     };
117 
118 private:
119     uint32_t supplierId;
120 };
121 } // namespace Wifi
122 } // namespace OHOS
123 #endif // CELLULAR_DATA_NET_AGENT_H
124