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