1 /*
2  * Copyright (C) 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_C_P2P_H
17 #define OHOS_C_P2P_H
18 
19 #include<stdint.h>
20 #include "wifi_error_code.h"
21 #include "wifi_p2p_config.h"
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 typedef void (*P2pStateChangedCallback)(P2pState state);
28 typedef void (*P2pPersistentGroupsChangedCallback)(void);
29 typedef void (*P2pConnectionChangedCallback)(const WifiP2pLinkedInfo info);
30 typedef void (*P2pPeersChangedCallback)(WifiP2pDevice* devices, int len);
31 typedef void (*P2pPrivatePeersChangedCallback)(char* priWfdInfo);
32 
33 /**
34  * @Description Enabling the P2P Mode.
35  *
36  * @return WifiErrorCode - operation result
37  */
38 WifiErrorCode EnableP2p();
39 
40 /**
41  * @Description Disable the P2P mode.
42  *
43  * @return WifiErrorCode - operation result
44  */
45 WifiErrorCode DisableP2p();
46 
47 /**
48  * @Description Get p2p enable status
49  *
50  * @param state - enable status
51  * @return WifiErrorCode - operation result
52  */
53 WifiErrorCode GetP2pEnableStatus(P2pState* state);
54 
55 /**
56  * @Description Start Wi-Fi P2P device search.
57  *
58  * @return WifiErrorCode - operation result
59  */
60 WifiErrorCode DiscoverDevices();
61 
62 /**
63  * @Description Stop Wi-Fi P2P device search.
64  *
65  * @return WifiErrorCode - operation result
66  */
67 WifiErrorCode StopDiscoverDevices();
68 
69 /**
70  * @Description Start the search for the Wi-Fi P2P service.
71  *
72  * @return WifiErrorCode - operation result
73  */
74 WifiErrorCode DiscoverServices();
75 
76 /**
77  * @Description Stop the search for the Wi-Fi P2P service.
78  *
79  * @return WifiErrorCode - operation result
80  */
81 WifiErrorCode StopDiscoverServices();
82 
83 /**
84  * @Description Enable Wi-Fi P2P listening.
85  *
86  * @param period - period
87  * @param interval - interval
88  * @return WifiErrorCode - operation result
89  */
90 WifiErrorCode StartP2pListen(int period, int interval);
91 
92 /**
93  * @Description Disable Wi-Fi P2P listening.
94  *
95  * @return ErrCode - operation result
96  */
97 WifiErrorCode StopP2pListen();
98 
99 /**
100  * @Description Creating a P2P Group.
101  *
102  * @param config - WifiP2pConfig object
103  * @return WifiErrorCode - operation result
104  */
105 WifiErrorCode CreateGroup(const WifiP2pConfig* config);
106 
107 /**
108  * @Description Remove a P2P Group.
109  *
110  * @return WifiErrorCode - operation result
111  */
112 WifiErrorCode RemoveGroup();
113 
114 /**
115  * @Description Delete a p2p Group.
116  *
117  * @param group - WifiP2pGroupInfo object
118  * @return ErrCode - operation result
119  */
120 WifiErrorCode DeleteGroup(const WifiP2pGroupInfo* group);
121 
122 /**
123  * @Description P2P connection.
124  *
125  * @param config - WifiP2pConfig object
126  * @return WifiErrorCode - operation result
127  */
128 WifiErrorCode P2pConnect(const WifiP2pConfig* config);
129 
130 /**
131  * @Description Cancel a P2P connection.
132  *
133  * @return WifiErrorCode - operation result
134  */
135 WifiErrorCode P2pCancelConnect();
136 
137 /**
138  * @Description Get the Current Group object.
139  *
140  * @param groupInfo - the WifiP2pGroupInfo object
141  * @return WifiErrorCode - operation result
142  */
143 WifiErrorCode GetCurrentGroup(WifiP2pGroupInfo* groupInfo);
144 
145 /**
146  * @Description Obtains the P2P connection status.
147  *
148  * @param status - the P2P connection status
149  * @return WifiErrorCode - operation result
150  */
151 WifiErrorCode GetP2pConnectedStatus(int* status);
152 
153 /**
154  * @Description Query the information about the found devices.
155  *
156  * @param clientDevices - pre-allocate memory for client devices
157  * @param size - the allocate size for clientDevices
158  * @param retSize - the queryed size of the client devices, used for return.
159  * @return WifiErrorCode - operation result
160  */
161 WifiErrorCode QueryP2pDevices(WifiP2pDevice* clientDevices, int size, int* retSize);
162 
163 /**
164  * @Description Query the information about the local device info.
165  *
166  * @param deviceInfo - the WifiP2pDevice object
167  * @return ErrCode - operation result
168  */
169 WifiErrorCode QueryP2pLocalDevice(WifiP2pDevice* deviceInfo);
170 
171 /**
172  * @Description Query the information about the found groups.
173  *
174  * @param groupInfo - pre-allocate memory for group size
175  * @param size - the allocate size for groupInfo
176  * @return ErrCode - operation result
177  */
178 WifiErrorCode QueryP2pGroups(WifiP2pGroupInfo* groupInfo, int size);
179 
180 /**
181  * @Description register p2p state changed event
182  *
183  * @param callback - callback function
184  * @return ErrCode - operation result
185  */
186 WifiErrorCode RegisterP2pStateChangedCallback(const P2pStateChangedCallback callback);
187 
188 /**
189  * @Description register p2p persistent group change event
190  *
191  * @param callback - callback function
192  * @return ErrCode - operation result
193  */
194 WifiErrorCode RegisterP2pPersistentGroupsChangedCallback(const P2pPersistentGroupsChangedCallback callback);
195 
196 /**
197  * @Description register p2p connection change event
198  *
199  * @param callback - callback function
200  * @return ErrCode - operation result
201  */
202 WifiErrorCode RegisterP2pConnectionChangedCallback(const P2pConnectionChangedCallback callback);
203 
204 /**
205  * @Description register p2p peers change event
206  *
207  * @param callback - callback function
208  * @return ErrCode - operation result
209  */
210 WifiErrorCode RegisterP2pPeersChangedCallback(const P2pPeersChangedCallback callback);
211 
212 /**
213  * @Description register p2p peers change event
214  *
215  * @param callback - callback function
216  * @return ErrCode - operation result
217  */
218 WifiErrorCode RegisterP2pPrivatePeersChangedCallback(const P2pPrivatePeersChangedCallback callback);
219 
220 /**
221  * @Description Remove a P2P Group.
222  *
223  * @return WifiErrorCode - operation result
224  */
225 WifiErrorCode DiscoverPeers(int32_t channelid);
226 
227 /**
228  * @Description Remove a P2P Group.
229  *
230  * @return WifiErrorCode - operation result
231  */
232 WifiErrorCode DisableRandomMac(int setmode);
233 
234 /**
235  * @Description Check can use P2P
236  *
237  * @return WifiErrorCode - operation result
238  */
239 WifiErrorCode CheckCanUseP2p();
240 
241 #ifdef __cplusplus
242 }
243 #endif
244 
245 #endif
246