bcm53xx: add workaround for Netgear R8000 network
[15.05/openwrt.git] / target / linux / bcm53xx / base-files / etc / board.d / 02_network
1 #!/bin/sh
2 #
3 # Copyright (C) 2011 OpenWrt.org
4 #
5
6 . /lib/functions/uci-defaults-new.sh
7
8 board_config_update
9
10 board=$(cat /proc/device-tree/compatible | tr '\0' '\t' | cut -f 1)
11 case "$board" in
12 asus,rt-ac87u)
13         ifname=eth1
14         ;;
15 netgear,r8000)
16         ifname=eth2
17         ;;
18 *)
19         ifname=eth0
20         ;;
21 esac
22
23 # Workaround for devices using eth2
24 case "$board" in
25 netgear,r8000)
26         ifname=eth0
27         ;;
28 esac
29
30 ucidef_set_interface_loopback
31 ucidef_set_interfaces_lan_wan "$ifname.1" "$ifname.2"
32 ucidef_add_switch "switch0" "1" "1"
33
34 # Workaround for devices using CPU port 8 (connected to eth2)
35 case "$board" in
36 netgear,r8000)
37         ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 5t"
38         ucidef_add_switch_vlan "switch0" "2" "4 5t"
39         board_config_flush
40         exit 0
41         ;;
42 esac
43
44 # NVRAM entries may contain unsorted ports, e.g. Netgear R6250 uses
45 # vlan1ports=3 2 1 0 5*
46 # vlan2ports=4 5u
47 # and early Netgear R8000 was using
48 # vlan1ports=3 2 1 0 5 7 8*
49 vlan1ports="$(echo $(nvram get vlan1ports | tr " " "\n" | sort))"
50 vlan2ports="$(echo $(nvram get vlan2ports | tr " " "\n" | sort))"
51 if echo "$vlan1ports" | egrep -q "^1 2 3 4 5" && \
52    echo "$vlan2ports" | egrep -q "^0 5"; then
53         ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 5t"
54         ucidef_add_switch_vlan "switch0" "2" "0 5t"
55 elif echo "$vlan1ports" | egrep -q "^1 2 3 5 7" && \
56      echo "$vlan2ports" | egrep -q "^0 7"; then
57         ucidef_add_switch_vlan "switch0" "1" "1 2 3 5 7t"
58         ucidef_add_switch_vlan "switch0" "2" "0 7t"
59 elif echo "$vlan1ports" | egrep -q "^0 1 2 3 5 7 8" && \
60      echo "$vlan2ports" | egrep -q "^4 8"; then
61         ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 5 7 8t"
62         ucidef_add_switch_vlan "switch0" "2" "4 8t"
63 else
64         ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 5t"
65         ucidef_add_switch_vlan "switch0" "2" "4 5t"
66 fi
67
68 board_config_flush
69
70 exit 0