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 |
| 8 | |
developer | 0858735 | 2022-08-29 18:59:45 +0800 | [diff] [blame] | 9 | for _dev in /sys/class/ieee80211/*; do |
| 10 | [ -e "$_dev" ] || continue |
developer | 7b43f2d | 2022-04-29 17:53:25 +0800 | [diff] [blame] | 11 | |
developer | 0858735 | 2022-08-29 18:59:45 +0800 | [diff] [blame] | 12 | dev="${_dev##*/}" |
developer | 7b43f2d | 2022-04-29 17:53:25 +0800 | [diff] [blame] | 13 | |
developer | ba026b6 | 2022-10-18 10:04:07 +0800 | [diff] [blame] | 14 | band="$(uci get wireless.radio${phyidx}.band)" |
| 15 | channel="$(uci get wireless.radio${phyidx}.channel)" |
developer | c30fe12 | 2023-02-17 14:27:23 +0800 | [diff] [blame] | 16 | # Use random MAC to prevent use the same MAC address |
| 17 | rand="$(hexdump -C /dev/urandom | head -n 1 | awk '{printf ""$3":"$4""}' &)" |
| 18 | killall hexdump |
| 19 | MAC="00:0${devidx}:12:34:${rand}" |
developer | 0858735 | 2022-08-29 18:59:45 +0800 | [diff] [blame] | 20 | chip="$(cat /sys/class/ieee80211/"$dev"/device/device)" |
developer | 7b43f2d | 2022-04-29 17:53:25 +0800 | [diff] [blame] | 21 | |
developer | 396fb8c | 2022-12-06 18:44:57 +0800 | [diff] [blame] | 22 | if [ $chip == "0x7915" ]; then |
| 23 | path="$(realpath /sys/class/ieee80211/"$dev"/device | cut -d/ -f4-)" |
| 24 | if [ -n "$path" ]; then |
| 25 | if [ "$path" == "$old_path" ] || [ "$old_path" == "" ]; then |
| 26 | pcie7915count="1" |
| 27 | else |
| 28 | pcie7915count="2" |
| 29 | fi |
| 30 | fi |
| 31 | old_path=$path |
| 32 | fi |
developer | c30fe12 | 2023-02-17 14:27:23 +0800 | [diff] [blame] | 33 | iw wlan$phyidx del > /dev/null |
developer | ba026b6 | 2022-10-18 10:04:07 +0800 | [diff] [blame] | 34 | if [ "$(uci get wireless.radio${phyidx}.disabled)" == "1" ]; then |
| 35 | phyidx=$(($phyidx + 1)) |
developer | 0858735 | 2022-08-29 18:59:45 +0800 | [diff] [blame] | 36 | continue |
| 37 | fi |
developer | 7b43f2d | 2022-04-29 17:53:25 +0800 | [diff] [blame] | 38 | |
developer | 0858735 | 2022-08-29 18:59:45 +0800 | [diff] [blame] | 39 | if [ ! -f /nvram/hostapd"$devidx".conf ]; then |
| 40 | touch /nvram/hostapd"$devidx".conf |
| 41 | else |
developer | 3107eaa | 2022-12-15 14:36:22 +0800 | [diff] [blame] | 42 | ifname="$(cat /nvram/hostapd"$devidx".conf | grep ^interface= | cut -d '=' -f2 | tr -d '\n')" |
developer | c30fe12 | 2023-02-17 14:27:23 +0800 | [diff] [blame] | 43 | iw phy phy$phyidx interface add $ifname type __ap > /dev/null |
developer | 3107eaa | 2022-12-15 14:36:22 +0800 | [diff] [blame] | 44 | touch /nvram/hostapd-acl$devidx |
| 45 | touch /nvram/hostapd$devidx.psk |
| 46 | touch /nvram/hostapd-deny$devidx |
developer | ba026b6 | 2022-10-18 10:04:07 +0800 | [diff] [blame] | 47 | touch /tmp/$dev-wifi$devidx |
developer | d8b860f | 2023-02-23 17:13:38 +0800 | [diff] [blame] | 48 | hostapd_cli -i global raw ADD bss_config=$dev:/nvram/hostapd"$devidx".conf |
developer | 0858735 | 2022-08-29 18:59:45 +0800 | [diff] [blame] | 49 | devidx=$(($devidx + 1)) |
developer | ba026b6 | 2022-10-18 10:04:07 +0800 | [diff] [blame] | 50 | phyidx=$(($phyidx + 1)) |
developer | 0858735 | 2022-08-29 18:59:45 +0800 | [diff] [blame] | 51 | continue |
| 52 | fi |
developer | 7b43f2d | 2022-04-29 17:53:25 +0800 | [diff] [blame] | 53 | |
developer | 7b43f2d | 2022-04-29 17:53:25 +0800 | [diff] [blame] | 54 | |
developer | 0858735 | 2022-08-29 18:59:45 +0800 | [diff] [blame] | 55 | if [ "$band" == "2g" ]; then |
| 56 | cp -f /etc/hostapd-2G.conf /nvram/hostapd"$devidx".conf |
| 57 | fi |
developer | 7b43f2d | 2022-04-29 17:53:25 +0800 | [diff] [blame] | 58 | |
developer | 0858735 | 2022-08-29 18:59:45 +0800 | [diff] [blame] | 59 | if [ "$band" == "5g" ]; then |
developer | 7b43f2d | 2022-04-29 17:53:25 +0800 | [diff] [blame] | 60 | |
developer | 0858735 | 2022-08-29 18:59:45 +0800 | [diff] [blame] | 61 | if [ $chip == "0x7906" ]; then |
| 62 | cp -f /etc/hostapd-5G-7916.conf /nvram/hostapd"$devidx".conf |
| 63 | elif [ $chip == "0x7915" ]; then |
| 64 | cp -f /etc/hostapd-5G-7915.conf /nvram/hostapd"$devidx".conf |
| 65 | else |
| 66 | cp -f /etc/hostapd-5G.conf /nvram/hostapd"$devidx".conf |
| 67 | fi |
| 68 | fi |
developer | 7b43f2d | 2022-04-29 17:53:25 +0800 | [diff] [blame] | 69 | |
developer | 396fb8c | 2022-12-06 18:44:57 +0800 | [diff] [blame] | 70 | if [ "$pcie7915count" == "2" ]; then |
| 71 | cp -f /etc/hostapd-2G.conf /nvram/hostapd"$devidx".conf |
| 72 | fi |
| 73 | |
developer | 0858735 | 2022-08-29 18:59:45 +0800 | [diff] [blame] | 74 | if [ "$band" == "6g" ]; then |
| 75 | cp -f /etc/hostapd-6G.conf /nvram/hostapd"$devidx".conf |
| 76 | fi |
developer | 7b43f2d | 2022-04-29 17:53:25 +0800 | [diff] [blame] | 77 | |
developer | 0858735 | 2022-08-29 18:59:45 +0800 | [diff] [blame] | 78 | sed -i "/^interface=.*/c\interface=wifi$devidx" /nvram/hostapd"$devidx".conf |
developer | 1ac426a | 2022-12-22 19:44:36 +0800 | [diff] [blame] | 79 | sed -i "/^bssid=/c\bssid=$MAC" /nvram/hostapd"$devidx".conf |
developer | 3107eaa | 2022-12-15 14:36:22 +0800 | [diff] [blame] | 80 | echo "wpa_psk_file=/nvram/hostapd$devidx.psk" >> /nvram/hostapd"$devidx".conf |
developer | c30fe12 | 2023-02-17 14:27:23 +0800 | [diff] [blame] | 81 | iw phy phy$phyidx interface add wifi$devidx type __ap > /dev/null |
developer | 3107eaa | 2022-12-15 14:36:22 +0800 | [diff] [blame] | 82 | touch /nvram/hostapd-acl$devidx |
| 83 | touch /nvram/hostapd$devidx.psk |
| 84 | touch /nvram/hostapd-deny$devidx |
developer | ba026b6 | 2022-10-18 10:04:07 +0800 | [diff] [blame] | 85 | touch /tmp/$dev-wifi$devidx |
developer | 3107eaa | 2022-12-15 14:36:22 +0800 | [diff] [blame] | 86 | 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] | 87 | devidx=$(($devidx + 1)) |
| 88 | phyidx=$(($phyidx + 1)) |
developer | 0858735 | 2022-08-29 18:59:45 +0800 | [diff] [blame] | 89 | |
| 90 | done |
| 91 | } |
developer | 7b43f2d | 2022-04-29 17:53:25 +0800 | [diff] [blame] | 92 | #Creating files for tracking AssociatedDevices |
| 93 | touch /tmp/AllAssociated_Devices_2G.txt |
| 94 | touch /tmp/AllAssociated_Devices_5G.txt |
| 95 | |
developer | 7b43f2d | 2022-04-29 17:53:25 +0800 | [diff] [blame] | 96 | #Create wps pin request log file |
| 97 | touch /var/run/hostapd_wps_pin_requests.log |
| 98 | |
developer | 7b43f2d | 2022-04-29 17:53:25 +0800 | [diff] [blame] | 99 | |
developer | 0858735 | 2022-08-29 18:59:45 +0800 | [diff] [blame] | 100 | create_hostapdConf |
developer | 21ea813 | 2022-07-11 11:52:59 +0800 | [diff] [blame] | 101 | |
developer | 3107eaa | 2022-12-15 14:36:22 +0800 | [diff] [blame] | 102 | exit 0 |