WLAN
Introduction
This repository defines and implements the WLAN-related Hardware Driver Interfaces (HDIs) which provide the following functionalities:
- Creating and stopping a channel between the hardware abstraction layer (HAL) and the WLAN driver
- Obtaining the WLAN features supported by the device
- 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
Usage Guidelines
The following describes how to use the WLAN HAL module.
- Call the WifiConstruct function to create an IWiFi object.
- 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.
- 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).
- 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.
- Call the destroyFeature function to destroy the created feature.
- Call the stop function to stop the channel between the HAL and the driver.
- 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;
}