8

I'm looking for a way to set up purely virtual (i.e. no actual signal) 802.11 network on a single device - for testing purposes in a way that would give me functionality similar to this:

  • create multiple access point interfaces (say, ap0, ap1..)
    • set their basic parameters (ssid ...)
    • set up dhcp server on each of these,
    • manage their signal strength with shell command (iw?)
    • allow cryptography management (changing passwords, encryption methods etc)
  • create single access point client interface (wifi0), that would
    • see specific access points (or all of them)
    • allow me to connect to specific interface with help of tools such an NetworkManager

it's very basic, actually, and seeing how veth driver works with ip link gave me a lot of hopes.

is it possible at all with iw tool? if so - how do I do that?

if not, how would i typically pursue the matter if I needed to implement this? by creating a fake wpa_supplicant driver that feeds data?

I'd appreciate any hints and pointers on the matter.

Tomasz W
  • 1,841
  • 1
  • 16
  • 25

2 Answers2

9

I attempted to follow hints posted by Stefano Cappa without luck. My interfaces consistently report No valid interface combinations which suggested I should be stuck (but wasn't).

Virtual WIFI can be brought up with the help of

  • mac80211_hwsim kernel module
    • module is configurable with the radios parameter indicating number of virtual physical cards (phy#).
    • Each phy# can simulate an independent wireless radio card.
    • Each phy# card gets an associated lan interface (wlan#).
    • module brings also a hwsim# interface which can be used to snoop on the pseudo-wifi traffic happening between all radio cards.
  • hostapd tool that is capable of turning any radio (including the simulated one) into an access point,
  • wpa_supplicant tool that can be used to scan the area for access points or connect to these.

I have eventually come up with a solution (took me a while, as I'm trying to achieve that with Android) that relies just on these three things. The tools would use nl80211 driver to talk to the pseudo-hardware.

My simplistic configuration files look as follows:

hostapd.conf (note, this file has more settings than required, but i'm posting all of my settings here)

interface=wlan1
driver=nl80211
logger_syslog=-1
logger_syslog_level=2
logger_stdout=-1
logger_stdout_level=2
ctrl_interface_group=0
ssid=Vamonos Pest
country_code=US
hw_mode=g
channel=1
beacon_int=100
dtim_period=2
max_num_sta=255
rts_threshold=2347
fragm_threshold=2346
macaddr_acl=0
auth_algs=3
ignore_broadcast_ssid=0
wmm_enabled=1
wmm_ac_bk_cwmin=4
wmm_ac_bk_cwmax=10
wmm_ac_bk_aifs=7
wmm_ac_bk_txop_limit=0
wmm_ac_bk_acm=0
wmm_ac_be_aifs=3
wmm_ac_be_cwmin=4
wmm_ac_be_cwmax=10
wmm_ac_be_txop_limit=0
wmm_ac_be_acm=0
wmm_ac_vi_aifs=2
wmm_ac_vi_cwmin=3
wmm_ac_vi_cwmax=4
wmm_ac_vi_txop_limit=94
wmm_ac_vi_acm=0
wmm_ac_vo_aifs=2
wmm_ac_vo_cwmin=2
wmm_ac_vo_cwmax=3
wmm_ac_vo_txop_limit=47
wmm_ac_vo_acm=0
eapol_key_index_workaround=0
eap_server=0
own_ip_addr=127.0.0.1

wpa_supplicant.conf

network={
    ssid="Vamonos Pest"
    key_mgmt=NONE
    priority=16
}

Finally launched the two:

hostapd -d hostapd.conf 
wpa_supplicant -Dnl80211 -iwlan0 -d -csupplicant.conf

that did the trick. wpa_supplicant is capable of scanning network area and finding all the virtual wifi access points. more can be created if hwsim module uses more that two radios. From here the rest is easy - start dhcp server on wlan1, dhcp client on wlan0 and you're done.

Pierz
  • 7,064
  • 52
  • 59
Tomasz W
  • 1,841
  • 1
  • 16
  • 25
0

I cannot answer to all you questions, but I can give you a hint.

You can use iw to create a virtual network interface, but be careful, because the driver of your wifi card can be limited by the manufacturer.

Try to check the "valid interface combinations" using a command like (choose the correct "phy" before) :

iw phy phy0 info

And check the maximum number of interfaces and the combination of these.

I'm not sure, but probably you can create a virtual interface directly with wpa_supplicant (like this software does for wi-fi direct). If you need help about wpa_supplicant, I suggest to you this mailing list: http://lists.shmoo.com/pipermail/hostap/

And a small example. I used a Nexus 5 with Android and wpa_supplicant. I compiled iw for Android and the result was:

> iw phy phy0 info
Supported interface modes:
              * IBSS
              * managed
              * AP
              * P2P-client
              * P2P-GO
     software interface modes (can always be added):
     valid interface combinations:
              * #{ managed } <= 2, #{ P2P-client, P2P-GO } <= 2, #{ IBSS } <= 1,
                total <= 3, #channels <= 2


 >iw dev
     phy#0
     Interface p2p1
             ifindex 24
             type managed
     Interface wlan0
             ifindex 21
             type managed
     Interface p2p0
             ifindex 20
             type managed

Obviously, if you are using a PC with linux, the number of interfaces can be higher. This is a smartphone with limited driver.

And finally, be careful, because, like explained to me by the creator of wpa_supplicant, if you want a veth with full 802.11 support you should choose the correct type, for example, using driver nl80211 and not macvtap with ip link.

Stefano Cappa
  • 575
  • 3
  • 17