#
# Original File
# -------------
#	http://www.Linux-Sec.net/Wireless/wl.install.sh
#
#
# Key Sizes
# ----------
#	http://www.iss.net/wireless/WLAN_FAQ.php 
#	5 char	- 40 bit
#	6 char	- 48 bit
#
#
# MadWifi Driver ( Atheros )
# --------------
#	http://madwifi.sourceforge.net
#
#
# MadWifi FAQ
# -----------
#	http://www.mattfoster.clara.co.uk/madwifi-faq.htm
#	-- order dependent --
#	  iwconfig ath0 key XXXXXXXXXX
#	  iwconfig ath0 ap XX:XX:XX:XX:XX:XX
#	  iwconfig ath0 channel X
#	  iwconfig ath0 essid foobar
#	  iwconfig ath0 rate XXMB
#
#
# Config Options
# ---------------
#	http://www.sodan.ecc.u-tokyo.ac.jp/~okayama/memo/atheros.shtml
#	http://www.atre.t.u-tokyo.ac.jp/seminars/mech_enshu/wirelesslan.html
#
# 	http://www.wlanfr.net/forum.php?op=mess&pid=1336
#	  iwconfig ath0 mode ad-hoc
#
#	http://www.sistemistiindipendenti.org/pdf/wireless_dlink.pdf
#
#	http://mtlin.org/blog/archives/000021.html
#	  iwlist ath0 scan                list AP's the driver has scanned
#	  iwconfig ath0 essid "foo"       set the ssid to foo
#	  iwpriv ath0 mode 1              lock operation to 11a only
#	  iwpriv ath0 mode 2              lock operation to 11b only
#	  iwpriv ath0 mode 3              lock operation to 11g only
#	  iwpriv ath0 mode 0              autoselect from 11a/b/g (default)
#
#	  echo 1 > /proc/sys/net/ath/debug    enable console msgs from the driver
#	  echo 1 > /proc/net/wlan0/debug      enable console msgs from the wlan module
#	  echo hal > /proc/sys/net/ath/dump   dump h/w register state to the console
#
#
#
# 10-Dec-03 amo Install Wireless PCI card ( Netgear WQG311 -- 802.11g )
# 19-Dec-03 amo Allow for 2.6.0 vs 2.4.23 kernels
# 02-Jan-04 amo Added slackware/redhat switch
# 04-Jan-04 amo Converted to stop|start format, iwconfig, iwpriv commands
#
#
#
# Define the Wireless Network
# ----------------------------
#
CHANNEL=1
ESSID="WL.Linux-Sec.net"
INTERFACE="ath0"
IPADDR="192.168.11.11"
KEY="02468"
#
# Set the card in master mode -  for AccessPoint
MODE="Master"
NETMASK="255.255.255.0" 
#
#
# Determine broadcast and network addresses from the IP address and netmask:
#
# 192.168.11.255
BROADCAST=`ipmask $NETMASK $IPADDR | cut -f 1 -d ' '`
#
# 192.168.11.0
NETWORK=`ipmask $NETMASK $IPADDR | cut -f 2 -d ' '`
#
#
# Set up the WiFi card
#
echo "Configuring Wireless: ${INTERFACE}:"
#
if [ `uname -r` = "2.6.0" ];
then
  #
  WLAN="/lib/modules/`uname -r`/net/wlan.ko"
  HAL="/lib/modules/`uname -r`/net/ath_hal.ko"
  PCI="/lib/modules/`uname -r`/net/ath_pci.ko"
  #
else
  #
  WLAN="/lib/modules/`uname -r`/net/wlan.o"
  HAL="/lib/modules/`uname -r`/net/ath_hal.o"
  PCI="/lib/modules/`uname -r`/net/ath_pci.o"
  #
