#!/bin/bash # Luis R. Rodriguez # Linuxwireless.org generic AP setup utility # # Use this script setup an AP to tests drivers in STA mode against # generic AP modes. This script was designed to support all current # Linux wireless drivers which support AP mode but was tested mainly with # MadWifi # # Requirements: # # * hostapd # * wireless-tools # * Wireless card and a respective Linux wireless driver which supports AP mode # #### Configurable items ESSID="linuxwireless.org-testap01" DEV="ath2" # Used for WEP and TKIP and CCMP PSK passphrase WEPKEY1="linuxwireless" MODULE="ath_pci" HOSTAPD_TKIP="/tmp/hostapd.conf.tkip" HOSTAPD_CCMP="/tmp/hostapd.conf.ccmp" #### You should not need to edit anything else bellow function generic-ap-setup() { echo "Removing module $DRIVER..." rmmod $MODULE echo "Adding module $DRIVER..." modprobe $MODULE # Some drivers in AP mode will need this echo "Letting module breathe for a bit..." sleep 2 case "$MODULE" in ath_pci) wlanconfig $DEV destroy wlanconfig $DEV create wlandev wifi0 wlanmode ap ;; *) iwconfig $DEV mode master ;; esac iwconfig $DEV essid $ESSID } function generate-hostapd() { if [[ $# -ne 2 ]]; then echo "Not enough arguments for generate-hostapd()" usage exit fi case "$1" in TKIP) PAIRWISE_ALG="TKIP"; ;; CCMP) PAIRWISE_ALG="CCMP"; ;; *) echo -e "Unsupported hostapd pairwise algorythm: $1" exit ;; esac DRIVER="hostap" case "$MODULE" in ath_pci) DRIVER="madwifi" ;; # Other hostapd drivers are hostap, wired, and prism54, all these match # ther respective module name *) DRIVER="$MODULE" ;; esac echo " interface=$DEV driver=$DRIVER logger_syslog=-1 logger_syslog_level=2 logger_stdout=-1 logger_stdout_level=2 debug=0 dump_file=/tmp/hostapd.dump ctrl_interface=/var/run/hostapd ctrl_interface_group=0 ssid=$ESSID max_num_sta=255 macaddr_acl=0 auth_algs=3 wme_enabled=1 wme_ac_bk_cwmin=4 wme_ac_bk_cwmax=10 wme_ac_bk_aifs=7 wme_ac_bk_txop_limit=0 wme_ac_bk_acm=0 wme_ac_be_aifs=3 wme_ac_be_cwmin=4 wme_ac_be_cwmax=10 wme_ac_be_txop_limit=0 wme_ac_be_acm=0 wme_ac_vi_aifs=2 wme_ac_vi_cwmin=3 wme_ac_vi_cwmax=4 wme_ac_vi_txop_limit=94 wme_ac_vi_acm=0 wme_ac_vo_aifs=2 wme_ac_vo_cwmin=2 wme_ac_vo_cwmax=3 wme_ac_vo_txop_limit=47 wme_ac_vo_acm=0 eapol_key_index_workaround=0 eap_server=0 own_ip_addr=127.0.0.1 wpa=2 wpa_passphrase=$WEPKEY1 wpa_key_mgmt=WPA-PSK wpa_pairwise=$PAIRWISE_ALG " > $2 } function mode-ap() { echo "Setting up AP..." generic-ap-setup ifconfig $DEV up echo "AP setup complete" } function mode-ap-wep() { echo "Setting up AP in AP-WEP mode..." generic-ap-setup iwconfig $DEV key s:$WEPKEY1 ifconfig $DEV up echo "AP setup complete" } function mode-ap-wpa() { if [[ $# -ne 1 ]]; then echo "Not enough arguments for mode-ap-wpa()" usage exit fi case "$1" in TKIP) PAIRWISE_ALG="TKIP" HOSTAPD_CONF="$HOSTAPD_TKIP" ;; CCMP) PAIRWISE_ALG="CCMP" HOSTAPD_CONF="$HOSTAPD_CCMP" ;; *) echo -e "Unsupported hostapd pairwise algorithm: $1" exit; ;; esac echo "Setting up AP in AP-$PAIRWISE_ALG mode..." generic-ap-setup ifconfig $DEV up generate-hostapd $PAIRWISE_ALG $HOSTAPD_CONF hostapd $HOSTAPD_CONF echo "AP setup complete" } function usage() { echo -e "Usage: $0 AP-Mode" echo -e "AP-Modes available:" echo -e "\tAP\tNo encryption" echo -e "\tAP-WEP\tWEP encryption" echo -e "\tAP-TKIP\tTKIP encryption" echo -e "\tAP-CCMP\tCCMP encryption" } if [[ $# -ne 1 ]]; then usage exit fi case "$1" in AP) mode-ap; ;; AP-WEP) mode-ap-wep; ;; AP-TKIP) mode-ap-wpa TKIP; ;; AP-CCMP) mode-ap-wpa CCMP; ;; *) echo -e "Unsupported AP mode: $1" usage; ;; esac