#!/bin/bash # # /etc/rc.d/rc.wireless.sl5354MP.wrap # # - for Atheros AR5212A - aka SL-5354MP Aires # # # Original File # ------------- # http://Wrap-Box.net/CF/rc.wireless.MadWifi.SL5354MP.wrap # http://Linux-Wireless.org/Install-HOWTO/WL/wl.install.madwifi.sl5354mp.wrap # # # http://www.Linux-Wireless.org/Install-HowTo/WL/Install.txt - help docs # http://www.Linux-Wireless.org/Install-HowTo/WL/wl.config - config file # http://www.Linux-Wireless.org/Install-HowTo/WL/wl.install.sh - install script # # http://www.Linux-Wireless.org/Install-HowTo/WL/wl.wrap.install.sh - install script # # # ======================================================================= # Wireless Install Scripts for Atheros MiniPCI Card on WRAP motherboard # # http://www.pcengines.ch/wrap.htm - motherboard # http://www.atheros.com/xxxx - atheros miniPCI card # http://www.Wrap-Box.net/CF - minimized slackware-10 w/ wireless # # http://hpl.hp.com/personal/Jean_Tourrilhes/Linux/Tools.html - iwconfig # # http://www.Linux-Wireless.org/Install-HowTo/WL # # ======================================================================= # # # 10-Dec-03 amo Install Wireless PCI card ( Netgear WQG311 -- 802.11g ) # 17-Sep-04 amo Modified for Atheros miniPCI card # 21-Aug-05 amo Added Wrap-box and Linux-Wireless.or url for wl.install.madwifi.sl5354mp.wrap # # # VERSION="20040917" # # # # Wireless Options # ----------------- # # Host IP# of this wireless device # IPADDR="192.168.1.21" # # # Wireless Gateway # GATEWAY="192.168.1.1" # # # Wired gateway to the internet ( when it's the AP for the wireless network ) # OUTSIDE="www.xxx.yyy.zzz" # # # Determine broadcast and network addresses from the IP address and netmask: # # BROADCAST=`ipmask $NETMASK $IPADDR | cut -f 1 -d ' '` BROADCAST=192.168.1.255 # # NETWORK=`ipmask $NETMASK $IPADDR | cut -f 2 -d ' '` NETWORK=192.168.1.0 # # # Network Mask NETMASK="255.255.255.0" # # # ------------------------------------- # Define the Wireless Network Variables # ------------------------------------- # # ESSID (extended network name) : My Network, any # - it is case SenSitiVe # - up to 32 alphanumeric characters # - Do not use spaces, dashes, slashes, or other non-alphanumeric characters. # # use the same ESSID and same Channel as the ESSID for your AP # ESSID="any" ESSID="Testing-ESSID" # # NICK="Test-Wrap" # INTERFACE="ath0" # # # 11b Rates: 1Mbps 2Mbps 5.5Mbps 11Mbps # 11g Rates: 1Mbps 2Mbps 5.5Mbps 11Mbps 6Mbps 9Mbps 12Mbps 18Mbps 24Mbps 36Mbps 48Mbps 54Mbps # # RATE="auto" # RATE="54MB" # RATE="54M" # RATE="24MB" # RATE="11Mbps" # RATE="auto" # # # Access Point to associate with # ------------------------------ # AP="xx:xx:xx:xx:xx:xx" # # # if this is the AccessPoint # AP="" # # # http://www.Linux-Wireless.org/Install-HOWTO/WL/WEP-Key-HOWTO.txt # KEY="0123-4567-89 key 0123-4567-89ab-cdef-0123-4567-89 [2]" # KEY="key s:abcdefghij key s:abcdefghijklmnopqrstuvwxyz" # # use key[2] ( 104bit key ) as default # KEY="0123-4567-89 key 0123-4567-89ab-cdef-0123-4567-89 [2]" # KEY="off" # # # Are we an Access Point or client # -------------------------------- # # wireless AP # MODE="Master" # # # wireless client MODE="Managed" # # # # 3 - 802.11g # 2 - 802.11b # 1 - 802.11a # # MODEGBA=3 MODEGBA=2 # MODEGBA=1 # # FREQ="" # # # use the same ESSID and same Channel as the ESSID for your AP # For best use of the spectrum and sharing with neighbors # 802.11b networks should use channels 01, 06 or 11. # CHANNEL="1" # # TxPower=20 # # RTS="off" FRAG=off # # # End user Config # # ======================================================================= # # # Wireless Modules # ---------------- WLAN="/lib/modules/`uname -r`/net/wlan.o" WEP="/lib/modules/`uname -r`/net/wlan_wep.o" HAL="/lib/modules/`uname -r`/net/ath_hal.o" PCI="/lib/modules/`uname -r`/net/ath_pci.o" # # # Define the Executables # ---------------------- # PATH="/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin" # # # # Define some global variables # ---------------------------- # # Sometimes loading and unloading modules might cause non-fatal errors, so keep going by EXITONERR=0 # EXITONERR=1 # # Lets see the iwconfig values as they are defined/changed DEBUG=1 # # # # =========================================================== # # You should NOT have to change anything below where # # =========================================================== # # # First stop the network # ----------------------- # stop () { # echo "#" echo "# Stopping Wireless: ${INTERFACE}:" echo "#" # # cmd="ifconfig $INTERFACE down" # wlan=`ifconfig -v | grep ^$INTERFACE` if [ -z "$wlan" ]; then echo " WARNING: $cmd : already down" else docmd " $cmd" # echo "#" echo "# Sometimes removing these modules seems to hang/lock the server" echo "#" # domod rmmod ath_pci domod rmmod ath_hal domod rmmod wlan_wep domod rmmod wlan fi # # echo "" # } # stop # # # # Load the wireless modules and add the wireless routes # ----------------------------------------------------- # start() { # # Turn on the WiFi card # echo "#" echo "# Start Wireless: ${INTERFACE}:" echo "#" # # # Add madwifi driver for NetGear WM311 # ------------------------------------ # # http://www.Linux-Wireless.org/Install-HOWTO/Drivers/madwifi/madwifi.txt # # echo "# Installing madwifi drivers" # EXITONERR=0 # domod insmod $WLAN domod insmod $WEP domod insmod $HAL domod insmod $PCI # # EXITONERR=1 # # echo "#" docmd " ifconfig $INTERFACE down" # echo "" docmd " ifconfig ${INTERFACE} ${IPADDR} broadcast ${BROADCAST} netmask ${NETMASK} up" docmd " sleep 1" # echo "" case $MODEGBA in 3 ) echo "# Configure $INTERFACE for 802.11G" ;; 2 ) echo "# Configure $INTERFACE for 802.11B" ;; 1 ) echo "# Configure $INTERFACE for 802.11A" ;; esac # if [ ! -z $MODEGBA ]; then docmd " iwpriv $INTERFACE mode $MODEGBA" ; echo "" ; fi # # # # Sometimes Order makes a difference # # ---------------------------------- # # iwconfig ath0 key XXXXXXXXXX # # iwconfig ath0 ap XX:XX:XX:XX:XX:XX # # iwconfig ath0 channel X # # iwconfig ath0 essid foo # # iwconfig ath0 rate XXMB # # # Missing essid seems to require "Mode Master" to be defined # if [ ! -z $DEBUG ]; then echo "#" echo "# Default State: ( after ifconfig $INTERFACE )" echo "#" echo " `iwconfig $INTERFACE` " echo "" fi # # docmd2 mode ad-hoc # #-- seems to define aribitrary and unmodifiable AP values # #-- creates Cell instead of AP after essid is defined # docmd2 mode "$MODE" docmd2 ap "$AP" docmd2 channel "$CHANNEL" docmd2 essid "$ESSID" # you should Wait 1-3 seconds after setting essid ( done in docmd2() ) # docmd2 rate "$RATE" docmd2 nick "$NICK" docmd2 txpower "$TxPower" # # For Example key configurations # ------------------------------ # http://www.linux-Wireless.org/Install-HOWTO/WL/WEP-Key-HOWTO.txt # echo "#" echo "# Turn off all the WEP keys and reset it" echo "#" # docmd2 key off echo "" # # # To view the key status # ---------------------- docmd " iwlist $INTERFACE key" echo "" # # HaveKey="" # # # Define the WEP keys to use if any # --------------------------------- # if [ ! -z "$KEY" -a "$KEY" != "off" ]; then docmd2 key "$KEY" ; HaveKey=1 ; fi # if [ ! -z "$KEY1" ]; then docmd2 key "[1] $KEY1" ; HaveKey=1 ; fi if [ ! -z "$KEY2" ]; then docmd2 key "[2] $KEY2" ; HaveKey=1 ; fi if [ ! -z "$KEY3" ]; then docmd2 key "[3] $KEY3" ; HaveKey=1 ; fi if [ ! -z "$KEY4" ]; then docmd2 key "[4] $KEY4" ; HaveKey=1 ; fi # # if [ ! -z "$HaveKey" ]; then # echo "#" echo "# Review the WEP keys you defined" echo "# -------------------------------" echo "#" docmd " iwlist $INTERFACE key" echo "" # fi # # # Remove the Wireless Default network 192.168.1.0 on the AP # --------------------------------------------------------- if [ $MODE = "Master" ]; then docmd " route del -net 192.168.1.0 gw 0.0.0.0 netmask 255.255.255.0" fi # # echo "#" echo "# Allow only these particular IP# into the wireless network" echo "#" # # # Use Static IP# instead of wide open dhcp # ---------------------------------------- docmd " route add -host 192.168.1.11 netmask 0.0.0.0 gw $GATEWAY " docmd " route add -host 192.168.1.12 netmask 0.0.0.0 gw $GATEWAY " docmd " route add -host 192.168.1.13 netmask 0.0.0.0 gw $GATEWAY " #ocmd " route add -host 192.168.1.14 netmask 0.0.0.0 gw $GATEWAY " #ocmd " route add -host 192.168.1.18 netmask 0.0.0.0 gw $GATEWAY " # echo "" # echo "ifconfig -v ; route -nv ; iwconfig $INTERFACE ; iwlist $INTERFACE key ; iwlist scan " echo "#" echo "# To Change WEP Key to key[2]: " echo "# iwconfig ath0 key [2]" echo "" # # # Check if we are a Gateway for the Wireless subnet # if [ "$MODE" = "Master" ]; then echo "#" echo "# ===================================================================" echo "# Now Configure the AccessPoint for the Wireless network ( $INTERFACE )" echo "# $0 ap " echo "# ===================================================================" echo "#" else # # for wireless clients # if [ ` ifconfig -v | grep ^eth0 | wc -l ` = 0 ]; then echo "#" echo "# Making your Wireless Gateway ( $GATEWAY ) the default route " docmd " route add default gw $GATEWAY" echo "#" else echo "#" echo "# you have one or more routes, i don't know which is your gateway out" echo "#" fi # fi # echo "" # } # start # # # Load the wireless modules and add the wireless routes # ----------------------------------------------------- # # http://www.netfilter.org/documentation/HOWTO/NAT-HOWTO.html # ap() { # HOST=`hostname -s` # echo "" echo "# Make this host ( $HOST ) the AccessPoint for ${INTERFACE}:" # # if [ $MODE = "Master" ]; then docmd2 mode Master fi echo "" # # echo "# Turn on packet forwarding" # echo " echo 1 > /proc/sys/net/ipv4/ip_forward" echo 1 > /proc/sys/net/ipv4/ip_forward echo "" # # # http://www.e-infomax.com/ipmasq/ # echo "# Install a minimal firewall/gateway" #cho " # rc.firewall-2.2 ( ipchains ) " echo " # rc.firewall-2.4 ( iptables ) " echo "" # # # --------------------------------------------------- # 3-line ipchains firewall # ------------------------ # ipchains -A forward -s 192.168.1.0/24 -d 0.0.0.0/0 -j MASK" # ## hains -A forward -i ppp0 -j MASQ # ipchains -P forward DENY" # echo 1 > /proc/sys/net/ipv4/ip_forward # # --------------------------------------------------- # 4-line iptable firewall # ----------------------- # iptables -F # iptables -t nat -F # iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE # echo 1 > /proc/sys/net/ipv4/ip_forward # # IPTABLES="iptables" EXTIF="eth0" INTIF="ath0" # echo "# 7-commands to Clear the IPTables first" # iptables -F $IPTABLES -P INPUT ACCEPT $IPTABLES -F INPUT $IPTABLES -P OUTPUT ACCEPT $IPTABLES -F OUTPUT $IPTABLES -P FORWARD DROP $IPTABLES -F FORWARD $IPTABLES -t nat -F echo "" # # # # ToDo: # # Change to allow only specific 192.168.x.y ip# only # iptables -A FORWARD -s 192.168.1.12 -i eth0 -j ACCEPT ( works or not ?? ) # echo "# FWD: Allow all connections OUT and only existing and related ones IN" docmd " $IPTABLES -A FORWARD -i $EXTIF -o $INTIF -m state --state ESTABLISHED,RELATED -j ACCEPT" docmd " $IPTABLES -A FORWARD -i $INTIF -o $EXTIF -j ACCEPT" docmd " $IPTABLES -A FORWARD -j LOG" echo "" # echo "# Enabling SNAT (MASQUERADE) functionality on $EXTIF" #ocmd " $IPTABLES -t nat -A POSTROUTING -o $EXTIF -j MASQUERADE" # iptables: No chain/target/match by that name # # this works for the wireless box to get outside docmd " $IPTABLES -t nat -A POSTROUTING -o $EXTIF -j SNAT --to $OUTSIDE" # # # try to allow only 192.168.1.12 connectivity in or out # ------------------------------------------------------- #ocmd " $IPTABLES -t nat -A POSTROUTING -s 192.168.1.12 -o $EXTIF -j SNAT --to $OUTSIDE" echo "" # echo "# Check the rules:" docmd " $IPTABLES -L" echo "" # # } # ap # # # Load the Modules # ---------------- # domod () { ins=$1 mod=$2 # cmd="$ins $mod" # # doit="" # # # if the module is loaded, remove it .. # - show warning if it was previously installed # if [ $ins = "rmmod" ]; then # # cat /proc/modules | grep -q ath_pci # if [ $? -eq 0 ]; then # remove # fi # # m=`lsmod | grep $mod ` if [ -z "$m" ]; then echo " WARNING: $cmd : module not installed " else doit=1 fi fi # # # If the module is NOT loaded, doit # if the module is loaded, just echo and continue # # insmod /lib/modules/`uname -r`/net/wlan.o # if [ $ins = "insmod" ]; then # b24=`basename $mod .o` m24=`lsmod | grep $b24 ` s24=$? # b26=`basename $mod .ko` m26=`lsmod | grep $b26 ` s26=$? # if [ "$s24" = 0 -o "$s26" = 0 ]; then echo " WARNING: $cmd : module already installed " else doit="1" fi fi # # # Install the Modules or Remove it if it was previously installed # if [ ! -z "$doit" ]; then # echo " $cmd" $cmd # # 1 == already installed # # # if [ $? != 0 -o $? != 1 ]; then if [ $? != 0 ]; then echo "# " echo "# ERROR: Module Failed: $ins $mod " echo "# " # if [ $EXITONERR = 1 ]; then exit 1 else echo "# ..keep going anyway" fi fi fi # } # domod # # # # Show the Command and Execute it # ------------------------------- docmd() { cmd=$1 # echo "$cmd" $cmd # if [ $? != 0 ]; then echo "# " echo "# ERROR: Command Failed: $cmd " echo "# " # if [ $EXITONERR = 1 ]; then exit 1 else echo "# ..keep going anyway" fi fi # } # docmd # # # Do the Command if defined # ------------------------- # docmd2() { opt=$1 var=$2 # if [ -z "$var" ]; then # no options defined echo " # iwconfig $INTERFACE $opt xxxx" echo "" # else docmd " iwconfig $INTERFACE $opt $var" sleep 2 # # see that the value was defined as set # if [ ! -z $DEBUG ]; then echo " `iwconfig $INTERFACE | egrep -i 'ESSID|Access|Cell|Rate|key'` " echo "" fi fi # } # docmd2 # # # What Operation to Perform # ------------------------- # case "$1" in # "ap") ap # ;; "start") start # # $0 status ;; # "stop") stop ;; # "status") # echo "" echo " lsmod " lsmod # ifconfig -v ; route -nv ; iwconfig $INTERFACE ;; # "-v") # # Which Versions are we using # iwver=` iwconfig -v | grep iwconfig ` iwver27=` iwconfig -v | grep iwconfig | cut -d " " -f 5` # New=27 # echo "" echo "$0 $VERSION" echo " http://www.Linux-Wireless.org/Install-HOWTO/WL" echo "" echo " $iwver " if [ $iwver27 -lt $New ]; then echo " # you should be using the new wireless_tools.27.pre22.tar.gz or later " echo " # http://www.hpl.hp.com/personal/Jean_Tourrilhes/Linux/Tools.html" fi echo "" exit 1 ;; # "ping") ping -c 3 $IPADDR # ;; *) echo "" echo "Usage: $0 < stop|start|status|AP|-v >" echo "" exit 1 esac # # # End