Wi-Fi STA and wpa_supplicant

  • In this section, you are going to learn

  • How to run wpa_supplicant in STA mode

#

Version

Ubuntu

Ubuntu 22.04 64 bit

Linux Kernel

6.9.0

Supplicant

wpa_supplicant 2.9

  • STEP 1: Remove if any old packages of wpa_supplicant or hostapd is present

test:~$ cd $HOME
test:~$ pwd
/home/test

test:~$ rm -rf hostap* wpa_supp*
  • Make sure internet is available in laptop to download wpa_supplicant package

test:~$ sudo wget https://w1.fi/releases/wpa_supplicant-2.9.tar.gz
  • Make sure internet is available in laptop to download libraries

test:~$ sudo apt install libnl-genl-3-dev libnl-3-dev libdbus-glib-1-dev
  • Internet is cut-off after this !

test:~$ sudo killall wpa_supplicant

test:~$ sudo killall wpa_cli

test:~$ sudo killall hostapd

test:~$ sudo killall hostapd_cli

test:~$ sudo systemctl stop NetworkManager.service

test:~$ sudo rfkill list all
0: hci0: Bluetooth
        Soft blocked: no
        Hard blocked: no
1: dell-wifi: Wireless LAN
        Soft blocked: no
        Hard blocked: no
2: dell-bluetooth: Bluetooth
        Soft blocked: no
        Hard blocked: no
3: phy0: Wireless LAN
        Soft blocked: no
        Hard blocked: no
4: phy1: Wireless LAN
        Soft blocked: no
        Hard blocked: no
5: phy2: Wireless LAN
        Soft blocked: no
        Hard blocked: no

test:~$ sudo rfkill unblock all

test:~$ sudo ifconfig wlan1 up
  • wlan1 is the name of wireless interface on this laptop

test:~$ sudo iwconfig wlan1
wlan1     IEEE 802.11  ESSID:off/any
          Mode:Managed  Access Point: Not-Associated   Tx-Power=20 dBm
          Retry short limit:7   RTS thr:off   Fragment thr:off
          Power Management:on
  • wlan1 is the name of wireless interface on this laptop

test:~$ sudo ifconfig wlan1
wlan1: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        ether 02:00:00:00:01:00  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
  • tar -xvf command extracts zipped supplicant package

test:~$ sudo tar -xvf wpa_supplicant-2.9.tar.gz
  • Change to wpa_supplicant-2.9/wpa_supplicant directory

  • Copy defconfig to .config file

  • .config file is required for make to start compilation of supplicant

test:~$ cd wpa_supplicant-2.9/wpa_supplicant

test:~/wpa_supplicant-2.9/wpa_supplicant$ cp defconfig .config

test:~/wpa_supplicant-2.9/wpa_supplicant$ make
  • Turn on hotspot in AP

  • ssid is your hotspot name

  • psk is password of your hotspot

  • ssid in ./run_supplicant.conf should match ssid in step 9

  • psk in ./run_supplicant.conf should match psk in step 9

test:~/wpa_supplicant-2.9/wpa_supplicant$ sudo vim ./run_supplicant.conf

ctrl_interface=/run/wpa_supplicant
update_config=1
network={
ssid="test_wpa2"
proto=WPA2
key_mgmt=WPA-PSK
psk="12345678"
}
  • CTRL-EVENT-CONNECTED indicates successful connection to AP

test:~/wpa_supplicant-2.9/wpa_supplicant$ sudo ./wpa_supplicant -Dnl80211 -i wlan1 -c ./run_supplicant.conf

Successfully initialized wpa_supplicant
wlan1: SME: Trying to authenticate with 02:00:00:00:00:00 (SSID='test_wpa2' freq=2437 MHz)
wlan1: Trying to associate with 02:00:00:00:00:00 (SSID='test_wpa2' freq=2437 MHz)
wlan1: Associated with 02:00:00:00:00:00
wlan1: CTRL-EVENT-SUBNET-STATUS-UPDATE status=0
wlan1: WPA: Key negotiation completed with 02:00:00:00:00:00 [PTK=CCMP GTK=CCMP]
wlan1: CTRL-EVENT-CONNECTED - Connection to 02:00:00:00:00:00 completed [id=0 id_str=]
test:~/wpa_supplicant-2.9/wpa_supplicant$ ps -N | grep -i wpa
36164 pts/2    00:00:00 wpa_supplicant
  • wpa_state=COMPLETED indicates successful connection. Check output of status

