• 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      * @param power - 1001 1002 1003······
130      * @return ErrCode - operation result
131      */
132     ErrCode SetWifiTxPower(int power) override;
133 
134     /**
135      * @Description Update a wifi device configuration.
136      *
137      * @param config - WifiDeviceConfig object
138      * @param result - the device configuration's network id after updated
139      * @return ErrCode - operation result
140      */
141     ErrCode UpdateDeviceConfig(const WifiDeviceConfig &config, int &result) override;
142 
143     /**
144      * @Description Remove the wifi device config equals to input network id
145      *
146      * @param networkId - want to remove device config's network id
147      * @return ErrCode - operation result
148      */
149     ErrCode RemoveDevice(int networkId) override;
150 
151     /**
152      * @Description Remove all device configs.
153      *
154      * @return ErrCode - operation result
155      */
156     ErrCode RemoveAllDevice() override;
157 
158     /**
159      * @Description Get all the device configs
160      *
161      * @param result - Get result vector of WifiDeviceConfig
162      * @param isCandidate - Whether is candidate
163      * @return ErrCode - operation result
164      */
165     ErrCode GetDeviceConfigs(std::vector<WifiDeviceConfig> &result, bool isCandidate) override;
166 
167     /**
168      * @Description Connecting to a Specified Network
169      *
170      * @param networkId - network id
171      * @param isCandidate - Whether is candidate
172      * @return ErrCode - operation result
173      */
174     ErrCode ConnectToNetwork(int networkId, bool isCandidate) override;
175 
176     /**
177      * @Description Connect To a network base WifiDeviceConfig object
178      *
179      * @param config - WifiDeviceConfig object
180      * @return ErrCode - operation result
181      */
182     ErrCode ConnectToDevice(const WifiDeviceConfig &config) override;
183 
184     /**
185      * @Description Check whether Wi-Fi is connected.
186      *
187      * @param isConnected - true: connected, false: not connected
188      * @return ErrCode - operation result
189      */
190     ErrCode IsConnected(bool &isConnected) override;
191 
192     /**
193      * @Description Disconnect
194      *
195      * @return ErrCode - operation result
196      */
197     ErrCode Disconnect(void) override;
198 
199     /**
200      * @Description Check whether Wi-Fi is active
201      *
202      * @param bActive - active / inactive
203      * @return ErrCode - operation result
204      */
205     ErrCode IsWifiActive(bool &bActive) override;
206 
207     /**
208      * @Description Check whether Wi-Fi is metered hotspot
209      *
210      * @param bMeteredHotspot - isMeteredHotspot / notMeteredHotspot
211      * @return ErrCode - operation result
212      */
213     ErrCode IsMeteredHotspot(bool &bMeteredHotspot) override;
214     /**
215      * @Description Get the Wifi State
216      *
217      * @param state - return current wifi state
218      * @return ErrCode - operation result
219      */
220     ErrCode GetWifiState(int &state) override;
221 
222     /**
223      * @Description Obtains the current Wi-Fi connection information
224      *
225      * @param info - WifiLinkedInfo object
226      * @return ErrCode - operation result
227      */
228     ErrCode GetLinkedInfo(WifiLinkedInfo &info) override;
229 
230     ErrCode GetSignalPollInfoArray(std::vector<WifiSignalPollInfo> &wifiSignalPollInfos, int length) override;
231 
232     /**
233      * @Description Obtains the disconnected reason information
234      *
235      * @param reason - DisconnectedReason object
236      * @return ErrCode - operation result
237      */
238     ErrCode GetDisconnectedReason(DisconnectedReason &reason) override;
239 
240     /**
241      * @Description Set the Country Code
242      *
243      * @param countryCode - country code
244      * @return ErrCode - operation result
245      */
246     ErrCode SetCountryCode(const std::string &countryCode) override;
247 
248     /**
249      * @Description Obtains the country code
250      *
251      * @param countryCode - output the country code
252      * @return ErrCode - operation result
253      */
254     ErrCode GetCountryCode(std::string &countryCode) override;
255 
256     /**
257      * @Description Register callback function.
258      *
259      * @param callback - IWifiDeviceCallBack object
260      * @return ErrCode - operation result
261      */
262 #ifdef OHOS_ARCH_LITE
263     ErrCode RegisterCallBack(const std::shared_ptr<IWifiDeviceCallBack> &callback,
264         const std::vector<std::string> &event) override;
265 #else
266     ErrCode RegisterCallBack(const sptr<IWifiDeviceCallBack> &callback, const std::vector<std::string> &event) override;
267 #endif
268 
269     /**
270      * @Description Get the Signal Level object
271      *
272      * @param rssi - rssi
273      * @param band - band
274      * @param level - return the level
275      * @return ErrCode - operation result
276      */
277     ErrCode GetSignalLevel(const int &rssi, const int &band, int &level) override;
278 
279     /**
280      * @Description Get supported features
281      *
282      * @param features - return supported features
283      * @return ErrCode - operation result
284      */
285     ErrCode GetSupportedFeatures(long &features) override;
286 
287     /**
288      * @Description Check if supported input feature
289      *
290      * @param feature - input feature
291      * @param isSupported - return true if supported, false if unsupported
292      * @return ErrCode - operation result
293      */
294     ErrCode IsFeatureSupported(long feature, bool &isSupported) override;
295 
296     /**
297      * @Description Enable device config, when set attemptEnable, disable other device config
298      *
299      * @param networkId - need enable device config's network id
300      * @param attemptEnable - if set true, disable other device config
301      * @return ErrCode - operation result
302      */
303     ErrCode EnableDeviceConfig(int networkId, bool attemptEnable) override;
304 
305     /**
306      * @Description Disable Wi-Fi device configuration.
307      *
308      * @param networkId - device config's network id
309      * @return ErrCode - operation result
310      */
311     ErrCode DisableDeviceConfig(int networkId) override;
312 
313     /**
314      * @Description Set whether to allow automatic connect by networkid.
315      *
316      * @param networkId - Identifies the network to be set. The value of networkId cannot be less thann 0.
317      * @param isAllowed - Identifies whether allow auto connect or not.
318      * @return ErrCode - operation result
319      */
320     ErrCode AllowAutoConnect(int32_t networkId, bool isAllowed) override;
321 
322     /**
323      * @Description Obtaining ip Request Information
324      *
325      * @param info - IpInfo object
326      * @return ErrCode - operation result
327      */
328     ErrCode GetIpInfo(IpInfo &info) override;
329 
330     /**
331      * @Description Obtaining ipV6 Request Information
332      *
333      * @param info - IpInfo object
334      * @return ErrCode - operation result
335      */
336     ErrCode GetIpv6Info(IpV6Info &info) override;
337 
338     /**
339      * @Description Reconnect to the currently active network
340      *
341      * @return ErrCode - operation result
342      */
343     ErrCode ReConnect() override;
344 
345     /**
346      * @Description ReAssociate network
347      *
348      * @return ErrCode - operation result
349      */
350     ErrCode ReAssociate() override;
351 
352     /**
353      * @Description Enable WPS connection
354      *
355      * @param config - WpsConfig object
356      * @return ErrCode - operation result
357      */
358     ErrCode StartWps(const WpsConfig &config);
359 
360     /**
361      * @Description Close the WPS connection
362      *
363      * @return ErrCode - operation result
364      */
365     ErrCode CancelWps(void);
366 
367     /**
368      * @Description  Get the device MAC address.
369      *
370      * @param result - Get device mac String
371      * @return ErrCode - operation result
372      */
373     ErrCode GetDeviceMacAddress(std::string &result) override;
374 
375     /**
376      * @Description check wifi-band type is supported
377      *
378      * @param bandType - wifi band type
379      * @param supported - supported / unsupported
380      * @return ErrCode - operation result
381      */
382     ErrCode IsBandTypeSupported(int bandType, bool &supported) override;
383 
384     /**
385      * @Description get all 5g channellist
386      *
387      * @param result - get result vector of int
388      * @return ErrCode - operation result
389      */
390     ErrCode Get5GHzChannelList(std::vector<int> &result) override;
391 
392     /**
393      * @Description start portal certification
394      *
395      * @return ErrCode - operation result
396      */
397     ErrCode StartPortalCertification() override;
398 
399     /**
400      * @Description set low latency mode
401      *
402      * @param enabled - true: enable low latency, false: disable low latency
403      * @return bool - operation result
404      */
405     bool SetLowLatencyMode(bool enabled) override;
406 
407     /**
408      * @Description set frozen app
409      *
410      * @param pidList - pids of frozen app
411      * @param isFrozen - is app frozen
412      * @return ErrCode - operation result
413      */
414     ErrCode SetAppFrozen(std::set<int> pidList, bool isFrozen) override;
415 
416     /**
417      * @Description reset all frozen app
418      *
419      * @return ErrCode - operation result
420      */
421     ErrCode ResetAllFrozenApp() override;
422 
423     /**
424      * @Description  disable auto join.
425      *
426      * @param conditionName autoJoinDisabled condition.
427      * @return WifiErrorNo
428      */
429     ErrCode DisableAutoJoin(const std::string &conditionName) override;
430 
431     /**
432      * @Description  enable auto join.
433      *
434      * @param conditionName autoJoinDisabled condition.
435      * @return WifiErrorNo
436      */
437     ErrCode EnableAutoJoin(const std::string &conditionName) override;
438 
439     /**
440      * @Description  register auto join condition.
441      *
442      * @param conditionName the name of condition.
443      * @param autoJoinCondition condition.
444      * @return WifiErrorNo
445      */
446     ErrCode RegisterAutoJoinCondition(const std::string &conditionName,
447                                       const std::function<bool()> &autoJoinCondition) override;
448 
449     /**
450      * @Description  deregister auto join condition.
451      *
452      * @param conditionName the name of condition.
453      * @return WifiErrorNo
454      */
455     ErrCode DeregisterAutoJoinCondition(const std::string &conditionName) override;
456 
457     /**
458      * @Description  register external filter builder.
459      *
460      * @param filterTag filterTag which define where the filter should be inserted.
461      * @param filterName the name of the filter to build.
462      * @param filterBuilder filter builder.
463      * @return WifiErrorNo
464      */
465     ErrCode RegisterFilterBuilder(const FilterTag &filterTag, const std::string &filterName,
466                                   const FilterBuilder &filterBuilder) override;
467 
468     /**
469      * @Description  deregister external filter builder.
470      *
471      * @param filterTag filterTag which define where the filter should be inserted.
472      * @param filterName the name of the filter to build.
473      * @return WifiErrorNo
474      */
475     ErrCode DeregisterFilterBuilder(const FilterTag &filterTag, const std::string &filterName) override;
476 
477     /**
478      * Register the common builder function
479      *
480      * @param TagType scoreTag which define where the score or filter should be inserted.
481      * @param tagName the score or filter name.
482      * @param CommonBuilder CommonBuilder function.
483      */
484     ErrCode RegisterCommonBuilder(const TagType &tagType, const std::string &tagName,
485                                const CommonBuilder &commonBuilder) override;
486     /**
487      * Deregister the common builder function
488      *
489      * @param TagType TagType which define where the score or filter should be inserted.
490      * @param tagName the score or filte name.
491      */
492     ErrCode DeregisterCommonBuilder(const TagType &tagType, const std::string &tagName) override;
493 
494     /**
495      * @Description Check whether service is died.
496      *
497      * @return bool - true: service is died, false: service is not died.
498      */
499     bool IsRemoteDied(void);
500 
501     /**
502      * @Description get last Change devicecConfig
503      *
504      * @return ErrCode - operation result
505      */
506     ErrCode GetChangeDeviceConfig(ConfigChange &value, WifiDeviceConfig &config) override;
507 
508     /**
509      * @Description reset factiry
510      *
511      * @return ErrCode - operation result
512      */
513     ErrCode FactoryReset() override;
514 
515     /**
516      * @Description Accept network control information from RSS.
517      *
518      * @param networkControlInfo - structure of network control infomation
519      * @return ErrCode - operation result
520      */
521     ErrCode ReceiveNetworkControlInfo(const WifiNetworkControlInfo& networkControlInfo) override;
522 
523     /**
524      * @Description  limit speed
525      *
526      * @param controlId 1: game 2: stream 3:temp 4: cellular speed limit
527      * @param limitMode speed limit mode, ranges 1 to 9
528      * @return WifiErrorNo
529      */
530     ErrCode LimitSpeed(const int controlId, const int limitMode) override;
531 
532     /**
533      * @Description set low tx power
534      *
535      * @return ErrCode - operation result
536      */
537     ErrCode SetLowTxPower(const WifiLowPowerParam wifiLowPowerParam) override;
538 
539     /**
540      * @Description hilink connect
541      *
542      * @return ErrCode - hilink connect result
543      */
544     ErrCode EnableHiLinkHandshake(bool uiFlag, std::string &bssid, WifiDeviceConfig &deviceConfig) override;
545 
546     /**
547      * @Description Enable semi-Wifi
548      *
549      * @return ErrCode - operation result
550      */
551     ErrCode EnableSemiWifi() override;
552 
553     /**
554      * @Description Obtains the wifi detail state
555      *
556      * @param state - WifiDetailState object
557      * @return ErrCode - operation result
558      */
559     ErrCode GetWifiDetailState(WifiDetailState &state) override;
560 
561     /**
562      * @Description set satellite state
563      * @param state 3009:satellite start 3010:satellite stop 3011:satellite check
564      *
565      * @return ErrCode - operation result
566      */
567     virtual ErrCode SetSatelliteState(const int state) override;
568 
569     /**
570      * @Description roam to target bssid
571      *
572      * @param networkId - target networkId
573      * @param bssid - target bssid
574      * @param isCandidate - Whether is candidate
575      * @return ErrCode - operation result
576      */
577     ErrCode StartRoamToNetwork(const int networkId, const std::string bssid, const bool isCandidate) override;
578 
579     /**
580      * @Description connect to user select ssid and bssid network
581      *
582      * @param networkId - target networkId
583      * @param bssid - target bssid
584      * @param isCandidate - Whether is candidate
585      * @return ErrCode - operation result
586      */
587     ErrCode StartConnectToUserSelectNetwork(int networkId, std::string bssid, bool isCandidate) override;
588 
589     /**
590      * @Description Get single device config
591      *
592      * @param networkId - the network id of the device config
593      * @param config - Get result vector of WifiDeviceConfig
594      * @return ErrCode - operation result
595      */
596     ErrCode GetDeviceConfig(const int &networkId, WifiDeviceConfig &config) override;
597 
598     /**
599      * @Description set data packet identification mark rule
600      *
601      * @param uid - target app uid
602      * @param protocol - target protocol type
603      * @param enable - enable/disable dpi mark
604      */
605     ErrCode SetDpiMarkRule(const std::string &ifaceName, int uid, int protocol, int enable) override;
606 
607     /**
608      * @Description Update Network Lag Info
609      *
610      * @param networkLagType - recv networkLagType
611      * @param networkLagInfo - recv networkLagInfo
612      * @return ErrCode - operation result
613      */
614     ErrCode UpdateNetworkLagInfo(const NetworkLagType networkLagType, const NetworkLagInfo &networkLagInfo) override;
615 
616     /**
617      * @Description Get Vowifi Signal Info.
618      *
619      * @return VoWifiSignalInfo : wifi signal info
620      */
621     ErrCode FetchWifiSignalInfoForVoWiFi(VoWifiSignalInfo &signalInfo) override;
622 
623     /**
624      * @Description Check Is Support VoWifi Detect.
625      *
626      * @return bool - supported: true, unsupported: false.
627      */
628     ErrCode IsSupportVoWifiDetect(bool &isSupported) override;
629 
630     /**
631      * @Description set VoWifi detect mode.
632      *
633      * @param info WifiDetectConfInfo
634      */
635     ErrCode SetVoWifiDetectMode(WifiDetectConfInfo info) override;
636 
637     /**
638      * indicate VoWifiDetectMode
639      *
640      * @return VoWifiDetectMode
641      */
642     ErrCode GetVoWifiDetectMode(WifiDetectConfInfo &info) override;
643 
644     /**
645      * @Description set vowifi detect period.
646      *
647      * @param period period of vowifi detect
648      */
649     ErrCode SetVoWifiDetectPeriod(int period) override;
650 
651     /**
652      * @Description Get vowifi detection period
653      *
654      * @return vowifi detection period
655      */
656     ErrCode GetVoWifiDetectPeriod(int &period) override;
657 
658     /**
659      * @Description Obtains the MLO Wi-Fi connection information
660      *
661      * @param multiLinkedInfo - Wifi MLO Linked Info
662      * @return ErrCode - operation result
663      */
664     ErrCode GetMultiLinkedInfo(std::vector<WifiLinkedInfo> &multiLinkedInfo) override;
665 
666 private:
667     bool GetWifiDeviceProxy();
668     std::atomic<int> systemAbilityId_;
669     int instId_;
670     std::mutex mutex_;
671 #ifdef OHOS_ARCH_LITE
672     IWifiDevice *client_;
673 #else
674     sptr<IWifiDevice> client_;
675 #endif
676 };
677 }  // namespace Wifi
678 }  // namespace OHOS
679 #endif
680