fi
#
#
# First stop the network
# -----------------------
#
stop () {
  #
  if [ -f /etc/redhat-release ];
  then
    /etc/rc.d/init.d/network stop
  fi
  #
  if [ -f /etc/slackware-version ];
  then
    ifconfig ath0 down
  fi
  #
  #
  # Unload the wireless modules
  #
  rmmod ath_pci
  rmmod wlan
  rmmod ath_hal
  #
} # stop
#
#
#
# Load the wireless modules and add the wireless routes
# -----------------------------------------------------
#
start() {
  #
  # Add the wireless drivers
  # ------------------------
  insmod $WLAN
  #
  insmod  $HAL
  #
  insmod  $PCI
  #
  #
  # Restart with the wirless network ( ath0 )
  # --------------------------------
  if [ -f /etc/redhat-release ];
  then
    #
    /etc/rc.d/init.d/network start
    #
    # other end of the wireless connection
    #
    route add -net 192.168.11.0 gw 192.168.11.11 netmask 255.255.255.0 ath0
  fi
  #
  if [ -f /etc/slackware-version ];
  then
    #
    #
    # Set up as a 'master'
    iwconfig ath0 mode $MODE essid "$ESSID" channel $CHANNEL 
    #
    #
    # Define the Access Point on ath0 
    # -------------------------------
    ifconfig ${INTERFACE} ${IPADDR} broadcast ${BROADCAST} netmask ${NETMASK}
    #
    # route add -net $NETWORK gw $GATEWAY netmask $NETMASK ath0
    #
    #
    # autoselect from 11a/b/g (default)
    iwpriv ${INTERFACE} mode 0
    #
    iwconfig ${INTERFACE} key ${KEY}
    #
  fi
  #
} # start
#
#
#
case "$1" in
	#
  "start")
	start
	;;
	#
  "stop")
	stop
	;;
	#
  "status")
	#
	echo ""
	echo "ifconfig -v"
	ifconfig -v
	#
	#
	echo ""
	echo "lsmod"
	lsmod
	# --------
	# Module                  Size  Used by    Tainted: P  
	# ath_pci                30736   1 
	# ath_hal               109792   1  [ath_pci]
	# wlan                   37056   1  [ath_pci]
	;;
  *)
	echo ""
	echo "Usage: $0 < stop|start|status >"
	echo ""
	exit 1
esac
#
#
#
# insmod  $HAL
# -------------
#	Warning: loading ath_hal/ath_hal.o will taint the kernel: non-GPL license - Proprietary
#	  See http://www.tux.org/lkml/#export-tainted for information about tainted modules
#	Module ath_hal loaded, with warnings
#
#
# insmod  $PCI
# --------------
#	ath0: 11b rates: 1Mbps 2Mbps 5.5Mbps 11Mbps
#	ath0: 11g rates: 1Mbps 2Mbps 5.5Mbps 11Mbps 6Mbps 9Mbps 12Mbps 18Mbps 24Mbps 36Mbps 48Mbps 54Mbps
#	ath0: 802.11 address: 00:09:5b:89:48:97
#
#
# dmesg
# --------------
# wlan: 0.7.1.1 BETA (Sam Leffler <sam@errno.com>)
# ath_hal: module license 'Proprietary' taints kernel.
# ath_hal: 0.9.5.3 BETA (Sam Leffler <sam@errno.com>)
# ath_pci: 0.8.3.2 BETA (Sam Leffler <sam@errno.com>)
# ath0: 11b rates: 1Mbps 2Mbps 5.5Mbps 11Mbps
# ath0: 11g rates: 1Mbps 2Mbps 5.5Mbps 11Mbps 6Mbps 9Mbps 12Mbps 18Mbps 24Mbps 36Mbps 48Mbps 54Mbps
# ath0: 802.11 address: 00:09:5b:89:48:97
# ath0: Atheros 5212: mem=0xff8f0000, irq=21
#
#
# iwconfig
# --------
#	lo        no wireless extensions.
#	eth0      no wireless extensions.
#	ath0      no wireless extensions.
#
#
# iwconfig Errors
# -----------------
#
# Error for wireless request "Set Mode" (8B06) :
#    SET failed on device ath0 ; Invalid argument.
# ath0      no private ioctls.
#
# Error for wireless request "Set Encode" (8B2A) :
#    SET failed on device ath0 ; Invalid argument.
#
#
# End of file
                                                                                                                                                  
