Wireless/Configuration

From Gentoo Linux Wiki
(Redirected from WLAN)
Jump to: navigation, search
Gentoo.png
Gentoo has an official article on:

This is a step-by-step of wireless networking (aka WiFi or WLAN).

Contents

[edit] Kernel & driver configuration

[edit] Networking section

Networking section can be configured straightforwardly:

Linux Kernel Configuration: Wireless configuration
Networking  --->
   [*] Networking support
   Wireless  --->
     <*> Improved wireless configuration API

The following is only used by very old drivers:
     [ ] Wireless extensions

mac80211:
     <*> Generic IEEE 802.11 Networking Stack (mac80211)

Or, for old kernels:
     <*> Generic IEEE 802.11 Networking Stack

     [ ]   Enable full debugging output
     ---   IEEE 802.11 WEP encryption (802.1x)
     <*>   IEEE 802.11i CCMP support
     <*>   IEEE 802.11i TKIP encryption
     <*>   Software MAC add-on to the IEEE 802.11 networking stack
     [ ]     Enable full debugging output
     [*]   Enable RAIODTAP headers for capibilities that can support it.

[edit] Driver

You often encounter problems on drivers. For the status of your chip, see Linux wireless which is very useful, the main source of Linux wireless documentation. See also Category:Wireless.

Drivers are classifed into 4 by their origin:

  1. Kernel itself
  2. Chip manufacturer
  3. Open source package
  4. Window's driver + ndiswrapper

Furthermore, you may need a firmware. All will be explained.

First, even if your driver is not in kernel, turn on the following flag:

Linux Kernel Configuration: Wireless configuration
 Device Drivers  --->
   Network device support  --->
     Wireless LAN  --->
       [*] Wireless LAN (IEEE 802.11)
       ... Select driver as needed if it's in the kernel source ...

Some drivers can simply be emerged. For example, net-wireless/madwifi-ng is for WiFi adapters based on Atheros chips.

If you need to use Windows' driver, use the translator ndiswrapper.

If a firmware is necessary, do emerge --search firmware. sys-kernel/firmware contains many firmwares.

[edit] Drivers from kernel

WiFi development is very active, so if you have troubles, try the latest kernel. Or, you can install "compat-wireless" driver; it's in fact the kernel drivers, but distributed seperately so that you don't have to upgrade the kernel each time. Its ebuilds are available at "pentoo" overlay.

Compat-wireless installation requires a bit work, so read the README (and emerge log) carefully.

It's also good to know that your device may be supported by staging drivers in the kernel, which should be considered "experimental". They become available by enabling a kernel configuration option found at the end of "drivers" section. Compat-wireless contains staging drivers, too.

[edit] Cryptography

The following should be on automatically by dependencies, but if not, turn it on:

Linux Kernel Configuration: Wireless configuration
 Cryptographic options  --->
   [*] Cryptographic API
Note: There is a minimal list of algorithms which must be enabled for wireless to function correctly, if you know this information, please add it here.

[edit] Checking if the driver loaded

If you're driver is configured correctly and supports your device, it'll appear as wlan0. Or if your driver is 3rd-party, it may be called otherwise, e.g. ra0 or ath0:

root /usr/src/linux $ ifconfig -a
dummy0    Link encap:Ethernet  HWaddr 2a:5b:e3:fc:28:79  
	  ...
lo        Link encap:Local Loopback  
	  ...
wlan0     Link encap:Ethernet  HWaddr 01:23:45:ab:cd:ef
          BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:2725 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2302 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:2579360 (2.4 MiB)  TX bytes:304309 (297.1 KiB)

Or, if net-wireless/wireless-tools is installed, you can use iwconfig:

Code: iwconfig sample output
wlan0     IEEE 802.11g  ESSID:"<removed>"
          Mode:Managed  Frequency:2.437 GHz  Access Point: <removed>
          Bit Rate:54 Mb/s   Tx-Power:15 dBm
          Retry limit:15   RTS thr:off   Fragment thr:off
          Encryption key:<removed>   Security mode:open
          Power Management:off
          Link Quality=85/100  Signal level=-48 dBm  Noise level=-103 dBm
          Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0
          Tx excessive retries:0  Invalid misc:430   Missed beacon:0

