blob: 35c9b08e59d35b9632acadcdf858644ea3082d2d [file] [log] [blame]
developer617abbd2024-04-23 14:50:01 +08001#!/bin/sh
2
3create_hostapdConf() {
4 devidx=0
5 phyidx=0
6 old_path=""
7 pcie7915count=0
8 vap_per_radio=8
9 radio_num="$(iw list | grep Wiphy | wc -l)"
10
11 for _dev in /sys/class/ieee80211/*; do
12 [ -e "$_dev" ] || continue
13
14 dev="${_dev##*/}"
15
16 band="$(uci get wireless.radio${phyidx}.band)"
17 channel="$(uci get wireless.radio${phyidx}.channel)"
18 # 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}"
22 chip="$(cat /sys/class/ieee80211/"$dev"/device/device)"
23
24 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
35
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
52 phyidx=$(($phyidx + 1))
53 continue
54 fi
55
56 if [ ! -f /nvram/hostapd"$devidx".conf ]; then
57 touch /nvram/hostapd"$devidx".conf
58 else
59 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)"
63 if [ -n $ifname ] && [[ $vapstat -eq "1" ]]; then
64 if [ $i = 0 ]; then
65 ## first interface in this phy
66 iw phy phy0 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
71 if [ $phyidx = $ifidx ]; then
72 touch /tmp/$dev-wifi$ifidx
73 fi
74 hostapd_cli -i global raw ADD bss_config=$dev:/nvram/hostapd"$ifidx".conf
75 fi
76 done
77 devidx=$(($devidx + 1))
78 phyidx=$(($phyidx + 1))
79 continue
80 fi
81
82
83 if [ "$band" == "2g" ]; then
84 cp -f /etc/hostapd-2G.conf /nvram/hostapd"$devidx".conf
85 fi
86
87 if [ "$band" == "5g" ]; then
88
89 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
97
98 if [ "$band" == "6g" ]; then
99 cp -f /etc/hostapd-6G.conf /nvram/hostapd"$devidx".conf
100 fi
101
102 sed -i "/^interface=.*/c\interface=wifi$devidx" /nvram/hostapd"$devidx".conf
103 sed -i "/^bssid=/c\bssid=$MAC" /nvram/hostapd"$devidx".conf
104 echo "wpa_psk_file=/nvram/hostapd$devidx.psk" >> /nvram/hostapd"$devidx".conf
105 iw phy phy0 interface add wifi$devidx type __ap > /dev/null
106 touch /nvram/hostapd-acl$devidx
107 touch /nvram/hostapd$devidx.psk
108 touch /nvram/hostapd-deny$devidx
109 touch /tmp/$dev-wifi$devidx
110 hostapd_cli -i global raw ADD bss_config=$dev:/nvram/hostapd"$devidx".conf && echo -e "wifi"$devidx"=1" >> /nvram/vap-status
111 devidx=$(($devidx + 1))
112 phyidx=$(($phyidx + 1))
113
114 done
115}
116#Creating files for tracking AssociatedDevices
117touch /tmp/AllAssociated_Devices_2G.txt
118touch /tmp/AllAssociated_Devices_5G.txt
119
120#Create wps pin request log file
121touch /var/run/hostapd_wps_pin_requests.log
122
123
124create_hostapdConf
125
126exit 0