STA mode – wpa_supplicant installation and use

wpa_supplicant is an open source software project, which realizes the function of managing and controlling wireless networks in WIFI STA mode. It is a tool for connecting and configuring WIFI, mainly including two programs: wpa_supplicant and wpa_cli.

Prepare third-party software as follows:

Download link: wpa_supplicant software package free download

One, wpa_supplicant installation

Description: wpa_supplicant depends on openssl and libnl.

1. Install openssl

1) Unzip

$ tar -xvzf openssl-1.1.1d.tar.gz

$ cd openssl-1.1.1d

2) Configuration

$ mkdir /home/dongao/tools/openssl //New directory

$ ./config no-asm shared –prefix=/home/dongao/tools/openssl CROSS_COMPILE=aarch64-linux-gnu- //Configuration

–prefix : used to specify the compilation result storage directory, set to the directory just created.

$ vi Makefile //Remove the -m64 inside (the -m64 command passed in FLAG)

3) Execute the installation

$ make

$ make install

4) Copy the libcrypto and libssl libraries under the lib directory to the /usr/lib directory of the ARM board root file system

$ sudo cp libcrypto.so* ~/share/wifi/lib/openssl/

$ sudo cp libssl.so* ~/share/wifi/lib/openssl/

2. Install libnl

1) Install dependent environment

$ sudo apt-get install flex

$ sudo apt-get install bison

2) Unzip

$ tar -xzf libnl-3.2.23.tar.gz

$ cd libnl-3.2.23

3) Configuration

$ mkdir /home/dongao/tools/libnl //New installation directory

$ ./configure –host=aarch64-linux-gnu –prefix=/home/dongao/tools/libnl //Configuration

–host : Used to specify the prefix of the cross compiler, set to “aarch64-linux-gnu” here;

–prefix : Used to specify the compilation result storage directory, set to the libnl folder just created.

4) install

$ make //compile

$ make install //installation

5) Copy the library files in the lib directory to the /usr/lib directory of the ARM root file system

$ cd /home/dongao/tools/libnl

$ sudo cp lib/* ~/share/wifi/lib/libnl_lib/ -rf

3. Install wpa_supplicant

1) Unzip

$ tar -xzf wpa_supplicant-2.7.tar.gz

$ cd wpa_supplicant-2.7/wpa_supplicant/

2) Configuration

$ cp defconfig.config

$ vi.config

3) compile

$ export PKG_CONFIG_PATH=/home/dongao/tools/libnl/lib/pkgconfig:$PKG_CONFIG_PATH //Specify the libnl library pkgconfig package location

$ make //compile

The successfully compiled files are as follows:

Copy wpa_cli and wpa_supplicant to ARM board.

$ wpa_supplicant -v //View version

2. Use of wpa_supplicant

Preparations: The wifi driver needs to be loaded successfully

1. Create wpa_supplicant.conf configuration file

$ vi /etc/wpa_supplicant.conf //Create a configuration file named “wpa_supplicant.conf” in the etc directory

ctrl_interface=/var/run/wpa_supplicant
ap_scan=1
network={
        scan_ssid=1
        ssid="xd iphone"
        key_mgmt=WPA-PSK
        psk="8888asdf"
}

$ mkdir /var/run/wpa_supplicant -p //wpa_supplicant tool needs to use this directory

2. Connect to wifi

$ wpa_supplicant -D nl80211 -i mlan0 -c /etc/wpa_supplicant.conf -B //Connect wifi

-D: driver name (can be multiple drivers: nl80211, wext)

-i: interface name (mlan0 is the STA NIC)

-c: configuration file

-B: run the daemon in the background

3. View the status of the mlan0 network card

$ wpa_cli -i mlan0 status //Check the connection status, the following information indicates the connection is successful

4. After connecting to wifi, dynamically obtain the ip address

$ udhcpc -i mlan0 //DHCP automatically obtains ip

Encountered a problem: Why does mlan0 have no IP address after DHCP automatically obtains ip?

Reason: After the arm motherboard obtains the ip with udhcpc, it is not directly set on the mlan0 network card. Because there is no script to set this IP (no /usr/share/udhcpc/default.script script)

$ udhcpc -h

Solution: $ udhcpc -i mlan0 -s /etc/udhcpc.script , or copy /etc/udhcpc.script to /usr/share/udhcpc/default.script and execute udhcpc -i mlan0 again.

After that mlan0 has an ip address.

5. Test

$ ping -I 172.20.10.8 www.baidu.com //Specify the mlan0 network card to ping the external network

Test OK