OpenHarmony HDF WIFI之WLAN_HDI(上) 原创

杀手来过
发布于 2022-4-9 09:45
浏览
0收藏

@[toc]

WLAN_HDI

关于WLAN HDI的介绍,可见官网文档wlan · OpenHarmony/drivers_peripheral - 码云 - 开源中国 (gitee.com),其结构可如图所示:

OpenHarmony HDF WIFI之WLAN_HDI(上)-鸿蒙开发者社区

WLAN HDI 目的是提供接口给 Wi-Fi Service调用,其提供的功能有:启动/关闭WLAN,查看连接状态,注册回调函数,启动wlan扫描等。

一、WILAN HAL

WLAN HAL模块作为HDI的中间层,提供给Wi-Fi service IWiFi 对象,以及IWiFiSta、IWiFiAp、IWiFiBaseFeature对象来发送和接受WLAN 命令。

struct IWiFi {
    //打开hal层和driver的通道
    int32_t (*start)(struct IWiFi *iwifi);
    //关闭hal层和driver的通道
    int32_t (*stop)(struct IWiFi *iwifi);
	//获取wifi驱动支持的feature
    int32_t (*getSupportFeature)(uint8_t *supType, uint32_t size);
	//获取wifi驱动支持的feature组合
    int32_t (*getSupportCombo)(uint64_t *combo, uint32_t size);
    //创建一个feature
    int32_t (*createFeature)(int32_t type, struct IWiFiBaseFeature **ifeature);
    int32_t (*getFeatureByIfName)(const char *ifName, struct IWiFiBaseFeature **ifeature);
	//注册回调函数监听 wifi event 
    int32_t (*registerEventCallback)(CallbackFunc cbFunc, const char *ifName);
    int32_t (*unregisterEventCallback)(CallbackFunc cbFunc, const char *ifName);
    int32_t (*destroyFeature)(struct IWiFiBaseFeature *ifeature);
	//复位芯片驱动程序
    int32_t (*resetDriver)(const uint8_t chipId, const char *ifName);
    //get net device infos.
    int32_t (*getNetDevInfo)(struct NetDeviceInfoResult *netDeviceInfoResult);
};

1.1、IWiFi

WifiConstruct用于创建 IWiFi 对象,并对其函数赋值。开发者就可以调用IWiFi对象的方法创建IWiFiSta、IWiFiAp、IWiFiBaseFeature对象。再通过这三个对象发送具体的WIFI命令

int32_t WifiConstruct(struct IWiFi **wifiInstance)
{
    static bool isInited = false;
    static struct IWiFi singleWifiInstance;

    if (!isInited) {
        if (HalMutexInit() != HDF_SUCCESS) {
            HDF_LOGE("%s: HalMutexInit failed, line: %d\n", __FUNCTION__, __LINE__);
            return HDF_FAILURE;
        }
        //给函数赋值
        singleWifiInstance.start = Start;
        singleWifiInstance.stop = Stop;
        singleWifiInstance.getSupportFeature = GetSupportFeature;
        singleWifiInstance.getSupportCombo = GetSupportCombo;
        singleWifiInstance.createFeature = CreateFeature;
        singleWifiInstance.getFeatureByIfName = GetFeatureByIfName;
        singleWifiInstance.destroyFeature = DestroyFeature;
        singleWifiInstance.registerEventCallback = HalRegisterEventCallback;
        singleWifiInstance.unregisterEventCallback = HalUnregisterEventCallback;
        singleWifiInstance.resetDriver = ResetDriver;
        singleWifiInstance.getNetDevInfo = GetNetDevInfo;
        InitIWiFiList();
        isInited = true;
    }
    (*wifiInstance) = &singleWifiInstance;
    return HDF_SUCCESS;
}

1.2、IWiFiBaseFeature

IWiFiSta、IWiFiAp都是基于IWiFiBaseFeature的扩展,我们以IWiFiSta 为例,了解HAL层是如何发送命令的。

struct IWiFiSta {
    //继承了IWiFiBaseFeature
    struct IWiFiBaseFeature baseFeature; 
    //扫描指定的mac地址
    int32_t (*setScanningMacAddress)(const struct IWiFiSta *staFeature, unsigned char *scanMac, uint8_t len);
    //开始扫描
    int32_t (*startScan)(const char *ifName, WifiScan *scan);
};

struct IWiFiBaseFeature {
    char ifName[IFNAME_MAX_LEN];  
    int32_t type;   
	//获取网卡名称
    const char *(*getNetworkIfaceName)(const struct IWiFiBaseFeature *baseFeature);
	//获取feature类型
    int32_t (*getFeatureType)(const struct IWiFiBaseFeature *baseFeature);
	//设置mac地址
    int32_t (*setMacAddress)(const struct IWiFiBaseFeature *baseFeature, unsigned char *mac, uint8_t len);
	//获取设备mac地址
    int32_t (*getDeviceMacAddress)(const struct IWiFiBaseFeature *baseFeature, unsigned char *mac, uint8_t len);
	//获取wifi带宽
    int32_t (*getValidFreqsWithBand)(const struct IWiFiBaseFeature *baseFeature, int32_t band, int32_t *freqs,
        uint32_t count, uint32_t *num);
	//设置发送电源
    int32_t (*setTxPower)(const struct IWiFiBaseFeature *baseFeature, int32_t power);
	//获取芯片id
    int32_t (*getChipId)(const struct IWiFiBaseFeature *baseFeature, uint8_t *chipId);
	//获取网口名称
    int32_t (*getIfNamesByChipId)(const uint8_t chipId, char **ifNames, uint32_t *num);
};

首先是创建IWiFiSta,需要调用 IWiFi 对象的createFeature()方法创建,具体的内容就是填充IWiFiSta对象中的方法。

下面就以createFeature()为例,学习feature的函数是如何发送命令到wifi驱动的。

©著作权归作者所有,如需转载,请注明出处,否则将追究法律责任
2
收藏
回复
举报
1条回复
按时间正序
/
按时间倒序
motilyfor
motilyfor

hdf 架构中,wifi service不再借助wpa和驱动交互了吗

回复
2022-8-23 10:10:42
回复
    相关推荐