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