developer | faf1ea2 | 2022-04-29 17:53:25 +0800 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
developer | 42af00d | 2022-08-29 18:59:45 +0800 | [diff] [blame] | 3 | create_hostapdConf() { |
| 4 | devidx=0 |
developer | 10f1e5c | 2022-10-18 10:04:07 +0800 | [diff] [blame] | 5 | phyidx=0 |
developer | 6371ff4 | 2022-12-06 18:44:57 +0800 | [diff] [blame] | 6 | old_path="" |
| 7 | pcie7915count=0 |
| 8 | |
developer | 42af00d | 2022-08-29 18:59:45 +0800 | [diff] [blame] | 9 | for _dev in /sys/class/ieee80211/*; do |
| 10 | [ -e "$_dev" ] || continue |
developer | faf1ea2 | 2022-04-29 17:53:25 +0800 | [diff] [blame] | 11 | |
developer | 42af00d | 2022-08-29 18:59:45 +0800 | [diff] [blame] | 12 | dev="${_dev##*/}" |
developer | faf1ea2 | 2022-04-29 17:53:25 +0800 | [diff] [blame] | 13 | |
developer | 10f1e5c | 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)" |
| 16 | MAC="$(cat /sys/class/net/wlan${phyidx}/address)" |
developer | 42af00d | 2022-08-29 18:59:45 +0800 | [diff] [blame] | 17 | 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)" |
developer | faf1ea2 | 2022-04-29 17:53:25 +0800 | [diff] [blame] | 19 | |
developer | 6371ff4 | 2022-12-06 18:44:57 +0800 | [diff] [blame] | 20 | 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 |
developer | 10f1e5c | 2022-10-18 10:04:07 +0800 | [diff] [blame] | 31 | if [ "$(uci get wireless.radio${phyidx}.disabled)" == "1" ]; then |
| 32 | phyidx=$(($phyidx + 1)) |
developer | 42af00d | 2022-08-29 18:59:45 +0800 | [diff] [blame] | 33 | continue |
| 34 | fi |
developer | faf1ea2 | 2022-04-29 17:53:25 +0800 | [diff] [blame] | 35 | |
developer | 42af00d | 2022-08-29 18:59:45 +0800 | [diff] [blame] | 36 | if [ ! -f /nvram/hostapd"$devidx".conf ]; then |
| 37 | touch /nvram/hostapd"$devidx".conf |
| 38 | else |
developer | fe315c3 | 2022-12-15 14:36:22 +0800 | [diff] [blame^] | 39 | 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 |
developer | 10f1e5c | 2022-10-18 10:04:07 +0800 | [diff] [blame] | 44 | touch /tmp/$dev-wifi$devidx |
developer | fe315c3 | 2022-12-15 14:36:22 +0800 | [diff] [blame^] | 45 | hostapd_cli -i global raw ADD bss_config=$dev:/nvram/hostapd"$devidx".conf && echo -e $ifname=1 >> /nvram/vap-status |
developer | 42af00d | 2022-08-29 18:59:45 +0800 | [diff] [blame] | 46 | devidx=$(($devidx + 1)) |
developer | 10f1e5c | 2022-10-18 10:04:07 +0800 | [diff] [blame] | 47 | phyidx=$(($phyidx + 1)) |
developer | 42af00d | 2022-08-29 18:59:45 +0800 | [diff] [blame] | 48 | continue |
| 49 | fi |
developer | faf1ea2 | 2022-04-29 17:53:25 +0800 | [diff] [blame] | 50 | |
developer | faf1ea2 | 2022-04-29 17:53:25 +0800 | [diff] [blame] | 51 | |
developer | 42af00d | 2022-08-29 18:59:45 +0800 | [diff] [blame] | 52 | if [ "$band" == "2g" ]; then |
| 53 | cp -f /etc/hostapd-2G.conf /nvram/hostapd"$devidx".conf |
| 54 | fi |
developer | faf1ea2 | 2022-04-29 17:53:25 +0800 | [diff] [blame] | 55 | |
developer | 42af00d | 2022-08-29 18:59:45 +0800 | [diff] [blame] | 56 | if [ "$band" == "5g" ]; then |
developer | faf1ea2 | 2022-04-29 17:53:25 +0800 | [diff] [blame] | 57 | |
developer | 42af00d | 2022-08-29 18:59:45 +0800 | [diff] [blame] | 58 | 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 |
developer | faf1ea2 | 2022-04-29 17:53:25 +0800 | [diff] [blame] | 66 | |
developer | 6371ff4 | 2022-12-06 18:44:57 +0800 | [diff] [blame] | 67 | if [ "$pcie7915count" == "2" ]; then |
| 68 | cp -f /etc/hostapd-2G.conf /nvram/hostapd"$devidx".conf |
| 69 | fi |
| 70 | |
developer | 42af00d | 2022-08-29 18:59:45 +0800 | [diff] [blame] | 71 | if [ "$band" == "6g" ]; then |
| 72 | cp -f /etc/hostapd-6G.conf /nvram/hostapd"$devidx".conf |
| 73 | fi |
developer | faf1ea2 | 2022-04-29 17:53:25 +0800 | [diff] [blame] | 74 | |
developer | 42af00d | 2022-08-29 18:59:45 +0800 | [diff] [blame] | 75 | sed -i "/^interface=.*/c\interface=wifi$devidx" /nvram/hostapd"$devidx".conf |
| 76 | sed -i "/^bssid=/c\bssid=$NEW_MAC" /nvram/hostapd"$devidx".conf |
developer | fe315c3 | 2022-12-15 14:36:22 +0800 | [diff] [blame^] | 77 | 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 |
developer | 10f1e5c | 2022-10-18 10:04:07 +0800 | [diff] [blame] | 82 | touch /tmp/$dev-wifi$devidx |
developer | fe315c3 | 2022-12-15 14:36:22 +0800 | [diff] [blame^] | 83 | hostapd_cli -i global raw ADD bss_config=$dev:/nvram/hostapd"$devidx".conf && echo -e "wifi"$devidx"=1" >> /nvram/vap-status |
developer | 10f1e5c | 2022-10-18 10:04:07 +0800 | [diff] [blame] | 84 | devidx=$(($devidx + 1)) |
| 85 | phyidx=$(($phyidx + 1)) |
developer | 42af00d | 2022-08-29 18:59:45 +0800 | [diff] [blame] | 86 | |
| 87 | done |
| 88 | } |
developer | faf1ea2 | 2022-04-29 17:53:25 +0800 | [diff] [blame] | 89 | #Creating files for tracking AssociatedDevices |
| 90 | touch /tmp/AllAssociated_Devices_2G.txt |
| 91 | touch /tmp/AllAssociated_Devices_5G.txt |
| 92 | |
developer | faf1ea2 | 2022-04-29 17:53:25 +0800 | [diff] [blame] | 93 | #Create wps pin request log file |
| 94 | touch /var/run/hostapd_wps_pin_requests.log |
| 95 | |
developer | faf1ea2 | 2022-04-29 17:53:25 +0800 | [diff] [blame] | 96 | |
developer | 42af00d | 2022-08-29 18:59:45 +0800 | [diff] [blame] | 97 | create_hostapdConf |
developer | 880c829 | 2022-07-11 11:52:59 +0800 | [diff] [blame] | 98 | |
developer | fe315c3 | 2022-12-15 14:36:22 +0800 | [diff] [blame^] | 99 | exit 0 |