Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Wireless configuration script
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
koprimer
n00b
n00b


Joined: 29 Feb 2004
Posts: 64

PostPosted: Sun Jul 17, 2005 12:04 am    Post subject: Wireless configuration script Reply with quote

EDIT: Wireless configuration script updated with wpa_supplicant WPA-PSK support

Introduction:
---------------
There are many netcard configuration scripts out there, and I just wanted to throw in mine to see what everyone thought of it. I've been using it for the past couple of years, mainly because I haven't found a utility that allows me to switch APs without it overwriting or corrupting my gentoo wireless settings.

The script can be found here.

Features:
-----------
At the moment, the script only supports cards that support iwconfig. The default dhcp client I use is dhcpcd. I haven't tested this script with any other dhcp client but I'm sure it wouldn't be hard to modify or add the support in. The script has two uses:
1. A command line configuration script for wireless interfaces
2. A UI for configuring wireless interfaces.
The UI uses dialogs, similar to what you'll find in a netcard config script.

Command Line Help:
------------------------
./wifiup -h

Examples:
------------
#overwrite default values and prompt:
./wifiup -e MyEssid -p

#connect to a wireless ap:
./wifiup -e MyEssid

#connect to an encrypted ap
./wifiup -e MyEssid -k 1234-1234-1234-1234
#or
./wifiup -e MyEssid -k s:mypassword


Please feel free to give any suggestions, comments, or additions you might have.

Thanks. -coprime

EDIT: Adding the code since it isn't very long. Will help if the link goes down, or if it goes unmaintained. --pjp
Code:
#!/bin/bash
#/***************************************************************************
#*   Copyright (C) 2005 by coprime                                          *
#*   coprime@rootshell.be                                                   *
#*                                                                          *
#*   This program is free software; you can redistribute it and/or modify   *
#*   it under the terms of the GNU General Public License as published by   *
#*   the Free Software Foundation; either version 2 of the License, or      *
#*   (at your option) any later version.                                    *
#*                                                                          *
#*   This program is distributed in the hope that it will be useful,        *
#*   but WITHOUT ANY WARRANTY; without even the implied warranty of         *
#*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
#*   GNU General Public License for more details.                           *
#*                                                                          *
#*   You should have received a copy of the GNU General Public License      *
#*   along with this program; if not, write to the                          *
#*   Free Software Foundation, Inc.,                                        *
#*   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.              *
#****************************************************************************/
# TODO:
# Make sure you look over the default values and modify them


# default values
EXTIF="eth1"
MAC=""
IP=""
NETMASK="255.255.255.0"
GATEWAY="192.168.1.1"
ESSID=""
BSSID=""
CHANNEL=""
KEY=""
WPA_DRIVER="hostap"
WPA_SUPPCONF="/etc/wpa_wifiup.conf"
WPA_CTRL_INT="/var/run/wpa_supplicant"
WPA_CTRL_GRP="0"
WPA_EAPOL_VER="1"
WPA_AP_SCAN="1"
WPA_FAST_REAUTH="1"
ENC=0
PROMPT=0
DISCONNECT=0


# program locations
IFCONFIG="/sbin/ifconfig"
IWCONFIG="/sbin/iwconfig"
ROUTE="/sbin/route"
DHCPCD="/sbin/dhcpcd"
WPA_SUPPLICANT="/sbin/wpa_supplicant"


VERSION="1.0.5"
DIALOG=`which dialog`
# use other dialogs if possible
if [ -n "$DISPLAY" ] && [ -x /usr/bin/xdialog ]; then
    DIALOG="xdialog"
elif [ -n "$DISPLAY" ] && [ -x /usr/bin/gdialog ]; then
    DIALOG="gdialog"
elif [ -n "$DISPLAY" ] && [ -x /usr/bin/kdialog ]; then
    DIALOG="kdialog"
fi

