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 #ifndef OHOS_WIFI_DEVICE_H 16 #define OHOS_WIFI_DEVICE_H 17 18 #include <set> 19 #include "i_wifi_device_callback.h" 20 #include "wifi_errcode.h" 21 #include "wifi_msg.h" 22 #include "network_selection.h" 23 24 namespace OHOS { 25 namespace Wifi { 26 class WifiDevice { 27 public: 28 static std::shared_ptr<WifiDevice> GetInstance(int systemAbilityId, int instId = 0); 29 30 virtual ~WifiDevice(); 31 32 /** 33 * @Description Turn on Wi-Fi. 34 * 35 * @return ErrCode - operation result 36 */ 37 virtual ErrCode EnableWifi() = 0; 38 39 /** 40 * @Description Turn off Wi-Fi. 41 * 42 * @return ErrCode - operation result 43 */ 44 virtual ErrCode DisableWifi() = 0; 45 /** 46 * @Description create the Wi-Fi protect. 47 * 48 * @param protectType - WifiProtectMode object 49 * @param protectName - the protect name 50 * @return ErrCode - operation result 51 */ 52 virtual ErrCode InitWifiProtect(const WifiProtectType &protectType, const std::string &protectName) = 0; 53 54 /** 55 * @Description Acquire the Wi-Fi protect mode. 56 * 57 * @param protectMode - WifiProtectMode object 58 * @param protectName - the protect name 59 * @return ErrCode - operation result 60 */ 61 virtual ErrCode GetWifiProtectRef(const WifiProtectMode &protectMode, const std::string &protectName) = 0; 62 63 /** 64 * @Description Release the Wi-Fi protect mode. 65 * 66 * @param protectName - the protect name 67 * @return ErrCode - operation result 68 */ 69 virtual ErrCode PutWifiProtectRef(const std::string &protectName) = 0; 70 71 /** 72 * @Description Query application whether or not has held the Wi-Fi protect. 73 * 74 * @param protectName - the protect name 75 * @param isHeld - out whether or not has held the Wi-Fi protect 76 * @return ErrCode - operation result 77 */ 78 virtual ErrCode IsHeldWifiProtectRef(const std::string &protectName, bool &isHeld) = 0; 79 80 #ifndef OHOS_ARCH_LITE 81 virtual ErrCode IsHeldWifiProtect(bool &isHeld) = 0; 82 83 /** 84 * @Description Acquire the Wi-Fi protect mode. 85 * 86 * @param protectMode - WifiProtectMode object 87 * @return ErrCode - operation result 88 */ 89 virtual ErrCode GetWifiProtect(const WifiProtectMode &protectMode) = 0; 90 91 /** 92 * @Description Release the Wi-Fi protect mode. 93 * 94 * @return ErrCode - operation result 95 */ 96 virtual ErrCode PutWifiProtect() = 0; 97 #endif 98 /** 99 * @Description Remove the wifi candidate device config equals to input network id 100 * 101 * @param networkId - the candidate device network id 102 * @return ErrCode - operation result 103 */ 104 virtual ErrCode RemoveCandidateConfig(int networkId) = 0; 105 106 /** 107 * @Description Remove a specified candidate hotspot configuration. 108 * 109 * @param config - WifiDeviceConfig object 110 * @return ErrCode - operation result 111 */ 112 virtual ErrCode RemoveCandidateConfig(const WifiDeviceConfig &config) = 0; 113 114 /** 115 * @Description Add a wifi device configuration. 116 * 117 * @param config - WifiDeviceConfig object 118 * @param result - the device configuration's network id 119 * @param isCandidate - Whether is candidate 120 * @return ErrCode - operation result 121 */ 122 virtual ErrCode AddDeviceConfig(const WifiDeviceConfig &config, int &result, bool isCandidate) = 0; 123 124 /** 125 * @Description Update a wifi device configuration. 126 * 127 * @param config - WifiDeviceConfig object 128 * @param result - the device configuration's network id after updated 129 * @return ErrCode - operation result 130 */ 131 virtual ErrCode UpdateDeviceConfig(const WifiDeviceConfig &config, int &result) = 0; 132 133 /** 134 * @Description Remove the wifi device config equals to input network id. 135 * 136 * @param networkId - want to remove device config's network id 137 * @return ErrCode - operation result 138 */ 139 virtual ErrCode RemoveDevice(int networkId) = 0; 140 141 /** 142 * @Description Remove all device configs. 143 * 144 * @return ErrCode - operation result 145 */ 146 virtual ErrCode RemoveAllDevice() = 0; 147 148 /** 149 * @Description Get all the device configs. 150 * 151 * @param result - Get result vector of WifiDeviceConfig 152 * @param isCandidate - Whether is candidate 153 * @return ErrCode - operation result 154 */ 155 virtual ErrCode GetDeviceConfigs(std::vector<WifiDeviceConfig> &result, bool isCandidate) = 0; 156 157 /** 158 * @Description Connecting to a Specified Network. 159 * 160 * @param networkId - network id 161 * @param isCandidate - Whether is candidate 162 * @return ErrCode - operation result 163 */ 164 virtual ErrCode ConnectToNetwork(int networkId, bool isCandidate) = 0; 165 166 /** 167 * @Description Connect To a network base WifiDeviceConfig object. 168 * 169 * @param config - WifiDeviceConfig object 170 * @return ErrCode - operation result 171 */ 172 virtual ErrCode ConnectToDevice(const WifiDeviceConfig &config) = 0; 173 174 /** 175 * @Description Check whether Wi-Fi is connected. 176 * 177 * @return bool - true: connected, false: not connected 178 */ 179 virtual ErrCode IsConnected(bool &isConnected) = 0; 180 181 /** 182 * @Description Disconnect. 183 * 184 * @return ErrCode - operation result 185 */ 186 virtual ErrCode Disconnect(void) = 0; 187 188 /** 189 * @Description Check whether Wi-Fi is active. 190 * 191 * @param bActive - active / inactive 192 * @return ErrCode - operation result 193 */ 194 virtual ErrCode IsWifiActive(bool &bActive) = 0; 195 196 /** 197 * @Description Check whether Wi-Fi is metered hotspot. 198 * 199 * @param bMeteredHotspot - isMeteredHotspot / notMeteredHotspot 200 * @return ErrCode - operation result 201 */ 202 virtual ErrCode IsMeteredHotspot(bool &bMeteredHotspot) = 0; 203 204 /** 205 * @Description Get the Wi-Fi State. 206 * 207 * @param state - return current wifi state 208 * @return ErrCode - operation result 209 */ 210 virtual ErrCode GetWifiState(int &state) = 0; 211 212 /** 213 * @Description Obtains the current Wi-Fi connection information. 214 * 215 * @param info - WifiLinkedInfo object 216 * @return ErrCode - operation result 217 */ 218 virtual ErrCode GetLinkedInfo(WifiLinkedInfo &info) = 0; 219 220 /** 221 * @Description Obtains the disconnected reason 222 * 223 * @param reason - DisconnectedReason object 224 * @return ErrCode - operation result 225 * @since 10 226 */ 227 virtual ErrCode GetDisconnectedReason(DisconnectedReason &reason) = 0; 228 229 /** 230 * @Description Set the country code. 231 * 232 * @param countryCode - country code 233 * @return ErrCode - operation result 234 */ 235 virtual ErrCode SetCountryCode(const std::string &countryCode) = 0; 236 237 /** 238 * @Description Obtains the country code. 239 * 240 * @param countryCode - output the country code 241 * @return ErrCode - operation result 242 */ 243 virtual ErrCode GetCountryCode(std::string &countryCode) = 0; 244 245 /** 246 * @Description Register callback function. 247 * 248 * @param callback - IWifiDeviceCallBack object 249 * @return ErrCode - operation result 250 */ 251 #ifdef OHOS_ARCH_LITE 252 virtual ErrCode RegisterCallBack(const std::shared_ptr<IWifiDeviceCallBack> &callback, 253 const std::vector<std::string> &event) = 0; 254 #else 255 virtual ErrCode RegisterCallBack(const sptr<IWifiDeviceCallBack> &callback, 256 const std::vector<std::string> &event) = 0; 257 #endif 258 259 /** 260 * @Description Get the signal level object. 261 * 262 * @param rssi - rssi 263 * @param band - band 264 * @param level - return the level 265 * @return ErrCode - operation result 266 */ 267 virtual ErrCode GetSignalLevel(const int &rssi, const int &band, int &level) = 0; 268 269 /** 270 * @Description Get supported features 271 * 272 * @param features - return supported features 273 * @return ErrCode - operation result 274 */ 275 virtual ErrCode GetSupportedFeatures(long &features) = 0; 276 277 /** 278 * @Description Check if supported input feature 279 * 280 * @param feature - input feature 281 * @param isSupported - return true if supported, false if unsupported 282 * @return ErrCode - operation result 283 */ 284 virtual ErrCode IsFeatureSupported(long feature, bool &isSupported) = 0; 285 286 /** 287 * @Description Enable device config, when set attemptEnable, disable other device config 288 * 289 * @param networkId - need enable device config's network id 290 * @param attemptEnable - if set true, disable other device config 291 * @return ErrCode - operation result 292 */ 293 virtual ErrCode EnableDeviceConfig(int networkId, bool attemptEnable) = 0; 294 295 /** 296 * @Description set tx power for sar 297 * @param power - 1001 1002 1003······ 298 * @return ErrCode - operation result 299 */ 300 virtual ErrCode SetWifiTxPower(int power) = 0; 301 302 /** 303 * @Description Disable Wi-Fi device configuration. 304 * 305 * @param networkId - device config's network id 306 * @return ErrCode - operation result 307 */ 308 virtual ErrCode DisableDeviceConfig(int networkId) = 0; 309 310 /** 311 * @Description Obtaining ip Request Information 312 * 313 * @param info - IpInfo object 314 * @return ErrCode - operation result 315 */ 316 virtual ErrCode GetIpInfo(IpInfo &info) = 0; 317 318 /** 319 * @Description Obtaining ip Request Information 320 * 321 * @param info - IpV6Info object 322 * @return ErrCode - operation result 323 */ 324 virtual ErrCode GetIpv6Info(IpV6Info &info) = 0; 325 326 /** 327 * @Description Reconnect to the currently active network 328 * 329 * @return ErrCode - operation result 330 */ 331 virtual ErrCode ReConnect() = 0; 332 333 /** 334 * @Description ReAssociate network 335 * 336 * @return ErrCode - operation result 337 */ 338 virtual ErrCode ReAssociate() = 0; 339 340 /** 341 * @Description Get the device MAC address. 342 * 343 * @param result - Get device mac String 344 * @return ErrCode - operation result 345 */ 346 virtual ErrCode GetDeviceMacAddress(std::string &result) = 0; 347 348 /** 349 * @Description check wifi-band type is supported 350 * 351 * @param bandType - wifi band type 352 * @param supported - supported / unsupported 353 * @return ErrCode - operation result 354 */ 355 virtual ErrCode IsBandTypeSupported(int bandType, bool &supported) = 0; 356 357 /** 358 * @Description get all 5g channellist 359 * 360 * @param result - get result vector of int 361 * @return ErrCode - operation result 362 */ 363 virtual ErrCode Get5GHzChannelList(std::vector<int> &result) = 0; 364 365 /** 366 * @Description start portal certification 367 * 368 * @return ErrCode - operation result 369 */ 370 virtual ErrCode StartPortalCertification() = 0; 371 372 /** 373 * @Description set low latency mode 374 * 375 * @param enabled - true: enable low latency, false: disable low latency 376 * @return bool - operation result 377 */ 378 virtual bool SetLowLatencyMode(bool enabled) = 0; 379 380 /** 381 * @Description set frozen app 382 * 383 * @param pidList - pids of frozen app 384 * @param isFrozen - is app frozen 385 * @return ErrCode - operation result 386 */ 387 virtual ErrCode SetAppFrozen(std::set<int> pidList, bool isFrozen) = 0; 388 389 /** 390 * @Description reset all frozen app 391 * 392 * @return ErrCode - operation result 393 */ 394 virtual ErrCode ResetAllFrozenApp() = 0; 395 396 /** 397 * @Description disable auto join. 398 * 399 * @param conditionName autoJoinDisabled condition. 400 * @return WifiErrorNo 401 */ 402 virtual ErrCode DisableAutoJoin(const std::string &conditionName) = 0; 403 404 /** 405 * @Description enable auto join. 406 * 407 * @param conditionName autoJoinDisabled condition. 408 * @return WifiErrorNo 409 */ 410 virtual ErrCode EnableAutoJoin(const std::string &conditionName) = 0; 411 412 /** 413 * @Description register auto join condition. 414 * 415 * @param conditionName the name of condition. 416 * @param autoJoinCondition condition. 417 * @return WifiErrorNo 418 */ 419 virtual ErrCode RegisterAutoJoinCondition(const std::string &conditionName, 420 const std::function<bool()> &autoJoinCondition) = 0; 421 422 /** 423 * @Description deregister auto join condition. 424 * 425 * @param conditionName the name of condition. 426 * @return WifiErrorNo 427 */ 428 virtual ErrCode DeregisterAutoJoinCondition(const std::string &conditionName) = 0; 429 430 /** 431 * @Description register external filter builder. 432 * 433 * @param filterTag filterTag which define where the filter should be inserted. 434 * @param filterName the name of the filter to build. 435 * @param filterBuilder filter builder. 436 * @return WifiErrorNo 437 */ 438 virtual ErrCode RegisterFilterBuilder(const FilterTag &filterTag, const std::string &filterName, 439 const FilterBuilder &filterBuilder) = 0; 440 441 /** 442 * @Description deregister external filter builder. 443 * 444 * @param filterTag filterTag which define where the filter should be inserted. 445 * @param filterName the name of the filter to build. 446 * @return WifiErrorNo 447 */ 448 virtual ErrCode DeregisterFilterBuilder(const FilterTag &filterTag, const std::string &filterName) = 0; 449 450 /** 451 * Register the common builder function 452 * 453 * @param TagType scoreTag which define where the score or filter should be inserted. 454 * @param tagName the score or filter name. 455 * @param CommonBuilder CommonBuilder function. 456 */ 457 virtual ErrCode RegisterCommonBuilder(const TagType &tagType, const std::string &tagName, 458 const CommonBuilder &commonBuilder) = 0; 459 460 /** 461 * Deregister the common builder function 462 * 463 * @param TagType TagType which define where the score or filter should be inserted. 464 * @param tagName the score or filte name. 465 */ 466 virtual ErrCode DeregisterCommonBuilder(const TagType &tagType, const std::string &tagName) = 0; 467 468 virtual ErrCode GetChangeDeviceConfig(ConfigChange& value, WifiDeviceConfig &config) = 0; 469 470 /** 471 * @Description reset factory 472 * 473 * @return ErrCode - operation result 474 */ 475 virtual ErrCode FactoryReset() = 0; 476 477 /** 478 * @Description limit speed 479 * 480 * @param controlId 1: game 2: stream 3:temp 4: cellular speed limit 481 * @param limitMode speed limit mode, ranges 1 to 9 482 * @return WifiErrorNo 483 */ 484 virtual ErrCode LimitSpeed(const int controlId, const int limitMode) = 0; 485 486 /** 487 * @Description set low tx power 488 * 489 * @return ErrCode - operation result 490 */ 491 virtual ErrCode SetLowTxPower(const WifiLowPowerParam wifiLowPowerParam) = 0; 492 493 /** 494 * @Description hilink connect 495 * 496 * @return ErrCode - hilink connect result 497 */ 498 virtual ErrCode EnableHiLinkHandshake(bool uiFlag, std::string &bssid, WifiDeviceConfig &deviceConfig) = 0; 499 500 /** 501 * @Description Enable semi-Wifi 502 * 503 * @return ErrCode - operation result 504 */ 505 virtual ErrCode EnableSemiWifi() = 0; 506 507 /** 508 * @Description Obtains the wifi detail state 509 * 510 * @param state - WifiDetailState object 511 * @return ErrCode - operation result 512 */ 513 virtual ErrCode GetWifiDetailState(WifiDetailState &state) = 0; 514 515 /** 516 * @Description set satellite state 517 * 518 * @return ErrCode - operation result 519 */ 520 virtual ErrCode SetSatelliteState(const int state) = 0; 521 522 /** 523 * @Description roam to target bssid 524 * 525 * @param networkId - target networkId 526 * @param bssid - target bssid 527 * @param isCandidate - Whether is candidate 528 * @return ErrCode - operation result 529 */ 530 virtual ErrCode StartRoamToNetwork(const int networkId, const std::string bssid, const bool isCandidate) = 0; 531 532 /** 533 * @Description connect to user select ssid and bssid network 534 * 535 * @param networkId - target networkId 536 * @param bssid - target bssid 537 * @param isCandidate - Whether is candidate 538 * @return ErrCode - operation result 539 */ 540 virtual ErrCode StartConnectToUserSelectNetwork(int networkId, std::string bssid, bool isCandidate) = 0; 541 542 /** 543 * @Description Get single device config 544 * 545 * @param networkId - the network id of the device config 546 * @param config - Get result vector of WifiDeviceConfig 547 * @return ErrCode - operation result 548 */ 549 virtual ErrCode GetDeviceConfig(const int &networkId, WifiDeviceConfig &config) = 0; 550 551 /** 552 * @Description set data packet identification mark rule 553 * 554 * @param uid - target app uid 555 * @param protocol - target protocol type 556 * @param enable - enable/disable dpi mark 557 */ 558 virtual ErrCode SetDpiMarkRule(const std::string &ifaceName, int uid, int protocol, int enable) = 0; 559 }; 560 } // namespace Wifi 561 } // namespace OHOS 562 #endif 563