• 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 
16 #ifndef OHOS_P2P_INTERFACE_H
17 #define OHOS_P2P_INTERFACE_H
18 
19 #include "ip2p_service.h"
20 #include "wifi_p2p_service.h"
21 #include "p2p_monitor.h"
22 #include "p2p_state_machine.h"
23 #include "authorizing_negotiation_request_state.h"
24 #include "group_formed_state.h"
25 #include "group_negotiation_state.h"
26 #include "invitation_received_state.h"
27 #include "invitation_request_state.h"
28 #include "p2p_default_state.h"
29 #include "p2p_disabled_state.h"
30 #include "p2p_disabling_state.h"
31 #include "p2p_enabled_state.h"
32 #include "p2p_enabling_state.h"
33 #include "p2p_group_formation_state.h"
34 #include "p2p_group_join_state.h"
35 #include "p2p_group_operating_state.h"
36 #include "p2p_idle_state.h"
37 #include "p2p_inviting_state.h"
38 #include "provision_discovery_state.h"
39 #include "wifi_p2p_group_manager.h"
40 #include "p2p_group_remove_state.h"
41 
42 namespace OHOS {
43 namespace Wifi {
44 class P2pInterface : public IP2pService {
45 public:
46     /**
47      * @Description Construct a new P2pInterface object.
48      */
49     P2pInterface();
50 
51     /**
52      * @Description Destroy the P2pInterface object.
53      */
54     ~P2pInterface() = default;
55 
56 public:
57     /**
58      * @Description - Enable the P2P mode.
59      * @return ErrCode - operation result
60      */
61     virtual ErrCode EnableP2p() override;
62 
63     /**
64      * @Description - Disable the P2P mode.
65      * @return ErrCode - operation result
66      */
67     virtual ErrCode DisableP2p() override;
68 
69     /**
70      * @Description - Start P2P device discovery.
71      * @return ErrCode - operation result
72      */
73     virtual ErrCode DiscoverDevices() override;
74 
75     /**
76      * @Description - Stop P2P device discovery.
77      * @return ErrCode - operation result
78      */
79     virtual ErrCode StopDiscoverDevices() override;
80 
81     /**
82      * @Description - Start P2P services discovery.
83      * @return ErrCode - operation result
84      */
85     virtual ErrCode DiscoverServices() override;
86 
87     /**
88      * @Description - Stop P2P services discovery.
89      * @return ErrCode - operation result
90      */
91     virtual ErrCode StopDiscoverServices() override;
92 
93     /**
94      * @Description - Register local P2P service.
95      * @param  srvInfo - local service information
96      * @return ErrCode - operation result
97      */
98     virtual ErrCode PutLocalP2pService(const WifiP2pServiceInfo &srvInfo) override;
99 
100     /**
101      * @Description - Delete local P2P service.
102      * @param  srvInfo - local service information
103      * @return ErrCode - operation result
104      */
105     virtual ErrCode DeleteLocalP2pService(const WifiP2pServiceInfo &srvInfo) override;
106 
107     /**
108      * @Description - Request specified services.
109      * @param  device - requested target device
110      * @param  request - initiated service request data
111      * @return ErrCode - operation result
112      */
113     virtual ErrCode RequestService(const WifiP2pDevice &device, const WifiP2pServiceRequest &request) override;
114 
115     /**
116      * @Description - Start the P2P listening. Unit: millisecond.
117      * @param  period - listening period
118      * @param  interval - listening interval
119      * @return ErrCode - operation result
120      */
121     virtual ErrCode StartP2pListen(int period, int interval) override;
122 
123     /**
124      * @Description - Stop the P2P listening.
125      * @return ErrCode - operation result
126      */
127     virtual ErrCode StopP2pListen() override;
128 
129     /**
130      * @Description - Create a P2P group.
131      * @param  config - config for creating group
132      * @return ErrCode - operation result
133      */
134     virtual ErrCode CreateGroup(const WifiP2pConfig &config) override;
135 
136     /**
137      * @Description - Remove the current P2P group.
138      * @return ErrCode - operation result
139      */
140     virtual ErrCode RemoveGroup() override;
141 
142     /**
143      * @Description Remove a P2P client of current group.
144      *
145      * @return ErrCode - operation result
146      */
147     virtual ErrCode RemoveGroupClient(const GcInfo &info) override;
148 
149     /**
150      * @Description - Delete a persistent group.
151      * @param  group - specified group
152      * @return ErrCode - operation result
153      */
154     virtual ErrCode DeleteGroup(const WifiP2pGroupInfo &group) override;
155 
156     /**
157      * @Description - Connect to a P2P device.
158      * @param  config - config for connection
159      * @return ErrCode - operation result
160      */
161     virtual ErrCode P2pConnect(const WifiP2pConfig &config) override;
162 
163     /**
164      * @Description - Canceling a P2P connection.
165      * @return ErrCode - operation result
166      */
167     virtual ErrCode P2pCancelConnect() override;
168 
169     /**
170      * @Description - Set this device name.
171      *
172      * @param devName - specified device name
173      * @return ErrCode
174      */
175     virtual ErrCode SetP2pDeviceName(const std::string &devName) override;
176 
177     /**
178      * @Description - Query P2P connection information.
179      * @param  linkedInfo - object that stores connection information
180      * @return ErrCode - operation result
181      */
182     virtual ErrCode QueryP2pLinkedInfo(WifiP2pLinkedInfo &linkedInfo) override;
183 
184     /**
185      * @Description set p2p wifi display info
186      * @param wfdInfo - wifi display info
187      * @return ErrCode - operation result
188      */
189     virtual ErrCode SetP2pWfdInfo(const WifiP2pWfdInfo &wfdInfo) override;
190 
191     /**
192      * @Description - Get the current group information.
193      * @param  group - object that stores the current group
194      * @return ErrCode - operation result
195      */
196     virtual ErrCode GetCurrentGroup(WifiP2pGroupInfo &group) override;
197 
198     /**
199      * @Description - Obtain the P2P status.
200      * @param  status - object that stores P2P status
201      * @return ErrCode - operation result
202      */
203     virtual ErrCode GetP2pEnableStatus(int &status) override;
204 
205     /**
206      * @Description - Obtain the P2P discovery status.
207      * @param  status - object that stores discovery status
208      * @return ErrCode - operation result
209      */
210     virtual ErrCode GetP2pDiscoverStatus(int &status) override;
211 
212     /**
213      * @Description - Obtain the P2P connection status.
214      * @param  status - object that stores connection status
215      * @return ErrCode - operation result
216      */
217     virtual ErrCode GetP2pConnectedStatus(int &status) override;
218 
219     /**
220      * @Description - Query the information about the found devices.
221      * @param  devices - list of queryed device
222      * @return ErrCode - operation result
223      */
224     virtual ErrCode QueryP2pDevices(std::vector<WifiP2pDevice> &devices) override;
225 
226     /**
227      * @Description - Query the information about own device.
228      * @param  device - own device
229      * @return ErrCode - operation result
230      */
231     virtual ErrCode QueryP2pLocalDevice(WifiP2pDevice &device) override;
232 
233     /**
234      * @Description - Obtain information about all groups.
235      * @param  groups - list of group information
236      * @return ErrCode - operation result
237      */
238     virtual ErrCode QueryP2pGroups(std::vector<WifiP2pGroupInfo> &groups) override;
239 
240     /**
241      * @Description - Query the information about the found services.
242      * @param  services - list of service information
243      * @return ErrCode - operation result
244      */
245     virtual ErrCode QueryP2pServices(std::vector<WifiP2pServiceInfo> &services) override;
246 
247     /**
248      * @Description - Register all callbacks provided by the P2P.
249      * @param  callbacks - all callbacks added
250      * @return ErrCode - operation result
251      */
252     virtual ErrCode RegisterP2pServiceCallbacks(const IP2pServiceCallbacks &callbacks) override;
253 
254     /**
255      * @Description - UnRegister all callbacks provided by the P2P.
256      * @param  callbacks - all callbacks added
257      * @return ErrCode - operation result
258      */
259     virtual ErrCode UnRegisterP2pServiceCallbacks(const IP2pServiceCallbacks &callbacks) override;
260 
261     /**
262      * @Description Create hid2d group, used on the GO side.
263      *
264      * @param frequency - frequency
265      * @param type - frequency type
266      * @return ErrCode - operation result
267      */
268     virtual ErrCode Hid2dCreateGroup(const int frequency, FreqType type) override;
269 
270     /**
271      * @Description Connect to a specified group using hid2d, used on the GC side.
272      *
273      * @param config - connection parameters
274      * @return ErrCode - operation result
275      */
276     virtual ErrCode Hid2dConnect(const Hid2dConnectConfig& config) override;
277 
278     /**
279      * @Description Set self config info
280      *
281      * @param gcMac - gc mac address
282      * @param ipAddr - allocated ip address
283      * @return ErrCode - operate result
284      */
285     virtual ErrCode Hid2dRequestGcIp(const std::string& gcMac, std::string& ipAddr) override;
286 
287     /**
288      * @Description Increase the reference count of the hid2d service.
289      *
290      * @param callingUid - the UID of caller
291      */
292     virtual void IncreaseSharedLink(int callingUid) override;
293 
294     /**
295      * @Description Decrease the reference count of the hid2d service.
296      *
297      * @param callingUid - the UID of caller
298      */
299     virtual void DecreaseSharedLink(int callingUid) override;
300 
301     /**
302      * @Description Handle the exception of upper-layer business.
303      *
304      * @param systemAbilityId - systemAbilityId of upper-layer business.
305      * @return ErrCode - operation result
306      */
307     virtual ErrCode HandleBusinessSAException(int systemAbilityId) override;
308 
309     /**
310      * @Description - Get P2P recommended channel.
311      *
312      * @return - int - Recommended channel
313      */
314     virtual int GetP2pRecommendChannel(void) override;
315 
316     /**
317      * @Description Set the scene of upper layer
318      *
319      * @param ifName - interface name
320      * @param scene - scene
321      * @return ErrCode - operate result
322      */
323     virtual ErrCode Hid2dSetUpperScene(const std::string& ifName, const Hid2dUpperScene& scene) override;
324 
325     /**
326      * @Description Monitor the wifi configuration change
327      *
328      * @return ErrCode - operate result
329      */
330     virtual ErrCode MonitorCfgChange(void)  override;
331 
332     virtual ErrCode DiscoverPeers(int32_t channelid) override;
333 
334     virtual ErrCode DisableRandomMac(int setmode) override;
335 
336     /**
337      * @Description Set gc ip infomation
338      *
339      * @return ErrCode - operate result
340      */
341     virtual ErrCode SetGcIpAddress(const IpAddrInfo& ipInfo) override;
342 
343     /**
344      * @Description Set EnhanceService to p2p service
345      *
346      * @param enhanceService IEnhanceService object
347      * @return success: WIFI_OPT_SUCCESS, failed: WIFI_OPT_FAILED
348      */
349     virtual ErrCode SetEnhanceService(IEnhanceService* enhanceService) override;
350 private:
351     WifiP2pGroupManager groupManager;    /* group manager */
352     WifiP2pDeviceManager deviceMgr;  /* device manager */
353     WifiP2pServiceManager svrMgr;
354 
355     AuthorizingNegotiationRequestState p2pAuthorizingNegotiationRequestState;
356     GroupFormedState p2pGroupFormedState;
357     GroupNegotiationState p2pGroupNegotiationState;
358     InvitationReceivedState p2pInvitationReceivedState;
359     InvitationRequestState p2pInvitationRequestState;
360     P2pDefaultState p2pDefaultState;
361     P2pDisabledState p2pDisabledState;
362     P2pDisablingState p2pDisablingState;
363     P2pEnabledState p2pEnabledState;
364     P2pEnablingState p2pEnablingState;
365     P2pGroupFormationState p2pGroupFormationState;
366     P2pGroupJoinState p2pGroupJoinState;
367     P2pGroupOperatingState p2pGroupOperatingState;
368     P2pIdleState p2pIdleState;
369     P2pInvitingState p2pInvitingState;
370     ProvisionDiscoveryState p2pProvisionDiscoveryState;
371     P2pGroupRemoveState p2pGroupRemoveState;
372 
373     P2pMonitor p2pMonitor;
374     P2pStateMachine p2pStateMachine;
375     WifiP2pService p2pService;
376 };
377 }  // namespace Wifi
378 }  // namespace OHOS
379 
380 #endif  // OHOS_P2P_INTERFACE_H
381