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