blob: 7bb37d3f0b9557173ec491fceda422ee44681608 [file] [log] [blame]
developerfaf1ea22022-04-29 17:53:25 +08001#!/bin/sh
2
developer42af00d2022-08-29 18:59:45 +08003create_hostapdConf() {
4 devidx=0
developer10f1e5c2022-10-18 10:04:07 +08005 phyidx=0
developer6371ff42022-12-06 18:44:57 +08006 old_path=""
7 pcie7915count=0
8
developer42af00d2022-08-29 18:59:45 +08009 for _dev in /sys/class/ieee80211/*; do
10 [ -e "$_dev" ] || continue
developerfaf1ea22022-04-29 17:53:25 +080011
developer42af00d2022-08-29 18:59:45 +080012 dev="${_dev##*/}"
developerfaf1ea22022-04-29 17:53:25 +080013
developer10f1e5c2022-10-18 10:04:07 +080014 band="$(uci get wireless.radio${phyidx}.band)"
15 channel="$(uci get wireless.radio${phyidx}.channel)"
16 MAC="$(cat /sys/class/net/wlan${phyidx}/address)"
developer42af00d2022-08-29 18:59:45 +080017 NEW_MAC=$(echo 0x$MAC| awk -F: '{printf "%02x:%s:%s:%s:%s:%s", strtonum($1)+2, $2, $3, $4 ,$5, $6}')
18 chip="$(cat /sys/class/ieee80211/"$dev"/device/device)"
developerfaf1ea22022-04-29 17:53:25 +080019
developer6371ff42022-12-06 18:44:57 +080020 if [ $chip == "0x7915" ]; then
21 path="$(realpath /sys/class/ieee80211/"$dev"/device | cut -d/ -f4-)"
22 if [ -n "$path" ]; then
23 if [ "$path" == "$old_path" ] || [ "$old_path" == "" ]; then
24 pcie7915count="1"
25 else
26 pcie7915count="2"
27 fi
28 fi
29 old_path=$path
30 fi
developer10f1e5c2022-10-18 10:04:07 +080031 if [ "$(uci get wireless.radio${phyidx}.disabled)" == "1" ]; then
32 phyidx=$(($phyidx + 1))
developer42af00d2022-08-29 18:59:45 +080033 continue
34 fi
developerfaf1ea22022-04-29 17:53:25 +080035
developer42af00d2022-08-29 18:59:45 +080036 if [ ! -f /nvram/hostapd"$devidx".conf ]; then
37 touch /nvram/hostapd"$devidx".conf
38 else
developerfe315c32022-12-15 14:36:22 +080039 ifname="$(cat /nvram/hostapd"$devidx".conf | grep ^interface= | cut -d '=' -f2 | tr -d '\n')"
40 iw phy phy$phyidx interface add $ifname type __ap
41 touch /nvram/hostapd-acl$devidx
42 touch /nvram/hostapd$devidx.psk
43 touch /nvram/hostapd-deny$devidx
developer10f1e5c2022-10-18 10:04:07 +080044 touch /tmp/$dev-wifi$devidx
developerfe315c32022-12-15 14:36:22 +080045 hostapd_cli -i global raw ADD bss_config=$dev:/nvram/hostapd"$devidx".conf && echo -e $ifname=1 >> /nvram/vap-status
developer42af00d2022-08-29 18:59:45 +080046 devidx=$(($devidx + 1))
developer10f1e5c2022-10-18 10:04:07 +080047 phyidx=$(($phyidx + 1))
developer42af00d2022-08-29 18:59:45 +080048 continue
49 fi
developerfaf1ea22022-04-29 17:53:25 +080050
developerfaf1ea22022-04-29 17:53:25 +080051
developer42af00d2022-08-29 18:59:45 +080052 if [ "$band" == "2g" ]; then
53 cp -f /etc/hostapd-2G.conf /nvram/hostapd"$devidx".conf
54 fi
developerfaf1ea22022-04-29 17:53:25 +080055
developer42af00d2022-08-29 18:59:45 +080056 if [ "$band" == "5g" ]; then
developerfaf1ea22022-04-29 17:53:25 +080057
developer42af00d2022-08-29 18:59:45 +080058 if [ $chip == "0x7906" ]; then
59 cp -f /etc/hostapd-5G-7916.conf /nvram/hostapd"$devidx".conf
60 elif [ $chip == "0x7915" ]; then
61 cp -f /etc/hostapd-5G-7915.conf /nvram/hostapd"$devidx".conf
62 else
63 cp -f /etc/hostapd-5G.conf /nvram/hostapd"$devidx".conf
64 fi
65 fi
developerfaf1ea22022-04-29 17:53:25 +080066
developer6371ff42022-12-06 18:44:57 +080067 if [ "$pcie7915count" == "2" ]; then
68 cp -f /etc/hostapd-2G.conf /nvram/hostapd"$devidx".conf
69 fi
70
developer42af00d2022-08-29 18:59:45 +080071 if [ "$band" == "6g" ]; then
72 cp -f /etc/hostapd-6G.conf /nvram/hostapd"$devidx".conf
73 fi
developerfaf1ea22022-04-29 17:53:25 +080074
developer42af00d2022-08-29 18:59:45 +080075 sed -i "/^interface=.*/c\interface=wifi$devidx" /nvram/hostapd"$devidx".conf
76 sed -i "/^bssid=/c\bssid=$NEW_MAC" /nvram/hostapd"$devidx".conf
developerfe315c32022-12-15 14:36:22 +080077 echo "wpa_psk_file=/nvram/hostapd$devidx.psk" >> /nvram/hostapd"$devidx".conf
78 iw phy phy$phyidx interface add wifi$devidx type __ap
79 touch /nvram/hostapd-acl$devidx
80 touch /nvram/hostapd$devidx.psk
81 touch /nvram/hostapd-deny$devidx
developer10f1e5c2022-10-18 10:04:07 +080082 touch /tmp/$dev-wifi$devidx
developerfe315c32022-12-15 14:36:22 +080083 hostapd_cli -i global raw ADD bss_config=$dev:/nvram/hostapd"$devidx".conf && echo -e "wifi"$devidx"=1" >> /nvram/vap-status
developer10f1e5c2022-10-18 10:04:07 +080084 devidx=$(($devidx + 1))
85 phyidx=$(($phyidx + 1))
developer42af00d2022-08-29 18:59:45 +080086
87 done
88}
developerfaf1ea22022-04-29 17:53:25 +080089#Creating files for tracking AssociatedDevices
90touch /tmp/AllAssociated_Devices_2G.txt
91touch /tmp/AllAssociated_Devices_5G.txt
92
developerfaf1ea22022-04-29 17:53:25 +080093#Create wps pin request log file
94touch /var/run/hostapd_wps_pin_requests.log
95
developerfaf1ea22022-04-29 17:53:25 +080096
developer42af00d2022-08-29 18:59:45 +080097create_hostapdConf
developer880c8292022-07-11 11:52:59 +080098
developerfe315c32022-12-15 14:36:22 +080099exit 0