1 Star 0 Fork 1K

bigA2021 / drivers_peripheral_11.15

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
README.md 17.16 KB
一键复制 编辑 原始数据 按行查看 历史

WLAN

Introduction

This repository defines and implements the WLAN-related Hardware Driver Interfaces (HDIs) which provide the following functionalities:

  1. Creating and stopping a channel between the hardware abstraction layer (HAL) and the WLAN driver
  2. Obtaining the WLAN features supported by the device
  3. Creating a WLAN feature instance

Figure 1 WLAN driver module architecture

Directory Structure

The directory structure of the WLAN repository is as follows:

/drivers/peripheral/wlan
├── client             # Client that implements the communication between the user space and kernel space
│   └── include       # Client header files
│   └── src           # Client code
├── hal                # HAL code
│   └── include       # HAL header files
│   └── src           # HAL code implementation
├── interfaces         # APIs exposed externally
│   └── include       # Header files containing APIs exposed externally

Available APIs

The WLAN HAL module provides APIs for the Wi-Fi service, such as creating and destroying an IWiFi object and setting the MAC address. The following table lists the APIs.

Table 1 APIs provided by the WLAN HAL module

Header File

API

Description

wifi_hal.h

int32_t WifiConstruct(struct IWiFi **wifiInstance);

Creates an IWiFi object with basic capabilities.

int32_t WifiDestruct(struct IWiFi **wifiInstance);

Destroys an IWiFi object.

int32_t (*start)(struct IWiFi *);

Creates a channel between the HAL and the driver and obtains the NIC supported by the driver.

int32_t (*stop)(struct IWiFi *);

Stops the channel between the HAL and the driver.

int32_t (*getSupportFeature)(uint8_t *supType, uint32_t size);

Obtains the WLAN features available for the device no matter whether it works as an AP, STA, or P2P server/client.

int32_t (*getSupportCombo)(uint64_t *combo, uint32_t size);

Obtains the WLAN features available for the device that plays different roles simultaneously (any combination of AP, STA, and P2P server/client).

int32_t (*createFeature)(int32_t type, struct IWiFiBaseFeature **ifeature);

Creates an IWiFiBaseFeature object of a specified type.

int32_t (*getFeatureByIfName)(const char *ifName, struct IWiFiBaseFeature **ifeature);

Obtains an IWiFiBaseFeature object based on a specified network interface name.

int32_t (*registerEventCallback)(CallbackFunc cbFunc);

Registers a callback to listen for IWiFi asynchronous events.

int32_t (*unRegisterEventCallback)(void);

Unregisters an IWiFi callback.

int32_t (*destroyFeature)(struct IWiFiBaseFeature *ifeature);

Destroys a specified IWiFiBaseFeature object.

int32_t (*resetDriver)(const uint8_t chipId);

Resets the WLAN driver with a specified chip ID.

wifi_hal_ap_feature.h

int32_t (*getAssociatedStas)(const struct IWiFiAp *apFeature, struct StaInfo *staInfo, uint32_t count, uint32_t *num);

Obtains information (MAC addresses only in the current version) about all the connected STAs.

int32_t (*setCountryCode)(const struct IWiFiAp *apFeature, const char *code, uint32_t len);

Sets the country/region code.

wifi_hal_sta_feature.h

int32_t (*setScanningMacAddres)(const struct IWiFiSta *staFeature, unsigned char *scanMac, uint8_t len);

Sets a single MAC address to scan for.

wifi_hal_base_feature.h

const char *(*getNetworkIfaceName)(const struct IWiFiBaseFeature *baseFeature);

Obtains the name of a network interface.

int32_t (*getFeatureType)(const struct IWiFiBaseFeature *);

Obtains the feature type.

int32_t (*setMacAddress)(const struct IWiFiBaseFeature *, unsigned char *, uint8_t);

Sets the MAC address.

int32_t (*getDeviceMacAddress)(const struct IWiFiBaseFeature *, unsigned char *, uint8_t);

Obtains the device MAC address.

int32_t (*getValidFreqsWithBand)(const struct IWiFiBaseFeature *baseFeature, int32_t band, int32_t *freqs, uint32_t count, uint32_t *num);

Obtains the frequencies supported by the 2.4 GHz or 5 GHz band.

int32_t (*setTxPower)(const struct IWiFiBaseFeature *, int32_t);

Sets the transmit power.

int32_t (*getChipId)(const struct IWiFiBaseFeature *baseFeature, uint8_t *chipId);

Obtains the chip ID of the current driver.

int32_t (*getIfNamesByChipId)(const uint8_t chipId, char **ifNames, uint32_t *num);

Obtains names of all the NICs of the current chip based on the chip ID.

Usage Guidelines

The following describes how to use the WLAN HAL module.

  1. Call the WifiConstruct function to create an IWiFi object.
  2. Use the created IWiFi object to call the start function to create a channel between the HAL and the driver and obtain the driver NIC information.
  3. Call the createFeature function to create an AP feature or STA feature. You can call functions to perform operations on the created feature (use an AP feature as an example).
  4. Call functions to perform operations, such as calling the setMacAddress function to set the MAC address and calling the getDeviceMacAddress function to obtain the device MAC address.
  5. Call the destroyFeature function to destroy the created feature.
  6. Call the stop function to stop the channel between the HAL and the driver.
  7. Call the WifiDestruct function to destroy the IWiFi object.

The sample code is as follows:

#include "wifi_hal.h"
#include "wifi_hal_sta_feature.h"
#include "wifi_hal_ap_feature.h"
#include "wifi_hal_cmd.h"
#include "wifi_hal_event.h"

#define MAC_LEN 6

static void *hal_main()
{
    int ret;
    struct IWiFi *wifi;

    /* Create an IWiFi object. */
    ret = WifiConstruct(&wifi);
    if (ret != 0 || wifi == NULL) {
        return;
    }

    /* Create a channel between the HAL and the driver. */
    ret = wifi->start(wifi);
    if (ret != 0) {
        return;
    }

    /* Create an AP feature. */
    ret = wifi->createFeature(PROTOCOL_80211_IFTYPE_AP, (struct IWiFiBaseFeature **)&apFeature);
    if (ret != 0) {
        return;
    }

    /* Obtain the device MAC address. */
    unsigned char mac[MAC_LEN] = {0};
    ret = apFeature->baseFeature.getDeviceMacAddress((struct IWiFiBaseFeature *)apFeature, mac, MAC_LEN);
    if (ret != 0) {
        return;
    }

    /* Destroy the created AP feature. */
    ret = wifi->destroyFeature((struct IWiFiBaseFeature *)apFeature);
    if (ret != 0) {
        return;
    }

    /* Stop the created channel. */
    ret = wifi->stop(wifi);
    if (ret != 0) {
        return;
    }

    /* Destroy the created IWiFi object. */
    ret = WifiDestruct(&wifi);
    if (ret != 0) {
        return;
    }
    return;
}

Repositories Involved

Driver subsystem

drivers_framework

drivers_adapter

drivers_adapter_khdf_linux

drivers_peripheral

1
https://gitee.com/biga2021/drivers_peripheral_11.15.git
git@gitee.com:biga2021/drivers_peripheral_11.15.git
biga2021
drivers_peripheral_11.15
drivers_peripheral_11.15
master

搜索帮助