同步操作将从 OpenHarmony/docs 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
Provides functions for the Wi-Fi station and hotspot modes.
You can use this module to enable and disable the Wi-Fi station or hotspot mode, connect to and disconnect from a station or hotspot, query the station or hotspot status, and listen for events.
Since:
1.0
Version:
1.0
Indicates the maximum number of Wi-Fi station configurations that can be added using AddDeviceConfig. |
|
WIFI_CONFIG_INVALID (-1) |
Indicates the value of networkId when the configuration file is unavailable. |
Indicates the maximum length of a Wi-Fi MAC address or a Wi-Fi BSSID. |
|
WIFI_PSK_LEN 32 |
|
Indicates the maximum number of event listeners that can be registered using RegisterWifiEvent. |
|
Defines the maximum number of stations connected to a hotspot. |
|
Indicates the maximum number of hotspots that can be detected in a Wi-Fi scan. |
typedef struct WifiDeviceConfig Represents the Wi-Fi station configuration used to connect to a specified Wi-Fi device. |
WifiSecurityType { WIFI_SEC_TYPE_INVALID = -1, WIFI_SEC_TYPE_OPEN, WIFI_SEC_TYPE_WEP, WIFI_SEC_TYPE_PSK, WIFI_SEC_TYPE_SAE } |
|
WifiScanType { WIFI_FREQ_SCAN, WIFI_SSID_SCAN, WIFI_BSSID_SCAN, WIFI_BAND_SCAN } |
|
WifiErrorCode { WIFI_SUCCESS = 0, ERROR_WIFI_INVALID_ARGS = -1, ERROR_WIFI_CHIP_INVALID = -2, ERROR_WIFI_IFACE_INVALID = -3, ERROR_WIFI_RTT_CONTROLLER_INVALID = -4, ERROR_WIFI_NOT_SUPPORTED = -5, ERROR_WIFI_NOT_AVAILABLE = -6, ERROR_WIFI_NOT_STARTED = -7, ERROR_WIFI_BUSY = -8, ERROR_WIFI_UNKNOWN = -9 } |
|
WifiEventState { WIFI_STATE_NOT_AVALIABLE = 0, WIFI_STATE_AVALIABLE } |
|
RssiLevel { RSSI_LEVEL_1 = 1, RSSI_LEVEL_2 = 2, RSSI_LEVEL_3 = 3, RSSI_LEVEL_4 = 4 } |
Enumerates received signal strength indicator (RSSI) levels. |
HotspotBandType { HOTSPOT_BAND_TYPE_2G = 1, HOTSPOT_BAND_TYPE_5G = 2 } |
Enumerates frequency bands supported by the Wi-Fi hotspot mode. |
EnableWifi (void) |
|
DisableWifi (void) |
|
IsWifiActive (void) |
|
Scan (void) |
|
GetScanInfoList (WifiScanInfo *result, unsigned int *size) |
|
AddDeviceConfig (const WifiDeviceConfig *config, int *result) |
Adds a specified hotspot configuration for connecting to a hotspot. |
GetDeviceConfigs (WifiDeviceConfig *result, unsigned int *size) |
|
RemoveDevice (int networkId) |
Removes a hotspot configuration matching a specified networkId. |
ConnectTo (int networkId) |
|
Disconnect (void) |
|
GetLinkedInfo (WifiLinkedInfo *result) |
|
RegisterWifiEvent (WifiEvent *event) |
|
UnRegisterWifiEvent (const WifiEvent *event) |
Unregisters a callback previously registered for a specified Wi-Fi event. |
GetDeviceMacAddress (unsigned char *result) |
|
AdvanceScan (WifiScanParams *params) |
|
EnableHotspot (void) |
|
DisableHotspot (void) |
|
SetHotspotConfig (const HotspotConfig *config) |
|
GetHotspotConfig (HotspotConfig *result) |
|
IsHotspotActive (void) |
|
GetStationList (StationInfo *result, unsigned int *size) |
|
GetSignalLevel (int rssi, int band) |
Obtains the signal level indicated by a specified received signal strength indicator (RSSI) and frequency band. |
SetBand (int band) |
|
GetBand (int *result) |
#define WIFI_CONFIG_INVALID (-1)
Description:
Indicates the value of networkId when the configuration file is unavailable.
Generally, the configuration file is unavailable because the configuration matching the networkId is uninitialized.
#define WIFI_HOTSPOT_ACTIVE 1
Description:
Indicates that the Wi-Fi hotspot mode is enabled.
#define WIFI_HOTSPOT_NOT_ACTIVE 0
Description:
Indicates that the Wi-Fi hotspot mode is disabled.
#define WIFI_MAC_LEN 6
Description:
Indicates the maximum length of a Wi-Fi MAC address or a Wi-Fi BSSID.
#define WIFI_MAX_CONFIG_SIZE 10
Description:
Indicates the maximum number of Wi-Fi station configurations that can be added using AddDeviceConfig.
If the maximum number is reached, an error will be returned. In this case, you must delete at least one configuration before you can add new ones.
#define WIFI_MAX_EVENT_SIZE 10
Description:
Indicates the maximum number of event listeners that can be registered using RegisterWifiEvent.
When the maximum number is reached, you need to unregister at least one listener before registering new ones.
#define WIFI_MAX_KEY_LEN 65
Description:
Indicates the maximum length of a Wi-Fi key.
The maximum length is 64, and the last bit is reserved and set to \0.
#define WIFI_MAX_SSID_LEN 33
Description:
Indicates the maximum length of a Wi-Fi SSID.
The maximum length is 32, and the last bit is reserved and set to \0.
#define WIFI_PSK_LEN 32
Description:
Indicates the maximum length of a Wi-Fi PSK.
#define WIFI_STA_ACTIVE 1
Description:
Indicates that the Wi-Fi station mode is enabled.
#define WIFI_STA_NOT_ACTIVE 0
Description:
Indicates that the Wi-Fi station mode is disabled.
typedef struct [WifiDeviceConfig](WifiDeviceConfig.md) [WifiDeviceConfig](WifiDeviceConfig.md)
Description:
Represents the Wi-Fi station configuration used to connect to a specified Wi-Fi device.
enum [HotspotBandType](Wifiservice.md#ga37e10532da87571ee89193beac42d246)
Description:
Enumerates frequency bands supported by the Wi-Fi hotspot mode.
HOTSPOT_BAND_TYPE_2G | |
HOTSPOT_BAND_TYPE_5G |
enum [RssiLevel](Wifiservice.md#gadb1b12fe6311711103e759aac7a470d4)
Description:
Enumerates received signal strength indicator (RSSI) levels.
Four RSSI levels are available: 1 to 4. The higher the RSSI level, the stronger the Wi-Fi signal.
enum [WifiConnState](Wifiservice.md#ga970b7d5373775b1c7f3b31074bae50e1)
Description:
Enumerates Wi-Fi connection states.
WIFI_DISCONNECTED | |
WIFI_CONNECTED |
enum [WifiErrorCode](Wifiservice.md#ga2506c6ad226c4feb1d19248013ff9568)
Description:
Enumerates Wi-Fi error codes.
enum [WifiEventState](Wifiservice.md#ga6be99f93ce0d2d222c1f5f0a8217354d)
Description:
Enumerates states in Wi-Fi events.
WIFI_STATE_NOT_AVALIABLE | |
WIFI_STATE_AVALIABLE |
enum [WifiPskType](Wifiservice.md#gaa1a44d23b8478232f14d2adfc82cee77)
Description:
Enumerates psk encryption types.
WIFI_PSK_TYPE_ASCII | |
WIFI_PSK_TYPE_HEX |
enum [WifiScanType](Wifiservice.md#ga007bf5e22727debc02cad860e41a60a3)
Description:
Enumerates Wi-Fi scan types.
WIFI_FREQ_SCAN | |
WIFI_SSID_SCAN | |
WIFI_BSSID_SCAN | |
WIFI_BAND_SCAN |
enum [WifiSecurityType](Wifiservice.md#ga97c133f7db7c1234babcde03c4ce1b05)
Description:
Enumerates Wi-Fi security types.
WIFI_SEC_TYPE_INVALID | |
WIFI_SEC_TYPE_OPEN | |
WIFI_SEC_TYPE_WEP | |
WIFI_SEC_TYPE_PSK | |
WIFI_SEC_TYPE_SAE |
[WifiErrorCode](Wifiservice.md#ga2506c6ad226c4feb1d19248013ff9568) AddDeviceConfig (const [WifiDeviceConfig](WifiDeviceConfig.md) * config, int * result )
Description:
Adds a specified hotspot configuration for connecting to a hotspot.
This function generates a networkId.
Parameters:
config | Indicates the hotspot configuration to add. |
result | Indicates the generated networkId. Each networkId matches a hotspot configuration. |
Returns:
Returns WIFI_SUCCESS if the specified hotspot configuration is added; returns an error code defined in WifiErrorCode otherwise.
[WifiErrorCode](Wifiservice.md#ga2506c6ad226c4feb1d19248013ff9568) AdvanceScan ([WifiScanParams](WifiScanParams.md) * params)
Description:
Starts a Wi-Fi scan based on a specified parameter.
Only results matching the specified parameter will be returned for the Wi-Fi scan.
Parameters:
params | Indicates the pointer to the parameter for starting the Wi-Fi scan. For details, see WifiScanParams. |
Returns:
Returns WIFI_SUCCESS if the Wi-Fi scan is started successfully; returns an error code defined in WifiErrorCode otherwise.
[WifiErrorCode](Wifiservice.md#ga2506c6ad226c4feb1d19248013ff9568) ConnectTo (int networkId)
Description:
Connects to a hotspot matching a specified networkId.
Before calling this function, call AddDeviceConfig to add a hotspot configuration.
Parameters:
networkId | Indicates the networkId matching the target hotspot. |
Returns:
Returns WIFI_SUCCESS if the hotspot is connected; returns an error code defined in WifiErrorCode otherwise.
[WifiErrorCode](Wifiservice.md#ga2506c6ad226c4feb1d19248013ff9568) DisableHotspot (void )
Description:
Disables the hotspot mode.
Returns:
Returns WIFI_SUCCESS if the hotspot mode is disabled; returns an error code defined in WifiErrorCode otherwise.
[WifiErrorCode](Wifiservice.md#ga2506c6ad226c4feb1d19248013ff9568) DisableWifi (void )
Description:
Disables the station mode.
Returns:
Returns WIFI_SUCCESS if the station mode is disabled; returns an error code defined in WifiErrorCode otherwise.
[WifiErrorCode](Wifiservice.md#ga2506c6ad226c4feb1d19248013ff9568) Disconnect (void )
Description:
Disconnects this Wi-Fi connection.
Returns:
Returns WIFI_SUCCESS if this Wi-Fi connection is disconnected; returns an error code defined in WifiErrorCode otherwise.
[WifiErrorCode](Wifiservice.md#ga2506c6ad226c4feb1d19248013ff9568) EnableHotspot (void )
Description:
Enables the hotspot mode.
Before using this function, you need to invoke SetHotspotConfig and set at least the SSID, security type, and key.
Returns:
Returns WIFI_SUCCESS if the hotspot mode is enabled; returns an error code defined in WifiErrorCode otherwise.
[WifiErrorCode](Wifiservice.md#ga2506c6ad226c4feb1d19248013ff9568) EnableWifi (void )
Description:
Enables the station mode.
Returns:
Returns WIFI_SUCCESS if the station mode is enabled; returns an error code defined in WifiErrorCode otherwise.
[WifiErrorCode](Wifiservice.md#ga2506c6ad226c4feb1d19248013ff9568) GetBand (int * result)
Description:
Obtains the frequency band of this hotspot.
Parameters:
result | Indicates the obtained frequency band. |
Returns:
Returns WIFI_SUCCESS if the frequency band is obtained; returns an error code defined in WifiErrorCode otherwise.
[WifiErrorCode](Wifiservice.md#ga2506c6ad226c4feb1d19248013ff9568) GetDeviceConfigs ([WifiDeviceConfig](WifiDeviceConfig.md) * result, unsigned int * size )
Description:
Obtains all hotspot configurations.
Hotspot configurations were added using AddDeviceConfig.
Parameters:
result | Indicates the array of all hotspot configurations. The array is requested and released by the caller. The value must be greater than or equal to WIFI_MAX_CONFIG_SIZE. |
size | Indicates the size of the array. |
Returns:
Returns WIFI_SUCCESS if all hotspot configurations are obtained; returns an error code defined in WifiErrorCode otherwise.
[WifiErrorCode](Wifiservice.md#ga2506c6ad226c4feb1d19248013ff9568) GetDeviceMacAddress (unsigned char * result)
Description:
Obtains the MAC address of this device.
Parameters:
result | Indicates the MAC address of this device. It is a char array whose length is 6. |
Returns:
Returns WIFI_SUCCESS if the MAC address of this device is obtained; returns an error code defined in WifiErrorCode otherwise.
[WifiErrorCode](Wifiservice.md#ga2506c6ad226c4feb1d19248013ff9568) GetHotspotConfig ([HotspotConfig](HotspotConfig.md) * result)
Description:
Obtains a specified hotspot configuration.
The hotspot configuration includes the SSID, security type, and key.
Parameters:
result | Indicates the obtained hotspot configuration. |
Returns:
Returns WIFI_SUCCESS if the hotspot configuration is obtained; returns an error code defined in WifiErrorCode otherwise.
[WifiErrorCode](Wifiservice.md#ga2506c6ad226c4feb1d19248013ff9568) GetLinkedInfo ([WifiLinkedInfo](WifiLinkedInfo.md) * result)
Description:
Obtains information about the connected hotspot.
Parameters:
result | Indicates the information about the connected hotspot. |
Returns:
Returns WIFI_SUCCESS if the information about the connected hotspot is obtained; returns an error code defined in WifiErrorCode otherwise.
[WifiErrorCode](Wifiservice.md#ga2506c6ad226c4feb1d19248013ff9568) GetScanInfoList ([WifiScanInfo](WifiScanInfo.md) * result, unsigned int * size )
Description:
Obtains an array of hotspots detected in a Wi-Fi scan.
The array of hotspots can be obtained only after the Wi-Fi scan is complete.
Parameters:
result | Indicates the array of hotspots detected in a Wi-Fi scan. The array is requested and released by the caller. The value must be greater than or equal to WIFI_SCAN_HOTSPOT_LIMIT. |
size | Indicates the size of the array. |
Returns:
Returns WIFI_SUCCESS if the array of hotspots detected in the Wi-Fi scan is obtained; returns an error code defined in WifiErrorCode otherwise.
int GetSignalLevel (int rssi, int band )
Description:
Obtains the signal level indicated by a specified received signal strength indicator (RSSI) and frequency band.
Based on the signal level, you can display the signal strength represented by the number of signal bars.
Parameters:
rssi | Indicates the RSSI. |
band | Indicates the frequency band, either HOTSPOT_BAND_TYPE_5G or HOTSPOT_BAND_TYPE_2G. |
Returns:
Returns the signal level if it is obtained; returns -1 otherwise.
[WifiErrorCode](Wifiservice.md#ga2506c6ad226c4feb1d19248013ff9568) GetStationList ([StationInfo](StationInfo.md) * result, unsigned int * size )
Description:
Obtains an array of stations connected to this hotspot.
The station information is defined in StationInfo.
Parameters:
result | Indicates the array of stations connected to this hotspot. The array is requested and released by the caller. The value must be greater than or equal to WIFI_MAX_STA_NUM. |
size | Indicates the size of the array. |
Returns:
Returns WIFI_SUCCESS if the array of stations connected to this hotspot is obtained; returns an error code defined in WifiErrorCode otherwise.
int IsHotspotActive (void )
Description:
Checks whether the hotspot mode is enabled.
Returns:
Returns WIFI_HOTSPOT_ACTIVE if the hotspot mode is enabled; returns WIFI_HOTSPOT_NOT_ACTIVE otherwise.
int IsWifiActive (void )
Description:
Checks whether the station mode is enabled.
Returns:
Returns WIFI_STA_ACTIVE if the station mode is enabled; returns WIFI_STA_NOT_ACTIVE otherwise.
[WifiErrorCode](Wifiservice.md#ga2506c6ad226c4feb1d19248013ff9568) RegisterWifiEvent ([WifiEvent](WifiEvent.md) * event)
Description:
Registers a callback for a specified Wi-Fi event.
The registered callback will be invoked when the Wi-Fi event defined in WifiEvent occurs.
Parameters:
event | Indicates the event for which the callback is to be registered. |
Returns:
Returns WIFI_SUCCESS if the callback is registered successfully; returns an error code defined in WifiErrorCode otherwise.
[WifiErrorCode](Wifiservice.md#ga2506c6ad226c4feb1d19248013ff9568) RemoveDevice (int networkId)
Description:
Removes a hotspot configuration matching a specified networkId.
Parameters:
networkId | Indicates the networkId matching the hotspot configuration to remove. |
Returns:
Returns WIFI_SUCCESS if the hotspot configuration is removed; returns an error code defined in WifiErrorCode otherwise.
[WifiErrorCode](Wifiservice.md#ga2506c6ad226c4feb1d19248013ff9568) Scan (void )
Description:
Starts a Wi-Fi scan.
Returns:
Returns WIFI_SUCCESS if the Wi-Fi scan is started; returns an error code defined in WifiErrorCode otherwise.
[WifiErrorCode](Wifiservice.md#ga2506c6ad226c4feb1d19248013ff9568) SetBand (int band)
Description:
Sets the frequency band for this hotspot.
Parameters:
band | Indicates the frequency band to set. |
Returns:
Returns WIFI_SUCCESS if the frequency band is set; returns an error code defined in WifiErrorCode otherwise.
[WifiErrorCode](Wifiservice.md#ga2506c6ad226c4feb1d19248013ff9568) SetHotspotConfig (const [HotspotConfig](HotspotConfig.md) * config)
Description:
Sets a specified hotspot configuration.
The hotspot configuration includes the SSID, security type, and key. The configuration set overwrites the existing configuration and takes effect after the hotspot mode is re-enabled. Before enabling the hotspot mode for the first time, you must call this function.
Parameters:
config | Indicates the hotspot configuration to set. |
Returns:
Returns WIFI_SUCCESS if the hotspot configuration is set; returns an error code defined in WifiErrorCode otherwise.
[WifiErrorCode](Wifiservice.md#ga2506c6ad226c4feb1d19248013ff9568) UnRegisterWifiEvent (const [WifiEvent](WifiEvent.md) * event)
Description:
Unregisters a callback previously registered for a specified Wi-Fi event.
Parameters:
event | Indicates the event for which the callback is to be unregistered. |
Returns:
Returns WIFI_SUCCESS if the callback is unregistered successfully; returns an error code defined in WifiErrorCode otherwise.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。