Please note: This project is no longer active. The website is kept online for historic purposes only.
If you´re looking for a Linux driver for your Atheros WLAN device, you should continue here .

Installing Madwifi on Gentoo

Due to new branches of madwifi, gentoo has added new use flags for the madwifi-driver. These USE= flags choose between the HEAD, BSD and WDS branches of madwifi. The madwifi-tools ebuild has been removed from portage due to each branch having different tools. The new ebuild installs the tools per USE= flags. If current snapshot is out of date, just copy the current ebuild to your portage overlay and rename it to the new snapshot. Note: The above applies only if using experimental packages found here

Important note for recent madwifi builds. Recent madwifi builds have the autocreate feature which will create (by default) a client interface (ath0). In order to force the creation of a master version of this interface (for an AP) one must add the following line to /etc/modules.autoload.d/kernel-2.6

ath_pci autocreate=ap

Warning: when using etc-update the default for gentoo is to remove this line from /etc/modules.autoload.d/kernel-2.6

Alternatively. If this does not work, you may need to instead add the following line to /etc/modules.d/ath_pci:

options ath_pci autocreate=ap

Frequency Scaling

Using Madwifi-HEAD along with Gentoo’s kernel can cause some problems. The lesson seems to be avoid frequency scaling with and Gentoo.

User Contributed Script

Faye Pearson has written a script that gets invoked by hotplug which brings up a WiFi card, ready configured for any known access point in an area. To make it work, you’ll need some variables in the file /etc/conf.d/net: First, if the essid is broadcast by the AP.


Secondly, if you want to force the essid you can use this form:


Thanks go to Martin Ifflan, and Andy Wang for pointing out these alternative forms, and clearing up what they do.

Faye is planning on adding further functionality, but expect to find the latest version at the URL above.

As well as Faye’s script, I’ve had an email about another gentoo script, inspired by Faye’s. Roy Marples’ script has the following features:

  • Configure wireless values to the IFACE
  • Configure WEP keys and network settings per ESSID
  • Scan for a list of available ESSIDs connect to them in a preferred order
  • Basic scanning supported when the wireless driver doesn’t support scanning

Roy has also provided a sample /etc/conf/net config file, which you used to be able to find on his site. I think it may now have made it into gentoo, but don’t actually use gentoo, so can’t be sure.

Apparently there’s been quite a bit of discussion (as ever) on Gentoo’s famous forums at:

Creating athX automatically at boot time

The new madwifi approach is to create actual interface (I will use ath0) with wlanconfig against wifi0 (which appears when the appropriate modules are loaded).

The problem with this concept is that ath0 is not available at boot time and thus /etc/conf.d/wireless cannot set it up properly.

I was looking for a solution which would be along the lines of the Gentoo philosophy and the closest I got to is to create a new script in /etc/conf.d which I called wlanconfig.ath0:


