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