53f557c4952e5a7c5c8a1738f144c887927472cc
[oweals/openwrt.git] / target / linux / ar71xx / base-files / etc / board.d / 02_network
1 #!/bin/sh
2 #
3 # Copyright (C) 2011-2015 OpenWrt.org
4 #
5
6 . /lib/functions/system.sh
7 . /lib/functions/uci-defaults.sh
8 . /lib/ar71xx.sh
9
10 ar71xx_setup_interfaces()
11 {
12         local board="$1"
13
14         case "$board" in
15         all0315n|\
16         all0258n|\
17         dlan-hotspot|\
18         dlan-pro-500-wp|\
19         dr344|\
20         ja76pf2|\
21         rocket-m-ti|\
22         ubnt-unifi-outdoor)
23                 ucidef_set_interface_lan "eth0 eth1"
24                 ;;
25         ap132|\
26         ap136|\
27         ap152|\
28         rb-750gl|\
29         rb-751g|\
30         rb-951g-2hnd|\
31         wlr8100|\
32         wzr-hp-g450h)
33                 ucidef_add_switch "switch0" \
34                         "0@eth0" "2:lan" "3:lan" "4:lan" "5:lan" "1:wan"
35                 ;;
36         esr1750|\
37         epg5000)
38                 ucidef_add_switch "switch0" \
39                         "0@eth0" "1:lan:4" "2:lan:3" "3:lan:2" "4:lan:1" "5:wan"
40                 ;;
41         cr5000|\
42         dgl-5500-a1|\
43         dhp-1565-a1|\
44         dir-835-a1|\
45         dir-825-c1|\
46         esr900|\
47         mynet-n750|\
48         wndr3700v4|\
49         wndr4300)
50                 ucidef_add_switch "switch0" \
51                         "0@eth0" "1:lan" "2:lan" "3:lan" "4:lan" "5:wan"
52                 ;;
53         ap136-010|\
54         ap147-010|\
55         nbg6616|\
56         nbg6716)
57                 ucidef_set_interfaces_lan_wan "eth0" "eth1"
58                 ucidef_add_switch "switch0" \
59                         "0@eth0" "1:lan" "2:lan" "3:lan" "4:lan" "5:wan" "6@eth1"
60                 ;;
61         ap136-020|\
62         ap135-020|\
63         tew-823dru|\
64         tl-wr1043nd-v2|\
65         wzr-450hp2)
66                 ucidef_set_interfaces_lan_wan "eth1" "eth0"
67                 ucidef_add_switch "switch0" \
68                         "0@eth1" "1:lan:4" "2:lan:3" "3:lan:2" "4:lan:1" "5:wan" "6@eth0"
69                 ;;
70         archer-c5|\
71         archer-c7|\
72         tl-wdr4900-v2)
73                 ucidef_set_interfaces_lan_wan "eth1" "eth0"
74                 ucidef_add_switch "switch0" \
75                         "0@eth1" "2:lan" "3:lan" "4:lan" "5:lan" "6@eth0" "1:wan"
76                 ;;
77         bsb)
78                 ucidef_set_interfaces_lan_wan "eth1" "eth0"
79                 ucidef_add_switch "switch0" \
80                         "0@eth1" "1:lan" "3:lan"
81                 ;;
82         cpe210|\
83         cpe510)
84                 ucidef_add_switch "switch0" \
85                         "0@eth0" "5:lan" "4:wan"
86                 ;;
87         airgatewaypro)
88                 ucidef_add_switch "switch0" \
89                         "0@eth0" "4:lan" "5:wan"
90                 ;;
91         db120|\
92         rb-2011l|\
93         rb-2011uas|\
94         rb-2011uias|\
95         rb-2011uas-2hnd|\
96         rb-2011uias-2hnd)
97                 case "$board" in
98                 rb-2011uas*|\
99                 rb-2011uias|\
100                 rb-2011uias-2hnd)
101                         ucidef_add_switch "switch0" \
102                                 "0@eth0" "2:lan" "3:lan" "4:lan" "5:lan" "1:wan" "6:sfp"
103                 ;;
104                 *)
105                         ucidef_add_switch "switch0" \
106                                 "0@eth0" "2:lan" "3:lan" "4:lan" "5:lan" "1:wan"
107                 ;;
108                 esac
109
110                 ucidef_add_switch "switch1" \
111                         "0@eth1" "1:lan" "2:lan" "3:lan" "4:lan" "5:lan"
112                 ;;
113         dir-825-b1|\
114         nbg460n_550n_550nh|\
115         tew-673gru|\
116         wzr-hp-g300nh)
117                 ucidef_set_interfaces_lan_wan "eth0" "eth1"
118                 ucidef_add_switch "switch0" \
119                         "0:lan" "1:lan" "2:lan" "3:lan" "5@eth0"
120                 ;;
121         f9k1115v2)
122                 ucidef_set_interfaces_lan_wan "eth1" "eth0"
123                 ucidef_add_switch "switch0" \
124                         "2:lan" "3:lan" "4:lan" "5:lan" "6@eth1" "0@eth0" "1:wan"
125                 ;;
126         ap143|\
127         rb-433|\
128         rb-433u)
129                 ucidef_set_interfaces_lan_wan "eth1" "eth0"
130                 ucidef_add_switch "switch0" \
131                         "1:lan" "2:lan" "5@eth1"
132                 ;;
133         rb-435g)
134                 ucidef_set_interfaces_lan_wan "eth1" "eth0"
135                 ucidef_add_switch "switch0" \
136                         "0@eth1" "1:lan" "2:lan"
137                 ;;
138         rb-450)
139                 ucidef_set_interfaces_lan_wan "eth1" "eth0"
140                 ucidef_add_switch "switch0" \
141                         "0:lan" "1:lan" "2:lan" "3:lan" "5@eth1"
142                 ;;
143         rb-450g|\
144         routerstation-pro)
145                 ucidef_set_interfaces_lan_wan "eth1" "eth0"
146                 ucidef_add_switch "switch0" \
147                         "0@eth1" "2:lan:3" "3:lan:2" "4:lan:1"
148                 ;;
149         rb-493g)
150                 ucidef_set_interfaces_lan_wan "eth0 eth1.1" "eth1.2"
151                 ucidef_add_switch "switch0" \
152                         "0@eth0" "1:lan" "2:lan" "3:lan" "4:lan"
153                 ucidef_add_switch "switch1" \
154                         "0@eth1" "1:lan" "2:lan" "3:lan" "4:lan" "5:wan"
155                 ;;
156         wzr-hp-g300nh2|\
157         pb92|\
158         ap113)
159                 ucidef_add_switch "switch0" \
160                         "0@eth0" "1:lan:1" "3:lan:2" "4:lan:3" "5:lan:4" "2:wan"
161                 ;;
162         el-m150)
163                 ucidef_set_interfaces_lan_wan "eth1" "eth0"
164                 ucidef_add_switch "switch0" \
165                         "0:lan" "1:lan" "3@eth1"
166                 ;;
167         tellstick-znet-lite)
168                 ucidef_set_interface_wan "eth0"
169                 ucidef_set_interface_raw "wlan" "wlan0" "dhcp"
170                 ;;
171         tl-wdr4300|\
172         tl-wr1041n-v2)
173                 ucidef_add_switch "switch0" \
174                         "0@eth0" "2:lan:1" "3:lan:2" "4:lan:3" "5:lan:4" "1:wan"
175                 ;;
176         tl-wr1043nd)
177                 ucidef_add_switch "switch0" \
178                         "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "5@eth0"
179                 ;;
180         tl-wr2543n)
181                 ucidef_add_switch "switch0" \
182                         "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "9@eth0"
183                 ;;
184         tl-wr841n-v1|\
185         tl-wr941nd)
186                 ucidef_set_interface_raw "eth" "eth0"
187                 ucidef_set_interfaces_lan_wan "lan1 lan2 lan3 lan4" "wan"
188                 ;;
189         dir-615-i1|\
190         omy-g1|\
191         r6100|\
192         smart-300|\
193         tl-mr3420-v2|\
194         tl-wr841n-v8|\
195         tl-wr842n-v2|\
196         tl-wr941nd-v5|\
197         tl-wr941nd-v6|\
198         tl-wdr6500-v2|\
199         wnr2000-v3|\
200         wnr2000-v4|\
201         wnr2200|\
202         wnr612-v2|\
203         wnr1000-v2|\
204         wpn824n)
205                 ucidef_set_interfaces_lan_wan "eth1" "eth0"
206                 ucidef_add_switch "switch0" \
207                         "0:lan:4" "1:lan:3" "2:lan:2" "3:lan:1" "4@eth1"
208                 ;;
209         uap-pro|\
210         wpj342)
211                 ucidef_add_switch "switch0" \
212                         "0@eth0" "1:lan" "2:wan"
213                 ;;
214         nanostation-m-xw)
215                 ucidef_add_switch "switch0" \
216                         "0@eth0" "5:lan" "1:wan"
217                 ;;
218         wrt160nl)
219                 ucidef_set_interfaces_lan_wan "eth0" "eth1"
220                 ucidef_add_switch "switch0" \
221                         "0:lan:4" "1:lan:3" "2:lan:2" "3:lan:1" "4@eth0"
222                 ;;
223         cr3000)
224                 ucidef_set_interfaces_lan_wan "eth0" "eth1"
225                 ucidef_add_switch "switch0" \
226                         "0@eth0" "1:lan:1" "2:lan:4" "3:lan:3" "4:lan:2"
227                 ;;
228         onion-omega)
229                 ucidef_set_interface_lan "wlan0"
230                 ;;
231         dlan-pro-1200-ac)
232                 ucidef_set_interface_lan "eth0"
233                 ucidef_add_switch "switch0" \
234                         "0@eth0" "2:lan" "3:lan" "4:lan"
235                 ucidef_add_switch_attr "switch0" "enable" "false"
236                 ;;
237         alfa-ap120c|\
238         all0305|\
239         antminer-s1|\
240         antminer-s3|\
241         antrouter-r1|\
242         aw-nr580|\
243         bullet-m|\
244         c-55|\
245         cap4200ag|\
246         eap300v2|\
247         eap7660d|\
248         el-mini|\
249         loco-m-xw|\
250         mr1750|\
251         mr1750v2|\
252         mr18|\
253         mr600|\
254         mr600v2|\
255         mr900|\
256         mr900v2|\
257         rb-411|\
258         rb-911g-2hpnd|\
259         rb-911g-5hpacd|\
260         rb-911g-5hpnd|\
261         rb-912uag-2hpnd|\
262         rb-912uag-5hpnd|\
263         rb-sxt2n|\
264         rb-sxt5n|\
265         rocket-m-xw|\
266         tl-mr10u|\
267         tl-mr11u|\
268         tl-mr12u|\
269         tl-mr13u|\
270         tl-mr3020|\
271         tl-mr3040|\
272         tl-mr3040-v2|\
273         tl-wa701nd-v2|\
274         tl-wa7210n-v2|\
275         tl-wa750re|\
276         tl-wa850re|\
277         tl-wa830re-v2|\
278         tl-wa801nd-v2|\
279         tl-wa901nd|\
280         tl-wa901nd-v2|\
281         tl-wa901nd-v3|\
282         tl-wa901nd-v4|\
283         tl-wr703n|\
284         tube2h|\
285         unifiac-lite|\
286         wndap360|\
287         mynet-rext|\
288         wp543)
289                 ucidef_set_interface_lan "eth0"
290                 ;;
291         cap324)
292                 ucidef_set_interface_lan "eth0" "dhcp"
293                 ;;
294         arduino-yun|\
295         tl-wa801nd-v3|\
296         dir-505-a1)
297                 ucidef_set_interface_lan "eth1"
298                 ;;
299         alfa-ap96|\
300         alfa-nx|\
301         ap83|\
302         gl-ar150|\
303         gl-ar300m|\
304         gl-domino|\
305         gl-inet|\
306         gl-mifi|\
307         jwap003|\
308         pb42|\
309         pb44|\
310         rb-951ui-2hnd|\
311         routerstation|\
312         tl-wr710n|\
313         tl-wr720n-v3|\
314         tl-wr810n|\
315         wpe72|\
316         wrtnode2q)
317                 ucidef_set_interfaces_lan_wan "eth1" "eth0"
318                 ;;
319         gl-ar300)
320                 ucidef_set_interfaces_lan_wan "eth1" "eth0"
321                 ucidef_add_switch "switch0" \
322                         "0@eth1" "1:lan" "2:lan" "3:lan" "4:lan"
323                 ;;
324         jwap230)
325                 ucidef_set_interfaces_lan_wan "eth0" "eth1"
326                 ucidef_add_switch "switch0" \
327                         "0@eth0" "1:lan" "5:wan" "6@eth1"
328                 ;;
329         wpj344)
330                 ucidef_add_switch "switch0" \
331                         "0@eth0" "3:lan" "2:wan"
332                 ;;
333         unifiac-pro)
334                 ucidef_add_switch "switch0" \
335                         "0@eth0" "2:lan" "3:wan"
336                 ;;
337         wpj558)
338                 ucidef_add_switch "switch0" \
339                         "5:lan" "1:wan" "6@eth0"
340                 ;;
341         ap121|\
342         ap121-mini|\
343         ap96|\
344         airrouter|\
345         dir-600-a1|\
346         dir-615-c1|\
347         dir-615-e1|\
348         dir-615-e4|\
349         hiwifi-hc6361|\
350         ja76pf|\
351         mc-mac1200r|\
352         minibox-v1|\
353         mynet-n600|\
354         oolite|\
355         qihoo-c301|\
356         rb-750|\
357         rb-751|\
358         som9331|\
359         tew-632brp|\
360         tew-712br|\
361         tew-732br|\
362         tl-mr3220|\
363         tl-mr3220-v2|\
364         tl-mr3420|\
365         tl-wdr3320-v2|\
366         tl-wdr3500|\
367         tl-wr741nd|\
368         tl-wr741nd-v4|\
369         tl-wr841n-v7|\
370         tl-wr841n-v9|\
371         tl-wr841n-v11|\
372         tl-wr842n-v3|\
373         whr-g301n|\
374         whr-hp-g300n|\
375         whr-hp-gn|\
376         wzr-hp-ag300h|\
377         zbt-we1526)
378                 ucidef_set_interfaces_lan_wan "eth0" "eth1"
379                 ucidef_add_switch "switch0" \
380                         "0@eth0" "1:lan:4" "2:lan:3" "3:lan:2" "4:lan:1"
381                 ;;
382         wzr-hp-g450h)
383                 ucidef_add_switch "switch0" \
384                         "0@eth0" "2:lan:1 3:lan:2 4:lan:3 5:lan:4" "1:wan"
385                 ;;
386         ew-dorin)
387                 ucidef_add_switch "switch0" \
388                         "0@eth0" "1:lan" "2:lan" "3:wan"
389                 ;;
390         ew-dorin-router)
391                 ucidef_set_interfaces_lan_wan "eth0" "eth1"
392                 ucidef_add_switch "switch0" \
393                         "0@eth0" "2:lan" "3:lan"
394                 ;;
395         wndr3700)
396                 ucidef_set_interfaces_lan_wan "eth0" "eth1"
397                 ucidef_add_switch "switch0" \
398                         "0:lan" "1:lan" "2:lan" "3:lan" "5@eth0"
399
400                 ucidef_add_switch_attr "switch0" "blinkrate" 2
401                 ucidef_add_switch_port_attr "switch0" 1 led 6
402                 ucidef_add_switch_port_attr "switch0" 2 led 9
403                 ucidef_add_switch_port_attr "switch0" 5 led 2
404                 ;;
405         z1)
406                 ucidef_set_interfaces_lan_wan "eth0" "eth1"
407                 ucidef_add_switch "switch0" \
408                         "0@eth0" "1:lan:1" "2:lan:2" "3:lan:3" "4:lan:4" "5:wan"
409                 ;;
410         *)
411                 ucidef_set_interfaces_lan_wan "eth0" "eth1"
412                 ;;
413         esac
414 }
415
416 ar71xx_setup_macs()
417 {
418         local board="$1"
419         local lan_mac=""
420         local wan_mac=""
421
422         case $board in
423         dgl-5500-a1|\
424         dir-825-c1)
425                 wan_mac=$(mtd_get_mac_ascii nvram "wan_mac")
426                 ;;
427         dhp-1565-a1|\
428         dir-835-a1|\
429         wndr3700v4|\
430         wndr4300)
431                 lan_mac=$(mtd_get_mac_binary caldata 0)
432                 wan_mac=$(mtd_get_mac_binary caldata 6)
433                 ;;
434         esr900)
435                 wan_mac=$(mtd_get_mac_ascii u-boot-env "wanaddr")
436                 ;;
437         mynet-n750)
438                 wan_mac=$(mtd_get_mac_ascii devdata "wanmac")
439                 ;;
440         esac
441
442         [ -n "$lan_mac" ] && ucidef_set_interface_macaddr "lan" $lan_mac
443         [ -n "$wan_mac" ] && ucidef_set_interface_macaddr "wan" $wan_mac
444 }
445
446 board_config_update
447 board=$(ar71xx_board_name)
448 ar71xx_setup_interfaces $board
449 ar71xx_setup_macs $board
450 board_config_flush
451
452 exit 0