Wi-Fi Manager
概述
本文档介绍bl_iot_sdk的WiFi联网功能。主要包括
- 基站模式(即 STA 模式或 Wi-Fi 客户端模式),此时 BL_IoT 连接到接入点 (AP)。
- AP 模式(即 Soft-AP 模式或接入点模式),此时基站连接到 BL_IoT。
- AP-STA 共存模式(BL_IoT 既是接入点,同时又作为基站连接到另外一个接入点)。
- 上述模式的各种安全模式(WPA、WPA2 及 WEP(AP模式不支持))。
- 扫描接入点(包括主动扫描及被动扫描)。
- 使用混杂模式监控 IEEE802.11 Wi-Fi 数据包。
应用实例
BL_IoT的实例 bl602_demo_wifi
目录下包含了一个应用程序,该demo介绍了如何使用BL_IoT模组连接到AP等一系列wifi操作。该实例实现的主要思路如下:
- 在主函数
bfl_main()
中创建一个aos_loop_proc()
线程,在此线程中调用aos_register_event_filter()
接口注册一个EV_WIFI
事件的监听函数event_cb_wifi_event()
; - 首先用户在终端中输入
stack_wifi
命令后,在cmd_stack_wifi()
函数中创建一个wifi_main()
的线程,接着调用aos_post_event()
接口发布CODE_WIFI_ON_INIT_DONE
事件后,event_cb_wifi_event()
会被调用,并进入caseCODE_WIFI_ON_INIT_DONE
分支从而调用wifi_mgmr_start_background()
开启WiFi Manager,同时发布CODE_WIFI_ON_MGMR_DONE
事件,进入caseCODE_WIFI_ON_MGMR_DONE
分支调用_connect_wifi()
函数,此函数先判断easyflash中是否设置了可连接的ssid,如果设置了则会自动进行wifi连接,没有设置则需手动输命令设置; - 如用户在终端中输入
wifi_sta_connect
命令,会调用相应的api实现。如需实现wifi相关的其他功能可通过调用对应api来实现。
API参考
Header File
- components/network/wifi_manager/bl60x_wifi_driver/include/wifi_mgmr_ext.h
Functions
-
int
wifi_mgmr_psk_cal
(char *password, char *ssid, int ssid_len, char *output)
-
int
wifi_mgmr_drv_init
(wifi_conf_t *conf)
-
int
wifi_mgmr_init
(void)
-
void
wifi_mgmr_start
(void)
-
void
wifi_mgmr_start_background
(wifi_conf_t *conf)
-
void
wifi_mgmr_get_wifi_channel_conf
(wifi_conf_t *wifi_chan_conf)
-
wifi_interface_t
wifi_mgmr_sta_enable
(void)
-
int
wifi_mgmr_sta_disable
(wifi_interface_t *interface)
-
struct netif *
wifi_mgmr_sta_netif_get
(void)
-
struct netif *
wifi_mgmr_ap_netif_get
(void)
-
int
wifi_mgmr_sta_mac_set
(uint8_t mac[6])
-
int
wifi_mgmr_sta_mac_get
(uint8_t mac[6])
-
int
wifi_mgmr_sta_ip_get
(uint32_t *ip, uint32_t *gw, uint32_t *mask)
-
int
wifi_mgmr_sta_ip_set
(uint32_t ip, uint32_t mask, uint32_t gw, uint32_t dns1, uint32_t dns2)
-
int
wifi_mgmr_sta_dns_get
(uint32_t *dns1, uint32_t *dns2)
-
int
wifi_mgmr_sta_ip_unset
(void)
-
int
wifi_mgmr_sta_connect_ext
(wifi_interface_t *wifi_interface, char *ssid, char *passphr, const ap_connect_adv_t *conn_adv_param)
-
int
wifi_mgmr_sta_connect_mid
(wifi_interface_t *wifi_interface, char *ssid, char *psk, char *pmk, uint8_t *mac, uint8_t band, uint8_t chan_id, uint8_t use_dhcp, uint32_t flags)
-
int
wifi_mgmr_sta_connect
(wifi_interface_t *wifi_interface, char *ssid, char *psk, char *pmk, uint8_t *mac, uint8_t band, uint8_t chan_id)
-
int
wifi_mgmr_sta_disconnect
(void)
-
int
wifi_sta_ip4_addr_get
(uint32_t *addr, uint32_t *mask, uint32_t *gw, uint32_t *dns)
-
int
wifi_mgmr_sta_ps_enter
(uint32_t ps_level)
-
int
wifi_mgmr_sta_ps_exit
()
-
int
wifi_mgmr_sta_autoconnect_enable
(void)
-
int
wifi_mgmr_sta_autoconnect_disable
(void)
-
void
wifi_mgmr_sta_ssid_set
(char *ssid)
-
void
wifi_mgmr_sta_passphr_set
(char *passphr)
-
void
wifi_mgmr_sta_psk_set
(char *psk)
-
void
wifi_mgmr_sta_connect_ind_stat_get
(wifi_mgmr_sta_connect_ind_stat_info_t *wifi_mgmr_ind_stat)
-
wifi_interface_t
wifi_mgmr_ap_enable
(void)
-
int
wifi_mgmr_ap_mac_set
(uint8_t mac[6])
-
int
wifi_mgmr_ap_mac_get
(uint8_t mac[6])
-
int
wifi_mgmr_ap_ip_get
(uint32_t *ip, uint32_t *gw, uint32_t *mask)
-
int
wifi_mgmr_ap_stop
(wifi_interface_t *interface)
-
int
wifi_mgmr_ap_start
(wifi_interface_t *interface, char *ssid, int hidden_ssid, char *passwd, int channel)
-
int
wifi_mgmr_ap_start_adv
(wifi_interface_t *interface, char *ssid, int hidden_ssid, char *passwd, int channel, uint8_t use_dhcp)
-
int
wifi_mgmr_ap_start_atcmd
(wifi_interface_t *interface, char *ssid, int hidden_ssid, char *passwd, int channel, int max_sta_supported)
-
int
wifi_mgmr_ap_sta_cnt_get
(uint8_t *sta_cnt)
-
int
wifi_mgmr_ap_sta_info_get
(struct wifi_sta_basic_info *sta_info, uint8_t idx)
-
int
wifi_mgmr_ap_sta_delete
(uint8_t sta_idx)
-
int
wifi_mgmr_ap_set_gateway
(char *gateway)
-
int
wifi_mgmr_sniffer_enable
(void)
-
int
wifi_mgmr_sniffer_disable
(void)
-
int
wifi_mgmr_rate_config
(uint16_t config)
-
int
wifi_mgmr_conf_max_sta
(uint8_t max_sta_supported)
-
int
wifi_mgmr_sniffer_register
(void *env, sniffer_cb_t cb)
-
int
wifi_mgmr_sniffer_unregister
(void *env)
-
int
wifi_mgmr_sniffer_register_adv
(void *env, sniffer_cb_adv_t cb)
-
int
wifi_mgmr_sniffer_unregister_adv
(void *env)
-
int
wifi_mgmr_state_get
(int *state)
-
int
wifi_mgmr_detailed_state_get
(int *state, int *state_detailed)
-
int
wifi_mgmr_status_code_get
(int *s_code)
-
int
wifi_mgmr_rssi_get
(int *rssi)
-
int
wifi_mgmr_channel_get
(int *channel)
-
int
wifi_mgmr_channel_set
(int channel, int use_40Mhz)
-
int
wifi_mgmr_all_ap_scan
(wifi_mgmr_ap_item_t **ap_ary, uint32_t *num)
-
int
wifi_mgmr_scan
(void *data, scan_complete_cb_t cb)
-
int
wifi_mgmr_scan_adv
(void *data, scan_complete_cb_t cb, uint16_t *channels, uint16_t channel_num, const uint8_t bssid[6], const char *ssid, uint8_t scan_mode, uint32_t duration_scan)
-
int
wifi_mgmr_cfg_req
(uint32_t ops, uint32_t task, uint32_t element, uint32_t type, uint32_t length, uint32_t *buf)
-
int
wifi_mgmr_scan_complete_callback
()
-
int
wifi_mgmr_cli_scanlist
(void)
-
int
wifi_mgmr_cli_init
(void)
-
int
wifi_mgmr_scan_ap
(char *ssid, wifi_mgmr_ap_item_t *item)
-
int
wifi_mgmr_scan_ap_all
(wifi_mgmr_ap_item_t *env, uint32_t *param1, scan_item_cb_t cb)
-
int
wifi_mgmr_raw_80211_send
(uint8_t *pkt, int len)
-
int
wifi_mgmr_set_country_code
(char *country_code)
-
int
wifi_mgmr_ext_dump_needed
()
-
const char *
wifi_mgmr_status_code_str
(uint16_t status_code)
-
int
wifi_mgmr_beacon_interval_set
(uint16_t beacon_int)
-
void
wifi_mgmr_conn_result_get
(uint16_t *status_code, uint16_t *reason_code)
-
int
wifi_mgmr_set_wifi_active_time
(uint32_t ms)
-
int
wifi_mgmr_set_listen_interval
(uint16_t itv)
-
int
wifi_mgmr_pm_ops_register
(void)
-
int
wifi_mgmr_fw_affair_ops
(void)
-
int
wifi_mgmr_bcnind_auth_to_ext
(int auth)
-
int
wifi_mgmr_bcnind_cipher_to_ext
(int cipher)
-
struct sm_connect_tlv_desc *
wifi_mgmr_diagnose_tlv_get_ele
(void)
-
void
wifi_mgmr_diagnose_tlv_free_ele
(struct sm_connect_tlv_desc *ele)
Structures
-
struct
ap_info
-
struct
ap_connect_adv
-
struct
bl_rx_info
-
struct
wifi_mgmr_ap_item
-
struct
wifi_mgmr_sta_connect_ind_stat_info
-
struct
wifi_sta_basic_info
-
struct
wifi_sta_ps_conf
-
struct
wifi_conf
Macros
-
WIFI_CONNECT_STOP_SCAN_ALL_CHANNEL_IF_TARGET_AP_FOUND
-
WIFI_CONNECT_PCI_EN
-
WIFI_CONNECT_STOP_SCAN_CURRENT_CHANNEL_IF_TARGET_AP_FOUND
-
WIFI_CONNECT_PMF_CAPABLE
-
WIFI_CONNECT_PMF_REQUIRED
-
WIFI_STATE_AP_IS_ENABLED
(status)
Type Definitions
-
typedef struct ap_connect_adv
ap_connect_adv_t
-
typedef struct bl_rx_info
bl_rx_info_t
-
typedef struct wifi_mgmr_ap_item
wifi_mgmr_ap_item_t
-
typedef struct wifi_mgmr_sta_connect_ind_stat_info
wifi_mgmr_sta_connect_ind_stat_info_t
-
typedef struct wifi_sta_basic_info
wifi_sta_basic_info_t
-
typedef struct wifi_sta_ps_conf
wifi_sta_ps_conf_t
-
typedef void *
wifi_interface_t
-
typedef void (*
sniffer_cb_t
)(void *env, uint8_t *pkt, int len, bl_rx_info_t *info)
-
typedef void (*
sniffer_cb_adv_t
)(void *env, void *pkt_wrap, bl_rx_info_t *info)
-
typedef void (*
scan_item_cb_t
)(wifi_mgmr_ap_item_t *env, uint32_t *param1, wifi_mgmr_ap_item_t *item)
-
typedef void (*
scan_complete_cb_t
)(void *data, void *param)
Enumerations
-
enum
wifi_mgmr_ap_cipher_t
Values:
-
WM_WIFI_CIPHER_NONE
= 0
-
WM_WIFI_CIPHER_WEP
-
WM_WIFI_CIPHER_AES
-
WM_WIFI_CIPHER_TKIP
-
WM_WIFI_CIPHER_TKIP_AES
-
WM_WIFI_CIPHER_MAX
-
-
enum
wifi_mgmr_ap_auth_mode_t
Values:
-
WM_WIFI_AUTH_UNKNOWN
= 0
-
WM_WIFI_AUTH_OPEN
-
WM_WIFI_AUTH_WEP
-
WM_WIFI_AUTH_WPA_PSK
-
WM_WIFI_AUTH_WPA2_PSK
-
WM_WIFI_AUTH_WPA_WPA2_PSK
-
WM_WIFI_AUTH_WPA_ENTERPRISE
-
WM_WIFI_AUTH_WPA3_SAE
-
WM_WIFI_AUTH_WPA2_PSK_WPA3_SAE
-
WM_WIFI_AUTH_MAX
-
-
enum
[anonymous]
Power Save mode setting.
Values:
-
PS_MODE_OFF
Power-save off.
-
PS_MODE_ON
Power-save on - Normal mode.
-
PS_MODE_ON_DYN
Power-save on - Dynamic mode.
-
-
enum
WIFI_STATE_ENUM_LIST
Values:
-
WIFI_STATE_UNKNOWN
= 0x00
-
WIFI_STATE_IDLE
= 0x01
-
WIFI_STATE_CONNECTING
= 0x02
-
WIFI_STATE_CONNECTED_IP_GETTING
= 0x03
-
WIFI_STATE_CONNECTED_IP_GOT
= 0x04
-
WIFI_STATE_DISCONNECT
= 0x05
-
WIFI_STATE_WITH_AP_IDLE
= 0x11
-
WIFI_STATE_WITH_AP_CONNECTING
= 0x12
-
WIFI_STATE_WITH_AP_CONNECTED_IP_GETTING
= 0x13
-
WIFI_STATE_WITH_AP_CONNECTED_IP_GOT
= 0x14
-
WIFI_STATE_WITH_AP_DISCONNECT
= 0x15
-
WIFI_STATE_IFDOWN
= 0x06
-
WIFI_STATE_SNIFFER
= 0x07
-
WIFI_STATE_PSK_ERROR
= 0x08
-
WIFI_STATE_NO_AP_FOUND
= 0x09
-
-
enum
WIFI_SCAN_DONE_EVENT_TYPE
Values:
-
WIFI_SCAN_DONE_EVENT_OK
= 0x00
-
WIFI_SCAN_DONE_EVENT_BUSY
= 0x01
-
-
enum
WIFI_COEX_PM_LEVEL
Values:
-
WIFI_COEX_PM_STA_NONE
= PM_MODE_STA_NONE
-
WIFI_COEX_PM_STA_IDLE
= PM_MODE_STA_IDLE
-
WIFI_COEX_PM_STA_MESH
= PM_MODE_STA_MESH
-
WIFI_COEX_PM_STA_DOZE
= PM_MODE_STA_DOZE
-
WIFI_COEX_PM_STA_COEX
= PM_MODE_STA_COEX
-
WIFI_COEX_PM_STA_DOWN
= PM_MODE_STA_DOWN
-
WIFI_COEX_PM_AP_IDLE
= PM_MODE_AP_IDLE
-
WIFI_COEX_PM_MAX
= PM_MODE_MAX
-