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