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