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