Created
December 23, 2020 18:41
-
-
Save danitool/c0b8e25c2a8ea78be6df165bc60f9d6e to your computer and use it in GitHub Desktop.
WDS script to set this mode the TD-W8968 v2 router
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
while [[ -z "$(ifconfig | awk '$1 == "apcli0" {print $1}')" ]] || [[ -z "$(ifconfig | awk '$1 == "ra0" {print $1}')" ]]; do | |
sleep 66 | |
done | |
RTCONFIG="/var/Wireless/RT2860AP/RT2860AP.dat" | |
wait=9 | |
while true; do | |
WIRELESS_MODE=`awk -F= '$1 == "WirelessMode" {print $2}' $RTCONFIG` | |
RADIO=`ifconfig | awk '$1 == "ra0" {print $1}'` | |
WDS_STRING=`awk -F= '$1 == "ApCliSsid" {print $2}' $RTCONFIG` | |
APCLI_ENABLE=`awk -F= '$1 == "ApCliEnable" {print $2}' $RTCONFIG` | |
WDS_ENABLE=`awk -F= '$1 == "WdsEnable" {print $2}' $RTCONFIG` | |
WDS_UP=`ifconfig | awk '$1 == "wds0" {print $1}'` | |
APCLI_UP=`ifconfig | awk '$1 == "apcli0" {print $1}'` | |
#WDSENABLED=`cat /dev/mtd4 | awk '$1 == "<X_TP_WdsBridgeEnable" {print $2;exit}'` | |
if [[ "$WDS_UP" ]] && [[ -z "$APCLI_UP" ]]; then | |
#if [[ -z "$RADIO" ]] || [[ -z "$WDSENABLED" ]]; then | |
if [[ -z "$RADIO" ]] || [[ "$WDS_STRING" != "WDS" && "$WDS_STRING" != "WDSBRIDGE" ]] || [[ -z "$WDS_ENABLE" ]]; then | |
ifconfig wds0 down | |
brctl addif br0 apcli0 | |
fi | |
: | |
elif [[ "$WDS_STRING" != "WDS" && "$WDS_STRING" != "WDSBRIDGE" ]] && [[ "$WDS_UP" ]]; then | |
ifconfig wds0 down | |
brctl addif br0 apcli0 | |
#simple approach, if the ApCliSsid string is "WDS" then configure the WDS bridge with the ApCliBssid as WDS remote mac address | |
#elif [[ "$WDS_STRING" == "WDS" ]] && [[ "$RADIO" ]] && [[ "$WDSENABLED" ]]; then | |
elif [[ "$RADIO" ]] && [[ "$APCLI_UP" || "$APCLI_ENABLE" == "1" ]] && [[ "$WDS_STRING" == "WDS" || "$WDS_STRING" == "WDSBRIDGE" ]]; then | |
WDS_CRYPT=`awk -F= '$1 == "ApCliEncrypType" {print $2}' $RTCONFIG` | |
WDS_BSSID=`awk -F= '$1 == "ApCliBssid" {print $2}' $RTCONFIG` | |
if [[ "$WDS_CRYPT" == "WEP" ]]; then | |
WDS_KEY=`awk -F= '$1 == "ApCliKey1Str" {print $2}' $RTCONFIG` | |
else | |
WDS_KEY=`awk -F= '$1 == "ApCliWPAPSK" {print $2}' $RTCONFIG` | |
fi | |
echo "configuring wds... " | |
ifconfig ra0 down | |
ifconfig apcli0 down | |
ifconfig wds0 down | |
rmmod rt5390ap | |
#Delete WDS lines, if exist | |
sed -r -i "/^WdsEnable/d" $RTCONFIG | |
sed -r -i "/^WdsList/d" $RTCONFIG | |
sed -r -i "/^WdsEncrypType/d" $RTCONFIG | |
sed -r -i "/^WdsKey/d" $RTCONFIG | |
sed -r -i "/^Wds0Key/d" $RTCONFIG | |
if [[ "$WDS_STRING" == "WDS" ]]; then | |
echo "WdsEnable=1" >> $RTCONFIG | |
else | |
echo "WDS bridge, no AP function" | |
echo "WdsEnable=2" >> $RTCONFIG | |
fi | |
echo "WdsList=$WDS_BSSID;" >> $RTCONFIG | |
echo "WdsEncrypType=$WDS_CRYPT" >> $RTCONFIG | |
#echo "WdsKey=$WDS_KEY" >> $RTCONFIG | |
echo "Wds0Key=$WDS_KEY" >> $RTCONFIG | |
#Disable apcli mode, we'll use a real WDS instead | |
sed -r -i "s/(ApCliEnable=)(.*)/\10/" $RTCONFIG | |
insmod /lib/modules/rt5390ap.ko | |
#triple command to avoid operstate=unknown | |
ifconfig ra0 up && ifconfig ra0 down && ifconfig ra0 up | |
ifconfig wds0 up | |
brctl addif br0 ra0 | |
brctl addif br0 wds0 | |
wait=9 | |
echo "wds configured" | |
else | |
: | |
fi | |
#stock firmware doesn't allow to select the channel 14 in the web interface | |
#check if the SSID ends "14", if true set this channel | |
CHAN_SSID=`awk -F= '$1 == "SSID1" {print substr($2, length($2) - 1)}' $RTCONFIG` | |
if [[ $CHAN_SSID == 14 ]]; then | |
CHAN_CUR=`iwpriv ra0 stat | awk '$1 == "Channel" {print $3}'` | |
if [[ $CHAN_CUR != 14 ]]; then | |
iwpriv ra0 set CountryRegion=5 | |
iwpriv ra0 set Channel=14 | |
wait=9 | |
fi | |
fi | |
if [[ $wait == 10 ]]; then | |
#Bug?, the wireless mode is lost on wireless reconnect, let's assert it periodically with the proper command | |
iwpriv ra0 set WirelessMode=$WIRELESS_MODE | |
wait=0 | |
fi | |
wait=$((wait+1)) | |
sleep 60 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment