• 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_P2P_IMPL_H
16 #define OHOS_WIFI_P2P_IMPL_H
17 
18 #include "wifi_p2p.h"
19 #include "wifi_p2p_proxy.h"
20 #include "wifi_hid2d.h"
21 
22 namespace OHOS {
23 namespace Wifi {
24 class WifiP2pImpl : public WifiP2p, public Hid2d {
25 public:
26     WifiP2pImpl();
27     virtual ~WifiP2pImpl();
28     bool Init(int systemAbilityId);
29 
30     /**
31      * @Description Enabling the P2P Mode
32      *
33      * @return ErrCode - operation result
34      */
35     ErrCode EnableP2p(void) override;
36 
37     /**
38      * @Description Disable the P2P mode
39      *
40      * @return ErrCode - operation result
41      */
42     ErrCode DisableP2p(void) override;
43 
44     /**
45      * @Description Start Wi-Fi P2P device search
46      *
47      * @return ErrCode - operation result
48      */
49     ErrCode DiscoverDevices(void) override;
50 
51     /**
52      * @Description Stop Wi-Fi P2P device search
53      *
54      * @return ErrCode - operation result
55      */
56     ErrCode StopDiscoverDevices(void) override;
57 
58     /**
59      * @Description Start the search for the Wi-Fi P2P service
60      *
61      * @return ErrCode - operation result
62      */
63     ErrCode DiscoverServices(void) override;
64 
65     /**
66      * @Description Stop the search for the Wi-Fi P2P service
67      *
68      * @return ErrCode - operation result
69      */
70     ErrCode StopDiscoverServices(void) override;
71 
72     /**
73      * @Description request the P2P service
74      *
75      * @param device - WifiP2pDevice object
76      * @param request - WifiP2pServiceRequest object
77      * @return ErrCode - operation result
78      */
79     ErrCode RequestService(const WifiP2pDevice &device, const WifiP2pServiceRequest &request) override;
80 
81     /**
82      * @Description Register the local P2P service
83      *
84      * @param srvInfo - WifiP2pServiceInfo object
85      * @return ErrCode - operation result
86      */
87     ErrCode PutLocalP2pService(const WifiP2pServiceInfo &srvInfo) override;
88 
89     /**
90      * @Description Delete the local P2P service
91      *
92      * @param srvInfo - WifiP2pServiceInfo object
93      * @return ErrCode - operation result
94      */
95     ErrCode DeleteLocalP2pService(const WifiP2pServiceInfo &srvInfo) override;
96 
97     /**
98      * @Description Enable Wi-Fi P2P listening
99      *
100      * @param period - period
101      * @param interval - interval
102      * @return ErrCode - operation result
103      */
104     ErrCode StartP2pListen(int period, int interval) override;
105 
106     /**
107      * @Description Disable Wi-Fi P2P listening
108      *
109      * @return ErrCode - operation result
110      */
111     ErrCode StopP2pListen(void) override;
112 
113     /**
114      * @Description Creating a P2P Group
115      *
116      * @param config - WifiP2pGroupInfo object
117      * @return ErrCode - operation result
118      */
119     ErrCode CreateGroup(const WifiP2pConfig &config) override;
120 
121     /**
122      * @Description Remove a P2P Group
123      *
124      *
125      * @return ErrCode - operation result
126      */
127     ErrCode RemoveGroup(void) override;
128 
129     /**
130      * @Description Remove a P2P client of current group.
131      *
132      * @param deviceMac - client deviceMac address
133      * @return ErrCode - operation result
134      */
135     ErrCode RemoveGroupClient(const GcInfo &info) override;
136 
137     /**
138      * @Description Delete a p2p Group
139      *
140      * @param group - WifiP2pGroupInfo object
141      * @return ErrCode - operation result
142      */
143     ErrCode DeleteGroup(const WifiP2pGroupInfo &group) override;
144 
145     /**
146      * @Description P2P connection
147      *
148      * @param config - WifiP2pConfig object
149      * @return ErrCode - operation result
150      */
151     ErrCode P2pConnect(const WifiP2pConfig &config) override;
152 
153     /**
154      * @Description Canceling a P2P connection
155      *
156      * @return ErrCode - operation result
157      */
158     ErrCode P2pCancelConnect(void) override;
159 
160     /**
161      * @Description Querying Wi-Fi P2P Connection Information
162      *
163      * @param linkedInfo - Get the WifiP2pLinkedInfo msg
164      * @return ErrCode - operation result
165      */
166     ErrCode QueryP2pLinkedInfo(WifiP2pLinkedInfo &linkedInfo) override;
167 
168     /**
169      * @Description Get the Current Group object
170      *
171      * @param group - the WifiP2pGroupInfo object
172      * @return ErrCode - operation result
173      */
174     ErrCode GetCurrentGroup(WifiP2pGroupInfo &group) override;
175 
176     /**
177      * @Description Obtains the P2P switch status
178      *
179      * @param status - the P2P switch status
180      * @return ErrCode - operation result
181      */
182     ErrCode GetP2pEnableStatus(int &status) override;
183 
184     /**
185      * @Description Obtains the P2P discovery status
186      *
187      * @param status - the P2P discovery status
188      * @return ErrCode
189      */
190     ErrCode GetP2pDiscoverStatus(int &status) override;
191 
192     /**
193      * @Description Obtains the P2P connection status
194      *
195      * @param status - the P2P connection status
196      * @return ErrCode - operation result
197      */
198     ErrCode GetP2pConnectedStatus(int &status) override;
199 
200     /**
201      * @Description Query the information about the found devices
202      *
203      * @param devices - Get result vector of WifiP2pDevice
204      * @return ErrCode - operation result
205      */
206     ErrCode QueryP2pDevices(std::vector<WifiP2pDevice> &devices) override;
207 
208     /**
209      * @Description Query the information about the local device
210      *
211      * @param devives - Get result of WifiP2pDevice
212      * @return ErrCode - operation result
213      */
214     ErrCode QueryP2pLocalDevice(WifiP2pDevice &devive) override;
215 
216     /**
217      * @Description Query the information about the found groups
218      *
219      * @param groups - Get result vector of WifiP2pGroupInfo
220      * @return ErrCode - operation result
221      */
222     ErrCode QueryP2pGroups(std::vector<WifiP2pGroupInfo> &groups) override;
223 
224     /**
225      * @Description Query the service information
226      *
227      * @param services - Get result vector of Device
228      * @return ErrCode - operation result
229      */
230     ErrCode QueryP2pServices(std::vector<WifiP2pServiceInfo> &services) override;
231 
232     /**
233      * @Description Register callback function
234      *
235      * @param callback - IWifiP2pCallback object
236      * @return ErrCode - operation result
237      */
238     ErrCode RegisterCallBack(const sptr<IWifiP2pCallback> &callback, const std::vector<std::string> &event) override;
239 
240     /**
241      * @Description Get supported features
242      *
243      * @param features - return supported features
244      * @return ErrCode - operation result
245      */
246     ErrCode GetSupportedFeatures(long &features) override;
247 
248     /**
249      * @Description Check if supported input feature
250      *
251      * @param feature - input feature
252      * @return true - supported
253      * @return false - unsupported
254      */
255     bool IsFeatureSupported(long feature) override;
256 
257     /**
258      * @Description set the device name
259      *
260      * @param deviceName - device name
261      * @return ErrCode - operation result
262      */
263     ErrCode SetP2pDeviceName(const std::string &deviceName) override;
264 
265     /**
266      * @Description set p2p wifi display info
267      *
268      * @param wfdInfo - wifi display info
269      * @return ErrCode - operation result
270      */
271     ErrCode SetP2pWfdInfo(const WifiP2pWfdInfo &wfdInfo) override;
272 
273     /**
274      * @Description Request an IP address to the Gc from the IP address pool, used on the GO side.
275      *
276      * @param gcMac - gc mac address
277      * @param ipAddr - applied ip address
278      * @return ErrCode - operation result
279      */
280     ErrCode Hid2dRequestGcIp(const std::string& gcMac, std::string& ipAddr) override;
281 
282     /**
283      * @Description Increase(+1) hid2d shared link reference counting
284      *
285      * @return ErrCode - operation result
286      */
287     ErrCode Hid2dSharedlinkIncrease() override;
288 
289     /**
290      * @Description Decrease(-1) hid2d shared link reference counting
291      *
292      * @return ErrCode - operation result
293      */
294     ErrCode Hid2dSharedlinkDecrease() override;
295 
296     /**
297      * @Description Create hid2d group, used on the GO side.
298      *
299      * @param frequency - frequency
300      * @param type - frequency type
301      * @return ErrCode - operation result
302      */
303     ErrCode Hid2dCreateGroup(const int frequency, FreqType type) override;
304 
305     /**
306      * @Description The GC side actively disconnects from the GO, used on the GC side.
307      *
308      * @param gcIfName - network interface name
309      * @return ErrCode - operation result
310      */
311     ErrCode Hid2dRemoveGcGroup(const std::string& gcIfName) override;
312 
313     /**
314      * @Description Connect to a specified group using hid2d, used on the GC side.
315      *
316      * @param config - connection parameters
317      * @return ErrCode - operation result
318      */
319     ErrCode Hid2dConnect(const Hid2dConnectConfig& config) override;
320 
321     /**
322      * @Description Configuring IP addresses for P2P network interfaces, used on the GC side.
323      *
324      * @param ifName - network interface name
325      * @param ipInfo - IP infos
326      * @return ErrCode - operation result
327      */
328     ErrCode Hid2dConfigIPAddr(const std::string& ifName, const IpAddrInfo& ipInfo) override;
329 
330     /**
331      * @Description Clear IP address when the P2P connection is disconnected, used on the GC side.
332      *
333      * @param ifName - network interface name
334      * @return ErrCode - operation result
335      */
336     ErrCode Hid2dReleaseIPAddr(const std::string& ifName) override;
337 
338      /**
339      * @Description Obtain the recommended channel and bandwidth for link setup
340      *
341      * @param request - request data
342      * @param response - response result
343      * @return ErrCode - operation result
344      */
345     ErrCode Hid2dGetRecommendChannel(const RecommendChannelRequest& request,
346         RecommendChannelResponse& response) override;
347 
348     /**
349      * @Description get 5G channel list
350      *
351      * @param vecChannelList - result for channel list
352      * @return ErrCode - operation result
353      */
354     ErrCode Hid2dGetChannelListFor5G(std::vector<int>& vecChannelList) override;
355 
356     /**
357      * @Description get the self wifi configuration information
358      *
359      * @param cfgType - configuration type
360      * @param cfgData - the queried data of wifi configuration
361      * @param getDatValidLen - the valid data length in the array `cfgData`
362      * @return ErrCode - operation result
363      */
364     ErrCode Hid2dGetSelfWifiCfgInfo(SelfCfgType cfgType,
365         char cfgData[CFG_DATA_MAX_BYTES], int* getDatValidLen) override;
366 
367     /**
368      * @Description set the peer wifi configuration information
369      *
370      * @param cfgType - configuration type
371      * @param cfgData - the wifi configuration data to be set
372      * @param setDataValidLen - the valid data length in the array `cfgData`
373      * @return ErrCode - operation result
374      */
375     ErrCode Hid2dSetPeerWifiCfgInfo(PeerCfgType cfgType,
376         char cfgData[CFG_DATA_MAX_BYTES], int setDataValidLen) override;
377 
378     /**
379      * @Description Set the scene of upper layer
380      *
381      * @param ifName - interface name
382      * @param scene - scene
383      * @return ErrCode - operate result
384      */
385     ErrCode Hid2dSetUpperScene(const std::string& ifName, const Hid2dUpperScene& scene) override;
386 
387     /**
388      * @Description Check whether service is died.
389      *
390      * @return bool - true: service is died, false: service is not died.
391      */
392     bool IsRemoteDied(void);
393 
394     /**
395      * @Description Check whether service is died.
396      *
397      * @return bool - true: service is died, false: service is not died.
398      */
399     ErrCode DiscoverPeers(int32_t channelid) override;
400 
401     /**
402      * @Description Check whether service is died.
403      *
404      * @return bool - true: service is died, false: service is not died.
405      */
406     ErrCode DisableRandomMac(int setmode) override;
407 
408     /**
409      * @Description Check can use P2P
410      *
411      * @return ErrCode - operation result
412      */
413     ErrCode CheckCanUseP2p() override;
414 
415     /**
416      * @Description Hid2d Is Wide Bandwidth Supported
417      *
418      * @param isSupport - is support 160M
419      * @return ErrCode - operation result
420      */
421     ErrCode Hid2dIsWideBandwidthSupported(bool &isSupport) override;
422 
423 private:
424     bool GetWifiP2pProxy();
425     std::atomic<int> systemAbilityId_;
426     sptr<IWifiP2p> client_;
427     std::mutex mutex_;
428 };
429 }  // namespace Wifi
430 }  // namespace OHOS
431 #endif