• 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 - operate result
35      */
36     ErrCode EnableP2p(void) override;
37 
38     /**
39      * @Description Disable the P2P mode
40      *
41      * @return ErrCode - operate result
42      */
43     ErrCode DisableP2p(void) override;
44 
45     /**
46      * @Description Start Wi-Fi P2P device search
47      *
48      * @return ErrCode - operate result
49      */
50     ErrCode DiscoverDevices(void) override;
51 
52     /**
53      * @Description Stop Wi-Fi P2P device search
54      *
55      * @return ErrCode - operate result
56      */
57     ErrCode StopDiscoverDevices(void) override;
58 
59     /**
60      * @Description Start the search for the Wi-Fi P2P service
61      *
62      * @return ErrCode - operate result
63      */
64     ErrCode DiscoverServices(void) override;
65 
66     /**
67      * @Description Stop the search for the Wi-Fi P2P service
68      *
69      * @return ErrCode - operate 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 - operate 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 - operate 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 - operate 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 - operate result
104      */
105     ErrCode StartP2pListen(int period, int interval) override;
106 
107     /**
108      * @Description Disable Wi-Fi P2P listening
109      *
110      * @return ErrCode - operate result
111      */
112     ErrCode StopP2pListen(void) override;
113 
114     /**
115      * @Description Creating a P2P Group
116      *
117      * @param config - WifiP2pGroupInfo object
118      * @return ErrCode - operate result
119      */
120     ErrCode FormGroup(const WifiP2pConfig &config) override;
121 
122     /**
123      * @Description Remove a P2P Group
124      *
125      *
126      * @return ErrCode - operate result
127      */
128     ErrCode RemoveGroup(void) override;
129 
130     /**
131      * @Description Delete a p2p Group
132      *
133      * @param group - WifiP2pGroupInfo object
134      * @return ErrCode - operate result
135      */
136     ErrCode DeleteGroup(const WifiP2pGroupInfo &group) override;
137 
138     /**
139      * @Description P2P connection
140      *
141      * @param config - WifiP2pConfig object
142      * @return ErrCode - operate result
143      */
144     ErrCode P2pConnect(const WifiP2pConfig &config) override;
145 
146     /**
147      * @Description P2P disconnection
148      *
149      * @return ErrCode - operate result
150      */
151     ErrCode P2pDisConnect(void) override;
152 
153     /**
154      * @Description Querying Wi-Fi P2P Connection Information
155      *
156      * @param linkedInfo - Get the WifiP2pLinkedInfo msg
157      * @return ErrCode - operate 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 - operate 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 - operate 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 - operate result
190      */
191     ErrCode GetP2pConnectedStatus(int &status) override;
192 
193     /**
194      * @Description Query the information about the found devices
195      *
196      * @param devives - Get result vector of WifiP2pDevice
197      * @return ErrCode - operate result
198      */
199     ErrCode QueryP2pDevices(std::vector<WifiP2pDevice> &devives) override;
200 
201     /**
202      * @Description Query the information about the found groups
203      *
204      * @param groups - Get result vector of WifiP2pGroupInfo
205      * @return ErrCode - operate result
206      */
207     ErrCode QueryP2pGroups(std::vector<WifiP2pGroupInfo> &groups) override;
208 
209     /**
210      * @Description Query the service information
211      *
212      * @param services - Get result vector of Device
213      * @return ErrCode - operate result
214      */
215     ErrCode QueryP2pServices(std::vector<WifiP2pServiceInfo> &services) override;
216 
217     /**
218      * @Description Register callback function
219      *
220      * @param callback - IWifiP2pCallback object
221      * @return ErrCode - operate result
222      */
223     ErrCode RegisterCallBack(const sptr<IWifiP2pCallback> &callback) override;
224 
225     /**
226      * @Description Get supported features
227      *
228      * @param features - return supported features
229      * @return ErrCode - operation result
230      */
231     ErrCode GetSupportedFeatures(long &features) override;
232 
233     /**
234      * @Description Check if supported input feature
235      *
236      * @param feature - input feature
237      * @return true - supported
238      * @return false - unsupported
239      */
240     bool IsFeatureSupported(long feature) override;
241 
242     /**
243      * @Description set the device name
244      *
245      * @param deviceName - device name
246      * @return ErrCode - operate result
247      */
248     ErrCode SetP2pDeviceName(const std::string &deviceName) override;
249 
250     /**
251      * @Description set p2p wifi display info
252      *
253      * @param wfdInfo - wifi display info
254      * @return ErrCode - operate result
255      */
256     ErrCode SetP2pWfdInfo(const WifiP2pWfdInfo &wfdInfo) override;
257 
258     /**
259      * @Description Request an IP address to the Gc from the IP address pool, used on the GO side.
260      *
261      * @param gcMac - gc mac address
262      * @param ipAddr - applied ip address
263      * @return ErrCode - operate result
264      */
265     ErrCode Hid2dRequestGcIp(const std::string& gcMac, std::string& ipAddr) override;
266 
267     /**
268      * @Description Increase(+1) hid2d shared link reference counting
269      *
270      * @return ErrCode - operate result
271      */
272     ErrCode Hid2dSharedlinkIncrease() override;
273 
274     /**
275      * @Description Decrease(-1) hid2d shared link reference counting
276      *
277      * @return ErrCode - operate result
278      */
279     ErrCode Hid2dSharedlinkDecrease() override;
280 
281     /**
282      * @Description Create hid2d group, used on the GO side.
283      *
284      * @param frequency - frequency
285      * @param type - frequency type
286      * @return ErrCode - operate result
287      */
288     ErrCode Hid2dCreateGroup(const int frequency, FreqType type) override;
289 
290     /**
291      * @Description The GC side actively disconnects from the GO, used on the GC side.
292      *
293      * @param gcIfName - network interface name
294      * @return ErrCode - operate result
295      */
296     ErrCode Hid2dRemoveGcGroup(const std::string& gcIfName) override;
297 
298     /**
299      * @Description Connect to a specified group using hid2d, used on the GC side.
300      *
301      * @param config - connection parameters
302      * @return ErrCode - operate result
303      */
304     ErrCode Hid2dConnect(const Hid2dConnectConfig& config) override;
305 
306     /**
307      * @Description Configuring IP addresses for P2P network interfaces, used on the GC side.
308      *
309      * @param ifName - network interface name
310      * @param ipInfo - IP infos
311      * @return ErrCode - operate result
312      */
313     ErrCode Hid2dConfigIPAddr(const std::string& ifName, const IpAddrInfo& ipInfo) override;
314 
315     /**
316      * @Description Clear IP address when the P2P connection is disconnected, used on the GC side.
317      *
318      * @param ifName - network interface name
319      * @return ErrCode - operate result
320      */
321     ErrCode Hid2dReleaseIPAddr(const std::string& ifName) override;
322 
323      /**
324      * @Description Obtain the recommended channel and bandwidth for link setup
325      *
326      * @param request - request data
327      * @param response - response result
328      * @return ErrCode - operate result
329      */
330     ErrCode Hid2dGetRecommendChannel(const RecommendChannelRequest& request,
331         RecommendChannelResponse& response) override;
332 
333     /**
334      * @Description get 5G channel list
335      *
336      * @param vecChannelList - result for channel list
337      * @return ErrCode - operate result
338      */
339     ErrCode Hid2dGetChannelListFor5G(std::vector<int>& vecChannelList) override;
340 
341     /**
342      * @Description get the self wifi configuration information
343      *
344      * @param cfgType - configuration type
345      * @param cfgData - the queried data of wifi configuration
346      * @param getDatValidLen - the valid data length in the array `cfgData`
347      * @return ErrCode - operate result
348      */
349     ErrCode Hid2dGetSelfWifiCfgInfo(SelfCfgType cfgType,
350         char cfgData[CFG_DATA_MAX_BYTES], int* getDatValidLen) override;
351 
352     /**
353      * @Description set the peer wifi configuration information
354      *
355      * @param cfgType - configuration type
356      * @param cfgData - the wifi configuration data to be set
357      * @param setDataValidLen - the valid data length in the array `cfgData`
358      * @return ErrCode - operate result
359      */
360     ErrCode Hid2dSetPeerWifiCfgInfo(PeerCfgType cfgType,
361         char cfgData[CFG_DATA_MAX_BYTES], int setDataValidLen) override;
362 
363 private:
364     int systemAbilityId_;
365     sptr<IWifiP2p> client_;
366 };
367 }  // namespace Wifi
368 }  // namespace OHOS
369 #endif