WiFi Module Driver Porting and Debugging Guide

Click on the top“Hardcore Wang Classmate”, select“Pin/Star Public Account”

Get the latest benefits and resources

WiFi Module Driver Porting and Debugging Guide

Hello everyone, I am Hardcore Wang Classmate.

Recently, I have ported an SDIO type WiFi module, and here I will record the porting and debugging process.

1. WiFi Driver Configuration

When we have a new WiFi module and need to configure the driver for the project, the original manufacturer will provide you with the corresponding materials, such as the porting manual, driver code, etc., which can be used for porting. Here I will only discussSDIO type WiFi modules.

There are two compilation methods for porting the WiFi module driver:

1. Compile the driver separately
2. Compile the new WiFi driver into the kernel

In the end, both methods generate a .ko file, which can be copied to the device and successfully used by executing insmod.

(1) Compile the Driver Separately

First, save the original manufacturer’s driver code and place it in your own file path.

WiFi Module Driver Porting and Debugging Guide

1. Configure the Compilation Environment

Modify the Makefile in the driver files to configure the corresponding kernel path, cross-compilation toolchain, platform architecture, etc.
WiFi Module Driver Porting and Debugging Guide

Parameter Description:

  • KDIR: Kernel Path

  • CC: Cross Compiler

  • architecture: Platform Architecture

  • system: Operating System Used

  • platform_soc: Platform Macro

2. Configure Driver Options

In the root directory of the driver, run make menuconfig.
WiFi Module Driver Porting and Debugging Guide
Configure according to your needs, you can refer to the English description for configuration; I won’t demonstrate too much here.
Different manufacturers and different modules require different configurations. You can configure based on the manual provided by the original manufacturer for this WiFi module, or ask the manufacturer’s technical support for assistance.

WiFi Module Driver Porting and Debugging Guide

3. Driver Compilation

The compilation methods may vary slightly depending on the manufacturer and chip. Here, I will introduce three common compilation methods.
a. Direct Compilation
make; make strip
b. Compile with Parameters
WiFi Module Driver Porting and Debugging Guide

Parameter Description:

  • KDIR: Kernel Path
  • CC: Cross Compiler
  • architecture: Platform Architecture
  • system: Operating System Used
  • platform_soc: Platform Macro
c. Compile Using Script
Place build_driver.sh in the root directory of the driver, and add the corresponding platform according to the format.

WiFi Module Driver Porting and Debugging Guide
Execute:
  • ./build_driver.sh is the help description;
  • ./build_driver.sh XXXXX will compile the WiFi driver completely.
  • ./build_driver.sh XXXX conf will enter the driver configuration interface.

(2) Compile in the Kernel

1. Configure the Compilation Environment

Go to the kernel directory under drivers/net/wireless/.
WiFi Module Driver Porting and Debugging GuideCopy the driver source directory of XXXXXXX to the kernel directory under drivers/net/wireless/./
WiFi Module Driver Porting and Debugging GuideModify the Makefile and Kconfig files in this directory.
Makefile: Add the compilation options for the corresponding WiFi module.
WiFi Module Driver Porting and Debugging Guide
Kconfig: Introduce an external Kconfig file path in the current Kconfig file.
WiFi Module Driver Porting and Debugging Guide

2. Configure Driver Options

After modifying the Makefile and Kconfig files, return to the top-level kernel directory for configuration compilation.

Use make menuconfig to configure the path as follows:

-> Device Drivers
-> [*] Network device support
-> [*] Wireless LAN
-> <M> XXXXXXXXXXXXXXXXXXXXXXXXXXX

3. Driver Compilation

After configuration, run make ARCH=arm for compilation.
  • In Linux drivers, using the “M” form module indicator indicates that the module will be compiled as a loadable module. This means the module will be compiled into a standalone binary file rather than statically linked to the kernel.
  • These module files are usually located in /lib/modules/{kernel_version}/, where {kernel_version} is the version number of the running Linux kernel.
  • When loading or unloading the module, you can use insmod or modprobe commands to load it into the kernel, or use rmmod command to unload it.

(3) Driver Loading Test

There are two ways to copy the generated .ko file to the device.

1. The first method is to directly copy the .ko file to the device using the cp command.
2. The second method is to directly copy the generated kernel to the device and reboot; the .ko file will be in the directory lib/modules/x.x.xx (Linux kernel version).
For the first method,insmod XXXXXX.ko can load the driver into the kernel, at which point some kernel logs will be printed based on the driver code. You can also use dmesg to view.
WiFi Module Driver Porting and Debugging Guide
Enter the command ifconfig -a to check whether the network card wlanX(X=0….n) exists; it is generally wlan0 unless there are multiple WiFi modules working on the board.
WiFi Module Driver Porting and Debugging Guide

From the image, we can see that the current development board has a network card called wlan0, which corresponds to our driver.

2. Configuring WiFi Network

