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