vwifi
implements a minimal interface to achieve basic functionalities,
such as scanning dummy Wi-Fi network, connecting, and disconnecting from it.
vwifi
is based on cfg80211 subsystem,
which works together with FullMAC drivers. At present, it only supports station mode (STA).
The following packages must be installed before building vwifi
.
In order to compile the kernel driver successfully, package versions of currently used kernel, kernel-devel and kernel-headers need to be matched.
$ sudo apt install linux-headers-$(uname -r)
Since vwifi
relies on the Linux wireless (IEEE-802.11) subsystem, iw is necessary for retrieving more information and configuring:
sudo apt install iw
Run make
to build the kernel module:
make
Load cfg80211
kernel module:
sudo modprobe cfg80211
Insert vwifi
driver:
sudo insmod vwifi.ko ssid_list='[MyHomeWiFi][MyWifi_1][MyWifi_2]'
Check network interfaces:
ip link
There should be an entry starting with owl0
, which is exactly the interface created by vwifi
.
Bring up the network interface:
sudo ip link set owl0 up
Show available wireless interfaces:
sudo iw dev
You should get something as following:
phy#0
Interface owl0
ifindex 3
wdev 0x1
addr 00:00:00:00:00:00
type managed
Dump wireless information:
sudo iw list
Reference output:
Wiphy owl
max # scan SSIDs: 69
max scan IEs length: 0 bytes
max # sched scan SSIDs: 0
max # match sets: 0
max # scan plans: 1
max scan plan interval: -1
max scan plan iterations: 0
Retry short limit: 7
Retry long limit: 4
Coverage class: 0 (up to 0m)
Available Antennas: TX 0 RX 0
Supported interface modes:
* managed
Then, perform scanning:
sudo iw dev owl0 scan
You should get the following:
BSS ca:9c:00:c6:c2:eb(on owl0)
TSF: 47065806941 usec (0d, 13:04:25)
freq: 2437
beacon interval: 100 TUs
capability: ESS (0x0001)
signal: -59.00 dBm
last seen: 0 ms ago
SSID: MyHomeWifi
SSID: MyHomeWiFi
Finally, we can connect to the dummy SSID MyHomeWiFi
:
sudo iw dev owl0 connect MyHomeWiFi
Validate the connection:
sudo iw dev owl0 link
Reference output:
Connected to 26:05:d1:60:34:c8 (on owl0)
SSID: MyHomeWiFi
freq: 2437
Change wifi list:
echo -n "[MyHomeWiFi][MyWifi_1][MyWifi_2]" | sudo tee /sys/module/vwifi/parameters/ssid_list
SSID Naming Convention:
Don't put [
or ]
in your SSID.
Also, the length of each SSID should be restricted between 0 and 32.
The default value of ssid_list
is [MyHomeWiFi]
if it's not specified explicitly by user.
Optional, you can use wireless device monitoring applications such as wavemon to
watch signal and noise levels, packet statistics, device configuration and network parameters of vwifi
.
sudo apt install wavemon
Redirect Packet to Kernel Network Stack:
On the host ingress side, if the incoming packet source IP or source MAC is same as the host, the the packet will be ignored by kernel.
In order to handle the protocol packets via kernel, we create two network namespaces (netns
) to isolate the host network environment and viwifi
network counterpart.
A network namespace is a logical copy of the network stack from the host system.
Network namespaces are useful for setting up containers or virtual environments.
Each namespace has its IP addresses, network interfaces, routing tables, and so forth.
On the other hand, a netns
need an interface to communicate with host network with L2 ability, and MACVLAN Bridge mode matches the requirement.
The MACVLAN
provides two essential functionalities for testing scenario.
- Create L2 virtual network interface for
netns
. - Binding L2 virtual network with vwifi network interface.
Hence, when owl0
received the packet, it will send to the namespace and allow kernel network stack manipulating the protocol packets.
vwifi
is released under the MIT license. Use of this source code is governed
by a MIT-style license that can be found in the LICENSE file.
- mac80211_hwsim: software simulator of 802.11 radio(s) for mac80211
- Emulating WLAN in Linux - part I: the 802.11 stack
- Emulating WLAN in Linux - part II: mac80211_hwsim
- virt_wifi: a completet virtual wireless driver that can be used as a wrapper around Ethernet.
- vwifi: simulate Wi-Fi (802.11) between Linux Virtual Machines.