# procedures
usage() {
    echo -en "usage: $0 <option> <argument>\n"
    echo -en "\tWifiup Wireless Configuration v$VERSION - by coprime\n\n"
    echo -en "\tOption:\t\tDescription:\n"
    echo -en "\t-p\t\tPrompt for arguments using dialog\n"
    echo -en "\t-i [extif]\tSet the external wireless interface\n"
    echo -en "\t-e [essid]\tThe essid for wireless interface\n"
    echo -en "\t-b [bssid]\tThe bssid for wireless interface\n"
    echo -en "\t-m [mac]\tMac address for the wireless interface\n"
    echo -en "\t-c [chan]\tThe channel for the wireless interface\n"
    echo -en "\t-s [ip]\t\tSet IP address, DHCP disabled if used\n"
    echo -en "\t-n [nm]\t\tSet Network Mask, used with IP address\n"
    echo -en "\t-g [gw]\t\tGateway address, used with IP address\n"
    echo -en "\t-t [enc]\tSpecify the type of encryption to use\n"
    echo -en "\t\t\t0 - None (default)\n"
    echo -en "\t\t\t1 - WEP encryption\n"
    echo -en "\t\t\t2 - WPA PSK encryption\n"
    echo -en "\t-D [driver]\tDriver to use in wpa_supplicant\n"
    echo -en "\t-k [key]\tThe key to use for encrypted access points\n"
    echo -en "\t-d\t\tDisconnect the wireless interface\n"
    echo -en "\t-h\t\tPrints out this help\n"
    exit 1
}

getargs() {
    while getopts "hpdi:e:b:m:c:s:n:g:k:t:D:" opt $@; do
        case "$opt" in
            p) PROMPT=1;;
            i) EXTIF="$OPTARG";;
           e) ESSID="$OPTARG";;
            b) BSSID="$OPTARG";;
           m) MAC="$OPTARG";;
            c) CHANNEL="$OPTARG";;
            s) IP="$OPTARG";;
            n) NETMASK="$OPTARG";;
           g) GATEWAY="$OPTARG";;
       k) KEY="$OPTARG";;
            t) ENC="$OPTARG";;
            D) WPA_DRIVER="$OPTARG";;
            d) DISCONNECT=1;;
            h) usage;;
       ?) usage;;
        esac
    done
}

prompt() {
    TITLE="Wifiup Wireless Configuration"
    BG="$TITLE v$VERSION - by coprime"
    exec 3>&1  #some io redirection since --stdout doesn't work for some dialog programs
    EXTIF=$($DIALOG --backtitle "$BG" --title "$TITLE" --inputbox "Enter in external wireless interface" 9 50 $EXTIF 2>&1 1>&3)
    if [ $? -gt 0 ]; then exit 1; fi;
    ESSID=$($DIALOG --backtitle "$BG" --title "$TITLE" --inputbox "Enter in wireless ESSID" 9 50 $ESSID 2>&1 1>&3)
    if [ $? -gt 0 ]; then exit 1; fi;
    if [ -z "$ESSID" ]; then echo "$0: invalid essid"; exit 1; fi
    MAC=$($DIALOG --backtitle "$BG" --title "$TITLE" --inputbox "Enter in interface MAC Address" 9 50 $MAC 2>&1 1>&3)
    if [ $? -gt 0 ]; then exit 1; fi;
    #user can specify channel if they want through command arguments
    #CHANNEL=$($DIALOG --backtitle "$BG" --title "$TITLE" --inputbox "Enter in wireless interface channel" 9 50 $CHANNEL 2>&1 1>&3)
    #if [ $? -gt 0 ]; then exit 1; fi;
    RET=$($DIALOG --backtitle "$BG" --title "$TITLE" --radiolist "What type of encryption do you want to use?" 12 55 3 "None" "Use no encyrption" ON "WEP" "Use WEP encryption" OFF "WPA-PSK" "Use WPA-PSK encryption" OFF 2>&1 1>&3)
    if [ $? -gt 0 ]; then exit 1; fi;
    if [ "$RET" == "None" ]; then ENC=0;
    elif [ "$RET" == "WEP" ]; then ENC=1;
    elif [ "$RET" == "WPA-PSK" ]; then ENC=2; fi
    if [ $ENC -gt 0 ]; then
        KEY=$($DIALOG --backtitle "$BG" --title "$TITLE" --inputbox "Enter in the key for an encrypted access point" 9 50 $KEY 2>&1 1>&3)
        if [ $? -gt 0 ]; then exit 1; fi;
    fi
    $DIALOG --backtitle "$BG" --title "$TITLE" --yesno "Do you want to use DHCP?" 9 50
    if [ $? -eq 0 ]; then
   IP=""
    else
        IP=$($DIALOG --backtitle "$BG" --title "$TITLE" --inputbox "Enter in your IP address" 9 50 $IP 2>&1 1>&3)
   if [ $? -gt 0 ]; then exit 1; fi;
   NETMASK=$($DIALOG --backtitle "$BG" --title "$TITLE" --inputbox "Enter in your network mask" 9 50 $NETMASK 2>&1 1>&3)
   if [ $? -gt 0 ]; then exit 1; fi;
   GATEWAY=$($DIALOG --backtitle "$BG" --title "$TITLE" --inputbox "Enter in your gateway address" 9 50 $GATEWAY 2>&1 1>&3)
   if [ $? -gt 0 ]; then exit 1; fi;
    fi
    exec 3>&-  #close the file descriptor
}

