blob: db83db3f8953a0d50ca3a734f559a4cd74b937d8 [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
developer8b53cab2023-04-04 17:10:03 +08008 vap_per_radio=8
9 radio_num="$(iw list | grep Wiphy | wc -l)"
10
11 for _dev in /sys/class/ieee80211/*; do
developer08587352022-08-29 18:59:45 +080012 [ -e "$_dev" ] || continue
developer7b43f2d2022-04-29 17:53:25 +080013
developer08587352022-08-29 18:59:45 +080014 dev="${_dev##*/}"
developer7b43f2d2022-04-29 17:53:25 +080015
developerba026b62022-10-18 10:04:07 +080016 band="$(uci get wireless.radio${phyidx}.band)"
17 channel="$(uci get wireless.radio${phyidx}.channel)"
developerc30fe122023-02-17 14:27:23 +080018 # Use random MAC to prevent use the same MAC address
19 rand="$(hexdump -C /dev/urandom | head -n 1 | awk '{printf ""$3":"$4""}' &)"
20 killall hexdump
21 MAC="00:0${devidx}:12:34:${rand}"
developer08587352022-08-29 18:59:45 +080022 chip="$(cat /sys/class/ieee80211/"$dev"/device/device)"
developer7b43f2d2022-04-29 17:53:25 +080023
developer396fb8c2022-12-06 18:44:57 +080024 if [ $chip == "0x7915" ]; then
25 path="$(realpath /sys/class/ieee80211/"$dev"/device | cut -d/ -f4-)"
26 if [ -n "$path" ]; then
27 if [ "$path" == "$old_path" ] || [ "$old_path" == "" ]; then
28 pcie7915count="1"
29 else
30 pcie7915count="2"
31 fi
32 fi
33 old_path=$path
34 fi
developer8b53cab2023-04-04 17:10:03 +080035
36 if [ -e /sys/class/net/wlan$phyidx ]; then
37 iw wlan$phyidx del > /dev/null
38 elif [ -e /sys/class/net/wifi$phyidx ]; then
39 for((i=0;i<$vap_per_radio;i++)); do
40 ifidx=$(($phyidx+$i*$radio_num))
41 ifname="$(cat /nvram/hostapd"$ifidx".conf | grep ^interface= | cut -d '=' -f2 | tr -d '\n')"
42 if [ -n $ifname ]; then
43 hostapd_cli -i global raw REMOVE wifi$ifidx > /dev/null
44 if [ $i -eq 0 ]; then
45 iw wifi$ifidx del > /dev/null
46 fi
47 fi
48 done
49 fi
50
51 if [ "$(uci get wireless.radio${phyidx}.disabled)" == "1" ]; then
developerba026b62022-10-18 10:04:07 +080052 phyidx=$(($phyidx + 1))
developer08587352022-08-29 18:59:45 +080053 continue
54 fi
developer7b43f2d2022-04-29 17:53:25 +080055
developer08587352022-08-29 18:59:45 +080056 if [ ! -f /nvram/hostapd"$devidx".conf ]; then
57 touch /nvram/hostapd"$devidx".conf
58 else
developer8b53cab2023-04-04 17:10:03 +080059 for((i=0;i<$vap_per_radio;i++)); do
60 ifidx=$(($phyidx+$i*$radio_num))
61 ifname="$(cat /nvram/hostapd"$ifidx".conf | grep ^interface= | cut -d '=' -f2 | tr -d '\n')"
62 vapstat="$(cat /nvram/vap-status | grep wifi"$ifidx"= | cut -d'=' -f2)"
developer19c4f2d2023-04-20 20:51:47 +080063 if [ -n $ifname ] && [[ $vapstat -eq "1" ]]; then
developer8b53cab2023-04-04 17:10:03 +080064 if [ $i = 0 ]; then
65 ## first interface in this phy
66 iw phy phy$phyidx interface add $ifname type __ap > /dev/null
67 fi
68 touch /nvram/hostapd-acl$ifidx
69 touch /nvram/hostapd$ifidx.psk
70 touch /nvram/hostapd-deny$ifidx
developerc4bd5132023-04-26 20:05:34 +080071 if [ $phyidx = $ifidx ]; then
72 touch /tmp/$dev-wifi$ifidx
73 fi
developer8b53cab2023-04-04 17:10:03 +080074 hostapd_cli -i global raw ADD bss_config=$dev:/nvram/hostapd"$ifidx".conf
75 fi
76 done
developer08587352022-08-29 18:59:45 +080077 devidx=$(($devidx + 1))
developerba026b62022-10-18 10:04:07 +080078 phyidx=$(($phyidx + 1))
developer8b53cab2023-04-04 17:10:03 +080079 continue
developer08587352022-08-29 18:59:45 +080080 fi
developer7b43f2d2022-04-29 17:53:25 +080081
developer7b43f2d2022-04-29 17:53:25 +080082
developer08587352022-08-29 18:59:45 +080083 if [ "$band" == "2g" ]; then
84 cp -f /etc/hostapd-2G.conf /nvram/hostapd"$devidx".conf
85 fi
developer7b43f2d2022-04-29 17:53:25 +080086
developer08587352022-08-29 18:59:45 +080087 if [ "$band" == "5g" ]; then
developer7b43f2d2022-04-29 17:53:25 +080088
developer08587352022-08-29 18:59:45 +080089 if [ $chip == "0x7906" ]; then
90 cp -f /etc/hostapd-5G-7916.conf /nvram/hostapd"$devidx".conf
91 elif [ $chip == "0x7915" ]; then
92 cp -f /etc/hostapd-5G-7915.conf /nvram/hostapd"$devidx".conf
93 else
94 cp -f /etc/hostapd-5G.conf /nvram/hostapd"$devidx".conf
95 fi
96 fi
developer7b43f2d2022-04-29 17:53:25 +080097
developer08587352022-08-29 18:59:45 +080098 if [ "$band" == "6g" ]; then
99 cp -f /etc/hostapd-6G.conf /nvram/hostapd"$devidx".conf
100 fi
developer7b43f2d2022-04-29 17:53:25 +0800101
developer08587352022-08-29 18:59:45 +0800102 sed -i "/^interface=.*/c\interface=wifi$devidx" /nvram/hostapd"$devidx".conf
developer1ac426a2022-12-22 19:44:36 +0800103 sed -i "/^bssid=/c\bssid=$MAC" /nvram/hostapd"$devidx".conf
developer3107eaa2022-12-15 14:36:22 +0800104 echo "wpa_psk_file=/nvram/hostapd$devidx.psk" >> /nvram/hostapd"$devidx".conf
developerc30fe122023-02-17 14:27:23 +0800105 iw phy phy$phyidx interface add wifi$devidx type __ap > /dev/null
developer3107eaa2022-12-15 14:36:22 +0800106 touch /nvram/hostapd-acl$devidx
107 touch /nvram/hostapd$devidx.psk
108 touch /nvram/hostapd-deny$devidx
developerba026b62022-10-18 10:04:07 +0800109 touch /tmp/$dev-wifi$devidx
developer3107eaa2022-12-15 14:36:22 +0800110 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 +0800111 devidx=$(($devidx + 1))
112 phyidx=$(($phyidx + 1))
developer08587352022-08-29 18:59:45 +0800113
114 done
115}
developer7b43f2d2022-04-29 17:53:25 +0800116#Creating files for tracking AssociatedDevices
117touch /tmp/AllAssociated_Devices_2G.txt
118touch /tmp/AllAssociated_Devices_5G.txt
119
developer7b43f2d2022-04-29 17:53:25 +0800120#Create wps pin request log file
121touch /var/run/hostapd_wps_pin_requests.log
122
developer7b43f2d2022-04-29 17:53:25 +0800123
developer08587352022-08-29 18:59:45 +0800124create_hostapdConf
developer21ea8132022-07-11 11:52:59 +0800125
developer3107eaa2022-12-15 14:36:22 +0800126exit 0