Now make the symlink in /etc/init.d/:

$ cd /etc/init.d
$ ln -s net.lo net.wlan0 
Or in general
$ ln -s net.lo net.INTERFACE

[edit] Gentoo configuration

Gentoo network configuration is done in /etc/conf.d/net. It's documented in the Gentoo handbook "Gentoo network configuration" part and the example file, /usr/share/doc/openrc-x.y.z/net.example.

It may help to set rc_logger=yes in /etc/rc.conf, and

ifconfig <device> down rmmod <module name> modprobe <module name>

See also dmesg.

[edit] Softwares

Before you edit /etc/conf.d/net, you have to install some packages for wireless. You can use Wicd or NetworkManager for easy configuration of your networks, including wireless. In this section, more low-level configuration is explained.

You need a dedicated software for WiFi. We recommend net-wireless/wpa_supplicant. Older alternative is net-wireless/wireless-tools, which does not support WPA nor WPA2. If unsure, use wpa_supplicant. (They're wireless part backends of wicd and NetworkManager.) If you want a GUI, build wpa_supplicant with qt4 USE flag.

Probably you also need dhcp client e.g. dhcpcd. Candidates are listed in the Gentoo handbook Part 4, Chap 3 and net.example (see above).

[edit] Required information

To configure your WLAN device, you need to know the following information about your access point:

  • ESSID: The wireless access point's ID. You can get the list of ESSID by commands as explained below.
Note: If the ESSID has dashes or other non-alphanumeric English characters (i.e. anything that isn't a letter or number, or that does not appear in the English alphabet) replace it with an underscore.
  • Encryption: None, WEP, WPA or others.
  • Password (also known as "key" or "passphrase"): If using any encryption.

[edit] WPA supplicant

In this section, we describe configuration with wpa_supplicant.

[edit] Basics of wpa_supplicant

Most of configuration is done in the /etc/wpa_supplicant/wpa_supplicant.conf file. An exhaustive example file is found at /usr/share/doc/wpa_supplicant-<version>/wpa_supplicant.conf.bz2. Basic instruction is well documented in Handbook's Wireless chapter. Here we merely add some tips.

First let's see /etc/conf.d/net.

File: /etc/conf.d/net
modules="wpa_supplicant"

# To use dhcp
# ** Regardless of your dhcp client **, it's "dhcp", not "dhcpcd".
config_wlan0="dhcp"

## Suffixes like _eth0 or _wlan0 are the interface name. Use ifconfig
## to check.

# For madwifi driver
wpa_supplicant_ath0="-Dmadwifi"

# For Intel ipw2100/2200 (Centrino) chips with older kernels
wpa_supplicant_ath0="-Dipw"
wpa_timeout_ath0=60

# For centrino as of kernel 2.6.15 (and probably earlier)
wpa_supplicant_ath0="-Dwext"
wpa_timeout_ath0=60

# If you use kernel's driver, you don't need "-D" option, 
# which is automatically set to "-Dwext"

# Instead of /etc/wpa_supplicant/wpa_supplicant.conf,
# you can use any configuration file:
wpa_supplicant_wlan0="-Dwext -c /path/to/file"

[edit] Checking tools

Now you can run wpa_supplicant by /etc/init.d/net.wlan0 start. You can check if your wpa_suppilcant.conf is correctly configured with runninig wpa_supplicant at hand.

Almost all you have to do is:

Scan and list the access points
$ wpa_cli scan
$ wpa_cli scan_results

How's your network?
$ wpa_cli list_networks
Selected interface 'wlan0'
network id / ssid / bssid / flags
0    <your-ap-ssid>  any   [CURRENT]

[CURRENT] means your adapter is connected to that access point.

$ wpa_cli status
Selected interface 'wlan0'
bssid=<your ap MAC address>
ssid=<your ap ssid>
id=0
mode=station
pairwise_cipher=CCMP
group_cipher=CCMP
key_mgmt=WPA2-PSK
wpa_state=4WAY_HANDSHAKE

This means password authentication is wrong. 
If it's correct, the last line will be
wpa_state=COMPLETE

If there's trouble, edit config, and restart
$ /etc/init.d/net.wlan0 restart

[edit] wpa_supplicant.conf

The wpa_supplicant configuration file is a bit tricky. Double quotes are not optional but meaningful, so be sure to follow the examples.

Shortest example:

File: /etc/wpa_supplicant/wpa_supplicant.conf
# This is a network block that connects to a specific unsecured access point.
# We give it a higher priority.
network={
	ssid="YOUR_ACCESS_POINT_NAME"
	key_mgmt=NONE
	priority=5
}

# This is a network block that connects to any unsecured access point.
# We give it a low priority so any defined blocks are preferred.
network={
	key_mgmt=NONE
	priority=-9999999
}

# If psk is used
network={
        # ssid is necessary for psk
        ssid="Your-AP-SSID"
	# You need double quotes
        psk="your-password"
        key_mgmt=WPA-PSK
        priority=5
}

# If your access point doesn't broadcast its SSID:
ap_scan=2

To use wpa_gui, the gui supplied by wpa_supplicant, you need:

File: /etc/wpa_supplicant/wpa_supplicant.conf
ctrl_interface=/var/run/wpa_supplicant
# Here group is an entry of /etc/group
ctrl_interface_group=users
update_config=1
Note: For transition from wireless-tools: You will need to comment out any config_ESSID settings, as they do not work in conjunction with wpa_supplicant.

[edit] Wireless-tools

Warning: This section is obosolete Hangfire 15:02, 16 October 2011 (GMT)

[edit] Configuring /etc/conf.d/net

It's possible to run completely different network settings per ESSID connected to - check the /etc/conf.d/wireless.example file for details on how to achieve this. Also for more details look at the Gentoo Linux Networking Handbook.

Note: /etc/conf.d/wireless is deprecated. Please put all settings in /etc/conf.d/net.

A sample configuration file would look like this:

File: /etc/conf.d/net
essid_ath1="YOUR_ACCESS_POINT"
config_ath1=( "dhcp" )
dhcpcd_ath1="-t 30" # Timeout after 30 seconds
File: /etc/conf.d/net
preferred_aps=( "MY-ESSID" )

Some cards (or drivers) may need some time to complete the association with the access point:

File: /etc/conf.d/net
sleep_scan_DEVICE="1"
sleep_associate_DEVICE="25"

Check the wireless section in /etc/conf.d/net.example for examples.

[edit] WEP Encryption

Warning: WEP is very insecure, and can be cracked in < 7 minutes by people who know what they are doing. If you have the option consider using WPA2 instead.

Up to 4 WEP keys can be specified for wireless networks. If your WEP key is in ASCII precede the key with 's:'.

File: /etc/conf.d/net
key_SSID1="s:yourkeyhere enc open"

If you WEP key is hexadecimal (containing only the digits 0-9 and letters A-F), leave out the 's:'.

File: /etc/conf.d/net
key_SSID2="aaaa-bbbb-cccc-dd" 

If you do not want to use the /etc/conf.d/net script, you can create a bash file which executes all commands manually. Note that this will only work with unencrypted or WEP protected access points. For WPA encryption, you need to use wpa_supplicant.

File: wireless-connect.sh
#!/bin/bash
ifconfig <device> up
iwconfig <device> key <WEP key>
dhcpcd <device>

Then make it executable:

chmod +x wireless-connect.sh

Many people put this in local.start to have it initiated at boot.

File: /etc/conf.d/local.start
# My init script to start the network
/home/user/myscripts/wireless-connect

[edit] Manual connection

To do all manually:

ifconfig wlan0 up iwlist wlan0 scan iwconfig wlan0 essid networkname dhcpcd wlan0

[edit] When you're done

To start the wireless connection at boot, do

rc-update add net.<device> default

[edit] Useful scripts

[edit] Wireless + Ethernet connections

Some computers (mostly laptops) have both ethernet and wireless connectors. Double network connection is generally not needed. Bringing up the wireless network interface can be prevented by the preup() function in /etc/conf.d/net (change wlan0 and eth0 as appropriate):

File: /etc/conf.d/net
preup() {
if [[ ${IFACE} == "wlan0" ]]; then
	if ifplugstatus | grep -q 'eth0: link beat detected'; then
		ewarn "Wired connection on eth0 detected, aborting configuration on ${IFACE}"
		return 1
	fi
fi
return 0
}

[edit] Wireless + Ethernet (ifplugd)

If the wired ethernet device is controlled via ifplugd we are able to use /etc/ifplugd/ifplugd.action to fire up the wireless device as soon as the ethernet cord is removed and bring it down if the cord is plugged in again. Add the lines marked new below in /etc/ifplugd/ifplugd.action:

File: /etc/ifplugd/ifplugd.action
...
case "$2" in
    up)
	if [ "${INITNG}" = "yes" ]
	then
	    ARGS="-u net/$1"
	else
	    /etc/init.d/net.wlan0 --quiet stop	# this line is new
	    modprobe -r iwl3945			# this line is new
	    ARGS="--quiet start"
	fi
	;;
    down)
	if [ "${INITNG}" = "yes" ]
	then
	    ARGS="-d net/$1"
	else
	    ARGS="--quiet stop"
	    modprobe iwl3945			# this line is new
	    /etc/init.d/net.wlan0 --quiet start	# this line is new
	fi
	;;
