ralink: fix lenovo y1 wan port mapping
[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         wsr-600 | \
125         wsr-1166 | \
126         wt1520 | \
127         y1)
128                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
129                 ucidef_add_switch "switch0" "1" "1"
130                 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 6t"
131                 ucidef_add_switch_vlan "switch0" "2" "4 6t"
132                 ;;
133
134         whr-1166d)
135                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
136                 ucidef_add_switch "switch0" "1" "1"
137                 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 6t"
138                 ucidef_add_switch_vlan "switch0" "2" "5 6t"
139                 ;;
140
141         awm002-evb | \
142         awm003-evb | \
143         argus-atp52b | \
144         dir-645 | \
145         f5d8235-v1 | \
146         f5d8235-v2 | \
147         hg255d | \
148         rt-n14u | \
149         wrtnode | \
150         wt3020 | \
151         ur-326n4g | \
152         zbt-wa05)
153                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
154                 ucidef_add_switch "switch0" "1" "1"
155                 ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 6t"
156                 ucidef_add_switch_vlan "switch0" "2" "0 6t"
157                 ;;
158
159         ur-336un)
160                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
161                 ;;
162
163         br6524n | \
164         v11st-fe)
165                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
166                 ucidef_add_switch "switch0" "1" "1"
167                 ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 5t"
168                 ucidef_add_switch_vlan "switch0" "2" "0 5t"
169                 ;;
170
171         ar670w | \
172         ar725w | \
173         rt-n15 | \
174         wl-351)
175                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
176                 ucidef_add_switch "switch0" "1" "1"
177                 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 5t"
178                 ucidef_add_switch_vlan "switch0" "2" "4 5t"
179                 ;;
180
181         rt-n56u)
182                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
183                 ucidef_add_switch "switch0" "1" "1"
184                 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 8t"
185                 ucidef_add_switch_vlan "switch0" "2" "4 8t"
186                 ;;
187
188         tew-691gr|\
189         tew-692gr)
190                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
191                 ucidef_add_switch "switch0" "1" "1"
192                 ucidef_add_switch_vlan "switch0" "1" "0t 1 2 3 4"
193                 ucidef_add_switch_vlan "switch0" "2" "0t 5"
194                 ;;
195
196         vocore)
197                 ucidef_set_interface_lan "eth0.1"
198                 ucidef_add_switch "switch0" "1" "1"
199                 ucidef_add_switch_vlan "switch0" "1" "0 4 6t"
200                 ;;
201
202         wcr-150gn)
203                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
204                 ucidef_add_switch "switch0" "1" "1"
205                 ucidef_add_switch_vlan "switch0" "1" "0 6t"
206                 ucidef_add_switch_vlan "switch0" "2" "6t"
207                 ;;
208
209         wr8305rt)
210                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
211                 ucidef_add_switch "switch0" "1" "1"
212                 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 4 6t"
213                 ucidef_add_switch_vlan "switch0" "2" "4 6t"
214                 ;;
215
216         y1s)
217                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
218                 ucidef_add_switch "switch0" "1" "1"
219                 ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 5 6t"
220                 ucidef_add_switch_vlan "switch0" "2" "0 6t"
221                 ;;
222         d105 | \
223         na930 | \
224         omni-emb-hpm|\
225         wli-tx4-ag300n)
226                 ucidef_set_interface_lan "eth0"
227                 ;;
228
229         e1700 | \
230         mt7620a_mt7530)
231                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
232                 ucidef_add_switch "switch1" "1" "1"
233                 ucidef_add_switch_vlan "switch1" "1" "0 1 2 3 6t"
234                 ucidef_add_switch_vlan "switch1" "2" "4 6t"
235                 ;;
236
237         *)
238                 RT3X5X=`cat /proc/cpuinfo | egrep "(RT3.5|RT5350)"`
239                 if [ -n "${RT3X5X}" ]; then
240                         ramips_setup_rt3x5x_vlans
241                 else
242                         ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
243                 fi
244                 ;;
245         esac
246 }
247
248 ramips_setup_macs()
249 {
250         local board="$1"
251         local lan_mac=""
252         local wan_mac=""
253
254         case $board in
255         br-6475nd)
256                 lan_mac=$(cat /sys/class/net/eth0/address)
257                 wan_mac=$(mtd_get_mac_binary devdata 7)
258                 ;;
259
260         w306r-v20)
261                 lan_mac=$(cat /sys/class/net/eth0/address)
262                 wan_mac=$(macaddr_add "$lan_mac" 5)
263                 ;;
264
265         tew-691gr)
266                 lan_mac=$(cat /sys/class/net/eth0/address)
267                 wan_mac=$(macaddr_add "$lan_mac" 3)
268                 ;;
269
270         tew-692gr)
271                 lan_mac=$(cat /sys/class/net/eth0/address)
272                 wan_mac=$(macaddr_add "$lan_mac" 4)
273                 ;;
274
275         m3 |\
276         m4 |\
277         x5 |\
278         x8)
279                 lan_mac=$(cat /sys/class/net/eth0/address)
280                 lan_mac=$(macaddr_add "$lan_mac" -2)
281                 ;;
282
283         a5-v11 |\
284         bc2 |\
285         broadway |\
286         d105 |\
287         dir-620-a1 |\
288         esr-9753 |\
289         freestation5 |\
290         hlk-rm04 | \
291         mpr-a1 | \
292         mpr-a2 | \
293         ht-tm02 | \
294         dir-300-b7 | \
295         dir-320-b1 | \
296         psr-680w |\
297         sl-r7205 |\
298         y1 |\
299         y1s)
300                 lan_mac=$(cat /sys/class/net/eth0/address)
301                 lan_mac=$(macaddr_setbit_la "$lan_mac")
302                 wan_mac=$(macaddr_add "$lan_mac" 1)
303                 ;;
304
305         cy-swr1100 | \
306         dir-645)
307                 lan_mac=$(mtd_get_mac_ascii nvram lanmac)
308                 wan_mac=$(mtd_get_mac_ascii nvram wanmac)
309                 ;;
310
311         e1700)
312                 wan_mac=$(mtd_get_mac_ascii config WAN_MAC_ADDR)
313                 ;;
314
315         wcr-150gn)
316                 wan_mac=$(mtd_get_mac_binary factory 40)
317                 ;;
318
319         rt-n56u)
320                 lan_mac=$(cat /sys/class/net/eth0/address)
321                 lan_mac=$(macaddr_setbit_la "$lan_mac")
322                 wan_mac=$(mtd_get_mac_binary factory 32772)
323                 ;;
324
325         all0239-3g | \
326         carambola | \
327         freestation5 | \
328         w502u | \
329         wnce2001)
330                 wan_mac=$(mtd_get_mac_binary factory 46)
331                 ;;
332
333         *)
334                 lan_mac=$(cat /sys/class/net/eth0/address)
335                 wan_mac=$(macaddr_add "$lan_mac" 1)
336                 ;;
337
338         esac
339
340         [ -n "$lan_mac" ] && ucidef_set_interface_macaddr lan $lan_mac
341         [ -n "$wan_mac" ] && ucidef_set_interface_macaddr wan $wan_mac
342 }
343
344 board_config_update
345 board=$(ramips_board_name)
346 ramips_setup_interfaces $board
347 ramips_setup_macs $board
348 board_config_flush
349
350 exit 0