brcm47xx: fix switch port order for Netgear WN2500RP V1
[openwrt/openwrt.git] / target / linux / brcm47xx / base-files / etc / board.d / 01_network
1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2006-2015 OpenWrt.org
3
4 . /lib/functions/system.sh
5 . /lib/functions/uci-defaults.sh
6
7 configure_by_vlanports() {
8 local vlan0ports="$(nvram get vlan0ports)"
9 local vlan1ports="$(nvram get vlan1ports)"
10 local vlan2ports="$(nvram get vlan2ports)"
11 local cpuport="$(swconfig dev switch0 help 2>/dev/null | sed -ne "s|.*cpu @ \([0-9]*\).*|\1|p")"
12
13 if [ "${vlan0ports:0:9}" = "0 1 2 3 8" -a "${vlan1ports:0:3}" = "4 8" -a ${cpuport:-0} -eq 8 ] || \
14 [ "${vlan1ports:0:9}" = "0 1 2 3 8" -a "${vlan2ports:0:3}" = "4 8" -a ${cpuport:-0} -eq 8 ] || \
15 [ "${vlan2ports:0:9}" = "0 1 2 3 8" -a "${vlan1ports:0:3}" = "4 8" -a ${cpuport:-0} -eq 8 ];
16 then
17 ucidef_add_switch "switch0" \
18 "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "8@eth0"
19
20 elif [ "${vlan0ports:0:9}" = "1 2 3 4 8" -a "${vlan1ports:0:3}" = "0 8" -a ${cpuport:-0} -eq 8 ] || \
21 [ "${vlan1ports:0:9}" = "1 2 3 4 8" -a "${vlan2ports:0:3}" = "0 8" -a ${cpuport:-0} -eq 8 ] || \
22 [ "${vlan2ports:0:9}" = "1 2 3 4 8" -a "${vlan1ports:0:3}" = "0 8" -a ${cpuport:-0} -eq 8 ];
23 then
24 ucidef_add_switch "switch0" \
25 "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "8@eth0"
26
27 elif [ "${vlan0ports:0:9}" = "0 1 2 3 5" -a "${vlan1ports:0:3}" = "4 5" -a ${cpuport:-0} -eq 5 ] || \
28 [ "${vlan1ports:0:9}" = "0 1 2 3 5" -a "${vlan2ports:0:3}" = "4 5" -a ${cpuport:-0} -eq 5 ] || \
29 [ "${vlan2ports:0:9}" = "0 1 2 3 5" -a "${vlan1ports:0:3}" = "4 5" -a ${cpuport:-0} -eq 5 ];
30 then
31 ucidef_add_switch "switch0" \
32 "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "5@eth0"
33
34 elif [ "${vlan0ports:0:9}" = "1 2 3 4 5" -a "${vlan1ports:0:3}" = "0 5" -a ${cpuport:-0} -eq 5 ] || \
35 [ "${vlan1ports:0:9}" = "1 2 3 4 5" -a "${vlan2ports:0:3}" = "0 5" -a ${cpuport:-0} -eq 5 ] || \
36 [ "${vlan2ports:0:9}" = "1 2 3 4 5" -a "${vlan1ports:0:3}" = "0 5" -a ${cpuport:-0} -eq 5 ];
37 then
38 ucidef_add_switch "switch0" \
39 "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "5@eth0"
40
41 else
42 logger -t "01_network" "Unable to determine network configuration"
43 ucidef_set_interface_lan "eth0"
44 fi
45 }
46
47 configure_by_boardnum() {
48 local boardnum="$1"
49
50 case "$boardnum" in
51 # WAP54G, Sitecom WL-105b
52 "2" | \
53 "1024")
54 ucidef_set_interface_lan "eth0"
55 ;;
56
57 # Generic detection fallback
58 *)
59 configure_by_vlanports
60 ;;
61 esac
62 }
63
64 configure_by_boardtype() {
65 local boardtype="$1"
66 local boardnum="$2"
67
68 case "$boardtype" in
69 "bcm94710r4")
70 ucidef_set_interfaces_lan_wan "eth0" "eth1"
71 ;;
72
73 "0x0467")
74 ucidef_add_switch "switch0" \
75 "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "5@eth0"
76 ;;
77
78 "0x042f" | \
79 "0x0472")
80 # WL-500gP
81 if [ "$boardnum" = "45" ]; then
82 ucidef_add_switch "switch0" \
83 "0:wan" "1:lan" "2:lan" "3:lan" "4:lan" "5@eth0"
84
85 # Generic BCM94704
86 else
87 ucidef_set_interface_wan "eth1"
88 ucidef_add_switch "switch0" \
89 "0:lan" "1:lan" "2:lan" "3:lan" "4:lan" "5@eth0"
90
91 # MAC addresses on 4704 tend to be screwed up. Add a workaround here
92 local mac="$(nvram get et0macaddr)"
93 local pat="[0-9a-fA-F][0-9a-fA-F]:[0-9a-fA-F][0-9a-fA-F]"
94 pat="$pat:[0-9a-fA-F][0-9a-fA-F]:[0-9a-fA-F][0-9a-fA-F]"
95 pat="$pat:[0-9a-fA-F][0-9a-fA-F]:[0-9a-fA-F][0-9a-fA-F]"
96
97 case "$mac" in
98 $pat)
99 ucidef_set_interface_macaddr "lan" "$mac"
100 ucidef_set_interface_macaddr "wan" "$(macaddr_add "$mac" 1)"
101 ;;
102 esac
103 fi
104 ;;
105
106 # Buffalo WBR-B11 and Buffalo WBR-G54
107 "bcm94710ap")
108 ucidef_set_interface_wan "eth1"
109 ucidef_add_switch "switch0" \
110 "0:lan" "1:lan" "2:lan" "3:lan" "4:lan" "5@eth0"
111 ;;
112
113 *)
114 configure_by_boardnum "$boardnum"
115 ;;
116 esac
117 }
118
119 configure_by_model() {
120 local model="$1"
121 local boardtype="$2"
122 local boardnum="$3"
123
124 # Netgear WGT634U exception
125 if grep -sqE 'mtd0: 000(6|a)0000' /proc/mtd; then
126 ucidef_add_switch "switch0" \
127 "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "5@eth0"
128 return
129 fi
130
131 case "$model" in
132 "Asus WLHDD" | \
133 "Asus WL300G")
134 ucidef_set_interface_lan "eth1"
135 ;;
136
137 "Asus WL330GE")
138 ucidef_add_switch "switch0" "4:lan" "5t@eth0"
139 ;;
140
141 "Asus WL500G" | \
142 "Microsoft MN-700")
143 ucidef_set_interfaces_lan_wan "eth0" "eth1"
144 ;;
145
146 "Asus WL500GP V2")
147 ucidef_add_switch "switch0" \
148 "0:lan:4" "1:lan:3" "2:lan:2" "3:lan:1" "4:wan" "5@eth0"
149 ;;
150
151 "Asus RT-N12"* | \
152 "Buffalo WHR-G125" | \
153 "D-Link DIR-330" | \
154 "Motorola WR850G" | \
155 "Siemens SE505 V2")
156 ucidef_add_switch "switch0" \
157 "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "5@eth0"
158 ;;
159
160 "Asus WL700")
161 ucidef_add_switch "switch0" \
162 "0:wan" "1:lan" "2:lan" "3:lan" "4:lan" "5@eth0"
163 ;;
164
165 "Asus WL500W" | \
166 "Dell TrueMobile 2300")
167 ucidef_set_interface_wan "eth1"
168 ucidef_add_switch "switch0" \
169 "0:lan" "1:lan" "2:lan" "3:lan" "5@eth0"
170 ;;
171
172 "Asus RT-N16"* | \
173 "Linksys E3000 V1" | \
174 "Netgear WNR3500 V2" | \
175 "Netgear WNR3500L")
176 ucidef_add_switch "switch0" \
177 "0:wan" "1:lan:4" "2:lan:3" "3:lan:2" "4:lan:1" "8@eth0"
178 ;;
179
180 "Netgear WN2500RP V1")
181 ucidef_add_switch "switch0" \
182 "0:lan:4" "1:lan:3" "2:lan:2" "3:lan:1" "5@eth0"
183 ;;
184
185 *)
186 configure_by_boardtype "$boardtype" "$boardnum"
187 ;;
188 esac
189 }
190
191
192 model="$(cat /tmp/sysinfo/model)"
193 boardtype="$(board_name)"
194
195 case "$boardtype" in
196 *:*)
197 boardnum="${boardtype##*:}"
198 boardtype="${boardtype%:*}"
199 ;;
200 esac
201
202 board_config_update
203
204 configure_by_model "$model" "$boardtype" "$boardnum"
205
206 board_config_flush