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_IP2P_SERVICE_H 17 #define OHOS_IP2P_SERVICE_H 18 19 #include "wifi_errcode.h" 20 #include "wifi_msg.h" 21 #include "ip2p_service_callbacks.h" 22 #include "wifi_hid2d_msg.h" 23 #include "wifi_ap_msg.h" 24 #include "ienhance_service.h" 25 26 namespace OHOS { 27 namespace Wifi { 28 class IP2pService { 29 public: 30 /** 31 * @Description Destroy the IP2pService object. 32 */ 33 virtual ~IP2pService() = default; 34 35 /** 36 * @Description - The interface of enable p2p. 37 * @return ErrCode - operation result 38 */ 39 virtual ErrCode EnableP2p() = 0; 40 41 /** 42 * @Description - The interface of disable p2p. 43 * @return ErrCode - operation result 44 */ 45 virtual ErrCode DisableP2p() = 0; 46 47 /** 48 * @Description - The interface of start discover peers. 49 * @return ErrCode - operation result 50 */ 51 virtual ErrCode DiscoverDevices() = 0; 52 53 /** 54 * @Description - The interface of stop discover peers. 55 * @return ErrCode - operation result 56 */ 57 virtual ErrCode StopDiscoverDevices() = 0; 58 59 /** 60 * @Description - The interface of start discover services. 61 * @return ErrCode - operation result 62 */ 63 virtual ErrCode DiscoverServices() = 0; 64 65 /** 66 * @Description - The interface of stop discover services. 67 * @return ErrCode - operation result 68 */ 69 virtual ErrCode StopDiscoverServices() = 0; 70 71 /** 72 * @Description - The interface of add local p2p service. 73 * @param srvInfo - information of service. 74 * @return ErrCode - operation result 75 */ 76 virtual ErrCode PutLocalP2pService(const WifiP2pServiceInfo &srvInfo) = 0; 77 78 /** 79 * @Description - The interface of delete local p2p service. 80 * @param srvInfo - information of service. 81 * @return ErrCode - operation result 82 */ 83 virtual ErrCode DeleteLocalP2pService(const WifiP2pServiceInfo &srvInfo) = 0; 84 85 /** 86 * @Description - The interface of add service request. 87 * @param device - target device information. 88 * @param request - request information. 89 * @return ErrCode - operation result 90 */ 91 virtual ErrCode RequestService(const WifiP2pDevice &device, const WifiP2pServiceRequest &request) = 0; 92 93 /** 94 * @Description - The interface of start p2p listen(milliseconds). 95 * @param period - time of period. 96 * @param interval - time of interval. 97 * @return ErrCode - operation result 98 */ 99 virtual ErrCode StartP2pListen(int period, int interval) = 0; 100 101 /** 102 * @Description - The interface of stop p2p listen. 103 * @return ErrCode - operation result 104 */ 105 virtual ErrCode StopP2pListen() = 0; 106 107 /** 108 * @DescriptionCreate - The interface of create group. 109 * @param config - configure of group. 110 * @return ErrCode - operation result 111 */ 112 virtual ErrCode CreateGroup(const WifiP2pConfig &config) = 0; 113 114 /** 115 * @Description - The interface of remove current group. 116 * @return ErrCode - operation result 117 */ 118 virtual ErrCode RemoveGroup() = 0; 119 120 /** 121 * @Description Remove a P2P client of current group. 122 * 123 * @param deviceMac - client deviceMac address 124 * @return ErrCode - operation result 125 */ 126 virtual ErrCode RemoveGroupClient(const GcInfo &info) = 0; 127 128 /** 129 * @Description - The interface of delete a saved group. 130 * @param group - information of group. 131 * @return ErrCode - operation result 132 */ 133 virtual ErrCode DeleteGroup(const WifiP2pGroupInfo &group) = 0; 134 135 /** 136 * @Description - The interface of p2p connect. 137 * @param config - configure of connect. 138 * @return ErrCode - operation result 139 */ 140 virtual ErrCode P2pConnect(const WifiP2pConfig &config) = 0; 141 142 /** 143 * @Description - The interface of canceling a p2p connection. 144 * @return ErrCode - operation result 145 */ 146 virtual ErrCode P2pCancelConnect() = 0; 147 /** 148 * @Description - Set this device name. 149 * 150 * @param devName - specified device name 151 * @return ErrCode 152 */ 153 virtual ErrCode SetP2pDeviceName(const std::string &devName) = 0; 154 /** 155 * @Description - The interface of query p2p information like the group state,device information and ip address. 156 * @param linkedInfo - struct WifiP2pLinkedInfo. 157 * @return ErrCode - operation result 158 */ 159 virtual ErrCode QueryP2pLinkedInfo(WifiP2pLinkedInfo &linkedInfo) = 0; 160 161 /** 162 * @DescriptionGet - The interface of get current group information. 163 * @param group - struct WifiP2pGroupInfo. 164 * @return ErrCode - operation result 165 */ 166 virtual ErrCode GetCurrentGroup(WifiP2pGroupInfo &group) = 0; 167 168 /** 169 * @Description - The interface of get p2p running status. 170 * @param status - information of status. 171 * @return ErrCode - operation result 172 */ 173 virtual ErrCode GetP2pEnableStatus(int &status) = 0; 174 175 /** 176 * @Description - The interface of get p2p discover status. 177 * @param status - information of status. 178 * @return ErrCode - operation result 179 */ 180 virtual ErrCode GetP2pDiscoverStatus(int &status) = 0; 181 182 /** 183 * @Description - The interface of get p2p connected status. 184 * @param status - information of status. 185 * @return ErrCode - operation result 186 */ 187 virtual ErrCode GetP2pConnectedStatus(int &status) = 0; 188 189 /** 190 * @Description - The interface of query p2p devices information. 191 * @param devices - information of devices. 192 * @return ErrCode - operation result 193 */ 194 virtual ErrCode QueryP2pDevices(std::vector<WifiP2pDevice> &devices) = 0; 195 196 /** 197 * @Description - Query the information about own device. 198 * @param device - own device 199 * @return ErrCode - operation result 200 */ 201 virtual ErrCode QueryP2pLocalDevice(WifiP2pDevice &device) = 0; 202 203 /** 204 * @Description - The interface of query p2p group information. 205 * @param groups - information of groups. 206 * @return ErrCode - operation result 207 */ 208 virtual ErrCode QueryP2pGroups(std::vector<WifiP2pGroupInfo> &groups) = 0; 209 210 /** 211 * @Description - The interface of query p2p services information. 212 * @param services - information of services. 213 * @return ErrCode - operation result 214 */ 215 virtual ErrCode QueryP2pServices(std::vector<WifiP2pServiceInfo> &services) = 0; 216 217 /** 218 * @Description - The interface of register p2p service callbacks, 219 * @param callbacks - information of callbacks. 220 * @return ErrCode - operation result 221 */ 222 virtual ErrCode RegisterP2pServiceCallbacks(const IP2pServiceCallbacks &callbacks) = 0; 223 224 /** 225 * @Description - The interface of unregister p2p service callbacks, 226 * @param callbacks - information of callbacks. 227 * @return ErrCode - operation result 228 */ 229 virtual ErrCode UnRegisterP2pServiceCallbacks(const IP2pServiceCallbacks &callbacks) = 0; 230 231 /** 232 * @Description set p2p wifi display info 233 * 234 * @param wfdInfo - wifi display info 235 * @return ErrCode - operation result 236 */ 237 virtual ErrCode SetP2pWfdInfo(const WifiP2pWfdInfo &wfdInfo) = 0; 238 239 /** 240 * @Description Create hid2d group, used on the GO side. 241 * 242 * @param frequency - frequency 243 * @param type - frequency type 244 * @return ErrCode - operation result 245 */ 246 virtual ErrCode Hid2dCreateGroup(const int frequency, FreqType type) = 0; 247 248 /** 249 * @Description Connect to a specified group using hid2d, used on the GC side. 250 * 251 * @param config - connection parameters 252 * @return ErrCode - operation result 253 */ 254 virtual ErrCode Hid2dConnect(const Hid2dConnectConfig& config) = 0; 255 256 /** 257 * @Description Set self config info 258 * 259 * @param gcMac - gc mac address 260 * @param ipAddr - allocated ip address 261 * @return ErrCode - operate result 262 */ 263 virtual ErrCode Hid2dRequestGcIp(const std::string& gcMac, std::string& ipAddr) = 0; 264 265 /** 266 * @Description Increase the reference count of the hid2d service. 267 * 268 * @param callingUid - the UID of caller 269 */ 270 virtual void IncreaseSharedLink(int callingUid) = 0; 271 272 /** 273 * @Description Decrease the reference count of the hid2d service. 274 * 275 * @param callingUid - the UID of caller 276 */ 277 virtual void DecreaseSharedLink(int callingUid) = 0; 278 279 /** 280 * @Description Handle the exception of upper-layer business. 281 * 282 * @param systemAbilityId - systemAbilityId of upper-layer business. 283 * @return ErrCode - operation result 284 */ 285 virtual ErrCode HandleBusinessSAException(int systemAbilityId) = 0; 286 287 /** 288 * @Description - Get P2P recommended channel. 289 * 290 * @return - int - Recommended channel 291 */ 292 virtual int GetP2pRecommendChannel(void) = 0; 293 294 /** 295 * @Description Set the scene of upper layer 296 * 297 * @param ifName - interface name 298 * @param scene - scene 299 * @return ErrCode - operate result 300 */ 301 virtual ErrCode Hid2dSetUpperScene(const std::string& ifName, const Hid2dUpperScene& scene) = 0; 302 303 /** 304 * @Description Monitor the wifi configuration change 305 * 306 * @return ErrCode - operate result 307 */ 308 virtual ErrCode MonitorCfgChange(void) = 0; 309 310 /** 311 * @Description Remove a P2P Group. 312 * 313 * @return ErrCode - operation result 314 */ 315 virtual ErrCode DiscoverPeers(int32_t channelid) = 0; 316 317 /** 318 * @Description Remove a P2P Group. 319 * 320 * @return ErrCode - operation result 321 */ 322 virtual ErrCode DisableRandomMac(int setmode) = 0; 323 324 /** 325 * @Description Set gc ip infomation 326 * 327 * @return ErrCode - operate result 328 */ 329 virtual ErrCode SetGcIpAddress(const IpAddrInfo& ipInfo) = 0; 330 331 /** 332 * @Description create rpt group 333 * 334 * @return ErrCode - operate result 335 */ 336 virtual ErrCode CreateRptGroup(const WifiP2pConfig &config) = 0; 337 338 /** 339 * @Description get station list of rpt 340 * 341 * @return ErrCode - operate result 342 */ 343 virtual ErrCode GetRptStationsList(std::vector<StationInfo> &result) = 0; 344 345 /** 346 * @Description Set EnhanceService to p2p service 347 * 348 * @param enhanceService IEnhanceService object 349 * @return success: WIFI_OPT_SUCCESS, failed: WIFI_OPT_FAILED 350 */ 351 virtual ErrCode SetEnhanceService(IEnhanceService* enhanceService) = 0; 352 353 /** 354 * @Description Notify user accept result to p2p service 355 * 356 * @param isAccept if user accept to projection screen 357 * @return success: WIFI_OPT_SUCCESS, failed: WIFI_OPT_FAILED 358 */ 359 virtual void NotifyWscDialogConfirmResult(bool isAccept) = 0; 360 361 /** 362 * @Description Set miracast sink config 363 * 364 * @param config - miracast config 365 * @return success: WIFI_OPT_SUCCESS, failed: WIFI_OPT_FAILED 366 */ 367 virtual ErrCode SetMiracastSinkConfig(const std::string& config) = 0; 368 369 /** 370 * @Description notify remote die for remove p2p group 371 * 372 * @param uid - remote's uid 373 * @return success: WIFI_OPT_SUCCESS, failed: WIFI_OPT_FAILED 374 */ 375 virtual ErrCode NotifyRemoteDie(int uid) = 0; 376 377 /** 378 * @Description Set p2p high perf mode 379 * 380 * @param isEnable - enable high perf mode or not 381 * @return success: WIFI_OPT_SUCCESS, failed: WIFI_OPT_FAILED 382 */ 383 virtual ErrCode SetP2pHighPerf(bool isEnable) = 0; 384 }; 385 } // namespace Wifi 386 } // namespace OHOS 387 388 #endif // OHOS_IP2P_SERVICE_H 389