blob: a8d9365547630f7ac59a3d56d266a473abe792fa [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
developer10f1e5c2022-10-18 10:04:07 +080039 iw dev wlan$phyidx interface add wifi$devidx type __ap
developer42af00d2022-08-29 18:59:45 +080040 touch /tmp/hostapd-acl$devidx
41 touch /tmp/hostapd$devidx.psk
developer10f1e5c2022-10-18 10:04:07 +080042 touch /tmp/hostapd-deny$devidx
43 touch /tmp/$dev-wifi$devidx
developer42af00d2022-08-29 18:59:45 +080044 hostapd_cli -i global raw ADD bss_config=$dev:/nvram/hostapd"$devidx".conf
45 devidx=$(($devidx + 1))
developer10f1e5c2022-10-18 10:04:07 +080046 phyidx=$(($phyidx + 1))
developer42af00d2022-08-29 18:59:45 +080047 continue
48 fi
developerfaf1ea22022-04-29 17:53:25 +080049
developerfaf1ea22022-04-29 17:53:25 +080050
developer42af00d2022-08-29 18:59:45 +080051 if [ "$band" == "2g" ]; then
52 cp -f /etc/hostapd-2G.conf /nvram/hostapd"$devidx".conf
53 fi
developerfaf1ea22022-04-29 17:53:25 +080054
developer42af00d2022-08-29 18:59:45 +080055 if [ "$band" == "5g" ]; then
developerfaf1ea22022-04-29 17:53:25 +080056
developer42af00d2022-08-29 18:59:45 +080057 if [ $chip == "0x7906" ]; then
58 cp -f /etc/hostapd-5G-7916.conf /nvram/hostapd"$devidx".conf
59 elif [ $chip == "0x7915" ]; then
60 cp -f /etc/hostapd-5G-7915.conf /nvram/hostapd"$devidx".conf
61 else
62 cp -f /etc/hostapd-5G.conf /nvram/hostapd"$devidx".conf
63 fi
64 fi
developerfaf1ea22022-04-29 17:53:25 +080065
developer6371ff42022-12-06 18:44:57 +080066 if [ "$pcie7915count" == "2" ]; then
67 cp -f /etc/hostapd-2G.conf /nvram/hostapd"$devidx".conf
68 fi
69
developer42af00d2022-08-29 18:59:45 +080070 if [ "$band" == "6g" ]; then
71 cp -f /etc/hostapd-6G.conf /nvram/hostapd"$devidx".conf
72 fi
developerfaf1ea22022-04-29 17:53:25 +080073
developer42af00d2022-08-29 18:59:45 +080074 sed -i "/^interface=.*/c\interface=wifi$devidx" /nvram/hostapd"$devidx".conf
75 sed -i "/^bssid=/c\bssid=$NEW_MAC" /nvram/hostapd"$devidx".conf
76 echo "wpa_psk_file=/tmp/hostapd$devidx.psk" >> /nvram/hostapd"$devidx".conf
developer10f1e5c2022-10-18 10:04:07 +080077 iw dev wlan$phyidx interface add wifi$devidx type __ap
developer42af00d2022-08-29 18:59:45 +080078 touch /tmp/hostapd-acl$devidx
79 touch /tmp/hostapd$devidx.psk
developer10f1e5c2022-10-18 10:04:07 +080080 touch /tmp/hostapd-deny$devidx
81 touch /tmp/$dev-wifi$devidx
developer42af00d2022-08-29 18:59:45 +080082 hostapd_cli -i global raw ADD bss_config=$dev:/nvram/hostapd"$devidx".conf
developer10f1e5c2022-10-18 10:04:07 +080083 devidx=$(($devidx + 1))
84 phyidx=$(($phyidx + 1))
developer42af00d2022-08-29 18:59:45 +080085
86 done
87}
developerfaf1ea22022-04-29 17:53:25 +080088echo -e "wifi0=1\nwifi1=1\nwifi2=0\nwifi3=0\nwifi4=0\nwifi5=0\nwifi6=0\nwifi7=0" >/tmp/vap-status
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
developer42af00d2022-08-29 18:59:45 +080099exit 0