test:~/wpa_supplicant-2.9/wpa_supplicant$ sudo ./wpa_cli -i wlan1
> status
bssid=02:00:00:00:00:00
freq=2437
ssid=test_wpa2
id=0
mode=station
pairwise_cipher=CCMP
group_cipher=CCMP
key_mgmt=WPA2-PSK
wpa_state=COMPLETED
address=02:00:00:00:01:00
uuid=572cf82f-c957-5653-9b16-b5cfb298abf1

test:~/wpa_supplicant-2.9/wpa_supplicant$ sudo ./wpa_cli -i wlan1
> scan
OK
<3>CTRL-EVENT-SCAN-STARTED
<3>CTRL-EVENT-SCAN-RESULTS
>
> scan_result
bssid / frequency / signal level / flags / ssid
02:00:00:00:00:00       2437    -30     [WPA2-PSK-CCMP][ESS]    test_wpa2
>
> add_network
0
> set_network 0 ssid "test_wpa2"
OK
<3>CTRL-EVENT-SCAN-STARTED
set_network 0 key_mgmt WPA-PSK
> OK
<3>CTRL-EVENT-SCAN-RESULTS
set_network 0 proto WPA2
> OK
> set_network 0 psk "12345678"
OK
> enable_network 0
OK
<3>CTRL-EVENT-SCAN-STARTED
>
<3>CTRL-EVENT-SCAN-RESULTS
<3>SME: Trying to authenticate with 02:00:00:00:00:00 (SSID='test_wpa2' freq=2437 MHz)
<3>Trying to associate with 02:00:00:00:00:00 (SSID='test_wpa2' freq=2437 MHz)
<3>Associated with 02:00:00:00:00:00
<3>CTRL-EVENT-SUBNET-STATUS-UPDATE status=0
<3>WPA: Key negotiation completed with 02:00:00:00:00:00 [PTK=CCMP GTK=CCMP]
<3>CTRL-EVENT-CONNECTED - Connection to 02:00:00:00:00:00 completed [id=0 id_str=]
<3>CTRL-EVENT-SCAN-STARTED
>
> status
bssid=02:00:00:00:00:00
freq=2437
ssid=test_wpa2
id=0
mode=station
pairwise_cipher=CCMP
group_cipher=CCMP
key_mgmt=WPA2-PSK
wpa_state=COMPLETED
address=02:00:00:00:01:00
uuid=572cf82f-c957-5653-9b16-b5cfb298abf1
  • ESSID field in iwconfig should show ssid of AccessPoint

test:~/wpa_supplicant-2.9/wpa_supplicant$ sudo iwconfig
wlan1     IEEE 802.11  ESSID:"test_wpa2"
          Mode:Managed  Frequency:2.437 GHz  Access Point: 02:00:00:00:00:00
          Bit Rate:54 Mb/s   Tx-Power=20 dBm
          Retry short limit:7   RTS thr:off   Fragment thr:off
          Power Management:on
          Link Quality=70/70  Signal level=-30 dBm
          Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0
          Tx excessive retries:0  Invalid misc:0   Missed beacon:0

test:~/wpa_supplicant-2.9/wpa_supplicant$ sudo iw dev
phy#2
        Interface wlan1
                ifindex 6
                wdev 0x200000001
                addr 02:00:00:00:01:00
                ssid test_wpa2
                type managed
                channel 6 (2437 MHz), width: 20 MHz (no HT), center1: 2437 MHz
  • Station and AP should be in same IP subnet

  • Assign 192.168.3.1 to AP

  • Station and AP should be in same IP subnet

  • Assign 192.168.3.10 to Station

test:~/wpa_supplicant-2.9/wpa_supplicant$ sudo ifconfig wlan1 192.168.3.10 up

test:~/wpa_supplicant-2.9/wpa_supplicant$ sudo ifconfig wlan1
wlan1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.3.10  netmask 255.255.255.0  broadcast 192.168.3.255
        ether 02:00:00:00:01:00  txqueuelen 1000  (Ethernet)
        RX packets 73  bytes 13119 (13.1 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 65  bytes 13111 (13.1 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
  • 192.168.3.1 is IP address of Access Point

test:~/wpa_supplicant-2.9/wpa_supplicant$ sudo ping 192.168.3.1
PING 192.168.3.1 (192.168.3.1) 56(84) bytes of data.
64 bytes from 192.168.3.1: icmp_seq=1 ttl=64 time=0.121 ms
64 bytes from 192.168.3.1: icmp_seq=2 ttl=64 time=0.091 ms
64 bytes from 192.168.3.1: icmp_seq=3 ttl=64 time=0.090 ms
64 bytes from 192.168.3.1: icmp_seq=4 ttl=64 time=0.097 ms
64 bytes from 192.168.3.1: icmp_seq=5 ttl=64 time=0.243 ms