25#define EXAMPLE_SCAN_CHANNEL_START 1
26#define EXAMPLE_SCAN_CHANNEL_END 13
27#define EXAMPLE_SCAN_RESULT_SIZE 32
28#define EXAMPLE_SCAN_BLOCK_IS_ENABLE 1
30#if EXAMPLE_SCAN_BLOCK_IS_ENABLE
31# define EXAMPLE_SCAN_BLOCK true
33# define EXAMPLE_SCAN_BLOCK false
36#define EXAMPLE_WIFI_NTASK_PRIORITY 15
37#define EXAMPLE_WIFI_NTASK_PERIOD_MS 10
42#define TBL_IT(v) {v, XSTR(v)}
44#define EXAMPLE_WIFI_SSID "myssid"
45#define EXAMPLE_WIFI_PASS "mypassword"
97static const char *
TAG =
"scan";
122#define ERROR_CHECK(expression) \
124 if (unlikely((expression) != XF_OK)) { \
125 XF_LOGE(TAG, "An error occurred: %s", XSTR(expression != XF_OK)); \
126 _error_check_failed(); \
169#if (!EXAMPLE_SCAN_BLOCK_IS_ENABLE)
178 uint32_t result_num = 0;
202 int32_t matched_index = -1;
203 int32_t cmp_res = -1;
207 XF_LOGI(
TAG,
"------------------------------");
228 if ((0 == cmp_res) && (-1 == matched_index)) {
236 XF_LOGI(
TAG,
"------------------------------");
239 if (matched_index != -1) {
282 XF_LOGI(
TAG,
"The STA is connected to the AP.");
295 XF_LOGI(
TAG,
"The STA has been disconnected from the AP.");
349 for (i = 0; i < (
unsigned int)
ARRAY_SIZE(ex_auth_mode_msg_table); ++i) {
350 if (ex_auth_mode_msg_table[i].code == code) {
351 return ex_auth_mode_msg_table[i].
msg;
354 return ex_auth_mode_msg_table[
ARRAY_SIZE(ex_auth_mode_msg_table) - 1].
msg;
int32_t xf_ip_event_id_t
ip 事件 id。见 xf_ip_event_code_t.
#define XF_IP2STR(ipaddr)
#define XF_NTASK_BEGIN(ntask)
#define xf_ntask_delay(delay_ms)
static xf_task_t xf_ttask_create_loop(xf_task_func_t func, void *func_arg, uint16_t priority, uint32_t delay_ms)
在默认的任务管理下,创建 ttask 循环任务。
#define ARRAY_SIZE(arr)
ARRAY_SIZE - 获取数组 arr 中的元素数量。
xf_err_t xf_wifi_sta_set_ip_cb(xf_ip_cb_t cb_func, void *user_args)
STA 设置 ip 事件回调函数.
xf_err_t xf_wifi_scan_get_result(xf_wifi_ap_info_t result_array[], uint32_t result_array_size, uint32_t *p_result_num)
wifi 获取扫描结果。
xf_err_t xf_wifi_sta_connect(xf_wifi_sta_cfg_t *p_cfg)
STA 连接到指定 AP.
xf_err_t xf_wifi_scan_start(const xf_wifi_scan_cfg_t *p_cfg, bool block)
wifi 启动 AP 扫描。
bool xf_wifi_sta_is_connected(void)
STA 检查是否已经连接到 AP.
xf_err_t xf_wifi_scan_clear_result(void)
wifi 清除扫描结果。
xf_err_t xf_wifi_sta_set_cb(xf_wifi_cb_t cb_func, void *user_args)
wifi STA 设置回调函数.
xf_err_t xf_wifi_sta_init(const xf_wifi_sta_cfg_t *p_cfg)
启用 wifi STA 模式.
xf_err_t xf_wifi_enable(void)
启用 wifi 协议栈.
enum _xf_wifi_authenticate_mode_t xf_wifi_auth_mode_t
授权模式的强度。 OPEN < WEP < WPA_PSK < OWE < WPA2_PSK = WPA_WPA2_PSK < WAPI_PSK < WPA3_PSK = WPA2_WPA3_PSK
int32_t xf_wifi_event_id_t
wifi 事件 id。见 xf_wifi_event_code_t.
@ XF_WIFI_AUTH_WPA_WPA2_PSK
@ XF_WIFI_AUTH_ENTERPRISE
@ XF_WIFI_AUTH_WPA3_ENT_192
@ XF_WIFI_AUTH_WPA2_WPA3_PSK
@ XF_WIFI_EVENT_STA_START
@ XF_WIFI_EVENT_SCAN_DONE
@ XF_WIFI_EVENT_STA_DISCONNECTED
@ XF_WIFI_EVENT_STA_CONNECTED
XF_IP_EVENT_STA_GOT_IP 事件的事件结构。
xf_netif_ip_info_t ip_info
uint8_t bssid[XF_MAC_LEN_MAX]
xf_wifi_auth_mode_t authmode
uint8_t ssid[XF_WIFI_SSID_LEN_MAX]
STA 事件消息类型: 已连接到 AP。 事件 id 见 XF_WIFI_EVENT_STA_CONNECTED.
uint8_t bssid[XF_MAC_LEN_MAX]
xf_wifi_auth_mode_t authmode
uint8_t ssid[XF_WIFI_SSID_LEN_MAX]
STA 事件消息类型: 已从 AP 断开连接。 事件 id 见 XF_WIFI_EVENT_STA_DISCONNECTED.
uint8_t bssid[XF_MAC_LEN_MAX]
uint8_t ssid[XF_WIFI_SSID_LEN_MAX]
Parameters for an SSID scan.
xf_wifi_auth_mode_t authmode
uint8_t ssid[XF_WIFI_SSID_LEN_MAX]
xf_wifi_ap_info_t ap_info[EXAMPLE_SCAN_RESULT_SIZE]
uint8_t curr_scan_channel
static void task(xf_task_t task)
#define ERROR_CHECK(expression)
static void _error_check_failed(void)
#define EXAMPLE_WIFI_SSID
#define EXAMPLE_WIFI_PASS
static uint8_t s_is_connected
static xf_wifi_sta_cfg_t s_sta_cfg
#define EXAMPLE_WIFI_NTASK_PERIOD_MS
#define EXAMPLE_SCAN_CHANNEL_START
struct example_authenticate_mode_message_s ex_auth_mode_msg_t
static void _wifi_ntask(xf_task_t task)
#define EXAMPLE_WIFI_NTASK_PRIORITY
#define EXAMPLE_SCAN_CHANNEL_END
static void _wifi_sta_event_handler(xf_wifi_event_id_t event_id, void *event_data, void *user_args)
#define EXAMPLE_SCAN_BLOCK
static const char * ex_auth_mode_to_name(xf_wifi_auth_mode_t code)
struct example_scan_context_s ex_scan_ctx_t
static ex_scan_ctx_t * sp_ctx
#define EXAMPLE_SCAN_RESULT_SIZE
static void _ip_event_handler(xf_ip_event_id_t event_id, void *event_data, void *user_args)
#define XF_LOGI(tag, format,...)