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