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