Cooking with UNIX/Linux
Cooking with UNIX/Linux > Wireless cards / access points

Wireless cards / access points

LINUX WIRELESS RECIPE by Frederik Dannemare

## Setup of wireless cards and wireless access points in Linux.
#
# This recipe assumes PCI-based/CardBus-based (32-bit) NICs, but
# should you instead have a PCMCIA card (16-bit) and not one of the newer
# 32-bit PCI/CardBus cards, I believe, you will also need to install the
# pcmcia package (and use hostap_cs whereever I mention hostap_pci).



## Installing hostap driver with 2.4.x kernel (easy).
#
# Download the necessary packages and associate the hostap_pci driver
# with the wlan0 interface (which we will create in a minute).
# The hostap-modules-<version> must match your kernel version.
#
apt-get install hostap-modules-2.4.26-1-386 hostap-utils wireless-tools



## Installing hostap driver with 2.6.x kernel (a bit more complicated).
#
# If you are using a 2.6 Debian kernel (e.g. kernel-image-2.6.8-4-686),
# you will not find a hostap-modules-<version> package corresponding to
# your kernel. Thus, you must instead download the hostap-source package
# to build your own hostap-modules-<version> package.
#
# Since you shouldn't build software as root, let somebody else
# own everything in /usr/src, and then build software as that user.
#
apt-get install hostap-source kernel-source-2.6.8 hostap-utils wireless-tools
chown -R frederik:frederik /usr/src
su - frederik
cd /usr/src
tar jxvf kernel-source-2.6.8.tar.bz2
tar zxvf hostap-source.tar.gz
ln -sf kernel-source-2.6.8 linux
cd linux
cp /boot/config-2.6.8-4-686 .config
fakeroot make-kpkg --append-to-version -1-686 modules_clean
fakeroot make-kpkg --append-to-version -1-686 modules_image
logout
dpkg -i /usr/src/hostap-modules-2.6.8-4-686_10.00.Custom+0.1.3-3_i386.deb
depmod -a



## Post-configuration.
#
# Associate the wlan0 network interface with the hostap_pci kernel module.
#
echo "alias wlan0 hostap_pci" >/etc/modutils/hostap
update-modules

# Ensure that you have a wlan0 section in /etc/network/interfaces
# similar to this where the interface is put into managed mode and
# having an essid and wep key matching that of the wireless access point.
#
auto wlan0
iface wlan0 inet static
        address 192.168.1.1
        netmask 255.255.255.0
        network 192.168.1.0
        broadcast 192.168.1.255
        wireless-mode managed
        wireless-essid foobar
        wireless-key 1234-5678-90aa-bbcc-ddee-ffff-ff



## Loading the correct modules.
#
# Make sure discover and hotplug doesn't load
# the orinoco and hermes driver at boot time..
#
echo "skip orinoco_pci orinoco hermes" >>/etc/discover.conf
echo -e "orinoco_pci\norinoco\nhermes" >>/etc/hotplug/blacklist

# Since we don't want to reboot, we'll manually remove orinoco/hermes for now
# and manually modprobe hostap_pci.
#
rmmod orinoco_pci orinoco hermes
modprobe hostap_pci

# Now up the interface and you're done.
#
ifup wlan0



** How to setup a Linux Wireless Access Point **



## Using a wireless card (with prism chipset) as a wireless access point.
#
# It is likely that you'll need to update the firmware on your wireless card
# in order for it to act as a wireless access point.
#
# BEWARE: As with firmware updates in general, things may to wrong
# if you are not 100% sure that you get the correct firmware for
# your specific card. No guarantees are given!

# Download newest firmware files (in .hex format) from
# http://linux.junsun.net/intersil-prism/firmware/1.7.4/
#
# Note: The particular firmwares at v1.7.4 may not necessarily
# suit your specific card. You may want to do some extra reading
# from these two URLs:
#
# http://linux.junsun.net/intersil-prism/
# http://trekweb.com/~jasonb/articles/hostap_20030727.shtml



## Check the card's NICID and get the right firmware.
#
hostap_diag wlan0

