developer | 15a4331 | 2022-04-12 11:23:23 +0800 | [diff] [blame^] | 1 | # If not stated otherwise in this file or this component's LICENSE |
| 2 | # file the following copyright and licenses apply: |
| 3 | # |
| 4 | #Copyright [2019] [RDK Management] |
| 5 | # |
| 6 | #Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | #you may not use this file except in compliance with the License. |
| 8 | #You may obtain a copy of the License at |
| 9 | # |
| 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | # |
| 12 | #Unless required by applicable law or agreed to in writing, software |
| 13 | #distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | #WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | #See the License for the specific language governing permissions and |
| 16 | #limitations under the License. |
| 17 | |
| 18 | #!/bin/sh |
| 19 | |
| 20 | device_type=`cat /version.txt | grep imagename | cut -d':' -f2 | cut -d'-' -f3` |
| 21 | echo "device_type: $device_type" |
| 22 | if [ $device_type == "extender" ]; |
| 23 | then |
| 24 | #Workaround: allowing devices initialization |
| 25 | sleep 5; |
| 26 | fi |
| 27 | |
| 28 | nvram_mounted=`mount | grep nvram -wc` |
| 29 | if [ $nvram_mounted == 0 ]; then |
| 30 | mkdir -p /nvram |
| 31 | if [ -b /dev/mmcblk0p6 ]; then |
| 32 | #for Older Turris Omnia |
| 33 | mount /dev/mmcblk0p6 /nvram |
| 34 | else |
| 35 | #for Omnia2019 and Omnia2020 |
| 36 | mount /dev/mmcblk0p5 /nvram |
| 37 | fi |
| 38 | fi |
| 39 | |
| 40 | WIFI0_MAC=`cat /sys/class/net/wlan0/address` |
| 41 | WIFI1_MAC=`cat /sys/class/net/wlan1/address` |
| 42 | echo "2.4GHz Radio MAC: $WIFI0_MAC" |
| 43 | echo "5GHz Radio MAC: $WIFI1_MAC" |
| 44 | |
| 45 | if [ ! -f /nvram/hostapd0.conf ] |
| 46 | then |
| 47 | cp /etc/hostapd-2G.conf /nvram/hostapd0.conf |
| 48 | #Set bssid for wifi0 |
| 49 | NEW_MAC=$(echo 0x$WIFI0_MAC| awk -F: '{printf "%02x:%s:%s:%s:%s:%s", strtonum($1)+2, $2, $3, $4 ,$5, $6}') |
| 50 | sed -i "/^bssid=/c\bssid=$NEW_MAC" /nvram/hostapd0.conf |
| 51 | echo "wpa_psk_file=/tmp/hostapd0.psk" >> /nvram/hostapd0.conf |
| 52 | fi |
| 53 | |
| 54 | if [ ! -f /nvram/hostapd1.conf ] |
| 55 | then |
| 56 | cp /etc/hostapd-5G.conf /nvram/hostapd1.conf |
| 57 | #Set bssid for wifi1 |
| 58 | NEW_MAC=$(echo 0x$WIFI1_MAC| awk -F: '{printf "%02x:%s:%s:%s:%s:%s", strtonum($1)+2, $2, $3, $4 ,$5, $6}') |
| 59 | sed -i "/^bssid=/c\bssid=$NEW_MAC" /nvram/hostapd1.conf |
| 60 | echo "wpa_psk_file=/tmp/hostapd1.psk" >> /nvram/hostapd1.conf |
| 61 | fi |
| 62 | |
| 63 | if [ ! -f /nvram/hostapd2.conf ] |
| 64 | then |
| 65 | cp /etc/hostapd-bhaul2G.conf /nvram/hostapd2.conf |
| 66 | #Set bssid for wifi2 |
| 67 | NEW_MAC=$(echo 0x$WIFI0_MAC| awk -F: '{printf "%02x:%s:%s:%s:%s:%s", strtonum($1)+4, $2, $3, $4 ,$5, $6}') |
| 68 | sed -i "/^bssid=/c\bssid=$NEW_MAC" /nvram/hostapd2.conf |
| 69 | echo "wpa_psk_file=/tmp/hostapd2.psk" >> /nvram/hostapd2.conf |
| 70 | fi |
| 71 | |
| 72 | if [ ! -f /nvram/hostapd3.conf ] |
| 73 | then |
| 74 | cp /etc/hostapd-bhaul5G.conf /nvram/hostapd3.conf |
| 75 | #Set bssid for wifi3 |
| 76 | NEW_MAC=$(echo 0x$WIFI1_MAC| awk -F: '{printf "%02x:%s:%s:%s:%s:%s", strtonum($1)+4, $2, $3, $4 ,$5, $6}') |
| 77 | sed -i "/^bssid=/c\bssid=$NEW_MAC" /nvram/hostapd3.conf |
| 78 | echo "wpa_psk_file=/tmp/hostapd3.psk" >> /nvram/hostapd3.conf |
| 79 | fi |
| 80 | |
| 81 | if [ ! -f /nvram/hostapd4.conf ] |
| 82 | then |
| 83 | cp /etc/hostapd-bhaul2G.conf /nvram/hostapd4.conf |
| 84 | #Set bssid for wifi4 |
| 85 | NEW_MAC=$(echo 0x$WIFI0_MAC| awk -F: '{printf "%02x:%s:%s:%s:%s:%s", strtonum($1)+6, $2, $3, $4 ,$5, $6}') |
| 86 | sed -i "/^bssid=/c\bssid=$NEW_MAC" /nvram/hostapd4.conf |
| 87 | sed -i "/^interface=/c\interface=wifi4" /nvram/hostapd4.conf |
| 88 | sed -i "/^accept_mac/c\accept_mac_file=/tmp/hostapd-acl4" /nvram/hostapd4.conf |
| 89 | echo "wpa_psk_file=/tmp/hostapd4.psk" >> /nvram/hostapd4.conf |
| 90 | fi |
| 91 | |
| 92 | if [ ! -f /nvram/hostapd5.conf ] |
| 93 | then |
| 94 | cp /etc/hostapd-bhaul5G.conf /nvram/hostapd5.conf |
| 95 | #Set bssid for wifi5 |
| 96 | NEW_MAC=$(echo 0x$WIFI1_MAC| awk -F: '{printf "%02x:%s:%s:%s:%s:%s", strtonum($1)+6, $2, $3, $4 ,$5, $6}') |
| 97 | sed -i "/^bssid=/c\bssid=$NEW_MAC" /nvram/hostapd5.conf |
| 98 | sed -i "/^interface=/c\interface=wifi5" /nvram/hostapd5.conf |
| 99 | sed -i "/^accept_mac/c\accept_mac_file=/tmp/hostapd-acl5" /nvram/hostapd5.conf |
| 100 | echo "wpa_psk_file=/tmp/hostapd5.psk" >> /nvram/hostapd5.conf |
| 101 | fi |
| 102 | |
| 103 | if [ ! -f /nvram/hostapd6.conf ] |
| 104 | then |
| 105 | cp /etc/hostapd-bhaul2G.conf /nvram/hostapd6.conf |
| 106 | #Set bssid for wifi6 |
| 107 | NEW_MAC=$(echo 0x$WIFI1_MAC| awk -F: '{printf "%02x:%s:%s:%s:%s:%s", strtonum($1)+8, $2, $3, $4 ,$5, $6}') |
| 108 | sed -i "/^bssid=/c\bssid=$NEW_MAC" /nvram/hostapd6.conf |
| 109 | sed -i "/^interface=/c\interface=wifi6" /nvram/hostapd6.conf |
| 110 | sed -i "/^accept_mac/c\accept_mac_file=/tmp/hostapd-acl6" /nvram/hostapd6.conf |
| 111 | echo "wpa_psk_file=/tmp/hostapd6.psk" >> /nvram/hostapd6.conf |
| 112 | fi |
| 113 | |
| 114 | if [ ! -f /nvram/hostapd7.conf ] |
| 115 | then |
| 116 | cp /etc/hostapd-bhaul5G.conf /nvram/hostapd7.conf |
| 117 | #Set bssid for wifi7 |
| 118 | NEW_MAC=$(echo 0x$WIFI1_MAC| awk -F: '{printf "%02x:%s:%s:%s:%s:%s", strtonum($1)+8, $2, $3, $4 ,$5, $6}') |
| 119 | sed -i "/^bssid=/c\bssid=$NEW_MAC" /nvram/hostapd7.conf |
| 120 | sed -i "/^interface=/c\interface=wifi7" /nvram/hostapd7.conf |
| 121 | sed -i "/^accept_mac/c\accept_mac_file=/tmp/hostapd-acl7" /nvram/hostapd7.conf |
| 122 | echo "wpa_psk_file=/tmp/hostapd7.psk" >> /nvram/hostapd7.conf |
| 123 | fi |
| 124 | |
| 125 | #Setting up VAP status file |
| 126 | echo -e "wifi0=1\nwifi1=1\nwifi2=0\nwifi3=0\nwifi4=0\nwifi5=0\nwifi6=0\nwifi7=0" >/tmp/vap-status |
| 127 | |
| 128 | #Creating files for tracking AssociatedDevices |
| 129 | touch /tmp/AllAssociated_Devices_2G.txt |
| 130 | touch /tmp/AllAssociated_Devices_5G.txt |
| 131 | |
| 132 | if [ $device_type == "extender" ]; |
| 133 | then |
| 134 | ifconfig wlan0 down |
| 135 | ifconfig wlan1 down |
| 136 | exit 0; |
| 137 | fi |
| 138 | |
| 139 | #Creating virtual interfaces wifi0 and wifi1 for Home APs |
| 140 | iw dev wlan0 interface add wifi0 type __ap |
| 141 | iw dev wlan1 interface add wifi1 type __ap |
| 142 | |
| 143 | #2.4GHz Virtual Access Points for backhaul connection |
| 144 | iw dev wlan0 interface add wifi2 type __ap |
| 145 | ip addr add 169.254.0.1/25 dev wifi2 |
| 146 | ifconfig wifi2 mtu 1600 |
| 147 | |
| 148 | #5GHz Virtual Access Points for backhaul connection |
| 149 | iw dev wlan1 interface add wifi3 type __ap |
| 150 | ip addr add 169.254.1.1/25 dev wifi3 |
| 151 | ifconfig wifi3 mtu 1600 |
| 152 | |
| 153 | #Creating virtual interfaces wifi4 and wifi5 for Guest APs |
| 154 | iw dev wlan0 interface add wifi4 type __ap |
| 155 | iw dev wlan1 interface add wifi5 type __ap |
| 156 | |
| 157 | #2.4GHz Virtual Access Points for Secure Onboard connection |
| 158 | iw dev wlan0 interface add wifi6 type __ap |
| 159 | ip addr add 169.254.0.129/25 dev wifi6 |
| 160 | ifconfig wifi6 mtu 1600 |
| 161 | |
| 162 | #5GHz Virtual Access Points for onboard connection |
| 163 | iw dev wlan1 interface add wifi7 type __ap |
| 164 | ip addr add 169.254.1.129/25 dev wifi7 |
| 165 | ifconfig wifi7 mtu 1600 |
| 166 | |
| 167 | #Creating virtual interfaces wifi8 and wifi9 for Service APs |
| 168 | iw dev wlan0 interface add wifi8 type __ap |
| 169 | iw dev wlan1 interface add wifi9 type __ap |
| 170 | |
| 171 | #Create empty acl list for hostapd |
| 172 | touch /tmp/hostapd-acl0 |
| 173 | touch /tmp/hostapd-acl1 |
| 174 | touch /tmp/hostapd-acl2 |
| 175 | touch /tmp/hostapd-acl3 |
| 176 | touch /tmp/hostapd-acl4 |
| 177 | touch /tmp/hostapd-acl5 |
| 178 | touch /tmp/hostapd-acl6 |
| 179 | touch /tmp/hostapd-acl7 |
| 180 | touch /tmp/hostapd-acl8 |
| 181 | touch /tmp/hostapd-acl9 |
| 182 | |
| 183 | #create empty psk files |
| 184 | touch /tmp/hostapd0.psk |
| 185 | touch /tmp/hostapd1.psk |
| 186 | touch /tmp/hostapd2.psk |
| 187 | touch /tmp/hostapd3.psk |
| 188 | touch /tmp/hostapd6.psk |
| 189 | touch /tmp/hostapd7.psk |
| 190 | touch /tmp/hostapd8.psk |
| 191 | touch /tmp/hostapd9.psk |
| 192 | |
| 193 | #Create wps pin request log file |
| 194 | touch /var/run/hostapd_wps_pin_requests.log |
| 195 | |
| 196 | #Setting brlan0 bridge |
| 197 | if [ ! -f /sys/class/net/brlan0 ] |
| 198 | then |
| 199 | brctl addbr brlan0 |
| 200 | ip link set brlan0 address `cat /sys/class/net/eth1/address` |
| 201 | ifconfig brlan0 10.0.0.1 netmask 255.255.255.0 up |
| 202 | fi |
| 203 | |
| 204 | #Work around for Ethernet connected clients |
| 205 | brctl addif brlan0 lan0 |
| 206 | brctl addif brlan0 lan1 |
| 207 | brctl addif brlan0 lan2 |
| 208 | brctl addif brlan0 lan3 |
| 209 | brctl addif brlan0 lan4 |
| 210 | |
| 211 | ifconfig eth1 up |
| 212 | ifconfig lan0 up |
| 213 | ifconfig lan1 up |
| 214 | ifconfig lan2 up |
| 215 | ifconfig lan3 up |
| 216 | ifconfig lan4 up |
| 217 | |
| 218 | #workaround: creating /opt/secure folder for ssh service |
| 219 | mkdir /opt/secure |
| 220 | |
| 221 | exit 0 |
| 222 | |