Get the latest benefits and resources

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:
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.

1. Configure the Compilation Environment

Parameter Description:
-
KDIR: Kernel Path
-
CC: Cross Compiler
-
architecture: Platform Architecture
-
system: Operating System Used
-
platform_soc: Platform Macro
2. Configure Driver Options


3. Driver Compilation

Parameter Description:
-
KDIR: Kernel Path -
CC: Cross Compiler -
architecture: Platform Architecture -
system: Operating System Used -
platform_soc: Platform Macro

-
./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




2. Configure Driver Options
Use make menuconfig to configure the path as follows:
3. Driver 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.


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.
Finally, two files, hostapd and hostapd_cli, will be generated. These two files are used to configure the wireless hotspot.
(3) Compile dnsmasq
For how to configure dnsmasq, you can refer to the following links; I won’t go into detail about the operation process.
Finally, a file for dnsmasq will be generated, which is also used to configure the wireless hotspot.
(4) hostapd.conf


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

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

end
Follow the public account and reply“Join Group” to jointhe technical exchange group