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