# drivers_peripheral_wlan **Repository Path**: silence2455/drivers_peripheral_wlan ## Basic Information - **Project Name**: drivers_peripheral_wlan - **Description**: No description available - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 39 - **Created**: 2021-04-13 - **Last Updated**: 2021-06-21 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # WLAN - [Introduction](#section11660541593) - [Directory Structure](#section161941989596) - [Available APIs](#section1564411661810) - [Usage Guidelines](#section19806524151819) - [Repositories Involved](#section1371113476307) ## 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 ![](figures/wlan-driver-module-architecture.png "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. **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.

wifi_hal_base_feature.h

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 (*setTxPower)(const struct IWiFiBaseFeature *, int32_t);

Sets the transmit power.

## 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 station 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](https://gitee.com/openharmony/docs/blob/master/en/readme/driver-subsystem.md) [drivers\_framework](https://gitee.com/openharmony/drivers_framework/blob/master/README.md)