update_wpaconf() {
    if [ -z "$WPA_CTRL_INT" ]; then echo "$0: cannot update wpa configuration without WPA_CTRL_INT"; exit 1; fi
    echo -en "ctrl_interface=$WPA_CTRL_INT\n" > $WPA_SUPPCONF
    if [ -n "$WPA_CTRL_GRP" ]; then echo -en "ctrl_interface_group=$WPA_CTRL_GRP\n" >> $WPA_SUPPCONF; fi
    if [ -n "$WPA_EAPOL_VER" ]; then echo -en "eapol_version=$WPA_EAPOL_VER\n" >> $WPA_SUPPCONF; fi
    if [ -n "$WPA_AP_SCAN" ]; then echo -en "ap_scan=$WPA_AP_SCAN\n" >> $WPA_SUPPCONF; fi
    if [ -n "$WPA_FAST_REAUTH" ]; then echo -en "fast_reauth=$WPA_FAST_REAUTH\n" >> $WPA_SUPPCONF; fi
    echo -en "\nnetwork={\n" >> $WPA_SUPPCONF
    echo -en "\tssid=\"$ESSID\"\n" >> $WPA_SUPPCONF
    if [ -n "$BSSID" ]; then echo -en "\tbssid=$BSSID\n" >> $WPA_SUPPCONF; fi
    echo -en "\tscan_ssid=1\n" >> $WPA_SUPPCONF
    case $ENC in
        2)
            echo -en "\tkey_mgmt=WPA-PSK\n" >> $WPA_SUPPCONF
            echo -en "\tpsk=\"$KEY\"\n" >> $WPA_SUPPCONF
            ;;
    esac
    echo -en "}\n" >> $WPA_SUPPCONF
    chmod 600 $WPA_SUPPCONF  #need to set to rw for root only
}

wifidown() {
    $IFCONFIG $EXTIF down
    killall $WPA_SUPPLICANT >& /dev/null
    killall $DHCPCD >& /dev/null
}

wifiup() {
    case $ENC in
        [0-1])
            $IWCONFIG $EXTIF mode Managed
            $IWCONFIG $EXTIF essid $ESSID
            if [ -n "$BSSID" ]; then $IWCONFIG $EXTIF ap $BSSID; fi
            if [ -n "$CHANNEL" ]; then $IWCONFIG $EXTIF channel $CHANNEL; fi
            if [ -n "$KEY" ]; then $IWCONFIG $EXTIF key $KEY; fi
            ;;
        2)
            if [ -z "$KEY" ]; then
                echo $0: invalid key; exit 1
            else
                update_wpaconf
                if [ -x "$WPA_CTRL_INT/$EXTIF" ]; then rm $WPA_CTRL_INT/$EXTIF; fi
                $WPA_SUPPLICANT -i $EXTIF -c $WPA_SUPPCONF -D $WPA_DRIVER -B
            fi
            ;;
    esac
    if [ -n "$MAC" ]; then $IFCONFIG $EXTIF hw ether $MAC; fi
    if [ -n "$IP" ]; then
       $IFCONFIG $EXTIF $IP
   $IFCONFIG $EXTIF up
        $ROUTE add -net default netmask $NETMASK dev $EXTIF gw $GATEWAY
    else
        $IFCONFIG $EXTIF up
        if [ -f /var/run/dhcpcd-$EXTIF.pid ]; then rm /var/run/dhcpcd-$EXTIF.pid; fi
        $DHCPCD -dYN $EXTIF
    fi
}