# Command output:
#
---------------------------------------------------------------------
Host AP driver diagnostics information for 'wlan0'

NICID: id=0x8013 v1.0.0 (PRISM II (2.5) Mini-PCI (SST parallel flash))
PRIID: id=0x0015 v1.0.7
STAID: id=0x001f v1.3.6 (station firmware)
---------------------------------------------------------------------

# Determine which firmware to grab by looking in this table
# http://linux.junsun.net/intersil-prism/IDtable.html
#
# For instance, the Secondary Release Code ID for my card (with
# ID 8013) is 'f', so I'll grab sf010704.hex. The 's' in this filename
# indicates that this image is for the secondary (station) firmware,
# and the 'f' indicates that this image is to be used for downloading
# it into flash (non-volatile memory).
#
# For more info regarding file name schemes have a look at:
# http://linux.junsun.net/intersil-prism/
# http://trekweb.com/~jasonb/articles/hostap_20030727.shtml



## Updating the firmware.
#
# Now let's update the card's firmware.
# First do a test run (only use -v).
#
prism2_srec -v wlan0 sf010704.hex

# Verify that all went well...
# Output should end with something like this:
#
---------------------------------------------------------------------
[...]
Generating CRC-16 (start=0x007e1800, len=65414) at 0x007e17fe
OK.
---------------------------------------------------------------------

# If all went well, do a real run now (using -vf).
#
prism2_srec -vf wlan0 sf010704.hex

# Output should end with something like this:
#
---------------------------------------------------------------------
[...]
OK.
Components after download:
  NICID: 0x8013 v1.0.0
  PRIID: 0x0015 v1.0.7
  STAID: 0x001f v1.7.4
---------------------------------------------------------------------



## hostapd (MAC address filtering on the access point)
#
apt-get install hostapd

# Now we should define which MAC addresses may access our access point.
# Keep /etc/hostapd/hostapd.deny empty, and list in /etc/hostapd/hostapd.accept
# the MAC addresses (one MAC address per line) that you will allow to connect
# to the access point.

# Configure hostapd (look at /etc/hostapd.conf or simply use the below as your
# configuration (it should be suitable for most people, I think).
# Move the original /etc/hostapd.conf to /etc/hostapd.conf.orig.

######################################################
interface=wlan0
logger_syslog=-1
logger_syslog_level=2
logger_stdout=-1
logger_stdout_level=2
debug=0
dump_file=/tmp/hostapd.dump
daemonize=1

ssid=foobar
macaddr_acl=1
accept_mac_file=/etc/hostapd/hostapd.accept
deny_mac_file=/etc/hostapd/hostapd.deny
auth_algs=1
wep_key_len_broadcast=1
wep_rekey_period=0
######################################################



## Activate our new access point.
#
# Now start hostapd and put your access point into master mode with
# WEP-encryption activated (make an rc (start/stop) script for this).
#
# Notice that if you stop and restart hostapd, you'll have to reset
# the WEP key as well (hostapd sets a random key upon startup).
#
/usr/sbin/hostapd /etc/hostapd/hostapd.conf </dev/null >/dev/null 2>&1 &
iwconfig wlan0 essid foobar
iwconfig wlan0 channel 1
iwconfig wlan0 mode master
iwconfig wlan0 key 1234-5678-90aa-bbcc-ddee-ffff-ff restricted

# Alternatively, these iwconfig values may be defined in /etc/network/interfaces
# like it is already described further above, but be aware that a restart
# of hostapd sets a random wep key upon startup which is why I suggest
# putting the above line in an rc script.



## Connecting to the new access point.
#
# Other wireless cards may now associate with this access point. Thus,
# after configuring the wireless card on your other hosts, issue these
# commands to put it into managed mode in order to associate.
#
iwconfig wlan0 essid foobar
iwconfig wlan0 mode managed
iwconfig wlan0 key 1234-5678-90aa-bbcc-ddee-ffff-ff restricted

# Alternatively, just define these values in /etc/network/interfaces
# like it is already described further above.