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