#main
getargs $@
if [ $DISCONNECT -eq 1 ]; then
    wifidown
else
    if [ $PROMPT -eq 1 ] || [ -z $ESSID ]; then
        prompt
    fi
    wifidown
    wifiup
fi


Last edited by koprimer on Tue Oct 18, 2005 4:07 am; edited 1 time in total
Back to top
View user's profile Send private message
paddler
n00b
n00b


Joined: 03 Apr 2005
Posts: 37
Location: glacial moraine

PostPosted: Wed Jul 20, 2005 2:28 am    Post subject: Reply with quote

Just what i was looking for. Thanks!
Back to top
View user's profile Send private message
koprimer
n00b
n00b


Joined: 29 Feb 2004
Posts: 64

PostPosted: Tue Jul 26, 2005 3:04 am    Post subject: Reply with quote

glad to hear paddler :D

I know this script can use some improvements. One of them is to take out hardcoding the net mask providing the option for the user to set it. The other would be to support other wireless configuration tools like wpa_supplicant or hostap (if they still use their own tools). I some how feel I'm recreating the wheel here from the lack of responses. I can really use some help with supporting other DHCP clients. If anyone else uses a different dhcp client and has a suggestion on how to obtain a DHCP lease with it, please post your suggestion. Thanks!

-coprime
Back to top
View user's profile Send private message
raccoon
n00b
n00b


Joined: 28 Apr 2004
Posts: 36
Location: Wonderland

PostPosted: Wed Aug 24, 2005 10:14 pm    Post subject: Reply with quote

Thanks alot; needed something just like this to get me started in the world of Linux WiFi!
_________________
Adopt an unanswered post!
Back to top
View user's profile Send private message
koprimer
n00b
n00b


Joined: 29 Feb 2004
Posts: 64

PostPosted: Thu Oct 13, 2005 1:04 am    Post subject: Reply with quote

Wireless Configuration Script Update
------------------------------------------
Grab the latest here. Will soon add support for other wpa_supplicant options.

EDIT: if anyone has any suggestions to improve the script, please feel free to comment.

CHANGELOG v1.0.5 - 10/12/2005
---------------------------------------
* Added WPA-PSK support
* Added the -d option to disconnect the wireless interface
* Can now use xdialog, gdialog, and kdialog along with dialog
* Changed the -a option to -b
* Added the -n option to set network mask

TODO v1.0.5 - 10/12/2005
-------------------------------
* Add support for other wpa_supplicant options
* Switch from using getopts to getopt because I'm running out of characters
* Switch from using wpa_supplicant to wireless tools as soon as it's ready.
Back to top
View user's profile Send private message
asyr
n00b
n00b


Joined: 01 Sep 2004
Posts: 56
Location: Hellas

PostPosted: Tue Oct 18, 2005 7:06 am    Post subject: Reply with quote

