blob: 71ddc7448d13ef29525412645f2bebed254f7edb [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
developer396fb8c2022-12-06 18:44:57 +08006 old_path=""
7 pcie7915count=0
8
developer08587352022-08-29 18:59:45 +08009 for _dev in /sys/class/ieee80211/*; do
10 [ -e "$_dev" ] || continue
developer7b43f2d2022-04-29 17:53:25 +080011
developer08587352022-08-29 18:59:45 +080012 dev="${_dev##*/}"
developer7b43f2d2022-04-29 17:53:25 +080013
developerba026b62022-10-18 10:04:07 +080014 band="$(uci get wireless.radio${phyidx}.band)"
15 channel="$(uci get wireless.radio${phyidx}.channel)"
developerc30fe122023-02-17 14:27:23 +080016 # Use random MAC to prevent use the same MAC address
17 rand="$(hexdump -C /dev/urandom | head -n 1 | awk '{printf ""$3":"$4""}' &)"
18 killall hexdump
19 MAC="00:0${devidx}:12:34:${rand}"
developer08587352022-08-29 18:59:45 +080020 chip="$(cat /sys/class/ieee80211/"$dev"/device/device)"
developer7b43f2d2022-04-29 17:53:25 +080021
developer396fb8c2022-12-06 18:44:57 +080022 if [ $chip == "0x7915" ]; then
23 path="$(realpath /sys/class/ieee80211/"$dev"/device | cut -d/ -f4-)"
24 if [ -n "$path" ]; then
25 if [ "$path" == "$old_path" ] || [ "$old_path" == "" ]; then
26 pcie7915count="1"
27 else
28 pcie7915count="2"
29 fi
30 fi
31 old_path=$path
32 fi
developerc30fe122023-02-17 14:27:23 +080033 iw wlan$phyidx del > /dev/null
developerba026b62022-10-18 10:04:07 +080034 if [ "$(uci get wireless.radio${phyidx}.disabled)" == "1" ]; then
35 phyidx=$(($phyidx + 1))
developer08587352022-08-29 18:59:45 +080036 continue
37 fi
developer7b43f2d2022-04-29 17:53:25 +080038
developer08587352022-08-29 18:59:45 +080039 if [ ! -f /nvram/hostapd"$devidx".conf ]; then
40 touch /nvram/hostapd"$devidx".conf
41 else
developer3107eaa2022-12-15 14:36:22 +080042 ifname="$(cat /nvram/hostapd"$devidx".conf | grep ^interface= | cut -d '=' -f2 | tr -d '\n')"
developerc30fe122023-02-17 14:27:23 +080043 iw phy phy$phyidx interface add $ifname type __ap > /dev/null
developer3107eaa2022-12-15 14:36:22 +080044 touch /nvram/hostapd-acl$devidx
45 touch /nvram/hostapd$devidx.psk
46 touch /nvram/hostapd-deny$devidx
developerba026b62022-10-18 10:04:07 +080047 touch /tmp/$dev-wifi$devidx
developerd8b860f2023-02-23 17:13:38 +080048 hostapd_cli -i global raw ADD bss_config=$dev:/nvram/hostapd"$devidx".conf
developer08587352022-08-29 18:59:45 +080049 devidx=$(($devidx + 1))
developerba026b62022-10-18 10:04:07 +080050 phyidx=$(($phyidx + 1))
developer08587352022-08-29 18:59:45 +080051 continue
52 fi
developer7b43f2d2022-04-29 17:53:25 +080053
developer7b43f2d2022-04-29 17:53:25 +080054
developer08587352022-08-29 18:59:45 +080055 if [ "$band" == "2g" ]; then
56 cp -f /etc/hostapd-2G.conf /nvram/hostapd"$devidx".conf
57 fi
developer7b43f2d2022-04-29 17:53:25 +080058
developer08587352022-08-29 18:59:45 +080059 if [ "$band" == "5g" ]; then
developer7b43f2d2022-04-29 17:53:25 +080060
developer08587352022-08-29 18:59:45 +080061 if [ $chip == "0x7906" ]; then
62 cp -f /etc/hostapd-5G-7916.conf /nvram/hostapd"$devidx".conf
63 elif [ $chip == "0x7915" ]; then
64 cp -f /etc/hostapd-5G-7915.conf /nvram/hostapd"$devidx".conf
65 else
66 cp -f /etc/hostapd-5G.conf /nvram/hostapd"$devidx".conf
67 fi
68 fi
developer7b43f2d2022-04-29 17:53:25 +080069
developer396fb8c2022-12-06 18:44:57 +080070 if [ "$pcie7915count" == "2" ]; then
71 cp -f /etc/hostapd-2G.conf /nvram/hostapd"$devidx".conf
72 fi
73
developer08587352022-08-29 18:59:45 +080074 if [ "$band" == "6g" ]; then
75 cp -f /etc/hostapd-6G.conf /nvram/hostapd"$devidx".conf
76 fi
developer7b43f2d2022-04-29 17:53:25 +080077
developer08587352022-08-29 18:59:45 +080078 sed -i "/^interface=.*/c\interface=wifi$devidx" /nvram/hostapd"$devidx".conf
developer1ac426a2022-12-22 19:44:36 +080079 sed -i "/^bssid=/c\bssid=$MAC" /nvram/hostapd"$devidx".conf
developer3107eaa2022-12-15 14:36:22 +080080 echo "wpa_psk_file=/nvram/hostapd$devidx.psk" >> /nvram/hostapd"$devidx".conf
developerc30fe122023-02-17 14:27:23 +080081 iw phy phy$phyidx interface add wifi$devidx type __ap > /dev/null
developer3107eaa2022-12-15 14:36:22 +080082 touch /nvram/hostapd-acl$devidx
83 touch /nvram/hostapd$devidx.psk
84 touch /nvram/hostapd-deny$devidx
developerba026b62022-10-18 10:04:07 +080085 touch /tmp/$dev-wifi$devidx
developer3107eaa2022-12-15 14:36:22 +080086 hostapd_cli -i global raw ADD bss_config=$dev:/nvram/hostapd"$devidx".conf && echo -e "wifi"$devidx"=1" >> /nvram/vap-status
developerba026b62022-10-18 10:04:07 +080087 devidx=$(($devidx + 1))
88 phyidx=$(($phyidx + 1))
developer08587352022-08-29 18:59:45 +080089
90 done
91}
developer7b43f2d2022-04-29 17:53:25 +080092#Creating files for tracking AssociatedDevices
93touch /tmp/AllAssociated_Devices_2G.txt
94touch /tmp/AllAssociated_Devices_5G.txt
95
developer7b43f2d2022-04-29 17:53:25 +080096#Create wps pin request log file
97touch /var/run/hostapd_wps_pin_requests.log
98
developer7b43f2d2022-04-29 17:53:25 +080099
developer08587352022-08-29 18:59:45 +0800100create_hostapdConf
developer21ea8132022-07-11 11:52:59 +0800101
developer3107eaa2022-12-15 14:36:22 +0800102exit 0