• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021-2025 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 
16 #ifndef OHOS_WIFI_DEVICE_SERVICE_IMPL_H
17 #define OHOS_WIFI_DEVICE_SERVICE_IMPL_H
18 
19 #include <mutex>
20 #include "wifi_errcode.h"
21 #include "wifi_msg.h"
22 #include "i_wifi_device_callback.h"
23 #ifdef OHOS_ARCH_LITE
24 #include "wifi_device_stub_lite.h"
25 #else
26 #include "system_ability.h"
27 #include "wifi_device_stub.h"
28 #include "iremote_object.h"
29 #include "bundle_constants.h"
30 #endif
31 
32 namespace OHOS {
33 namespace Wifi {
34 #ifdef OHOS_ARCH_LITE
35 enum ServiceRunningState { STATE_NOT_START, STATE_RUNNING };
36 #endif
37 
38 class WifiDeviceServiceImpl : public WifiDeviceStub {
39 public:
40     WifiDeviceServiceImpl();
41 #ifdef OHOS_ARCH_LITE
42     static std::shared_ptr<WifiDeviceServiceImpl> GetInstance();
43     void OnStart();
44     void OnStop();
45 #else
46     explicit WifiDeviceServiceImpl(int instId);
47     static ErrCode OnBackup(MessageParcel& data, MessageParcel& reply);
48     static ErrCode OnRestore(MessageParcel& data, MessageParcel& reply);
49 #endif
50     virtual ~WifiDeviceServiceImpl();
51 
52     ErrCode EnableWifi() override;
53 
54     ErrCode DisableWifi() override;
55 
56     ErrCode InitWifiProtect(const WifiProtectType &protectType, const std::string &protectName) override;
57 
58     ErrCode GetWifiProtectRef(const WifiProtectMode &protectMode, const std::string &protectName) override;
59 
60     ErrCode PutWifiProtectRef(const std::string &protectName) override;
61 
62     ErrCode IsHeldWifiProtectRef(const std::string &protectName, bool &isHoldProtect) override;
63 
64     ErrCode AddDeviceConfig(const WifiDeviceConfig &config, int &result, bool isCandidate) override;
65 
66     ErrCode UpdateDeviceConfig(const WifiDeviceConfig &config, int &result) override;
67 
68     ErrCode RemoveDevice(int networkId) override;
69 
70     ErrCode RemoveAllDevice() override;
71 
72     ErrCode SetTxPower(int power) override;
73 
74     ErrCode SetDpiMarkRule(const std::string &ifaceName, int uid, int protocol, int enable) override;
75 
76     ErrCode GetDeviceConfigs(std::vector<WifiDeviceConfig> &result, bool isCandidate) override;
77 
78     ErrCode EnableDeviceConfig(int networkId, bool attemptEnable) override;
79 
80     ErrCode DisableDeviceConfig(int networkId) override;
81 
82     ErrCode AllowAutoConnect(int32_t networkId, bool isAllowed) override;
83 
84     ErrCode ConnectToNetwork(int networkId, bool isCandidate) override;
85 
86     ErrCode ConnectToDevice(const WifiDeviceConfig &config) override;
87 
88     ErrCode StartRoamToNetwork(const int networkId, const std::string bssid, const bool isCandidate) override;
89 
90     ErrCode StartConnectToUserSelectNetwork(int networkId, std::string bssid, bool isCandidate) override;
91 
92     ErrCode IsConnected(bool &isConnected) override;
93 
94     ErrCode ReConnect() override;
95 
96     ErrCode ReAssociate(void) override;
97 
98     ErrCode Disconnect(void) override;
99 
100     ErrCode StartWps(const WpsConfig &config) override;
101 
102     ErrCode CancelWps(void) override;
103 
104     ErrCode IsWifiActive(bool &bActive) override;
105 
106     ErrCode GetWifiState(int &state) override;
107 
108     ErrCode IsMeteredHotspot(bool &bMeteredHotspot) override;
109 
110     ErrCode GetLinkedInfo(WifiLinkedInfo &info) override;
111 
112     ErrCode GetSignalPollInfoArray(std::vector<WifiSignalPollInfo> &wifiSignalPollInfos, int length) override;
113 
114     ErrCode GetMultiLinkedInfo(std::vector<WifiLinkedInfo> &mloLinkInfo) override;
115 
116     ErrCode GetDisconnectedReason(DisconnectedReason &reason) override;
117 
118     ErrCode GetIpInfo(IpInfo &info) override;
119 
120     ErrCode GetIpv6Info(IpV6Info &info) override;
121 
122     ErrCode SetCountryCode(const std::string &countryCode) override;
123 
124     ErrCode GetCountryCode(std::string &countryCode) override;
125 
126     ErrCode SetAppFrozen(std::set<int> pidList, bool isFrozen) override;
127 
128     ErrCode ResetAllFrozenApp() override;
129 
130     ErrCode DisableAutoJoin(const std::string &conditionName) override;
131 
132     ErrCode EnableAutoJoin(const std::string &conditionName) override;
133 
134     ErrCode RegisterAutoJoinCondition(const std::string &conditionName,
135                                       const std::function<bool()> &autoJoinCondition) override;
136 
137     ErrCode DeregisterAutoJoinCondition(const std::string &conditionName) override;
138 
139     ErrCode RegisterFilterBuilder(const FilterTag &filterTag, const std::string &builderName,
140                                   const FilterBuilder &filterBuilder) override;
141 
142     ErrCode DeregisterFilterBuilder(const FilterTag &filterTag, const std::string &builderName) override;
143 
144     ErrCode RegisterCommonBuilder(const TagType &tagType, const std::string &tagName,
145                                const CommonBuilder &commonBuilder) override;
146 
147     ErrCode DeregisterCommonBuilder(const TagType &tagType, const std::string &tagName) override;
148 
149 #ifdef OHOS_ARCH_LITE
150     ErrCode RegisterCallBack(const std::shared_ptr<IWifiDeviceCallBack> &callback,
151         const std::vector<std::string> &event) override;
152 #else
153     ErrCode RegisterCallBack(const sptr<IWifiDeviceCallBack> &callback, const std::vector<std::string> &event) override;
154 #endif
155 
156     ErrCode GetSignalLevel(const int &rssi, const int &band, int &level) override;
157 
158     ErrCode GetSupportedFeatures(long &features) override;
159 
160     ErrCode IsFeatureSupported(long feature, bool &isSupported) override;
161 
162     ErrCode GetDeviceMacAddress(std::string &result) override;
163 
164     bool SetLowLatencyMode(bool enabled) override;
165 
166     ErrCode RemoveCandidateConfig(int networkId) override;
167 
168     ErrCode RemoveCandidateConfig(const WifiDeviceConfig &config) override;
169 
170     bool IsRemoteDied(void) override;
171 
172     ErrCode IsBandTypeSupported(int bandType, bool &supported) override;
173 
174     ErrCode Get5GHzChannelList(std::vector<int> &result) override;
175 
176     ErrCode StartPortalCertification() override;
177 
178     static void SaBasicDump(std::string& result);
179 
180     ErrCode GetChangeDeviceConfig(ConfigChange& value, WifiDeviceConfig &config) override;
181 
182     ErrCode FactoryReset() override;
183 
184     ErrCode ReceiveNetworkControlInfo(const WifiNetworkControlInfo& networkControlInfo) override;
185 
186     ErrCode LimitSpeed(const int controlId, const int limitMode) override;
187 
188     ErrCode SetLowTxPower(const WifiLowPowerParam wifiLowPowerParam) override;
189 
190     ErrCode EnableHiLinkHandshake(bool uiFlag, std::string &bssid, WifiDeviceConfig &deviceConfig) override;
191 
192     ErrCode EnableSemiWifi() override;
193 
194     ErrCode GetWifiDetailState(WifiDetailState &state) override;
195 
196     ErrCode SetSatelliteState(const int state) override;
197 
198     ErrCode GetDeviceConfig(const int &networkId, WifiDeviceConfig &config) override;
199 
200     ErrCode UpdateNetworkLagInfo(const NetworkLagType networkLagType, const NetworkLagInfo &networkLagInfo) override;
201 
202     ErrCode FetchWifiSignalInfoForVoWiFi(VoWifiSignalInfo &signalInfo) override;
203 
204     ErrCode IsSupportVoWifiDetect(bool &isSupported) override;
205 
206     ErrCode SetVoWifiDetectMode(WifiDetectConfInfo info) override;
207 
208     ErrCode GetVoWifiDetectMode(WifiDetectConfInfo &info) override;
209 
210     ErrCode SetVoWifiDetectPeriod(int period) override;
211 
212     ErrCode GetVoWifiDetectPeriod(int &period) override;
213 
214     ErrCode SetWifiRestrictedList(const std::vector<WifiRestrictedInfo> &wifiRestrictedInfoList) override;
215 private:
216     bool Init();
217     ErrCode CheckCanEnableWifi(void);
218     ErrCode CheckCanAddDeviceConfig(const bool isCandidate);
219     bool IsStaServiceRunning();
220     bool IsScanServiceRunning();
221     bool CheckConfigEap(const WifiDeviceConfig &config);
222     bool CheckConfigPwd(const WifiDeviceConfig &config);
223     bool CheckConfigWapi(const WifiDeviceConfig &config);
224     ErrCode CheckCallingUid(int &uid);
225     bool IsWifiBrokerProcess(int uid);
226     ErrCode CheckRemoveCandidateConfig(void);
227     void SetWifiConnectedMode(void);
228     ErrCode HilinkGetMacAddress(WifiDeviceConfig &deviceConfig, std::string &currentMac);
229 #ifndef OHOS_ARCH_LITE
230     bool InitWifiBrokerProcessInfo(const WifiDeviceConfig &config);
231     ErrCode FactoryResetNotify();
232 #endif
233     void ReplaceConfigWhenCandidateConnected(std::vector<WifiDeviceConfig> &result);
234     void updateStaDeviceMacAddress(WifiDeviceConfig &config);
235     int ProcessPermissionVerify(const std::string &appId, const std::string &packageName);
236     void UpdateWifiLinkInfo(WifiLinkedInfo &info);
237 #ifdef DYNAMIC_UNLOAD_SA
238     void StopUnloadStaTimer(void) override;
239 #endif
240     bool IsDisableWifiProhibitedByEdm(void);
241 
242     private:
243     static constexpr int MAX_PRESHAREDKEY_LEN = 63;
244     static constexpr int MAX_HEX_LEN = 64;
245     static constexpr int MIN_PSK_LEN = 8;
246     static constexpr int MIN_SAE_LEN = 1;
247     static constexpr int WEP_KEY_LEN1 = 5;
248     static constexpr int WEP_KEY_LEN2 = 13;
249     static constexpr int WEP_KEY_LEN3 = 16;
250 
251 #ifdef OHOS_ARCH_LITE
252     static std::mutex g_instanceLock;
253     static std::shared_ptr<WifiDeviceServiceImpl> g_instance;
254     ServiceRunningState mState;
255 #endif
256 };
257 }  // namespace Wifi
258 }  // namespace OHOS
259 #endif
260