• 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_PROXY_H
16 #define OHOS_WIFI_P2P_PROXY_H
17 
18 #include "i_wifi_p2p.h"
19 #include "iremote_proxy.h"
20 #include "wifi_errcode.h"
21 #include "wifi_p2p_msg.h"
22 
23 namespace OHOS {
24 namespace Wifi {
25 class WifiP2pProxy : public IRemoteProxy<IWifiP2p> {
26 public:
27     explicit WifiP2pProxy(const sptr<IRemoteObject> &impl);
28     ~WifiP2pProxy();
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 Delete a p2p Group
131      *
132      * @param group - WifiP2pGroupInfo object
133      * @return ErrCode - operation result
134      */
135     ErrCode DeleteGroup(const WifiP2pGroupInfo &group) override;
136 
137     /**
138      * @Description P2P connection
139      *
140      * @param config - WifiP2pConfig object
141      * @return ErrCode - operation result
142      */
143     ErrCode P2pConnect(const WifiP2pConfig &config) override;
144 
145     /**
146      * @Description Canceling a P2P connection
147      *
148      * @return ErrCode - operation result
149      */
150     ErrCode P2pCancelConnect(void) override;
151 
152     /**
153      * @Description Querying Wi-Fi P2P Connection Information
154      *
155      * @param linkedInfo - Get the WifiP2pLinkedInfo msg
156      * @return ErrCode - operation result
157      */
158     ErrCode QueryP2pLinkedInfo(WifiP2pLinkedInfo &linkedInfo) override;
159 
160     /**
161      * @Description Get the Current Group object
162      *
163      * @param group - the WifiP2pGroupInfo object
164      * @return ErrCode - operation result
165      */
166     ErrCode GetCurrentGroup(WifiP2pGroupInfo &group) override;
167 
168     /**
169      * @Description Obtains the P2P switch status
170      *
171      * @param status - the P2P switch status
172      * @return ErrCode - operation result
173      */
174     ErrCode GetP2pEnableStatus(int &status) override;
175 
176     /**
177      * @Description Obtains the P2P discovery status
178      *
179      * @param status - the P2P discovery status
180      * @return ErrCode
181      */
182     ErrCode GetP2pDiscoverStatus(int &status) override;
183 
184     /**
185      * @Description Obtains the P2P connection status
186      *
187      * @param status - the P2P connection status
188      * @return ErrCode - operation result
189      */
190     ErrCode GetP2pConnectedStatus(int &status) override;
191 
192     /**
193      * @Description Query the information about the found devices
194      *
195      * @param devices - Get result vector of WifiP2pDevice
196      * @return ErrCode - operation result
197      */
198     ErrCode QueryP2pDevices(std::vector<WifiP2pDevice> &devices) override;
199 
200     /**
201      * @Description Query the information about local device info
202      *
203      * @param devices - Get result of WifiP2pDevice
204      * @return ErrCode - operation result
205      */
206     ErrCode QueryP2pLocalDevice(WifiP2pDevice &device) override;
207 
208     /**
209      * @Description Query the information about the found groups
210      *
211      * @param groups - Get result vector of WifiP2pGroupInfo
212      * @return ErrCode - operation result
213      */
214     ErrCode QueryP2pGroups(std::vector<WifiP2pGroupInfo> &groups) override;
215 
216     /**
217      * @Description Query the service information
218      *
219      * @param services - Get result vector of Device
220      * @return ErrCode - operation result
221      */
222     ErrCode QueryP2pServices(std::vector<WifiP2pServiceInfo> &services) override;
223 
224     /**
225      * @Description Register callback function
226      *
227      * @param callback - IWifiP2pCallback object
228      * @return ErrCode - operation result
229      */
230     ErrCode RegisterCallBack(const sptr<IWifiP2pCallback> &callback, const std::vector<std::string> &event) override;
231 
232     /**
233      * @Description Get supported features
234      *
235      * @param features - return supported features
236      * @return ErrCode - operation result
237      */
238     ErrCode GetSupportedFeatures(long &features) override;
239 
240     /**
241      * @Description set the device name
242      *
243      * @param deviceName - device name
244      * @return ErrCode - operation result
245      */
246     ErrCode SetP2pDeviceName(const std::string &deviceName) override;
247 
248     /**
249      * @Description set p2p wifi display info
250      *
251      * @param wfdInfo - wifi display info
252      * @return ErrCode - operation result
253      */
254     ErrCode SetP2pWfdInfo(const WifiP2pWfdInfo &wfdInfo) override;
255 
256     /**
257      * @Description Request an IP address to the Gc from the IP address pool, used on the GO side.
258      *
259      * @param gcMac - gc mac address
260      * @param ipAddr - applied ip address
261      * @return ErrCode - operation result
262      */
263     ErrCode Hid2dRequestGcIp(const std::string& gcMac, std::string& ipAddr) override;
264 
265     /**
266      * @Description Increase(+1) hid2d shared link reference counting
267      *
268      * @return ErrCode - operation result
269      */
270     ErrCode Hid2dSharedlinkIncrease() override;
271 
272     /**
273      * @Description Decrease(-1) hid2d shared link reference counting
274      *
275      * @return ErrCode - operation result
276      */
277     ErrCode Hid2dSharedlinkDecrease() override;
278 
279     /**
280      * @Description Create hid2d group, used on the GO side.
281      *
282      * @param frequency - frequency
283      * @param type - frequency type
284      * @return ErrCode - operation result
285      */
286     ErrCode Hid2dCreateGroup(const int frequency, FreqType type) override;
287 
288     /**
289      * @Description The GC side actively disconnects from the GO, used on the GC side.
290      *
291      * @param gcIfName - network interface name
292      * @return ErrCode - operation result
293      */
294     ErrCode Hid2dRemoveGcGroup(const std::string& gcIfName) override;
295 
296     /**
297      * @Description Connect to a specified group using hid2d, used on the GC side.
298      *
299      * @param config - connection parameters
300      * @return ErrCode - operation result
301      */
302     ErrCode Hid2dConnect(const Hid2dConnectConfig& config) override;
303 
304     /**
305      * @Description Configuring IP addresses for P2P network interfaces, used on the GC side.
306      *
307      * @param ifName - network interface name
308      * @param ipInfo - IP infos
309      * @return ErrCode - operation result
310      */
311     ErrCode Hid2dConfigIPAddr(const std::string& ifName, const IpAddrInfo& ipInfo) override;
312 
313     /**
314      * @Description Clear IP address when the P2P connection is disconnected, used on the GC side.
315      *
316      * @param ifName - network interface name
317      * @return ErrCode - operation result
318      */
319     ErrCode Hid2dReleaseIPAddr(const std::string& ifName) override;
320 
321      /**
322      * @Description Obtain the recommended channel and bandwidth for link setup
323      *
324      * @param request - request data
325      * @param response - response result
326      * @return ErrCode - operation result
327      */
328     ErrCode Hid2dGetRecommendChannel(const RecommendChannelRequest& request,
329         RecommendChannelResponse& response) override;
330 
331     /**
332      * @Description get 5G channel list
333      *
334      * @param vecChannelList - result for channel list
335      * @return ErrCode - operation result
336      */
337     ErrCode Hid2dGetChannelListFor5G(std::vector<int>& vecChannelList) override;
338 
339     /**
340      * @Description get the self wifi configuration information
341      *
342      * @param cfgType - configuration type
343      * @param cfgData - the queried data of wifi configuration
344      * @param getDatValidLen - the valid data length in the array `cfgData`
345      * @return ErrCode - operation result
346      */
347     ErrCode Hid2dGetSelfWifiCfgInfo(SelfCfgType cfgType,
348         char cfgData[CFG_DATA_MAX_BYTES], int* getDatValidLen) override;
349 
350     /**
351      * @Description set the peer wifi configuration information
352      *
353      * @param cfgType - configuration type
354      * @param cfgData - the wifi configuration data to be set
355      * @param setDataValidLen - the valid data length in the array `cfgData`
356      * @return ErrCode - operation result
357      */
358     ErrCode Hid2dSetPeerWifiCfgInfo(PeerCfgType cfgType,
359         char cfgData[CFG_DATA_MAX_BYTES], int setDataValidLen) override;
360 
361     /**
362      * @Description Set the scene of upper layer
363      *
364      * @param ifName - interface name
365      * @param scene - scene
366      * @return ErrCode - operate result
367      */
368     ErrCode Hid2dSetUpperScene(const std::string& ifName, const Hid2dUpperScene& scene) override;
369 
370     /**
371     * @Description Handle remote object died event.
372     * @param remoteObject remote object.
373     */
374     void OnRemoteDied(const wptr<IRemoteObject> &remoteObject);
375 
376     /**
377      * @Description Check whether service is died.
378      *
379      * @return bool - true: service is died, false: service is not died.
380      */
381     bool IsRemoteDied(void) override   ;
382 
383 private:
384     class WifiDeathRecipient : public IRemoteObject::DeathRecipient {
385     public:
WifiDeathRecipient(WifiP2pProxy & client)386         explicit WifiDeathRecipient(WifiP2pProxy &client) : client_(client) {}
387         ~WifiDeathRecipient() override = default;
OnRemoteDied(const wptr<IRemoteObject> & remote)388         void OnRemoteDied(const wptr<IRemoteObject> &remote) override
389         {
390             client_.OnRemoteDied(remote);
391         }
392 
393     private:
394         WifiP2pProxy &client_;
395     };
396 
397     void RemoveDeathRecipient(void);
398     void ReadWifiP2pServiceInfo(MessageParcel &reply, WifiP2pServiceInfo &info) const;
399     void WriteWifiP2pServiceInfo(MessageParcel &data, const WifiP2pServiceInfo &info) const;
400     void WriteWifiP2pServiceRequest(
401         MessageParcel &data, const WifiP2pDevice &device, const WifiP2pServiceRequest &request) const;
402     void WriteWifiP2pDeviceData(MessageParcel &data, const WifiP2pDevice &device) const;
403     void ReadWifiP2pDeviceData(MessageParcel &reply, WifiP2pDevice &device) const;
404     void WriteWifiP2pGroupData(MessageParcel &data, const WifiP2pGroupInfo &info) const;
405     void ReadWifiP2pGroupData(MessageParcel &reply, WifiP2pGroupInfo &info) const;
406     void WriteWifiP2pConfigData(MessageParcel &data, const WifiP2pConfig &config) const;
407 
408 private:
409     bool mRemoteDied;
410     static BrokerDelegator<WifiP2pProxy> delegator;
411     sptr<IRemoteObject> remote_ = nullptr;
412     std::mutex mutex_;
413     sptr<IRemoteObject::DeathRecipient> deathRecipient_ = nullptr;
414 };
415 }  // namespace Wifi
416 }  // namespace OHOS
417 #endif