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