#!/bin/bash # Luis R. Rodriguez # Linuxwireless.org generic STA test utility # # Use this script to test Linux wireless drivers # which require to associate to an access point. # #### Configurable items ESSID="linuxwireless.org-testap01" DEV="ath2" # Used for WEP and TKIP and CCMP PSK passphrase WEPKEY1="linuxwireless" MODULE="ath_pci" WPASUPPLICANT_TKIP="/tmp/wpasupplicant.conf.tkip" WPASUPPLICANT_CCMP="/tmp/wpasupplicant.conf.ccmp" #### You should not need to edit anything else bellow function generic-sta-setup() { echo "Removing module $MODULE..." rmmod $MODULE echo "Adding module $MODULE..." modprobe $MODULE # Some drivers in AP mode will need this echo "Letting module breathe for a bit..." sleep 2 iwconfig $DEV mode Managed iwconfig $DEV essid $ESSID } function generate-wpasupplicant() { if [[ $# -ne 2 ]]; then echo "Not enough arguments for generate-wpasupplicant()" usage exit fi case "$1" in TKIP) PAIRWISE_ALG="TKIP"; GROUPWISE_ALG="TKIP"; ;; CCMP) PAIRWISE_ALG="CCMP"; GROUPWISE_ALG="CCMP"; ;; *) echo -e "Unsupported hostapd pairwise algorythm: $1" exit ;; esac echo " #ctrl_interface=/var/run/wpa_supplicant ctrl_interface_group=wheel network={ ssid=\"$ESSID\" scan_ssid=1 key_mgmt=WPA-PSK pairwise=$PAIRWISE_ALG group=$GROUPWISE_ALG psk=\"$WEPKEY1\" } " > $2 } function mode-sta() { echo "Setting up STA..." generic-sta-setup ifconfig $DEV up echo "STA setup complete" } function mode-sta-wep() { echo "Setting up AP in AP-WEP mode..." generic-sta-setup iwconfig $DEV key s:$WEPKEY1 ifconfig $DEV up echo "STA setup complete" } function mode-sta-wpa() { if [[ $# -ne 1 ]]; then echo "Not enough arguments for mode-sta-wpa()" usage exit fi case "$1" in TKIP) PAIRWISE_ALG="TKIP" WPASUPPLICANT_CONF="$WPASUPPLICANT_TKIP" ;; CCMP) PAIRWISE_ALG="CCMP" WPASUPPLICANT_CONF="$WPASUPPLICANT_CCMP" ;; *) echo -e "Unsupported wpasupplicant pairwise algorithm: $1" exit ;; esac DRIVER="wext" case "$MODULE" in ath_pci) DRIVER="madwifi" ;; # Drivers should now support wext *) DRIVER="wext" ;; esac echo "Setting up STA in STA-$PAIRWISE_ALG mode..." generic-sta-setup ifconfig $DEV up generate-wpasupplicant $PAIRWISE_ALG $WPASUPPLICANT_CONF wpa_supplicant -D${DRIVER} -i${DEV} -c $WPASUPPLICANT_CONF echo "STA setup complete" } function usage() { echo -e "Usage: $0 STA-Mode" echo -e "STA-Modes available:" echo -e "\tSTA\tNo encryption" echo -e "\tSTA-WEP\tWEP encryption" echo -e "\tSTA-TKIP\tTKIP encryption" echo -e "\tSTA-CCMP\tCCMP encryption" } if [[ $# -ne 1 ]]; then usage exit fi case "$1" in STA) mode-sta; ;; STA-WEP) mode-sta-wep; ;; STA-TKIP) mode-sta-wpa TKIP; ;; STA-CCMP) mode-sta-wpa CCMP; ;; *) echo -e "Unsupported STA mode: $1" usage; ;; esac