2013年12月30日 星期一
Atheros beacon stuffing
Add Vendor-specific information at the end of a beacon packet. The code is at trunk\apps\athr-hostap\src\ap\beacon.c.
2013年12月24日 星期二
activateVAP trace note
#!/bin/sh
####################################################################################
##
## set_random_ssid
##
## Set a random SSID for the given interface
## arguments
## $1 - APNAME - name of the interface eg. ath0
##
set_random_ssid() {
apname=$1
apindex=$2
if [ "${apindex}" != "0" ]; then
vapident="_$apindex"
else
vapident=""
fi
RAND_SSID="AP_SSID$vapident"
eval RAND_SSID=\$$RAND_SSID
---------------------------------------------------------------------
eval - construct command by concatenating arguments.
Assume the value of RAND_SSID is "AP_SSID_0".
By expanding and concatenating all arguments, we get
RAND_SSID=$AP_SSID_0
Notice, here it does not mean RAND_SSID="$AP_SSID_0",
instead should read it as RAND_SSID has the value of AP_SSID_0
----------------------------------------------------------------------
if [ "${RANDOM_SSID}" -eq "1" ]; then
TEMP_SSID=$RAND_SSID:`ifconfig $apname | grep HWaddr | cut -d ' ' -f 11 | cut -d ":" -f 4-`
TEMP_SSID_1=`echo $TEMP_SSID | cut -d ":" -f 1`
TEMP_SSID_2=`echo $TEMP_SSID | cut -d ":" -f 2`
TEMP_SSID_3=`echo $TEMP_SSID | cut -d ":" -f 3`
TEMP_SSID_4=`echo $TEMP_SSID | cut -d ":" -f 4`
AP_RANDOM_SSID="$TEMP_SSID_1$TEMP_SSID_2$TEMP_SSID_3$TEMP_SSID_4"
else
AP_RANDOM_SSID=$RAND_SSID
fi
cfg -a AP_RANDOM_SSID$vapident=$AP_RANDOM_SSID
----------------------------------------------------------------------
cut - remove sections from each line of files and get the desired string.
-d : specify delimiter
-f : specify field number of desired string
4- : all fields including and after the 4th are requested
----------------------------------------------------------------------
`...` : get the result as a string from a shell command, not ' nor ", watch
out for the similarity.----------------------------------------------------------------------
}
#end set_random_ssid
####################################################################
## activateVAP
##
## This script is used to activate a VAP that was created earlier.
## Activation involves bringing the interface up, associating with
## a bridge, and configuring the security mode. The VAP MUST EXIST
## prior to calling the activate script.
##
## The form of the command is
##
## activateVAP <vap> <BR> <Security> <SEC Args> <WSC> <VAP_TIE>
##
## Where
## vap: Vap ID (e.g. ath0)
## BR: Bridge to join (or - if not bridged)
## Security: Security mode (WEP,WPA,WSC,NONE)
## Sec Args: File containing security configuration. For WPA this is the hostapd
## conf file. For WEP this is a list of iwconfig commands setting the
## keys.
##
## Examples:
## Open Access Point
## activateVAP ath0 br0 NONE
## WPA Access Point
## activateVAP ath1 br0 WPA wpa2-psk.conf
## WEP Station
## activateVAP ath0 br0 WEP wep.conf
##
###################################################################
. /etc/ath/apcfg
if [ "${1}" = "" ]; then
echo "activateVAP usage"
echo "activateVAP VAPid:Radio bridge Security Security_file"
echo
echo "vapid: e.g. ath0"
echo "bridge: Name of bridge to add to,(typically br0)"
echo "Security: [ WPA | WEP | WSC | NONE ]"
echo "Security_file: Name of file in /etc/ath containing security config"
echo
exit
fi
BRIDGE=$2
SECMODE=$3
SECFILE=$4
WSCMODE=$5
VAPTIE=$6
APNAME=`echo $1 | cut -d ':' -f 1`
RADIO=`echo $1 | cut -d ':' -f 2`
if [ "$RADIO" = "" ]; then
RADIO="0"
fi
KVER=`uname -r | cut -f 1 -d '-'`
MODULE_PATH=/lib/modules/$KVER/net
MODE=`iwconfig ${APNAME} | grep "Mode:Master"`
HOSTAPD_VER=`hostapd -v 2>&1|grep hostapd|cut -f2 -d' '`
----------------------------------------------------------------------
2>&1 ?
2 : stderr
1: stdout
& : 2>1 actually redirects stderr to a file, so & lets 1 to be interpreted
as a file descriptor correctly.----------------------------------------------------------------------
if [ "${HOSTAPD_VER}" != "v0.5.9" ]; then
if [ "${SECMODE}" = "WEP" -a "${WSCMODE}" != "0" ]; then
echo "*** WARNING: WPS is enabled in WEP mode!! ***"
echo "*** WARNING: WPS is disabled ***"
WSCMODE=0
fi
if [ "${SECMODE}" = "WPA" -a "${AP_CYPHER}" = "TKIP" -a "${WSCMODE}" != "0" ]; then
echo "*** WARNING: WPS is enabled in TKIP only mode!! ***"
echo "*** WARNING: WPS is disabled ***"
WSCMODE=0
fi
fi
if [ "${WSCMODE}" = "1" -o "${WSCMODE}" = "2" ]; then
if [ "${SECMODE}" != "WPA" ]; then
echo "*** WARNING: WPS is enabled with No/Incorrect Security settings !! ***"
fi
fi
if [ "${AP_HIDESSID}" = "1" ]; then
echo "*** WARNING: invalid config WPS is enabled with hidden ssid !! ***"
echo "*** WARNING: WPS is disabled ***"
WSCMODE=0
fi
##
## Create an AP index, based on the VAP (ath) number
##
APINDEX=`echo ${APNAME}| sed -e 's/[a-z]//g'`
----------------------------------------------------------------------------------
sed -e 's/regexpr/replacement/g' : A classic and typical sed replacement command
----------------------------------------------------------------------------------
if [ "$APINDEX" != "0" ]; then
APINDEX=`expr ${APINDEX} + 1`
fi
------------------------------------------------------------------------------------------
expr : An old math-in-script method. Popular in Bourne shell. very picky at space!
there has to be space around operators! And since it's a command, command substitution
is needed (`...`).
------------------------------------------------------------------------------------------
##
## First, let us see if the indicated VAP exists. If not, it must be created
##
VAPLIST=`iwconfig | grep ${APNAME} | cut -b 1-4`
------------------------------------------------------------------------------------------
cut -b 1-4 : get bytes 1 to 4
------------------------------------------------------------------------------------------
if [ "${VAPLIST}" = "" ]; then
echo "VAP ${APNAME} must be created first!! (use makeVAP)"
exit
fi
##
## Must determine if the scan modules need to be loaded. Remember, only once!
## This is in station mode if the MODE value is blank
##
STATIONSCAN=`lsmod | grep wlan_scan_sta`
if [ "${MODE}" = "" -a "${STATIONSCAN}" = "" ]; then
#
# Check for a specific MAC address that is specified. Only valid for stations
#
if [ "${AP_REQ_MAC}" != "" ]; then
iwconfig $APNAME ap $AP_REQ_MAC
fi
fi
#
# Bring the interface up at this point!!
# configure bridge, or set an IP address for the WLAN interface
#
if [ "${BRIDGE}" != "none" -a "${BRIDGE}" != "-" ]; then
ifconfig ${APNAME} up
brctl addif ${BRIDGE} ${APNAME}
echo -e "\tinterface ${APNAME}" >> /tmp/${BRIDGE}
------------------------------------------------------------------------------------------
echo
-e : enable backslash escapes (\t, etc)
\t : tab------------------------------------------------------------------------------------------
#
# Add the arping command to ensure all nodes are updated on the network!
#
arping -U -c 1 -I ${BRIDGE} $AP_IPADDR
------------------------------------------------------------------------------------------
arping : send ARP packets to neighbor hosts
-U : reply is not required
-c : stop after sending this amount of packet
-I : interface
$AP_IPADDR : host IP, defined by /etc/ath/apcfg
------------------------------------------------------------------------------------------
else
ifconfig ${APNAME} up ${WAN_IPADDR}
fi
#
# We need to determine if WSC is enabled or not. If not, we do the standard "stuff"
#
if [ "${WSCMODE}" = "1" -o "${WSCMODE}" = "2" ]; then
echo ">>>>> WPS ENABLED, ${SECFILE}"
iwpriv ${APNAME} wps 1
##
## WSC VAP. Determine the file correctly.
##
#EV 89918 & 98568
WIFIINDEX=$RADIO
if [ "$WIFIINDEX" != "0" ]; then
WIFIINDEX=`expr ${WIFIINDEX} + 1`
fi
if [ "$WIFIINDEX" != "0" ]; then
ITER_CHMODE="AP_CHMODE_$WIFIINDEX"
eval ITER_CHMODE=\$$ITER_CHMODE
isa=`expr match $ITER_CHMODE .*A.*`
isg=`expr match $ITER_CHMODE .*G.*`
else
isa=`expr match $AP_CHMODE .*A.*`
isg=`expr match $AP_CHMODE .*G.*`
fi
if [ "${isa}" != 0 ]
then
sed -i 's/hw_mode=[bg]/hw_mode=a/g' /etc/ath/WSC.conf
else
if [ "${isg}" != 0 ]
then
sed -i 's/hw_mode=[ab]/hw_mode=g/g' /etc/ath/WSC.conf
else
sed -i 's/hw_mode=[ga]/hw_mode=b/g' /etc/ath/WSC.conf
fi
fi
if [ "${SECFILE}" = "EAP" ]; then
echo "Cannot use EAP modes with WPS"
exit 255
fi
if [ "${HOSTAPD_VER}" = "v0.5.9" ]; then
if [ "${VAPTIE}" != "" ]; then
echo ">>> VAP Tied: ${VAPTIE}"
fname="WSC_${VAPTIE}.conf"
else
fname="WSC_${APNAME}.conf"
fexist=`ls /etc/wpa2 | grep ${APNAME}`
unconf=`cat /etc/wpa2/WSC_${APNAME}.conf | grep "wps_configured=1"`
if [ "${fexist}" = "" -o "${unconf}" = "" ]; then
#
# We have to use this file "in place" to have WSC work
# properly.
#
echo ">>>>> WPS Translate, Index:${APINDEX}"
cfg -t${APINDEX} /etc/ath/WSC.conf > /etc/wpa2/WSC_${APNAME}.conf
fi
fi
echo -e "\t\tbss ${APNAME}" >> /tmp/aplist$RADIO
echo -e "\t\t{" >> /tmp/aplist$RADIO
echo -e "\t\t\tconfig /etc/wpa2/${fname}" >> /tmp/aplist$RADIO
echo -e "\t\t}" >> /tmp/aplist$RADIO
else
if [ "${MODE}" = "" ]; then
#
# For client mode and WPS is Enabled use WSC_sta.conf
#
fname="WSC_sta.conf"
fexist=`ls /tmp | grep ${fname}`
if [ "${fexist}" = "" ]; then
cp /etc/ath/WSC_sta.conf /tmp/
fi
echo -e "-c/tmp/WSC_sta.conf -i${APNAME} -bbr0" > /tmp/sta_conf_filename
else
fname="WSC_${APNAME}.conf"
fexist=`ls /etc/wpa2 | grep ${APNAME}`
unconf=`cat /etc/wpa2/WSC_${APNAME}.conf | grep "^wps_state=2"`
if [ "${fexist}" = "" -o "${unconf}" = "" ]; then
#
# We have to use this file "in place" to have WSC work
# properly.
#
echo ">>>>> WPS Translate, Index:${APINDEX}"
set_random_ssid ${APNAME} ${APINDEX}
cfg -t${APINDEX} /etc/ath/WSC.conf > /etc/wpa2/WSC_${APNAME}.conf
fi
echo -e "/etc/wpa2/WSC_${APNAME}.conf \c\h" >> /tmp/conf_filename
fi
fi
else
##
## Non WSC VAP. Use Standard Security
##
if [ "${SECMODE}" = "WPA" ]; then
#
# WPA now processes all WPA sub modes
# Here the file is "translated" from the template.
#
if [ "${MODE}" != "" ]; then
#
# This is the method using the "translation" mode of cgiMain to
# create an appropriate security file for PSK or Enterprise mode
#
cfg -t${APINDEX} /etc/ath/${SECFILE}.ap_bss ${APNAME} > /tmp/sec${APNAME}
if [ "${HOSTAPD_VER}" = "v0.5.9" ]; then
echo -e "\t\tbss ${APNAME}" >> /tmp/aplist$RADIO
echo -e "\t\t{" >> /tmp/aplist$RADIO
echo -e "\t\t\tconfig /tmp/sec${APNAME}" >> /tmp/aplist$RADIO
echo -e "\t\t}" >> /tmp/aplist$RADIO
else
echo -e "/tmp/sec${APNAME} \c\h" >> /tmp/conf_filename
fi
else
#
# This is a managed (station) node
#
cfg -t${APINDEX} /etc/ath/${SECFILE}.sta ${APNAME} > /tmp/sup${APNAME}
if [ "${HOSTAPD_VER}" = "v0.5.9" ]; then
echo -e "\tsta ${APNAME}" >> /tmp/stalist$RADIO
echo -e "\t{" >> /tmp/stalist$RADIO
echo -e "\t\tconfig /tmp/sup${APNAME}" >> /tmp/stalist$RADIO
echo -e "\t}" >> /tmp/stalist$RADIO
else
echo -e "-c/tmp/sup${APNAME} -i${APNAME} -bbr0" > /tmp/sta_conf_filename
fi
fi
fi
if [ "${SECMODE}" = "WEP" ]; then
NUM_KEY=1
#
# Insert the keys as required
#
my_wep_keys=" _1 _2 _3 _4 "
for i in $my_wep_keys;
do
ITER_AP_WEP_RADIO_NUM0_KEY="WEP_RADIO_NUM0_KEY$i"
ITER_AP_WEP_RADIO_NUM1_KEY="WEP_RADIO_NUM1_KEY$i"
eval ITER_AP_WEP_RADIO_NUM0_KEY=\$$ITER_AP_WEP_RADIO_NUM0_KEY
eval ITER_AP_WEP_RADIO_NUM1_KEY=\$$ITER_AP_WEP_RADIO_NUM1_KEY
if [ "${RADIO}" = "0" ]; then
if [ "${ITER_AP_WEP_RADIO_NUM0_KEY}" != "" ]; then
cfg -h ${ITER_AP_WEP_RADIO_NUM0_KEY} 1
if [ $? = 1 ]; then
iwconfig ${APNAME} enc ${ITER_AP_WEP_RADIO_NUM0_KEY} [$NUM_KEY]
else
iwconfig ${APNAME} enc s:${ITER_AP_WEP_RADIO_NUM0_KEY} [$NUM_KEY]
fi
fi
fi
if [ "${RADIO}" = "1" ]; then
if [ "${ITER_AP_WEP_RADIO_NUM1_KEY}" != "" ]; then
cfg -h ${ITER_AP_WEP_RADIO_NUM1_KEY} 1
if [ $? = 1 ]; then
iwconfig ${APNAME} enc ${ITER_AP_WEP_RADIO_NUM1_KEY} [$NUM_KEY]
else
iwconfig ${APNAME} enc s:${ITER_AP_WEP_RADIO_NUM1_KEY} [$NUM_KEY]
fi
fi
fi
NUM_KEY=$(($NUM_KEY+1))
done
if [ "${RADIO}" = "0" ]; then
if [ "${AP_WEP_MODE_0}" != "" -a "${AP_WEP_MODE_0}" != "1" ]; then
iwpriv ${APNAME} authmode ${AP_WEP_MODE_0}
fi
if [ "${AP_PRIMARY_KEY_0}" != "" ]; then
iwconfig ${APNAME} enc [${AP_PRIMARY_KEY_0}]
fi
fi
if [ "${RADIO}" = "1" ]; then
if [ "${AP_WEP_MODE_1}" != "" -a "${AP_WEP_MODE_1}" != "1" ]; then
iwpriv ${APNAME} authmode ${AP_WEP_MODE_1}
fi
if [ "${AP_PRIMARY_KEY_1}" != "" ]; then
iwconfig ${APNAME} enc [${AP_PRIMARY_KEY_1}]
fi
fi
fi
fi
####################################################################################
##
## set_random_ssid
##
## Set a random SSID for the given interface
## arguments
## $1 - APNAME - name of the interface eg. ath0
##
set_random_ssid() {
apname=$1
apindex=$2
if [ "${apindex}" != "0" ]; then
vapident="_$apindex"
else
vapident=""
fi
RAND_SSID="AP_SSID$vapident"
eval RAND_SSID=\$$RAND_SSID
---------------------------------------------------------------------
eval - construct command by concatenating arguments.
Assume the value of RAND_SSID is "AP_SSID_0".
By expanding and concatenating all arguments, we get
RAND_SSID=$AP_SSID_0
Notice, here it does not mean RAND_SSID="$AP_SSID_0",
instead should read it as RAND_SSID has the value of AP_SSID_0
----------------------------------------------------------------------
if [ "${RANDOM_SSID}" -eq "1" ]; then
TEMP_SSID=$RAND_SSID:`ifconfig $apname | grep HWaddr | cut -d ' ' -f 11 | cut -d ":" -f 4-`
TEMP_SSID_1=`echo $TEMP_SSID | cut -d ":" -f 1`
TEMP_SSID_2=`echo $TEMP_SSID | cut -d ":" -f 2`
TEMP_SSID_3=`echo $TEMP_SSID | cut -d ":" -f 3`
TEMP_SSID_4=`echo $TEMP_SSID | cut -d ":" -f 4`
AP_RANDOM_SSID="$TEMP_SSID_1$TEMP_SSID_2$TEMP_SSID_3$TEMP_SSID_4"
else
AP_RANDOM_SSID=$RAND_SSID
fi
cfg -a AP_RANDOM_SSID$vapident=$AP_RANDOM_SSID
----------------------------------------------------------------------
cut - remove sections from each line of files and get the desired string.
-d : specify delimiter
-f : specify field number of desired string
4- : all fields including and after the 4th are requested
----------------------------------------------------------------------
`...` : get the result as a string from a shell command, not ' nor ", watch
out for the similarity.----------------------------------------------------------------------
}
#end set_random_ssid
####################################################################
## activateVAP
##
## This script is used to activate a VAP that was created earlier.
## Activation involves bringing the interface up, associating with
## a bridge, and configuring the security mode. The VAP MUST EXIST
## prior to calling the activate script.
##
## The form of the command is
##
## activateVAP <vap> <BR> <Security> <SEC Args> <WSC> <VAP_TIE>
##
## Where
## vap: Vap ID (e.g. ath0)
## BR: Bridge to join (or - if not bridged)
## Security: Security mode (WEP,WPA,WSC,NONE)
## Sec Args: File containing security configuration. For WPA this is the hostapd
## conf file. For WEP this is a list of iwconfig commands setting the
## keys.
##
## Examples:
## Open Access Point
## activateVAP ath0 br0 NONE
## WPA Access Point
## activateVAP ath1 br0 WPA wpa2-psk.conf
## WEP Station
## activateVAP ath0 br0 WEP wep.conf
##
###################################################################
. /etc/ath/apcfg
if [ "${1}" = "" ]; then
echo "activateVAP usage"
echo "activateVAP VAPid:Radio bridge Security Security_file"
echo
echo "vapid: e.g. ath0"
echo "bridge: Name of bridge to add to,(typically br0)"
echo "Security: [ WPA | WEP | WSC | NONE ]"
echo "Security_file: Name of file in /etc/ath containing security config"
echo
exit
fi
BRIDGE=$2
SECMODE=$3
SECFILE=$4
WSCMODE=$5
VAPTIE=$6
APNAME=`echo $1 | cut -d ':' -f 1`
RADIO=`echo $1 | cut -d ':' -f 2`
if [ "$RADIO" = "" ]; then
RADIO="0"
fi
KVER=`uname -r | cut -f 1 -d '-'`
MODULE_PATH=/lib/modules/$KVER/net
MODE=`iwconfig ${APNAME} | grep "Mode:Master"`
HOSTAPD_VER=`hostapd -v 2>&1|grep hostapd|cut -f2 -d' '`
----------------------------------------------------------------------
2>&1 ?
2 : stderr
1: stdout
& : 2>1 actually redirects stderr to a file, so & lets 1 to be interpreted
as a file descriptor correctly.----------------------------------------------------------------------
if [ "${HOSTAPD_VER}" != "v0.5.9" ]; then
if [ "${SECMODE}" = "WEP" -a "${WSCMODE}" != "0" ]; then
echo "*** WARNING: WPS is enabled in WEP mode!! ***"
echo "*** WARNING: WPS is disabled ***"
WSCMODE=0
fi
if [ "${SECMODE}" = "WPA" -a "${AP_CYPHER}" = "TKIP" -a "${WSCMODE}" != "0" ]; then
echo "*** WARNING: WPS is enabled in TKIP only mode!! ***"
echo "*** WARNING: WPS is disabled ***"
WSCMODE=0
fi
fi
if [ "${WSCMODE}" = "1" -o "${WSCMODE}" = "2" ]; then
if [ "${SECMODE}" != "WPA" ]; then
echo "*** WARNING: WPS is enabled with No/Incorrect Security settings !! ***"
fi
fi
if [ "${AP_HIDESSID}" = "1" ]; then
echo "*** WARNING: invalid config WPS is enabled with hidden ssid !! ***"
echo "*** WARNING: WPS is disabled ***"
WSCMODE=0
fi
##
## Create an AP index, based on the VAP (ath) number
##
APINDEX=`echo ${APNAME}| sed -e 's/[a-z]//g'`
----------------------------------------------------------------------------------
sed -e 's/regexpr/replacement/g' : A classic and typical sed replacement command
----------------------------------------------------------------------------------
if [ "$APINDEX" != "0" ]; then
APINDEX=`expr ${APINDEX} + 1`
fi
------------------------------------------------------------------------------------------
expr : An old math-in-script method. Popular in Bourne shell. very picky at space!
there has to be space around operators! And since it's a command, command substitution
is needed (`...`).
------------------------------------------------------------------------------------------
##
## First, let us see if the indicated VAP exists. If not, it must be created
##
VAPLIST=`iwconfig | grep ${APNAME} | cut -b 1-4`
------------------------------------------------------------------------------------------
cut -b 1-4 : get bytes 1 to 4
------------------------------------------------------------------------------------------
if [ "${VAPLIST}" = "" ]; then
echo "VAP ${APNAME} must be created first!! (use makeVAP)"
exit
fi
##
## Must determine if the scan modules need to be loaded. Remember, only once!
## This is in station mode if the MODE value is blank
##
STATIONSCAN=`lsmod | grep wlan_scan_sta`
if [ "${MODE}" = "" -a "${STATIONSCAN}" = "" ]; then
#
# Check for a specific MAC address that is specified. Only valid for stations
#
if [ "${AP_REQ_MAC}" != "" ]; then
iwconfig $APNAME ap $AP_REQ_MAC
fi
fi
#
# Bring the interface up at this point!!
# configure bridge, or set an IP address for the WLAN interface
#
if [ "${BRIDGE}" != "none" -a "${BRIDGE}" != "-" ]; then
ifconfig ${APNAME} up
brctl addif ${BRIDGE} ${APNAME}
echo -e "\tinterface ${APNAME}" >> /tmp/${BRIDGE}
------------------------------------------------------------------------------------------
echo
-e : enable backslash escapes (\t, etc)
\t : tab------------------------------------------------------------------------------------------
#
# Add the arping command to ensure all nodes are updated on the network!
#
arping -U -c 1 -I ${BRIDGE} $AP_IPADDR
------------------------------------------------------------------------------------------
arping : send ARP packets to neighbor hosts
-U : reply is not required
-c : stop after sending this amount of packet
-I : interface
$AP_IPADDR : host IP, defined by /etc/ath/apcfg
------------------------------------------------------------------------------------------
else
ifconfig ${APNAME} up ${WAN_IPADDR}
fi
#
# We need to determine if WSC is enabled or not. If not, we do the standard "stuff"
#
if [ "${WSCMODE}" = "1" -o "${WSCMODE}" = "2" ]; then
echo ">>>>> WPS ENABLED, ${SECFILE}"
iwpriv ${APNAME} wps 1
##
## WSC VAP. Determine the file correctly.
##
#EV 89918 & 98568
WIFIINDEX=$RADIO
if [ "$WIFIINDEX" != "0" ]; then
WIFIINDEX=`expr ${WIFIINDEX} + 1`
fi
if [ "$WIFIINDEX" != "0" ]; then
ITER_CHMODE="AP_CHMODE_$WIFIINDEX"
eval ITER_CHMODE=\$$ITER_CHMODE
isa=`expr match $ITER_CHMODE .*A.*`
isg=`expr match $ITER_CHMODE .*G.*`
else
isa=`expr match $AP_CHMODE .*A.*`
isg=`expr match $AP_CHMODE .*G.*`
fi
if [ "${isa}" != 0 ]
then
sed -i 's/hw_mode=[bg]/hw_mode=a/g' /etc/ath/WSC.conf
else
if [ "${isg}" != 0 ]
then
sed -i 's/hw_mode=[ab]/hw_mode=g/g' /etc/ath/WSC.conf
else
sed -i 's/hw_mode=[ga]/hw_mode=b/g' /etc/ath/WSC.conf
fi
fi
if [ "${SECFILE}" = "EAP" ]; then
echo "Cannot use EAP modes with WPS"
exit 255
fi
if [ "${HOSTAPD_VER}" = "v0.5.9" ]; then
if [ "${VAPTIE}" != "" ]; then
echo ">>> VAP Tied: ${VAPTIE}"
fname="WSC_${VAPTIE}.conf"
else
fname="WSC_${APNAME}.conf"
fexist=`ls /etc/wpa2 | grep ${APNAME}`
unconf=`cat /etc/wpa2/WSC_${APNAME}.conf | grep "wps_configured=1"`
if [ "${fexist}" = "" -o "${unconf}" = "" ]; then
#
# We have to use this file "in place" to have WSC work
# properly.
#
echo ">>>>> WPS Translate, Index:${APINDEX}"
cfg -t${APINDEX} /etc/ath/WSC.conf > /etc/wpa2/WSC_${APNAME}.conf
fi
fi
echo -e "\t\tbss ${APNAME}" >> /tmp/aplist$RADIO
echo -e "\t\t{" >> /tmp/aplist$RADIO
echo -e "\t\t\tconfig /etc/wpa2/${fname}" >> /tmp/aplist$RADIO
echo -e "\t\t}" >> /tmp/aplist$RADIO
else
if [ "${MODE}" = "" ]; then
#
# For client mode and WPS is Enabled use WSC_sta.conf
#
fname="WSC_sta.conf"
fexist=`ls /tmp | grep ${fname}`
if [ "${fexist}" = "" ]; then
cp /etc/ath/WSC_sta.conf /tmp/
fi
echo -e "-c/tmp/WSC_sta.conf -i${APNAME} -bbr0" > /tmp/sta_conf_filename
else
fname="WSC_${APNAME}.conf"
fexist=`ls /etc/wpa2 | grep ${APNAME}`
unconf=`cat /etc/wpa2/WSC_${APNAME}.conf | grep "^wps_state=2"`
if [ "${fexist}" = "" -o "${unconf}" = "" ]; then
#
# We have to use this file "in place" to have WSC work
# properly.
#
echo ">>>>> WPS Translate, Index:${APINDEX}"
set_random_ssid ${APNAME} ${APINDEX}
cfg -t${APINDEX} /etc/ath/WSC.conf > /etc/wpa2/WSC_${APNAME}.conf
fi
echo -e "/etc/wpa2/WSC_${APNAME}.conf \c\h" >> /tmp/conf_filename
fi
fi
else
##
## Non WSC VAP. Use Standard Security
##
if [ "${SECMODE}" = "WPA" ]; then
#
# WPA now processes all WPA sub modes
# Here the file is "translated" from the template.
#
if [ "${MODE}" != "" ]; then
#
# This is the method using the "translation" mode of cgiMain to
# create an appropriate security file for PSK or Enterprise mode
#
cfg -t${APINDEX} /etc/ath/${SECFILE}.ap_bss ${APNAME} > /tmp/sec${APNAME}
if [ "${HOSTAPD_VER}" = "v0.5.9" ]; then
echo -e "\t\tbss ${APNAME}" >> /tmp/aplist$RADIO
echo -e "\t\t{" >> /tmp/aplist$RADIO
echo -e "\t\t\tconfig /tmp/sec${APNAME}" >> /tmp/aplist$RADIO
echo -e "\t\t}" >> /tmp/aplist$RADIO
else
echo -e "/tmp/sec${APNAME} \c\h" >> /tmp/conf_filename
fi
else
#
# This is a managed (station) node
#
cfg -t${APINDEX} /etc/ath/${SECFILE}.sta ${APNAME} > /tmp/sup${APNAME}
if [ "${HOSTAPD_VER}" = "v0.5.9" ]; then
echo -e "\tsta ${APNAME}" >> /tmp/stalist$RADIO
echo -e "\t{" >> /tmp/stalist$RADIO
echo -e "\t\tconfig /tmp/sup${APNAME}" >> /tmp/stalist$RADIO
echo -e "\t}" >> /tmp/stalist$RADIO
else
echo -e "-c/tmp/sup${APNAME} -i${APNAME} -bbr0" > /tmp/sta_conf_filename
fi
fi
fi
if [ "${SECMODE}" = "WEP" ]; then
NUM_KEY=1
#
# Insert the keys as required
#
my_wep_keys=" _1 _2 _3 _4 "
for i in $my_wep_keys;
do
ITER_AP_WEP_RADIO_NUM0_KEY="WEP_RADIO_NUM0_KEY$i"
ITER_AP_WEP_RADIO_NUM1_KEY="WEP_RADIO_NUM1_KEY$i"
eval ITER_AP_WEP_RADIO_NUM0_KEY=\$$ITER_AP_WEP_RADIO_NUM0_KEY
eval ITER_AP_WEP_RADIO_NUM1_KEY=\$$ITER_AP_WEP_RADIO_NUM1_KEY
if [ "${RADIO}" = "0" ]; then
if [ "${ITER_AP_WEP_RADIO_NUM0_KEY}" != "" ]; then
cfg -h ${ITER_AP_WEP_RADIO_NUM0_KEY} 1
if [ $? = 1 ]; then
--------------------------------------------------------------------------------------
$?:
the exit status of the last command executed is given as a decimal string. When a command completes successfully, it returns the exit status of 0 (zero), otherwise it returns a non-zero exit status.
-----------------------------------------------------------------
iwconfig ${APNAME} enc ${ITER_AP_WEP_RADIO_NUM0_KEY} [$NUM_KEY]
else
iwconfig ${APNAME} enc s:${ITER_AP_WEP_RADIO_NUM0_KEY} [$NUM_KEY]
fi
fi
fi
if [ "${RADIO}" = "1" ]; then
if [ "${ITER_AP_WEP_RADIO_NUM1_KEY}" != "" ]; then
cfg -h ${ITER_AP_WEP_RADIO_NUM1_KEY} 1
if [ $? = 1 ]; then
iwconfig ${APNAME} enc ${ITER_AP_WEP_RADIO_NUM1_KEY} [$NUM_KEY]
else
iwconfig ${APNAME} enc s:${ITER_AP_WEP_RADIO_NUM1_KEY} [$NUM_KEY]
fi
fi
fi
NUM_KEY=$(($NUM_KEY+1))
done
if [ "${RADIO}" = "0" ]; then
if [ "${AP_WEP_MODE_0}" != "" -a "${AP_WEP_MODE_0}" != "1" ]; then
iwpriv ${APNAME} authmode ${AP_WEP_MODE_0}
fi
if [ "${AP_PRIMARY_KEY_0}" != "" ]; then
iwconfig ${APNAME} enc [${AP_PRIMARY_KEY_0}]
fi
fi
if [ "${RADIO}" = "1" ]; then
if [ "${AP_WEP_MODE_1}" != "" -a "${AP_WEP_MODE_1}" != "1" ]; then
iwpriv ${APNAME} authmode ${AP_WEP_MODE_1}
fi
if [ "${AP_PRIMARY_KEY_1}" != "" ]; then
iwconfig ${APNAME} enc [${AP_PRIMARY_KEY_1}]
fi
fi
fi
fi
2013年12月22日 星期日
2013年12月20日 星期五
wpa_supplicant, wpa_cli
Reference links
http://hostap.epitest.fi/wpa_supplicant/devel/
http://rtl8192cu.googlecode.com/hg-history/bdd3a2265bdd6a92f24cef3d52fa594b2844c9c1/document/wpa_cli_with_wpa_supplicant.pdf
http://ubuntuforums.org/showthread.php?t=263136
http://linux.die.net/man/5/wpa_supplicant.conf
https://wiki.archlinux.org/index.php/WPA_supplicant
http://hostap.epitest.fi/wpa_supplicant/devel/
http://rtl8192cu.googlecode.com/hg-history/bdd3a2265bdd6a92f24cef3d52fa594b2844c9c1/document/wpa_cli_with_wpa_supplicant.pdf
http://ubuntuforums.org/showthread.php?t=263136
http://linux.die.net/man/5/wpa_supplicant.conf
https://wiki.archlinux.org/index.php/WPA_supplicant
2013年12月11日 星期三
Atheros extender commands
!!Newest version!!
[non-WDS]
Survey:
iwlist ath1 scanning
Configure:
~
# ifconfig ath0 down
~
# ifconfig br0 down
~
# wlanconfig ath0 destroy
~
# wlanconfig ath create wlandev wifi0 wlanmode ap
~ # wlanconfig ath create
wlandev wifi0 wlanmode sta nosbeacon
~ # iwpriv ath0 extap 1
~ # iwpriv ath1 extap 1
-----------------------------
WEP
~
# iwconfig ath1 essid AP_SSID
~
# iwconfig ath1 key 1 ENCRYPTION_KEY
~ # iwpriv ath1 authmode mode auto
~
# ifconfig ath1 up
WPA
WPA2
First, create wpa_supplicant.conf adding ctrl_interface=DIR=/var/run/wpa_supplicant
~ # wpa_supplicant –Dathr –c wpa_supplicant.conf
–iath1 -B
~ # wpa_cli –p/var/run/wpa_supplicant
remove_network 0
~ # wpa_cli –p/var/run/wpa_supplicant
ap_scan 1
~ # wpa_cli –p/var/run/wpa_supplicant
add_network
~ # wpa_cli –p/var/run/wpa_supplicant
set_network 0 ssid ‘”AP_SSID”’
~ # wpa_cli –p/var/run/wpa_supplicant
set_network 0 psk ‘”AP_PASSPHRASE”’
~ # wpa_cli –p/var/run/wpa_supplicant
set_network 0 proto ‘AP_PROTO’
~ # wpa_cli –p/var/run/wpa_supplicant
set_network 0 key_mgmt ‘WPA-PSK’
~ # wpa_cli –p/var/run/wpa_supplicant
set_network 0 pairwise ‘AP_PAIRWISE’
~ # wpa_cli –p/var/run/wpa_supplicant
set_network 0 group ‘AP_GROUP’
~ # wpa_cli –p/var/run/wpa_supplicant
select_network 0
-----------------------------
WEP
~
# iwconfig ath0 essid EXTENDER_SSID
~ # iwconfig ath0 key 1 ENCRYPTION_KEY
~ # iwpriv ath0 authmode mode auto
~ # ifconfig ath0 up
WPA
WPA2
First, modify /etc/ath/hostapd_ctrl_interface.conf for the
following attributes:
Interface=ath0
bridge=br0
ssid=REPEATER_SSID
wpa=1/2
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP/CCMP/TKIP CCMP
wpa_passphrase=SECRET_PASSPHRASE
~ # hostapd
/etc/ath/hostapd_ctrl_interface.conf -B
-----------------------------
~
# brctl addif br0 ath0
~
# brctl addif br0 ath1
~
# brctl setfd br0 1
~
# ifconfig br0 up
[WDS]
Survey:
iwlist ath1 scanning
Configure:
~
# ifconfig ath0 down
~
# ifconfig br0 down
~
# wlanconfig ath0 destroy
~
# wlanconfig ath create wlandev wifi0 wlanmode ap
~ # wlanconfig ath create
wlandev wifi0 wlanmode sta nosbeacon
~ # iwpriv ath0 wds 1
~ # iwpriv ath1 wds 1
-----------------------------
WEP
~
# iwconfig ath1 essid AP_SSID
~
# iwconfig ath1 key 1 ENCRYPTION_KEY
~ # iwpriv ath1 authmode mode auto
~
# ifconfig ath1 up
WPA
WPA2
First, create wpa_supplicant.conf adding ctrl_interface=DIR=/var/run/wpa_supplicant
~ # wpa_supplicant –Dathr –c wpa_supplicant.conf
–iath1 -B
~ # wpa_cli –p/var/run/wpa_supplicant
remove_network 0
~ # wpa_cli –p/var/run/wpa_supplicant
ap_scan 1
~ # wpa_cli –p/var/run/wpa_supplicant
add_network
~ # wpa_cli –p/var/run/wpa_supplicant
set_network 0 ssid ‘”AP_SSID”’
~ # wpa_cli –p/var/run/wpa_supplicant
set_network 0 psk ‘”AP_PASSPHRASE”’
~ # wpa_cli –p/var/run/wpa_supplicant
set_network 0 proto ‘AP_PROTO’
~ # wpa_cli –p/var/run/wpa_supplicant
set_network 0 key_mgmt ‘WPA-PSK’
~ # wpa_cli –p/var/run/wpa_supplicant
set_network 0 pairwise ‘AP_PAIRWISE’
~ # wpa_cli –p/var/run/wpa_supplicant
set_network 0 group ‘AP_GROUP’
~ # wpa_cli –p/var/run/wpa_supplicant
select_network 0
-----------------------------
WEP
~
# iwconfig ath0 essid EXTENDER_SSID
~ # iwconfig ath0 key 1 ENCRYPTION_KEY
~ # iwpriv ath0 authmode mode auto
~ # ifconfig ath0 up
WPA
WPA2
First, modify /etc/ath/hostapd_ctrl_interface.conf for the
following attributes:
Interface=ath0
bridge=br0
ssid=REPEATER_SSID
wpa=1/2
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP/CCMP/TKIP CCMP
wpa_passphrase=SECRET_PASSPHRASE
~ # hostapd
/etc/ath/hostapd_ctrl_interface.conf -B
-----------------------------
~
# brctl addif br0 ath0
~
# brctl addif br0 ath1
~
# brctl setfd br0 1
~ # ifconfig br0 up[non-WDS]
~ # ifconfig ath0
down
~ # ifconfig br0
down
~ # wlanconfig
ath0 destroy
~ # wlanconfig
ath create wlandev wifi0 wlanmode ap
~ # wlanconfig
ath create wlandev wifi0 wlanmode sta nosbeacon
~ # iwconfig ath0
essid Edison_1211 channel 11
~ # iwconfig ath0
key 1 9800071234
~ # iwpriv ath0
mode 11G
~ # iwpriv ath0
extap 1
~ # iwpriv ath0
authmode mode open
~ # iwconfig ath1
essid Edison-Buffalo-G
~ # iwconfig ath1
key 1 9800071234
~ # iwpriv ath1
authmode mode open
~ # iwpriv ath1
mode 11G
~ # iwpriv ath1
extap 1
~ # ifconfig ath1
up
~ # ifconfig ath0
up
~ # brctl addif
br0 ath0
~ # brctl addif
br0 ath1
~ # brctl setfd
br0 1
~ # ifconfig br0
192.168.11.110 up
~ # echo 1 >
/proc/sys/net/ipv4/ip_forward
~ # ifconfig br0
192.168.11.110 up
[WDS]
~ # ifconfig ath0
down
~ # ifconfig br0
down
~ # wlanconfig
ath0 destroy
~ # wlanconfig
ath create wlandev wifi0 wlanmode ap
~ # wlanconfig
ath create wlandev wifi0 wlanmode sta nosbeacon
~ # iwconfig ath0
essid Edison_1211 channel 11
~ # iwconfig ath0
key 1 9800071234
~ # iwpriv ath0
mode 11G
~ # iwpriv ath0
wds 1
~ # iwpriv ath0
authmode mode open
~ # iwconfig ath1
essid Edison-Buffalo-G
~ # iwconfig ath1
key 1 9800071234
~ # iwpriv ath1
authmode mode open
~ # iwpriv ath1
mode 11G
~ # iwpriv ath1
wds 1
~ # ifconfig ath1
up
~ # ifconfig ath0
up
~ # brctl addif
br0 ath0
~ # brctl addif
br0 ath1
~ # brctl setfd
br0 1
~ # ifconfig br0
192.168.11.110 up
~ # echo 1 >
/proc/sys/net/ipv4/ip_forward
~ #
ifconfig br0 192.168.11.110 up
訂閱:
文章 (Atom)