3df6fde229c907ea3a8351f737edf3b7478694d1
[openwrt/openwrt.git] / target / linux / ath79 / base-files / etc / board.d / 02_network
1 #!/bin/sh
2
3 . /lib/functions/system.sh
4 . /lib/functions/uci-defaults.sh
5 . /lib/functions/k2t.sh
6
7 ath79_setup_interfaces()
8 {
9 local board="$1"
10
11 case "$board" in
12 aruba,ap-105|\
13 avm,fritz300e|\
14 devolo,dvl1200i|\
15 devolo,dvl1750c|\
16 devolo,dvl1750i|\
17 devolo,dvl1750x|\
18 engenius,ecb1750|\
19 glinet,gl-ar300m-lite|\
20 netgear,ex6400|\
21 netgear,ex7300|\
22 ocedo,koala|\
23 ocedo,raccoon|\
24 pcs,cap324|\
25 pisen,wmm003n|\
26 pqi,air-pen|\
27 tplink,cpe210-v2|\
28 tplink,cpe210-v3|\
29 tplink,re350k-v1|\
30 tplink,re450-v2|\
31 tplink,tl-mr10u|\
32 tplink,tl-mr3020-v1|\
33 tplink,tl-mr3040-v2|\
34 tplink,tl-wa901nd-v2|\
35 tplink,tl-wr703n|\
36 ubnt,bullet-m|\
37 ubnt,bullet-m-xw|\
38 ubnt,lap-120|\
39 ubnt,nanobeam-ac|\
40 ubnt,nanostation-ac-loco|\
41 ubnt,nanostation-loco-m|\
42 ubnt,picostation-m|\
43 ubnt,rocket-m|\
44 ubnt,unifiac-lite|\
45 ubnt,unifiac-lr|\
46 ubnt,unifiac-mesh|\
47 ubnt,unifi|\
48 wd,mynet-wifi-rangeextender|\
49 winchannel,wb2000)
50 ucidef_set_interface_lan "eth0"
51 ;;
52 avm,fritz4020|\
53 pcs,cr3000|\
54 tplink,archer-c58-v1|\
55 tplink,archer-c59-v1)
56 ucidef_set_interface_wan "eth1"
57 ucidef_add_switch "switch0" \
58 "0@eth0" "1:lan:1" "2:lan:4" "3:lan:3" "4:lan:2"
59 ;;
60 buffalo,bhr-4grv|\
61 buffalo,wzr-hp-g450h)
62 ucidef_add_switch "switch0" \
63 "0@eth0" "2:lan" "3:lan" "4:lan" "5:lan" "1:wan"
64 ;;
65 buffalo,bhr-4grv2)
66 ucidef_add_switch "switch0" \
67 "0@eth1" "1:lan" "2:lan" "3:lan" "4:lan" "5:wan" "6@eth0"
68 ;;
69 buffalo,whr-g301n)
70 ucidef_set_interface_wan "eth0"
71 ucidef_add_switch "switch0" \
72 "0@eth1" "1:lan:4" "2:lan:3" "3:lan:2" "4:lan:1"
73 ;;
74 buffalo,wzr-hp-ag300h|\
75 tplink,archer-c25-v1|\
76 tplink,tl-mr3220-v1|\
77 tplink,tl-mr3420-v1|\
78 tplink,tl-wr841-v7|\
79 tplink,tl-wr841-v9|\
80 tplink,tl-wr841-v10|\
81 tplink,tl-wr841-v11|\
82 tplink,tl-wr841-v12|\
83 tplink,tl-wr842n-v1|\
84 tplink,tl-wr842n-v3|\
85 ubnt,airrouter)
86 ucidef_set_interface_wan "eth1"
87 ucidef_add_switch "switch0" \
88 "0@eth0" "1:lan:4" "2:lan:3" "3:lan:2" "4:lan:1"
89 ;;
90 buffalo,wzr-hp-g302h-a1a0)
91 ucidef_add_switch "switch0" \
92 "0@eth0" "1:lan:1" "3:lan:4" "4:lan:3" "5:lan:2" "2:wan"
93 ;;
94 comfast,cf-e110n-v2|\
95 comfast,cf-e120a-v3|\
96 tplink,cpe220-v3|\
97 ubnt,nanostation-m|\
98 ubnt,routerstation)
99 ucidef_set_interfaces_lan_wan "eth1" "eth0"
100 ;;
101 devolo,dvl1200e|\
102 devolo,dvl1750e|\
103 ocedo,ursus)
104 ucidef_set_interface_lan "eth0 eth1"
105 ;;
106 dlink,dir-825-b1)
107 ucidef_set_interface_wan "eth1"
108 ucidef_add_switch "switch0" \
109 "0:lan" "1:lan" "2:lan" "3:lan" "5@eth0"
110 ;;
111 dlink,dir-825-c1|\
112 dlink,dir-835-a1|\
113 dlink,dir-859-a1|\
114 engenius,epg5000|\
115 tplink,archer-c2-v3|\
116 tplink,tl-wr1043nd-v4|\
117 tplink,tl-wr1043n-v5)
118 ucidef_add_switch "switch0" \
119 "0@eth0" "1:lan:4" "2:lan:3" "3:lan:2" "4:lan:1" "5:wan"
120 ;;
121 elecom,wrc-1750ghbk2-i|\
122 elecom,wrc-300ghbk2-i)
123 ucidef_add_switch "switch0" \
124 "0@eth0" "2:lan:4" "3:lan:3" "4:lan:2" "5:lan:1" "1:wan"
125 ;;
126 embeddedwireless,dorin)
127 ucidef_add_switch "switch0" \
128 "0@eth0" "1:wan" "2:lan:3" "3:lan:2"
129 ;;
130 engenius,ews511ap)
131 ucidef_set_interface_lan "eth0 eth1" "dhcp"
132 ;;
133 etactica,eg200)
134 ucidef_set_interface_lan "eth0" "dhcp"
135 ;;
136 glinet,gl-ar750s)
137 ucidef_add_switch "switch0" \
138 "0@eth0" "2:lan:2" "3:lan:1" "1:wan"
139 ;;
140 iodata,etg3-r|\
141 iodata,wn-ac1167dgr|\
142 iodata,wn-ac1600dgr|\
143 iodata,wn-ac1600dgr2|\
144 iodata,wn-ag300dgr|\
145 pcs,cr5000|\
146 wd,mynet-n750)
147 ucidef_add_switch "switch0" \
148 "0@eth0" "1:lan" "2:lan" "3:lan" "4:lan" "5:wan"
149 ;;
150 librerouter,librerouter-v1)
151 ucidef_add_switch "switch0" \
152 "0@eth0" "5:wan" "6@eth1" "4:lan"
153 ;;
154 nec,wg1200cr|\
155 ubnt,nanostation-ac|\
156 ubnt,unifiac-mesh-pro|\
157 ubnt,unifiac-pro|\
158 yuncore,a782|\
159 yuncore,xd4200)
160 ucidef_add_switch "switch0" \
161 "0@eth0" "2:lan" "3:wan"
162 ;;
163 nec,wg800hp)
164 ucidef_add_switch "switch0" \
165 "0@eth0" "2:lan" "3:lan" "4:lan" "1:wan"
166 ;;
167 netgear,wndr3700|\
168 netgear,wndr3700v2|\
169 netgear,wndr3800)
170 ucidef_set_interfaces_lan_wan "eth0" "eth1"
171 ucidef_add_switch "switch0" \
172 "0:lan:4" "1:lan:3" "2:lan:2" "3:lan:1" "5u@eth0"
173 ucidef_add_switch_attr "switch0" "blinkrate" 2
174 ucidef_add_switch_port_attr "switch0" 1 led 6
175 ucidef_add_switch_port_attr "switch0" 2 led 9
176 ucidef_add_switch_port_attr "switch0" 5 led 2
177 ;;
178 netgear,wnr612-v2|\
179 on,n150r|\
180 tplink,tl-wr740n-v1|\
181 tplink,tl-wr740n-v3|\
182 tplink,tl-wr741-v1|\
183 tplink,tl-wr743nd-v1|\
184 tplink,tl-wr841-v5|\
185 tplink,tl-wr941-v4)
186 ucidef_set_interface_wan "eth0"
187 ucidef_add_switch "switch0" \
188 "0@eth1" "1:lan" "2:lan" "3:lan" "4:lan"
189 ;;
190 phicomm,k2t)
191 ucidef_add_switch "switch0" \
192 "0@eth0" "3:lan:1" "5:lan:2" "4:wan"
193 ;;
194 rosinson,wr818)
195 ucidef_add_switch "switch0" \
196 "0@eth0" "1:lan" "2:lan" "3:wan"
197 ;;
198 tplink,archer-a7-v5|\
199 tplink,archer-c6-v2|\
200 tplink,archer-c7-v4|\
201 tplink,archer-c7-v5|\
202 tplink,tl-wdr3600-v1|\
203 tplink,tl-wdr4300-v1|\
204 tplink,tl-wdr4300-v1-il|\
205 tplink,tl-wr941n-v7-cn)
206 ucidef_add_switch "switch0" \
207 "0@eth0" "2:lan:1" "3:lan:2" "4:lan:3" "5:lan:4" "1:wan"
208 ;;
209 tplink,archer-c5-v1|\
210 tplink,archer-c7-v1|\
211 tplink,archer-c7-v2|\
212 tplink,tl-wdr4900-v2)
213 ucidef_add_switch "switch0" \
214 "0@eth1" "2:lan" "3:lan" "4:lan" "5:lan" "6@eth0" "1:wan"
215 ;;
216 tplink,archer-c60-v1|\
217 tplink,archer-c60-v2)
218 ucidef_set_interface_wan "eth1"
219 ucidef_add_switch "switch0" \
220 "0@eth0" "1:lan" "2:lan" "3:lan" "4:lan"
221 ;;
222 tplink,archer-d50-v1)
223 ucidef_add_switch "switch0" \
224 "0@eth0" "2:lan:3" "3:lan:2" "4:lan:1" "1:wan"
225 ;;
226 tplink,tl-wr1043nd-v1)
227 ucidef_add_switch "switch0" \
228 "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "5@eth0"
229 ;;
230 tplink,tl-wr1043nd-v2|\
231 tplink,tl-wr1043nd-v3)
232 ucidef_add_switch "switch0" \
233 "0@eth1" "1:lan:4" "2:lan:3" "3:lan:2" "4:lan:1" "5:wan" "6@eth0"
234 ;;
235 tplink,tl-wr2543-v1)
236 ucidef_add_switch "switch0" \
237 "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "9@eth0"
238 ;;
239 tplink,tl-wr740n-v4|\
240 tplink,tl-wr741nd-v4|\
241 tplink,tl-wr841-v8|\
242 tplink,tl-wr842n-v2)
243 ucidef_set_interface_wan "eth1"
244 ucidef_add_switch "switch0" \
245 "0@eth0" "1:lan:4" "2:lan:1" "3:lan:2" "4:lan:3"
246 ;;
247 tplink,tl-wr941-v2)
248 ucidef_set_interfaces_lan_wan "lan1 lan2 lan3 lan4" "wan"
249 ;;
250 ubnt,acb-isp)
251 ucidef_set_interface_wan "eth1"
252 ucidef_add_switch "switch0" \
253 "0@eth0" "2:lan:1" "3:lan:3" "4:lan:2"
254 ;;
255 ubnt,routerstation-pro)
256 ucidef_set_interface_wan "eth0"
257 ucidef_add_switch "switch0" \
258 "0@eth1" "2:lan:3" "3:lan:2" "4:lan:1"
259 ;;
260 ubnt,nanostation-m-xw)
261 ucidef_add_switch "switch0" \
262 "0@eth0" "5:lan" "1:wan"
263 ;;
264 zbtlink,zbt-wd323|\
265 xiaomi,mi-router-4q)
266 ucidef_set_interface_wan "eth1"
267 ucidef_add_switch "switch0" \
268 "0@eth0" "3:lan:1" "4:lan:2"
269 ;;
270 *)
271 ucidef_set_interfaces_lan_wan "eth0" "eth1"
272 ;;
273 esac
274 }
275
276 ath79_setup_macs()
277 {
278 local board="$1"
279
280 case "$board" in
281 avm,fritz300e)
282 lan_mac=$(fritz_tffs -n maca -i $(find_mtd_part "tffs (1)"))
283 ;;
284 avm,fritz4020)
285 lan_mac=$(fritz_tffs -n maca -i $(find_mtd_part "tffs (1)"))
286 wan_mac=$(fritz_tffs -n macb -i $(find_mtd_part "tffs (1)"))
287 ;;
288 dlink,dir-825-b1)
289 lan_mac=$(mtd_get_mac_text "caldata" 65440)
290 wan_mac=$(mtd_get_mac_text "caldata" 65460)
291 ;;
292 dlink,dir-825-c1|\
293 dlink,dir-835-a1)
294 lan_mac=$(mtd_get_mac_text "mac" 4)
295 wan_mac=$(mtd_get_mac_text "mac" 24)
296 ;;
297 dlink,dir-859-a1|\
298 nec,wg1200cr|\
299 wd,mynet-n750)
300 lan_mac=$(mtd_get_mac_ascii devdata "lanmac")
301 wan_mac=$(mtd_get_mac_ascii devdata "wanmac")
302 ;;
303 elecom,wrc-1750ghbk2-i|\
304 elecom,wrc-300ghbk2-i)
305 wan_mac=$(macaddr_add "$(mtd_get_mac_binary art 4098)" -2)
306 ;;
307 engenius,ecb1750)
308 lan_mac=$(mtd_get_mac_ascii u-boot-env ethaddr)
309 ;;
310 engenius,epg5000|\
311 iodata,wn-ac1167dgr|\
312 iodata,wn-ac1600dgr|\
313 iodata,wn-ac1600dgr2|\
314 iodata,wn-ag300dgr)
315 lan_mac=$(mtd_get_mac_ascii u-boot-env ethaddr)
316 wan_mac=$(mtd_get_mac_ascii u-boot-env wanaddr)
317 ;;
318 engenius,ews511ap)
319 lan_mac=$(mtd_get_mac_text "u-boot-env" 233)
320 eth1_mac=$(macaddr_add "$lan_mac" 1)
321 ucidef_set_interface "eth0" ifname "eth0" protocol "none" macaddr "$lan_mac"
322 ucidef_set_interface "eth1" ifname "eth1" protocol "none" macaddr "$eth1_mac"
323 ;;
324 iodata,etg3-r)
325 lan_mac=$(mtd_get_mac_ascii u-boot-env ethaddr)
326 wan_mac=$(macaddr_add "$lan_mac" -1)
327 ;;
328 jjplus,ja76pf2)
329 wan_mac=$(fconfig -s -r -d $(find_mtd_part "RedBoot config") -n alias/ethaddr)
330 lan_mac=$(macaddr_add "$wan_mac" 1)
331 ;;
332 nec,wg800hp)
333 lan_mac=$(mtd_get_mac_text board_data 640)
334 wan_mac=$(mtd_get_mac_text board_data 1152)
335 ;;
336 netgear,wndr3700|\
337 netgear,wndr3700v2|\
338 netgear,wndr3800)
339 lan_mac=$(macaddr_setbit_la "$(mtd_get_mac_binary art 0)")
340 ;;
341 phicomm,k2t)
342 lan_mac=$(k2t_get_mac "lan_mac")
343 wan_mac=$(k2t_get_mac "wan_mac")
344 ;;
345 rosinson,wr818)
346 wan_mac=$(mtd_get_mac_binary factory 0)
347 lan_mac=$(macaddr_setbit_la "$wan_mac")
348 ;;
349 tplink,archer-a7-v5|\
350 tplink,archer-c7-v4|\
351 tplink,archer-c7-v5|\
352 tplink,tl-wr1043nd-v4|\
353 tplink,tl-wr1043n-v5)
354 base_mac=$(mtd_get_mac_binary info 8)
355 wan_mac=$(macaddr_add "$base_mac" 1)
356 ;;
357 tplink,tl-wdr3600-v1|\
358 tplink,tl-wdr4300-v1|\
359 tplink,tl-wdr4300-v1-il)
360 base_mac=$(mtd_get_mac_binary u-boot 0x1fc00)
361 wan_mac=$(macaddr_add "$base_mac" 1)
362 ;;
363 tplink,tl-wr941-v2|\
364 tplink,tl-wr941n-v7-cn)
365 base_mac=$(mtd_get_mac_binary u-boot 130048)
366 wan_mac=$(macaddr_add "$base_mac" 1)
367 ;;
368 ubnt,routerstation|\
369 ubnt,routerstation-pro)
370 wan_mac=$(fconfig -s -r -d $(find_mtd_part "RedBoot config") -n ar7100_esa)
371 lan_mac=$(macaddr_add "$wan_mac" 1)
372 ;;
373 wd,mynet-wifi-rangeextender)
374 lan_mac=$(nvram get et0macaddr)
375 ;;
376 esac
377
378 [ -n "$lan_mac" ] && ucidef_set_interface_macaddr "lan" $lan_mac
379 [ -n "$wan_mac" ] && ucidef_set_interface_macaddr "wan" $wan_mac
380 }
381
382 board_config_update
383 board=$(board_name)
384 ath79_setup_interfaces $board
385 ath79_setup_macs $board
386 board_config_flush
387
388 exit 0