文档内容拷贝自:
codebase_host/yunhal/opendoc/zh/yunhal_doc/wifi.md
联系人:@邢冲
YunOS WiFi 功能主要有Station Mode, Access Point Mode,等。 我们将YunHal之上称为YunOS的WiFi framework,YunHAL之下有WiFi的native daemon: wpa_supplicant, hostapd以及vendor厂商的WiFi驱动等。
YunOS WiFi 软件架构如下:

VendorModule接口介绍
| 域 | 类型 | 说明 |
|---|---|---|
| version | uint32_t | 模块版本 |
| id | const char* | 模块标识 |
| name | const char * | 模块名 |
| author | const char * | 作者 |
| CreateDevice() | int32_t (*CreateDevice) (const struct __vendor_module_t* module, const char* deviceID, struct __vendor_device_t** device); | 工厂方法: "生产"VendorDevice |
代码如下:
static int32_t createDevice(const VendorModule\* module, const char\* deviceID, VendorDevice\*\* outDevice) {
LOG_D("%s", \_\_func\_\_);
\*outDevice = \&(sWifiModule.device);
return 0;
}`
申明模块入口
static int32_t createDevice(const VendorModule* module, const char* deviceID, VendorDevice** outDevice);
static int32_t destroyDevice(VendorDevice* device);
typedef struct {
VendorModule common;
WifiDevice device;
} WifiModule;
static WifiModule sWifiModule = {
.common.version = 1,
.common.id = "Wifi",
.common.name = "SprdWifi",
.common.author = "alibaba",
.common.CreateDevice = createDevice,
.device = {
.common.version = 1,
.common.id = "host version",
.common.module = (VendorModule *)&sWifiModule,
.common.Destroy = destroyDevice;
.change_firmware_mode = change_firmware_mode,
.is_driver_loaded = is_wifi_driver_loaded,
.load_driver = wifi_load_driver,
.start_wpas = wifi_start_supplicant,
.stop_wpas = wifi_stop_supplicant,
.unload_driver = wifi_unload_driver,
.connect_to_supplicant = wifi_connect_to_supplicant,
.close_supplicant_connection = wifi_close_supplicant_connection,
.wait_for_event = wifi_wait_for_event,
.command = wifi_command,
.start_hostapd = wifi_start_hostapd,
.stop_hostapd = wifi_stop_hostapd,
.connect_to_hostapd = wifi_connect_to_hostapd,
.disconnect_from_hostapd = wifi_disconnect_from_hostapd,
.wait_hostapd_event = wifi_wait_hostapd_event,
.hostapd_command = wifi_hostapd_command,
}
};
VENDOR_MODULE_ENTRY(sWifiModule);`
Wifi yunhal APIs作为WifiDevice的成员函数,如上述代码,说明如下:
| 域 | 类型 | 说明 |
|---|---|---|
| version | uint32_t | 设备版本 |
| id | const char* | 设备标识 |
| module | const VendorModule* | 指向模块的指针 |
| Destroy | int32_t destroyDevice(VendorDevice* device); | “析构”函数 |
| change_firmware_mode | int (*change_firmware_mode)(unsigned int mode); | 改变wifi芯片firmware的模式 |
| is_driver_loaded | unsigned char (*is_driver_loaded)(); | 判断当前wifi驱动是否已经加载 |
| load_driver | int (*load_driver)(); | 加载wifi驱动 |
| unload_driver | int (*unload_driver)(); | 卸载wifi驱动 |
| start_wpas | int (*start_wpas)(unsigned char p2p_supported); | 启动wpa_supplicant |
| stop_wpas | int (*stop_wpas)(unsigned char p2p_supported); | 停止wpa_supplicant |
| connect_to_supplicant | int (*connect_to_supplicant)(); | 连接wpa_supplicant |
| close_supplicant_connection | void (*close_supplicant_connection)(); | 断掉和wpa_supplicant的连接 |
| wait_for_event | int (*wait_for_event)(char * buf, unsigned int buflen); | 从wpa_supplicant中读回wpa_supplicant发送出来的事件 |
| command | int (*command)(char * cmd, char * reply, unsigned int * reply_len); | 往wpa_supplicant发送命令 |
| start_hostapd | int (*start_hostapd)(); | 启动hostapd |
| stop_hostapd | int (*stop_hostapd)(); | 停止hostapd |
| connect_to_hostapd | int (*connect_to_hostapd)(char * ifname); | 建立与hostapd的连接 |
| disconnect_from_hostapd | void (*disconnect_from_hostapd)(char * ifname); | 停止与hostapd的连接 |
| wait_hostapd_event | int (*wait_hostapd_event)(char * buf, unsigned int buflen); | 从hostapd中读回其发送出来的事件 |
| hostapd_command | int (*hostapd_command)(char * cmd, char * reply, unsigned int * reply_len); | 向hostapd发送命令 |
MakeFile如下:
LOCAL_PATH:=$(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := sprdwifi
LOCAL_MODULE_PATH := usr/lib/yunhal
LOCAL_SRC_FILES := WifiDeviceImpl.c
LOCAL_CFLAGS := -std=c++11
LOCAL_C_INCLUDES := \
$(base-includes) \
$(yunhal-includes) \
$(hal-includes) \
$(libwpaclient-includes) \
$(properties-includes)
LOCAL_SHARED_LIBRARIES := liblog libproperties libwpa_client
LOCAL_LDLIBS += -lstdc++ \
-lhardware -Wl,-rpath=/usr/lib/android
LOCAL_COMPILE_SHELL_CMD := \
mkdir -p \$(XMAKE_ROOTFS)/usr/lib/yunhal/ && \
ln -sf sprdwifi.so $(XMAKE_ROOTFS)/usr/lib/yunhal/libyunhal_Wifi.so
include $(BUILD_SHARED_LIBRARY)`
WiFi Vendor Test Suite是基于gtest开发的,通过WifiDevice.h定义的Wifi yunhal APIs,对vendor实现的yunhal进行自动化测试,以最小的effect测试厂商实现的yunhal。在原则上,如果gtest可以正常运行,那么wifid也可以正常的使用这个yunhal,以快速方便的实现yunos wifi framework的在不同的厂商平台上的bring up。
| 模块 | 测试用例 | 说明 | 备注 |
|---|---|---|---|
| Station Mode | loadDriver | 检查驱动,加载驱动 | N/A |
| Station Mode | startWpas | 启动wpa_supplicant, 建立wpa_suppliant connection, ping supplicant | N/A |
| Station Mode | scan | 启动wpa_supplicant, 建立connection,scan周围环境中的AP | N/A |
startWpas

scan