I made some changes to your script. Because I do not have a sito to upload, I post it here:
Code:
#!/bin/bash
#/***************************************************************************
#*   Copyright (C) 2005 by coprime                                          *
#*   coprime@rootshell.be                                                   *
#*                                                                          *
#*   This program is free software; you can redistribute it and/or modify   *
#*   it under the terms of the GNU General Public License as published by   *
#*   the Free Software Foundation; either version 2 of the License, or      *
#*   (at your option) any later version.                                    *
#*                                                                          *
#*   This program is distributed in the hope that it will be useful,        *
#*   but WITHOUT ANY WARRANTY; without even the implied warranty of         *
#*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
#*   GNU General Public License for more details.                           *
#*                                                                          *
#*   You should have received a copy of the GNU General Public License      *
#*   along with this program; if not, write to the                          *
#*   Free Software Foundation, Inc.,                                        *
#*   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.              *
#****************************************************************************/
# TODO:
# Make sure you look over the default values and modify them
#############################################################################
# Changes by Andrew Syreggelas
#
# - Automatic recognition of the WIFI interfaces
# - Checking if the defined interface is a WIFI
# - Correcting the procedure of identifying other dialog utilities
# - New 'Dialog' procedure to hide the detailes for the 'dialog' or the
#   'kdialog' utility
#   NOTE: No info for the 'xdialog' and 'gdialog' utilities
# - Changing the logic at the end of the script:
#   wifidown always but wifiup only if the DISCONNECT is not set.
# - A 'Demo' variable added, in order to get the following:
#   Demo=""    means that the script works as before
#   Demo=echo  means that the script just echoes the commands without
#              executing them (test mode)
#   Demo=sudo  means that the script could be used by a non root user
#              that have sudo priviledges (without password)
#############################################################################

Demo=
# Uncomment the following line for demo (not-execute) mode
#Demo=echo
# Uncomment the following line for user with sudo priviledges
#Demo=sudo

# default values
EXTIF=""
MAC=""
IP=""
NETMASK="255.255.255.0"
GATEWAY="192.168.1.1"
ESSID=""
BSSID=""
CHANNEL=""
KEY=""
WPA_DRIVER="hostap"
WPA_SUPPCONF="/etc/wpa_wifiup.conf"
WPA_CTRL_INT="/var/run/wpa_supplicant"
WPA_CTRL_GRP="0"
WPA_EAPOL_VER="1"
WPA_AP_SCAN="1"
WPA_FAST_REAUTH="1"
ENC=0
PROMPT=0
DISCONNECT=0


# program locations
IFCONFIG="/sbin/ifconfig"
IWCONFIG="/sbin/iwconfig"
ROUTE="/sbin/route"
DHCPCD="/sbin/dhcpcd"
WPA_SUPPLICANT="/sbin/wpa_supplicant"


VERSION="1.0.5a"
DIALOG=`which dialog`
xDIALOG=`which xdialog 2>/dev/null`
kDIALOG=`which kdialog 2>/dev/null`
gDIALOG=`which gdialog 2>/dev/null`
# use other dialogs if possible
[ -n "$DISPLAY" ] && {
  if   [ -n "$xDIALOG" ]; then
    DIALOG=$xDIALOG
  elif [ -n "$kDIALOG" ]; then
    DIALOG=$kDIALOG
  elif [ -n "$gDIALOG" ]; then
    DIALOG=$gDIALOG
  fi
}

# procedures
usage() {
    echo -en "usage: $0 <option> <argument>\n"
    echo -en "\tWifiup Wireless Configuration v$VERSION - by coprime\n\n"
    echo -en "\tOption:\t\tDescription:\n"
    echo -en "\t-p\t\tPrompt for arguments using dialog\n"
    echo -en "\t-i [extif]\tSet the external wireless interface\n"
    echo -en "\t-e [essid]\tThe essid for wireless interface\n"
    echo -en "\t-b [bssid]\tThe bssid for wireless interface\n"
    echo -en "\t-m [mac]\tMac address for the wireless interface\n"
    echo -en "\t-c [chan]\tThe channel for the wireless interface\n"
    echo -en "\t-s [ip]\t\tSet IP address, DHCP disabled if used\n"
    echo -en "\t-n [nm]\t\tSet Network Mask, used with IP address\n"
    echo -en "\t-g [gw]\t\tGateway address, used with IP address\n"
    echo -en "\t-t [enc]\tSpecify the type of encryption to use\n"
    echo -en "\t\t\t0 - None (default)\n"
    echo -en "\t\t\t1 - WEP encryption\n"
    echo -en "\t\t\t2 - WPA PSK encryption\n"
    echo -en "\t-D [driver]\tDriver to use in wpa_supplicant\n"
    echo -en "\t-k [key]\tThe key to use for encrypted access points\n"
    echo -en "\t-d\t\tDisconnect the wireless interface\n"
    echo -en "\t-h\t\tPrints out this help\n"
    exit 1
}

