mac80211_hwsim: 802.11 radio simulator for mac80211
Subsystems (2)
PATCH 1/1 mac80211_hwsim: 802.11 radio simulator for mac80211
mac80211_hwsim is a Linux kernel module that can be used to simulate arbitrary number of IEEE 802.11 radios for mac80211 on a single device. It can be used to test most of the mac80211 functionality and user space tools (e.g., hostapd and wpa_supplicant) in a way that matches very closely with the normal case of using real WLAN hardware. From the mac80211 view point, mac80211_hwsim is yet another hardware driver, i.e., no changes to mac80211 are needed to use this testing tool.
Documentation/networking/mac80211_hwsim/README new file +68 -0
@@ -0,0 +1,68 @@ +mac80211_hwsim - software simulator of 802.11 radio(s) for mac80211 +Copyright (c) 2008, Jouni Malinen <[email protected]> + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License version 2 as +published by the Free Software Foundation. + + +Introduction + +mac80211_hwsim is a Linux kernel module that can be used to simulate +arbitrary number of IEEE 802.11 radios for mac80211 on a single +device. It can be used to test most of the mac80211 functionality and +user space tools (e.g., hostapd and wpa_supplicant) in a way that +matches very closely with the normal case of using real WLAN +hardware. From the mac80211 view point, mac80211_hwsim is yet another +hardware driver, i.e., no changes to mac80211 are needed to use this +testing tool. + +The main goal for mac80211_hwsim is to make it easier for developers +to test their code and work with new features to mac80211, hostapd, +and wpa_supplicant. The simulated radios do not have the limitations +of real hardware, so it is easy to generate an arbitrary test setup +and always reproduce the same setup for future tests. In addition, +since all radio operation is simulated, any channel can be used in +tests regardless of regulatory rules. + +mac80211_hwsim kernel module has a parameter 'radios' that can be used +to select how many radios are simulates (default 2). This allows +configuration of both very simply setups (e.g., just a single access +point and a station) or large scale tests (multiple access points with +hundreds of stations). + +mac80211_hwsim works by tracking the current channel of each virtual +radio and copying all transmitted frames to all other radios that are +currently enabled and on the same channel as the transmitting +radio. Software encryption in mac80211 is used so that the frames are +actually encrypted over the virtual air interface to allow more +complete testing of encryption. + +A global monitoring netdev, hwsim#, is created independent of +mac80211. This interface can be used to monitor all transmitted frames +regardless of channel. + + +Simple example + +This example shows how to use mac80211_hwsim to simulate two radios: +one to act as an access point and the other as a station that +associates with the AP. hostapd and wpa_supplicant are used to take +care of WPA2-PSK authentication. In addition, hostapd is also +processing access point side of association. + +Please note that the current Linux kernel does not enable AP mode, so a +simple patch is needed to enable AP mode selection: +http://johannes.sipsolutions.net/patches/kernel/all/LATEST/006-allow-ap-vlan-modes.patch + + +# Build mac80211_hwsim as part of kernel configuration + +# Load the module +modprobe mac80211_hwsim + +# Run hostapd (AP) for wlan0 +hostapd hostapd.conf + +# Run wpa_supplicant (station) for wlan1 +wpa_supplicant -Dwext -iwlan1 -c wpa_supplicant.conf
Documentation/networking/mac80211_hwsim/hostapd.conf new file +11 -0
@@ -0,0 +1,11 @@ +interface=wlan0 +driver=nl80211 + +hw_mode=g +channel=1 +ssid=mac80211 test + +wpa=2 +wpa_key_mgmt=WPA-PSK +wpa_pairwise=CCMP +wpa_passphrase=12345678
Documentation/networking/mac80211_hwsim/wpa_supplicant.conf new file +10 -0
@@ -0,0 +1,10 @@ +ctrl_interface=/var/run/wpa_supplicant + +network={ + ssid="mac80211 test" + psk="12345678" + key_mgmt=WPA-PSK + proto=WPA2 + pairwise=CCMP + group=CCMP +}
drivers/net/wireless/Kconfig +13 -0
@@ -681,6 +681,19 @@ config ADM8211 Thanks to Infineon-ADMtek for their support of this driver. +config MAC80211_HWSIM + tristate "Simulated radio testing tool for mac80211" + depends on MAC80211 && WLAN_80211 + ---help--- + This driver is a developer testing tool that can be used to test + IEEE 802.11 networking stack (mac80211) functionality. This is not + needed for normal wireless LAN usage and is only for testing. See + Documentation/networking/mac80211_hwsim for more information on how + to use this tool. + + To compile this driver as a module, choose M here: the module will be + called mac80211_hwsim. If unsure, say N. + source "drivers/net/wireless/p54/Kconfig" source "drivers/net/wireless/ath5k/Kconfig" source "drivers/net/wireless/iwlwifi/Kconfig"
drivers/net/wireless/Makefile +2 -0
@@ -64,3 +64,5 @@ obj-$(CONFIG_RT2X00) += rt2x00/ obj-$(CONFIG_P54_COMMON) += p54/ obj-$(CONFIG_ATH5K) += ath5k/ + +obj-$(CONFIG_MAC80211_HWSIM) += mac80211_hwsim.o
drivers/net/wireless/mac80211_hwsim.c new file +533 -0
533 lines not on this page · raw message
Signature · 1 line
Jouni Malinen PGP id EFC895FA
Hi,
A few more minor comments:
Documentation/networking/mac80211_hwsim/README
Quoted 3 lines
Documentation/networking/mac80211_hwsim/README new file +3
-0+mac80211_hwsim is a Linux kernel module that can be used to simulate +arbitrary number of IEEE 802.11 radios for mac80211 on a single +device.
To me, that makes it sound as though you needed an underlying wireless device. Maybe that "on a single device" should just be removed?
Documentation/networking/mac80211_hwsim/README line 29
Quoted 2 lines
Documentation/networking/mac80211_hwsim/README new file +2
-0+mac80211_hwsim kernel module has a parameter 'radios' that can be used +to select how many radios are simulates (default 2). This allows
^ typo, simulated
Documentation/networking/mac80211_hwsim/README line 56
Quoted 9 lines
Documentation/networking/mac80211_hwsim/README new file +9
-0+This example shows how to use mac80211_hwsim to simulate two radios: +one to act as an access point and the other as a station that +associates with the AP. hostapd and wpa_supplicant are used to take +care of WPA2-PSK authentication. In addition, hostapd is also +processing access point side of association. + +Please note that the current Linux kernel does not enable AP mode, so a +simple patch is needed to enable AP mode selection: +http://johannes.sipsolutions.net/patches/kernel/all/LATEST/006-allow-ap-vlan-modes.patch
Ok, once this code is in I'll add a hunk to my patch there that removes this note.
drivers/net/wireless/mac80211_hwsim.c line 142
Quoted 6 lines
drivers/net/wireless/mac80211_hwsim.c new file +5
-0+ hdr->hdr.it_present =__constant_cpu_to_le32 ( + (1 <<IEEE80211_RADIOTAP_FLAGS ) | + (1 <<IEEE80211_RADIOTAP_RATE ) | + (1 <<IEEE80211_RADIOTAP_CHANNEL )); + skb->protocol =__constant_htons (ETH_P_802_2 );
No need to use the __constant_ prefix, the regular macros are smart enough to optimise out in that case; the __constant versions are only needed when the compiler expression has to be constant, e.g. for
switch (..) {
case __constant_cpu_to_le32(7): ...
}
drivers/net/wireless/mac80211_hwsim.c line 199
Quoted 3 lines
drivers/net/wireless/mac80211_hwsim.c new file +3
-0+if (memcmp (hdr->addr1, hwsim_radios[i]->wiphy->perm_addr, +ETH_ALEN ) ==0 ) + ack =1 ;
Since you never set "ack" anywhere else, you could just say
ack = memcmp(...) == 0;
and remove the =0 assignment earlier. Not that it matters, though.
Quoted 34 lines
drivers/net/wireless/mac80211_hwsim.c new file +34
-0+static void mac80211_hwsim_beacon_tx (void *arg,u8 *mac, +struct ieee80211_vif *vif) +{ +struct ieee80211_hw *hw = arg; +struct mac80211_hwsim_data *data = hw->priv; +struct sk_buff *skb; +struct ieee80211_rx_status rx_status; +int i; +struct ieee80211_tx_info *info; + +if (vif->type !=IEEE80211_IF_TYPE_AP ) +return ; + + skb =ieee80211_beacon_get (hw, vif); +if (skb ==NULL ) +return ; + info =IEEE80211_SKB_CB (skb); + +mac80211_hwsim_monitor_rx (hw, skb); + +memset (&rx_status,0 ,sizeof (rx_status)); +/* TODO: set mactime */ + rx_status.freq = data->channel->center_freq; + rx_status.band = data->channel->band; + rx_status.rate_idx = info->tx_rate_idx; +/* TODO: simulate signal strength (and optional packet drop) */ + +/* Copy skb to all enabled radios that are on the current frequency */ +for (i =0 ; i < hwsim_radio_count; i++) { +struct mac80211_hwsim_data *data2; +struct sk_buff *nskb; + +if (hwsim_radios[i] ==NULL || hwsim_radios[i] == hw) +continue ;
drivers/net/wireless/mac80211_hwsim.c line 297
Quoted 10 lines
drivers/net/wireless/mac80211_hwsim.c new file +10
-0+ data2 = hwsim_radios[i]->priv; +if (!data2->started || !data2->radio_enabled || + data->channel->center_freq != data2->channel->center_freq) +continue ; + + nskb =skb_copy (skb,GFP_ATOMIC ); +if (nskb ==NULL ) +continue ; + +ieee80211_rx_irqsafe (hwsim_radios[i], nskb, &rx_status);
Maybe there should be a helper function for all this? It seems mostly duplicated.
drivers/net/wireless/mac80211_hwsim.c line 312
Quoted 1 line
drivers/net/wireless/mac80211_hwsim.c new file +1
-0+ieee80211_iterate_active_interfaces (hw, mac80211_hwsim_beacon_tx, hw);
Hmm. You could use the _atomic version to avoid taking the RTNL, it uses RCU instead.
None of this is really all that important, so
johannes
Quoted 6 lines · Johannes Berg
Documentation/networking/mac80211_hwsim/README
Quoted 3 lines
Documentation/networking/mac80211_hwsim/README new file +3
-0+mac80211_hwsim is a Linux kernel module that can be used to simulate +arbitrary number of IEEE 802.11 radios for mac80211 on a single +device.To me, that makes it sound as though you needed an underlying wireless device. Maybe that "on a single device" should just be removed?
Agreed, removing that sounds reasonable.
Quoted 2 lines
Quoted 1 line
+to select how many radios are simulates (default 2). This allows
^ typo, simulated
Thanks, will fix.
Quoted 6 lines
Documentation/networking/mac80211_hwsim/README line 56
Quoted 3 lines
Documentation/networking/mac80211_hwsim/README new file +3
-0+Please note that the current Linux kernel does not enable AP mode, so a +simple patch is needed to enable AP mode selection: +http://johannes.sipsolutions.net/patches/kernel/all/LATEST/006-allow-ap-vlan-modes.patchOk, once this code is in I'll add a hunk to my patch there that removes this note.
By the way, what's the current plan on applying this patch to allow AP modes to be enabled? I would assume they are still disabled because AP functionality is not yet complete, but is there a clear set of features that need to be added/fixed before this change goes in?
Quoted 6 lines
drivers/net/wireless/mac80211_hwsim.c line 142
Quoted 2 lines
drivers/net/wireless/mac80211_hwsim.c new file +2
-0+ hdr->hdr.it_present =__constant_cpu_to_le32 ( + skb->protocol = __constant_htons(ETH_P_802_2);No need to use the
__constant_prefix, the regular macros are smart enough to optimise out in that case; the__constantversions are only needed when the compiler expression has to be constant, e.g. for
OK.
Quoted 6 lines
drivers/net/wireless/mac80211_hwsim.c line 199
Quoted 3 lines
drivers/net/wireless/mac80211_hwsim.c new file +3
-0+if (memcmp (hdr->addr1, hwsim_radios[i]->wiphy->perm_addr, +ETH_ALEN ) ==0 ) + ack =1 ;Since you never set "ack" anywhere else, you could just say
ack = memcmp(...) == 0;
This is in a loop, so ack must not be cleared back to zero if it was once set to 1 for an earlier radio..
Quoted 5 lines
drivers/net/wireless/mac80211_hwsim.c line 255
Quoted 2 lines
drivers/net/wireless/mac80211_hwsim.c new file +2
-0+static void mac80211_hwsim_beacon_tx (void *arg,u8 *mac, +struct ieee80211_vif *vif)Maybe there should be a helper function for all this? It seems mostly duplicated.
Yes, I was hoping to do this first, but there were some differences that I did not want to deal with at the time. I'll take a closer look at moving that to a shared function. It will likely make this bit slower, but then again, I'm not really concerned about how fast this sort of simulation code will work; it'll be much faster than actually going over the air to another host for sure ;-).
Quoted 4 lines
drivers/net/wireless/mac80211_hwsim.c line 312
Quoted 1 line
drivers/net/wireless/mac80211_hwsim.c new file +1
-0+ieee80211_iterate_active_interfaces (hw, mac80211_hwsim_beacon_tx, hw);Hmm. You could use the
_atomicversion to avoid taking the RTNL, it uses RCU instead.
Sounds reasonable. I did not even notice that version when I just stopped at the first match on 'iterate' ;-).
Quoted 3 lines
None of this is really all that important, so
Acked-by Johannes Berg <[email protected]>
Thanks!
John: I have the changes mentioned here in another patch. Would you like to get a new version of the previous patch with this merged in or a separate cleanup patch that applies on top of the previous one?
Signature · 1 line
Jouni Malinen PGP id EFC895FA
Johannes Berg
maintainerQuoted 8 lines
Quoted 7 lines
Documentation/networking/mac80211_hwsim/README line 56
Quoted 4 lines
Documentation/networking/mac80211_hwsim/README new file +3
-0+Please note that the current Linux kernel does not enable AP mode, so a +simple patch is needed to enable AP mode selection: +http://johannes.sipsolutions.net/patches/kernel/all/LATEST/006-allow-ap-vlan-modes.patchOk, once this code is in I'll add a hunk to my patch there that removes this note.
Quoted 4 lines
By the way, what's the current plan on applying this patch to allow AP modes to be enabled? I would assume they are still disabled because AP functionality is not yet complete, but is there a clear set of features that need to be added/fixed before this change goes in?
Well mostly the channel stuff, basic rate sets, rts/cts, short slot and stuff like that. See
http://wireless.kernel.org/en/developers/todo-list#APsupport
Quoted 5 lines
Quoted 2 lines
Since you never set "ack" anywhere else, you could just say
ack = memcmp(...) == 0;This is in a loop, so ack must not be cleared back to zero if it was once set to 1 for an earlier radio..
Oh, right, sorry.
Quoted 6 lines
Quoted 5 lines
drivers/net/wireless/mac80211_hwsim.c line 255
Quoted 2 lines
drivers/net/wireless/mac80211_hwsim.c new file +2
-0+static void mac80211_hwsim_beacon_tx (void *arg,u8 *mac, +struct ieee80211_vif *vif)Maybe there should be a helper function for all this? It seems mostly duplicated.
Quoted 6 lines
Yes, I was hoping to do this first, but there were some differences that I did not want to deal with at the time. I'll take a closer look at moving that to a shared function. It will likely make this bit slower, but then again, I'm not really concerned about how fast this sort of simulation code will work; it'll be much faster than actually going over the air to another host for sure ;-).
Heh. Well I didn't look too closely so if this isn't easy to do I guess you shouldn't bother, it just seemed to be very similar to me on first sight.
johannes
Quoted 3 lines · Johannes Berg
Well mostly the channel stuff, basic rate sets, rts/cts, short slot and stuff like that. See
http://wireless.kernel.org/en/developers/todo-list#APsupport
OK, thanks.
Quoted 3 lines
Heh. Well I didn't look too closely so if this isn't easy to do I guess you shouldn't bother, it just seemed to be very similar to me on first sight.
It turned out to be trivial in the current version. I think there was something else in an earlier version when I last looked at cleaning this up, but anyway, I now have a patch to use a shared function.
Signature · 1 line
Jouni Malinen PGP id EFC895FA
Quoted 3 lines · Jouni Malinen
John: I have the changes mentioned here in another patch. Would you like to get a new version of the previous patch with this merged in or a separate cleanup patch that applies on top of the previous one?
Sending just the cleanup patch sounds good.
Thanks!
John
Signature · 2 lines
John W. Linville [email protected]