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