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