blob: c49bb5f554b76c7a41e0e8d7e2f734974cd9beaa [file] [log] [blame]
developer7b43f2d2022-04-29 17:53:25 +08001#!/bin/sh
2
developer08587352022-08-29 18:59:45 +08003create_hostapdConf() {
4 devidx=0
developerba026b62022-10-18 10:04:07 +08005 phyidx=0
developer7b43f2d2022-04-29 17:53:25 +08006
developer08587352022-08-29 18:59:45 +08007 for _dev in /sys/class/ieee80211/*; do
8 [ -e "$_dev" ] || continue
developer7b43f2d2022-04-29 17:53:25 +08009
developer08587352022-08-29 18:59:45 +080010 dev="${_dev##*/}"
developer7b43f2d2022-04-29 17:53:25 +080011
developerba026b62022-10-18 10:04:07 +080012 band="$(uci get wireless.radio${phyidx}.band)"
13 channel="$(uci get wireless.radio${phyidx}.channel)"
14 MAC="$(cat /sys/class/net/wlan${phyidx}/address)"
developer08587352022-08-29 18:59:45 +080015 NEW_MAC=$(echo 0x$MAC| awk -F: '{printf "%02x:%s:%s:%s:%s:%s", strtonum($1)+2, $2, $3, $4 ,$5, $6}')
16 chip="$(cat /sys/class/ieee80211/"$dev"/device/device)"
developer7b43f2d2022-04-29 17:53:25 +080017
developerba026b62022-10-18 10:04:07 +080018 if [ "$(uci get wireless.radio${phyidx}.disabled)" == "1" ]; then
19 phyidx=$(($phyidx + 1))
developer08587352022-08-29 18:59:45 +080020 continue
21 fi
developer7b43f2d2022-04-29 17:53:25 +080022
developer08587352022-08-29 18:59:45 +080023 if [ ! -f /nvram/hostapd"$devidx".conf ]; then
24 touch /nvram/hostapd"$devidx".conf
25 else
developerba026b62022-10-18 10:04:07 +080026 iw dev wlan$phyidx interface add wifi$devidx type __ap
developer08587352022-08-29 18:59:45 +080027 touch /tmp/hostapd-acl$devidx
28 touch /tmp/hostapd$devidx.psk
developerba026b62022-10-18 10:04:07 +080029 touch /tmp/hostapd-deny$devidx
30 touch /tmp/$dev-wifi$devidx
developer08587352022-08-29 18:59:45 +080031 hostapd_cli -i global raw ADD bss_config=$dev:/nvram/hostapd"$devidx".conf
32 devidx=$(($devidx + 1))
developerba026b62022-10-18 10:04:07 +080033 phyidx=$(($phyidx + 1))
developer08587352022-08-29 18:59:45 +080034 continue
35 fi
developer7b43f2d2022-04-29 17:53:25 +080036
developer7b43f2d2022-04-29 17:53:25 +080037
developer08587352022-08-29 18:59:45 +080038 if [ "$band" == "2g" ]; then
39 cp -f /etc/hostapd-2G.conf /nvram/hostapd"$devidx".conf
40 fi
developer7b43f2d2022-04-29 17:53:25 +080041
developer08587352022-08-29 18:59:45 +080042 if [ "$band" == "5g" ]; then
developer7b43f2d2022-04-29 17:53:25 +080043
developer08587352022-08-29 18:59:45 +080044 if [ $chip == "0x7906" ]; then
45 cp -f /etc/hostapd-5G-7916.conf /nvram/hostapd"$devidx".conf
46 elif [ $chip == "0x7915" ]; then
47 cp -f /etc/hostapd-5G-7915.conf /nvram/hostapd"$devidx".conf
48 else
49 cp -f /etc/hostapd-5G.conf /nvram/hostapd"$devidx".conf
50 fi
51 fi
developer7b43f2d2022-04-29 17:53:25 +080052
developer08587352022-08-29 18:59:45 +080053 if [ "$band" == "6g" ]; then
54 cp -f /etc/hostapd-6G.conf /nvram/hostapd"$devidx".conf
55 fi
developer7b43f2d2022-04-29 17:53:25 +080056
developer08587352022-08-29 18:59:45 +080057 sed -i "/^interface=.*/c\interface=wifi$devidx" /nvram/hostapd"$devidx".conf
58 sed -i "/^bssid=/c\bssid=$NEW_MAC" /nvram/hostapd"$devidx".conf
59 echo "wpa_psk_file=/tmp/hostapd$devidx.psk" >> /nvram/hostapd"$devidx".conf
developerba026b62022-10-18 10:04:07 +080060 iw dev wlan$phyidx interface add wifi$devidx type __ap
developer08587352022-08-29 18:59:45 +080061 touch /tmp/hostapd-acl$devidx
62 touch /tmp/hostapd$devidx.psk
developerba026b62022-10-18 10:04:07 +080063 touch /tmp/hostapd-deny$devidx
64 touch /tmp/$dev-wifi$devidx
developer08587352022-08-29 18:59:45 +080065 hostapd_cli -i global raw ADD bss_config=$dev:/nvram/hostapd"$devidx".conf
developerba026b62022-10-18 10:04:07 +080066 devidx=$(($devidx + 1))
67 phyidx=$(($phyidx + 1))
developer08587352022-08-29 18:59:45 +080068
69 done
70}
developer7b43f2d2022-04-29 17:53:25 +080071echo -e "wifi0=1\nwifi1=1\nwifi2=0\nwifi3=0\nwifi4=0\nwifi5=0\nwifi6=0\nwifi7=0" >/tmp/vap-status
developer7b43f2d2022-04-29 17:53:25 +080072#Creating files for tracking AssociatedDevices
73touch /tmp/AllAssociated_Devices_2G.txt
74touch /tmp/AllAssociated_Devices_5G.txt
75
developer7b43f2d2022-04-29 17:53:25 +080076#Create wps pin request log file
77touch /var/run/hostapd_wps_pin_requests.log
78
developer7b43f2d2022-04-29 17:53:25 +080079
developer08587352022-08-29 18:59:45 +080080create_hostapdConf
developer21ea8132022-07-11 11:52:59 +080081
developer08587352022-08-29 18:59:45 +080082exit 0