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_WIFI_P2P_H 17 #define OHOS_WIFI_P2P_H 18 19 #include "wifi_errcode.h" 20 #include "wifi_p2p_msg.h" 21 #include "i_wifi_p2p_callback.h" 22 23 namespace OHOS { 24 namespace Wifi { 25 class WifiP2p { 26 public: 27 static std::shared_ptr<WifiP2p> GetInstance(int system_ability_id); 28 29 virtual ~WifiP2p(); 30 31 /** 32 * @Description Enabling the P2P Mode. 33 * 34 * @return ErrCode - operation result 35 */ 36 virtual ErrCode EnableP2p(void) = 0; 37 38 /** 39 * @Description Disable the P2P mode. 40 * 41 * @return ErrCode - operation result 42 */ 43 virtual ErrCode DisableP2p(void) = 0; 44 45 /** 46 * @Description Start Wi-Fi P2P device search. 47 * 48 * @return ErrCode - operation result 49 */ 50 virtual ErrCode DiscoverDevices(void) = 0; 51 52 /** 53 * @Description Stop Wi-Fi P2P device search. 54 * 55 * @return ErrCode - operation result 56 */ 57 virtual ErrCode StopDiscoverDevices(void) = 0; 58 59 /** 60 * @Description Start the search for the Wi-Fi P2P service. 61 * 62 * @return ErrCode - operation result 63 */ 64 virtual ErrCode DiscoverServices(void) = 0; 65 66 /** 67 * @Description Stop the search for the Wi-Fi P2P service. 68 * 69 * @return ErrCode - operation result 70 */ 71 virtual ErrCode StopDiscoverServices(void) = 0; 72 73 /** 74 * @Description request the P2P service. 75 * 76 * @param device - WifiP2pDevice object 77 * @param request - WifiP2pServiceRequest object 78 * @return ErrCode - operation result 79 */ 80 virtual ErrCode RequestService(const WifiP2pDevice &device, const WifiP2pServiceRequest &request) = 0; 81 82 /** 83 * @Description Register the local P2P service. 84 * 85 * @param srvInfo - WifiP2pServiceInfo object 86 * @return ErrCode - operation result 87 */ 88 virtual ErrCode PutLocalP2pService(const WifiP2pServiceInfo &srvInfo) = 0; 89 90 /** 91 * @Description Delete the local P2P service. 92 * 93 * @param srvInfo - WifiP2pServiceInfo object 94 * @return ErrCode - operation result 95 */ 96 virtual ErrCode DeleteLocalP2pService(const WifiP2pServiceInfo &srvInfo) = 0; 97 98 /** 99 * @Description Enable Wi-Fi P2P listening. 100 * 101 * @param period - period 102 * @param interval - interval 103 * @return ErrCode - operation result 104 */ 105 virtual ErrCode StartP2pListen(int period, int interval) = 0; 106 107 /** 108 * @Description Disable Wi-Fi P2P listening. 109 * 110 * @return ErrCode - operation result 111 */ 112 virtual ErrCode StopP2pListen(void) = 0; 113 114 /** 115 * @Description Creating a P2P Group. 116 * 117 * @param config - WifiP2pConfig object 118 * @return ErrCode - operation result 119 */ 120 virtual ErrCode CreateGroup(const WifiP2pConfig &config) = 0; 121 122 /** 123 * @Description Remove a P2P Group. 124 * 125 * @return ErrCode - operation result 126 */ 127 virtual ErrCode RemoveGroup(void) = 0; 128 129 /** 130 * @Description Remove a P2P client of current group. 131 * 132 * @param deviceMac - client deviceMac address 133 * @return ErrCode - operation result 134 */ 135 virtual ErrCode RemoveGroupClient(const GcInfo &info) = 0; 136 137 /** 138 * @Description Delete a p2p Group. 139 * 140 * @param group - WifiP2pGroupInfo object 141 * @return ErrCode - operation result 142 */ 143 virtual ErrCode DeleteGroup(const WifiP2pGroupInfo &group) = 0; 144 145 /** 146 * @Description P2P connection. 147 * 148 * @param config - WifiP2pConfig object 149 * @return ErrCode - operation result 150 */ 151 virtual ErrCode P2pConnect(const WifiP2pConfig &config) = 0; 152 153 /** 154 * @Description Canceling a P2P connection. 155 * 156 * @return ErrCode - operation result 157 */ 158 virtual ErrCode P2pCancelConnect(void) = 0; 159 160 /** 161 * @Description Querying Wi-Fi P2P Connection Information. 162 * 163 * @param linkedInfo - Get the WifiP2pLinkedInfo msg 164 * @return ErrCode - operation result 165 */ 166 virtual ErrCode QueryP2pLinkedInfo(WifiP2pLinkedInfo &linkedInfo) = 0; 167 168 /** 169 * @Description Get the Current Group object. 170 * 171 * @param group - the WifiP2pGroupInfo object 172 * @return ErrCode - operation result 173 */ 174 virtual ErrCode GetCurrentGroup(WifiP2pGroupInfo &group) = 0; 175 176 /** 177 * @Description Obtains the P2P switch status. 178 * 179 * @param status - the P2P switch status 180 * @return ErrCode - operation result 181 */ 182 virtual ErrCode GetP2pEnableStatus(int &status) = 0; 183 184 /** 185 * @Description Obtains the P2P discovery status. 186 * 187 * @param status - the P2P discovery status 188 * @return ErrCode - operation result 189 */ 190 virtual ErrCode GetP2pDiscoverStatus(int &status) = 0; 191 192 /** 193 * @Description Obtains the P2P connection status. 194 * 195 * @param status - the P2P connection status 196 * @return ErrCode - operation result 197 */ 198 virtual ErrCode GetP2pConnectedStatus(int &status) = 0; 199 200 /** 201 * @Description Query the local device information. 202 * 203 * @param devives - Get result of WifiP2pDevice 204 * @return ErrCode - operation result 205 */ 206 virtual ErrCode QueryP2pLocalDevice(WifiP2pDevice &device) = 0; 207 208 /** 209 * @Description Query the information about the found devices. 210 * 211 * @param devices - Get result vector of WifiP2pDevice 212 * @return ErrCode - operation result 213 */ 214 virtual ErrCode QueryP2pDevices(std::vector<WifiP2pDevice> &devices) = 0; 215 216 /** 217 * @Description Query the information about the found groups. 218 * 219 * @param groups - Get result vector of WifiP2pGroupInfo 220 * @return ErrCode - operation result 221 */ 222 virtual ErrCode QueryP2pGroups(std::vector<WifiP2pGroupInfo> &groups) = 0; 223 224 /** 225 * @Description Query the service information. 226 * 227 * @param services - Get result vector of Device 228 * @return ErrCode - operation result 229 */ 230 virtual ErrCode QueryP2pServices(std::vector<WifiP2pServiceInfo> &services) = 0; 231 232 /** 233 * @Description Register callback function. 234 * 235 * @param callback - IWifiP2pCallback object 236 * @return ErrCode - operation result 237 */ 238 virtual ErrCode RegisterCallBack(const sptr<IWifiP2pCallback> &callback, const std::vector<std::string> &event) = 0; 239 240 /** 241 * @Description Get supported features 242 * 243 * @param features - return supported features 244 * @return ErrCode - operation result 245 */ 246 virtual ErrCode GetSupportedFeatures(long &features) = 0; 247 248 /** 249 * @Description Check if supported input feature 250 * 251 * @param feature - input feature 252 * @return bool - true if supported, false if unsupported 253 */ 254 virtual bool IsFeatureSupported(long feature) = 0; 255 256 /** 257 * @Description set the device name 258 * 259 * @param deviceName - device name 260 * @return ErrCode - operation result 261 */ 262 virtual ErrCode SetP2pDeviceName(const std::string &deviceName) = 0; 263 264 /** 265 * @Description set p2p wifi display info 266 * 267 * @param wfdInfo - wifi display info 268 * @return ErrCode - operation result 269 */ 270 virtual ErrCode SetP2pWfdInfo(const WifiP2pWfdInfo &wfdInfo) = 0; 271 272 /** 273 * @Description set p2p wifi display info 274 * 275 * @param wfdInfo - wifi display info 276 * @return ErrCode - operation result 277 */ 278 virtual ErrCode DiscoverPeers(int32_t channelid) = 0; 279 280 /** 281 * @Description set p2p wifi display info 282 * 283 * @param wfdInfo - wifi display info 284 * @return ErrCode - operation result 285 */ 286 virtual ErrCode DisableRandomMac(int setmode) = 0; 287 288 /** 289 * @Description Check can use P2P 290 * 291 * @return ErrCode - operation result 292 */ 293 virtual ErrCode CheckCanUseP2p() = 0; 294 }; 295 } // namespace Wifi 296 } // namespace OHOS 297 #endif