| #!/bin/sh |
| |
| create_hostapdConf() { |
| devidx=0 |
| phyidx=0 |
| old_path="" |
| pcie7915count=0 |
| |
| 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 |
| iw wlan$phyidx del > /dev/null |
| 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 |
| ifname="$(cat /nvram/hostapd"$devidx".conf | grep ^interface= | cut -d '=' -f2 | tr -d '\n')" |
| iw phy phy$phyidx interface add $ifname 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 |
| 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 |