1 /* 2 * Copyright (C) 2021 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_STA_SERVICE_H 17 #define OHOS_WIFI_STA_SERVICE_H 18 19 #include "sta_define.h" 20 #include "wifi_errcode.h" 21 #ifndef OHOS_ARCH_LITE 22 #include "app_state_data.h" 23 #include "ienhance_service.h" 24 #endif 25 #include "wifi_msg.h" 26 #include "sta_service_callback.h" 27 #include "network_selection.h" 28 29 namespace OHOS { 30 namespace Wifi { 31 class IStaService { 32 public: 33 virtual ~IStaService() = default; 34 /** 35 * @Description Enable wifi 36 * 37 * @Output: Return operating results to Interface Service after enable wifi 38 successfully through callback function instead of returning 39 result immediately. 40 * @Return success: WIFI_OPT_SUCCESS fail: WIFI_OPT_FAILED 41 */ 42 virtual ErrCode EnableStaService() = 0; 43 /** 44 * @Description Disable wifi 45 * 46 * @Output: Return operating results to Interface Service after enable wifi 47 successfully through callback function instead of returning 48 result immediately. 49 * @Return success: WIFI_OPT_SUCCESS fail: WIFI_OPT_FAILED 50 */ 51 virtual ErrCode DisableStaService() = 0; 52 /** 53 * @Description Connect to a new network 54 * 55 * @param config - the configuration of network which is going to connect.(in) 56 * @Output: Return operating results to Interface Service after enable wifi 57 successfully through callback function instead of returning 58 result immediately. 59 * @Return success: WIFI_OPT_SUCCESS fail: WIFI_OPT_FAILED 60 */ 61 virtual ErrCode ConnectToDevice(const WifiDeviceConfig &config) = 0; 62 /** 63 * @Description Connecting to a specified network. 64 * 65 * @param networkId - interior saved network index.(in) 66 * @param type - select network type: SelectedType 67 * @Output: Return operating results to Interface Service after enable wifi 68 successfully through callback function instead of returning 69 result immediately. 70 * @Return success: WIFI_OPT_SUCCESS fail: WIFI_OPT_FAILED 71 */ 72 virtual ErrCode ConnectToNetwork(int networkId, int type = NETWORK_SELECTED_BY_USER) = 0; 73 74 /** 75 * @Description roam to target bssid 76 * 77 * @param networkId - target networkId 78 * @param bssid - target bssid 79 * @return ErrCode - operation result 80 */ 81 virtual ErrCode StartRoamToNetwork(const int networkId, const std::string bssid) = 0; 82 83 /** 84 * @Description connect to user select ssid and bssid network 85 * 86 * @param networkId - target networkId 87 * @param bssid - target bssid 88 * @return ErrCode - operation result 89 */ 90 virtual ErrCode StartConnectToUserSelectNetwork(int networkId, std::string bssid) = 0; 91 92 /** 93 * @Description Disconnect to the network 94 * 95 * @Output: Return operating results to Interface Service after enable wifi 96 successfully through callback function instead of returning 97 result immediately. 98 * @Return success: WIFI_OPT_SUCCESS fail: WIFI_OPT_FAILED 99 */ 100 virtual ErrCode Disconnect() = 0; 101 /** 102 * @Description ReConnect network 103 * 104 * @Return success: WIFI_OPT_SUCCESS fail: WIFI_OPT_FAILED 105 */ 106 virtual ErrCode ReConnect() = 0; 107 /** 108 * @Description ReAssociate network 109 * 110 * @Return success: WIFI_OPT_SUCCESS fail: WIFI_OPT_FAILED 111 */ 112 virtual ErrCode ReAssociate() = 0; 113 114 /** 115 * @Description Add a specified candidate hotspot configuration. 116 * 117 * @param uid - call app uid 118 * @param config - WifiDeviceConfig object 119 * @param netWorkId - the network id of the hotspot configuration.(out) 120 * @Return success: WIFI_OPT_SUCCESS fail: WIFI_OPT_FAILED 121 */ 122 virtual ErrCode AddCandidateConfig(const int uid, const WifiDeviceConfig &config, int& netWorkId) = 0; 123 124 /** 125 * @Description Connect to a candidate specified network. 126 * 127 * @param uid - call app uid 128 * @param networkId - the candidate device network id 129 * @Return ErrCode - operation result 130 */ 131 virtual ErrCode ConnectToCandidateConfig(const int uid, const int networkId) = 0; 132 133 /** 134 * @Description Remove the wifi candidate device config equals to input network id 135 * 136 * @param uid - call app uid 137 * @param networkId - the candidate device network id 138 * @return ErrCode - operation result 139 */ 140 virtual ErrCode RemoveCandidateConfig(const int uid, const int networkId) = 0; 141 142 /** 143 * @Description Remove all the wifi candidate device config equals to input uid 144 * 145 * @param uid - call app uid 146 * @return ErrCode - operation result 147 */ 148 virtual ErrCode RemoveAllCandidateConfig(const int uid) = 0; 149 150 /** 151 * @Description Add a network to config 152 * 153 * @param config -The Network info(in) 154 * @Return success: WIFI_OPT_SUCCESS fail: WIFI_OPT_FAILED 155 */ 156 virtual int AddDeviceConfig(const WifiDeviceConfig &config) = 0; 157 /** 158 * @Description Update a network to config 159 * 160 * @param config -The Network info(in) 161 * @Return success: networkId fail: -1 162 */ 163 virtual int UpdateDeviceConfig(const WifiDeviceConfig &config) = 0; 164 /** 165 * @Description Remove network 166 * 167 * @param networkId -The NetworkId is going to be removed.(in) 168 * @Return success: WIFI_OPT_SUCCESS fail: WIFI_OPT_FAILED 169 */ 170 virtual ErrCode RemoveDevice(int networkId) = 0; 171 /** 172 * @Description Remove all network configs 173 * 174 * @Return success: WIFI_OPT_SUCCESS fail: WIFI_OPT_FAILED 175 */ 176 virtual ErrCode RemoveAllDevice() = 0; 177 /** 178 * @Description Enable WI-FI device configuration 179 * 180 * @param networkId - The NetworkId (in) 181 * @param networkId - if set true, disable other device configuration (in) 182 * @Return success: WIFI_OPT_SUCCESS fail: WIFI_OPT_FAILED 183 */ 184 virtual ErrCode EnableDeviceConfig(int networkId, bool attemptEnable) = 0; 185 /** 186 * @Description Disable WI-FI device configuration 187 * 188 * @param networkId - device configuration's network id 189 * @return ErrCode - success: WIFI_OPT_SUCCESS fail: WIFI_OPT_FAILED 190 */ 191 virtual ErrCode DisableDeviceConfig(int networkId) = 0; 192 /** 193 * @Description Start WPS Connection 194 * 195 * @Output: Return operating results to Interface Service after enable wifi 196 successfully through callback function instead of returning 197 result immediately. 198 * @Return success: WIFI_OPT_SUCCESS fail: WIFI_OPT_FAILED 199 */ 200 virtual ErrCode StartWps(const WpsConfig &config) = 0; 201 /** 202 * @Description Close WPS Connection 203 * 204 * @Output: Return operating results to Interface Service after enable wifi 205 successfully through callback function instead of returning 206 result immediately. 207 * @Return success: WIFI_OPT_SUCCESS fail: WIFI_OPT_FAILED 208 */ 209 virtual ErrCode CancelWps() = 0; 210 211 /** 212 * @Description ConnectivityManager process scan results. 213 * 214 * @Output: Return operating results to Interface Service after enable wifi 215 successfully through callback function instead of returning 216 result immediately. 217 * @Return success: WIFI_OPT_SUCCESS fail: WIFI_OPT_FAILED 218 */ 219 virtual ErrCode ConnectivityManager(const std::vector<InterScanInfo> &scanInfos) = 0; 220 /** 221 * @Description Register sta callback function 222 * 223 * @param callbacks - Callback function pointer storage structure 224 * @return ErrCode - success: WIFI_OPT_SUCCESS fail: WIFI_OPT_FAILED 225 */ 226 virtual ErrCode RegisterStaServiceCallback(const StaServiceCallback &callbacks) = 0; 227 228 /** 229 * @Description UnRegister sta callback function 230 * 231 * @param callbacks - Callback function pointer storage structure 232 * @return ErrCode - success: WIFI_OPT_SUCCESS fail: WIFI_OPT_FAILED 233 */ 234 virtual ErrCode UnRegisterStaServiceCallback(const StaServiceCallback &callbacks) = 0; 235 236 /** 237 * @Description send suspend mode for wpa. 238 * 239 * @param mode: true for suspend, false for resume. 240 * @return WifiErrorNo 241 */ 242 virtual ErrCode SetSuspendMode(bool mode) = 0; 243 244 /** 245 * @Description send power mode for wpa. 246 * 247 * @param mode: true for power, false for resume. 248 * @return WifiErrorNo 249 */ 250 virtual ErrCode SetPowerMode(bool mode) = 0; 251 252 /** 253 * @Description systemabilitychanged 254 * 255 * @param mode: true for setup, false for shutdown. 256 * @return WifiErrorNo 257 */ 258 virtual ErrCode OnSystemAbilityChanged(int systemAbilityid, bool add) = 0; 259 /** 260 * @Description Processes interface service screen change request. 261 * 262 * @param screenState screen state[in] 263 * @return success: WIFI_OPT_SUCCESS, failed: WIFI_OPT_FAILED 264 */ 265 virtual ErrCode OnScreenStateChanged(int screenState) = 0; 266 267 /** 268 * @Description disable auto join. 269 * 270 * @param conditionName autoJoinDisabled condition. 271 * @return WifiErrorNo 272 */ 273 virtual ErrCode DisableAutoJoin(const std::string &conditionName) = 0; 274 275 /** 276 * @Description enable auto join. 277 * 278 * @param conditionName autoJoinDisabled condition. 279 * @return WifiErrorNo 280 */ 281 virtual ErrCode EnableAutoJoin(const std::string &conditionName) = 0; 282 283 /** 284 * @Description register auto join condition. 285 * 286 * @param conditionName the name of condition. 287 * @param autoJoinCondition condition. 288 * @return WifiErrorNo 289 */ 290 virtual ErrCode RegisterAutoJoinCondition(const std::string &conditionName, 291 const std::function<bool()> &autoJoinCondition) = 0; 292 293 /** 294 * @Description deregister auto join condition. 295 * 296 * @param conditionName the name of condition. 297 * @return WifiErrorNo 298 */ 299 virtual ErrCode DeregisterAutoJoinCondition(const std::string &conditionName) = 0; 300 301 /** 302 * @Description register external filter builder. 303 * 304 * @param filterTag filterTag which define where the filter should be inserted. 305 * @param filterName the name of the filter to build. 306 * @param filterBuilder filter builder. 307 * @return WifiErrorNo 308 */ 309 virtual ErrCode RegisterFilterBuilder(const FilterTag &filterTag, const std::string &filterName, 310 const FilterBuilder &filterBuilder) = 0; 311 312 /** 313 * @Description deregister external filter builder. 314 * 315 * @param filterTag filterTag which define where the filter should be inserted. 316 * @param filterName the name of the filter to build. 317 * @return WifiErrorNo 318 */ 319 virtual ErrCode DeregisterFilterBuilder(const FilterTag &filterTag, const std::string &filterName) = 0; 320 321 /** 322 * Register the common builder function 323 * 324 * @param TagType scoreTag which define where the score or filter should be inserted. 325 * @param tagName the score or filter name. 326 * @param CommonBuilder CommonBuilder function. 327 */ 328 virtual ErrCode RegisterCommonBuilder(const TagType &tagType, const std::string &tagName, 329 const CommonBuilder &commonBuilder) = 0; 330 331 /** 332 * Deregister the common builder function 333 * 334 * @param TagType TagType which define where the score or filter should be inserted. 335 * @param tagName the score or filte name. 336 */ 337 virtual ErrCode DeregisterCommonBuilder(const TagType &tagType, const std::string &tagName) = 0; 338 339 /** 340 * @Description start portal certification. 341 * 342 * @return success: WIFI_OPT_SUCCESS, failed: WIFI_OPT_FAILED 343 */ 344 virtual ErrCode StartPortalCertification() = 0; 345 346 /** 347 * @Description Handle foreground app changed action. 348 * 349 * @param bundleName app name. 350 * @param uid app uid. 351 * @param pid app pid. 352 * @param state app state. 353 * @return success: WIFI_OPT_SUCCESS, failed: WIFI_OPT_FAILED 354 */ 355 #ifndef OHOS_ARCH_LITE 356 virtual ErrCode HandleForegroundAppChangedAction(const AppExecFwk::AppStateData &appStateData) = 0; 357 358 /** 359 * @Description Set EnhanceService to sta Service. 360 * 361 * @param enhanceService IEnhanceService object 362 * @return success: WIFI_OPT_SUCCESS, failed: WIFI_OPT_FAILED 363 */ 364 virtual ErrCode SetEnhanceService(IEnhanceService *enhanceService) = 0; 365 #endif 366 /** 367 * @Description enable hilink 368 * 369 * @return success: WIFI_OPT_SUCCESS, failed: WIFI_OPT_FAILED 370 */ 371 virtual ErrCode EnableHiLinkHandshake(const WifiDeviceConfig &config, const std::string &bssid) = 0; 372 373 /** 374 * @Description deliver mac 375 * 376 * @return success: WIFI_OPT_SUCCESS, failed: WIFI_OPT_FAILED 377 */ 378 virtual ErrCode DeliverStaIfaceData(const std::string ¤tMac) = 0; 379 }; 380 } // namespace Wifi 381 } // namespace OHOS 382 #endif