...

[edit] Troubleshooting

[edit] Connection times out every time

According to ArchLinux Wiki, if the connection always times out, you should set the rate of the card to 5.5M:

iwconfig wlan0 rate 5.5M auto

In Gentoo, this can be automated at startup by adding the following line to your /etc/conf.d/net:

File: /etc/conf.d/net
rate_wlan0=( "5.5M auto" )

If this does not work for you, you could also try out 11M instead of 5.5M (see this link). You can also try to change from pid to simple rate control algorithm by replacing this line config.mk:

File: config.mk
CONFIG_MAC80211_RC_DEFAULT=pid

with:

File: config.mk
CONFIG_MAC80211_RC_DEFAULT=simple

[edit] Failed to initialize WEP

If your card cannot be initialized due to an -12 error and you have error lines saying something like this:

Code: dmesg

wmaster0: Failed to initialize wep

Be sure you compiled Generic IEEE 802.11 Networking Stack into kernel (and not as a module!)

Linux Kernel Configuration: Wifi
Networking --->
  [*] Networking support
  Wireless --->
    <*> Generic IEEE 802.11 Networking Stack (mac80211)

[edit] Net services like Apache don't start if both wlan0 and eth0 aren't started

If RC strict is set to "yes", then it will require that all net devices are started before any of the net services are started, you need to set this to "no":

  • for baselayout-1: open /etc/conf.d/rc and change RC_NET_STRICT_CHECKING to "NO"
  • for baselayout-2: open /etc/rc.conf and change rc_depend_strict to "NO"

[edit] SIOCSIFADDR: No such device

It's a kernel or driver problem. Chances are you're using NDISwrapper and it's not configured correctly.

In addition one could be missing the proper microcode. For the Intel 3945ABG this situation can be resolved with:

emerge iwl3945-ucode

[edit] Prism based card behaving unreliably

Possibly cause by old buggy firmware. See here for a possible fix.

[edit] "Failed to initialize EAPOL state machines" error upon starting wpa_supplicant

Comment out the openssl lines in the wpa_supplicant config file (source: Gentoo forum):

File: /etc/wpa_supplicant/wpa_supplicant.conf
#opensc_engine_path=/usr/lib/opensc/engine_opensc.so
#pkcs11_engine_path=/usr/lib/opensc/engine_pkcs11.so
#pkcs11_module_path=/usr/lib/pkcs11/opensc-pkcs11.so

[edit] Wireless extensions missing even though the device is a wireless adapter

Wireless-Extensions must be enabled in the kernel. net-wireless/wireless-tools must be reinstalled for the new kernel.

[edit] See also

Personal tools