depend() {
        use net
        before net.ath0

start() {
        ebegin "Creating ath0 in station mode"
        /usr/local/bin/wlanconfig ath0 create wlandev wifi0 wlanmode sta
        eend $?

It should be added to the default runlevel with

rc-update add wlanconfig.ath0 default

I am sure there is a better way, but this is at least a start. If someone has a politically correct solution I would be glad to hear about it at wojtek[at]swiatek[dot]name.

Creating athX automatically using Gentoo net scripts framework

This is another approach to automatically creating a Madwifi-ng interface when required. It makes use of existing facilties within the Gentoo networking scripts (documented in the /etc/conf.d/net.example file). Add the following to /etc/conf.d/net along with your existing ath0 configuration:

preup() {
        if [ "${IFACE}" = "ath0" ]
                /sbin/wlanconfig ath0 create wlandev wifi0 wlanmode ap
                return $?

postdown() {
        if [ "${IFACE}" = "ath0" ]
                /sbin/wlanconfig ath0 destroy

Adjust the interface names (ath0, wifi0) and mode (ap, sta etc.) to suit. I'm sure there are ways to elegantly cater for more than one interface but I leave that for those with a need.

Creating athX automatically by hotplug on Gentoo

This approach is useful if you don't want to use the Gentoo net scripts framework for wifi (e.g. you'd rather use quickswitch on a laptop). If you want to automatically have your devices created by hotplug, you should put the following script as /etc/init.d/net.wifi0:


depend() { 
        need localmount 
start() { 
        ebegin "Configure madwifi-ng devices & loading necessary modules" 
	modprobe wlan_tkip
	wlanconfig ath0 create wlandev wifi0 wlanmode sta
	wlanconfig wmon1 create wlandev wifi0 wlanmode monitor
        eend 0 
stop() { 
        ebegin "Removing modules to leave a clean slate :-)" 
        rmmod wlan_tkip
	rmmod wlan_acl
	rmmod wlan_ccmp
	rmmod wlan_wep
	rmmod wlan_xauth
	rmmod ath_pci
	rmmod ath_rate_sample
	rmmod ath_rate_onoe
	rmmod ath_rate_amrr
	rmmod ath_hal
	rmmod wlan_scan_sta
	rmmod wlan_scan_ap
	rmmod wlan
        eend 0 


  • Also creates a monitoring interface
  • Manually loads the auth module (wpa_supplicant fails to do that in my case)
  • Removes the madwifi-ng modules after you plug the card out (in case of a pcmcia network card). Currently this is necessary to allow the creation fo the same interfaces after replug (otherwise creation of ath0 is refused, it would have to be ath2)
  • You don't need to 'rc-update add' this script, as it is called automatically by hotplug.

Creating athX automatically using udev with Gentoo

The following script was taken from Brix (, allthough slightly edited to reflect changes in the ath_pci driver. This is useful if you want the device automatically configured once the module is loaded. To do this, create the following file:


# Madwifi devices
# See wlanconfig(8) for more information
# Access Point configuration
#KERNEL=="wifi[0-9]*", DRIVERS=="ath_pci", ACTION=="add", RUN+="/sbin/wlanconfig ath create wlandev %k wlanmode ap"
# Normal station configuration
KERNEL=="wifi[0-9]*", DRIVERS=="ath_pci", ACTION=="add", RUN+="/sbin/wlanconfig ath create wlandev %k wlanmode sta"

Comment / uncomment the KERNEL= line depending on if you want to run an access point or a client. To get udev to recognize the changes, either reboot your system or run udevstart.

Creating athX via the commonly used /etc/conf.d/wireless file

Many Gentoo users configure their wireless card through the wireless-tools and /etc/conf.d/wireless, such as providing it different access points to connect to.

The configuration file can also be used to set the card into adhoc mode so that net.ath0 can start in bootup via rc-update

# Set the mode to adhoc

# Give it an essid

# Set the channel

# Set the rate
iwconfig_ath0=("rate 54M")

# Give the interface an IP

# Set the mode 802.11a (1) 802.11b (2) or 802.11g (3)
#  ... just make sure that you get a matching frequency and rate
iwpriv_ath0=("mode 3")

WPA Supplicant and MadWifi not starting on boot

During a completely fresh install of Gentoo I found that MadWifi wasn't working even though I was using my existing working scripts from my old installation. It seems that is a problem with the current versions of bash, wpa_supplicant and madwifi which stops the network card from coming up using the init.d scripts. This has something to do with the way the latest version of bash (3.1) handles arrays and the scripts used for configuring the network. The workaround is to unmask sys-apps/baselayout in /etc/portage/package.keywords and emerge the latest version. It will then work fine.

N.B: I haven't tried this with the latest kernel and madwifi drivers as yet as there are a lot of unresolved references during these compilations

WPA Supplicant and MadWifi not starting on boot (2nd issue)

In the WPA examples it's shown to use the -w flag for the wpa_supplicant. But exactly this flag caused the boot problem on some systems. So just leave the -w flag.

Creating athX using 'modules' feature of newer rc net scripts

Just put this in /lib/rcscripts/net.modules.d

# char* madwifi_provides(void)
# Returns a string to change module definition for starting up
madwifi_provides() {
	echo "madwifi"

# void madwifi_depend(void)
# Sets up the dependancies for the module
madwifi_depend() {
	before wireless

# bool madwifi_check_installed(void)
# Returns 1 if ifenslave is installed, otherwise 0
madwifi_check_installed() {
	[[ ${SVCNAME} =~ "\.(wifi[[:digit:]])\." ]] || return 1

	if ! [[ -d /sys/module/ath_pci ]] ; then
		modprobe ath_pci ||
		eerror "madwifi: no madwifi device found.\
		\nProbably you should go get 'madwifi-ng' package." && return 1

	if ! [[ -d /sys/class/net/${MADDEV} ]] ; then
   	eerror "madwifi: device $MADDEV not present in system"
		return 1

	return 0

# bool madwifi_check_depends(void)
# Checks to see if we have the needed functions
madwifi_check_depends() {
	local f

	for f in interface_variable ; do
		[[ $( type -t ${f} ) == function ]] && continue
		eerror "madwifi: missing required function ${f}\n"
		return 1

	if [[ ! -x /sbin/wlanconfig ]] ; then
		eerror "madwifi: /sbin/wlanconfig not found.\
		\nProbably it's because madwifi-ng-tools package not installed"
		return 1

	return 0

# bool madwifi_pre_start(char *iface)
# starts virtual device on designated physical madwifi device
madwifi_pre_start() {
	ebegin "Creating ${IFACE} on madwifi-ng device ${MADDEV}"
	local ifvar=$( interface_variable ${IFACE} )
	local mode=$( eval echo \$\{mode_${ifvar}\} )
	local wasmode=$( wireless_get_mode ${IFACE} )  #no fear if function is undefined
	if [[ $mode == $wasmode ]] ; then 
		eend 0
		return 0
	[[ -d /sys/class/net/${IFACE} ]] && wlanconfig ${IFACE} destroy
	local create=$( wlanconfig ${IFACE} create wlandev ${MADDEV} wlanmode $mode )
	if [[ $create != ${IFACE} ]] ; then
		eend 1
		return 1
	eend 0
	return 0

#bool madwifi_stop (char* iface)
#stops destroys virtual madwifi device
madwifi_stop() {
	ebegin "Destroying ${IFACE}"
   if [[ ! -d /sys/class/net/${IFACE} ]] || wlanconfig ${IFACE} destroy  && ! [[ -d /sys/class/net/${IFACE} ]] ; then
   	eend 0
   	return 0

	eend 1
	return 1

Then, name the appropriate services in /etc/init.d after 'net.wifiN.athX' pattern. athX will be automatically created (or recreated) on wifiN device, based on your /etc/conf.d/wireless config.