developer | 7b43f2d | 2022-04-29 17:53:25 +0800 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
developer | 0858735 | 2022-08-29 18:59:45 +0800 | [diff] [blame] | 3 | create_hostapdConf() { |
| 4 | devidx=0 |
developer | ba026b6 | 2022-10-18 10:04:07 +0800 | [diff] [blame] | 5 | phyidx=0 |
developer | 396fb8c | 2022-12-06 18:44:57 +0800 | [diff] [blame] | 6 | old_path="" |
| 7 | pcie7915count=0 |
developer | 8b53cab | 2023-04-04 17:10:03 +0800 | [diff] [blame] | 8 | vap_per_radio=8 |
| 9 | radio_num="$(iw list | grep Wiphy | wc -l)" |
| 10 | |
| 11 | for _dev in /sys/class/ieee80211/*; do |
developer | 0858735 | 2022-08-29 18:59:45 +0800 | [diff] [blame] | 12 | [ -e "$_dev" ] || continue |
developer | 7b43f2d | 2022-04-29 17:53:25 +0800 | [diff] [blame] | 13 | |
developer | 0858735 | 2022-08-29 18:59:45 +0800 | [diff] [blame] | 14 | dev="${_dev##*/}" |
developer | 7b43f2d | 2022-04-29 17:53:25 +0800 | [diff] [blame] | 15 | |
developer | ba026b6 | 2022-10-18 10:04:07 +0800 | [diff] [blame] | 16 | band="$(uci get wireless.radio${phyidx}.band)" |
| 17 | channel="$(uci get wireless.radio${phyidx}.channel)" |
developer | c30fe12 | 2023-02-17 14:27:23 +0800 | [diff] [blame] | 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}" |
developer | 0858735 | 2022-08-29 18:59:45 +0800 | [diff] [blame] | 22 | chip="$(cat /sys/class/ieee80211/"$dev"/device/device)" |
developer | 7b43f2d | 2022-04-29 17:53:25 +0800 | [diff] [blame] | 23 | |
developer | 396fb8c | 2022-12-06 18:44:57 +0800 | [diff] [blame] | 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 |
developer | 8b53cab | 2023-04-04 17:10:03 +0800 | [diff] [blame] | 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 |
developer | ba026b6 | 2022-10-18 10:04:07 +0800 | [diff] [blame] | 52 | phyidx=$(($phyidx + 1)) |
developer | 0858735 | 2022-08-29 18:59:45 +0800 | [diff] [blame] | 53 | continue |
| 54 | fi |
developer | 7b43f2d | 2022-04-29 17:53:25 +0800 | [diff] [blame] | 55 | |
developer | 0858735 | 2022-08-29 18:59:45 +0800 | [diff] [blame] | 56 | if [ ! -f /nvram/hostapd"$devidx".conf ]; then |
| 57 | touch /nvram/hostapd"$devidx".conf |
| 58 | else |
developer | 8b53cab | 2023-04-04 17:10:03 +0800 | [diff] [blame] | 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)" |
developer | 19c4f2d | 2023-04-20 20:51:47 +0800 | [diff] [blame] | 63 | if [ -n $ifname ] && [[ $vapstat -eq "1" ]]; then |
developer | 8b53cab | 2023-04-04 17:10:03 +0800 | [diff] [blame] | 64 | 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 |
developer | c4bd513 | 2023-04-26 20:05:34 +0800 | [diff] [blame] | 71 | if [ $phyidx = $ifidx ]; then |
| 72 | touch /tmp/$dev-wifi$ifidx |
| 73 | fi |
developer | 8b53cab | 2023-04-04 17:10:03 +0800 | [diff] [blame] | 74 | hostapd_cli -i global raw ADD bss_config=$dev:/nvram/hostapd"$ifidx".conf |
| 75 | fi |
| 76 | done |
developer | 0858735 | 2022-08-29 18:59:45 +0800 | [diff] [blame] | 77 | devidx=$(($devidx + 1)) |
developer | ba026b6 | 2022-10-18 10:04:07 +0800 | [diff] [blame] | 78 | phyidx=$(($phyidx + 1)) |
developer | 8b53cab | 2023-04-04 17:10:03 +0800 | [diff] [blame] | 79 | continue |
developer | 0858735 | 2022-08-29 18:59:45 +0800 | [diff] [blame] | 80 | fi |
developer | 7b43f2d | 2022-04-29 17:53:25 +0800 | [diff] [blame] | 81 | |
developer | 7b43f2d | 2022-04-29 17:53:25 +0800 | [diff] [blame] | 82 | |
developer | 0858735 | 2022-08-29 18:59:45 +0800 | [diff] [blame] | 83 | if [ "$band" == "2g" ]; then |
| 84 | cp -f /etc/hostapd-2G.conf /nvram/hostapd"$devidx".conf |
| 85 | fi |
developer | 7b43f2d | 2022-04-29 17:53:25 +0800 | [diff] [blame] | 86 | |
developer | 0858735 | 2022-08-29 18:59:45 +0800 | [diff] [blame] | 87 | if [ "$band" == "5g" ]; then |
developer | 7b43f2d | 2022-04-29 17:53:25 +0800 | [diff] [blame] | 88 | |
developer | 0858735 | 2022-08-29 18:59:45 +0800 | [diff] [blame] | 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 |
developer | 7b43f2d | 2022-04-29 17:53:25 +0800 | [diff] [blame] | 97 | |
developer | 0858735 | 2022-08-29 18:59:45 +0800 | [diff] [blame] | 98 | if [ "$band" == "6g" ]; then |
| 99 | cp -f /etc/hostapd-6G.conf /nvram/hostapd"$devidx".conf |
| 100 | fi |
developer | 7b43f2d | 2022-04-29 17:53:25 +0800 | [diff] [blame] | 101 | |
developer | 0858735 | 2022-08-29 18:59:45 +0800 | [diff] [blame] | 102 | sed -i "/^interface=.*/c\interface=wifi$devidx" /nvram/hostapd"$devidx".conf |
developer | 1ac426a | 2022-12-22 19:44:36 +0800 | [diff] [blame] | 103 | sed -i "/^bssid=/c\bssid=$MAC" /nvram/hostapd"$devidx".conf |
developer | 3107eaa | 2022-12-15 14:36:22 +0800 | [diff] [blame] | 104 | echo "wpa_psk_file=/nvram/hostapd$devidx.psk" >> /nvram/hostapd"$devidx".conf |
developer | c30fe12 | 2023-02-17 14:27:23 +0800 | [diff] [blame] | 105 | iw phy phy$phyidx interface add wifi$devidx type __ap > /dev/null |
developer | 3107eaa | 2022-12-15 14:36:22 +0800 | [diff] [blame] | 106 | touch /nvram/hostapd-acl$devidx |
| 107 | touch /nvram/hostapd$devidx.psk |
| 108 | touch /nvram/hostapd-deny$devidx |
developer | ba026b6 | 2022-10-18 10:04:07 +0800 | [diff] [blame] | 109 | touch /tmp/$dev-wifi$devidx |
developer | 3107eaa | 2022-12-15 14:36:22 +0800 | [diff] [blame] | 110 | hostapd_cli -i global raw ADD bss_config=$dev:/nvram/hostapd"$devidx".conf && echo -e "wifi"$devidx"=1" >> /nvram/vap-status |
developer | ba026b6 | 2022-10-18 10:04:07 +0800 | [diff] [blame] | 111 | devidx=$(($devidx + 1)) |
| 112 | phyidx=$(($phyidx + 1)) |
developer | 0858735 | 2022-08-29 18:59:45 +0800 | [diff] [blame] | 113 | |
| 114 | done |
| 115 | } |
developer | 7b43f2d | 2022-04-29 17:53:25 +0800 | [diff] [blame] | 116 | #Creating files for tracking AssociatedDevices |
| 117 | touch /tmp/AllAssociated_Devices_2G.txt |
| 118 | touch /tmp/AllAssociated_Devices_5G.txt |
| 119 | |
developer | 7b43f2d | 2022-04-29 17:53:25 +0800 | [diff] [blame] | 120 | #Create wps pin request log file |
| 121 | touch /var/run/hostapd_wps_pin_requests.log |
| 122 | |
developer | 7b43f2d | 2022-04-29 17:53:25 +0800 | [diff] [blame] | 123 | |
developer | 0858735 | 2022-08-29 18:59:45 +0800 | [diff] [blame] | 124 | create_hostapdConf |
developer | 21ea813 | 2022-07-11 11:52:59 +0800 | [diff] [blame] | 125 | |
developer | 3107eaa | 2022-12-15 14:36:22 +0800 | [diff] [blame] | 126 | exit 0 |