No matter what WiFi it is, when the driver test works normally, we need to configure the network. For WiFi to connect to the internet, we need to port some other third-party components, otherwise, it cannot connect to the router or be configured as a router. Next, we will configure these third-party components.

(1) Introduction to Basic Third-Party Libraries and Software:

  • OpenSSL: OpenSSL is an open-source software library that provides implementations of common security protocols (such as SSL/TLS) for encrypted communication and protection of network data. It is widely used in many network applications and operating systems.

  • libnl-3.5.0: libnl is a library for operating the Linux kernel’s network portion, providing management and configuration functions for network interfaces, routing tables, etc. libnl-3.5.0 is a specific version of libnl.

  • Hostapd: Hostapd is software used to implement wireless network access point (AP) functionality. It can turn a computer or device’s wireless network card into a standalone wireless access point, allowing other devices to connect to the network through it.

  • DHCP: DHCP (Dynamic Host Configuration Protocol) is a network protocol that automatically assigns IP addresses, subnet masks, gateways, DNS servers, and other network parameters to computers, simplifying the network configuration process. It is commonly used for devices in local area networks to automatically obtain IP addresses.

When we need to configure WiFi for normal internet access, we can use OpenSSL + libnl-3.5.0 + hostapd + DHCP to achieve this.

(2) Compile Hostapd

The open-source repository for hostapd:git clone git://w1.fi/hostap.git

For how to configure hostapd, you can refer to the following links; I won’t go into detail about the operation process.

https://blog.csdn.net/weixin_40209493/article/details/128716621?fromshare=blogdetail&sharetype=blogdetail&sharerId=128716621&sharerefer=PC&sharesource=qq_56921854&sharefrom=from_link
https://blog.csdn.net/weixin_43209963/article/details/128310918?fromshare=blogdetail&sharetype=blogdetail&sharerefer=PC&sharesource=qq_56921854&sharefrom=from_link

Finally, two files, hostapd and hostapd_cli, will be generated. These two files are used to configure the wireless hotspot.

(3) Compile dnsmasq

The open-source repository for dnsmasq:git clone git://w1.fi/hostap.git

For how to configure dnsmasq, you can refer to the following links; I won’t go into detail about the operation process.

https://www.xjx100.cn/news/291221.html?action=onClick
https://www.cnblogs.com/weidongliu/p/17361053.html

Finally, a file for dnsmasq will be generated, which is also used to configure the wireless hotspot.

(4) hostapd.conf

Copy the programs generated in the previous step to the TF card to control the WiFi network connection. However, before running Hostapd, you also need a hostapd.conf configuration file. This file is located in the source code directory under the Hostapd directory (the programs generated in the previous step are also in this directory).
WiFi Module Driver Porting and Debugging Guide
hostapd.conf is the main configuration file for setting up a wireless access point (AP). It is the configuration file for the HostAP (Host Access Point) driver, defining parameters and settings for the wireless network, including SSID (wireless network name), encryption method, authentication method, frequency band, wireless channel, etc. By editing the hostapd.conf file, you can customize various parameters of the wireless network to meet specific needs and security requirements.
Detailed configuration can be done according to the instructions in this file located in the source directory:
WiFi Module Driver Porting and Debugging Guide
I have written a hostapd configuration file myself:
interface=wlan0
driver=nl80211
ctrl_interface_group=0
ssid=CDR_00000
country_code=CN
ieee80211d=1
hw_mode=g
channel=11
chanlist=1 6 11
beacon_int=100
max_num_sta=10
auth_algs=1
wmm_enabled=1
wpa=2
wpa_passphrase=12345678
wpa_key_mgmt=WPA-PSK WPA-EAP
wpa_pairwise=TKIP CCM
rsn_pairwise=CCMP
wpa_group_rekey=86400

(5) Run hostapd

The WiFi function can use this wlan network card, so first check if this network card exists.
WiFi Module Driver Porting and Debugging Guide

If it exists, copy the above three files to the device.

You can enter the command to start it: /system/bin/hostapd — -d -s /data/wifi/hostapd_xj.conf

Since it needs to act as an AP, you also need to configure the DHCP server.

ifconfig p2p0 192.168.42.129
mkdir -p /var/lib/misc/
start-stop-daemon -S -q -m -b -p /var/run/dnsmasq.pid \
        -x /system/bin/dnsmasq -- --interface=p2p0 \
        --dhcp-range=192.168.42.10,192.168.42.100,1h \
        --except-interface=lo --bind-interfaces \
        --keep-in-foreground --no-poll --user=root

This creates a WiFi (AP) and allows other devices to connect.

(6) WiFi Network Test

Mobile phone connection test, can connect to this WiFi!!!
WiFi Module Driver Porting and Debugging Guide

end

Follow the public account and reply“Join Group” to jointhe technical exchange groupWiFi Module Driver Porting and Debugging Guide

Leave a Comment