• 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_IMPL_H
16 #define OHOS_WIFI_DEVICE_IMPL_H
17 
18 #include <string>
19 #include <vector>
20 #include "i_wifi_device.h"
21 #include "i_wifi_device_callback.h"
22 #include "refbase.h"
23 #include "wifi_device.h"
24 #include "wifi_errcode.h"
25 #include "wifi_msg.h"
26 
27 namespace OHOS {
28 namespace Wifi {
29 class WifiDeviceImpl : public WifiDevice {
30 public:
31     WifiDeviceImpl();
32     virtual ~WifiDeviceImpl();
33     bool Init(int systemAbilityId, int instId);
34 
35     /**
36      * @Description Turn on Wi-Fi
37      *
38      * @return ErrCode - operation result
39      */
40     ErrCode EnableWifi() override;
41 
42     /**
43      * @Description Turn off Wi-Fi
44      *
45      * @return ErrCode - operation result
46      */
47     ErrCode DisableWifi() override;
48 
49     /**
50      * @Description create the Wi-Fi protect.
51      *
52      * @param protectType - WifiProtectMode object
53      * @param protectName - the protect name
54      * @return ErrCode - operation result
55      */
56     ErrCode InitWifiProtect(const WifiProtectType &protectType, const std::string &protectName) override;
57 
58     /**
59      * @Description Acquire the Wi-Fi protect mode.
60      *
61      * @param protectMode - WifiProtectMode object
62      * @param protectName - the protect name
63      * @return ErrCode - operation result
64      */
65     ErrCode GetWifiProtectRef(const WifiProtectMode &protectMode, const std::string &protectName) override;
66 
67     /**
68      * @Description Release the Wi-Fi protect mode.
69      *
70      * @param protectName - the protect name
71      * @return ErrCode - operation result
72      */
73     ErrCode PutWifiProtectRef(const std::string &protectName) override;
74 
75     /**
76      * @Description Query application whether or not has held the Wi-Fi protect.
77      *
78      * @param protectName - the protect name
79      * @param isHeld - out whether or not has held the Wi-Fi protect
80      * @return ErrCode - operation result
81      */
82     ErrCode IsHeldWifiProtectRef(const std::string &protectName, bool &isHeld) override;
83 
84 #ifndef OHOS_ARCH_LITE
85     ErrCode IsHeldWifiProtect(bool &isHeld) override;
86     /**
87      * @Description Acquire the Wi-Fi protect mode.
88      *
89      * @param protectMode - WifiProtectMode object
90      * @return ErrCode - operation result
91      */
92     ErrCode GetWifiProtect(const WifiProtectMode &protectMode) override;
93 
94     /**
95      * @Description Release the Wi-Fi protect mode.
96      *
97      * @return ErrCode - operation result
98      */
99     ErrCode PutWifiProtect() override;
100 #endif
101     /**
102      * @Description Remove the wifi candidate device config equals to input network id
103      *
104      * @param networkId - the candidate device network id
105      * @return ErrCode - operation result
106      */
107     virtual ErrCode RemoveCandidateConfig(int networkId) override;
108 
109     /**
110      * @Description Remove a specified candidate hotspot configuration.
111      *
112      * @param config - WifiDeviceConfig object
113      * @return ErrCode - operation result
114      */
115     virtual ErrCode RemoveCandidateConfig(const WifiDeviceConfig &config) override;
116 
117     /**
118      * @Description Add a wifi device configuration.
119      *
120      * @param config - WifiDeviceConfig object
121      * @param result - the device configuration's network id
122      * @param isCandidate - Whether is candidate
123      * @return ErrCode - operation result
124      */
125     ErrCode AddDeviceConfig(const WifiDeviceConfig &config, int &result, bool isCandidate) override;
126 
127     /**
128      * @Description set tx power for sar
129      *
130      * @param power - 1001 1002 1003······
131      * @return ErrCode - operation result
132      */
133     ErrCode SetWifiTxPower(int power) override;
134 
135     /**
136      * @Description Update a wifi device configuration.
137      *
138      * @param config - WifiDeviceConfig object
139      * @param result - the device configuration's network id after updated
140      * @return ErrCode - operation result
141      */
142     ErrCode UpdateDeviceConfig(const WifiDeviceConfig &config, int &result) override;
143 
144     /**
145      * @Description Remove the wifi device config equals to input network id
146      *
147      * @param networkId - want to remove device config's network id
148      * @return ErrCode - operation result
149      */
150     ErrCode RemoveDevice(int networkId) override;
151 
152     /**
153      * @Description Remove all device configs.
154      *
155      * @return ErrCode - operation result
156      */
157     ErrCode RemoveAllDevice() override;
158 
159     /**
160      * @Description Get all the device configs
161      *
162      * @param result - Get result vector of WifiDeviceConfig
163      * @param isCandidate - Whether is candidate
164      * @return ErrCode - operation result
165      */
166     ErrCode GetDeviceConfigs(std::vector<WifiDeviceConfig> &result, bool isCandidate) override;
167 
168     /**
169      * @Description Connecting to a Specified Network
170      *
171      * @param networkId - network id
172      * @param isCandidate - Whether is candidate
173      * @return ErrCode - operation result
174      */
175     ErrCode ConnectToNetwork(int networkId, bool isCandidate) override;
176 
177     /**
178      * @Description Connect To a network base WifiDeviceConfig object
179      *
180      * @param config - WifiDeviceConfig object
181      * @return ErrCode - operation result
182      */
183     ErrCode ConnectToDevice(const WifiDeviceConfig &config) override;
184 
185     /**
186      * @Description Check whether Wi-Fi is connected.
187      *
188      * @param isConnected - true: connected, false: not connected
189      * @return ErrCode - operation result
190      */
191     ErrCode IsConnected(bool &isConnected) override;
192 
193     /**
194      * @Description Disconnect
195      *
196      * @return ErrCode - operation result
197      */
198     ErrCode Disconnect(void) override;
199 
200     /**
201      * @Description Check whether Wi-Fi is active
202      *
203      * @param bActive - active / inactive
204      * @return ErrCode - operation result
205      */
206     ErrCode IsWifiActive(bool &bActive) override;
207 
208     /**
209      * @Description Check whether Wi-Fi is metered hotspot
210      *
211      * @param bMeteredHotspot - isMeteredHotspot / notMeteredHotspot
212      * @return ErrCode - operation result
213      */
214     ErrCode IsMeteredHotspot(bool &bMeteredHotspot) override;
215     /**
216      * @Description Get the Wifi State
217      *
218      * @param state - return current wifi state
219      * @return ErrCode - operation result
220      */
221     ErrCode GetWifiState(int &state) override;
222 
223     /**
224      * @Description Obtains the current Wi-Fi connection information
225      *
226      * @param info - WifiLinkedInfo object
227      * @return ErrCode - operation result
228      */
229     ErrCode GetLinkedInfo(WifiLinkedInfo &info) override;
230 
231     /**
232      * @Description Obtains the disconnected reason information
233      *
234      * @param reason - DisconnectedReason object
235      * @return ErrCode - operation result
236      */
237     ErrCode GetDisconnectedReason(DisconnectedReason &reason) override;
238 
239     /**
240      * @Description Set the Country Code
241      *
242      * @param countryCode - country code
243      * @return ErrCode - operation result
244      */
245     ErrCode SetCountryCode(const std::string &countryCode) override;
246 
247     /**
248      * @Description Obtains the country code
249      *
250      * @param countryCode - output the country code
251      * @return ErrCode - operation result
252      */
253     ErrCode GetCountryCode(std::string &countryCode) override;
254 
255     /**
256      * @Description Register callback function.
257      *
258      * @param callback - IWifiDeviceCallBack object
259      * @return ErrCode - operation result
260      */
261 #ifdef OHOS_ARCH_LITE
262     ErrCode RegisterCallBack(const std::shared_ptr<IWifiDeviceCallBack> &callback,
263         const std::vector<std::string> &event) override;
264 #else
265     ErrCode RegisterCallBack(const sptr<IWifiDeviceCallBack> &callback, const std::vector<std::string> &event) override;
266 #endif
267 
268     /**
269      * @Description Get the Signal Level object
270      *
271      * @param rssi - rssi
272      * @param band - band
273      * @param level - return the level
274      * @return ErrCode - operation result
275      */
276     ErrCode GetSignalLevel(const int &rssi, const int &band, int &level) override;
277 
278     /**
279      * @Description Get supported features
280      *
281      * @param features - return supported features
282      * @return ErrCode - operation result
283      */
284     ErrCode GetSupportedFeatures(long &features) override;
285 
286     /**
287      * @Description Check if supported input feature
288      *
289      * @param feature - input feature
290      * @param isSupported - return true if supported, false if unsupported
291      * @return ErrCode - operation result
292      */
293     ErrCode IsFeatureSupported(long feature, bool &isSupported) override;
294 
295     /**
296      * @Description Enable device config, when set attemptEnable, disable other device config
297      *
298      * @param networkId - need enable device config's network id
299      * @param attemptEnable - if set true, disable other device config
300      * @return ErrCode - operation result
301      */
302     ErrCode EnableDeviceConfig(int networkId, bool attemptEnable) override;
303 
304     /**
305      * @Description Disable Wi-Fi device configuration.
306      *
307      * @param networkId - device config's network id
308      * @return ErrCode - operation result
309      */
310     ErrCode DisableDeviceConfig(int networkId) override;
311 
312     /**
313      * @Description Obtaining ip Request Information
314      *
315      * @param info - IpInfo object
316      * @return ErrCode - operation result
317      */
318     ErrCode GetIpInfo(IpInfo &info) override;
319 
320     /**
321      * @Description Obtaining ipV6 Request Information
322      *
323      * @param info - IpInfo object
324      * @return ErrCode - operation result
325      */
326     ErrCode GetIpv6Info(IpV6Info &info) override;
327 
328     /**
329      * @Description Reconnect to the currently active network
330      *
331      * @return ErrCode - operation result
332      */
333     ErrCode ReConnect() override;
334 
335     /**
336      * @Description ReAssociate network
337      *
338      * @return ErrCode - operation result
339      */
340     ErrCode ReAssociate() override;
341 
342     /**
343      * @Description Enable WPS connection
344      *
345      * @param config - WpsConfig object
346      * @return ErrCode - operation result
347      */
348     ErrCode StartWps(const WpsConfig &config);
349 
350     /**
351      * @Description Close the WPS connection
352      *
353      * @return ErrCode - operation result
354      */
355     ErrCode CancelWps(void);
356 
357     /**
358      * @Description  Get the device MAC address.
359      *
360      * @param result - Get device mac String
361      * @return ErrCode - operation result
362      */
363     ErrCode GetDeviceMacAddress(std::string &result) override;
364 
365     /**
366      * @Description check wifi-band type is supported
367      *
368      * @param bandType - wifi band type
369      * @param supported - supported / unsupported
370      * @return ErrCode - operation result
371      */
372     ErrCode IsBandTypeSupported(int bandType, bool &supported) override;
373 
374     /**
375      * @Description get all 5g channellist
376      *
377      * @param result - get result vector of int
378      * @return ErrCode - operation result
379      */
380     ErrCode Get5GHzChannelList(std::vector<int> &result) override;
381 
382     /**
383      * @Description start portal certification
384      *
385      * @return ErrCode - operation result
386      */
387     ErrCode StartPortalCertification() override;
388 
389     /**
390      * @Description set low latency mode
391      *
392      * @param enabled - true: enable low latency, false: disable low latency
393      * @return bool - operation result
394      */
395     bool SetLowLatencyMode(bool enabled) override;
396 
397     /**
398      * @Description set frozen app
399      *
400      * @param pidList - pids of frozen app
401      * @param isFrozen - is app frozen
402      * @return ErrCode - operation result
403      */
404     ErrCode SetAppFrozen(std::set<int> pidList, bool isFrozen) override;
405 
406     /**
407      * @Description reset all frozen app
408      *
409      * @return ErrCode - operation result
410      */
411     ErrCode ResetAllFrozenApp() override;
412 
413     /**
414      * @Description  disable auto join.
415      *
416      * @param conditionName autoJoinDisabled condition.
417      * @return WifiErrorNo
418      */
419     ErrCode DisableAutoJoin(const std::string &conditionName) override;
420 
421     /**
422      * @Description  enable auto join.
423      *
424      * @param conditionName autoJoinDisabled condition.
425      * @return WifiErrorNo
426      */
427     ErrCode EnableAutoJoin(const std::string &conditionName) override;
428 
429     /**
430      * @Description  register auto join condition.
431      *
432      * @param conditionName the name of condition.
433      * @param autoJoinCondition condition.
434      * @return WifiErrorNo
435      */
436     ErrCode RegisterAutoJoinCondition(const std::string &conditionName,
437                                       const std::function<bool()> &autoJoinCondition) override;
438 
439     /**
440      * @Description  deregister auto join condition.
441      *
442      * @param conditionName the name of condition.
443      * @return WifiErrorNo
444      */
445     ErrCode DeregisterAutoJoinCondition(const std::string &conditionName) override;
446 
447     /**
448      * @Description  register external filter builder.
449      *
450      * @param filterTag filterTag which define where the filter should be inserted.
451      * @param filterName the name of the filter to build.
452      * @param filterBuilder filter builder.
453      * @return WifiErrorNo
454      */
455     ErrCode RegisterFilterBuilder(const FilterTag &filterTag, const std::string &filterName,
456                                   const FilterBuilder &filterBuilder) override;
457 
458     /**
459      * @Description  deregister external filter builder.
460      *
461      * @param filterTag filterTag which define where the filter should be inserted.
462      * @param filterName the name of the filter to build.
463      * @return WifiErrorNo
464      */
465     ErrCode DeregisterFilterBuilder(const FilterTag &filterTag, const std::string &filterName) override;
466 
467     /**
468      * Register the common builder function
469      *
470      * @param TagType scoreTag which define where the score or filter should be inserted.
471      * @param tagName the score or filter name.
472      * @param CommonBuilder CommonBuilder function.
473      */
474     ErrCode RegisterCommonBuilder(const TagType &tagType, const std::string &tagName,
475                                const CommonBuilder &commonBuilder) override;
476     /**
477      * Deregister the common builder function
478      *
479      * @param TagType TagType which define where the score or filter should be inserted.
480      * @param tagName the score or filte name.
481      */
482     ErrCode DeregisterCommonBuilder(const TagType &tagType, const std::string &tagName) override;
483 
484     /**
485      * @Description Check whether service is died.
486      *
487      * @return bool - true: service is died, false: service is not died.
488      */
489     bool IsRemoteDied(void);
490 
491     /**
492      * @Description get last Change devicecConfig
493      *
494      * @return ErrCode - operation result
495      */
496     ErrCode GetChangeDeviceConfig(ConfigChange &value, WifiDeviceConfig &config) override;
497 
498     /**
499      * @Description reset factiry
500      *
501      * @return ErrCode - operation result
502      */
503     ErrCode FactoryReset() override;
504 
505     /**
506      * @Description  limit speed
507      *
508      * @param controlId 1: game 2: stream 3:temp 4: cellular speed limit
509      * @param limitMode speed limit mode, ranges 1 to 9
510      * @return WifiErrorNo
511      */
512     ErrCode LimitSpeed(const int controlId, const int limitMode) override;
513 
514     /**
515      * @Description set low tx power
516      *
517      * @return ErrCode - operation result
518      */
519     ErrCode SetLowTxPower(const WifiLowPowerParam wifiLowPowerParam) override;
520 
521     /**
522      * @Description hilink connect
523      *
524      * @return ErrCode - hilink connect result
525      */
526     ErrCode EnableHiLinkHandshake(bool uiFlag, std::string &bssid, WifiDeviceConfig &deviceConfig) override;
527 
528     /**
529      * @Description Enable semi-Wifi
530      *
531      * @return ErrCode - operation result
532      */
533     ErrCode EnableSemiWifi() override;
534 
535     /**
536      * @Description Obtains the wifi detail state
537      *
538      * @param state - WifiDetailState object
539      * @return ErrCode - operation result
540      */
541     ErrCode GetWifiDetailState(WifiDetailState &state) override;
542 
543     /**
544      * @Description set satellite state
545      * @param state 3009:satellite start 3010:satellite stop 3011:satellite check
546      *
547      * @return ErrCode - operation result
548      */
549     virtual ErrCode SetSatelliteState(const int state) override;
550 
551     /**
552      * @Description roam to target bssid
553      *
554      * @param networkId - target networkId
555      * @param bssid - target bssid
556      * @param isCandidate - Whether is candidate
557      * @return ErrCode - operation result
558      */
559     ErrCode StartRoamToNetwork(const int networkId, const std::string bssid, const bool isCandidate) override;
560 
561     /**
562      * @Description connect to user select ssid and bssid network
563      *
564      * @param networkId - target networkId
565      * @param bssid - target bssid
566      * @param isCandidate - Whether is candidate
567      * @return ErrCode - operation result
568      */
569     ErrCode StartConnectToUserSelectNetwork(int networkId, std::string bssid, bool isCandidate) override;
570 
571     /**
572      * @Description Get single device config
573      *
574      * @param networkId - the network id of the device config
575      * @param config - Get result vector of WifiDeviceConfig
576      * @return ErrCode - operation result
577      */
578     ErrCode GetDeviceConfig(const int &networkId, WifiDeviceConfig &config) override;
579 
580     /**
581      * @Description set data packet identification mark rule
582      *
583      * @param uid - target app uid
584      * @param protocol - target protocol type
585      * @param enable - enable/disable dpi mark
586      */
587     ErrCode SetDpiMarkRule(const std::string &ifaceName, int uid, int protocol, int enable) override;
588 private:
589     bool GetWifiDeviceProxy();
590     std::atomic<int> systemAbilityId_;
591     int instId_;
592     std::mutex mutex_;
593 #ifdef OHOS_ARCH_LITE
594     IWifiDevice *client_;
595 #else
596     sptr<IWifiDevice> client_;
597 #endif
598 };
599 }  // namespace Wifi
600 }  // namespace OHOS
601 #endif
602