Gentoo Wiki




MadWifi is short for Multiband Atheros Driver for Wireless Fidelity. The MadWifi drivers provide support for a wide range of Atheros wireless network devices.

The driver works such that your wireless device will appear as a normal network interface in the system. Additionally there is support for the Wireless Extensions API. This allows you to configure most aspects of the device using common (wireless) network tools (ifconfig, iwconfig and friends).

For a list of devices known to be compatible with MadWifi, see the MadWifi compatibility page.


Make sure you have compiled your kernel with the following options (note that the location of options in your kernel may differ).

Linux Kernel Configuration: MadWifi kernel options (before 2.6.22)
  Loadable module support
    [*] Enable loadable module support
    [*] Module unloading
    [*] Automatic kernel module loading
  Device Drivers
    [*] Networking support
    Wireless LAN (non-hamradio) --->
      [*] Wireless LAN drivers (non-hamradio) & Wireless Extensions
Linux Kernel Configuration: MadWifi kernel options (2.6.22 and later)
  Loadable module support
    [*] Enable loadable module support
    [*] Module unloading
    [*] Automatic kernel module loading
      [*] Wireless extensions: enabled 

After ensuring that you have fulfilled the MadWifi requirements, install the madwifi-ng package with: emerge -av madwifi-ng madwifi-ng-tools

The kernel module for modprobe is "ath_pci".

Installing from source

If you have installed MadWifi from portage, you should remove it first: emerge -C madwifi-ng madwifi-ng-tools

For information on different methods of obtaining MadWifi, see the MadWifi wiki article Getting MadWifi.

If you choose to use subversion, you will first need to install it with: emerge -a subversion

For instructions on installing MadWifi from source, see the MadWifi First Time How To.

Using your device as an access point

This is only about configuring your card to operate as an access point. See Wireless/Access point for information on NAT-forwarding, bridging and WEP/WPA encryption.

Your card will enter standard mode by default, but you need to bring the driver up in master mode. To accomplish this, you need to edit the module options. Note that the default behavior of etc-update will be to remove this customization, so remember to do what is necessary to keep your changes after re-emerging madwifi-ng (say, after a kernel compile).

File: /etc/modprobe.d/ath_pci
options ath_pci autocreate=ap

You'll now need to run: update-modules.

It's also possible to set the driver into master mode without needing to reload the module itself. This way, you have to take the interface down, destroy it, and rebuild it in the new mode, which goes by the name ap rather than master. Here's how it works:

ifconfig ath0 down
wlanconfig ath0 destroy
wlanconfig ath0 create wlandev wifi0 wlanmode ap

You could also skip the 0 in the last command, as wlandev will choose the first available integer if none is supplied. The benefit of this tool seems to be that you can create an arbitrary number of virtual ath interfaces, which could presumably be used to service multiple separate LANs with different access control and/or features. In any case, once you've created the new device in mode 'ap' you should see it in the output from iwconfig and it should say Mode:Master.

Note that in all the rest of the configuration you should use the 'ath0' device, rather than 'wifi0' which appears to just be a container for the rest of the stuff.

File: /etc/conf.d/net
postup() {
	if [ $1 == "ath0" ] ; then
		# Set txpower to 6
		# iwconfig ath0 txpower 6

		# Disable antenna diversity (prevent MadWifi from throwing a kernel panic, see bug #1998) and fix weak signal strength problem
		sysctl -w dev.wifi0.diversity=0
		sysctl -w dev.wifi0.txantenna=1
		sysctl -w dev.wifi0.rxantenna=1

	return 0

# net.ath0 will not work if you use the preup- or postup function to set the values of mode_ath0, essid_ath0 and config_ath0. You must set them here manually.

# set ath0 into access point mode ("master")

# master mode requires an ESSID

# If you do not set this variable, the init.d script tries to obtain one via DHCP, so we need to specify the access point's IP here
	" netmask"
# Note: ifconfig_ath0 is deprecated, use config_ath0 instead

# Set the channel (1-14)

	# Set the card's 802.11a/b/g mode:
	# Mode 0 = Autoselect (this mode will automatically detect the client's mode and change to it)
	#      1 = 802.11a
	#      2 = 802.11b
	#      3 = 802.11g
	"mode 0"

	# Enable turbo mode (only available in 5 GHz frequency range)
	# "turbo 1"

	# Disabling background scanning (fixes "stuck beacon" problem; see bug #1017)
	# This also increases the performance (see
	"bgscan 0"

	# Disable fast frames and bursting
	# "ff 0"
	# "burst 0"

	# Disable 802.1g Protection Mode
	"protmode 0"

	# Set the RSSI threshold for 802.11a/b/g mode to 11
	"rssi11a 11"
	"rssi11b 11"
	"rssi11g 11"

	# See bug #1957
	# "bmiss 50"

	# Reduce the beacon interval time (see
	"bintval 500"
	# Suppress SSID broadcasting
	# "hide_ssid 1"

# Set host_roaming to 2 before scanning and after scanning to 0
iwpriv_scan_pre_ath0="host_roaming 2"
iwpriv_scan_post_ath0="host_roaming 0"


If you get the error "Could not connect to kernel driver" (when trying to start hostapd) look in your hostapd.conf if you have enabled encryption because if you haven't, the interface isn't started correctly. For details, see the MadWifi ticket #552.


If you have any problems with building MadWifi, please first refer to "BuildProblems" on the MadWifi wiki.

Broken Regulatory Domain

Some Atheros-based cards (in particular D-Link models such as the DWL-AG530) have the regulatory domain set wrong. The domain set for these cards will work with the vendor-specific Windows drivers, but not with generic Atheros drivers such as madwifi.

To check your card's regulatory domain, type the following with MadWifi loaded, replacing "wifi0" by the device name: sysctl dev.wifi0.regdomain.

You should see output along the lines of:

dev.wifi0.regdomain = 18

If the regular domain is set to 18 (unknown, 0x12), you will need to fix it. Use these steps to patch the regdomain to 16 (FCC, 0x10):

Code: lspci -v
 0000:00:0a.0 Ethernet controller: Atheros Communications, Inc. AR5212 802.11abg NIC (rev 01)
 Subsystem: D-Link System Inc: Unknown device 3a14
 Flags: bus master, medium devsel, latency 168, IRQ 169
 Memory at ec100000 (32-bit, non-prefetchable) size=64K Capabilities: 44 Power Management version 2

The memory address shown above is 0xec100000.

If you ever want to undo this change, just run the command again with the old regdomain value.

Channel hopping

If the card constantly changing channels and can not connect to any access point, try to lock it in the desired channel: athchans -i ath0 6-6.


Retrieved from ""

Last modified: Sat, 11 Oct 2008 06:46:00 +0000 Hits: 12,354