FreeRTOS 上的网络,驱动部分源码没有开源,用户实际使用时也无需关系具体实现,更多的是做网络管理的逻辑接口开发,所以我们提供了网络中间件?Wi-Fi Manager
,Wi-Fi Manager
?支持sta
,?ap
,?monitor
?等多种网络工作模式的管理,本文档重点介绍?Wi-Fi Manager
?中间件的使用,配置,框架,接口。
目前R128 平台上的Wi?Fi 一般可处于3 种工作模式,分别是STATION,AP,MONITOR。
FreeRTOS 中wlan 相关代码主要分布在四个地方:
1)驱动部分:lichee/rtos/drivers/drv/wireless/xradio
2)协议栈部分:lichee/rtos?components/thirdparty/network/lwip?2.1.2
3)应用协议部分:lichee/rtos?components/aw/network/service
4)中间件部分:lichee/rtos?components/aw/wireless/Wi-Fi Manager
FreeRTOS 中 wlan 相关配置分为 c906 和 m33:
> System components > aw components > wireless
[*] wireless common
[*] Wi-Fi Manager?v2.0 ???>
Wi-Fi Manager?v2.0 Configuration ???>
[ ] CONFIG_WMG_PROTOCOL_SOFTAP
[ ] CONFIG_WMG_PROTOCOL_BLE
[ ] CONFIG_WMG_PROTOCOL_XCONFIG
[ ] CONFIG_WMG_PROTOCOL_SOUNDWAVE
Wi-Fi Manager support platform (FREERTOS PLATFORM OS) ???>
(X) FREERTOS PLATFORM OS
[*] Wi-Fi Manager unregister callback function
[*] Wi-Fi Manager support send expand cmd
Wi-Fi Manager support mode Configuration ???>
[*] Wi-Fi Manager support sta mode enable
[*] Wi-Fi Manager support ap mode enable
[ ] Wi-Fi Manager support monitor mode enable
[ ] Wi-Fi Manager support p2p mode enable
Wi-Fi Manager set default debug level (default debug level: to info) ???>
(X) default debug level: to info
> Drivers Options > other drivers
[*] rfkill drivers
> Drivers Options > other drivers > wireless devices
[*] XRADIO driver ???>
[*] Enable xradio test cmd
Xradio chip (Enable r128 driver) ???>
[*] Wi?Fi Certification of WFA
[*] wlan station mode
[ ] wlan station mode with wps support
[*] wlan monitor mode
[*] wlan ap mode
select the source of frequency offset (SDD file) ???>
[ ] wlan ETF test
> System components > aw components > aw network
[*] tcp ip adapter
[ ] loop interface test demo
[ ] wifi test demo
[ ] wifi fast connect test demo
[ ] get mac_addr test demo
[ ] set/get country code optional
service ???>
[ ] udhcpd demo
[ ] sntp demo
[*] iperf demo
[*] ping demo
[ ] nopoll demo
[ ] mqtt demo
[ ] shttpd demo
[ ] mbedtls demo
[ ] httpc demo
[ ] mini_wget
[ ] telnet
> System components > aw components > AMP Components Support
[*] AMP Network Stub Functions
[*] AMP Network Service
> System components > thirdparty components > network
?*? lwip ???>
lwip version (lwip?2.1.2) ???>
?*? udhcpd (DHCP Server)
[*] ping
?*? mbedtls ???>
mbedtls version (mbedtls?2.16.0) ???>
[ ] httpclient
[ ] websocket
[ ] nghttp2
[ ] sntp
[ ] nopoll
[ ] shttpd
[ ] mqtt
> Drivers Options > other drivers
[*] rfkill drivers
> Drivers Options > other drivers > wireless devices
[*] XRADIO driver ???>
[*] Enable xradio test cmd
Xradio chip (Enable r128 driver) ???>
[*] Wi?Fi Certification of WFA
[*] wlan station mode
[ ] wlan station mode with wps support
[*] wlan monitor mode
[*] wlan ap mode
select the source of frequency offset (SDD file) ???>
[ ] wlan ETF test
> System components > aw components > AMP Components Support
[*] AMP Network Stub Functions
[*] AMP Network Service
> System components > thirdparty components > network
[ ] lwip ????
[ ] udhcpd (DHCP Server)
[ ] ping
?*? mbedtls ???>
mbedtls version (mbedtls?2.16.0) ???>
[ ] httpclient
[ ] nghttp2
[ ] sntp
[ ] nopoll
[ ] shttpd
[ ] mqtt
Wi-Fi Manager 用于wifi 的连接管理,通信以及wifi 的一些额外功能。支持sta、ap、monitor、p2p 模式,并且集成了配网模式以及其他功能。屏蔽了底层系统的具体实现,能对接各种差异化系统平台例如 linux,rtos,xrlink(linux 系统mcu 模组)。用户如果需要进行独自的2 次开发(把对应的wifi 功能集成到各自的应用里),请重点查阅 Wi-Fi Manager 框架,Wi-Fi Manager 代码目录结构,核心层代码章节。用户如果不需要独自的2 次开发,可以直接使用 Wi-Fi Manager 提供的命令行demo,仅需查看Wi-Fi Manager demo 介绍章节。
Wi-Fi Manager: 兼容linux,xrlink,freertos 等系统。支持sta,ap,monitor 和p2p 等模式,集成了softap,ble,xconfig,soundwave 等配网功能。提供了完善的api 接口方便用户调用,同时提供了一个基本完整功能的demo,方便用户直接使用和测试。上图是Wi-Fi Manager 的软件结构,整体分为3 部分:应用层,lib 层(接口抽象层,模式抽象层,os 抽象层),os 具体实现层。
wifimager 开发包在FreeRTOS SDK 里的路径如下:
rtos/lichee/rtos?components/aw/wireless/Wi-Fi Manager
Wi-Fi Manager 的主要目录结构如下:
├── app // 用于保存配网时使用的一些配网工具。
├── core // 核心代码
│ ├── include // 存放核心代码相关头文件
│ │ └── wifimg.h // 对上提供的api接口头文件
│ └── src // 核心代码具体实现
│ ├── linkd.c // 配网抽象层代码
│ ├── wifimg.c // 对上提供的api接口实现代码
│ ├── wmg_common.c // 模式切换共存逻辑处理层实现代码
│ ├── wmg_sta.c // sta模式抽象层代码
│ ├── wmg_ap.c // ap模式抽象层代码
│ ├── wmg_monitor.c // monitor模式抽象层代码
│ ├── wmg_p2p.c // p2p模式抽象层代码
│ ├── expand_cmd.c // 扩展命令(与模组或系统特殊功能有关,例如获取或设置mac地址,设置特殊模组的ioct等)
│ └── os // 具体os(linux,xrlink,freertos)模式功能实现代码
├── demo // 比较完整功能的demo实例
│ ├── wifi.c
│ └── wifi_daemon.c
├── files // 相关的配置文件
.
├── include
│ ├── linkd.h
│ ├── os
│ ├── wifi_log.h
│ ├── wifimg.h
│ ├── wmg_ap.h
│ ├── wmg_common.h
│ ├── wmg_monitor.h
│ ├── wmg_p2p.h
│ ├── expand_cmd.h
│ └── wmg_sta.h
└── src
├── linkd.c
├── log
├── os
│ ├── linux // (在非linux系统该目录不存在)
│ ├── xrlink // (在非xrlink系统该目录不存在)
│ └── freertos // (在非freertos系统该目录不存在)
├── wifimg.c
├── wmg_ap.c
├── wmg_common.c
├── wmg_monitor.c
├── wmg_p2p.c
├── expand_cmd.c
└── wmg_sta.c
核心代码里各文件调用关系图如下:
该章节主要用于描述核心代码中使用到的一些关键的结构体。不需要单独阅读该章节,该章节属于查询性质,当在其他章节中查看到需要查询的结构体时再查询该章节即可。该章节的关键结构体都在?Wi-Fi Manager/core/include/wifimg.h
?文件里定义。
结构体描述:该结构体主要用于定义Wi-Fi Manager 各函数执行后的返回码
typedef enum {
WMG_STATUS_SUCCESS = 0,
WMG_STATUS_FAIL = ?1,
WMG_STATUS_NOT_READY = ?2,
WMG_STATUS_NOMEM = ?3,
WMG_STATUS_BUSY = ?4,
WMG_STATUS_UNSUPPORTED = ?5,
WMG_STATUS_INVALID = ?6,
WMG_STATUS_TIMEOUT = ?7,
WMG_STATUS_UNHANDLED = ?8,
} wmg_status_t;
结构体描述:该结构体主要用于定义Wi-Fi Manager 的模式
typedef enum {
WIFI_MODE_UNKNOWN = 0b0,
WIFI_STATION = 0b1,
WIFI_AP = 0b10,
WIFI_MONITOR = 0b100,
WIFI_P2P = 0b1000,
} wifi_mode_t;
结构体描述:该结构体主要用于定义Wi-Fi Manager 对网卡设备状态的识别
typedef enum {
WLAN_STATUS_DOWN,
WLAN_STATUS_UP,
} wifi_dev_status_t;
结构体描述:该结构体主要用于定义Wi-Fi Manager 收到的回调消息的类型
typedef enum {
WIFI_MSG_ID_DEV_STATUS,
WIFI_MSG_ID_STA_CN_EVENT,
WIFI_MSG_ID_STA_STATE_CHANGE,
WIFI_MSG_ID_AP_CN_EVENT,
WIFI_MSG_ID_P2P_CN_EVENT,
WIFI_MSG_ID_P2P_STATE_CHANGE,
WIFI_MSG_ID_MONITOR,
WIFI_MSG_ID_MAX,
} wifi_msg_id_t;
结构体描述:该结构体主要用于定义Wi-Fi Manager 的加密方式
typedef enum {
WIFI_SEC_NONE,
WIFI_SEC_WEP,
WIFI_SEC_WPA_PSK,
WIFI_SEC_WPA2_PSK,
WIFI_SEC_WPA3_PSK,
} wifi_secure_t;
结构体描述:该结构体主要用于定义Wi-Fi Manager 的station 模式状态
typedef enum {
WIFI_STA_IDLE,
WIFI_STA_CONNECTING,
WIFI_STA_CONNECTED,
WIFI_STA_OBTAINING_IP,
WIFI_STA_NET_CONNECTED,
WIFI_STA_DHCP_TIMEOUT,
WIFI_STA_DISCONNECTING,
WIFI_STA_DISCONNECTED,
} wifi_sta_state_t;
结构体描述:该结构体主要用于定义Wi-Fi Manager 的station 模式在连接ap 过程中的事件
typedef enum {
WIFI_DISCONNECTED,
WIFI_SCAN_STARTED,
WIFI_SCAN_FAILED,
WIFI_SCAN_RESULTS,
WIFI_NETWORK_NOT_FOUND,
WIFI_PASSWORD_INCORRECT,
WIFI_AUTHENTIACATION,
WIFI_AUTH_REJECT,
WIFI_ASSOCIATING,
WIFI_ASSOC_REJECT,
WIFI_ASSOCIATED,
WIFI_4WAY_HANDSHAKE,
WIFI_GROUNP_HANDSHAKE,
WIFI_GROUNP_HANDSHAKE_DONE,
WIFI_CONNECTED,
WIFI_CONNECT_TIMEOUT,
WIFI_DEAUTH,
WIFI_DHCP_START,
WIFI_DHCP_TIMEOUT,
WIFI_DHCP_SUCCESS,
WIFI_TERMINATING,
WIFI_UNKNOWN,
} wifi_sta_event_t;
结构体描述:该结构体主要用于定义Wi-Fi Manager 的station 模式的一些信息
typedef struct {
int id;
int freq;
int rssi;
uint8_t bssid[6];
char ssid[SSID_MAX_LEN + 1];
uint8_t mac_addr[6];
uint8_t ip_addr[4];
uint8_t gw_addr[4];
wifi_secure_t sec;
} wifi_sta_info_t;
结构体描述:该结构体主要用于定义Wi-Fi Manager station 模式时曾经连接过的一条ap 信息
typedef struct {
int id;
char ssid[SSID_MAX_LEN + 1];
uint8_t bssid[6];
char flags[16];
} wifi_sta_list_nod_t;
结构体描述:该结构体主要用于描述Wi-Fi Manager station 模式时要连接过的ap 的配置信息,在连接某个特定ap 时,用户需要填充这个结构体。
typedef struct {
const char * ssid;
const char * password;
wifi_secure_t sec;
bool fast_connect;
} wifi_sta_cn_para_t;
结构体描述:该结构体主要用于定义Wi-Fi Manager station 模式时扫描到的一条ap 结果包含什么内容
typedef struct {
uint8_t bssid[6];
char ssid[SSID_MAX_LEN + 1];
uint32_t freq;
int rssi;
wifi_secure_t key_mgmt;
} wifi_scan_result_t;
结构体描述:该结构体主要用于描述Wi-Fi Manager ap 模式时的状态
typedef enum {
WIFI_AP_DISABLE,
WIFI_AP_ENABLE,
} wifi_ap_state_t;
结构体描述:该结构体主要用于描述Wi-Fi Manager ap 模式时的状态
typedef enum {
WIFI_AP_ENABLED = 1,
WIFI_AP_DISABLED,
WIFI_AP_STA_DISCONNECTED,
WIFI_AP_STA_CONNECTED,
WIFI_AP_UNKNOWN,
} wifi_ap_event_t;
结构体描述:该结构体主要用于定义Wi-Fi Manager ap 模式时开启的ap 热点的配置信息
typedef struct {
char *ssid;
char *psk;
wifi_secure_t sec;
uint8_t channel;
int key_mgmt;
uint8_t mac_addr[6];
uint8_t ip_addr[4];
uint8_t gw_addr[4];
char *dev_list[STA_MAX_NUM];
uint8_t sta_num;
} wifi_ap_config_t;
结构体描述:该结构体主要用于定义Wi-Fi Manager monitor 模式的状态
typedef enum {
WIFI_MONITOR_DISABLE,
WIFI_MONITOR_ENABLE,
} wifi_monitor_state_t;
结构体描述:该结构体主要用于描述Wi-Fi Manager monitor 模式时收到的帧的内容
typedef struct {
uint8_t *data;
uint32_t len;
uint8_t channel;
void *info;
} wifi_monitor_data_t;
typedef struct {
char *dev_name;
int listen_time;
int p2p_go_intent;
bool auto_connect;
} wifi_p2p_config_t;
typedef struct {
uint8_t bssid[6];
int mode;
int freq;
char ssid[SSID_MAX_LEN + 1];
} wifi_p2p_info_t;
typedef enum {
WIFI_P2P_ENABLE,
WIFI_P2P_DISABLE,
WIFI_P2P_CONNECTD_GC,
WIFI_P2P_CONNECTD_GO,
WIFI_P2P_DISCONNECTD,
} wifi_p2p_state_t;
typedef enum {
WIFI_P2P_DEV_FOUND,
WIFI_P2P_DEV_LOST,
WIFI_P2P_PBC_REQ,
WIFI_P2P_GO_NEG_RQ,
WIFI_P2P_GO_NEG_SUCCESS,
WIFI_P2P_GO_NEG_FAILURE,
WIFI_P2P_GROUP_FOR_SUCCESS,
WIFI_P2P_GROUP_FOR_FAILURE,
WIFI_P2P_GROUP_STARTED,
WIFI_P2P_GROUP_REMOVED,
WIFI_P2P_CROSS_CONNECT_ENABLE,
WIFI_P2P_CROSS_CONNECT_DISABLE,
/*Wi-Fi Manager self?defined state*/
WIFI_P2P_SCAN_RESULTS,
WIFI_P2P_GROUP_DHCP_DNS_FAILURE,
WIFI_P2P_GROUP_DHCP_SUCCESS,
WIFI_P2P_GROUP_DHCP_FAILURE,
WIFI_P2P_GROUP_DNS_SUCCESS,
WIFI_P2P_GROUP_DNS_FAILURE,
WIFI_P2P_UNKNOWN,
} wifi_p2p_event_t;
WIFI_P2P_DEV_FOUND:寻找p2p 设备事件
WIFI_P2P_DEV_LOST:p2p 设备丢失事件
typedef struct {
wifi_msg_id_t id;
union {
wifi_dev_status_t d_status;
wifi_sta_event_t event;
wifi_sta_state_t state;
wifi_ap_event_t ap_event;
wifi_ap_state_t ap_state;
wifi_monitor_state_t mon_state;
wifi_monitor_data_t *frame;
wifi_p2p_event_t p2p_event;
wifi_p2p_state_t p2p_state;
} data;
} wifi_msg_data_t;