Page MenuHomeFreeBSD

wtap(4): Implement STA/HostAP mode and support WPA/WPA2
Needs ReviewPublic

Authored by enweiwu on Aug 17 2022, 2:56 PM.
Referenced Files
F141737378: D36243.id118342.diff
Fri, Jan 9, 4:33 PM
F141728320: D36243.id169220.diff
Fri, Jan 9, 1:02 PM
Unknown Object (File)
Mon, Jan 5, 9:48 PM
Unknown Object (File)
Mon, Dec 29, 7:54 PM
Unknown Object (File)
Fri, Dec 19, 2:16 AM
Unknown Object (File)
Thu, Dec 18, 12:44 PM
Unknown Object (File)
Sun, Dec 14, 7:47 PM
Unknown Object (File)
Sun, Dec 14, 4:57 PM
Subscribers
None

Details

Reviewers
lwhsu
bz
adrian
Group Reviewers
wireless
Summary

Below is the commit message:

Wtap originally only supported mesh/ad-hoc mode, and cannot be combined
with wpa_supplicant(8) and hostapd(8) since it's unaware of encryption/decryption. 
This commit adds support for hostap and sta mode with WPA/WPA2, thus wtap(4) 
can now be used with hostapd(8) and wpa_supplicant(8).
Test Plan

Please run the following commands in privileged mode.
In this test scenario, wlan0 and wlan1 are in hostap and station modes respectively.

Load needed kernel moduels

wlan_xauth.ko is needed for wireless networking encryption/decryption.

kldload wlan_xauth.ko
kldload wtap.ko

Create two parent devices: wtap0, wtap1

Go to /usr/src/tools/tools/wtap/wtap, and execute the commands below:

./wtap c 0
./wtap c 1

Create two children wlan devices: wlan0, wlan1

ifconfig wlan0 create wlandev wtap0 wlanmode hostap ssid test
ifconfig wlan1 create wlandev wtap1 wlanmode sta ssid test

Enable communication between wlan0 and wlan1 via Visibility Plugin:

Go to /usr/src/tools/tools/wtap/vis_map, and run the following commands:

./vis_map o
./vis_map a 0 1
./vis_map a 1 0

Attach hostapd on wlan0

Prepare the demo script hostapd.conf as below:

interface=wlan0
debug=1
ctrl_interface=/var/run/hostapd
ctrl_interface_group=wheel
ssid=test
wpa=2
wpa_passphrase=12345678
wpa_key_mgmt=WPA-PSK
wpa_pairwise=CCMP

And run the following command:

hostapd -i wlan0 hostapd.conf

Attach wpa_supplicant on wlan1

Prepare the demo script wpa_supplicant.conf as below:

network={
	ssid="test"
	psk=fe727aa8b64ac9b3f54c72432da14faed933ea511ecab15bbc6c52e7522f709a
}

And run the following command:

wpa_supplicant -i wlan1 -dd -c wpa_supplicant.conf

See connection result

After running wpa_supplicant, you can check whether wlan1 connects to wlan0 by ifconfig(8):

ifconfig wlan1 | grep bssid

If you ever want to do ping test for wlan0 and wlan1, you may use jail(8) for isolating network stack.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

sys/dev/wtap/if_wtap.c
475

Please be aware of that there is a trailing space.

sys/dev/wtap/if_wtap.c
468

Please use a tab between`struct ieee80211_frame` and *wh;

enweiwu retitled this revision from wtap(4): Implement STA/HostAP mode to wtap(4): Implement STA/HostAP mode and support WPA/WPA2.
enweiwu edited the summary of this revision. (Show Details)
enweiwu edited the test plan for this revision. (Show Details)
enweiwu added a reviewer: cy.
enweiwu removed subscribers: zlei, imp.
enweiwu edited the summary of this revision. (Show Details)
enweiwu edited the test plan for this revision. (Show Details)
enweiwu edited the summary of this revision. (Show Details)
enweiwu edited the test plan for this revision. (Show Details)

Can you upload this with more context? Either use arc or git diff -U9999 when creating the diff. That'll help to see surrounding code (and probably stop asking me silly questions ;-) )

sys/dev/wtap/if_wtap.c
430

What is this pause for? Simulate delay or wait on something else?

484

Without more context here, this looks like it's writing something somewhere. Are we sure we are not overwriting anything and still write into valid memory?

wh probably already points to the right place from line 477?

635

What happens with the mbuf in that case?

693

Indentation seems odd in Phabricator?

sys/dev/wtap/if_wtap.c
430

What is this pause for? Simulate delay or wait on something else?

I have added comments, sorry for lack of explanation.

484

Without more context here, this looks like it's writing something somewhere. Are we sure we are not overwriting anything and still write into valid memory?

wh probably already points to the right place from line 477?

I'm inserting a TSF timer into the timestamp field in a probe response, which is the mandatory field. I think maybe I should do the boundary check to avoid malicious probe response.

sys/dev/wtap/if_wtap.c
476

Hm, is there no net80211 routine to update the TSF in a frame that has one? We should likely go add one.

enweiwu edited the summary of this revision. (Show Details)
enweiwu edited the test plan for this revision. (Show Details)
enweiwu removed reviewers: cy, cc.

Changes:

  • Removed unnecessary TSF insertion in probe response frames
  • Removed pause() workaround for wpa_supplicant(8) race condition
  • Added ic_cryptocaps configuration to declare supported cipher suites