#include "xf_utils.h"
#include "xf_task.h"
#define EXAMPLE_SCAN_CHANNEL_START 1
#define EXAMPLE_SCAN_CHANNEL_END 13
#define EXAMPLE_SCAN_RESULT_SIZE 32
#define EXAMPLE_SCAN_BLOCK_IS_ENABLE 1
#if EXAMPLE_SCAN_BLOCK_IS_ENABLE
# define EXAMPLE_SCAN_BLOCK true
#else
# define EXAMPLE_SCAN_BLOCK false
#endif
#define EXAMPLE_WIFI_NTASK_PRIORITY 15
#define EXAMPLE_WIFI_NTASK_PERIOD_MS 10
#define TBL_IT(v) {v, XSTR(v)}
#define EXAMPLE_WIFI_SSID "myssid"
#define EXAMPLE_WIFI_PASS "mypassword"
static const char *
TAG =
"scan";
.bssid_set = false,
.bssid = {0},
.channel = 0,
.p_cfg_ext = NULL,
.p_static_ip = NULL,
};
#define ERROR_CHECK(expression) \
do { \
if (unlikely((expression) != XF_OK)) { \
XF_LOGE(TAG, "An error occurred: %s", XSTR(expression != XF_OK)); \
_error_check_failed(); \
} \
} while (0)
{
}
{
for (;;) {
.show_hidden = true,
};
#if (!EXAMPLE_SCAN_BLOCK_IS_ENABLE)
}
#endif
uint32_t result_num = 0;
&result_num);
int32_t matched_index = -1;
int32_t cmp_res = -1;
for (uint32_t i = 0;
i++) {
"\n"
" index: %d\n"
" ssid: %s\n"
" rssi: %d\n"
" authmode: %s\n"
" channel: %d",
i,
if ((0 == cmp_res) && (-1 == matched_index)) {
matched_index = i;
}
}
if (matched_index != -1) {
while (1) {
break;
}
}
goto l_succ;
}
}
}
l_succ:;
}
{
switch (event_id) {
} break;
} break;
"\nssid: %s\n"
"channel: %d\n"
"authmode: %d",
} break;
XF_LOGI(
TAG,
"The STA has been disconnected from the AP.");
"\nssid: %s\n"
"rssi: %d",
}
} break;
} break;
default:
break;
}
}
{
switch (event_id) {
} break;
default:
break;
}
}
{
};
unsigned int i = 0;
for (i = 0; i < (
unsigned int)
ARRAY_SIZE(ex_auth_mode_msg_table); ++i) {
if (ex_auth_mode_msg_table[i].code == code) {
return ex_auth_mode_msg_table[i].
msg;
}
}
return ex_auth_mode_msg_table[
ARRAY_SIZE(ex_auth_mode_msg_table) - 1].
msg;
}
{
for (;;) {
}
}
static void _wifi_sta_event_handler(xf_wifi_event_id_t event_id, void *event_data, void *user_args)
static xf_wifi_sta_cfg_t s_sta_cfg
static void _ip_event_handler(xf_ip_event_id_t event_id, void *event_data, void *user_args)
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)
static void _error_check_failed(void)
#define EXAMPLE_WIFI_SSID
#define EXAMPLE_WIFI_PASS
static uint8_t s_is_connected
#define EXAMPLE_WIFI_NTASK_PERIOD_MS
static void _wifi_ntask(xf_task_t task)
wifi 无栈任务。
#define EXAMPLE_WIFI_NTASK_PRIORITY
#define EXAMPLE_SCAN_CHANNEL_START
struct example_authenticate_mode_message_s ex_auth_mode_msg_t
#define EXAMPLE_SCAN_CHANNEL_END
#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
#define XF_LOGI(tag, format,...)