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