文档中心 > 芯片厂商开放

文档内容拷贝自:codebase_host/yunhal/opendoc/zh/yunhal_doc/wifi.md
联系人:@邢冲

1. 概述(Introduction)

YunOS WiFi 功能主要有Station Mode, Access Point Mode,等。 我们将YunHal之上称为YunOS的WiFi framework,YunHAL之下有WiFi的native daemon: wpa_supplicant, hostapd以及vendor厂商的WiFi驱动等。

2. 架构(WiFi Framework Architecture)

YunOS WiFi 软件架构如下:

wifi_software_stack

3. 实现(Implement WiFi HAL)

3.1. WifiDevice.h 说明

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);`

3.2. “继承”和实现WifiDevice接口

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发送命令

3.3. 编译

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)`

4. 测试(Vendor Test Suite)

WiFi Vendor Test Suite是基于gtest开发的,通过WifiDevice.h定义的Wifi yunhal APIs,对vendor实现的yunhal进行自动化测试,以最小的effect测试厂商实现的yunhal。在原则上,如果gtest可以正常运行,那么wifid也可以正常的使用这个yunhal,以快速方便的实现yunos wifi framework的在不同的厂商平台上的bring up。

4.1. 测试用例

模块 测试用例 说明 备注
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

4.2. 使用说明

startWpas

<em>E7_B2_98_E8_B4_B4_E5_9B_BE_E7_89_87_1</em>

scan

<em>E7_B2_98_E8_B4_B4_E5_9B_BE_E7_89_87_2</em>

5. 附录(Appendix)

FAQ

关于此文档暂时还没有FAQ
返回
顶部