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