ath79: add support for TP-Link TL-WR841N/ND v12
[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-wr841-v12|\
81 tplink,tl-wr842n-v1|\
82 tplink,tl-wr842n-v3|\
83 ubnt,airrouter)
84 ucidef_set_interface_wan "eth1"
85 ucidef_add_switch "switch0" \
86 "0@eth0" "1:lan:4" "2:lan:3" "3:lan:2" "4:lan:1"
87 ;;
88 buffalo,wzr-hp-g302h-a1a0)
89 ucidef_add_switch "switch0" \
90 "0@eth0" "1:lan:1" "3:lan:4" "4:lan:3" "5:lan:2" "2:wan"
91 ;;
92 comfast,cf-e110n-v2|\
93 comfast,cf-e120a-v3|\
94 tplink,cpe220-v3|\
95 ubnt,nanostation-m|\
96 ubnt,routerstation)
97 ucidef_set_interfaces_lan_wan "eth1" "eth0"
98 ;;
99 devolo,dvl1200e|\
100 devolo,dvl1750e|\
101 ocedo,ursus)
102 ucidef_set_interface_lan "eth0 eth1"
103 ;;
104 dlink,dir-825-b1)
105 ucidef_set_interface_wan "eth1"
106 ucidef_add_switch "switch0" \
107 "0:lan" "1:lan" "2:lan" "3:lan" "5@eth0"
108 ;;
109 dlink,dir-825-c1|\
110 dlink,dir-835-a1|\
111 dlink,dir-859-a1|\
112 engenius,epg5000|\
113 tplink,archer-c2-v3|\
114 tplink,tl-wr1043nd-v4|\
115 tplink,tl-wr1043n-v5)
116 ucidef_add_switch "switch0" \
117 "0@eth0" "1:lan:4" "2:lan:3" "3:lan:2" "4:lan:1" "5:wan"
118 ;;
119 elecom,wrc-1750ghbk2-i|\
120 elecom,wrc-300ghbk2-i)
121 ucidef_add_switch "switch0" \
122 "0@eth0" "2:lan:4" "3:lan:3" "4:lan:2" "5:lan:1" "1:wan"
123 ;;
124 embeddedwireless,dorin)
125 ucidef_add_switch "switch0" \
126 "0@eth0" "1:wan" "2:lan:3" "3:lan:2"
127 ;;
128 engenius,ews511ap)
129 ucidef_set_interface_lan "eth0 eth1" "dhcp"
130 ;;
131 etactica,eg200)
132 ucidef_set_interface_lan "eth0" "dhcp"
133 ;;
134 glinet,gl-ar750s)
135 ucidef_add_switch "switch0" \
136 "0@eth0" "2:lan:2" "3:lan:1" "1:wan"
137 ;;
138 iodata,etg3-r|\
139 iodata,wn-ac1167dgr|\
140 iodata,wn-ac1600dgr|\
141 iodata,wn-ac1600dgr2|\
142 iodata,wn-ag300dgr|\
143 pcs,cr5000|\
144 wd,mynet-n750)
145 ucidef_add_switch "switch0" \
146 "0@eth0" "1:lan" "2:lan" "3:lan" "4:lan" "5:wan"
147 ;;
148 librerouter,librerouter-v1)
149 ucidef_add_switch "switch0" \
150 "0@eth0" "5:wan" "6@eth1" "4:lan"
151 ;;
152 nec,wg1200cr|\
153 ubnt,nanostation-ac|\
154 ubnt,unifiac-mesh-pro|\
155 ubnt,unifiac-pro|\
156 yuncore,a782|\
157 yuncore,xd4200)
158 ucidef_add_switch "switch0" \
159 "0@eth0" "2:lan" "3:wan"
160 ;;
161 nec,wg800hp)
162 ucidef_add_switch "switch0" \
163 "0@eth0" "2:lan" "3:lan" "4:lan" "1:wan"
164 ;;
165 netgear,wndr3700|\
166 netgear,wndr3700v2|\
167 netgear,wndr3800)
168 ucidef_set_interfaces_lan_wan "eth0" "eth1"
169 ucidef_add_switch "switch0" \
170 "0:lan:4" "1:lan:3" "2:lan:2" "3:lan:1" "5u@eth0"
171 ucidef_add_switch_attr "switch0" "blinkrate" 2
172 ucidef_add_switch_port_attr "switch0" 1 led 6
173 ucidef_add_switch_port_attr "switch0" 2 led 9
174 ucidef_add_switch_port_attr "switch0" 5 led 2
175 ;;
176 netgear,wnr612-v2|\
177 on,n150r|\
178 tplink,tl-wr740n-v1|\
179 tplink,tl-wr740n-v3|\
180 tplink,tl-wr741-v1|\
181 tplink,tl-wr743nd-v1|\
182 tplink,tl-wr841-v5|\
183 tplink,tl-wr941-v4)
184 ucidef_set_interface_wan "eth0"
185 ucidef_add_switch "switch0" \
186 "0@eth1" "1:lan" "2:lan" "3:lan" "4:lan"
187 ;;
188 phicomm,k2t)
189 ucidef_add_switch "switch0" \
190 "0@eth0" "3:lan:1" "5:lan:2" "4:wan"
191 ;;
192 rosinson,wr818)
193 ucidef_add_switch "switch0" \
194 "0@eth0" "1:lan" "2:lan" "3:wan"
195 ;;
196 tplink,archer-a7-v5|\
197 tplink,archer-c6-v2|\
198 tplink,archer-c7-v4|\
199 tplink,archer-c7-v5|\
200 tplink,tl-wdr3600-v1|\
201 tplink,tl-wdr4300-v1|\
202 tplink,tl-wdr4300-v1-il|\
203 tplink,tl-wr941n-v7-cn)
204 ucidef_add_switch "switch0" \
205 "0@eth0" "2:lan:1" "3:lan:2" "4:lan:3" "5:lan:4" "1:wan"
206 ;;
207 tplink,archer-c5-v1|\
208 tplink,archer-c7-v1|\
209 tplink,archer-c7-v2|\
210 tplink,tl-wdr4900-v2)
211 ucidef_add_switch "switch0" \
212 "0@eth1" "2:lan" "3:lan" "4:lan" "5:lan" "6@eth0" "1:wan"
213 ;;
214 tplink,archer-c60-v1|\
215 tplink,archer-c60-v2)
216 ucidef_set_interface_wan "eth1"
217 ucidef_add_switch "switch0" \
218 "0@eth0" "1:lan" "2:lan" "3:lan" "4:lan"
219 ;;
220 tplink,archer-d50-v1)
221 ucidef_add_switch "switch0" \
222 "0@eth0" "2:lan:3" "3:lan:2" "4:lan:1" "1:wan"
223 ;;
224 tplink,tl-wr1043nd-v1)
225 ucidef_add_switch "switch0" \
226 "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "5@eth0"
227 ;;
228 tplink,tl-wr1043nd-v2|\
229 tplink,tl-wr1043nd-v3)
230 ucidef_add_switch "switch0" \
231 "0@eth1" "1:lan:4" "2:lan:3" "3:lan:2" "4:lan:1" "5:wan" "6@eth0"
232 ;;
233 tplink,tl-wr2543-v1)
234 ucidef_add_switch "switch0" \
235 "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "9@eth0"
236 ;;
237 tplink,tl-wr740n-v4|\
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