ralink: mt7621 has a different base addr for PVID
[openwrt.git] / target / linux / ramips / base-files / etc / board.d / 02_network
1 #!/bin/sh
2
3 . /lib/functions.sh
4 . /lib/ramips.sh
5 . /lib/functions/uci-defaults-new.sh
6 . /lib/functions/system.sh
7
8 ramips_setup_rt3x5x_vlans()
9 {
10         if [ ! -x /sbin/swconfig ]; then
11                 # legacy default
12                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
13                 return
14         fi
15         local wanports=""
16         local lanports=""
17         for port in 5 4 3 2 1 0; do
18                 if [ `swconfig dev rt305x port $port get disable` = "1" ]; then
19                         continue
20                 fi
21                 if [ `swconfig dev rt305x port $port get lan` = "0" ]; then
22                         wanports="$port $wanports"
23                 else
24                         lanports="$port $lanports"
25                 fi
26         done
27         ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
28         ucidef_add_switch "rt305x" "1" "1"
29         ucidef_add_switch_vlan "rt305x" "1" "$lanports 6t"
30         ucidef_add_switch_vlan "rt305x" "2" "$wanports 6t"
31 }
32
33 ramips_setup_interfaces()
34 {
35         local board="$1"
36
37         ucidef_set_interface_loopback
38
39         case $board in
40         a5-v11)
41                 ucidef_set_interface_lan "eth0.1"
42                 ucidef_add_switch "switch0" "1" "1"
43                 ucidef_add_switch_vlan "switch0" "1" "0 6t"
44                 ;;
45
46         3g300m | \
47         w150m | \
48         all0256n | \
49         all5002 | \
50         all5003 | \
51         broadway | \
52         dcs-930| \
53         ncs601w | \
54         wnce2001)
55                 ucidef_add_switch "switch0" "1" "0"
56                 ucidef_set_interface_lan "eth0"
57                 ;;
58
59         3g-6200nl | \
60         mlw221)
61                 ucidef_set_interface_lan "eth0.2"
62                 ;;
63
64         wizard8800 | \
65         wl-330n | \
66         wmr300)
67                 ucidef_set_interface_lan "eth0.1"
68                 ;;
69
70         b2c | \
71         nw718 | \
72         psr-680w | \
73         sl-r7205 | \
74         w502u | \
75         wr6202)
76                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
77                 ;;
78
79         awapn2403)
80                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
81                 ucidef_add_switch "switch0" "1" "1"
82                 ucidef_add_switch_vlan "switch0" "1" "0 6t"
83                 ucidef_add_switch_vlan "switch0" "2" "1 6t"
84                 ;;
85
86         br-6475nd)
87                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
88                 ucidef_add_switch "switch0" "1" "1"
89                 ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 9t"
90                 ucidef_add_switch_vlan "switch0" "2" "0 9t"
91                 ;;
92
93         asl26555)
94                 ucidef_set_interface_lan "eth0.1"
95                 ucidef_add_switch "switch0" "1" "1"
96                 ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 6t"
97                 ;;
98
99         cy-swr1100)
100                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
101                 ucidef_add_switch "switch0" "1" "1"
102                 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 9t"
103                 ucidef_add_switch_vlan "switch0" "2" "4 9t"
104                 ;;
105
106         ht-tm02)
107                 ucidef_set_interface_lan "eth0.1"
108                 ucidef_add_switch "switch0" "1" "1"
109                 ucidef_add_switch_vlan "switch0" "1" "4 6t"
110                 ;;
111
112         3g-6200n | \
113         dir-610-a1 | \
114         dir-300-b7 | \
115         dir-320-b1 | \
116         dir-615-h1 | \
117         hlk-rm04 | \
118         mt7621 | \
119         mt7628 | \
120         mzk-w300nh2 | \
121         mzk-750dhp | \
122         whr-300hp2 | \
123         whr-600d | \
124         wt1520)
125                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
126                 ucidef_add_switch "switch0" "1" "1"
127                 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 6t"
128                 ucidef_add_switch_vlan "switch0" "2" "4 6t"
129                 ;;
130         whr-1166d)
131                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
132                 ucidef_add_switch "switch0" "1" "1"
133                 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 6t"
134                 ucidef_add_switch_vlan "switch0" "2" "5 6t"
135                 ;;
136
137         awm002-evb | \
138         awm003-evb | \
139         argus-atp52b | \
140         dir-645 | \
141         f5d8235-v1 | \
142         f5d8235-v2 | \
143         hg255d | \
144         rt-n14u | \
145         wrtnode | \
146         wt3020 | \
147         ur-326n4g | \
148         zbt-wa05)
149                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
150                 ucidef_add_switch "switch0" "1" "1"
151                 ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 6t"
152                 ucidef_add_switch_vlan "switch0" "2" "0 6t"
153                 ;;
154
155         ur-336un)
156                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
157                 ;;
158
159         br6524n | \
160         v11st-fe)
161                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
162                 ucidef_add_switch "switch0" "1" "1"
163                 ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 5t"
164                 ucidef_add_switch_vlan "switch0" "2" "0 5t"
165                 ;;
166
167         ar670w | \
168         ar725w | \
169         rt-n15 | \
170         wl-351)
171                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
172                 ucidef_add_switch "switch0" "1" "1"
173                 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 5t"
174                 ucidef_add_switch_vlan "switch0" "2" "4 5t"
175                 ;;
176
177         rt-n56u)
178                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
179                 ucidef_add_switch "switch0" "1" "1"
180                 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 8t"
181                 ucidef_add_switch_vlan "switch0" "2" "4 8t"
182                 ;;
183
184         tew-691gr|\
185         tew-692gr)
186                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
187                 ucidef_add_switch "switch0" "1" "1"
188                 ucidef_add_switch_vlan "switch0" "1" "0t 1 2 3 4"
189                 ucidef_add_switch_vlan "switch0" "2" "0t 5"
190                 ;;
191
192         vocore)
193                 ucidef_set_interface_lan "eth0.1"
194                 ucidef_add_switch "switch0" "1" "1"
195                 ucidef_add_switch_vlan "switch0" "1" "0 4 6t"
196                 ;;
197
198         wcr-150gn)
199                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
200                 ucidef_add_switch "switch0" "1" "1"
201                 ucidef_add_switch_vlan "switch0" "1" "0 6t"
202                 ucidef_add_switch_vlan "switch0" "2" "6t"
203                 ;;
204
205         wr8305rt)
206                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
207                 ucidef_add_switch "switch0" "1" "1"
208                 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 4 6t"
209                 ucidef_add_switch_vlan "switch0" "2" "4 6t"
210                 ;;
211
212         y1 |\
213         y1s)
214                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
215                 ucidef_add_switch "switch0" "1" "1"
216                 ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 5 6t"
217                 ucidef_add_switch_vlan "switch0" "2" "0 6t"
218                 ;;
219         d105 | \
220         na930 | \
221         omni-emb-hpm|\
222         wli-tx4-ag300n)
223                 ucidef_set_interface_lan "eth0"
224                 ;;
225
226         e1700 | \
227         mt7620a_mt7530)
228                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
229                 ucidef_add_switch "switch1" "1" "1"
230                 ucidef_add_switch_vlan "switch1" "1" "0 1 2 3 6t"
231                 ucidef_add_switch_vlan "switch1" "2" "4 6t"
232                 ;;
233
234         *)
235                 RT3X5X=`cat /proc/cpuinfo | egrep "(RT3.5|RT5350)"`
236                 if [ -n "${RT3X5X}" ]; then
237                         ramips_setup_rt3x5x_vlans
238                 else
239                         ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
240                 fi
241                 ;;
242         esac
243 }
244
245 ramips_setup_macs()
246 {
247         local board="$1"
248         local lan_mac=""
249         local wan_mac=""
250
251         case $board in
252         br-6475nd)
253                 lan_mac=$(cat /sys/class/net/eth0/address)
254                 wan_mac=$(mtd_get_mac_binary devdata 7)
255                 ;;
256
257         w306r-v20)
258                 lan_mac=$(cat /sys/class/net/eth0/address)
259                 wan_mac=$(macaddr_add "$lan_mac" 5)
260                 ;;
261
262         tew-691gr)
263                 lan_mac=$(cat /sys/class/net/eth0/address)
264                 wan_mac=$(macaddr_add "$lan_mac" 3)
265                 ;;
266
267         tew-692gr)
268                 lan_mac=$(cat /sys/class/net/eth0/address)
269                 wan_mac=$(macaddr_add "$lan_mac" 4)
270                 ;;
271
272         m3 |\
273         m4 |\
274         x5 |\
275         x8)
276                 lan_mac=$(cat /sys/class/net/eth0/address)
277                 lan_mac=$(macaddr_add "$lan_mac" -2)
278                 ;;
279
280         a5-v11 |\
281         bc2 |\
282         broadway |\
283         d105 |\
284         dir-620-a1 |\
285         esr-9753 |\
286         freestation5 |\
287         hlk-rm04 | \
288         mpr-a1 | \
289         mpr-a2 | \
290         ht-tm02 | \
291         dir-300-b7 | \
292         dir-320-b1 | \
293         psr-680w |\
294         sl-r7205 |\
295         y1 |\
296         y1s)
297                 lan_mac=$(cat /sys/class/net/eth0/address)
298                 lan_mac=$(macaddr_setbit_la "$lan_mac")
299                 wan_mac=$(macaddr_add "$lan_mac" 1)
300                 ;;
301
302         cy-swr1100 | \
303         dir-645)
304                 lan_mac=$(mtd_get_mac_ascii nvram lanmac)
305                 wan_mac=$(mtd_get_mac_ascii nvram wanmac)
306                 ;;
307
308         e1700)
309                 wan_mac=$(mtd_get_mac_ascii config WAN_MAC_ADDR)
310                 ;;
311
312         wcr-150gn)
313                 wan_mac=$(mtd_get_mac_binary factory 40)
314                 ;;
315
316         rt-n56u)
317                 lan_mac=$(cat /sys/class/net/eth0/address)
318                 lan_mac=$(macaddr_setbit_la "$lan_mac")
319                 wan_mac=$(mtd_get_mac_binary factory 32772)
320                 ;;
321
322         all0239-3g | \
323         carambola | \
324         freestation5 | \
325         w502u | \
326         wnce2001)
327                 wan_mac=$(mtd_get_mac_binary factory 46)
328                 ;;
329
330         *)
331                 lan_mac=$(cat /sys/class/net/eth0/address)
332                 wan_mac=$(macaddr_add "$lan_mac" 1)
333                 ;;
334
335         esac
336
337         [ -n "$lan_mac" ] && ucidef_set_interface_macaddr lan $lan_mac
338         [ -n "$wan_mac" ] && ucidef_set_interface_macaddr wan $wan_mac
339 }
340
341 board_config_update
342 board=$(ramips_board_name)
343 ramips_setup_interfaces $board
344 ramips_setup_macs $board
345 board_config_flush
346
347 exit 0