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