• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021-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 #ifndef OHOS_WIFI_DEVICE_PROXY_H
16 #define OHOS_WIFI_DEVICE_PROXY_H
17 
18 #include "i_wifi_device.h"
19 #include "iremote_proxy.h"
20 #include "wifi_errcode.h"
21 #include "wifi_msg.h"
22 
23 namespace OHOS {
24 namespace Wifi {
25 class WifiDeviceProxy : public IRemoteProxy<IWifiDevice>, public IRemoteObject::DeathRecipient {
26 public:
27     explicit WifiDeviceProxy(const sptr<IRemoteObject> &impl);
28     ~WifiDeviceProxy();
29 
30     /**
31      * @Description Turn on Wi-Fi
32      *
33      * @return ErrCode - operation result
34      */
35     ErrCode EnableWifi() override;
36 
37     /**
38      * @Description Turn off Wi-Fi
39      *
40      * @return ErrCode - operation result
41      */
42     ErrCode DisableWifi() override;
43 
44     /**
45      * @Description create the Wi-Fi protect.
46      *
47      * @param protectType - WifiProtectMode object
48      * @param protectName - the protect name
49      * @return ErrCode - operation result
50      */
51     ErrCode InitWifiProtect(const WifiProtectType &protectType, const std::string &protectName) override;
52 
53     /**
54      * @Description Acquire the Wi-Fi protect mode.
55      *
56      * @param protectMode - WifiProtectMode object
57      * @param protectName - the protect name
58      * @return ErrCode - operation result
59      */
60     ErrCode GetWifiProtectRef(const WifiProtectMode &protectMode, const std::string &protectName) override;
61 
62     /**
63      * @Description Release the Wi-Fi protect mode.
64      *
65      * @param protectName - the protect name
66      * @return ErrCode - operation result
67      */
68     ErrCode PutWifiProtectRef(const std::string &protectName) override;
69 
70     /**
71      * @Description Add a wifi device configuration.
72      *
73      * @param config - WifiDeviceConfig object
74      * @param result - the device configuration's network id
75      * @return ErrCode - operation result
76      */
77     ErrCode AddDeviceConfig(const WifiDeviceConfig &config, int &result) override;
78 
79     /**
80      * @Description Update a wifi device configuration.
81      *
82      * @param config - WifiDeviceConfig object
83      * @param result - the device configuration's network id after updated
84      * @return ErrCode - operation result
85      */
86     ErrCode UpdateDeviceConfig(const WifiDeviceConfig &config, int &result) override;
87 
88     /**
89      * @Description Remove the wifi device config equals to input network id
90      *
91      * @param networkId - want to remove device config's network id
92      * @return ErrCode - operation result
93      */
94     ErrCode RemoveDevice(int networkId) override;
95 
96     /**
97      * @Description Delete all device configs.
98      *
99      * @return ErrCode - operation result
100      */
101     ErrCode RemoveAllDevice() override;
102 
103     /**
104      * @Description Get all the device configs
105      *
106      * @param result - Get result vector of WifiDeviceConfig
107      * @return ErrCode - operation result
108      */
109     ErrCode GetDeviceConfigs(std::vector<WifiDeviceConfig> &result) override;
110 
111     /**
112      * @Description Enable device config, when set attemptEnable, disable other device config
113      *
114      * @param networkId - need enable device config's network id
115      * @param attemptEnable - if set true, disable other device config
116      * @return ErrCode - operation result
117      */
118     ErrCode EnableDeviceConfig(int networkId, bool attemptEnable) override;
119 
120     /**
121      * @Description Disable Wi-Fi device configuration.
122      *
123      * @param networkId - device config's network id
124      * @return ErrCode - operation result
125      */
126     ErrCode DisableDeviceConfig(int networkId) override;
127 
128     /**
129      * @Description Connecting to a Specified Network
130      *
131      * @param networkId - network id
132      * @return ErrCode - operation result
133      */
134     ErrCode ConnectToNetwork(int networkId) override;
135 
136     /**
137      * @Description Connect To a network base WifiDeviceConfig object
138      *
139      * @param config - WifiDeviceConfig object
140      * @return ErrCode - operation result
141      */
142     ErrCode ConnectToDevice(const WifiDeviceConfig &config) override;
143 
144     /**
145      * @Description Check whether Wi-Fi is connected.
146      *
147      * @return bool - true: connected, false: not connected
148      */
149     bool IsConnected() override;
150 
151     /**
152      * @Description Reconnect to the currently active network
153      *
154      * @return ErrCode - operation result
155      */
156     ErrCode ReConnect() override;
157 
158     /**
159      * @Description ReAssociate network
160      *
161      * @return ErrCode - operation result
162      */
163     ErrCode ReAssociate(void) override;
164 
165     /**
166      * @Description Disconnect
167      *
168      * @return ErrCode - operation result
169      */
170     ErrCode Disconnect(void) override;
171 
172     /**
173      * @Description Enable WPS connection
174      *
175      * @param config - WpsConfig object
176      * @return ErrCode - operation result
177      */
178     ErrCode StartWps(const WpsConfig &config) override;
179 
180     /**
181      * @Description Close the WPS connection
182      *
183      * @return ErrCode - operation result
184      */
185     ErrCode CancelWps(void) override;
186 
187     /**
188      * @Description Check whether Wi-Fi is active
189      *
190      * @param bActive - active / inactive
191      * @return ErrCode - operation result
192      */
193     ErrCode IsWifiActive(bool &bActive) override;
194 
195     /**
196      * @Description Get the Wifi State
197      *
198      * @param state - return current wifi state
199      * @return ErrCode - operation result
200      */
201     ErrCode GetWifiState(int &state) override;
202 
203     /**
204      * @Description Obtains the current Wi-Fi connection information
205      *
206      * @param info - WifiLinkedInfo object
207      * @return ErrCode - operation result
208      */
209     ErrCode GetLinkedInfo(WifiLinkedInfo &info) override;
210 
211     /**
212      * @Description Obtaining DHCP Request Information
213      *
214      * @param info - IpInfo object
215      * @return ErrCode - operation result
216      */
217     ErrCode GetIpInfo(IpInfo &info) override;
218 
219     /**
220      * @Description Set the Country Code
221      *
222      * @param countryCode - country code
223      * @return ErrCode - operation result
224      */
225     ErrCode SetCountryCode(const std::string &countryCode) override;
226 
227     /**
228      * @Description Obtains the country code
229      *
230      * @param countryCode - output the country code
231      * @return ErrCode - operation result
232      */
233     ErrCode GetCountryCode(std::string &countryCode) override;
234 
235     /**
236      * @Description Register callback function.
237      *
238      * @param callback - IWifiDeviceCallBack object
239      * @return ErrCode - operation result
240      */
241     ErrCode RegisterCallBack(const sptr<IWifiDeviceCallBack> &callback) override;
242 
243     /**
244      * @Description Get the Signal Level object
245      *
246      * @param rssi - rssi
247      * @param band - band
248      * @param level - return the level
249      * @return ErrCode - operation result
250      */
251     ErrCode GetSignalLevel(const int &rssi, const int &band, int &level) override;
252 
253     /**
254      * @Description Get supported features
255      *
256      * @param features - return supported features
257      * @return ErrCode - operation result
258      */
259     ErrCode GetSupportedFeatures(long &features) override;
260 
261     /**
262      * @Description  Get the device MAC address
263      *
264      * @param result - Get device mac String
265      * @return ErrCode - operation result
266      */
267     ErrCode GetDeviceMacAddress(std::string &result) override;
268 
269     /**
270      * @Description set low latency mode
271      *
272      * @param enabled - true: enable low latency, false: disable low latency
273      * @return bool - operate result
274      */
275     bool SetLowLatencyMode(bool enabled) override;
276 
277     /**
278     * @Description Handle remote object died event.
279     * @param remoteObject remote object.
280     */
281     void OnRemoteDied(const wptr<IRemoteObject> &remoteObject) override;
282 
283 private:
284     void WriteIpAddress(MessageParcel &data, const WifiIpAddress &address);
285     void ReadIpAddress(MessageParcel &reply, WifiIpAddress &address);
286     void ReadLinkedInfo(MessageParcel &reply, WifiLinkedInfo &info);
287     void WriteDeviceConfig(const WifiDeviceConfig &config, MessageParcel &data);
288     void ParseDeviceConfigs(MessageParcel &reply, std::vector<WifiDeviceConfig> &result);
289     static BrokerDelegator<WifiDeviceProxy> g_delegator;
290 
291     bool mRemoteDied;
292 };
293 }  // namespace Wifi
294 }  // namespace OHOS
295 #endif
296