blob: 0fd32468412df54898813d55a6c96301871c8227 [file] [log] [blame]
#!/bin/sh
create_hostapdConf() {
devidx=0
phyidx=0
old_path=""
pcie7915count=0
vap_per_radio=8
radio_num="$(iw list | grep Wiphy | wc -l)"
for _dev in /sys/class/ieee80211/*; do
[ -e "$_dev" ] || continue
dev="${_dev##*/}"
band="$(uci get wireless.radio${phyidx}.band)"
channel="$(uci get wireless.radio${phyidx}.channel)"
# Use random MAC to prevent use the same MAC address
rand="$(hexdump -C /dev/urandom | head -n 1 | awk '{printf ""$3":"$4""}' &)"
killall hexdump
MAC="00:0${devidx}:12:34:${rand}"
chip="$(cat /sys/class/ieee80211/"$dev"/device/device)"
if [ $chip == "0x7915" ]; then
path="$(realpath /sys/class/ieee80211/"$dev"/device | cut -d/ -f4-)"
if [ -n "$path" ]; then
if [ "$path" == "$old_path" ] || [ "$old_path" == "" ]; then
pcie7915count="1"
else
pcie7915count="2"
fi
fi
old_path=$path
fi
if [ -e /sys/class/net/wlan$phyidx ]; then
iw wlan$phyidx del > /dev/null
elif [ -e /sys/class/net/wifi$phyidx ]; then
for((i=0;i<$vap_per_radio;i++)); do
ifidx=$(($phyidx+$i*$radio_num))
ifname="$(cat /nvram/hostapd"$ifidx".conf | grep ^interface= | cut -d '=' -f2 | tr -d '\n')"
if [ -n $ifname ]; then
hostapd_cli -i global raw REMOVE wifi$ifidx > /dev/null
if [ $i -eq 0 ]; then
iw wifi$ifidx del > /dev/null
fi
fi
done
fi
if [ "$(uci get wireless.radio${phyidx}.disabled)" == "1" ]; then
phyidx=$(($phyidx + 1))
continue
fi
if [ ! -f /nvram/hostapd"$devidx".conf ]; then
touch /nvram/hostapd"$devidx".conf
else
for((i=0;i<$vap_per_radio;i++)); do
ifidx=$(($phyidx+$i*$radio_num))
ifname="$(cat /nvram/hostapd"$ifidx".conf | grep ^interface= | cut -d '=' -f2 | tr -d '\n')"
vapstat="$(cat /nvram/vap-status | grep wifi"$ifidx"= | cut -d'=' -f2)"
if [ -n $ifname ] && [ $vapstat -eq "1" ]; then
if [ $i = 0 ]; then
## first interface in this phy
iw phy phy$phyidx interface add $ifname type __ap > /dev/null
fi
touch /nvram/hostapd-acl$ifidx
touch /nvram/hostapd$ifidx.psk
touch /nvram/hostapd-deny$ifidx
touch /tmp/$dev-wifi$ifidx
hostapd_cli -i global raw ADD bss_config=$dev:/nvram/hostapd"$ifidx".conf
fi
done
devidx=$(($devidx + 1))
phyidx=$(($phyidx + 1))
continue
fi
if [ "$band" == "2g" ]; then
cp -f /etc/hostapd-2G.conf /nvram/hostapd"$devidx".conf
fi
if [ "$band" == "5g" ]; then
if [ $chip == "0x7906" ]; then
cp -f /etc/hostapd-5G-7916.conf /nvram/hostapd"$devidx".conf
elif [ $chip == "0x7915" ]; then
cp -f /etc/hostapd-5G-7915.conf /nvram/hostapd"$devidx".conf
else
cp -f /etc/hostapd-5G.conf /nvram/hostapd"$devidx".conf
fi
fi
if [ "$pcie7915count" == "2" ]; then
cp -f /etc/hostapd-2G.conf /nvram/hostapd"$devidx".conf
fi
if [ "$band" == "6g" ]; then
cp -f /etc/hostapd-6G.conf /nvram/hostapd"$devidx".conf
fi
sed -i "/^interface=.*/c\interface=wifi$devidx" /nvram/hostapd"$devidx".conf
sed -i "/^bssid=/c\bssid=$MAC" /nvram/hostapd"$devidx".conf
echo "wpa_psk_file=/nvram/hostapd$devidx.psk" >> /nvram/hostapd"$devidx".conf
iw phy phy$phyidx interface add wifi$devidx type __ap > /dev/null
touch /nvram/hostapd-acl$devidx
touch /nvram/hostapd$devidx.psk
touch /nvram/hostapd-deny$devidx
touch /tmp/$dev-wifi$devidx
hostapd_cli -i global raw ADD bss_config=$dev:/nvram/hostapd"$devidx".conf && echo -e "wifi"$devidx"=1" >> /nvram/vap-status
devidx=$(($devidx + 1))
phyidx=$(($phyidx + 1))
done
}
#Creating files for tracking AssociatedDevices
touch /tmp/AllAssociated_Devices_2G.txt
touch /tmp/AllAssociated_Devices_5G.txt
#Create wps pin request log file
touch /var/run/hostapd_wps_pin_requests.log
create_hostapdConf
exit 0