getargs() {
    WiFiIFs=$(iwconfig 2>/dev/null |
              awk '{if(substr($0,1,1)!=" ")print}' |
              egrep -v '^$' |
              awk 'BEGIN {s="on"} {printf "%s %s %s ",$1,$1,s;s="off"}')
    [ -z "$WiFiIFs" ] && echo "No WiFi interfaces found !" && exit 1

    while getopts "hpdei:b:m:c:s:n:g:k:t:D:" opt $@; do
        case "$opt" in
            p) PROMPT=1;;
            i) EXTIF="$OPTARG";;
            e) ESSID="$OPTARG";;
            b) BSSID="$OPTARG";;
            m) MAC="$OPTARG";;
            c) CHANNEL="$OPTARG";;
            s) IP="$OPTARG";;
            n) NETMASK="$OPTARG";;
            g) GATEWAY="$OPTARG";;
            k) KEY="$OPTARG";;
            t) ENC="$OPTARG";;
            D) WPA_DRIVER="$OPTARG";;
            d) DISCONNECT=1;;
            h) usage;;
            ?) usage;;
        esac
    done

    [ -n "$EXTIF" ] && {
      echo $WiFiIFs | awk '{for(i=1;i<=NF;i++)print $i}' |
      grep $EXTIF >/dev/null 2>&1 || {
        echo "Invalid WiFi interfaces $EXTIF !"
        exit 1
      }
    }
}

Dialog() {
  Type=$1;shift
  Label=$1;shift
  Height=$1;shift
  Width=$1;shift

  TITLE="Wifiup Wireless Configuration"
  BG="$TITLE v$VERSION - by coprime"

  case $DIALOG in
    ($kDIALOG)
      [[ "$Type" == "--radiolist" ]] && shift
      Answer=$($DIALOG --title "$TITLE" $Type "$Label" "$@")
      Result=$?
      ;;
    ($gDIALOG)
    ($xDIALOG)
    (*)
      Answer=$($DIALOG --backtitle "$BG" --title "$TITLE" $Type "$Label" $Height $Width "$@")
      Result=$?
      ;;
  esac

  [ $Result -gt 0 ] && [[ "$Type" != "--yesno" ]] && exit 1

  return $Result
}

prompt() {
    [ -z "$EXTIF" ] && {
      Dialog --radiolist "Which interface do you want to use?" 12 55 3 $WiFiIFs
      EXTIF=$Answer
    }
    [ $DISCONNECT -eq 1 ] && return
    Dialog --inputbox "Enter in wireless ESSID" 9 50 $ESSID
    ESSID=$Answer
    if [ -z "$ESSID" ]; then echo "$0: invalid essid"; exit 1; fi
    Dialog --inputbox "Enter in interface MAC Address" 9 50 $MAC
    MAC=$Answer
    #user can specify channel if they want through command arguments
    #Dialog --inputbox "Enter in wireless interface channel" 9 50 $CHANNEL
    #CHANNEL=$Answer
    Dialog --radiolist "What type of encryption do you want to use?" 12 55 3 "None" "Use no encyrption" off "WEP" "Use WEP encryption" on "WPA-PSK" "Use WPA-PSK encryption" off
    RET=$Answer
    if   [ "$RET" == "None"    ]; then ENC=0;
    elif [ "$RET" == "WEP"     ]; then ENC=1;
    elif [ "$RET" == "WPA-PSK" ]; then ENC=2; fi
    if [ $ENC -gt 0 ]; then
        Dialog --inputbox "Enter in the key for an encrypted access point" 9 50 $KEY
        KEY=$Answer
    fi
    Dialog --yesno "Do you want to use DHCP?" 9 50
    if [ $? -eq 0 ]; then
        IP=""
    else
        Dialog --inputbox "Enter in your IP address" 9 50 $IP
        IP=$Answer
        Dialog --inputbox "Enter in your network mask" 9 50 $NETMASK
        NETMASK=$Answer
        Dialog --inputbox "Enter in your gateway address" 9 50 $GATEWAY
        GATEWAY=$Answer
    fi
}

update_wpaconf() {
    if [ -z "$WPA_CTRL_INT" ]; then echo "$0: cannot update wpa configuration without WPA_CTRL_INT"; exit 1; fi
    echo -en "ctrl_interface=$WPA_CTRL_INT\n" > $WPA_SUPPCONF
    if [ -n "$WPA_CTRL_GRP" ]; then echo -en "ctrl_interface_group=$WPA_CTRL_GRP\n" >> $WPA_SUPPCONF; fi
    if [ -n "$WPA_EAPOL_VER" ]; then echo -en "eapol_version=$WPA_EAPOL_VER\n" >> $WPA_SUPPCONF; fi
    if [ -n "$WPA_AP_SCAN" ]; then echo -en "ap_scan=$WPA_AP_SCAN\n" >> $WPA_SUPPCONF; fi
    if [ -n "$WPA_FAST_REAUTH" ]; then echo -en "fast_reauth=$WPA_FAST_REAUTH\n" >> $WPA_SUPPCONF; fi
    echo -en "\nnetwork={\n" >> $WPA_SUPPCONF
    echo -en "\tssid=\"$ESSID\"\n" >> $WPA_SUPPCONF
    if [ -n "$BSSID" ]; then echo -en "\tbssid=$BSSID\n" >> $WPA_SUPPCONF; fi
    echo -en "\tscan_ssid=1\n" >> $WPA_SUPPCONF
    case $ENC in
        2)
            echo -en "\tkey_mgmt=WPA-PSK\n" >> $WPA_SUPPCONF
            echo -en "\tpsk=\"$KEY\"\n" >> $WPA_SUPPCONF
            ;;
    esac
    echo -en "}\n" >> $WPA_SUPPCONF
    chmod 600 $WPA_SUPPCONF  #need to set to rw for root only
}

wifidown() {
    $Demo $IFCONFIG $EXTIF down
    $Demo killall $WPA_SUPPLICANT >& /dev/null
    $Demo killall $DHCPCD >& /dev/null
}

wifiup() {
    case $ENC in
        [0-1])
            $Demo $IWCONFIG $EXTIF mode Managed
            $Demo $IWCONFIG $EXTIF essid $ESSID
            if [ -n "$BSSID" ];   then $Demo $IWCONFIG $EXTIF ap $BSSID; fi
            if [ -n "$CHANNEL" ]; then $Demo $IWCONFIG $EXTIF channel $CHANNEL; fi
            if [ -n "$KEY" ];     then $Demo $IWCONFIG $EXTIF key $KEY; fi
            ;;
        2)
            if [ -z "$KEY" ]; then
                echo $0: invalid key; exit 1
            else
                $Demo update_wpaconf
                if [ -x "$WPA_CTRL_INT/$EXTIF" ]; then $Demo rm $WPA_CTRL_INT/$EXTIF; fi
                $Demo $WPA_SUPPLICANT -i $EXTIF -c $WPA_SUPPCONF -D $WPA_DRIVER -B
            fi
            ;;
    esac
    if [ -n "$MAC" ]; then $Demo $IFCONFIG $EXTIF hw ether $MAC; fi
    if [ -n "$IP" ]; then
        $Demo $IFCONFIG $EXTIF $IP
        $Demo $IFCONFIG $EXTIF up
        $Demo $ROUTE add -net default netmask $NETMASK dev $EXTIF gw $GATEWAY
    else
        $Demo $IFCONFIG $EXTIF up
        if [ -f /var/run/dhcpcd-$EXTIF.pid ]; then $Demo rm /var/run/dhcpcd-$EXTIF.pid; fi
        $Demo $DHCPCD -dYN $EXTIF
    fi
}

#main
getargs $@

if [ $PROMPT -eq 1 ] || [ -z $ESSID ]; then
    prompt
fi
wifidown
[ $DISCONNECT -ne 1 ] && wifiup


Any comment are welcome...
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum